@relai-team/access-sdk 0.8.0 → 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 +58 -4
- package/dist/chunk-3WZBCXG3.js +36 -0
- package/dist/{errors-MCGRQUDJ.js → errors-L7B45UIZ.js} +0 -1
- package/dist/index.cjs +32 -14
- package/dist/index.d.cts +98 -36
- package/dist/index.d.ts +98 -36
- package/dist/index.js +18 -6
- package/dist/{payment-sheet-XOZDLRKL.js → payment-sheet-XIZYASSI.js} +1 -2
- package/package.json +1 -1
- package/dist/chunk-3RG5ZIWI.js +0 -8
- package/dist/chunk-TRAEMNHD.js +0 -27
package/README.md
CHANGED
|
@@ -46,6 +46,44 @@ const result = await relai.unlock({
|
|
|
46
46
|
console.log(result.accepted, result.command); // true "OPEN 3:0"
|
|
47
47
|
```
|
|
48
48
|
|
|
49
|
+
## Environments: one app, two keys
|
|
50
|
+
|
|
51
|
+
Your app holds a **sandbox** key pair from the moment it is created, and gains a
|
|
52
|
+
**production** pair alongside it once a Relai admin approves it. You never make a
|
|
53
|
+
second app to test, and going live moves nothing: same app id, same webhook
|
|
54
|
+
secret, same simulated Exchange Zones, same subscription.
|
|
55
|
+
|
|
56
|
+
Switching environments is switching the key. There is no mode flag:
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
const test = new RelaiClient({ publishableKey: "pk_sandbox_..." }); // simulated EZs, Stripe test
|
|
60
|
+
const live = new RelaiClient({ publishableKey: "pk_live_..." }); // real hardware, real money
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
A sandbox key sees only your simulated Exchange Zones; a production key sees only
|
|
64
|
+
real ones you have access to. Asking either for the other's Exchange Zone returns
|
|
65
|
+
`not_found`.
|
|
66
|
+
|
|
67
|
+
**Sessions belong to one environment.** A token issued under a sandbox key is
|
|
68
|
+
rejected when sent with a production key, and refreshing will not move a session
|
|
69
|
+
across. Prefer one `RelaiClient` per environment. If a stored session does end up
|
|
70
|
+
on the wrong side (a persisted token store surviving a key swap), the SDK drops
|
|
71
|
+
it on the first `invalid_token` so `auth.isSignedIn` goes false and your normal
|
|
72
|
+
signed-out path takes over; sign in again to get a session for the new
|
|
73
|
+
environment.
|
|
74
|
+
|
|
75
|
+
To sign in while building, create **test end-users** on your app's page in the
|
|
76
|
+
portal. Each gets a fixed sign-in code shown next to it, so your app runs the
|
|
77
|
+
normal OTP flow with no environment branch in your code:
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
await relai.auth.startOtp("dana.the.courier.abc12345@test.relai.us");
|
|
81
|
+
await relai.auth.verifyOtp("dana.the.courier.abc12345@test.relai.us", "455606");
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Test end-users receive no email, never appear among your real customers, and are
|
|
85
|
+
refused by production keys.
|
|
86
|
+
|
|
49
87
|
## How an open works
|
|
50
88
|
|
|
51
89
|
`relai.unlock(...)` runs the full server-owns-trust sequence:
|
|
@@ -110,9 +148,22 @@ month, then $1.00 each). Redeem via `overrideCode` on the open.
|
|
|
110
148
|
|
|
111
149
|
If the app is set to **Relai checkout** in the Relai portal (the default for
|
|
112
150
|
new apps), the platform charges the end user at the door and this SDK handles
|
|
113
|
-
the whole exchange. A payment-gated open answers 402 `payment_required
|
|
114
|
-
the
|
|
115
|
-
|
|
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:
|
|
116
167
|
|
|
117
168
|
```ts
|
|
118
169
|
// Exactly the same call as a free open. If payment is due, the sheet
|
|
@@ -120,6 +171,9 @@ the **standard Stripe Payment Sheet** and retries the open by itself:
|
|
|
120
171
|
await relai.unlock({ orderId: order.id, intent: Intents.Occupy, transport });
|
|
121
172
|
```
|
|
122
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
|
+
|
|
123
177
|
Prices are configured in the portal (per app, with per-Exchange-Zone
|
|
124
178
|
overrides), in two styles:
|
|
125
179
|
|
|
@@ -143,7 +197,7 @@ order.checkout?.drop_off_paid; // true once the drop-off charge settled
|
|
|
143
197
|
```
|
|
144
198
|
|
|
145
199
|
To build your own payment UI instead, pass `presentPaymentSheet: false` to
|
|
146
|
-
`unlock()` (or simply
|
|
200
|
+
`unlock()` (or simply omit `stripe`) and catch
|
|
147
201
|
`RelaiApiError` with code `payment_required`: `error.details` carries the
|
|
148
202
|
sheet parameters (`client_secret`, `publishable_key`, customer + ephemeral
|
|
149
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 };
|
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)
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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)
|
|
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({
|
|
@@ -137,6 +142,9 @@ var HttpClient = class {
|
|
|
137
142
|
const refreshed = await this.cfg.onTokenExpired();
|
|
138
143
|
if (refreshed) return this.attempt(opts, idem, true);
|
|
139
144
|
}
|
|
145
|
+
if (err instanceof exports.RelaiApiError && err.code === "invalid_token" && this.cfg.onTokenInvalid && !opts.noBearer) {
|
|
146
|
+
this.cfg.onTokenInvalid();
|
|
147
|
+
}
|
|
140
148
|
throw err;
|
|
141
149
|
}
|
|
142
150
|
}
|
|
@@ -295,6 +303,14 @@ var AuthModule = class {
|
|
|
295
303
|
return false;
|
|
296
304
|
}
|
|
297
305
|
}
|
|
306
|
+
/**
|
|
307
|
+
* Drop the local session without calling the server. For a session the server
|
|
308
|
+
* has already rejected as permanently invalid, where `signOut()`'s revoke call
|
|
309
|
+
* would just fail on a token that is already dead.
|
|
310
|
+
*/
|
|
311
|
+
clearSession() {
|
|
312
|
+
this.storage.clear();
|
|
313
|
+
}
|
|
298
314
|
/** Revoke the refresh token and clear local state. */
|
|
299
315
|
async signOut() {
|
|
300
316
|
const current = this.storage.get();
|
|
@@ -581,12 +597,14 @@ var DEFAULT_BASE_URL = "https://access.relai.us/api/v1";
|
|
|
581
597
|
var RelaiClient = class {
|
|
582
598
|
constructor(options) {
|
|
583
599
|
if (!options.publishableKey && !options.secretKey) throw new exports.RelaiMissingKeyError();
|
|
600
|
+
this.stripe = options.stripe;
|
|
584
601
|
const storage = options.tokenStorage ?? new MemoryTokenStorage();
|
|
585
602
|
let auth;
|
|
586
603
|
const httpConfig = {
|
|
587
604
|
baseUrl: options.baseUrl ?? DEFAULT_BASE_URL,
|
|
588
605
|
getBearer: () => auth?.accessToken,
|
|
589
606
|
onTokenExpired: () => auth?.refresh() ?? Promise.resolve(false),
|
|
607
|
+
onTokenInvalid: () => auth?.clearSession(),
|
|
590
608
|
...options.publishableKey !== void 0 ? { publishableKey: options.publishableKey } : {},
|
|
591
609
|
...options.secretKey !== void 0 ? { secretKey: options.secretKey } : {},
|
|
592
610
|
...options.fetchImpl !== void 0 ? { fetchImpl: options.fetchImpl } : {},
|
|
@@ -629,7 +647,7 @@ var RelaiClient = class {
|
|
|
629
647
|
if (input.presentPaymentSheet !== false && err instanceof RelaiApiError2 && err.code === "payment_required") {
|
|
630
648
|
const { asPaymentRequired: asPaymentRequired2, presentRelaiPaymentSheet: presentRelaiPaymentSheet2 } = await Promise.resolve().then(() => (init_payment_sheet(), payment_sheet_exports));
|
|
631
649
|
const details = asPaymentRequired2(err.details);
|
|
632
|
-
if (!details || !await presentRelaiPaymentSheet2(details)) throw err;
|
|
650
|
+
if (!details || !await presentRelaiPaymentSheet2(details, this.stripe)) throw err;
|
|
633
651
|
open = await requestOpen();
|
|
634
652
|
} else {
|
|
635
653
|
throw err;
|
package/dist/index.d.cts
CHANGED
|
@@ -6,6 +6,12 @@ interface HttpConfig {
|
|
|
6
6
|
getBearer?: () => string | undefined;
|
|
7
7
|
/** Invoked once on `token_expired`; returns true if a refresh succeeded. */
|
|
8
8
|
onTokenExpired?: () => Promise<boolean>;
|
|
9
|
+
/**
|
|
10
|
+
* Invoked on `invalid_token`: the stored session is permanently dead and no
|
|
11
|
+
* refresh can save it (wrong environment, revoked epoch, wrong app). The
|
|
12
|
+
* client drops it so `auth.isSignedIn` goes false.
|
|
13
|
+
*/
|
|
14
|
+
onTokenInvalid?: () => void;
|
|
9
15
|
fetchImpl?: typeof fetch;
|
|
10
16
|
maxRetries?: number;
|
|
11
17
|
}
|
|
@@ -272,6 +278,12 @@ declare class AuthModule {
|
|
|
272
278
|
/** Rotate the token pair. Single-flight: concurrent callers share one refresh. */
|
|
273
279
|
refresh(): Promise<boolean>;
|
|
274
280
|
private doRefresh;
|
|
281
|
+
/**
|
|
282
|
+
* Drop the local session without calling the server. For a session the server
|
|
283
|
+
* has already rejected as permanently invalid, where `signOut()`'s revoke call
|
|
284
|
+
* would just fail on a token that is already dead.
|
|
285
|
+
*/
|
|
286
|
+
clearSession(): void;
|
|
275
287
|
/** Revoke the refresh token and clear local state. */
|
|
276
288
|
signOut(): Promise<void>;
|
|
277
289
|
}
|
|
@@ -563,6 +575,75 @@ interface DeliverOptions {
|
|
|
563
575
|
*/
|
|
564
576
|
declare function deliverOpen(deps: UnlockDeps, open: Open, opts: DeliverOptions): Promise<UnlockResult>;
|
|
565
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
|
+
|
|
566
647
|
interface RelaiClientOptions {
|
|
567
648
|
/** Publishable key (pk_…): safe in client apps. */
|
|
568
649
|
publishableKey?: string;
|
|
@@ -577,6 +658,20 @@ interface RelaiClientOptions {
|
|
|
577
658
|
maxRetries?: number;
|
|
578
659
|
/** Persistent telemetry queue (default: in-memory). RN apps can back it with storage. */
|
|
579
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;
|
|
580
675
|
}
|
|
581
676
|
interface UnlockInput {
|
|
582
677
|
orderId: string;
|
|
@@ -615,6 +710,8 @@ declare class RelaiClient {
|
|
|
615
710
|
/** Queue-and-retry telemetry uploader (used by unlock; flush opportunistically). */
|
|
616
711
|
readonly telemetryUploader: TelemetryUploader;
|
|
617
712
|
private readonly http;
|
|
713
|
+
/** The app-supplied Stripe module, if any. See `RelaiClientOptions.stripe`. */
|
|
714
|
+
private readonly stripe;
|
|
618
715
|
constructor(options: RelaiClientOptions);
|
|
619
716
|
/** Drain any telemetry queued after a failed send (e.g. on app foreground). */
|
|
620
717
|
flushTelemetry(): Promise<{
|
|
@@ -629,41 +726,6 @@ declare class RelaiClient {
|
|
|
629
726
|
unlock(input: UnlockInput): Promise<UnlockResult>;
|
|
630
727
|
}
|
|
631
728
|
|
|
632
|
-
/**
|
|
633
|
-
* Relai checkout payment sheet (owner spec, 2026-08-02). When an open is
|
|
634
|
-
* gated on payment the API answers 402 `payment_required` with everything
|
|
635
|
-
* Stripe's standard Payment Sheet needs; this module presents that sheet with
|
|
636
|
-
* ZERO app code, provided the optional peer `@stripe/stripe-react-native` is
|
|
637
|
-
* installed. Apps that want their own payment UI simply do not install it (or
|
|
638
|
-
* pass `presentPaymentSheet: false` to `unlock`) and handle the error's
|
|
639
|
-
* `details` themselves.
|
|
640
|
-
*/
|
|
641
|
-
interface PaymentRequiredDetails {
|
|
642
|
-
kind: "prepaid" | "payg_base" | "payg_setup" | "payg_pickup";
|
|
643
|
-
client_secret: string | null;
|
|
644
|
-
/** True when this is a card SAVE (PAYG with a zero base), not a charge. */
|
|
645
|
-
setup: boolean;
|
|
646
|
-
publishable_key: string | null;
|
|
647
|
-
customer_id?: string;
|
|
648
|
-
ephemeral_key?: string;
|
|
649
|
-
statement_suffix?: string | null;
|
|
650
|
-
breakdown: {
|
|
651
|
-
price_cents: number;
|
|
652
|
-
item_cents: number;
|
|
653
|
-
platform_fee_cents: number;
|
|
654
|
-
processing_cents: number;
|
|
655
|
-
total_cents: number;
|
|
656
|
-
};
|
|
657
|
-
}
|
|
658
|
-
/** Narrow an error's `details` into the payment-sheet shape, if it is one. */
|
|
659
|
-
declare function asPaymentRequired(details: Record<string, unknown> | undefined): PaymentRequiredDetails | null;
|
|
660
|
-
/**
|
|
661
|
-
* Present the standard Stripe Payment Sheet for a gate. Returns true when the
|
|
662
|
-
* payment (or card save) completed and the open should be retried; false when
|
|
663
|
-
* the sheet is unavailable (peer not installed / no key) or was canceled.
|
|
664
|
-
*/
|
|
665
|
-
declare function presentRelaiPaymentSheet(details: PaymentRequiredDetails): Promise<boolean>;
|
|
666
|
-
|
|
667
729
|
/**
|
|
668
730
|
* Persistent telemetry queue (owner, 2026-07-24). `MemoryTelemetryQueue` loses
|
|
669
731
|
* anything queued when the app is killed; a React Native app that opens nodes
|
|
@@ -940,4 +1002,4 @@ declare class RelaiTransportError extends RelaiError {
|
|
|
940
1002
|
constructor(message: string);
|
|
941
1003
|
}
|
|
942
1004
|
|
|
943
|
-
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
|
@@ -6,6 +6,12 @@ interface HttpConfig {
|
|
|
6
6
|
getBearer?: () => string | undefined;
|
|
7
7
|
/** Invoked once on `token_expired`; returns true if a refresh succeeded. */
|
|
8
8
|
onTokenExpired?: () => Promise<boolean>;
|
|
9
|
+
/**
|
|
10
|
+
* Invoked on `invalid_token`: the stored session is permanently dead and no
|
|
11
|
+
* refresh can save it (wrong environment, revoked epoch, wrong app). The
|
|
12
|
+
* client drops it so `auth.isSignedIn` goes false.
|
|
13
|
+
*/
|
|
14
|
+
onTokenInvalid?: () => void;
|
|
9
15
|
fetchImpl?: typeof fetch;
|
|
10
16
|
maxRetries?: number;
|
|
11
17
|
}
|
|
@@ -272,6 +278,12 @@ declare class AuthModule {
|
|
|
272
278
|
/** Rotate the token pair. Single-flight: concurrent callers share one refresh. */
|
|
273
279
|
refresh(): Promise<boolean>;
|
|
274
280
|
private doRefresh;
|
|
281
|
+
/**
|
|
282
|
+
* Drop the local session without calling the server. For a session the server
|
|
283
|
+
* has already rejected as permanently invalid, where `signOut()`'s revoke call
|
|
284
|
+
* would just fail on a token that is already dead.
|
|
285
|
+
*/
|
|
286
|
+
clearSession(): void;
|
|
275
287
|
/** Revoke the refresh token and clear local state. */
|
|
276
288
|
signOut(): Promise<void>;
|
|
277
289
|
}
|
|
@@ -563,6 +575,75 @@ interface DeliverOptions {
|
|
|
563
575
|
*/
|
|
564
576
|
declare function deliverOpen(deps: UnlockDeps, open: Open, opts: DeliverOptions): Promise<UnlockResult>;
|
|
565
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
|
+
|
|
566
647
|
interface RelaiClientOptions {
|
|
567
648
|
/** Publishable key (pk_…): safe in client apps. */
|
|
568
649
|
publishableKey?: string;
|
|
@@ -577,6 +658,20 @@ interface RelaiClientOptions {
|
|
|
577
658
|
maxRetries?: number;
|
|
578
659
|
/** Persistent telemetry queue (default: in-memory). RN apps can back it with storage. */
|
|
579
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;
|
|
580
675
|
}
|
|
581
676
|
interface UnlockInput {
|
|
582
677
|
orderId: string;
|
|
@@ -615,6 +710,8 @@ declare class RelaiClient {
|
|
|
615
710
|
/** Queue-and-retry telemetry uploader (used by unlock; flush opportunistically). */
|
|
616
711
|
readonly telemetryUploader: TelemetryUploader;
|
|
617
712
|
private readonly http;
|
|
713
|
+
/** The app-supplied Stripe module, if any. See `RelaiClientOptions.stripe`. */
|
|
714
|
+
private readonly stripe;
|
|
618
715
|
constructor(options: RelaiClientOptions);
|
|
619
716
|
/** Drain any telemetry queued after a failed send (e.g. on app foreground). */
|
|
620
717
|
flushTelemetry(): Promise<{
|
|
@@ -629,41 +726,6 @@ declare class RelaiClient {
|
|
|
629
726
|
unlock(input: UnlockInput): Promise<UnlockResult>;
|
|
630
727
|
}
|
|
631
728
|
|
|
632
|
-
/**
|
|
633
|
-
* Relai checkout payment sheet (owner spec, 2026-08-02). When an open is
|
|
634
|
-
* gated on payment the API answers 402 `payment_required` with everything
|
|
635
|
-
* Stripe's standard Payment Sheet needs; this module presents that sheet with
|
|
636
|
-
* ZERO app code, provided the optional peer `@stripe/stripe-react-native` is
|
|
637
|
-
* installed. Apps that want their own payment UI simply do not install it (or
|
|
638
|
-
* pass `presentPaymentSheet: false` to `unlock`) and handle the error's
|
|
639
|
-
* `details` themselves.
|
|
640
|
-
*/
|
|
641
|
-
interface PaymentRequiredDetails {
|
|
642
|
-
kind: "prepaid" | "payg_base" | "payg_setup" | "payg_pickup";
|
|
643
|
-
client_secret: string | null;
|
|
644
|
-
/** True when this is a card SAVE (PAYG with a zero base), not a charge. */
|
|
645
|
-
setup: boolean;
|
|
646
|
-
publishable_key: string | null;
|
|
647
|
-
customer_id?: string;
|
|
648
|
-
ephemeral_key?: string;
|
|
649
|
-
statement_suffix?: string | null;
|
|
650
|
-
breakdown: {
|
|
651
|
-
price_cents: number;
|
|
652
|
-
item_cents: number;
|
|
653
|
-
platform_fee_cents: number;
|
|
654
|
-
processing_cents: number;
|
|
655
|
-
total_cents: number;
|
|
656
|
-
};
|
|
657
|
-
}
|
|
658
|
-
/** Narrow an error's `details` into the payment-sheet shape, if it is one. */
|
|
659
|
-
declare function asPaymentRequired(details: Record<string, unknown> | undefined): PaymentRequiredDetails | null;
|
|
660
|
-
/**
|
|
661
|
-
* Present the standard Stripe Payment Sheet for a gate. Returns true when the
|
|
662
|
-
* payment (or card save) completed and the open should be retried; false when
|
|
663
|
-
* the sheet is unavailable (peer not installed / no key) or was canceled.
|
|
664
|
-
*/
|
|
665
|
-
declare function presentRelaiPaymentSheet(details: PaymentRequiredDetails): Promise<boolean>;
|
|
666
|
-
|
|
667
729
|
/**
|
|
668
730
|
* Persistent telemetry queue (owner, 2026-07-24). `MemoryTelemetryQueue` loses
|
|
669
731
|
* anything queued when the app is killed; a React Native app that opens nodes
|
|
@@ -940,4 +1002,4 @@ declare class RelaiTransportError extends RelaiError {
|
|
|
940
1002
|
constructor(message: string);
|
|
941
1003
|
}
|
|
942
1004
|
|
|
943
|
-
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-
|
|
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]);
|
|
@@ -27,6 +26,9 @@ var HttpClient = class {
|
|
|
27
26
|
const refreshed = await this.cfg.onTokenExpired();
|
|
28
27
|
if (refreshed) return this.attempt(opts, idem, true);
|
|
29
28
|
}
|
|
29
|
+
if (err instanceof RelaiApiError && err.code === "invalid_token" && this.cfg.onTokenInvalid && !opts.noBearer) {
|
|
30
|
+
this.cfg.onTokenInvalid();
|
|
31
|
+
}
|
|
30
32
|
throw err;
|
|
31
33
|
}
|
|
32
34
|
}
|
|
@@ -95,7 +97,7 @@ var HttpClient = class {
|
|
|
95
97
|
}
|
|
96
98
|
if (!body?.error?.code) body = { error: { code: "http_error", message: `HTTP ${res.status}` } };
|
|
97
99
|
if (body.error.code === "late_fee_due") {
|
|
98
|
-
const { RelaiLateFeeDue: RelaiLateFeeDue2 } = await import('./errors-
|
|
100
|
+
const { RelaiLateFeeDue: RelaiLateFeeDue2 } = await import('./errors-L7B45UIZ.js');
|
|
99
101
|
return new RelaiLateFeeDue2(res.status, body);
|
|
100
102
|
}
|
|
101
103
|
return new RelaiApiError(res.status, body);
|
|
@@ -184,6 +186,14 @@ var AuthModule = class {
|
|
|
184
186
|
return false;
|
|
185
187
|
}
|
|
186
188
|
}
|
|
189
|
+
/**
|
|
190
|
+
* Drop the local session without calling the server. For a session the server
|
|
191
|
+
* has already rejected as permanently invalid, where `signOut()`'s revoke call
|
|
192
|
+
* would just fail on a token that is already dead.
|
|
193
|
+
*/
|
|
194
|
+
clearSession() {
|
|
195
|
+
this.storage.clear();
|
|
196
|
+
}
|
|
187
197
|
/** Revoke the refresh token and clear local state. */
|
|
188
198
|
async signOut() {
|
|
189
199
|
const current = this.storage.get();
|
|
@@ -463,12 +473,14 @@ var DEFAULT_BASE_URL = "https://access.relai.us/api/v1";
|
|
|
463
473
|
var RelaiClient = class {
|
|
464
474
|
constructor(options) {
|
|
465
475
|
if (!options.publishableKey && !options.secretKey) throw new RelaiMissingKeyError();
|
|
476
|
+
this.stripe = options.stripe;
|
|
466
477
|
const storage = options.tokenStorage ?? new MemoryTokenStorage();
|
|
467
478
|
let auth;
|
|
468
479
|
const httpConfig = {
|
|
469
480
|
baseUrl: options.baseUrl ?? DEFAULT_BASE_URL,
|
|
470
481
|
getBearer: () => auth?.accessToken,
|
|
471
482
|
onTokenExpired: () => auth?.refresh() ?? Promise.resolve(false),
|
|
483
|
+
onTokenInvalid: () => auth?.clearSession(),
|
|
472
484
|
...options.publishableKey !== void 0 ? { publishableKey: options.publishableKey } : {},
|
|
473
485
|
...options.secretKey !== void 0 ? { secretKey: options.secretKey } : {},
|
|
474
486
|
...options.fetchImpl !== void 0 ? { fetchImpl: options.fetchImpl } : {},
|
|
@@ -507,11 +519,11 @@ var RelaiClient = class {
|
|
|
507
519
|
try {
|
|
508
520
|
open = await requestOpen();
|
|
509
521
|
} catch (err) {
|
|
510
|
-
const { RelaiApiError: RelaiApiError2 } = await import('./errors-
|
|
522
|
+
const { RelaiApiError: RelaiApiError2 } = await import('./errors-L7B45UIZ.js');
|
|
511
523
|
if (input.presentPaymentSheet !== false && err instanceof RelaiApiError2 && err.code === "payment_required") {
|
|
512
|
-
const { asPaymentRequired: asPaymentRequired2, presentRelaiPaymentSheet: presentRelaiPaymentSheet2 } = await import('./payment-sheet-
|
|
524
|
+
const { asPaymentRequired: asPaymentRequired2, presentRelaiPaymentSheet: presentRelaiPaymentSheet2 } = await import('./payment-sheet-XIZYASSI.js');
|
|
513
525
|
const details = asPaymentRequired2(err.details);
|
|
514
|
-
if (!details || !await presentRelaiPaymentSheet2(details)) throw err;
|
|
526
|
+
if (!details || !await presentRelaiPaymentSheet2(details, this.stripe)) throw err;
|
|
515
527
|
open = await requestOpen();
|
|
516
528
|
} else {
|
|
517
529
|
throw err;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export { asPaymentRequired, presentRelaiPaymentSheet } from './chunk-
|
|
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.
|
|
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",
|
package/dist/chunk-3RG5ZIWI.js
DELETED
|
@@ -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 };
|
package/dist/chunk-TRAEMNHD.js
DELETED
|
@@ -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 };
|