@relai-team/access-sdk 0.21.2 → 0.22.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.
@@ -59,6 +59,17 @@ var RelaiUnlockRejected = class extends RelaiError {
59
59
  this.verbHint = verbHint;
60
60
  }
61
61
  };
62
+ var RelaiLockNotActuated = class extends RelaiError {
63
+ constructor(command, detail) {
64
+ super(
65
+ "The Parent accepted the open and the lock did not answer" + (detail ? ` (${detail})` : "") + ". The compartment did not open."
66
+ );
67
+ this.name = "RelaiLockNotActuated";
68
+ this.code = "lock_not_actuated";
69
+ this.command = command;
70
+ this.detail = detail;
71
+ }
72
+ };
62
73
  var RelaiTransportError = class extends RelaiError {
63
74
  constructor(message) {
64
75
  super(message);
@@ -66,4 +77,4 @@ var RelaiTransportError = class extends RelaiError {
66
77
  }
67
78
  };
68
79
 
69
- export { RelaiApiError, RelaiConfigError, RelaiError, RelaiLateFeeDue, RelaiMissingKeyError, RelaiNetworkError, RelaiTransportError, RelaiUnlockRejected };
80
+ export { RelaiApiError, RelaiConfigError, RelaiError, RelaiLateFeeDue, RelaiLockNotActuated, RelaiMissingKeyError, RelaiNetworkError, RelaiTransportError, RelaiUnlockRejected };
@@ -12,14 +12,14 @@ function asPaymentRequired(details) {
12
12
  }
13
13
  async function presentRelaiPaymentSheet(details, stripe) {
14
14
  if (!details.client_secret) {
15
- const { RelaiConfigError } = await import('./errors-NKRGOFB3.js');
15
+ const { RelaiConfigError } = await import('./errors-2PYX6N33.js');
16
16
  throw new RelaiConfigError(
17
17
  "client_secret",
18
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
19
  );
20
20
  }
21
21
  if (!isStripePublishableKey(details.publishable_key)) {
22
- const { RelaiConfigError } = await import('./errors-NKRGOFB3.js');
22
+ const { RelaiConfigError } = await import('./errors-2PYX6N33.js');
23
23
  throw new RelaiConfigError(
24
24
  "publishable_key",
25
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.`
@@ -0,0 +1 @@
1
+ export { RelaiApiError, RelaiConfigError, RelaiError, RelaiLateFeeDue, RelaiLockNotActuated, RelaiMissingKeyError, RelaiNetworkError, RelaiTransportError, RelaiUnlockRejected } from './chunk-KIKYY6KA.js';
package/dist/index.cjs CHANGED
@@ -17,12 +17,13 @@ __export(errors_exports, {
17
17
  RelaiConfigError: () => exports.RelaiConfigError,
18
18
  RelaiError: () => exports.RelaiError,
19
19
  RelaiLateFeeDue: () => exports.RelaiLateFeeDue,
20
+ RelaiLockNotActuated: () => exports.RelaiLockNotActuated,
20
21
  RelaiMissingKeyError: () => exports.RelaiMissingKeyError,
21
22
  RelaiNetworkError: () => exports.RelaiNetworkError,
22
23
  RelaiTransportError: () => exports.RelaiTransportError,
23
24
  RelaiUnlockRejected: () => exports.RelaiUnlockRejected
24
25
  });
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;
26
+ 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.RelaiLockNotActuated = void 0; exports.RelaiTransportError = void 0;
26
27
  var init_errors = __esm({
27
28
  "src/errors.ts"() {
28
29
  exports.RelaiError = class extends Error {
@@ -85,6 +86,17 @@ var init_errors = __esm({
85
86
  this.verbHint = verbHint;
86
87
  }
87
88
  };
89
+ exports.RelaiLockNotActuated = class extends exports.RelaiError {
90
+ constructor(command, detail) {
91
+ super(
92
+ "The Parent accepted the open and the lock did not answer" + (detail ? ` (${detail})` : "") + ". The compartment did not open."
93
+ );
94
+ this.name = "RelaiLockNotActuated";
95
+ this.code = "lock_not_actuated";
96
+ this.command = command;
97
+ this.detail = detail;
98
+ }
99
+ };
88
100
  exports.RelaiTransportError = class extends exports.RelaiError {
89
101
  constructor(message) {
90
102
  super(message);
@@ -756,6 +768,7 @@ init_errors();
756
768
  init_errors();
757
769
 
758
770
  // src/transport/notify.ts
771
+ var LOCK_FAILED = "LOCK_FAILED";
759
772
  var REJECT_REASONS = [
760
773
  "B64",
761
774
  "UNTAGGED",
@@ -788,6 +801,24 @@ function parseNotifyLine(line) {
788
801
  const verbHint = verbParts.length > 0 ? verbParts.join(" ") : void 0;
789
802
  return { kind: "reject", reason: reason ?? "", verbHint };
790
803
  }
804
+ if (trimmed.startsWith("[CMD] ") || trimmed.startsWith("[ERR] ")) {
805
+ const rest = trimmed.slice("[CMD] ".length).trim();
806
+ const failed = /\bFAILED\b/.test(rest);
807
+ const acked = /\bACK\b(?!=)/.test(rest);
808
+ if (failed || acked) {
809
+ const command = rest.replace(/\s*(?:\u2192|->|-)?\s*(?:ACK|FAILED)\b.*$/, "").trim();
810
+ const why = /\(([^)]*)\)/.exec(rest);
811
+ return {
812
+ kind: "actuated",
813
+ ok: acked && !failed,
814
+ command,
815
+ detail: why?.[1]?.trim() || void 0
816
+ };
817
+ }
818
+ if (trimmed.startsWith("[ERR] ")) {
819
+ return { kind: "actuated", ok: false, command: "", detail: rest };
820
+ }
821
+ }
791
822
  return { kind: "passthrough", raw: trimmed };
792
823
  }
793
824
 
@@ -886,6 +917,9 @@ async function deliverOpen(deps, open, opts) {
886
917
  await wait(NOT_READY_BACKOFF_MS);
887
918
  continue;
888
919
  }
920
+ if (err instanceof exports.RelaiUnlockRejected) {
921
+ await reportOutcome(false, err.reason);
922
+ }
889
923
  throw err;
890
924
  }
891
925
  const minted = await deps.grants.mint(grant.grant_id, nonce);
@@ -914,6 +948,9 @@ async function deliverOpen(deps, open, opts) {
914
948
  }
915
949
  if (!ack.accepted) {
916
950
  await reportOutcome(false, ack.rejectReason ?? "UNKNOWN");
951
+ if (ack.rejectReason === LOCK_FAILED) {
952
+ throw new exports.RelaiLockNotActuated(ack.command, ack.detail);
953
+ }
917
954
  throw new exports.RelaiUnlockRejected(ack.rejectReason ?? "UNKNOWN", ack.verbHint);
918
955
  }
919
956
  await reportOutcome(true);
@@ -1347,8 +1384,10 @@ function serialMatches(advertised, granted) {
1347
1384
  var RELAI_UART_SERVICE = "0000ff00-0000-1000-8000-00805f9b34fb";
1348
1385
  var RELAI_RX_CHAR = "0000ff02-0000-1000-8000-00805f9b34fb";
1349
1386
  var RELAI_TX_CHAR = "0000ff03-0000-1000-8000-00805f9b34fb";
1387
+ var CHALLENGE_PAYLOAD = utf8ToBase64("CHALLENGE");
1350
1388
  var MIN_MTU = 110;
1351
1389
  var NOTIFY_TIMEOUT_MS = 8e3;
1390
+ var ACTUATION_TIMEOUT_MS = 2500;
1352
1391
  var CONNECT_TIMEOUT_MS = 1e4;
1353
1392
  var BleTransport = class {
1354
1393
  constructor(opts) {
@@ -1358,6 +1397,7 @@ var BleTransport = class {
1358
1397
  this.scanImpl = opts.scan;
1359
1398
  this.notifyTimeoutMs = opts.notifyTimeoutMs ?? NOTIFY_TIMEOUT_MS;
1360
1399
  this.connectTimeoutMs = opts.connectTimeoutMs ?? CONNECT_TIMEOUT_MS;
1400
+ this.actuationTimeoutMs = opts.actuationTimeoutMs ?? ACTUATION_TIMEOUT_MS;
1361
1401
  }
1362
1402
  /**
1363
1403
  * Relai Parents in range.
@@ -1466,6 +1506,7 @@ var BleTransport = class {
1466
1506
  accept: void 0,
1467
1507
  failed: void 0,
1468
1508
  error: void 0,
1509
+ heldActuation: void 0,
1469
1510
  remove: () => void 0
1470
1511
  };
1471
1512
  const sub = device.monitorCharacteristicForService(
@@ -1486,12 +1527,15 @@ var BleTransport = class {
1486
1527
  } catch {
1487
1528
  return;
1488
1529
  }
1489
- if (state.waiter && state.accept?.(parseNotifyLine(text))) {
1530
+ const parsed = parseNotifyLine(text);
1531
+ if (state.waiter && state.accept?.(parsed)) {
1490
1532
  const resolve = state.waiter;
1491
1533
  state.waiter = void 0;
1492
1534
  state.accept = void 0;
1493
1535
  state.failed = void 0;
1494
1536
  resolve(text);
1537
+ } else if (!state.waiter && parsed.kind === "actuated") {
1538
+ state.heldActuation = text;
1495
1539
  }
1496
1540
  }
1497
1541
  );
@@ -1506,7 +1550,11 @@ var BleTransport = class {
1506
1550
  }
1507
1551
  }
1508
1552
  async requestNonce(session) {
1509
- const line = await this.writeAndAwait(session, utf8ToBase64("CHALLENGE"));
1553
+ const line = await this.writeAndAwait(
1554
+ session,
1555
+ utf8ToBase64(CHALLENGE_PAYLOAD),
1556
+ (p) => p.kind === "nonce" || p.kind === "reject" || p.kind === "accept"
1557
+ );
1510
1558
  const parsed = parseNotifyLine(line);
1511
1559
  if (parsed.kind === "reject") {
1512
1560
  throw new exports.RelaiUnlockRejected(parsed.reason, parsed.verbHint);
@@ -1517,19 +1565,31 @@ var BleTransport = class {
1517
1565
  return parsed.nonceB64Url;
1518
1566
  }
1519
1567
  async sendCommand(session, token) {
1568
+ const state = this.notify.get(session.id);
1569
+ if (state) state.heldActuation = void 0;
1520
1570
  const line = await this.writeAndAwait(
1521
1571
  session,
1522
1572
  utf8ToBase64(token),
1523
1573
  (p) => p.kind === "accept" || p.kind === "reject"
1524
1574
  );
1525
1575
  const parsed = parseNotifyLine(line);
1526
- if (parsed.kind === "accept") {
1527
- return { accepted: true, command: parsed.command, rejectReason: void 0, verbHint: void 0 };
1528
- }
1529
1576
  if (parsed.kind === "reject") {
1530
1577
  return { accepted: false, command: void 0, rejectReason: parsed.reason, verbHint: parsed.verbHint };
1531
1578
  }
1532
- throw new exports.RelaiTransportError(`Expected an [AUTH] ack, got: ${line}`);
1579
+ if (parsed.kind !== "accept") {
1580
+ throw new exports.RelaiTransportError(`Expected an [AUTH] ack, got: ${line}`);
1581
+ }
1582
+ const verdict = await this.awaitActuation(session, parsed.command);
1583
+ if (verdict && !verdict.ok) {
1584
+ return {
1585
+ accepted: false,
1586
+ command: parsed.command,
1587
+ rejectReason: LOCK_FAILED,
1588
+ verbHint: verdict.command || parsed.command,
1589
+ ...verdict.detail !== void 0 ? { detail: verdict.detail } : {}
1590
+ };
1591
+ }
1592
+ return { accepted: true, command: parsed.command, rejectReason: void 0, verbHint: void 0 };
1533
1593
  }
1534
1594
  readTelemetry(_session) {
1535
1595
  return Promise.resolve({});
@@ -1549,6 +1609,47 @@ var BleTransport = class {
1549
1609
  this.devices.delete(session.id);
1550
1610
  }
1551
1611
  }
1612
+ /**
1613
+ * Await the lock's verdict for a command the Parent has already accepted.
1614
+ *
1615
+ * Writes NOTHING: this line answers no write, so there is nothing to send
1616
+ * and nothing to retry. Resolves null when the budget runs out, which the
1617
+ * caller reads as "no verdict" rather than as a failure.
1618
+ */
1619
+ async awaitActuation(session, command) {
1620
+ const state = this.notify.get(session.id);
1621
+ if (!state) return null;
1622
+ const mine = (p) => p.kind === "actuated" && (p.command === command || p.command === "");
1623
+ const held = state.heldActuation;
1624
+ if (held !== void 0) {
1625
+ state.heldActuation = void 0;
1626
+ const parsed2 = parseNotifyLine(held);
1627
+ if (mine(parsed2) && parsed2.kind === "actuated") {
1628
+ return { ok: parsed2.ok, command: parsed2.command, detail: parsed2.detail };
1629
+ }
1630
+ }
1631
+ if (state.error) return null;
1632
+ if (state.waiter) return null;
1633
+ const line = await new Promise((resolve) => {
1634
+ let settled = false;
1635
+ const finish = (value) => {
1636
+ if (settled) return;
1637
+ settled = true;
1638
+ clearTimeout(timer);
1639
+ state.waiter = void 0;
1640
+ state.accept = void 0;
1641
+ state.failed = void 0;
1642
+ resolve(value);
1643
+ };
1644
+ state.accept = mine;
1645
+ state.waiter = (l) => finish(l);
1646
+ state.failed = () => finish(null);
1647
+ const timer = setTimeout(() => finish(null), this.actuationTimeoutMs);
1648
+ });
1649
+ if (line === null) return null;
1650
+ const parsed = parseNotifyLine(line);
1651
+ return parsed.kind === "actuated" ? { ok: parsed.ok, command: parsed.command, detail: parsed.detail } : null;
1652
+ }
1552
1653
  /**
1553
1654
  * Write one value and await the first notify line that matches `accept`.
1554
1655
  *
@@ -1565,8 +1666,14 @@ var BleTransport = class {
1565
1666
  *
1566
1667
  * The subscription itself is opened in `connect` and held for the session, so
1567
1668
  * the gap between the nonce leg and the command leg is covered too.
1669
+ *
1670
+ * `accept` is REQUIRED rather than defaulted. It defaulted to "anything that
1671
+ * is not passthrough", which silently widened every caller the day the
1672
+ * parser learned a new line kind: the challenge leg started accepting the
1673
+ * lock's verdict and reporting a healthy Parent as unreachable. Each caller
1674
+ * names the lines its own write can get.
1568
1675
  */
1569
- writeAndAwait(session, valueBase64, accept = (p) => p.kind !== "passthrough") {
1676
+ writeAndAwait(session, valueBase64, accept) {
1570
1677
  const device = this.devices.get(session.id);
1571
1678
  const state = this.notify.get(session.id);
1572
1679
  if (!device || !state) return Promise.reject(new exports.RelaiTransportError("Not connected."));
package/dist/index.d.cts CHANGED
@@ -997,6 +997,15 @@ interface CommandAck {
997
997
  rejectReason: string | undefined;
998
998
  /** Correlation hint only: untrusted echoed verb. */
999
999
  verbHint: string | undefined;
1000
+ /**
1001
+ * The Parent's own words about why, when it gave any: the parenthesised
1002
+ * cause on `[ERR] <command> -> FAILED (no ACK)`, or the whole explanation on
1003
+ * the lines that name no command. Untrusted echoed bytes, for logs only.
1004
+ *
1005
+ * Optional rather than `| undefined`, so the three fields that have always
1006
+ * been there stay the shape every caller already constructs.
1007
+ */
1008
+ detail?: string;
1000
1009
  }
1001
1010
 
1002
1011
  /**
@@ -1421,6 +1430,8 @@ interface BleTransportOptions {
1421
1430
  notifyTimeoutMs?: number;
1422
1431
  /** Per-candidate connection timeout; see CONNECT_TIMEOUT_MS. */
1423
1432
  connectTimeoutMs?: number;
1433
+ /** How long to wait for the lock's verdict; see ACTUATION_TIMEOUT_MS. */
1434
+ actuationTimeoutMs?: number;
1424
1435
  }
1425
1436
  declare class BleTransport implements ParentTransport {
1426
1437
  private readonly manager;
@@ -1429,6 +1440,7 @@ declare class BleTransport implements ParentTransport {
1429
1440
  private readonly scanImpl;
1430
1441
  private readonly notifyTimeoutMs;
1431
1442
  private readonly connectTimeoutMs;
1443
+ private readonly actuationTimeoutMs;
1432
1444
  constructor(opts: BleTransportOptions);
1433
1445
  /**
1434
1446
  * Relai Parents in range.
@@ -1459,6 +1471,14 @@ declare class BleTransport implements ParentTransport {
1459
1471
  sendCommand(session: Session, token: string): Promise<CommandAck>;
1460
1472
  readTelemetry(_session: Session): Promise<TowerTelemetry>;
1461
1473
  disconnect(session: Session): Promise<void>;
1474
+ /**
1475
+ * Await the lock's verdict for a command the Parent has already accepted.
1476
+ *
1477
+ * Writes NOTHING: this line answers no write, so there is nothing to send
1478
+ * and nothing to retry. Resolves null when the budget runs out, which the
1479
+ * caller reads as "no verdict" rather than as a failure.
1480
+ */
1481
+ private awaitActuation;
1462
1482
  /**
1463
1483
  * Write one value and await the first notify line that matches `accept`.
1464
1484
  *
@@ -1475,6 +1495,12 @@ declare class BleTransport implements ParentTransport {
1475
1495
  *
1476
1496
  * The subscription itself is opened in `connect` and held for the session, so
1477
1497
  * the gap between the nonce leg and the command leg is covered too.
1498
+ *
1499
+ * `accept` is REQUIRED rather than defaulted. It defaulted to "anything that
1500
+ * is not passthrough", which silently widened every caller the day the
1501
+ * parser learned a new line kind: the challenge leg started accepting the
1502
+ * lock's verdict and reporting a healthy Parent as unreachable. Each caller
1503
+ * names the lines its own write can get.
1478
1504
  */
1479
1505
  private writeAndAwait;
1480
1506
  }
@@ -1491,6 +1517,15 @@ declare class BleTransport implements ParentTransport {
1491
1517
  * NONCE <b64url>
1492
1518
  * [AUTH] ACCEPT <command> (emitted at verify time, before output)
1493
1519
  * [AUTH] REJECT <reason> [verb] (verb echoed only on tagged-path rejects)
1520
+ * [CMD] <command> -> ACK (the lock answered)
1521
+ * [ERR] <command> -> FAILED [(why)] (it did not)
1522
+ *
1523
+ * THE ACCEPT IS NOT THE OPEN. `Commands::handleInput` notifies
1524
+ * `[AUTH] ACCEPT <command>` the moment the tag verifies, then pushes the
1525
+ * command onto a queue; `Commands::loop` dispatches it afterwards and notifies
1526
+ * the lock's answer as a SECOND line. So a Parent that verified a token and
1527
+ * then failed to move the lock says both, and reading only the first reports a
1528
+ * compartment as open while its door is shut.
1494
1529
  *
1495
1530
  * SECURITY: on a REJECT the echoed verb is ATTACKER-CONTROLLED bytes reflected
1496
1531
  * by the Parent. It is surfaced as `verbHint` for correlation/logging only and
@@ -1506,28 +1541,27 @@ type NotifyLine = {
1506
1541
  kind: "reject";
1507
1542
  reason: string;
1508
1543
  verbHint: string | undefined;
1509
- } | {
1510
- kind: "passthrough";
1511
- raw: string;
1512
- };
1544
+ }
1513
1545
  /**
1514
- * Reject reasons the firmware can emit (documentation/validation aid).
1546
+ * What the lock did, which arrives after the accept.
1515
1547
  *
1516
- * ONE OF THESE IS WORTH RETRYING AND THE REST ARE NOT, which is the whole
1517
- * reason to enumerate them:
1548
+ * `command` is the Parent's echo of the verb it ran, e.g. `OPEN 3:0`, and is
1549
+ * empty on the lines that report a command dropped before dispatch (a full
1550
+ * queue), where the firmware names no verb. `detail` is the parenthesised
1551
+ * cause when there is one (`no ACK`).
1518
1552
  *
1519
- * - `NOTREADY` is TRANSIENT. The Parent rejected before its key store had
1520
- * finished loading, so the same command a moment later can succeed. Back off
1521
- * briefly and try again. Firmware 1.1.0 added it; before that this case sent
1522
- * NO reply at all, so the only symptom was a timeout, which is
1523
- * indistinguishable from a Parent that is out of range or wedged.
1524
- * - `B64`, `UNTAGGED`, `FORMAT`, `KEYVERSION`, `TAG`, `NONCE` mean the envelope
1525
- * was wrong. Retrying the SAME bytes cannot help; mint a fresh token against
1526
- * a fresh nonce, and if that fails too the key is out of step with the
1527
- * Parent and it needs re-commissioning.
1528
- * - `LOCKED` and `ROTATE` are commissioning states. Nothing an app does fixes
1529
- * them.
1553
+ * SECURITY: like `verbHint`, both fields are bytes the Parent chose. They
1554
+ * correlate and they log; `ok` is the only thing that decides anything.
1530
1555
  */
1556
+ | {
1557
+ kind: "actuated";
1558
+ ok: boolean;
1559
+ command: string;
1560
+ detail: string | undefined;
1561
+ } | {
1562
+ kind: "passthrough";
1563
+ raw: string;
1564
+ };
1531
1565
  declare const REJECT_REASONS: readonly ["B64", "UNTAGGED", "FORMAT", "KEYVERSION", "TAG", "NONCE", "LOCKED", "ROTATE", "NOTREADY"];
1532
1566
  /**
1533
1567
  * Is this rejection worth trying again as-is?
@@ -1768,10 +1802,32 @@ declare class RelaiUnlockRejected extends RelaiError {
1768
1802
  readonly verbHint: string | undefined;
1769
1803
  constructor(reason: string, verbHint?: string);
1770
1804
  }
1805
+ /**
1806
+ * The Parent verified the command and then the lock did not open.
1807
+ *
1808
+ * Its own class, because `RelaiUnlockRejected` would say "Parent rejected the
1809
+ * command" and that is the opposite of what happened: the token was good, the
1810
+ * Parent accepted it, and the hardware past the Parent did not answer. The
1811
+ * distinction is the whole point for whoever reads this. A rejection means
1812
+ * fix the credential; this means go and look at the compartment.
1813
+ *
1814
+ * Nothing about it is retryable from the app. The tag verified, so the nonce
1815
+ * is spent, and a lock that did not answer will not answer to the same command
1816
+ * a second later. A person needs to open it another way.
1817
+ */
1818
+ declare class RelaiLockNotActuated extends RelaiError {
1819
+ readonly name = "RelaiLockNotActuated";
1820
+ readonly code = "lock_not_actuated";
1821
+ /** The Parent's echo of the command it ran, e.g. `OPEN 3:0`. Untrusted. */
1822
+ readonly command: string | undefined;
1823
+ /** The Parent's own words, when it gave any (`no ACK`). Untrusted. */
1824
+ readonly detail: string | undefined;
1825
+ constructor(command?: string, detail?: string);
1826
+ }
1771
1827
  /** The BLE/transport layer failed (connect, write, timeout, no nonce, …). */
1772
1828
  declare class RelaiTransportError extends RelaiError {
1773
1829
  readonly name = "RelaiTransportError";
1774
1830
  constructor(message: string);
1775
1831
  }
1776
1832
 
1777
- 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, needsFreshNonce, parseAdvertisedSerial, parseNotifyLine, presentRelaiPaymentSheet, serialMatches, verifyWebhook };
1833
+ 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, RelaiLockNotActuated, 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, needsFreshNonce, parseAdvertisedSerial, parseNotifyLine, presentRelaiPaymentSheet, serialMatches, verifyWebhook };
package/dist/index.d.ts CHANGED
@@ -997,6 +997,15 @@ interface CommandAck {
997
997
  rejectReason: string | undefined;
998
998
  /** Correlation hint only: untrusted echoed verb. */
999
999
  verbHint: string | undefined;
1000
+ /**
1001
+ * The Parent's own words about why, when it gave any: the parenthesised
1002
+ * cause on `[ERR] <command> -> FAILED (no ACK)`, or the whole explanation on
1003
+ * the lines that name no command. Untrusted echoed bytes, for logs only.
1004
+ *
1005
+ * Optional rather than `| undefined`, so the three fields that have always
1006
+ * been there stay the shape every caller already constructs.
1007
+ */
1008
+ detail?: string;
1000
1009
  }
1001
1010
 
1002
1011
  /**
@@ -1421,6 +1430,8 @@ interface BleTransportOptions {
1421
1430
  notifyTimeoutMs?: number;
1422
1431
  /** Per-candidate connection timeout; see CONNECT_TIMEOUT_MS. */
1423
1432
  connectTimeoutMs?: number;
1433
+ /** How long to wait for the lock's verdict; see ACTUATION_TIMEOUT_MS. */
1434
+ actuationTimeoutMs?: number;
1424
1435
  }
1425
1436
  declare class BleTransport implements ParentTransport {
1426
1437
  private readonly manager;
@@ -1429,6 +1440,7 @@ declare class BleTransport implements ParentTransport {
1429
1440
  private readonly scanImpl;
1430
1441
  private readonly notifyTimeoutMs;
1431
1442
  private readonly connectTimeoutMs;
1443
+ private readonly actuationTimeoutMs;
1432
1444
  constructor(opts: BleTransportOptions);
1433
1445
  /**
1434
1446
  * Relai Parents in range.
@@ -1459,6 +1471,14 @@ declare class BleTransport implements ParentTransport {
1459
1471
  sendCommand(session: Session, token: string): Promise<CommandAck>;
1460
1472
  readTelemetry(_session: Session): Promise<TowerTelemetry>;
1461
1473
  disconnect(session: Session): Promise<void>;
1474
+ /**
1475
+ * Await the lock's verdict for a command the Parent has already accepted.
1476
+ *
1477
+ * Writes NOTHING: this line answers no write, so there is nothing to send
1478
+ * and nothing to retry. Resolves null when the budget runs out, which the
1479
+ * caller reads as "no verdict" rather than as a failure.
1480
+ */
1481
+ private awaitActuation;
1462
1482
  /**
1463
1483
  * Write one value and await the first notify line that matches `accept`.
1464
1484
  *
@@ -1475,6 +1495,12 @@ declare class BleTransport implements ParentTransport {
1475
1495
  *
1476
1496
  * The subscription itself is opened in `connect` and held for the session, so
1477
1497
  * the gap between the nonce leg and the command leg is covered too.
1498
+ *
1499
+ * `accept` is REQUIRED rather than defaulted. It defaulted to "anything that
1500
+ * is not passthrough", which silently widened every caller the day the
1501
+ * parser learned a new line kind: the challenge leg started accepting the
1502
+ * lock's verdict and reporting a healthy Parent as unreachable. Each caller
1503
+ * names the lines its own write can get.
1478
1504
  */
1479
1505
  private writeAndAwait;
1480
1506
  }
@@ -1491,6 +1517,15 @@ declare class BleTransport implements ParentTransport {
1491
1517
  * NONCE <b64url>
1492
1518
  * [AUTH] ACCEPT <command> (emitted at verify time, before output)
1493
1519
  * [AUTH] REJECT <reason> [verb] (verb echoed only on tagged-path rejects)
1520
+ * [CMD] <command> -> ACK (the lock answered)
1521
+ * [ERR] <command> -> FAILED [(why)] (it did not)
1522
+ *
1523
+ * THE ACCEPT IS NOT THE OPEN. `Commands::handleInput` notifies
1524
+ * `[AUTH] ACCEPT <command>` the moment the tag verifies, then pushes the
1525
+ * command onto a queue; `Commands::loop` dispatches it afterwards and notifies
1526
+ * the lock's answer as a SECOND line. So a Parent that verified a token and
1527
+ * then failed to move the lock says both, and reading only the first reports a
1528
+ * compartment as open while its door is shut.
1494
1529
  *
1495
1530
  * SECURITY: on a REJECT the echoed verb is ATTACKER-CONTROLLED bytes reflected
1496
1531
  * by the Parent. It is surfaced as `verbHint` for correlation/logging only and
@@ -1506,28 +1541,27 @@ type NotifyLine = {
1506
1541
  kind: "reject";
1507
1542
  reason: string;
1508
1543
  verbHint: string | undefined;
1509
- } | {
1510
- kind: "passthrough";
1511
- raw: string;
1512
- };
1544
+ }
1513
1545
  /**
1514
- * Reject reasons the firmware can emit (documentation/validation aid).
1546
+ * What the lock did, which arrives after the accept.
1515
1547
  *
1516
- * ONE OF THESE IS WORTH RETRYING AND THE REST ARE NOT, which is the whole
1517
- * reason to enumerate them:
1548
+ * `command` is the Parent's echo of the verb it ran, e.g. `OPEN 3:0`, and is
1549
+ * empty on the lines that report a command dropped before dispatch (a full
1550
+ * queue), where the firmware names no verb. `detail` is the parenthesised
1551
+ * cause when there is one (`no ACK`).
1518
1552
  *
1519
- * - `NOTREADY` is TRANSIENT. The Parent rejected before its key store had
1520
- * finished loading, so the same command a moment later can succeed. Back off
1521
- * briefly and try again. Firmware 1.1.0 added it; before that this case sent
1522
- * NO reply at all, so the only symptom was a timeout, which is
1523
- * indistinguishable from a Parent that is out of range or wedged.
1524
- * - `B64`, `UNTAGGED`, `FORMAT`, `KEYVERSION`, `TAG`, `NONCE` mean the envelope
1525
- * was wrong. Retrying the SAME bytes cannot help; mint a fresh token against
1526
- * a fresh nonce, and if that fails too the key is out of step with the
1527
- * Parent and it needs re-commissioning.
1528
- * - `LOCKED` and `ROTATE` are commissioning states. Nothing an app does fixes
1529
- * them.
1553
+ * SECURITY: like `verbHint`, both fields are bytes the Parent chose. They
1554
+ * correlate and they log; `ok` is the only thing that decides anything.
1530
1555
  */
1556
+ | {
1557
+ kind: "actuated";
1558
+ ok: boolean;
1559
+ command: string;
1560
+ detail: string | undefined;
1561
+ } | {
1562
+ kind: "passthrough";
1563
+ raw: string;
1564
+ };
1531
1565
  declare const REJECT_REASONS: readonly ["B64", "UNTAGGED", "FORMAT", "KEYVERSION", "TAG", "NONCE", "LOCKED", "ROTATE", "NOTREADY"];
1532
1566
  /**
1533
1567
  * Is this rejection worth trying again as-is?
@@ -1768,10 +1802,32 @@ declare class RelaiUnlockRejected extends RelaiError {
1768
1802
  readonly verbHint: string | undefined;
1769
1803
  constructor(reason: string, verbHint?: string);
1770
1804
  }
1805
+ /**
1806
+ * The Parent verified the command and then the lock did not open.
1807
+ *
1808
+ * Its own class, because `RelaiUnlockRejected` would say "Parent rejected the
1809
+ * command" and that is the opposite of what happened: the token was good, the
1810
+ * Parent accepted it, and the hardware past the Parent did not answer. The
1811
+ * distinction is the whole point for whoever reads this. A rejection means
1812
+ * fix the credential; this means go and look at the compartment.
1813
+ *
1814
+ * Nothing about it is retryable from the app. The tag verified, so the nonce
1815
+ * is spent, and a lock that did not answer will not answer to the same command
1816
+ * a second later. A person needs to open it another way.
1817
+ */
1818
+ declare class RelaiLockNotActuated extends RelaiError {
1819
+ readonly name = "RelaiLockNotActuated";
1820
+ readonly code = "lock_not_actuated";
1821
+ /** The Parent's echo of the command it ran, e.g. `OPEN 3:0`. Untrusted. */
1822
+ readonly command: string | undefined;
1823
+ /** The Parent's own words, when it gave any (`no ACK`). Untrusted. */
1824
+ readonly detail: string | undefined;
1825
+ constructor(command?: string, detail?: string);
1826
+ }
1771
1827
  /** The BLE/transport layer failed (connect, write, timeout, no nonce, …). */
1772
1828
  declare class RelaiTransportError extends RelaiError {
1773
1829
  readonly name = "RelaiTransportError";
1774
1830
  constructor(message: string);
1775
1831
  }
1776
1832
 
1777
- 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, needsFreshNonce, parseAdvertisedSerial, parseNotifyLine, presentRelaiPaymentSheet, serialMatches, verifyWebhook };
1833
+ 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, RelaiLockNotActuated, 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, needsFreshNonce, parseAdvertisedSerial, parseNotifyLine, presentRelaiPaymentSheet, serialMatches, verifyWebhook };
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import { RelaiApiError, RelaiTransportError, RelaiError, RelaiMissingKeyError, RelaiUnlockRejected, 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';
1
+ import { RelaiApiError, RelaiTransportError, RelaiError, RelaiMissingKeyError, RelaiUnlockRejected, RelaiLockNotActuated, RelaiNetworkError } from './chunk-KIKYY6KA.js';
2
+ export { RelaiApiError, RelaiConfigError, RelaiError, RelaiLateFeeDue, RelaiLockNotActuated, RelaiMissingKeyError, RelaiNetworkError, RelaiTransportError, RelaiUnlockRejected } from './chunk-KIKYY6KA.js';
3
+ export { asPaymentRequired, isStripePublishableKey, presentRelaiPaymentSheet } from './chunk-W2JF74T3.js';
4
4
 
5
5
  // src/http.ts
6
6
  var RETRYABLE_STATUS = /* @__PURE__ */ new Set([429, 500, 502, 503, 504]);
@@ -114,7 +114,7 @@ var HttpClient = class {
114
114
  path: opts.path
115
115
  };
116
116
  if (body.error.code === "late_fee_due") {
117
- const { RelaiLateFeeDue: RelaiLateFeeDue2 } = await import('./errors-NKRGOFB3.js');
117
+ const { RelaiLateFeeDue: RelaiLateFeeDue2 } = await import('./errors-2PYX6N33.js');
118
118
  return new RelaiLateFeeDue2(res.status, body, ctx);
119
119
  }
120
120
  return new RelaiApiError(res.status, body, ctx);
@@ -593,6 +593,7 @@ var TelemetryUploader = class {
593
593
  };
594
594
 
595
595
  // src/transport/notify.ts
596
+ var LOCK_FAILED = "LOCK_FAILED";
596
597
  var REJECT_REASONS = [
597
598
  "B64",
598
599
  "UNTAGGED",
@@ -625,6 +626,24 @@ function parseNotifyLine(line) {
625
626
  const verbHint = verbParts.length > 0 ? verbParts.join(" ") : void 0;
626
627
  return { kind: "reject", reason: reason ?? "", verbHint };
627
628
  }
629
+ if (trimmed.startsWith("[CMD] ") || trimmed.startsWith("[ERR] ")) {
630
+ const rest = trimmed.slice("[CMD] ".length).trim();
631
+ const failed = /\bFAILED\b/.test(rest);
632
+ const acked = /\bACK\b(?!=)/.test(rest);
633
+ if (failed || acked) {
634
+ const command = rest.replace(/\s*(?:\u2192|->|-)?\s*(?:ACK|FAILED)\b.*$/, "").trim();
635
+ const why = /\(([^)]*)\)/.exec(rest);
636
+ return {
637
+ kind: "actuated",
638
+ ok: acked && !failed,
639
+ command,
640
+ detail: why?.[1]?.trim() || void 0
641
+ };
642
+ }
643
+ if (trimmed.startsWith("[ERR] ")) {
644
+ return { kind: "actuated", ok: false, command: "", detail: rest };
645
+ }
646
+ }
628
647
  return { kind: "passthrough", raw: trimmed };
629
648
  }
630
649
 
@@ -723,6 +742,9 @@ async function deliverOpen(deps, open, opts) {
723
742
  await wait(NOT_READY_BACKOFF_MS);
724
743
  continue;
725
744
  }
745
+ if (err instanceof RelaiUnlockRejected) {
746
+ await reportOutcome(false, err.reason);
747
+ }
726
748
  throw err;
727
749
  }
728
750
  const minted = await deps.grants.mint(grant.grant_id, nonce);
@@ -751,6 +773,9 @@ async function deliverOpen(deps, open, opts) {
751
773
  }
752
774
  if (!ack.accepted) {
753
775
  await reportOutcome(false, ack.rejectReason ?? "UNKNOWN");
776
+ if (ack.rejectReason === LOCK_FAILED) {
777
+ throw new RelaiLockNotActuated(ack.command, ack.detail);
778
+ }
754
779
  throw new RelaiUnlockRejected(ack.rejectReason ?? "UNKNOWN", ack.verbHint);
755
780
  }
756
781
  await reportOutcome(true);
@@ -901,10 +926,10 @@ var RelaiClient = class {
901
926
  try {
902
927
  open = await requestOpen();
903
928
  } catch (err) {
904
- const { RelaiApiError: RelaiApiError2 } = await import('./errors-NKRGOFB3.js');
929
+ const { RelaiApiError: RelaiApiError2 } = await import('./errors-2PYX6N33.js');
905
930
  const payable = err instanceof RelaiApiError2 && (err.code === "payment_required" || err.code === "late_fee_due");
906
931
  if (input.presentPaymentSheet !== false && payable) {
907
- const { asPaymentRequired: asPaymentRequired2, presentRelaiPaymentSheet: presentRelaiPaymentSheet2 } = await import('./payment-sheet-B3X5QQMO.js');
932
+ const { asPaymentRequired: asPaymentRequired2, presentRelaiPaymentSheet: presentRelaiPaymentSheet2 } = await import('./payment-sheet-XUG5PHOW.js');
908
933
  const details = asPaymentRequired2(err.details);
909
934
  if (!details || !await presentRelaiPaymentSheet2(details, this.stripe)) throw err;
910
935
  open = await requestOpen();
@@ -1177,8 +1202,10 @@ function serialMatches(advertised, granted) {
1177
1202
  var RELAI_UART_SERVICE = "0000ff00-0000-1000-8000-00805f9b34fb";
1178
1203
  var RELAI_RX_CHAR = "0000ff02-0000-1000-8000-00805f9b34fb";
1179
1204
  var RELAI_TX_CHAR = "0000ff03-0000-1000-8000-00805f9b34fb";
1205
+ var CHALLENGE_PAYLOAD = utf8ToBase64("CHALLENGE");
1180
1206
  var MIN_MTU = 110;
1181
1207
  var NOTIFY_TIMEOUT_MS = 8e3;
1208
+ var ACTUATION_TIMEOUT_MS = 2500;
1182
1209
  var CONNECT_TIMEOUT_MS = 1e4;
1183
1210
  var BleTransport = class {
1184
1211
  constructor(opts) {
@@ -1188,6 +1215,7 @@ var BleTransport = class {
1188
1215
  this.scanImpl = opts.scan;
1189
1216
  this.notifyTimeoutMs = opts.notifyTimeoutMs ?? NOTIFY_TIMEOUT_MS;
1190
1217
  this.connectTimeoutMs = opts.connectTimeoutMs ?? CONNECT_TIMEOUT_MS;
1218
+ this.actuationTimeoutMs = opts.actuationTimeoutMs ?? ACTUATION_TIMEOUT_MS;
1191
1219
  }
1192
1220
  /**
1193
1221
  * Relai Parents in range.
@@ -1296,6 +1324,7 @@ var BleTransport = class {
1296
1324
  accept: void 0,
1297
1325
  failed: void 0,
1298
1326
  error: void 0,
1327
+ heldActuation: void 0,
1299
1328
  remove: () => void 0
1300
1329
  };
1301
1330
  const sub = device.monitorCharacteristicForService(
@@ -1316,12 +1345,15 @@ var BleTransport = class {
1316
1345
  } catch {
1317
1346
  return;
1318
1347
  }
1319
- if (state.waiter && state.accept?.(parseNotifyLine(text))) {
1348
+ const parsed = parseNotifyLine(text);
1349
+ if (state.waiter && state.accept?.(parsed)) {
1320
1350
  const resolve = state.waiter;
1321
1351
  state.waiter = void 0;
1322
1352
  state.accept = void 0;
1323
1353
  state.failed = void 0;
1324
1354
  resolve(text);
1355
+ } else if (!state.waiter && parsed.kind === "actuated") {
1356
+ state.heldActuation = text;
1325
1357
  }
1326
1358
  }
1327
1359
  );
@@ -1336,7 +1368,11 @@ var BleTransport = class {
1336
1368
  }
1337
1369
  }
1338
1370
  async requestNonce(session) {
1339
- const line = await this.writeAndAwait(session, utf8ToBase64("CHALLENGE"));
1371
+ const line = await this.writeAndAwait(
1372
+ session,
1373
+ utf8ToBase64(CHALLENGE_PAYLOAD),
1374
+ (p) => p.kind === "nonce" || p.kind === "reject" || p.kind === "accept"
1375
+ );
1340
1376
  const parsed = parseNotifyLine(line);
1341
1377
  if (parsed.kind === "reject") {
1342
1378
  throw new RelaiUnlockRejected(parsed.reason, parsed.verbHint);
@@ -1347,19 +1383,31 @@ var BleTransport = class {
1347
1383
  return parsed.nonceB64Url;
1348
1384
  }
1349
1385
  async sendCommand(session, token) {
1386
+ const state = this.notify.get(session.id);
1387
+ if (state) state.heldActuation = void 0;
1350
1388
  const line = await this.writeAndAwait(
1351
1389
  session,
1352
1390
  utf8ToBase64(token),
1353
1391
  (p) => p.kind === "accept" || p.kind === "reject"
1354
1392
  );
1355
1393
  const parsed = parseNotifyLine(line);
1356
- if (parsed.kind === "accept") {
1357
- return { accepted: true, command: parsed.command, rejectReason: void 0, verbHint: void 0 };
1358
- }
1359
1394
  if (parsed.kind === "reject") {
1360
1395
  return { accepted: false, command: void 0, rejectReason: parsed.reason, verbHint: parsed.verbHint };
1361
1396
  }
1362
- throw new RelaiTransportError(`Expected an [AUTH] ack, got: ${line}`);
1397
+ if (parsed.kind !== "accept") {
1398
+ throw new RelaiTransportError(`Expected an [AUTH] ack, got: ${line}`);
1399
+ }
1400
+ const verdict = await this.awaitActuation(session, parsed.command);
1401
+ if (verdict && !verdict.ok) {
1402
+ return {
1403
+ accepted: false,
1404
+ command: parsed.command,
1405
+ rejectReason: LOCK_FAILED,
1406
+ verbHint: verdict.command || parsed.command,
1407
+ ...verdict.detail !== void 0 ? { detail: verdict.detail } : {}
1408
+ };
1409
+ }
1410
+ return { accepted: true, command: parsed.command, rejectReason: void 0, verbHint: void 0 };
1363
1411
  }
1364
1412
  readTelemetry(_session) {
1365
1413
  return Promise.resolve({});
@@ -1379,6 +1427,47 @@ var BleTransport = class {
1379
1427
  this.devices.delete(session.id);
1380
1428
  }
1381
1429
  }
1430
+ /**
1431
+ * Await the lock's verdict for a command the Parent has already accepted.
1432
+ *
1433
+ * Writes NOTHING: this line answers no write, so there is nothing to send
1434
+ * and nothing to retry. Resolves null when the budget runs out, which the
1435
+ * caller reads as "no verdict" rather than as a failure.
1436
+ */
1437
+ async awaitActuation(session, command) {
1438
+ const state = this.notify.get(session.id);
1439
+ if (!state) return null;
1440
+ const mine = (p) => p.kind === "actuated" && (p.command === command || p.command === "");
1441
+ const held = state.heldActuation;
1442
+ if (held !== void 0) {
1443
+ state.heldActuation = void 0;
1444
+ const parsed2 = parseNotifyLine(held);
1445
+ if (mine(parsed2) && parsed2.kind === "actuated") {
1446
+ return { ok: parsed2.ok, command: parsed2.command, detail: parsed2.detail };
1447
+ }
1448
+ }
1449
+ if (state.error) return null;
1450
+ if (state.waiter) return null;
1451
+ const line = await new Promise((resolve) => {
1452
+ let settled = false;
1453
+ const finish = (value) => {
1454
+ if (settled) return;
1455
+ settled = true;
1456
+ clearTimeout(timer);
1457
+ state.waiter = void 0;
1458
+ state.accept = void 0;
1459
+ state.failed = void 0;
1460
+ resolve(value);
1461
+ };
1462
+ state.accept = mine;
1463
+ state.waiter = (l) => finish(l);
1464
+ state.failed = () => finish(null);
1465
+ const timer = setTimeout(() => finish(null), this.actuationTimeoutMs);
1466
+ });
1467
+ if (line === null) return null;
1468
+ const parsed = parseNotifyLine(line);
1469
+ return parsed.kind === "actuated" ? { ok: parsed.ok, command: parsed.command, detail: parsed.detail } : null;
1470
+ }
1382
1471
  /**
1383
1472
  * Write one value and await the first notify line that matches `accept`.
1384
1473
  *
@@ -1395,8 +1484,14 @@ var BleTransport = class {
1395
1484
  *
1396
1485
  * The subscription itself is opened in `connect` and held for the session, so
1397
1486
  * the gap between the nonce leg and the command leg is covered too.
1487
+ *
1488
+ * `accept` is REQUIRED rather than defaulted. It defaulted to "anything that
1489
+ * is not passthrough", which silently widened every caller the day the
1490
+ * parser learned a new line kind: the challenge leg started accepting the
1491
+ * lock's verdict and reporting a healthy Parent as unreachable. Each caller
1492
+ * names the lines its own write can get.
1398
1493
  */
1399
- writeAndAwait(session, valueBase64, accept = (p) => p.kind !== "passthrough") {
1494
+ writeAndAwait(session, valueBase64, accept) {
1400
1495
  const device = this.devices.get(session.id);
1401
1496
  const state = this.notify.get(session.id);
1402
1497
  if (!device || !state) return Promise.reject(new RelaiTransportError("Not connected."));
@@ -1 +1 @@
1
- export { asPaymentRequired, isStripePublishableKey, presentRelaiPaymentSheet } from './chunk-BIHTDL4L.js';
1
+ export { asPaymentRequired, isStripePublishableKey, presentRelaiPaymentSheet } from './chunk-W2JF74T3.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@relai-team/access-sdk",
3
- "version": "0.21.2",
3
+ "version": "0.22.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",
@@ -1 +0,0 @@
1
- export { RelaiApiError, RelaiConfigError, RelaiError, RelaiLateFeeDue, RelaiMissingKeyError, RelaiNetworkError, RelaiTransportError, RelaiUnlockRejected } from './chunk-B2T3KFBF.js';