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