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