Bump Spree SDK to 0.14 - #73
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughThe PR updates the storefront to align with Spree SDK 0.14.x: it renames address fields (firstname/lastname/zipcode → first_name/last_name/postal_code), address containers (ship_address/bill_address → shipping_address/billing_address), card fields (cc_type/last_digits → brand/last4), discount fields (promo_total/promotions → discount_total/discounts), and product option fields (presentation → label) across UI, data, and analytics code. Changes
Estimated Code Review Effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
📝 Coding Plan
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: 3
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/lib/utils/address.ts (1)
62-75:⚠️ Potential issue | 🔴 CriticalFix camelCase key mismatch in address conversion.
The
AddressParamstype from@spree/sdkv0.14.2 expects camelCase keys (firstname,lastname,zipcode), not snake_case. This function will send ignored keys and break address persistence for names and postal codes.Required changes
export function formDataToAddress(data: AddressFormData): AddressParams { return { - first_name: data.first_name, - last_name: data.last_name, + firstname: data.first_name, + lastname: data.last_name, address1: data.address1, address2: data.address2 || undefined, city: data.city, - postal_code: data.postal_code, + zipcode: data.postal_code, phone: data.phone || undefined, company: data.company || undefined, country_iso: data.country_iso, state_abbr: data.state_abbr || undefined, state_name: data.state_name || undefined, }; }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/lib/utils/address.ts` around lines 62 - 75, The formDataToAddress function returns snake_case keys that don't match the AddressParams shape from `@spree/sdk` v0.14.2; update the returned object in formDataToAddress to use the expected AddressParams property names (e.g., map first_name -> firstname, last_name -> lastname, postal_code -> zipcode, state_abbr -> stateAbbr, state_name -> stateName, address2/phone/company keep as optional but using the SDK's key casing) so the address payload matches the SDK contract.
🧹 Nitpick comments (1)
src/lib/utils/address.ts (1)
17-29: PrefersatisfiesforemptyAddress.This keeps the literal checked against
AddressFormDatawithout widening it through an annotation.As per coding guidelines, "Use strict TypeScript type checking. Always define explicit return types for functions, use 'satisfies' for type checking object literals, and avoid 'any' (use 'unknown' instead)."♻️ Possible cleanup
-export const emptyAddress: AddressFormData = { +export const emptyAddress = { first_name: "", last_name: "", address1: "", address2: "", city: "", postal_code: "", phone: "", company: "", country_iso: "", state_abbr: "", state_name: "", -}; +} satisfies AddressFormData;🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/lib/utils/address.ts` around lines 17 - 29, Replace the type annotation on the emptyAddress object with TypeScript's "satisfies" operator so the literal is type-checked against AddressFormData without widening; locate the exported constant emptyAddress and change its declaration to use "satisfies AddressFormData" (retaining the same property values) so the compiler enforces the shape while preserving literal types.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/components/checkout/Summary.tsx`:
- Around line 68-73: The conditional uses parseFloat(cart.discount_total) which
yields NaN when discount_total is undefined, causing the Discount row to render;
update the check in the Summary component to guard for a missing value first,
e.g. use Number(cart.discount_total ?? 0) !== 0 or (cart.discount_total != null
&& parseFloat(cart.discount_total) !== 0) so the row only renders when
cart.discount_total is present and non-zero; keep rendering of
cart.display_discount_total unchanged.
In `@src/lib/analytics/gtm.ts`:
- Line 221: The code currently assigns coupon with order.discounts?.[0]?.code
which picks index 0 even when that discount has no code; change it to search for
the first discount object that has a non-empty code (e.g., use
Array.prototype.find on order.discounts) and set coupon to that discount.code
(ensuring null/undefined safety), updating the variable named coupon in
src/lib/analytics/gtm.ts so coupon reflects the first discount with a code
rather than always index 0.
- Around line 110-112: The code sets item.discount from the line-level
discount_total which overstates discounts when quantity > 1; change the
assignment in the GTM mapping so that if discountTotal < 0 you divide the
absolute line discount by the lineItem.quantity (use
safeParseFloat(lineItem.quantity) or parseInt) to compute a per-unit discount,
and assign that value to item.discount (preserving existing use of
safeParseFloat for discountTotal and referencing lineItem.discount_total,
lineItem.quantity, and item.discount to locate the change).
---
Outside diff comments:
In `@src/lib/utils/address.ts`:
- Around line 62-75: The formDataToAddress function returns snake_case keys that
don't match the AddressParams shape from `@spree/sdk` v0.14.2; update the returned
object in formDataToAddress to use the expected AddressParams property names
(e.g., map first_name -> firstname, last_name -> lastname, postal_code ->
zipcode, state_abbr -> stateAbbr, state_name -> stateName,
address2/phone/company keep as optional but using the SDK's key casing) so the
address payload matches the SDK contract.
---
Nitpick comments:
In `@src/lib/utils/address.ts`:
- Around line 17-29: Replace the type annotation on the emptyAddress object with
TypeScript's "satisfies" operator so the literal is type-checked against
AddressFormData without widening; locate the exported constant emptyAddress and
change its declaration to use "satisfies AddressFormData" (retaining the same
property values) so the compiler enforces the shape while preserving literal
types.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 4ca4bf4e-3102-4fae-ab20-a3dac8568e4a
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (23)
package.jsonsrc/app/[country]/[locale]/(checkout)/checkout/[id]/page.tsxsrc/app/[country]/[locale]/(checkout)/order-placed/[id]/page.tsxsrc/app/[country]/[locale]/(storefront)/cart/page.tsxsrc/components/account/CreditCardList.tsxsrc/components/account/OrderDetail.tsxsrc/components/addresses/AddressManagement.tsxsrc/components/cart/CartDrawer.tsxsrc/components/checkout/AddressEditModal.tsxsrc/components/checkout/AddressFormFields.tsxsrc/components/checkout/AddressSection.tsxsrc/components/checkout/AddressSelector.tsxsrc/components/checkout/CouponCode.tsxsrc/components/checkout/PaymentSection.tsxsrc/components/checkout/Summary.tsxsrc/components/products/VariantPicker.tsxsrc/components/products/filters/FilterChips.tsxsrc/components/products/filters/MobileFilterDrawer.tsxsrc/components/products/filters/OptionDropdownContent.tsxsrc/components/products/filters/ProductFilters.tsxsrc/lib/analytics/gtm.tssrc/lib/data/checkout.tssrc/lib/utils/address.ts
Summary by CodeRabbit