@shop-on/theme-server 0.10.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/account-state.js +1 -2
- package/dist/account.d.ts +1 -3
- package/dist/account.js +1 -3
- package/dist/activity.d.ts +1 -3
- package/dist/activity.js +1 -2
- package/dist/analytics-proxy.d.ts +8 -14
- package/dist/analytics-proxy.js +111 -28
- package/dist/analytics-script-proxy.d.ts +1 -5
- package/dist/analytics-script-proxy.js +4 -14
- package/dist/api-contract/src/addresses.js +32 -0
- package/dist/api-contract/src/areas.js +49 -0
- package/dist/api-contract/src/custom-data.d.ts +31 -0
- package/dist/api-contract/src/custom-data.js +303 -0
- package/dist/api-contract/src/ids.js +110 -0
- package/dist/api-contract/src/image.js +65 -0
- package/dist/api-contract/src/limits.js +44 -0
- package/dist/api-contract/src/media.js +13 -0
- package/dist/api-contract/src/pickup.js +11 -0
- package/dist/api-contract/src/recommendations.js +4 -0
- package/dist/api-contract/src/shops.js +27 -0
- package/dist/api-contract/src/storefront/analytics.d.ts +100 -0
- package/dist/api-contract/src/storefront/analytics.js +138 -0
- package/dist/api-contract/src/storefront/areas.d.ts +2 -0
- package/dist/api-contract/src/storefront/cart.d.ts +132 -0
- package/dist/api-contract/src/storefront/cart.js +248 -0
- package/dist/api-contract/src/storefront/catalog.d.ts +3 -0
- package/dist/api-contract/src/storefront/checkout-analytics.d.ts +2 -0
- package/dist/api-contract/src/storefront/checkout.d.ts +2 -0
- package/dist/api-contract/src/storefront/checkout.js +624 -0
- package/dist/api-contract/src/storefront/client.d.ts +3 -0
- package/dist/api-contract/src/storefront/client.js +6 -0
- package/dist/api-contract/src/storefront/content.d.ts +3 -0
- package/dist/api-contract/src/storefront/custom-data.d.ts +2 -0
- package/dist/api-contract/src/storefront/custom-data.js +27 -0
- package/dist/api-contract/src/storefront/customer.d.ts +2 -0
- package/dist/api-contract/src/storefront/customer.js +261 -0
- package/dist/api-contract/src/storefront/downloads.d.ts +2 -0
- package/dist/api-contract/src/storefront/draft-order-invoice.d.ts +2 -0
- package/dist/api-contract/src/storefront/forms.d.ts +2 -0
- package/dist/api-contract/src/storefront/forms.js +82 -0
- package/dist/api-contract/src/storefront/index.d.ts +20956 -0
- package/dist/api-contract/src/storefront/orders.d.ts +2 -0
- package/dist/api-contract/src/storefront/policies.d.ts +2 -0
- package/dist/api-contract/src/storefront/procedure.d.ts +2 -0
- package/dist/api-contract/src/storefront/procedure.js +29 -0
- package/dist/api-contract/src/storefront/reviews.d.ts +20 -0
- package/dist/api-contract/src/storefront/search.d.ts +3 -0
- package/dist/api-contract/src/storefront/seo.d.ts +2 -0
- package/dist/api-contract/src/storefront/seo.js +132 -0
- package/dist/api-contract/src/storefront/shop.d.ts +2 -0
- package/dist/api-contract/src/storefront/shop.js +101 -0
- package/dist/api-contract/src/taxonomy.js +5 -0
- package/dist/api-contract/src/text.js +15 -0
- package/dist/api-contract/src/theme-documents.js +13 -0
- package/dist/api-contract/src/theme-translations.d.ts +14 -0
- package/dist/api-contract/src/theme-translations.js +30 -0
- package/dist/api-contract/src/video.js +19 -0
- package/dist/availability.d.ts +6 -3
- package/dist/availability.js +11 -5
- package/dist/blog.d.ts +53 -59
- package/dist/blog.js +197 -497
- package/dist/cache.d.ts +5 -6
- package/dist/cache.js +1 -2
- package/dist/canonical-host.d.ts +4 -6
- package/dist/canonical-host.js +5 -6
- package/dist/card.js +159 -0
- package/dist/cart-customer.d.ts +1 -3
- package/dist/cart-customer.js +64 -105
- package/dist/cart-mutations.d.ts +43 -77
- package/dist/cart-mutations.js +106 -232
- package/dist/cart-recommendations.d.ts +1 -3
- package/dist/cart-recommendations.js +1 -2
- package/dist/cart-session.d.ts +1 -3
- package/dist/cart-session.js +1 -2
- package/dist/cart.d.ts +63 -224
- package/dist/cart.js +70 -197
- package/dist/checkout.d.ts +13 -17
- package/dist/checkout.js +75 -101
- package/dist/coalesce.js +57 -0
- package/dist/collection.d.ts +89 -298
- package/dist/collection.js +210 -656
- package/dist/contact.d.ts +20 -10
- package/dist/contact.js +36 -30
- package/dist/content-version.d.ts +37 -21
- package/dist/content-version.js +64 -42
- package/dist/contract-kit/src/client.d.ts +12 -0
- package/dist/contract-kit/src/client.js +156 -0
- package/dist/contract-kit/src/errors.d.ts +1 -0
- package/dist/contract-kit/src/errors.js +81 -0
- package/dist/contract-kit/src/ids.d.ts +1 -0
- package/dist/contract-kit/src/ids.js +118 -0
- package/dist/contract-kit/src/index.d.ts +7 -0
- package/dist/contract-kit/src/money.d.ts +1 -0
- package/dist/contract-kit/src/money.js +10 -0
- package/dist/contract-kit/src/pagination.d.ts +1 -0
- package/dist/contract-kit/src/procedure.d.ts +69 -0
- package/dist/contract-kit/src/procedure.js +16 -0
- package/dist/contract-kit/src/realtime.d.ts +1 -0
- package/dist/cookie-secret.js +1 -2
- package/dist/csrf.js +1 -2
- package/dist/customer-handoff.d.ts +1 -3
- package/dist/customer-handoff.js +10 -25
- package/dist/customer-session.d.ts +1 -3
- package/dist/customer-session.js +1 -2
- package/dist/customer.d.ts +2 -3
- package/dist/customer.js +27 -44
- package/dist/files.d.ts +49 -10
- package/dist/files.js +106 -89
- package/dist/fonts.d.ts +3 -5
- package/dist/fonts.js +16 -35
- package/dist/html.d.ts +1 -3
- package/dist/html.js +1 -2
- package/dist/liquid.d.ts +4 -10
- package/dist/liquid.js +25 -32
- package/dist/listing.js +79 -0
- package/dist/marketing-cookies.d.ts +1 -3
- package/dist/marketing-cookies.js +1 -2
- package/dist/menu.d.ts +46 -155
- package/dist/menu.js +51 -61
- package/dist/metafields.d.ts +9 -5
- package/dist/metafields.js +10 -38
- package/dist/metaobject.d.ts +10 -5
- package/dist/metaobject.js +43 -66
- package/dist/money.d.ts +7 -0
- package/dist/money.js +18 -0
- package/dist/newsletter.d.ts +19 -10
- package/dist/newsletter.js +31 -25
- package/dist/page.d.ts +13 -17
- package/dist/page.js +49 -105
- package/dist/password-session.d.ts +1 -3
- package/dist/password-session.js +1 -2
- package/dist/password.d.ts +25 -18
- package/dist/password.js +41 -59
- package/dist/policy.d.ts +7 -7
- package/dist/policy.js +19 -55
- package/dist/product.d.ts +42 -67
- package/dist/product.js +144 -644
- package/dist/read-ahead.d.ts +18 -0
- package/dist/read-ahead.js +32 -0
- package/dist/recommendations.d.ts +6 -12
- package/dist/recommendations.js +36 -60
- package/dist/review.d.ts +134 -94
- package/dist/review.js +257 -469
- package/dist/search.d.ts +59 -64
- package/dist/search.js +170 -469
- package/dist/seo-context.d.ts +1 -3
- package/dist/seo-context.js +4 -5
- package/dist/seo-documents.d.ts +50 -0
- package/dist/seo-documents.js +149 -0
- package/dist/shop-seo.d.ts +3 -5
- package/dist/shop-seo.js +7 -26
- package/dist/shop.d.ts +38 -42
- package/dist/shop.js +37 -51
- package/dist/store-availability.d.ts +12 -14
- package/dist/store-availability.js +18 -56
- package/dist/storefront.js +199 -0
- package/dist/structured-data.d.ts +3 -28
- package/dist/structured-data.js +19 -49
- package/dist/trace.js +1 -2
- package/dist/translations.d.ts +26 -31
- package/dist/translations.js +55 -28
- package/package.json +16 -14
- package/dist/graphql-env.d.ts +0 -22778
- package/dist/graphql.d.ts +0 -64
- package/dist/graphql.js +0 -344
- package/dist/schema.storefront.graphql +0 -10483
- package/dist/seo-proxy.d.ts +0 -11
- package/dist/seo-proxy.js +0 -26
package/dist/cart.d.ts
CHANGED
|
@@ -1,246 +1,85 @@
|
|
|
1
|
+
import { StorefrontCart } from "./api-contract/src/storefront/cart.js";
|
|
2
|
+
import "./api-contract/src/storefront/index.js";
|
|
1
3
|
import { ImageFileInfo } from "./files.js";
|
|
2
|
-
import { FragmentOf } from "gql.tada";
|
|
3
4
|
import { Money } from "@shop-on/theme-runtime/money";
|
|
4
|
-
//#region src/cart.d.ts
|
|
5
|
-
export type CartLineAttribute = {
|
|
6
|
-
name: string;
|
|
7
|
-
value: string;
|
|
8
|
-
visible: boolean;
|
|
9
|
-
};
|
|
10
5
|
export type CartLine = {
|
|
11
6
|
id: string;
|
|
12
7
|
quantity: number;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
8
|
+
/** The buyer's line properties (gift message, engraving, …): the visible ones only. */
|
|
9
|
+
customAttributes: {
|
|
10
|
+
name: string;
|
|
11
|
+
value: string;
|
|
12
|
+
}[];
|
|
13
|
+
/** The variant's price now. */
|
|
14
|
+
unitPrice: Money;
|
|
15
|
+
/** Its compare-at price, only while it is above the price (on sale). */
|
|
16
|
+
compareAtPrice: Money | null;
|
|
17
|
+
/** The unit price × quantity. */
|
|
18
|
+
subtotal: Money;
|
|
19
|
+
/** What the cart's discounts take off this line. */
|
|
20
|
+
discount: Money;
|
|
21
|
+
/** Whether the whole cart's demand on this variant can be sold now. */
|
|
22
|
+
available: boolean;
|
|
23
|
+
/** Units the shop can sell; null when nothing bounds them. */
|
|
24
|
+
quantityAvailable: number | null;
|
|
20
25
|
variant: {
|
|
21
26
|
id: string;
|
|
27
|
+
/** Its option values joined by " / "; empty without options. */
|
|
22
28
|
title: string;
|
|
23
29
|
sku: string | null;
|
|
24
|
-
/**
|
|
25
|
-
|
|
26
|
-
* "Size: XS / Color: Black" instead of one opaque "XS / Black" string.
|
|
27
|
-
* Empty for a product with no options. Optional on the type for the same
|
|
28
|
-
* reason as `customAttributes` — existing fixtures predate the field. */
|
|
29
|
-
selectedOptions?: {
|
|
30
|
+
/** `Size` → `XS`: a row prints these rather than the opaque title. */
|
|
31
|
+
selectedOptions: {
|
|
30
32
|
name: string;
|
|
31
33
|
value: string;
|
|
32
34
|
}[];
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
|
|
42
|
-
|
|
35
|
+
/** Whether the line ships, which a free-shipping threshold counts. */
|
|
36
|
+
requiresShipping: boolean;
|
|
37
|
+
image: ImageFileInfo | null;
|
|
38
|
+
};
|
|
39
|
+
product: {
|
|
40
|
+
id: string;
|
|
41
|
+
handle: string;
|
|
42
|
+
/** `/products/<handle>`. */
|
|
43
|
+
url: string;
|
|
44
|
+
title: string;
|
|
45
|
+
vendor: string | null;
|
|
46
|
+
/** The product's first image: a row's fallback when the variant has none. */
|
|
43
47
|
image: ImageFileInfo | null;
|
|
44
|
-
product: {
|
|
45
|
-
id: string;
|
|
46
|
-
handle: string;
|
|
47
|
-
title: string;
|
|
48
|
-
/** Merchant vendor, null when unset. Cart UIs that offer a "show vendor"
|
|
49
|
-
* setting read it off the line rather than refetching the product. */
|
|
50
|
-
vendor: string | null;
|
|
51
|
-
/** Product's featured media. Cart UIs use this as a fallback when the
|
|
52
|
-
* variant carries no media of its own (common for single-image listings
|
|
53
|
-
* where merchants only attach a photo to the product, not each variant). */
|
|
54
|
-
image: ImageFileInfo | null;
|
|
55
|
-
};
|
|
56
48
|
};
|
|
57
|
-
};
|
|
58
|
-
export type CartDiscountAllocation = {
|
|
59
|
-
/** Non-null for line-item allocations — matches `CartLine.id`. Null for
|
|
60
|
-
* order-level allocations (whole-cart deductions). Shipping allocations
|
|
61
|
-
* can't appear at the cart layer; the cart never resolves a shipping rate. */
|
|
62
|
-
targetLineItemId: string | null;
|
|
63
|
-
amount: Money;
|
|
64
49
|
};
|
|
65
50
|
export type CartDiscountApplication = {
|
|
66
|
-
|
|
51
|
+
source: "code" | "automatic";
|
|
52
|
+
class: "product" | "order" | "shipping";
|
|
67
53
|
title: string;
|
|
68
54
|
code: string | null;
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
55
|
+
amount: Money;
|
|
56
|
+
/** By line; `lineId` null for a deduction off the whole order. */
|
|
57
|
+
allocations: {
|
|
58
|
+
lineId: string | null;
|
|
59
|
+
amount: Money;
|
|
60
|
+
}[];
|
|
73
61
|
};
|
|
74
|
-
export type CartData = {
|
|
75
|
-
id: string;
|
|
76
|
-
totalQuantity: number;
|
|
77
|
-
subtotalAmount: Money;
|
|
78
|
-
/** Automatic-discount preview total (product + order class). Cart never
|
|
79
|
-
* carries a shipping-class discount preview — no rate is selected yet,
|
|
80
|
-
* so the API's `ShopCart.discountAmount` excludes shipping by design.
|
|
81
|
-
* Zero when no discount applies. */
|
|
82
|
-
discountAmount: Money;
|
|
83
|
-
discountApplications: CartDiscountApplication[];
|
|
62
|
+
export type CartData = StorefrontCartFields & {
|
|
84
63
|
lines: CartLine[];
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
};
|
|
91
|
-
export declare const CartFields: import("gql.tada").TadaDocumentNode<{
|
|
92
|
-
attachedToCurrentCustomer: boolean;
|
|
93
|
-
discountAmount: {
|
|
94
|
-
amount: string;
|
|
95
|
-
currencyCode: "CNY" | "EUR" | "GBP" | "JPY" | "KRW" | "MNT" | "RUB" | "USD";
|
|
96
|
-
};
|
|
97
|
-
discountApplications: {
|
|
98
|
-
allocatedAmount: {
|
|
99
|
-
amount: string;
|
|
100
|
-
currencyCode: "CNY" | "EUR" | "GBP" | "JPY" | "KRW" | "MNT" | "RUB" | "USD";
|
|
101
|
-
};
|
|
102
|
-
allocations: {
|
|
103
|
-
amount: {
|
|
104
|
-
amount: string;
|
|
105
|
-
currencyCode: "CNY" | "EUR" | "GBP" | "JPY" | "KRW" | "MNT" | "RUB" | "USD";
|
|
106
|
-
};
|
|
107
|
-
targetLineItemId: string | null;
|
|
108
|
-
}[];
|
|
109
|
-
code: string | null;
|
|
110
|
-
id: string | null;
|
|
111
|
-
source: "AUTOMATIC" | "CODE" | "MANUAL";
|
|
112
|
-
targetType: "LINE_ITEM" | "ORDER" | "SHIPPING";
|
|
113
|
-
title: string;
|
|
114
|
-
}[];
|
|
115
|
-
expiresAt: string;
|
|
116
|
-
hasCustomer: boolean;
|
|
117
|
-
id: string;
|
|
118
|
-
lines: {
|
|
119
|
-
nodes: {
|
|
120
|
-
cost: {
|
|
121
|
-
amount: string;
|
|
122
|
-
currencyCode: "CNY" | "EUR" | "GBP" | "JPY" | "KRW" | "MNT" | "RUB" | "USD";
|
|
123
|
-
};
|
|
124
|
-
customAttributes: {
|
|
125
|
-
name: string;
|
|
126
|
-
value: string;
|
|
127
|
-
visible: boolean;
|
|
128
|
-
}[];
|
|
129
|
-
id: string;
|
|
130
|
-
quantity: number;
|
|
131
|
-
variant: {
|
|
132
|
-
availableForSale: boolean;
|
|
133
|
-
compareAtV2: {
|
|
134
|
-
amount: string;
|
|
135
|
-
currencyCode: "CNY" | "EUR" | "GBP" | "JPY" | "KRW" | "MNT" | "RUB" | "USD";
|
|
136
|
-
} | null;
|
|
137
|
-
featuredMedia: {
|
|
138
|
-
__typename: "ShopFont";
|
|
139
|
-
alt: string | null;
|
|
140
|
-
id: string;
|
|
141
|
-
} | {
|
|
142
|
-
__typename: "ShopMediaImage";
|
|
143
|
-
alt: string | null;
|
|
144
|
-
focalPoint: {
|
|
145
|
-
x: number;
|
|
146
|
-
y: number;
|
|
147
|
-
} | null;
|
|
148
|
-
height: number | null;
|
|
149
|
-
id: string;
|
|
150
|
-
url: string | null;
|
|
151
|
-
url2x: string | null;
|
|
152
|
-
width: number | null;
|
|
153
|
-
} | {
|
|
154
|
-
__typename: "ShopVideo";
|
|
155
|
-
alt: string | null;
|
|
156
|
-
id: string;
|
|
157
|
-
} | null;
|
|
158
|
-
id: string;
|
|
159
|
-
priceV2: {
|
|
160
|
-
amount: string;
|
|
161
|
-
currencyCode: "CNY" | "EUR" | "GBP" | "JPY" | "KRW" | "MNT" | "RUB" | "USD";
|
|
162
|
-
};
|
|
163
|
-
product: {
|
|
164
|
-
featuredMedia: {
|
|
165
|
-
__typename: "ShopFont";
|
|
166
|
-
alt: string | null;
|
|
167
|
-
id: string;
|
|
168
|
-
} | {
|
|
169
|
-
__typename: "ShopMediaImage";
|
|
170
|
-
alt: string | null;
|
|
171
|
-
focalPoint: {
|
|
172
|
-
x: number;
|
|
173
|
-
y: number;
|
|
174
|
-
} | null;
|
|
175
|
-
height: number | null;
|
|
176
|
-
id: string;
|
|
177
|
-
url: string | null;
|
|
178
|
-
url2x: string | null;
|
|
179
|
-
width: number | null;
|
|
180
|
-
} | {
|
|
181
|
-
__typename: "ShopVideo";
|
|
182
|
-
alt: string | null;
|
|
183
|
-
id: string;
|
|
184
|
-
} | null;
|
|
185
|
-
handle: string;
|
|
186
|
-
id: string;
|
|
187
|
-
title: string;
|
|
188
|
-
vendor: string | null;
|
|
189
|
-
};
|
|
190
|
-
quantityAvailable: number | null;
|
|
191
|
-
requiresShipping: boolean;
|
|
192
|
-
selectedOptions: {
|
|
193
|
-
name: string;
|
|
194
|
-
value: string;
|
|
195
|
-
}[];
|
|
196
|
-
sku: string | null;
|
|
197
|
-
title: string;
|
|
198
|
-
};
|
|
199
|
-
}[];
|
|
200
|
-
};
|
|
201
|
-
note: string | null;
|
|
202
|
-
subtotalAmount: {
|
|
203
|
-
amount: string;
|
|
204
|
-
currencyCode: "CNY" | "EUR" | "GBP" | "JPY" | "KRW" | "MNT" | "RUB" | "USD";
|
|
205
|
-
};
|
|
206
|
-
totalQuantity: number;
|
|
207
|
-
}, {}, {
|
|
208
|
-
fragment: "CartFields";
|
|
209
|
-
on: "ShopCart";
|
|
210
|
-
masked: true;
|
|
211
|
-
}>;
|
|
212
|
-
/** Exported because a theme's `resolveCart` needs to forward a customer-session
|
|
213
|
-
* token via the request helper's third arg (the package-level
|
|
214
|
-
* `fetchCartByToken` is anonymous-only). Anonymous callers should prefer
|
|
215
|
-
* `fetchCartByToken` — it owns the error swallowing + decode for that path. */
|
|
216
|
-
export declare const CartByTokenQuery: import("gql.tada").TadaDocumentNode<{
|
|
217
|
-
cart: {
|
|
218
|
-
[$tada.fragmentRefs]: {
|
|
219
|
-
CartFields: "ShopCart";
|
|
220
|
-
};
|
|
221
|
-
} | null;
|
|
222
|
-
}, {
|
|
223
|
-
cartToken: string;
|
|
224
|
-
}, void>;
|
|
225
|
-
export type CartReadResult = {
|
|
226
|
-
cart: CartData;
|
|
227
|
-
attachedToCurrentCustomer: boolean;
|
|
228
|
-
hasCustomer: boolean;
|
|
229
|
-
expiresAt: string;
|
|
64
|
+
discountApplications: CartDiscountApplication[];
|
|
65
|
+
subtotal: Money;
|
|
66
|
+
discount: Money;
|
|
67
|
+
vat: Money;
|
|
68
|
+
total: Money;
|
|
230
69
|
};
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
*
|
|
236
|
-
*
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
*
|
|
240
|
-
*
|
|
241
|
-
*
|
|
242
|
-
*
|
|
243
|
-
|
|
70
|
+
type StorefrontCartFields = Pick<StorefrontCart, "id" | "note" | "totalQuantity" | "discountCode" | "taxesIncluded" | "warnings">;
|
|
71
|
+
/** The api's cart as a theme reads it. */
|
|
72
|
+
export declare function toCart(cart: StorefrontCart): CartData;
|
|
73
|
+
/** Whether a call failed because its token opens no cart (unknown, expired,
|
|
74
|
+
* placed or merged): the theme's signal to drop its cookie. A NOT_FOUND that
|
|
75
|
+
* names a variant or a line leaves the cart as it was. */
|
|
76
|
+
export declare function isCartGone(error: unknown): boolean;
|
|
77
|
+
/**
|
|
78
|
+
* The cart a token opens, three ways: `not_found` when the api says it opens
|
|
79
|
+
* none (the caller clears its cookie), `error` on any other failure (the
|
|
80
|
+
* caller keeps its cookie: clearing on a blip would orphan a valid cart).
|
|
81
|
+
* A misconfigured storefront still throws.
|
|
82
|
+
*/
|
|
244
83
|
export type CartTokenReadResult = {
|
|
245
84
|
status: "ok";
|
|
246
85
|
cart: CartData;
|
|
@@ -249,5 +88,5 @@ export type CartTokenReadResult = {
|
|
|
249
88
|
} | {
|
|
250
89
|
status: "error";
|
|
251
90
|
};
|
|
252
|
-
export declare function readCartByToken(
|
|
253
|
-
|
|
91
|
+
export declare function readCartByToken(token: string, locale?: string): Promise<CartTokenReadResult>;
|
|
92
|
+
export {};
|
package/dist/cart.js
CHANGED
|
@@ -1,209 +1,82 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
note
|
|
10
|
-
expiresAt
|
|
11
|
-
hasCustomer
|
|
12
|
-
attachedToCurrentCustomer
|
|
13
|
-
subtotalAmount {
|
|
14
|
-
amount
|
|
15
|
-
currencyCode
|
|
16
|
-
}
|
|
17
|
-
discountAmount {
|
|
18
|
-
amount
|
|
19
|
-
currencyCode
|
|
20
|
-
}
|
|
21
|
-
discountApplications {
|
|
22
|
-
id
|
|
23
|
-
title
|
|
24
|
-
code
|
|
25
|
-
source
|
|
26
|
-
targetType
|
|
27
|
-
allocatedAmount {
|
|
28
|
-
amount
|
|
29
|
-
currencyCode
|
|
30
|
-
}
|
|
31
|
-
allocations {
|
|
32
|
-
targetLineItemId
|
|
33
|
-
amount {
|
|
34
|
-
amount
|
|
35
|
-
currencyCode
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
lines(first: 25) {
|
|
40
|
-
nodes {
|
|
41
|
-
id
|
|
42
|
-
quantity
|
|
43
|
-
cost {
|
|
44
|
-
amount
|
|
45
|
-
currencyCode
|
|
46
|
-
}
|
|
47
|
-
customAttributes {
|
|
48
|
-
name
|
|
49
|
-
value
|
|
50
|
-
visible
|
|
51
|
-
}
|
|
52
|
-
variant {
|
|
53
|
-
id
|
|
54
|
-
title
|
|
55
|
-
sku
|
|
56
|
-
selectedOptions {
|
|
57
|
-
name
|
|
58
|
-
value
|
|
59
|
-
}
|
|
60
|
-
priceV2 {
|
|
61
|
-
amount
|
|
62
|
-
currencyCode
|
|
63
|
-
}
|
|
64
|
-
compareAtV2 {
|
|
65
|
-
amount
|
|
66
|
-
currencyCode
|
|
67
|
-
}
|
|
68
|
-
availableForSale
|
|
69
|
-
quantityAvailable
|
|
70
|
-
requiresShipping
|
|
71
|
-
featuredMedia {
|
|
72
|
-
__typename
|
|
73
|
-
id
|
|
74
|
-
alt
|
|
75
|
-
... on ShopMediaImage {
|
|
76
|
-
url(transform: { maxWidth: 128 })
|
|
77
|
-
url2x: url(transform: { maxWidth: 128, scale: 2 })
|
|
78
|
-
width
|
|
79
|
-
height
|
|
80
|
-
focalPoint {
|
|
81
|
-
x
|
|
82
|
-
y
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
product {
|
|
87
|
-
id
|
|
88
|
-
handle
|
|
89
|
-
title
|
|
90
|
-
vendor
|
|
91
|
-
featuredMedia {
|
|
92
|
-
__typename
|
|
93
|
-
id
|
|
94
|
-
alt
|
|
95
|
-
... on ShopMediaImage {
|
|
96
|
-
url(transform: { maxWidth: 128 })
|
|
97
|
-
url2x: url(transform: { maxWidth: 128, scale: 2 })
|
|
98
|
-
width
|
|
99
|
-
height
|
|
100
|
-
focalPoint {
|
|
101
|
-
x
|
|
102
|
-
y
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
`);
|
|
112
|
-
/** Exported because a theme's `resolveCart` needs to forward a customer-session
|
|
113
|
-
* token via the request helper's third arg (the package-level
|
|
114
|
-
* `fetchCartByToken` is anonymous-only). Anonymous callers should prefer
|
|
115
|
-
* `fetchCartByToken` — it owns the error swallowing + decode for that path. */
|
|
116
|
-
const CartByTokenQuery = graphql(`
|
|
117
|
-
query CartByToken($cartToken: String!) {
|
|
118
|
-
cart(cartToken: $cartToken) {
|
|
119
|
-
...CartFields
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
`, [CartFields]);
|
|
123
|
-
function toMoney(m) {
|
|
124
|
-
return {
|
|
125
|
-
amount: Number(m.amount),
|
|
126
|
-
currencyCode: m.currencyCode
|
|
127
|
-
};
|
|
1
|
+
import { imageFileInfo } from "./files.js";
|
|
2
|
+
import { toMoney } from "./money.js";
|
|
3
|
+
import { StorefrontConfigError, errorCode, storefront } from "./storefront.js";
|
|
4
|
+
// src/cart.ts
|
|
5
|
+
/** The width a cart row draws its thumbnail at. */
|
|
6
|
+
const CART_IMAGE_WIDTH = 128;
|
|
7
|
+
function toImage(image) {
|
|
8
|
+
return image ? imageFileInfo(image, CART_IMAGE_WIDTH) : null;
|
|
128
9
|
}
|
|
129
|
-
|
|
130
|
-
|
|
10
|
+
/** The api's cart as a theme reads it. */
|
|
11
|
+
function toCart(cart) {
|
|
131
12
|
return {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
vendor: l.variant.product.vendor ?? null,
|
|
181
|
-
image: productFile?.kind === "image" ? productFile : null
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
};
|
|
185
|
-
})
|
|
186
|
-
},
|
|
187
|
-
attachedToCurrentCustomer: data.attachedToCurrentCustomer,
|
|
188
|
-
hasCustomer: data.hasCustomer,
|
|
189
|
-
expiresAt: data.expiresAt
|
|
13
|
+
id: cart.id,
|
|
14
|
+
note: cart.note,
|
|
15
|
+
totalQuantity: cart.totalQuantity,
|
|
16
|
+
discountCode: cart.discountCode,
|
|
17
|
+
taxesIncluded: cart.taxesIncluded,
|
|
18
|
+
warnings: cart.warnings,
|
|
19
|
+
subtotal: toMoney(cart.subtotal),
|
|
20
|
+
discount: toMoney(cart.discount),
|
|
21
|
+
vat: toMoney(cart.vat),
|
|
22
|
+
total: toMoney(cart.total),
|
|
23
|
+
discountApplications: cart.discountApplications.map((application) => ({
|
|
24
|
+
source: application.source,
|
|
25
|
+
class: application.class,
|
|
26
|
+
title: application.title,
|
|
27
|
+
code: application.code,
|
|
28
|
+
amount: toMoney(application.amount),
|
|
29
|
+
allocations: application.allocations.map((a) => ({
|
|
30
|
+
lineId: a.lineId,
|
|
31
|
+
amount: toMoney(a.amount)
|
|
32
|
+
}))
|
|
33
|
+
})),
|
|
34
|
+
lines: cart.lines.map((line) => ({
|
|
35
|
+
id: line.id,
|
|
36
|
+
quantity: line.quantity,
|
|
37
|
+
customAttributes: line.customAttributes,
|
|
38
|
+
unitPrice: toMoney(line.unitPrice),
|
|
39
|
+
compareAtPrice: line.compareAtPrice === null ? null : toMoney(line.compareAtPrice),
|
|
40
|
+
subtotal: toMoney(line.subtotal),
|
|
41
|
+
discount: toMoney(line.discount),
|
|
42
|
+
available: line.available,
|
|
43
|
+
quantityAvailable: line.quantityAvailable,
|
|
44
|
+
variant: {
|
|
45
|
+
id: line.variant.id,
|
|
46
|
+
title: line.variant.title,
|
|
47
|
+
sku: line.variant.sku,
|
|
48
|
+
selectedOptions: line.variant.selectedOptions,
|
|
49
|
+
requiresShipping: line.variant.requiresShipping,
|
|
50
|
+
image: toImage(line.variant.image)
|
|
51
|
+
},
|
|
52
|
+
product: {
|
|
53
|
+
id: line.product.id,
|
|
54
|
+
handle: line.product.handle,
|
|
55
|
+
url: line.product.url,
|
|
56
|
+
title: line.product.title,
|
|
57
|
+
vendor: line.product.vendor,
|
|
58
|
+
image: toImage(line.product.image)
|
|
59
|
+
}
|
|
60
|
+
}))
|
|
190
61
|
};
|
|
191
62
|
}
|
|
192
|
-
|
|
193
|
-
|
|
63
|
+
/** Whether a call failed because its token opens no cart (unknown, expired,
|
|
64
|
+
* placed or merged): the theme's signal to drop its cookie. A NOT_FOUND that
|
|
65
|
+
* names a variant or a line leaves the cart as it was. */
|
|
66
|
+
function isCartGone(error) {
|
|
67
|
+
return errorCode(error) === "NOT_FOUND" && error.data?.resource === "cart";
|
|
194
68
|
}
|
|
195
|
-
async function readCartByToken(
|
|
69
|
+
async function readCartByToken(token, locale) {
|
|
196
70
|
try {
|
|
197
|
-
const result = await request(CartByTokenQuery, { cartToken }, locale ? { acceptLanguage: locale } : void 0);
|
|
198
|
-
if (!result.cart) return { status: "not_found" };
|
|
199
71
|
return {
|
|
200
72
|
status: "ok",
|
|
201
|
-
cart:
|
|
73
|
+
cart: toCart(await storefront(locale).cart.get({ token }))
|
|
202
74
|
};
|
|
203
|
-
} catch (
|
|
204
|
-
|
|
75
|
+
} catch (error) {
|
|
76
|
+
if (error instanceof StorefrontConfigError) throw error;
|
|
77
|
+
if (isCartGone(error)) return { status: "not_found" };
|
|
78
|
+
console.warn(`[readCartByToken] failed: ${errorCode(error) ?? String(error)}`);
|
|
205
79
|
return { status: "error" };
|
|
206
80
|
}
|
|
207
81
|
}
|
|
208
|
-
|
|
209
|
-
export { CartByTokenQuery, CartFields, decodeCart, readCartByToken, readCartFields };
|
|
82
|
+
export { isCartGone, readCartByToken, toCart };
|
package/dist/checkout.d.ts
CHANGED
|
@@ -1,25 +1,21 @@
|
|
|
1
|
-
//#region src/checkout.d.ts
|
|
2
1
|
export type CheckoutHandoffResult = {
|
|
3
2
|
ok: true;
|
|
4
3
|
redirectTo: string;
|
|
5
4
|
} | {
|
|
6
5
|
ok: false;
|
|
7
|
-
reason: "no_cart"
|
|
6
|
+
reason: "no_cart";
|
|
8
7
|
};
|
|
8
|
+
/** Whether this buyer has a cart to check out, and where to go with it: the theme's `/checkout`. */
|
|
9
|
+
export declare function checkoutEntry(): Promise<CheckoutHandoffResult>;
|
|
9
10
|
/**
|
|
10
|
-
* The theme's
|
|
11
|
-
* a
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* returns the buyer here with one. Mints nothing.
|
|
16
|
-
* - A state: mint the cart handoff with it (`mintCheckoutHandoff`).
|
|
17
|
-
*
|
|
18
|
-
* The customer-session token is injected: forwarded as `X-Customer-Session` on
|
|
19
|
-
* the mint so Rails folds the buyer into the handoff payload in one trip.
|
|
11
|
+
* The theme's `GET /{-$locale}/checkout`. A preview (`?preview`) is a 404;
|
|
12
|
+
* a buyer with no cart, an unknown or expired one, or an empty one goes to
|
|
13
|
+
* the storefront's home; a cart already being paid goes to the checkout
|
|
14
|
+
* app, whose cookie still opens its checkout. Anything else the api refuses
|
|
15
|
+
* is thrown (the theme's 500).
|
|
20
16
|
*/
|
|
21
|
-
export declare function
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
17
|
+
export declare function handleCheckoutGet(request: Request, { locale }: {
|
|
18
|
+
locale?: string;
|
|
19
|
+
}): Promise<Response>;
|
|
20
|
+
/** The page that POSTs the checkout token, and a signed-in buyer's handoff token, to the checkout app's `/begin`. Pure. */
|
|
21
|
+
export declare function renderCheckoutHandoffForm(beginUrl: string, token: string, customerHandoff: string | null): string;
|