@relai-team/access-sdk 0.21.2 → 0.23.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/{chunk-B2T3KFBF.js → chunk-KIKYY6KA.js} +12 -1
- package/dist/{chunk-BIHTDL4L.js → chunk-W2JF74T3.js} +2 -2
- package/dist/errors-2PYX6N33.js +1 -0
- package/dist/index.cjs +155 -8
- package/dist/index.d.cts +128 -19
- package/dist/index.d.ts +128 -19
- package/dist/index.js +148 -13
- package/dist/{payment-sheet-B3X5QQMO.js → payment-sheet-XUG5PHOW.js} +1 -1
- package/package.json +1 -1
- package/dist/errors-NKRGOFB3.js +0 -1
|
@@ -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-
|
|
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-
|
|
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);
|
|
@@ -1047,6 +1084,46 @@ var RelaiClient = class {
|
|
|
1047
1084
|
me() {
|
|
1048
1085
|
return this.http.request({ path: "/me" });
|
|
1049
1086
|
}
|
|
1087
|
+
/**
|
|
1088
|
+
* Delete the signed-in end user's account. Irreversible.
|
|
1089
|
+
*
|
|
1090
|
+
* Here because an app store requires it: Apple's guideline 5.1.1(v) says an
|
|
1091
|
+
* app that creates accounts has to let somebody delete one from inside the
|
|
1092
|
+
* app, and sending them to a web page is at best a grudging second place.
|
|
1093
|
+
*
|
|
1094
|
+
* Three things are worth knowing before you put this behind a button.
|
|
1095
|
+
*
|
|
1096
|
+
* IT ENDS THE SESSION AS IT RETURNS. Every token is revoked server-side,
|
|
1097
|
+
* including refresh tokens on other devices, so the client this was called
|
|
1098
|
+
* from is signed out whether or not it says so. Call `auth.signOut()` after
|
|
1099
|
+
* it, and clear whatever your app keeps locally: a stored access code for an
|
|
1100
|
+
* order that no longer exists is a code for a door that no longer opens.
|
|
1101
|
+
*
|
|
1102
|
+
* IT RELEASES COMPARTMENTS. Open orders end. One whose compartment is empty
|
|
1103
|
+
* is cancelled and the compartment returns to use. One whose compartment
|
|
1104
|
+
* still holds something is marked abandoned and taken out of service, which
|
|
1105
|
+
* is the same thing that happens when a pick-up window runs out and nobody
|
|
1106
|
+
* comes, and `orders_abandoned` counts those. Show that number. It is the
|
|
1107
|
+
* last chance anybody has to tell this person their belongings are about to
|
|
1108
|
+
* become a Host's problem.
|
|
1109
|
+
*
|
|
1110
|
+
* THE ORDERS SURVIVE, anonymized. They carry payments that settled and a
|
|
1111
|
+
* record of which compartment held what, which a Host or an auditor can ask
|
|
1112
|
+
* about long after the account is gone. The email address and `@tag` are
|
|
1113
|
+
* released, so the same person can sign up again later.
|
|
1114
|
+
*
|
|
1115
|
+
* A RETRY ANSWERS `unauthorized`, not success. The deletion itself is
|
|
1116
|
+
* idempotent, but the token a retry would use was destroyed by the first
|
|
1117
|
+
* call, so a request lost on a flaky connection cannot be told apart from
|
|
1118
|
+
* one that never arrived. Treat `unauthorized` here as the account being
|
|
1119
|
+
* gone: every path to it ends with this device signed out anyway.
|
|
1120
|
+
*
|
|
1121
|
+
* A guest, a test identity, or the store-reviewer identity is refused with
|
|
1122
|
+
* `forbidden`.
|
|
1123
|
+
*/
|
|
1124
|
+
deleteAccount() {
|
|
1125
|
+
return this.http.request({ path: "/me", method: "DELETE" });
|
|
1126
|
+
}
|
|
1050
1127
|
/**
|
|
1051
1128
|
* Open a node: request the grant, then drive the physical unlock over the
|
|
1052
1129
|
* given transport (challenge → mint → write → ack). Throws
|
|
@@ -1347,8 +1424,10 @@ function serialMatches(advertised, granted) {
|
|
|
1347
1424
|
var RELAI_UART_SERVICE = "0000ff00-0000-1000-8000-00805f9b34fb";
|
|
1348
1425
|
var RELAI_RX_CHAR = "0000ff02-0000-1000-8000-00805f9b34fb";
|
|
1349
1426
|
var RELAI_TX_CHAR = "0000ff03-0000-1000-8000-00805f9b34fb";
|
|
1427
|
+
var CHALLENGE_PAYLOAD = utf8ToBase64("CHALLENGE");
|
|
1350
1428
|
var MIN_MTU = 110;
|
|
1351
1429
|
var NOTIFY_TIMEOUT_MS = 8e3;
|
|
1430
|
+
var ACTUATION_TIMEOUT_MS = 2500;
|
|
1352
1431
|
var CONNECT_TIMEOUT_MS = 1e4;
|
|
1353
1432
|
var BleTransport = class {
|
|
1354
1433
|
constructor(opts) {
|
|
@@ -1358,6 +1437,7 @@ var BleTransport = class {
|
|
|
1358
1437
|
this.scanImpl = opts.scan;
|
|
1359
1438
|
this.notifyTimeoutMs = opts.notifyTimeoutMs ?? NOTIFY_TIMEOUT_MS;
|
|
1360
1439
|
this.connectTimeoutMs = opts.connectTimeoutMs ?? CONNECT_TIMEOUT_MS;
|
|
1440
|
+
this.actuationTimeoutMs = opts.actuationTimeoutMs ?? ACTUATION_TIMEOUT_MS;
|
|
1361
1441
|
}
|
|
1362
1442
|
/**
|
|
1363
1443
|
* Relai Parents in range.
|
|
@@ -1466,6 +1546,7 @@ var BleTransport = class {
|
|
|
1466
1546
|
accept: void 0,
|
|
1467
1547
|
failed: void 0,
|
|
1468
1548
|
error: void 0,
|
|
1549
|
+
heldActuation: void 0,
|
|
1469
1550
|
remove: () => void 0
|
|
1470
1551
|
};
|
|
1471
1552
|
const sub = device.monitorCharacteristicForService(
|
|
@@ -1486,12 +1567,15 @@ var BleTransport = class {
|
|
|
1486
1567
|
} catch {
|
|
1487
1568
|
return;
|
|
1488
1569
|
}
|
|
1489
|
-
|
|
1570
|
+
const parsed = parseNotifyLine(text);
|
|
1571
|
+
if (state.waiter && state.accept?.(parsed)) {
|
|
1490
1572
|
const resolve = state.waiter;
|
|
1491
1573
|
state.waiter = void 0;
|
|
1492
1574
|
state.accept = void 0;
|
|
1493
1575
|
state.failed = void 0;
|
|
1494
1576
|
resolve(text);
|
|
1577
|
+
} else if (!state.waiter && parsed.kind === "actuated") {
|
|
1578
|
+
state.heldActuation = text;
|
|
1495
1579
|
}
|
|
1496
1580
|
}
|
|
1497
1581
|
);
|
|
@@ -1506,7 +1590,11 @@ var BleTransport = class {
|
|
|
1506
1590
|
}
|
|
1507
1591
|
}
|
|
1508
1592
|
async requestNonce(session) {
|
|
1509
|
-
const line = await this.writeAndAwait(
|
|
1593
|
+
const line = await this.writeAndAwait(
|
|
1594
|
+
session,
|
|
1595
|
+
utf8ToBase64(CHALLENGE_PAYLOAD),
|
|
1596
|
+
(p) => p.kind === "nonce" || p.kind === "reject" || p.kind === "accept"
|
|
1597
|
+
);
|
|
1510
1598
|
const parsed = parseNotifyLine(line);
|
|
1511
1599
|
if (parsed.kind === "reject") {
|
|
1512
1600
|
throw new exports.RelaiUnlockRejected(parsed.reason, parsed.verbHint);
|
|
@@ -1517,19 +1605,31 @@ var BleTransport = class {
|
|
|
1517
1605
|
return parsed.nonceB64Url;
|
|
1518
1606
|
}
|
|
1519
1607
|
async sendCommand(session, token) {
|
|
1608
|
+
const state = this.notify.get(session.id);
|
|
1609
|
+
if (state) state.heldActuation = void 0;
|
|
1520
1610
|
const line = await this.writeAndAwait(
|
|
1521
1611
|
session,
|
|
1522
1612
|
utf8ToBase64(token),
|
|
1523
1613
|
(p) => p.kind === "accept" || p.kind === "reject"
|
|
1524
1614
|
);
|
|
1525
1615
|
const parsed = parseNotifyLine(line);
|
|
1526
|
-
if (parsed.kind === "accept") {
|
|
1527
|
-
return { accepted: true, command: parsed.command, rejectReason: void 0, verbHint: void 0 };
|
|
1528
|
-
}
|
|
1529
1616
|
if (parsed.kind === "reject") {
|
|
1530
1617
|
return { accepted: false, command: void 0, rejectReason: parsed.reason, verbHint: parsed.verbHint };
|
|
1531
1618
|
}
|
|
1532
|
-
|
|
1619
|
+
if (parsed.kind !== "accept") {
|
|
1620
|
+
throw new exports.RelaiTransportError(`Expected an [AUTH] ack, got: ${line}`);
|
|
1621
|
+
}
|
|
1622
|
+
const verdict = await this.awaitActuation(session, parsed.command);
|
|
1623
|
+
if (verdict && !verdict.ok) {
|
|
1624
|
+
return {
|
|
1625
|
+
accepted: false,
|
|
1626
|
+
command: parsed.command,
|
|
1627
|
+
rejectReason: LOCK_FAILED,
|
|
1628
|
+
verbHint: verdict.command || parsed.command,
|
|
1629
|
+
...verdict.detail !== void 0 ? { detail: verdict.detail } : {}
|
|
1630
|
+
};
|
|
1631
|
+
}
|
|
1632
|
+
return { accepted: true, command: parsed.command, rejectReason: void 0, verbHint: void 0 };
|
|
1533
1633
|
}
|
|
1534
1634
|
readTelemetry(_session) {
|
|
1535
1635
|
return Promise.resolve({});
|
|
@@ -1549,6 +1649,47 @@ var BleTransport = class {
|
|
|
1549
1649
|
this.devices.delete(session.id);
|
|
1550
1650
|
}
|
|
1551
1651
|
}
|
|
1652
|
+
/**
|
|
1653
|
+
* Await the lock's verdict for a command the Parent has already accepted.
|
|
1654
|
+
*
|
|
1655
|
+
* Writes NOTHING: this line answers no write, so there is nothing to send
|
|
1656
|
+
* and nothing to retry. Resolves null when the budget runs out, which the
|
|
1657
|
+
* caller reads as "no verdict" rather than as a failure.
|
|
1658
|
+
*/
|
|
1659
|
+
async awaitActuation(session, command) {
|
|
1660
|
+
const state = this.notify.get(session.id);
|
|
1661
|
+
if (!state) return null;
|
|
1662
|
+
const mine = (p) => p.kind === "actuated" && (p.command === command || p.command === "");
|
|
1663
|
+
const held = state.heldActuation;
|
|
1664
|
+
if (held !== void 0) {
|
|
1665
|
+
state.heldActuation = void 0;
|
|
1666
|
+
const parsed2 = parseNotifyLine(held);
|
|
1667
|
+
if (mine(parsed2) && parsed2.kind === "actuated") {
|
|
1668
|
+
return { ok: parsed2.ok, command: parsed2.command, detail: parsed2.detail };
|
|
1669
|
+
}
|
|
1670
|
+
}
|
|
1671
|
+
if (state.error) return null;
|
|
1672
|
+
if (state.waiter) return null;
|
|
1673
|
+
const line = await new Promise((resolve) => {
|
|
1674
|
+
let settled = false;
|
|
1675
|
+
const finish = (value) => {
|
|
1676
|
+
if (settled) return;
|
|
1677
|
+
settled = true;
|
|
1678
|
+
clearTimeout(timer);
|
|
1679
|
+
state.waiter = void 0;
|
|
1680
|
+
state.accept = void 0;
|
|
1681
|
+
state.failed = void 0;
|
|
1682
|
+
resolve(value);
|
|
1683
|
+
};
|
|
1684
|
+
state.accept = mine;
|
|
1685
|
+
state.waiter = (l) => finish(l);
|
|
1686
|
+
state.failed = () => finish(null);
|
|
1687
|
+
const timer = setTimeout(() => finish(null), this.actuationTimeoutMs);
|
|
1688
|
+
});
|
|
1689
|
+
if (line === null) return null;
|
|
1690
|
+
const parsed = parseNotifyLine(line);
|
|
1691
|
+
return parsed.kind === "actuated" ? { ok: parsed.ok, command: parsed.command, detail: parsed.detail } : null;
|
|
1692
|
+
}
|
|
1552
1693
|
/**
|
|
1553
1694
|
* Write one value and await the first notify line that matches `accept`.
|
|
1554
1695
|
*
|
|
@@ -1565,8 +1706,14 @@ var BleTransport = class {
|
|
|
1565
1706
|
*
|
|
1566
1707
|
* The subscription itself is opened in `connect` and held for the session, so
|
|
1567
1708
|
* the gap between the nonce leg and the command leg is covered too.
|
|
1709
|
+
*
|
|
1710
|
+
* `accept` is REQUIRED rather than defaulted. It defaulted to "anything that
|
|
1711
|
+
* is not passthrough", which silently widened every caller the day the
|
|
1712
|
+
* parser learned a new line kind: the challenge leg started accepting the
|
|
1713
|
+
* lock's verdict and reporting a healthy Parent as unreachable. Each caller
|
|
1714
|
+
* names the lines its own write can get.
|
|
1568
1715
|
*/
|
|
1569
|
-
writeAndAwait(session, valueBase64, accept
|
|
1716
|
+
writeAndAwait(session, valueBase64, accept) {
|
|
1570
1717
|
const device = this.devices.get(session.id);
|
|
1571
1718
|
const state = this.notify.get(session.id);
|
|
1572
1719
|
if (!device || !state) return Promise.reject(new exports.RelaiTransportError("Not connected."));
|
package/dist/index.d.cts
CHANGED
|
@@ -296,6 +296,21 @@ interface Me {
|
|
|
296
296
|
environment: "sandbox" | "production";
|
|
297
297
|
};
|
|
298
298
|
}
|
|
299
|
+
/** What is left behind when somebody deletes their account. */
|
|
300
|
+
interface AccountDeleted {
|
|
301
|
+
deleted: true;
|
|
302
|
+
/** Open orders ended because their compartment was empty or unassigned. */
|
|
303
|
+
orders_cancelled: number;
|
|
304
|
+
/**
|
|
305
|
+
* Open orders whose compartment still held something.
|
|
306
|
+
*
|
|
307
|
+
* SAY THIS ONE OUT LOUD. Those nodes are now out of service and a Host has
|
|
308
|
+
* been told to clear them, because deleting an account cannot empty a steel
|
|
309
|
+
* box. The person who just deleted the account is the only one who knows
|
|
310
|
+
* what is inside, and this is the last moment anyone can tell them.
|
|
311
|
+
*/
|
|
312
|
+
orders_abandoned: number;
|
|
313
|
+
}
|
|
299
314
|
interface TowerNode {
|
|
300
315
|
id: string;
|
|
301
316
|
tower_id: string;
|
|
@@ -997,6 +1012,15 @@ interface CommandAck {
|
|
|
997
1012
|
rejectReason: string | undefined;
|
|
998
1013
|
/** Correlation hint only: untrusted echoed verb. */
|
|
999
1014
|
verbHint: string | undefined;
|
|
1015
|
+
/**
|
|
1016
|
+
* The Parent's own words about why, when it gave any: the parenthesised
|
|
1017
|
+
* cause on `[ERR] <command> -> FAILED (no ACK)`, or the whole explanation on
|
|
1018
|
+
* the lines that name no command. Untrusted echoed bytes, for logs only.
|
|
1019
|
+
*
|
|
1020
|
+
* Optional rather than `| undefined`, so the three fields that have always
|
|
1021
|
+
* been there stay the shape every caller already constructs.
|
|
1022
|
+
*/
|
|
1023
|
+
detail?: string;
|
|
1000
1024
|
}
|
|
1001
1025
|
|
|
1002
1026
|
/**
|
|
@@ -1328,6 +1352,44 @@ declare class RelaiClient {
|
|
|
1328
1352
|
* 0.12.0: it was named in both and never actually existed.
|
|
1329
1353
|
*/
|
|
1330
1354
|
me(): Promise<Me>;
|
|
1355
|
+
/**
|
|
1356
|
+
* Delete the signed-in end user's account. Irreversible.
|
|
1357
|
+
*
|
|
1358
|
+
* Here because an app store requires it: Apple's guideline 5.1.1(v) says an
|
|
1359
|
+
* app that creates accounts has to let somebody delete one from inside the
|
|
1360
|
+
* app, and sending them to a web page is at best a grudging second place.
|
|
1361
|
+
*
|
|
1362
|
+
* Three things are worth knowing before you put this behind a button.
|
|
1363
|
+
*
|
|
1364
|
+
* IT ENDS THE SESSION AS IT RETURNS. Every token is revoked server-side,
|
|
1365
|
+
* including refresh tokens on other devices, so the client this was called
|
|
1366
|
+
* from is signed out whether or not it says so. Call `auth.signOut()` after
|
|
1367
|
+
* it, and clear whatever your app keeps locally: a stored access code for an
|
|
1368
|
+
* order that no longer exists is a code for a door that no longer opens.
|
|
1369
|
+
*
|
|
1370
|
+
* IT RELEASES COMPARTMENTS. Open orders end. One whose compartment is empty
|
|
1371
|
+
* is cancelled and the compartment returns to use. One whose compartment
|
|
1372
|
+
* still holds something is marked abandoned and taken out of service, which
|
|
1373
|
+
* is the same thing that happens when a pick-up window runs out and nobody
|
|
1374
|
+
* comes, and `orders_abandoned` counts those. Show that number. It is the
|
|
1375
|
+
* last chance anybody has to tell this person their belongings are about to
|
|
1376
|
+
* become a Host's problem.
|
|
1377
|
+
*
|
|
1378
|
+
* THE ORDERS SURVIVE, anonymized. They carry payments that settled and a
|
|
1379
|
+
* record of which compartment held what, which a Host or an auditor can ask
|
|
1380
|
+
* about long after the account is gone. The email address and `@tag` are
|
|
1381
|
+
* released, so the same person can sign up again later.
|
|
1382
|
+
*
|
|
1383
|
+
* A RETRY ANSWERS `unauthorized`, not success. The deletion itself is
|
|
1384
|
+
* idempotent, but the token a retry would use was destroyed by the first
|
|
1385
|
+
* call, so a request lost on a flaky connection cannot be told apart from
|
|
1386
|
+
* one that never arrived. Treat `unauthorized` here as the account being
|
|
1387
|
+
* gone: every path to it ends with this device signed out anyway.
|
|
1388
|
+
*
|
|
1389
|
+
* A guest, a test identity, or the store-reviewer identity is refused with
|
|
1390
|
+
* `forbidden`.
|
|
1391
|
+
*/
|
|
1392
|
+
deleteAccount(): Promise<AccountDeleted>;
|
|
1331
1393
|
/**
|
|
1332
1394
|
* Open a node: request the grant, then drive the physical unlock over the
|
|
1333
1395
|
* given transport (challenge → mint → write → ack). Throws
|
|
@@ -1421,6 +1483,8 @@ interface BleTransportOptions {
|
|
|
1421
1483
|
notifyTimeoutMs?: number;
|
|
1422
1484
|
/** Per-candidate connection timeout; see CONNECT_TIMEOUT_MS. */
|
|
1423
1485
|
connectTimeoutMs?: number;
|
|
1486
|
+
/** How long to wait for the lock's verdict; see ACTUATION_TIMEOUT_MS. */
|
|
1487
|
+
actuationTimeoutMs?: number;
|
|
1424
1488
|
}
|
|
1425
1489
|
declare class BleTransport implements ParentTransport {
|
|
1426
1490
|
private readonly manager;
|
|
@@ -1429,6 +1493,7 @@ declare class BleTransport implements ParentTransport {
|
|
|
1429
1493
|
private readonly scanImpl;
|
|
1430
1494
|
private readonly notifyTimeoutMs;
|
|
1431
1495
|
private readonly connectTimeoutMs;
|
|
1496
|
+
private readonly actuationTimeoutMs;
|
|
1432
1497
|
constructor(opts: BleTransportOptions);
|
|
1433
1498
|
/**
|
|
1434
1499
|
* Relai Parents in range.
|
|
@@ -1459,6 +1524,14 @@ declare class BleTransport implements ParentTransport {
|
|
|
1459
1524
|
sendCommand(session: Session, token: string): Promise<CommandAck>;
|
|
1460
1525
|
readTelemetry(_session: Session): Promise<TowerTelemetry>;
|
|
1461
1526
|
disconnect(session: Session): Promise<void>;
|
|
1527
|
+
/**
|
|
1528
|
+
* Await the lock's verdict for a command the Parent has already accepted.
|
|
1529
|
+
*
|
|
1530
|
+
* Writes NOTHING: this line answers no write, so there is nothing to send
|
|
1531
|
+
* and nothing to retry. Resolves null when the budget runs out, which the
|
|
1532
|
+
* caller reads as "no verdict" rather than as a failure.
|
|
1533
|
+
*/
|
|
1534
|
+
private awaitActuation;
|
|
1462
1535
|
/**
|
|
1463
1536
|
* Write one value and await the first notify line that matches `accept`.
|
|
1464
1537
|
*
|
|
@@ -1475,6 +1548,12 @@ declare class BleTransport implements ParentTransport {
|
|
|
1475
1548
|
*
|
|
1476
1549
|
* The subscription itself is opened in `connect` and held for the session, so
|
|
1477
1550
|
* the gap between the nonce leg and the command leg is covered too.
|
|
1551
|
+
*
|
|
1552
|
+
* `accept` is REQUIRED rather than defaulted. It defaulted to "anything that
|
|
1553
|
+
* is not passthrough", which silently widened every caller the day the
|
|
1554
|
+
* parser learned a new line kind: the challenge leg started accepting the
|
|
1555
|
+
* lock's verdict and reporting a healthy Parent as unreachable. Each caller
|
|
1556
|
+
* names the lines its own write can get.
|
|
1478
1557
|
*/
|
|
1479
1558
|
private writeAndAwait;
|
|
1480
1559
|
}
|
|
@@ -1491,6 +1570,15 @@ declare class BleTransport implements ParentTransport {
|
|
|
1491
1570
|
* NONCE <b64url>
|
|
1492
1571
|
* [AUTH] ACCEPT <command> (emitted at verify time, before output)
|
|
1493
1572
|
* [AUTH] REJECT <reason> [verb] (verb echoed only on tagged-path rejects)
|
|
1573
|
+
* [CMD] <command> -> ACK (the lock answered)
|
|
1574
|
+
* [ERR] <command> -> FAILED [(why)] (it did not)
|
|
1575
|
+
*
|
|
1576
|
+
* THE ACCEPT IS NOT THE OPEN. `Commands::handleInput` notifies
|
|
1577
|
+
* `[AUTH] ACCEPT <command>` the moment the tag verifies, then pushes the
|
|
1578
|
+
* command onto a queue; `Commands::loop` dispatches it afterwards and notifies
|
|
1579
|
+
* the lock's answer as a SECOND line. So a Parent that verified a token and
|
|
1580
|
+
* then failed to move the lock says both, and reading only the first reports a
|
|
1581
|
+
* compartment as open while its door is shut.
|
|
1494
1582
|
*
|
|
1495
1583
|
* SECURITY: on a REJECT the echoed verb is ATTACKER-CONTROLLED bytes reflected
|
|
1496
1584
|
* by the Parent. It is surfaced as `verbHint` for correlation/logging only and
|
|
@@ -1506,28 +1594,27 @@ type NotifyLine = {
|
|
|
1506
1594
|
kind: "reject";
|
|
1507
1595
|
reason: string;
|
|
1508
1596
|
verbHint: string | undefined;
|
|
1509
|
-
}
|
|
1510
|
-
kind: "passthrough";
|
|
1511
|
-
raw: string;
|
|
1512
|
-
};
|
|
1597
|
+
}
|
|
1513
1598
|
/**
|
|
1514
|
-
*
|
|
1599
|
+
* What the lock did, which arrives after the accept.
|
|
1515
1600
|
*
|
|
1516
|
-
*
|
|
1517
|
-
*
|
|
1601
|
+
* `command` is the Parent's echo of the verb it ran, e.g. `OPEN 3:0`, and is
|
|
1602
|
+
* empty on the lines that report a command dropped before dispatch (a full
|
|
1603
|
+
* queue), where the firmware names no verb. `detail` is the parenthesised
|
|
1604
|
+
* cause when there is one (`no ACK`).
|
|
1518
1605
|
*
|
|
1519
|
-
*
|
|
1520
|
-
*
|
|
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.
|
|
1606
|
+
* SECURITY: like `verbHint`, both fields are bytes the Parent chose. They
|
|
1607
|
+
* correlate and they log; `ok` is the only thing that decides anything.
|
|
1530
1608
|
*/
|
|
1609
|
+
| {
|
|
1610
|
+
kind: "actuated";
|
|
1611
|
+
ok: boolean;
|
|
1612
|
+
command: string;
|
|
1613
|
+
detail: string | undefined;
|
|
1614
|
+
} | {
|
|
1615
|
+
kind: "passthrough";
|
|
1616
|
+
raw: string;
|
|
1617
|
+
};
|
|
1531
1618
|
declare const REJECT_REASONS: readonly ["B64", "UNTAGGED", "FORMAT", "KEYVERSION", "TAG", "NONCE", "LOCKED", "ROTATE", "NOTREADY"];
|
|
1532
1619
|
/**
|
|
1533
1620
|
* Is this rejection worth trying again as-is?
|
|
@@ -1768,10 +1855,32 @@ declare class RelaiUnlockRejected extends RelaiError {
|
|
|
1768
1855
|
readonly verbHint: string | undefined;
|
|
1769
1856
|
constructor(reason: string, verbHint?: string);
|
|
1770
1857
|
}
|
|
1858
|
+
/**
|
|
1859
|
+
* The Parent verified the command and then the lock did not open.
|
|
1860
|
+
*
|
|
1861
|
+
* Its own class, because `RelaiUnlockRejected` would say "Parent rejected the
|
|
1862
|
+
* command" and that is the opposite of what happened: the token was good, the
|
|
1863
|
+
* Parent accepted it, and the hardware past the Parent did not answer. The
|
|
1864
|
+
* distinction is the whole point for whoever reads this. A rejection means
|
|
1865
|
+
* fix the credential; this means go and look at the compartment.
|
|
1866
|
+
*
|
|
1867
|
+
* Nothing about it is retryable from the app. The tag verified, so the nonce
|
|
1868
|
+
* is spent, and a lock that did not answer will not answer to the same command
|
|
1869
|
+
* a second later. A person needs to open it another way.
|
|
1870
|
+
*/
|
|
1871
|
+
declare class RelaiLockNotActuated extends RelaiError {
|
|
1872
|
+
readonly name = "RelaiLockNotActuated";
|
|
1873
|
+
readonly code = "lock_not_actuated";
|
|
1874
|
+
/** The Parent's echo of the command it ran, e.g. `OPEN 3:0`. Untrusted. */
|
|
1875
|
+
readonly command: string | undefined;
|
|
1876
|
+
/** The Parent's own words, when it gave any (`no ACK`). Untrusted. */
|
|
1877
|
+
readonly detail: string | undefined;
|
|
1878
|
+
constructor(command?: string, detail?: string);
|
|
1879
|
+
}
|
|
1771
1880
|
/** The BLE/transport layer failed (connect, write, timeout, no nonce, …). */
|
|
1772
1881
|
declare class RelaiTransportError extends RelaiError {
|
|
1773
1882
|
readonly name = "RelaiTransportError";
|
|
1774
1883
|
constructor(message: string);
|
|
1775
1884
|
}
|
|
1776
1885
|
|
|
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 };
|
|
1886
|
+
export { type AccessLinkTarget, AccessLinksModule, type AccountDeleted, 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
|
@@ -296,6 +296,21 @@ interface Me {
|
|
|
296
296
|
environment: "sandbox" | "production";
|
|
297
297
|
};
|
|
298
298
|
}
|
|
299
|
+
/** What is left behind when somebody deletes their account. */
|
|
300
|
+
interface AccountDeleted {
|
|
301
|
+
deleted: true;
|
|
302
|
+
/** Open orders ended because their compartment was empty or unassigned. */
|
|
303
|
+
orders_cancelled: number;
|
|
304
|
+
/**
|
|
305
|
+
* Open orders whose compartment still held something.
|
|
306
|
+
*
|
|
307
|
+
* SAY THIS ONE OUT LOUD. Those nodes are now out of service and a Host has
|
|
308
|
+
* been told to clear them, because deleting an account cannot empty a steel
|
|
309
|
+
* box. The person who just deleted the account is the only one who knows
|
|
310
|
+
* what is inside, and this is the last moment anyone can tell them.
|
|
311
|
+
*/
|
|
312
|
+
orders_abandoned: number;
|
|
313
|
+
}
|
|
299
314
|
interface TowerNode {
|
|
300
315
|
id: string;
|
|
301
316
|
tower_id: string;
|
|
@@ -997,6 +1012,15 @@ interface CommandAck {
|
|
|
997
1012
|
rejectReason: string | undefined;
|
|
998
1013
|
/** Correlation hint only: untrusted echoed verb. */
|
|
999
1014
|
verbHint: string | undefined;
|
|
1015
|
+
/**
|
|
1016
|
+
* The Parent's own words about why, when it gave any: the parenthesised
|
|
1017
|
+
* cause on `[ERR] <command> -> FAILED (no ACK)`, or the whole explanation on
|
|
1018
|
+
* the lines that name no command. Untrusted echoed bytes, for logs only.
|
|
1019
|
+
*
|
|
1020
|
+
* Optional rather than `| undefined`, so the three fields that have always
|
|
1021
|
+
* been there stay the shape every caller already constructs.
|
|
1022
|
+
*/
|
|
1023
|
+
detail?: string;
|
|
1000
1024
|
}
|
|
1001
1025
|
|
|
1002
1026
|
/**
|
|
@@ -1328,6 +1352,44 @@ declare class RelaiClient {
|
|
|
1328
1352
|
* 0.12.0: it was named in both and never actually existed.
|
|
1329
1353
|
*/
|
|
1330
1354
|
me(): Promise<Me>;
|
|
1355
|
+
/**
|
|
1356
|
+
* Delete the signed-in end user's account. Irreversible.
|
|
1357
|
+
*
|
|
1358
|
+
* Here because an app store requires it: Apple's guideline 5.1.1(v) says an
|
|
1359
|
+
* app that creates accounts has to let somebody delete one from inside the
|
|
1360
|
+
* app, and sending them to a web page is at best a grudging second place.
|
|
1361
|
+
*
|
|
1362
|
+
* Three things are worth knowing before you put this behind a button.
|
|
1363
|
+
*
|
|
1364
|
+
* IT ENDS THE SESSION AS IT RETURNS. Every token is revoked server-side,
|
|
1365
|
+
* including refresh tokens on other devices, so the client this was called
|
|
1366
|
+
* from is signed out whether or not it says so. Call `auth.signOut()` after
|
|
1367
|
+
* it, and clear whatever your app keeps locally: a stored access code for an
|
|
1368
|
+
* order that no longer exists is a code for a door that no longer opens.
|
|
1369
|
+
*
|
|
1370
|
+
* IT RELEASES COMPARTMENTS. Open orders end. One whose compartment is empty
|
|
1371
|
+
* is cancelled and the compartment returns to use. One whose compartment
|
|
1372
|
+
* still holds something is marked abandoned and taken out of service, which
|
|
1373
|
+
* is the same thing that happens when a pick-up window runs out and nobody
|
|
1374
|
+
* comes, and `orders_abandoned` counts those. Show that number. It is the
|
|
1375
|
+
* last chance anybody has to tell this person their belongings are about to
|
|
1376
|
+
* become a Host's problem.
|
|
1377
|
+
*
|
|
1378
|
+
* THE ORDERS SURVIVE, anonymized. They carry payments that settled and a
|
|
1379
|
+
* record of which compartment held what, which a Host or an auditor can ask
|
|
1380
|
+
* about long after the account is gone. The email address and `@tag` are
|
|
1381
|
+
* released, so the same person can sign up again later.
|
|
1382
|
+
*
|
|
1383
|
+
* A RETRY ANSWERS `unauthorized`, not success. The deletion itself is
|
|
1384
|
+
* idempotent, but the token a retry would use was destroyed by the first
|
|
1385
|
+
* call, so a request lost on a flaky connection cannot be told apart from
|
|
1386
|
+
* one that never arrived. Treat `unauthorized` here as the account being
|
|
1387
|
+
* gone: every path to it ends with this device signed out anyway.
|
|
1388
|
+
*
|
|
1389
|
+
* A guest, a test identity, or the store-reviewer identity is refused with
|
|
1390
|
+
* `forbidden`.
|
|
1391
|
+
*/
|
|
1392
|
+
deleteAccount(): Promise<AccountDeleted>;
|
|
1331
1393
|
/**
|
|
1332
1394
|
* Open a node: request the grant, then drive the physical unlock over the
|
|
1333
1395
|
* given transport (challenge → mint → write → ack). Throws
|
|
@@ -1421,6 +1483,8 @@ interface BleTransportOptions {
|
|
|
1421
1483
|
notifyTimeoutMs?: number;
|
|
1422
1484
|
/** Per-candidate connection timeout; see CONNECT_TIMEOUT_MS. */
|
|
1423
1485
|
connectTimeoutMs?: number;
|
|
1486
|
+
/** How long to wait for the lock's verdict; see ACTUATION_TIMEOUT_MS. */
|
|
1487
|
+
actuationTimeoutMs?: number;
|
|
1424
1488
|
}
|
|
1425
1489
|
declare class BleTransport implements ParentTransport {
|
|
1426
1490
|
private readonly manager;
|
|
@@ -1429,6 +1493,7 @@ declare class BleTransport implements ParentTransport {
|
|
|
1429
1493
|
private readonly scanImpl;
|
|
1430
1494
|
private readonly notifyTimeoutMs;
|
|
1431
1495
|
private readonly connectTimeoutMs;
|
|
1496
|
+
private readonly actuationTimeoutMs;
|
|
1432
1497
|
constructor(opts: BleTransportOptions);
|
|
1433
1498
|
/**
|
|
1434
1499
|
* Relai Parents in range.
|
|
@@ -1459,6 +1524,14 @@ declare class BleTransport implements ParentTransport {
|
|
|
1459
1524
|
sendCommand(session: Session, token: string): Promise<CommandAck>;
|
|
1460
1525
|
readTelemetry(_session: Session): Promise<TowerTelemetry>;
|
|
1461
1526
|
disconnect(session: Session): Promise<void>;
|
|
1527
|
+
/**
|
|
1528
|
+
* Await the lock's verdict for a command the Parent has already accepted.
|
|
1529
|
+
*
|
|
1530
|
+
* Writes NOTHING: this line answers no write, so there is nothing to send
|
|
1531
|
+
* and nothing to retry. Resolves null when the budget runs out, which the
|
|
1532
|
+
* caller reads as "no verdict" rather than as a failure.
|
|
1533
|
+
*/
|
|
1534
|
+
private awaitActuation;
|
|
1462
1535
|
/**
|
|
1463
1536
|
* Write one value and await the first notify line that matches `accept`.
|
|
1464
1537
|
*
|
|
@@ -1475,6 +1548,12 @@ declare class BleTransport implements ParentTransport {
|
|
|
1475
1548
|
*
|
|
1476
1549
|
* The subscription itself is opened in `connect` and held for the session, so
|
|
1477
1550
|
* the gap between the nonce leg and the command leg is covered too.
|
|
1551
|
+
*
|
|
1552
|
+
* `accept` is REQUIRED rather than defaulted. It defaulted to "anything that
|
|
1553
|
+
* is not passthrough", which silently widened every caller the day the
|
|
1554
|
+
* parser learned a new line kind: the challenge leg started accepting the
|
|
1555
|
+
* lock's verdict and reporting a healthy Parent as unreachable. Each caller
|
|
1556
|
+
* names the lines its own write can get.
|
|
1478
1557
|
*/
|
|
1479
1558
|
private writeAndAwait;
|
|
1480
1559
|
}
|
|
@@ -1491,6 +1570,15 @@ declare class BleTransport implements ParentTransport {
|
|
|
1491
1570
|
* NONCE <b64url>
|
|
1492
1571
|
* [AUTH] ACCEPT <command> (emitted at verify time, before output)
|
|
1493
1572
|
* [AUTH] REJECT <reason> [verb] (verb echoed only on tagged-path rejects)
|
|
1573
|
+
* [CMD] <command> -> ACK (the lock answered)
|
|
1574
|
+
* [ERR] <command> -> FAILED [(why)] (it did not)
|
|
1575
|
+
*
|
|
1576
|
+
* THE ACCEPT IS NOT THE OPEN. `Commands::handleInput` notifies
|
|
1577
|
+
* `[AUTH] ACCEPT <command>` the moment the tag verifies, then pushes the
|
|
1578
|
+
* command onto a queue; `Commands::loop` dispatches it afterwards and notifies
|
|
1579
|
+
* the lock's answer as a SECOND line. So a Parent that verified a token and
|
|
1580
|
+
* then failed to move the lock says both, and reading only the first reports a
|
|
1581
|
+
* compartment as open while its door is shut.
|
|
1494
1582
|
*
|
|
1495
1583
|
* SECURITY: on a REJECT the echoed verb is ATTACKER-CONTROLLED bytes reflected
|
|
1496
1584
|
* by the Parent. It is surfaced as `verbHint` for correlation/logging only and
|
|
@@ -1506,28 +1594,27 @@ type NotifyLine = {
|
|
|
1506
1594
|
kind: "reject";
|
|
1507
1595
|
reason: string;
|
|
1508
1596
|
verbHint: string | undefined;
|
|
1509
|
-
}
|
|
1510
|
-
kind: "passthrough";
|
|
1511
|
-
raw: string;
|
|
1512
|
-
};
|
|
1597
|
+
}
|
|
1513
1598
|
/**
|
|
1514
|
-
*
|
|
1599
|
+
* What the lock did, which arrives after the accept.
|
|
1515
1600
|
*
|
|
1516
|
-
*
|
|
1517
|
-
*
|
|
1601
|
+
* `command` is the Parent's echo of the verb it ran, e.g. `OPEN 3:0`, and is
|
|
1602
|
+
* empty on the lines that report a command dropped before dispatch (a full
|
|
1603
|
+
* queue), where the firmware names no verb. `detail` is the parenthesised
|
|
1604
|
+
* cause when there is one (`no ACK`).
|
|
1518
1605
|
*
|
|
1519
|
-
*
|
|
1520
|
-
*
|
|
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.
|
|
1606
|
+
* SECURITY: like `verbHint`, both fields are bytes the Parent chose. They
|
|
1607
|
+
* correlate and they log; `ok` is the only thing that decides anything.
|
|
1530
1608
|
*/
|
|
1609
|
+
| {
|
|
1610
|
+
kind: "actuated";
|
|
1611
|
+
ok: boolean;
|
|
1612
|
+
command: string;
|
|
1613
|
+
detail: string | undefined;
|
|
1614
|
+
} | {
|
|
1615
|
+
kind: "passthrough";
|
|
1616
|
+
raw: string;
|
|
1617
|
+
};
|
|
1531
1618
|
declare const REJECT_REASONS: readonly ["B64", "UNTAGGED", "FORMAT", "KEYVERSION", "TAG", "NONCE", "LOCKED", "ROTATE", "NOTREADY"];
|
|
1532
1619
|
/**
|
|
1533
1620
|
* Is this rejection worth trying again as-is?
|
|
@@ -1768,10 +1855,32 @@ declare class RelaiUnlockRejected extends RelaiError {
|
|
|
1768
1855
|
readonly verbHint: string | undefined;
|
|
1769
1856
|
constructor(reason: string, verbHint?: string);
|
|
1770
1857
|
}
|
|
1858
|
+
/**
|
|
1859
|
+
* The Parent verified the command and then the lock did not open.
|
|
1860
|
+
*
|
|
1861
|
+
* Its own class, because `RelaiUnlockRejected` would say "Parent rejected the
|
|
1862
|
+
* command" and that is the opposite of what happened: the token was good, the
|
|
1863
|
+
* Parent accepted it, and the hardware past the Parent did not answer. The
|
|
1864
|
+
* distinction is the whole point for whoever reads this. A rejection means
|
|
1865
|
+
* fix the credential; this means go and look at the compartment.
|
|
1866
|
+
*
|
|
1867
|
+
* Nothing about it is retryable from the app. The tag verified, so the nonce
|
|
1868
|
+
* is spent, and a lock that did not answer will not answer to the same command
|
|
1869
|
+
* a second later. A person needs to open it another way.
|
|
1870
|
+
*/
|
|
1871
|
+
declare class RelaiLockNotActuated extends RelaiError {
|
|
1872
|
+
readonly name = "RelaiLockNotActuated";
|
|
1873
|
+
readonly code = "lock_not_actuated";
|
|
1874
|
+
/** The Parent's echo of the command it ran, e.g. `OPEN 3:0`. Untrusted. */
|
|
1875
|
+
readonly command: string | undefined;
|
|
1876
|
+
/** The Parent's own words, when it gave any (`no ACK`). Untrusted. */
|
|
1877
|
+
readonly detail: string | undefined;
|
|
1878
|
+
constructor(command?: string, detail?: string);
|
|
1879
|
+
}
|
|
1771
1880
|
/** The BLE/transport layer failed (connect, write, timeout, no nonce, …). */
|
|
1772
1881
|
declare class RelaiTransportError extends RelaiError {
|
|
1773
1882
|
readonly name = "RelaiTransportError";
|
|
1774
1883
|
constructor(message: string);
|
|
1775
1884
|
}
|
|
1776
1885
|
|
|
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 };
|
|
1886
|
+
export { type AccessLinkTarget, AccessLinksModule, type AccountDeleted, 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-
|
|
2
|
-
export { RelaiApiError, RelaiConfigError, RelaiError, RelaiLateFeeDue, RelaiMissingKeyError, RelaiNetworkError, RelaiTransportError, RelaiUnlockRejected } from './chunk-
|
|
3
|
-
export { asPaymentRequired, isStripePublishableKey, presentRelaiPaymentSheet } from './chunk-
|
|
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-
|
|
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);
|
|
@@ -884,6 +909,46 @@ var RelaiClient = class {
|
|
|
884
909
|
me() {
|
|
885
910
|
return this.http.request({ path: "/me" });
|
|
886
911
|
}
|
|
912
|
+
/**
|
|
913
|
+
* Delete the signed-in end user's account. Irreversible.
|
|
914
|
+
*
|
|
915
|
+
* Here because an app store requires it: Apple's guideline 5.1.1(v) says an
|
|
916
|
+
* app that creates accounts has to let somebody delete one from inside the
|
|
917
|
+
* app, and sending them to a web page is at best a grudging second place.
|
|
918
|
+
*
|
|
919
|
+
* Three things are worth knowing before you put this behind a button.
|
|
920
|
+
*
|
|
921
|
+
* IT ENDS THE SESSION AS IT RETURNS. Every token is revoked server-side,
|
|
922
|
+
* including refresh tokens on other devices, so the client this was called
|
|
923
|
+
* from is signed out whether or not it says so. Call `auth.signOut()` after
|
|
924
|
+
* it, and clear whatever your app keeps locally: a stored access code for an
|
|
925
|
+
* order that no longer exists is a code for a door that no longer opens.
|
|
926
|
+
*
|
|
927
|
+
* IT RELEASES COMPARTMENTS. Open orders end. One whose compartment is empty
|
|
928
|
+
* is cancelled and the compartment returns to use. One whose compartment
|
|
929
|
+
* still holds something is marked abandoned and taken out of service, which
|
|
930
|
+
* is the same thing that happens when a pick-up window runs out and nobody
|
|
931
|
+
* comes, and `orders_abandoned` counts those. Show that number. It is the
|
|
932
|
+
* last chance anybody has to tell this person their belongings are about to
|
|
933
|
+
* become a Host's problem.
|
|
934
|
+
*
|
|
935
|
+
* THE ORDERS SURVIVE, anonymized. They carry payments that settled and a
|
|
936
|
+
* record of which compartment held what, which a Host or an auditor can ask
|
|
937
|
+
* about long after the account is gone. The email address and `@tag` are
|
|
938
|
+
* released, so the same person can sign up again later.
|
|
939
|
+
*
|
|
940
|
+
* A RETRY ANSWERS `unauthorized`, not success. The deletion itself is
|
|
941
|
+
* idempotent, but the token a retry would use was destroyed by the first
|
|
942
|
+
* call, so a request lost on a flaky connection cannot be told apart from
|
|
943
|
+
* one that never arrived. Treat `unauthorized` here as the account being
|
|
944
|
+
* gone: every path to it ends with this device signed out anyway.
|
|
945
|
+
*
|
|
946
|
+
* A guest, a test identity, or the store-reviewer identity is refused with
|
|
947
|
+
* `forbidden`.
|
|
948
|
+
*/
|
|
949
|
+
deleteAccount() {
|
|
950
|
+
return this.http.request({ path: "/me", method: "DELETE" });
|
|
951
|
+
}
|
|
887
952
|
/**
|
|
888
953
|
* Open a node: request the grant, then drive the physical unlock over the
|
|
889
954
|
* given transport (challenge → mint → write → ack). Throws
|
|
@@ -901,10 +966,10 @@ var RelaiClient = class {
|
|
|
901
966
|
try {
|
|
902
967
|
open = await requestOpen();
|
|
903
968
|
} catch (err) {
|
|
904
|
-
const { RelaiApiError: RelaiApiError2 } = await import('./errors-
|
|
969
|
+
const { RelaiApiError: RelaiApiError2 } = await import('./errors-2PYX6N33.js');
|
|
905
970
|
const payable = err instanceof RelaiApiError2 && (err.code === "payment_required" || err.code === "late_fee_due");
|
|
906
971
|
if (input.presentPaymentSheet !== false && payable) {
|
|
907
|
-
const { asPaymentRequired: asPaymentRequired2, presentRelaiPaymentSheet: presentRelaiPaymentSheet2 } = await import('./payment-sheet-
|
|
972
|
+
const { asPaymentRequired: asPaymentRequired2, presentRelaiPaymentSheet: presentRelaiPaymentSheet2 } = await import('./payment-sheet-XUG5PHOW.js');
|
|
908
973
|
const details = asPaymentRequired2(err.details);
|
|
909
974
|
if (!details || !await presentRelaiPaymentSheet2(details, this.stripe)) throw err;
|
|
910
975
|
open = await requestOpen();
|
|
@@ -1177,8 +1242,10 @@ function serialMatches(advertised, granted) {
|
|
|
1177
1242
|
var RELAI_UART_SERVICE = "0000ff00-0000-1000-8000-00805f9b34fb";
|
|
1178
1243
|
var RELAI_RX_CHAR = "0000ff02-0000-1000-8000-00805f9b34fb";
|
|
1179
1244
|
var RELAI_TX_CHAR = "0000ff03-0000-1000-8000-00805f9b34fb";
|
|
1245
|
+
var CHALLENGE_PAYLOAD = utf8ToBase64("CHALLENGE");
|
|
1180
1246
|
var MIN_MTU = 110;
|
|
1181
1247
|
var NOTIFY_TIMEOUT_MS = 8e3;
|
|
1248
|
+
var ACTUATION_TIMEOUT_MS = 2500;
|
|
1182
1249
|
var CONNECT_TIMEOUT_MS = 1e4;
|
|
1183
1250
|
var BleTransport = class {
|
|
1184
1251
|
constructor(opts) {
|
|
@@ -1188,6 +1255,7 @@ var BleTransport = class {
|
|
|
1188
1255
|
this.scanImpl = opts.scan;
|
|
1189
1256
|
this.notifyTimeoutMs = opts.notifyTimeoutMs ?? NOTIFY_TIMEOUT_MS;
|
|
1190
1257
|
this.connectTimeoutMs = opts.connectTimeoutMs ?? CONNECT_TIMEOUT_MS;
|
|
1258
|
+
this.actuationTimeoutMs = opts.actuationTimeoutMs ?? ACTUATION_TIMEOUT_MS;
|
|
1191
1259
|
}
|
|
1192
1260
|
/**
|
|
1193
1261
|
* Relai Parents in range.
|
|
@@ -1296,6 +1364,7 @@ var BleTransport = class {
|
|
|
1296
1364
|
accept: void 0,
|
|
1297
1365
|
failed: void 0,
|
|
1298
1366
|
error: void 0,
|
|
1367
|
+
heldActuation: void 0,
|
|
1299
1368
|
remove: () => void 0
|
|
1300
1369
|
};
|
|
1301
1370
|
const sub = device.monitorCharacteristicForService(
|
|
@@ -1316,12 +1385,15 @@ var BleTransport = class {
|
|
|
1316
1385
|
} catch {
|
|
1317
1386
|
return;
|
|
1318
1387
|
}
|
|
1319
|
-
|
|
1388
|
+
const parsed = parseNotifyLine(text);
|
|
1389
|
+
if (state.waiter && state.accept?.(parsed)) {
|
|
1320
1390
|
const resolve = state.waiter;
|
|
1321
1391
|
state.waiter = void 0;
|
|
1322
1392
|
state.accept = void 0;
|
|
1323
1393
|
state.failed = void 0;
|
|
1324
1394
|
resolve(text);
|
|
1395
|
+
} else if (!state.waiter && parsed.kind === "actuated") {
|
|
1396
|
+
state.heldActuation = text;
|
|
1325
1397
|
}
|
|
1326
1398
|
}
|
|
1327
1399
|
);
|
|
@@ -1336,7 +1408,11 @@ var BleTransport = class {
|
|
|
1336
1408
|
}
|
|
1337
1409
|
}
|
|
1338
1410
|
async requestNonce(session) {
|
|
1339
|
-
const line = await this.writeAndAwait(
|
|
1411
|
+
const line = await this.writeAndAwait(
|
|
1412
|
+
session,
|
|
1413
|
+
utf8ToBase64(CHALLENGE_PAYLOAD),
|
|
1414
|
+
(p) => p.kind === "nonce" || p.kind === "reject" || p.kind === "accept"
|
|
1415
|
+
);
|
|
1340
1416
|
const parsed = parseNotifyLine(line);
|
|
1341
1417
|
if (parsed.kind === "reject") {
|
|
1342
1418
|
throw new RelaiUnlockRejected(parsed.reason, parsed.verbHint);
|
|
@@ -1347,19 +1423,31 @@ var BleTransport = class {
|
|
|
1347
1423
|
return parsed.nonceB64Url;
|
|
1348
1424
|
}
|
|
1349
1425
|
async sendCommand(session, token) {
|
|
1426
|
+
const state = this.notify.get(session.id);
|
|
1427
|
+
if (state) state.heldActuation = void 0;
|
|
1350
1428
|
const line = await this.writeAndAwait(
|
|
1351
1429
|
session,
|
|
1352
1430
|
utf8ToBase64(token),
|
|
1353
1431
|
(p) => p.kind === "accept" || p.kind === "reject"
|
|
1354
1432
|
);
|
|
1355
1433
|
const parsed = parseNotifyLine(line);
|
|
1356
|
-
if (parsed.kind === "accept") {
|
|
1357
|
-
return { accepted: true, command: parsed.command, rejectReason: void 0, verbHint: void 0 };
|
|
1358
|
-
}
|
|
1359
1434
|
if (parsed.kind === "reject") {
|
|
1360
1435
|
return { accepted: false, command: void 0, rejectReason: parsed.reason, verbHint: parsed.verbHint };
|
|
1361
1436
|
}
|
|
1362
|
-
|
|
1437
|
+
if (parsed.kind !== "accept") {
|
|
1438
|
+
throw new RelaiTransportError(`Expected an [AUTH] ack, got: ${line}`);
|
|
1439
|
+
}
|
|
1440
|
+
const verdict = await this.awaitActuation(session, parsed.command);
|
|
1441
|
+
if (verdict && !verdict.ok) {
|
|
1442
|
+
return {
|
|
1443
|
+
accepted: false,
|
|
1444
|
+
command: parsed.command,
|
|
1445
|
+
rejectReason: LOCK_FAILED,
|
|
1446
|
+
verbHint: verdict.command || parsed.command,
|
|
1447
|
+
...verdict.detail !== void 0 ? { detail: verdict.detail } : {}
|
|
1448
|
+
};
|
|
1449
|
+
}
|
|
1450
|
+
return { accepted: true, command: parsed.command, rejectReason: void 0, verbHint: void 0 };
|
|
1363
1451
|
}
|
|
1364
1452
|
readTelemetry(_session) {
|
|
1365
1453
|
return Promise.resolve({});
|
|
@@ -1379,6 +1467,47 @@ var BleTransport = class {
|
|
|
1379
1467
|
this.devices.delete(session.id);
|
|
1380
1468
|
}
|
|
1381
1469
|
}
|
|
1470
|
+
/**
|
|
1471
|
+
* Await the lock's verdict for a command the Parent has already accepted.
|
|
1472
|
+
*
|
|
1473
|
+
* Writes NOTHING: this line answers no write, so there is nothing to send
|
|
1474
|
+
* and nothing to retry. Resolves null when the budget runs out, which the
|
|
1475
|
+
* caller reads as "no verdict" rather than as a failure.
|
|
1476
|
+
*/
|
|
1477
|
+
async awaitActuation(session, command) {
|
|
1478
|
+
const state = this.notify.get(session.id);
|
|
1479
|
+
if (!state) return null;
|
|
1480
|
+
const mine = (p) => p.kind === "actuated" && (p.command === command || p.command === "");
|
|
1481
|
+
const held = state.heldActuation;
|
|
1482
|
+
if (held !== void 0) {
|
|
1483
|
+
state.heldActuation = void 0;
|
|
1484
|
+
const parsed2 = parseNotifyLine(held);
|
|
1485
|
+
if (mine(parsed2) && parsed2.kind === "actuated") {
|
|
1486
|
+
return { ok: parsed2.ok, command: parsed2.command, detail: parsed2.detail };
|
|
1487
|
+
}
|
|
1488
|
+
}
|
|
1489
|
+
if (state.error) return null;
|
|
1490
|
+
if (state.waiter) return null;
|
|
1491
|
+
const line = await new Promise((resolve) => {
|
|
1492
|
+
let settled = false;
|
|
1493
|
+
const finish = (value) => {
|
|
1494
|
+
if (settled) return;
|
|
1495
|
+
settled = true;
|
|
1496
|
+
clearTimeout(timer);
|
|
1497
|
+
state.waiter = void 0;
|
|
1498
|
+
state.accept = void 0;
|
|
1499
|
+
state.failed = void 0;
|
|
1500
|
+
resolve(value);
|
|
1501
|
+
};
|
|
1502
|
+
state.accept = mine;
|
|
1503
|
+
state.waiter = (l) => finish(l);
|
|
1504
|
+
state.failed = () => finish(null);
|
|
1505
|
+
const timer = setTimeout(() => finish(null), this.actuationTimeoutMs);
|
|
1506
|
+
});
|
|
1507
|
+
if (line === null) return null;
|
|
1508
|
+
const parsed = parseNotifyLine(line);
|
|
1509
|
+
return parsed.kind === "actuated" ? { ok: parsed.ok, command: parsed.command, detail: parsed.detail } : null;
|
|
1510
|
+
}
|
|
1382
1511
|
/**
|
|
1383
1512
|
* Write one value and await the first notify line that matches `accept`.
|
|
1384
1513
|
*
|
|
@@ -1395,8 +1524,14 @@ var BleTransport = class {
|
|
|
1395
1524
|
*
|
|
1396
1525
|
* The subscription itself is opened in `connect` and held for the session, so
|
|
1397
1526
|
* the gap between the nonce leg and the command leg is covered too.
|
|
1527
|
+
*
|
|
1528
|
+
* `accept` is REQUIRED rather than defaulted. It defaulted to "anything that
|
|
1529
|
+
* is not passthrough", which silently widened every caller the day the
|
|
1530
|
+
* parser learned a new line kind: the challenge leg started accepting the
|
|
1531
|
+
* lock's verdict and reporting a healthy Parent as unreachable. Each caller
|
|
1532
|
+
* names the lines its own write can get.
|
|
1398
1533
|
*/
|
|
1399
|
-
writeAndAwait(session, valueBase64, accept
|
|
1534
|
+
writeAndAwait(session, valueBase64, accept) {
|
|
1400
1535
|
const device = this.devices.get(session.id);
|
|
1401
1536
|
const state = this.notify.get(session.id);
|
|
1402
1537
|
if (!device || !state) return Promise.reject(new RelaiTransportError("Not connected."));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { asPaymentRequired, isStripePublishableKey, presentRelaiPaymentSheet } from './chunk-
|
|
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.
|
|
3
|
+
"version": "0.23.0",
|
|
4
4
|
"description": "Official Relai Access SDK, open Relai Exchange Zone nodes over BLE, backed by the Relai Access platform (server-owns-trust).",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"type": "module",
|
package/dist/errors-NKRGOFB3.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { RelaiApiError, RelaiConfigError, RelaiError, RelaiLateFeeDue, RelaiMissingKeyError, RelaiNetworkError, RelaiTransportError, RelaiUnlockRejected } from './chunk-B2T3KFBF.js';
|