@bowlos/reservations 0.36.0 → 0.41.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.
Files changed (74) hide show
  1. package/AGENTS.md +300 -0
  2. package/HEADLESS.md +534 -10
  3. package/README.md +242 -2
  4. package/dist/{data-BJkB-tvM.d.cts → account-DEX2Lr78.d.cts} +208 -1
  5. package/dist/{data-BJkB-tvM.d.ts → account-DEX2Lr78.d.ts} +208 -1
  6. package/dist/booking-change-4DGu-B08.d.ts +1282 -0
  7. package/dist/booking-change-aK6P37FZ.d.cts +1282 -0
  8. package/dist/{chunk-3JSVEOKG.js → chunk-44WKP6MW.js} +32 -5
  9. package/dist/chunk-44WKP6MW.js.map +1 -0
  10. package/dist/{chunk-TEHRROVY.js → chunk-BWJHRJN6.js} +47 -192
  11. package/dist/chunk-BWJHRJN6.js.map +1 -0
  12. package/dist/{chunk-Y3YSDO3H.js → chunk-FMFHNBDH.js} +56 -5
  13. package/dist/chunk-FMFHNBDH.js.map +1 -0
  14. package/dist/chunk-I37IJNYU.js +139 -0
  15. package/dist/chunk-I37IJNYU.js.map +1 -0
  16. package/dist/chunk-VJIS56OO.js +717 -0
  17. package/dist/chunk-VJIS56OO.js.map +1 -0
  18. package/dist/cli.cjs +29 -3
  19. package/dist/cli.cjs.map +1 -1
  20. package/dist/components.cjs +1595 -2
  21. package/dist/components.cjs.map +1 -1
  22. package/dist/components.d.cts +208 -7
  23. package/dist/components.d.ts +208 -7
  24. package/dist/components.js +1045 -7
  25. package/dist/components.js.map +1 -1
  26. package/dist/index.cjs +270 -3
  27. package/dist/index.cjs.map +1 -1
  28. package/dist/index.d.cts +56 -5
  29. package/dist/index.d.ts +56 -5
  30. package/dist/index.js +58 -3
  31. package/dist/index.js.map +1 -1
  32. package/dist/payments.cjs +203 -0
  33. package/dist/payments.cjs.map +1 -1
  34. package/dist/payments.d.cts +16 -2
  35. package/dist/payments.d.ts +16 -2
  36. package/dist/payments.js +78 -2
  37. package/dist/payments.js.map +1 -1
  38. package/dist/{react-0MyyTtE4.d.ts → react-CrRciA7I.d.ts} +2 -2
  39. package/dist/{react-CWAG4cW0.d.cts → react-QJrsaOnN.d.cts} +2 -2
  40. package/dist/react.cjs +758 -27
  41. package/dist/react.cjs.map +1 -1
  42. package/dist/react.d.cts +139 -12
  43. package/dist/react.d.ts +139 -12
  44. package/dist/react.js +72 -4
  45. package/dist/react.js.map +1 -1
  46. package/package.json +8 -2
  47. package/templates/center-site/README.md +5 -0
  48. package/templates/center-site/app/account/game-cards/page.tsx +17 -0
  49. package/templates/center-site/app/account/layout.tsx +16 -0
  50. package/templates/center-site/app/account/memberships/[id]/page.tsx +23 -0
  51. package/templates/center-site/app/account/memberships/page.tsx +33 -0
  52. package/templates/center-site/app/account/orders/page.tsx +17 -0
  53. package/templates/center-site/app/account/page.tsx +14 -0
  54. package/templates/center-site/app/account/payment-methods/page.tsx +23 -0
  55. package/templates/center-site/app/account/privacy/page.tsx +17 -0
  56. package/templates/center-site/app/account/profile/page.tsx +45 -0
  57. package/templates/center-site/app/account/reservations/[displayId]/change/page.tsx +46 -0
  58. package/templates/center-site/app/account/reservations/[displayId]/page.tsx +41 -0
  59. package/templates/center-site/app/account/reservations/page.tsx +35 -0
  60. package/templates/center-site/app/account/security/page.tsx +17 -0
  61. package/templates/center-site/app/events/[slug]/page.tsx +130 -0
  62. package/templates/center-site/app/events/page.tsx +57 -0
  63. package/templates/center-site/app/pay/[token]/page.tsx +53 -0
  64. package/templates/center-site/app/site-header.tsx +1 -0
  65. package/templates/center-site/lib/reservation.ts +14 -0
  66. package/templates/center-site/package.json +1 -1
  67. package/templates/center-site/tsconfig.json +7 -9
  68. package/dist/account-DfM2COaz.d.ts +0 -210
  69. package/dist/account-oCvYWmO9.d.cts +0 -210
  70. package/dist/catalog-DbhdwmnX.d.cts +0 -224
  71. package/dist/catalog-XkjgPI5C.d.ts +0 -224
  72. package/dist/chunk-3JSVEOKG.js.map +0 -1
  73. package/dist/chunk-TEHRROVY.js.map +0 -1
  74. package/dist/chunk-Y3YSDO3H.js.map +0 -1
@@ -0,0 +1,717 @@
1
+ import { previewAccountDeletion, deleteMyAccount, previewBookingChange, createBookingChangePayment, getPendingBookingChange } from './chunk-I37IJNYU.js';
2
+ import { useBowlosClient, useBowlosMutation, useBowlosQuery, useIdempotentMutation } from './chunk-BWJHRJN6.js';
3
+ import { BowlosApiError, BOWLOS_ERROR_CODES, createBooking, createCheckoutPaymentIntent, getCheckoutStatus, abandonCheckout } from './chunk-44WKP6MW.js';
4
+ import { useState, useRef, useCallback, useEffect } from 'react';
5
+
6
+ var DEFAULT_POLL_MS = 2500;
7
+ function useBookingFlow() {
8
+ const client = useBowlosClient();
9
+ const [status, setStatus] = useState("idle");
10
+ const [hold, setHold] = useState(null);
11
+ const [refToken, setRefToken] = useState(null);
12
+ const [paymentIntent, setPaymentIntent] = useState(null);
13
+ const [reservation, setReservation] = useState(null);
14
+ const [error, setError] = useState(null);
15
+ const refTokenRef = useRef(null);
16
+ const pollRef = useRef(null);
17
+ const stopPolling = useCallback(() => {
18
+ if (pollRef.current !== null) {
19
+ clearInterval(pollRef.current);
20
+ pollRef.current = null;
21
+ }
22
+ }, []);
23
+ useEffect(() => stopPolling, [stopPolling]);
24
+ const reset = useCallback(() => {
25
+ stopPolling();
26
+ refTokenRef.current = null;
27
+ setRefToken(null);
28
+ setHold(null);
29
+ setPaymentIntent(null);
30
+ setReservation(null);
31
+ setError(null);
32
+ setStatus("idle");
33
+ }, [stopPolling]);
34
+ const applyStatus = useCallback(
35
+ (s) => {
36
+ switch (s.status) {
37
+ case "paid_materialized":
38
+ setReservation({
39
+ reservationId: s.reservationId,
40
+ reservationDisplayId: s.reservationDisplayId
41
+ });
42
+ setStatus("confirmed");
43
+ stopPolling();
44
+ break;
45
+ case "expired":
46
+ setStatus("expired");
47
+ stopPolling();
48
+ break;
49
+ case "abandoned":
50
+ setStatus("abandoned");
51
+ stopPolling();
52
+ break;
53
+ case "payment_failed_retryable":
54
+ setStatus("failed");
55
+ stopPolling();
56
+ break;
57
+ case "not_found":
58
+ setError(new BowlosApiError(BOWLOS_ERROR_CODES.NOT_FOUND, "Checkout not found.", 404));
59
+ setStatus("error");
60
+ stopPolling();
61
+ break;
62
+ }
63
+ },
64
+ [stopPolling]
65
+ );
66
+ const startHold = useCallback(
67
+ async (args) => {
68
+ stopPolling();
69
+ setError(null);
70
+ setPaymentIntent(null);
71
+ setReservation(null);
72
+ setStatus("holding");
73
+ try {
74
+ const h = await createBooking(client, args);
75
+ setHold(h);
76
+ const rt = typeof h.checkoutRefToken === "string" ? h.checkoutRefToken : null;
77
+ refTokenRef.current = rt;
78
+ setRefToken(rt);
79
+ if (!h.requiresPayment) {
80
+ setReservation({
81
+ reservationId: h.reservationId ?? null,
82
+ reservationDisplayId: h.reservationDisplayId ?? null
83
+ });
84
+ setStatus("confirmed");
85
+ } else if (rt) {
86
+ setStatus("held");
87
+ } else {
88
+ setError(
89
+ new BowlosApiError(
90
+ "UNSUPPORTED_BOOKING_PATH",
91
+ "This booking requires payment but no checkout hold was returned.",
92
+ 0
93
+ )
94
+ );
95
+ setStatus("error");
96
+ }
97
+ } catch (e) {
98
+ if (e instanceof BowlosApiError) setError(e);
99
+ setStatus("error");
100
+ }
101
+ },
102
+ [client, stopPolling]
103
+ );
104
+ const preparePayment = useCallback(async () => {
105
+ const rt = refTokenRef.current;
106
+ if (!rt) return null;
107
+ setError(null);
108
+ setStatus("preparingPayment");
109
+ try {
110
+ const pi = await createCheckoutPaymentIntent(client, rt);
111
+ setPaymentIntent(pi);
112
+ setStatus("awaitingPayment");
113
+ return pi;
114
+ } catch (e) {
115
+ if (e instanceof BowlosApiError) setError(e);
116
+ setStatus("error");
117
+ return null;
118
+ }
119
+ }, [client]);
120
+ const pollStatus = useCallback(async () => {
121
+ const rt = refTokenRef.current;
122
+ if (!rt) return null;
123
+ try {
124
+ const s = await getCheckoutStatus(client, rt);
125
+ applyStatus(s);
126
+ return s;
127
+ } catch (e) {
128
+ if (e instanceof BowlosApiError) setError(e);
129
+ return null;
130
+ }
131
+ }, [client, applyStatus]);
132
+ const startPolling = useCallback(
133
+ (intervalMs = DEFAULT_POLL_MS) => {
134
+ stopPolling();
135
+ void pollStatus();
136
+ pollRef.current = setInterval(() => {
137
+ void pollStatus();
138
+ }, intervalMs);
139
+ },
140
+ [pollStatus, stopPolling]
141
+ );
142
+ const abandon = useCallback(async () => {
143
+ stopPolling();
144
+ const rt = refTokenRef.current;
145
+ if (rt) {
146
+ try {
147
+ await abandonCheckout(client, rt);
148
+ } catch {
149
+ }
150
+ }
151
+ setStatus("abandoned");
152
+ }, [client, stopPolling]);
153
+ return {
154
+ status,
155
+ hold,
156
+ refToken,
157
+ paymentIntent,
158
+ reservation,
159
+ requiresPayment: hold ? hold.requiresPayment : null,
160
+ error,
161
+ startHold,
162
+ preparePayment,
163
+ pollStatus,
164
+ startPolling,
165
+ stopPolling,
166
+ abandon,
167
+ reset
168
+ };
169
+ }
170
+ function useUpdateMyProfile() {
171
+ return useBowlosMutation("updateMyProfile", {
172
+ auth: true
173
+ });
174
+ }
175
+ function useMyCommunicationPrefs(args, options) {
176
+ return useBowlosQuery("listMyMarketingPrefs", args, {
177
+ ...options,
178
+ auth: true
179
+ });
180
+ }
181
+ function useSetMyCommunicationPref() {
182
+ return useBowlosMutation(
183
+ "setMyMarketingPref",
184
+ { auth: true }
185
+ );
186
+ }
187
+ function useSetMyMobile() {
188
+ return useBowlosMutation("setMyMobile", { auth: true });
189
+ }
190
+ function useSubmitSupportRequest() {
191
+ return useBowlosMutation(
192
+ "submitMySupportRequest",
193
+ { auth: true }
194
+ );
195
+ }
196
+ function useDeleteMyAccount() {
197
+ const client = useBowlosClient();
198
+ const mutation = useBowlosMutation(
199
+ "deleteMyAccount",
200
+ { auth: true }
201
+ );
202
+ const run = useCallback(
203
+ async (args) => {
204
+ const result = await mutation.run(args);
205
+ await client.signOut();
206
+ return result;
207
+ },
208
+ [client, mutation.run]
209
+ );
210
+ return { ...mutation, run };
211
+ }
212
+ function useExportMyData() {
213
+ return useBowlosMutation("exportMyData", {
214
+ auth: true
215
+ });
216
+ }
217
+ function useMyPackageOrders(args, options) {
218
+ return useBowlosQuery("listMyPackageOrders", args, {
219
+ ...options,
220
+ auth: true
221
+ });
222
+ }
223
+ function useMyPackageOrder(args, options) {
224
+ return useBowlosQuery("getMyPackageOrder", args, {
225
+ ...options,
226
+ auth: true
227
+ });
228
+ }
229
+ function useMyMembershipMembers(args, options) {
230
+ return useBowlosQuery("listMyMembershipMembers", args, {
231
+ ...options,
232
+ auth: true
233
+ });
234
+ }
235
+ function useAddMyMembershipMember() {
236
+ return useBowlosMutation(
237
+ "addMyMembershipMember",
238
+ { auth: true }
239
+ );
240
+ }
241
+ function useMyLoyaltyHistory(args, options) {
242
+ return useBowlosQuery("listMyLoyaltyHistory", args, {
243
+ ...options,
244
+ auth: true
245
+ });
246
+ }
247
+ function useReceipt(args, options) {
248
+ return useBowlosQuery("getReservationByDisplayId", args, {
249
+ ...options,
250
+ auth: false
251
+ });
252
+ }
253
+ function useProduct(args, options) {
254
+ return useBowlosQuery("getPublicProduct", args, { ...options, auth: false });
255
+ }
256
+ function useMembership(args, options) {
257
+ return useBowlosQuery("getPublicMembership", args, {
258
+ ...options,
259
+ auth: false
260
+ });
261
+ }
262
+ function useGameCard(args, options) {
263
+ return useBowlosQuery("getPublicGameCard", args, {
264
+ ...options,
265
+ auth: false
266
+ });
267
+ }
268
+ function useProductSubtypes(args, options) {
269
+ return useBowlosQuery("listSubtypesForProduct", args, {
270
+ ...options,
271
+ auth: false
272
+ });
273
+ }
274
+ function useBrandMemberships(args, options) {
275
+ return useBowlosQuery("listBrandMemberships", args, {
276
+ ...options,
277
+ auth: false
278
+ });
279
+ }
280
+ function usePackagesLabel(args, options) {
281
+ return useBowlosQuery("getBrandPackagesLabelPublic", args, {
282
+ ...options,
283
+ auth: false
284
+ });
285
+ }
286
+ function useSlotPrices(args, options) {
287
+ return useBowlosQuery("previewSlotPrices", args, {
288
+ ...options,
289
+ auth: false
290
+ });
291
+ }
292
+ function useHours(args, options) {
293
+ return useBowlosQuery("listPublicHours", args, { ...options, auth: false });
294
+ }
295
+ function useOperatingHours(args, options) {
296
+ return useBowlosQuery("getOperatingHours", args, {
297
+ ...options,
298
+ auth: false
299
+ });
300
+ }
301
+ function useCenterOperatingHoursForType(args, options) {
302
+ return useBowlosQuery(
303
+ "getCenterOperatingHoursForType",
304
+ args,
305
+ { ...options, auth: false }
306
+ );
307
+ }
308
+ function useCenters(args, options) {
309
+ return useBowlosQuery("listPublicCenters", args, {
310
+ ...options,
311
+ auth: false
312
+ });
313
+ }
314
+ function useCancelMyMembership() {
315
+ return useIdempotentMutation(
316
+ "cancelMyMembership",
317
+ { auth: true }
318
+ );
319
+ }
320
+ function useApplyMyModification() {
321
+ return useIdempotentMutation(
322
+ "applyMyModification",
323
+ { auth: true }
324
+ );
325
+ }
326
+ function useAccountDeletion(args) {
327
+ const client = useBowlosClient();
328
+ const [preview, setPreview] = useState();
329
+ const [status, setStatus] = useState("loading");
330
+ const [error, setError] = useState();
331
+ const generation = useRef(0);
332
+ const busy = useRef(false);
333
+ const phrase = useRef(void 0);
334
+ const timer = useRef(void 0);
335
+ const wake = useRef(void 0);
336
+ const reload = useCallback(async () => {
337
+ const current = generation.current;
338
+ const value = await previewAccountDeletion(client, { brandId: args.brandId });
339
+ if (generation.current === current) setPreview(value);
340
+ return value;
341
+ }, [client, args.brandId]);
342
+ useEffect(() => {
343
+ const current = ++generation.current;
344
+ busy.current = false;
345
+ phrase.current = void 0;
346
+ setPreview(void 0);
347
+ setError(void 0);
348
+ setStatus("loading");
349
+ void previewAccountDeletion(client, { brandId: args.brandId }).then(
350
+ (value) => {
351
+ if (generation.current === current) {
352
+ setPreview(value);
353
+ setStatus("ready");
354
+ }
355
+ },
356
+ (e) => {
357
+ if (generation.current === current) {
358
+ setError(e);
359
+ setStatus("error");
360
+ }
361
+ }
362
+ );
363
+ return () => {
364
+ generation.current++;
365
+ clearTimeout(timer.current);
366
+ wake.current?.();
367
+ };
368
+ }, [client, args.brandId]);
369
+ const confirm = useCallback(
370
+ async (typedPhrase) => {
371
+ if (busy.current || !preview) return;
372
+ if (typedPhrase !== preview.confirmPhrase) {
373
+ setError(
374
+ new BowlosApiError("VALIDATION_FAILED", "Enter the confirmation phrase exactly.", 400)
375
+ );
376
+ return;
377
+ }
378
+ busy.current = true;
379
+ phrase.current = typedPhrase;
380
+ const current = generation.current;
381
+ setError(void 0);
382
+ setStatus("deleting");
383
+ try {
384
+ for (let attempt = 0; attempt <= 5; attempt++) {
385
+ if (generation.current !== current) return;
386
+ try {
387
+ await deleteMyAccount(client, {
388
+ brandId: args.brandId,
389
+ confirmPhrase: typedPhrase,
390
+ previewToken: preview.previewToken
391
+ });
392
+ if (generation.current === current) setStatus("deleted");
393
+ return;
394
+ } catch (e) {
395
+ if (generation.current !== current) return;
396
+ if (e instanceof BowlosApiError && e.code === "DELETION_PREVIEW_STALE") {
397
+ await reload();
398
+ if (generation.current === current) {
399
+ setError(e);
400
+ setStatus("stale");
401
+ }
402
+ return;
403
+ }
404
+ if (!(e instanceof BowlosApiError) || e.code !== "DELETION_PENDING_STRIPE") throw e;
405
+ setStatus("pending");
406
+ if (attempt === 5) {
407
+ setError(e);
408
+ return;
409
+ }
410
+ const seconds = e.details?.retryAfterSec;
411
+ const delay = typeof seconds === "number" && seconds >= 0 ? seconds * 1e3 : 1e3;
412
+ await new Promise((resolve) => {
413
+ wake.current = resolve;
414
+ timer.current = setTimeout(resolve, Math.min(delay * 2 ** attempt, 2147483647));
415
+ });
416
+ }
417
+ }
418
+ } catch (e) {
419
+ if (generation.current === current) {
420
+ setError(e);
421
+ setStatus("error");
422
+ }
423
+ } finally {
424
+ if (generation.current === current) busy.current = false;
425
+ }
426
+ },
427
+ [client, args.brandId, preview, reload]
428
+ );
429
+ const retry = useCallback(async () => {
430
+ if (phrase.current && preview && status !== "stale") await confirm(phrase.current);
431
+ else {
432
+ try {
433
+ await reload();
434
+ setError(void 0);
435
+ setStatus("ready");
436
+ } catch (e) {
437
+ setError(e);
438
+ setStatus("error");
439
+ }
440
+ }
441
+ }, [confirm, preview, reload, status]);
442
+ return {
443
+ preview,
444
+ consequences: preview,
445
+ confirmPhrase: preview?.confirmPhrase,
446
+ status,
447
+ error,
448
+ confirm,
449
+ retry
450
+ };
451
+ }
452
+
453
+ // src/toolkit-hooks.tsx
454
+ function useBrandEventOffers(args, options) {
455
+ return useBowlosQuery("listPublicEventOffersForBrand", args, {
456
+ ...options,
457
+ auth: false
458
+ });
459
+ }
460
+ function useMyGameCard(args, options) {
461
+ return useBowlosQuery("getMyGameCard", args, { ...options, auth: true });
462
+ }
463
+ function useMyGameCardRedemptions(args, options) {
464
+ return useBowlosQuery("getMyGameCardRedemptions", args, {
465
+ ...options,
466
+ auth: true
467
+ });
468
+ }
469
+ function useMyGameCardHistory(args, options) {
470
+ return useBowlosQuery("getMyGameCardRedemptionsPage", args, {
471
+ ...options,
472
+ auth: true
473
+ });
474
+ }
475
+ function useWalletPassUrl() {
476
+ return useBowlosMutation("getMyWalletPassUrl", {
477
+ auth: true
478
+ });
479
+ }
480
+ function useMyHold(args, options) {
481
+ return useBowlosQuery("getMyHoldGroup", args, { ...options, auth: true });
482
+ }
483
+ function useExtendMyHold() {
484
+ return useBowlosMutation("customerExtendMyHold", {
485
+ auth: true
486
+ });
487
+ }
488
+ function useReleaseMyHold() {
489
+ return useBowlosMutation("customerReleaseMyHold", { auth: true });
490
+ }
491
+ function useRequestEmailVerification() {
492
+ return useBowlosMutation(
493
+ "requestEmailVerification",
494
+ { auth: true }
495
+ );
496
+ }
497
+ function useConfirmEmailVerification() {
498
+ return useBowlosMutation("confirmEmailVerification", {
499
+ auth: true
500
+ });
501
+ }
502
+ function useEmailVerificationStatus(args, options) {
503
+ return useBowlosQuery("getEmailVerificationStatus", args, {
504
+ ...options,
505
+ auth: true
506
+ });
507
+ }
508
+ function useEmailVerificationSendState(args, options) {
509
+ return useBowlosQuery("getEmailVerificationSendState", args, {
510
+ ...options,
511
+ auth: true
512
+ });
513
+ }
514
+ function useCancellationPolicy(args, options) {
515
+ return useBowlosQuery("getCancellationPolicy", args, {
516
+ ...options,
517
+ auth: false
518
+ });
519
+ }
520
+ function useCancelMyPendingBooking() {
521
+ return useBowlosMutation(
522
+ "cancelMyPendingReservation",
523
+ { auth: true }
524
+ );
525
+ }
526
+ function useOpenMembershipBillingPortal() {
527
+ return useBowlosMutation(
528
+ "createBillingPortalSession",
529
+ { auth: true }
530
+ );
531
+ }
532
+ function usePayLink(args, options) {
533
+ return useBowlosQuery("getPayLinkInfo", args, { ...options, auth: false });
534
+ }
535
+ function useCreatePayLinkPayment() {
536
+ const mutation = useBowlosMutation(
537
+ "createPayIntentForPayLinkToken",
538
+ { auth: false }
539
+ );
540
+ const run = useCallback(
541
+ (args) => mutation.run({ token: args.token, brandId: args.brandId, centerId: args.centerId }),
542
+ [mutation.run]
543
+ );
544
+ return { ...mutation, run };
545
+ }
546
+ function useBookingChange(scope) {
547
+ const client = useBowlosClient();
548
+ const applyMutation = useIdempotentMutation(
549
+ "applyMyModification",
550
+ { auth: true }
551
+ );
552
+ const [status, setStatus] = useState("idle");
553
+ const [preview, setPreview] = useState();
554
+ const [payment, setPayment] = useState();
555
+ const [pending, setPending] = useState();
556
+ const [pendingId, setPendingId] = useState();
557
+ const [error, setError] = useState();
558
+ const generation = useRef(0);
559
+ const busy = useRef(false);
560
+ const reset = useCallback(() => {
561
+ generation.current++;
562
+ busy.current = false;
563
+ setStatus("idle");
564
+ setPreview(void 0);
565
+ setPayment(void 0);
566
+ setPending(void 0);
567
+ setPendingId(void 0);
568
+ setError(void 0);
569
+ applyMutation.reset();
570
+ }, [applyMutation.reset]);
571
+ useEffect(() => {
572
+ reset();
573
+ return () => {
574
+ generation.current++;
575
+ };
576
+ }, [scope.brandId, scope.centerId, reset]);
577
+ const loadPreview = useCallback(
578
+ async (args) => {
579
+ if (busy.current) return;
580
+ busy.current = true;
581
+ const current = ++generation.current;
582
+ setStatus("previewing");
583
+ setError(void 0);
584
+ setPayment(void 0);
585
+ setPendingId(void 0);
586
+ try {
587
+ const value = await previewBookingChange(client, { ...args, ...scope });
588
+ if (generation.current === current) {
589
+ setPreview(value);
590
+ setStatus("preview");
591
+ }
592
+ return value;
593
+ } catch (e) {
594
+ if (generation.current === current) {
595
+ setError(e);
596
+ setStatus("error");
597
+ }
598
+ throw e;
599
+ } finally {
600
+ if (generation.current === current) busy.current = false;
601
+ }
602
+ },
603
+ [client, scope.brandId, scope.centerId]
604
+ );
605
+ const apply = useCallback(
606
+ async (args) => {
607
+ if (busy.current) return;
608
+ busy.current = true;
609
+ const current = generation.current;
610
+ setError(void 0);
611
+ setStatus("applying");
612
+ try {
613
+ const value = await applyMutation.run({ ...args, ...scope });
614
+ if (generation.current !== current) return value;
615
+ if (value.requiresPayment) {
616
+ setPendingId(value.pendingModificationId);
617
+ setStatus("pay");
618
+ } else setStatus("done");
619
+ return value;
620
+ } catch (e) {
621
+ if (generation.current === current) {
622
+ setError(e);
623
+ setStatus("error");
624
+ }
625
+ throw e;
626
+ } finally {
627
+ if (generation.current === current) busy.current = false;
628
+ }
629
+ },
630
+ [applyMutation.run, scope.brandId, scope.centerId]
631
+ );
632
+ const createPayment = useCallback(async () => {
633
+ if (!pendingId || busy.current || status !== "pay") return;
634
+ busy.current = true;
635
+ const current = generation.current;
636
+ setError(void 0);
637
+ try {
638
+ const value = await createBookingChangePayment(client, {
639
+ ...scope,
640
+ pendingModificationId: pendingId
641
+ });
642
+ if (generation.current === current) setPayment(value);
643
+ return value;
644
+ } catch (e) {
645
+ if (generation.current === current) setError(e);
646
+ throw e;
647
+ } finally {
648
+ if (generation.current === current) busy.current = false;
649
+ }
650
+ }, [client, pendingId, scope.brandId, scope.centerId, status]);
651
+ const resume = useCallback((args) => {
652
+ generation.current++;
653
+ busy.current = false;
654
+ setPayment(void 0);
655
+ setError(void 0);
656
+ setPendingId(args.pendingModificationId);
657
+ setStatus("pay");
658
+ }, []);
659
+ useEffect(() => {
660
+ if (!pendingId || status !== "polling" && status !== "pay") return;
661
+ let cancelled = false;
662
+ let timer;
663
+ const poll = async () => {
664
+ try {
665
+ const value = await getPendingBookingChange(client, {
666
+ ...scope,
667
+ pendingModificationId: pendingId
668
+ });
669
+ if (cancelled) return;
670
+ setPending(value);
671
+ setError(void 0);
672
+ if (value.status === "applied") {
673
+ setStatus("done");
674
+ return;
675
+ }
676
+ if (value.status !== "pending_payment") {
677
+ setStatus(value.status);
678
+ return;
679
+ }
680
+ if (value.expiresAt <= Date.now()) {
681
+ setStatus("expired");
682
+ return;
683
+ }
684
+ } catch (e) {
685
+ if (cancelled) return;
686
+ setError(e);
687
+ }
688
+ timer = setTimeout(() => void poll(), 1500);
689
+ };
690
+ void poll();
691
+ return () => {
692
+ cancelled = true;
693
+ clearTimeout(timer);
694
+ };
695
+ }, [client, scope.brandId, scope.centerId, pendingId, status]);
696
+ const paymentConfirmed = useCallback(() => {
697
+ if (pendingId) setStatus("polling");
698
+ }, [pendingId]);
699
+ return {
700
+ status,
701
+ preview,
702
+ payment,
703
+ pending,
704
+ pendingModificationId: pendingId,
705
+ error,
706
+ loadPreview,
707
+ apply,
708
+ createPayment,
709
+ paymentConfirmed,
710
+ resume,
711
+ reset
712
+ };
713
+ }
714
+
715
+ export { useAccountDeletion, useAddMyMembershipMember, useApplyMyModification, useBookingChange, useBookingFlow, useBrandEventOffers, useBrandMemberships, useCancelMyMembership, useCancelMyPendingBooking, useCancellationPolicy, useCenterOperatingHoursForType, useCenters, useConfirmEmailVerification, useCreatePayLinkPayment, useDeleteMyAccount, useEmailVerificationSendState, useEmailVerificationStatus, useExportMyData, useExtendMyHold, useGameCard, useHours, useMembership, useMyCommunicationPrefs, useMyGameCard, useMyGameCardHistory, useMyGameCardRedemptions, useMyHold, useMyLoyaltyHistory, useMyMembershipMembers, useMyPackageOrder, useMyPackageOrders, useOpenMembershipBillingPortal, useOperatingHours, usePackagesLabel, usePayLink, useProduct, useProductSubtypes, useReceipt, useReleaseMyHold, useRequestEmailVerification, useSetMyCommunicationPref, useSetMyMobile, useSlotPrices, useSubmitSupportRequest, useUpdateMyProfile, useWalletPassUrl };
716
+ //# sourceMappingURL=chunk-VJIS56OO.js.map
717
+ //# sourceMappingURL=chunk-VJIS56OO.js.map