@relai-team/access-sdk 0.8.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/LICENSE +62 -0
- package/README.md +267 -0
- package/dist/chunk-3RG5ZIWI.js +8 -0
- package/dist/chunk-MNXTMLX2.js +50 -0
- package/dist/chunk-TRAEMNHD.js +27 -0
- package/dist/errors-MCGRQUDJ.js +2 -0
- package/dist/index.cjs +1054 -0
- package/dist/index.d.cts +943 -0
- package/dist/index.d.ts +943 -0
- package/dist/index.js +901 -0
- package/dist/payment-sheet-XOZDLRKL.js +2 -0
- package/package.json +68 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
Relai Access SDK License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Relai Group, Inc. All rights reserved.
|
|
4
|
+
|
|
5
|
+
This software (the "SDK") is made publicly available so that developers can
|
|
6
|
+
integrate their applications with the Relai Access platform. It is proprietary
|
|
7
|
+
software, not open source, and the following terms govern all use of it.
|
|
8
|
+
|
|
9
|
+
1. Grant
|
|
10
|
+
|
|
11
|
+
Relai Group, Inc. ("Relai") grants you a non-exclusive, non-transferable,
|
|
12
|
+
revocable, royalty-free license to download, install, and use the SDK, in
|
|
13
|
+
source or compiled form, for the sole purpose of building and operating an
|
|
14
|
+
application that communicates with the Relai Access platform.
|
|
15
|
+
|
|
16
|
+
2. Restrictions
|
|
17
|
+
|
|
18
|
+
You may not:
|
|
19
|
+
|
|
20
|
+
(a) redistribute, sublicense, sell, rent, or otherwise make the SDK
|
|
21
|
+
available to any third party, whether alone or as part of another
|
|
22
|
+
software distribution, except as embedded in your own application;
|
|
23
|
+
(b) modify, adapt, translate, or create derivative works of the SDK, or
|
|
24
|
+
publish a fork of it;
|
|
25
|
+
(c) reverse engineer, decompile, or disassemble the SDK, or attempt to
|
|
26
|
+
derive the firmware command vocabulary, cryptographic scheme, or any
|
|
27
|
+
other protocol detail that the SDK does not itself expose, except to
|
|
28
|
+
the extent that this restriction is unenforceable under applicable law;
|
|
29
|
+
(d) remove or obscure any copyright, trademark, or other proprietary notice;
|
|
30
|
+
(e) use the SDK to access, probe, or interfere with Relai hardware or
|
|
31
|
+
accounts you are not authorized to use.
|
|
32
|
+
|
|
33
|
+
3. Platform terms
|
|
34
|
+
|
|
35
|
+
Use of the SDK against the Relai Access platform additionally requires valid
|
|
36
|
+
API credentials and is governed by the Relai Access Terms and Conditions. This
|
|
37
|
+
license grants no right to access the platform itself.
|
|
38
|
+
|
|
39
|
+
4. Trademarks
|
|
40
|
+
|
|
41
|
+
This license grants no right to use the Relai name, logo, or other trademarks,
|
|
42
|
+
except to state factually that your application integrates with Relai Access.
|
|
43
|
+
|
|
44
|
+
5. No warranty
|
|
45
|
+
|
|
46
|
+
THE SDK IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
47
|
+
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
|
48
|
+
PARTICULAR PURPOSE, AND NONINFRINGEMENT.
|
|
49
|
+
|
|
50
|
+
6. Limitation of liability
|
|
51
|
+
|
|
52
|
+
IN NO EVENT SHALL RELAI BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY,
|
|
53
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM, OUT OF, OR
|
|
54
|
+
IN CONNECTION WITH THE SDK OR ITS USE.
|
|
55
|
+
|
|
56
|
+
7. Termination
|
|
57
|
+
|
|
58
|
+
This license terminates automatically if you breach any term of it, or when
|
|
59
|
+
your authorization to use the Relai Access platform ends. On termination you
|
|
60
|
+
must stop using and remove the SDK from your applications.
|
|
61
|
+
|
|
62
|
+
Questions: hello@relai.us
|
package/README.md
ADDED
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
# @relai-team/access-sdk
|
|
2
|
+
|
|
3
|
+
Open Relai Exchange Zone nodes over BLE, backed by the Relai Access platform.
|
|
4
|
+
|
|
5
|
+
The SDK is a **dumb pipe**. The platform authorizes and mints every command; the
|
|
6
|
+
SDK relays opaque bytes to the tower's Parent controller and reads its response.
|
|
7
|
+
It holds **no keys and no command vocabulary**. Trust lives entirely on the
|
|
8
|
+
server (server-owns-trust).
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
npm install @relai-team/access-sdk
|
|
14
|
+
# For real hardware (React Native), also install the BLE driver:
|
|
15
|
+
npm install react-native-ble-plx
|
|
16
|
+
# For Relai checkout (end users pay at the door), the Stripe sheet:
|
|
17
|
+
npm install @stripe/stripe-react-native
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Quick start
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import { RelaiClient, SimulatedTransport, Intents } from "@relai-team/access-sdk";
|
|
24
|
+
|
|
25
|
+
const relai = new RelaiClient({ publishableKey: "pk_sandbox_…" });
|
|
26
|
+
|
|
27
|
+
// 1. End-user signs in (OTP by email)
|
|
28
|
+
await relai.auth.startOtp("rider@example.com");
|
|
29
|
+
await relai.auth.verifyOtp("rider@example.com", "123456");
|
|
30
|
+
|
|
31
|
+
// 2. Find an Exchange Zone and create an order
|
|
32
|
+
const [ez] = await relai.exchangeZones.near({ lat: 40.7128, lng: -74.006 });
|
|
33
|
+
const order = await relai.orders.create({ exchangeZoneId: ez.id });
|
|
34
|
+
|
|
35
|
+
// 3. Open a node. In sandbox, use SimulatedTransport; on device, BleTransport.
|
|
36
|
+
// The grant names the tower's Parent and Exchange Zone; the SDK selects the
|
|
37
|
+
// Parent and attributes telemetry automatically.
|
|
38
|
+
const transport = new SimulatedTransport();
|
|
39
|
+
|
|
40
|
+
const result = await relai.unlock({
|
|
41
|
+
orderId: order.id,
|
|
42
|
+
intent: Intents.Occupy,
|
|
43
|
+
transport,
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
console.log(result.accepted, result.command); // true "OPEN 3:0"
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## How an open works
|
|
50
|
+
|
|
51
|
+
`relai.unlock(...)` runs the full server-owns-trust sequence:
|
|
52
|
+
|
|
53
|
+
1. `POST /orders/:id/opens` → an **Open** carrying an unlock grant.
|
|
54
|
+
2. `transport.connect(parent)` → a BLE session to the tower's Parent.
|
|
55
|
+
3. `transport.requestNonce()` → writes `CHALLENGE`, reads the Parent's
|
|
56
|
+
single-use **nonce**.
|
|
57
|
+
4. `POST /grants/:id/mint { nonce }` → the platform returns the authenticated,
|
|
58
|
+
**opaque token** signed for that nonce.
|
|
59
|
+
5. `transport.sendCommand(token)` → the token is written **verbatim**; the
|
|
60
|
+
Parent replies `[AUTH] ACCEPT <command>` or `[AUTH] REJECT <reason>`.
|
|
61
|
+
6. Best-effort telemetry.
|
|
62
|
+
|
|
63
|
+
Legacy `relai-plain-v1` towers skip 3–4 (the grant already carries a token).
|
|
64
|
+
|
|
65
|
+
A rejection throws `RelaiUnlockRejected` with a `reason`
|
|
66
|
+
(`TAG` | `NONCE` | `KEYVERSION` | …). On tagged rejects the Parent may echo the
|
|
67
|
+
claimed verb; the SDK exposes it as `verbHint` for **logging correlation only**;
|
|
68
|
+
it is attacker-influenced and never drives control flow.
|
|
69
|
+
|
|
70
|
+
## Drop-offs & pick-ups (handoff modes)
|
|
71
|
+
|
|
72
|
+
Every order is a drop-off (`Intents.Occupy`) followed by a pick-up
|
|
73
|
+
(`Intents.MakeAvailable`). The app's **enabled handoff modes** (set in the
|
|
74
|
+
Relai portal) decide who may pick up; every order resolves to exactly ONE
|
|
75
|
+
mode at creation and keeps it (`orders.create({ handoffMode })` picks one, a
|
|
76
|
+
named recipient implies directed, otherwise the app's default applies):
|
|
77
|
+
|
|
78
|
+
- **self**: the dropper alone; re-opens allowed (self-storage).
|
|
79
|
+
- **directed**: the dropper names one recipient by exact email or `@access-tag`:
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
const match = await relai.recipients.lookup("@sam-r"); // confirm identity
|
|
83
|
+
const order = await relai.orders.create({ exchangeZoneId: ez.id, recipientUserId: match.user_id });
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
A recipient can pause their tag or block a sender in the Relai portal; both
|
|
87
|
+
surface as a plain `not_found` from `recipients.lookup` or `orders.create`.
|
|
88
|
+
Treat `not_found` as "cannot reach this recipient", never as proof the tag
|
|
89
|
+
does not exist, and have the sender re-check the address instead of retrying.
|
|
90
|
+
|
|
91
|
+
- **open**: the drop-off's Open includes a single-use `access_link`
|
|
92
|
+
(`relai.access.app.ez.xxxxxxxxxxxx`). The picker resolves and redeems it:
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
const target = await relai.accessLinks.resolve(code);
|
|
96
|
+
await relai.unlock({ orderId: target.order_id, intent: Intents.MakeAvailable, accessLink: code, transport });
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Directed and open orders have a **pick-up window** (per-app, default 4h). Past
|
|
100
|
+
it, the open can throw `RelaiLateFeeDue` (402): a flat-step fee ($5 / $15 / $30)
|
|
101
|
+
must be paid first: `clientSecret` carries the Stripe PaymentIntent when the
|
|
102
|
+
end-user is the payer; collect it, then retry. Past 24h the order is abandoned.
|
|
103
|
+
On Relai checkout apps the end user is always the payer.
|
|
104
|
+
|
|
105
|
+
Server-side (secret key), `relai.overrideLinks.request({ nodeId })` mints a
|
|
106
|
+
single-use override code that opens a node with no paywall (10 free per org per
|
|
107
|
+
month, then $1.00 each). Redeem via `overrideCode` on the open.
|
|
108
|
+
|
|
109
|
+
## Relai checkout: end users pay, you write no payment code
|
|
110
|
+
|
|
111
|
+
If the app is set to **Relai checkout** in the Relai portal (the default for
|
|
112
|
+
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`; with
|
|
114
|
+
the optional peer `@stripe/stripe-react-native` installed, `unlock()` presents
|
|
115
|
+
the **standard Stripe Payment Sheet** and retries the open by itself:
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
// Exactly the same call as a free open. If payment is due, the sheet
|
|
119
|
+
// appears; once paid (or the card is saved), the door opens.
|
|
120
|
+
await relai.unlock({ orderId: order.id, intent: Intents.Occupy, transport });
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Prices are configured in the portal (per app, with per-Exchange-Zone
|
|
124
|
+
overrides), in two styles:
|
|
125
|
+
|
|
126
|
+
- **Prepaid**: one flat price collected at the drop-off; it covers the whole
|
|
127
|
+
order, including self re-opens and the pick-up.
|
|
128
|
+
- **Pay-as-you-go** (self orders via `Intents.OccupyLongTerm`): a base at
|
|
129
|
+
drop-off, which may be zero (then the sheet only saves the card), plus an
|
|
130
|
+
hourly rate collected when the pick-up open is requested. Guests cannot
|
|
131
|
+
start pay-as-you-go holds; they need a signed-in account so the card can be
|
|
132
|
+
saved.
|
|
133
|
+
|
|
134
|
+
To show prices before any sheet appears, read them off the Exchange Zone
|
|
135
|
+
detail; to show charge state on an order, read `order.checkout`:
|
|
136
|
+
|
|
137
|
+
```ts
|
|
138
|
+
const ez = await relai.exchangeZones.get(ezId);
|
|
139
|
+
ez.end_user_pricing?.prepaid_total_cents; // full sheet total, fees included
|
|
140
|
+
|
|
141
|
+
const order = await relai.orders.get(orderId);
|
|
142
|
+
order.checkout?.drop_off_paid; // true once the drop-off charge settled
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
To build your own payment UI instead, pass `presentPaymentSheet: false` to
|
|
146
|
+
`unlock()` (or simply do not install the Stripe peer) and catch
|
|
147
|
+
`RelaiApiError` with code `payment_required`: `error.details` carries the
|
|
148
|
+
sheet parameters (`client_secret`, `publishable_key`, customer + ephemeral
|
|
149
|
+
key when signed in, and a breakdown of item, Platform Fee, and Processing
|
|
150
|
+
lines). Confirmation never needs a `return_url`; redirect-based payment
|
|
151
|
+
methods are disabled on these intents.
|
|
152
|
+
|
|
153
|
+
Receipts come from Relai by email, itemized the same way. If the app manages
|
|
154
|
+
its own payments instead (**app-managed** mode), none of this fires and opens
|
|
155
|
+
never gate on payment.
|
|
156
|
+
|
|
157
|
+
## Real hardware (React Native)
|
|
158
|
+
|
|
159
|
+
```ts
|
|
160
|
+
import { BleManager } from "react-native-ble-plx";
|
|
161
|
+
import { BleTransport } from "@relai-team/access-sdk";
|
|
162
|
+
|
|
163
|
+
const manager = new BleManager();
|
|
164
|
+
const transport = new BleTransport({
|
|
165
|
+
manager,
|
|
166
|
+
scan: async () => {
|
|
167
|
+
/* drive react-native-ble-plx scanning; return DiscoveredParent[] */
|
|
168
|
+
},
|
|
169
|
+
});
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
`react-native-ble-plx` is an **optional peer dependency**; the core package runs
|
|
173
|
+
in Node (e.g. a partner backend creating orders with a secret key) without it.
|
|
174
|
+
|
|
175
|
+
## Sandbox: authenticated Parent, no hardware
|
|
176
|
+
|
|
177
|
+
To exercise the FULL authenticated open flow (challenge → mint → verify) without
|
|
178
|
+
a bench, `SimAuthenticatedTransport` drives the platform's sandbox "sim Parent"
|
|
179
|
+
over HTTP. The server runs the real firmware verification, so reject reasons
|
|
180
|
+
(`TAG` / `NONCE` / `KEYVERSION` / `FORMAT`) behave like a device: great for
|
|
181
|
+
testing your error handling.
|
|
182
|
+
|
|
183
|
+
```ts
|
|
184
|
+
import { RelaiClient, SimAuthenticatedTransport } from "@relai-team/access-sdk";
|
|
185
|
+
|
|
186
|
+
// One-time, with a SECRET sandbox key (server side): give the EZ's simulated
|
|
187
|
+
// towers a Parent key so opens go authenticated.
|
|
188
|
+
// POST /api/v1/sandbox/parents/provision { ez_id }
|
|
189
|
+
|
|
190
|
+
const client = new RelaiClient({ publishableKey: "pk_sandbox_…" });
|
|
191
|
+
const transport = new SimAuthenticatedTransport({ publishableKey: "pk_sandbox_…" });
|
|
192
|
+
|
|
193
|
+
const result = await client.unlock({ orderId, intent: Intents.Occupy, transport });
|
|
194
|
+
// result.accepted === true, result.command === "OPEN 3:0"
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
`SimulatedTransport` (fully offline, no crypto) is still the right choice for
|
|
198
|
+
plain flow tests; reach for `SimAuthenticatedTransport` only to exercise the
|
|
199
|
+
authenticated path and its reject cases. Sandbox keys only.
|
|
200
|
+
|
|
201
|
+
## Push notifications
|
|
202
|
+
|
|
203
|
+
Register the end-user's device push token so drop-off / pick-up events notify
|
|
204
|
+
them (delivery is enabled server-side per app):
|
|
205
|
+
|
|
206
|
+
```ts
|
|
207
|
+
await fetch(`${baseUrl}/push/tokens`, {
|
|
208
|
+
method: "POST",
|
|
209
|
+
headers: { authorization: `Bearer ${endUserAccessToken}`, "content-type": "application/json" },
|
|
210
|
+
body: JSON.stringify({ token: expoPushToken, platform: "expo" }),
|
|
211
|
+
});
|
|
212
|
+
// DELETE the same route on sign-out.
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
## Offline-durable telemetry
|
|
216
|
+
|
|
217
|
+
Every open reports best-effort telemetry. If the network is down when a node
|
|
218
|
+
opens, the report is queued and retried on the next `client.flushTelemetry()`
|
|
219
|
+
(call it on app foreground / connectivity regained). The default queue is
|
|
220
|
+
in-memory, so it is lost if the app is killed. For an app that opens nodes
|
|
221
|
+
offline, back the queue with persistent storage so nothing is lost across
|
|
222
|
+
restarts: pass `@react-native-async-storage/async-storage` (or any
|
|
223
|
+
`getItem/setItem/removeItem` store) straight in:
|
|
224
|
+
|
|
225
|
+
```ts
|
|
226
|
+
import AsyncStorage from "@react-native-async-storage/async-storage";
|
|
227
|
+
import { RelaiClient, StorageTelemetryQueue } from "@relai-team/access-sdk";
|
|
228
|
+
|
|
229
|
+
const client = new RelaiClient({
|
|
230
|
+
publishableKey,
|
|
231
|
+
telemetryQueue: new StorageTelemetryQueue(AsyncStorage),
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
// e.g. on AppState 'active' or a NetInfo reconnect:
|
|
235
|
+
await client.flushTelemetry();
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
The queue caps at 500 items (oldest dropped) and self-heals from a corrupt
|
|
239
|
+
blob. Telemetry never blocks or fails an unlock.
|
|
240
|
+
|
|
241
|
+
## Verifying webhooks (partner backends)
|
|
242
|
+
|
|
243
|
+
```ts
|
|
244
|
+
import { verifyWebhook } from "@relai-team/access-sdk";
|
|
245
|
+
|
|
246
|
+
const ok = await verifyWebhook({
|
|
247
|
+
payload: rawRequestBody, // the RAW body string, before JSON.parse
|
|
248
|
+
signature: req.headers["x-relai-signature"],
|
|
249
|
+
secret: process.env.RELAI_WEBHOOK_SECRET,
|
|
250
|
+
});
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
Scheme: `X-Relai-Signature: t=<unix>,v1=<hex HMAC-SHA256(secret, "<t>.<rawBody>")>`,
|
|
254
|
+
5-minute replay tolerance by default.
|
|
255
|
+
|
|
256
|
+
## Security notes
|
|
257
|
+
|
|
258
|
+
- The SDK never sees or constructs the command payload; it relays what the
|
|
259
|
+
platform mints. The firmware command vocabulary is not in this package.
|
|
260
|
+
- Commissioning, key rotation, and technician commands (`PROVISION`,
|
|
261
|
+
`PROVISIONLOCK`, `ROTATE`, `FORCE*`, OTA…) are **deliberately absent**; they
|
|
262
|
+
are platform + private-tooling concerns, not the public open path.
|
|
263
|
+
- Secret keys (`sk_…`) are server-only. Never ship one in a client app.
|
|
264
|
+
|
|
265
|
+
## License
|
|
266
|
+
|
|
267
|
+
Proprietary. © Relai Group, Inc. All rights reserved.
|
|
@@ -0,0 +1,8 @@
|
|
|
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 };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// src/errors.ts
|
|
2
|
+
var RelaiError = class extends Error {
|
|
3
|
+
constructor(message) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.name = "RelaiError";
|
|
6
|
+
}
|
|
7
|
+
};
|
|
8
|
+
var RelaiApiError = class extends RelaiError {
|
|
9
|
+
constructor(status, body) {
|
|
10
|
+
super(body.error.message);
|
|
11
|
+
this.name = "RelaiApiError";
|
|
12
|
+
this.code = body.error.code;
|
|
13
|
+
this.status = status;
|
|
14
|
+
this.docsUrl = body.error.docs_url;
|
|
15
|
+
this.details = body.error.details;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
var RelaiLateFeeDue = class extends RelaiApiError {
|
|
19
|
+
constructor(status, body) {
|
|
20
|
+
super(status, body);
|
|
21
|
+
this.feeCents = typeof this.details?.["fee_cents"] === "number" ? this.details["fee_cents"] : 0;
|
|
22
|
+
const cs = this.details?.["client_secret"];
|
|
23
|
+
this.clientSecret = typeof cs === "string" ? cs : null;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
var RelaiMissingKeyError = class extends RelaiError {
|
|
27
|
+
constructor() {
|
|
28
|
+
super(
|
|
29
|
+
'No Relai key configured. Create a client with `new RelaiClient({ publishableKey: "pk_..." })`. Publishable keys are safe in your app; secret keys (sk_) are server-only.'
|
|
30
|
+
);
|
|
31
|
+
this.name = "RelaiMissingKeyError";
|
|
32
|
+
this.code = "missing_publishable_key";
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
var RelaiUnlockRejected = class extends RelaiError {
|
|
36
|
+
constructor(reason, verbHint) {
|
|
37
|
+
super(`Parent rejected the command: ${reason}`);
|
|
38
|
+
this.name = "RelaiUnlockRejected";
|
|
39
|
+
this.reason = reason;
|
|
40
|
+
this.verbHint = verbHint;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
var RelaiTransportError = class extends RelaiError {
|
|
44
|
+
constructor(message) {
|
|
45
|
+
super(message);
|
|
46
|
+
this.name = "RelaiTransportError";
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export { RelaiApiError, RelaiError, RelaiLateFeeDue, RelaiMissingKeyError, RelaiTransportError, RelaiUnlockRejected };
|
|
@@ -0,0 +1,27 @@
|
|
|
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 };
|