Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions vtex/actions/masterdata/createDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { CreateNewDocument } from "../../utils/types.ts";
export interface Props {
data: Record<string, unknown>;
acronym: string;
schema?: string;
isPrivateEntity?: boolean;
}

Expand All @@ -20,7 +21,7 @@ const action = async (
/* no-explicit-any */
): Promise<CreateNewDocument> => {
const { vcs, vcsDeprecated } = ctx;
const { data, acronym, isPrivateEntity } = props;
const { data, acronym, isPrivateEntity, schema } = props;
const { cookie } = parseCookie(req.headers, ctx.account);

const requestOptions = {
Expand All @@ -35,11 +36,11 @@ const action = async (
const response =
await (isPrivateEntity
? vcs[`POST /api/dataentities/:acronym/documents`](
{ acronym },
schema ? { acronym, _schema: schema } : { acronym },
requestOptions,
)
: vcsDeprecated[`POST /api/dataentities/:acronym/documents`](
{ acronym },
schema ? { acronym, _schema: schema } : { acronym },
requestOptions,
));

Expand Down
7 changes: 4 additions & 3 deletions vtex/actions/masterdata/updateDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface Props {
acronym: string;
data: Record<string, unknown>;
createIfNotExists?: boolean;
schema?: string;
}

/**
Expand All @@ -24,7 +25,7 @@ const action = async (
ctx: AppContext,
): Promise<unknown | IdHrefDocumentID> => {
const { vcs } = ctx;
const { id, data, acronym, createIfNotExists } = props;
const { id, data, acronym, createIfNotExists, schema } = props;
const { cookie } = parseCookie(req.headers, ctx.account);

const requestOptions = {
Expand All @@ -39,11 +40,11 @@ const action = async (
const response =
await (createIfNotExists
? vcs["PATCH /api/dataentities/:acronym/documents"](
{ acronym },
schema ? { acronym, _schema: schema } : { acronym },
requestOptions,
)
: vcs["PATCH /api/dataentities/:acronym/documents/:id"](
{ acronym, id },
schema ? { acronym, id, _schema: schema } : { acronym, id },
requestOptions,
));

Expand Down
7 changes: 6 additions & 1 deletion vtex/loaders/masterdata/searchDocuments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ interface Props {
* @description Specification of filters.
*/
where?: string;
/**
* @description Schema of the data entity.
*/
schema?: string;
/**
* @description Inform a field name plus ASC to sort results by this field value in ascending order or DESC to sort by descending order.
*/
Expand Down Expand Up @@ -47,7 +51,7 @@ export default async function loader(
ctx: AppContext,
): Promise<Document[]> {
const { vcs } = ctx;
const { acronym, fields, where, sort, skip = 0, take = 10 } = props;
const { acronym, fields, where, sort, skip = 0, take = 10, schema } = props;
const { cookie } = parseCookie(req.headers, ctx.account);
const limits = resourceRange(skip, take);

Expand All @@ -56,6 +60,7 @@ export default async function loader(
_fields: fields,
_where: where,
_sort: sort,
_schema: schema,
}, {
headers: {
accept: "application/vnd.vtex.ds.v10+json",
Expand Down
3 changes: 3 additions & 0 deletions vtex/utils/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@ export interface VTEXCommerceStable {
};
};
"POST /api/dataentities/:acronym/documents": {
searchParams: {
_schema?: string;
};
response: CreateNewDocument;
body: Record<string, unknown>;
};
Expand Down
39 changes: 38 additions & 1 deletion vtex/utils/openapi/vcs.openapi.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,10 @@ searchParams: {
* Names of the fields that will be returned per document, separated by a comma `,`. It is possible to fetch all fields using `_all` as the value of this query parameter. However, in order to avoid permission errors, we strongly recommend informing only the names of the exact fields that will be used.
*/
_fields?: string
/**
* Name of the [schema](https://developers.vtex.com/docs/guides/master-data-schema-lifecycle) that the document complies with. This field is required when using `_where` or `_fields` query parameters.
*/
_schema?: string
/**
* Specification of filters.
*/
Expand Down Expand Up @@ -861,6 +865,12 @@ to?: number
* Create a new document
*/
"POST /api/dataentities/:acronym/documents": {
searchParams: {
/**
* Name of the [schema](https://developers.vtex.com/docs/guides/master-data-schema-lifecycle) that the document complies with. This field is required when using `_where` or `_fields` query parameters.
*/
_schema?: string
}
body: {
anyProperty?: string
}
Expand Down Expand Up @@ -890,6 +900,12 @@ DocumentId?: string
* >❗ To prevent integrations from having excessive permissions, consider the [best practices for managing app keys](https://help.vtex.com/en/tutorial/best-practices-application-keys--7b6nD1VMHa49aI5brlOvJm) when assigning License Manager roles to integrations.
*/
"PATCH /api/dataentities/:acronym/documents": {
searchParams: {
/**
* Name of the [schema](https://developers.vtex.com/docs/guides/master-data-schema-lifecycle) that the document complies with. This field is required when using `_where` or `_fields` query parameters.
*/
_schema?: string
}
body: {
/**
* Unique identifier of the document to be created.
Expand Down Expand Up @@ -927,6 +943,10 @@ searchParams: {
* Names of the fields that will be returned per document, separated by a comma `,`. It is possible to fetch all fields using `_all` as the value of this query parameter. However, in order to avoid permission errors, we strongly recommend informing only the names of the exact fields that will be used.
*/
_fields?: string
/**
* Name of the [schema](https://developers.vtex.com/docs/guides/master-data-schema-lifecycle) that the document complies with. This field is required when using `_where` or `_fields` query parameters.
*/
_schema?: string
}
response: Document
}
Expand Down Expand Up @@ -975,6 +995,12 @@ response: Document
* >❗ To prevent integrations from having excessive permissions, consider the [best practices for managing app keys](https://help.vtex.com/en/tutorial/best-practices-application-keys--7b6nD1VMHa49aI5brlOvJm) when assigning License Manager roles to integrations.
*/
"PUT /api/dataentities/:acronym/documents/:id": {
searchParams: {
/**
* Name of the [schema](https://developers.vtex.com/docs/guides/master-data-schema-lifecycle) that the document complies with. This field is required when using `_where` or `_fields` query parameters.
*/
_schema?: string
}
/**
* Object with document fields and their respective values.
*/
Expand Down Expand Up @@ -1003,7 +1029,12 @@ body: {
* >❗ To prevent integrations from having excessive permissions, consider the [best practices for managing app keys](https://help.vtex.com/en/tutorial/best-practices-application-keys--7b6nD1VMHa49aI5brlOvJm) when assigning License Manager roles to integrations.
*/
"DELETE /api/dataentities/:acronym/documents/:id": {

searchParams: {
/**
* Name of the [schema](https://developers.vtex.com/docs/guides/master-data-schema-lifecycle) that the document complies with. This field is required when using `_where` or `_fields` query parameters.
*/
_schema?: string
}
}
/**
* Updates a subset of fields of a document, without impacting the other fields.
Expand All @@ -1025,6 +1056,12 @@ body: {
* >❗ To prevent integrations from having excessive permissions, consider the [best practices for managing app keys](https://help.vtex.com/en/tutorial/best-practices-application-keys--7b6nD1VMHa49aI5brlOvJm) when assigning License Manager roles to integrations.
*/
"PATCH /api/dataentities/:acronym/documents/:id": {
searchParams: {
/**
* Name of the [schema](https://developers.vtex.com/docs/guides/master-data-schema-lifecycle) that the document complies with. This field is required when using `_where` or `_fields` query parameters.
*/
_schema?: string
}
/**
* Object with the fields to be updated and their respective values.
*/
Expand Down
37 changes: 37 additions & 0 deletions vtex/utils/openapi/vcs.openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,17 @@
"example": "email,firstName,document"
}
},
{
"name": "_schema",
"in": "query",
"description": "Name of the [schema](https://developers.vtex.com/docs/guides/master-data-schema-lifecycle) that the document complies with. This field is required when using `_where` or `_fields` query parameters.",
"required": false,
"style": "form",
"schema": {
"type": "string",
"example": "schema"
}
},
{
"name": "_where",
"in": "query",
Expand Down Expand Up @@ -1557,6 +1568,17 @@
"schema": {
"type": "string"
}
},
{
"name": "_schema",
"in": "query",
"description": "Name of the [schema](https://developers.vtex.com/docs/guides/master-data-schema-lifecycle) that the document complies with. This field is required when using `_where` or `_fields` query parameters.",
"required": false,
"style": "form",
"schema": {
"type": "string",
"example": "schema"
}
}
],
"requestBody": {
Expand Down Expand Up @@ -1614,6 +1636,9 @@
},
{
"$ref": "#/components/parameters/acronym"
},
{
"$ref": "#/components/parameters/_schema"
}
],
"requestBody": {
Expand Down Expand Up @@ -1685,6 +1710,9 @@
},
{
"$ref": "#/components/parameters/fields"
},
{
"$ref": "#/components/parameters/_schema"
}
],
"responses": {
Expand Down Expand Up @@ -1745,6 +1773,9 @@
},
{
"$ref": "#/components/parameters/id"
},
{
"$ref": "#/components/parameters/_schema"
}
],
"requestBody": {
Expand Down Expand Up @@ -1810,6 +1841,9 @@
},
{
"$ref": "#/components/parameters/id"
},
{
"$ref": "#/components/parameters/_schema"
}
],
"requestBody": {
Expand Down Expand Up @@ -1851,6 +1885,9 @@
},
{
"$ref": "#/components/parameters/id"
},
{
"$ref": "#/components/parameters/_schema"
}
],
"responses": {
Expand Down
Loading