diff --git a/vtex/actions/address/create.ts b/vtex/actions/address/create.ts index 414cf4a40..43f1821db 100644 --- a/vtex/actions/address/create.ts +++ b/vtex/actions/address/create.ts @@ -112,7 +112,7 @@ async function action( ctx: AppContext, ): Promise { const { io } = ctx; - const { cookie, payload } = parseCookie(req.headers, ctx.account); + const { cookie, payload } = parseCookie(req.headers); if (!payload?.sub || !payload?.userId) { throw new Error("User cookie is invalid"); diff --git a/vtex/actions/address/delete.ts b/vtex/actions/address/delete.ts index a09899ee4..38ebb41db 100644 --- a/vtex/actions/address/delete.ts +++ b/vtex/actions/address/delete.ts @@ -53,7 +53,7 @@ interface Props { */ async function action({ addressId }: Props, req: Request, ctx: AppContext) { const { io } = ctx; - const { cookie, payload } = parseCookie(req.headers, ctx.account); + const { cookie, payload } = parseCookie(req.headers); if (!payload?.sub || !payload?.userId) { throw new Error("User cookie is invalid"); diff --git a/vtex/actions/address/update.ts b/vtex/actions/address/update.ts index 41f7783db..8721eb5a5 100644 --- a/vtex/actions/address/update.ts +++ b/vtex/actions/address/update.ts @@ -96,7 +96,7 @@ async function action( ctx: AppContext, ): Promise { const { io } = ctx; - const { cookie, payload } = parseCookie(req.headers, ctx.account); + const { cookie, payload } = parseCookie(req.headers); if (!payload?.sub || !payload?.userId) { throw new Error("User cookie is invalid"); diff --git a/vtex/actions/authentication/logout.ts b/vtex/actions/authentication/logout.ts index 39f3d5747..cf4b3b058 100644 --- a/vtex/actions/authentication/logout.ts +++ b/vtex/actions/authentication/logout.ts @@ -12,7 +12,7 @@ export default async function action( ctx: AppContext, ) { const cookies = getCookies(req.headers); - const { payload } = parseCookie(req.headers, ctx.account); + const { payload } = parseCookie(req.headers); for (const cookieName in cookies) { if (cookieName.startsWith("VtexIdclientAutCookie")) { diff --git a/vtex/actions/cart/addItems.ts b/vtex/actions/cart/addItems.ts index c8b883f7c..0f3b716ae 100644 --- a/vtex/actions/cart/addItems.ts +++ b/vtex/actions/cart/addItems.ts @@ -1,6 +1,6 @@ import { AppContext } from "../../mod.ts"; import { proxySetCookie } from "../../utils/cookies.ts"; -import { parseCookie } from "../../utils/orderForm.ts"; +import { parseCookieWithoutAuth } from "../../utils/orderForm.ts"; import { getSegmentFromBag } from "../../utils/segment.ts"; import type { OrderForm } from "../../utils/types.ts"; import { forceHttpsOnAssets } from "../../utils/transform.ts"; @@ -33,8 +33,7 @@ const action = async ( orderItems, allowedOutdatedData = ["paymentData"], } = props; - const { orderFormId } = parseCookie(req.headers); - const cookie = req.headers.get("cookie") ?? ""; + const { orderFormId, cookie } = parseCookieWithoutAuth(req.headers); const segment = getSegmentFromBag(ctx); try { diff --git a/vtex/actions/cart/addOfferings.ts b/vtex/actions/cart/addOfferings.ts index 7c3f427fd..08f682aca 100644 --- a/vtex/actions/cart/addOfferings.ts +++ b/vtex/actions/cart/addOfferings.ts @@ -1,6 +1,6 @@ import { AppContext } from "../../mod.ts"; import { proxySetCookie } from "../../utils/cookies.ts"; -import { parseCookie } from "../../utils/orderForm.ts"; +import { parseCookieWithoutAuth } from "../../utils/orderForm.ts"; import { forceHttpsOnAssets } from "../../utils/transform.ts"; import { OrderForm } from "../../utils/types.ts"; import { DEFAULT_EXPECTED_SECTIONS } from "./updateItemAttachment.ts"; @@ -24,8 +24,7 @@ const action = async ( props; const { vcsDeprecated } = ctx; - const { orderFormId } = parseCookie(req.headers); - const cookie = req.headers.get("cookie") ?? ""; + const { orderFormId, cookie } = parseCookieWithoutAuth(req.headers); try { const response = await vcsDeprecated diff --git a/vtex/actions/cart/clearOrderformMessages.ts b/vtex/actions/cart/clearOrderformMessages.ts index 115966593..ab4c20101 100644 --- a/vtex/actions/cart/clearOrderformMessages.ts +++ b/vtex/actions/cart/clearOrderformMessages.ts @@ -1,6 +1,6 @@ import { AppContext } from "../../mod.ts"; import { proxySetCookie } from "../../utils/cookies.ts"; -import { parseCookie } from "../../utils/orderForm.ts"; +import { parseCookieWithoutAuth } from "../../utils/orderForm.ts"; import type { OrderForm } from "../../utils/types.ts"; /** @@ -13,8 +13,7 @@ const action = async ( ctx: AppContext, ): Promise => { const { vcsDeprecated } = ctx; - const { orderFormId } = parseCookie(req.headers); - const cookie = req.headers.get("cookie") ?? ""; + const { orderFormId, cookie } = parseCookieWithoutAuth(req.headers); const response = await vcsDeprecated[ "POST /api/checkout/pub/orderForm/:orderFormId/messages/clear" diff --git a/vtex/actions/cart/getInstallment.ts b/vtex/actions/cart/getInstallment.ts index 17beb3838..4dffa3a07 100644 --- a/vtex/actions/cart/getInstallment.ts +++ b/vtex/actions/cart/getInstallment.ts @@ -1,6 +1,6 @@ import { AppContext } from "../../mod.ts"; import { proxySetCookie } from "../../utils/cookies.ts"; -import { parseCookie } from "../../utils/orderForm.ts"; +import { parseCookieWithoutAuth } from "../../utils/orderForm.ts"; import type { InstallmentOption } from "../../utils/types.ts"; import { getSegmentFromBag } from "../../utils/segment.ts"; @@ -20,8 +20,7 @@ const action = async ( ): Promise => { const { vcsDeprecated } = ctx; const { paymentSystem } = props; - const { orderFormId } = parseCookie(req.headers); - const cookie = req.headers.get("cookie") ?? ""; + const { orderFormId, cookie } = parseCookieWithoutAuth(req.headers); const segment = getSegmentFromBag(ctx); const response = await vcsDeprecated diff --git a/vtex/actions/cart/removeItemAttachment.ts b/vtex/actions/cart/removeItemAttachment.ts index 16be3a213..8e4c942b6 100644 --- a/vtex/actions/cart/removeItemAttachment.ts +++ b/vtex/actions/cart/removeItemAttachment.ts @@ -1,6 +1,6 @@ import { AppContext } from "../../mod.ts"; import { proxySetCookie } from "../../utils/cookies.ts"; -import { parseCookie } from "../../utils/orderForm.ts"; +import { parseCookieWithoutAuth } from "../../utils/orderForm.ts"; import type { OrderForm } from "../../utils/types.ts"; import { getSegmentFromBag } from "../../utils/segment.ts"; @@ -49,8 +49,7 @@ const action = async ( noSplitItem = true, expectedOrderFormSections = DEFAULT_EXPECTED_SECTIONS, } = props; - const { orderFormId } = parseCookie(req.headers); - const cookie = req.headers.get("cookie") ?? ""; + const { orderFormId, cookie } = parseCookieWithoutAuth(req.headers); const segment = getSegmentFromBag(ctx); const response = await vcsDeprecated diff --git a/vtex/actions/cart/removeItems.ts b/vtex/actions/cart/removeItems.ts index 5ad34095c..a30714e36 100644 --- a/vtex/actions/cart/removeItems.ts +++ b/vtex/actions/cart/removeItems.ts @@ -1,6 +1,6 @@ import { AppContext } from "../../mod.ts"; import { proxySetCookie } from "../../utils/cookies.ts"; -import { parseCookie } from "../../utils/orderForm.ts"; +import { parseCookieWithoutAuth } from "../../utils/orderForm.ts"; import type { OrderForm } from "../../utils/types.ts"; import { getSegmentFromBag } from "../../utils/segment.ts"; @@ -15,8 +15,7 @@ const action = async ( ctx: AppContext, ): Promise => { const { vcsDeprecated } = ctx; - const { orderFormId } = parseCookie(req.headers); - const cookie = req.headers.get("cookie") ?? ""; + const { orderFormId, cookie } = parseCookieWithoutAuth(req.headers); const segment = getSegmentFromBag(ctx); const response = await vcsDeprecated diff --git a/vtex/actions/cart/removeOffering.ts b/vtex/actions/cart/removeOffering.ts index 016818b24..6d743e015 100644 --- a/vtex/actions/cart/removeOffering.ts +++ b/vtex/actions/cart/removeOffering.ts @@ -1,6 +1,6 @@ import { AppContext } from "../../mod.ts"; import { proxySetCookie } from "../../utils/cookies.ts"; -import { parseCookie } from "../../utils/orderForm.ts"; +import { parseCookieWithoutAuth } from "../../utils/orderForm.ts"; import { forceHttpsOnAssets } from "../../utils/transform.ts"; import { OrderForm } from "../../utils/types.ts"; import { DEFAULT_EXPECTED_SECTIONS } from "./updateItemAttachment.ts"; @@ -24,8 +24,7 @@ const action = async ( props; const { vcsDeprecated } = ctx; - const { orderFormId } = parseCookie(req.headers); - const cookie = req.headers.get("cookie") ?? ""; + const { orderFormId, cookie } = parseCookieWithoutAuth(req.headers); try { const response = await vcsDeprecated diff --git a/vtex/actions/cart/simulation.ts b/vtex/actions/cart/simulation.ts index 4bb75b72c..392bf1323 100644 --- a/vtex/actions/cart/simulation.ts +++ b/vtex/actions/cart/simulation.ts @@ -1,4 +1,5 @@ import { AppContext } from "../../mod.ts"; +import { parseCookieWithoutAuth } from "../../utils/orderForm.ts"; import type { SimulationOrderForm } from "../../utils/types.ts"; import { getSegmentFromBag } from "../../utils/segment.ts"; @@ -25,7 +26,7 @@ const action = async ( req: Request, ctx: AppContext, ): Promise => { - const cookie = req.headers.get("cookie") ?? ""; + const { cookie } = parseCookieWithoutAuth(req.headers); const { vcsDeprecated } = ctx; const { items, postalCode, country, RnbBehavior = 1 } = props; const segment = getSegmentFromBag(ctx); diff --git a/vtex/actions/cart/updateAttachment.ts b/vtex/actions/cart/updateAttachment.ts index 37cf4c40b..e6d3c00c4 100644 --- a/vtex/actions/cart/updateAttachment.ts +++ b/vtex/actions/cart/updateAttachment.ts @@ -1,6 +1,6 @@ import { AppContext } from "../../mod.ts"; import { proxySetCookie } from "../../utils/cookies.ts"; -import { parseCookie } from "../../utils/orderForm.ts"; +import { parseCookieWithoutAuth } from "../../utils/orderForm.ts"; import type { OrderForm } from "../../utils/types.ts"; import { DEFAULT_EXPECTED_SECTIONS } from "./updateItemAttachment.ts"; import { getSegmentFromBag } from "../../utils/segment.ts"; @@ -27,13 +27,11 @@ const action = async ( body, expectedOrderFormSections = DEFAULT_EXPECTED_SECTIONS, } = props; - const { orderFormId } = parseCookie(req.headers); + const { orderFormId, cookie } = parseCookieWithoutAuth(req.headers); if (!orderFormId || orderFormId === "") { throw new Error("Order form ID is required"); } - - const cookie = req.headers.get("cookie") ?? ""; const segment = getSegmentFromBag(ctx); const response = await vcsDeprecated diff --git a/vtex/actions/cart/updateCoupons.ts b/vtex/actions/cart/updateCoupons.ts index 852c42065..88d13a4f7 100644 --- a/vtex/actions/cart/updateCoupons.ts +++ b/vtex/actions/cart/updateCoupons.ts @@ -1,6 +1,6 @@ import { AppContext } from "../../mod.ts"; import { proxySetCookie } from "../../utils/cookies.ts"; -import { parseCookie } from "../../utils/orderForm.ts"; +import { parseCookieWithoutAuth } from "../../utils/orderForm.ts"; import type { OrderForm } from "../../utils/types.ts"; import { getSegmentFromBag } from "../../utils/segment.ts"; @@ -20,8 +20,7 @@ const action = async ( ): Promise => { const { vcsDeprecated } = ctx; const { text } = props; - const cookie = req.headers.get("cookie") ?? ""; - const { orderFormId } = parseCookie(req.headers); + const { orderFormId, cookie } = parseCookieWithoutAuth(req.headers); const segment = getSegmentFromBag(ctx); const response = await vcsDeprecated diff --git a/vtex/actions/cart/updateGifts.ts b/vtex/actions/cart/updateGifts.ts index 64ff219d9..8d31aa22c 100644 --- a/vtex/actions/cart/updateGifts.ts +++ b/vtex/actions/cart/updateGifts.ts @@ -1,6 +1,6 @@ import { AppContext } from "../../mod.ts"; import { proxySetCookie } from "../../utils/cookies.ts"; -import { parseCookie } from "../../utils/orderForm.ts"; +import { parseCookieWithoutAuth } from "../../utils/orderForm.ts"; import type { OrderForm, SelectableGifts } from "../../utils/types.ts"; import { DEFAULT_EXPECTED_SECTIONS } from "./updateItemAttachment.ts"; @@ -23,8 +23,7 @@ const action = async ( id, selectedGifts, } = props; - const { orderFormId } = parseCookie(req.headers); - const cookie = req.headers.get("cookie") ?? ""; + const { orderFormId, cookie } = parseCookieWithoutAuth(req.headers); const response = await vcsDeprecated[ "POST /api/checkout/pub/orderForm/:orderFormId/selectable-gifts/:giftId" diff --git a/vtex/actions/cart/updateItemAttachment.ts b/vtex/actions/cart/updateItemAttachment.ts index 3b20412fe..93e7d3899 100644 --- a/vtex/actions/cart/updateItemAttachment.ts +++ b/vtex/actions/cart/updateItemAttachment.ts @@ -1,6 +1,6 @@ import { AppContext } from "../../mod.ts"; import { proxySetCookie } from "../../utils/cookies.ts"; -import { parseCookie } from "../../utils/orderForm.ts"; +import { parseCookieWithoutAuth } from "../../utils/orderForm.ts"; import type { OrderForm } from "../../utils/types.ts"; import { getSegmentFromBag } from "../../utils/segment.ts"; @@ -49,8 +49,7 @@ const action = async ( noSplitItem = true, expectedOrderFormSections = DEFAULT_EXPECTED_SECTIONS, } = props; - const { orderFormId } = parseCookie(req.headers); - const cookie = req.headers.get("cookie") ?? ""; + const { orderFormId, cookie } = parseCookieWithoutAuth(req.headers); const segment = getSegmentFromBag(ctx); const response = await vcsDeprecated diff --git a/vtex/actions/cart/updateItemPrice.ts b/vtex/actions/cart/updateItemPrice.ts index 034bcbc84..ea2dd4015 100644 --- a/vtex/actions/cart/updateItemPrice.ts +++ b/vtex/actions/cart/updateItemPrice.ts @@ -1,6 +1,6 @@ import { AppContext } from "../../mod.ts"; import { proxySetCookie } from "../../utils/cookies.ts"; -import { parseCookie } from "../../utils/orderForm.ts"; +import { parseCookieWithoutAuth } from "../../utils/orderForm.ts"; import type { OrderForm } from "../../utils/types.ts"; import { getSegmentFromBag } from "../../utils/segment.ts"; @@ -24,8 +24,7 @@ const action = async ( itemIndex, price, } = props; - const { orderFormId } = parseCookie(req.headers); - const cookie = req.headers.get("cookie") ?? ""; + const { orderFormId, cookie } = parseCookieWithoutAuth(req.headers); const segment = getSegmentFromBag(ctx); const response = await vcsDeprecated diff --git a/vtex/actions/cart/updateItems.ts b/vtex/actions/cart/updateItems.ts index bb0ea3e8c..ad875ef25 100644 --- a/vtex/actions/cart/updateItems.ts +++ b/vtex/actions/cart/updateItems.ts @@ -1,6 +1,6 @@ import { AppContext } from "../../mod.ts"; import { proxySetCookie } from "../../utils/cookies.ts"; -import { parseCookie } from "../../utils/orderForm.ts"; +import { parseCookieWithoutAuth } from "../../utils/orderForm.ts"; import { getSegmentFromBag } from "../../utils/segment.ts"; import type { OrderForm } from "../../utils/types.ts"; @@ -31,8 +31,7 @@ const action = async ( allowedOutdatedData = ["paymentData"], noSplitItem, } = props; - const { orderFormId } = parseCookie(req.headers); - const cookie = req.headers.get("cookie") ?? ""; + const { orderFormId, cookie } = parseCookieWithoutAuth(req.headers); const segment = getSegmentFromBag(ctx); const response = await vcsDeprecated diff --git a/vtex/actions/cart/updateProfile.ts b/vtex/actions/cart/updateProfile.ts index cb621dc91..96c34d162 100644 --- a/vtex/actions/cart/updateProfile.ts +++ b/vtex/actions/cart/updateProfile.ts @@ -1,6 +1,6 @@ import { AppContext } from "../../mod.ts"; import { proxySetCookie } from "../../utils/cookies.ts"; -import { parseCookie } from "../../utils/orderForm.ts"; +import { parseCookieWithoutAuth } from "../../utils/orderForm.ts"; import type { OrderForm } from "../../utils/types.ts"; import { getSegmentFromBag } from "../../utils/segment.ts"; @@ -20,8 +20,7 @@ const action = async ( ): Promise => { const { vcsDeprecated } = ctx; const { ignoreProfileData } = props; - const { orderFormId } = parseCookie(req.headers); - const cookie = req.headers.get("cookie") ?? ""; + const { orderFormId, cookie } = parseCookieWithoutAuth(req.headers); const segment = getSegmentFromBag(ctx); const response = await vcsDeprecated diff --git a/vtex/actions/cart/updateUser.ts b/vtex/actions/cart/updateUser.ts index dca9184e8..6b8e77432 100644 --- a/vtex/actions/cart/updateUser.ts +++ b/vtex/actions/cart/updateUser.ts @@ -1,6 +1,6 @@ import { AppContext } from "../../mod.ts"; import { proxySetCookie } from "../../utils/cookies.ts"; -import { parseCookie } from "../../utils/orderForm.ts"; +import { parseCookieWithoutAuth } from "../../utils/orderForm.ts"; import type { OrderForm } from "../../utils/types.ts"; import { getSegmentFromBag } from "../../utils/segment.ts"; @@ -15,8 +15,7 @@ const action = async ( ctx: AppContext, ): Promise => { const { vcsDeprecated } = ctx; - const { orderFormId } = parseCookie(req.headers); - const cookie = req.headers.get("cookie") ?? ""; + const { orderFormId, cookie } = parseCookieWithoutAuth(req.headers); const segment = getSegmentFromBag(ctx); const response = await vcsDeprecated diff --git a/vtex/actions/masterdata/createDocument.ts b/vtex/actions/masterdata/createDocument.ts index 1982d077f..6d9a80ed4 100644 --- a/vtex/actions/masterdata/createDocument.ts +++ b/vtex/actions/masterdata/createDocument.ts @@ -22,7 +22,7 @@ const action = async ( ): Promise => { const { vcs, vcsDeprecated } = ctx; const { data, acronym, isPrivateEntity, schema } = props; - const { cookie } = parseCookie(req.headers, ctx.account); + const { cookie } = parseCookie(req.headers); const requestOptions = { body: data, diff --git a/vtex/actions/masterdata/updateDocument.ts b/vtex/actions/masterdata/updateDocument.ts index 78f3484f7..b9663141d 100644 --- a/vtex/actions/masterdata/updateDocument.ts +++ b/vtex/actions/masterdata/updateDocument.ts @@ -26,7 +26,7 @@ const action = async ( ): Promise => { const { vcs } = ctx; const { id, data, acronym, createIfNotExists, schema } = props; - const { cookie } = parseCookie(req.headers, ctx.account); + const { cookie } = parseCookie(req.headers); const requestOptions = { body: createIfNotExists ? { ...data, id } : data, diff --git a/vtex/actions/newsletter/updateNewsletterOptIn.ts b/vtex/actions/newsletter/updateNewsletterOptIn.ts index e54229735..e6b111db9 100644 --- a/vtex/actions/newsletter/updateNewsletterOptIn.ts +++ b/vtex/actions/newsletter/updateNewsletterOptIn.ts @@ -23,7 +23,7 @@ async function loader( ctx: AppContext, ): Promise<{ subscribed: boolean }> { const { io } = ctx; - const { cookie, payload } = parseCookie(req.headers, ctx.account); + const { cookie, payload } = parseCookie(req.headers); if (!payload?.sub || !payload?.userId) { throw new Error("User cookie is invalid"); diff --git a/vtex/actions/orders/cancel.ts b/vtex/actions/orders/cancel.ts index 6d2ae0d2a..080ffdee0 100644 --- a/vtex/actions/orders/cancel.ts +++ b/vtex/actions/orders/cancel.ts @@ -17,7 +17,7 @@ async function action( ): Promise { const { orderId, reason } = props; const { vcsDeprecated } = ctx; - const { cookie } = parseCookie(req.headers, ctx.account); + const { cookie } = parseCookie(req.headers); const response = await vcsDeprecated ["POST /api/checkout/pub/orders/:orderId/user-cancel-request"]( diff --git a/vtex/actions/payment/deletePaymentToken.ts b/vtex/actions/payment/deletePaymentToken.ts index 1fc989a2d..967be7a09 100644 --- a/vtex/actions/payment/deletePaymentToken.ts +++ b/vtex/actions/payment/deletePaymentToken.ts @@ -23,7 +23,7 @@ async function loader( ctx: AppContext, ): Promise { const { io } = ctx; - const { cookie, payload } = parseCookie(req.headers, ctx.account); + const { cookie, payload } = parseCookie(req.headers); if (!payload?.sub || !payload?.userId) { throw new Error("User cookie is invalid"); diff --git a/vtex/actions/profile/updateProfile.ts b/vtex/actions/profile/updateProfile.ts index 06194d936..6768e72c1 100644 --- a/vtex/actions/profile/updateProfile.ts +++ b/vtex/actions/profile/updateProfile.ts @@ -31,7 +31,7 @@ async function action( ctx: AppContext, ): Promise { const { io } = ctx; - const { cookie, payload } = parseCookie(req.headers, ctx.account); + const { cookie, payload } = parseCookie(req.headers); if (!payload?.sub || !payload?.userId) { throw new Error("User cookie is invalid"); diff --git a/vtex/actions/session/deleteSession.ts b/vtex/actions/session/deleteSession.ts index 0d24516f2..c3869a024 100644 --- a/vtex/actions/session/deleteSession.ts +++ b/vtex/actions/session/deleteSession.ts @@ -23,7 +23,7 @@ async function action( ctx: AppContext, ): Promise { const { io } = ctx; - const { cookie, payload } = parseCookie(req.headers, ctx.account); + const { cookie, payload } = parseCookie(req.headers); if (!payload?.sub || !payload?.userId) { throw new Error("User cookie is invalid"); diff --git a/vtex/actions/session/editSession.ts b/vtex/actions/session/editSession.ts index c97e0d1bb..d6780734c 100644 --- a/vtex/actions/session/editSession.ts +++ b/vtex/actions/session/editSession.ts @@ -17,7 +17,7 @@ async function action( ctx: AppContext, ): Promise { const { vcs } = ctx; - const { cookie } = parseCookie(req.headers, ctx.account); + const { cookie } = parseCookie(req.headers); const response = await vcs["PATCH /api/sessions"]({}, { body: { diff --git a/vtex/actions/wishlist/addItem.ts b/vtex/actions/wishlist/addItem.ts index a89075375..aa1295ada 100644 --- a/vtex/actions/wishlist/addItem.ts +++ b/vtex/actions/wishlist/addItem.ts @@ -17,7 +17,7 @@ const action = async ( ctx: AppContext, ): Promise => { const { io } = ctx; - const { cookie, payload } = parseCookie(req.headers, ctx.account); + const { cookie, payload } = parseCookie(req.headers); const user = payload?.sub; if (!user) { diff --git a/vtex/actions/wishlist/removeItem.ts b/vtex/actions/wishlist/removeItem.ts index 7d8cbd59c..b08d49695 100644 --- a/vtex/actions/wishlist/removeItem.ts +++ b/vtex/actions/wishlist/removeItem.ts @@ -15,7 +15,7 @@ const action = async ( ctx: AppContext, ): Promise => { const { io } = ctx; - const { cookie, payload } = parseCookie(req.headers, ctx.account); + const { cookie, payload } = parseCookie(req.headers); const user = payload?.sub; const { id } = props; diff --git a/vtex/loaders/address/getUserAddresses.ts b/vtex/loaders/address/getUserAddresses.ts index 1d7375642..a954427fb 100644 --- a/vtex/loaders/address/getUserAddresses.ts +++ b/vtex/loaders/address/getUserAddresses.ts @@ -35,7 +35,7 @@ async function loader( ctx: AppContext, ): Promise { const { io } = ctx; - const { cookie, payload } = parseCookie(req.headers, ctx.account); + const { cookie, payload } = parseCookie(req.headers); if (!payload?.sub || !payload?.userId) { throw new Error("User cookie is invalid"); diff --git a/vtex/loaders/masterdata/searchDocuments.ts b/vtex/loaders/masterdata/searchDocuments.ts index 4956a50fa..d844ad795 100644 --- a/vtex/loaders/masterdata/searchDocuments.ts +++ b/vtex/loaders/masterdata/searchDocuments.ts @@ -52,7 +52,7 @@ export default async function loader( ): Promise { const { vcs } = ctx; const { acronym, fields, where, sort, skip = 0, take = 10, schema } = props; - const { cookie } = parseCookie(req.headers, ctx.account); + const { cookie } = parseCookie(req.headers); const limits = resourceRange(skip, take); const documents = await vcs["GET /api/dataentities/:acronym/search"]({ diff --git a/vtex/loaders/orders/getById.ts b/vtex/loaders/orders/getById.ts index 245c7f45f..e45f140ca 100644 --- a/vtex/loaders/orders/getById.ts +++ b/vtex/loaders/orders/getById.ts @@ -15,7 +15,7 @@ export default async function loader( ctx: AppContext, ) { const { vcsDeprecated } = ctx; - const { cookie } = parseCookie(req.headers, ctx.account); + const { cookie } = parseCookie(req.headers); const order = await vcsDeprecated["GET /api/oms/user/orders/:orderId"]( { diff --git a/vtex/loaders/orders/list.ts b/vtex/loaders/orders/list.ts index 2402110d1..c1d75102c 100644 --- a/vtex/loaders/orders/list.ts +++ b/vtex/loaders/orders/list.ts @@ -19,7 +19,7 @@ export default async function loader( ): Promise { const { vcsDeprecated } = ctx; const { clientEmail, page = "0", per_page = "15" } = props; - const { cookie } = parseCookie(req.headers, ctx.account); + const { cookie } = parseCookie(req.headers); const ordersResponse = await vcsDeprecated ["GET /api/oms/user/orders"]( diff --git a/vtex/loaders/payment/paymentSystems.ts b/vtex/loaders/payment/paymentSystems.ts index 76053762a..cc47403f1 100644 --- a/vtex/loaders/payment/paymentSystems.ts +++ b/vtex/loaders/payment/paymentSystems.ts @@ -39,7 +39,7 @@ async function loader( ctx: AppContext, ) { const { io } = ctx; - const { cookie, payload } = parseCookie(req.headers, ctx.account); + const { cookie, payload } = parseCookie(req.headers); if (!payload?.sub || !payload?.userId) { throw new Error("User cookie is invalid"); diff --git a/vtex/loaders/payment/userPayments.ts b/vtex/loaders/payment/userPayments.ts index ad770a0d7..656b6e575 100644 --- a/vtex/loaders/payment/userPayments.ts +++ b/vtex/loaders/payment/userPayments.ts @@ -35,7 +35,7 @@ async function loader( ctx: AppContext, ): Promise { const { io } = ctx; - const { cookie, payload } = parseCookie(req.headers, ctx.account); + const { cookie, payload } = parseCookie(req.headers); if (!payload?.sub || !payload?.userId) { throw new Error("User cookie is invalid"); diff --git a/vtex/loaders/profile/getCurrentProfile.ts b/vtex/loaders/profile/getCurrentProfile.ts index 8fd51456e..1e9dcd32d 100644 --- a/vtex/loaders/profile/getCurrentProfile.ts +++ b/vtex/loaders/profile/getCurrentProfile.ts @@ -69,7 +69,7 @@ async function loader( ctx: AppContext, ): Promise { const { io } = ctx; - const { cookie, payload } = parseCookie(req.headers, ctx.account); + const { cookie, payload } = parseCookie(req.headers); if (!payload?.sub || !payload?.userId) { throw new Error("User cookie is invalid"); diff --git a/vtex/loaders/profile/getProfileByEmail.ts b/vtex/loaders/profile/getProfileByEmail.ts index f3b0f84d9..dc4e4f951 100644 --- a/vtex/loaders/profile/getProfileByEmail.ts +++ b/vtex/loaders/profile/getProfileByEmail.ts @@ -16,7 +16,7 @@ export async function loader( ctx: AppContext, ) { const { vcs } = ctx; - const { cookie } = parseCookie(req.headers, ctx.account); + const { cookie } = parseCookie(req.headers); const response = await vcs["GET /api/checkout/pub/profiles"]({ email, diff --git a/vtex/loaders/promotion/getPromotionById.ts b/vtex/loaders/promotion/getPromotionById.ts index 16c6a6867..ba769d0b8 100644 --- a/vtex/loaders/promotion/getPromotionById.ts +++ b/vtex/loaders/promotion/getPromotionById.ts @@ -22,7 +22,7 @@ export default async function loader( ): Promise { const { vcs } = ctx; const { idCalculatorConfiguration } = props; - const { cookie } = parseCookie(req.headers, ctx.account); + const { cookie } = parseCookie(req.headers); const promotionById = await vcs ["GET /api/rnb/pvt/calculatorconfiguration/:idCalculatorConfiguration"]({ diff --git a/vtex/loaders/session/getUserSessions.ts b/vtex/loaders/session/getUserSessions.ts index 1fdbe4873..8e68d7b54 100644 --- a/vtex/loaders/session/getUserSessions.ts +++ b/vtex/loaders/session/getUserSessions.ts @@ -30,7 +30,7 @@ async function loader( ctx: AppContext, ): Promise { const { io } = ctx; - const { cookie, payload } = parseCookie(req.headers, ctx.account); + const { cookie, payload } = parseCookie(req.headers); if (!payload?.sub || !payload?.userId) { throw new Error("User cookie is invalid"); diff --git a/vtex/loaders/user.ts b/vtex/loaders/user.ts index 751f49b59..dbb6c905b 100644 --- a/vtex/loaders/user.ts +++ b/vtex/loaders/user.ts @@ -32,7 +32,7 @@ async function loader( ctx: AppContext, ): Promise { const { io } = ctx; - const { cookie, payload } = parseCookie(req.headers, ctx.account); + const { cookie, payload } = parseCookie(req.headers); if (!payload?.sub || !payload?.userId) { return null; diff --git a/vtex/loaders/wishlist.ts b/vtex/loaders/wishlist.ts index 9061cd0d6..9b57c6e45 100644 --- a/vtex/loaders/wishlist.ts +++ b/vtex/loaders/wishlist.ts @@ -27,7 +27,7 @@ const loader = async ( const url = new URL(req.url); const page = Number(url.searchParams.get("page")) || 0; const count = props.count || Infinity; - const { cookie, payload } = parseCookie(req.headers, ctx.account); + const { cookie, payload } = parseCookie(req.headers); const user = payload?.sub; if (!user) { diff --git a/vtex/mod.ts b/vtex/mod.ts index 59e3598bd..b6a1d92fc 100644 --- a/vtex/mod.ts +++ b/vtex/mod.ts @@ -45,6 +45,11 @@ export interface Props { * @description VTEX Account name. For more info, read here: https://help.vtex.com/en/tutorial/o-que-e-account-name--i0mIGLcg3QyEy8OCicEoC. */ account: string; + /** + * @title Store Name + * @description VTEX Store name For more info, read here: https://help.vtex.com/en/tutorial/account-details-page--2vhUVOKfCaswqLguT2F9xq#stores + */ + subAccount?: string; /** * @title Public store URL * @description Domain that is registered on License Manager (e.g: secure.mystore.com.br) to enable account/checkout/api proxy. Important: dont use the same domain as the public store url, or it will create a loop and break the app. @@ -70,12 +75,6 @@ export interface Props { /** * @title Default Segment */ - /** - * @title Set Refresh Token - * @description Set the refresh token in the cookies in headless login actions (actions/authentication/*) - * @default false - */ - setRefreshToken?: boolean; defaultSegment?: SegmentCulture; usePortalSitemap?: boolean; /** @@ -120,7 +119,7 @@ export const color = 0xf71963; * @logo https://decoims.com/mcp/0d6e795b-cefd-4853-9a51-93b346c52c3f/VTEX.svg */ export default function VTEX( - { appKey, appToken, account, publicUrl: _publicUrl, salesChannel, ...props }: + { appKey, appToken, account, subAccount, publicUrl: _publicUrl, salesChannel, ...props }: Props, ) { const publicUrl = _publicUrl?.startsWith("https://") @@ -148,20 +147,17 @@ export default function VTEX( fetcher: fetchSafe, }); const vcsDeprecated = createHttpClient({ - base: publicUrl, + base: `https://${account}.vtexcommercestable.com.br`, processHeaders: removeDirtyCookies, fetcher: fetchSafe, }); - const ioUrl = publicUrl.endsWith("/") - ? `${publicUrl}api/io/_v/private/graphql/v1` - : `${publicUrl}/api/io/_v/private/graphql/v1`; const io = createGraphqlClient({ - endpoint: ioUrl, + endpoint: `https://${subAccount || account}.vtexcommercestable.com.br/api/io/_v/private/graphql/v1`, processHeaders: removeDirtyCookies, fetcher: fetchSafe, }); const vcs = createHttpClient({ - base: publicUrl, + base: `https://${account}.vtexcommercestable.com.br`, fetcher: fetchSafe, processHeaders: removeDirtyCookies, headers: headers, diff --git a/vtex/utils/orderForm.ts b/vtex/utils/orderForm.ts index 271e857fa..f52cbe93c 100644 --- a/vtex/utils/orderForm.ts +++ b/vtex/utils/orderForm.ts @@ -61,6 +61,28 @@ export const parseCookie = (headers: Headers) => { }; }; +export const parseCookieWithoutAuth = (headers: Headers) => { + const cookies = getCookies(headers); + const ofidCookie = cookies[VTEX_CHECKOUT_COOKIE]; + + if (ofidCookie == null) { + return { orderFormId: "", cookie: "" }; + } + + if (!/^__ofid=([0-9a-fA-F])+$/.test(ofidCookie)) { + throw new Error( + `Not a valid VTEX orderForm cookie. Expected: /^__ofid=([0-9])+$/, receveid: ${ofidCookie}`, + ); + } + + const [_, id] = ofidCookie.split("="); + + return { + orderFormId: id, + cookie: stringify({ [VTEX_CHECKOUT_COOKIE]: ofidCookie }), + }; +}; + export const formatCookie = (orderFormId: string): Cookie => ({ value: `__ofid=${orderFormId}`, name: "checkout.vtex.com", diff --git a/vtex/utils/vtexId.ts b/vtex/utils/vtexId.ts index 4bb401927..4dafea7d9 100644 --- a/vtex/utils/vtexId.ts +++ b/vtex/utils/vtexId.ts @@ -15,6 +15,7 @@ interface CookiePayload { export const parseAuthCookie = (headers: Headers) => { const cookies = getCookies(headers); + const token = cookies[VTEX_ID_CLIENT_COOKIE] || Object.entries(cookies).find(([k]) => k.startsWith(`${VTEX_ID_CLIENT_COOKIE}_`) @@ -26,24 +27,23 @@ export const parseAuthCookie = (headers: Headers) => { return decoded?.[1] as CookiePayload | undefined ?? null; }; -export const parseCookie = (headers: Headers, account: string) => { +export const parseCookie = (headers: Headers) => { const cookies = getCookies(headers); - const cookie = cookies[VTEX_ID_CLIENT_COOKIE] || - cookies[`${VTEX_ID_CLIENT_COOKIE}_${account}`]; - const decoded = cookie ? decode(cookie) : null; + const authCookieName = Object.keys(cookies) + .toSorted((a, z) => a.length - z.length) + .find((cookieName) => cookieName.startsWith("VtexIdclientAutCookie")); + + if (!authCookieName) { + return { cookie: "", payload: undefined }; + } + + const cookie = cookies[authCookieName]; + const decoded = cookie ? decode(cookie) : null; const payload = decoded?.[1] as CookiePayload | undefined; return { - cookie: stringify({ - ...(cookies[VTEX_ID_CLIENT_COOKIE] && - { [VTEX_ID_CLIENT_COOKIE]: cookies[VTEX_ID_CLIENT_COOKIE] }), - ...(cookies[`${VTEX_ID_CLIENT_COOKIE}_${account}`] && - { - [`${VTEX_ID_CLIENT_COOKIE}_${account}`]: - cookies[`${VTEX_ID_CLIENT_COOKIE}_${account}`], - }), - }), + cookie: stringify({ [authCookieName]: cookie }), payload, }; }; diff --git a/website/handlers/proxy.ts b/website/handlers/proxy.ts index 6b659e3c8..d49166ea0 100644 --- a/website/handlers/proxy.ts +++ b/website/handlers/proxy.ts @@ -177,6 +177,7 @@ export default function Proxy({ // Prepare scripts to insert let scriptsInsert = ""; for (const script of (includeScriptsToHead?.includes ?? [])) { + if (!script || !script.src) continue; scriptsInsert += typeof script.src === "string" ? script.src : script.src(req); @@ -199,6 +200,7 @@ export default function Proxy({ // Prepare scripts to insert let scriptsInsert = ""; for (const script of (includeScriptsToBody?.includes ?? [])) { + if (!script || !script.src) continue; scriptsInsert += typeof script.src === "string" ? script.src : script.src(req);