@doswiftly/storefront-sdk 21.0.0 → 22.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +35 -0
- package/README.md +818 -527
- package/dist/core/auth/handlers.d.ts +10 -9
- package/dist/core/auth/handlers.d.ts.map +1 -1
- package/dist/core/auth/handlers.js +10 -9
- package/dist/core/auth/session-events.d.ts +2 -2
- package/dist/core/auth/session-events.js +2 -2
- package/dist/core/cart/cart-client.d.ts +23 -24
- package/dist/core/cart/cart-client.d.ts.map +1 -1
- package/dist/core/cart/cart-client.js +24 -25
- package/dist/core/generated/operation-types.d.ts +52 -52
- package/dist/core/generated/operation-types.d.ts.map +1 -1
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +2 -0
- package/dist/core/middleware/session-retry.d.ts +5 -6
- package/dist/core/middleware/session-retry.d.ts.map +1 -1
- package/dist/core/middleware/session-retry.js +7 -8
- package/dist/core/operations/auth.d.ts.map +1 -1
- package/dist/core/operations/auth.js +4 -0
- package/dist/core/operations/cart.d.ts +11 -10
- package/dist/core/operations/cart.d.ts.map +1 -1
- package/dist/core/operations/cart.js +14 -11
- package/dist/core/referral/cookie-config.d.ts +56 -0
- package/dist/core/referral/cookie-config.d.ts.map +1 -0
- package/dist/core/referral/cookie-config.js +83 -0
- package/dist/react/components/PaymentInstrumentSection.d.ts +24 -24
- package/dist/react/components/PaymentInstrumentSection.d.ts.map +1 -1
- package/dist/react/components/PaymentInstrumentSection.js +15 -15
- package/dist/react/components/PaymentInstrumentTile.d.ts +19 -20
- package/dist/react/components/PaymentInstrumentTile.d.ts.map +1 -1
- package/dist/react/components/PaymentInstrumentTile.js +15 -16
- package/dist/react/helpers/browser-data.d.ts +30 -33
- package/dist/react/helpers/browser-data.d.ts.map +1 -1
- package/dist/react/helpers/browser-data.js +26 -29
- package/dist/react/hooks/use-cart-manager.d.ts +1 -1
- package/dist/react/hooks/use-cart-manager.js +1 -1
- package/dist/react/hooks/use-cart.d.ts +2 -2
- package/dist/react/hooks/use-cart.js +3 -3
- package/dist/react/hooks/use-referral-capture.d.ts +9 -0
- package/dist/react/hooks/use-referral-capture.d.ts.map +1 -0
- package/dist/react/hooks/use-referral-capture.js +40 -0
- package/dist/react/hooks/use-session-expired.d.ts +6 -5
- package/dist/react/hooks/use-session-expired.d.ts.map +1 -1
- package/dist/react/hooks/use-session-expired.js +6 -5
- package/dist/react/index.d.ts +2 -0
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +5 -1
- package/dist/react/referral.d.ts +53 -0
- package/dist/react/referral.d.ts.map +1 -0
- package/dist/react/referral.js +51 -0
- package/dist/react/server/cookie-readers.d.ts +7 -0
- package/dist/react/server/cookie-readers.d.ts.map +1 -1
- package/dist/react/server/cookie-readers.js +10 -0
- package/dist/react/server/index.d.ts +1 -1
- package/dist/react/server/index.d.ts.map +1 -1
- package/dist/react/server/index.js +2 -2
- package/dist/react/stores/auth.store.d.ts.map +1 -1
- package/dist/react/stores/auth.store.js +13 -10
- package/dist/react/stores/cart.store.d.ts +1 -1
- package/dist/react/stores/cart.store.js +1 -1
- package/package.json +1 -1
|
@@ -182,18 +182,19 @@ interface WhoamiHandlerOptions {
|
|
|
182
182
|
isTrustedOrigin?: OriginValidator | null;
|
|
183
183
|
}
|
|
184
184
|
/**
|
|
185
|
-
* Create a GET handler that hydrates customer state
|
|
185
|
+
* Create a GET handler that hydrates customer state from the httpOnly cookie.
|
|
186
186
|
*
|
|
187
|
-
*
|
|
188
|
-
* (XSS
|
|
189
|
-
* UI
|
|
187
|
+
* A browser-based storefront mounts the React app after hydration with a clean
|
|
188
|
+
* auth store (XSS hardening — `accessToken` is never persisted to localStorage).
|
|
189
|
+
* To show the "logged in" UI without a login round-trip, the client calls GET
|
|
190
|
+
* `/api/auth/whoami`:
|
|
190
191
|
*
|
|
191
|
-
* 1.
|
|
192
|
-
* 2.
|
|
193
|
-
* 3.
|
|
194
|
-
* 4.
|
|
192
|
+
* 1. The endpoint reads the httpOnly cookie `customerAccessToken` (server-side, JS-inaccessible)
|
|
193
|
+
* 2. Forwards it as an `Authorization: Bearer` header to the backend GraphQL `customer` query
|
|
194
|
+
* 3. Returns `{ isAuthenticated, customer | null }` to the client
|
|
195
|
+
* 4. The client calls setAuth(customer, '') — the token is NOT in the body (the cookie keeps handling per-request auth)
|
|
195
196
|
*
|
|
196
|
-
* Security: origin validation, fetch via Bearer (cookie
|
|
197
|
+
* Security: origin validation, fetch via Bearer (the cookie never crosses the API boundary).
|
|
197
198
|
* Pass `isTrustedOrigin` when running behind a reverse proxy — see
|
|
198
199
|
* {@link trustedForwardedHostValidator}.
|
|
199
200
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handlers.d.ts","sourceRoot":"","sources":["../../../src/core/auth/handlers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH;;;;;;GAMG;AACH,MAAM,WAAW,sBAAsB;IACrC,mEAAmE;IACnE,MAAM,EAAE,MAAM,CAAC;IACf,yEAAyE;IACzE,UAAU,EAAE,MAAM,CAAC;IACnB,iEAAiE;IACjE,OAAO,EAAE,OAAO,CAAC;CAClB;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,eAAe,GAAG,CAC5B,GAAG,EAAE,sBAAsB,KACxB,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;AAEhC,UAAU,sBAAsB;IAC9B,2CAA2C;IAC3C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,sEAAsE;IACtE,eAAe,CAAC,EAAE,eAAe,GAAG,IAAI,CAAC;CAC1C;AAED,UAAU,wBAAwB;IAChC,sEAAsE;IACtE,eAAe,CAAC,EAAE,eAAe,GAAG,IAAI,CAAC;CAC1C;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,OAAO,EA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AACH,wBAAgB,qBAAqB,CACnC,SAAS,CAAC,EAAE,sBAAsB,GACjC,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAiEzC;AAED,UAAU,oBAAoB;IAC5B,0EAA0E;IAC1E,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,4CAA4C;IAC5C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,sEAAsE;IACtE,eAAe,CAAC,EAAE,eAAe,GAAG,IAAI,CAAC;CAC1C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,GAAE,oBAAyB,GACjC,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAwEzC;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,CAAC,EAAE,wBAAwB,GACjC,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAoCzC"}
|
|
@@ -265,18 +265,19 @@ export function createSetTokenHandler(overrides) {
|
|
|
265
265
|
};
|
|
266
266
|
}
|
|
267
267
|
/**
|
|
268
|
-
* Create a GET handler that hydrates customer state
|
|
268
|
+
* Create a GET handler that hydrates customer state from the httpOnly cookie.
|
|
269
269
|
*
|
|
270
|
-
*
|
|
271
|
-
* (XSS
|
|
272
|
-
* UI
|
|
270
|
+
* A browser-based storefront mounts the React app after hydration with a clean
|
|
271
|
+
* auth store (XSS hardening — `accessToken` is never persisted to localStorage).
|
|
272
|
+
* To show the "logged in" UI without a login round-trip, the client calls GET
|
|
273
|
+
* `/api/auth/whoami`:
|
|
273
274
|
*
|
|
274
|
-
* 1.
|
|
275
|
-
* 2.
|
|
276
|
-
* 3.
|
|
277
|
-
* 4.
|
|
275
|
+
* 1. The endpoint reads the httpOnly cookie `customerAccessToken` (server-side, JS-inaccessible)
|
|
276
|
+
* 2. Forwards it as an `Authorization: Bearer` header to the backend GraphQL `customer` query
|
|
277
|
+
* 3. Returns `{ isAuthenticated, customer | null }` to the client
|
|
278
|
+
* 4. The client calls setAuth(customer, '') — the token is NOT in the body (the cookie keeps handling per-request auth)
|
|
278
279
|
*
|
|
279
|
-
* Security: origin validation, fetch via Bearer (cookie
|
|
280
|
+
* Security: origin validation, fetch via Bearer (the cookie never crosses the API boundary).
|
|
280
281
|
* Pass `isTrustedOrigin` when running behind a reverse proxy — see
|
|
281
282
|
* {@link trustedForwardedHostValidator}.
|
|
282
283
|
*
|
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
* a 401 also failed. Storefronts subscribe once globally (`useSessionExpired`)
|
|
7
7
|
* and react (notify + redirect to sign-in).
|
|
8
8
|
*
|
|
9
|
-
* 0-deps
|
|
10
|
-
* instance (`useRef` + Context
|
|
9
|
+
* 0-deps: plain `Set` + closure, no React / DOM. The provider owns the
|
|
10
|
+
* instance (`useRef` + Context) — never a module-level singleton.
|
|
11
11
|
*/
|
|
12
12
|
export type SessionExpiredReason =
|
|
13
13
|
/** Proactive scheduler tried to refresh on tab wake but the session was already gone. */
|
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
* a 401 also failed. Storefronts subscribe once globally (`useSessionExpired`)
|
|
7
7
|
* and react (notify + redirect to sign-in).
|
|
8
8
|
*
|
|
9
|
-
* 0-deps
|
|
10
|
-
* instance (`useRef` + Context
|
|
9
|
+
* 0-deps: plain `Set` + closure, no React / DOM. The provider owns the
|
|
10
|
+
* instance (`useRef` + Context) — never a module-level singleton.
|
|
11
11
|
*/
|
|
12
12
|
export function createSessionExpiredEmitter() {
|
|
13
13
|
const listeners = new Set();
|
|
@@ -172,13 +172,13 @@ export declare class CartClient {
|
|
|
172
172
|
*/
|
|
173
173
|
setShippingAddress(input: CartSetShippingAddressInput): Promise<CartMutationOutcome>;
|
|
174
174
|
/**
|
|
175
|
-
* Set billing address on the cart (independent
|
|
176
|
-
* even when "billing same as shipping").
|
|
175
|
+
* Set billing address on the cart (independent of the shipping address —
|
|
176
|
+
* pass it even when "billing same as shipping").
|
|
177
177
|
*/
|
|
178
178
|
setBillingAddress(input: CartSetBillingAddressInput): Promise<CartMutationOutcome>;
|
|
179
179
|
/**
|
|
180
|
-
* Select shipping method on the cart (
|
|
181
|
-
*
|
|
180
|
+
* Select shipping method on the cart (typed `shippingMethodId` — an ID,
|
|
181
|
+
* not a plain string).
|
|
182
182
|
*/
|
|
183
183
|
selectShippingMethod(input: CartSelectShippingMethodInput): Promise<CartMutationOutcome>;
|
|
184
184
|
/**
|
|
@@ -187,28 +187,27 @@ export declare class CartClient {
|
|
|
187
187
|
*/
|
|
188
188
|
selectPaymentMethod(input: CartSelectPaymentMethodInput): Promise<CartMutationOutcome>;
|
|
189
189
|
/**
|
|
190
|
-
* Clear all payment selection state on the cart —
|
|
191
|
-
* provider code, instrument code
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
* Added by payment-instrument-preselection-advanced Adv-1 Req 3.6.
|
|
190
|
+
* Clear all payment selection state on the cart — atomically NULLs the method
|
|
191
|
+
* type, provider code, instrument code and legacy method ID. Idempotent —
|
|
192
|
+
* repeated calls produce the same final state. Use it for "back to payment
|
|
193
|
+
* method selection" accordion UI flows. The cart MUST be `ACTIVE` (CONVERTED
|
|
194
|
+
* carts throw with `ALREADY_COMPLETED`).
|
|
196
195
|
*/
|
|
197
196
|
clearPaymentSelection(input: CartClearPaymentSelectionInput): Promise<CartMutationOutcome>;
|
|
198
197
|
/**
|
|
199
|
-
* Apply gift card to cart (stackable
|
|
198
|
+
* Apply gift card to cart (stackable with discount codes, FIFO consumption).
|
|
200
199
|
* Balance NOT debited yet — actual deduction at cartComplete.
|
|
201
200
|
*/
|
|
202
201
|
applyGiftCard(input: CartApplyGiftCardInput): Promise<CartMutationOutcome>;
|
|
203
202
|
/**
|
|
204
|
-
* Remove applied gift card from cart. Re-calculates FIFO amounts
|
|
205
|
-
*
|
|
203
|
+
* Remove applied gift card from cart. Re-calculates FIFO amounts for the
|
|
204
|
+
* remaining cards.
|
|
206
205
|
*/
|
|
207
206
|
removeGiftCard(input: CartRemoveGiftCardInput): Promise<CartMutationOutcome>;
|
|
208
207
|
/**
|
|
209
|
-
* Update gift card recipient info
|
|
210
|
-
* recipientEmail, recipientName, message). Required
|
|
211
|
-
*
|
|
208
|
+
* Update gift card recipient info on a line item (personalised delivery —
|
|
209
|
+
* recipientEmail, recipientName, message). Required before cartComplete
|
|
210
|
+
* for every gift card line item.
|
|
212
211
|
*/
|
|
213
212
|
updateGiftCardRecipient(input: CartUpdateGiftCardRecipientInput): Promise<CartMutationOutcome>;
|
|
214
213
|
/**
|
|
@@ -221,8 +220,8 @@ export declare class CartClient {
|
|
|
221
220
|
* is CONVERTED/locked, so drop your local cart and work with the Order. The
|
|
222
221
|
* Order carries `canCreatePayment` + `paymentMethodType` so the storefront can
|
|
223
222
|
* decide the payment flow. `paymentUrl` is intentionally NOT in the response
|
|
224
|
-
*
|
|
225
|
-
*
|
|
223
|
+
* — the payment session is created by a separate `paymentCreate` mutation
|
|
224
|
+
* after checking `order.canCreatePayment`.
|
|
226
225
|
*/
|
|
227
226
|
complete(input: CartCompleteInput): Promise<CartCompleteOutcome>;
|
|
228
227
|
/**
|
|
@@ -244,13 +243,13 @@ export declare class CartClient {
|
|
|
244
243
|
*/
|
|
245
244
|
createPayment(input: PaymentCreateInput): Promise<PaymentSession>;
|
|
246
245
|
/**
|
|
247
|
-
* Validate discount code
|
|
248
|
-
*
|
|
249
|
-
* — storefront UI
|
|
246
|
+
* Validate a discount code as a preview — a read-only Query, NOT a mutation:
|
|
247
|
+
* validation must not mutate cart state. Returns `{ isValid, discount?, error? }`
|
|
248
|
+
* — storefront UI uses it for inline feedback while the customer types a code.
|
|
250
249
|
*
|
|
251
|
-
* Caching: storefront
|
|
252
|
-
* cache key
|
|
253
|
-
* order amount).
|
|
250
|
+
* Caching: the storefront should use `fetchPolicy: 'network-only'` or a
|
|
251
|
+
* cache key that includes `cart.subtotal` (discount eligibility may depend
|
|
252
|
+
* on a minimum order amount).
|
|
254
253
|
*/
|
|
255
254
|
validateDiscountCode(cartId: string, discountCode: string): Promise<DiscountValidationResult>;
|
|
256
255
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cart-client.d.ts","sourceRoot":"","sources":["../../../src/core/cart/cart-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,KAAK,EACV,IAAI,EACJ,eAAe,EACf,aAAa,EACb,mBAAmB,EACnB,sBAAsB,EACtB,kBAAkB,EAClB,2BAA2B,EAC3B,0BAA0B,EAC1B,6BAA6B,EAC7B,4BAA4B,EAC5B,8BAA8B,EAC9B,sBAAsB,EACtB,uBAAuB,EACvB,gCAAgC,EAChC,iBAAiB,EACjB,WAAW,EACX,KAAK,EACL,wBAAwB,EACxB,cAAc,EACd,kBAAkB,EAClB,+BAA+B,EAC/B,uBAAuB,EACvB,oBAAoB,EACrB,MAAM,SAAS,CAAC;AAoEjB;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,IAAI,CAAC;IACX,QAAQ,EAAE,WAAW,EAAE,CAAC;CACzB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,uBAAwB,SAAQ,mBAAmB;IAClE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,KAAK,CAAC;IACb,QAAQ,EAAE,WAAW,EAAE,CAAC;CACzB;AAED,qBAAa,UAAU;IACT,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,gBAAgB;IAErD;;;OAGG;IACG,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;IAQ/C;;;;;;;;;;;;;;;OAeG;IACG,2BAA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AC,mBAAmB,CAAC;IASlF;;;;OAIG;IACG,uBAAuB,CAAC,KAAK,EAAE,gCAAgC,GAAG,OAAO,CAAC,mBAAmB,CAAC;IASpG;;;;;;;;;;;;OAYG;IACG,QAAQ,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAYtE;;;;;;;;;;;;;;;;OAgBG;IACG,aAAa,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,cAAc,CAAC;IASvE;;;;;;;;OAQG;IACG,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,wBAAwB,CAAC;CAOpG"}
|
|
@@ -206,7 +206,7 @@ export class CartClient {
|
|
|
206
206
|
};
|
|
207
207
|
}
|
|
208
208
|
// -------------------------------------------------------------------------
|
|
209
|
-
//
|
|
209
|
+
// Cart completion lifecycle methods
|
|
210
210
|
// -------------------------------------------------------------------------
|
|
211
211
|
/**
|
|
212
212
|
* Set shipping address on the cart. Full replace (not patch). Triggers cart
|
|
@@ -218,8 +218,8 @@ export class CartClient {
|
|
|
218
218
|
return { cart: data.cartSetShippingAddress.cart, warnings: data.cartSetShippingAddress.warnings ?? [] };
|
|
219
219
|
}
|
|
220
220
|
/**
|
|
221
|
-
* Set billing address on the cart (independent
|
|
222
|
-
* even when "billing same as shipping").
|
|
221
|
+
* Set billing address on the cart (independent of the shipping address —
|
|
222
|
+
* pass it even when "billing same as shipping").
|
|
223
223
|
*/
|
|
224
224
|
async setBillingAddress(input) {
|
|
225
225
|
const data = await this.client.mutate(CART_SET_BILLING_ADDRESS, { input });
|
|
@@ -227,8 +227,8 @@ export class CartClient {
|
|
|
227
227
|
return { cart: data.cartSetBillingAddress.cart, warnings: data.cartSetBillingAddress.warnings ?? [] };
|
|
228
228
|
}
|
|
229
229
|
/**
|
|
230
|
-
* Select shipping method on the cart (
|
|
231
|
-
*
|
|
230
|
+
* Select shipping method on the cart (typed `shippingMethodId` — an ID,
|
|
231
|
+
* not a plain string).
|
|
232
232
|
*/
|
|
233
233
|
async selectShippingMethod(input) {
|
|
234
234
|
const data = await this.client.mutate(CART_SELECT_SHIPPING_METHOD, { input });
|
|
@@ -245,12 +245,11 @@ export class CartClient {
|
|
|
245
245
|
return { cart: data.cartSelectPaymentMethod.cart, warnings: data.cartSelectPaymentMethod.warnings ?? [] };
|
|
246
246
|
}
|
|
247
247
|
/**
|
|
248
|
-
* Clear all payment selection state on the cart —
|
|
249
|
-
* provider code, instrument code
|
|
250
|
-
*
|
|
251
|
-
*
|
|
252
|
-
*
|
|
253
|
-
* Added by payment-instrument-preselection-advanced Adv-1 Req 3.6.
|
|
248
|
+
* Clear all payment selection state on the cart — atomically NULLs the method
|
|
249
|
+
* type, provider code, instrument code and legacy method ID. Idempotent —
|
|
250
|
+
* repeated calls produce the same final state. Use it for "back to payment
|
|
251
|
+
* method selection" accordion UI flows. The cart MUST be `ACTIVE` (CONVERTED
|
|
252
|
+
* carts throw with `ALREADY_COMPLETED`).
|
|
254
253
|
*/
|
|
255
254
|
async clearPaymentSelection(input) {
|
|
256
255
|
const data = await this.client.mutate(CART_CLEAR_PAYMENT_SELECTION, { input });
|
|
@@ -261,7 +260,7 @@ export class CartClient {
|
|
|
261
260
|
};
|
|
262
261
|
}
|
|
263
262
|
/**
|
|
264
|
-
* Apply gift card to cart (stackable
|
|
263
|
+
* Apply gift card to cart (stackable with discount codes, FIFO consumption).
|
|
265
264
|
* Balance NOT debited yet — actual deduction at cartComplete.
|
|
266
265
|
*/
|
|
267
266
|
async applyGiftCard(input) {
|
|
@@ -270,8 +269,8 @@ export class CartClient {
|
|
|
270
269
|
return { cart: data.cartApplyGiftCard.cart, warnings: data.cartApplyGiftCard.warnings ?? [] };
|
|
271
270
|
}
|
|
272
271
|
/**
|
|
273
|
-
* Remove applied gift card from cart. Re-calculates FIFO amounts
|
|
274
|
-
*
|
|
272
|
+
* Remove applied gift card from cart. Re-calculates FIFO amounts for the
|
|
273
|
+
* remaining cards.
|
|
275
274
|
*/
|
|
276
275
|
async removeGiftCard(input) {
|
|
277
276
|
const data = await this.client.mutate(CART_REMOVE_GIFT_CARD, { input });
|
|
@@ -279,9 +278,9 @@ export class CartClient {
|
|
|
279
278
|
return { cart: data.cartRemoveGiftCard.cart, warnings: data.cartRemoveGiftCard.warnings ?? [] };
|
|
280
279
|
}
|
|
281
280
|
/**
|
|
282
|
-
* Update gift card recipient info
|
|
283
|
-
* recipientEmail, recipientName, message). Required
|
|
284
|
-
*
|
|
281
|
+
* Update gift card recipient info on a line item (personalised delivery —
|
|
282
|
+
* recipientEmail, recipientName, message). Required before cartComplete
|
|
283
|
+
* for every gift card line item.
|
|
285
284
|
*/
|
|
286
285
|
async updateGiftCardRecipient(input) {
|
|
287
286
|
const data = await this.client.mutate(CART_UPDATE_GIFT_CARD_RECIPIENT, { input });
|
|
@@ -298,8 +297,8 @@ export class CartClient {
|
|
|
298
297
|
* is CONVERTED/locked, so drop your local cart and work with the Order. The
|
|
299
298
|
* Order carries `canCreatePayment` + `paymentMethodType` so the storefront can
|
|
300
299
|
* decide the payment flow. `paymentUrl` is intentionally NOT in the response
|
|
301
|
-
*
|
|
302
|
-
*
|
|
300
|
+
* — the payment session is created by a separate `paymentCreate` mutation
|
|
301
|
+
* after checking `order.canCreatePayment`.
|
|
303
302
|
*/
|
|
304
303
|
async complete(input) {
|
|
305
304
|
const data = await this.client.mutate(CART_COMPLETE, { input });
|
|
@@ -332,13 +331,13 @@ export class CartClient {
|
|
|
332
331
|
return data.paymentCreate.payment;
|
|
333
332
|
}
|
|
334
333
|
/**
|
|
335
|
-
* Validate discount code
|
|
336
|
-
*
|
|
337
|
-
* — storefront UI
|
|
334
|
+
* Validate a discount code as a preview — a read-only Query, NOT a mutation:
|
|
335
|
+
* validation must not mutate cart state. Returns `{ isValid, discount?, error? }`
|
|
336
|
+
* — storefront UI uses it for inline feedback while the customer types a code.
|
|
338
337
|
*
|
|
339
|
-
* Caching: storefront
|
|
340
|
-
* cache key
|
|
341
|
-
* order amount).
|
|
338
|
+
* Caching: the storefront should use `fetchPolicy: 'network-only'` or a
|
|
339
|
+
* cache key that includes `cart.subtotal` (discount eligibility may depend
|
|
340
|
+
* on a minimum order amount).
|
|
342
341
|
*/
|
|
343
342
|
async validateDiscountCode(cartId, discountCode) {
|
|
344
343
|
const data = await this.client.query(CART_VALIDATE_DISCOUNT_CODE, { cartId, discountCode });
|