@relai-team/access-sdk 0.16.0 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -144,6 +144,29 @@ A rejection throws `RelaiUnlockRejected` with a `reason`
144
144
  claimed verb; the SDK exposes it as `verbHint` for **logging correlation only**;
145
145
  it is attacker-influenced and never drives control flow.
146
146
 
147
+ **Only one reason is worth retrying.** `NOTREADY` (firmware 1.1.0+) means the
148
+ Parent answered before its key store had finished loading, so the same open a
149
+ moment later can succeed; back off briefly and try again. Every other reason
150
+ means the envelope or the commissioning state is wrong, and re-sending the same
151
+ bytes just burns another nonce. `isRetryableRejectReason(reason)` encodes that,
152
+ and answers `false` for any reason it does not recognise, so firmware newer than
153
+ this package surfaces the rejection to you instead of spinning.
154
+
155
+ ```ts
156
+ import { isRetryableRejectReason, RelaiUnlockRejected } from "@relai-team/access-sdk";
157
+
158
+ try {
159
+ await relai.unlock({ orderId, intent: Intents.Occupy, transport });
160
+ } catch (err) {
161
+ if (err instanceof RelaiUnlockRejected && isRetryableRejectReason(err.reason)) {
162
+ await new Promise((r) => setTimeout(r, 750));
163
+ await relai.unlock({ orderId, intent: Intents.Occupy, transport });
164
+ } else {
165
+ throw err;
166
+ }
167
+ }
168
+ ```
169
+
147
170
  ## Drop-offs & pick-ups (handoff modes)
148
171
 
149
172
  Every order is a drop-off (`Intents.Occupy`) followed by a pick-up
package/dist/index.cjs CHANGED
@@ -1101,8 +1101,12 @@ var REJECT_REASONS = [
1101
1101
  "TAG",
1102
1102
  "NONCE",
1103
1103
  "LOCKED",
1104
- "ROTATE"
1104
+ "ROTATE",
1105
+ "NOTREADY"
1105
1106
  ];
1107
+ function isRetryableRejectReason(reason) {
1108
+ return reason === "NOTREADY";
1109
+ }
1106
1110
  function parseNotifyLine(line) {
1107
1111
  const trimmed = line.trim();
1108
1112
  if (trimmed.startsWith("NONCE ")) {
@@ -1296,6 +1300,7 @@ exports.TelemetryModule = TelemetryModule;
1296
1300
  exports.TelemetryUploader = TelemetryUploader;
1297
1301
  exports.asPaymentRequired = asPaymentRequired;
1298
1302
  exports.deliverOpen = deliverOpen;
1303
+ exports.isRetryableRejectReason = isRetryableRejectReason;
1299
1304
  exports.isStripePublishableKey = isStripePublishableKey;
1300
1305
  exports.parseNotifyLine = parseNotifyLine;
1301
1306
  exports.presentRelaiPaymentSheet = presentRelaiPaymentSheet;
package/dist/index.d.cts CHANGED
@@ -1352,8 +1352,35 @@ type NotifyLine = {
1352
1352
  kind: "passthrough";
1353
1353
  raw: string;
1354
1354
  };
1355
- /** Reject reasons the firmware can emit (documentation/validation aid). */
1356
- declare const REJECT_REASONS: readonly ["B64", "UNTAGGED", "FORMAT", "KEYVERSION", "TAG", "NONCE", "LOCKED", "ROTATE"];
1355
+ /**
1356
+ * Reject reasons the firmware can emit (documentation/validation aid).
1357
+ *
1358
+ * ONE OF THESE IS WORTH RETRYING AND THE REST ARE NOT, which is the whole
1359
+ * reason to enumerate them:
1360
+ *
1361
+ * - `NOTREADY` is TRANSIENT. The Parent rejected before its key store had
1362
+ * finished loading, so the same command a moment later can succeed. Back off
1363
+ * briefly and try again. Firmware 1.1.0 added it; before that this case sent
1364
+ * NO reply at all, so the only symptom was a timeout, which is
1365
+ * indistinguishable from a Parent that is out of range or wedged.
1366
+ * - `B64`, `UNTAGGED`, `FORMAT`, `KEYVERSION`, `TAG`, `NONCE` mean the envelope
1367
+ * was wrong. Retrying the SAME bytes cannot help; mint a fresh token against
1368
+ * a fresh nonce, and if that fails too the key is out of step with the
1369
+ * Parent and it needs re-commissioning.
1370
+ * - `LOCKED` and `ROTATE` are commissioning states. Nothing an app does fixes
1371
+ * them.
1372
+ */
1373
+ declare const REJECT_REASONS: readonly ["B64", "UNTAGGED", "FORMAT", "KEYVERSION", "TAG", "NONCE", "LOCKED", "ROTATE", "NOTREADY"];
1374
+ /**
1375
+ * Is this rejection worth trying again as-is?
1376
+ *
1377
+ * Deliberately a function over the raw string rather than a narrowed type: the
1378
+ * reason arrives from hardware that ships on its own schedule, and a firmware
1379
+ * newer than this package can name a reason it has never heard of. An unknown
1380
+ * reason answers `false`, so a future addition degrades to "surface it to the
1381
+ * caller" rather than to an infinite retry loop.
1382
+ */
1383
+ declare function isRetryableRejectReason(reason: string): boolean;
1357
1384
  /** Parse one already-decoded (plain-text) notify line. */
1358
1385
  declare function parseNotifyLine(line: string): NotifyLine;
1359
1386
 
@@ -1497,7 +1524,13 @@ declare class RelaiMissingKeyError extends RelaiError {
1497
1524
  /** A Parent rejected an authenticated command (parsed from `[AUTH] REJECT`). */
1498
1525
  declare class RelaiUnlockRejected extends RelaiError {
1499
1526
  readonly name = "RelaiUnlockRejected";
1500
- /** B64 | UNTAGGED | FORMAT | KEYVERSION | TAG | NONCE | LOCKED | ROTATE. */
1527
+ /**
1528
+ * B64 | UNTAGGED | FORMAT | KEYVERSION | TAG | NONCE | LOCKED | ROTATE |
1529
+ * NOTREADY.
1530
+ *
1531
+ * `NOTREADY` is the only one worth retrying: the Parent answered before its
1532
+ * key store had loaded. See `isRetryableRejectReason`.
1533
+ */
1501
1534
  readonly reason: string;
1502
1535
  /**
1503
1536
  * Correlation hint only: for tagged-path rejects the Parent echoes the
@@ -1513,4 +1546,4 @@ declare class RelaiTransportError extends RelaiError {
1513
1546
  constructor(message: string);
1514
1547
  }
1515
1548
 
1516
- export { type AccessLinkTarget, AccessLinksModule, type AnyWebhookEvent, type ApiEnvironment, type ApiErrorBody, AppModule, type AppSelf, AuthModule, type BleDeviceLike, type BleManagerLike, BleTransport, type BleTransportOptions, type CommandAck, type DayWindow, 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 OperatingHours, type Order, type OrderPage, 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 };
1549
+ export { type AccessLinkTarget, AccessLinksModule, type AnyWebhookEvent, type ApiEnvironment, type ApiErrorBody, AppModule, type AppSelf, AuthModule, type BleDeviceLike, type BleManagerLike, BleTransport, type BleTransportOptions, type CommandAck, type DayWindow, 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 OperatingHours, type Order, type OrderPage, 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, isRetryableRejectReason, isStripePublishableKey, parseNotifyLine, presentRelaiPaymentSheet, verifyWebhook };
package/dist/index.d.ts CHANGED
@@ -1352,8 +1352,35 @@ type NotifyLine = {
1352
1352
  kind: "passthrough";
1353
1353
  raw: string;
1354
1354
  };
1355
- /** Reject reasons the firmware can emit (documentation/validation aid). */
1356
- declare const REJECT_REASONS: readonly ["B64", "UNTAGGED", "FORMAT", "KEYVERSION", "TAG", "NONCE", "LOCKED", "ROTATE"];
1355
+ /**
1356
+ * Reject reasons the firmware can emit (documentation/validation aid).
1357
+ *
1358
+ * ONE OF THESE IS WORTH RETRYING AND THE REST ARE NOT, which is the whole
1359
+ * reason to enumerate them:
1360
+ *
1361
+ * - `NOTREADY` is TRANSIENT. The Parent rejected before its key store had
1362
+ * finished loading, so the same command a moment later can succeed. Back off
1363
+ * briefly and try again. Firmware 1.1.0 added it; before that this case sent
1364
+ * NO reply at all, so the only symptom was a timeout, which is
1365
+ * indistinguishable from a Parent that is out of range or wedged.
1366
+ * - `B64`, `UNTAGGED`, `FORMAT`, `KEYVERSION`, `TAG`, `NONCE` mean the envelope
1367
+ * was wrong. Retrying the SAME bytes cannot help; mint a fresh token against
1368
+ * a fresh nonce, and if that fails too the key is out of step with the
1369
+ * Parent and it needs re-commissioning.
1370
+ * - `LOCKED` and `ROTATE` are commissioning states. Nothing an app does fixes
1371
+ * them.
1372
+ */
1373
+ declare const REJECT_REASONS: readonly ["B64", "UNTAGGED", "FORMAT", "KEYVERSION", "TAG", "NONCE", "LOCKED", "ROTATE", "NOTREADY"];
1374
+ /**
1375
+ * Is this rejection worth trying again as-is?
1376
+ *
1377
+ * Deliberately a function over the raw string rather than a narrowed type: the
1378
+ * reason arrives from hardware that ships on its own schedule, and a firmware
1379
+ * newer than this package can name a reason it has never heard of. An unknown
1380
+ * reason answers `false`, so a future addition degrades to "surface it to the
1381
+ * caller" rather than to an infinite retry loop.
1382
+ */
1383
+ declare function isRetryableRejectReason(reason: string): boolean;
1357
1384
  /** Parse one already-decoded (plain-text) notify line. */
1358
1385
  declare function parseNotifyLine(line: string): NotifyLine;
1359
1386
 
@@ -1497,7 +1524,13 @@ declare class RelaiMissingKeyError extends RelaiError {
1497
1524
  /** A Parent rejected an authenticated command (parsed from `[AUTH] REJECT`). */
1498
1525
  declare class RelaiUnlockRejected extends RelaiError {
1499
1526
  readonly name = "RelaiUnlockRejected";
1500
- /** B64 | UNTAGGED | FORMAT | KEYVERSION | TAG | NONCE | LOCKED | ROTATE. */
1527
+ /**
1528
+ * B64 | UNTAGGED | FORMAT | KEYVERSION | TAG | NONCE | LOCKED | ROTATE |
1529
+ * NOTREADY.
1530
+ *
1531
+ * `NOTREADY` is the only one worth retrying: the Parent answered before its
1532
+ * key store had loaded. See `isRetryableRejectReason`.
1533
+ */
1501
1534
  readonly reason: string;
1502
1535
  /**
1503
1536
  * Correlation hint only: for tagged-path rejects the Parent echoes the
@@ -1513,4 +1546,4 @@ declare class RelaiTransportError extends RelaiError {
1513
1546
  constructor(message: string);
1514
1547
  }
1515
1548
 
1516
- export { type AccessLinkTarget, AccessLinksModule, type AnyWebhookEvent, type ApiEnvironment, type ApiErrorBody, AppModule, type AppSelf, AuthModule, type BleDeviceLike, type BleManagerLike, BleTransport, type BleTransportOptions, type CommandAck, type DayWindow, 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 OperatingHours, type Order, type OrderPage, 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 };
1549
+ export { type AccessLinkTarget, AccessLinksModule, type AnyWebhookEvent, type ApiEnvironment, type ApiErrorBody, AppModule, type AppSelf, AuthModule, type BleDeviceLike, type BleManagerLike, BleTransport, type BleTransportOptions, type CommandAck, type DayWindow, 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 OperatingHours, type Order, type OrderPage, 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, isRetryableRejectReason, isStripePublishableKey, parseNotifyLine, presentRelaiPaymentSheet, verifyWebhook };
package/dist/index.js CHANGED
@@ -933,8 +933,12 @@ var REJECT_REASONS = [
933
933
  "TAG",
934
934
  "NONCE",
935
935
  "LOCKED",
936
- "ROTATE"
936
+ "ROTATE",
937
+ "NOTREADY"
937
938
  ];
939
+ function isRetryableRejectReason(reason) {
940
+ return reason === "NOTREADY";
941
+ }
938
942
  function parseNotifyLine(line) {
939
943
  const trimmed = line.trim();
940
944
  if (trimmed.startsWith("NONCE ")) {
@@ -1098,4 +1102,4 @@ var Intents = {
1098
1102
  MakeAvailable: "make_available"
1099
1103
  };
1100
1104
 
1101
- export { AccessLinksModule, AppModule, AuthModule, BleTransport, EndUsersModule, ExchangeZonesModule, GrantsModule, Intents, MemoryTelemetryQueue, MemoryTokenStorage, OrdersModule, OverrideLinksModule, PushModule, REJECT_REASONS, RELAI_RX_CHAR, RELAI_TX_CHAR, RELAI_UART_SERVICE, RecipientsModule, RelaiClient, SandboxModule, SimAuthenticatedTransport, SimulatedTransport, StorageTelemetryQueue, TelemetryModule, TelemetryUploader, deliverOpen, parseNotifyLine, verifyWebhook };
1105
+ export { AccessLinksModule, AppModule, AuthModule, BleTransport, EndUsersModule, ExchangeZonesModule, GrantsModule, Intents, MemoryTelemetryQueue, MemoryTokenStorage, OrdersModule, OverrideLinksModule, PushModule, REJECT_REASONS, RELAI_RX_CHAR, RELAI_TX_CHAR, RELAI_UART_SERVICE, RecipientsModule, RelaiClient, SandboxModule, SimAuthenticatedTransport, SimulatedTransport, StorageTelemetryQueue, TelemetryModule, TelemetryUploader, deliverOpen, isRetryableRejectReason, parseNotifyLine, verifyWebhook };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@relai-team/access-sdk",
3
- "version": "0.16.0",
3
+ "version": "0.17.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",