@simpleapps-com/augur-hooks 2.0.22 → 2.1.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/EXPORTS.md +10 -117
- package/dist/cart-pricing-D_mSECzx.d.cts +184 -0
- package/dist/cart-pricing-D_mSECzx.d.ts +184 -0
- package/dist/chunk-JPSDNJIZ.js +138 -0
- package/dist/chunk-JPSDNJIZ.js.map +1 -0
- package/dist/chunk-Q5YH4HDR.cjs +138 -0
- package/dist/chunk-Q5YH4HDR.cjs.map +1 -0
- package/dist/index.cjs +53 -818
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -622
- package/dist/index.d.ts +5 -622
- package/dist/index.js +28 -793
- package/dist/index.js.map +1 -1
- package/dist/server.cjs +2 -82
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.js +1 -81
- package/dist/server.js.map +1 -1
- package/dist/web.cjs +42 -6
- package/dist/web.cjs.map +1 -1
- package/dist/web.d.cts +16 -3
- package/dist/web.d.ts +16 -3
- package/dist/web.js +40 -4
- package/dist/web.js.map +1 -1
- package/llms.txt +12 -117
- package/package.json +3 -3
- package/dist/chunk-AXCNTEAB.cjs +0 -44
- package/dist/chunk-AXCNTEAB.cjs.map +0 -1
- package/dist/chunk-H7OXSAHP.cjs +0 -748
- package/dist/chunk-H7OXSAHP.cjs.map +0 -1
- package/dist/chunk-LTBEP4MC.js +0 -44
- package/dist/chunk-LTBEP4MC.js.map +0 -1
- package/dist/chunk-QFZHOGID.js +0 -748
- package/dist/chunk-QFZHOGID.js.map +0 -1
- package/dist/customer-quotes-BQYqzomR.d.cts +0 -562
- package/dist/customer-quotes-BQYqzomR.d.ts +0 -562
- package/dist/use-image-with-fallback-DgmtrGZU.d.cts +0 -17
- package/dist/use-image-with-fallback-DgmtrGZU.d.ts +0 -17
package/dist/index.js
CHANGED
|
@@ -1,74 +1,25 @@
|
|
|
1
1
|
import {
|
|
2
2
|
executeBatchQuery,
|
|
3
|
-
getBatchInvMastDocKey,
|
|
4
|
-
getBatchInvMastDocOptions,
|
|
5
3
|
getCartPricingQueryOptions,
|
|
6
|
-
getCategoryItemsInfiniteKey,
|
|
7
|
-
getCategoryItemsInfiniteOptions,
|
|
8
|
-
getCustomerInvoiceDetailKey,
|
|
9
|
-
getCustomerInvoicesKey,
|
|
10
|
-
getCustomerOrderDetailKey,
|
|
11
|
-
getCustomerOrdersKey,
|
|
12
|
-
getCustomerQuoteDetailKey,
|
|
13
|
-
getCustomerQuotesKey,
|
|
14
|
-
getInvMastDocKey,
|
|
15
|
-
getInvMastDocOptions,
|
|
16
|
-
getInvMastKey,
|
|
17
|
-
getInvMastOptions,
|
|
18
|
-
getInvMastStockKey,
|
|
19
|
-
getInvMastStockOptions,
|
|
20
|
-
getItemAttributesKey,
|
|
21
|
-
getItemAttributesOptions,
|
|
22
|
-
getItemCategoryKey,
|
|
23
|
-
getItemCategoryOptions,
|
|
24
|
-
getItemDetailsKey,
|
|
25
|
-
getItemDetailsOptions,
|
|
26
4
|
getItemPriceKey,
|
|
27
5
|
getItemPriceOptions,
|
|
28
|
-
getItemSearchInfiniteKey,
|
|
29
|
-
getItemSearchInfiniteOptions,
|
|
30
|
-
getJoomlaContentKey,
|
|
31
|
-
getJoomlaContentListKey,
|
|
32
|
-
getJoomlaContentListOptions,
|
|
33
|
-
getJoomlaContentOptions,
|
|
34
|
-
getJoomlaMenuDocKey,
|
|
35
|
-
getJoomlaMenuDocOptions,
|
|
36
|
-
getJoomlaMenuKey,
|
|
37
|
-
getJoomlaMenuOptions,
|
|
38
|
-
getProductCategoryKey,
|
|
39
|
-
getProductCategoryOptions,
|
|
40
|
-
getProductSearchKey,
|
|
41
|
-
getProductSearchOptions,
|
|
42
|
-
getSearchSuggestionsKey,
|
|
43
|
-
getSearchSuggestionsOptions,
|
|
44
6
|
getStockKey,
|
|
45
7
|
getStockOptions
|
|
46
|
-
} from "./chunk-
|
|
47
|
-
import {
|
|
48
|
-
useImageWithFallback
|
|
49
|
-
} from "./chunk-LTBEP4MC.js";
|
|
8
|
+
} from "./chunk-JPSDNJIZ.js";
|
|
50
9
|
|
|
51
10
|
// src/provider.tsx
|
|
52
11
|
import { createContext, useContext, useMemo } from "react";
|
|
53
12
|
import { createOptionsProxy } from "@simpleapps-com/augur-core";
|
|
54
13
|
import { jsx } from "react/jsx-runtime";
|
|
55
14
|
var AugurApiContext = createContext(null);
|
|
56
|
-
var AugurCallbacksContext = createContext(void 0);
|
|
57
15
|
var AugurAuthReactContext = createContext(void 0);
|
|
58
16
|
var AugurCacheContext = createContext(void 0);
|
|
59
17
|
var AugurOptionsContext = createContext(null);
|
|
60
18
|
var AugurSiteContext = createContext(void 0);
|
|
61
|
-
function AugurHooksProvider({
|
|
62
|
-
api
|
|
63
|
-
callbacks,
|
|
64
|
-
auth,
|
|
65
|
-
cache,
|
|
66
|
-
site,
|
|
67
|
-
children
|
|
68
|
-
}) {
|
|
69
|
-
if (process.env["NODE_ENV"] === "development" && !api && !callbacks) {
|
|
19
|
+
function AugurHooksProvider({ api, auth, cache, site, children }) {
|
|
20
|
+
if (process.env["NODE_ENV"] === "development" && !api) {
|
|
70
21
|
console.warn(
|
|
71
|
-
"AugurHooksProvider:
|
|
22
|
+
"AugurHooksProvider: no `api` provided. Hooks will fail at runtime unless every hook receives a queryFn override."
|
|
72
23
|
);
|
|
73
24
|
}
|
|
74
25
|
const proxyConfig = cache ? { cache: { static: cache.static, semiStatic: cache.semiStatic } } : void 0;
|
|
@@ -77,7 +28,7 @@ function AugurHooksProvider({
|
|
|
77
28
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
78
29
|
[api]
|
|
79
30
|
);
|
|
80
|
-
return /* @__PURE__ */ jsx(AugurApiContext.Provider, { value: api ?? null, children: /* @__PURE__ */ jsx(
|
|
31
|
+
return /* @__PURE__ */ jsx(AugurApiContext.Provider, { value: api ?? null, children: /* @__PURE__ */ jsx(AugurAuthReactContext.Provider, { value: auth, children: /* @__PURE__ */ jsx(AugurCacheContext.Provider, { value: cache, children: /* @__PURE__ */ jsx(AugurSiteContext.Provider, { value: site, children: /* @__PURE__ */ jsx(AugurOptionsContext.Provider, { value: options, children }) }) }) }) });
|
|
81
32
|
}
|
|
82
33
|
function useAugurOptions() {
|
|
83
34
|
const options = useContext(AugurOptionsContext);
|
|
@@ -100,9 +51,6 @@ function useAugurApi() {
|
|
|
100
51
|
}
|
|
101
52
|
return api;
|
|
102
53
|
}
|
|
103
|
-
function useAugurCallbacks() {
|
|
104
|
-
return useContext(AugurCallbacksContext);
|
|
105
|
-
}
|
|
106
54
|
function useAugurAuth() {
|
|
107
55
|
return useContext(AugurAuthReactContext);
|
|
108
56
|
}
|
|
@@ -226,122 +174,16 @@ function useFormatPrice(optionsOrLocale, legacyCurrency) {
|
|
|
226
174
|
return { formatPrice };
|
|
227
175
|
}
|
|
228
176
|
|
|
229
|
-
// src/hooks/use-
|
|
177
|
+
// src/hooks/use-stock.ts
|
|
230
178
|
import { useMemo as useMemo2 } from "react";
|
|
231
179
|
import { useQuery } from "@tanstack/react-query";
|
|
232
|
-
import { derivePrice } from "@simpleapps-com/augur-utils";
|
|
233
|
-
function useItemPrice(itemId, customerId, quantity = 1, options = {}) {
|
|
234
|
-
const api = useAugurApiOptional();
|
|
235
|
-
const callbacks = useAugurCallbacks();
|
|
236
|
-
const auth = useAugurAuth();
|
|
237
|
-
const cache = useAugurCache();
|
|
238
|
-
const site = useAugurSite();
|
|
239
|
-
const effectiveCustomerId = customerId ?? auth?.customerId ?? site?.defaults?.customerId;
|
|
240
|
-
const defaultOptions = getItemPriceOptions(api, itemId, effectiveCustomerId, quantity, cache);
|
|
241
|
-
const resolvedQueryFn = options.queryFn ?? (callbacks?.getItemPrice ? () => callbacks.getItemPrice(itemId, effectiveCustomerId, quantity) : void 0);
|
|
242
|
-
const query = useQuery({
|
|
243
|
-
...defaultOptions,
|
|
244
|
-
...resolvedQueryFn ? { queryFn: resolvedQueryFn } : {},
|
|
245
|
-
enabled: options.enabled ?? (Boolean(itemId) && Boolean(effectiveCustomerId)),
|
|
246
|
-
retry: 3
|
|
247
|
-
});
|
|
248
|
-
const derived = useMemo2(
|
|
249
|
-
() => derivePrice({ priceData: query.data, quantity }),
|
|
250
|
-
[query.data, quantity]
|
|
251
|
-
);
|
|
252
|
-
return { ...query, derived };
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
// src/hooks/use-inv-mast-doc.ts
|
|
256
|
-
import { useQuery as useQuery2 } from "@tanstack/react-query";
|
|
257
|
-
function useInvMastDoc(invMastUid, itemId, options = {}) {
|
|
258
|
-
const api = useAugurApiOptional();
|
|
259
|
-
const callbacks = useAugurCallbacks();
|
|
260
|
-
const cache = useAugurCache();
|
|
261
|
-
const queryOpts = getInvMastDocOptions(
|
|
262
|
-
api,
|
|
263
|
-
invMastUid,
|
|
264
|
-
itemId,
|
|
265
|
-
options.includePricing ?? "N",
|
|
266
|
-
cache
|
|
267
|
-
);
|
|
268
|
-
const { data, isLoading, error } = useQuery2({
|
|
269
|
-
...queryOpts,
|
|
270
|
-
...options.queryFn ?? callbacks?.getInvMastDoc ? {
|
|
271
|
-
queryFn: options.queryFn ?? (() => callbacks.getInvMastDoc(invMastUid, itemId, options.includePricing ?? "N"))
|
|
272
|
-
} : {},
|
|
273
|
-
enabled: options.enabled ?? true,
|
|
274
|
-
initialData: options.initialData
|
|
275
|
-
});
|
|
276
|
-
return { item: data, isLoading, error };
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
// src/hooks/use-item-category.ts
|
|
280
|
-
import { useQuery as useQuery3 } from "@tanstack/react-query";
|
|
281
|
-
function useItemCategory(itemCategoryUid, options = {}) {
|
|
282
|
-
const api = useAugurApiOptional();
|
|
283
|
-
const callbacks = useAugurCallbacks();
|
|
284
|
-
const cache = useAugurCache();
|
|
285
|
-
const queryOpts = getItemCategoryOptions(api, itemCategoryUid, options.apiOptions, cache);
|
|
286
|
-
const { data, isLoading, error } = useQuery3({
|
|
287
|
-
...queryOpts,
|
|
288
|
-
...options.queryFn ?? callbacks?.getItemCategory ? {
|
|
289
|
-
queryFn: options.queryFn ?? (() => callbacks.getItemCategory(itemCategoryUid, options.apiOptions))
|
|
290
|
-
} : {},
|
|
291
|
-
enabled: options.enabled ?? true
|
|
292
|
-
});
|
|
293
|
-
return { category: data, isLoading, error };
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
// src/hooks/use-inv-mast.ts
|
|
297
|
-
import { useQuery as useQuery4 } from "@tanstack/react-query";
|
|
298
|
-
function useInvMast(invMastUid, itemId, options = {}) {
|
|
299
|
-
const api = useAugurApiOptional();
|
|
300
|
-
const callbacks = useAugurCallbacks();
|
|
301
|
-
const cache = useAugurCache();
|
|
302
|
-
const queryOpts = getInvMastOptions(api, invMastUid, itemId, cache);
|
|
303
|
-
const { data, isLoading, error } = useQuery4({
|
|
304
|
-
...queryOpts,
|
|
305
|
-
...options.queryFn ?? callbacks?.getInvMast ? { queryFn: options.queryFn ?? (() => callbacks.getInvMast(invMastUid, itemId)) } : {},
|
|
306
|
-
enabled: options.enabled ?? true
|
|
307
|
-
});
|
|
308
|
-
return { item: data, isLoading, error };
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
// src/hooks/use-inv-mast-stock.ts
|
|
312
|
-
import { useQuery as useQuery5 } from "@tanstack/react-query";
|
|
313
|
-
function useInvMastStock(invMastUid, options = {}) {
|
|
314
|
-
const api = useAugurApiOptional();
|
|
315
|
-
const callbacks = useAugurCallbacks();
|
|
316
|
-
const cache = useAugurCache();
|
|
317
|
-
const queryOpts = getInvMastStockOptions(api, invMastUid, cache);
|
|
318
|
-
const { data, isLoading, error } = useQuery5({
|
|
319
|
-
...queryOpts,
|
|
320
|
-
...options.queryFn ?? callbacks?.getInvMastStock ? { queryFn: options.queryFn ?? (() => callbacks.getInvMastStock(invMastUid)) } : {},
|
|
321
|
-
enabled: (options.enabled ?? true) && !!invMastUid,
|
|
322
|
-
retry: 3,
|
|
323
|
-
/* v8 ignore start */
|
|
324
|
-
retryDelay: (attemptIndex) => Math.min(1e3 * 2 ** attemptIndex, 1e4)
|
|
325
|
-
/* v8 ignore stop */
|
|
326
|
-
});
|
|
327
|
-
return {
|
|
328
|
-
qtyOnHand: data ?? null,
|
|
329
|
-
loading: isLoading,
|
|
330
|
-
error
|
|
331
|
-
};
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
// src/hooks/use-stock.ts
|
|
335
|
-
import { useMemo as useMemo3 } from "react";
|
|
336
|
-
import { useQuery as useQuery6 } from "@tanstack/react-query";
|
|
337
180
|
import { resolveStock } from "@simpleapps-com/augur-utils";
|
|
338
181
|
function useStock(invMastUid, options = {}) {
|
|
339
182
|
const api = useAugurApiOptional();
|
|
340
|
-
const callbacks = useAugurCallbacks();
|
|
341
183
|
const cache = useAugurCache();
|
|
342
184
|
const queryOpts = getStockOptions(api, invMastUid, cache);
|
|
343
|
-
const resolvedQueryFn = options.queryFn
|
|
344
|
-
const query =
|
|
185
|
+
const resolvedQueryFn = options.queryFn;
|
|
186
|
+
const query = useQuery({
|
|
345
187
|
...queryOpts,
|
|
346
188
|
...resolvedQueryFn ? { queryFn: resolvedQueryFn } : {},
|
|
347
189
|
enabled: (options.enabled ?? true) && !!invMastUid,
|
|
@@ -350,7 +192,7 @@ function useStock(invMastUid, options = {}) {
|
|
|
350
192
|
retryDelay: (attemptIndex) => Math.min(1e3 * 2 ** attemptIndex, 1e4)
|
|
351
193
|
/* v8 ignore stop */
|
|
352
194
|
});
|
|
353
|
-
const resolved =
|
|
195
|
+
const resolved = useMemo2(
|
|
354
196
|
() => resolveStock({
|
|
355
197
|
stock: query.data ?? null,
|
|
356
198
|
companyKey: options.companyKey,
|
|
@@ -374,189 +216,9 @@ function useStock(invMastUid, options = {}) {
|
|
|
374
216
|
};
|
|
375
217
|
}
|
|
376
218
|
|
|
377
|
-
// src/hooks/use-batch-inv-mast-doc.ts
|
|
378
|
-
import { useQuery as useQuery7, useQueryClient } from "@tanstack/react-query";
|
|
379
|
-
function useBatchInvMastDoc(params, options = {}) {
|
|
380
|
-
const api = useAugurApiOptional();
|
|
381
|
-
const callbacks = useAugurCallbacks();
|
|
382
|
-
const cache = useAugurCache();
|
|
383
|
-
const queryClient = useQueryClient();
|
|
384
|
-
const includePricing = options.includePricing ?? "N";
|
|
385
|
-
const batchOpts = getBatchInvMastDocOptions(api, params, includePricing, cache);
|
|
386
|
-
const resolveFetchItems = (uncached) => {
|
|
387
|
-
if (options.queryFn) {
|
|
388
|
-
return options.queryFn(uncached, includePricing);
|
|
389
|
-
}
|
|
390
|
-
if (callbacks?.batchGetInvMastDocs) {
|
|
391
|
-
return callbacks.batchGetInvMastDocs(uncached, includePricing);
|
|
392
|
-
}
|
|
393
|
-
const fallbackOpts = getBatchInvMastDocOptions(api, uncached, includePricing, cache);
|
|
394
|
-
return fallbackOpts.queryFn();
|
|
395
|
-
};
|
|
396
|
-
const { data, isLoading, error } = useQuery7({
|
|
397
|
-
queryKey: batchOpts.queryKey,
|
|
398
|
-
queryFn: () => executeBatchQuery({
|
|
399
|
-
params,
|
|
400
|
-
queryClient,
|
|
401
|
-
getItemKey: (p) => getInvMastDocKey(p.invMastUid, p.itemId, includePricing),
|
|
402
|
-
getResultKey: (p) => p.itemId.toUpperCase(),
|
|
403
|
-
fetchItems: resolveFetchItems,
|
|
404
|
-
getSeedKey: (_key, doc) => getInvMastDocKey(doc.invMastUid, doc.itemId, includePricing)
|
|
405
|
-
}),
|
|
406
|
-
staleTime: batchOpts.staleTime,
|
|
407
|
-
gcTime: batchOpts.gcTime,
|
|
408
|
-
enabled: params.length > 0 && (options.enabled ?? true)
|
|
409
|
-
});
|
|
410
|
-
return { items: data ?? {}, isLoading, error: error ?? null };
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
// src/hooks/use-product-category.ts
|
|
414
|
-
import { useQuery as useQuery8 } from "@tanstack/react-query";
|
|
415
|
-
function resolveData(data) {
|
|
416
|
-
return {
|
|
417
|
-
childrenTotal: data?.childrenTotal ?? 0,
|
|
418
|
-
itemCategoryDesc: data?.itemCategoryDesc ?? "",
|
|
419
|
-
productCategories: data?.children ?? null,
|
|
420
|
-
productCategoryImage: data?.categoryImage ?? null
|
|
421
|
-
};
|
|
422
|
-
}
|
|
423
|
-
function useProductCategory(itemCategoryUid, options = {}) {
|
|
424
|
-
const api = useAugurApiOptional();
|
|
425
|
-
const callbacks = useAugurCallbacks();
|
|
426
|
-
const cache = useAugurCache();
|
|
427
|
-
const baseOptions = itemCategoryUid ? getProductCategoryOptions(api, itemCategoryUid, cache) : {
|
|
428
|
-
queryKey: getProductCategoryKey(null),
|
|
429
|
-
/* v8 ignore next */
|
|
430
|
-
queryFn: () => Promise.reject()
|
|
431
|
-
};
|
|
432
|
-
const resolvedQueryFn = options.queryFn ?? (callbacks?.getProductCategory ? () => callbacks.getProductCategory(itemCategoryUid) : void 0);
|
|
433
|
-
const { data, isLoading, error } = useQuery8({
|
|
434
|
-
...baseOptions,
|
|
435
|
-
...resolvedQueryFn ? { queryFn: resolvedQueryFn } : {},
|
|
436
|
-
enabled: (options.enabled ?? true) && !!itemCategoryUid,
|
|
437
|
-
retry: 3,
|
|
438
|
-
/* v8 ignore start */
|
|
439
|
-
retryDelay: (attemptIndex) => Math.min(1e3 * 2 ** attemptIndex, 1e4)
|
|
440
|
-
/* v8 ignore stop */
|
|
441
|
-
});
|
|
442
|
-
return {
|
|
443
|
-
...resolveData(data),
|
|
444
|
-
loading: isLoading,
|
|
445
|
-
error
|
|
446
|
-
};
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
// src/hooks/use-item-details.ts
|
|
450
|
-
import { useQuery as useQuery9 } from "@tanstack/react-query";
|
|
451
|
-
function useItemDetails(itemId, options = {}) {
|
|
452
|
-
const api = useAugurApiOptional();
|
|
453
|
-
const callbacks = useAugurCallbacks();
|
|
454
|
-
const cache = useAugurCache();
|
|
455
|
-
const { data, isLoading, error } = useQuery9({
|
|
456
|
-
...itemId ? getItemDetailsOptions(api, itemId, cache) : {
|
|
457
|
-
queryKey: getItemDetailsKey(""),
|
|
458
|
-
/* v8 ignore next */
|
|
459
|
-
queryFn: () => Promise.reject()
|
|
460
|
-
},
|
|
461
|
-
...options.queryFn ?? callbacks?.getItemDetails ? { queryFn: options.queryFn ?? (() => callbacks.getItemDetails(itemId)) } : {},
|
|
462
|
-
enabled: (options.enabled ?? true) && !!itemId,
|
|
463
|
-
retry: 3,
|
|
464
|
-
/* v8 ignore start */
|
|
465
|
-
retryDelay: (attemptIndex) => Math.min(1e3 * 2 ** attemptIndex, 1e4)
|
|
466
|
-
/* v8 ignore stop */
|
|
467
|
-
});
|
|
468
|
-
const categoryList = data?.categoryList ?? [];
|
|
469
|
-
return {
|
|
470
|
-
itemCategoryUid: categoryList.length > 0 ? categoryList[categoryList.length - 1] : null,
|
|
471
|
-
itemDetails: data ?? null,
|
|
472
|
-
loading: isLoading,
|
|
473
|
-
error
|
|
474
|
-
};
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
// src/hooks/use-item-attributes.ts
|
|
478
|
-
import { useQuery as useQuery10 } from "@tanstack/react-query";
|
|
479
|
-
function useItemAttributes(itemCategoryUid, options = {}) {
|
|
480
|
-
const api = useAugurApiOptional();
|
|
481
|
-
const callbacks = useAugurCallbacks();
|
|
482
|
-
const cache = useAugurCache();
|
|
483
|
-
const { data, isLoading, error } = useQuery10({
|
|
484
|
-
...itemCategoryUid ? getItemAttributesOptions(api, itemCategoryUid, cache) : {
|
|
485
|
-
queryKey: getItemAttributesKey(null),
|
|
486
|
-
/* v8 ignore next */
|
|
487
|
-
queryFn: () => Promise.reject()
|
|
488
|
-
},
|
|
489
|
-
...options.queryFn ?? callbacks?.getItemAttributes ? { queryFn: options.queryFn ?? (() => callbacks.getItemAttributes(itemCategoryUid)) } : {},
|
|
490
|
-
enabled: (options.enabled ?? true) && !!itemCategoryUid,
|
|
491
|
-
retry: 3,
|
|
492
|
-
/* v8 ignore start */
|
|
493
|
-
retryDelay: (attemptIndex) => Math.min(1e3 * 2 ** attemptIndex, 1e4)
|
|
494
|
-
/* v8 ignore stop */
|
|
495
|
-
});
|
|
496
|
-
return {
|
|
497
|
-
attributes: data?.attributes ?? null,
|
|
498
|
-
loading: isLoading,
|
|
499
|
-
error
|
|
500
|
-
};
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
// src/hooks/use-product-search.ts
|
|
504
|
-
import { useQuery as useQuery11 } from "@tanstack/react-query";
|
|
505
|
-
function useProductSearch(pageData, options = {}) {
|
|
506
|
-
const api = useAugurApiOptional();
|
|
507
|
-
const callbacks = useAugurCallbacks();
|
|
508
|
-
const cache = useAugurCache();
|
|
509
|
-
const defaultOptions = getProductSearchOptions(api, pageData, cache);
|
|
510
|
-
const { data, isLoading, error } = useQuery11({
|
|
511
|
-
...defaultOptions,
|
|
512
|
-
...options.queryFn ?? callbacks?.getProductSearch ? { queryFn: options.queryFn ?? (() => callbacks.getProductSearch(pageData)) } : {},
|
|
513
|
-
retry: 3,
|
|
514
|
-
/* v8 ignore start */
|
|
515
|
-
retryDelay: (attemptIndex) => Math.min(1e3 * 2 ** attemptIndex, 1e4)
|
|
516
|
-
/* v8 ignore stop */
|
|
517
|
-
});
|
|
518
|
-
return {
|
|
519
|
-
productItems: data?.items ?? null,
|
|
520
|
-
total: data?.totalResults ?? 0,
|
|
521
|
-
result: data,
|
|
522
|
-
loading: isLoading,
|
|
523
|
-
error
|
|
524
|
-
};
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
// src/hooks/use-search-suggestions.ts
|
|
528
|
-
import { useQuery as useQuery12 } from "@tanstack/react-query";
|
|
529
|
-
function useSearchSuggestions(query, options = {}) {
|
|
530
|
-
const api = useAugurApiOptional();
|
|
531
|
-
const callbacks = useAugurCallbacks();
|
|
532
|
-
const cache = useAugurCache();
|
|
533
|
-
const limit = options.limit ?? 10;
|
|
534
|
-
const offset = options.offset ?? 0;
|
|
535
|
-
const enabled = (options.enabled ?? true) && query.trim().length > 0;
|
|
536
|
-
const defaultOptions = getSearchSuggestionsOptions(api, query, limit, offset, cache);
|
|
537
|
-
const { data, isLoading, error } = useQuery12({
|
|
538
|
-
...defaultOptions,
|
|
539
|
-
...options.queryFn ?? callbacks?.getSearchSuggestions ? {
|
|
540
|
-
queryFn: options.queryFn ?? (() => callbacks.getSearchSuggestions(query, limit, offset))
|
|
541
|
-
} : {},
|
|
542
|
-
enabled
|
|
543
|
-
});
|
|
544
|
-
return {
|
|
545
|
-
suggestions: data?.data ?? [],
|
|
546
|
-
total: data?.total ?? 0,
|
|
547
|
-
count: data?.count,
|
|
548
|
-
totalResults: data?.totalResults,
|
|
549
|
-
message: data?.message,
|
|
550
|
-
status: data?.status,
|
|
551
|
-
result: data,
|
|
552
|
-
isLoading,
|
|
553
|
-
error
|
|
554
|
-
};
|
|
555
|
-
}
|
|
556
|
-
|
|
557
219
|
// src/hooks/use-cart-actions.ts
|
|
558
220
|
import { useCallback } from "react";
|
|
559
|
-
import { useQueryClient
|
|
221
|
+
import { useQueryClient } from "@tanstack/react-query";
|
|
560
222
|
function requireCartUid(cartHdrUid) {
|
|
561
223
|
const num = typeof cartHdrUid === "string" ? Number(cartHdrUid) : cartHdrUid;
|
|
562
224
|
if (!num) throw new Error("Cart UID is not set");
|
|
@@ -585,7 +247,7 @@ function buildOptimisticAdd(cartLines, item, cartHdrUid, itemId) {
|
|
|
585
247
|
];
|
|
586
248
|
}
|
|
587
249
|
function useCartActions(callbacks) {
|
|
588
|
-
const queryClient =
|
|
250
|
+
const queryClient = useQueryClient();
|
|
589
251
|
const cartHdrUid = useCartHdrUid();
|
|
590
252
|
const cartLines = useCartLines();
|
|
591
253
|
const setCartLines = useSetCartLines();
|
|
@@ -896,8 +558,8 @@ function usePaymentFlow({
|
|
|
896
558
|
}
|
|
897
559
|
|
|
898
560
|
// src/hooks/use-cart-initialization.ts
|
|
899
|
-
import { useEffect as useEffect3, useMemo as
|
|
900
|
-
import { useQuery as
|
|
561
|
+
import { useEffect as useEffect3, useMemo as useMemo3, useRef } from "react";
|
|
562
|
+
import { useQuery as useQuery2, useQueryClient as useQueryClient2 } from "@tanstack/react-query";
|
|
901
563
|
var MAX_RETRY_ATTEMPTS = 7;
|
|
902
564
|
var RETRY_DELAY_MS = 1e3;
|
|
903
565
|
var defaultGetCartToken = () => localStorage.getItem("cartToken");
|
|
@@ -912,11 +574,11 @@ function useCartInitialization(session, callbacks) {
|
|
|
912
574
|
const setCartHdrUid = useSetCartHdrUid();
|
|
913
575
|
const setCartLines = useSetCartLines();
|
|
914
576
|
const clearCart = useClearCart();
|
|
915
|
-
const queryClient =
|
|
577
|
+
const queryClient = useQueryClient2();
|
|
916
578
|
const effectiveStatus = session.status;
|
|
917
579
|
const effectiveUserId = session.userId ?? auth?.userId;
|
|
918
580
|
const effectiveCartHdrUid = session.cartHdrUid ?? auth?.cartHdrUid;
|
|
919
|
-
const effectiveSession =
|
|
581
|
+
const effectiveSession = useMemo3(
|
|
920
582
|
() => ({ status: effectiveStatus, userId: effectiveUserId, cartHdrUid: effectiveCartHdrUid }),
|
|
921
583
|
[effectiveStatus, effectiveUserId, effectiveCartHdrUid]
|
|
922
584
|
);
|
|
@@ -984,7 +646,7 @@ function useCartInitialization(session, callbacks) {
|
|
|
984
646
|
saveCartToken,
|
|
985
647
|
generateCartToken
|
|
986
648
|
]);
|
|
987
|
-
const { data: cartLinesData } =
|
|
649
|
+
const { data: cartLinesData } = useQuery2({
|
|
988
650
|
queryKey: ["cartLines", cartHdrUid],
|
|
989
651
|
queryFn: async () => await callbacks.getCartLines(Number(cartHdrUid)) ?? [],
|
|
990
652
|
enabled: !!cartHdrUid
|
|
@@ -1002,18 +664,17 @@ function useCartInitialization(session, callbacks) {
|
|
|
1002
664
|
}
|
|
1003
665
|
|
|
1004
666
|
// src/hooks/use-cart-pricing.ts
|
|
1005
|
-
import { useMemo as
|
|
667
|
+
import { useMemo as useMemo4 } from "react";
|
|
1006
668
|
import { useQueries } from "@tanstack/react-query";
|
|
1007
|
-
import { derivePrice
|
|
669
|
+
import { derivePrice } from "@simpleapps-com/augur-utils";
|
|
1008
670
|
function useCartPricing(options = {}) {
|
|
1009
671
|
const api = useAugurApiOptional();
|
|
1010
|
-
const callbacks = useAugurCallbacks();
|
|
1011
672
|
const auth = useAugurAuth();
|
|
1012
673
|
const cache = useAugurCache();
|
|
1013
674
|
const site = useAugurSite();
|
|
1014
675
|
const cartLines = useCartLines();
|
|
1015
676
|
const customerId = options.customerId ?? auth?.customerId ?? site?.defaults?.customerId;
|
|
1016
|
-
const priceFn = options.queryFn
|
|
677
|
+
const priceFn = options.queryFn;
|
|
1017
678
|
const priceQueries = useQueries({
|
|
1018
679
|
queries: cartLines.map((line) => {
|
|
1019
680
|
const base = priceFn ? {
|
|
@@ -1029,12 +690,12 @@ function useCartPricing(options = {}) {
|
|
|
1029
690
|
};
|
|
1030
691
|
})
|
|
1031
692
|
});
|
|
1032
|
-
const prices =
|
|
693
|
+
const prices = useMemo4(() => {
|
|
1033
694
|
const map = {};
|
|
1034
695
|
cartLines.forEach((line, index) => {
|
|
1035
696
|
const queryResult = priceQueries[index];
|
|
1036
697
|
if (queryResult?.data) {
|
|
1037
|
-
const derived =
|
|
698
|
+
const derived = derivePrice({ priceData: queryResult.data, quantity: line.quantity });
|
|
1038
699
|
map[line.itemId.toUpperCase()] = {
|
|
1039
700
|
unitPrice: derived.unitPrice,
|
|
1040
701
|
priceData: queryResult.data
|
|
@@ -1043,17 +704,17 @@ function useCartPricing(options = {}) {
|
|
|
1043
704
|
});
|
|
1044
705
|
return map;
|
|
1045
706
|
}, [cartLines, priceQueries]);
|
|
1046
|
-
const getUnitPrice =
|
|
707
|
+
const getUnitPrice = useMemo4(() => {
|
|
1047
708
|
return (itemId) => {
|
|
1048
709
|
return prices[itemId?.toUpperCase()]?.unitPrice ?? 0;
|
|
1049
710
|
};
|
|
1050
711
|
}, [prices]);
|
|
1051
|
-
const getItemTotal =
|
|
712
|
+
const getItemTotal = useMemo4(() => {
|
|
1052
713
|
return (itemId, quantity) => {
|
|
1053
714
|
return getUnitPrice(itemId) * quantity;
|
|
1054
715
|
};
|
|
1055
716
|
}, [getUnitPrice]);
|
|
1056
|
-
const subtotal =
|
|
717
|
+
const subtotal = useMemo4(() => {
|
|
1057
718
|
return cartLines.reduce((sum, line) => {
|
|
1058
719
|
const unitPrice = prices[line.itemId.toUpperCase()]?.unitPrice ?? 0;
|
|
1059
720
|
return sum + unitPrice * line.quantity;
|
|
@@ -1074,7 +735,7 @@ function useCartPricing(options = {}) {
|
|
|
1074
735
|
}
|
|
1075
736
|
|
|
1076
737
|
// src/hooks/use-pagination-prefetch.ts
|
|
1077
|
-
import { useQueryClient as
|
|
738
|
+
import { useQueryClient as useQueryClient3 } from "@tanstack/react-query";
|
|
1078
739
|
import { useCallback as useCallback3 } from "react";
|
|
1079
740
|
var usePaginationPrefetch = ({
|
|
1080
741
|
queryKey,
|
|
@@ -1085,7 +746,7 @@ var usePaginationPrefetch = ({
|
|
|
1085
746
|
gcTime = 30 * 60 * 1e3,
|
|
1086
747
|
enabled = true
|
|
1087
748
|
}) => {
|
|
1088
|
-
const queryClient =
|
|
749
|
+
const queryClient = useQueryClient3();
|
|
1089
750
|
const prefetchPage = useCallback3(
|
|
1090
751
|
async (page) => {
|
|
1091
752
|
if (!enabled) return;
|
|
@@ -1116,370 +777,8 @@ var usePaginationPrefetch = ({
|
|
|
1116
777
|
};
|
|
1117
778
|
};
|
|
1118
779
|
|
|
1119
|
-
// src/hooks/use-category-items-infinite.ts
|
|
1120
|
-
import { useInfiniteQuery } from "@tanstack/react-query";
|
|
1121
|
-
function useCategoryItemsInfinite(itemCategoryUid, itemsFilters, options = {}) {
|
|
1122
|
-
const api = useAugurApiOptional();
|
|
1123
|
-
const callbacks = useAugurCallbacks();
|
|
1124
|
-
const cache = useAugurCache();
|
|
1125
|
-
const { enabled = true } = options;
|
|
1126
|
-
const defaultOptions = getCategoryItemsInfiniteOptions(api, itemCategoryUid, itemsFilters, cache);
|
|
1127
|
-
const cb = callbacks?.getCategoryItemsInfinite;
|
|
1128
|
-
const resolvedQueryFn = options.queryFn ?? (cb ? ({ pageParam }) => cb({
|
|
1129
|
-
itemCategoryUid,
|
|
1130
|
-
itemsFilters,
|
|
1131
|
-
/* v8 ignore next */
|
|
1132
|
-
pageParam: pageParam ?? 0
|
|
1133
|
-
}) : void 0);
|
|
1134
|
-
return useInfiniteQuery({
|
|
1135
|
-
...defaultOptions,
|
|
1136
|
-
...resolvedQueryFn ? { queryFn: resolvedQueryFn } : {},
|
|
1137
|
-
enabled: enabled && !!itemCategoryUid
|
|
1138
|
-
});
|
|
1139
|
-
}
|
|
1140
|
-
|
|
1141
|
-
// src/hooks/use-item-search-infinite.ts
|
|
1142
|
-
import { useInfiniteQuery as useInfiniteQuery2 } from "@tanstack/react-query";
|
|
1143
|
-
function useItemSearchInfinite(itemsFilters, itemCategoryUid, options = {}) {
|
|
1144
|
-
const api = useAugurApiOptional();
|
|
1145
|
-
const callbacks = useAugurCallbacks();
|
|
1146
|
-
const cache = useAugurCache();
|
|
1147
|
-
const { enabled = true } = options;
|
|
1148
|
-
const defaultOptions = getItemSearchInfiniteOptions(api, itemsFilters, itemCategoryUid, cache);
|
|
1149
|
-
const cb = callbacks?.getItemSearchInfinite;
|
|
1150
|
-
const resolvedQueryFn = options.queryFn ?? (cb ? ({ pageParam }) => cb({
|
|
1151
|
-
itemsFilters,
|
|
1152
|
-
itemCategoryUid,
|
|
1153
|
-
/* v8 ignore next */
|
|
1154
|
-
pageParam: pageParam ?? 0
|
|
1155
|
-
}) : void 0);
|
|
1156
|
-
return useInfiniteQuery2({
|
|
1157
|
-
...defaultOptions,
|
|
1158
|
-
...resolvedQueryFn ? { queryFn: resolvedQueryFn } : {},
|
|
1159
|
-
enabled: enabled && !!itemsFilters.q
|
|
1160
|
-
});
|
|
1161
|
-
}
|
|
1162
|
-
|
|
1163
|
-
// src/hooks/use-joomla-content.ts
|
|
1164
|
-
import { useQuery as useQuery14 } from "@tanstack/react-query";
|
|
1165
|
-
function useJoomlaContent(articleId, options = {}) {
|
|
1166
|
-
const api = useAugurApiOptional();
|
|
1167
|
-
const callbacks = useAugurCallbacks();
|
|
1168
|
-
const cache = useAugurCache();
|
|
1169
|
-
const { data, isLoading, error } = useQuery14({
|
|
1170
|
-
...articleId ? getJoomlaContentOptions(api, articleId, cache) : {
|
|
1171
|
-
queryKey: getJoomlaContentKey(""),
|
|
1172
|
-
/* v8 ignore next */
|
|
1173
|
-
queryFn: () => Promise.reject()
|
|
1174
|
-
},
|
|
1175
|
-
...options.queryFn ?? callbacks?.getJoomlaContent ? { queryFn: options.queryFn ?? (() => callbacks.getJoomlaContent(articleId)) } : {},
|
|
1176
|
-
enabled: (options.enabled ?? true) && !!articleId
|
|
1177
|
-
});
|
|
1178
|
-
return {
|
|
1179
|
-
article: data ?? null,
|
|
1180
|
-
isLoading,
|
|
1181
|
-
error
|
|
1182
|
-
};
|
|
1183
|
-
}
|
|
1184
|
-
|
|
1185
|
-
// src/hooks/use-joomla-content-list.ts
|
|
1186
|
-
import { useQuery as useQuery15 } from "@tanstack/react-query";
|
|
1187
|
-
var EMPTY_LIST = { data: [], total: 0 };
|
|
1188
|
-
function useJoomlaContentList(categoryId, options = {}) {
|
|
1189
|
-
const api = useAugurApiOptional();
|
|
1190
|
-
const callbacks = useAugurCallbacks();
|
|
1191
|
-
const cache = useAugurCache();
|
|
1192
|
-
const { data, isLoading, error } = useQuery15({
|
|
1193
|
-
...categoryId ? getJoomlaContentListOptions(api, categoryId, options.filters, cache) : {
|
|
1194
|
-
queryKey: getJoomlaContentListKey(""),
|
|
1195
|
-
/* v8 ignore next */
|
|
1196
|
-
queryFn: () => Promise.reject()
|
|
1197
|
-
},
|
|
1198
|
-
...options.queryFn ?? callbacks?.getJoomlaContentList ? {
|
|
1199
|
-
queryFn: options.queryFn ?? (() => callbacks.getJoomlaContentList(categoryId, options.filters))
|
|
1200
|
-
} : {},
|
|
1201
|
-
enabled: (options.enabled ?? true) && !!categoryId
|
|
1202
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1203
|
-
});
|
|
1204
|
-
const result = data || EMPTY_LIST;
|
|
1205
|
-
return {
|
|
1206
|
-
articles: result.data,
|
|
1207
|
-
total: result.total,
|
|
1208
|
-
count: result.count,
|
|
1209
|
-
totalResults: result.totalResults,
|
|
1210
|
-
message: result.message,
|
|
1211
|
-
status: result.status,
|
|
1212
|
-
result,
|
|
1213
|
-
isLoading,
|
|
1214
|
-
error
|
|
1215
|
-
};
|
|
1216
|
-
}
|
|
1217
|
-
|
|
1218
|
-
// src/hooks/use-joomla-menu.ts
|
|
1219
|
-
import { useQuery as useQuery16 } from "@tanstack/react-query";
|
|
1220
|
-
var EMPTY_LIST2 = { data: [], total: 0 };
|
|
1221
|
-
function useJoomlaMenu(options = {}) {
|
|
1222
|
-
const api = useAugurApiOptional();
|
|
1223
|
-
const callbacks = useAugurCallbacks();
|
|
1224
|
-
const cache = useAugurCache();
|
|
1225
|
-
const { data, isLoading, error } = useQuery16({
|
|
1226
|
-
...getJoomlaMenuOptions(api, options.filters, cache),
|
|
1227
|
-
...options.queryFn ?? callbacks?.getJoomlaMenu ? {
|
|
1228
|
-
queryFn: options.queryFn ?? (() => callbacks.getJoomlaMenu(options.filters))
|
|
1229
|
-
} : {},
|
|
1230
|
-
enabled: options.enabled ?? true
|
|
1231
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1232
|
-
});
|
|
1233
|
-
const result = data || EMPTY_LIST2;
|
|
1234
|
-
return {
|
|
1235
|
-
menuItems: result.data,
|
|
1236
|
-
total: result.total,
|
|
1237
|
-
count: result.count,
|
|
1238
|
-
totalResults: result.totalResults,
|
|
1239
|
-
message: result.message,
|
|
1240
|
-
status: result.status,
|
|
1241
|
-
result,
|
|
1242
|
-
isLoading,
|
|
1243
|
-
error
|
|
1244
|
-
};
|
|
1245
|
-
}
|
|
1246
|
-
|
|
1247
|
-
// src/hooks/use-joomla-menu-doc.ts
|
|
1248
|
-
import { useQuery as useQuery17 } from "@tanstack/react-query";
|
|
1249
|
-
function useJoomlaMenuDoc(menuId, options = {}) {
|
|
1250
|
-
const api = useAugurApiOptional();
|
|
1251
|
-
const callbacks = useAugurCallbacks();
|
|
1252
|
-
const cache = useAugurCache();
|
|
1253
|
-
const { data, isLoading, error } = useQuery17({
|
|
1254
|
-
...menuId ? getJoomlaMenuDocOptions(api, menuId, cache) : {
|
|
1255
|
-
queryKey: getJoomlaMenuDocKey(""),
|
|
1256
|
-
/* v8 ignore next */
|
|
1257
|
-
queryFn: () => Promise.reject()
|
|
1258
|
-
},
|
|
1259
|
-
...options.queryFn ?? callbacks?.getJoomlaMenuDoc ? { queryFn: options.queryFn ?? (() => callbacks.getJoomlaMenuDoc(menuId)) } : {},
|
|
1260
|
-
enabled: (options.enabled ?? true) && !!menuId
|
|
1261
|
-
});
|
|
1262
|
-
return {
|
|
1263
|
-
menuItem: data ?? null,
|
|
1264
|
-
isLoading,
|
|
1265
|
-
error
|
|
1266
|
-
};
|
|
1267
|
-
}
|
|
1268
|
-
|
|
1269
|
-
// src/hooks/use-customer-orders.ts
|
|
1270
|
-
import { useQuery as useQuery18 } from "@tanstack/react-query";
|
|
1271
|
-
var EMPTY_LIST3 = { data: [], total: 0 };
|
|
1272
|
-
function useCustomerOrders(customerId, params, options = {}) {
|
|
1273
|
-
const callbacks = useAugurCallbacks();
|
|
1274
|
-
const auth = useAugurAuth();
|
|
1275
|
-
const site = useAugurSite();
|
|
1276
|
-
const effectiveCustomerId = customerId ?? auth?.customerId ?? site?.defaults?.customerId;
|
|
1277
|
-
const resolvedQueryFn = options.queryFn ?? (callbacks?.getCustomerOrders ? () => callbacks.getCustomerOrders(effectiveCustomerId, params) : void 0);
|
|
1278
|
-
const enabled = (options.enabled ?? true) && !!effectiveCustomerId && !!resolvedQueryFn;
|
|
1279
|
-
const { data, isLoading, error } = useQuery18({
|
|
1280
|
-
queryKey: getCustomerOrdersKey(effectiveCustomerId, params),
|
|
1281
|
-
queryFn: resolvedQueryFn,
|
|
1282
|
-
enabled
|
|
1283
|
-
});
|
|
1284
|
-
const result = data || EMPTY_LIST3;
|
|
1285
|
-
return {
|
|
1286
|
-
orders: result.data,
|
|
1287
|
-
total: result.total,
|
|
1288
|
-
count: result.count,
|
|
1289
|
-
totalResults: result.totalResults,
|
|
1290
|
-
message: result.message,
|
|
1291
|
-
status: result.status,
|
|
1292
|
-
result,
|
|
1293
|
-
isLoading,
|
|
1294
|
-
error
|
|
1295
|
-
};
|
|
1296
|
-
}
|
|
1297
|
-
function useOrderDetail(customerId, orderId, options = {}) {
|
|
1298
|
-
const callbacks = useAugurCallbacks();
|
|
1299
|
-
const auth = useAugurAuth();
|
|
1300
|
-
const site = useAugurSite();
|
|
1301
|
-
const effectiveCustomerId = customerId ?? auth?.customerId ?? site?.defaults?.customerId;
|
|
1302
|
-
const resolvedQueryFn = options.queryFn ?? (callbacks?.getCustomerOrderDetail ? () => callbacks.getCustomerOrderDetail(effectiveCustomerId, orderId) : void 0);
|
|
1303
|
-
const enabled = (options.enabled ?? true) && !!effectiveCustomerId && !!orderId && !!resolvedQueryFn;
|
|
1304
|
-
const { data, isLoading, error } = useQuery18({
|
|
1305
|
-
queryKey: getCustomerOrderDetailKey(effectiveCustomerId, orderId),
|
|
1306
|
-
queryFn: resolvedQueryFn,
|
|
1307
|
-
enabled
|
|
1308
|
-
});
|
|
1309
|
-
return {
|
|
1310
|
-
order: data || null,
|
|
1311
|
-
isLoading,
|
|
1312
|
-
error
|
|
1313
|
-
};
|
|
1314
|
-
}
|
|
1315
|
-
|
|
1316
|
-
// src/hooks/use-customer-invoices.ts
|
|
1317
|
-
import { useQuery as useQuery19 } from "@tanstack/react-query";
|
|
1318
|
-
var EMPTY_LIST4 = { data: [], total: 0 };
|
|
1319
|
-
function useCustomerInvoices(customerId, params, options = {}) {
|
|
1320
|
-
const callbacks = useAugurCallbacks();
|
|
1321
|
-
const auth = useAugurAuth();
|
|
1322
|
-
const site = useAugurSite();
|
|
1323
|
-
const effectiveCustomerId = customerId ?? auth?.customerId ?? site?.defaults?.customerId;
|
|
1324
|
-
const resolvedQueryFn = options.queryFn ?? (callbacks?.getCustomerInvoices ? () => callbacks.getCustomerInvoices(effectiveCustomerId, params) : void 0);
|
|
1325
|
-
const enabled = (options.enabled ?? true) && !!effectiveCustomerId && !!resolvedQueryFn;
|
|
1326
|
-
const { data, isLoading, error } = useQuery19({
|
|
1327
|
-
queryKey: getCustomerInvoicesKey(effectiveCustomerId, params),
|
|
1328
|
-
queryFn: resolvedQueryFn,
|
|
1329
|
-
enabled
|
|
1330
|
-
});
|
|
1331
|
-
const result = data || EMPTY_LIST4;
|
|
1332
|
-
return {
|
|
1333
|
-
invoices: result.data,
|
|
1334
|
-
total: result.total,
|
|
1335
|
-
count: result.count,
|
|
1336
|
-
totalResults: result.totalResults,
|
|
1337
|
-
message: result.message,
|
|
1338
|
-
status: result.status,
|
|
1339
|
-
result,
|
|
1340
|
-
isLoading,
|
|
1341
|
-
error
|
|
1342
|
-
};
|
|
1343
|
-
}
|
|
1344
|
-
function useInvoiceDetail(customerId, invoiceNo, options = {}) {
|
|
1345
|
-
const callbacks = useAugurCallbacks();
|
|
1346
|
-
const auth = useAugurAuth();
|
|
1347
|
-
const site = useAugurSite();
|
|
1348
|
-
const effectiveCustomerId = customerId ?? auth?.customerId ?? site?.defaults?.customerId;
|
|
1349
|
-
const resolvedQueryFn = options.queryFn ?? (callbacks?.getCustomerInvoiceDetail ? () => callbacks.getCustomerInvoiceDetail(effectiveCustomerId, invoiceNo) : void 0);
|
|
1350
|
-
const enabled = (options.enabled ?? true) && !!effectiveCustomerId && !!invoiceNo && !!resolvedQueryFn;
|
|
1351
|
-
const { data, isLoading, error } = useQuery19({
|
|
1352
|
-
queryKey: getCustomerInvoiceDetailKey(effectiveCustomerId, invoiceNo),
|
|
1353
|
-
queryFn: resolvedQueryFn,
|
|
1354
|
-
enabled
|
|
1355
|
-
});
|
|
1356
|
-
return {
|
|
1357
|
-
invoice: data || null,
|
|
1358
|
-
isLoading,
|
|
1359
|
-
error
|
|
1360
|
-
};
|
|
1361
|
-
}
|
|
1362
|
-
|
|
1363
|
-
// src/hooks/use-customer-quotes.ts
|
|
1364
|
-
import { useQuery as useQuery20 } from "@tanstack/react-query";
|
|
1365
|
-
var EMPTY_LIST5 = { data: [], total: 0 };
|
|
1366
|
-
function useCustomerQuotes(customerId, params, options = {}) {
|
|
1367
|
-
const callbacks = useAugurCallbacks();
|
|
1368
|
-
const auth = useAugurAuth();
|
|
1369
|
-
const site = useAugurSite();
|
|
1370
|
-
const effectiveCustomerId = customerId ?? auth?.customerId ?? site?.defaults?.customerId;
|
|
1371
|
-
const resolvedQueryFn = options.queryFn ?? (callbacks?.getCustomerQuotes ? () => callbacks.getCustomerQuotes(effectiveCustomerId, params) : void 0);
|
|
1372
|
-
const enabled = (options.enabled ?? true) && !!effectiveCustomerId && !!resolvedQueryFn;
|
|
1373
|
-
const { data, isLoading, error } = useQuery20({
|
|
1374
|
-
queryKey: getCustomerQuotesKey(effectiveCustomerId, params),
|
|
1375
|
-
queryFn: resolvedQueryFn,
|
|
1376
|
-
enabled
|
|
1377
|
-
});
|
|
1378
|
-
const result = data || EMPTY_LIST5;
|
|
1379
|
-
return {
|
|
1380
|
-
quotes: result.data,
|
|
1381
|
-
total: result.total,
|
|
1382
|
-
count: result.count,
|
|
1383
|
-
totalResults: result.totalResults,
|
|
1384
|
-
message: result.message,
|
|
1385
|
-
status: result.status,
|
|
1386
|
-
result,
|
|
1387
|
-
isLoading,
|
|
1388
|
-
error
|
|
1389
|
-
};
|
|
1390
|
-
}
|
|
1391
|
-
function useQuoteDetail(customerId, quoteNo, options = {}) {
|
|
1392
|
-
const callbacks = useAugurCallbacks();
|
|
1393
|
-
const auth = useAugurAuth();
|
|
1394
|
-
const site = useAugurSite();
|
|
1395
|
-
const effectiveCustomerId = customerId ?? auth?.customerId ?? site?.defaults?.customerId;
|
|
1396
|
-
const resolvedQueryFn = options.queryFn ?? (callbacks?.getCustomerQuoteDetail ? () => callbacks.getCustomerQuoteDetail(effectiveCustomerId, quoteNo) : void 0);
|
|
1397
|
-
const enabled = (options.enabled ?? true) && !!effectiveCustomerId && !!quoteNo && !!resolvedQueryFn;
|
|
1398
|
-
const { data, isLoading, error } = useQuery20({
|
|
1399
|
-
queryKey: getCustomerQuoteDetailKey(effectiveCustomerId, quoteNo),
|
|
1400
|
-
queryFn: resolvedQueryFn,
|
|
1401
|
-
enabled
|
|
1402
|
-
});
|
|
1403
|
-
return {
|
|
1404
|
-
quote: data || null,
|
|
1405
|
-
isLoading,
|
|
1406
|
-
error
|
|
1407
|
-
};
|
|
1408
|
-
}
|
|
1409
|
-
|
|
1410
|
-
// src/create-site-hooks.ts
|
|
1411
|
-
import { createElement } from "react";
|
|
1412
|
-
function createSiteHooks(config = {}) {
|
|
1413
|
-
const { callbacks, defaultCustomerId, cache, imageConfig } = config;
|
|
1414
|
-
function Provider({ api, auth, children }) {
|
|
1415
|
-
const mergedAuth = {
|
|
1416
|
-
status: auth?.status ?? "unauthenticated",
|
|
1417
|
-
customerId: auth?.customerId,
|
|
1418
|
-
userId: auth?.userId,
|
|
1419
|
-
cartHdrUid: auth?.cartHdrUid
|
|
1420
|
-
};
|
|
1421
|
-
return createElement(AugurHooksProvider, {
|
|
1422
|
-
api,
|
|
1423
|
-
callbacks,
|
|
1424
|
-
auth: mergedAuth,
|
|
1425
|
-
cache,
|
|
1426
|
-
site: defaultCustomerId ? { name: "", defaults: { customerId: defaultCustomerId } } : void 0,
|
|
1427
|
-
children
|
|
1428
|
-
});
|
|
1429
|
-
}
|
|
1430
|
-
Provider.displayName = "AugurSiteProvider";
|
|
1431
|
-
return {
|
|
1432
|
-
Provider,
|
|
1433
|
-
// Hooks -- pricing
|
|
1434
|
-
useItemPrice,
|
|
1435
|
-
useCartPricing,
|
|
1436
|
-
// Hooks -- inventory
|
|
1437
|
-
useInvMast,
|
|
1438
|
-
useInvMastDoc,
|
|
1439
|
-
useBatchInvMastDoc,
|
|
1440
|
-
useInvMastStock,
|
|
1441
|
-
// Hooks -- items & categories
|
|
1442
|
-
useItemCategory,
|
|
1443
|
-
useProductCategory,
|
|
1444
|
-
useItemDetails,
|
|
1445
|
-
useItemAttributes,
|
|
1446
|
-
// Hooks -- search
|
|
1447
|
-
useProductSearch,
|
|
1448
|
-
useSearchSuggestions,
|
|
1449
|
-
// Hooks -- cart
|
|
1450
|
-
useCartActions,
|
|
1451
|
-
useCartInitialization,
|
|
1452
|
-
// Hooks -- pagination & infinite scroll
|
|
1453
|
-
usePaginationPrefetch,
|
|
1454
|
-
useCategoryItemsInfinite,
|
|
1455
|
-
useItemSearchInfinite,
|
|
1456
|
-
// Hooks -- Joomla
|
|
1457
|
-
useJoomlaContent,
|
|
1458
|
-
useJoomlaContentList,
|
|
1459
|
-
useJoomlaMenu,
|
|
1460
|
-
useJoomlaMenuDoc,
|
|
1461
|
-
// Hooks -- customer
|
|
1462
|
-
useCustomerOrders,
|
|
1463
|
-
useOrderDetail,
|
|
1464
|
-
useCustomerInvoices,
|
|
1465
|
-
useInvoiceDetail,
|
|
1466
|
-
useCustomerQuotes,
|
|
1467
|
-
useQuoteDetail,
|
|
1468
|
-
// Hooks -- utilities
|
|
1469
|
-
useDebounce,
|
|
1470
|
-
useFormatPrice,
|
|
1471
|
-
// Hooks -- images
|
|
1472
|
-
useImageWithFallback: (imagePath, options) => {
|
|
1473
|
-
if (!imageConfig) {
|
|
1474
|
-
throw new Error("useImageWithFallback requires imageConfig in createSiteHooks config");
|
|
1475
|
-
}
|
|
1476
|
-
return useImageWithFallback(imageConfig, imagePath, options);
|
|
1477
|
-
}
|
|
1478
|
-
};
|
|
1479
|
-
}
|
|
1480
|
-
|
|
1481
780
|
// src/persistence/use-persistence.ts
|
|
1482
|
-
import { useState as useState3, useEffect as useEffect5, useMemo as
|
|
781
|
+
import { useState as useState3, useEffect as useEffect5, useMemo as useMemo5 } from "react";
|
|
1483
782
|
|
|
1484
783
|
// src/persistence/serializer.ts
|
|
1485
784
|
function serialize(data) {
|
|
@@ -1624,7 +923,7 @@ function useAugurPersistence(config) {
|
|
|
1624
923
|
useStorageMonitor(config);
|
|
1625
924
|
const isDev = typeof process !== "undefined" && process.env?.["NODE_ENV"] === "development";
|
|
1626
925
|
const { persistableKeys } = config;
|
|
1627
|
-
const dehydrateOptions =
|
|
926
|
+
const dehydrateOptions = useMemo5(
|
|
1628
927
|
() => ({
|
|
1629
928
|
shouldDehydrateQuery: (query) => {
|
|
1630
929
|
const key = query.queryKey;
|
|
@@ -1644,49 +943,8 @@ function useAugurPersistence(config) {
|
|
|
1644
943
|
}
|
|
1645
944
|
export {
|
|
1646
945
|
AugurHooksProvider,
|
|
1647
|
-
createSiteHooks,
|
|
1648
946
|
executeBatchQuery,
|
|
1649
|
-
getBatchInvMastDocKey,
|
|
1650
|
-
getBatchInvMastDocOptions,
|
|
1651
947
|
getCartPricingQueryOptions,
|
|
1652
|
-
getCategoryItemsInfiniteKey,
|
|
1653
|
-
getCategoryItemsInfiniteOptions,
|
|
1654
|
-
getCustomerInvoiceDetailKey,
|
|
1655
|
-
getCustomerInvoicesKey,
|
|
1656
|
-
getCustomerOrderDetailKey,
|
|
1657
|
-
getCustomerOrdersKey,
|
|
1658
|
-
getCustomerQuoteDetailKey,
|
|
1659
|
-
getCustomerQuotesKey,
|
|
1660
|
-
getInvMastDocKey,
|
|
1661
|
-
getInvMastDocOptions,
|
|
1662
|
-
getInvMastKey,
|
|
1663
|
-
getInvMastOptions,
|
|
1664
|
-
getInvMastStockKey,
|
|
1665
|
-
getInvMastStockOptions,
|
|
1666
|
-
getItemAttributesKey,
|
|
1667
|
-
getItemAttributesOptions,
|
|
1668
|
-
getItemCategoryKey,
|
|
1669
|
-
getItemCategoryOptions,
|
|
1670
|
-
getItemDetailsKey,
|
|
1671
|
-
getItemDetailsOptions,
|
|
1672
|
-
getItemPriceKey,
|
|
1673
|
-
getItemPriceOptions,
|
|
1674
|
-
getItemSearchInfiniteKey,
|
|
1675
|
-
getItemSearchInfiniteOptions,
|
|
1676
|
-
getJoomlaContentKey,
|
|
1677
|
-
getJoomlaContentListKey,
|
|
1678
|
-
getJoomlaContentListOptions,
|
|
1679
|
-
getJoomlaContentOptions,
|
|
1680
|
-
getJoomlaMenuDocKey,
|
|
1681
|
-
getJoomlaMenuDocOptions,
|
|
1682
|
-
getJoomlaMenuKey,
|
|
1683
|
-
getJoomlaMenuOptions,
|
|
1684
|
-
getProductCategoryKey,
|
|
1685
|
-
getProductCategoryOptions,
|
|
1686
|
-
getProductSearchKey,
|
|
1687
|
-
getProductSearchOptions,
|
|
1688
|
-
getSearchSuggestionsKey,
|
|
1689
|
-
getSearchSuggestionsOptions,
|
|
1690
948
|
getStockKey,
|
|
1691
949
|
getStockOptions,
|
|
1692
950
|
useAugurApi,
|
|
@@ -1696,7 +954,6 @@ export {
|
|
|
1696
954
|
useAugurOptions,
|
|
1697
955
|
useAugurPersistence,
|
|
1698
956
|
useAugurSite,
|
|
1699
|
-
useBatchInvMastDoc,
|
|
1700
957
|
useCartActions,
|
|
1701
958
|
useCartHdrUid,
|
|
1702
959
|
useCartInitialization,
|
|
@@ -1705,34 +962,12 @@ export {
|
|
|
1705
962
|
useCartPricing,
|
|
1706
963
|
useCartQuantityTotal,
|
|
1707
964
|
useCartStore,
|
|
1708
|
-
useCategoryItemsInfinite,
|
|
1709
965
|
useClearCart,
|
|
1710
|
-
useCustomerInvoices,
|
|
1711
|
-
useCustomerOrders,
|
|
1712
|
-
useCustomerQuotes,
|
|
1713
966
|
useDebounce,
|
|
1714
967
|
useFormatPrice,
|
|
1715
|
-
useInvMast,
|
|
1716
|
-
useInvMastDoc,
|
|
1717
|
-
useInvMastStock,
|
|
1718
|
-
useInvoiceDetail,
|
|
1719
|
-
useItemAttributes,
|
|
1720
|
-
useItemCategory,
|
|
1721
|
-
useItemDetails,
|
|
1722
968
|
useItemFiltersStore,
|
|
1723
|
-
useItemPrice,
|
|
1724
|
-
useItemSearchInfinite,
|
|
1725
|
-
useJoomlaContent,
|
|
1726
|
-
useJoomlaContentList,
|
|
1727
|
-
useJoomlaMenu,
|
|
1728
|
-
useJoomlaMenuDoc,
|
|
1729
|
-
useOrderDetail,
|
|
1730
969
|
usePaginationPrefetch,
|
|
1731
970
|
usePaymentFlow,
|
|
1732
|
-
useProductCategory,
|
|
1733
|
-
useProductSearch,
|
|
1734
|
-
useQuoteDetail,
|
|
1735
|
-
useSearchSuggestions,
|
|
1736
971
|
useSetCartHdrUid,
|
|
1737
972
|
useSetCartLines,
|
|
1738
973
|
useStock
|