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