@simpleapps-com/augur-hooks 2026.11.3 → 2026.11.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/EXPORTS.md +1 -1
- package/README.md +7 -1
- package/dist/checkout/create-checkout-provider.d.ts.map +1 -1
- package/dist/checkout/index.cjs +35 -22
- package/dist/checkout/index.cjs.map +1 -1
- package/dist/checkout/index.js +22 -9
- package/dist/checkout/index.js.map +1 -1
- package/dist/{chunk-D5C6WWFO.js → chunk-7SUD5Z2V.js} +1 -1
- package/dist/chunk-7SUD5Z2V.js.map +1 -0
- package/dist/{chunk-BWBJPKLV.cjs → chunk-CRVSCSGP.cjs} +39 -2
- package/dist/chunk-CRVSCSGP.cjs.map +1 -0
- package/dist/{chunk-2BTOULIS.js → chunk-LLTE6COX.js} +38 -1
- package/dist/chunk-LLTE6COX.js.map +1 -0
- package/dist/{chunk-6Z6JGK2C.cjs → chunk-WJ4D5OCQ.cjs} +1 -1
- package/dist/chunk-WJ4D5OCQ.cjs.map +1 -0
- package/dist/hooks/use-cart-actions.d.ts +21 -8
- package/dist/hooks/use-cart-actions.d.ts.map +1 -1
- package/dist/hooks/use-cart-initialization.d.ts +7 -0
- package/dist/hooks/use-cart-initialization.d.ts.map +1 -1
- package/dist/index.cjs +187 -102
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +155 -70
- package/dist/index.js.map +1 -1
- package/dist/query-action-registry.d.ts +7 -4
- package/dist/query-action-registry.d.ts.map +1 -1
- package/dist/rules.d.ts +55 -0
- package/dist/rules.d.ts.map +1 -1
- package/dist/server.cjs +3 -3
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.ts +2 -2
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +1 -1
- package/dist/server.js.map +1 -1
- package/dist/stores/cart-store.d.ts +11 -1
- package/dist/stores/cart-store.d.ts.map +1 -1
- package/llms.txt +1 -1
- package/package.json +4 -4
- package/dist/chunk-2BTOULIS.js.map +0 -1
- package/dist/chunk-6Z6JGK2C.cjs.map +0 -1
- package/dist/chunk-BWBJPKLV.cjs.map +0 -1
- package/dist/chunk-D5C6WWFO.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _chunkWJ4D5OCQcjs = require('./chunk-WJ4D5OCQ.cjs');
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
@@ -31,7 +31,13 @@ var _chunk6Z6JGK2Ccjs = require('./chunk-6Z6JGK2C.cjs');
|
|
|
31
31
|
|
|
32
32
|
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
var _chunkCRVSCSGPcjs = require('./chunk-CRVSCSGP.cjs');
|
|
35
41
|
|
|
36
42
|
// src/provider.tsx
|
|
37
43
|
var _react = require('react');
|
|
@@ -48,11 +54,11 @@ var AugurOptionsContext = _react.createContext.call(void 0, null);
|
|
|
48
54
|
var AugurSiteContext = _react.createContext.call(void 0, void 0);
|
|
49
55
|
function AugurHooksProvider({ api, auth, cache, site, children }) {
|
|
50
56
|
const proxyConfig = cache ? { cache: { static: cache.static, semiStatic: cache.semiStatic } } : void 0;
|
|
51
|
-
const proxyConfigRef =
|
|
57
|
+
const proxyConfigRef = _chunkCRVSCSGPcjs.useLatest.call(void 0, proxyConfig);
|
|
52
58
|
const options = _react.useMemo.call(void 0, () => {
|
|
53
59
|
const config = proxyConfigRef.current;
|
|
54
60
|
if (api) return _augurcore.createOptionsProxy.call(void 0, api, config);
|
|
55
|
-
const registeredAction =
|
|
61
|
+
const registeredAction = _chunkWJ4D5OCQcjs.getRegisteredQueryAction.call(void 0, );
|
|
56
62
|
if (registeredAction) return _augurcore.createQueryActionProxy.call(void 0, registeredAction, config);
|
|
57
63
|
return _augurcore.createKeysOnlyProxy.call(void 0, config);
|
|
58
64
|
}, [api, proxyConfigRef]);
|
|
@@ -182,9 +188,9 @@ function useStock(invMastUid, options = {}) {
|
|
|
182
188
|
const query = _reactquery.useQuery.call(void 0, {
|
|
183
189
|
...proxyOpts,
|
|
184
190
|
...resolvedQueryFn ? { queryFn: resolvedQueryFn } : {},
|
|
185
|
-
enabled:
|
|
191
|
+
enabled: _chunkCRVSCSGPcjs.stockEnabled.call(void 0, options.enabled, !!invMastUid),
|
|
186
192
|
retry: 3,
|
|
187
|
-
retryDelay:
|
|
193
|
+
retryDelay: _chunkCRVSCSGPcjs.stockRetryDelay
|
|
188
194
|
});
|
|
189
195
|
const stockData = _nullishCoalesce(query.data, () => ( null));
|
|
190
196
|
const resolved = _react.useMemo.call(void 0,
|
|
@@ -208,21 +214,24 @@ function useStock(invMastUid, options = {}) {
|
|
|
208
214
|
// src/hooks/use-cart-actions.ts
|
|
209
215
|
|
|
210
216
|
|
|
211
|
-
function
|
|
217
|
+
function cartUidOf(cartHdrUid) {
|
|
212
218
|
const num = typeof cartHdrUid === "string" ? Number(cartHdrUid) : cartHdrUid;
|
|
213
|
-
|
|
219
|
+
return num === void 0 || Number.isNaN(num) ? void 0 : num;
|
|
220
|
+
}
|
|
221
|
+
function requireCartUid(cartHdrUid) {
|
|
222
|
+
const uid = _chunkCRVSCSGPcjs.requiredCartUid.call(void 0, cartUidOf(cartHdrUid));
|
|
214
223
|
if (uid === null) throw new Error("Cart UID is not set");
|
|
215
224
|
return uid;
|
|
216
225
|
}
|
|
217
226
|
function liveCart() {
|
|
218
|
-
const { cartHdrUid, cartLines } =
|
|
227
|
+
const { cartHdrUid, cartLines } = _chunkCRVSCSGPcjs.useCartStore.getState();
|
|
219
228
|
return { uid: requireCartUid(cartHdrUid), lines: cartLines };
|
|
220
229
|
}
|
|
221
230
|
function buildOptimisticAdd(cartLines, item, cartHdrUid, itemId) {
|
|
222
|
-
const existingIndex =
|
|
231
|
+
const existingIndex = _chunkCRVSCSGPcjs.indexOfUidFrom.call(void 0, uidsOf(cartLines), item.invMastUid, 0);
|
|
223
232
|
if (existingIndex >= 0) {
|
|
224
233
|
return cartLines.map(
|
|
225
|
-
(line, index) => index === existingIndex ? { ...line, quantity:
|
|
234
|
+
(line, index) => index === existingIndex ? { ...line, quantity: _chunkCRVSCSGPcjs.qtyOrZero.call(void 0, line.quantity) + item.quantity } : line
|
|
226
235
|
);
|
|
227
236
|
}
|
|
228
237
|
return [
|
|
@@ -243,58 +252,99 @@ function buildOptimisticAdd(cartLines, item, cartHdrUid, itemId) {
|
|
|
243
252
|
];
|
|
244
253
|
}
|
|
245
254
|
function reverseAdd(cartLines, invMastUid, quantity) {
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
255
|
+
const index = _chunkCRVSCSGPcjs.indexOfUidFrom.call(void 0, uidsOf(cartLines), invMastUid, 0);
|
|
256
|
+
if (index < 0) return cartLines;
|
|
257
|
+
const line = cartLines[index];
|
|
258
|
+
if (!_chunkCRVSCSGPcjs.keepsAfterReverse.call(void 0, line.quantity, quantity)) {
|
|
259
|
+
return [...cartLines.slice(0, index), ...cartLines.slice(index + 1)];
|
|
260
|
+
}
|
|
261
|
+
return cartLines.map(
|
|
262
|
+
(l, i) => i === index ? { ...l, quantity: _chunkCRVSCSGPcjs.qtyOrZero.call(void 0, l.quantity) - quantity } : l
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
function targetOf(cartLines, invMastUid, unitOfMeasure) {
|
|
266
|
+
const first = _chunkCRVSCSGPcjs.indexOfUidFrom.call(void 0, uidsOf(cartLines), invMastUid, 0);
|
|
267
|
+
if (first < 0) return null;
|
|
268
|
+
const unit = _nullishCoalesce(unitOfMeasure, () => ( unitOf(cartLines[first])));
|
|
269
|
+
if (_chunkCRVSCSGPcjs.indexOfUnitFrom.call(void 0, uidsOf(cartLines), unitsOf(cartLines), invMastUid, unit, 0) < 0) return null;
|
|
270
|
+
return { invMastUid, unit };
|
|
271
|
+
}
|
|
272
|
+
function isTarget(line, target) {
|
|
273
|
+
return _chunkCRVSCSGPcjs.indexOfUnitFrom.call(void 0, [line.invMastUid], [unitOf(line)], target.invMastUid, target.unit, 0) === 0;
|
|
274
|
+
}
|
|
275
|
+
function targetLine(cartLines, target) {
|
|
276
|
+
const index = _chunkCRVSCSGPcjs.indexOfUnitFrom.call(void 0,
|
|
277
|
+
uidsOf(cartLines),
|
|
278
|
+
unitsOf(cartLines),
|
|
279
|
+
target.invMastUid,
|
|
280
|
+
target.unit,
|
|
281
|
+
0
|
|
282
|
+
);
|
|
283
|
+
return cartLines[index];
|
|
250
284
|
}
|
|
251
|
-
function reverseQuantity(cartLines,
|
|
252
|
-
if (previousQuantity === void 0) return cartLines;
|
|
285
|
+
function reverseQuantity(cartLines, target, previousQuantity) {
|
|
253
286
|
return cartLines.map(
|
|
254
|
-
(line) => line
|
|
287
|
+
(line) => isTarget(line, target) ? { ...line, quantity: previousQuantity } : line
|
|
255
288
|
);
|
|
256
289
|
}
|
|
257
|
-
function restoreRemoved(cartLines,
|
|
258
|
-
if (
|
|
259
|
-
|
|
290
|
+
function restoreRemoved(cartLines, target, removedLine) {
|
|
291
|
+
if (_chunkCRVSCSGPcjs.indexOfUnitFrom.call(void 0, uidsOf(cartLines), unitsOf(cartLines), target.invMastUid, target.unit, 0) >= 0) {
|
|
292
|
+
return cartLines;
|
|
293
|
+
}
|
|
260
294
|
return [...cartLines, removedLine];
|
|
261
295
|
}
|
|
262
296
|
function mergeRestore(cartLines, snapshot) {
|
|
263
297
|
const merged = [...cartLines];
|
|
264
298
|
for (const line of snapshot) {
|
|
265
|
-
if (!
|
|
299
|
+
if (!_chunkCRVSCSGPcjs.hasNumberFrom.call(void 0, uidsOf(merged), line.invMastUid, 0)) merged.push(line);
|
|
266
300
|
}
|
|
267
301
|
return merged;
|
|
268
302
|
}
|
|
303
|
+
function sentLine(line, quantity) {
|
|
304
|
+
const { unitPrice, ...rest } = line;
|
|
305
|
+
const sent = { ...rest, quantity, lineNo: 0 };
|
|
306
|
+
if (_chunkCRVSCSGPcjs.sendsPrice.call(void 0, unitPrice)) sent.unitPrice = unitPrice;
|
|
307
|
+
return sent;
|
|
308
|
+
}
|
|
269
309
|
function uidsOf(cartLines) {
|
|
270
310
|
return cartLines.map((line) => line.invMastUid);
|
|
271
311
|
}
|
|
312
|
+
function unitOf(line) {
|
|
313
|
+
return _nullishCoalesce(line.unitOfMeasure, () => ( ""));
|
|
314
|
+
}
|
|
315
|
+
function unitsOf(cartLines) {
|
|
316
|
+
return cartLines.map(unitOf);
|
|
317
|
+
}
|
|
272
318
|
function sendToast(notify, kind, showToast, message) {
|
|
273
319
|
if (showToast && message !== void 0) _optionalChain([notify, 'optionalAccess', _4 => _4[kind], 'optionalCall', _5 => _5(message)]);
|
|
274
320
|
}
|
|
275
321
|
async function settleCartOp(op, options, notify, invalidate) {
|
|
322
|
+
const { endCartOp } = _chunkCRVSCSGPcjs.useCartStore.getState();
|
|
276
323
|
try {
|
|
277
324
|
const success = await op.call();
|
|
278
325
|
if (!success) throw new Error(op.failure);
|
|
279
|
-
invalidate();
|
|
280
|
-
sendToast(notify, "info", op.showToast, op.infoMessage);
|
|
281
|
-
_optionalChain([options, 'access', _6 => _6.onSuccess, 'optionalCall', _7 => _7()]);
|
|
282
|
-
return true;
|
|
283
326
|
} catch (error) {
|
|
284
|
-
op.rollback();
|
|
327
|
+
if (_chunkCRVSCSGPcjs.rollsBack.call(void 0, cartUidOf(_chunkCRVSCSGPcjs.useCartStore.getState().cartHdrUid), op.cartUid)) op.rollback();
|
|
328
|
+
endCartOp();
|
|
329
|
+
invalidate();
|
|
285
330
|
sendToast(notify, "error", op.showToast, op.errorMessage);
|
|
286
|
-
_optionalChain([options, 'access',
|
|
331
|
+
_optionalChain([options, 'access', _6 => _6.onError, 'optionalCall', _7 => _7(error)]);
|
|
287
332
|
return false;
|
|
288
333
|
}
|
|
334
|
+
endCartOp();
|
|
335
|
+
invalidate();
|
|
336
|
+
sendToast(notify, "info", op.showToast, op.infoMessage);
|
|
337
|
+
_optionalChain([options, 'access', _8 => _8.onSuccess, 'optionalCall', _9 => _9()]);
|
|
338
|
+
return true;
|
|
289
339
|
}
|
|
290
340
|
function useCartActions(callbacks) {
|
|
291
341
|
const queryClient = _reactquery.useQueryClient.call(void 0, );
|
|
292
|
-
const cartHdrUid =
|
|
293
|
-
const cartLines =
|
|
294
|
-
const setCartLines =
|
|
342
|
+
const cartHdrUid = _chunkCRVSCSGPcjs.useCartHdrUid.call(void 0, );
|
|
343
|
+
const cartLines = _chunkCRVSCSGPcjs.useCartLines.call(void 0, );
|
|
344
|
+
const setCartLines = _chunkCRVSCSGPcjs.useSetCartLines.call(void 0, );
|
|
295
345
|
const notify = callbacks.toast;
|
|
296
346
|
const invalidateCartCache = _react.useCallback.call(void 0, () => {
|
|
297
|
-
void queryClient.invalidateQueries({ queryKey: ["cartLines"
|
|
347
|
+
void queryClient.invalidateQueries({ queryKey: ["cartLines"] });
|
|
298
348
|
void queryClient.invalidateQueries({
|
|
299
349
|
queryKey: ["cart-also-bought", cartHdrUid]
|
|
300
350
|
});
|
|
@@ -303,9 +353,11 @@ function useCartActions(callbacks) {
|
|
|
303
353
|
async (item, options = {}) => {
|
|
304
354
|
const { showToast = true, itemId = "" } = options;
|
|
305
355
|
const { uid, lines: liveLines } = liveCart();
|
|
356
|
+
_chunkCRVSCSGPcjs.useCartStore.getState().beginCartOp();
|
|
306
357
|
setCartLines(buildOptimisticAdd(liveLines, item, uid, itemId));
|
|
307
358
|
return settleCartOp(
|
|
308
359
|
{
|
|
360
|
+
cartUid: uid,
|
|
309
361
|
call: () => callbacks.addToCart(uid, [
|
|
310
362
|
{
|
|
311
363
|
cartHdrUid: uid,
|
|
@@ -319,7 +371,7 @@ function useCartActions(callbacks) {
|
|
|
319
371
|
errorMessage: "Failed to add item to cart. Please try again.",
|
|
320
372
|
showToast,
|
|
321
373
|
rollback: () => setCartLines(
|
|
322
|
-
reverseAdd(
|
|
374
|
+
reverseAdd(_chunkCRVSCSGPcjs.useCartStore.getState().cartLines, item.invMastUid, item.quantity)
|
|
323
375
|
)
|
|
324
376
|
},
|
|
325
377
|
options,
|
|
@@ -331,21 +383,25 @@ function useCartActions(callbacks) {
|
|
|
331
383
|
);
|
|
332
384
|
const updateQuantity = _react.useCallback.call(void 0,
|
|
333
385
|
async (invMastUid, newQuantity, options = {}) => {
|
|
334
|
-
const { showToast = false } = options;
|
|
386
|
+
const { showToast = false, unitOfMeasure } = options;
|
|
335
387
|
const { uid, lines: liveLines } = liveCart();
|
|
336
|
-
const
|
|
337
|
-
|
|
338
|
-
|
|
388
|
+
const target = targetOf(liveLines, invMastUid, unitOfMeasure);
|
|
389
|
+
if (target === null) return true;
|
|
390
|
+
const line = targetLine(liveLines, target);
|
|
391
|
+
const previousQuantity = line.quantity;
|
|
392
|
+
_chunkCRVSCSGPcjs.useCartStore.getState().beginCartOp();
|
|
393
|
+
setCartLines(
|
|
394
|
+
liveLines.map((l) => isTarget(l, target) ? { ...l, quantity: newQuantity } : l)
|
|
339
395
|
);
|
|
340
|
-
setCartLines(updatedLines);
|
|
341
396
|
return settleCartOp(
|
|
342
397
|
{
|
|
343
|
-
|
|
398
|
+
cartUid: uid,
|
|
399
|
+
call: () => callbacks.updateCartLines(uid, [sentLine(line, newQuantity)]),
|
|
344
400
|
failure: "Failed to update quantity",
|
|
345
401
|
errorMessage: "Failed to update quantity. Please try again.",
|
|
346
402
|
showToast,
|
|
347
403
|
rollback: () => setCartLines(
|
|
348
|
-
reverseQuantity(
|
|
404
|
+
reverseQuantity(_chunkCRVSCSGPcjs.useCartStore.getState().cartLines, target, previousQuantity)
|
|
349
405
|
)
|
|
350
406
|
},
|
|
351
407
|
options,
|
|
@@ -357,23 +413,22 @@ function useCartActions(callbacks) {
|
|
|
357
413
|
);
|
|
358
414
|
const removeFromCart = _react.useCallback.call(void 0,
|
|
359
415
|
async (invMastUid, options = {}) => {
|
|
360
|
-
const { showToast = true, itemId = "" } = options;
|
|
416
|
+
const { showToast = true, itemId = "", unitOfMeasure } = options;
|
|
361
417
|
const { uid, lines: liveLines } = liveCart();
|
|
362
|
-
const
|
|
363
|
-
|
|
364
|
-
const
|
|
365
|
-
|
|
366
|
-
);
|
|
418
|
+
const target = targetOf(liveLines, invMastUid, unitOfMeasure);
|
|
419
|
+
if (target === null) return true;
|
|
420
|
+
const removedLine = targetLine(liveLines, target);
|
|
421
|
+
_chunkCRVSCSGPcjs.useCartStore.getState().beginCartOp();
|
|
422
|
+
setCartLines(liveLines.filter((l) => !isTarget(l, target)));
|
|
367
423
|
return settleCartOp(
|
|
368
424
|
{
|
|
369
|
-
|
|
425
|
+
cartUid: uid,
|
|
426
|
+
call: () => callbacks.updateCartLines(uid, [sentLine(removedLine, 0)]),
|
|
370
427
|
failure: "Failed to remove item",
|
|
371
428
|
infoMessage: `${itemId || "Item"} removed from cart`,
|
|
372
429
|
errorMessage: "Failed to remove item. Please try again.",
|
|
373
430
|
showToast,
|
|
374
|
-
rollback: () => setCartLines(
|
|
375
|
-
restoreRemoved(_chunkBWBJPKLVcjs.useCartStore.getState().cartLines, invMastUid, removedLine)
|
|
376
|
-
)
|
|
431
|
+
rollback: () => setCartLines(restoreRemoved(_chunkCRVSCSGPcjs.useCartStore.getState().cartLines, target, removedLine))
|
|
377
432
|
},
|
|
378
433
|
options,
|
|
379
434
|
notify,
|
|
@@ -386,15 +441,17 @@ function useCartActions(callbacks) {
|
|
|
386
441
|
async (options = {}) => {
|
|
387
442
|
const { showToast = true } = options;
|
|
388
443
|
const { uid, lines: snapshot } = liveCart();
|
|
444
|
+
_chunkCRVSCSGPcjs.useCartStore.getState().beginCartOp();
|
|
389
445
|
setCartLines([]);
|
|
390
446
|
return settleCartOp(
|
|
391
447
|
{
|
|
448
|
+
cartUid: uid,
|
|
392
449
|
call: () => callbacks.deleteItemsFromCart(uid),
|
|
393
450
|
failure: "Failed to clear cart",
|
|
394
451
|
infoMessage: "Cart cleared",
|
|
395
452
|
errorMessage: "Failed to clear cart. Please try again.",
|
|
396
453
|
showToast,
|
|
397
|
-
rollback: () => setCartLines(mergeRestore(
|
|
454
|
+
rollback: () => setCartLines(mergeRestore(_chunkCRVSCSGPcjs.useCartStore.getState().cartLines, snapshot))
|
|
398
455
|
},
|
|
399
456
|
options,
|
|
400
457
|
notify,
|
|
@@ -411,7 +468,7 @@ function useCartActions(callbacks) {
|
|
|
411
468
|
);
|
|
412
469
|
const getItemQuantity = _react.useCallback.call(void 0,
|
|
413
470
|
(invMastUid) => {
|
|
414
|
-
return _nullishCoalesce(_optionalChain([cartLines, 'access',
|
|
471
|
+
return _nullishCoalesce(_optionalChain([cartLines, 'access', _10 => _10.find, 'call', _11 => _11((line) => line.invMastUid === invMastUid), 'optionalAccess', _12 => _12.quantity]), () => ( 0));
|
|
415
472
|
},
|
|
416
473
|
[cartLines]
|
|
417
474
|
);
|
|
@@ -456,6 +513,7 @@ function useModalLifecycle(isOpen, onClose) {
|
|
|
456
513
|
|
|
457
514
|
var MAX_RETRY_ATTEMPTS = 7;
|
|
458
515
|
var RETRY_DELAY_MS = 1e3;
|
|
516
|
+
var LOOKUP_RESTART_MS = 3e4;
|
|
459
517
|
async function waitBeforeRetry(attempt) {
|
|
460
518
|
if (attempt >= MAX_RETRY_ATTEMPTS) return;
|
|
461
519
|
const delay = Math.min(RETRY_DELAY_MS * Math.pow(1.5, attempt), 1e4);
|
|
@@ -464,19 +522,22 @@ async function waitBeforeRetry(attempt) {
|
|
|
464
522
|
var defaultGetCartToken = () => localStorage.getItem("cartToken");
|
|
465
523
|
var defaultSaveCartToken = (token) => localStorage.setItem("cartToken", token);
|
|
466
524
|
var defaultGenerateCartToken = () => crypto.randomUUID();
|
|
525
|
+
function cartKey(uid) {
|
|
526
|
+
return uid === void 0 ? void 0 : String(uid);
|
|
527
|
+
}
|
|
467
528
|
function useCartInitialization(session, callbacks) {
|
|
468
529
|
const getCartToken = _nullishCoalesce(callbacks.getCartToken, () => ( defaultGetCartToken));
|
|
469
530
|
const saveCartToken = _nullishCoalesce(callbacks.saveCartToken, () => ( defaultSaveCartToken));
|
|
470
531
|
const generateCartToken = _nullishCoalesce(callbacks.generateCartToken, () => ( defaultGenerateCartToken));
|
|
471
532
|
const auth = useAugurAuth();
|
|
472
|
-
const cartHdrUid =
|
|
473
|
-
const setCartHdrUid =
|
|
474
|
-
const setCartLines =
|
|
475
|
-
const clearCart =
|
|
533
|
+
const cartHdrUid = _chunkCRVSCSGPcjs.useCartHdrUid.call(void 0, );
|
|
534
|
+
const setCartHdrUid = _chunkCRVSCSGPcjs.useSetCartHdrUid.call(void 0, );
|
|
535
|
+
const setCartLines = _chunkCRVSCSGPcjs.useSetCartLines.call(void 0, );
|
|
536
|
+
const clearCart = _chunkCRVSCSGPcjs.useClearCart.call(void 0, );
|
|
476
537
|
const queryClient = _reactquery.useQueryClient.call(void 0, );
|
|
477
538
|
const effectiveStatus = session.status;
|
|
478
|
-
const effectiveUserId = _nullishCoalesce(session.userId, () => ( _optionalChain([auth, 'optionalAccess',
|
|
479
|
-
const effectiveCartHdrUid = _nullishCoalesce(session.cartHdrUid, () => ( _optionalChain([auth, 'optionalAccess',
|
|
539
|
+
const effectiveUserId = _nullishCoalesce(session.userId, () => ( _optionalChain([auth, 'optionalAccess', _13 => _13.userId])));
|
|
540
|
+
const effectiveCartHdrUid = _nullishCoalesce(session.cartHdrUid, () => ( _optionalChain([auth, 'optionalAccess', _14 => _14.cartHdrUid])));
|
|
480
541
|
const effectiveSession = _react.useMemo.call(void 0,
|
|
481
542
|
() => ({ status: effectiveStatus, userId: effectiveUserId, cartHdrUid: effectiveCartHdrUid }),
|
|
482
543
|
[effectiveStatus, effectiveUserId, effectiveCartHdrUid]
|
|
@@ -484,6 +545,11 @@ function useCartInitialization(session, callbacks) {
|
|
|
484
545
|
const retryCountRef = _react.useRef.call(void 0, 0);
|
|
485
546
|
const isInitializingRef = _react.useRef.call(void 0, false);
|
|
486
547
|
const prevStatusRef = _react.useRef.call(void 0, effectiveSession.status);
|
|
548
|
+
const statusRef = _react.useRef.call(void 0, effectiveSession.status);
|
|
549
|
+
statusRef.current = effectiveSession.status;
|
|
550
|
+
const [lookupRound, setLookupRound] = _react.useState.call(void 0, 0);
|
|
551
|
+
const restartTimerRef = _react.useRef.call(void 0, void 0);
|
|
552
|
+
_react.useEffect.call(void 0, () => () => clearTimeout(restartTimerRef.current), []);
|
|
487
553
|
_react.useEffect.call(void 0, () => {
|
|
488
554
|
const prevStatus = prevStatusRef.current;
|
|
489
555
|
prevStatusRef.current = effectiveSession.status;
|
|
@@ -494,40 +560,57 @@ function useCartInitialization(session, callbacks) {
|
|
|
494
560
|
}
|
|
495
561
|
}, [effectiveSession.status, clearCart, queryClient]);
|
|
496
562
|
_react.useEffect.call(void 0, () => {
|
|
497
|
-
|
|
498
|
-
|
|
563
|
+
const step = _chunkCRVSCSGPcjs.initStepOf.call(void 0,
|
|
564
|
+
effectiveSession.status === "loading",
|
|
565
|
+
effectiveSession.status === "authenticated",
|
|
566
|
+
!!effectiveSession.cartHdrUid,
|
|
567
|
+
cartKey(cartHdrUid) === cartKey(effectiveSession.cartHdrUid),
|
|
568
|
+
!!cartHdrUid,
|
|
569
|
+
effectiveSession.userId !== void 0,
|
|
570
|
+
isInitializingRef.current
|
|
571
|
+
);
|
|
572
|
+
if (step.kind === "stay") return;
|
|
573
|
+
if (step.kind === "session") {
|
|
499
574
|
setCartHdrUid(effectiveSession.cartHdrUid);
|
|
500
575
|
return;
|
|
501
576
|
}
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
577
|
+
const forUser = step.kind === "user";
|
|
578
|
+
const lookupUserId = forUser ? effectiveSession.userId : "0";
|
|
579
|
+
isInitializingRef.current = true;
|
|
580
|
+
retryCountRef.current = 0;
|
|
581
|
+
const lookUpCart = async () => {
|
|
582
|
+
const existingToken = getCartToken();
|
|
583
|
+
const cartToken = existingToken && typeof existingToken === "string" ? existingToken : generateCartToken();
|
|
584
|
+
let lastError;
|
|
585
|
+
while (retryCountRef.current < MAX_RETRY_ATTEMPTS) {
|
|
586
|
+
try {
|
|
587
|
+
const cartHdr = await callbacks.cartHdrLookup(lookupUserId, cartToken);
|
|
588
|
+
if (cartHdr && cartHdr.cartHdrUid !== 0) {
|
|
589
|
+
const stillApplies = _chunkCRVSCSGPcjs.acceptsLookup.call(void 0,
|
|
590
|
+
forUser,
|
|
591
|
+
statusRef.current === "authenticated",
|
|
592
|
+
!!_chunkCRVSCSGPcjs.useCartStore.getState().cartHdrUid
|
|
593
|
+
);
|
|
594
|
+
if (stillApplies) {
|
|
513
595
|
saveCartToken(cartToken);
|
|
514
596
|
setCartHdrUid(cartHdr.cartHdrUid);
|
|
515
|
-
isInitializingRef.current = false;
|
|
516
|
-
return;
|
|
517
597
|
}
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
} catch (error) {
|
|
521
|
-
lastError = error;
|
|
522
|
-
retryCountRef.current++;
|
|
523
|
-
await waitBeforeRetry(retryCountRef.current);
|
|
598
|
+
isInitializingRef.current = false;
|
|
599
|
+
return;
|
|
524
600
|
}
|
|
601
|
+
retryCountRef.current++;
|
|
602
|
+
await waitBeforeRetry(retryCountRef.current);
|
|
603
|
+
} catch (error) {
|
|
604
|
+
lastError = error;
|
|
605
|
+
retryCountRef.current++;
|
|
606
|
+
await waitBeforeRetry(retryCountRef.current);
|
|
525
607
|
}
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
}
|
|
608
|
+
}
|
|
609
|
+
console.error(`Cart initialization failed after ${MAX_RETRY_ATTEMPTS} attempts`, lastError);
|
|
610
|
+
isInitializingRef.current = false;
|
|
611
|
+
restartTimerRef.current = setTimeout(() => setLookupRound((n) => n + 1), LOOKUP_RESTART_MS);
|
|
612
|
+
};
|
|
613
|
+
void lookUpCart();
|
|
531
614
|
}, [
|
|
532
615
|
effectiveSession,
|
|
533
616
|
cartHdrUid,
|
|
@@ -535,15 +618,17 @@ function useCartInitialization(session, callbacks) {
|
|
|
535
618
|
callbacks,
|
|
536
619
|
getCartToken,
|
|
537
620
|
saveCartToken,
|
|
538
|
-
generateCartToken
|
|
621
|
+
generateCartToken,
|
|
622
|
+
lookupRound
|
|
539
623
|
]);
|
|
540
624
|
const { data: cartLinesData } = _reactquery.useQuery.call(void 0, {
|
|
541
625
|
queryKey: ["cartLines", cartHdrUid],
|
|
542
626
|
queryFn: async () => await _asyncNullishCoalesce(await callbacks.getCartLines(Number(cartHdrUid)), async () => ( [])),
|
|
543
|
-
enabled: !!cartHdrUid
|
|
627
|
+
enabled: !!cartHdrUid,
|
|
628
|
+
structuralSharing: false
|
|
544
629
|
});
|
|
545
630
|
_react.useEffect.call(void 0, () => {
|
|
546
|
-
if (cartLinesData) {
|
|
631
|
+
if (cartLinesData && _chunkCRVSCSGPcjs.cartIdle.call(void 0, _chunkCRVSCSGPcjs.useCartStore.getState().pendingCartOps)) {
|
|
547
632
|
setCartLines(cartLinesData);
|
|
548
633
|
}
|
|
549
634
|
}, [cartLinesData, setCartLines]);
|
|
@@ -575,15 +660,15 @@ function useCartPricing(options = {}) {
|
|
|
575
660
|
const proxy = useAugurOptions();
|
|
576
661
|
const auth = useAugurAuth();
|
|
577
662
|
const site = useAugurSite();
|
|
578
|
-
const cartLines =
|
|
579
|
-
const customerId = _nullishCoalesce(_nullishCoalesce(options.customerId, () => ( _optionalChain([auth, 'optionalAccess',
|
|
663
|
+
const cartLines = _chunkCRVSCSGPcjs.useCartLines.call(void 0, );
|
|
664
|
+
const customerId = _nullishCoalesce(_nullishCoalesce(options.customerId, () => ( _optionalChain([auth, 'optionalAccess', _15 => _15.customerId]))), () => ( _optionalChain([site, 'optionalAccess', _16 => _16.defaults, 'optionalAccess', _17 => _17.customerId])));
|
|
580
665
|
const priceFn = options.queryFn;
|
|
581
666
|
const priceQueries = _reactquery.useQueries.call(void 0, {
|
|
582
667
|
queries: cartLines.map((line) => {
|
|
583
668
|
const quantity = _nullishCoalesce(line.quantity, () => ( 1));
|
|
584
669
|
if (priceFn) {
|
|
585
670
|
return {
|
|
586
|
-
queryKey: ["price", _optionalChain([line, 'access',
|
|
671
|
+
queryKey: ["price", _optionalChain([line, 'access', _18 => _18.itemId, 'optionalAccess', _19 => _19.toUpperCase, 'call', _20 => _20()]) || "", customerId, quantity],
|
|
587
672
|
queryFn: () => priceFn(line.itemId, customerId, quantity),
|
|
588
673
|
refetchOnReconnect: true,
|
|
589
674
|
refetchOnWindowFocus: false,
|
|
@@ -592,7 +677,7 @@ function useCartPricing(options = {}) {
|
|
|
592
677
|
};
|
|
593
678
|
}
|
|
594
679
|
const proxyOpts = proxy.pricing.priceEngine.list({
|
|
595
|
-
itemId: _optionalChain([line, 'access',
|
|
680
|
+
itemId: _optionalChain([line, 'access', _21 => _21.itemId, 'optionalAccess', _22 => _22.toUpperCase, 'call', _23 => _23()]) || "",
|
|
596
681
|
customerId: Number(customerId),
|
|
597
682
|
quantity
|
|
598
683
|
});
|
|
@@ -609,7 +694,7 @@ function useCartPricing(options = {}) {
|
|
|
609
694
|
const map = {};
|
|
610
695
|
cartLines.forEach((line, index) => {
|
|
611
696
|
const queryResult = priceQueries[index];
|
|
612
|
-
const priceData = _optionalChain([queryResult, 'optionalAccess',
|
|
697
|
+
const priceData = _optionalChain([queryResult, 'optionalAccess', _24 => _24.data]);
|
|
613
698
|
if (priceData) {
|
|
614
699
|
const unitPrice = deriveLineUnitPrice(priceData, line.quantity);
|
|
615
700
|
map[line.itemId.toUpperCase()] = {
|
|
@@ -622,7 +707,7 @@ function useCartPricing(options = {}) {
|
|
|
622
707
|
}, [cartLines, priceQueries]);
|
|
623
708
|
const getUnitPrice = _react.useMemo.call(void 0, () => {
|
|
624
709
|
return (itemId) => {
|
|
625
|
-
return _nullishCoalesce(_optionalChain([prices, 'access',
|
|
710
|
+
return _nullishCoalesce(_optionalChain([prices, 'access', _25 => _25[_optionalChain([itemId, 'optionalAccess', _26 => _26.toUpperCase, 'call', _27 => _27()])], 'optionalAccess', _28 => _28.unitPrice]), () => ( 0));
|
|
626
711
|
};
|
|
627
712
|
}, [prices]);
|
|
628
713
|
const getItemTotal = _react.useMemo.call(void 0, () => {
|
|
@@ -632,7 +717,7 @@ function useCartPricing(options = {}) {
|
|
|
632
717
|
}, [getUnitPrice]);
|
|
633
718
|
const subtotal = _react.useMemo.call(void 0, () => {
|
|
634
719
|
return cartLines.reduce((sum, line) => {
|
|
635
|
-
const unitPrice = _nullishCoalesce(_optionalChain([prices, 'access',
|
|
720
|
+
const unitPrice = _nullishCoalesce(_optionalChain([prices, 'access', _29 => _29[line.itemId.toUpperCase()], 'optionalAccess', _30 => _30.unitPrice]), () => ( 0));
|
|
636
721
|
return _augurutils.cleanMoney.call(void 0, sum + lineTotal(unitPrice, line.quantity));
|
|
637
722
|
}, 0);
|
|
638
723
|
}, [cartLines, prices]);
|
|
@@ -710,7 +795,7 @@ function deserialize(data) {
|
|
|
710
795
|
|
|
711
796
|
// src/persistence/apply-limits.ts
|
|
712
797
|
function applyLimits(data, limits) {
|
|
713
|
-
const queries = _optionalChain([data, 'access',
|
|
798
|
+
const queries = _optionalChain([data, 'access', _31 => _31.clientState, 'optionalAccess', _32 => _32.queries]);
|
|
714
799
|
if (!queries || Object.keys(limits).length === 0) return data;
|
|
715
800
|
const entries = queries;
|
|
716
801
|
const unlimited = [];
|
|
@@ -794,7 +879,7 @@ function createPersister(config) {
|
|
|
794
879
|
var CHECK_INTERVAL = _augurutils.toMillis.call(void 0, _augurutils.minutes.call(void 0, 5));
|
|
795
880
|
function useStorageMonitor(config) {
|
|
796
881
|
const { key, limits = {}, maxStorageMB = 3 } = config;
|
|
797
|
-
const limitKeysRef =
|
|
882
|
+
const limitKeysRef = _chunkCRVSCSGPcjs.useLatest.call(void 0, Object.keys(limits));
|
|
798
883
|
const limitCount = limitKeysRef.current.length;
|
|
799
884
|
_react.useEffect.call(void 0, () => {
|
|
800
885
|
const limitKeys = limitKeysRef.current;
|
|
@@ -812,7 +897,7 @@ function useStorageMonitor(config) {
|
|
|
812
897
|
const raw = storage.getItem(key);
|
|
813
898
|
if (!raw) return;
|
|
814
899
|
const parsed = JSON.parse(raw);
|
|
815
|
-
if (!_optionalChain([parsed, 'access',
|
|
900
|
+
if (!_optionalChain([parsed, 'access', _33 => _33.clientState, 'optionalAccess', _34 => _34.queries])) return;
|
|
816
901
|
parsed.clientState.queries = parsed.clientState.queries.filter(
|
|
817
902
|
(q) => {
|
|
818
903
|
if (!Array.isArray(q.queryKey)) return true;
|
|
@@ -840,14 +925,14 @@ function useAugurPersistence(config) {
|
|
|
840
925
|
setIsMounted(true);
|
|
841
926
|
}, []);
|
|
842
927
|
useStorageMonitor(config);
|
|
843
|
-
const isDev = typeof process !== "undefined" && _optionalChain([process, 'access',
|
|
928
|
+
const isDev = typeof process !== "undefined" && _optionalChain([process, 'access', _35 => _35.env, 'optionalAccess', _36 => _36["NODE_ENV"]]) === "development";
|
|
844
929
|
const { persistableKeys } = config;
|
|
845
930
|
const dehydrateOptions = _react.useMemo.call(void 0,
|
|
846
931
|
() => ({
|
|
847
932
|
shouldDehydrateQuery: (query) => {
|
|
848
933
|
const key = query.queryKey;
|
|
849
934
|
const hasHead = Array.isArray(key) && key.length > 0;
|
|
850
|
-
return
|
|
935
|
+
return _chunkCRVSCSGPcjs.shouldPersistOf.call(void 0,
|
|
851
936
|
hasHead,
|
|
852
937
|
query.state.status === "success",
|
|
853
938
|
hasHead && persistableKeys.includes(key[0])
|
|
@@ -868,11 +953,11 @@ function useAugurPersistence(config) {
|
|
|
868
953
|
|
|
869
954
|
function keyPathOf(key) {
|
|
870
955
|
const segments = _nullishCoalesce(key, () => ( []));
|
|
871
|
-
const n =
|
|
956
|
+
const n = _chunkCRVSCSGPcjs.leadingTextsFrom.call(void 0,
|
|
872
957
|
segments.map((s) => typeof s === "string"),
|
|
873
958
|
0
|
|
874
959
|
);
|
|
875
|
-
return
|
|
960
|
+
return _chunkCRVSCSGPcjs.keyPathFrom.call(void 0, segments, n);
|
|
876
961
|
}
|
|
877
962
|
function clearUserReadsOnWrite(queryClient, mutationKey) {
|
|
878
963
|
const writePath = keyPathOf(mutationKey);
|
|
@@ -925,5 +1010,5 @@ function userWriteClearing(getQueryClient) {
|
|
|
925
1010
|
|
|
926
1011
|
|
|
927
1012
|
|
|
928
|
-
exports.AugurHooksProvider = AugurHooksProvider; exports.clearCheckoutPersistence =
|
|
1013
|
+
exports.AugurHooksProvider = AugurHooksProvider; exports.clearCheckoutPersistence = _chunkCRVSCSGPcjs.clearCheckoutPersistence; exports.clearFromSession = _chunkCRVSCSGPcjs.clearFromSession; exports.clearUserReadsOnWrite = clearUserReadsOnWrite; exports.determineOrderReadiness = _chunkCRVSCSGPcjs.determineOrderReadiness; exports.executeBatchQuery = _chunkWJ4D5OCQcjs.executeBatchQuery; exports.getRegisteredQueryAction = _chunkWJ4D5OCQcjs.getRegisteredQueryAction; exports.keyPathOf = keyPathOf; exports.loadFromSession = _chunkCRVSCSGPcjs.loadFromSession; exports.registerQueryAction = _chunkWJ4D5OCQcjs.registerQueryAction; exports.saveToSession = _chunkCRVSCSGPcjs.saveToSession; exports.useAugurApi = useAugurApi; exports.useAugurApiOptional = useAugurApiOptional; exports.useAugurAuth = useAugurAuth; exports.useAugurCache = useAugurCache; exports.useAugurOptions = useAugurOptions; exports.useAugurPersistence = useAugurPersistence; exports.useAugurSite = useAugurSite; exports.useCartActions = useCartActions; exports.useCartHdrUid = _chunkCRVSCSGPcjs.useCartHdrUid; exports.useCartInitialization = useCartInitialization; exports.useCartLineCount = _chunkCRVSCSGPcjs.useCartLineCount; exports.useCartLines = _chunkCRVSCSGPcjs.useCartLines; exports.useCartPricing = useCartPricing; exports.useCartQuantityTotal = _chunkCRVSCSGPcjs.useCartQuantityTotal; exports.useCartStore = _chunkCRVSCSGPcjs.useCartStore; exports.useCheckoutPersistence = _chunkCRVSCSGPcjs.useCheckoutPersistence; exports.useClearCart = _chunkCRVSCSGPcjs.useClearCart; exports.useDebounce = useDebounce; exports.useFormatPrice = useFormatPrice; exports.useItemFiltersStore = useItemFiltersStore; exports.useModalLifecycle = useModalLifecycle; exports.useOrderReadiness = _chunkCRVSCSGPcjs.useOrderReadiness; exports.usePaginationPrefetch = usePaginationPrefetch; exports.usePaymentFlow = _chunkCRVSCSGPcjs.usePaymentFlow; exports.useSetCartHdrUid = _chunkCRVSCSGPcjs.useSetCartHdrUid; exports.useSetCartLines = _chunkCRVSCSGPcjs.useSetCartLines; exports.useStock = useStock; exports.userWriteClearing = userWriteClearing;
|
|
929
1014
|
//# sourceMappingURL=index.cjs.map
|