fix: resolve erro fetch in request subacconts#1593
Conversation
Tagging OptionsShould a new tag be published when this PR is merged?
|
📝 WalkthroughWalkthroughWidespread VTEX cookie parsing refactor: parseCookie no longer accepts account, a new parseCookieWithoutAuth was added and propagated to cart actions; VTEX app Props and stable-domain endpoints were updated; proxy handler received defensive guards for script injection. ChangesVTEX cookie & endpoint updates
Website proxy handler fixes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@vtex/mod.ts`:
- Line 155: The object property "endpoint" in vtex/mod.ts has an extra space
after the colon ("endpoint: `https://...`"); remove the double space so it
reads "endpoint: `https://...`" (i.e., ensure a single space after the colon in
the endpoint property/template-string) to fix the formatting failure.
- Around line 48-52: The JSDoc block above the subAccount property is
mis-indented and failing Deno fmt; fix by aligning the comment markers and
content to standard JSDoc formatting so the opening /**, each line with a single
leading space and the closing */ align with the property declaration; update the
comment that documents subAccount (symbol: subAccount) to use consistent
indentation and spacing for title/description lines so the formatter passes.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 80e1142b-b191-45b0-b9b2-4235f8d04de6
📒 Files selected for processing (45)
vtex/actions/address/create.tsvtex/actions/address/delete.tsvtex/actions/address/update.tsvtex/actions/authentication/logout.tsvtex/actions/cart/addItems.tsvtex/actions/cart/addOfferings.tsvtex/actions/cart/clearOrderformMessages.tsvtex/actions/cart/getInstallment.tsvtex/actions/cart/removeItemAttachment.tsvtex/actions/cart/removeItems.tsvtex/actions/cart/removeOffering.tsvtex/actions/cart/simulation.tsvtex/actions/cart/updateAttachment.tsvtex/actions/cart/updateCoupons.tsvtex/actions/cart/updateGifts.tsvtex/actions/cart/updateItemAttachment.tsvtex/actions/cart/updateItemPrice.tsvtex/actions/cart/updateItems.tsvtex/actions/cart/updateProfile.tsvtex/actions/cart/updateUser.tsvtex/actions/masterdata/createDocument.tsvtex/actions/masterdata/updateDocument.tsvtex/actions/newsletter/updateNewsletterOptIn.tsvtex/actions/orders/cancel.tsvtex/actions/payment/deletePaymentToken.tsvtex/actions/profile/updateProfile.tsvtex/actions/session/deleteSession.tsvtex/actions/session/editSession.tsvtex/actions/wishlist/addItem.tsvtex/actions/wishlist/removeItem.tsvtex/loaders/address/getUserAddresses.tsvtex/loaders/masterdata/searchDocuments.tsvtex/loaders/orders/getById.tsvtex/loaders/orders/list.tsvtex/loaders/payment/paymentSystems.tsvtex/loaders/payment/userPayments.tsvtex/loaders/profile/getCurrentProfile.tsvtex/loaders/profile/getProfileByEmail.tsvtex/loaders/promotion/getPromotionById.tsvtex/loaders/session/getUserSessions.tsvtex/loaders/user.tsvtex/loaders/wishlist.tsvtex/mod.tsvtex/utils/orderForm.tsvtex/utils/vtexId.ts
| /** | ||
| * @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; |
There was a problem hiding this comment.
Formatting issues causing pipeline failure.
The JSDoc block has inconsistent indentation - the /** and content are misaligned. This is causing the Deno fmt check to fail.
🔧 Proposed fix
- /**
- * `@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` Store Name
+ * `@description` VTEX Store name For more info, read here: https://help.vtex.com/en/tutorial/account-details-page--2vhUVOKfCaswqLguT2F9xq#stores
+ */
+ subAccount?: string;📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| /** | |
| * @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` Store Name | |
| * `@description` VTEX Store name For more info, read here: https://help.vtex.com/en/tutorial/account-details-page--2vhUVOKfCaswqLguT2F9xq#stores | |
| */ | |
| subAccount?: string; |
🧰 Tools
🪛 GitHub Actions: ci / Bundle & Check Apps (ubuntu-latest)
[error] 48-164: deno fmt --check failed. Found 1 not formatted file. Run 'deno fmt' (or 'deno fmt --write') to apply formatting.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@vtex/mod.ts` around lines 48 - 52, The JSDoc block above the subAccount
property is mis-indented and failing Deno fmt; fix by aligning the comment
markers and content to standard JSDoc formatting so the opening /**, each line
with a single leading space and the closing */ align with the property
declaration; update the comment that documents subAccount (symbol: subAccount)
to use consistent indentation and spacing for title/description lines so the
formatter passes.
| : `${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`, |
There was a problem hiding this comment.
Extra whitespace causing fmt failure.
There's a double space after endpoint: that should be a single space.
🔧 Proposed fix
- endpoint: `https://${subAccount || account}.vtexcommercestable.com.br/api/io/_v/private/graphql/v1`,
+ endpoint: `https://${subAccount || account}.vtexcommercestable.com.br/api/io/_v/private/graphql/v1`,📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| endpoint: `https://${subAccount || account}.vtexcommercestable.com.br/api/io/_v/private/graphql/v1`, | |
| endpoint: `https://${subAccount || account}.vtexcommercestable.com.br/api/io/_v/private/graphql/v1`, |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@vtex/mod.ts` at line 155, The object property "endpoint" in vtex/mod.ts has
an extra space after the colon ("endpoint: `https://...`"); remove the double
space so it reads "endpoint: `https://...`" (i.e., ensure a single space after
the colon in the endpoint property/template-string) to fix the formatting
failure.
ProblemaEm cenários VTEX multistore/subaccount, o cookie de autenticação pode vir em dois formatos:
O Além disso, todas as actions de carrinho estavam encaminhando o header Alterações
|
There was a problem hiding this comment.
1 issue found across 45 files (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="vtex/mod.ts">
<violation number="1" location="vtex/mod.ts:155">
P2: Double space after `endpoint:` is causing the `deno fmt` check to fail. Should be a single space.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| : `${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`, |
There was a problem hiding this comment.
P2: Double space after endpoint: is causing the deno fmt check to fail. Should be a single space.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At vtex/mod.ts, line 155:
<comment>Double space after `endpoint:` is causing the `deno fmt` check to fail. Should be a single space.</comment>
<file context>
@@ -152,16 +151,13 @@ export default function VTEX(
- : `${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,
</file context>
| endpoint: `https://${subAccount || account}.vtexcommercestable.com.br/api/io/_v/private/graphql/v1`, | |
| endpoint: `https://${subAccount || account}.vtexcommercestable.com.br/api/io/_v/private/graphql/v1`, |
Fix: Sales Channel não respeitado no Intelligent Search
Problema
Produtos de todas as políticas comerciais estavam sendo retornados, ignorando a configuração
salesChannel: "4".Causa Raiz
No arquivo
newapps-deco/apps/vtex/mod.ts(linha ~150), o cliente HTTPvcsDeprecatedestava configurado com:O domínio
secure.lojaspaqueta.com.brpossui um binding no License Manager da VTEX que não respeita corretamente o filtro de sales channel, retornando produtos de múltiplas políticas comerciais.Solução
Alterado para usar o domínio
vtexcommercestable, que respeita corretamente a política comercial:Impacto
salesChannel: "4"../apps/vtex/Arquivo Modificado
/Users/matheus/Documents/Trabalho/newapps-deco/apps/vtex/mod.ts(linha ~150)Fix: Null Script Error no Proxy Handler
Arquivo:
/Users/matheus/Documents/Trabalho/newapps-deco/apps/website/handlers/proxy.tsProblema
O proxy handler quebrava quando
includeScriptsToHead.includesouincludeScriptsToBody.includescontinham valoresnull/undefined.Causa
O loader
analytics/loaders/DecoAnalyticsScript.tsconfigurado em.deco/blocks/site.jsonretornanullem determinadas situações, causando erro ao tentar acessarscript.src.Solução
Adicionada validação para ignorar scripts nulos antes de acessar propriedades:
Aplicado em:
includeScriptsToHead(linha ~179)includeScriptsToBody(linha ~203)Resultado
Proxy agora ignora scripts inválidos em vez de quebrar a aplicação.
Summary by cubic
Fixes VTEX subaccount fetch/auth issues by routing clients through
vtexcommercestable(with subaccount support) and ensures Intelligent Search respects the configured sales channel; also guards against null scripts in the proxy.https://${account}.vtexcommercestable.com.brand setioGraphQL tohttps://${subAccount || account}.vtexcommercestable.com.br/api/io/_v/private/graphql/v1so subaccount requests work and Intelligent Search respectssalesChannel.VtexIdclientAutCookie(account or subaccount) inparseCookie, and addparseCookieWithoutAuthto safely read__ofidand send only the checkout cookie in cart/simulation requests.includeScriptsToHeadandincludeScriptsToBodyto avoid "Cannot read properties of null (reading 'src')" errors.Written for commit b8e322f. Summary will update on new commits. Review in cubic
Summary by CodeRabbit
New Features
Bug Fixes