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