@relai-team/access-sdk 0.8.1 → 0.10.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 CHANGED
@@ -148,9 +148,22 @@ month, then $1.00 each). Redeem via `overrideCode` on the open.
148
148
 
149
149
  If the app is set to **Relai checkout** in the Relai portal (the default for
150
150
  new apps), the platform charges the end user at the door and this SDK handles
151
- the whole exchange. A payment-gated open answers 402 `payment_required`; with
152
- the optional peer `@stripe/stripe-react-native` installed, `unlock()` presents
153
- the **standard Stripe Payment Sheet** and retries the open by itself:
151
+ the whole exchange. A payment-gated open answers 402 `payment_required`, and
152
+ `unlock()` presents the **standard Stripe Payment Sheet** and retries the open
153
+ by itself.
154
+
155
+ Install the peer and hand the module to the client. **You import it, the SDK
156
+ does not** — React Native resolves imports at build time, so a specifier
157
+ written inside this package would force Stripe on every app, including the
158
+ ones that want their own payment UI:
159
+
160
+ ```ts
161
+ import * as Stripe from "@stripe/stripe-react-native";
162
+
163
+ const relai = new RelaiClient({ publishableKey: "pk_sandbox_…", stripe: Stripe });
164
+ ```
165
+
166
+ From then on, paying is invisible in your code:
154
167
 
155
168
  ```ts
156
169
  // Exactly the same call as a free open. If payment is due, the sheet
@@ -158,11 +171,35 @@ the **standard Stripe Payment Sheet** and retries the open by itself:
158
171
  await relai.unlock({ orderId: order.id, intent: Intents.Occupy, transport });
159
172
  ```
160
173
 
174
+ Leave `stripe` out and payment-gated opens throw instead of presenting, with
175
+ the reason on the console and the sheet parameters in `error.details`.
176
+
161
177
  Prices are configured in the portal (per app, with per-Exchange-Zone
162
178
  overrides), in two styles:
163
179
 
164
- - **Prepaid**: one flat price collected at the drop-off; it covers the whole
165
- order, including self re-opens and the pick-up.
180
+ - **Prepaid**: one price collected at the drop-off; it covers the whole order,
181
+ including self re-opens and the pick-up.
182
+
183
+ An app may offer up to **ten pick-up windows**, each a length of time with its
184
+ own price, and the end user picks one. Read the menu off the Exchange Zone and
185
+ pass the chosen `hours` back:
186
+
187
+ ```ts
188
+ const ez = await relai.exchangeZones.get(ezId);
189
+ const windows = ez.end_user_pricing?.pickup_windows ?? [];
190
+ // e.g. [{ hours: 2, price_cents: 300, total_cents: 371 }, { hours: 24, … }]
191
+
192
+ const order = await relai.orders.create({
193
+ exchangeZoneId: ez.id,
194
+ pickupWindowHours: windows[1]?.hours, // what the user tapped
195
+ });
196
+ ```
197
+
198
+ `total_cents` already includes the Platform Fee and Processing lines, so show
199
+ it as-is. Omit `pickupWindowHours` and the shortest (cheapest) window applies.
200
+ An `hours` the app does not offer is rejected. When `pickup_windows` is absent
201
+ the app offers no choice and `prepaid_cents` is the price. Late fees start when
202
+ the chosen window runs out, and `order.pickup_window_hours` reports it back.
166
203
  - **Pay-as-you-go** (self orders via `Intents.OccupyLongTerm`): a base at
167
204
  drop-off, which may be zero (then the sheet only saves the card), plus an
168
205
  hourly rate collected when the pick-up open is requested. Guests cannot
@@ -181,7 +218,7 @@ order.checkout?.drop_off_paid; // true once the drop-off charge settled
181
218
  ```
182
219
 
183
220
  To build your own payment UI instead, pass `presentPaymentSheet: false` to
184
- `unlock()` (or simply do not install the Stripe peer) and catch
221
+ `unlock()` (or simply omit `stripe`) and catch
185
222
  `RelaiApiError` with code `payment_required`: `error.details` carries the
186
223
  sheet parameters (`client_secret`, `publishable_key`, customer + ephemeral
187
224
  key when signed in, and a breakdown of item, Platform Fee, and Processing
@@ -0,0 +1,36 @@
1
+ // src/payment-sheet.ts
2
+ function asPaymentRequired(details) {
3
+ if (!details || typeof details["client_secret"] !== "string" || typeof details["kind"] !== "string") return null;
4
+ return details;
5
+ }
6
+ async function presentRelaiPaymentSheet(details, stripe) {
7
+ if (!details.client_secret || !details.publishable_key) {
8
+ console.warn(
9
+ "[relai] Cannot present the payment sheet: the server did not return a client secret or publishable key."
10
+ );
11
+ return false;
12
+ }
13
+ if (!stripe) {
14
+ console.warn(
15
+ '[relai] Cannot present the payment sheet: no Stripe module was provided. Install @stripe/stripe-react-native and pass it to the client:\n import * as Stripe from "@stripe/stripe-react-native";\n new RelaiClient({ publishableKey, stripe: Stripe });\nThe SDK cannot import it for you: a bundled specifier would make React Native resolve Stripe at build time, breaking apps that deliberately do not install it.'
16
+ );
17
+ return false;
18
+ }
19
+ await stripe.initStripe({ publishableKey: details.publishable_key });
20
+ const { error: initError } = await stripe.initPaymentSheet({
21
+ merchantDisplayName: "Relai Access",
22
+ ...details.setup ? { setupIntentClientSecret: details.client_secret } : { paymentIntentClientSecret: details.client_secret },
23
+ ...details.customer_id && details.ephemeral_key ? { customerId: details.customer_id, customerEphemeralKeySecret: details.ephemeral_key } : {}
24
+ });
25
+ if (initError) {
26
+ console.warn("[relai] Stripe rejected the payment sheet parameters:", initError);
27
+ return false;
28
+ }
29
+ const { error } = await stripe.presentPaymentSheet();
30
+ if (error && error.code !== "Canceled") {
31
+ console.warn("[relai] The payment sheet did not complete:", error);
32
+ }
33
+ return !error;
34
+ }
35
+
36
+ export { asPaymentRequired, presentRelaiPaymentSheet };
@@ -1,2 +1 @@
1
1
  export { RelaiApiError, RelaiError, RelaiLateFeeDue, RelaiMissingKeyError, RelaiTransportError, RelaiUnlockRejected } from './chunk-MNXTMLX2.js';
2
- import './chunk-3RG5ZIWI.js';
package/dist/index.cjs CHANGED
@@ -2,12 +2,6 @@
2
2
 
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
6
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
7
- }) : x)(function(x) {
8
- if (typeof require !== "undefined") return require.apply(this, arguments);
9
- throw Error('Dynamic require of "' + x + '" is not supported');
10
- });
11
5
  var __esm = (fn, res) => function __init() {
12
6
  return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
13
7
  };
@@ -89,12 +83,17 @@ function asPaymentRequired(details) {
89
83
  if (!details || typeof details["client_secret"] !== "string" || typeof details["kind"] !== "string") return null;
90
84
  return details;
91
85
  }
92
- async function presentRelaiPaymentSheet(details) {
93
- if (!details.client_secret || !details.publishable_key) return false;
94
- let stripe;
95
- try {
96
- stripe = __require("@stripe/stripe-react-native");
97
- } catch {
86
+ async function presentRelaiPaymentSheet(details, stripe) {
87
+ if (!details.client_secret || !details.publishable_key) {
88
+ console.warn(
89
+ "[relai] Cannot present the payment sheet: the server did not return a client secret or publishable key."
90
+ );
91
+ return false;
92
+ }
93
+ if (!stripe) {
94
+ console.warn(
95
+ '[relai] Cannot present the payment sheet: no Stripe module was provided. Install @stripe/stripe-react-native and pass it to the client:\n import * as Stripe from "@stripe/stripe-react-native";\n new RelaiClient({ publishableKey, stripe: Stripe });\nThe SDK cannot import it for you: a bundled specifier would make React Native resolve Stripe at build time, breaking apps that deliberately do not install it.'
96
+ );
98
97
  return false;
99
98
  }
100
99
  await stripe.initStripe({ publishableKey: details.publishable_key });
@@ -103,8 +102,14 @@ async function presentRelaiPaymentSheet(details) {
103
102
  ...details.setup ? { setupIntentClientSecret: details.client_secret } : { paymentIntentClientSecret: details.client_secret },
104
103
  ...details.customer_id && details.ephemeral_key ? { customerId: details.customer_id, customerEphemeralKeySecret: details.ephemeral_key } : {}
105
104
  });
106
- if (initError) return false;
105
+ if (initError) {
106
+ console.warn("[relai] Stripe rejected the payment sheet parameters:", initError);
107
+ return false;
108
+ }
107
109
  const { error } = await stripe.presentPaymentSheet();
110
+ if (error && error.code !== "Canceled") {
111
+ console.warn("[relai] The payment sheet did not complete:", error);
112
+ }
108
113
  return !error;
109
114
  }
110
115
  var init_payment_sheet = __esm({
@@ -355,6 +360,7 @@ var OrdersModule = class {
355
360
  if (input.recipient !== void 0) body["recipient"] = input.recipient;
356
361
  if (input.recipientUserId !== void 0) body["recipient_user_id"] = input.recipientUserId;
357
362
  if (input.recipientEmail !== void 0) body["recipient_email"] = input.recipientEmail;
363
+ if (input.pickupWindowHours !== void 0) body["pickup_window_hours"] = input.pickupWindowHours;
358
364
  if (input.promotionCode !== void 0) body["promotion_code"] = input.promotionCode;
359
365
  if (input.metadata !== void 0) body["metadata"] = input.metadata;
360
366
  return this.http.request({ method: "POST", path: "/orders", body });
@@ -592,6 +598,7 @@ var DEFAULT_BASE_URL = "https://access.relai.us/api/v1";
592
598
  var RelaiClient = class {
593
599
  constructor(options) {
594
600
  if (!options.publishableKey && !options.secretKey) throw new exports.RelaiMissingKeyError();
601
+ this.stripe = options.stripe;
595
602
  const storage = options.tokenStorage ?? new MemoryTokenStorage();
596
603
  let auth;
597
604
  const httpConfig = {
@@ -641,7 +648,7 @@ var RelaiClient = class {
641
648
  if (input.presentPaymentSheet !== false && err instanceof RelaiApiError2 && err.code === "payment_required") {
642
649
  const { asPaymentRequired: asPaymentRequired2, presentRelaiPaymentSheet: presentRelaiPaymentSheet2 } = await Promise.resolve().then(() => (init_payment_sheet(), payment_sheet_exports));
643
650
  const details = asPaymentRequired2(err.details);
644
- if (!details || !await presentRelaiPaymentSheet2(details)) throw err;
651
+ if (!details || !await presentRelaiPaymentSheet2(details, this.stripe)) throw err;
645
652
  open = await requestOpen();
646
653
  } else {
647
654
  throw err;
package/dist/index.d.cts CHANGED
@@ -101,6 +101,8 @@ interface Order extends OrderStatusFields {
101
101
  } | null;
102
102
  /** When the pick-up window closes; late fees escalate past it. Null = no window. */
103
103
  pickup_window_expires_at: string | null;
104
+ /** The pick-up window this order was created under, in hours. */
105
+ pickup_window_hours: number | null;
104
106
  /** The currently assessed late pick-up fee (flat step: $5 / $15 / $30). */
105
107
  late_fee_cents: number;
106
108
  late_fee_settled: boolean;
@@ -124,6 +126,8 @@ interface AccessLinkTarget {
124
126
  node_id: string;
125
127
  expires_at: string;
126
128
  pickup_window_expires_at: string | null;
129
+ /** The pick-up window this order was created under, in hours. */
130
+ pickup_window_hours: number | null;
127
131
  late_fee_cents: number;
128
132
  }
129
133
  /** A single-use override access link (bypasses every paywall). */
@@ -229,6 +233,18 @@ interface ExchangeZoneDetail extends ExchangeZone {
229
233
  payg_base_cents: number;
230
234
  payg_base_total_cents: number;
231
235
  payg_hourly_cents: number;
236
+ /**
237
+ * The app's priced pick-up windows, shortest first. Present only when the
238
+ * app offers a choice; absent means `prepaid_cents` above is the price and
239
+ * there is nothing to pick. Each `total_cents` already includes the
240
+ * Platform Fee and Processing lines, so render it as-is and pass the
241
+ * chosen `hours` to `orders.create({ pickupWindowHours })`.
242
+ */
243
+ pickup_windows?: {
244
+ hours: number;
245
+ price_cents: number;
246
+ total_cents: number;
247
+ }[];
232
248
  };
233
249
  }
234
250
  interface TokenPair {
@@ -338,6 +354,13 @@ declare class OrdersModule {
338
354
  * expired, or exhausted codes fail with `invalid_request` whose message
339
355
  * is written for the person who typed the code.
340
356
  */
357
+ /**
358
+ * The pick-up window the end user chose, in hours. Must be one the app
359
+ * offers (see `end_user_pricing.pickup_windows` on the Exchange Zone); its
360
+ * price becomes this order's prepaid price. Omitted where the app offers a
361
+ * menu: the shortest, which is the cheapest.
362
+ */
363
+ pickupWindowHours?: number;
341
364
  promotionCode?: string;
342
365
  metadata?: Record<string, string>;
343
366
  }): Promise<Order>;
@@ -575,6 +598,75 @@ interface DeliverOptions {
575
598
  */
576
599
  declare function deliverOpen(deps: UnlockDeps, open: Open, opts: DeliverOptions): Promise<UnlockResult>;
577
600
 
601
+ /**
602
+ * Relai checkout payment sheet (owner spec, 2026-08-02). When an open is gated
603
+ * on payment the API answers 402 `payment_required` with everything Stripe's
604
+ * standard Payment Sheet needs; this module presents that sheet so the app
605
+ * writes no payment logic.
606
+ *
607
+ * The Stripe module is INJECTED by the app (2026-08-04), not resolved here.
608
+ * That is forced by how Metro builds, and there is no third option:
609
+ *
610
+ * - A bundled `require("@stripe/stripe-react-native")` does not survive. tsup
611
+ * compiles ESM source, so esbuild rewrites bare `require` to its own
612
+ * `__require` shim. Metro collects dependencies by statically matching
613
+ * `require("<literal>")`, and `__require(...)` does not match, so Stripe was
614
+ * never bundled. At runtime the shim threw, the catch below returned false,
615
+ * and the caller saw the original 402 with no sheet and no explanation.
616
+ * - Writing the specifier so Metro DOES see it (a literal require, or a
617
+ * dynamic import, which esbuild does preserve) makes Metro resolve it at
618
+ * BUILD time, so every app that deliberately omits Stripe fails to build.
619
+ * That breaks the apps this peer is optional for.
620
+ *
621
+ * Injection is the only form that is correct in both cases: the app's own
622
+ * `import` is what Metro sees, and it exists only in apps that installed it.
623
+ */
624
+ interface PaymentRequiredDetails {
625
+ kind: "prepaid" | "payg_base" | "payg_setup" | "payg_pickup";
626
+ client_secret: string | null;
627
+ /** True when this is a card SAVE (PAYG with a zero base), not a charge. */
628
+ setup: boolean;
629
+ publishable_key: string | null;
630
+ customer_id?: string;
631
+ ephemeral_key?: string;
632
+ statement_suffix?: string | null;
633
+ breakdown: {
634
+ price_cents: number;
635
+ item_cents: number;
636
+ platform_fee_cents: number;
637
+ processing_cents: number;
638
+ total_cents: number;
639
+ };
640
+ }
641
+ /**
642
+ * The slice of `@stripe/stripe-react-native` this SDK uses. Structural on
643
+ * purpose: the SDK must compile and ship without Stripe installed, so it never
644
+ * imports Stripe's types.
645
+ */
646
+ interface StripeSdk {
647
+ initStripe: (o: {
648
+ publishableKey: string;
649
+ }) => Promise<unknown>;
650
+ initPaymentSheet: (o: Record<string, unknown>) => Promise<{
651
+ error?: unknown;
652
+ }>;
653
+ presentPaymentSheet: () => Promise<{
654
+ error?: unknown;
655
+ }>;
656
+ }
657
+ /** Narrow an error's `details` into the payment-sheet shape, if it is one. */
658
+ declare function asPaymentRequired(details: Record<string, unknown> | undefined): PaymentRequiredDetails | null;
659
+ /**
660
+ * Present the standard Stripe Payment Sheet for a gate. Returns true when the
661
+ * payment (or card save) completed and the open should be retried; false when
662
+ * the sheet cannot be shown or was canceled.
663
+ *
664
+ * Every `false` that is not a user cancel explains itself on the console. The
665
+ * failure this replaced was silent: the caller just re-threw `payment_required`
666
+ * and a developer had no way to tell a declined card from a missing module.
667
+ */
668
+ declare function presentRelaiPaymentSheet(details: PaymentRequiredDetails, stripe?: StripeSdk): Promise<boolean>;
669
+
578
670
  interface RelaiClientOptions {
579
671
  /** Publishable key (pk_…): safe in client apps. */
580
672
  publishableKey?: string;
@@ -589,6 +681,20 @@ interface RelaiClientOptions {
589
681
  maxRetries?: number;
590
682
  /** Persistent telemetry queue (default: in-memory). RN apps can back it with storage. */
591
683
  telemetryQueue?: TelemetryQueue;
684
+ /**
685
+ * The `@stripe/stripe-react-native` module, for Relai checkout. Pass it and
686
+ * payment-gated opens present the standard Payment Sheet and retry
687
+ * themselves; omit it and they throw `payment_required` with the sheet
688
+ * parameters in `error.details` for you to handle.
689
+ *
690
+ * You import it, not the SDK. React Native resolves imports at build time, so
691
+ * a specifier written inside this package would force every app to install
692
+ * Stripe, including the ones that want their own payment UI.
693
+ *
694
+ * import * as Stripe from "@stripe/stripe-react-native";
695
+ * new RelaiClient({ publishableKey, stripe: Stripe });
696
+ */
697
+ stripe?: StripeSdk;
592
698
  }
593
699
  interface UnlockInput {
594
700
  orderId: string;
@@ -627,6 +733,8 @@ declare class RelaiClient {
627
733
  /** Queue-and-retry telemetry uploader (used by unlock; flush opportunistically). */
628
734
  readonly telemetryUploader: TelemetryUploader;
629
735
  private readonly http;
736
+ /** The app-supplied Stripe module, if any. See `RelaiClientOptions.stripe`. */
737
+ private readonly stripe;
630
738
  constructor(options: RelaiClientOptions);
631
739
  /** Drain any telemetry queued after a failed send (e.g. on app foreground). */
632
740
  flushTelemetry(): Promise<{
@@ -641,41 +749,6 @@ declare class RelaiClient {
641
749
  unlock(input: UnlockInput): Promise<UnlockResult>;
642
750
  }
643
751
 
644
- /**
645
- * Relai checkout payment sheet (owner spec, 2026-08-02). When an open is
646
- * gated on payment the API answers 402 `payment_required` with everything
647
- * Stripe's standard Payment Sheet needs; this module presents that sheet with
648
- * ZERO app code, provided the optional peer `@stripe/stripe-react-native` is
649
- * installed. Apps that want their own payment UI simply do not install it (or
650
- * pass `presentPaymentSheet: false` to `unlock`) and handle the error's
651
- * `details` themselves.
652
- */
653
- interface PaymentRequiredDetails {
654
- kind: "prepaid" | "payg_base" | "payg_setup" | "payg_pickup";
655
- client_secret: string | null;
656
- /** True when this is a card SAVE (PAYG with a zero base), not a charge. */
657
- setup: boolean;
658
- publishable_key: string | null;
659
- customer_id?: string;
660
- ephemeral_key?: string;
661
- statement_suffix?: string | null;
662
- breakdown: {
663
- price_cents: number;
664
- item_cents: number;
665
- platform_fee_cents: number;
666
- processing_cents: number;
667
- total_cents: number;
668
- };
669
- }
670
- /** Narrow an error's `details` into the payment-sheet shape, if it is one. */
671
- declare function asPaymentRequired(details: Record<string, unknown> | undefined): PaymentRequiredDetails | null;
672
- /**
673
- * Present the standard Stripe Payment Sheet for a gate. Returns true when the
674
- * payment (or card save) completed and the open should be retried; false when
675
- * the sheet is unavailable (peer not installed / no key) or was canceled.
676
- */
677
- declare function presentRelaiPaymentSheet(details: PaymentRequiredDetails): Promise<boolean>;
678
-
679
752
  /**
680
753
  * Persistent telemetry queue (owner, 2026-07-24). `MemoryTelemetryQueue` loses
681
754
  * anything queued when the app is killed; a React Native app that opens nodes
@@ -952,4 +1025,4 @@ declare class RelaiTransportError extends RelaiError {
952
1025
  constructor(message: string);
953
1026
  }
954
1027
 
955
- export { type AccessLinkTarget, AccessLinksModule, type ApiEnvironment, type ApiErrorBody, AuthModule, type BleDeviceLike, type BleManagerLike, BleTransport, type BleTransportOptions, type CommandAck, type DeliverOptions, type DiscoveredParent, type ExchangeZone, type ExchangeZoneDetail, ExchangeZonesModule, type GrantAlgorithm, GrantsModule, type HandoffMode, type Intent, Intents, type KeyValueStorage, MemoryTelemetryQueue, MemoryTokenStorage, type MintedCommand, type NotifyLine, type Open, type Order, OrdersModule, type OverrideLink, OverrideLinksModule, type ParentTransport, type PaymentRequiredDetails, type QueuedTelemetry, REJECT_REASONS, RELAI_RX_CHAR, RELAI_TX_CHAR, RELAI_UART_SERVICE, type RecipientMatch, RecipientsModule, RelaiApiError, RelaiClient, type RelaiClientOptions, RelaiError, RelaiLateFeeDue, RelaiMissingKeyError, RelaiTransportError, RelaiUnlockRejected, type SelfBillingChoice, type Session, SimAuthenticatedTransport, type SimAuthenticatedTransportOptions, type SimulatedParentConfig, SimulatedTransport, StorageTelemetryQueue, type StorageTelemetryQueueOptions, type TelemetryAction, type TelemetryEvent, TelemetryModule, type TelemetryPayload, type TelemetryQueue, TelemetryUploader, type TokenPair, type TokenStorage, type Tower, type TowerNode, type TowerTelemetry, type UnlockDeps, type UnlockGrant, type UnlockInput, type UnlockResult, type VerifyWebhookInput, asPaymentRequired, deliverOpen, parseNotifyLine, presentRelaiPaymentSheet, verifyWebhook };
1028
+ export { type AccessLinkTarget, AccessLinksModule, type ApiEnvironment, type ApiErrorBody, AuthModule, type BleDeviceLike, type BleManagerLike, BleTransport, type BleTransportOptions, type CommandAck, type DeliverOptions, type DiscoveredParent, type ExchangeZone, type ExchangeZoneDetail, ExchangeZonesModule, type GrantAlgorithm, GrantsModule, type HandoffMode, type Intent, Intents, type KeyValueStorage, MemoryTelemetryQueue, MemoryTokenStorage, type MintedCommand, type NotifyLine, type Open, type Order, OrdersModule, type OverrideLink, OverrideLinksModule, type ParentTransport, type PaymentRequiredDetails, type QueuedTelemetry, REJECT_REASONS, RELAI_RX_CHAR, RELAI_TX_CHAR, RELAI_UART_SERVICE, type RecipientMatch, RecipientsModule, RelaiApiError, RelaiClient, type RelaiClientOptions, RelaiError, RelaiLateFeeDue, RelaiMissingKeyError, RelaiTransportError, RelaiUnlockRejected, type SelfBillingChoice, type Session, SimAuthenticatedTransport, type SimAuthenticatedTransportOptions, type SimulatedParentConfig, SimulatedTransport, StorageTelemetryQueue, type StorageTelemetryQueueOptions, type StripeSdk, type TelemetryAction, type TelemetryEvent, TelemetryModule, type TelemetryPayload, type TelemetryQueue, TelemetryUploader, type TokenPair, type TokenStorage, type Tower, type TowerNode, type TowerTelemetry, type UnlockDeps, type UnlockGrant, type UnlockInput, type UnlockResult, type VerifyWebhookInput, asPaymentRequired, deliverOpen, parseNotifyLine, presentRelaiPaymentSheet, verifyWebhook };
package/dist/index.d.ts CHANGED
@@ -101,6 +101,8 @@ interface Order extends OrderStatusFields {
101
101
  } | null;
102
102
  /** When the pick-up window closes; late fees escalate past it. Null = no window. */
103
103
  pickup_window_expires_at: string | null;
104
+ /** The pick-up window this order was created under, in hours. */
105
+ pickup_window_hours: number | null;
104
106
  /** The currently assessed late pick-up fee (flat step: $5 / $15 / $30). */
105
107
  late_fee_cents: number;
106
108
  late_fee_settled: boolean;
@@ -124,6 +126,8 @@ interface AccessLinkTarget {
124
126
  node_id: string;
125
127
  expires_at: string;
126
128
  pickup_window_expires_at: string | null;
129
+ /** The pick-up window this order was created under, in hours. */
130
+ pickup_window_hours: number | null;
127
131
  late_fee_cents: number;
128
132
  }
129
133
  /** A single-use override access link (bypasses every paywall). */
@@ -229,6 +233,18 @@ interface ExchangeZoneDetail extends ExchangeZone {
229
233
  payg_base_cents: number;
230
234
  payg_base_total_cents: number;
231
235
  payg_hourly_cents: number;
236
+ /**
237
+ * The app's priced pick-up windows, shortest first. Present only when the
238
+ * app offers a choice; absent means `prepaid_cents` above is the price and
239
+ * there is nothing to pick. Each `total_cents` already includes the
240
+ * Platform Fee and Processing lines, so render it as-is and pass the
241
+ * chosen `hours` to `orders.create({ pickupWindowHours })`.
242
+ */
243
+ pickup_windows?: {
244
+ hours: number;
245
+ price_cents: number;
246
+ total_cents: number;
247
+ }[];
232
248
  };
233
249
  }
234
250
  interface TokenPair {
@@ -338,6 +354,13 @@ declare class OrdersModule {
338
354
  * expired, or exhausted codes fail with `invalid_request` whose message
339
355
  * is written for the person who typed the code.
340
356
  */
357
+ /**
358
+ * The pick-up window the end user chose, in hours. Must be one the app
359
+ * offers (see `end_user_pricing.pickup_windows` on the Exchange Zone); its
360
+ * price becomes this order's prepaid price. Omitted where the app offers a
361
+ * menu: the shortest, which is the cheapest.
362
+ */
363
+ pickupWindowHours?: number;
341
364
  promotionCode?: string;
342
365
  metadata?: Record<string, string>;
343
366
  }): Promise<Order>;
@@ -575,6 +598,75 @@ interface DeliverOptions {
575
598
  */
576
599
  declare function deliverOpen(deps: UnlockDeps, open: Open, opts: DeliverOptions): Promise<UnlockResult>;
577
600
 
601
+ /**
602
+ * Relai checkout payment sheet (owner spec, 2026-08-02). When an open is gated
603
+ * on payment the API answers 402 `payment_required` with everything Stripe's
604
+ * standard Payment Sheet needs; this module presents that sheet so the app
605
+ * writes no payment logic.
606
+ *
607
+ * The Stripe module is INJECTED by the app (2026-08-04), not resolved here.
608
+ * That is forced by how Metro builds, and there is no third option:
609
+ *
610
+ * - A bundled `require("@stripe/stripe-react-native")` does not survive. tsup
611
+ * compiles ESM source, so esbuild rewrites bare `require` to its own
612
+ * `__require` shim. Metro collects dependencies by statically matching
613
+ * `require("<literal>")`, and `__require(...)` does not match, so Stripe was
614
+ * never bundled. At runtime the shim threw, the catch below returned false,
615
+ * and the caller saw the original 402 with no sheet and no explanation.
616
+ * - Writing the specifier so Metro DOES see it (a literal require, or a
617
+ * dynamic import, which esbuild does preserve) makes Metro resolve it at
618
+ * BUILD time, so every app that deliberately omits Stripe fails to build.
619
+ * That breaks the apps this peer is optional for.
620
+ *
621
+ * Injection is the only form that is correct in both cases: the app's own
622
+ * `import` is what Metro sees, and it exists only in apps that installed it.
623
+ */
624
+ interface PaymentRequiredDetails {
625
+ kind: "prepaid" | "payg_base" | "payg_setup" | "payg_pickup";
626
+ client_secret: string | null;
627
+ /** True when this is a card SAVE (PAYG with a zero base), not a charge. */
628
+ setup: boolean;
629
+ publishable_key: string | null;
630
+ customer_id?: string;
631
+ ephemeral_key?: string;
632
+ statement_suffix?: string | null;
633
+ breakdown: {
634
+ price_cents: number;
635
+ item_cents: number;
636
+ platform_fee_cents: number;
637
+ processing_cents: number;
638
+ total_cents: number;
639
+ };
640
+ }
641
+ /**
642
+ * The slice of `@stripe/stripe-react-native` this SDK uses. Structural on
643
+ * purpose: the SDK must compile and ship without Stripe installed, so it never
644
+ * imports Stripe's types.
645
+ */
646
+ interface StripeSdk {
647
+ initStripe: (o: {
648
+ publishableKey: string;
649
+ }) => Promise<unknown>;
650
+ initPaymentSheet: (o: Record<string, unknown>) => Promise<{
651
+ error?: unknown;
652
+ }>;
653
+ presentPaymentSheet: () => Promise<{
654
+ error?: unknown;
655
+ }>;
656
+ }
657
+ /** Narrow an error's `details` into the payment-sheet shape, if it is one. */
658
+ declare function asPaymentRequired(details: Record<string, unknown> | undefined): PaymentRequiredDetails | null;
659
+ /**
660
+ * Present the standard Stripe Payment Sheet for a gate. Returns true when the
661
+ * payment (or card save) completed and the open should be retried; false when
662
+ * the sheet cannot be shown or was canceled.
663
+ *
664
+ * Every `false` that is not a user cancel explains itself on the console. The
665
+ * failure this replaced was silent: the caller just re-threw `payment_required`
666
+ * and a developer had no way to tell a declined card from a missing module.
667
+ */
668
+ declare function presentRelaiPaymentSheet(details: PaymentRequiredDetails, stripe?: StripeSdk): Promise<boolean>;
669
+
578
670
  interface RelaiClientOptions {
579
671
  /** Publishable key (pk_…): safe in client apps. */
580
672
  publishableKey?: string;
@@ -589,6 +681,20 @@ interface RelaiClientOptions {
589
681
  maxRetries?: number;
590
682
  /** Persistent telemetry queue (default: in-memory). RN apps can back it with storage. */
591
683
  telemetryQueue?: TelemetryQueue;
684
+ /**
685
+ * The `@stripe/stripe-react-native` module, for Relai checkout. Pass it and
686
+ * payment-gated opens present the standard Payment Sheet and retry
687
+ * themselves; omit it and they throw `payment_required` with the sheet
688
+ * parameters in `error.details` for you to handle.
689
+ *
690
+ * You import it, not the SDK. React Native resolves imports at build time, so
691
+ * a specifier written inside this package would force every app to install
692
+ * Stripe, including the ones that want their own payment UI.
693
+ *
694
+ * import * as Stripe from "@stripe/stripe-react-native";
695
+ * new RelaiClient({ publishableKey, stripe: Stripe });
696
+ */
697
+ stripe?: StripeSdk;
592
698
  }
593
699
  interface UnlockInput {
594
700
  orderId: string;
@@ -627,6 +733,8 @@ declare class RelaiClient {
627
733
  /** Queue-and-retry telemetry uploader (used by unlock; flush opportunistically). */
628
734
  readonly telemetryUploader: TelemetryUploader;
629
735
  private readonly http;
736
+ /** The app-supplied Stripe module, if any. See `RelaiClientOptions.stripe`. */
737
+ private readonly stripe;
630
738
  constructor(options: RelaiClientOptions);
631
739
  /** Drain any telemetry queued after a failed send (e.g. on app foreground). */
632
740
  flushTelemetry(): Promise<{
@@ -641,41 +749,6 @@ declare class RelaiClient {
641
749
  unlock(input: UnlockInput): Promise<UnlockResult>;
642
750
  }
643
751
 
644
- /**
645
- * Relai checkout payment sheet (owner spec, 2026-08-02). When an open is
646
- * gated on payment the API answers 402 `payment_required` with everything
647
- * Stripe's standard Payment Sheet needs; this module presents that sheet with
648
- * ZERO app code, provided the optional peer `@stripe/stripe-react-native` is
649
- * installed. Apps that want their own payment UI simply do not install it (or
650
- * pass `presentPaymentSheet: false` to `unlock`) and handle the error's
651
- * `details` themselves.
652
- */
653
- interface PaymentRequiredDetails {
654
- kind: "prepaid" | "payg_base" | "payg_setup" | "payg_pickup";
655
- client_secret: string | null;
656
- /** True when this is a card SAVE (PAYG with a zero base), not a charge. */
657
- setup: boolean;
658
- publishable_key: string | null;
659
- customer_id?: string;
660
- ephemeral_key?: string;
661
- statement_suffix?: string | null;
662
- breakdown: {
663
- price_cents: number;
664
- item_cents: number;
665
- platform_fee_cents: number;
666
- processing_cents: number;
667
- total_cents: number;
668
- };
669
- }
670
- /** Narrow an error's `details` into the payment-sheet shape, if it is one. */
671
- declare function asPaymentRequired(details: Record<string, unknown> | undefined): PaymentRequiredDetails | null;
672
- /**
673
- * Present the standard Stripe Payment Sheet for a gate. Returns true when the
674
- * payment (or card save) completed and the open should be retried; false when
675
- * the sheet is unavailable (peer not installed / no key) or was canceled.
676
- */
677
- declare function presentRelaiPaymentSheet(details: PaymentRequiredDetails): Promise<boolean>;
678
-
679
752
  /**
680
753
  * Persistent telemetry queue (owner, 2026-07-24). `MemoryTelemetryQueue` loses
681
754
  * anything queued when the app is killed; a React Native app that opens nodes
@@ -952,4 +1025,4 @@ declare class RelaiTransportError extends RelaiError {
952
1025
  constructor(message: string);
953
1026
  }
954
1027
 
955
- export { type AccessLinkTarget, AccessLinksModule, type ApiEnvironment, type ApiErrorBody, AuthModule, type BleDeviceLike, type BleManagerLike, BleTransport, type BleTransportOptions, type CommandAck, type DeliverOptions, type DiscoveredParent, type ExchangeZone, type ExchangeZoneDetail, ExchangeZonesModule, type GrantAlgorithm, GrantsModule, type HandoffMode, type Intent, Intents, type KeyValueStorage, MemoryTelemetryQueue, MemoryTokenStorage, type MintedCommand, type NotifyLine, type Open, type Order, OrdersModule, type OverrideLink, OverrideLinksModule, type ParentTransport, type PaymentRequiredDetails, type QueuedTelemetry, REJECT_REASONS, RELAI_RX_CHAR, RELAI_TX_CHAR, RELAI_UART_SERVICE, type RecipientMatch, RecipientsModule, RelaiApiError, RelaiClient, type RelaiClientOptions, RelaiError, RelaiLateFeeDue, RelaiMissingKeyError, RelaiTransportError, RelaiUnlockRejected, type SelfBillingChoice, type Session, SimAuthenticatedTransport, type SimAuthenticatedTransportOptions, type SimulatedParentConfig, SimulatedTransport, StorageTelemetryQueue, type StorageTelemetryQueueOptions, type TelemetryAction, type TelemetryEvent, TelemetryModule, type TelemetryPayload, type TelemetryQueue, TelemetryUploader, type TokenPair, type TokenStorage, type Tower, type TowerNode, type TowerTelemetry, type UnlockDeps, type UnlockGrant, type UnlockInput, type UnlockResult, type VerifyWebhookInput, asPaymentRequired, deliverOpen, parseNotifyLine, presentRelaiPaymentSheet, verifyWebhook };
1028
+ export { type AccessLinkTarget, AccessLinksModule, type ApiEnvironment, type ApiErrorBody, AuthModule, type BleDeviceLike, type BleManagerLike, BleTransport, type BleTransportOptions, type CommandAck, type DeliverOptions, type DiscoveredParent, type ExchangeZone, type ExchangeZoneDetail, ExchangeZonesModule, type GrantAlgorithm, GrantsModule, type HandoffMode, type Intent, Intents, type KeyValueStorage, MemoryTelemetryQueue, MemoryTokenStorage, type MintedCommand, type NotifyLine, type Open, type Order, OrdersModule, type OverrideLink, OverrideLinksModule, type ParentTransport, type PaymentRequiredDetails, type QueuedTelemetry, REJECT_REASONS, RELAI_RX_CHAR, RELAI_TX_CHAR, RELAI_UART_SERVICE, type RecipientMatch, RecipientsModule, RelaiApiError, RelaiClient, type RelaiClientOptions, RelaiError, RelaiLateFeeDue, RelaiMissingKeyError, RelaiTransportError, RelaiUnlockRejected, type SelfBillingChoice, type Session, SimAuthenticatedTransport, type SimAuthenticatedTransportOptions, type SimulatedParentConfig, SimulatedTransport, StorageTelemetryQueue, type StorageTelemetryQueueOptions, type StripeSdk, type TelemetryAction, type TelemetryEvent, TelemetryModule, type TelemetryPayload, type TelemetryQueue, TelemetryUploader, type TokenPair, type TokenStorage, type Tower, type TowerNode, type TowerTelemetry, type UnlockDeps, type UnlockGrant, type UnlockInput, type UnlockResult, type VerifyWebhookInput, asPaymentRequired, deliverOpen, parseNotifyLine, presentRelaiPaymentSheet, verifyWebhook };
package/dist/index.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import { RelaiApiError, RelaiTransportError, RelaiUnlockRejected, RelaiMissingKeyError, RelaiError } from './chunk-MNXTMLX2.js';
2
2
  export { RelaiApiError, RelaiError, RelaiLateFeeDue, RelaiMissingKeyError, RelaiTransportError, RelaiUnlockRejected } from './chunk-MNXTMLX2.js';
3
- export { asPaymentRequired, presentRelaiPaymentSheet } from './chunk-TRAEMNHD.js';
4
- import './chunk-3RG5ZIWI.js';
3
+ export { asPaymentRequired, presentRelaiPaymentSheet } from './chunk-3WZBCXG3.js';
5
4
 
6
5
  // src/http.ts
7
6
  var RETRYABLE_STATUS = /* @__PURE__ */ new Set([429, 500, 502, 503, 504]);
@@ -98,7 +97,7 @@ var HttpClient = class {
98
97
  }
99
98
  if (!body?.error?.code) body = { error: { code: "http_error", message: `HTTP ${res.status}` } };
100
99
  if (body.error.code === "late_fee_due") {
101
- const { RelaiLateFeeDue: RelaiLateFeeDue2 } = await import('./errors-MCGRQUDJ.js');
100
+ const { RelaiLateFeeDue: RelaiLateFeeDue2 } = await import('./errors-L7B45UIZ.js');
102
101
  return new RelaiLateFeeDue2(res.status, body);
103
102
  }
104
103
  return new RelaiApiError(res.status, body);
@@ -244,6 +243,7 @@ var OrdersModule = class {
244
243
  if (input.recipient !== void 0) body["recipient"] = input.recipient;
245
244
  if (input.recipientUserId !== void 0) body["recipient_user_id"] = input.recipientUserId;
246
245
  if (input.recipientEmail !== void 0) body["recipient_email"] = input.recipientEmail;
246
+ if (input.pickupWindowHours !== void 0) body["pickup_window_hours"] = input.pickupWindowHours;
247
247
  if (input.promotionCode !== void 0) body["promotion_code"] = input.promotionCode;
248
248
  if (input.metadata !== void 0) body["metadata"] = input.metadata;
249
249
  return this.http.request({ method: "POST", path: "/orders", body });
@@ -474,6 +474,7 @@ var DEFAULT_BASE_URL = "https://access.relai.us/api/v1";
474
474
  var RelaiClient = class {
475
475
  constructor(options) {
476
476
  if (!options.publishableKey && !options.secretKey) throw new RelaiMissingKeyError();
477
+ this.stripe = options.stripe;
477
478
  const storage = options.tokenStorage ?? new MemoryTokenStorage();
478
479
  let auth;
479
480
  const httpConfig = {
@@ -519,11 +520,11 @@ var RelaiClient = class {
519
520
  try {
520
521
  open = await requestOpen();
521
522
  } catch (err) {
522
- const { RelaiApiError: RelaiApiError2 } = await import('./errors-MCGRQUDJ.js');
523
+ const { RelaiApiError: RelaiApiError2 } = await import('./errors-L7B45UIZ.js');
523
524
  if (input.presentPaymentSheet !== false && err instanceof RelaiApiError2 && err.code === "payment_required") {
524
- const { asPaymentRequired: asPaymentRequired2, presentRelaiPaymentSheet: presentRelaiPaymentSheet2 } = await import('./payment-sheet-XOZDLRKL.js');
525
+ const { asPaymentRequired: asPaymentRequired2, presentRelaiPaymentSheet: presentRelaiPaymentSheet2 } = await import('./payment-sheet-XIZYASSI.js');
525
526
  const details = asPaymentRequired2(err.details);
526
- if (!details || !await presentRelaiPaymentSheet2(details)) throw err;
527
+ if (!details || !await presentRelaiPaymentSheet2(details, this.stripe)) throw err;
527
528
  open = await requestOpen();
528
529
  } else {
529
530
  throw err;
@@ -1,2 +1 @@
1
- export { asPaymentRequired, presentRelaiPaymentSheet } from './chunk-TRAEMNHD.js';
2
- import './chunk-3RG5ZIWI.js';
1
+ export { asPaymentRequired, presentRelaiPaymentSheet } from './chunk-3WZBCXG3.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@relai-team/access-sdk",
3
- "version": "0.8.1",
3
+ "version": "0.10.0",
4
4
  "description": "Official Relai Access SDK, open Relai Exchange Zone nodes over BLE, backed by the Relai Access platform (server-owns-trust).",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "type": "module",
@@ -1,8 +0,0 @@
1
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
- }) : x)(function(x) {
4
- if (typeof require !== "undefined") return require.apply(this, arguments);
5
- throw Error('Dynamic require of "' + x + '" is not supported');
6
- });
7
-
8
- export { __require };
@@ -1,27 +0,0 @@
1
- import { __require } from './chunk-3RG5ZIWI.js';
2
-
3
- // src/payment-sheet.ts
4
- function asPaymentRequired(details) {
5
- if (!details || typeof details["client_secret"] !== "string" || typeof details["kind"] !== "string") return null;
6
- return details;
7
- }
8
- async function presentRelaiPaymentSheet(details) {
9
- if (!details.client_secret || !details.publishable_key) return false;
10
- let stripe;
11
- try {
12
- stripe = __require("@stripe/stripe-react-native");
13
- } catch {
14
- return false;
15
- }
16
- await stripe.initStripe({ publishableKey: details.publishable_key });
17
- const { error: initError } = await stripe.initPaymentSheet({
18
- merchantDisplayName: "Relai Access",
19
- ...details.setup ? { setupIntentClientSecret: details.client_secret } : { paymentIntentClientSecret: details.client_secret },
20
- ...details.customer_id && details.ephemeral_key ? { customerId: details.customer_id, customerEphemeralKeySecret: details.ephemeral_key } : {}
21
- });
22
- if (initError) return false;
23
- const { error } = await stripe.presentPaymentSheet();
24
- return !error;
25
- }
26
-
27
- export { asPaymentRequired, presentRelaiPaymentSheet };