@commerce-blocks/sdk 1.3.0 → 2.0.0-alpha.1

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