@bowlos/reservations 0.1.0 → 0.3.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/README.md +63 -0
- package/dist/account-COEgvwfx.d.cts +43 -0
- package/dist/account-CzyIERC5.d.ts +43 -0
- package/dist/chunk-4VDDL2CN.js +299 -0
- package/dist/chunk-4VDDL2CN.js.map +1 -0
- package/dist/components.cjs +1120 -0
- package/dist/components.cjs.map +1 -0
- package/dist/components.d.cts +353 -0
- package/dist/components.d.ts +353 -0
- package/dist/components.js +765 -0
- package/dist/components.js.map +1 -0
- package/dist/{account-Cl6hElpL.d.cts → data-DrM0D6Pi.d.cts} +1 -41
- package/dist/{account-Cl6hElpL.d.ts → data-DrM0D6Pi.d.ts} +1 -41
- package/dist/index.d.cts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/react-B_8H7AyT.d.cts +43 -0
- package/dist/react-bG9YV_xP.d.ts +43 -0
- package/dist/react.d.cts +7 -42
- package/dist/react.d.ts +7 -42
- package/dist/react.js +3 -297
- package/dist/react.js.map +1 -1
- package/package.json +11 -1
package/README.md
CHANGED
|
@@ -108,6 +108,69 @@ Every read also has a framework-agnostic function in the core entry
|
|
|
108
108
|
(`checkAvailability`, `bookingPreview`, `getMyReservations`, `runDoctor`, …) for
|
|
109
109
|
non-React or server use.
|
|
110
110
|
|
|
111
|
+
## Drop-in components (`@bowlos/reservations/components`)
|
|
112
|
+
|
|
113
|
+
Don't want to build the UI from hooks? A **themeable, white-label** component
|
|
114
|
+
layer sits on top of them:
|
|
115
|
+
|
|
116
|
+
```tsx
|
|
117
|
+
import { BowlosProvider } from "@bowlos/reservations/react";
|
|
118
|
+
import { BookingFlow, BowlosTheme } from "@bowlos/reservations/components";
|
|
119
|
+
|
|
120
|
+
<BowlosProvider client={bowlos}>
|
|
121
|
+
<BowlosTheme theme={{ colorPrimary: "#e4002b", radius: "8px" }}>
|
|
122
|
+
<BookingFlow
|
|
123
|
+
centerId="center_…"
|
|
124
|
+
productId="product_…"
|
|
125
|
+
unitLabel={{ singular: "lane", plural: "lanes" }}
|
|
126
|
+
renderPayment={({ paymentIntent, onPaid, onError }) => (
|
|
127
|
+
<YourStripeForm paymentIntent={paymentIntent} onPaid={onPaid} onError={onError} />
|
|
128
|
+
)}
|
|
129
|
+
onConfirmed={(r) => console.log("booked", r.reservationDisplayId)}
|
|
130
|
+
/>
|
|
131
|
+
</BowlosTheme>
|
|
132
|
+
</BowlosProvider>;
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Three drop-in surfaces cover a center site end to end:
|
|
136
|
+
|
|
137
|
+
**`<BookingFlow>`** runs the whole funnel (availability + price → reserve → pay →
|
|
138
|
+
confirm). It **hands you the Stripe Connect PaymentIntent** via `renderPayment`
|
|
139
|
+
— the SDK never loads Stripe.js, so you render Elements yourself
|
|
140
|
+
(`loadStripe(pk, { stripeAccount: paymentIntent.connectedAccountId })` →
|
|
141
|
+
`confirmPayment` → call `onPaid()`).
|
|
142
|
+
|
|
143
|
+
**`<AccountDashboard brandId>`** is a complete account page: it signs the
|
|
144
|
+
customer in (via the built-in `<AuthGate>`), then shows their reservations,
|
|
145
|
+
memberships, loyalty, account credit, and passes. Pick a subset with
|
|
146
|
+
`sections={["reservations", "credits"]}`.
|
|
147
|
+
|
|
148
|
+
```tsx
|
|
149
|
+
import { AccountDashboard } from "@bowlos/reservations/components";
|
|
150
|
+
|
|
151
|
+
<AccountDashboard brandId="brand_…" />;
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
**`<FlashSale slug>`** is the branded, login-gated flash-sale page. Anonymous
|
|
155
|
+
visitors see the brand, a live countdown, the operator's pre-login message, and
|
|
156
|
+
item names with prices **locked** behind a sign-in form — sale prices are
|
|
157
|
+
member-only and **never cross the wire** until a customer of the Brand signs in.
|
|
158
|
+
Once signed in, prices unlock (shown as a per-date range) and each item gets a
|
|
159
|
+
Book button you hand off via `onBook`:
|
|
160
|
+
|
|
161
|
+
```tsx
|
|
162
|
+
import { FlashSale } from "@bowlos/reservations/components";
|
|
163
|
+
|
|
164
|
+
<FlashSale slug="tuesday-blowout" onBook={(item) => router.push(`/book?flashItem=${item.id}`)} />;
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
`<AuthGate>` (sign in / create account / finish profile) is also exported on its
|
|
168
|
+
own if you want to gate your own content behind a customer session.
|
|
169
|
+
|
|
170
|
+
**Theming:** neutral defaults with **no BowlOS branding** (these are *your*
|
|
171
|
+
center's pages). Restyle via `<BowlosTheme>` or by setting the `--bowlos-*` CSS
|
|
172
|
+
variables yourself (`--bowlos-color-primary`, `--bowlos-radius`, `--bowlos-font`, …).
|
|
173
|
+
|
|
111
174
|
## Errors
|
|
112
175
|
|
|
113
176
|
Failed calls throw a typed `BowlosApiError` with a stable `.code` — branch on
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { j as BowlosClient } from './data-DrM0D6Pi.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Typed account + flash reads for @bowlos/reservations.
|
|
5
|
+
*
|
|
6
|
+
* Session-scoped account reads (require a signed-in customer) and the
|
|
7
|
+
* session-aware flash-sale reads. Args are typed precisely — every account read
|
|
8
|
+
* is brand-scoped. Results are generic (`<T = unknown>`): parameterize with your
|
|
9
|
+
* own shape, or read `unknown` and narrow. (The backend return shapes are rich
|
|
10
|
+
* and evolving; the SDK doesn't pin them here.) Each read has a framework-agnostic
|
|
11
|
+
* function here and a React hook in `hooks.tsx`.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/** Every account read is scoped to the customer's Brand. */
|
|
15
|
+
type BrandScoped = {
|
|
16
|
+
brandId: string;
|
|
17
|
+
};
|
|
18
|
+
type ReservationDetailArgs = {
|
|
19
|
+
brandId: string;
|
|
20
|
+
displayId: string;
|
|
21
|
+
};
|
|
22
|
+
type MembershipDetailArgs = {
|
|
23
|
+
brandId: string;
|
|
24
|
+
membershipId: string;
|
|
25
|
+
};
|
|
26
|
+
type FlashSaleArgs = {
|
|
27
|
+
slug: string;
|
|
28
|
+
};
|
|
29
|
+
type FlashBookingOptionsArgs = {
|
|
30
|
+
slug: string;
|
|
31
|
+
itemId: string;
|
|
32
|
+
};
|
|
33
|
+
declare function getMyReservations<T = unknown>(client: BowlosClient, args: BrandScoped): Promise<T>;
|
|
34
|
+
declare function getMyReservationDetail<T = unknown>(client: BowlosClient, args: ReservationDetailArgs): Promise<T>;
|
|
35
|
+
declare function getMyMemberships<T = unknown>(client: BowlosClient, args: BrandScoped): Promise<T>;
|
|
36
|
+
declare function getMyMembershipDetail<T = unknown>(client: BowlosClient, args: MembershipDetailArgs): Promise<T>;
|
|
37
|
+
declare function getMyLoyalty<T = unknown>(client: BowlosClient, args: BrandScoped): Promise<T>;
|
|
38
|
+
declare function getMyCredits<T = unknown>(client: BowlosClient, args: BrandScoped): Promise<T>;
|
|
39
|
+
declare function getMyPasses<T = unknown>(client: BowlosClient, args: BrandScoped): Promise<T>;
|
|
40
|
+
declare function getFlashSale<T = unknown>(client: BowlosClient, args: FlashSaleArgs): Promise<T>;
|
|
41
|
+
declare function getFlashSaleBookingOptions<T = unknown>(client: BowlosClient, args: FlashBookingOptionsArgs): Promise<T>;
|
|
42
|
+
|
|
43
|
+
export { type BrandScoped as B, type FlashBookingOptionsArgs as F, type MembershipDetailArgs as M, type ReservationDetailArgs as R, type FlashSaleArgs as a, getFlashSaleBookingOptions as b, getMyCredits as c, getMyLoyalty as d, getMyMembershipDetail as e, getMyMemberships as f, getFlashSale as g, getMyPasses as h, getMyReservationDetail as i, getMyReservations as j };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { j as BowlosClient } from './data-DrM0D6Pi.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Typed account + flash reads for @bowlos/reservations.
|
|
5
|
+
*
|
|
6
|
+
* Session-scoped account reads (require a signed-in customer) and the
|
|
7
|
+
* session-aware flash-sale reads. Args are typed precisely — every account read
|
|
8
|
+
* is brand-scoped. Results are generic (`<T = unknown>`): parameterize with your
|
|
9
|
+
* own shape, or read `unknown` and narrow. (The backend return shapes are rich
|
|
10
|
+
* and evolving; the SDK doesn't pin them here.) Each read has a framework-agnostic
|
|
11
|
+
* function here and a React hook in `hooks.tsx`.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/** Every account read is scoped to the customer's Brand. */
|
|
15
|
+
type BrandScoped = {
|
|
16
|
+
brandId: string;
|
|
17
|
+
};
|
|
18
|
+
type ReservationDetailArgs = {
|
|
19
|
+
brandId: string;
|
|
20
|
+
displayId: string;
|
|
21
|
+
};
|
|
22
|
+
type MembershipDetailArgs = {
|
|
23
|
+
brandId: string;
|
|
24
|
+
membershipId: string;
|
|
25
|
+
};
|
|
26
|
+
type FlashSaleArgs = {
|
|
27
|
+
slug: string;
|
|
28
|
+
};
|
|
29
|
+
type FlashBookingOptionsArgs = {
|
|
30
|
+
slug: string;
|
|
31
|
+
itemId: string;
|
|
32
|
+
};
|
|
33
|
+
declare function getMyReservations<T = unknown>(client: BowlosClient, args: BrandScoped): Promise<T>;
|
|
34
|
+
declare function getMyReservationDetail<T = unknown>(client: BowlosClient, args: ReservationDetailArgs): Promise<T>;
|
|
35
|
+
declare function getMyMemberships<T = unknown>(client: BowlosClient, args: BrandScoped): Promise<T>;
|
|
36
|
+
declare function getMyMembershipDetail<T = unknown>(client: BowlosClient, args: MembershipDetailArgs): Promise<T>;
|
|
37
|
+
declare function getMyLoyalty<T = unknown>(client: BowlosClient, args: BrandScoped): Promise<T>;
|
|
38
|
+
declare function getMyCredits<T = unknown>(client: BowlosClient, args: BrandScoped): Promise<T>;
|
|
39
|
+
declare function getMyPasses<T = unknown>(client: BowlosClient, args: BrandScoped): Promise<T>;
|
|
40
|
+
declare function getFlashSale<T = unknown>(client: BowlosClient, args: FlashSaleArgs): Promise<T>;
|
|
41
|
+
declare function getFlashSaleBookingOptions<T = unknown>(client: BowlosClient, args: FlashBookingOptionsArgs): Promise<T>;
|
|
42
|
+
|
|
43
|
+
export { type BrandScoped as B, type FlashBookingOptionsArgs as F, type MembershipDetailArgs as M, type ReservationDetailArgs as R, type FlashSaleArgs as a, getFlashSaleBookingOptions as b, getMyCredits as c, getMyLoyalty as d, getMyMembershipDetail as e, getMyMemberships as f, getFlashSale as g, getMyPasses as h, getMyReservationDetail as i, getMyReservations as j };
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
import { createBooking, createCheckoutPaymentIntent, getCheckoutStatus, abandonCheckout } from './chunk-TZTFJVDI.js';
|
|
2
|
+
import { createBowlosClient, BowlosApiError, BOWLOS_ERROR_CODES } from './chunk-TCYTNCUL.js';
|
|
3
|
+
import { createContext, useRef, useContext, useState, useCallback, useEffect } from 'react';
|
|
4
|
+
import { jsx } from 'react/jsx-runtime';
|
|
5
|
+
|
|
6
|
+
var BowlosContext = createContext(null);
|
|
7
|
+
function BowlosProvider({ client, config, children }) {
|
|
8
|
+
const ref = useRef(client ?? null);
|
|
9
|
+
if (!ref.current) {
|
|
10
|
+
if (!config) {
|
|
11
|
+
throw new Error("BowlosProvider requires either a `client` or a `config`.");
|
|
12
|
+
}
|
|
13
|
+
ref.current = createBowlosClient(config);
|
|
14
|
+
}
|
|
15
|
+
return /* @__PURE__ */ jsx(BowlosContext.Provider, { value: ref.current, children });
|
|
16
|
+
}
|
|
17
|
+
function useBowlosClient() {
|
|
18
|
+
const client = useContext(BowlosContext);
|
|
19
|
+
if (!client) {
|
|
20
|
+
throw new Error("useBowlosClient must be used within a <BowlosProvider>.");
|
|
21
|
+
}
|
|
22
|
+
return client;
|
|
23
|
+
}
|
|
24
|
+
function useAccount() {
|
|
25
|
+
const client = useBowlosClient();
|
|
26
|
+
const [status, setStatus] = useState("loading");
|
|
27
|
+
const [customer, setCustomer] = useState(null);
|
|
28
|
+
const [error, setError] = useState(null);
|
|
29
|
+
const refresh = useCallback(async () => {
|
|
30
|
+
try {
|
|
31
|
+
const state = await client.probe();
|
|
32
|
+
setStatus(state);
|
|
33
|
+
setCustomer(state === "linked" ? await client.me() : null);
|
|
34
|
+
setError(null);
|
|
35
|
+
} catch (e) {
|
|
36
|
+
setStatus("unauthenticated");
|
|
37
|
+
setCustomer(null);
|
|
38
|
+
if (e instanceof BowlosApiError) setError(e);
|
|
39
|
+
}
|
|
40
|
+
}, [client]);
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
void refresh();
|
|
43
|
+
}, [refresh]);
|
|
44
|
+
const run = useCallback(
|
|
45
|
+
async (action) => {
|
|
46
|
+
setError(null);
|
|
47
|
+
try {
|
|
48
|
+
await action();
|
|
49
|
+
await refresh();
|
|
50
|
+
} catch (e) {
|
|
51
|
+
if (e instanceof BowlosApiError) setError(e);
|
|
52
|
+
throw e;
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
[refresh]
|
|
56
|
+
);
|
|
57
|
+
const signIn = useCallback(
|
|
58
|
+
(email, password) => run(() => client.signIn(email, password)),
|
|
59
|
+
[client, run]
|
|
60
|
+
);
|
|
61
|
+
const signUp = useCallback(
|
|
62
|
+
(email, password) => run(() => client.signUp(email, password)),
|
|
63
|
+
[client, run]
|
|
64
|
+
);
|
|
65
|
+
const link = useCallback((profile) => run(() => client.link(profile)), [client, run]);
|
|
66
|
+
const signOut = useCallback(() => run(() => client.signOut()), [client, run]);
|
|
67
|
+
return { status, customer, error, signIn, signUp, link, signOut, refresh };
|
|
68
|
+
}
|
|
69
|
+
function useBowlosQuery(name, args = {}, options = {}) {
|
|
70
|
+
const client = useBowlosClient();
|
|
71
|
+
const auth = options.auth ?? false;
|
|
72
|
+
const enabled = options.enabled ?? true;
|
|
73
|
+
const [data, setData] = useState(null);
|
|
74
|
+
const [error, setError] = useState(null);
|
|
75
|
+
const [loading, setLoading] = useState(enabled);
|
|
76
|
+
const argsKey = JSON.stringify(args);
|
|
77
|
+
const refetch = useCallback(async () => {
|
|
78
|
+
setLoading(true);
|
|
79
|
+
setError(null);
|
|
80
|
+
try {
|
|
81
|
+
const result = await client.call(name, JSON.parse(argsKey), {
|
|
82
|
+
auth
|
|
83
|
+
});
|
|
84
|
+
setData(result);
|
|
85
|
+
} catch (e) {
|
|
86
|
+
if (e instanceof BowlosApiError) setError(e);
|
|
87
|
+
setData(null);
|
|
88
|
+
} finally {
|
|
89
|
+
setLoading(false);
|
|
90
|
+
}
|
|
91
|
+
}, [client, name, argsKey, auth]);
|
|
92
|
+
useEffect(() => {
|
|
93
|
+
if (enabled) void refetch();
|
|
94
|
+
}, [enabled, refetch]);
|
|
95
|
+
return { data, error, loading, refetch };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// src/hooks.tsx
|
|
99
|
+
function useAvailability(args, options) {
|
|
100
|
+
return useBowlosQuery("checkAvailability", args, options);
|
|
101
|
+
}
|
|
102
|
+
function useBookingPreview(args, options) {
|
|
103
|
+
return useBowlosQuery("bookingPreview", args, options);
|
|
104
|
+
}
|
|
105
|
+
function useMyReservations(args, options) {
|
|
106
|
+
return useBowlosQuery("listMyReservations", args, { ...options, auth: true });
|
|
107
|
+
}
|
|
108
|
+
function useMyReservationDetail(args, options) {
|
|
109
|
+
return useBowlosQuery("getMyReservationDetail", args, { ...options, auth: true });
|
|
110
|
+
}
|
|
111
|
+
function useMyMemberships(args, options) {
|
|
112
|
+
return useBowlosQuery("listMyMemberships", args, { ...options, auth: true });
|
|
113
|
+
}
|
|
114
|
+
function useMyMembershipDetail(args, options) {
|
|
115
|
+
return useBowlosQuery("getMyMembershipDetail", args, { ...options, auth: true });
|
|
116
|
+
}
|
|
117
|
+
function useMyLoyalty(args, options) {
|
|
118
|
+
return useBowlosQuery("getMyLoyalty", args, { ...options, auth: true });
|
|
119
|
+
}
|
|
120
|
+
function useMyCredits(args, options) {
|
|
121
|
+
return useBowlosQuery("listMyCredits", args, { ...options, auth: true });
|
|
122
|
+
}
|
|
123
|
+
function useMyPasses(args, options) {
|
|
124
|
+
return useBowlosQuery("listMyPasses", args, { ...options, auth: true });
|
|
125
|
+
}
|
|
126
|
+
function useFlashSale(args, options) {
|
|
127
|
+
return useBowlosQuery("getPublicFlashSaleBySlug", args, { ...options, auth: true });
|
|
128
|
+
}
|
|
129
|
+
function useFlashSaleBookingOptions(args, options) {
|
|
130
|
+
return useBowlosQuery("getFlashSaleBookingOptions", args, { ...options, auth: true });
|
|
131
|
+
}
|
|
132
|
+
var DEFAULT_POLL_MS = 2500;
|
|
133
|
+
function useBookingFlow() {
|
|
134
|
+
const client = useBowlosClient();
|
|
135
|
+
const [status, setStatus] = useState("idle");
|
|
136
|
+
const [hold, setHold] = useState(null);
|
|
137
|
+
const [refToken, setRefToken] = useState(null);
|
|
138
|
+
const [paymentIntent, setPaymentIntent] = useState(null);
|
|
139
|
+
const [reservation, setReservation] = useState(null);
|
|
140
|
+
const [error, setError] = useState(null);
|
|
141
|
+
const refTokenRef = useRef(null);
|
|
142
|
+
const pollRef = useRef(null);
|
|
143
|
+
const stopPolling = useCallback(() => {
|
|
144
|
+
if (pollRef.current !== null) {
|
|
145
|
+
clearInterval(pollRef.current);
|
|
146
|
+
pollRef.current = null;
|
|
147
|
+
}
|
|
148
|
+
}, []);
|
|
149
|
+
useEffect(() => stopPolling, [stopPolling]);
|
|
150
|
+
const reset = useCallback(() => {
|
|
151
|
+
stopPolling();
|
|
152
|
+
refTokenRef.current = null;
|
|
153
|
+
setRefToken(null);
|
|
154
|
+
setHold(null);
|
|
155
|
+
setPaymentIntent(null);
|
|
156
|
+
setReservation(null);
|
|
157
|
+
setError(null);
|
|
158
|
+
setStatus("idle");
|
|
159
|
+
}, [stopPolling]);
|
|
160
|
+
const applyStatus = useCallback(
|
|
161
|
+
(s) => {
|
|
162
|
+
switch (s.status) {
|
|
163
|
+
case "paid_materialized":
|
|
164
|
+
setReservation({
|
|
165
|
+
reservationId: s.reservationId,
|
|
166
|
+
reservationDisplayId: s.reservationDisplayId
|
|
167
|
+
});
|
|
168
|
+
setStatus("confirmed");
|
|
169
|
+
stopPolling();
|
|
170
|
+
break;
|
|
171
|
+
case "expired":
|
|
172
|
+
setStatus("expired");
|
|
173
|
+
stopPolling();
|
|
174
|
+
break;
|
|
175
|
+
case "abandoned":
|
|
176
|
+
setStatus("abandoned");
|
|
177
|
+
stopPolling();
|
|
178
|
+
break;
|
|
179
|
+
case "payment_failed_retryable":
|
|
180
|
+
setStatus("failed");
|
|
181
|
+
stopPolling();
|
|
182
|
+
break;
|
|
183
|
+
case "not_found":
|
|
184
|
+
setError(new BowlosApiError(BOWLOS_ERROR_CODES.NOT_FOUND, "Checkout not found.", 404));
|
|
185
|
+
setStatus("error");
|
|
186
|
+
stopPolling();
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
},
|
|
190
|
+
[stopPolling]
|
|
191
|
+
);
|
|
192
|
+
const startHold = useCallback(
|
|
193
|
+
async (args) => {
|
|
194
|
+
stopPolling();
|
|
195
|
+
setError(null);
|
|
196
|
+
setPaymentIntent(null);
|
|
197
|
+
setReservation(null);
|
|
198
|
+
setStatus("holding");
|
|
199
|
+
try {
|
|
200
|
+
const h = await createBooking(client, args);
|
|
201
|
+
setHold(h);
|
|
202
|
+
const rt = typeof h.checkoutRefToken === "string" ? h.checkoutRefToken : null;
|
|
203
|
+
refTokenRef.current = rt;
|
|
204
|
+
setRefToken(rt);
|
|
205
|
+
if (!h.requiresPayment) {
|
|
206
|
+
setReservation({
|
|
207
|
+
reservationId: h.reservationId ?? null,
|
|
208
|
+
reservationDisplayId: h.reservationDisplayId ?? null
|
|
209
|
+
});
|
|
210
|
+
setStatus("confirmed");
|
|
211
|
+
} else if (rt) {
|
|
212
|
+
setStatus("held");
|
|
213
|
+
} else {
|
|
214
|
+
setError(
|
|
215
|
+
new BowlosApiError(
|
|
216
|
+
"UNSUPPORTED_BOOKING_PATH",
|
|
217
|
+
"This booking requires payment but no checkout hold was returned.",
|
|
218
|
+
0
|
|
219
|
+
)
|
|
220
|
+
);
|
|
221
|
+
setStatus("error");
|
|
222
|
+
}
|
|
223
|
+
} catch (e) {
|
|
224
|
+
if (e instanceof BowlosApiError) setError(e);
|
|
225
|
+
setStatus("error");
|
|
226
|
+
}
|
|
227
|
+
},
|
|
228
|
+
[client, stopPolling]
|
|
229
|
+
);
|
|
230
|
+
const preparePayment = useCallback(async () => {
|
|
231
|
+
const rt = refTokenRef.current;
|
|
232
|
+
if (!rt) return null;
|
|
233
|
+
setError(null);
|
|
234
|
+
setStatus("preparingPayment");
|
|
235
|
+
try {
|
|
236
|
+
const pi = await createCheckoutPaymentIntent(client, rt);
|
|
237
|
+
setPaymentIntent(pi);
|
|
238
|
+
setStatus("awaitingPayment");
|
|
239
|
+
return pi;
|
|
240
|
+
} catch (e) {
|
|
241
|
+
if (e instanceof BowlosApiError) setError(e);
|
|
242
|
+
setStatus("error");
|
|
243
|
+
return null;
|
|
244
|
+
}
|
|
245
|
+
}, [client]);
|
|
246
|
+
const pollStatus = useCallback(async () => {
|
|
247
|
+
const rt = refTokenRef.current;
|
|
248
|
+
if (!rt) return null;
|
|
249
|
+
try {
|
|
250
|
+
const s = await getCheckoutStatus(client, rt);
|
|
251
|
+
applyStatus(s);
|
|
252
|
+
return s;
|
|
253
|
+
} catch (e) {
|
|
254
|
+
if (e instanceof BowlosApiError) setError(e);
|
|
255
|
+
return null;
|
|
256
|
+
}
|
|
257
|
+
}, [client, applyStatus]);
|
|
258
|
+
const startPolling = useCallback(
|
|
259
|
+
(intervalMs = DEFAULT_POLL_MS) => {
|
|
260
|
+
stopPolling();
|
|
261
|
+
void pollStatus();
|
|
262
|
+
pollRef.current = setInterval(() => {
|
|
263
|
+
void pollStatus();
|
|
264
|
+
}, intervalMs);
|
|
265
|
+
},
|
|
266
|
+
[pollStatus, stopPolling]
|
|
267
|
+
);
|
|
268
|
+
const abandon = useCallback(async () => {
|
|
269
|
+
stopPolling();
|
|
270
|
+
const rt = refTokenRef.current;
|
|
271
|
+
if (rt) {
|
|
272
|
+
try {
|
|
273
|
+
await abandonCheckout(client, rt);
|
|
274
|
+
} catch {
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
setStatus("abandoned");
|
|
278
|
+
}, [client, stopPolling]);
|
|
279
|
+
return {
|
|
280
|
+
status,
|
|
281
|
+
hold,
|
|
282
|
+
refToken,
|
|
283
|
+
paymentIntent,
|
|
284
|
+
reservation,
|
|
285
|
+
requiresPayment: hold ? hold.requiresPayment : null,
|
|
286
|
+
error,
|
|
287
|
+
startHold,
|
|
288
|
+
preparePayment,
|
|
289
|
+
pollStatus,
|
|
290
|
+
startPolling,
|
|
291
|
+
stopPolling,
|
|
292
|
+
abandon,
|
|
293
|
+
reset
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
export { BowlosProvider, useAccount, useAvailability, useBookingFlow, useBookingPreview, useBowlosClient, useBowlosQuery, useFlashSale, useFlashSaleBookingOptions, useMyCredits, useMyLoyalty, useMyMembershipDetail, useMyMemberships, useMyPasses, useMyReservationDetail, useMyReservations };
|
|
298
|
+
//# sourceMappingURL=chunk-4VDDL2CN.js.map
|
|
299
|
+
//# sourceMappingURL=chunk-4VDDL2CN.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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;AAStD,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,2BAAQ,aAAA,CAAc,QAAA,EAAd,EAAuB,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EAAW;AAAA,MAClB,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-4VDDL2CN.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);\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 return <BowlosContext.Provider value={ref.current}>{children}</BowlosContext.Provider>;\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/** Customer session state + actions. Probes once on mount; each action\n * re-probes so `status`/`customer` stay current. */\nexport function useAccount(): UseAccountResult {\n const client = useBowlosClient();\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// ── 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} from \"./data\";\nimport type {\n BrandScoped,\n FlashBookingOptionsArgs,\n FlashSaleArgs,\n MembershipDetailArgs,\n ReservationDetailArgs,\n} from \"./account\";\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// ── 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/** 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 * 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"]}
|