@commerce-blocks/sdk 1.2.1 → 2.0.0-alpha.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/README.md +226 -93
- package/dist/index.d.ts +231 -119
- package/dist/index.js +1224 -1038
- package/package.json +7 -2
package/dist/index.js
CHANGED
|
@@ -1,26 +1,46 @@
|
|
|
1
|
-
import { signal as
|
|
2
|
-
import { batch as
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { signal as L, computed as N } from "@preact/signals-core";
|
|
2
|
+
import { batch as wn, computed as On, effect as Rn, signal as kn } from "@preact/signals-core";
|
|
3
|
+
const je = "2.0.0-alpha.0", He = {
|
|
4
|
+
version: je
|
|
5
|
+
}, Qe = "2026-01", Ke = "https://app.uselayers.com/api/storefront/v1", ze = 1e3, ke = 1e3, Ce = 100, Xe = 300 * ze, pe = He.version, ae = 250, B = 20, G = 250, se = 250, ie = 250, ce = 1, le = 1, Y = 1, Z = 24, ue = 1, de = 1, fe = 100, We = 20, Je = 50, Ye = 300, Ze = 50, et = "USD", tt = "en-US", nt = 1e3, we = /* @__PURE__ */ new Map();
|
|
6
|
+
function rt(e, t) {
|
|
7
|
+
const n = `${e}:${t}`;
|
|
8
|
+
let o = we.get(n);
|
|
7
9
|
return o || (o = new Intl.NumberFormat(tt, {
|
|
8
10
|
style: "currency",
|
|
9
11
|
currency: t
|
|
10
|
-
}).format(e),
|
|
12
|
+
}).format(e), we.set(n, o)), o;
|
|
11
13
|
}
|
|
12
|
-
function
|
|
14
|
+
function D(e) {
|
|
13
15
|
return { data: e };
|
|
14
16
|
}
|
|
15
|
-
function
|
|
17
|
+
function v(e) {
|
|
16
18
|
return { error: e };
|
|
17
19
|
}
|
|
18
20
|
function ee() {
|
|
19
21
|
return (/* @__PURE__ */ new Date()).toISOString();
|
|
20
22
|
}
|
|
21
|
-
|
|
23
|
+
function ot(e, t, n, o) {
|
|
24
|
+
return {
|
|
25
|
+
status: e,
|
|
26
|
+
statusText: t,
|
|
27
|
+
headers: n ? st(n) : void 0,
|
|
28
|
+
body: o ? it(o) : void 0
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
const at = ["authorization", "x-shopify-access-token", "cookie", "set-cookie"];
|
|
32
|
+
function st(e) {
|
|
33
|
+
const t = {};
|
|
34
|
+
for (const [n, o] of Object.entries(e))
|
|
35
|
+
t[n] = at.includes(n.toLowerCase()) ? "[REDACTED]" : o;
|
|
36
|
+
return t;
|
|
37
|
+
}
|
|
38
|
+
function it(e, t = 1e3) {
|
|
39
|
+
return e.length > t ? e.slice(0, t) + "...[truncated]" : e;
|
|
40
|
+
}
|
|
41
|
+
const ct = ["TIMEOUT", "CONNECTION_FAILED", "DNS_FAILED"];
|
|
22
42
|
function J(e) {
|
|
23
|
-
const t =
|
|
43
|
+
const t = ct.includes(e.code);
|
|
24
44
|
return {
|
|
25
45
|
_tag: "NetworkError",
|
|
26
46
|
code: e.code,
|
|
@@ -32,18 +52,19 @@ function J(e) {
|
|
|
32
52
|
retryAfterMs: t ? 1e3 : void 0
|
|
33
53
|
};
|
|
34
54
|
}
|
|
35
|
-
function
|
|
55
|
+
function lt(e) {
|
|
36
56
|
if (!e) return;
|
|
37
57
|
const t = e["retry-after"] ?? e["Retry-After"];
|
|
38
58
|
if (!t) return;
|
|
39
|
-
const
|
|
40
|
-
if (
|
|
59
|
+
const n = t.trim();
|
|
60
|
+
if (/^\d+$/.test(n))
|
|
61
|
+
return Number(n) * 1e3;
|
|
41
62
|
const o = new Date(t);
|
|
42
63
|
if (!isNaN(o.getTime()))
|
|
43
64
|
return Math.max(0, o.getTime() - Date.now());
|
|
44
65
|
}
|
|
45
|
-
function
|
|
46
|
-
const t = e.code === "RATE_LIMITED" || e.code === "SERVICE_UNAVAILABLE" || e.status !== void 0 && e.status >= 500,
|
|
66
|
+
function $(e) {
|
|
67
|
+
const t = e.code === "RATE_LIMITED" || e.code === "SERVICE_UNAVAILABLE" || e.status !== void 0 && e.status >= 500, n = e.retryAfterMs ?? lt(e.response?.headers) ?? (t ? 1e3 : void 0);
|
|
47
68
|
return {
|
|
48
69
|
_tag: "ApiError",
|
|
49
70
|
code: e.code,
|
|
@@ -52,14 +73,14 @@ function O(e) {
|
|
|
52
73
|
timestamp: ee(),
|
|
53
74
|
status: e.status,
|
|
54
75
|
retryable: t,
|
|
55
|
-
retryAfterMs:
|
|
76
|
+
retryAfterMs: n,
|
|
56
77
|
request: e.request,
|
|
57
78
|
response: e.response,
|
|
58
79
|
cause: e.cause,
|
|
59
80
|
details: e.details
|
|
60
81
|
};
|
|
61
82
|
}
|
|
62
|
-
function
|
|
83
|
+
function q(e) {
|
|
63
84
|
return {
|
|
64
85
|
_tag: "ValidationError",
|
|
65
86
|
code: "VALIDATION_FAILED",
|
|
@@ -70,16 +91,16 @@ function D(e) {
|
|
|
70
91
|
input: e.input
|
|
71
92
|
};
|
|
72
93
|
}
|
|
73
|
-
function
|
|
94
|
+
function C(e, t, n, o) {
|
|
74
95
|
return {
|
|
75
96
|
path: e.split("."),
|
|
76
97
|
field: e.split(".").pop() ?? e,
|
|
77
98
|
code: t,
|
|
78
|
-
message:
|
|
99
|
+
message: n,
|
|
79
100
|
...o
|
|
80
101
|
};
|
|
81
102
|
}
|
|
82
|
-
function
|
|
103
|
+
function U(e) {
|
|
83
104
|
return {
|
|
84
105
|
_tag: "ConfigError",
|
|
85
106
|
code: e.code,
|
|
@@ -90,22 +111,29 @@ function B(e) {
|
|
|
90
111
|
expected: e.expected
|
|
91
112
|
};
|
|
92
113
|
}
|
|
93
|
-
|
|
94
|
-
|
|
114
|
+
const ut = ["NetworkError", "ApiError", "ValidationError", "ConfigError"];
|
|
115
|
+
function ln(e) {
|
|
116
|
+
return typeof e == "object" && e !== null && ut.includes(e._tag ?? "");
|
|
95
117
|
}
|
|
96
|
-
function
|
|
118
|
+
function un(e) {
|
|
97
119
|
return "retryable" in e ? e.retryable : !1;
|
|
98
120
|
}
|
|
99
|
-
function
|
|
100
|
-
const
|
|
101
|
-
return
|
|
102
|
-
code:
|
|
121
|
+
function dt(e, t) {
|
|
122
|
+
const { status: n } = e, o = n === 401 ? "UNAUTHORIZED" : n === 403 ? "FORBIDDEN" : n === 404 ? "NOT_FOUND" : n === 429 ? "RATE_LIMITED" : n >= 500 ? "SERVICE_UNAVAILABLE" : "UNKNOWN";
|
|
123
|
+
return $({
|
|
124
|
+
code: o,
|
|
103
125
|
source: "layers",
|
|
104
|
-
message: t || `HTTP ${
|
|
105
|
-
status:
|
|
126
|
+
message: t || `HTTP ${n}`,
|
|
127
|
+
status: n,
|
|
128
|
+
response: ot(
|
|
129
|
+
n,
|
|
130
|
+
e.statusText,
|
|
131
|
+
Object.fromEntries(e.headers.entries()),
|
|
132
|
+
t
|
|
133
|
+
)
|
|
106
134
|
});
|
|
107
135
|
}
|
|
108
|
-
function
|
|
136
|
+
function ve(e) {
|
|
109
137
|
if (e instanceof Error && (e.name === "AbortError" || e.name === "TimeoutError")) {
|
|
110
138
|
const t = e.name === "TimeoutError" || e.message.includes("timeout");
|
|
111
139
|
return J({
|
|
@@ -120,16 +148,16 @@ function Ee(e) {
|
|
|
120
148
|
cause: e
|
|
121
149
|
});
|
|
122
150
|
}
|
|
123
|
-
async function
|
|
151
|
+
async function ye(e) {
|
|
124
152
|
if (!e.ok) {
|
|
125
153
|
const t = await e.text().catch(() => "");
|
|
126
|
-
return
|
|
154
|
+
return v(dt(e, t));
|
|
127
155
|
}
|
|
128
156
|
try {
|
|
129
|
-
return
|
|
157
|
+
return D(await e.json());
|
|
130
158
|
} catch (t) {
|
|
131
|
-
return
|
|
132
|
-
|
|
159
|
+
return v(
|
|
160
|
+
$({
|
|
133
161
|
code: "PARSE_ERROR",
|
|
134
162
|
source: "layers",
|
|
135
163
|
message: "Invalid JSON response",
|
|
@@ -142,71 +170,71 @@ function Ie({
|
|
|
142
170
|
token: e,
|
|
143
171
|
json: t = !0
|
|
144
172
|
}) {
|
|
145
|
-
const
|
|
173
|
+
const n = {
|
|
146
174
|
Accept: "application/json",
|
|
147
175
|
"X-Storefront-Access-Token": e,
|
|
148
|
-
"X-SDK-Client": `commerce-blocks-sdk/${
|
|
176
|
+
"X-SDK-Client": `commerce-blocks-sdk/${pe}`
|
|
149
177
|
};
|
|
150
|
-
return t && (
|
|
178
|
+
return t && (n["Content-Type"] = "application/json"), n;
|
|
151
179
|
}
|
|
152
|
-
function
|
|
153
|
-
const { layersBaseUrl:
|
|
154
|
-
return `${
|
|
180
|
+
function Ee({ config: e, endpoint: t }) {
|
|
181
|
+
const { layersBaseUrl: n = Ke } = e;
|
|
182
|
+
return `${n}${t}`;
|
|
155
183
|
}
|
|
156
|
-
async function
|
|
184
|
+
async function x(e) {
|
|
157
185
|
const t = e.config.fetch ?? fetch;
|
|
158
186
|
try {
|
|
159
|
-
const
|
|
187
|
+
const n = await t(Ee({ config: e.config, endpoint: e.endpoint }), {
|
|
160
188
|
method: "POST",
|
|
161
189
|
headers: Ie({ token: e.config.layersPublicToken }),
|
|
162
190
|
body: JSON.stringify(e.body),
|
|
163
191
|
signal: e.signal
|
|
164
192
|
});
|
|
165
|
-
return
|
|
166
|
-
} catch (
|
|
167
|
-
return
|
|
193
|
+
return ye(n);
|
|
194
|
+
} catch (n) {
|
|
195
|
+
return v(ve(n));
|
|
168
196
|
}
|
|
169
197
|
}
|
|
170
|
-
async function
|
|
198
|
+
async function ft(e) {
|
|
171
199
|
const t = new URLSearchParams();
|
|
172
200
|
for (const [s, i] of Object.entries(e.params))
|
|
173
201
|
i != null && t.append(s, typeof i == "object" ? JSON.stringify(i) : String(i));
|
|
174
|
-
const
|
|
202
|
+
const n = t.toString(), o = n ? `${e.endpoint}?${n}` : e.endpoint, r = e.config.fetch ?? fetch;
|
|
175
203
|
try {
|
|
176
|
-
const s = await
|
|
204
|
+
const s = await r(Ee({ config: e.config, endpoint: o }), {
|
|
177
205
|
method: "GET",
|
|
178
206
|
headers: Ie({ token: e.config.layersPublicToken }),
|
|
179
207
|
signal: e.signal
|
|
180
208
|
});
|
|
181
|
-
return
|
|
209
|
+
return ye(s);
|
|
182
210
|
} catch (s) {
|
|
183
|
-
return
|
|
211
|
+
return v(ve(s));
|
|
184
212
|
}
|
|
185
213
|
}
|
|
186
|
-
async function
|
|
214
|
+
async function gt(e) {
|
|
187
215
|
const t = e.config.fetch ?? fetch;
|
|
188
216
|
try {
|
|
189
|
-
const
|
|
217
|
+
const n = await t(Ee({ config: e.config, endpoint: e.endpoint }), {
|
|
190
218
|
method: "POST",
|
|
191
219
|
headers: Ie({ token: e.config.layersPublicToken, json: !1 }),
|
|
192
220
|
body: e.formData,
|
|
193
221
|
signal: e.signal
|
|
194
222
|
});
|
|
195
|
-
return
|
|
196
|
-
} catch (
|
|
197
|
-
return
|
|
223
|
+
return ye(n);
|
|
224
|
+
} catch (n) {
|
|
225
|
+
return v(ve(n));
|
|
198
226
|
}
|
|
199
227
|
}
|
|
200
|
-
function
|
|
228
|
+
function j(e, t) {
|
|
201
229
|
if (!e) return null;
|
|
202
|
-
const
|
|
203
|
-
return e.page !== void 0 && e.page < ue &&
|
|
204
|
-
|
|
230
|
+
const n = [];
|
|
231
|
+
return e.page !== void 0 && e.page < ue && n.push(
|
|
232
|
+
C("pagination.page", "OUT_OF_RANGE", `page must be >= ${ue}`, {
|
|
205
233
|
value: e.page,
|
|
206
234
|
constraints: { min: ue }
|
|
207
235
|
})
|
|
208
|
-
), e.limit !== void 0 && (e.limit < de || e.limit > fe) &&
|
|
209
|
-
|
|
236
|
+
), e.limit !== void 0 && (e.limit < de || e.limit > fe) && n.push(
|
|
237
|
+
C(
|
|
210
238
|
"pagination.limit",
|
|
211
239
|
"OUT_OF_RANGE",
|
|
212
240
|
`limit must be between ${de} and ${fe}`,
|
|
@@ -215,9 +243,9 @@ function Q(e, t) {
|
|
|
215
243
|
constraints: { min: de, max: fe }
|
|
216
244
|
}
|
|
217
245
|
)
|
|
218
|
-
),
|
|
246
|
+
), n.length > 0 ? q({ operation: t, fields: n }) : null;
|
|
219
247
|
}
|
|
220
|
-
const
|
|
248
|
+
const mt = [
|
|
221
249
|
"title",
|
|
222
250
|
"handle",
|
|
223
251
|
"body_html",
|
|
@@ -236,12 +264,19 @@ const lt = [
|
|
|
236
264
|
"metafields",
|
|
237
265
|
"calculated",
|
|
238
266
|
"named_tags",
|
|
239
|
-
"category"
|
|
267
|
+
"category",
|
|
268
|
+
"created_at",
|
|
269
|
+
"published_at",
|
|
270
|
+
"updated_at",
|
|
271
|
+
"combined_listing_parent_product_id",
|
|
272
|
+
"combined_listing_role",
|
|
273
|
+
"has_variants_that_require_components",
|
|
274
|
+
"original_options"
|
|
240
275
|
];
|
|
241
|
-
function
|
|
276
|
+
function pt(e) {
|
|
242
277
|
if (!e.layersPublicToken)
|
|
243
|
-
return
|
|
244
|
-
|
|
278
|
+
return v(
|
|
279
|
+
U({
|
|
245
280
|
code: "MISSING_CONFIG",
|
|
246
281
|
message: "layersPublicToken is required",
|
|
247
282
|
field: "layersPublicToken",
|
|
@@ -249,189 +284,189 @@ function ut(e) {
|
|
|
249
284
|
})
|
|
250
285
|
);
|
|
251
286
|
if (!e.sorts || e.sorts.length === 0)
|
|
252
|
-
return
|
|
253
|
-
|
|
287
|
+
return v(
|
|
288
|
+
U({
|
|
254
289
|
code: "MISSING_CONFIG",
|
|
255
290
|
message: "At least one sort option is required",
|
|
256
291
|
field: "sorts",
|
|
257
292
|
expected: "non-empty array of Sort"
|
|
258
293
|
})
|
|
259
294
|
);
|
|
260
|
-
function t(
|
|
261
|
-
return [.../* @__PURE__ */ new Set([...
|
|
295
|
+
function t(r) {
|
|
296
|
+
return [.../* @__PURE__ */ new Set([...mt, ...e.attributes ?? [], ...r ?? []])];
|
|
262
297
|
}
|
|
263
|
-
const
|
|
298
|
+
const n = {
|
|
264
299
|
layersPublicToken: e.layersPublicToken,
|
|
265
300
|
layersBaseUrl: e.layersBaseUrl,
|
|
266
301
|
fetch: e.fetch
|
|
267
302
|
};
|
|
268
|
-
return
|
|
269
|
-
browse: async (
|
|
270
|
-
if (!
|
|
271
|
-
return
|
|
272
|
-
|
|
303
|
+
return D({
|
|
304
|
+
browse: async (r, s) => {
|
|
305
|
+
if (!r.collectionHandle)
|
|
306
|
+
return v(
|
|
307
|
+
q({
|
|
273
308
|
operation: "browse",
|
|
274
309
|
fields: [
|
|
275
|
-
|
|
310
|
+
C("collectionHandle", "REQUIRED_FIELD", "collectionHandle is required")
|
|
276
311
|
]
|
|
277
312
|
})
|
|
278
313
|
);
|
|
279
|
-
if (!
|
|
280
|
-
return
|
|
281
|
-
|
|
314
|
+
if (!r.sort_order_code)
|
|
315
|
+
return v(
|
|
316
|
+
q({
|
|
282
317
|
operation: "browse",
|
|
283
318
|
fields: [
|
|
284
|
-
|
|
319
|
+
C("sort_order_code", "REQUIRED_FIELD", "sort_order_code is required")
|
|
285
320
|
]
|
|
286
321
|
})
|
|
287
322
|
);
|
|
288
|
-
const i =
|
|
289
|
-
if (i) return
|
|
290
|
-
const { collectionHandle: a, attributes: l, transformBody:
|
|
291
|
-
let
|
|
292
|
-
facets: e.facets,
|
|
323
|
+
const i = j(r.pagination, "browse");
|
|
324
|
+
if (i) return v(i);
|
|
325
|
+
const { collectionHandle: a, attributes: l, transformBody: c, ...g } = r;
|
|
326
|
+
let d = {
|
|
327
|
+
facets: e.facets.map((p) => p.code),
|
|
293
328
|
attributes: t(l),
|
|
294
329
|
retrieveFacetCount: !0,
|
|
295
330
|
includeFacetRanges: !0,
|
|
296
331
|
...g
|
|
297
332
|
};
|
|
298
|
-
return
|
|
299
|
-
config:
|
|
333
|
+
return c && (d = c(d)), x({
|
|
334
|
+
config: n,
|
|
300
335
|
endpoint: `/browse/${a}`,
|
|
301
|
-
body:
|
|
336
|
+
body: d,
|
|
302
337
|
signal: s
|
|
303
338
|
});
|
|
304
339
|
},
|
|
305
|
-
predictiveSearch: async (
|
|
306
|
-
config:
|
|
340
|
+
predictiveSearch: async (r, s) => r ? ft({
|
|
341
|
+
config: n,
|
|
307
342
|
endpoint: "/search/complete",
|
|
308
|
-
params: { query:
|
|
343
|
+
params: { query: r },
|
|
309
344
|
signal: s
|
|
310
|
-
}) :
|
|
311
|
-
|
|
345
|
+
}) : v(
|
|
346
|
+
q({
|
|
312
347
|
operation: "predictiveSearch",
|
|
313
|
-
fields: [
|
|
348
|
+
fields: [C("query", "REQUIRED_FIELD", "query is required")]
|
|
314
349
|
})
|
|
315
350
|
),
|
|
316
|
-
prepareSearch: async (
|
|
317
|
-
if (!
|
|
318
|
-
return
|
|
319
|
-
|
|
351
|
+
prepareSearch: async (r, s) => {
|
|
352
|
+
if (!r.query)
|
|
353
|
+
return v(
|
|
354
|
+
q({
|
|
320
355
|
operation: "prepareSearch",
|
|
321
|
-
fields: [
|
|
356
|
+
fields: [C("query", "REQUIRED_FIELD", "query is required")]
|
|
322
357
|
})
|
|
323
358
|
);
|
|
324
|
-
const { query: i, transformBody: a, ...l } =
|
|
325
|
-
let
|
|
326
|
-
return a && (
|
|
327
|
-
config:
|
|
359
|
+
const { query: i, transformBody: a, ...l } = r;
|
|
360
|
+
let c = { ...l };
|
|
361
|
+
return a && (c = a(c)), x({
|
|
362
|
+
config: n,
|
|
328
363
|
endpoint: `/search/${encodeURIComponent(i)}/prepare`,
|
|
329
|
-
body:
|
|
364
|
+
body: c,
|
|
330
365
|
signal: s
|
|
331
366
|
});
|
|
332
367
|
},
|
|
333
|
-
search: async (
|
|
334
|
-
if (!
|
|
335
|
-
return
|
|
336
|
-
|
|
368
|
+
search: async (r, s) => {
|
|
369
|
+
if (!r.query)
|
|
370
|
+
return v(
|
|
371
|
+
q({
|
|
337
372
|
operation: "search",
|
|
338
|
-
fields: [
|
|
373
|
+
fields: [C("query", "REQUIRED_FIELD", "query is required")]
|
|
339
374
|
})
|
|
340
375
|
);
|
|
341
|
-
const i =
|
|
342
|
-
if (i) return
|
|
343
|
-
const { query: a, attributes: l, transformBody:
|
|
344
|
-
let
|
|
345
|
-
facets: e.facets,
|
|
376
|
+
const i = j(r.pagination, "search");
|
|
377
|
+
if (i) return v(i);
|
|
378
|
+
const { query: a, attributes: l, transformBody: c, ...g } = r;
|
|
379
|
+
let d = {
|
|
380
|
+
facets: e.facets.map((p) => p.code),
|
|
346
381
|
attributes: t(l),
|
|
347
382
|
retrieveFacetCount: !0,
|
|
348
383
|
includeFacetRanges: !0,
|
|
349
384
|
...g
|
|
350
385
|
};
|
|
351
|
-
return
|
|
352
|
-
config:
|
|
386
|
+
return c && (d = c(d)), x({
|
|
387
|
+
config: n,
|
|
353
388
|
endpoint: `/search/${encodeURIComponent(a)}/execute`,
|
|
354
|
-
body:
|
|
389
|
+
body: d,
|
|
355
390
|
signal: s
|
|
356
391
|
});
|
|
357
392
|
},
|
|
358
|
-
imageSearch: async (
|
|
359
|
-
if (!
|
|
360
|
-
return
|
|
361
|
-
|
|
393
|
+
imageSearch: async (r, s) => {
|
|
394
|
+
if (!r.image_data && !r.image_id)
|
|
395
|
+
return v(
|
|
396
|
+
q({
|
|
362
397
|
operation: "imageSearch",
|
|
363
398
|
fields: [
|
|
364
|
-
|
|
399
|
+
C("image_data", "REQUIRED_FIELD", "image_data or image_id is required")
|
|
365
400
|
]
|
|
366
401
|
})
|
|
367
402
|
);
|
|
368
|
-
const i =
|
|
369
|
-
if (i) return
|
|
370
|
-
const { attributes: a, transformBody: l, ...
|
|
403
|
+
const i = j(r.pagination, "imageSearch");
|
|
404
|
+
if (i) return v(i);
|
|
405
|
+
const { attributes: a, transformBody: l, ...c } = r;
|
|
371
406
|
let g = {
|
|
372
407
|
attributes: t(a),
|
|
373
|
-
...
|
|
408
|
+
...c
|
|
374
409
|
};
|
|
375
|
-
return l && (g = l(g)),
|
|
376
|
-
config:
|
|
410
|
+
return l && (g = l(g)), x({
|
|
411
|
+
config: n,
|
|
377
412
|
endpoint: "/search/image",
|
|
378
413
|
body: g,
|
|
379
414
|
signal: s
|
|
380
415
|
});
|
|
381
416
|
},
|
|
382
|
-
uploadImage: async (
|
|
417
|
+
uploadImage: async (r, s) => {
|
|
383
418
|
const i = new FormData();
|
|
384
|
-
return i.append("image",
|
|
385
|
-
config:
|
|
419
|
+
return i.append("image", r), gt({
|
|
420
|
+
config: n,
|
|
386
421
|
endpoint: "/images/upload",
|
|
387
422
|
formData: i,
|
|
388
423
|
signal: s
|
|
389
424
|
});
|
|
390
425
|
},
|
|
391
|
-
blocks: async (
|
|
392
|
-
if (!
|
|
393
|
-
return
|
|
394
|
-
|
|
426
|
+
blocks: async (r, s) => {
|
|
427
|
+
if (!r.blockId)
|
|
428
|
+
return v(
|
|
429
|
+
q({
|
|
395
430
|
operation: "block",
|
|
396
|
-
fields: [
|
|
431
|
+
fields: [C("blockId", "REQUIRED_FIELD", "blockId is required")]
|
|
397
432
|
})
|
|
398
433
|
);
|
|
399
|
-
const i =
|
|
400
|
-
if (i) return
|
|
401
|
-
const { blockId: a, attributes: l, transformBody:
|
|
402
|
-
let
|
|
403
|
-
facets: e.facets,
|
|
434
|
+
const i = j(r.pagination, "block");
|
|
435
|
+
if (i) return v(i);
|
|
436
|
+
const { blockId: a, attributes: l, transformBody: c, ...g } = r;
|
|
437
|
+
let d = {
|
|
438
|
+
facets: e.facets.map((p) => p.code),
|
|
404
439
|
attributes: t(l),
|
|
405
440
|
retrieveFacetCount: !0,
|
|
406
441
|
includeFacetRanges: !0,
|
|
407
442
|
...g
|
|
408
443
|
};
|
|
409
|
-
return
|
|
410
|
-
config:
|
|
444
|
+
return c && (d = c(d)), x({
|
|
445
|
+
config: n,
|
|
411
446
|
endpoint: `/blocks/${a}/products`,
|
|
412
|
-
body:
|
|
447
|
+
body: d,
|
|
413
448
|
signal: s
|
|
414
449
|
});
|
|
415
450
|
},
|
|
416
|
-
similarProducts: async (
|
|
417
|
-
if (!
|
|
418
|
-
return
|
|
419
|
-
|
|
451
|
+
similarProducts: async (r, s) => {
|
|
452
|
+
if (!r.productId)
|
|
453
|
+
return v(
|
|
454
|
+
q({
|
|
420
455
|
operation: "similarProducts",
|
|
421
|
-
fields: [
|
|
456
|
+
fields: [C("productId", "REQUIRED_FIELD", "productId is required")]
|
|
422
457
|
})
|
|
423
458
|
);
|
|
424
|
-
const i =
|
|
425
|
-
if (i) return
|
|
426
|
-
const { productId: a, attributes: l, transformBody:
|
|
427
|
-
let
|
|
459
|
+
const i = j(r.pagination, "similarProducts");
|
|
460
|
+
if (i) return v(i);
|
|
461
|
+
const { productId: a, attributes: l, transformBody: c, ...g } = r;
|
|
462
|
+
let d = {
|
|
428
463
|
attributes: t(l),
|
|
429
464
|
...g
|
|
430
465
|
};
|
|
431
|
-
return
|
|
432
|
-
config:
|
|
466
|
+
return c && (d = c(d)), x({
|
|
467
|
+
config: n,
|
|
433
468
|
endpoint: `/search/product/${a}`,
|
|
434
|
-
body:
|
|
469
|
+
body: d,
|
|
435
470
|
signal: s
|
|
436
471
|
});
|
|
437
472
|
}
|
|
@@ -442,28 +477,28 @@ const te = `
|
|
|
442
477
|
title
|
|
443
478
|
description
|
|
444
479
|
}
|
|
445
|
-
`,
|
|
480
|
+
`, De = `
|
|
446
481
|
fragment FilterValueFields on FilterValue {
|
|
447
482
|
id
|
|
448
483
|
label
|
|
449
484
|
count
|
|
450
485
|
input
|
|
451
486
|
}
|
|
452
|
-
`,
|
|
487
|
+
`, Ne = `
|
|
453
488
|
fragment FilterFields on Filter {
|
|
454
489
|
id
|
|
455
490
|
label
|
|
456
491
|
type
|
|
457
492
|
values { ...FilterValueFields }
|
|
458
493
|
}
|
|
459
|
-
`,
|
|
494
|
+
`, ne = `
|
|
460
495
|
fragment ImageFields on Image {
|
|
461
496
|
url
|
|
462
497
|
altText
|
|
463
498
|
width
|
|
464
499
|
height
|
|
465
500
|
}
|
|
466
|
-
`,
|
|
501
|
+
`, be = `
|
|
467
502
|
fragment MoneyFields on MoneyV2 {
|
|
468
503
|
amount
|
|
469
504
|
currencyCode
|
|
@@ -473,12 +508,12 @@ const te = `
|
|
|
473
508
|
name
|
|
474
509
|
value
|
|
475
510
|
}
|
|
476
|
-
`,
|
|
511
|
+
`, Se = `
|
|
477
512
|
fragment PriceRangeFields on ProductPriceRange {
|
|
478
513
|
minVariantPrice { ...MoneyFields }
|
|
479
514
|
maxVariantPrice { ...MoneyFields }
|
|
480
515
|
}
|
|
481
|
-
`,
|
|
516
|
+
`, Me = `
|
|
482
517
|
fragment ProductOptionFields on ProductOption {
|
|
483
518
|
id
|
|
484
519
|
name
|
|
@@ -501,19 +536,14 @@ const te = `
|
|
|
501
536
|
type
|
|
502
537
|
}
|
|
503
538
|
`;
|
|
504
|
-
function
|
|
539
|
+
function Ae(e) {
|
|
505
540
|
return `
|
|
506
541
|
fragment VariantFields on ProductVariant {
|
|
507
542
|
id
|
|
508
543
|
title
|
|
509
544
|
availableForSale
|
|
510
545
|
currentlyNotInStock
|
|
511
|
-
quantityAvailable
|
|
512
546
|
sku
|
|
513
|
-
barcode
|
|
514
|
-
weight
|
|
515
|
-
weightUnit
|
|
516
|
-
requiresShipping
|
|
517
547
|
price { ...MoneyFields }
|
|
518
548
|
compareAtPrice { ...MoneyFields }
|
|
519
549
|
selectedOptions { ...SelectedOptionFields }
|
|
@@ -522,8 +552,8 @@ function Pe(e) {
|
|
|
522
552
|
}
|
|
523
553
|
`;
|
|
524
554
|
}
|
|
525
|
-
function
|
|
526
|
-
const { maxImages: t, maxVariants:
|
|
555
|
+
function Te(e) {
|
|
556
|
+
const { maxImages: t, maxVariants: n, includeProductMetafields: o } = e;
|
|
527
557
|
return `
|
|
528
558
|
fragment ProductFields on Product {
|
|
529
559
|
id
|
|
@@ -536,20 +566,18 @@ function Re(e) {
|
|
|
536
566
|
tags
|
|
537
567
|
availableForSale
|
|
538
568
|
isGiftCard
|
|
539
|
-
totalInventory
|
|
540
|
-
onlineStoreUrl
|
|
541
569
|
featuredImage { ...ImageFields }
|
|
542
570
|
images(first: ${t}) { nodes { ...ImageFields } }
|
|
543
571
|
priceRange { ...PriceRangeFields }
|
|
544
572
|
compareAtPriceRange { ...PriceRangeFields }
|
|
545
573
|
options { ...ProductOptionFields }
|
|
546
|
-
variants(first: ${
|
|
574
|
+
variants(first: ${n}) { nodes { ...VariantFields } }
|
|
547
575
|
selectedOrFirstAvailableVariant { ...VariantFields }
|
|
548
576
|
${o ? "metafields(identifiers: $productMetafields) { ...MetafieldFields }" : ""}
|
|
549
577
|
}
|
|
550
578
|
`;
|
|
551
579
|
}
|
|
552
|
-
function
|
|
580
|
+
function qe(e) {
|
|
553
581
|
return `
|
|
554
582
|
fragment CollectionFields on Collection {
|
|
555
583
|
id
|
|
@@ -564,7 +592,7 @@ function Ue(e) {
|
|
|
564
592
|
}
|
|
565
593
|
`;
|
|
566
594
|
}
|
|
567
|
-
function
|
|
595
|
+
function $e(e) {
|
|
568
596
|
return `
|
|
569
597
|
fragment PageFields on Page {
|
|
570
598
|
id
|
|
@@ -580,31 +608,31 @@ function Ve(e) {
|
|
|
580
608
|
}
|
|
581
609
|
`;
|
|
582
610
|
}
|
|
583
|
-
function
|
|
584
|
-
const { includeProductMetafields: t, includeVariantMetafields:
|
|
611
|
+
function ht(e) {
|
|
612
|
+
const { includeProductMetafields: t, includeVariantMetafields: n } = e;
|
|
585
613
|
return [
|
|
586
|
-
|
|
587
|
-
|
|
614
|
+
ne,
|
|
615
|
+
be,
|
|
588
616
|
Fe,
|
|
589
|
-
Me,
|
|
590
617
|
Se,
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
618
|
+
Me,
|
|
619
|
+
t || n ? z : "",
|
|
620
|
+
Ae(n),
|
|
621
|
+
Te(e)
|
|
594
622
|
].join(`
|
|
595
623
|
`);
|
|
596
624
|
}
|
|
597
|
-
function
|
|
625
|
+
function _t(e = {}) {
|
|
598
626
|
const {
|
|
599
|
-
maxImages: t =
|
|
600
|
-
maxVariants:
|
|
627
|
+
maxImages: t = B,
|
|
628
|
+
maxVariants: n = G,
|
|
601
629
|
productMetafields: o = [],
|
|
602
|
-
variantMetafields:
|
|
603
|
-
} = e, s = o.length > 0, i =
|
|
630
|
+
variantMetafields: r = []
|
|
631
|
+
} = e, s = o.length > 0, i = r.length > 0, a = ["$ids: [ID!]!"];
|
|
604
632
|
return s && a.push("$productMetafields: [HasMetafieldsIdentifier!]!"), i && a.push("$variantMetafields: [HasMetafieldsIdentifier!]!"), `
|
|
605
|
-
${
|
|
633
|
+
${ht({
|
|
606
634
|
maxImages: t,
|
|
607
|
-
maxVariants:
|
|
635
|
+
maxVariants: n,
|
|
608
636
|
includeProductMetafields: s,
|
|
609
637
|
includeVariantMetafields: i
|
|
610
638
|
})}
|
|
@@ -618,37 +646,37 @@ function ft(e = {}) {
|
|
|
618
646
|
}
|
|
619
647
|
`;
|
|
620
648
|
}
|
|
621
|
-
function
|
|
649
|
+
function vt(e = {}) {
|
|
622
650
|
const {
|
|
623
|
-
maxImages: t =
|
|
624
|
-
maxVariants:
|
|
651
|
+
maxImages: t = B,
|
|
652
|
+
maxVariants: n = G,
|
|
625
653
|
productMetafields: o = [],
|
|
626
|
-
variantMetafields:
|
|
654
|
+
variantMetafields: r = [],
|
|
627
655
|
collectionMetafields: s = [],
|
|
628
656
|
includeFilters: i = !1
|
|
629
|
-
} = e, a = o.length > 0, l =
|
|
630
|
-
return a &&
|
|
657
|
+
} = e, a = o.length > 0, l = r.length > 0, c = s.length > 0, g = a || l || c, d = ["$ids: [ID!]!", "$handle: String!"];
|
|
658
|
+
return a && d.push("$productMetafields: [HasMetafieldsIdentifier!]!"), l && d.push("$variantMetafields: [HasMetafieldsIdentifier!]!"), c && d.push("$collectionMetafields: [HasMetafieldsIdentifier!]!"), `
|
|
631
659
|
${[
|
|
632
|
-
|
|
633
|
-
|
|
660
|
+
ne,
|
|
661
|
+
be,
|
|
634
662
|
Fe,
|
|
635
|
-
Me,
|
|
636
663
|
Se,
|
|
664
|
+
Me,
|
|
637
665
|
te,
|
|
638
666
|
g ? z : "",
|
|
639
|
-
i ?
|
|
640
|
-
i ?
|
|
641
|
-
|
|
642
|
-
|
|
667
|
+
i ? De : "",
|
|
668
|
+
i ? Ne : "",
|
|
669
|
+
Ae(l),
|
|
670
|
+
Te({
|
|
643
671
|
maxImages: t,
|
|
644
|
-
maxVariants:
|
|
672
|
+
maxVariants: n,
|
|
645
673
|
includeProductMetafields: a
|
|
646
674
|
}),
|
|
647
|
-
|
|
675
|
+
qe(c)
|
|
648
676
|
].join(`
|
|
649
677
|
`)}
|
|
650
678
|
|
|
651
|
-
query CollectionWithProducts(${
|
|
679
|
+
query CollectionWithProducts(${d.join(", ")}) {
|
|
652
680
|
collection(handle: $handle) {
|
|
653
681
|
...CollectionFields
|
|
654
682
|
${i ? "products(first: 1) { filters { ...FilterFields } }" : ""}
|
|
@@ -661,34 +689,34 @@ function gt(e = {}) {
|
|
|
661
689
|
}
|
|
662
690
|
`;
|
|
663
691
|
}
|
|
664
|
-
function
|
|
665
|
-
const { collectionMetafields: t = [], includeFilters:
|
|
666
|
-
return o &&
|
|
692
|
+
function yt(e = {}) {
|
|
693
|
+
const { collectionMetafields: t = [], includeFilters: n = !1 } = e, o = t.length > 0, r = ["$handle: String!"];
|
|
694
|
+
return o && r.push("$collectionMetafields: [HasMetafieldsIdentifier!]!"), `
|
|
667
695
|
${[
|
|
668
|
-
|
|
696
|
+
ne,
|
|
669
697
|
te,
|
|
670
698
|
o ? z : "",
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
699
|
+
n ? De : "",
|
|
700
|
+
n ? Ne : "",
|
|
701
|
+
qe(o)
|
|
674
702
|
].join(`
|
|
675
703
|
`)}
|
|
676
704
|
|
|
677
|
-
query Collection(${
|
|
705
|
+
query Collection(${r.join(", ")}) {
|
|
678
706
|
collection(handle: $handle) {
|
|
679
707
|
...CollectionFields
|
|
680
|
-
${
|
|
708
|
+
${n ? "products(first: 1) { filters { ...FilterFields } }" : ""}
|
|
681
709
|
}
|
|
682
710
|
}
|
|
683
711
|
`;
|
|
684
712
|
}
|
|
685
|
-
function
|
|
686
|
-
const { pageMetafields: t = [] } = e,
|
|
687
|
-
return
|
|
713
|
+
function It(e = {}) {
|
|
714
|
+
const { pageMetafields: t = [] } = e, n = t.length > 0, o = ["$handle: String!"];
|
|
715
|
+
return n && o.push("$pageMetafields: [HasMetafieldsIdentifier!]!"), `
|
|
688
716
|
${[
|
|
689
717
|
te,
|
|
690
|
-
|
|
691
|
-
|
|
718
|
+
n ? z : "",
|
|
719
|
+
$e(n)
|
|
692
720
|
].join(`
|
|
693
721
|
`)}
|
|
694
722
|
|
|
@@ -699,30 +727,30 @@ function pt(e = {}) {
|
|
|
699
727
|
}
|
|
700
728
|
`;
|
|
701
729
|
}
|
|
702
|
-
function
|
|
730
|
+
function Et(e = {}) {
|
|
703
731
|
const {
|
|
704
|
-
maxImages: t =
|
|
705
|
-
maxVariants:
|
|
732
|
+
maxImages: t = B,
|
|
733
|
+
maxVariants: n = G,
|
|
706
734
|
productMetafields: o = [],
|
|
707
|
-
variantMetafields:
|
|
735
|
+
variantMetafields: r = [],
|
|
708
736
|
pageMetafields: s = []
|
|
709
|
-
} = e, i = o.length > 0, a =
|
|
737
|
+
} = e, i = o.length > 0, a = r.length > 0, l = s.length > 0, c = i || a || l, g = ["$ids: [ID!]!", "$handle: String!"];
|
|
710
738
|
return i && g.push("$productMetafields: [HasMetafieldsIdentifier!]!"), a && g.push("$variantMetafields: [HasMetafieldsIdentifier!]!"), l && g.push("$pageMetafields: [HasMetafieldsIdentifier!]!"), `
|
|
711
739
|
${[
|
|
712
|
-
|
|
713
|
-
|
|
740
|
+
ne,
|
|
741
|
+
be,
|
|
714
742
|
Fe,
|
|
715
|
-
Me,
|
|
716
743
|
Se,
|
|
744
|
+
Me,
|
|
717
745
|
te,
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
746
|
+
c ? z : "",
|
|
747
|
+
Ae(a),
|
|
748
|
+
Te({
|
|
721
749
|
maxImages: t,
|
|
722
|
-
maxVariants:
|
|
750
|
+
maxVariants: n,
|
|
723
751
|
includeProductMetafields: i
|
|
724
752
|
}),
|
|
725
|
-
|
|
753
|
+
$e(l)
|
|
726
754
|
].join(`
|
|
727
755
|
`)}
|
|
728
756
|
|
|
@@ -738,16 +766,16 @@ function ht(e = {}) {
|
|
|
738
766
|
}
|
|
739
767
|
`;
|
|
740
768
|
}
|
|
741
|
-
function
|
|
769
|
+
function bt({
|
|
742
770
|
shop: e,
|
|
743
771
|
token: t,
|
|
744
|
-
apiVersion:
|
|
772
|
+
apiVersion: n,
|
|
745
773
|
customFetch: o = fetch
|
|
746
774
|
}) {
|
|
747
|
-
const
|
|
775
|
+
const r = `https://${e}/api/${n}/graphql.json`;
|
|
748
776
|
return {
|
|
749
777
|
async request(s, { variables: i, signal: a } = {}) {
|
|
750
|
-
const l = await o(
|
|
778
|
+
const l = await o(r, {
|
|
751
779
|
method: "POST",
|
|
752
780
|
headers: {
|
|
753
781
|
"Content-Type": "application/json",
|
|
@@ -761,21 +789,21 @@ function yt({
|
|
|
761
789
|
data: null,
|
|
762
790
|
errors: { message: `HTTP ${l.status}`, networkStatusCode: l.status }
|
|
763
791
|
};
|
|
764
|
-
const
|
|
765
|
-
return
|
|
792
|
+
const c = await l.json();
|
|
793
|
+
return c.errors ? { data: c.data, errors: { graphQLErrors: c.errors } } : { data: c.data };
|
|
766
794
|
}
|
|
767
795
|
};
|
|
768
796
|
}
|
|
769
797
|
function ge({ ids: e, maxSize: t }) {
|
|
770
|
-
const
|
|
798
|
+
const n = [];
|
|
771
799
|
for (let o = 0; o < e.length; o += t)
|
|
772
|
-
|
|
773
|
-
return
|
|
800
|
+
n.push(e.slice(o, o + t));
|
|
801
|
+
return n;
|
|
774
802
|
}
|
|
775
|
-
function
|
|
803
|
+
function Ft(e) {
|
|
776
804
|
if (!e.storefrontPublicToken)
|
|
777
|
-
return
|
|
778
|
-
|
|
805
|
+
return v(
|
|
806
|
+
U({
|
|
779
807
|
code: "MISSING_CONFIG",
|
|
780
808
|
message: "storefrontPublicToken is required",
|
|
781
809
|
field: "storefrontPublicToken",
|
|
@@ -783,311 +811,311 @@ function Et(e) {
|
|
|
783
811
|
})
|
|
784
812
|
);
|
|
785
813
|
if (!e.shop)
|
|
786
|
-
return
|
|
787
|
-
|
|
814
|
+
return v(
|
|
815
|
+
U({
|
|
788
816
|
code: "MISSING_CONFIG",
|
|
789
817
|
message: "shop is required",
|
|
790
818
|
field: "shop",
|
|
791
819
|
expected: "non-empty string"
|
|
792
820
|
})
|
|
793
821
|
);
|
|
794
|
-
const { storefrontApiVersion: t = Qe } = e,
|
|
822
|
+
const { storefrontApiVersion: t = Qe } = e, n = bt({
|
|
795
823
|
shop: e.shop,
|
|
796
824
|
token: e.storefrontPublicToken,
|
|
797
825
|
apiVersion: t,
|
|
798
826
|
customFetch: e.fetch
|
|
799
827
|
});
|
|
800
|
-
return
|
|
801
|
-
async getProducts(
|
|
828
|
+
return D({
|
|
829
|
+
async getProducts(r) {
|
|
802
830
|
const {
|
|
803
831
|
ids: s,
|
|
804
832
|
productMetafields: i = [],
|
|
805
833
|
variantMetafields: a = [],
|
|
806
|
-
maxImages: l =
|
|
807
|
-
maxVariants:
|
|
834
|
+
maxImages: l = B,
|
|
835
|
+
maxVariants: c = G,
|
|
808
836
|
signal: g
|
|
809
|
-
} =
|
|
810
|
-
if (
|
|
811
|
-
return
|
|
837
|
+
} = r, d = me(r);
|
|
838
|
+
if (d.length > 0)
|
|
839
|
+
return v(q({ operation: "getProducts", fields: d }));
|
|
812
840
|
if (s.length === 0)
|
|
813
|
-
return
|
|
814
|
-
const
|
|
841
|
+
return D([]);
|
|
842
|
+
const p = _t({
|
|
815
843
|
maxImages: l,
|
|
816
|
-
maxVariants:
|
|
844
|
+
maxVariants: c,
|
|
817
845
|
productMetafields: i,
|
|
818
846
|
variantMetafields: a
|
|
819
|
-
}),
|
|
820
|
-
for (const h of
|
|
847
|
+
}), u = ge({ ids: s, maxSize: ae }), f = [];
|
|
848
|
+
for (const h of u) {
|
|
821
849
|
const y = { ids: h };
|
|
822
850
|
i.length > 0 && (y.productMetafields = i), a.length > 0 && (y.variantMetafields = a);
|
|
823
|
-
const
|
|
824
|
-
if (
|
|
825
|
-
return
|
|
826
|
-
|
|
851
|
+
const E = await St({ graphqlClient: n, query: p, variables: y, signal: g });
|
|
852
|
+
if (E.error)
|
|
853
|
+
return E;
|
|
854
|
+
f.push(...E.data);
|
|
827
855
|
}
|
|
828
|
-
return
|
|
856
|
+
return D(f);
|
|
829
857
|
},
|
|
830
|
-
async getCollection(
|
|
831
|
-
const { handle: s, collectionMetafields: i = [], includeFilters: a = !1, signal: l } =
|
|
858
|
+
async getCollection(r) {
|
|
859
|
+
const { handle: s, collectionMetafields: i = [], includeFilters: a = !1, signal: l } = r;
|
|
832
860
|
if (!s)
|
|
833
|
-
return
|
|
834
|
-
|
|
861
|
+
return v(
|
|
862
|
+
q({
|
|
835
863
|
operation: "getCollection",
|
|
836
|
-
fields: [
|
|
864
|
+
fields: [C("handle", "REQUIRED_FIELD", "handle is required")]
|
|
837
865
|
})
|
|
838
866
|
);
|
|
839
|
-
const
|
|
867
|
+
const c = yt({ collectionMetafields: i, includeFilters: a }), g = { handle: s };
|
|
840
868
|
i.length > 0 && (g.collectionMetafields = i);
|
|
841
869
|
try {
|
|
842
|
-
const { data:
|
|
843
|
-
if (
|
|
844
|
-
return
|
|
845
|
-
const
|
|
846
|
-
return
|
|
847
|
-
|
|
870
|
+
const { data: d, errors: p } = await n.request(c, { variables: g, signal: l });
|
|
871
|
+
if (p)
|
|
872
|
+
return v(H(p));
|
|
873
|
+
const u = d;
|
|
874
|
+
return u.collection ? D(u.collection) : v(
|
|
875
|
+
$({
|
|
848
876
|
code: "NOT_FOUND",
|
|
849
|
-
source: "
|
|
877
|
+
source: "storefront",
|
|
850
878
|
message: `Collection not found: ${s}`
|
|
851
879
|
})
|
|
852
880
|
);
|
|
853
|
-
} catch (
|
|
854
|
-
return
|
|
881
|
+
} catch (d) {
|
|
882
|
+
return v(Q(d));
|
|
855
883
|
}
|
|
856
884
|
},
|
|
857
|
-
async getCollectionWithProducts(
|
|
885
|
+
async getCollectionWithProducts(r) {
|
|
858
886
|
const {
|
|
859
887
|
handle: s,
|
|
860
888
|
ids: i,
|
|
861
889
|
productMetafields: a = [],
|
|
862
890
|
variantMetafields: l = [],
|
|
863
|
-
collectionMetafields:
|
|
891
|
+
collectionMetafields: c = [],
|
|
864
892
|
includeFilters: g = !1,
|
|
865
|
-
maxImages:
|
|
866
|
-
maxVariants:
|
|
867
|
-
signal:
|
|
868
|
-
} =
|
|
869
|
-
if (s ||
|
|
870
|
-
return
|
|
871
|
-
|
|
893
|
+
maxImages: d = B,
|
|
894
|
+
maxVariants: p = G,
|
|
895
|
+
signal: u
|
|
896
|
+
} = r, f = me(r);
|
|
897
|
+
if (s || f.push(C("handle", "REQUIRED_FIELD", "handle is required")), f.length > 0)
|
|
898
|
+
return v(
|
|
899
|
+
q({
|
|
872
900
|
operation: "getCollectionWithProducts",
|
|
873
|
-
fields:
|
|
901
|
+
fields: f
|
|
874
902
|
})
|
|
875
903
|
);
|
|
876
|
-
const h =
|
|
877
|
-
maxImages:
|
|
878
|
-
maxVariants:
|
|
904
|
+
const h = vt({
|
|
905
|
+
maxImages: d,
|
|
906
|
+
maxVariants: p,
|
|
879
907
|
productMetafields: a,
|
|
880
908
|
variantMetafields: l,
|
|
881
|
-
collectionMetafields:
|
|
909
|
+
collectionMetafields: c,
|
|
882
910
|
includeFilters: g
|
|
883
|
-
}), y = i.length > 0 ? ge({ ids: i, maxSize:
|
|
884
|
-
let
|
|
885
|
-
const
|
|
886
|
-
for (let
|
|
887
|
-
const
|
|
888
|
-
a.length > 0 && (
|
|
911
|
+
}), y = i.length > 0 ? ge({ ids: i, maxSize: ae }) : [[]];
|
|
912
|
+
let E = null;
|
|
913
|
+
const M = [];
|
|
914
|
+
for (let T = 0; T < y.length; T++) {
|
|
915
|
+
const b = { ids: y[T], handle: s };
|
|
916
|
+
a.length > 0 && (b.productMetafields = a), l.length > 0 && (b.variantMetafields = l), c.length > 0 && (b.collectionMetafields = c);
|
|
889
917
|
try {
|
|
890
|
-
const { data:
|
|
891
|
-
if (
|
|
892
|
-
return
|
|
893
|
-
const
|
|
894
|
-
if (
|
|
895
|
-
return
|
|
896
|
-
|
|
918
|
+
const { data: m, errors: _ } = await n.request(h, { variables: b, signal: u });
|
|
919
|
+
if (_)
|
|
920
|
+
return v(H(_));
|
|
921
|
+
const F = m;
|
|
922
|
+
if (T === 0 && (E = F.collection ?? null, !E))
|
|
923
|
+
return v(
|
|
924
|
+
$({
|
|
897
925
|
code: "NOT_FOUND",
|
|
898
|
-
source: "
|
|
926
|
+
source: "storefront",
|
|
899
927
|
message: `Collection not found: ${s}`
|
|
900
928
|
})
|
|
901
929
|
);
|
|
902
|
-
const
|
|
903
|
-
|
|
904
|
-
} catch (
|
|
905
|
-
return
|
|
930
|
+
const S = (F.nodes ?? []).filter((A) => A !== null);
|
|
931
|
+
M.push(...S);
|
|
932
|
+
} catch (m) {
|
|
933
|
+
return v(Q(m));
|
|
906
934
|
}
|
|
907
935
|
}
|
|
908
|
-
return
|
|
936
|
+
return D({ collection: E, products: M });
|
|
909
937
|
},
|
|
910
|
-
async getPage(
|
|
911
|
-
const { handle: s, pageMetafields: i = [], signal: a } =
|
|
938
|
+
async getPage(r) {
|
|
939
|
+
const { handle: s, pageMetafields: i = [], signal: a } = r;
|
|
912
940
|
if (!s)
|
|
913
|
-
return
|
|
914
|
-
|
|
941
|
+
return v(
|
|
942
|
+
q({
|
|
915
943
|
operation: "getPage",
|
|
916
|
-
fields: [
|
|
944
|
+
fields: [C("handle", "REQUIRED_FIELD", "handle is required")]
|
|
917
945
|
})
|
|
918
946
|
);
|
|
919
|
-
const l =
|
|
920
|
-
i.length > 0 && (
|
|
947
|
+
const l = It({ pageMetafields: i }), c = { handle: s };
|
|
948
|
+
i.length > 0 && (c.pageMetafields = i);
|
|
921
949
|
try {
|
|
922
|
-
const { data: g, errors:
|
|
923
|
-
if (
|
|
924
|
-
return
|
|
925
|
-
const
|
|
926
|
-
return
|
|
927
|
-
|
|
950
|
+
const { data: g, errors: d } = await n.request(l, { variables: c, signal: a });
|
|
951
|
+
if (d)
|
|
952
|
+
return v(H(d));
|
|
953
|
+
const p = g;
|
|
954
|
+
return p.page ? D(p.page) : v(
|
|
955
|
+
$({
|
|
928
956
|
code: "NOT_FOUND",
|
|
929
|
-
source: "
|
|
957
|
+
source: "storefront",
|
|
930
958
|
message: `Page not found: ${s}`
|
|
931
959
|
})
|
|
932
960
|
);
|
|
933
961
|
} catch (g) {
|
|
934
|
-
return
|
|
962
|
+
return v(Q(g));
|
|
935
963
|
}
|
|
936
964
|
},
|
|
937
|
-
async getPageWithProducts(
|
|
965
|
+
async getPageWithProducts(r) {
|
|
938
966
|
const {
|
|
939
967
|
handle: s,
|
|
940
968
|
ids: i,
|
|
941
969
|
productMetafields: a = [],
|
|
942
970
|
variantMetafields: l = [],
|
|
943
|
-
pageMetafields:
|
|
944
|
-
maxImages: g =
|
|
945
|
-
maxVariants:
|
|
946
|
-
signal:
|
|
947
|
-
} =
|
|
948
|
-
if (s ||
|
|
949
|
-
return
|
|
950
|
-
|
|
971
|
+
pageMetafields: c = [],
|
|
972
|
+
maxImages: g = B,
|
|
973
|
+
maxVariants: d = G,
|
|
974
|
+
signal: p
|
|
975
|
+
} = r, u = me(r);
|
|
976
|
+
if (s || u.push(C("handle", "REQUIRED_FIELD", "handle is required")), u.length > 0)
|
|
977
|
+
return v(
|
|
978
|
+
q({ operation: "getPageWithProducts", fields: u })
|
|
951
979
|
);
|
|
952
|
-
const
|
|
980
|
+
const f = Et({
|
|
953
981
|
maxImages: g,
|
|
954
|
-
maxVariants:
|
|
982
|
+
maxVariants: d,
|
|
955
983
|
productMetafields: a,
|
|
956
984
|
variantMetafields: l,
|
|
957
|
-
pageMetafields:
|
|
958
|
-
}), h = i.length > 0 ? ge({ ids: i, maxSize:
|
|
985
|
+
pageMetafields: c
|
|
986
|
+
}), h = i.length > 0 ? ge({ ids: i, maxSize: ae }) : [[]];
|
|
959
987
|
let y = null;
|
|
960
|
-
const
|
|
961
|
-
for (let
|
|
962
|
-
const
|
|
963
|
-
a.length > 0 && (
|
|
988
|
+
const E = [];
|
|
989
|
+
for (let M = 0; M < h.length; M++) {
|
|
990
|
+
const w = { ids: h[M], handle: s };
|
|
991
|
+
a.length > 0 && (w.productMetafields = a), l.length > 0 && (w.variantMetafields = l), c.length > 0 && (w.pageMetafields = c);
|
|
964
992
|
try {
|
|
965
|
-
const { data:
|
|
966
|
-
if (
|
|
967
|
-
return
|
|
968
|
-
const
|
|
969
|
-
if (
|
|
970
|
-
return
|
|
971
|
-
|
|
993
|
+
const { data: b, errors: m } = await n.request(f, { variables: w, signal: p });
|
|
994
|
+
if (m)
|
|
995
|
+
return v(H(m));
|
|
996
|
+
const _ = b;
|
|
997
|
+
if (M === 0 && (y = _.page ?? null, !y))
|
|
998
|
+
return v(
|
|
999
|
+
$({
|
|
972
1000
|
code: "NOT_FOUND",
|
|
973
|
-
source: "
|
|
1001
|
+
source: "storefront",
|
|
974
1002
|
message: `Page not found: ${s}`
|
|
975
1003
|
})
|
|
976
1004
|
);
|
|
977
|
-
const
|
|
978
|
-
|
|
979
|
-
} catch (
|
|
980
|
-
return
|
|
1005
|
+
const F = (_.nodes ?? []).filter((S) => S !== null);
|
|
1006
|
+
E.push(...F);
|
|
1007
|
+
} catch (b) {
|
|
1008
|
+
return v(Q(b));
|
|
981
1009
|
}
|
|
982
1010
|
}
|
|
983
|
-
return
|
|
1011
|
+
return D({ page: y, products: E });
|
|
984
1012
|
}
|
|
985
1013
|
});
|
|
986
1014
|
}
|
|
987
1015
|
function me(e) {
|
|
988
1016
|
const t = [];
|
|
989
|
-
e.maxImages !== void 0 && (e.maxImages < ce || e.maxImages >
|
|
990
|
-
|
|
1017
|
+
e.maxImages !== void 0 && (e.maxImages < ce || e.maxImages > se) && t.push(
|
|
1018
|
+
C(
|
|
991
1019
|
"maxImages",
|
|
992
1020
|
"OUT_OF_RANGE",
|
|
993
|
-
`maxImages must be between ${ce} and ${
|
|
1021
|
+
`maxImages must be between ${ce} and ${se}`,
|
|
994
1022
|
{
|
|
995
1023
|
value: e.maxImages,
|
|
996
|
-
constraints: { min: ce, max:
|
|
1024
|
+
constraints: { min: ce, max: se }
|
|
997
1025
|
}
|
|
998
1026
|
)
|
|
999
|
-
), e.maxVariants !== void 0 && (e.maxVariants < le || e.maxVariants >
|
|
1000
|
-
|
|
1027
|
+
), e.maxVariants !== void 0 && (e.maxVariants < le || e.maxVariants > ie) && t.push(
|
|
1028
|
+
C(
|
|
1001
1029
|
"maxVariants",
|
|
1002
1030
|
"OUT_OF_RANGE",
|
|
1003
|
-
`maxVariants must be between ${le} and ${
|
|
1031
|
+
`maxVariants must be between ${le} and ${ie}`,
|
|
1004
1032
|
{
|
|
1005
1033
|
value: e.maxVariants,
|
|
1006
|
-
constraints: { min: le, max:
|
|
1034
|
+
constraints: { min: le, max: ie }
|
|
1007
1035
|
}
|
|
1008
1036
|
)
|
|
1009
1037
|
);
|
|
1010
|
-
for (const
|
|
1011
|
-
(!
|
|
1012
|
-
|
|
1038
|
+
for (const n of e.productMetafields ?? [])
|
|
1039
|
+
(!n.namespace || !n.key) && t.push(
|
|
1040
|
+
C(
|
|
1013
1041
|
"productMetafields",
|
|
1014
1042
|
"REQUIRED_FIELD",
|
|
1015
1043
|
"Metafield identifier requires both namespace and key",
|
|
1016
1044
|
{
|
|
1017
|
-
value:
|
|
1045
|
+
value: n,
|
|
1018
1046
|
expected: "{ namespace: string, key: string }"
|
|
1019
1047
|
}
|
|
1020
1048
|
)
|
|
1021
1049
|
);
|
|
1022
|
-
for (const
|
|
1023
|
-
(!
|
|
1024
|
-
|
|
1050
|
+
for (const n of e.variantMetafields ?? [])
|
|
1051
|
+
(!n.namespace || !n.key) && t.push(
|
|
1052
|
+
C(
|
|
1025
1053
|
"variantMetafields",
|
|
1026
1054
|
"REQUIRED_FIELD",
|
|
1027
1055
|
"Metafield identifier requires both namespace and key",
|
|
1028
1056
|
{
|
|
1029
|
-
value:
|
|
1057
|
+
value: n,
|
|
1030
1058
|
expected: "{ namespace: string, key: string }"
|
|
1031
1059
|
}
|
|
1032
1060
|
)
|
|
1033
1061
|
);
|
|
1034
1062
|
return t;
|
|
1035
1063
|
}
|
|
1036
|
-
async function
|
|
1037
|
-
|
|
1064
|
+
async function St({
|
|
1065
|
+
graphqlClient: e,
|
|
1038
1066
|
query: t,
|
|
1039
|
-
variables:
|
|
1067
|
+
variables: n,
|
|
1040
1068
|
signal: o
|
|
1041
1069
|
}) {
|
|
1042
1070
|
try {
|
|
1043
|
-
const { data:
|
|
1071
|
+
const { data: r, errors: s } = await e.request(t, { variables: n, signal: o });
|
|
1044
1072
|
if (s)
|
|
1045
|
-
return
|
|
1046
|
-
const i = (
|
|
1073
|
+
return v(H(s));
|
|
1074
|
+
const i = (r?.nodes ?? []).filter(
|
|
1047
1075
|
(a) => a !== null
|
|
1048
1076
|
);
|
|
1049
|
-
return
|
|
1050
|
-
} catch (
|
|
1051
|
-
return
|
|
1077
|
+
return D(i);
|
|
1078
|
+
} catch (r) {
|
|
1079
|
+
return v(Q(r));
|
|
1052
1080
|
}
|
|
1053
1081
|
}
|
|
1054
|
-
function
|
|
1082
|
+
function H(e) {
|
|
1055
1083
|
const t = e.networkStatusCode;
|
|
1056
|
-
return t === 401 ?
|
|
1084
|
+
return t === 401 ? $({
|
|
1057
1085
|
code: "UNAUTHORIZED",
|
|
1058
|
-
source: "
|
|
1086
|
+
source: "storefront",
|
|
1059
1087
|
message: "Unauthorized: Invalid or missing storefront access token",
|
|
1060
1088
|
status: t
|
|
1061
|
-
}) : t === 403 ?
|
|
1089
|
+
}) : t === 403 ? $({
|
|
1062
1090
|
code: "FORBIDDEN",
|
|
1063
|
-
source: "
|
|
1091
|
+
source: "storefront",
|
|
1064
1092
|
message: "Forbidden: Access denied to the requested resource",
|
|
1065
1093
|
status: t
|
|
1066
|
-
}) : t === 429 ?
|
|
1094
|
+
}) : t === 429 ? $({
|
|
1067
1095
|
code: "RATE_LIMITED",
|
|
1068
|
-
source: "
|
|
1096
|
+
source: "storefront",
|
|
1069
1097
|
message: "Rate limited: Too many requests to the Storefront API",
|
|
1070
1098
|
status: t
|
|
1071
|
-
}) : t !== void 0 && t >= 500 ?
|
|
1099
|
+
}) : t !== void 0 && t >= 500 ? $({
|
|
1072
1100
|
code: "SERVICE_UNAVAILABLE",
|
|
1073
|
-
source: "
|
|
1074
|
-
message: `
|
|
1101
|
+
source: "storefront",
|
|
1102
|
+
message: `Storefront service error: ${e.message ?? `HTTP ${t}`}`,
|
|
1075
1103
|
status: t
|
|
1076
|
-
}) :
|
|
1104
|
+
}) : $({
|
|
1077
1105
|
code: "GRAPHQL_ERROR",
|
|
1078
|
-
source: "
|
|
1106
|
+
source: "storefront",
|
|
1079
1107
|
message: e.message ?? "GraphQL request failed",
|
|
1080
1108
|
status: t,
|
|
1081
1109
|
details: {
|
|
1082
|
-
graphqlErrors: e.graphQLErrors?.map((
|
|
1083
|
-
message:
|
|
1084
|
-
path:
|
|
1085
|
-
extensions:
|
|
1110
|
+
graphqlErrors: e.graphQLErrors?.map((n) => ({
|
|
1111
|
+
message: n.message,
|
|
1112
|
+
path: n.path,
|
|
1113
|
+
extensions: n.extensions
|
|
1086
1114
|
}))
|
|
1087
1115
|
}
|
|
1088
1116
|
});
|
|
1089
1117
|
}
|
|
1090
|
-
function
|
|
1118
|
+
function Q(e) {
|
|
1091
1119
|
if (e instanceof Error && (e.name === "AbortError" || e.name === "TimeoutError")) {
|
|
1092
1120
|
const t = e.name === "TimeoutError" || e.message.includes("timeout");
|
|
1093
1121
|
return J({
|
|
@@ -1102,376 +1130,457 @@ function K(e) {
|
|
|
1102
1130
|
cause: e
|
|
1103
1131
|
});
|
|
1104
1132
|
}
|
|
1105
|
-
const
|
|
1106
|
-
function
|
|
1107
|
-
return typeof window > "u" || !window.localStorage ? null :
|
|
1133
|
+
const Mt = "cb-sdk-store";
|
|
1134
|
+
function At(e) {
|
|
1135
|
+
return typeof window > "u" || !window.localStorage ? null : {
|
|
1136
|
+
read: () => window.localStorage.getItem(e),
|
|
1137
|
+
write: (t) => window.localStorage.setItem(e, t),
|
|
1138
|
+
remove: () => window.localStorage.removeItem(e)
|
|
1139
|
+
};
|
|
1108
1140
|
}
|
|
1109
|
-
function
|
|
1110
|
-
|
|
1141
|
+
function dn(e, t) {
|
|
1142
|
+
return {
|
|
1143
|
+
read() {
|
|
1144
|
+
try {
|
|
1145
|
+
return t.readFileSync(e, "utf-8");
|
|
1146
|
+
} catch {
|
|
1147
|
+
return null;
|
|
1148
|
+
}
|
|
1149
|
+
},
|
|
1150
|
+
write(n) {
|
|
1151
|
+
try {
|
|
1152
|
+
t.writeFileSync(e, n, "utf-8");
|
|
1153
|
+
} catch {
|
|
1154
|
+
}
|
|
1155
|
+
},
|
|
1156
|
+
remove() {
|
|
1157
|
+
try {
|
|
1158
|
+
t.unlinkSync(e);
|
|
1159
|
+
} catch {
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
};
|
|
1163
|
+
}
|
|
1164
|
+
function Tt(e) {
|
|
1165
|
+
typeof requestIdleCallback == "function" ? requestIdleCallback(e, { timeout: nt }) : setTimeout(e, 0);
|
|
1111
1166
|
}
|
|
1112
|
-
function
|
|
1113
|
-
return [...e].sort((t,
|
|
1167
|
+
function Oe(e) {
|
|
1168
|
+
return [...e].sort((t, n) => n[1].timestamp - t[1].timestamp);
|
|
1114
1169
|
}
|
|
1115
|
-
function
|
|
1116
|
-
storageKey: e =
|
|
1170
|
+
function Pt({
|
|
1171
|
+
storageKey: e = Mt,
|
|
1117
1172
|
maxProducts: t = ke,
|
|
1118
|
-
maxQueries:
|
|
1173
|
+
maxQueries: n = Ce,
|
|
1174
|
+
adapter: o
|
|
1119
1175
|
} = {}) {
|
|
1176
|
+
const r = o ?? At(e);
|
|
1177
|
+
let s = 0;
|
|
1120
1178
|
return {
|
|
1121
|
-
save(
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1179
|
+
save(i) {
|
|
1180
|
+
if (!r) return;
|
|
1181
|
+
const a = ++s;
|
|
1182
|
+
Tt(() => {
|
|
1183
|
+
if (a === s)
|
|
1184
|
+
try {
|
|
1185
|
+
const l = {
|
|
1186
|
+
products: Oe(i.products).slice(
|
|
1187
|
+
0,
|
|
1188
|
+
t
|
|
1189
|
+
),
|
|
1190
|
+
queries: Oe(i.queries).slice(0, n),
|
|
1191
|
+
collections: i.collections,
|
|
1192
|
+
version: pe
|
|
1193
|
+
};
|
|
1194
|
+
r.write(JSON.stringify(l));
|
|
1195
|
+
} catch {
|
|
1196
|
+
}
|
|
1137
1197
|
});
|
|
1138
1198
|
},
|
|
1139
1199
|
restore() {
|
|
1140
|
-
|
|
1141
|
-
if (!o) return null;
|
|
1200
|
+
if (!r) return null;
|
|
1142
1201
|
try {
|
|
1143
|
-
const
|
|
1144
|
-
if (!
|
|
1145
|
-
const
|
|
1146
|
-
return
|
|
1202
|
+
const i = r.read();
|
|
1203
|
+
if (!i) return null;
|
|
1204
|
+
const a = JSON.parse(i);
|
|
1205
|
+
return a.version !== pe || !Array.isArray(a.products) || !Array.isArray(a.queries) ? (r.remove(), null) : a;
|
|
1147
1206
|
} catch {
|
|
1148
|
-
return
|
|
1207
|
+
return r.remove(), null;
|
|
1149
1208
|
}
|
|
1150
1209
|
},
|
|
1151
1210
|
clear() {
|
|
1152
|
-
|
|
1211
|
+
s++, r?.remove();
|
|
1153
1212
|
}
|
|
1154
1213
|
};
|
|
1155
1214
|
}
|
|
1156
|
-
function
|
|
1215
|
+
function wt(e, t) {
|
|
1157
1216
|
if (e.size <= t) return;
|
|
1158
|
-
const o = [...e.entries()].sort((
|
|
1159
|
-
for (const [
|
|
1160
|
-
e.delete(
|
|
1217
|
+
const o = [...e.entries()].sort((r, s) => r[1].timestamp - s[1].timestamp).slice(0, e.size - t);
|
|
1218
|
+
for (const [r] of o)
|
|
1219
|
+
e.delete(r);
|
|
1161
1220
|
}
|
|
1162
|
-
function
|
|
1221
|
+
function Ot(e, t) {
|
|
1163
1222
|
if (e.size <= t) return;
|
|
1164
|
-
const
|
|
1165
|
-
for (const [
|
|
1166
|
-
s.value &&
|
|
1167
|
-
|
|
1168
|
-
const o =
|
|
1169
|
-
for (const [
|
|
1170
|
-
const s = e.get(
|
|
1171
|
-
s && (s.value = null), e.delete(
|
|
1223
|
+
const n = [];
|
|
1224
|
+
for (const [r, s] of e)
|
|
1225
|
+
s.value && n.push([r, s.value.timestamp]);
|
|
1226
|
+
n.sort((r, s) => r[1] - s[1]);
|
|
1227
|
+
const o = n.slice(0, e.size - t);
|
|
1228
|
+
for (const [r] of o) {
|
|
1229
|
+
const s = e.get(r);
|
|
1230
|
+
s && (s.value = null), e.delete(r);
|
|
1172
1231
|
}
|
|
1173
1232
|
}
|
|
1174
|
-
function
|
|
1233
|
+
function Rt(e = {}) {
|
|
1175
1234
|
const {
|
|
1176
1235
|
ttl: t = Xe,
|
|
1177
|
-
maxProducts:
|
|
1178
|
-
maxQueries: o =
|
|
1179
|
-
storageKey:
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1236
|
+
maxProducts: n = ke,
|
|
1237
|
+
maxQueries: o = Ce,
|
|
1238
|
+
storageKey: r,
|
|
1239
|
+
storageAdapter: s
|
|
1240
|
+
} = e, i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map(), g = Pt({
|
|
1241
|
+
storageKey: r,
|
|
1242
|
+
maxProducts: n,
|
|
1243
|
+
maxQueries: o,
|
|
1244
|
+
adapter: s
|
|
1245
|
+
});
|
|
1246
|
+
function d(u) {
|
|
1247
|
+
return Date.now() - u > t;
|
|
1183
1248
|
}
|
|
1184
|
-
function
|
|
1185
|
-
let
|
|
1186
|
-
return
|
|
1249
|
+
function p(u) {
|
|
1250
|
+
let f = c.get(u);
|
|
1251
|
+
return f || (f = L(null), c.set(u, f)), f;
|
|
1187
1252
|
}
|
|
1188
1253
|
return {
|
|
1189
1254
|
products: {
|
|
1190
|
-
get(
|
|
1191
|
-
const
|
|
1192
|
-
if (
|
|
1193
|
-
if (
|
|
1194
|
-
|
|
1255
|
+
get(u) {
|
|
1256
|
+
const f = i.get(u);
|
|
1257
|
+
if (f) {
|
|
1258
|
+
if (d(f.timestamp)) {
|
|
1259
|
+
i.delete(u);
|
|
1195
1260
|
return;
|
|
1196
1261
|
}
|
|
1197
|
-
return
|
|
1262
|
+
return f.data;
|
|
1198
1263
|
}
|
|
1199
1264
|
},
|
|
1200
|
-
getMany(
|
|
1201
|
-
const
|
|
1202
|
-
for (const
|
|
1203
|
-
const
|
|
1204
|
-
|
|
1265
|
+
getMany(u) {
|
|
1266
|
+
const f = [], h = [];
|
|
1267
|
+
for (const y of u) {
|
|
1268
|
+
const E = i.get(y);
|
|
1269
|
+
E && !d(E.timestamp) ? f.push(E.data) : h.push(y);
|
|
1205
1270
|
}
|
|
1206
|
-
return { cached:
|
|
1271
|
+
return { cached: f, missing: h };
|
|
1207
1272
|
},
|
|
1208
|
-
set(
|
|
1209
|
-
const
|
|
1210
|
-
for (const
|
|
1211
|
-
|
|
1212
|
-
|
|
1273
|
+
set(u) {
|
|
1274
|
+
const f = Date.now(), h = Array.isArray(u) ? u : [u];
|
|
1275
|
+
for (const y of h)
|
|
1276
|
+
i.set(y.gid, { data: y, timestamp: f });
|
|
1277
|
+
wt(i, n);
|
|
1213
1278
|
},
|
|
1214
|
-
has(
|
|
1215
|
-
const
|
|
1216
|
-
return
|
|
1279
|
+
has(u) {
|
|
1280
|
+
const f = i.get(u);
|
|
1281
|
+
return f != null && !d(f.timestamp);
|
|
1217
1282
|
}
|
|
1218
1283
|
},
|
|
1219
1284
|
queries: {
|
|
1220
|
-
get(
|
|
1221
|
-
return
|
|
1285
|
+
get(u) {
|
|
1286
|
+
return p(u);
|
|
1222
1287
|
},
|
|
1223
|
-
set(
|
|
1224
|
-
const
|
|
1225
|
-
|
|
1288
|
+
set(u, f) {
|
|
1289
|
+
const h = p(u);
|
|
1290
|
+
h.value = { data: f, timestamp: Date.now() }, Ot(c, o);
|
|
1226
1291
|
},
|
|
1227
|
-
isExpired(
|
|
1228
|
-
const
|
|
1229
|
-
return
|
|
1292
|
+
isExpired(u) {
|
|
1293
|
+
const f = c.get(u);
|
|
1294
|
+
return f?.value ? d(f.value.timestamp) : !0;
|
|
1230
1295
|
},
|
|
1231
|
-
invalidate(
|
|
1232
|
-
for (const [
|
|
1233
|
-
|
|
1296
|
+
invalidate(u) {
|
|
1297
|
+
for (const [f, h] of c)
|
|
1298
|
+
f.includes(u) && (h.value = null);
|
|
1234
1299
|
}
|
|
1235
1300
|
},
|
|
1236
1301
|
collections: {
|
|
1237
|
-
get(
|
|
1238
|
-
return
|
|
1302
|
+
get(u) {
|
|
1303
|
+
return a.get(u);
|
|
1239
1304
|
},
|
|
1240
|
-
set(
|
|
1241
|
-
|
|
1305
|
+
set(u, f) {
|
|
1306
|
+
a.set(u, { ...f, handle: u });
|
|
1242
1307
|
},
|
|
1243
|
-
delete(
|
|
1244
|
-
|
|
1308
|
+
delete(u) {
|
|
1309
|
+
a.delete(u);
|
|
1245
1310
|
}
|
|
1246
1311
|
},
|
|
1247
1312
|
pages: {
|
|
1248
|
-
get(
|
|
1249
|
-
return
|
|
1313
|
+
get(u) {
|
|
1314
|
+
return l.get(u);
|
|
1250
1315
|
},
|
|
1251
|
-
set(
|
|
1252
|
-
|
|
1316
|
+
set(u, f) {
|
|
1317
|
+
l.set(u, { ...f, handle: u });
|
|
1253
1318
|
},
|
|
1254
|
-
delete(
|
|
1255
|
-
|
|
1319
|
+
delete(u) {
|
|
1320
|
+
l.delete(u);
|
|
1256
1321
|
}
|
|
1257
1322
|
},
|
|
1258
1323
|
persist() {
|
|
1259
|
-
const
|
|
1260
|
-
for (const [
|
|
1261
|
-
|
|
1262
|
-
for (const [
|
|
1263
|
-
|
|
1264
|
-
for (const [
|
|
1265
|
-
|
|
1266
|
-
|
|
1324
|
+
const u = [], f = [], h = [];
|
|
1325
|
+
for (const [y, E] of i)
|
|
1326
|
+
d(E.timestamp) || u.push([y, E]);
|
|
1327
|
+
for (const [y, E] of c)
|
|
1328
|
+
E.value && !d(E.value.timestamp) && f.push([y, E.value]);
|
|
1329
|
+
for (const [y, E] of a)
|
|
1330
|
+
h.push([y, E]);
|
|
1331
|
+
g.save({ products: u, queries: f, collections: h });
|
|
1267
1332
|
},
|
|
1268
1333
|
restore() {
|
|
1269
|
-
const
|
|
1270
|
-
if (
|
|
1271
|
-
for (const [
|
|
1272
|
-
|
|
1273
|
-
for (const [
|
|
1274
|
-
if (!
|
|
1275
|
-
const
|
|
1276
|
-
|
|
1334
|
+
const u = g.restore();
|
|
1335
|
+
if (u) {
|
|
1336
|
+
for (const [f, h] of u.products)
|
|
1337
|
+
d(h.timestamp) || i.set(f, h);
|
|
1338
|
+
for (const [f, h] of u.queries)
|
|
1339
|
+
if (!d(h.timestamp)) {
|
|
1340
|
+
const y = p(f);
|
|
1341
|
+
y.value = h;
|
|
1277
1342
|
}
|
|
1278
|
-
for (const [
|
|
1279
|
-
|
|
1343
|
+
for (const [f, h] of u.collections)
|
|
1344
|
+
a.set(f, h);
|
|
1280
1345
|
}
|
|
1281
1346
|
},
|
|
1282
1347
|
clear() {
|
|
1283
|
-
|
|
1284
|
-
for (const
|
|
1285
|
-
|
|
1348
|
+
i.clear();
|
|
1349
|
+
for (const u of c.values()) u.value = null;
|
|
1350
|
+
c.clear(), a.clear(), l.clear(), g.clear();
|
|
1286
1351
|
},
|
|
1287
1352
|
get stats() {
|
|
1288
1353
|
return {
|
|
1289
|
-
products:
|
|
1290
|
-
queries:
|
|
1291
|
-
collections:
|
|
1292
|
-
pages:
|
|
1354
|
+
products: i.size,
|
|
1355
|
+
queries: c.size,
|
|
1356
|
+
collections: a.size,
|
|
1357
|
+
pages: l.size
|
|
1293
1358
|
};
|
|
1294
1359
|
}
|
|
1295
1360
|
};
|
|
1296
1361
|
}
|
|
1297
|
-
function
|
|
1298
|
-
return
|
|
1299
|
-
|
|
1362
|
+
function Le(e, t) {
|
|
1363
|
+
return `gid://shopify/${e}/${t}`;
|
|
1364
|
+
}
|
|
1365
|
+
function kt(e) {
|
|
1366
|
+
return Le("Product", e);
|
|
1367
|
+
}
|
|
1368
|
+
function Ct(e) {
|
|
1369
|
+
return Le("ProductVariant", e);
|
|
1370
|
+
}
|
|
1371
|
+
const Re = (e) => encodeURIComponent(e).replace(/-/g, "%2D");
|
|
1372
|
+
function Ve({
|
|
1373
|
+
type: e,
|
|
1374
|
+
selectedOptions: t
|
|
1375
|
+
}) {
|
|
1376
|
+
if (t.length === 0)
|
|
1377
|
+
return `${e}-`;
|
|
1378
|
+
const n = t.map(({ name: o, value: r }) => `${Re(o)}:${Re(r)}`).join("-");
|
|
1379
|
+
return `${e}-${n}`;
|
|
1380
|
+
}
|
|
1381
|
+
function Ue(e) {
|
|
1382
|
+
return e.product_id ?? e.id;
|
|
1383
|
+
}
|
|
1384
|
+
function he(e) {
|
|
1385
|
+
return kt(Ue(e));
|
|
1386
|
+
}
|
|
1387
|
+
function Pe(e, t = []) {
|
|
1388
|
+
return Object.entries(e).filter(([n, o]) => o != null && !t.includes(n)).sort(([n], [o]) => n.localeCompare(o)).map(
|
|
1389
|
+
([n, o]) => `${encodeURIComponent(n)}=${encodeURIComponent(typeof o == "object" ? JSON.stringify(o) : String(o))}`
|
|
1300
1390
|
).join("&");
|
|
1301
1391
|
}
|
|
1302
|
-
function
|
|
1392
|
+
function Dt(e, t = {}) {
|
|
1303
1393
|
if (!e?.trim()) return;
|
|
1304
|
-
const
|
|
1305
|
-
return o ? `${
|
|
1394
|
+
const n = `/browse/${encodeURIComponent(e)}`, o = Pe(t, ["collectionHandle", "signal"]);
|
|
1395
|
+
return o ? `${n}?${o}` : n;
|
|
1306
1396
|
}
|
|
1307
|
-
function
|
|
1397
|
+
function Nt(e, t = {}) {
|
|
1308
1398
|
if (!e?.trim()) return;
|
|
1309
|
-
const
|
|
1310
|
-
return o ? `${
|
|
1399
|
+
const n = `/search/${encodeURIComponent(e)}`, o = Pe(t, ["query", "signal"]);
|
|
1400
|
+
return o ? `${n}?${o}` : n;
|
|
1311
1401
|
}
|
|
1312
|
-
function
|
|
1402
|
+
function qt(e, t = {}) {
|
|
1313
1403
|
if (!e?.trim()) return;
|
|
1314
|
-
const
|
|
1315
|
-
return o ? `${
|
|
1404
|
+
const n = `/blocks/${encodeURIComponent(e)}`, o = Pe(t, ["blockId", "signal"]);
|
|
1405
|
+
return o ? `${n}?${o}` : n;
|
|
1316
1406
|
}
|
|
1317
|
-
var
|
|
1318
|
-
function
|
|
1407
|
+
var _e = /* @__PURE__ */ ((e) => (e.Equal = "eq", e.NotEqual = "not_eq", e.In = "in", e.NotIn = "not_in", e.GreaterThan = "gt", e.GreaterThanOrEqual = "gte", e.LessThan = "lt", e.LessThanOrEqual = "lte", e.Exists = "exists", e.NotExists = "not_exists", e))(_e || {}), xe = /* @__PURE__ */ ((e) => (e.And = "AND", e.Or = "OR", e))(xe || {});
|
|
1408
|
+
function fn(e, t) {
|
|
1319
1409
|
return { property: e, operator: "eq", values: [t] };
|
|
1320
1410
|
}
|
|
1321
|
-
function
|
|
1411
|
+
function gn(e, t) {
|
|
1322
1412
|
return { property: e, operator: "not_eq", values: [t] };
|
|
1323
1413
|
}
|
|
1324
|
-
function
|
|
1414
|
+
function mn(e, t) {
|
|
1325
1415
|
return { property: e, operator: "in", values: t };
|
|
1326
1416
|
}
|
|
1327
|
-
function
|
|
1417
|
+
function pn(e, t) {
|
|
1328
1418
|
return { property: e, operator: "not_in", values: t };
|
|
1329
1419
|
}
|
|
1330
|
-
function
|
|
1420
|
+
function hn(e, t) {
|
|
1331
1421
|
return { property: e, operator: "gt", values: [t] };
|
|
1332
1422
|
}
|
|
1333
|
-
function
|
|
1423
|
+
function _n(e, t) {
|
|
1334
1424
|
return { property: e, operator: "gte", values: [t] };
|
|
1335
1425
|
}
|
|
1336
|
-
function
|
|
1426
|
+
function vn(e, t) {
|
|
1337
1427
|
return { property: e, operator: "lt", values: [t] };
|
|
1338
1428
|
}
|
|
1339
|
-
function
|
|
1429
|
+
function yn(e, t) {
|
|
1340
1430
|
return { property: e, operator: "lte", values: [t] };
|
|
1341
1431
|
}
|
|
1342
|
-
function
|
|
1432
|
+
function In(e) {
|
|
1343
1433
|
return { property: e, operator: "exists", values: [] };
|
|
1344
1434
|
}
|
|
1345
|
-
function
|
|
1435
|
+
function En(e) {
|
|
1346
1436
|
return { property: e, operator: "not_exists", values: [] };
|
|
1347
1437
|
}
|
|
1348
|
-
function
|
|
1438
|
+
function $t(...e) {
|
|
1349
1439
|
return { conditional: "AND", expressions: e };
|
|
1350
1440
|
}
|
|
1351
|
-
function
|
|
1441
|
+
function bn(...e) {
|
|
1352
1442
|
return { conditional: "OR", expressions: e };
|
|
1353
1443
|
}
|
|
1354
|
-
function
|
|
1444
|
+
function Lt(e) {
|
|
1355
1445
|
return "conditional" in e;
|
|
1356
1446
|
}
|
|
1357
|
-
function
|
|
1358
|
-
return
|
|
1359
|
-
}
|
|
1360
|
-
function Dt(e, t) {
|
|
1361
|
-
return `gid://shopify/${e}/${t}`;
|
|
1362
|
-
}
|
|
1363
|
-
function Ct(e) {
|
|
1364
|
-
return Dt("Product", e);
|
|
1447
|
+
function Fn(e) {
|
|
1448
|
+
return Lt(e) ? e : $t(e);
|
|
1365
1449
|
}
|
|
1366
|
-
function
|
|
1367
|
-
|
|
1368
|
-
|
|
1450
|
+
function Vt({
|
|
1451
|
+
layers: e,
|
|
1452
|
+
currencyCode: t = et,
|
|
1453
|
+
formatPrice: n = rt,
|
|
1454
|
+
swatches: o = [],
|
|
1455
|
+
breakoutContext: r
|
|
1369
1456
|
}) {
|
|
1370
|
-
const
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1457
|
+
const s = Ue(e), i = he(e), a = e.title, l = e.handle ?? "", c = e.vendor ?? "", g = e.product_type ?? "", d = e.body_html ?? "", p = e.available ?? !1, u = e.is_gift_card ?? !1, f = e.tags ?? [], h = Ut(e), y = xt(e.price_range, t, n), E = Bt(e, o), M = jt(e, t, n), T = M.map((I) => I.compareAtPrice).filter((I) => I !== null), w = T.length > 0 ? {
|
|
1458
|
+
min: T.reduce((I, k) => I.amount < k.amount ? I : k),
|
|
1459
|
+
max: T.reduce((I, k) => I.amount > k.amount ? I : k)
|
|
1460
|
+
} : void 0, b = e.first_or_matched_variant ? Gt(e.first_or_matched_variant) : [], m = Ve({ type: "Product", selectedOptions: b }), _ = e.metafields ?? {}, F = e.category ? {
|
|
1461
|
+
id: e.category.id,
|
|
1462
|
+
name: e.category.name,
|
|
1463
|
+
fullName: e.category.full_name,
|
|
1464
|
+
isLeaf: e.category.is_leaf,
|
|
1465
|
+
isRoot: e.category.is_root
|
|
1466
|
+
} : null, S = e.featured_media ? {
|
|
1467
|
+
mediaContentType: e.featured_media.mediaContentType ?? null,
|
|
1468
|
+
url: e.featured_media.src,
|
|
1469
|
+
alt: e.featured_media.alt ?? "",
|
|
1470
|
+
width: e.featured_media.width,
|
|
1471
|
+
height: e.featured_media.height
|
|
1472
|
+
} : null, A = e.named_tags ? Array.isArray(e.named_tags) ? void 0 : Object.entries(e.named_tags).map(([I, k]) => ({ name: I, value: k })) : void 0, R = e.first_or_matched_variant ? M.find((I) => I.numericId === e.first_or_matched_variant.id) ?? null : null;
|
|
1473
|
+
let O, P;
|
|
1474
|
+
if (r?.isVariantTile) {
|
|
1475
|
+
P = r.variantId;
|
|
1476
|
+
const I = M.find((k) => k.numericId === P);
|
|
1477
|
+
if (I) {
|
|
1478
|
+
const k = new Set(r.optionCodes);
|
|
1479
|
+
O = I.selectedOptions.filter((V) => k.has(V.name));
|
|
1480
|
+
}
|
|
1481
|
+
}
|
|
1388
1482
|
return {
|
|
1389
|
-
id:
|
|
1483
|
+
id: m,
|
|
1390
1484
|
gid: i,
|
|
1391
1485
|
numericId: s,
|
|
1392
1486
|
title: a,
|
|
1393
1487
|
handle: l,
|
|
1394
1488
|
type: g,
|
|
1395
|
-
vendor:
|
|
1396
|
-
description:
|
|
1397
|
-
availableForSale:
|
|
1398
|
-
images:
|
|
1399
|
-
priceRange:
|
|
1400
|
-
compareAtPriceRange:
|
|
1401
|
-
options:
|
|
1402
|
-
tags:
|
|
1403
|
-
variants:
|
|
1404
|
-
selectedOptions:
|
|
1405
|
-
metafields:
|
|
1489
|
+
vendor: c,
|
|
1490
|
+
description: d,
|
|
1491
|
+
availableForSale: p,
|
|
1492
|
+
images: h,
|
|
1493
|
+
priceRange: y,
|
|
1494
|
+
compareAtPriceRange: w,
|
|
1495
|
+
options: E,
|
|
1496
|
+
tags: f,
|
|
1497
|
+
variants: M,
|
|
1498
|
+
selectedOptions: b,
|
|
1499
|
+
metafields: _,
|
|
1406
1500
|
calculated: e.calculated,
|
|
1407
|
-
isGiftCard:
|
|
1408
|
-
|
|
1409
|
-
|
|
1501
|
+
isGiftCard: u,
|
|
1502
|
+
category: F,
|
|
1503
|
+
createdAt: e.created_at ?? null,
|
|
1504
|
+
publishedAt: e.published_at ?? null,
|
|
1505
|
+
updatedAt: e.updated_at ?? null,
|
|
1506
|
+
featuredMedia: S,
|
|
1507
|
+
namedTags: A,
|
|
1508
|
+
combinedListingParentProductId: e.combined_listing_parent_product_id ?? null,
|
|
1509
|
+
combinedListingRole: e.combined_listing_role ?? null,
|
|
1510
|
+
hasVariantsThatRequireComponents: e.has_variants_that_require_components ?? !1,
|
|
1511
|
+
originalOptions: e.original_options ?? {},
|
|
1512
|
+
selectedVariant: R,
|
|
1513
|
+
breakoutOptions: O,
|
|
1514
|
+
breakoutVariantId: P
|
|
1410
1515
|
};
|
|
1411
1516
|
}
|
|
1412
|
-
function
|
|
1413
|
-
return (e.images ?? []).map((t) => ({
|
|
1517
|
+
function Ut(e) {
|
|
1518
|
+
return (e.images ?? []).map((t, n) => ({
|
|
1414
1519
|
url: t.src,
|
|
1415
1520
|
alt: t.alt ?? "",
|
|
1416
1521
|
width: t.width,
|
|
1417
|
-
height: t.height
|
|
1522
|
+
height: t.height,
|
|
1523
|
+
position: t.position ?? n,
|
|
1524
|
+
variantIds: t.variant_ids ?? []
|
|
1418
1525
|
}));
|
|
1419
1526
|
}
|
|
1420
|
-
function
|
|
1421
|
-
const o = e?.from ?? 0,
|
|
1527
|
+
function xt(e, t, n) {
|
|
1528
|
+
const o = e?.from ?? 0, r = e?.to ?? o;
|
|
1422
1529
|
return {
|
|
1423
|
-
min: { amount: o, currencyCode: t, formatted:
|
|
1424
|
-
max: { amount:
|
|
1530
|
+
min: { amount: o, currencyCode: t, formatted: n(o, t) },
|
|
1531
|
+
max: { amount: r, currencyCode: t, formatted: n(r, t) }
|
|
1425
1532
|
};
|
|
1426
1533
|
}
|
|
1427
|
-
function
|
|
1428
|
-
const
|
|
1429
|
-
for (const [
|
|
1534
|
+
function Bt(e, t) {
|
|
1535
|
+
const n = [], o = e.options ?? {};
|
|
1536
|
+
for (const [r, s] of Object.entries(o))
|
|
1430
1537
|
for (const i of s) {
|
|
1431
|
-
const a = t.find((l) => l.name ===
|
|
1432
|
-
|
|
1538
|
+
const a = t.find((l) => l.name === r && l.value === i);
|
|
1539
|
+
n.push({ name: r, value: i, swatch: a });
|
|
1433
1540
|
}
|
|
1434
|
-
return
|
|
1541
|
+
return n;
|
|
1435
1542
|
}
|
|
1436
|
-
function
|
|
1543
|
+
function Gt(e) {
|
|
1437
1544
|
return e.selected_options.map((t) => ({ name: t.name, value: t.value }));
|
|
1438
1545
|
}
|
|
1439
|
-
function
|
|
1440
|
-
return (e.variants ?? []).map((o) =>
|
|
1546
|
+
function jt(e, t, n) {
|
|
1547
|
+
return (e.variants ?? []).map((o) => Ht(o, t, n));
|
|
1441
1548
|
}
|
|
1442
|
-
function
|
|
1443
|
-
const o = parseFloat(e.price),
|
|
1549
|
+
function Ht(e, t, n) {
|
|
1550
|
+
const o = parseFloat(e.price), r = e.compare_at_price ? parseFloat(e.compare_at_price) : null;
|
|
1444
1551
|
return {
|
|
1445
|
-
id:
|
|
1446
|
-
gid:
|
|
1552
|
+
id: Ve({ type: "ProductVariant", selectedOptions: e.selected_options }),
|
|
1553
|
+
gid: Ct(e.id),
|
|
1447
1554
|
numericId: e.id,
|
|
1448
1555
|
title: e.title,
|
|
1449
1556
|
availableForSale: e.available,
|
|
1450
1557
|
currentlyNotInStock: !e.available,
|
|
1451
|
-
quantityAvailable: e.inventory_quantity ?? 0,
|
|
1452
1558
|
sku: e.sku ?? null,
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
price: { amount: o, currencyCode: t, formatted: r(o, t) },
|
|
1458
|
-
compareAtPrice: n != null ? {
|
|
1459
|
-
amount: n,
|
|
1559
|
+
position: e.position,
|
|
1560
|
+
price: { amount: o, currencyCode: t, formatted: n(o, t) },
|
|
1561
|
+
compareAtPrice: r != null ? {
|
|
1562
|
+
amount: r,
|
|
1460
1563
|
currencyCode: t,
|
|
1461
|
-
formatted: r
|
|
1564
|
+
formatted: n(r, t)
|
|
1462
1565
|
} : null,
|
|
1463
1566
|
image: e.featured_media ? {
|
|
1464
1567
|
url: e.featured_media.src,
|
|
1465
1568
|
alt: e.featured_media.alt ?? "",
|
|
1466
1569
|
width: e.featured_media.width,
|
|
1467
|
-
height: e.featured_media.height
|
|
1570
|
+
height: e.featured_media.height,
|
|
1571
|
+
position: 0,
|
|
1572
|
+
variantIds: [e.id]
|
|
1468
1573
|
} : null,
|
|
1469
1574
|
selectedOptions: e.selected_options.map((s) => ({ name: s.name, value: s.value })),
|
|
1470
|
-
metafields:
|
|
1471
|
-
inventoryLevels: e.inventory_levels ?? {}
|
|
1575
|
+
metafields: Qt(e.metafields),
|
|
1576
|
+
inventoryLevels: e.inventory_levels ?? {},
|
|
1577
|
+
inventoryPolicy: e.inventory_policy ?? null,
|
|
1578
|
+
inStockLocationIds: e.in_stock_location_ids ?? [],
|
|
1579
|
+
requiresSellingPlan: e.requires_selling_plan ?? !1,
|
|
1580
|
+
hasSellingPlan: e.has_selling_plan ?? !1
|
|
1472
1581
|
};
|
|
1473
1582
|
}
|
|
1474
|
-
function
|
|
1583
|
+
function Qt(e) {
|
|
1475
1584
|
return e ? e.map((t) => ({
|
|
1476
1585
|
namespace: t.namespace,
|
|
1477
1586
|
key: t.key,
|
|
@@ -1479,291 +1588,200 @@ function Vt(e) {
|
|
|
1479
1588
|
type: t.value_type
|
|
1480
1589
|
})) : [];
|
|
1481
1590
|
}
|
|
1482
|
-
function
|
|
1483
|
-
const t = e.first_or_matched_variant;
|
|
1484
|
-
return t?.inventory_quantity != null ? t.inventory_quantity : 0;
|
|
1485
|
-
}
|
|
1486
|
-
function He() {
|
|
1591
|
+
function Be() {
|
|
1487
1592
|
return typeof window < "u" && typeof window.document < "u";
|
|
1488
1593
|
}
|
|
1489
|
-
const
|
|
1490
|
-
function
|
|
1491
|
-
|
|
1594
|
+
const Ge = "__COMMERCE_BLOCKS__";
|
|
1595
|
+
function Kt(e) {
|
|
1596
|
+
Be() && (window[Ge] = e);
|
|
1492
1597
|
}
|
|
1493
|
-
function
|
|
1494
|
-
if (!
|
|
1495
|
-
return
|
|
1496
|
-
|
|
1598
|
+
function zt() {
|
|
1599
|
+
if (!Be())
|
|
1600
|
+
return v(
|
|
1601
|
+
U({
|
|
1497
1602
|
code: "INVALID_CONFIG",
|
|
1498
1603
|
message: "SDK only available in browser",
|
|
1499
1604
|
field: "environment",
|
|
1500
1605
|
expected: "browser"
|
|
1501
1606
|
})
|
|
1502
1607
|
);
|
|
1503
|
-
const e = window[
|
|
1504
|
-
return e ?
|
|
1505
|
-
|
|
1608
|
+
const e = window[Ge];
|
|
1609
|
+
return e ? D(e) : v(
|
|
1610
|
+
U({
|
|
1506
1611
|
code: "MISSING_CONFIG",
|
|
1507
1612
|
message: "SDK not initialized. Call createSdk() first.",
|
|
1508
1613
|
field: "sdk"
|
|
1509
1614
|
})
|
|
1510
1615
|
);
|
|
1511
1616
|
}
|
|
1512
|
-
function
|
|
1513
|
-
return
|
|
1617
|
+
function Sn() {
|
|
1618
|
+
return zt().data !== void 0;
|
|
1514
1619
|
}
|
|
1515
|
-
function
|
|
1620
|
+
function re({
|
|
1516
1621
|
products: e,
|
|
1517
1622
|
raw: t,
|
|
1518
|
-
extender:
|
|
1623
|
+
extender: n
|
|
1519
1624
|
}) {
|
|
1520
1625
|
const o = {
|
|
1521
1626
|
products: e,
|
|
1522
1627
|
totalResults: t.totalResults,
|
|
1523
1628
|
totalPages: t.totalPages,
|
|
1524
1629
|
page: t.page,
|
|
1525
|
-
|
|
1630
|
+
resultsPerPage: t.resultsPerPage,
|
|
1631
|
+
facets: t.facets ?? {},
|
|
1632
|
+
facetRanges: t.facetRanges,
|
|
1633
|
+
attributionToken: t.attributionToken,
|
|
1634
|
+
_workflow: t._workflow
|
|
1526
1635
|
};
|
|
1527
|
-
return
|
|
1636
|
+
return n ? n(o, t) : o;
|
|
1528
1637
|
}
|
|
1529
|
-
function
|
|
1530
|
-
return {
|
|
1531
|
-
id: "",
|
|
1532
|
-
handle: e.handle,
|
|
1533
|
-
title: e.title ?? "",
|
|
1534
|
-
description: e.description ?? "",
|
|
1535
|
-
descriptionHtml: e.descriptionHtml ?? "",
|
|
1536
|
-
image: e.image ? {
|
|
1537
|
-
url: e.image.url,
|
|
1538
|
-
altText: e.image.alt ?? null,
|
|
1539
|
-
width: e.image.width ?? 0,
|
|
1540
|
-
height: e.image.height ?? 0
|
|
1541
|
-
} : null,
|
|
1542
|
-
seo: { title: null, description: null },
|
|
1543
|
-
updatedAt: "",
|
|
1544
|
-
metafields: e.metafields
|
|
1545
|
-
};
|
|
1546
|
-
}
|
|
1547
|
-
function jt({ ctx: e }) {
|
|
1638
|
+
function Xt({ ctx: e }) {
|
|
1548
1639
|
function t(a) {
|
|
1549
|
-
return a.map(
|
|
1640
|
+
return a.map((l) => he(l));
|
|
1550
1641
|
}
|
|
1551
|
-
function
|
|
1552
|
-
const
|
|
1642
|
+
function n(a, l) {
|
|
1643
|
+
const c = Vt({ layers: a, ...e.mergeConfig, breakoutContext: l });
|
|
1553
1644
|
return e.config.extendProduct ? { ...e.config.extendProduct({
|
|
1554
|
-
base:
|
|
1645
|
+
base: c,
|
|
1555
1646
|
raw: a,
|
|
1556
|
-
|
|
1557
|
-
}), _base:
|
|
1647
|
+
storefront: null
|
|
1648
|
+
}), _base: c } : c;
|
|
1558
1649
|
}
|
|
1559
|
-
function o(a, l
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1650
|
+
function o(a, l) {
|
|
1651
|
+
if (!(a.__typename !== "Variant" || l.length === 0))
|
|
1652
|
+
return {
|
|
1653
|
+
isVariantTile: !0,
|
|
1654
|
+
variantId: a.variant_id,
|
|
1655
|
+
optionCodes: l
|
|
1656
|
+
};
|
|
1564
1657
|
}
|
|
1565
|
-
|
|
1566
|
-
const g =
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1658
|
+
function r(a, l, c) {
|
|
1659
|
+
const g = c?.variantBreakouts?.map((d) => d.optionCode) ?? [];
|
|
1660
|
+
return a.map((d) => {
|
|
1661
|
+
const p = he(d), u = o(d, g);
|
|
1662
|
+
if (!u) {
|
|
1663
|
+
const f = l.get(p);
|
|
1664
|
+
if (f) return f;
|
|
1665
|
+
}
|
|
1666
|
+
return n(d, u);
|
|
1572
1667
|
});
|
|
1573
|
-
if (f.error) return m(f.error);
|
|
1574
|
-
for (const c of f.data)
|
|
1575
|
-
g.set(c.id, c);
|
|
1576
|
-
return M(g);
|
|
1577
|
-
}
|
|
1578
|
-
async function s(a) {
|
|
1579
|
-
const l = t(a), { cached: u, missing: g } = e.store.products.getMany(l), f = new Map(u.map((d) => [d.gid, d]));
|
|
1580
|
-
if (g.length === 0)
|
|
1581
|
-
return M(l.map((d) => f.get(d)));
|
|
1582
|
-
const c = await n(g);
|
|
1583
|
-
return c.error ? m(c.error) : M(o(a, c.data, f));
|
|
1584
1668
|
}
|
|
1585
|
-
function
|
|
1669
|
+
function s(a) {
|
|
1586
1670
|
if (a) {
|
|
1587
1671
|
if (e.config.transformFilters)
|
|
1588
1672
|
return e.config.transformFilters(a);
|
|
1589
1673
|
if (e.config.filterMap && typeof a == "object" && !Array.isArray(a)) {
|
|
1590
|
-
const l = a,
|
|
1591
|
-
for (const [g,
|
|
1592
|
-
if (
|
|
1593
|
-
const
|
|
1594
|
-
const
|
|
1595
|
-
return
|
|
1674
|
+
const l = a, c = [];
|
|
1675
|
+
for (const [g, d] of Object.entries(l)) {
|
|
1676
|
+
if (d == null) continue;
|
|
1677
|
+
const p = e.config.filterMap[g], u = typeof p == "string" ? p : p?.property ?? g, f = typeof p == "object" ? p.values : void 0, y = (Array.isArray(d) ? d : [d]).map((E) => {
|
|
1678
|
+
const M = String(E);
|
|
1679
|
+
return f?.[M] ?? M;
|
|
1596
1680
|
});
|
|
1597
|
-
|
|
1598
|
-
property:
|
|
1599
|
-
operator: y.length > 1 ?
|
|
1681
|
+
c.push({
|
|
1682
|
+
property: u,
|
|
1683
|
+
operator: y.length > 1 ? _e.In : _e.Equal,
|
|
1600
1684
|
values: y
|
|
1601
1685
|
});
|
|
1602
1686
|
}
|
|
1603
|
-
return
|
|
1604
|
-
conditional:
|
|
1605
|
-
expressions:
|
|
1687
|
+
return c.length === 0 ? void 0 : {
|
|
1688
|
+
conditional: xe.And,
|
|
1689
|
+
expressions: c
|
|
1606
1690
|
};
|
|
1607
1691
|
}
|
|
1608
1692
|
return a;
|
|
1609
1693
|
}
|
|
1610
1694
|
}
|
|
1695
|
+
function i(a) {
|
|
1696
|
+
return a.filter((l) => !l.breakoutVariantId);
|
|
1697
|
+
}
|
|
1611
1698
|
return {
|
|
1612
1699
|
extractGids: t,
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
fetchAndBuildProducts: s,
|
|
1617
|
-
transformFilters: i
|
|
1700
|
+
buildProducts: r,
|
|
1701
|
+
transformFilters: s,
|
|
1702
|
+
filterCacheableProducts: i
|
|
1618
1703
|
};
|
|
1619
1704
|
}
|
|
1620
1705
|
function oe(e) {
|
|
1621
1706
|
const t = new AbortController();
|
|
1622
1707
|
return e && (e.aborted ? t.abort(e.reason) : e.addEventListener("abort", () => t.abort(e.reason), { once: !0 })), t;
|
|
1623
1708
|
}
|
|
1624
|
-
function
|
|
1625
|
-
definitions: e
|
|
1626
|
-
}) {
|
|
1627
|
-
if (!e) return {};
|
|
1628
|
-
const t = {};
|
|
1629
|
-
for (const [r, o] of Object.entries(e)) {
|
|
1630
|
-
const n = o({ key: r });
|
|
1631
|
-
n != null && (t[r] = n);
|
|
1632
|
-
}
|
|
1633
|
-
return t;
|
|
1634
|
-
}
|
|
1635
|
-
function X({
|
|
1709
|
+
function K({
|
|
1636
1710
|
params: e,
|
|
1637
1711
|
paramDefinitions: t,
|
|
1638
|
-
transformBody:
|
|
1712
|
+
transformBody: n
|
|
1639
1713
|
}) {
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1714
|
+
return !e && !t && !n ? (o) => o : (o) => {
|
|
1715
|
+
let r = o;
|
|
1716
|
+
const s = t && Object.keys(t).length > 0;
|
|
1717
|
+
if (e || s) {
|
|
1718
|
+
const i = {};
|
|
1719
|
+
if (t)
|
|
1720
|
+
for (const [a, l] of Object.entries(t)) {
|
|
1721
|
+
const c = l(a);
|
|
1722
|
+
c != null && (i[a] = c);
|
|
1723
|
+
}
|
|
1724
|
+
r = { ...r, ...e, ...i };
|
|
1725
|
+
}
|
|
1726
|
+
return n ? n(r) : r;
|
|
1727
|
+
};
|
|
1646
1728
|
}
|
|
1647
1729
|
function Wt({
|
|
1648
1730
|
ctx: e,
|
|
1649
1731
|
helpers: t
|
|
1650
1732
|
}) {
|
|
1651
|
-
return ({ handle:
|
|
1652
|
-
const
|
|
1733
|
+
return ({ handle: n, defaultSort: o }) => {
|
|
1734
|
+
const r = L({
|
|
1653
1735
|
data: null,
|
|
1654
1736
|
error: null,
|
|
1655
1737
|
isFetching: !1
|
|
1656
1738
|
});
|
|
1657
1739
|
let s = null, i = o ?? e.config.sorts[0]?.code;
|
|
1658
1740
|
return {
|
|
1659
|
-
state:
|
|
1741
|
+
state: r,
|
|
1660
1742
|
async execute(a = {}) {
|
|
1661
1743
|
const {
|
|
1662
1744
|
page: l = Y,
|
|
1663
|
-
limit:
|
|
1745
|
+
limit: c = Z,
|
|
1664
1746
|
filters: g,
|
|
1665
|
-
sortOrderCode:
|
|
1666
|
-
signal:
|
|
1667
|
-
includeMeta:
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
const
|
|
1677
|
-
n.value = { data: E, error: null, isFetching: !0 };
|
|
1678
|
-
const { data: F, error: P } = await e.layers.browse(
|
|
1747
|
+
sortOrderCode: d,
|
|
1748
|
+
signal: p,
|
|
1749
|
+
includeMeta: u = e.config.includeMeta ?? !1,
|
|
1750
|
+
dynamicLinking: f,
|
|
1751
|
+
params: h,
|
|
1752
|
+
paramDefinitions: y,
|
|
1753
|
+
transformBody: E
|
|
1754
|
+
} = a, M = d ?? i;
|
|
1755
|
+
i = M, s?.abort(), s = oe(p);
|
|
1756
|
+
const T = r.value.data;
|
|
1757
|
+
r.value = { data: T, error: null, isFetching: !0 };
|
|
1758
|
+
const { data: w, error: b } = await e.layers.browse(
|
|
1679
1759
|
{
|
|
1680
|
-
collectionHandle:
|
|
1681
|
-
sort_order_code:
|
|
1682
|
-
pagination: { page: l, limit:
|
|
1760
|
+
collectionHandle: n,
|
|
1761
|
+
sort_order_code: M,
|
|
1762
|
+
pagination: { page: l, limit: c },
|
|
1683
1763
|
filter_group: t.transformFilters(g),
|
|
1684
|
-
dynamicLinking:
|
|
1685
|
-
transformBody:
|
|
1764
|
+
dynamicLinking: f,
|
|
1765
|
+
transformBody: K({ params: h, paramDefinitions: y, transformBody: E })
|
|
1686
1766
|
},
|
|
1687
1767
|
s.signal
|
|
1688
1768
|
);
|
|
1689
|
-
if (
|
|
1690
|
-
return
|
|
1691
|
-
const { results:
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
x = C.map((w) => L.get(w));
|
|
1695
|
-
else if (e.storefrontEnabled && d && !Te) {
|
|
1696
|
-
const w = await e.storefront.getCollectionWithProducts({
|
|
1697
|
-
handle: r,
|
|
1698
|
-
ids: k,
|
|
1699
|
-
productMetafields: e.config.productMetafields,
|
|
1700
|
-
variantMetafields: e.config.variantMetafields,
|
|
1701
|
-
collectionMetafields: p,
|
|
1702
|
-
includeFilters: h
|
|
1703
|
-
});
|
|
1704
|
-
if (w.data) {
|
|
1705
|
-
T = w.data.collection;
|
|
1706
|
-
const V = /* @__PURE__ */ new Map();
|
|
1707
|
-
for (const De of w.data.products)
|
|
1708
|
-
V.set(De.id, De);
|
|
1709
|
-
x = t.buildProductsWithCache(_, V, L);
|
|
1710
|
-
} else {
|
|
1711
|
-
const V = await t.fetchStorefrontProductsMap(k);
|
|
1712
|
-
if (V.error)
|
|
1713
|
-
return n.value = { data: E, error: V.error, isFetching: !1 }, m(V.error);
|
|
1714
|
-
x = t.buildProductsWithCache(
|
|
1715
|
-
_,
|
|
1716
|
-
V.data,
|
|
1717
|
-
L
|
|
1718
|
-
);
|
|
1719
|
-
}
|
|
1720
|
-
} else {
|
|
1721
|
-
const w = await t.fetchStorefrontProductsMap(k);
|
|
1722
|
-
if (w.error)
|
|
1723
|
-
return n.value = { data: E, error: w.error, isFetching: !1 }, m(w.error);
|
|
1724
|
-
x = t.buildProductsWithCache(
|
|
1725
|
-
_,
|
|
1726
|
-
w.data,
|
|
1727
|
-
L
|
|
1728
|
-
);
|
|
1729
|
-
}
|
|
1730
|
-
if (e.storefrontEnabled && d && !T)
|
|
1731
|
-
if (Te)
|
|
1732
|
-
T = Ht(U);
|
|
1733
|
-
else {
|
|
1734
|
-
const w = await e.storefront.getCollection({
|
|
1735
|
-
handle: r,
|
|
1736
|
-
collectionMetafields: p,
|
|
1737
|
-
includeFilters: h
|
|
1738
|
-
});
|
|
1739
|
-
w.data && (T = w.data);
|
|
1740
|
-
}
|
|
1741
|
-
const q = ne({
|
|
1742
|
-
products: x,
|
|
1743
|
-
raw: F,
|
|
1769
|
+
if (b)
|
|
1770
|
+
return r.value = { data: T, error: b, isFetching: !1 }, v(b);
|
|
1771
|
+
const { results: m, _meta: _ } = w, F = t.extractGids(m), { cached: S } = e.store.products.getMany(F), A = new Map(S.map((I) => [I.gid, I])), R = t.buildProducts(m, A, _), O = re({
|
|
1772
|
+
products: R,
|
|
1773
|
+
raw: w,
|
|
1744
1774
|
extender: e.config.extendCollection
|
|
1745
1775
|
});
|
|
1746
|
-
|
|
1747
|
-
const
|
|
1748
|
-
return
|
|
1749
|
-
totalProducts:
|
|
1750
|
-
totalPages:
|
|
1776
|
+
u && w._meta && (O._meta = w._meta);
|
|
1777
|
+
const P = Dt(n, { sortOrderCode: M, page: l, limit: c, filters: g });
|
|
1778
|
+
return P && e.store.queries.set(P, O), e.store.products.set(t.filterCacheableProducts(R)), e.store.collections.set(n, {
|
|
1779
|
+
totalProducts: O.totalResults,
|
|
1780
|
+
totalPages: O.totalPages,
|
|
1751
1781
|
lastPageFetched: l,
|
|
1752
|
-
facets:
|
|
1753
|
-
lastFetched: Date.now()
|
|
1754
|
-
|
|
1755
|
-
title: T.title,
|
|
1756
|
-
description: T.description,
|
|
1757
|
-
descriptionHtml: T.descriptionHtml,
|
|
1758
|
-
image: T.image ? {
|
|
1759
|
-
url: T.image.url,
|
|
1760
|
-
alt: T.image.altText ?? void 0,
|
|
1761
|
-
width: T.image.width,
|
|
1762
|
-
height: T.image.height
|
|
1763
|
-
} : void 0,
|
|
1764
|
-
metafields: T.metafields
|
|
1765
|
-
}
|
|
1766
|
-
}), n.value = { data: q, error: null, isFetching: !1 }, M(q);
|
|
1782
|
+
facets: O.facets,
|
|
1783
|
+
lastFetched: Date.now()
|
|
1784
|
+
}), r.value = { data: O, error: null, isFetching: !1 }, D(O);
|
|
1767
1785
|
},
|
|
1768
1786
|
dispose() {
|
|
1769
1787
|
s?.abort();
|
|
@@ -1771,120 +1789,117 @@ function Wt({
|
|
|
1771
1789
|
};
|
|
1772
1790
|
};
|
|
1773
1791
|
}
|
|
1774
|
-
function
|
|
1792
|
+
function Jt({
|
|
1775
1793
|
ctx: e,
|
|
1776
1794
|
helpers: t
|
|
1777
1795
|
}) {
|
|
1778
1796
|
return () => {
|
|
1779
|
-
const
|
|
1797
|
+
const n = L({
|
|
1780
1798
|
data: null,
|
|
1781
1799
|
error: null,
|
|
1782
1800
|
isFetching: !1
|
|
1783
1801
|
});
|
|
1784
|
-
let o = null,
|
|
1802
|
+
let o = null, r;
|
|
1785
1803
|
return {
|
|
1786
|
-
state:
|
|
1804
|
+
state: n,
|
|
1787
1805
|
async prepare(s) {
|
|
1788
1806
|
const {
|
|
1789
1807
|
query: i,
|
|
1790
1808
|
filters: a,
|
|
1791
1809
|
tuning: l,
|
|
1792
|
-
signal:
|
|
1810
|
+
signal: c,
|
|
1793
1811
|
dynamicLinking: g,
|
|
1794
|
-
params:
|
|
1795
|
-
paramDefinitions:
|
|
1796
|
-
transformBody:
|
|
1797
|
-
} = s,
|
|
1812
|
+
params: d,
|
|
1813
|
+
paramDefinitions: p,
|
|
1814
|
+
transformBody: u
|
|
1815
|
+
} = s, f = t.transformFilters(a), h = await e.layers.prepareSearch(
|
|
1798
1816
|
{
|
|
1799
1817
|
query: i,
|
|
1800
|
-
filter_group:
|
|
1818
|
+
filter_group: f,
|
|
1801
1819
|
tuning: l,
|
|
1802
1820
|
dynamicLinking: g,
|
|
1803
|
-
transformBody:
|
|
1821
|
+
transformBody: K({ params: d, paramDefinitions: p, transformBody: u })
|
|
1804
1822
|
},
|
|
1805
|
-
|
|
1823
|
+
c
|
|
1806
1824
|
);
|
|
1807
|
-
return h.error ?
|
|
1825
|
+
return h.error ? v(h.error) : (r = h.data.search_id, D({ searchId: h.data.search_id }));
|
|
1808
1826
|
},
|
|
1809
1827
|
async execute(s) {
|
|
1810
1828
|
const {
|
|
1811
1829
|
query: i,
|
|
1812
1830
|
searchId: a,
|
|
1813
1831
|
page: l = Y,
|
|
1814
|
-
limit:
|
|
1832
|
+
limit: c = Z,
|
|
1815
1833
|
filters: g,
|
|
1816
|
-
tuning:
|
|
1817
|
-
signal:
|
|
1818
|
-
dynamicLinking:
|
|
1819
|
-
params:
|
|
1834
|
+
tuning: d,
|
|
1835
|
+
signal: p,
|
|
1836
|
+
dynamicLinking: u,
|
|
1837
|
+
params: f,
|
|
1820
1838
|
paramDefinitions: h,
|
|
1821
1839
|
transformBody: y
|
|
1822
|
-
} = s,
|
|
1823
|
-
o?.abort(), o = oe(
|
|
1824
|
-
let
|
|
1825
|
-
if (
|
|
1826
|
-
const
|
|
1840
|
+
} = s, E = t.transformFilters(g), M = K({ params: f, paramDefinitions: h, transformBody: y });
|
|
1841
|
+
o?.abort(), o = oe(p), n.value = { ...n.value, isFetching: !0, error: null };
|
|
1842
|
+
let T = a ?? r;
|
|
1843
|
+
if (r = void 0, !T) {
|
|
1844
|
+
const I = await e.layers.prepareSearch(
|
|
1827
1845
|
{
|
|
1828
1846
|
query: i,
|
|
1829
|
-
filter_group:
|
|
1830
|
-
tuning:
|
|
1831
|
-
dynamicLinking:
|
|
1832
|
-
transformBody:
|
|
1847
|
+
filter_group: E,
|
|
1848
|
+
tuning: d,
|
|
1849
|
+
dynamicLinking: u,
|
|
1850
|
+
transformBody: M
|
|
1833
1851
|
},
|
|
1834
1852
|
o.signal
|
|
1835
1853
|
);
|
|
1836
|
-
if (
|
|
1837
|
-
return
|
|
1838
|
-
|
|
1854
|
+
if (I.error)
|
|
1855
|
+
return n.value = { ...n.value, isFetching: !1, error: I.error }, v(I.error);
|
|
1856
|
+
T = I.data.search_id;
|
|
1839
1857
|
}
|
|
1840
|
-
const
|
|
1841
|
-
let
|
|
1858
|
+
const w = We;
|
|
1859
|
+
let b = await e.layers.search(
|
|
1842
1860
|
{
|
|
1843
1861
|
query: i,
|
|
1844
|
-
search_id:
|
|
1845
|
-
pagination: { page: l, limit:
|
|
1846
|
-
filter_group:
|
|
1847
|
-
tuning:
|
|
1848
|
-
dynamicLinking:
|
|
1849
|
-
transformBody:
|
|
1862
|
+
search_id: T,
|
|
1863
|
+
pagination: { page: l, limit: c },
|
|
1864
|
+
filter_group: E,
|
|
1865
|
+
tuning: d,
|
|
1866
|
+
dynamicLinking: u,
|
|
1867
|
+
transformBody: M
|
|
1850
1868
|
},
|
|
1851
1869
|
o.signal
|
|
1852
1870
|
);
|
|
1853
|
-
for (let
|
|
1854
|
-
const k =
|
|
1871
|
+
for (let I = 0; I < w && b.error; I++) {
|
|
1872
|
+
const k = b.error;
|
|
1855
1873
|
if (k._tag !== "ApiError" || k.status !== 425) break;
|
|
1856
|
-
let
|
|
1874
|
+
let V = Je;
|
|
1857
1875
|
try {
|
|
1858
|
-
const
|
|
1859
|
-
|
|
1876
|
+
const X = JSON.parse(k.message);
|
|
1877
|
+
X.retry_after_ms && (V = X.retry_after_ms);
|
|
1860
1878
|
} catch {
|
|
1861
1879
|
}
|
|
1862
|
-
await new Promise((
|
|
1880
|
+
await new Promise((X) => setTimeout(X, V)), b = await e.layers.search(
|
|
1863
1881
|
{
|
|
1864
1882
|
query: i,
|
|
1865
|
-
search_id:
|
|
1866
|
-
pagination: { page: l, limit:
|
|
1867
|
-
filter_group:
|
|
1868
|
-
tuning:
|
|
1869
|
-
dynamicLinking:
|
|
1870
|
-
transformBody:
|
|
1883
|
+
search_id: T,
|
|
1884
|
+
pagination: { page: l, limit: c },
|
|
1885
|
+
filter_group: E,
|
|
1886
|
+
tuning: d,
|
|
1887
|
+
dynamicLinking: u,
|
|
1888
|
+
transformBody: M
|
|
1871
1889
|
},
|
|
1872
1890
|
o.signal
|
|
1873
1891
|
);
|
|
1874
1892
|
}
|
|
1875
|
-
if (
|
|
1876
|
-
return
|
|
1877
|
-
const { results:
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
const A = P.data, _ = ne({
|
|
1881
|
-
products: A,
|
|
1882
|
-
raw: E.data,
|
|
1893
|
+
if (b.error)
|
|
1894
|
+
return n.value = { data: n.value.data, error: b.error, isFetching: !1 }, v(b.error);
|
|
1895
|
+
const { results: m, _meta: _ } = b.data, F = t.extractGids(m), { cached: S } = e.store.products.getMany(F), A = new Map(S.map((I) => [I.gid, I])), R = t.buildProducts(m, A, _), O = re({
|
|
1896
|
+
products: R,
|
|
1897
|
+
raw: b.data,
|
|
1883
1898
|
extender: e.config.extendSearch
|
|
1884
1899
|
});
|
|
1885
|
-
e.config.includeMeta &&
|
|
1886
|
-
const
|
|
1887
|
-
return
|
|
1900
|
+
e.config.includeMeta && b.data._meta && (O._meta = b.data._meta), e.store.products.set(t.filterCacheableProducts(R));
|
|
1901
|
+
const P = Nt(i, { page: l, limit: c, filters: g });
|
|
1902
|
+
return P && e.store.queries.set(P, O), n.value = { data: O, error: null, isFetching: !1 }, D(O);
|
|
1888
1903
|
},
|
|
1889
1904
|
dispose() {
|
|
1890
1905
|
o?.abort();
|
|
@@ -1892,12 +1907,12 @@ function Kt({
|
|
|
1892
1907
|
};
|
|
1893
1908
|
};
|
|
1894
1909
|
}
|
|
1895
|
-
function
|
|
1910
|
+
function Yt({
|
|
1896
1911
|
ctx: e,
|
|
1897
1912
|
helpers: t
|
|
1898
1913
|
}) {
|
|
1899
|
-
return ({ blockId:
|
|
1900
|
-
const s =
|
|
1914
|
+
return ({ blockId: n, anchorId: o, anchorHandle: r }) => {
|
|
1915
|
+
const s = L({
|
|
1901
1916
|
data: null,
|
|
1902
1917
|
error: null,
|
|
1903
1918
|
isFetching: !1
|
|
@@ -1908,46 +1923,43 @@ function Xt({
|
|
|
1908
1923
|
async execute(a = {}) {
|
|
1909
1924
|
const {
|
|
1910
1925
|
page: l = Y,
|
|
1911
|
-
limit:
|
|
1926
|
+
limit: c = Z,
|
|
1912
1927
|
filters: g,
|
|
1913
|
-
signal:
|
|
1914
|
-
discountEntitlements:
|
|
1915
|
-
context:
|
|
1916
|
-
dynamicLinking:
|
|
1928
|
+
signal: d,
|
|
1929
|
+
discountEntitlements: p,
|
|
1930
|
+
context: u,
|
|
1931
|
+
dynamicLinking: f,
|
|
1917
1932
|
params: h,
|
|
1918
1933
|
paramDefinitions: y,
|
|
1919
|
-
transformBody:
|
|
1934
|
+
transformBody: E
|
|
1920
1935
|
} = a;
|
|
1921
|
-
i?.abort(), i = oe(
|
|
1922
|
-
const
|
|
1923
|
-
s.value = { data:
|
|
1924
|
-
const { data:
|
|
1936
|
+
i?.abort(), i = oe(d);
|
|
1937
|
+
const M = s.value.data;
|
|
1938
|
+
s.value = { data: M, error: null, isFetching: !0 };
|
|
1939
|
+
const { data: T, error: w } = await e.layers.blocks(
|
|
1925
1940
|
{
|
|
1926
|
-
blockId:
|
|
1941
|
+
blockId: n,
|
|
1927
1942
|
anchor_id: o,
|
|
1928
|
-
anchor_handle:
|
|
1929
|
-
pagination: { page: l, limit:
|
|
1943
|
+
anchor_handle: r,
|
|
1944
|
+
pagination: { page: l, limit: c },
|
|
1930
1945
|
filter_group: t.transformFilters(g),
|
|
1931
|
-
discountEntitlements:
|
|
1932
|
-
context:
|
|
1933
|
-
dynamicLinking:
|
|
1934
|
-
transformBody:
|
|
1946
|
+
discountEntitlements: p,
|
|
1947
|
+
context: u,
|
|
1948
|
+
dynamicLinking: f,
|
|
1949
|
+
transformBody: K({ params: h, paramDefinitions: y, transformBody: E })
|
|
1935
1950
|
},
|
|
1936
1951
|
i.signal
|
|
1937
1952
|
);
|
|
1938
|
-
if (
|
|
1939
|
-
return s.value = { data:
|
|
1940
|
-
const { results:
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
const P = F.data, A = ne({
|
|
1944
|
-
products: P,
|
|
1945
|
-
raw: v,
|
|
1953
|
+
if (w)
|
|
1954
|
+
return s.value = { data: M, error: w, isFetching: !1 }, v(w);
|
|
1955
|
+
const { results: b, _meta: m } = T, _ = t.extractGids(b), { cached: F } = e.store.products.getMany(_), S = new Map(F.map((P) => [P.gid, P])), A = t.buildProducts(b, S, m), R = re({
|
|
1956
|
+
products: A,
|
|
1957
|
+
raw: T,
|
|
1946
1958
|
extender: e.config.extendBlock
|
|
1947
1959
|
});
|
|
1948
|
-
e.config.includeMeta &&
|
|
1949
|
-
const
|
|
1950
|
-
return
|
|
1960
|
+
e.config.includeMeta && T._meta && (R._meta = T._meta), T.block && (R.block = T.block);
|
|
1961
|
+
const O = qt(n, { anchorId: o, anchorHandle: r, page: l, limit: c, filters: g });
|
|
1962
|
+
return O && e.store.queries.set(O, R), e.store.products.set(t.filterCacheableProducts(A)), s.value = { data: R, error: null, isFetching: !1 }, D(R);
|
|
1951
1963
|
},
|
|
1952
1964
|
dispose() {
|
|
1953
1965
|
i?.abort();
|
|
@@ -1955,73 +1967,77 @@ function Xt({
|
|
|
1955
1967
|
};
|
|
1956
1968
|
};
|
|
1957
1969
|
}
|
|
1958
|
-
function
|
|
1959
|
-
let
|
|
1970
|
+
function Zt(e, t) {
|
|
1971
|
+
let n = null;
|
|
1960
1972
|
return {
|
|
1961
1973
|
call(...o) {
|
|
1962
|
-
|
|
1974
|
+
n && clearTimeout(n), n = setTimeout(() => {
|
|
1975
|
+
n = null, e(...o);
|
|
1976
|
+
}, t);
|
|
1963
1977
|
},
|
|
1964
1978
|
cancel() {
|
|
1965
|
-
|
|
1979
|
+
n && (clearTimeout(n), n = null);
|
|
1966
1980
|
}
|
|
1967
1981
|
};
|
|
1968
1982
|
}
|
|
1969
|
-
function
|
|
1983
|
+
function en({
|
|
1970
1984
|
ctx: e
|
|
1971
1985
|
}) {
|
|
1972
1986
|
return (t = {}) => {
|
|
1973
|
-
const { debounceMs:
|
|
1987
|
+
const { debounceMs: n = Ye, signal: o } = t, r = L({
|
|
1974
1988
|
data: null,
|
|
1975
1989
|
error: null,
|
|
1976
1990
|
isFetching: !1
|
|
1977
1991
|
});
|
|
1978
|
-
let s = null;
|
|
1979
|
-
const
|
|
1980
|
-
function
|
|
1981
|
-
|
|
1992
|
+
let s = null, i = 0;
|
|
1993
|
+
const a = /* @__PURE__ */ new Map();
|
|
1994
|
+
function l() {
|
|
1995
|
+
c.cancel(), s?.abort(), a.clear();
|
|
1982
1996
|
}
|
|
1983
|
-
o?.addEventListener("abort",
|
|
1984
|
-
const
|
|
1985
|
-
if (!
|
|
1986
|
-
|
|
1997
|
+
o?.addEventListener("abort", l, { once: !0 });
|
|
1998
|
+
const c = Zt(async (g) => {
|
|
1999
|
+
if (!g.trim()) {
|
|
2000
|
+
r.value = { data: null, error: null, isFetching: !1 };
|
|
1987
2001
|
return;
|
|
1988
2002
|
}
|
|
1989
|
-
const
|
|
1990
|
-
if (
|
|
1991
|
-
|
|
2003
|
+
const d = g.trim().toLowerCase(), p = a.get(d);
|
|
2004
|
+
if (p) {
|
|
2005
|
+
r.value = { data: p, error: null, isFetching: !1 };
|
|
1992
2006
|
return;
|
|
1993
2007
|
}
|
|
1994
|
-
s?.abort(), s = oe(o)
|
|
1995
|
-
const
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
2008
|
+
s?.abort(), s = oe(o);
|
|
2009
|
+
const u = ++i;
|
|
2010
|
+
r.value = { ...r.value, isFetching: !0 };
|
|
2011
|
+
const f = await e.layers.predictiveSearch(g.trim(), s.signal);
|
|
2012
|
+
u === i && (f.error ? f.error._tag !== "NetworkError" || f.error.code !== "ABORTED" ? r.value = { data: null, error: f.error, isFetching: !1 } : r.value = { ...r.value, isFetching: !1 } : (a.set(d, f.data), a.size > Ze && a.delete(a.keys().next().value), r.value = { data: f.data, error: null, isFetching: !1 }));
|
|
2013
|
+
}, n);
|
|
2014
|
+
return { state: r, execute: (g) => c.call(g), dispose: l };
|
|
1999
2015
|
};
|
|
2000
2016
|
}
|
|
2001
|
-
function
|
|
2017
|
+
function tn({
|
|
2002
2018
|
ctx: e
|
|
2003
2019
|
}) {
|
|
2004
2020
|
return (t) => {
|
|
2005
2021
|
const {
|
|
2006
|
-
ids:
|
|
2022
|
+
ids: n,
|
|
2007
2023
|
meta: o,
|
|
2008
|
-
collectionMetafields:
|
|
2024
|
+
collectionMetafields: r = e.config.collectionMetafields,
|
|
2009
2025
|
pageMetafields: s = e.config.pageMetafields,
|
|
2010
2026
|
signal: i
|
|
2011
|
-
} = t, a =
|
|
2027
|
+
} = t, a = L({
|
|
2012
2028
|
data: null,
|
|
2013
2029
|
error: null,
|
|
2014
2030
|
isFetching: !1
|
|
2015
2031
|
});
|
|
2016
|
-
if (
|
|
2032
|
+
if (n.length === 0)
|
|
2017
2033
|
return a.value = { data: { products: [] }, error: null, isFetching: !1 }, a;
|
|
2018
|
-
const l =
|
|
2019
|
-
return !o || !e.storefrontEnabled ? (a.value = { data: { products:
|
|
2020
|
-
let
|
|
2034
|
+
const l = n, { cached: c } = e.store.products.getMany(l), g = new Map(c.map((p) => [p.gid, p])), d = l.map((p) => g.get(p)).filter((p) => p != null);
|
|
2035
|
+
return !o || !e.storefrontEnabled ? (a.value = { data: { products: d }, error: null, isFetching: !1 }, a) : (a.value = { data: null, error: null, isFetching: !0 }, (async () => {
|
|
2036
|
+
let p, u;
|
|
2021
2037
|
if (o.collection) {
|
|
2022
2038
|
const h = await e.storefront.getCollection({
|
|
2023
2039
|
handle: o.collection,
|
|
2024
|
-
collectionMetafields:
|
|
2040
|
+
collectionMetafields: r,
|
|
2025
2041
|
includeFilters: o.includeFilters,
|
|
2026
2042
|
signal: i
|
|
2027
2043
|
});
|
|
@@ -2029,7 +2045,7 @@ function Yt({
|
|
|
2029
2045
|
a.value = { data: null, error: h.error, isFetching: !1 };
|
|
2030
2046
|
return;
|
|
2031
2047
|
}
|
|
2032
|
-
|
|
2048
|
+
p = h.data;
|
|
2033
2049
|
}
|
|
2034
2050
|
if (o.page) {
|
|
2035
2051
|
const h = await e.storefront.getPage({
|
|
@@ -2041,86 +2057,81 @@ function Yt({
|
|
|
2041
2057
|
a.value = { data: null, error: h.error, isFetching: !1 };
|
|
2042
2058
|
return;
|
|
2043
2059
|
}
|
|
2044
|
-
|
|
2060
|
+
u = h.data;
|
|
2045
2061
|
}
|
|
2046
|
-
const
|
|
2047
|
-
|
|
2062
|
+
const f = { products: d };
|
|
2063
|
+
p && (f.collection = p), u && (f.page = u), a.value = { data: f, error: null, isFetching: !1 };
|
|
2048
2064
|
})(), a);
|
|
2049
2065
|
};
|
|
2050
2066
|
}
|
|
2051
|
-
function
|
|
2067
|
+
function nn({ ctx: e }) {
|
|
2052
2068
|
return ({
|
|
2053
2069
|
image: t,
|
|
2054
|
-
signal:
|
|
2070
|
+
signal: n
|
|
2055
2071
|
}) => {
|
|
2056
|
-
const o =
|
|
2072
|
+
const o = L({
|
|
2057
2073
|
data: null,
|
|
2058
2074
|
error: null,
|
|
2059
2075
|
isFetching: !0
|
|
2060
2076
|
});
|
|
2061
2077
|
return (async () => {
|
|
2062
|
-
const
|
|
2063
|
-
if (
|
|
2064
|
-
o.value = { data: null, error:
|
|
2078
|
+
const r = await e.layers.uploadImage(t, n);
|
|
2079
|
+
if (r.error) {
|
|
2080
|
+
o.value = { data: null, error: r.error, isFetching: !1 };
|
|
2065
2081
|
return;
|
|
2066
2082
|
}
|
|
2067
|
-
o.value = { data: { imageId:
|
|
2083
|
+
o.value = { data: { imageId: r.data.imageId }, error: null, isFetching: !1 };
|
|
2068
2084
|
})(), o;
|
|
2069
2085
|
};
|
|
2070
2086
|
}
|
|
2071
|
-
function
|
|
2087
|
+
function rn({
|
|
2072
2088
|
ctx: e,
|
|
2073
2089
|
helpers: t
|
|
2074
2090
|
}) {
|
|
2075
|
-
return (
|
|
2091
|
+
return (n) => {
|
|
2076
2092
|
const {
|
|
2077
2093
|
imageId: o,
|
|
2078
|
-
page:
|
|
2094
|
+
page: r = Y,
|
|
2079
2095
|
limit: s = Z,
|
|
2080
2096
|
filters: i,
|
|
2081
2097
|
tuning: a,
|
|
2082
2098
|
signal: l,
|
|
2083
|
-
dynamicLinking:
|
|
2099
|
+
dynamicLinking: c,
|
|
2084
2100
|
params: g,
|
|
2085
|
-
paramDefinitions:
|
|
2086
|
-
transformBody:
|
|
2087
|
-
} =
|
|
2101
|
+
paramDefinitions: d,
|
|
2102
|
+
transformBody: p
|
|
2103
|
+
} = n, u = L({
|
|
2088
2104
|
data: null,
|
|
2089
2105
|
error: null,
|
|
2090
2106
|
isFetching: !0
|
|
2091
2107
|
});
|
|
2092
2108
|
return (async () => {
|
|
2093
|
-
const
|
|
2109
|
+
const f = await e.layers.imageSearch(
|
|
2094
2110
|
{
|
|
2095
2111
|
image_id: o,
|
|
2096
|
-
pagination: { page:
|
|
2112
|
+
pagination: { page: r, limit: s },
|
|
2097
2113
|
filter_group: t.transformFilters(i),
|
|
2098
2114
|
tuning: a,
|
|
2099
|
-
dynamicLinking:
|
|
2100
|
-
transformBody:
|
|
2115
|
+
dynamicLinking: c,
|
|
2116
|
+
transformBody: K({ params: g, paramDefinitions: d, transformBody: p })
|
|
2101
2117
|
},
|
|
2102
2118
|
l
|
|
2103
2119
|
);
|
|
2104
|
-
if (
|
|
2105
|
-
|
|
2106
|
-
return;
|
|
2107
|
-
}
|
|
2108
|
-
const { results: h } = p.data, y = await t.fetchAndBuildProducts(h);
|
|
2109
|
-
if (y.error) {
|
|
2110
|
-
d.value = { data: null, error: y.error, isFetching: !1 };
|
|
2120
|
+
if (f.error) {
|
|
2121
|
+
u.value = { data: null, error: f.error, isFetching: !1 };
|
|
2111
2122
|
return;
|
|
2112
2123
|
}
|
|
2113
|
-
const
|
|
2114
|
-
products:
|
|
2115
|
-
raw:
|
|
2124
|
+
const { results: h, _meta: y } = f.data, E = t.extractGids(h), { cached: M } = e.store.products.getMany(E), T = new Map(M.map((m) => [m.gid, m])), w = t.buildProducts(h, T, y), b = re({
|
|
2125
|
+
products: w,
|
|
2126
|
+
raw: f.data,
|
|
2116
2127
|
extender: e.config.extendSearch
|
|
2117
2128
|
});
|
|
2118
|
-
e.store.products.set(
|
|
2119
|
-
})(),
|
|
2129
|
+
e.store.products.set(t.filterCacheableProducts(w)), u.value = { data: b, error: null, isFetching: !1 };
|
|
2130
|
+
})(), u;
|
|
2120
2131
|
};
|
|
2121
2132
|
}
|
|
2122
|
-
function
|
|
2123
|
-
const t =
|
|
2133
|
+
function Mn(e) {
|
|
2134
|
+
const t = pt({
|
|
2124
2135
|
layersPublicToken: e.layersPublicToken,
|
|
2125
2136
|
layersBaseUrl: e.layersBaseUrl,
|
|
2126
2137
|
sorts: e.sorts,
|
|
@@ -2128,77 +2139,252 @@ function yr(e) {
|
|
|
2128
2139
|
attributes: e.attributes,
|
|
2129
2140
|
fetch: e.fetch
|
|
2130
2141
|
});
|
|
2131
|
-
if (t.error) return
|
|
2132
|
-
const
|
|
2133
|
-
let o,
|
|
2142
|
+
if (t.error) return v(t.error);
|
|
2143
|
+
const n = t.data;
|
|
2144
|
+
let o, r = !1;
|
|
2134
2145
|
if (e.enableStorefront) {
|
|
2135
2146
|
if (!e.shop || !e.storefrontPublicToken)
|
|
2136
|
-
return
|
|
2137
|
-
|
|
2147
|
+
return v(
|
|
2148
|
+
U({
|
|
2138
2149
|
code: "MISSING_CONFIG",
|
|
2139
2150
|
message: "shop and storefrontPublicToken are required when enableStorefront is true",
|
|
2140
2151
|
field: e.shop ? "storefrontPublicToken" : "shop",
|
|
2141
2152
|
expected: "non-empty string"
|
|
2142
2153
|
})
|
|
2143
2154
|
);
|
|
2144
|
-
const
|
|
2155
|
+
const c = Ft({
|
|
2145
2156
|
shop: e.shop,
|
|
2146
2157
|
storefrontPublicToken: e.storefrontPublicToken,
|
|
2147
2158
|
storefrontApiVersion: e.storefrontApiVersion,
|
|
2148
2159
|
fetch: e.fetch
|
|
2149
2160
|
});
|
|
2150
|
-
if (
|
|
2151
|
-
o =
|
|
2161
|
+
if (c.error) return v(c.error);
|
|
2162
|
+
o = c.data, r = !0;
|
|
2152
2163
|
}
|
|
2153
|
-
const s =
|
|
2164
|
+
const s = Rt({
|
|
2154
2165
|
maxProducts: e.cacheMaxProducts,
|
|
2155
2166
|
maxQueries: e.cacheMaxEntries,
|
|
2156
|
-
ttl: e.cacheTtl
|
|
2157
|
-
|
|
2167
|
+
ttl: e.cacheTtl,
|
|
2168
|
+
storageAdapter: e.storageAdapter
|
|
2169
|
+
});
|
|
2170
|
+
if (e.restoreFromStorage !== !1 && s.restore(), e.initialData) {
|
|
2171
|
+
const { products: c, queries: g, collections: d } = e.initialData;
|
|
2172
|
+
if (c?.length && s.products.set(c), g)
|
|
2173
|
+
for (const [p, u] of Object.entries(g))
|
|
2174
|
+
s.queries.set(p, u);
|
|
2175
|
+
if (d)
|
|
2176
|
+
for (const [p, u] of Object.entries(d))
|
|
2177
|
+
s.collections.set(p, u);
|
|
2178
|
+
}
|
|
2179
|
+
const i = {
|
|
2158
2180
|
config: e,
|
|
2159
|
-
layers:
|
|
2181
|
+
layers: n,
|
|
2160
2182
|
storefront: o,
|
|
2161
|
-
storefrontEnabled:
|
|
2183
|
+
storefrontEnabled: r,
|
|
2162
2184
|
store: s,
|
|
2163
2185
|
mergeConfig: {
|
|
2164
2186
|
currencyCode: e.currencyCode,
|
|
2165
2187
|
formatPrice: e.formatPrice,
|
|
2166
2188
|
swatches: e.swatches
|
|
2167
2189
|
}
|
|
2168
|
-
}, a =
|
|
2190
|
+
}, a = Xt({ ctx: i }), l = {
|
|
2169
2191
|
config: e,
|
|
2170
2192
|
store: s,
|
|
2171
2193
|
collection: Wt({ ctx: i, helpers: a }),
|
|
2172
|
-
search:
|
|
2173
|
-
blocks:
|
|
2174
|
-
autocomplete:
|
|
2175
|
-
storefront:
|
|
2176
|
-
uploadImage:
|
|
2177
|
-
imageSearch:
|
|
2194
|
+
search: Jt({ ctx: i, helpers: a }),
|
|
2195
|
+
blocks: Yt({ ctx: i, helpers: a }),
|
|
2196
|
+
autocomplete: en({ ctx: i }),
|
|
2197
|
+
storefront: tn({ ctx: i }),
|
|
2198
|
+
uploadImage: nn({ ctx: i }),
|
|
2199
|
+
imageSearch: rn({ ctx: i, helpers: a })
|
|
2178
2200
|
};
|
|
2179
|
-
return
|
|
2201
|
+
return Kt(l), D(l);
|
|
2202
|
+
}
|
|
2203
|
+
function An({
|
|
2204
|
+
product: e,
|
|
2205
|
+
selectedOptions: t = [],
|
|
2206
|
+
breakoutOptions: n
|
|
2207
|
+
}) {
|
|
2208
|
+
const o = "_base" in e ? e._base : e, r = n ?? o.breakoutOptions ?? [], s = L(t), i = L(r), a = N(() => on(o.variants, i.value)), l = N(() => new Set(i.value.map((m) => m.name))), c = N(() => {
|
|
2209
|
+
const m = s.value.filter((_) => !l.value.has(_.name));
|
|
2210
|
+
return [...i.value, ...m];
|
|
2211
|
+
}), g = N(
|
|
2212
|
+
() => W(a.value, c.value)
|
|
2213
|
+
), d = N(
|
|
2214
|
+
() => an(a.value, o.options, l.value)
|
|
2215
|
+
), p = N(() => [...new Set(d.value.map((m) => m.name))]), u = N(() => d.value.find((_) => _.swatch)?.name ?? null), f = N(() => {
|
|
2216
|
+
const m = u.value;
|
|
2217
|
+
if (!m) return /* @__PURE__ */ new Map();
|
|
2218
|
+
const _ = /* @__PURE__ */ new Map();
|
|
2219
|
+
for (const F of a.value) {
|
|
2220
|
+
const S = F.selectedOptions.find((A) => A.name === m);
|
|
2221
|
+
S && _.set(F.numericId, S.value);
|
|
2222
|
+
}
|
|
2223
|
+
return _;
|
|
2224
|
+
}), h = N(() => {
|
|
2225
|
+
const m = u.value;
|
|
2226
|
+
return m ? d.value.filter((_) => _.name === m).map((_) => _.value) : [];
|
|
2227
|
+
}), y = N(() => {
|
|
2228
|
+
const m = u.value, _ = h.value, F = f.value;
|
|
2229
|
+
if (!m || _.length === 0)
|
|
2230
|
+
return [...o.images].sort((P, I) => P.position - I.position);
|
|
2231
|
+
const S = g.value ? F.get(g.value.numericId) : null, A = /* @__PURE__ */ new Map(), R = [];
|
|
2232
|
+
for (const P of o.images) {
|
|
2233
|
+
if (P.variantIds.length === 0) {
|
|
2234
|
+
R.push(P);
|
|
2235
|
+
continue;
|
|
2236
|
+
}
|
|
2237
|
+
let I = null;
|
|
2238
|
+
for (const k of P.variantIds) {
|
|
2239
|
+
const V = F.get(k);
|
|
2240
|
+
if (V) {
|
|
2241
|
+
I = V;
|
|
2242
|
+
break;
|
|
2243
|
+
}
|
|
2244
|
+
}
|
|
2245
|
+
if (I) {
|
|
2246
|
+
const k = A.get(I) ?? [];
|
|
2247
|
+
k.push(P), A.set(I, k);
|
|
2248
|
+
} else
|
|
2249
|
+
R.push(P);
|
|
2250
|
+
}
|
|
2251
|
+
for (const P of A.values())
|
|
2252
|
+
P.sort((I, k) => I.position - k.position);
|
|
2253
|
+
R.sort((P, I) => P.position - I.position);
|
|
2254
|
+
const O = [];
|
|
2255
|
+
S && A.has(S) && O.push(...A.get(S));
|
|
2256
|
+
for (const P of _)
|
|
2257
|
+
P !== S && A.has(P) && O.push(...A.get(P));
|
|
2258
|
+
return O.push(...R), O;
|
|
2259
|
+
}), E = N(() => {
|
|
2260
|
+
const m = g.value;
|
|
2261
|
+
if (!m?.image) return y.value;
|
|
2262
|
+
if (!u.value) return m.image ? [m.image] : y.value;
|
|
2263
|
+
const F = f.value.get(m.numericId);
|
|
2264
|
+
return F ? y.value.filter((S) => S.variantIds.length === 0 ? !1 : S.variantIds.some(
|
|
2265
|
+
(A) => f.value.get(A) === F
|
|
2266
|
+
)) : m.image ? [m.image] : y.value;
|
|
2267
|
+
}), M = N(() => y.value), T = N(() => {
|
|
2268
|
+
const m = new Set(c.value.map((_) => _.name));
|
|
2269
|
+
return p.value.every((_) => m.has(_));
|
|
2270
|
+
}), w = N(() => {
|
|
2271
|
+
const m = g.value;
|
|
2272
|
+
if (!m?.image) return 0;
|
|
2273
|
+
const _ = E.value.findIndex((F) => F.url === m.image?.url);
|
|
2274
|
+
return Math.max(0, _);
|
|
2275
|
+
});
|
|
2276
|
+
function b(m) {
|
|
2277
|
+
if (!m.image) return 0;
|
|
2278
|
+
const _ = y.value.findIndex((F) => F.url === m.image?.url);
|
|
2279
|
+
return Math.max(0, _);
|
|
2280
|
+
}
|
|
2281
|
+
return {
|
|
2282
|
+
product: e,
|
|
2283
|
+
// Reactive state
|
|
2284
|
+
variants: a,
|
|
2285
|
+
selectedVariant: g,
|
|
2286
|
+
selectedOptions: c,
|
|
2287
|
+
options: d,
|
|
2288
|
+
optionNames: p,
|
|
2289
|
+
swatchOptionName: u,
|
|
2290
|
+
images: E,
|
|
2291
|
+
allImages: M,
|
|
2292
|
+
carouselIndex: w,
|
|
2293
|
+
isSelectionComplete: T,
|
|
2294
|
+
// Actions
|
|
2295
|
+
selectOption(m, _) {
|
|
2296
|
+
const S = s.value.filter((A) => A.name !== m).concat({ name: m, value: _ });
|
|
2297
|
+
s.value = S;
|
|
2298
|
+
},
|
|
2299
|
+
setSelectedOptions(m) {
|
|
2300
|
+
const _ = new Set(m.map((S) => S.name)), F = s.value.filter((S) => !_.has(S.name));
|
|
2301
|
+
s.value = [...F, ...m];
|
|
2302
|
+
},
|
|
2303
|
+
setBreakoutOptions(m) {
|
|
2304
|
+
i.value = m;
|
|
2305
|
+
},
|
|
2306
|
+
// Queries
|
|
2307
|
+
getOptionValues(m) {
|
|
2308
|
+
return sn(a.value, m);
|
|
2309
|
+
},
|
|
2310
|
+
getSwatches(m) {
|
|
2311
|
+
return d.value.filter((_) => _.name === m && _.swatch).map((_) => _.swatch);
|
|
2312
|
+
},
|
|
2313
|
+
getVariantByOptions(m) {
|
|
2314
|
+
const _ = [...i.value, ...m];
|
|
2315
|
+
return W(a.value, _);
|
|
2316
|
+
},
|
|
2317
|
+
getCarouselIndexForVariant: b,
|
|
2318
|
+
isOptionAvailable(m, _) {
|
|
2319
|
+
const F = s.value.filter((R) => R.name !== m).concat({ name: m, value: _ }), S = [...i.value, ...F];
|
|
2320
|
+
return W(a.value, S)?.availableForSale ?? !1;
|
|
2321
|
+
},
|
|
2322
|
+
isVariantAvailable(m) {
|
|
2323
|
+
return m.availableForSale;
|
|
2324
|
+
},
|
|
2325
|
+
getOptionAvailabilityStatus(m, _) {
|
|
2326
|
+
const F = s.value.filter((R) => R.name !== m).concat({ name: m, value: _ }), S = [...i.value, ...F], A = W(a.value, S);
|
|
2327
|
+
return A ? A.availableForSale ? "available" : A.inventoryPolicy === "CONTINUE" ? "backorderable" : "sold-out" : "unavailable";
|
|
2328
|
+
},
|
|
2329
|
+
dispose() {
|
|
2330
|
+
}
|
|
2331
|
+
};
|
|
2332
|
+
}
|
|
2333
|
+
function on(e, t) {
|
|
2334
|
+
return t.length === 0 ? e : e.filter(
|
|
2335
|
+
(n) => t.every(
|
|
2336
|
+
(o) => n.selectedOptions.some((r) => r.name === o.name && r.value === o.value)
|
|
2337
|
+
)
|
|
2338
|
+
);
|
|
2339
|
+
}
|
|
2340
|
+
function W(e, t) {
|
|
2341
|
+
return t.length === 0 ? e[0] ?? null : e.find(
|
|
2342
|
+
(n) => t.every(
|
|
2343
|
+
(o) => n.selectedOptions.some((r) => r.name === o.name && r.value === o.value)
|
|
2344
|
+
)
|
|
2345
|
+
) ?? null;
|
|
2346
|
+
}
|
|
2347
|
+
function an(e, t, n) {
|
|
2348
|
+
const o = /* @__PURE__ */ new Set();
|
|
2349
|
+
for (const r of e)
|
|
2350
|
+
for (const s of r.selectedOptions)
|
|
2351
|
+
n.has(s.name) || o.add(`${s.name}:${s.value}`);
|
|
2352
|
+
return t.filter(
|
|
2353
|
+
(r) => !n.has(r.name) && o.has(`${r.name}:${r.value}`)
|
|
2354
|
+
);
|
|
2355
|
+
}
|
|
2356
|
+
function sn(e, t) {
|
|
2357
|
+
const n = /* @__PURE__ */ new Set();
|
|
2358
|
+
for (const o of e) {
|
|
2359
|
+
const r = o.selectedOptions.find((s) => s.name === t);
|
|
2360
|
+
r && n.add(r.value);
|
|
2361
|
+
}
|
|
2362
|
+
return [...n];
|
|
2180
2363
|
}
|
|
2181
2364
|
export {
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2365
|
+
$t as and,
|
|
2366
|
+
wn as batch,
|
|
2367
|
+
On as computed,
|
|
2368
|
+
An as createProductCard,
|
|
2369
|
+
Mn as createSdk,
|
|
2370
|
+
Rn as effect,
|
|
2371
|
+
fn as eq,
|
|
2372
|
+
In as exists,
|
|
2373
|
+
Fn as filter,
|
|
2374
|
+
zt as getSdk,
|
|
2375
|
+
hn as gt,
|
|
2376
|
+
_n as gte,
|
|
2377
|
+
mn as inValues,
|
|
2378
|
+
Sn as isInitialized,
|
|
2379
|
+
un as isRetryable,
|
|
2380
|
+
ln as isSdkError,
|
|
2381
|
+
dn as jsonFileAdapter,
|
|
2382
|
+
At as localStorageAdapter,
|
|
2383
|
+
vn as lt,
|
|
2384
|
+
yn as lte,
|
|
2385
|
+
gn as notEq,
|
|
2386
|
+
En as notExists,
|
|
2387
|
+
pn as notIn,
|
|
2388
|
+
bn as or,
|
|
2389
|
+
kn as signal
|
|
2204
2390
|
};
|