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