@shop-on/theme-server 0.9.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-mutations.js
CHANGED
|
@@ -1,273 +1,147 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const CartLinesAddMutation = graphql(`
|
|
21
|
-
mutation CartLinesAdd($cartToken: String!, $lines: [CartLineInput!]!) {
|
|
22
|
-
cartLinesAdd(input: { cartToken: $cartToken, lines: $lines }) {
|
|
23
|
-
cart {
|
|
24
|
-
...CartFields
|
|
25
|
-
}
|
|
26
|
-
userErrors {
|
|
27
|
-
code
|
|
28
|
-
field
|
|
29
|
-
message
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
`, [CartFields]);
|
|
34
|
-
const CartLinesUpdateMutation = graphql(`
|
|
35
|
-
mutation CartLinesUpdate($cartToken: String!, $lines: [CartLineUpdateInput!]!) {
|
|
36
|
-
cartLinesUpdate(input: { cartToken: $cartToken, lines: $lines }) {
|
|
37
|
-
cart {
|
|
38
|
-
...CartFields
|
|
39
|
-
}
|
|
40
|
-
userErrors {
|
|
41
|
-
code
|
|
42
|
-
field
|
|
43
|
-
message
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
`, [CartFields]);
|
|
48
|
-
const CartLinesRemoveMutation = graphql(`
|
|
49
|
-
mutation CartLinesRemove($cartToken: String!, $lineIds: [ID!]!) {
|
|
50
|
-
cartLinesRemove(input: { cartToken: $cartToken, lineIds: $lineIds }) {
|
|
51
|
-
cart {
|
|
52
|
-
...CartFields
|
|
53
|
-
}
|
|
54
|
-
userErrors {
|
|
55
|
-
code
|
|
56
|
-
field
|
|
57
|
-
message
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
`, [CartFields]);
|
|
62
|
-
const CartNoteUpdateMutation = graphql(`
|
|
63
|
-
mutation CartNoteUpdate($cartToken: String!, $note: String) {
|
|
64
|
-
cartNoteUpdate(input: { cartToken: $cartToken, note: $note }) {
|
|
65
|
-
cart {
|
|
66
|
-
...CartFields
|
|
67
|
-
}
|
|
68
|
-
userErrors {
|
|
69
|
-
code
|
|
70
|
-
field
|
|
71
|
-
message
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
`, [CartFields]);
|
|
76
|
-
function firstError(errors) {
|
|
77
|
-
return errors[0] ?? {
|
|
78
|
-
code: "UNKNOWN",
|
|
79
|
-
field: null,
|
|
80
|
-
message: "Cart action failed."
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
function unwrapCartPayload(payload) {
|
|
84
|
-
if (!payload) return {
|
|
1
|
+
import { liteId } from "./api-contract/src/ids.js";
|
|
2
|
+
import { isCartGone, toCart } from "./cart.js";
|
|
3
|
+
import { StorefrontConfigError, buyerStorefront, errorCode, storefront } from "./storefront.js";
|
|
4
|
+
// src/cart-mutations.ts
|
|
5
|
+
async function refused(error, session, op) {
|
|
6
|
+
if (error instanceof StorefrontConfigError) throw error;
|
|
7
|
+
const message = error instanceof Error ? error.message : "Cart action failed.";
|
|
8
|
+
if (isCartGone(error)) {
|
|
9
|
+
await session?.clear();
|
|
10
|
+
return {
|
|
11
|
+
ok: false,
|
|
12
|
+
code: "NOT_FOUND",
|
|
13
|
+
resource: "cart",
|
|
14
|
+
message
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
const code = errorCode(error);
|
|
18
|
+
const data = error.data;
|
|
19
|
+
if (code === "NOT_FOUND") return {
|
|
85
20
|
ok: false,
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
message: "Cart action failed."
|
|
90
|
-
}
|
|
21
|
+
code,
|
|
22
|
+
resource: typeof data?.resource === "string" ? data.resource : null,
|
|
23
|
+
message
|
|
91
24
|
};
|
|
92
|
-
if (
|
|
25
|
+
if (code === "PRECONDITION_FAILED" && data?.condition === "sales.cart_paying") return {
|
|
93
26
|
ok: false,
|
|
94
|
-
|
|
27
|
+
code: "CART_PAYING",
|
|
28
|
+
resource: null,
|
|
29
|
+
message
|
|
95
30
|
};
|
|
96
|
-
if (
|
|
31
|
+
if (code === "INSUFFICIENT_INVENTORY" || code === "LIMIT_EXCEEDED" || code === "VALIDATION_FAILED" || code === "RATE_LIMITED") return {
|
|
97
32
|
ok: false,
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
message: "Cart action failed."
|
|
102
|
-
}
|
|
33
|
+
code,
|
|
34
|
+
resource: null,
|
|
35
|
+
message
|
|
103
36
|
};
|
|
37
|
+
console.warn(`[cart] ${op} failed: ${code ?? String(error)}`);
|
|
104
38
|
return {
|
|
105
|
-
ok: true,
|
|
106
|
-
cart: payload.cart
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
function isCartTokenNotFound(error) {
|
|
110
|
-
return error.code === "NOT_FOUND" && error.field === "cartToken";
|
|
111
|
-
}
|
|
112
|
-
function surfaceClientError(err, op) {
|
|
113
|
-
console.warn(`[cart] ${op} failed:`, err);
|
|
114
|
-
if (err instanceof ClientError) return {
|
|
115
39
|
ok: false,
|
|
116
40
|
code: "REQUEST_FAILED",
|
|
117
|
-
|
|
118
|
-
message
|
|
119
|
-
};
|
|
120
|
-
return {
|
|
121
|
-
ok: false,
|
|
122
|
-
code: "UNKNOWN",
|
|
123
|
-
field: null,
|
|
124
|
-
message: "Cart action failed."
|
|
41
|
+
resource: null,
|
|
42
|
+
message
|
|
125
43
|
};
|
|
126
44
|
}
|
|
127
|
-
|
|
128
|
-
* cart is born attached to that customer. Returns the plaintext token + the
|
|
129
|
-
* server-authoritative `expiresAt` so the caller can write its cookie; never
|
|
130
|
-
* touches the cookie itself. */
|
|
131
|
-
async function mintCart(customerToken) {
|
|
45
|
+
async function write(session, op, call) {
|
|
132
46
|
try {
|
|
133
|
-
const payload = (await request(CartCreateMutation, {}, customerToken ? { customerSessionToken: customerToken } : void 0)).cartCreate;
|
|
134
|
-
const unwrapped = unwrapCartPayload(payload);
|
|
135
|
-
if (!unwrapped.ok || !payload?.cartToken) return {
|
|
136
|
-
ok: false,
|
|
137
|
-
...!unwrapped.ok ? unwrapped.error : {
|
|
138
|
-
code: "UNKNOWN",
|
|
139
|
-
field: null,
|
|
140
|
-
message: "Cart action failed."
|
|
141
|
-
}
|
|
142
|
-
};
|
|
143
47
|
return {
|
|
144
48
|
ok: true,
|
|
145
|
-
|
|
146
|
-
expiresAt: readCartFields(unwrapped.cart).expiresAt
|
|
49
|
+
cart: toCart(await call(storefront().cart))
|
|
147
50
|
};
|
|
148
|
-
} catch (
|
|
149
|
-
return
|
|
51
|
+
} catch (error) {
|
|
52
|
+
return refused(error, session, op);
|
|
150
53
|
}
|
|
151
54
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
if (isCartTokenNotFound(unwrapped.error)) await session.clear();
|
|
161
|
-
return {
|
|
162
|
-
ok: false,
|
|
163
|
-
...unwrapped.error
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
return {
|
|
167
|
-
ok: true,
|
|
168
|
-
cart: decodeCart(unwrapped.cart)
|
|
169
|
-
};
|
|
170
|
-
} catch (err) {
|
|
171
|
-
return surfaceClientError(err, "addToCart");
|
|
55
|
+
/** The ids a theme hands in, as the api's: one that is no id of its kind
|
|
56
|
+
* names nothing, so the call is refused as NOT_FOUND without being made. */
|
|
57
|
+
function ids(schema, refs) {
|
|
58
|
+
const parsed = [];
|
|
59
|
+
for (const ref of refs) {
|
|
60
|
+
const id = schema.safeParse(ref);
|
|
61
|
+
if (!id.success) return null;
|
|
62
|
+
parsed.push(id.data);
|
|
172
63
|
}
|
|
64
|
+
return parsed;
|
|
173
65
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
return {
|
|
184
|
-
ok: false,
|
|
185
|
-
...unwrapped.error
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
return {
|
|
189
|
-
ok: true,
|
|
190
|
-
cart: decodeCart(unwrapped.cart)
|
|
191
|
-
};
|
|
192
|
-
} catch (err) {
|
|
193
|
-
return surfaceClientError(err, "updateCartLine");
|
|
194
|
-
}
|
|
66
|
+
const VARIANT_ID = liteId("variant");
|
|
67
|
+
const LINE_ID = liteId("basket_line");
|
|
68
|
+
function unknown(resource) {
|
|
69
|
+
return {
|
|
70
|
+
ok: false,
|
|
71
|
+
code: "NOT_FOUND",
|
|
72
|
+
resource,
|
|
73
|
+
message: `No such ${resource}.`
|
|
74
|
+
};
|
|
195
75
|
}
|
|
196
|
-
|
|
197
|
-
|
|
76
|
+
/** Open a new, empty cart, the signed-in buyer's when `buyerSession` is
|
|
77
|
+
* given. Answers its token and when it expires (30 days, never extended) for
|
|
78
|
+
* the caller's cookie; never touches the cookie itself. */
|
|
79
|
+
async function mintCart(buyerSession) {
|
|
198
80
|
try {
|
|
199
|
-
const
|
|
200
|
-
cartToken: token,
|
|
201
|
-
lineIds
|
|
202
|
-
}, customerToken ? { customerSessionToken: customerToken } : void 0)).cartLinesRemove);
|
|
203
|
-
if (!unwrapped.ok) {
|
|
204
|
-
if (isCartTokenNotFound(unwrapped.error)) await session.clear();
|
|
205
|
-
return {
|
|
206
|
-
ok: false,
|
|
207
|
-
...unwrapped.error
|
|
208
|
-
};
|
|
209
|
-
}
|
|
81
|
+
const { token, cart } = await (buyerSession ? buyerStorefront(buyerSession) : storefront()).cart.create({});
|
|
210
82
|
return {
|
|
211
83
|
ok: true,
|
|
212
|
-
|
|
84
|
+
token,
|
|
85
|
+
expiresAt: cart.expiresAt
|
|
213
86
|
};
|
|
214
|
-
} catch (
|
|
215
|
-
return
|
|
87
|
+
} catch (error) {
|
|
88
|
+
return refused(error, null, "create");
|
|
216
89
|
}
|
|
217
90
|
}
|
|
91
|
+
/** Add lines, all or nothing. */
|
|
92
|
+
function addLines(args) {
|
|
93
|
+
const { session, token, lines } = args;
|
|
94
|
+
const variantIds = ids(VARIANT_ID, lines.map((l) => l.variantId));
|
|
95
|
+
if (!variantIds) return Promise.resolve(unknown("variant"));
|
|
96
|
+
return write(session, "add", (cart) => cart.lines.add({
|
|
97
|
+
token,
|
|
98
|
+
lines: lines.map((l, i) => ({
|
|
99
|
+
...l,
|
|
100
|
+
variantId: variantIds[i]
|
|
101
|
+
}))
|
|
102
|
+
}));
|
|
103
|
+
}
|
|
104
|
+
function removeLines(args) {
|
|
105
|
+
const lineIds = ids(LINE_ID, args.lineIds);
|
|
106
|
+
if (!lineIds) return Promise.resolve(unknown("cart_line"));
|
|
107
|
+
const { session, token } = args;
|
|
108
|
+
return write(session, "remove", (cart) => cart.lines.remove({
|
|
109
|
+
token,
|
|
110
|
+
lineIds
|
|
111
|
+
}));
|
|
112
|
+
}
|
|
218
113
|
/**
|
|
219
|
-
* Set
|
|
220
|
-
*
|
|
221
|
-
*
|
|
222
|
-
* constraint error. This is the op cart UIs should call for a quantity change;
|
|
223
|
-
* `updateLines` (batch) stays internal.
|
|
114
|
+
* Set one line's quantity. A quantity of 0 or less removes the line (the api
|
|
115
|
+
* takes a quantity of at least 1), so a stepper can go straight down to 0.
|
|
116
|
+
* The op cart UIs call for a quantity change.
|
|
224
117
|
*/
|
|
225
|
-
|
|
226
|
-
const { session, token,
|
|
118
|
+
function setLineQuantity(args) {
|
|
119
|
+
const { session, token, lineId, quantity } = args;
|
|
227
120
|
if (quantity <= 0) return removeLines({
|
|
228
121
|
session,
|
|
229
122
|
token,
|
|
230
|
-
customerToken,
|
|
231
123
|
lineIds: [lineId]
|
|
232
124
|
});
|
|
233
|
-
|
|
234
|
-
|
|
125
|
+
const [id] = ids(LINE_ID, [lineId]) ?? [];
|
|
126
|
+
if (!id) return Promise.resolve(unknown("cart_line"));
|
|
127
|
+
return write(session, "update", (cart) => cart.lines.update({
|
|
235
128
|
token,
|
|
236
|
-
customerToken,
|
|
237
129
|
lines: [{
|
|
238
|
-
|
|
130
|
+
lineId: id,
|
|
239
131
|
quantity
|
|
240
132
|
}]
|
|
241
|
-
});
|
|
133
|
+
}));
|
|
242
134
|
}
|
|
243
135
|
/**
|
|
244
|
-
* Set or clear the buyer's cart note.
|
|
245
|
-
*
|
|
246
|
-
*
|
|
247
|
-
* (`VALIDATION_ERROR`, `field: "note"`); a theme's field mirrors the cap as
|
|
248
|
-
* `maxLength`.
|
|
136
|
+
* Set or clear the buyer's cart note. The api trims it, and a blank one clears
|
|
137
|
+
* it; it refuses one past `CART_NOTE_MAX_LENGTH` (`VALIDATION_FAILED`), which a
|
|
138
|
+
* theme's field mirrors as `maxLength`.
|
|
249
139
|
*/
|
|
250
|
-
|
|
251
|
-
const { session, token,
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
}, customerToken ? { customerSessionToken: customerToken } : void 0)).cartNoteUpdate);
|
|
257
|
-
if (!unwrapped.ok) {
|
|
258
|
-
if (isCartTokenNotFound(unwrapped.error)) await session.clear();
|
|
259
|
-
return {
|
|
260
|
-
ok: false,
|
|
261
|
-
...unwrapped.error
|
|
262
|
-
};
|
|
263
|
-
}
|
|
264
|
-
return {
|
|
265
|
-
ok: true,
|
|
266
|
-
cart: decodeCart(unwrapped.cart)
|
|
267
|
-
};
|
|
268
|
-
} catch (err) {
|
|
269
|
-
return surfaceClientError(err, "setCartNote");
|
|
270
|
-
}
|
|
140
|
+
function setNote(args) {
|
|
141
|
+
const { session, token, note } = args;
|
|
142
|
+
return write(session, "note", (cart) => cart.note.set({
|
|
143
|
+
token,
|
|
144
|
+
note
|
|
145
|
+
}));
|
|
271
146
|
}
|
|
272
|
-
|
|
273
|
-
export { addLines, mintCart, removeLines, setLineQuantity, setNote, unwrapCartPayload };
|
|
147
|
+
export { addLines, mintCart, removeLines, setLineQuantity, setNote };
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { CollectionProductData } from "./collection.js";
|
|
2
|
-
//#region src/cart-recommendations.d.ts
|
|
3
2
|
export declare const fetchCartRecommendations: ({ handles, locale, maxResults }: {
|
|
4
3
|
/** Every line's product handle, in cart order. */
|
|
5
4
|
handles: string[];
|
|
6
5
|
locale?: string;
|
|
7
6
|
/** How many products the theme's rail draws. */
|
|
8
7
|
maxResults: number;
|
|
9
|
-
}) => Promise<CollectionProductData[]>;
|
|
10
|
-
//#endregion
|
|
8
|
+
}) => Promise<CollectionProductData[]>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { fetchProductRecommendations } from "./recommendations.js";
|
|
2
|
-
|
|
2
|
+
// src/cart-recommendations.ts
|
|
3
3
|
const MAX_REFERENCES = 5;
|
|
4
4
|
/** One deduped list in reference order, minus whatever is already in the cart. */
|
|
5
5
|
function merge(results, inCart, maxResults) {
|
|
@@ -27,5 +27,4 @@ const fetchCartRecommendations = async ({ handles, locale, maxResults }) => {
|
|
|
27
27
|
if (complementary.length > 0) return complementary;
|
|
28
28
|
return merge(await fanOut("RELATED"), inCart, maxResults);
|
|
29
29
|
};
|
|
30
|
-
//#endregion
|
|
31
30
|
export { fetchCartRecommendations };
|
package/dist/cart-session.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { SealedSession } from "@shop-on/customer-runtime/sealed-session";
|
|
2
|
-
//#region src/cart-session.d.ts
|
|
3
2
|
export interface CartSessionData {
|
|
4
3
|
token?: string;
|
|
5
4
|
expiresAtMs?: number;
|
|
6
5
|
}
|
|
7
|
-
export declare const useCartSession: () => Promise<SealedSession<CartSessionData>>;
|
|
8
|
-
//#endregion
|
|
6
|
+
export declare const useCartSession: () => Promise<SealedSession<CartSessionData>>;
|
package/dist/cart-session.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { derivedCookieSecret } from "./cookie-secret.js";
|
|
2
2
|
import { createServerOnlyFn } from "@tanstack/react-start";
|
|
3
3
|
import { createShopBoundCookieConfig } from "@shop-on/customer-runtime/session-cookie";
|
|
4
|
-
|
|
4
|
+
// src/cart-session.ts
|
|
5
5
|
const TTL_SECONDS = 2592e3;
|
|
6
6
|
const DOMAIN_LABEL = "cart";
|
|
7
7
|
const sessionConfig = createServerOnlyFn(async () => {
|
|
@@ -15,5 +15,4 @@ const useCartSession = createServerOnlyFn(async () => {
|
|
|
15
15
|
const { openSession } = await import("@shop-on/customer-runtime/sealed-session");
|
|
16
16
|
return openSession(await sessionConfig());
|
|
17
17
|
});
|
|
18
|
-
//#endregion
|
|
19
18
|
export { useCartSession };
|