@viu/emporix-sdk-react 2.13.1 → 2.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/hooks.cjs CHANGED
@@ -1,11 +1,133 @@
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
- require('react/jsx-runtime');
21
+ // src/hooks/index.ts
22
+ var hooks_exports = {};
23
+ __export(hooks_exports, {
24
+ useActiveCart: () => useActiveCart,
25
+ useActiveSite: () => useActiveSite,
26
+ useAddGroupMember: () => useAddGroupMember,
27
+ useAddToShoppingList: () => useAddToShoppingList,
28
+ useAddressMutations: () => useAddressMutations,
29
+ useApproval: () => useApproval,
30
+ useApprovals: () => useApprovals,
31
+ useAssignContact: () => useAssignContact,
32
+ useAvailabilities: () => useAvailabilities,
33
+ useAvailability: () => useAvailability,
34
+ useCancelOrder: () => useCancelOrder,
35
+ useCart: () => useCart,
36
+ useCartMutations: () => useCartMutations,
37
+ useCategories: () => useCategories,
38
+ useCategoriesInfinite: () => useCategoriesInfinite,
39
+ useCategory: () => useCategory,
40
+ useCategoryTree: () => useCategoryTree,
41
+ useChangePassword: () => useChangePassword,
42
+ useCheckout: () => useCheckout,
43
+ useCloudFunction: () => useCloudFunction,
44
+ useCompany: () => useCompany,
45
+ useCompanyContacts: () => useCompanyContacts,
46
+ useCompanyGroups: () => useCompanyGroups,
47
+ useCompanyLocations: () => useCompanyLocations,
48
+ useCompanySwitcher: () => useCompanySwitcher,
49
+ useCreateApproval: () => useCreateApproval,
50
+ useCreateCart: () => useCreateCart,
51
+ useCreateCompany: () => useCreateCompany,
52
+ useCreateLocation: () => useCreateLocation,
53
+ useCreateReturn: () => useCreateReturn,
54
+ useCreateShoppingList: () => useCreateShoppingList,
55
+ useCustomerAddresses: () => useCustomerAddresses,
56
+ useCustomerSession: () => useCustomerSession,
57
+ useDefaultSite: () => useDefaultSite,
58
+ useDeleteCompany: () => useDeleteCompany,
59
+ useDeleteLocation: () => useDeleteLocation,
60
+ useDeleteShoppingList: () => useDeleteShoppingList,
61
+ useInvokeCloudFunction: () => useInvokeCloudFunction,
62
+ useMatchPrices: () => useMatchPrices,
63
+ useMatchPricesChunked: () => useMatchPricesChunked,
64
+ useMyCompanies: () => useMyCompanies,
65
+ useMyOrders: () => useMyOrders,
66
+ useMyOrdersInfinite: () => useMyOrdersInfinite,
67
+ useMyReturns: () => useMyReturns,
68
+ useMyRewardPoints: () => useMyRewardPoints,
69
+ useMyRewardPointsSummary: () => useMyRewardPointsSummary,
70
+ useMySegmentCategories: () => useMySegmentCategories,
71
+ useMySegmentCategoriesInfinite: () => useMySegmentCategoriesInfinite,
72
+ useMySegmentCategoryTree: () => useMySegmentCategoryTree,
73
+ useMySegmentItems: () => useMySegmentItems,
74
+ useMySegmentProducts: () => useMySegmentProducts,
75
+ useMySegmentProductsInfinite: () => useMySegmentProductsInfinite,
76
+ useMySegments: () => useMySegments,
77
+ useOrder: () => useOrder,
78
+ useOrderTransition: () => useOrderTransition,
79
+ usePasswordReset: () => usePasswordReset,
80
+ usePaymentModes: () => usePaymentModes,
81
+ useProduct: () => useProduct,
82
+ useProductByCode: () => useProductByCode,
83
+ useProductMedia: () => useProductMedia,
84
+ useProductNameSearch: () => useProductNameSearch,
85
+ useProductSearch: () => useProductSearch,
86
+ useProducts: () => useProducts,
87
+ useProductsByCodes: () => useProductsByCodes,
88
+ useProductsInCategory: () => useProductsInCategory,
89
+ useProductsInCategoryInfinite: () => useProductsInCategoryInfinite,
90
+ useProductsInfinite: () => useProductsInfinite,
91
+ useRedeemCoupon: () => useRedeemCoupon,
92
+ useRedeemOptions: () => useRedeemOptions,
93
+ useRedeemRewardPoints: () => useRedeemRewardPoints,
94
+ useRemoveFromShoppingList: () => useRemoveFromShoppingList,
95
+ useRemoveGroupMember: () => useRemoveGroupMember,
96
+ useReorder: () => useReorder,
97
+ useReturn: () => useReturn,
98
+ useSalesOrder: () => useSalesOrder,
99
+ useSetShoppingListItemQuantity: () => useSetShoppingListItemQuantity,
100
+ useShoppingLists: () => useShoppingLists,
101
+ useSiteContext: () => useSiteContext,
102
+ useSites: () => useSites,
103
+ useSubcategories: () => useSubcategories,
104
+ useUnassignContact: () => useUnassignContact,
105
+ useUpdateApproval: () => useUpdateApproval,
106
+ useUpdateCompany: () => useUpdateCompany,
107
+ useUpdateContactAssignment: () => useUpdateContactAssignment,
108
+ useUpdateCustomer: () => useUpdateCustomer,
109
+ useUpdateLocation: () => useUpdateLocation,
110
+ useUpdateSalesOrder: () => useUpdateSalesOrder,
111
+ useValidateCoupon: () => useValidateCoupon,
112
+ useVariantChildren: () => useVariantChildren
113
+ });
114
+ module.exports = __toCommonJS(hooks_exports);
7
115
 
8
116
  // src/hooks/use-customer-session.ts
117
+ var import_react3 = require("react");
118
+ var import_react_query3 = require("@tanstack/react-query");
119
+ var import_emporix_sdk3 = require("@viu/emporix-sdk");
120
+
121
+ // src/provider.tsx
122
+ var import_react2 = require("react");
123
+ var import_react_query2 = require("@tanstack/react-query");
124
+ var import_emporix_sdk2 = require("@viu/emporix-sdk");
125
+
126
+ // src/company-context.tsx
127
+ var import_react = require("react");
128
+ var import_react_query = require("@tanstack/react-query");
129
+ var import_emporix_sdk = require("@viu/emporix-sdk");
130
+ var import_jsx_runtime = require("react/jsx-runtime");
9
131
  var NULL_CTX = {
10
132
  activeCompany: null,
11
133
  myCompanies: [],
@@ -18,14 +140,17 @@ var NULL_CTX = {
18
140
  refetchMyCompanies: async () => {
19
141
  }
20
142
  };
21
- var EmporixCompanyContext = react.createContext(NULL_CTX);
143
+ var EmporixCompanyContext = (0, import_react.createContext)(NULL_CTX);
22
144
  function useActiveCompany() {
23
- return react.useContext(EmporixCompanyContext);
145
+ return (0, import_react.useContext)(EmporixCompanyContext);
24
146
  }
25
- var EmporixContext = react.createContext(null);
26
- var EmporixSiteContext = react.createContext(null);
147
+
148
+ // src/provider.tsx
149
+ var import_jsx_runtime2 = require("react/jsx-runtime");
150
+ var EmporixContext = (0, import_react2.createContext)(null);
151
+ var EmporixSiteContext = (0, import_react2.createContext)(null);
27
152
  function useEmporix() {
28
- const ctx = react.useContext(EmporixContext);
153
+ const ctx = (0, import_react2.useContext)(EmporixContext);
29
154
  if (!ctx) throw new Error("useEmporix must be used within an EmporixProvider");
30
155
  return ctx;
31
156
  }
@@ -82,6 +207,9 @@ function getCustomerSessionStore(storage) {
82
207
  };
83
208
  }
84
209
  };
210
+ storage.subscribe?.((t) => {
211
+ store.setState((s) => s.token === t ? s : { ...s, token: t });
212
+ });
85
213
  stores.set(storage, store);
86
214
  return store;
87
215
  }
@@ -94,23 +222,20 @@ var EMPTY_SESSION = {
94
222
  };
95
223
  function useCustomerSession() {
96
224
  const { client, storage } = useEmporix();
97
- const qc = reactQuery.useQueryClient();
98
- const siteCtx = react.useContext(EmporixSiteContext);
99
- const store = react.useMemo(() => getCustomerSessionStore(storage), [storage]);
100
- const session = react.useSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);
225
+ const qc = (0, import_react_query3.useQueryClient)();
226
+ const siteCtx = (0, import_react3.useContext)(EmporixSiteContext);
227
+ const store = (0, import_react3.useMemo)(() => getCustomerSessionStore(storage), [storage]);
228
+ const session = (0, import_react3.useSyncExternalStore)(store.subscribe, store.getSnapshot, store.getSnapshot);
101
229
  const setSession = store.setState;
102
- react.useEffect(() => {
103
- return storage.subscribe?.((t) => setSession((s) => ({ ...s, token: t })));
104
- }, [storage, setSession]);
105
- const meQuery = reactQuery.useQuery({
230
+ const meQuery = (0, import_react_query3.useQuery)({
106
231
  queryKey: ["emporix", "customer", "me", { tenant: client.tenant, hasToken: session.token !== null }],
107
232
  enabled: session.token !== null,
108
- queryFn: () => client.customers.me(emporixSdk.auth.customer(session.token)),
233
+ queryFn: () => client.customers.me(import_emporix_sdk3.auth.customer(session.token)),
109
234
  // 30s — matches Balanced default. Lets honourPreferredSite's fetchQuery
110
235
  // (with staleTime: Infinity) reuse the cache instead of refetching.
111
236
  staleTime: 3e4
112
237
  });
113
- const login = react.useCallback(
238
+ const login = (0, import_react3.useCallback)(
114
239
  async (input) => {
115
240
  const result = await client.customers.login(input);
116
241
  storage.setCustomerToken(result.customerToken);
@@ -138,13 +263,13 @@ function useCustomerSession() {
138
263
  },
139
264
  [client, storage, qc, siteCtx, setSession]
140
265
  );
141
- const signup = react.useCallback(
266
+ const signup = (0, import_react3.useCallback)(
142
267
  async (input) => {
143
268
  await client.customers.signup(input);
144
269
  },
145
270
  [client]
146
271
  );
147
- const applySession = react.useCallback(
272
+ const applySession = (0, import_react3.useCallback)(
148
273
  async (incoming) => {
149
274
  storage.setCustomerToken(incoming.customerToken);
150
275
  storage.setRefreshToken(incoming.refreshToken || null);
@@ -171,22 +296,22 @@ function useCustomerSession() {
171
296
  },
172
297
  [client, storage, qc, siteCtx, setSession]
173
298
  );
174
- const socialLogin = react.useCallback(
299
+ const socialLogin = (0, import_react3.useCallback)(
175
300
  async (input) => {
176
301
  await applySession(await client.customers.socialLogin(input));
177
302
  },
178
303
  [client, applySession]
179
304
  );
180
- const exchangeToken = react.useCallback(
305
+ const exchangeToken = (0, import_react3.useCallback)(
181
306
  async (input) => {
182
307
  await applySession(await client.customers.exchangeToken(input));
183
308
  },
184
309
  [client, applySession]
185
310
  );
186
- const logout = react.useCallback(async () => {
311
+ const logout = (0, import_react3.useCallback)(async () => {
187
312
  if (session.token) {
188
313
  try {
189
- await client.customers.logout(emporixSdk.auth.customer(session.token));
314
+ await client.customers.logout(import_emporix_sdk3.auth.customer(session.token));
190
315
  } catch {
191
316
  }
192
317
  }
@@ -195,13 +320,12 @@ function useCustomerSession() {
195
320
  storage.setActiveLegalEntityId(null);
196
321
  storage.setCartId(null);
197
322
  setSession(EMPTY_SESSION);
198
- qc.removeQueries({ queryKey: ["emporix", "customer"] });
199
- qc.removeQueries({ queryKey: ["emporix", "cart"] });
323
+ qc.removeQueries({ queryKey: ["emporix"] });
200
324
  }, [client, session.token, storage, qc, setSession]);
201
- const refresh = react.useCallback(async () => {
325
+ const refresh = (0, import_react3.useCallback)(async () => {
202
326
  await meQuery.refetch();
203
327
  }, [meQuery]);
204
- const refreshSession = react.useCallback(async () => {
328
+ const refreshSession = (0, import_react3.useCallback)(async () => {
205
329
  if (!session.refreshToken) return;
206
330
  const refreshed = await client.customers.refresh({
207
331
  refreshToken: session.refreshToken,
@@ -244,7 +368,7 @@ async function honourPreferredSite(opts) {
244
368
  "me",
245
369
  { tenant: client.tenant, hasToken: true }
246
370
  ],
247
- queryFn: () => client.customers.me(emporixSdk.auth.customer(customerToken)),
371
+ queryFn: () => client.customers.me(import_emporix_sdk3.auth.customer(customerToken)),
248
372
  // Reuse whatever meQuery already wrote (login flow runs meQuery in
249
373
  // parallel). Without this, fetchQuery refetches if meQuery's data is
250
374
  // already stale (default staleTime: 0 on meQuery).
@@ -261,7 +385,7 @@ async function onboardCustomerCart(opts) {
261
385
  const { qc, client, storage, customerToken } = opts;
262
386
  const siteCode = client.config?.credentials?.storefront?.context?.siteCode;
263
387
  if (!siteCode) return;
264
- const ctx = emporixSdk.auth.customer(customerToken);
388
+ const ctx = import_emporix_sdk3.auth.customer(customerToken);
265
389
  try {
266
390
  const customerCart = await bootstrapCart({
267
391
  qc,
@@ -279,22 +403,53 @@ async function onboardCustomerCart(opts) {
279
403
  } catch {
280
404
  }
281
405
  }
282
- function useReadAuth(override) {
406
+
407
+ // src/hooks/use-products.ts
408
+ var import_react_query5 = require("@tanstack/react-query");
409
+ var import_emporix_sdk5 = require("@viu/emporix-sdk");
410
+
411
+ // src/hooks/internal/use-read-auth.ts
412
+ var import_emporix_sdk4 = require("@viu/emporix-sdk");
413
+
414
+ // src/hooks/internal/use-storage-snapshot.ts
415
+ var import_react4 = require("react");
416
+ function useCustomerToken() {
283
417
  const { storage } = useEmporix();
418
+ const store = (0, import_react4.useMemo)(() => getCustomerSessionStore(storage), [storage]);
419
+ const getToken = (0, import_react4.useCallback)(() => store.getSnapshot().token, [store]);
420
+ return (0, import_react4.useSyncExternalStore)(store.subscribe, getToken, getToken);
421
+ }
422
+ function useCartId() {
423
+ const { storage } = useEmporix();
424
+ const subscribe = (0, import_react4.useCallback)(
425
+ (onChange) => storage.subscribeAll?.((key) => {
426
+ if (key === "cartId") onChange();
427
+ }) ?? (() => {
428
+ }),
429
+ [storage]
430
+ );
431
+ const getCartId = (0, import_react4.useCallback)(() => storage.getCartId(), [storage]);
432
+ return (0, import_react4.useSyncExternalStore)(subscribe, getCartId, getCartId);
433
+ }
434
+
435
+ // src/hooks/internal/use-read-auth.ts
436
+ function useReadAuth(override) {
437
+ const token = useCustomerToken();
284
438
  if (override) return { ctx: override };
285
- const token = storage.getCustomerToken();
286
- return token ? { ctx: emporixSdk.auth.customer(token) } : { ctx: emporixSdk.auth.anonymous() };
439
+ return token ? { ctx: import_emporix_sdk4.auth.customer(token) } : { ctx: import_emporix_sdk4.auth.anonymous() };
287
440
  }
288
441
  function useCustomerOnlyCtx() {
289
- const { storage } = useEmporix();
290
- const token = storage.getCustomerToken();
442
+ const token = useCustomerToken();
291
443
  if (!token) {
292
444
  throw new Error("Requires a logged-in customer (no token in storage)");
293
445
  }
294
- return emporixSdk.auth.customer(token);
446
+ return import_emporix_sdk4.auth.customer(token);
295
447
  }
448
+
449
+ // src/hooks/internal/use-read-site.ts
450
+ var import_react5 = require("react");
296
451
  function useReadSite() {
297
- const ctx = react.useContext(EmporixSiteContext);
452
+ const ctx = (0, import_react5.useContext)(EmporixSiteContext);
298
453
  return { siteCode: ctx?.siteCode ?? null, language: ctx?.language ?? null };
299
454
  }
300
455
 
@@ -312,8 +467,11 @@ function emporixKey(resource, args, context) {
312
467
  }
313
468
  return ["emporix", resource, ...args, meta];
314
469
  }
470
+
471
+ // src/hooks/internal/use-emporix-infinite.ts
472
+ var import_react_query4 = require("@tanstack/react-query");
315
473
  function useEmporixInfinite(opts) {
316
- return reactQuery.useInfiniteQuery({
474
+ return (0, import_react_query4.useInfiniteQuery)({
317
475
  queryKey: opts.queryKey,
318
476
  initialPageParam: 1,
319
477
  queryFn: ({ pageParam }) => opts.fetchPage(pageParam),
@@ -329,7 +487,7 @@ function useProduct(productId, options = {}) {
329
487
  const { client } = useEmporix();
330
488
  const { ctx } = useReadAuth(options.auth);
331
489
  const { siteCode, language } = useReadSite();
332
- return reactQuery.useQuery({
490
+ return (0, import_react_query5.useQuery)({
333
491
  queryKey: emporixKey("product", [productId], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
334
492
  queryFn: () => client.products.get(productId, void 0, ctx),
335
493
  staleTime: PRODUCTS_STALE_TIME
@@ -339,7 +497,7 @@ function useProducts(params = {}, options = {}) {
339
497
  const { client } = useEmporix();
340
498
  const { ctx } = useReadAuth(options.auth);
341
499
  const { siteCode, language } = useReadSite();
342
- return reactQuery.useQuery({
500
+ return (0, import_react_query5.useQuery)({
343
501
  queryKey: emporixKey("products", [params], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
344
502
  queryFn: () => client.products.list(params, ctx),
345
503
  staleTime: PRODUCTS_STALE_TIME
@@ -362,7 +520,7 @@ function useProductByCode(code, options = {}) {
362
520
  const { client } = useEmporix();
363
521
  const { ctx } = useReadAuth(options.auth);
364
522
  const { siteCode, language } = useReadSite();
365
- return reactQuery.useQuery({
523
+ return (0, import_react_query5.useQuery)({
366
524
  queryKey: emporixKey("product-by-code", [code], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
367
525
  enabled: typeof code === "string" && code !== "",
368
526
  queryFn: () => client.products.getByCode(code, ctx),
@@ -373,7 +531,7 @@ function useProductSearch(query, params = {}, options = {}) {
373
531
  const { client } = useEmporix();
374
532
  const { ctx } = useReadAuth(options.auth);
375
533
  const { siteCode, language } = useReadSite();
376
- return reactQuery.useQuery({
534
+ return (0, import_react_query5.useQuery)({
377
535
  queryKey: emporixKey("product-search", [query, params], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
378
536
  enabled: typeof query === "string" && query.trim() !== "",
379
537
  queryFn: () => client.products.search(query, params, ctx),
@@ -384,7 +542,7 @@ function useProductNameSearch(term, params = {}, options = {}) {
384
542
  const { client } = useEmporix();
385
543
  const { ctx } = useReadAuth(options.auth);
386
544
  const { siteCode, language } = useReadSite();
387
- return reactQuery.useQuery({
545
+ return (0, import_react_query5.useQuery)({
388
546
  queryKey: emporixKey("product-name-search", [term, params], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
389
547
  enabled: typeof term === "string" && term.trim() !== "",
390
548
  queryFn: () => client.products.searchByName(term, params, ctx),
@@ -395,7 +553,7 @@ function useProductsByCodes(codes, options = {}) {
395
553
  const { client } = useEmporix();
396
554
  const { ctx } = useReadAuth(options.auth);
397
555
  const { siteCode, language } = useReadSite();
398
- return reactQuery.useQuery({
556
+ return (0, import_react_query5.useQuery)({
399
557
  queryKey: emporixKey("products-by-codes", [codes, options.chunkSize], {
400
558
  tenant: client.tenant,
401
559
  authKind: ctx.kind,
@@ -411,13 +569,17 @@ function useProductsByCodes(codes, options = {}) {
411
569
  staleTime: 3e4
412
570
  });
413
571
  }
572
+
573
+ // src/hooks/use-shopping-lists.ts
574
+ var import_react_query6 = require("@tanstack/react-query");
575
+ var import_emporix_sdk6 = require("@viu/emporix-sdk");
414
576
  var SHOPPING_LIST_STALE_TIME = 3e4;
415
577
  var INVALIDATE_KEY = ["emporix", "shopping-lists"];
416
578
  function useShoppingLists(opts = {}) {
417
579
  const { client } = useEmporix();
418
580
  const ctx = useCustomerOnlyCtx();
419
581
  const { siteCode, language } = useReadSite();
420
- return reactQuery.useQuery({
582
+ return (0, import_react_query6.useQuery)({
421
583
  queryKey: emporixKey("shopping-lists", [opts.name ?? null], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
422
584
  queryFn: () => client.shoppingLists.list(ctx, opts),
423
585
  staleTime: SHOPPING_LIST_STALE_TIME
@@ -426,8 +588,8 @@ function useShoppingLists(opts = {}) {
426
588
  function useCreateShoppingList() {
427
589
  const { client } = useEmporix();
428
590
  const ctx = useCustomerOnlyCtx();
429
- const qc = reactQuery.useQueryClient();
430
- return reactQuery.useMutation({
591
+ const qc = (0, import_react_query6.useQueryClient)();
592
+ return (0, import_react_query6.useMutation)({
431
593
  mutationFn: (draft) => client.shoppingLists.create(draft, ctx),
432
594
  onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY })
433
595
  });
@@ -435,8 +597,8 @@ function useCreateShoppingList() {
435
597
  function useDeleteShoppingList() {
436
598
  const { client } = useEmporix();
437
599
  const ctx = useCustomerOnlyCtx();
438
- const qc = reactQuery.useQueryClient();
439
- return reactQuery.useMutation({
600
+ const qc = (0, import_react_query6.useQueryClient)();
601
+ return (0, import_react_query6.useMutation)({
440
602
  mutationFn: ({ customerId, name }) => client.shoppingLists.delete(customerId, ctx, name !== void 0 ? { name } : {}),
441
603
  onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY })
442
604
  });
@@ -444,8 +606,8 @@ function useDeleteShoppingList() {
444
606
  function useAddToShoppingList() {
445
607
  const { client } = useEmporix();
446
608
  const ctx = useCustomerOnlyCtx();
447
- const qc = reactQuery.useQueryClient();
448
- return reactQuery.useMutation({
609
+ const qc = (0, import_react_query6.useQueryClient)();
610
+ return (0, import_react_query6.useMutation)({
449
611
  mutationFn: ({ customerId, listName, item }) => client.shoppingLists.addItem(customerId, listName, item, ctx),
450
612
  onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY })
451
613
  });
@@ -453,8 +615,8 @@ function useAddToShoppingList() {
453
615
  function useRemoveFromShoppingList() {
454
616
  const { client } = useEmporix();
455
617
  const ctx = useCustomerOnlyCtx();
456
- const qc = reactQuery.useQueryClient();
457
- return reactQuery.useMutation({
618
+ const qc = (0, import_react_query6.useQueryClient)();
619
+ return (0, import_react_query6.useMutation)({
458
620
  mutationFn: ({ customerId, listName, productId }) => client.shoppingLists.removeItem(customerId, listName, productId, ctx),
459
621
  onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY })
460
622
  });
@@ -462,18 +624,22 @@ function useRemoveFromShoppingList() {
462
624
  function useSetShoppingListItemQuantity() {
463
625
  const { client } = useEmporix();
464
626
  const ctx = useCustomerOnlyCtx();
465
- const qc = reactQuery.useQueryClient();
466
- return reactQuery.useMutation({
627
+ const qc = (0, import_react_query6.useQueryClient)();
628
+ return (0, import_react_query6.useMutation)({
467
629
  mutationFn: ({ customerId, listName, productId, quantity }) => client.shoppingLists.setItemQuantity(customerId, listName, productId, quantity, ctx),
468
630
  onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY })
469
631
  });
470
632
  }
633
+
634
+ // src/hooks/use-variant-children.ts
635
+ var import_react_query7 = require("@tanstack/react-query");
636
+ var import_emporix_sdk7 = require("@viu/emporix-sdk");
471
637
  var VARIANT_CHILDREN_STALE_TIME = 6e4;
472
638
  function useVariantChildren(parentVariantId, options = {}) {
473
639
  const { client } = useEmporix();
474
640
  const { ctx } = useReadAuth(options.auth);
475
641
  const { siteCode, language } = useReadSite();
476
- return reactQuery.useQuery({
642
+ return (0, import_react_query7.useQuery)({
477
643
  queryKey: emporixKey(
478
644
  "variant-children",
479
645
  [parentVariantId, { pageSize: options.pageSize }],
@@ -488,12 +654,16 @@ function useVariantChildren(parentVariantId, options = {}) {
488
654
  staleTime: VARIANT_CHILDREN_STALE_TIME
489
655
  });
490
656
  }
657
+
658
+ // src/hooks/use-categories.ts
659
+ var import_react_query8 = require("@tanstack/react-query");
660
+ var import_emporix_sdk8 = require("@viu/emporix-sdk");
491
661
  var CATEGORIES_STALE_TIME = 5 * 6e4;
492
662
  function useCategory(categoryId, options = {}) {
493
663
  const { client } = useEmporix();
494
664
  const { ctx } = useReadAuth(options.auth);
495
665
  const { siteCode, language } = useReadSite();
496
- return reactQuery.useQuery({
666
+ return (0, import_react_query8.useQuery)({
497
667
  queryKey: emporixKey("category", [categoryId], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
498
668
  queryFn: () => client.categories.get(categoryId, ctx),
499
669
  staleTime: CATEGORIES_STALE_TIME
@@ -503,7 +673,7 @@ function useSubcategories(categoryId, params = {}, options = {}) {
503
673
  const { client } = useEmporix();
504
674
  const { ctx } = useReadAuth(options.auth);
505
675
  const { siteCode, language } = useReadSite();
506
- return reactQuery.useQuery({
676
+ return (0, import_react_query8.useQuery)({
507
677
  queryKey: emporixKey("subcategories", [categoryId ?? null, params], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
508
678
  enabled: typeof categoryId === "string" && categoryId !== "",
509
679
  queryFn: () => client.categories.subcategories(categoryId, params, ctx),
@@ -514,7 +684,7 @@ function useCategories(params = {}, options = {}) {
514
684
  const { client } = useEmporix();
515
685
  const { ctx } = useReadAuth(options.auth);
516
686
  const { siteCode, language } = useReadSite();
517
- return reactQuery.useQuery({
687
+ return (0, import_react_query8.useQuery)({
518
688
  queryKey: emporixKey("categories", [params], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
519
689
  queryFn: () => client.categories.list(params, ctx),
520
690
  staleTime: CATEGORIES_STALE_TIME
@@ -537,7 +707,7 @@ function useCategoryTree(options = {}) {
537
707
  const { client } = useEmporix();
538
708
  const { ctx } = useReadAuth(options.auth);
539
709
  const { siteCode, language } = useReadSite();
540
- return reactQuery.useQuery({
710
+ return (0, import_react_query8.useQuery)({
541
711
  queryKey: emporixKey("category-tree", [], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
542
712
  queryFn: () => client.categories.tree(ctx),
543
713
  staleTime: CATEGORIES_STALE_TIME
@@ -547,7 +717,7 @@ function useProductsInCategory(categoryId, params = {}, options = {}) {
547
717
  const { client } = useEmporix();
548
718
  const { ctx } = useReadAuth(options.auth);
549
719
  const { siteCode, language } = useReadSite();
550
- return reactQuery.useQuery({
720
+ return (0, import_react_query8.useQuery)({
551
721
  queryKey: emporixKey("products-in-category", [categoryId, params], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
552
722
  enabled: typeof categoryId === "string" && categoryId !== "",
553
723
  queryFn: () => client.categories.productsIn(categoryId, params, ctx),
@@ -569,13 +739,19 @@ function useProductsInCategoryInfinite(categoryId, params = {}, options = {}) {
569
739
  staleTime: CATEGORIES_STALE_TIME
570
740
  });
571
741
  }
742
+
743
+ // src/hooks/use-cart.ts
744
+ var import_react6 = require("react");
745
+ var import_react_query9 = require("@tanstack/react-query");
746
+ var import_emporix_sdk9 = require("@viu/emporix-sdk");
572
747
  function useCart(cartId, options = {}) {
573
- const { client, storage } = useEmporix();
748
+ const { client } = useEmporix();
574
749
  const { ctx } = useReadAuth(options.auth);
575
750
  const { siteCode, language } = useReadSite();
576
751
  const { activeCompany } = useActiveCompany();
577
- const resolvedId = cartId ?? storage.getCartId() ?? void 0;
578
- return reactQuery.useQuery({
752
+ const storedCartId = useCartId();
753
+ const resolvedId = cartId ?? storedCartId ?? void 0;
754
+ return (0, import_react_query9.useQuery)({
579
755
  queryKey: emporixKey(
580
756
  "cart",
581
757
  [resolvedId ?? null, activeCompany?.id ?? null],
@@ -587,14 +763,14 @@ function useCart(cartId, options = {}) {
587
763
  }
588
764
  function useCartMutations(cartId) {
589
765
  const { client, storage } = useEmporix();
590
- const qc = reactQuery.useQueryClient();
766
+ const qc = (0, import_react_query9.useQueryClient)();
591
767
  const { ctx } = useReadAuth();
592
768
  const { siteCode, language } = useReadSite();
593
769
  const { activeCompany } = useActiveCompany();
594
770
  const resolveId = () => {
595
771
  const id = cartId ?? storage.getCartId();
596
772
  if (!id) {
597
- throw new emporixSdk.EmporixError(
773
+ throw new import_emporix_sdk9.EmporixError(
598
774
  "useCartMutations: no cartId available \u2014 pass one explicitly or call useActiveCart({ create: true }) first"
599
775
  );
600
776
  }
@@ -606,7 +782,7 @@ function useCartMutations(cartId) {
606
782
  { tenant: client.tenant, authKind: ctx.kind, siteCode, language }
607
783
  );
608
784
  function make(run, optimistic) {
609
- return reactQuery.useMutation({
785
+ return (0, import_react_query9.useMutation)({
610
786
  mutationFn: async (vars) => run(resolveId(), vars),
611
787
  onMutate: async (vars) => {
612
788
  const id = resolveId();
@@ -663,9 +839,9 @@ function useCartMutations(cartId) {
663
839
  }
664
840
  function useCreateCart() {
665
841
  const { client, storage } = useEmporix();
666
- const qc = reactQuery.useQueryClient();
842
+ const qc = (0, import_react_query9.useQueryClient)();
667
843
  const { ctx } = useReadAuth();
668
- return reactQuery.useMutation({
844
+ return (0, import_react_query9.useMutation)({
669
845
  mutationFn: (input) => client.carts.create(input, ctx),
670
846
  onSuccess: async (cart) => {
671
847
  if (cart.cartId) storage.setCartId(cart.cartId);
@@ -675,21 +851,13 @@ function useCreateCart() {
675
851
  }
676
852
  function useActiveCart(opts) {
677
853
  const { client, storage } = useEmporix();
678
- const qc = reactQuery.useQueryClient();
854
+ const qc = (0, import_react_query9.useQueryClient)();
679
855
  const { ctx } = useReadAuth(opts?.auth);
680
856
  const { siteCode: activeSite } = useReadSite();
681
857
  const { activeCompany } = useActiveCompany();
682
- const [cartId, setCartId] = react.useState(() => storage.getCartId());
858
+ const cartId = useCartId();
683
859
  const effectiveLegalEntityId = opts?.legalEntityId ?? activeCompany?.id;
684
- react.useEffect(() => {
685
- if (!storage.subscribeAll) return;
686
- return storage.subscribeAll((key) => {
687
- if (key !== "cartId") return;
688
- const next = storage.getCartId();
689
- setCartId((prev) => prev === next ? prev : next);
690
- });
691
- }, [storage]);
692
- react.useEffect(() => {
860
+ (0, import_react6.useEffect)(() => {
693
861
  if (cartId !== null) return;
694
862
  if (!opts?.create) return;
695
863
  const siteCode = activeSite ?? client.config?.credentials?.storefront?.context?.siteCode;
@@ -706,7 +874,6 @@ function useActiveCart(opts) {
706
874
  if (cancelled) return;
707
875
  if (cart?.id) {
708
876
  storage.setCartId(cart.id);
709
- setCartId(cart.id);
710
877
  }
711
878
  }).catch(() => {
712
879
  });
@@ -718,10 +885,14 @@ function useActiveCart(opts) {
718
885
  const data = cartId === null ? null : inner.data;
719
886
  return { ...inner, data };
720
887
  }
888
+
889
+ // src/hooks/use-checkout.ts
890
+ var import_react_query10 = require("@tanstack/react-query");
891
+ var import_emporix_sdk10 = require("@viu/emporix-sdk");
721
892
  var PAYMENT_MODES_STALE_TIME = 10 * 6e4;
722
893
  function customerOnlyCtx(token) {
723
894
  if (!token) throw new Error("usePaymentModes requires a logged-in customer token");
724
- return emporixSdk.auth.customer(token);
895
+ return import_emporix_sdk10.auth.customer(token);
725
896
  }
726
897
  function useCheckout() {
727
898
  const { client } = useEmporix();
@@ -732,13 +903,13 @@ function useCheckout() {
732
903
  if ("legalEntityId" in input) return input;
733
904
  return { ...input, legalEntityId: activeCompany.id };
734
905
  };
735
- const placeOrder = reactQuery.useMutation({
906
+ const placeOrder = (0, import_react_query10.useMutation)({
736
907
  mutationFn: (v) => client.checkout.placeOrder(withLE(v.input), ctx, {
737
908
  ...v.saasToken !== void 0 ? { saasToken: v.saasToken } : {},
738
909
  ...v.siteCode !== void 0 ? { siteCode: v.siteCode } : {}
739
910
  })
740
911
  });
741
- const placeOrderFromQuote = reactQuery.useMutation({
912
+ const placeOrderFromQuote = (0, import_react_query10.useMutation)({
742
913
  mutationFn: (v) => client.checkout.placeOrderFromQuote(withLE(v.input), ctx, {
743
914
  ...v.saasToken !== void 0 ? { saasToken: v.saasToken } : {},
744
915
  ...v.siteCode !== void 0 ? { siteCode: v.siteCode } : {}
@@ -747,11 +918,11 @@ function useCheckout() {
747
918
  return { placeOrder, placeOrderFromQuote };
748
919
  }
749
920
  function usePaymentModes(options = {}) {
750
- const { client, storage } = useEmporix();
751
- const token = storage.getCustomerToken();
921
+ const { client } = useEmporix();
922
+ const token = useCustomerToken();
752
923
  const { siteCode } = useReadSite();
753
924
  const { activeCompany } = useActiveCompany();
754
- return reactQuery.useQuery({
925
+ return (0, import_react_query10.useQuery)({
755
926
  queryKey: emporixKey(
756
927
  "payment-modes",
757
928
  [activeCompany?.id ?? null],
@@ -762,12 +933,16 @@ function usePaymentModes(options = {}) {
762
933
  staleTime: PAYMENT_MODES_STALE_TIME
763
934
  });
764
935
  }
936
+
937
+ // src/hooks/use-match-prices.ts
938
+ var import_react_query11 = require("@tanstack/react-query");
939
+ var import_emporix_sdk11 = require("@viu/emporix-sdk");
765
940
  var PRICES_STALE_TIME = 6e4;
766
941
  function useMatchPrices(input, options = {}) {
767
942
  const { client } = useEmporix();
768
943
  const { siteCode } = useReadSite();
769
- const ctx = options.customerToken ? emporixSdk.auth.customer(options.customerToken) : emporixSdk.auth.anonymous();
770
- return reactQuery.useQuery({
944
+ const ctx = options.customerToken ? import_emporix_sdk11.auth.customer(options.customerToken) : import_emporix_sdk11.auth.anonymous();
945
+ return (0, import_react_query11.useQuery)({
771
946
  queryKey: [
772
947
  "emporix",
773
948
  "match-prices",
@@ -778,12 +953,16 @@ function useMatchPrices(input, options = {}) {
778
953
  staleTime: PRICES_STALE_TIME
779
954
  });
780
955
  }
956
+
957
+ // src/hooks/use-match-prices-chunked.ts
958
+ var import_react_query12 = require("@tanstack/react-query");
959
+ var import_emporix_sdk12 = require("@viu/emporix-sdk");
781
960
  var PRICES_STALE_TIME2 = 6e4;
782
961
  function useMatchPricesChunked(input, options = {}) {
783
962
  const { client } = useEmporix();
784
963
  const { siteCode } = useReadSite();
785
- const ctx = options.customerToken ? emporixSdk.auth.customer(options.customerToken) : emporixSdk.auth.anonymous();
786
- return reactQuery.useQuery({
964
+ const ctx = options.customerToken ? import_emporix_sdk12.auth.customer(options.customerToken) : import_emporix_sdk12.auth.anonymous();
965
+ return (0, import_react_query12.useQuery)({
787
966
  queryKey: [
788
967
  "emporix",
789
968
  "match-prices-chunked",
@@ -815,16 +994,20 @@ function useProductMedia(productId) {
815
994
  const data = q.data?.productMedia;
816
995
  return { data, isLoading: q.isLoading, error: q.error };
817
996
  }
997
+
998
+ // src/hooks/use-my-segments.ts
999
+ var import_react_query13 = require("@tanstack/react-query");
1000
+ var import_emporix_sdk13 = require("@viu/emporix-sdk");
818
1001
  var SEGMENTS_STALE_TIME = 5 * 6e4;
819
1002
  function customerCtx(token) {
820
1003
  if (!token) throw new Error("requires a customer token in storage");
821
- return emporixSdk.auth.customer(token);
1004
+ return import_emporix_sdk13.auth.customer(token);
822
1005
  }
823
1006
  function useMySegments(query = {}) {
824
- const { client, storage } = useEmporix();
825
- const token = storage.getCustomerToken();
1007
+ const { client } = useEmporix();
1008
+ const token = useCustomerToken();
826
1009
  const { siteCode, language } = useReadSite();
827
- return reactQuery.useQuery({
1010
+ return (0, import_react_query13.useQuery)({
828
1011
  queryKey: ["emporix", "segment", "list", { tenant: client.tenant, query, siteCode, language }],
829
1012
  enabled: token !== null,
830
1013
  queryFn: () => client.segments.list(query, customerCtx(token)),
@@ -832,10 +1015,10 @@ function useMySegments(query = {}) {
832
1015
  });
833
1016
  }
834
1017
  function useMySegmentItems(query = {}) {
835
- const { client, storage } = useEmporix();
836
- const token = storage.getCustomerToken();
1018
+ const { client } = useEmporix();
1019
+ const token = useCustomerToken();
837
1020
  const { siteCode, language } = useReadSite();
838
- return reactQuery.useQuery({
1021
+ return (0, import_react_query13.useQuery)({
839
1022
  queryKey: ["emporix", "segment", "items", { tenant: client.tenant, query, siteCode, language }],
840
1023
  enabled: token !== null,
841
1024
  queryFn: () => client.segments.listItems(query, customerCtx(token)),
@@ -843,10 +1026,10 @@ function useMySegmentItems(query = {}) {
843
1026
  });
844
1027
  }
845
1028
  function useMySegmentCategoryTree(query = {}) {
846
- const { client, storage } = useEmporix();
847
- const token = storage.getCustomerToken();
1029
+ const { client } = useEmporix();
1030
+ const token = useCustomerToken();
848
1031
  const { siteCode, language } = useReadSite();
849
- return reactQuery.useQuery({
1032
+ return (0, import_react_query13.useQuery)({
850
1033
  queryKey: ["emporix", "segment", "categoryTree", { tenant: client.tenant, query, siteCode, language }],
851
1034
  enabled: token !== null,
852
1035
  queryFn: () => client.segments.getCategoryTree(query, customerCtx(token)),
@@ -854,10 +1037,10 @@ function useMySegmentCategoryTree(query = {}) {
854
1037
  });
855
1038
  }
856
1039
  function useMySegmentProducts(query = {}) {
857
- const { client, storage } = useEmporix();
858
- const token = storage.getCustomerToken();
1040
+ const { client } = useEmporix();
1041
+ const token = useCustomerToken();
859
1042
  const { siteCode, language } = useReadSite();
860
- return reactQuery.useQuery({
1043
+ return (0, import_react_query13.useQuery)({
861
1044
  queryKey: ["emporix", "segment", "myProducts", { tenant: client.tenant, query, siteCode, language }],
862
1045
  enabled: token !== null,
863
1046
  queryFn: () => client.segments.listMyProducts(query, customerCtx(token)),
@@ -865,8 +1048,8 @@ function useMySegmentProducts(query = {}) {
865
1048
  });
866
1049
  }
867
1050
  function useMySegmentProductsInfinite(query = {}) {
868
- const { client, storage } = useEmporix();
869
- const token = storage.getCustomerToken();
1051
+ const { client } = useEmporix();
1052
+ const token = useCustomerToken();
870
1053
  const { siteCode, language } = useReadSite();
871
1054
  return useEmporixInfinite({
872
1055
  queryKey: [
@@ -884,10 +1067,10 @@ function useMySegmentProductsInfinite(query = {}) {
884
1067
  });
885
1068
  }
886
1069
  function useMySegmentCategories(query = {}) {
887
- const { client, storage } = useEmporix();
888
- const token = storage.getCustomerToken();
1070
+ const { client } = useEmporix();
1071
+ const token = useCustomerToken();
889
1072
  const { siteCode, language } = useReadSite();
890
- return reactQuery.useQuery({
1073
+ return (0, import_react_query13.useQuery)({
891
1074
  queryKey: ["emporix", "segment", "myCategories", { tenant: client.tenant, query, siteCode, language }],
892
1075
  enabled: token !== null,
893
1076
  queryFn: () => client.segments.listMyCategories(query, customerCtx(token)),
@@ -895,8 +1078,8 @@ function useMySegmentCategories(query = {}) {
895
1078
  });
896
1079
  }
897
1080
  function useMySegmentCategoriesInfinite(query = {}) {
898
- const { client, storage } = useEmporix();
899
- const token = storage.getCustomerToken();
1081
+ const { client } = useEmporix();
1082
+ const token = useCustomerToken();
900
1083
  const { siteCode, language } = useReadSite();
901
1084
  return useEmporixInfinite({
902
1085
  queryKey: [
@@ -913,11 +1096,15 @@ function useMySegmentCategoriesInfinite(query = {}) {
913
1096
  staleTime: SEGMENTS_STALE_TIME
914
1097
  });
915
1098
  }
1099
+
1100
+ // src/hooks/use-customer-profile.ts
1101
+ var import_react_query14 = require("@tanstack/react-query");
1102
+ var import_emporix_sdk14 = require("@viu/emporix-sdk");
916
1103
  function useUpdateCustomer() {
917
1104
  const { client } = useEmporix();
918
1105
  const ctx = useCustomerOnlyCtx();
919
- const qc = reactQuery.useQueryClient();
920
- return reactQuery.useMutation({
1106
+ const qc = (0, import_react_query14.useQueryClient)();
1107
+ return (0, import_react_query14.useMutation)({
921
1108
  mutationFn: (patch) => client.customers.update(patch, ctx),
922
1109
  onSuccess: () => {
923
1110
  void qc.invalidateQueries({ queryKey: ["emporix", "customer", "me"] });
@@ -927,17 +1114,21 @@ function useUpdateCustomer() {
927
1114
  function useChangePassword() {
928
1115
  const { client } = useEmporix();
929
1116
  const ctx = useCustomerOnlyCtx();
930
- return reactQuery.useMutation({
1117
+ return (0, import_react_query14.useMutation)({
931
1118
  mutationFn: (input) => client.customers.changePassword(input, ctx)
932
1119
  });
933
1120
  }
1121
+
1122
+ // src/hooks/use-customer-addresses.ts
1123
+ var import_react_query15 = require("@tanstack/react-query");
1124
+ var import_emporix_sdk15 = require("@viu/emporix-sdk");
934
1125
  var ADDRESSES_KEY = ["emporix", "customer", "addresses"];
935
1126
  function useCustomerAddresses(options = {}) {
936
- const { client, storage } = useEmporix();
937
- const token = storage.getCustomerToken();
1127
+ const { client } = useEmporix();
1128
+ const token = useCustomerToken();
938
1129
  const { activeCompany } = useActiveCompany();
939
- const ctx = options.auth ?? (token ? emporixSdk.auth.customer(token) : null);
940
- return reactQuery.useQuery({
1130
+ const ctx = options.auth ?? (token ? import_emporix_sdk15.auth.customer(token) : null);
1131
+ return (0, import_react_query15.useQuery)({
941
1132
  queryKey: [
942
1133
  ...ADDRESSES_KEY,
943
1134
  { tenant: client.tenant, hasToken: token !== null, legalEntityId: activeCompany?.id ?? null }
@@ -949,39 +1140,49 @@ function useCustomerAddresses(options = {}) {
949
1140
  function useAddressMutations() {
950
1141
  const { client } = useEmporix();
951
1142
  const ctx = useCustomerOnlyCtx();
952
- const qc = reactQuery.useQueryClient();
1143
+ const qc = (0, import_react_query15.useQueryClient)();
953
1144
  const invalidate = () => {
954
1145
  void qc.invalidateQueries({ queryKey: ADDRESSES_KEY });
955
1146
  };
956
1147
  return {
957
- add: reactQuery.useMutation({
1148
+ add: (0, import_react_query15.useMutation)({
958
1149
  mutationFn: (input) => client.customers.addresses.add(input, ctx),
959
1150
  onSuccess: invalidate
960
1151
  }),
961
- update: reactQuery.useMutation({
1152
+ update: (0, import_react_query15.useMutation)({
962
1153
  mutationFn: ({ id, patch }) => client.customers.addresses.update(id, patch, ctx),
963
1154
  onSuccess: invalidate
964
1155
  }),
965
- remove: reactQuery.useMutation({
1156
+ remove: (0, import_react_query15.useMutation)({
966
1157
  mutationFn: ({ id }) => client.customers.addresses.remove(id, ctx),
967
1158
  onSuccess: invalidate
968
1159
  })
969
1160
  };
970
1161
  }
1162
+
1163
+ // src/hooks/use-password-reset.ts
1164
+ var import_react_query16 = require("@tanstack/react-query");
1165
+ var import_emporix_sdk16 = require("@viu/emporix-sdk");
971
1166
  function usePasswordReset() {
972
1167
  const { client } = useEmporix();
973
- const anonCtx = emporixSdk.auth.anonymous();
1168
+ const anonCtx = import_emporix_sdk16.auth.anonymous();
974
1169
  return {
975
- request: reactQuery.useMutation({
1170
+ request: (0, import_react_query16.useMutation)({
976
1171
  mutationFn: (input) => client.customers.requestPasswordReset(input, anonCtx)
977
1172
  }),
978
- confirm: reactQuery.useMutation({
1173
+ confirm: (0, import_react_query16.useMutation)({
979
1174
  mutationFn: (input) => client.customers.confirmPasswordReset(input, anonCtx)
980
1175
  })
981
1176
  };
982
1177
  }
1178
+
1179
+ // src/hooks/use-sites.ts
1180
+ var import_react_query17 = require("@tanstack/react-query");
1181
+
1182
+ // src/hooks/use-site-context.ts
1183
+ var import_react7 = require("react");
983
1184
  function useSiteContext() {
984
- const ctx = react.useContext(EmporixSiteContext);
1185
+ const ctx = (0, import_react7.useContext)(EmporixSiteContext);
985
1186
  if (!ctx) {
986
1187
  throw new Error("useSiteContext must be used within an EmporixProvider");
987
1188
  }
@@ -993,7 +1194,7 @@ var SITES_STALE_TIME = 10 * 6e4;
993
1194
  function useSites(options = {}) {
994
1195
  const { client } = useEmporix();
995
1196
  const { ctx } = useReadAuth(options.auth);
996
- return reactQuery.useQuery({
1197
+ return (0, import_react_query17.useQuery)({
997
1198
  queryKey: emporixKey("sites", [], { tenant: client.tenant, authKind: ctx.kind }),
998
1199
  queryFn: () => client.sites.list(ctx),
999
1200
  staleTime: SITES_STALE_TIME
@@ -1002,7 +1203,7 @@ function useSites(options = {}) {
1002
1203
  function useDefaultSite(options = {}) {
1003
1204
  const { client } = useEmporix();
1004
1205
  const { ctx } = useReadAuth(options.auth);
1005
- return reactQuery.useQuery({
1206
+ return (0, import_react_query17.useQuery)({
1006
1207
  queryKey: emporixKey("site-default", [], { tenant: client.tenant, authKind: ctx.kind }),
1007
1208
  queryFn: () => client.sites.current(ctx),
1008
1209
  staleTime: SITES_STALE_TIME
@@ -1013,79 +1214,103 @@ function useActiveSite(options = {}) {
1013
1214
  const { data: sites } = useSites(options);
1014
1215
  return siteCode ? sites?.find((s) => s.code === siteCode) : void 0;
1015
1216
  }
1217
+
1218
+ // src/hooks/use-my-companies.ts
1219
+ var import_react_query18 = require("@tanstack/react-query");
1220
+ var import_emporix_sdk17 = require("@viu/emporix-sdk");
1016
1221
  function useMyCompanies() {
1017
- const { client, storage } = useEmporix();
1018
- const token = storage.getCustomerToken();
1019
- return reactQuery.useQuery({
1222
+ const { client } = useEmporix();
1223
+ const token = useCustomerToken();
1224
+ return (0, import_react_query18.useQuery)({
1020
1225
  queryKey: emporixKey("companies", ["mine"], {
1021
1226
  tenant: client.tenant,
1022
1227
  authKind: token ? "customer" : "anonymous"
1023
1228
  }),
1024
1229
  enabled: token !== null,
1025
- queryFn: () => client.companies.listMine(emporixSdk.auth.customer(token))
1230
+ queryFn: () => client.companies.listMine(import_emporix_sdk17.auth.customer(token))
1026
1231
  });
1027
1232
  }
1233
+
1234
+ // src/hooks/use-company.ts
1235
+ var import_react_query19 = require("@tanstack/react-query");
1236
+ var import_emporix_sdk18 = require("@viu/emporix-sdk");
1028
1237
  function useCompany(legalEntityId) {
1029
- const { client, storage } = useEmporix();
1030
- const token = storage.getCustomerToken();
1031
- return reactQuery.useQuery({
1238
+ const { client } = useEmporix();
1239
+ const token = useCustomerToken();
1240
+ return (0, import_react_query19.useQuery)({
1032
1241
  queryKey: emporixKey("companies", [legalEntityId ?? null], {
1033
1242
  tenant: client.tenant,
1034
1243
  authKind: token ? "customer" : "anonymous"
1035
1244
  }),
1036
1245
  enabled: token !== null && legalEntityId !== void 0,
1037
- queryFn: () => client.companies.get(legalEntityId, emporixSdk.auth.customer(token))
1246
+ queryFn: () => client.companies.get(legalEntityId, import_emporix_sdk18.auth.customer(token))
1038
1247
  });
1039
1248
  }
1249
+
1250
+ // src/hooks/use-company-contacts.ts
1251
+ var import_react_query20 = require("@tanstack/react-query");
1252
+ var import_emporix_sdk19 = require("@viu/emporix-sdk");
1040
1253
  function useCompanyContacts(legalEntityId) {
1041
1254
  const { client, storage } = useEmporix();
1042
1255
  const token = storage.getCustomerToken();
1043
- return reactQuery.useQuery({
1256
+ return (0, import_react_query20.useQuery)({
1044
1257
  queryKey: emporixKey("companies", ["contacts", legalEntityId ?? null], {
1045
1258
  tenant: client.tenant,
1046
1259
  authKind: token ? "customer" : "anonymous"
1047
1260
  }),
1048
1261
  enabled: token !== null && legalEntityId !== void 0,
1049
- queryFn: () => client.contacts.listForCompany(legalEntityId, emporixSdk.auth.customer(token))
1262
+ queryFn: () => client.contacts.listForCompany(legalEntityId, import_emporix_sdk19.auth.customer(token))
1050
1263
  });
1051
1264
  }
1265
+
1266
+ // src/hooks/use-company-locations.ts
1267
+ var import_react_query21 = require("@tanstack/react-query");
1268
+ var import_emporix_sdk20 = require("@viu/emporix-sdk");
1052
1269
  function useCompanyLocations(legalEntityId) {
1053
- const { client, storage } = useEmporix();
1054
- const token = storage.getCustomerToken();
1055
- return reactQuery.useQuery({
1270
+ const { client } = useEmporix();
1271
+ const token = useCustomerToken();
1272
+ return (0, import_react_query21.useQuery)({
1056
1273
  queryKey: emporixKey("companies", ["locations", legalEntityId ?? null], {
1057
1274
  tenant: client.tenant,
1058
1275
  authKind: token ? "customer" : "anonymous"
1059
1276
  }),
1060
1277
  enabled: token !== null && legalEntityId !== void 0,
1061
- queryFn: () => client.locations.listForCompany(legalEntityId, emporixSdk.auth.customer(token))
1278
+ queryFn: () => client.locations.listForCompany(legalEntityId, import_emporix_sdk20.auth.customer(token))
1062
1279
  });
1063
1280
  }
1281
+
1282
+ // src/hooks/use-company-groups.ts
1283
+ var import_react_query22 = require("@tanstack/react-query");
1284
+ var import_emporix_sdk21 = require("@viu/emporix-sdk");
1064
1285
  function useCompanyGroups(legalEntityId) {
1065
- const { client, storage } = useEmporix();
1066
- const token = storage.getCustomerToken();
1067
- return reactQuery.useQuery({
1286
+ const { client } = useEmporix();
1287
+ const token = useCustomerToken();
1288
+ return (0, import_react_query22.useQuery)({
1068
1289
  queryKey: emporixKey("companies", ["groups", legalEntityId ?? null], {
1069
1290
  tenant: client.tenant,
1070
1291
  authKind: token ? "customer" : "anonymous"
1071
1292
  }),
1072
1293
  enabled: token !== null && legalEntityId !== void 0,
1073
- queryFn: () => client.customerGroups.listForCompany(legalEntityId, emporixSdk.auth.customer(token))
1294
+ queryFn: () => client.customerGroups.listForCompany(legalEntityId, import_emporix_sdk21.auth.customer(token))
1074
1295
  });
1075
1296
  }
1297
+
1298
+ // src/hooks/use-company-mutations.ts
1299
+ var import_react_query23 = require("@tanstack/react-query");
1300
+ var import_emporix_sdk22 = require("@viu/emporix-sdk");
1076
1301
  function useCustomerAuthResolver() {
1077
1302
  const { storage } = useEmporix();
1078
1303
  return () => {
1079
1304
  const token = storage.getCustomerToken();
1080
1305
  if (!token) throw new Error("Mutation requires a logged-in customer token");
1081
- return emporixSdk.auth.customer(token);
1306
+ return import_emporix_sdk22.auth.customer(token);
1082
1307
  };
1083
1308
  }
1084
1309
  function useCreateCompany() {
1085
1310
  const { client } = useEmporix();
1086
1311
  const resolveAuth = useCustomerAuthResolver();
1087
- const qc = reactQuery.useQueryClient();
1088
- return reactQuery.useMutation({
1312
+ const qc = (0, import_react_query23.useQueryClient)();
1313
+ return (0, import_react_query23.useMutation)({
1089
1314
  mutationFn: (input) => client.companies.create(input, resolveAuth()),
1090
1315
  onSuccess: () => qc.invalidateQueries({ queryKey: ["emporix", "companies", "mine"] })
1091
1316
  });
@@ -1093,8 +1318,8 @@ function useCreateCompany() {
1093
1318
  function useUpdateCompany() {
1094
1319
  const { client } = useEmporix();
1095
1320
  const resolveAuth = useCustomerAuthResolver();
1096
- const qc = reactQuery.useQueryClient();
1097
- return reactQuery.useMutation({
1321
+ const qc = (0, import_react_query23.useQueryClient)();
1322
+ return (0, import_react_query23.useMutation)({
1098
1323
  mutationFn: ({ id, patch }) => client.companies.update(id, patch, resolveAuth()),
1099
1324
  onSuccess: () => qc.invalidateQueries({ queryKey: ["emporix", "companies"] })
1100
1325
  });
@@ -1102,8 +1327,8 @@ function useUpdateCompany() {
1102
1327
  function useDeleteCompany() {
1103
1328
  const { client } = useEmporix();
1104
1329
  const resolveAuth = useCustomerAuthResolver();
1105
- const qc = reactQuery.useQueryClient();
1106
- return reactQuery.useMutation({
1330
+ const qc = (0, import_react_query23.useQueryClient)();
1331
+ return (0, import_react_query23.useMutation)({
1107
1332
  mutationFn: (id) => client.companies.delete(id, resolveAuth()),
1108
1333
  onSuccess: () => qc.invalidateQueries({ queryKey: ["emporix", "companies"] })
1109
1334
  });
@@ -1111,8 +1336,8 @@ function useDeleteCompany() {
1111
1336
  function useAssignContact() {
1112
1337
  const { client } = useEmporix();
1113
1338
  const resolveAuth = useCustomerAuthResolver();
1114
- const qc = reactQuery.useQueryClient();
1115
- return reactQuery.useMutation({
1339
+ const qc = (0, import_react_query23.useQueryClient)();
1340
+ return (0, import_react_query23.useMutation)({
1116
1341
  mutationFn: (input) => client.contacts.assign(input, resolveAuth()),
1117
1342
  onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("contacts") })
1118
1343
  });
@@ -1120,8 +1345,8 @@ function useAssignContact() {
1120
1345
  function useUpdateContactAssignment() {
1121
1346
  const { client } = useEmporix();
1122
1347
  const resolveAuth = useCustomerAuthResolver();
1123
- const qc = reactQuery.useQueryClient();
1124
- return reactQuery.useMutation({
1348
+ const qc = (0, import_react_query23.useQueryClient)();
1349
+ return (0, import_react_query23.useMutation)({
1125
1350
  mutationFn: ({ id, patch }) => client.contacts.update(id, patch, resolveAuth()),
1126
1351
  onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("contacts") })
1127
1352
  });
@@ -1129,8 +1354,8 @@ function useUpdateContactAssignment() {
1129
1354
  function useUnassignContact() {
1130
1355
  const { client } = useEmporix();
1131
1356
  const resolveAuth = useCustomerAuthResolver();
1132
- const qc = reactQuery.useQueryClient();
1133
- return reactQuery.useMutation({
1357
+ const qc = (0, import_react_query23.useQueryClient)();
1358
+ return (0, import_react_query23.useMutation)({
1134
1359
  mutationFn: (id) => client.contacts.unassign(id, resolveAuth()),
1135
1360
  onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("contacts") })
1136
1361
  });
@@ -1138,8 +1363,8 @@ function useUnassignContact() {
1138
1363
  function useCreateLocation() {
1139
1364
  const { client } = useEmporix();
1140
1365
  const resolveAuth = useCustomerAuthResolver();
1141
- const qc = reactQuery.useQueryClient();
1142
- return reactQuery.useMutation({
1366
+ const qc = (0, import_react_query23.useQueryClient)();
1367
+ return (0, import_react_query23.useMutation)({
1143
1368
  mutationFn: (input) => client.locations.create(input, resolveAuth()),
1144
1369
  onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("locations") })
1145
1370
  });
@@ -1147,8 +1372,8 @@ function useCreateLocation() {
1147
1372
  function useUpdateLocation() {
1148
1373
  const { client } = useEmporix();
1149
1374
  const resolveAuth = useCustomerAuthResolver();
1150
- const qc = reactQuery.useQueryClient();
1151
- return reactQuery.useMutation({
1375
+ const qc = (0, import_react_query23.useQueryClient)();
1376
+ return (0, import_react_query23.useMutation)({
1152
1377
  mutationFn: ({ id, patch }) => client.locations.update(id, patch, resolveAuth()),
1153
1378
  onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("locations") })
1154
1379
  });
@@ -1156,8 +1381,8 @@ function useUpdateLocation() {
1156
1381
  function useDeleteLocation() {
1157
1382
  const { client } = useEmporix();
1158
1383
  const resolveAuth = useCustomerAuthResolver();
1159
- const qc = reactQuery.useQueryClient();
1160
- return reactQuery.useMutation({
1384
+ const qc = (0, import_react_query23.useQueryClient)();
1385
+ return (0, import_react_query23.useMutation)({
1161
1386
  mutationFn: (id) => client.locations.delete(id, resolveAuth()),
1162
1387
  onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("locations") })
1163
1388
  });
@@ -1165,8 +1390,8 @@ function useDeleteLocation() {
1165
1390
  function useAddGroupMember() {
1166
1391
  const { client } = useEmporix();
1167
1392
  const resolveAuth = useCustomerAuthResolver();
1168
- const qc = reactQuery.useQueryClient();
1169
- return reactQuery.useMutation({
1393
+ const qc = (0, import_react_query23.useQueryClient)();
1394
+ return (0, import_react_query23.useMutation)({
1170
1395
  mutationFn: ({ groupId, member }) => client.customerGroups.addMember(groupId, member, resolveAuth()),
1171
1396
  onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("groups") })
1172
1397
  });
@@ -1174,19 +1399,22 @@ function useAddGroupMember() {
1174
1399
  function useRemoveGroupMember() {
1175
1400
  const { client } = useEmporix();
1176
1401
  const resolveAuth = useCustomerAuthResolver();
1177
- const qc = reactQuery.useQueryClient();
1178
- return reactQuery.useMutation({
1402
+ const qc = (0, import_react_query23.useQueryClient)();
1403
+ return (0, import_react_query23.useMutation)({
1179
1404
  mutationFn: ({ groupId, userId }) => client.customerGroups.removeMember(groupId, userId, resolveAuth()),
1180
1405
  onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("groups") })
1181
1406
  });
1182
1407
  }
1408
+
1409
+ // src/hooks/use-company-switcher.ts
1410
+ var import_react8 = require("react");
1183
1411
  function useCompanySwitcher() {
1184
1412
  const ctx = useActiveCompany();
1185
- const switchFn = react.useCallback(
1413
+ const switchFn = (0, import_react8.useCallback)(
1186
1414
  (legalEntityId) => ctx.setActiveCompany(legalEntityId),
1187
1415
  [ctx]
1188
1416
  );
1189
- const clearFn = react.useCallback(() => ctx.setActiveCompany(null), [ctx]);
1417
+ const clearFn = (0, import_react8.useCallback)(() => ctx.setActiveCompany(null), [ctx]);
1190
1418
  return {
1191
1419
  companies: ctx.myCompanies,
1192
1420
  active: ctx.activeCompany,
@@ -1195,23 +1423,27 @@ function useCompanySwitcher() {
1195
1423
  clear: clearFn
1196
1424
  };
1197
1425
  }
1426
+
1427
+ // src/hooks/use-cloud-functions.ts
1428
+ var import_react_query24 = require("@tanstack/react-query");
1429
+ var import_emporix_sdk23 = require("@viu/emporix-sdk");
1198
1430
  function useInvokeCloudFunction() {
1199
1431
  const { client, storage } = useEmporix();
1200
- return reactQuery.useMutation({
1432
+ return (0, import_react_query24.useMutation)({
1201
1433
  mutationFn: (vars) => {
1202
1434
  const { functionId, auth: authOverride, ...options } = vars;
1203
1435
  const token = storage.getCustomerToken();
1204
- const authCtx = authOverride ?? (token ? emporixSdk.auth.customer(token) : emporixSdk.auth.anonymous());
1436
+ const authCtx = authOverride ?? (token ? import_emporix_sdk23.auth.customer(token) : import_emporix_sdk23.auth.anonymous());
1205
1437
  return client.cloudFunctions.invoke(functionId, options, authCtx);
1206
1438
  }
1207
1439
  });
1208
1440
  }
1209
1441
  function useCloudFunction(functionId, options, queryOptions) {
1210
- const { client, storage } = useEmporix();
1211
- const token = storage.getCustomerToken();
1442
+ const { client } = useEmporix();
1443
+ const token = useCustomerToken();
1212
1444
  const { auth: authOverride, ...invokeOptions } = options ?? {};
1213
- const authCtx = authOverride ?? (token ? emporixSdk.auth.customer(token) : emporixSdk.auth.anonymous());
1214
- return reactQuery.useQuery({
1445
+ const authCtx = authOverride ?? (token ? import_emporix_sdk23.auth.customer(token) : import_emporix_sdk23.auth.anonymous());
1446
+ return (0, import_react_query24.useQuery)({
1215
1447
  queryKey: emporixKey(
1216
1448
  "cloud-function",
1217
1449
  [functionId ?? null, invokeOptions.path ?? null, invokeOptions.query ?? null],
@@ -1226,20 +1458,24 @@ function useCloudFunction(functionId, options, queryOptions) {
1226
1458
  )
1227
1459
  });
1228
1460
  }
1461
+
1462
+ // src/hooks/use-my-orders.ts
1463
+ var import_react_query25 = require("@tanstack/react-query");
1464
+ var import_emporix_sdk24 = require("@viu/emporix-sdk");
1229
1465
  function useMyOrders(options = {}) {
1230
- const { client, storage } = useEmporix();
1466
+ const { client } = useEmporix();
1231
1467
  const { activeCompany } = useActiveCompany();
1232
1468
  const { siteCode, language } = useReadSite();
1233
- const token = storage.getCustomerToken();
1469
+ const token = useCustomerToken();
1234
1470
  const effectiveLE = options.legalEntityId === null ? void 0 : options.legalEntityId ?? activeCompany?.id;
1235
- return reactQuery.useQuery({
1471
+ return (0, import_react_query25.useQuery)({
1236
1472
  queryKey: emporixKey(
1237
1473
  "orders",
1238
1474
  ["mine", effectiveLE ?? null, options.status ?? null, options.pageNumber ?? 1, options.pageSize ?? null],
1239
1475
  { tenant: client.tenant, authKind: token ? "customer" : "anonymous", siteCode, language }
1240
1476
  ),
1241
1477
  enabled: token !== null,
1242
- queryFn: () => client.orders.listMine(emporixSdk.auth.customer(token), {
1478
+ queryFn: () => client.orders.listMine(import_emporix_sdk24.auth.customer(token), {
1243
1479
  ...options.pageNumber !== void 0 ? { pageNumber: options.pageNumber } : {},
1244
1480
  ...options.pageSize !== void 0 ? { pageSize: options.pageSize } : {},
1245
1481
  ...options.status !== void 0 ? { status: options.status } : {},
@@ -1249,11 +1485,14 @@ function useMyOrders(options = {}) {
1249
1485
  })
1250
1486
  });
1251
1487
  }
1488
+
1489
+ // src/hooks/use-my-orders-infinite.ts
1490
+ var import_emporix_sdk25 = require("@viu/emporix-sdk");
1252
1491
  function useMyOrdersInfinite(options = {}) {
1253
- const { client, storage } = useEmporix();
1492
+ const { client } = useEmporix();
1254
1493
  const { activeCompany } = useActiveCompany();
1255
1494
  const { siteCode, language } = useReadSite();
1256
- const token = storage.getCustomerToken();
1495
+ const token = useCustomerToken();
1257
1496
  const effectiveLE = options.legalEntityId === null ? void 0 : options.legalEntityId ?? activeCompany?.id;
1258
1497
  return useEmporixInfinite({
1259
1498
  queryKey: emporixKey(
@@ -1262,7 +1501,7 @@ function useMyOrdersInfinite(options = {}) {
1262
1501
  { tenant: client.tenant, authKind: token ? "customer" : "anonymous", siteCode, language }
1263
1502
  ),
1264
1503
  enabled: token !== null,
1265
- fetchPage: (pageNumber) => client.orders.listMine(emporixSdk.auth.customer(token), {
1504
+ fetchPage: (pageNumber) => client.orders.listMine(import_emporix_sdk25.auth.customer(token), {
1266
1505
  pageNumber,
1267
1506
  ...options.pageSize !== void 0 ? { pageSize: options.pageSize } : {},
1268
1507
  ...options.status !== void 0 ? { status: options.status } : {},
@@ -1272,11 +1511,15 @@ function useMyOrdersInfinite(options = {}) {
1272
1511
  })
1273
1512
  });
1274
1513
  }
1514
+
1515
+ // src/hooks/use-order.ts
1516
+ var import_react_query26 = require("@tanstack/react-query");
1517
+ var import_emporix_sdk26 = require("@viu/emporix-sdk");
1275
1518
  function useOrder(orderId, options = {}) {
1276
- const { client, storage } = useEmporix();
1277
- const token = storage.getCustomerToken();
1519
+ const { client } = useEmporix();
1520
+ const token = useCustomerToken();
1278
1521
  const { language } = useReadSite();
1279
- return reactQuery.useQuery({
1522
+ return (0, import_react_query26.useQuery)({
1280
1523
  queryKey: emporixKey("orders", [orderId ?? null], {
1281
1524
  tenant: client.tenant,
1282
1525
  authKind: token ? "customer" : "anonymous",
@@ -1285,15 +1528,19 @@ function useOrder(orderId, options = {}) {
1285
1528
  enabled: token !== null && orderId !== void 0,
1286
1529
  queryFn: () => client.orders.get(
1287
1530
  orderId,
1288
- emporixSdk.auth.customer(token),
1531
+ import_emporix_sdk26.auth.customer(token),
1289
1532
  options.saasToken ? { saasToken: options.saasToken } : {}
1290
1533
  )
1291
1534
  });
1292
1535
  }
1536
+
1537
+ // src/hooks/use-cancel-order.ts
1538
+ var import_react_query27 = require("@tanstack/react-query");
1539
+ var import_emporix_sdk27 = require("@viu/emporix-sdk");
1293
1540
  function useCancelOrder() {
1294
1541
  const { client, storage } = useEmporix();
1295
- const qc = reactQuery.useQueryClient();
1296
- return reactQuery.useMutation({
1542
+ const qc = (0, import_react_query27.useQueryClient)();
1543
+ return (0, import_react_query27.useMutation)({
1297
1544
  mutationKey: ["emporix", "orders", "cancel"],
1298
1545
  mutationFn: async (input) => {
1299
1546
  const token = storage.getCustomerToken();
@@ -1301,7 +1548,7 @@ function useCancelOrder() {
1301
1548
  const { orderId, saasToken } = typeof input === "string" ? { orderId: input, saasToken: void 0 } : input;
1302
1549
  await client.orders.cancel(
1303
1550
  orderId,
1304
- emporixSdk.auth.customer(token),
1551
+ import_emporix_sdk27.auth.customer(token),
1305
1552
  saasToken ? { saasToken } : {}
1306
1553
  );
1307
1554
  },
@@ -1310,10 +1557,14 @@ function useCancelOrder() {
1310
1557
  })
1311
1558
  });
1312
1559
  }
1560
+
1561
+ // src/hooks/use-order-transition.ts
1562
+ var import_react_query28 = require("@tanstack/react-query");
1563
+ var import_emporix_sdk28 = require("@viu/emporix-sdk");
1313
1564
  function useOrderTransition() {
1314
1565
  const { client, storage } = useEmporix();
1315
- const qc = reactQuery.useQueryClient();
1316
- return reactQuery.useMutation({
1566
+ const qc = (0, import_react_query28.useQueryClient)();
1567
+ return (0, import_react_query28.useMutation)({
1317
1568
  mutationKey: ["emporix", "orders", "transition"],
1318
1569
  mutationFn: async ({ orderId, status, comment, saasToken }) => {
1319
1570
  const token = storage.getCustomerToken();
@@ -1321,7 +1572,7 @@ function useOrderTransition() {
1321
1572
  await client.orders.transition(
1322
1573
  orderId,
1323
1574
  status,
1324
- emporixSdk.auth.customer(token),
1575
+ import_emporix_sdk28.auth.customer(token),
1325
1576
  {
1326
1577
  ...comment !== void 0 ? { comment } : {},
1327
1578
  ...saasToken !== void 0 ? { saasToken } : {}
@@ -1333,15 +1584,19 @@ function useOrderTransition() {
1333
1584
  })
1334
1585
  });
1335
1586
  }
1587
+
1588
+ // src/hooks/use-reorder.ts
1589
+ var import_react_query29 = require("@tanstack/react-query");
1590
+ var import_emporix_sdk29 = require("@viu/emporix-sdk");
1336
1591
  function useReorder() {
1337
1592
  const { client, storage } = useEmporix();
1338
- const qc = reactQuery.useQueryClient();
1339
- return reactQuery.useMutation({
1593
+ const qc = (0, import_react_query29.useQueryClient)();
1594
+ return (0, import_react_query29.useMutation)({
1340
1595
  mutationKey: ["emporix", "orders", "reorder"],
1341
1596
  mutationFn: async ({ orderId, saasToken }) => {
1342
1597
  const token = storage.getCustomerToken();
1343
1598
  if (!token) throw new Error("useReorder: requires a logged-in customer");
1344
- const ctx = emporixSdk.auth.customer(token);
1599
+ const ctx = import_emporix_sdk29.auth.customer(token);
1345
1600
  const order = await qc.fetchQuery({
1346
1601
  queryKey: emporixKey("orders", [orderId], { tenant: client.tenant, authKind: ctx.kind }),
1347
1602
  queryFn: () => client.orders.get(orderId, ctx, saasToken ? { saasToken } : {})
@@ -1386,10 +1641,14 @@ function useReorder() {
1386
1641
  }
1387
1642
  });
1388
1643
  }
1644
+
1645
+ // src/hooks/use-sales-order.ts
1646
+ var import_react_query30 = require("@tanstack/react-query");
1647
+ var import_emporix_sdk30 = require("@viu/emporix-sdk");
1389
1648
  function useSalesOrder(orderId, authCtx) {
1390
1649
  const { client } = useEmporix();
1391
1650
  const { language } = useReadSite();
1392
- return reactQuery.useQuery({
1651
+ return (0, import_react_query30.useQuery)({
1393
1652
  queryKey: emporixKey("salesorders", [orderId ?? null], {
1394
1653
  tenant: client.tenant,
1395
1654
  authKind: authCtx?.kind ?? "anonymous",
@@ -1399,10 +1658,14 @@ function useSalesOrder(orderId, authCtx) {
1399
1658
  queryFn: () => client.salesOrders.get(orderId, authCtx)
1400
1659
  });
1401
1660
  }
1661
+
1662
+ // src/hooks/use-update-sales-order.ts
1663
+ var import_react_query31 = require("@tanstack/react-query");
1664
+ var import_emporix_sdk31 = require("@viu/emporix-sdk");
1402
1665
  function useUpdateSalesOrder() {
1403
1666
  const { client } = useEmporix();
1404
- const qc = reactQuery.useQueryClient();
1405
- return reactQuery.useMutation({
1667
+ const qc = (0, import_react_query31.useQueryClient)();
1668
+ return (0, import_react_query31.useMutation)({
1406
1669
  mutationKey: ["emporix", "salesorders", "update"],
1407
1670
  mutationFn: async ({ orderId, patch, auth: auth26, recalculate }) => {
1408
1671
  if (!auth26) throw new Error("useUpdateSalesOrder: requires an auth context");
@@ -1420,11 +1683,15 @@ function useUpdateSalesOrder() {
1420
1683
  }
1421
1684
  });
1422
1685
  }
1686
+
1687
+ // src/hooks/use-availability.ts
1688
+ var import_react_query32 = require("@tanstack/react-query");
1689
+ var import_emporix_sdk32 = require("@viu/emporix-sdk");
1423
1690
  var AVAILABILITY_STALE_TIME = 3e4;
1424
1691
  function useAvailability(productId, siteCode, options = {}) {
1425
1692
  const { client } = useEmporix();
1426
- const ctx = options.customerToken ? emporixSdk.auth.customer(options.customerToken) : emporixSdk.auth.anonymous();
1427
- return reactQuery.useQuery({
1693
+ const ctx = options.customerToken ? import_emporix_sdk32.auth.customer(options.customerToken) : import_emporix_sdk32.auth.anonymous();
1694
+ return (0, import_react_query32.useQuery)({
1428
1695
  queryKey: [
1429
1696
  "emporix",
1430
1697
  "availability",
@@ -1443,11 +1710,15 @@ function useAvailability(productId, siteCode, options = {}) {
1443
1710
  staleTime: AVAILABILITY_STALE_TIME
1444
1711
  });
1445
1712
  }
1713
+
1714
+ // src/hooks/use-availabilities.ts
1715
+ var import_react_query33 = require("@tanstack/react-query");
1716
+ var import_emporix_sdk33 = require("@viu/emporix-sdk");
1446
1717
  var AVAILABILITY_STALE_TIME2 = 3e4;
1447
1718
  function useAvailabilities(productIds, siteCode, options = {}) {
1448
1719
  const { client } = useEmporix();
1449
- const ctx = options.customerToken ? emporixSdk.auth.customer(options.customerToken) : emporixSdk.auth.anonymous();
1450
- return reactQuery.useQuery({
1720
+ const ctx = options.customerToken ? import_emporix_sdk33.auth.customer(options.customerToken) : import_emporix_sdk33.auth.anonymous();
1721
+ return (0, import_react_query33.useQuery)({
1451
1722
  queryKey: [
1452
1723
  "emporix",
1453
1724
  "availabilities",
@@ -1466,29 +1737,35 @@ function useAvailabilities(productIds, siteCode, options = {}) {
1466
1737
  staleTime: AVAILABILITY_STALE_TIME2
1467
1738
  });
1468
1739
  }
1740
+
1741
+ // src/hooks/use-coupons.ts
1742
+ var import_react_query34 = require("@tanstack/react-query");
1469
1743
  var INVALIDATE_KEY2 = ["emporix", "coupons"];
1470
1744
  function useValidateCoupon() {
1471
1745
  const { client } = useEmporix();
1472
1746
  const { ctx } = useReadAuth();
1473
- return reactQuery.useMutation({
1747
+ return (0, import_react_query34.useMutation)({
1474
1748
  mutationFn: ({ code, redemption }) => client.coupons.validateCoupon(code, redemption, ctx)
1475
1749
  });
1476
1750
  }
1477
1751
  function useRedeemCoupon() {
1478
1752
  const { client } = useEmporix();
1479
1753
  const { ctx } = useReadAuth();
1480
- const qc = reactQuery.useQueryClient();
1481
- return reactQuery.useMutation({
1754
+ const qc = (0, import_react_query34.useQueryClient)();
1755
+ return (0, import_react_query34.useMutation)({
1482
1756
  mutationFn: ({ code, redemption }) => client.coupons.redeemCoupon(code, redemption, ctx),
1483
1757
  onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY2 })
1484
1758
  });
1485
1759
  }
1760
+
1761
+ // src/hooks/use-reward-points.ts
1762
+ var import_react_query35 = require("@tanstack/react-query");
1486
1763
  var STALE = 3e4;
1487
1764
  var INVALIDATE_KEY3 = ["emporix", "reward-points"];
1488
1765
  function useMyRewardPoints() {
1489
1766
  const { client } = useEmporix();
1490
1767
  const ctx = useCustomerOnlyCtx();
1491
- return reactQuery.useQuery({
1768
+ return (0, import_react_query35.useQuery)({
1492
1769
  queryKey: emporixKey("reward-points", ["mine"], { tenant: client.tenant, authKind: ctx.kind }),
1493
1770
  queryFn: () => client.rewardPoints.getMyPoints(ctx),
1494
1771
  staleTime: STALE
@@ -1497,7 +1774,7 @@ function useMyRewardPoints() {
1497
1774
  function useMyRewardPointsSummary() {
1498
1775
  const { client } = useEmporix();
1499
1776
  const ctx = useCustomerOnlyCtx();
1500
- return reactQuery.useQuery({
1777
+ return (0, import_react_query35.useQuery)({
1501
1778
  queryKey: emporixKey("reward-points", ["mine", "summary"], { tenant: client.tenant, authKind: ctx.kind }),
1502
1779
  queryFn: () => client.rewardPoints.getMySummary(ctx),
1503
1780
  staleTime: STALE
@@ -1506,7 +1783,7 @@ function useMyRewardPointsSummary() {
1506
1783
  function useRedeemOptions() {
1507
1784
  const { client } = useEmporix();
1508
1785
  const { ctx } = useReadAuth();
1509
- return reactQuery.useQuery({
1786
+ return (0, import_react_query35.useQuery)({
1510
1787
  queryKey: emporixKey("reward-points", ["redeem-options"], { tenant: client.tenant, authKind: ctx.kind }),
1511
1788
  queryFn: () => client.rewardPoints.listRedeemOptions(ctx),
1512
1789
  staleTime: STALE
@@ -1515,18 +1792,21 @@ function useRedeemOptions() {
1515
1792
  function useRedeemRewardPoints() {
1516
1793
  const { client } = useEmporix();
1517
1794
  const ctx = useCustomerOnlyCtx();
1518
- const qc = reactQuery.useQueryClient();
1519
- return reactQuery.useMutation({
1795
+ const qc = (0, import_react_query35.useQueryClient)();
1796
+ return (0, import_react_query35.useMutation)({
1520
1797
  mutationFn: (input) => client.rewardPoints.redeemMyPoints(input, ctx),
1521
1798
  onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY3 })
1522
1799
  });
1523
1800
  }
1801
+
1802
+ // src/hooks/use-returns.ts
1803
+ var import_react_query36 = require("@tanstack/react-query");
1524
1804
  var STALE2 = 3e4;
1525
1805
  var INVALIDATE_KEY4 = ["emporix", "returns"];
1526
1806
  function useMyReturns(opts = {}) {
1527
1807
  const { client } = useEmporix();
1528
1808
  const ctx = useCustomerOnlyCtx();
1529
- return reactQuery.useQuery({
1809
+ return (0, import_react_query36.useQuery)({
1530
1810
  queryKey: emporixKey("returns", [opts.query ?? null], { tenant: client.tenant, authKind: ctx.kind }),
1531
1811
  queryFn: () => client.returns.listReturns(opts.query ?? {}, ctx),
1532
1812
  staleTime: STALE2
@@ -1535,7 +1815,7 @@ function useMyReturns(opts = {}) {
1535
1815
  function useReturn(returnId) {
1536
1816
  const { client } = useEmporix();
1537
1817
  const ctx = useCustomerOnlyCtx();
1538
- return reactQuery.useQuery({
1818
+ return (0, import_react_query36.useQuery)({
1539
1819
  queryKey: emporixKey("returns", [returnId ?? null], { tenant: client.tenant, authKind: ctx.kind }),
1540
1820
  queryFn: () => client.returns.getReturn(returnId, ctx),
1541
1821
  enabled: Boolean(returnId),
@@ -1545,18 +1825,21 @@ function useReturn(returnId) {
1545
1825
  function useCreateReturn() {
1546
1826
  const { client } = useEmporix();
1547
1827
  const ctx = useCustomerOnlyCtx();
1548
- const qc = reactQuery.useQueryClient();
1549
- return reactQuery.useMutation({
1828
+ const qc = (0, import_react_query36.useQueryClient)();
1829
+ return (0, import_react_query36.useMutation)({
1550
1830
  mutationFn: (input) => client.returns.createReturn(input, ctx),
1551
1831
  onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY4 })
1552
1832
  });
1553
1833
  }
1834
+
1835
+ // src/hooks/use-approvals.ts
1836
+ var import_react_query37 = require("@tanstack/react-query");
1554
1837
  var STALE3 = 3e4;
1555
1838
  var INVALIDATE_KEY5 = ["emporix", "approvals"];
1556
1839
  function useApprovals(opts = {}) {
1557
1840
  const { client } = useEmporix();
1558
1841
  const ctx = useCustomerOnlyCtx();
1559
- return reactQuery.useQuery({
1842
+ return (0, import_react_query37.useQuery)({
1560
1843
  queryKey: emporixKey("approvals", [opts.query ?? null], { tenant: client.tenant, authKind: ctx.kind }),
1561
1844
  queryFn: () => client.approvals.listApprovals(opts.query ?? {}, ctx),
1562
1845
  staleTime: STALE3
@@ -1565,7 +1848,7 @@ function useApprovals(opts = {}) {
1565
1848
  function useApproval(approvalId) {
1566
1849
  const { client } = useEmporix();
1567
1850
  const ctx = useCustomerOnlyCtx();
1568
- return reactQuery.useQuery({
1851
+ return (0, import_react_query37.useQuery)({
1569
1852
  queryKey: emporixKey("approvals", [approvalId ?? null], { tenant: client.tenant, authKind: ctx.kind }),
1570
1853
  queryFn: () => client.approvals.getApproval(approvalId, ctx),
1571
1854
  enabled: Boolean(approvalId),
@@ -1575,8 +1858,8 @@ function useApproval(approvalId) {
1575
1858
  function useCreateApproval() {
1576
1859
  const { client } = useEmporix();
1577
1860
  const ctx = useCustomerOnlyCtx();
1578
- const qc = reactQuery.useQueryClient();
1579
- return reactQuery.useMutation({
1861
+ const qc = (0, import_react_query37.useQueryClient)();
1862
+ return (0, import_react_query37.useMutation)({
1580
1863
  mutationFn: (input) => client.approvals.createApproval(input, ctx),
1581
1864
  onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY5 })
1582
1865
  });
@@ -1584,101 +1867,102 @@ function useCreateApproval() {
1584
1867
  function useUpdateApproval() {
1585
1868
  const { client } = useEmporix();
1586
1869
  const ctx = useCustomerOnlyCtx();
1587
- const qc = reactQuery.useQueryClient();
1588
- return reactQuery.useMutation({
1870
+ const qc = (0, import_react_query37.useQueryClient)();
1871
+ return (0, import_react_query37.useMutation)({
1589
1872
  mutationFn: ({ approvalId, ops }) => client.approvals.updateApproval(approvalId, ops, ctx),
1590
1873
  onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY5 })
1591
1874
  });
1592
1875
  }
1593
-
1594
- exports.useActiveCart = useActiveCart;
1595
- exports.useActiveSite = useActiveSite;
1596
- exports.useAddGroupMember = useAddGroupMember;
1597
- exports.useAddToShoppingList = useAddToShoppingList;
1598
- exports.useAddressMutations = useAddressMutations;
1599
- exports.useApproval = useApproval;
1600
- exports.useApprovals = useApprovals;
1601
- exports.useAssignContact = useAssignContact;
1602
- exports.useAvailabilities = useAvailabilities;
1603
- exports.useAvailability = useAvailability;
1604
- exports.useCancelOrder = useCancelOrder;
1605
- exports.useCart = useCart;
1606
- exports.useCartMutations = useCartMutations;
1607
- exports.useCategories = useCategories;
1608
- exports.useCategoriesInfinite = useCategoriesInfinite;
1609
- exports.useCategory = useCategory;
1610
- exports.useCategoryTree = useCategoryTree;
1611
- exports.useChangePassword = useChangePassword;
1612
- exports.useCheckout = useCheckout;
1613
- exports.useCloudFunction = useCloudFunction;
1614
- exports.useCompany = useCompany;
1615
- exports.useCompanyContacts = useCompanyContacts;
1616
- exports.useCompanyGroups = useCompanyGroups;
1617
- exports.useCompanyLocations = useCompanyLocations;
1618
- exports.useCompanySwitcher = useCompanySwitcher;
1619
- exports.useCreateApproval = useCreateApproval;
1620
- exports.useCreateCart = useCreateCart;
1621
- exports.useCreateCompany = useCreateCompany;
1622
- exports.useCreateLocation = useCreateLocation;
1623
- exports.useCreateReturn = useCreateReturn;
1624
- exports.useCreateShoppingList = useCreateShoppingList;
1625
- exports.useCustomerAddresses = useCustomerAddresses;
1626
- exports.useCustomerSession = useCustomerSession;
1627
- exports.useDefaultSite = useDefaultSite;
1628
- exports.useDeleteCompany = useDeleteCompany;
1629
- exports.useDeleteLocation = useDeleteLocation;
1630
- exports.useDeleteShoppingList = useDeleteShoppingList;
1631
- exports.useInvokeCloudFunction = useInvokeCloudFunction;
1632
- exports.useMatchPrices = useMatchPrices;
1633
- exports.useMatchPricesChunked = useMatchPricesChunked;
1634
- exports.useMyCompanies = useMyCompanies;
1635
- exports.useMyOrders = useMyOrders;
1636
- exports.useMyOrdersInfinite = useMyOrdersInfinite;
1637
- exports.useMyReturns = useMyReturns;
1638
- exports.useMyRewardPoints = useMyRewardPoints;
1639
- exports.useMyRewardPointsSummary = useMyRewardPointsSummary;
1640
- exports.useMySegmentCategories = useMySegmentCategories;
1641
- exports.useMySegmentCategoriesInfinite = useMySegmentCategoriesInfinite;
1642
- exports.useMySegmentCategoryTree = useMySegmentCategoryTree;
1643
- exports.useMySegmentItems = useMySegmentItems;
1644
- exports.useMySegmentProducts = useMySegmentProducts;
1645
- exports.useMySegmentProductsInfinite = useMySegmentProductsInfinite;
1646
- exports.useMySegments = useMySegments;
1647
- exports.useOrder = useOrder;
1648
- exports.useOrderTransition = useOrderTransition;
1649
- exports.usePasswordReset = usePasswordReset;
1650
- exports.usePaymentModes = usePaymentModes;
1651
- exports.useProduct = useProduct;
1652
- exports.useProductByCode = useProductByCode;
1653
- exports.useProductMedia = useProductMedia;
1654
- exports.useProductNameSearch = useProductNameSearch;
1655
- exports.useProductSearch = useProductSearch;
1656
- exports.useProducts = useProducts;
1657
- exports.useProductsByCodes = useProductsByCodes;
1658
- exports.useProductsInCategory = useProductsInCategory;
1659
- exports.useProductsInCategoryInfinite = useProductsInCategoryInfinite;
1660
- exports.useProductsInfinite = useProductsInfinite;
1661
- exports.useRedeemCoupon = useRedeemCoupon;
1662
- exports.useRedeemOptions = useRedeemOptions;
1663
- exports.useRedeemRewardPoints = useRedeemRewardPoints;
1664
- exports.useRemoveFromShoppingList = useRemoveFromShoppingList;
1665
- exports.useRemoveGroupMember = useRemoveGroupMember;
1666
- exports.useReorder = useReorder;
1667
- exports.useReturn = useReturn;
1668
- exports.useSalesOrder = useSalesOrder;
1669
- exports.useSetShoppingListItemQuantity = useSetShoppingListItemQuantity;
1670
- exports.useShoppingLists = useShoppingLists;
1671
- exports.useSiteContext = useSiteContext;
1672
- exports.useSites = useSites;
1673
- exports.useSubcategories = useSubcategories;
1674
- exports.useUnassignContact = useUnassignContact;
1675
- exports.useUpdateApproval = useUpdateApproval;
1676
- exports.useUpdateCompany = useUpdateCompany;
1677
- exports.useUpdateContactAssignment = useUpdateContactAssignment;
1678
- exports.useUpdateCustomer = useUpdateCustomer;
1679
- exports.useUpdateLocation = useUpdateLocation;
1680
- exports.useUpdateSalesOrder = useUpdateSalesOrder;
1681
- exports.useValidateCoupon = useValidateCoupon;
1682
- exports.useVariantChildren = useVariantChildren;
1683
- //# sourceMappingURL=hooks.cjs.map
1876
+ // Annotate the CommonJS export names for ESM import in node:
1877
+ 0 && (module.exports = {
1878
+ useActiveCart,
1879
+ useActiveSite,
1880
+ useAddGroupMember,
1881
+ useAddToShoppingList,
1882
+ useAddressMutations,
1883
+ useApproval,
1884
+ useApprovals,
1885
+ useAssignContact,
1886
+ useAvailabilities,
1887
+ useAvailability,
1888
+ useCancelOrder,
1889
+ useCart,
1890
+ useCartMutations,
1891
+ useCategories,
1892
+ useCategoriesInfinite,
1893
+ useCategory,
1894
+ useCategoryTree,
1895
+ useChangePassword,
1896
+ useCheckout,
1897
+ useCloudFunction,
1898
+ useCompany,
1899
+ useCompanyContacts,
1900
+ useCompanyGroups,
1901
+ useCompanyLocations,
1902
+ useCompanySwitcher,
1903
+ useCreateApproval,
1904
+ useCreateCart,
1905
+ useCreateCompany,
1906
+ useCreateLocation,
1907
+ useCreateReturn,
1908
+ useCreateShoppingList,
1909
+ useCustomerAddresses,
1910
+ useCustomerSession,
1911
+ useDefaultSite,
1912
+ useDeleteCompany,
1913
+ useDeleteLocation,
1914
+ useDeleteShoppingList,
1915
+ useInvokeCloudFunction,
1916
+ useMatchPrices,
1917
+ useMatchPricesChunked,
1918
+ useMyCompanies,
1919
+ useMyOrders,
1920
+ useMyOrdersInfinite,
1921
+ useMyReturns,
1922
+ useMyRewardPoints,
1923
+ useMyRewardPointsSummary,
1924
+ useMySegmentCategories,
1925
+ useMySegmentCategoriesInfinite,
1926
+ useMySegmentCategoryTree,
1927
+ useMySegmentItems,
1928
+ useMySegmentProducts,
1929
+ useMySegmentProductsInfinite,
1930
+ useMySegments,
1931
+ useOrder,
1932
+ useOrderTransition,
1933
+ usePasswordReset,
1934
+ usePaymentModes,
1935
+ useProduct,
1936
+ useProductByCode,
1937
+ useProductMedia,
1938
+ useProductNameSearch,
1939
+ useProductSearch,
1940
+ useProducts,
1941
+ useProductsByCodes,
1942
+ useProductsInCategory,
1943
+ useProductsInCategoryInfinite,
1944
+ useProductsInfinite,
1945
+ useRedeemCoupon,
1946
+ useRedeemOptions,
1947
+ useRedeemRewardPoints,
1948
+ useRemoveFromShoppingList,
1949
+ useRemoveGroupMember,
1950
+ useReorder,
1951
+ useReturn,
1952
+ useSalesOrder,
1953
+ useSetShoppingListItemQuantity,
1954
+ useShoppingLists,
1955
+ useSiteContext,
1956
+ useSites,
1957
+ useSubcategories,
1958
+ useUnassignContact,
1959
+ useUpdateApproval,
1960
+ useUpdateCompany,
1961
+ useUpdateContactAssignment,
1962
+ useUpdateCustomer,
1963
+ useUpdateLocation,
1964
+ useUpdateSalesOrder,
1965
+ useValidateCoupon,
1966
+ useVariantChildren
1967
+ });
1684
1968
  //# sourceMappingURL=hooks.cjs.map