@relai-team/access-sdk 0.13.0 → 0.14.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 +38 -2
- package/dist/{chunk-U4CSAG73.js → chunk-B2T3KFBF.js} +9 -1
- package/dist/{chunk-3WZBCXG3.js → chunk-BIHTDL4L.js} +21 -6
- package/dist/errors-NKRGOFB3.js +1 -0
- package/dist/index.cjs +32 -6
- package/dist/index.d.cts +59 -3
- package/dist/index.d.ts +59 -3
- package/dist/index.js +6 -6
- package/dist/payment-sheet-B3X5QQMO.js +1 -0
- package/package.json +1 -1
- package/dist/errors-N4TYPXJ4.js +0 -1
- package/dist/payment-sheet-XIZYASSI.js +0 -1
package/README.md
CHANGED
|
@@ -411,10 +411,18 @@ Faults: `jammed_door`, `dead_battery`, `out_of_service`, and `clear`.
|
|
|
411
411
|
|
|
412
412
|
```ts
|
|
413
413
|
const app = await relai.app.self();
|
|
414
|
-
app.plan;
|
|
415
|
-
app.real_token_balance; // remaining
|
|
414
|
+
app.plan; // { id, name } or null when unmetered
|
|
415
|
+
app.real_token_balance; // remaining REAL opens
|
|
416
|
+
app.sim_token_balance; // remaining SIMULATED opens (0.14.0)
|
|
416
417
|
```
|
|
417
418
|
|
|
419
|
+
An open against a simulated Exchange Zone draws from `sim_token_balance`, not
|
|
420
|
+
the real one, and hitting zero raises `quota_exceeded` on the open exactly as it
|
|
421
|
+
does for real opens. A sandbox can dead-end mid-test, so check this before a
|
|
422
|
+
long test run, not after.
|
|
423
|
+
|
|
424
|
+
Null on either means "no active plan". It does NOT mean unlimited.
|
|
425
|
+
|
|
418
426
|
Worth calling at launch. Without it the first sign that an app is out of real
|
|
419
427
|
opens is a door that did not open, which is both the worst moment to find out
|
|
420
428
|
and the worst possible messenger. Warn while there is still time to top up.
|
|
@@ -443,6 +451,34 @@ There is deliberately no `payment.authorized`: Relai checkout intents capture
|
|
|
443
451
|
immediately, so success IS the capture. The published contract listed one until
|
|
444
452
|
0.13.0, and omitted `order.abandoned`, which really is delivered.
|
|
445
453
|
|
|
454
|
+
## When a payment gate is broken, not declined
|
|
455
|
+
|
|
456
|
+
`unlock()` presents the Stripe Payment Sheet when the platform answers 402
|
|
457
|
+
`payment_required`. If the gate itself is unusable, the SDK throws
|
|
458
|
+
`RelaiConfigError` rather than letting the 402 surface:
|
|
459
|
+
|
|
460
|
+
```ts
|
|
461
|
+
import { RelaiConfigError } from "@relai-team/access-sdk";
|
|
462
|
+
|
|
463
|
+
try {
|
|
464
|
+
await relai.unlock({ orderId, intent: "occupy", transport });
|
|
465
|
+
} catch (err) {
|
|
466
|
+
if (err instanceof RelaiConfigError) {
|
|
467
|
+
// Relai's side is misconfigured. Retrying will not help and the person did
|
|
468
|
+
// nothing wrong. `err.field` names the offending value.
|
|
469
|
+
report(`Relai configuration problem: ${err.field}`);
|
|
470
|
+
} else if (err instanceof RelaiApiError && err.code === "payment_required") {
|
|
471
|
+
// A real payment outcome: declined, or the sheet was cancelled.
|
|
472
|
+
showPaymentNeeded();
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
```
|
|
476
|
+
|
|
477
|
+
Before 0.14.0 these were the same thing. The key was checked for PRESENCE, so a
|
|
478
|
+
malformed value reached Stripe, failed there, and the SDK rethrew the original
|
|
479
|
+
402. An app could not tell "your card was declined" from "Relai's Stripe key is
|
|
480
|
+
wrong", and neither could the person holding the phone.
|
|
481
|
+
|
|
446
482
|
## Offline-durable telemetry
|
|
447
483
|
|
|
448
484
|
Every open reports best-effort telemetry. If the network is down when a node
|
|
@@ -34,6 +34,14 @@ var RelaiLateFeeDue = class extends RelaiApiError {
|
|
|
34
34
|
this.clientSecret = typeof cs === "string" ? cs : null;
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
|
+
var RelaiConfigError = class extends RelaiError {
|
|
38
|
+
constructor(field, message) {
|
|
39
|
+
super(message);
|
|
40
|
+
this.name = "RelaiConfigError";
|
|
41
|
+
this.code = "invalid_gate_configuration";
|
|
42
|
+
this.field = field;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
37
45
|
var RelaiMissingKeyError = class extends RelaiError {
|
|
38
46
|
constructor() {
|
|
39
47
|
super(
|
|
@@ -58,4 +66,4 @@ var RelaiTransportError = class extends RelaiError {
|
|
|
58
66
|
}
|
|
59
67
|
};
|
|
60
68
|
|
|
61
|
-
export { RelaiApiError, RelaiError, RelaiLateFeeDue, RelaiMissingKeyError, RelaiNetworkError, RelaiTransportError, RelaiUnlockRejected };
|
|
69
|
+
export { RelaiApiError, RelaiConfigError, RelaiError, RelaiLateFeeDue, RelaiMissingKeyError, RelaiNetworkError, RelaiTransportError, RelaiUnlockRejected };
|
|
@@ -1,14 +1,29 @@
|
|
|
1
1
|
// src/payment-sheet.ts
|
|
2
|
+
function isStripePublishableKey(v) {
|
|
3
|
+
return typeof v === "string" && /^pk_(test|live)_[A-Za-z0-9]/.test(v);
|
|
4
|
+
}
|
|
5
|
+
function redactForMessage(v) {
|
|
6
|
+
if (typeof v !== "string") return String(v);
|
|
7
|
+
return v.length <= 12 ? v : `${v.slice(0, 12)}\u2026(${v.length} chars)`;
|
|
8
|
+
}
|
|
2
9
|
function asPaymentRequired(details) {
|
|
3
|
-
if (!details || typeof details["
|
|
10
|
+
if (!details || typeof details["kind"] !== "string") return null;
|
|
4
11
|
return details;
|
|
5
12
|
}
|
|
6
13
|
async function presentRelaiPaymentSheet(details, stripe) {
|
|
7
|
-
if (!details.client_secret
|
|
8
|
-
|
|
9
|
-
|
|
14
|
+
if (!details.client_secret) {
|
|
15
|
+
const { RelaiConfigError } = await import('./errors-NKRGOFB3.js');
|
|
16
|
+
throw new RelaiConfigError(
|
|
17
|
+
"client_secret",
|
|
18
|
+
"Relai returned a payment gate with no client secret, so the payment sheet cannot be shown. This is a platform fault, not a declined payment. Quote the request id from the 402 to Relai support."
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
if (!isStripePublishableKey(details.publishable_key)) {
|
|
22
|
+
const { RelaiConfigError } = await import('./errors-NKRGOFB3.js');
|
|
23
|
+
throw new RelaiConfigError(
|
|
24
|
+
"publishable_key",
|
|
25
|
+
`Relai returned "${redactForMessage(details.publishable_key)}" as the Stripe publishable key, which is not one (it must start with pk_test_ or pk_live_). This is a platform misconfiguration, not a declined payment: retrying will not help, and no key on this device can substitute for it. Quote the request id from the 402 to Relai support.`
|
|
10
26
|
);
|
|
11
|
-
return false;
|
|
12
27
|
}
|
|
13
28
|
if (!stripe) {
|
|
14
29
|
console.warn(
|
|
@@ -33,4 +48,4 @@ async function presentRelaiPaymentSheet(details, stripe) {
|
|
|
33
48
|
return !error;
|
|
34
49
|
}
|
|
35
50
|
|
|
36
|
-
export { asPaymentRequired, presentRelaiPaymentSheet };
|
|
51
|
+
export { asPaymentRequired, isStripePublishableKey, presentRelaiPaymentSheet };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { RelaiApiError, RelaiConfigError, RelaiError, RelaiLateFeeDue, RelaiMissingKeyError, RelaiNetworkError, RelaiTransportError, RelaiUnlockRejected } from './chunk-B2T3KFBF.js';
|
package/dist/index.cjs
CHANGED
|
@@ -14,6 +14,7 @@ var __export = (target, all) => {
|
|
|
14
14
|
var errors_exports = {};
|
|
15
15
|
__export(errors_exports, {
|
|
16
16
|
RelaiApiError: () => exports.RelaiApiError,
|
|
17
|
+
RelaiConfigError: () => exports.RelaiConfigError,
|
|
17
18
|
RelaiError: () => exports.RelaiError,
|
|
18
19
|
RelaiLateFeeDue: () => exports.RelaiLateFeeDue,
|
|
19
20
|
RelaiMissingKeyError: () => exports.RelaiMissingKeyError,
|
|
@@ -21,7 +22,7 @@ __export(errors_exports, {
|
|
|
21
22
|
RelaiTransportError: () => exports.RelaiTransportError,
|
|
22
23
|
RelaiUnlockRejected: () => exports.RelaiUnlockRejected
|
|
23
24
|
});
|
|
24
|
-
exports.RelaiError = void 0; exports.RelaiApiError = void 0; exports.RelaiNetworkError = void 0; exports.RelaiLateFeeDue = void 0; exports.RelaiMissingKeyError = void 0; exports.RelaiUnlockRejected = void 0; exports.RelaiTransportError = void 0;
|
|
25
|
+
exports.RelaiError = void 0; exports.RelaiApiError = void 0; exports.RelaiNetworkError = void 0; exports.RelaiLateFeeDue = void 0; exports.RelaiConfigError = void 0; exports.RelaiMissingKeyError = void 0; exports.RelaiUnlockRejected = void 0; exports.RelaiTransportError = void 0;
|
|
25
26
|
var init_errors = __esm({
|
|
26
27
|
"src/errors.ts"() {
|
|
27
28
|
exports.RelaiError = class extends Error {
|
|
@@ -59,6 +60,14 @@ var init_errors = __esm({
|
|
|
59
60
|
this.clientSecret = typeof cs === "string" ? cs : null;
|
|
60
61
|
}
|
|
61
62
|
};
|
|
63
|
+
exports.RelaiConfigError = class extends exports.RelaiError {
|
|
64
|
+
constructor(field, message) {
|
|
65
|
+
super(message);
|
|
66
|
+
this.name = "RelaiConfigError";
|
|
67
|
+
this.code = "invalid_gate_configuration";
|
|
68
|
+
this.field = field;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
62
71
|
exports.RelaiMissingKeyError = class extends exports.RelaiError {
|
|
63
72
|
constructor() {
|
|
64
73
|
super(
|
|
@@ -89,18 +98,34 @@ var init_errors = __esm({
|
|
|
89
98
|
var payment_sheet_exports = {};
|
|
90
99
|
__export(payment_sheet_exports, {
|
|
91
100
|
asPaymentRequired: () => asPaymentRequired,
|
|
101
|
+
isStripePublishableKey: () => isStripePublishableKey,
|
|
92
102
|
presentRelaiPaymentSheet: () => presentRelaiPaymentSheet
|
|
93
103
|
});
|
|
104
|
+
function isStripePublishableKey(v) {
|
|
105
|
+
return typeof v === "string" && /^pk_(test|live)_[A-Za-z0-9]/.test(v);
|
|
106
|
+
}
|
|
107
|
+
function redactForMessage(v) {
|
|
108
|
+
if (typeof v !== "string") return String(v);
|
|
109
|
+
return v.length <= 12 ? v : `${v.slice(0, 12)}\u2026(${v.length} chars)`;
|
|
110
|
+
}
|
|
94
111
|
function asPaymentRequired(details) {
|
|
95
|
-
if (!details || typeof details["
|
|
112
|
+
if (!details || typeof details["kind"] !== "string") return null;
|
|
96
113
|
return details;
|
|
97
114
|
}
|
|
98
115
|
async function presentRelaiPaymentSheet(details, stripe) {
|
|
99
|
-
if (!details.client_secret
|
|
100
|
-
|
|
101
|
-
|
|
116
|
+
if (!details.client_secret) {
|
|
117
|
+
const { RelaiConfigError: RelaiConfigError2 } = await Promise.resolve().then(() => (init_errors(), errors_exports));
|
|
118
|
+
throw new RelaiConfigError2(
|
|
119
|
+
"client_secret",
|
|
120
|
+
"Relai returned a payment gate with no client secret, so the payment sheet cannot be shown. This is a platform fault, not a declined payment. Quote the request id from the 402 to Relai support."
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
if (!isStripePublishableKey(details.publishable_key)) {
|
|
124
|
+
const { RelaiConfigError: RelaiConfigError2 } = await Promise.resolve().then(() => (init_errors(), errors_exports));
|
|
125
|
+
throw new RelaiConfigError2(
|
|
126
|
+
"publishable_key",
|
|
127
|
+
`Relai returned "${redactForMessage(details.publishable_key)}" as the Stripe publishable key, which is not one (it must start with pk_test_ or pk_live_). This is a platform misconfiguration, not a declined payment: retrying will not help, and no key on this device can substitute for it. Quote the request id from the 402 to Relai support.`
|
|
102
128
|
);
|
|
103
|
-
return false;
|
|
104
129
|
}
|
|
105
130
|
if (!stripe) {
|
|
106
131
|
console.warn(
|
|
@@ -1229,6 +1254,7 @@ exports.TelemetryModule = TelemetryModule;
|
|
|
1229
1254
|
exports.TelemetryUploader = TelemetryUploader;
|
|
1230
1255
|
exports.asPaymentRequired = asPaymentRequired;
|
|
1231
1256
|
exports.deliverOpen = deliverOpen;
|
|
1257
|
+
exports.isStripePublishableKey = isStripePublishableKey;
|
|
1232
1258
|
exports.parseNotifyLine = parseNotifyLine;
|
|
1233
1259
|
exports.presentRelaiPaymentSheet = presentRelaiPaymentSheet;
|
|
1234
1260
|
exports.verifyWebhook = verifyWebhook;
|
package/dist/index.d.cts
CHANGED
|
@@ -318,7 +318,8 @@ interface AppSelf {
|
|
|
318
318
|
id: string;
|
|
319
319
|
name: string;
|
|
320
320
|
environment: ApiEnvironment;
|
|
321
|
-
|
|
321
|
+
/** Booleans by contract; empty today. */
|
|
322
|
+
feature_flags: Record<string, boolean>;
|
|
322
323
|
webhook_url: string | null;
|
|
323
324
|
/** Null when the app is unmetered (no active subscription). */
|
|
324
325
|
plan: {
|
|
@@ -327,6 +328,16 @@ interface AppSelf {
|
|
|
327
328
|
} | null;
|
|
328
329
|
/** Remaining real opens. Null when unmetered. Warn the user before this hits zero. */
|
|
329
330
|
real_token_balance: number | null;
|
|
331
|
+
/**
|
|
332
|
+
* Remaining SIMULATED opens (0.14.0). An open against a simulated Exchange
|
|
333
|
+
* Zone draws from this balance rather than the real one, and hitting zero
|
|
334
|
+
* raises `quota_exceeded` on the open exactly as it does for real opens, so a
|
|
335
|
+
* sandbox can dead-end mid-test with no warning.
|
|
336
|
+
*
|
|
337
|
+
* Null means "no active plan", NOT "unlimited": the same rule as
|
|
338
|
+
* `real_token_balance`, on purpose.
|
|
339
|
+
*/
|
|
340
|
+
sim_token_balance: number | null;
|
|
330
341
|
}
|
|
331
342
|
/**
|
|
332
343
|
* Every event the platform can deliver.
|
|
@@ -953,7 +964,28 @@ interface StripeSdk {
|
|
|
953
964
|
error?: unknown;
|
|
954
965
|
}>;
|
|
955
966
|
}
|
|
956
|
-
/**
|
|
967
|
+
/**
|
|
968
|
+
* Is this a Stripe PUBLISHABLE key?
|
|
969
|
+
*
|
|
970
|
+
* Deliberately narrow. A publishable key is public by design and ships inside
|
|
971
|
+
* every app binary, so the only thing worth checking is that it is the right
|
|
972
|
+
* KIND of value. `sk_` is matched by the same prefix rule failing, which is what
|
|
973
|
+
* we want: a secret key here would be a far worse bug than a missing one.
|
|
974
|
+
*/
|
|
975
|
+
declare function isStripePublishableKey(v: unknown): v is string;
|
|
976
|
+
/**
|
|
977
|
+
* Narrow an error's `details` into the payment-sheet shape, if it is one.
|
|
978
|
+
*
|
|
979
|
+
* Narrows on `kind` ALONE (owner, 2026-08-06). It used to also require a string
|
|
980
|
+
* `client_secret`, which meant a gate arriving without one was not recognised as
|
|
981
|
+
* a gate at all: `unlock()` saw null and rethrew the original 402, so a platform
|
|
982
|
+
* fault surfaced to the app as "payment declined". That is the same ambiguity a
|
|
983
|
+
* builder reported for `publishable_key`, one field over.
|
|
984
|
+
*
|
|
985
|
+
* `kind` is the discriminator that says "this IS a payment gate". Whether the
|
|
986
|
+
* gate is USABLE is `presentRelaiPaymentSheet`'s judgement, and it now says so
|
|
987
|
+
* with a `RelaiConfigError` naming the field.
|
|
988
|
+
*/
|
|
957
989
|
declare function asPaymentRequired(details: Record<string, unknown> | undefined): PaymentRequiredDetails | null;
|
|
958
990
|
/**
|
|
959
991
|
* Present the standard Stripe Payment Sheet for a gate. Returns true when the
|
|
@@ -1355,6 +1387,30 @@ declare class RelaiLateFeeDue extends RelaiApiError {
|
|
|
1355
1387
|
readonly clientSecret: string | null;
|
|
1356
1388
|
constructor(status: number, body: ApiErrorBody, ctx?: RelaiErrorContext);
|
|
1357
1389
|
}
|
|
1390
|
+
/**
|
|
1391
|
+
* The platform answered with a gate the app CANNOT act on, because a value it
|
|
1392
|
+
* needs is missing or malformed. A configuration fault, not a payment outcome.
|
|
1393
|
+
*
|
|
1394
|
+
* This exists because the two were indistinguishable (reported by a Relai 3
|
|
1395
|
+
* builder, 2026-08-06). `presentRelaiPaymentSheet` checked
|
|
1396
|
+
* `!details.publishable_key`, which is a presence check where a validity check
|
|
1397
|
+
* belongs: any non-empty string passed, went to `initStripe`, and was rejected
|
|
1398
|
+
* later by `initPaymentSheet`. That returned `false`, and `unlock()` rethrows
|
|
1399
|
+
* the original 402 on `false`, so an app receiving `payment_required` could not
|
|
1400
|
+
* tell "your card was declined" from "Relai's Stripe key is misconfigured".
|
|
1401
|
+
* Diagnosing it took a builder several steps and a packet capture.
|
|
1402
|
+
*
|
|
1403
|
+
* It is deliberately NOT a `payment_required` and never reaches the retry path:
|
|
1404
|
+
* retrying cannot fix it, and nothing the app or the person does will either.
|
|
1405
|
+
* `field` names the offending value so a support message can quote it.
|
|
1406
|
+
*/
|
|
1407
|
+
declare class RelaiConfigError extends RelaiError {
|
|
1408
|
+
readonly name = "RelaiConfigError";
|
|
1409
|
+
readonly code = "invalid_gate_configuration";
|
|
1410
|
+
/** The response field at fault, e.g. `publishable_key`. */
|
|
1411
|
+
readonly field: string;
|
|
1412
|
+
constructor(field: string, message: string);
|
|
1413
|
+
}
|
|
1358
1414
|
/**
|
|
1359
1415
|
* The "doorway" error: the SDK was called with no publishable key. Thrown
|
|
1360
1416
|
* locally (before any request) with actionable guidance, since it's the most
|
|
@@ -1384,4 +1440,4 @@ declare class RelaiTransportError extends RelaiError {
|
|
|
1384
1440
|
constructor(message: string);
|
|
1385
1441
|
}
|
|
1386
1442
|
|
|
1387
|
-
export { type AccessLinkTarget, AccessLinksModule, type AnyWebhookEvent, type ApiEnvironment, type ApiErrorBody, AppModule, type AppSelf, AuthModule, type BleDeviceLike, type BleManagerLike, BleTransport, type BleTransportOptions, type CommandAck, type DeliverOptions, type DiscoveredParent, type EndUser, type EndUserPage, EndUsersModule, type ExchangeZone, type ExchangeZoneDetail, type ExchangeZonePage, ExchangeZonesModule, type GrantAlgorithm, GrantsModule, type HandoffMode, type Intent, Intents, type KeyValueStorage, type Me, MemoryTelemetryQueue, MemoryTokenStorage, type MintedCommand, type NotifyLine, type Open, type Order, type OrderStatusFields, OrdersModule, type OverrideLink, OverrideLinksModule, type ParentTransport, type PaymentRequiredDetails, PushModule, type PushPlatform, type QueuedTelemetry, REJECT_REASONS, RELAI_RX_CHAR, RELAI_TX_CHAR, RELAI_UART_SERVICE, type RecipientMatch, RecipientsModule, RelaiApiError, RelaiClient, type RelaiClientOptions, RelaiError, type RelaiErrorContext, RelaiLateFeeDue, RelaiMissingKeyError, RelaiNetworkError, RelaiTransportError, RelaiUnlockRejected, type SandboxFault, type SandboxFaultResult, SandboxModule, 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, type WebhookEvent, type WebhookEventOf, type WebhookEventType, type WebhookPayloads, asPaymentRequired, deliverOpen, parseNotifyLine, presentRelaiPaymentSheet, verifyWebhook };
|
|
1443
|
+
export { type AccessLinkTarget, AccessLinksModule, type AnyWebhookEvent, type ApiEnvironment, type ApiErrorBody, AppModule, type AppSelf, AuthModule, type BleDeviceLike, type BleManagerLike, BleTransport, type BleTransportOptions, type CommandAck, type DeliverOptions, type DiscoveredParent, type EndUser, type EndUserPage, EndUsersModule, type ExchangeZone, type ExchangeZoneDetail, type ExchangeZonePage, ExchangeZonesModule, type GrantAlgorithm, GrantsModule, type HandoffMode, type Intent, Intents, type KeyValueStorage, type Me, MemoryTelemetryQueue, MemoryTokenStorage, type MintedCommand, type NotifyLine, type Open, type Order, type OrderStatusFields, OrdersModule, type OverrideLink, OverrideLinksModule, type ParentTransport, type PaymentRequiredDetails, PushModule, type PushPlatform, type QueuedTelemetry, REJECT_REASONS, RELAI_RX_CHAR, RELAI_TX_CHAR, RELAI_UART_SERVICE, type RecipientMatch, RecipientsModule, RelaiApiError, RelaiClient, type RelaiClientOptions, RelaiConfigError, RelaiError, type RelaiErrorContext, RelaiLateFeeDue, RelaiMissingKeyError, RelaiNetworkError, RelaiTransportError, RelaiUnlockRejected, type SandboxFault, type SandboxFaultResult, SandboxModule, 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, type WebhookEvent, type WebhookEventOf, type WebhookEventType, type WebhookPayloads, asPaymentRequired, deliverOpen, isStripePublishableKey, parseNotifyLine, presentRelaiPaymentSheet, verifyWebhook };
|
package/dist/index.d.ts
CHANGED
|
@@ -318,7 +318,8 @@ interface AppSelf {
|
|
|
318
318
|
id: string;
|
|
319
319
|
name: string;
|
|
320
320
|
environment: ApiEnvironment;
|
|
321
|
-
|
|
321
|
+
/** Booleans by contract; empty today. */
|
|
322
|
+
feature_flags: Record<string, boolean>;
|
|
322
323
|
webhook_url: string | null;
|
|
323
324
|
/** Null when the app is unmetered (no active subscription). */
|
|
324
325
|
plan: {
|
|
@@ -327,6 +328,16 @@ interface AppSelf {
|
|
|
327
328
|
} | null;
|
|
328
329
|
/** Remaining real opens. Null when unmetered. Warn the user before this hits zero. */
|
|
329
330
|
real_token_balance: number | null;
|
|
331
|
+
/**
|
|
332
|
+
* Remaining SIMULATED opens (0.14.0). An open against a simulated Exchange
|
|
333
|
+
* Zone draws from this balance rather than the real one, and hitting zero
|
|
334
|
+
* raises `quota_exceeded` on the open exactly as it does for real opens, so a
|
|
335
|
+
* sandbox can dead-end mid-test with no warning.
|
|
336
|
+
*
|
|
337
|
+
* Null means "no active plan", NOT "unlimited": the same rule as
|
|
338
|
+
* `real_token_balance`, on purpose.
|
|
339
|
+
*/
|
|
340
|
+
sim_token_balance: number | null;
|
|
330
341
|
}
|
|
331
342
|
/**
|
|
332
343
|
* Every event the platform can deliver.
|
|
@@ -953,7 +964,28 @@ interface StripeSdk {
|
|
|
953
964
|
error?: unknown;
|
|
954
965
|
}>;
|
|
955
966
|
}
|
|
956
|
-
/**
|
|
967
|
+
/**
|
|
968
|
+
* Is this a Stripe PUBLISHABLE key?
|
|
969
|
+
*
|
|
970
|
+
* Deliberately narrow. A publishable key is public by design and ships inside
|
|
971
|
+
* every app binary, so the only thing worth checking is that it is the right
|
|
972
|
+
* KIND of value. `sk_` is matched by the same prefix rule failing, which is what
|
|
973
|
+
* we want: a secret key here would be a far worse bug than a missing one.
|
|
974
|
+
*/
|
|
975
|
+
declare function isStripePublishableKey(v: unknown): v is string;
|
|
976
|
+
/**
|
|
977
|
+
* Narrow an error's `details` into the payment-sheet shape, if it is one.
|
|
978
|
+
*
|
|
979
|
+
* Narrows on `kind` ALONE (owner, 2026-08-06). It used to also require a string
|
|
980
|
+
* `client_secret`, which meant a gate arriving without one was not recognised as
|
|
981
|
+
* a gate at all: `unlock()` saw null and rethrew the original 402, so a platform
|
|
982
|
+
* fault surfaced to the app as "payment declined". That is the same ambiguity a
|
|
983
|
+
* builder reported for `publishable_key`, one field over.
|
|
984
|
+
*
|
|
985
|
+
* `kind` is the discriminator that says "this IS a payment gate". Whether the
|
|
986
|
+
* gate is USABLE is `presentRelaiPaymentSheet`'s judgement, and it now says so
|
|
987
|
+
* with a `RelaiConfigError` naming the field.
|
|
988
|
+
*/
|
|
957
989
|
declare function asPaymentRequired(details: Record<string, unknown> | undefined): PaymentRequiredDetails | null;
|
|
958
990
|
/**
|
|
959
991
|
* Present the standard Stripe Payment Sheet for a gate. Returns true when the
|
|
@@ -1355,6 +1387,30 @@ declare class RelaiLateFeeDue extends RelaiApiError {
|
|
|
1355
1387
|
readonly clientSecret: string | null;
|
|
1356
1388
|
constructor(status: number, body: ApiErrorBody, ctx?: RelaiErrorContext);
|
|
1357
1389
|
}
|
|
1390
|
+
/**
|
|
1391
|
+
* The platform answered with a gate the app CANNOT act on, because a value it
|
|
1392
|
+
* needs is missing or malformed. A configuration fault, not a payment outcome.
|
|
1393
|
+
*
|
|
1394
|
+
* This exists because the two were indistinguishable (reported by a Relai 3
|
|
1395
|
+
* builder, 2026-08-06). `presentRelaiPaymentSheet` checked
|
|
1396
|
+
* `!details.publishable_key`, which is a presence check where a validity check
|
|
1397
|
+
* belongs: any non-empty string passed, went to `initStripe`, and was rejected
|
|
1398
|
+
* later by `initPaymentSheet`. That returned `false`, and `unlock()` rethrows
|
|
1399
|
+
* the original 402 on `false`, so an app receiving `payment_required` could not
|
|
1400
|
+
* tell "your card was declined" from "Relai's Stripe key is misconfigured".
|
|
1401
|
+
* Diagnosing it took a builder several steps and a packet capture.
|
|
1402
|
+
*
|
|
1403
|
+
* It is deliberately NOT a `payment_required` and never reaches the retry path:
|
|
1404
|
+
* retrying cannot fix it, and nothing the app or the person does will either.
|
|
1405
|
+
* `field` names the offending value so a support message can quote it.
|
|
1406
|
+
*/
|
|
1407
|
+
declare class RelaiConfigError extends RelaiError {
|
|
1408
|
+
readonly name = "RelaiConfigError";
|
|
1409
|
+
readonly code = "invalid_gate_configuration";
|
|
1410
|
+
/** The response field at fault, e.g. `publishable_key`. */
|
|
1411
|
+
readonly field: string;
|
|
1412
|
+
constructor(field: string, message: string);
|
|
1413
|
+
}
|
|
1358
1414
|
/**
|
|
1359
1415
|
* The "doorway" error: the SDK was called with no publishable key. Thrown
|
|
1360
1416
|
* locally (before any request) with actionable guidance, since it's the most
|
|
@@ -1384,4 +1440,4 @@ declare class RelaiTransportError extends RelaiError {
|
|
|
1384
1440
|
constructor(message: string);
|
|
1385
1441
|
}
|
|
1386
1442
|
|
|
1387
|
-
export { type AccessLinkTarget, AccessLinksModule, type AnyWebhookEvent, type ApiEnvironment, type ApiErrorBody, AppModule, type AppSelf, AuthModule, type BleDeviceLike, type BleManagerLike, BleTransport, type BleTransportOptions, type CommandAck, type DeliverOptions, type DiscoveredParent, type EndUser, type EndUserPage, EndUsersModule, type ExchangeZone, type ExchangeZoneDetail, type ExchangeZonePage, ExchangeZonesModule, type GrantAlgorithm, GrantsModule, type HandoffMode, type Intent, Intents, type KeyValueStorage, type Me, MemoryTelemetryQueue, MemoryTokenStorage, type MintedCommand, type NotifyLine, type Open, type Order, type OrderStatusFields, OrdersModule, type OverrideLink, OverrideLinksModule, type ParentTransport, type PaymentRequiredDetails, PushModule, type PushPlatform, type QueuedTelemetry, REJECT_REASONS, RELAI_RX_CHAR, RELAI_TX_CHAR, RELAI_UART_SERVICE, type RecipientMatch, RecipientsModule, RelaiApiError, RelaiClient, type RelaiClientOptions, RelaiError, type RelaiErrorContext, RelaiLateFeeDue, RelaiMissingKeyError, RelaiNetworkError, RelaiTransportError, RelaiUnlockRejected, type SandboxFault, type SandboxFaultResult, SandboxModule, 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, type WebhookEvent, type WebhookEventOf, type WebhookEventType, type WebhookPayloads, asPaymentRequired, deliverOpen, parseNotifyLine, presentRelaiPaymentSheet, verifyWebhook };
|
|
1443
|
+
export { type AccessLinkTarget, AccessLinksModule, type AnyWebhookEvent, type ApiEnvironment, type ApiErrorBody, AppModule, type AppSelf, AuthModule, type BleDeviceLike, type BleManagerLike, BleTransport, type BleTransportOptions, type CommandAck, type DeliverOptions, type DiscoveredParent, type EndUser, type EndUserPage, EndUsersModule, type ExchangeZone, type ExchangeZoneDetail, type ExchangeZonePage, ExchangeZonesModule, type GrantAlgorithm, GrantsModule, type HandoffMode, type Intent, Intents, type KeyValueStorage, type Me, MemoryTelemetryQueue, MemoryTokenStorage, type MintedCommand, type NotifyLine, type Open, type Order, type OrderStatusFields, OrdersModule, type OverrideLink, OverrideLinksModule, type ParentTransport, type PaymentRequiredDetails, PushModule, type PushPlatform, type QueuedTelemetry, REJECT_REASONS, RELAI_RX_CHAR, RELAI_TX_CHAR, RELAI_UART_SERVICE, type RecipientMatch, RecipientsModule, RelaiApiError, RelaiClient, type RelaiClientOptions, RelaiConfigError, RelaiError, type RelaiErrorContext, RelaiLateFeeDue, RelaiMissingKeyError, RelaiNetworkError, RelaiTransportError, RelaiUnlockRejected, type SandboxFault, type SandboxFaultResult, SandboxModule, 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, type WebhookEvent, type WebhookEventOf, type WebhookEventType, type WebhookPayloads, asPaymentRequired, deliverOpen, isStripePublishableKey, parseNotifyLine, presentRelaiPaymentSheet, verifyWebhook };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { RelaiApiError, RelaiTransportError, RelaiUnlockRejected, RelaiMissingKeyError, RelaiError, RelaiNetworkError } from './chunk-
|
|
2
|
-
export { RelaiApiError, RelaiError, RelaiLateFeeDue, RelaiMissingKeyError, RelaiNetworkError, RelaiTransportError, RelaiUnlockRejected } from './chunk-
|
|
3
|
-
export { asPaymentRequired, presentRelaiPaymentSheet } from './chunk-
|
|
1
|
+
import { RelaiApiError, RelaiTransportError, RelaiUnlockRejected, RelaiMissingKeyError, RelaiError, RelaiNetworkError } from './chunk-B2T3KFBF.js';
|
|
2
|
+
export { RelaiApiError, RelaiConfigError, RelaiError, RelaiLateFeeDue, RelaiMissingKeyError, RelaiNetworkError, RelaiTransportError, RelaiUnlockRejected } from './chunk-B2T3KFBF.js';
|
|
3
|
+
export { asPaymentRequired, isStripePublishableKey, presentRelaiPaymentSheet } from './chunk-BIHTDL4L.js';
|
|
4
4
|
|
|
5
5
|
// src/http.ts
|
|
6
6
|
var RETRYABLE_STATUS = /* @__PURE__ */ new Set([429, 500, 502, 503, 504]);
|
|
@@ -113,7 +113,7 @@ var HttpClient = class {
|
|
|
113
113
|
path: opts.path
|
|
114
114
|
};
|
|
115
115
|
if (body.error.code === "late_fee_due") {
|
|
116
|
-
const { RelaiLateFeeDue: RelaiLateFeeDue2 } = await import('./errors-
|
|
116
|
+
const { RelaiLateFeeDue: RelaiLateFeeDue2 } = await import('./errors-NKRGOFB3.js');
|
|
117
117
|
return new RelaiLateFeeDue2(res.status, body, ctx);
|
|
118
118
|
}
|
|
119
119
|
return new RelaiApiError(res.status, body, ctx);
|
|
@@ -658,9 +658,9 @@ var RelaiClient = class {
|
|
|
658
658
|
try {
|
|
659
659
|
open = await requestOpen();
|
|
660
660
|
} catch (err) {
|
|
661
|
-
const { RelaiApiError: RelaiApiError2 } = await import('./errors-
|
|
661
|
+
const { RelaiApiError: RelaiApiError2 } = await import('./errors-NKRGOFB3.js');
|
|
662
662
|
if (input.presentPaymentSheet !== false && err instanceof RelaiApiError2 && err.code === "payment_required") {
|
|
663
|
-
const { asPaymentRequired: asPaymentRequired2, presentRelaiPaymentSheet: presentRelaiPaymentSheet2 } = await import('./payment-sheet-
|
|
663
|
+
const { asPaymentRequired: asPaymentRequired2, presentRelaiPaymentSheet: presentRelaiPaymentSheet2 } = await import('./payment-sheet-B3X5QQMO.js');
|
|
664
664
|
const details = asPaymentRequired2(err.details);
|
|
665
665
|
if (!details || !await presentRelaiPaymentSheet2(details, this.stripe)) throw err;
|
|
666
666
|
open = await requestOpen();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { asPaymentRequired, isStripePublishableKey, presentRelaiPaymentSheet } from './chunk-BIHTDL4L.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@relai-team/access-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.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/errors-N4TYPXJ4.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { RelaiApiError, RelaiError, RelaiLateFeeDue, RelaiMissingKeyError, RelaiNetworkError, RelaiTransportError, RelaiUnlockRejected } from './chunk-U4CSAG73.js';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { asPaymentRequired, presentRelaiPaymentSheet } from './chunk-3WZBCXG3.js';
|