@bowlos/reservations 0.41.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 (61) hide show
  1. package/AGENTS.md +20 -5
  2. package/CHANGELOG.md +22 -0
  3. package/HEADLESS.md +187 -41
  4. package/README.md +77 -0
  5. package/dist/{account-DEX2Lr78.d.cts → account-b8chVpED.d.cts} +892 -14
  6. package/dist/{account-DEX2Lr78.d.ts → account-b8chVpED.d.ts} +892 -14
  7. package/dist/booking-change-B-ADuVEz.d.cts +562 -0
  8. package/dist/booking-change-BrJ-XESC.d.ts +562 -0
  9. package/dist/chunk-43WZ6TLQ.js +12 -0
  10. package/dist/chunk-43WZ6TLQ.js.map +1 -0
  11. package/dist/{chunk-VJIS56OO.js → chunk-CTJODEHR.js} +119 -7
  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-BWJHRJN6.js → chunk-EXEKCMQ2.js} +57 -22
  16. package/dist/chunk-EXEKCMQ2.js.map +1 -0
  17. package/dist/{chunk-44WKP6MW.js → chunk-IDRTMFJJ.js} +36 -3
  18. package/dist/chunk-IDRTMFJJ.js.map +1 -0
  19. package/dist/{chunk-FMFHNBDH.js → chunk-LFFANITL.js} +98 -12
  20. package/dist/chunk-LFFANITL.js.map +1 -0
  21. package/dist/cli.cjs +5 -0
  22. package/dist/cli.cjs.map +1 -1
  23. package/dist/components.cjs +670 -131
  24. package/dist/components.cjs.map +1 -1
  25. package/dist/components.d.cts +19 -7
  26. package/dist/components.d.ts +19 -7
  27. package/dist/components.js +304 -66
  28. package/dist/components.js.map +1 -1
  29. package/dist/index.cjs +67 -0
  30. package/dist/index.cjs.map +1 -1
  31. package/dist/index.d.cts +4 -4
  32. package/dist/index.d.ts +4 -4
  33. package/dist/index.js +5 -4
  34. package/dist/index.js.map +1 -1
  35. package/dist/payments.cjs +34 -12
  36. package/dist/payments.cjs.map +1 -1
  37. package/dist/payments.d.cts +10 -2
  38. package/dist/payments.d.ts +10 -2
  39. package/dist/payments.js +6 -78
  40. package/dist/payments.js.map +1 -1
  41. package/dist/{react-CrRciA7I.d.ts → react-cqGEohr0.d.cts} +4 -2
  42. package/dist/{react-QJrsaOnN.d.cts → react-s4J-e10i.d.ts} +4 -2
  43. package/dist/react.cjs +202 -19
  44. package/dist/react.cjs.map +1 -1
  45. package/dist/react.d.cts +28 -6
  46. package/dist/react.d.ts +28 -6
  47. package/dist/react.js +5 -5
  48. package/package.json +2 -1
  49. package/templates/center-site/README.md +1 -0
  50. package/templates/center-site/app/book/event-reservation-form.tsx +276 -0
  51. package/templates/center-site/app/book/page.tsx +107 -49
  52. package/templates/center-site/app/catalog/page.tsx +3 -1
  53. package/templates/center-site/app/events/[slug]/page.tsx +7 -10
  54. package/templates/center-site/package.json +1 -1
  55. package/dist/booking-change-4DGu-B08.d.ts +0 -1282
  56. package/dist/booking-change-aK6P37FZ.d.cts +0 -1282
  57. package/dist/chunk-44WKP6MW.js.map +0 -1
  58. package/dist/chunk-BWJHRJN6.js.map +0 -1
  59. package/dist/chunk-FMFHNBDH.js.map +0 -1
  60. package/dist/chunk-VJIS56OO.js.map +0 -1
  61. package/dist/chunk-YAXBZJMI.js.map +0 -1
@@ -1,7 +1,7 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { ReactNode } from 'react';
3
- import { A as AuthState, B as BowlosClient, h as BowlosClientConfig, r as Customer, O as LinkProfile } from './account-DEX2Lr78.cjs';
4
- import { as as BowlosApiError } from './booking-change-aK6P37FZ.cjs';
3
+ import { a4 as AuthState, B as BowlosClient, ac as BowlosClientConfig, an as Customer, aK as LinkProfile } from './account-b8chVpED.js';
4
+ import { s as BowlosApiError } from './booking-change-BrJ-XESC.js';
5
5
 
6
6
  interface BowlosProviderProps {
7
7
  /** A prebuilt client, or pass `config` to have one created and memoized. */
@@ -41,6 +41,8 @@ interface UseQueryOptions {
41
41
  auth?: boolean;
42
42
  /** Skip fetching until true. Defaults to true. */
43
43
  enabled?: boolean;
44
+ /** Keep the last result while inputs change. Defaults to true. */
45
+ keepPreviousData?: boolean;
44
46
  }
45
47
  interface UseQueryResult<T> {
46
48
  data: T | null;
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",
@@ -40,6 +53,11 @@ var BowlosApiError = class _BowlosApiError extends Error {
40
53
  this.retryAfterSeconds = options.retryAfterSeconds;
41
54
  Object.setPrototypeOf(this, _BowlosApiError.prototype);
42
55
  }
56
+ /** Typed additive createAnonymousBooking slot-full details, when present. */
57
+ get slotFullDetails() {
58
+ const d = this.details;
59
+ return this.code === "VALIDATION_FAILED" && d?.reason === "slot_full" && typeof d.waitlistAvailable === "boolean" && typeof d.requested === "number" && typeof d.available === "number" ? d : void 0;
60
+ }
43
61
  /** Too many requests — caller should back off `retryAfterSeconds`. */
44
62
  get isRateLimited() {
45
63
  return this.code === BOWLOS_ERROR_CODES.RATE_LIMITED;
@@ -433,29 +451,48 @@ function useBowlosQuery(name, args = {}, options = {}) {
433
451
  const client = useBowlosClient();
434
452
  const auth = options.auth ?? false;
435
453
  const enabled = options.enabled ?? true;
436
- const [data, setData] = react.useState(null);
437
- const [error, setError] = react.useState(null);
438
- 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);
439
457
  const argsKey = JSON.stringify(args);
458
+ const key = react.useMemo(
459
+ () => ({ client, name, argsKey, auth, enabled }),
460
+ [client, name, argsKey, auth, enabled]
461
+ );
440
462
  const refetch = react.useCallback(async () => {
441
- setLoading(true);
442
- 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
+ }));
443
470
  try {
444
- const result = await client.call(name, JSON.parse(argsKey), {
445
- auth
446
- });
447
- 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 });
448
477
  } catch (e) {
449
- if (e instanceof BowlosApiError) setError(e);
450
- setData(null);
451
- } finally {
452
- setLoading(false);
478
+ if (request.current === id) {
479
+ setState({ key, data: null, error: e instanceof BowlosApiError ? e : null, loading: false });
480
+ }
453
481
  }
454
- }, [client, name, argsKey, auth]);
482
+ }, [key, keepPreviousData]);
455
483
  react.useEffect(() => {
456
484
  if (enabled) void refetch();
485
+ return () => {
486
+ request.current++;
487
+ };
457
488
  }, [enabled, refetch]);
458
- 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
+ };
459
496
  }
460
497
  function useBowlosMutation(name, options = {}) {
461
498
  const client = useBowlosClient();
@@ -583,6 +620,21 @@ function getCheckoutStatus(client, refToken) {
583
620
  function abandonCheckout(client, refToken) {
584
621
  return client.call("abandonCheckout", { refToken }, { auth: true });
585
622
  }
623
+ function joinWaitlist(client, args) {
624
+ return client.call("joinWaitlist", args, {
625
+ auth: true
626
+ });
627
+ }
628
+ function createWaitlistSetupIntent(client, args) {
629
+ return client.call(
630
+ "createWaitlistSetupIntent",
631
+ args,
632
+ { auth: true }
633
+ );
634
+ }
635
+ function confirmWaitlistCard(client, args) {
636
+ return client.call("confirmWaitlistCard", args, { auth: true });
637
+ }
586
638
 
587
639
  // src/idempotent-mutation.ts
588
640
  function useIdempotentMutation(name, options = {}) {
@@ -624,13 +676,19 @@ function useAvailability(args, options) {
624
676
  return useBowlosQuery("checkAvailability", args, options);
625
677
  }
626
678
  function useBookingPreview(args, options) {
627
- return useBowlosQuery("bookingPreview", args, options);
679
+ return useBowlosQuery("bookingPreview", args, {
680
+ ...options,
681
+ keepPreviousData: args.eventOfferSlug ? false : options?.keepPreviousData
682
+ });
628
683
  }
629
684
  function useAddons(args, options) {
630
685
  return useBowlosQuery("listPublicAddons", args, options);
631
686
  }
632
687
  function useStartTimes(args, options) {
633
- return useBowlosQuery("availableStartTimes", args, options);
688
+ return useBowlosQuery("availableStartTimes", args, {
689
+ ...options,
690
+ keepPreviousData: args.eventOfferSlug ? false : options?.keepPreviousData
691
+ });
634
692
  }
635
693
  function useMyReservations(args, options) {
636
694
  return useBowlosQuery("listMyReservations", args, { ...options, auth: true });
@@ -720,6 +778,9 @@ function useEvents(args, options) {
720
778
  function useEventOffers(args, options) {
721
779
  return useBowlosQuery("listPublicEventOffers", args, options);
722
780
  }
781
+ function useEventOfferOptions(args, options) {
782
+ return useBowlosQuery("eventOfferOptions", args, { ...options, keepPreviousData: false });
783
+ }
723
784
  function useEventOffer(args, options) {
724
785
  return useBowlosQuery("getPublicEventOffer", args, options);
725
786
  }
@@ -792,6 +853,13 @@ function useChangePassword() {
792
853
  );
793
854
  return { ...mutation, run };
794
855
  }
856
+ function useDuplicateBooking(args, options) {
857
+ return useBowlosQuery(
858
+ "checkDuplicateBooking",
859
+ args,
860
+ options
861
+ );
862
+ }
795
863
  var DEFAULT_POLL_MS = 2500;
796
864
  function useBookingFlow() {
797
865
  const client = useBowlosClient();
@@ -832,6 +900,7 @@ function useBookingFlow() {
832
900
  stopPolling();
833
901
  break;
834
902
  case "expired":
903
+ setError(new BowlosApiError(BOWLOS_ERROR_CODES.CHECKOUT_EXPIRED, "Your hold expired \u2014 please pick your time again", 409));
835
904
  setStatus("expired");
836
905
  stopPolling();
837
906
  break;
@@ -890,12 +959,30 @@ function useBookingFlow() {
890
959
  },
891
960
  [client, stopPolling]
892
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]);
893
979
  const preparePayment = react.useCallback(async () => {
894
980
  const rt = refTokenRef.current;
895
981
  if (!rt) return null;
896
982
  setError(null);
897
983
  setStatus("preparingPayment");
898
984
  try {
985
+ if (!await checkBeforePayment()) return null;
899
986
  const pi = await createCheckoutPaymentIntent(client, rt);
900
987
  setPaymentIntent(pi);
901
988
  setStatus("awaitingPayment");
@@ -905,7 +992,7 @@ function useBookingFlow() {
905
992
  setStatus("error");
906
993
  return null;
907
994
  }
908
- }, [client]);
995
+ }, [client, checkBeforePayment]);
909
996
  const pollStatus = react.useCallback(async () => {
910
997
  const rt = refTokenRef.current;
911
998
  if (!rt) return null;
@@ -949,6 +1036,7 @@ function useBookingFlow() {
949
1036
  error,
950
1037
  startHold,
951
1038
  preparePayment,
1039
+ checkBeforePayment,
952
1040
  pollStatus,
953
1041
  startPolling,
954
1042
  stopPolling,
@@ -1319,7 +1407,8 @@ function usePackagesLabel(args, options) {
1319
1407
  function useSlotPrices(args, options) {
1320
1408
  return useBowlosQuery("previewSlotPrices", args, {
1321
1409
  ...options,
1322
- auth: false
1410
+ auth: args.eventOfferSlug ? options?.auth : false,
1411
+ keepPreviousData: args.eventOfferSlug ? false : options?.keepPreviousData
1323
1412
  });
1324
1413
  }
1325
1414
  function useHours(args, options) {
@@ -1841,6 +1930,97 @@ function useBookingChange(scope) {
1841
1930
  reset
1842
1931
  };
1843
1932
  }
1933
+ function useWaitlistJoin() {
1934
+ const client = useBowlosClient();
1935
+ const [status, setStatus] = react.useState("idle");
1936
+ const [entry, setEntry] = react.useState();
1937
+ const [setupIntent, setSetupIntent] = react.useState();
1938
+ const [error, setError] = react.useState();
1939
+ const generation = react.useRef(0);
1940
+ const busy = react.useRef(false);
1941
+ react.useEffect(
1942
+ () => () => {
1943
+ generation.current++;
1944
+ },
1945
+ [client]
1946
+ );
1947
+ function reset() {
1948
+ generation.current++;
1949
+ busy.current = false;
1950
+ setStatus("idle");
1951
+ setEntry(void 0);
1952
+ setSetupIntent(void 0);
1953
+ setError(void 0);
1954
+ }
1955
+ async function join(args) {
1956
+ if (busy.current) return;
1957
+ busy.current = true;
1958
+ const current = ++generation.current;
1959
+ setStatus("quoting");
1960
+ setError(void 0);
1961
+ setEntry(void 0);
1962
+ setSetupIntent(void 0);
1963
+ try {
1964
+ const value = await joinWaitlist(client, args);
1965
+ if (current === generation.current) {
1966
+ setEntry(value);
1967
+ setStatus("card");
1968
+ }
1969
+ return value;
1970
+ } catch (e) {
1971
+ if (current === generation.current) {
1972
+ setError(e);
1973
+ setStatus("error");
1974
+ }
1975
+ throw e;
1976
+ } finally {
1977
+ if (current === generation.current) busy.current = false;
1978
+ }
1979
+ }
1980
+ async function createCardSetup() {
1981
+ if (!entry || busy.current || status !== "card") return;
1982
+ busy.current = true;
1983
+ const current = generation.current;
1984
+ try {
1985
+ const value = await createWaitlistSetupIntent(client, { entryId: entry.entryId });
1986
+ if (current === generation.current) setSetupIntent(value);
1987
+ return value;
1988
+ } catch (e) {
1989
+ if (current === generation.current) {
1990
+ setError(e);
1991
+ setStatus("error");
1992
+ }
1993
+ throw e;
1994
+ } finally {
1995
+ if (current === generation.current) busy.current = false;
1996
+ }
1997
+ }
1998
+ async function cardConfirmed(intent) {
1999
+ if (!entry || busy.current || status !== "card") return;
2000
+ if (intent.status !== "succeeded") return;
2001
+ busy.current = true;
2002
+ const current = generation.current;
2003
+ setStatus("confirming");
2004
+ setError(void 0);
2005
+ try {
2006
+ const result = await confirmWaitlistCard(client, {
2007
+ entryId: entry.entryId,
2008
+ setupIntentId: intent.id
2009
+ });
2010
+ if (result.status !== "waiting") throw new Error("Waitlist card confirmation incomplete.");
2011
+ if (current === generation.current) setStatus("joined");
2012
+ } catch (e) {
2013
+ if (current === generation.current) {
2014
+ setError(e);
2015
+ setStatus("error");
2016
+ }
2017
+ throw e;
2018
+ } finally {
2019
+ if (current === generation.current) busy.current = false;
2020
+ }
2021
+ }
2022
+ return { status, entry, setupIntent, error, join, createCardSetup, cardConfirmed, reset };
2023
+ }
1844
2024
 
1845
2025
  exports.BowlosProvider = BowlosProvider;
1846
2026
  exports.useAccount = useAccount;
@@ -1873,10 +2053,12 @@ exports.useConfirmEmailVerification = useConfirmEmailVerification;
1873
2053
  exports.useCreateCardSetup = useCreateCardSetup;
1874
2054
  exports.useCreatePayLinkPayment = useCreatePayLinkPayment;
1875
2055
  exports.useDeleteMyAccount = useDeleteMyAccount;
2056
+ exports.useDuplicateBooking = useDuplicateBooking;
1876
2057
  exports.useEmailVerification = useEmailVerification;
1877
2058
  exports.useEmailVerificationSendState = useEmailVerificationSendState;
1878
2059
  exports.useEmailVerificationStatus = useEmailVerificationStatus;
1879
2060
  exports.useEventOffer = useEventOffer;
2061
+ exports.useEventOfferOptions = useEventOfferOptions;
1880
2062
  exports.useEventOffers = useEventOffers;
1881
2063
  exports.useEventOrderCancelPreview = useEventOrderCancelPreview;
1882
2064
  exports.useEventTicketPreview = useEventTicketPreview;
@@ -1947,6 +2129,7 @@ exports.useStartTimes = useStartTimes;
1947
2129
  exports.useSubmitSupportRequest = useSubmitSupportRequest;
1948
2130
  exports.useTestMode = useTestMode;
1949
2131
  exports.useUpdateMyProfile = useUpdateMyProfile;
2132
+ exports.useWaitlistJoin = useWaitlistJoin;
1950
2133
  exports.useWalletPassUrl = useWalletPassUrl;
1951
2134
  //# sourceMappingURL=react.cjs.map
1952
2135
  //# sourceMappingURL=react.cjs.map