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