@bowlos/reservations 0.43.0 → 1.0.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 (56) hide show
  1. package/AGENTS.md +14 -5
  2. package/CHANGELOG.md +22 -0
  3. package/HEADLESS.md +126 -41
  4. package/README.md +16 -0
  5. package/dist/{account-B4sZBmPI.d.cts → account-b8chVpED.d.cts} +27 -1
  6. package/dist/{account-B4sZBmPI.d.ts → account-b8chVpED.d.ts} +27 -1
  7. package/dist/{booking-change-DzYs9133.d.ts → booking-change-B-ADuVEz.d.cts} +77 -2
  8. package/dist/{booking-change-Dd4PVgd3.d.cts → booking-change-BrJ-XESC.d.ts} +77 -2
  9. package/dist/chunk-43WZ6TLQ.js +12 -0
  10. package/dist/chunk-43WZ6TLQ.js.map +1 -0
  11. package/dist/{chunk-4JMGS4YB.js → chunk-CTJODEHR.js} +27 -6
  12. package/dist/chunk-CTJODEHR.js.map +1 -0
  13. package/dist/{chunk-YAXBZJMI.js → chunk-EPYGIJRJ.js} +20 -3
  14. package/dist/chunk-EPYGIJRJ.js.map +1 -0
  15. package/dist/{chunk-YQRTBGXU.js → chunk-EXEKCMQ2.js} +57 -22
  16. package/dist/chunk-EXEKCMQ2.js.map +1 -0
  17. package/dist/{chunk-V4JRDYW4.js → chunk-IDRTMFJJ.js} +8 -3
  18. package/dist/chunk-IDRTMFJJ.js.map +1 -0
  19. package/dist/{chunk-T2E6AEC7.js → chunk-LFFANITL.js} +4 -11
  20. package/dist/chunk-LFFANITL.js.map +1 -0
  21. package/dist/components.cjs +357 -131
  22. package/dist/components.cjs.map +1 -1
  23. package/dist/components.d.cts +11 -5
  24. package/dist/components.d.ts +11 -5
  25. package/dist/components.js +200 -65
  26. package/dist/components.js.map +1 -1
  27. package/dist/index.cjs +34 -0
  28. package/dist/index.cjs.map +1 -1
  29. package/dist/index.d.cts +4 -4
  30. package/dist/index.d.ts +4 -4
  31. package/dist/index.js +5 -4
  32. package/dist/index.js.map +1 -1
  33. package/dist/payments.cjs.map +1 -1
  34. package/dist/payments.d.cts +1 -1
  35. package/dist/payments.d.ts +1 -1
  36. package/dist/payments.js +5 -4
  37. package/dist/payments.js.map +1 -1
  38. package/dist/{react-C6NWC80d.d.cts → react-cqGEohr0.d.cts} +4 -2
  39. package/dist/{react-DVdtpw5n.d.ts → react-s4J-e10i.d.ts} +4 -2
  40. package/dist/react.cjs +90 -19
  41. package/dist/react.cjs.map +1 -1
  42. package/dist/react.d.cts +11 -5
  43. package/dist/react.d.ts +11 -5
  44. package/dist/react.js +5 -5
  45. package/package.json +2 -1
  46. package/templates/center-site/README.md +1 -0
  47. package/templates/center-site/app/book/event-reservation-form.tsx +276 -0
  48. package/templates/center-site/app/book/page.tsx +107 -49
  49. package/templates/center-site/app/catalog/page.tsx +3 -1
  50. package/templates/center-site/app/events/[slug]/page.tsx +7 -10
  51. package/templates/center-site/package.json +1 -1
  52. package/dist/chunk-4JMGS4YB.js.map +0 -1
  53. package/dist/chunk-T2E6AEC7.js.map +0 -1
  54. package/dist/chunk-V4JRDYW4.js.map +0 -1
  55. package/dist/chunk-YAXBZJMI.js.map +0 -1
  56. package/dist/chunk-YQRTBGXU.js.map +0 -1
package/dist/react.cjs CHANGED
@@ -12,12 +12,25 @@ var BOWLOS_ERROR_CODES = {
12
12
  API_KEY_INVALID: "API_KEY_INVALID",
13
13
  ORIGIN_NOT_ALLOWED: "ORIGIN_NOT_ALLOWED",
14
14
  RATE_LIMITED: "RATE_LIMITED",
15
+ // Auth
16
+ PASSWORD_TOO_WEAK: "PASSWORD_TOO_WEAK",
15
17
  CURRENT_PASSWORD_INCORRECT: "CURRENT_PASSWORD_INCORRECT",
16
18
  CURRENT_PASSWORD_REQUIRED: "CURRENT_PASSWORD_REQUIRED",
17
19
  INVALID_CREDENTIALS: "INVALID_CREDENTIALS",
20
+ SIGNUP_FAILED: "SIGNUP_FAILED",
21
+ // Shared backend codes
22
+ VALIDATION_FAILED: "VALIDATION_FAILED",
18
23
  PERMISSION_DENIED: "PERMISSION_DENIED",
19
24
  SCOPE_REVOKED: "SCOPE_REVOKED",
20
25
  NOT_FOUND: "NOT_FOUND",
26
+ VERSION_CONFLICT: "VERSION_CONFLICT",
27
+ PRICING_SNAPSHOT_STALE: "PRICING_SNAPSHOT_STALE",
28
+ PAYMENTS_NOT_CONNECTED: "PAYMENTS_NOT_CONNECTED",
29
+ CONNECT_ACCOUNT_RESTRICTED: "CONNECT_ACCOUNT_RESTRICTED",
30
+ BILLING_PORTAL_UNAVAILABLE: "BILLING_PORTAL_UNAVAILABLE",
31
+ RETURN_URL_NOT_ALLOWED: "RETURN_URL_NOT_ALLOWED",
32
+ CONFLICT_RETRY: "CONFLICT_RETRY",
33
+ CHECKOUT_EXPIRED: "CHECKOUT_EXPIRED",
21
34
  // Client-side
22
35
  ROUTE_NOT_FOUND: "ROUTE_NOT_FOUND",
23
36
  NETWORK_ERROR: "NETWORK_ERROR",
@@ -438,29 +451,48 @@ function useBowlosQuery(name, args = {}, options = {}) {
438
451
  const client = useBowlosClient();
439
452
  const auth = options.auth ?? false;
440
453
  const enabled = options.enabled ?? true;
441
- const [data, setData] = react.useState(null);
442
- const [error, setError] = react.useState(null);
443
- const [loading, setLoading] = react.useState(enabled);
454
+ const keepPreviousData = options.keepPreviousData ?? true;
455
+ const [state, setState] = react.useState(null);
456
+ const request = react.useRef(0);
444
457
  const argsKey = JSON.stringify(args);
458
+ const key = react.useMemo(
459
+ () => ({ client, name, argsKey, auth, enabled }),
460
+ [client, name, argsKey, auth, enabled]
461
+ );
445
462
  const refetch = react.useCallback(async () => {
446
- setLoading(true);
447
- setError(null);
463
+ const id = ++request.current;
464
+ setState((previous) => ({
465
+ key,
466
+ data: keepPreviousData || previous?.key === key ? previous?.data ?? null : null,
467
+ error: null,
468
+ loading: true
469
+ }));
448
470
  try {
449
- const result = await client.call(name, JSON.parse(argsKey), {
450
- auth
451
- });
452
- setData(result);
471
+ const data = await key.client.call(
472
+ key.name,
473
+ JSON.parse(key.argsKey),
474
+ { auth: key.auth }
475
+ );
476
+ if (request.current === id) setState({ key, data, error: null, loading: false });
453
477
  } catch (e) {
454
- if (e instanceof BowlosApiError) setError(e);
455
- setData(null);
456
- } finally {
457
- setLoading(false);
478
+ if (request.current === id) {
479
+ setState({ key, data: null, error: e instanceof BowlosApiError ? e : null, loading: false });
480
+ }
458
481
  }
459
- }, [client, name, argsKey, auth]);
482
+ }, [key, keepPreviousData]);
460
483
  react.useEffect(() => {
461
484
  if (enabled) void refetch();
485
+ return () => {
486
+ request.current++;
487
+ };
462
488
  }, [enabled, refetch]);
463
- return { data, error, loading, refetch };
489
+ const visible = keepPreviousData || state?.key === key ? state : null;
490
+ return {
491
+ data: visible?.data ?? null,
492
+ error: visible?.error ?? null,
493
+ loading: visible?.key === key ? visible.loading : enabled,
494
+ refetch
495
+ };
464
496
  }
465
497
  function useBowlosMutation(name, options = {}) {
466
498
  const client = useBowlosClient();
@@ -644,13 +676,19 @@ function useAvailability(args, options) {
644
676
  return useBowlosQuery("checkAvailability", args, options);
645
677
  }
646
678
  function useBookingPreview(args, options) {
647
- return useBowlosQuery("bookingPreview", args, options);
679
+ return useBowlosQuery("bookingPreview", args, {
680
+ ...options,
681
+ keepPreviousData: args.eventOfferSlug ? false : options?.keepPreviousData
682
+ });
648
683
  }
649
684
  function useAddons(args, options) {
650
685
  return useBowlosQuery("listPublicAddons", args, options);
651
686
  }
652
687
  function useStartTimes(args, options) {
653
- return useBowlosQuery("availableStartTimes", args, options);
688
+ return useBowlosQuery("availableStartTimes", args, {
689
+ ...options,
690
+ keepPreviousData: args.eventOfferSlug ? false : options?.keepPreviousData
691
+ });
654
692
  }
655
693
  function useMyReservations(args, options) {
656
694
  return useBowlosQuery("listMyReservations", args, { ...options, auth: true });
@@ -740,6 +778,9 @@ function useEvents(args, options) {
740
778
  function useEventOffers(args, options) {
741
779
  return useBowlosQuery("listPublicEventOffers", args, options);
742
780
  }
781
+ function useEventOfferOptions(args, options) {
782
+ return useBowlosQuery("eventOfferOptions", args, { ...options, keepPreviousData: false });
783
+ }
743
784
  function useEventOffer(args, options) {
744
785
  return useBowlosQuery("getPublicEventOffer", args, options);
745
786
  }
@@ -812,6 +853,13 @@ function useChangePassword() {
812
853
  );
813
854
  return { ...mutation, run };
814
855
  }
856
+ function useDuplicateBooking(args, options) {
857
+ return useBowlosQuery(
858
+ "checkDuplicateBooking",
859
+ args,
860
+ options
861
+ );
862
+ }
815
863
  var DEFAULT_POLL_MS = 2500;
816
864
  function useBookingFlow() {
817
865
  const client = useBowlosClient();
@@ -852,6 +900,7 @@ function useBookingFlow() {
852
900
  stopPolling();
853
901
  break;
854
902
  case "expired":
903
+ setError(new BowlosApiError(BOWLOS_ERROR_CODES.CHECKOUT_EXPIRED, "Your hold expired \u2014 please pick your time again", 409));
855
904
  setStatus("expired");
856
905
  stopPolling();
857
906
  break;
@@ -910,12 +959,30 @@ function useBookingFlow() {
910
959
  },
911
960
  [client, stopPolling]
912
961
  );
962
+ const checkBeforePayment = react.useCallback(async () => {
963
+ const rt = refTokenRef.current;
964
+ if (!rt) return false;
965
+ try {
966
+ const latest = await getCheckoutStatus(client, rt);
967
+ if (latest.status === "pending_payment" || latest.status === "payment_failed_retryable") return true;
968
+ applyStatus(latest);
969
+ if (latest.status === "expired" || latest.status === "abandoned") {
970
+ setError(new BowlosApiError(BOWLOS_ERROR_CODES.CHECKOUT_EXPIRED, "Your hold expired \u2014 please pick your time again", 409));
971
+ }
972
+ return false;
973
+ } catch (e) {
974
+ if (e instanceof BowlosApiError) setError(e);
975
+ setStatus("error");
976
+ return false;
977
+ }
978
+ }, [client, applyStatus]);
913
979
  const preparePayment = react.useCallback(async () => {
914
980
  const rt = refTokenRef.current;
915
981
  if (!rt) return null;
916
982
  setError(null);
917
983
  setStatus("preparingPayment");
918
984
  try {
985
+ if (!await checkBeforePayment()) return null;
919
986
  const pi = await createCheckoutPaymentIntent(client, rt);
920
987
  setPaymentIntent(pi);
921
988
  setStatus("awaitingPayment");
@@ -925,7 +992,7 @@ function useBookingFlow() {
925
992
  setStatus("error");
926
993
  return null;
927
994
  }
928
- }, [client]);
995
+ }, [client, checkBeforePayment]);
929
996
  const pollStatus = react.useCallback(async () => {
930
997
  const rt = refTokenRef.current;
931
998
  if (!rt) return null;
@@ -969,6 +1036,7 @@ function useBookingFlow() {
969
1036
  error,
970
1037
  startHold,
971
1038
  preparePayment,
1039
+ checkBeforePayment,
972
1040
  pollStatus,
973
1041
  startPolling,
974
1042
  stopPolling,
@@ -1339,7 +1407,8 @@ function usePackagesLabel(args, options) {
1339
1407
  function useSlotPrices(args, options) {
1340
1408
  return useBowlosQuery("previewSlotPrices", args, {
1341
1409
  ...options,
1342
- auth: false
1410
+ auth: args.eventOfferSlug ? options?.auth : false,
1411
+ keepPreviousData: args.eventOfferSlug ? false : options?.keepPreviousData
1343
1412
  });
1344
1413
  }
1345
1414
  function useHours(args, options) {
@@ -1984,10 +2053,12 @@ exports.useConfirmEmailVerification = useConfirmEmailVerification;
1984
2053
  exports.useCreateCardSetup = useCreateCardSetup;
1985
2054
  exports.useCreatePayLinkPayment = useCreatePayLinkPayment;
1986
2055
  exports.useDeleteMyAccount = useDeleteMyAccount;
2056
+ exports.useDuplicateBooking = useDuplicateBooking;
1987
2057
  exports.useEmailVerification = useEmailVerification;
1988
2058
  exports.useEmailVerificationSendState = useEmailVerificationSendState;
1989
2059
  exports.useEmailVerificationStatus = useEmailVerificationStatus;
1990
2060
  exports.useEventOffer = useEventOffer;
2061
+ exports.useEventOfferOptions = useEventOfferOptions;
1991
2062
  exports.useEventOffers = useEventOffers;
1992
2063
  exports.useEventOrderCancelPreview = useEventOrderCancelPreview;
1993
2064
  exports.useEventTicketPreview = useEventTicketPreview;