@tanqory/theme-kit 0.1.0 → 2.0.0-alpha.19
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/LICENSE +21 -0
- package/README.md +128 -10
- package/dist/abi/canvas-live.d.ts +72 -0
- package/dist/abi/canvas-live.js +159 -0
- package/dist/abi/cart.d.ts +60 -0
- package/dist/abi/cart.js +396 -0
- package/dist/abi/convert.d.ts +360 -0
- package/dist/abi/convert.js +1330 -0
- package/dist/abi/data-api.d.ts +15 -0
- package/dist/abi/data-api.js +213 -0
- package/dist/abi/jcs.d.ts +6 -0
- package/dist/abi/jcs.js +28 -0
- package/dist/abi/labels.d.ts +3 -0
- package/dist/abi/labels.js +34 -0
- package/dist/abi/page-data.d.ts +264 -0
- package/dist/abi/page-data.js +746 -0
- package/dist/abi/page.d.ts +28 -0
- package/dist/abi/page.js +57 -0
- package/dist/abi/referrals.d.ts +23 -0
- package/dist/abi/referrals.js +89 -0
- package/dist/abi/rewards.d.ts +27 -0
- package/dist/abi/rewards.js +82 -0
- package/dist/abi/seo.d.ts +47 -0
- package/dist/abi/seo.js +68 -0
- package/dist/abi/shell.d.ts +23 -0
- package/dist/abi/shell.js +10 -0
- package/dist/abi/state-pack.d.ts +17 -0
- package/dist/abi/state-pack.js +43 -0
- package/dist/abi/wire.d.ts +46 -0
- package/dist/abi/wire.js +114 -0
- package/dist/build.d.ts +121 -0
- package/dist/build.js +401 -0
- package/dist/chunks.d.ts +23 -0
- package/dist/chunks.js +41 -0
- package/dist/client.d.ts +26 -0
- package/dist/client.js +101 -0
- package/dist/contract.d.ts +6 -0
- package/dist/contract.js +6 -0
- package/dist/headless/ai.d.ts +132 -0
- package/dist/headless/ai.js +99 -0
- package/dist/headless/hooks.d.ts +276 -0
- package/dist/headless/hooks.js +544 -0
- package/dist/headless/i18n.d.ts +13 -0
- package/dist/headless/i18n.js +45 -0
- package/dist/headless/index.d.ts +44 -0
- package/dist/headless/index.js +48 -0
- package/dist/headless/lazy-component.d.ts +72 -0
- package/dist/headless/lazy-component.js +225 -0
- package/dist/headless/lazy-section.d.ts +38 -0
- package/dist/headless/lazy-section.js +97 -0
- package/dist/headless/model.d.ts +73 -0
- package/dist/headless/model.js +115 -0
- package/dist/headless/money.d.ts +17 -0
- package/dist/headless/money.js +63 -0
- package/dist/headless/page.d.ts +45 -0
- package/dist/headless/page.js +53 -0
- package/dist/headless/platform.d.ts +55 -0
- package/dist/headless/platform.js +77 -0
- package/dist/headless/primitives/cart.d.ts +90 -0
- package/dist/headless/primitives/cart.js +153 -0
- package/dist/headless/primitives/collection.d.ts +68 -0
- package/dist/headless/primitives/collection.js +80 -0
- package/dist/headless/primitives/product.d.ts +101 -0
- package/dist/headless/primitives/product.js +117 -0
- package/dist/headless/primitives/storefront.d.ts +106 -0
- package/dist/headless/primitives/storefront.js +187 -0
- package/dist/headless/primitives/util.d.ts +19 -0
- package/dist/headless/primitives/util.js +42 -0
- package/dist/headless/strings.d.ts +9 -0
- package/dist/headless/strings.js +198 -0
- package/dist/headless/structured-data.d.ts +31 -0
- package/dist/headless/structured-data.js +57 -0
- package/dist/headless/tanqory-money.generated.d.ts +493 -0
- package/dist/headless/tanqory-money.generated.js +507 -0
- package/dist/headless/theme.d.ts +109 -0
- package/dist/headless/theme.js +62 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +21 -553
- package/dist/runtime/data/StoreProvider.d.ts +84 -0
- package/dist/runtime/data/StoreProvider.js +380 -0
- package/dist/runtime/data/handle.d.ts +14 -0
- package/dist/runtime/data/handle.js +16 -0
- package/dist/runtime/data/routes.d.ts +87 -0
- package/dist/runtime/data/routes.js +158 -0
- package/dist/runtime/data/to-ui.d.ts +286 -0
- package/dist/runtime/data/to-ui.js +1009 -0
- package/dist/runtime/entries/register.d.ts +9 -0
- package/dist/runtime/entries/register.js +9 -0
- package/dist/runtime/entries/sections.d.ts +16 -0
- package/dist/runtime/entries/sections.js +19 -0
- package/dist/{types → runtime/kit}/SectionTree.d.ts +2 -1
- package/dist/runtime/kit/SectionTree.js +100 -0
- package/dist/runtime/kit/analytics.d.ts +63 -0
- package/dist/runtime/kit/analytics.js +250 -0
- package/dist/runtime/kit/cart.d.ts +222 -0
- package/dist/runtime/kit/cart.js +545 -0
- package/dist/{types → runtime/kit}/composition.d.ts +1 -1
- package/dist/runtime/kit/composition.js +3 -0
- package/dist/{types → runtime/kit}/config.d.ts +2 -2
- package/dist/runtime/kit/config.js +6 -0
- package/dist/runtime/kit/consent.d.ts +29 -0
- package/dist/runtime/kit/consent.js +159 -0
- package/dist/runtime/kit/contract/content.d.ts +213 -0
- package/dist/runtime/kit/contract/content.js +119 -0
- package/dist/runtime/kit/contract/field-types.d.ts +360 -0
- package/dist/runtime/kit/contract/field-types.js +216 -0
- package/dist/runtime/kit/contract/groups.d.ts +230 -0
- package/dist/runtime/kit/contract/groups.js +402 -0
- package/dist/runtime/kit/contract/index.d.ts +33 -0
- package/dist/runtime/kit/contract/index.js +33 -0
- package/dist/runtime/kit/contract/transform.d.ts +82 -0
- package/dist/runtime/kit/contract/transform.js +133 -0
- package/dist/runtime/kit/contract/validate.d.ts +77 -0
- package/dist/runtime/kit/contract/validate.js +520 -0
- package/dist/runtime/kit/data.d.ts +732 -0
- package/dist/runtime/kit/data.js +1131 -0
- package/dist/{types → runtime/kit}/defineSection.d.ts +1 -1
- package/dist/runtime/kit/defineSection.js +10 -0
- package/dist/runtime/kit/dynamic-source.d.ts +118 -0
- package/dist/runtime/kit/dynamic-source.js +311 -0
- package/dist/runtime/kit/index.d.ts +24 -0
- package/dist/runtime/kit/index.js +24 -0
- package/dist/{types → runtime/kit}/jsx-to-json.d.ts +1 -1
- package/dist/runtime/kit/jsx-to-json.js +28 -0
- package/dist/{types → runtime/kit}/mount.d.ts +25 -4
- package/dist/runtime/kit/mount.js +124 -0
- package/dist/{types → runtime/kit}/registry.d.ts +1 -1
- package/dist/runtime/kit/registry.js +12 -0
- package/dist/{types → runtime/kit}/ssg.d.ts +9 -3
- package/dist/runtime/kit/ssg.js +56 -0
- package/dist/runtime/kit/storefront.d.ts +652 -0
- package/dist/runtime/kit/storefront.js +723 -0
- package/dist/{types → runtime/kit}/theme-context.d.ts +8 -2
- package/dist/runtime/kit/theme-context.js +25 -0
- package/dist/runtime/kit/types.d.ts +155 -0
- package/dist/runtime/kit/types.js +1 -0
- package/dist/runtime/platform/TrackingPixels.d.ts +14 -0
- package/dist/runtime/platform/TrackingPixels.js +63 -0
- package/dist/runtime/platform/environment.d.ts +68 -0
- package/dist/runtime/platform/environment.js +85 -0
- package/dist/runtime/platform/locale.d.ts +27 -0
- package/dist/runtime/platform/locale.js +42 -0
- package/dist/runtime/platform/route-analytics.d.ts +15 -0
- package/dist/runtime/platform/route-analytics.js +72 -0
- package/dist/runtime/platform/safe-href.d.ts +25 -0
- package/dist/runtime/platform/safe-href.js +69 -0
- package/dist/runtime/platform/safe-values.d.ts +37 -0
- package/dist/runtime/platform/safe-values.js +140 -0
- package/dist/runtime/render/SectionRenderer.d.ts +4 -0
- package/dist/runtime/render/SectionRenderer.js +199 -0
- package/dist/runtime/render/listing-query.d.ts +52 -0
- package/dist/runtime/render/listing-query.js +122 -0
- package/dist/runtime/render/localized-copy.d.ts +86 -0
- package/dist/runtime/render/localized-copy.js +129 -0
- package/dist/runtime/render/product-listing.d.ts +11 -0
- package/dist/runtime/render/product-listing.js +243 -0
- package/dist/runtime/render/resolved.d.ts +47 -0
- package/dist/runtime/render/resolved.js +80 -0
- package/dist/runtime/render/section-actions.d.ts +67 -0
- package/dist/runtime/render/section-actions.js +205 -0
- package/dist/runtime/render/starter.d.ts +11 -0
- package/dist/runtime/render/starter.js +96 -0
- package/dist/runtime/seo/head.d.ts +115 -0
- package/dist/runtime/seo/head.js +281 -0
- package/dist/runtime/seo/structured-data.d.ts +83 -0
- package/dist/runtime/seo/structured-data.js +252 -0
- package/dist/runtime/shell/PageShell.d.ts +18 -0
- package/dist/runtime/shell/PageShell.js +118 -0
- package/dist/runtime/shell/RuntimeBridge.d.ts +18 -0
- package/dist/runtime/shell/RuntimeBridge.js +124 -0
- package/dist/runtime/shell/overlay-state.d.ts +31 -0
- package/dist/runtime/shell/overlay-state.js +59 -0
- package/dist/runtime/shell/preview-mode.d.ts +2 -0
- package/dist/runtime/shell/preview-mode.js +11 -0
- package/dist/runtime/shell/spa-router.d.ts +14 -0
- package/dist/runtime/shell/spa-router.js +76 -0
- package/dist/runtime/shell/url-redirects.d.ts +6 -0
- package/dist/runtime/shell/url-redirects.js +37 -0
- package/dist/runtime/slots.d.ts +74 -0
- package/dist/runtime/slots.js +16 -0
- package/dist/runtime.d.ts +34 -0
- package/dist/runtime.js +40 -0
- package/dist/sdk/app-block.d.ts +29 -0
- package/dist/sdk/app-block.js +22 -0
- package/dist/sdk/font-hooks.d.ts +7 -0
- package/dist/sdk/font-hooks.js +21 -0
- package/dist/sdk/fonts.d.ts +144 -0
- package/dist/sdk/fonts.js +241 -0
- package/dist/sdk/index.d.ts +32 -0
- package/dist/sdk/index.js +36 -0
- package/dist/sdk/motion-hooks.d.ts +23 -0
- package/dist/sdk/motion-hooks.js +46 -0
- package/dist/sdk/motion.d.ts +78 -0
- package/dist/sdk/motion.js +292 -0
- package/dist/sdk/referrals.d.ts +62 -0
- package/dist/sdk/referrals.js +20 -0
- package/dist/sdk/rewards.d.ts +85 -0
- package/dist/sdk/rewards.js +29 -0
- package/dist/sdk/runtime-context.d.ts +230 -0
- package/dist/sdk/runtime-context.js +73 -0
- package/dist/sdk/schema.d.ts +249 -0
- package/dist/sdk/schema.js +168 -0
- package/dist/sdk/server-render.d.ts +8 -0
- package/dist/sdk/server-render.js +12 -0
- package/dist/sdk/store-lookup.d.ts +32 -0
- package/dist/sdk/store-lookup.js +48 -0
- package/dist/sdk/store.d.ts +164 -0
- package/dist/sdk/store.js +5 -0
- package/dist/sdk/sx.d.ts +45 -0
- package/dist/sdk/sx.js +117 -0
- package/dist/sdk/theme.d.ts +212 -0
- package/dist/sdk/theme.js +27 -0
- package/dist/sdk/types.d.ts +789 -0
- package/dist/sdk/types.js +7 -0
- package/dist/server.d.ts +112 -0
- package/dist/server.js +589 -0
- package/dist/vite-chunks.d.ts +10 -0
- package/dist/vite-chunks.js +44 -0
- package/docs/headless-api.md +250 -0
- package/package.json +72 -26
- package/dist/index.js.map +0 -1
- package/dist/ssg-BZ5FYTw7.js +0 -1802
- package/dist/ssg-BZ5FYTw7.js.map +0 -1
- package/dist/ssg.js +0 -8
- package/dist/ssg.js.map +0 -1
- package/dist/types/cart.d.ts +0 -86
- package/dist/types/data.d.ts +0 -357
- package/dist/types/dynamic-source.d.ts +0 -84
- package/dist/types/editor.d.ts +0 -5
- package/dist/types/index.d.ts +0 -20
- package/dist/types/preview-bridge.d.ts +0 -9
- package/dist/types/storefront.d.ts +0 -333
- package/dist/types/types.d.ts +0 -44
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import { type Money } from './data.js';
|
|
3
|
+
export interface CartLine {
|
|
4
|
+
/** Cart line id — the handle used for update/remove. */
|
|
5
|
+
id: string;
|
|
6
|
+
/** The purchasable variant (merchandise) id. */
|
|
7
|
+
variantId: string;
|
|
8
|
+
quantity: number;
|
|
9
|
+
/** Product title shown in the cart. */
|
|
10
|
+
title: string;
|
|
11
|
+
/** Variant title (e.g. "Black / M"); empty for single-variant products. */
|
|
12
|
+
variantTitle?: string;
|
|
13
|
+
image?: {
|
|
14
|
+
url: string;
|
|
15
|
+
altText?: string;
|
|
16
|
+
} | null;
|
|
17
|
+
/** Per-unit price. */
|
|
18
|
+
price: Money;
|
|
19
|
+
/** Line subtotal (price × quantity). */
|
|
20
|
+
lineSubtotal: Money;
|
|
21
|
+
/** The line's total after its own discounts, when the cart source sends it (Theme ABI `CartLine.cost.totalAmount`). */
|
|
22
|
+
lineTotal?: Money;
|
|
23
|
+
/** Product handle for linking back to the PDP. */
|
|
24
|
+
productHandle?: string;
|
|
25
|
+
/** The line's product id (theme-abi Cart-4 `merchandise.product.id`), when the cart source sends it. */
|
|
26
|
+
productId?: string;
|
|
27
|
+
/** The variant's options (`Size: Queen`, `Colour: Oat`), when the cart source carries them. */
|
|
28
|
+
selectedOptions?: Array<{
|
|
29
|
+
name: string;
|
|
30
|
+
value: string;
|
|
31
|
+
}>;
|
|
32
|
+
/** Per-unit compare-at price, when the cart source carries one. */
|
|
33
|
+
compareAtPrice?: Money | null;
|
|
34
|
+
/** False when the merchandise can no longer be bought; absent = unknown (treated as purchasable). */
|
|
35
|
+
availableForSale?: boolean;
|
|
36
|
+
/** Custom line properties (`line_item.properties`). */
|
|
37
|
+
attributes?: Array<{
|
|
38
|
+
key: string;
|
|
39
|
+
value?: string | null;
|
|
40
|
+
}>;
|
|
41
|
+
/** Per-line discounts (`line_item.discount_allocations`). */
|
|
42
|
+
discountAllocations?: Array<{
|
|
43
|
+
title?: string | null;
|
|
44
|
+
code?: string | null;
|
|
45
|
+
amount: Money;
|
|
46
|
+
}>;
|
|
47
|
+
/** Subscription plan chosen for this line (`line_item.selling_plan_allocation`). */
|
|
48
|
+
sellingPlanAllocation?: {
|
|
49
|
+
sellingPlanId: string;
|
|
50
|
+
sellingPlanName: string;
|
|
51
|
+
checkoutCharge?: Money | null;
|
|
52
|
+
remainingBalance?: Money | null;
|
|
53
|
+
/** Theme ABI alpha.20 (NEW-SUB-2): the per-delivery unit the line is priced at and the one-time unit it was discounted from. */
|
|
54
|
+
perDeliveryPrice?: Money | null;
|
|
55
|
+
compareAtPrice?: Money | null;
|
|
56
|
+
} | null;
|
|
57
|
+
}
|
|
58
|
+
/** A discount code applied to the cart (`applicable=false` when it didn't qualify). */
|
|
59
|
+
export interface AppliedDiscountCode {
|
|
60
|
+
code: string;
|
|
61
|
+
applicable: boolean;
|
|
62
|
+
}
|
|
63
|
+
/** A gift card applied to the cart — masked (only last 4 chars ever leave the API). */
|
|
64
|
+
export interface AppliedGiftCard {
|
|
65
|
+
id: string;
|
|
66
|
+
lastCharacters: string;
|
|
67
|
+
amountUsed: Money;
|
|
68
|
+
balance: Money;
|
|
69
|
+
}
|
|
70
|
+
export interface CartState {
|
|
71
|
+
/**
|
|
72
|
+
* Why the first load of the cart failed (wire code, e.g. `rate_limited`), while `ready` stays
|
|
73
|
+
* false. A cart we could not read is NOT an empty cart. Absent/null once the cart has loaded.
|
|
74
|
+
*/
|
|
75
|
+
loadError?: string | null;
|
|
76
|
+
/** With `loadError`: true while another attempt is scheduled (Retry-After / backoff). */
|
|
77
|
+
loadRetrying?: boolean;
|
|
78
|
+
id: string | null;
|
|
79
|
+
lines: CartLine[];
|
|
80
|
+
subtotal: Money;
|
|
81
|
+
/** Final amount after discounts + gift cards (cost.totalAmount). */
|
|
82
|
+
total: Money;
|
|
83
|
+
/** Estimated tax (cost.totalTaxAmount) — null until known (usually at checkout). */
|
|
84
|
+
tax?: Money | null;
|
|
85
|
+
/** Estimated duties (cost.totalDutyAmount) — null unless cross-border. */
|
|
86
|
+
duty?: Money | null;
|
|
87
|
+
/** Cart-level order note (`cart.note`). */
|
|
88
|
+
note?: string | null;
|
|
89
|
+
/** Cart-level custom attributes (`cart.attributes`). */
|
|
90
|
+
attributes?: {
|
|
91
|
+
key: string;
|
|
92
|
+
value: string | null;
|
|
93
|
+
}[];
|
|
94
|
+
totalQuantity: number;
|
|
95
|
+
checkoutUrl: string | null;
|
|
96
|
+
/** Discount codes applied to the cart. */
|
|
97
|
+
discountCodes: AppliedDiscountCode[];
|
|
98
|
+
/** Total savings across all discount allocations — null when nothing's discounted. */
|
|
99
|
+
discountAmount: Money | null;
|
|
100
|
+
/**
|
|
101
|
+
* The cart's order-level discounts by name (automatic: `title`; code: `code`), when the source sends them.
|
|
102
|
+
* Absent = not known (the Theme ABI cart carries only totals and codes).
|
|
103
|
+
*/
|
|
104
|
+
discountAllocations?: Array<{
|
|
105
|
+
title?: string | null;
|
|
106
|
+
code?: string | null;
|
|
107
|
+
amount: Money;
|
|
108
|
+
}>;
|
|
109
|
+
/** Gift cards applied to the cart. */
|
|
110
|
+
appliedGiftCards: AppliedGiftCard[];
|
|
111
|
+
/** True while a mutation/bootstrap is in flight. */
|
|
112
|
+
loading: boolean;
|
|
113
|
+
/** True once the client has hydrated cart state post-mount. */
|
|
114
|
+
ready: boolean;
|
|
115
|
+
error: string | null;
|
|
116
|
+
}
|
|
117
|
+
export interface AddToCartInput {
|
|
118
|
+
/** Line properties the buyer filled in (a gift card recipient, an engraving), shown on the order. */
|
|
119
|
+
attributes?: Array<{
|
|
120
|
+
key: string;
|
|
121
|
+
value: string;
|
|
122
|
+
}>;
|
|
123
|
+
variantId: string;
|
|
124
|
+
quantity?: number;
|
|
125
|
+
/** The selling plan the shopper picked (`Product.sellingPlanGroups[].plans[].id`): a subscription line. Absent = one-time. */
|
|
126
|
+
sellingPlanId?: string;
|
|
127
|
+
/** Display data — used only by the in-memory MOCK driver (editor/offline). */
|
|
128
|
+
product?: {
|
|
129
|
+
title: string;
|
|
130
|
+
price: Money;
|
|
131
|
+
image?: {
|
|
132
|
+
url: string;
|
|
133
|
+
altText?: string;
|
|
134
|
+
} | null;
|
|
135
|
+
handle?: string;
|
|
136
|
+
variantTitle?: string;
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Why the platform refused a cart write, when it said (theme-abi 2.0.0-alpha.13 `CartRefusal`, Cart-1 / Cart-3).
|
|
141
|
+
* `cart_limit_exceeded`: more of one product than the merchant's "Maximum quantity per product" allows;
|
|
142
|
+
* `maxQuantity` is that limit when the platform knows it.
|
|
143
|
+
* `quantity_rule`: the cart is bought for a company location and the quantity is outside its rule for the variant —
|
|
144
|
+
* below the `minimum`, above the `maximum`, or not a multiple of the `increment` (the rule's numbers are not sent).
|
|
145
|
+
*/
|
|
146
|
+
export type CartRefusal = {
|
|
147
|
+
code: 'cart_limit_exceeded';
|
|
148
|
+
maxQuantity?: number;
|
|
149
|
+
} | {
|
|
150
|
+
code: 'quantity_rule';
|
|
151
|
+
rule: 'minimum' | 'maximum' | 'increment';
|
|
152
|
+
};
|
|
153
|
+
export interface CartApi extends CartState {
|
|
154
|
+
/** Re-read the cart after something outside this provider changed it. Never rejects. */
|
|
155
|
+
reload?: (id?: string) => Promise<void>;
|
|
156
|
+
/**
|
|
157
|
+
* Resolves `true` when the line is in the cart, `false` when the backend
|
|
158
|
+
* refused it (sold out, quantity rule, expired cart, network) — `error` then
|
|
159
|
+
* holds the reason. Never rejects, so a caller must check the result before
|
|
160
|
+
* treating the add as done.
|
|
161
|
+
*/
|
|
162
|
+
add: (input: AddToCartInput) => Promise<boolean>;
|
|
163
|
+
updateQuantity: (lineId: string, quantity: number) => Promise<void>;
|
|
164
|
+
remove: (lineId: string) => Promise<void>;
|
|
165
|
+
clear: () => Promise<void>;
|
|
166
|
+
/** Apply discount codes (replaces the current set; [] clears them). LIVE only. */
|
|
167
|
+
applyDiscountCodes: (codes: string[]) => Promise<void>;
|
|
168
|
+
/** Apply gift card codes to the cart. LIVE only. */
|
|
169
|
+
applyGiftCardCodes: (codes: string[]) => Promise<void>;
|
|
170
|
+
/** Remove applied gift cards by id. LIVE only. */
|
|
171
|
+
removeGiftCards: (ids: string[]) => Promise<void>;
|
|
172
|
+
/** Set the cart-level order note (`cart.note`). LIVE only. */
|
|
173
|
+
updateNote: (note: string) => Promise<void>;
|
|
174
|
+
/** Replace the cart-level custom attributes (`cart.attributes`). LIVE only. */
|
|
175
|
+
updateAttributes: (attributes: {
|
|
176
|
+
key: string;
|
|
177
|
+
value: string;
|
|
178
|
+
}[]) => Promise<void>;
|
|
179
|
+
/**
|
|
180
|
+
* The refusal of the latest cart write, when the platform said why (else null). A getter, not
|
|
181
|
+
* state: read it right after `add` / `updateQuantity` resolves, before the next render.
|
|
182
|
+
*/
|
|
183
|
+
lastRefusal?: () => CartRefusal | null;
|
|
184
|
+
/**
|
|
185
|
+
* What stock let the latest `add` put in the cart when the platform cut it (Cart-2), else null. A getter, read right
|
|
186
|
+
* after `add` resolves. With it `add` resolves false when nothing was added.
|
|
187
|
+
*/
|
|
188
|
+
lastAddStock?: () => CartAddStock | null;
|
|
189
|
+
/**
|
|
190
|
+
* Put a discount code on the cart, beside the codes already there, and say how it went; never rejects.
|
|
191
|
+
* `not_applicable`: the store keeps the code but does not apply it — it is taken off again and the other codes stay.
|
|
192
|
+
* `applied` may push out an earlier code it does not combine with (`lastDiscountReplaced`). Absent where the source
|
|
193
|
+
* cannot tell (the GraphQL driver).
|
|
194
|
+
*/
|
|
195
|
+
applyDiscountCode?: (code: string) => Promise<DiscountCodeResult>;
|
|
196
|
+
/** Take a discount code off the cart; resolves true once it is gone. Present with `applyDiscountCode`. */
|
|
197
|
+
removeDiscountCode?: (code: string) => Promise<boolean>;
|
|
198
|
+
/** Why the code the last `applyDiscountCode` refused does not apply, when the platform said why (else null). A getter. */
|
|
199
|
+
lastDiscountRefusal?: () => DiscountCodeRefusal | null;
|
|
200
|
+
/** The earlier codes the last `applyDiscountCode` took off because the new code does not combine with them ([] when none). A getter. */
|
|
201
|
+
lastDiscountReplaced?: () => readonly string[];
|
|
202
|
+
}
|
|
203
|
+
/** How applying a discount code went. */
|
|
204
|
+
export type DiscountCodeResult = 'applied' | 'not_applicable' | 'failed';
|
|
205
|
+
/**
|
|
206
|
+
* What stock let the last `add` put in the cart, when the platform cut it (theme-abi Cart-2: the ABI cart's `warnings`
|
|
207
|
+
* on the variant's line). `out_of_stock`: nothing was added; `not_enough_stock`: `added` were, all that is in stock.
|
|
208
|
+
*/
|
|
209
|
+
export type CartAddStock = {
|
|
210
|
+
code: 'out_of_stock';
|
|
211
|
+
} | {
|
|
212
|
+
code: 'not_enough_stock';
|
|
213
|
+
added: number;
|
|
214
|
+
};
|
|
215
|
+
/** Why a code does not apply (the Storefront API's DISCOUNT_* cart warning, via the ABI cart's `discountCodes[].refusal`). */
|
|
216
|
+
export type DiscountCodeRefusal = 'not_found' | 'inactive' | 'usage_limit' | 'already_used' | 'sign_in' | 'not_eligible' | 'no_items' | 'minimum_quantity' | 'minimum_subtotal' | 'delivery' | 'not_combinable';
|
|
217
|
+
/** Exported so another cart driver (lib/abi/cart.tsx, Theme ABI v2) can provide the same `useCart()`. */
|
|
218
|
+
export declare const CartContext: import("react").Context<CartApi | null>;
|
|
219
|
+
export declare function CartProvider({ children }: {
|
|
220
|
+
children: ReactNode;
|
|
221
|
+
}): JSX.Element;
|
|
222
|
+
export declare function useCart(): CartApi;
|