@bowlos/reservations 0.34.0 → 0.36.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.
Files changed (43) hide show
  1. package/HEADLESS.md +196 -2
  2. package/README.md +130 -0
  3. package/dist/{account-CsCusw5Z.d.ts → account-DfM2COaz.d.ts} +47 -2
  4. package/dist/{account-Di8nktqp.d.cts → account-oCvYWmO9.d.cts} +47 -2
  5. package/dist/{catalog-DdvLcOrs.d.cts → catalog-DbhdwmnX.d.cts} +4 -1
  6. package/dist/{catalog-DT-ePirK.d.ts → catalog-XkjgPI5C.d.ts} +4 -1
  7. package/dist/{chunk-GIAJQPMM.js → chunk-3JSVEOKG.js} +8 -4
  8. package/dist/chunk-3JSVEOKG.js.map +1 -0
  9. package/dist/{chunk-CAXGTKJQ.js → chunk-TEHRROVY.js} +37 -4
  10. package/dist/chunk-TEHRROVY.js.map +1 -0
  11. package/dist/{chunk-EQH5HDYQ.js → chunk-YAXBZJMI.js} +2 -2
  12. package/dist/{chunk-EQH5HDYQ.js.map → chunk-YAXBZJMI.js.map} +1 -1
  13. package/dist/cli.cjs +5 -3
  14. package/dist/cli.cjs.map +1 -1
  15. package/dist/components.cjs +13 -5
  16. package/dist/components.cjs.map +1 -1
  17. package/dist/components.d.cts +4 -4
  18. package/dist/components.d.ts +4 -4
  19. package/dist/components.js +16 -7
  20. package/dist/components.js.map +1 -1
  21. package/dist/{data-BaHVz6fa.d.cts → data-BJkB-tvM.d.cts} +32 -4
  22. package/dist/{data-BaHVz6fa.d.ts → data-BJkB-tvM.d.ts} +32 -4
  23. package/dist/index.cjs +28 -2
  24. package/dist/index.cjs.map +1 -1
  25. package/dist/index.d.cts +4 -4
  26. package/dist/index.d.ts +4 -4
  27. package/dist/index.js +22 -5
  28. package/dist/index.js.map +1 -1
  29. package/dist/payments.d.cts +1 -1
  30. package/dist/payments.d.ts +1 -1
  31. package/dist/{react-DImwA9C9.d.ts → react-0MyyTtE4.d.ts} +2 -2
  32. package/dist/{react-DK1elmLQ.d.cts → react-CWAG4cW0.d.cts} +2 -2
  33. package/dist/react.cjs +43 -3
  34. package/dist/react.cjs.map +1 -1
  35. package/dist/react.d.cts +23 -7
  36. package/dist/react.d.ts +23 -7
  37. package/dist/react.js +3 -3
  38. package/package.json +3 -2
  39. package/templates/center-site/app/book/page.tsx +11 -23
  40. package/templates/center-site/app/catalog/page.tsx +16 -9
  41. package/templates/center-site/package.json +1 -1
  42. package/dist/chunk-CAXGTKJQ.js.map +0 -1
  43. package/dist/chunk-GIAJQPMM.js.map +0 -1
package/HEADLESS.md CHANGED
@@ -22,6 +22,95 @@ All hooks come from `@bowlos/reservations/react`; the framework-agnostic twins
22
22
 
23
23
  ## Capability map
24
24
 
25
+ ### Saved cards and signed-in password changes (v0.36.0)
26
+
27
+ These APIs require a signed-in customer. Card arguments are
28
+ `{ brandId, centerId }`; remove/default also require `paymentMethodId`.
29
+ The gateway pins scope to the API key. A brand-wide key requires an explicit
30
+ center; a center-scoped key supplies its center. Cards are per connected Stripe
31
+ account and belong only to the caller's customer at that Brand.
32
+
33
+ | Core helper | React hook | Gateway POST route |
34
+ | --- | --- | --- |
35
+ | `listSavedCards` | `useSavedCards(scope, options?)` | `listMyPaymentMethods` |
36
+ | `createCardSetup` | `useCreateCardSetup()` | `createSetupIntentForAddingCard` |
37
+ | `removeSavedCard` | `useRemoveCard()` | `detachPaymentMethod` |
38
+ | `setDefaultCard` | `useSetDefaultCard()` | `setDefaultPaymentMethod` |
39
+ | `changePassword` | `useChangePassword()` | `changeMyPassword` |
40
+
41
+ Core helpers take `(client, args)`; data methods are not on `BowlosClient`. Import helpers
42
+ and types from `@bowlos/reservations`, hooks from `@bowlos/reservations/react`.
43
+ Mutation hooks expose `{ run, data, loading, error, reset }`. `useSavedCards`
44
+ returns `{ data, loading, error, refetch }`; call `refetch()` after confirming a
45
+ setup, removing a card, or changing the default. The list returns
46
+ `{ methods: SavedCard[], chargeable }`; each card has `id`, `brand`, `last4`,
47
+ `expMonth`, `expYear`, `isDefault`. Disable Add when `chargeable` is false;
48
+ viewing/removing cards remains available when the account cannot charge.
49
+
50
+ #### Add a card with Stripe.js
51
+
52
+ ```ts
53
+ import { loadStripe } from "@stripe/stripe-js";
54
+ import { createCardSetup, listSavedCards } from "@bowlos/reservations";
55
+
56
+ const setup = await createCardSetup(client, { brandId, centerId });
57
+ // Always use this response's key/account, including for a flagged Test Account.
58
+ const stripe = await loadStripe(setup.publishableKey, {
59
+ stripeAccount: setup.stripeAccount,
60
+ });
61
+ if (!stripe) throw new Error("Stripe could not load");
62
+ const elements = stripe.elements();
63
+ const card = elements.create("card");
64
+ card.mount("#card-element");
65
+ // On your site's Save card submit:
66
+ const { error } = await stripe.confirmCardSetup(setup.clientSecret, {
67
+ payment_method: { card },
68
+ });
69
+ if (error) throw error;
70
+ // Reload saved cards after confirmation; unmount the element when leaving.
71
+ const cards = await listSavedCards(client, { brandId, centerId });
72
+ ```
73
+
74
+ For a Payment Element, initialize `stripe.elements({ clientSecret:
75
+ setup.clientSecret })`, mount its `payment` element, and call
76
+ `stripe.confirmSetup({ elements, confirmParams: { return_url },
77
+ redirect: "if_required" })`; handle errors and any redirect completion before
78
+ refreshing. `CardSetupResult` also exposes `stripeMode: "test" | "live"`,
79
+ and `merchantDisplayName`. No ephemeral key or Stripe customer ID is returned.
80
+ Never substitute a build-time Stripe key or a different connected account.
81
+ Mode follows center state and `customers.isTestAccount`, matching checkout; API key mode does not override it. Setup intents are limited to 5/hour/customer (`RATE_LIMITED`, 429).
82
+
83
+ #### Change password
84
+
85
+ ```ts
86
+ import { changePassword } from "@bowlos/reservations";
87
+
88
+ await changePassword(client, { currentPassword, newPassword });
89
+ // All sessions are invalidated; show your sign-in screen.
90
+ ```
91
+
92
+ The current password is mandatory. The new password uses the same
93
+ `validatePassword` rules as signup. On success the SDK core helper and
94
+ hook clear the local session with best-effort sign-out. Failed changes preserve
95
+ it. An OAuth-only account cannot use password change.
96
+
97
+ Match `BowlosApiError.code` (hook `error.code`), never message text:
98
+
99
+ - `PASSWORD_TOO_WEAK` (400): new password fails signup strength rules.
100
+ - `CURRENT_PASSWORD_INCORRECT` (400): current password is incorrect.
101
+ - `CURRENT_PASSWORD_REQUIRED` (400): enter the current password; a stale session cannot omit it.
102
+ - `RATE_LIMITED` (429): password attempt lockout or setup-intent budget exhausted.
103
+ - `NOT_FOUND` (404): no password login exists.
104
+ - `PERMISSION_DENIED` (403): no signed-in customer or another customer's card.
105
+ - `KEY_SCOPE_MISMATCH` (403): body scope conflicts with the API key.
106
+ - `VALIDATION_FAILED` (400): missing center context, center outside the Brand, unavailable saved cards,
107
+ or a card used by an active membership (update that membership first).
108
+ - `PAYMENTS_NOT_CONNECTED` / `CONNECT_ACCOUNT_RESTRICTED`: adding a card is unavailable.
109
+
110
+ Exported types: `SavedCardScope`, `SavedCardArgs`, `SavedCard`,
111
+ `SavedCardsResult`, `CardSetupResult`, `ChangePasswordArgs`.
112
+
113
+
25
114
  ### 1. Login gate — browse + price open, **log in to purchase** (v0.27.0)
26
115
 
27
116
  Online booking mirrors the white-label site exactly: **anyone can browse the
@@ -34,7 +123,11 @@ kills conversion.
34
123
  > **Changed in v0.27.0.** Before this, the whole funnel was gated on `signedIn`.
35
124
  > Now: render the form + fetch pricing for anonymous visitors; gate at Review.
36
125
  > The server enforces login on the booking-create mutation regardless (a
37
- > headless site can't accidentally allow an anonymous purchase).
126
+ > headless site can't accidentally allow an anonymous purchase). Minting
127
+ > the payment intent, cancelling that intent, and abandoning the checkout
128
+ > also reject a signed-out caller. The checkout `refToken` identifies the
129
+ > attempt; it is not a session. Pay-link tokens for an existing reservation
130
+ > stay token-gated and do not require a session.
38
131
 
39
132
  What this means for your build:
40
133
 
@@ -189,10 +282,22 @@ const preview = useBookingPreview(
189
282
  { centerId, productId, dateISO, startMinuteOfDay, endMinuteOfDay, mode: pricingMode, ...countField(count), addons: selectedAddons },
190
283
  { enabled: dateISO !== "", auth: signedIn }, // v0.27.0: anonymous → standard; auth → member rate + credit
191
284
  );
192
- const freeUnits = availability.data ? availableUnitCount(availability.data) : null;
285
+ const availableUnits = availability.data ? availableUnitCount(availability.data) : null;
193
286
  const quoteCents = preview.data?.totalCentsPerPlan?.[0]?.totalCents ?? null; // includes add-ons + tax + credit
287
+
288
+ // v0.35.0: the operator-configured noun for this attraction (a lane / room /
289
+ // bay / bowler / game) — NEVER hardcode "lane". Both `useAvailability` and
290
+ // `useBookingPreview` now return `unitNoun: { singular, plural }`. Pick by count.
291
+ const noun = (n: { singular: string; plural: string } | undefined, count: number, fb = { singular: "lane", plural: "lanes" }) =>
292
+ count === 1 ? (n ?? fb).singular : (n ?? fb).plural;
293
+ // availability line: `${availableUnits} ${noun(availability.data?.unitNoun, availableUnits)} available`
294
+ // review/order line: `${count} ${noun(preview.data?.unitNoun, count)}` // e.g. "1 room", "2 rooms"
194
295
  ```
195
296
 
297
+ > ⚠️ **`availableUnitCount` / `useAvailability` count UNOCCUPIED units — this is an availability signal, NOT "free of charge."** Label it **"available"** or **"open"** (e.g. `"2 lanes available"`). **Never render it as "free"** — `"2 lanes free"` sitting next to a price reads as *no cost* and misleads the customer. The drop-in `<BookingFlow>` renders `"N lanes available"` for exactly this reason; match that word in your own UI.
298
+
299
+ > 🏷️ **Never hardcode the unit noun.** A party room, VIP bay, or axe-throwing target is NOT a "lane". As of **v0.35.0** the gateway sends `unitNoun: { singular, plural }` on both `useAvailability` and `useBookingPreview`, resolved from the operator's admin config and the pricing mode (unit → lane/room, per-person → bowler/guest, per-game → game). Render `{count} {singular|plural}` — count-aware — so a single room reads **"1 room"**, not **"1 lanes"**. Older gateways omit `unitNoun`; fall back to `"lane"/"lanes"`.
300
+
196
301
  ### 5. Start time — a dropdown of bookable slots (not a free-form clock)
197
302
 
198
303
  `useStartTimes` returns the minute-of-day slots that are within open hours, clear
@@ -813,6 +918,8 @@ Headless function twins (non-React): `getPackage(client, { packageId })`,
813
918
 
814
919
  ## Buying a one-time membership
815
920
 
921
+ **Unreleased / backend:** Self-cancel now stops future Stripe billing at period end; no package change required.
922
+
816
923
  A one-time membership is the same **direct-purchase** lifecycle as a game pass —
817
924
  `useMembershipPurchase` on the shared `usePurchase` engine, no inventory hold, no
818
925
  date/time. Mint a connected-account PaymentIntent → pay with `<BowlosPaymentForm>`
@@ -940,6 +1047,12 @@ subscriptions materialize via webhook; read `getMyMemberships(client, { brandId
940
1047
 
941
1048
  ## Booking a flash-sale item at the sale price (headless)
942
1049
 
1050
+ As of **v0.36.0**, the server applies the event's `loyaltyDiscountEnabled` toggle
1051
+ for signed-in members, using the higher of earned and complimentary tier rank.
1052
+ Use checkout totals for the Review and Pay steps. `breakdown.tierDiscountCents`
1053
+ (reservations) and `tierDiscountCents`/`tierDiscountLabel` (flat preview responses)
1054
+ explain savings already included in the subtotal; do not subtract them again.
1055
+
943
1056
  A flash-sale reservation item books through a **purpose-built path** — never
944
1057
  the regular booking calendar (the sale price only exists on the sale's own
945
1058
  dates/blocks). All reads/creates are signed-in only.
@@ -1119,6 +1232,40 @@ as done and re-read the list.
1119
1232
  `getMyGameCards(client, { brandId })`, etc. (generate the key with
1120
1233
  `generateIdempotencyKey()`).
1121
1234
 
1235
+ ## Frozen purchase description on reservation reads (backend-additive)
1236
+
1237
+ The reservation-detail reads — `useMyReservationDetail` / `getMyReservationDetail`
1238
+ (signed-in account) and the receipt read `getReservationByDisplayId` — now return
1239
+ **frozen, point-in-time purchase info** on `snapshot`, so a headless *My bookings*
1240
+ or *receipt* screen can show the same "what's included" line and reconciling tax
1241
+ that the operator admin, confirmation email, and check-in show. This is a
1242
+ **gateway-additive** change (no SDK version bump; these reads are generic
1243
+ `<T = unknown>`, so you simply widen your own type):
1244
+
1245
+ ```ts
1246
+ type ReservationSnapshot = {
1247
+ finalCents: number;
1248
+ // …existing breakdown (baseSubtotalCents, addonLineItems, appliedDiscount*, reservationFee*)…
1249
+ // Added:
1250
+ purchaseSummary: string | null; // one-line "what's included" (render verbatim)
1251
+ pricePlanName: string | null; // e.g. "Thursday Special" (null = standard rate)
1252
+ pricePlanDescription: string | null;
1253
+ appliedDiscountLabel: string | null; // human label; prefer over the raw discount source
1254
+ shoesIncluded: boolean | null;
1255
+ taxTotalCents: number | null; // show so Total reconciles (base − discount + tax + fee)
1256
+ taxLines: Array<{ label: string; taxableBaseCents: number; taxCents: number }> | null;
1257
+ };
1258
+ ```
1259
+
1260
+ **Point-in-time:** these reflect what the customer bought when they booked — a
1261
+ later product/plan rename or price edit does NOT change a past booking's summary.
1262
+ **Legacy:** reservations booked before this ships return `null` for the new keys;
1263
+ fall back to the product name + whatever breakdown the snapshot already had (never
1264
+ re-derive the summary from current config). **Render guidance:** show
1265
+ `purchaseSummary` as the headline line under the product name, `pricePlanName` as a
1266
+ "Special" chip when non-null, and a tax row from `taxTotalCents` (label from
1267
+ `taxLines[0].label`) above the total.
1268
+
1122
1269
  ## Wallet passes — hide the add-to-wallet once a pass is stale
1123
1270
 
1124
1271
  `useMyPasses({ brandId })` (core: `getMyPasses(client, { brandId })`) lists the
@@ -1351,7 +1498,54 @@ Headless sites do **not** get these from a version bump — apply them by hand.
1351
1498
  | **0.31.0** | **Per-weekday package start times** — `getPublicPackage` / `usePackage` now return `startTimesByWeekday: [{ dayOfWeek, startTimes }]` (a package can run at different times each weekday — Sun 2:30/5:00, M–Th 5:30, Fri 5:30/8:00, Sat 12/3/6). New exported helpers `resolvePackageStartTimesForWeekday(pkg, weekday)` + `weekdayForDateISO(dateISO)` + `usesPerWeekdayStartTimes(pkg)` fold the new map and the legacy `allowedStartTimes`/`applicabilityDays` into one call. **Also: retail pricing page** — new `useRetailPricing({ centerId })` + `listRetailPricing` core fn return a center's walk-in (matrix) rates grouped by attraction + opted-in "website specials"; reference `<PricingTable>` component. | "Buying a package" §2 — replace the hand-rolled `allowedStartTimes`/`applicabilityDays` slot filter with `resolvePackageStartTimesForWeekday(pkg, weekdayForDateISO(dateISO))` (→ `null` continuous, `[]` not bookable that day, else the exact minutes; still intersect with open hours). The buy mutation enforces the same rule, so a stale time still rejects `VALIDATION_FAILED`. **Plus** the new "Retail pricing page" section — read `useRetailPricing` for a price-list page (or drop in `<PricingTable centerId>`); render-only, not a booking surface. Both additive — continuous/legacy packages + sites without a pricing page are unchanged. |
1352
1499
 
1353
1500
  | **0.32.0** | **Flash sale for any sellable type** — packages, memberships (one-time), game passes, and event tickets can now be put on a flash sale and bought at the sale price (reservations already had the dedicated flow). `useFlashSale` items carry `sourceType`/`sourceId`/`buyPath`; every flat buy + preview hook/fn (`useGameCardPurchase`/`useGameCardPreview`, `usePackage*`, `useMembership*`, `useEventTicket*` + the `previewX`/`createXOrder` core fns) gained an optional `flashSaleItemId`. | "Flat items on a flash sale" sub-section under "Booking a flash-sale item". Read `useFlashSale`, route flat items by `sourceType`, and pass `flashSaleItemId: item.id` into BOTH the preview and the create so Review + charge both show the sale price. The server validates Live + match, so a stale id is rejected. Additive — omit it and the buy is full price; reservation flash is unchanged. |
1501
+ | **0.35.0** | **Per-product unit noun** — `useAvailability` (`AvailabilityResult`) and `useBookingPreview` (`BookingQuote`) now return `unitNoun: { singular, plural }`, the operator-configured word for the booked thing (a lane / party room / VIP bay / bowler / game), resolved by pricing mode. Fixes the funnel hardcoding "lanes" for non-bowling attractions (a party room rendered "1 lanes"). | §4 "Live availability + price" — read `unitNoun` off both hooks and render `{count} {singular\|plural}` **count-aware** for the availability line AND the review/order line; never hardcode "lane"/"lanes". Additive: older gateways omit `unitNoun` → fall back to `"lane"/"lanes"`. The drop-in `<BookingFlow>` now does this automatically (and fixes the "1 lanes" → "1 lane"/"1 room" grammar). |
1354
1502
  | **0.34.0** | **Package add-ons: `included` vs `optional` (revenue-blocking bug fix).** New exported `PackageAddon`/`PackageAddonMode` types + helpers `splitPackageAddons(addons)` (→ `{ included, optional }` for rendering) and `toOptionalAddonsInput(addons, qtyMap)` (builds the `optionalAddons` request from a quantity map, keeping ONLY `mode:"optional"` add-ons, flooring to positive ints, capping at `maxOptionalQuantity`, dropping included/unknown ids). Fixes the field bug where a site sent an `included` add-on in `optionalAddons` → `VALIDATION_FAILED — Add-on "X" is not optional` ("Couldn't load the total"). | "Buying a package" §1 — render add-ons via `splitPackageAddons` (included read-only, optional as steppers) and build the request via `toOptionalAddonsInput` instead of hand-mapping. Also surface the envelope `error.message` on failure. Purely additive: the add-on `mode` field was already returned; these are typed helpers so the mistake is impossible. |
1355
1503
 
1356
1504
  When you add the next release here, add its row **and** any new capability-map
1357
1505
  section in the same PR.
1506
+
1507
+
1508
+ ### v0.36.0 — Saved cards and current-password verification (2026-10-30, unpublished)
1509
+
1510
+ Headless sites can add account pages using `useSavedCards`,
1511
+ `useCreateCardSetup`, `useRemoveCard`, `useSetDefaultCard`, and
1512
+ `useChangePassword` (or the corresponding core helpers).
1513
+ Follow the saved-card capability map above to confirm the SetupIntent with its
1514
+ returned Stripe key/account, then refetch cards. Password forms must collect
1515
+ `currentPassword` and `newPassword`; handle `CURRENT_PASSWORD_INCORRECT`, `CURRENT_PASSWORD_REQUIRED`, and
1516
+ `PASSWORD_TOO_WEAK`, and return to sign-in after success. No UI component adoption
1517
+ is required.
1518
+
1519
+ Sites on `^0.35.x` must change their dependency range to `^0.36.0` by hand;
1520
+ pre-1.0 caret ranges do not cross minor versions.
1521
+
1522
+ Password changes sign out every device. Offer “Forgot your current password?”
1523
+ beside the current-password field and start the existing email-code reset flow:
1524
+ `client.requestPasswordReset(email)`, then `client.resetPassword(email, code, newPassword)`.
1525
+ The reset page must remain accessible while signed in. Handle change-password
1526
+ errors inline using the new `CURRENT_PASSWORD_INCORRECT` /
1527
+ `CURRENT_PASSWORD_REQUIRED` codes; they are not auth errors and never refresh or
1528
+ clear tokens. Existing `INVALID_CREDENTIALS` and `PERMISSION_DENIED` behavior on
1529
+ other routes is unchanged.
1530
+
1531
+ Includes the unpublished 0.35.1 flash-sale fixes:
1532
+
1533
+ Flash checkout now honors `loyaltyDiscountEnabled` for signed-in tier members,
1534
+ including complimentary tiers. Reservation sessions round once per lane before
1535
+ multiplying by lanes; flat buys round per item. A one-cent floor applies before
1536
+ promo codes, tax, and the Center fee. Membership setup fees and renewals are unchanged.
1537
+
1538
+ Headless adoption: use the server checkout amount; never recompute a charge from
1539
+ public sale prices. `createFlashSaleBooking().breakdown.tierDiscountCents` reports
1540
+ savings already included in `baseSubtotalCents` and `amountDueCents`. Display it as
1541
+ an informational discount line; do not subtract it a second time. Existing sales
1542
+ with the toggle enabled begin applying this benefit when the Convex change deploys.
1543
+
1544
+
1545
+ Checkout replay policy (P8 review fix): retries with the same checkout key retain
1546
+ the attempt's original amount and tier discount, even if the customer's tier
1547
+ changes. Render the checkout response amount/breakdown rather than a new preview;
1548
+ the PaymentIntent uses that same pinned amount. Flash reservation retries whose
1549
+ frozen preview is missing or inconsistent return `CHECKOUT_EXPIRED`: request a
1550
+ fresh quote and generate a new key. This also applies after an interruption
1551
+ between persisting the attempt and creating its PaymentIntent.
package/README.md CHANGED
@@ -216,6 +216,15 @@ unknown ids, so sending an included add-on (→ `VALIDATION_FAILED — Add-on "X
216
216
  not optional`) can't happen. Surface the envelope `error.message` on failure. See
217
217
  "Buying a package" in `HEADLESS.md`.
218
218
 
219
+ **Per-product unit noun (v0.35.0):** `useAvailability` and `useBookingPreview`
220
+ now return `unitNoun: { singular, plural }` — the operator-configured word for
221
+ the booked thing (a lane / party room / VIP bay / bowler / game), resolved by
222
+ pricing mode. Render `{count} {singular|plural}` **count-aware** on both the
223
+ availability line and the review/order line; never hardcode "lane"/"lanes" (a
224
+ party room is not a "lane"). Older gateways omit it → fall back to `"lane"/
225
+ "lanes"`. The drop-in `<BookingFlow>` uses it automatically. See §4 in
226
+ `HEADLESS.md`.
227
+
219
228
  ## Drop-in components (`@bowlos/reservations/components`)
220
229
 
221
230
  > These are a **reference / fast-start**, not the delivered product. Center sites
@@ -451,3 +460,124 @@ try {
451
460
  ## License
452
461
 
453
462
  MIT
463
+
464
+
465
+ ## Saved cards and signed-in password changes (v0.36.0)
466
+
467
+ These APIs require a signed-in customer. Card arguments are
468
+ `{ brandId, centerId }`; remove/default also require `paymentMethodId`.
469
+ The gateway pins scope to the API key. A brand-wide key requires an explicit
470
+ center; a center-scoped key supplies its center. Cards are per connected Stripe
471
+ account and belong only to the caller's customer at that Brand.
472
+
473
+ | Core helper | React hook | Gateway POST route |
474
+ | --- | --- | --- |
475
+ | `listSavedCards` | `useSavedCards(scope, options?)` | `listMyPaymentMethods` |
476
+ | `createCardSetup` | `useCreateCardSetup()` | `createSetupIntentForAddingCard` |
477
+ | `removeSavedCard` | `useRemoveCard()` | `detachPaymentMethod` |
478
+ | `setDefaultCard` | `useSetDefaultCard()` | `setDefaultPaymentMethod` |
479
+ | `changePassword` | `useChangePassword()` | `changeMyPassword` |
480
+
481
+ Core helpers take `(client, args)`; data methods are not on `BowlosClient`. Import helpers
482
+ and types from `@bowlos/reservations`, hooks from `@bowlos/reservations/react`.
483
+ Mutation hooks expose `{ run, data, loading, error, reset }`. `useSavedCards`
484
+ returns `{ data, loading, error, refetch }`; call `refetch()` after confirming a
485
+ setup, removing a card, or changing the default. The list returns
486
+ `{ methods: SavedCard[], chargeable }`; each card has `id`, `brand`, `last4`,
487
+ `expMonth`, `expYear`, `isDefault`. Disable Add when `chargeable` is false;
488
+ viewing/removing cards remains available when the account cannot charge.
489
+
490
+ ### Add a card with Stripe.js
491
+
492
+ ```ts
493
+ import { loadStripe } from "@stripe/stripe-js";
494
+ import { createCardSetup, listSavedCards } from "@bowlos/reservations";
495
+
496
+ const setup = await createCardSetup(client, { brandId, centerId });
497
+ // Always use this response's key/account, including for a flagged Test Account.
498
+ const stripe = await loadStripe(setup.publishableKey, {
499
+ stripeAccount: setup.stripeAccount,
500
+ });
501
+ if (!stripe) throw new Error("Stripe could not load");
502
+ const elements = stripe.elements();
503
+ const card = elements.create("card");
504
+ card.mount("#card-element");
505
+ // On your site's Save card submit:
506
+ const { error } = await stripe.confirmCardSetup(setup.clientSecret, {
507
+ payment_method: { card },
508
+ });
509
+ if (error) throw error;
510
+ // Reload saved cards after confirmation; unmount the element when leaving.
511
+ const cards = await listSavedCards(client, { brandId, centerId });
512
+ ```
513
+
514
+ For a Payment Element, initialize `stripe.elements({ clientSecret:
515
+ setup.clientSecret })`, mount its `payment` element, and call
516
+ `stripe.confirmSetup({ elements, confirmParams: { return_url },
517
+ redirect: "if_required" })`; handle errors and any redirect completion before
518
+ refreshing. `CardSetupResult` also exposes `stripeMode: "test" | "live"`,
519
+ and `merchantDisplayName`. No ephemeral key or Stripe customer ID is returned.
520
+ Never substitute a build-time Stripe key or a different connected account.
521
+ Mode follows center state and `customers.isTestAccount`, matching checkout; API key mode does not override it. Setup intents are limited to 5/hour/customer (`RATE_LIMITED`, 429).
522
+
523
+ ### Change password
524
+
525
+ ```ts
526
+ import { changePassword } from "@bowlos/reservations";
527
+
528
+ await changePassword(client, { currentPassword, newPassword });
529
+ // All sessions are invalidated; show your sign-in screen.
530
+ ```
531
+
532
+ The current password is mandatory. The new password uses the same
533
+ `validatePassword` rules as signup. On success the SDK core helper and
534
+ hook clear the local session with best-effort sign-out. Failed changes preserve
535
+ it. An OAuth-only account cannot use password change.
536
+
537
+ Match `BowlosApiError.code` (hook `error.code`), never message text:
538
+
539
+ - `PASSWORD_TOO_WEAK` (400): new password fails signup strength rules.
540
+ - `CURRENT_PASSWORD_INCORRECT` (400): current password is incorrect.
541
+ - `CURRENT_PASSWORD_REQUIRED` (400): enter the current password; a stale session cannot omit it.
542
+ - `RATE_LIMITED` (429): password attempt lockout or setup-intent budget exhausted.
543
+ - `NOT_FOUND` (404): no password login exists.
544
+ - `PERMISSION_DENIED` (403): no signed-in customer or another customer's card.
545
+ - `KEY_SCOPE_MISMATCH` (403): body scope conflicts with the API key.
546
+ - `VALIDATION_FAILED` (400): missing center context, center outside the Brand, unavailable saved cards,
547
+ or a card used by an active membership (update that membership first).
548
+ - `PAYMENTS_NOT_CONNECTED` / `CONNECT_ACCOUNT_RESTRICTED`: adding a card is unavailable.
549
+
550
+ Exported types: `SavedCardScope`, `SavedCardArgs`, `SavedCard`,
551
+ `SavedCardsResult`, `CardSetupResult`, `ChangePasswordArgs`.
552
+
553
+ ### v0.36.0 — Saved cards and change password (2026-10-30, unpublished)
554
+
555
+ Adds the five core helpers and five React hooks above, typed
556
+ SetupIntent configuration, scoped gateway access, and current-password
557
+ verification. Existing headless sites add their own card/password forms using
558
+ [the headless guide](./HEADLESS.md).
559
+
560
+ Sites on `^0.35.x` must change their dependency range to `^0.36.0` by hand;
561
+ pre-1.0 caret ranges do not cross minor versions.
562
+
563
+ Password changes sign out every device. Offer “Forgot your current password?”
564
+ beside the current-password field and start the existing email-code reset flow:
565
+ `client.requestPasswordReset(email)`, then `client.resetPassword(email, code, newPassword)`.
566
+ The reset page must remain accessible while signed in. Handle change-password
567
+ errors inline using the new `CURRENT_PASSWORD_INCORRECT` /
568
+ `CURRENT_PASSWORD_REQUIRED` codes; they are not auth errors and never refresh or
569
+ clear tokens. Existing `INVALID_CREDENTIALS` and `PERMISSION_DENIED` behavior on
570
+ other routes is unchanged.
571
+
572
+ Includes the unpublished 0.35.1 flash-sale fixes:
573
+
574
+ Flash checkout now honors `loyaltyDiscountEnabled` for signed-in tier members,
575
+ including complimentary tiers. Reservation sessions round once per lane before
576
+ multiplying by lanes; flat buys round per item. A one-cent floor applies before
577
+ promo codes, tax, and the Center fee. Membership setup fees and renewals are unchanged.
578
+
579
+ Headless adoption: use the server checkout amount; never recompute a charge from
580
+ public sale prices. `createFlashSaleBooking().breakdown.tierDiscountCents` reports
581
+ savings already included in `baseSubtotalCents` and `amountDueCents`. Display it as
582
+ an informational discount line; do not subtract it a second time. Existing sales
583
+ with the toggle enabled begin applying this benefit when the Convex change deploys.
@@ -1,4 +1,4 @@
1
- import { g as BowlosClient } from './data-BaHVz6fa.js';
1
+ import { g as BowlosClient } from './data-BJkB-tvM.js';
2
2
 
3
3
  /**
4
4
  * Typed account + flash reads for @bowlos/reservations.
@@ -145,6 +145,8 @@ interface FlashSaleBookingResult {
145
145
  amountDueCents: number;
146
146
  holdExpiresAt: number;
147
147
  breakdown: {
148
+ /** Tier savings already removed from baseSubtotalCents; do not subtract again. */
149
+ tierDiscountCents: number;
148
150
  baseSubtotalCents: number;
149
151
  reservationFeeCents: number;
150
152
  reservationFeeLabel: string | null;
@@ -161,5 +163,48 @@ interface FlashSaleBookingResult {
161
163
  * list — never the regular booking calendar.
162
164
  */
163
165
  declare function createFlashSaleBooking(client: BowlosClient, args: CreateFlashSaleBookingArgs): Promise<FlashSaleBookingResult>;
166
+ /** Saved cards belong to the active location's connected Stripe account. */
167
+ type SavedCardScope = {
168
+ brandId: string;
169
+ centerId: string;
170
+ };
171
+ type SavedCardArgs = SavedCardScope & {
172
+ paymentMethodId: string;
173
+ };
174
+ interface SavedCard {
175
+ id: string;
176
+ brand: string;
177
+ last4: string;
178
+ expMonth: number;
179
+ expYear: number;
180
+ isDefault: boolean;
181
+ }
182
+ interface SavedCardsResult {
183
+ methods: SavedCard[];
184
+ chargeable: boolean;
185
+ }
186
+ interface CardSetupResult {
187
+ clientSecret: string;
188
+ publishableKey: string;
189
+ stripeAccount: string;
190
+ stripeMode: "test" | "live";
191
+ merchantDisplayName: string;
192
+ }
193
+ type ChangePasswordArgs = {
194
+ currentPassword: string;
195
+ newPassword: string;
196
+ };
197
+ declare function listSavedCards(client: BowlosClient, args: SavedCardScope): Promise<SavedCardsResult>;
198
+ declare function createCardSetup(client: BowlosClient, args: SavedCardScope): Promise<CardSetupResult>;
199
+ declare function removeSavedCard(client: BowlosClient, args: SavedCardArgs): Promise<{
200
+ detached: boolean;
201
+ }>;
202
+ declare function setDefaultCard(client: BowlosClient, args: SavedCardArgs): Promise<{
203
+ ok: boolean;
204
+ }>;
205
+ /** Success invalidates all sessions; discard local tokens and show sign-in. */
206
+ declare function changePassword(client: BowlosClient, args: ChangePasswordArgs): Promise<{
207
+ ok: true;
208
+ }>;
164
209
 
165
- export { previewGameCardCancellation as A, type BrandScoped as B, type CancelPreview as C, previewPackageOrderCancellation as D, type EventOrderDetailArgs as E, type FlashBookingOptionsArgs as F, type GameCardCancelArgs as G, previewReservationCancellation as H, type MembershipDetailArgs as M, type OrderCancelArgs as O, type ReservationCancelArgs as R, type CancelResult as a, type CreateFlashSaleBookingArgs as b, type FlashSaleArgs as c, type FlashSaleBookingResult as d, type FlashSalesArgs as e, type MyGameCard as f, type ReservationDetailArgs as g, cancelMyEventOrder as h, cancelMyGameCard as i, cancelMyPackageOrder as j, cancelMyReservation as k, createFlashSaleBooking as l, getFlashSale as m, getFlashSaleBookingOptions as n, getFlashSales as o, getMyCredits as p, getMyEventOrder as q, getMyEventOrders as r, getMyGameCards as s, getMyLoyalty as t, getMyMembershipDetail as u, getMyMemberships as v, getMyPasses as w, getMyReservationDetail as x, getMyReservations as y, previewEventOrderCancellation as z };
210
+ export { getMyLoyalty as A, type BrandScoped as B, type CancelPreview as C, getMyMembershipDetail as D, type EventOrderDetailArgs as E, type FlashBookingOptionsArgs as F, type GameCardCancelArgs as G, getMyMemberships as H, getMyPasses as I, getMyReservationDetail as J, getMyReservations as K, listSavedCards as L, type MembershipDetailArgs as M, previewEventOrderCancellation as N, type OrderCancelArgs as O, previewGameCardCancellation as P, previewPackageOrderCancellation as Q, type ReservationCancelArgs as R, type SavedCard as S, previewReservationCancellation as T, removeSavedCard as U, setDefaultCard as V, type CancelResult as a, type CardSetupResult as b, type ChangePasswordArgs as c, type CreateFlashSaleBookingArgs as d, type FlashSaleArgs as e, type FlashSaleBookingResult as f, type FlashSalesArgs as g, type MyGameCard as h, type ReservationDetailArgs as i, type SavedCardArgs as j, type SavedCardScope as k, type SavedCardsResult as l, cancelMyEventOrder as m, cancelMyGameCard as n, cancelMyPackageOrder as o, cancelMyReservation as p, changePassword as q, createCardSetup as r, createFlashSaleBooking as s, getFlashSale as t, getFlashSaleBookingOptions as u, getFlashSales as v, getMyCredits as w, getMyEventOrder as x, getMyEventOrders as y, getMyGameCards as z };
@@ -1,4 +1,4 @@
1
- import { g as BowlosClient } from './data-BaHVz6fa.cjs';
1
+ import { g as BowlosClient } from './data-BJkB-tvM.cjs';
2
2
 
3
3
  /**
4
4
  * Typed account + flash reads for @bowlos/reservations.
@@ -145,6 +145,8 @@ interface FlashSaleBookingResult {
145
145
  amountDueCents: number;
146
146
  holdExpiresAt: number;
147
147
  breakdown: {
148
+ /** Tier savings already removed from baseSubtotalCents; do not subtract again. */
149
+ tierDiscountCents: number;
148
150
  baseSubtotalCents: number;
149
151
  reservationFeeCents: number;
150
152
  reservationFeeLabel: string | null;
@@ -161,5 +163,48 @@ interface FlashSaleBookingResult {
161
163
  * list — never the regular booking calendar.
162
164
  */
163
165
  declare function createFlashSaleBooking(client: BowlosClient, args: CreateFlashSaleBookingArgs): Promise<FlashSaleBookingResult>;
166
+ /** Saved cards belong to the active location's connected Stripe account. */
167
+ type SavedCardScope = {
168
+ brandId: string;
169
+ centerId: string;
170
+ };
171
+ type SavedCardArgs = SavedCardScope & {
172
+ paymentMethodId: string;
173
+ };
174
+ interface SavedCard {
175
+ id: string;
176
+ brand: string;
177
+ last4: string;
178
+ expMonth: number;
179
+ expYear: number;
180
+ isDefault: boolean;
181
+ }
182
+ interface SavedCardsResult {
183
+ methods: SavedCard[];
184
+ chargeable: boolean;
185
+ }
186
+ interface CardSetupResult {
187
+ clientSecret: string;
188
+ publishableKey: string;
189
+ stripeAccount: string;
190
+ stripeMode: "test" | "live";
191
+ merchantDisplayName: string;
192
+ }
193
+ type ChangePasswordArgs = {
194
+ currentPassword: string;
195
+ newPassword: string;
196
+ };
197
+ declare function listSavedCards(client: BowlosClient, args: SavedCardScope): Promise<SavedCardsResult>;
198
+ declare function createCardSetup(client: BowlosClient, args: SavedCardScope): Promise<CardSetupResult>;
199
+ declare function removeSavedCard(client: BowlosClient, args: SavedCardArgs): Promise<{
200
+ detached: boolean;
201
+ }>;
202
+ declare function setDefaultCard(client: BowlosClient, args: SavedCardArgs): Promise<{
203
+ ok: boolean;
204
+ }>;
205
+ /** Success invalidates all sessions; discard local tokens and show sign-in. */
206
+ declare function changePassword(client: BowlosClient, args: ChangePasswordArgs): Promise<{
207
+ ok: true;
208
+ }>;
164
209
 
165
- export { previewGameCardCancellation as A, type BrandScoped as B, type CancelPreview as C, previewPackageOrderCancellation as D, type EventOrderDetailArgs as E, type FlashBookingOptionsArgs as F, type GameCardCancelArgs as G, previewReservationCancellation as H, type MembershipDetailArgs as M, type OrderCancelArgs as O, type ReservationCancelArgs as R, type CancelResult as a, type CreateFlashSaleBookingArgs as b, type FlashSaleArgs as c, type FlashSaleBookingResult as d, type FlashSalesArgs as e, type MyGameCard as f, type ReservationDetailArgs as g, cancelMyEventOrder as h, cancelMyGameCard as i, cancelMyPackageOrder as j, cancelMyReservation as k, createFlashSaleBooking as l, getFlashSale as m, getFlashSaleBookingOptions as n, getFlashSales as o, getMyCredits as p, getMyEventOrder as q, getMyEventOrders as r, getMyGameCards as s, getMyLoyalty as t, getMyMembershipDetail as u, getMyMemberships as v, getMyPasses as w, getMyReservationDetail as x, getMyReservations as y, previewEventOrderCancellation as z };
210
+ export { getMyLoyalty as A, type BrandScoped as B, type CancelPreview as C, getMyMembershipDetail as D, type EventOrderDetailArgs as E, type FlashBookingOptionsArgs as F, type GameCardCancelArgs as G, getMyMemberships as H, getMyPasses as I, getMyReservationDetail as J, getMyReservations as K, listSavedCards as L, type MembershipDetailArgs as M, previewEventOrderCancellation as N, type OrderCancelArgs as O, previewGameCardCancellation as P, previewPackageOrderCancellation as Q, type ReservationCancelArgs as R, type SavedCard as S, previewReservationCancellation as T, removeSavedCard as U, setDefaultCard as V, type CancelResult as a, type CardSetupResult as b, type ChangePasswordArgs as c, type CreateFlashSaleBookingArgs as d, type FlashSaleArgs as e, type FlashSaleBookingResult as f, type FlashSalesArgs as g, type MyGameCard as h, type ReservationDetailArgs as i, type SavedCardArgs as j, type SavedCardScope as k, type SavedCardsResult as l, cancelMyEventOrder as m, cancelMyGameCard as n, cancelMyPackageOrder as o, cancelMyReservation as p, changePassword as q, createCardSetup as r, createFlashSaleBooking as s, getFlashSale as t, getFlashSaleBookingOptions as u, getFlashSales as v, getMyCredits as w, getMyEventOrder as x, getMyEventOrders as y, getMyGameCards as z };
@@ -1,4 +1,4 @@
1
- import { g as BowlosClient } from './data-BaHVz6fa.cjs';
1
+ import { g as BowlosClient } from './data-BJkB-tvM.cjs';
2
2
 
3
3
  /**
4
4
  * Error model for the BowlOS Reservations SDK.
@@ -17,6 +17,9 @@ declare const BOWLOS_ERROR_CODES: {
17
17
  readonly API_KEY_INVALID: "API_KEY_INVALID";
18
18
  readonly ORIGIN_NOT_ALLOWED: "ORIGIN_NOT_ALLOWED";
19
19
  readonly RATE_LIMITED: "RATE_LIMITED";
20
+ readonly PASSWORD_TOO_WEAK: "PASSWORD_TOO_WEAK";
21
+ readonly CURRENT_PASSWORD_INCORRECT: "CURRENT_PASSWORD_INCORRECT";
22
+ readonly CURRENT_PASSWORD_REQUIRED: "CURRENT_PASSWORD_REQUIRED";
20
23
  readonly INVALID_CREDENTIALS: "INVALID_CREDENTIALS";
21
24
  readonly SIGNUP_FAILED: "SIGNUP_FAILED";
22
25
  readonly VALIDATION_FAILED: "VALIDATION_FAILED";
@@ -1,4 +1,4 @@
1
- import { g as BowlosClient } from './data-BaHVz6fa.js';
1
+ import { g as BowlosClient } from './data-BJkB-tvM.js';
2
2
 
3
3
  /**
4
4
  * Error model for the BowlOS Reservations SDK.
@@ -17,6 +17,9 @@ declare const BOWLOS_ERROR_CODES: {
17
17
  readonly API_KEY_INVALID: "API_KEY_INVALID";
18
18
  readonly ORIGIN_NOT_ALLOWED: "ORIGIN_NOT_ALLOWED";
19
19
  readonly RATE_LIMITED: "RATE_LIMITED";
20
+ readonly PASSWORD_TOO_WEAK: "PASSWORD_TOO_WEAK";
21
+ readonly CURRENT_PASSWORD_INCORRECT: "CURRENT_PASSWORD_INCORRECT";
22
+ readonly CURRENT_PASSWORD_REQUIRED: "CURRENT_PASSWORD_REQUIRED";
20
23
  readonly INVALID_CREDENTIALS: "INVALID_CREDENTIALS";
21
24
  readonly SIGNUP_FAILED: "SIGNUP_FAILED";
22
25
  readonly VALIDATION_FAILED: "VALIDATION_FAILED";
@@ -6,6 +6,9 @@ var BOWLOS_ERROR_CODES = {
6
6
  ORIGIN_NOT_ALLOWED: "ORIGIN_NOT_ALLOWED",
7
7
  RATE_LIMITED: "RATE_LIMITED",
8
8
  // Auth
9
+ PASSWORD_TOO_WEAK: "PASSWORD_TOO_WEAK",
10
+ CURRENT_PASSWORD_INCORRECT: "CURRENT_PASSWORD_INCORRECT",
11
+ CURRENT_PASSWORD_REQUIRED: "CURRENT_PASSWORD_REQUIRED",
9
12
  INVALID_CREDENTIALS: "INVALID_CREDENTIALS",
10
13
  SIGNUP_FAILED: "SIGNUP_FAILED",
11
14
  // Shared backend codes
@@ -86,7 +89,8 @@ function isConfigErrorCode(code) {
86
89
  return code === BOWLOS_ERROR_CODES.API_KEY_MISSING || code === BOWLOS_ERROR_CODES.API_KEY_INVALID || code === BOWLOS_ERROR_CODES.ORIGIN_NOT_ALLOWED || code === BOWLOS_ERROR_CODES.RATE_LIMITED;
87
90
  }
88
91
  function looksLikeExpiredSession(status, code) {
89
- if (isConfigErrorCode(code)) return false;
92
+ if (isConfigErrorCode(code) || code === BOWLOS_ERROR_CODES.CURRENT_PASSWORD_INCORRECT || code === BOWLOS_ERROR_CODES.CURRENT_PASSWORD_REQUIRED)
93
+ return false;
90
94
  return status === 401 || code === BOWLOS_ERROR_CODES.PERMISSION_DENIED || code === BOWLOS_ERROR_CODES.SCOPE_REVOKED;
91
95
  }
92
96
  var BowlosClient = class {
@@ -196,7 +200,7 @@ var BowlosClient = class {
196
200
  }
197
201
  const code = env.error?.code ?? (status === 429 ? BOWLOS_ERROR_CODES.RATE_LIMITED : status === 404 ? BOWLOS_ERROR_CODES.NOT_FOUND : BOWLOS_ERROR_CODES.UNKNOWN);
198
202
  const message = env.error?.message ?? `Request to "${name}" failed (HTTP ${status}).`;
199
- if (auth && !retried && this.store.get() && looksLikeExpiredSession(status, code)) {
203
+ if (name !== "changeMyPassword" && auth && !retried && this.store.get() && looksLikeExpiredSession(status, code)) {
200
204
  const refreshed = await this.tryRefresh();
201
205
  if (refreshed) return this.callInternal(name, args, auth, true, method);
202
206
  }
@@ -470,5 +474,5 @@ function abandonCheckout(client, refToken) {
470
474
  }
471
475
 
472
476
  export { BOWLOS_ERROR_CODES, BowlosApiError, BowlosClient, abandonCheckout, availableUnitCount, bookingPreview, checkAvailability, createBooking, createBowlosClient, createCheckoutPaymentIntent, createEventTicketOrder, createGameCardOrder, createMembershipOrder, createMembershipSubscriptionOrder, createPackageOrder, generateIdempotencyKey, getCheckoutStatus, getEventTicketStatus, getGameCardStatus, getMembershipStatus, getPackageStatus, listAddons, listStartTimes, localStorageTokenStore, previewEventTicket, previewGameCard, previewMembership, previewMembershipSubscription, previewPackage };
473
- //# sourceMappingURL=chunk-GIAJQPMM.js.map
474
- //# sourceMappingURL=chunk-GIAJQPMM.js.map
477
+ //# sourceMappingURL=chunk-3JSVEOKG.js.map
478
+ //# sourceMappingURL=chunk-3JSVEOKG.js.map