@bowlos/reservations 0.1.0 → 0.4.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 +83 -0
- package/dist/account-COEgvwfx.d.cts +43 -0
- package/dist/account-CzyIERC5.d.ts +43 -0
- package/dist/{chunk-TZTFJVDI.js → chunk-2RMK6BWO.js} +2 -2
- package/dist/{chunk-TZTFJVDI.js.map → chunk-2RMK6BWO.js.map} +1 -1
- package/dist/{chunk-T5DDHWEC.js → chunk-4FL2QYSS.js} +3 -3
- package/dist/{chunk-T5DDHWEC.js.map → chunk-4FL2QYSS.js.map} +1 -1
- package/dist/chunk-NYTGLAQH.js +299 -0
- package/dist/chunk-NYTGLAQH.js.map +1 -0
- package/dist/{chunk-TCYTNCUL.js → chunk-QGTGKNJW.js} +11 -3
- package/dist/chunk-QGTGKNJW.js.map +1 -0
- package/dist/cli.cjs +74 -4
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +76 -6
- package/dist/cli.js.map +1 -1
- 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/index.js +3 -3
- 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 +14 -3
- package/templates/center-site/README.md +85 -0
- package/templates/center-site/app/account/page.tsx +19 -0
- package/templates/center-site/app/book/checkout-form.tsx +85 -0
- package/templates/center-site/app/book/page.tsx +181 -0
- package/templates/center-site/app/flash/[slug]/page.tsx +24 -0
- package/templates/center-site/app/layout.tsx +17 -0
- package/templates/center-site/app/page.tsx +26 -0
- package/templates/center-site/app/providers.tsx +21 -0
- package/templates/center-site/env.example +18 -0
- package/templates/center-site/gitignore +8 -0
- package/templates/center-site/lib/bowlos.ts +31 -0
- package/templates/center-site/next.config.mjs +8 -0
- package/templates/center-site/package.json +26 -0
- package/templates/center-site/tsconfig.json +38 -0
- package/dist/chunk-TCYTNCUL.js.map +0 -1
package/README.md
CHANGED
|
@@ -11,6 +11,26 @@ operator's own account.
|
|
|
11
11
|
`@bowlos/reservations/react` (provider + hooks). React is an optional peer.
|
|
12
12
|
- **Dual ESM + CJS**, fully typed.
|
|
13
13
|
|
|
14
|
+
## Quickest start: scaffold a site
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npx @bowlos/reservations init my-center-site
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Scaffolds a complete, runnable Next.js center site — `/book`, `/account`, and
|
|
21
|
+
`/flash/[slug]` already wired, with the Stripe Connect payment handoff and a
|
|
22
|
+
themeable provider. It ships **both build styles** as a working reference:
|
|
23
|
+
`/book` is built from the headless hooks; `/account` and `/flash` use the
|
|
24
|
+
themeable components. Keep what fits, swap the rest. Then:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
cd my-center-site && npm install
|
|
28
|
+
cp env.example .env.local # fill in your key + brand/center/product ids
|
|
29
|
+
npm run dev
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Prefer to wire it by hand, or add the SDK to an existing app? Read on.
|
|
33
|
+
|
|
14
34
|
## Install
|
|
15
35
|
|
|
16
36
|
```bash
|
|
@@ -108,6 +128,69 @@ Every read also has a framework-agnostic function in the core entry
|
|
|
108
128
|
(`checkAvailability`, `bookingPreview`, `getMyReservations`, `runDoctor`, …) for
|
|
109
129
|
non-React or server use.
|
|
110
130
|
|
|
131
|
+
## Drop-in components (`@bowlos/reservations/components`)
|
|
132
|
+
|
|
133
|
+
Don't want to build the UI from hooks? A **themeable, white-label** component
|
|
134
|
+
layer sits on top of them:
|
|
135
|
+
|
|
136
|
+
```tsx
|
|
137
|
+
import { BowlosProvider } from "@bowlos/reservations/react";
|
|
138
|
+
import { BookingFlow, BowlosTheme } from "@bowlos/reservations/components";
|
|
139
|
+
|
|
140
|
+
<BowlosProvider client={bowlos}>
|
|
141
|
+
<BowlosTheme theme={{ colorPrimary: "#e4002b", radius: "8px" }}>
|
|
142
|
+
<BookingFlow
|
|
143
|
+
centerId="center_…"
|
|
144
|
+
productId="product_…"
|
|
145
|
+
unitLabel={{ singular: "lane", plural: "lanes" }}
|
|
146
|
+
renderPayment={({ paymentIntent, onPaid, onError }) => (
|
|
147
|
+
<YourStripeForm paymentIntent={paymentIntent} onPaid={onPaid} onError={onError} />
|
|
148
|
+
)}
|
|
149
|
+
onConfirmed={(r) => console.log("booked", r.reservationDisplayId)}
|
|
150
|
+
/>
|
|
151
|
+
</BowlosTheme>
|
|
152
|
+
</BowlosProvider>;
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Three drop-in surfaces cover a center site end to end:
|
|
156
|
+
|
|
157
|
+
**`<BookingFlow>`** runs the whole funnel (availability + price → reserve → pay →
|
|
158
|
+
confirm). It **hands you the Stripe Connect PaymentIntent** via `renderPayment`
|
|
159
|
+
— the SDK never loads Stripe.js, so you render Elements yourself
|
|
160
|
+
(`loadStripe(pk, { stripeAccount: paymentIntent.connectedAccountId })` →
|
|
161
|
+
`confirmPayment` → call `onPaid()`).
|
|
162
|
+
|
|
163
|
+
**`<AccountDashboard brandId>`** is a complete account page: it signs the
|
|
164
|
+
customer in (via the built-in `<AuthGate>`), then shows their reservations,
|
|
165
|
+
memberships, loyalty, account credit, and passes. Pick a subset with
|
|
166
|
+
`sections={["reservations", "credits"]}`.
|
|
167
|
+
|
|
168
|
+
```tsx
|
|
169
|
+
import { AccountDashboard } from "@bowlos/reservations/components";
|
|
170
|
+
|
|
171
|
+
<AccountDashboard brandId="brand_…" />;
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
**`<FlashSale slug>`** is the branded, login-gated flash-sale page. Anonymous
|
|
175
|
+
visitors see the brand, a live countdown, the operator's pre-login message, and
|
|
176
|
+
item names with prices **locked** behind a sign-in form — sale prices are
|
|
177
|
+
member-only and **never cross the wire** until a customer of the Brand signs in.
|
|
178
|
+
Once signed in, prices unlock (shown as a per-date range) and each item gets a
|
|
179
|
+
Book button you hand off via `onBook`:
|
|
180
|
+
|
|
181
|
+
```tsx
|
|
182
|
+
import { FlashSale } from "@bowlos/reservations/components";
|
|
183
|
+
|
|
184
|
+
<FlashSale slug="tuesday-blowout" onBook={(item) => router.push(`/book?flashItem=${item.id}`)} />;
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
`<AuthGate>` (sign in / create account / finish profile) is also exported on its
|
|
188
|
+
own if you want to gate your own content behind a customer session.
|
|
189
|
+
|
|
190
|
+
**Theming:** neutral defaults with **no BowlOS branding** (these are *your*
|
|
191
|
+
center's pages). Restyle via `<BowlosTheme>` or by setting the `--bowlos-*` CSS
|
|
192
|
+
variables yourself (`--bowlos-color-primary`, `--bowlos-radius`, `--bowlos-font`, …).
|
|
193
|
+
|
|
111
194
|
## Errors
|
|
112
195
|
|
|
113
196
|
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 };
|
|
@@ -37,5 +37,5 @@ function abandonCheckout(client, refToken) {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
export { abandonCheckout, availableUnitCount, bookingPreview, checkAvailability, createBooking, createCheckoutPaymentIntent, generateIdempotencyKey, getCheckoutStatus };
|
|
40
|
-
//# sourceMappingURL=chunk-
|
|
41
|
-
//# sourceMappingURL=chunk-
|
|
40
|
+
//# sourceMappingURL=chunk-2RMK6BWO.js.map
|
|
41
|
+
//# sourceMappingURL=chunk-2RMK6BWO.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/data.ts"],"names":[],"mappings":";AAwDO,SAAS,iBAAA,CACd,QACA,IAAA,EAC6B;AAC7B,EAAA,OAAO,MAAA,CAAO,IAAA,CAAyB,mBAAA,EAAqB,IAAI,CAAA;AAClE;AAIO,SAAS,cAAA,CACd,QACA,IAAA,EACuB;AACvB,EAAA,OAAO,MAAA,CAAO,IAAA,CAAmB,gBAAA,EAAkB,IAAI,CAAA;AACzD;AAGO,SAAS,mBAAmB,YAAA,EAA0C;AAC3E,EAAA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A2B,mBAAA,EAAqB,EAAE,UAAS,EAAG,EAAE,IAAA,EAAM,IAAA,EAAM,CAAA;AAC5F;AAGO,SAAS,eAAA,CACd,QACA,QAAA,EAC0B;AAC1B,EAAA,OAAO,MAAA,CAAO,KAAsB,iBAAA,EAAmB,EAAE,UAAS,EAAG,EAAE,IAAA,EAAM,IAAA,EAAM,CAAA;AACrF","file":"chunk-2RMK6BWO.js","sourcesContent":["/**\n * Typed data surface for @bowlos/reservations — booking-funnel reads.\n *\n * Arg shapes mirror the gateway functions; result shapes type the headline\n * fields and pass the rest through (`[key: string]: unknown`), so the backend's\n * full breakdown can grow without an SDK release. Each read has a\n * framework-agnostic function here and a React hook in `hooks.tsx`, sharing\n * these types.\n *\n * This file is React-free, so it's exported from the core entry. The hooks\n * (React) live in `hooks.tsx` under the React entry.\n */\nimport type { BowlosClient } from \"./client\";\n\n/** Inputs for `checkAvailability`. Times are minutes-of-day in the Center's tz. */\nexport type AvailabilityArgs = {\n productId: string;\n dateISO: string;\n startMinuteOfDay: number;\n endMinuteOfDay: number;\n};\n\nexport interface AvailabilityResult {\n totalUnits: number;\n busyUnitIds: string[];\n}\n\nexport type PricingMode = \"per_unit_per_hour\" | \"per_person_per_hour\" | \"per_game\";\n\nexport type BookingAddonSelection = { addonId: string; quantity: number };\n\n/** Inputs for `bookingPreview` (the authoritative price quote). */\nexport type BookingPreviewArgs = {\n centerId: string;\n productId: string;\n dateISO: string;\n startMinuteOfDay: number;\n endMinuteOfDay: number;\n mode: PricingMode;\n units?: number;\n persons?: number;\n games?: number;\n addons?: BookingAddonSelection[];\n shareToken?: string;\n subtypeId?: string;\n};\n\n/** The price quote. Headline fields are typed; the engine's full breakdown\n * (line items, discounts, tax, credit) is passed through. */\nexport interface BookingQuote {\n reservationFee: Record<string, unknown> | null;\n totalCentsPerPlan: Array<{ pricePlanId: string; totalCents: number }>;\n [key: string]: unknown;\n}\n\n/** Free units for a product/date/time window (anonymous). */\nexport function checkAvailability(\n client: BowlosClient,\n args: AvailabilityArgs,\n): Promise<AvailabilityResult> {\n return client.call<AvailabilityResult>(\"checkAvailability\", args);\n}\n\n/** Authoritative price quote for the chosen inputs (anonymous; a signed-in\n * session unlocks member rates + account credit). */\nexport function bookingPreview(\n client: BowlosClient,\n args: BookingPreviewArgs,\n): Promise<BookingQuote> {\n return client.call<BookingQuote>(\"bookingPreview\", args);\n}\n\n/** Convenience: free units = total minus the busy set (never negative). */\nexport function availableUnitCount(availability: AvailabilityResult): number {\n return Math.max(0, availability.totalUnits - availability.busyUnitIds.length);\n}\n\n// ── booking flow (hold → pay → confirm) ──────────────────────────────────────\n\n/** Customer identity for a booking (collected in the booking form; the server\n * links/creates the customer per the booking-flow-only signup rule). */\nexport type BookingCustomer = {\n fullName: string;\n email: string;\n mobile?: string;\n marketingOptIn: boolean;\n};\n\n/** Inputs for `createAnonymousBooking` — places the inventory hold. */\nexport type CreateBookingArgs = {\n centerId: string;\n productId: string;\n dateISO: string;\n startMinuteOfDay: number;\n endMinuteOfDay: number;\n mode: PricingMode;\n units?: number;\n persons?: number;\n games?: number;\n addons?: BookingAddonSelection[];\n customer: BookingCustomer;\n /** Apply account credit (requires a signed-in customer). */\n applyCredit?: boolean;\n /** Idempotency key for the create. The SDK generates one if omitted. */\n idempotencyKey?: string;\n shareToken?: string;\n subtypeId?: string;\n};\n\n/** Result of placing a booking. The hold→pay path returns `checkoutRefToken`\n * with `requiresPayment: true`; a credit-covered / $0 booking returns the\n * materialized `reservationId` + `reservationDisplayId` with\n * `requiresPayment: false`. Headline fields typed; the rest passes through. */\nexport interface BookingHold {\n checkoutRefToken?: string;\n reservationId?: string | null;\n reservationDisplayId?: string | null;\n requiresPayment: boolean;\n finalCents: number;\n appliedCreditCents: number;\n paidCents?: number;\n holdExpiresAt?: number;\n replayed?: boolean;\n [key: string]: unknown;\n}\n\nexport type CheckoutStatus =\n | \"not_found\"\n | \"pending_payment\"\n | \"paid_materialized\"\n | \"expired\"\n | \"payment_failed_retryable\"\n | \"abandoned\";\n\nexport interface CheckoutStatusResult {\n status: CheckoutStatus;\n reservationDisplayId: string | null;\n reservationId: string | null;\n}\n\n/** Stripe (Connect) PaymentIntent data for the UI layer to render Elements.\n * The SDK does NOT load Stripe.js — initialize it with `connectedAccountId`\n * (the operator's connected account) + `clientSecret`. */\nexport interface PaymentIntentInfo {\n paymentIntentId: string;\n clientSecret: string;\n amountCents: number;\n customerId: string;\n ephemeralKey: string;\n customerSessionClientSecret: string;\n connectedAccountId: string;\n}\n\n/** Browser/Node-safe idempotency key for booking creates. */\nexport function generateIdempotencyKey(): string {\n if (typeof crypto !== \"undefined\" && typeof crypto.randomUUID === \"function\") {\n return crypto.randomUUID();\n }\n return `idem_${Date.now()}_${Math.random().toString(36).slice(2, 10)}`;\n}\n\n/** Place the inventory hold + open a checkout. Sends the session when present\n * (member rates + account credit); falls back to anonymous. */\nexport function createBooking(\n client: BowlosClient,\n args: CreateBookingArgs,\n): Promise<BookingHold> {\n const idempotencyKey = args.idempotencyKey ?? generateIdempotencyKey();\n return client.call<BookingHold>(\n \"createAnonymousBooking\",\n { ...args, idempotencyKey },\n { auth: true },\n );\n}\n\n/** Mint the Stripe Connect PaymentIntent for a held checkout (by refToken). */\nexport function createCheckoutPaymentIntent(\n client: BowlosClient,\n refToken: string,\n): Promise<PaymentIntentInfo> {\n return client.call<PaymentIntentInfo>(\n \"createCheckoutPaymentIntent\",\n { refToken },\n { auth: true },\n );\n}\n\n/** Poll the hold→pay→materialize state for a checkout (by refToken). */\nexport function getCheckoutStatus(\n client: BowlosClient,\n refToken: string,\n): Promise<CheckoutStatusResult> {\n return client.call<CheckoutStatusResult>(\"getCheckoutStatus\", { refToken }, { auth: true });\n}\n\n/** Release the hold + cancel the checkout (the \"Back\" button). */\nexport function abandonCheckout(\n client: BowlosClient,\n refToken: string,\n): Promise<{ ok: boolean }> {\n return client.call<{ ok: boolean }>(\"abandonCheckout\", { refToken }, { auth: true });\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createBowlosClient, BOWLOS_ERROR_CODES, BowlosApiError } from './chunk-
|
|
1
|
+
import { createBowlosClient, BOWLOS_ERROR_CODES, BowlosApiError } from './chunk-QGTGKNJW.js';
|
|
2
2
|
|
|
3
3
|
// src/doctor.ts
|
|
4
4
|
var GATEWAY_SUFFIX = "/api/public/v1";
|
|
@@ -170,5 +170,5 @@ async function runDoctor(options) {
|
|
|
170
170
|
}
|
|
171
171
|
|
|
172
172
|
export { runDoctor };
|
|
173
|
-
//# sourceMappingURL=chunk-
|
|
174
|
-
//# sourceMappingURL=chunk-
|
|
173
|
+
//# sourceMappingURL=chunk-4FL2QYSS.js.map
|
|
174
|
+
//# sourceMappingURL=chunk-4FL2QYSS.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/doctor.ts"],"names":[],"mappings":";;;AA0DA,IAAM,cAAA,GAAiB,gBAAA;AAIvB,eAAsB,UAAU,OAAA,EAA+C;AAC7E,EAAA,MAAM,SAAwB,EAAC;AAC/B,EAAA,MAAM,SAAuB,EAAE,EAAA,EAAI,MAAM,MAAA,EAAQ,OAAA,EAAS,QAAQ,OAAA,EAAQ;AAG1E,EAAA,MAAM,eAAyB,EAAC;AAChC,EAAA,IAAI,CAAC,OAAA,CAAQ,MAAA,EAAQ,YAAA,CAAa,KAAK,mBAAmB,CAAA;AAC1D,EAAA,IAAI,SAAA,GAAwB,IAAA;AAC5B,EAAA,IAAI;AACF,IAAA,SAAA,GAAY,IAAI,GAAA,CAAI,OAAA,CAAQ,OAAO,CAAA;AAAA,EACrC,CAAA,CAAA,MAAQ;AACN,IAAA,YAAA,CAAa,KAAK,8BAA8B,CAAA;AAAA,EAClD;AACA,EAAA,IAAI,YAAA,CAAa,SAAS,CAAA,EAAG;AAC3B,IAAA,MAAA,CAAO,IAAA,CAAK;AAAA,MACV,EAAA,EAAI,QAAA;AAAA,MACJ,KAAA,EAAO,sBAAA;AAAA,MACP,MAAA,EAAQ,MAAA;AA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GAAA;AAAA,IACR,GAAA,EAAK;AAAA,GACN,CAAA;AAED,EAAA,MAAA,CAAO,EAAA,GAAK,CAAC,MAAA,CAAO,IAAA,CAAK,CAAC,CAAA,KAAM,CAAA,CAAE,WAAW,MAAM,CAAA;AACnD,EAAA,OAAO,MAAA;AACT","file":"chunk-T5DDHWEC.js","sourcesContent":["/**\n * `runDoctor` — a setup-readiness oracle for a site built on @bowlos/reservations.\n *\n * It runs a short sequence of checks against a configured gateway + API key and\n * returns a structured report (pass / warn / fail / skip), each with a one-line\n * fix when it isn't a pass. The point is to make per-site setup self-debuggable\n * — it walks the failure modes a new center site actually hits, in order:\n * config → gateway reachable → API key valid → origin allow-listed → data plane.\n *\n * Framework-agnostic and dependency-free: it builds a `BowlosClient`, leans on\n * `client.ping()` (one call covers reachability + key + origin + rate-limit),\n * and reports honestly — checks it can't run from the current environment are\n * `skip`ped with guidance rather than faked. The `bowlos doctor` CLI is a thin\n * wrapper that pretty-prints the report.\n */\nimport { createBowlosClient } from \"./client\";\nimport { BowlosApiError, BOWLOS_ERROR_CODES } from \"./errors\";\nimport type { FetchLike, PingResult } from \"./types\";\n\nexport type DoctorCheckStatus = \"pass\" | \"warn\" | \"fail\" | \"skip\";\n\nexport interface DoctorCheck {\n /** Stable id (`config` | `gateway` | `api-key` | `origin` | `rate-limit` | `data-read` | `payments`). */\n id: string;\n title: string;\n status: DoctorCheckStatus;\n detail: string;\n /** One-line remediation, present when `status` isn't `pass`. */\n fix?: string;\n}\n\nexport interface DoctorReport {\n /** True when no check failed (warnings and skips are tolerated). */\n ok: boolean;\n checks: DoctorCheck[];\n /** Echoed back so the CLI can show what it probed. */\n baseUrl: string;\n /** From a successful ping — the key's brand + mode. */\n brandId?: string;\n mode?: \"live\" | \"test\";\n}\n\nexport interface DoctorOptions {\n apiKey: string;\n baseUrl: string;\n /**\n * The deployed site origin. Origin allow-listing is enforced by the gateway\n * only for browser requests (Origin is a forbidden header from Node), so this\n * can be actively verified only in a browser; from Node it informs the\n * skip-guidance message.\n */\n origin?: string;\n /** Skip the (anonymous) data-plane read even when a brand is known. */\n skipDataRead?: boolean;\n /** Injectable transport (tests / SSR polyfills). */\n fetch?: FetchLike;\n}\n\nconst GATEWAY_SUFFIX = \"/api/public/v1\";\n\n/** Run the readiness checks and return a structured report. Never throws — every\n * failure mode is captured as a check. */\nexport async function runDoctor(options: DoctorOptions): Promise<DoctorReport> {\n const checks: DoctorCheck[] = [];\n const report: DoctorReport = { ok: true, checks, baseUrl: options.baseUrl };\n\n // 1) config — can we even build a client?\n const configIssues: string[] = [];\n if (!options.apiKey) configIssues.push(\"`apiKey` is empty\");\n let parsedUrl: URL | null = null;\n try {\n parsedUrl = new URL(options.baseUrl);\n } catch {\n configIssues.push(\"`baseUrl` is not a valid URL\");\n }\n if (configIssues.length > 0) {\n checks.push({\n id: \"config\",\n title: \"Client configuration\",\n status: \"fail\",\n detail: `${configIssues.join(\"; \")}.`,\n fix: \"Pass a brand API key and the gateway base URL, e.g. https://<deployment>.convex.site/api/public/v1\",\n });\n report.ok = false;\n return report; // can't probe without a valid client config\n }\n\n const urlMisaimed =\n parsedUrl !== null && !parsedUrl.pathname.replace(/\\/+$/, \"\").endsWith(GATEWAY_SUFFIX);\n checks.push({\n id: \"config\",\n title: \"Client configuration\",\n status: urlMisaimed ? \"warn\" : \"pass\",\n detail: urlMisaimed\n ? `baseUrl \"${options.baseUrl}\" doesn't end with ${GATEWAY_SUFFIX} — it should point at the gateway, not the site root.`\n : \"API key present; base URL well-formed.\",\n fix: urlMisaimed ? `Use the gateway URL, e.g. ${parsedUrl?.origin}${GATEWAY_SUFFIX}` : undefined,\n });\n\n const client = createBowlosClient({\n apiKey: options.apiKey,\n baseUrl: options.baseUrl,\n fetch: options.fetch,\n });\n\n // 2) one ping covers: gateway reachable + key valid + (browser) origin + rate-limit.\n let ping: PingResult | null = null;\n try {\n ping = await client.ping();\n report.brandId = ping.brandId;\n report.mode = ping.mode;\n checks.push({\n id: \"gateway\",\n title: \"Gateway reachable\",\n status: \"pass\",\n detail: `Reached ${options.baseUrl} (service \"${ping.service}\", ${ping.version}).`,\n });\n checks.push({\n id: \"api-key\",\n title: \"API key accepted\",\n status: \"pass\",\n detail: `Key valid for brand ${ping.brandId} — mode: ${ping.mode}.`,\n });\n } catch (e) {\n const err = e instanceof BowlosApiError ? e : null;\n const code = err?.code ?? BOWLOS_ERROR_CODES.UNKNOWN;\n // A network error (status 0) or a router 404 means no real gateway answered;\n // any other coded envelope means the gateway responded (and judged the key).\n const reached =\n err !== null && err.status !== 0 && code !== BOWLOS_ERROR_CODES.NETWORK_ERROR && code !== BOWLOS_ERROR_CODES.NOT_FOUND;\n\n checks.push({\n id: \"gateway\",\n title: \"Gateway reachable\",\n status: reached ? \"pass\" : \"fail\",\n detail: reached\n ? `Reached ${options.baseUrl}.`\n : code === BOWLOS_ERROR_CODES.NETWORK_ERROR\n ? `Could not reach ${options.baseUrl} (network error).`\n : `No public-API gateway responded at ${options.baseUrl}.`,\n fix: reached\n ? undefined\n : \"Check the base URL, that the Convex deployment is live, and that the public-API routes are deployed.\",\n });\n\n if (code === BOWLOS_ERROR_CODES.RATE_LIMITED) {\n checks.push({\n id: \"api-key\",\n title: \"API key accepted\",\n status: \"pass\",\n detail: \"Key accepted (this probe was rate-limited).\",\n });\n checks.push({\n id: \"rate-limit\",\n title: \"Rate-limit headroom\",\n status: \"warn\",\n detail: `Currently rate-limited${err?.retryAfterSeconds ? ` — retry after ${err.retryAfterSeconds}s` : \"\"}.`,\n fix: \"Back off and retry; raise the key's per-minute limit if your real traffic is higher.\",\n });\n } else if (code === BOWLOS_ERROR_CODES.ORIGIN_NOT_ALLOWED) {\n checks.push({\n id: \"api-key\",\n title: \"API key accepted\",\n status: \"pass\",\n detail: \"Key accepted; the request was blocked on origin.\",\n });\n checks.push({\n id: \"origin\",\n title: \"Origin allow-listed\",\n status: \"fail\",\n detail: \"The request origin is not on the key's allow-list.\",\n fix: `Add your site origin${options.origin ? ` (${options.origin})` : \"\"} to the API key's allowed origins.`,\n });\n } else if (reached) {\n checks.push({\n id: \"api-key\",\n title: \"API key accepted\",\n status: \"fail\",\n detail:\n code === BOWLOS_ERROR_CODES.API_KEY_INVALID || code === BOWLOS_ERROR_CODES.API_KEY_MISSING\n ? \"The gateway rejected the API key.\"\n : `The gateway returned ${code}.`,\n fix: \"Mint or rotate a brand API key in the operator admin (Super-Admin → API keys) and use that value.\",\n });\n } else {\n checks.push({\n id: \"api-key\",\n title: \"API key accepted\",\n status: \"skip\",\n detail: \"Skipped — the gateway wasn't reachable.\",\n });\n }\n }\n\n // 3) origin — only actively verifiable in a browser (Origin is a forbidden\n // header from Node). A successful ping in a browser means the current\n // origin IS allow-listed; otherwise skip with guidance.\n if (!checks.some((c) => c.id === \"origin\")) {\n const browserOrigin =\n typeof window !== \"undefined\" && typeof window.location?.origin === \"string\"\n ? window.location.origin\n : null;\n if (ping !== null && browserOrigin !== null) {\n checks.push({\n id: \"origin\",\n title: \"Origin allow-listed\",\n status: \"pass\",\n detail: `This origin (${browserOrigin}) is allow-listed for the key.`,\n });\n } else {\n checks.push({\n id: \"origin\",\n title: \"Origin allow-listed\",\n status: \"skip\",\n detail: \"Origin allow-listing is enforced only for browser requests, so it can't be verified from a CLI.\",\n fix: `Ensure your deployed site origin${options.origin ? ` (${options.origin})` : \"\"} is on the key's allowed-origins list; load the site and watch for ORIGIN_NOT_ALLOWED.`,\n });\n }\n }\n\n // 4) data plane — a cheap anonymous read proves gateway → manifest → query → scope.\n if (ping !== null && options.skipDataRead !== true) {\n try {\n const data = await client.call<unknown>(\"listPublicCenters\", { brandId: ping.brandId });\n const innerError = typeof data === \"object\" && data !== null && (data as { ok?: boolean }).ok === false;\n checks.push({\n id: \"data-read\",\n title: \"Data passthrough\",\n status: innerError ? \"warn\" : \"pass\",\n detail: innerError\n ? \"Reached the data plane, but listPublicCenters returned an error envelope.\"\n : \"Anonymous read (listPublicCenters) succeeded — gateway → query passthrough works.\",\n fix: innerError ? \"Confirm the brand has at least one published center.\" : undefined,\n });\n } catch (e) {\n const err = e instanceof BowlosApiError ? e : null;\n checks.push({\n id: \"data-read\",\n title: \"Data passthrough\",\n status: \"warn\",\n detail: `An anonymous read failed${err ? ` (${err.code})` : \"\"}.`,\n fix: \"Key + gateway are fine; this read may need a published center or differ by brand. Safe to ignore if your booking reads work.\",\n });\n }\n } else if (ping === null) {\n checks.push({\n id: \"data-read\",\n title: \"Data passthrough\",\n status: \"skip\",\n detail: \"Skipped — needs a reachable gateway.\",\n });\n }\n\n // 5) payments — Stripe Connect status isn't exposed over the public API yet.\n // Honest skip (no faked pass) so the operator knows to verify it elsewhere.\n checks.push({\n id: \"payments\",\n title: \"Payments connected\",\n status: \"skip\",\n detail: \"Stripe Connect status isn't exposed over the public API yet, so the doctor can't verify it here.\",\n fix: \"Confirm the operator's Stripe account is connected + charges-enabled in the admin (Payments → Connect).\",\n });\n\n report.ok = !checks.some((c) => c.status === \"fail\");\n return report;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/doctor.ts"],"names":[],"mappings":";;;AA0DA,IAAM,cAAA,GAAiB,gBAAA;AAIvB,eAAsB,UAAU,OAAA,EAA+C;AAC7E,EAAA,MAAM,SAAwB,EAAC;AAC/B,EAAA,MAAM,SAAuB,EAAE,EAAA,EAAI,MAAM,MAAA,EAAQ,OAAA,EAAS,QAAQ,OAAA,EAAQ;AAG1E,EAAA,MAAM,eAAyB,EAAC;AAChC,EAAA,IAAI,CAAC,OAAA,CAAQ,MAAA,EAAQ,YAAA,CAAa,KAAK,mBAAmB,CAAA;AAC1D,EAAA,IAAI,SAAA,GAAwB,IAAA;AAC5B,EAAA,IAAI;AACF,IAAA,SAAA,GAAY,IAAI,GAAA,CAAI,OAAA,CAAQ,OAAO,CAAA;AAAA,EACrC,CAAA,CAAA,MAAQ;AACN,IAAA,YAAA,CAAa,KAAK,8BAA8B,CAAA;AAAA,EAClD;AACA,EAAA,IAAI,YAAA,CAAa,SAAS,CAAA,EAAG;AAC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AAA,CAAK;AAAA,IACV,EAAA,EAAI,UAAA;AAAA,IACJ,KAAA,EAAO,oBAAA;AAAA,IACP,MAAA,EAAQ,MAAA;AAAA,IACR,MAAA,EAAQ,kGAAA;AAAA,IACR,GAAA,EAAK;AAAA,GACN,CAAA;AAED,EAAA,MAAA,CAAO,EAAA,GAAK,CAAC,MAAA,CAAO,IAAA,CAAK,CAAC,CAAA,KAAM,CAAA,CAAE,WAAW,MAAM,CAAA;AACnD,EAAA,OAAO,MAAA;AACT","file":"chunk-4FL2QYSS.js","sourcesContent":["/**\n * `runDoctor` — a setup-readiness oracle for a site built on @bowlos/reservations.\n *\n * It runs a short sequence of checks against a configured gateway + API key and\n * returns a structured report (pass / warn / fail / skip), each with a one-line\n * fix when it isn't a pass. The point is to make per-site setup self-debuggable\n * — it walks the failure modes a new center site actually hits, in order:\n * config → gateway reachable → API key valid → origin allow-listed → data plane.\n *\n * Framework-agnostic and dependency-free: it builds a `BowlosClient`, leans on\n * `client.ping()` (one call covers reachability + key + origin + rate-limit),\n * and reports honestly — checks it can't run from the current environment are\n * `skip`ped with guidance rather than faked. The `bowlos doctor` CLI is a thin\n * wrapper that pretty-prints the report.\n */\nimport { createBowlosClient } from \"./client\";\nimport { BowlosApiError, BOWLOS_ERROR_CODES } from \"./errors\";\nimport type { FetchLike, PingResult } from \"./types\";\n\nexport type DoctorCheckStatus = \"pass\" | \"warn\" | \"fail\" | \"skip\";\n\nexport interface DoctorCheck {\n /** Stable id (`config` | `gateway` | `api-key` | `origin` | `rate-limit` | `data-read` | `payments`). */\n id: string;\n title: string;\n status: DoctorCheckStatus;\n detail: string;\n /** One-line remediation, present when `status` isn't `pass`. */\n fix?: string;\n}\n\nexport interface DoctorReport {\n /** True when no check failed (warnings and skips are tolerated). */\n ok: boolean;\n checks: DoctorCheck[];\n /** Echoed back so the CLI can show what it probed. */\n baseUrl: string;\n /** From a successful ping — the key's brand + mode. */\n brandId?: string;\n mode?: \"live\" | \"test\";\n}\n\nexport interface DoctorOptions {\n apiKey: string;\n baseUrl: string;\n /**\n * The deployed site origin. Origin allow-listing is enforced by the gateway\n * only for browser requests (Origin is a forbidden header from Node), so this\n * can be actively verified only in a browser; from Node it informs the\n * skip-guidance message.\n */\n origin?: string;\n /** Skip the (anonymous) data-plane read even when a brand is known. */\n skipDataRead?: boolean;\n /** Injectable transport (tests / SSR polyfills). */\n fetch?: FetchLike;\n}\n\nconst GATEWAY_SUFFIX = \"/api/public/v1\";\n\n/** Run the readiness checks and return a structured report. Never throws — every\n * failure mode is captured as a check. */\nexport async function runDoctor(options: DoctorOptions): Promise<DoctorReport> {\n const checks: DoctorCheck[] = [];\n const report: DoctorReport = { ok: true, checks, baseUrl: options.baseUrl };\n\n // 1) config — can we even build a client?\n const configIssues: string[] = [];\n if (!options.apiKey) configIssues.push(\"`apiKey` is empty\");\n let parsedUrl: URL | null = null;\n try {\n parsedUrl = new URL(options.baseUrl);\n } catch {\n configIssues.push(\"`baseUrl` is not a valid URL\");\n }\n if (configIssues.length > 0) {\n checks.push({\n id: \"config\",\n title: \"Client configuration\",\n status: \"fail\",\n detail: `${configIssues.join(\"; \")}.`,\n fix: \"Pass a brand API key and the gateway base URL, e.g. https://<deployment>.convex.site/api/public/v1\",\n });\n report.ok = false;\n return report; // can't probe without a valid client config\n }\n\n const urlMisaimed =\n parsedUrl !== null && !parsedUrl.pathname.replace(/\\/+$/, \"\").endsWith(GATEWAY_SUFFIX);\n checks.push({\n id: \"config\",\n title: \"Client configuration\",\n status: urlMisaimed ? \"warn\" : \"pass\",\n detail: urlMisaimed\n ? `baseUrl \"${options.baseUrl}\" doesn't end with ${GATEWAY_SUFFIX} — it should point at the gateway, not the site root.`\n : \"API key present; base URL well-formed.\",\n fix: urlMisaimed ? `Use the gateway URL, e.g. ${parsedUrl?.origin}${GATEWAY_SUFFIX}` : undefined,\n });\n\n const client = createBowlosClient({\n apiKey: options.apiKey,\n baseUrl: options.baseUrl,\n fetch: options.fetch,\n });\n\n // 2) one ping covers: gateway reachable + key valid + (browser) origin + rate-limit.\n let ping: PingResult | null = null;\n try {\n ping = await client.ping();\n report.brandId = ping.brandId;\n report.mode = ping.mode;\n checks.push({\n id: \"gateway\",\n title: \"Gateway reachable\",\n status: \"pass\",\n detail: `Reached ${options.baseUrl} (service \"${ping.service}\", ${ping.version}).`,\n });\n checks.push({\n id: \"api-key\",\n title: \"API key accepted\",\n status: \"pass\",\n detail: `Key valid for brand ${ping.brandId} — mode: ${ping.mode}.`,\n });\n } catch (e) {\n const err = e instanceof BowlosApiError ? e : null;\n const code = err?.code ?? BOWLOS_ERROR_CODES.UNKNOWN;\n // A network error (status 0) or a router 404 means no real gateway answered;\n // any other coded envelope means the gateway responded (and judged the key).\n const reached =\n err !== null && err.status !== 0 && code !== BOWLOS_ERROR_CODES.NETWORK_ERROR && code !== BOWLOS_ERROR_CODES.NOT_FOUND;\n\n checks.push({\n id: \"gateway\",\n title: \"Gateway reachable\",\n status: reached ? \"pass\" : \"fail\",\n detail: reached\n ? `Reached ${options.baseUrl}.`\n : code === BOWLOS_ERROR_CODES.NETWORK_ERROR\n ? `Could not reach ${options.baseUrl} (network error).`\n : `No public-API gateway responded at ${options.baseUrl}.`,\n fix: reached\n ? undefined\n : \"Check the base URL, that the Convex deployment is live, and that the public-API routes are deployed.\",\n });\n\n if (code === BOWLOS_ERROR_CODES.RATE_LIMITED) {\n checks.push({\n id: \"api-key\",\n title: \"API key accepted\",\n status: \"pass\",\n detail: \"Key accepted (this probe was rate-limited).\",\n });\n checks.push({\n id: \"rate-limit\",\n title: \"Rate-limit headroom\",\n status: \"warn\",\n detail: `Currently rate-limited${err?.retryAfterSeconds ? ` — retry after ${err.retryAfterSeconds}s` : \"\"}.`,\n fix: \"Back off and retry; raise the key's per-minute limit if your real traffic is higher.\",\n });\n } else if (code === BOWLOS_ERROR_CODES.ORIGIN_NOT_ALLOWED) {\n checks.push({\n id: \"api-key\",\n title: \"API key accepted\",\n status: \"pass\",\n detail: \"Key accepted; the request was blocked on origin.\",\n });\n checks.push({\n id: \"origin\",\n title: \"Origin allow-listed\",\n status: \"fail\",\n detail: \"The request origin is not on the key's allow-list.\",\n fix: `Add your site origin${options.origin ? ` (${options.origin})` : \"\"} to the API key's allowed origins.`,\n });\n } else if (reached) {\n checks.push({\n id: \"api-key\",\n title: \"API key accepted\",\n status: \"fail\",\n detail:\n code === BOWLOS_ERROR_CODES.API_KEY_INVALID || code === BOWLOS_ERROR_CODES.API_KEY_MISSING\n ? \"The gateway rejected the API key.\"\n : `The gateway returned ${code}.`,\n fix: \"Mint or rotate a brand API key in the operator admin (Super-Admin → API keys) and use that value.\",\n });\n } else {\n checks.push({\n id: \"api-key\",\n title: \"API key accepted\",\n status: \"skip\",\n detail: \"Skipped — the gateway wasn't reachable.\",\n });\n }\n }\n\n // 3) origin — only actively verifiable in a browser (Origin is a forbidden\n // header from Node). A successful ping in a browser means the current\n // origin IS allow-listed; otherwise skip with guidance.\n if (!checks.some((c) => c.id === \"origin\")) {\n const browserOrigin =\n typeof window !== \"undefined\" && typeof window.location?.origin === \"string\"\n ? window.location.origin\n : null;\n if (ping !== null && browserOrigin !== null) {\n checks.push({\n id: \"origin\",\n title: \"Origin allow-listed\",\n status: \"pass\",\n detail: `This origin (${browserOrigin}) is allow-listed for the key.`,\n });\n } else {\n checks.push({\n id: \"origin\",\n title: \"Origin allow-listed\",\n status: \"skip\",\n detail: \"Origin allow-listing is enforced only for browser requests, so it can't be verified from a CLI.\",\n fix: `Ensure your deployed site origin${options.origin ? ` (${options.origin})` : \"\"} is on the key's allowed-origins list; load the site and watch for ORIGIN_NOT_ALLOWED.`,\n });\n }\n }\n\n // 4) data plane — a cheap anonymous read proves gateway → manifest → query → scope.\n if (ping !== null && options.skipDataRead !== true) {\n try {\n const data = await client.call<unknown>(\"listPublicCenters\", { brandId: ping.brandId });\n const innerError = typeof data === \"object\" && data !== null && (data as { ok?: boolean }).ok === false;\n checks.push({\n id: \"data-read\",\n title: \"Data passthrough\",\n status: innerError ? \"warn\" : \"pass\",\n detail: innerError\n ? \"Reached the data plane, but listPublicCenters returned an error envelope.\"\n : \"Anonymous read (listPublicCenters) succeeded — gateway → query passthrough works.\",\n fix: innerError ? \"Confirm the brand has at least one published center.\" : undefined,\n });\n } catch (e) {\n const err = e instanceof BowlosApiError ? e : null;\n checks.push({\n id: \"data-read\",\n title: \"Data passthrough\",\n status: \"warn\",\n detail: `An anonymous read failed${err ? ` (${err.code})` : \"\"}.`,\n fix: \"Key + gateway are fine; this read may need a published center or differ by brand. Safe to ignore if your booking reads work.\",\n });\n }\n } else if (ping === null) {\n checks.push({\n id: \"data-read\",\n title: \"Data passthrough\",\n status: \"skip\",\n detail: \"Skipped — needs a reachable gateway.\",\n });\n }\n\n // 5) payments — Stripe Connect status isn't exposed over the public API yet.\n // Honest skip (no faked pass) so the operator knows to verify it elsewhere.\n checks.push({\n id: \"payments\",\n title: \"Payments connected\",\n status: \"skip\",\n detail: \"Stripe Connect status isn't exposed over the public API yet, so the doctor can't verify it here.\",\n fix: \"Confirm the operator's Stripe account is connected + charges-enabled in the admin (Payments → Connect).\",\n });\n\n report.ok = !checks.some((c) => c.status === \"fail\");\n return report;\n}\n"]}
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
import { createBooking, createCheckoutPaymentIntent, getCheckoutStatus, abandonCheckout } from './chunk-2RMK6BWO.js';
|
|
2
|
+
import { createBowlosClient, BowlosApiError, BOWLOS_ERROR_CODES } from './chunk-QGTGKNJW.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-NYTGLAQH.js.map
|
|
299
|
+
//# sourceMappingURL=chunk-NYTGLAQH.js.map
|