From 518d3167f8cf86a68a9a8d4cf1612b9b7aec835e Mon Sep 17 00:00:00 2001 From: soutofernando Date: Tue, 24 Sep 2024 21:15:51 -0300 Subject: [PATCH 01/22] feat: make it possible to exclude routes from being proxied in vtex --- vtex/loaders/proxy.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/vtex/loaders/proxy.ts b/vtex/loaders/proxy.ts index f1466d502..916fe5f27 100644 --- a/vtex/loaders/proxy.ts +++ b/vtex/loaders/proxy.ts @@ -27,6 +27,7 @@ const buildProxyRoutes = ( includeSiteMap, generateDecoSiteMap, excludePathsFromDecoSiteMap, + excludePathsFromVtexProxy, includeScriptsToHead, includeScriptsToBody, }: { @@ -35,6 +36,7 @@ const buildProxyRoutes = ( includeSiteMap?: string[]; generateDecoSiteMap?: boolean; excludePathsFromDecoSiteMap: string[]; + excludePathsFromVtexProxy?: string[]; includeScriptsToHead?: { includes?: Script[]; }; @@ -96,7 +98,10 @@ const buildProxyRoutes = ( }, }); }; - const routesFromPaths = [...PATHS_TO_PROXY, ...extraPaths].map( + const currentPathsToProxy = PATHS_TO_PROXY.filter((path) => + !excludePathsFromVtexProxy?.includes(path) + ); + const routesFromPaths = [...currentPathsToProxy, ...extraPaths].map( routeFromPath, ); @@ -154,6 +159,10 @@ export interface Props { * @title Exclude paths from /deco-sitemap.xml */ excludePathsFromDecoSiteMap?: string[]; + /** + * @title Exclude paths from VTEX PATHS_TO_PROXY + */ + excludePathsFromVtexProxy?: string[]; /** * @title Scripts to include on Html head */ @@ -177,6 +186,7 @@ function loader( includeSiteMap = [], generateDecoSiteMap = true, excludePathsFromDecoSiteMap = [], + excludePathsFromVtexProxy = [], includeScriptsToHead = { includes: [] }, includeScriptsToBody = { includes: [] }, }: Props, @@ -186,6 +196,7 @@ function loader( return buildProxyRoutes({ generateDecoSiteMap, excludePathsFromDecoSiteMap, + excludePathsFromVtexProxy, includeSiteMap, publicUrl: ctx.publicUrl, extraPaths: extraPathsToProxy, From 4c4daee7eb037615e0002a54462ad7e4cd863c95 Mon Sep 17 00:00:00 2001 From: vitoUwu Date: Thu, 26 Sep 2024 09:27:36 -0400 Subject: [PATCH 02/22] feat: add session loaders --- vtex/actions/sessions/delete.ts | 39 +++++++++++++++++++ vtex/loaders/sessions/info.ts | 68 +++++++++++++++++++++++++++++++++ vtex/manifest.gen.ts | 32 +++++++++------- 3 files changed, 125 insertions(+), 14 deletions(-) create mode 100644 vtex/actions/sessions/delete.ts create mode 100644 vtex/loaders/sessions/info.ts diff --git a/vtex/actions/sessions/delete.ts b/vtex/actions/sessions/delete.ts new file mode 100644 index 000000000..e55b77e31 --- /dev/null +++ b/vtex/actions/sessions/delete.ts @@ -0,0 +1,39 @@ +import { AppContext } from "../../mod.ts"; +import { parseCookie } from "../../utils/vtexId.ts"; + +export interface DeleteSession { + logOutFromSession: string; +} + +interface Props { + sessionId: string; +} + +async function loader( + { sessionId }: Props, + req: Request, + ctx: AppContext, +): Promise { + const { io } = ctx; + const { cookie, payload } = parseCookie(req.headers, ctx.account); + + if (!payload?.sub || !payload?.userId) { + return null; + } + + const mutation = `mutation LogOutFromSession($sessionId: ID) { + logOutFromSession(sessionId: $sessionId) @context(provider: "vtex.store-graphql@2.x") + }`; + + try { + return await io.query({ + query: mutation, + variables: { sessionId }, + }, { headers: { cookie } }); + } catch (e) { + console.error(e); + return null; + } +} + +export default loader; diff --git a/vtex/loaders/sessions/info.ts b/vtex/loaders/sessions/info.ts new file mode 100644 index 000000000..1739fd41c --- /dev/null +++ b/vtex/loaders/sessions/info.ts @@ -0,0 +1,68 @@ +import { AppContext } from "../../mod.ts"; +import { parseCookie } from "../../utils/vtexId.ts"; + +export interface LoginSessionInfo { + currentLoginSessionId: string; + loginSessions: LoginSession[]; +} + +export interface LoginSession { + id: string; + cacheId: string; + deviceType: string; + lastAccess: string; + city: string; + fullAddress: string; + ip: string; + browser: string; + os: string; + firstAccess: string; +} + +async function loader( + _props: unknown, + req: Request, + ctx: AppContext, +): Promise { + const { io } = ctx; + const { cookie, payload } = parseCookie(req.headers, ctx.account); + + if (!payload?.sub || !payload?.userId) { + return null; + } + + const query = `query getUserSessions { + loginSessionsInfo { + currentLoginSessionId + loginSessions { + id + cacheId + deviceType + lastAccess + city + fullAddress + ip + browser + os + firstAccess + } + } + }`; + + try { + const data = await io.query< + { loginSessionsInfo: LoginSessionInfo }, + null + >( + { query }, + { headers: { cookie } }, + ); + + return data.loginSessionsInfo; + } catch (e) { + console.error(e); + return null; + } +} + +export default loader; diff --git a/vtex/manifest.gen.ts b/vtex/manifest.gen.ts index a0f0c0ca2..ce1452cdb 100644 --- a/vtex/manifest.gen.ts +++ b/vtex/manifest.gen.ts @@ -23,9 +23,10 @@ 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 $$$$$$$$$21 from "./actions/sessions/delete.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"; @@ -59,10 +60,11 @@ import * as $$$28 from "./loaders/product/extensions/listingPage.ts"; import * as $$$29 from "./loaders/product/extensions/suggestions.ts"; import * as $$$30 from "./loaders/product/wishlist.ts"; import * as $$$31 from "./loaders/proxy.ts"; -import * as $$$32 from "./loaders/user.ts"; -import * as $$$33 from "./loaders/wishlist.ts"; -import * as $$$34 from "./loaders/workflow/product.ts"; -import * as $$$35 from "./loaders/workflow/products.ts"; +import * as $$$32 from "./loaders/sessions/info.ts"; +import * as $$$33 from "./loaders/user.ts"; +import * as $$$34 from "./loaders/wishlist.ts"; +import * as $$$35 from "./loaders/workflow/product.ts"; +import * as $$$36 from "./loaders/workflow/products.ts"; import * as $$$$$$0 from "./sections/Analytics/Vtex.tsx"; import * as $$$$$$$$$$0 from "./workflows/events.ts"; import * as $$$$$$$$$$1 from "./workflows/product/index.ts"; @@ -101,10 +103,11 @@ const manifest = { "vtex/loaders/product/extensions/suggestions.ts": $$$29, "vtex/loaders/product/wishlist.ts": $$$30, "vtex/loaders/proxy.ts": $$$31, - "vtex/loaders/user.ts": $$$32, - "vtex/loaders/wishlist.ts": $$$33, - "vtex/loaders/workflow/product.ts": $$$34, - "vtex/loaders/workflow/products.ts": $$$35, + "vtex/loaders/sessions/info.ts": $$$32, + "vtex/loaders/user.ts": $$$33, + "vtex/loaders/wishlist.ts": $$$34, + "vtex/loaders/workflow/product.ts": $$$35, + "vtex/loaders/workflow/products.ts": $$$36, }, "handlers": { "vtex/handlers/sitemap.ts": $$$$0, @@ -134,9 +137,10 @@ const manifest = { "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/sessions/delete.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, From 4d14fd985f1b62af41c75a02920a232cc2f84846 Mon Sep 17 00:00:00 2001 From: vitoUwu Date: Thu, 3 Oct 2024 14:49:32 -0400 Subject: [PATCH 03/22] feat: some payments related loaders --- vtex/actions/payments/delete.ts | 39 ++++++++++++++ vtex/loaders/payments/info.ts | 55 ++++++++++++++++++++ vtex/loaders/payments/userPayments.ts | 61 ++++++++++++++++++++++ vtex/manifest.gen.ts | 74 +++++++++++++++------------ 4 files changed, 195 insertions(+), 34 deletions(-) create mode 100644 vtex/actions/payments/delete.ts create mode 100644 vtex/loaders/payments/info.ts create mode 100644 vtex/loaders/payments/userPayments.ts diff --git a/vtex/actions/payments/delete.ts b/vtex/actions/payments/delete.ts new file mode 100644 index 000000000..341ecee37 --- /dev/null +++ b/vtex/actions/payments/delete.ts @@ -0,0 +1,39 @@ +import { AppContext } from "../../mod.ts"; +import { parseCookie } from "../../utils/vtexId.ts"; + +export interface DeleteCard { + deletePaymentToken: boolean; +} + +interface Props { + id: string; +} + +async function loader( + { id }: Props, + req: Request, + ctx: AppContext, +): Promise { + const { io } = ctx; + const { cookie, payload } = parseCookie(req.headers, ctx.account); + + if (!payload?.sub || !payload?.userId) { + return null; + } + + const mutation = `mutation DeleteCreditCardToken($tokenId: ID!) { + deletePaymentToken(tokenId: $tokenId) @context(provider: "vtex.my-cards-graphql@2.x") + }`; + + try { + return await io.query({ + query: mutation, + variables: { tokenId: id }, + }, { headers: { cookie } }); + } catch (e) { + console.error(e); + return null; + } +} + +export default loader; diff --git a/vtex/loaders/payments/info.ts b/vtex/loaders/payments/info.ts new file mode 100644 index 000000000..3390d23fd --- /dev/null +++ b/vtex/loaders/payments/info.ts @@ -0,0 +1,55 @@ +import { AppContext } from "../../mod.ts"; +import { parseCookie } from "../../utils/vtexId.ts"; + +const query = `query getPaymentSystems { + paymentSystems { + name + groupName + requiresDocument + displayDocument + validator { + regex + mask + cardCodeMask + cardCodeRegex + } + } +}`; + +export interface PaymentSystem { + name: string; + groupName: string; + requiresDocument: boolean; + displayDocument: boolean; + validator: { + regex: string | null; + mask: string | null; + cardCodeMask: string | null; + cardCodeRegex: string | null; + }; +} + +export default async function loader( + _props: unknown, + req: Request, + ctx: AppContext, +) { + const { io } = ctx; + const { cookie, payload } = parseCookie(req.headers, ctx.account); + + if (!payload?.sub || !payload?.userId) { + return null; + } + + try { + const data = await io.query<{ paymentSystems: PaymentSystem[] }, null>( + { query }, + { headers: { cookie } }, + ); + + return data.paymentSystems; + } catch (e) { + console.error(e); + return null; + } +} diff --git a/vtex/loaders/payments/userPayments.ts b/vtex/loaders/payments/userPayments.ts new file mode 100644 index 000000000..78cd5f2d0 --- /dev/null +++ b/vtex/loaders/payments/userPayments.ts @@ -0,0 +1,61 @@ +// fetch("https://www.als.com/_v/private/graphql/v1?workspace=master&maxAge=long&appsEtag=remove&domain=store&locale=en-US&__bindingId=d8649f18-3877-43de-88e6-c45a81eddc02", { +// "headers": { +// "content-type": "application/json", +// }, +// "body": "{\"operationName\":\"Payments\",\"variables\":{},\"extensions\":{\"persistedQuery\":{\"version\":1,\"sha256Hash\":\"95af11127e44f1857144e38f18635e0d085113c3bfdda3e4b8bc99ae63e14e60\",\"sender\":\"vtex.my-cards@1.x\",\"provider\":\"vtex.store-graphql@2.x\"}}}", +// "method": "POST" +// }) + +import { AppContext } from "../../mod.ts"; +import { parseCookie } from "../../utils/vtexId.ts"; + +export interface Payment { + accountStatus: string | null; + cardNumber: string; + expirationDate: string; + id: string; + isExpired: boolean; + paymentSystem: string; + paymentSystemName: string; +} + +async function loader( + _props: unknown, + req: Request, + ctx: AppContext, +): Promise { + const { io } = ctx; + const { cookie, payload } = parseCookie(req.headers, ctx.account); + + if (!payload?.sub || !payload?.userId) { + return null; + } + + const query = `query getUserPayments { + profile { + payments { + accountStatus + cardNumber + expirationDate + id + isExpired + paymentSystem + paymentSystemName + } + } + }`; + + try { + const data = await io.query<{ profile: { payments: Payment[] } }, null>( + { query }, + { headers: { cookie } }, + ); + + return data.profile.payments; + } catch (e) { + console.error(e); + return null; + } +} + +export default loader; diff --git a/vtex/manifest.gen.ts b/vtex/manifest.gen.ts index ce1452cdb..d50f9fdc5 100644 --- a/vtex/manifest.gen.ts +++ b/vtex/manifest.gen.ts @@ -22,11 +22,12 @@ 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/sessions/delete.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 $$$$$$$$$20 from "./actions/payments/delete.ts"; +import * as $$$$$$$$$21 from "./actions/review/submit.ts"; +import * as $$$$$$$$$22 from "./actions/sessions/delete.ts"; +import * as $$$$$$$$$23 from "./actions/trigger.ts"; +import * as $$$$$$$$$24 from "./actions/wishlist/addItem.ts"; +import * as $$$$$$$$$25 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"; @@ -53,18 +54,20 @@ import * as $$$21 from "./loaders/options/productIdByTerm.ts"; import * as $$$22 from "./loaders/orders/list.ts"; import * as $$$23 from "./loaders/paths/PDPDefaultPath.ts"; import * as $$$24 from "./loaders/paths/PLPDefaultPath.ts"; -import * as $$$25 from "./loaders/product/extend.ts"; -import * as $$$26 from "./loaders/product/extensions/detailsPage.ts"; -import * as $$$27 from "./loaders/product/extensions/list.ts"; -import * as $$$28 from "./loaders/product/extensions/listingPage.ts"; -import * as $$$29 from "./loaders/product/extensions/suggestions.ts"; -import * as $$$30 from "./loaders/product/wishlist.ts"; -import * as $$$31 from "./loaders/proxy.ts"; -import * as $$$32 from "./loaders/sessions/info.ts"; -import * as $$$33 from "./loaders/user.ts"; -import * as $$$34 from "./loaders/wishlist.ts"; -import * as $$$35 from "./loaders/workflow/product.ts"; -import * as $$$36 from "./loaders/workflow/products.ts"; +import * as $$$25 from "./loaders/payments/info.ts"; +import * as $$$26 from "./loaders/payments/userPayments.ts"; +import * as $$$27 from "./loaders/product/extend.ts"; +import * as $$$28 from "./loaders/product/extensions/detailsPage.ts"; +import * as $$$29 from "./loaders/product/extensions/list.ts"; +import * as $$$30 from "./loaders/product/extensions/listingPage.ts"; +import * as $$$31 from "./loaders/product/extensions/suggestions.ts"; +import * as $$$32 from "./loaders/product/wishlist.ts"; +import * as $$$33 from "./loaders/proxy.ts"; +import * as $$$34 from "./loaders/sessions/info.ts"; +import * as $$$35 from "./loaders/user.ts"; +import * as $$$36 from "./loaders/wishlist.ts"; +import * as $$$37 from "./loaders/workflow/product.ts"; +import * as $$$38 from "./loaders/workflow/products.ts"; import * as $$$$$$0 from "./sections/Analytics/Vtex.tsx"; import * as $$$$$$$$$$0 from "./workflows/events.ts"; import * as $$$$$$$$$$1 from "./workflows/product/index.ts"; @@ -96,18 +99,20 @@ const manifest = { "vtex/loaders/orders/list.ts": $$$22, "vtex/loaders/paths/PDPDefaultPath.ts": $$$23, "vtex/loaders/paths/PLPDefaultPath.ts": $$$24, - "vtex/loaders/product/extend.ts": $$$25, - "vtex/loaders/product/extensions/detailsPage.ts": $$$26, - "vtex/loaders/product/extensions/list.ts": $$$27, - "vtex/loaders/product/extensions/listingPage.ts": $$$28, - "vtex/loaders/product/extensions/suggestions.ts": $$$29, - "vtex/loaders/product/wishlist.ts": $$$30, - "vtex/loaders/proxy.ts": $$$31, - "vtex/loaders/sessions/info.ts": $$$32, - "vtex/loaders/user.ts": $$$33, - "vtex/loaders/wishlist.ts": $$$34, - "vtex/loaders/workflow/product.ts": $$$35, - "vtex/loaders/workflow/products.ts": $$$36, + "vtex/loaders/payments/info.ts": $$$25, + "vtex/loaders/payments/userPayments.ts": $$$26, + "vtex/loaders/product/extend.ts": $$$27, + "vtex/loaders/product/extensions/detailsPage.ts": $$$28, + "vtex/loaders/product/extensions/list.ts": $$$29, + "vtex/loaders/product/extensions/listingPage.ts": $$$30, + "vtex/loaders/product/extensions/suggestions.ts": $$$31, + "vtex/loaders/product/wishlist.ts": $$$32, + "vtex/loaders/proxy.ts": $$$33, + "vtex/loaders/sessions/info.ts": $$$34, + "vtex/loaders/user.ts": $$$35, + "vtex/loaders/wishlist.ts": $$$36, + "vtex/loaders/workflow/product.ts": $$$37, + "vtex/loaders/workflow/products.ts": $$$38, }, "handlers": { "vtex/handlers/sitemap.ts": $$$$0, @@ -136,11 +141,12 @@ const manifest = { "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/sessions/delete.ts": $$$$$$$$$21, - "vtex/actions/trigger.ts": $$$$$$$$$22, - "vtex/actions/wishlist/addItem.ts": $$$$$$$$$23, - "vtex/actions/wishlist/removeItem.ts": $$$$$$$$$24, + "vtex/actions/payments/delete.ts": $$$$$$$$$20, + "vtex/actions/review/submit.ts": $$$$$$$$$21, + "vtex/actions/sessions/delete.ts": $$$$$$$$$22, + "vtex/actions/trigger.ts": $$$$$$$$$23, + "vtex/actions/wishlist/addItem.ts": $$$$$$$$$24, + "vtex/actions/wishlist/removeItem.ts": $$$$$$$$$25, }, "workflows": { "vtex/workflows/events.ts": $$$$$$$$$$0, From cdfdaaa010e60f2d0f62d4eed21757b1cab816f1 Mon Sep 17 00:00:00 2001 From: "Ana Carolina D. C" <76822093+devartes@users.noreply.github.com> Date: Thu, 3 Oct 2024 14:59:28 -0300 Subject: [PATCH 04/22] feat: my account vtex profile (#899) --- commerce/types.ts | 22 ++++++ vtex/actions/profile/newsletterProfile.ts | 60 +++++++++++++++ vtex/actions/profile/updateProfile.ts | 93 +++++++++++++++++++++++ vtex/loaders/user.ts | 26 +++++-- vtex/manifest.gen.ts | 24 +++--- 5 files changed, 209 insertions(+), 16 deletions(-) create mode 100644 vtex/actions/profile/newsletterProfile.ts create mode 100644 vtex/actions/profile/updateProfile.ts diff --git a/commerce/types.ts b/commerce/types.ts index 81967c7be..8d2b2fe9a 100644 --- a/commerce/types.ts +++ b/commerce/types.ts @@ -409,7 +409,29 @@ export interface Person extends Omit { image?: ImageObject[] | null; /** The Tax / Fiscal ID of the organization or person, e.g. the TIN in the US or the CIF/NIF in Spain. */ taxID?: string; + /** The telephone number. */ + telephone?: string; + /** The birth date of the person. */ + birthDate?: string; + /** User's corporate name */ + corporateName?: string; + /** User's corporate document */ + corporateDocument?: string; + /** User's corporate trade name */ + tradeName?: string; + /** User's business phone */ + businessPhone?: string; + /** Whether the user is a corporation or not */ + isCorporate?: boolean; + /** Custom fields */ + customFields?: CustomFields[]; +} + +interface CustomFields { + key: string; + value: string; } + // NON SCHEMA.ORG Compliant. Should be removed ASAP export interface Author extends Omit { "@type": "Author"; diff --git a/vtex/actions/profile/newsletterProfile.ts b/vtex/actions/profile/newsletterProfile.ts new file mode 100644 index 000000000..1f14b6403 --- /dev/null +++ b/vtex/actions/profile/newsletterProfile.ts @@ -0,0 +1,60 @@ +import { AppContext } from "../../mod.ts"; +import { parseCookie } from "../../utils/vtexId.ts"; + +interface NewsletterInput { + email: string; + isNewsletterOptIn: boolean; +} + +const newsletterProfile = async ( + props: NewsletterInput, + req: Request, + ctx: AppContext, +): Promise => { + const { io } = ctx; + const { cookie } = parseCookie(req.headers, ctx.account); + + if (!props?.email) { + console.error("User profile not found or email is missing:", props.email); + return null; + } + + const mutation = ` + mutation SubscribeNewsletter($email: String!, $isNewsletterOptIn: Boolean!) { + subscribeNewsletter(email: $email, isNewsletterOptIn: $isNewsletterOptIn) + @context(provider: "vtex.store-graphql@2.x") + } + `; + + const variables = { + email: props.email, + isNewsletterOptIn: props.isNewsletterOptIn, + }; + + try { + await io.query<{ subscribeNewsletter: boolean }, unknown>( + { + query: mutation, + operationName: "SubscribeNewsletter", + variables, + }, + { + headers: { + cookie, + }, + }, + ); + + const result = await ctx.invoke("vtex/loaders/user.ts"); + const newsletterField = result?.customFields?.find((field) => + field.key === "isNewsletterOptIn" + ); + + return newsletterField?.value === "true"; + } catch (error) { + console.error("Error subscribing to newsletter:", error); + return null; + } +}; + +export default newsletterProfile; diff --git a/vtex/actions/profile/updateProfile.ts b/vtex/actions/profile/updateProfile.ts new file mode 100644 index 000000000..17c4f724b --- /dev/null +++ b/vtex/actions/profile/updateProfile.ts @@ -0,0 +1,93 @@ +import { AppContext } from "../../mod.ts"; +import { parseCookie } from "../../utils/vtexId.ts"; +import { Person } from "../../../commerce/types.ts"; +import type { User } from "../../loaders/user.ts"; + +export interface UserMutation { + firstName?: string; + lastName?: string; + email?: string; + homePhone?: string | null; + gender?: string | null; + birthDate?: string | null; + corporateName?: string | null; + tradeName?: string | null; + businessPhone?: string | null; + isCorporate?: boolean; +} + +const updateProfile = async ( + props: UserMutation, + req: Request, + ctx: AppContext, +): Promise => { + const { io } = ctx; + const { cookie } = parseCookie(req.headers, ctx.account); + + if (!props?.email) { + console.error("User profile not found or email is missing:", props.email); + return null; + } + const mutation = ` + mutation UpdateProfile($input: ProfileInput!) { + updateProfile(fields: $input) @context(provider: "vtex.store-graphql") { + cacheId + firstName + lastName + birthDate + gender + homePhone + businessPhone + document + email + tradeName + corporateName + corporateDocument + stateRegistration + isCorporate + } + } + `; + + try { + const { updateProfile: updatedUser } = await io.query< + { updateProfile: User }, + { input: UserMutation } + >( + { + query: mutation, + operationName: "UpdateProfile", + variables: { + input: { + ...props, + email: props.email, + }, + }, + }, + { headers: { cookie } }, + ); + + return { + "@id": updatedUser?.userId ?? updatedUser.id, + email: updatedUser.email, + givenName: updatedUser?.firstName, + familyName: updatedUser?.lastName, + taxID: updatedUser?.document?.replace(/[^\d]/g, ""), + gender: updatedUser?.gender === "female" + ? "https://schema.org/Female" + : "https://schema.org/Male", + telephone: updatedUser?.homePhone, + birthDate: updatedUser?.birthDate, + corporateName: updatedUser?.tradeName, + corporateDocument: updatedUser?.corporateDocument, + businessPhone: updatedUser?.businessPhone, + isCorporate: updatedUser?.isCorporate, + customFields: updatedUser?.customFields, + }; + } catch (error) { + console.error("Error updating user profile:", error); + return null; + } +}; + +export default updateProfile; diff --git a/vtex/loaders/user.ts b/vtex/loaders/user.ts index 174398e71..07e710b32 100644 --- a/vtex/loaders/user.ts +++ b/vtex/loaders/user.ts @@ -2,7 +2,7 @@ import { Person } from "../../commerce/types.ts"; import { AppContext } from "../mod.ts"; import { parseCookie } from "../utils/vtexId.ts"; -interface User { +export interface User { id: string; userId: string; email: string; @@ -11,6 +11,13 @@ interface User { profilePicture?: string; gender?: string; document?: string; + homePhone?: string; + birthDate?: string; + corporateDocument?: string; + tradeName?: string; + businessPhone?: string; + isCorporate?: boolean; + customFields?: { key: string; value: string }[]; } async function loader( @@ -26,7 +33,7 @@ async function loader( } const query = - "query getUserProfile { profile { id userId email firstName lastName profilePicture gender document }}"; + `query getUserProfile { profile(customFields: "isNewsletterOptIn") { id userId email firstName lastName profilePicture gender document homePhone birthDate corporateDocument tradeName businessPhone isCorporate customFields { key value } }}`; try { const { profile: user } = await io.query<{ profile: User }, null>( @@ -35,14 +42,21 @@ async function loader( ); return { - "@id": user.userId ?? user.id, + "@id": user?.userId ?? user.id, email: user.email, - givenName: user.firstName, - familyName: user.lastName, + givenName: user?.firstName, + familyName: user?.lastName, taxID: user?.document?.replace(/[^\d]/g, ""), - gender: user.gender === "f" + gender: user?.gender === "female" ? "https://schema.org/Female" : "https://schema.org/Male", + telephone: user?.homePhone, + birthDate: user?.birthDate, + corporateName: user?.tradeName, + corporateDocument: user?.corporateDocument, + businessPhone: user?.businessPhone, + isCorporate: user?.isCorporate, + customFields: user?.customFields, }; } catch (_) { return null; diff --git a/vtex/manifest.gen.ts b/vtex/manifest.gen.ts index d50f9fdc5..e759e6a97 100644 --- a/vtex/manifest.gen.ts +++ b/vtex/manifest.gen.ts @@ -23,11 +23,13 @@ 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/payments/delete.ts"; -import * as $$$$$$$$$21 from "./actions/review/submit.ts"; -import * as $$$$$$$$$22 from "./actions/sessions/delete.ts"; -import * as $$$$$$$$$23 from "./actions/trigger.ts"; -import * as $$$$$$$$$24 from "./actions/wishlist/addItem.ts"; -import * as $$$$$$$$$25 from "./actions/wishlist/removeItem.ts"; +import * as $$$$$$$$$21 from "./actions/profile/newsletterProfile.ts"; +import * as $$$$$$$$$22 from "./actions/profile/updateProfile.ts"; +import * as $$$$$$$$$23 from "./actions/review/submit.ts"; +import * as $$$$$$$$$24 from "./actions/sessions/delete.ts"; +import * as $$$$$$$$$25 from "./actions/trigger.ts"; +import * as $$$$$$$$$26 from "./actions/wishlist/addItem.ts"; +import * as $$$$$$$$$27 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"; @@ -142,11 +144,13 @@ const manifest = { "vtex/actions/newsletter/subscribe.ts": $$$$$$$$$18, "vtex/actions/notifyme.ts": $$$$$$$$$19, "vtex/actions/payments/delete.ts": $$$$$$$$$20, - "vtex/actions/review/submit.ts": $$$$$$$$$21, - "vtex/actions/sessions/delete.ts": $$$$$$$$$22, - "vtex/actions/trigger.ts": $$$$$$$$$23, - "vtex/actions/wishlist/addItem.ts": $$$$$$$$$24, - "vtex/actions/wishlist/removeItem.ts": $$$$$$$$$25, + "vtex/actions/profile/newsletterProfile.ts": $$$$$$$$$21, + "vtex/actions/profile/updateProfile.ts": $$$$$$$$$22, + "vtex/actions/review/submit.ts": $$$$$$$$$23, + "vtex/actions/sessions/delete.ts": $$$$$$$$$24, + "vtex/actions/trigger.ts": $$$$$$$$$25, + "vtex/actions/wishlist/addItem.ts": $$$$$$$$$26, + "vtex/actions/wishlist/removeItem.ts": $$$$$$$$$27, }, "workflows": { "vtex/workflows/events.ts": $$$$$$$$$$0, From c66022a5ad2d85552447f191810514e4c4fec04f Mon Sep 17 00:00:00 2001 From: marcoferreiradev Date: Thu, 3 Oct 2024 15:06:51 -0300 Subject: [PATCH 05/22] feat: add the unitary order loader and start creating its typing --- vtex/loaders/orders/order.ts | 35 ++++++++++++++ vtex/manifest.gen.ts | 66 +++++++++++++------------- vtex/utils/client.ts | 4 ++ vtex/utils/types.ts | 92 +++++++++++++++++++++++++++++++++++- 4 files changed, 163 insertions(+), 34 deletions(-) create mode 100644 vtex/loaders/orders/order.ts diff --git a/vtex/loaders/orders/order.ts b/vtex/loaders/orders/order.ts new file mode 100644 index 000000000..9489b04f4 --- /dev/null +++ b/vtex/loaders/orders/order.ts @@ -0,0 +1,35 @@ +import { RequestURLParam } from "../../../website/functions/requestToParam.ts"; +import { AppContext } from "../../mod.ts"; +import { Order } from "../../utils/types.ts"; +import { parseCookie } from "../../utils/vtexId.ts"; + +export interface Props { + slug: RequestURLParam; +} + +export default async function loader( + props: Props, + req: Request, + ctx: AppContext, +): Promise { + const { vcsDeprecated } = ctx; + const { cookie } = parseCookie(req.headers, ctx.account); + + const { slug } = props; + + const response = await vcsDeprecated["GET /api/oms/user/orders/:orderId"]( + { orderId: slug }, + { + headers: { + cookie, + }, + }, + ); + + if (response.ok) { + const order = await response.json(); + return order; + } + + return null; +} diff --git a/vtex/manifest.gen.ts b/vtex/manifest.gen.ts index e759e6a97..b4a5d4077 100644 --- a/vtex/manifest.gen.ts +++ b/vtex/manifest.gen.ts @@ -54,22 +54,23 @@ import * as $$$19 from "./loaders/masterdata/searchDocuments.ts"; import * as $$$20 from "./loaders/navbar.ts"; import * as $$$21 from "./loaders/options/productIdByTerm.ts"; import * as $$$22 from "./loaders/orders/list.ts"; -import * as $$$23 from "./loaders/paths/PDPDefaultPath.ts"; -import * as $$$24 from "./loaders/paths/PLPDefaultPath.ts"; -import * as $$$25 from "./loaders/payments/info.ts"; -import * as $$$26 from "./loaders/payments/userPayments.ts"; -import * as $$$27 from "./loaders/product/extend.ts"; -import * as $$$28 from "./loaders/product/extensions/detailsPage.ts"; -import * as $$$29 from "./loaders/product/extensions/list.ts"; -import * as $$$30 from "./loaders/product/extensions/listingPage.ts"; -import * as $$$31 from "./loaders/product/extensions/suggestions.ts"; -import * as $$$32 from "./loaders/product/wishlist.ts"; -import * as $$$33 from "./loaders/proxy.ts"; -import * as $$$34 from "./loaders/sessions/info.ts"; -import * as $$$35 from "./loaders/user.ts"; -import * as $$$36 from "./loaders/wishlist.ts"; -import * as $$$37 from "./loaders/workflow/product.ts"; -import * as $$$38 from "./loaders/workflow/products.ts"; +import * as $$$23 from "./loaders/orders/order.ts"; +import * as $$$24 from "./loaders/paths/PDPDefaultPath.ts"; +import * as $$$25 from "./loaders/paths/PLPDefaultPath.ts"; +import * as $$$26 from "./loaders/payments/info.ts"; +import * as $$$27 from "./loaders/payments/userPayments.ts"; +import * as $$$28 from "./loaders/product/extend.ts"; +import * as $$$29 from "./loaders/product/extensions/detailsPage.ts"; +import * as $$$30 from "./loaders/product/extensions/list.ts"; +import * as $$$31 from "./loaders/product/extensions/listingPage.ts"; +import * as $$$32 from "./loaders/product/extensions/suggestions.ts"; +import * as $$$33 from "./loaders/product/wishlist.ts"; +import * as $$$34 from "./loaders/proxy.ts"; +import * as $$$35 from "./loaders/sessions/info.ts"; +import * as $$$36 from "./loaders/user.ts"; +import * as $$$37 from "./loaders/wishlist.ts"; +import * as $$$38 from "./loaders/workflow/product.ts"; +import * as $$$39 from "./loaders/workflow/products.ts"; import * as $$$$$$0 from "./sections/Analytics/Vtex.tsx"; import * as $$$$$$$$$$0 from "./workflows/events.ts"; import * as $$$$$$$$$$1 from "./workflows/product/index.ts"; @@ -99,22 +100,23 @@ const manifest = { "vtex/loaders/navbar.ts": $$$20, "vtex/loaders/options/productIdByTerm.ts": $$$21, "vtex/loaders/orders/list.ts": $$$22, - "vtex/loaders/paths/PDPDefaultPath.ts": $$$23, - "vtex/loaders/paths/PLPDefaultPath.ts": $$$24, - "vtex/loaders/payments/info.ts": $$$25, - "vtex/loaders/payments/userPayments.ts": $$$26, - "vtex/loaders/product/extend.ts": $$$27, - "vtex/loaders/product/extensions/detailsPage.ts": $$$28, - "vtex/loaders/product/extensions/list.ts": $$$29, - "vtex/loaders/product/extensions/listingPage.ts": $$$30, - "vtex/loaders/product/extensions/suggestions.ts": $$$31, - "vtex/loaders/product/wishlist.ts": $$$32, - "vtex/loaders/proxy.ts": $$$33, - "vtex/loaders/sessions/info.ts": $$$34, - "vtex/loaders/user.ts": $$$35, - "vtex/loaders/wishlist.ts": $$$36, - "vtex/loaders/workflow/product.ts": $$$37, - "vtex/loaders/workflow/products.ts": $$$38, + "vtex/loaders/orders/order.ts": $$$23, + "vtex/loaders/paths/PDPDefaultPath.ts": $$$24, + "vtex/loaders/paths/PLPDefaultPath.ts": $$$25, + "vtex/loaders/payments/info.ts": $$$26, + "vtex/loaders/payments/userPayments.ts": $$$27, + "vtex/loaders/product/extend.ts": $$$28, + "vtex/loaders/product/extensions/detailsPage.ts": $$$29, + "vtex/loaders/product/extensions/list.ts": $$$30, + "vtex/loaders/product/extensions/listingPage.ts": $$$31, + "vtex/loaders/product/extensions/suggestions.ts": $$$32, + "vtex/loaders/product/wishlist.ts": $$$33, + "vtex/loaders/proxy.ts": $$$34, + "vtex/loaders/sessions/info.ts": $$$35, + "vtex/loaders/user.ts": $$$36, + "vtex/loaders/wishlist.ts": $$$37, + "vtex/loaders/workflow/product.ts": $$$38, + "vtex/loaders/workflow/products.ts": $$$39, }, "handlers": { "vtex/handlers/sitemap.ts": $$$$0, diff --git a/vtex/utils/client.ts b/vtex/utils/client.ts index 46be6e682..c252ce705 100644 --- a/vtex/utils/client.ts +++ b/vtex/utils/client.ts @@ -8,6 +8,7 @@ import { LegacyFacets, LegacyProduct, LegacySort, + Order, OrderForm, PageType, PortalSuggestion, @@ -247,6 +248,9 @@ export interface VTEXCommerceStable { "GET /api/oms/user/orders": { response: Userorderslist; }; + "GET /api/oms/user/orders/:orderId": { + response: Order; + }; } export interface SP { diff --git a/vtex/utils/types.ts b/vtex/utils/types.ts index 0fedd1893..c662603a4 100644 --- a/vtex/utils/types.ts +++ b/vtex/utils/types.ts @@ -62,11 +62,12 @@ export interface ClientProfileData { export interface ClientPreferencesData { locale: string; - optinNewsLetter: null; + optinNewsLetter: boolean; } export interface ItemMetadata { - items: ItemMetadataItem[]; + items?: ItemMetadataItem[]; + Items?: ItemMetadataItemUppercase[]; } export interface ItemMetadataItem { @@ -82,6 +83,19 @@ export interface ItemMetadataItem { assemblyOptions: AssemblyOption[]; } +export interface ItemMetadataItemUppercase { + Id: string; + Seller: string; + Name: string; + SkuName: string; + ProductId: string; + RefId: string; + Ean: null | string; + ImageUrl: string; + DetailUrl: string; + AssemblyOptions: AssemblyOption[]; +} + export interface AssemblyOption { id: Name; name: Name; @@ -1282,6 +1296,7 @@ export interface Order { invoiceOutput: string[]; isAllDelivered: boolean; isAnyDelivered: boolean; + itemMetadata: ItemMetadata; items: OrderFormItem[]; lastChange: string; lastMessageUnread: string; @@ -1304,6 +1319,79 @@ export interface Order { workflowInRetry: boolean; } +export interface OrderItem { + affiliateId: string; + allowCancellation: boolean; + allowEdition?: boolean; + authorizedDate: string; + callCenterOperatorData: string; + cancelReason: string; + cancellationData: { + RequestedByUser: boolean; + RequestedBySystem: boolean; + RequestedBySellerNotification: boolean; + RequestedByPaymentNotification: boolean; + Reason: string; + CancellationDate: string; + }; + cancellationRequests?: null; + changesAttachment: string; + checkedInPickupPointId: string | null; + clientPreferencesData: ClientPreferencesData; + clientProfileData: ClientProfileData | null; + // deno-lint-ignore no-explicit-any + commercialConditionData?: any | null; + creationDate: string; + // deno-lint-ignore no-explicit-any + customData?: Record | null; + followUpEmail?: string; + giftRegistryData?: GiftRegistry | null; + hostname: string; + // deno-lint-ignore no-explicit-any + invoiceData: any | null; + invoicedDate: string | null; + isCheckedIn: boolean; + isCompleted: boolean; + itemMetadata: ItemMetadata; + items: OrderFormItem[]; + lastChange: string; + lastMessage: string; + marketingData: OrderFormMarketingData | null; + marketplace: Marketplace; + marketplaceItems: []; + marketplaceOrderId: string; + marketplaceServicesEndpoint: string; + merchantName: string; + // deno-lint-ignore no-explicit-any + openTextField: any | null; +} + +interface Marketplace { + baseURL: string; + // deno-lint-ignore no-explicit-any + isCertified?: any | null; + name: string; +} + +interface OrderFormMarketingData { + utmCampaign?: string; + utmMedium?: string; + utmSource?: string; + utmiCampaign?: string; + utmiPart?: string; + utmipage?: string; + marketingTags?: string | string[]; +} + +interface GiftRegistry { + attachmentId: string; + giftRegistryId: string; + giftRegistryType: string; + giftRegistryTypeName: string; + addressId: string; + description: string; +} + export interface Orders { facets: Facet[]; list: Order[]; From 53d1d2e9046a1872271bdb46a161ea153152dd1f Mon Sep 17 00:00:00 2001 From: devartes Date: Thu, 3 Oct 2024 17:09:43 -0300 Subject: [PATCH 06/22] fix: props user.ts --- vtex/loaders/user.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/vtex/loaders/user.ts b/vtex/loaders/user.ts index 07e710b32..533b4a8f3 100644 --- a/vtex/loaders/user.ts +++ b/vtex/loaders/user.ts @@ -14,6 +14,7 @@ export interface User { homePhone?: string; birthDate?: string; corporateDocument?: string; + corporateName?: string; tradeName?: string; businessPhone?: string; isCorporate?: boolean; @@ -33,7 +34,7 @@ async function loader( } const query = - `query getUserProfile { profile(customFields: "isNewsletterOptIn") { id userId email firstName lastName profilePicture gender document homePhone birthDate corporateDocument tradeName businessPhone isCorporate customFields { key value } }}`; + `query getUserProfile { profile(customFields: "isNewsletterOptIn") { id userId email firstName lastName profilePicture gender document homePhone birthDate corporateDocument corporateName tradeName businessPhone isCorporate customFields { key value } }}`; try { const { profile: user } = await io.query<{ profile: User }, null>( @@ -52,7 +53,8 @@ async function loader( : "https://schema.org/Male", telephone: user?.homePhone, birthDate: user?.birthDate, - corporateName: user?.tradeName, + corporateName: user?.corporateName, + tradeName: user?.tradeName, corporateDocument: user?.corporateDocument, businessPhone: user?.businessPhone, isCorporate: user?.isCorporate, From 9f2cf75b32d245c0e22ff1b4d71be1849900b786 Mon Sep 17 00:00:00 2001 From: soutofernando Date: Thu, 3 Oct 2024 17:29:36 -0300 Subject: [PATCH 07/22] feat: updateAddress action --- vtex/actions/address/updateAddress.ts | 120 ++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 vtex/actions/address/updateAddress.ts diff --git a/vtex/actions/address/updateAddress.ts b/vtex/actions/address/updateAddress.ts new file mode 100644 index 000000000..15ff73d0f --- /dev/null +++ b/vtex/actions/address/updateAddress.ts @@ -0,0 +1,120 @@ +import { PostalAddress } from "../../../commerce/types.ts"; +import { AppContext } from "../../mod.ts"; +import { parseCookie } from "../../utils/vtexId.ts"; + +interface Address { + name?: string; + addressName?: string; + addressType?: string; + city?: string; + complement?: string; + country?: string; + geoCoordinates?: number[]; + neighborhood?: string; + number?: string; + postalCode?: string; + receiverName?: string; + reference?: string; + state?: string; + street?: string; +} + +interface AddressInput { + addressId?: string; + name?: string; + addressName?: string; + addressType?: string; + city?: string; + complement?: string; + country?: string; + geoCoordinates?: number[]; + neighborhood?: string; + number?: string; + postalCode?: string; + receiverName?: string; + reference?: string; + state?: string; + street?: string; +} + +async function loader( + _props: unknown, + req: Request, + ctx: AppContext, +): Promise { + const { io } = ctx; + const { cookie } = parseCookie(req.headers, ctx.account); + + const moc: AddressInput = { + addressType: "Residential", + addressName: "Home Address", + city: "Los Angeles", + complement: "Apt 4B", + country: "USA", + neighborhood: "Downtown", + number: "1234", + postalCode: "90001", + geoCoordinates: [-111.98, 40.74], + receiverName: "John Maria", + reference: "Near the central park", + state: "UTA", + street: "Main St", + }; + + const mutation = ` + mutation UpdateAddress($addressId: String, $addressFields: AddressInput) { + updateAddress(id: $addressId, fields: $addressFields) + @context(provider: "vtex.store-graphql") { + cacheId + addresses: address { + addressId: id + addressType + addressName + city + complement + country + neighborhood + number + postalCode + geoCoordinates + receiverName + reference + state + street + } + } + }`; + + try { + const { updateAddress: updatedAddress } = await io.query< + { updateAddress: Address }, + { addressId: string; addressFields: AddressInput } + >( + { + query: mutation, + operationName: "UpdateAddress", + variables: { + addressId: "9y11rmhpsq", + addressFields: { + ...moc, + }, + }, + }, + { headers: { cookie } }, + ); + + return { + "@type": "PostalAddress", + addressCountry: updatedAddress?.country, + addressLocality: updatedAddress?.city, + addressRegion: updatedAddress?.state, + postalCode: updatedAddress?.postalCode, + streetAddress: updatedAddress?.street, + }; + } catch (error) { + console.error("Error updating address:", error); + return null; + } +} + +export default loader; From 9e3bee2983d3df60583780a10aee75ef18fef6b4 Mon Sep 17 00:00:00 2001 From: soutofernando Date: Thu, 3 Oct 2024 17:37:09 -0300 Subject: [PATCH 08/22] chore: rebuild manifest --- vtex/manifest.gen.ts | 114 ++++++++++++++++++++++--------------------- 1 file changed, 58 insertions(+), 56 deletions(-) diff --git a/vtex/manifest.gen.ts b/vtex/manifest.gen.ts index b4a5d4077..41d235212 100644 --- a/vtex/manifest.gen.ts +++ b/vtex/manifest.gen.ts @@ -2,34 +2,35 @@ // This file SHOULD be checked into source version control. // This file is automatically updated during development when running `dev.ts`. -import * as $$$$$$$$$0 from "./actions/analytics/sendEvent.ts"; -import * as $$$$$$$$$1 from "./actions/cart/addItems.ts"; -import * as $$$$$$$$$2 from "./actions/cart/addOfferings.ts"; -import * as $$$$$$$$$3 from "./actions/cart/clearOrderformMessages.ts"; -import * as $$$$$$$$$4 from "./actions/cart/getInstallment.ts"; -import * as $$$$$$$$$5 from "./actions/cart/removeItemAttachment.ts"; -import * as $$$$$$$$$6 from "./actions/cart/removeItems.ts"; -import * as $$$$$$$$$7 from "./actions/cart/removeOffering.ts"; -import * as $$$$$$$$$8 from "./actions/cart/simulation.ts"; -import * as $$$$$$$$$9 from "./actions/cart/updateAttachment.ts"; -import * as $$$$$$$$$10 from "./actions/cart/updateCoupons.ts"; -import * as $$$$$$$$$11 from "./actions/cart/updateGifts.ts"; -import * as $$$$$$$$$12 from "./actions/cart/updateItemAttachment.ts"; -import * as $$$$$$$$$13 from "./actions/cart/updateItemPrice.ts"; -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/payments/delete.ts"; -import * as $$$$$$$$$21 from "./actions/profile/newsletterProfile.ts"; -import * as $$$$$$$$$22 from "./actions/profile/updateProfile.ts"; -import * as $$$$$$$$$23 from "./actions/review/submit.ts"; -import * as $$$$$$$$$24 from "./actions/sessions/delete.ts"; -import * as $$$$$$$$$25 from "./actions/trigger.ts"; -import * as $$$$$$$$$26 from "./actions/wishlist/addItem.ts"; -import * as $$$$$$$$$27 from "./actions/wishlist/removeItem.ts"; +import * as $$$$$$$$$0 from "./actions/address/updateAddress.ts"; +import * as $$$$$$$$$1 from "./actions/analytics/sendEvent.ts"; +import * as $$$$$$$$$2 from "./actions/cart/addItems.ts"; +import * as $$$$$$$$$3 from "./actions/cart/addOfferings.ts"; +import * as $$$$$$$$$4 from "./actions/cart/clearOrderformMessages.ts"; +import * as $$$$$$$$$5 from "./actions/cart/getInstallment.ts"; +import * as $$$$$$$$$6 from "./actions/cart/removeItemAttachment.ts"; +import * as $$$$$$$$$7 from "./actions/cart/removeItems.ts"; +import * as $$$$$$$$$8 from "./actions/cart/removeOffering.ts"; +import * as $$$$$$$$$9 from "./actions/cart/simulation.ts"; +import * as $$$$$$$$$10 from "./actions/cart/updateAttachment.ts"; +import * as $$$$$$$$$11 from "./actions/cart/updateCoupons.ts"; +import * as $$$$$$$$$12 from "./actions/cart/updateGifts.ts"; +import * as $$$$$$$$$13 from "./actions/cart/updateItemAttachment.ts"; +import * as $$$$$$$$$14 from "./actions/cart/updateItemPrice.ts"; +import * as $$$$$$$$$15 from "./actions/cart/updateItems.ts"; +import * as $$$$$$$$$16 from "./actions/cart/updateProfile.ts"; +import * as $$$$$$$$$17 from "./actions/cart/updateUser.ts"; +import * as $$$$$$$$$18 from "./actions/masterdata/createDocument.ts"; +import * as $$$$$$$$$19 from "./actions/newsletter/subscribe.ts"; +import * as $$$$$$$$$20 from "./actions/notifyme.ts"; +import * as $$$$$$$$$21 from "./actions/payments/delete.ts"; +import * as $$$$$$$$$22 from "./actions/profile/newsletterProfile.ts"; +import * as $$$$$$$$$23 from "./actions/profile/updateProfile.ts"; +import * as $$$$$$$$$24 from "./actions/review/submit.ts"; +import * as $$$$$$$$$25 from "./actions/sessions/delete.ts"; +import * as $$$$$$$$$26 from "./actions/trigger.ts"; +import * as $$$$$$$$$27 from "./actions/wishlist/addItem.ts"; +import * as $$$$$$$$$28 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"; @@ -125,34 +126,35 @@ const manifest = { "vtex/sections/Analytics/Vtex.tsx": $$$$$$0, }, "actions": { - "vtex/actions/analytics/sendEvent.ts": $$$$$$$$$0, - "vtex/actions/cart/addItems.ts": $$$$$$$$$1, - "vtex/actions/cart/addOfferings.ts": $$$$$$$$$2, - "vtex/actions/cart/clearOrderformMessages.ts": $$$$$$$$$3, - "vtex/actions/cart/getInstallment.ts": $$$$$$$$$4, - "vtex/actions/cart/removeItemAttachment.ts": $$$$$$$$$5, - "vtex/actions/cart/removeItems.ts": $$$$$$$$$6, - "vtex/actions/cart/removeOffering.ts": $$$$$$$$$7, - "vtex/actions/cart/simulation.ts": $$$$$$$$$8, - "vtex/actions/cart/updateAttachment.ts": $$$$$$$$$9, - "vtex/actions/cart/updateCoupons.ts": $$$$$$$$$10, - "vtex/actions/cart/updateGifts.ts": $$$$$$$$$11, - "vtex/actions/cart/updateItemAttachment.ts": $$$$$$$$$12, - "vtex/actions/cart/updateItemPrice.ts": $$$$$$$$$13, - "vtex/actions/cart/updateItems.ts": $$$$$$$$$14, - "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/payments/delete.ts": $$$$$$$$$20, - "vtex/actions/profile/newsletterProfile.ts": $$$$$$$$$21, - "vtex/actions/profile/updateProfile.ts": $$$$$$$$$22, - "vtex/actions/review/submit.ts": $$$$$$$$$23, - "vtex/actions/sessions/delete.ts": $$$$$$$$$24, - "vtex/actions/trigger.ts": $$$$$$$$$25, - "vtex/actions/wishlist/addItem.ts": $$$$$$$$$26, - "vtex/actions/wishlist/removeItem.ts": $$$$$$$$$27, + "vtex/actions/address/updateAddress.ts": $$$$$$$$$0, + "vtex/actions/analytics/sendEvent.ts": $$$$$$$$$1, + "vtex/actions/cart/addItems.ts": $$$$$$$$$2, + "vtex/actions/cart/addOfferings.ts": $$$$$$$$$3, + "vtex/actions/cart/clearOrderformMessages.ts": $$$$$$$$$4, + "vtex/actions/cart/getInstallment.ts": $$$$$$$$$5, + "vtex/actions/cart/removeItemAttachment.ts": $$$$$$$$$6, + "vtex/actions/cart/removeItems.ts": $$$$$$$$$7, + "vtex/actions/cart/removeOffering.ts": $$$$$$$$$8, + "vtex/actions/cart/simulation.ts": $$$$$$$$$9, + "vtex/actions/cart/updateAttachment.ts": $$$$$$$$$10, + "vtex/actions/cart/updateCoupons.ts": $$$$$$$$$11, + "vtex/actions/cart/updateGifts.ts": $$$$$$$$$12, + "vtex/actions/cart/updateItemAttachment.ts": $$$$$$$$$13, + "vtex/actions/cart/updateItemPrice.ts": $$$$$$$$$14, + "vtex/actions/cart/updateItems.ts": $$$$$$$$$15, + "vtex/actions/cart/updateProfile.ts": $$$$$$$$$16, + "vtex/actions/cart/updateUser.ts": $$$$$$$$$17, + "vtex/actions/masterdata/createDocument.ts": $$$$$$$$$18, + "vtex/actions/newsletter/subscribe.ts": $$$$$$$$$19, + "vtex/actions/notifyme.ts": $$$$$$$$$20, + "vtex/actions/payments/delete.ts": $$$$$$$$$21, + "vtex/actions/profile/newsletterProfile.ts": $$$$$$$$$22, + "vtex/actions/profile/updateProfile.ts": $$$$$$$$$23, + "vtex/actions/review/submit.ts": $$$$$$$$$24, + "vtex/actions/sessions/delete.ts": $$$$$$$$$25, + "vtex/actions/trigger.ts": $$$$$$$$$26, + "vtex/actions/wishlist/addItem.ts": $$$$$$$$$27, + "vtex/actions/wishlist/removeItem.ts": $$$$$$$$$28, }, "workflows": { "vtex/workflows/events.ts": $$$$$$$$$$0, From 677dc1c9663e6f03b07c5bccf7798b4543ec9b4e Mon Sep 17 00:00:00 2001 From: soutofernando Date: Thu, 3 Oct 2024 17:38:09 -0300 Subject: [PATCH 09/22] deno check --- vtex/actions/address/updateAddress.ts | 158 +++++++++++++------------- 1 file changed, 79 insertions(+), 79 deletions(-) diff --git a/vtex/actions/address/updateAddress.ts b/vtex/actions/address/updateAddress.ts index 15ff73d0f..27135c375 100644 --- a/vtex/actions/address/updateAddress.ts +++ b/vtex/actions/address/updateAddress.ts @@ -3,65 +3,65 @@ import { AppContext } from "../../mod.ts"; import { parseCookie } from "../../utils/vtexId.ts"; interface Address { - name?: string; - addressName?: string; - addressType?: string; - city?: string; - complement?: string; - country?: string; - geoCoordinates?: number[]; - neighborhood?: string; - number?: string; - postalCode?: string; - receiverName?: string; - reference?: string; - state?: string; - street?: string; + name?: string; + addressName?: string; + addressType?: string; + city?: string; + complement?: string; + country?: string; + geoCoordinates?: number[]; + neighborhood?: string; + number?: string; + postalCode?: string; + receiverName?: string; + reference?: string; + state?: string; + street?: string; } interface AddressInput { - addressId?: string; - name?: string; - addressName?: string; - addressType?: string; - city?: string; - complement?: string; - country?: string; - geoCoordinates?: number[]; - neighborhood?: string; - number?: string; - postalCode?: string; - receiverName?: string; - reference?: string; - state?: string; - street?: string; + addressId?: string; + name?: string; + addressName?: string; + addressType?: string; + city?: string; + complement?: string; + country?: string; + geoCoordinates?: number[]; + neighborhood?: string; + number?: string; + postalCode?: string; + receiverName?: string; + reference?: string; + state?: string; + street?: string; } async function loader( - _props: unknown, - req: Request, - ctx: AppContext, + _props: unknown, + req: Request, + ctx: AppContext, ): Promise { - const { io } = ctx; - const { cookie } = parseCookie(req.headers, ctx.account); + const { io } = ctx; + const { cookie } = parseCookie(req.headers, ctx.account); - const moc: AddressInput = { - addressType: "Residential", - addressName: "Home Address", - city: "Los Angeles", - complement: "Apt 4B", - country: "USA", - neighborhood: "Downtown", - number: "1234", - postalCode: "90001", - geoCoordinates: [-111.98, 40.74], - receiverName: "John Maria", - reference: "Near the central park", - state: "UTA", - street: "Main St", - }; + const moc: AddressInput = { + addressType: "Residential", + addressName: "Home Address", + city: "Los Angeles", + complement: "Apt 4B", + country: "USA", + neighborhood: "Downtown", + number: "1234", + postalCode: "90001", + geoCoordinates: [-111.98, 40.74], + receiverName: "John Maria", + reference: "Near the central park", + state: "UTA", + street: "Main St", + }; - const mutation = ` + const mutation = ` mutation UpdateAddress($addressId: String, $addressFields: AddressInput) { updateAddress(id: $addressId, fields: $addressFields) @context(provider: "vtex.store-graphql") { @@ -85,36 +85,36 @@ async function loader( } }`; - try { - const { updateAddress: updatedAddress } = await io.query< - { updateAddress: Address }, - { addressId: string; addressFields: AddressInput } - >( - { - query: mutation, - operationName: "UpdateAddress", - variables: { - addressId: "9y11rmhpsq", - addressFields: { - ...moc, - }, - }, - }, - { headers: { cookie } }, - ); + try { + const { updateAddress: updatedAddress } = await io.query< + { updateAddress: Address }, + { addressId: string; addressFields: AddressInput } + >( + { + query: mutation, + operationName: "UpdateAddress", + variables: { + addressId: "9y11rmhpsq", + addressFields: { + ...moc, + }, + }, + }, + { headers: { cookie } }, + ); - return { - "@type": "PostalAddress", - addressCountry: updatedAddress?.country, - addressLocality: updatedAddress?.city, - addressRegion: updatedAddress?.state, - postalCode: updatedAddress?.postalCode, - streetAddress: updatedAddress?.street, - }; - } catch (error) { - console.error("Error updating address:", error); - return null; - } + return { + "@type": "PostalAddress", + addressCountry: updatedAddress?.country, + addressLocality: updatedAddress?.city, + addressRegion: updatedAddress?.state, + postalCode: updatedAddress?.postalCode, + streetAddress: updatedAddress?.street, + }; + } catch (error) { + console.error("Error updating address:", error); + return null; + } } export default loader; From 36064d71ea7c6b7e50f55fdab322341b4e5aa732 Mon Sep 17 00:00:00 2001 From: guitavano Date: Fri, 4 Oct 2024 11:04:20 -0300 Subject: [PATCH 10/22] add try catch --- vtex/utils/similars.ts | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/vtex/utils/similars.ts b/vtex/utils/similars.ts index 1ba304260..fe804f465 100644 --- a/vtex/utils/similars.ts +++ b/vtex/utils/similars.ts @@ -13,14 +13,20 @@ export const withIsSimilarTo = async ( return product; } - const isSimilarTo = await relatedProductsLoader( - { - crossSelling: "similars", - id: product.inProductGroupWithID, - }, - req, - ctx, - ); + let isSimilarTo = undefined; + + try{ + isSimilarTo = await relatedProductsLoader( + { + crossSelling: "similars", + id: product.inProductGroupWithID, + }, + req, + ctx, + ); + }catch(e){ + console.error(e) + } return { ...product, From 92ad19be5f8785826b0e87504e9503863c885a3b Mon Sep 17 00:00:00 2001 From: guitavano Date: Fri, 4 Oct 2024 11:21:18 -0300 Subject: [PATCH 11/22] remov throw --- vtex/utils/similars.ts | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/vtex/utils/similars.ts b/vtex/utils/similars.ts index fe804f465..1ba304260 100644 --- a/vtex/utils/similars.ts +++ b/vtex/utils/similars.ts @@ -13,20 +13,14 @@ export const withIsSimilarTo = async ( return product; } - let isSimilarTo = undefined; - - try{ - isSimilarTo = await relatedProductsLoader( - { - crossSelling: "similars", - id: product.inProductGroupWithID, - }, - req, - ctx, - ); - }catch(e){ - console.error(e) - } + const isSimilarTo = await relatedProductsLoader( + { + crossSelling: "similars", + id: product.inProductGroupWithID, + }, + req, + ctx, + ); return { ...product, From 50d3d4c223da78a1b44aa22cb2129bde5b3a4bd5 Mon Sep 17 00:00:00 2001 From: marcoferreiradev Date: Mon, 7 Oct 2024 14:45:10 -0300 Subject: [PATCH 12/22] feat: adds address list loader Co-authored-by: @yuri_assuncx --- .../storefront/storefront.graphql.gen.ts | 7 + vtex/loaders/address/list.ts | 71 ++++++++ vtex/manifest.gen.ts | 162 +++++++++--------- 3 files changed, 160 insertions(+), 80 deletions(-) create mode 100644 vtex/loaders/address/list.ts diff --git a/shopify/utils/storefront/storefront.graphql.gen.ts b/shopify/utils/storefront/storefront.graphql.gen.ts index 79e3afe54..f0f734a23 100644 --- a/shopify/utils/storefront/storefront.graphql.gen.ts +++ b/shopify/utils/storefront/storefront.graphql.gen.ts @@ -7779,6 +7779,13 @@ export type FetchCustomerInfoQueryVariables = Exact<{ }>; +export type FetchCustomerInfoQuery = { customer?: { id: string, email?: string | null, firstName?: string | null, lastName?: string | null } | null }; + +export type FetchCustomerInfoQueryVariables = Exact<{ + customerAccessToken: Scalars['String']['input']; +}>; + + export type FetchCustomerInfoQuery = { customer?: { id: string, email?: string | null, firstName?: string | null, lastName?: string | null } | null }; export type AddItemToCartMutationVariables = Exact<{ diff --git a/vtex/loaders/address/list.ts b/vtex/loaders/address/list.ts new file mode 100644 index 000000000..0aa5c9cc7 --- /dev/null +++ b/vtex/loaders/address/list.ts @@ -0,0 +1,71 @@ +import { Address } from "../../utils/types.ts"; +import { PostalAddress } from "../../../commerce/types.ts"; +import { parseCookie } from "../../utils/vtexId.ts"; +import { AppContext } from "../../mod.ts"; + +export interface User { + id: string; + userId: string; + email: string; + firstName?: string; + lastName?: string; + profilePicture?: string; + gender?: string; + document?: string; + homePhone?: string; + birthDate?: string; + corporateDocument?: string; + corporateName?: string; + tradeName?: string; + businessPhone?: string; + isCorporate?: boolean; + customFields?: { key: string; value: string }[]; +} + +async function loader( + _props: unknown, + req: Request, + ctx: AppContext, +): Promise { + const { io } = ctx; + const { cookie, payload } = parseCookie(req.headers, ctx.account); + + if (!payload?.sub || !payload?.userId) { + return null; + } + + const query = `query getUserAddresses { + profile { + addresses { + city + country + postalCode + state + street + } + } + }`; + + try { + const { profile } = await io.query< + { profile: { addresses: Address[] } }, + null + >( + { query }, + { headers: { cookie } }, + ); + + return profile?.addresses?.map((address) => ({ + "@type": "PostalAddress", + addressCountry: address?.country, + addressLocality: address?.city, + addressRegion: address?.state, + postalCode: address?.postalCode, + streetAddress: address?.street, + })); + } catch (_) { + return null; + } +} + +export default loader; diff --git a/vtex/manifest.gen.ts b/vtex/manifest.gen.ts index 41d235212..2c7c21c88 100644 --- a/vtex/manifest.gen.ts +++ b/vtex/manifest.gen.ts @@ -32,92 +32,94 @@ import * as $$$$$$$$$26 from "./actions/trigger.ts"; import * as $$$$$$$$$27 from "./actions/wishlist/addItem.ts"; import * as $$$$$$$$$28 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"; -import * as $$$2 from "./loaders/collections/list.ts"; -import * as $$$3 from "./loaders/config.ts"; -import * as $$$4 from "./loaders/intelligentSearch/productDetailsPage.ts"; -import * as $$$5 from "./loaders/intelligentSearch/productList.ts"; -import * as $$$6 from "./loaders/intelligentSearch/productListingPage.ts"; -import * as $$$7 from "./loaders/intelligentSearch/productSearchValidator.ts"; -import * as $$$8 from "./loaders/intelligentSearch/suggestions.ts"; -import * as $$$9 from "./loaders/intelligentSearch/topsearches.ts"; -import * as $$$10 from "./loaders/legacy/brands.ts"; -import * as $$$11 from "./loaders/legacy/pageType.ts"; -import * as $$$12 from "./loaders/legacy/productDetailsPage.ts"; -import * as $$$13 from "./loaders/legacy/productList.ts"; -import * as $$$14 from "./loaders/legacy/productListingPage.ts"; -import * as $$$15 from "./loaders/legacy/relatedProductsLoader.ts"; -import * as $$$16 from "./loaders/legacy/suggestions.ts"; -import * as $$$17 from "./loaders/logistics/listPickupPoints.ts"; -import * as $$$18 from "./loaders/logistics/listPickupPointsByLocation.ts"; -import * as $$$19 from "./loaders/masterdata/searchDocuments.ts"; -import * as $$$20 from "./loaders/navbar.ts"; -import * as $$$21 from "./loaders/options/productIdByTerm.ts"; -import * as $$$22 from "./loaders/orders/list.ts"; -import * as $$$23 from "./loaders/orders/order.ts"; -import * as $$$24 from "./loaders/paths/PDPDefaultPath.ts"; -import * as $$$25 from "./loaders/paths/PLPDefaultPath.ts"; -import * as $$$26 from "./loaders/payments/info.ts"; -import * as $$$27 from "./loaders/payments/userPayments.ts"; -import * as $$$28 from "./loaders/product/extend.ts"; -import * as $$$29 from "./loaders/product/extensions/detailsPage.ts"; -import * as $$$30 from "./loaders/product/extensions/list.ts"; -import * as $$$31 from "./loaders/product/extensions/listingPage.ts"; -import * as $$$32 from "./loaders/product/extensions/suggestions.ts"; -import * as $$$33 from "./loaders/product/wishlist.ts"; -import * as $$$34 from "./loaders/proxy.ts"; -import * as $$$35 from "./loaders/sessions/info.ts"; -import * as $$$36 from "./loaders/user.ts"; -import * as $$$37 from "./loaders/wishlist.ts"; -import * as $$$38 from "./loaders/workflow/product.ts"; -import * as $$$39 from "./loaders/workflow/products.ts"; +import * as $$$0 from "./loaders/address/list.ts"; +import * as $$$1 from "./loaders/cart.ts"; +import * as $$$2 from "./loaders/categories/tree.ts"; +import * as $$$3 from "./loaders/collections/list.ts"; +import * as $$$4 from "./loaders/config.ts"; +import * as $$$5 from "./loaders/intelligentSearch/productDetailsPage.ts"; +import * as $$$6 from "./loaders/intelligentSearch/productList.ts"; +import * as $$$7 from "./loaders/intelligentSearch/productListingPage.ts"; +import * as $$$8 from "./loaders/intelligentSearch/productSearchValidator.ts"; +import * as $$$9 from "./loaders/intelligentSearch/suggestions.ts"; +import * as $$$10 from "./loaders/intelligentSearch/topsearches.ts"; +import * as $$$11 from "./loaders/legacy/brands.ts"; +import * as $$$12 from "./loaders/legacy/pageType.ts"; +import * as $$$13 from "./loaders/legacy/productDetailsPage.ts"; +import * as $$$14 from "./loaders/legacy/productList.ts"; +import * as $$$15 from "./loaders/legacy/productListingPage.ts"; +import * as $$$16 from "./loaders/legacy/relatedProductsLoader.ts"; +import * as $$$17 from "./loaders/legacy/suggestions.ts"; +import * as $$$18 from "./loaders/logistics/listPickupPoints.ts"; +import * as $$$19 from "./loaders/logistics/listPickupPointsByLocation.ts"; +import * as $$$20 from "./loaders/masterdata/searchDocuments.ts"; +import * as $$$21 from "./loaders/navbar.ts"; +import * as $$$22 from "./loaders/options/productIdByTerm.ts"; +import * as $$$23 from "./loaders/orders/list.ts"; +import * as $$$24 from "./loaders/orders/order.ts"; +import * as $$$25 from "./loaders/paths/PDPDefaultPath.ts"; +import * as $$$26 from "./loaders/paths/PLPDefaultPath.ts"; +import * as $$$27 from "./loaders/payments/info.ts"; +import * as $$$28 from "./loaders/payments/userPayments.ts"; +import * as $$$29 from "./loaders/product/extend.ts"; +import * as $$$30 from "./loaders/product/extensions/detailsPage.ts"; +import * as $$$31 from "./loaders/product/extensions/list.ts"; +import * as $$$32 from "./loaders/product/extensions/listingPage.ts"; +import * as $$$33 from "./loaders/product/extensions/suggestions.ts"; +import * as $$$34 from "./loaders/product/wishlist.ts"; +import * as $$$35 from "./loaders/proxy.ts"; +import * as $$$36 from "./loaders/sessions/info.ts"; +import * as $$$37 from "./loaders/user.ts"; +import * as $$$38 from "./loaders/wishlist.ts"; +import * as $$$39 from "./loaders/workflow/product.ts"; +import * as $$$40 from "./loaders/workflow/products.ts"; import * as $$$$$$0 from "./sections/Analytics/Vtex.tsx"; import * as $$$$$$$$$$0 from "./workflows/events.ts"; import * as $$$$$$$$$$1 from "./workflows/product/index.ts"; const manifest = { "loaders": { - "vtex/loaders/cart.ts": $$$0, - "vtex/loaders/categories/tree.ts": $$$1, - "vtex/loaders/collections/list.ts": $$$2, - "vtex/loaders/config.ts": $$$3, - "vtex/loaders/intelligentSearch/productDetailsPage.ts": $$$4, - "vtex/loaders/intelligentSearch/productList.ts": $$$5, - "vtex/loaders/intelligentSearch/productListingPage.ts": $$$6, - "vtex/loaders/intelligentSearch/productSearchValidator.ts": $$$7, - "vtex/loaders/intelligentSearch/suggestions.ts": $$$8, - "vtex/loaders/intelligentSearch/topsearches.ts": $$$9, - "vtex/loaders/legacy/brands.ts": $$$10, - "vtex/loaders/legacy/pageType.ts": $$$11, - "vtex/loaders/legacy/productDetailsPage.ts": $$$12, - "vtex/loaders/legacy/productList.ts": $$$13, - "vtex/loaders/legacy/productListingPage.ts": $$$14, - "vtex/loaders/legacy/relatedProductsLoader.ts": $$$15, - "vtex/loaders/legacy/suggestions.ts": $$$16, - "vtex/loaders/logistics/listPickupPoints.ts": $$$17, - "vtex/loaders/logistics/listPickupPointsByLocation.ts": $$$18, - "vtex/loaders/masterdata/searchDocuments.ts": $$$19, - "vtex/loaders/navbar.ts": $$$20, - "vtex/loaders/options/productIdByTerm.ts": $$$21, - "vtex/loaders/orders/list.ts": $$$22, - "vtex/loaders/orders/order.ts": $$$23, - "vtex/loaders/paths/PDPDefaultPath.ts": $$$24, - "vtex/loaders/paths/PLPDefaultPath.ts": $$$25, - "vtex/loaders/payments/info.ts": $$$26, - "vtex/loaders/payments/userPayments.ts": $$$27, - "vtex/loaders/product/extend.ts": $$$28, - "vtex/loaders/product/extensions/detailsPage.ts": $$$29, - "vtex/loaders/product/extensions/list.ts": $$$30, - "vtex/loaders/product/extensions/listingPage.ts": $$$31, - "vtex/loaders/product/extensions/suggestions.ts": $$$32, - "vtex/loaders/product/wishlist.ts": $$$33, - "vtex/loaders/proxy.ts": $$$34, - "vtex/loaders/sessions/info.ts": $$$35, - "vtex/loaders/user.ts": $$$36, - "vtex/loaders/wishlist.ts": $$$37, - "vtex/loaders/workflow/product.ts": $$$38, - "vtex/loaders/workflow/products.ts": $$$39, + "vtex/loaders/address/list.ts": $$$0, + "vtex/loaders/cart.ts": $$$1, + "vtex/loaders/categories/tree.ts": $$$2, + "vtex/loaders/collections/list.ts": $$$3, + "vtex/loaders/config.ts": $$$4, + "vtex/loaders/intelligentSearch/productDetailsPage.ts": $$$5, + "vtex/loaders/intelligentSearch/productList.ts": $$$6, + "vtex/loaders/intelligentSearch/productListingPage.ts": $$$7, + "vtex/loaders/intelligentSearch/productSearchValidator.ts": $$$8, + "vtex/loaders/intelligentSearch/suggestions.ts": $$$9, + "vtex/loaders/intelligentSearch/topsearches.ts": $$$10, + "vtex/loaders/legacy/brands.ts": $$$11, + "vtex/loaders/legacy/pageType.ts": $$$12, + "vtex/loaders/legacy/productDetailsPage.ts": $$$13, + "vtex/loaders/legacy/productList.ts": $$$14, + "vtex/loaders/legacy/productListingPage.ts": $$$15, + "vtex/loaders/legacy/relatedProductsLoader.ts": $$$16, + "vtex/loaders/legacy/suggestions.ts": $$$17, + "vtex/loaders/logistics/listPickupPoints.ts": $$$18, + "vtex/loaders/logistics/listPickupPointsByLocation.ts": $$$19, + "vtex/loaders/masterdata/searchDocuments.ts": $$$20, + "vtex/loaders/navbar.ts": $$$21, + "vtex/loaders/options/productIdByTerm.ts": $$$22, + "vtex/loaders/orders/list.ts": $$$23, + "vtex/loaders/orders/order.ts": $$$24, + "vtex/loaders/paths/PDPDefaultPath.ts": $$$25, + "vtex/loaders/paths/PLPDefaultPath.ts": $$$26, + "vtex/loaders/payments/info.ts": $$$27, + "vtex/loaders/payments/userPayments.ts": $$$28, + "vtex/loaders/product/extend.ts": $$$29, + "vtex/loaders/product/extensions/detailsPage.ts": $$$30, + "vtex/loaders/product/extensions/list.ts": $$$31, + "vtex/loaders/product/extensions/listingPage.ts": $$$32, + "vtex/loaders/product/extensions/suggestions.ts": $$$33, + "vtex/loaders/product/wishlist.ts": $$$34, + "vtex/loaders/proxy.ts": $$$35, + "vtex/loaders/sessions/info.ts": $$$36, + "vtex/loaders/user.ts": $$$37, + "vtex/loaders/wishlist.ts": $$$38, + "vtex/loaders/workflow/product.ts": $$$39, + "vtex/loaders/workflow/products.ts": $$$40, }, "handlers": { "vtex/handlers/sitemap.ts": $$$$0, From 647f3e63a04081dc940dadafa314878262953f4a Mon Sep 17 00:00:00 2001 From: marcoferreiradev Date: Wed, 9 Oct 2024 19:29:19 -0300 Subject: [PATCH 13/22] feat: add loader to check if the password has already been changed --- vtex/loaders/profile/passwordLastUpdate.ts | 39 ++++++++++++++++++++++ vtex/manifest.gen.ts | 26 ++++++++------- 2 files changed, 53 insertions(+), 12 deletions(-) create mode 100644 vtex/loaders/profile/passwordLastUpdate.ts diff --git a/vtex/loaders/profile/passwordLastUpdate.ts b/vtex/loaders/profile/passwordLastUpdate.ts new file mode 100644 index 000000000..f60d69731 --- /dev/null +++ b/vtex/loaders/profile/passwordLastUpdate.ts @@ -0,0 +1,39 @@ +import { AppContext } from "../../mod.ts"; +import { parseCookie } from "../../utils/vtexId.ts"; + +export interface ProfilePassword { + passwordLastUpdate?: PasswordLastUpdate; +} + +export type PasswordLastUpdate = string | null; + +async function loader( + _props: unknown, + req: Request, + ctx: AppContext, +): Promise { + const { io } = ctx; + const { cookie, payload } = parseCookie(req.headers, ctx.account); + + if (!payload?.sub || !payload?.userId) { + return null; + } + console.log({ teste: payload?.userId }); + + const query = `query getUserProfile { profile { passwordLastUpdate }}`; + + try { + const { profile } = await io.query<{ profile: ProfilePassword }, null>( + { query }, + { headers: { cookie } }, + ); + + console.log({ profile }); + + return profile.passwordLastUpdate ?? null; + } catch (_) { + return null; + } +} + +export default loader; diff --git a/vtex/manifest.gen.ts b/vtex/manifest.gen.ts index 2c7c21c88..27cb89cdd 100644 --- a/vtex/manifest.gen.ts +++ b/vtex/manifest.gen.ts @@ -67,12 +67,13 @@ import * as $$$31 from "./loaders/product/extensions/list.ts"; import * as $$$32 from "./loaders/product/extensions/listingPage.ts"; import * as $$$33 from "./loaders/product/extensions/suggestions.ts"; import * as $$$34 from "./loaders/product/wishlist.ts"; -import * as $$$35 from "./loaders/proxy.ts"; -import * as $$$36 from "./loaders/sessions/info.ts"; -import * as $$$37 from "./loaders/user.ts"; -import * as $$$38 from "./loaders/wishlist.ts"; -import * as $$$39 from "./loaders/workflow/product.ts"; -import * as $$$40 from "./loaders/workflow/products.ts"; +import * as $$$35 from "./loaders/profile/passwordLastUpdate.ts"; +import * as $$$36 from "./loaders/proxy.ts"; +import * as $$$37 from "./loaders/sessions/info.ts"; +import * as $$$38 from "./loaders/user.ts"; +import * as $$$39 from "./loaders/wishlist.ts"; +import * as $$$40 from "./loaders/workflow/product.ts"; +import * as $$$41 from "./loaders/workflow/products.ts"; import * as $$$$$$0 from "./sections/Analytics/Vtex.tsx"; import * as $$$$$$$$$$0 from "./workflows/events.ts"; import * as $$$$$$$$$$1 from "./workflows/product/index.ts"; @@ -114,12 +115,13 @@ const manifest = { "vtex/loaders/product/extensions/listingPage.ts": $$$32, "vtex/loaders/product/extensions/suggestions.ts": $$$33, "vtex/loaders/product/wishlist.ts": $$$34, - "vtex/loaders/proxy.ts": $$$35, - "vtex/loaders/sessions/info.ts": $$$36, - "vtex/loaders/user.ts": $$$37, - "vtex/loaders/wishlist.ts": $$$38, - "vtex/loaders/workflow/product.ts": $$$39, - "vtex/loaders/workflow/products.ts": $$$40, + "vtex/loaders/profile/passwordLastUpdate.ts": $$$35, + "vtex/loaders/proxy.ts": $$$36, + "vtex/loaders/sessions/info.ts": $$$37, + "vtex/loaders/user.ts": $$$38, + "vtex/loaders/wishlist.ts": $$$39, + "vtex/loaders/workflow/product.ts": $$$40, + "vtex/loaders/workflow/products.ts": $$$41, }, "handlers": { "vtex/handlers/sitemap.ts": $$$$0, From b617008d78e69ae3b076bedfa4787e1a48e73e1a Mon Sep 17 00:00:00 2001 From: soutofernando Date: Fri, 11 Oct 2024 11:54:26 -0300 Subject: [PATCH 14/22] fix: receive address update props --- vtex/actions/address/updateAddress.ts | 60 +++++++++++++-------------- vtex/loaders/address/list.ts | 8 +++- 2 files changed, 36 insertions(+), 32 deletions(-) diff --git a/vtex/actions/address/updateAddress.ts b/vtex/actions/address/updateAddress.ts index 27135c375..f1893653c 100644 --- a/vtex/actions/address/updateAddress.ts +++ b/vtex/actions/address/updateAddress.ts @@ -4,7 +4,7 @@ import { parseCookie } from "../../utils/vtexId.ts"; interface Address { name?: string; - addressName?: string; + addressName: string; addressType?: string; city?: string; complement?: string; @@ -20,45 +20,44 @@ interface Address { } interface AddressInput { - addressId?: string; - name?: string; - addressName?: string; - addressType?: string; - city?: string; - complement?: string; - country?: string; - geoCoordinates?: number[]; - neighborhood?: string; - number?: string; - postalCode?: string; receiverName?: string; - reference?: string; + complement?: string | null; + neighborhood?: string | null; + country?: string; state?: string; + number?: string | null; street?: string; + geoCoordinates?: number[]; + postalCode?: string; + city?: string; + reference?: string | null; + addressName: string; + addressType?: string; } async function loader( - _props: unknown, + props: Address, req: Request, ctx: AppContext, -): Promise { +): Promise { const { io } = ctx; const { cookie } = parseCookie(req.headers, ctx.account); + const id = props.addressName; const moc: AddressInput = { - addressType: "Residential", - addressName: "Home Address", - city: "Los Angeles", - complement: "Apt 4B", + addressName: "l1ov8h0kea", + addressType: "residential", + city: "SAINT GEORGE", + complement: null, country: "USA", - neighborhood: "Downtown", - number: "1234", - postalCode: "90001", - geoCoordinates: [-111.98, 40.74], - receiverName: "John Maria", - reference: "Near the central park", - state: "UTA", - street: "Main St", + geoCoordinates: [-113.57, 37.06], + neighborhood: null, + number: null, + postalCode: "84790", + receiverName: "Joao maria", + reference: null, + state: "UT", + street: "SAINT GEORGE, UT - 4555", }; const mutation = ` @@ -94,10 +93,8 @@ async function loader( query: mutation, operationName: "UpdateAddress", variables: { - addressId: "9y11rmhpsq", - addressFields: { - ...moc, - }, + addressId: id, + addressFields: props, }, }, { headers: { cookie } }, @@ -110,6 +107,7 @@ async function loader( addressRegion: updatedAddress?.state, postalCode: updatedAddress?.postalCode, streetAddress: updatedAddress?.street, + receiverName: updatedAddress?.receiverName, }; } catch (error) { console.error("Error updating address:", error); diff --git a/vtex/loaders/address/list.ts b/vtex/loaders/address/list.ts index 0aa5c9cc7..7caf8033f 100644 --- a/vtex/loaders/address/list.ts +++ b/vtex/loaders/address/list.ts @@ -26,7 +26,9 @@ async function loader( _props: unknown, req: Request, ctx: AppContext, -): Promise { +): Promise< + PostalAddress[] & { receiverName?: string; addressName?: string } | null +> { const { io } = ctx; const { cookie, payload } = parseCookie(req.headers, ctx.account); @@ -42,6 +44,8 @@ async function loader( postalCode state street + receiverName + addressName } } }`; @@ -62,6 +66,8 @@ async function loader( addressRegion: address?.state, postalCode: address?.postalCode, streetAddress: address?.street, + receiverName: address?.receiverName, + addressName: address?.addressName, })); } catch (_) { return null; From d9c45c62da3f3b13bddcc3d9b0a35d05ce413d4b Mon Sep 17 00:00:00 2001 From: soutofernando Date: Fri, 11 Oct 2024 14:54:00 -0300 Subject: [PATCH 15/22] feat: create adress action --- vtex/actions/address/createAddress.ts | 91 ++++++++++++++++++++ vtex/actions/address/updateAddress.ts | 22 ++--- vtex/loaders/address/list.ts | 8 +- vtex/manifest.gen.ts | 118 +++++++++++++------------- 4 files changed, 163 insertions(+), 76 deletions(-) create mode 100644 vtex/actions/address/createAddress.ts diff --git a/vtex/actions/address/createAddress.ts b/vtex/actions/address/createAddress.ts new file mode 100644 index 000000000..6d16f3588 --- /dev/null +++ b/vtex/actions/address/createAddress.ts @@ -0,0 +1,91 @@ +import { PostalAddress } from "../../../commerce/types.ts"; +import { AppContext } from "../../mod.ts"; +import { parseCookie } from "../../utils/vtexId.ts"; + +interface Address { + name?: string; + addressName: string; + addressType?: string; + city?: string; + complement?: string; + country?: string; + geoCoordinates?: number[]; + neighborhood?: string; + number?: string; + postalCode?: string; + receiverName?: string; + reference?: string; + state?: string; + street?: string; +} + +interface AddressInput { + receiverName?: string; + complement?: string | null; + neighborhood?: string | null; + country?: string; + state?: string; + number?: string | null; + street?: string; + geoCoordinates?: number[]; + postalCode?: string; + city?: string; + reference?: string | null; + addressName: string; + addressType?: string; +} + +async function loader( + props: Address, + req: Request, + ctx: AppContext, +): Promise< + | PostalAddress & { + receiverName?: string | null; + complement?: string | null; + } + | null +> { + const { io } = ctx; + const { cookie } = parseCookie(req.headers, ctx.account); + + const mutation = ` + mutation SaveAddress($address: AddressInput!) { + saveAddress(address: $address) @context(provider: "vtex.store-graphql") { + id + cacheId + } + }`; + + try { + const { saveAddress: updatedAddress } = await io.query< + { saveAddress: Address }, + { address: AddressInput } + >( + { + query: mutation, + operationName: "SaveAddress", + variables: { + address: props, + }, + }, + { headers: { cookie } }, + ); + + return { + "@type": "PostalAddress", + addressCountry: updatedAddress?.country, + addressLocality: updatedAddress?.city, + addressRegion: updatedAddress?.state, + postalCode: updatedAddress?.postalCode, + streetAddress: updatedAddress?.street, + receiverName: updatedAddress?.receiverName, + complement: updatedAddress?.complement, + }; + } catch (error) { + console.error("Error saving address:", error); + return null; + } +} + +export default loader; diff --git a/vtex/actions/address/updateAddress.ts b/vtex/actions/address/updateAddress.ts index f1893653c..ccddc0d35 100644 --- a/vtex/actions/address/updateAddress.ts +++ b/vtex/actions/address/updateAddress.ts @@ -39,27 +39,14 @@ async function loader( props: Address, req: Request, ctx: AppContext, -): Promise { +): Promise< + | PostalAddress & { receiverName?: string | null; complement?: string | null } + | null +> { const { io } = ctx; const { cookie } = parseCookie(req.headers, ctx.account); const id = props.addressName; - const moc: AddressInput = { - addressName: "l1ov8h0kea", - addressType: "residential", - city: "SAINT GEORGE", - complement: null, - country: "USA", - geoCoordinates: [-113.57, 37.06], - neighborhood: null, - number: null, - postalCode: "84790", - receiverName: "Joao maria", - reference: null, - state: "UT", - street: "SAINT GEORGE, UT - 4555", - }; - const mutation = ` mutation UpdateAddress($addressId: String, $addressFields: AddressInput) { updateAddress(id: $addressId, fields: $addressFields) @@ -108,6 +95,7 @@ async function loader( postalCode: updatedAddress?.postalCode, streetAddress: updatedAddress?.street, receiverName: updatedAddress?.receiverName, + complement: updatedAddress?.complement, }; } catch (error) { console.error("Error updating address:", error); diff --git a/vtex/loaders/address/list.ts b/vtex/loaders/address/list.ts index 7caf8033f..718b68887 100644 --- a/vtex/loaders/address/list.ts +++ b/vtex/loaders/address/list.ts @@ -27,7 +27,11 @@ async function loader( req: Request, ctx: AppContext, ): Promise< - PostalAddress[] & { receiverName?: string; addressName?: string } | null + PostalAddress[] & { + receiverName?: string; + addressName?: string; + complement?: string | null; + } | null > { const { io } = ctx; const { cookie, payload } = parseCookie(req.headers, ctx.account); @@ -46,6 +50,7 @@ async function loader( street receiverName addressName + complement } } }`; @@ -68,6 +73,7 @@ async function loader( streetAddress: address?.street, receiverName: address?.receiverName, addressName: address?.addressName, + complement: address?.complement, })); } catch (_) { return null; diff --git a/vtex/manifest.gen.ts b/vtex/manifest.gen.ts index 27cb89cdd..e41ce7090 100644 --- a/vtex/manifest.gen.ts +++ b/vtex/manifest.gen.ts @@ -2,35 +2,36 @@ // This file SHOULD be checked into source version control. // This file is automatically updated during development when running `dev.ts`. -import * as $$$$$$$$$0 from "./actions/address/updateAddress.ts"; -import * as $$$$$$$$$1 from "./actions/analytics/sendEvent.ts"; -import * as $$$$$$$$$2 from "./actions/cart/addItems.ts"; -import * as $$$$$$$$$3 from "./actions/cart/addOfferings.ts"; -import * as $$$$$$$$$4 from "./actions/cart/clearOrderformMessages.ts"; -import * as $$$$$$$$$5 from "./actions/cart/getInstallment.ts"; -import * as $$$$$$$$$6 from "./actions/cart/removeItemAttachment.ts"; -import * as $$$$$$$$$7 from "./actions/cart/removeItems.ts"; -import * as $$$$$$$$$8 from "./actions/cart/removeOffering.ts"; -import * as $$$$$$$$$9 from "./actions/cart/simulation.ts"; -import * as $$$$$$$$$10 from "./actions/cart/updateAttachment.ts"; -import * as $$$$$$$$$11 from "./actions/cart/updateCoupons.ts"; -import * as $$$$$$$$$12 from "./actions/cart/updateGifts.ts"; -import * as $$$$$$$$$13 from "./actions/cart/updateItemAttachment.ts"; -import * as $$$$$$$$$14 from "./actions/cart/updateItemPrice.ts"; -import * as $$$$$$$$$15 from "./actions/cart/updateItems.ts"; -import * as $$$$$$$$$16 from "./actions/cart/updateProfile.ts"; -import * as $$$$$$$$$17 from "./actions/cart/updateUser.ts"; -import * as $$$$$$$$$18 from "./actions/masterdata/createDocument.ts"; -import * as $$$$$$$$$19 from "./actions/newsletter/subscribe.ts"; -import * as $$$$$$$$$20 from "./actions/notifyme.ts"; -import * as $$$$$$$$$21 from "./actions/payments/delete.ts"; -import * as $$$$$$$$$22 from "./actions/profile/newsletterProfile.ts"; -import * as $$$$$$$$$23 from "./actions/profile/updateProfile.ts"; -import * as $$$$$$$$$24 from "./actions/review/submit.ts"; -import * as $$$$$$$$$25 from "./actions/sessions/delete.ts"; -import * as $$$$$$$$$26 from "./actions/trigger.ts"; -import * as $$$$$$$$$27 from "./actions/wishlist/addItem.ts"; -import * as $$$$$$$$$28 from "./actions/wishlist/removeItem.ts"; +import * as $$$$$$$$$0 from "./actions/address/createAddress.ts"; +import * as $$$$$$$$$1 from "./actions/address/updateAddress.ts"; +import * as $$$$$$$$$2 from "./actions/analytics/sendEvent.ts"; +import * as $$$$$$$$$3 from "./actions/cart/addItems.ts"; +import * as $$$$$$$$$4 from "./actions/cart/addOfferings.ts"; +import * as $$$$$$$$$5 from "./actions/cart/clearOrderformMessages.ts"; +import * as $$$$$$$$$6 from "./actions/cart/getInstallment.ts"; +import * as $$$$$$$$$7 from "./actions/cart/removeItemAttachment.ts"; +import * as $$$$$$$$$8 from "./actions/cart/removeItems.ts"; +import * as $$$$$$$$$9 from "./actions/cart/removeOffering.ts"; +import * as $$$$$$$$$10 from "./actions/cart/simulation.ts"; +import * as $$$$$$$$$11 from "./actions/cart/updateAttachment.ts"; +import * as $$$$$$$$$12 from "./actions/cart/updateCoupons.ts"; +import * as $$$$$$$$$13 from "./actions/cart/updateGifts.ts"; +import * as $$$$$$$$$14 from "./actions/cart/updateItemAttachment.ts"; +import * as $$$$$$$$$15 from "./actions/cart/updateItemPrice.ts"; +import * as $$$$$$$$$16 from "./actions/cart/updateItems.ts"; +import * as $$$$$$$$$17 from "./actions/cart/updateProfile.ts"; +import * as $$$$$$$$$18 from "./actions/cart/updateUser.ts"; +import * as $$$$$$$$$19 from "./actions/masterdata/createDocument.ts"; +import * as $$$$$$$$$20 from "./actions/newsletter/subscribe.ts"; +import * as $$$$$$$$$21 from "./actions/notifyme.ts"; +import * as $$$$$$$$$22 from "./actions/payments/delete.ts"; +import * as $$$$$$$$$23 from "./actions/profile/newsletterProfile.ts"; +import * as $$$$$$$$$24 from "./actions/profile/updateProfile.ts"; +import * as $$$$$$$$$25 from "./actions/review/submit.ts"; +import * as $$$$$$$$$26 from "./actions/sessions/delete.ts"; +import * as $$$$$$$$$27 from "./actions/trigger.ts"; +import * as $$$$$$$$$28 from "./actions/wishlist/addItem.ts"; +import * as $$$$$$$$$29 from "./actions/wishlist/removeItem.ts"; import * as $$$$0 from "./handlers/sitemap.ts"; import * as $$$0 from "./loaders/address/list.ts"; import * as $$$1 from "./loaders/cart.ts"; @@ -130,35 +131,36 @@ const manifest = { "vtex/sections/Analytics/Vtex.tsx": $$$$$$0, }, "actions": { - "vtex/actions/address/updateAddress.ts": $$$$$$$$$0, - "vtex/actions/analytics/sendEvent.ts": $$$$$$$$$1, - "vtex/actions/cart/addItems.ts": $$$$$$$$$2, - "vtex/actions/cart/addOfferings.ts": $$$$$$$$$3, - "vtex/actions/cart/clearOrderformMessages.ts": $$$$$$$$$4, - "vtex/actions/cart/getInstallment.ts": $$$$$$$$$5, - "vtex/actions/cart/removeItemAttachment.ts": $$$$$$$$$6, - "vtex/actions/cart/removeItems.ts": $$$$$$$$$7, - "vtex/actions/cart/removeOffering.ts": $$$$$$$$$8, - "vtex/actions/cart/simulation.ts": $$$$$$$$$9, - "vtex/actions/cart/updateAttachment.ts": $$$$$$$$$10, - "vtex/actions/cart/updateCoupons.ts": $$$$$$$$$11, - "vtex/actions/cart/updateGifts.ts": $$$$$$$$$12, - "vtex/actions/cart/updateItemAttachment.ts": $$$$$$$$$13, - "vtex/actions/cart/updateItemPrice.ts": $$$$$$$$$14, - "vtex/actions/cart/updateItems.ts": $$$$$$$$$15, - "vtex/actions/cart/updateProfile.ts": $$$$$$$$$16, - "vtex/actions/cart/updateUser.ts": $$$$$$$$$17, - "vtex/actions/masterdata/createDocument.ts": $$$$$$$$$18, - "vtex/actions/newsletter/subscribe.ts": $$$$$$$$$19, - "vtex/actions/notifyme.ts": $$$$$$$$$20, - "vtex/actions/payments/delete.ts": $$$$$$$$$21, - "vtex/actions/profile/newsletterProfile.ts": $$$$$$$$$22, - "vtex/actions/profile/updateProfile.ts": $$$$$$$$$23, - "vtex/actions/review/submit.ts": $$$$$$$$$24, - "vtex/actions/sessions/delete.ts": $$$$$$$$$25, - "vtex/actions/trigger.ts": $$$$$$$$$26, - "vtex/actions/wishlist/addItem.ts": $$$$$$$$$27, - "vtex/actions/wishlist/removeItem.ts": $$$$$$$$$28, + "vtex/actions/address/createAddress.ts": $$$$$$$$$0, + "vtex/actions/address/updateAddress.ts": $$$$$$$$$1, + "vtex/actions/analytics/sendEvent.ts": $$$$$$$$$2, + "vtex/actions/cart/addItems.ts": $$$$$$$$$3, + "vtex/actions/cart/addOfferings.ts": $$$$$$$$$4, + "vtex/actions/cart/clearOrderformMessages.ts": $$$$$$$$$5, + "vtex/actions/cart/getInstallment.ts": $$$$$$$$$6, + "vtex/actions/cart/removeItemAttachment.ts": $$$$$$$$$7, + "vtex/actions/cart/removeItems.ts": $$$$$$$$$8, + "vtex/actions/cart/removeOffering.ts": $$$$$$$$$9, + "vtex/actions/cart/simulation.ts": $$$$$$$$$10, + "vtex/actions/cart/updateAttachment.ts": $$$$$$$$$11, + "vtex/actions/cart/updateCoupons.ts": $$$$$$$$$12, + "vtex/actions/cart/updateGifts.ts": $$$$$$$$$13, + "vtex/actions/cart/updateItemAttachment.ts": $$$$$$$$$14, + "vtex/actions/cart/updateItemPrice.ts": $$$$$$$$$15, + "vtex/actions/cart/updateItems.ts": $$$$$$$$$16, + "vtex/actions/cart/updateProfile.ts": $$$$$$$$$17, + "vtex/actions/cart/updateUser.ts": $$$$$$$$$18, + "vtex/actions/masterdata/createDocument.ts": $$$$$$$$$19, + "vtex/actions/newsletter/subscribe.ts": $$$$$$$$$20, + "vtex/actions/notifyme.ts": $$$$$$$$$21, + "vtex/actions/payments/delete.ts": $$$$$$$$$22, + "vtex/actions/profile/newsletterProfile.ts": $$$$$$$$$23, + "vtex/actions/profile/updateProfile.ts": $$$$$$$$$24, + "vtex/actions/review/submit.ts": $$$$$$$$$25, + "vtex/actions/sessions/delete.ts": $$$$$$$$$26, + "vtex/actions/trigger.ts": $$$$$$$$$27, + "vtex/actions/wishlist/addItem.ts": $$$$$$$$$28, + "vtex/actions/wishlist/removeItem.ts": $$$$$$$$$29, }, "workflows": { "vtex/workflows/events.ts": $$$$$$$$$$0, From 4d783d18b6b592dc30bb068b93ec4606f270359c Mon Sep 17 00:00:00 2001 From: marcoferreiradev Date: Mon, 14 Oct 2024 14:03:31 -0300 Subject: [PATCH 16/22] chore: fixes typing error pointing by linter --- vtex/actions/address/createAddress.ts | 132 +++++++++++++------------- vtex/utils/types.ts | 1 + 2 files changed, 67 insertions(+), 66 deletions(-) diff --git a/vtex/actions/address/createAddress.ts b/vtex/actions/address/createAddress.ts index 6d16f3588..f63917a19 100644 --- a/vtex/actions/address/createAddress.ts +++ b/vtex/actions/address/createAddress.ts @@ -3,53 +3,53 @@ import { AppContext } from "../../mod.ts"; import { parseCookie } from "../../utils/vtexId.ts"; interface Address { - name?: string; - addressName: string; - addressType?: string; - city?: string; - complement?: string; - country?: string; - geoCoordinates?: number[]; - neighborhood?: string; - number?: string; - postalCode?: string; - receiverName?: string; - reference?: string; - state?: string; - street?: string; + name?: string; + addressName: string; + addressType?: string; + city?: string; + complement?: string; + country?: string; + geoCoordinates?: number[]; + neighborhood?: string; + number?: string; + postalCode?: string; + receiverName?: string; + reference?: string; + state?: string; + street?: string; } interface AddressInput { - receiverName?: string; - complement?: string | null; - neighborhood?: string | null; - country?: string; - state?: string; - number?: string | null; - street?: string; - geoCoordinates?: number[]; - postalCode?: string; - city?: string; - reference?: string | null; - addressName: string; - addressType?: string; + receiverName?: string; + complement?: string | null; + neighborhood?: string | null; + country?: string; + state?: string; + number?: string | null; + street?: string; + geoCoordinates?: number[]; + postalCode?: string; + city?: string; + reference?: string | null; + addressName: string; + addressType?: string; } async function loader( - props: Address, - req: Request, - ctx: AppContext, + props: Address, + req: Request, + ctx: AppContext, ): Promise< - | PostalAddress & { - receiverName?: string | null; - complement?: string | null; - } - | null + | PostalAddress & { + receiverName?: string | null; + complement?: string | null; + } + | null > { - const { io } = ctx; - const { cookie } = parseCookie(req.headers, ctx.account); + const { io } = ctx; + const { cookie } = parseCookie(req.headers, ctx.account); - const mutation = ` + const mutation = ` mutation SaveAddress($address: AddressInput!) { saveAddress(address: $address) @context(provider: "vtex.store-graphql") { id @@ -57,35 +57,35 @@ async function loader( } }`; - try { - const { saveAddress: updatedAddress } = await io.query< - { saveAddress: Address }, - { address: AddressInput } - >( - { - query: mutation, - operationName: "SaveAddress", - variables: { - address: props, - }, - }, - { headers: { cookie } }, - ); + try { + const { saveAddress: updatedAddress } = await io.query< + { saveAddress: Address }, + { address: AddressInput } + >( + { + query: mutation, + operationName: "SaveAddress", + variables: { + address: props, + }, + }, + { headers: { cookie } }, + ); - return { - "@type": "PostalAddress", - addressCountry: updatedAddress?.country, - addressLocality: updatedAddress?.city, - addressRegion: updatedAddress?.state, - postalCode: updatedAddress?.postalCode, - streetAddress: updatedAddress?.street, - receiverName: updatedAddress?.receiverName, - complement: updatedAddress?.complement, - }; - } catch (error) { - console.error("Error saving address:", error); - return null; - } + return { + "@type": "PostalAddress", + addressCountry: updatedAddress?.country, + addressLocality: updatedAddress?.city, + addressRegion: updatedAddress?.state, + postalCode: updatedAddress?.postalCode, + streetAddress: updatedAddress?.street, + receiverName: updatedAddress?.receiverName, + complement: updatedAddress?.complement, + }; + } catch (error) { + console.error("Error saving address:", error); + return null; + } } export default loader; diff --git a/vtex/utils/types.ts b/vtex/utils/types.ts index c662603a4..6f32cc987 100644 --- a/vtex/utils/types.ts +++ b/vtex/utils/types.ts @@ -378,6 +378,7 @@ export interface ShippingData { export interface Address { addressType: string; + addressName: string; receiverName: null; addressId: string; isDisposable: boolean; From 036818e66d200eca69faa1565bde449d6a24f029 Mon Sep 17 00:00:00 2001 From: marcoferreiradev Date: Mon, 14 Oct 2024 14:30:31 -0300 Subject: [PATCH 17/22] chore: fixes typing error pointing by linter --- shopify/utils/storefront/storefront.graphql.gen.ts | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/shopify/utils/storefront/storefront.graphql.gen.ts b/shopify/utils/storefront/storefront.graphql.gen.ts index f0f734a23..d4ca1d33b 100644 --- a/shopify/utils/storefront/storefront.graphql.gen.ts +++ b/shopify/utils/storefront/storefront.graphql.gen.ts @@ -7779,13 +7779,6 @@ export type FetchCustomerInfoQueryVariables = Exact<{ }>; -export type FetchCustomerInfoQuery = { customer?: { id: string, email?: string | null, firstName?: string | null, lastName?: string | null } | null }; - -export type FetchCustomerInfoQueryVariables = Exact<{ - customerAccessToken: Scalars['String']['input']; -}>; - - export type FetchCustomerInfoQuery = { customer?: { id: string, email?: string | null, firstName?: string | null, lastName?: string | null } | null }; export type AddItemToCartMutationVariables = Exact<{ @@ -7818,4 +7811,4 @@ export type SignInWithEmailAndPasswordMutationVariables = Exact<{ }>; -export type SignInWithEmailAndPasswordMutation = { customerAccessTokenCreate?: { customerAccessToken?: { accessToken: string, expiresAt: any } | null, customerUserErrors: Array<{ code?: CustomerErrorCode | null, message: string }> } | null }; +export type SignInWithEmailAndPasswordMutation = { customerAccessTokenCreate?: { customerAccessToken?: { accessToken: string, expiresAt: any } | null, customerUserErrors: Array<{ code?: CustomerErrorCode | null, message: string }> } | null }; \ No newline at end of file From febc6ebeceb2ed1fdbb82482019d6c9a81316785 Mon Sep 17 00:00:00 2001 From: soutofernando Date: Mon, 14 Oct 2024 19:33:18 -0300 Subject: [PATCH 18/22] feat: get address by postal code loader --- vtex/loaders/address/getAddressByZIP.ts | 59 ++++++++ vtex/manifest.gen.ts | 170 ++++++++++++------------ 2 files changed, 145 insertions(+), 84 deletions(-) create mode 100644 vtex/loaders/address/getAddressByZIP.ts diff --git a/vtex/loaders/address/getAddressByZIP.ts b/vtex/loaders/address/getAddressByZIP.ts new file mode 100644 index 000000000..a7f7a1e53 --- /dev/null +++ b/vtex/loaders/address/getAddressByZIP.ts @@ -0,0 +1,59 @@ +import { AppContext } from "../../mod.ts"; + +interface Props { + /** + * @description User country code. Ex: USA + */ + countryCode: string; + /** + * @description User postal code. + */ + postalCode: string; +} + +interface AddressByPostalCode { + postalCode: string; + city: string; + state: string; + country: string; + street: string | null; + number: string | null; + neighborhood: string | null; + complement: string | null; + reference: string | null; + geoCoordinates: number[] | null; +} + +export default async function loader( + props: Props, + _req: Request, + ctx: AppContext, +): Promise { + const { countryCode, postalCode } = props; + const { vcs } = ctx; + + try { + const addressByPostalCode = await vcs + ["GET /api/checkout/pub/postal-code/:countryCode/:postalCode"]({ + countryCode, + postalCode, + }) + .then((r) => r.json()) as AddressByPostalCode; + + return addressByPostalCode; + } catch (error) { + console.log(error); + return { + postalCode: "", + city: "", + state: "", + country: "", + street: null, + number: null, + neighborhood: null, + complement: null, + reference: null, + geoCoordinates: [], + }; + } +} diff --git a/vtex/manifest.gen.ts b/vtex/manifest.gen.ts index e41ce7090..9e2bf4193 100644 --- a/vtex/manifest.gen.ts +++ b/vtex/manifest.gen.ts @@ -33,96 +33,98 @@ import * as $$$$$$$$$27 from "./actions/trigger.ts"; import * as $$$$$$$$$28 from "./actions/wishlist/addItem.ts"; import * as $$$$$$$$$29 from "./actions/wishlist/removeItem.ts"; import * as $$$$0 from "./handlers/sitemap.ts"; -import * as $$$0 from "./loaders/address/list.ts"; -import * as $$$1 from "./loaders/cart.ts"; -import * as $$$2 from "./loaders/categories/tree.ts"; -import * as $$$3 from "./loaders/collections/list.ts"; -import * as $$$4 from "./loaders/config.ts"; -import * as $$$5 from "./loaders/intelligentSearch/productDetailsPage.ts"; -import * as $$$6 from "./loaders/intelligentSearch/productList.ts"; -import * as $$$7 from "./loaders/intelligentSearch/productListingPage.ts"; -import * as $$$8 from "./loaders/intelligentSearch/productSearchValidator.ts"; -import * as $$$9 from "./loaders/intelligentSearch/suggestions.ts"; -import * as $$$10 from "./loaders/intelligentSearch/topsearches.ts"; -import * as $$$11 from "./loaders/legacy/brands.ts"; -import * as $$$12 from "./loaders/legacy/pageType.ts"; -import * as $$$13 from "./loaders/legacy/productDetailsPage.ts"; -import * as $$$14 from "./loaders/legacy/productList.ts"; -import * as $$$15 from "./loaders/legacy/productListingPage.ts"; -import * as $$$16 from "./loaders/legacy/relatedProductsLoader.ts"; -import * as $$$17 from "./loaders/legacy/suggestions.ts"; -import * as $$$18 from "./loaders/logistics/listPickupPoints.ts"; -import * as $$$19 from "./loaders/logistics/listPickupPointsByLocation.ts"; -import * as $$$20 from "./loaders/masterdata/searchDocuments.ts"; -import * as $$$21 from "./loaders/navbar.ts"; -import * as $$$22 from "./loaders/options/productIdByTerm.ts"; -import * as $$$23 from "./loaders/orders/list.ts"; -import * as $$$24 from "./loaders/orders/order.ts"; -import * as $$$25 from "./loaders/paths/PDPDefaultPath.ts"; -import * as $$$26 from "./loaders/paths/PLPDefaultPath.ts"; -import * as $$$27 from "./loaders/payments/info.ts"; -import * as $$$28 from "./loaders/payments/userPayments.ts"; -import * as $$$29 from "./loaders/product/extend.ts"; -import * as $$$30 from "./loaders/product/extensions/detailsPage.ts"; -import * as $$$31 from "./loaders/product/extensions/list.ts"; -import * as $$$32 from "./loaders/product/extensions/listingPage.ts"; -import * as $$$33 from "./loaders/product/extensions/suggestions.ts"; -import * as $$$34 from "./loaders/product/wishlist.ts"; -import * as $$$35 from "./loaders/profile/passwordLastUpdate.ts"; -import * as $$$36 from "./loaders/proxy.ts"; -import * as $$$37 from "./loaders/sessions/info.ts"; -import * as $$$38 from "./loaders/user.ts"; -import * as $$$39 from "./loaders/wishlist.ts"; -import * as $$$40 from "./loaders/workflow/product.ts"; -import * as $$$41 from "./loaders/workflow/products.ts"; +import * as $$$0 from "./loaders/address/getAddressByZIP.ts"; +import * as $$$1 from "./loaders/address/list.ts"; +import * as $$$2 from "./loaders/cart.ts"; +import * as $$$3 from "./loaders/categories/tree.ts"; +import * as $$$4 from "./loaders/collections/list.ts"; +import * as $$$5 from "./loaders/config.ts"; +import * as $$$6 from "./loaders/intelligentSearch/productDetailsPage.ts"; +import * as $$$7 from "./loaders/intelligentSearch/productList.ts"; +import * as $$$8 from "./loaders/intelligentSearch/productListingPage.ts"; +import * as $$$9 from "./loaders/intelligentSearch/productSearchValidator.ts"; +import * as $$$10 from "./loaders/intelligentSearch/suggestions.ts"; +import * as $$$11 from "./loaders/intelligentSearch/topsearches.ts"; +import * as $$$12 from "./loaders/legacy/brands.ts"; +import * as $$$13 from "./loaders/legacy/pageType.ts"; +import * as $$$14 from "./loaders/legacy/productDetailsPage.ts"; +import * as $$$15 from "./loaders/legacy/productList.ts"; +import * as $$$16 from "./loaders/legacy/productListingPage.ts"; +import * as $$$17 from "./loaders/legacy/relatedProductsLoader.ts"; +import * as $$$18 from "./loaders/legacy/suggestions.ts"; +import * as $$$19 from "./loaders/logistics/listPickupPoints.ts"; +import * as $$$20 from "./loaders/logistics/listPickupPointsByLocation.ts"; +import * as $$$21 from "./loaders/masterdata/searchDocuments.ts"; +import * as $$$22 from "./loaders/navbar.ts"; +import * as $$$23 from "./loaders/options/productIdByTerm.ts"; +import * as $$$24 from "./loaders/orders/list.ts"; +import * as $$$25 from "./loaders/orders/order.ts"; +import * as $$$26 from "./loaders/paths/PDPDefaultPath.ts"; +import * as $$$27 from "./loaders/paths/PLPDefaultPath.ts"; +import * as $$$28 from "./loaders/payments/info.ts"; +import * as $$$29 from "./loaders/payments/userPayments.ts"; +import * as $$$30 from "./loaders/product/extend.ts"; +import * as $$$31 from "./loaders/product/extensions/detailsPage.ts"; +import * as $$$32 from "./loaders/product/extensions/list.ts"; +import * as $$$33 from "./loaders/product/extensions/listingPage.ts"; +import * as $$$34 from "./loaders/product/extensions/suggestions.ts"; +import * as $$$35 from "./loaders/product/wishlist.ts"; +import * as $$$36 from "./loaders/profile/passwordLastUpdate.ts"; +import * as $$$37 from "./loaders/proxy.ts"; +import * as $$$38 from "./loaders/sessions/info.ts"; +import * as $$$39 from "./loaders/user.ts"; +import * as $$$40 from "./loaders/wishlist.ts"; +import * as $$$41 from "./loaders/workflow/product.ts"; +import * as $$$42 from "./loaders/workflow/products.ts"; import * as $$$$$$0 from "./sections/Analytics/Vtex.tsx"; import * as $$$$$$$$$$0 from "./workflows/events.ts"; import * as $$$$$$$$$$1 from "./workflows/product/index.ts"; const manifest = { "loaders": { - "vtex/loaders/address/list.ts": $$$0, - "vtex/loaders/cart.ts": $$$1, - "vtex/loaders/categories/tree.ts": $$$2, - "vtex/loaders/collections/list.ts": $$$3, - "vtex/loaders/config.ts": $$$4, - "vtex/loaders/intelligentSearch/productDetailsPage.ts": $$$5, - "vtex/loaders/intelligentSearch/productList.ts": $$$6, - "vtex/loaders/intelligentSearch/productListingPage.ts": $$$7, - "vtex/loaders/intelligentSearch/productSearchValidator.ts": $$$8, - "vtex/loaders/intelligentSearch/suggestions.ts": $$$9, - "vtex/loaders/intelligentSearch/topsearches.ts": $$$10, - "vtex/loaders/legacy/brands.ts": $$$11, - "vtex/loaders/legacy/pageType.ts": $$$12, - "vtex/loaders/legacy/productDetailsPage.ts": $$$13, - "vtex/loaders/legacy/productList.ts": $$$14, - "vtex/loaders/legacy/productListingPage.ts": $$$15, - "vtex/loaders/legacy/relatedProductsLoader.ts": $$$16, - "vtex/loaders/legacy/suggestions.ts": $$$17, - "vtex/loaders/logistics/listPickupPoints.ts": $$$18, - "vtex/loaders/logistics/listPickupPointsByLocation.ts": $$$19, - "vtex/loaders/masterdata/searchDocuments.ts": $$$20, - "vtex/loaders/navbar.ts": $$$21, - "vtex/loaders/options/productIdByTerm.ts": $$$22, - "vtex/loaders/orders/list.ts": $$$23, - "vtex/loaders/orders/order.ts": $$$24, - "vtex/loaders/paths/PDPDefaultPath.ts": $$$25, - "vtex/loaders/paths/PLPDefaultPath.ts": $$$26, - "vtex/loaders/payments/info.ts": $$$27, - "vtex/loaders/payments/userPayments.ts": $$$28, - "vtex/loaders/product/extend.ts": $$$29, - "vtex/loaders/product/extensions/detailsPage.ts": $$$30, - "vtex/loaders/product/extensions/list.ts": $$$31, - "vtex/loaders/product/extensions/listingPage.ts": $$$32, - "vtex/loaders/product/extensions/suggestions.ts": $$$33, - "vtex/loaders/product/wishlist.ts": $$$34, - "vtex/loaders/profile/passwordLastUpdate.ts": $$$35, - "vtex/loaders/proxy.ts": $$$36, - "vtex/loaders/sessions/info.ts": $$$37, - "vtex/loaders/user.ts": $$$38, - "vtex/loaders/wishlist.ts": $$$39, - "vtex/loaders/workflow/product.ts": $$$40, - "vtex/loaders/workflow/products.ts": $$$41, + "vtex/loaders/address/getAddressByZIP.ts": $$$0, + "vtex/loaders/address/list.ts": $$$1, + "vtex/loaders/cart.ts": $$$2, + "vtex/loaders/categories/tree.ts": $$$3, + "vtex/loaders/collections/list.ts": $$$4, + "vtex/loaders/config.ts": $$$5, + "vtex/loaders/intelligentSearch/productDetailsPage.ts": $$$6, + "vtex/loaders/intelligentSearch/productList.ts": $$$7, + "vtex/loaders/intelligentSearch/productListingPage.ts": $$$8, + "vtex/loaders/intelligentSearch/productSearchValidator.ts": $$$9, + "vtex/loaders/intelligentSearch/suggestions.ts": $$$10, + "vtex/loaders/intelligentSearch/topsearches.ts": $$$11, + "vtex/loaders/legacy/brands.ts": $$$12, + "vtex/loaders/legacy/pageType.ts": $$$13, + "vtex/loaders/legacy/productDetailsPage.ts": $$$14, + "vtex/loaders/legacy/productList.ts": $$$15, + "vtex/loaders/legacy/productListingPage.ts": $$$16, + "vtex/loaders/legacy/relatedProductsLoader.ts": $$$17, + "vtex/loaders/legacy/suggestions.ts": $$$18, + "vtex/loaders/logistics/listPickupPoints.ts": $$$19, + "vtex/loaders/logistics/listPickupPointsByLocation.ts": $$$20, + "vtex/loaders/masterdata/searchDocuments.ts": $$$21, + "vtex/loaders/navbar.ts": $$$22, + "vtex/loaders/options/productIdByTerm.ts": $$$23, + "vtex/loaders/orders/list.ts": $$$24, + "vtex/loaders/orders/order.ts": $$$25, + "vtex/loaders/paths/PDPDefaultPath.ts": $$$26, + "vtex/loaders/paths/PLPDefaultPath.ts": $$$27, + "vtex/loaders/payments/info.ts": $$$28, + "vtex/loaders/payments/userPayments.ts": $$$29, + "vtex/loaders/product/extend.ts": $$$30, + "vtex/loaders/product/extensions/detailsPage.ts": $$$31, + "vtex/loaders/product/extensions/list.ts": $$$32, + "vtex/loaders/product/extensions/listingPage.ts": $$$33, + "vtex/loaders/product/extensions/suggestions.ts": $$$34, + "vtex/loaders/product/wishlist.ts": $$$35, + "vtex/loaders/profile/passwordLastUpdate.ts": $$$36, + "vtex/loaders/proxy.ts": $$$37, + "vtex/loaders/sessions/info.ts": $$$38, + "vtex/loaders/user.ts": $$$39, + "vtex/loaders/wishlist.ts": $$$40, + "vtex/loaders/workflow/product.ts": $$$41, + "vtex/loaders/workflow/products.ts": $$$42, }, "handlers": { "vtex/handlers/sitemap.ts": $$$$0, From 57824d4c4e39e090f7b7285f6f3090b361fe03ca Mon Sep 17 00:00:00 2001 From: soutofernando Date: Wed, 16 Oct 2024 13:55:52 -0300 Subject: [PATCH 19/22] feat: delete address action --- .github/workflows/ci.yaml | 2 +- .github/workflows/issues.yaml | 2 +- .github/workflows/releaser.yaml | 16 +-- .../storefront/storefront.graphql.gen.ts | 2 +- vtex/actions/address/createAddress.ts | 4 +- vtex/actions/address/deleteAddress.ts | 58 +++++++++ vtex/actions/address/updateAddress.ts | 4 +- vtex/manifest.gen.ts | 118 +++++++++--------- 8 files changed, 133 insertions(+), 73 deletions(-) create mode 100644 vtex/actions/address/deleteAddress.ts diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index b7384362d..aa1d2bb32 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -51,4 +51,4 @@ jobs: - name: Benchmark continue-on-error: true - run: deno bench --lock=deno.lock --lock-write -A . \ No newline at end of file + run: deno bench --lock=deno.lock --lock-write -A . diff --git a/.github/workflows/issues.yaml b/.github/workflows/issues.yaml index 9504b5705..d5f99f015 100644 --- a/.github/workflows/issues.yaml +++ b/.github/workflows/issues.yaml @@ -15,4 +15,4 @@ jobs: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} GH_REPO: ${{ github.repository }} NUMBER: ${{ github.event.issue.number }} - LABELS: triage \ No newline at end of file + LABELS: triage diff --git a/.github/workflows/releaser.yaml b/.github/workflows/releaser.yaml index 5584f177e..f4fb8d2a0 100644 --- a/.github/workflows/releaser.yaml +++ b/.github/workflows/releaser.yaml @@ -9,9 +9,9 @@ on: - main permissions: - contents: write # Necessary for accessing and modifying repository content - pull-requests: write # Necessary for interacting with pull requests - actions: write # Necessary for triggering other workflows + contents: write # Necessary for accessing and modifying repository content + pull-requests: write # Necessary for interacting with pull requests + actions: write # Necessary for triggering other workflows jobs: tag-discussion: @@ -21,9 +21,9 @@ jobs: - name: Checkout Code uses: actions/checkout@v3 with: - ref: ${{ github.event.pull_request.base.ref }} # Checkout the base branch (target repository) - repository: ${{ github.event.pull_request.base.repo.full_name }} # Checkout from the target repo - + ref: ${{ github.event.pull_request.base.ref }} # Checkout the base branch (target repository) + repository: ${{ github.event.pull_request.base.repo.full_name }} # Checkout from the target repo + - name: Calculate new versions id: calculate_versions run: | @@ -162,11 +162,11 @@ jobs: run: | git tag ${{ steps.determine_version.outputs.new_version }} git push origin ${{ steps.determine_version.outputs.new_version }} - + - name: Trigger Release Workflow run: | curl -X POST \ -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ -H "Accept: application/vnd.github.everest-preview+json" \ https://api.github.com/repos/${{ github.repository }}/actions/workflows/release.yaml/dispatches \ - -d '{"ref":"main", "inputs":{"tag_name":"${{ steps.determine_version.outputs.new_version }}"}}' \ No newline at end of file + -d '{"ref":"main", "inputs":{"tag_name":"${{ steps.determine_version.outputs.new_version }}"}}' diff --git a/shopify/utils/storefront/storefront.graphql.gen.ts b/shopify/utils/storefront/storefront.graphql.gen.ts index d4ca1d33b..79e3afe54 100644 --- a/shopify/utils/storefront/storefront.graphql.gen.ts +++ b/shopify/utils/storefront/storefront.graphql.gen.ts @@ -7811,4 +7811,4 @@ export type SignInWithEmailAndPasswordMutationVariables = Exact<{ }>; -export type SignInWithEmailAndPasswordMutation = { customerAccessTokenCreate?: { customerAccessToken?: { accessToken: string, expiresAt: any } | null, customerUserErrors: Array<{ code?: CustomerErrorCode | null, message: string }> } | null }; \ No newline at end of file +export type SignInWithEmailAndPasswordMutation = { customerAccessTokenCreate?: { customerAccessToken?: { accessToken: string, expiresAt: any } | null, customerUserErrors: Array<{ code?: CustomerErrorCode | null, message: string }> } | null }; diff --git a/vtex/actions/address/createAddress.ts b/vtex/actions/address/createAddress.ts index f63917a19..13f881d1d 100644 --- a/vtex/actions/address/createAddress.ts +++ b/vtex/actions/address/createAddress.ts @@ -35,7 +35,7 @@ interface AddressInput { addressType?: string; } -async function loader( +async function action( props: Address, req: Request, ctx: AppContext, @@ -88,4 +88,4 @@ async function loader( } } -export default loader; +export default action; diff --git a/vtex/actions/address/deleteAddress.ts b/vtex/actions/address/deleteAddress.ts new file mode 100644 index 000000000..1a36ef63d --- /dev/null +++ b/vtex/actions/address/deleteAddress.ts @@ -0,0 +1,58 @@ +import { AppContext } from "../../mod.ts"; +import { parseCookie } from "../../utils/vtexId.ts"; + +interface DeleteAddress { + addressId: string; +} + +interface AddressInput { + id: string; +} + +async function action( + { id }: AddressInput, + req: Request, + ctx: AppContext, +) { + const { io } = ctx; + const { cookie } = parseCookie(req.headers, ctx.account); + + const mutation = ` + mutation DeleteAddress($addressId: String) { + deleteAddress(id: $addressId) { + cacheId + addresses: address { + addressId: id + addressType + addressName + city + complement + country + neighborhood + number + postalCode + geoCoordinates + receiverName + reference + state + street + } + } + }`; + + try { + return await io.query( + { + query: mutation, + operationName: "DeleteAddress", + variables: { id }, + }, + { headers: { cookie } }, + ); + } catch (error) { + console.error("Error deleting address:", error); + return null; + } +} + +export default action; diff --git a/vtex/actions/address/updateAddress.ts b/vtex/actions/address/updateAddress.ts index ccddc0d35..96e16cc16 100644 --- a/vtex/actions/address/updateAddress.ts +++ b/vtex/actions/address/updateAddress.ts @@ -35,7 +35,7 @@ interface AddressInput { addressType?: string; } -async function loader( +async function action( props: Address, req: Request, ctx: AppContext, @@ -103,4 +103,4 @@ async function loader( } } -export default loader; +export default action; diff --git a/vtex/manifest.gen.ts b/vtex/manifest.gen.ts index 9e2bf4193..57e04b557 100644 --- a/vtex/manifest.gen.ts +++ b/vtex/manifest.gen.ts @@ -3,35 +3,36 @@ // This file is automatically updated during development when running `dev.ts`. import * as $$$$$$$$$0 from "./actions/address/createAddress.ts"; -import * as $$$$$$$$$1 from "./actions/address/updateAddress.ts"; -import * as $$$$$$$$$2 from "./actions/analytics/sendEvent.ts"; -import * as $$$$$$$$$3 from "./actions/cart/addItems.ts"; -import * as $$$$$$$$$4 from "./actions/cart/addOfferings.ts"; -import * as $$$$$$$$$5 from "./actions/cart/clearOrderformMessages.ts"; -import * as $$$$$$$$$6 from "./actions/cart/getInstallment.ts"; -import * as $$$$$$$$$7 from "./actions/cart/removeItemAttachment.ts"; -import * as $$$$$$$$$8 from "./actions/cart/removeItems.ts"; -import * as $$$$$$$$$9 from "./actions/cart/removeOffering.ts"; -import * as $$$$$$$$$10 from "./actions/cart/simulation.ts"; -import * as $$$$$$$$$11 from "./actions/cart/updateAttachment.ts"; -import * as $$$$$$$$$12 from "./actions/cart/updateCoupons.ts"; -import * as $$$$$$$$$13 from "./actions/cart/updateGifts.ts"; -import * as $$$$$$$$$14 from "./actions/cart/updateItemAttachment.ts"; -import * as $$$$$$$$$15 from "./actions/cart/updateItemPrice.ts"; -import * as $$$$$$$$$16 from "./actions/cart/updateItems.ts"; -import * as $$$$$$$$$17 from "./actions/cart/updateProfile.ts"; -import * as $$$$$$$$$18 from "./actions/cart/updateUser.ts"; -import * as $$$$$$$$$19 from "./actions/masterdata/createDocument.ts"; -import * as $$$$$$$$$20 from "./actions/newsletter/subscribe.ts"; -import * as $$$$$$$$$21 from "./actions/notifyme.ts"; -import * as $$$$$$$$$22 from "./actions/payments/delete.ts"; -import * as $$$$$$$$$23 from "./actions/profile/newsletterProfile.ts"; -import * as $$$$$$$$$24 from "./actions/profile/updateProfile.ts"; -import * as $$$$$$$$$25 from "./actions/review/submit.ts"; -import * as $$$$$$$$$26 from "./actions/sessions/delete.ts"; -import * as $$$$$$$$$27 from "./actions/trigger.ts"; -import * as $$$$$$$$$28 from "./actions/wishlist/addItem.ts"; -import * as $$$$$$$$$29 from "./actions/wishlist/removeItem.ts"; +import * as $$$$$$$$$1 from "./actions/address/deleteAddress.ts"; +import * as $$$$$$$$$2 from "./actions/address/updateAddress.ts"; +import * as $$$$$$$$$3 from "./actions/analytics/sendEvent.ts"; +import * as $$$$$$$$$4 from "./actions/cart/addItems.ts"; +import * as $$$$$$$$$5 from "./actions/cart/addOfferings.ts"; +import * as $$$$$$$$$6 from "./actions/cart/clearOrderformMessages.ts"; +import * as $$$$$$$$$7 from "./actions/cart/getInstallment.ts"; +import * as $$$$$$$$$8 from "./actions/cart/removeItemAttachment.ts"; +import * as $$$$$$$$$9 from "./actions/cart/removeItems.ts"; +import * as $$$$$$$$$10 from "./actions/cart/removeOffering.ts"; +import * as $$$$$$$$$11 from "./actions/cart/simulation.ts"; +import * as $$$$$$$$$12 from "./actions/cart/updateAttachment.ts"; +import * as $$$$$$$$$13 from "./actions/cart/updateCoupons.ts"; +import * as $$$$$$$$$14 from "./actions/cart/updateGifts.ts"; +import * as $$$$$$$$$15 from "./actions/cart/updateItemAttachment.ts"; +import * as $$$$$$$$$16 from "./actions/cart/updateItemPrice.ts"; +import * as $$$$$$$$$17 from "./actions/cart/updateItems.ts"; +import * as $$$$$$$$$18 from "./actions/cart/updateProfile.ts"; +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 $$$$0 from "./handlers/sitemap.ts"; import * as $$$0 from "./loaders/address/getAddressByZIP.ts"; import * as $$$1 from "./loaders/address/list.ts"; @@ -134,35 +135,36 @@ const manifest = { }, "actions": { "vtex/actions/address/createAddress.ts": $$$$$$$$$0, - "vtex/actions/address/updateAddress.ts": $$$$$$$$$1, - "vtex/actions/analytics/sendEvent.ts": $$$$$$$$$2, - "vtex/actions/cart/addItems.ts": $$$$$$$$$3, - "vtex/actions/cart/addOfferings.ts": $$$$$$$$$4, - "vtex/actions/cart/clearOrderformMessages.ts": $$$$$$$$$5, - "vtex/actions/cart/getInstallment.ts": $$$$$$$$$6, - "vtex/actions/cart/removeItemAttachment.ts": $$$$$$$$$7, - "vtex/actions/cart/removeItems.ts": $$$$$$$$$8, - "vtex/actions/cart/removeOffering.ts": $$$$$$$$$9, - "vtex/actions/cart/simulation.ts": $$$$$$$$$10, - "vtex/actions/cart/updateAttachment.ts": $$$$$$$$$11, - "vtex/actions/cart/updateCoupons.ts": $$$$$$$$$12, - "vtex/actions/cart/updateGifts.ts": $$$$$$$$$13, - "vtex/actions/cart/updateItemAttachment.ts": $$$$$$$$$14, - "vtex/actions/cart/updateItemPrice.ts": $$$$$$$$$15, - "vtex/actions/cart/updateItems.ts": $$$$$$$$$16, - "vtex/actions/cart/updateProfile.ts": $$$$$$$$$17, - "vtex/actions/cart/updateUser.ts": $$$$$$$$$18, - "vtex/actions/masterdata/createDocument.ts": $$$$$$$$$19, - "vtex/actions/newsletter/subscribe.ts": $$$$$$$$$20, - "vtex/actions/notifyme.ts": $$$$$$$$$21, - "vtex/actions/payments/delete.ts": $$$$$$$$$22, - "vtex/actions/profile/newsletterProfile.ts": $$$$$$$$$23, - "vtex/actions/profile/updateProfile.ts": $$$$$$$$$24, - "vtex/actions/review/submit.ts": $$$$$$$$$25, - "vtex/actions/sessions/delete.ts": $$$$$$$$$26, - "vtex/actions/trigger.ts": $$$$$$$$$27, - "vtex/actions/wishlist/addItem.ts": $$$$$$$$$28, - "vtex/actions/wishlist/removeItem.ts": $$$$$$$$$29, + "vtex/actions/address/deleteAddress.ts": $$$$$$$$$1, + "vtex/actions/address/updateAddress.ts": $$$$$$$$$2, + "vtex/actions/analytics/sendEvent.ts": $$$$$$$$$3, + "vtex/actions/cart/addItems.ts": $$$$$$$$$4, + "vtex/actions/cart/addOfferings.ts": $$$$$$$$$5, + "vtex/actions/cart/clearOrderformMessages.ts": $$$$$$$$$6, + "vtex/actions/cart/getInstallment.ts": $$$$$$$$$7, + "vtex/actions/cart/removeItemAttachment.ts": $$$$$$$$$8, + "vtex/actions/cart/removeItems.ts": $$$$$$$$$9, + "vtex/actions/cart/removeOffering.ts": $$$$$$$$$10, + "vtex/actions/cart/simulation.ts": $$$$$$$$$11, + "vtex/actions/cart/updateAttachment.ts": $$$$$$$$$12, + "vtex/actions/cart/updateCoupons.ts": $$$$$$$$$13, + "vtex/actions/cart/updateGifts.ts": $$$$$$$$$14, + "vtex/actions/cart/updateItemAttachment.ts": $$$$$$$$$15, + "vtex/actions/cart/updateItemPrice.ts": $$$$$$$$$16, + "vtex/actions/cart/updateItems.ts": $$$$$$$$$17, + "vtex/actions/cart/updateProfile.ts": $$$$$$$$$18, + "vtex/actions/cart/updateUser.ts": $$$$$$$$$19, + "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, }, "workflows": { "vtex/workflows/events.ts": $$$$$$$$$$0, From e295484660d2623bc3734a151ffe7e040d10df7d Mon Sep 17 00:00:00 2001 From: "@yuri_assuncx" Date: Thu, 24 Oct 2024 20:00:59 -0300 Subject: [PATCH 20/22] feat: add order cancellation action --- vtex/actions/orders/cancel.ts | 40 +++++++++++++++++++++++++++++++++++ vtex/manifest.gen.ts | 34 +++++++++++++++-------------- vtex/utils/client.ts | 3 +++ 3 files changed, 61 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..ef9fc6259 --- /dev/null +++ b/vtex/actions/orders/cancel.ts @@ -0,0 +1,40 @@ +import { parseCookie } from "../../utils/vtexId.ts"; +import { AppContext } from "../../mod.ts"; + +interface Props { + orderId: string; +} + +async function action( + props: Props, + req: Request, + ctx: AppContext, +) { + const { vcsDeprecated } = ctx; + const { cookie, payload } = parseCookie(req.headers, ctx.account); + + if (!payload?.sub || !payload?.userId) { + return null; + } + + const { orderId } = props; + + const response = await vcsDeprecated + ["POST /api/oms/user/orders/:orderId/cancel"]( + { orderId }, + { + headers: { + cookie, + }, + }, + ); + + if (response.ok) { + const order = await response.json(); + return order; + } + + 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..584e30181 100644 --- a/vtex/utils/client.ts +++ b/vtex/utils/client.ts @@ -252,6 +252,9 @@ export interface VTEXCommerceStable { "GET /api/oms/user/orders/:orderId": { response: OrderItem; }; + "POST /api/oms/user/orders/:orderId/cancel": { + response: void; + }; } export interface SP { From 8b061067d43eea2bbf515f410298f9240c598cce Mon Sep 17 00:00:00 2001 From: "@yuri_assuncx" Date: Fri, 25 Oct 2024 20:32:59 -0300 Subject: [PATCH 21/22] feat(vtex): Package type added --- vtex/utils/types.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/vtex/utils/types.ts b/vtex/utils/types.ts index 5721144a3..31181dd98 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; From 04b9be862d6bfae13c9fe256c04af319639cd13b Mon Sep 17 00:00:00 2001 From: "@yuri_assuncx" Date: Fri, 25 Oct 2024 21:27:52 -0300 Subject: [PATCH 22/22] feat: type added to the return of the cancel order action --- vtex/actions/orders/cancel.ts | 11 +++++++---- vtex/utils/client.ts | 6 +++++- vtex/utils/types.ts | 8 +++++++- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/vtex/actions/orders/cancel.ts b/vtex/actions/orders/cancel.ts index ef9fc6259..c6dfa38d1 100644 --- a/vtex/actions/orders/cancel.ts +++ b/vtex/actions/orders/cancel.ts @@ -1,15 +1,17 @@ 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); @@ -17,12 +19,13 @@ async function action( return null; } - const { orderId } = props; + const { orderId, reason } = props; const response = await vcsDeprecated ["POST /api/oms/user/orders/:orderId/cancel"]( { orderId }, { + body: { reason }, headers: { cookie, }, @@ -30,8 +33,8 @@ async function action( ); if (response.ok) { - const order = await response.json(); - return order; + const canceledOrder = await response.json(); + return canceledOrder; } return null; diff --git a/vtex/utils/client.ts b/vtex/utils/client.ts index 584e30181..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, @@ -253,7 +254,10 @@ export interface VTEXCommerceStable { response: OrderItem; }; "POST /api/oms/user/orders/:orderId/cancel": { - response: void; + response: CanceledOrder; + body: { + reason: string; + }; }; } diff --git a/vtex/utils/types.ts b/vtex/utils/types.ts index 31181dd98..5ccebbf57 100644 --- a/vtex/utils/types.ts +++ b/vtex/utils/types.ts @@ -1375,7 +1375,7 @@ export interface Package { finished: boolean; deliveredDate: string; }; - type: "Input" | "Output" + type: "Input" | "Output"; } export interface OrderItem { @@ -1452,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