@viu/emporix-sdk-react 2.13.1 → 2.15.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.
Files changed (47) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/{chunk-VMDBYVWG.js → chunk-62GKMVS3.js} +30 -4
  3. package/dist/chunk-62GKMVS3.js.map +1 -0
  4. package/dist/{chunk-SXZCM2LE.js → chunk-IREROKYI.js} +658 -311
  5. package/dist/chunk-IREROKYI.js.map +1 -0
  6. package/dist/{chunk-4YDWCA7A.js → chunk-ZNE3J25W.js} +165 -107
  7. package/dist/chunk-ZNE3J25W.js.map +1 -0
  8. package/dist/hooks.cjs +751 -430
  9. package/dist/hooks.cjs.map +1 -1
  10. package/dist/hooks.d.cts +2 -2
  11. package/dist/hooks.d.ts +2 -2
  12. package/dist/hooks.js +185 -4
  13. package/dist/hooks.js.map +1 -1
  14. package/dist/index.cjs +950 -551
  15. package/dist/index.cjs.map +1 -1
  16. package/dist/index.d.cts +40 -6
  17. package/dist/index.d.ts +40 -6
  18. package/dist/index.js +240 -8
  19. package/dist/index.js.map +1 -1
  20. package/dist/{provider-Bcb-tOpS.d.ts → provider-Cgm9QVoo.d.ts} +1 -1
  21. package/dist/{provider-Ddo7aSOI.d.cts → provider-DGjmBPMr.d.cts} +1 -1
  22. package/dist/provider.cjs +193 -123
  23. package/dist/provider.cjs.map +1 -1
  24. package/dist/provider.d.cts +1 -1
  25. package/dist/provider.d.ts +1 -1
  26. package/dist/provider.js +12 -3
  27. package/dist/provider.js.map +1 -1
  28. package/dist/ssr.cjs +36 -5
  29. package/dist/ssr.cjs.map +1 -1
  30. package/dist/ssr.d.cts +22 -6
  31. package/dist/ssr.d.ts +22 -6
  32. package/dist/ssr.js +54 -1
  33. package/dist/ssr.js.map +1 -1
  34. package/dist/storage.cjs +58 -9
  35. package/dist/storage.cjs.map +1 -1
  36. package/dist/storage.d.cts +8 -2
  37. package/dist/storage.d.ts +8 -2
  38. package/dist/storage.js +15 -2
  39. package/dist/storage.js.map +1 -1
  40. package/dist/{use-returns-uZJiO46w.d.ts → use-returns-DrqdwizU.d.ts} +1 -1
  41. package/dist/{use-returns-DT98Ptod.d.cts → use-returns-fKPIgjmU.d.cts} +1 -1
  42. package/package.json +5 -4
  43. package/dist/chunk-4YDWCA7A.js.map +0 -1
  44. package/dist/chunk-SXZCM2LE.js.map +0 -1
  45. package/dist/chunk-TIS4BKHK.js +0 -25
  46. package/dist/chunk-TIS4BKHK.js.map +0 -1
  47. package/dist/chunk-VMDBYVWG.js.map +0 -1
package/dist/index.cjs CHANGED
@@ -1,11 +1,132 @@
1
- 'use strict';
1
+ "use client";
2
+ "use strict";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
2
20
 
3
- var react = require('react');
4
- var reactQuery = require('@tanstack/react-query');
5
- var emporixSdk = require('@viu/emporix-sdk');
6
- var jsxRuntime = require('react/jsx-runtime');
21
+ // src/index.ts
22
+ var src_exports = {};
23
+ __export(src_exports, {
24
+ CompanyContextProvider: () => CompanyContextProvider,
25
+ EmporixCompanyContext: () => EmporixCompanyContext,
26
+ EmporixErrorBoundary: () => EmporixErrorBoundary,
27
+ EmporixProvider: () => EmporixProvider,
28
+ createCookieStorage: () => createCookieStorage,
29
+ createLocalStorageStorage: () => createLocalStorageStorage,
30
+ createMemoryStorage: () => createMemoryStorage,
31
+ prefetchCart: () => prefetchCart,
32
+ prefetchOrder: () => prefetchOrder,
33
+ prefetchProduct: () => prefetchProduct,
34
+ useActiveCart: () => useActiveCart,
35
+ useActiveCompany: () => useActiveCompany,
36
+ useActiveSite: () => useActiveSite,
37
+ useAddGroupMember: () => useAddGroupMember,
38
+ useAddToShoppingList: () => useAddToShoppingList,
39
+ useAddressMutations: () => useAddressMutations,
40
+ useAssignContact: () => useAssignContact,
41
+ useAvailabilities: () => useAvailabilities,
42
+ useAvailability: () => useAvailability,
43
+ useCancelOrder: () => useCancelOrder,
44
+ useCart: () => useCart,
45
+ useCartMutations: () => useCartMutations,
46
+ useCategories: () => useCategories,
47
+ useCategoriesInfinite: () => useCategoriesInfinite,
48
+ useCategory: () => useCategory,
49
+ useCategoryTree: () => useCategoryTree,
50
+ useChangePassword: () => useChangePassword,
51
+ useCheckout: () => useCheckout,
52
+ useCloudFunction: () => useCloudFunction,
53
+ useCompany: () => useCompany,
54
+ useCompanyContacts: () => useCompanyContacts,
55
+ useCompanyGroups: () => useCompanyGroups,
56
+ useCompanyLocations: () => useCompanyLocations,
57
+ useCompanySwitcher: () => useCompanySwitcher,
58
+ useCreateCart: () => useCreateCart,
59
+ useCreateCompany: () => useCreateCompany,
60
+ useCreateLocation: () => useCreateLocation,
61
+ useCreateReturn: () => useCreateReturn,
62
+ useCreateShoppingList: () => useCreateShoppingList,
63
+ useCustomerAddresses: () => useCustomerAddresses,
64
+ useCustomerSession: () => useCustomerSession,
65
+ useDefaultSite: () => useDefaultSite,
66
+ useDeleteCompany: () => useDeleteCompany,
67
+ useDeleteLocation: () => useDeleteLocation,
68
+ useDeleteShoppingList: () => useDeleteShoppingList,
69
+ useEmporix: () => useEmporix,
70
+ useEmporixErrorHandler: () => useEmporixErrorHandler,
71
+ useEmporixTelemetry: () => useEmporixTelemetry,
72
+ useInvokeCloudFunction: () => useInvokeCloudFunction,
73
+ useMatchPrices: () => useMatchPrices,
74
+ useMatchPricesChunked: () => useMatchPricesChunked,
75
+ useMyCompanies: () => useMyCompanies,
76
+ useMyOrders: () => useMyOrders,
77
+ useMyOrdersInfinite: () => useMyOrdersInfinite,
78
+ useMyReturns: () => useMyReturns,
79
+ useMyRewardPoints: () => useMyRewardPoints,
80
+ useMyRewardPointsSummary: () => useMyRewardPointsSummary,
81
+ useMySegmentCategories: () => useMySegmentCategories,
82
+ useMySegmentCategoriesInfinite: () => useMySegmentCategoriesInfinite,
83
+ useMySegmentCategoryTree: () => useMySegmentCategoryTree,
84
+ useMySegmentItems: () => useMySegmentItems,
85
+ useMySegmentProducts: () => useMySegmentProducts,
86
+ useMySegmentProductsInfinite: () => useMySegmentProductsInfinite,
87
+ useMySegments: () => useMySegments,
88
+ useOrder: () => useOrder,
89
+ useOrderTransition: () => useOrderTransition,
90
+ usePasswordReset: () => usePasswordReset,
91
+ usePaymentModes: () => usePaymentModes,
92
+ useProduct: () => useProduct,
93
+ useProductByCode: () => useProductByCode,
94
+ useProductMedia: () => useProductMedia,
95
+ useProductNameSearch: () => useProductNameSearch,
96
+ useProductSearch: () => useProductSearch,
97
+ useProducts: () => useProducts,
98
+ useProductsByCodes: () => useProductsByCodes,
99
+ useProductsInCategory: () => useProductsInCategory,
100
+ useProductsInCategoryInfinite: () => useProductsInCategoryInfinite,
101
+ useProductsInfinite: () => useProductsInfinite,
102
+ useRedeemCoupon: () => useRedeemCoupon,
103
+ useRedeemOptions: () => useRedeemOptions,
104
+ useRedeemRewardPoints: () => useRedeemRewardPoints,
105
+ useRemoveFromShoppingList: () => useRemoveFromShoppingList,
106
+ useRemoveGroupMember: () => useRemoveGroupMember,
107
+ useReorder: () => useReorder,
108
+ useReturn: () => useReturn,
109
+ useSalesOrder: () => useSalesOrder,
110
+ useSetShoppingListItemQuantity: () => useSetShoppingListItemQuantity,
111
+ useShoppingLists: () => useShoppingLists,
112
+ useSiteContext: () => useSiteContext,
113
+ useSites: () => useSites,
114
+ useSubcategories: () => useSubcategories,
115
+ useUnassignContact: () => useUnassignContact,
116
+ useUpdateCompany: () => useUpdateCompany,
117
+ useUpdateContactAssignment: () => useUpdateContactAssignment,
118
+ useUpdateCustomer: () => useUpdateCustomer,
119
+ useUpdateLocation: () => useUpdateLocation,
120
+ useUpdateSalesOrder: () => useUpdateSalesOrder,
121
+ useValidateCoupon: () => useValidateCoupon,
122
+ useVariantChildren: () => useVariantChildren
123
+ });
124
+ module.exports = __toCommonJS(src_exports);
7
125
 
8
126
  // src/provider.tsx
127
+ var import_react3 = require("react");
128
+ var import_react_query2 = require("@tanstack/react-query");
129
+ var import_emporix_sdk2 = require("@viu/emporix-sdk");
9
130
 
10
131
  // src/storage/local-storage.ts
11
132
  var DEFAULT_TOKEN_KEY = "emporix.customerToken";
@@ -15,6 +136,7 @@ var SITE_KEY = "emporix.siteCode";
15
136
  var LANGUAGE_KEY = "emporix.language";
16
137
  var ACTIVE_LE_KEY = "emporix.activeLegalEntityId";
17
138
  var REFRESH_KEY = "emporix.refreshToken";
139
+ var SAAS_KEY = "emporix.saasToken";
18
140
  function createLocalStorageStorage(opts = {}) {
19
141
  const tokenKey = opts.key ?? DEFAULT_TOKEN_KEY;
20
142
  const available = typeof globalThis !== "undefined" && typeof globalThis.localStorage !== "undefined";
@@ -73,6 +195,12 @@ function createLocalStorageStorage(opts = {}) {
73
195
  else ls.setItem(REFRESH_KEY, t);
74
196
  all.notify("refreshToken");
75
197
  },
198
+ getSaasToken: () => ls.getItem(SAAS_KEY),
199
+ setSaasToken: (t) => {
200
+ if (t === null) ls.removeItem(SAAS_KEY);
201
+ else ls.setItem(SAAS_KEY, t);
202
+ all.notify("saasToken");
203
+ },
76
204
  subscribeAll: (l) => all.add(l)
77
205
  };
78
206
  }
@@ -85,10 +213,11 @@ var SITE_NAME = "emporix.siteCode";
85
213
  var LANGUAGE_NAME = "emporix.language";
86
214
  var ACTIVE_LE_NAME = "emporix.activeLegalEntityId";
87
215
  var REFRESH_NAME = "emporix.refreshToken";
216
+ var SAAS_NAME = "emporix.saasToken";
88
217
  function createCookieStorage(opts = {}) {
89
218
  const tokenName = opts.name ?? DEFAULT_TOKEN_NAME;
90
219
  const sameSite = opts.sameSite ?? "lax";
91
- const secure = opts.secure ?? false;
220
+ const secure = opts.secure ?? (typeof location !== "undefined" && location.protocol === "https:");
92
221
  if (typeof document === "undefined") {
93
222
  console.warn("[emporix] document unavailable; cookie storage falling back to in-memory");
94
223
  return createMemoryStorage();
@@ -144,6 +273,11 @@ function createCookieStorage(opts = {}) {
144
273
  writeCookie(REFRESH_NAME, t);
145
274
  all.notify("refreshToken");
146
275
  },
276
+ getSaasToken: () => readCookie(SAAS_NAME),
277
+ setSaasToken: (t) => {
278
+ writeCookie(SAAS_NAME, t);
279
+ all.notify("saasToken");
280
+ },
147
281
  subscribeAll: (l) => all.add(l)
148
282
  };
149
283
  }
@@ -188,6 +322,7 @@ function createMemoryStorage(opts = {}) {
188
322
  let language = null;
189
323
  let activeLegalEntityId = null;
190
324
  let refreshToken = null;
325
+ let saasToken = null;
191
326
  const tokenListeners = /* @__PURE__ */ new Set();
192
327
  const all = createListenerSet();
193
328
  return {
@@ -231,17 +366,31 @@ function createMemoryStorage(opts = {}) {
231
366
  refreshToken = t;
232
367
  all.notify("refreshToken");
233
368
  },
369
+ getSaasToken: () => saasToken,
370
+ setSaasToken: (t) => {
371
+ saasToken = t;
372
+ all.notify("saasToken");
373
+ },
234
374
  subscribeAll: (l) => all.add(l)
235
375
  };
236
376
  }
237
- var EmporixTelemetryContext = react.createContext(null);
377
+
378
+ // src/telemetry.ts
379
+ var import_react = require("react");
380
+ var EmporixTelemetryContext = (0, import_react.createContext)(null);
238
381
  function useEmporixTelemetry() {
239
- const ctx = react.useContext(EmporixTelemetryContext);
382
+ const ctx = (0, import_react.useContext)(EmporixTelemetryContext);
240
383
  if (!ctx) {
241
384
  throw new Error("useEmporixTelemetry must be used within an EmporixProvider");
242
385
  }
243
386
  return ctx;
244
387
  }
388
+
389
+ // src/company-context.tsx
390
+ var import_react2 = require("react");
391
+ var import_react_query = require("@tanstack/react-query");
392
+ var import_emporix_sdk = require("@viu/emporix-sdk");
393
+ var import_jsx_runtime = require("react/jsx-runtime");
245
394
  var NULL_CTX = {
246
395
  activeCompany: null,
247
396
  myCompanies: [],
@@ -254,9 +403,9 @@ var NULL_CTX = {
254
403
  refetchMyCompanies: async () => {
255
404
  }
256
405
  };
257
- var EmporixCompanyContext = react.createContext(NULL_CTX);
406
+ var EmporixCompanyContext = (0, import_react2.createContext)(NULL_CTX);
258
407
  function useActiveCompany() {
259
- return react.useContext(EmporixCompanyContext);
408
+ return (0, import_react2.useContext)(EmporixCompanyContext);
260
409
  }
261
410
  function CompanyContextProvider({
262
411
  client,
@@ -264,83 +413,103 @@ function CompanyContextProvider({
264
413
  initialActiveLegalEntityId,
265
414
  children
266
415
  }) {
267
- const qc = reactQuery.useQueryClient();
416
+ const qc = (0, import_react_query.useQueryClient)();
268
417
  const { emit } = useEmporixTelemetry();
269
- const [myCompanies, setMyCompanies] = react.useState([]);
270
- const [activeCompany, setActive] = react.useState(null);
271
- const [status, setStatus] = react.useState("idle");
272
- const [error, setError] = react.useState(null);
273
- const activeRef = react.useRef(null);
274
- activeRef.current = activeCompany;
275
- const switchTo = react.useCallback(
276
- async (target) => {
277
- const start = Date.now();
278
- const from = activeRef.current?.id ?? null;
279
- const refreshToken = storage.getRefreshToken();
280
- const token = storage.getCustomerToken();
281
- if (!refreshToken || !token) {
282
- setActive(target);
283
- storage.setActiveLegalEntityId(target?.id ?? null);
284
- } else {
285
- const next = await client.customers.refresh({
286
- refreshToken,
287
- ...target ? { legalEntityId: target.id } : {}
288
- });
289
- storage.setCustomerToken(next.customerToken);
290
- if (next.refreshToken) storage.setRefreshToken(next.refreshToken);
291
- storage.setCartId(null);
292
- storage.setActiveLegalEntityId(target?.id ?? null);
293
- setActive(target);
294
- qc.invalidateQueries({
295
- predicate: (q) => Array.isArray(q.queryKey) && q.queryKey.some(
296
- (k) => k === "cart" || k === "companies" || k === "customer" || k === from || target !== null && k === target.id
297
- )
418
+ const [myCompanies, setMyCompanies] = (0, import_react2.useState)([]);
419
+ const [activeCompany, setActive] = (0, import_react2.useState)(null);
420
+ const [status, setStatus] = (0, import_react2.useState)("idle");
421
+ const [error, setError] = (0, import_react2.useState)(null);
422
+ const activeRef = (0, import_react2.useRef)(null);
423
+ (0, import_react2.useEffect)(() => {
424
+ activeRef.current = activeCompany;
425
+ }, [activeCompany]);
426
+ const switchChain = (0, import_react2.useRef)(Promise.resolve());
427
+ const switchTo = (0, import_react2.useCallback)(
428
+ (target) => {
429
+ const run = async () => {
430
+ const start = Date.now();
431
+ const from = activeRef.current?.id ?? null;
432
+ const refreshToken = storage.getRefreshToken();
433
+ const token = storage.getCustomerToken();
434
+ if (!refreshToken || !token) {
435
+ setActive(target);
436
+ storage.setActiveLegalEntityId(target?.id ?? null);
437
+ } else {
438
+ const next = await client.customers.refresh({
439
+ refreshToken,
440
+ ...target ? { legalEntityId: target.id } : {}
441
+ });
442
+ storage.setCustomerToken(next.customerToken);
443
+ if (next.refreshToken) storage.setRefreshToken(next.refreshToken);
444
+ storage.setCartId(null);
445
+ storage.setActiveLegalEntityId(target?.id ?? null);
446
+ setActive(target);
447
+ qc.invalidateQueries({
448
+ predicate: (q) => Array.isArray(q.queryKey) && q.queryKey.some(
449
+ (k) => k === "cart" || k === "companies" || k === "customer" || k === from || target !== null && k === target.id
450
+ )
451
+ });
452
+ }
453
+ emit({
454
+ type: "company:switched",
455
+ from,
456
+ to: target?.id ?? null,
457
+ durationMs: Date.now() - start
298
458
  });
299
- }
300
- emit({
301
- type: "company:switched",
302
- from,
303
- to: target?.id ?? null,
304
- durationMs: Date.now() - start
459
+ };
460
+ const task = switchChain.current.then(run, run);
461
+ switchChain.current = task.catch(() => {
305
462
  });
463
+ return task;
306
464
  },
307
465
  [client, storage, qc, emit]
308
466
  );
309
- const load = react.useCallback(async () => {
310
- const token = storage.getCustomerToken();
311
- if (!token) {
312
- setMyCompanies([]);
313
- setActive(null);
314
- setStatus("idle");
315
- return;
316
- }
317
- setStatus("loading");
318
- try {
319
- const companies = await client.companies.listMine(emporixSdk.auth.customer(token));
320
- setMyCompanies(companies);
321
- const persisted = initialActiveLegalEntityId ?? storage.getActiveLegalEntityId();
322
- const matched = persisted ? companies.find((c) => c.id === persisted) ?? null : null;
323
- if (matched) {
324
- setActive(matched);
325
- if (storage.getActiveLegalEntityId() !== matched.id) {
326
- storage.setActiveLegalEntityId(matched.id ?? null);
327
- }
328
- } else if (companies.length === 1) {
329
- await switchTo(companies[0] ?? null);
330
- } else {
467
+ const load = (0, import_react2.useCallback)(
468
+ async (signal) => {
469
+ const token = storage.getCustomerToken();
470
+ if (!token) {
471
+ if (signal?.cancelled) return;
472
+ setMyCompanies([]);
331
473
  setActive(null);
332
- if (persisted && !matched) storage.setActiveLegalEntityId(null);
474
+ setStatus("idle");
475
+ return;
333
476
  }
334
- setStatus("idle");
335
- } catch (e) {
336
- setError(e);
337
- setStatus("error");
338
- }
339
- }, [client, storage, initialActiveLegalEntityId, switchTo]);
340
- react.useEffect(() => {
341
- void load();
477
+ setStatus("loading");
478
+ try {
479
+ const companies = await client.companies.listMine(import_emporix_sdk.auth.customer(token));
480
+ if (signal?.cancelled) return;
481
+ setMyCompanies(companies);
482
+ const persisted = initialActiveLegalEntityId ?? storage.getActiveLegalEntityId();
483
+ const matched = persisted ? companies.find((c) => c.id === persisted) ?? null : null;
484
+ if (matched) {
485
+ setActive(matched);
486
+ if (storage.getActiveLegalEntityId() !== matched.id) {
487
+ storage.setActiveLegalEntityId(matched.id ?? null);
488
+ }
489
+ } else if (companies.length === 1) {
490
+ await switchTo(companies[0] ?? null);
491
+ } else {
492
+ setActive(null);
493
+ if (persisted && !matched) storage.setActiveLegalEntityId(null);
494
+ }
495
+ if (signal?.cancelled) return;
496
+ setStatus("idle");
497
+ } catch (e) {
498
+ if (signal?.cancelled) return;
499
+ setError(e);
500
+ setStatus("error");
501
+ }
502
+ },
503
+ [client, storage, initialActiveLegalEntityId, switchTo]
504
+ );
505
+ (0, import_react2.useEffect)(() => {
506
+ const signal = { cancelled: false };
507
+ void load(signal);
508
+ return () => {
509
+ signal.cancelled = true;
510
+ };
342
511
  }, [load]);
343
- react.useEffect(() => {
512
+ (0, import_react2.useEffect)(() => {
344
513
  let prev = storage.getCustomerToken();
345
514
  return storage.subscribe?.((next) => {
346
515
  const becameAuth = !prev && next;
@@ -349,7 +518,7 @@ function CompanyContextProvider({
349
518
  if (becameAuth || becameUnauth) void load();
350
519
  });
351
520
  }, [storage, load]);
352
- const setActiveCompany = react.useCallback(
521
+ const setActiveCompany = (0, import_react2.useCallback)(
353
522
  async (legalEntityId) => {
354
523
  setStatus("switching");
355
524
  try {
@@ -369,7 +538,7 @@ function CompanyContextProvider({
369
538
  },
370
539
  [myCompanies, switchTo]
371
540
  );
372
- const value = react.useMemo(() => {
541
+ const value = (0, import_react2.useMemo)(() => {
373
542
  const mode = activeCompany ? "b2b" : myCompanies.length > 1 ? "unresolved" : "b2c";
374
543
  return {
375
544
  activeCompany,
@@ -381,10 +550,13 @@ function CompanyContextProvider({
381
550
  refetchMyCompanies: load
382
551
  };
383
552
  }, [activeCompany, myCompanies, status, error, setActiveCompany, load]);
384
- return /* @__PURE__ */ jsxRuntime.jsx(EmporixCompanyContext.Provider, { value, children });
553
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EmporixCompanyContext.Provider, { value, children });
385
554
  }
386
- var EmporixContext = react.createContext(null);
387
- var EmporixSiteContext = react.createContext(null);
555
+
556
+ // src/provider.tsx
557
+ var import_jsx_runtime2 = require("react/jsx-runtime");
558
+ var EmporixContext = (0, import_react3.createContext)(null);
559
+ var EmporixSiteContext = (0, import_react3.createContext)(null);
388
560
  var DEFAULT_QUERY_OPTIONS = {
389
561
  staleTime: 3e4,
390
562
  refetchOnWindowFocus: false,
@@ -403,27 +575,35 @@ function EmporixProvider({
403
575
  onCustomerSessionExpired,
404
576
  children
405
577
  }) {
406
- const value = react.useMemo(() => {
578
+ const value = (0, import_react3.useMemo)(() => {
407
579
  const s = storage ?? createMemoryStorage(
408
580
  initialCustomerToken !== void 0 ? { initial: initialCustomerToken } : {}
409
581
  );
410
- if (initialCustomerToken && storage && storage.getCustomerToken() === null) {
411
- storage.setCustomerToken(initialCustomerToken);
412
- }
413
582
  return { client, storage: s };
414
583
  }, [client, storage, initialCustomerToken]);
415
- const qc = react.useMemo(
416
- () => queryClient ?? new reactQuery.QueryClient({ defaultOptions: { queries: DEFAULT_QUERY_OPTIONS } }),
417
- [queryClient]
418
- );
419
- react.useState(() => {
584
+ const [fallbackQc] = (0, import_react3.useState)(() => new import_react_query2.QueryClient());
585
+ const qc = queryClient ?? fallbackQc;
586
+ const defaultsRef = (0, import_react3.useRef)(null);
587
+ if (defaultsRef.current !== qc) {
588
+ qc.setQueryDefaults(["emporix"], {
589
+ ...DEFAULT_QUERY_OPTIONS,
590
+ ...qc.getDefaultOptions().queries,
591
+ ...qc.getQueryDefaults(["emporix"])
592
+ });
593
+ defaultsRef.current = qc;
594
+ }
595
+ const wiredRef = (0, import_react3.useRef)(null);
596
+ if (wiredRef.current?.client !== client || wiredRef.current?.storage !== value.storage) {
420
597
  client.tokenProvider.attachAnonymousStore?.({
421
598
  read: () => value.storage.getAnonymousSession(),
422
599
  write: (s) => value.storage.setAnonymousSession(s)
423
600
  });
424
- return null;
425
- });
426
- const safeEmit = react.useCallback(
601
+ if (initialCustomerToken && storage && storage.getCustomerToken() === null) {
602
+ storage.setCustomerToken(initialCustomerToken);
603
+ }
604
+ wiredRef.current = { client, storage: value.storage };
605
+ }
606
+ const safeEmit = (0, import_react3.useCallback)(
427
607
  (event) => {
428
608
  if (!onTelemetry) return;
429
609
  try {
@@ -434,8 +614,8 @@ function EmporixProvider({
434
614
  },
435
615
  [onTelemetry]
436
616
  );
437
- const telemetryValue = react.useMemo(() => ({ emit: safeEmit }), [safeEmit]);
438
- react.useEffect(() => {
617
+ const telemetryValue = (0, import_react3.useMemo)(() => ({ emit: safeEmit }), [safeEmit]);
618
+ (0, import_react3.useEffect)(() => {
439
619
  if (!onTelemetry) return;
440
620
  const startedAt = /* @__PURE__ */ new Map();
441
621
  const unsubQuery = qc.getQueryCache().subscribe((event) => {
@@ -514,7 +694,7 @@ function EmporixProvider({
514
694
  unsubStorage?.();
515
695
  };
516
696
  }, [qc, onTelemetry, client, value.storage, safeEmit]);
517
- react.useEffect(() => {
697
+ (0, import_react3.useEffect)(() => {
518
698
  if (!autoRefreshCustomerToken) return;
519
699
  const storage2 = value.storage;
520
700
  client.setCustomerTokenRefresher({
@@ -544,14 +724,14 @@ function EmporixProvider({
544
724
  });
545
725
  return () => client.setCustomerTokenRefresher(null);
546
726
  }, [autoRefreshCustomerToken, client, value.storage, safeEmit, onCustomerSessionExpired]);
547
- return /* @__PURE__ */ jsxRuntime.jsx(EmporixContext.Provider, { value, children: /* @__PURE__ */ jsxRuntime.jsx(EmporixTelemetryContext.Provider, { value: telemetryValue, children: /* @__PURE__ */ jsxRuntime.jsx(reactQuery.QueryClientProvider, { client: qc, children: /* @__PURE__ */ jsxRuntime.jsx(
727
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(EmporixContext.Provider, { value, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(EmporixTelemetryContext.Provider, { value: telemetryValue, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_query2.QueryClientProvider, { client: qc, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
548
728
  SiteContextProvider,
549
729
  {
550
730
  client,
551
731
  storage: value.storage,
552
732
  ...initialSiteCode !== void 0 ? { initialSiteCode } : {},
553
733
  ...initialLanguage !== void 0 ? { initialLanguage } : {},
554
- children: /* @__PURE__ */ jsxRuntime.jsx(
734
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
555
735
  CompanyContextProvider,
556
736
  {
557
737
  client,
@@ -570,30 +750,30 @@ function SiteContextProvider({
570
750
  initialLanguage,
571
751
  children
572
752
  }) {
573
- const qc = reactQuery.useQueryClient();
574
- const [siteCode, setSiteCodeState] = react.useState(() => {
753
+ const qc = (0, import_react_query2.useQueryClient)();
754
+ const [siteCode, setSiteCodeState] = (0, import_react3.useState)(() => {
575
755
  if (initialSiteCode !== void 0) return initialSiteCode;
576
756
  const fromStorage = storage.getSiteCode();
577
757
  if (fromStorage !== null) return fromStorage;
578
758
  return client.config?.credentials?.storefront?.context?.siteCode ?? null;
579
759
  });
580
- const [currency, setCurrencyState] = react.useState(
760
+ const [currency, setCurrencyState] = (0, import_react3.useState)(
581
761
  () => client.config?.credentials?.storefront?.context?.currency ?? null
582
762
  );
583
- const [language, setLanguageState] = react.useState(() => {
763
+ const [language, setLanguageState] = (0, import_react3.useState)(() => {
584
764
  if (initialLanguage !== void 0) return initialLanguage;
585
765
  const fromStorage = storage.getLanguage();
586
766
  if (fromStorage !== null) return fromStorage;
587
767
  return client.config?.credentials?.storefront?.context?.language ?? null;
588
768
  });
589
- const [targetLocation, setTargetLocation] = react.useState(null);
590
- const [isSwitching, setIsSwitching] = react.useState(false);
591
- const [switchError, setSwitchError] = react.useState(null);
592
- react.useEffect(() => {
769
+ const [targetLocation, setTargetLocation] = (0, import_react3.useState)(null);
770
+ const [isSwitching, setIsSwitching] = (0, import_react3.useState)(false);
771
+ const [switchError, setSwitchError] = (0, import_react3.useState)(null);
772
+ (0, import_react3.useEffect)(() => {
593
773
  if (!siteCode || currency !== null && targetLocation !== null && language !== null) return;
594
774
  let cancelled = false;
595
775
  const token = storage.getCustomerToken();
596
- const authCtx = token ? emporixSdk.auth.customer(token) : emporixSdk.auth.anonymous();
776
+ const authCtx = token ? import_emporix_sdk2.auth.customer(token) : import_emporix_sdk2.auth.anonymous();
597
777
  qc.fetchQuery({
598
778
  queryKey: [
599
779
  "emporix",
@@ -617,10 +797,10 @@ function SiteContextProvider({
617
797
  cancelled = true;
618
798
  };
619
799
  }, [siteCode]);
620
- react.useEffect(() => {
800
+ (0, import_react3.useEffect)(() => {
621
801
  if (language) client.setStorefrontContext({ language });
622
802
  }, []);
623
- const setSite = react.useCallback(
803
+ const setSite = (0, import_react3.useCallback)(
624
804
  async (code) => {
625
805
  storage.setSiteCode(code);
626
806
  storage.setCartId(null);
@@ -635,7 +815,7 @@ function SiteContextProvider({
635
815
  setIsSwitching(true);
636
816
  try {
637
817
  const token = storage.getCustomerToken();
638
- const authCtx = token ? emporixSdk.auth.customer(token) : emporixSdk.auth.anonymous();
818
+ const authCtx = token ? import_emporix_sdk2.auth.customer(token) : import_emporix_sdk2.auth.anonymous();
639
819
  const site = await qc.fetchQuery({
640
820
  queryKey: [
641
821
  "emporix",
@@ -670,7 +850,7 @@ function SiteContextProvider({
670
850
  },
671
851
  [client, storage, qc, language]
672
852
  );
673
- const setCurrency = react.useCallback(
853
+ const setCurrency = (0, import_react3.useCallback)(
674
854
  async (next) => {
675
855
  storage.setCartId(null);
676
856
  setCurrencyState(next);
@@ -680,7 +860,7 @@ function SiteContextProvider({
680
860
  setIsSwitching(true);
681
861
  try {
682
862
  const token = storage.getCustomerToken();
683
- const authCtx = token ? emporixSdk.auth.customer(token) : emporixSdk.auth.anonymous();
863
+ const authCtx = token ? import_emporix_sdk2.auth.customer(token) : import_emporix_sdk2.auth.anonymous();
684
864
  await client.sessionContext.patch(
685
865
  { currency: next, ...siteCode ? { siteCode } : {} },
686
866
  authCtx
@@ -693,7 +873,7 @@ function SiteContextProvider({
693
873
  },
694
874
  [client, storage, qc, siteCode]
695
875
  );
696
- const setLanguage = react.useCallback(
876
+ const setLanguage = (0, import_react3.useCallback)(
697
877
  async (next) => {
698
878
  storage.setLanguage(next);
699
879
  setLanguageState(next);
@@ -703,7 +883,7 @@ function SiteContextProvider({
703
883
  setIsSwitching(true);
704
884
  try {
705
885
  const token = storage.getCustomerToken();
706
- const authCtx = token ? emporixSdk.auth.customer(token) : emporixSdk.auth.anonymous();
886
+ const authCtx = token ? import_emporix_sdk2.auth.customer(token) : import_emporix_sdk2.auth.anonymous();
707
887
  await client.sessionContext.patch(
708
888
  { language: next, ...siteCode ? { siteCode } : {} },
709
889
  authCtx
@@ -716,7 +896,7 @@ function SiteContextProvider({
716
896
  },
717
897
  [client, storage, qc, siteCode]
718
898
  );
719
- const value = react.useMemo(
899
+ const value = (0, import_react3.useMemo)(
720
900
  () => ({
721
901
  siteCode,
722
902
  currency,
@@ -730,14 +910,19 @@ function SiteContextProvider({
730
910
  }),
731
911
  [siteCode, currency, targetLocation, language, setSite, setCurrency, setLanguage, isSwitching, switchError]
732
912
  );
733
- return /* @__PURE__ */ jsxRuntime.jsx(EmporixSiteContext.Provider, { value, children });
913
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(EmporixSiteContext.Provider, { value, children });
734
914
  }
735
915
  function useEmporix() {
736
- const ctx = react.useContext(EmporixContext);
916
+ const ctx = (0, import_react3.useContext)(EmporixContext);
737
917
  if (!ctx) throw new Error("useEmporix must be used within an EmporixProvider");
738
918
  return ctx;
739
919
  }
740
920
 
921
+ // src/hooks/use-customer-session.ts
922
+ var import_react4 = require("react");
923
+ var import_react_query3 = require("@tanstack/react-query");
924
+ var import_emporix_sdk3 = require("@viu/emporix-sdk");
925
+
741
926
  // src/hooks/internal/bootstrap-cart.ts
742
927
  async function bootstrapCart(opts) {
743
928
  return opts.qc.fetchQuery({
@@ -771,8 +956,8 @@ function getCustomerSessionStore(storage) {
771
956
  if (existing) return existing;
772
957
  let state = {
773
958
  token: storage.getCustomerToken(),
774
- refreshToken: null,
775
- saasToken: null
959
+ refreshToken: storage.getRefreshToken(),
960
+ saasToken: storage.getSaasToken?.() ?? null
776
961
  };
777
962
  const listeners = /* @__PURE__ */ new Set();
778
963
  const store = {
@@ -790,6 +975,9 @@ function getCustomerSessionStore(storage) {
790
975
  };
791
976
  }
792
977
  };
978
+ storage.subscribe?.((t) => {
979
+ store.setState((s) => s.token === t ? s : { ...s, token: t });
980
+ });
793
981
  stores.set(storage, store);
794
982
  return store;
795
983
  }
@@ -802,27 +990,25 @@ var EMPTY_SESSION = {
802
990
  };
803
991
  function useCustomerSession() {
804
992
  const { client, storage } = useEmporix();
805
- const qc = reactQuery.useQueryClient();
806
- const siteCtx = react.useContext(EmporixSiteContext);
807
- const store = react.useMemo(() => getCustomerSessionStore(storage), [storage]);
808
- const session = react.useSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);
993
+ const qc = (0, import_react_query3.useQueryClient)();
994
+ const siteCtx = (0, import_react4.useContext)(EmporixSiteContext);
995
+ const store = (0, import_react4.useMemo)(() => getCustomerSessionStore(storage), [storage]);
996
+ const session = (0, import_react4.useSyncExternalStore)(store.subscribe, store.getSnapshot, store.getSnapshot);
809
997
  const setSession = store.setState;
810
- react.useEffect(() => {
811
- return storage.subscribe?.((t) => setSession((s) => ({ ...s, token: t })));
812
- }, [storage, setSession]);
813
- const meQuery = reactQuery.useQuery({
998
+ const meQuery = (0, import_react_query3.useQuery)({
814
999
  queryKey: ["emporix", "customer", "me", { tenant: client.tenant, hasToken: session.token !== null }],
815
1000
  enabled: session.token !== null,
816
- queryFn: () => client.customers.me(emporixSdk.auth.customer(session.token)),
1001
+ queryFn: () => client.customers.me(import_emporix_sdk3.auth.customer(session.token)),
817
1002
  // 30s — matches Balanced default. Lets honourPreferredSite's fetchQuery
818
1003
  // (with staleTime: Infinity) reuse the cache instead of refetching.
819
1004
  staleTime: 3e4
820
1005
  });
821
- const login = react.useCallback(
1006
+ const login = (0, import_react4.useCallback)(
822
1007
  async (input) => {
823
1008
  const result = await client.customers.login(input);
824
1009
  storage.setCustomerToken(result.customerToken);
825
1010
  storage.setRefreshToken(result.refreshToken || null);
1011
+ storage.setSaasToken?.(result.saasToken || null);
826
1012
  storage.setAnonymousSession(null);
827
1013
  setSession({
828
1014
  token: result.customerToken,
@@ -846,16 +1032,17 @@ function useCustomerSession() {
846
1032
  },
847
1033
  [client, storage, qc, siteCtx, setSession]
848
1034
  );
849
- const signup = react.useCallback(
1035
+ const signup = (0, import_react4.useCallback)(
850
1036
  async (input) => {
851
1037
  await client.customers.signup(input);
852
1038
  },
853
1039
  [client]
854
1040
  );
855
- const applySession = react.useCallback(
1041
+ const applySession = (0, import_react4.useCallback)(
856
1042
  async (incoming) => {
857
1043
  storage.setCustomerToken(incoming.customerToken);
858
1044
  storage.setRefreshToken(incoming.refreshToken || null);
1045
+ storage.setSaasToken?.(incoming.saasToken || null);
859
1046
  storage.setAnonymousSession(null);
860
1047
  setSession({
861
1048
  token: incoming.customerToken,
@@ -879,37 +1066,37 @@ function useCustomerSession() {
879
1066
  },
880
1067
  [client, storage, qc, siteCtx, setSession]
881
1068
  );
882
- const socialLogin = react.useCallback(
1069
+ const socialLogin = (0, import_react4.useCallback)(
883
1070
  async (input) => {
884
1071
  await applySession(await client.customers.socialLogin(input));
885
1072
  },
886
1073
  [client, applySession]
887
1074
  );
888
- const exchangeToken = react.useCallback(
1075
+ const exchangeToken = (0, import_react4.useCallback)(
889
1076
  async (input) => {
890
1077
  await applySession(await client.customers.exchangeToken(input));
891
1078
  },
892
1079
  [client, applySession]
893
1080
  );
894
- const logout = react.useCallback(async () => {
1081
+ const logout = (0, import_react4.useCallback)(async () => {
895
1082
  if (session.token) {
896
1083
  try {
897
- await client.customers.logout(emporixSdk.auth.customer(session.token));
1084
+ await client.customers.logout(import_emporix_sdk3.auth.customer(session.token));
898
1085
  } catch {
899
1086
  }
900
1087
  }
901
1088
  storage.setCustomerToken(null);
902
1089
  storage.setRefreshToken(null);
1090
+ storage.setSaasToken?.(null);
903
1091
  storage.setActiveLegalEntityId(null);
904
1092
  storage.setCartId(null);
905
1093
  setSession(EMPTY_SESSION);
906
- qc.removeQueries({ queryKey: ["emporix", "customer"] });
907
- qc.removeQueries({ queryKey: ["emporix", "cart"] });
1094
+ qc.removeQueries({ queryKey: ["emporix"] });
908
1095
  }, [client, session.token, storage, qc, setSession]);
909
- const refresh = react.useCallback(async () => {
1096
+ const refresh = (0, import_react4.useCallback)(async () => {
910
1097
  await meQuery.refetch();
911
1098
  }, [meQuery]);
912
- const refreshSession = react.useCallback(async () => {
1099
+ const refreshSession = (0, import_react4.useCallback)(async () => {
913
1100
  if (!session.refreshToken) return;
914
1101
  const refreshed = await client.customers.refresh({
915
1102
  refreshToken: session.refreshToken,
@@ -917,6 +1104,7 @@ function useCustomerSession() {
917
1104
  });
918
1105
  storage.setCustomerToken(refreshed.customerToken);
919
1106
  if (refreshed.refreshToken) storage.setRefreshToken(refreshed.refreshToken);
1107
+ if (refreshed.saasToken) storage.setSaasToken?.(refreshed.saasToken);
920
1108
  setSession((s) => ({
921
1109
  token: refreshed.customerToken,
922
1110
  refreshToken: refreshed.refreshToken || s.refreshToken,
@@ -952,7 +1140,7 @@ async function honourPreferredSite(opts) {
952
1140
  "me",
953
1141
  { tenant: client.tenant, hasToken: true }
954
1142
  ],
955
- queryFn: () => client.customers.me(emporixSdk.auth.customer(customerToken)),
1143
+ queryFn: () => client.customers.me(import_emporix_sdk3.auth.customer(customerToken)),
956
1144
  // Reuse whatever meQuery already wrote (login flow runs meQuery in
957
1145
  // parallel). Without this, fetchQuery refetches if meQuery's data is
958
1146
  // already stale (default staleTime: 0 on meQuery).
@@ -969,7 +1157,7 @@ async function onboardCustomerCart(opts) {
969
1157
  const { qc, client, storage, customerToken } = opts;
970
1158
  const siteCode = client.config?.credentials?.storefront?.context?.siteCode;
971
1159
  if (!siteCode) return;
972
- const ctx = emporixSdk.auth.customer(customerToken);
1160
+ const ctx = import_emporix_sdk3.auth.customer(customerToken);
973
1161
  try {
974
1162
  const customerCart = await bootstrapCart({
975
1163
  qc,
@@ -987,22 +1175,53 @@ async function onboardCustomerCart(opts) {
987
1175
  } catch {
988
1176
  }
989
1177
  }
990
- function useReadAuth(override) {
1178
+
1179
+ // src/hooks/use-products.ts
1180
+ var import_react_query6 = require("@tanstack/react-query");
1181
+ var import_emporix_sdk6 = require("@viu/emporix-sdk");
1182
+
1183
+ // src/hooks/internal/use-read-auth.ts
1184
+ var import_emporix_sdk4 = require("@viu/emporix-sdk");
1185
+
1186
+ // src/hooks/internal/use-storage-snapshot.ts
1187
+ var import_react5 = require("react");
1188
+ function useCustomerToken() {
991
1189
  const { storage } = useEmporix();
1190
+ const store = (0, import_react5.useMemo)(() => getCustomerSessionStore(storage), [storage]);
1191
+ const getToken = (0, import_react5.useCallback)(() => store.getSnapshot().token, [store]);
1192
+ return (0, import_react5.useSyncExternalStore)(store.subscribe, getToken, getToken);
1193
+ }
1194
+ function useCartId() {
1195
+ const { storage } = useEmporix();
1196
+ const subscribe = (0, import_react5.useCallback)(
1197
+ (onChange) => storage.subscribeAll?.((key) => {
1198
+ if (key === "cartId") onChange();
1199
+ }) ?? (() => {
1200
+ }),
1201
+ [storage]
1202
+ );
1203
+ const getCartId = (0, import_react5.useCallback)(() => storage.getCartId(), [storage]);
1204
+ return (0, import_react5.useSyncExternalStore)(subscribe, getCartId, getCartId);
1205
+ }
1206
+
1207
+ // src/hooks/internal/use-read-auth.ts
1208
+ function useReadAuth(override) {
1209
+ const token = useCustomerToken();
992
1210
  if (override) return { ctx: override };
993
- const token = storage.getCustomerToken();
994
- return token ? { ctx: emporixSdk.auth.customer(token) } : { ctx: emporixSdk.auth.anonymous() };
1211
+ return token ? { ctx: import_emporix_sdk4.auth.customer(token) } : { ctx: import_emporix_sdk4.auth.anonymous() };
995
1212
  }
996
1213
  function useCustomerOnlyCtx() {
997
- const { storage } = useEmporix();
998
- const token = storage.getCustomerToken();
1214
+ const token = useCustomerToken();
999
1215
  if (!token) {
1000
1216
  throw new Error("Requires a logged-in customer (no token in storage)");
1001
1217
  }
1002
- return emporixSdk.auth.customer(token);
1218
+ return import_emporix_sdk4.auth.customer(token);
1003
1219
  }
1220
+
1221
+ // src/hooks/internal/use-read-site.ts
1222
+ var import_react6 = require("react");
1004
1223
  function useReadSite() {
1005
- const ctx = react.useContext(EmporixSiteContext);
1224
+ const ctx = (0, import_react6.useContext)(EmporixSiteContext);
1006
1225
  return { siteCode: ctx?.siteCode ?? null, language: ctx?.language ?? null };
1007
1226
  }
1008
1227
 
@@ -1020,8 +1239,11 @@ function emporixKey(resource, args, context) {
1020
1239
  }
1021
1240
  return ["emporix", resource, ...args, meta];
1022
1241
  }
1242
+
1243
+ // src/hooks/internal/use-emporix-infinite.ts
1244
+ var import_react_query4 = require("@tanstack/react-query");
1023
1245
  function useEmporixInfinite(opts) {
1024
- return reactQuery.useInfiniteQuery({
1246
+ return (0, import_react_query4.useInfiniteQuery)({
1025
1247
  queryKey: opts.queryKey,
1026
1248
  initialPageParam: 1,
1027
1249
  queryFn: ({ pageParam }) => opts.fetchPage(pageParam),
@@ -1031,25 +1253,54 @@ function useEmporixInfinite(opts) {
1031
1253
  });
1032
1254
  }
1033
1255
 
1256
+ // src/hooks/internal/use-emporix-query.ts
1257
+ var import_react_query5 = require("@tanstack/react-query");
1258
+ var import_emporix_sdk5 = require("@viu/emporix-sdk");
1259
+ function useEmporixQuery(cfg) {
1260
+ const { client } = useEmporix();
1261
+ const token = useCustomerToken();
1262
+ const { siteCode, language } = useReadSite();
1263
+ const authOverride = cfg.mode === "read-auth" ? cfg.authOverride : void 0;
1264
+ const readCtx = authOverride ?? (token ? import_emporix_sdk5.auth.customer(token) : import_emporix_sdk5.auth.anonymous());
1265
+ const authKind = cfg.mode === "customer" ? token ? "customer" : "anonymous" : readCtx.kind;
1266
+ const resolvedCtx = cfg.mode === "customer" ? import_emporix_sdk5.auth.customer(token) : readCtx;
1267
+ const siteMeta = cfg.site === "full" ? { siteCode, language } : cfg.site === "language" ? { language } : {};
1268
+ const enabled = (cfg.enabled ?? true) && (cfg.mode === "customer" ? token !== null : true);
1269
+ return (0, import_react_query5.useQuery)({
1270
+ queryKey: emporixKey(cfg.resource, cfg.args, {
1271
+ tenant: client.tenant,
1272
+ authKind,
1273
+ ...siteMeta
1274
+ }),
1275
+ queryFn: () => cfg.queryFn(resolvedCtx),
1276
+ enabled,
1277
+ ...cfg.staleTime !== void 0 ? { staleTime: cfg.staleTime } : {}
1278
+ });
1279
+ }
1280
+
1034
1281
  // src/hooks/use-products.ts
1035
1282
  var PRODUCTS_STALE_TIME = 6e4;
1036
1283
  function useProduct(productId, options = {}) {
1037
1284
  const { client } = useEmporix();
1038
- const { ctx } = useReadAuth(options.auth);
1039
- const { siteCode, language } = useReadSite();
1040
- return reactQuery.useQuery({
1041
- queryKey: emporixKey("product", [productId], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
1042
- queryFn: () => client.products.get(productId, void 0, ctx),
1285
+ return useEmporixQuery({
1286
+ mode: "read-auth",
1287
+ site: "full",
1288
+ resource: "product",
1289
+ args: [productId],
1290
+ ...options.auth ? { authOverride: options.auth } : {},
1291
+ queryFn: (ctx) => client.products.get(productId, void 0, ctx),
1043
1292
  staleTime: PRODUCTS_STALE_TIME
1044
1293
  });
1045
1294
  }
1046
1295
  function useProducts(params = {}, options = {}) {
1047
1296
  const { client } = useEmporix();
1048
- const { ctx } = useReadAuth(options.auth);
1049
- const { siteCode, language } = useReadSite();
1050
- return reactQuery.useQuery({
1051
- queryKey: emporixKey("products", [params], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
1052
- queryFn: () => client.products.list(params, ctx),
1297
+ return useEmporixQuery({
1298
+ mode: "read-auth",
1299
+ site: "full",
1300
+ resource: "products",
1301
+ args: [params],
1302
+ ...options.auth ? { authOverride: options.auth } : {},
1303
+ queryFn: (ctx) => client.products.list(params, ctx),
1053
1304
  staleTime: PRODUCTS_STALE_TIME
1054
1305
  });
1055
1306
  }
@@ -1068,50 +1319,53 @@ function useProductsInfinite(params = {}, options = {}) {
1068
1319
  }
1069
1320
  function useProductByCode(code, options = {}) {
1070
1321
  const { client } = useEmporix();
1071
- const { ctx } = useReadAuth(options.auth);
1072
- const { siteCode, language } = useReadSite();
1073
- return reactQuery.useQuery({
1074
- queryKey: emporixKey("product-by-code", [code], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
1322
+ return useEmporixQuery({
1323
+ mode: "read-auth",
1324
+ site: "full",
1325
+ resource: "product-by-code",
1326
+ args: [code],
1327
+ ...options.auth ? { authOverride: options.auth } : {},
1075
1328
  enabled: typeof code === "string" && code !== "",
1076
- queryFn: () => client.products.getByCode(code, ctx),
1329
+ queryFn: (ctx) => client.products.getByCode(code, ctx),
1077
1330
  staleTime: PRODUCTS_STALE_TIME
1078
1331
  });
1079
1332
  }
1080
1333
  function useProductSearch(query, params = {}, options = {}) {
1081
1334
  const { client } = useEmporix();
1082
- const { ctx } = useReadAuth(options.auth);
1083
- const { siteCode, language } = useReadSite();
1084
- return reactQuery.useQuery({
1085
- queryKey: emporixKey("product-search", [query, params], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
1335
+ return useEmporixQuery({
1336
+ mode: "read-auth",
1337
+ site: "full",
1338
+ resource: "product-search",
1339
+ args: [query, params],
1340
+ ...options.auth ? { authOverride: options.auth } : {},
1086
1341
  enabled: typeof query === "string" && query.trim() !== "",
1087
- queryFn: () => client.products.search(query, params, ctx),
1342
+ queryFn: (ctx) => client.products.search(query, params, ctx),
1088
1343
  staleTime: PRODUCTS_STALE_TIME
1089
1344
  });
1090
1345
  }
1091
1346
  function useProductNameSearch(term, params = {}, options = {}) {
1092
1347
  const { client } = useEmporix();
1093
- const { ctx } = useReadAuth(options.auth);
1094
- const { siteCode, language } = useReadSite();
1095
- return reactQuery.useQuery({
1096
- queryKey: emporixKey("product-name-search", [term, params], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
1348
+ return useEmporixQuery({
1349
+ mode: "read-auth",
1350
+ site: "full",
1351
+ resource: "product-name-search",
1352
+ args: [term, params],
1353
+ ...options.auth ? { authOverride: options.auth } : {},
1097
1354
  enabled: typeof term === "string" && term.trim() !== "",
1098
- queryFn: () => client.products.searchByName(term, params, ctx),
1355
+ queryFn: (ctx) => client.products.searchByName(term, params, ctx),
1099
1356
  staleTime: PRODUCTS_STALE_TIME
1100
1357
  });
1101
1358
  }
1102
1359
  function useProductsByCodes(codes, options = {}) {
1103
1360
  const { client } = useEmporix();
1104
- const { ctx } = useReadAuth(options.auth);
1105
- const { siteCode, language } = useReadSite();
1106
- return reactQuery.useQuery({
1107
- queryKey: emporixKey("products-by-codes", [codes, options.chunkSize], {
1108
- tenant: client.tenant,
1109
- authKind: ctx.kind,
1110
- siteCode,
1111
- language
1112
- }),
1361
+ return useEmporixQuery({
1362
+ mode: "read-auth",
1363
+ site: "full",
1364
+ resource: "products-by-codes",
1365
+ args: [codes, options.chunkSize],
1366
+ ...options.auth ? { authOverride: options.auth } : {},
1113
1367
  enabled: codes.length > 0,
1114
- queryFn: () => client.products.searchByCodes(
1368
+ queryFn: (ctx) => client.products.searchByCodes(
1115
1369
  codes,
1116
1370
  options.chunkSize !== void 0 ? { chunkSize: options.chunkSize } : {},
1117
1371
  ctx
@@ -1119,13 +1373,17 @@ function useProductsByCodes(codes, options = {}) {
1119
1373
  staleTime: 3e4
1120
1374
  });
1121
1375
  }
1376
+
1377
+ // src/hooks/use-shopping-lists.ts
1378
+ var import_react_query7 = require("@tanstack/react-query");
1379
+ var import_emporix_sdk7 = require("@viu/emporix-sdk");
1122
1380
  var SHOPPING_LIST_STALE_TIME = 3e4;
1123
1381
  var INVALIDATE_KEY = ["emporix", "shopping-lists"];
1124
1382
  function useShoppingLists(opts = {}) {
1125
1383
  const { client } = useEmporix();
1126
1384
  const ctx = useCustomerOnlyCtx();
1127
1385
  const { siteCode, language } = useReadSite();
1128
- return reactQuery.useQuery({
1386
+ return (0, import_react_query7.useQuery)({
1129
1387
  queryKey: emporixKey("shopping-lists", [opts.name ?? null], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
1130
1388
  queryFn: () => client.shoppingLists.list(ctx, opts),
1131
1389
  staleTime: SHOPPING_LIST_STALE_TIME
@@ -1134,8 +1392,8 @@ function useShoppingLists(opts = {}) {
1134
1392
  function useCreateShoppingList() {
1135
1393
  const { client } = useEmporix();
1136
1394
  const ctx = useCustomerOnlyCtx();
1137
- const qc = reactQuery.useQueryClient();
1138
- return reactQuery.useMutation({
1395
+ const qc = (0, import_react_query7.useQueryClient)();
1396
+ return (0, import_react_query7.useMutation)({
1139
1397
  mutationFn: (draft) => client.shoppingLists.create(draft, ctx),
1140
1398
  onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY })
1141
1399
  });
@@ -1143,8 +1401,8 @@ function useCreateShoppingList() {
1143
1401
  function useDeleteShoppingList() {
1144
1402
  const { client } = useEmporix();
1145
1403
  const ctx = useCustomerOnlyCtx();
1146
- const qc = reactQuery.useQueryClient();
1147
- return reactQuery.useMutation({
1404
+ const qc = (0, import_react_query7.useQueryClient)();
1405
+ return (0, import_react_query7.useMutation)({
1148
1406
  mutationFn: ({ customerId, name }) => client.shoppingLists.delete(customerId, ctx, name !== void 0 ? { name } : {}),
1149
1407
  onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY })
1150
1408
  });
@@ -1152,8 +1410,8 @@ function useDeleteShoppingList() {
1152
1410
  function useAddToShoppingList() {
1153
1411
  const { client } = useEmporix();
1154
1412
  const ctx = useCustomerOnlyCtx();
1155
- const qc = reactQuery.useQueryClient();
1156
- return reactQuery.useMutation({
1413
+ const qc = (0, import_react_query7.useQueryClient)();
1414
+ return (0, import_react_query7.useMutation)({
1157
1415
  mutationFn: ({ customerId, listName, item }) => client.shoppingLists.addItem(customerId, listName, item, ctx),
1158
1416
  onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY })
1159
1417
  });
@@ -1161,8 +1419,8 @@ function useAddToShoppingList() {
1161
1419
  function useRemoveFromShoppingList() {
1162
1420
  const { client } = useEmporix();
1163
1421
  const ctx = useCustomerOnlyCtx();
1164
- const qc = reactQuery.useQueryClient();
1165
- return reactQuery.useMutation({
1422
+ const qc = (0, import_react_query7.useQueryClient)();
1423
+ return (0, import_react_query7.useMutation)({
1166
1424
  mutationFn: ({ customerId, listName, productId }) => client.shoppingLists.removeItem(customerId, listName, productId, ctx),
1167
1425
  onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY })
1168
1426
  });
@@ -1170,25 +1428,27 @@ function useRemoveFromShoppingList() {
1170
1428
  function useSetShoppingListItemQuantity() {
1171
1429
  const { client } = useEmporix();
1172
1430
  const ctx = useCustomerOnlyCtx();
1173
- const qc = reactQuery.useQueryClient();
1174
- return reactQuery.useMutation({
1431
+ const qc = (0, import_react_query7.useQueryClient)();
1432
+ return (0, import_react_query7.useMutation)({
1175
1433
  mutationFn: ({ customerId, listName, productId, quantity }) => client.shoppingLists.setItemQuantity(customerId, listName, productId, quantity, ctx),
1176
1434
  onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY })
1177
1435
  });
1178
1436
  }
1437
+
1438
+ // src/hooks/use-variant-children.ts
1439
+ var import_react_query8 = require("@tanstack/react-query");
1440
+ var import_emporix_sdk8 = require("@viu/emporix-sdk");
1179
1441
  var VARIANT_CHILDREN_STALE_TIME = 6e4;
1180
1442
  function useVariantChildren(parentVariantId, options = {}) {
1181
1443
  const { client } = useEmporix();
1182
- const { ctx } = useReadAuth(options.auth);
1183
- const { siteCode, language } = useReadSite();
1184
- return reactQuery.useQuery({
1185
- queryKey: emporixKey(
1186
- "variant-children",
1187
- [parentVariantId, { pageSize: options.pageSize }],
1188
- { tenant: client.tenant, authKind: ctx.kind, siteCode, language }
1189
- ),
1444
+ return useEmporixQuery({
1445
+ mode: "read-auth",
1446
+ site: "full",
1447
+ resource: "variant-children",
1448
+ args: [parentVariantId, { pageSize: options.pageSize }],
1449
+ ...options.auth ? { authOverride: options.auth } : {},
1190
1450
  enabled: typeof parentVariantId === "string" && parentVariantId !== "",
1191
- queryFn: () => client.products.listVariantChildren(
1451
+ queryFn: (ctx) => client.products.listVariantChildren(
1192
1452
  parentVariantId,
1193
1453
  options.pageSize !== void 0 ? { pageSize: options.pageSize } : {},
1194
1454
  ctx
@@ -1196,35 +1456,45 @@ function useVariantChildren(parentVariantId, options = {}) {
1196
1456
  staleTime: VARIANT_CHILDREN_STALE_TIME
1197
1457
  });
1198
1458
  }
1459
+
1460
+ // src/hooks/use-categories.ts
1461
+ var import_react_query9 = require("@tanstack/react-query");
1462
+ var import_emporix_sdk9 = require("@viu/emporix-sdk");
1199
1463
  var CATEGORIES_STALE_TIME = 5 * 6e4;
1200
1464
  function useCategory(categoryId, options = {}) {
1201
1465
  const { client } = useEmporix();
1202
- const { ctx } = useReadAuth(options.auth);
1203
- const { siteCode, language } = useReadSite();
1204
- return reactQuery.useQuery({
1205
- queryKey: emporixKey("category", [categoryId], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
1206
- queryFn: () => client.categories.get(categoryId, ctx),
1466
+ return useEmporixQuery({
1467
+ mode: "read-auth",
1468
+ site: "full",
1469
+ resource: "category",
1470
+ args: [categoryId],
1471
+ ...options.auth ? { authOverride: options.auth } : {},
1472
+ queryFn: (ctx) => client.categories.get(categoryId, ctx),
1207
1473
  staleTime: CATEGORIES_STALE_TIME
1208
1474
  });
1209
1475
  }
1210
1476
  function useSubcategories(categoryId, params = {}, options = {}) {
1211
1477
  const { client } = useEmporix();
1212
- const { ctx } = useReadAuth(options.auth);
1213
- const { siteCode, language } = useReadSite();
1214
- return reactQuery.useQuery({
1215
- queryKey: emporixKey("subcategories", [categoryId ?? null, params], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
1478
+ return useEmporixQuery({
1479
+ mode: "read-auth",
1480
+ site: "full",
1481
+ resource: "subcategories",
1482
+ args: [categoryId ?? null, params],
1483
+ ...options.auth ? { authOverride: options.auth } : {},
1216
1484
  enabled: typeof categoryId === "string" && categoryId !== "",
1217
- queryFn: () => client.categories.subcategories(categoryId, params, ctx),
1485
+ queryFn: (ctx) => client.categories.subcategories(categoryId, params, ctx),
1218
1486
  staleTime: CATEGORIES_STALE_TIME
1219
1487
  });
1220
1488
  }
1221
1489
  function useCategories(params = {}, options = {}) {
1222
1490
  const { client } = useEmporix();
1223
- const { ctx } = useReadAuth(options.auth);
1224
- const { siteCode, language } = useReadSite();
1225
- return reactQuery.useQuery({
1226
- queryKey: emporixKey("categories", [params], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
1227
- queryFn: () => client.categories.list(params, ctx),
1491
+ return useEmporixQuery({
1492
+ mode: "read-auth",
1493
+ site: "full",
1494
+ resource: "categories",
1495
+ args: [params],
1496
+ ...options.auth ? { authOverride: options.auth } : {},
1497
+ queryFn: (ctx) => client.categories.list(params, ctx),
1228
1498
  staleTime: CATEGORIES_STALE_TIME
1229
1499
  });
1230
1500
  }
@@ -1243,22 +1513,26 @@ function useCategoriesInfinite(params = {}, options = {}) {
1243
1513
  }
1244
1514
  function useCategoryTree(options = {}) {
1245
1515
  const { client } = useEmporix();
1246
- const { ctx } = useReadAuth(options.auth);
1247
- const { siteCode, language } = useReadSite();
1248
- return reactQuery.useQuery({
1249
- queryKey: emporixKey("category-tree", [], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
1250
- queryFn: () => client.categories.tree(ctx),
1516
+ return useEmporixQuery({
1517
+ mode: "read-auth",
1518
+ site: "full",
1519
+ resource: "category-tree",
1520
+ args: [],
1521
+ ...options.auth ? { authOverride: options.auth } : {},
1522
+ queryFn: (ctx) => client.categories.tree(ctx),
1251
1523
  staleTime: CATEGORIES_STALE_TIME
1252
1524
  });
1253
1525
  }
1254
1526
  function useProductsInCategory(categoryId, params = {}, options = {}) {
1255
1527
  const { client } = useEmporix();
1256
- const { ctx } = useReadAuth(options.auth);
1257
- const { siteCode, language } = useReadSite();
1258
- return reactQuery.useQuery({
1259
- queryKey: emporixKey("products-in-category", [categoryId, params], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
1528
+ return useEmporixQuery({
1529
+ mode: "read-auth",
1530
+ site: "full",
1531
+ resource: "products-in-category",
1532
+ args: [categoryId, params],
1533
+ ...options.auth ? { authOverride: options.auth } : {},
1260
1534
  enabled: typeof categoryId === "string" && categoryId !== "",
1261
- queryFn: () => client.categories.productsIn(categoryId, params, ctx),
1535
+ queryFn: (ctx) => client.categories.productsIn(categoryId, params, ctx),
1262
1536
  staleTime: CATEGORIES_STALE_TIME
1263
1537
  });
1264
1538
  }
@@ -1277,32 +1551,36 @@ function useProductsInCategoryInfinite(categoryId, params = {}, options = {}) {
1277
1551
  staleTime: CATEGORIES_STALE_TIME
1278
1552
  });
1279
1553
  }
1554
+
1555
+ // src/hooks/use-cart.ts
1556
+ var import_react7 = require("react");
1557
+ var import_react_query10 = require("@tanstack/react-query");
1558
+ var import_emporix_sdk10 = require("@viu/emporix-sdk");
1280
1559
  function useCart(cartId, options = {}) {
1281
- const { client, storage } = useEmporix();
1282
- const { ctx } = useReadAuth(options.auth);
1283
- const { siteCode, language } = useReadSite();
1560
+ const { client } = useEmporix();
1284
1561
  const { activeCompany } = useActiveCompany();
1285
- const resolvedId = cartId ?? storage.getCartId() ?? void 0;
1286
- return reactQuery.useQuery({
1287
- queryKey: emporixKey(
1288
- "cart",
1289
- [resolvedId ?? null, activeCompany?.id ?? null],
1290
- { tenant: client.tenant, authKind: ctx.kind, siteCode, language }
1291
- ),
1562
+ const storedCartId = useCartId();
1563
+ const resolvedId = cartId ?? storedCartId ?? void 0;
1564
+ return useEmporixQuery({
1565
+ mode: "read-auth",
1566
+ site: "full",
1567
+ resource: "cart",
1568
+ args: [resolvedId ?? null, activeCompany?.id ?? null],
1569
+ ...options.auth ? { authOverride: options.auth } : {},
1292
1570
  enabled: resolvedId !== void 0,
1293
- queryFn: () => client.carts.get(resolvedId, ctx)
1571
+ queryFn: (ctx) => client.carts.get(resolvedId, ctx)
1294
1572
  });
1295
1573
  }
1296
1574
  function useCartMutations(cartId) {
1297
1575
  const { client, storage } = useEmporix();
1298
- const qc = reactQuery.useQueryClient();
1576
+ const qc = (0, import_react_query10.useQueryClient)();
1299
1577
  const { ctx } = useReadAuth();
1300
1578
  const { siteCode, language } = useReadSite();
1301
1579
  const { activeCompany } = useActiveCompany();
1302
1580
  const resolveId = () => {
1303
1581
  const id = cartId ?? storage.getCartId();
1304
1582
  if (!id) {
1305
- throw new emporixSdk.EmporixError(
1583
+ throw new import_emporix_sdk10.EmporixError(
1306
1584
  "useCartMutations: no cartId available \u2014 pass one explicitly or call useActiveCart({ create: true }) first"
1307
1585
  );
1308
1586
  }
@@ -1314,7 +1592,7 @@ function useCartMutations(cartId) {
1314
1592
  { tenant: client.tenant, authKind: ctx.kind, siteCode, language }
1315
1593
  );
1316
1594
  function make(run, optimistic) {
1317
- return reactQuery.useMutation({
1595
+ return (0, import_react_query10.useMutation)({
1318
1596
  mutationFn: async (vars) => run(resolveId(), vars),
1319
1597
  onMutate: async (vars) => {
1320
1598
  const id = resolveId();
@@ -1371,9 +1649,9 @@ function useCartMutations(cartId) {
1371
1649
  }
1372
1650
  function useCreateCart() {
1373
1651
  const { client, storage } = useEmporix();
1374
- const qc = reactQuery.useQueryClient();
1652
+ const qc = (0, import_react_query10.useQueryClient)();
1375
1653
  const { ctx } = useReadAuth();
1376
- return reactQuery.useMutation({
1654
+ return (0, import_react_query10.useMutation)({
1377
1655
  mutationFn: (input) => client.carts.create(input, ctx),
1378
1656
  onSuccess: async (cart) => {
1379
1657
  if (cart.cartId) storage.setCartId(cart.cartId);
@@ -1383,21 +1661,13 @@ function useCreateCart() {
1383
1661
  }
1384
1662
  function useActiveCart(opts) {
1385
1663
  const { client, storage } = useEmporix();
1386
- const qc = reactQuery.useQueryClient();
1664
+ const qc = (0, import_react_query10.useQueryClient)();
1387
1665
  const { ctx } = useReadAuth(opts?.auth);
1388
1666
  const { siteCode: activeSite } = useReadSite();
1389
1667
  const { activeCompany } = useActiveCompany();
1390
- const [cartId, setCartId] = react.useState(() => storage.getCartId());
1668
+ const cartId = useCartId();
1391
1669
  const effectiveLegalEntityId = opts?.legalEntityId ?? activeCompany?.id;
1392
- react.useEffect(() => {
1393
- if (!storage.subscribeAll) return;
1394
- return storage.subscribeAll((key) => {
1395
- if (key !== "cartId") return;
1396
- const next = storage.getCartId();
1397
- setCartId((prev) => prev === next ? prev : next);
1398
- });
1399
- }, [storage]);
1400
- react.useEffect(() => {
1670
+ (0, import_react7.useEffect)(() => {
1401
1671
  if (cartId !== null) return;
1402
1672
  if (!opts?.create) return;
1403
1673
  const siteCode = activeSite ?? client.config?.credentials?.storefront?.context?.siteCode;
@@ -1414,7 +1684,6 @@ function useActiveCart(opts) {
1414
1684
  if (cancelled) return;
1415
1685
  if (cart?.id) {
1416
1686
  storage.setCartId(cart.id);
1417
- setCartId(cart.id);
1418
1687
  }
1419
1688
  }).catch(() => {
1420
1689
  });
@@ -1426,13 +1695,18 @@ function useActiveCart(opts) {
1426
1695
  const data = cartId === null ? null : inner.data;
1427
1696
  return { ...inner, data };
1428
1697
  }
1698
+
1699
+ // src/hooks/use-checkout.ts
1700
+ var import_react_query11 = require("@tanstack/react-query");
1701
+ var import_emporix_sdk11 = require("@viu/emporix-sdk");
1429
1702
  var PAYMENT_MODES_STALE_TIME = 10 * 6e4;
1430
1703
  function customerOnlyCtx(token) {
1431
1704
  if (!token) throw new Error("usePaymentModes requires a logged-in customer token");
1432
- return emporixSdk.auth.customer(token);
1705
+ return import_emporix_sdk11.auth.customer(token);
1433
1706
  }
1434
1707
  function useCheckout() {
1435
- const { client } = useEmporix();
1708
+ const { client, storage } = useEmporix();
1709
+ const qc = (0, import_react_query11.useQueryClient)();
1436
1710
  const { ctx } = useReadAuth();
1437
1711
  const { activeCompany } = useActiveCompany();
1438
1712
  const withLE = (input) => {
@@ -1440,26 +1714,32 @@ function useCheckout() {
1440
1714
  if ("legalEntityId" in input) return input;
1441
1715
  return { ...input, legalEntityId: activeCompany.id };
1442
1716
  };
1443
- const placeOrder = reactQuery.useMutation({
1717
+ const onOrderPlaced = () => {
1718
+ storage.setCartId(null);
1719
+ qc.removeQueries({ queryKey: ["emporix", "cart-bootstrap"] });
1720
+ };
1721
+ const placeOrder = (0, import_react_query11.useMutation)({
1444
1722
  mutationFn: (v) => client.checkout.placeOrder(withLE(v.input), ctx, {
1445
1723
  ...v.saasToken !== void 0 ? { saasToken: v.saasToken } : {},
1446
1724
  ...v.siteCode !== void 0 ? { siteCode: v.siteCode } : {}
1447
- })
1725
+ }),
1726
+ onSuccess: onOrderPlaced
1448
1727
  });
1449
- const placeOrderFromQuote = reactQuery.useMutation({
1728
+ const placeOrderFromQuote = (0, import_react_query11.useMutation)({
1450
1729
  mutationFn: (v) => client.checkout.placeOrderFromQuote(withLE(v.input), ctx, {
1451
1730
  ...v.saasToken !== void 0 ? { saasToken: v.saasToken } : {},
1452
1731
  ...v.siteCode !== void 0 ? { siteCode: v.siteCode } : {}
1453
- })
1732
+ }),
1733
+ onSuccess: onOrderPlaced
1454
1734
  });
1455
1735
  return { placeOrder, placeOrderFromQuote };
1456
1736
  }
1457
1737
  function usePaymentModes(options = {}) {
1458
- const { client, storage } = useEmporix();
1459
- const token = storage.getCustomerToken();
1738
+ const { client } = useEmporix();
1739
+ const token = useCustomerToken();
1460
1740
  const { siteCode } = useReadSite();
1461
1741
  const { activeCompany } = useActiveCompany();
1462
- return reactQuery.useQuery({
1742
+ return (0, import_react_query11.useQuery)({
1463
1743
  queryKey: emporixKey(
1464
1744
  "payment-modes",
1465
1745
  [activeCompany?.id ?? null],
@@ -1470,12 +1750,16 @@ function usePaymentModes(options = {}) {
1470
1750
  staleTime: PAYMENT_MODES_STALE_TIME
1471
1751
  });
1472
1752
  }
1753
+
1754
+ // src/hooks/use-match-prices.ts
1755
+ var import_react_query12 = require("@tanstack/react-query");
1756
+ var import_emporix_sdk12 = require("@viu/emporix-sdk");
1473
1757
  var PRICES_STALE_TIME = 6e4;
1474
1758
  function useMatchPrices(input, options = {}) {
1475
1759
  const { client } = useEmporix();
1476
1760
  const { siteCode } = useReadSite();
1477
- const ctx = options.customerToken ? emporixSdk.auth.customer(options.customerToken) : emporixSdk.auth.anonymous();
1478
- return reactQuery.useQuery({
1761
+ const ctx = options.customerToken ? import_emporix_sdk12.auth.customer(options.customerToken) : import_emporix_sdk12.auth.anonymous();
1762
+ return (0, import_react_query12.useQuery)({
1479
1763
  queryKey: [
1480
1764
  "emporix",
1481
1765
  "match-prices",
@@ -1486,12 +1770,16 @@ function useMatchPrices(input, options = {}) {
1486
1770
  staleTime: PRICES_STALE_TIME
1487
1771
  });
1488
1772
  }
1773
+
1774
+ // src/hooks/use-match-prices-chunked.ts
1775
+ var import_react_query13 = require("@tanstack/react-query");
1776
+ var import_emporix_sdk13 = require("@viu/emporix-sdk");
1489
1777
  var PRICES_STALE_TIME2 = 6e4;
1490
1778
  function useMatchPricesChunked(input, options = {}) {
1491
1779
  const { client } = useEmporix();
1492
1780
  const { siteCode } = useReadSite();
1493
- const ctx = options.customerToken ? emporixSdk.auth.customer(options.customerToken) : emporixSdk.auth.anonymous();
1494
- return reactQuery.useQuery({
1781
+ const ctx = options.customerToken ? import_emporix_sdk13.auth.customer(options.customerToken) : import_emporix_sdk13.auth.anonymous();
1782
+ return (0, import_react_query13.useQuery)({
1495
1783
  queryKey: [
1496
1784
  "emporix",
1497
1785
  "match-prices-chunked",
@@ -1523,16 +1811,20 @@ function useProductMedia(productId) {
1523
1811
  const data = q.data?.productMedia;
1524
1812
  return { data, isLoading: q.isLoading, error: q.error };
1525
1813
  }
1814
+
1815
+ // src/hooks/use-my-segments.ts
1816
+ var import_react_query14 = require("@tanstack/react-query");
1817
+ var import_emporix_sdk14 = require("@viu/emporix-sdk");
1526
1818
  var SEGMENTS_STALE_TIME = 5 * 6e4;
1527
1819
  function customerCtx(token) {
1528
1820
  if (!token) throw new Error("requires a customer token in storage");
1529
- return emporixSdk.auth.customer(token);
1821
+ return import_emporix_sdk14.auth.customer(token);
1530
1822
  }
1531
1823
  function useMySegments(query = {}) {
1532
- const { client, storage } = useEmporix();
1533
- const token = storage.getCustomerToken();
1824
+ const { client } = useEmporix();
1825
+ const token = useCustomerToken();
1534
1826
  const { siteCode, language } = useReadSite();
1535
- return reactQuery.useQuery({
1827
+ return (0, import_react_query14.useQuery)({
1536
1828
  queryKey: ["emporix", "segment", "list", { tenant: client.tenant, query, siteCode, language }],
1537
1829
  enabled: token !== null,
1538
1830
  queryFn: () => client.segments.list(query, customerCtx(token)),
@@ -1540,10 +1832,10 @@ function useMySegments(query = {}) {
1540
1832
  });
1541
1833
  }
1542
1834
  function useMySegmentItems(query = {}) {
1543
- const { client, storage } = useEmporix();
1544
- const token = storage.getCustomerToken();
1835
+ const { client } = useEmporix();
1836
+ const token = useCustomerToken();
1545
1837
  const { siteCode, language } = useReadSite();
1546
- return reactQuery.useQuery({
1838
+ return (0, import_react_query14.useQuery)({
1547
1839
  queryKey: ["emporix", "segment", "items", { tenant: client.tenant, query, siteCode, language }],
1548
1840
  enabled: token !== null,
1549
1841
  queryFn: () => client.segments.listItems(query, customerCtx(token)),
@@ -1551,10 +1843,10 @@ function useMySegmentItems(query = {}) {
1551
1843
  });
1552
1844
  }
1553
1845
  function useMySegmentCategoryTree(query = {}) {
1554
- const { client, storage } = useEmporix();
1555
- const token = storage.getCustomerToken();
1846
+ const { client } = useEmporix();
1847
+ const token = useCustomerToken();
1556
1848
  const { siteCode, language } = useReadSite();
1557
- return reactQuery.useQuery({
1849
+ return (0, import_react_query14.useQuery)({
1558
1850
  queryKey: ["emporix", "segment", "categoryTree", { tenant: client.tenant, query, siteCode, language }],
1559
1851
  enabled: token !== null,
1560
1852
  queryFn: () => client.segments.getCategoryTree(query, customerCtx(token)),
@@ -1562,10 +1854,10 @@ function useMySegmentCategoryTree(query = {}) {
1562
1854
  });
1563
1855
  }
1564
1856
  function useMySegmentProducts(query = {}) {
1565
- const { client, storage } = useEmporix();
1566
- const token = storage.getCustomerToken();
1857
+ const { client } = useEmporix();
1858
+ const token = useCustomerToken();
1567
1859
  const { siteCode, language } = useReadSite();
1568
- return reactQuery.useQuery({
1860
+ return (0, import_react_query14.useQuery)({
1569
1861
  queryKey: ["emporix", "segment", "myProducts", { tenant: client.tenant, query, siteCode, language }],
1570
1862
  enabled: token !== null,
1571
1863
  queryFn: () => client.segments.listMyProducts(query, customerCtx(token)),
@@ -1573,8 +1865,8 @@ function useMySegmentProducts(query = {}) {
1573
1865
  });
1574
1866
  }
1575
1867
  function useMySegmentProductsInfinite(query = {}) {
1576
- const { client, storage } = useEmporix();
1577
- const token = storage.getCustomerToken();
1868
+ const { client } = useEmporix();
1869
+ const token = useCustomerToken();
1578
1870
  const { siteCode, language } = useReadSite();
1579
1871
  return useEmporixInfinite({
1580
1872
  queryKey: [
@@ -1592,10 +1884,10 @@ function useMySegmentProductsInfinite(query = {}) {
1592
1884
  });
1593
1885
  }
1594
1886
  function useMySegmentCategories(query = {}) {
1595
- const { client, storage } = useEmporix();
1596
- const token = storage.getCustomerToken();
1887
+ const { client } = useEmporix();
1888
+ const token = useCustomerToken();
1597
1889
  const { siteCode, language } = useReadSite();
1598
- return reactQuery.useQuery({
1890
+ return (0, import_react_query14.useQuery)({
1599
1891
  queryKey: ["emporix", "segment", "myCategories", { tenant: client.tenant, query, siteCode, language }],
1600
1892
  enabled: token !== null,
1601
1893
  queryFn: () => client.segments.listMyCategories(query, customerCtx(token)),
@@ -1603,8 +1895,8 @@ function useMySegmentCategories(query = {}) {
1603
1895
  });
1604
1896
  }
1605
1897
  function useMySegmentCategoriesInfinite(query = {}) {
1606
- const { client, storage } = useEmporix();
1607
- const token = storage.getCustomerToken();
1898
+ const { client } = useEmporix();
1899
+ const token = useCustomerToken();
1608
1900
  const { siteCode, language } = useReadSite();
1609
1901
  return useEmporixInfinite({
1610
1902
  queryKey: [
@@ -1621,11 +1913,15 @@ function useMySegmentCategoriesInfinite(query = {}) {
1621
1913
  staleTime: SEGMENTS_STALE_TIME
1622
1914
  });
1623
1915
  }
1916
+
1917
+ // src/hooks/use-customer-profile.ts
1918
+ var import_react_query15 = require("@tanstack/react-query");
1919
+ var import_emporix_sdk15 = require("@viu/emporix-sdk");
1624
1920
  function useUpdateCustomer() {
1625
1921
  const { client } = useEmporix();
1626
1922
  const ctx = useCustomerOnlyCtx();
1627
- const qc = reactQuery.useQueryClient();
1628
- return reactQuery.useMutation({
1923
+ const qc = (0, import_react_query15.useQueryClient)();
1924
+ return (0, import_react_query15.useMutation)({
1629
1925
  mutationFn: (patch) => client.customers.update(patch, ctx),
1630
1926
  onSuccess: () => {
1631
1927
  void qc.invalidateQueries({ queryKey: ["emporix", "customer", "me"] });
@@ -1635,17 +1931,21 @@ function useUpdateCustomer() {
1635
1931
  function useChangePassword() {
1636
1932
  const { client } = useEmporix();
1637
1933
  const ctx = useCustomerOnlyCtx();
1638
- return reactQuery.useMutation({
1934
+ return (0, import_react_query15.useMutation)({
1639
1935
  mutationFn: (input) => client.customers.changePassword(input, ctx)
1640
1936
  });
1641
1937
  }
1938
+
1939
+ // src/hooks/use-customer-addresses.ts
1940
+ var import_react_query16 = require("@tanstack/react-query");
1941
+ var import_emporix_sdk16 = require("@viu/emporix-sdk");
1642
1942
  var ADDRESSES_KEY = ["emporix", "customer", "addresses"];
1643
1943
  function useCustomerAddresses(options = {}) {
1644
- const { client, storage } = useEmporix();
1645
- const token = storage.getCustomerToken();
1944
+ const { client } = useEmporix();
1945
+ const token = useCustomerToken();
1646
1946
  const { activeCompany } = useActiveCompany();
1647
- const ctx = options.auth ?? (token ? emporixSdk.auth.customer(token) : null);
1648
- return reactQuery.useQuery({
1947
+ const ctx = options.auth ?? (token ? import_emporix_sdk16.auth.customer(token) : null);
1948
+ return (0, import_react_query16.useQuery)({
1649
1949
  queryKey: [
1650
1950
  ...ADDRESSES_KEY,
1651
1951
  { tenant: client.tenant, hasToken: token !== null, legalEntityId: activeCompany?.id ?? null }
@@ -1657,39 +1957,49 @@ function useCustomerAddresses(options = {}) {
1657
1957
  function useAddressMutations() {
1658
1958
  const { client } = useEmporix();
1659
1959
  const ctx = useCustomerOnlyCtx();
1660
- const qc = reactQuery.useQueryClient();
1960
+ const qc = (0, import_react_query16.useQueryClient)();
1661
1961
  const invalidate = () => {
1662
1962
  void qc.invalidateQueries({ queryKey: ADDRESSES_KEY });
1663
1963
  };
1664
1964
  return {
1665
- add: reactQuery.useMutation({
1965
+ add: (0, import_react_query16.useMutation)({
1666
1966
  mutationFn: (input) => client.customers.addresses.add(input, ctx),
1667
1967
  onSuccess: invalidate
1668
1968
  }),
1669
- update: reactQuery.useMutation({
1969
+ update: (0, import_react_query16.useMutation)({
1670
1970
  mutationFn: ({ id, patch }) => client.customers.addresses.update(id, patch, ctx),
1671
1971
  onSuccess: invalidate
1672
1972
  }),
1673
- remove: reactQuery.useMutation({
1973
+ remove: (0, import_react_query16.useMutation)({
1674
1974
  mutationFn: ({ id }) => client.customers.addresses.remove(id, ctx),
1675
1975
  onSuccess: invalidate
1676
1976
  })
1677
1977
  };
1678
1978
  }
1979
+
1980
+ // src/hooks/use-password-reset.ts
1981
+ var import_react_query17 = require("@tanstack/react-query");
1982
+ var import_emporix_sdk17 = require("@viu/emporix-sdk");
1679
1983
  function usePasswordReset() {
1680
1984
  const { client } = useEmporix();
1681
- const anonCtx = emporixSdk.auth.anonymous();
1985
+ const anonCtx = import_emporix_sdk17.auth.anonymous();
1682
1986
  return {
1683
- request: reactQuery.useMutation({
1987
+ request: (0, import_react_query17.useMutation)({
1684
1988
  mutationFn: (input) => client.customers.requestPasswordReset(input, anonCtx)
1685
1989
  }),
1686
- confirm: reactQuery.useMutation({
1990
+ confirm: (0, import_react_query17.useMutation)({
1687
1991
  mutationFn: (input) => client.customers.confirmPasswordReset(input, anonCtx)
1688
1992
  })
1689
1993
  };
1690
1994
  }
1995
+
1996
+ // src/hooks/use-sites.ts
1997
+ var import_react_query18 = require("@tanstack/react-query");
1998
+
1999
+ // src/hooks/use-site-context.ts
2000
+ var import_react8 = require("react");
1691
2001
  function useSiteContext() {
1692
- const ctx = react.useContext(EmporixSiteContext);
2002
+ const ctx = (0, import_react8.useContext)(EmporixSiteContext);
1693
2003
  if (!ctx) {
1694
2004
  throw new Error("useSiteContext must be used within an EmporixProvider");
1695
2005
  }
@@ -1701,7 +2011,7 @@ var SITES_STALE_TIME = 10 * 6e4;
1701
2011
  function useSites(options = {}) {
1702
2012
  const { client } = useEmporix();
1703
2013
  const { ctx } = useReadAuth(options.auth);
1704
- return reactQuery.useQuery({
2014
+ return (0, import_react_query18.useQuery)({
1705
2015
  queryKey: emporixKey("sites", [], { tenant: client.tenant, authKind: ctx.kind }),
1706
2016
  queryFn: () => client.sites.list(ctx),
1707
2017
  staleTime: SITES_STALE_TIME
@@ -1710,7 +2020,7 @@ function useSites(options = {}) {
1710
2020
  function useDefaultSite(options = {}) {
1711
2021
  const { client } = useEmporix();
1712
2022
  const { ctx } = useReadAuth(options.auth);
1713
- return reactQuery.useQuery({
2023
+ return (0, import_react_query18.useQuery)({
1714
2024
  queryKey: emporixKey("site-default", [], { tenant: client.tenant, authKind: ctx.kind }),
1715
2025
  queryFn: () => client.sites.current(ctx),
1716
2026
  staleTime: SITES_STALE_TIME
@@ -1721,79 +2031,97 @@ function useActiveSite(options = {}) {
1721
2031
  const { data: sites } = useSites(options);
1722
2032
  return siteCode ? sites?.find((s) => s.code === siteCode) : void 0;
1723
2033
  }
2034
+
2035
+ // src/hooks/use-my-companies.ts
2036
+ var import_react_query19 = require("@tanstack/react-query");
2037
+ var import_emporix_sdk18 = require("@viu/emporix-sdk");
1724
2038
  function useMyCompanies() {
1725
- const { client, storage } = useEmporix();
1726
- const token = storage.getCustomerToken();
1727
- return reactQuery.useQuery({
1728
- queryKey: emporixKey("companies", ["mine"], {
1729
- tenant: client.tenant,
1730
- authKind: token ? "customer" : "anonymous"
1731
- }),
1732
- enabled: token !== null,
1733
- queryFn: () => client.companies.listMine(emporixSdk.auth.customer(token))
2039
+ const { client } = useEmporix();
2040
+ return useEmporixQuery({
2041
+ mode: "customer",
2042
+ site: "none",
2043
+ resource: "companies",
2044
+ args: ["mine"],
2045
+ queryFn: (ctx) => client.companies.listMine(ctx)
1734
2046
  });
1735
2047
  }
2048
+
2049
+ // src/hooks/use-company.ts
2050
+ var import_react_query20 = require("@tanstack/react-query");
2051
+ var import_emporix_sdk19 = require("@viu/emporix-sdk");
1736
2052
  function useCompany(legalEntityId) {
1737
- const { client, storage } = useEmporix();
1738
- const token = storage.getCustomerToken();
1739
- return reactQuery.useQuery({
1740
- queryKey: emporixKey("companies", [legalEntityId ?? null], {
1741
- tenant: client.tenant,
1742
- authKind: token ? "customer" : "anonymous"
1743
- }),
1744
- enabled: token !== null && legalEntityId !== void 0,
1745
- queryFn: () => client.companies.get(legalEntityId, emporixSdk.auth.customer(token))
2053
+ const { client } = useEmporix();
2054
+ return useEmporixQuery({
2055
+ mode: "customer",
2056
+ site: "none",
2057
+ resource: "companies",
2058
+ args: [legalEntityId ?? null],
2059
+ enabled: legalEntityId !== void 0,
2060
+ queryFn: (ctx) => client.companies.get(legalEntityId, ctx)
1746
2061
  });
1747
2062
  }
2063
+
2064
+ // src/hooks/use-company-contacts.ts
2065
+ var import_react_query21 = require("@tanstack/react-query");
2066
+ var import_emporix_sdk20 = require("@viu/emporix-sdk");
1748
2067
  function useCompanyContacts(legalEntityId) {
1749
- const { client, storage } = useEmporix();
1750
- const token = storage.getCustomerToken();
1751
- return reactQuery.useQuery({
1752
- queryKey: emporixKey("companies", ["contacts", legalEntityId ?? null], {
1753
- tenant: client.tenant,
1754
- authKind: token ? "customer" : "anonymous"
1755
- }),
1756
- enabled: token !== null && legalEntityId !== void 0,
1757
- queryFn: () => client.contacts.listForCompany(legalEntityId, emporixSdk.auth.customer(token))
2068
+ const { client } = useEmporix();
2069
+ return useEmporixQuery({
2070
+ mode: "customer",
2071
+ site: "none",
2072
+ resource: "companies",
2073
+ args: ["contacts", legalEntityId ?? null],
2074
+ enabled: legalEntityId !== void 0,
2075
+ queryFn: (ctx) => client.contacts.listForCompany(legalEntityId, ctx)
1758
2076
  });
1759
2077
  }
2078
+
2079
+ // src/hooks/use-company-locations.ts
2080
+ var import_react_query22 = require("@tanstack/react-query");
2081
+ var import_emporix_sdk21 = require("@viu/emporix-sdk");
1760
2082
  function useCompanyLocations(legalEntityId) {
1761
- const { client, storage } = useEmporix();
1762
- const token = storage.getCustomerToken();
1763
- return reactQuery.useQuery({
1764
- queryKey: emporixKey("companies", ["locations", legalEntityId ?? null], {
1765
- tenant: client.tenant,
1766
- authKind: token ? "customer" : "anonymous"
1767
- }),
1768
- enabled: token !== null && legalEntityId !== void 0,
1769
- queryFn: () => client.locations.listForCompany(legalEntityId, emporixSdk.auth.customer(token))
2083
+ const { client } = useEmporix();
2084
+ return useEmporixQuery({
2085
+ mode: "customer",
2086
+ site: "none",
2087
+ resource: "companies",
2088
+ args: ["locations", legalEntityId ?? null],
2089
+ enabled: legalEntityId !== void 0,
2090
+ queryFn: (ctx) => client.locations.listForCompany(legalEntityId, ctx)
1770
2091
  });
1771
2092
  }
2093
+
2094
+ // src/hooks/use-company-groups.ts
2095
+ var import_react_query23 = require("@tanstack/react-query");
2096
+ var import_emporix_sdk22 = require("@viu/emporix-sdk");
1772
2097
  function useCompanyGroups(legalEntityId) {
1773
- const { client, storage } = useEmporix();
1774
- const token = storage.getCustomerToken();
1775
- return reactQuery.useQuery({
1776
- queryKey: emporixKey("companies", ["groups", legalEntityId ?? null], {
1777
- tenant: client.tenant,
1778
- authKind: token ? "customer" : "anonymous"
1779
- }),
1780
- enabled: token !== null && legalEntityId !== void 0,
1781
- queryFn: () => client.customerGroups.listForCompany(legalEntityId, emporixSdk.auth.customer(token))
2098
+ const { client } = useEmporix();
2099
+ return useEmporixQuery({
2100
+ mode: "customer",
2101
+ site: "none",
2102
+ resource: "companies",
2103
+ args: ["groups", legalEntityId ?? null],
2104
+ enabled: legalEntityId !== void 0,
2105
+ queryFn: (ctx) => client.customerGroups.listForCompany(legalEntityId, ctx)
1782
2106
  });
1783
2107
  }
2108
+
2109
+ // src/hooks/use-company-mutations.ts
2110
+ var import_react_query24 = require("@tanstack/react-query");
2111
+ var import_emporix_sdk23 = require("@viu/emporix-sdk");
1784
2112
  function useCustomerAuthResolver() {
1785
2113
  const { storage } = useEmporix();
1786
2114
  return () => {
1787
2115
  const token = storage.getCustomerToken();
1788
2116
  if (!token) throw new Error("Mutation requires a logged-in customer token");
1789
- return emporixSdk.auth.customer(token);
2117
+ return import_emporix_sdk23.auth.customer(token);
1790
2118
  };
1791
2119
  }
1792
2120
  function useCreateCompany() {
1793
2121
  const { client } = useEmporix();
1794
2122
  const resolveAuth = useCustomerAuthResolver();
1795
- const qc = reactQuery.useQueryClient();
1796
- return reactQuery.useMutation({
2123
+ const qc = (0, import_react_query24.useQueryClient)();
2124
+ return (0, import_react_query24.useMutation)({
1797
2125
  mutationFn: (input) => client.companies.create(input, resolveAuth()),
1798
2126
  onSuccess: () => qc.invalidateQueries({ queryKey: ["emporix", "companies", "mine"] })
1799
2127
  });
@@ -1801,8 +2129,8 @@ function useCreateCompany() {
1801
2129
  function useUpdateCompany() {
1802
2130
  const { client } = useEmporix();
1803
2131
  const resolveAuth = useCustomerAuthResolver();
1804
- const qc = reactQuery.useQueryClient();
1805
- return reactQuery.useMutation({
2132
+ const qc = (0, import_react_query24.useQueryClient)();
2133
+ return (0, import_react_query24.useMutation)({
1806
2134
  mutationFn: ({ id, patch }) => client.companies.update(id, patch, resolveAuth()),
1807
2135
  onSuccess: () => qc.invalidateQueries({ queryKey: ["emporix", "companies"] })
1808
2136
  });
@@ -1810,8 +2138,8 @@ function useUpdateCompany() {
1810
2138
  function useDeleteCompany() {
1811
2139
  const { client } = useEmporix();
1812
2140
  const resolveAuth = useCustomerAuthResolver();
1813
- const qc = reactQuery.useQueryClient();
1814
- return reactQuery.useMutation({
2141
+ const qc = (0, import_react_query24.useQueryClient)();
2142
+ return (0, import_react_query24.useMutation)({
1815
2143
  mutationFn: (id) => client.companies.delete(id, resolveAuth()),
1816
2144
  onSuccess: () => qc.invalidateQueries({ queryKey: ["emporix", "companies"] })
1817
2145
  });
@@ -1819,8 +2147,8 @@ function useDeleteCompany() {
1819
2147
  function useAssignContact() {
1820
2148
  const { client } = useEmporix();
1821
2149
  const resolveAuth = useCustomerAuthResolver();
1822
- const qc = reactQuery.useQueryClient();
1823
- return reactQuery.useMutation({
2150
+ const qc = (0, import_react_query24.useQueryClient)();
2151
+ return (0, import_react_query24.useMutation)({
1824
2152
  mutationFn: (input) => client.contacts.assign(input, resolveAuth()),
1825
2153
  onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("contacts") })
1826
2154
  });
@@ -1828,8 +2156,8 @@ function useAssignContact() {
1828
2156
  function useUpdateContactAssignment() {
1829
2157
  const { client } = useEmporix();
1830
2158
  const resolveAuth = useCustomerAuthResolver();
1831
- const qc = reactQuery.useQueryClient();
1832
- return reactQuery.useMutation({
2159
+ const qc = (0, import_react_query24.useQueryClient)();
2160
+ return (0, import_react_query24.useMutation)({
1833
2161
  mutationFn: ({ id, patch }) => client.contacts.update(id, patch, resolveAuth()),
1834
2162
  onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("contacts") })
1835
2163
  });
@@ -1837,8 +2165,8 @@ function useUpdateContactAssignment() {
1837
2165
  function useUnassignContact() {
1838
2166
  const { client } = useEmporix();
1839
2167
  const resolveAuth = useCustomerAuthResolver();
1840
- const qc = reactQuery.useQueryClient();
1841
- return reactQuery.useMutation({
2168
+ const qc = (0, import_react_query24.useQueryClient)();
2169
+ return (0, import_react_query24.useMutation)({
1842
2170
  mutationFn: (id) => client.contacts.unassign(id, resolveAuth()),
1843
2171
  onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("contacts") })
1844
2172
  });
@@ -1846,8 +2174,8 @@ function useUnassignContact() {
1846
2174
  function useCreateLocation() {
1847
2175
  const { client } = useEmporix();
1848
2176
  const resolveAuth = useCustomerAuthResolver();
1849
- const qc = reactQuery.useQueryClient();
1850
- return reactQuery.useMutation({
2177
+ const qc = (0, import_react_query24.useQueryClient)();
2178
+ return (0, import_react_query24.useMutation)({
1851
2179
  mutationFn: (input) => client.locations.create(input, resolveAuth()),
1852
2180
  onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("locations") })
1853
2181
  });
@@ -1855,8 +2183,8 @@ function useCreateLocation() {
1855
2183
  function useUpdateLocation() {
1856
2184
  const { client } = useEmporix();
1857
2185
  const resolveAuth = useCustomerAuthResolver();
1858
- const qc = reactQuery.useQueryClient();
1859
- return reactQuery.useMutation({
2186
+ const qc = (0, import_react_query24.useQueryClient)();
2187
+ return (0, import_react_query24.useMutation)({
1860
2188
  mutationFn: ({ id, patch }) => client.locations.update(id, patch, resolveAuth()),
1861
2189
  onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("locations") })
1862
2190
  });
@@ -1864,8 +2192,8 @@ function useUpdateLocation() {
1864
2192
  function useDeleteLocation() {
1865
2193
  const { client } = useEmporix();
1866
2194
  const resolveAuth = useCustomerAuthResolver();
1867
- const qc = reactQuery.useQueryClient();
1868
- return reactQuery.useMutation({
2195
+ const qc = (0, import_react_query24.useQueryClient)();
2196
+ return (0, import_react_query24.useMutation)({
1869
2197
  mutationFn: (id) => client.locations.delete(id, resolveAuth()),
1870
2198
  onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("locations") })
1871
2199
  });
@@ -1873,8 +2201,8 @@ function useDeleteLocation() {
1873
2201
  function useAddGroupMember() {
1874
2202
  const { client } = useEmporix();
1875
2203
  const resolveAuth = useCustomerAuthResolver();
1876
- const qc = reactQuery.useQueryClient();
1877
- return reactQuery.useMutation({
2204
+ const qc = (0, import_react_query24.useQueryClient)();
2205
+ return (0, import_react_query24.useMutation)({
1878
2206
  mutationFn: ({ groupId, member }) => client.customerGroups.addMember(groupId, member, resolveAuth()),
1879
2207
  onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("groups") })
1880
2208
  });
@@ -1882,19 +2210,22 @@ function useAddGroupMember() {
1882
2210
  function useRemoveGroupMember() {
1883
2211
  const { client } = useEmporix();
1884
2212
  const resolveAuth = useCustomerAuthResolver();
1885
- const qc = reactQuery.useQueryClient();
1886
- return reactQuery.useMutation({
2213
+ const qc = (0, import_react_query24.useQueryClient)();
2214
+ return (0, import_react_query24.useMutation)({
1887
2215
  mutationFn: ({ groupId, userId }) => client.customerGroups.removeMember(groupId, userId, resolveAuth()),
1888
2216
  onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("groups") })
1889
2217
  });
1890
2218
  }
2219
+
2220
+ // src/hooks/use-company-switcher.ts
2221
+ var import_react9 = require("react");
1891
2222
  function useCompanySwitcher() {
1892
2223
  const ctx = useActiveCompany();
1893
- const switchFn = react.useCallback(
2224
+ const switchFn = (0, import_react9.useCallback)(
1894
2225
  (legalEntityId) => ctx.setActiveCompany(legalEntityId),
1895
2226
  [ctx]
1896
2227
  );
1897
- const clearFn = react.useCallback(() => ctx.setActiveCompany(null), [ctx]);
2228
+ const clearFn = (0, import_react9.useCallback)(() => ctx.setActiveCompany(null), [ctx]);
1898
2229
  return {
1899
2230
  companies: ctx.myCompanies,
1900
2231
  active: ctx.activeCompany,
@@ -1903,23 +2234,27 @@ function useCompanySwitcher() {
1903
2234
  clear: clearFn
1904
2235
  };
1905
2236
  }
2237
+
2238
+ // src/hooks/use-cloud-functions.ts
2239
+ var import_react_query25 = require("@tanstack/react-query");
2240
+ var import_emporix_sdk24 = require("@viu/emporix-sdk");
1906
2241
  function useInvokeCloudFunction() {
1907
2242
  const { client, storage } = useEmporix();
1908
- return reactQuery.useMutation({
2243
+ return (0, import_react_query25.useMutation)({
1909
2244
  mutationFn: (vars) => {
1910
2245
  const { functionId, auth: authOverride, ...options } = vars;
1911
2246
  const token = storage.getCustomerToken();
1912
- const authCtx = authOverride ?? (token ? emporixSdk.auth.customer(token) : emporixSdk.auth.anonymous());
2247
+ const authCtx = authOverride ?? (token ? import_emporix_sdk24.auth.customer(token) : import_emporix_sdk24.auth.anonymous());
1913
2248
  return client.cloudFunctions.invoke(functionId, options, authCtx);
1914
2249
  }
1915
2250
  });
1916
2251
  }
1917
2252
  function useCloudFunction(functionId, options, queryOptions) {
1918
- const { client, storage } = useEmporix();
1919
- const token = storage.getCustomerToken();
2253
+ const { client } = useEmporix();
2254
+ const token = useCustomerToken();
1920
2255
  const { auth: authOverride, ...invokeOptions } = options ?? {};
1921
- const authCtx = authOverride ?? (token ? emporixSdk.auth.customer(token) : emporixSdk.auth.anonymous());
1922
- return reactQuery.useQuery({
2256
+ const authCtx = authOverride ?? (token ? import_emporix_sdk24.auth.customer(token) : import_emporix_sdk24.auth.anonymous());
2257
+ return (0, import_react_query25.useQuery)({
1923
2258
  queryKey: emporixKey(
1924
2259
  "cloud-function",
1925
2260
  [functionId ?? null, invokeOptions.path ?? null, invokeOptions.query ?? null],
@@ -1934,20 +2269,21 @@ function useCloudFunction(functionId, options, queryOptions) {
1934
2269
  )
1935
2270
  });
1936
2271
  }
2272
+
2273
+ // src/hooks/use-my-orders.ts
2274
+ var import_react_query26 = require("@tanstack/react-query");
2275
+ var import_emporix_sdk25 = require("@viu/emporix-sdk");
1937
2276
  function useMyOrders(options = {}) {
1938
- const { client, storage } = useEmporix();
2277
+ const { client } = useEmporix();
1939
2278
  const { activeCompany } = useActiveCompany();
1940
- const { siteCode, language } = useReadSite();
1941
- const token = storage.getCustomerToken();
2279
+ const { siteCode } = useReadSite();
1942
2280
  const effectiveLE = options.legalEntityId === null ? void 0 : options.legalEntityId ?? activeCompany?.id;
1943
- return reactQuery.useQuery({
1944
- queryKey: emporixKey(
1945
- "orders",
1946
- ["mine", effectiveLE ?? null, options.status ?? null, options.pageNumber ?? 1, options.pageSize ?? null],
1947
- { tenant: client.tenant, authKind: token ? "customer" : "anonymous", siteCode, language }
1948
- ),
1949
- enabled: token !== null,
1950
- queryFn: () => client.orders.listMine(emporixSdk.auth.customer(token), {
2281
+ return useEmporixQuery({
2282
+ mode: "customer",
2283
+ site: "full",
2284
+ resource: "orders",
2285
+ args: ["mine", effectiveLE ?? null, options.status ?? null, options.pageNumber ?? 1, options.pageSize ?? null],
2286
+ queryFn: (ctx) => client.orders.listMine(ctx, {
1951
2287
  ...options.pageNumber !== void 0 ? { pageNumber: options.pageNumber } : {},
1952
2288
  ...options.pageSize !== void 0 ? { pageSize: options.pageSize } : {},
1953
2289
  ...options.status !== void 0 ? { status: options.status } : {},
@@ -1957,11 +2293,14 @@ function useMyOrders(options = {}) {
1957
2293
  })
1958
2294
  });
1959
2295
  }
2296
+
2297
+ // src/hooks/use-my-orders-infinite.ts
2298
+ var import_emporix_sdk26 = require("@viu/emporix-sdk");
1960
2299
  function useMyOrdersInfinite(options = {}) {
1961
- const { client, storage } = useEmporix();
2300
+ const { client } = useEmporix();
1962
2301
  const { activeCompany } = useActiveCompany();
1963
2302
  const { siteCode, language } = useReadSite();
1964
- const token = storage.getCustomerToken();
2303
+ const token = useCustomerToken();
1965
2304
  const effectiveLE = options.legalEntityId === null ? void 0 : options.legalEntityId ?? activeCompany?.id;
1966
2305
  return useEmporixInfinite({
1967
2306
  queryKey: emporixKey(
@@ -1970,7 +2309,7 @@ function useMyOrdersInfinite(options = {}) {
1970
2309
  { tenant: client.tenant, authKind: token ? "customer" : "anonymous", siteCode, language }
1971
2310
  ),
1972
2311
  enabled: token !== null,
1973
- fetchPage: (pageNumber) => client.orders.listMine(emporixSdk.auth.customer(token), {
2312
+ fetchPage: (pageNumber) => client.orders.listMine(import_emporix_sdk26.auth.customer(token), {
1974
2313
  pageNumber,
1975
2314
  ...options.pageSize !== void 0 ? { pageSize: options.pageSize } : {},
1976
2315
  ...options.status !== void 0 ? { status: options.status } : {},
@@ -1980,28 +2319,33 @@ function useMyOrdersInfinite(options = {}) {
1980
2319
  })
1981
2320
  });
1982
2321
  }
2322
+
2323
+ // src/hooks/use-order.ts
2324
+ var import_react_query27 = require("@tanstack/react-query");
2325
+ var import_emporix_sdk27 = require("@viu/emporix-sdk");
1983
2326
  function useOrder(orderId, options = {}) {
1984
- const { client, storage } = useEmporix();
1985
- const token = storage.getCustomerToken();
1986
- const { language } = useReadSite();
1987
- return reactQuery.useQuery({
1988
- queryKey: emporixKey("orders", [orderId ?? null], {
1989
- tenant: client.tenant,
1990
- authKind: token ? "customer" : "anonymous",
1991
- language
1992
- }),
1993
- enabled: token !== null && orderId !== void 0,
1994
- queryFn: () => client.orders.get(
2327
+ const { client } = useEmporix();
2328
+ return useEmporixQuery({
2329
+ mode: "customer",
2330
+ site: "language",
2331
+ resource: "orders",
2332
+ args: [orderId ?? null],
2333
+ enabled: orderId !== void 0,
2334
+ queryFn: (ctx) => client.orders.get(
1995
2335
  orderId,
1996
- emporixSdk.auth.customer(token),
2336
+ ctx,
1997
2337
  options.saasToken ? { saasToken: options.saasToken } : {}
1998
2338
  )
1999
2339
  });
2000
2340
  }
2341
+
2342
+ // src/hooks/use-cancel-order.ts
2343
+ var import_react_query28 = require("@tanstack/react-query");
2344
+ var import_emporix_sdk28 = require("@viu/emporix-sdk");
2001
2345
  function useCancelOrder() {
2002
2346
  const { client, storage } = useEmporix();
2003
- const qc = reactQuery.useQueryClient();
2004
- return reactQuery.useMutation({
2347
+ const qc = (0, import_react_query28.useQueryClient)();
2348
+ return (0, import_react_query28.useMutation)({
2005
2349
  mutationKey: ["emporix", "orders", "cancel"],
2006
2350
  mutationFn: async (input) => {
2007
2351
  const token = storage.getCustomerToken();
@@ -2009,7 +2353,7 @@ function useCancelOrder() {
2009
2353
  const { orderId, saasToken } = typeof input === "string" ? { orderId: input, saasToken: void 0 } : input;
2010
2354
  await client.orders.cancel(
2011
2355
  orderId,
2012
- emporixSdk.auth.customer(token),
2356
+ import_emporix_sdk28.auth.customer(token),
2013
2357
  saasToken ? { saasToken } : {}
2014
2358
  );
2015
2359
  },
@@ -2018,10 +2362,14 @@ function useCancelOrder() {
2018
2362
  })
2019
2363
  });
2020
2364
  }
2365
+
2366
+ // src/hooks/use-order-transition.ts
2367
+ var import_react_query29 = require("@tanstack/react-query");
2368
+ var import_emporix_sdk29 = require("@viu/emporix-sdk");
2021
2369
  function useOrderTransition() {
2022
2370
  const { client, storage } = useEmporix();
2023
- const qc = reactQuery.useQueryClient();
2024
- return reactQuery.useMutation({
2371
+ const qc = (0, import_react_query29.useQueryClient)();
2372
+ return (0, import_react_query29.useMutation)({
2025
2373
  mutationKey: ["emporix", "orders", "transition"],
2026
2374
  mutationFn: async ({ orderId, status, comment, saasToken }) => {
2027
2375
  const token = storage.getCustomerToken();
@@ -2029,7 +2377,7 @@ function useOrderTransition() {
2029
2377
  await client.orders.transition(
2030
2378
  orderId,
2031
2379
  status,
2032
- emporixSdk.auth.customer(token),
2380
+ import_emporix_sdk29.auth.customer(token),
2033
2381
  {
2034
2382
  ...comment !== void 0 ? { comment } : {},
2035
2383
  ...saasToken !== void 0 ? { saasToken } : {}
@@ -2041,15 +2389,19 @@ function useOrderTransition() {
2041
2389
  })
2042
2390
  });
2043
2391
  }
2392
+
2393
+ // src/hooks/use-reorder.ts
2394
+ var import_react_query30 = require("@tanstack/react-query");
2395
+ var import_emporix_sdk30 = require("@viu/emporix-sdk");
2044
2396
  function useReorder() {
2045
2397
  const { client, storage } = useEmporix();
2046
- const qc = reactQuery.useQueryClient();
2047
- return reactQuery.useMutation({
2398
+ const qc = (0, import_react_query30.useQueryClient)();
2399
+ return (0, import_react_query30.useMutation)({
2048
2400
  mutationKey: ["emporix", "orders", "reorder"],
2049
2401
  mutationFn: async ({ orderId, saasToken }) => {
2050
2402
  const token = storage.getCustomerToken();
2051
2403
  if (!token) throw new Error("useReorder: requires a logged-in customer");
2052
- const ctx = emporixSdk.auth.customer(token);
2404
+ const ctx = import_emporix_sdk30.auth.customer(token);
2053
2405
  const order = await qc.fetchQuery({
2054
2406
  queryKey: emporixKey("orders", [orderId], { tenant: client.tenant, authKind: ctx.kind }),
2055
2407
  queryFn: () => client.orders.get(orderId, ctx, saasToken ? { saasToken } : {})
@@ -2094,10 +2446,14 @@ function useReorder() {
2094
2446
  }
2095
2447
  });
2096
2448
  }
2449
+
2450
+ // src/hooks/use-sales-order.ts
2451
+ var import_react_query31 = require("@tanstack/react-query");
2452
+ var import_emporix_sdk31 = require("@viu/emporix-sdk");
2097
2453
  function useSalesOrder(orderId, authCtx) {
2098
2454
  const { client } = useEmporix();
2099
2455
  const { language } = useReadSite();
2100
- return reactQuery.useQuery({
2456
+ return (0, import_react_query31.useQuery)({
2101
2457
  queryKey: emporixKey("salesorders", [orderId ?? null], {
2102
2458
  tenant: client.tenant,
2103
2459
  authKind: authCtx?.kind ?? "anonymous",
@@ -2107,17 +2463,21 @@ function useSalesOrder(orderId, authCtx) {
2107
2463
  queryFn: () => client.salesOrders.get(orderId, authCtx)
2108
2464
  });
2109
2465
  }
2466
+
2467
+ // src/hooks/use-update-sales-order.ts
2468
+ var import_react_query32 = require("@tanstack/react-query");
2469
+ var import_emporix_sdk32 = require("@viu/emporix-sdk");
2110
2470
  function useUpdateSalesOrder() {
2111
2471
  const { client } = useEmporix();
2112
- const qc = reactQuery.useQueryClient();
2113
- return reactQuery.useMutation({
2472
+ const qc = (0, import_react_query32.useQueryClient)();
2473
+ return (0, import_react_query32.useMutation)({
2114
2474
  mutationKey: ["emporix", "salesorders", "update"],
2115
- mutationFn: async ({ orderId, patch, auth: auth27, recalculate }) => {
2116
- if (!auth27) throw new Error("useUpdateSalesOrder: requires an auth context");
2475
+ mutationFn: async ({ orderId, patch, auth: auth21, recalculate }) => {
2476
+ if (!auth21) throw new Error("useUpdateSalesOrder: requires an auth context");
2117
2477
  return client.salesOrders.update(
2118
2478
  orderId,
2119
2479
  patch,
2120
- auth27,
2480
+ auth21,
2121
2481
  recalculate !== void 0 ? { recalculate } : {}
2122
2482
  );
2123
2483
  },
@@ -2128,11 +2488,15 @@ function useUpdateSalesOrder() {
2128
2488
  }
2129
2489
  });
2130
2490
  }
2491
+
2492
+ // src/hooks/use-availability.ts
2493
+ var import_react_query33 = require("@tanstack/react-query");
2494
+ var import_emporix_sdk33 = require("@viu/emporix-sdk");
2131
2495
  var AVAILABILITY_STALE_TIME = 3e4;
2132
2496
  function useAvailability(productId, siteCode, options = {}) {
2133
2497
  const { client } = useEmporix();
2134
- const ctx = options.customerToken ? emporixSdk.auth.customer(options.customerToken) : emporixSdk.auth.anonymous();
2135
- return reactQuery.useQuery({
2498
+ const ctx = options.customerToken ? import_emporix_sdk33.auth.customer(options.customerToken) : import_emporix_sdk33.auth.anonymous();
2499
+ return (0, import_react_query33.useQuery)({
2136
2500
  queryKey: [
2137
2501
  "emporix",
2138
2502
  "availability",
@@ -2151,11 +2515,15 @@ function useAvailability(productId, siteCode, options = {}) {
2151
2515
  staleTime: AVAILABILITY_STALE_TIME
2152
2516
  });
2153
2517
  }
2518
+
2519
+ // src/hooks/use-availabilities.ts
2520
+ var import_react_query34 = require("@tanstack/react-query");
2521
+ var import_emporix_sdk34 = require("@viu/emporix-sdk");
2154
2522
  var AVAILABILITY_STALE_TIME2 = 3e4;
2155
2523
  function useAvailabilities(productIds, siteCode, options = {}) {
2156
2524
  const { client } = useEmporix();
2157
- const ctx = options.customerToken ? emporixSdk.auth.customer(options.customerToken) : emporixSdk.auth.anonymous();
2158
- return reactQuery.useQuery({
2525
+ const ctx = options.customerToken ? import_emporix_sdk34.auth.customer(options.customerToken) : import_emporix_sdk34.auth.anonymous();
2526
+ return (0, import_react_query34.useQuery)({
2159
2527
  queryKey: [
2160
2528
  "emporix",
2161
2529
  "availabilities",
@@ -2174,29 +2542,35 @@ function useAvailabilities(productIds, siteCode, options = {}) {
2174
2542
  staleTime: AVAILABILITY_STALE_TIME2
2175
2543
  });
2176
2544
  }
2545
+
2546
+ // src/hooks/use-coupons.ts
2547
+ var import_react_query35 = require("@tanstack/react-query");
2177
2548
  var INVALIDATE_KEY2 = ["emporix", "coupons"];
2178
2549
  function useValidateCoupon() {
2179
2550
  const { client } = useEmporix();
2180
2551
  const { ctx } = useReadAuth();
2181
- return reactQuery.useMutation({
2552
+ return (0, import_react_query35.useMutation)({
2182
2553
  mutationFn: ({ code, redemption }) => client.coupons.validateCoupon(code, redemption, ctx)
2183
2554
  });
2184
2555
  }
2185
2556
  function useRedeemCoupon() {
2186
2557
  const { client } = useEmporix();
2187
2558
  const { ctx } = useReadAuth();
2188
- const qc = reactQuery.useQueryClient();
2189
- return reactQuery.useMutation({
2559
+ const qc = (0, import_react_query35.useQueryClient)();
2560
+ return (0, import_react_query35.useMutation)({
2190
2561
  mutationFn: ({ code, redemption }) => client.coupons.redeemCoupon(code, redemption, ctx),
2191
2562
  onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY2 })
2192
2563
  });
2193
2564
  }
2565
+
2566
+ // src/hooks/use-reward-points.ts
2567
+ var import_react_query36 = require("@tanstack/react-query");
2194
2568
  var STALE = 3e4;
2195
2569
  var INVALIDATE_KEY3 = ["emporix", "reward-points"];
2196
2570
  function useMyRewardPoints() {
2197
2571
  const { client } = useEmporix();
2198
2572
  const ctx = useCustomerOnlyCtx();
2199
- return reactQuery.useQuery({
2573
+ return (0, import_react_query36.useQuery)({
2200
2574
  queryKey: emporixKey("reward-points", ["mine"], { tenant: client.tenant, authKind: ctx.kind }),
2201
2575
  queryFn: () => client.rewardPoints.getMyPoints(ctx),
2202
2576
  staleTime: STALE
@@ -2205,7 +2579,7 @@ function useMyRewardPoints() {
2205
2579
  function useMyRewardPointsSummary() {
2206
2580
  const { client } = useEmporix();
2207
2581
  const ctx = useCustomerOnlyCtx();
2208
- return reactQuery.useQuery({
2582
+ return (0, import_react_query36.useQuery)({
2209
2583
  queryKey: emporixKey("reward-points", ["mine", "summary"], { tenant: client.tenant, authKind: ctx.kind }),
2210
2584
  queryFn: () => client.rewardPoints.getMySummary(ctx),
2211
2585
  staleTime: STALE
@@ -2214,7 +2588,7 @@ function useMyRewardPointsSummary() {
2214
2588
  function useRedeemOptions() {
2215
2589
  const { client } = useEmporix();
2216
2590
  const { ctx } = useReadAuth();
2217
- return reactQuery.useQuery({
2591
+ return (0, import_react_query36.useQuery)({
2218
2592
  queryKey: emporixKey("reward-points", ["redeem-options"], { tenant: client.tenant, authKind: ctx.kind }),
2219
2593
  queryFn: () => client.rewardPoints.listRedeemOptions(ctx),
2220
2594
  staleTime: STALE
@@ -2223,18 +2597,21 @@ function useRedeemOptions() {
2223
2597
  function useRedeemRewardPoints() {
2224
2598
  const { client } = useEmporix();
2225
2599
  const ctx = useCustomerOnlyCtx();
2226
- const qc = reactQuery.useQueryClient();
2227
- return reactQuery.useMutation({
2600
+ const qc = (0, import_react_query36.useQueryClient)();
2601
+ return (0, import_react_query36.useMutation)({
2228
2602
  mutationFn: (input) => client.rewardPoints.redeemMyPoints(input, ctx),
2229
2603
  onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY3 })
2230
2604
  });
2231
2605
  }
2606
+
2607
+ // src/hooks/use-returns.ts
2608
+ var import_react_query37 = require("@tanstack/react-query");
2232
2609
  var STALE2 = 3e4;
2233
2610
  var INVALIDATE_KEY4 = ["emporix", "returns"];
2234
2611
  function useMyReturns(opts = {}) {
2235
2612
  const { client } = useEmporix();
2236
2613
  const ctx = useCustomerOnlyCtx();
2237
- return reactQuery.useQuery({
2614
+ return (0, import_react_query37.useQuery)({
2238
2615
  queryKey: emporixKey("returns", [opts.query ?? null], { tenant: client.tenant, authKind: ctx.kind }),
2239
2616
  queryFn: () => client.returns.listReturns(opts.query ?? {}, ctx),
2240
2617
  staleTime: STALE2
@@ -2243,7 +2620,7 @@ function useMyReturns(opts = {}) {
2243
2620
  function useReturn(returnId) {
2244
2621
  const { client } = useEmporix();
2245
2622
  const ctx = useCustomerOnlyCtx();
2246
- return reactQuery.useQuery({
2623
+ return (0, import_react_query37.useQuery)({
2247
2624
  queryKey: emporixKey("returns", [returnId ?? null], { tenant: client.tenant, authKind: ctx.kind }),
2248
2625
  queryFn: () => client.returns.getReturn(returnId, ctx),
2249
2626
  enabled: Boolean(returnId),
@@ -2253,13 +2630,17 @@ function useReturn(returnId) {
2253
2630
  function useCreateReturn() {
2254
2631
  const { client } = useEmporix();
2255
2632
  const ctx = useCustomerOnlyCtx();
2256
- const qc = reactQuery.useQueryClient();
2257
- return reactQuery.useMutation({
2633
+ const qc = (0, import_react_query37.useQueryClient)();
2634
+ return (0, import_react_query37.useMutation)({
2258
2635
  mutationFn: (input) => client.returns.createReturn(input, ctx),
2259
2636
  onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY4 })
2260
2637
  });
2261
2638
  }
2262
- var EmporixErrorBoundary = class extends react.Component {
2639
+
2640
+ // src/errors.tsx
2641
+ var import_react10 = require("react");
2642
+ var import_emporix_sdk35 = require("@viu/emporix-sdk");
2643
+ var EmporixErrorBoundary = class extends import_react10.Component {
2263
2644
  state = { error: null };
2264
2645
  static getDerivedStateFromError(error) {
2265
2646
  return { error };
@@ -2274,127 +2655,145 @@ var EmporixErrorBoundary = class extends react.Component {
2274
2655
  };
2275
2656
  function useEmporixErrorHandler(handlers) {
2276
2657
  return (error) => {
2277
- if (error instanceof emporixSdk.EmporixAuthError) handlers.onAuthError?.(error);
2278
- else if (error instanceof emporixSdk.EmporixError) handlers.onError?.(error);
2658
+ if (error instanceof import_emporix_sdk35.EmporixAuthError) handlers.onAuthError?.(error);
2659
+ else if (error instanceof import_emporix_sdk35.EmporixError) handlers.onError?.(error);
2279
2660
  };
2280
2661
  }
2281
- async function prefetchProduct(qc, client, productId, authCtx = emporixSdk.auth.anonymous()) {
2662
+
2663
+ // src/ssr.ts
2664
+ var import_emporix_sdk36 = require("@viu/emporix-sdk");
2665
+ async function prefetchProduct(qc, client, productId, authCtx = import_emporix_sdk36.auth.anonymous(), opts = {}) {
2282
2666
  await qc.prefetchQuery({
2283
- queryKey: ["emporix", "product", productId, { tenant: client.tenant, authKind: authCtx.kind }],
2667
+ queryKey: emporixKey("product", [productId], {
2668
+ tenant: client.tenant,
2669
+ authKind: authCtx.kind,
2670
+ siteCode: opts.siteCode ?? null,
2671
+ language: opts.language ?? null
2672
+ }),
2284
2673
  queryFn: () => client.products.get(productId, void 0, authCtx)
2285
2674
  });
2286
2675
  }
2287
- async function prefetchCart(qc, client, cartId, authCtx) {
2676
+ async function prefetchCart(qc, client, cartId, authCtx, opts = {}) {
2288
2677
  await qc.prefetchQuery({
2289
- queryKey: ["emporix", "cart", cartId, { tenant: client.tenant, authKind: authCtx.kind }],
2678
+ queryKey: emporixKey("cart", [cartId, opts.activeCompanyId ?? null], {
2679
+ tenant: client.tenant,
2680
+ authKind: authCtx.kind,
2681
+ siteCode: opts.siteCode ?? null,
2682
+ language: opts.language ?? null
2683
+ }),
2290
2684
  queryFn: () => client.carts.get(cartId, authCtx)
2291
2685
  });
2292
2686
  }
2293
2687
  async function prefetchOrder(qc, client, orderId, authCtx, opts = {}) {
2294
2688
  await qc.prefetchQuery({
2295
- queryKey: ["emporix", "orders", orderId, { tenant: client.tenant, authKind: authCtx.kind }],
2689
+ queryKey: emporixKey("orders", [orderId], {
2690
+ tenant: client.tenant,
2691
+ authKind: authCtx.kind,
2692
+ language: opts.language ?? null
2693
+ }),
2296
2694
  queryFn: () => client.orders.get(orderId, authCtx, opts.saasToken ? { saasToken: opts.saasToken } : {})
2297
2695
  });
2298
2696
  }
2299
-
2300
- exports.CompanyContextProvider = CompanyContextProvider;
2301
- exports.EmporixCompanyContext = EmporixCompanyContext;
2302
- exports.EmporixErrorBoundary = EmporixErrorBoundary;
2303
- exports.EmporixProvider = EmporixProvider;
2304
- exports.createCookieStorage = createCookieStorage;
2305
- exports.createLocalStorageStorage = createLocalStorageStorage;
2306
- exports.createMemoryStorage = createMemoryStorage;
2307
- exports.prefetchCart = prefetchCart;
2308
- exports.prefetchOrder = prefetchOrder;
2309
- exports.prefetchProduct = prefetchProduct;
2310
- exports.useActiveCart = useActiveCart;
2311
- exports.useActiveCompany = useActiveCompany;
2312
- exports.useActiveSite = useActiveSite;
2313
- exports.useAddGroupMember = useAddGroupMember;
2314
- exports.useAddToShoppingList = useAddToShoppingList;
2315
- exports.useAddressMutations = useAddressMutations;
2316
- exports.useAssignContact = useAssignContact;
2317
- exports.useAvailabilities = useAvailabilities;
2318
- exports.useAvailability = useAvailability;
2319
- exports.useCancelOrder = useCancelOrder;
2320
- exports.useCart = useCart;
2321
- exports.useCartMutations = useCartMutations;
2322
- exports.useCategories = useCategories;
2323
- exports.useCategoriesInfinite = useCategoriesInfinite;
2324
- exports.useCategory = useCategory;
2325
- exports.useCategoryTree = useCategoryTree;
2326
- exports.useChangePassword = useChangePassword;
2327
- exports.useCheckout = useCheckout;
2328
- exports.useCloudFunction = useCloudFunction;
2329
- exports.useCompany = useCompany;
2330
- exports.useCompanyContacts = useCompanyContacts;
2331
- exports.useCompanyGroups = useCompanyGroups;
2332
- exports.useCompanyLocations = useCompanyLocations;
2333
- exports.useCompanySwitcher = useCompanySwitcher;
2334
- exports.useCreateCart = useCreateCart;
2335
- exports.useCreateCompany = useCreateCompany;
2336
- exports.useCreateLocation = useCreateLocation;
2337
- exports.useCreateReturn = useCreateReturn;
2338
- exports.useCreateShoppingList = useCreateShoppingList;
2339
- exports.useCustomerAddresses = useCustomerAddresses;
2340
- exports.useCustomerSession = useCustomerSession;
2341
- exports.useDefaultSite = useDefaultSite;
2342
- exports.useDeleteCompany = useDeleteCompany;
2343
- exports.useDeleteLocation = useDeleteLocation;
2344
- exports.useDeleteShoppingList = useDeleteShoppingList;
2345
- exports.useEmporix = useEmporix;
2346
- exports.useEmporixErrorHandler = useEmporixErrorHandler;
2347
- exports.useEmporixTelemetry = useEmporixTelemetry;
2348
- exports.useInvokeCloudFunction = useInvokeCloudFunction;
2349
- exports.useMatchPrices = useMatchPrices;
2350
- exports.useMatchPricesChunked = useMatchPricesChunked;
2351
- exports.useMyCompanies = useMyCompanies;
2352
- exports.useMyOrders = useMyOrders;
2353
- exports.useMyOrdersInfinite = useMyOrdersInfinite;
2354
- exports.useMyReturns = useMyReturns;
2355
- exports.useMyRewardPoints = useMyRewardPoints;
2356
- exports.useMyRewardPointsSummary = useMyRewardPointsSummary;
2357
- exports.useMySegmentCategories = useMySegmentCategories;
2358
- exports.useMySegmentCategoriesInfinite = useMySegmentCategoriesInfinite;
2359
- exports.useMySegmentCategoryTree = useMySegmentCategoryTree;
2360
- exports.useMySegmentItems = useMySegmentItems;
2361
- exports.useMySegmentProducts = useMySegmentProducts;
2362
- exports.useMySegmentProductsInfinite = useMySegmentProductsInfinite;
2363
- exports.useMySegments = useMySegments;
2364
- exports.useOrder = useOrder;
2365
- exports.useOrderTransition = useOrderTransition;
2366
- exports.usePasswordReset = usePasswordReset;
2367
- exports.usePaymentModes = usePaymentModes;
2368
- exports.useProduct = useProduct;
2369
- exports.useProductByCode = useProductByCode;
2370
- exports.useProductMedia = useProductMedia;
2371
- exports.useProductNameSearch = useProductNameSearch;
2372
- exports.useProductSearch = useProductSearch;
2373
- exports.useProducts = useProducts;
2374
- exports.useProductsByCodes = useProductsByCodes;
2375
- exports.useProductsInCategory = useProductsInCategory;
2376
- exports.useProductsInCategoryInfinite = useProductsInCategoryInfinite;
2377
- exports.useProductsInfinite = useProductsInfinite;
2378
- exports.useRedeemCoupon = useRedeemCoupon;
2379
- exports.useRedeemOptions = useRedeemOptions;
2380
- exports.useRedeemRewardPoints = useRedeemRewardPoints;
2381
- exports.useRemoveFromShoppingList = useRemoveFromShoppingList;
2382
- exports.useRemoveGroupMember = useRemoveGroupMember;
2383
- exports.useReorder = useReorder;
2384
- exports.useReturn = useReturn;
2385
- exports.useSalesOrder = useSalesOrder;
2386
- exports.useSetShoppingListItemQuantity = useSetShoppingListItemQuantity;
2387
- exports.useShoppingLists = useShoppingLists;
2388
- exports.useSiteContext = useSiteContext;
2389
- exports.useSites = useSites;
2390
- exports.useSubcategories = useSubcategories;
2391
- exports.useUnassignContact = useUnassignContact;
2392
- exports.useUpdateCompany = useUpdateCompany;
2393
- exports.useUpdateContactAssignment = useUpdateContactAssignment;
2394
- exports.useUpdateCustomer = useUpdateCustomer;
2395
- exports.useUpdateLocation = useUpdateLocation;
2396
- exports.useUpdateSalesOrder = useUpdateSalesOrder;
2397
- exports.useValidateCoupon = useValidateCoupon;
2398
- exports.useVariantChildren = useVariantChildren;
2399
- //# sourceMappingURL=index.cjs.map
2697
+ // Annotate the CommonJS export names for ESM import in node:
2698
+ 0 && (module.exports = {
2699
+ CompanyContextProvider,
2700
+ EmporixCompanyContext,
2701
+ EmporixErrorBoundary,
2702
+ EmporixProvider,
2703
+ createCookieStorage,
2704
+ createLocalStorageStorage,
2705
+ createMemoryStorage,
2706
+ prefetchCart,
2707
+ prefetchOrder,
2708
+ prefetchProduct,
2709
+ useActiveCart,
2710
+ useActiveCompany,
2711
+ useActiveSite,
2712
+ useAddGroupMember,
2713
+ useAddToShoppingList,
2714
+ useAddressMutations,
2715
+ useAssignContact,
2716
+ useAvailabilities,
2717
+ useAvailability,
2718
+ useCancelOrder,
2719
+ useCart,
2720
+ useCartMutations,
2721
+ useCategories,
2722
+ useCategoriesInfinite,
2723
+ useCategory,
2724
+ useCategoryTree,
2725
+ useChangePassword,
2726
+ useCheckout,
2727
+ useCloudFunction,
2728
+ useCompany,
2729
+ useCompanyContacts,
2730
+ useCompanyGroups,
2731
+ useCompanyLocations,
2732
+ useCompanySwitcher,
2733
+ useCreateCart,
2734
+ useCreateCompany,
2735
+ useCreateLocation,
2736
+ useCreateReturn,
2737
+ useCreateShoppingList,
2738
+ useCustomerAddresses,
2739
+ useCustomerSession,
2740
+ useDefaultSite,
2741
+ useDeleteCompany,
2742
+ useDeleteLocation,
2743
+ useDeleteShoppingList,
2744
+ useEmporix,
2745
+ useEmporixErrorHandler,
2746
+ useEmporixTelemetry,
2747
+ useInvokeCloudFunction,
2748
+ useMatchPrices,
2749
+ useMatchPricesChunked,
2750
+ useMyCompanies,
2751
+ useMyOrders,
2752
+ useMyOrdersInfinite,
2753
+ useMyReturns,
2754
+ useMyRewardPoints,
2755
+ useMyRewardPointsSummary,
2756
+ useMySegmentCategories,
2757
+ useMySegmentCategoriesInfinite,
2758
+ useMySegmentCategoryTree,
2759
+ useMySegmentItems,
2760
+ useMySegmentProducts,
2761
+ useMySegmentProductsInfinite,
2762
+ useMySegments,
2763
+ useOrder,
2764
+ useOrderTransition,
2765
+ usePasswordReset,
2766
+ usePaymentModes,
2767
+ useProduct,
2768
+ useProductByCode,
2769
+ useProductMedia,
2770
+ useProductNameSearch,
2771
+ useProductSearch,
2772
+ useProducts,
2773
+ useProductsByCodes,
2774
+ useProductsInCategory,
2775
+ useProductsInCategoryInfinite,
2776
+ useProductsInfinite,
2777
+ useRedeemCoupon,
2778
+ useRedeemOptions,
2779
+ useRedeemRewardPoints,
2780
+ useRemoveFromShoppingList,
2781
+ useRemoveGroupMember,
2782
+ useReorder,
2783
+ useReturn,
2784
+ useSalesOrder,
2785
+ useSetShoppingListItemQuantity,
2786
+ useShoppingLists,
2787
+ useSiteContext,
2788
+ useSites,
2789
+ useSubcategories,
2790
+ useUnassignContact,
2791
+ useUpdateCompany,
2792
+ useUpdateContactAssignment,
2793
+ useUpdateCustomer,
2794
+ useUpdateLocation,
2795
+ useUpdateSalesOrder,
2796
+ useValidateCoupon,
2797
+ useVariantChildren
2798
+ });
2400
2799
  //# sourceMappingURL=index.cjs.map