@relai-team/access-sdk 0.8.1 → 0.9.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,6 +171,9 @@ 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
 
@@ -181,7 +197,7 @@ order.checkout?.drop_off_paid; // true once the drop-off charge settled
181
197
  ```
182
198
 
183
199
  To build your own payment UI instead, pass `presentPaymentSheet: false` to
184
- `unlock()` (or simply do not install the Stripe peer) and catch
200
+ `unlock()` (or simply omit `stripe`) and catch
185
201
  `RelaiApiError` with code `payment_required`: `error.details` carries the
186
202
  sheet parameters (`client_secret`, `publishable_key`, customer + ephemeral
187
203
  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({
@@ -592,6 +597,7 @@ var DEFAULT_BASE_URL = "https://access.relai.us/api/v1";
592
597
  var RelaiClient = class {
593
598
  constructor(options) {
594
599
  if (!options.publishableKey && !options.secretKey) throw new exports.RelaiMissingKeyError();
600
+ this.stripe = options.stripe;
595
601
  const storage = options.tokenStorage ?? new MemoryTokenStorage();
596
602
  let auth;
597
603
  const httpConfig = {
@@ -641,7 +647,7 @@ var RelaiClient = class {
641
647
  if (input.presentPaymentSheet !== false && err instanceof RelaiApiError2 && err.code === "payment_required") {
642
648
  const { asPaymentRequired: asPaymentRequired2, presentRelaiPaymentSheet: presentRelaiPaymentSheet2 } = await Promise.resolve().then(() => (init_payment_sheet(), payment_sheet_exports));
643
649
  const details = asPaymentRequired2(err.details);
644
- if (!details || !await presentRelaiPaymentSheet2(details)) throw err;
650
+ if (!details || !await presentRelaiPaymentSheet2(details, this.stripe)) throw err;
645
651
  open = await requestOpen();
646
652
  } else {
647
653
  throw err;
package/dist/index.d.cts CHANGED
@@ -575,6 +575,75 @@ interface DeliverOptions {
575
575
  */
576
576
  declare function deliverOpen(deps: UnlockDeps, open: Open, opts: DeliverOptions): Promise<UnlockResult>;
577
577
 
578
+ /**
579
+ * Relai checkout payment sheet (owner spec, 2026-08-02). When an open is gated
580
+ * on payment the API answers 402 `payment_required` with everything Stripe's
581
+ * standard Payment Sheet needs; this module presents that sheet so the app
582
+ * writes no payment logic.
583
+ *
584
+ * The Stripe module is INJECTED by the app (2026-08-04), not resolved here.
585
+ * That is forced by how Metro builds, and there is no third option:
586
+ *
587
+ * - A bundled `require("@stripe/stripe-react-native")` does not survive. tsup
588
+ * compiles ESM source, so esbuild rewrites bare `require` to its own
589
+ * `__require` shim. Metro collects dependencies by statically matching
590
+ * `require("<literal>")`, and `__require(...)` does not match, so Stripe was
591
+ * never bundled. At runtime the shim threw, the catch below returned false,
592
+ * and the caller saw the original 402 with no sheet and no explanation.
593
+ * - Writing the specifier so Metro DOES see it (a literal require, or a
594
+ * dynamic import, which esbuild does preserve) makes Metro resolve it at
595
+ * BUILD time, so every app that deliberately omits Stripe fails to build.
596
+ * That breaks the apps this peer is optional for.
597
+ *
598
+ * Injection is the only form that is correct in both cases: the app's own
599
+ * `import` is what Metro sees, and it exists only in apps that installed it.
600
+ */
601
+ interface PaymentRequiredDetails {
602
+ kind: "prepaid" | "payg_base" | "payg_setup" | "payg_pickup";
603
+ client_secret: string | null;
604
+ /** True when this is a card SAVE (PAYG with a zero base), not a charge. */
605
+ setup: boolean;
606
+ publishable_key: string | null;
607
+ customer_id?: string;
608
+ ephemeral_key?: string;
609
+ statement_suffix?: string | null;
610
+ breakdown: {
611
+ price_cents: number;
612
+ item_cents: number;
613
+ platform_fee_cents: number;
614
+ processing_cents: number;
615
+ total_cents: number;
616
+ };
617
+ }
618
+ /**
619
+ * The slice of `@stripe/stripe-react-native` this SDK uses. Structural on
620
+ * purpose: the SDK must compile and ship without Stripe installed, so it never
621
+ * imports Stripe's types.
622
+ */
623
+ interface StripeSdk {
624
+ initStripe: (o: {
625
+ publishableKey: string;
626
+ }) => Promise<unknown>;
627
+ initPaymentSheet: (o: Record<string, unknown>) => Promise<{
628
+ error?: unknown;
629
+ }>;
630
+ presentPaymentSheet: () => Promise<{
631
+ error?: unknown;
632
+ }>;
633
+ }
634
+ /** Narrow an error's `details` into the payment-sheet shape, if it is one. */
635
+ declare function asPaymentRequired(details: Record<string, unknown> | undefined): PaymentRequiredDetails | null;
636
+ /**
637
+ * Present the standard Stripe Payment Sheet for a gate. Returns true when the
638
+ * payment (or card save) completed and the open should be retried; false when
639
+ * the sheet cannot be shown or was canceled.
640
+ *
641
+ * Every `false` that is not a user cancel explains itself on the console. The
642
+ * failure this replaced was silent: the caller just re-threw `payment_required`
643
+ * and a developer had no way to tell a declined card from a missing module.
644
+ */
645
+ declare function presentRelaiPaymentSheet(details: PaymentRequiredDetails, stripe?: StripeSdk): Promise<boolean>;
646
+
578
647
  interface RelaiClientOptions {
579
648
  /** Publishable key (pk_…): safe in client apps. */
580
649
  publishableKey?: string;
@@ -589,6 +658,20 @@ interface RelaiClientOptions {
589
658
  maxRetries?: number;
590
659
  /** Persistent telemetry queue (default: in-memory). RN apps can back it with storage. */
591
660
  telemetryQueue?: TelemetryQueue;
661
+ /**
662
+ * The `@stripe/stripe-react-native` module, for Relai checkout. Pass it and
663
+ * payment-gated opens present the standard Payment Sheet and retry
664
+ * themselves; omit it and they throw `payment_required` with the sheet
665
+ * parameters in `error.details` for you to handle.
666
+ *
667
+ * You import it, not the SDK. React Native resolves imports at build time, so
668
+ * a specifier written inside this package would force every app to install
669
+ * Stripe, including the ones that want their own payment UI.
670
+ *
671
+ * import * as Stripe from "@stripe/stripe-react-native";
672
+ * new RelaiClient({ publishableKey, stripe: Stripe });
673
+ */
674
+ stripe?: StripeSdk;
592
675
  }
593
676
  interface UnlockInput {
594
677
  orderId: string;
@@ -627,6 +710,8 @@ declare class RelaiClient {
627
710
  /** Queue-and-retry telemetry uploader (used by unlock; flush opportunistically). */
628
711
  readonly telemetryUploader: TelemetryUploader;
629
712
  private readonly http;
713
+ /** The app-supplied Stripe module, if any. See `RelaiClientOptions.stripe`. */
714
+ private readonly stripe;
630
715
  constructor(options: RelaiClientOptions);
631
716
  /** Drain any telemetry queued after a failed send (e.g. on app foreground). */
632
717
  flushTelemetry(): Promise<{
@@ -641,41 +726,6 @@ declare class RelaiClient {
641
726
  unlock(input: UnlockInput): Promise<UnlockResult>;
642
727
  }
643
728
 
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
729
  /**
680
730
  * Persistent telemetry queue (owner, 2026-07-24). `MemoryTelemetryQueue` loses
681
731
  * anything queued when the app is killed; a React Native app that opens nodes
@@ -952,4 +1002,4 @@ declare class RelaiTransportError extends RelaiError {
952
1002
  constructor(message: string);
953
1003
  }
954
1004
 
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 };
1005
+ 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
@@ -575,6 +575,75 @@ interface DeliverOptions {
575
575
  */
576
576
  declare function deliverOpen(deps: UnlockDeps, open: Open, opts: DeliverOptions): Promise<UnlockResult>;
577
577
 
578
+ /**
579
+ * Relai checkout payment sheet (owner spec, 2026-08-02). When an open is gated
580
+ * on payment the API answers 402 `payment_required` with everything Stripe's
581
+ * standard Payment Sheet needs; this module presents that sheet so the app
582
+ * writes no payment logic.
583
+ *
584
+ * The Stripe module is INJECTED by the app (2026-08-04), not resolved here.
585
+ * That is forced by how Metro builds, and there is no third option:
586
+ *
587
+ * - A bundled `require("@stripe/stripe-react-native")` does not survive. tsup
588
+ * compiles ESM source, so esbuild rewrites bare `require` to its own
589
+ * `__require` shim. Metro collects dependencies by statically matching
590
+ * `require("<literal>")`, and `__require(...)` does not match, so Stripe was
591
+ * never bundled. At runtime the shim threw, the catch below returned false,
592
+ * and the caller saw the original 402 with no sheet and no explanation.
593
+ * - Writing the specifier so Metro DOES see it (a literal require, or a
594
+ * dynamic import, which esbuild does preserve) makes Metro resolve it at
595
+ * BUILD time, so every app that deliberately omits Stripe fails to build.
596
+ * That breaks the apps this peer is optional for.
597
+ *
598
+ * Injection is the only form that is correct in both cases: the app's own
599
+ * `import` is what Metro sees, and it exists only in apps that installed it.
600
+ */
601
+ interface PaymentRequiredDetails {
602
+ kind: "prepaid" | "payg_base" | "payg_setup" | "payg_pickup";
603
+ client_secret: string | null;
604
+ /** True when this is a card SAVE (PAYG with a zero base), not a charge. */
605
+ setup: boolean;
606
+ publishable_key: string | null;
607
+ customer_id?: string;
608
+ ephemeral_key?: string;
609
+ statement_suffix?: string | null;
610
+ breakdown: {
611
+ price_cents: number;
612
+ item_cents: number;
613
+ platform_fee_cents: number;
614
+ processing_cents: number;
615
+ total_cents: number;
616
+ };
617
+ }
618
+ /**
619
+ * The slice of `@stripe/stripe-react-native` this SDK uses. Structural on
620
+ * purpose: the SDK must compile and ship without Stripe installed, so it never
621
+ * imports Stripe's types.
622
+ */
623
+ interface StripeSdk {
624
+ initStripe: (o: {
625
+ publishableKey: string;
626
+ }) => Promise<unknown>;
627
+ initPaymentSheet: (o: Record<string, unknown>) => Promise<{
628
+ error?: unknown;
629
+ }>;
630
+ presentPaymentSheet: () => Promise<{
631
+ error?: unknown;
632
+ }>;
633
+ }
634
+ /** Narrow an error's `details` into the payment-sheet shape, if it is one. */
635
+ declare function asPaymentRequired(details: Record<string, unknown> | undefined): PaymentRequiredDetails | null;
636
+ /**
637
+ * Present the standard Stripe Payment Sheet for a gate. Returns true when the
638
+ * payment (or card save) completed and the open should be retried; false when
639
+ * the sheet cannot be shown or was canceled.
640
+ *
641
+ * Every `false` that is not a user cancel explains itself on the console. The
642
+ * failure this replaced was silent: the caller just re-threw `payment_required`
643
+ * and a developer had no way to tell a declined card from a missing module.
644
+ */
645
+ declare function presentRelaiPaymentSheet(details: PaymentRequiredDetails, stripe?: StripeSdk): Promise<boolean>;
646
+
578
647
  interface RelaiClientOptions {
579
648
  /** Publishable key (pk_…): safe in client apps. */
580
649
  publishableKey?: string;
@@ -589,6 +658,20 @@ interface RelaiClientOptions {
589
658
  maxRetries?: number;
590
659
  /** Persistent telemetry queue (default: in-memory). RN apps can back it with storage. */
591
660
  telemetryQueue?: TelemetryQueue;
661
+ /**
662
+ * The `@stripe/stripe-react-native` module, for Relai checkout. Pass it and
663
+ * payment-gated opens present the standard Payment Sheet and retry
664
+ * themselves; omit it and they throw `payment_required` with the sheet
665
+ * parameters in `error.details` for you to handle.
666
+ *
667
+ * You import it, not the SDK. React Native resolves imports at build time, so
668
+ * a specifier written inside this package would force every app to install
669
+ * Stripe, including the ones that want their own payment UI.
670
+ *
671
+ * import * as Stripe from "@stripe/stripe-react-native";
672
+ * new RelaiClient({ publishableKey, stripe: Stripe });
673
+ */
674
+ stripe?: StripeSdk;
592
675
  }
593
676
  interface UnlockInput {
594
677
  orderId: string;
@@ -627,6 +710,8 @@ declare class RelaiClient {
627
710
  /** Queue-and-retry telemetry uploader (used by unlock; flush opportunistically). */
628
711
  readonly telemetryUploader: TelemetryUploader;
629
712
  private readonly http;
713
+ /** The app-supplied Stripe module, if any. See `RelaiClientOptions.stripe`. */
714
+ private readonly stripe;
630
715
  constructor(options: RelaiClientOptions);
631
716
  /** Drain any telemetry queued after a failed send (e.g. on app foreground). */
632
717
  flushTelemetry(): Promise<{
@@ -641,41 +726,6 @@ declare class RelaiClient {
641
726
  unlock(input: UnlockInput): Promise<UnlockResult>;
642
727
  }
643
728
 
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
729
  /**
680
730
  * Persistent telemetry queue (owner, 2026-07-24). `MemoryTelemetryQueue` loses
681
731
  * anything queued when the app is killed; a React Native app that opens nodes
@@ -952,4 +1002,4 @@ declare class RelaiTransportError extends RelaiError {
952
1002
  constructor(message: string);
953
1003
  }
954
1004
 
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 };
1005
+ 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);
@@ -474,6 +473,7 @@ var DEFAULT_BASE_URL = "https://access.relai.us/api/v1";
474
473
  var RelaiClient = class {
475
474
  constructor(options) {
476
475
  if (!options.publishableKey && !options.secretKey) throw new RelaiMissingKeyError();
476
+ this.stripe = options.stripe;
477
477
  const storage = options.tokenStorage ?? new MemoryTokenStorage();
478
478
  let auth;
479
479
  const httpConfig = {
@@ -519,11 +519,11 @@ var RelaiClient = class {
519
519
  try {
520
520
  open = await requestOpen();
521
521
  } catch (err) {
522
- const { RelaiApiError: RelaiApiError2 } = await import('./errors-MCGRQUDJ.js');
522
+ const { RelaiApiError: RelaiApiError2 } = await import('./errors-L7B45UIZ.js');
523
523
  if (input.presentPaymentSheet !== false && err instanceof RelaiApiError2 && err.code === "payment_required") {
524
- const { asPaymentRequired: asPaymentRequired2, presentRelaiPaymentSheet: presentRelaiPaymentSheet2 } = await import('./payment-sheet-XOZDLRKL.js');
524
+ const { asPaymentRequired: asPaymentRequired2, presentRelaiPaymentSheet: presentRelaiPaymentSheet2 } = await import('./payment-sheet-XIZYASSI.js');
525
525
  const details = asPaymentRequired2(err.details);
526
- if (!details || !await presentRelaiPaymentSheet2(details)) throw err;
526
+ if (!details || !await presentRelaiPaymentSheet2(details, this.stripe)) throw err;
527
527
  open = await requestOpen();
528
528
  } else {
529
529
  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.9.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 };