fix(core-flows, medusa): Prevent cart addresses duplication on update (#13841)

* Allow id field in addresses properties for cart update validator

* Update cart addresses in update step where id is provided, both reference and nested fields

* Add tests

* Add changeset

* Remove unnecessary map step

* Review changes
This commit is contained in:
Nicolas Gorga authored and GitHub committed 2025-12-09 21:49:16 -03:00
1 parent 4dbf46f2cb
commit fdc2b722d9
4 files changed
+337 -5

No files matched your search

@@ -43,13 +43,17 @@ export const StoreRemoveCartPromotions = z
})
.strict()
const StoreCartUpsertAddress = AddressPayload.merge(z.object({
id: z.string().optional(),
}))
export type StoreUpdateCartType = z.infer<typeof UpdateCart>
export const UpdateCart = z
.object({
region_id: z.string().optional(),
email: z.string().email().nullish(),
billing_address: z.union([AddressPayload, z.string()]).optional(),
shipping_address: z.union([AddressPayload, z.string()]).optional(),
billing_address: z.union([StoreCartUpsertAddress, z.string()]).optional(),
shipping_address: z.union([StoreCartUpsertAddress, z.string()]).optional(),
sales_channel_id: z.string().nullish(),
metadata: z.record(z.unknown()).nullish(),
promo_codes: z.array(z.string()).optional(),