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

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