@behio/storefront-sdk 1.8.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-LQ4GGXMJ.js → chunk-CY6D2YEI.js} +15 -0
- package/dist/{chunk-LA6K4KYS.mjs → chunk-XMKY4RI5.mjs} +15 -0
- package/dist/{client-BP9n3a_D.d.mts → client-C635vSzU.d.mts} +19 -0
- package/dist/{client-BP9n3a_D.d.ts → client-C635vSzU.d.ts} +19 -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 +74 -1
- package/dist/react.d.ts +74 -1
- package/dist/react.js +173 -89
- package/dist/react.mjs +149 -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);
|
|
@@ -297,6 +298,21 @@ var BehioStorefront = class {
|
|
|
297
298
|
body: input
|
|
298
299
|
});
|
|
299
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
|
+
}
|
|
300
316
|
/** Get basic shop info */
|
|
301
317
|
async getShopInfo() {
|
|
302
318
|
return this.request("GET", "/shop");
|
|
@@ -3236,11 +3252,78 @@ function usePersonalOffers(options) {
|
|
|
3236
3252
|
};
|
|
3237
3253
|
}
|
|
3238
3254
|
|
|
3239
|
-
// src/react/hooks/use-
|
|
3255
|
+
// src/react/hooks/use-visitor-messages.ts
|
|
3240
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");
|
|
3241
3324
|
function useAnalyticsEvents() {
|
|
3242
3325
|
const { client } = useBehio();
|
|
3243
|
-
const track = (0,
|
|
3326
|
+
const track = (0, import_react12.useCallback)(
|
|
3244
3327
|
(events, opts) => {
|
|
3245
3328
|
const list = Array.isArray(events) ? events : [events];
|
|
3246
3329
|
if (list.length === 0) return Promise.resolve();
|
|
@@ -3252,7 +3335,7 @@ function useAnalyticsEvents() {
|
|
|
3252
3335
|
},
|
|
3253
3336
|
[client]
|
|
3254
3337
|
);
|
|
3255
|
-
const trackEvent = (0,
|
|
3338
|
+
const trackEvent = (0, import_react12.useCallback)(
|
|
3256
3339
|
(name, props) => track({ type: "custom", name, props }),
|
|
3257
3340
|
[track]
|
|
3258
3341
|
);
|
|
@@ -3267,28 +3350,28 @@ function useAnalyticsEvents() {
|
|
|
3267
3350
|
}
|
|
3268
3351
|
|
|
3269
3352
|
// src/react/hooks/use-newsletter.ts
|
|
3270
|
-
var
|
|
3353
|
+
var import_react_query30 = require("@tanstack/react-query");
|
|
3271
3354
|
function useNewsletterSubscribe() {
|
|
3272
3355
|
const { client } = useBehio();
|
|
3273
|
-
return (0,
|
|
3356
|
+
return (0, import_react_query30.useMutation)({
|
|
3274
3357
|
mutationFn: (input) => unwrap(client.newsletter.subscribe(input))
|
|
3275
3358
|
});
|
|
3276
3359
|
}
|
|
3277
3360
|
function useNewsletterUnsubscribe() {
|
|
3278
3361
|
const { client } = useBehio();
|
|
3279
|
-
return (0,
|
|
3362
|
+
return (0, import_react_query30.useMutation)({
|
|
3280
3363
|
mutationFn: (email) => unwrap(client.newsletter.unsubscribe(email))
|
|
3281
3364
|
});
|
|
3282
3365
|
}
|
|
3283
3366
|
|
|
3284
3367
|
// src/react/hooks/use-orders.ts
|
|
3285
|
-
var
|
|
3286
|
-
var
|
|
3368
|
+
var import_react13 = require("react");
|
|
3369
|
+
var import_react_query31 = require("@tanstack/react-query");
|
|
3287
3370
|
function useOrders(options) {
|
|
3288
3371
|
const { client } = useBehio();
|
|
3289
3372
|
const { page: initialPage, limit, enabled } = options ?? {};
|
|
3290
|
-
const [page, setPage] = (0,
|
|
3291
|
-
const infinite = (0,
|
|
3373
|
+
const [page, setPage] = (0, import_react13.useState)(initialPage ?? 1);
|
|
3374
|
+
const infinite = (0, import_react_query31.useInfiniteQuery)({
|
|
3292
3375
|
queryKey: ["behio", "orders", limit, page],
|
|
3293
3376
|
queryFn: ({ pageParam }) => unwrap(client.orders.list({ limit, page: pageParam })),
|
|
3294
3377
|
initialPageParam: page,
|
|
@@ -3296,18 +3379,18 @@ function useOrders(options) {
|
|
|
3296
3379
|
getPreviousPageParam: (firstPage) => firstPage.page > 1 ? firstPage.page - 1 : void 0,
|
|
3297
3380
|
enabled: enabled !== false && !!client.getAccessToken()
|
|
3298
3381
|
});
|
|
3299
|
-
const items = (0,
|
|
3382
|
+
const items = (0, import_react13.useMemo)(
|
|
3300
3383
|
() => infinite.data?.pages.flatMap((p) => p.items) ?? [],
|
|
3301
3384
|
[infinite.data]
|
|
3302
3385
|
);
|
|
3303
3386
|
const lastPage = infinite.data?.pages[infinite.data.pages.length - 1];
|
|
3304
|
-
const loadMore = (0,
|
|
3387
|
+
const loadMore = (0, import_react13.useCallback)(() => {
|
|
3305
3388
|
if (infinite.hasNextPage && !infinite.isFetchingNextPage) {
|
|
3306
3389
|
return infinite.fetchNextPage();
|
|
3307
3390
|
}
|
|
3308
3391
|
return Promise.resolve();
|
|
3309
3392
|
}, [infinite]);
|
|
3310
|
-
const goToPage = (0,
|
|
3393
|
+
const goToPage = (0, import_react13.useCallback)((newPage) => {
|
|
3311
3394
|
setPage(newPage);
|
|
3312
3395
|
}, []);
|
|
3313
3396
|
return {
|
|
@@ -3333,28 +3416,28 @@ function useOrders(options) {
|
|
|
3333
3416
|
}
|
|
3334
3417
|
|
|
3335
3418
|
// src/react/hooks/use-order.ts
|
|
3336
|
-
var
|
|
3337
|
-
var
|
|
3419
|
+
var import_react14 = require("react");
|
|
3420
|
+
var import_react_query32 = require("@tanstack/react-query");
|
|
3338
3421
|
function useOrder(orderNumber, options) {
|
|
3339
3422
|
const { client } = useBehio();
|
|
3340
|
-
const queryClient = (0,
|
|
3423
|
+
const queryClient = (0, import_react_query32.useQueryClient)();
|
|
3341
3424
|
const {
|
|
3342
3425
|
data,
|
|
3343
3426
|
isLoading,
|
|
3344
3427
|
error
|
|
3345
|
-
} = (0,
|
|
3428
|
+
} = (0, import_react_query32.useQuery)({
|
|
3346
3429
|
queryKey: ["behio", "order", orderNumber],
|
|
3347
3430
|
queryFn: () => unwrap(client.orders.get(orderNumber)),
|
|
3348
3431
|
enabled: options?.enabled !== false && !!orderNumber && !!client.getAccessToken()
|
|
3349
3432
|
});
|
|
3350
|
-
const cancelMutation = (0,
|
|
3433
|
+
const cancelMutation = (0, import_react_query32.useMutation)({
|
|
3351
3434
|
mutationFn: () => unwrap(client.orders.cancel(orderNumber)),
|
|
3352
3435
|
onSuccess: (updated) => {
|
|
3353
3436
|
queryClient.setQueryData(["behio", "order", orderNumber], updated);
|
|
3354
3437
|
queryClient.invalidateQueries({ queryKey: ["behio", "orders"] });
|
|
3355
3438
|
}
|
|
3356
3439
|
});
|
|
3357
|
-
const cancel = (0,
|
|
3440
|
+
const cancel = (0, import_react14.useCallback)(
|
|
3358
3441
|
() => cancelMutation.mutateAsync(),
|
|
3359
3442
|
[cancelMutation]
|
|
3360
3443
|
);
|
|
@@ -3368,22 +3451,22 @@ function useOrder(orderNumber, options) {
|
|
|
3368
3451
|
}
|
|
3369
3452
|
|
|
3370
3453
|
// src/react/hooks/use-order-access.ts
|
|
3371
|
-
var
|
|
3372
|
-
var
|
|
3454
|
+
var import_react15 = require("react");
|
|
3455
|
+
var import_react_query33 = require("@tanstack/react-query");
|
|
3373
3456
|
function useOrderAccess() {
|
|
3374
3457
|
const { client } = useBehio();
|
|
3375
|
-
const [orderNumber, setOrderNumber] = (0,
|
|
3376
|
-
const [email, setEmail] = (0,
|
|
3377
|
-
const [order, setOrder] = (0,
|
|
3378
|
-
const [accessToken, setAccessToken] = (0,
|
|
3379
|
-
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)({
|
|
3380
3463
|
mutationFn: (input) => unwrap(client.orders.requestAccessCode(input.orderNumber, input.email)),
|
|
3381
3464
|
onSuccess: (_data, input) => {
|
|
3382
3465
|
setOrderNumber(input.orderNumber);
|
|
3383
3466
|
setEmail(input.email);
|
|
3384
3467
|
}
|
|
3385
3468
|
});
|
|
3386
|
-
const verifyMutation = (0,
|
|
3469
|
+
const verifyMutation = (0, import_react_query33.useMutation)({
|
|
3387
3470
|
mutationFn: (code) => {
|
|
3388
3471
|
if (!orderNumber || !email) {
|
|
3389
3472
|
throw new Error("Request a code before verifying");
|
|
@@ -3395,12 +3478,12 @@ function useOrderAccess() {
|
|
|
3395
3478
|
setAccessToken(result.accessToken);
|
|
3396
3479
|
}
|
|
3397
3480
|
});
|
|
3398
|
-
const requestCode = (0,
|
|
3481
|
+
const requestCode = (0, import_react15.useCallback)(
|
|
3399
3482
|
(on, em) => requestMutation.mutateAsync({ orderNumber: on, email: em }),
|
|
3400
3483
|
[requestMutation]
|
|
3401
3484
|
);
|
|
3402
|
-
const verifyCode = (0,
|
|
3403
|
-
const reset = (0,
|
|
3485
|
+
const verifyCode = (0, import_react15.useCallback)((code) => verifyMutation.mutateAsync(code), [verifyMutation]);
|
|
3486
|
+
const reset = (0, import_react15.useCallback)(() => {
|
|
3404
3487
|
setOrderNumber(null);
|
|
3405
3488
|
setEmail(null);
|
|
3406
3489
|
setOrder(null);
|
|
@@ -3428,13 +3511,13 @@ function useOrderAccess() {
|
|
|
3428
3511
|
}
|
|
3429
3512
|
|
|
3430
3513
|
// src/react/hooks/use-checkout.ts
|
|
3431
|
-
var
|
|
3432
|
-
var
|
|
3514
|
+
var import_react16 = require("react");
|
|
3515
|
+
var import_react_query34 = require("@tanstack/react-query");
|
|
3433
3516
|
function useCheckout() {
|
|
3434
3517
|
const { client, storage } = useBehio();
|
|
3435
|
-
const queryClient = (0,
|
|
3436
|
-
const [order, setOrder] = (0,
|
|
3437
|
-
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)({
|
|
3438
3521
|
mutationFn: (input) => unwrap(client.checkout.createOrder(input)),
|
|
3439
3522
|
onSuccess: (result) => {
|
|
3440
3523
|
setOrder(result);
|
|
@@ -3443,11 +3526,11 @@ function useCheckout() {
|
|
|
3443
3526
|
queryClient.invalidateQueries({ queryKey: ["behio", "orders"] });
|
|
3444
3527
|
}
|
|
3445
3528
|
});
|
|
3446
|
-
const createOrder = (0,
|
|
3529
|
+
const createOrder = (0, import_react16.useCallback)(
|
|
3447
3530
|
(input) => mutation.mutateAsync(input),
|
|
3448
3531
|
[mutation]
|
|
3449
3532
|
);
|
|
3450
|
-
const reset = (0,
|
|
3533
|
+
const reset = (0, import_react16.useCallback)(() => {
|
|
3451
3534
|
setOrder(null);
|
|
3452
3535
|
mutation.reset();
|
|
3453
3536
|
}, [mutation]);
|
|
@@ -3461,10 +3544,10 @@ function useCheckout() {
|
|
|
3461
3544
|
}
|
|
3462
3545
|
|
|
3463
3546
|
// src/react/hooks/use-pages.ts
|
|
3464
|
-
var
|
|
3547
|
+
var import_react_query35 = require("@tanstack/react-query");
|
|
3465
3548
|
function usePages(locale, options) {
|
|
3466
3549
|
const { client } = useBehio();
|
|
3467
|
-
return (0,
|
|
3550
|
+
return (0, import_react_query35.useQuery)({
|
|
3468
3551
|
queryKey: ["behio", "pages", locale],
|
|
3469
3552
|
queryFn: async () => {
|
|
3470
3553
|
const result = await unwrap(client.pages.list(locale));
|
|
@@ -3475,7 +3558,7 @@ function usePages(locale, options) {
|
|
|
3475
3558
|
}
|
|
3476
3559
|
function usePage(slug, locale, options) {
|
|
3477
3560
|
const { client } = useBehio();
|
|
3478
|
-
return (0,
|
|
3561
|
+
return (0, import_react_query35.useQuery)({
|
|
3479
3562
|
queryKey: ["behio", "page", slug, locale],
|
|
3480
3563
|
queryFn: () => unwrap(client.pages.get(slug, locale)),
|
|
3481
3564
|
enabled: options?.enabled !== false && !!slug
|
|
@@ -3483,10 +3566,10 @@ function usePage(slug, locale, options) {
|
|
|
3483
3566
|
}
|
|
3484
3567
|
|
|
3485
3568
|
// src/react/hooks/use-shop-info.ts
|
|
3486
|
-
var
|
|
3569
|
+
var import_react_query36 = require("@tanstack/react-query");
|
|
3487
3570
|
function useShopInfo(options) {
|
|
3488
3571
|
const { client } = useBehio();
|
|
3489
|
-
return (0,
|
|
3572
|
+
return (0, import_react_query36.useQuery)({
|
|
3490
3573
|
queryKey: ["behio", "shop-info"],
|
|
3491
3574
|
queryFn: () => unwrap(client.getShopInfo()),
|
|
3492
3575
|
enabled: options?.enabled !== false
|
|
@@ -3494,10 +3577,10 @@ function useShopInfo(options) {
|
|
|
3494
3577
|
}
|
|
3495
3578
|
|
|
3496
3579
|
// src/react/hooks/use-shop-scripts.ts
|
|
3497
|
-
var
|
|
3580
|
+
var import_react_query37 = require("@tanstack/react-query");
|
|
3498
3581
|
function useShopScripts(options) {
|
|
3499
3582
|
const { client } = useBehio();
|
|
3500
|
-
return (0,
|
|
3583
|
+
return (0, import_react_query37.useQuery)({
|
|
3501
3584
|
queryKey: ["behio", "shop-scripts"],
|
|
3502
3585
|
queryFn: () => unwrap(client.getShopScripts()),
|
|
3503
3586
|
enabled: options?.enabled !== false
|
|
@@ -3505,11 +3588,11 @@ function useShopScripts(options) {
|
|
|
3505
3588
|
}
|
|
3506
3589
|
|
|
3507
3590
|
// src/react/hooks/use-shop-seo.ts
|
|
3508
|
-
var
|
|
3591
|
+
var import_react_query38 = require("@tanstack/react-query");
|
|
3509
3592
|
function useShopSeo(options) {
|
|
3510
3593
|
const { client } = useBehio();
|
|
3511
3594
|
const { locale, initialData, enabled = true } = options ?? {};
|
|
3512
|
-
return (0,
|
|
3595
|
+
return (0, import_react_query38.useQuery)({
|
|
3513
3596
|
queryKey: ["behio", "shop-seo", locale ?? "_default"],
|
|
3514
3597
|
queryFn: () => unwrap(client.getShopSeo(locale)),
|
|
3515
3598
|
initialData,
|
|
@@ -3569,23 +3652,23 @@ function CurrencySwitcher({
|
|
|
3569
3652
|
}
|
|
3570
3653
|
|
|
3571
3654
|
// src/react/components/storefront-scripts.tsx
|
|
3572
|
-
var
|
|
3655
|
+
var import_react17 = require("react");
|
|
3573
3656
|
|
|
3574
3657
|
// src/react/hooks/use-consent.ts
|
|
3575
|
-
var
|
|
3658
|
+
var import_react_query39 = require("@tanstack/react-query");
|
|
3576
3659
|
function useCookieConsent(visitorId) {
|
|
3577
3660
|
const { client } = useBehio();
|
|
3578
|
-
const qc = (0,
|
|
3579
|
-
const query = (0,
|
|
3661
|
+
const qc = (0, import_react_query39.useQueryClient)();
|
|
3662
|
+
const query = (0, import_react_query39.useQuery)({
|
|
3580
3663
|
queryKey: ["behio", "consent", visitorId],
|
|
3581
3664
|
queryFn: () => unwrap(client.consent.get(visitorId)),
|
|
3582
3665
|
enabled: Boolean(visitorId)
|
|
3583
3666
|
});
|
|
3584
|
-
const recordMutation = (0,
|
|
3667
|
+
const recordMutation = (0, import_react_query39.useMutation)({
|
|
3585
3668
|
mutationFn: (input) => unwrap(client.consent.record(input)),
|
|
3586
3669
|
onSuccess: () => qc.invalidateQueries({ queryKey: ["behio", "consent"] })
|
|
3587
3670
|
});
|
|
3588
|
-
const revokeMutation = (0,
|
|
3671
|
+
const revokeMutation = (0, import_react_query39.useMutation)({
|
|
3589
3672
|
mutationFn: () => unwrap(client.consent.revoke(visitorId)),
|
|
3590
3673
|
onSuccess: () => qc.invalidateQueries({ queryKey: ["behio", "consent"] })
|
|
3591
3674
|
});
|
|
@@ -3659,8 +3742,8 @@ function injectHtml(target, html) {
|
|
|
3659
3742
|
}
|
|
3660
3743
|
function StorefrontScripts({ visitorId: visitorIdProp } = {}) {
|
|
3661
3744
|
const { data } = useShopScripts();
|
|
3662
|
-
const [visitorId, setVisitorId] = (0,
|
|
3663
|
-
(0,
|
|
3745
|
+
const [visitorId, setVisitorId] = (0, import_react17.useState)(visitorIdProp ?? "");
|
|
3746
|
+
(0, import_react17.useEffect)(() => {
|
|
3664
3747
|
if (visitorIdProp) return;
|
|
3665
3748
|
try {
|
|
3666
3749
|
const v = localStorage.getItem(VISITOR_KEY);
|
|
@@ -3670,15 +3753,15 @@ function StorefrontScripts({ visitorId: visitorIdProp } = {}) {
|
|
|
3670
3753
|
}, [visitorIdProp]);
|
|
3671
3754
|
const { data: consent } = useCookieConsent(visitorId || void 0);
|
|
3672
3755
|
const analyticsOk = Boolean(consent?.analytics);
|
|
3673
|
-
const scripts = (0,
|
|
3756
|
+
const scripts = (0, import_react17.useMemo)(
|
|
3674
3757
|
() => (data?.scripts ?? []).filter((s) => !s.consentRequired || analyticsOk),
|
|
3675
3758
|
[data, analyticsOk]
|
|
3676
3759
|
);
|
|
3677
|
-
const signature = (0,
|
|
3760
|
+
const signature = (0, import_react17.useMemo)(
|
|
3678
3761
|
() => JSON.stringify(scripts.map((s) => [s.id, s.type, s.placement, s.value])),
|
|
3679
3762
|
[scripts]
|
|
3680
3763
|
);
|
|
3681
|
-
(0,
|
|
3764
|
+
(0, import_react17.useEffect)(() => {
|
|
3682
3765
|
if (typeof document === "undefined") return;
|
|
3683
3766
|
const added = [];
|
|
3684
3767
|
for (const s of scripts) {
|
|
@@ -3695,7 +3778,7 @@ function StorefrontScripts({ visitorId: visitorIdProp } = {}) {
|
|
|
3695
3778
|
}
|
|
3696
3779
|
|
|
3697
3780
|
// src/react/components/behio-analytics.tsx
|
|
3698
|
-
var
|
|
3781
|
+
var import_react18 = require("react");
|
|
3699
3782
|
|
|
3700
3783
|
// src/react/hooks/use-behio-client.ts
|
|
3701
3784
|
function useBehioClient() {
|
|
@@ -3705,7 +3788,7 @@ function useBehioClient() {
|
|
|
3705
3788
|
// src/react/components/behio-analytics.tsx
|
|
3706
3789
|
function BehioAnalyticsTracker() {
|
|
3707
3790
|
const client = useBehioClient();
|
|
3708
|
-
(0,
|
|
3791
|
+
(0, import_react18.useEffect)(() => {
|
|
3709
3792
|
if (typeof window === "undefined") return;
|
|
3710
3793
|
const w = window;
|
|
3711
3794
|
if (w.__behioAnalytics) return;
|
|
@@ -3944,10 +4027,10 @@ function utmFromSearch(search) {
|
|
|
3944
4027
|
}
|
|
3945
4028
|
|
|
3946
4029
|
// src/react/hooks/use-bundles.ts
|
|
3947
|
-
var
|
|
4030
|
+
var import_react_query40 = require("@tanstack/react-query");
|
|
3948
4031
|
function useBundles(options) {
|
|
3949
4032
|
const { client } = useBehio();
|
|
3950
|
-
return (0,
|
|
4033
|
+
return (0, import_react_query40.useQuery)({
|
|
3951
4034
|
queryKey: ["behio", "bundles"],
|
|
3952
4035
|
queryFn: () => unwrap(client.catalog.getBundles()),
|
|
3953
4036
|
enabled: options?.enabled ?? true,
|
|
@@ -3956,7 +4039,7 @@ function useBundles(options) {
|
|
|
3956
4039
|
}
|
|
3957
4040
|
function useBundle(slug, options) {
|
|
3958
4041
|
const { client } = useBehio();
|
|
3959
|
-
return (0,
|
|
4042
|
+
return (0, import_react_query40.useQuery)({
|
|
3960
4043
|
queryKey: ["behio", "bundle", slug],
|
|
3961
4044
|
queryFn: () => unwrap(client.catalog.getBundle(slug)),
|
|
3962
4045
|
enabled: Boolean(slug) && (options?.enabled ?? true),
|
|
@@ -3965,10 +4048,10 @@ function useBundle(slug, options) {
|
|
|
3965
4048
|
}
|
|
3966
4049
|
|
|
3967
4050
|
// src/react/hooks/use-product-group.ts
|
|
3968
|
-
var
|
|
4051
|
+
var import_react_query41 = require("@tanstack/react-query");
|
|
3969
4052
|
function useProductGroup(slug, options) {
|
|
3970
4053
|
const { client } = useBehio();
|
|
3971
|
-
return (0,
|
|
4054
|
+
return (0, import_react_query41.useQuery)({
|
|
3972
4055
|
queryKey: ["behio", "product-group", slug, options?.locale, options?.currency],
|
|
3973
4056
|
queryFn: () => unwrap(
|
|
3974
4057
|
client.catalog.getProductGroup(slug, {
|
|
@@ -3982,10 +4065,10 @@ function useProductGroup(slug, options) {
|
|
|
3982
4065
|
}
|
|
3983
4066
|
|
|
3984
4067
|
// src/react/hooks/use-cross-sell.ts
|
|
3985
|
-
var
|
|
4068
|
+
var import_react_query42 = require("@tanstack/react-query");
|
|
3986
4069
|
function useCrossSell(productSlug, options) {
|
|
3987
4070
|
const { client } = useBehio();
|
|
3988
|
-
return (0,
|
|
4071
|
+
return (0, import_react_query42.useQuery)({
|
|
3989
4072
|
queryKey: ["behio", "cross-sell", productSlug, options?.locale, options?.currency],
|
|
3990
4073
|
queryFn: () => unwrap(
|
|
3991
4074
|
client.catalog.getCrossSell(productSlug, {
|
|
@@ -3999,10 +4082,10 @@ function useCrossSell(productSlug, options) {
|
|
|
3999
4082
|
}
|
|
4000
4083
|
|
|
4001
4084
|
// src/react/hooks/use-product-promotions.ts
|
|
4002
|
-
var
|
|
4085
|
+
var import_react_query43 = require("@tanstack/react-query");
|
|
4003
4086
|
function useProductPromotions(productSlug, options) {
|
|
4004
4087
|
const { client } = useBehio();
|
|
4005
|
-
return (0,
|
|
4088
|
+
return (0, import_react_query43.useQuery)({
|
|
4006
4089
|
queryKey: ["behio", "product-promotions", productSlug],
|
|
4007
4090
|
queryFn: () => unwrap(client.catalog.getProductPromotions(productSlug)),
|
|
4008
4091
|
enabled: Boolean(productSlug) && (options?.enabled ?? true),
|
|
@@ -4011,11 +4094,11 @@ function useProductPromotions(productSlug, options) {
|
|
|
4011
4094
|
}
|
|
4012
4095
|
|
|
4013
4096
|
// src/react/hooks/use-gift-card.ts
|
|
4014
|
-
var
|
|
4097
|
+
var import_react_query44 = require("@tanstack/react-query");
|
|
4015
4098
|
function useGiftCardBalance(code, options) {
|
|
4016
4099
|
const { client } = useBehio();
|
|
4017
4100
|
const trimmed = code?.trim();
|
|
4018
|
-
return (0,
|
|
4101
|
+
return (0, import_react_query44.useQuery)({
|
|
4019
4102
|
queryKey: ["behio", "gift-card-balance", trimmed],
|
|
4020
4103
|
queryFn: () => unwrap(client.catalog.checkGiftCard(trimmed)),
|
|
4021
4104
|
enabled: Boolean(trimmed && trimmed.length >= 6) && (options?.enabled ?? true)
|
|
@@ -4023,20 +4106,20 @@ function useGiftCardBalance(code, options) {
|
|
|
4023
4106
|
}
|
|
4024
4107
|
|
|
4025
4108
|
// src/react/hooks/use-wishlist.ts
|
|
4026
|
-
var
|
|
4109
|
+
var import_react_query45 = require("@tanstack/react-query");
|
|
4027
4110
|
function useWishlist(options) {
|
|
4028
4111
|
const { client } = useBehio();
|
|
4029
|
-
const qc = (0,
|
|
4030
|
-
const query = (0,
|
|
4112
|
+
const qc = (0, import_react_query45.useQueryClient)();
|
|
4113
|
+
const query = (0, import_react_query45.useQuery)({
|
|
4031
4114
|
queryKey: ["behio", "wishlist"],
|
|
4032
4115
|
queryFn: () => unwrap(client.wishlist.get()),
|
|
4033
4116
|
enabled: options?.enabled ?? true
|
|
4034
4117
|
});
|
|
4035
|
-
const addMutation = (0,
|
|
4118
|
+
const addMutation = (0, import_react_query45.useMutation)({
|
|
4036
4119
|
mutationFn: (productId) => unwrap(client.wishlist.add(productId)),
|
|
4037
4120
|
onSuccess: () => qc.invalidateQueries({ queryKey: ["behio", "wishlist"] })
|
|
4038
4121
|
});
|
|
4039
|
-
const removeMutation = (0,
|
|
4122
|
+
const removeMutation = (0, import_react_query45.useMutation)({
|
|
4040
4123
|
mutationFn: (productId) => unwrap(client.wishlist.remove(productId)),
|
|
4041
4124
|
onSuccess: () => qc.invalidateQueries({ queryKey: ["behio", "wishlist"] })
|
|
4042
4125
|
});
|
|
@@ -4050,7 +4133,7 @@ function useWishlist(options) {
|
|
|
4050
4133
|
}
|
|
4051
4134
|
function useIsInWishlist(productId) {
|
|
4052
4135
|
const { client } = useBehio();
|
|
4053
|
-
return (0,
|
|
4136
|
+
return (0, import_react_query45.useQuery)({
|
|
4054
4137
|
queryKey: ["behio", "wishlist-check", productId],
|
|
4055
4138
|
queryFn: () => unwrap(client.wishlist.isInWishlist(productId)),
|
|
4056
4139
|
enabled: Boolean(productId)
|
|
@@ -4058,10 +4141,10 @@ function useIsInWishlist(productId) {
|
|
|
4058
4141
|
}
|
|
4059
4142
|
|
|
4060
4143
|
// src/react/hooks/use-reviews.ts
|
|
4061
|
-
var
|
|
4144
|
+
var import_react_query46 = require("@tanstack/react-query");
|
|
4062
4145
|
function useProductReviews(productId, options) {
|
|
4063
4146
|
const { client } = useBehio();
|
|
4064
|
-
return (0,
|
|
4147
|
+
return (0, import_react_query46.useQuery)({
|
|
4065
4148
|
queryKey: ["behio", "reviews", productId, options?.page ?? 1],
|
|
4066
4149
|
queryFn: () => unwrap(client.reviews.getProductReviews(productId, options?.page, options?.limit)),
|
|
4067
4150
|
enabled: Boolean(productId) && (options?.enabled ?? true)
|
|
@@ -4069,30 +4152,30 @@ function useProductReviews(productId, options) {
|
|
|
4069
4152
|
}
|
|
4070
4153
|
function useSubmitReview() {
|
|
4071
4154
|
const { client } = useBehio();
|
|
4072
|
-
const qc = (0,
|
|
4073
|
-
return (0,
|
|
4155
|
+
const qc = (0, import_react_query46.useQueryClient)();
|
|
4156
|
+
return (0, import_react_query46.useMutation)({
|
|
4074
4157
|
mutationFn: (input) => unwrap(client.reviews.submit(input)),
|
|
4075
4158
|
onSuccess: (_, input) => qc.invalidateQueries({ queryKey: ["behio", "reviews", input.productId] })
|
|
4076
4159
|
});
|
|
4077
4160
|
}
|
|
4078
4161
|
|
|
4079
4162
|
// src/react/hooks/use-returns.ts
|
|
4080
|
-
var
|
|
4163
|
+
var import_react_query47 = require("@tanstack/react-query");
|
|
4081
4164
|
function useLookupReturnableOrder() {
|
|
4082
4165
|
const { client } = useBehio();
|
|
4083
|
-
return (0,
|
|
4166
|
+
return (0, import_react_query47.useMutation)({
|
|
4084
4167
|
mutationFn: ({ orderNumber, email }) => unwrap(client.returns.lookupOrder(orderNumber, email))
|
|
4085
4168
|
});
|
|
4086
4169
|
}
|
|
4087
4170
|
function useSubmitReturn() {
|
|
4088
4171
|
const { client } = useBehio();
|
|
4089
|
-
return (0,
|
|
4172
|
+
return (0, import_react_query47.useMutation)({
|
|
4090
4173
|
mutationFn: (input) => unwrap(client.returns.submit(input))
|
|
4091
4174
|
});
|
|
4092
4175
|
}
|
|
4093
4176
|
function useReturnStatus(returnId, email) {
|
|
4094
4177
|
const { client } = useBehio();
|
|
4095
|
-
return (0,
|
|
4178
|
+
return (0, import_react_query47.useQuery)({
|
|
4096
4179
|
queryKey: ["behio", "return-status", returnId],
|
|
4097
4180
|
queryFn: () => unwrap(client.returns.getStatus(returnId, email)),
|
|
4098
4181
|
enabled: Boolean(returnId && email)
|
|
@@ -4100,16 +4183,16 @@ function useReturnStatus(returnId, email) {
|
|
|
4100
4183
|
}
|
|
4101
4184
|
|
|
4102
4185
|
// src/react/hooks/use-quotes.ts
|
|
4103
|
-
var
|
|
4186
|
+
var import_react_query48 = require("@tanstack/react-query");
|
|
4104
4187
|
function useSubmitQuote() {
|
|
4105
4188
|
const { client } = useBehio();
|
|
4106
|
-
return (0,
|
|
4189
|
+
return (0, import_react_query48.useMutation)({
|
|
4107
4190
|
mutationFn: (input) => unwrap(client.quotes.submit(input))
|
|
4108
4191
|
});
|
|
4109
4192
|
}
|
|
4110
4193
|
function useQuoteStatus(quoteId, email) {
|
|
4111
4194
|
const { client } = useBehio();
|
|
4112
|
-
return (0,
|
|
4195
|
+
return (0, import_react_query48.useQuery)({
|
|
4113
4196
|
queryKey: ["behio", "quote-status", quoteId],
|
|
4114
4197
|
queryFn: () => unwrap(client.quotes.getStatus(quoteId, email)),
|
|
4115
4198
|
enabled: Boolean(quoteId && email)
|
|
@@ -4117,10 +4200,10 @@ function useQuoteStatus(quoteId, email) {
|
|
|
4117
4200
|
}
|
|
4118
4201
|
|
|
4119
4202
|
// src/react/hooks/use-back-in-stock.ts
|
|
4120
|
-
var
|
|
4203
|
+
var import_react_query49 = require("@tanstack/react-query");
|
|
4121
4204
|
function useNotifyWhenAvailable() {
|
|
4122
4205
|
const { client } = useBehio();
|
|
4123
|
-
return (0,
|
|
4206
|
+
return (0, import_react_query49.useMutation)({
|
|
4124
4207
|
mutationFn: ({ productId, email }) => unwrap(client.catalog.notifyWhenAvailable(productId, email))
|
|
4125
4208
|
});
|
|
4126
4209
|
}
|
|
@@ -4314,5 +4397,6 @@ async function revokeAnalyticsConsent(client) {
|
|
|
4314
4397
|
useSubmitReturn,
|
|
4315
4398
|
useSubmitReview,
|
|
4316
4399
|
useSubscriptions,
|
|
4400
|
+
useVisitorMessages,
|
|
4317
4401
|
useWishlist
|
|
4318
4402
|
});
|