@simpleapps-com/augur-hooks 0.1.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,4 +1,35 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/provider.tsx
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+ var _chunkMRQREI4Lcjs = require('./chunk-MRQREI4L.cjs');
31
+
32
+ // src/provider.tsx
2
33
  var _react = require('react');
3
34
  var _jsxruntime = require('react/jsx-runtime');
4
35
  var AugurApiContext = _react.createContext.call(void 0, null);
@@ -102,31 +133,9 @@ function useFormatPrice(locale = "en-US", currency = "USD") {
102
133
 
103
134
  // src/hooks/use-item-price.ts
104
135
  var _reactquery = require('@tanstack/react-query');
105
- var _augurutils = require('@simpleapps-com/augur-utils');
106
- var PRICE_CACHE_OPTIONS = {
107
- ..._augurutils.CACHE_CONFIG.SEMI_STATIC,
108
- refetchOnReconnect: true,
109
- refetchOnWindowFocus: false,
110
- meta: { persist: true }
111
- };
112
- var getItemPriceKey = (itemId, customerId, quantity = 1) => {
113
- return ["price", _optionalChain([itemId, 'optionalAccess', _ => _.toUpperCase, 'call', _2 => _2()]) || "", customerId, quantity];
114
- };
115
- var getItemPriceOptions = (api, itemId, customerId, quantity = 1) => ({
116
- queryKey: getItemPriceKey(itemId, customerId, quantity),
117
- queryFn: async () => {
118
- const response = await api.pricing.priceEngine.get({
119
- itemId: _optionalChain([itemId, 'optionalAccess', _3 => _3.toUpperCase, 'call', _4 => _4()]) || "",
120
- customerId: Number(customerId),
121
- quantity
122
- });
123
- return response.data;
124
- },
125
- ...PRICE_CACHE_OPTIONS
126
- });
127
136
  function useItemPrice(itemId, customerId, quantity = 1, options = {}) {
128
137
  const api = useAugurApi();
129
- const defaultOptions = getItemPriceOptions(api, itemId, customerId, quantity);
138
+ const defaultOptions = _chunkMRQREI4Lcjs.getItemPriceOptions.call(void 0, api, itemId, customerId, quantity);
130
139
  return _reactquery.useQuery.call(void 0, {
131
140
  ...defaultOptions,
132
141
  ...options.queryFn ? { queryFn: options.queryFn } : {},
@@ -137,30 +146,9 @@ function useItemPrice(itemId, customerId, quantity = 1, options = {}) {
137
146
 
138
147
  // src/hooks/use-inv-mast-doc.ts
139
148
 
140
-
141
- var INV_MAST_DOC_CACHE_OPTIONS = _augurutils.CACHE_CONFIG.STATIC;
142
- var getInvMastDocKey = (invMastUid, itemId, includePricing) => {
143
- return [
144
- "invMastDoc",
145
- invMastUid,
146
- itemId.toUpperCase(),
147
- includePricing
148
- ];
149
- };
150
- var getInvMastDocOptions = (api, invMastUid, itemId, includePricing) => ({
151
- queryKey: getInvMastDocKey(invMastUid, itemId, includePricing),
152
- queryFn: async () => {
153
- const response = await api.items.invMast.doc.list(invMastUid, {
154
- includePricing
155
- });
156
- if (!response.data) throw new Error("Item not found");
157
- return response.data;
158
- },
159
- ...INV_MAST_DOC_CACHE_OPTIONS
160
- });
161
149
  function useInvMastDoc(invMastUid, itemId, options = {}) {
162
150
  const api = useAugurApi();
163
- const queryOpts = getInvMastDocOptions(
151
+ const queryOpts = _chunkMRQREI4Lcjs.getInvMastDocOptions.call(void 0,
164
152
  api,
165
153
  invMastUid,
166
154
  itemId,
@@ -177,26 +165,9 @@ function useInvMastDoc(invMastUid, itemId, options = {}) {
177
165
 
178
166
  // src/hooks/use-item-category.ts
179
167
 
180
-
181
- var CATEGORY_CACHE_OPTIONS = _augurutils.CACHE_CONFIG.STATIC;
182
- var getItemCategoryKey = (itemCategoryUid, apiOptions) => {
183
- return ["itemCategory", itemCategoryUid, apiOptions];
184
- };
185
- var getItemCategoryOptions = (api, itemCategoryUid, apiOptions) => ({
186
- queryKey: getItemCategoryKey(itemCategoryUid, apiOptions),
187
- queryFn: async () => {
188
- const response = await api.items.itemCategory.get(
189
- itemCategoryUid,
190
- apiOptions
191
- );
192
- if (!response.data) throw new Error("Item category not found");
193
- return response.data;
194
- },
195
- ...CATEGORY_CACHE_OPTIONS
196
- });
197
168
  function useItemCategory(itemCategoryUid, options = {}) {
198
169
  const api = useAugurApi();
199
- const queryOpts = getItemCategoryOptions(
170
+ const queryOpts = _chunkMRQREI4Lcjs.getItemCategoryOptions.call(void 0,
200
171
  api,
201
172
  itemCategoryUid,
202
173
  options.apiOptions
@@ -211,23 +182,9 @@ function useItemCategory(itemCategoryUid, options = {}) {
211
182
 
212
183
  // src/hooks/use-inv-mast.ts
213
184
 
214
-
215
- var INV_MAST_CACHE_OPTIONS = _augurutils.CACHE_CONFIG.STATIC;
216
- var getInvMastKey = (invMastUid, itemId) => {
217
- return ["invMast", invMastUid, itemId.toUpperCase()];
218
- };
219
- var getInvMastOptions = (api, invMastUid, itemId) => ({
220
- queryKey: getInvMastKey(invMastUid, itemId),
221
- queryFn: async () => {
222
- const response = await api.items.invMast.get(invMastUid);
223
- if (!response.data) throw new Error("Item not found");
224
- return response.data;
225
- },
226
- ...INV_MAST_CACHE_OPTIONS
227
- });
228
185
  function useInvMast(invMastUid, itemId, options = {}) {
229
186
  const api = useAugurApi();
230
- const queryOpts = getInvMastOptions(api, invMastUid, itemId);
187
+ const queryOpts = _chunkMRQREI4Lcjs.getInvMastOptions.call(void 0, api, invMastUid, itemId);
231
188
  const { data, isLoading, error } = _reactquery.useQuery.call(void 0, {
232
189
  ...queryOpts,
233
190
  ...options.queryFn ? { queryFn: options.queryFn } : {},
@@ -238,25 +195,9 @@ function useInvMast(invMastUid, itemId, options = {}) {
238
195
 
239
196
  // src/hooks/use-inv-mast-stock.ts
240
197
 
241
-
242
- var getInvMastStockKey = (invMastUid) => {
243
- return ["invMastStock", invMastUid];
244
- };
245
- var getInvMastStockOptions = (api, invMastUid) => ({
246
- queryKey: getInvMastStockKey(invMastUid),
247
- queryFn: async () => {
248
- const response = await api.items.invMast.stock.list(Number(invMastUid));
249
- const stockData = _nullishCoalesce(_optionalChain([response, 'access', _5 => _5.data, 'optionalAccess', _6 => _6.stockData]), () => ( []));
250
- return stockData.reduce(
251
- (qty, stock) => qty + stock.qtyOnHand,
252
- 0
253
- );
254
- },
255
- ..._augurutils.CACHE_CONFIG.SEMI_STATIC
256
- });
257
198
  function useInvMastStock(invMastUid, options = {}) {
258
199
  const api = useAugurApi();
259
- const queryOpts = getInvMastStockOptions(api, invMastUid);
200
+ const queryOpts = _chunkMRQREI4Lcjs.getInvMastStockOptions.call(void 0, api, invMastUid);
260
201
  const { data, isLoading, error } = _reactquery.useQuery.call(void 0, {
261
202
  ...queryOpts,
262
203
  ...options.queryFn ? { queryFn: options.queryFn } : {},
@@ -275,25 +216,11 @@ function useInvMastStock(invMastUid, options = {}) {
275
216
 
276
217
  // src/hooks/use-product-category.ts
277
218
 
278
-
279
- var getProductCategoryKey = (itemCategoryUid) => {
280
- return ["productCategory", itemCategoryUid];
281
- };
282
- var getProductCategoryOptions = (api, itemCategoryUid) => ({
283
- queryKey: getProductCategoryKey(itemCategoryUid),
284
- queryFn: async () => {
285
- const response = await api.items.itemCategory.get(
286
- Number(itemCategoryUid)
287
- );
288
- return response.data;
289
- },
290
- ..._augurutils.CACHE_CONFIG.STATIC
291
- });
292
219
  function useProductCategory(itemCategoryUid, options = {}) {
293
220
  const api = useAugurApi();
294
221
  const { data, isLoading, error } = _reactquery.useQuery.call(void 0, {
295
- ...itemCategoryUid ? getProductCategoryOptions(api, itemCategoryUid) : {
296
- queryKey: getProductCategoryKey(null),
222
+ ...itemCategoryUid ? _chunkMRQREI4Lcjs.getProductCategoryOptions.call(void 0, api, itemCategoryUid) : {
223
+ queryKey: _chunkMRQREI4Lcjs.getProductCategoryKey.call(void 0, null),
297
224
  /* v8 ignore next */
298
225
  queryFn: () => Promise.reject()
299
226
  },
@@ -305,10 +232,10 @@ function useProductCategory(itemCategoryUid, options = {}) {
305
232
  /* v8 ignore stop */
306
233
  });
307
234
  return {
308
- childrenTotal: _nullishCoalesce(_optionalChain([data, 'optionalAccess', _7 => _7.childrenTotal]), () => ( 0)),
309
- itemCategoryDesc: _nullishCoalesce(_optionalChain([data, 'optionalAccess', _8 => _8.itemCategoryDesc]), () => ( "")),
310
- productCategories: _nullishCoalesce(_optionalChain([data, 'optionalAccess', _9 => _9.children]), () => ( null)),
311
- productCategoryImage: _nullishCoalesce(_optionalChain([data, 'optionalAccess', _10 => _10.categoryImage]), () => ( null)),
235
+ childrenTotal: _nullishCoalesce(_optionalChain([data, 'optionalAccess', _ => _.childrenTotal]), () => ( 0)),
236
+ itemCategoryDesc: _nullishCoalesce(_optionalChain([data, 'optionalAccess', _2 => _2.itemCategoryDesc]), () => ( "")),
237
+ productCategories: _nullishCoalesce(_optionalChain([data, 'optionalAccess', _3 => _3.children]), () => ( null)),
238
+ productCategoryImage: _nullishCoalesce(_optionalChain([data, 'optionalAccess', _4 => _4.categoryImage]), () => ( null)),
312
239
  loading: isLoading,
313
240
  error
314
241
  };
@@ -316,24 +243,11 @@ function useProductCategory(itemCategoryUid, options = {}) {
316
243
 
317
244
  // src/hooks/use-item-details.ts
318
245
 
319
-
320
- var getItemDetailsKey = (itemId) => {
321
- return ["itemDetails", itemId];
322
- };
323
- var getItemDetailsOptions = (api, itemId) => ({
324
- queryKey: getItemDetailsKey(itemId),
325
- queryFn: async () => {
326
- const response = await api.items.invMast.doc.list(Number(itemId));
327
- if (!response.data) throw new Error("Item not found");
328
- return response.data;
329
- },
330
- ..._augurutils.CACHE_CONFIG.STATIC
331
- });
332
246
  function useItemDetails(itemId, options = {}) {
333
247
  const api = useAugurApi();
334
248
  const { data, isLoading, error } = _reactquery.useQuery.call(void 0, {
335
- ...itemId ? getItemDetailsOptions(api, itemId) : {
336
- queryKey: getItemDetailsKey(""),
249
+ ...itemId ? _chunkMRQREI4Lcjs.getItemDetailsOptions.call(void 0, api, itemId) : {
250
+ queryKey: _chunkMRQREI4Lcjs.getItemDetailsKey.call(void 0, ""),
337
251
  /* v8 ignore next */
338
252
  queryFn: () => Promise.reject()
339
253
  },
@@ -344,7 +258,7 @@ function useItemDetails(itemId, options = {}) {
344
258
  retryDelay: (attemptIndex) => Math.min(1e3 * 2 ** attemptIndex, 1e4)
345
259
  /* v8 ignore stop */
346
260
  });
347
- const categoryList = _nullishCoalesce(_optionalChain([data, 'optionalAccess', _11 => _11.categoryList]), () => ( []));
261
+ const categoryList = _nullishCoalesce(_optionalChain([data, 'optionalAccess', _5 => _5.categoryList]), () => ( []));
348
262
  return {
349
263
  itemCategoryUid: categoryList.length > 0 ? categoryList[categoryList.length - 1] : null,
350
264
  itemDetails: _nullishCoalesce(data, () => ( null)),
@@ -355,27 +269,11 @@ function useItemDetails(itemId, options = {}) {
355
269
 
356
270
  // src/hooks/use-item-attributes.ts
357
271
 
358
-
359
- var getItemAttributesKey = (itemCategoryUid) => {
360
- return ["itemAttributes", itemCategoryUid];
361
- };
362
- var getItemAttributesOptions = (api, itemCategoryUid) => ({
363
- queryKey: getItemAttributesKey(itemCategoryUid),
364
- queryFn: async () => {
365
- const response = await api.openSearch.itemSearch.attributes.list({
366
- q: "",
367
- searchType: "query",
368
- classId5List: String(itemCategoryUid)
369
- });
370
- return response.data;
371
- },
372
- ..._augurutils.CACHE_CONFIG.STATIC
373
- });
374
272
  function useItemAttributes(itemCategoryUid, options = {}) {
375
273
  const api = useAugurApi();
376
274
  const { data, isLoading, error } = _reactquery.useQuery.call(void 0, {
377
- ...itemCategoryUid ? getItemAttributesOptions(api, itemCategoryUid) : {
378
- queryKey: getItemAttributesKey(null),
275
+ ...itemCategoryUid ? _chunkMRQREI4Lcjs.getItemAttributesOptions.call(void 0, api, itemCategoryUid) : {
276
+ queryKey: _chunkMRQREI4Lcjs.getItemAttributesKey.call(void 0, null),
379
277
  /* v8 ignore next */
380
278
  queryFn: () => Promise.reject()
381
279
  },
@@ -387,7 +285,7 @@ function useItemAttributes(itemCategoryUid, options = {}) {
387
285
  /* v8 ignore stop */
388
286
  });
389
287
  return {
390
- attributes: _nullishCoalesce(_optionalChain([data, 'optionalAccess', _12 => _12.attributes]), () => ( null)),
288
+ attributes: _nullishCoalesce(_optionalChain([data, 'optionalAccess', _6 => _6.attributes]), () => ( null)),
391
289
  loading: isLoading,
392
290
  error
393
291
  };
@@ -395,35 +293,9 @@ function useItemAttributes(itemCategoryUid, options = {}) {
395
293
 
396
294
  // src/hooks/use-product-search.ts
397
295
 
398
-
399
- var getProductSearchKey = (pageData) => {
400
- return [
401
- "productSearch",
402
- pageData.q,
403
- pageData.limit,
404
- pageData.offset,
405
- pageData.sortBy,
406
- pageData.itemCategoryUid
407
- ];
408
- };
409
- var getProductSearchOptions = (api, pageData) => ({
410
- queryKey: getProductSearchKey(pageData),
411
- queryFn: async () => {
412
- const response = await api.openSearch.itemSearch.list({
413
- q: pageData.q,
414
- searchType: "query",
415
- size: pageData.limit,
416
- from: pageData.offset,
417
- classId5List: pageData.itemCategoryUid ? String(pageData.itemCategoryUid) : void 0,
418
- filters: pageData.filters ? JSON.stringify(pageData.filters) : void 0
419
- });
420
- return response.data;
421
- },
422
- ..._augurutils.CACHE_CONFIG.SEMI_STATIC
423
- });
424
296
  function useProductSearch(pageData, options = {}) {
425
297
  const api = useAugurApi();
426
- const defaultOptions = getProductSearchOptions(api, pageData);
298
+ const defaultOptions = _chunkMRQREI4Lcjs.getProductSearchOptions.call(void 0, api, pageData);
427
299
  const { data, isLoading, error } = _reactquery.useQuery.call(void 0, {
428
300
  ...defaultOptions,
429
301
  ...options.queryFn ? { queryFn: options.queryFn } : {},
@@ -433,8 +305,8 @@ function useProductSearch(pageData, options = {}) {
433
305
  /* v8 ignore stop */
434
306
  });
435
307
  return {
436
- productItems: _nullishCoalesce(_optionalChain([data, 'optionalAccess', _13 => _13.items]), () => ( null)),
437
- total: _nullishCoalesce(_optionalChain([data, 'optionalAccess', _14 => _14.totalResults]), () => ( 0)),
308
+ productItems: _nullishCoalesce(_optionalChain([data, 'optionalAccess', _7 => _7.items]), () => ( null)),
309
+ total: _nullishCoalesce(_optionalChain([data, 'optionalAccess', _8 => _8.totalResults]), () => ( 0)),
438
310
  loading: isLoading,
439
311
  error
440
312
  };
@@ -442,35 +314,20 @@ function useProductSearch(pageData, options = {}) {
442
314
 
443
315
  // src/hooks/use-search-suggestions.ts
444
316
 
445
-
446
- var SEARCH_SUGGESTIONS_CACHE_OPTIONS = _augurutils.CACHE_CONFIG.STATIC;
447
- var getSearchSuggestionsKey = (query, limit, offset) => {
448
- return ["searchSuggestions", query, limit, offset];
449
- };
450
- var getSearchSuggestionsOptions = (api, query, limit = 10, offset = 0) => ({
451
- queryKey: getSearchSuggestionsKey(query, limit, offset),
452
- queryFn: async () => {
453
- const response = await api.openSearch.suggestions.suggest.list({
454
- q: query
455
- });
456
- return response.data;
457
- },
458
- ...SEARCH_SUGGESTIONS_CACHE_OPTIONS
459
- });
460
317
  function useSearchSuggestions(query, options = {}) {
461
318
  const api = useAugurApi();
462
319
  const limit = _nullishCoalesce(options.limit, () => ( 10));
463
320
  const offset = _nullishCoalesce(options.offset, () => ( 0));
464
321
  const enabled = (_nullishCoalesce(options.enabled, () => ( true))) && query.trim().length > 0;
465
- const defaultOptions = getSearchSuggestionsOptions(api, query, limit, offset);
322
+ const defaultOptions = _chunkMRQREI4Lcjs.getSearchSuggestionsOptions.call(void 0, api, query, limit, offset);
466
323
  const { data, isLoading, error } = _reactquery.useQuery.call(void 0, {
467
324
  ...defaultOptions,
468
325
  ...options.queryFn ? { queryFn: options.queryFn } : {},
469
326
  enabled
470
327
  });
471
328
  return {
472
- suggestions: _nullishCoalesce(_optionalChain([data, 'optionalAccess', _15 => _15.data]), () => ( [])),
473
- total: _nullishCoalesce(_optionalChain([data, 'optionalAccess', _16 => _16.total]), () => ( 0)),
329
+ suggestions: _nullishCoalesce(_optionalChain([data, 'optionalAccess', _9 => _9.data]), () => ( [])),
330
+ total: _nullishCoalesce(_optionalChain([data, 'optionalAccess', _10 => _10.total]), () => ( 0)),
474
331
  isLoading,
475
332
  error
476
333
  };
@@ -537,17 +394,17 @@ function useCartActions(callbacks) {
537
394
  ]);
538
395
  if (!success) throw new Error("Failed to add item to cart");
539
396
  invalidateCartCache();
540
- if (showToast && _optionalChain([notify, 'optionalAccess', _17 => _17.info])) {
397
+ if (showToast && _optionalChain([notify, 'optionalAccess', _11 => _11.info])) {
541
398
  notify.info(`${item.quantity} x ${itemId || "Item"} added to cart`);
542
399
  }
543
- _optionalChain([onSuccess, 'optionalCall', _18 => _18()]);
400
+ _optionalChain([onSuccess, 'optionalCall', _12 => _12()]);
544
401
  return true;
545
402
  } catch (error) {
546
403
  setCartLines(previousCartLines);
547
- if (showToast && _optionalChain([notify, 'optionalAccess', _19 => _19.error])) {
404
+ if (showToast && _optionalChain([notify, 'optionalAccess', _13 => _13.error])) {
548
405
  notify.error("Failed to add item to cart. Please try again.");
549
406
  }
550
- _optionalChain([onError, 'optionalCall', _20 => _20(error)]);
407
+ _optionalChain([onError, 'optionalCall', _14 => _14(error)]);
551
408
  return false;
552
409
  }
553
410
  },
@@ -566,14 +423,14 @@ function useCartActions(callbacks) {
566
423
  const success = await callbacks.updateCartLines(uid, updatedLines);
567
424
  if (!success) throw new Error("Failed to update quantity");
568
425
  invalidateCartCache();
569
- _optionalChain([onSuccess, 'optionalCall', _21 => _21()]);
426
+ _optionalChain([onSuccess, 'optionalCall', _15 => _15()]);
570
427
  return true;
571
428
  } catch (error) {
572
429
  setCartLines(previousCartLines);
573
- if (showToast && _optionalChain([notify, 'optionalAccess', _22 => _22.error])) {
430
+ if (showToast && _optionalChain([notify, 'optionalAccess', _16 => _16.error])) {
574
431
  notify.error("Failed to update quantity. Please try again.");
575
432
  }
576
- _optionalChain([onError, 'optionalCall', _23 => _23(error)]);
433
+ _optionalChain([onError, 'optionalCall', _17 => _17(error)]);
577
434
  return false;
578
435
  }
579
436
  },
@@ -592,17 +449,17 @@ function useCartActions(callbacks) {
592
449
  const success = await callbacks.updateCartLines(uid, zeroedLines);
593
450
  if (!success) throw new Error("Failed to remove item");
594
451
  invalidateCartCache();
595
- if (showToast && _optionalChain([notify, 'optionalAccess', _24 => _24.info])) {
452
+ if (showToast && _optionalChain([notify, 'optionalAccess', _18 => _18.info])) {
596
453
  notify.info(`${itemId || "Item"} removed from cart`);
597
454
  }
598
- _optionalChain([onSuccess, 'optionalCall', _25 => _25()]);
455
+ _optionalChain([onSuccess, 'optionalCall', _19 => _19()]);
599
456
  return true;
600
457
  } catch (error) {
601
458
  setCartLines(previousCartLines);
602
- if (showToast && _optionalChain([notify, 'optionalAccess', _26 => _26.error])) {
459
+ if (showToast && _optionalChain([notify, 'optionalAccess', _20 => _20.error])) {
603
460
  notify.error("Failed to remove item. Please try again.");
604
461
  }
605
- _optionalChain([onError, 'optionalCall', _27 => _27(error)]);
462
+ _optionalChain([onError, 'optionalCall', _21 => _21(error)]);
606
463
  return false;
607
464
  }
608
465
  },
@@ -618,17 +475,17 @@ function useCartActions(callbacks) {
618
475
  const success = await callbacks.deleteItemsFromCart(uid);
619
476
  if (!success) throw new Error("Failed to clear cart");
620
477
  invalidateCartCache();
621
- if (showToast && _optionalChain([notify, 'optionalAccess', _28 => _28.info])) {
478
+ if (showToast && _optionalChain([notify, 'optionalAccess', _22 => _22.info])) {
622
479
  notify.info("Cart cleared");
623
480
  }
624
- _optionalChain([onSuccess, 'optionalCall', _29 => _29()]);
481
+ _optionalChain([onSuccess, 'optionalCall', _23 => _23()]);
625
482
  return true;
626
483
  } catch (error) {
627
484
  setCartLines(previousCartLines);
628
- if (showToast && _optionalChain([notify, 'optionalAccess', _30 => _30.error])) {
485
+ if (showToast && _optionalChain([notify, 'optionalAccess', _24 => _24.error])) {
629
486
  notify.error("Failed to clear cart. Please try again.");
630
487
  }
631
- _optionalChain([onError, 'optionalCall', _31 => _31(error)]);
488
+ _optionalChain([onError, 'optionalCall', _25 => _25(error)]);
632
489
  return false;
633
490
  }
634
491
  },
@@ -642,7 +499,7 @@ function useCartActions(callbacks) {
642
499
  );
643
500
  const getItemQuantity = _react.useCallback.call(void 0,
644
501
  (invMastUid) => {
645
- return _nullishCoalesce(_optionalChain([cartLines, 'access', _32 => _32.find, 'call', _33 => _33((line) => line.invMastUid === invMastUid), 'optionalAccess', _34 => _34.quantity]), () => ( 0));
502
+ return _nullishCoalesce(_optionalChain([cartLines, 'access', _26 => _26.find, 'call', _27 => _27((line) => line.invMastUid === invMastUid), 'optionalAccess', _28 => _28.quantity]), () => ( 0));
646
503
  },
647
504
  [cartLines]
648
505
  );
@@ -662,7 +519,7 @@ function useCartActions(callbacks) {
662
519
  // src/hooks/use-cart-initialization.ts
663
520
 
664
521
 
665
-
522
+ var _augurutils = require('@simpleapps-com/augur-utils');
666
523
  var MAX_RETRY_ATTEMPTS = 7;
667
524
  var RETRY_DELAY_MS = 1e3;
668
525
  function useCartInitialization(session, callbacks) {
@@ -762,7 +619,7 @@ function useCartPricing(options = {}) {
762
619
  const { customerId } = options;
763
620
  const priceQueries = _reactquery.useQueries.call(void 0, {
764
621
  queries: cartLines.map((line) => ({
765
- ...getItemPriceOptions(api, line.itemId, customerId, line.quantity),
622
+ ..._chunkMRQREI4Lcjs.getItemPriceOptions.call(void 0, api, line.itemId, customerId, line.quantity),
766
623
  enabled: !!customerId && !!line.itemId
767
624
  }))
768
625
  });
@@ -770,7 +627,7 @@ function useCartPricing(options = {}) {
770
627
  const map = {};
771
628
  cartLines.forEach((line, index) => {
772
629
  const queryResult = priceQueries[index];
773
- if (_optionalChain([queryResult, 'optionalAccess', _35 => _35.data])) {
630
+ if (_optionalChain([queryResult, 'optionalAccess', _29 => _29.data])) {
774
631
  map[line.itemId.toUpperCase()] = {
775
632
  unitPrice: _nullishCoalesce(queryResult.data.unitPrice, () => ( 0)),
776
633
  priceData: queryResult.data
@@ -781,7 +638,7 @@ function useCartPricing(options = {}) {
781
638
  }, [cartLines, priceQueries]);
782
639
  const getUnitPrice = _react.useMemo.call(void 0, () => {
783
640
  return (itemId) => {
784
- return _nullishCoalesce(_optionalChain([prices, 'access', _36 => _36[_optionalChain([itemId, 'optionalAccess', _37 => _37.toUpperCase, 'call', _38 => _38()])], 'optionalAccess', _39 => _39.unitPrice]), () => ( 0));
641
+ return _nullishCoalesce(_optionalChain([prices, 'access', _30 => _30[_optionalChain([itemId, 'optionalAccess', _31 => _31.toUpperCase, 'call', _32 => _32()])], 'optionalAccess', _33 => _33.unitPrice]), () => ( 0));
785
642
  };
786
643
  }, [prices]);
787
644
  const getItemTotal = _react.useMemo.call(void 0, () => {
@@ -791,7 +648,7 @@ function useCartPricing(options = {}) {
791
648
  }, [getUnitPrice]);
792
649
  const subtotal = _react.useMemo.call(void 0, () => {
793
650
  return cartLines.reduce((sum, line) => {
794
- const unitPrice = _nullishCoalesce(_optionalChain([prices, 'access', _40 => _40[line.itemId.toUpperCase()], 'optionalAccess', _41 => _41.unitPrice]), () => ( 0));
651
+ const unitPrice = _nullishCoalesce(_optionalChain([prices, 'access', _34 => _34[line.itemId.toUpperCase()], 'optionalAccess', _35 => _35.unitPrice]), () => ( 0));
795
652
  return sum + unitPrice * line.quantity;
796
653
  }, 0);
797
654
  }, [cartLines, prices]);
@@ -808,12 +665,6 @@ function useCartPricing(options = {}) {
808
665
  isError
809
666
  };
810
667
  }
811
- function getCartPricingQueryOptions(api, cartLines, customerId) {
812
- return cartLines.map((line) => ({
813
- ...getItemPriceOptions(api, line.itemId, customerId, line.quantity),
814
- enabled: !!customerId && !!line.itemId
815
- }));
816
- }
817
668
 
818
669
  // src/hooks/use-pagination-prefetch.ts
819
670
 
@@ -862,18 +713,11 @@ var usePaginationPrefetch = ({
862
713
 
863
714
 
864
715
 
865
- var getCategoryItemsInfiniteKey = (itemCategoryUid, itemsFilters) => {
866
- return [
867
- "categoryItemsInfinite",
868
- itemCategoryUid,
869
- JSON.stringify(itemsFilters)
870
- ];
871
- };
872
716
  function useCategoryItemsInfinite(itemCategoryUid, itemsFilters, options = {}) {
873
717
  const api = useAugurApi();
874
718
  const { enabled = true } = options;
875
719
  return _reactquery.useInfiniteQuery.call(void 0, {
876
- queryKey: getCategoryItemsInfiniteKey(itemCategoryUid, itemsFilters),
720
+ queryKey: _chunkMRQREI4Lcjs.getCategoryItemsInfiniteKey.call(void 0, itemCategoryUid, itemsFilters),
877
721
  queryFn: async ({ pageParam = 0 }) => {
878
722
  const response = await api.openSearch.itemSearch.list({
879
723
  q: itemsFilters.q || "",
@@ -881,10 +725,10 @@ function useCategoryItemsInfinite(itemCategoryUid, itemsFilters, options = {}) {
881
725
  size: itemsFilters.limit,
882
726
  from: pageParam,
883
727
  classId5List: String(itemCategoryUid),
884
- filters: _optionalChain([itemsFilters, 'access', _42 => _42.filters, 'optionalAccess', _43 => _43.length]) ? JSON.stringify(itemsFilters.filters) : void 0
728
+ filters: _optionalChain([itemsFilters, 'access', _36 => _36.filters, 'optionalAccess', _37 => _37.length]) ? JSON.stringify(itemsFilters.filters) : void 0
885
729
  });
886
- const items = _nullishCoalesce(_optionalChain([response, 'access', _44 => _44.data, 'optionalAccess', _45 => _45.items]), () => ( []));
887
- const total = _nullishCoalesce(_optionalChain([response, 'access', _46 => _46.data, 'optionalAccess', _47 => _47.totalResults]), () => ( 0));
730
+ const items = _nullishCoalesce(_optionalChain([response, 'access', _38 => _38.data, 'optionalAccess', _39 => _39.items]), () => ( []));
731
+ const total = _nullishCoalesce(_optionalChain([response, 'access', _40 => _40.data, 'optionalAccess', _41 => _41.totalResults]), () => ( 0));
888
732
  const nextOffset = pageParam + itemsFilters.limit;
889
733
  return {
890
734
  data: items,
@@ -904,18 +748,11 @@ function useCategoryItemsInfinite(itemCategoryUid, itemsFilters, options = {}) {
904
748
 
905
749
 
906
750
 
907
- var getItemSearchInfiniteKey = (itemsFilters, itemCategoryUid) => {
908
- return [
909
- "itemSearchInfinite",
910
- JSON.stringify(itemsFilters),
911
- itemCategoryUid
912
- ];
913
- };
914
751
  function useItemSearchInfinite(itemsFilters, itemCategoryUid, options = {}) {
915
752
  const api = useAugurApi();
916
753
  const { enabled = true } = options;
917
754
  return _reactquery.useInfiniteQuery.call(void 0, {
918
- queryKey: getItemSearchInfiniteKey(itemsFilters, itemCategoryUid),
755
+ queryKey: _chunkMRQREI4Lcjs.getItemSearchInfiniteKey.call(void 0, itemsFilters, itemCategoryUid),
919
756
  queryFn: async ({ pageParam = 0 }) => {
920
757
  const response = await api.openSearch.itemSearch.list({
921
758
  q: itemsFilters.q,
@@ -923,10 +760,10 @@ function useItemSearchInfinite(itemsFilters, itemCategoryUid, options = {}) {
923
760
  size: itemsFilters.limit,
924
761
  from: pageParam,
925
762
  classId5List: itemCategoryUid ? String(itemCategoryUid) : void 0,
926
- filters: _optionalChain([itemsFilters, 'access', _48 => _48.filters, 'optionalAccess', _49 => _49.length]) ? JSON.stringify(itemsFilters.filters) : void 0
763
+ filters: _optionalChain([itemsFilters, 'access', _42 => _42.filters, 'optionalAccess', _43 => _43.length]) ? JSON.stringify(itemsFilters.filters) : void 0
927
764
  });
928
- const items = _nullishCoalesce(_optionalChain([response, 'access', _50 => _50.data, 'optionalAccess', _51 => _51.items]), () => ( []));
929
- const total = _nullishCoalesce(_optionalChain([response, 'access', _52 => _52.data, 'optionalAccess', _53 => _53.totalResults]), () => ( 0));
765
+ const items = _nullishCoalesce(_optionalChain([response, 'access', _44 => _44.data, 'optionalAccess', _45 => _45.items]), () => ( []));
766
+ const total = _nullishCoalesce(_optionalChain([response, 'access', _46 => _46.data, 'optionalAccess', _47 => _47.totalResults]), () => ( 0));
930
767
  const nextOffset = pageParam + itemsFilters.limit;
931
768
  return {
932
769
  data: items,
@@ -997,5 +834,6 @@ function useItemSearchInfinite(itemsFilters, itemCategoryUid, options = {}) {
997
834
 
998
835
 
999
836
 
1000
- exports.AugurHooksProvider = AugurHooksProvider; exports.CATEGORY_CACHE_OPTIONS = CATEGORY_CACHE_OPTIONS; exports.INV_MAST_CACHE_OPTIONS = INV_MAST_CACHE_OPTIONS; exports.INV_MAST_DOC_CACHE_OPTIONS = INV_MAST_DOC_CACHE_OPTIONS; exports.PRICE_CACHE_OPTIONS = PRICE_CACHE_OPTIONS; exports.getCartPricingQueryOptions = getCartPricingQueryOptions; exports.getCategoryItemsInfiniteKey = getCategoryItemsInfiniteKey; exports.getInvMastDocKey = getInvMastDocKey; exports.getInvMastDocOptions = getInvMastDocOptions; exports.getInvMastKey = getInvMastKey; exports.getInvMastOptions = getInvMastOptions; exports.getInvMastStockKey = getInvMastStockKey; exports.getInvMastStockOptions = getInvMastStockOptions; exports.getItemAttributesKey = getItemAttributesKey; exports.getItemAttributesOptions = getItemAttributesOptions; exports.getItemCategoryKey = getItemCategoryKey; exports.getItemCategoryOptions = getItemCategoryOptions; exports.getItemDetailsKey = getItemDetailsKey; exports.getItemDetailsOptions = getItemDetailsOptions; exports.getItemPriceKey = getItemPriceKey; exports.getItemPriceOptions = getItemPriceOptions; exports.getItemSearchInfiniteKey = getItemSearchInfiniteKey; exports.getProductCategoryKey = getProductCategoryKey; exports.getProductCategoryOptions = getProductCategoryOptions; exports.getProductSearchKey = getProductSearchKey; exports.getProductSearchOptions = getProductSearchOptions; exports.getSearchSuggestionsKey = getSearchSuggestionsKey; exports.getSearchSuggestionsOptions = getSearchSuggestionsOptions; exports.useAugurApi = useAugurApi; exports.useCartActions = useCartActions; exports.useCartHdrUid = useCartHdrUid; exports.useCartInitialization = useCartInitialization; exports.useCartItemCount = useCartItemCount; exports.useCartLines = useCartLines; exports.useCartPricing = useCartPricing; exports.useCartStore = useCartStore; exports.useCategoryItemsInfinite = useCategoryItemsInfinite; exports.useClearCart = useClearCart; exports.useDebounce = useDebounce; exports.useFormatPrice = useFormatPrice; exports.useInvMast = useInvMast; exports.useInvMastDoc = useInvMastDoc; exports.useInvMastStock = useInvMastStock; exports.useItemAttributes = useItemAttributes; exports.useItemCategory = useItemCategory; exports.useItemDetails = useItemDetails; exports.useItemFiltersStore = useItemFiltersStore; exports.useItemPrice = useItemPrice; exports.useItemSearchInfinite = useItemSearchInfinite; exports.usePaginationPrefetch = usePaginationPrefetch; exports.useProductCategory = useProductCategory; exports.useProductSearch = useProductSearch; exports.useSearchSuggestions = useSearchSuggestions; exports.useSetCartHdrUid = useSetCartHdrUid; exports.useSetCartLines = useSetCartLines;
837
+
838
+ exports.AugurHooksProvider = AugurHooksProvider; exports.CATEGORY_CACHE_OPTIONS = _chunkMRQREI4Lcjs.CATEGORY_CACHE_OPTIONS; exports.INV_MAST_CACHE_OPTIONS = _chunkMRQREI4Lcjs.INV_MAST_CACHE_OPTIONS; exports.INV_MAST_DOC_CACHE_OPTIONS = _chunkMRQREI4Lcjs.INV_MAST_DOC_CACHE_OPTIONS; exports.PRICE_CACHE_OPTIONS = _chunkMRQREI4Lcjs.PRICE_CACHE_OPTIONS; exports.SEARCH_SUGGESTIONS_CACHE_OPTIONS = _chunkMRQREI4Lcjs.SEARCH_SUGGESTIONS_CACHE_OPTIONS; exports.getCartPricingQueryOptions = _chunkMRQREI4Lcjs.getCartPricingQueryOptions; exports.getCategoryItemsInfiniteKey = _chunkMRQREI4Lcjs.getCategoryItemsInfiniteKey; exports.getInvMastDocKey = _chunkMRQREI4Lcjs.getInvMastDocKey; exports.getInvMastDocOptions = _chunkMRQREI4Lcjs.getInvMastDocOptions; exports.getInvMastKey = _chunkMRQREI4Lcjs.getInvMastKey; exports.getInvMastOptions = _chunkMRQREI4Lcjs.getInvMastOptions; exports.getInvMastStockKey = _chunkMRQREI4Lcjs.getInvMastStockKey; exports.getInvMastStockOptions = _chunkMRQREI4Lcjs.getInvMastStockOptions; exports.getItemAttributesKey = _chunkMRQREI4Lcjs.getItemAttributesKey; exports.getItemAttributesOptions = _chunkMRQREI4Lcjs.getItemAttributesOptions; exports.getItemCategoryKey = _chunkMRQREI4Lcjs.getItemCategoryKey; exports.getItemCategoryOptions = _chunkMRQREI4Lcjs.getItemCategoryOptions; exports.getItemDetailsKey = _chunkMRQREI4Lcjs.getItemDetailsKey; exports.getItemDetailsOptions = _chunkMRQREI4Lcjs.getItemDetailsOptions; exports.getItemPriceKey = _chunkMRQREI4Lcjs.getItemPriceKey; exports.getItemPriceOptions = _chunkMRQREI4Lcjs.getItemPriceOptions; exports.getItemSearchInfiniteKey = _chunkMRQREI4Lcjs.getItemSearchInfiniteKey; exports.getProductCategoryKey = _chunkMRQREI4Lcjs.getProductCategoryKey; exports.getProductCategoryOptions = _chunkMRQREI4Lcjs.getProductCategoryOptions; exports.getProductSearchKey = _chunkMRQREI4Lcjs.getProductSearchKey; exports.getProductSearchOptions = _chunkMRQREI4Lcjs.getProductSearchOptions; exports.getSearchSuggestionsKey = _chunkMRQREI4Lcjs.getSearchSuggestionsKey; exports.getSearchSuggestionsOptions = _chunkMRQREI4Lcjs.getSearchSuggestionsOptions; exports.useAugurApi = useAugurApi; exports.useCartActions = useCartActions; exports.useCartHdrUid = useCartHdrUid; exports.useCartInitialization = useCartInitialization; exports.useCartItemCount = useCartItemCount; exports.useCartLines = useCartLines; exports.useCartPricing = useCartPricing; exports.useCartStore = useCartStore; exports.useCategoryItemsInfinite = useCategoryItemsInfinite; exports.useClearCart = useClearCart; exports.useDebounce = useDebounce; exports.useFormatPrice = useFormatPrice; exports.useInvMast = useInvMast; exports.useInvMastDoc = useInvMastDoc; exports.useInvMastStock = useInvMastStock; exports.useItemAttributes = useItemAttributes; exports.useItemCategory = useItemCategory; exports.useItemDetails = useItemDetails; exports.useItemFiltersStore = useItemFiltersStore; exports.useItemPrice = useItemPrice; exports.useItemSearchInfinite = useItemSearchInfinite; exports.usePaginationPrefetch = usePaginationPrefetch; exports.useProductCategory = useProductCategory; exports.useProductSearch = useProductSearch; exports.useSearchSuggestions = useSearchSuggestions; exports.useSetCartHdrUid = useSetCartHdrUid; exports.useSetCartLines = useSetCartLines;
1001
839
  //# sourceMappingURL=index.cjs.map