@behio/storefront-sdk 0.32.0 → 0.34.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/react.mjs CHANGED
@@ -1,10 +1,14 @@
1
1
  import {
2
2
  formatPrice,
3
+ generateVisitorId,
4
+ getStoredVisitorId,
5
+ grantAnalyticsConsent,
6
+ revokeAnalyticsConsent,
3
7
  trackEcommerceEvent
4
- } from "./chunk-ZOZAJG6T.mjs";
8
+ } from "./chunk-QUU76QUB.mjs";
5
9
  import {
6
10
  BehioStorefront
7
- } from "./chunk-Y7QAB75P.mjs";
11
+ } from "./chunk-5KJDVDUM.mjs";
8
12
 
9
13
  // src/react/provider.tsx
10
14
  import { useRef, useEffect, useMemo, useState, useCallback } from "react";
@@ -885,12 +889,50 @@ function useLoyalty(options) {
885
889
  return { loyalty: data, isLoading, error, refetch };
886
890
  }
887
891
 
892
+ // src/react/hooks/use-subscriptions.ts
893
+ import { useQuery as useQuery15, useMutation as useMutation5, useQueryClient as useQueryClient7 } from "@tanstack/react-query";
894
+ var SUBSCRIPTIONS_KEY = ["behio", "subscriptions"];
895
+ function useSubscriptions(options) {
896
+ const { client } = useBehio();
897
+ const qc = useQueryClient7();
898
+ const query = useQuery15({
899
+ queryKey: [...SUBSCRIPTIONS_KEY],
900
+ queryFn: () => unwrap(client.subscriptions.list()),
901
+ enabled: options?.enabled !== false && !!client.getAccessToken()
902
+ });
903
+ const invalidate = () => qc.invalidateQueries({ queryKey: [...SUBSCRIPTIONS_KEY] });
904
+ const pauseMutation = useMutation5({
905
+ mutationFn: (subscriptionId) => unwrap(client.subscriptions.pause(subscriptionId)),
906
+ onSuccess: invalidate
907
+ });
908
+ const resumeMutation = useMutation5({
909
+ mutationFn: (subscriptionId) => unwrap(client.subscriptions.resume(subscriptionId)),
910
+ onSuccess: invalidate
911
+ });
912
+ const cancelMutation = useMutation5({
913
+ mutationFn: (subscriptionId) => unwrap(client.subscriptions.cancel(subscriptionId)),
914
+ onSuccess: invalidate
915
+ });
916
+ return {
917
+ subscriptions: query.data?.items ?? [],
918
+ isLoading: query.isLoading,
919
+ error: query.error,
920
+ refetch: query.refetch,
921
+ pause: pauseMutation.mutateAsync,
922
+ resume: resumeMutation.mutateAsync,
923
+ cancel: cancelMutation.mutateAsync,
924
+ isPausing: pauseMutation.isPending,
925
+ isResuming: resumeMutation.isPending,
926
+ isCancelling: cancelMutation.isPending
927
+ };
928
+ }
929
+
888
930
  // src/react/hooks/use-pickup-points.ts
889
- import { useQuery as useQuery15 } from "@tanstack/react-query";
931
+ import { useQuery as useQuery16 } from "@tanstack/react-query";
890
932
  function usePickupPoints(input) {
891
933
  const { client } = useBehio();
892
934
  const { methodId, query, country, limit, enabled } = input;
893
- const { data, isLoading, error, refetch } = useQuery15({
935
+ const { data, isLoading, error, refetch } = useQuery16({
894
936
  queryKey: ["behio", "pickup-points", methodId, query ?? "", country ?? "", limit ?? 30],
895
937
  queryFn: () => unwrap(
896
938
  client.shipping.getPickupPoints({
@@ -905,28 +947,179 @@ function usePickupPoints(input) {
905
947
  return { pickupPoints: data?.items ?? [], isLoading, error, refetch };
906
948
  }
907
949
 
950
+ // src/react/hooks/use-shipping-methods.ts
951
+ import { useQuery as useQuery17 } from "@tanstack/react-query";
952
+ function useShippingMethods(options) {
953
+ const { client, currency: activeCurrency } = useBehio();
954
+ const currency = options?.currency ?? activeCurrency;
955
+ const { country, cartTotal, cartWeightKg } = options ?? {};
956
+ const { data, isLoading, error, refetch } = useQuery17({
957
+ queryKey: [
958
+ "behio",
959
+ "shipping-methods",
960
+ currency ?? "",
961
+ country ?? "",
962
+ cartTotal ?? "",
963
+ cartWeightKg ?? ""
964
+ ],
965
+ queryFn: () => unwrap(client.shipping.listMethods({ currency, country, cartTotal, cartWeightKg })),
966
+ enabled: options?.enabled !== false
967
+ });
968
+ return { methods: data?.items ?? [], isLoading, error, refetch };
969
+ }
970
+
971
+ // src/react/hooks/use-shipping-quote.ts
972
+ import { useQuery as useQuery18 } from "@tanstack/react-query";
973
+ function useShippingQuote(options) {
974
+ const { client, currency: activeCurrency } = useBehio();
975
+ const { destinationAddress, items, cartTotal, enabled } = options ?? {};
976
+ const currency = options?.currency ?? activeCurrency;
977
+ const { data, isLoading, error, refetch } = useQuery18({
978
+ queryKey: [
979
+ "behio",
980
+ "shipping-quote",
981
+ JSON.stringify(destinationAddress ?? null),
982
+ JSON.stringify(items ?? null),
983
+ cartTotal ?? "",
984
+ currency ?? ""
985
+ ],
986
+ queryFn: () => unwrap(
987
+ client.shipping.quote({
988
+ destinationAddress,
989
+ items,
990
+ cartTotal,
991
+ currency
992
+ })
993
+ ),
994
+ enabled: enabled !== false && !!destinationAddress?.country
995
+ });
996
+ return { quotes: data?.items ?? [], isLoading, error, refetch };
997
+ }
998
+
999
+ // src/react/hooks/use-payment-methods.ts
1000
+ import { useQuery as useQuery19 } from "@tanstack/react-query";
1001
+ function usePaymentMethods(options) {
1002
+ const { client, currency: activeCurrency } = useBehio();
1003
+ const currency = options?.currency ?? activeCurrency;
1004
+ const { data, isLoading, error, refetch } = useQuery19({
1005
+ queryKey: ["behio", "payment-methods", currency ?? ""],
1006
+ queryFn: () => unwrap(client.catalog.listPaymentMethods({ currency })),
1007
+ enabled: options?.enabled !== false
1008
+ });
1009
+ return { methods: data?.items ?? [], isLoading, error, refetch };
1010
+ }
1011
+
1012
+ // src/react/hooks/use-personal-offers.ts
1013
+ import { useCallback as useCallback8, useEffect as useEffect4, useState as useState5 } from "react";
1014
+ import { useMutation as useMutation6, useQuery as useQuery20, useQueryClient as useQueryClient8 } from "@tanstack/react-query";
1015
+ function usePersonalOffers(options) {
1016
+ const { client } = useBehio();
1017
+ const queryClient = useQueryClient8();
1018
+ const [polledVid, setPolledVid] = useState5(null);
1019
+ const explicitVid = options?.visitorId;
1020
+ useEffect4(() => {
1021
+ if (explicitVid) return;
1022
+ const read = () => {
1023
+ const vid = client.getAnalyticsVisitorId();
1024
+ if (vid) setPolledVid(vid);
1025
+ return vid;
1026
+ };
1027
+ if (read()) return;
1028
+ const timer = setInterval(() => {
1029
+ if (read()) clearInterval(timer);
1030
+ }, 3e3);
1031
+ return () => clearInterval(timer);
1032
+ }, [client, explicitVid]);
1033
+ const visitorId = explicitVid ?? polledVid;
1034
+ const queryKey = ["behio", "personal-offers", visitorId ?? ""];
1035
+ const { data, isLoading, error, refetch } = useQuery20({
1036
+ queryKey,
1037
+ queryFn: () => unwrap(client.getPersonalOffers(visitorId)),
1038
+ enabled: options?.enabled !== false && !!visitorId
1039
+ });
1040
+ const claimMutation = useMutation6({
1041
+ mutationFn: ({ offerId, email }) => unwrap(client.claimOfferByEmail(offerId, { visitorId, email })),
1042
+ onSuccess: (result, { offerId }) => {
1043
+ queryClient.setQueryData(
1044
+ queryKey,
1045
+ (prev) => prev ? {
1046
+ items: prev.items.map(
1047
+ (o) => o.id === offerId ? { ...o, code: result.code, status: "CLAIMED" } : o
1048
+ )
1049
+ } : prev
1050
+ );
1051
+ }
1052
+ });
1053
+ const claimByEmail = useCallback8(
1054
+ (offerId, email) => claimMutation.mutateAsync({ offerId, email }),
1055
+ [claimMutation]
1056
+ );
1057
+ return {
1058
+ offers: data?.items ?? [],
1059
+ /** Resolved consent-gated visitor id (null before consent). */
1060
+ visitorId: visitorId ?? null,
1061
+ isLoading,
1062
+ error,
1063
+ refetch,
1064
+ /** E-mail gate: trade an e-mail for the discount code of the given offer. */
1065
+ claimByEmail,
1066
+ isClaiming: claimMutation.isPending,
1067
+ claimError: claimMutation.error
1068
+ };
1069
+ }
1070
+
1071
+ // src/react/hooks/use-analytics-events.ts
1072
+ import { useCallback as useCallback9 } from "react";
1073
+ function useAnalyticsEvents() {
1074
+ const { client } = useBehio();
1075
+ const track = useCallback9(
1076
+ (events, opts) => {
1077
+ const list = Array.isArray(events) ? events : [events];
1078
+ if (list.length === 0) return Promise.resolve();
1079
+ return client.sendAnalyticsEvents({
1080
+ sessionId: opts?.sessionId,
1081
+ visitorId: client.getAnalyticsVisitorId() ?? void 0,
1082
+ events: list.map((e) => ({ ts: Date.now(), ...e }))
1083
+ });
1084
+ },
1085
+ [client]
1086
+ );
1087
+ const trackEvent = useCallback9(
1088
+ (name, props) => track({ type: "custom", name, props }),
1089
+ [track]
1090
+ );
1091
+ return {
1092
+ /** Send one or more raw analytics events. */
1093
+ track,
1094
+ /** Convenience: send a named `custom` event with optional props. */
1095
+ trackEvent,
1096
+ /** Consent-gated visitor id, null before analytics consent. */
1097
+ getVisitorId: () => client.getAnalyticsVisitorId()
1098
+ };
1099
+ }
1100
+
908
1101
  // src/react/hooks/use-newsletter.ts
909
- import { useMutation as useMutation5 } from "@tanstack/react-query";
1102
+ import { useMutation as useMutation7 } from "@tanstack/react-query";
910
1103
  function useNewsletterSubscribe() {
911
1104
  const { client } = useBehio();
912
- return useMutation5({
1105
+ return useMutation7({
913
1106
  mutationFn: (input) => unwrap(client.newsletter.subscribe(input))
914
1107
  });
915
1108
  }
916
1109
  function useNewsletterUnsubscribe() {
917
1110
  const { client } = useBehio();
918
- return useMutation5({
1111
+ return useMutation7({
919
1112
  mutationFn: (email) => unwrap(client.newsletter.unsubscribe(email))
920
1113
  });
921
1114
  }
922
1115
 
923
1116
  // src/react/hooks/use-orders.ts
924
- import { useCallback as useCallback8, useMemo as useMemo3, useState as useState5 } from "react";
1117
+ import { useCallback as useCallback10, useMemo as useMemo3, useState as useState6 } from "react";
925
1118
  import { useInfiniteQuery as useInfiniteQuery2 } from "@tanstack/react-query";
926
1119
  function useOrders(options) {
927
1120
  const { client } = useBehio();
928
1121
  const { page: initialPage, limit, enabled } = options ?? {};
929
- const [page, setPage] = useState5(initialPage ?? 1);
1122
+ const [page, setPage] = useState6(initialPage ?? 1);
930
1123
  const infinite = useInfiniteQuery2({
931
1124
  queryKey: ["behio", "orders", limit, page],
932
1125
  queryFn: ({ pageParam }) => unwrap(client.orders.list({ limit, page: pageParam })),
@@ -940,13 +1133,13 @@ function useOrders(options) {
940
1133
  [infinite.data]
941
1134
  );
942
1135
  const lastPage = infinite.data?.pages[infinite.data.pages.length - 1];
943
- const loadMore = useCallback8(() => {
1136
+ const loadMore = useCallback10(() => {
944
1137
  if (infinite.hasNextPage && !infinite.isFetchingNextPage) {
945
1138
  return infinite.fetchNextPage();
946
1139
  }
947
1140
  return Promise.resolve();
948
1141
  }, [infinite]);
949
- const goToPage = useCallback8((newPage) => {
1142
+ const goToPage = useCallback10((newPage) => {
950
1143
  setPage(newPage);
951
1144
  }, []);
952
1145
  return {
@@ -972,28 +1165,28 @@ function useOrders(options) {
972
1165
  }
973
1166
 
974
1167
  // src/react/hooks/use-order.ts
975
- import { useCallback as useCallback9 } from "react";
976
- import { useQuery as useQuery16, useMutation as useMutation6, useQueryClient as useQueryClient7 } from "@tanstack/react-query";
1168
+ import { useCallback as useCallback11 } from "react";
1169
+ import { useQuery as useQuery21, useMutation as useMutation8, useQueryClient as useQueryClient9 } from "@tanstack/react-query";
977
1170
  function useOrder(orderNumber, options) {
978
1171
  const { client } = useBehio();
979
- const queryClient = useQueryClient7();
1172
+ const queryClient = useQueryClient9();
980
1173
  const {
981
1174
  data,
982
1175
  isLoading,
983
1176
  error
984
- } = useQuery16({
1177
+ } = useQuery21({
985
1178
  queryKey: ["behio", "order", orderNumber],
986
1179
  queryFn: () => unwrap(client.orders.get(orderNumber)),
987
1180
  enabled: options?.enabled !== false && !!orderNumber && !!client.getAccessToken()
988
1181
  });
989
- const cancelMutation = useMutation6({
1182
+ const cancelMutation = useMutation8({
990
1183
  mutationFn: () => unwrap(client.orders.cancel(orderNumber)),
991
1184
  onSuccess: (updated) => {
992
1185
  queryClient.setQueryData(["behio", "order", orderNumber], updated);
993
1186
  queryClient.invalidateQueries({ queryKey: ["behio", "orders"] });
994
1187
  }
995
1188
  });
996
- const cancel = useCallback9(
1189
+ const cancel = useCallback11(
997
1190
  () => cancelMutation.mutateAsync(),
998
1191
  [cancelMutation]
999
1192
  );
@@ -1007,22 +1200,22 @@ function useOrder(orderNumber, options) {
1007
1200
  }
1008
1201
 
1009
1202
  // src/react/hooks/use-order-access.ts
1010
- import { useCallback as useCallback10, useState as useState6 } from "react";
1011
- import { useMutation as useMutation7 } from "@tanstack/react-query";
1203
+ import { useCallback as useCallback12, useState as useState7 } from "react";
1204
+ import { useMutation as useMutation9 } from "@tanstack/react-query";
1012
1205
  function useOrderAccess() {
1013
1206
  const { client } = useBehio();
1014
- const [orderNumber, setOrderNumber] = useState6(null);
1015
- const [email, setEmail] = useState6(null);
1016
- const [order, setOrder] = useState6(null);
1017
- const [accessToken, setAccessToken] = useState6(null);
1018
- const requestMutation = useMutation7({
1207
+ const [orderNumber, setOrderNumber] = useState7(null);
1208
+ const [email, setEmail] = useState7(null);
1209
+ const [order, setOrder] = useState7(null);
1210
+ const [accessToken, setAccessToken] = useState7(null);
1211
+ const requestMutation = useMutation9({
1019
1212
  mutationFn: (input) => unwrap(client.orders.requestAccessCode(input.orderNumber, input.email)),
1020
1213
  onSuccess: (_data, input) => {
1021
1214
  setOrderNumber(input.orderNumber);
1022
1215
  setEmail(input.email);
1023
1216
  }
1024
1217
  });
1025
- const verifyMutation = useMutation7({
1218
+ const verifyMutation = useMutation9({
1026
1219
  mutationFn: (code) => {
1027
1220
  if (!orderNumber || !email) {
1028
1221
  throw new Error("Request a code before verifying");
@@ -1034,12 +1227,12 @@ function useOrderAccess() {
1034
1227
  setAccessToken(result.accessToken);
1035
1228
  }
1036
1229
  });
1037
- const requestCode = useCallback10(
1230
+ const requestCode = useCallback12(
1038
1231
  (on, em) => requestMutation.mutateAsync({ orderNumber: on, email: em }),
1039
1232
  [requestMutation]
1040
1233
  );
1041
- const verifyCode = useCallback10((code) => verifyMutation.mutateAsync(code), [verifyMutation]);
1042
- const reset = useCallback10(() => {
1234
+ const verifyCode = useCallback12((code) => verifyMutation.mutateAsync(code), [verifyMutation]);
1235
+ const reset = useCallback12(() => {
1043
1236
  setOrderNumber(null);
1044
1237
  setEmail(null);
1045
1238
  setOrder(null);
@@ -1067,13 +1260,13 @@ function useOrderAccess() {
1067
1260
  }
1068
1261
 
1069
1262
  // src/react/hooks/use-checkout.ts
1070
- import { useState as useState7, useCallback as useCallback11 } from "react";
1071
- import { useMutation as useMutation8, useQueryClient as useQueryClient8 } from "@tanstack/react-query";
1263
+ import { useState as useState8, useCallback as useCallback13 } from "react";
1264
+ import { useMutation as useMutation10, useQueryClient as useQueryClient10 } from "@tanstack/react-query";
1072
1265
  function useCheckout() {
1073
1266
  const { client, storage } = useBehio();
1074
- const queryClient = useQueryClient8();
1075
- const [order, setOrder] = useState7(null);
1076
- const mutation = useMutation8({
1267
+ const queryClient = useQueryClient10();
1268
+ const [order, setOrder] = useState8(null);
1269
+ const mutation = useMutation10({
1077
1270
  mutationFn: (input) => unwrap(client.checkout.createOrder(input)),
1078
1271
  onSuccess: (result) => {
1079
1272
  setOrder(result);
@@ -1082,11 +1275,11 @@ function useCheckout() {
1082
1275
  queryClient.invalidateQueries({ queryKey: ["behio", "orders"] });
1083
1276
  }
1084
1277
  });
1085
- const createOrder = useCallback11(
1278
+ const createOrder = useCallback13(
1086
1279
  (input) => mutation.mutateAsync(input),
1087
1280
  [mutation]
1088
1281
  );
1089
- const reset = useCallback11(() => {
1282
+ const reset = useCallback13(() => {
1090
1283
  setOrder(null);
1091
1284
  mutation.reset();
1092
1285
  }, [mutation]);
@@ -1100,10 +1293,10 @@ function useCheckout() {
1100
1293
  }
1101
1294
 
1102
1295
  // src/react/hooks/use-pages.ts
1103
- import { useQuery as useQuery17 } from "@tanstack/react-query";
1296
+ import { useQuery as useQuery22 } from "@tanstack/react-query";
1104
1297
  function usePages(locale, options) {
1105
1298
  const { client } = useBehio();
1106
- return useQuery17({
1299
+ return useQuery22({
1107
1300
  queryKey: ["behio", "pages", locale],
1108
1301
  queryFn: async () => {
1109
1302
  const result = await unwrap(client.pages.list(locale));
@@ -1114,7 +1307,7 @@ function usePages(locale, options) {
1114
1307
  }
1115
1308
  function usePage(slug, locale, options) {
1116
1309
  const { client } = useBehio();
1117
- return useQuery17({
1310
+ return useQuery22({
1118
1311
  queryKey: ["behio", "page", slug, locale],
1119
1312
  queryFn: () => unwrap(client.pages.get(slug, locale)),
1120
1313
  enabled: options?.enabled !== false && !!slug
@@ -1122,10 +1315,10 @@ function usePage(slug, locale, options) {
1122
1315
  }
1123
1316
 
1124
1317
  // src/react/hooks/use-shop-info.ts
1125
- import { useQuery as useQuery18 } from "@tanstack/react-query";
1318
+ import { useQuery as useQuery23 } from "@tanstack/react-query";
1126
1319
  function useShopInfo(options) {
1127
1320
  const { client } = useBehio();
1128
- return useQuery18({
1321
+ return useQuery23({
1129
1322
  queryKey: ["behio", "shop-info"],
1130
1323
  queryFn: () => unwrap(client.getShopInfo()),
1131
1324
  enabled: options?.enabled !== false
@@ -1133,10 +1326,10 @@ function useShopInfo(options) {
1133
1326
  }
1134
1327
 
1135
1328
  // src/react/hooks/use-shop-scripts.ts
1136
- import { useQuery as useQuery19 } from "@tanstack/react-query";
1329
+ import { useQuery as useQuery24 } from "@tanstack/react-query";
1137
1330
  function useShopScripts(options) {
1138
1331
  const { client } = useBehio();
1139
- return useQuery19({
1332
+ return useQuery24({
1140
1333
  queryKey: ["behio", "shop-scripts"],
1141
1334
  queryFn: () => unwrap(client.getShopScripts()),
1142
1335
  enabled: options?.enabled !== false
@@ -1144,11 +1337,11 @@ function useShopScripts(options) {
1144
1337
  }
1145
1338
 
1146
1339
  // src/react/hooks/use-shop-seo.ts
1147
- import { useQuery as useQuery20 } from "@tanstack/react-query";
1340
+ import { useQuery as useQuery25 } from "@tanstack/react-query";
1148
1341
  function useShopSeo(options) {
1149
1342
  const { client } = useBehio();
1150
1343
  const { locale, initialData, enabled = true } = options ?? {};
1151
- return useQuery20({
1344
+ return useQuery25({
1152
1345
  queryKey: ["behio", "shop-seo", locale ?? "_default"],
1153
1346
  queryFn: () => unwrap(client.getShopSeo(locale)),
1154
1347
  initialData,
@@ -1208,23 +1401,23 @@ function CurrencySwitcher({
1208
1401
  }
1209
1402
 
1210
1403
  // src/react/components/storefront-scripts.tsx
1211
- import { useEffect as useEffect4, useMemo as useMemo4, useState as useState8 } from "react";
1404
+ import { useEffect as useEffect5, useMemo as useMemo4, useState as useState9 } from "react";
1212
1405
 
1213
1406
  // src/react/hooks/use-consent.ts
1214
- import { useQuery as useQuery21, useMutation as useMutation9, useQueryClient as useQueryClient9 } from "@tanstack/react-query";
1407
+ import { useQuery as useQuery26, useMutation as useMutation11, useQueryClient as useQueryClient11 } from "@tanstack/react-query";
1215
1408
  function useCookieConsent(visitorId) {
1216
1409
  const { client } = useBehio();
1217
- const qc = useQueryClient9();
1218
- const query = useQuery21({
1410
+ const qc = useQueryClient11();
1411
+ const query = useQuery26({
1219
1412
  queryKey: ["behio", "consent", visitorId],
1220
1413
  queryFn: () => unwrap(client.consent.get(visitorId)),
1221
1414
  enabled: Boolean(visitorId)
1222
1415
  });
1223
- const recordMutation = useMutation9({
1416
+ const recordMutation = useMutation11({
1224
1417
  mutationFn: (input) => unwrap(client.consent.record(input)),
1225
1418
  onSuccess: () => qc.invalidateQueries({ queryKey: ["behio", "consent"] })
1226
1419
  });
1227
- const revokeMutation = useMutation9({
1420
+ const revokeMutation = useMutation11({
1228
1421
  mutationFn: () => unwrap(client.consent.revoke(visitorId)),
1229
1422
  onSuccess: () => qc.invalidateQueries({ queryKey: ["behio", "consent"] })
1230
1423
  });
@@ -1298,8 +1491,8 @@ function injectHtml(target, html) {
1298
1491
  }
1299
1492
  function StorefrontScripts({ visitorId: visitorIdProp } = {}) {
1300
1493
  const { data } = useShopScripts();
1301
- const [visitorId, setVisitorId] = useState8(visitorIdProp ?? "");
1302
- useEffect4(() => {
1494
+ const [visitorId, setVisitorId] = useState9(visitorIdProp ?? "");
1495
+ useEffect5(() => {
1303
1496
  if (visitorIdProp) return;
1304
1497
  try {
1305
1498
  const v = localStorage.getItem(VISITOR_KEY);
@@ -1317,7 +1510,7 @@ function StorefrontScripts({ visitorId: visitorIdProp } = {}) {
1317
1510
  () => JSON.stringify(scripts.map((s) => [s.id, s.type, s.placement, s.value])),
1318
1511
  [scripts]
1319
1512
  );
1320
- useEffect4(() => {
1513
+ useEffect5(() => {
1321
1514
  if (typeof document === "undefined") return;
1322
1515
  const added = [];
1323
1516
  for (const s of scripts) {
@@ -1334,7 +1527,7 @@ function StorefrontScripts({ visitorId: visitorIdProp } = {}) {
1334
1527
  }
1335
1528
 
1336
1529
  // src/react/components/behio-analytics.tsx
1337
- import { useEffect as useEffect5 } from "react";
1530
+ import { useEffect as useEffect6 } from "react";
1338
1531
 
1339
1532
  // src/react/hooks/use-behio-client.ts
1340
1533
  function useBehioClient() {
@@ -1344,7 +1537,7 @@ function useBehioClient() {
1344
1537
  // src/react/components/behio-analytics.tsx
1345
1538
  function BehioAnalyticsTracker() {
1346
1539
  const client = useBehioClient();
1347
- useEffect5(() => {
1540
+ useEffect6(() => {
1348
1541
  if (typeof window === "undefined") return;
1349
1542
  const w = window;
1350
1543
  if (w.__behioAnalytics) return;
@@ -1473,6 +1666,18 @@ function initTracker(client) {
1473
1666
  href = void 0;
1474
1667
  }
1475
1668
  }
1669
+ const dataProps = {};
1670
+ const dataset = el.dataset;
1671
+ if (dataset) {
1672
+ for (const k of Object.keys(dataset)) {
1673
+ if (k.startsWith("behio") && k !== "behioEvent") {
1674
+ const short = k.slice("behio".length);
1675
+ const propKey = short.charAt(0).toLowerCase() + short.slice(1);
1676
+ const v = dataset[k];
1677
+ if (v != null) dataProps[propKey] = String(v).slice(0, 120);
1678
+ }
1679
+ }
1680
+ }
1476
1681
  enqueue({
1477
1682
  type: "custom",
1478
1683
  name: explicit || "click",
@@ -1481,13 +1686,29 @@ function initTracker(client) {
1481
1686
  props: {
1482
1687
  tag: el.tagName.toLowerCase(),
1483
1688
  ...text ? { text } : {},
1484
- ...href ? { href } : {}
1689
+ ...href ? { href } : {},
1690
+ ...dataProps
1485
1691
  }
1486
1692
  });
1487
1693
  };
1488
1694
  const w = window;
1489
1695
  w.__behioEcommerceSink = (event, payload) => {
1490
1696
  if (event === "purchase") return;
1697
+ const items = Array.isArray(payload.items) ? payload.items : [];
1698
+ const props = {
1699
+ ...payload.props ?? {},
1700
+ ...payload.search_term != null ? { query: payload.search_term } : {},
1701
+ ...payload.shipping_tier != null ? { shippingTier: payload.shipping_tier } : {},
1702
+ ...payload.payment_type != null ? { paymentType: payload.payment_type } : {},
1703
+ ...payload.item_list_id != null ? { listId: payload.item_list_id } : {},
1704
+ ...payload.item_list_name != null ? { listName: payload.item_list_name } : {},
1705
+ ...items.length > 0 ? {
1706
+ items: items.length,
1707
+ // First item id = the product (view_item/add_to_cart are
1708
+ // single-product in practice) - Behavioral Offers count on it.
1709
+ itemId: items[0]?.item_id
1710
+ } : {}
1711
+ };
1491
1712
  enqueue({
1492
1713
  type: "ecommerce",
1493
1714
  name: event,
@@ -1495,14 +1716,7 @@ function initTracker(client) {
1495
1716
  ts: Date.now(),
1496
1717
  ...payload.value != null ? { value: payload.value } : {},
1497
1718
  ...payload.currency ? { currency: payload.currency } : {},
1498
- ...Array.isArray(payload.items) && payload.items.length > 0 ? {
1499
- props: {
1500
- items: payload.items.length,
1501
- // First item id = the product (view_item/add_to_cart are
1502
- // single-product in practice) - Behavioral Offers count on it.
1503
- itemId: payload.items[0]?.item_id
1504
- }
1505
- } : {}
1719
+ ...Object.keys(props).length > 0 ? { props } : {}
1506
1720
  });
1507
1721
  };
1508
1722
  const origPush = history.pushState.bind(history);
@@ -1548,7 +1762,13 @@ function utmFromSearch(search) {
1548
1762
  return {
1549
1763
  utmSource: p.get("utm_source") ?? void 0,
1550
1764
  utmMedium: p.get("utm_medium") ?? void 0,
1551
- utmCampaign: p.get("utm_campaign") ?? void 0
1765
+ utmCampaign: p.get("utm_campaign") ?? void 0,
1766
+ // Extended attribution: paid-search term/content + click ids. The
1767
+ // backend folds these into event props (raw columns unchanged).
1768
+ utmTerm: p.get("utm_term") ?? void 0,
1769
+ utmContent: p.get("utm_content") ?? void 0,
1770
+ gclid: p.get("gclid") ?? void 0,
1771
+ fbclid: p.get("fbclid") ?? void 0
1552
1772
  };
1553
1773
  } catch {
1554
1774
  return {};
@@ -1556,10 +1776,10 @@ function utmFromSearch(search) {
1556
1776
  }
1557
1777
 
1558
1778
  // src/react/hooks/use-bundles.ts
1559
- import { useQuery as useQuery22 } from "@tanstack/react-query";
1779
+ import { useQuery as useQuery27 } from "@tanstack/react-query";
1560
1780
  function useBundles(options) {
1561
1781
  const { client } = useBehio();
1562
- return useQuery22({
1782
+ return useQuery27({
1563
1783
  queryKey: ["behio", "bundles"],
1564
1784
  queryFn: () => unwrap(client.catalog.getBundles()),
1565
1785
  enabled: options?.enabled ?? true,
@@ -1568,7 +1788,7 @@ function useBundles(options) {
1568
1788
  }
1569
1789
  function useBundle(slug, options) {
1570
1790
  const { client } = useBehio();
1571
- return useQuery22({
1791
+ return useQuery27({
1572
1792
  queryKey: ["behio", "bundle", slug],
1573
1793
  queryFn: () => unwrap(client.catalog.getBundle(slug)),
1574
1794
  enabled: Boolean(slug) && (options?.enabled ?? true),
@@ -1577,10 +1797,10 @@ function useBundle(slug, options) {
1577
1797
  }
1578
1798
 
1579
1799
  // src/react/hooks/use-product-group.ts
1580
- import { useQuery as useQuery23 } from "@tanstack/react-query";
1800
+ import { useQuery as useQuery28 } from "@tanstack/react-query";
1581
1801
  function useProductGroup(slug, options) {
1582
1802
  const { client } = useBehio();
1583
- return useQuery23({
1803
+ return useQuery28({
1584
1804
  queryKey: ["behio", "product-group", slug, options?.locale, options?.currency],
1585
1805
  queryFn: () => unwrap(
1586
1806
  client.catalog.getProductGroup(slug, {
@@ -1594,10 +1814,10 @@ function useProductGroup(slug, options) {
1594
1814
  }
1595
1815
 
1596
1816
  // src/react/hooks/use-cross-sell.ts
1597
- import { useQuery as useQuery24 } from "@tanstack/react-query";
1817
+ import { useQuery as useQuery29 } from "@tanstack/react-query";
1598
1818
  function useCrossSell(productSlug, options) {
1599
1819
  const { client } = useBehio();
1600
- return useQuery24({
1820
+ return useQuery29({
1601
1821
  queryKey: ["behio", "cross-sell", productSlug, options?.locale, options?.currency],
1602
1822
  queryFn: () => unwrap(
1603
1823
  client.catalog.getCrossSell(productSlug, {
@@ -1611,10 +1831,10 @@ function useCrossSell(productSlug, options) {
1611
1831
  }
1612
1832
 
1613
1833
  // src/react/hooks/use-product-promotions.ts
1614
- import { useQuery as useQuery25 } from "@tanstack/react-query";
1834
+ import { useQuery as useQuery30 } from "@tanstack/react-query";
1615
1835
  function useProductPromotions(productSlug, options) {
1616
1836
  const { client } = useBehio();
1617
- return useQuery25({
1837
+ return useQuery30({
1618
1838
  queryKey: ["behio", "product-promotions", productSlug],
1619
1839
  queryFn: () => unwrap(client.catalog.getProductPromotions(productSlug)),
1620
1840
  enabled: Boolean(productSlug) && (options?.enabled ?? true),
@@ -1623,11 +1843,11 @@ function useProductPromotions(productSlug, options) {
1623
1843
  }
1624
1844
 
1625
1845
  // src/react/hooks/use-gift-card.ts
1626
- import { useQuery as useQuery26 } from "@tanstack/react-query";
1846
+ import { useQuery as useQuery31 } from "@tanstack/react-query";
1627
1847
  function useGiftCardBalance(code, options) {
1628
1848
  const { client } = useBehio();
1629
1849
  const trimmed = code?.trim();
1630
- return useQuery26({
1850
+ return useQuery31({
1631
1851
  queryKey: ["behio", "gift-card-balance", trimmed],
1632
1852
  queryFn: () => unwrap(client.catalog.checkGiftCard(trimmed)),
1633
1853
  enabled: Boolean(trimmed && trimmed.length >= 6) && (options?.enabled ?? true)
@@ -1635,20 +1855,20 @@ function useGiftCardBalance(code, options) {
1635
1855
  }
1636
1856
 
1637
1857
  // src/react/hooks/use-wishlist.ts
1638
- import { useQuery as useQuery27, useMutation as useMutation10, useQueryClient as useQueryClient10 } from "@tanstack/react-query";
1858
+ import { useQuery as useQuery32, useMutation as useMutation12, useQueryClient as useQueryClient12 } from "@tanstack/react-query";
1639
1859
  function useWishlist(options) {
1640
1860
  const { client } = useBehio();
1641
- const qc = useQueryClient10();
1642
- const query = useQuery27({
1861
+ const qc = useQueryClient12();
1862
+ const query = useQuery32({
1643
1863
  queryKey: ["behio", "wishlist"],
1644
1864
  queryFn: () => unwrap(client.wishlist.get()),
1645
1865
  enabled: options?.enabled ?? true
1646
1866
  });
1647
- const addMutation = useMutation10({
1867
+ const addMutation = useMutation12({
1648
1868
  mutationFn: (productId) => unwrap(client.wishlist.add(productId)),
1649
1869
  onSuccess: () => qc.invalidateQueries({ queryKey: ["behio", "wishlist"] })
1650
1870
  });
1651
- const removeMutation = useMutation10({
1871
+ const removeMutation = useMutation12({
1652
1872
  mutationFn: (productId) => unwrap(client.wishlist.remove(productId)),
1653
1873
  onSuccess: () => qc.invalidateQueries({ queryKey: ["behio", "wishlist"] })
1654
1874
  });
@@ -1662,7 +1882,7 @@ function useWishlist(options) {
1662
1882
  }
1663
1883
  function useIsInWishlist(productId) {
1664
1884
  const { client } = useBehio();
1665
- return useQuery27({
1885
+ return useQuery32({
1666
1886
  queryKey: ["behio", "wishlist-check", productId],
1667
1887
  queryFn: () => unwrap(client.wishlist.isInWishlist(productId)),
1668
1888
  enabled: Boolean(productId)
@@ -1670,10 +1890,10 @@ function useIsInWishlist(productId) {
1670
1890
  }
1671
1891
 
1672
1892
  // src/react/hooks/use-reviews.ts
1673
- import { useQuery as useQuery28, useMutation as useMutation11, useQueryClient as useQueryClient11 } from "@tanstack/react-query";
1893
+ import { useQuery as useQuery33, useMutation as useMutation13, useQueryClient as useQueryClient13 } from "@tanstack/react-query";
1674
1894
  function useProductReviews(productId, options) {
1675
1895
  const { client } = useBehio();
1676
- return useQuery28({
1896
+ return useQuery33({
1677
1897
  queryKey: ["behio", "reviews", productId, options?.page ?? 1],
1678
1898
  queryFn: () => unwrap(client.reviews.getProductReviews(productId, options?.page, options?.limit)),
1679
1899
  enabled: Boolean(productId) && (options?.enabled ?? true)
@@ -1681,30 +1901,30 @@ function useProductReviews(productId, options) {
1681
1901
  }
1682
1902
  function useSubmitReview() {
1683
1903
  const { client } = useBehio();
1684
- const qc = useQueryClient11();
1685
- return useMutation11({
1904
+ const qc = useQueryClient13();
1905
+ return useMutation13({
1686
1906
  mutationFn: (input) => unwrap(client.reviews.submit(input)),
1687
1907
  onSuccess: (_, input) => qc.invalidateQueries({ queryKey: ["behio", "reviews", input.productId] })
1688
1908
  });
1689
1909
  }
1690
1910
 
1691
1911
  // src/react/hooks/use-returns.ts
1692
- import { useQuery as useQuery29, useMutation as useMutation12 } from "@tanstack/react-query";
1912
+ import { useQuery as useQuery34, useMutation as useMutation14 } from "@tanstack/react-query";
1693
1913
  function useLookupReturnableOrder() {
1694
1914
  const { client } = useBehio();
1695
- return useMutation12({
1915
+ return useMutation14({
1696
1916
  mutationFn: ({ orderNumber, email }) => unwrap(client.returns.lookupOrder(orderNumber, email))
1697
1917
  });
1698
1918
  }
1699
1919
  function useSubmitReturn() {
1700
1920
  const { client } = useBehio();
1701
- return useMutation12({
1921
+ return useMutation14({
1702
1922
  mutationFn: (input) => unwrap(client.returns.submit(input))
1703
1923
  });
1704
1924
  }
1705
1925
  function useReturnStatus(returnId, email) {
1706
1926
  const { client } = useBehio();
1707
- return useQuery29({
1927
+ return useQuery34({
1708
1928
  queryKey: ["behio", "return-status", returnId],
1709
1929
  queryFn: () => unwrap(client.returns.getStatus(returnId, email)),
1710
1930
  enabled: Boolean(returnId && email)
@@ -1712,16 +1932,16 @@ function useReturnStatus(returnId, email) {
1712
1932
  }
1713
1933
 
1714
1934
  // src/react/hooks/use-quotes.ts
1715
- import { useMutation as useMutation13, useQuery as useQuery30 } from "@tanstack/react-query";
1935
+ import { useMutation as useMutation15, useQuery as useQuery35 } from "@tanstack/react-query";
1716
1936
  function useSubmitQuote() {
1717
1937
  const { client } = useBehio();
1718
- return useMutation13({
1938
+ return useMutation15({
1719
1939
  mutationFn: (input) => unwrap(client.quotes.submit(input))
1720
1940
  });
1721
1941
  }
1722
1942
  function useQuoteStatus(quoteId, email) {
1723
1943
  const { client } = useBehio();
1724
- return useQuery30({
1944
+ return useQuery35({
1725
1945
  queryKey: ["behio", "quote-status", quoteId],
1726
1946
  queryFn: () => unwrap(client.quotes.getStatus(quoteId, email)),
1727
1947
  enabled: Boolean(quoteId && email)
@@ -1729,10 +1949,10 @@ function useQuoteStatus(quoteId, email) {
1729
1949
  }
1730
1950
 
1731
1951
  // src/react/hooks/use-back-in-stock.ts
1732
- import { useMutation as useMutation14 } from "@tanstack/react-query";
1952
+ import { useMutation as useMutation16 } from "@tanstack/react-query";
1733
1953
  function useNotifyWhenAvailable() {
1734
1954
  const { client } = useBehio();
1735
- return useMutation14({
1955
+ return useMutation16({
1736
1956
  mutationFn: ({ productId, email }) => unwrap(client.catalog.notifyWhenAvailable(productId, email))
1737
1957
  });
1738
1958
  }
@@ -1745,11 +1965,16 @@ export {
1745
1965
  createMemoryStorage,
1746
1966
  detectStorage,
1747
1967
  formatPrice,
1968
+ generateVisitorId,
1969
+ getStoredVisitorId,
1970
+ grantAnalyticsConsent,
1748
1971
  localStorageAdapter,
1749
1972
  memoryStorage,
1973
+ revokeAnalyticsConsent,
1750
1974
  trackEcommerceEvent,
1751
1975
  useAddressAutocomplete,
1752
1976
  useAddresses,
1977
+ useAnalyticsEvents,
1753
1978
  useAuth,
1754
1979
  useBehio,
1755
1980
  useBehioClient,
@@ -1780,6 +2005,8 @@ export {
1780
2005
  useOrders,
1781
2006
  usePage,
1782
2007
  usePages,
2008
+ usePaymentMethods,
2009
+ usePersonalOffers,
1783
2010
  usePickupPoints,
1784
2011
  useProduct,
1785
2012
  useProductGroup,
@@ -1789,11 +2016,14 @@ export {
1789
2016
  useQuoteStatus,
1790
2017
  useReturnStatus,
1791
2018
  useSearch,
2019
+ useShippingMethods,
2020
+ useShippingQuote,
1792
2021
  useShopInfo,
1793
2022
  useShopScripts,
1794
2023
  useShopSeo,
1795
2024
  useSubmitQuote,
1796
2025
  useSubmitReturn,
1797
2026
  useSubmitReview,
2027
+ useSubscriptions,
1798
2028
  useWishlist
1799
2029
  };