Repository navigation
feat: expose updateOrderFormAttachment in VTEX invoke - #2
Merged
Merged
Conversation
Needed by useCart.sendAttachment for cart profile/payment attachment updates. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
|
🎉 This PR is included in version 0.21.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
3 tasks
JonasJesus42
added a commit
that referenced
this pull request
Jun 2, 2026
…eno prod)
Adds 21 unit tests across 3 files covering the surfaces this PR ports.
Tests pin behavior the Fresh/Deno production code (deco-cx/apps/magento)
established, so future refactors of the apps-start port can refactor
freely without drifting from prod.
magento/__tests__/client.test.ts (12 tests):
configureMagento / getMagentoConfig:
- throws before configure (no implicit defaults)
- returns the configured value after configure
magentoFetch — same-origin:
- attaches Authorization + x-origin-header + forced Referer
- resolves relative path against baseUrl
- authenticated:false drops Bearer (still attaches origin/referer)
- preserves caller-supplied Referer (no force-overwrite)
magentoFetch — cross-origin guard:
- strips Bearer (regression for cubic finding #1)
- strips x-origin-header (regression for cubic finding #2)
- strips forced Referer (regression for cubic finding #2)
- forwards caller-supplied headers through
- same-origin absolute URL still gets identity headers
magento/__tests__/features.test.ts (2 tests):
- returns the configured features object
- returns {} when features omitted
magento/__tests__/cart.test.ts (7 tests):
- returns null when no cookie (matches prod's `if (!cartId) return null`)
- reads dataservices_cart_id cookie (JSON-quoted form)
- reads dataservices_cart_id cookie (raw form, no quotes)
- props.cartId override beats the cookie
- URL-encodes cartId — regression for cubic finding #3 (path injection)
- 404 returns null (expired cookie)
- non-404 errors throw
- cart fetch attaches Bearer + x-origin-header (same-origin)
Drive-by fix: cart loader was hitting /:site/V1/carts/:cartId, but Magento
exposes the cart endpoint at /rest/:site/V1/carts/:cartId — the /rest/
prefix is mandatory and matches the legacy clientAdmin's typed key
`GET /rest/:site/V1/carts/:cartId`. Tests pin the corrected path.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
JonasJesus42
added a commit
that referenced
this pull request
Jun 2, 2026
…61) * feat(magento): initial scaffold port from deco-cx/apps to apps-start Starts the Magento app port to @decocms/apps following the same shape as vtex/ and shopify/. This first commit lands the configure surface and 2 reference loaders (features, cart) — enough to unblock real consumer sites; the remaining ~20 loaders/actions are itemized in magento/README.md and will follow in separate commits. Contents: - magento/client.ts — configureMagento({ baseUrl, apiKey, storeId, ... }) with module-global state, mirroring configureVtex. magentoFetch() helper attaches Bearer auth + Referer + optional x-origin-header on every call. initMagentoFromBlocks(blocks) resolves the CMS block's `__resolveType: "website/loaders/secret.ts"` references via env vars, same fallback granadobr-tanstack already uses in production. - magento/types.ts — MagentoCart + MagentoCartItem shapes used by the ported loaders. - magento/loaders/features.ts — returns the resolved Features block from the config. The simplest loader, used as the smoke test. - magento/loaders/cart.ts — fetches the customer's active cart by reading `dataservices_cart_id` cookie via @decocms/start/sdk/cookie and calling the Magento admin REST endpoint. Returns null for anonymous sessions (expected) and on 404 (expired cookie). - magento/middleware.ts — passthrough today; the legacy changeCardIdAfterCheckout reconciliation flow is deferred to a follow-up PR. - magento/index.ts — re-export entry, parallel to vtex/index.ts. - package.json — adds @decocms/apps/magento/* exports. Motivation: deco-sites/granadobr-tanstack (Granado, Brazilian cosmetics) just migrated from Fresh/Deno to TanStack Start. Its parity audit reported a HIGH severity finding: invoke(magento/loaders/features) failed: handler not found …because no @decocms/apps/magento/* resolver existed. The site is working around it with an in-site adapter that re-uses the legacy mod.ts shape; this PR begins the upstream fix so the next Magento storefront doesn't need to repeat the work. Companion issue: #60 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * fix(magento): address 3 cubic-dev-ai review findings (all P1) 1. package.json: `magento/` was in `exports` but not `files`. npm publish excludes any path not listed under `files`, so the entire magento folder would be missing from the published tarball — every consumer site would get module-resolution errors. Added `magento/` to the array alongside commerce/shopify/vtex/etc. 2. magento/loaders/cart.ts: cartId comes from a request cookie (`dataservices_cart_id`) and was spliced into the admin REST path unencoded. Wrapped both `site` and `cartId` in encodeURIComponent so user input can't break out of the path segment to tack on query or fragment parts that would hit a different endpoint with the privileged Bearer token attached. 3. magento/client.ts: magentoFetch() accepted any `path` value, including absolute URLs to arbitrary hosts. The auth headers (Bearer, Referer, x-origin-header) were attached unconditionally, so a caller passing `https://attacker.example/...` would leak the Magento admin token. Now constructs a URL up front, compares its origin against the configured baseUrl, and force-disables `authenticated` when the request is cross-origin. Genuine third-party calls remain possible via the explicit `authenticated: false` opt-out. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * fix(magento): biome formatting + add magento/** to lint includes Biome's includes array was missing magento/**, so the new package was skipped by lint entirely. Added it to the includes alongside the other apps. Also ran biome --write to convert space indentation to tab (project convention) across the 5 magento source files. Note: the test job also surfaces pre-existing lint errors in vtex/__tests__/ client-set-cookie-forward.test.ts and website/components/__tests__/ OneDollarStats.test.ts. Those are unrelated to this PR — they were already failing on main before any magento file was added. Splitting that into a separate PR. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * fix(magento): strip ALL Magento-identity headers in cross-origin requests Cubic's second pass caught that the previous fix only suppressed the Bearer token but still leaked `x-origin-header` (an opaque secret) and a forced `Referer` pointing at the Magento storefront URL whenever a caller passed an absolute non-Magento URL. Now `buildHeaders` takes an explicit `attachMagentoIdentity` flag. `magentoFetch` sets it to `target.origin === baseUrl.origin`, so a cross-origin call gets only whatever headers the caller passed in their `opts.headers` — no Magento-side credentials, no origin-header secret, no forced Referer. Callers wanting a genuinely cross-origin GET should still flip `authenticated: false` at the call site for intent, but security no longer relies on that single flag being correct. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * test(magento): pin behavior parity with deco-cx/apps/magento (Fresh/Deno prod) Adds 21 unit tests across 3 files covering the surfaces this PR ports. Tests pin behavior the Fresh/Deno production code (deco-cx/apps/magento) established, so future refactors of the apps-start port can refactor freely without drifting from prod. magento/__tests__/client.test.ts (12 tests): configureMagento / getMagentoConfig: - throws before configure (no implicit defaults) - returns the configured value after configure magentoFetch — same-origin: - attaches Authorization + x-origin-header + forced Referer - resolves relative path against baseUrl - authenticated:false drops Bearer (still attaches origin/referer) - preserves caller-supplied Referer (no force-overwrite) magentoFetch — cross-origin guard: - strips Bearer (regression for cubic finding #1) - strips x-origin-header (regression for cubic finding #2) - strips forced Referer (regression for cubic finding #2) - forwards caller-supplied headers through - same-origin absolute URL still gets identity headers magento/__tests__/features.test.ts (2 tests): - returns the configured features object - returns {} when features omitted magento/__tests__/cart.test.ts (7 tests): - returns null when no cookie (matches prod's `if (!cartId) return null`) - reads dataservices_cart_id cookie (JSON-quoted form) - reads dataservices_cart_id cookie (raw form, no quotes) - props.cartId override beats the cookie - URL-encodes cartId — regression for cubic finding #3 (path injection) - 404 returns null (expired cookie) - non-404 errors throw - cart fetch attaches Bearer + x-origin-header (same-origin) Drive-by fix: cart loader was hitting /:site/V1/carts/:cartId, but Magento exposes the cart endpoint at /rest/:site/V1/carts/:cartId — the /rest/ prefix is mandatory and matches the legacy clientAdmin's typed key `GET /rest/:site/V1/carts/:cartId`. Tests pin the corrected path. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
updateOrderFormAttachmentto the VTEXinvokeobject, needed byuseCart.sendAttachmentfor updating cart profile/payment attachmentsTest plan
🤖 Generated with Claude Code
Summary by cubic
Exposed
updateOrderFormAttachmenton VTEXinvokesouseCart.sendAttachmentcan update cart profile, custom data, and payment attachments.invoke.checkout.updateOrderFormAttachment({ orderFormId, attachment, body }) => Promise<OrderForm>with unwrapped result.Written for commit 20f1ceb. Summary will update on new commits.