@zappie/sdk 0.28.2 → 0.29.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/CHANGELOG.md +18 -0
- package/dist/account/index.d.ts +16 -2
- package/dist/account/index.js +0 -1
- package/dist/account/url.js +0 -1
- package/dist/branches/index.d.ts +2 -0
- package/dist/branches/index.js +0 -1
- package/dist/cart/branch.d.ts +18 -0
- package/dist/cart/branch.js +0 -1
- package/dist/cart/errors.js +0 -1
- package/dist/cart/held.js +0 -1
- package/dist/cart/index.js +1 -2
- package/dist/cart/item.d.ts +1 -1
- package/dist/cart/item.js +0 -1
- package/dist/cart/preview.js +0 -1
- package/dist/cart/price.js +0 -1
- package/dist/cart/quote-client.js +0 -1
- package/dist/cart/quote-response.js +1 -2
- package/dist/cart/quote.d.ts +1 -1
- package/dist/cart/reconcile.js +0 -1
- package/dist/cart/source-menu.js +0 -1
- package/dist/cart/storage.js +0 -1
- package/dist/cart/types.js +0 -1
- package/dist/cart/validate.js +0 -1
- package/dist/cart/wire.js +0 -1
- package/dist/cart/working-set.js +0 -1
- package/dist/checkout/client.js +0 -1
- package/dist/checkout/embed.d.ts +67 -2
- package/dist/checkout/embed.js +0 -1
- package/dist/checkout/error.js +0 -1
- package/dist/checkout/index.d.ts +74 -3
- package/dist/checkout/index.js +0 -1
- package/dist/checkout/react.d.ts +67 -2
- package/dist/checkout/react.js +0 -1
- package/dist/checkout/readiness.js +0 -1
- package/dist/checkout/sdk.js +0 -1
- package/dist/checkout/session.js +0 -1
- package/dist/checkout/types.js +0 -1
- package/dist/checkout-defaults/index.d.ts +10 -1
- package/dist/checkout-defaults/index.js +0 -1
- package/dist/{client-B89-aNcl.d.ts → client-CW_OWZ0l.d.ts} +229 -5
- package/dist/client.js +0 -1
- package/dist/config/index.d.ts +38 -3
- package/dist/config/index.js +0 -1
- package/dist/config.js +0 -1
- package/dist/customer/client.js +0 -1
- package/dist/customer/error.js +0 -1
- package/dist/customer/index.d.ts +180 -5
- package/dist/customer/index.js +0 -1
- package/dist/customer/navigation.js +0 -1
- package/dist/customer/react.js +0 -1
- package/dist/customer/reorder.d.ts +8 -0
- package/dist/customer/reorder.js +0 -1
- package/dist/customer/request.js +0 -1
- package/dist/customer/types.js +0 -1
- package/dist/customer/watch-order.js +0 -1
- package/dist/debug.js +1 -2
- package/dist/display/index.d.ts +5 -1
- package/dist/display/index.js +0 -1
- package/dist/error-pages/art.js +0 -1
- package/dist/error-pages/index.d.ts +12 -1
- package/dist/error-pages/index.js +0 -1
- package/dist/error-pages/react.js +0 -1
- package/dist/errors.js +1 -2
- package/dist/in-venue/bill.js +0 -1
- package/dist/in-venue/client.js +0 -1
- package/dist/in-venue/error.js +0 -1
- package/dist/in-venue/index.d.ts +110 -2
- package/dist/in-venue/index.js +0 -1
- package/dist/in-venue/react/bill-page.js +0 -1
- package/dist/in-venue/react/in-venue-page.js +0 -1
- package/dist/in-venue/react/order-panel.js +0 -1
- package/dist/in-venue/react/pay-point-page.js +0 -1
- package/dist/in-venue/react/shared.js +0 -1
- package/dist/in-venue/react/table-menus-page.js +0 -1
- package/dist/in-venue/react.js +0 -1
- package/dist/in-venue/table.js +0 -1
- package/dist/in-venue/types.js +0 -1
- package/dist/in-venue/watch.js +0 -1
- package/dist/index.d.ts +32 -8
- package/dist/index.js +1 -2
- package/dist/integrations/index.d.ts +15 -2
- package/dist/integrations/index.js +0 -1
- package/dist/internal/abort.js +0 -1
- package/dist/internal/cache.js +0 -1
- package/dist/internal/customer-http.js +1 -2
- package/dist/internal/emitter.js +0 -1
- package/dist/internal/image-widths.js +0 -1
- package/dist/internal/money-math.js +0 -1
- package/dist/internal/perk-hold.js +0 -1
- package/dist/internal/remembered-address.js +0 -1
- package/dist/internal/return-path.js +0 -1
- package/dist/internal/service-url.js +0 -1
- package/dist/internal.d.ts +2 -2
- package/dist/internal.js +0 -1
- package/dist/loyalty/cart.js +0 -1
- package/dist/loyalty/client.js +0 -1
- package/dist/loyalty/index.d.ts +410 -2
- package/dist/loyalty/index.js +0 -1
- package/dist/loyalty/react.d.ts +15 -1
- package/dist/loyalty/react.js +0 -1
- package/dist/loyalty/release.js +0 -1
- package/dist/loyalty/types.js +0 -1
- package/dist/menu/index.d.ts +5 -1
- package/dist/menu/index.js +0 -1
- package/dist/models-C77LjkK8.d.ts +540 -0
- package/dist/models.js +0 -1
- package/dist/money.js +0 -1
- package/dist/navigation/index.d.ts +8 -0
- package/dist/navigation/index.js +0 -1
- package/dist/navigation/react.js +0 -1
- package/dist/navigation-progress/index.js +0 -1
- package/dist/options/index.d.ts +5 -1
- package/dist/options/index.js +0 -1
- package/dist/persist/catalogue.d.ts +3 -3
- package/dist/persist/catalogue.js +0 -1
- package/dist/places/client.js +0 -1
- package/dist/places/error.js +0 -1
- package/dist/places/index.d.ts +41 -1
- package/dist/places/index.js +0 -1
- package/dist/places/request.js +0 -1
- package/dist/places/sdk.js +0 -1
- package/dist/places/search.js +0 -1
- package/dist/places/types.js +0 -1
- package/dist/pricing/index.js +0 -1
- package/dist/react/cart.js +0 -1
- package/dist/react/changes.js +0 -1
- package/dist/react/hooks.js +0 -1
- package/dist/react/index.js +0 -1
- package/dist/react/provider.js +0 -1
- package/dist/react/rollback.js +0 -1
- package/dist/receipts/index.js +1 -2
- package/dist/redirect/index.js +0 -1
- package/dist/rich-text/index.d.ts +4 -0
- package/dist/rich-text/index.js +0 -1
- package/dist/server/auth/crypto.js +0 -1
- package/dist/server/auth/jwt.js +0 -1
- package/dist/server/auth/session-store.js +0 -1
- package/dist/server/chosen-branch.js +0 -1
- package/dist/server/edge-cache.js +0 -1
- package/dist/server/edge-snapshot.js +0 -1
- package/dist/server/index.d.ts +179 -8
- package/dist/server/index.js +0 -1
- package/dist/server/legacy-order.js +0 -1
- package/dist/server/page-cache.js +0 -1
- package/dist/server/security.js +0 -1
- package/dist/server/sign-in.js +0 -1
- package/dist/server/site-seo.js +0 -1
- package/dist/server/site-worker.js +0 -1
- package/dist/server/storefront-url/build-v1.js +0 -1
- package/dist/server/storefront-url/build-v2.js +0 -1
- package/dist/server/storefront-url/build.js +0 -1
- package/dist/server/storefront-url/canonical.js +0 -1
- package/dist/server/storefront-url/contract.js +0 -1
- package/dist/server/storefront-url/index.js +0 -1
- package/dist/server/storefront-url/installation.js +0 -1
- package/dist/server/storefront-url/params.js +0 -1
- package/dist/server/storefront-url/parse-v1.js +0 -1
- package/dist/server/storefront-url/parse-v2.js +0 -1
- package/dist/server/storefront-url/parse.js +0 -1
- package/dist/server/storefront-url/public-id.js +0 -1
- package/dist/server/storefront-url/redirect.js +0 -1
- package/dist/server/storefront-url/sign-in.js +0 -1
- package/dist/server/storefront-url/types.js +0 -1
- package/dist/server/storefront-url/url.js +0 -1
- package/dist/server/webhook.js +0 -1
- package/dist/services/index.d.ts +5 -1
- package/dist/services/index.js +0 -1
- package/dist/site-closed/index.d.ts +3 -0
- package/dist/site-closed/index.js +0 -1
- package/dist/site-config/helpers.js +0 -1
- package/dist/site-config/sections.js +0 -1
- package/dist/site-config/types.js +0 -1
- package/dist/site-config/validate.js +0 -1
- package/dist/site-error/index.d.ts +9 -1
- package/dist/site-error/index.js +0 -1
- package/dist/site-error/react.js +0 -1
- package/dist/studio/index.d.ts +2 -0
- package/dist/template/index.d.ts +7 -1
- package/dist/template/index.js +0 -1
- package/dist/template/react.js +0 -1
- package/dist/testing/index.d.ts +28 -1
- package/dist/testing/index.js +1 -1
- package/dist/testing/loyalty.js +0 -1
- package/dist/transport/category-page.js +0 -1
- package/dist/transport/mappers.js +0 -1
- package/dist/transport/presentation.js +0 -1
- package/dist/transport/quote-body.js +0 -1
- package/dist/transport/rest.js +0 -1
- package/dist/transport/search.d.ts +1 -1
- package/dist/transport/search.js +0 -1
- package/dist/transport/selected-menu.d.ts +3 -3
- package/dist/transport/selected-menu.js +0 -1
- package/dist/transport/store.js +0 -1
- package/dist/transport/types.js +0 -1
- package/dist/types-CuPaBf6k.d.ts +838 -0
- package/dist/uploads/index.js +0 -1
- package/dist/url/index.d.ts +31 -0
- package/dist/url/index.js +0 -1
- package/dist/visits/index.d.ts +26 -1
- package/dist/visits/index.js +0 -1
- package/dist/visits/page-views.js +0 -1
- package/dist/vite/index.d.ts +2 -0
- package/package.json +2 -2
- package/dist/account/index.js.map +0 -6
- package/dist/account/url.js.map +0 -6
- package/dist/branches/index.js.map +0 -6
- package/dist/cart/branch.js.map +0 -6
- package/dist/cart/errors.js.map +0 -6
- package/dist/cart/held.js.map +0 -6
- package/dist/cart/index.js.map +0 -6
- package/dist/cart/item.js.map +0 -6
- package/dist/cart/preview.js.map +0 -6
- package/dist/cart/price.js.map +0 -6
- package/dist/cart/quote-client.js.map +0 -6
- package/dist/cart/quote-response.js.map +0 -6
- package/dist/cart/reconcile.js.map +0 -6
- package/dist/cart/source-menu.js.map +0 -6
- package/dist/cart/storage.js.map +0 -6
- package/dist/cart/types.js.map +0 -6
- package/dist/cart/validate.js.map +0 -6
- package/dist/cart/wire.js.map +0 -6
- package/dist/cart/working-set.js.map +0 -6
- package/dist/checkout/client.js.map +0 -6
- package/dist/checkout/embed.js.map +0 -6
- package/dist/checkout/error.js.map +0 -6
- package/dist/checkout/index.js.map +0 -6
- package/dist/checkout/react.js.map +0 -6
- package/dist/checkout/readiness.js.map +0 -6
- package/dist/checkout/sdk.js.map +0 -6
- package/dist/checkout/session.js.map +0 -6
- package/dist/checkout/types.js.map +0 -6
- package/dist/checkout-defaults/index.js.map +0 -6
- package/dist/client.js.map +0 -6
- package/dist/config/index.js.map +0 -6
- package/dist/config.js.map +0 -6
- package/dist/customer/client.js.map +0 -6
- package/dist/customer/error.js.map +0 -6
- package/dist/customer/index.js.map +0 -6
- package/dist/customer/navigation.js.map +0 -6
- package/dist/customer/react.js.map +0 -6
- package/dist/customer/reorder.js.map +0 -6
- package/dist/customer/request.js.map +0 -6
- package/dist/customer/types.js.map +0 -6
- package/dist/customer/watch-order.js.map +0 -6
- package/dist/debug.js.map +0 -6
- package/dist/display/index.js.map +0 -6
- package/dist/error-pages/art.js.map +0 -6
- package/dist/error-pages/index.js.map +0 -6
- package/dist/error-pages/react.js.map +0 -6
- package/dist/errors.js.map +0 -6
- package/dist/in-venue/bill.js.map +0 -6
- package/dist/in-venue/client.js.map +0 -6
- package/dist/in-venue/error.js.map +0 -6
- package/dist/in-venue/index.js.map +0 -6
- package/dist/in-venue/react/bill-page.js.map +0 -6
- package/dist/in-venue/react/in-venue-page.js.map +0 -6
- package/dist/in-venue/react/order-panel.js.map +0 -6
- package/dist/in-venue/react/pay-point-page.js.map +0 -6
- package/dist/in-venue/react/shared.js.map +0 -6
- package/dist/in-venue/react/table-menus-page.js.map +0 -6
- package/dist/in-venue/react.js.map +0 -6
- package/dist/in-venue/table.js.map +0 -6
- package/dist/in-venue/types.js.map +0 -6
- package/dist/in-venue/watch.js.map +0 -6
- package/dist/index.js.map +0 -6
- package/dist/integrations/index.js.map +0 -6
- package/dist/internal/abort.js.map +0 -6
- package/dist/internal/cache.js.map +0 -6
- package/dist/internal/customer-http.js.map +0 -6
- package/dist/internal/emitter.js.map +0 -6
- package/dist/internal/image-widths.js.map +0 -6
- package/dist/internal/money-math.js.map +0 -6
- package/dist/internal/perk-hold.js.map +0 -6
- package/dist/internal/remembered-address.js.map +0 -6
- package/dist/internal/return-path.js.map +0 -6
- package/dist/internal/service-url.js.map +0 -6
- package/dist/internal.js.map +0 -6
- package/dist/loyalty/cart.js.map +0 -6
- package/dist/loyalty/client.js.map +0 -6
- package/dist/loyalty/index.js.map +0 -6
- package/dist/loyalty/react.js.map +0 -6
- package/dist/loyalty/release.js.map +0 -6
- package/dist/loyalty/types.js.map +0 -6
- package/dist/menu/index.js.map +0 -6
- package/dist/models-DLGs3UI2.d.ts +0 -307
- package/dist/models.js.map +0 -6
- package/dist/money.js.map +0 -6
- package/dist/navigation/index.js.map +0 -6
- package/dist/navigation/react.js.map +0 -6
- package/dist/navigation-progress/index.js.map +0 -6
- package/dist/options/index.js.map +0 -6
- package/dist/persist/catalogue.js.map +0 -6
- package/dist/places/client.js.map +0 -6
- package/dist/places/error.js.map +0 -6
- package/dist/places/index.js.map +0 -6
- package/dist/places/request.js.map +0 -6
- package/dist/places/sdk.js.map +0 -6
- package/dist/places/search.js.map +0 -6
- package/dist/places/types.js.map +0 -6
- package/dist/pricing/index.js.map +0 -6
- package/dist/react/cart.js.map +0 -6
- package/dist/react/changes.js.map +0 -6
- package/dist/react/hooks.js.map +0 -6
- package/dist/react/index.js.map +0 -6
- package/dist/react/provider.js.map +0 -6
- package/dist/react/rollback.js.map +0 -6
- package/dist/receipts/index.js.map +0 -6
- package/dist/redirect/index.js.map +0 -6
- package/dist/rich-text/index.js.map +0 -6
- package/dist/server/auth/crypto.js.map +0 -6
- package/dist/server/auth/jwt.js.map +0 -6
- package/dist/server/auth/session-store.js.map +0 -6
- package/dist/server/chosen-branch.js.map +0 -6
- package/dist/server/edge-cache.js.map +0 -6
- package/dist/server/edge-snapshot.js.map +0 -6
- package/dist/server/index.js.map +0 -6
- package/dist/server/legacy-order.js.map +0 -6
- package/dist/server/page-cache.js.map +0 -6
- package/dist/server/security.js.map +0 -6
- package/dist/server/sign-in.js.map +0 -6
- package/dist/server/site-seo.js.map +0 -6
- package/dist/server/site-worker.js.map +0 -6
- package/dist/server/storefront-url/build-v1.js.map +0 -6
- package/dist/server/storefront-url/build-v2.js.map +0 -6
- package/dist/server/storefront-url/build.js.map +0 -6
- package/dist/server/storefront-url/canonical.js.map +0 -6
- package/dist/server/storefront-url/contract.js.map +0 -6
- package/dist/server/storefront-url/index.js.map +0 -6
- package/dist/server/storefront-url/installation.js.map +0 -6
- package/dist/server/storefront-url/params.js.map +0 -6
- package/dist/server/storefront-url/parse-v1.js.map +0 -6
- package/dist/server/storefront-url/parse-v2.js.map +0 -6
- package/dist/server/storefront-url/parse.js.map +0 -6
- package/dist/server/storefront-url/public-id.js.map +0 -6
- package/dist/server/storefront-url/redirect.js.map +0 -6
- package/dist/server/storefront-url/sign-in.js.map +0 -6
- package/dist/server/storefront-url/types.js.map +0 -6
- package/dist/server/storefront-url/url.js.map +0 -6
- package/dist/server/webhook.js.map +0 -6
- package/dist/services/index.js.map +0 -6
- package/dist/site-closed/index.js.map +0 -6
- package/dist/site-config/helpers.js.map +0 -6
- package/dist/site-config/sections.js.map +0 -6
- package/dist/site-config/types.js.map +0 -6
- package/dist/site-config/validate.js.map +0 -6
- package/dist/site-error/index.js.map +0 -6
- package/dist/site-error/react.js.map +0 -6
- package/dist/template/index.js.map +0 -6
- package/dist/template/react.js.map +0 -6
- package/dist/testing/loyalty.js.map +0 -6
- package/dist/transport/category-page.js.map +0 -6
- package/dist/transport/mappers.js.map +0 -6
- package/dist/transport/presentation.js.map +0 -6
- package/dist/transport/quote-body.js.map +0 -6
- package/dist/transport/rest.js.map +0 -6
- package/dist/transport/search.js.map +0 -6
- package/dist/transport/selected-menu.js.map +0 -6
- package/dist/transport/store.js.map +0 -6
- package/dist/transport/types.js.map +0 -6
- package/dist/types-8HB4-7D9.d.ts +0 -457
- package/dist/uploads/index.js.map +0 -6
- package/dist/url/index.js.map +0 -6
- package/dist/visits/index.js.map +0 -6
- package/dist/visits/page-views.js.map +0 -6
package/dist/loyalty/index.d.ts
CHANGED
|
@@ -13,8 +13,11 @@ declare const MoneyBrand: unique symbol;
|
|
|
13
13
|
type Currency = string;
|
|
14
14
|
/** A frozen amount in safe integer minor units. Create it with money(). */
|
|
15
15
|
type Money = {
|
|
16
|
+
/** The amount in minor units of the currency, such as kobo for NGN. A safe integer, never rounded. */
|
|
16
17
|
readonly amountMinor: number;
|
|
18
|
+
/** The ISO 4217 currency code, in capitals, such as `NGN`. */
|
|
17
19
|
readonly currency: Currency;
|
|
20
|
+
/** A type-only brand, so only `money()` makes a Money. It holds no value at runtime. */
|
|
18
21
|
readonly [MoneyBrand]: true;
|
|
19
22
|
};
|
|
20
23
|
|
|
@@ -22,9 +25,13 @@ type Money = {
|
|
|
22
25
|
type Variant = {
|
|
23
26
|
/** A low-stock hint for shoppers. This does not give a stock balance. */
|
|
24
27
|
lowStock?: boolean;
|
|
28
|
+
/** The variant id. A cart line names it as `variantId`. */
|
|
25
29
|
id: string;
|
|
30
|
+
/** The attribute choices that select this variant, as attribute group id to choice id. Empty for an item without attributes. */
|
|
26
31
|
attributeChoices: Record<string, string>;
|
|
32
|
+
/** The variant's full price, not a difference from the item price. */
|
|
27
33
|
price: Money;
|
|
34
|
+
/** Whether the variant can be ordered at this branch. */
|
|
28
35
|
isAvailable: boolean;
|
|
29
36
|
/**
|
|
30
37
|
* Photos of this exact variant, such as one colour. Empty when the variant
|
|
@@ -43,10 +50,13 @@ type Item = {
|
|
|
43
50
|
}[];
|
|
44
51
|
/** Stock text for display. Use isAvailable and the server quote to check eligibility. */
|
|
45
52
|
stockLabel?: string;
|
|
53
|
+
/** The active promotion on the item, by name. Left out when there is none. */
|
|
46
54
|
promo?: {
|
|
47
55
|
name: string;
|
|
48
56
|
};
|
|
57
|
+
/** The item id. */
|
|
49
58
|
id: string;
|
|
59
|
+
/** The item name. */
|
|
50
60
|
name: string;
|
|
51
61
|
/** Plain text with the editor's formatting removed. */
|
|
52
62
|
description?: string;
|
|
@@ -56,61 +66,124 @@ type Item = {
|
|
|
56
66
|
* renders it. Render it where you show `description`, and fall back to `description` without it.
|
|
57
67
|
*/
|
|
58
68
|
descriptionHtml?: string;
|
|
69
|
+
/** The item's image URLs. Empty when it has none. */
|
|
59
70
|
images: string[];
|
|
71
|
+
/** The branch price. For an item whose own price is 0, the lowest variant price. */
|
|
60
72
|
price: Money;
|
|
73
|
+
/** The earlier price, to show struck through. Left out unless it is above `price`. */
|
|
61
74
|
compareAtPrice?: Money;
|
|
75
|
+
/**
|
|
76
|
+
* Whether the item can be ordered now. Also false when the item carries an option rule or variant
|
|
77
|
+
* this SDK can't read, so the cart never takes it.
|
|
78
|
+
*/
|
|
62
79
|
isAvailable: boolean;
|
|
80
|
+
/**
|
|
81
|
+
* How many one line can order. `min` is 1 when the item sets none. `max` is left out when the item
|
|
82
|
+
* sets none. `step` is always 1.
|
|
83
|
+
*/
|
|
63
84
|
quantity: {
|
|
64
85
|
min: number;
|
|
65
86
|
max?: number;
|
|
66
87
|
step: number;
|
|
67
88
|
};
|
|
89
|
+
/** The item's exact variants. There is always at least one. */
|
|
68
90
|
variants: [Variant, ...Variant[]];
|
|
91
|
+
/** The attribute groups first, then the add-on and instruction groups. */
|
|
69
92
|
optionGroups: OptionGroup[];
|
|
93
|
+
/** Labels for the item. The API doesn't send tags today, so REST reads give an empty list. */
|
|
70
94
|
tags: string[];
|
|
71
95
|
};
|
|
72
96
|
/** Conditions that change option rules when selected choices match. */
|
|
73
97
|
type OptionCondition = {
|
|
98
|
+
/** The group whose picks the rule reads. */
|
|
74
99
|
groupId: string;
|
|
100
|
+
/** The choices in that group that trigger the rule. Empty when the rule counts picks instead. */
|
|
75
101
|
choiceIds: string[];
|
|
102
|
+
/**
|
|
103
|
+
* How `choiceIds` trigger the rule. `any` triggers when the shopper picks one of them. `all` needs
|
|
104
|
+
* every one. Defaults to `any`.
|
|
105
|
+
*/
|
|
76
106
|
match: "any" | "all";
|
|
107
|
+
/**
|
|
108
|
+
* Triggers on how many different choices the shopper picks in that group, whatever their
|
|
109
|
+
* quantities. `eq` is exactly `value`, `gte` is `value` or more and `lte` is `value` or fewer. When
|
|
110
|
+
* set, `choiceIds` and `match` don't apply.
|
|
111
|
+
*/
|
|
77
112
|
count?: {
|
|
78
113
|
op: "eq" | "gte" | "lte";
|
|
79
114
|
value: number;
|
|
80
115
|
};
|
|
116
|
+
/** Whether the group needs a pick while the rule applies. Left out when the rule doesn't change it. */
|
|
81
117
|
setRequired?: boolean | null;
|
|
118
|
+
/** The group's `selection.min` while the rule applies. Left out when the rule doesn't change it. */
|
|
82
119
|
setMin?: number | null;
|
|
120
|
+
/** The group's `selection.max` while the rule applies. 0 removes the upper limit. Left out when the rule doesn't change it. */
|
|
83
121
|
setMax?: number | null;
|
|
84
122
|
};
|
|
85
123
|
/** Addon or exact-variant attribute selection rules. */
|
|
86
124
|
type OptionGroup = {
|
|
125
|
+
/** The group id. A cart line's choices name it as `groupId`, and its `inputs` key text by it. */
|
|
87
126
|
id: string;
|
|
127
|
+
/** The group name, such as Size or Add-ons. */
|
|
88
128
|
name: string;
|
|
129
|
+
/** Help to show with the group. Left out when none is set. */
|
|
89
130
|
helpText?: string;
|
|
131
|
+
/**
|
|
132
|
+
* How the shopper answers. `select` picks from `choices`, for attribute and add-on groups. `text`
|
|
133
|
+
* is an instruction the shopper types. `number`, `date` (`YYYY-MM-DD`), `time` (`HH:MM`) and
|
|
134
|
+
* `toggle` (`true` or `false`) are typed answers the cart validates. The REST transport only
|
|
135
|
+
* produces `select` and `text`. A group of a kind newer than the SDK is dropped, and its item
|
|
136
|
+
* reads as unavailable.
|
|
137
|
+
*/
|
|
90
138
|
kind: "select" | "text" | "number" | "date" | "time" | "toggle";
|
|
139
|
+
/** Whether the shopper must pick or type something in this group. Attribute groups always need a pick. A condition's `setRequired` can change it. */
|
|
91
140
|
required: boolean;
|
|
141
|
+
/** False when the group is off. The cart then drops its picks and never requires it. The REST transport never sets it. */
|
|
92
142
|
isAvailable?: boolean;
|
|
143
|
+
/**
|
|
144
|
+
* True when a `select` group also takes a typed response in place of a pick. The REST transport
|
|
145
|
+
* never sets it.
|
|
146
|
+
*/
|
|
93
147
|
isInformational?: boolean;
|
|
148
|
+
/**
|
|
149
|
+
* How many units the shopper picks. `min` is the fewest once they pick anything, and each choice
|
|
150
|
+
* counts its quantity. `max` is left out when the group has no upper limit.
|
|
151
|
+
*/
|
|
94
152
|
selection: {
|
|
95
153
|
min: number;
|
|
96
154
|
max?: number;
|
|
97
155
|
};
|
|
156
|
+
/** True for an attribute group, whose picks select the exact variant. False for add-ons and instructions. */
|
|
98
157
|
isAttribute: boolean;
|
|
158
|
+
/** The choices of an attribute or add-on group. Empty for a text group. */
|
|
99
159
|
choices: Choice[];
|
|
160
|
+
/**
|
|
161
|
+
* Settings for a typed answer. `placeholder` is the input's placeholder. `maxLength` is the most
|
|
162
|
+
* characters the cart takes, 500 when unset. The REST transport fills only `placeholder`.
|
|
163
|
+
*/
|
|
100
164
|
input?: {
|
|
101
165
|
maxLength?: number;
|
|
102
166
|
placeholder?: string;
|
|
103
167
|
};
|
|
168
|
+
/** Rules that change this group while the shopper's picks in another group match. They apply in order. Left out when there are none. */
|
|
104
169
|
conditions?: OptionCondition[];
|
|
105
170
|
};
|
|
106
171
|
/** A selectable option. Attribute prices are zero to avoid charging twice. */
|
|
107
172
|
type Choice = {
|
|
108
173
|
/** An attribute price adjustment for display. Cart calculations exclude it. */
|
|
109
174
|
priceHint?: Money;
|
|
175
|
+
/** The choice id. */
|
|
110
176
|
id: string;
|
|
177
|
+
/** The choice name, such as Large. */
|
|
111
178
|
name: string;
|
|
179
|
+
/** What one unit of the choice adds to the line. Zero for an attribute choice. */
|
|
112
180
|
price: Money;
|
|
181
|
+
/** Whether the shopper can pick the choice now. Attribute choices are always true, and the variant's `isAvailable` decides. */
|
|
113
182
|
isAvailable: boolean;
|
|
183
|
+
/**
|
|
184
|
+
* How many units of the choice one pick takes, when the shopper can pick more than one. `min`
|
|
185
|
+
* defaults to 1. Left out when the quantity is always 1.
|
|
186
|
+
*/
|
|
114
187
|
quantity?: {
|
|
115
188
|
min: number;
|
|
116
189
|
max?: number;
|
|
@@ -121,20 +194,40 @@ type Choice = {
|
|
|
121
194
|
* An item selection you submit to the cart, with optional quantity, choices, inputs and source menu.
|
|
122
195
|
*/
|
|
123
196
|
type CartLineInput = {
|
|
197
|
+
/** The item's ID. */
|
|
124
198
|
itemId: string;
|
|
125
199
|
/**
|
|
126
200
|
* The source menu the shopper selected. The SDK checks catalogue membership. Without one, the
|
|
127
201
|
* cart files the line under its default menu, `withDefaultMenu`.
|
|
128
202
|
*/
|
|
129
203
|
menuId?: string;
|
|
204
|
+
/**
|
|
205
|
+
* How many units of the item. Defaults to the item's minimum quantity. It must be a whole
|
|
206
|
+
* number within the item's limits and step, and 99 at most.
|
|
207
|
+
*/
|
|
130
208
|
quantity?: number;
|
|
209
|
+
/**
|
|
210
|
+
* The choices the shopper picked, each by its option group ID and choice ID. A choice's
|
|
211
|
+
* `quantity` is how many units of it, and defaults to 1. Choices in an unavailable group are
|
|
212
|
+
* dropped.
|
|
213
|
+
*/
|
|
131
214
|
choices?: {
|
|
132
215
|
groupId: string;
|
|
133
216
|
choiceId: string;
|
|
134
217
|
quantity?: number;
|
|
135
218
|
}[];
|
|
219
|
+
/**
|
|
220
|
+
* What the shopper typed for the item's input groups (text, number, date, time or toggle),
|
|
221
|
+
* keyed by group ID. A date is `YYYY-MM-DD`, a time is `HH:MM` or `HH:MM:SS`, and a toggle is
|
|
222
|
+
* `true` or `false`. A saved cart left alone for more than 24 hours loses its inputs.
|
|
223
|
+
*/
|
|
136
224
|
inputs?: Record<string, string>;
|
|
225
|
+
/**
|
|
226
|
+
* The exact variant. When you leave it out, the cart picks the one variant that matches the
|
|
227
|
+
* attribute choices in `choices`. A variant that doesn't match them is refused.
|
|
228
|
+
*/
|
|
137
229
|
variantId?: string;
|
|
230
|
+
/** The shopper's note for this line, 280 characters at most. It goes on the order. */
|
|
138
231
|
note?: string;
|
|
139
232
|
};
|
|
140
233
|
/**
|
|
@@ -163,14 +256,23 @@ type CartLine = Readonly<{
|
|
|
163
256
|
* A cart delivery address with optional place coordinates and instructions.
|
|
164
257
|
*/
|
|
165
258
|
type DeliveryAddress = {
|
|
259
|
+
/** The first line of the address, such as the street and number. It can't be blank. */
|
|
166
260
|
line1: string;
|
|
261
|
+
/**
|
|
262
|
+
* A second address line. The cart keeps it, but the API doesn't take it, so quotes and checkout
|
|
263
|
+
* leave it out.
|
|
264
|
+
*/
|
|
167
265
|
line2?: string;
|
|
266
|
+
/** The city. */
|
|
168
267
|
city?: string;
|
|
268
|
+
/** A place ID from the places lookup. The quote prices delivery to that place. */
|
|
169
269
|
placeId?: string;
|
|
270
|
+
/** The address's latitude and longitude in degrees. */
|
|
170
271
|
coordinates?: {
|
|
171
272
|
lat: number;
|
|
172
273
|
lng: number;
|
|
173
274
|
};
|
|
275
|
+
/** Instructions for the rider or the counter. Pricing ignores them. */
|
|
174
276
|
instructions?: string;
|
|
175
277
|
};
|
|
176
278
|
/** A shopper's selection, distinct from the store's Fulfilment capabilities. */
|
|
@@ -199,52 +301,221 @@ type CartFulfilment = {
|
|
|
199
301
|
* address. It is never sent to checkout.
|
|
200
302
|
*/
|
|
201
303
|
type PendingFulfilment = {
|
|
304
|
+
/** Always `delivery`. Pickup and dine-in need no address, so you set them with `setFulfilment`. */
|
|
202
305
|
type: "delivery";
|
|
306
|
+
/**
|
|
307
|
+
* When the order is for, as an RFC 3339 date and time. Left out for as soon as possible.
|
|
308
|
+
*/
|
|
203
309
|
scheduledFor?: string | undefined;
|
|
204
310
|
};
|
|
205
311
|
/**
|
|
206
312
|
* Stable identifiers for cart validation and quote issues you can handle in your UI.
|
|
207
313
|
*/
|
|
208
|
-
type CartIssueCode =
|
|
314
|
+
type CartIssueCode =
|
|
315
|
+
/**
|
|
316
|
+
* The item, its variant or its menu can't be ordered now. The cart raises it when the item is
|
|
317
|
+
* missing from its catalogue, is unavailable, or no menu at the branch lists it, and as a warning
|
|
318
|
+
* from `moveTo` for each line the new branch can't sell. A blocking quote issue whose code is
|
|
319
|
+
* newer than this SDK also arrives as this code, with the API's code in `data.code`.
|
|
320
|
+
*/
|
|
321
|
+
"item_unavailable"
|
|
322
|
+
/**
|
|
323
|
+
* The item isn't on the branch's menus. The cart raises it when `update` names a line ID the
|
|
324
|
+
* cart doesn't hold.
|
|
325
|
+
*/
|
|
326
|
+
| "item_not_found"
|
|
327
|
+
/**
|
|
328
|
+
* A picked choice is unavailable. The cart also raises it for a choice or input whose option
|
|
329
|
+
* group no longer exists.
|
|
330
|
+
*/
|
|
331
|
+
| "option_unavailable"
|
|
332
|
+
/**
|
|
333
|
+
* A required option group has no pick, or an item with attributes has no variant. The cart
|
|
334
|
+
* raises it for a required group with no choice and no typed answer.
|
|
335
|
+
*/
|
|
336
|
+
| "option_required"
|
|
337
|
+
/**
|
|
338
|
+
* The picks break a group's rules, such as too many units or a choice from another group. The
|
|
339
|
+
* cart also raises it for a note over 280 characters, a group given both a choice and a typed
|
|
340
|
+
* answer, an answer in the wrong format, a choice quantity out of range, and choices that match
|
|
341
|
+
* no available variant.
|
|
342
|
+
*/
|
|
343
|
+
| "option_limit"
|
|
344
|
+
/**
|
|
345
|
+
* The quantity is outside the item's limits. From the quote, `data.quantity` is the nearest
|
|
346
|
+
* allowed. The cart raises it for a quantity that isn't a whole number in the item's range and
|
|
347
|
+
* step, with a `set_quantity` fix, and when an add would take the cart past 100 lines.
|
|
348
|
+
*/
|
|
349
|
+
| "quantity_limit"
|
|
350
|
+
/**
|
|
351
|
+
* A line's price changed. The quote raises it when the price differs from the one at the
|
|
352
|
+
* request's `menu_version`. The cart raises it as a warning when a saved or refreshed line's
|
|
353
|
+
* estimate differs from the price it held. Both give `data.previous` and `data.current`.
|
|
354
|
+
*/
|
|
355
|
+
| "price_changed"
|
|
356
|
+
/**
|
|
357
|
+
* The branch is closed now. `data.next_open_at` says when it opens again. It is `info` for a
|
|
358
|
+
* scheduled cart. Only the quote raises it.
|
|
359
|
+
*/
|
|
360
|
+
| "branch_closed"
|
|
361
|
+
/**
|
|
362
|
+
* The branch doesn't take this fulfilment mode, and `data.offered` lists the modes it does. The
|
|
363
|
+
* cart raises it when `setFulfilment` gets an invalid selection or one for another branch, and
|
|
364
|
+
* when `toCheckoutPayload` runs with no lines or no fulfilment.
|
|
365
|
+
*/
|
|
366
|
+
| "fulfilment_unavailable"
|
|
367
|
+
/**
|
|
368
|
+
* The branch doesn't deliver to the address. `data.reason` is `outside_zone`, or
|
|
369
|
+
* `address_unresolved` when the address could not be found. Only the quote raises it.
|
|
370
|
+
*/
|
|
371
|
+
| "outside_delivery_zone"
|
|
372
|
+
/**
|
|
373
|
+
* The shopper must pick one of the branch's delivery regions, then you set it as
|
|
374
|
+
* `deliveryRegionId`. Only the quote raises it.
|
|
375
|
+
*/
|
|
376
|
+
| "delivery_region_required"
|
|
377
|
+
/**
|
|
378
|
+
* The scheduled time is in the past or too soon for the menu's notice. Only the quote raises it.
|
|
379
|
+
*/
|
|
380
|
+
| "schedule_invalid"
|
|
381
|
+
/**
|
|
382
|
+
* The promo code doesn't apply, with the code in `data.promo_code`. A warning. Only the quote
|
|
383
|
+
* raises it.
|
|
384
|
+
*/
|
|
385
|
+
| "promo_invalid"
|
|
386
|
+
/** The cart is below the promo code's minimum spend. A warning. Only the quote raises it. */
|
|
387
|
+
| "promo_min_spend"
|
|
388
|
+
/** Reserved. The API doesn't send it today. */
|
|
389
|
+
| "min_order"
|
|
390
|
+
/**
|
|
391
|
+
* The menus changed since the request's `menu_version`, and `data.menu_version` is the current
|
|
392
|
+
* one. An `info` issue. The cart refreshes its menu when it sees it. Only the quote raises it.
|
|
393
|
+
*/
|
|
394
|
+
| "menu_version_stale"
|
|
395
|
+
/**
|
|
396
|
+
* A perk redemption can't be used on this order, because it was cancelled, used or reserved at
|
|
397
|
+
* another branch. The quote is then priced without the perks. Only the quote raises it.
|
|
398
|
+
*/
|
|
399
|
+
| "perk_invalid"
|
|
400
|
+
/**
|
|
401
|
+
* A checkout field the store asks for is missing. `data.field` names the field. It comes only for a
|
|
402
|
+
* signed-in customer, and only from the quote.
|
|
403
|
+
*/
|
|
404
|
+
| "checkout_field_required"
|
|
405
|
+
/**
|
|
406
|
+
* A checkout field's value can't be used. `data.field` names the field and `data.reason` is
|
|
407
|
+
* `format`, or `taken` when the email is on another account. It comes only for a signed-in
|
|
408
|
+
* customer, and only from the quote.
|
|
409
|
+
*/
|
|
410
|
+
| "checkout_field_invalid";
|
|
209
411
|
/**
|
|
210
412
|
* A suggested cart correction, including any option, quantity or fulfilment details it needs.
|
|
211
413
|
*/
|
|
212
414
|
type CartFix = {
|
|
415
|
+
/**
|
|
416
|
+
* What to offer the shopper. `remove_line` takes the issue's line out, and `applyFix` does
|
|
417
|
+
* it. `accept_price` keeps the line at its new price, and `applyFix` clears the issue.
|
|
418
|
+
* `remove_promo` drops the promo code, and `applyFix` does it. `change_address` asks for
|
|
419
|
+
* another address, which you set with `setFulfilment`. `choose_region` asks the shopper to
|
|
420
|
+
* pick a delivery region, which you set as `deliveryRegionId` with `setFulfilment`.
|
|
421
|
+
* `remove_perks` drops the perk redemptions, and `applyFix` does it.
|
|
422
|
+
*/
|
|
213
423
|
action: "remove_line" | "accept_price" | "remove_promo" | "change_address" | "choose_region" | "remove_perks";
|
|
214
424
|
} | {
|
|
425
|
+
/**
|
|
426
|
+
* `choose_option` asks the shopper to pick in the group. `choose_other_option` asks for
|
|
427
|
+
* another choice in the group, because the picked one is unavailable. Apply either with
|
|
428
|
+
* `update`.
|
|
429
|
+
*/
|
|
215
430
|
action: "choose_option" | "choose_other_option";
|
|
431
|
+
/** The option group to pick in. */
|
|
216
432
|
groupId: string;
|
|
217
433
|
} | {
|
|
434
|
+
/** `set_quantity` changes the line's quantity to `quantity`, and `applyFix` does it. */
|
|
218
435
|
action: "set_quantity";
|
|
436
|
+
/** The nearest quantity the item allows, from 1 to 99. */
|
|
219
437
|
quantity: number;
|
|
220
438
|
} | {
|
|
439
|
+
/**
|
|
440
|
+
* `schedule` asks the shopper to schedule the order, for `nextOpenAt` or later. Set the time
|
|
441
|
+
* with `setFulfilment`.
|
|
442
|
+
*/
|
|
221
443
|
action: "schedule";
|
|
444
|
+
/**
|
|
445
|
+
* When the branch or the menu opens next, as an RFC 3339 date and time in UTC. Left out
|
|
446
|
+
* when the API sends none.
|
|
447
|
+
*/
|
|
222
448
|
nextOpenAt?: string;
|
|
449
|
+
/** Reserved for times the shopper can choose. The API doesn't send it today. */
|
|
223
450
|
slots?: string[];
|
|
224
451
|
} | {
|
|
452
|
+
/** `switch_fulfilment` asks the shopper to change to one of the modes in `types`. */
|
|
225
453
|
action: "switch_fulfilment";
|
|
454
|
+
/** The fulfilment modes the branch offers. The SDK drops modes it doesn't know. */
|
|
226
455
|
types: CartFulfilment["type"][];
|
|
456
|
+
} | {
|
|
457
|
+
/**
|
|
458
|
+
* `fill_field` asks the shopper for the checkout field in `field`, on a
|
|
459
|
+
* `checkout_field_required` or `checkout_field_invalid` issue. Ask for it in your checkout
|
|
460
|
+
* form. `applyFix` can't fill it in.
|
|
461
|
+
*/
|
|
462
|
+
action: "fill_field";
|
|
463
|
+
/** The checkout field's key, such as `email` or a key from `Quote.checkout.fields`. */
|
|
464
|
+
field: string;
|
|
227
465
|
};
|
|
228
466
|
/**
|
|
229
467
|
* What the shopper typed for the store's built-in checkout fields, with API field names. A detail
|
|
230
468
|
* the signed-in customer's account already holds is used instead.
|
|
231
469
|
*/
|
|
232
470
|
type CheckoutCustomer = {
|
|
471
|
+
/** The shopper's first name, 100 characters at most. */
|
|
233
472
|
given_name?: string;
|
|
473
|
+
/** The shopper's last name, 100 characters at most. */
|
|
234
474
|
family_name?: string;
|
|
475
|
+
/**
|
|
476
|
+
* The shopper's email, 254 characters at most. An email on another account comes back as
|
|
477
|
+
* `checkout_field_invalid` with `data.reason` `taken`.
|
|
478
|
+
*/
|
|
235
479
|
email?: string;
|
|
236
480
|
};
|
|
237
481
|
/**
|
|
238
482
|
* A local or quoted cart issue with severity, display message and suggested fixes.
|
|
239
483
|
*/
|
|
240
484
|
type CartIssue = {
|
|
485
|
+
/** What the problem is. Each code says when it is raised and what goes in `data`. */
|
|
241
486
|
code: CartIssueCode;
|
|
487
|
+
/**
|
|
488
|
+
* How much the issue matters. `blocking` stops checkout until the shopper fixes it. Every issue
|
|
489
|
+
* the cart raises itself is `blocking`, except `price_changed` and the lines `moveTo` drops.
|
|
490
|
+
* `warning` tells the shopper something changed, and checkout still goes through. `info` is a
|
|
491
|
+
* notice only, and leaves the cart state `quoted`.
|
|
492
|
+
*/
|
|
242
493
|
severity: "blocking" | "warning" | "info";
|
|
494
|
+
/** The cart line the issue is about. Left out for an issue with the whole cart. */
|
|
243
495
|
lineId?: string;
|
|
496
|
+
/**
|
|
497
|
+
* The option group the issue is about. The cart's own checks set it, and a quote issue takes it
|
|
498
|
+
* from the API's `data.group_id`, so the cart shows a problem both report once. Left out for an
|
|
499
|
+
* issue with no group.
|
|
500
|
+
*/
|
|
244
501
|
groupId?: string;
|
|
502
|
+
/** A message you can show the shopper. */
|
|
245
503
|
message: string;
|
|
504
|
+
/**
|
|
505
|
+
* Details that depend on the code, listed with each `CartIssueCode`. From the quote, it holds
|
|
506
|
+
* the API's details as sent, in snake_case with money as `amount_minor` and `currency`. Left out
|
|
507
|
+
* when there are none.
|
|
508
|
+
*/
|
|
246
509
|
data?: Record<string, unknown>;
|
|
510
|
+
/**
|
|
511
|
+
* Ways to resolve the issue, in the order to offer them. It can be empty. Pass one to
|
|
512
|
+
* `applyFix`.
|
|
513
|
+
*/
|
|
247
514
|
fixes: CartFix[];
|
|
515
|
+
/**
|
|
516
|
+
* Where the issue comes from. `local` means the cart's own checks against the menu it holds
|
|
517
|
+
* found it. `quote` means the API's quote reported it.
|
|
518
|
+
*/
|
|
248
519
|
source: "local" | "quote";
|
|
249
520
|
};
|
|
250
521
|
/**
|
|
@@ -276,8 +547,18 @@ type Quote = {
|
|
|
276
547
|
etaMinutes?: number[];
|
|
277
548
|
deliveryRegionId?: string;
|
|
278
549
|
};
|
|
550
|
+
/**
|
|
551
|
+
* True when you can't trust the per-line prices, which can then be null. The overall totals
|
|
552
|
+
* still hold. Left out otherwise.
|
|
553
|
+
*/
|
|
279
554
|
linesUnpriced?: boolean;
|
|
555
|
+
/** What the lines cost before charges and discounts. A line with status `invalid` isn't in it. */
|
|
280
556
|
subtotal: Money;
|
|
557
|
+
/**
|
|
558
|
+
* The charges on top of the subtotal other than delivery, such as a service charge, packaging
|
|
559
|
+
* or VAT. `code` says what each is for and `label` is the business's own name for it. A charge
|
|
560
|
+
* at zero is left out.
|
|
561
|
+
*/
|
|
281
562
|
fees: {
|
|
282
563
|
code: string;
|
|
283
564
|
label: string;
|
|
@@ -285,6 +566,10 @@ type Quote = {
|
|
|
285
566
|
}[];
|
|
286
567
|
/** The sum of `fees`, so you can show one fees line. Zero when there are none. Delivery is not included. */
|
|
287
568
|
feesTotal: Money;
|
|
569
|
+
/**
|
|
570
|
+
* The delivery fee. Left out when the quote has no delivery charge, as for pickup, or a
|
|
571
|
+
* delivery with no address yet.
|
|
572
|
+
*/
|
|
288
573
|
delivery?: Money;
|
|
289
574
|
/** A perk's discount has code `perk` and the `redemptionId` it comes from. */
|
|
290
575
|
discounts: {
|
|
@@ -293,16 +578,39 @@ type Quote = {
|
|
|
293
578
|
amount: Money;
|
|
294
579
|
redemptionId?: string;
|
|
295
580
|
}[];
|
|
581
|
+
/** The subtotal plus the fees, delivery and discounts. Discount amounts are negative. */
|
|
296
582
|
total: Money;
|
|
583
|
+
/**
|
|
584
|
+
* Everything the quote found, in the order it found it. These are the quote's issues only. The
|
|
585
|
+
* cart's `issues` adds its own checks.
|
|
586
|
+
*/
|
|
297
587
|
issues: CartIssue[];
|
|
588
|
+
/** False when any issue is blocking or a delivery has no address yet. */
|
|
298
589
|
canCheckout: boolean;
|
|
590
|
+
/** Whether you can open a checkout session next. Use it to show the right button. */
|
|
299
591
|
checkout: {
|
|
592
|
+
/** True when you can open a checkout session for this cart now. */
|
|
300
593
|
ready: boolean;
|
|
594
|
+
/**
|
|
595
|
+
* Why checkout is not ready. `issues` means a blocking issue stops it. `customer_required`
|
|
596
|
+
* means the cart needs a signed-in customer. Left out when checkout is ready, for a delivery
|
|
597
|
+
* that only needs its address, and for a reason newer than this SDK.
|
|
598
|
+
*/
|
|
301
599
|
reason?: "issues" | "customer_required";
|
|
302
600
|
/** The store's checkout field keys this cart asks for, in display order. */
|
|
303
601
|
fields?: string[];
|
|
304
602
|
};
|
|
603
|
+
/**
|
|
604
|
+
* The branch's current menu version, which names the state of its menus. Compare the whole
|
|
605
|
+
* string and don't parse it. When it differs from the cart's menu, the cart refreshes the menu
|
|
606
|
+
* and quotes again.
|
|
607
|
+
*/
|
|
305
608
|
menuVersion: string;
|
|
609
|
+
/**
|
|
610
|
+
* When the quote expires, 15 minutes after it was made, as an RFC 3339 date and time in UTC.
|
|
611
|
+
* Until then the cart reuses it for an unchanged cart. Checkout prices the cart again, so it
|
|
612
|
+
* never refuses a quote for being old.
|
|
613
|
+
*/
|
|
306
614
|
expiresAt: string;
|
|
307
615
|
};
|
|
308
616
|
/**
|
|
@@ -330,7 +638,10 @@ type AppliedPerk = Readonly<{
|
|
|
330
638
|
pointsSpent: number;
|
|
331
639
|
/** When the reservation gives its points back if no order uses it. */
|
|
332
640
|
expiresAt: string;
|
|
333
|
-
/**
|
|
641
|
+
/**
|
|
642
|
+
* What the perk gives, when the perk was applied from the perk list. `order_discount` takes an
|
|
643
|
+
* amount or a percentage off the order. `free_item` gives items for free.
|
|
644
|
+
*/
|
|
334
645
|
reward?: "order_discount" | "free_item";
|
|
335
646
|
}>;
|
|
336
647
|
/**
|
|
@@ -339,15 +650,36 @@ type AppliedPerk = Readonly<{
|
|
|
339
650
|
type CartSnapshot = {
|
|
340
651
|
/** Selected branch remains available before a fulfilment mode is chosen. */
|
|
341
652
|
readonly branchId?: string | undefined;
|
|
653
|
+
/** The lines in the order they were added. */
|
|
342
654
|
readonly lines: readonly CartLine[];
|
|
655
|
+
/** The number of units across every line. */
|
|
343
656
|
readonly count: number;
|
|
657
|
+
/**
|
|
658
|
+
* The sum of the lines' local estimates, before charges and discounts. Null when a line can't be
|
|
659
|
+
* priced from the menu the cart holds. The quote's `subtotal` is the price to trust.
|
|
660
|
+
*/
|
|
344
661
|
readonly subtotal: Money | null;
|
|
662
|
+
/**
|
|
663
|
+
* How the shopper gets the order. Null until you call `setFulfilment`, and again after `clear` or
|
|
664
|
+
* `moveTo`. A saved delivery is dropped after 24 hours without a change, and a scheduled time
|
|
665
|
+
* already past is removed when the cart loads.
|
|
666
|
+
*/
|
|
345
667
|
readonly fulfilment: CartFulfilment | null;
|
|
668
|
+
/** The promo code sent with each quote and checkout, trimmed. Null when there is none. */
|
|
346
669
|
readonly promoCode: string | null;
|
|
347
670
|
/** The perks redeemed into the bag, sent with each quote and checkout. Never on an in-venue order. */
|
|
348
671
|
readonly perks: readonly AppliedPerk[];
|
|
672
|
+
/** Where the cart is in validating and quoting, with the latest quote when it has one. */
|
|
349
673
|
readonly state: CartState;
|
|
674
|
+
/**
|
|
675
|
+
* Every open issue: the cart's own checks first, then the quote's issues that the cart doesn't
|
|
676
|
+
* already report.
|
|
677
|
+
*/
|
|
350
678
|
readonly issues: readonly CartIssue[];
|
|
679
|
+
/**
|
|
680
|
+
* True once the cart has loaded the saved cart for its branch, by `hydrate`, `mount` or the first
|
|
681
|
+
* edit.
|
|
682
|
+
*/
|
|
351
683
|
readonly isHydrated: boolean;
|
|
352
684
|
};
|
|
353
685
|
/**
|
|
@@ -371,10 +703,25 @@ interface CartModule extends CartSnapshot {
|
|
|
371
703
|
* Throws `ZappieCartError` when the line is invalid, for example when no menu lists the item.
|
|
372
704
|
*/
|
|
373
705
|
add(item: Item | string, input?: Omit<CartLineInput, "itemId">): CartLine;
|
|
706
|
+
/**
|
|
707
|
+
* Change a line and return it. Fields you leave out keep their values. A patch with `choices`
|
|
708
|
+
* and no `variantId` picks the variant again. A change that makes the line equal to another
|
|
709
|
+
* merges the two. Throws `ZappieCartError` with `item_not_found` when the cart has no such line,
|
|
710
|
+
* or with the line's issues when the change is invalid.
|
|
711
|
+
* @param lineId - The ID of the cart line to change.
|
|
712
|
+
* @param patch - The fields to change.
|
|
713
|
+
*/
|
|
374
714
|
update(lineId: string, patch: Partial<Omit<CartLineInput, "itemId">>): CartLine;
|
|
715
|
+
/** Take a line out of the cart. An ID the cart doesn't hold changes nothing. */
|
|
375
716
|
remove(lineId: string): void;
|
|
717
|
+
/** Empty the cart, and drop its fulfilment, promo code and perks. */
|
|
376
718
|
clear(): void;
|
|
719
|
+
/**
|
|
720
|
+
* Set how the shopper gets the order. Throws `ZappieCartError` with `fulfilment_unavailable`
|
|
721
|
+
* when the selection is invalid or names another branch than the cart's.
|
|
722
|
+
*/
|
|
377
723
|
setFulfilment(fulfilment: CartFulfilment): void;
|
|
724
|
+
/** Set the promo code to send with each quote and checkout. Null or a blank code removes it. */
|
|
378
725
|
setPromoCode(code: string | null): void;
|
|
379
726
|
/**
|
|
380
727
|
* Set what the shopper typed for the store's checkout fields. Each quote and the checkout send it.
|
|
@@ -392,18 +739,45 @@ interface CartModule extends CartSnapshot {
|
|
|
392
739
|
* fulfilment, and `setFulfilment` with the address takes over. It stays in memory only.
|
|
393
740
|
*/
|
|
394
741
|
setPendingFulfilment(pending: PendingFulfilment | null): void;
|
|
742
|
+
/**
|
|
743
|
+
* Ask the API to price the cart and resolve with the quote. A cart with lines also quotes by
|
|
744
|
+
* itself 300 milliseconds after each change. An unchanged cart gets its last quote back until it expires,
|
|
745
|
+
* and a cart that just failed to price throws the same error for 30 seconds.
|
|
746
|
+
* @param opts - Set `force` to ask the API again in either case.
|
|
747
|
+
*/
|
|
395
748
|
quote(opts?: {
|
|
396
749
|
force?: boolean;
|
|
397
750
|
}): Promise<Quote>;
|
|
398
751
|
/** Handle interactive fixes by calling the option, address or time setter. */
|
|
399
752
|
applyFix(issue: CartIssue, fix?: CartFix): void;
|
|
753
|
+
/**
|
|
754
|
+
* Move the cart to another branch of the store. Lines the new branch can't sell are dropped,
|
|
755
|
+
* each with an `item_unavailable` warning, and the fulfilment, promo code and perks are cleared.
|
|
756
|
+
* The old branch's saved cart is removed.
|
|
757
|
+
* @param branchId - The ID of the branch to move to.
|
|
758
|
+
*/
|
|
400
759
|
moveTo(branchId: string): Promise<void>;
|
|
760
|
+
/**
|
|
761
|
+
* Load the store, the branch's menu and the saved cart. It then asks for a quote when the cart
|
|
762
|
+
* has none, and refreshes the menu when its version changed. On a loaded cart it does only that.
|
|
763
|
+
*/
|
|
401
764
|
hydrate(): Promise<void>;
|
|
402
765
|
/** Attach browser listeners. Use the returned cleanup in your component effect. */
|
|
403
766
|
mount(): () => void;
|
|
767
|
+
/** Stop the cart for good: cancel its quotes, detach its listeners and drop its subscribers. */
|
|
404
768
|
dispose(): void;
|
|
769
|
+
/**
|
|
770
|
+
* Call `fn` after each change to the cart's snapshot. Returns a function that unsubscribes. It
|
|
771
|
+
* fits `useSyncExternalStore` with `getSnapshot`.
|
|
772
|
+
*/
|
|
405
773
|
subscribe(fn: () => void): () => void;
|
|
774
|
+
/** The current snapshot. It is frozen and only replaced when the cart changes. */
|
|
406
775
|
getSnapshot(): CartSnapshot;
|
|
776
|
+
/**
|
|
777
|
+
* The cart as a checkout request body, in API field names. Throws `ZappieCartError` with the
|
|
778
|
+
* blocking issues, or with `fulfilment_unavailable` when the cart has no lines or no
|
|
779
|
+
* fulfilment.
|
|
780
|
+
*/
|
|
407
781
|
toCheckoutPayload(): {
|
|
408
782
|
lines: WireLine[];
|
|
409
783
|
fulfilment: CartFulfilment;
|
|
@@ -417,35 +791,52 @@ interface CartModule extends CartSnapshot {
|
|
|
417
791
|
* A cart line serialized with API field names for quote and checkout requests.
|
|
418
792
|
*/
|
|
419
793
|
type WireLine = {
|
|
794
|
+
/** The cart line's ID. The quote returns it unchanged. */
|
|
420
795
|
line_id: string;
|
|
796
|
+
/** The item's ID. */
|
|
421
797
|
item_id: string;
|
|
798
|
+
/**
|
|
799
|
+
* The menu the shopper chose the item from. The API needs it when the item is on more than one
|
|
800
|
+
* menu.
|
|
801
|
+
*/
|
|
422
802
|
menu_id?: string;
|
|
803
|
+
/** How many units, from 1 to 99. */
|
|
423
804
|
quantity: number;
|
|
805
|
+
/** The exact variant. The API needs it when the item has attribute groups. */
|
|
424
806
|
variant_id?: string;
|
|
807
|
+
/** The choices picked in option groups, each with how many units of it. */
|
|
425
808
|
options: {
|
|
426
809
|
group_id: string;
|
|
427
810
|
choice_id: string;
|
|
428
811
|
quantity: number;
|
|
429
812
|
}[];
|
|
813
|
+
/** What the shopper typed for each input group, keyed by group ID. */
|
|
430
814
|
inputs: Record<string, string>;
|
|
815
|
+
/** The shopper's note for this line. It goes on the order. */
|
|
431
816
|
note?: string;
|
|
432
817
|
};
|
|
433
818
|
/**
|
|
434
819
|
* An API monetary amount in minor units with its currency code.
|
|
435
820
|
*/
|
|
436
821
|
type WireMoney = {
|
|
822
|
+
/** The amount in minor units of the currency, such as kobo or cents. */
|
|
437
823
|
amount_minor: number;
|
|
824
|
+
/** The ISO 4217 currency code. */
|
|
438
825
|
currency: Currency;
|
|
439
826
|
};
|
|
440
827
|
|
|
441
828
|
/** The customer's points with the business. `enabled` is false while it has no loyalty programme set up. */
|
|
442
829
|
type Loyalty = {
|
|
830
|
+
/** Always `loyalty`. */
|
|
443
831
|
object: "loyalty";
|
|
832
|
+
/** False while the business has no loyalty programme set up. */
|
|
444
833
|
enabled: boolean;
|
|
834
|
+
/** The customer's points with the business. Test keys read 0. */
|
|
445
835
|
points: number;
|
|
446
836
|
};
|
|
447
837
|
/** What a perk gives, to show the shopper. The quote prices it exactly. */
|
|
448
838
|
type PerkReward = {
|
|
839
|
+
/** What kind of reward it is. `order_discount` takes `percent_off` or `amount_off` off the order. `free_item` gives the items in `items` for free. */
|
|
449
840
|
type: "order_discount" | "free_item";
|
|
450
841
|
/** A percentage off the order. */
|
|
451
842
|
percent_off?: number;
|
|
@@ -459,19 +850,28 @@ type PerkReward = {
|
|
|
459
850
|
};
|
|
460
851
|
/** A perk the customer can spend points on at a branch. */
|
|
461
852
|
type Perk = {
|
|
853
|
+
/** The perk's ID. Pass it to `redeem`. */
|
|
462
854
|
id: string;
|
|
855
|
+
/** Always `perk`. */
|
|
463
856
|
object: "perk";
|
|
857
|
+
/** The perk's name. */
|
|
464
858
|
name: string;
|
|
859
|
+
/** The perk's description. Null when it has none. */
|
|
465
860
|
description: string | null;
|
|
861
|
+
/** The points a redemption spends. At least 1. */
|
|
466
862
|
points_cost: number;
|
|
863
|
+
/** What the perk gives. */
|
|
467
864
|
reward: PerkReward;
|
|
468
865
|
/** The order types the business made the perk for. */
|
|
469
866
|
fulfilments: ("delivery" | "pickup" | "dine_in")[];
|
|
470
867
|
};
|
|
471
868
|
/** A redemption: points spent on a perk, reserved until an order uses it or it is cancelled. */
|
|
472
869
|
type PerkRedemption = {
|
|
870
|
+
/** The redemption's ID. Pass it to `cancel`. */
|
|
473
871
|
id: string;
|
|
872
|
+
/** Always `perk_redemption`. */
|
|
474
873
|
object: "perk_redemption";
|
|
874
|
+
/** Where it stands. `reserved` means the points are taken and held for 24 hours, until `expires_at`, for an order to use. `cancelled` means you released it or it ran out unused, and its points went back. */
|
|
475
875
|
status: "reserved" | "cancelled";
|
|
476
876
|
/** Sent when it is reserved. */
|
|
477
877
|
points_spent?: number;
|
|
@@ -485,21 +885,29 @@ type PerkRedemption = {
|
|
|
485
885
|
};
|
|
486
886
|
/** What claiming an order's points earned, and the balance after it. */
|
|
487
887
|
type LoyaltyClaim = {
|
|
888
|
+
/** Always `loyalty_claim`. */
|
|
488
889
|
object: "loyalty_claim";
|
|
890
|
+
/** The order the points were claimed for. */
|
|
489
891
|
order_id: string;
|
|
892
|
+
/** The points this claim added. 0 when the order's points were already awarded. */
|
|
490
893
|
points_earned: number;
|
|
894
|
+
/** The customer's balance after the claim. */
|
|
491
895
|
points: number;
|
|
492
896
|
};
|
|
493
897
|
/** The customer's store credit at a branch. `enabled` is false when the branch doesn't take it. */
|
|
494
898
|
type StoreCredit = {
|
|
899
|
+
/** Always `store_credit`. */
|
|
495
900
|
object: "store_credit";
|
|
901
|
+
/** False when the branch doesn't take store credit. */
|
|
496
902
|
enabled: boolean;
|
|
903
|
+
/** The customer's store credit at the branch, in minor units. Test keys read 0. */
|
|
497
904
|
balance: WireMoney;
|
|
498
905
|
};
|
|
499
906
|
/** Where the loyalty client sends its requests. */
|
|
500
907
|
type LoyaltyClientOptions = {
|
|
501
908
|
/** The same-origin customer API base. Defaults to `/_zappie/api`. */
|
|
502
909
|
customerBase?: string;
|
|
910
|
+
/** The fetch implementation for every request. Defaults to the global `fetch`. */
|
|
503
911
|
fetch?: typeof fetch;
|
|
504
912
|
};
|
|
505
913
|
|