@bowlos/reservations 0.19.0 → 0.21.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.
- package/HEADLESS.md +331 -6
- package/README.md +23 -10
- package/dist/{catalog-Dgapnrdm.d.ts → catalog-BuafmB8y.d.cts} +67 -2
- package/dist/{catalog-Db8EdzJ2.d.cts → catalog-bpCn9klL.d.ts} +67 -2
- package/dist/{chunk-BPLYLQO3.js → chunk-FV6SROO2.js} +31 -4
- package/dist/chunk-FV6SROO2.js.map +1 -0
- package/dist/{chunk-FWPXQII5.js → chunk-S5T4OCBY.js} +61 -3
- package/dist/chunk-S5T4OCBY.js.map +1 -0
- package/dist/components.cjs +11 -6
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +10 -4
- package/dist/components.d.ts +10 -4
- package/dist/components.js +11 -6
- package/dist/components.js.map +1 -1
- package/dist/{data-DevEKBmK.d.cts → data-BKlgn8Ln.d.cts} +174 -1
- package/dist/{data-DevEKBmK.d.ts → data-BKlgn8Ln.d.ts} +174 -1
- package/dist/index.cjs +86 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +18 -3
- package/dist/index.js.map +1 -1
- package/dist/payments.d.cts +1 -1
- package/dist/payments.d.ts +1 -1
- package/dist/{react-BgP6rtBS.d.ts → react-BI2RKM5p.d.ts} +1 -1
- package/dist/{react-D73ZxxDw.d.cts → react-D2mBw_-l.d.cts} +1 -1
- package/dist/react.cjs +173 -0
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +77 -5
- package/dist/react.d.ts +77 -5
- package/dist/react.js +102 -4
- package/dist/react.js.map +1 -1
- package/package.json +1 -1
- package/templates/center-site/package.json +1 -1
- package/dist/chunk-BPLYLQO3.js.map +0 -1
- package/dist/chunk-FWPXQII5.js.map +0 -1
package/dist/react.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { U as UseQueryOptions, a as UseQueryResult } from './react-
|
|
2
|
-
export { A as AccountStatus, B as BowlosProvider, b as BowlosProviderProps, c as UseAccountResult, u as useAccount, d as useBowlosClient, e as useBowlosQuery } from './react-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { U as UseQueryOptions, a as UseQueryResult } from './react-D2mBw_-l.cjs';
|
|
2
|
+
export { A as AccountStatus, B as BowlosProvider, b as BowlosProviderProps, c as UseAccountResult, u as useAccount, d as useBowlosClient, e as useBowlosQuery } from './react-D2mBw_-l.cjs';
|
|
3
|
+
import { V as PublicAddon, a as AvailabilityArgs, b as AvailabilityResult, e as BookingPreviewArgs, f as BookingQuote, n as EventTicketPreviewResult, m as EventTicketPreviewArgs, s as GameCardPreviewResult, r as GameCardPreviewArgs, x as MembershipPreviewResult, w as MembershipPreviewArgs, J as MembershipSubscriptionPreviewResult, N as PackagePreviewResult, K as PackagePreviewArgs, W as StartTimesArgs, d as BookingHold, S as PaymentIntentInfo, k as CreateBookingArgs, i as CheckoutStatusResult, I as MembershipSubscriptionIntent, H as MembershipSubscriptionArgs, o as EventTicketPurchaseArgs, t as GameCardPurchaseArgs, y as MembershipPurchaseArgs, O as PackagePurchaseArgs } from './data-BKlgn8Ln.cjs';
|
|
4
|
+
import { e as CatalogResult, b as CatalogArgs, h as CenterHoursArgs, i as CenterScoped, j as FlashSaleArgs, F as FlashBookingOptionsArgs, k as FlashSalesArgs, B as BrandCatalogArgs, a as BrandScoped, E as EventOrderDetailArgs, M as MembershipDetailArgs, R as ReservationDetailArgs, P as PackageDetailArgs } from './catalog-BuafmB8y.cjs';
|
|
5
5
|
import { a as BowlosApiError } from './errors-IIK7xibp.cjs';
|
|
6
6
|
import 'react/jsx-runtime';
|
|
7
7
|
import 'react';
|
|
@@ -25,6 +25,10 @@ declare function useStartTimes(args: StartTimesArgs, options?: UseQueryOptions):
|
|
|
25
25
|
declare function useMyReservations<T = unknown>(args: BrandScoped, options?: UseQueryOptions): UseQueryResult<T>;
|
|
26
26
|
/** One of the customer's reservations, by displayId. */
|
|
27
27
|
declare function useMyReservationDetail<T = unknown>(args: ReservationDetailArgs, options?: UseQueryOptions): UseQueryResult<T>;
|
|
28
|
+
/** The signed-in customer's event ticket orders. */
|
|
29
|
+
declare function useMyEventOrders<T = unknown>(args: BrandScoped, options?: UseQueryOptions): UseQueryResult<T>;
|
|
30
|
+
/** One of the customer's event ticket orders. */
|
|
31
|
+
declare function useMyEventOrder<T = unknown>(args: EventOrderDetailArgs, options?: UseQueryOptions): UseQueryResult<T>;
|
|
28
32
|
/** The customer's memberships. */
|
|
29
33
|
declare function useMyMemberships<T = unknown>(args: BrandScoped, options?: UseQueryOptions): UseQueryResult<T>;
|
|
30
34
|
/** One membership's detail. */
|
|
@@ -41,10 +45,24 @@ declare function useFlashSale<T = unknown>(args: FlashSaleArgs, options?: UseQue
|
|
|
41
45
|
declare function useFlashSales<T = unknown>(args: FlashSalesArgs, options?: UseQueryOptions): UseQueryResult<T>;
|
|
42
46
|
/** Per-start-hour options for a flash-sale reservation item (members only). */
|
|
43
47
|
declare function useFlashSaleBookingOptions<T = unknown>(args: FlashBookingOptionsArgs, options?: UseQueryOptions): UseQueryResult<T>;
|
|
48
|
+
/**
|
|
49
|
+
* The canonical public catalog for a surface — every category grouped, with the
|
|
50
|
+
* Center admin's per-surface visibility already applied. Prefer this over the
|
|
51
|
+
* per-category hooks below when you want the full, visibility-aware catalog
|
|
52
|
+
* (it stays consistent with the white-label web + mobile surfaces). Anonymous.
|
|
53
|
+
*/
|
|
54
|
+
declare function useCatalog<T = CatalogResult>(args: CatalogArgs, options?: UseQueryOptions): UseQueryResult<T>;
|
|
44
55
|
/** Bookable products at a Center (each carries `attractionTypeKey`). */
|
|
45
56
|
declare function useProducts<T = unknown>(args: CenterScoped, options?: UseQueryOptions): UseQueryResult<T>;
|
|
46
57
|
/** Upcoming pricing events at a Center. */
|
|
47
58
|
declare function useEvents<T = unknown>(args: CenterScoped, options?: UseQueryOptions): UseQueryResult<T>;
|
|
59
|
+
/** Sellable event offers at a Center. Use these for the product lineup and
|
|
60
|
+
* event landing pages; each row carries a slug and purchase mode. */
|
|
61
|
+
declare function useEventOffers<T = unknown>(args: CenterScoped, options?: UseQueryOptions): UseQueryResult<T>;
|
|
62
|
+
/** One sellable event offer by landing-page slug. */
|
|
63
|
+
declare function useEventOffer<T = unknown>(args: {
|
|
64
|
+
slug: string;
|
|
65
|
+
}, options?: UseQueryOptions): UseQueryResult<T>;
|
|
48
66
|
/** Purchasable packages at a Brand. */
|
|
49
67
|
declare function usePackages<T = unknown>(args: BrandCatalogArgs, options?: UseQueryOptions): UseQueryResult<T>;
|
|
50
68
|
/** Full detail for one package (components, add-ons, allowed start times, …) —
|
|
@@ -70,6 +88,23 @@ declare function useGameCards<T = unknown>(args: BrandCatalogArgs, options?: Use
|
|
|
70
88
|
* same engine as the PaymentIntent, so it never diverges from what the
|
|
71
89
|
* customer is charged. */
|
|
72
90
|
declare function useGameCardPreview<T = GameCardPreviewResult>(args: GameCardPreviewArgs, options?: UseQueryOptions): UseQueryResult<T>;
|
|
91
|
+
/** Itemized quote for a ticket-mode event offer — base tickets, tax lines,
|
|
92
|
+
* Center event fee, and authoritative grand total. Requires a signed-in
|
|
93
|
+
* customer so tax exemptions match the eventual charge. */
|
|
94
|
+
declare function useEventTicketPreview<T = EventTicketPreviewResult>(args: EventTicketPreviewArgs, options?: UseQueryOptions): UseQueryResult<T>;
|
|
95
|
+
/** Itemized quote for a one-time membership purchase — dues, the one-time setup
|
|
96
|
+
* fee, tax lines, the selling Center's booking fee, and the authoritative grand
|
|
97
|
+
* total. Drives the headless **Review** step. Requires a signed-in customer (tax
|
|
98
|
+
* exemptions are applied + the home Center is resolved server-side), and is
|
|
99
|
+
* computed by the same engine as the PaymentIntent, so it never diverges from
|
|
100
|
+
* what the customer is charged. */
|
|
101
|
+
declare function useMembershipPreview<T = MembershipPreviewResult>(args: MembershipPreviewArgs, options?: UseQueryOptions): UseQueryResult<T>;
|
|
102
|
+
/** Itemized quote for a RECURRING membership subscription — the one-time Review
|
|
103
|
+
* fields ("Due today") PLUS `recurringTotalCents` + `cadence` ("Auto-renews
|
|
104
|
+
* at"). Drives the recurring **Review** step. Requires a signed-in customer, and
|
|
105
|
+
* is computed by the same engine as the subscription's first invoice, so it
|
|
106
|
+
* never diverges from what the customer is charged. */
|
|
107
|
+
declare function useMembershipSubscriptionPreview<T = MembershipSubscriptionPreviewResult>(args: MembershipPreviewArgs, options?: UseQueryOptions): UseQueryResult<T>;
|
|
73
108
|
|
|
74
109
|
type BookingFlowStatus = "idle" | "holding" | "held" | "preparingPayment" | "awaitingPayment" | "confirmed" | "expired" | "failed" | "abandoned" | "error";
|
|
75
110
|
interface BookingReservationRef {
|
|
@@ -150,5 +185,42 @@ declare function useGameCardPurchase(): UsePurchaseResult<GameCardPurchaseArgs>;
|
|
|
150
185
|
* MUST be one of those slots or the create rejects with VALIDATION_FAILED.
|
|
151
186
|
*/
|
|
152
187
|
declare function usePackagePurchase(): UsePurchaseResult<PackagePurchaseArgs>;
|
|
188
|
+
/**
|
|
189
|
+
* Buy tickets for a ticket-mode event offer. `start({ eventOfferId, quantity })`
|
|
190
|
+
* → render `<BowlosPaymentForm {...purchase.paymentIntent} onPaid={purchase.startPolling}>`
|
|
191
|
+
* → `status === "confirmed"` (`resultId` = the event order id). The charge
|
|
192
|
+
* lands on the operator's connected account and the order receipt is available
|
|
193
|
+
* through `useMyEventOrder` after confirmation.
|
|
194
|
+
*/
|
|
195
|
+
declare function useEventTicketPurchase(): UsePurchaseResult<EventTicketPurchaseArgs>;
|
|
196
|
+
/**
|
|
197
|
+
* Buy a one-time membership. Same lifecycle as a game pass (no config) —
|
|
198
|
+
* `start({ templateId })` → render
|
|
199
|
+
* `<BowlosPaymentForm {...purchase.paymentIntent} onPaid={purchase.startPolling}>`
|
|
200
|
+
* → `status === "confirmed"` (`resultId` = the new membership id). The charge
|
|
201
|
+
* lands on the operator's connected account.
|
|
202
|
+
*/
|
|
203
|
+
declare function useMembershipPurchase(): UsePurchaseResult<MembershipPurchaseArgs>;
|
|
204
|
+
/** State for `useMembershipSubscriptionCheckout`. A recurring subscription has no
|
|
205
|
+
* refToken to poll — it materializes via webhook — so this is a leaner machine
|
|
206
|
+
* than `usePurchase`: mint the first-invoice payment, confirm it, then re-query
|
|
207
|
+
* `useMyMemberships` (which updates reactively once the webhook lands). */
|
|
208
|
+
interface UseSubscriptionCheckoutResult {
|
|
209
|
+
status: "idle" | "creating" | "awaitingPayment" | "error";
|
|
210
|
+
subscriptionIntent: MembershipSubscriptionIntent | null;
|
|
211
|
+
error: BowlosApiError | null;
|
|
212
|
+
/** Mint the subscription + its first-invoice payment → "awaitingPayment". */
|
|
213
|
+
start: (args: MembershipSubscriptionArgs) => Promise<void>;
|
|
214
|
+
reset: () => void;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Start a recurring membership subscription. `start({ templateId })` mints the
|
|
218
|
+
* subscription + its first-invoice PaymentIntent on the operator's connected
|
|
219
|
+
* account → render `<BowlosPaymentForm {...checkout.subscriptionIntent}>` to
|
|
220
|
+
* confirm. There is **no poll**: once the customer pays, the subscription
|
|
221
|
+
* materializes via webhook — re-query `useMyMemberships` to show the new
|
|
222
|
+
* membership (the list updates reactively).
|
|
223
|
+
*/
|
|
224
|
+
declare function useMembershipSubscriptionCheckout(): UseSubscriptionCheckoutResult;
|
|
153
225
|
|
|
154
|
-
export { type BookingFlowStatus, type BookingReservationRef, type PurchasePaymentIntent, type PurchaseStatus, type UseBookingFlowResult, type UsePurchaseResult, UseQueryOptions, UseQueryResult, useAddons, useAvailability, useBookingFlow, useBookingPreview, useCenterHours, useEvents, useFlashSale, useFlashSaleBookingOptions, useFlashSales, useGameCardPreview, useGameCardPurchase, useGameCards, useMyCredits, useMyLoyalty, useMyMembershipDetail, useMyMemberships, useMyPasses, useMyReservationDetail, useMyReservations, usePackage, usePackagePreview, usePackagePurchase, usePackages, useProducts, usePublicMemberships, usePurchase, useStartTimes };
|
|
226
|
+
export { type BookingFlowStatus, type BookingReservationRef, type PurchasePaymentIntent, type PurchaseStatus, type UseBookingFlowResult, type UsePurchaseResult, UseQueryOptions, UseQueryResult, type UseSubscriptionCheckoutResult, useAddons, useAvailability, useBookingFlow, useBookingPreview, useCatalog, useCenterHours, useEventOffer, useEventOffers, useEventTicketPreview, useEventTicketPurchase, useEvents, useFlashSale, useFlashSaleBookingOptions, useFlashSales, useGameCardPreview, useGameCardPurchase, useGameCards, useMembershipPreview, useMembershipPurchase, useMembershipSubscriptionCheckout, useMembershipSubscriptionPreview, useMyCredits, useMyEventOrder, useMyEventOrders, useMyLoyalty, useMyMembershipDetail, useMyMemberships, useMyPasses, useMyReservationDetail, useMyReservations, usePackage, usePackagePreview, usePackagePurchase, usePackages, useProducts, usePublicMemberships, usePurchase, useStartTimes };
|
package/dist/react.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { U as UseQueryOptions, a as UseQueryResult } from './react-
|
|
2
|
-
export { A as AccountStatus, B as BowlosProvider, b as BowlosProviderProps, c as UseAccountResult, u as useAccount, d as useBowlosClient, e as useBowlosQuery } from './react-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { U as UseQueryOptions, a as UseQueryResult } from './react-BI2RKM5p.js';
|
|
2
|
+
export { A as AccountStatus, B as BowlosProvider, b as BowlosProviderProps, c as UseAccountResult, u as useAccount, d as useBowlosClient, e as useBowlosQuery } from './react-BI2RKM5p.js';
|
|
3
|
+
import { V as PublicAddon, a as AvailabilityArgs, b as AvailabilityResult, e as BookingPreviewArgs, f as BookingQuote, n as EventTicketPreviewResult, m as EventTicketPreviewArgs, s as GameCardPreviewResult, r as GameCardPreviewArgs, x as MembershipPreviewResult, w as MembershipPreviewArgs, J as MembershipSubscriptionPreviewResult, N as PackagePreviewResult, K as PackagePreviewArgs, W as StartTimesArgs, d as BookingHold, S as PaymentIntentInfo, k as CreateBookingArgs, i as CheckoutStatusResult, I as MembershipSubscriptionIntent, H as MembershipSubscriptionArgs, o as EventTicketPurchaseArgs, t as GameCardPurchaseArgs, y as MembershipPurchaseArgs, O as PackagePurchaseArgs } from './data-BKlgn8Ln.js';
|
|
4
|
+
import { e as CatalogResult, b as CatalogArgs, h as CenterHoursArgs, i as CenterScoped, j as FlashSaleArgs, F as FlashBookingOptionsArgs, k as FlashSalesArgs, B as BrandCatalogArgs, a as BrandScoped, E as EventOrderDetailArgs, M as MembershipDetailArgs, R as ReservationDetailArgs, P as PackageDetailArgs } from './catalog-bpCn9klL.js';
|
|
5
5
|
import { a as BowlosApiError } from './errors-IIK7xibp.js';
|
|
6
6
|
import 'react/jsx-runtime';
|
|
7
7
|
import 'react';
|
|
@@ -25,6 +25,10 @@ declare function useStartTimes(args: StartTimesArgs, options?: UseQueryOptions):
|
|
|
25
25
|
declare function useMyReservations<T = unknown>(args: BrandScoped, options?: UseQueryOptions): UseQueryResult<T>;
|
|
26
26
|
/** One of the customer's reservations, by displayId. */
|
|
27
27
|
declare function useMyReservationDetail<T = unknown>(args: ReservationDetailArgs, options?: UseQueryOptions): UseQueryResult<T>;
|
|
28
|
+
/** The signed-in customer's event ticket orders. */
|
|
29
|
+
declare function useMyEventOrders<T = unknown>(args: BrandScoped, options?: UseQueryOptions): UseQueryResult<T>;
|
|
30
|
+
/** One of the customer's event ticket orders. */
|
|
31
|
+
declare function useMyEventOrder<T = unknown>(args: EventOrderDetailArgs, options?: UseQueryOptions): UseQueryResult<T>;
|
|
28
32
|
/** The customer's memberships. */
|
|
29
33
|
declare function useMyMemberships<T = unknown>(args: BrandScoped, options?: UseQueryOptions): UseQueryResult<T>;
|
|
30
34
|
/** One membership's detail. */
|
|
@@ -41,10 +45,24 @@ declare function useFlashSale<T = unknown>(args: FlashSaleArgs, options?: UseQue
|
|
|
41
45
|
declare function useFlashSales<T = unknown>(args: FlashSalesArgs, options?: UseQueryOptions): UseQueryResult<T>;
|
|
42
46
|
/** Per-start-hour options for a flash-sale reservation item (members only). */
|
|
43
47
|
declare function useFlashSaleBookingOptions<T = unknown>(args: FlashBookingOptionsArgs, options?: UseQueryOptions): UseQueryResult<T>;
|
|
48
|
+
/**
|
|
49
|
+
* The canonical public catalog for a surface — every category grouped, with the
|
|
50
|
+
* Center admin's per-surface visibility already applied. Prefer this over the
|
|
51
|
+
* per-category hooks below when you want the full, visibility-aware catalog
|
|
52
|
+
* (it stays consistent with the white-label web + mobile surfaces). Anonymous.
|
|
53
|
+
*/
|
|
54
|
+
declare function useCatalog<T = CatalogResult>(args: CatalogArgs, options?: UseQueryOptions): UseQueryResult<T>;
|
|
44
55
|
/** Bookable products at a Center (each carries `attractionTypeKey`). */
|
|
45
56
|
declare function useProducts<T = unknown>(args: CenterScoped, options?: UseQueryOptions): UseQueryResult<T>;
|
|
46
57
|
/** Upcoming pricing events at a Center. */
|
|
47
58
|
declare function useEvents<T = unknown>(args: CenterScoped, options?: UseQueryOptions): UseQueryResult<T>;
|
|
59
|
+
/** Sellable event offers at a Center. Use these for the product lineup and
|
|
60
|
+
* event landing pages; each row carries a slug and purchase mode. */
|
|
61
|
+
declare function useEventOffers<T = unknown>(args: CenterScoped, options?: UseQueryOptions): UseQueryResult<T>;
|
|
62
|
+
/** One sellable event offer by landing-page slug. */
|
|
63
|
+
declare function useEventOffer<T = unknown>(args: {
|
|
64
|
+
slug: string;
|
|
65
|
+
}, options?: UseQueryOptions): UseQueryResult<T>;
|
|
48
66
|
/** Purchasable packages at a Brand. */
|
|
49
67
|
declare function usePackages<T = unknown>(args: BrandCatalogArgs, options?: UseQueryOptions): UseQueryResult<T>;
|
|
50
68
|
/** Full detail for one package (components, add-ons, allowed start times, …) —
|
|
@@ -70,6 +88,23 @@ declare function useGameCards<T = unknown>(args: BrandCatalogArgs, options?: Use
|
|
|
70
88
|
* same engine as the PaymentIntent, so it never diverges from what the
|
|
71
89
|
* customer is charged. */
|
|
72
90
|
declare function useGameCardPreview<T = GameCardPreviewResult>(args: GameCardPreviewArgs, options?: UseQueryOptions): UseQueryResult<T>;
|
|
91
|
+
/** Itemized quote for a ticket-mode event offer — base tickets, tax lines,
|
|
92
|
+
* Center event fee, and authoritative grand total. Requires a signed-in
|
|
93
|
+
* customer so tax exemptions match the eventual charge. */
|
|
94
|
+
declare function useEventTicketPreview<T = EventTicketPreviewResult>(args: EventTicketPreviewArgs, options?: UseQueryOptions): UseQueryResult<T>;
|
|
95
|
+
/** Itemized quote for a one-time membership purchase — dues, the one-time setup
|
|
96
|
+
* fee, tax lines, the selling Center's booking fee, and the authoritative grand
|
|
97
|
+
* total. Drives the headless **Review** step. Requires a signed-in customer (tax
|
|
98
|
+
* exemptions are applied + the home Center is resolved server-side), and is
|
|
99
|
+
* computed by the same engine as the PaymentIntent, so it never diverges from
|
|
100
|
+
* what the customer is charged. */
|
|
101
|
+
declare function useMembershipPreview<T = MembershipPreviewResult>(args: MembershipPreviewArgs, options?: UseQueryOptions): UseQueryResult<T>;
|
|
102
|
+
/** Itemized quote for a RECURRING membership subscription — the one-time Review
|
|
103
|
+
* fields ("Due today") PLUS `recurringTotalCents` + `cadence` ("Auto-renews
|
|
104
|
+
* at"). Drives the recurring **Review** step. Requires a signed-in customer, and
|
|
105
|
+
* is computed by the same engine as the subscription's first invoice, so it
|
|
106
|
+
* never diverges from what the customer is charged. */
|
|
107
|
+
declare function useMembershipSubscriptionPreview<T = MembershipSubscriptionPreviewResult>(args: MembershipPreviewArgs, options?: UseQueryOptions): UseQueryResult<T>;
|
|
73
108
|
|
|
74
109
|
type BookingFlowStatus = "idle" | "holding" | "held" | "preparingPayment" | "awaitingPayment" | "confirmed" | "expired" | "failed" | "abandoned" | "error";
|
|
75
110
|
interface BookingReservationRef {
|
|
@@ -150,5 +185,42 @@ declare function useGameCardPurchase(): UsePurchaseResult<GameCardPurchaseArgs>;
|
|
|
150
185
|
* MUST be one of those slots or the create rejects with VALIDATION_FAILED.
|
|
151
186
|
*/
|
|
152
187
|
declare function usePackagePurchase(): UsePurchaseResult<PackagePurchaseArgs>;
|
|
188
|
+
/**
|
|
189
|
+
* Buy tickets for a ticket-mode event offer. `start({ eventOfferId, quantity })`
|
|
190
|
+
* → render `<BowlosPaymentForm {...purchase.paymentIntent} onPaid={purchase.startPolling}>`
|
|
191
|
+
* → `status === "confirmed"` (`resultId` = the event order id). The charge
|
|
192
|
+
* lands on the operator's connected account and the order receipt is available
|
|
193
|
+
* through `useMyEventOrder` after confirmation.
|
|
194
|
+
*/
|
|
195
|
+
declare function useEventTicketPurchase(): UsePurchaseResult<EventTicketPurchaseArgs>;
|
|
196
|
+
/**
|
|
197
|
+
* Buy a one-time membership. Same lifecycle as a game pass (no config) —
|
|
198
|
+
* `start({ templateId })` → render
|
|
199
|
+
* `<BowlosPaymentForm {...purchase.paymentIntent} onPaid={purchase.startPolling}>`
|
|
200
|
+
* → `status === "confirmed"` (`resultId` = the new membership id). The charge
|
|
201
|
+
* lands on the operator's connected account.
|
|
202
|
+
*/
|
|
203
|
+
declare function useMembershipPurchase(): UsePurchaseResult<MembershipPurchaseArgs>;
|
|
204
|
+
/** State for `useMembershipSubscriptionCheckout`. A recurring subscription has no
|
|
205
|
+
* refToken to poll — it materializes via webhook — so this is a leaner machine
|
|
206
|
+
* than `usePurchase`: mint the first-invoice payment, confirm it, then re-query
|
|
207
|
+
* `useMyMemberships` (which updates reactively once the webhook lands). */
|
|
208
|
+
interface UseSubscriptionCheckoutResult {
|
|
209
|
+
status: "idle" | "creating" | "awaitingPayment" | "error";
|
|
210
|
+
subscriptionIntent: MembershipSubscriptionIntent | null;
|
|
211
|
+
error: BowlosApiError | null;
|
|
212
|
+
/** Mint the subscription + its first-invoice payment → "awaitingPayment". */
|
|
213
|
+
start: (args: MembershipSubscriptionArgs) => Promise<void>;
|
|
214
|
+
reset: () => void;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Start a recurring membership subscription. `start({ templateId })` mints the
|
|
218
|
+
* subscription + its first-invoice PaymentIntent on the operator's connected
|
|
219
|
+
* account → render `<BowlosPaymentForm {...checkout.subscriptionIntent}>` to
|
|
220
|
+
* confirm. There is **no poll**: once the customer pays, the subscription
|
|
221
|
+
* materializes via webhook — re-query `useMyMemberships` to show the new
|
|
222
|
+
* membership (the list updates reactively).
|
|
223
|
+
*/
|
|
224
|
+
declare function useMembershipSubscriptionCheckout(): UseSubscriptionCheckoutResult;
|
|
153
225
|
|
|
154
|
-
export { type BookingFlowStatus, type BookingReservationRef, type PurchasePaymentIntent, type PurchaseStatus, type UseBookingFlowResult, type UsePurchaseResult, UseQueryOptions, UseQueryResult, useAddons, useAvailability, useBookingFlow, useBookingPreview, useCenterHours, useEvents, useFlashSale, useFlashSaleBookingOptions, useFlashSales, useGameCardPreview, useGameCardPurchase, useGameCards, useMyCredits, useMyLoyalty, useMyMembershipDetail, useMyMemberships, useMyPasses, useMyReservationDetail, useMyReservations, usePackage, usePackagePreview, usePackagePurchase, usePackages, useProducts, usePublicMemberships, usePurchase, useStartTimes };
|
|
226
|
+
export { type BookingFlowStatus, type BookingReservationRef, type PurchasePaymentIntent, type PurchaseStatus, type UseBookingFlowResult, type UsePurchaseResult, UseQueryOptions, UseQueryResult, type UseSubscriptionCheckoutResult, useAddons, useAvailability, useBookingFlow, useBookingPreview, useCatalog, useCenterHours, useEventOffer, useEventOffers, useEventTicketPreview, useEventTicketPurchase, useEvents, useFlashSale, useFlashSaleBookingOptions, useFlashSales, useGameCardPreview, useGameCardPurchase, useGameCards, useMembershipPreview, useMembershipPurchase, useMembershipSubscriptionCheckout, useMembershipSubscriptionPreview, useMyCredits, useMyEventOrder, useMyEventOrders, useMyLoyalty, useMyMembershipDetail, useMyMemberships, useMyPasses, useMyReservationDetail, useMyReservations, usePackage, usePackagePreview, usePackagePurchase, usePackages, useProducts, usePublicMemberships, usePurchase, useStartTimes };
|
package/dist/react.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { useBowlosClient } from './chunk-
|
|
2
|
-
export { BowlosProvider, useAccount, useAddons, useAvailability, useBookingFlow, useBookingPreview, useBowlosClient, useBowlosQuery, useCenterHours, useEvents, useFlashSale, useFlashSaleBookingOptions, useFlashSales, useGameCardPreview, useGameCards, useMyCredits, useMyLoyalty, useMyMembershipDetail, useMyMemberships, useMyPasses, useMyReservationDetail, useMyReservations, usePackage, usePackagePreview, usePackages, useProducts, usePublicMemberships, useStartTimes } from './chunk-
|
|
3
|
-
import { BowlosApiError, getGameCardStatus, createGameCardOrder, getPackageStatus, createPackageOrder } from './chunk-
|
|
1
|
+
import { useBowlosClient } from './chunk-FV6SROO2.js';
|
|
2
|
+
export { BowlosProvider, useAccount, useAddons, useAvailability, useBookingFlow, useBookingPreview, useBowlosClient, useBowlosQuery, useCatalog, useCenterHours, useEventOffer, useEventOffers, useEventTicketPreview, useEvents, useFlashSale, useFlashSaleBookingOptions, useFlashSales, useGameCardPreview, useGameCards, useMembershipPreview, useMembershipSubscriptionPreview, useMyCredits, useMyEventOrder, useMyEventOrders, useMyLoyalty, useMyMembershipDetail, useMyMemberships, useMyPasses, useMyReservationDetail, useMyReservations, usePackage, usePackagePreview, usePackages, useProducts, usePublicMemberships, useStartTimes } from './chunk-FV6SROO2.js';
|
|
3
|
+
import { BowlosApiError, getGameCardStatus, createGameCardOrder, getPackageStatus, createPackageOrder, getEventTicketStatus, createEventTicketOrder, getMembershipStatus, createMembershipOrder, createMembershipSubscriptionOrder } from './chunk-S5T4OCBY.js';
|
|
4
4
|
import { useState, useRef, useCallback, useEffect } from 'react';
|
|
5
5
|
|
|
6
6
|
var DEFAULT_POLL_MS = 2500;
|
|
@@ -149,7 +149,105 @@ function usePackagePurchase() {
|
|
|
149
149
|
}
|
|
150
150
|
});
|
|
151
151
|
}
|
|
152
|
+
function useEventTicketPurchase() {
|
|
153
|
+
const client = useBowlosClient();
|
|
154
|
+
return usePurchase({
|
|
155
|
+
createIntent: async (args) => {
|
|
156
|
+
const r = await createEventTicketOrder(client, args);
|
|
157
|
+
return {
|
|
158
|
+
paymentIntent: {
|
|
159
|
+
paymentIntentId: r.paymentIntentId,
|
|
160
|
+
clientSecret: r.clientSecret,
|
|
161
|
+
amountCents: r.amountCents,
|
|
162
|
+
connectedAccountId: r.connectedAccountId,
|
|
163
|
+
customerSessionClientSecret: r.customerSessionClientSecret
|
|
164
|
+
},
|
|
165
|
+
refToken: r.orderId
|
|
166
|
+
};
|
|
167
|
+
},
|
|
168
|
+
pollStatus: (orderId) => getEventTicketStatus(client, orderId),
|
|
169
|
+
interpret: (s) => {
|
|
170
|
+
switch (s.status) {
|
|
171
|
+
case "paid":
|
|
172
|
+
return { done: true, terminal: "confirmed", id: s.orderId };
|
|
173
|
+
case "cancelled":
|
|
174
|
+
case "refunded":
|
|
175
|
+
return { done: true, terminal: "failed", id: null };
|
|
176
|
+
case "not_found":
|
|
177
|
+
return { done: true, terminal: "error", id: null };
|
|
178
|
+
case "pending_payment":
|
|
179
|
+
default:
|
|
180
|
+
return { done: false, terminal: null, id: null };
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
function useMembershipPurchase() {
|
|
186
|
+
const client = useBowlosClient();
|
|
187
|
+
return usePurchase({
|
|
188
|
+
createIntent: async (args) => {
|
|
189
|
+
const r = await createMembershipOrder(client, args);
|
|
190
|
+
return {
|
|
191
|
+
paymentIntent: {
|
|
192
|
+
paymentIntentId: r.paymentIntentId,
|
|
193
|
+
clientSecret: r.clientSecret,
|
|
194
|
+
amountCents: r.amountCents,
|
|
195
|
+
connectedAccountId: r.connectedAccountId,
|
|
196
|
+
customerSessionClientSecret: r.customerSessionClientSecret
|
|
197
|
+
},
|
|
198
|
+
refToken: r.refToken
|
|
199
|
+
};
|
|
200
|
+
},
|
|
201
|
+
pollStatus: (refToken) => getMembershipStatus(client, refToken),
|
|
202
|
+
interpret: (s) => {
|
|
203
|
+
switch (s.status) {
|
|
204
|
+
case "paid_materialized":
|
|
205
|
+
return { done: true, terminal: "confirmed", id: s.membershipId };
|
|
206
|
+
case "expired":
|
|
207
|
+
return { done: true, terminal: "expired", id: null };
|
|
208
|
+
case "payment_failed_retryable":
|
|
209
|
+
case "abandoned":
|
|
210
|
+
return { done: true, terminal: "failed", id: null };
|
|
211
|
+
case "not_found":
|
|
212
|
+
return { done: true, terminal: "error", id: null };
|
|
213
|
+
case "pending_payment":
|
|
214
|
+
default:
|
|
215
|
+
return { done: false, terminal: null, id: null };
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
function useMembershipSubscriptionCheckout() {
|
|
221
|
+
const client = useBowlosClient();
|
|
222
|
+
const [status, setStatus] = useState(
|
|
223
|
+
"idle"
|
|
224
|
+
);
|
|
225
|
+
const [subscriptionIntent, setSubscriptionIntent] = useState(null);
|
|
226
|
+
const [error, setError] = useState(null);
|
|
227
|
+
const start = useCallback(
|
|
228
|
+
async (args) => {
|
|
229
|
+
setError(null);
|
|
230
|
+
setSubscriptionIntent(null);
|
|
231
|
+
setStatus("creating");
|
|
232
|
+
try {
|
|
233
|
+
const intent = await createMembershipSubscriptionOrder(client, args);
|
|
234
|
+
setSubscriptionIntent(intent);
|
|
235
|
+
setStatus("awaitingPayment");
|
|
236
|
+
} catch (e) {
|
|
237
|
+
if (e instanceof BowlosApiError) setError(e);
|
|
238
|
+
setStatus("error");
|
|
239
|
+
}
|
|
240
|
+
},
|
|
241
|
+
[client]
|
|
242
|
+
);
|
|
243
|
+
const reset = useCallback(() => {
|
|
244
|
+
setSubscriptionIntent(null);
|
|
245
|
+
setError(null);
|
|
246
|
+
setStatus("idle");
|
|
247
|
+
}, []);
|
|
248
|
+
return { status, subscriptionIntent, error, start, reset };
|
|
249
|
+
}
|
|
152
250
|
|
|
153
|
-
export { useGameCardPurchase, usePackagePurchase, usePurchase };
|
|
251
|
+
export { useEventTicketPurchase, useGameCardPurchase, useMembershipPurchase, useMembershipSubscriptionCheckout, usePackagePurchase, usePurchase };
|
|
154
252
|
//# sourceMappingURL=react.js.map
|
|
155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,UACb,iBAAiB,CAAA,CAAE,eAAA;AAAA,UACnB,cAAc,CAAA,CAAE,YAAA;AAAA,UAChB,aAAa,CAAA,CAAE,WAAA;AAAA,UACf,oBAAoB,CAAA,CAAE,kBAAA;AAAA,UACtB,6BAA6B,CAAA,CAAE;AAAA,SACjC;AAAA;AAAA,QAEA,UAAU,CAAA,CAAE;AAAA,OACd;AAAA,IACF,CAAA;AAAA,IACA,UAAA,EAAY,CAAC,OAAA,KAAY,gBAAA,CAAiB,QAAQ,OAAO,CAAA;AAAA,IACzD,SAAA,EAAW,CAAC,CAAA,KAAM;AAChB,MAAA,QAAQ,EAAE,MAAA;AAAQ,QAChB,KAAK,MAAA;AACH,UAAA,OAAO,EAAE,IAAA,EAAM,IAAA,EAAM,UAAU,WAAA,EAAa,EAAA,EAAI,EAAE,OAAA,EAAQ;AAAA,QAC5D,KAAK,WAAA;AAAA,QACL,KAAK,UAAA;AACH,UAAA,OAAO,EAAE,IAAA,EAAM,IAAA,EAAM,QAAA,EAAU,QAAA,EAAU,IAAI,IAAA,EAAK;AAAA,QACpD,KAAK,WAAA;AACH,UAAA,OAAO,EAAE,IAAA,EAAM,IAAA,EAAM,QAAA,EAAU,OAAA,EAAS,IAAI,IAAA,EAAK;AAAA,QACnD,KAAK,iBAAA;AAAA,QACL;AACE,UAAA,OAAO,EAAE,IAAA,EAAM,KAAA,EAAO,QAAA,EAAU,IAAA,EAAM,IAAI,IAAA,EAAK;AAAA;AACnD,IACF;AAAA,GACD,CAAA;AACH","file":"react.js","sourcesContent":["\"use client\";\n/**\n * usePurchase — the headless buy state machine for game passes (packages +\n * memberships adopt it next). Mirrors `useBookingFlow`, minus the inventory\n * hold: the PaymentIntent IS the purchase.\n *\n * start(args) → mints the connected-account PaymentIntent → \"awaitingPayment\"\n * [render <BowlosPaymentForm {...paymentIntent}> and the customer pays]\n * startPolling() → polls the type's status endpoint → \"confirmed\" (+ resultId)\n *\n * Per-type wrappers (`useGameCardPurchase`, …) supply the create call + a status\n * interpreter that maps the type's status to the shared terminal states (D2/D5).\n */\nimport { useCallback, useEffect, useRef, useState } from \"react\";\nimport { useBowlosClient } from \"./react\";\nimport { BowlosApiError } from \"./errors\";\nimport {\n createGameCardOrder,\n getGameCardStatus,\n createPackageOrder,\n getPackageStatus,\n type GameCardPurchaseArgs,\n type GameCardStatusResult,\n type PackagePurchaseArgs,\n type PackageStatusResult,\n} from \"./data\";\n\nexport type PurchaseStatus =\n | \"idle\"\n | \"creating\"\n | \"awaitingPayment\"\n | \"confirming\"\n | \"confirmed\"\n | \"failed\"\n | \"expired\"\n | \"error\";\n\n/** The connected-account payment to confirm with `<BowlosPaymentForm>`. */\nexport interface PurchasePaymentIntent {\n paymentIntentId: string;\n clientSecret: string;\n amountCents: number;\n connectedAccountId: string;\n customerSessionClientSecret: string;\n}\n\nexport interface UsePurchaseResult<Args> {\n status: PurchaseStatus;\n paymentIntent: PurchasePaymentIntent | null;\n /** The materialized id (game card / order / membership) once confirmed. */\n resultId: string | null;\n error: BowlosApiError | null;\n /** Mint the PaymentIntent → \"awaitingPayment\". */\n start: (args: Args) => Promise<void>;\n /** Call after `<BowlosPaymentForm>` confirms → begins polling to materialization. */\n startPolling: (intervalMs?: number) => void;\n stopPolling: () => void;\n reset: () => void;\n}\n\n/** A type-specific status mapped to the shared terminal states. */\ntype Interpreted = {\n done: boolean;\n terminal: \"confirmed\" | \"failed\" | \"expired\" | \"error\" | null;\n id: string | null;\n};\n\nconst DEFAULT_POLL_MS = 2500;\n\nexport function usePurchase<Args, Status>(config: {\n createIntent: (\n args: Args,\n ) => Promise<{ paymentIntent: PurchasePaymentIntent; refToken: string | null }>;\n pollStatus: (refToken: string) => Promise<Status>;\n interpret: (status: Status) => Interpreted;\n}): UsePurchaseResult<Args> {\n const [status, setStatus] = useState<PurchaseStatus>(\"idle\");\n const [paymentIntent, setPaymentIntent] = useState<PurchasePaymentIntent | null>(null);\n const [resultId, setResultId] = useState<string | null>(null);\n const [error, setError] = useState<BowlosApiError | null>(null);\n\n const refTokenRef = useRef<string | null>(null);\n const pollRef = useRef<ReturnType<typeof setInterval> | null>(null);\n // Latest config in a ref so the polling interval never captures a stale closure.\n const cfgRef = useRef(config);\n cfgRef.current = config;\n\n const stopPolling = useCallback(() => {\n if (pollRef.current !== null) {\n clearInterval(pollRef.current);\n pollRef.current = null;\n }\n }, []);\n useEffect(() => stopPolling, [stopPolling]);\n\n const reset = useCallback(() => {\n stopPolling();\n refTokenRef.current = null;\n setPaymentIntent(null);\n setResultId(null);\n setError(null);\n setStatus(\"idle\");\n }, [stopPolling]);\n\n const start = useCallback(\n async (args: Args) => {\n stopPolling();\n setError(null);\n setResultId(null);\n setPaymentIntent(null);\n setStatus(\"creating\");\n try {\n const { paymentIntent: pi, refToken } = await cfgRef.current.createIntent(args);\n refTokenRef.current = refToken;\n setPaymentIntent(pi);\n setStatus(\"awaitingPayment\");\n } catch (e) {\n if (e instanceof BowlosApiError) setError(e);\n setStatus(\"error\");\n }\n },\n [stopPolling],\n );\n\n const poll = useCallback(async () => {\n const rt = refTokenRef.current;\n if (!rt) return;\n try {\n const r = cfgRef.current.interpret(await cfgRef.current.pollStatus(rt));\n if (!r.done) return;\n stopPolling();\n if (r.terminal === \"confirmed\") {\n setResultId(r.id);\n setStatus(\"confirmed\");\n } else if (r.terminal === \"expired\") {\n setStatus(\"expired\");\n } else if (r.terminal === \"failed\") {\n setStatus(\"failed\");\n } else {\n setError(new BowlosApiError(\"NOT_FOUND\", \"Purchase not found.\", 404));\n setStatus(\"error\");\n }\n } catch (e) {\n if (e instanceof BowlosApiError) setError(e);\n }\n }, [stopPolling]);\n\n const startPolling = useCallback(\n (intervalMs: number = DEFAULT_POLL_MS) => {\n stopPolling();\n setStatus(\"confirming\");\n void poll();\n pollRef.current = setInterval(() => void poll(), intervalMs);\n },\n [poll, stopPolling],\n );\n\n return { status, paymentIntent, resultId, error, start, startPolling, stopPolling, reset };\n}\n\n/**\n * Buy a game pass. `start({ templateId })` → render\n * `<BowlosPaymentForm {...purchase.paymentIntent} onPaid={purchase.startPolling}>`\n * → `status === \"confirmed\"` (`resultId` = the new game card id).\n */\nexport function useGameCardPurchase(): UsePurchaseResult<GameCardPurchaseArgs> {\n const client = useBowlosClient();\n return usePurchase<GameCardPurchaseArgs, GameCardStatusResult>({\n createIntent: async (args) => {\n const r = await createGameCardOrder(client, args);\n return {\n paymentIntent: {\n paymentIntentId: r.paymentIntentId,\n clientSecret: r.clientSecret,\n amountCents: r.amountCents,\n connectedAccountId: r.connectedAccountId,\n customerSessionClientSecret: r.customerSessionClientSecret,\n },\n refToken: r.refToken,\n };\n },\n pollStatus: (refToken) => getGameCardStatus(client, refToken),\n interpret: (s) => {\n switch (s.status) {\n case \"paid_materialized\":\n return { done: true, terminal: \"confirmed\", id: s.gameCardId };\n case \"expired\":\n return { done: true, terminal: \"expired\", id: null };\n case \"payment_failed_retryable\":\n case \"abandoned\":\n return { done: true, terminal: \"failed\", id: null };\n case \"not_found\":\n return { done: true, terminal: \"error\", id: null };\n case \"pending_payment\":\n default:\n return { done: false, terminal: null, id: null };\n }\n },\n });\n}\n\n/**\n * Buy a package (birthday party, lane bundle, …). Unlike a game pass, a package\n * carries a configuration — `start()` takes the Center, date/time, quantity, and\n * any optional add-ons:\n *\n * start({ packageId, centerId, quantity, scheduledDate, scheduledStartMinute, optionalAddons })\n * → render `<BowlosPaymentForm {...purchase.paymentIntent} onPaid={purchase.startPolling}>`\n * → `status === \"confirmed\"` (`resultId` = the new package order id).\n *\n * The site owns the config UI (see HEADLESS.md → \"Buying a package\" for computing\n * the bookable start times from the package + Center hours). `scheduledStartMinute`\n * MUST be one of those slots or the create rejects with VALIDATION_FAILED.\n */\nexport function usePackagePurchase(): UsePurchaseResult<PackagePurchaseArgs> {\n const client = useBowlosClient();\n return usePurchase<PackagePurchaseArgs, PackageStatusResult>({\n createIntent: async (args) => {\n const r = await createPackageOrder(client, args);\n return {\n paymentIntent: {\n paymentIntentId: r.paymentIntentId,\n clientSecret: r.clientSecret,\n amountCents: r.amountCents,\n connectedAccountId: r.connectedAccountId,\n customerSessionClientSecret: r.customerSessionClientSecret,\n },\n // The order id is the poll handle (packages have no refToken).\n refToken: r.orderId,\n };\n },\n pollStatus: (orderId) => getPackageStatus(client, orderId),\n interpret: (s) => {\n switch (s.status) {\n case \"paid\":\n return { done: true, terminal: \"confirmed\", id: s.orderId };\n case \"cancelled\":\n case \"refunded\":\n return { done: true, terminal: \"failed\", id: null };\n case \"not_found\":\n return { done: true, terminal: \"error\", id: null };\n case \"pending_payment\":\n default:\n return { done: false, terminal: null, id: null };\n }\n },\n });\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/use-purchase.tsx"],"names":[],"mappings":";;;;;AA8EA,IAAM,eAAA,GAAkB,IAAA;AAEjB,SAAS,YAA0B,MAAA,EAMd;AAC1B,EAAA,MAAM,CAAC,MAAA,EAAQ,SAAS,CAAA,GAAI,SAAyB,MAAM,CAAA;AAC3D,EAAA,MAAM,CAAC,aAAA,EAAe,gBAAgB,CAAA,GAAI,SAAuC,IAAI,CAAA;AACrF,EAAA,MAAM,CAAC,QAAA,EAAU,WAAW,CAAA,GAAI,SAAwB,IAAI,CAAA;AAC5D,EAAA,MAAM,CAAC,KAAA,EAAO,QAAQ,CAAA,GAAI,SAAgC,IAAI,CAAA;AAE9D,EAAA,MAAM,WAAA,GAAc,OAAsB,IAAI,CAAA;AAC9C,EAAA,MAAM,OAAA,GAAU,OAA8C,IAAI,CAAA;AAElE,EAAA,MAAM,MAAA,GAAS,OAAO,MAAM,CAAA;AAC5B,EAAA,MAAA,CAAO,OAAA,GAAU,MAAA;AAEjB,EAAA,MAAM,WAAA,GAAc,YAAY,MAAM;AACpC,IAAA,IAAI,OAAA,CAAQ,YAAY,IAAA,EAAM;AAC5B,MAAA,aAAA,CAAc,QAAQ,OAAO,CAAA;AAC7B,MAAA,OAAA,CAAQ,OAAA,GAAU,IAAA;AAAA,IACpB;AAAA,EACF,CAAA,EAAG,EAAE,CAAA;A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passes (packages +\n * memberships adopt it next). Mirrors `useBookingFlow`, minus the inventory\n * hold: the PaymentIntent IS the purchase.\n *\n * start(args) → mints the connected-account PaymentIntent → \"awaitingPayment\"\n * [render <BowlosPaymentForm {...paymentIntent}> and the customer pays]\n * startPolling() → polls the type's status endpoint → \"confirmed\" (+ resultId)\n *\n * Per-type wrappers (`useGameCardPurchase`, …) supply the create call + a status\n * interpreter that maps the type's status to the shared terminal states (D2/D5).\n */\nimport { useCallback, useEffect, useRef, useState } from \"react\";\nimport { useBowlosClient } from \"./react\";\nimport { BowlosApiError } from \"./errors\";\nimport {\n createGameCardOrder,\n getGameCardStatus,\n createPackageOrder,\n getPackageStatus,\n createEventTicketOrder,\n getEventTicketStatus,\n createMembershipOrder,\n getMembershipStatus,\n createMembershipSubscriptionOrder,\n type GameCardPurchaseArgs,\n type GameCardStatusResult,\n type PackagePurchaseArgs,\n type PackageStatusResult,\n type EventTicketPurchaseArgs,\n type EventTicketStatusResult,\n type MembershipPurchaseArgs,\n type MembershipStatusResult,\n type MembershipSubscriptionArgs,\n type MembershipSubscriptionIntent,\n} from \"./data\";\n\nexport type PurchaseStatus =\n | \"idle\"\n | \"creating\"\n | \"awaitingPayment\"\n | \"confirming\"\n | \"confirmed\"\n | \"failed\"\n | \"expired\"\n | \"error\";\n\n/** The connected-account payment to confirm with `<BowlosPaymentForm>`. */\nexport interface PurchasePaymentIntent {\n paymentIntentId: string;\n clientSecret: string;\n amountCents: number;\n connectedAccountId: string;\n customerSessionClientSecret: string;\n}\n\nexport interface UsePurchaseResult<Args> {\n status: PurchaseStatus;\n paymentIntent: PurchasePaymentIntent | null;\n /** The materialized id (game card / order / membership) once confirmed. */\n resultId: string | null;\n error: BowlosApiError | null;\n /** Mint the PaymentIntent → \"awaitingPayment\". */\n start: (args: Args) => Promise<void>;\n /** Call after `<BowlosPaymentForm>` confirms → begins polling to materialization. */\n startPolling: (intervalMs?: number) => void;\n stopPolling: () => void;\n reset: () => void;\n}\n\n/** A type-specific status mapped to the shared terminal states. */\ntype Interpreted = {\n done: boolean;\n terminal: \"confirmed\" | \"failed\" | \"expired\" | \"error\" | null;\n id: string | null;\n};\n\nconst DEFAULT_POLL_MS = 2500;\n\nexport function usePurchase<Args, Status>(config: {\n createIntent: (\n args: Args,\n ) => Promise<{ paymentIntent: PurchasePaymentIntent; refToken: string | null }>;\n pollStatus: (refToken: string) => Promise<Status>;\n interpret: (status: Status) => Interpreted;\n}): UsePurchaseResult<Args> {\n const [status, setStatus] = useState<PurchaseStatus>(\"idle\");\n const [paymentIntent, setPaymentIntent] = useState<PurchasePaymentIntent | null>(null);\n const [resultId, setResultId] = useState<string | null>(null);\n const [error, setError] = useState<BowlosApiError | null>(null);\n\n const refTokenRef = useRef<string | null>(null);\n const pollRef = useRef<ReturnType<typeof setInterval> | null>(null);\n // Latest config in a ref so the polling interval never captures a stale closure.\n const cfgRef = useRef(config);\n cfgRef.current = config;\n\n const stopPolling = useCallback(() => {\n if (pollRef.current !== null) {\n clearInterval(pollRef.current);\n pollRef.current = null;\n }\n }, []);\n useEffect(() => stopPolling, [stopPolling]);\n\n const reset = useCallback(() => {\n stopPolling();\n refTokenRef.current = null;\n setPaymentIntent(null);\n setResultId(null);\n setError(null);\n setStatus(\"idle\");\n }, [stopPolling]);\n\n const start = useCallback(\n async (args: Args) => {\n stopPolling();\n setError(null);\n setResultId(null);\n setPaymentIntent(null);\n setStatus(\"creating\");\n try {\n const { paymentIntent: pi, refToken } = await cfgRef.current.createIntent(args);\n refTokenRef.current = refToken;\n setPaymentIntent(pi);\n setStatus(\"awaitingPayment\");\n } catch (e) {\n if (e instanceof BowlosApiError) setError(e);\n setStatus(\"error\");\n }\n },\n [stopPolling],\n );\n\n const poll = useCallback(async () => {\n const rt = refTokenRef.current;\n if (!rt) return;\n try {\n const r = cfgRef.current.interpret(await cfgRef.current.pollStatus(rt));\n if (!r.done) return;\n stopPolling();\n if (r.terminal === \"confirmed\") {\n setResultId(r.id);\n setStatus(\"confirmed\");\n } else if (r.terminal === \"expired\") {\n setStatus(\"expired\");\n } else if (r.terminal === \"failed\") {\n setStatus(\"failed\");\n } else {\n setError(new BowlosApiError(\"NOT_FOUND\", \"Purchase not found.\", 404));\n setStatus(\"error\");\n }\n } catch (e) {\n if (e instanceof BowlosApiError) setError(e);\n }\n }, [stopPolling]);\n\n const startPolling = useCallback(\n (intervalMs: number = DEFAULT_POLL_MS) => {\n stopPolling();\n setStatus(\"confirming\");\n void poll();\n pollRef.current = setInterval(() => void poll(), intervalMs);\n },\n [poll, stopPolling],\n );\n\n return { status, paymentIntent, resultId, error, start, startPolling, stopPolling, reset };\n}\n\n/**\n * Buy a game pass. `start({ templateId })` → render\n * `<BowlosPaymentForm {...purchase.paymentIntent} onPaid={purchase.startPolling}>`\n * → `status === \"confirmed\"` (`resultId` = the new game card id).\n */\nexport function useGameCardPurchase(): UsePurchaseResult<GameCardPurchaseArgs> {\n const client = useBowlosClient();\n return usePurchase<GameCardPurchaseArgs, GameCardStatusResult>({\n createIntent: async (args) => {\n const r = await createGameCardOrder(client, args);\n return {\n paymentIntent: {\n paymentIntentId: r.paymentIntentId,\n clientSecret: r.clientSecret,\n amountCents: r.amountCents,\n connectedAccountId: r.connectedAccountId,\n customerSessionClientSecret: r.customerSessionClientSecret,\n },\n refToken: r.refToken,\n };\n },\n pollStatus: (refToken) => getGameCardStatus(client, refToken),\n interpret: (s) => {\n switch (s.status) {\n case \"paid_materialized\":\n return { done: true, terminal: \"confirmed\", id: s.gameCardId };\n case \"expired\":\n return { done: true, terminal: \"expired\", id: null };\n case \"payment_failed_retryable\":\n case \"abandoned\":\n return { done: true, terminal: \"failed\", id: null };\n case \"not_found\":\n return { done: true, terminal: \"error\", id: null };\n case \"pending_payment\":\n default:\n return { done: false, terminal: null, id: null };\n }\n },\n });\n}\n\n/**\n * Buy a package (birthday party, lane bundle, …). Unlike a game pass, a package\n * carries a configuration — `start()` takes the Center, date/time, quantity, and\n * any optional add-ons:\n *\n * start({ packageId, centerId, quantity, scheduledDate, scheduledStartMinute, optionalAddons })\n * → render `<BowlosPaymentForm {...purchase.paymentIntent} onPaid={purchase.startPolling}>`\n * → `status === \"confirmed\"` (`resultId` = the new package order id).\n *\n * The site owns the config UI (see HEADLESS.md → \"Buying a package\" for computing\n * the bookable start times from the package + Center hours). `scheduledStartMinute`\n * MUST be one of those slots or the create rejects with VALIDATION_FAILED.\n */\nexport function usePackagePurchase(): UsePurchaseResult<PackagePurchaseArgs> {\n const client = useBowlosClient();\n return usePurchase<PackagePurchaseArgs, PackageStatusResult>({\n createIntent: async (args) => {\n const r = await createPackageOrder(client, args);\n return {\n paymentIntent: {\n paymentIntentId: r.paymentIntentId,\n clientSecret: r.clientSecret,\n amountCents: r.amountCents,\n connectedAccountId: r.connectedAccountId,\n customerSessionClientSecret: r.customerSessionClientSecret,\n },\n // The order id is the poll handle (packages have no refToken).\n refToken: r.orderId,\n };\n },\n pollStatus: (orderId) => getPackageStatus(client, orderId),\n interpret: (s) => {\n switch (s.status) {\n case \"paid\":\n return { done: true, terminal: \"confirmed\", id: s.orderId };\n case \"cancelled\":\n case \"refunded\":\n return { done: true, terminal: \"failed\", id: null };\n case \"not_found\":\n return { done: true, terminal: \"error\", id: null };\n case \"pending_payment\":\n default:\n return { done: false, terminal: null, id: null };\n }\n },\n });\n}\n\n/**\n * Buy tickets for a ticket-mode event offer. `start({ eventOfferId, quantity })`\n * → render `<BowlosPaymentForm {...purchase.paymentIntent} onPaid={purchase.startPolling}>`\n * → `status === \"confirmed\"` (`resultId` = the event order id). The charge\n * lands on the operator's connected account and the order receipt is available\n * through `useMyEventOrder` after confirmation.\n */\nexport function useEventTicketPurchase(): UsePurchaseResult<EventTicketPurchaseArgs> {\n const client = useBowlosClient();\n return usePurchase<EventTicketPurchaseArgs, EventTicketStatusResult>({\n createIntent: async (args) => {\n const r = await createEventTicketOrder(client, args);\n return {\n paymentIntent: {\n paymentIntentId: r.paymentIntentId,\n clientSecret: r.clientSecret,\n amountCents: r.amountCents,\n connectedAccountId: r.connectedAccountId,\n customerSessionClientSecret: r.customerSessionClientSecret,\n },\n refToken: r.orderId,\n };\n },\n pollStatus: (orderId) => getEventTicketStatus(client, orderId),\n interpret: (s) => {\n switch (s.status) {\n case \"paid\":\n return { done: true, terminal: \"confirmed\", id: s.orderId };\n case \"cancelled\":\n case \"refunded\":\n return { done: true, terminal: \"failed\", id: null };\n case \"not_found\":\n return { done: true, terminal: \"error\", id: null };\n case \"pending_payment\":\n default:\n return { done: false, terminal: null, id: null };\n }\n },\n });\n}\n\n/**\n * Buy a one-time membership. Same lifecycle as a game pass (no config) —\n * `start({ templateId })` → render\n * `<BowlosPaymentForm {...purchase.paymentIntent} onPaid={purchase.startPolling}>`\n * → `status === \"confirmed\"` (`resultId` = the new membership id). The charge\n * lands on the operator's connected account.\n */\nexport function useMembershipPurchase(): UsePurchaseResult<MembershipPurchaseArgs> {\n const client = useBowlosClient();\n return usePurchase<MembershipPurchaseArgs, MembershipStatusResult>({\n createIntent: async (args) => {\n const r = await createMembershipOrder(client, args);\n return {\n paymentIntent: {\n paymentIntentId: r.paymentIntentId,\n clientSecret: r.clientSecret,\n amountCents: r.amountCents,\n connectedAccountId: r.connectedAccountId,\n customerSessionClientSecret: r.customerSessionClientSecret,\n },\n refToken: r.refToken,\n };\n },\n pollStatus: (refToken) => getMembershipStatus(client, refToken),\n interpret: (s) => {\n switch (s.status) {\n case \"paid_materialized\":\n return { done: true, terminal: \"confirmed\", id: s.membershipId };\n case \"expired\":\n return { done: true, terminal: \"expired\", id: null };\n case \"payment_failed_retryable\":\n case \"abandoned\":\n return { done: true, terminal: \"failed\", id: null };\n case \"not_found\":\n return { done: true, terminal: \"error\", id: null };\n case \"pending_payment\":\n default:\n return { done: false, terminal: null, id: null };\n }\n },\n });\n}\n\n/** State for `useMembershipSubscriptionCheckout`. A recurring subscription has no\n * refToken to poll — it materializes via webhook — so this is a leaner machine\n * than `usePurchase`: mint the first-invoice payment, confirm it, then re-query\n * `useMyMemberships` (which updates reactively once the webhook lands). */\nexport interface UseSubscriptionCheckoutResult {\n status: \"idle\" | \"creating\" | \"awaitingPayment\" | \"error\";\n subscriptionIntent: MembershipSubscriptionIntent | null;\n error: BowlosApiError | null;\n /** Mint the subscription + its first-invoice payment → \"awaitingPayment\". */\n start: (args: MembershipSubscriptionArgs) => Promise<void>;\n reset: () => void;\n}\n\n/**\n * Start a recurring membership subscription. `start({ templateId })` mints the\n * subscription + its first-invoice PaymentIntent on the operator's connected\n * account → render `<BowlosPaymentForm {...checkout.subscriptionIntent}>` to\n * confirm. There is **no poll**: once the customer pays, the subscription\n * materializes via webhook — re-query `useMyMemberships` to show the new\n * membership (the list updates reactively).\n */\nexport function useMembershipSubscriptionCheckout(): UseSubscriptionCheckoutResult {\n const client = useBowlosClient();\n const [status, setStatus] = useState<\"idle\" | \"creating\" | \"awaitingPayment\" | \"error\">(\n \"idle\",\n );\n const [subscriptionIntent, setSubscriptionIntent] =\n useState<MembershipSubscriptionIntent | null>(null);\n const [error, setError] = useState<BowlosApiError | null>(null);\n\n const start = useCallback(\n async (args: MembershipSubscriptionArgs) => {\n setError(null);\n setSubscriptionIntent(null);\n setStatus(\"creating\");\n try {\n const intent = await createMembershipSubscriptionOrder(client, args);\n setSubscriptionIntent(intent);\n setStatus(\"awaitingPayment\");\n } catch (e) {\n if (e instanceof BowlosApiError) setError(e);\n setStatus(\"error\");\n }\n },\n [client],\n );\n\n const reset = useCallback(() => {\n setSubscriptionIntent(null);\n setError(null);\n setStatus(\"idle\");\n }, []);\n\n return { status, subscriptionIntent, error, start, reset };\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bowlos/reservations",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.0",
|
|
4
4
|
"description": "BowlOS Reservations SDK — headless client + React hooks for the Module 14 public API gateway. White-label booking, account, and flash-sale reads for third-party-hosted center sites.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "BowlOS",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/react.tsx","../src/hooks.tsx","../src/use-booking-flow.tsx"],"names":["useState","useRef","useCallback","useEffect"],"mappings":";;;;AAwBA,IAAM,aAAA,GAAgB,cAAmC,IAAI,CAAA;AAC7D,IAAM,cAAA,GAAiB,cAAuC,IAAI,CAAA;AAS3D,SAAS,cAAA,CAAe,EAAE,MAAA,EAAQ,MAAA,EAAQ,UAAS,EAAwB;AAChF,EAAA,MAAM,GAAA,GAAM,MAAA,CAA4B,MAAA,IAAU,IAAI,CAAA;AACtD,EAAA,IAAI,CAAC,IAAI,OAAA,EAAS;AAChB,IAAA,IAAI,CAAC,MAAA,EAAQ;AACX,MAAA,MAAM,IAAI,MAAM,0DAA0D,CAAA;AAAA,IAC5E;AACA,IAAA,GAAA,CAAI,OAAA,GAAU,mBAAmB,MAAM,CAAA;AAAA,EACzC;AACA,EAAA,MAAM,eAAe,GAAA,CAAI,OAAA;AAGzB,EAAA,MAAM,OAAA,GAAU,gBAAgB,YAAY,CAAA;AAC5C,EAAA,uBACE,GAAA,CAAC,aAAA,CAAc,QAAA,EAAd,EAAuB,KAAA,EAAO,YAAA,EAC7B,QAAA,kBAAA,GAAA,CAAC,cAAA,CAAe,QAAA,EAAf,EAAwB,KAAA,EAAO,OAAA,EAAU,UAAS,CAAA,EACrD,CAAA;AAEJ;AAEO,SAAS,eAAA,GAAgC;AAC9C,EAAA,MAAM,MAAA,GAAS,WAAW,aAAa,CAAA;AACvC,EAAA,IAAI,CAAC,MAAA,EAAQ;AACX,IAAA,MAAM,IAAI,MAAM,yDAAyD,CAAA;AAAA,EAC3E;AACA,EAAA,OAAO,MAAA;AACT;AAoBA,SAAS,gBAAgB,MAAA,EAAwC;AAC/D,EAAA,MAAM,CAAC,MAAA,EAAQ,SAAS,CAAA,GAAI,SAAwB,SAAS,CAAA;AAC7D,EAAA,MAAM,CAAC,QAAA,EAAU,WAAW,CAA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ClB,GAAG,UAAU,CAAA;AAAA,IACf,CAAA;AAAA,IACA,CAAC,YAAY,WAAW;AAAA,GAC1B;AAEA,EAAA,MAAM,OAAA,GAAUA,YAAY,YAAY;AACtC,IAAA,WAAA,EAAY;AACZ,IAAA,MAAM,KAAK,WAAA,CAAY,OAAA;AACvB,IAAA,IAAI,EAAA,EAAI;AACN,MAAA,IAAI;AACF,QAAA,MAAM,eAAA,CAAoB,QAAQ,EAAE,CAAA;AAAA,MACtC,CAAA,CAAA,MAAQ;AAAA,MAER;AAAA,IACF;AACA,IAAA,SAAA,CAAU,WAAW,CAAA;AAAA,EACvB,CAAA,EAAG,CAAC,MAAA,EAAQ,WAAW,CAAC,CAAA;AAExB,EAAA,OAAO;AAAA,IACL,MAAA;AAAA,IACA,IAAA;AAAA,IACA,QAAA;AAAA,IACA,aAAA;AAAA,IACA,WAAA;AAAA,IACA,eAAA,EAAiB,IAAA,GAAO,IAAA,CAAK,eAAA,GAAkB,IAAA;AAAA,IAC/C,KAAA;AAAA,IACA,SAAA;AAAA,IACA,cAAA;AAAA,IACA,UAAA;AAAA,IACA,YAAA;AAAA,IACA,WAAA;AAAA,IACA,OAAA;AAAA,IACA;AAAA,GACF;AACF","file":"chunk-BPLYLQO3.js","sourcesContent":["/**\n * React layer for @bowlos/reservations.\n *\n * `<BowlosProvider>` holds one `BowlosClient`; `useAccount()` manages the\n * customer session (probe on mount, sign-in/up/link/out, current customer);\n * `useBowlosQuery()` is the generic read hook the typed data hooks\n * (`useAvailability`, `useBookingFlow`, …) will build on next.\n *\n * Lives in its own module so non-React consumers of the core never pull React.\n * (The `@bowlos/reservations/react` export subpath is wired with the publish build.)\n */\nimport {\n createContext,\n useCallback,\n useContext,\n useEffect,\n useRef,\n useState,\n type ReactNode,\n} from \"react\";\nimport { BowlosClient, createBowlosClient } from \"./client\";\nimport { BowlosApiError } from \"./errors\";\nimport type { AuthState, BowlosClientConfig, Customer, LinkProfile } from \"./types\";\n\nconst BowlosContext = createContext<BowlosClient | null>(null);\nconst AccountContext = createContext<UseAccountResult | null>(null);\n\nexport interface BowlosProviderProps {\n /** A prebuilt client, or pass `config` to have one created and memoized. */\n client?: BowlosClient;\n config?: BowlosClientConfig;\n children: ReactNode;\n}\n\nexport function BowlosProvider({ client, config, children }: BowlosProviderProps) {\n const ref = useRef<BowlosClient | null>(client ?? null);\n if (!ref.current) {\n if (!config) {\n throw new Error(\"BowlosProvider requires either a `client` or a `config`.\");\n }\n ref.current = createBowlosClient(config);\n }\n const bowlosClient = ref.current as BowlosClient; // non-null after the guard above\n // Run the session machine ONCE here and share it via context, so every\n // useAccount() across the app sees the same session.\n const account = useAccountState(bowlosClient);\n return (\n <BowlosContext.Provider value={bowlosClient}>\n <AccountContext.Provider value={account}>{children}</AccountContext.Provider>\n </BowlosContext.Provider>\n );\n}\n\nexport function useBowlosClient(): BowlosClient {\n const client = useContext(BowlosContext);\n if (!client) {\n throw new Error(\"useBowlosClient must be used within a <BowlosProvider>.\");\n }\n return client;\n}\n\n// ── useAccount ──────────────────────────────────────────────────────────────\n\nexport type AccountStatus = \"loading\" | AuthState;\n\nexport interface UseAccountResult {\n status: AccountStatus;\n customer: Customer | null;\n error: BowlosApiError | null;\n signIn: (email: string, password: string) => Promise<void>;\n signUp: (email: string, password: string) => Promise<void>;\n link: (profile: LinkProfile) => Promise<void>;\n signOut: () => Promise<void>;\n refresh: () => Promise<void>;\n}\n\n/** The session state machine — runs ONCE inside `<BowlosProvider>` and is shared\n * via context. Probes once on mount; each action re-probes so `status`/`customer`\n * stay current. Consumers use `useAccount()`, never this directly. */\nfunction useAccountState(client: BowlosClient): UseAccountResult {\n const [status, setStatus] = useState<AccountStatus>(\"loading\");\n const [customer, setCustomer] = useState<Customer | null>(null);\n const [error, setError] = useState<BowlosApiError | null>(null);\n\n const refresh = useCallback(async () => {\n try {\n const state = await client.probe();\n setStatus(state);\n setCustomer(state === \"linked\" ? await client.me() : null);\n setError(null);\n } catch (e) {\n setStatus(\"unauthenticated\");\n setCustomer(null);\n if (e instanceof BowlosApiError) setError(e);\n }\n }, [client]);\n\n useEffect(() => {\n void refresh();\n }, [refresh]);\n\n const run = useCallback(\n async (action: () => Promise<unknown>) => {\n setError(null);\n try {\n await action();\n await refresh();\n } catch (e) {\n if (e instanceof BowlosApiError) setError(e);\n throw e;\n }\n },\n [refresh],\n );\n\n const signIn = useCallback(\n (email: string, password: string) => run(() => client.signIn(email, password)),\n [client, run],\n );\n const signUp = useCallback(\n (email: string, password: string) => run(() => client.signUp(email, password)),\n [client, run],\n );\n const link = useCallback((profile: LinkProfile) => run(() => client.link(profile)), [client, run]);\n const signOut = useCallback(() => run(() => client.signOut()), [client, run]);\n\n return { status, customer, error, signIn, signUp, link, signOut, refresh };\n}\n\n/**\n * The customer session (state + actions), shared across the whole app. Every\n * call returns the SAME session — signing in or out anywhere updates the header,\n * the booking form, everywhere at once. Must be used within a `<BowlosProvider>`.\n */\nexport function useAccount(): UseAccountResult {\n const account = useContext(AccountContext);\n if (!account) {\n throw new Error(\"useAccount must be used within a <BowlosProvider>.\");\n }\n return account;\n}\n\n// ── useBowlosQuery ────────────────────────────────────────────────────────────\n\nexport interface UseQueryOptions {\n /** Send the customer bearer token (for session-scoped reads). */\n auth?: boolean;\n /** Skip fetching until true. Defaults to true. */\n enabled?: boolean;\n}\n\nexport interface UseQueryResult<T> {\n data: T | null;\n error: BowlosApiError | null;\n loading: boolean;\n refetch: () => Promise<void>;\n}\n\n/** Generic read hook over a gateway route. The typed data hooks\n * (`useAvailability`, etc.) will wrap this with route names + arg types. */\nexport function useBowlosQuery<T = unknown>(\n name: string,\n args: Record<string, unknown> = {},\n options: UseQueryOptions = {},\n): UseQueryResult<T> {\n const client = useBowlosClient();\n const auth = options.auth ?? false;\n const enabled = options.enabled ?? true;\n const [data, setData] = useState<T | null>(null);\n const [error, setError] = useState<BowlosApiError | null>(null);\n const [loading, setLoading] = useState<boolean>(enabled);\n // Stabilize the args object across renders so the effect doesn't loop.\n const argsKey = JSON.stringify(args);\n\n const refetch = useCallback(async () => {\n setLoading(true);\n setError(null);\n try {\n const result = await client.call<T>(name, JSON.parse(argsKey) as Record<string, unknown>, {\n auth,\n });\n setData(result);\n } catch (e) {\n if (e instanceof BowlosApiError) setError(e);\n setData(null);\n } finally {\n setLoading(false);\n }\n }, [client, name, argsKey, auth]);\n\n useEffect(() => {\n if (enabled) void refetch();\n }, [enabled, refetch]);\n\n return { data, error, loading, refetch };\n}\n","/**\n * Typed React data hooks for the booking funnel, built on `useBowlosQuery`.\n * Same arg/result types as the framework-agnostic functions in `data.ts`.\n */\nimport { useBowlosQuery, type UseQueryOptions, type UseQueryResult } from \"./react\";\nimport type {\n AvailabilityArgs,\n AvailabilityResult,\n BookingPreviewArgs,\n BookingQuote,\n PublicAddon,\n StartTimesArgs,\n PackagePreviewArgs,\n PackagePreviewResult,\n GameCardPreviewArgs,\n GameCardPreviewResult,\n} from \"./data\";\nimport type {\n BrandScoped,\n FlashBookingOptionsArgs,\n FlashSaleArgs,\n FlashSalesArgs,\n MembershipDetailArgs,\n ReservationDetailArgs,\n} from \"./account\";\nimport type { BrandCatalogArgs, CenterScoped, PackageDetailArgs, CenterHoursArgs } from \"./catalog\";\n\n/** Live free-unit availability for a product / date / time window. */\nexport function useAvailability(\n args: AvailabilityArgs,\n options?: UseQueryOptions,\n): UseQueryResult<AvailabilityResult> {\n return useBowlosQuery<AvailabilityResult>(\"checkAvailability\", args, options);\n}\n\n/** Authoritative price quote for the chosen booking inputs. */\nexport function useBookingPreview(\n args: BookingPreviewArgs,\n options?: UseQueryOptions,\n): UseQueryResult<BookingQuote> {\n return useBowlosQuery<BookingQuote>(\"bookingPreview\", args, options);\n}\n\n/** Bookable add-ons (shoe rental, upgrades…) for a product. */\nexport function useAddons(\n args: { productId: string },\n options?: UseQueryOptions,\n): UseQueryResult<PublicAddon[]> {\n return useBowlosQuery<PublicAddon[]>(\"listPublicAddons\", args, options);\n}\n\n/** Bookable start times (minute-of-day) for a product on a date. */\nexport function useStartTimes(\n args: StartTimesArgs,\n options?: UseQueryOptions,\n): UseQueryResult<number[]> {\n return useBowlosQuery<number[]>(\"availableStartTimes\", args, options);\n}\n\n// ── account (require a signed-in customer) ───────────────────────────────────\n// Results are generic (`<T = unknown>`) — parameterize with your own shape.\n\n/** The signed-in customer's reservations. */\nexport function useMyReservations<T = unknown>(\n args: BrandScoped,\n options?: UseQueryOptions,\n): UseQueryResult<T> {\n return useBowlosQuery<T>(\"listMyReservations\", args, { ...options, auth: true });\n}\n\n/** One of the customer's reservations, by displayId. */\nexport function useMyReservationDetail<T = unknown>(\n args: ReservationDetailArgs,\n options?: UseQueryOptions,\n): UseQueryResult<T> {\n return useBowlosQuery<T>(\"getMyReservationDetail\", args, { ...options, auth: true });\n}\n\n/** The customer's memberships. */\nexport function useMyMemberships<T = unknown>(\n args: BrandScoped,\n options?: UseQueryOptions,\n): UseQueryResult<T> {\n return useBowlosQuery<T>(\"listMyMemberships\", args, { ...options, auth: true });\n}\n\n/** One membership's detail. */\nexport function useMyMembershipDetail<T = unknown>(\n args: MembershipDetailArgs,\n options?: UseQueryOptions,\n): UseQueryResult<T> {\n return useBowlosQuery<T>(\"getMyMembershipDetail\", args, { ...options, auth: true });\n}\n\n/** Loyalty tier + points. */\nexport function useMyLoyalty<T = unknown>(\n args: BrandScoped,\n options?: UseQueryOptions,\n): UseQueryResult<T> {\n return useBowlosQuery<T>(\"getMyLoyalty\", args, { ...options, auth: true });\n}\n\n/** Account credit balance + ledger. */\nexport function useMyCredits<T = unknown>(\n args: BrandScoped,\n options?: UseQueryOptions,\n): UseQueryResult<T> {\n return useBowlosQuery<T>(\"listMyCredits\", args, { ...options, auth: true });\n}\n\n/** Issued wallet passes. */\nexport function useMyPasses<T = unknown>(\n args: BrandScoped,\n options?: UseQueryOptions,\n): UseQueryResult<T> {\n return useBowlosQuery<T>(\"listMyPasses\", args, { ...options, auth: true });\n}\n\n// ── flash sales (session-aware: members see prices) ──────────────────────────\n\n/** The public flash-sale page (members see prices; anonymous gets the locked view). */\nexport function useFlashSale<T = unknown>(\n args: FlashSaleArgs,\n options?: UseQueryOptions,\n): UseQueryResult<T> {\n return useBowlosQuery<T>(\"getPublicFlashSaleBySlug\", args, { ...options, auth: true });\n}\n\n/** The public flash-sale index for a Brand (live + upcoming; no prices). Public. */\nexport function useFlashSales<T = unknown>(\n args: FlashSalesArgs,\n options?: UseQueryOptions,\n): UseQueryResult<T> {\n return useBowlosQuery<T>(\"listPublicFlashSales\", args, options);\n}\n\n/** Per-start-hour options for a flash-sale reservation item (members only). */\nexport function useFlashSaleBookingOptions<T = unknown>(\n args: FlashBookingOptionsArgs,\n options?: UseQueryOptions,\n): UseQueryResult<T> {\n return useBowlosQuery<T>(\"getFlashSaleBookingOptions\", args, { ...options, auth: true });\n}\n\n// ── public catalog (anonymous; power `<BookingCatalog>`) ──────────────────────\n\n/** Bookable products at a Center (each carries `attractionTypeKey`). */\nexport function useProducts<T = unknown>(\n args: CenterScoped,\n options?: UseQueryOptions,\n): UseQueryResult<T> {\n return useBowlosQuery<T>(\"listPublicProducts\", args, options);\n}\n\n/** Upcoming pricing events at a Center. */\nexport function useEvents<T = unknown>(\n args: CenterScoped,\n options?: UseQueryOptions,\n): UseQueryResult<T> {\n return useBowlosQuery<T>(\"listPublicEvents\", args, options);\n}\n\n/** Purchasable packages at a Brand. */\nexport function usePackages<T = unknown>(\n args: BrandCatalogArgs,\n options?: UseQueryOptions,\n): UseQueryResult<T> {\n return useBowlosQuery<T>(\"listPublicPackages\", args, options);\n}\n\n/** Full detail for one package (components, add-ons, allowed start times, …) —\n * drives the headless package config UI before `usePackagePurchase`. */\nexport function usePackage<T = unknown>(\n args: PackageDetailArgs,\n options?: UseQueryOptions,\n): UseQueryResult<T> {\n return useBowlosQuery<T>(\"getPublicPackage\", args, options);\n}\n\n/** A Center's open/close window for the given attraction types on a date — use\n * the package's component attraction-type keys to bound its bookable slots. */\nexport function useCenterHours<T = unknown>(\n args: CenterHoursArgs,\n options?: UseQueryOptions,\n): UseQueryResult<T> {\n return useBowlosQuery<T>(\"getCenterOperatingHoursForTypes\", args, options);\n}\n\n/** Itemized quote for a package order — base, add-ons, tax lines, the selling\n * Center's booking fee, and the authoritative grand total. Drives the headless\n * **Review** step. Requires a signed-in customer (tax exemptions are applied),\n * and is computed by the same engine as the PaymentIntent, so it never diverges\n * from what the customer is charged. */\nexport function usePackagePreview<T = PackagePreviewResult>(\n args: PackagePreviewArgs,\n options?: UseQueryOptions,\n): UseQueryResult<T> {\n return useBowlosQuery<T>(\"previewPackageOrder\", args, { ...options, auth: true });\n}\n\n/** Purchasable memberships at a Center. */\nexport function usePublicMemberships<T = unknown>(\n args: CenterScoped,\n options?: UseQueryOptions,\n): UseQueryResult<T> {\n return useBowlosQuery<T>(\"listPublicMemberships\", args, options);\n}\n\n/** Purchasable game cards / passes at a Brand. */\nexport function useGameCards<T = unknown>(\n args: BrandCatalogArgs,\n options?: UseQueryOptions,\n): UseQueryResult<T> {\n return useBowlosQuery<T>(\"listPublicGameCards\", args, options);\n}\n\n/** Itemized quote for a game-pass purchase — the base price, tax lines, the\n * selling Center's booking fee, and the authoritative grand total. Drives the\n * headless **Review** step. Requires a signed-in customer (tax exemptions are\n * applied + the home Center is resolved server-side), and is computed by the\n * same engine as the PaymentIntent, so it never diverges from what the\n * customer is charged. */\nexport function useGameCardPreview<T = GameCardPreviewResult>(\n args: GameCardPreviewArgs,\n options?: UseQueryOptions,\n): UseQueryResult<T> {\n return useBowlosQuery<T>(\"previewGameCardOrder\", args, { ...options, auth: true });\n}\n","/**\n * useBookingFlow — the hold → pay → confirm state machine.\n *\n * Orchestrates the booking funnel and HANDS the Stripe (Connect) payment data\n * to the UI layer; it does NOT load Stripe.js. After `preparePayment()`, render\n * Stripe Elements from `paymentIntent` (initialize Stripe with\n * `connectedAccountId` + `clientSecret`), let the customer pay, then\n * `startPolling()` until the webhook materializes the booking\n * (`status: \"confirmed\"`).\n *\n * Flow:\n * startHold(args) → \"held\" (requiresPayment) | \"confirmed\" (credit covered)\n * preparePayment() → \"awaitingPayment\" (+ paymentIntent)\n * [consumer renders Stripe Elements + the customer pays]\n * startPolling() → \"confirmed\" | \"expired\" | \"failed\" | \"abandoned\"\n */\nimport { useCallback, useEffect, useRef, useState } from \"react\";\nimport { useBowlosClient } from \"./react\";\nimport { BowlosApiError, BOWLOS_ERROR_CODES } from \"./errors\";\nimport {\n abandonCheckout as abandonCheckoutCall,\n createBooking as createBookingCall,\n createCheckoutPaymentIntent as createPaymentIntentCall,\n getCheckoutStatus as getCheckoutStatusCall,\n type BookingHold,\n type CheckoutStatusResult,\n type CreateBookingArgs,\n type PaymentIntentInfo,\n} from \"./data\";\n\nexport type BookingFlowStatus =\n | \"idle\"\n | \"holding\"\n | \"held\"\n | \"preparingPayment\"\n | \"awaitingPayment\"\n | \"confirmed\"\n | \"expired\"\n | \"failed\"\n | \"abandoned\"\n | \"error\";\n\nexport interface BookingReservationRef {\n reservationId: string | null;\n reservationDisplayId: string | null;\n}\n\nexport interface UseBookingFlowResult {\n status: BookingFlowStatus;\n hold: BookingHold | null;\n refToken: string | null;\n paymentIntent: PaymentIntentInfo | null;\n reservation: BookingReservationRef | null;\n requiresPayment: boolean | null;\n error: BowlosApiError | null;\n startHold: (args: CreateBookingArgs) => Promise<void>;\n preparePayment: () => Promise<PaymentIntentInfo | null>;\n pollStatus: () => Promise<CheckoutStatusResult | null>;\n startPolling: (intervalMs?: number) => void;\n stopPolling: () => void;\n abandon: () => Promise<void>;\n reset: () => void;\n}\n\nconst DEFAULT_POLL_MS = 2500;\n\nexport function useBookingFlow(): UseBookingFlowResult {\n const client = useBowlosClient();\n const [status, setStatus] = useState<BookingFlowStatus>(\"idle\");\n const [hold, setHold] = useState<BookingHold | null>(null);\n const [refToken, setRefToken] = useState<string | null>(null);\n const [paymentIntent, setPaymentIntent] = useState<PaymentIntentInfo | null>(null);\n const [reservation, setReservation] = useState<BookingReservationRef | null>(null);\n const [error, setError] = useState<BowlosApiError | null>(null);\n\n // Mirror of refToken for the polling interval (avoids a stale closure).\n const refTokenRef = useRef<string | null>(null);\n const pollRef = useRef<ReturnType<typeof setInterval> | null>(null);\n\n const stopPolling = useCallback(() => {\n if (pollRef.current !== null) {\n clearInterval(pollRef.current);\n pollRef.current = null;\n }\n }, []);\n\n useEffect(() => stopPolling, [stopPolling]); // clear the interval on unmount\n\n const reset = useCallback(() => {\n stopPolling();\n refTokenRef.current = null;\n setRefToken(null);\n setHold(null);\n setPaymentIntent(null);\n setReservation(null);\n setError(null);\n setStatus(\"idle\");\n }, [stopPolling]);\n\n const applyStatus = useCallback(\n (s: CheckoutStatusResult) => {\n switch (s.status) {\n case \"paid_materialized\":\n setReservation({\n reservationId: s.reservationId,\n reservationDisplayId: s.reservationDisplayId,\n });\n setStatus(\"confirmed\");\n stopPolling();\n break;\n case \"expired\":\n setStatus(\"expired\");\n stopPolling();\n break;\n case \"abandoned\":\n setStatus(\"abandoned\");\n stopPolling();\n break;\n case \"payment_failed_retryable\":\n setStatus(\"failed\");\n stopPolling();\n break;\n case \"not_found\":\n setError(new BowlosApiError(BOWLOS_ERROR_CODES.NOT_FOUND, \"Checkout not found.\", 404));\n setStatus(\"error\");\n stopPolling();\n break;\n case \"pending_payment\":\n default:\n break; // keep waiting\n }\n },\n [stopPolling],\n );\n\n const startHold = useCallback(\n async (args: CreateBookingArgs) => {\n stopPolling();\n setError(null);\n setPaymentIntent(null);\n setReservation(null);\n setStatus(\"holding\");\n try {\n const h = await createBookingCall(client, args);\n setHold(h);\n const rt = typeof h.checkoutRefToken === \"string\" ? h.checkoutRefToken : null;\n refTokenRef.current = rt;\n setRefToken(rt);\n if (!h.requiresPayment) {\n setReservation({\n reservationId: h.reservationId ?? null,\n reservationDisplayId: h.reservationDisplayId ?? null,\n });\n setStatus(\"confirmed\");\n } else if (rt) {\n setStatus(\"held\");\n } else {\n setError(\n new BowlosApiError(\n \"UNSUPPORTED_BOOKING_PATH\",\n \"This booking requires payment but no checkout hold was returned.\",\n 0,\n ),\n );\n setStatus(\"error\");\n }\n } catch (e) {\n if (e instanceof BowlosApiError) setError(e);\n setStatus(\"error\");\n }\n },\n [client, stopPolling],\n );\n\n const preparePayment = useCallback(async (): Promise<PaymentIntentInfo | null> => {\n const rt = refTokenRef.current;\n if (!rt) return null;\n setError(null);\n setStatus(\"preparingPayment\");\n try {\n const pi = await createPaymentIntentCall(client, rt);\n setPaymentIntent(pi);\n setStatus(\"awaitingPayment\");\n return pi;\n } catch (e) {\n if (e instanceof BowlosApiError) setError(e);\n setStatus(\"error\");\n return null;\n }\n }, [client]);\n\n const pollStatus = useCallback(async (): Promise<CheckoutStatusResult | null> => {\n const rt = refTokenRef.current;\n if (!rt) return null;\n try {\n const s = await getCheckoutStatusCall(client, rt);\n applyStatus(s);\n return s;\n } catch (e) {\n if (e instanceof BowlosApiError) setError(e);\n return null;\n }\n }, [client, applyStatus]);\n\n const startPolling = useCallback(\n (intervalMs: number = DEFAULT_POLL_MS) => {\n stopPolling();\n void pollStatus();\n pollRef.current = setInterval(() => {\n void pollStatus();\n }, intervalMs);\n },\n [pollStatus, stopPolling],\n );\n\n const abandon = useCallback(async () => {\n stopPolling();\n const rt = refTokenRef.current;\n if (rt) {\n try {\n await abandonCheckoutCall(client, rt);\n } catch {\n // best-effort: the hold also frees itself on its TTL\n }\n }\n setStatus(\"abandoned\");\n }, [client, stopPolling]);\n\n return {\n status,\n hold,\n refToken,\n paymentIntent,\n reservation,\n requiresPayment: hold ? hold.requiresPayment : null,\n error,\n startHold,\n preparePayment,\n pollStatus,\n startPolling,\n stopPolling,\n abandon,\n reset,\n };\n}\n"]}
|