Skip to content

Commit

Permalink
Merge pull request #7 from onready/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Juan Cernadas authored Jun 22, 2020
2 parents 60042c8 + f2b8938 commit 3506d9c
Show file tree
Hide file tree
Showing 45 changed files with 965 additions and 198 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
- :hammer: Built 100% with Typescript.
- :muscle: 0 dependencies. It uses the native `https` Node module.
- :tada: Promise based.
- :dizzy: Type definitions for all VTEX requests and responses.
- :dizzy: Type definitions for many VTEX requests and responses.

<ins>**Note**</ins>: *<strong>This is not a VTEX official package, we are VTEX Partners since 2017 and we developed this to collaborate with VTEX Community.</strong>*

Expand Down Expand Up @@ -88,17 +88,17 @@ API | Implemented
:------------: | :-------------:|
OMS | :white_check_mark: |
Logistics | :white_check_mark: |
Pricing | Comming soon... |
Pricing | :white_check_mark: |
Master Data (V2) | :white_check_mark: (*) <em>Attachments API pending</em> |
Antifraud Provider | :x: |
Catalog | :x: |
Catalog | Comming soon... |
Checkout | :x: |
CMS | :x: |
Customer Credit | :x: |
Giftcard | :x: |
Giftcard Hub | :x: |
Giftcard Provider Protocol | :x: |
License Manager | :x: |
Master Data (V2) | :x: |
Payment Provider Protocol | :x: |
Payments Gateway | :x: |
Rates and Benefits | :x: |
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onreadydesa/vtex-node-sdk",
"version": "1.1.0-alpha",
"version": "1.3.0-alpha",
"description": "VTEX Node SDK, built 100% with Typescript and 0 dependencies!",
"author": "Onready",
"private": false,
Expand All @@ -27,22 +27,22 @@
"lint": "eslint ."
},
"devDependencies": {
"@babel/core": "7.10.2",
"@babel/preset-env": "7.10.2",
"@babel/core": "7.10.3",
"@babel/preset-env": "7.10.3",
"@babel/preset-typescript": "7.10.1",
"@types/jest": "26.0.0",
"@types/node": "14.0.13",
"@typescript-eslint/eslint-plugin": "3.3.0",
"@typescript-eslint/parser": "3.3.0",
"babel-jest": "26.0.1",
"eslint": "7.2.0",
"eslint": "7.3.0",
"eslint-config-airbnb-base": "14.2.0",
"eslint-plugin-import": "2.21.2",
"eslint-plugin-jest": "23.13.2",
"eslint-plugin-jest": "23.16.0",
"jest": "26.0.1",
"nock": "12.0.3",
"rimraf": "3.0.2",
"ts-jest": "26.1.0",
"ts-jest": "26.1.1",
"typescript": "3.9.5"
},
"engines": {
Expand Down
14 changes: 14 additions & 0 deletions src/VTEX.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { VtexCredentials } from './VtexCredentials';
import { VtexHttpClient } from './utils/VtexHttpClient';
import { OMS } from './modules/OMS';
import { Logistics } from './modules/logistics';
import { Pricing } from './modules/pricing';
import { MasterData } from './modules/master-data/v2';

export class VTEX {
private static buildErrorMessage(paramName: string): string {
Expand Down Expand Up @@ -32,6 +34,16 @@ export class VTEX {
*/
readonly logistics: Logistics;

/**
* Pricing Module
*/
readonly pricing: Pricing;

/**
* Master Data (V2) Module
*/
readonly masterData: MasterData;

/**
* @param {string} store
* @param {string} appKey
Expand All @@ -48,5 +60,7 @@ export class VTEX {
// Create needed modules
this.oms = new OMS(vtexHttpClient);
this.logistics = new Logistics(vtexHttpClient);
this.pricing = new Pricing(vtexHttpClient);
this.masterData = new MasterData(vtexHttpClient);
}
}
55 changes: 55 additions & 0 deletions src/modules/master-data/v2/MasterData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { VtexHttpClient } from '../../../utils/VtexHttpClient';
import { Documents } from './apis/documents';
import { Search } from './apis/search';
import { Scroll } from './apis/scroll';
import { Schemas } from './apis/schemas';
import { Indices } from './apis/indices';
import { Clusters } from './apis/clusters';
import { Versions } from './apis/versions';

export class MasterData {
/**
* Documents API
*/
readonly documents: Documents;

/**
* Search API
*/
readonly search: Search;

/**
* Scroll API
*/
readonly scroll: Scroll;

/**
* Schemas API
*/
readonly schemas: Schemas;

/**
* Indices API
*/
readonly indices: Indices;

/**
* Clusters API
*/
readonly clusters: Clusters;

/**
* Versions API
*/
readonly versions: Versions;

constructor(vtexHttpClient: VtexHttpClient) {
this.documents = new Documents(vtexHttpClient);
this.search = new Search(vtexHttpClient);
this.scroll = new Scroll(vtexHttpClient);
this.schemas = new Schemas(vtexHttpClient);
this.indices = new Indices(vtexHttpClient);
this.clusters = new Clusters(vtexHttpClient);
this.versions = new Versions(vtexHttpClient);
}
}
20 changes: 20 additions & 0 deletions src/modules/master-data/v2/apis/clusters/Clusters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { AbstractApi } from '../../../../AbstractApi';
import { VtexHttpResponse } from '../../../../../utils/VtexHttpResponse';
import { ValidateDocumentByClustersRequestItem } from './requests/ValidateDocumentByClustersRequestItem';

export class Clusters extends AbstractApi {
/**
* Lets you know if a particular document is in one or more clusters.
* @param {string} dataEntityName
* @param {string} id
* @param {Array<ValidateDocumentByClustersRequestItem>} rules
*/
validateDocumentByClusters(dataEntityName: string, id: string,
rules: Array<ValidateDocumentByClustersRequestItem>): Promise<VtexHttpResponse> {
return this.vtexHttpClient.performRequest(
`/api/dataentities/${dataEntityName}/documents/${id}/clusters`,
this.HTTP_METHODS.POST,
rules,
);
}
}
1 change: 1 addition & 0 deletions src/modules/master-data/v2/apis/clusters/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './Clusters';
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface ValidateDocumentByClustersRequestItem {
name?: string;
rule?: string;
}
92 changes: 92 additions & 0 deletions src/modules/master-data/v2/apis/documents/Documents.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { AbstractApi } from '../../../../AbstractApi';
import { VtexHttpResponse } from '../../../../../utils/VtexHttpResponse';
import { CreateNewDocumentResponse } from './responses/CreateNewDocumentResponse';
import { GetDocumentResponse } from './responses/GetDocumentResponse';

export class Documents extends AbstractApi {
private static readonly BASE_PATH: string = '/api/dataentities';

/**
*
* @param {string} dataEntityName
* @param {any} documentData
* @param {string} params Example: _schema=schema1
*/
createNewDocument(dataEntityName: string, documentData: any, params?: string)
: Promise<VtexHttpResponse<CreateNewDocumentResponse>> {
const path = `${Documents.BASE_PATH}/${dataEntityName}/documents?${params}`;
return this.vtexHttpClient.performRequest(path, this.HTTP_METHODS.POST, documentData);
}

/**
*
* @param {string} dataEntityName
* @param {any} documentData
* @param {string} params Example: _schema=schema1
*/
createOrUpdateEntireDocument(dataEntityName: string, documentData: any, params?: string)
: Promise<VtexHttpResponse> {
const path = `${Documents.BASE_PATH}/${dataEntityName}/documents?${params}`;
return this.vtexHttpClient.performRequest(path, this.HTTP_METHODS.PUT, documentData);
}

/**
*
* @param {string} dataEntityName
* @param {any} documentData
* @param {string} params Example: _schema=schema1
*/
createOrUpdatePartialDocument(dataEntityName: string, documentData: any, params?: string)
: Promise<VtexHttpResponse> {
const path = `${Documents.BASE_PATH}/${dataEntityName}/documents?${params}`;
return this.vtexHttpClient.performRequest(path, this.HTTP_METHODS.PATCH, documentData);
}

/**
*
* @param {string} dataEntityName
* @param {string} id
* @param {string} params Example: _schema=schema1&_where=where-statement
*/
getDocument(dataEntityName: string, id: string, params?: string)
: Promise<VtexHttpResponse<GetDocumentResponse>> {
const path = `${Documents.BASE_PATH}/${dataEntityName}/documents/${id}?${params}`;
return this.vtexHttpClient.performRequest(path, this.HTTP_METHODS.GET);
}

/**
*
* @param {string} dataEntityName
* @param {string} id
* @param {any} documentData
* @param {string} params Example: _schema=schema1&_where=where-statement
*/
updateEntireDocument(dataEntityName: string, id: string, documentData: any, params?: string)
: Promise<VtexHttpResponse> {
const path = `${Documents.BASE_PATH}/${dataEntityName}/documents/${id}?${params}`;
return this.vtexHttpClient.performRequest(path, this.HTTP_METHODS.PUT, documentData);
}

/**
*
* @param {string} dataEntityName
* @param {string} id
* @param {any} documentData
* @param {string} params Example: _schema=schema1&_where=where-statement
*/
updatePartialDocument(dataEntityName: string, id: string, documentData: any, params?: string)
: Promise<VtexHttpResponse> {
const path = `${Documents.BASE_PATH}/${dataEntityName}/documents/${id}?${params}`;
return this.vtexHttpClient.performRequest(path, this.HTTP_METHODS.PATCH, documentData);
}

/**
*
* @param {string} dataEntityName
* @param {string} id
*/
deleteDocument(dataEntityName: string, id: string): Promise<VtexHttpResponse> {
const path = `${Documents.BASE_PATH}/${dataEntityName}/documents/${id}`;
return this.vtexHttpClient.performRequest(path, this.HTTP_METHODS.DELETE);
}
}
1 change: 1 addition & 0 deletions src/modules/master-data/v2/apis/documents/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './Documents';
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface CreateNewDocumentResponse {
Id?: string;
Href?: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface GetDocumentResponse {
id?: string;
accountId?: string;
accountName?: string;
dataEntityId?: string;
}
36 changes: 36 additions & 0 deletions src/modules/master-data/v2/apis/indices/Indices.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { AbstractApi } from '../../../../AbstractApi';
import { VtexHttpResponse } from '../../../../../utils/VtexHttpResponse';
import { PutIndicesRequest } from './requests/PutIndicesRequest';

export class Indices extends AbstractApi {
private static readonly BASE_PATH: string = '/api/dataentities';

/**
* Return the list of indices by data entity.
* @param {string} dataEntityName
*/
getIndices(dataEntityName: string): Promise<VtexHttpResponse> {
const path = `${Indices.BASE_PATH}/${dataEntityName}/indices`;
return this.vtexHttpClient.performRequest(path, this.HTTP_METHODS.GET);
}

/**
* Create an indice.
* @param {string} dataEntityName
* @param {PutIndicesRequest} indexData
*/
putIndices(dataEntityName: string, indiceData: PutIndicesRequest): Promise<VtexHttpResponse> {
const path = `${Indices.BASE_PATH}/${dataEntityName}/indices`;
return this.vtexHttpClient.performRequest(path, this.HTTP_METHODS.PUT, indiceData);
}

/**
* Return an indice.
* @param {string} dataEntityName
* @param {string} indiceName
*/
getIndiceByName(dataEntityName: string, indiceName: string): Promise<VtexHttpResponse> {
const path = `${Indices.BASE_PATH}/${dataEntityName}/indices/${indiceName}`;
return this.vtexHttpClient.performRequest(path, this.HTTP_METHODS.GET);
}
}
1 change: 1 addition & 0 deletions src/modules/master-data/v2/apis/indices/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './Indices';
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface PutIndicesRequest {
name?: string;
multiple?: boolean;
fields?: string;
}
37 changes: 37 additions & 0 deletions src/modules/master-data/v2/apis/schemas/Schemas.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { AbstractApi } from '../../../../AbstractApi';
import { VtexHttpResponse } from '../../../../../utils/VtexHttpResponse';

export class Schemas extends AbstractApi {
private static readonly BASE_PATH: string = '/api/dataentities';

/**
* Return the schemas saved.
* @param {string} dataEntityName
*/
getSchemas(dataEntityName: string): Promise<VtexHttpResponse> {
const path = `${Schemas.BASE_PATH}/${dataEntityName}/schemas`;
return this.vtexHttpClient.performRequest(path, this.HTTP_METHODS.GET);
}

/**
* Return the schema saved.
* @param {string} dataEntityName
* @param {string} schemaName
*/
getSchemaByName(dataEntityName: string, schemaName: string): Promise<VtexHttpResponse> {
const path = `${Schemas.BASE_PATH}/${dataEntityName}/schemas/${schemaName}`;
return this.vtexHttpClient.performRequest(path, this.HTTP_METHODS.GET);
}

/**
* Save the schema.
* @param {string} dataEntityName
* @param {string} schemaName
* @param {any} schemaData
*/
saveSchemaByName(dataEntityName: string, schemaName: string, schemaData: any)
: Promise<VtexHttpResponse> {
const path = `${Schemas.BASE_PATH}/${dataEntityName}/schemas/${schemaName}`;
return this.vtexHttpClient.performRequest(path, this.HTTP_METHODS.PUT, schemaData);
}
}
1 change: 1 addition & 0 deletions src/modules/master-data/v2/apis/schemas/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './Schemas';
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface SaveSchemaByNameRequest {
properties?: any;
}
14 changes: 14 additions & 0 deletions src/modules/master-data/v2/apis/scroll/Scroll.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { AbstractApi } from '../../../../AbstractApi';

export class Scroll extends AbstractApi {
/**
*
* @param {string} dataEntityName
* @param {string} params See https://developers.vtex.com/reference/scroll#scrolldocuments
*/
scrollDocuments(dataEntityName: string, params?: string) {
return this.vtexHttpClient.performRequest(
`/api/dataentities/${dataEntityName}/scroll?${params}`, this.HTTP_METHODS.GET,
);
}
}
1 change: 1 addition & 0 deletions src/modules/master-data/v2/apis/scroll/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './Scroll';
Loading

0 comments on commit 3506d9c

Please sign in to comment.