Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat(VTEX): Implement masterdata update document API #1002

Merged
merged 1 commit into from
Feb 18, 2025
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
56 changes: 56 additions & 0 deletions vtex/actions/masterdata/updateDocument.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { AppContext } from "../../mod.ts";
import type { IdHrefDocumentID } from "../../utils/openapi/vcs.openapi.gen.ts";
import { parseCookie } from "../../utils/vtexId.ts";

export interface Props {
/**
* Unique identifier of the document to be created.
*/
id: string;
acronym: string;
data: Record<string, unknown>;
createIfNotExists?: boolean;
}

/**
* @docs https://developers.vtex.com/docs/api-reference/masterdata-api#patch-/api/dataentities/-acronym-/documents?endpoint=patch-/api/dataentities/-acronym-/documents
* @docs https://developers.vtex.com/docs/api-reference/masterdata-api#patch-/api/dataentities/-acronym-/documents/-id-?endpoint=patch-/api/dataentities/-acronym-/documents/-id-
*/
const action = async (
props: Props,
req: Request,
ctx: AppContext,
): Promise<unknown | IdHrefDocumentID> => {
const { vcs } = ctx;
const { id, data, acronym, createIfNotExists } = props;
const { cookie } = parseCookie(req.headers, ctx.account);

const requestOptions = {
body: createIfNotExists ? { ...data, id } : data,
headers: {
accept: "application/json",
"content-type": "application/json",
cookie,
},
};

const response =
await (createIfNotExists
? vcs["PATCH /api/dataentities/:acronym/documents"](
{ acronym },
requestOptions,
)
: vcs["PATCH /api/dataentities/:acronym/documents/:id"](
{ acronym, id },
requestOptions,
));

if (response.headers.get("content-type")?.includes("application/json")) {
return response.json();
}

return;
};

export const defaultVisibility = "private";
export default action;
26 changes: 14 additions & 12 deletions vtex/manifest.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ import * as $$$$$$$$$14 from "./actions/cart/updateItems.ts";
import * as $$$$$$$$$15 from "./actions/cart/updateProfile.ts";
import * as $$$$$$$$$16 from "./actions/cart/updateUser.ts";
import * as $$$$$$$$$17 from "./actions/masterdata/createDocument.ts";
import * as $$$$$$$$$18 from "./actions/newsletter/subscribe.ts";
import * as $$$$$$$$$19 from "./actions/notifyme.ts";
import * as $$$$$$$$$20 from "./actions/review/submit.ts";
import * as $$$$$$$$$21 from "./actions/trigger.ts";
import * as $$$$$$$$$22 from "./actions/wishlist/addItem.ts";
import * as $$$$$$$$$23 from "./actions/wishlist/removeItem.ts";
import * as $$$$$$$$$18 from "./actions/masterdata/updateDocument.ts";
import * as $$$$$$$$$19 from "./actions/newsletter/subscribe.ts";
import * as $$$$$$$$$20 from "./actions/notifyme.ts";
import * as $$$$$$$$$21 from "./actions/review/submit.ts";
import * as $$$$$$$$$22 from "./actions/trigger.ts";
import * as $$$$$$$$$23 from "./actions/wishlist/addItem.ts";
import * as $$$$$$$$$24 from "./actions/wishlist/removeItem.ts";
import * as $$$$0 from "./handlers/sitemap.ts";
import * as $$$0 from "./loaders/cart.ts";
import * as $$$1 from "./loaders/categories/tree.ts";
Expand Down Expand Up @@ -139,12 +140,13 @@ const manifest = {
"vtex/actions/cart/updateProfile.ts": $$$$$$$$$15,
"vtex/actions/cart/updateUser.ts": $$$$$$$$$16,
"vtex/actions/masterdata/createDocument.ts": $$$$$$$$$17,
"vtex/actions/newsletter/subscribe.ts": $$$$$$$$$18,
"vtex/actions/notifyme.ts": $$$$$$$$$19,
"vtex/actions/review/submit.ts": $$$$$$$$$20,
"vtex/actions/trigger.ts": $$$$$$$$$21,
"vtex/actions/wishlist/addItem.ts": $$$$$$$$$22,
"vtex/actions/wishlist/removeItem.ts": $$$$$$$$$23,
"vtex/actions/masterdata/updateDocument.ts": $$$$$$$$$18,
"vtex/actions/newsletter/subscribe.ts": $$$$$$$$$19,
"vtex/actions/notifyme.ts": $$$$$$$$$20,
"vtex/actions/review/submit.ts": $$$$$$$$$21,
"vtex/actions/trigger.ts": $$$$$$$$$22,
"vtex/actions/wishlist/addItem.ts": $$$$$$$$$23,
"vtex/actions/wishlist/removeItem.ts": $$$$$$$$$24,
},
"workflows": {
"vtex/workflows/events.ts": $$$$$$$$$$0,
Expand Down
204 changes: 204 additions & 0 deletions vtex/utils/openapi/vcs.openapi.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,168 @@ response: {
Id?: string
Href?: string
DocumentId?: string
}
}
/**
* Creates a partial document, sending only some of the fields.
*
* > You can use this request to create documents in any given data entity. Because of this, you are not restricted to using the fields exemplified below in your requests. But you should be aware of the fields allowed or required for each document you wish to update.
*
* ## Permissions
*
* Any user or [application key](https://developers.vtex.com/docs/guides/api-authentication-using-application-keys) must have at least one of the appropriate [License Manager resources](https://help.vtex.com/en/tutorial/license-manager-resources--3q6ztrC8YynQf6rdc6euk3) to be able to successfully run this request. Otherwise they will receive a status code `403` error. These are the applicable resources for this endpoint:
*
* | **Product** | **Category** | **Resource** |
* | --------------- | ----------------- | ----------------- |
* | Dynamic Storage | Dynamic storage generic resources | **Insert or update document (not remove)** |
* | Dynamic Storage | Dynamic storage generic resources | **Full access to all documents** |
* | Dynamic Storage | Dynamic storage generic resources | **Master Data administrator** |
*
* There are no applicable [predefined roles](https://help.vtex.com/en/tutorial/predefined-roles--jGDurZKJHvHJS13LnO7Dy) for this resource list. You must [create a custom role](https://help.vtex.com/en/tutorial/roles--7HKK5Uau2H6wxE1rH5oRbc#creating-a-role) and add at least one of the resources above in order to use this endpoint.To learn more about machine authentication at VTEX, see [Authentication overview](https://developers.vtex.com/docs/guides/authentication).
*
* >❗ 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": {
body: {
/**
* Unique identifier of the document to be created.
*/
id?: string
/**
* Field(s) to be filled in and its respective value(s).
*/
"{fieldName}"?: string
[k: string]: any
}
response: IdHrefDocumentID
}
/**
* Retrieves a document.
*
* ## Permissions
*
* Any user or [application key](https://developers.vtex.com/docs/guides/api-authentication-using-application-keys) must have at least one of the appropriate [License Manager resources](https://help.vtex.com/en/tutorial/license-manager-resources--3q6ztrC8YynQf6rdc6euk3) to be able to successfully run this request. Otherwise they will receive a status code `403` error. These are the applicable resources for this endpoint:
*
* | **Product** | **Category** | **Resource** |
* | --------------- | ----------------- | ----------------- |
* | Dynamic Storage | Dynamic storage generic resources | **Read only documents** |
* | Dynamic Storage | Dynamic storage generic resources | **Insert or update document (not remove)** |
* | Dynamic Storage | Dynamic storage generic resources | **Full access to all documents** |
* | Dynamic Storage | Dynamic storage generic resources | **Master Data administrator** |
*
* There are no applicable [predefined roles](https://help.vtex.com/en/tutorial/predefined-roles--jGDurZKJHvHJS13LnO7Dy) for this resource list. You must [create a custom role](https://help.vtex.com/en/tutorial/roles--7HKK5Uau2H6wxE1rH5oRbc#creating-a-role) and add at least one of the resources above in order to use this endpoint.To learn more about machine authentication at VTEX, see [Authentication overview](https://developers.vtex.com/docs/guides/authentication).
*
* >❗ 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.
*/
"GET /api/dataentities/:acronym/documents/:id": {
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
}
response: Document
}
/**
* Creates a new document with a custom ID, or updates an entire document if there is already a document with the informed ID.
*
* >ℹ️ You can use this request to create or update documents in any given data entity. Because of this, you are not restricted to using the fields exemplified below in your requests. But you should be aware of the fields allowed or required for each document you wish to update.
*
* ## Custom field types
*
* The table below presents the types of custom fields you can use when creating or updating documents in Master Data v1 and example values.
*
* | Field Type| Example value |
* | - | - |
* | Boolean | `true` |
* | Currency | `2.5` |
* | Date | `1992-11-17` |
* | Date_Time | `2016-09-14T19:21:01.3163733Z` |
* | Decimal | `2.5` |
* | Email | `meu@email.com` |
* | Integer | `1000000` |
* | Long | `1000000000` |
* | Percent | `85.42` |
* | Time | `23:50` |
* | URL | `https://www.vtex.com` |
* | Varchar10 | `Lorem ipsu` |
* | Varchar50 | `Lorem ipsum dolor sit amet, consectetur adipiscing` |
* | Varchar750 | `Lorem ipsum dolor sit amet, consectetur adipiscing elit...` |
* | Varchar100 | `Lorem ipsum dolor sit amet, consectetur adipiscing elit...` |
* | Relationship | `5eb31afb-7ab0-11e6-94b4-0a44686e393f` |
* | Text | `Lorem ipsum dolor sit amet, consectetur adipiscing elit...` |
*
*
* ## Permissions
*
* Any user or [application key](https://developers.vtex.com/docs/guides/api-authentication-using-application-keys) must have at least one of the appropriate [License Manager resources](https://help.vtex.com/en/tutorial/license-manager-resources--3q6ztrC8YynQf6rdc6euk3) to be able to successfully run this request. Otherwise they will receive a status code `403` error. These are the applicable resources for this endpoint:
*
* | **Product** | **Category** | **Resource** |
* | --------------- | ----------------- | ----------------- |
* | Dynamic Storage | Dynamic storage generic resources | **Insert or update document (not remove)** |
* | Dynamic Storage | Dynamic storage generic resources | **Full access to all documents** |
* | Dynamic Storage | Dynamic storage generic resources | **Master Data administrator** |
*
* There are no applicable [predefined roles](https://help.vtex.com/en/tutorial/predefined-roles--jGDurZKJHvHJS13LnO7Dy) for this resource list. You must [create a custom role](https://help.vtex.com/en/tutorial/roles--7HKK5Uau2H6wxE1rH5oRbc#creating-a-role) and add at least one of the resources above in order to use this endpoint.To learn more about machine authentication at VTEX, see [Authentication overview](https://developers.vtex.com/docs/guides/authentication).
*
* >❗ 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": {
/**
* Object with document fields and their respective values.
*/
body: {
/**
* Field name and value.
*/
"{fieldName}"?: string
[k: string]: any
}
}
/**
* Deletes a document.
*
* ## Permissions
*
* Any user or [application key](https://developers.vtex.com/docs/guides/api-authentication-using-application-keys) must have at least one of the appropriate [License Manager resources](https://help.vtex.com/en/tutorial/license-manager-resources--3q6ztrC8YynQf6rdc6euk3) to be able to successfully run this request. Otherwise they will receive a status code `403` error. These are the applicable resources for this endpoint:
*
* | **Product** | **Category** | **Resource** |
* | --------------- | ----------------- | ----------------- |
* | Dynamic Storage | Dynamic storage generic resources | **Full access to all documents** |
* | Dynamic Storage | Dynamic storage generic resources | **Master Data administrator** |
*
* There are no applicable [predefined roles](https://help.vtex.com/en/tutorial/predefined-roles--jGDurZKJHvHJS13LnO7Dy) for this resource list. You must [create a custom role](https://help.vtex.com/en/tutorial/roles--7HKK5Uau2H6wxE1rH5oRbc#creating-a-role) and add at least one of the resources above in order to use this endpoint.To learn more about machine authentication at VTEX, see [Authentication overview](https://developers.vtex.com/docs/guides/authentication).
*
* >❗ 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": {

}
/**
* Updates a subset of fields of a document, without impacting the other fields.
*
* >ℹ️ You can use this request to update documents in any given data entity. Because of this, you are not restricted to using the fields exemplified below in your requests. But you should be aware of the fields allowed or required for each document you wish to update.
*
* ## Permissions
*
* Any user or [application key](https://developers.vtex.com/docs/guides/api-authentication-using-application-keys) must have at least one of the appropriate [License Manager resources](https://help.vtex.com/en/tutorial/license-manager-resources--3q6ztrC8YynQf6rdc6euk3) to be able to successfully run this request. Otherwise they will receive a status code `403` error. These are the applicable resources for this endpoint:
*
* | **Product** | **Category** | **Resource** |
* | --------------- | ----------------- | ----------------- |
* | Dynamic Storage | Dynamic storage generic resources | **Insert or update document (not remove)** |
* | Dynamic Storage | Dynamic storage generic resources | **Full access to all documents** |
* | Dynamic Storage | Dynamic storage generic resources | **Master Data administrator** |
*
* There are no applicable [predefined roles](https://help.vtex.com/en/tutorial/predefined-roles--jGDurZKJHvHJS13LnO7Dy) for this resource list. You must [create a custom role](https://help.vtex.com/en/tutorial/roles--7HKK5Uau2H6wxE1rH5oRbc#creating-a-role) and add at least one of the resources above in order to use this endpoint.To learn more about machine authentication at VTEX, see [Authentication overview](https://developers.vtex.com/docs/guides/authentication).
*
* >❗ 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": {
/**
* Object with the fields to be updated and their respective values.
*/
body: {

}
}
/**
Expand Down Expand Up @@ -19539,6 +19701,48 @@ parentAccountName?: string
*/
originalId?: string
}
/**
* Document information.
*/
export interface IdHrefDocumentID {
/**
* ID of the document that was created, with data entity prefix.
*/
Id?: string
/**
* Document reference URL.
*/
Href?: string
/**
* Unique identifier of the document.
*/
DocumentId?: string
}
/**
* Object representing each document.
*/
export interface Document {
/**
* Custom property.
*/
"{customProperty}"?: string
/**
* Unique identifier of the document.
*/
id: string
/**
* Unique identifier of the account.
*/
accountId: string
/**
* Account name.
*/
accountName: string
/**
* Two-letter string that identifies the data entity.
*/
dataEntityId: string
}
export interface GetorUpdateProductSpecification {
/**
* Array with Specification values.
Expand Down
Loading
Loading