@commerce-blocks/sdk 2.0.0-alpha.1 → 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 +185 -93
  2. package/dist/index.d.ts +135 -148
  3. package/dist/index.js +1218 -1164
  4. package/package.json +1 -1
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 Cn, signal as kn } from "@preact/signals-core";
3
- const Qe = "2.0.0-alpha.1", Ke = {
4
- version: Qe
5
- }, ze = "2026-01", Xe = "https://app.uselayers.com/api/storefront/v1", We = 1e3, Ce = 1e3, ke = 100, Je = 300 * We, pe = Ke.version, ae = 250, B = 20, G = 250, se = 250, ie = 250, ce = 1, le = 1, Y = 1, Z = 24, ue = 1, de = 1, fe = 100, Ye = 20, Ze = 50, et = 300, tt = 50, De = "USD", nt = "en-US", rt = 1e3, Re = /* @__PURE__ */ new Map();
6
- function Ne(e, t) {
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 = Re.get(n);
9
- return o || (o = new Intl.NumberFormat(nt, {
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), Re.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 k(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 un(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 dn(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 = Xe } = 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 [a, i] of Object.entries(e.params))
201
- i != null && t.append(a, typeof i == "object" ? JSON.stringify(i) : String(i));
202
- const n = t.toString(), o = n ? `${e.endpoint}?${n}` : e.endpoint, r = e.config.fetch ?? fetch;
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 a = 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(a);
210
- } catch (a) {
211
- return v(ve(a));
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
- k("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(
237
- k(
246
+ ), e.limit !== void 0 && (e.limit < ge || e.limit > me) && n.push(
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, a) => {
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
- k("collectionHandle", "REQUIRED_FIELD", "collectionHandle is required")
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
- k("sort_order_code", "REQUIRED_FIELD", "sort_order_code is required")
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: s, 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/${s}`,
336
- body: d,
337
- signal: a
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, a) => 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: a
345
- }) : v(
346
- q({
358
+ params: { query: o },
359
+ signal: i
360
+ }) : y(
361
+ D({
347
362
  operation: "predictiveSearch",
348
- fields: [k("query", "REQUIRED_FIELD", "query is required")]
363
+ fields: [C("query", "REQUIRED_FIELD", "query is required")]
349
364
  })
350
365
  ),
351
- prepareSearch: async (r, a) => {
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
- fields: [k("query", "REQUIRED_FIELD", "query is required")]
371
+ fields: [C("query", "REQUIRED_FIELD", "query is required")]
357
372
  })
358
373
  );
359
- const { query: i, transformBody: s, ...l } = r;
360
- let c = { ...l };
361
- return s && (c = s(c)), x({
362
- config: n,
363
- endpoint: `/search/${encodeURIComponent(i)}/prepare`,
364
- body: c,
365
- signal: a
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, a) => {
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
- fields: [k("query", "REQUIRED_FIELD", "query is required")]
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: s, 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(s)}/execute`,
389
- body: d,
390
- signal: a
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, a) => {
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
- k("image_data", "REQUIRED_FIELD", "image_data or image_id is required")
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: s, transformBody: l, ...c } = r;
406
- let g = {
407
- attributes: t(s),
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: a
417
+ body: n({ attributes: c, transformBody: u, rest: g, includeFacets: !1 }),
418
+ signal: i
415
419
  });
416
420
  },
417
- uploadImage: async (r, a) => {
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: a
426
+ formData: a,
427
+ signal: i
424
428
  });
425
429
  },
426
- blocks: async (r, a) => {
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
- fields: [k("blockId", "REQUIRED_FIELD", "blockId is required")]
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: s, 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/${s}/products`,
447
- body: d,
448
- signal: a
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, a) => {
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
- fields: [k("productId", "REQUIRED_FIELD", "productId is required")]
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: s, 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/${s}`,
469
- body: d,
470
- signal: a
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
- `, qe = `
473
+ `, Ue = `
481
474
  fragment FilterValueFields on FilterValue {
482
475
  id
483
476
  label
484
477
  count
485
478
  input
486
479
  }
487
- `, $e = `
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 Pe(e) {
532
+ function Te(e) {
540
533
  return `
541
534
  fragment VariantFields on ProductVariant {
542
535
  id
@@ -552,8 +545,8 @@ function Pe(e) {
552
545
  }
553
546
  `;
554
547
  }
555
- function Ae(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 Ae(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 Le(e) {
573
+ function Be(e) {
581
574
  return `
582
575
  fragment CollectionFields on Collection {
583
576
  id
@@ -592,7 +585,7 @@ function Le(e) {
592
585
  }
593
586
  `;
594
587
  }
595
- function Ve(e) {
588
+ function Ge(e) {
596
589
  return `
597
590
  fragment PageFields on Page {
598
591
  id
@@ -608,36 +601,36 @@ function Ve(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
- Pe(n),
621
- Ae(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, a = o.length > 0, i = r.length > 0, s = ["$ids: [ID!]!"];
632
- return a && s.push("$productMetafields: [HasMetafieldsIdentifier!]!"), i && s.push("$variantMetafields: [HasMetafieldsIdentifier!]!"), `
633
- ${ht({
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: a,
629
+ includeProductMetafields: o,
637
630
  includeVariantMetafields: i
638
631
  })}
639
632
 
640
- query ProductsByIds(${s.join(", ")}) {
633
+ query ProductsByIds(${a.join(", ")}) {
641
634
  nodes(ids: $ids) {
642
635
  ... on Product {
643
636
  ...ProductFields
@@ -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: a = [],
644
+ maxImages: t = G,
645
+ maxVariants: n = j,
646
+ productMetafields: r = [],
647
+ variantMetafields: s = [],
648
+ collectionMetafields: o = [],
656
649
  includeFilters: i = !1
657
- } = e, s = o.length > 0, l = r.length > 0, c = a.length > 0, g = s || l || c, d = ["$ids: [ID!]!", "$handle: String!"];
658
- return s && d.push("$productMetafields: [HasMetafieldsIdentifier!]!"), l && d.push("$variantMetafields: [HasMetafieldsIdentifier!]!"), c && d.push("$collectionMetafields: [HasMetafieldsIdentifier!]!"), `
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 ? qe : "",
668
- i ? $e : "",
669
- Pe(l),
670
- Ae({
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
- includeProductMetafields: s
666
+ includeProductMetafields: a
674
667
  }),
675
- Le(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 ? qe : "",
700
- n ? $e : "",
701
- Le(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
- Ve(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: a = []
737
- } = e, i = o.length > 0, s = r.length > 0, l = a.length > 0, c = i || s || l, g = ["$ids: [ID!]!", "$handle: String!"];
738
- return i && g.push("$productMetafields: [HasMetafieldsIdentifier!]!"), s && g.push("$variantMetafields: [HasMetafieldsIdentifier!]!"), l && g.push("$pageMetafields: [HasMetafieldsIdentifier!]!"), `
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
- Pe(s),
748
- Ae({
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
- Ve(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(a, { variables: i, signal: s } = {}) {
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: a, variables: i }),
785
- signal: s
777
+ body: JSON.stringify({ query: o, variables: i }),
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,225 +812,225 @@ function Ft(e) {
819
812
  expected: "non-empty string"
820
813
  })
821
814
  );
822
- const { storefrontApiVersion: t = ze } = 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: a,
824
+ ids: o,
832
825
  productMetafields: i = [],
833
- variantMetafields: s = [],
834
- maxImages: l = B,
835
- maxVariants: c = G,
826
+ variantMetafields: a = [],
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 (a.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
- variantMetafields: s
847
- }), u = ge({ ids: a, maxSize: ae }), f = [];
848
- for (const h of u) {
849
- const y = { ids: h };
850
- i.length > 0 && (y.productMetafields = i), s.length > 0 && (y.variantMetafields = s);
851
- const E = await St({ graphqlClient: n, query: p, variables: y, signal: g });
852
- if (E.error)
853
- return E;
854
- f.push(...E.data);
839
+ variantMetafields: a
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: a, collectionMetafields: i = [], includeFilters: s = !1, signal: l } = r;
860
- if (!a)
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
- fields: [k("handle", "REQUIRED_FIELD", "handle is required")]
857
+ fields: [C("handle", "REQUIRED_FIELD", "handle is required")]
865
858
  })
866
859
  );
867
- const c = yt({ collectionMetafields: i, includeFilters: s }), g = { handle: a };
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: ${a}`
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: a,
880
+ handle: o,
888
881
  ids: i,
889
- productMetafields: s = [],
890
- variantMetafields: l = [],
891
- collectionMetafields: c = [],
882
+ productMetafields: a = [],
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 (a || f.push(k("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,
907
- productMetafields: s,
908
- variantMetafields: l,
909
- collectionMetafields: c,
899
+ maxVariants: m,
900
+ productMetafields: a,
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 A = 0; A < y.length; A++) {
915
- const b = { ids: y[A], handle: a };
916
- s.length > 0 && (b.productMetafields = s), l.length > 0 && (b.variantMetafields = l), c.length > 0 && (b.collectionMetafields = c);
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 (A === 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: ${a}`
920
+ message: `Collection not found: ${o}`
928
921
  })
929
922
  );
930
- const S = (F.nodes ?? []).filter((P) => P !== 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: a, pageMetafields: i = [], signal: s } = r;
940
- if (!a)
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
- fields: [k("handle", "REQUIRED_FIELD", "handle is required")]
937
+ fields: [C("handle", "REQUIRED_FIELD", "handle is required")]
945
938
  })
946
939
  );
947
- const l = It({ pageMetafields: i }), c = { handle: a };
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: s });
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: ${a}`
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: a,
960
+ handle: o,
968
961
  ids: i,
969
- productMetafields: s = [],
970
- variantMetafields: l = [],
971
- pageMetafields: c = [],
972
- maxImages: g = B,
973
- maxVariants: d = G,
974
- signal: p
975
- } = r, u = me(r);
976
- if (a || u.push(k("handle", "REQUIRED_FIELD", "handle is required")), u.length > 0)
977
- return v(
978
- q({ operation: "getPageWithProducts", fields: u })
962
+ productMetafields: a = [],
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
- productMetafields: s,
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 R = { ids: h[M], handle: a };
991
- s.length > 0 && (R.productMetafields = s), l.length > 0 && (R.variantMetafields = l), c.length > 0 && (R.pageMetafields = c);
976
+ productMetafields: a,
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: R, signal: p });
994
- if (m)
995
- return v(H(m));
996
- const _ = b;
997
- if (M === 0 && (y = _.page ?? null, !y))
998
- return v(
999
- $({
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: ${a}`
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(
1018
- k(
1010
+ e.maxImages !== void 0 && (e.maxImages < ue || e.maxImages > ce) && t.push(
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(
1028
- k(
1020
+ ), e.maxVariants !== void 0 && (e.maxVariants < de || e.maxVariants > le) && t.push(
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
  );
1038
1031
  for (const n of e.productMetafields ?? [])
1039
1032
  (!n.namespace || !n.key) && t.push(
1040
- k(
1033
+ C(
1041
1034
  "productMetafields",
1042
1035
  "REQUIRED_FIELD",
1043
1036
  "Metafield identifier requires both namespace and key",
@@ -1049,7 +1042,7 @@ function me(e) {
1049
1042
  );
1050
1043
  for (const n of e.variantMetafields ?? [])
1051
1044
  (!n.namespace || !n.key) && t.push(
1052
- k(
1045
+ C(
1053
1046
  "variantMetafields",
1054
1047
  "REQUIRED_FIELD",
1055
1048
  "Metafield identifier requires both namespace and key",
@@ -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: a } = await e.request(t, { variables: n, signal: o });
1072
- if (a)
1073
- return v(H(a));
1074
- const i = (r?.nodes ?? []).filter(
1075
- (s) => s !== null
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(
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 Pt(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 fn(e, t) {
1134
+ function yn(e, t) {
1142
1135
  return {
1143
1136
  read() {
1144
1137
  try {
@@ -1161,360 +1154,360 @@ function fn(e, t) {
1161
1154
  }
1162
1155
  };
1163
1156
  }
1164
- function At(e) {
1165
- typeof requestIdleCallback == "function" ? requestIdleCallback(e, { timeout: rt }) : setTimeout(e, 0);
1157
+ function Dt(e) {
1158
+ typeof requestIdleCallback == "function" ? requestIdleCallback(e, { timeout: ct }) : setTimeout(e, 0);
1166
1159
  }
1167
- function we(e) {
1160
+ function De(e) {
1168
1161
  return [...e].sort((t, n) => n[1].timestamp - t[1].timestamp);
1169
1162
  }
1170
- function Tt({
1171
- storageKey: e = Mt,
1172
- maxProducts: t = Ce,
1173
- maxQueries: n = ke,
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 ?? Pt(e);
1177
- let a = 0;
1169
+ const s = r ?? kt(e);
1170
+ let o = 0;
1178
1171
  return {
1179
1172
  save(i) {
1180
- if (!r) return;
1181
- const s = ++a;
1182
- At(() => {
1183
- if (s === a)
1173
+ if (!s) return;
1174
+ const a = ++o;
1175
+ Dt(() => {
1176
+ if (a === o)
1184
1177
  try {
1185
- const l = {
1186
- products: we(i.products).slice(
1178
+ const c = {
1179
+ products: De(i.products).slice(
1187
1180
  0,
1188
1181
  t
1189
1182
  ),
1190
- queries: we(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
- const s = JSON.parse(i);
1205
- return s.version !== pe || !Array.isArray(s.products) || !Array.isArray(s.queries) ? (r.remove(), null) : s;
1197
+ const a = JSON.parse(i);
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
- a++, r?.remove();
1204
+ o++, s?.remove();
1212
1205
  }
1213
1206
  };
1214
1207
  }
1215
- function Rt(e, t) {
1208
+ function qt(e, t) {
1216
1209
  if (e.size <= t) return;
1217
- const o = [...e.entries()].sort((r, a) => r[1].timestamp - a[1].timestamp).slice(0, e.size - t);
1218
- for (const [r] of o)
1219
- e.delete(r);
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 wt(e, t) {
1214
+ function Lt(e, t) {
1222
1215
  if (e.size <= t) return;
1223
1216
  const n = [];
1224
- for (const [r, a] of e)
1225
- a.value && n.push([r, a.value.timestamp]);
1226
- n.sort((r, a) => r[1] - a[1]);
1227
- const o = n.slice(0, e.size - t);
1228
- for (const [r] of o) {
1229
- const a = e.get(r);
1230
- a && (a.value = null), e.delete(r);
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 Ot(e = {}) {
1226
+ function $t(e = {}) {
1234
1227
  const {
1235
- ttl: t = Je,
1236
- maxProducts: n = Ce,
1237
- maxQueries: o = ke,
1238
- storageKey: r,
1239
- storageAdapter: a
1240
- } = e, i = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map(), g = Tt({
1241
- storageKey: r,
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: a
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
- Rt(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() }, wt(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 s.get(u);
1295
+ get(l) {
1296
+ return a.get(l);
1304
1297
  },
1305
- set(u, f) {
1306
- s.set(u, { ...f, handle: u });
1298
+ set(l, f) {
1299
+ a.set(l, { ...f, handle: l });
1307
1300
  },
1308
- delete(u) {
1309
- s.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 s)
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
- s.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(), s.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,
1356
- collections: s.size,
1357
- pages: l.size
1348
+ queries: u.size,
1349
+ collections: a.size,
1350
+ pages: c.size
1358
1351
  };
1359
1352
  }
1360
1353
  };
1361
1354
  }
1362
- function Ue(e, t) {
1355
+ function je(e, t) {
1363
1356
  return `gid://shopify/${e}/${t}`;
1364
1357
  }
1365
- function Ct(e) {
1366
- return Ue("Product", e);
1358
+ function Vt(e) {
1359
+ return je("Product", e);
1367
1360
  }
1368
- function kt(e) {
1369
- return Ue("ProductVariant", e);
1361
+ function Ut(e) {
1362
+ return je("ProductVariant", e);
1370
1363
  }
1371
- const Oe = (e) => encodeURIComponent(e).replace(/-/g, "%2D");
1372
- function xe({
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 }) => `${Oe(o)}:${Oe(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 Be(e) {
1374
+ function Qe(e) {
1382
1375
  return e.product_id ?? e.id;
1383
1376
  }
1384
- function he(e) {
1385
- return Ct(Be(e));
1377
+ function ve(e) {
1378
+ return Vt(Qe(e));
1386
1379
  }
1387
- function Te(e, t = []) {
1388
- return Object.entries(e).filter(([n, o]) => o != null && !t.includes(n)).sort(([n], [o]) => n.localeCompare(o)).map(
1389
- ([n, o]) => `${encodeURIComponent(n)}=${encodeURIComponent(typeof o == "object" ? JSON.stringify(o) : String(o))}`
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 = Te(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 = Te(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 = Te(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 || {}), Ge = /* @__PURE__ */ ((e) => (e.And = "AND", e.Or = "OR", e))(Ge || {});
1408
- function gn(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 mn(e, t) {
1404
+ function En(e, t) {
1412
1405
  return { property: e, operator: "not_eq", values: [t] };
1413
1406
  }
1414
- function pn(e, t) {
1407
+ function In(e, t) {
1415
1408
  return { property: e, operator: "in", values: t };
1416
1409
  }
1417
- function hn(e, t) {
1410
+ function Sn(e, t) {
1418
1411
  return { property: e, operator: "not_in", values: t };
1419
1412
  }
1420
- function _n(e, t) {
1413
+ function Fn(e, t) {
1421
1414
  return { property: e, operator: "gt", values: [t] };
1422
1415
  }
1423
- function vn(e, t) {
1416
+ function Mn(e, t) {
1424
1417
  return { property: e, operator: "gte", values: [t] };
1425
1418
  }
1426
- function yn(e, t) {
1419
+ function Pn(e, t) {
1427
1420
  return { property: e, operator: "lt", values: [t] };
1428
1421
  }
1429
- function In(e, t) {
1422
+ function An(e, t) {
1430
1423
  return { property: e, operator: "lte", values: [t] };
1431
1424
  }
1432
- function En(e) {
1425
+ function Tn(e) {
1433
1426
  return { property: e, operator: "exists", values: [] };
1434
1427
  }
1435
- function bn(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 Fn(...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 Sn(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 = De,
1453
- formatPrice: n = Ne,
1454
- swatches: o = [],
1455
- breakoutContext: r
1445
+ currencyCode: t = $e,
1446
+ formatPrice: n = Ve,
1447
+ swatches: r = [],
1448
+ breakoutContext: s
1456
1449
  }) {
1457
- const a = Be(e), i = he(e), s = e.title, l = e.handle ?? "", c = e.vendor ?? "", g = e.product_type ?? "", d = e.body_html ?? "", p = e.available ?? !1, u = e.is_gift_card ?? !1, f = e.tags ?? [], h = Ut(e), y = xt(e.price_range, t, n), E = Bt(e, o), M = jt(e, t, n), A = M.map((I) => I.compareAtPrice).filter((I) => I !== null), R = A.length > 0 ? {
1458
- min: A.reduce((I, C) => I.amount < C.amount ? I : C),
1459
- max: A.reduce((I, C) => I.amount > C.amount ? I : C)
1460
- } : void 0, b = e.first_or_matched_variant ? Gt(e.first_or_matched_variant) : [], m = xe({ type: "Product", selectedOptions: b }), _ = e.metafields ?? {}, F = e.category ? {
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, P = e.named_tags ? Array.isArray(e.named_tags) ? void 0 : Object.entries(e.named_tags).map(([I, C]) => ({ name: I, value: C })) : void 0, O = e.first_or_matched_variant ? M.find((I) => I.numericId === e.first_or_matched_variant.id) ?? null : null;
1473
- let w, T;
1474
- if (r?.isVariantTile) {
1475
- T = r.variantId;
1476
- const I = M.find((C) => C.numericId === T);
1477
- if (I) {
1478
- const C = new Set(r.optionCodes);
1479
- w = I.selectedOptions.filter((V) => C.has(V.name));
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: a,
1486
- title: s,
1487
- handle: l,
1478
+ numericId: o,
1479
+ title: a,
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,
1494
- compareAtPriceRange: R,
1495
- options: E,
1484
+ availableForSale: m,
1485
+ images: _,
1486
+ priceRange: h,
1487
+ compareAtPriceRange: w,
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: P,
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
- selectedVariant: O,
1513
- breakoutOptions: w,
1514
- breakoutVariantId: T
1505
+ selectedVariant: R,
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, a] of Object.entries(o))
1537
- for (const i of a) {
1538
- const s = t.find((l) => l.name === r && l.value === i);
1539
- n.push({ name: r, value: i, swatch: s });
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: xe({ type: "ProductVariant", selectedOptions: e.selected_options }),
1553
- gid: kt(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((a) => ({ name: a.name, value: a.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 je() {
1584
+ function ze() {
1592
1585
  return typeof window < "u" && typeof window.document < "u";
1593
1586
  }
1594
- const He = "__COMMERCE_BLOCKS__";
1595
- function Kt(e) {
1596
- je() && (window[He] = e);
1587
+ const Xe = "__COMMERCE_BLOCKS__";
1588
+ function en(e) {
1589
+ ze() && (window[Xe] = e);
1597
1590
  }
1598
- function zt() {
1599
- if (!je())
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[He];
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,17 +1607,17 @@ function zt() {
1614
1607
  })
1615
1608
  );
1616
1609
  }
1617
- function Mn() {
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
1616
  extender: n,
1624
- currencyCode: o = De,
1625
- formatPrice: r = Ne
1617
+ currencyCode: r = $e,
1618
+ formatPrice: s = Ve
1626
1619
  }) {
1627
- const a = {
1620
+ const o = {
1628
1621
  products: e,
1629
1622
  totalResults: t.totalResults,
1630
1623
  totalPages: t.totalPages,
@@ -1632,364 +1625,413 @@ function re({
1632
1625
  resultsPerPage: t.resultsPerPage,
1633
1626
  facets: t.facets ?? {},
1634
1627
  facetRanges: t.facetRanges,
1635
- priceRange: Xt(t.facetRanges, o, r),
1628
+ priceRange: nn(t.facetRanges, r, s),
1636
1629
  attributionToken: t.attributionToken,
1637
1630
  _workflow: t._workflow
1638
1631
  };
1639
- return n ? n(a, t) : a;
1632
+ return n ? n(o, t) : o;
1640
1633
  }
1641
- function Xt(e, t, n) {
1642
- const o = e?.["variants.price"];
1643
- if (o)
1634
+ function nn(e, t, n) {
1635
+ const r = e?.["variants.price"];
1636
+ if (r)
1644
1637
  return {
1645
- min: { amount: o.min, currencyCode: t, formatted: n(o.min, t) },
1646
- max: { amount: o.max, currencyCode: t, formatted: n(o.max, t) }
1638
+ min: { amount: r.min, currencyCode: t, formatted: n(r.min, t) },
1639
+ max: { amount: r.max, currencyCode: t, formatted: n(r.max, t) }
1647
1640
  };
1648
1641
  }
1649
- function Wt({ ctx: e }) {
1650
- function t(s) {
1651
- return s.map((l) => he(l));
1642
+ function rn({ ctx: e }) {
1643
+ function t(a) {
1644
+ return a.map((c) => ve(c));
1652
1645
  }
1653
- function n(s, l) {
1654
- const c = Vt({ layers: s, ...e.mergeConfig, breakoutContext: l });
1646
+ function n(a, c) {
1647
+ const u = Qt({ layers: a, ...e.mergeConfig, breakoutContext: c });
1655
1648
  return e.config.extendProduct ? { ...e.config.extendProduct({
1656
- base: c,
1657
- raw: s,
1649
+ base: u,
1650
+ raw: a,
1658
1651
  storefront: null
1659
- }), _base: c } : c;
1652
+ }), _base: u } : u;
1660
1653
  }
1661
- function o(s, l) {
1662
- if (!(s.__typename !== "Variant" || l.length === 0))
1654
+ function r(a, c) {
1655
+ if (!(a.__typename !== "Variant" || c.length === 0))
1663
1656
  return {
1664
1657
  isVariantTile: !0,
1665
- variantId: s.variant_id,
1666
- optionCodes: l
1658
+ variantId: a.variant_id,
1659
+ optionCodes: c
1667
1660
  };
1668
1661
  }
1669
- function r(s, l, c) {
1670
- const g = c?.variantBreakouts?.map((d) => d.optionCode) ?? [];
1671
- return s.map((d) => {
1672
- const p = he(d), u = o(d, g);
1673
- if (!u) {
1674
- const f = l.get(p);
1662
+ function s(a, c, u) {
1663
+ const g = u?.variantBreakouts?.map((d) => d.optionCode) ?? [];
1664
+ return a.map((d) => {
1665
+ const m = ve(d), l = r(d, g);
1666
+ if (!l) {
1667
+ const f = c.get(m);
1675
1668
  if (f) return f;
1676
1669
  }
1677
- return n(d, u);
1670
+ return n(d, l);
1678
1671
  });
1679
1672
  }
1680
- function a(s) {
1681
- if (s) {
1673
+ function o(a) {
1674
+ if (a) {
1682
1675
  if (e.config.transformFilters)
1683
- return e.config.transformFilters(s);
1684
- if (e.config.filterMap && typeof s == "object" && !Array.isArray(s)) {
1685
- const l = s, c = [];
1686
- for (const [g, d] of Object.entries(l)) {
1676
+ return e.config.transformFilters(a);
1677
+ if (e.config.filterMap && typeof a == "object" && !Array.isArray(a)) {
1678
+ const c = a, u = [];
1679
+ for (const [g, d] of Object.entries(c)) {
1687
1680
  if (d == null) continue;
1688
- const p = e.config.filterMap[g], u = typeof p == "string" ? p : p?.property ?? g, f = typeof p == "object" ? p.values : void 0, y = (Array.isArray(d) ? d : [d]).map((E) => {
1689
- const M = String(E);
1690
- return f?.[M] ?? M;
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;
1691
1684
  });
1692
- c.push({
1693
- property: u,
1694
- operator: y.length > 1 ? _e.In : _e.Equal,
1695
- values: y
1685
+ u.push({
1686
+ property: l,
1687
+ operator: h.length > 1 ? ye.In : ye.Equal,
1688
+ values: h
1696
1689
  });
1697
1690
  }
1698
- return c.length === 0 ? void 0 : {
1699
- conditional: Ge.And,
1700
- expressions: c
1691
+ return u.length === 0 ? void 0 : {
1692
+ conditional: Ke.And,
1693
+ expressions: u
1701
1694
  };
1702
1695
  }
1703
- return s;
1696
+ return a;
1704
1697
  }
1705
1698
  }
1706
- function i(s) {
1707
- return s.filter((l) => !l.breakoutVariantId);
1699
+ function i(a) {
1700
+ return a.filter((c) => !c.breakoutVariantId);
1708
1701
  }
1709
1702
  return {
1710
1703
  extractGids: t,
1711
- buildProducts: r,
1712
- transformFilters: a,
1704
+ buildProducts: s,
1705
+ transformFilters: o,
1713
1706
  filterCacheableProducts: i
1714
1707
  };
1715
1708
  }
1716
- function oe(e) {
1709
+ function z(...e) {
1717
1710
  const t = new AbortController();
1718
- 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;
1719
1720
  }
1720
- function K({
1721
+ function se(e, t) {
1722
+ return We(() => t(e.value));
1723
+ }
1724
+ function X({
1721
1725
  params: e,
1722
1726
  paramDefinitions: t,
1723
1727
  transformBody: n
1724
1728
  }) {
1725
- return !e && !t && !n ? (o) => o : (o) => {
1726
- let r = o;
1727
- const a = t && Object.keys(t).length > 0;
1728
- if (e || a) {
1729
+ return !e && !t && !n ? (r) => r : (r) => {
1730
+ let s = r;
1731
+ const o = t && Object.keys(t).length > 0;
1732
+ if (e || o) {
1729
1733
  const i = {};
1730
1734
  if (t)
1731
- for (const [s, l] of Object.entries(t)) {
1732
- const c = l(s);
1733
- c != null && (i[s] = c);
1735
+ for (const [a, c] of Object.entries(t)) {
1736
+ const u = c(a);
1737
+ u != null && (i[a] = u);
1734
1738
  }
1735
- r = { ...r, ...e, ...i };
1739
+ s = { ...s, ...e, ...i };
1736
1740
  }
1737
- return n ? n(r) : r;
1741
+ return n ? n(s) : s;
1738
1742
  };
1739
1743
  }
1740
- function Jt({
1744
+ function on({
1741
1745
  ctx: e,
1742
1746
  helpers: t
1743
1747
  }) {
1744
- return ({ handle: n, defaultSort: o }) => {
1745
- const r = L({
1748
+ return ({ handle: n, defaultSort: r }) => {
1749
+ const s = V({
1746
1750
  data: null,
1747
1751
  error: null,
1748
1752
  isFetching: !1
1749
1753
  });
1750
- let a = 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();
1751
1756
  return {
1752
- state: r,
1753
- async execute(s = {}) {
1757
+ state: s,
1758
+ async execute(c = {}) {
1754
1759
  const {
1755
- page: l = Y,
1756
- limit: c = Z,
1757
- filters: g,
1758
- sortOrderCode: d,
1759
- signal: p,
1760
- includeMeta: u = e.config.includeMeta ?? !1,
1761
- 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: _,
1762
1767
  params: h,
1763
- paramDefinitions: y,
1764
- transformBody: E
1765
- } = s, M = d ?? i;
1766
- i = M, a?.abort(), a = oe(p);
1767
- const A = r.value.data;
1768
- r.value = { data: A, error: null, isFetching: !0 };
1769
- const { data: R, error: b } = await e.layers.browse(
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(
1770
1775
  {
1771
1776
  collectionHandle: n,
1772
- sort_order_code: M,
1773
- pagination: { page: l, limit: c },
1774
- filter_group: t.transformFilters(g),
1775
- dynamicLinking: f,
1776
- transformBody: K({ params: h, paramDefinitions: y, transformBody: E })
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 })
1777
1782
  },
1778
- a.signal
1783
+ o.signal
1779
1784
  );
1780
- if (b)
1781
- return r.value = { data: A, error: b, isFetching: !1 }, v(b);
1782
- const { results: m, _meta: _ } = R, F = t.extractGids(m), { cached: S } = e.store.products.getMany(F), P = new Map(S.map((I) => [I.gid, I])), O = t.buildProducts(m, P, _), w = re({
1783
- products: O,
1784
- raw: R,
1785
+ 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,
1785
1790
  extender: e.config.extendCollection,
1786
1791
  currencyCode: e.mergeConfig.currencyCode,
1787
1792
  formatPrice: e.mergeConfig.formatPrice
1788
1793
  });
1789
- u && R._meta && (w._meta = R._meta);
1790
- const T = Dt(n, { sortOrderCode: M, page: l, limit: c, filters: g });
1791
- return T && e.store.queries.set(T, w), e.store.products.set(t.filterCacheableProducts(O)), e.store.collections.set(n, {
1792
- totalProducts: w.totalResults,
1793
- totalPages: w.totalPages,
1794
- lastPageFetched: l,
1795
- facets: w.facets,
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,
1796
1801
  lastFetched: Date.now()
1797
- }), r.value = { data: w, error: null, isFetching: !1 }, D(w);
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
+ };
1798
1809
  },
1799
1810
  dispose() {
1800
- a?.abort();
1811
+ a.forEach((c) => c()), a.clear(), o?.abort();
1801
1812
  }
1802
1813
  };
1803
1814
  };
1804
1815
  }
1805
- function Yt({
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({
1806
1823
  ctx: e,
1807
1824
  helpers: t
1808
1825
  }) {
1809
- return () => {
1810
- const n = L({
1826
+ return (n = {}) => {
1827
+ const r = V({
1811
1828
  data: null,
1812
1829
  error: null,
1813
1830
  isFetching: !1
1814
1831
  });
1815
- 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
+ }
1816
1853
  return {
1817
- state: n,
1818
- async prepare(a) {
1819
- const {
1820
- query: i,
1821
- filters: s,
1822
- tuning: l,
1823
- signal: c,
1824
- dynamicLinking: g,
1825
- params: d,
1826
- paramDefinitions: p,
1827
- transformBody: u
1828
- } = a, f = t.transformFilters(s), 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(
1829
1873
  {
1830
- query: i,
1831
- filter_group: f,
1832
- tuning: l,
1833
- dynamicLinking: g,
1834
- 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 })
1835
1879
  },
1836
- c
1880
+ d.signal
1837
1881
  );
1838
- 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 }));
1839
1883
  },
1840
- async execute(a) {
1841
- const {
1842
- query: i,
1843
- searchId: s,
1844
- page: l = Y,
1845
- limit: c = Z,
1846
- filters: g,
1847
- tuning: d,
1848
- signal: p,
1849
- dynamicLinking: u,
1850
- params: f,
1851
- paramDefinitions: h,
1852
- transformBody: y
1853
- } = a, E = t.transformFilters(g), M = K({ params: f, paramDefinitions: h, transformBody: y });
1854
- o?.abort(), o = oe(p), n.value = { ...n.value, isFetching: !0, error: null };
1855
- let A = s ?? r;
1856
- if (r = void 0, !A) {
1857
- const I = await e.layers.prepareSearch(
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(
1858
1908
  {
1859
- query: i,
1860
- filter_group: E,
1861
- tuning: d,
1862
- dynamicLinking: u,
1863
- transformBody: M
1909
+ query: l,
1910
+ filter_group: v,
1911
+ tuning: b,
1912
+ dynamicLinking: A,
1913
+ transformBody: E
1864
1914
  },
1865
- o.signal
1915
+ I.signal
1866
1916
  );
1867
- if (I.error)
1868
- return n.value = { ...n.value, isFetching: !1, error: I.error }, v(I.error);
1869
- A = I.data.search_id;
1917
+ if ($.error)
1918
+ return r.value = { ...r.value, isFetching: !1, error: $.error }, y($.error);
1919
+ M = $.data.search_id;
1870
1920
  }
1871
- const R = Ye;
1872
- let b = await e.layers.search(
1873
- {
1874
- query: i,
1875
- search_id: A,
1876
- pagination: { page: l, limit: c },
1877
- filter_group: E,
1878
- tuning: d,
1879
- dynamicLinking: u,
1880
- transformBody: M
1881
- },
1882
- o.signal
1883
- );
1884
- for (let I = 0; I < R && b.error; I++) {
1885
- const C = b.error;
1886
- if (C._tag !== "ApiError" || C.status !== 425) break;
1887
- let V = Ze;
1888
- try {
1889
- const X = JSON.parse(C.message);
1890
- X.retry_after_ms && (V = X.retry_after_ms);
1891
- } catch {
1892
- }
1893
- await new Promise((X) => setTimeout(X, V)), b = await e.layers.search(
1921
+ const R = await an(
1922
+ () => e.layers.search(
1894
1923
  {
1895
- query: i,
1896
- search_id: A,
1897
- pagination: { page: l, limit: c },
1898
- filter_group: E,
1899
- tuning: d,
1900
- dynamicLinking: u,
1901
- 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
1902
1931
  },
1903
- o.signal
1904
- );
1905
- }
1906
- if (b.error)
1907
- return n.value = { data: n.value.data, error: b.error, isFetching: !1 }, v(b.error);
1908
- const { results: m, _meta: _ } = b.data, F = t.extractGids(m), { cached: S } = e.store.products.getMany(F), P = new Map(S.map((I) => [I.gid, I])), O = t.buildProducts(m, P, _), w = re({
1909
- products: O,
1910
- raw: b.data,
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,
1911
1941
  extender: e.config.extendSearch,
1912
1942
  currencyCode: e.mergeConfig.currencyCode,
1913
1943
  formatPrice: e.mergeConfig.formatPrice
1914
1944
  });
1915
- e.config.includeMeta && b.data._meta && (w._meta = b.data._meta), e.store.products.set(t.filterCacheableProducts(O));
1916
- const T = Nt(i, { page: l, limit: c, filters: g });
1917
- return T && e.store.queries.set(T, w), n.value = { data: w, error: null, isFetching: !1 }, D(w);
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
+ };
1918
1954
  },
1919
1955
  dispose() {
1920
- o?.abort();
1956
+ c.forEach((d) => d()), c.clear(), i?.abort();
1921
1957
  }
1922
1958
  };
1923
1959
  };
1924
1960
  }
1925
- function Zt({
1961
+ function cn({
1926
1962
  ctx: e,
1927
1963
  helpers: t
1928
1964
  }) {
1929
- return ({ blockId: n, anchorId: o, anchorHandle: r }) => {
1930
- const a = L({
1965
+ return ({ blockId: n, anchorId: r }) => {
1966
+ const s = V({
1931
1967
  data: null,
1932
1968
  error: null,
1933
1969
  isFetching: !1
1934
1970
  });
1935
- let i = null;
1971
+ let o = null;
1972
+ const i = /* @__PURE__ */ new Set();
1936
1973
  return {
1937
- state: a,
1938
- async execute(s = {}) {
1974
+ state: s,
1975
+ async execute(a = {}) {
1939
1976
  const {
1940
- page: l = Y,
1941
- limit: c = Z,
1977
+ page: c = ee,
1978
+ limit: u = te,
1942
1979
  filters: g,
1943
1980
  signal: d,
1944
- discountEntitlements: p,
1945
- context: u,
1981
+ discountEntitlements: m,
1982
+ context: l,
1946
1983
  dynamicLinking: f,
1947
- params: h,
1948
- paramDefinitions: y,
1949
- transformBody: E
1950
- } = s;
1951
- i?.abort(), i = oe(d);
1952
- const M = a.value.data;
1953
- a.value = { data: M, error: null, isFetching: !0 };
1954
- const { data: A, error: R } = await e.layers.blocks(
1984
+ params: _,
1985
+ paramDefinitions: h,
1986
+ transformBody: b
1987
+ } = a;
1988
+ o?.abort(), o = z(d);
1989
+ const A = s.value.data;
1990
+ s.value = { data: A, error: null, isFetching: !0 };
1991
+ const { data: T, error: w } = await e.layers.blocks(
1955
1992
  {
1956
1993
  blockId: n,
1957
- anchor_id: o,
1958
- anchor_handle: r,
1959
- pagination: { page: l, limit: c },
1994
+ anchor_id: r,
1995
+ pagination: { page: c, limit: u },
1960
1996
  filter_group: t.transformFilters(g),
1961
- discountEntitlements: p,
1962
- context: u,
1997
+ discountEntitlements: m,
1998
+ context: l,
1963
1999
  dynamicLinking: f,
1964
- transformBody: K({ params: h, paramDefinitions: y, transformBody: E })
2000
+ transformBody: X({ params: _, paramDefinitions: h, transformBody: b })
1965
2001
  },
1966
- i.signal
2002
+ o.signal
1967
2003
  );
1968
- if (R)
1969
- return a.value = { data: M, error: R, isFetching: !1 }, v(R);
1970
- const { results: b, _meta: m } = A, _ = t.extractGids(b), { cached: F } = e.store.products.getMany(_), S = new Map(F.map((T) => [T.gid, T])), P = t.buildProducts(b, S, m), O = re({
1971
- products: P,
1972
- raw: A,
2004
+ if (w)
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,
2008
+ raw: T,
1973
2009
  extender: e.config.extendBlock,
1974
2010
  currencyCode: e.mergeConfig.currencyCode,
1975
2011
  formatPrice: e.mergeConfig.formatPrice
1976
2012
  });
1977
- e.config.includeMeta && A._meta && (O._meta = A._meta), A.block && (O.block = A.block);
1978
- const w = qt(n, { anchorId: o, anchorHandle: r, page: l, limit: c, filters: g });
1979
- return w && e.store.queries.set(w, O), e.store.products.set(t.filterCacheableProducts(P)), a.value = { data: O, error: null, isFetching: !1 }, D(O);
2013
+ e.config.includeMeta && T._meta && (R._meta = T._meta), T.block && (R.block = T.block);
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
+ };
1980
2022
  },
1981
2023
  dispose() {
1982
- i?.abort();
2024
+ i.forEach((a) => a()), i.clear(), o?.abort();
1983
2025
  }
1984
2026
  };
1985
2027
  };
1986
2028
  }
1987
- function en(e, t) {
2029
+ function ln(e, t) {
1988
2030
  let n = null;
1989
2031
  return {
1990
- call(...o) {
2032
+ call(...r) {
1991
2033
  n && clearTimeout(n), n = setTimeout(() => {
1992
- n = null, e(...o);
2034
+ n = null, e(...r);
1993
2035
  }, t);
1994
2036
  },
1995
2037
  cancel() {
@@ -1997,127 +2039,138 @@ function en(e, t) {
1997
2039
  }
1998
2040
  };
1999
2041
  }
2000
- function tn({
2042
+ function un({
2001
2043
  ctx: e
2002
2044
  }) {
2003
2045
  return (t = {}) => {
2004
- const { debounceMs: n = et, signal: o } = t, r = L({
2046
+ const { debounceMs: n = at, signal: r } = t, s = V({
2005
2047
  data: null,
2006
2048
  error: null,
2007
2049
  isFetching: !1
2008
2050
  });
2009
- let a = null, i = 0;
2010
- const s = /* @__PURE__ */ new Map();
2011
- function l() {
2012
- c.cancel(), a?.abort(), s.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();
2013
2055
  }
2014
- o?.addEventListener("abort", l, { once: !0 });
2015
- const c = en(async (g) => {
2016
- if (!g.trim()) {
2017
- r.value = { data: null, error: null, isFetching: !1 };
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 };
2018
2060
  return;
2019
2061
  }
2020
- const d = g.trim().toLowerCase(), p = s.get(d);
2021
- if (p) {
2022
- 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 };
2023
2065
  return;
2024
2066
  }
2025
- a?.abort(), a = oe(o);
2026
- const u = ++i;
2027
- r.value = { ...r.value, isFetching: !0 };
2028
- const f = await e.layers.predictiveSearch(g.trim(), a.signal);
2029
- u === i && (f.error ? f.error._tag !== "NetworkError" || f.error.code !== "ABORTED" ? r.value = { data: null, error: f.error, isFetching: !1 } : r.value = { ...r.value, isFetching: !1 } : (s.set(d, f.data), s.size > tt && s.delete(s.keys().next().value), r.value = { data: f.data, error: null, isFetching: !1 }));
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 }));
2030
2072
  }, n);
2031
- 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
+ };
2032
2085
  };
2033
2086
  }
2034
- function nn({
2087
+ function dn({
2035
2088
  ctx: e
2036
2089
  }) {
2037
2090
  return (t) => {
2038
2091
  const {
2039
2092
  ids: n,
2040
- meta: o,
2041
- collectionMetafields: r = e.config.collectionMetafields,
2042
- pageMetafields: a = e.config.pageMetafields,
2093
+ meta: r,
2094
+ collectionMetafields: s = e.config.collectionMetafields,
2095
+ pageMetafields: o = e.config.pageMetafields,
2043
2096
  signal: i
2044
- } = t, s = L({
2097
+ } = t, a = V({
2045
2098
  data: null,
2046
2099
  error: null,
2047
2100
  isFetching: !1
2048
2101
  });
2049
2102
  if (n.length === 0)
2050
- return s.value = { data: { products: [] }, error: null, isFetching: !1 }, s;
2051
- const l = n, { cached: c } = e.store.products.getMany(l), g = new Map(c.map((p) => [p.gid, p])), d = l.map((p) => g.get(p)).filter((p) => p != null);
2052
- return !o || !e.storefrontEnabled ? (s.value = { data: { products: d }, error: null, isFetching: !1 }, s) : (s.value = { data: null, error: null, isFetching: !0 }, (async () => {
2053
- let p, u;
2054
- if (o.collection) {
2055
- const h = await e.storefront.getCollection({
2056
- handle: o.collection,
2057
- collectionMetafields: r,
2058
- includeFilters: o.includeFilters,
2103
+ return a.value = { data: { products: [] }, error: null, isFetching: !1 }, a;
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,
2059
2112
  signal: i
2060
2113
  });
2061
- if (h.error) {
2062
- s.value = { data: null, error: h.error, isFetching: !1 };
2114
+ if (_.error) {
2115
+ a.value = { data: null, error: _.error, isFetching: !1 };
2063
2116
  return;
2064
2117
  }
2065
- p = h.data;
2118
+ m = _.data;
2066
2119
  }
2067
- if (o.page) {
2068
- const h = await e.storefront.getPage({
2069
- handle: o.page,
2070
- pageMetafields: a,
2120
+ if (r.page) {
2121
+ const _ = await e.storefront.getPage({
2122
+ handle: r.page,
2123
+ pageMetafields: o,
2071
2124
  signal: i
2072
2125
  });
2073
- if (h.error) {
2074
- s.value = { data: null, error: h.error, isFetching: !1 };
2126
+ if (_.error) {
2127
+ a.value = { data: null, error: _.error, isFetching: !1 };
2075
2128
  return;
2076
2129
  }
2077
- u = h.data;
2130
+ l = _.data;
2078
2131
  }
2079
2132
  const f = { products: d };
2080
- p && (f.collection = p), u && (f.page = u), s.value = { data: f, error: null, isFetching: !1 };
2081
- })(), s);
2133
+ m && (f.collection = m), l && (f.page = l), a.value = { data: f, error: null, isFetching: !1 };
2134
+ })(), a);
2082
2135
  };
2083
2136
  }
2084
- function rn({ ctx: e }) {
2137
+ function fn({ ctx: e }) {
2085
2138
  return ({
2086
2139
  image: t,
2087
2140
  signal: n
2088
2141
  }) => {
2089
- const o = L({
2142
+ const r = V({
2090
2143
  data: null,
2091
2144
  error: null,
2092
2145
  isFetching: !0
2093
2146
  });
2094
2147
  return (async () => {
2095
- const r = await e.layers.uploadImage(t, n);
2096
- if (r.error) {
2097
- 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 };
2098
2151
  return;
2099
2152
  }
2100
- o.value = { data: { imageId: r.data.imageId }, error: null, isFetching: !1 };
2101
- })(), o;
2153
+ r.value = { data: { imageId: s.data.imageId }, error: null, isFetching: !1 };
2154
+ })(), r;
2102
2155
  };
2103
2156
  }
2104
- function on({
2157
+ function gn({
2105
2158
  ctx: e,
2106
2159
  helpers: t
2107
2160
  }) {
2108
2161
  return (n) => {
2109
2162
  const {
2110
- imageId: o,
2111
- page: r = Y,
2112
- limit: a = Z,
2163
+ imageId: r,
2164
+ page: s = ee,
2165
+ limit: o = te,
2113
2166
  filters: i,
2114
- tuning: s,
2115
- signal: l,
2116
- dynamicLinking: c,
2167
+ tuning: a,
2168
+ signal: c,
2169
+ dynamicLinking: u,
2117
2170
  params: g,
2118
2171
  paramDefinitions: d,
2119
- transformBody: p
2120
- } = n, u = L({
2172
+ transformBody: m
2173
+ } = n, l = V({
2121
2174
  data: null,
2122
2175
  error: null,
2123
2176
  isFetching: !0
@@ -2125,32 +2178,32 @@ function on({
2125
2178
  return (async () => {
2126
2179
  const f = await e.layers.imageSearch(
2127
2180
  {
2128
- image_id: o,
2129
- pagination: { page: r, limit: a },
2181
+ image_id: r,
2182
+ pagination: { page: s, limit: o },
2130
2183
  filter_group: t.transformFilters(i),
2131
- tuning: s,
2132
- dynamicLinking: c,
2133
- transformBody: K({ params: g, paramDefinitions: d, transformBody: p })
2184
+ tuning: a,
2185
+ dynamicLinking: u,
2186
+ transformBody: X({ params: g, paramDefinitions: d, transformBody: m })
2134
2187
  },
2135
- l
2188
+ c
2136
2189
  );
2137
2190
  if (f.error) {
2138
- u.value = { data: null, error: f.error, isFetching: !1 };
2191
+ l.value = { data: null, error: f.error, isFetching: !1 };
2139
2192
  return;
2140
2193
  }
2141
- const { results: h, _meta: y } = f.data, E = t.extractGids(h), { cached: M } = e.store.products.getMany(E), A = new Map(M.map((m) => [m.gid, m])), R = t.buildProducts(h, A, y), b = re({
2142
- products: R,
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({
2195
+ products: w,
2143
2196
  raw: f.data,
2144
2197
  extender: e.config.extendSearch,
2145
2198
  currencyCode: e.mergeConfig.currencyCode,
2146
2199
  formatPrice: e.mergeConfig.formatPrice
2147
2200
  });
2148
- e.store.products.set(t.filterCacheableProducts(R)), u.value = { data: b, error: null, isFetching: !1 };
2149
- })(), u;
2201
+ e.store.products.set(t.filterCacheableProducts(w)), l.value = { data: P, error: null, isFetching: !1 };
2202
+ })(), l;
2150
2203
  };
2151
2204
  }
2152
- function Pn(e) {
2153
- const t = pt({
2205
+ function kn(e) {
2206
+ const t = It({
2154
2207
  layersPublicToken: e.layersPublicToken,
2155
2208
  layersBaseUrl: e.layersBaseUrl,
2156
2209
  sorts: e.sorts,
@@ -2158,12 +2211,12 @@ function Pn(e) {
2158
2211
  attributes: e.attributes,
2159
2212
  fetch: e.fetch
2160
2213
  });
2161
- if (t.error) return v(t.error);
2214
+ if (t.error) return y(t.error);
2162
2215
  const n = t.data;
2163
- let o, r = !1;
2216
+ let r, s = !1;
2164
2217
  if (e.enableStorefront) {
2165
2218
  if (!e.shop || !e.storefrontPublicToken)
2166
- return v(
2219
+ return y(
2167
2220
  U({
2168
2221
  code: "MISSING_CONFIG",
2169
2222
  message: "shop and storefrontPublicToken are required when enableStorefront is true",
@@ -2171,239 +2224,240 @@ function Pn(e) {
2171
2224
  expected: "non-empty string"
2172
2225
  })
2173
2226
  );
2174
- const c = Ft({
2227
+ const u = wt({
2175
2228
  shop: e.shop,
2176
2229
  storefrontPublicToken: e.storefrontPublicToken,
2177
2230
  storefrontApiVersion: e.storefrontApiVersion,
2178
2231
  fetch: e.fetch
2179
2232
  });
2180
- if (c.error) return v(c.error);
2181
- o = c.data, r = !0;
2233
+ if (u.error) return y(u.error);
2234
+ r = u.data, s = !0;
2182
2235
  }
2183
- const a = Ot({
2236
+ const o = $t({
2184
2237
  maxProducts: e.cacheMaxProducts,
2185
2238
  maxQueries: e.cacheMaxEntries,
2186
2239
  ttl: e.cacheTtl,
2187
2240
  storageAdapter: e.storageAdapter
2188
2241
  });
2189
- if (e.restoreFromStorage !== !1 && a.restore(), e.initialData) {
2190
- const { products: c, queries: g, collections: d } = e.initialData;
2191
- if (c?.length && a.products.set(c), g)
2192
- for (const [p, u] of Object.entries(g))
2193
- a.queries.set(p, u);
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);
2194
2247
  if (d)
2195
- for (const [p, u] of Object.entries(d))
2196
- a.collections.set(p, u);
2248
+ for (const [m, l] of Object.entries(d))
2249
+ o.collections.set(m, l);
2197
2250
  }
2198
2251
  const i = {
2199
2252
  config: e,
2200
2253
  layers: n,
2201
- storefront: o,
2202
- storefrontEnabled: r,
2203
- store: a,
2254
+ storefront: r,
2255
+ storefrontEnabled: s,
2256
+ store: o,
2204
2257
  mergeConfig: {
2205
2258
  currencyCode: e.currencyCode,
2206
2259
  formatPrice: e.formatPrice,
2207
2260
  swatches: e.swatches
2208
2261
  }
2209
- }, s = Wt({ ctx: i }), l = {
2262
+ }, a = rn({ ctx: i }), c = {
2210
2263
  config: e,
2211
- store: a,
2212
- collection: Jt({ ctx: i, helpers: s }),
2213
- search: Yt({ ctx: i, helpers: s }),
2214
- blocks: Zt({ ctx: i, helpers: s }),
2215
- autocomplete: tn({ ctx: i }),
2216
- storefront: nn({ ctx: i }),
2217
- uploadImage: rn({ ctx: i }),
2218
- imageSearch: on({ ctx: i, helpers: s })
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 })
2219
2272
  };
2220
- return Kt(l), D(l);
2273
+ return en(c), N(c);
2221
2274
  }
2222
- function An({
2275
+ function Dn({
2223
2276
  product: e,
2224
2277
  selectedOptions: t = [],
2225
2278
  breakoutOptions: n
2226
2279
  }) {
2227
- const o = "_base" in e ? e._base : e, r = n ?? o.breakoutOptions ?? [], a = L(t), i = L(r), s = N(() => an(o.variants, i.value)), l = N(() => new Set(i.value.map((m) => m.name))), c = N(() => {
2228
- const m = a.value.filter((_) => !l.value.has(_.name));
2229
- return [...i.value, ...m];
2230
- }), g = N(
2231
- () => W(s.value, c.value)
2232
- ), d = N(
2233
- () => sn(s.value, o.options, l.value)
2234
- ), p = N(() => [...new Set(d.value.map((m) => m.name))]), u = N(() => d.value.find((_) => _.swatch)?.name ?? null), f = N(() => {
2235
- const m = u.value;
2236
- if (!m) return /* @__PURE__ */ new Map();
2237
- const _ = /* @__PURE__ */ new Map();
2238
- for (const F of s.value) {
2239
- const S = F.selectedOptions.find((P) => P.name === m);
2240
- S && _.set(F.numericId, S.value);
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);
2241
2294
  }
2242
- return _;
2243
- }), h = N(() => {
2244
- const m = u.value;
2245
- return m ? d.value.filter((_) => _.name === m).map((_) => _.value) : [];
2246
- }), y = N(() => {
2247
- const m = u.value, _ = h.value, F = f.value;
2248
- if (!m || _.length === 0)
2249
- return [...o.images].sort((T, I) => T.position - I.position);
2250
- const S = g.value ? F.get(g.value.numericId) : null, P = /* @__PURE__ */ new Map(), O = [];
2251
- for (const T of o.images) {
2252
- if (T.variantIds.length === 0) {
2253
- O.push(T);
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);
2254
2307
  continue;
2255
2308
  }
2256
- let I = null;
2257
- for (const C of T.variantIds) {
2258
- const V = F.get(C);
2259
- if (V) {
2260
- 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;
2261
2314
  break;
2262
2315
  }
2263
2316
  }
2264
- if (I) {
2265
- const C = P.get(I) ?? [];
2266
- C.push(T), P.set(I, C);
2317
+ if (F) {
2318
+ const O = M.get(F) ?? [];
2319
+ O.push(S), M.set(F, O);
2267
2320
  } else
2268
- O.push(T);
2321
+ R.push(S);
2269
2322
  }
2270
- for (const T of P.values())
2271
- T.sort((I, C) => I.position - C.position);
2272
- O.sort((T, I) => T.position - I.position);
2273
- const w = [];
2274
- S && P.has(S) && w.push(...P.get(S));
2275
- for (const T of _)
2276
- T !== S && P.has(T) && w.push(...P.get(T));
2277
- return w.push(...O), w;
2278
- }), E = N(() => {
2279
- const m = g.value;
2280
- if (!m?.image) return y.value;
2281
- if (!u.value) return m.image ? [m.image] : y.value;
2282
- const F = f.value.get(m.numericId);
2283
- return F ? y.value.filter((S) => S.variantIds.length === 0 ? !1 : S.variantIds.some(
2284
- (P) => f.value.get(P) === F
2285
- )) : m.image ? [m.image] : y.value;
2286
- }), M = N(() => y.value), A = N(() => {
2287
- const m = new Set(c.value.map((_) => _.name));
2288
- return p.value.every((_) => m.has(_));
2289
- }), R = N(() => {
2290
- const m = g.value;
2291
- if (!m?.image) return 0;
2292
- const _ = E.value.findIndex((F) => F.url === m.image?.url);
2293
- return Math.max(0, _);
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);
2294
2347
  });
2295
- function b(m) {
2296
- if (!m.image) return 0;
2297
- const _ = y.value.findIndex((F) => F.url === m.image?.url);
2298
- return Math.max(0, _);
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);
2299
2352
  }
2300
2353
  return {
2301
2354
  product: e,
2302
2355
  // Reactive state
2303
- variants: s,
2356
+ variants: a,
2304
2357
  selectedVariant: g,
2305
- selectedOptions: c,
2358
+ selectedOptions: u,
2306
2359
  options: d,
2307
- optionNames: p,
2308
- swatchOptionName: u,
2309
- images: E,
2310
- allImages: M,
2311
- carouselIndex: R,
2312
- isSelectionComplete: A,
2360
+ optionNames: m,
2361
+ swatchOptionName: l,
2362
+ images: b,
2363
+ allImages: A,
2364
+ carouselIndex: w,
2365
+ isSelectionComplete: T,
2313
2366
  // Actions
2314
- selectOption(m, _) {
2315
- const S = a.value.filter((P) => P.name !== m).concat({ name: m, value: _ });
2316
- a.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;
2317
2370
  },
2318
- setSelectedOptions(m) {
2319
- const _ = new Set(m.map((S) => S.name)), F = a.value.filter((S) => !_.has(S.name));
2320
- a.value = [...F, ...m];
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];
2321
2374
  },
2322
- setBreakoutOptions(m) {
2323
- i.value = m;
2375
+ setBreakoutOptions(p) {
2376
+ i.value = p;
2324
2377
  },
2325
2378
  // Queries
2326
- getOptionValues(m) {
2327
- return cn(s.value, m);
2379
+ getOptionValues(p) {
2380
+ return hn(a.value, p);
2328
2381
  },
2329
- getSwatches(m) {
2330
- 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);
2331
2384
  },
2332
- getVariantByOptions(m) {
2333
- const _ = [...i.value, ...m];
2334
- return W(s.value, _);
2385
+ getVariantByOptions(p) {
2386
+ const v = [...i.value, ...p];
2387
+ return Y(a.value, v);
2335
2388
  },
2336
- getCarouselIndexForVariant: b,
2337
- isOptionAvailable(m, _) {
2338
- const F = a.value.filter((O) => O.name !== m).concat({ name: m, value: _ }), S = [...i.value, ...F];
2339
- return W(s.value, S)?.availableForSale ?? !1;
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;
2340
2393
  },
2341
- isVariantAvailable(m) {
2342
- return m.availableForSale;
2394
+ isVariantAvailable(p) {
2395
+ return p.availableForSale;
2343
2396
  },
2344
- getOptionAvailabilityStatus(m, _) {
2345
- const F = a.value.filter((O) => O.name !== m).concat({ name: m, value: _ }), S = [...i.value, ...F], P = W(s.value, S);
2346
- return P ? P.availableForSale ? "available" : P.inventoryPolicy === "CONTINUE" ? "backorderable" : "sold-out" : "unavailable";
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";
2347
2400
  },
2348
2401
  dispose() {
2349
2402
  }
2350
2403
  };
2351
2404
  }
2352
- function an(e, t) {
2405
+ function mn(e, t) {
2353
2406
  return t.length === 0 ? e : e.filter(
2354
2407
  (n) => t.every(
2355
- (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)
2356
2409
  )
2357
2410
  );
2358
2411
  }
2359
- function W(e, t) {
2412
+ function Y(e, t) {
2360
2413
  return t.length === 0 ? e[0] ?? null : e.find(
2361
2414
  (n) => t.every(
2362
- (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)
2363
2416
  )
2364
2417
  ) ?? null;
2365
2418
  }
2366
- function sn(e, t, n) {
2367
- const o = /* @__PURE__ */ new Set();
2368
- for (const r of e)
2369
- for (const a of r.selectedOptions)
2370
- n.has(a.name) || o.add(`${a.name}:${a.value}`);
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}`);
2371
2424
  return t.filter(
2372
- (r) => !n.has(r.name) && o.has(`${r.name}:${r.value}`)
2425
+ (s) => !n.has(s.name) && r.has(`${s.name}:${s.value}`)
2373
2426
  );
2374
2427
  }
2375
- function cn(e, t) {
2428
+ function hn(e, t) {
2376
2429
  const n = /* @__PURE__ */ new Set();
2377
- for (const o of e) {
2378
- const r = o.selectedOptions.find((a) => a.name === t);
2379
- r && n.add(r.value);
2430
+ for (const r of e) {
2431
+ const s = r.selectedOptions.find((o) => o.name === t);
2432
+ s && n.add(s.value);
2380
2433
  }
2381
2434
  return [...n];
2382
2435
  }
2383
2436
  export {
2384
- $t as and,
2385
- wn as batch,
2386
- On as computed,
2387
- An as createProductCard,
2388
- Pn as createSdk,
2389
- Cn as effect,
2390
- gn as eq,
2391
- En as exists,
2392
- Sn as filter,
2393
- zt as getSdk,
2394
- _n as gt,
2395
- vn as gte,
2396
- pn as inValues,
2397
- Mn as isInitialized,
2398
- dn as isRetryable,
2399
- un as isSdkError,
2400
- fn as jsonFileAdapter,
2401
- Pt as localStorageAdapter,
2402
- yn as lt,
2403
- In as lte,
2404
- mn as notEq,
2405
- bn as notExists,
2406
- hn as notIn,
2407
- Fn as or,
2408
- kn as signal
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
2409
2463
  };