@bowlos/reservations 0.41.0 → 0.43.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 (48) hide show
  1. package/AGENTS.md +9 -3
  2. package/HEADLESS.md +61 -0
  3. package/README.md +61 -0
  4. package/dist/{account-DEX2Lr78.d.cts → account-B4sZBmPI.d.cts} +866 -14
  5. package/dist/{account-DEX2Lr78.d.ts → account-B4sZBmPI.d.ts} +866 -14
  6. package/dist/booking-change-Dd4PVgd3.d.cts +487 -0
  7. package/dist/booking-change-DzYs9133.d.ts +487 -0
  8. package/dist/{chunk-VJIS56OO.js → chunk-4JMGS4YB.js} +96 -5
  9. package/dist/chunk-4JMGS4YB.js.map +1 -0
  10. package/dist/{chunk-FMFHNBDH.js → chunk-T2E6AEC7.js} +98 -5
  11. package/dist/chunk-T2E6AEC7.js.map +1 -0
  12. package/dist/{chunk-44WKP6MW.js → chunk-V4JRDYW4.js} +31 -3
  13. package/dist/chunk-V4JRDYW4.js.map +1 -0
  14. package/dist/{chunk-BWJHRJN6.js → chunk-YQRTBGXU.js} +3 -3
  15. package/dist/{chunk-BWJHRJN6.js.map → chunk-YQRTBGXU.js.map} +1 -1
  16. package/dist/cli.cjs +5 -0
  17. package/dist/cli.cjs.map +1 -1
  18. package/dist/components.cjs +313 -0
  19. package/dist/components.cjs.map +1 -1
  20. package/dist/components.d.cts +12 -6
  21. package/dist/components.d.ts +12 -6
  22. package/dist/components.js +109 -6
  23. package/dist/components.js.map +1 -1
  24. package/dist/index.cjs +33 -0
  25. package/dist/index.cjs.map +1 -1
  26. package/dist/index.d.cts +4 -4
  27. package/dist/index.d.ts +4 -4
  28. package/dist/index.js +2 -2
  29. package/dist/payments.cjs +34 -12
  30. package/dist/payments.cjs.map +1 -1
  31. package/dist/payments.d.cts +10 -2
  32. package/dist/payments.d.ts +10 -2
  33. package/dist/payments.js +5 -78
  34. package/dist/payments.js.map +1 -1
  35. package/dist/{react-CrRciA7I.d.ts → react-C6NWC80d.d.cts} +2 -2
  36. package/dist/{react-QJrsaOnN.d.cts → react-DVdtpw5n.d.ts} +2 -2
  37. package/dist/react.cjs +112 -0
  38. package/dist/react.cjs.map +1 -1
  39. package/dist/react.d.cts +22 -6
  40. package/dist/react.d.ts +22 -6
  41. package/dist/react.js +5 -5
  42. package/package.json +1 -1
  43. package/templates/center-site/package.json +1 -1
  44. package/dist/booking-change-4DGu-B08.d.ts +0 -1282
  45. package/dist/booking-change-aK6P37FZ.d.cts +0 -1282
  46. package/dist/chunk-44WKP6MW.js.map +0 -1
  47. package/dist/chunk-FMFHNBDH.js.map +0 -1
  48. package/dist/chunk-VJIS56OO.js.map +0 -1
@@ -2,6 +2,8 @@
2
2
 
3
3
  var jsxRuntime = require('react/jsx-runtime');
4
4
  var react = require('react');
5
+ var stripeJs = require('@stripe/stripe-js');
6
+ var reactStripeJs = require('@stripe/react-stripe-js');
5
7
 
6
8
  // src/components/theme.tsx
7
9
  var VAR = {
@@ -78,6 +80,11 @@ var BowlosApiError = class _BowlosApiError extends Error {
78
80
  this.retryAfterSeconds = options.retryAfterSeconds;
79
81
  Object.setPrototypeOf(this, _BowlosApiError.prototype);
80
82
  }
83
+ /** Typed additive createAnonymousBooking slot-full details, when present. */
84
+ get slotFullDetails() {
85
+ const d = this.details;
86
+ return this.code === "VALIDATION_FAILED" && d?.reason === "slot_full" && typeof d.waitlistAvailable === "boolean" && typeof d.requested === "number" && typeof d.available === "number" ? d : void 0;
87
+ }
81
88
  /** Too many requests — caller should back off `retryAfterSeconds`. */
82
89
  get isRateLimited() {
83
90
  return this.code === BOWLOS_ERROR_CODES.RATE_LIMITED;
@@ -198,6 +205,21 @@ function getCheckoutStatus(client, refToken) {
198
205
  function abandonCheckout(client, refToken) {
199
206
  return client.call("abandonCheckout", { refToken }, { auth: true });
200
207
  }
208
+ function joinWaitlist(client, args) {
209
+ return client.call("joinWaitlist", args, {
210
+ auth: true
211
+ });
212
+ }
213
+ function createWaitlistSetupIntent(client, args) {
214
+ return client.call(
215
+ "createWaitlistSetupIntent",
216
+ args,
217
+ { auth: true }
218
+ );
219
+ }
220
+ function confirmWaitlistCard(client, args) {
221
+ return client.call("confirmWaitlistCard", args, { auth: true });
222
+ }
201
223
 
202
224
  // src/idempotent-mutation.ts
203
225
  function useIdempotentMutation(name, options = {}) {
@@ -293,6 +315,11 @@ function useRetailPricing(args, options) {
293
315
  function useSavedCards(args, options) {
294
316
  return useBowlosQuery("listMyPaymentMethods", args, { ...options, auth: true });
295
317
  }
318
+ function useCreateCardSetup() {
319
+ return useBowlosMutation("createSetupIntentForAddingCard", {
320
+ auth: true
321
+ });
322
+ }
296
323
  function useRemoveCard() {
297
324
  return useBowlosMutation("detachPaymentMethod", {
298
325
  auth: true
@@ -1826,6 +1853,42 @@ function CommunicationPrefs({ brandId, labels, className }) {
1826
1853
  action.feedback
1827
1854
  ] });
1828
1855
  }
1856
+ function MyWaitlist({ brandId, centerId }) {
1857
+ const rows = useBowlosQuery(
1858
+ "listMyWaitlist",
1859
+ { brandId, centerId },
1860
+ { auth: true }
1861
+ );
1862
+ const leave = useBowlosMutation("leaveWaitlist", {
1863
+ auth: true
1864
+ });
1865
+ const action = useAccountAction();
1866
+ return /* @__PURE__ */ jsxRuntime.jsxs(AccountPanel, { title: "Pending \u2014 waitlist", children: [
1867
+ /* @__PURE__ */ jsxRuntime.jsx(QueryState, { ...rows, loadingLabel: "Loading\u2026" }),
1868
+ /* @__PURE__ */ jsxRuntime.jsx("ul", { children: rows.data?.filter((e) => e.status === "waiting" || e.status === "pending_card").map((e) => /* @__PURE__ */ jsxRuntime.jsxs("li", { children: [
1869
+ e.product,
1870
+ " \u2014 ",
1871
+ e.dateISO,
1872
+ " \u2014 ",
1873
+ formatCents(e.amountCents),
1874
+ " \u2014",
1875
+ " ",
1876
+ e.status === "pending_card" ? "Card required" : "Card on file",
1877
+ /* @__PURE__ */ jsxRuntime.jsx(
1878
+ "button",
1879
+ {
1880
+ disabled: action.busy,
1881
+ onClick: () => void action.run(async () => {
1882
+ await leave.run({ brandId, centerId, entryId: e.entryId });
1883
+ await rows.refetch();
1884
+ }, "Removed from waitlist \u2014 not charged."),
1885
+ children: "Leave"
1886
+ }
1887
+ )
1888
+ ] }, e.entryId)) }),
1889
+ action.feedback
1890
+ ] });
1891
+ }
1829
1892
  function SavedCards({
1830
1893
  brandId,
1831
1894
  centerId,
@@ -2405,6 +2468,8 @@ function Dashboard({
2405
2468
  /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.listTitle, children: p.kind }),
2406
2469
  /* @__PURE__ */ jsxRuntime.jsx("span", { style: s.badge, children: p.state })
2407
2470
  ] }, p.id)) }) }, section);
2471
+ case "waitlist":
2472
+ return /* @__PURE__ */ jsxRuntime.jsx(MyWaitlist, { brandId, centerId }, section);
2408
2473
  case "eventOrders":
2409
2474
  return /* @__PURE__ */ jsxRuntime.jsx(EventOrders, { brandId, title: labels?.eventOrders }, section);
2410
2475
  case "packageOrders":
@@ -3567,6 +3632,253 @@ function BookingChange({
3567
3632
  !["idle", "pay", "polling", "applying", "previewing"].includes(change.status) && /* @__PURE__ */ jsxRuntime.jsx("button", { style: styles().ghostBtn, disabled: action.busy, onClick: change.reset, children: t.reset })
3568
3633
  ] });
3569
3634
  }
3635
+ function useWaitlistJoin() {
3636
+ const client = useBowlosClient();
3637
+ const [status, setStatus] = react.useState("idle");
3638
+ const [entry, setEntry] = react.useState();
3639
+ const [setupIntent, setSetupIntent] = react.useState();
3640
+ const [error, setError] = react.useState();
3641
+ const generation = react.useRef(0);
3642
+ const busy = react.useRef(false);
3643
+ react.useEffect(
3644
+ () => () => {
3645
+ generation.current++;
3646
+ },
3647
+ [client]
3648
+ );
3649
+ function reset() {
3650
+ generation.current++;
3651
+ busy.current = false;
3652
+ setStatus("idle");
3653
+ setEntry(void 0);
3654
+ setSetupIntent(void 0);
3655
+ setError(void 0);
3656
+ }
3657
+ async function join(args) {
3658
+ if (busy.current) return;
3659
+ busy.current = true;
3660
+ const current = ++generation.current;
3661
+ setStatus("quoting");
3662
+ setError(void 0);
3663
+ setEntry(void 0);
3664
+ setSetupIntent(void 0);
3665
+ try {
3666
+ const value = await joinWaitlist(client, args);
3667
+ if (current === generation.current) {
3668
+ setEntry(value);
3669
+ setStatus("card");
3670
+ }
3671
+ return value;
3672
+ } catch (e) {
3673
+ if (current === generation.current) {
3674
+ setError(e);
3675
+ setStatus("error");
3676
+ }
3677
+ throw e;
3678
+ } finally {
3679
+ if (current === generation.current) busy.current = false;
3680
+ }
3681
+ }
3682
+ async function createCardSetup() {
3683
+ if (!entry || busy.current || status !== "card") return;
3684
+ busy.current = true;
3685
+ const current = generation.current;
3686
+ try {
3687
+ const value = await createWaitlistSetupIntent(client, { entryId: entry.entryId });
3688
+ if (current === generation.current) setSetupIntent(value);
3689
+ return value;
3690
+ } catch (e) {
3691
+ if (current === generation.current) {
3692
+ setError(e);
3693
+ setStatus("error");
3694
+ }
3695
+ throw e;
3696
+ } finally {
3697
+ if (current === generation.current) busy.current = false;
3698
+ }
3699
+ }
3700
+ async function cardConfirmed(intent) {
3701
+ if (!entry || busy.current || status !== "card") return;
3702
+ if (intent.status !== "succeeded") return;
3703
+ busy.current = true;
3704
+ const current = generation.current;
3705
+ setStatus("confirming");
3706
+ setError(void 0);
3707
+ try {
3708
+ const result = await confirmWaitlistCard(client, {
3709
+ entryId: entry.entryId,
3710
+ setupIntentId: intent.id
3711
+ });
3712
+ if (result.status !== "waiting") throw new Error("Waitlist card confirmation incomplete.");
3713
+ if (current === generation.current) setStatus("joined");
3714
+ } catch (e) {
3715
+ if (current === generation.current) {
3716
+ setError(e);
3717
+ setStatus("error");
3718
+ }
3719
+ throw e;
3720
+ } finally {
3721
+ if (current === generation.current) busy.current = false;
3722
+ }
3723
+ }
3724
+ return { status, entry, setupIntent, error, join, createCardSetup, cardConfirmed, reset };
3725
+ }
3726
+ function AddCardForm({
3727
+ brandId,
3728
+ centerId,
3729
+ onAdded,
3730
+ setupIntent,
3731
+ onSetupConfirmed,
3732
+ appearance,
3733
+ labels,
3734
+ className
3735
+ }) {
3736
+ const t = {
3737
+ title: "Add a card",
3738
+ start: "Add card",
3739
+ save: "Save card",
3740
+ saved: "Card saved.",
3741
+ error: "Unable to save this card.",
3742
+ ...labels
3743
+ };
3744
+ const setup = useCreateCardSetup();
3745
+ const action = useAccountAction();
3746
+ const [intent, setIntent] = react.useState();
3747
+ const activeIntent = setupIntent ?? intent;
3748
+ const stripe = react.useMemo(
3749
+ () => activeIntent ? stripeJs.loadStripe(activeIntent.publishableKey, { stripeAccount: activeIntent.stripeAccount }) : null,
3750
+ [activeIntent]
3751
+ );
3752
+ return /* @__PURE__ */ jsxRuntime.jsxs(AccountPanel, { title: t.title, className, children: [
3753
+ !activeIntent ? /* @__PURE__ */ jsxRuntime.jsx(
3754
+ "button",
3755
+ {
3756
+ style: styles().primaryBtn,
3757
+ disabled: action.busy,
3758
+ onClick: () => void action.run(async () => setIntent(await setup.run({ brandId, centerId }))),
3759
+ children: t.start
3760
+ }
3761
+ ) : /* @__PURE__ */ jsxRuntime.jsx(
3762
+ reactStripeJs.Elements,
3763
+ {
3764
+ stripe,
3765
+ options: {
3766
+ clientSecret: activeIntent.clientSecret,
3767
+ appearance,
3768
+ ..."customerSessionClientSecret" in activeIntent ? { customerSessionClientSecret: activeIntent.customerSessionClientSecret } : {}
3769
+ },
3770
+ children: /* @__PURE__ */ jsxRuntime.jsx(
3771
+ SetupForm,
3772
+ {
3773
+ labels: t,
3774
+ onSetupConfirmed,
3775
+ onAdded: () => {
3776
+ setIntent(void 0);
3777
+ onAdded?.();
3778
+ }
3779
+ }
3780
+ )
3781
+ }
3782
+ ),
3783
+ action.feedback
3784
+ ] });
3785
+ }
3786
+ function SetupForm({
3787
+ labels,
3788
+ onAdded,
3789
+ onSetupConfirmed
3790
+ }) {
3791
+ const stripe = reactStripeJs.useStripe();
3792
+ const elements = reactStripeJs.useElements();
3793
+ const action = useAccountAction();
3794
+ return /* @__PURE__ */ jsxRuntime.jsxs(
3795
+ "form",
3796
+ {
3797
+ style: styles().stack,
3798
+ onSubmit: (e) => {
3799
+ e.preventDefault();
3800
+ if (!stripe || !elements) return;
3801
+ void action.run(async () => {
3802
+ const result = await stripe.confirmSetup({ elements, redirect: "if_required" });
3803
+ if (result.error) throw new Error(result.error.message ?? labels.error);
3804
+ if (result.setupIntent?.status !== "succeeded") throw new Error(labels.error);
3805
+ await onSetupConfirmed?.(result.setupIntent);
3806
+ onAdded();
3807
+ }, labels.saved);
3808
+ },
3809
+ children: [
3810
+ /* @__PURE__ */ jsxRuntime.jsx(reactStripeJs.PaymentElement, {}),
3811
+ /* @__PURE__ */ jsxRuntime.jsx("button", { style: styles().primaryBtn, disabled: !stripe || !elements || action.busy, children: labels.save }),
3812
+ action.feedback
3813
+ ]
3814
+ }
3815
+ );
3816
+ }
3817
+ function WaitlistJoin({ args, onJoined }) {
3818
+ const flow = useWaitlistJoin();
3819
+ const [consent, setConsent] = react.useState(false);
3820
+ return /* @__PURE__ */ jsxRuntime.jsxs("section", { "aria-label": "Join waitlist", children: [
3821
+ flow.status === "idle" && /* @__PURE__ */ jsxRuntime.jsx(
3822
+ "button",
3823
+ {
3824
+ onClick: () => {
3825
+ setConsent(false);
3826
+ void flow.join(args).catch(() => {
3827
+ });
3828
+ },
3829
+ children: "Join waitlist"
3830
+ }
3831
+ ),
3832
+ flow.status === "quoting" && /* @__PURE__ */ jsxRuntime.jsx("p", { children: "Getting your price\u2026" }),
3833
+ flow.status === "card" && flow.entry && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
3834
+ /* @__PURE__ */ jsxRuntime.jsxs("p", { children: [
3835
+ formatCents(flow.entry.amountCents),
3836
+ " \u2014 charged only if a spot opens."
3837
+ ] }),
3838
+ !flow.setupIntent ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
3839
+ /* @__PURE__ */ jsxRuntime.jsxs("label", { children: [
3840
+ /* @__PURE__ */ jsxRuntime.jsx(
3841
+ "input",
3842
+ {
3843
+ type: "checkbox",
3844
+ checked: consent,
3845
+ onChange: (e) => setConsent(e.target.checked)
3846
+ }
3847
+ ),
3848
+ "I authorize a charge of ",
3849
+ formatCents(flow.entry.amountCents),
3850
+ " to this card if a spot opens."
3851
+ ] }),
3852
+ /* @__PURE__ */ jsxRuntime.jsx(
3853
+ "button",
3854
+ {
3855
+ disabled: !consent,
3856
+ onClick: () => void flow.createCardSetup().catch(() => {
3857
+ }),
3858
+ children: "Add card"
3859
+ }
3860
+ )
3861
+ ] }) : /* @__PURE__ */ jsxRuntime.jsx(
3862
+ AddCardForm,
3863
+ {
3864
+ brandId: args.brandId ?? "",
3865
+ centerId: args.centerId,
3866
+ setupIntent: flow.setupIntent,
3867
+ onSetupConfirmed: async (intent) => {
3868
+ await flow.cardConfirmed(intent);
3869
+ onJoined?.();
3870
+ }
3871
+ }
3872
+ )
3873
+ ] }),
3874
+ flow.status === "confirming" && /* @__PURE__ */ jsxRuntime.jsx("p", { children: "Confirming\u2026" }),
3875
+ flow.status === "joined" && /* @__PURE__ */ jsxRuntime.jsx("p", { children: "Pending \u2014 waitlist. You will be charged only if a spot opens." }),
3876
+ flow.status === "error" && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
3877
+ /* @__PURE__ */ jsxRuntime.jsx("p", { role: "alert", children: flow.error instanceof Error ? flow.error.message : "Unable to join waitlist." }),
3878
+ /* @__PURE__ */ jsxRuntime.jsx("button", { onClick: flow.reset, children: "Try again" })
3879
+ ] })
3880
+ ] });
3881
+ }
3570
3882
 
3571
3883
  exports.AccountDashboard = AccountDashboard;
3572
3884
  exports.AccountMenu = AccountMenu;
@@ -3591,6 +3903,7 @@ exports.PricingTable = PricingTable;
3591
3903
  exports.PrivacyCenter = PrivacyCenter;
3592
3904
  exports.ProfileForm = ProfileForm;
3593
3905
  exports.SavedCards = SavedCards;
3906
+ exports.WaitlistJoin = WaitlistJoin;
3594
3907
  exports.formatCents = formatCents;
3595
3908
  exports.formatCentsRange = formatCentsRange;
3596
3909
  //# sourceMappingURL=components.cjs.map