@bowlos/reservations 0.1.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/LICENSE +21 -0
- package/README.md +130 -0
- package/dist/account-Cl6hElpL.d.cts +367 -0
- package/dist/account-Cl6hElpL.d.ts +367 -0
- package/dist/chunk-T5DDHWEC.js +174 -0
- package/dist/chunk-T5DDHWEC.js.map +1 -0
- package/dist/chunk-TCYTNCUL.js +287 -0
- package/dist/chunk-TCYTNCUL.js.map +1 -0
- package/dist/chunk-TZTFJVDI.js +41 -0
- package/dist/chunk-TZTFJVDI.js.map +1 -0
- package/dist/cli.cjs +530 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +106 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.cjs +547 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +43 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.js +36 -0
- package/dist/index.js.map +1 -0
- package/dist/react.cjs +602 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +94 -0
- package/dist/react.d.ts +94 -0
- package/dist/react.js +299 -0
- package/dist/react.js.map +1 -0
- package/package.json +73 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 BowlOS
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# @bowlos/reservations
|
|
2
|
+
|
|
3
|
+
Headless client + React hooks for the **BowlOS public API gateway** — white-label
|
|
4
|
+
booking, customer accounts, and flash-sale reads for third-party-hosted center
|
|
5
|
+
websites. Built for React/Next sites (including AI-agent-built ones) that book on
|
|
6
|
+
a BowlOS operator's behalf, with **Stripe Connect** payments landing on the
|
|
7
|
+
operator's own account.
|
|
8
|
+
|
|
9
|
+
- **Headless-first.** A typed client + hooks; you own the UI.
|
|
10
|
+
- **Two entry points.** `@bowlos/reservations` (React-free core) and
|
|
11
|
+
`@bowlos/reservations/react` (provider + hooks). React is an optional peer.
|
|
12
|
+
- **Dual ESM + CJS**, fully typed.
|
|
13
|
+
|
|
14
|
+
## Install
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @bowlos/reservations
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
React is a peer dependency (only needed for the `/react` entry):
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install react
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Configure
|
|
27
|
+
|
|
28
|
+
You need a **brand API key** (minted by the operator) and the gateway **base
|
|
29
|
+
URL**. The key is *publishable* — it's gated by a per-key origin allow-list, so
|
|
30
|
+
it's safe in browser code (like a Stripe publishable key). Add your site's
|
|
31
|
+
origin to the key's allow-list.
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
import { createBowlosClient, localStorageTokenStore } from "@bowlos/reservations";
|
|
35
|
+
|
|
36
|
+
export const bowlos = createBowlosClient({
|
|
37
|
+
apiKey: process.env.NEXT_PUBLIC_BOWLOS_API_KEY!,
|
|
38
|
+
baseUrl: "https://<deployment>.convex.site/api/public/v1",
|
|
39
|
+
tokenStore: localStorageTokenStore(), // persists the customer session
|
|
40
|
+
});
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Verify your setup
|
|
44
|
+
|
|
45
|
+
A built-in doctor checks reachability, the API key, origin allow-listing, and
|
|
46
|
+
the data plane:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
npx bowlos doctor --api-key "$NEXT_PUBLIC_BOWLOS_API_KEY" --base-url "https://<deployment>.convex.site/api/public/v1"
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Quick start (React)
|
|
53
|
+
|
|
54
|
+
Wrap your app in the provider, then use the typed hooks:
|
|
55
|
+
|
|
56
|
+
```tsx
|
|
57
|
+
import { BowlosProvider } from "@bowlos/reservations/react";
|
|
58
|
+
import { bowlos } from "./bowlos";
|
|
59
|
+
|
|
60
|
+
export function Providers({ children }: { children: React.ReactNode }) {
|
|
61
|
+
return <BowlosProvider client={bowlos}>{children}</BowlosProvider>;
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
```tsx
|
|
66
|
+
import { useAvailability } from "@bowlos/reservations/react";
|
|
67
|
+
|
|
68
|
+
function LaneAvailability() {
|
|
69
|
+
const availability = useAvailability({
|
|
70
|
+
productId: "<product_id>",
|
|
71
|
+
dateISO: "2026-07-04",
|
|
72
|
+
startMinuteOfDay: 18 * 60,
|
|
73
|
+
endMinuteOfDay: 19 * 60,
|
|
74
|
+
});
|
|
75
|
+
if (availability.loading) return <p>Checking…</p>;
|
|
76
|
+
return <p>{availability.data?.busyUnitIds.length ?? 0} units busy</p>;
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Booking → pay → confirm
|
|
81
|
+
|
|
82
|
+
`useBookingFlow` orchestrates the hold → payment → confirmation state machine.
|
|
83
|
+
It **hands you the Stripe Connect PaymentIntent** (`clientSecret` +
|
|
84
|
+
`connectedAccountId`) — it does not load Stripe.js, so you render Stripe Elements
|
|
85
|
+
yourself, scoped to the operator's connected account:
|
|
86
|
+
|
|
87
|
+
```tsx
|
|
88
|
+
import { useBookingFlow } from "@bowlos/reservations/react";
|
|
89
|
+
|
|
90
|
+
const flow = useBookingFlow();
|
|
91
|
+
// flow.startHold(args) → "held"
|
|
92
|
+
// flow.preparePayment() → "awaitingPayment" (+ flow.paymentIntent)
|
|
93
|
+
// render Stripe Elements: loadStripe(pk, { stripeAccount: flow.paymentIntent.connectedAccountId })
|
|
94
|
+
// flow.startPolling() → "confirmed"
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
A complete reference site (Next.js App Router) using this flow lives in the
|
|
98
|
+
BowlOS repo under `examples/center-site`.
|
|
99
|
+
|
|
100
|
+
## Account + flash sales
|
|
101
|
+
|
|
102
|
+
Signed-in reads (require a customer session): `useMyReservations`,
|
|
103
|
+
`useMyMemberships`, `useMyLoyalty`, `useMyCredits`, `useMyPasses`, plus details.
|
|
104
|
+
Session-aware flash sales: `useFlashSale`, `useFlashSaleBookingOptions`. Manage
|
|
105
|
+
the session with `useAccount` (`signIn` / `signUp` / `link` / `signOut`).
|
|
106
|
+
|
|
107
|
+
Every read also has a framework-agnostic function in the core entry
|
|
108
|
+
(`checkAvailability`, `bookingPreview`, `getMyReservations`, `runDoctor`, …) for
|
|
109
|
+
non-React or server use.
|
|
110
|
+
|
|
111
|
+
## Errors
|
|
112
|
+
|
|
113
|
+
Failed calls throw a typed `BowlosApiError` with a stable `.code` — branch on
|
|
114
|
+
that, never on message text:
|
|
115
|
+
|
|
116
|
+
```ts
|
|
117
|
+
import { BowlosApiError } from "@bowlos/reservations";
|
|
118
|
+
|
|
119
|
+
try {
|
|
120
|
+
await bowlos.signIn(email, password);
|
|
121
|
+
} catch (e) {
|
|
122
|
+
if (e instanceof BowlosApiError && e.code === "INVALID_CREDENTIALS") {
|
|
123
|
+
// show "wrong email or password"
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## License
|
|
129
|
+
|
|
130
|
+
MIT
|
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core types for the BowlOS Reservations SDK client.
|
|
3
|
+
*/
|
|
4
|
+
/** The customer session token pair returned by the auth relay. */
|
|
5
|
+
interface Tokens {
|
|
6
|
+
token: string;
|
|
7
|
+
refreshToken: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Where the client persists the customer's session. Defaults to in-memory.
|
|
11
|
+
* Browser apps pass `localStorageTokenStore()`; SSR / native pass their own.
|
|
12
|
+
*
|
|
13
|
+
* Sync for the web-first scaffold. Async stores (e.g. secure storage) are a
|
|
14
|
+
* follow-up — they will widen these to `| Promise<...>`.
|
|
15
|
+
*/
|
|
16
|
+
interface TokenStore {
|
|
17
|
+
get(): Tokens | null;
|
|
18
|
+
set(tokens: Tokens | null): void;
|
|
19
|
+
}
|
|
20
|
+
/** Minimal fetch surface the client needs — injectable for tests / SSR. */
|
|
21
|
+
type FetchLike = (input: string, init?: RequestInit) => Promise<Response>;
|
|
22
|
+
interface BowlosClientConfig {
|
|
23
|
+
/** Brand publishable API key, sent as `X-BowlOS-Api-Key` on every request. */
|
|
24
|
+
apiKey: string;
|
|
25
|
+
/**
|
|
26
|
+
* Gateway base URL, including the version prefix, e.g.
|
|
27
|
+
* `https://<deployment>.convex.site/api/public/v1`. A trailing slash is fine.
|
|
28
|
+
*/
|
|
29
|
+
baseUrl: string;
|
|
30
|
+
/** Session persistence. Defaults to an in-memory store (lost on reload). */
|
|
31
|
+
tokenStore?: TokenStore;
|
|
32
|
+
/** Override `fetch` (tests, SSR polyfills). Defaults to `globalThis.fetch`. */
|
|
33
|
+
fetch?: FetchLike;
|
|
34
|
+
}
|
|
35
|
+
/** The signed-in customer, as returned by `/auth/me`. Extra fields are passed
|
|
36
|
+
* through so the shape can grow server-side without an SDK release. */
|
|
37
|
+
interface Customer {
|
|
38
|
+
_id: string;
|
|
39
|
+
brandId: string;
|
|
40
|
+
displayId: string;
|
|
41
|
+
fullName: string;
|
|
42
|
+
email: string;
|
|
43
|
+
mobile?: string | null;
|
|
44
|
+
marketingOptIn?: boolean;
|
|
45
|
+
preferredCenterId?: string | null;
|
|
46
|
+
[key: string]: unknown;
|
|
47
|
+
}
|
|
48
|
+
/** Result of `/auth/probe` — the three-state session bootstrap. */
|
|
49
|
+
type AuthState = "unauthenticated" | "authed_no_customer" | "linked";
|
|
50
|
+
/** Result of `GET /ping` — a cheap health + key-validity probe. `mode` reports
|
|
51
|
+
* whether this is a `live` or `test` key; `authenticated` is true when a valid
|
|
52
|
+
* customer bearer happened to be attached. */
|
|
53
|
+
interface PingResult {
|
|
54
|
+
service: string;
|
|
55
|
+
version: string;
|
|
56
|
+
brandId: string;
|
|
57
|
+
mode: "live" | "test";
|
|
58
|
+
authenticated: boolean;
|
|
59
|
+
}
|
|
60
|
+
/** Profile fields collected when linking a freshly-signed-up auth user to a
|
|
61
|
+
* customer record (the second half of sign-up). */
|
|
62
|
+
interface LinkProfile {
|
|
63
|
+
fullName: string;
|
|
64
|
+
email: string;
|
|
65
|
+
mobile?: string;
|
|
66
|
+
marketingOptIn?: boolean;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* BowlosClient — the framework-agnostic core of the Reservations SDK.
|
|
71
|
+
*
|
|
72
|
+
* It is a thin, typed client for the public API gateway (`/api/public/v1/*`):
|
|
73
|
+
* - sends the brand API key (`X-BowlOS-Api-Key`) on every request,
|
|
74
|
+
* - attaches the customer bearer token on authenticated calls,
|
|
75
|
+
* - parses the `{ ok, data | error }` envelope and throws a typed
|
|
76
|
+
* `BowlosApiError` on failure,
|
|
77
|
+
* - owns the customer session: sign-in / sign-up / link / sign-out, plus
|
|
78
|
+
* a transparent refresh-and-retry-once when a session has expired.
|
|
79
|
+
*
|
|
80
|
+
* The React layer (hooks + components) wraps this; nothing here imports React.
|
|
81
|
+
*/
|
|
82
|
+
|
|
83
|
+
/** A `TokenStore` backed by `localStorage` for browser apps. No-ops under SSR
|
|
84
|
+
* / environments without `localStorage`. */
|
|
85
|
+
declare function localStorageTokenStore(storageKey?: string): TokenStore;
|
|
86
|
+
declare class BowlosClient {
|
|
87
|
+
private readonly apiKey;
|
|
88
|
+
private readonly baseUrl;
|
|
89
|
+
private readonly store;
|
|
90
|
+
private readonly fetchFn;
|
|
91
|
+
constructor(config: BowlosClientConfig);
|
|
92
|
+
/** Is there a stored session right now? (Does not validate it server-side.) */
|
|
93
|
+
isAuthenticated(): boolean;
|
|
94
|
+
/** The current token pair, if any (rarely needed directly). */
|
|
95
|
+
getTokens(): Tokens | null;
|
|
96
|
+
/**
|
|
97
|
+
* Health + key-validity probe (`GET /ping`). Resolves with the gateway's
|
|
98
|
+
* service info when the API key is accepted; throws a `BowlosApiError` whose
|
|
99
|
+
* `.code` distinguishes the failure (`NETWORK_ERROR`, `API_KEY_INVALID`,
|
|
100
|
+
* `ORIGIN_NOT_ALLOWED`, `RATE_LIMITED`, …). Cheap enough to call on boot, and
|
|
101
|
+
* the basis for `runDoctor`.
|
|
102
|
+
*/
|
|
103
|
+
ping(): Promise<PingResult>;
|
|
104
|
+
private request;
|
|
105
|
+
/**
|
|
106
|
+
* Call a gateway route by name (`POST /api/public/v1/<name>`), returning the
|
|
107
|
+
* unwrapped `data`. Set `{ auth: true }` to attach the bearer token and
|
|
108
|
+
* enable refresh-and-retry on an expired session.
|
|
109
|
+
*/
|
|
110
|
+
call<T = unknown>(name: string, args?: Record<string, unknown>, opts?: {
|
|
111
|
+
auth?: boolean;
|
|
112
|
+
method?: "GET" | "POST";
|
|
113
|
+
}): Promise<T>;
|
|
114
|
+
private callInternal;
|
|
115
|
+
/** Exchange the stored refresh token for a fresh pair. Clears the session if
|
|
116
|
+
* the refresh token is itself invalid/expired. Returns success. */
|
|
117
|
+
private tryRefresh;
|
|
118
|
+
/** Sign an existing customer in; stores the session on success. */
|
|
119
|
+
signIn(email: string, password: string): Promise<Tokens>;
|
|
120
|
+
/** Create a login (the auth half of sign-up); stores the session. Follow with
|
|
121
|
+
* `link()` to attach the customer profile. */
|
|
122
|
+
signUp(email: string, password: string): Promise<Tokens>;
|
|
123
|
+
/** Link the signed-in auth user to a customer profile at the brand. */
|
|
124
|
+
link(profile: LinkProfile): Promise<unknown>;
|
|
125
|
+
/** End the session (best-effort server call; always clears locally). */
|
|
126
|
+
signOut(): Promise<void>;
|
|
127
|
+
/** Session bootstrap: unauthenticated / authed-no-customer / linked.
|
|
128
|
+
* GET — matches the gateway's `GET /auth/probe` route. */
|
|
129
|
+
probe(): Promise<AuthState>;
|
|
130
|
+
/** The signed-in customer's profile, or null.
|
|
131
|
+
* GET — matches the gateway's `GET /auth/me` route. */
|
|
132
|
+
me(): Promise<Customer | null>;
|
|
133
|
+
}
|
|
134
|
+
/** Create a configured client. */
|
|
135
|
+
declare function createBowlosClient(config: BowlosClientConfig): BowlosClient;
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Error model for the BowlOS Reservations SDK.
|
|
139
|
+
*
|
|
140
|
+
* Every failed gateway call surfaces as a single `BowlosApiError` carrying a
|
|
141
|
+
* stable `code` (string), the HTTP `status`, and — for rate limits — a
|
|
142
|
+
* `retryAfterSeconds`. The gateway normalizes the backend's two error
|
|
143
|
+
* conventions (thrown ConvexError + `{ ok:false }` envelopes) into one JSON
|
|
144
|
+
* shape; this class is the client-side mirror of that shape, so consumers
|
|
145
|
+
* branch on `error.code`, never on message text.
|
|
146
|
+
*/
|
|
147
|
+
/** Stable error codes the gateway / backend can return. Open set — treat
|
|
148
|
+
* `code` as a string and match against these for known cases. */
|
|
149
|
+
declare const BOWLOS_ERROR_CODES: {
|
|
150
|
+
readonly API_KEY_MISSING: "API_KEY_MISSING";
|
|
151
|
+
readonly API_KEY_INVALID: "API_KEY_INVALID";
|
|
152
|
+
readonly ORIGIN_NOT_ALLOWED: "ORIGIN_NOT_ALLOWED";
|
|
153
|
+
readonly RATE_LIMITED: "RATE_LIMITED";
|
|
154
|
+
readonly INVALID_CREDENTIALS: "INVALID_CREDENTIALS";
|
|
155
|
+
readonly SIGNUP_FAILED: "SIGNUP_FAILED";
|
|
156
|
+
readonly VALIDATION_FAILED: "VALIDATION_FAILED";
|
|
157
|
+
readonly PERMISSION_DENIED: "PERMISSION_DENIED";
|
|
158
|
+
readonly SCOPE_REVOKED: "SCOPE_REVOKED";
|
|
159
|
+
readonly NOT_FOUND: "NOT_FOUND";
|
|
160
|
+
readonly VERSION_CONFLICT: "VERSION_CONFLICT";
|
|
161
|
+
readonly PRICING_SNAPSHOT_STALE: "PRICING_SNAPSHOT_STALE";
|
|
162
|
+
readonly PAYMENTS_NOT_CONNECTED: "PAYMENTS_NOT_CONNECTED";
|
|
163
|
+
readonly CONNECT_ACCOUNT_RESTRICTED: "CONNECT_ACCOUNT_RESTRICTED";
|
|
164
|
+
readonly CHECKOUT_EXPIRED: "CHECKOUT_EXPIRED";
|
|
165
|
+
readonly NETWORK_ERROR: "NETWORK_ERROR";
|
|
166
|
+
readonly UNKNOWN: "ERROR";
|
|
167
|
+
};
|
|
168
|
+
type BowlosErrorCode = (typeof BOWLOS_ERROR_CODES)[keyof typeof BOWLOS_ERROR_CODES] | (string & {});
|
|
169
|
+
interface BowlosApiErrorOptions {
|
|
170
|
+
retryAfterSeconds?: number;
|
|
171
|
+
cause?: unknown;
|
|
172
|
+
}
|
|
173
|
+
declare class BowlosApiError extends Error {
|
|
174
|
+
/** Stable, machine-readable code. Branch on this, not on `message`. */
|
|
175
|
+
readonly code: BowlosErrorCode;
|
|
176
|
+
/** HTTP status (0 for a network failure before any response). */
|
|
177
|
+
readonly status: number;
|
|
178
|
+
/** Seconds to wait before retrying — present only on `RATE_LIMITED`. */
|
|
179
|
+
readonly retryAfterSeconds?: number;
|
|
180
|
+
constructor(code: BowlosErrorCode, message: string, status: number, options?: BowlosApiErrorOptions);
|
|
181
|
+
/** Too many requests — caller should back off `retryAfterSeconds`. */
|
|
182
|
+
get isRateLimited(): boolean;
|
|
183
|
+
/** Bad/expired login. The session could not be established or has lapsed. */
|
|
184
|
+
get isAuthError(): boolean;
|
|
185
|
+
/** Wrong/missing API key or a disallowed origin — a site-config problem,
|
|
186
|
+
* not something the end customer can fix. */
|
|
187
|
+
get isConfigError(): boolean;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Typed data surface for @bowlos/reservations — booking-funnel reads.
|
|
192
|
+
*
|
|
193
|
+
* Arg shapes mirror the gateway functions; result shapes type the headline
|
|
194
|
+
* fields and pass the rest through (`[key: string]: unknown`), so the backend's
|
|
195
|
+
* full breakdown can grow without an SDK release. Each read has a
|
|
196
|
+
* framework-agnostic function here and a React hook in `hooks.tsx`, sharing
|
|
197
|
+
* these types.
|
|
198
|
+
*
|
|
199
|
+
* This file is React-free, so it's exported from the core entry. The hooks
|
|
200
|
+
* (React) live in `hooks.tsx` under the React entry.
|
|
201
|
+
*/
|
|
202
|
+
|
|
203
|
+
/** Inputs for `checkAvailability`. Times are minutes-of-day in the Center's tz. */
|
|
204
|
+
type AvailabilityArgs = {
|
|
205
|
+
productId: string;
|
|
206
|
+
dateISO: string;
|
|
207
|
+
startMinuteOfDay: number;
|
|
208
|
+
endMinuteOfDay: number;
|
|
209
|
+
};
|
|
210
|
+
interface AvailabilityResult {
|
|
211
|
+
totalUnits: number;
|
|
212
|
+
busyUnitIds: string[];
|
|
213
|
+
}
|
|
214
|
+
type PricingMode = "per_unit_per_hour" | "per_person_per_hour" | "per_game";
|
|
215
|
+
type BookingAddonSelection = {
|
|
216
|
+
addonId: string;
|
|
217
|
+
quantity: number;
|
|
218
|
+
};
|
|
219
|
+
/** Inputs for `bookingPreview` (the authoritative price quote). */
|
|
220
|
+
type BookingPreviewArgs = {
|
|
221
|
+
centerId: string;
|
|
222
|
+
productId: string;
|
|
223
|
+
dateISO: string;
|
|
224
|
+
startMinuteOfDay: number;
|
|
225
|
+
endMinuteOfDay: number;
|
|
226
|
+
mode: PricingMode;
|
|
227
|
+
units?: number;
|
|
228
|
+
persons?: number;
|
|
229
|
+
games?: number;
|
|
230
|
+
addons?: BookingAddonSelection[];
|
|
231
|
+
shareToken?: string;
|
|
232
|
+
subtypeId?: string;
|
|
233
|
+
};
|
|
234
|
+
/** The price quote. Headline fields are typed; the engine's full breakdown
|
|
235
|
+
* (line items, discounts, tax, credit) is passed through. */
|
|
236
|
+
interface BookingQuote {
|
|
237
|
+
reservationFee: Record<string, unknown> | null;
|
|
238
|
+
totalCentsPerPlan: Array<{
|
|
239
|
+
pricePlanId: string;
|
|
240
|
+
totalCents: number;
|
|
241
|
+
}>;
|
|
242
|
+
[key: string]: unknown;
|
|
243
|
+
}
|
|
244
|
+
/** Free units for a product/date/time window (anonymous). */
|
|
245
|
+
declare function checkAvailability(client: BowlosClient, args: AvailabilityArgs): Promise<AvailabilityResult>;
|
|
246
|
+
/** Authoritative price quote for the chosen inputs (anonymous; a signed-in
|
|
247
|
+
* session unlocks member rates + account credit). */
|
|
248
|
+
declare function bookingPreview(client: BowlosClient, args: BookingPreviewArgs): Promise<BookingQuote>;
|
|
249
|
+
/** Convenience: free units = total minus the busy set (never negative). */
|
|
250
|
+
declare function availableUnitCount(availability: AvailabilityResult): number;
|
|
251
|
+
/** Customer identity for a booking (collected in the booking form; the server
|
|
252
|
+
* links/creates the customer per the booking-flow-only signup rule). */
|
|
253
|
+
type BookingCustomer = {
|
|
254
|
+
fullName: string;
|
|
255
|
+
email: string;
|
|
256
|
+
mobile?: string;
|
|
257
|
+
marketingOptIn: boolean;
|
|
258
|
+
};
|
|
259
|
+
/** Inputs for `createAnonymousBooking` — places the inventory hold. */
|
|
260
|
+
type CreateBookingArgs = {
|
|
261
|
+
centerId: string;
|
|
262
|
+
productId: string;
|
|
263
|
+
dateISO: string;
|
|
264
|
+
startMinuteOfDay: number;
|
|
265
|
+
endMinuteOfDay: number;
|
|
266
|
+
mode: PricingMode;
|
|
267
|
+
units?: number;
|
|
268
|
+
persons?: number;
|
|
269
|
+
games?: number;
|
|
270
|
+
addons?: BookingAddonSelection[];
|
|
271
|
+
customer: BookingCustomer;
|
|
272
|
+
/** Apply account credit (requires a signed-in customer). */
|
|
273
|
+
applyCredit?: boolean;
|
|
274
|
+
/** Idempotency key for the create. The SDK generates one if omitted. */
|
|
275
|
+
idempotencyKey?: string;
|
|
276
|
+
shareToken?: string;
|
|
277
|
+
subtypeId?: string;
|
|
278
|
+
};
|
|
279
|
+
/** Result of placing a booking. The hold→pay path returns `checkoutRefToken`
|
|
280
|
+
* with `requiresPayment: true`; a credit-covered / $0 booking returns the
|
|
281
|
+
* materialized `reservationId` + `reservationDisplayId` with
|
|
282
|
+
* `requiresPayment: false`. Headline fields typed; the rest passes through. */
|
|
283
|
+
interface BookingHold {
|
|
284
|
+
checkoutRefToken?: string;
|
|
285
|
+
reservationId?: string | null;
|
|
286
|
+
reservationDisplayId?: string | null;
|
|
287
|
+
requiresPayment: boolean;
|
|
288
|
+
finalCents: number;
|
|
289
|
+
appliedCreditCents: number;
|
|
290
|
+
paidCents?: number;
|
|
291
|
+
holdExpiresAt?: number;
|
|
292
|
+
replayed?: boolean;
|
|
293
|
+
[key: string]: unknown;
|
|
294
|
+
}
|
|
295
|
+
type CheckoutStatus = "not_found" | "pending_payment" | "paid_materialized" | "expired" | "payment_failed_retryable" | "abandoned";
|
|
296
|
+
interface CheckoutStatusResult {
|
|
297
|
+
status: CheckoutStatus;
|
|
298
|
+
reservationDisplayId: string | null;
|
|
299
|
+
reservationId: string | null;
|
|
300
|
+
}
|
|
301
|
+
/** Stripe (Connect) PaymentIntent data for the UI layer to render Elements.
|
|
302
|
+
* The SDK does NOT load Stripe.js — initialize it with `connectedAccountId`
|
|
303
|
+
* (the operator's connected account) + `clientSecret`. */
|
|
304
|
+
interface PaymentIntentInfo {
|
|
305
|
+
paymentIntentId: string;
|
|
306
|
+
clientSecret: string;
|
|
307
|
+
amountCents: number;
|
|
308
|
+
customerId: string;
|
|
309
|
+
ephemeralKey: string;
|
|
310
|
+
customerSessionClientSecret: string;
|
|
311
|
+
connectedAccountId: string;
|
|
312
|
+
}
|
|
313
|
+
/** Browser/Node-safe idempotency key for booking creates. */
|
|
314
|
+
declare function generateIdempotencyKey(): string;
|
|
315
|
+
/** Place the inventory hold + open a checkout. Sends the session when present
|
|
316
|
+
* (member rates + account credit); falls back to anonymous. */
|
|
317
|
+
declare function createBooking(client: BowlosClient, args: CreateBookingArgs): Promise<BookingHold>;
|
|
318
|
+
/** Mint the Stripe Connect PaymentIntent for a held checkout (by refToken). */
|
|
319
|
+
declare function createCheckoutPaymentIntent(client: BowlosClient, refToken: string): Promise<PaymentIntentInfo>;
|
|
320
|
+
/** Poll the hold→pay→materialize state for a checkout (by refToken). */
|
|
321
|
+
declare function getCheckoutStatus(client: BowlosClient, refToken: string): Promise<CheckoutStatusResult>;
|
|
322
|
+
/** Release the hold + cancel the checkout (the "Back" button). */
|
|
323
|
+
declare function abandonCheckout(client: BowlosClient, refToken: string): Promise<{
|
|
324
|
+
ok: boolean;
|
|
325
|
+
}>;
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* Typed account + flash reads for @bowlos/reservations.
|
|
329
|
+
*
|
|
330
|
+
* Session-scoped account reads (require a signed-in customer) and the
|
|
331
|
+
* session-aware flash-sale reads. Args are typed precisely — every account read
|
|
332
|
+
* is brand-scoped. Results are generic (`<T = unknown>`): parameterize with your
|
|
333
|
+
* own shape, or read `unknown` and narrow. (The backend return shapes are rich
|
|
334
|
+
* and evolving; the SDK doesn't pin them here.) Each read has a framework-agnostic
|
|
335
|
+
* function here and a React hook in `hooks.tsx`.
|
|
336
|
+
*/
|
|
337
|
+
|
|
338
|
+
/** Every account read is scoped to the customer's Brand. */
|
|
339
|
+
type BrandScoped = {
|
|
340
|
+
brandId: string;
|
|
341
|
+
};
|
|
342
|
+
type ReservationDetailArgs = {
|
|
343
|
+
brandId: string;
|
|
344
|
+
displayId: string;
|
|
345
|
+
};
|
|
346
|
+
type MembershipDetailArgs = {
|
|
347
|
+
brandId: string;
|
|
348
|
+
membershipId: string;
|
|
349
|
+
};
|
|
350
|
+
type FlashSaleArgs = {
|
|
351
|
+
slug: string;
|
|
352
|
+
};
|
|
353
|
+
type FlashBookingOptionsArgs = {
|
|
354
|
+
slug: string;
|
|
355
|
+
itemId: string;
|
|
356
|
+
};
|
|
357
|
+
declare function getMyReservations<T = unknown>(client: BowlosClient, args: BrandScoped): Promise<T>;
|
|
358
|
+
declare function getMyReservationDetail<T = unknown>(client: BowlosClient, args: ReservationDetailArgs): Promise<T>;
|
|
359
|
+
declare function getMyMemberships<T = unknown>(client: BowlosClient, args: BrandScoped): Promise<T>;
|
|
360
|
+
declare function getMyMembershipDetail<T = unknown>(client: BowlosClient, args: MembershipDetailArgs): Promise<T>;
|
|
361
|
+
declare function getMyLoyalty<T = unknown>(client: BowlosClient, args: BrandScoped): Promise<T>;
|
|
362
|
+
declare function getMyCredits<T = unknown>(client: BowlosClient, args: BrandScoped): Promise<T>;
|
|
363
|
+
declare function getMyPasses<T = unknown>(client: BowlosClient, args: BrandScoped): Promise<T>;
|
|
364
|
+
declare function getFlashSale<T = unknown>(client: BowlosClient, args: FlashSaleArgs): Promise<T>;
|
|
365
|
+
declare function getFlashSaleBookingOptions<T = unknown>(client: BowlosClient, args: FlashBookingOptionsArgs): Promise<T>;
|
|
366
|
+
|
|
367
|
+
export { type AuthState as A, BOWLOS_ERROR_CODES as B, type CheckoutStatus as C, createBowlosClient as D, createCheckoutPaymentIntent as E, type FetchLike as F, generateIdempotencyKey as G, getCheckoutStatus as H, getFlashSale as I, getFlashSaleBookingOptions as J, getMyCredits as K, type LinkProfile as L, type MembershipDetailArgs as M, getMyLoyalty as N, getMyMembershipDetail as O, type PaymentIntentInfo as P, getMyMemberships as Q, type ReservationDetailArgs as R, getMyPasses as S, type TokenStore as T, getMyReservationDetail as U, getMyReservations as V, localStorageTokenStore as W, type AvailabilityArgs as a, type AvailabilityResult as b, type BookingAddonSelection as c, type BookingCustomer as d, type BookingHold as e, type BookingPreviewArgs as f, type BookingQuote as g, BowlosApiError as h, type BowlosApiErrorOptions as i, BowlosClient as j, type BowlosClientConfig as k, type BowlosErrorCode as l, type BrandScoped as m, type CheckoutStatusResult as n, type CreateBookingArgs as o, type Customer as p, type FlashBookingOptionsArgs as q, type FlashSaleArgs as r, type PingResult as s, type PricingMode as t, type Tokens as u, abandonCheckout as v, availableUnitCount as w, bookingPreview as x, checkAvailability as y, createBooking as z };
|