@doswiftly/storefront-sdk 9.0.0 → 10.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 +180 -0
- package/dist/core/auth/types.d.ts +10 -3
- package/dist/core/auth/types.d.ts.map +1 -1
- package/dist/core/cart/cart-client.d.ts +96 -11
- package/dist/core/cart/cart-client.d.ts.map +1 -1
- package/dist/core/cart/cart-client.js +131 -22
- package/dist/core/cart/types.d.ts +189 -0
- package/dist/core/cart/types.d.ts.map +1 -1
- package/dist/core/index.d.ts +2 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/middleware/bot-protection.d.ts +1 -1
- package/dist/core/middleware/bot-protection.d.ts.map +1 -1
- package/dist/core/operations/auth.d.ts +2 -2
- package/dist/core/operations/auth.d.ts.map +1 -1
- package/dist/core/operations/auth.js +4 -3
- package/dist/core/operations/cart.d.ts +38 -11
- package/dist/core/operations/cart.d.ts.map +1 -1
- package/dist/core/operations/cart.js +264 -20
- package/dist/react/hooks/use-cart-manager.d.ts +6 -5
- package/dist/react/hooks/use-cart-manager.d.ts.map +1 -1
- package/dist/react/hooks/use-cart-manager.js +2 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,185 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 10.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- 95a24d3: Cart and customer operations realigned with the backend GraphQL contract + non-blocking `warnings` surface + richer type exports.
|
|
8
|
+
|
|
9
|
+
**`@doswiftly/storefront-operations`** — additive:
|
|
10
|
+
- `fragment Order` now includes `canCreatePayment: Boolean!` and `paymentMethodType: PaymentMethodType!`. After `cartComplete`, the storefront can read these directly from the resulting `Order` (instead of branching on hard-coded provider names) to decide whether to call `paymentCreate` or render a "complete on delivery" message.
|
|
11
|
+
|
|
12
|
+
**`@doswiftly/storefront-sdk`** — breaking, action required:
|
|
13
|
+
|
|
14
|
+
Cart mutation names, arguments, and result shapes are now aligned with the published GraphQL contract. Previous names worked against an older backend snapshot; the package now ships GraphQL documents the live API actually accepts.
|
|
15
|
+
- Cart line mutations renamed: `cartLinesAdd` → `cartAddLines`, `cartLinesUpdate` → `cartUpdateLines`, `cartLinesRemove` → `cartRemoveLines`.
|
|
16
|
+
- Cart attribute mutations renamed: `cartNoteUpdate` → `cartUpdateNote`, `cartBuyerIdentityUpdate` → `cartUpdateBuyerIdentity`.
|
|
17
|
+
- Cart mutation argument `cartId` renamed to `id` on six mutations: `cartAddLines`, `cartUpdateLines`, `cartRemoveLines`, `cartDiscountCodesUpdate`, `cartUpdateNote`, `cartUpdateBuyerIdentity`. (Phase 3 lifecycle mutations and `cartComplete` keep their typed `*Input!` argument unchanged.)
|
|
18
|
+
- All 16 cart mutations now return `warnings: [CartWarning!]!` (non-blocking advisory hints — e.g. low stock, partial availability). `CartClient` methods return `{ cart, warnings }` instead of `Cart`; storefronts can render `warnings` as soft notices without aborting the flow. `cartComplete` returns `{ cart, order, warnings }`.
|
|
19
|
+
- `useCartManager()` React hook methods (`addItem`, `updateItem`, `removeItem`, `updateDiscountCodes`, `updateNote`) now return `CartMutationOutcome` (`{ cart, warnings }`) to match the underlying `CartClient`.
|
|
20
|
+
- `cartComplete` now requests the full `Order` fragment (with `canCreatePayment` + `paymentMethodType`) — the prior local `OrderMinimal` fragment is removed. The exported `Order` type now mirrors the full fragment shape (`totals`, lifecycle timestamps, `shippingAddress`).
|
|
21
|
+
- `Customer` type fields match the GraphQL schema: `emailVerified` → `isEmailVerified`, `emailMarketingState` → `emailMarketing`, `ordersCount` → `orderCount`. Customer's `defaultAddress` now includes the computed `name` field.
|
|
22
|
+
- `CustomerCreateInput` exposes `phone`, `acceptsMarketing`, and `marketingOptInLevel` (`'SINGLE_OPT_IN' | 'CONFIRMED_OPT_IN'`) so signup forms can collect marketing consent without dropping to raw GraphQL.
|
|
23
|
+
- New types exported from the package root: `CartWarning`, `Order`, `PaymentMethodType`, `CartMutationOutcome`, `CartCompleteOutcome`, all Phase 3 cart-completion input types (`CartAddressInput`, `CartSetShippingAddressInput`, `CartSetBillingAddressInput`, `CartSelectShippingMethodInput`, `CartSelectPaymentMethodInput`, `CartApplyGiftCardInput`, `CartRemoveGiftCardInput`, `CartUpdateGiftCardRecipientInput`, `CartCompleteInput`), and discount-validation types (`DiscountValidationResult`, `DiscountInfo`, `DiscountValidationError`, `DiscountErrorCode`, `DiscountApplicationType`).
|
|
24
|
+
- `CartBuyerIdentityInput` exposes optional `languageCode` (ISO 639-1, e.g. `'PL'`) to match the backend input shape.
|
|
25
|
+
|
|
26
|
+
**Migration**
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
// Before
|
|
30
|
+
const cart = await cartClient.addItems(cartId, [{ variantId, quantity: 1 }]);
|
|
31
|
+
// ^^^^ Cart
|
|
32
|
+
|
|
33
|
+
// After
|
|
34
|
+
const { cart, warnings } = await cartClient.addItems(cartId, [
|
|
35
|
+
{ variantId, quantity: 1 },
|
|
36
|
+
]);
|
|
37
|
+
for (const w of warnings) console.warn(`[${w.code}] ${w.message}`);
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
If you were writing raw GraphQL operations rather than using `CartClient`, update mutation names and the `cartId` → `id` argument as above, and add a `warnings { message code target }` selection to each cart mutation.
|
|
41
|
+
|
|
42
|
+
If you read `customer.emailVerified` / `customer.emailMarketingState` / `customer.ordersCount` anywhere, rename to `isEmailVerified` / `emailMarketing` / `orderCount` respectively.
|
|
43
|
+
|
|
44
|
+
- ff246df: `PaymentMethodType` trimmed to the categories the API actually returns today.
|
|
45
|
+
|
|
46
|
+
`APPLE_PAY`, `GOOGLE_PAY`, and `PAYPAL` were placeholders for wallet providers that aren't deployed yet — they could never appear in a real response. They are removed from `PaymentMethodType` (both as a GraphQL enum value and as a SDK union member). The enum is now `'CARD' | 'BLIK' | 'BANK_TRANSFER' | 'CASH_ON_DELIVERY' | 'OTHER'`.
|
|
47
|
+
|
|
48
|
+
**Migration**
|
|
49
|
+
|
|
50
|
+
If your storefront branches on these values (`if (order.paymentMethodType === 'APPLE_PAY') { … }`), those branches were dead code — remove them. When wallet providers ship, the corresponding type values will be reintroduced alongside their implementation.
|
|
51
|
+
|
|
52
|
+
Unrecognized providers continue to fall through to `OTHER` — your default fallback path is unchanged.
|
|
53
|
+
|
|
54
|
+
- fcd4c75: Cart GraphQL surface rebuild — Phase 3 Cluster 2 of cart unification.
|
|
55
|
+
|
|
56
|
+
**Breaking changes**:
|
|
57
|
+
- **`cartApplyDiscountCodes` mutation renamed to `cartDiscountCodesUpdate`**. Semantyka pozostaje replace-all (overwrite całej listy discount codes). Migration: change mutation name in your GraphQL queries; arguments + return shape unchanged. Operation name w typed client (`CartApplyDiscountCodes` → `CartDiscountCodesUpdate`).
|
|
58
|
+
- **`CartApplyDiscountCodesPayload` payload type renamed to `CartDiscountCodesUpdatePayload`**. Schema name + TypeScript type reference both renamed.
|
|
59
|
+
|
|
60
|
+
**New mutations** (additive, non-breaking — opt-in for new functionality):
|
|
61
|
+
- `cartSetShippingAddress(input: CartSetShippingAddressInput): CartSetShippingAddressPayload` — ustaw adres dostawy na koszyku.
|
|
62
|
+
- `cartSetBillingAddress(input: CartSetBillingAddressInput): CartSetBillingAddressPayload` — ustaw adres do faktury (jeśli różny od shipping).
|
|
63
|
+
- `cartSelectShippingMethod(input: CartSelectShippingMethodInput): CartSelectShippingMethodPayload` — wybierz metodę wysyłki; argument `shippingMethodId: ID!` (typed UUID, NIE String).
|
|
64
|
+
- `cartSelectPaymentMethod(input: CartSelectPaymentMethodInput): CartSelectPaymentMethodPayload` — wybierz integration payment provider.
|
|
65
|
+
- `cartApplyGiftCard(input: CartApplyGiftCardInput): CartApplyGiftCardPayload` — apply gift card code.
|
|
66
|
+
- `cartRemoveGiftCard(input: CartRemoveGiftCardInput): CartRemoveGiftCardPayload` — remove applied gift card.
|
|
67
|
+
- `cartUpdateGiftCardRecipient(input: CartUpdateGiftCardRecipientInput): CartUpdateGiftCardRecipientPayload` — set recipient info for a gift card line item (personalised delivery).
|
|
68
|
+
- `cartComplete(input: CartCompleteInput): CartCompletePayload` — finalize cart → create Order. Returns `{ cart, order, userErrors, warnings }`. Bez `paymentUrl` w response — wywołaj `order(id: ...)` query po `cartComplete` żeby pobrać `canCreatePayment` + `paymentMethodType` signals (cart aware payment provider selection).
|
|
69
|
+
|
|
70
|
+
**Extended types**:
|
|
71
|
+
- `Cart` object dostaje 7 nowych pól reprezentujących cart completion state:
|
|
72
|
+
- `email: String`
|
|
73
|
+
- `phone: String`
|
|
74
|
+
- `shippingAddress: MailingAddress`
|
|
75
|
+
- `billingAddress: MailingAddress`
|
|
76
|
+
- `selectedShippingMethod: CartShippingMethod` — typed jako nowy ObjectType `CartShippingMethod` (handle, title, price).
|
|
77
|
+
- `selectedPaymentMethod: PaymentMethod`
|
|
78
|
+
- `appliedGiftCards: [CartAppliedGiftCard!]!` — non-null array (empty `[]` gdy zero gift cards applied).
|
|
79
|
+
- `CartCreateInput` dostaje opcjonalne pola `email: String` + `shippingAddress: CartAddressInput` — pozwala utworzyć cart z initial fulfillment context w jednym round-trip (zamiast cartCreate → cartUpdateBuyerIdentity → cartSetShippingAddress fanout).
|
|
80
|
+
- `cartUpdateBuyerIdentity` mutation now persists `email` + `phone` fields (previously these were silently ignored — only `customerId` was persisted to the cart). Migration: jeśli storefront wysyła email/phone w `buyerIdentity` input, te wartości będą teraz trwale zapisane.
|
|
81
|
+
|
|
82
|
+
**New error codes** w `CartErrorCode` enum:
|
|
83
|
+
- `SHIPPING_ADDRESS_REQUIRED` — emit przez `cartComplete` gdy adres dostawy nie ustawiony.
|
|
84
|
+
- `SHIPPING_METHOD_REQUIRED` — emit przez `cartComplete` lub `cartSelectShippingMethod` gdy metoda wymagana.
|
|
85
|
+
- `PAYMENT_METHOD_REQUIRED` — emit przez `cartComplete` lub `cartSelectPaymentMethod`.
|
|
86
|
+
- `EMAIL_REQUIRED` — emit przez `cartComplete` gdy email nie ustawiony.
|
|
87
|
+
- `INVALID_ADDRESS` — emit przez address mutations dla nieprawidłowego adresu.
|
|
88
|
+
- `GIFT_CARD_NOT_FOUND` / `GIFT_CARD_DEPLETED` / `GIFT_CARD_UNUSABLE` — emit przez gift card mutations.
|
|
89
|
+
|
|
90
|
+
**Migration guide**:
|
|
91
|
+
|
|
92
|
+
Update GraphQL queries w storefront:
|
|
93
|
+
|
|
94
|
+
```diff
|
|
95
|
+
- mutation CartApplyDiscountCodes($id: ID!, $discountCodes: [String!]!) {
|
|
96
|
+
- cartApplyDiscountCodes(id: $id, discountCodes: $discountCodes) {
|
|
97
|
+
+ mutation CartDiscountCodesUpdate($id: ID!, $discountCodes: [String!]!) {
|
|
98
|
+
+ cartDiscountCodesUpdate(id: $id, discountCodes: $discountCodes) {
|
|
99
|
+
cart { ...Cart }
|
|
100
|
+
userErrors { ...UserError }
|
|
101
|
+
warnings { ...CartWarning }
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
SDK methods: regenerate typed-document via `pnpm codegen` po update do nowej wersji `@doswiftly/storefront-operations` — `CartApplyDiscountCodesDocument` zostanie zastąpiony `CartDiscountCodesUpdateDocument`. Jeśli używasz typed React hooks, sygnatury hook stays the same (`useCartDiscountCodesUpdateMutation`).
|
|
107
|
+
|
|
108
|
+
### Minor Changes
|
|
109
|
+
|
|
110
|
+
- 270249e: CartClient extension — Phase 6 unify-cart-graphql-surface (additive over major changes from Phase 3 Cluster 2).
|
|
111
|
+
|
|
112
|
+
**9 new CartClient methods**:
|
|
113
|
+
- `cartClient.setShippingAddress(input)` — set shipping address on cart.
|
|
114
|
+
- `cartClient.setBillingAddress(input)` — set billing address.
|
|
115
|
+
- `cartClient.selectShippingMethod(input)` — Decision D8 typed `shippingMethodId: ID!`.
|
|
116
|
+
- `cartClient.selectPaymentMethod(input)` — select integration payment provider.
|
|
117
|
+
- `cartClient.applyGiftCard(input)` — stackable gift card application (FIFO consumption).
|
|
118
|
+
- `cartClient.removeGiftCard(input)` — remove applied gift card.
|
|
119
|
+
- `cartClient.updateGiftCardRecipient(input)` — set recipient info on gift card line item (personalised delivery — required przed `complete` dla gift card SKU).
|
|
120
|
+
- `cartClient.complete(input)` — finalize cart → Order (returns `{ cart, order }`). Idempotent on `idempotencyKey`. No `paymentUrl` (Decision D4) — caller wywoła osobną mutation if online payment needed.
|
|
121
|
+
- `cartClient.validateDiscountCode(cartId, code)` — Query (Decision D3 read-only preview). Returns `{ isValid, discount?, error? }`. NIE modifies cart state.
|
|
122
|
+
|
|
123
|
+
**Extended SDK types**:
|
|
124
|
+
|
|
125
|
+
`Cart` interface extends z fulfillment + payment + gift card fields:
|
|
126
|
+
|
|
127
|
+
```diff
|
|
128
|
+
interface Cart {
|
|
129
|
+
id: string;
|
|
130
|
+
// ... existing fields ...
|
|
131
|
+
+ email: string | null;
|
|
132
|
+
+ phone: string | null;
|
|
133
|
+
+ shippingAddress: MailingAddress | null;
|
|
134
|
+
+ billingAddress: MailingAddress | null;
|
|
135
|
+
+ selectedShippingMethod: CartShippingMethod | null;
|
|
136
|
+
+ selectedPaymentMethod: CartSelectedPaymentMethod | null;
|
|
137
|
+
+ appliedGiftCards: CartAppliedGiftCard[];
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
`CartCreateInput` extends z `email?: string` + `shippingAddress?: CartAddressInput` (Phase 3 Task 3.2 — initial fulfillment context w jednym round-trip).
|
|
142
|
+
|
|
143
|
+
New types exported z `@doswiftly/storefront-sdk`:
|
|
144
|
+
- `MailingAddress`, `CartAddressInput`, `CartShippingMethod`, `CartAppliedGiftCard`, `CartSelectedPaymentMethod`, `PaymentMethodType`
|
|
145
|
+
- Input types: `CartSetShippingAddressInput`, `CartSetBillingAddressInput`, `CartSelectShippingMethodInput`, `CartSelectPaymentMethodInput`, `CartApplyGiftCardInput`, `CartRemoveGiftCardInput`, `CartUpdateGiftCardRecipientInput`, `CartCompleteInput`
|
|
146
|
+
- `Order` (minimal shape z `canCreatePayment` + `paymentMethodType` ResolveFields — Phase 4 capability signal)
|
|
147
|
+
- `DiscountValidationResult`, `DiscountInfo`, `DiscountValidationError`, `DiscountErrorCode`, `DiscountApplicationType`
|
|
148
|
+
|
|
149
|
+
**New GraphQL operations** (`@doswiftly/storefront-sdk/operations/cart`):
|
|
150
|
+
|
|
151
|
+
8 mutations + 1 Query — `CART_SET_SHIPPING_ADDRESS`, `CART_SET_BILLING_ADDRESS`, `CART_SELECT_SHIPPING_METHOD`, `CART_SELECT_PAYMENT_METHOD`, `CART_APPLY_GIFT_CARD`, `CART_REMOVE_GIFT_CARD`, `CART_UPDATE_GIFT_CARD_RECIPIENT`, `CART_COMPLETE`, `CART_VALIDATE_DISCOUNT_CODE`. Wszystkie inline fragments — zero codegen w SDK.
|
|
152
|
+
|
|
153
|
+
**Caching guidance dla `validateDiscountCode`**:
|
|
154
|
+
|
|
155
|
+
Read-only Query — możesz cache'ować z TanStack Query lub fetch wrapper. Recommendation: `fetchPolicy: 'network-only'` lub cache key zawierający `cart.subtotal` (discount eligibility może zależeć od minimum order amount).
|
|
156
|
+
|
|
157
|
+
**Note for `complete()`**:
|
|
158
|
+
|
|
159
|
+
Method zwraca `{ cart, order: Order | null }`. `order.canCreatePayment` signals czy storefront może zainicjować online płatność (false dla COD/manual/bank_transfer/PAID/CANCELLED — pokaż instrukcję manualną; true dla PayU/Stripe online flow — wywołaj `paymentCreate`). `order.paymentMethodType` daje payment category (CARD/BLIK/BANK_TRANSFER/CASH_ON_DELIVERY/PAYPAL/APPLE_PAY/GOOGLE_PAY/OTHER) dla UI iconography.
|
|
160
|
+
|
|
161
|
+
**Linked storefront-operations bump**: minor `version-sync, no code change` per linked rule (Phase 3 Cluster 2 + Cluster 3 już dodały wszystkie operations w backend SSOT i synced storefront-operations npm).
|
|
162
|
+
|
|
163
|
+
## 9.1.0
|
|
164
|
+
|
|
165
|
+
### Minor Changes
|
|
166
|
+
|
|
167
|
+
- f2ad734: **Version-sync release**: align `@doswiftly/storefront-operations` and `@doswiftly/storefront-sdk` back to the same version (`9.1.0`) as required by their linked package contract.
|
|
168
|
+
|
|
169
|
+
### Why this release
|
|
170
|
+
|
|
171
|
+
A prior release sequence left the two linked packages on different majors (`@doswiftly/storefront-operations@8.0.0` + `@doswiftly/storefront-sdk@9.0.0`). The linked contract guarantees consumers a "matching set of operation names ↔ SDK runtime" — desynced majors break that guarantee and confuse downstream codegen consumers.
|
|
172
|
+
|
|
173
|
+
This release re-aligns both to `9.1.0`. **No API surface change**, no operation rename, no SDK behavior change. Pure version-sync.
|
|
174
|
+
|
|
175
|
+
### Migration
|
|
176
|
+
|
|
177
|
+
None. If you have either package on `^8.x` or `^9.x`, upgrade both to `9.1.0` to stay on a supported linked pair. Subsequent releases ship from this aligned baseline.
|
|
178
|
+
|
|
179
|
+
### Reference
|
|
180
|
+
|
|
181
|
+
Linked semantics in `.changeset/config.json`: changesets calculates `max(versions across linked pair) + bump-type` and applies it to every member. With `operations@8.0.0` and `sdk@9.0.0` already published, `max = 9.0.0`; a minor bump on both yields `9.1.0` for both. Future major releases (real BREAKING changes) jump from this aligned baseline organically.
|
|
182
|
+
|
|
3
183
|
## 9.0.0
|
|
4
184
|
|
|
5
185
|
### Major Changes
|
|
@@ -12,10 +12,10 @@ export interface Customer {
|
|
|
12
12
|
lastName: string | null;
|
|
13
13
|
displayName: string | null;
|
|
14
14
|
phone: string | null;
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
isEmailVerified: boolean;
|
|
16
|
+
emailMarketing: string | null;
|
|
17
17
|
defaultAddress: MailingAddress | null;
|
|
18
|
-
|
|
18
|
+
orderCount: number;
|
|
19
19
|
totalSpent: {
|
|
20
20
|
amount: string;
|
|
21
21
|
currencyCode: string;
|
|
@@ -33,6 +33,8 @@ export interface MailingAddress {
|
|
|
33
33
|
countryCode: string | null;
|
|
34
34
|
firstName: string | null;
|
|
35
35
|
lastName: string | null;
|
|
36
|
+
/** Computed full name (`firstName + " " + lastName`). */
|
|
37
|
+
name: string | null;
|
|
36
38
|
phone: string | null;
|
|
37
39
|
state: string | null;
|
|
38
40
|
stateCode: string | null;
|
|
@@ -49,5 +51,10 @@ export interface CustomerCreateInput {
|
|
|
49
51
|
password: string;
|
|
50
52
|
firstName?: string;
|
|
51
53
|
lastName?: string;
|
|
54
|
+
phone?: string;
|
|
55
|
+
/** Opt-in to email marketing. `true` → SUBSCRIBED (lub PENDING gdy CONFIRMED_OPT_IN). */
|
|
56
|
+
acceptsMarketing?: boolean;
|
|
57
|
+
/** Marketing opt-in level — `'SINGLE_OPT_IN'` (default) lub `'CONFIRMED_OPT_IN'` (double opt-in via email). */
|
|
58
|
+
marketingOptInLevel?: 'SINGLE_OPT_IN' | 'CONFIRMED_OPT_IN';
|
|
52
59
|
}
|
|
53
60
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/core/auth/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,mBAAmB;IAClC,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/core/auth/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,mBAAmB;IAClC,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,eAAe,EAAE,OAAO,CAAC;IACzB,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,cAAc,EAAE,cAAc,GAAG,IAAI,CAAC;IACtC,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IAC5D,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,yDAAyD;IACzD,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,SAAS,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,UAAU;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,yFAAyF;IACzF,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,+GAA+G;IAC/G,mBAAmB,CAAC,EAAE,eAAe,GAAG,kBAAkB,CAAC;CAC5D"}
|
|
@@ -4,18 +4,43 @@
|
|
|
4
4
|
* Wraps StorefrontClient.mutate/query with typed operations.
|
|
5
5
|
* Auto-throws on userErrors via assertNoUserErrors.
|
|
6
6
|
*
|
|
7
|
+
* Each mutation returns `{ cart, warnings }` — `warnings` is non-blocking advisory
|
|
8
|
+
* hints (low stock, partial availability) the storefront UI may render as soft
|
|
9
|
+
* notices. `userErrors` causes the call to throw before returning.
|
|
10
|
+
*
|
|
7
11
|
* @example
|
|
8
12
|
* ```typescript
|
|
9
13
|
* const cartClient = new CartClient(storefrontClient);
|
|
10
14
|
*
|
|
11
|
-
* const cart = await cartClient.create();
|
|
12
|
-
* const updated = await cartClient.
|
|
15
|
+
* const { cart } = await cartClient.create();
|
|
16
|
+
* const { cart: updated, warnings } = await cartClient.addItems(cart.id, [
|
|
13
17
|
* { variantId: 'variant-123', quantity: 1 }
|
|
14
18
|
* ]);
|
|
19
|
+
* for (const w of warnings) {
|
|
20
|
+
* console.warn(`[${w.code}] ${w.message}`);
|
|
21
|
+
* }
|
|
15
22
|
* ```
|
|
16
23
|
*/
|
|
17
24
|
import type { StorefrontClient } from '../client/types';
|
|
18
|
-
import type { Cart, CartCreateInput, CartLineInput, CartLineUpdateInput, CartBuyerIdentityInput } from './types';
|
|
25
|
+
import type { Cart, CartCreateInput, CartLineInput, CartLineUpdateInput, CartBuyerIdentityInput, CartSetShippingAddressInput, CartSetBillingAddressInput, CartSelectShippingMethodInput, CartSelectPaymentMethodInput, CartApplyGiftCardInput, CartRemoveGiftCardInput, CartUpdateGiftCardRecipientInput, CartCompleteInput, CartWarning, Order, DiscountValidationResult } from './types';
|
|
26
|
+
/**
|
|
27
|
+
* Standard mutation return shape — `cart` is non-null on success (userErrors
|
|
28
|
+
* cause assertNoUserErrors to throw), `warnings` may be empty.
|
|
29
|
+
*/
|
|
30
|
+
export interface CartMutationOutcome {
|
|
31
|
+
cart: Cart;
|
|
32
|
+
warnings: CartWarning[];
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* cartComplete result — `order` may be null while backend resolver Phase 4
|
|
36
|
+
* follow-up lands (currently storefront should fallback to `order(id)` query
|
|
37
|
+
* if null). `cart` is the final post-completion state.
|
|
38
|
+
*/
|
|
39
|
+
export interface CartCompleteOutcome {
|
|
40
|
+
cart: Cart;
|
|
41
|
+
order: Order | null;
|
|
42
|
+
warnings: CartWarning[];
|
|
43
|
+
}
|
|
19
44
|
export declare class CartClient {
|
|
20
45
|
private readonly client;
|
|
21
46
|
constructor(client: StorefrontClient);
|
|
@@ -27,31 +52,91 @@ export declare class CartClient {
|
|
|
27
52
|
/**
|
|
28
53
|
* Create a new cart, optionally with initial lines.
|
|
29
54
|
*/
|
|
30
|
-
create(input?: CartCreateInput): Promise<
|
|
55
|
+
create(input?: CartCreateInput): Promise<CartMutationOutcome>;
|
|
31
56
|
/**
|
|
32
57
|
* Add line items to an existing cart.
|
|
33
58
|
*/
|
|
34
|
-
addItems(cartId: string, lines: CartLineInput[]): Promise<
|
|
59
|
+
addItems(cartId: string, lines: CartLineInput[]): Promise<CartMutationOutcome>;
|
|
35
60
|
/**
|
|
36
61
|
* Update line items (quantity, attributes).
|
|
37
62
|
*/
|
|
38
|
-
updateItems(cartId: string, lines: CartLineUpdateInput[]): Promise<
|
|
63
|
+
updateItems(cartId: string, lines: CartLineUpdateInput[]): Promise<CartMutationOutcome>;
|
|
39
64
|
/**
|
|
40
65
|
* Remove line items by their line IDs.
|
|
41
66
|
*/
|
|
42
|
-
removeItems(cartId: string, lineIds: string[]): Promise<
|
|
67
|
+
removeItems(cartId: string, lineIds: string[]): Promise<CartMutationOutcome>;
|
|
43
68
|
/**
|
|
44
69
|
* Update discount codes (replaces all existing codes).
|
|
45
70
|
* Pass empty array to clear discounts.
|
|
46
71
|
*/
|
|
47
|
-
updateDiscountCodes(cartId: string, discountCodes: string[]): Promise<
|
|
72
|
+
updateDiscountCodes(cartId: string, discountCodes: string[]): Promise<CartMutationOutcome>;
|
|
48
73
|
/**
|
|
49
74
|
* Update cart note / gift message.
|
|
50
75
|
*/
|
|
51
|
-
updateNote(cartId: string, note: string): Promise<
|
|
76
|
+
updateNote(cartId: string, note: string): Promise<CartMutationOutcome>;
|
|
77
|
+
/**
|
|
78
|
+
* Update buyer identity (email, phone, country, customer link, languageCode).
|
|
79
|
+
*/
|
|
80
|
+
updateBuyerIdentity(cartId: string, buyerIdentity: CartBuyerIdentityInput): Promise<CartMutationOutcome>;
|
|
81
|
+
/**
|
|
82
|
+
* Set shipping address on the cart. Full replace (not patch). Triggers cart
|
|
83
|
+
* re-pricing (tax recalculation per address country/region).
|
|
84
|
+
*/
|
|
85
|
+
setShippingAddress(input: CartSetShippingAddressInput): Promise<CartMutationOutcome>;
|
|
86
|
+
/**
|
|
87
|
+
* Set billing address on the cart (independent z shipping address — pass
|
|
88
|
+
* even when "billing same as shipping").
|
|
89
|
+
*/
|
|
90
|
+
setBillingAddress(input: CartSetBillingAddressInput): Promise<CartMutationOutcome>;
|
|
91
|
+
/**
|
|
92
|
+
* Select shipping method on the cart (Decision D8 term unification — typed
|
|
93
|
+
* `shippingMethodId` jako ID, NIE String).
|
|
94
|
+
*/
|
|
95
|
+
selectShippingMethod(input: CartSelectShippingMethodInput): Promise<CartMutationOutcome>;
|
|
96
|
+
/**
|
|
97
|
+
* Select payment method on the cart. Validates existence + active status;
|
|
98
|
+
* no pre-authorization.
|
|
99
|
+
*/
|
|
100
|
+
selectPaymentMethod(input: CartSelectPaymentMethodInput): Promise<CartMutationOutcome>;
|
|
101
|
+
/**
|
|
102
|
+
* Apply gift card to cart (stackable z discount codes, FIFO consumption).
|
|
103
|
+
* Balance NOT debited yet — actual deduction at cartComplete.
|
|
104
|
+
*/
|
|
105
|
+
applyGiftCard(input: CartApplyGiftCardInput): Promise<CartMutationOutcome>;
|
|
106
|
+
/**
|
|
107
|
+
* Remove applied gift card from cart. Re-calculates FIFO amounts dla
|
|
108
|
+
* pozostałych cards.
|
|
109
|
+
*/
|
|
110
|
+
removeGiftCard(input: CartRemoveGiftCardInput): Promise<CartMutationOutcome>;
|
|
111
|
+
/**
|
|
112
|
+
* Update gift card recipient info na line item (personalised delivery —
|
|
113
|
+
* recipientEmail, recipientName, message). Required przed cartComplete
|
|
114
|
+
* dla każdego gift card line item.
|
|
115
|
+
*/
|
|
116
|
+
updateGiftCardRecipient(input: CartUpdateGiftCardRecipientInput): Promise<CartMutationOutcome>;
|
|
117
|
+
/**
|
|
118
|
+
* Complete cart → create Order. Returns `{ cart, order, warnings }`.
|
|
119
|
+
* Idempotent on `idempotencyKey` (auto-generated z cartId + minute timestamp
|
|
120
|
+
* jeśli omitted).
|
|
121
|
+
*
|
|
122
|
+
* Order zawiera `canCreatePayment` + `paymentMethodType` (po extend fragment
|
|
123
|
+
* Order w SSOT) — storefront czyta żeby zdecydować payment flow. paymentUrl
|
|
124
|
+
* celowo NIE w response (Decision D4) — storefront inicjuje payment osobnym
|
|
125
|
+
* `paymentCreate` mutation (po sprawdzeniu order.canCreatePayment).
|
|
126
|
+
*
|
|
127
|
+
* Backend resolver może obecnie zwrócić `order: null` (Phase 4 follow-up) —
|
|
128
|
+
* storefront powinien fallback do `order(id, orderNumber)` query.
|
|
129
|
+
*/
|
|
130
|
+
complete(input: CartCompleteInput): Promise<CartCompleteOutcome>;
|
|
52
131
|
/**
|
|
53
|
-
*
|
|
132
|
+
* Validate discount code preview (Decision D3) — read-only Query, NIE
|
|
133
|
+
* mutation. Doesn't modify cart state. Returns `{ isValid, discount?, error? }`
|
|
134
|
+
* — storefront UI używa do inline feedback gdy klient wpisuje kod.
|
|
135
|
+
*
|
|
136
|
+
* Caching: storefront powinien używać `fetchPolicy: 'network-only'` lub
|
|
137
|
+
* cache key z `cart.subtotal` (discount eligibility może zależeć od minimum
|
|
138
|
+
* order amount).
|
|
54
139
|
*/
|
|
55
|
-
|
|
140
|
+
validateDiscountCode(cartId: string, discountCode: string): Promise<DiscountValidationResult>;
|
|
56
141
|
}
|
|
57
142
|
//# sourceMappingURL=cart-client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cart-client.d.ts","sourceRoot":"","sources":["../../../src/core/cart/cart-client.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"cart-client.d.ts","sourceRoot":"","sources":["../../../src/core/cart/cart-client.ts"],"names":[],"mappings":"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"}
|
|
@@ -4,18 +4,25 @@
|
|
|
4
4
|
* Wraps StorefrontClient.mutate/query with typed operations.
|
|
5
5
|
* Auto-throws on userErrors via assertNoUserErrors.
|
|
6
6
|
*
|
|
7
|
+
* Each mutation returns `{ cart, warnings }` — `warnings` is non-blocking advisory
|
|
8
|
+
* hints (low stock, partial availability) the storefront UI may render as soft
|
|
9
|
+
* notices. `userErrors` causes the call to throw before returning.
|
|
10
|
+
*
|
|
7
11
|
* @example
|
|
8
12
|
* ```typescript
|
|
9
13
|
* const cartClient = new CartClient(storefrontClient);
|
|
10
14
|
*
|
|
11
|
-
* const cart = await cartClient.create();
|
|
12
|
-
* const updated = await cartClient.
|
|
15
|
+
* const { cart } = await cartClient.create();
|
|
16
|
+
* const { cart: updated, warnings } = await cartClient.addItems(cart.id, [
|
|
13
17
|
* { variantId: 'variant-123', quantity: 1 }
|
|
14
18
|
* ]);
|
|
19
|
+
* for (const w of warnings) {
|
|
20
|
+
* console.warn(`[${w.code}] ${w.message}`);
|
|
21
|
+
* }
|
|
15
22
|
* ```
|
|
16
23
|
*/
|
|
17
24
|
import { assertNoUserErrors } from '../helpers/assert-no-user-errors';
|
|
18
|
-
import { CART_QUERY, CART_CREATE,
|
|
25
|
+
import { CART_QUERY, CART_CREATE, CART_ADD_LINES, CART_UPDATE_LINES, CART_REMOVE_LINES, CART_DISCOUNT_CODES_UPDATE, CART_UPDATE_NOTE, CART_UPDATE_BUYER_IDENTITY, CART_SET_SHIPPING_ADDRESS, CART_SET_BILLING_ADDRESS, CART_SELECT_SHIPPING_METHOD, CART_SELECT_PAYMENT_METHOD, CART_APPLY_GIFT_CARD, CART_REMOVE_GIFT_CARD, CART_UPDATE_GIFT_CARD_RECIPIENT, CART_COMPLETE, CART_VALIDATE_DISCOUNT_CODE, } from '../operations/cart';
|
|
19
26
|
export class CartClient {
|
|
20
27
|
client;
|
|
21
28
|
constructor(client) {
|
|
@@ -35,55 +42,157 @@ export class CartClient {
|
|
|
35
42
|
async create(input) {
|
|
36
43
|
const data = await this.client.mutate(CART_CREATE, { input: input ?? {} });
|
|
37
44
|
assertNoUserErrors(data.cartCreate);
|
|
38
|
-
return data.cartCreate.cart;
|
|
45
|
+
return { cart: data.cartCreate.cart, warnings: data.cartCreate.warnings ?? [] };
|
|
39
46
|
}
|
|
40
47
|
/**
|
|
41
48
|
* Add line items to an existing cart.
|
|
42
49
|
*/
|
|
43
50
|
async addItems(cartId, lines) {
|
|
44
|
-
const data = await this.client.mutate(
|
|
45
|
-
assertNoUserErrors(data.
|
|
46
|
-
return data.
|
|
51
|
+
const data = await this.client.mutate(CART_ADD_LINES, { id: cartId, lines });
|
|
52
|
+
assertNoUserErrors(data.cartAddLines);
|
|
53
|
+
return { cart: data.cartAddLines.cart, warnings: data.cartAddLines.warnings ?? [] };
|
|
47
54
|
}
|
|
48
55
|
/**
|
|
49
56
|
* Update line items (quantity, attributes).
|
|
50
57
|
*/
|
|
51
58
|
async updateItems(cartId, lines) {
|
|
52
|
-
const data = await this.client.mutate(
|
|
53
|
-
assertNoUserErrors(data.
|
|
54
|
-
return data.
|
|
59
|
+
const data = await this.client.mutate(CART_UPDATE_LINES, { id: cartId, lines });
|
|
60
|
+
assertNoUserErrors(data.cartUpdateLines);
|
|
61
|
+
return { cart: data.cartUpdateLines.cart, warnings: data.cartUpdateLines.warnings ?? [] };
|
|
55
62
|
}
|
|
56
63
|
/**
|
|
57
64
|
* Remove line items by their line IDs.
|
|
58
65
|
*/
|
|
59
66
|
async removeItems(cartId, lineIds) {
|
|
60
|
-
const data = await this.client.mutate(
|
|
61
|
-
assertNoUserErrors(data.
|
|
62
|
-
return data.
|
|
67
|
+
const data = await this.client.mutate(CART_REMOVE_LINES, { id: cartId, lineIds });
|
|
68
|
+
assertNoUserErrors(data.cartRemoveLines);
|
|
69
|
+
return { cart: data.cartRemoveLines.cart, warnings: data.cartRemoveLines.warnings ?? [] };
|
|
63
70
|
}
|
|
64
71
|
/**
|
|
65
72
|
* Update discount codes (replaces all existing codes).
|
|
66
73
|
* Pass empty array to clear discounts.
|
|
67
74
|
*/
|
|
68
75
|
async updateDiscountCodes(cartId, discountCodes) {
|
|
69
|
-
const data = await this.client.mutate(CART_DISCOUNT_CODES_UPDATE, { cartId, discountCodes });
|
|
76
|
+
const data = await this.client.mutate(CART_DISCOUNT_CODES_UPDATE, { id: cartId, discountCodes });
|
|
70
77
|
assertNoUserErrors(data.cartDiscountCodesUpdate);
|
|
71
|
-
return data.cartDiscountCodesUpdate.cart;
|
|
78
|
+
return { cart: data.cartDiscountCodesUpdate.cart, warnings: data.cartDiscountCodesUpdate.warnings ?? [] };
|
|
72
79
|
}
|
|
73
80
|
/**
|
|
74
81
|
* Update cart note / gift message.
|
|
75
82
|
*/
|
|
76
83
|
async updateNote(cartId, note) {
|
|
77
|
-
const data = await this.client.mutate(
|
|
78
|
-
assertNoUserErrors(data.
|
|
79
|
-
return data.
|
|
84
|
+
const data = await this.client.mutate(CART_UPDATE_NOTE, { id: cartId, note });
|
|
85
|
+
assertNoUserErrors(data.cartUpdateNote);
|
|
86
|
+
return { cart: data.cartUpdateNote.cart, warnings: data.cartUpdateNote.warnings ?? [] };
|
|
80
87
|
}
|
|
81
88
|
/**
|
|
82
|
-
* Update buyer identity (email, phone, country, customer link).
|
|
89
|
+
* Update buyer identity (email, phone, country, customer link, languageCode).
|
|
83
90
|
*/
|
|
84
91
|
async updateBuyerIdentity(cartId, buyerIdentity) {
|
|
85
|
-
const data = await this.client.mutate(
|
|
86
|
-
assertNoUserErrors(data.
|
|
87
|
-
return data.
|
|
92
|
+
const data = await this.client.mutate(CART_UPDATE_BUYER_IDENTITY, { id: cartId, buyerIdentity });
|
|
93
|
+
assertNoUserErrors(data.cartUpdateBuyerIdentity);
|
|
94
|
+
return { cart: data.cartUpdateBuyerIdentity.cart, warnings: data.cartUpdateBuyerIdentity.warnings ?? [] };
|
|
95
|
+
}
|
|
96
|
+
// -------------------------------------------------------------------------
|
|
97
|
+
// Phase 3 — Cart completion lifecycle methods
|
|
98
|
+
// -------------------------------------------------------------------------
|
|
99
|
+
/**
|
|
100
|
+
* Set shipping address on the cart. Full replace (not patch). Triggers cart
|
|
101
|
+
* re-pricing (tax recalculation per address country/region).
|
|
102
|
+
*/
|
|
103
|
+
async setShippingAddress(input) {
|
|
104
|
+
const data = await this.client.mutate(CART_SET_SHIPPING_ADDRESS, { input });
|
|
105
|
+
assertNoUserErrors(data.cartSetShippingAddress);
|
|
106
|
+
return { cart: data.cartSetShippingAddress.cart, warnings: data.cartSetShippingAddress.warnings ?? [] };
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Set billing address on the cart (independent z shipping address — pass
|
|
110
|
+
* even when "billing same as shipping").
|
|
111
|
+
*/
|
|
112
|
+
async setBillingAddress(input) {
|
|
113
|
+
const data = await this.client.mutate(CART_SET_BILLING_ADDRESS, { input });
|
|
114
|
+
assertNoUserErrors(data.cartSetBillingAddress);
|
|
115
|
+
return { cart: data.cartSetBillingAddress.cart, warnings: data.cartSetBillingAddress.warnings ?? [] };
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Select shipping method on the cart (Decision D8 term unification — typed
|
|
119
|
+
* `shippingMethodId` jako ID, NIE String).
|
|
120
|
+
*/
|
|
121
|
+
async selectShippingMethod(input) {
|
|
122
|
+
const data = await this.client.mutate(CART_SELECT_SHIPPING_METHOD, { input });
|
|
123
|
+
assertNoUserErrors(data.cartSelectShippingMethod);
|
|
124
|
+
return { cart: data.cartSelectShippingMethod.cart, warnings: data.cartSelectShippingMethod.warnings ?? [] };
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Select payment method on the cart. Validates existence + active status;
|
|
128
|
+
* no pre-authorization.
|
|
129
|
+
*/
|
|
130
|
+
async selectPaymentMethod(input) {
|
|
131
|
+
const data = await this.client.mutate(CART_SELECT_PAYMENT_METHOD, { input });
|
|
132
|
+
assertNoUserErrors(data.cartSelectPaymentMethod);
|
|
133
|
+
return { cart: data.cartSelectPaymentMethod.cart, warnings: data.cartSelectPaymentMethod.warnings ?? [] };
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Apply gift card to cart (stackable z discount codes, FIFO consumption).
|
|
137
|
+
* Balance NOT debited yet — actual deduction at cartComplete.
|
|
138
|
+
*/
|
|
139
|
+
async applyGiftCard(input) {
|
|
140
|
+
const data = await this.client.mutate(CART_APPLY_GIFT_CARD, { input });
|
|
141
|
+
assertNoUserErrors(data.cartApplyGiftCard);
|
|
142
|
+
return { cart: data.cartApplyGiftCard.cart, warnings: data.cartApplyGiftCard.warnings ?? [] };
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Remove applied gift card from cart. Re-calculates FIFO amounts dla
|
|
146
|
+
* pozostałych cards.
|
|
147
|
+
*/
|
|
148
|
+
async removeGiftCard(input) {
|
|
149
|
+
const data = await this.client.mutate(CART_REMOVE_GIFT_CARD, { input });
|
|
150
|
+
assertNoUserErrors(data.cartRemoveGiftCard);
|
|
151
|
+
return { cart: data.cartRemoveGiftCard.cart, warnings: data.cartRemoveGiftCard.warnings ?? [] };
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Update gift card recipient info na line item (personalised delivery —
|
|
155
|
+
* recipientEmail, recipientName, message). Required przed cartComplete
|
|
156
|
+
* dla każdego gift card line item.
|
|
157
|
+
*/
|
|
158
|
+
async updateGiftCardRecipient(input) {
|
|
159
|
+
const data = await this.client.mutate(CART_UPDATE_GIFT_CARD_RECIPIENT, { input });
|
|
160
|
+
assertNoUserErrors(data.cartUpdateGiftCardRecipient);
|
|
161
|
+
return { cart: data.cartUpdateGiftCardRecipient.cart, warnings: data.cartUpdateGiftCardRecipient.warnings ?? [] };
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Complete cart → create Order. Returns `{ cart, order, warnings }`.
|
|
165
|
+
* Idempotent on `idempotencyKey` (auto-generated z cartId + minute timestamp
|
|
166
|
+
* jeśli omitted).
|
|
167
|
+
*
|
|
168
|
+
* Order zawiera `canCreatePayment` + `paymentMethodType` (po extend fragment
|
|
169
|
+
* Order w SSOT) — storefront czyta żeby zdecydować payment flow. paymentUrl
|
|
170
|
+
* celowo NIE w response (Decision D4) — storefront inicjuje payment osobnym
|
|
171
|
+
* `paymentCreate` mutation (po sprawdzeniu order.canCreatePayment).
|
|
172
|
+
*
|
|
173
|
+
* Backend resolver może obecnie zwrócić `order: null` (Phase 4 follow-up) —
|
|
174
|
+
* storefront powinien fallback do `order(id, orderNumber)` query.
|
|
175
|
+
*/
|
|
176
|
+
async complete(input) {
|
|
177
|
+
const data = await this.client.mutate(CART_COMPLETE, { input });
|
|
178
|
+
assertNoUserErrors(data.cartComplete);
|
|
179
|
+
return {
|
|
180
|
+
cart: data.cartComplete.cart,
|
|
181
|
+
order: data.cartComplete.order,
|
|
182
|
+
warnings: data.cartComplete.warnings ?? [],
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Validate discount code preview (Decision D3) — read-only Query, NIE
|
|
187
|
+
* mutation. Doesn't modify cart state. Returns `{ isValid, discount?, error? }`
|
|
188
|
+
* — storefront UI używa do inline feedback gdy klient wpisuje kod.
|
|
189
|
+
*
|
|
190
|
+
* Caching: storefront powinien używać `fetchPolicy: 'network-only'` lub
|
|
191
|
+
* cache key z `cart.subtotal` (discount eligibility może zależeć od minimum
|
|
192
|
+
* order amount).
|
|
193
|
+
*/
|
|
194
|
+
async validateDiscountCode(cartId, discountCode) {
|
|
195
|
+
const data = await this.client.query(CART_VALIDATE_DISCOUNT_CODE, { cartId, discountCode });
|
|
196
|
+
return data.cartValidateDiscountCode;
|
|
88
197
|
}
|
|
89
198
|
}
|