From c779bcc3561bc90fc109308e8121b8f03c9b6f56 Mon Sep 17 00:00:00 2001 From: "@yuri_assuncx" Date: Mon, 28 Oct 2024 13:52:04 -0300 Subject: [PATCH] [VTEX] Feat: add new types and cancel order action (#945) --- vtex/actions/orders/cancel.ts | 43 +++++++++++++++++++++++++++++++++++ vtex/manifest.gen.ts | 34 ++++++++++++++------------- vtex/utils/client.ts | 7 ++++++ vtex/utils/types.ts | 27 ++++++++++++++++++++++ 4 files changed, 95 insertions(+), 16 deletions(-) create mode 100644 vtex/actions/orders/cancel.ts diff --git a/vtex/actions/orders/cancel.ts b/vtex/actions/orders/cancel.ts new file mode 100644 index 000000000..c6dfa38d1 --- /dev/null +++ b/vtex/actions/orders/cancel.ts @@ -0,0 +1,43 @@ +import { parseCookie } from "../../utils/vtexId.ts"; +import { AppContext } from "../../mod.ts"; +import { CanceledOrder } from "../../utils/types.ts"; + +interface Props { + orderId: string; + reason: string; +} + +async function action( + props: Props, + req: Request, + ctx: AppContext, +): Promise { + const { vcsDeprecated } = ctx; + const { cookie, payload } = parseCookie(req.headers, ctx.account); + + if (!payload?.sub || !payload?.userId) { + return null; + } + + const { orderId, reason } = props; + + const response = await vcsDeprecated + ["POST /api/oms/user/orders/:orderId/cancel"]( + { orderId }, + { + body: { reason }, + headers: { + cookie, + }, + }, + ); + + if (response.ok) { + const canceledOrder = await response.json(); + return canceledOrder; + } + + return null; +} + +export default action; diff --git a/vtex/manifest.gen.ts b/vtex/manifest.gen.ts index 3131df2c0..f53cdd0c5 100644 --- a/vtex/manifest.gen.ts +++ b/vtex/manifest.gen.ts @@ -25,14 +25,15 @@ import * as $$$$$$$$$19 from "./actions/cart/updateUser.ts"; import * as $$$$$$$$$20 from "./actions/masterdata/createDocument.ts"; import * as $$$$$$$$$21 from "./actions/newsletter/subscribe.ts"; import * as $$$$$$$$$22 from "./actions/notifyme.ts"; -import * as $$$$$$$$$23 from "./actions/payments/delete.ts"; -import * as $$$$$$$$$24 from "./actions/profile/newsletterProfile.ts"; -import * as $$$$$$$$$25 from "./actions/profile/updateProfile.ts"; -import * as $$$$$$$$$26 from "./actions/review/submit.ts"; -import * as $$$$$$$$$27 from "./actions/sessions/delete.ts"; -import * as $$$$$$$$$28 from "./actions/trigger.ts"; -import * as $$$$$$$$$29 from "./actions/wishlist/addItem.ts"; -import * as $$$$$$$$$30 from "./actions/wishlist/removeItem.ts"; +import * as $$$$$$$$$23 from "./actions/orders/cancel.ts"; +import * as $$$$$$$$$24 from "./actions/payments/delete.ts"; +import * as $$$$$$$$$25 from "./actions/profile/newsletterProfile.ts"; +import * as $$$$$$$$$26 from "./actions/profile/updateProfile.ts"; +import * as $$$$$$$$$27 from "./actions/review/submit.ts"; +import * as $$$$$$$$$28 from "./actions/sessions/delete.ts"; +import * as $$$$$$$$$29 from "./actions/trigger.ts"; +import * as $$$$$$$$$30 from "./actions/wishlist/addItem.ts"; +import * as $$$$$$$$$31 from "./actions/wishlist/removeItem.ts"; import * as $$$$0 from "./handlers/sitemap.ts"; import * as $$$0 from "./loaders/address/getAddressByZIP.ts"; import * as $$$1 from "./loaders/address/list.ts"; @@ -159,14 +160,15 @@ const manifest = { "vtex/actions/masterdata/createDocument.ts": $$$$$$$$$20, "vtex/actions/newsletter/subscribe.ts": $$$$$$$$$21, "vtex/actions/notifyme.ts": $$$$$$$$$22, - "vtex/actions/payments/delete.ts": $$$$$$$$$23, - "vtex/actions/profile/newsletterProfile.ts": $$$$$$$$$24, - "vtex/actions/profile/updateProfile.ts": $$$$$$$$$25, - "vtex/actions/review/submit.ts": $$$$$$$$$26, - "vtex/actions/sessions/delete.ts": $$$$$$$$$27, - "vtex/actions/trigger.ts": $$$$$$$$$28, - "vtex/actions/wishlist/addItem.ts": $$$$$$$$$29, - "vtex/actions/wishlist/removeItem.ts": $$$$$$$$$30, + "vtex/actions/orders/cancel.ts": $$$$$$$$$23, + "vtex/actions/payments/delete.ts": $$$$$$$$$24, + "vtex/actions/profile/newsletterProfile.ts": $$$$$$$$$25, + "vtex/actions/profile/updateProfile.ts": $$$$$$$$$26, + "vtex/actions/review/submit.ts": $$$$$$$$$27, + "vtex/actions/sessions/delete.ts": $$$$$$$$$28, + "vtex/actions/trigger.ts": $$$$$$$$$29, + "vtex/actions/wishlist/addItem.ts": $$$$$$$$$30, + "vtex/actions/wishlist/removeItem.ts": $$$$$$$$$31, }, "workflows": { "vtex/workflows/events.ts": $$$$$$$$$$0, diff --git a/vtex/utils/client.ts b/vtex/utils/client.ts index 6794f41e7..0f1feb091 100644 --- a/vtex/utils/client.ts +++ b/vtex/utils/client.ts @@ -1,6 +1,7 @@ import { Userorderslist } from "./openapi/vcs.openapi.gen.ts"; import { Brand, + CanceledOrder, Category, CreateNewDocument, FacetSearchResult, @@ -252,6 +253,12 @@ export interface VTEXCommerceStable { "GET /api/oms/user/orders/:orderId": { response: OrderItem; }; + "POST /api/oms/user/orders/:orderId/cancel": { + response: CanceledOrder; + body: { + reason: string; + }; + }; } export interface SP { diff --git a/vtex/utils/types.ts b/vtex/utils/types.ts index 5721144a3..5ccebbf57 100644 --- a/vtex/utils/types.ts +++ b/vtex/utils/types.ts @@ -1360,6 +1360,24 @@ export interface Order { workflowInRetry: boolean; } +export interface Package { + cfop: string | null; + invoiceNumber: string; + invoiceValue: number; + invoiceUrl: string | null; + issuanceDate: string; + trackingNumber: string | null; + invoiceKey: string; + trackingUrl: string | null; + embeddedInvoice: string; + courierStatus: { + status: string | null; + finished: boolean; + deliveredDate: string; + }; + type: "Input" | "Output"; +} + export interface OrderItem { orderId: string; sequence: string; @@ -1377,6 +1395,9 @@ export interface OrderItem { authorizedDate: string; callCenterOperatorData: string; cancelReason: string; + packageAttachment: { + packages: Package[]; + } | null; cancellationData: { RequestedByUser: boolean; RequestedBySystem: boolean; @@ -1431,6 +1452,12 @@ export interface OrderItem { openTextField: string | null; } +export interface CanceledOrder { + date: string; + orderId: string; + receipt: string | null; +} + interface Marketplace { baseURL: string; // deno-lint-ignore no-explicit-any