@bowlos/reservations 0.3.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 +20 -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-4VDDL2CN.js → chunk-NYTGLAQH.js} +4 -4
- package/dist/{chunk-4VDDL2CN.js.map → chunk-NYTGLAQH.js.map} +1 -1
- 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.js +3 -3
- package/dist/index.js +3 -3
- package/dist/react.js +3 -3
- package/package.json +4 -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
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useMemo, useState, type FormEvent } from "react";
|
|
3
|
+
import { loadStripe } from "@stripe/stripe-js";
|
|
4
|
+
import { Elements, PaymentElement, useElements, useStripe } from "@stripe/react-stripe-js";
|
|
5
|
+
import type { PaymentIntentInfo } from "@bowlos/reservations";
|
|
6
|
+
import { STRIPE_PUBLISHABLE_KEY } from "../../lib/bowlos";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* THE PAYMENT HANDOFF.
|
|
10
|
+
*
|
|
11
|
+
* The SDK never loads Stripe.js — `useBookingFlow().preparePayment()` returns a
|
|
12
|
+
* `PaymentIntentInfo` and hands it here. We initialize Stripe.js with the
|
|
13
|
+
* PLATFORM publishable key but scoped to the operator's CONNECTED account
|
|
14
|
+
* (`stripeAccount: connectedAccountId`), so the charge is created directly on
|
|
15
|
+
* the operator's Stripe account — their business name lands on the card
|
|
16
|
+
* statement, receipt, and wallet sheet (the white-label requirement). Then we
|
|
17
|
+
* confirm the PaymentIntent with its `clientSecret`.
|
|
18
|
+
*/
|
|
19
|
+
export function CheckoutForm({
|
|
20
|
+
paymentIntent,
|
|
21
|
+
onPaid,
|
|
22
|
+
}: {
|
|
23
|
+
paymentIntent: PaymentIntentInfo;
|
|
24
|
+
onPaid: () => void;
|
|
25
|
+
}) {
|
|
26
|
+
const stripePromise = useMemo(
|
|
27
|
+
() => loadStripe(STRIPE_PUBLISHABLE_KEY, { stripeAccount: paymentIntent.connectedAccountId }),
|
|
28
|
+
[paymentIntent.connectedAccountId],
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<Elements
|
|
33
|
+
stripe={stripePromise}
|
|
34
|
+
options={{
|
|
35
|
+
clientSecret: paymentIntent.clientSecret,
|
|
36
|
+
// For saved cards across this operator, also pass the SDK's customer
|
|
37
|
+
// session: customerSessionClientSecret: paymentIntent.customerSessionClientSecret
|
|
38
|
+
}}
|
|
39
|
+
>
|
|
40
|
+
<PayForm onPaid={onPaid} />
|
|
41
|
+
</Elements>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function PayForm({ onPaid }: { onPaid: () => void }) {
|
|
46
|
+
const stripe = useStripe();
|
|
47
|
+
const elements = useElements();
|
|
48
|
+
const [submitting, setSubmitting] = useState(false);
|
|
49
|
+
const [message, setMessage] = useState<string | null>(null);
|
|
50
|
+
|
|
51
|
+
async function handleSubmit(e: FormEvent) {
|
|
52
|
+
e.preventDefault();
|
|
53
|
+
if (!stripe || !elements) return;
|
|
54
|
+
setSubmitting(true);
|
|
55
|
+
setMessage(null);
|
|
56
|
+
|
|
57
|
+
// `redirect: "if_required"` keeps the customer on-page for card payments;
|
|
58
|
+
// wallets that need a redirect still work.
|
|
59
|
+
const { error } = await stripe.confirmPayment({ elements, redirect: "if_required" });
|
|
60
|
+
|
|
61
|
+
if (error) {
|
|
62
|
+
setMessage(error.message ?? "Payment failed — please try again.");
|
|
63
|
+
setSubmitting(false);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Paid. The gateway's Stripe webhook materializes the reservation
|
|
68
|
+
// asynchronously, so hand control back so the page can poll for it.
|
|
69
|
+
onPaid();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return (
|
|
73
|
+
<form onSubmit={handleSubmit}>
|
|
74
|
+
<PaymentElement />
|
|
75
|
+
<button type="submit" disabled={!stripe || submitting} style={{ marginTop: "1rem" }}>
|
|
76
|
+
{submitting ? "Paying…" : "Pay now"}
|
|
77
|
+
</button>
|
|
78
|
+
{message && (
|
|
79
|
+
<p role="alert" style={{ color: "crimson" }}>
|
|
80
|
+
{message}
|
|
81
|
+
</p>
|
|
82
|
+
)}
|
|
83
|
+
</form>
|
|
84
|
+
);
|
|
85
|
+
}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useMemo, useState, type FormEvent } from "react";
|
|
3
|
+
import { useAvailability, useBookingPreview, useBookingFlow } from "@bowlos/reservations/react";
|
|
4
|
+
import { availableUnitCount, type CreateBookingArgs } from "@bowlos/reservations";
|
|
5
|
+
import { CENTER_ID, DEMO_PRODUCT_ID, formatCents } from "../../lib/bowlos";
|
|
6
|
+
import { CheckoutForm } from "./checkout-form";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The booking funnel as a single page, driven by `useBookingFlow`:
|
|
10
|
+
* form → startHold → (held) → preparePayment → (awaitingPayment) → pay
|
|
11
|
+
* → startPolling → (confirmed).
|
|
12
|
+
* Availability + the price quote are live reads via the typed hooks.
|
|
13
|
+
*/
|
|
14
|
+
export default function BookPage() {
|
|
15
|
+
const [dateISO, setDateISO] = useState("2026-07-04");
|
|
16
|
+
const [startMinuteOfDay, setStartMinuteOfDay] = useState(18 * 60); // 6:00 PM
|
|
17
|
+
const endMinuteOfDay = startMinuteOfDay + 60;
|
|
18
|
+
const [units, setUnits] = useState(1);
|
|
19
|
+
const [fullName, setFullName] = useState("");
|
|
20
|
+
const [email, setEmail] = useState("");
|
|
21
|
+
|
|
22
|
+
const availability = useAvailability({
|
|
23
|
+
productId: DEMO_PRODUCT_ID,
|
|
24
|
+
dateISO,
|
|
25
|
+
startMinuteOfDay,
|
|
26
|
+
endMinuteOfDay,
|
|
27
|
+
});
|
|
28
|
+
const preview = useBookingPreview({
|
|
29
|
+
centerId: CENTER_ID,
|
|
30
|
+
productId: DEMO_PRODUCT_ID,
|
|
31
|
+
dateISO,
|
|
32
|
+
startMinuteOfDay,
|
|
33
|
+
endMinuteOfDay,
|
|
34
|
+
mode: "per_unit_per_hour",
|
|
35
|
+
units,
|
|
36
|
+
});
|
|
37
|
+
const flow = useBookingFlow();
|
|
38
|
+
|
|
39
|
+
const freeUnits = availability.data ? availableUnitCount(availability.data) : null;
|
|
40
|
+
const quoteCents = preview.data?.totalCentsPerPlan?.[0]?.totalCents ?? null;
|
|
41
|
+
|
|
42
|
+
const bookingArgs: CreateBookingArgs = useMemo(
|
|
43
|
+
() => ({
|
|
44
|
+
centerId: CENTER_ID,
|
|
45
|
+
productId: DEMO_PRODUCT_ID,
|
|
46
|
+
dateISO,
|
|
47
|
+
startMinuteOfDay,
|
|
48
|
+
endMinuteOfDay,
|
|
49
|
+
mode: "per_unit_per_hour",
|
|
50
|
+
units,
|
|
51
|
+
customer: { fullName, email, marketingOptIn: false },
|
|
52
|
+
}),
|
|
53
|
+
[dateISO, startMinuteOfDay, endMinuteOfDay, units, fullName, email],
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
async function onHold(e: FormEvent) {
|
|
57
|
+
e.preventDefault();
|
|
58
|
+
await flow.startHold(bookingArgs);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// ── confirmed ──────────────────────────────────────────────────────────────
|
|
62
|
+
if (flow.status === "confirmed") {
|
|
63
|
+
return (
|
|
64
|
+
<main>
|
|
65
|
+
<h1>You're booked 🎳</h1>
|
|
66
|
+
<p>Confirmation: {flow.reservation?.reservationDisplayId ?? "(materializing…)"}</p>
|
|
67
|
+
<button onClick={flow.reset}>Book another</button>
|
|
68
|
+
</main>
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// ── pay: hand the Connect PaymentIntent to Stripe Elements ───────────────────
|
|
73
|
+
if (flow.status === "awaitingPayment" && flow.paymentIntent) {
|
|
74
|
+
return (
|
|
75
|
+
<main>
|
|
76
|
+
<h1>Payment</h1>
|
|
77
|
+
<p>Paying {formatCents(flow.paymentIntent.amountCents)} to the operator.</p>
|
|
78
|
+
<CheckoutForm paymentIntent={flow.paymentIntent} onPaid={() => flow.startPolling()} />
|
|
79
|
+
<button onClick={flow.abandon} style={{ marginTop: "1rem" }}>
|
|
80
|
+
Cancel
|
|
81
|
+
</button>
|
|
82
|
+
</main>
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// ── held: lane reserved, continue to payment ─────────────────────────────────
|
|
87
|
+
if (flow.status === "held" || flow.status === "preparingPayment") {
|
|
88
|
+
const preparing = flow.status === "preparingPayment";
|
|
89
|
+
return (
|
|
90
|
+
<main>
|
|
91
|
+
<h1>Lane held</h1>
|
|
92
|
+
<p>Your lane is held for a few minutes. Continue to payment to confirm.</p>
|
|
93
|
+
<button onClick={() => flow.preparePayment()} disabled={preparing}>
|
|
94
|
+
{preparing ? "Preparing…" : "Continue to payment →"}
|
|
95
|
+
</button>{" "}
|
|
96
|
+
<button onClick={flow.abandon}>Release hold</button>
|
|
97
|
+
{flow.error && <p role="alert">Error: {flow.error.code}</p>}
|
|
98
|
+
</main>
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// ── form (idle / holding / error) ────────────────────────────────────────────
|
|
103
|
+
const holding = flow.status === "holding";
|
|
104
|
+
return (
|
|
105
|
+
<main>
|
|
106
|
+
<h1>Book a lane</h1>
|
|
107
|
+
<form onSubmit={onHold} style={{ display: "grid", gap: "0.75rem", maxWidth: 360 }}>
|
|
108
|
+
<label>
|
|
109
|
+
Date{" "}
|
|
110
|
+
<input type="date" value={dateISO} onChange={(e) => setDateISO(e.target.value)} />
|
|
111
|
+
</label>
|
|
112
|
+
<label>
|
|
113
|
+
Start{" "}
|
|
114
|
+
<input
|
|
115
|
+
type="time"
|
|
116
|
+
value={minutesToTime(startMinuteOfDay)}
|
|
117
|
+
onChange={(e) => setStartMinuteOfDay(timeToMinutes(e.target.value))}
|
|
118
|
+
/>
|
|
119
|
+
</label>
|
|
120
|
+
<label>
|
|
121
|
+
Lanes{" "}
|
|
122
|
+
<input
|
|
123
|
+
type="number"
|
|
124
|
+
min={1}
|
|
125
|
+
value={units}
|
|
126
|
+
onChange={(e) => setUnits(Math.max(1, Number(e.target.value) || 1))}
|
|
127
|
+
/>
|
|
128
|
+
</label>
|
|
129
|
+
<label>
|
|
130
|
+
Name{" "}
|
|
131
|
+
<input value={fullName} onChange={(e) => setFullName(e.target.value)} required />
|
|
132
|
+
</label>
|
|
133
|
+
<label>
|
|
134
|
+
Email{" "}
|
|
135
|
+
<input type="email" value={email} onChange={(e) => setEmail(e.target.value)} required />
|
|
136
|
+
</label>
|
|
137
|
+
|
|
138
|
+
<p aria-live="polite">
|
|
139
|
+
{availability.loading
|
|
140
|
+
? "Checking availability…"
|
|
141
|
+
: freeUnits !== null
|
|
142
|
+
? `${freeUnits} lane(s) free`
|
|
143
|
+
: availability.error
|
|
144
|
+
? `Availability unavailable (${availability.error.code})`
|
|
145
|
+
: ""}
|
|
146
|
+
</p>
|
|
147
|
+
<p aria-live="polite">
|
|
148
|
+
{preview.loading
|
|
149
|
+
? "Pricing…"
|
|
150
|
+
: quoteCents !== null
|
|
151
|
+
? `Quote: ${formatCents(quoteCents)}`
|
|
152
|
+
: preview.error
|
|
153
|
+
? `Pricing unavailable (${preview.error.code})`
|
|
154
|
+
: ""}
|
|
155
|
+
</p>
|
|
156
|
+
|
|
157
|
+
<button type="submit" disabled={holding || !fullName || !email}>
|
|
158
|
+
{holding ? "Holding…" : "Hold my lane"}
|
|
159
|
+
</button>
|
|
160
|
+
</form>
|
|
161
|
+
{flow.error && (
|
|
162
|
+
<p role="alert">
|
|
163
|
+
Booking error: {flow.error.code} — {flow.error.message}
|
|
164
|
+
</p>
|
|
165
|
+
)}
|
|
166
|
+
</main>
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function minutesToTime(min: number): string {
|
|
171
|
+
const h = Math.floor(min / 60)
|
|
172
|
+
.toString()
|
|
173
|
+
.padStart(2, "0");
|
|
174
|
+
const m = (min % 60).toString().padStart(2, "0");
|
|
175
|
+
return `${h}:${m}`;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function timeToMinutes(t: string): number {
|
|
179
|
+
const [h, m] = t.split(":").map(Number);
|
|
180
|
+
return (h ?? 0) * 60 + (m ?? 0);
|
|
181
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useParams, useRouter } from "next/navigation";
|
|
3
|
+
import { FlashSale } from "@bowlos/reservations/components";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The branded flash-sale page at `/flash/<slug>`. `<FlashSale>` is session-aware:
|
|
7
|
+
* logged-out visitors see the brand, countdown, the operator's pre-login message,
|
|
8
|
+
* and item names with prices locked behind a sign-in form (sale prices never
|
|
9
|
+
* cross the wire until a customer signs in). Once signed in, prices unlock and
|
|
10
|
+
* Book hands off — here we route into the booking flow carrying the flash item
|
|
11
|
+
* (the storefront-handoff pattern, so checkout reuses the one hardened path).
|
|
12
|
+
*/
|
|
13
|
+
export default function FlashSalePage() {
|
|
14
|
+
const params = useParams<{ slug: string }>();
|
|
15
|
+
const router = useRouter();
|
|
16
|
+
return (
|
|
17
|
+
<main>
|
|
18
|
+
<FlashSale
|
|
19
|
+
slug={params.slug}
|
|
20
|
+
onBook={(item) => router.push(`/book?flashItem=${item.id}`)}
|
|
21
|
+
/>
|
|
22
|
+
</main>
|
|
23
|
+
);
|
|
24
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import { Providers } from "./providers";
|
|
3
|
+
|
|
4
|
+
export const metadata = {
|
|
5
|
+
title: "Lucky Strike Lanes",
|
|
6
|
+
description: "Book a lane — demo center site on @bowlos/reservations",
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export default function RootLayout({ children }: { children: ReactNode }) {
|
|
10
|
+
return (
|
|
11
|
+
<html lang="en">
|
|
12
|
+
<body style={{ fontFamily: "system-ui, sans-serif", maxWidth: 640, margin: "2rem auto", padding: "0 1rem" }}>
|
|
13
|
+
<Providers>{children}</Providers>
|
|
14
|
+
</body>
|
|
15
|
+
</html>
|
|
16
|
+
);
|
|
17
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import Link from "next/link";
|
|
2
|
+
|
|
3
|
+
export default function HomePage() {
|
|
4
|
+
return (
|
|
5
|
+
<main>
|
|
6
|
+
<h1>Lucky Strike Lanes</h1>
|
|
7
|
+
<p>
|
|
8
|
+
A reference center website built entirely on <code>@bowlos/reservations</code> — booking,
|
|
9
|
+
Stripe Connect payment, account, and flash sales, all over the public API gateway and
|
|
10
|
+
themed with one <code><BowlosTheme></code>.
|
|
11
|
+
</p>
|
|
12
|
+
<ul>
|
|
13
|
+
<li>
|
|
14
|
+
<Link href="/book">Book a lane →</Link> <small>(lower-level hooks)</small>
|
|
15
|
+
</li>
|
|
16
|
+
<li>
|
|
17
|
+
<Link href="/account">My account →</Link> <small>(<AccountDashboard>)</small>
|
|
18
|
+
</li>
|
|
19
|
+
<li>
|
|
20
|
+
<Link href="/flash/tuesday-blowout">Flash sale →</Link>{" "}
|
|
21
|
+
<small>(<FlashSale>, swap in your slug)</small>
|
|
22
|
+
</li>
|
|
23
|
+
</ul>
|
|
24
|
+
</main>
|
|
25
|
+
);
|
|
26
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useState, type ReactNode } from "react";
|
|
3
|
+
import { BowlosProvider } from "@bowlos/reservations/react";
|
|
4
|
+
import { BowlosTheme } from "@bowlos/reservations/components";
|
|
5
|
+
import { makeBowlosClient } from "../lib/bowlos";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Wraps the app in the SDK provider + a `<BowlosTheme>`. The client is created
|
|
9
|
+
* once (lazy `useState` initializer) and shared via context to every hook below;
|
|
10
|
+
* the theme sets the `--bowlos-*` CSS vars so every drop-in component
|
|
11
|
+
* (`<BookingFlow>`, `<AccountDashboard>`, `<FlashSale>`) picks up this center's
|
|
12
|
+
* accent + radius. Restyle the whole site by editing the `theme` here.
|
|
13
|
+
*/
|
|
14
|
+
export function Providers({ children }: { children: ReactNode }) {
|
|
15
|
+
const [client] = useState(() => makeBowlosClient());
|
|
16
|
+
return (
|
|
17
|
+
<BowlosProvider client={client}>
|
|
18
|
+
<BowlosTheme theme={{ colorPrimary: "#e4002b", radius: "8px" }}>{children}</BowlosTheme>
|
|
19
|
+
</BowlosProvider>
|
|
20
|
+
);
|
|
21
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Copy to .env.local and fill in. All NEXT_PUBLIC_* values are exposed to the
|
|
2
|
+
# browser — that is correct here: the brand API key is a *publishable* key,
|
|
3
|
+
# gated by the gateway's per-key origin allow-list (just like a Stripe
|
|
4
|
+
# publishable key). Never put a secret key in a NEXT_PUBLIC_* var.
|
|
5
|
+
|
|
6
|
+
# Gateway base URL (include the version prefix) + the brand publishable key.
|
|
7
|
+
NEXT_PUBLIC_BOWLOS_BASE_URL=https://your-deployment.convex.site/api/public/v1
|
|
8
|
+
NEXT_PUBLIC_BOWLOS_API_KEY=bpk_live_xxxxxxxxxxxx
|
|
9
|
+
|
|
10
|
+
# The brand + center this site books against, and a bookable product.
|
|
11
|
+
NEXT_PUBLIC_BOWLOS_BRAND_ID=brand_xxxxxxxx
|
|
12
|
+
NEXT_PUBLIC_BOWLOS_CENTER_ID=center_xxxxxxxx
|
|
13
|
+
NEXT_PUBLIC_DEMO_PRODUCT_ID=product_xxxxxxxx
|
|
14
|
+
|
|
15
|
+
# Platform Stripe *publishable* key — used WITH the operator's connected
|
|
16
|
+
# account id (returned by the SDK) so the charge lands on the operator's
|
|
17
|
+
# Stripe account. Use a test key (pk_test_…) for the sandbox proof.
|
|
18
|
+
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_test_xxxxxxxxxxxx
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { createBowlosClient, localStorageTokenStore } from "@bowlos/reservations";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* One configured client for the whole site. The brand API key is *publishable*
|
|
5
|
+
* (gated by the gateway's origin allow-list), so reading it from a public env
|
|
6
|
+
* var is intentional. The session is persisted in localStorage.
|
|
7
|
+
*/
|
|
8
|
+
export function makeBowlosClient() {
|
|
9
|
+
const apiKey = process.env.NEXT_PUBLIC_BOWLOS_API_KEY;
|
|
10
|
+
const baseUrl = process.env.NEXT_PUBLIC_BOWLOS_BASE_URL;
|
|
11
|
+
if (!apiKey || !baseUrl) {
|
|
12
|
+
throw new Error(
|
|
13
|
+
"Missing NEXT_PUBLIC_BOWLOS_API_KEY / NEXT_PUBLIC_BOWLOS_BASE_URL — copy env.example to .env.local.",
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
return createBowlosClient({ apiKey, baseUrl, tokenStore: localStorageTokenStore() });
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** The brand this site books against (brand-scoped reads: account, memberships). */
|
|
20
|
+
export const BRAND_ID = process.env.NEXT_PUBLIC_BOWLOS_BRAND_ID ?? "";
|
|
21
|
+
/** The center this site books against (center-scoped: availability, booking). */
|
|
22
|
+
export const CENTER_ID = process.env.NEXT_PUBLIC_BOWLOS_CENTER_ID ?? "";
|
|
23
|
+
/** A bookable product (in a real site, from `listPublicProducts`). */
|
|
24
|
+
export const DEMO_PRODUCT_ID = process.env.NEXT_PUBLIC_DEMO_PRODUCT_ID ?? "";
|
|
25
|
+
/** Platform Stripe publishable key — used WITH the connected account id. */
|
|
26
|
+
export const STRIPE_PUBLISHABLE_KEY = process.env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY ?? "";
|
|
27
|
+
|
|
28
|
+
/** Format integer cents as USD for display. */
|
|
29
|
+
export function formatCents(cents: number): string {
|
|
30
|
+
return (cents / 100).toLocaleString(undefined, { style: "currency", currency: "USD" });
|
|
31
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** @type {import('next').NextConfig} */
|
|
2
|
+
const nextConfig = {
|
|
3
|
+
// @bowlos/reservations ships dual ESM + CJS with a `/react` subpath, so no
|
|
4
|
+
// transpilePackages / special config is needed. This file exists so the
|
|
5
|
+
// template runs with `next dev` out of the box.
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export default nextConfig;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "bowlos-center-site",
|
|
3
|
+
"private": true,
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"description": "Reference center website built on @bowlos/reservations — the agent-build proof. Standalone Next.js App Router app: book → pay (Stripe Connect handoff) → confirm, plus account reads.",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"dev": "next dev",
|
|
9
|
+
"build": "next build",
|
|
10
|
+
"start": "next start",
|
|
11
|
+
"typecheck": "tsc --noEmit"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@bowlos/reservations": "^0.4.0",
|
|
15
|
+
"@stripe/react-stripe-js": "6.3.0",
|
|
16
|
+
"@stripe/stripe-js": "9.4.0",
|
|
17
|
+
"next": "16.2.4",
|
|
18
|
+
"react": "19.2.4",
|
|
19
|
+
"react-dom": "19.2.4"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@types/react": "19.2.14",
|
|
23
|
+
"@types/react-dom": "19.2.3",
|
|
24
|
+
"typescript": "6.0.3"
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"lib": [
|
|
5
|
+
"ES2023",
|
|
6
|
+
"DOM",
|
|
7
|
+
"DOM.Iterable"
|
|
8
|
+
],
|
|
9
|
+
"module": "ESNext",
|
|
10
|
+
"moduleResolution": "Bundler",
|
|
11
|
+
"jsx": "react-jsx",
|
|
12
|
+
"strict": true,
|
|
13
|
+
"noEmit": true,
|
|
14
|
+
"esModuleInterop": true,
|
|
15
|
+
"allowSyntheticDefaultImports": true,
|
|
16
|
+
"resolveJsonModule": true,
|
|
17
|
+
"isolatedModules": true,
|
|
18
|
+
"skipLibCheck": true,
|
|
19
|
+
"forceConsistentCasingInFileNames": true,
|
|
20
|
+
"plugins": [
|
|
21
|
+
{
|
|
22
|
+
"name": "next"
|
|
23
|
+
}
|
|
24
|
+
],
|
|
25
|
+
"allowJs": true,
|
|
26
|
+
"incremental": true
|
|
27
|
+
},
|
|
28
|
+
"include": [
|
|
29
|
+
"**/*.ts",
|
|
30
|
+
"**/*.tsx",
|
|
31
|
+
".next/types/**/*.ts",
|
|
32
|
+
"next-env.d.ts",
|
|
33
|
+
".next/dev/types/**/*.ts"
|
|
34
|
+
],
|
|
35
|
+
"exclude": [
|
|
36
|
+
"node_modules"
|
|
37
|
+
]
|
|
38
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/errors.ts","../src/client.ts"],"names":[],"mappings":";AAaO,IAAM,kBAAA,GAAqB;AAAA;AAAA,EAEhC,eAAA,EAAiB,iBAAA;AAAA,EACjB,eAAA,EAAiB,iBAAA;AAAA,EACjB,kBAAA,EAAoB,oBAAA;AAAA,EACpB,YAAA,EAAc,cAAA;AAAA;AAAA,EAEd,mBAAA,EAAqB,qBAAA;AAAA,EACrB,aAAA,EAAe,eAAA;AAAA;AAAA,EAEf,iBAAA,EAAmB,mBAAA;AAAA,EACnB,iBAAA,EAAmB,mBAAA;AAAA,EACnB,aAAA,EAAe,eAAA;AAAA,EACf,SAAA,EAAW,WAAA;AAAA,EACX,gBAAA,EAAkB,kBAAA;AAAA,EAClB,sBAAA,EAAwB,wBAAA;AAAA,EACxB,sBAAA,EAAwB,wBAAA;AAAA,EACxB,0BAAA,EAA4B,4BAAA;AAAA,EAC5B,gBAAA,EAAkB,kBAAA;AAAA;AAAA,EAElB,aAAA,EAAe,eAAA;AAAA,EACf,OAAA,EAAS;AACX;AAWO,IAAM,cAAA,GAAN,MAAM,eAAA,SAAuB,KAAA,CAAM;AAAA;AAAA,EAE/B,IAAA;AAAA;AAAA,EAEA,MAAA;AAAA;AAAA,EAEA,iBAAA;AAAA,EAET,YACE,IAAA,EACA,OAAA,EACA,MAAA,EACA,OAAA,GAAiC,EAAC,EAClC;AACA,IAAA,KAAA,CAAM,OAAA,EAAS,QAAQ,KAAA,KAAU,MAAA,GAAY,SAAY,EAAE,KAAA,EAAO,OAAA,CAAQ,KAAA,EAAO,CAAA;A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AmB,aAAA;AAAA,MACnB,iDAAA;AAAA,MACA;AAAA,KACF;AAAA,EACF;AACA,EAAA,OAAO,UAAA,CAAW,KAAA,CAAM,KAAA,EAAO,IAAI,CAAA;AACrC,CAAA;AAGO,SAAS,mBAAmB,MAAA,EAA0C;AAC3E,EAAA,OAAO,IAAI,aAAa,MAAM,CAAA;AAChC","file":"chunk-TCYTNCUL.js","sourcesContent":["/**\n * Error model for the BowlOS Reservations SDK.\n *\n * Every failed gateway call surfaces as a single `BowlosApiError` carrying a\n * stable `code` (string), the HTTP `status`, and — for rate limits — a\n * `retryAfterSeconds`. The gateway normalizes the backend's two error\n * conventions (thrown ConvexError + `{ ok:false }` envelopes) into one JSON\n * shape; this class is the client-side mirror of that shape, so consumers\n * branch on `error.code`, never on message text.\n */\n\n/** Stable error codes the gateway / backend can return. Open set — treat\n * `code` as a string and match against these for known cases. */\nexport const BOWLOS_ERROR_CODES = {\n // Gateway front door\n API_KEY_MISSING: \"API_KEY_MISSING\",\n API_KEY_INVALID: \"API_KEY_INVALID\",\n ORIGIN_NOT_ALLOWED: \"ORIGIN_NOT_ALLOWED\",\n RATE_LIMITED: \"RATE_LIMITED\",\n // Auth\n INVALID_CREDENTIALS: \"INVALID_CREDENTIALS\",\n SIGNUP_FAILED: \"SIGNUP_FAILED\",\n // Shared backend codes\n VALIDATION_FAILED: \"VALIDATION_FAILED\",\n PERMISSION_DENIED: \"PERMISSION_DENIED\",\n SCOPE_REVOKED: \"SCOPE_REVOKED\",\n NOT_FOUND: \"NOT_FOUND\",\n VERSION_CONFLICT: \"VERSION_CONFLICT\",\n PRICING_SNAPSHOT_STALE: \"PRICING_SNAPSHOT_STALE\",\n PAYMENTS_NOT_CONNECTED: \"PAYMENTS_NOT_CONNECTED\",\n CONNECT_ACCOUNT_RESTRICTED: \"CONNECT_ACCOUNT_RESTRICTED\",\n CHECKOUT_EXPIRED: \"CHECKOUT_EXPIRED\",\n // Client-side\n NETWORK_ERROR: \"NETWORK_ERROR\",\n UNKNOWN: \"ERROR\",\n} as const;\n\nexport type BowlosErrorCode =\n | (typeof BOWLOS_ERROR_CODES)[keyof typeof BOWLOS_ERROR_CODES]\n | (string & {});\n\nexport interface BowlosApiErrorOptions {\n retryAfterSeconds?: number;\n cause?: unknown;\n}\n\nexport class BowlosApiError extends Error {\n /** Stable, machine-readable code. Branch on this, not on `message`. */\n readonly code: BowlosErrorCode;\n /** HTTP status (0 for a network failure before any response). */\n readonly status: number;\n /** Seconds to wait before retrying — present only on `RATE_LIMITED`. */\n readonly retryAfterSeconds?: number;\n\n constructor(\n code: BowlosErrorCode,\n message: string,\n status: number,\n options: BowlosApiErrorOptions = {},\n ) {\n super(message, options.cause === undefined ? undefined : { cause: options.cause });\n this.name = \"BowlosApiError\";\n this.code = code;\n this.status = status;\n this.retryAfterSeconds = options.retryAfterSeconds;\n // Restore prototype chain for instanceof across transpile targets.\n Object.setPrototypeOf(this, BowlosApiError.prototype);\n }\n\n /** Too many requests — caller should back off `retryAfterSeconds`. */\n get isRateLimited(): boolean {\n return this.code === BOWLOS_ERROR_CODES.RATE_LIMITED;\n }\n\n /** Bad/expired login. The session could not be established or has lapsed. */\n get isAuthError(): boolean {\n return (\n this.code === BOWLOS_ERROR_CODES.INVALID_CREDENTIALS ||\n this.code === BOWLOS_ERROR_CODES.PERMISSION_DENIED ||\n this.code === BOWLOS_ERROR_CODES.SCOPE_REVOKED\n );\n }\n\n /** Wrong/missing API key or a disallowed origin — a site-config problem,\n * not something the end customer can fix. */\n get isConfigError(): boolean {\n return (\n this.code === BOWLOS_ERROR_CODES.API_KEY_MISSING ||\n this.code === BOWLOS_ERROR_CODES.API_KEY_INVALID ||\n this.code === BOWLOS_ERROR_CODES.ORIGIN_NOT_ALLOWED\n );\n }\n}\n","/**\n * BowlosClient — the framework-agnostic core of the Reservations SDK.\n *\n * It is a thin, typed client for the public API gateway (`/api/public/v1/*`):\n * - sends the brand API key (`X-BowlOS-Api-Key`) on every request,\n * - attaches the customer bearer token on authenticated calls,\n * - parses the `{ ok, data | error }` envelope and throws a typed\n * `BowlosApiError` on failure,\n * - owns the customer session: sign-in / sign-up / link / sign-out, plus\n * a transparent refresh-and-retry-once when a session has expired.\n *\n * The React layer (hooks + components) wraps this; nothing here imports React.\n */\n\nimport { BowlosApiError, BOWLOS_ERROR_CODES } from \"./errors\";\nimport type {\n AuthState,\n BowlosClientConfig,\n Customer,\n FetchLike,\n LinkProfile,\n PingResult,\n TokenStore,\n Tokens,\n} from \"./types\";\n\nclass MemoryTokenStore implements TokenStore {\n private tokens: Tokens | null = null;\n get(): Tokens | null {\n return this.tokens;\n }\n set(tokens: Tokens | null): void {\n this.tokens = tokens;\n }\n}\n\n/** A `TokenStore` backed by `localStorage` for browser apps. No-ops under SSR\n * / environments without `localStorage`. */\nexport function localStorageTokenStore(storageKey = \"bowlos.tokens\"): TokenStore {\n return {\n get(): Tokens | null {\n if (typeof localStorage === \"undefined\") return null;\n const raw = localStorage.getItem(storageKey);\n if (!raw) return null;\n try {\n const parsed = JSON.parse(raw) as Partial<Tokens>;\n return parsed.token && parsed.refreshToken\n ? { token: parsed.token, refreshToken: parsed.refreshToken }\n : null;\n } catch {\n return null;\n }\n },\n set(tokens: Tokens | null): void {\n if (typeof localStorage === \"undefined\") return;\n if (tokens) localStorage.setItem(storageKey, JSON.stringify(tokens));\n else localStorage.removeItem(storageKey);\n },\n };\n}\n\ninterface RawResponse {\n status: number;\n body: unknown;\n retryAfterSeconds?: number;\n}\n\ninterface Envelope {\n ok?: boolean;\n data?: unknown;\n error?: { code?: string; message?: string };\n}\n\n/** Codes that mean \"the API key / origin is wrong\" — refreshing the customer\n * token can't fix these, so never retry them. */\nfunction isConfigErrorCode(code: string): boolean {\n return (\n code === BOWLOS_ERROR_CODES.API_KEY_MISSING ||\n code === BOWLOS_ERROR_CODES.API_KEY_INVALID ||\n code === BOWLOS_ERROR_CODES.ORIGIN_NOT_ALLOWED ||\n code === BOWLOS_ERROR_CODES.RATE_LIMITED\n );\n}\n\n/** Heuristic for \"the customer session lapsed\" — worth one refresh + retry.\n * An expired bearer surfaces as 401, or as PERMISSION_DENIED/SCOPE_REVOKED\n * from the delegated function. Key/origin errors are excluded above. */\nfunction looksLikeExpiredSession(status: number, code: string): boolean {\n if (isConfigErrorCode(code)) return false;\n return (\n status === 401 ||\n code === BOWLOS_ERROR_CODES.PERMISSION_DENIED ||\n code === BOWLOS_ERROR_CODES.SCOPE_REVOKED\n );\n}\n\nexport class BowlosClient {\n private readonly apiKey: string;\n private readonly baseUrl: string;\n private readonly store: TokenStore;\n private readonly fetchFn: FetchLike;\n\n constructor(config: BowlosClientConfig) {\n this.apiKey = config.apiKey;\n this.baseUrl = config.baseUrl.replace(/\\/+$/, \"\");\n this.store = config.tokenStore ?? new MemoryTokenStore();\n this.fetchFn = config.fetch ?? defaultFetch;\n\n if (!this.apiKey) throw new Error(\"BowlosClient: `apiKey` is required.\");\n if (!this.baseUrl) throw new Error(\"BowlosClient: `baseUrl` is required.\");\n }\n\n /** Is there a stored session right now? (Does not validate it server-side.) */\n isAuthenticated(): boolean {\n return this.store.get() !== null;\n }\n\n /** The current token pair, if any (rarely needed directly). */\n getTokens(): Tokens | null {\n return this.store.get();\n }\n\n /**\n * Health + key-validity probe (`GET /ping`). Resolves with the gateway's\n * service info when the API key is accepted; throws a `BowlosApiError` whose\n * `.code` distinguishes the failure (`NETWORK_ERROR`, `API_KEY_INVALID`,\n * `ORIGIN_NOT_ALLOWED`, `RATE_LIMITED`, …). Cheap enough to call on boot, and\n * the basis for `runDoctor`.\n */\n async ping(): Promise<PingResult> {\n const { status, body, retryAfterSeconds } = await this.request(\n \"ping\",\n {},\n this.store.get()?.token,\n \"GET\",\n );\n const env = (body ?? {}) as Envelope;\n if (env.ok === true) return env.data as PingResult;\n\n const code =\n env.error?.code ??\n (status === 429\n ? BOWLOS_ERROR_CODES.RATE_LIMITED\n : status === 404\n ? BOWLOS_ERROR_CODES.NOT_FOUND\n : BOWLOS_ERROR_CODES.UNKNOWN);\n throw new BowlosApiError(\n code,\n env.error?.message ?? `Health ping failed (HTTP ${status}).`,\n status,\n { retryAfterSeconds: code === BOWLOS_ERROR_CODES.RATE_LIMITED ? retryAfterSeconds : undefined },\n );\n }\n\n // ── low-level transport ────────────────────────────────────────────────\n\n private async request(\n name: string,\n args: Record<string, unknown>,\n bearer?: string,\n method: \"GET\" | \"POST\" = \"POST\",\n ): Promise<RawResponse> {\n const headers: Record<string, string> = {\n \"X-BowlOS-Api-Key\": this.apiKey,\n };\n if (method !== \"GET\") headers[\"Content-Type\"] = \"application/json\";\n if (bearer) headers[\"Authorization\"] = `Bearer ${bearer}`;\n\n const init: RequestInit = { method, headers };\n if (method !== \"GET\") init.body = JSON.stringify(args);\n\n let res: Response;\n try {\n res = await this.fetchFn(`${this.baseUrl}/${name}`, init);\n } catch (cause) {\n throw new BowlosApiError(\n BOWLOS_ERROR_CODES.NETWORK_ERROR,\n `Network request to \"${name}\" failed.`,\n 0,\n { cause },\n );\n }\n\n const retryHeader = res.headers.get(\"Retry-After\");\n const retryAfterSeconds = retryHeader ? Number(retryHeader) || undefined : undefined;\n\n let body: unknown = null;\n const text = await res.text();\n if (text) {\n try {\n body = JSON.parse(text);\n } catch {\n // Non-JSON (e.g. the router's plain \"No matching routes found\" 404).\n body = { ok: false, error: { code: BOWLOS_ERROR_CODES.NOT_FOUND, message: text.slice(0, 200) } };\n }\n }\n return { status: res.status, body, retryAfterSeconds };\n }\n\n /**\n * Call a gateway route by name (`POST /api/public/v1/<name>`), returning the\n * unwrapped `data`. Set `{ auth: true }` to attach the bearer token and\n * enable refresh-and-retry on an expired session.\n */\n async call<T = unknown>(\n name: string,\n args: Record<string, unknown> = {},\n opts: { auth?: boolean; method?: \"GET\" | \"POST\" } = {},\n ): Promise<T> {\n return this.callInternal<T>(name, args, opts.auth ?? false, false, opts.method ?? \"POST\");\n }\n\n private async callInternal<T>(\n name: string,\n args: Record<string, unknown>,\n auth: boolean,\n retried: boolean,\n method: \"GET\" | \"POST\",\n ): Promise<T> {\n const bearer = auth ? this.store.get()?.token : undefined;\n const { status, body, retryAfterSeconds } = await this.request(name, args, bearer, method);\n const env = (body ?? {}) as Envelope;\n\n if (env.ok === true) {\n // The data-passthrough routes delegate to functions that return their\n // OWN `{ schema_version, ok, data }` envelope, so the gateway double-wraps\n // them. Detect that inner envelope (uniquely marked by `schema_version`)\n // and unwrap it — surfacing an inner `{ ok:false }` as a thrown error.\n // Auth relays + the raw payment-intent payload have no `schema_version`,\n // so they pass straight through. Forward-compatible if the gateway is ever\n // changed to single-wrap (no inner envelope → nothing to unwrap).\n const data: unknown = env.data;\n if (data !== null && typeof data === \"object\" && \"schema_version\" in data && \"ok\" in data) {\n const inner = data as {\n ok: boolean;\n data?: unknown;\n error?: { code?: string; message?: string };\n };\n if (inner.ok === false) {\n throw new BowlosApiError(\n inner.error?.code ?? BOWLOS_ERROR_CODES.UNKNOWN,\n inner.error?.message ?? `Request to \"${name}\" failed.`,\n status,\n );\n }\n return inner.data as T;\n }\n return data as T;\n }\n\n const code =\n env.error?.code ??\n (status === 429\n ? BOWLOS_ERROR_CODES.RATE_LIMITED\n : status === 404\n ? BOWLOS_ERROR_CODES.NOT_FOUND\n : BOWLOS_ERROR_CODES.UNKNOWN);\n const message = env.error?.message ?? `Request to \"${name}\" failed (HTTP ${status}).`;\n\n if (auth && !retried && this.store.get() && looksLikeExpiredSession(status, code)) {\n const refreshed = await this.tryRefresh();\n if (refreshed) return this.callInternal<T>(name, args, auth, true, method);\n }\n\n throw new BowlosApiError(code, message, status, {\n retryAfterSeconds: code === BOWLOS_ERROR_CODES.RATE_LIMITED ? retryAfterSeconds : undefined,\n });\n }\n\n /** Exchange the stored refresh token for a fresh pair. Clears the session if\n * the refresh token is itself invalid/expired. Returns success. */\n private async tryRefresh(): Promise<boolean> {\n const current = this.store.get();\n if (!current?.refreshToken) return false;\n const { status, body } = await this.request(\"auth/refresh\", {\n refreshToken: current.refreshToken,\n });\n const env = (body ?? {}) as Envelope & { data?: { tokens?: Tokens } };\n if (status >= 200 && status < 300 && env.ok === true && env.data?.tokens) {\n this.store.set(env.data.tokens);\n return true;\n }\n this.store.set(null);\n return false;\n }\n\n // ── auth lifecycle ───────────────────────────────────────────────────────\n\n /** Sign an existing customer in; stores the session on success. */\n async signIn(email: string, password: string): Promise<Tokens> {\n const { tokens } = await this.call<{ tokens: Tokens }>(\"auth/signin\", { email, password });\n this.store.set(tokens);\n return tokens;\n }\n\n /** Create a login (the auth half of sign-up); stores the session. Follow with\n * `link()` to attach the customer profile. */\n async signUp(email: string, password: string): Promise<Tokens> {\n const { tokens } = await this.call<{ tokens: Tokens }>(\"auth/signup\", { email, password });\n this.store.set(tokens);\n return tokens;\n }\n\n /** Link the signed-in auth user to a customer profile at the brand. */\n async link(profile: LinkProfile): Promise<unknown> {\n return this.call(\"auth/link\", { ...profile }, { auth: true });\n }\n\n /** End the session (best-effort server call; always clears locally). */\n async signOut(): Promise<void> {\n try {\n await this.call(\"auth/signout\", {}, { auth: true });\n } catch {\n // Even if the server call fails (expired token, network), drop locally.\n } finally {\n this.store.set(null);\n }\n }\n\n /** Session bootstrap: unauthenticated / authed-no-customer / linked.\n * GET — matches the gateway's `GET /auth/probe` route. */\n async probe(): Promise<AuthState> {\n const { state } = await this.call<{ state: AuthState }>(\n \"auth/probe\",\n {},\n { auth: true, method: \"GET\" },\n );\n return state;\n }\n\n /** The signed-in customer's profile, or null.\n * GET — matches the gateway's `GET /auth/me` route. */\n async me(): Promise<Customer | null> {\n const { customer } = await this.call<{ customer: Customer | null }>(\n \"auth/me\",\n {},\n { auth: true, method: \"GET\" },\n );\n return customer;\n }\n}\n\n/** Default transport: the global fetch, invoked on `globalThis` so browsers\n * don't throw \"Illegal invocation\". Fails only on first use if absent. */\nconst defaultFetch: FetchLike = (input, init) => {\n if (typeof globalThis.fetch !== \"function\") {\n throw new BowlosApiError(\n BOWLOS_ERROR_CODES.NETWORK_ERROR,\n \"No global fetch available. Pass `config.fetch`.\",\n 0,\n );\n }\n return globalThis.fetch(input, init);\n};\n\n/** Create a configured client. */\nexport function createBowlosClient(config: BowlosClientConfig): BowlosClient {\n return new BowlosClient(config);\n}\n"]}
|