-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from onready/develop
Develop
- Loading branch information
Showing
45 changed files
with
965 additions
and
198 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './Clusters'; |
4 changes: 4 additions & 0 deletions
4
src/modules/master-data/v2/apis/clusters/requests/ValidateDocumentByClustersRequestItem.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export interface ValidateDocumentByClustersRequestItem { | ||
name?: string; | ||
rule?: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './Documents'; |
4 changes: 4 additions & 0 deletions
4
src/modules/master-data/v2/apis/documents/responses/CreateNewDocumentResponse.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export interface CreateNewDocumentResponse { | ||
Id?: string; | ||
Href?: string; | ||
} |
6 changes: 6 additions & 0 deletions
6
src/modules/master-data/v2/apis/documents/responses/GetDocumentResponse.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './Indices'; |
5 changes: 5 additions & 0 deletions
5
src/modules/master-data/v2/apis/indices/requests/PutIndicesRequest.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export interface PutIndicesRequest { | ||
name?: string; | ||
multiple?: boolean; | ||
fields?: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './Schemas'; |
3 changes: 3 additions & 0 deletions
3
src/modules/master-data/v2/apis/schemas/requests/SaveSchemaByNameRequest.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export interface SaveSchemaByNameRequest { | ||
properties?: any; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './Scroll'; |
Oops, something went wrong.