@behio/storefront-sdk 0.31.1 → 0.33.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-O7HDB5R4.mjs → chunk-5KJDVDUM.mjs} +78 -0
- package/dist/{chunk-NG46DR3A.js → chunk-Y4ZCK5HD.js} +78 -0
- package/dist/{client-D1GZSa-N.d.mts → client-BQlF_Vn9.d.mts} +377 -6
- package/dist/{client-D1GZSa-N.d.ts → client-BQlF_Vn9.d.ts} +377 -6
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- 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 +171 -3
- package/dist/react.d.ts +171 -3
- package/dist/react.js +240 -45
- package/dist/react.mjs +279 -84
- package/package.json +3 -3
package/dist/react.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
} from "./chunk-ZOZAJG6T.mjs";
|
|
5
5
|
import {
|
|
6
6
|
BehioStorefront
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-5KJDVDUM.mjs";
|
|
8
8
|
|
|
9
9
|
// src/react/provider.tsx
|
|
10
10
|
import { useRef, useEffect, useMemo, useState, useCallback } from "react";
|
|
@@ -885,12 +885,50 @@ function useLoyalty(options) {
|
|
|
885
885
|
return { loyalty: data, isLoading, error, refetch };
|
|
886
886
|
}
|
|
887
887
|
|
|
888
|
+
// src/react/hooks/use-subscriptions.ts
|
|
889
|
+
import { useQuery as useQuery15, useMutation as useMutation5, useQueryClient as useQueryClient7 } from "@tanstack/react-query";
|
|
890
|
+
var SUBSCRIPTIONS_KEY = ["behio", "subscriptions"];
|
|
891
|
+
function useSubscriptions(options) {
|
|
892
|
+
const { client } = useBehio();
|
|
893
|
+
const qc = useQueryClient7();
|
|
894
|
+
const query = useQuery15({
|
|
895
|
+
queryKey: [...SUBSCRIPTIONS_KEY],
|
|
896
|
+
queryFn: () => unwrap(client.subscriptions.list()),
|
|
897
|
+
enabled: options?.enabled !== false && !!client.getAccessToken()
|
|
898
|
+
});
|
|
899
|
+
const invalidate = () => qc.invalidateQueries({ queryKey: [...SUBSCRIPTIONS_KEY] });
|
|
900
|
+
const pauseMutation = useMutation5({
|
|
901
|
+
mutationFn: (subscriptionId) => unwrap(client.subscriptions.pause(subscriptionId)),
|
|
902
|
+
onSuccess: invalidate
|
|
903
|
+
});
|
|
904
|
+
const resumeMutation = useMutation5({
|
|
905
|
+
mutationFn: (subscriptionId) => unwrap(client.subscriptions.resume(subscriptionId)),
|
|
906
|
+
onSuccess: invalidate
|
|
907
|
+
});
|
|
908
|
+
const cancelMutation = useMutation5({
|
|
909
|
+
mutationFn: (subscriptionId) => unwrap(client.subscriptions.cancel(subscriptionId)),
|
|
910
|
+
onSuccess: invalidate
|
|
911
|
+
});
|
|
912
|
+
return {
|
|
913
|
+
subscriptions: query.data?.items ?? [],
|
|
914
|
+
isLoading: query.isLoading,
|
|
915
|
+
error: query.error,
|
|
916
|
+
refetch: query.refetch,
|
|
917
|
+
pause: pauseMutation.mutateAsync,
|
|
918
|
+
resume: resumeMutation.mutateAsync,
|
|
919
|
+
cancel: cancelMutation.mutateAsync,
|
|
920
|
+
isPausing: pauseMutation.isPending,
|
|
921
|
+
isResuming: resumeMutation.isPending,
|
|
922
|
+
isCancelling: cancelMutation.isPending
|
|
923
|
+
};
|
|
924
|
+
}
|
|
925
|
+
|
|
888
926
|
// src/react/hooks/use-pickup-points.ts
|
|
889
|
-
import { useQuery as
|
|
927
|
+
import { useQuery as useQuery16 } from "@tanstack/react-query";
|
|
890
928
|
function usePickupPoints(input) {
|
|
891
929
|
const { client } = useBehio();
|
|
892
930
|
const { methodId, query, country, limit, enabled } = input;
|
|
893
|
-
const { data, isLoading, error, refetch } =
|
|
931
|
+
const { data, isLoading, error, refetch } = useQuery16({
|
|
894
932
|
queryKey: ["behio", "pickup-points", methodId, query ?? "", country ?? "", limit ?? 30],
|
|
895
933
|
queryFn: () => unwrap(
|
|
896
934
|
client.shipping.getPickupPoints({
|
|
@@ -905,28 +943,179 @@ function usePickupPoints(input) {
|
|
|
905
943
|
return { pickupPoints: data?.items ?? [], isLoading, error, refetch };
|
|
906
944
|
}
|
|
907
945
|
|
|
946
|
+
// src/react/hooks/use-shipping-methods.ts
|
|
947
|
+
import { useQuery as useQuery17 } from "@tanstack/react-query";
|
|
948
|
+
function useShippingMethods(options) {
|
|
949
|
+
const { client, currency: activeCurrency } = useBehio();
|
|
950
|
+
const currency = options?.currency ?? activeCurrency;
|
|
951
|
+
const { country, cartTotal, cartWeightKg } = options ?? {};
|
|
952
|
+
const { data, isLoading, error, refetch } = useQuery17({
|
|
953
|
+
queryKey: [
|
|
954
|
+
"behio",
|
|
955
|
+
"shipping-methods",
|
|
956
|
+
currency ?? "",
|
|
957
|
+
country ?? "",
|
|
958
|
+
cartTotal ?? "",
|
|
959
|
+
cartWeightKg ?? ""
|
|
960
|
+
],
|
|
961
|
+
queryFn: () => unwrap(client.shipping.listMethods({ currency, country, cartTotal, cartWeightKg })),
|
|
962
|
+
enabled: options?.enabled !== false
|
|
963
|
+
});
|
|
964
|
+
return { methods: data?.items ?? [], isLoading, error, refetch };
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
// src/react/hooks/use-shipping-quote.ts
|
|
968
|
+
import { useQuery as useQuery18 } from "@tanstack/react-query";
|
|
969
|
+
function useShippingQuote(options) {
|
|
970
|
+
const { client, currency: activeCurrency } = useBehio();
|
|
971
|
+
const { destinationAddress, items, cartTotal, enabled } = options ?? {};
|
|
972
|
+
const currency = options?.currency ?? activeCurrency;
|
|
973
|
+
const { data, isLoading, error, refetch } = useQuery18({
|
|
974
|
+
queryKey: [
|
|
975
|
+
"behio",
|
|
976
|
+
"shipping-quote",
|
|
977
|
+
JSON.stringify(destinationAddress ?? null),
|
|
978
|
+
JSON.stringify(items ?? null),
|
|
979
|
+
cartTotal ?? "",
|
|
980
|
+
currency ?? ""
|
|
981
|
+
],
|
|
982
|
+
queryFn: () => unwrap(
|
|
983
|
+
client.shipping.quote({
|
|
984
|
+
destinationAddress,
|
|
985
|
+
items,
|
|
986
|
+
cartTotal,
|
|
987
|
+
currency
|
|
988
|
+
})
|
|
989
|
+
),
|
|
990
|
+
enabled: enabled !== false && !!destinationAddress?.country
|
|
991
|
+
});
|
|
992
|
+
return { quotes: data?.items ?? [], isLoading, error, refetch };
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
// src/react/hooks/use-payment-methods.ts
|
|
996
|
+
import { useQuery as useQuery19 } from "@tanstack/react-query";
|
|
997
|
+
function usePaymentMethods(options) {
|
|
998
|
+
const { client, currency: activeCurrency } = useBehio();
|
|
999
|
+
const currency = options?.currency ?? activeCurrency;
|
|
1000
|
+
const { data, isLoading, error, refetch } = useQuery19({
|
|
1001
|
+
queryKey: ["behio", "payment-methods", currency ?? ""],
|
|
1002
|
+
queryFn: () => unwrap(client.catalog.listPaymentMethods({ currency })),
|
|
1003
|
+
enabled: options?.enabled !== false
|
|
1004
|
+
});
|
|
1005
|
+
return { methods: data?.items ?? [], isLoading, error, refetch };
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
// src/react/hooks/use-personal-offers.ts
|
|
1009
|
+
import { useCallback as useCallback8, useEffect as useEffect4, useState as useState5 } from "react";
|
|
1010
|
+
import { useMutation as useMutation6, useQuery as useQuery20, useQueryClient as useQueryClient8 } from "@tanstack/react-query";
|
|
1011
|
+
function usePersonalOffers(options) {
|
|
1012
|
+
const { client } = useBehio();
|
|
1013
|
+
const queryClient = useQueryClient8();
|
|
1014
|
+
const [polledVid, setPolledVid] = useState5(null);
|
|
1015
|
+
const explicitVid = options?.visitorId;
|
|
1016
|
+
useEffect4(() => {
|
|
1017
|
+
if (explicitVid) return;
|
|
1018
|
+
const read = () => {
|
|
1019
|
+
const vid = client.getAnalyticsVisitorId();
|
|
1020
|
+
if (vid) setPolledVid(vid);
|
|
1021
|
+
return vid;
|
|
1022
|
+
};
|
|
1023
|
+
if (read()) return;
|
|
1024
|
+
const timer = setInterval(() => {
|
|
1025
|
+
if (read()) clearInterval(timer);
|
|
1026
|
+
}, 3e3);
|
|
1027
|
+
return () => clearInterval(timer);
|
|
1028
|
+
}, [client, explicitVid]);
|
|
1029
|
+
const visitorId = explicitVid ?? polledVid;
|
|
1030
|
+
const queryKey = ["behio", "personal-offers", visitorId ?? ""];
|
|
1031
|
+
const { data, isLoading, error, refetch } = useQuery20({
|
|
1032
|
+
queryKey,
|
|
1033
|
+
queryFn: () => unwrap(client.getPersonalOffers(visitorId)),
|
|
1034
|
+
enabled: options?.enabled !== false && !!visitorId
|
|
1035
|
+
});
|
|
1036
|
+
const claimMutation = useMutation6({
|
|
1037
|
+
mutationFn: ({ offerId, email }) => unwrap(client.claimOfferByEmail(offerId, { visitorId, email })),
|
|
1038
|
+
onSuccess: (result, { offerId }) => {
|
|
1039
|
+
queryClient.setQueryData(
|
|
1040
|
+
queryKey,
|
|
1041
|
+
(prev) => prev ? {
|
|
1042
|
+
items: prev.items.map(
|
|
1043
|
+
(o) => o.id === offerId ? { ...o, code: result.code, status: "CLAIMED" } : o
|
|
1044
|
+
)
|
|
1045
|
+
} : prev
|
|
1046
|
+
);
|
|
1047
|
+
}
|
|
1048
|
+
});
|
|
1049
|
+
const claimByEmail = useCallback8(
|
|
1050
|
+
(offerId, email) => claimMutation.mutateAsync({ offerId, email }),
|
|
1051
|
+
[claimMutation]
|
|
1052
|
+
);
|
|
1053
|
+
return {
|
|
1054
|
+
offers: data?.items ?? [],
|
|
1055
|
+
/** Resolved consent-gated visitor id (null before consent). */
|
|
1056
|
+
visitorId: visitorId ?? null,
|
|
1057
|
+
isLoading,
|
|
1058
|
+
error,
|
|
1059
|
+
refetch,
|
|
1060
|
+
/** E-mail gate: trade an e-mail for the discount code of the given offer. */
|
|
1061
|
+
claimByEmail,
|
|
1062
|
+
isClaiming: claimMutation.isPending,
|
|
1063
|
+
claimError: claimMutation.error
|
|
1064
|
+
};
|
|
1065
|
+
}
|
|
1066
|
+
|
|
1067
|
+
// src/react/hooks/use-analytics-events.ts
|
|
1068
|
+
import { useCallback as useCallback9 } from "react";
|
|
1069
|
+
function useAnalyticsEvents() {
|
|
1070
|
+
const { client } = useBehio();
|
|
1071
|
+
const track = useCallback9(
|
|
1072
|
+
(events, opts) => {
|
|
1073
|
+
const list = Array.isArray(events) ? events : [events];
|
|
1074
|
+
if (list.length === 0) return Promise.resolve();
|
|
1075
|
+
return client.sendAnalyticsEvents({
|
|
1076
|
+
sessionId: opts?.sessionId,
|
|
1077
|
+
visitorId: client.getAnalyticsVisitorId() ?? void 0,
|
|
1078
|
+
events: list.map((e) => ({ ts: Date.now(), ...e }))
|
|
1079
|
+
});
|
|
1080
|
+
},
|
|
1081
|
+
[client]
|
|
1082
|
+
);
|
|
1083
|
+
const trackEvent = useCallback9(
|
|
1084
|
+
(name, props) => track({ type: "custom", name, props }),
|
|
1085
|
+
[track]
|
|
1086
|
+
);
|
|
1087
|
+
return {
|
|
1088
|
+
/** Send one or more raw analytics events. */
|
|
1089
|
+
track,
|
|
1090
|
+
/** Convenience: send a named `custom` event with optional props. */
|
|
1091
|
+
trackEvent,
|
|
1092
|
+
/** Consent-gated visitor id, null before analytics consent. */
|
|
1093
|
+
getVisitorId: () => client.getAnalyticsVisitorId()
|
|
1094
|
+
};
|
|
1095
|
+
}
|
|
1096
|
+
|
|
908
1097
|
// src/react/hooks/use-newsletter.ts
|
|
909
|
-
import { useMutation as
|
|
1098
|
+
import { useMutation as useMutation7 } from "@tanstack/react-query";
|
|
910
1099
|
function useNewsletterSubscribe() {
|
|
911
1100
|
const { client } = useBehio();
|
|
912
|
-
return
|
|
1101
|
+
return useMutation7({
|
|
913
1102
|
mutationFn: (input) => unwrap(client.newsletter.subscribe(input))
|
|
914
1103
|
});
|
|
915
1104
|
}
|
|
916
1105
|
function useNewsletterUnsubscribe() {
|
|
917
1106
|
const { client } = useBehio();
|
|
918
|
-
return
|
|
1107
|
+
return useMutation7({
|
|
919
1108
|
mutationFn: (email) => unwrap(client.newsletter.unsubscribe(email))
|
|
920
1109
|
});
|
|
921
1110
|
}
|
|
922
1111
|
|
|
923
1112
|
// src/react/hooks/use-orders.ts
|
|
924
|
-
import { useCallback as
|
|
1113
|
+
import { useCallback as useCallback10, useMemo as useMemo3, useState as useState6 } from "react";
|
|
925
1114
|
import { useInfiniteQuery as useInfiniteQuery2 } from "@tanstack/react-query";
|
|
926
1115
|
function useOrders(options) {
|
|
927
1116
|
const { client } = useBehio();
|
|
928
1117
|
const { page: initialPage, limit, enabled } = options ?? {};
|
|
929
|
-
const [page, setPage] =
|
|
1118
|
+
const [page, setPage] = useState6(initialPage ?? 1);
|
|
930
1119
|
const infinite = useInfiniteQuery2({
|
|
931
1120
|
queryKey: ["behio", "orders", limit, page],
|
|
932
1121
|
queryFn: ({ pageParam }) => unwrap(client.orders.list({ limit, page: pageParam })),
|
|
@@ -940,13 +1129,13 @@ function useOrders(options) {
|
|
|
940
1129
|
[infinite.data]
|
|
941
1130
|
);
|
|
942
1131
|
const lastPage = infinite.data?.pages[infinite.data.pages.length - 1];
|
|
943
|
-
const loadMore =
|
|
1132
|
+
const loadMore = useCallback10(() => {
|
|
944
1133
|
if (infinite.hasNextPage && !infinite.isFetchingNextPage) {
|
|
945
1134
|
return infinite.fetchNextPage();
|
|
946
1135
|
}
|
|
947
1136
|
return Promise.resolve();
|
|
948
1137
|
}, [infinite]);
|
|
949
|
-
const goToPage =
|
|
1138
|
+
const goToPage = useCallback10((newPage) => {
|
|
950
1139
|
setPage(newPage);
|
|
951
1140
|
}, []);
|
|
952
1141
|
return {
|
|
@@ -972,28 +1161,28 @@ function useOrders(options) {
|
|
|
972
1161
|
}
|
|
973
1162
|
|
|
974
1163
|
// src/react/hooks/use-order.ts
|
|
975
|
-
import { useCallback as
|
|
976
|
-
import { useQuery as
|
|
1164
|
+
import { useCallback as useCallback11 } from "react";
|
|
1165
|
+
import { useQuery as useQuery21, useMutation as useMutation8, useQueryClient as useQueryClient9 } from "@tanstack/react-query";
|
|
977
1166
|
function useOrder(orderNumber, options) {
|
|
978
1167
|
const { client } = useBehio();
|
|
979
|
-
const queryClient =
|
|
1168
|
+
const queryClient = useQueryClient9();
|
|
980
1169
|
const {
|
|
981
1170
|
data,
|
|
982
1171
|
isLoading,
|
|
983
1172
|
error
|
|
984
|
-
} =
|
|
1173
|
+
} = useQuery21({
|
|
985
1174
|
queryKey: ["behio", "order", orderNumber],
|
|
986
1175
|
queryFn: () => unwrap(client.orders.get(orderNumber)),
|
|
987
1176
|
enabled: options?.enabled !== false && !!orderNumber && !!client.getAccessToken()
|
|
988
1177
|
});
|
|
989
|
-
const cancelMutation =
|
|
1178
|
+
const cancelMutation = useMutation8({
|
|
990
1179
|
mutationFn: () => unwrap(client.orders.cancel(orderNumber)),
|
|
991
1180
|
onSuccess: (updated) => {
|
|
992
1181
|
queryClient.setQueryData(["behio", "order", orderNumber], updated);
|
|
993
1182
|
queryClient.invalidateQueries({ queryKey: ["behio", "orders"] });
|
|
994
1183
|
}
|
|
995
1184
|
});
|
|
996
|
-
const cancel =
|
|
1185
|
+
const cancel = useCallback11(
|
|
997
1186
|
() => cancelMutation.mutateAsync(),
|
|
998
1187
|
[cancelMutation]
|
|
999
1188
|
);
|
|
@@ -1007,22 +1196,22 @@ function useOrder(orderNumber, options) {
|
|
|
1007
1196
|
}
|
|
1008
1197
|
|
|
1009
1198
|
// src/react/hooks/use-order-access.ts
|
|
1010
|
-
import { useCallback as
|
|
1011
|
-
import { useMutation as
|
|
1199
|
+
import { useCallback as useCallback12, useState as useState7 } from "react";
|
|
1200
|
+
import { useMutation as useMutation9 } from "@tanstack/react-query";
|
|
1012
1201
|
function useOrderAccess() {
|
|
1013
1202
|
const { client } = useBehio();
|
|
1014
|
-
const [orderNumber, setOrderNumber] =
|
|
1015
|
-
const [email, setEmail] =
|
|
1016
|
-
const [order, setOrder] =
|
|
1017
|
-
const [accessToken, setAccessToken] =
|
|
1018
|
-
const requestMutation =
|
|
1203
|
+
const [orderNumber, setOrderNumber] = useState7(null);
|
|
1204
|
+
const [email, setEmail] = useState7(null);
|
|
1205
|
+
const [order, setOrder] = useState7(null);
|
|
1206
|
+
const [accessToken, setAccessToken] = useState7(null);
|
|
1207
|
+
const requestMutation = useMutation9({
|
|
1019
1208
|
mutationFn: (input) => unwrap(client.orders.requestAccessCode(input.orderNumber, input.email)),
|
|
1020
1209
|
onSuccess: (_data, input) => {
|
|
1021
1210
|
setOrderNumber(input.orderNumber);
|
|
1022
1211
|
setEmail(input.email);
|
|
1023
1212
|
}
|
|
1024
1213
|
});
|
|
1025
|
-
const verifyMutation =
|
|
1214
|
+
const verifyMutation = useMutation9({
|
|
1026
1215
|
mutationFn: (code) => {
|
|
1027
1216
|
if (!orderNumber || !email) {
|
|
1028
1217
|
throw new Error("Request a code before verifying");
|
|
@@ -1034,12 +1223,12 @@ function useOrderAccess() {
|
|
|
1034
1223
|
setAccessToken(result.accessToken);
|
|
1035
1224
|
}
|
|
1036
1225
|
});
|
|
1037
|
-
const requestCode =
|
|
1226
|
+
const requestCode = useCallback12(
|
|
1038
1227
|
(on, em) => requestMutation.mutateAsync({ orderNumber: on, email: em }),
|
|
1039
1228
|
[requestMutation]
|
|
1040
1229
|
);
|
|
1041
|
-
const verifyCode =
|
|
1042
|
-
const reset =
|
|
1230
|
+
const verifyCode = useCallback12((code) => verifyMutation.mutateAsync(code), [verifyMutation]);
|
|
1231
|
+
const reset = useCallback12(() => {
|
|
1043
1232
|
setOrderNumber(null);
|
|
1044
1233
|
setEmail(null);
|
|
1045
1234
|
setOrder(null);
|
|
@@ -1067,13 +1256,13 @@ function useOrderAccess() {
|
|
|
1067
1256
|
}
|
|
1068
1257
|
|
|
1069
1258
|
// src/react/hooks/use-checkout.ts
|
|
1070
|
-
import { useState as
|
|
1071
|
-
import { useMutation as
|
|
1259
|
+
import { useState as useState8, useCallback as useCallback13 } from "react";
|
|
1260
|
+
import { useMutation as useMutation10, useQueryClient as useQueryClient10 } from "@tanstack/react-query";
|
|
1072
1261
|
function useCheckout() {
|
|
1073
1262
|
const { client, storage } = useBehio();
|
|
1074
|
-
const queryClient =
|
|
1075
|
-
const [order, setOrder] =
|
|
1076
|
-
const mutation =
|
|
1263
|
+
const queryClient = useQueryClient10();
|
|
1264
|
+
const [order, setOrder] = useState8(null);
|
|
1265
|
+
const mutation = useMutation10({
|
|
1077
1266
|
mutationFn: (input) => unwrap(client.checkout.createOrder(input)),
|
|
1078
1267
|
onSuccess: (result) => {
|
|
1079
1268
|
setOrder(result);
|
|
@@ -1082,11 +1271,11 @@ function useCheckout() {
|
|
|
1082
1271
|
queryClient.invalidateQueries({ queryKey: ["behio", "orders"] });
|
|
1083
1272
|
}
|
|
1084
1273
|
});
|
|
1085
|
-
const createOrder =
|
|
1274
|
+
const createOrder = useCallback13(
|
|
1086
1275
|
(input) => mutation.mutateAsync(input),
|
|
1087
1276
|
[mutation]
|
|
1088
1277
|
);
|
|
1089
|
-
const reset =
|
|
1278
|
+
const reset = useCallback13(() => {
|
|
1090
1279
|
setOrder(null);
|
|
1091
1280
|
mutation.reset();
|
|
1092
1281
|
}, [mutation]);
|
|
@@ -1100,10 +1289,10 @@ function useCheckout() {
|
|
|
1100
1289
|
}
|
|
1101
1290
|
|
|
1102
1291
|
// src/react/hooks/use-pages.ts
|
|
1103
|
-
import { useQuery as
|
|
1292
|
+
import { useQuery as useQuery22 } from "@tanstack/react-query";
|
|
1104
1293
|
function usePages(locale, options) {
|
|
1105
1294
|
const { client } = useBehio();
|
|
1106
|
-
return
|
|
1295
|
+
return useQuery22({
|
|
1107
1296
|
queryKey: ["behio", "pages", locale],
|
|
1108
1297
|
queryFn: async () => {
|
|
1109
1298
|
const result = await unwrap(client.pages.list(locale));
|
|
@@ -1114,7 +1303,7 @@ function usePages(locale, options) {
|
|
|
1114
1303
|
}
|
|
1115
1304
|
function usePage(slug, locale, options) {
|
|
1116
1305
|
const { client } = useBehio();
|
|
1117
|
-
return
|
|
1306
|
+
return useQuery22({
|
|
1118
1307
|
queryKey: ["behio", "page", slug, locale],
|
|
1119
1308
|
queryFn: () => unwrap(client.pages.get(slug, locale)),
|
|
1120
1309
|
enabled: options?.enabled !== false && !!slug
|
|
@@ -1122,10 +1311,10 @@ function usePage(slug, locale, options) {
|
|
|
1122
1311
|
}
|
|
1123
1312
|
|
|
1124
1313
|
// src/react/hooks/use-shop-info.ts
|
|
1125
|
-
import { useQuery as
|
|
1314
|
+
import { useQuery as useQuery23 } from "@tanstack/react-query";
|
|
1126
1315
|
function useShopInfo(options) {
|
|
1127
1316
|
const { client } = useBehio();
|
|
1128
|
-
return
|
|
1317
|
+
return useQuery23({
|
|
1129
1318
|
queryKey: ["behio", "shop-info"],
|
|
1130
1319
|
queryFn: () => unwrap(client.getShopInfo()),
|
|
1131
1320
|
enabled: options?.enabled !== false
|
|
@@ -1133,10 +1322,10 @@ function useShopInfo(options) {
|
|
|
1133
1322
|
}
|
|
1134
1323
|
|
|
1135
1324
|
// src/react/hooks/use-shop-scripts.ts
|
|
1136
|
-
import { useQuery as
|
|
1325
|
+
import { useQuery as useQuery24 } from "@tanstack/react-query";
|
|
1137
1326
|
function useShopScripts(options) {
|
|
1138
1327
|
const { client } = useBehio();
|
|
1139
|
-
return
|
|
1328
|
+
return useQuery24({
|
|
1140
1329
|
queryKey: ["behio", "shop-scripts"],
|
|
1141
1330
|
queryFn: () => unwrap(client.getShopScripts()),
|
|
1142
1331
|
enabled: options?.enabled !== false
|
|
@@ -1144,11 +1333,11 @@ function useShopScripts(options) {
|
|
|
1144
1333
|
}
|
|
1145
1334
|
|
|
1146
1335
|
// src/react/hooks/use-shop-seo.ts
|
|
1147
|
-
import { useQuery as
|
|
1336
|
+
import { useQuery as useQuery25 } from "@tanstack/react-query";
|
|
1148
1337
|
function useShopSeo(options) {
|
|
1149
1338
|
const { client } = useBehio();
|
|
1150
1339
|
const { locale, initialData, enabled = true } = options ?? {};
|
|
1151
|
-
return
|
|
1340
|
+
return useQuery25({
|
|
1152
1341
|
queryKey: ["behio", "shop-seo", locale ?? "_default"],
|
|
1153
1342
|
queryFn: () => unwrap(client.getShopSeo(locale)),
|
|
1154
1343
|
initialData,
|
|
@@ -1208,23 +1397,23 @@ function CurrencySwitcher({
|
|
|
1208
1397
|
}
|
|
1209
1398
|
|
|
1210
1399
|
// src/react/components/storefront-scripts.tsx
|
|
1211
|
-
import { useEffect as
|
|
1400
|
+
import { useEffect as useEffect5, useMemo as useMemo4, useState as useState9 } from "react";
|
|
1212
1401
|
|
|
1213
1402
|
// src/react/hooks/use-consent.ts
|
|
1214
|
-
import { useQuery as
|
|
1403
|
+
import { useQuery as useQuery26, useMutation as useMutation11, useQueryClient as useQueryClient11 } from "@tanstack/react-query";
|
|
1215
1404
|
function useCookieConsent(visitorId) {
|
|
1216
1405
|
const { client } = useBehio();
|
|
1217
|
-
const qc =
|
|
1218
|
-
const query =
|
|
1406
|
+
const qc = useQueryClient11();
|
|
1407
|
+
const query = useQuery26({
|
|
1219
1408
|
queryKey: ["behio", "consent", visitorId],
|
|
1220
1409
|
queryFn: () => unwrap(client.consent.get(visitorId)),
|
|
1221
1410
|
enabled: Boolean(visitorId)
|
|
1222
1411
|
});
|
|
1223
|
-
const recordMutation =
|
|
1412
|
+
const recordMutation = useMutation11({
|
|
1224
1413
|
mutationFn: (input) => unwrap(client.consent.record(input)),
|
|
1225
1414
|
onSuccess: () => qc.invalidateQueries({ queryKey: ["behio", "consent"] })
|
|
1226
1415
|
});
|
|
1227
|
-
const revokeMutation =
|
|
1416
|
+
const revokeMutation = useMutation11({
|
|
1228
1417
|
mutationFn: () => unwrap(client.consent.revoke(visitorId)),
|
|
1229
1418
|
onSuccess: () => qc.invalidateQueries({ queryKey: ["behio", "consent"] })
|
|
1230
1419
|
});
|
|
@@ -1298,8 +1487,8 @@ function injectHtml(target, html) {
|
|
|
1298
1487
|
}
|
|
1299
1488
|
function StorefrontScripts({ visitorId: visitorIdProp } = {}) {
|
|
1300
1489
|
const { data } = useShopScripts();
|
|
1301
|
-
const [visitorId, setVisitorId] =
|
|
1302
|
-
|
|
1490
|
+
const [visitorId, setVisitorId] = useState9(visitorIdProp ?? "");
|
|
1491
|
+
useEffect5(() => {
|
|
1303
1492
|
if (visitorIdProp) return;
|
|
1304
1493
|
try {
|
|
1305
1494
|
const v = localStorage.getItem(VISITOR_KEY);
|
|
@@ -1317,7 +1506,7 @@ function StorefrontScripts({ visitorId: visitorIdProp } = {}) {
|
|
|
1317
1506
|
() => JSON.stringify(scripts.map((s) => [s.id, s.type, s.placement, s.value])),
|
|
1318
1507
|
[scripts]
|
|
1319
1508
|
);
|
|
1320
|
-
|
|
1509
|
+
useEffect5(() => {
|
|
1321
1510
|
if (typeof document === "undefined") return;
|
|
1322
1511
|
const added = [];
|
|
1323
1512
|
for (const s of scripts) {
|
|
@@ -1334,7 +1523,7 @@ function StorefrontScripts({ visitorId: visitorIdProp } = {}) {
|
|
|
1334
1523
|
}
|
|
1335
1524
|
|
|
1336
1525
|
// src/react/components/behio-analytics.tsx
|
|
1337
|
-
import { useEffect as
|
|
1526
|
+
import { useEffect as useEffect6 } from "react";
|
|
1338
1527
|
|
|
1339
1528
|
// src/react/hooks/use-behio-client.ts
|
|
1340
1529
|
function useBehioClient() {
|
|
@@ -1344,7 +1533,7 @@ function useBehioClient() {
|
|
|
1344
1533
|
// src/react/components/behio-analytics.tsx
|
|
1345
1534
|
function BehioAnalyticsTracker() {
|
|
1346
1535
|
const client = useBehioClient();
|
|
1347
|
-
|
|
1536
|
+
useEffect6(() => {
|
|
1348
1537
|
if (typeof window === "undefined") return;
|
|
1349
1538
|
const w = window;
|
|
1350
1539
|
if (w.__behioAnalytics) return;
|
|
@@ -1556,10 +1745,10 @@ function utmFromSearch(search) {
|
|
|
1556
1745
|
}
|
|
1557
1746
|
|
|
1558
1747
|
// src/react/hooks/use-bundles.ts
|
|
1559
|
-
import { useQuery as
|
|
1748
|
+
import { useQuery as useQuery27 } from "@tanstack/react-query";
|
|
1560
1749
|
function useBundles(options) {
|
|
1561
1750
|
const { client } = useBehio();
|
|
1562
|
-
return
|
|
1751
|
+
return useQuery27({
|
|
1563
1752
|
queryKey: ["behio", "bundles"],
|
|
1564
1753
|
queryFn: () => unwrap(client.catalog.getBundles()),
|
|
1565
1754
|
enabled: options?.enabled ?? true,
|
|
@@ -1568,7 +1757,7 @@ function useBundles(options) {
|
|
|
1568
1757
|
}
|
|
1569
1758
|
function useBundle(slug, options) {
|
|
1570
1759
|
const { client } = useBehio();
|
|
1571
|
-
return
|
|
1760
|
+
return useQuery27({
|
|
1572
1761
|
queryKey: ["behio", "bundle", slug],
|
|
1573
1762
|
queryFn: () => unwrap(client.catalog.getBundle(slug)),
|
|
1574
1763
|
enabled: Boolean(slug) && (options?.enabled ?? true),
|
|
@@ -1577,10 +1766,10 @@ function useBundle(slug, options) {
|
|
|
1577
1766
|
}
|
|
1578
1767
|
|
|
1579
1768
|
// src/react/hooks/use-product-group.ts
|
|
1580
|
-
import { useQuery as
|
|
1769
|
+
import { useQuery as useQuery28 } from "@tanstack/react-query";
|
|
1581
1770
|
function useProductGroup(slug, options) {
|
|
1582
1771
|
const { client } = useBehio();
|
|
1583
|
-
return
|
|
1772
|
+
return useQuery28({
|
|
1584
1773
|
queryKey: ["behio", "product-group", slug, options?.locale, options?.currency],
|
|
1585
1774
|
queryFn: () => unwrap(
|
|
1586
1775
|
client.catalog.getProductGroup(slug, {
|
|
@@ -1594,10 +1783,10 @@ function useProductGroup(slug, options) {
|
|
|
1594
1783
|
}
|
|
1595
1784
|
|
|
1596
1785
|
// src/react/hooks/use-cross-sell.ts
|
|
1597
|
-
import { useQuery as
|
|
1786
|
+
import { useQuery as useQuery29 } from "@tanstack/react-query";
|
|
1598
1787
|
function useCrossSell(productSlug, options) {
|
|
1599
1788
|
const { client } = useBehio();
|
|
1600
|
-
return
|
|
1789
|
+
return useQuery29({
|
|
1601
1790
|
queryKey: ["behio", "cross-sell", productSlug, options?.locale, options?.currency],
|
|
1602
1791
|
queryFn: () => unwrap(
|
|
1603
1792
|
client.catalog.getCrossSell(productSlug, {
|
|
@@ -1611,10 +1800,10 @@ function useCrossSell(productSlug, options) {
|
|
|
1611
1800
|
}
|
|
1612
1801
|
|
|
1613
1802
|
// src/react/hooks/use-product-promotions.ts
|
|
1614
|
-
import { useQuery as
|
|
1803
|
+
import { useQuery as useQuery30 } from "@tanstack/react-query";
|
|
1615
1804
|
function useProductPromotions(productSlug, options) {
|
|
1616
1805
|
const { client } = useBehio();
|
|
1617
|
-
return
|
|
1806
|
+
return useQuery30({
|
|
1618
1807
|
queryKey: ["behio", "product-promotions", productSlug],
|
|
1619
1808
|
queryFn: () => unwrap(client.catalog.getProductPromotions(productSlug)),
|
|
1620
1809
|
enabled: Boolean(productSlug) && (options?.enabled ?? true),
|
|
@@ -1623,11 +1812,11 @@ function useProductPromotions(productSlug, options) {
|
|
|
1623
1812
|
}
|
|
1624
1813
|
|
|
1625
1814
|
// src/react/hooks/use-gift-card.ts
|
|
1626
|
-
import { useQuery as
|
|
1815
|
+
import { useQuery as useQuery31 } from "@tanstack/react-query";
|
|
1627
1816
|
function useGiftCardBalance(code, options) {
|
|
1628
1817
|
const { client } = useBehio();
|
|
1629
1818
|
const trimmed = code?.trim();
|
|
1630
|
-
return
|
|
1819
|
+
return useQuery31({
|
|
1631
1820
|
queryKey: ["behio", "gift-card-balance", trimmed],
|
|
1632
1821
|
queryFn: () => unwrap(client.catalog.checkGiftCard(trimmed)),
|
|
1633
1822
|
enabled: Boolean(trimmed && trimmed.length >= 6) && (options?.enabled ?? true)
|
|
@@ -1635,20 +1824,20 @@ function useGiftCardBalance(code, options) {
|
|
|
1635
1824
|
}
|
|
1636
1825
|
|
|
1637
1826
|
// src/react/hooks/use-wishlist.ts
|
|
1638
|
-
import { useQuery as
|
|
1827
|
+
import { useQuery as useQuery32, useMutation as useMutation12, useQueryClient as useQueryClient12 } from "@tanstack/react-query";
|
|
1639
1828
|
function useWishlist(options) {
|
|
1640
1829
|
const { client } = useBehio();
|
|
1641
|
-
const qc =
|
|
1642
|
-
const query =
|
|
1830
|
+
const qc = useQueryClient12();
|
|
1831
|
+
const query = useQuery32({
|
|
1643
1832
|
queryKey: ["behio", "wishlist"],
|
|
1644
1833
|
queryFn: () => unwrap(client.wishlist.get()),
|
|
1645
1834
|
enabled: options?.enabled ?? true
|
|
1646
1835
|
});
|
|
1647
|
-
const addMutation =
|
|
1836
|
+
const addMutation = useMutation12({
|
|
1648
1837
|
mutationFn: (productId) => unwrap(client.wishlist.add(productId)),
|
|
1649
1838
|
onSuccess: () => qc.invalidateQueries({ queryKey: ["behio", "wishlist"] })
|
|
1650
1839
|
});
|
|
1651
|
-
const removeMutation =
|
|
1840
|
+
const removeMutation = useMutation12({
|
|
1652
1841
|
mutationFn: (productId) => unwrap(client.wishlist.remove(productId)),
|
|
1653
1842
|
onSuccess: () => qc.invalidateQueries({ queryKey: ["behio", "wishlist"] })
|
|
1654
1843
|
});
|
|
@@ -1662,7 +1851,7 @@ function useWishlist(options) {
|
|
|
1662
1851
|
}
|
|
1663
1852
|
function useIsInWishlist(productId) {
|
|
1664
1853
|
const { client } = useBehio();
|
|
1665
|
-
return
|
|
1854
|
+
return useQuery32({
|
|
1666
1855
|
queryKey: ["behio", "wishlist-check", productId],
|
|
1667
1856
|
queryFn: () => unwrap(client.wishlist.isInWishlist(productId)),
|
|
1668
1857
|
enabled: Boolean(productId)
|
|
@@ -1670,10 +1859,10 @@ function useIsInWishlist(productId) {
|
|
|
1670
1859
|
}
|
|
1671
1860
|
|
|
1672
1861
|
// src/react/hooks/use-reviews.ts
|
|
1673
|
-
import { useQuery as
|
|
1862
|
+
import { useQuery as useQuery33, useMutation as useMutation13, useQueryClient as useQueryClient13 } from "@tanstack/react-query";
|
|
1674
1863
|
function useProductReviews(productId, options) {
|
|
1675
1864
|
const { client } = useBehio();
|
|
1676
|
-
return
|
|
1865
|
+
return useQuery33({
|
|
1677
1866
|
queryKey: ["behio", "reviews", productId, options?.page ?? 1],
|
|
1678
1867
|
queryFn: () => unwrap(client.reviews.getProductReviews(productId, options?.page, options?.limit)),
|
|
1679
1868
|
enabled: Boolean(productId) && (options?.enabled ?? true)
|
|
@@ -1681,30 +1870,30 @@ function useProductReviews(productId, options) {
|
|
|
1681
1870
|
}
|
|
1682
1871
|
function useSubmitReview() {
|
|
1683
1872
|
const { client } = useBehio();
|
|
1684
|
-
const qc =
|
|
1685
|
-
return
|
|
1873
|
+
const qc = useQueryClient13();
|
|
1874
|
+
return useMutation13({
|
|
1686
1875
|
mutationFn: (input) => unwrap(client.reviews.submit(input)),
|
|
1687
1876
|
onSuccess: (_, input) => qc.invalidateQueries({ queryKey: ["behio", "reviews", input.productId] })
|
|
1688
1877
|
});
|
|
1689
1878
|
}
|
|
1690
1879
|
|
|
1691
1880
|
// src/react/hooks/use-returns.ts
|
|
1692
|
-
import { useQuery as
|
|
1881
|
+
import { useQuery as useQuery34, useMutation as useMutation14 } from "@tanstack/react-query";
|
|
1693
1882
|
function useLookupReturnableOrder() {
|
|
1694
1883
|
const { client } = useBehio();
|
|
1695
|
-
return
|
|
1884
|
+
return useMutation14({
|
|
1696
1885
|
mutationFn: ({ orderNumber, email }) => unwrap(client.returns.lookupOrder(orderNumber, email))
|
|
1697
1886
|
});
|
|
1698
1887
|
}
|
|
1699
1888
|
function useSubmitReturn() {
|
|
1700
1889
|
const { client } = useBehio();
|
|
1701
|
-
return
|
|
1890
|
+
return useMutation14({
|
|
1702
1891
|
mutationFn: (input) => unwrap(client.returns.submit(input))
|
|
1703
1892
|
});
|
|
1704
1893
|
}
|
|
1705
1894
|
function useReturnStatus(returnId, email) {
|
|
1706
1895
|
const { client } = useBehio();
|
|
1707
|
-
return
|
|
1896
|
+
return useQuery34({
|
|
1708
1897
|
queryKey: ["behio", "return-status", returnId],
|
|
1709
1898
|
queryFn: () => unwrap(client.returns.getStatus(returnId, email)),
|
|
1710
1899
|
enabled: Boolean(returnId && email)
|
|
@@ -1712,16 +1901,16 @@ function useReturnStatus(returnId, email) {
|
|
|
1712
1901
|
}
|
|
1713
1902
|
|
|
1714
1903
|
// src/react/hooks/use-quotes.ts
|
|
1715
|
-
import { useMutation as
|
|
1904
|
+
import { useMutation as useMutation15, useQuery as useQuery35 } from "@tanstack/react-query";
|
|
1716
1905
|
function useSubmitQuote() {
|
|
1717
1906
|
const { client } = useBehio();
|
|
1718
|
-
return
|
|
1907
|
+
return useMutation15({
|
|
1719
1908
|
mutationFn: (input) => unwrap(client.quotes.submit(input))
|
|
1720
1909
|
});
|
|
1721
1910
|
}
|
|
1722
1911
|
function useQuoteStatus(quoteId, email) {
|
|
1723
1912
|
const { client } = useBehio();
|
|
1724
|
-
return
|
|
1913
|
+
return useQuery35({
|
|
1725
1914
|
queryKey: ["behio", "quote-status", quoteId],
|
|
1726
1915
|
queryFn: () => unwrap(client.quotes.getStatus(quoteId, email)),
|
|
1727
1916
|
enabled: Boolean(quoteId && email)
|
|
@@ -1729,10 +1918,10 @@ function useQuoteStatus(quoteId, email) {
|
|
|
1729
1918
|
}
|
|
1730
1919
|
|
|
1731
1920
|
// src/react/hooks/use-back-in-stock.ts
|
|
1732
|
-
import { useMutation as
|
|
1921
|
+
import { useMutation as useMutation16 } from "@tanstack/react-query";
|
|
1733
1922
|
function useNotifyWhenAvailable() {
|
|
1734
1923
|
const { client } = useBehio();
|
|
1735
|
-
return
|
|
1924
|
+
return useMutation16({
|
|
1736
1925
|
mutationFn: ({ productId, email }) => unwrap(client.catalog.notifyWhenAvailable(productId, email))
|
|
1737
1926
|
});
|
|
1738
1927
|
}
|
|
@@ -1750,6 +1939,7 @@ export {
|
|
|
1750
1939
|
trackEcommerceEvent,
|
|
1751
1940
|
useAddressAutocomplete,
|
|
1752
1941
|
useAddresses,
|
|
1942
|
+
useAnalyticsEvents,
|
|
1753
1943
|
useAuth,
|
|
1754
1944
|
useBehio,
|
|
1755
1945
|
useBehioClient,
|
|
@@ -1780,6 +1970,8 @@ export {
|
|
|
1780
1970
|
useOrders,
|
|
1781
1971
|
usePage,
|
|
1782
1972
|
usePages,
|
|
1973
|
+
usePaymentMethods,
|
|
1974
|
+
usePersonalOffers,
|
|
1783
1975
|
usePickupPoints,
|
|
1784
1976
|
useProduct,
|
|
1785
1977
|
useProductGroup,
|
|
@@ -1789,11 +1981,14 @@ export {
|
|
|
1789
1981
|
useQuoteStatus,
|
|
1790
1982
|
useReturnStatus,
|
|
1791
1983
|
useSearch,
|
|
1984
|
+
useShippingMethods,
|
|
1985
|
+
useShippingQuote,
|
|
1792
1986
|
useShopInfo,
|
|
1793
1987
|
useShopScripts,
|
|
1794
1988
|
useShopSeo,
|
|
1795
1989
|
useSubmitQuote,
|
|
1796
1990
|
useSubmitReturn,
|
|
1797
1991
|
useSubmitReview,
|
|
1992
|
+
useSubscriptions,
|
|
1798
1993
|
useWishlist
|
|
1799
1994
|
};
|