Repository navigation
feat(apps-nuvemshop): minicart cart loader and typed checkout errors - #632
Merged
Merged
Conversation
JonasJesus42
force-pushed
the
JonasJesus42/nuvemshop-account
branch
from
October 7, 2026 01:20
49db110 to
e0fff42
Compare
The cart stays client-side (useCart) and goes through the Storefront API —
the classic /comprar/ endpoint IP-blocks a server-side proxy after a few
carts, so it's not used.
- loaders/cart: resolves the client items into minicart lines (name,
variant, image, price/list price, subtotal) and totals/savings, fetching
the products by ids (≤30 per call, cached). Quantities are clamped to
stock because POST /checkouts rejects a line above it (422
checkout_rejected); missing and sold-out variants go to `unavailable`.
- createCheckout: returns { error, message } for coupon_rejected,
out_of_stock (checkout_rejected), unavailable (404) and invalid (400)
instead of throwing; success shape { checkoutUrl } is unchanged.
NuvemshopApiError carries the API status/code.
- hooks: fetchCartDetails + useCartDetails for the minicart;
checkout() throws CheckoutError(code).
Live: a 50-unit line is clamped to the variant's 17, the unclamped one is
rejected as out_of_stock, an invalid coupon maps to coupon_rejected, and the
created checkout's total equals the loader's subtotal.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
JonasJesus42
changed the base branch from
JonasJesus42/nuvemshop-account
to
main
October 7, 2026 01:20
JonasJesus42
force-pushed
the
JonasJesus42/nuvemshop-cart
branch
from
October 7, 2026 01:20
f767ad2 to
e0cca9a
Compare
|
🎉 This PR is included in version 7.77.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
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.
What
The minicart data for
@decocms/apps-nuvemshop, using the Storefront API.The cart stays in the browser (
useCart,localStorage). Checkout goes throughPOST /checkouts. We don't use the theme's classic/comprar/endpoint: after about 15 carts created in a few minutes, Nuvemshop returned 403 on every/comprar/from that IP for over 40 minutes. A server-side proxy would send every buyer through the Worker's egress IPs, so one spike could block add-to-cart for the whole store. Details are in theapps-nuvemshopskill.loaders/cartturns the client items into minicart lines: name, variant, image, price, list price, subtotal andmaxQuantity, plus totals and savings.ids, up to 30 per call, through the existing SWR cache.POST /checkoutsrejects a line above it with422 checkout_rejected.unavailableand are left out of the totals.createCheckoutnow returns{ error, message }instead of throwing. The success shape ({ checkoutUrl }) is unchanged.error422 coupon_rejectedcoupon_rejected422 checkout_rejectedout_of_stock404 resource_not_foundunavailable400 invalid_requestinvalidNuvemshopApiErrorcarries the API's status and code.Hooks:
fetchCartDetailsanduseCartDetails()back the minicart;checkout()throws aCheckoutErrorwith the code, so the UI can show the right message.There is no coupon preview before checkout, because the API has none. The checkout validates the coupon.
Stacked on #631.
Verified
tsc, biome andskills:checkare clean.out_of_stock;unavailable;coupon_rejected;🤖 Generated with Claude Code
Summary by cubic
Adds a minicart loader and typed checkout errors to
@decocms/apps-nuvemshop, moving checkout to the Storefront API instead of the classic/comprar/endpoint, which IP-blocks server-side proxies after a handful of carts.loaders/cartresolves client-helduseCartitems into minicart lines (name, variant, image, prices, subtotal) with totals and savings, fetching products byids, batched ≤30 per call and cached.POST /checkoutsdoesn't reject a line with422 checkout_rejected; missing, hidden, and sold-out variants move tounavailableand are excluded from totals.createCheckoutnow returns{ error, message }on failures instead of throwing, mapping API codes to typed errors (coupon_rejected,out_of_stock,unavailable,invalid); the success shape{ checkoutUrl }is unchanged andNuvemshopApiErrorcarries the status and code.fetchCartDetails/useCartDetailshooks back the minicart;checkout()throws aCheckoutErrorcarrying the code so the UI can react.Written for commit e0cca9a. Summary will update on new commits.