@behio/storefront-sdk 1.8.0 → 1.17.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/README.md +11 -9
- package/dist/{chunk-LQ4GGXMJ.js → chunk-FMMFIZHA.js} +188 -26
- package/dist/{chunk-LA6K4KYS.mjs → chunk-PU4QV6JS.mjs} +163 -1
- package/dist/{client-BP9n3a_D.d.mts → client-yo90ANGT.d.mts} +414 -4
- package/dist/{client-BP9n3a_D.d.ts → client-yo90ANGT.d.ts} +414 -4
- package/dist/index.d.mts +44 -3
- package/dist/index.d.ts +44 -3
- package/dist/index.js +743 -2
- package/dist/index.mjs +742 -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 +503 -10
- package/dist/react.d.ts +503 -10
- package/dist/react.js +457 -92
- package/dist/react.mjs +440 -81
- package/package.json +2 -2
package/dist/react.js
CHANGED
|
@@ -42,6 +42,9 @@ __export(react_exports, {
|
|
|
42
42
|
useAuth: () => useAuth,
|
|
43
43
|
useBehio: () => useBehio,
|
|
44
44
|
useBehioClient: () => useBehioClient,
|
|
45
|
+
useBlogPost: () => useBlogPost,
|
|
46
|
+
useBlogPosts: () => useBlogPosts,
|
|
47
|
+
useBlogs: () => useBlogs,
|
|
45
48
|
useBundle: () => useBundle,
|
|
46
49
|
useBundles: () => useBundles,
|
|
47
50
|
useCart: () => useCart,
|
|
@@ -95,10 +98,13 @@ __export(react_exports, {
|
|
|
95
98
|
useShopInfo: () => useShopInfo,
|
|
96
99
|
useShopScripts: () => useShopScripts,
|
|
97
100
|
useShopSeo: () => useShopSeo,
|
|
101
|
+
useSiteForm: () => useSiteForm,
|
|
102
|
+
useSiteFormSubmit: () => useSiteFormSubmit,
|
|
98
103
|
useSubmitQuote: () => useSubmitQuote,
|
|
99
104
|
useSubmitReturn: () => useSubmitReturn,
|
|
100
105
|
useSubmitReview: () => useSubmitReview,
|
|
101
106
|
useSubscriptions: () => useSubscriptions,
|
|
107
|
+
useVisitorMessages: () => useVisitorMessages,
|
|
102
108
|
useWishlist: () => useWishlist
|
|
103
109
|
});
|
|
104
110
|
module.exports = __toCommonJS(react_exports);
|
|
@@ -108,6 +114,38 @@ var import_react2 = require("react");
|
|
|
108
114
|
var import_react_query = require("@tanstack/react-query");
|
|
109
115
|
|
|
110
116
|
// src/types.ts
|
|
117
|
+
var BE_CODE_TO_ERROR = {
|
|
118
|
+
"be.storefront.cartIsEmpty": "CART_EMPTY",
|
|
119
|
+
"be.storefront.productNotFound": "PRODUCT_NOT_FOUND",
|
|
120
|
+
"be.storefront.productNotAvailable": "PRODUCT_NOT_FOUND",
|
|
121
|
+
"be.storefront.invalidEmailOrPassword": "INVALID_CREDENTIALS",
|
|
122
|
+
"be.storefront.currentPasswordIncorrect": "INVALID_CREDENTIALS",
|
|
123
|
+
"be.storefront.discountExpired": "DISCOUNT_EXPIRED",
|
|
124
|
+
"be.storefront.discountExpiredOrLimit": "DISCOUNT_EXPIRED",
|
|
125
|
+
"be.storefront.invalidDiscountCode": "INVALID_DISCOUNT",
|
|
126
|
+
"be.storefront.discountInvalid": "INVALID_DISCOUNT",
|
|
127
|
+
"be.storefront.discountInactive": "INVALID_DISCOUNT",
|
|
128
|
+
"be.storefront.discountWrongCurrency": "INVALID_DISCOUNT",
|
|
129
|
+
"be.storefront.discountNotApplicable": "INVALID_DISCOUNT",
|
|
130
|
+
"be.storefront.discountNotYetValid": "INVALID_DISCOUNT",
|
|
131
|
+
"be.storefront.discountUsageLimitReached": "INVALID_DISCOUNT",
|
|
132
|
+
"be.storefront.discountLimitedToGroups": "INVALID_DISCOUNT",
|
|
133
|
+
"be.storefront.tokenInvalid": "TOKEN_INVALID",
|
|
134
|
+
"be.storefront.orderAccessTokenInvalid": "TOKEN_INVALID",
|
|
135
|
+
"be.storefront.resetTokenInvalid": "TOKEN_INVALID",
|
|
136
|
+
"be.storefront.invalidVerificationToken": "TOKEN_INVALID",
|
|
137
|
+
"be.storefront.invalidRefreshToken": "TOKEN_INVALID",
|
|
138
|
+
"be.storefront.refreshTokenExpired": "TOKEN_EXPIRED",
|
|
139
|
+
"be.storefront.apiKeyExpired": "TOKEN_EXPIRED",
|
|
140
|
+
"be.storefront.customerEmailTaken": "EMAIL_ALREADY_EXISTS",
|
|
141
|
+
"be.storefront.orderNotCancellable": "ORDER_NOT_CANCELLABLE",
|
|
142
|
+
"be.storefront.orderCancelledNotReturnable": "ORDER_NOT_CANCELLABLE",
|
|
143
|
+
"be.validation.failed": "VALIDATION_ERROR",
|
|
144
|
+
"be.forms.formNotFound": "NOT_FOUND",
|
|
145
|
+
"be.forms.validationFailed": "VALIDATION_ERROR",
|
|
146
|
+
"be.forms.consentRequired": "VALIDATION_ERROR",
|
|
147
|
+
"be.forms.tooLarge": "VALIDATION_ERROR"
|
|
148
|
+
};
|
|
111
149
|
var BehioApiError = class _BehioApiError extends Error {
|
|
112
150
|
constructor(status, body, message) {
|
|
113
151
|
super(message || `API Error ${status}`);
|
|
@@ -124,6 +162,11 @@ var BehioApiError = class _BehioApiError extends Error {
|
|
|
124
162
|
if (status === 409) return "EMAIL_ALREADY_EXISTS";
|
|
125
163
|
if (status === 429) return "RATE_LIMITED";
|
|
126
164
|
if (status >= 500) return "INTERNAL_ERROR";
|
|
165
|
+
const rawCode = body?.code;
|
|
166
|
+
if (typeof rawCode === "string") {
|
|
167
|
+
const mapped = BE_CODE_TO_ERROR[rawCode];
|
|
168
|
+
if (mapped) return mapped;
|
|
169
|
+
}
|
|
127
170
|
const msg = (body?.message || "").toLowerCase();
|
|
128
171
|
if (msg.includes("invalid") && msg.includes("password"))
|
|
129
172
|
return "INVALID_CREDENTIALS";
|
|
@@ -229,6 +272,8 @@ var BehioStorefront = class {
|
|
|
229
272
|
this.orders = new OrdersModule(this);
|
|
230
273
|
this.customer = new CustomerModule(this);
|
|
231
274
|
this.pages = new PagesModule(this);
|
|
275
|
+
this.blog = new BlogModule(this);
|
|
276
|
+
this.forms = new FormsModule(this);
|
|
232
277
|
this.wishlist = new WishlistModule(this);
|
|
233
278
|
this.reviews = new ReviewsModule(this);
|
|
234
279
|
this.returns = new ReturnsModule(this);
|
|
@@ -297,6 +342,21 @@ var BehioStorefront = class {
|
|
|
297
342
|
body: input
|
|
298
343
|
});
|
|
299
344
|
}
|
|
345
|
+
/**
|
|
346
|
+
* Visitor messages from merchant automations (storefront.event action).
|
|
347
|
+
* Consent-gated visitor id; each message carries a merchant-defined `name`
|
|
348
|
+
* and free-form `payload` the template reacts to (modal, banner, ...).
|
|
349
|
+
* Messages stay listed until acknowledged via `ackVisitorMessage`.
|
|
350
|
+
*/
|
|
351
|
+
async getVisitorMessages(visitorId) {
|
|
352
|
+
return this.request("GET", "/messages", { query: { visitorId } });
|
|
353
|
+
}
|
|
354
|
+
/** Acknowledge a visitor message so it is not delivered again. */
|
|
355
|
+
async ackVisitorMessage(messageId, visitorId) {
|
|
356
|
+
return this.request("POST", `/messages/${messageId}/ack`, {
|
|
357
|
+
query: { visitorId }
|
|
358
|
+
});
|
|
359
|
+
}
|
|
300
360
|
/** Get basic shop info */
|
|
301
361
|
async getShopInfo() {
|
|
302
362
|
return this.request("GET", "/shop");
|
|
@@ -916,16 +976,27 @@ var CatalogModule = class {
|
|
|
916
976
|
{ body: input }
|
|
917
977
|
);
|
|
918
978
|
}
|
|
919
|
-
/**
|
|
979
|
+
/**
|
|
980
|
+
* List configured payment methods (filtered by currency). `locale` picks the
|
|
981
|
+
* language of `instruments[].label` / `swifts[].label` (SDK 1.14.0); pass the
|
|
982
|
+
* locale of the page so the instrument tiles read in the shopper's language.
|
|
983
|
+
*/
|
|
920
984
|
async listPaymentMethods(opts) {
|
|
921
985
|
const query = {};
|
|
922
986
|
if (opts?.currency) query.currency = opts.currency;
|
|
987
|
+
if (opts?.locale) query.locale = opts.locale;
|
|
988
|
+
if (opts?.country) query.country = opts.country;
|
|
989
|
+
if (opts?.shippingMethodId) query.shippingMethodId = opts.shippingMethodId;
|
|
923
990
|
return this.client.request(
|
|
924
991
|
"GET",
|
|
925
992
|
"/catalog/payment-methods",
|
|
926
993
|
{ query }
|
|
927
994
|
);
|
|
928
995
|
}
|
|
996
|
+
/** Alias of `listPaymentMethods` (SDK 1.14.0). */
|
|
997
|
+
paymentMethods(opts) {
|
|
998
|
+
return this.listPaymentMethods(opts);
|
|
999
|
+
}
|
|
929
1000
|
};
|
|
930
1001
|
var AuthModule = class {
|
|
931
1002
|
constructor(client) {
|
|
@@ -1079,6 +1150,26 @@ var CartModule = class {
|
|
|
1079
1150
|
this.client.emit("cart:updated", res.data);
|
|
1080
1151
|
return res;
|
|
1081
1152
|
}
|
|
1153
|
+
/**
|
|
1154
|
+
* Tell the cart where the order will ship (and, for B2B, the buyer's VAT
|
|
1155
|
+
* ID) so the VAT breakdown matches the checkout before the address form:
|
|
1156
|
+
* destination-country rate (OSS), 0 % export outside the EU, or reverse
|
|
1157
|
+
* charge for an EU business with a VIES-valid VAT ID. `cart.vatMode` says
|
|
1158
|
+
* which rule applied. SDK 1.17.0.
|
|
1159
|
+
*
|
|
1160
|
+
* ```ts
|
|
1161
|
+
* await client.cart.setDestination({ country: "SK" });
|
|
1162
|
+
* await client.cart.setDestination({ vatId: "SK2020000001" }); // "" clears
|
|
1163
|
+
* ```
|
|
1164
|
+
*/
|
|
1165
|
+
async setDestination(input) {
|
|
1166
|
+
const res = await this.client.request("PUT", "/cart/destination", {
|
|
1167
|
+
body: input
|
|
1168
|
+
});
|
|
1169
|
+
if (res.error) return res;
|
|
1170
|
+
this.client.emit("cart:updated", res.data);
|
|
1171
|
+
return res;
|
|
1172
|
+
}
|
|
1082
1173
|
/** Update item quantity */
|
|
1083
1174
|
async updateQuantity(itemId, quantity) {
|
|
1084
1175
|
const res = await this.client.request(
|
|
@@ -1230,6 +1321,30 @@ var OrdersModule = class {
|
|
|
1230
1321
|
constructor(client) {
|
|
1231
1322
|
this.client = client;
|
|
1232
1323
|
}
|
|
1324
|
+
/**
|
|
1325
|
+
* Ask the backend to re-check this order's payment with the gateway.
|
|
1326
|
+
*
|
|
1327
|
+
* Call it on the thank-you page the customer lands on after paying, BEFORE
|
|
1328
|
+
* you read the order. Some gateways (Tatrapay+) have no server-to-server
|
|
1329
|
+
* notification at all, so the customer's return is the only fast way the
|
|
1330
|
+
* payment gets confirmed; for the others it is a safety net for a lost
|
|
1331
|
+
* notification.
|
|
1332
|
+
*
|
|
1333
|
+
* The response is deliberately opaque (`{ok: true}` every time, even for an
|
|
1334
|
+
* order number that does not exist): order numbers are sequential, so
|
|
1335
|
+
* anything else would turn this into a probe for other people's orders.
|
|
1336
|
+
* Read the actual state afterwards through a path that proves entitlement
|
|
1337
|
+
* ({@link get}, {@link track} or the guest access-code flow).
|
|
1338
|
+
*
|
|
1339
|
+
* Never throws for a missing order and never blocks the page: treat a
|
|
1340
|
+
* failure as "not confirmed yet", the backend poller catches up on its own.
|
|
1341
|
+
*/
|
|
1342
|
+
async syncPaymentOnReturn(orderNumber) {
|
|
1343
|
+
return this.client.request(
|
|
1344
|
+
"POST",
|
|
1345
|
+
`/payments/return/${orderNumber}`
|
|
1346
|
+
);
|
|
1347
|
+
}
|
|
1233
1348
|
/** List customer orders (requires auth) */
|
|
1234
1349
|
async list(options) {
|
|
1235
1350
|
return this.client.request(
|
|
@@ -1582,6 +1697,59 @@ var PagesModule = class {
|
|
|
1582
1697
|
});
|
|
1583
1698
|
}
|
|
1584
1699
|
};
|
|
1700
|
+
var BlogModule = class {
|
|
1701
|
+
constructor(client) {
|
|
1702
|
+
this.client = client;
|
|
1703
|
+
}
|
|
1704
|
+
/** List the site's blogs (active only). */
|
|
1705
|
+
async list(locale) {
|
|
1706
|
+
return this.client.request("GET", "/blogs", {
|
|
1707
|
+
query: { locale }
|
|
1708
|
+
});
|
|
1709
|
+
}
|
|
1710
|
+
/** Published posts of one blog, newest first (featured first), paginated. */
|
|
1711
|
+
async posts(handle, query = {}) {
|
|
1712
|
+
return this.client.request("GET", `/blogs/${handle}/posts`, {
|
|
1713
|
+
query: {
|
|
1714
|
+
locale: query.locale,
|
|
1715
|
+
page: query.page,
|
|
1716
|
+
limit: query.limit,
|
|
1717
|
+
tag: query.tag
|
|
1718
|
+
}
|
|
1719
|
+
});
|
|
1720
|
+
}
|
|
1721
|
+
/** One published post with sanitised HTML content and related posts. */
|
|
1722
|
+
async post(handle, slug, locale) {
|
|
1723
|
+
return this.client.request("GET", `/blogs/${handle}/posts/${slug}`, {
|
|
1724
|
+
query: { locale }
|
|
1725
|
+
});
|
|
1726
|
+
}
|
|
1727
|
+
};
|
|
1728
|
+
var FormsModule = class {
|
|
1729
|
+
constructor(client) {
|
|
1730
|
+
this.client = client;
|
|
1731
|
+
}
|
|
1732
|
+
/** Public definition of one form (fields + settings). 404 for an unknown or inactive slug. */
|
|
1733
|
+
async get(slug) {
|
|
1734
|
+
return this.client.request(
|
|
1735
|
+
"GET",
|
|
1736
|
+
`/forms/${encodeURIComponent(slug)}`
|
|
1737
|
+
);
|
|
1738
|
+
}
|
|
1739
|
+
/**
|
|
1740
|
+
* Submit a response. On `be.forms.validationFailed` the returned error
|
|
1741
|
+
* carries per-field codes: read them with `formFieldErrors(error)`. Other
|
|
1742
|
+
* rejections: `be.forms.consentRequired`, `be.forms.tooLarge`,
|
|
1743
|
+
* `be.forms.formNotFound`; rate limit 10 submits per minute per visitor.
|
|
1744
|
+
*/
|
|
1745
|
+
async submit(slug, input) {
|
|
1746
|
+
return this.client.request(
|
|
1747
|
+
"POST",
|
|
1748
|
+
`/forms/${encodeURIComponent(slug)}/submit`,
|
|
1749
|
+
{ body: input, auth: false }
|
|
1750
|
+
);
|
|
1751
|
+
}
|
|
1752
|
+
};
|
|
1585
1753
|
var WishlistModule = class {
|
|
1586
1754
|
constructor(client) {
|
|
1587
1755
|
this.client = client;
|
|
@@ -3169,9 +3337,10 @@ var import_react_query27 = require("@tanstack/react-query");
|
|
|
3169
3337
|
function usePaymentMethods(options) {
|
|
3170
3338
|
const { client, currency: activeCurrency } = useBehio();
|
|
3171
3339
|
const currency = options?.currency ?? activeCurrency;
|
|
3340
|
+
const locale = options?.locale;
|
|
3172
3341
|
const { data, isLoading, error, refetch } = (0, import_react_query27.useQuery)({
|
|
3173
|
-
queryKey: ["behio", "payment-methods", currency ?? ""],
|
|
3174
|
-
queryFn: () => unwrap(client.catalog.listPaymentMethods({ currency })),
|
|
3342
|
+
queryKey: ["behio", "payment-methods", currency ?? "", locale ?? ""],
|
|
3343
|
+
queryFn: () => unwrap(client.catalog.listPaymentMethods({ currency, ...locale ? { locale } : {} })),
|
|
3175
3344
|
enabled: options?.enabled !== false
|
|
3176
3345
|
});
|
|
3177
3346
|
return { methods: data?.items ?? [], isLoading, error, refetch };
|
|
@@ -3236,11 +3405,78 @@ function usePersonalOffers(options) {
|
|
|
3236
3405
|
};
|
|
3237
3406
|
}
|
|
3238
3407
|
|
|
3239
|
-
// src/react/hooks/use-
|
|
3408
|
+
// src/react/hooks/use-visitor-messages.ts
|
|
3240
3409
|
var import_react11 = require("react");
|
|
3410
|
+
var import_react_query29 = require("@tanstack/react-query");
|
|
3411
|
+
function useVisitorMessages(options) {
|
|
3412
|
+
const { client } = useBehio();
|
|
3413
|
+
const queryClient = (0, import_react_query29.useQueryClient)();
|
|
3414
|
+
const [polledVid, setPolledVid] = (0, import_react11.useState)(null);
|
|
3415
|
+
const seenRef = (0, import_react11.useRef)(/* @__PURE__ */ new Set());
|
|
3416
|
+
const explicitVid = options?.visitorId;
|
|
3417
|
+
(0, import_react11.useEffect)(() => {
|
|
3418
|
+
if (explicitVid) return;
|
|
3419
|
+
const read = () => {
|
|
3420
|
+
const vid = client.getAnalyticsVisitorId();
|
|
3421
|
+
if (vid) setPolledVid(vid);
|
|
3422
|
+
return vid;
|
|
3423
|
+
};
|
|
3424
|
+
if (read()) return;
|
|
3425
|
+
const timer = setInterval(() => {
|
|
3426
|
+
if (read()) clearInterval(timer);
|
|
3427
|
+
}, 3e3);
|
|
3428
|
+
return () => clearInterval(timer);
|
|
3429
|
+
}, [client, explicitVid]);
|
|
3430
|
+
const visitorId = explicitVid ?? polledVid;
|
|
3431
|
+
const pollMs = options?.pollMs ?? 3e4;
|
|
3432
|
+
const queryKey = ["behio", "visitor-messages", visitorId ?? ""];
|
|
3433
|
+
const { data, isLoading, error, refetch } = (0, import_react_query29.useQuery)({
|
|
3434
|
+
queryKey,
|
|
3435
|
+
queryFn: () => unwrap(client.getVisitorMessages(visitorId)),
|
|
3436
|
+
enabled: options?.enabled !== false && !!visitorId,
|
|
3437
|
+
refetchInterval: pollMs > 0 ? pollMs : false
|
|
3438
|
+
});
|
|
3439
|
+
const ack = (0, import_react11.useCallback)(
|
|
3440
|
+
async (messageId) => {
|
|
3441
|
+
if (!visitorId) return false;
|
|
3442
|
+
const result = await unwrap(client.ackVisitorMessage(messageId, visitorId));
|
|
3443
|
+
queryClient.setQueryData(
|
|
3444
|
+
queryKey,
|
|
3445
|
+
(prev) => prev ? { items: prev.items.filter((m) => m.id !== messageId) } : prev
|
|
3446
|
+
);
|
|
3447
|
+
return result.ok;
|
|
3448
|
+
},
|
|
3449
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3450
|
+
[client, visitorId, queryClient]
|
|
3451
|
+
);
|
|
3452
|
+
const onMessage = options?.onMessage;
|
|
3453
|
+
const dispatchDom = options?.dispatchDomEvents !== false;
|
|
3454
|
+
(0, import_react11.useEffect)(() => {
|
|
3455
|
+
for (const message of data?.items ?? []) {
|
|
3456
|
+
if (seenRef.current.has(message.id)) continue;
|
|
3457
|
+
seenRef.current.add(message.id);
|
|
3458
|
+
if (dispatchDom && typeof window !== "undefined") {
|
|
3459
|
+
window.dispatchEvent(new CustomEvent("behio:visitor-message", { detail: message }));
|
|
3460
|
+
}
|
|
3461
|
+
onMessage?.(message);
|
|
3462
|
+
}
|
|
3463
|
+
}, [data, onMessage, dispatchDom]);
|
|
3464
|
+
return {
|
|
3465
|
+
messages: data?.items ?? [],
|
|
3466
|
+
isLoading,
|
|
3467
|
+
error,
|
|
3468
|
+
refetch,
|
|
3469
|
+
/** Mark a message as shown; it will not be delivered again. */
|
|
3470
|
+
ack,
|
|
3471
|
+
visitorId
|
|
3472
|
+
};
|
|
3473
|
+
}
|
|
3474
|
+
|
|
3475
|
+
// src/react/hooks/use-analytics-events.ts
|
|
3476
|
+
var import_react12 = require("react");
|
|
3241
3477
|
function useAnalyticsEvents() {
|
|
3242
3478
|
const { client } = useBehio();
|
|
3243
|
-
const track = (0,
|
|
3479
|
+
const track = (0, import_react12.useCallback)(
|
|
3244
3480
|
(events, opts) => {
|
|
3245
3481
|
const list = Array.isArray(events) ? events : [events];
|
|
3246
3482
|
if (list.length === 0) return Promise.resolve();
|
|
@@ -3252,7 +3488,7 @@ function useAnalyticsEvents() {
|
|
|
3252
3488
|
},
|
|
3253
3489
|
[client]
|
|
3254
3490
|
);
|
|
3255
|
-
const trackEvent = (0,
|
|
3491
|
+
const trackEvent = (0, import_react12.useCallback)(
|
|
3256
3492
|
(name, props) => track({ type: "custom", name, props }),
|
|
3257
3493
|
[track]
|
|
3258
3494
|
);
|
|
@@ -3267,28 +3503,28 @@ function useAnalyticsEvents() {
|
|
|
3267
3503
|
}
|
|
3268
3504
|
|
|
3269
3505
|
// src/react/hooks/use-newsletter.ts
|
|
3270
|
-
var
|
|
3506
|
+
var import_react_query30 = require("@tanstack/react-query");
|
|
3271
3507
|
function useNewsletterSubscribe() {
|
|
3272
3508
|
const { client } = useBehio();
|
|
3273
|
-
return (0,
|
|
3509
|
+
return (0, import_react_query30.useMutation)({
|
|
3274
3510
|
mutationFn: (input) => unwrap(client.newsletter.subscribe(input))
|
|
3275
3511
|
});
|
|
3276
3512
|
}
|
|
3277
3513
|
function useNewsletterUnsubscribe() {
|
|
3278
3514
|
const { client } = useBehio();
|
|
3279
|
-
return (0,
|
|
3515
|
+
return (0, import_react_query30.useMutation)({
|
|
3280
3516
|
mutationFn: (email) => unwrap(client.newsletter.unsubscribe(email))
|
|
3281
3517
|
});
|
|
3282
3518
|
}
|
|
3283
3519
|
|
|
3284
3520
|
// src/react/hooks/use-orders.ts
|
|
3285
|
-
var
|
|
3286
|
-
var
|
|
3521
|
+
var import_react13 = require("react");
|
|
3522
|
+
var import_react_query31 = require("@tanstack/react-query");
|
|
3287
3523
|
function useOrders(options) {
|
|
3288
3524
|
const { client } = useBehio();
|
|
3289
3525
|
const { page: initialPage, limit, enabled } = options ?? {};
|
|
3290
|
-
const [page, setPage] = (0,
|
|
3291
|
-
const infinite = (0,
|
|
3526
|
+
const [page, setPage] = (0, import_react13.useState)(initialPage ?? 1);
|
|
3527
|
+
const infinite = (0, import_react_query31.useInfiniteQuery)({
|
|
3292
3528
|
queryKey: ["behio", "orders", limit, page],
|
|
3293
3529
|
queryFn: ({ pageParam }) => unwrap(client.orders.list({ limit, page: pageParam })),
|
|
3294
3530
|
initialPageParam: page,
|
|
@@ -3296,18 +3532,18 @@ function useOrders(options) {
|
|
|
3296
3532
|
getPreviousPageParam: (firstPage) => firstPage.page > 1 ? firstPage.page - 1 : void 0,
|
|
3297
3533
|
enabled: enabled !== false && !!client.getAccessToken()
|
|
3298
3534
|
});
|
|
3299
|
-
const items = (0,
|
|
3535
|
+
const items = (0, import_react13.useMemo)(
|
|
3300
3536
|
() => infinite.data?.pages.flatMap((p) => p.items) ?? [],
|
|
3301
3537
|
[infinite.data]
|
|
3302
3538
|
);
|
|
3303
3539
|
const lastPage = infinite.data?.pages[infinite.data.pages.length - 1];
|
|
3304
|
-
const loadMore = (0,
|
|
3540
|
+
const loadMore = (0, import_react13.useCallback)(() => {
|
|
3305
3541
|
if (infinite.hasNextPage && !infinite.isFetchingNextPage) {
|
|
3306
3542
|
return infinite.fetchNextPage();
|
|
3307
3543
|
}
|
|
3308
3544
|
return Promise.resolve();
|
|
3309
3545
|
}, [infinite]);
|
|
3310
|
-
const goToPage = (0,
|
|
3546
|
+
const goToPage = (0, import_react13.useCallback)((newPage) => {
|
|
3311
3547
|
setPage(newPage);
|
|
3312
3548
|
}, []);
|
|
3313
3549
|
return {
|
|
@@ -3333,28 +3569,28 @@ function useOrders(options) {
|
|
|
3333
3569
|
}
|
|
3334
3570
|
|
|
3335
3571
|
// src/react/hooks/use-order.ts
|
|
3336
|
-
var
|
|
3337
|
-
var
|
|
3572
|
+
var import_react14 = require("react");
|
|
3573
|
+
var import_react_query32 = require("@tanstack/react-query");
|
|
3338
3574
|
function useOrder(orderNumber, options) {
|
|
3339
3575
|
const { client } = useBehio();
|
|
3340
|
-
const queryClient = (0,
|
|
3576
|
+
const queryClient = (0, import_react_query32.useQueryClient)();
|
|
3341
3577
|
const {
|
|
3342
3578
|
data,
|
|
3343
3579
|
isLoading,
|
|
3344
3580
|
error
|
|
3345
|
-
} = (0,
|
|
3581
|
+
} = (0, import_react_query32.useQuery)({
|
|
3346
3582
|
queryKey: ["behio", "order", orderNumber],
|
|
3347
3583
|
queryFn: () => unwrap(client.orders.get(orderNumber)),
|
|
3348
3584
|
enabled: options?.enabled !== false && !!orderNumber && !!client.getAccessToken()
|
|
3349
3585
|
});
|
|
3350
|
-
const cancelMutation = (0,
|
|
3586
|
+
const cancelMutation = (0, import_react_query32.useMutation)({
|
|
3351
3587
|
mutationFn: () => unwrap(client.orders.cancel(orderNumber)),
|
|
3352
3588
|
onSuccess: (updated) => {
|
|
3353
3589
|
queryClient.setQueryData(["behio", "order", orderNumber], updated);
|
|
3354
3590
|
queryClient.invalidateQueries({ queryKey: ["behio", "orders"] });
|
|
3355
3591
|
}
|
|
3356
3592
|
});
|
|
3357
|
-
const cancel = (0,
|
|
3593
|
+
const cancel = (0, import_react14.useCallback)(
|
|
3358
3594
|
() => cancelMutation.mutateAsync(),
|
|
3359
3595
|
[cancelMutation]
|
|
3360
3596
|
);
|
|
@@ -3368,22 +3604,22 @@ function useOrder(orderNumber, options) {
|
|
|
3368
3604
|
}
|
|
3369
3605
|
|
|
3370
3606
|
// src/react/hooks/use-order-access.ts
|
|
3371
|
-
var
|
|
3372
|
-
var
|
|
3607
|
+
var import_react15 = require("react");
|
|
3608
|
+
var import_react_query33 = require("@tanstack/react-query");
|
|
3373
3609
|
function useOrderAccess() {
|
|
3374
3610
|
const { client } = useBehio();
|
|
3375
|
-
const [orderNumber, setOrderNumber] = (0,
|
|
3376
|
-
const [email, setEmail] = (0,
|
|
3377
|
-
const [order, setOrder] = (0,
|
|
3378
|
-
const [accessToken, setAccessToken] = (0,
|
|
3379
|
-
const requestMutation = (0,
|
|
3611
|
+
const [orderNumber, setOrderNumber] = (0, import_react15.useState)(null);
|
|
3612
|
+
const [email, setEmail] = (0, import_react15.useState)(null);
|
|
3613
|
+
const [order, setOrder] = (0, import_react15.useState)(null);
|
|
3614
|
+
const [accessToken, setAccessToken] = (0, import_react15.useState)(null);
|
|
3615
|
+
const requestMutation = (0, import_react_query33.useMutation)({
|
|
3380
3616
|
mutationFn: (input) => unwrap(client.orders.requestAccessCode(input.orderNumber, input.email)),
|
|
3381
3617
|
onSuccess: (_data, input) => {
|
|
3382
3618
|
setOrderNumber(input.orderNumber);
|
|
3383
3619
|
setEmail(input.email);
|
|
3384
3620
|
}
|
|
3385
3621
|
});
|
|
3386
|
-
const verifyMutation = (0,
|
|
3622
|
+
const verifyMutation = (0, import_react_query33.useMutation)({
|
|
3387
3623
|
mutationFn: (code) => {
|
|
3388
3624
|
if (!orderNumber || !email) {
|
|
3389
3625
|
throw new Error("Request a code before verifying");
|
|
@@ -3395,12 +3631,12 @@ function useOrderAccess() {
|
|
|
3395
3631
|
setAccessToken(result.accessToken);
|
|
3396
3632
|
}
|
|
3397
3633
|
});
|
|
3398
|
-
const requestCode = (0,
|
|
3634
|
+
const requestCode = (0, import_react15.useCallback)(
|
|
3399
3635
|
(on, em) => requestMutation.mutateAsync({ orderNumber: on, email: em }),
|
|
3400
3636
|
[requestMutation]
|
|
3401
3637
|
);
|
|
3402
|
-
const verifyCode = (0,
|
|
3403
|
-
const reset = (0,
|
|
3638
|
+
const verifyCode = (0, import_react15.useCallback)((code) => verifyMutation.mutateAsync(code), [verifyMutation]);
|
|
3639
|
+
const reset = (0, import_react15.useCallback)(() => {
|
|
3404
3640
|
setOrderNumber(null);
|
|
3405
3641
|
setEmail(null);
|
|
3406
3642
|
setOrder(null);
|
|
@@ -3428,13 +3664,13 @@ function useOrderAccess() {
|
|
|
3428
3664
|
}
|
|
3429
3665
|
|
|
3430
3666
|
// src/react/hooks/use-checkout.ts
|
|
3431
|
-
var
|
|
3432
|
-
var
|
|
3667
|
+
var import_react16 = require("react");
|
|
3668
|
+
var import_react_query34 = require("@tanstack/react-query");
|
|
3433
3669
|
function useCheckout() {
|
|
3434
3670
|
const { client, storage } = useBehio();
|
|
3435
|
-
const queryClient = (0,
|
|
3436
|
-
const [order, setOrder] = (0,
|
|
3437
|
-
const mutation = (0,
|
|
3671
|
+
const queryClient = (0, import_react_query34.useQueryClient)();
|
|
3672
|
+
const [order, setOrder] = (0, import_react16.useState)(null);
|
|
3673
|
+
const mutation = (0, import_react_query34.useMutation)({
|
|
3438
3674
|
mutationFn: (input) => unwrap(client.checkout.createOrder(input)),
|
|
3439
3675
|
onSuccess: (result) => {
|
|
3440
3676
|
setOrder(result);
|
|
@@ -3443,11 +3679,11 @@ function useCheckout() {
|
|
|
3443
3679
|
queryClient.invalidateQueries({ queryKey: ["behio", "orders"] });
|
|
3444
3680
|
}
|
|
3445
3681
|
});
|
|
3446
|
-
const createOrder = (0,
|
|
3682
|
+
const createOrder = (0, import_react16.useCallback)(
|
|
3447
3683
|
(input) => mutation.mutateAsync(input),
|
|
3448
3684
|
[mutation]
|
|
3449
3685
|
);
|
|
3450
|
-
const reset = (0,
|
|
3686
|
+
const reset = (0, import_react16.useCallback)(() => {
|
|
3451
3687
|
setOrder(null);
|
|
3452
3688
|
mutation.reset();
|
|
3453
3689
|
}, [mutation]);
|
|
@@ -3461,10 +3697,10 @@ function useCheckout() {
|
|
|
3461
3697
|
}
|
|
3462
3698
|
|
|
3463
3699
|
// src/react/hooks/use-pages.ts
|
|
3464
|
-
var
|
|
3700
|
+
var import_react_query35 = require("@tanstack/react-query");
|
|
3465
3701
|
function usePages(locale, options) {
|
|
3466
3702
|
const { client } = useBehio();
|
|
3467
|
-
return (0,
|
|
3703
|
+
return (0, import_react_query35.useQuery)({
|
|
3468
3704
|
queryKey: ["behio", "pages", locale],
|
|
3469
3705
|
queryFn: async () => {
|
|
3470
3706
|
const result = await unwrap(client.pages.list(locale));
|
|
@@ -3475,18 +3711,141 @@ function usePages(locale, options) {
|
|
|
3475
3711
|
}
|
|
3476
3712
|
function usePage(slug, locale, options) {
|
|
3477
3713
|
const { client } = useBehio();
|
|
3478
|
-
return (0,
|
|
3714
|
+
return (0, import_react_query35.useQuery)({
|
|
3479
3715
|
queryKey: ["behio", "page", slug, locale],
|
|
3480
3716
|
queryFn: () => unwrap(client.pages.get(slug, locale)),
|
|
3481
3717
|
enabled: options?.enabled !== false && !!slug
|
|
3482
3718
|
});
|
|
3483
3719
|
}
|
|
3484
3720
|
|
|
3721
|
+
// src/react/hooks/use-blog.ts
|
|
3722
|
+
var import_react_query36 = require("@tanstack/react-query");
|
|
3723
|
+
function useBlogs(locale, options) {
|
|
3724
|
+
const { client } = useBehio();
|
|
3725
|
+
return (0, import_react_query36.useQuery)({
|
|
3726
|
+
queryKey: ["behio", "blogs", locale],
|
|
3727
|
+
queryFn: async () => {
|
|
3728
|
+
const result = await unwrap(client.blog.list(locale));
|
|
3729
|
+
return result.blogs;
|
|
3730
|
+
},
|
|
3731
|
+
enabled: options?.enabled !== false
|
|
3732
|
+
});
|
|
3733
|
+
}
|
|
3734
|
+
function useBlogPosts(handle, query, options) {
|
|
3735
|
+
const { client } = useBehio();
|
|
3736
|
+
return (0, import_react_query36.useQuery)({
|
|
3737
|
+
queryKey: ["behio", "blog", handle, "posts", query?.locale, query?.page, query?.limit, query?.tag],
|
|
3738
|
+
queryFn: () => unwrap(client.blog.posts(handle, query)),
|
|
3739
|
+
enabled: options?.enabled !== false && !!handle
|
|
3740
|
+
});
|
|
3741
|
+
}
|
|
3742
|
+
function useBlogPost(handle, slug, locale, options) {
|
|
3743
|
+
const { client } = useBehio();
|
|
3744
|
+
return (0, import_react_query36.useQuery)({
|
|
3745
|
+
queryKey: ["behio", "blog", handle, "post", slug, locale],
|
|
3746
|
+
queryFn: () => unwrap(client.blog.post(handle, slug, locale)),
|
|
3747
|
+
enabled: options?.enabled !== false && !!handle && !!slug
|
|
3748
|
+
});
|
|
3749
|
+
}
|
|
3750
|
+
|
|
3751
|
+
// src/react/hooks/use-site-form.ts
|
|
3752
|
+
var import_react17 = require("react");
|
|
3753
|
+
var import_react_query37 = require("@tanstack/react-query");
|
|
3754
|
+
|
|
3755
|
+
// src/errors.ts
|
|
3756
|
+
function bodyOf(err) {
|
|
3757
|
+
const body = err instanceof BehioApiError ? err.body : err && typeof err === "object" && "body" in err ? err.body : err;
|
|
3758
|
+
return body && typeof body === "object" ? body : null;
|
|
3759
|
+
}
|
|
3760
|
+
function errorCode(err) {
|
|
3761
|
+
const body = bodyOf(err);
|
|
3762
|
+
if (!body) return null;
|
|
3763
|
+
const code = body.code ?? body.key;
|
|
3764
|
+
return typeof code === "string" && code.startsWith("be.") ? code : null;
|
|
3765
|
+
}
|
|
3766
|
+
function errorParams(err) {
|
|
3767
|
+
const body = bodyOf(err);
|
|
3768
|
+
const params = body?.params;
|
|
3769
|
+
return params && typeof params === "object" && !Array.isArray(params) ? params : {};
|
|
3770
|
+
}
|
|
3771
|
+
var FORM_FIELD_ERROR_CODES = /* @__PURE__ */ new Set([
|
|
3772
|
+
"required",
|
|
3773
|
+
"invalid",
|
|
3774
|
+
"tooShort",
|
|
3775
|
+
"tooLong",
|
|
3776
|
+
"min",
|
|
3777
|
+
"max",
|
|
3778
|
+
"notOption",
|
|
3779
|
+
"pattern"
|
|
3780
|
+
]);
|
|
3781
|
+
function formFieldErrors(err) {
|
|
3782
|
+
if (errorCode(err) !== "be.forms.validationFailed") return [];
|
|
3783
|
+
const raw = errorParams(err).errors;
|
|
3784
|
+
if (!Array.isArray(raw)) return [];
|
|
3785
|
+
const out = [];
|
|
3786
|
+
for (const entry of raw) {
|
|
3787
|
+
if (typeof entry !== "string") continue;
|
|
3788
|
+
const idx = entry.lastIndexOf(":");
|
|
3789
|
+
if (idx <= 0) continue;
|
|
3790
|
+
const key = entry.slice(0, idx);
|
|
3791
|
+
const code = entry.slice(idx + 1);
|
|
3792
|
+
if (!FORM_FIELD_ERROR_CODES.has(code)) continue;
|
|
3793
|
+
out.push({ key, code });
|
|
3794
|
+
}
|
|
3795
|
+
return out;
|
|
3796
|
+
}
|
|
3797
|
+
|
|
3798
|
+
// src/react/hooks/use-site-form.ts
|
|
3799
|
+
function useSiteForm(slug, options) {
|
|
3800
|
+
const { client } = useBehio();
|
|
3801
|
+
return (0, import_react_query37.useQuery)({
|
|
3802
|
+
queryKey: ["behio", "form", slug],
|
|
3803
|
+
queryFn: () => unwrap(client.forms.get(slug)),
|
|
3804
|
+
enabled: options?.enabled !== false && !!slug
|
|
3805
|
+
});
|
|
3806
|
+
}
|
|
3807
|
+
function useSiteFormSubmit(slug) {
|
|
3808
|
+
const { client } = useBehio();
|
|
3809
|
+
const mutation = (0, import_react_query37.useMutation)({
|
|
3810
|
+
mutationFn: (input) => unwrap(client.forms.submit(slug, input))
|
|
3811
|
+
});
|
|
3812
|
+
const sdkError = mutation.error instanceof UnwrappedError ? mutation.error.sdkError : null;
|
|
3813
|
+
const fieldErrors = (0, import_react17.useMemo)(() => {
|
|
3814
|
+
const out = {};
|
|
3815
|
+
for (const e of formFieldErrors(sdkError)) out[e.key] = e.code;
|
|
3816
|
+
return out;
|
|
3817
|
+
}, [sdkError]);
|
|
3818
|
+
const errorCode2 = (0, import_react17.useMemo)(() => {
|
|
3819
|
+
const body = sdkError?.body;
|
|
3820
|
+
const code = body?.code ?? body?.key;
|
|
3821
|
+
return typeof code === "string" ? code : sdkError ? sdkError.code : null;
|
|
3822
|
+
}, [sdkError]);
|
|
3823
|
+
const submit = (0, import_react17.useCallback)(
|
|
3824
|
+
(input) => mutation.mutateAsync(input).catch(() => null),
|
|
3825
|
+
[mutation]
|
|
3826
|
+
);
|
|
3827
|
+
return {
|
|
3828
|
+
/** Resolves to the result, or null when the submit was rejected (see `fieldErrors` / `errorCode`). */
|
|
3829
|
+
submit,
|
|
3830
|
+
isSubmitting: mutation.isPending,
|
|
3831
|
+
isSuccess: mutation.isSuccess,
|
|
3832
|
+
/** `{ok, id, message, redirectUrl}` after a successful submit. */
|
|
3833
|
+
result: mutation.data ?? null,
|
|
3834
|
+
/** Field key -> validation code after a rejected submit. */
|
|
3835
|
+
fieldErrors,
|
|
3836
|
+
/** Backend error key (`be.forms.*`) or SDK code when the rejection is not per field. */
|
|
3837
|
+
errorCode: errorCode2,
|
|
3838
|
+
/** Raw SDK error (pass to `errorMessage(error, locale)` for a sentence). */
|
|
3839
|
+
error: sdkError,
|
|
3840
|
+
reset: mutation.reset
|
|
3841
|
+
};
|
|
3842
|
+
}
|
|
3843
|
+
|
|
3485
3844
|
// src/react/hooks/use-shop-info.ts
|
|
3486
|
-
var
|
|
3845
|
+
var import_react_query38 = require("@tanstack/react-query");
|
|
3487
3846
|
function useShopInfo(options) {
|
|
3488
3847
|
const { client } = useBehio();
|
|
3489
|
-
return (0,
|
|
3848
|
+
return (0, import_react_query38.useQuery)({
|
|
3490
3849
|
queryKey: ["behio", "shop-info"],
|
|
3491
3850
|
queryFn: () => unwrap(client.getShopInfo()),
|
|
3492
3851
|
enabled: options?.enabled !== false
|
|
@@ -3494,10 +3853,10 @@ function useShopInfo(options) {
|
|
|
3494
3853
|
}
|
|
3495
3854
|
|
|
3496
3855
|
// src/react/hooks/use-shop-scripts.ts
|
|
3497
|
-
var
|
|
3856
|
+
var import_react_query39 = require("@tanstack/react-query");
|
|
3498
3857
|
function useShopScripts(options) {
|
|
3499
3858
|
const { client } = useBehio();
|
|
3500
|
-
return (0,
|
|
3859
|
+
return (0, import_react_query39.useQuery)({
|
|
3501
3860
|
queryKey: ["behio", "shop-scripts"],
|
|
3502
3861
|
queryFn: () => unwrap(client.getShopScripts()),
|
|
3503
3862
|
enabled: options?.enabled !== false
|
|
@@ -3505,11 +3864,11 @@ function useShopScripts(options) {
|
|
|
3505
3864
|
}
|
|
3506
3865
|
|
|
3507
3866
|
// src/react/hooks/use-shop-seo.ts
|
|
3508
|
-
var
|
|
3867
|
+
var import_react_query40 = require("@tanstack/react-query");
|
|
3509
3868
|
function useShopSeo(options) {
|
|
3510
3869
|
const { client } = useBehio();
|
|
3511
3870
|
const { locale, initialData, enabled = true } = options ?? {};
|
|
3512
|
-
return (0,
|
|
3871
|
+
return (0, import_react_query40.useQuery)({
|
|
3513
3872
|
queryKey: ["behio", "shop-seo", locale ?? "_default"],
|
|
3514
3873
|
queryFn: () => unwrap(client.getShopSeo(locale)),
|
|
3515
3874
|
initialData,
|
|
@@ -3569,23 +3928,23 @@ function CurrencySwitcher({
|
|
|
3569
3928
|
}
|
|
3570
3929
|
|
|
3571
3930
|
// src/react/components/storefront-scripts.tsx
|
|
3572
|
-
var
|
|
3931
|
+
var import_react18 = require("react");
|
|
3573
3932
|
|
|
3574
3933
|
// src/react/hooks/use-consent.ts
|
|
3575
|
-
var
|
|
3934
|
+
var import_react_query41 = require("@tanstack/react-query");
|
|
3576
3935
|
function useCookieConsent(visitorId) {
|
|
3577
3936
|
const { client } = useBehio();
|
|
3578
|
-
const qc = (0,
|
|
3579
|
-
const query = (0,
|
|
3937
|
+
const qc = (0, import_react_query41.useQueryClient)();
|
|
3938
|
+
const query = (0, import_react_query41.useQuery)({
|
|
3580
3939
|
queryKey: ["behio", "consent", visitorId],
|
|
3581
3940
|
queryFn: () => unwrap(client.consent.get(visitorId)),
|
|
3582
3941
|
enabled: Boolean(visitorId)
|
|
3583
3942
|
});
|
|
3584
|
-
const recordMutation = (0,
|
|
3943
|
+
const recordMutation = (0, import_react_query41.useMutation)({
|
|
3585
3944
|
mutationFn: (input) => unwrap(client.consent.record(input)),
|
|
3586
3945
|
onSuccess: () => qc.invalidateQueries({ queryKey: ["behio", "consent"] })
|
|
3587
3946
|
});
|
|
3588
|
-
const revokeMutation = (0,
|
|
3947
|
+
const revokeMutation = (0, import_react_query41.useMutation)({
|
|
3589
3948
|
mutationFn: () => unwrap(client.consent.revoke(visitorId)),
|
|
3590
3949
|
onSuccess: () => qc.invalidateQueries({ queryKey: ["behio", "consent"] })
|
|
3591
3950
|
});
|
|
@@ -3659,8 +4018,8 @@ function injectHtml(target, html) {
|
|
|
3659
4018
|
}
|
|
3660
4019
|
function StorefrontScripts({ visitorId: visitorIdProp } = {}) {
|
|
3661
4020
|
const { data } = useShopScripts();
|
|
3662
|
-
const [visitorId, setVisitorId] = (0,
|
|
3663
|
-
(0,
|
|
4021
|
+
const [visitorId, setVisitorId] = (0, import_react18.useState)(visitorIdProp ?? "");
|
|
4022
|
+
(0, import_react18.useEffect)(() => {
|
|
3664
4023
|
if (visitorIdProp) return;
|
|
3665
4024
|
try {
|
|
3666
4025
|
const v = localStorage.getItem(VISITOR_KEY);
|
|
@@ -3670,15 +4029,15 @@ function StorefrontScripts({ visitorId: visitorIdProp } = {}) {
|
|
|
3670
4029
|
}, [visitorIdProp]);
|
|
3671
4030
|
const { data: consent } = useCookieConsent(visitorId || void 0);
|
|
3672
4031
|
const analyticsOk = Boolean(consent?.analytics);
|
|
3673
|
-
const scripts = (0,
|
|
4032
|
+
const scripts = (0, import_react18.useMemo)(
|
|
3674
4033
|
() => (data?.scripts ?? []).filter((s) => !s.consentRequired || analyticsOk),
|
|
3675
4034
|
[data, analyticsOk]
|
|
3676
4035
|
);
|
|
3677
|
-
const signature = (0,
|
|
4036
|
+
const signature = (0, import_react18.useMemo)(
|
|
3678
4037
|
() => JSON.stringify(scripts.map((s) => [s.id, s.type, s.placement, s.value])),
|
|
3679
4038
|
[scripts]
|
|
3680
4039
|
);
|
|
3681
|
-
(0,
|
|
4040
|
+
(0, import_react18.useEffect)(() => {
|
|
3682
4041
|
if (typeof document === "undefined") return;
|
|
3683
4042
|
const added = [];
|
|
3684
4043
|
for (const s of scripts) {
|
|
@@ -3695,7 +4054,7 @@ function StorefrontScripts({ visitorId: visitorIdProp } = {}) {
|
|
|
3695
4054
|
}
|
|
3696
4055
|
|
|
3697
4056
|
// src/react/components/behio-analytics.tsx
|
|
3698
|
-
var
|
|
4057
|
+
var import_react19 = require("react");
|
|
3699
4058
|
|
|
3700
4059
|
// src/react/hooks/use-behio-client.ts
|
|
3701
4060
|
function useBehioClient() {
|
|
@@ -3705,7 +4064,7 @@ function useBehioClient() {
|
|
|
3705
4064
|
// src/react/components/behio-analytics.tsx
|
|
3706
4065
|
function BehioAnalyticsTracker() {
|
|
3707
4066
|
const client = useBehioClient();
|
|
3708
|
-
(0,
|
|
4067
|
+
(0, import_react19.useEffect)(() => {
|
|
3709
4068
|
if (typeof window === "undefined") return;
|
|
3710
4069
|
const w = window;
|
|
3711
4070
|
if (w.__behioAnalytics) return;
|
|
@@ -3944,10 +4303,10 @@ function utmFromSearch(search) {
|
|
|
3944
4303
|
}
|
|
3945
4304
|
|
|
3946
4305
|
// src/react/hooks/use-bundles.ts
|
|
3947
|
-
var
|
|
4306
|
+
var import_react_query42 = require("@tanstack/react-query");
|
|
3948
4307
|
function useBundles(options) {
|
|
3949
4308
|
const { client } = useBehio();
|
|
3950
|
-
return (0,
|
|
4309
|
+
return (0, import_react_query42.useQuery)({
|
|
3951
4310
|
queryKey: ["behio", "bundles"],
|
|
3952
4311
|
queryFn: () => unwrap(client.catalog.getBundles()),
|
|
3953
4312
|
enabled: options?.enabled ?? true,
|
|
@@ -3956,7 +4315,7 @@ function useBundles(options) {
|
|
|
3956
4315
|
}
|
|
3957
4316
|
function useBundle(slug, options) {
|
|
3958
4317
|
const { client } = useBehio();
|
|
3959
|
-
return (0,
|
|
4318
|
+
return (0, import_react_query42.useQuery)({
|
|
3960
4319
|
queryKey: ["behio", "bundle", slug],
|
|
3961
4320
|
queryFn: () => unwrap(client.catalog.getBundle(slug)),
|
|
3962
4321
|
enabled: Boolean(slug) && (options?.enabled ?? true),
|
|
@@ -3965,10 +4324,10 @@ function useBundle(slug, options) {
|
|
|
3965
4324
|
}
|
|
3966
4325
|
|
|
3967
4326
|
// src/react/hooks/use-product-group.ts
|
|
3968
|
-
var
|
|
4327
|
+
var import_react_query43 = require("@tanstack/react-query");
|
|
3969
4328
|
function useProductGroup(slug, options) {
|
|
3970
4329
|
const { client } = useBehio();
|
|
3971
|
-
return (0,
|
|
4330
|
+
return (0, import_react_query43.useQuery)({
|
|
3972
4331
|
queryKey: ["behio", "product-group", slug, options?.locale, options?.currency],
|
|
3973
4332
|
queryFn: () => unwrap(
|
|
3974
4333
|
client.catalog.getProductGroup(slug, {
|
|
@@ -3982,10 +4341,10 @@ function useProductGroup(slug, options) {
|
|
|
3982
4341
|
}
|
|
3983
4342
|
|
|
3984
4343
|
// src/react/hooks/use-cross-sell.ts
|
|
3985
|
-
var
|
|
4344
|
+
var import_react_query44 = require("@tanstack/react-query");
|
|
3986
4345
|
function useCrossSell(productSlug, options) {
|
|
3987
4346
|
const { client } = useBehio();
|
|
3988
|
-
return (0,
|
|
4347
|
+
return (0, import_react_query44.useQuery)({
|
|
3989
4348
|
queryKey: ["behio", "cross-sell", productSlug, options?.locale, options?.currency],
|
|
3990
4349
|
queryFn: () => unwrap(
|
|
3991
4350
|
client.catalog.getCrossSell(productSlug, {
|
|
@@ -3999,10 +4358,10 @@ function useCrossSell(productSlug, options) {
|
|
|
3999
4358
|
}
|
|
4000
4359
|
|
|
4001
4360
|
// src/react/hooks/use-product-promotions.ts
|
|
4002
|
-
var
|
|
4361
|
+
var import_react_query45 = require("@tanstack/react-query");
|
|
4003
4362
|
function useProductPromotions(productSlug, options) {
|
|
4004
4363
|
const { client } = useBehio();
|
|
4005
|
-
return (0,
|
|
4364
|
+
return (0, import_react_query45.useQuery)({
|
|
4006
4365
|
queryKey: ["behio", "product-promotions", productSlug],
|
|
4007
4366
|
queryFn: () => unwrap(client.catalog.getProductPromotions(productSlug)),
|
|
4008
4367
|
enabled: Boolean(productSlug) && (options?.enabled ?? true),
|
|
@@ -4011,11 +4370,11 @@ function useProductPromotions(productSlug, options) {
|
|
|
4011
4370
|
}
|
|
4012
4371
|
|
|
4013
4372
|
// src/react/hooks/use-gift-card.ts
|
|
4014
|
-
var
|
|
4373
|
+
var import_react_query46 = require("@tanstack/react-query");
|
|
4015
4374
|
function useGiftCardBalance(code, options) {
|
|
4016
4375
|
const { client } = useBehio();
|
|
4017
4376
|
const trimmed = code?.trim();
|
|
4018
|
-
return (0,
|
|
4377
|
+
return (0, import_react_query46.useQuery)({
|
|
4019
4378
|
queryKey: ["behio", "gift-card-balance", trimmed],
|
|
4020
4379
|
queryFn: () => unwrap(client.catalog.checkGiftCard(trimmed)),
|
|
4021
4380
|
enabled: Boolean(trimmed && trimmed.length >= 6) && (options?.enabled ?? true)
|
|
@@ -4023,20 +4382,20 @@ function useGiftCardBalance(code, options) {
|
|
|
4023
4382
|
}
|
|
4024
4383
|
|
|
4025
4384
|
// src/react/hooks/use-wishlist.ts
|
|
4026
|
-
var
|
|
4385
|
+
var import_react_query47 = require("@tanstack/react-query");
|
|
4027
4386
|
function useWishlist(options) {
|
|
4028
4387
|
const { client } = useBehio();
|
|
4029
|
-
const qc = (0,
|
|
4030
|
-
const query = (0,
|
|
4388
|
+
const qc = (0, import_react_query47.useQueryClient)();
|
|
4389
|
+
const query = (0, import_react_query47.useQuery)({
|
|
4031
4390
|
queryKey: ["behio", "wishlist"],
|
|
4032
4391
|
queryFn: () => unwrap(client.wishlist.get()),
|
|
4033
4392
|
enabled: options?.enabled ?? true
|
|
4034
4393
|
});
|
|
4035
|
-
const addMutation = (0,
|
|
4394
|
+
const addMutation = (0, import_react_query47.useMutation)({
|
|
4036
4395
|
mutationFn: (productId) => unwrap(client.wishlist.add(productId)),
|
|
4037
4396
|
onSuccess: () => qc.invalidateQueries({ queryKey: ["behio", "wishlist"] })
|
|
4038
4397
|
});
|
|
4039
|
-
const removeMutation = (0,
|
|
4398
|
+
const removeMutation = (0, import_react_query47.useMutation)({
|
|
4040
4399
|
mutationFn: (productId) => unwrap(client.wishlist.remove(productId)),
|
|
4041
4400
|
onSuccess: () => qc.invalidateQueries({ queryKey: ["behio", "wishlist"] })
|
|
4042
4401
|
});
|
|
@@ -4050,7 +4409,7 @@ function useWishlist(options) {
|
|
|
4050
4409
|
}
|
|
4051
4410
|
function useIsInWishlist(productId) {
|
|
4052
4411
|
const { client } = useBehio();
|
|
4053
|
-
return (0,
|
|
4412
|
+
return (0, import_react_query47.useQuery)({
|
|
4054
4413
|
queryKey: ["behio", "wishlist-check", productId],
|
|
4055
4414
|
queryFn: () => unwrap(client.wishlist.isInWishlist(productId)),
|
|
4056
4415
|
enabled: Boolean(productId)
|
|
@@ -4058,10 +4417,10 @@ function useIsInWishlist(productId) {
|
|
|
4058
4417
|
}
|
|
4059
4418
|
|
|
4060
4419
|
// src/react/hooks/use-reviews.ts
|
|
4061
|
-
var
|
|
4420
|
+
var import_react_query48 = require("@tanstack/react-query");
|
|
4062
4421
|
function useProductReviews(productId, options) {
|
|
4063
4422
|
const { client } = useBehio();
|
|
4064
|
-
return (0,
|
|
4423
|
+
return (0, import_react_query48.useQuery)({
|
|
4065
4424
|
queryKey: ["behio", "reviews", productId, options?.page ?? 1],
|
|
4066
4425
|
queryFn: () => unwrap(client.reviews.getProductReviews(productId, options?.page, options?.limit)),
|
|
4067
4426
|
enabled: Boolean(productId) && (options?.enabled ?? true)
|
|
@@ -4069,30 +4428,30 @@ function useProductReviews(productId, options) {
|
|
|
4069
4428
|
}
|
|
4070
4429
|
function useSubmitReview() {
|
|
4071
4430
|
const { client } = useBehio();
|
|
4072
|
-
const qc = (0,
|
|
4073
|
-
return (0,
|
|
4431
|
+
const qc = (0, import_react_query48.useQueryClient)();
|
|
4432
|
+
return (0, import_react_query48.useMutation)({
|
|
4074
4433
|
mutationFn: (input) => unwrap(client.reviews.submit(input)),
|
|
4075
4434
|
onSuccess: (_, input) => qc.invalidateQueries({ queryKey: ["behio", "reviews", input.productId] })
|
|
4076
4435
|
});
|
|
4077
4436
|
}
|
|
4078
4437
|
|
|
4079
4438
|
// src/react/hooks/use-returns.ts
|
|
4080
|
-
var
|
|
4439
|
+
var import_react_query49 = require("@tanstack/react-query");
|
|
4081
4440
|
function useLookupReturnableOrder() {
|
|
4082
4441
|
const { client } = useBehio();
|
|
4083
|
-
return (0,
|
|
4442
|
+
return (0, import_react_query49.useMutation)({
|
|
4084
4443
|
mutationFn: ({ orderNumber, email }) => unwrap(client.returns.lookupOrder(orderNumber, email))
|
|
4085
4444
|
});
|
|
4086
4445
|
}
|
|
4087
4446
|
function useSubmitReturn() {
|
|
4088
4447
|
const { client } = useBehio();
|
|
4089
|
-
return (0,
|
|
4448
|
+
return (0, import_react_query49.useMutation)({
|
|
4090
4449
|
mutationFn: (input) => unwrap(client.returns.submit(input))
|
|
4091
4450
|
});
|
|
4092
4451
|
}
|
|
4093
4452
|
function useReturnStatus(returnId, email) {
|
|
4094
4453
|
const { client } = useBehio();
|
|
4095
|
-
return (0,
|
|
4454
|
+
return (0, import_react_query49.useQuery)({
|
|
4096
4455
|
queryKey: ["behio", "return-status", returnId],
|
|
4097
4456
|
queryFn: () => unwrap(client.returns.getStatus(returnId, email)),
|
|
4098
4457
|
enabled: Boolean(returnId && email)
|
|
@@ -4100,16 +4459,16 @@ function useReturnStatus(returnId, email) {
|
|
|
4100
4459
|
}
|
|
4101
4460
|
|
|
4102
4461
|
// src/react/hooks/use-quotes.ts
|
|
4103
|
-
var
|
|
4462
|
+
var import_react_query50 = require("@tanstack/react-query");
|
|
4104
4463
|
function useSubmitQuote() {
|
|
4105
4464
|
const { client } = useBehio();
|
|
4106
|
-
return (0,
|
|
4465
|
+
return (0, import_react_query50.useMutation)({
|
|
4107
4466
|
mutationFn: (input) => unwrap(client.quotes.submit(input))
|
|
4108
4467
|
});
|
|
4109
4468
|
}
|
|
4110
4469
|
function useQuoteStatus(quoteId, email) {
|
|
4111
4470
|
const { client } = useBehio();
|
|
4112
|
-
return (0,
|
|
4471
|
+
return (0, import_react_query50.useQuery)({
|
|
4113
4472
|
queryKey: ["behio", "quote-status", quoteId],
|
|
4114
4473
|
queryFn: () => unwrap(client.quotes.getStatus(quoteId, email)),
|
|
4115
4474
|
enabled: Boolean(quoteId && email)
|
|
@@ -4117,10 +4476,10 @@ function useQuoteStatus(quoteId, email) {
|
|
|
4117
4476
|
}
|
|
4118
4477
|
|
|
4119
4478
|
// src/react/hooks/use-back-in-stock.ts
|
|
4120
|
-
var
|
|
4479
|
+
var import_react_query51 = require("@tanstack/react-query");
|
|
4121
4480
|
function useNotifyWhenAvailable() {
|
|
4122
4481
|
const { client } = useBehio();
|
|
4123
|
-
return (0,
|
|
4482
|
+
return (0, import_react_query51.useMutation)({
|
|
4124
4483
|
mutationFn: ({ productId, email }) => unwrap(client.catalog.notifyWhenAvailable(productId, email))
|
|
4125
4484
|
});
|
|
4126
4485
|
}
|
|
@@ -4257,6 +4616,9 @@ async function revokeAnalyticsConsent(client) {
|
|
|
4257
4616
|
useAuth,
|
|
4258
4617
|
useBehio,
|
|
4259
4618
|
useBehioClient,
|
|
4619
|
+
useBlogPost,
|
|
4620
|
+
useBlogPosts,
|
|
4621
|
+
useBlogs,
|
|
4260
4622
|
useBundle,
|
|
4261
4623
|
useBundles,
|
|
4262
4624
|
useCart,
|
|
@@ -4310,9 +4672,12 @@ async function revokeAnalyticsConsent(client) {
|
|
|
4310
4672
|
useShopInfo,
|
|
4311
4673
|
useShopScripts,
|
|
4312
4674
|
useShopSeo,
|
|
4675
|
+
useSiteForm,
|
|
4676
|
+
useSiteFormSubmit,
|
|
4313
4677
|
useSubmitQuote,
|
|
4314
4678
|
useSubmitReturn,
|
|
4315
4679
|
useSubmitReview,
|
|
4316
4680
|
useSubscriptions,
|
|
4681
|
+
useVisitorMessages,
|
|
4317
4682
|
useWishlist
|
|
4318
4683
|
});
|