@commerce-blocks/sdk 1.0.0 → 1.2.0

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