@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.mjs
CHANGED
|
@@ -85,6 +85,11 @@ function toSdkError(err) {
|
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
// src/client.ts
|
|
88
|
+
function isAvailabilityFailure(err) {
|
|
89
|
+
if (err instanceof BehioNetworkError) return true;
|
|
90
|
+
if (err instanceof BehioApiError) return err.isRetryable;
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
88
93
|
var BehioStorefront = class {
|
|
89
94
|
constructor(config) {
|
|
90
95
|
/** Consent-gated persistent visitor id — set by the analytics tracker. */
|
|
@@ -113,6 +118,7 @@ var BehioStorefront = class {
|
|
|
113
118
|
this.retries = config.retries ?? 1;
|
|
114
119
|
this.retryDelay = config.retryDelay ?? 1e3;
|
|
115
120
|
this.visitorIp = config.visitorIp;
|
|
121
|
+
this.throwOnAvailabilityError = config.throwOnAvailabilityError ?? false;
|
|
116
122
|
this.catalog = new CatalogModule(this);
|
|
117
123
|
this.auth = new AuthModule(this);
|
|
118
124
|
this.cart = new CartModule(this);
|
|
@@ -188,6 +194,21 @@ var BehioStorefront = class {
|
|
|
188
194
|
body: input
|
|
189
195
|
});
|
|
190
196
|
}
|
|
197
|
+
/**
|
|
198
|
+
* Visitor messages from merchant automations (storefront.event action).
|
|
199
|
+
* Consent-gated visitor id; each message carries a merchant-defined `name`
|
|
200
|
+
* and free-form `payload` the template reacts to (modal, banner, ...).
|
|
201
|
+
* Messages stay listed until acknowledged via `ackVisitorMessage`.
|
|
202
|
+
*/
|
|
203
|
+
async getVisitorMessages(visitorId) {
|
|
204
|
+
return this.request("GET", "/messages", { query: { visitorId } });
|
|
205
|
+
}
|
|
206
|
+
/** Acknowledge a visitor message so it is not delivered again. */
|
|
207
|
+
async ackVisitorMessage(messageId, visitorId) {
|
|
208
|
+
return this.request("POST", `/messages/${messageId}/ack`, {
|
|
209
|
+
query: { visitorId }
|
|
210
|
+
});
|
|
211
|
+
}
|
|
191
212
|
/** Get basic shop info */
|
|
192
213
|
async getShopInfo() {
|
|
193
214
|
return this.request("GET", "/shop");
|
|
@@ -343,6 +364,9 @@ var BehioStorefront = class {
|
|
|
343
364
|
const data = await this.rawRequest(method, path, options);
|
|
344
365
|
return ok(data);
|
|
345
366
|
} catch (err) {
|
|
367
|
+
if (this.throwOnAvailabilityError && isAvailabilityFailure(err)) {
|
|
368
|
+
throw err;
|
|
369
|
+
}
|
|
346
370
|
return { data: null, error: toSdkError(err) };
|
|
347
371
|
}
|
|
348
372
|
}
|
|
@@ -370,6 +394,9 @@ var BehioStorefront = class {
|
|
|
370
394
|
}
|
|
371
395
|
return ok(await res.blob());
|
|
372
396
|
} catch (err) {
|
|
397
|
+
if (this.throwOnAvailabilityError && isAvailabilityFailure(err)) {
|
|
398
|
+
throw err;
|
|
399
|
+
}
|
|
373
400
|
return { data: null, error: toSdkError(err) };
|
|
374
401
|
}
|
|
375
402
|
}
|
|
@@ -3121,11 +3148,78 @@ function usePersonalOffers(options) {
|
|
|
3121
3148
|
};
|
|
3122
3149
|
}
|
|
3123
3150
|
|
|
3151
|
+
// src/react/hooks/use-visitor-messages.ts
|
|
3152
|
+
import { useCallback as useCallback9, useEffect as useEffect5, useRef as useRef3, useState as useState6 } from "react";
|
|
3153
|
+
import { useQuery as useQuery27, useQueryClient as useQueryClient13 } from "@tanstack/react-query";
|
|
3154
|
+
function useVisitorMessages(options) {
|
|
3155
|
+
const { client } = useBehio();
|
|
3156
|
+
const queryClient = useQueryClient13();
|
|
3157
|
+
const [polledVid, setPolledVid] = useState6(null);
|
|
3158
|
+
const seenRef = useRef3(/* @__PURE__ */ new Set());
|
|
3159
|
+
const explicitVid = options?.visitorId;
|
|
3160
|
+
useEffect5(() => {
|
|
3161
|
+
if (explicitVid) return;
|
|
3162
|
+
const read = () => {
|
|
3163
|
+
const vid = client.getAnalyticsVisitorId();
|
|
3164
|
+
if (vid) setPolledVid(vid);
|
|
3165
|
+
return vid;
|
|
3166
|
+
};
|
|
3167
|
+
if (read()) return;
|
|
3168
|
+
const timer = setInterval(() => {
|
|
3169
|
+
if (read()) clearInterval(timer);
|
|
3170
|
+
}, 3e3);
|
|
3171
|
+
return () => clearInterval(timer);
|
|
3172
|
+
}, [client, explicitVid]);
|
|
3173
|
+
const visitorId = explicitVid ?? polledVid;
|
|
3174
|
+
const pollMs = options?.pollMs ?? 3e4;
|
|
3175
|
+
const queryKey = ["behio", "visitor-messages", visitorId ?? ""];
|
|
3176
|
+
const { data, isLoading, error, refetch } = useQuery27({
|
|
3177
|
+
queryKey,
|
|
3178
|
+
queryFn: () => unwrap(client.getVisitorMessages(visitorId)),
|
|
3179
|
+
enabled: options?.enabled !== false && !!visitorId,
|
|
3180
|
+
refetchInterval: pollMs > 0 ? pollMs : false
|
|
3181
|
+
});
|
|
3182
|
+
const ack = useCallback9(
|
|
3183
|
+
async (messageId) => {
|
|
3184
|
+
if (!visitorId) return false;
|
|
3185
|
+
const result = await unwrap(client.ackVisitorMessage(messageId, visitorId));
|
|
3186
|
+
queryClient.setQueryData(
|
|
3187
|
+
queryKey,
|
|
3188
|
+
(prev) => prev ? { items: prev.items.filter((m) => m.id !== messageId) } : prev
|
|
3189
|
+
);
|
|
3190
|
+
return result.ok;
|
|
3191
|
+
},
|
|
3192
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3193
|
+
[client, visitorId, queryClient]
|
|
3194
|
+
);
|
|
3195
|
+
const onMessage = options?.onMessage;
|
|
3196
|
+
const dispatchDom = options?.dispatchDomEvents !== false;
|
|
3197
|
+
useEffect5(() => {
|
|
3198
|
+
for (const message of data?.items ?? []) {
|
|
3199
|
+
if (seenRef.current.has(message.id)) continue;
|
|
3200
|
+
seenRef.current.add(message.id);
|
|
3201
|
+
if (dispatchDom && typeof window !== "undefined") {
|
|
3202
|
+
window.dispatchEvent(new CustomEvent("behio:visitor-message", { detail: message }));
|
|
3203
|
+
}
|
|
3204
|
+
onMessage?.(message);
|
|
3205
|
+
}
|
|
3206
|
+
}, [data, onMessage, dispatchDom]);
|
|
3207
|
+
return {
|
|
3208
|
+
messages: data?.items ?? [],
|
|
3209
|
+
isLoading,
|
|
3210
|
+
error,
|
|
3211
|
+
refetch,
|
|
3212
|
+
/** Mark a message as shown; it will not be delivered again. */
|
|
3213
|
+
ack,
|
|
3214
|
+
visitorId
|
|
3215
|
+
};
|
|
3216
|
+
}
|
|
3217
|
+
|
|
3124
3218
|
// src/react/hooks/use-analytics-events.ts
|
|
3125
|
-
import { useCallback as
|
|
3219
|
+
import { useCallback as useCallback10 } from "react";
|
|
3126
3220
|
function useAnalyticsEvents() {
|
|
3127
3221
|
const { client } = useBehio();
|
|
3128
|
-
const track =
|
|
3222
|
+
const track = useCallback10(
|
|
3129
3223
|
(events, opts) => {
|
|
3130
3224
|
const list = Array.isArray(events) ? events : [events];
|
|
3131
3225
|
if (list.length === 0) return Promise.resolve();
|
|
@@ -3137,7 +3231,7 @@ function useAnalyticsEvents() {
|
|
|
3137
3231
|
},
|
|
3138
3232
|
[client]
|
|
3139
3233
|
);
|
|
3140
|
-
const trackEvent =
|
|
3234
|
+
const trackEvent = useCallback10(
|
|
3141
3235
|
(name, props) => track({ type: "custom", name, props }),
|
|
3142
3236
|
[track]
|
|
3143
3237
|
);
|
|
@@ -3167,12 +3261,12 @@ function useNewsletterUnsubscribe() {
|
|
|
3167
3261
|
}
|
|
3168
3262
|
|
|
3169
3263
|
// src/react/hooks/use-orders.ts
|
|
3170
|
-
import { useCallback as
|
|
3264
|
+
import { useCallback as useCallback11, useMemo as useMemo3, useState as useState7 } from "react";
|
|
3171
3265
|
import { useInfiniteQuery as useInfiniteQuery2 } from "@tanstack/react-query";
|
|
3172
3266
|
function useOrders(options) {
|
|
3173
3267
|
const { client } = useBehio();
|
|
3174
3268
|
const { page: initialPage, limit, enabled } = options ?? {};
|
|
3175
|
-
const [page, setPage] =
|
|
3269
|
+
const [page, setPage] = useState7(initialPage ?? 1);
|
|
3176
3270
|
const infinite = useInfiniteQuery2({
|
|
3177
3271
|
queryKey: ["behio", "orders", limit, page],
|
|
3178
3272
|
queryFn: ({ pageParam }) => unwrap(client.orders.list({ limit, page: pageParam })),
|
|
@@ -3186,13 +3280,13 @@ function useOrders(options) {
|
|
|
3186
3280
|
[infinite.data]
|
|
3187
3281
|
);
|
|
3188
3282
|
const lastPage = infinite.data?.pages[infinite.data.pages.length - 1];
|
|
3189
|
-
const loadMore =
|
|
3283
|
+
const loadMore = useCallback11(() => {
|
|
3190
3284
|
if (infinite.hasNextPage && !infinite.isFetchingNextPage) {
|
|
3191
3285
|
return infinite.fetchNextPage();
|
|
3192
3286
|
}
|
|
3193
3287
|
return Promise.resolve();
|
|
3194
3288
|
}, [infinite]);
|
|
3195
|
-
const goToPage =
|
|
3289
|
+
const goToPage = useCallback11((newPage) => {
|
|
3196
3290
|
setPage(newPage);
|
|
3197
3291
|
}, []);
|
|
3198
3292
|
return {
|
|
@@ -3218,16 +3312,16 @@ function useOrders(options) {
|
|
|
3218
3312
|
}
|
|
3219
3313
|
|
|
3220
3314
|
// src/react/hooks/use-order.ts
|
|
3221
|
-
import { useCallback as
|
|
3222
|
-
import { useQuery as
|
|
3315
|
+
import { useCallback as useCallback12 } from "react";
|
|
3316
|
+
import { useQuery as useQuery28, useMutation as useMutation12, useQueryClient as useQueryClient14 } from "@tanstack/react-query";
|
|
3223
3317
|
function useOrder(orderNumber, options) {
|
|
3224
3318
|
const { client } = useBehio();
|
|
3225
|
-
const queryClient =
|
|
3319
|
+
const queryClient = useQueryClient14();
|
|
3226
3320
|
const {
|
|
3227
3321
|
data,
|
|
3228
3322
|
isLoading,
|
|
3229
3323
|
error
|
|
3230
|
-
} =
|
|
3324
|
+
} = useQuery28({
|
|
3231
3325
|
queryKey: ["behio", "order", orderNumber],
|
|
3232
3326
|
queryFn: () => unwrap(client.orders.get(orderNumber)),
|
|
3233
3327
|
enabled: options?.enabled !== false && !!orderNumber && !!client.getAccessToken()
|
|
@@ -3239,7 +3333,7 @@ function useOrder(orderNumber, options) {
|
|
|
3239
3333
|
queryClient.invalidateQueries({ queryKey: ["behio", "orders"] });
|
|
3240
3334
|
}
|
|
3241
3335
|
});
|
|
3242
|
-
const cancel =
|
|
3336
|
+
const cancel = useCallback12(
|
|
3243
3337
|
() => cancelMutation.mutateAsync(),
|
|
3244
3338
|
[cancelMutation]
|
|
3245
3339
|
);
|
|
@@ -3253,14 +3347,14 @@ function useOrder(orderNumber, options) {
|
|
|
3253
3347
|
}
|
|
3254
3348
|
|
|
3255
3349
|
// src/react/hooks/use-order-access.ts
|
|
3256
|
-
import { useCallback as
|
|
3350
|
+
import { useCallback as useCallback13, useState as useState8 } from "react";
|
|
3257
3351
|
import { useMutation as useMutation13 } from "@tanstack/react-query";
|
|
3258
3352
|
function useOrderAccess() {
|
|
3259
3353
|
const { client } = useBehio();
|
|
3260
|
-
const [orderNumber, setOrderNumber] =
|
|
3261
|
-
const [email, setEmail] =
|
|
3262
|
-
const [order, setOrder] =
|
|
3263
|
-
const [accessToken, setAccessToken] =
|
|
3354
|
+
const [orderNumber, setOrderNumber] = useState8(null);
|
|
3355
|
+
const [email, setEmail] = useState8(null);
|
|
3356
|
+
const [order, setOrder] = useState8(null);
|
|
3357
|
+
const [accessToken, setAccessToken] = useState8(null);
|
|
3264
3358
|
const requestMutation = useMutation13({
|
|
3265
3359
|
mutationFn: (input) => unwrap(client.orders.requestAccessCode(input.orderNumber, input.email)),
|
|
3266
3360
|
onSuccess: (_data, input) => {
|
|
@@ -3280,12 +3374,12 @@ function useOrderAccess() {
|
|
|
3280
3374
|
setAccessToken(result.accessToken);
|
|
3281
3375
|
}
|
|
3282
3376
|
});
|
|
3283
|
-
const requestCode =
|
|
3377
|
+
const requestCode = useCallback13(
|
|
3284
3378
|
(on, em) => requestMutation.mutateAsync({ orderNumber: on, email: em }),
|
|
3285
3379
|
[requestMutation]
|
|
3286
3380
|
);
|
|
3287
|
-
const verifyCode =
|
|
3288
|
-
const reset =
|
|
3381
|
+
const verifyCode = useCallback13((code) => verifyMutation.mutateAsync(code), [verifyMutation]);
|
|
3382
|
+
const reset = useCallback13(() => {
|
|
3289
3383
|
setOrderNumber(null);
|
|
3290
3384
|
setEmail(null);
|
|
3291
3385
|
setOrder(null);
|
|
@@ -3313,12 +3407,12 @@ function useOrderAccess() {
|
|
|
3313
3407
|
}
|
|
3314
3408
|
|
|
3315
3409
|
// src/react/hooks/use-checkout.ts
|
|
3316
|
-
import { useState as
|
|
3317
|
-
import { useMutation as useMutation14, useQueryClient as
|
|
3410
|
+
import { useState as useState9, useCallback as useCallback14 } from "react";
|
|
3411
|
+
import { useMutation as useMutation14, useQueryClient as useQueryClient15 } from "@tanstack/react-query";
|
|
3318
3412
|
function useCheckout() {
|
|
3319
3413
|
const { client, storage } = useBehio();
|
|
3320
|
-
const queryClient =
|
|
3321
|
-
const [order, setOrder] =
|
|
3414
|
+
const queryClient = useQueryClient15();
|
|
3415
|
+
const [order, setOrder] = useState9(null);
|
|
3322
3416
|
const mutation = useMutation14({
|
|
3323
3417
|
mutationFn: (input) => unwrap(client.checkout.createOrder(input)),
|
|
3324
3418
|
onSuccess: (result) => {
|
|
@@ -3328,11 +3422,11 @@ function useCheckout() {
|
|
|
3328
3422
|
queryClient.invalidateQueries({ queryKey: ["behio", "orders"] });
|
|
3329
3423
|
}
|
|
3330
3424
|
});
|
|
3331
|
-
const createOrder =
|
|
3425
|
+
const createOrder = useCallback14(
|
|
3332
3426
|
(input) => mutation.mutateAsync(input),
|
|
3333
3427
|
[mutation]
|
|
3334
3428
|
);
|
|
3335
|
-
const reset =
|
|
3429
|
+
const reset = useCallback14(() => {
|
|
3336
3430
|
setOrder(null);
|
|
3337
3431
|
mutation.reset();
|
|
3338
3432
|
}, [mutation]);
|
|
@@ -3346,10 +3440,10 @@ function useCheckout() {
|
|
|
3346
3440
|
}
|
|
3347
3441
|
|
|
3348
3442
|
// src/react/hooks/use-pages.ts
|
|
3349
|
-
import { useQuery as
|
|
3443
|
+
import { useQuery as useQuery29 } from "@tanstack/react-query";
|
|
3350
3444
|
function usePages(locale, options) {
|
|
3351
3445
|
const { client } = useBehio();
|
|
3352
|
-
return
|
|
3446
|
+
return useQuery29({
|
|
3353
3447
|
queryKey: ["behio", "pages", locale],
|
|
3354
3448
|
queryFn: async () => {
|
|
3355
3449
|
const result = await unwrap(client.pages.list(locale));
|
|
@@ -3360,7 +3454,7 @@ function usePages(locale, options) {
|
|
|
3360
3454
|
}
|
|
3361
3455
|
function usePage(slug, locale, options) {
|
|
3362
3456
|
const { client } = useBehio();
|
|
3363
|
-
return
|
|
3457
|
+
return useQuery29({
|
|
3364
3458
|
queryKey: ["behio", "page", slug, locale],
|
|
3365
3459
|
queryFn: () => unwrap(client.pages.get(slug, locale)),
|
|
3366
3460
|
enabled: options?.enabled !== false && !!slug
|
|
@@ -3368,10 +3462,10 @@ function usePage(slug, locale, options) {
|
|
|
3368
3462
|
}
|
|
3369
3463
|
|
|
3370
3464
|
// src/react/hooks/use-shop-info.ts
|
|
3371
|
-
import { useQuery as
|
|
3465
|
+
import { useQuery as useQuery30 } from "@tanstack/react-query";
|
|
3372
3466
|
function useShopInfo(options) {
|
|
3373
3467
|
const { client } = useBehio();
|
|
3374
|
-
return
|
|
3468
|
+
return useQuery30({
|
|
3375
3469
|
queryKey: ["behio", "shop-info"],
|
|
3376
3470
|
queryFn: () => unwrap(client.getShopInfo()),
|
|
3377
3471
|
enabled: options?.enabled !== false
|
|
@@ -3379,10 +3473,10 @@ function useShopInfo(options) {
|
|
|
3379
3473
|
}
|
|
3380
3474
|
|
|
3381
3475
|
// src/react/hooks/use-shop-scripts.ts
|
|
3382
|
-
import { useQuery as
|
|
3476
|
+
import { useQuery as useQuery31 } from "@tanstack/react-query";
|
|
3383
3477
|
function useShopScripts(options) {
|
|
3384
3478
|
const { client } = useBehio();
|
|
3385
|
-
return
|
|
3479
|
+
return useQuery31({
|
|
3386
3480
|
queryKey: ["behio", "shop-scripts"],
|
|
3387
3481
|
queryFn: () => unwrap(client.getShopScripts()),
|
|
3388
3482
|
enabled: options?.enabled !== false
|
|
@@ -3390,11 +3484,11 @@ function useShopScripts(options) {
|
|
|
3390
3484
|
}
|
|
3391
3485
|
|
|
3392
3486
|
// src/react/hooks/use-shop-seo.ts
|
|
3393
|
-
import { useQuery as
|
|
3487
|
+
import { useQuery as useQuery32 } from "@tanstack/react-query";
|
|
3394
3488
|
function useShopSeo(options) {
|
|
3395
3489
|
const { client } = useBehio();
|
|
3396
3490
|
const { locale, initialData, enabled = true } = options ?? {};
|
|
3397
|
-
return
|
|
3491
|
+
return useQuery32({
|
|
3398
3492
|
queryKey: ["behio", "shop-seo", locale ?? "_default"],
|
|
3399
3493
|
queryFn: () => unwrap(client.getShopSeo(locale)),
|
|
3400
3494
|
initialData,
|
|
@@ -3454,14 +3548,14 @@ function CurrencySwitcher({
|
|
|
3454
3548
|
}
|
|
3455
3549
|
|
|
3456
3550
|
// src/react/components/storefront-scripts.tsx
|
|
3457
|
-
import { useEffect as
|
|
3551
|
+
import { useEffect as useEffect6, useMemo as useMemo4, useState as useState10 } from "react";
|
|
3458
3552
|
|
|
3459
3553
|
// src/react/hooks/use-consent.ts
|
|
3460
|
-
import { useQuery as
|
|
3554
|
+
import { useQuery as useQuery33, useMutation as useMutation15, useQueryClient as useQueryClient16 } from "@tanstack/react-query";
|
|
3461
3555
|
function useCookieConsent(visitorId) {
|
|
3462
3556
|
const { client } = useBehio();
|
|
3463
|
-
const qc =
|
|
3464
|
-
const query =
|
|
3557
|
+
const qc = useQueryClient16();
|
|
3558
|
+
const query = useQuery33({
|
|
3465
3559
|
queryKey: ["behio", "consent", visitorId],
|
|
3466
3560
|
queryFn: () => unwrap(client.consent.get(visitorId)),
|
|
3467
3561
|
enabled: Boolean(visitorId)
|
|
@@ -3544,8 +3638,8 @@ function injectHtml(target, html) {
|
|
|
3544
3638
|
}
|
|
3545
3639
|
function StorefrontScripts({ visitorId: visitorIdProp } = {}) {
|
|
3546
3640
|
const { data } = useShopScripts();
|
|
3547
|
-
const [visitorId, setVisitorId] =
|
|
3548
|
-
|
|
3641
|
+
const [visitorId, setVisitorId] = useState10(visitorIdProp ?? "");
|
|
3642
|
+
useEffect6(() => {
|
|
3549
3643
|
if (visitorIdProp) return;
|
|
3550
3644
|
try {
|
|
3551
3645
|
const v = localStorage.getItem(VISITOR_KEY);
|
|
@@ -3563,7 +3657,7 @@ function StorefrontScripts({ visitorId: visitorIdProp } = {}) {
|
|
|
3563
3657
|
() => JSON.stringify(scripts.map((s) => [s.id, s.type, s.placement, s.value])),
|
|
3564
3658
|
[scripts]
|
|
3565
3659
|
);
|
|
3566
|
-
|
|
3660
|
+
useEffect6(() => {
|
|
3567
3661
|
if (typeof document === "undefined") return;
|
|
3568
3662
|
const added = [];
|
|
3569
3663
|
for (const s of scripts) {
|
|
@@ -3580,7 +3674,7 @@ function StorefrontScripts({ visitorId: visitorIdProp } = {}) {
|
|
|
3580
3674
|
}
|
|
3581
3675
|
|
|
3582
3676
|
// src/react/components/behio-analytics.tsx
|
|
3583
|
-
import { useEffect as
|
|
3677
|
+
import { useEffect as useEffect7 } from "react";
|
|
3584
3678
|
|
|
3585
3679
|
// src/react/hooks/use-behio-client.ts
|
|
3586
3680
|
function useBehioClient() {
|
|
@@ -3590,7 +3684,7 @@ function useBehioClient() {
|
|
|
3590
3684
|
// src/react/components/behio-analytics.tsx
|
|
3591
3685
|
function BehioAnalyticsTracker() {
|
|
3592
3686
|
const client = useBehioClient();
|
|
3593
|
-
|
|
3687
|
+
useEffect7(() => {
|
|
3594
3688
|
if (typeof window === "undefined") return;
|
|
3595
3689
|
const w = window;
|
|
3596
3690
|
if (w.__behioAnalytics) return;
|
|
@@ -3829,10 +3923,10 @@ function utmFromSearch(search) {
|
|
|
3829
3923
|
}
|
|
3830
3924
|
|
|
3831
3925
|
// src/react/hooks/use-bundles.ts
|
|
3832
|
-
import { useQuery as
|
|
3926
|
+
import { useQuery as useQuery34 } from "@tanstack/react-query";
|
|
3833
3927
|
function useBundles(options) {
|
|
3834
3928
|
const { client } = useBehio();
|
|
3835
|
-
return
|
|
3929
|
+
return useQuery34({
|
|
3836
3930
|
queryKey: ["behio", "bundles"],
|
|
3837
3931
|
queryFn: () => unwrap(client.catalog.getBundles()),
|
|
3838
3932
|
enabled: options?.enabled ?? true,
|
|
@@ -3841,7 +3935,7 @@ function useBundles(options) {
|
|
|
3841
3935
|
}
|
|
3842
3936
|
function useBundle(slug, options) {
|
|
3843
3937
|
const { client } = useBehio();
|
|
3844
|
-
return
|
|
3938
|
+
return useQuery34({
|
|
3845
3939
|
queryKey: ["behio", "bundle", slug],
|
|
3846
3940
|
queryFn: () => unwrap(client.catalog.getBundle(slug)),
|
|
3847
3941
|
enabled: Boolean(slug) && (options?.enabled ?? true),
|
|
@@ -3850,10 +3944,10 @@ function useBundle(slug, options) {
|
|
|
3850
3944
|
}
|
|
3851
3945
|
|
|
3852
3946
|
// src/react/hooks/use-product-group.ts
|
|
3853
|
-
import { useQuery as
|
|
3947
|
+
import { useQuery as useQuery35 } from "@tanstack/react-query";
|
|
3854
3948
|
function useProductGroup(slug, options) {
|
|
3855
3949
|
const { client } = useBehio();
|
|
3856
|
-
return
|
|
3950
|
+
return useQuery35({
|
|
3857
3951
|
queryKey: ["behio", "product-group", slug, options?.locale, options?.currency],
|
|
3858
3952
|
queryFn: () => unwrap(
|
|
3859
3953
|
client.catalog.getProductGroup(slug, {
|
|
@@ -3867,10 +3961,10 @@ function useProductGroup(slug, options) {
|
|
|
3867
3961
|
}
|
|
3868
3962
|
|
|
3869
3963
|
// src/react/hooks/use-cross-sell.ts
|
|
3870
|
-
import { useQuery as
|
|
3964
|
+
import { useQuery as useQuery36 } from "@tanstack/react-query";
|
|
3871
3965
|
function useCrossSell(productSlug, options) {
|
|
3872
3966
|
const { client } = useBehio();
|
|
3873
|
-
return
|
|
3967
|
+
return useQuery36({
|
|
3874
3968
|
queryKey: ["behio", "cross-sell", productSlug, options?.locale, options?.currency],
|
|
3875
3969
|
queryFn: () => unwrap(
|
|
3876
3970
|
client.catalog.getCrossSell(productSlug, {
|
|
@@ -3884,10 +3978,10 @@ function useCrossSell(productSlug, options) {
|
|
|
3884
3978
|
}
|
|
3885
3979
|
|
|
3886
3980
|
// src/react/hooks/use-product-promotions.ts
|
|
3887
|
-
import { useQuery as
|
|
3981
|
+
import { useQuery as useQuery37 } from "@tanstack/react-query";
|
|
3888
3982
|
function useProductPromotions(productSlug, options) {
|
|
3889
3983
|
const { client } = useBehio();
|
|
3890
|
-
return
|
|
3984
|
+
return useQuery37({
|
|
3891
3985
|
queryKey: ["behio", "product-promotions", productSlug],
|
|
3892
3986
|
queryFn: () => unwrap(client.catalog.getProductPromotions(productSlug)),
|
|
3893
3987
|
enabled: Boolean(productSlug) && (options?.enabled ?? true),
|
|
@@ -3896,11 +3990,11 @@ function useProductPromotions(productSlug, options) {
|
|
|
3896
3990
|
}
|
|
3897
3991
|
|
|
3898
3992
|
// src/react/hooks/use-gift-card.ts
|
|
3899
|
-
import { useQuery as
|
|
3993
|
+
import { useQuery as useQuery38 } from "@tanstack/react-query";
|
|
3900
3994
|
function useGiftCardBalance(code, options) {
|
|
3901
3995
|
const { client } = useBehio();
|
|
3902
3996
|
const trimmed = code?.trim();
|
|
3903
|
-
return
|
|
3997
|
+
return useQuery38({
|
|
3904
3998
|
queryKey: ["behio", "gift-card-balance", trimmed],
|
|
3905
3999
|
queryFn: () => unwrap(client.catalog.checkGiftCard(trimmed)),
|
|
3906
4000
|
enabled: Boolean(trimmed && trimmed.length >= 6) && (options?.enabled ?? true)
|
|
@@ -3908,11 +4002,11 @@ function useGiftCardBalance(code, options) {
|
|
|
3908
4002
|
}
|
|
3909
4003
|
|
|
3910
4004
|
// src/react/hooks/use-wishlist.ts
|
|
3911
|
-
import { useQuery as
|
|
4005
|
+
import { useQuery as useQuery39, useMutation as useMutation16, useQueryClient as useQueryClient17 } from "@tanstack/react-query";
|
|
3912
4006
|
function useWishlist(options) {
|
|
3913
4007
|
const { client } = useBehio();
|
|
3914
|
-
const qc =
|
|
3915
|
-
const query =
|
|
4008
|
+
const qc = useQueryClient17();
|
|
4009
|
+
const query = useQuery39({
|
|
3916
4010
|
queryKey: ["behio", "wishlist"],
|
|
3917
4011
|
queryFn: () => unwrap(client.wishlist.get()),
|
|
3918
4012
|
enabled: options?.enabled ?? true
|
|
@@ -3935,7 +4029,7 @@ function useWishlist(options) {
|
|
|
3935
4029
|
}
|
|
3936
4030
|
function useIsInWishlist(productId) {
|
|
3937
4031
|
const { client } = useBehio();
|
|
3938
|
-
return
|
|
4032
|
+
return useQuery39({
|
|
3939
4033
|
queryKey: ["behio", "wishlist-check", productId],
|
|
3940
4034
|
queryFn: () => unwrap(client.wishlist.isInWishlist(productId)),
|
|
3941
4035
|
enabled: Boolean(productId)
|
|
@@ -3943,10 +4037,10 @@ function useIsInWishlist(productId) {
|
|
|
3943
4037
|
}
|
|
3944
4038
|
|
|
3945
4039
|
// src/react/hooks/use-reviews.ts
|
|
3946
|
-
import { useQuery as
|
|
4040
|
+
import { useQuery as useQuery40, useMutation as useMutation17, useQueryClient as useQueryClient18 } from "@tanstack/react-query";
|
|
3947
4041
|
function useProductReviews(productId, options) {
|
|
3948
4042
|
const { client } = useBehio();
|
|
3949
|
-
return
|
|
4043
|
+
return useQuery40({
|
|
3950
4044
|
queryKey: ["behio", "reviews", productId, options?.page ?? 1],
|
|
3951
4045
|
queryFn: () => unwrap(client.reviews.getProductReviews(productId, options?.page, options?.limit)),
|
|
3952
4046
|
enabled: Boolean(productId) && (options?.enabled ?? true)
|
|
@@ -3954,7 +4048,7 @@ function useProductReviews(productId, options) {
|
|
|
3954
4048
|
}
|
|
3955
4049
|
function useSubmitReview() {
|
|
3956
4050
|
const { client } = useBehio();
|
|
3957
|
-
const qc =
|
|
4051
|
+
const qc = useQueryClient18();
|
|
3958
4052
|
return useMutation17({
|
|
3959
4053
|
mutationFn: (input) => unwrap(client.reviews.submit(input)),
|
|
3960
4054
|
onSuccess: (_, input) => qc.invalidateQueries({ queryKey: ["behio", "reviews", input.productId] })
|
|
@@ -3962,7 +4056,7 @@ function useSubmitReview() {
|
|
|
3962
4056
|
}
|
|
3963
4057
|
|
|
3964
4058
|
// src/react/hooks/use-returns.ts
|
|
3965
|
-
import { useQuery as
|
|
4059
|
+
import { useQuery as useQuery41, useMutation as useMutation18 } from "@tanstack/react-query";
|
|
3966
4060
|
function useLookupReturnableOrder() {
|
|
3967
4061
|
const { client } = useBehio();
|
|
3968
4062
|
return useMutation18({
|
|
@@ -3977,7 +4071,7 @@ function useSubmitReturn() {
|
|
|
3977
4071
|
}
|
|
3978
4072
|
function useReturnStatus(returnId, email) {
|
|
3979
4073
|
const { client } = useBehio();
|
|
3980
|
-
return
|
|
4074
|
+
return useQuery41({
|
|
3981
4075
|
queryKey: ["behio", "return-status", returnId],
|
|
3982
4076
|
queryFn: () => unwrap(client.returns.getStatus(returnId, email)),
|
|
3983
4077
|
enabled: Boolean(returnId && email)
|
|
@@ -3985,7 +4079,7 @@ function useReturnStatus(returnId, email) {
|
|
|
3985
4079
|
}
|
|
3986
4080
|
|
|
3987
4081
|
// src/react/hooks/use-quotes.ts
|
|
3988
|
-
import { useMutation as useMutation19, useQuery as
|
|
4082
|
+
import { useMutation as useMutation19, useQuery as useQuery42 } from "@tanstack/react-query";
|
|
3989
4083
|
function useSubmitQuote() {
|
|
3990
4084
|
const { client } = useBehio();
|
|
3991
4085
|
return useMutation19({
|
|
@@ -3994,7 +4088,7 @@ function useSubmitQuote() {
|
|
|
3994
4088
|
}
|
|
3995
4089
|
function useQuoteStatus(quoteId, email) {
|
|
3996
4090
|
const { client } = useBehio();
|
|
3997
|
-
return
|
|
4091
|
+
return useQuery42({
|
|
3998
4092
|
queryKey: ["behio", "quote-status", quoteId],
|
|
3999
4093
|
queryFn: () => unwrap(client.quotes.getStatus(quoteId, email)),
|
|
4000
4094
|
enabled: Boolean(quoteId && email)
|
|
@@ -4198,5 +4292,6 @@ export {
|
|
|
4198
4292
|
useSubmitReturn,
|
|
4199
4293
|
useSubmitReview,
|
|
4200
4294
|
useSubscriptions,
|
|
4295
|
+
useVisitorMessages,
|
|
4201
4296
|
useWishlist
|
|
4202
4297
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@behio/storefront-sdk",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "TypeScript SDK for Behio Headless E-Shop
|
|
3
|
+
"version": "1.9.0",
|
|
4
|
+
"description": "TypeScript SDK for Behio Headless E-Shop \u2014 core client + React hooks",
|
|
5
5
|
"author": "Behio",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "./dist/index.js",
|