@sixtyninecommerce/client 0.21.1 → 0.22.1
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/README.md +28 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +7 -1
- package/dist/client.js.map +1 -1
- package/dist/commerce/cart.d.ts.map +1 -1
- package/dist/commerce/cart.js +13 -5
- package/dist/commerce/cart.js.map +1 -1
- package/dist/commerce/checkout.d.ts +3 -2
- package/dist/commerce/checkout.d.ts.map +1 -1
- package/dist/commerce/checkout.js +11 -7
- package/dist/commerce/checkout.js.map +1 -1
- package/dist/commerce/index.d.ts +158 -2
- package/dist/commerce/index.d.ts.map +1 -1
- package/dist/commerce/index.js +1 -1
- package/dist/commerce/index.js.map +1 -1
- package/dist/commerce/placement-error.d.ts +6 -0
- package/dist/commerce/placement-error.d.ts.map +1 -0
- package/dist/commerce/placement-error.js +84 -0
- package/dist/commerce/placement-error.js.map +1 -0
- package/dist/commerce/queries.d.ts +16 -11
- package/dist/commerce/queries.d.ts.map +1 -1
- package/dist/commerce/queries.js +83 -19
- package/dist/commerce/queries.js.map +1 -1
- package/dist/commerce/quotes.d.ts.map +1 -1
- package/dist/commerce/quotes.js +27 -12
- package/dist/commerce/quotes.js.map +1 -1
- package/dist/constants.d.ts +1 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +1 -0
- package/dist/constants.js.map +1 -1
- package/dist/content/asset-urls.d.ts +7 -0
- package/dist/content/asset-urls.d.ts.map +1 -0
- package/dist/content/asset-urls.js +96 -0
- package/dist/content/asset-urls.js.map +1 -0
- package/dist/content/collection-pages.d.ts +2 -2
- package/dist/content/collection-pages.d.ts.map +1 -1
- package/dist/content/collection-pages.js +8 -2
- package/dist/content/collection-pages.js.map +1 -1
- package/dist/content/collections.d.ts +2 -2
- package/dist/content/collections.d.ts.map +1 -1
- package/dist/content/collections.js +10 -3
- package/dist/content/collections.js.map +1 -1
- package/dist/content/index.d.ts +26 -2
- package/dist/content/index.d.ts.map +1 -1
- package/dist/content/index.js +4 -4
- package/dist/content/index.js.map +1 -1
- package/dist/content/items.d.ts +2 -2
- package/dist/content/items.d.ts.map +1 -1
- package/dist/content/items.js +18 -4
- package/dist/content/items.js.map +1 -1
- package/dist/content/resolve.d.ts +2 -2
- package/dist/content/resolve.d.ts.map +1 -1
- package/dist/content/resolve.js +8 -2
- package/dist/content/resolve.js.map +1 -1
- package/dist/core/context.d.ts.map +1 -1
- package/dist/core/context.js +1 -0
- package/dist/core/context.js.map +1 -1
- package/dist/core/headers.d.ts.map +1 -1
- package/dist/core/headers.js +4 -0
- package/dist/core/headers.js.map +1 -1
- package/dist/core/http.d.ts.map +1 -1
- package/dist/core/http.js +4 -1
- package/dist/core/http.js.map +1 -1
- package/dist/credit/index.d.ts +4 -2
- package/dist/credit/index.d.ts.map +1 -1
- package/dist/credit/index.js.map +1 -1
- package/dist/errors.d.ts +10 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +7 -1
- package/dist/errors.js.map +1 -1
- package/dist/events/envelope.d.ts +24 -0
- package/dist/events/envelope.d.ts.map +1 -0
- package/dist/events/envelope.js +2 -0
- package/dist/events/envelope.js.map +1 -0
- package/dist/events/index.d.ts +3 -0
- package/dist/events/index.d.ts.map +1 -0
- package/dist/events/index.js +2 -0
- package/dist/events/index.js.map +1 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/order-scope.d.ts +3 -0
- package/dist/order-scope.d.ts.map +1 -0
- package/dist/order-scope.js +6 -0
- package/dist/order-scope.js.map +1 -0
- package/dist/pricing/index.d.ts +3 -1
- package/dist/pricing/index.d.ts.map +1 -1
- package/dist/pricing/index.js +35 -2
- package/dist/pricing/index.js.map +1 -1
- package/dist/pricing/tax-display.d.ts +9 -0
- package/dist/pricing/tax-display.d.ts.map +1 -0
- package/dist/pricing/tax-display.js +81 -0
- package/dist/pricing/tax-display.js.map +1 -0
- package/dist/seo/alternates.d.ts.map +1 -1
- package/dist/seo/alternates.js +3 -1
- package/dist/seo/alternates.js.map +1 -1
- package/dist/seo/locale-tag.d.ts +4 -0
- package/dist/seo/locale-tag.d.ts.map +1 -0
- package/dist/seo/locale-tag.js +10 -0
- package/dist/seo/locale-tag.js.map +1 -0
- package/dist/seo/meta-tags.d.ts.map +1 -1
- package/dist/seo/meta-tags.js +15 -12
- package/dist/seo/meta-tags.js.map +1 -1
- package/dist/seo/types.d.ts +1 -0
- package/dist/seo/types.d.ts.map +1 -1
- package/dist/seo/url-builder.d.ts.map +1 -1
- package/dist/seo/url-builder.js +6 -4
- package/dist/seo/url-builder.js.map +1 -1
- package/dist/types.d.ts +76 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -141,7 +141,7 @@ const data = await client.graphql(`query { activeChannel { id } }`);
|
|
|
141
141
|
| `commerce` | Products, collections, property trees, search, cart, checkout, customer auth |
|
|
142
142
|
| `content` | CMS resolve, content items, assets, forms, content strings, menus |
|
|
143
143
|
| `navigation` | Unified route manifest, route lookup |
|
|
144
|
-
| `pricing` | Price formatting, tier lookup, order validation (pure
|
|
144
|
+
| `pricing` | Price formatting, tier lookup, order validation (pure), resolved tax display mode |
|
|
145
145
|
| `media` | CDN URLs, preset URLs, responsive image data (pure functions) |
|
|
146
146
|
| `currency` | Exchange rates, currency conversion |
|
|
147
147
|
|
|
@@ -270,6 +270,33 @@ if (nextTier) {
|
|
|
270
270
|
}
|
|
271
271
|
```
|
|
272
272
|
|
|
273
|
+
## Tax display (incl./excl. VAT)
|
|
274
|
+
|
|
275
|
+
`pricesIncludeTax` is the channel's **storage** mode — which of `price` / `priceWithTax` the merchant typed in. It is not the answer to "which figure does *this* shopper see". A channel can quote Dutch consumers gross (the law requires it), Dutch B2B buyers net, and US shoppers net (US sales tax varies by state and district, so a tax-inclusive price is simply wrong there).
|
|
276
|
+
|
|
277
|
+
The engine resolves that per request; ask it once and let the display helper follow:
|
|
278
|
+
|
|
279
|
+
```typescript
|
|
280
|
+
// Once per request (SSR) or per session (client) — cheap and cached.
|
|
281
|
+
await client.pricing.getTaxDisplayMode(); // 'gross' | 'net'
|
|
282
|
+
|
|
283
|
+
// Then everywhere you render a price — no mode argument:
|
|
284
|
+
const display = client.pricing.selectDisplayPrice(variant);
|
|
285
|
+
client.pricing.formatPrice(display.amount); // display.isGross tells you which it is
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
| Method | Use |
|
|
289
|
+
|---|---|
|
|
290
|
+
| `getTaxDisplayMode({ refresh? })` | Resolve the mode from the server. Cached per identity; `refresh: true` forces a round-trip |
|
|
291
|
+
| `currentTaxDisplayMode()` | The last resolved mode, synchronously — for render paths |
|
|
292
|
+
| `selectDisplayPrice(variant, mode?)` | Picks `price`/`priceWithTax` (and the matching retail field). Omit `mode` to follow the resolved one; pass one only to override (a side-by-side table, a shopper-driven toggle) |
|
|
293
|
+
| `resolveTaxDisplayMode(policy, inputs)` | Pure preview of the same precedence rule — for a "who sees what" table |
|
|
294
|
+
| `parseTaxDisplayPolicy(activeChannel.customFields)` | Read the channel's policy (`taxDisplayDefault`, `taxDisplayB2b`, `taxExclusiveCountries`) |
|
|
295
|
+
|
|
296
|
+
Precedence, resolved server-side: **shopper's country is on the channel's tax-exclusive list → `net`**; else **B2B account (`activeCustomer.isB2B`) or the `trade` order scope → the channel's B2B setting**; else the channel default; else `pricesIncludeTax`. The country comes from the active order's shipping address, else the signed-in customer's default one — never from the currency or the locale.
|
|
297
|
+
|
|
298
|
+
The mode is re-resolved automatically after a sign-in/out, a `setOrderScope(...)`, and a `setShippingAddress(...)` (moving the cart to a listed country flips the whole cart to net). It never throws: an unreachable or older engine falls back to `pricesIncludeTax ? 'gross' : 'net'`, i.e. the behaviour before this existed.
|
|
299
|
+
|
|
273
300
|
## Product Documents
|
|
274
301
|
|
|
275
302
|
`commerce.getProduct(slug)` and `commerce.getProductById(id)` return a `documents: PublicProductDocument[]` field with downloadable files attached to the product (manuals, spec sheets, data sheets, certificates). The list is **already filtered by the current customer's visibility** before it leaves the server — the storefront just renders what it gets.
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAc,gBAAgB,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAmBvF,wBAAsB,sBAAsB,CAC1C,MAAM,EAAE,sBAAsB,GAC7B,OAAO,CAAC,gBAAgB,CAAC,CAwC3B"}
|
package/dist/client.js
CHANGED
|
@@ -18,7 +18,7 @@ export async function createStorefrontClient(config) {
|
|
|
18
18
|
commerce: createCommerceModule(http, ctx),
|
|
19
19
|
content: createContentModule(http, ctx),
|
|
20
20
|
navigation: createNavigationModule(http),
|
|
21
|
-
pricing: createPricingModule(ctx),
|
|
21
|
+
pricing: createPricingModule(ctx, http),
|
|
22
22
|
media: createMediaModule(ctx),
|
|
23
23
|
currency: createCurrencyModule(http),
|
|
24
24
|
credit: createCreditModule(http),
|
|
@@ -36,6 +36,12 @@ export async function createStorefrontClient(config) {
|
|
|
36
36
|
clearAuthToken() {
|
|
37
37
|
ctx.authToken = null;
|
|
38
38
|
},
|
|
39
|
+
setOrderScope(scope) {
|
|
40
|
+
ctx.orderScope = scope;
|
|
41
|
+
},
|
|
42
|
+
getOrderScope() {
|
|
43
|
+
return ctx.orderScope ?? null;
|
|
44
|
+
},
|
|
39
45
|
graphql(query, variables) {
|
|
40
46
|
return http.graphql(query, variables);
|
|
41
47
|
},
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE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GAAG,CAAC,YAAY,GAAG,IAAI,CAAC;QAC1B,CAAC;QACD,WAAW;YACT,OAAO,GAAG,CAAC,YAAY,CAAC;QAC1B,CAAC;QACD,YAAY,CAAC,KAAa;YACxB,GAAG,CAAC,SAAS,GAAG,KAAK,CAAC;QACxB,CAAC;QACD,cAAc;YACZ,GAAG,CAAC,SAAS,GAAG,IAAI,CAAC;QACvB,CAAC;QACD,aAAa,CAAC,KAAwB;YACpC,GAAG,CAAC,UAAU,GAAG,KAAK,CAAC;QACzB,CAAC;QACD,aAAa;YACX,OAAO,GAAG,CAAC,UAAU,IAAI,IAAI,CAAC;QAChC,CAAC;QACD,OAAO,CAAc,KAAa,EAAE,SAAmC;YACrE,OAAO,IAAI,CAAC,OAAO,CAAI,KAAK,EAAE,SAAS,CAAC,CAAC;QAC3C,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cart.d.ts","sourceRoot":"","sources":["../../src/commerce/cart.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,OAAO,KAAK,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"cart.d.ts","sourceRoot":"","sources":["../../src/commerce/cart.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,OAAO,KAAK,EAAE,KAAK,EAA0B,MAAM,aAAa,CAAC;AAgDjE,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,UAAU;sBAEtB,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC;yBAKlB,MAAM,YAAY,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;0BAS3D,KAAK,CAAC;QAAE,gBAAgB,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC,GAC3D,OAAO,CAAC,KAAK,CAAC;2BAiDY,MAAM,YAAY,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;2BAQzC,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;iBAOjC,OAAO,CAAC,KAAK,CAAC;0BAKL,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;2BAKtB,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;EAOvD"}
|
package/dist/commerce/cart.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { MutationError } from '../errors.js';
|
|
2
|
+
import { insufficientStockLine, toMutationError } from './placement-error.js';
|
|
2
3
|
import { ACTIVE_ORDER, ADD_ITEMS_TO_CART, ADD_TO_CART, ADJUST_ORDER_LINE, APPLY_COUPON, REMOVE_ALL_ORDER_LINES, REMOVE_COUPON, REMOVE_ORDER_LINE, } from './queries.js';
|
|
3
4
|
function unwrapOrderResult(data, operationField) {
|
|
4
5
|
const result = data[operationField];
|
|
@@ -6,7 +7,7 @@ function unwrapOrderResult(data, operationField) {
|
|
|
6
7
|
throw new MutationError('UNKNOWN_ERROR', `No result from ${operationField}`);
|
|
7
8
|
}
|
|
8
9
|
if ('errorCode' in result) {
|
|
9
|
-
throw
|
|
10
|
+
throw toMutationError(result);
|
|
10
11
|
}
|
|
11
12
|
return result;
|
|
12
13
|
}
|
|
@@ -31,12 +32,19 @@ export function createCartMethods(http) {
|
|
|
31
32
|
}
|
|
32
33
|
const firstError = result.errorResults[0];
|
|
33
34
|
if (firstError) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
const lines = result.errorResults.reduce((acc, entry) => {
|
|
36
|
+
const line = entry.errorCode === 'INSUFFICIENT_STOCK_ERROR'
|
|
37
|
+
? insufficientStockLine(entry)
|
|
38
|
+
: undefined;
|
|
39
|
+
if (line)
|
|
40
|
+
acc.push(line);
|
|
41
|
+
return acc;
|
|
42
|
+
}, []);
|
|
43
|
+
throw toMutationError(firstError, {
|
|
44
|
+
...firstError,
|
|
37
45
|
order: result.order,
|
|
38
46
|
errorResults: result.errorResults,
|
|
39
|
-
});
|
|
47
|
+
}, lines);
|
|
40
48
|
}
|
|
41
49
|
return result.order;
|
|
42
50
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cart.js","sourceRoot":"","sources":["../../src/commerce/cart.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,WAAW,EACX,iBAAiB,EACjB,YAAY,EACZ,sBAAsB,EACtB,aAAa,EACb,iBAAiB,GAClB,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"cart.js","sourceRoot":"","sources":["../../src/commerce/cart.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC9E,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,WAAW,EACX,iBAAiB,EACjB,YAAY,EACZ,sBAAsB,EACtB,aAAa,EACb,iBAAiB,GAClB,MAAM,cAAc,CAAC;AA0BtB,SAAS,iBAAiB,CAAC,IAA6B,EAAE,cAAsB;IAC9E,MAAM,MAAM,GAAG,IAAI,CAAC,cAAc,CAA4B,CAAC;IAC/D,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,aAAa,CAAC,eAAe,EAAE,kBAAkB,cAAc,EAAE,CAAC,CAAC;IAC/E,CAAC;IACD,IAAI,WAAW,IAAI,MAAM,EAAE,CAAC;QAC1B,MAAM,eAAe,CAAC,MAAM,CAAC,CAAC;IAChC,CAAC;IACD,OAAO,MAA0B,CAAC;AACpC,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,IAAgB;IAChD,OAAO;QACL,KAAK,CAAC,cAAc;YAClB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,OAAO,CAAgC,YAAY,CAAC,CAAC;YAC7E,OAAO,IAAI,CAAC,WA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,CAAC;QAED,KAAK,CAAC,cAAc,CAAC,MAAc,EAAE,QAAgB;YACnD,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,OAAO,CAA0B,iBAAiB,EAAE;gBAC1E,MAAM;gBACN,QAAQ;aACT,CAAC,CAAC;YACH,OAAO,iBAAiB,CAAC,IAAI,EAAE,iBAAiB,CAAC,CAAC;QACpD,CAAC;QAED,KAAK,CAAC,cAAc,CAAC,MAAc;YACjC,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,OAAO,CAA0B,iBAAiB,EAAE;gBAC1E,MAAM;aACP,CAAC,CAAC;YACH,OAAO,iBAAiB,CAAC,IAAI,EAAE,iBAAiB,CAAC,CAAC;QACpD,CAAC;QAED,KAAK,CAAC,SAAS;YACb,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,OAAO,CAA0B,sBAAsB,CAAC,CAAC;YACjF,OAAO,iBAAiB,CAAC,IAAI,EAAE,qBAAqB,CAAC,CAAC;QACxD,CAAC;QAED,KAAK,CAAC,eAAe,CAAC,IAAY;YAChC,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,OAAO,CAA0B,YAAY,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;YACjF,OAAO,iBAAiB,CAAC,IAAI,EAAE,iBAAiB,CAAC,CAAC;QACpD,CAAC;QAED,KAAK,CAAC,gBAAgB,CAAC,IAAY;YACjC,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,OAAO,CAA8B,aAAa,EAAE;gBAC1E,IAAI;aACL,CAAC,CAAC;YACH,OAAO,IAAI,CAAC,gBAAgB,CAAC;QAC/B,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { HttpClient, RequestOptions } from '../core/http.js';
|
|
2
|
-
import type { ActiveChannelOrderConstraints, AddressInput, CustomerDeliveryTerms, CustomerInput, Order, PaymentInput, PaymentMethod, PickupLocation, PickupLocationSearchInput, ShippingMethod } from '../types.js';
|
|
3
|
-
export declare function createCheckoutMethods(http: HttpClient): {
|
|
2
|
+
import type { ActiveChannelOrderConstraints, AddressInput, CustomerDeliveryTerms, CustomerInput, Order, OrderPaymentIntent, PaymentInput, PaymentMethod, PickupLocation, PickupLocationSearchInput, ShippingMethod, StoreContext } from '../types.js';
|
|
3
|
+
export declare function createCheckoutMethods(http: HttpClient, ctx?: StoreContext): {
|
|
4
4
|
setCustomerForOrder(input: CustomerInput): Promise<Order>;
|
|
5
5
|
setShippingAddress(input: AddressInput): Promise<Order>;
|
|
6
6
|
setBillingAddress(input: AddressInput): Promise<Order>;
|
|
@@ -10,6 +10,7 @@ export declare function createCheckoutMethods(http: HttpClient): {
|
|
|
10
10
|
applyPreferredShippingMethod(): Promise<Order>;
|
|
11
11
|
getEligiblePaymentMethods(): Promise<PaymentMethod[]>;
|
|
12
12
|
getOrderConstraints(): Promise<ActiveChannelOrderConstraints>;
|
|
13
|
+
setPaymentIntent(intent: OrderPaymentIntent): Promise<Order>;
|
|
13
14
|
transitionToArrangingPayment(): Promise<Order>;
|
|
14
15
|
addPayment(input: PaymentInput): Promise<Order>;
|
|
15
16
|
findPickupLocations(input: PickupLocationSearchInput): Promise<PickupLocation[]>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkout.d.ts","sourceRoot":"","sources":["../../src/commerce/checkout.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAElE,OAAO,KAAK,EACV,6BAA6B,EAC7B,YAAY,EACZ,qBAAqB,EACrB,aAAa,EACb,KAAK,EACL,YAAY,EACZ,aAAa,EACb,cAAc,EACd,yBAAyB,EACzB,cAAc,
|
|
1
|
+
{"version":3,"file":"checkout.d.ts","sourceRoot":"","sources":["../../src/commerce/checkout.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAElE,OAAO,KAAK,EACV,6BAA6B,EAC7B,YAAY,EACZ,qBAAqB,EACrB,aAAa,EACb,KAAK,EACL,kBAAkB,EAClB,YAAY,EACZ,aAAa,EACb,cAAc,EACd,yBAAyB,EACzB,cAAc,EACd,YAAY,EACb,MAAM,aAAa,CAAC;AAkDrB,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,UAAU,EAAE,GAAG,CAAC,EAAE,YAAY;+BAErC,aAAa,GAAG,OAAO,CAAC,KAAK,CAAC;8BAe/B,YAAY,GAAG,OAAO,CAAC,KAAK,CAAC;6BAU9B,YAAY,GAAG,OAAO,CAAC,KAAK,CAAC;kCAOxB,OAAO,CAAC,cAAc,EAAE,CAAC;+BAO5B,cAAc,GAAG,OAAO,CAAC,qBAAqB,GAAG,IAAI,CAAC;2BAS1D,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,CAAC;oCAOhB,OAAO,CAAC,KAAK,CAAC;iCAKjB,OAAO,CAAC,aAAa,EAAE,CAAC;2BAY9B,OAAO,CAAC,6BAA6B,CAAC;6BAyCpC,kBAAkB,GAAG,OAAO,CAAC,KAAK,CAAC;oCAK5B,OAAO,CAAC,KAAK,CAAC;sBAK5B,YAAY,GAAG,OAAO,CAAC,KAAK,CAAC;+BAYpB,yBAAyB,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;mCAiBjD,cAAc,GAAG,OAAO,CAAC,KAAK,CAAC;+BAYnC,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC;EAOlE"}
|
|
@@ -1,21 +1,18 @@
|
|
|
1
1
|
import { MutationError } from '../errors.js';
|
|
2
2
|
import { normalizePickupLocationInput, parseOptionalPickupLocation, parsePickupLocations, } from './pickup-location-parser.js';
|
|
3
|
-
import {
|
|
3
|
+
import { toMutationError } from './placement-error.js';
|
|
4
|
+
import { ACTIVE_CHANNEL_ORDER_CONSTRAINTS, ACTIVE_ORDER_PICKUP_LOCATION, ADD_PAYMENT, APPLY_PREFERRED_SHIPPING_METHOD, ELIGIBLE_PAYMENT_METHODS, ELIGIBLE_SHIPPING_METHODS, MY_DELIVERY_TERMS, PICKUP_LOCATIONS, SET_ACTIVE_ORDER_PICKUP_LOCATION, SET_BILLING_ADDRESS, SET_CUSTOMER, SET_PAYMENT_INTENT, SET_SHIPPING_ADDRESS, SET_SHIPPING_METHOD, TRANSITION_TO_ARRANGING_PAYMENT, } from './queries.js';
|
|
4
5
|
function unwrapResult(data, field) {
|
|
5
6
|
const result = data[field];
|
|
6
7
|
if (!result) {
|
|
7
8
|
throw new MutationError('UNKNOWN_ERROR', `No result from ${field}`);
|
|
8
9
|
}
|
|
9
10
|
if ('errorCode' in result) {
|
|
10
|
-
|
|
11
|
-
? result.transitionError
|
|
12
|
-
: null;
|
|
13
|
-
const message = transitionError ?? result.message;
|
|
14
|
-
throw new MutationError(result.errorCode, message, result);
|
|
11
|
+
throw toMutationError(result);
|
|
15
12
|
}
|
|
16
13
|
return result;
|
|
17
14
|
}
|
|
18
|
-
export function createCheckoutMethods(http) {
|
|
15
|
+
export function createCheckoutMethods(http, ctx) {
|
|
19
16
|
return {
|
|
20
17
|
async setCustomerForOrder(input) {
|
|
21
18
|
const data = await http.graphql(SET_CUSTOMER, { input });
|
|
@@ -25,6 +22,9 @@ export function createCheckoutMethods(http) {
|
|
|
25
22
|
const data = await http.graphql(SET_SHIPPING_ADDRESS, {
|
|
26
23
|
input,
|
|
27
24
|
});
|
|
25
|
+
if (ctx) {
|
|
26
|
+
ctx.taxDisplay = null;
|
|
27
|
+
}
|
|
28
28
|
return unwrapResult(data, 'setOrderShippingAddress');
|
|
29
29
|
},
|
|
30
30
|
async setBillingAddress(input) {
|
|
@@ -59,6 +59,10 @@ export function createCheckoutMethods(http) {
|
|
|
59
59
|
const data = await http.graphql(ACTIVE_CHANNEL_ORDER_CONSTRAINTS);
|
|
60
60
|
return data.activeChannelOrderConstraints;
|
|
61
61
|
},
|
|
62
|
+
async setPaymentIntent(intent) {
|
|
63
|
+
const data = await http.graphql(SET_PAYMENT_INTENT, { intent });
|
|
64
|
+
return unwrapResult(data, 'setOrderPaymentIntent');
|
|
65
|
+
},
|
|
62
66
|
async transitionToArrangingPayment() {
|
|
63
67
|
const data = await http.graphql(TRANSITION_TO_ARRANGING_PAYMENT);
|
|
64
68
|
return unwrapResult(data, 'transitionOrderToState');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkout.js","sourceRoot":"","sources":["../../src/commerce/checkout.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"checkout.js","sourceRoot":"","sources":["../../src/commerce/checkout.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAe7C,OAAO,EACL,4BAA4B,EAC5B,2BAA2B,EAC3B,oBAAoB,GACrB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EACL,gCAAgC,EAChC,4BAA4B,EAC5B,WAAW,EACX,+BAA+B,EAC/B,wBAAwB,EACxB,yBAAyB,EACzB,iBAAiB,EACjB,gBAAgB,EAChB,gCAAgC,EAChC,mBAAmB,EACnB,YAAY,EACZ,kBAAkB,EAClB,oBAAoB,EACpB,mBAAmB,EACnB,+BAA+B,GAChC,MAAM,cAAc,CAAC;AAgBtB,SAAS,YAAY,CAAC,IAA6B,EAAE,KAAa;IAChE,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAA4B,CAAC;IACtD,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,aAAa,CAAC,eAAe,EAAE,kBAAkB,KAAK,EAAE,CAAC,CAAC;IACtE,CAAC;IACD,IAAI,WAAW,IAAI,MAAM,EAAE,CAAC;QAC1B,MAAM,eAAe,CAAC,MAAM,CAAC,CAAC;IAChC,CAAC;IACD,OAAO,MAA0B,CAAC;AACpC,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,IA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aACN,CAAC,CAAC;YACH,OAAO,oBAAoB,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QACpD,CAAC;QAYD,KAAK,CAAC,oBAAoB,CAAC,QAAwB;YACjD,MAAM,UAAU,GAAG,4BAA4B,CAAC,QAAQ,CAAC,CAAC;YAC1D,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,OAAO,CAA0B,gCAAgC,EAAE;gBACzF,QAAQ,EAAE,UAAU;aACrB,CAAC,CAAC;YACH,OAAO,YAAY,CAAC,IAAI,EAAE,8BAA8B,CAAC,CAAC;QAC5D,CAAC;QAMD,KAAK,CAAC,uBAAuB;YAC3B,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,OAAO,CAC7B,4BAA4B,CAC7B,CAAC;YACF,OAAO,2BAA2B,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC;QACrE,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/commerce/index.d.ts
CHANGED
|
@@ -1,4 +1,160 @@
|
|
|
1
1
|
import type { HttpClient } from '../core/http.js';
|
|
2
|
-
import type {
|
|
3
|
-
export declare function createCommerceModule(http: HttpClient, ctx: StoreContext):
|
|
2
|
+
import type { StoreContext } from '../types.js';
|
|
3
|
+
export declare function createCommerceModule(http: HttpClient, ctx: StoreContext): {
|
|
4
|
+
getBranding(options?: import("../types.js").RequestOptions): Promise<import("../types.js").BrandingInfo>;
|
|
5
|
+
subscribeToStockNotification(productVariantId: string, emailAddress?: string): Promise<import("../types.js").StockNotificationSubscriptionResult>;
|
|
6
|
+
unsubscribeFromStockNotification(token: string): Promise<boolean>;
|
|
7
|
+
getDropOffPoints(input: import("../types.js").DropOffPointInput): Promise<import("../types.js").DropOffPoint[]>;
|
|
8
|
+
getDeliveryOptions(input: import("../types.js").DeliveryOptionsInput): Promise<import("../types.js").DeliveryOption[]>;
|
|
9
|
+
trackShipment(barcode: string, postalCode: string): Promise<import("../types.js").ShipmentTrackingInfo | null>;
|
|
10
|
+
getMyVatValidationStatus(): Promise<import("../types.js").VatValidationResult | null>;
|
|
11
|
+
setMyVatNumber(vatNumber: string): Promise<import("../types.js").VatValidationResult>;
|
|
12
|
+
clearMyVatNumber(): Promise<boolean>;
|
|
13
|
+
getMyReturns(options?: import("../types.js").CustomerReturnListOptions): Promise<import("../types.js").CustomerReturnList>;
|
|
14
|
+
getMyReturn(id: string): Promise<import("../types.js").CustomerReturn | null>;
|
|
15
|
+
requestReturn(input: import("../types.js").RequestReturnInput): Promise<import("../types.js").CustomerReturn>;
|
|
16
|
+
cancelMyReturn(id: string): Promise<import("../types.js").CustomerReturn>;
|
|
17
|
+
getReturnableLinesForOrder(orderId: string): Promise<import("../types.js").CustomerReturnEligibility>;
|
|
18
|
+
getMyQuotes(options?: import("../types.js").QuoteListOptions): Promise<import("../types.js").QuoteList>;
|
|
19
|
+
getMyQuote(id: string): Promise<import("../types.js").Quote | null>;
|
|
20
|
+
createQuoteRequest(input: import("../types.js").CreateQuoteRequestInput): Promise<import("../types.js").Quote>;
|
|
21
|
+
acceptQuote(id: string): Promise<import("../types.js").Order>;
|
|
22
|
+
cancelMyQuote(id: string, reason?: string): Promise<import("../types.js").Quote>;
|
|
23
|
+
getMySubscriptions(): Promise<import("../types.js").CustomerSubscription[]>;
|
|
24
|
+
getSubscriptionPlans(): Promise<import("../types.js").SubscriptionPlanPublic[]>;
|
|
25
|
+
getMyPaymentMandates(): Promise<import("../types.js").MyPaymentMandate[]>;
|
|
26
|
+
setupPaymentMandate(input: {
|
|
27
|
+
provider: string;
|
|
28
|
+
redirectUrl: string;
|
|
29
|
+
}): Promise<import("../types.js").SetupPaymentMandateResult>;
|
|
30
|
+
createSubscription(planId: string, mandateId: string): Promise<import("../types.js").CustomerSubscription>;
|
|
31
|
+
pauseMySubscription(id: string, reason?: string): Promise<import("../types.js").CustomerSubscription>;
|
|
32
|
+
resumeMySubscription(id: string): Promise<import("../types.js").CustomerSubscription>;
|
|
33
|
+
cancelMySubscription(id: string, options?: {
|
|
34
|
+
reason?: string;
|
|
35
|
+
immediate?: boolean;
|
|
36
|
+
}): Promise<import("../types.js").CustomerSubscription>;
|
|
37
|
+
getAgeVerificationStatus(): Promise<import("../types.js").AgeVerificationStatus>;
|
|
38
|
+
submitDateOfBirth(dateOfBirth: string): Promise<import("../types.js").AgeVerificationStatus>;
|
|
39
|
+
confirmAge(): Promise<import("../types.js").AgeVerificationStatus>;
|
|
40
|
+
getProductReviews(productId: string, options?: import("../types.js").ReviewListOptions): Promise<{
|
|
41
|
+
items: import("../types.js").ProductReview[];
|
|
42
|
+
totalItems: number;
|
|
43
|
+
nextCursor: string | null;
|
|
44
|
+
}>;
|
|
45
|
+
getRecentProductReviews(options?: import("../types.js").RecentReviewsOptions): Promise<import("../types.js").ProductReview[]>;
|
|
46
|
+
getReviewRatingSummary(productId: string): Promise<import("../types.js").ReviewRatingSummary>;
|
|
47
|
+
getReviewAttributeAggregations(productId: string): Promise<import("../types.js").ReviewAttributeAggregation[]>;
|
|
48
|
+
getReviewAttributes(productId?: string): Promise<import("../types.js").ReviewAttribute[]>;
|
|
49
|
+
getMyReview(productId: string): Promise<import("../types.js").ProductReview | null>;
|
|
50
|
+
getReviewChannelConfig(): Promise<import("../types.js").ReviewChannelConfig>;
|
|
51
|
+
createReview(input: import("../types.js").CreateReviewInput): Promise<import("../types.js").CreateReviewResult>;
|
|
52
|
+
updateReview(id: string, input: import("../types.js").UpdateReviewInput): Promise<import("../types.js").ProductReview>;
|
|
53
|
+
deleteReview(id: string): Promise<boolean>;
|
|
54
|
+
voteReview(reviewId: string, isHelpful: boolean): Promise<boolean>;
|
|
55
|
+
reportReview(reviewId: string, reason: string): Promise<boolean>;
|
|
56
|
+
uploadReviewMedia(files: File[]): Promise<import("../types.js").ReviewMediaUploadResult[]>;
|
|
57
|
+
getProductRecommendations(productId: string, groupSlug?: string): Promise<import("../types.js").RecommendedProductGroup[]>;
|
|
58
|
+
getMySavedLists(): Promise<import("../types.js").SavedList[]>;
|
|
59
|
+
getMySavedList(id: string): Promise<import("../types.js").SavedList | null>;
|
|
60
|
+
createSavedList(name: string): Promise<import("../types.js").SavedList>;
|
|
61
|
+
renameSavedList(id: string, name: string): Promise<import("../types.js").SavedList>;
|
|
62
|
+
deleteSavedList(id: string): Promise<boolean>;
|
|
63
|
+
addItemToSavedList(listId: string, variantId: string, quantity: number): Promise<import("../types.js").SavedList>;
|
|
64
|
+
updateSavedListItem(listId: string, variantId: string, quantity: number): Promise<import("../types.js").SavedList>;
|
|
65
|
+
removeItemFromSavedList(listId: string, variantId: string): Promise<import("../types.js").SavedList>;
|
|
66
|
+
getFavoriteVariantIds(): Promise<string[]>;
|
|
67
|
+
getMyFavorites(options?: {
|
|
68
|
+
take?: number;
|
|
69
|
+
skip?: number;
|
|
70
|
+
}): Promise<import("../types.js").PaginatedList<import("../types.js").FavoriteItem>>;
|
|
71
|
+
toggleFavorite(productVariantId: string): Promise<boolean>;
|
|
72
|
+
removeFavorite(productVariantId: string): Promise<boolean>;
|
|
73
|
+
login(email: string, password: string): Promise<import("../types.js").LoginResult>;
|
|
74
|
+
register(input: import("../types.js").RegisterInput): Promise<{
|
|
75
|
+
success: boolean;
|
|
76
|
+
}>;
|
|
77
|
+
logout(): Promise<void>;
|
|
78
|
+
verifyAccount(token: string, password?: string): Promise<{
|
|
79
|
+
id: string;
|
|
80
|
+
identifier: string;
|
|
81
|
+
}>;
|
|
82
|
+
refreshVerification(emailAddress: string): Promise<void>;
|
|
83
|
+
requestMagicLink(emailAddress: string): Promise<void>;
|
|
84
|
+
loginWithMagicLink(token: string): Promise<{
|
|
85
|
+
id: string;
|
|
86
|
+
identifier: string;
|
|
87
|
+
}>;
|
|
88
|
+
loginWithMagicCode(emailAddress: string, code: string): Promise<{
|
|
89
|
+
id: string;
|
|
90
|
+
identifier: string;
|
|
91
|
+
}>;
|
|
92
|
+
updatePassword(currentPassword: string, newPassword: string): Promise<void>;
|
|
93
|
+
requestPasswordReset(emailAddress: string): Promise<void>;
|
|
94
|
+
resetPassword(token: string, password: string): Promise<{
|
|
95
|
+
id: string;
|
|
96
|
+
identifier: string;
|
|
97
|
+
}>;
|
|
98
|
+
requestEmailUpdate(password: string, newEmailAddress: string): Promise<void>;
|
|
99
|
+
updateEmail(token: string): Promise<void>;
|
|
100
|
+
getCurrentCustomer(): Promise<import("../types.js").Customer | null>;
|
|
101
|
+
getActiveCustomerPriceLists(options?: import("../core/http.js").RequestOptions): Promise<import("../types.js").CustomerPriceList[]>;
|
|
102
|
+
updateCustomer(input: import("../types.js").UpdateCustomerInput): Promise<import("../types.js").Customer>;
|
|
103
|
+
getCustomerOrders(options?: import("../types.js").OrderListOptions): Promise<import("../types.js").PaginatedList<import("../types.js").OrderSummary>>;
|
|
104
|
+
createAddress(input: import("../types.js").AddressInput): Promise<import("../types.js").CustomerAddress>;
|
|
105
|
+
updateAddress(input: import("../types.js").UpdateAddressInput): Promise<import("../types.js").CustomerAddress>;
|
|
106
|
+
deleteAddress(id: string): Promise<void>;
|
|
107
|
+
getAvailableCountries(): Promise<import("../types.js").Country[]>;
|
|
108
|
+
getOrderByCode(code: string): Promise<import("../types.js").Order>;
|
|
109
|
+
getMyOrderInvoices(orderCode: string): Promise<import("../types.js").CustomerInvoice[]>;
|
|
110
|
+
getMyInvoicePdf(invoiceId: string): Promise<import("../types.js").CustomerInvoicePdf>;
|
|
111
|
+
reorder(orderCode: string): Promise<{
|
|
112
|
+
order: import("../types.js").Order;
|
|
113
|
+
addedLines: number;
|
|
114
|
+
skipped: import("../types.js").ReorderSkipped[];
|
|
115
|
+
}>;
|
|
116
|
+
getActiveChannel(): Promise<import("../types.js").ActiveChannel>;
|
|
117
|
+
createStripePaymentIntent(options?: import("../types.js").RequestOptions): Promise<import("../types.js").StripePaymentIntentResult>;
|
|
118
|
+
getMolliePaymentMethods(input: import("../types.js").MolliePaymentMethodsInput, options?: import("../types.js").RequestOptions): Promise<import("../types.js").MolliePaymentMethod[]>;
|
|
119
|
+
getOrderedMolliePaymentMethods(paymentMethodCode: string, options?: import("../types.js").RequestOptions): Promise<import("../types.js").OrderedMollieMethod[]>;
|
|
120
|
+
createMolliePaymentIntent(input: import("../types.js").CreateMolliePaymentIntentInput, options?: import("../types.js").RequestOptions): Promise<import("../types.js").MolliePaymentIntentResult>;
|
|
121
|
+
syncMolliePaymentStatus(orderCode: string, options?: import("../types.js").RequestOptions): Promise<import("../types.js").MollieOrderStatusResult | null>;
|
|
122
|
+
setCustomerForOrder(input: import("../types.js").CustomerInput): Promise<import("../types.js").Order>;
|
|
123
|
+
setShippingAddress(input: import("../types.js").AddressInput): Promise<import("../types.js").Order>;
|
|
124
|
+
setBillingAddress(input: import("../types.js").AddressInput): Promise<import("../types.js").Order>;
|
|
125
|
+
getEligibleShippingMethods(): Promise<import("../types.js").ShippingMethod[]>;
|
|
126
|
+
getDeliveryTerms(options?: import("../core/http.js").RequestOptions): Promise<import("../types.js").CustomerDeliveryTerms | null>;
|
|
127
|
+
setShippingMethod(ids: string[]): Promise<import("../types.js").Order>;
|
|
128
|
+
applyPreferredShippingMethod(): Promise<import("../types.js").Order>;
|
|
129
|
+
getEligiblePaymentMethods(): Promise<import("../types.js").PaymentMethod[]>;
|
|
130
|
+
getOrderConstraints(): Promise<import("../types.js").ActiveChannelOrderConstraints>;
|
|
131
|
+
setPaymentIntent(intent: import("../types.js").OrderPaymentIntent): Promise<import("../types.js").Order>;
|
|
132
|
+
transitionToArrangingPayment(): Promise<import("../types.js").Order>;
|
|
133
|
+
addPayment(input: import("../types.js").PaymentInput): Promise<import("../types.js").Order>;
|
|
134
|
+
findPickupLocations(input: import("../types.js").PickupLocationSearchInput): Promise<import("../types.js").PickupLocation[]>;
|
|
135
|
+
selectPickupLocation(location: import("../types.js").PickupLocation): Promise<import("../types.js").Order>;
|
|
136
|
+
getActivePickupLocation(): Promise<import("../types.js").PickupLocation | null>;
|
|
137
|
+
getActiveOrder(): Promise<import("../types.js").Order | null>;
|
|
138
|
+
addToCart(variantId: string, quantity: number): Promise<import("../types.js").Order>;
|
|
139
|
+
addItemsToCart(items: Array<{
|
|
140
|
+
productVariantId: string;
|
|
141
|
+
quantity: number;
|
|
142
|
+
}>): Promise<import("../types.js").Order>;
|
|
143
|
+
updateCartLine(lineId: string, quantity: number): Promise<import("../types.js").Order>;
|
|
144
|
+
removeFromCart(lineId: string): Promise<import("../types.js").Order>;
|
|
145
|
+
clearCart(): Promise<import("../types.js").Order>;
|
|
146
|
+
applyCouponCode(code: string): Promise<import("../types.js").Order>;
|
|
147
|
+
removeCouponCode(code: string): Promise<import("../types.js").Order>;
|
|
148
|
+
searchProducts(input: import("../types.js").SearchInput, options?: import("../types.js").RequestOptions): Promise<import("../types.js").SearchResult>;
|
|
149
|
+
getProduct(slug: string, options?: import("../types.js").RequestOptions): Promise<import("../types.js").Product>;
|
|
150
|
+
getProductById(id: string, options?: import("../types.js").RequestOptions): Promise<import("../types.js").Product>;
|
|
151
|
+
getProducts(listOptions?: import("../types.js").ProductListOptions, options?: import("../types.js").RequestOptions): Promise<import("../types.js").PaginatedList<import("../types.js").ProductSummary>>;
|
|
152
|
+
getProductsInCollection(collectionSlug: string, listOptions?: import("../types.js").CollectionProductListOptions, options?: import("../types.js").RequestOptions): Promise<import("../types.js").PaginatedList<import("../types.js").CollectionProductSummary>>;
|
|
153
|
+
getFacets(options?: import("../types.js").RequestOptions): Promise<import("../types.js").Facet[]>;
|
|
154
|
+
getCollections(listOptions?: import("../types.js").CollectionListOptions, options?: import("../types.js").RequestOptions): Promise<import("../types.js").Collection[]>;
|
|
155
|
+
getCollection(slug: string, options?: import("../types.js").RequestOptions): Promise<import("../types.js").CollectionDetail>;
|
|
156
|
+
getPropertyGroups(options?: import("../types.js").RequestOptions): Promise<import("../types.js").PropertyGroup[]>;
|
|
157
|
+
getProductProperties(productId: string, options?: import("../types.js").RequestOptions): Promise<import("../types.js").ProductPropertyGroupValues[]>;
|
|
158
|
+
mapProductProperties: typeof import("./products.js").mapProductProperties;
|
|
159
|
+
};
|
|
4
160
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/commerce/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/commerce/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAkB,YAAY,EAAE,MAAM,aAAa,CAAC;AAoBhE,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,UAAU,EAAE,GAAG,EAAE,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAyC07C,CAAC;iBAAmB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YArDp+C,CAAC;YAClC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmDlB"}
|
package/dist/commerce/index.js
CHANGED
|
@@ -20,7 +20,7 @@ export function createCommerceModule(http, ctx) {
|
|
|
20
20
|
const products = createProductMethods(http);
|
|
21
21
|
const search = createSearchMethods(http);
|
|
22
22
|
const cart = createCartMethods(http);
|
|
23
|
-
const checkout = createCheckoutMethods(http);
|
|
23
|
+
const checkout = createCheckoutMethods(http, ctx);
|
|
24
24
|
const payments = createPaymentMethods(http);
|
|
25
25
|
const customer = createCustomerMethods(http, ctx);
|
|
26
26
|
const favorites = createFavoritesMethods(http);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/commerce/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,4BAA4B,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACt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'../types.js';
|
|
3
|
+
export declare function readPlacement(result: Record<string, unknown>): PlacementRejection | undefined;
|
|
4
|
+
export declare function insufficientStockLine(result: Record<string, unknown>): PlacementRejectionLine | undefined;
|
|
5
|
+
export declare function toMutationError(result: Record<string, unknown>, fields?: Record<string, unknown>, linesOverride?: PlacementRejectionLine[]): MutationError;
|
|
6
|
+
//# sourceMappingURL=placement-error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"placement-error.d.ts","sourceRoot":"","sources":["../../src/commerce/placement-error.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,KAAK,EACV,kBAAkB,EAElB,sBAAsB,EACvB,MAAM,aAAa,CAAC;AAgFrB,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,kBAAkB,GAAG,SAAS,CAiB7F;AAQD,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC9B,sBAAsB,GAAG,SAAS,CAEpC;AAmBD,wBAAgB,eAAe,CAC7B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAU,EACxC,aAAa,CAAC,EAAE,sBAAsB,EAAE,GACvC,aAAa,CA+Bf"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { MutationError } from '../errors.js';
|
|
2
|
+
const REASON_FIELDS = ['transitionError', 'interceptorError'];
|
|
3
|
+
function nonEmpty(value) {
|
|
4
|
+
return typeof value === 'string' && value.trim().length > 0 ? value : undefined;
|
|
5
|
+
}
|
|
6
|
+
function readId(value) {
|
|
7
|
+
if (typeof value === 'string' && value.length > 0)
|
|
8
|
+
return value;
|
|
9
|
+
if (typeof value === 'number')
|
|
10
|
+
return String(value);
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
function readInt(value) {
|
|
14
|
+
return typeof value === 'number' ? value : undefined;
|
|
15
|
+
}
|
|
16
|
+
function readLine(raw) {
|
|
17
|
+
const productVariantId = readId(raw.productVariantId);
|
|
18
|
+
if (!productVariantId)
|
|
19
|
+
return undefined;
|
|
20
|
+
return {
|
|
21
|
+
productVariantId,
|
|
22
|
+
orderLineId: readId(raw.orderLineId),
|
|
23
|
+
sku: nonEmpty(raw.sku),
|
|
24
|
+
productName: nonEmpty(raw.productName),
|
|
25
|
+
productVariantName: nonEmpty(raw.productVariantName),
|
|
26
|
+
quantityRequested: readInt(raw.quantityRequested),
|
|
27
|
+
quantityAvailable: readInt(raw.quantityAvailable),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function readLines(raw) {
|
|
31
|
+
const lines = [];
|
|
32
|
+
for (const entry of raw) {
|
|
33
|
+
if (!entry || typeof entry !== 'object')
|
|
34
|
+
continue;
|
|
35
|
+
const line = readLine(entry);
|
|
36
|
+
if (line)
|
|
37
|
+
lines.push(line);
|
|
38
|
+
}
|
|
39
|
+
return lines;
|
|
40
|
+
}
|
|
41
|
+
export function readPlacement(result) {
|
|
42
|
+
const raw = result.placement;
|
|
43
|
+
if (!raw || typeof raw !== 'object')
|
|
44
|
+
return undefined;
|
|
45
|
+
const payload = raw;
|
|
46
|
+
const code = nonEmpty(payload.code);
|
|
47
|
+
if (!code)
|
|
48
|
+
return undefined;
|
|
49
|
+
const placement = {
|
|
50
|
+
...payload,
|
|
51
|
+
code,
|
|
52
|
+
linesTruncated: payload.linesTruncated === true,
|
|
53
|
+
};
|
|
54
|
+
if (Array.isArray(payload.lines))
|
|
55
|
+
placement.lines = readLines(payload.lines);
|
|
56
|
+
return placement;
|
|
57
|
+
}
|
|
58
|
+
export function insufficientStockLine(result) {
|
|
59
|
+
return readLine(result);
|
|
60
|
+
}
|
|
61
|
+
export function toMutationError(result, fields = result, linesOverride) {
|
|
62
|
+
const errorCode = nonEmpty(result.errorCode) ?? 'UNKNOWN_ERROR';
|
|
63
|
+
const placement = readPlacement(result);
|
|
64
|
+
const stockLine = errorCode === 'INSUFFICIENT_STOCK_ERROR' ? insufficientStockLine(result) : undefined;
|
|
65
|
+
const placementLines = placement?.lines?.length ? placement.lines : undefined;
|
|
66
|
+
const lines = linesOverride?.length
|
|
67
|
+
? linesOverride
|
|
68
|
+
: (placementLines ?? (stockLine ? [stockLine] : undefined));
|
|
69
|
+
const code = placement?.code ??
|
|
70
|
+
(errorCode === 'INSUFFICIENT_STOCK_ERROR'
|
|
71
|
+
? 'INSUFFICIENT_STOCK'
|
|
72
|
+
: undefined);
|
|
73
|
+
let reason;
|
|
74
|
+
for (const field of REASON_FIELDS) {
|
|
75
|
+
reason ??= nonEmpty(result[field]);
|
|
76
|
+
}
|
|
77
|
+
const message = nonEmpty(placement?.customerMessage) ?? reason ?? nonEmpty(result.message);
|
|
78
|
+
return new MutationError(errorCode, message ?? errorCode, fields, {
|
|
79
|
+
code,
|
|
80
|
+
placement,
|
|
81
|
+
lines,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=placement-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"placement-error.js","sourceRoot":"","sources":["../../src/commerce/placement-error.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AA4B7C,MAAM,aAAa,GAAG,CAAC,iBAAiB,EAAE,kBAAkB,CAAU,CAAC;AAEvE,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AAClF,CAAC;AAGD,SAAS,MAAM,CAAC,KAAc;IAC5B,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,GAAG,CAA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