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