@relai-team/access-sdk 0.12.4 → 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/dist/index.d.cts CHANGED
@@ -307,6 +307,122 @@ interface TelemetryEvent {
307
307
  transport?: "ble" | "simulated";
308
308
  at: string;
309
309
  }
310
+ type PushPlatform = "expo" | "ios" | "android" | "web";
311
+ type SandboxFault = "jammed_door" | "dead_battery" | "out_of_service" | "clear";
312
+ interface SandboxFaultResult {
313
+ ez_id: string;
314
+ node_id: string | null;
315
+ fault: SandboxFault;
316
+ }
317
+ interface AppSelf {
318
+ id: string;
319
+ name: string;
320
+ environment: ApiEnvironment;
321
+ /** Booleans by contract; empty today. */
322
+ feature_flags: Record<string, boolean>;
323
+ webhook_url: string | null;
324
+ /** Null when the app is unmetered (no active subscription). */
325
+ plan: {
326
+ id: string;
327
+ name: string;
328
+ } | null;
329
+ /** Remaining real opens. Null when unmetered. Warn the user before this hits zero. */
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;
341
+ }
342
+ /**
343
+ * Every event the platform can deliver.
344
+ *
345
+ * The SDK had no webhook type at all, so every partner backend hand-cast at the
346
+ * one boundary where a wrong guess is silent: an unhandled event is simply
347
+ * ignored, and a misspelled one never fires. The published contract disagreed
348
+ * with reality in both directions when this was written (it listed a
349
+ * `payment.authorized` that nothing sends, and omitted `order.abandoned`, which
350
+ * the hourly sweep really does send), so these names are now pinned by a test in
351
+ * the platform repo against `lib/webhooks.ts`, which is what `emitWebhook`
352
+ * accepts.
353
+ *
354
+ * There is deliberately no `payment.authorized`: Relai checkout intents capture
355
+ * immediately, so success IS the capture.
356
+ */
357
+ type WebhookEventType = "order.created" | "order.opened" | "order.completed" | "order.cancelled" | "order.refunded" | "order.abandoned" | "payment.captured" | "payment.failed" | "node.out_of_service" | "ez.status_changed";
358
+ /**
359
+ * The envelope every delivery arrives in.
360
+ *
361
+ * `K` is the discriminant, and it has to be a parameter rather than the whole
362
+ * `WebhookEventType` union: with `type: WebhookEventType` on every member,
363
+ * `switch (event.type)` narrows nothing and `event.data` stays the union of all
364
+ * payloads. A consumer typecheck against the built package caught that before
365
+ * this shipped, which is the only reason it is not decoration.
366
+ */
367
+ interface WebhookEvent<T = Record<string, unknown>, K extends WebhookEventType = WebhookEventType> {
368
+ id: string;
369
+ type: K;
370
+ created_at: string;
371
+ data: T;
372
+ }
373
+ /**
374
+ * Payload per event type, so `switch (event.type)` narrows `event.data`.
375
+ *
376
+ * `order.completed` carries `reason` only when the platform completed the order
377
+ * itself rather than a person doing it: today that means a node forced out of
378
+ * service. It used to ship two incompatible shapes depending on which code path
379
+ * fired, with nothing saying so; one shape now, `reason` additive.
380
+ */
381
+ interface WebhookPayloads {
382
+ "order.created": {
383
+ order: Order;
384
+ };
385
+ "order.opened": {
386
+ order: Order;
387
+ open: Open;
388
+ };
389
+ "order.completed": {
390
+ order: Order;
391
+ reason?: "node_out_of_service";
392
+ };
393
+ "order.cancelled": {
394
+ order: Order;
395
+ };
396
+ "order.refunded": {
397
+ order: Order;
398
+ };
399
+ "order.abandoned": {
400
+ order_id: string;
401
+ node_id: string | null;
402
+ };
403
+ "payment.captured": {
404
+ order_id: string;
405
+ amount_cents: number;
406
+ };
407
+ "payment.failed": {
408
+ order_id: string;
409
+ reason?: string;
410
+ };
411
+ "node.out_of_service": {
412
+ node_id: string;
413
+ order_id?: string;
414
+ };
415
+ "ez.status_changed": {
416
+ ez_id: string;
417
+ status: string;
418
+ };
419
+ }
420
+ /** A delivery narrowed to one event type: the argument to a typed handler. */
421
+ type WebhookEventOf<K extends WebhookEventType> = WebhookEvent<WebhookPayloads[K], K>;
422
+ /** The discriminated union to switch on. */
423
+ type AnyWebhookEvent = {
424
+ [K in WebhookEventType]: WebhookEventOf<K>;
425
+ }[WebhookEventType];
310
426
 
311
427
  /**
312
428
  * End-user auth: the OTP flow, rotating refresh (single-flight), and a pluggable
@@ -562,6 +678,76 @@ declare class TelemetryModule {
562
678
  ok?: boolean;
563
679
  } & Record<string, unknown>>;
564
680
  }
681
+ /**
682
+ * Device push tokens.
683
+ *
684
+ * Both docs pages told builders to call `POST /v1/push/tokens` by hand, and the
685
+ * README's snippet sent only a Bearer token, so it 401'd with
686
+ * `missing_publishable_key` while the builder held a perfectly valid session.
687
+ * That is the whole argument for the method existing: the endpoint needs BOTH
688
+ * the API key and the end-user bearer, and the client already knows how to send
689
+ * both.
690
+ */
691
+ declare class PushModule {
692
+ private readonly http;
693
+ constructor(http: HttpClient);
694
+ /**
695
+ * Register this device for handoff and pick-up notifications. Requires a
696
+ * signed-in end user. Safe to call on every launch: re-registering the same
697
+ * token updates it rather than duplicating it.
698
+ */
699
+ register(token: string, platform?: PushPlatform): Promise<{
700
+ ok: boolean;
701
+ }>;
702
+ /** Unregister on sign-out, or the next person to use the device gets their alerts. */
703
+ unregister(token: string): Promise<{
704
+ ok: boolean;
705
+ }>;
706
+ }
707
+ /**
708
+ * Sandbox fault injection.
709
+ *
710
+ * `app/api/v1/sandbox/faults/route.ts` has claimed in a comment that it "backs
711
+ * the SDK's `relai.sandbox.injectFault`" since it was written, and no such
712
+ * method existed. That is the same defect as the documented-but-absent
713
+ * `client.me()`, which a builder found for us: something referring confidently
714
+ * to an SDK surface nobody had built.
715
+ *
716
+ * Sandbox keys only. The platform rejects production keys with `forbidden`, and
717
+ * a non-simulated Exchange Zone with `not_simulated`.
718
+ */
719
+ declare class SandboxModule {
720
+ private readonly http;
721
+ constructor(http: HttpClient);
722
+ /**
723
+ * Force a fault so the app's unhappy paths can be exercised without hardware.
724
+ * `jammed_door` needs a `nodeId`; `dead_battery` applies to the whole
725
+ * Exchange Zone.
726
+ */
727
+ injectFault(input: {
728
+ exchangeZoneId: string;
729
+ fault: Exclude<SandboxFault, "clear">;
730
+ nodeId?: string;
731
+ }): Promise<SandboxFaultResult>;
732
+ /** Clear an injected fault and return the Exchange Zone to service. */
733
+ clearFault(input: {
734
+ exchangeZoneId: string;
735
+ nodeId?: string;
736
+ }): Promise<SandboxFaultResult>;
737
+ }
738
+ /**
739
+ * The calling app itself: configuration, feature flags, plan and token balance.
740
+ *
741
+ * Without this a builder learns they are out of real opens from a door that did
742
+ * not open, which is the worst possible moment and the worst possible messenger.
743
+ * `realTokenBalance` lets an app warn before it gets there.
744
+ */
745
+ declare class AppModule {
746
+ private readonly http;
747
+ constructor(http: HttpClient);
748
+ /** Config for the app the current key belongs to. */
749
+ self(): Promise<AppSelf>;
750
+ }
565
751
 
566
752
  /**
567
753
  * Telemetry queue-and-retry (owner rule 2026-07-23). A delivered-but-unreported
@@ -778,7 +964,28 @@ interface StripeSdk {
778
964
  error?: unknown;
779
965
  }>;
780
966
  }
781
- /** Narrow an error's `details` into the payment-sheet shape, if it is one. */
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
+ */
782
989
  declare function asPaymentRequired(details: Record<string, unknown> | undefined): PaymentRequiredDetails | null;
783
990
  /**
784
991
  * Present the standard Stripe Payment Sheet for a gate. Returns true when the
@@ -856,6 +1063,12 @@ declare class RelaiClient {
856
1063
  /** SERVER ONLY (secret key): your app's end users, name, email, access tag. */
857
1064
  readonly endUsers: EndUsersModule;
858
1065
  readonly telemetry: TelemetryModule;
1066
+ /** Device push tokens for handoff and pick-up alerts. Needs a signed-in end user. */
1067
+ readonly push: PushModule;
1068
+ /** SANDBOX ONLY: inject and clear simulated faults, to exercise unhappy paths. */
1069
+ readonly sandbox: SandboxModule;
1070
+ /** The calling app: config, feature flags, plan and remaining real-open balance. */
1071
+ readonly app: AppModule;
859
1072
  /** Queue-and-retry telemetry uploader (used by unlock; flush opportunistically). */
860
1073
  readonly telemetryUploader: TelemetryUploader;
861
1074
  private readonly http;
@@ -1112,15 +1325,55 @@ declare class RelaiError extends Error {
1112
1325
  readonly name: string;
1113
1326
  constructor(message: string);
1114
1327
  }
1328
+ /** Everything a caller needs to report a failed call without guessing. */
1329
+ interface RelaiErrorContext {
1330
+ /** `x-relai-request-id` from the response. Quote it in a support request. */
1331
+ requestId?: string | undefined;
1332
+ /** `Retry-After`, in seconds, when the server sent one. */
1333
+ retryAfterSeconds?: number | undefined;
1334
+ /** HTTP method of the failed request. */
1335
+ method?: string | undefined;
1336
+ /** Path of the failed request, e.g. `/orders/ord_1/opens`. */
1337
+ path?: string | undefined;
1338
+ }
1115
1339
  /** A structured error response from the platform. */
1116
1340
  declare class RelaiApiError extends RelaiError {
1117
- readonly name = "RelaiApiError";
1341
+ readonly name: string;
1118
1342
  readonly code: string;
1119
1343
  readonly status: number;
1120
1344
  readonly docsUrl: string | undefined;
1121
1345
  /** Machine-readable payload for codes that carry one (e.g. late_fee_due). */
1122
1346
  readonly details: Record<string, unknown> | undefined;
1123
- constructor(status: number, body: ApiErrorBody);
1347
+ /**
1348
+ * The id the platform stamps on EVERY response (`x-relai-request-id`) so a
1349
+ * partner can quote one line and have us find the request. It was being
1350
+ * dropped here, which made the header pointless: the server went to the
1351
+ * trouble of sending it and the SDK threw it away before anyone saw it.
1352
+ */
1353
+ readonly requestId: string | undefined;
1354
+ /** `Retry-After` in seconds. Used internally for backoff and then discarded
1355
+ * until now, so callers implementing their own queueing had to re-parse it. */
1356
+ readonly retryAfterSeconds: number | undefined;
1357
+ readonly method: string | undefined;
1358
+ readonly path: string | undefined;
1359
+ constructor(status: number, body: ApiErrorBody, ctx?: RelaiErrorContext);
1360
+ }
1361
+ /**
1362
+ * The request never reached the platform: no connection, DNS failure, TLS
1363
+ * failure, or the socket died mid-flight.
1364
+ *
1365
+ * This is the SINGLE most common failure on mobile and it used to throw a bare
1366
+ * `RelaiError` carrying nothing but a message string. Callers had no `code` to
1367
+ * branch on and no way to tell "you are offline, try again" apart from "the
1368
+ * platform refused this, do not retry", so the honest handler had to substring
1369
+ * match the message. It extends `RelaiApiError` so `catch (e) { e.code }` works
1370
+ * uniformly, with `status = 0` standing for "no response was ever received".
1371
+ */
1372
+ declare class RelaiNetworkError extends RelaiApiError {
1373
+ readonly name = "RelaiNetworkError";
1374
+ /** The underlying fetch rejection, when the runtime gave us one. */
1375
+ readonly cause: unknown;
1376
+ constructor(message: string, ctx?: RelaiErrorContext, cause?: unknown);
1124
1377
  }
1125
1378
  /**
1126
1379
  * `late_fee_due` (402): a late pick-up fee must be paid before the node opens.
@@ -1132,7 +1385,31 @@ declare class RelaiApiError extends RelaiError {
1132
1385
  declare class RelaiLateFeeDue extends RelaiApiError {
1133
1386
  readonly feeCents: number;
1134
1387
  readonly clientSecret: string | null;
1135
- constructor(status: number, body: ApiErrorBody);
1388
+ constructor(status: number, body: ApiErrorBody, ctx?: RelaiErrorContext);
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);
1136
1413
  }
1137
1414
  /**
1138
1415
  * The "doorway" error: the SDK was called with no publishable key. Thrown
@@ -1163,4 +1440,4 @@ declare class RelaiTransportError extends RelaiError {
1163
1440
  constructor(message: string);
1164
1441
  }
1165
1442
 
1166
- export { type AccessLinkTarget, AccessLinksModule, type ApiEnvironment, type ApiErrorBody, 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, 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 };
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
@@ -307,6 +307,122 @@ interface TelemetryEvent {
307
307
  transport?: "ble" | "simulated";
308
308
  at: string;
309
309
  }
310
+ type PushPlatform = "expo" | "ios" | "android" | "web";
311
+ type SandboxFault = "jammed_door" | "dead_battery" | "out_of_service" | "clear";
312
+ interface SandboxFaultResult {
313
+ ez_id: string;
314
+ node_id: string | null;
315
+ fault: SandboxFault;
316
+ }
317
+ interface AppSelf {
318
+ id: string;
319
+ name: string;
320
+ environment: ApiEnvironment;
321
+ /** Booleans by contract; empty today. */
322
+ feature_flags: Record<string, boolean>;
323
+ webhook_url: string | null;
324
+ /** Null when the app is unmetered (no active subscription). */
325
+ plan: {
326
+ id: string;
327
+ name: string;
328
+ } | null;
329
+ /** Remaining real opens. Null when unmetered. Warn the user before this hits zero. */
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;
341
+ }
342
+ /**
343
+ * Every event the platform can deliver.
344
+ *
345
+ * The SDK had no webhook type at all, so every partner backend hand-cast at the
346
+ * one boundary where a wrong guess is silent: an unhandled event is simply
347
+ * ignored, and a misspelled one never fires. The published contract disagreed
348
+ * with reality in both directions when this was written (it listed a
349
+ * `payment.authorized` that nothing sends, and omitted `order.abandoned`, which
350
+ * the hourly sweep really does send), so these names are now pinned by a test in
351
+ * the platform repo against `lib/webhooks.ts`, which is what `emitWebhook`
352
+ * accepts.
353
+ *
354
+ * There is deliberately no `payment.authorized`: Relai checkout intents capture
355
+ * immediately, so success IS the capture.
356
+ */
357
+ type WebhookEventType = "order.created" | "order.opened" | "order.completed" | "order.cancelled" | "order.refunded" | "order.abandoned" | "payment.captured" | "payment.failed" | "node.out_of_service" | "ez.status_changed";
358
+ /**
359
+ * The envelope every delivery arrives in.
360
+ *
361
+ * `K` is the discriminant, and it has to be a parameter rather than the whole
362
+ * `WebhookEventType` union: with `type: WebhookEventType` on every member,
363
+ * `switch (event.type)` narrows nothing and `event.data` stays the union of all
364
+ * payloads. A consumer typecheck against the built package caught that before
365
+ * this shipped, which is the only reason it is not decoration.
366
+ */
367
+ interface WebhookEvent<T = Record<string, unknown>, K extends WebhookEventType = WebhookEventType> {
368
+ id: string;
369
+ type: K;
370
+ created_at: string;
371
+ data: T;
372
+ }
373
+ /**
374
+ * Payload per event type, so `switch (event.type)` narrows `event.data`.
375
+ *
376
+ * `order.completed` carries `reason` only when the platform completed the order
377
+ * itself rather than a person doing it: today that means a node forced out of
378
+ * service. It used to ship two incompatible shapes depending on which code path
379
+ * fired, with nothing saying so; one shape now, `reason` additive.
380
+ */
381
+ interface WebhookPayloads {
382
+ "order.created": {
383
+ order: Order;
384
+ };
385
+ "order.opened": {
386
+ order: Order;
387
+ open: Open;
388
+ };
389
+ "order.completed": {
390
+ order: Order;
391
+ reason?: "node_out_of_service";
392
+ };
393
+ "order.cancelled": {
394
+ order: Order;
395
+ };
396
+ "order.refunded": {
397
+ order: Order;
398
+ };
399
+ "order.abandoned": {
400
+ order_id: string;
401
+ node_id: string | null;
402
+ };
403
+ "payment.captured": {
404
+ order_id: string;
405
+ amount_cents: number;
406
+ };
407
+ "payment.failed": {
408
+ order_id: string;
409
+ reason?: string;
410
+ };
411
+ "node.out_of_service": {
412
+ node_id: string;
413
+ order_id?: string;
414
+ };
415
+ "ez.status_changed": {
416
+ ez_id: string;
417
+ status: string;
418
+ };
419
+ }
420
+ /** A delivery narrowed to one event type: the argument to a typed handler. */
421
+ type WebhookEventOf<K extends WebhookEventType> = WebhookEvent<WebhookPayloads[K], K>;
422
+ /** The discriminated union to switch on. */
423
+ type AnyWebhookEvent = {
424
+ [K in WebhookEventType]: WebhookEventOf<K>;
425
+ }[WebhookEventType];
310
426
 
311
427
  /**
312
428
  * End-user auth: the OTP flow, rotating refresh (single-flight), and a pluggable
@@ -562,6 +678,76 @@ declare class TelemetryModule {
562
678
  ok?: boolean;
563
679
  } & Record<string, unknown>>;
564
680
  }
681
+ /**
682
+ * Device push tokens.
683
+ *
684
+ * Both docs pages told builders to call `POST /v1/push/tokens` by hand, and the
685
+ * README's snippet sent only a Bearer token, so it 401'd with
686
+ * `missing_publishable_key` while the builder held a perfectly valid session.
687
+ * That is the whole argument for the method existing: the endpoint needs BOTH
688
+ * the API key and the end-user bearer, and the client already knows how to send
689
+ * both.
690
+ */
691
+ declare class PushModule {
692
+ private readonly http;
693
+ constructor(http: HttpClient);
694
+ /**
695
+ * Register this device for handoff and pick-up notifications. Requires a
696
+ * signed-in end user. Safe to call on every launch: re-registering the same
697
+ * token updates it rather than duplicating it.
698
+ */
699
+ register(token: string, platform?: PushPlatform): Promise<{
700
+ ok: boolean;
701
+ }>;
702
+ /** Unregister on sign-out, or the next person to use the device gets their alerts. */
703
+ unregister(token: string): Promise<{
704
+ ok: boolean;
705
+ }>;
706
+ }
707
+ /**
708
+ * Sandbox fault injection.
709
+ *
710
+ * `app/api/v1/sandbox/faults/route.ts` has claimed in a comment that it "backs
711
+ * the SDK's `relai.sandbox.injectFault`" since it was written, and no such
712
+ * method existed. That is the same defect as the documented-but-absent
713
+ * `client.me()`, which a builder found for us: something referring confidently
714
+ * to an SDK surface nobody had built.
715
+ *
716
+ * Sandbox keys only. The platform rejects production keys with `forbidden`, and
717
+ * a non-simulated Exchange Zone with `not_simulated`.
718
+ */
719
+ declare class SandboxModule {
720
+ private readonly http;
721
+ constructor(http: HttpClient);
722
+ /**
723
+ * Force a fault so the app's unhappy paths can be exercised without hardware.
724
+ * `jammed_door` needs a `nodeId`; `dead_battery` applies to the whole
725
+ * Exchange Zone.
726
+ */
727
+ injectFault(input: {
728
+ exchangeZoneId: string;
729
+ fault: Exclude<SandboxFault, "clear">;
730
+ nodeId?: string;
731
+ }): Promise<SandboxFaultResult>;
732
+ /** Clear an injected fault and return the Exchange Zone to service. */
733
+ clearFault(input: {
734
+ exchangeZoneId: string;
735
+ nodeId?: string;
736
+ }): Promise<SandboxFaultResult>;
737
+ }
738
+ /**
739
+ * The calling app itself: configuration, feature flags, plan and token balance.
740
+ *
741
+ * Without this a builder learns they are out of real opens from a door that did
742
+ * not open, which is the worst possible moment and the worst possible messenger.
743
+ * `realTokenBalance` lets an app warn before it gets there.
744
+ */
745
+ declare class AppModule {
746
+ private readonly http;
747
+ constructor(http: HttpClient);
748
+ /** Config for the app the current key belongs to. */
749
+ self(): Promise<AppSelf>;
750
+ }
565
751
 
566
752
  /**
567
753
  * Telemetry queue-and-retry (owner rule 2026-07-23). A delivered-but-unreported
@@ -778,7 +964,28 @@ interface StripeSdk {
778
964
  error?: unknown;
779
965
  }>;
780
966
  }
781
- /** Narrow an error's `details` into the payment-sheet shape, if it is one. */
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
+ */
782
989
  declare function asPaymentRequired(details: Record<string, unknown> | undefined): PaymentRequiredDetails | null;
783
990
  /**
784
991
  * Present the standard Stripe Payment Sheet for a gate. Returns true when the
@@ -856,6 +1063,12 @@ declare class RelaiClient {
856
1063
  /** SERVER ONLY (secret key): your app's end users, name, email, access tag. */
857
1064
  readonly endUsers: EndUsersModule;
858
1065
  readonly telemetry: TelemetryModule;
1066
+ /** Device push tokens for handoff and pick-up alerts. Needs a signed-in end user. */
1067
+ readonly push: PushModule;
1068
+ /** SANDBOX ONLY: inject and clear simulated faults, to exercise unhappy paths. */
1069
+ readonly sandbox: SandboxModule;
1070
+ /** The calling app: config, feature flags, plan and remaining real-open balance. */
1071
+ readonly app: AppModule;
859
1072
  /** Queue-and-retry telemetry uploader (used by unlock; flush opportunistically). */
860
1073
  readonly telemetryUploader: TelemetryUploader;
861
1074
  private readonly http;
@@ -1112,15 +1325,55 @@ declare class RelaiError extends Error {
1112
1325
  readonly name: string;
1113
1326
  constructor(message: string);
1114
1327
  }
1328
+ /** Everything a caller needs to report a failed call without guessing. */
1329
+ interface RelaiErrorContext {
1330
+ /** `x-relai-request-id` from the response. Quote it in a support request. */
1331
+ requestId?: string | undefined;
1332
+ /** `Retry-After`, in seconds, when the server sent one. */
1333
+ retryAfterSeconds?: number | undefined;
1334
+ /** HTTP method of the failed request. */
1335
+ method?: string | undefined;
1336
+ /** Path of the failed request, e.g. `/orders/ord_1/opens`. */
1337
+ path?: string | undefined;
1338
+ }
1115
1339
  /** A structured error response from the platform. */
1116
1340
  declare class RelaiApiError extends RelaiError {
1117
- readonly name = "RelaiApiError";
1341
+ readonly name: string;
1118
1342
  readonly code: string;
1119
1343
  readonly status: number;
1120
1344
  readonly docsUrl: string | undefined;
1121
1345
  /** Machine-readable payload for codes that carry one (e.g. late_fee_due). */
1122
1346
  readonly details: Record<string, unknown> | undefined;
1123
- constructor(status: number, body: ApiErrorBody);
1347
+ /**
1348
+ * The id the platform stamps on EVERY response (`x-relai-request-id`) so a
1349
+ * partner can quote one line and have us find the request. It was being
1350
+ * dropped here, which made the header pointless: the server went to the
1351
+ * trouble of sending it and the SDK threw it away before anyone saw it.
1352
+ */
1353
+ readonly requestId: string | undefined;
1354
+ /** `Retry-After` in seconds. Used internally for backoff and then discarded
1355
+ * until now, so callers implementing their own queueing had to re-parse it. */
1356
+ readonly retryAfterSeconds: number | undefined;
1357
+ readonly method: string | undefined;
1358
+ readonly path: string | undefined;
1359
+ constructor(status: number, body: ApiErrorBody, ctx?: RelaiErrorContext);
1360
+ }
1361
+ /**
1362
+ * The request never reached the platform: no connection, DNS failure, TLS
1363
+ * failure, or the socket died mid-flight.
1364
+ *
1365
+ * This is the SINGLE most common failure on mobile and it used to throw a bare
1366
+ * `RelaiError` carrying nothing but a message string. Callers had no `code` to
1367
+ * branch on and no way to tell "you are offline, try again" apart from "the
1368
+ * platform refused this, do not retry", so the honest handler had to substring
1369
+ * match the message. It extends `RelaiApiError` so `catch (e) { e.code }` works
1370
+ * uniformly, with `status = 0` standing for "no response was ever received".
1371
+ */
1372
+ declare class RelaiNetworkError extends RelaiApiError {
1373
+ readonly name = "RelaiNetworkError";
1374
+ /** The underlying fetch rejection, when the runtime gave us one. */
1375
+ readonly cause: unknown;
1376
+ constructor(message: string, ctx?: RelaiErrorContext, cause?: unknown);
1124
1377
  }
1125
1378
  /**
1126
1379
  * `late_fee_due` (402): a late pick-up fee must be paid before the node opens.
@@ -1132,7 +1385,31 @@ declare class RelaiApiError extends RelaiError {
1132
1385
  declare class RelaiLateFeeDue extends RelaiApiError {
1133
1386
  readonly feeCents: number;
1134
1387
  readonly clientSecret: string | null;
1135
- constructor(status: number, body: ApiErrorBody);
1388
+ constructor(status: number, body: ApiErrorBody, ctx?: RelaiErrorContext);
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);
1136
1413
  }
1137
1414
  /**
1138
1415
  * The "doorway" error: the SDK was called with no publishable key. Thrown
@@ -1163,4 +1440,4 @@ declare class RelaiTransportError extends RelaiError {
1163
1440
  constructor(message: string);
1164
1441
  }
1165
1442
 
1166
- export { type AccessLinkTarget, AccessLinksModule, type ApiEnvironment, type ApiErrorBody, 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, 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 };
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 };