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