@commerce-blocks/sdk 1.2.1 → 2.0.0-alpha.0

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