@behio/storefront-sdk 1.7.0 → 1.9.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/dist/{chunk-TJ4TZ5FI.js → chunk-CY6D2YEI.js} +27 -0
- package/dist/{chunk-TOSF3K7J.mjs → chunk-XMKY4RI5.mjs} +27 -0
- package/dist/{client-BSDdOEcK.d.mts → client-C635vSzU.d.mts} +33 -0
- package/dist/{client-BSDdOEcK.d.ts → client-C635vSzU.d.ts} +33 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/index.mjs +1 -1
- package/dist/next.d.mts +1 -1
- package/dist/next.d.ts +1 -1
- package/dist/next.js +2 -2
- package/dist/next.mjs +1 -1
- package/dist/react.d.mts +88 -1
- package/dist/react.d.ts +88 -1
- package/dist/react.js +185 -89
- package/dist/react.mjs +161 -66
- package/package.json +2 -2
package/dist/react.js
CHANGED
|
@@ -99,6 +99,7 @@ __export(react_exports, {
|
|
|
99
99
|
useSubmitReturn: () => useSubmitReturn,
|
|
100
100
|
useSubmitReview: () => useSubmitReview,
|
|
101
101
|
useSubscriptions: () => useSubscriptions,
|
|
102
|
+
useVisitorMessages: () => useVisitorMessages,
|
|
102
103
|
useWishlist: () => useWishlist
|
|
103
104
|
});
|
|
104
105
|
module.exports = __toCommonJS(react_exports);
|
|
@@ -188,6 +189,11 @@ function toSdkError(err) {
|
|
|
188
189
|
}
|
|
189
190
|
|
|
190
191
|
// src/client.ts
|
|
192
|
+
function isAvailabilityFailure(err) {
|
|
193
|
+
if (err instanceof BehioNetworkError) return true;
|
|
194
|
+
if (err instanceof BehioApiError) return err.isRetryable;
|
|
195
|
+
return false;
|
|
196
|
+
}
|
|
191
197
|
var BehioStorefront = class {
|
|
192
198
|
constructor(config) {
|
|
193
199
|
/** Consent-gated persistent visitor id — set by the analytics tracker. */
|
|
@@ -216,6 +222,7 @@ var BehioStorefront = class {
|
|
|
216
222
|
this.retries = config.retries ?? 1;
|
|
217
223
|
this.retryDelay = config.retryDelay ?? 1e3;
|
|
218
224
|
this.visitorIp = config.visitorIp;
|
|
225
|
+
this.throwOnAvailabilityError = config.throwOnAvailabilityError ?? false;
|
|
219
226
|
this.catalog = new CatalogModule(this);
|
|
220
227
|
this.auth = new AuthModule(this);
|
|
221
228
|
this.cart = new CartModule(this);
|
|
@@ -291,6 +298,21 @@ var BehioStorefront = class {
|
|
|
291
298
|
body: input
|
|
292
299
|
});
|
|
293
300
|
}
|
|
301
|
+
/**
|
|
302
|
+
* Visitor messages from merchant automations (storefront.event action).
|
|
303
|
+
* Consent-gated visitor id; each message carries a merchant-defined `name`
|
|
304
|
+
* and free-form `payload` the template reacts to (modal, banner, ...).
|
|
305
|
+
* Messages stay listed until acknowledged via `ackVisitorMessage`.
|
|
306
|
+
*/
|
|
307
|
+
async getVisitorMessages(visitorId) {
|
|
308
|
+
return this.request("GET", "/messages", { query: { visitorId } });
|
|
309
|
+
}
|
|
310
|
+
/** Acknowledge a visitor message so it is not delivered again. */
|
|
311
|
+
async ackVisitorMessage(messageId, visitorId) {
|
|
312
|
+
return this.request("POST", `/messages/${messageId}/ack`, {
|
|
313
|
+
query: { visitorId }
|
|
314
|
+
});
|
|
315
|
+
}
|
|
294
316
|
/** Get basic shop info */
|
|
295
317
|
async getShopInfo() {
|
|
296
318
|
return this.request("GET", "/shop");
|
|
@@ -446,6 +468,9 @@ var BehioStorefront = class {
|
|
|
446
468
|
const data = await this.rawRequest(method, path, options);
|
|
447
469
|
return ok(data);
|
|
448
470
|
} catch (err) {
|
|
471
|
+
if (this.throwOnAvailabilityError && isAvailabilityFailure(err)) {
|
|
472
|
+
throw err;
|
|
473
|
+
}
|
|
449
474
|
return { data: null, error: toSdkError(err) };
|
|
450
475
|
}
|
|
451
476
|
}
|
|
@@ -473,6 +498,9 @@ var BehioStorefront = class {
|
|
|
473
498
|
}
|
|
474
499
|
return ok(await res.blob());
|
|
475
500
|
} catch (err) {
|
|
501
|
+
if (this.throwOnAvailabilityError && isAvailabilityFailure(err)) {
|
|
502
|
+
throw err;
|
|
503
|
+
}
|
|
476
504
|
return { data: null, error: toSdkError(err) };
|
|
477
505
|
}
|
|
478
506
|
}
|
|
@@ -3224,11 +3252,78 @@ function usePersonalOffers(options) {
|
|
|
3224
3252
|
};
|
|
3225
3253
|
}
|
|
3226
3254
|
|
|
3227
|
-
// src/react/hooks/use-
|
|
3255
|
+
// src/react/hooks/use-visitor-messages.ts
|
|
3228
3256
|
var import_react11 = require("react");
|
|
3257
|
+
var import_react_query29 = require("@tanstack/react-query");
|
|
3258
|
+
function useVisitorMessages(options) {
|
|
3259
|
+
const { client } = useBehio();
|
|
3260
|
+
const queryClient = (0, import_react_query29.useQueryClient)();
|
|
3261
|
+
const [polledVid, setPolledVid] = (0, import_react11.useState)(null);
|
|
3262
|
+
const seenRef = (0, import_react11.useRef)(/* @__PURE__ */ new Set());
|
|
3263
|
+
const explicitVid = options?.visitorId;
|
|
3264
|
+
(0, import_react11.useEffect)(() => {
|
|
3265
|
+
if (explicitVid) return;
|
|
3266
|
+
const read = () => {
|
|
3267
|
+
const vid = client.getAnalyticsVisitorId();
|
|
3268
|
+
if (vid) setPolledVid(vid);
|
|
3269
|
+
return vid;
|
|
3270
|
+
};
|
|
3271
|
+
if (read()) return;
|
|
3272
|
+
const timer = setInterval(() => {
|
|
3273
|
+
if (read()) clearInterval(timer);
|
|
3274
|
+
}, 3e3);
|
|
3275
|
+
return () => clearInterval(timer);
|
|
3276
|
+
}, [client, explicitVid]);
|
|
3277
|
+
const visitorId = explicitVid ?? polledVid;
|
|
3278
|
+
const pollMs = options?.pollMs ?? 3e4;
|
|
3279
|
+
const queryKey = ["behio", "visitor-messages", visitorId ?? ""];
|
|
3280
|
+
const { data, isLoading, error, refetch } = (0, import_react_query29.useQuery)({
|
|
3281
|
+
queryKey,
|
|
3282
|
+
queryFn: () => unwrap(client.getVisitorMessages(visitorId)),
|
|
3283
|
+
enabled: options?.enabled !== false && !!visitorId,
|
|
3284
|
+
refetchInterval: pollMs > 0 ? pollMs : false
|
|
3285
|
+
});
|
|
3286
|
+
const ack = (0, import_react11.useCallback)(
|
|
3287
|
+
async (messageId) => {
|
|
3288
|
+
if (!visitorId) return false;
|
|
3289
|
+
const result = await unwrap(client.ackVisitorMessage(messageId, visitorId));
|
|
3290
|
+
queryClient.setQueryData(
|
|
3291
|
+
queryKey,
|
|
3292
|
+
(prev) => prev ? { items: prev.items.filter((m) => m.id !== messageId) } : prev
|
|
3293
|
+
);
|
|
3294
|
+
return result.ok;
|
|
3295
|
+
},
|
|
3296
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3297
|
+
[client, visitorId, queryClient]
|
|
3298
|
+
);
|
|
3299
|
+
const onMessage = options?.onMessage;
|
|
3300
|
+
const dispatchDom = options?.dispatchDomEvents !== false;
|
|
3301
|
+
(0, import_react11.useEffect)(() => {
|
|
3302
|
+
for (const message of data?.items ?? []) {
|
|
3303
|
+
if (seenRef.current.has(message.id)) continue;
|
|
3304
|
+
seenRef.current.add(message.id);
|
|
3305
|
+
if (dispatchDom && typeof window !== "undefined") {
|
|
3306
|
+
window.dispatchEvent(new CustomEvent("behio:visitor-message", { detail: message }));
|
|
3307
|
+
}
|
|
3308
|
+
onMessage?.(message);
|
|
3309
|
+
}
|
|
3310
|
+
}, [data, onMessage, dispatchDom]);
|
|
3311
|
+
return {
|
|
3312
|
+
messages: data?.items ?? [],
|
|
3313
|
+
isLoading,
|
|
3314
|
+
error,
|
|
3315
|
+
refetch,
|
|
3316
|
+
/** Mark a message as shown; it will not be delivered again. */
|
|
3317
|
+
ack,
|
|
3318
|
+
visitorId
|
|
3319
|
+
};
|
|
3320
|
+
}
|
|
3321
|
+
|
|
3322
|
+
// src/react/hooks/use-analytics-events.ts
|
|
3323
|
+
var import_react12 = require("react");
|
|
3229
3324
|
function useAnalyticsEvents() {
|
|
3230
3325
|
const { client } = useBehio();
|
|
3231
|
-
const track = (0,
|
|
3326
|
+
const track = (0, import_react12.useCallback)(
|
|
3232
3327
|
(events, opts) => {
|
|
3233
3328
|
const list = Array.isArray(events) ? events : [events];
|
|
3234
3329
|
if (list.length === 0) return Promise.resolve();
|
|
@@ -3240,7 +3335,7 @@ function useAnalyticsEvents() {
|
|
|
3240
3335
|
},
|
|
3241
3336
|
[client]
|
|
3242
3337
|
);
|
|
3243
|
-
const trackEvent = (0,
|
|
3338
|
+
const trackEvent = (0, import_react12.useCallback)(
|
|
3244
3339
|
(name, props) => track({ type: "custom", name, props }),
|
|
3245
3340
|
[track]
|
|
3246
3341
|
);
|
|
@@ -3255,28 +3350,28 @@ function useAnalyticsEvents() {
|
|
|
3255
3350
|
}
|
|
3256
3351
|
|
|
3257
3352
|
// src/react/hooks/use-newsletter.ts
|
|
3258
|
-
var
|
|
3353
|
+
var import_react_query30 = require("@tanstack/react-query");
|
|
3259
3354
|
function useNewsletterSubscribe() {
|
|
3260
3355
|
const { client } = useBehio();
|
|
3261
|
-
return (0,
|
|
3356
|
+
return (0, import_react_query30.useMutation)({
|
|
3262
3357
|
mutationFn: (input) => unwrap(client.newsletter.subscribe(input))
|
|
3263
3358
|
});
|
|
3264
3359
|
}
|
|
3265
3360
|
function useNewsletterUnsubscribe() {
|
|
3266
3361
|
const { client } = useBehio();
|
|
3267
|
-
return (0,
|
|
3362
|
+
return (0, import_react_query30.useMutation)({
|
|
3268
3363
|
mutationFn: (email) => unwrap(client.newsletter.unsubscribe(email))
|
|
3269
3364
|
});
|
|
3270
3365
|
}
|
|
3271
3366
|
|
|
3272
3367
|
// src/react/hooks/use-orders.ts
|
|
3273
|
-
var
|
|
3274
|
-
var
|
|
3368
|
+
var import_react13 = require("react");
|
|
3369
|
+
var import_react_query31 = require("@tanstack/react-query");
|
|
3275
3370
|
function useOrders(options) {
|
|
3276
3371
|
const { client } = useBehio();
|
|
3277
3372
|
const { page: initialPage, limit, enabled } = options ?? {};
|
|
3278
|
-
const [page, setPage] = (0,
|
|
3279
|
-
const infinite = (0,
|
|
3373
|
+
const [page, setPage] = (0, import_react13.useState)(initialPage ?? 1);
|
|
3374
|
+
const infinite = (0, import_react_query31.useInfiniteQuery)({
|
|
3280
3375
|
queryKey: ["behio", "orders", limit, page],
|
|
3281
3376
|
queryFn: ({ pageParam }) => unwrap(client.orders.list({ limit, page: pageParam })),
|
|
3282
3377
|
initialPageParam: page,
|
|
@@ -3284,18 +3379,18 @@ function useOrders(options) {
|
|
|
3284
3379
|
getPreviousPageParam: (firstPage) => firstPage.page > 1 ? firstPage.page - 1 : void 0,
|
|
3285
3380
|
enabled: enabled !== false && !!client.getAccessToken()
|
|
3286
3381
|
});
|
|
3287
|
-
const items = (0,
|
|
3382
|
+
const items = (0, import_react13.useMemo)(
|
|
3288
3383
|
() => infinite.data?.pages.flatMap((p) => p.items) ?? [],
|
|
3289
3384
|
[infinite.data]
|
|
3290
3385
|
);
|
|
3291
3386
|
const lastPage = infinite.data?.pages[infinite.data.pages.length - 1];
|
|
3292
|
-
const loadMore = (0,
|
|
3387
|
+
const loadMore = (0, import_react13.useCallback)(() => {
|
|
3293
3388
|
if (infinite.hasNextPage && !infinite.isFetchingNextPage) {
|
|
3294
3389
|
return infinite.fetchNextPage();
|
|
3295
3390
|
}
|
|
3296
3391
|
return Promise.resolve();
|
|
3297
3392
|
}, [infinite]);
|
|
3298
|
-
const goToPage = (0,
|
|
3393
|
+
const goToPage = (0, import_react13.useCallback)((newPage) => {
|
|
3299
3394
|
setPage(newPage);
|
|
3300
3395
|
}, []);
|
|
3301
3396
|
return {
|
|
@@ -3321,28 +3416,28 @@ function useOrders(options) {
|
|
|
3321
3416
|
}
|
|
3322
3417
|
|
|
3323
3418
|
// src/react/hooks/use-order.ts
|
|
3324
|
-
var
|
|
3325
|
-
var
|
|
3419
|
+
var import_react14 = require("react");
|
|
3420
|
+
var import_react_query32 = require("@tanstack/react-query");
|
|
3326
3421
|
function useOrder(orderNumber, options) {
|
|
3327
3422
|
const { client } = useBehio();
|
|
3328
|
-
const queryClient = (0,
|
|
3423
|
+
const queryClient = (0, import_react_query32.useQueryClient)();
|
|
3329
3424
|
const {
|
|
3330
3425
|
data,
|
|
3331
3426
|
isLoading,
|
|
3332
3427
|
error
|
|
3333
|
-
} = (0,
|
|
3428
|
+
} = (0, import_react_query32.useQuery)({
|
|
3334
3429
|
queryKey: ["behio", "order", orderNumber],
|
|
3335
3430
|
queryFn: () => unwrap(client.orders.get(orderNumber)),
|
|
3336
3431
|
enabled: options?.enabled !== false && !!orderNumber && !!client.getAccessToken()
|
|
3337
3432
|
});
|
|
3338
|
-
const cancelMutation = (0,
|
|
3433
|
+
const cancelMutation = (0, import_react_query32.useMutation)({
|
|
3339
3434
|
mutationFn: () => unwrap(client.orders.cancel(orderNumber)),
|
|
3340
3435
|
onSuccess: (updated) => {
|
|
3341
3436
|
queryClient.setQueryData(["behio", "order", orderNumber], updated);
|
|
3342
3437
|
queryClient.invalidateQueries({ queryKey: ["behio", "orders"] });
|
|
3343
3438
|
}
|
|
3344
3439
|
});
|
|
3345
|
-
const cancel = (0,
|
|
3440
|
+
const cancel = (0, import_react14.useCallback)(
|
|
3346
3441
|
() => cancelMutation.mutateAsync(),
|
|
3347
3442
|
[cancelMutation]
|
|
3348
3443
|
);
|
|
@@ -3356,22 +3451,22 @@ function useOrder(orderNumber, options) {
|
|
|
3356
3451
|
}
|
|
3357
3452
|
|
|
3358
3453
|
// src/react/hooks/use-order-access.ts
|
|
3359
|
-
var
|
|
3360
|
-
var
|
|
3454
|
+
var import_react15 = require("react");
|
|
3455
|
+
var import_react_query33 = require("@tanstack/react-query");
|
|
3361
3456
|
function useOrderAccess() {
|
|
3362
3457
|
const { client } = useBehio();
|
|
3363
|
-
const [orderNumber, setOrderNumber] = (0,
|
|
3364
|
-
const [email, setEmail] = (0,
|
|
3365
|
-
const [order, setOrder] = (0,
|
|
3366
|
-
const [accessToken, setAccessToken] = (0,
|
|
3367
|
-
const requestMutation = (0,
|
|
3458
|
+
const [orderNumber, setOrderNumber] = (0, import_react15.useState)(null);
|
|
3459
|
+
const [email, setEmail] = (0, import_react15.useState)(null);
|
|
3460
|
+
const [order, setOrder] = (0, import_react15.useState)(null);
|
|
3461
|
+
const [accessToken, setAccessToken] = (0, import_react15.useState)(null);
|
|
3462
|
+
const requestMutation = (0, import_react_query33.useMutation)({
|
|
3368
3463
|
mutationFn: (input) => unwrap(client.orders.requestAccessCode(input.orderNumber, input.email)),
|
|
3369
3464
|
onSuccess: (_data, input) => {
|
|
3370
3465
|
setOrderNumber(input.orderNumber);
|
|
3371
3466
|
setEmail(input.email);
|
|
3372
3467
|
}
|
|
3373
3468
|
});
|
|
3374
|
-
const verifyMutation = (0,
|
|
3469
|
+
const verifyMutation = (0, import_react_query33.useMutation)({
|
|
3375
3470
|
mutationFn: (code) => {
|
|
3376
3471
|
if (!orderNumber || !email) {
|
|
3377
3472
|
throw new Error("Request a code before verifying");
|
|
@@ -3383,12 +3478,12 @@ function useOrderAccess() {
|
|
|
3383
3478
|
setAccessToken(result.accessToken);
|
|
3384
3479
|
}
|
|
3385
3480
|
});
|
|
3386
|
-
const requestCode = (0,
|
|
3481
|
+
const requestCode = (0, import_react15.useCallback)(
|
|
3387
3482
|
(on, em) => requestMutation.mutateAsync({ orderNumber: on, email: em }),
|
|
3388
3483
|
[requestMutation]
|
|
3389
3484
|
);
|
|
3390
|
-
const verifyCode = (0,
|
|
3391
|
-
const reset = (0,
|
|
3485
|
+
const verifyCode = (0, import_react15.useCallback)((code) => verifyMutation.mutateAsync(code), [verifyMutation]);
|
|
3486
|
+
const reset = (0, import_react15.useCallback)(() => {
|
|
3392
3487
|
setOrderNumber(null);
|
|
3393
3488
|
setEmail(null);
|
|
3394
3489
|
setOrder(null);
|
|
@@ -3416,13 +3511,13 @@ function useOrderAccess() {
|
|
|
3416
3511
|
}
|
|
3417
3512
|
|
|
3418
3513
|
// src/react/hooks/use-checkout.ts
|
|
3419
|
-
var
|
|
3420
|
-
var
|
|
3514
|
+
var import_react16 = require("react");
|
|
3515
|
+
var import_react_query34 = require("@tanstack/react-query");
|
|
3421
3516
|
function useCheckout() {
|
|
3422
3517
|
const { client, storage } = useBehio();
|
|
3423
|
-
const queryClient = (0,
|
|
3424
|
-
const [order, setOrder] = (0,
|
|
3425
|
-
const mutation = (0,
|
|
3518
|
+
const queryClient = (0, import_react_query34.useQueryClient)();
|
|
3519
|
+
const [order, setOrder] = (0, import_react16.useState)(null);
|
|
3520
|
+
const mutation = (0, import_react_query34.useMutation)({
|
|
3426
3521
|
mutationFn: (input) => unwrap(client.checkout.createOrder(input)),
|
|
3427
3522
|
onSuccess: (result) => {
|
|
3428
3523
|
setOrder(result);
|
|
@@ -3431,11 +3526,11 @@ function useCheckout() {
|
|
|
3431
3526
|
queryClient.invalidateQueries({ queryKey: ["behio", "orders"] });
|
|
3432
3527
|
}
|
|
3433
3528
|
});
|
|
3434
|
-
const createOrder = (0,
|
|
3529
|
+
const createOrder = (0, import_react16.useCallback)(
|
|
3435
3530
|
(input) => mutation.mutateAsync(input),
|
|
3436
3531
|
[mutation]
|
|
3437
3532
|
);
|
|
3438
|
-
const reset = (0,
|
|
3533
|
+
const reset = (0, import_react16.useCallback)(() => {
|
|
3439
3534
|
setOrder(null);
|
|
3440
3535
|
mutation.reset();
|
|
3441
3536
|
}, [mutation]);
|
|
@@ -3449,10 +3544,10 @@ function useCheckout() {
|
|
|
3449
3544
|
}
|
|
3450
3545
|
|
|
3451
3546
|
// src/react/hooks/use-pages.ts
|
|
3452
|
-
var
|
|
3547
|
+
var import_react_query35 = require("@tanstack/react-query");
|
|
3453
3548
|
function usePages(locale, options) {
|
|
3454
3549
|
const { client } = useBehio();
|
|
3455
|
-
return (0,
|
|
3550
|
+
return (0, import_react_query35.useQuery)({
|
|
3456
3551
|
queryKey: ["behio", "pages", locale],
|
|
3457
3552
|
queryFn: async () => {
|
|
3458
3553
|
const result = await unwrap(client.pages.list(locale));
|
|
@@ -3463,7 +3558,7 @@ function usePages(locale, options) {
|
|
|
3463
3558
|
}
|
|
3464
3559
|
function usePage(slug, locale, options) {
|
|
3465
3560
|
const { client } = useBehio();
|
|
3466
|
-
return (0,
|
|
3561
|
+
return (0, import_react_query35.useQuery)({
|
|
3467
3562
|
queryKey: ["behio", "page", slug, locale],
|
|
3468
3563
|
queryFn: () => unwrap(client.pages.get(slug, locale)),
|
|
3469
3564
|
enabled: options?.enabled !== false && !!slug
|
|
@@ -3471,10 +3566,10 @@ function usePage(slug, locale, options) {
|
|
|
3471
3566
|
}
|
|
3472
3567
|
|
|
3473
3568
|
// src/react/hooks/use-shop-info.ts
|
|
3474
|
-
var
|
|
3569
|
+
var import_react_query36 = require("@tanstack/react-query");
|
|
3475
3570
|
function useShopInfo(options) {
|
|
3476
3571
|
const { client } = useBehio();
|
|
3477
|
-
return (0,
|
|
3572
|
+
return (0, import_react_query36.useQuery)({
|
|
3478
3573
|
queryKey: ["behio", "shop-info"],
|
|
3479
3574
|
queryFn: () => unwrap(client.getShopInfo()),
|
|
3480
3575
|
enabled: options?.enabled !== false
|
|
@@ -3482,10 +3577,10 @@ function useShopInfo(options) {
|
|
|
3482
3577
|
}
|
|
3483
3578
|
|
|
3484
3579
|
// src/react/hooks/use-shop-scripts.ts
|
|
3485
|
-
var
|
|
3580
|
+
var import_react_query37 = require("@tanstack/react-query");
|
|
3486
3581
|
function useShopScripts(options) {
|
|
3487
3582
|
const { client } = useBehio();
|
|
3488
|
-
return (0,
|
|
3583
|
+
return (0, import_react_query37.useQuery)({
|
|
3489
3584
|
queryKey: ["behio", "shop-scripts"],
|
|
3490
3585
|
queryFn: () => unwrap(client.getShopScripts()),
|
|
3491
3586
|
enabled: options?.enabled !== false
|
|
@@ -3493,11 +3588,11 @@ function useShopScripts(options) {
|
|
|
3493
3588
|
}
|
|
3494
3589
|
|
|
3495
3590
|
// src/react/hooks/use-shop-seo.ts
|
|
3496
|
-
var
|
|
3591
|
+
var import_react_query38 = require("@tanstack/react-query");
|
|
3497
3592
|
function useShopSeo(options) {
|
|
3498
3593
|
const { client } = useBehio();
|
|
3499
3594
|
const { locale, initialData, enabled = true } = options ?? {};
|
|
3500
|
-
return (0,
|
|
3595
|
+
return (0, import_react_query38.useQuery)({
|
|
3501
3596
|
queryKey: ["behio", "shop-seo", locale ?? "_default"],
|
|
3502
3597
|
queryFn: () => unwrap(client.getShopSeo(locale)),
|
|
3503
3598
|
initialData,
|
|
@@ -3557,23 +3652,23 @@ function CurrencySwitcher({
|
|
|
3557
3652
|
}
|
|
3558
3653
|
|
|
3559
3654
|
// src/react/components/storefront-scripts.tsx
|
|
3560
|
-
var
|
|
3655
|
+
var import_react17 = require("react");
|
|
3561
3656
|
|
|
3562
3657
|
// src/react/hooks/use-consent.ts
|
|
3563
|
-
var
|
|
3658
|
+
var import_react_query39 = require("@tanstack/react-query");
|
|
3564
3659
|
function useCookieConsent(visitorId) {
|
|
3565
3660
|
const { client } = useBehio();
|
|
3566
|
-
const qc = (0,
|
|
3567
|
-
const query = (0,
|
|
3661
|
+
const qc = (0, import_react_query39.useQueryClient)();
|
|
3662
|
+
const query = (0, import_react_query39.useQuery)({
|
|
3568
3663
|
queryKey: ["behio", "consent", visitorId],
|
|
3569
3664
|
queryFn: () => unwrap(client.consent.get(visitorId)),
|
|
3570
3665
|
enabled: Boolean(visitorId)
|
|
3571
3666
|
});
|
|
3572
|
-
const recordMutation = (0,
|
|
3667
|
+
const recordMutation = (0, import_react_query39.useMutation)({
|
|
3573
3668
|
mutationFn: (input) => unwrap(client.consent.record(input)),
|
|
3574
3669
|
onSuccess: () => qc.invalidateQueries({ queryKey: ["behio", "consent"] })
|
|
3575
3670
|
});
|
|
3576
|
-
const revokeMutation = (0,
|
|
3671
|
+
const revokeMutation = (0, import_react_query39.useMutation)({
|
|
3577
3672
|
mutationFn: () => unwrap(client.consent.revoke(visitorId)),
|
|
3578
3673
|
onSuccess: () => qc.invalidateQueries({ queryKey: ["behio", "consent"] })
|
|
3579
3674
|
});
|
|
@@ -3647,8 +3742,8 @@ function injectHtml(target, html) {
|
|
|
3647
3742
|
}
|
|
3648
3743
|
function StorefrontScripts({ visitorId: visitorIdProp } = {}) {
|
|
3649
3744
|
const { data } = useShopScripts();
|
|
3650
|
-
const [visitorId, setVisitorId] = (0,
|
|
3651
|
-
(0,
|
|
3745
|
+
const [visitorId, setVisitorId] = (0, import_react17.useState)(visitorIdProp ?? "");
|
|
3746
|
+
(0, import_react17.useEffect)(() => {
|
|
3652
3747
|
if (visitorIdProp) return;
|
|
3653
3748
|
try {
|
|
3654
3749
|
const v = localStorage.getItem(VISITOR_KEY);
|
|
@@ -3658,15 +3753,15 @@ function StorefrontScripts({ visitorId: visitorIdProp } = {}) {
|
|
|
3658
3753
|
}, [visitorIdProp]);
|
|
3659
3754
|
const { data: consent } = useCookieConsent(visitorId || void 0);
|
|
3660
3755
|
const analyticsOk = Boolean(consent?.analytics);
|
|
3661
|
-
const scripts = (0,
|
|
3756
|
+
const scripts = (0, import_react17.useMemo)(
|
|
3662
3757
|
() => (data?.scripts ?? []).filter((s) => !s.consentRequired || analyticsOk),
|
|
3663
3758
|
[data, analyticsOk]
|
|
3664
3759
|
);
|
|
3665
|
-
const signature = (0,
|
|
3760
|
+
const signature = (0, import_react17.useMemo)(
|
|
3666
3761
|
() => JSON.stringify(scripts.map((s) => [s.id, s.type, s.placement, s.value])),
|
|
3667
3762
|
[scripts]
|
|
3668
3763
|
);
|
|
3669
|
-
(0,
|
|
3764
|
+
(0, import_react17.useEffect)(() => {
|
|
3670
3765
|
if (typeof document === "undefined") return;
|
|
3671
3766
|
const added = [];
|
|
3672
3767
|
for (const s of scripts) {
|
|
@@ -3683,7 +3778,7 @@ function StorefrontScripts({ visitorId: visitorIdProp } = {}) {
|
|
|
3683
3778
|
}
|
|
3684
3779
|
|
|
3685
3780
|
// src/react/components/behio-analytics.tsx
|
|
3686
|
-
var
|
|
3781
|
+
var import_react18 = require("react");
|
|
3687
3782
|
|
|
3688
3783
|
// src/react/hooks/use-behio-client.ts
|
|
3689
3784
|
function useBehioClient() {
|
|
@@ -3693,7 +3788,7 @@ function useBehioClient() {
|
|
|
3693
3788
|
// src/react/components/behio-analytics.tsx
|
|
3694
3789
|
function BehioAnalyticsTracker() {
|
|
3695
3790
|
const client = useBehioClient();
|
|
3696
|
-
(0,
|
|
3791
|
+
(0, import_react18.useEffect)(() => {
|
|
3697
3792
|
if (typeof window === "undefined") return;
|
|
3698
3793
|
const w = window;
|
|
3699
3794
|
if (w.__behioAnalytics) return;
|
|
@@ -3932,10 +4027,10 @@ function utmFromSearch(search) {
|
|
|
3932
4027
|
}
|
|
3933
4028
|
|
|
3934
4029
|
// src/react/hooks/use-bundles.ts
|
|
3935
|
-
var
|
|
4030
|
+
var import_react_query40 = require("@tanstack/react-query");
|
|
3936
4031
|
function useBundles(options) {
|
|
3937
4032
|
const { client } = useBehio();
|
|
3938
|
-
return (0,
|
|
4033
|
+
return (0, import_react_query40.useQuery)({
|
|
3939
4034
|
queryKey: ["behio", "bundles"],
|
|
3940
4035
|
queryFn: () => unwrap(client.catalog.getBundles()),
|
|
3941
4036
|
enabled: options?.enabled ?? true,
|
|
@@ -3944,7 +4039,7 @@ function useBundles(options) {
|
|
|
3944
4039
|
}
|
|
3945
4040
|
function useBundle(slug, options) {
|
|
3946
4041
|
const { client } = useBehio();
|
|
3947
|
-
return (0,
|
|
4042
|
+
return (0, import_react_query40.useQuery)({
|
|
3948
4043
|
queryKey: ["behio", "bundle", slug],
|
|
3949
4044
|
queryFn: () => unwrap(client.catalog.getBundle(slug)),
|
|
3950
4045
|
enabled: Boolean(slug) && (options?.enabled ?? true),
|
|
@@ -3953,10 +4048,10 @@ function useBundle(slug, options) {
|
|
|
3953
4048
|
}
|
|
3954
4049
|
|
|
3955
4050
|
// src/react/hooks/use-product-group.ts
|
|
3956
|
-
var
|
|
4051
|
+
var import_react_query41 = require("@tanstack/react-query");
|
|
3957
4052
|
function useProductGroup(slug, options) {
|
|
3958
4053
|
const { client } = useBehio();
|
|
3959
|
-
return (0,
|
|
4054
|
+
return (0, import_react_query41.useQuery)({
|
|
3960
4055
|
queryKey: ["behio", "product-group", slug, options?.locale, options?.currency],
|
|
3961
4056
|
queryFn: () => unwrap(
|
|
3962
4057
|
client.catalog.getProductGroup(slug, {
|
|
@@ -3970,10 +4065,10 @@ function useProductGroup(slug, options) {
|
|
|
3970
4065
|
}
|
|
3971
4066
|
|
|
3972
4067
|
// src/react/hooks/use-cross-sell.ts
|
|
3973
|
-
var
|
|
4068
|
+
var import_react_query42 = require("@tanstack/react-query");
|
|
3974
4069
|
function useCrossSell(productSlug, options) {
|
|
3975
4070
|
const { client } = useBehio();
|
|
3976
|
-
return (0,
|
|
4071
|
+
return (0, import_react_query42.useQuery)({
|
|
3977
4072
|
queryKey: ["behio", "cross-sell", productSlug, options?.locale, options?.currency],
|
|
3978
4073
|
queryFn: () => unwrap(
|
|
3979
4074
|
client.catalog.getCrossSell(productSlug, {
|
|
@@ -3987,10 +4082,10 @@ function useCrossSell(productSlug, options) {
|
|
|
3987
4082
|
}
|
|
3988
4083
|
|
|
3989
4084
|
// src/react/hooks/use-product-promotions.ts
|
|
3990
|
-
var
|
|
4085
|
+
var import_react_query43 = require("@tanstack/react-query");
|
|
3991
4086
|
function useProductPromotions(productSlug, options) {
|
|
3992
4087
|
const { client } = useBehio();
|
|
3993
|
-
return (0,
|
|
4088
|
+
return (0, import_react_query43.useQuery)({
|
|
3994
4089
|
queryKey: ["behio", "product-promotions", productSlug],
|
|
3995
4090
|
queryFn: () => unwrap(client.catalog.getProductPromotions(productSlug)),
|
|
3996
4091
|
enabled: Boolean(productSlug) && (options?.enabled ?? true),
|
|
@@ -3999,11 +4094,11 @@ function useProductPromotions(productSlug, options) {
|
|
|
3999
4094
|
}
|
|
4000
4095
|
|
|
4001
4096
|
// src/react/hooks/use-gift-card.ts
|
|
4002
|
-
var
|
|
4097
|
+
var import_react_query44 = require("@tanstack/react-query");
|
|
4003
4098
|
function useGiftCardBalance(code, options) {
|
|
4004
4099
|
const { client } = useBehio();
|
|
4005
4100
|
const trimmed = code?.trim();
|
|
4006
|
-
return (0,
|
|
4101
|
+
return (0, import_react_query44.useQuery)({
|
|
4007
4102
|
queryKey: ["behio", "gift-card-balance", trimmed],
|
|
4008
4103
|
queryFn: () => unwrap(client.catalog.checkGiftCard(trimmed)),
|
|
4009
4104
|
enabled: Boolean(trimmed && trimmed.length >= 6) && (options?.enabled ?? true)
|
|
@@ -4011,20 +4106,20 @@ function useGiftCardBalance(code, options) {
|
|
|
4011
4106
|
}
|
|
4012
4107
|
|
|
4013
4108
|
// src/react/hooks/use-wishlist.ts
|
|
4014
|
-
var
|
|
4109
|
+
var import_react_query45 = require("@tanstack/react-query");
|
|
4015
4110
|
function useWishlist(options) {
|
|
4016
4111
|
const { client } = useBehio();
|
|
4017
|
-
const qc = (0,
|
|
4018
|
-
const query = (0,
|
|
4112
|
+
const qc = (0, import_react_query45.useQueryClient)();
|
|
4113
|
+
const query = (0, import_react_query45.useQuery)({
|
|
4019
4114
|
queryKey: ["behio", "wishlist"],
|
|
4020
4115
|
queryFn: () => unwrap(client.wishlist.get()),
|
|
4021
4116
|
enabled: options?.enabled ?? true
|
|
4022
4117
|
});
|
|
4023
|
-
const addMutation = (0,
|
|
4118
|
+
const addMutation = (0, import_react_query45.useMutation)({
|
|
4024
4119
|
mutationFn: (productId) => unwrap(client.wishlist.add(productId)),
|
|
4025
4120
|
onSuccess: () => qc.invalidateQueries({ queryKey: ["behio", "wishlist"] })
|
|
4026
4121
|
});
|
|
4027
|
-
const removeMutation = (0,
|
|
4122
|
+
const removeMutation = (0, import_react_query45.useMutation)({
|
|
4028
4123
|
mutationFn: (productId) => unwrap(client.wishlist.remove(productId)),
|
|
4029
4124
|
onSuccess: () => qc.invalidateQueries({ queryKey: ["behio", "wishlist"] })
|
|
4030
4125
|
});
|
|
@@ -4038,7 +4133,7 @@ function useWishlist(options) {
|
|
|
4038
4133
|
}
|
|
4039
4134
|
function useIsInWishlist(productId) {
|
|
4040
4135
|
const { client } = useBehio();
|
|
4041
|
-
return (0,
|
|
4136
|
+
return (0, import_react_query45.useQuery)({
|
|
4042
4137
|
queryKey: ["behio", "wishlist-check", productId],
|
|
4043
4138
|
queryFn: () => unwrap(client.wishlist.isInWishlist(productId)),
|
|
4044
4139
|
enabled: Boolean(productId)
|
|
@@ -4046,10 +4141,10 @@ function useIsInWishlist(productId) {
|
|
|
4046
4141
|
}
|
|
4047
4142
|
|
|
4048
4143
|
// src/react/hooks/use-reviews.ts
|
|
4049
|
-
var
|
|
4144
|
+
var import_react_query46 = require("@tanstack/react-query");
|
|
4050
4145
|
function useProductReviews(productId, options) {
|
|
4051
4146
|
const { client } = useBehio();
|
|
4052
|
-
return (0,
|
|
4147
|
+
return (0, import_react_query46.useQuery)({
|
|
4053
4148
|
queryKey: ["behio", "reviews", productId, options?.page ?? 1],
|
|
4054
4149
|
queryFn: () => unwrap(client.reviews.getProductReviews(productId, options?.page, options?.limit)),
|
|
4055
4150
|
enabled: Boolean(productId) && (options?.enabled ?? true)
|
|
@@ -4057,30 +4152,30 @@ function useProductReviews(productId, options) {
|
|
|
4057
4152
|
}
|
|
4058
4153
|
function useSubmitReview() {
|
|
4059
4154
|
const { client } = useBehio();
|
|
4060
|
-
const qc = (0,
|
|
4061
|
-
return (0,
|
|
4155
|
+
const qc = (0, import_react_query46.useQueryClient)();
|
|
4156
|
+
return (0, import_react_query46.useMutation)({
|
|
4062
4157
|
mutationFn: (input) => unwrap(client.reviews.submit(input)),
|
|
4063
4158
|
onSuccess: (_, input) => qc.invalidateQueries({ queryKey: ["behio", "reviews", input.productId] })
|
|
4064
4159
|
});
|
|
4065
4160
|
}
|
|
4066
4161
|
|
|
4067
4162
|
// src/react/hooks/use-returns.ts
|
|
4068
|
-
var
|
|
4163
|
+
var import_react_query47 = require("@tanstack/react-query");
|
|
4069
4164
|
function useLookupReturnableOrder() {
|
|
4070
4165
|
const { client } = useBehio();
|
|
4071
|
-
return (0,
|
|
4166
|
+
return (0, import_react_query47.useMutation)({
|
|
4072
4167
|
mutationFn: ({ orderNumber, email }) => unwrap(client.returns.lookupOrder(orderNumber, email))
|
|
4073
4168
|
});
|
|
4074
4169
|
}
|
|
4075
4170
|
function useSubmitReturn() {
|
|
4076
4171
|
const { client } = useBehio();
|
|
4077
|
-
return (0,
|
|
4172
|
+
return (0, import_react_query47.useMutation)({
|
|
4078
4173
|
mutationFn: (input) => unwrap(client.returns.submit(input))
|
|
4079
4174
|
});
|
|
4080
4175
|
}
|
|
4081
4176
|
function useReturnStatus(returnId, email) {
|
|
4082
4177
|
const { client } = useBehio();
|
|
4083
|
-
return (0,
|
|
4178
|
+
return (0, import_react_query47.useQuery)({
|
|
4084
4179
|
queryKey: ["behio", "return-status", returnId],
|
|
4085
4180
|
queryFn: () => unwrap(client.returns.getStatus(returnId, email)),
|
|
4086
4181
|
enabled: Boolean(returnId && email)
|
|
@@ -4088,16 +4183,16 @@ function useReturnStatus(returnId, email) {
|
|
|
4088
4183
|
}
|
|
4089
4184
|
|
|
4090
4185
|
// src/react/hooks/use-quotes.ts
|
|
4091
|
-
var
|
|
4186
|
+
var import_react_query48 = require("@tanstack/react-query");
|
|
4092
4187
|
function useSubmitQuote() {
|
|
4093
4188
|
const { client } = useBehio();
|
|
4094
|
-
return (0,
|
|
4189
|
+
return (0, import_react_query48.useMutation)({
|
|
4095
4190
|
mutationFn: (input) => unwrap(client.quotes.submit(input))
|
|
4096
4191
|
});
|
|
4097
4192
|
}
|
|
4098
4193
|
function useQuoteStatus(quoteId, email) {
|
|
4099
4194
|
const { client } = useBehio();
|
|
4100
|
-
return (0,
|
|
4195
|
+
return (0, import_react_query48.useQuery)({
|
|
4101
4196
|
queryKey: ["behio", "quote-status", quoteId],
|
|
4102
4197
|
queryFn: () => unwrap(client.quotes.getStatus(quoteId, email)),
|
|
4103
4198
|
enabled: Boolean(quoteId && email)
|
|
@@ -4105,10 +4200,10 @@ function useQuoteStatus(quoteId, email) {
|
|
|
4105
4200
|
}
|
|
4106
4201
|
|
|
4107
4202
|
// src/react/hooks/use-back-in-stock.ts
|
|
4108
|
-
var
|
|
4203
|
+
var import_react_query49 = require("@tanstack/react-query");
|
|
4109
4204
|
function useNotifyWhenAvailable() {
|
|
4110
4205
|
const { client } = useBehio();
|
|
4111
|
-
return (0,
|
|
4206
|
+
return (0, import_react_query49.useMutation)({
|
|
4112
4207
|
mutationFn: ({ productId, email }) => unwrap(client.catalog.notifyWhenAvailable(productId, email))
|
|
4113
4208
|
});
|
|
4114
4209
|
}
|
|
@@ -4302,5 +4397,6 @@ async function revokeAnalyticsConsent(client) {
|
|
|
4302
4397
|
useSubmitReturn,
|
|
4303
4398
|
useSubmitReview,
|
|
4304
4399
|
useSubscriptions,
|
|
4400
|
+
useVisitorMessages,
|
|
4305
4401
|
useWishlist
|
|
4306
4402
|
});
|