@nice-code/commander 0.114.0 → 0.115.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/LICENSE +73 -0
- package/build/cli.cjs +1055 -484
- package/build/cli.cjs.map +1 -1
- package/build/cli.mjs +1056 -485
- package/build/cli.mjs.map +1 -1
- package/build/client/assets/index-C57hpMXr.js +23 -0
- package/build/client/assets/index-C57hpMXr.js.map +1 -0
- package/build/client/index.html +1 -1
- package/package.json +7 -6
- package/build/client/assets/index-Dc0xCRS3.js +0 -23
- package/build/client/assets/index-Dc0xCRS3.js.map +0 -1
package/build/cli.cjs
CHANGED
|
@@ -1513,24 +1513,35 @@ function staggerFor(config, terms) {
|
|
|
1513
1513
|
}
|
|
1514
1514
|
return stagger;
|
|
1515
1515
|
}
|
|
1516
|
-
|
|
1517
|
-
|
|
1516
|
+
/** Whether a frame is over `maxBytes`, encoding a text frame only when its length cannot settle it. */
|
|
1517
|
+
function isFrameOver(frame, maxBytes) {
|
|
1518
|
+
if (typeof frame !== "string") return frame.byteLength > maxBytes;
|
|
1519
|
+
if (frame.length > maxBytes) return true;
|
|
1520
|
+
if (frame.length * 3 <= maxBytes) return false;
|
|
1521
|
+
return new TextEncoder().encode(frame).byteLength > maxBytes;
|
|
1522
|
+
}
|
|
1518
1523
|
/** Build the inert lifecycle slot shared by duplex acceptor carrier factories. */
|
|
1519
1524
|
function createDuplexCarrierLifecycle(limits) {
|
|
1520
1525
|
let router;
|
|
1521
1526
|
let disposed = false;
|
|
1522
1527
|
const windows = /* @__PURE__ */ new Map();
|
|
1523
|
-
const maxFrameBytes = limits?.maxFrameBytes;
|
|
1528
|
+
const maxFrameBytes = limits?.maxFrameBytes ?? 1048576;
|
|
1524
1529
|
const rate = limits?.rate;
|
|
1525
|
-
if (maxFrameBytes
|
|
1530
|
+
if (maxFrameBytes !== Number.POSITIVE_INFINITY && (!Number.isSafeInteger(maxFrameBytes) || maxFrameBytes <= 0)) throw new Error("maxFrameBytes must be a positive safe integer, or Infinity for no limit");
|
|
1531
|
+
const exceeded = (connection, reason) => {
|
|
1532
|
+
if (limits?.onExceeded != null) {
|
|
1533
|
+
limits.onExceeded(connection, reason);
|
|
1534
|
+
return;
|
|
1535
|
+
}
|
|
1536
|
+
console.warn(reason === "frame_bytes" ? `[nice-wire] dropped an inbound frame over ${maxFrameBytes} bytes (inboundLimits.maxFrameBytes)` : "[nice-wire] dropped an inbound frame over the message rate (inboundLimits.rate)");
|
|
1537
|
+
};
|
|
1526
1538
|
if (rate != null && (!Number.isSafeInteger(rate.maxMessages) || rate.maxMessages <= 0 || !Number.isSafeInteger(rate.windowMs) || rate.windowMs <= 0)) throw new Error("inbound rate limits must be positive safe integers");
|
|
1527
|
-
const frameBytes = (frame) => typeof frame === "string" ? new TextEncoder().encode(frame).byteLength : frame instanceof ArrayBuffer ? frame.byteLength : frame.byteLength;
|
|
1528
1539
|
return {
|
|
1529
1540
|
receive(connection, frame) {
|
|
1530
1541
|
if (disposed) return;
|
|
1531
1542
|
if (router == null) throw new Error("acceptor carrier not served yet — activate it before feeding frames");
|
|
1532
|
-
if (
|
|
1533
|
-
|
|
1543
|
+
if (isFrameOver(frame, maxFrameBytes)) {
|
|
1544
|
+
exceeded(connection, "frame_bytes");
|
|
1534
1545
|
return;
|
|
1535
1546
|
}
|
|
1536
1547
|
if (rate != null) {
|
|
@@ -1545,7 +1556,7 @@ function createDuplexCarrierLifecycle(limits) {
|
|
|
1545
1556
|
}
|
|
1546
1557
|
window.count += 1;
|
|
1547
1558
|
if (window.count > rate.maxMessages) {
|
|
1548
|
-
|
|
1559
|
+
exceeded(connection, "message_rate");
|
|
1549
1560
|
return;
|
|
1550
1561
|
}
|
|
1551
1562
|
}
|
|
@@ -1583,6 +1594,25 @@ function wsAcceptorCarrier(options) {
|
|
|
1583
1594
|
};
|
|
1584
1595
|
}
|
|
1585
1596
|
//#endregion
|
|
1597
|
+
//#region ../nice-error/src/NiceError/nice_error.static.ts
|
|
1598
|
+
const DUR_OBJ_PACK_PREFIX = "NE_DUROBJ[[";
|
|
1599
|
+
const DUR_OBJ_PACK_SUFFIX = "]]NE_DUROBJ";
|
|
1600
|
+
/**
|
|
1601
|
+
* The domain of the generic wrapper `castNiceError` produces for anything that
|
|
1602
|
+
* wasn't already a `NiceError` (native throws, error-like objects, nullish,
|
|
1603
|
+
* primitives). `NiceError.isUnhandled` is defined as "belongs to this domain" —
|
|
1604
|
+
* i.e. an error we never accounted for and had to wrap. Kept here (not imported
|
|
1605
|
+
* from `nice_core_errors`) so `NiceError` can reference it without an import cycle.
|
|
1606
|
+
*/
|
|
1607
|
+
const ERR_CAST_NOT_NICE_DOMAIN = "err_cast_not_nice";
|
|
1608
|
+
/**
|
|
1609
|
+
* The sealed failure: the one id, sentence and status a peer is sent in place of an error this
|
|
1610
|
+
* side never accounted for. Shared by the cast domain's schema and `NiceError.toWireJsonObject`,
|
|
1611
|
+
* which cannot import that domain.
|
|
1612
|
+
*/
|
|
1613
|
+
const SEALED_FAILURE_ID = "unhandled";
|
|
1614
|
+
const SEALED_FAILURE_MESSAGE = "The other side failed and did not say how. The detail is in its own log, not in this error.";
|
|
1615
|
+
//#endregion
|
|
1586
1616
|
//#region ../nice-error/src/internal/internal_errors.ts
|
|
1587
1617
|
let _build;
|
|
1588
1618
|
/** Wired once by `nice_core_errors` at module init to avoid an import cycle. */
|
|
@@ -1612,18 +1642,54 @@ function getErrorDomainProps(holder) {
|
|
|
1612
1642
|
}
|
|
1613
1643
|
//#endregion
|
|
1614
1644
|
//#region ../nice-error/src/utils/jsErrorOrCastJsError.ts
|
|
1645
|
+
function messageOfThrown(thrown) {
|
|
1646
|
+
if (typeof thrown === "string") return thrown;
|
|
1647
|
+
if (typeof thrown === "object" && thrown != null && "message" in thrown && typeof thrown.message === "string") return thrown.message;
|
|
1648
|
+
return "No error message found";
|
|
1649
|
+
}
|
|
1615
1650
|
function jsErrorOrCastJsError(error, logMessage = true) {
|
|
1616
|
-
if (error instanceof Error) return
|
|
1617
|
-
const message =
|
|
1651
|
+
if (error instanceof Error) return error;
|
|
1652
|
+
const message = messageOfThrown(error);
|
|
1618
1653
|
if (logMessage) console.error(`An unknown and unstructured error was thrown: ${message}`, error);
|
|
1619
|
-
return {
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1654
|
+
return new Error(message, { cause: error });
|
|
1655
|
+
}
|
|
1656
|
+
//#endregion
|
|
1657
|
+
//#region ../nice-error/src/utils/jsonSafe.ts
|
|
1658
|
+
const CIRCULAR = "[Circular]";
|
|
1659
|
+
const UNSERIALIZABLE = "[Unserializable]";
|
|
1660
|
+
function jsonSafeCopy(value) {
|
|
1661
|
+
const ancestors = [];
|
|
1662
|
+
try {
|
|
1663
|
+
const text = JSON.stringify(value, function(_key, nested) {
|
|
1664
|
+
if (typeof nested === "bigint") return nested.toString();
|
|
1665
|
+
if (typeof nested !== "object" || nested == null) return nested;
|
|
1666
|
+
while (ancestors.length > 0 && ancestors[ancestors.length - 1] !== this) ancestors.pop();
|
|
1667
|
+
if (ancestors.includes(nested)) return CIRCULAR;
|
|
1668
|
+
ancestors.push(nested);
|
|
1669
|
+
return nested;
|
|
1670
|
+
});
|
|
1671
|
+
return text == null ? void 0 : JSON.parse(text);
|
|
1672
|
+
} catch {
|
|
1673
|
+
return UNSERIALIZABLE;
|
|
1674
|
+
}
|
|
1675
|
+
}
|
|
1676
|
+
/**
|
|
1677
|
+
* `value` itself when `JSON.stringify` accepts it. Otherwise a copy that it does accept: a BigInt
|
|
1678
|
+
* becomes its decimal string and a circular reference becomes `"[Circular]"`.
|
|
1679
|
+
*/
|
|
1680
|
+
function jsonSafe(value) {
|
|
1681
|
+
if (typeof value === "bigint") return value.toString();
|
|
1682
|
+
if (typeof value !== "object" || value == null) return value;
|
|
1683
|
+
try {
|
|
1684
|
+
JSON.stringify(value);
|
|
1685
|
+
return value;
|
|
1686
|
+
} catch {
|
|
1687
|
+
return jsonSafeCopy(value);
|
|
1688
|
+
}
|
|
1623
1689
|
}
|
|
1624
1690
|
//#endregion
|
|
1625
1691
|
//#region ../nice-error/package.json
|
|
1626
|
-
var version = "0.
|
|
1692
|
+
var version = "0.115.0";
|
|
1627
1693
|
//#endregion
|
|
1628
1694
|
//#region ../nice-error/src/utils/logger.ts
|
|
1629
1695
|
let activeLogger = {
|
|
@@ -1671,18 +1737,6 @@ function warnOfUnversionedCopy() {
|
|
|
1671
1737
|
} catch {}
|
|
1672
1738
|
}
|
|
1673
1739
|
//#endregion
|
|
1674
|
-
//#region ../nice-error/src/NiceError/nice_error.static.ts
|
|
1675
|
-
const DUR_OBJ_PACK_PREFIX = "NE_DUROBJ[[";
|
|
1676
|
-
const DUR_OBJ_PACK_SUFFIX = "]]NE_DUROBJ";
|
|
1677
|
-
/**
|
|
1678
|
-
* The domain of the generic wrapper `castNiceError` produces for anything that
|
|
1679
|
-
* wasn't already a `NiceError` (native throws, error-like objects, nullish,
|
|
1680
|
-
* primitives). `NiceError.isUnhandled` is defined as "belongs to this domain" —
|
|
1681
|
-
* i.e. an error we never accounted for and had to wrap. Kept here (not imported
|
|
1682
|
-
* from `nice_core_errors`) so `NiceError` can reference it without an import cycle.
|
|
1683
|
-
*/
|
|
1684
|
-
const ERR_CAST_NOT_NICE_DOMAIN = "err_cast_not_nice";
|
|
1685
|
-
//#endregion
|
|
1686
1740
|
//#region ../nice-error/src/utils/packError/causePack.ts
|
|
1687
1741
|
const causePack = (error) => {
|
|
1688
1742
|
error._packedState = {
|
|
@@ -1861,14 +1915,24 @@ var NiceError = class extends Error {
|
|
|
1861
1915
|
if (myIds.length !== otherIds.length) return false;
|
|
1862
1916
|
return myIds.every((id, i) => id === otherIds[i]);
|
|
1863
1917
|
}
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1918
|
+
_originErrorJson(summary) {
|
|
1919
|
+
if (this.originError == null) return void 0;
|
|
1920
|
+
const name = this.originError.name;
|
|
1921
|
+
const message = this.originError.cleanMessage ?? this.originError.message;
|
|
1922
|
+
if (summary) return {
|
|
1923
|
+
name,
|
|
1924
|
+
message
|
|
1925
|
+
};
|
|
1926
|
+
return {
|
|
1927
|
+
name,
|
|
1928
|
+
message,
|
|
1868
1929
|
stack: this.originError.stack,
|
|
1869
1930
|
cause: serializeErrorCause(this.originError.cause),
|
|
1870
1931
|
...Array.isArray(this.originError.errors) ? { errors: this.originError.errors.map((e) => serializeErrorCause(e)) } : {}
|
|
1871
|
-
}
|
|
1932
|
+
};
|
|
1933
|
+
}
|
|
1934
|
+
toJsonObject(options = {}) {
|
|
1935
|
+
const originErrorDetail = options.originError ?? "full";
|
|
1872
1936
|
const def = {
|
|
1873
1937
|
domain: this.def.domain,
|
|
1874
1938
|
allDomains: this.def.allDomains
|
|
@@ -1885,6 +1949,10 @@ var NiceError = class extends Error {
|
|
|
1885
1949
|
kind: "unhydrated",
|
|
1886
1950
|
serialized: data.contextState.serialized
|
|
1887
1951
|
};
|
|
1952
|
+
else if (data.contextState.kind === "serde_unset") contextState = {
|
|
1953
|
+
kind: "serde_unset",
|
|
1954
|
+
value: jsonSafe(data.contextState.value)
|
|
1955
|
+
};
|
|
1888
1956
|
else contextState = data.contextState;
|
|
1889
1957
|
errorData[id] = {
|
|
1890
1958
|
contextState,
|
|
@@ -1902,32 +1970,49 @@ var NiceError = class extends Error {
|
|
|
1902
1970
|
message: this.cleanMessage,
|
|
1903
1971
|
httpStatusCode: this.httpStatusCode,
|
|
1904
1972
|
timeCreated: this.timeCreated,
|
|
1905
|
-
...this.stack != null ? { stack: this.stack } : {},
|
|
1906
|
-
originError
|
|
1973
|
+
...options.stack !== false && this.stack != null ? { stack: this.stack } : {},
|
|
1974
|
+
...originErrorDetail === "omit" ? {} : { originError: this._originErrorJson(originErrorDetail === "summary") }
|
|
1907
1975
|
};
|
|
1908
1976
|
}
|
|
1909
1977
|
toJSON() {
|
|
1910
1978
|
return this.toJsonObject();
|
|
1911
1979
|
}
|
|
1912
1980
|
/**
|
|
1913
|
-
* The **wire form
|
|
1914
|
-
*
|
|
1915
|
-
*
|
|
1916
|
-
* and
|
|
1917
|
-
*
|
|
1981
|
+
* The **wire form**: what an untrusted peer is sent.
|
|
1982
|
+
*
|
|
1983
|
+
* - An error a domain defines is sent whole, without `stack` and `originError`: its ids, per-id
|
|
1984
|
+
* context, message and domain, so `castNiceError` on the far side rebuilds the same error.
|
|
1985
|
+
* - An error that {@link isUnhandled} is sent as the **sealed failure**: the cast domain's
|
|
1986
|
+
* `unhandled` id, one fixed sentence and status 500. Nothing of what was thrown is kept, since
|
|
1987
|
+
* a cast's message and context are the thrown value itself.
|
|
1918
1988
|
*
|
|
1919
|
-
*
|
|
1920
|
-
* realm reject frame fanned out to every client): the stack must not leave the process, and at
|
|
1921
|
-
* high frequency (a cursor-write reject storm) the ~1.5 kB full form is mostly stack. Keep the
|
|
1922
|
-
* complete {@link toJsonObject} for server-side logs and hooks.
|
|
1989
|
+
* Keep {@link toJsonObject} for this side's own logs.
|
|
1923
1990
|
*/
|
|
1924
1991
|
toWireJsonObject() {
|
|
1925
|
-
const
|
|
1926
|
-
|
|
1992
|
+
const wire = this.toJsonObject({
|
|
1993
|
+
stack: false,
|
|
1994
|
+
originError: "omit"
|
|
1995
|
+
});
|
|
1996
|
+
if (!this.isUnhandled) return wire;
|
|
1997
|
+
return {
|
|
1998
|
+
...wire,
|
|
1999
|
+
ids: [SEALED_FAILURE_ID],
|
|
2000
|
+
errorData: { [SEALED_FAILURE_ID]: {
|
|
2001
|
+
contextState: {
|
|
2002
|
+
kind: "serde_unset",
|
|
2003
|
+
value: void 0
|
|
2004
|
+
},
|
|
2005
|
+
message: SEALED_FAILURE_MESSAGE,
|
|
2006
|
+
httpStatusCode: 500,
|
|
2007
|
+
timeAdded: this.timeCreated
|
|
2008
|
+
} },
|
|
2009
|
+
message: SEALED_FAILURE_MESSAGE,
|
|
2010
|
+
httpStatusCode: 500
|
|
2011
|
+
};
|
|
1927
2012
|
}
|
|
1928
2013
|
/**
|
|
1929
2014
|
* A flat, log-friendly object for telemetry / structured logging — distinct
|
|
1930
|
-
* from {@link toJsonObject} (the
|
|
2015
|
+
* from {@link toJsonObject} (the serialized form). Surfaces {@link isUnhandled} so a
|
|
1931
2016
|
* sink can separate "an error we accounted for" from "one we didn't".
|
|
1932
2017
|
*/
|
|
1933
2018
|
toStructuredLog() {
|
|
@@ -2512,6 +2597,10 @@ const err_cast_not_nice = err_nice.createChildDomain({
|
|
|
2512
2597
|
} catch {}
|
|
2513
2598
|
return `An unhandled type [${typeof jsDataValue}] with value [${inspectedValue ?? "UNSERIALIZABLE"}] was encountered during casting, which is not a valid error type`;
|
|
2514
2599
|
}
|
|
2600
|
+
}),
|
|
2601
|
+
["unhandled"]: err({
|
|
2602
|
+
message: SEALED_FAILURE_MESSAGE,
|
|
2603
|
+
httpStatusCode: 500
|
|
2515
2604
|
})
|
|
2516
2605
|
}
|
|
2517
2606
|
});
|
|
@@ -2697,6 +2786,15 @@ async function niceTryAsync(fn) {
|
|
|
2697
2786
|
}
|
|
2698
2787
|
}
|
|
2699
2788
|
//#endregion
|
|
2789
|
+
//#region ../nice-error/src/utils/sealedFailure.ts
|
|
2790
|
+
/**
|
|
2791
|
+
* The sealed failure as an error: what an error that `isUnhandled` is sent as. For a server that
|
|
2792
|
+
* answers with it itself, in place of something it caught and will not send.
|
|
2793
|
+
*/
|
|
2794
|
+
function sealedFailure() {
|
|
2795
|
+
return err_cast_not_nice.fromId("unhandled");
|
|
2796
|
+
}
|
|
2797
|
+
//#endregion
|
|
2700
2798
|
//#region ../nice-wire/src/Connect/err_wire_connect.ts
|
|
2701
2799
|
/**
|
|
2702
2800
|
* The Connect layer's error domain. Declared with the types
|
|
@@ -2774,11 +2872,13 @@ const err_wire_connect = err_nice.createChildDomain({
|
|
|
2774
2872
|
*/
|
|
2775
2873
|
peer_identity_mismatch: err({ message: ({ expected, actual, endpoint }) => `Secure peer identity mismatch: expected envId=${JSON.stringify(expected.envId)}${expected.perId != null ? `, perId=${JSON.stringify(expected.perId)}` : ""}; received envId=${JSON.stringify(actual.envId)}${actual.perId != null ? `, perId=${JSON.stringify(actual.perId)}` : ""}. ${endpoint != null ? `Dialed ${endpoint}. ` : ""}Carrier fallback and automatic redial are parked until an explicit retry.` }),
|
|
2776
2874
|
/**
|
|
2777
|
-
* This runtime
|
|
2778
|
-
*
|
|
2779
|
-
*
|
|
2875
|
+
* This runtime cannot do the handshake's cryptography, so a secure transport cannot connect.
|
|
2876
|
+
* Not a network condition: transport selection moves on to a plain carrier when one is
|
|
2877
|
+
* configured, and otherwise automatic redial parks on it. No frame is sent. The first two
|
|
2878
|
+
* reasons are raised before any dial; `algorithm_unsupported` is found at the first key, by
|
|
2879
|
+
* which time a socket carrier has opened its socket.
|
|
2780
2880
|
*/
|
|
2781
|
-
crypto_unavailable: err({ message: ({ reason, pageOrigin }) => reason === "insecure_context" ? `A secure connection needs WebCrypto (crypto.subtle), which a browser provides only to a secure context — and this page${pageOrigin != null ? ` (${pageOrigin})` : ""} is not one. Open it over HTTPS or on localhost. Automatic redial is parked.` : "A secure connection needs WebCrypto (crypto.subtle), which this runtime does not provide. Install a WebCrypto polyfill before connecting (on React Native, react-native-quick-crypto), or set `secure: false` on the carrier for a plain connection. Automatic redial is parked." }),
|
|
2881
|
+
crypto_unavailable: err({ message: ({ reason, pageOrigin, algorithm }) => reason === "insecure_context" ? `A secure connection needs WebCrypto (crypto.subtle), which a browser provides only to a secure context — and this page${pageOrigin != null ? ` (${pageOrigin})` : ""} is not one. Open it over HTTPS or on localhost. Automatic redial is parked.` : reason === "algorithm_unsupported" ? `A secure connection needs ${algorithm ?? "a curve"}, which this runtime's WebCrypto (crypto.subtle) does not provide: the browser is older than its support for it. Update the browser, or list a plain carrier (\`secure: false\`) after the secure one. Automatic redial is parked.` : "A secure connection needs WebCrypto (crypto.subtle), which this runtime does not provide. Install a WebCrypto polyfill before connecting (on React Native, react-native-quick-crypto), or set `secure: false` on the carrier for a plain connection. Automatic redial is parked." }),
|
|
2782
2882
|
/** Phase 3 — a protocol sent on a connection whose peer did not advertise it (or the host never registered it). */
|
|
2783
2883
|
protocol_unsupported: err({ message: ({ protocolId }) => `Protocol "${protocolId}" cannot speak on this connection — the peer did not advertise "proto:${protocolId}" (or it is not registered here).` }),
|
|
2784
2884
|
/** Phase 6 — a prefixed protocol registered on an exchange-only connection (protocols need duplex; the protocol contract). */
|
|
@@ -3067,244 +3167,6 @@ function endpointFromConnectFailure(error) {
|
|
|
3067
3167
|
if (error.hasId("peer_identity_mismatch")) return sanitizeEndpoint(error.getContext("peer_identity_mismatch").endpoint);
|
|
3068
3168
|
}
|
|
3069
3169
|
//#endregion
|
|
3070
|
-
//#region ../nice-wire/src/Connect/ConnectionTransportManager.ts
|
|
3071
|
-
/**
|
|
3072
|
-
* Preference-ordered transport selection over a shared connection cache — moved from nice-action
|
|
3073
|
-
* with the routing params (`RP`), finalized methods
|
|
3074
|
-
* (`METHODS`), and connection type (`CONN`) generic. Behavior is byte-for-byte the pre-move
|
|
3075
|
-
* logic: strict preference order with parallel warm-up, cache adoption guarded against teardown
|
|
3076
|
-
* races, and disconnect-driven eviction.
|
|
3077
|
-
*/
|
|
3078
|
-
var ConnectionTransportManager$1 = class {
|
|
3079
|
-
_cache;
|
|
3080
|
-
_errors;
|
|
3081
|
-
_transports = [];
|
|
3082
|
-
constructor(_cache, _errors) {
|
|
3083
|
-
this._cache = _cache;
|
|
3084
|
-
this._errors = _errors;
|
|
3085
|
-
}
|
|
3086
|
-
addTransport(transport) {
|
|
3087
|
-
this._transports.push(transport);
|
|
3088
|
-
}
|
|
3089
|
-
/**
|
|
3090
|
-
* The highest-priority transport (first declared). Used to label a dispatch's route *before* the
|
|
3091
|
-
* transport has finished connecting — so a still-connecting dispatch shows its (expected)
|
|
3092
|
-
* destination instead of an "unknown" hop. {@link getReadyTransport} still decides the real winner,
|
|
3093
|
-
* and the caller corrects the hop if a lower-priority transport ends up serving it.
|
|
3094
|
-
*/
|
|
3095
|
-
getPreferredTransport() {
|
|
3096
|
-
return this._transports[0];
|
|
3097
|
-
}
|
|
3098
|
-
async getReadyTransport(input) {
|
|
3099
|
-
const candidates = [];
|
|
3100
|
-
const unavailableTransports = [];
|
|
3101
|
-
let cryptoUnavailable;
|
|
3102
|
-
for (const transport of this._transports) {
|
|
3103
|
-
let cacheKey = null;
|
|
3104
|
-
try {
|
|
3105
|
-
if (!transport.isAvailable(input)) {
|
|
3106
|
-
unavailableTransports.push(transport);
|
|
3107
|
-
continue;
|
|
3108
|
-
}
|
|
3109
|
-
cacheKey = transport.getCacheKey(input);
|
|
3110
|
-
if (cacheKey != null) {
|
|
3111
|
-
const cached = this._cache.get(cacheKey);
|
|
3112
|
-
if (cached != null) {
|
|
3113
|
-
if (cached instanceof Promise) {
|
|
3114
|
-
candidates.push({
|
|
3115
|
-
transport,
|
|
3116
|
-
promise: cached,
|
|
3117
|
-
cacheKey,
|
|
3118
|
-
fresh: false
|
|
3119
|
-
});
|
|
3120
|
-
continue;
|
|
3121
|
-
}
|
|
3122
|
-
candidates.push({
|
|
3123
|
-
transport,
|
|
3124
|
-
promise: Promise.resolve({
|
|
3125
|
-
...cached,
|
|
3126
|
-
transport
|
|
3127
|
-
}),
|
|
3128
|
-
cacheKey,
|
|
3129
|
-
fresh: false
|
|
3130
|
-
});
|
|
3131
|
-
break;
|
|
3132
|
-
}
|
|
3133
|
-
}
|
|
3134
|
-
const statusInfo = transport.getTransport(input);
|
|
3135
|
-
if (statusInfo.status === "ready") {
|
|
3136
|
-
const readyData = statusInfo.readyData;
|
|
3137
|
-
if (cacheKey != null) {
|
|
3138
|
-
const key = cacheKey;
|
|
3139
|
-
const entry = {
|
|
3140
|
-
methods: readyData,
|
|
3141
|
-
transport
|
|
3142
|
-
};
|
|
3143
|
-
this._cache.set(key, entry);
|
|
3144
|
-
readyData.addOnDisconnectListener?.(() => {
|
|
3145
|
-
if (this._cache.get(key) === entry) this._cache.delete(key);
|
|
3146
|
-
});
|
|
3147
|
-
}
|
|
3148
|
-
candidates.push({
|
|
3149
|
-
transport,
|
|
3150
|
-
promise: Promise.resolve({
|
|
3151
|
-
methods: readyData,
|
|
3152
|
-
transport
|
|
3153
|
-
}),
|
|
3154
|
-
cacheKey,
|
|
3155
|
-
fresh: true
|
|
3156
|
-
});
|
|
3157
|
-
break;
|
|
3158
|
-
}
|
|
3159
|
-
if (statusInfo.status === "unsupported") {
|
|
3160
|
-
unavailableTransports.push(transport);
|
|
3161
|
-
continue;
|
|
3162
|
-
}
|
|
3163
|
-
if (statusInfo.status === "initializing") {
|
|
3164
|
-
const key = cacheKey;
|
|
3165
|
-
const promise = statusInfo.initializationPromise.then((info) => {
|
|
3166
|
-
if (info.status === "failed") throw info.error;
|
|
3167
|
-
if (info.status === "unsupported") throw this._errors.unsupported([transport.type]);
|
|
3168
|
-
const readyData = info.readyData;
|
|
3169
|
-
const entry = {
|
|
3170
|
-
methods: readyData,
|
|
3171
|
-
transport
|
|
3172
|
-
};
|
|
3173
|
-
if (key != null) if (this._cache.get(key) === promise) {
|
|
3174
|
-
this._cache.set(key, entry);
|
|
3175
|
-
readyData.addOnDisconnectListener?.(() => {
|
|
3176
|
-
if (this._cache.get(key) === entry) this._cache.delete(key);
|
|
3177
|
-
});
|
|
3178
|
-
} else readyData.disconnect?.();
|
|
3179
|
-
return entry;
|
|
3180
|
-
}).catch((e) => {
|
|
3181
|
-
if (key != null && this._cache.get(key) === promise) this._cache.delete(key);
|
|
3182
|
-
throw e;
|
|
3183
|
-
});
|
|
3184
|
-
promise.catch(() => {});
|
|
3185
|
-
if (key != null) this._cache.set(key, promise);
|
|
3186
|
-
candidates.push({
|
|
3187
|
-
transport,
|
|
3188
|
-
promise,
|
|
3189
|
-
cacheKey: key,
|
|
3190
|
-
fresh: true
|
|
3191
|
-
});
|
|
3192
|
-
}
|
|
3193
|
-
} catch (e) {
|
|
3194
|
-
if (isDialUnavailable$1(e)) {
|
|
3195
|
-
if (candidates.length === 0) throw e;
|
|
3196
|
-
unavailableTransports.push(transport);
|
|
3197
|
-
continue;
|
|
3198
|
-
}
|
|
3199
|
-
if (isCryptoUnavailable(e)) {
|
|
3200
|
-
cryptoUnavailable ??= e;
|
|
3201
|
-
continue;
|
|
3202
|
-
}
|
|
3203
|
-
const failed = Promise.reject(e);
|
|
3204
|
-
failed.catch(() => {});
|
|
3205
|
-
candidates.push({
|
|
3206
|
-
transport,
|
|
3207
|
-
promise: failed,
|
|
3208
|
-
cacheKey,
|
|
3209
|
-
fresh: true,
|
|
3210
|
-
callerThrew: true
|
|
3211
|
-
});
|
|
3212
|
-
}
|
|
3213
|
-
}
|
|
3214
|
-
if (candidates.length === 0) {
|
|
3215
|
-
if (cryptoUnavailable != null) throw cryptoUnavailable;
|
|
3216
|
-
if (unavailableTransports.length > 0) throw this._errors.unsupported(unavailableTransports.map((t) => t.type));
|
|
3217
|
-
throw this._errors.notFound(input);
|
|
3218
|
-
}
|
|
3219
|
-
let lastError;
|
|
3220
|
-
let lastTransport;
|
|
3221
|
-
let lastCallerThrew = false;
|
|
3222
|
-
for (const candidate of candidates) {
|
|
3223
|
-
let ready;
|
|
3224
|
-
try {
|
|
3225
|
-
ready = await candidate.promise;
|
|
3226
|
-
} catch (e) {
|
|
3227
|
-
if (isTerminalSelectionError(e)) {
|
|
3228
|
-
this._abandonWarmUps(candidates, candidate);
|
|
3229
|
-
throw this._withDialedEndpoint(e, candidate.transport, input);
|
|
3230
|
-
}
|
|
3231
|
-
lastError = e;
|
|
3232
|
-
lastTransport = candidate.transport;
|
|
3233
|
-
lastCallerThrew = candidate.callerThrew === true;
|
|
3234
|
-
continue;
|
|
3235
|
-
}
|
|
3236
|
-
ready.methods.onSelected?.();
|
|
3237
|
-
return ready;
|
|
3238
|
-
}
|
|
3239
|
-
if (err_wire_connect.isExact(lastError) && (lastError.hasId("dial_unavailable") || lastError.hasId("identity_pin_mismatch") || lastError.hasId("protocol_version_mismatch") || lastError.hasId("peer_identity_mismatch"))) throw lastError;
|
|
3240
|
-
if (lastCallerThrew && !err_wire_connect.isExact(lastError)) throw lastError;
|
|
3241
|
-
throw this._errors.initializationFailed(input, {
|
|
3242
|
-
cause: describeTransportFailure(lastError),
|
|
3243
|
-
endpoint: endpointFromConnectFailure(lastError) ?? routeEndpoint(lastTransport, input),
|
|
3244
|
-
kind: classifyConnectFailure(lastError),
|
|
3245
|
-
origin: lastError
|
|
3246
|
-
});
|
|
3247
|
-
}
|
|
3248
|
-
/**
|
|
3249
|
-
* Close the parallel warm-ups this selection started besides `failed`. Each one's cache slot is
|
|
3250
|
-
* released so a later dispatch re-dials; a warm-up still connecting closes itself when it lands.
|
|
3251
|
-
*/
|
|
3252
|
-
_abandonWarmUps(candidates, failed) {
|
|
3253
|
-
for (const candidate of candidates) {
|
|
3254
|
-
if (candidate === failed || !candidate.fresh) continue;
|
|
3255
|
-
const key = candidate.cacheKey;
|
|
3256
|
-
if (key != null && this._cache.get(key) === candidate.promise) this._cache.delete(key);
|
|
3257
|
-
candidate.promise.then((entry) => {
|
|
3258
|
-
if (key == null) {
|
|
3259
|
-
entry.methods.disconnect?.();
|
|
3260
|
-
return;
|
|
3261
|
-
}
|
|
3262
|
-
const cached = this._cache.get(key);
|
|
3263
|
-
if (cached != null && !(cached instanceof Promise) && cached.methods === entry.methods) {
|
|
3264
|
-
this._cache.delete(key);
|
|
3265
|
-
entry.methods.disconnect?.();
|
|
3266
|
-
}
|
|
3267
|
-
}, () => {});
|
|
3268
|
-
}
|
|
3269
|
-
}
|
|
3270
|
-
/** Attach the sanitized dialed endpoint to a peer-identity mismatch that lacks one. */
|
|
3271
|
-
_withDialedEndpoint(error, transport, input) {
|
|
3272
|
-
if (!err_wire_connect.isExact(error) || !error.hasId("peer_identity_mismatch")) return error;
|
|
3273
|
-
const context = error.getContext("peer_identity_mismatch");
|
|
3274
|
-
if (context.endpoint != null) return error;
|
|
3275
|
-
const endpoint = routeEndpoint(transport, input);
|
|
3276
|
-
if (endpoint == null) return error;
|
|
3277
|
-
return err_wire_connect.fromId("peer_identity_mismatch", {
|
|
3278
|
-
...context,
|
|
3279
|
-
endpoint
|
|
3280
|
-
}).withOriginError(error);
|
|
3281
|
-
}
|
|
3282
|
-
};
|
|
3283
|
-
const isDialUnavailable$1 = (error) => err_wire_connect.isExact(error) && error.hasId("dial_unavailable");
|
|
3284
|
-
const isCryptoUnavailable = (error) => err_wire_connect.isExact(error) && error.hasId("crypto_unavailable");
|
|
3285
|
-
const isTerminalSelectionError = (error) => err_wire_connect.isExact(error) && (error.hasId("peer_identity_mismatch") || error.hasId("protocol_version_mismatch"));
|
|
3286
|
-
/** The transport's sanitized route URL for diagnostics; a throwing route resolver yields none. */
|
|
3287
|
-
function routeEndpoint(transport, input) {
|
|
3288
|
-
if (transport == null) return void 0;
|
|
3289
|
-
try {
|
|
3290
|
-
return sanitizeEndpoint(transport.getRouteInfo(input)?.url);
|
|
3291
|
-
} catch {
|
|
3292
|
-
return;
|
|
3293
|
-
}
|
|
3294
|
-
}
|
|
3295
|
-
/**
|
|
3296
|
-
* A short, human-readable reason for a transport failing to connect — surfaced in the
|
|
3297
|
-
* consumer's initialization-failed message so the caller sees *why* (e.g. a rejected handshake) rather
|
|
3298
|
-
* than a bare "not ready". The full error is still attached as the origin error for the complete
|
|
3299
|
-
* chain/stack.
|
|
3300
|
-
*/
|
|
3301
|
-
function describeTransportFailure(error) {
|
|
3302
|
-
if (error == null) return void 0;
|
|
3303
|
-
if (error instanceof Error) return error.message;
|
|
3304
|
-
if (typeof error === "string") return error;
|
|
3305
|
-
return String(error);
|
|
3306
|
-
}
|
|
3307
|
-
//#endregion
|
|
3308
3170
|
//#region ../nice-util/src/data_type/string/nullEmpty.ts
|
|
3309
3171
|
const notNullEmpty = (str) => {
|
|
3310
3172
|
return str != null && str.length > 0;
|
|
@@ -4135,9 +3997,43 @@ function createTypedStorage({ storageAdapter, schemas, onInvalid }) {
|
|
|
4135
3997
|
};
|
|
4136
3998
|
}
|
|
4137
3999
|
//#endregion
|
|
4000
|
+
//#region ../nice-util/src/crypto/webCryptoCurveSupport.ts
|
|
4001
|
+
const UNSUPPORTED_NAME = "WebCryptoAlgorithmUnsupportedError";
|
|
4002
|
+
/**
|
|
4003
|
+
* `crypto.subtle` exists but refused the curve itself: a browser from before it shipped the
|
|
4004
|
+
* algorithm (Chrome before 137 has no Ed25519).
|
|
4005
|
+
*/
|
|
4006
|
+
var WebCryptoAlgorithmUnsupportedError = class extends Error {
|
|
4007
|
+
algorithm;
|
|
4008
|
+
constructor(algorithm, cause) {
|
|
4009
|
+
super(`This runtime's WebCrypto does not support ${algorithm}.`, { cause });
|
|
4010
|
+
this.name = UNSUPPORTED_NAME;
|
|
4011
|
+
this.algorithm = algorithm;
|
|
4012
|
+
}
|
|
4013
|
+
};
|
|
4014
|
+
/** Matches by shape, so a second copy of this package in a bundle still matches. */
|
|
4015
|
+
function isWebCryptoAlgorithmUnsupportedError(error) {
|
|
4016
|
+
return error instanceof Error && error.name === UNSUPPORTED_NAME && "algorithm" in error && (error.algorithm === "Ed25519" || error.algorithm === "X25519");
|
|
4017
|
+
}
|
|
4018
|
+
function isNotSupportedError(error) {
|
|
4019
|
+
return typeof error === "object" && error != null && "name" in error && error.name === "NotSupportedError";
|
|
4020
|
+
}
|
|
4021
|
+
/**
|
|
4022
|
+
* Run one `crypto.subtle` call that names `algorithm`. A runtime answers an algorithm it does not
|
|
4023
|
+
* have with a `NotSupportedError`, which says nothing of which one: rethrown here with its name.
|
|
4024
|
+
*/
|
|
4025
|
+
async function withCurveSupport(algorithm, call) {
|
|
4026
|
+
try {
|
|
4027
|
+
return await call();
|
|
4028
|
+
} catch (error) {
|
|
4029
|
+
if (isNotSupportedError(error)) throw new WebCryptoAlgorithmUnsupportedError(algorithm, error);
|
|
4030
|
+
throw error;
|
|
4031
|
+
}
|
|
4032
|
+
}
|
|
4033
|
+
//#endregion
|
|
4138
4034
|
//#region ../nice-util/src/crypto/ed25519/generateEd25519KeyPair.ts
|
|
4139
4035
|
const generateEd25519KeyPair = async () => {
|
|
4140
|
-
return await crypto.subtle.generateKey({ name: "Ed25519" }, true, ["sign", "verify"]);
|
|
4036
|
+
return await withCurveSupport("Ed25519", () => crypto.subtle.generateKey({ name: "Ed25519" }, true, ["sign", "verify"]));
|
|
4141
4037
|
};
|
|
4142
4038
|
//#endregion
|
|
4143
4039
|
//#region ../nice-util/src/core/createDataStringConverter_stringToObject.ts
|
|
@@ -4815,10 +4711,10 @@ const convertX25519FormattedStringToSerializedKeyData = (input) => {
|
|
|
4815
4711
|
//#region ../nice-util/src/crypto/ed25519/importEd25519Key.ts
|
|
4816
4712
|
const fromBase64$1 = async (dataBase64, keyUsage, extractable) => {
|
|
4817
4713
|
const keyBuffer = Uint8Array.from(base64$1.decode(dataBase64));
|
|
4818
|
-
return await crypto.subtle.importKey("raw", keyBuffer, { name: "Ed25519" }, extractable, keyUsage);
|
|
4714
|
+
return await withCurveSupport("Ed25519", () => crypto.subtle.importKey("raw", keyBuffer, { name: "Ed25519" }, extractable, keyUsage));
|
|
4819
4715
|
};
|
|
4820
4716
|
const fromJwk$1 = async (jwk, keyUsage, extractable = true) => {
|
|
4821
|
-
return await crypto.subtle.importKey("jwk", jwk, { name: "Ed25519" }, extractable, keyUsage);
|
|
4717
|
+
return await withCurveSupport("Ed25519", () => crypto.subtle.importKey("jwk", jwk, { name: "Ed25519" }, extractable, keyUsage));
|
|
4822
4718
|
};
|
|
4823
4719
|
const fromSerializedObject$1 = async (serialized, keyUsage, extractable = true) => {
|
|
4824
4720
|
if (serialized.format === "jwk") return await fromJwk$1(serialized.data, keyUsage, extractable);
|
|
@@ -4885,16 +4781,16 @@ const verifyWithKeyEd25519 = async ({ challenge, signatureBase64, publicKey }) =
|
|
|
4885
4781
|
//#endregion
|
|
4886
4782
|
//#region ../nice-util/src/crypto/x25519/generateX25519KeyPair.ts
|
|
4887
4783
|
const generateX25519KeyPair = async () => {
|
|
4888
|
-
return await crypto.subtle.generateKey({ name: "X25519" }, true, ["deriveKey", "deriveBits"]);
|
|
4784
|
+
return await withCurveSupport("X25519", () => crypto.subtle.generateKey({ name: "X25519" }, true, ["deriveKey", "deriveBits"]));
|
|
4889
4785
|
};
|
|
4890
4786
|
//#endregion
|
|
4891
4787
|
//#region ../nice-util/src/crypto/x25519/importX25519Key.ts
|
|
4892
4788
|
const fromBase64 = async (dataBase64, keyUsage, extractable) => {
|
|
4893
4789
|
const keyBuffer = Uint8Array.from(base64$1.decode(dataBase64));
|
|
4894
|
-
return await crypto.subtle.importKey("raw", keyBuffer, { name: "X25519" }, extractable, keyUsage);
|
|
4790
|
+
return await withCurveSupport("X25519", () => crypto.subtle.importKey("raw", keyBuffer, { name: "X25519" }, extractable, keyUsage));
|
|
4895
4791
|
};
|
|
4896
4792
|
const fromJwk = async (jwk, keyUsage, extractable = true) => {
|
|
4897
|
-
return await crypto.subtle.importKey("jwk", jwk, { name: "X25519" }, extractable, keyUsage);
|
|
4793
|
+
return await withCurveSupport("X25519", () => crypto.subtle.importKey("jwk", jwk, { name: "X25519" }, extractable, keyUsage));
|
|
4898
4794
|
};
|
|
4899
4795
|
const fromSerializedObject = async (serialized, keyUsage, extractable = true) => {
|
|
4900
4796
|
if (serialized.format === "jwk") return await fromJwk(serialized.data, keyUsage, extractable);
|
|
@@ -5745,6 +5641,276 @@ function unrefTimer(timer) {
|
|
|
5745
5641
|
if (typeof timer !== "number") timer.unref?.();
|
|
5746
5642
|
}
|
|
5747
5643
|
//#endregion
|
|
5644
|
+
//#region ../nice-wire/src/Connect/webCryptoPreflight.ts
|
|
5645
|
+
/**
|
|
5646
|
+
* The one check before a secure transport dials. A browser gives `crypto.subtle` only to a secure
|
|
5647
|
+
* context (HTTPS, or localhost), and some runtimes ship none until a polyfill is installed; either
|
|
5648
|
+
* way the handshake cannot run, and no retry will change that.
|
|
5649
|
+
*/
|
|
5650
|
+
function assertWebCryptoAvailable() {
|
|
5651
|
+
const runtime = globalThis;
|
|
5652
|
+
if (runtime.crypto?.subtle != null) return;
|
|
5653
|
+
if (runtime.isSecureContext === false) throw err_wire_connect.fromId("crypto_unavailable", {
|
|
5654
|
+
reason: "insecure_context",
|
|
5655
|
+
pageOrigin: runtime.location?.origin
|
|
5656
|
+
});
|
|
5657
|
+
throw err_wire_connect.fromId("crypto_unavailable", { reason: "no_webcrypto" });
|
|
5658
|
+
}
|
|
5659
|
+
/**
|
|
5660
|
+
* The same condition found later: `crypto.subtle` exists and passed the check above, then refused
|
|
5661
|
+
* a curve at the first key. Returns any other failure as it was given.
|
|
5662
|
+
*/
|
|
5663
|
+
function asCryptoUnavailable(error) {
|
|
5664
|
+
if (!isWebCryptoAlgorithmUnsupportedError(error)) return error;
|
|
5665
|
+
return err_wire_connect.fromId("crypto_unavailable", {
|
|
5666
|
+
reason: "algorithm_unsupported",
|
|
5667
|
+
algorithm: error.algorithm
|
|
5668
|
+
}).withOriginError(error);
|
|
5669
|
+
}
|
|
5670
|
+
//#endregion
|
|
5671
|
+
//#region ../nice-wire/src/Connect/ConnectionTransportManager.ts
|
|
5672
|
+
/**
|
|
5673
|
+
* Preference-ordered transport selection over a shared connection cache — moved from nice-action
|
|
5674
|
+
* with the routing params (`RP`), finalized methods
|
|
5675
|
+
* (`METHODS`), and connection type (`CONN`) generic. Behavior is byte-for-byte the pre-move
|
|
5676
|
+
* logic: strict preference order with parallel warm-up, cache adoption guarded against teardown
|
|
5677
|
+
* races, and disconnect-driven eviction.
|
|
5678
|
+
*/
|
|
5679
|
+
var ConnectionTransportManager$1 = class {
|
|
5680
|
+
_cache;
|
|
5681
|
+
_errors;
|
|
5682
|
+
_transports = [];
|
|
5683
|
+
constructor(_cache, _errors) {
|
|
5684
|
+
this._cache = _cache;
|
|
5685
|
+
this._errors = _errors;
|
|
5686
|
+
}
|
|
5687
|
+
addTransport(transport) {
|
|
5688
|
+
this._transports.push(transport);
|
|
5689
|
+
}
|
|
5690
|
+
/**
|
|
5691
|
+
* The highest-priority transport (first declared). Used to label a dispatch's route *before* the
|
|
5692
|
+
* transport has finished connecting — so a still-connecting dispatch shows its (expected)
|
|
5693
|
+
* destination instead of an "unknown" hop. {@link getReadyTransport} still decides the real winner,
|
|
5694
|
+
* and the caller corrects the hop if a lower-priority transport ends up serving it.
|
|
5695
|
+
*/
|
|
5696
|
+
getPreferredTransport() {
|
|
5697
|
+
return this._transports[0];
|
|
5698
|
+
}
|
|
5699
|
+
async getReadyTransport(input) {
|
|
5700
|
+
const candidates = [];
|
|
5701
|
+
const unavailableTransports = [];
|
|
5702
|
+
let cryptoUnavailable;
|
|
5703
|
+
for (const transport of this._transports) {
|
|
5704
|
+
let cacheKey = null;
|
|
5705
|
+
try {
|
|
5706
|
+
if (!transport.isAvailable(input)) {
|
|
5707
|
+
unavailableTransports.push(transport);
|
|
5708
|
+
continue;
|
|
5709
|
+
}
|
|
5710
|
+
cacheKey = transport.getCacheKey(input);
|
|
5711
|
+
if (cacheKey != null) {
|
|
5712
|
+
const cached = this._cache.get(cacheKey);
|
|
5713
|
+
if (cached != null) {
|
|
5714
|
+
if (cached instanceof Promise) {
|
|
5715
|
+
candidates.push({
|
|
5716
|
+
transport,
|
|
5717
|
+
promise: cached,
|
|
5718
|
+
cacheKey,
|
|
5719
|
+
fresh: false
|
|
5720
|
+
});
|
|
5721
|
+
continue;
|
|
5722
|
+
}
|
|
5723
|
+
candidates.push({
|
|
5724
|
+
transport,
|
|
5725
|
+
promise: Promise.resolve({
|
|
5726
|
+
...cached,
|
|
5727
|
+
transport
|
|
5728
|
+
}),
|
|
5729
|
+
cacheKey,
|
|
5730
|
+
fresh: false
|
|
5731
|
+
});
|
|
5732
|
+
break;
|
|
5733
|
+
}
|
|
5734
|
+
}
|
|
5735
|
+
const statusInfo = transport.getTransport(input);
|
|
5736
|
+
if (statusInfo.status === "ready") {
|
|
5737
|
+
const readyData = statusInfo.readyData;
|
|
5738
|
+
if (cacheKey != null) {
|
|
5739
|
+
const key = cacheKey;
|
|
5740
|
+
const entry = {
|
|
5741
|
+
methods: readyData,
|
|
5742
|
+
transport
|
|
5743
|
+
};
|
|
5744
|
+
this._cache.set(key, entry);
|
|
5745
|
+
readyData.addOnDisconnectListener?.(() => {
|
|
5746
|
+
if (this._cache.get(key) === entry) this._cache.delete(key);
|
|
5747
|
+
});
|
|
5748
|
+
}
|
|
5749
|
+
candidates.push({
|
|
5750
|
+
transport,
|
|
5751
|
+
promise: Promise.resolve({
|
|
5752
|
+
methods: readyData,
|
|
5753
|
+
transport
|
|
5754
|
+
}),
|
|
5755
|
+
cacheKey,
|
|
5756
|
+
fresh: true
|
|
5757
|
+
});
|
|
5758
|
+
break;
|
|
5759
|
+
}
|
|
5760
|
+
if (statusInfo.status === "unsupported") {
|
|
5761
|
+
unavailableTransports.push(transport);
|
|
5762
|
+
continue;
|
|
5763
|
+
}
|
|
5764
|
+
if (statusInfo.status === "initializing") {
|
|
5765
|
+
const key = cacheKey;
|
|
5766
|
+
const promise = statusInfo.initializationPromise.then((info) => {
|
|
5767
|
+
if (info.status === "failed") throw info.error;
|
|
5768
|
+
if (info.status === "unsupported") throw this._errors.unsupported([transport.type]);
|
|
5769
|
+
const readyData = info.readyData;
|
|
5770
|
+
const entry = {
|
|
5771
|
+
methods: readyData,
|
|
5772
|
+
transport
|
|
5773
|
+
};
|
|
5774
|
+
if (key != null) if (this._cache.get(key) === promise) {
|
|
5775
|
+
this._cache.set(key, entry);
|
|
5776
|
+
readyData.addOnDisconnectListener?.(() => {
|
|
5777
|
+
if (this._cache.get(key) === entry) this._cache.delete(key);
|
|
5778
|
+
});
|
|
5779
|
+
} else readyData.disconnect?.();
|
|
5780
|
+
return entry;
|
|
5781
|
+
}).catch((e) => {
|
|
5782
|
+
if (key != null && this._cache.get(key) === promise) this._cache.delete(key);
|
|
5783
|
+
throw asCryptoUnavailable(e);
|
|
5784
|
+
});
|
|
5785
|
+
promise.catch(() => {});
|
|
5786
|
+
if (key != null) this._cache.set(key, promise);
|
|
5787
|
+
candidates.push({
|
|
5788
|
+
transport,
|
|
5789
|
+
promise,
|
|
5790
|
+
cacheKey: key,
|
|
5791
|
+
fresh: true
|
|
5792
|
+
});
|
|
5793
|
+
}
|
|
5794
|
+
} catch (e) {
|
|
5795
|
+
if (isDialUnavailable$1(e)) {
|
|
5796
|
+
if (candidates.length === 0) throw e;
|
|
5797
|
+
unavailableTransports.push(transport);
|
|
5798
|
+
continue;
|
|
5799
|
+
}
|
|
5800
|
+
if (isCryptoUnavailable(e)) {
|
|
5801
|
+
cryptoUnavailable ??= e;
|
|
5802
|
+
continue;
|
|
5803
|
+
}
|
|
5804
|
+
const failed = Promise.reject(e);
|
|
5805
|
+
failed.catch(() => {});
|
|
5806
|
+
candidates.push({
|
|
5807
|
+
transport,
|
|
5808
|
+
promise: failed,
|
|
5809
|
+
cacheKey,
|
|
5810
|
+
fresh: true,
|
|
5811
|
+
callerThrew: true
|
|
5812
|
+
});
|
|
5813
|
+
}
|
|
5814
|
+
}
|
|
5815
|
+
if (candidates.length === 0) {
|
|
5816
|
+
if (cryptoUnavailable != null) throw cryptoUnavailable;
|
|
5817
|
+
if (unavailableTransports.length > 0) throw this._errors.unsupported(unavailableTransports.map((t) => t.type));
|
|
5818
|
+
throw this._errors.notFound(input);
|
|
5819
|
+
}
|
|
5820
|
+
let lastError;
|
|
5821
|
+
let lastTransport;
|
|
5822
|
+
let lastCallerThrew = false;
|
|
5823
|
+
for (const candidate of candidates) {
|
|
5824
|
+
let ready;
|
|
5825
|
+
try {
|
|
5826
|
+
ready = await candidate.promise;
|
|
5827
|
+
} catch (e) {
|
|
5828
|
+
if (isTerminalSelectionError(e)) {
|
|
5829
|
+
this._abandonWarmUps(candidates, candidate);
|
|
5830
|
+
throw this._withDialedEndpoint(e, candidate.transport, input);
|
|
5831
|
+
}
|
|
5832
|
+
if (isCryptoUnavailable(e)) {
|
|
5833
|
+
cryptoUnavailable ??= e;
|
|
5834
|
+
continue;
|
|
5835
|
+
}
|
|
5836
|
+
lastError = e;
|
|
5837
|
+
lastTransport = candidate.transport;
|
|
5838
|
+
lastCallerThrew = candidate.callerThrew === true;
|
|
5839
|
+
continue;
|
|
5840
|
+
}
|
|
5841
|
+
ready.methods.onSelected?.();
|
|
5842
|
+
return ready;
|
|
5843
|
+
}
|
|
5844
|
+
if (lastTransport == null && cryptoUnavailable != null) throw cryptoUnavailable;
|
|
5845
|
+
if (err_wire_connect.isExact(lastError) && (lastError.hasId("dial_unavailable") || lastError.hasId("identity_pin_mismatch") || lastError.hasId("protocol_version_mismatch") || lastError.hasId("peer_identity_mismatch"))) throw lastError;
|
|
5846
|
+
if (lastCallerThrew && !err_wire_connect.isExact(lastError)) throw lastError;
|
|
5847
|
+
throw this._errors.initializationFailed(input, {
|
|
5848
|
+
cause: describeTransportFailure(lastError),
|
|
5849
|
+
endpoint: endpointFromConnectFailure(lastError) ?? routeEndpoint(lastTransport, input),
|
|
5850
|
+
kind: classifyConnectFailure(lastError),
|
|
5851
|
+
origin: lastError
|
|
5852
|
+
});
|
|
5853
|
+
}
|
|
5854
|
+
/**
|
|
5855
|
+
* Close the parallel warm-ups this selection started besides `failed`. Each one's cache slot is
|
|
5856
|
+
* released so a later dispatch re-dials; a warm-up still connecting closes itself when it lands.
|
|
5857
|
+
*/
|
|
5858
|
+
_abandonWarmUps(candidates, failed) {
|
|
5859
|
+
for (const candidate of candidates) {
|
|
5860
|
+
if (candidate === failed || !candidate.fresh) continue;
|
|
5861
|
+
const key = candidate.cacheKey;
|
|
5862
|
+
if (key != null && this._cache.get(key) === candidate.promise) this._cache.delete(key);
|
|
5863
|
+
candidate.promise.then((entry) => {
|
|
5864
|
+
if (key == null) {
|
|
5865
|
+
entry.methods.disconnect?.();
|
|
5866
|
+
return;
|
|
5867
|
+
}
|
|
5868
|
+
const cached = this._cache.get(key);
|
|
5869
|
+
if (cached != null && !(cached instanceof Promise) && cached.methods === entry.methods) {
|
|
5870
|
+
this._cache.delete(key);
|
|
5871
|
+
entry.methods.disconnect?.();
|
|
5872
|
+
}
|
|
5873
|
+
}, () => {});
|
|
5874
|
+
}
|
|
5875
|
+
}
|
|
5876
|
+
/** Attach the sanitized dialed endpoint to a peer-identity mismatch that lacks one. */
|
|
5877
|
+
_withDialedEndpoint(error, transport, input) {
|
|
5878
|
+
if (!err_wire_connect.isExact(error) || !error.hasId("peer_identity_mismatch")) return error;
|
|
5879
|
+
const context = error.getContext("peer_identity_mismatch");
|
|
5880
|
+
if (context.endpoint != null) return error;
|
|
5881
|
+
const endpoint = routeEndpoint(transport, input);
|
|
5882
|
+
if (endpoint == null) return error;
|
|
5883
|
+
return err_wire_connect.fromId("peer_identity_mismatch", {
|
|
5884
|
+
...context,
|
|
5885
|
+
endpoint
|
|
5886
|
+
}).withOriginError(error);
|
|
5887
|
+
}
|
|
5888
|
+
};
|
|
5889
|
+
const isDialUnavailable$1 = (error) => err_wire_connect.isExact(error) && error.hasId("dial_unavailable");
|
|
5890
|
+
const isCryptoUnavailable = (error) => err_wire_connect.isExact(error) && error.hasId("crypto_unavailable");
|
|
5891
|
+
const isTerminalSelectionError = (error) => err_wire_connect.isExact(error) && (error.hasId("peer_identity_mismatch") || error.hasId("protocol_version_mismatch"));
|
|
5892
|
+
/** The transport's sanitized route URL for diagnostics; a throwing route resolver yields none. */
|
|
5893
|
+
function routeEndpoint(transport, input) {
|
|
5894
|
+
if (transport == null) return void 0;
|
|
5895
|
+
try {
|
|
5896
|
+
return sanitizeEndpoint(transport.getRouteInfo(input)?.url);
|
|
5897
|
+
} catch {
|
|
5898
|
+
return;
|
|
5899
|
+
}
|
|
5900
|
+
}
|
|
5901
|
+
/**
|
|
5902
|
+
* A short, human-readable reason for a transport failing to connect — surfaced in the
|
|
5903
|
+
* consumer's initialization-failed message so the caller sees *why* (e.g. a rejected handshake) rather
|
|
5904
|
+
* than a bare "not ready". The full error is still attached as the origin error for the complete
|
|
5905
|
+
* chain/stack.
|
|
5906
|
+
*/
|
|
5907
|
+
function describeTransportFailure(error) {
|
|
5908
|
+
if (error == null) return void 0;
|
|
5909
|
+
if (error instanceof Error) return error.message;
|
|
5910
|
+
if (typeof error === "string") return error;
|
|
5911
|
+
return String(error);
|
|
5912
|
+
}
|
|
5913
|
+
//#endregion
|
|
5748
5914
|
//#region ../../node_modules/nanoid/url-alphabet/index.js
|
|
5749
5915
|
let urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
|
|
5750
5916
|
//#endregion
|
|
@@ -6429,7 +6595,7 @@ const isDialUnavailable = (e) => err_wire_connect.isExact(e) && e.hasId("dial_un
|
|
|
6429
6595
|
* right now ({@link isDialUnavailable}), or the peer rejected the handshake with
|
|
6430
6596
|
* `identity_pin_mismatch` (the peer has a different key pinned) or
|
|
6431
6597
|
* `protocol_version_mismatch` (the two builds have no compatible secure-wire generation), or this
|
|
6432
|
-
* runtime
|
|
6598
|
+
* runtime cannot do the handshake's cryptography at all (`crypto_unavailable`).
|
|
6433
6599
|
* Parking is not terminal: the next explicit `connect()`/dispatch may try again after the app has
|
|
6434
6600
|
* upgraded or changed endpoints. Other handshake rejections (e.g. a dictionary mismatch) retain
|
|
6435
6601
|
* the existing retry behavior because a matching deploy can heal them.
|
|
@@ -9775,22 +9941,6 @@ function onChannelClosed(disconnectListeners, lane) {
|
|
|
9775
9941
|
lane.onDetach?.();
|
|
9776
9942
|
}
|
|
9777
9943
|
//#endregion
|
|
9778
|
-
//#region ../nice-wire/src/Connect/webCryptoPreflight.ts
|
|
9779
|
-
/**
|
|
9780
|
-
* The one check before a secure transport dials. A browser gives `crypto.subtle` only to a secure
|
|
9781
|
-
* context (HTTPS, or localhost), and some runtimes ship none until a polyfill is installed; either
|
|
9782
|
-
* way the handshake cannot run, and no retry will change that.
|
|
9783
|
-
*/
|
|
9784
|
-
function assertWebCryptoAvailable() {
|
|
9785
|
-
const runtime = globalThis;
|
|
9786
|
-
if (runtime.crypto?.subtle != null) return;
|
|
9787
|
-
if (runtime.isSecureContext === false) throw err_wire_connect.fromId("crypto_unavailable", {
|
|
9788
|
-
reason: "insecure_context",
|
|
9789
|
-
pageOrigin: runtime.location?.origin
|
|
9790
|
-
});
|
|
9791
|
-
throw err_wire_connect.fromId("crypto_unavailable", { reason: "no_webcrypto" });
|
|
9792
|
-
}
|
|
9793
|
-
//#endregion
|
|
9794
9944
|
//#region ../nice-wire/src/Connect/TransportConnection.ts
|
|
9795
9945
|
let transportOrd = 0;
|
|
9796
9946
|
/**
|
|
@@ -10391,7 +10541,9 @@ function makeSession(carrier, source, insId) {
|
|
|
10391
10541
|
if (reply.k === "err") return {
|
|
10392
10542
|
ok: false,
|
|
10393
10543
|
reason: "peer_error",
|
|
10394
|
-
message: reply.message
|
|
10544
|
+
message: reply.message,
|
|
10545
|
+
id: reply.id,
|
|
10546
|
+
peerReason: reply.reason
|
|
10395
10547
|
};
|
|
10396
10548
|
const replyWire = await extractReplyWire(state, reply);
|
|
10397
10549
|
if (replyWire === void 0) return {
|
|
@@ -10512,6 +10664,23 @@ function asString(frame) {
|
|
|
10512
10664
|
return textDecoder$1.decode(frame instanceof ArrayBuffer ? new Uint8Array(frame) : frame);
|
|
10513
10665
|
}
|
|
10514
10666
|
//#endregion
|
|
10667
|
+
//#region ../nice-wire/src/Connect/requestOrigin.ts
|
|
10668
|
+
/**
|
|
10669
|
+
* The `403` for a request whose `Origin` is not allowed, or `undefined` when it may proceed. A
|
|
10670
|
+
* request that names no `Origin` passes: only a browser sends one, so this stops another site's
|
|
10671
|
+
* page, not a native or server client.
|
|
10672
|
+
*/
|
|
10673
|
+
function refuseUnlistedOrigin(request, allowedOrigins) {
|
|
10674
|
+
if (allowedOrigins == null) return void 0;
|
|
10675
|
+
const origin = request.headers.get("Origin");
|
|
10676
|
+
if (origin == null) return void 0;
|
|
10677
|
+
if (typeof allowedOrigins === "function" ? allowedOrigins(origin) : allowedOrigins.includes(origin)) return void 0;
|
|
10678
|
+
return new Response(JSON.stringify({ error: "origin not allowed" }), {
|
|
10679
|
+
status: 403,
|
|
10680
|
+
headers: { "Content-Type": "application/json" }
|
|
10681
|
+
});
|
|
10682
|
+
}
|
|
10683
|
+
//#endregion
|
|
10515
10684
|
//#region ../nice-wire/src/SecureSession/acceptorSecureSession.ts
|
|
10516
10685
|
/**
|
|
10517
10686
|
* The acceptor (accept-in) counterpart to the connector's `establishLinkSession`: one connection's
|
|
@@ -11229,10 +11398,18 @@ var WireExchangeAcceptor = class {
|
|
|
11229
11398
|
securityLevel,
|
|
11230
11399
|
encrypted: crypto != null
|
|
11231
11400
|
});
|
|
11232
|
-
if (!laneReply.ok)
|
|
11233
|
-
|
|
11234
|
-
|
|
11235
|
-
|
|
11401
|
+
if (!laneReply.ok) {
|
|
11402
|
+
const { message, id, reason } = laneReply;
|
|
11403
|
+
return id == null ? {
|
|
11404
|
+
k: "err",
|
|
11405
|
+
message
|
|
11406
|
+
} : {
|
|
11407
|
+
k: "err",
|
|
11408
|
+
message,
|
|
11409
|
+
id,
|
|
11410
|
+
reason
|
|
11411
|
+
};
|
|
11412
|
+
}
|
|
11236
11413
|
if (crypto != null) return {
|
|
11237
11414
|
k: "act",
|
|
11238
11415
|
c: bytesToBase64(await crypto.encryptFrame(textEncoder.encode(JSON.stringify(laneReply.wire))))
|
|
@@ -11891,26 +12068,32 @@ var ActionPayload_Result = class extends ActionPayload {
|
|
|
11891
12068
|
}
|
|
11892
12069
|
}
|
|
11893
12070
|
toJsonObject() {
|
|
11894
|
-
|
|
11895
|
-
|
|
11896
|
-
|
|
11897
|
-
|
|
11898
|
-
|
|
11899
|
-
|
|
11900
|
-
|
|
12071
|
+
if (this.result.ok) return {
|
|
12072
|
+
...this.toBaseJsonObject(),
|
|
12073
|
+
result: {
|
|
12074
|
+
ok: true,
|
|
12075
|
+
output: this.context.schema.serializeOutput(this.result.output)
|
|
12076
|
+
},
|
|
12077
|
+
outputHash: this.outputHash
|
|
11901
12078
|
};
|
|
12079
|
+
const error = this.result.error.toWireJsonObject();
|
|
11902
12080
|
return {
|
|
11903
12081
|
...this.toBaseJsonObject(),
|
|
11904
|
-
result:
|
|
11905
|
-
|
|
12082
|
+
result: {
|
|
12083
|
+
ok: false,
|
|
12084
|
+
expected: this.result.expected,
|
|
12085
|
+
error
|
|
12086
|
+
},
|
|
12087
|
+
outputHash: hashPayloadData(error.message)
|
|
11906
12088
|
};
|
|
11907
12089
|
}
|
|
11908
12090
|
toJsonString() {
|
|
11909
12091
|
return JSON.stringify(this.toJsonObject());
|
|
11910
12092
|
}
|
|
11911
12093
|
toHttpResponse({ useErrorStatus = true } = {}) {
|
|
11912
|
-
|
|
11913
|
-
|
|
12094
|
+
const json = this.toJsonObject();
|
|
12095
|
+
return new Response(JSON.stringify(json), {
|
|
12096
|
+
status: json.result.ok ? 200 : useErrorStatus ? json.result.error.httpStatusCode : 500,
|
|
11914
12097
|
headers: { "Content-Type": "application/json" }
|
|
11915
12098
|
});
|
|
11916
12099
|
}
|
|
@@ -12341,6 +12524,26 @@ const err_nice_action = err_nice.createChildDomain({
|
|
|
12341
12524
|
}
|
|
12342
12525
|
});
|
|
12343
12526
|
//#endregion
|
|
12527
|
+
//#region ../nice-action/src/utils/actionPayloadContextProblem.ts
|
|
12528
|
+
function isRouteItem(item) {
|
|
12529
|
+
return typeof item === "object" && item != null && "runtime" in item && typeof item.runtime === "object" && item.runtime != null;
|
|
12530
|
+
}
|
|
12531
|
+
/**
|
|
12532
|
+
* What stops a payload's `context` from being hydrated, or `undefined` when nothing does. `cuid`,
|
|
12533
|
+
* `timeCreated` and `originClient` may be absent; `routing` may not.
|
|
12534
|
+
*/
|
|
12535
|
+
function actionPayloadContextProblem(context) {
|
|
12536
|
+
if (typeof context !== "object" || context == null) return "missing";
|
|
12537
|
+
if (!("routing" in context) || !Array.isArray(context.routing)) return "routing";
|
|
12538
|
+
if (!context.routing.every(isRouteItem)) return "route_item";
|
|
12539
|
+
if ("cuid" in context && context.cuid != null && typeof context.cuid !== "string") return "cuid";
|
|
12540
|
+
if ("originClient" in context && context.originClient != null && typeof context.originClient !== "object") return "origin_client";
|
|
12541
|
+
}
|
|
12542
|
+
/** Whether a payload's `context` can be hydrated. */
|
|
12543
|
+
function hasHydratableContext(payload) {
|
|
12544
|
+
return "context" in payload && actionPayloadContextProblem(payload.context) == null;
|
|
12545
|
+
}
|
|
12546
|
+
//#endregion
|
|
12344
12547
|
//#region ../nice-action/src/utils/isAction_Base_JsonObject.ts
|
|
12345
12548
|
const isAction_Base_JsonObject = (obj) => {
|
|
12346
12549
|
return typeof obj === "object" && obj !== null && typeof obj.domain === "string" && typeof obj.id === "string" && typeof obj.form === "string";
|
|
@@ -12348,7 +12551,7 @@ const isAction_Base_JsonObject = (obj) => {
|
|
|
12348
12551
|
//#endregion
|
|
12349
12552
|
//#region ../nice-action/src/utils/isActionPayload_Result_JsonObject.ts
|
|
12350
12553
|
const isActionPayload_Result_JsonObject = (obj) => {
|
|
12351
|
-
return isAction_Base_JsonObject(obj) && obj.result != null && obj.form === "data" && obj.type === "result";
|
|
12554
|
+
return isAction_Base_JsonObject(obj) && "result" in obj && obj.result != null && obj.form === "data" && "type" in obj && obj.type === "result" && hasHydratableContext(obj);
|
|
12352
12555
|
};
|
|
12353
12556
|
//#endregion
|
|
12354
12557
|
//#region ../../node_modules/http-status-codes/build/cjs/legacy.js
|
|
@@ -14037,12 +14240,12 @@ const getAssumedRuntimeInfo = () => {
|
|
|
14037
14240
|
//#endregion
|
|
14038
14241
|
//#region ../nice-action/src/utils/isActionPayload_Progress_JsonObject.ts
|
|
14039
14242
|
const isActionPayload_Progress_JsonObject = (obj) => {
|
|
14040
|
-
return isAction_Base_JsonObject(obj) && "progress" in obj && obj.form === "data" && obj.type === "progress";
|
|
14243
|
+
return isAction_Base_JsonObject(obj) && "progress" in obj && obj.form === "data" && "type" in obj && obj.type === "progress" && hasHydratableContext(obj);
|
|
14041
14244
|
};
|
|
14042
14245
|
//#endregion
|
|
14043
14246
|
//#region ../nice-action/src/utils/isActionPayload_Request_JsonObject.ts
|
|
14044
14247
|
const isActionPayload_Request_JsonObject = (obj) => {
|
|
14045
|
-
return isAction_Base_JsonObject(obj) && obj.form === "data" && obj.type === "request";
|
|
14248
|
+
return isAction_Base_JsonObject(obj) && obj.form === "data" && "type" in obj && obj.type === "request" && hasHydratableContext(obj);
|
|
14046
14249
|
};
|
|
14047
14250
|
//#endregion
|
|
14048
14251
|
//#region ../nice-action/src/utils/isActionPayload_Any_JsonObject.ts
|
|
@@ -14082,6 +14285,14 @@ const err_nice_transport = err_nice_action.createChildDomain({
|
|
|
14082
14285
|
httpStatusCode: ({ httpStatusCode }) => httpStatusCode ?? 500
|
|
14083
14286
|
}),
|
|
14084
14287
|
["invalid_action_response"]: err({ message: ({ actionId }) => `Invalid action response JSON structure for action "${actionId}"` }),
|
|
14288
|
+
/**
|
|
14289
|
+
* The peer was reached and refused the request before any action ran. Over HTTP the call rejects
|
|
14290
|
+
* with this; on a socket it is the error of a failed result.
|
|
14291
|
+
*/
|
|
14292
|
+
["action_not_served"]: err({
|
|
14293
|
+
message: ({ domain, actionId, reason }) => `The peer does not serve action "${domain}:${actionId}" (${reason}).`,
|
|
14294
|
+
httpStatusCode: 404
|
|
14295
|
+
}),
|
|
14085
14296
|
["reliable_outbox_overflow"]: err({ message: ({ actionId, maxUnacked }) => `Reliable outbox for action "${actionId}" exceeded its unacked window (${maxUnacked}) — the peer is not acknowledging. Send rejected to bound memory.` }),
|
|
14086
14297
|
["reliable_delivery_abandoned"]: err({ message: ({ actionId, timeout }) => `Reliable action "${actionId}" was abandoned: not acknowledged within its ${timeout}ms delivery deadline (or swept with an aborted earlier frame on its stream). The stream skips past it and continues.` }),
|
|
14087
14298
|
["reliable_stream_closed"]: err({ message: ({ actionId, streamId }) => `Reliable action "${actionId}" was abandoned because its stream ("${streamId}") was closed (closeReliableStream) while the send was still unacknowledged.` })
|
|
@@ -15147,9 +15358,13 @@ var ActionRuntime = class {
|
|
|
15147
15358
|
}
|
|
15148
15359
|
/** @internal Hydrate a wire request and attach receiver-owned metadata before application dispatch. */
|
|
15149
15360
|
async _handleActionPayloadWireFromReceiver(wire, metadata) {
|
|
15361
|
+
return this.handleActionPayload(this._hydrateWireFromReceiver(wire, metadata));
|
|
15362
|
+
}
|
|
15363
|
+
/** @internal Throws for a wire this runtime cannot hydrate: an unknown domain or action. */
|
|
15364
|
+
_hydrateWireFromReceiver(wire, metadata) {
|
|
15150
15365
|
const action = this._hydrateActionPayloadWire(wire);
|
|
15151
15366
|
if (metadata != null) action.context._setReceiverMetadata(metadata);
|
|
15152
|
-
return
|
|
15367
|
+
return action;
|
|
15153
15368
|
}
|
|
15154
15369
|
_hydrateActionPayloadWire(wire) {
|
|
15155
15370
|
if (isActionPayload_Any_JsonObject(wire)) return this.actionRouter.domainManager.getActionDomainOrThrow(wire).hydrateAnyAction(wire);
|
|
@@ -15181,6 +15396,10 @@ var ActionRuntime = class {
|
|
|
15181
15396
|
reliabilityTierForWire(wire) {
|
|
15182
15397
|
return this.reliabilityTierForRoute(wire.domain, wire.id);
|
|
15183
15398
|
}
|
|
15399
|
+
/** @internal The registered domain a wire names, if this runtime has it. */
|
|
15400
|
+
_domainForWire(wire) {
|
|
15401
|
+
return this.actionRouter.domainManager.getActionDomain(wire);
|
|
15402
|
+
}
|
|
15184
15403
|
/**
|
|
15185
15404
|
* {@link reliabilityTierForWire} by bare `domain:id` route — for callers holding only a route, e.g. the
|
|
15186
15405
|
* reliable acceptor resolving which receive store an `rskip` control message (no action payload) applies to.
|
|
@@ -15608,6 +15827,7 @@ var ActionLocalHandler = class extends ActionHandler {
|
|
|
15608
15827
|
const metadata = state.request.context._getReceiverMetadata();
|
|
15609
15828
|
const context = {
|
|
15610
15829
|
runtime,
|
|
15830
|
+
cuid: state.request.context.cuid,
|
|
15611
15831
|
origin: state.request.context.originClient,
|
|
15612
15832
|
authenticatedOrigin: metadata?.originAuthenticated === true ? state.request.context.originClient : void 0,
|
|
15613
15833
|
securityLevel: metadata?.securityLevel,
|
|
@@ -15914,7 +16134,7 @@ var ActionDomain = class ActionDomain extends ActionDomainBase {
|
|
|
15914
16134
|
hydrateContext(id, contextData) {
|
|
15915
16135
|
return new ActionContext(this, id, {
|
|
15916
16136
|
timeCreated: contextData.timeCreated,
|
|
15917
|
-
cuid: contextData.cuid,
|
|
16137
|
+
cuid: contextData.cuid ?? nanoid(),
|
|
15918
16138
|
routing: contextData.routing.map((item) => {
|
|
15919
16139
|
return {
|
|
15920
16140
|
runtime: new RuntimeCoordinate(item.runtime),
|
|
@@ -16027,6 +16247,7 @@ function actionServeRequestInfo(wire, meta) {
|
|
|
16027
16247
|
domain: wire.domain,
|
|
16028
16248
|
action: wire.id,
|
|
16029
16249
|
actionId: `${wire.domain}/${wire.id}`,
|
|
16250
|
+
cuid: wire.context.cuid,
|
|
16030
16251
|
origin,
|
|
16031
16252
|
securityLevel: meta.securityLevel,
|
|
16032
16253
|
input: wire.input,
|
|
@@ -16046,6 +16267,22 @@ function serveResultErrorInfo(error) {
|
|
|
16046
16267
|
message: error.cleanMessage ?? error.message
|
|
16047
16268
|
};
|
|
16048
16269
|
}
|
|
16270
|
+
/** A failed action's outcome, as the line a serve logger's reporter takes. */
|
|
16271
|
+
function failedResultInfo(thrown, sealed, served) {
|
|
16272
|
+
return {
|
|
16273
|
+
ok: false,
|
|
16274
|
+
...served,
|
|
16275
|
+
error: serveResultErrorInfo(thrown),
|
|
16276
|
+
thrown,
|
|
16277
|
+
sealed
|
|
16278
|
+
};
|
|
16279
|
+
}
|
|
16280
|
+
/** What a log prints for a failed action: the value a handler threw, and not the cast around it. */
|
|
16281
|
+
function thrownForLog(error) {
|
|
16282
|
+
return error.isUnhandled ? error.originError ?? error : error;
|
|
16283
|
+
}
|
|
16284
|
+
/** Their messages quote the value the schema rejected, which a log hides as it hides an input. */
|
|
16285
|
+
const VALIDATION_FAILURE_IDS = new Set(["err_nice_action/action_input_validation_failed", "err_nice_action/action_output_validation_failed"]);
|
|
16049
16286
|
/**
|
|
16050
16287
|
* A ready-made {@link IActionServeLogger} that prints one line when a request arrives and one when it has
|
|
16051
16288
|
* been served, to `console` (or any `sink` you pass). Drop it straight into `serveChannel` so a "host and
|
|
@@ -16055,7 +16292,9 @@ function serveResultErrorInfo(error) {
|
|
|
16055
16292
|
* // → [nice-action] ▶ demo_basic/greet via http from envId[web_app]… [encrypted]
|
|
16056
16293
|
* // ← [nice-action] ✓ demo_basic/greet ok via http 12ms
|
|
16057
16294
|
* ```
|
|
16058
|
-
* Inputs are hidden by default (`logInputs: true` to include them).
|
|
16295
|
+
* Inputs are hidden by default (`logInputs: true` to include them). A failed line ends with the
|
|
16296
|
+
* request's `cuid`. For a failure the caller was sent sealed, the sink is also handed what the
|
|
16297
|
+
* handler threw.
|
|
16059
16298
|
*/
|
|
16060
16299
|
function createDefaultServeLogger(options = {}) {
|
|
16061
16300
|
const sink = options.sink ?? console;
|
|
@@ -16087,11 +16326,19 @@ function createDefaultServeLogger(options = {}) {
|
|
|
16087
16326
|
`${result.durationMs}ms`
|
|
16088
16327
|
];
|
|
16089
16328
|
if (result.bytes != null) line.push(`${result.bytes}B`);
|
|
16090
|
-
if (
|
|
16091
|
-
|
|
16092
|
-
|
|
16329
|
+
if (result.ok) {
|
|
16330
|
+
sink.log(line.join(" "));
|
|
16331
|
+
return;
|
|
16093
16332
|
}
|
|
16094
|
-
(result.
|
|
16333
|
+
if (result.error != null) {
|
|
16334
|
+
const { id, message } = result.error;
|
|
16335
|
+
const hidden = id != null && VALIDATION_FAILURE_IDS.has(id) && !options.logInputs;
|
|
16336
|
+
line.push(`— ${hidden ? id : id != null ? `${id}: ${message}` : message}`);
|
|
16337
|
+
}
|
|
16338
|
+
if (result.sealed) line.push("[sealed]");
|
|
16339
|
+
line.push(`cuid=${info.cuid}`);
|
|
16340
|
+
if (result.sealed && result.thrown != null) sink.error(line.join(" "), thrownForLog(result.thrown));
|
|
16341
|
+
else sink.error(line.join(" "));
|
|
16095
16342
|
};
|
|
16096
16343
|
} };
|
|
16097
16344
|
}
|
|
@@ -16103,6 +16350,201 @@ function safeJson(value) {
|
|
|
16103
16350
|
}
|
|
16104
16351
|
}
|
|
16105
16352
|
//#endregion
|
|
16353
|
+
//#region ../nice-action/src/ActionRuntime/actionFailureSealing.ts
|
|
16354
|
+
function isOwn(error, id) {
|
|
16355
|
+
return err_nice_action.isExact(error) && error.hasId(id);
|
|
16356
|
+
}
|
|
16357
|
+
/** What `"off"` sends: the failure with its stack and origin error, and unsealed. */
|
|
16358
|
+
var WholeFailureResult = class extends ActionPayload_Result {
|
|
16359
|
+
toJsonObject() {
|
|
16360
|
+
const json = super.toJsonObject();
|
|
16361
|
+
if (this.result.ok || json.result.ok) return json;
|
|
16362
|
+
const error = this.result.error.toJsonObject();
|
|
16363
|
+
return {
|
|
16364
|
+
...json,
|
|
16365
|
+
result: {
|
|
16366
|
+
...json.result,
|
|
16367
|
+
error
|
|
16368
|
+
},
|
|
16369
|
+
outputHash: hashPayloadData(error.message)
|
|
16370
|
+
};
|
|
16371
|
+
}
|
|
16372
|
+
};
|
|
16373
|
+
/**
|
|
16374
|
+
* A server's policy for what a failed action tells its caller. A function and not a runtime
|
|
16375
|
+
* method, so that a client bundle does not carry it.
|
|
16376
|
+
*/
|
|
16377
|
+
function createFailureSealer(options) {
|
|
16378
|
+
const sealing = options.sealFailures ?? "undeclared";
|
|
16379
|
+
const warned = /* @__PURE__ */ new Set();
|
|
16380
|
+
const mustSeal = (error, declared) => {
|
|
16381
|
+
if (error.isUnhandled) return true;
|
|
16382
|
+
if (sealing === "unhandled" || declared) return false;
|
|
16383
|
+
return !isOwn(error, "action_input_validation_failed");
|
|
16384
|
+
};
|
|
16385
|
+
return { seal(result) {
|
|
16386
|
+
if (result.result.ok) return {
|
|
16387
|
+
sent: result,
|
|
16388
|
+
sealed: false
|
|
16389
|
+
};
|
|
16390
|
+
const error = result.result.error;
|
|
16391
|
+
if (sealing === "off") return {
|
|
16392
|
+
sent: new WholeFailureResult({ context: result.context }, {
|
|
16393
|
+
ok: false,
|
|
16394
|
+
error
|
|
16395
|
+
}, { time: result.time }),
|
|
16396
|
+
sealed: false
|
|
16397
|
+
};
|
|
16398
|
+
if (!mustSeal(error, result.result.expected)) return {
|
|
16399
|
+
sent: result,
|
|
16400
|
+
sealed: false
|
|
16401
|
+
};
|
|
16402
|
+
const action = `${result.domain}/${result.id}`;
|
|
16403
|
+
if (!error.isUnhandled && !isOwn(error, "action_output_validation_failed")) {
|
|
16404
|
+
const thrown = serveResultErrorInfo(error).id;
|
|
16405
|
+
if (!warned.has(`${action} ${thrown}`)) {
|
|
16406
|
+
warned.add(`${action} ${thrown}`);
|
|
16407
|
+
console.warn(`[nice-action] ${action} failed with ${thrown}, which the action does not declare, so its caller was sent the sealed failure. Declare it with .throws() to send it whole.`);
|
|
16408
|
+
}
|
|
16409
|
+
}
|
|
16410
|
+
if (!options.hasLogger) console.error(`[nice-action] ${action} failed, and its caller was sent the sealed failure (cuid ${result.context.cuid})`, thrownForLog(error));
|
|
16411
|
+
return {
|
|
16412
|
+
sent: new ActionPayload_Result({ context: result.context }, {
|
|
16413
|
+
ok: false,
|
|
16414
|
+
error: sealedFailure()
|
|
16415
|
+
}, { time: result.time }),
|
|
16416
|
+
sealed: true
|
|
16417
|
+
};
|
|
16418
|
+
} };
|
|
16419
|
+
}
|
|
16420
|
+
//#endregion
|
|
16421
|
+
//#region ../nice-action/src/utils/requestWireProblem.ts
|
|
16422
|
+
const CONTEXT_PROBLEM_SENTENCES = {
|
|
16423
|
+
missing: "Action wire has no \"context\": it needs at least { \"routing\": [] }.",
|
|
16424
|
+
routing: "Action wire \"context.routing\" must be an array ([] when written by hand).",
|
|
16425
|
+
route_item: "Action wire \"context.routing\" holds an entry with no \"runtime\".",
|
|
16426
|
+
cuid: "Action wire \"context.cuid\" must be a string.",
|
|
16427
|
+
origin_client: "Action wire \"context.originClient\" must be a runtime coordinate."
|
|
16428
|
+
};
|
|
16429
|
+
/** Why `wire` fails `isActionPayload_Request_JsonObject`, as a sentence for whoever sent it. */
|
|
16430
|
+
function requestWireProblem(wire) {
|
|
16431
|
+
const notActionData = () => err_nice_action.fromId("wire_not_action_data").message;
|
|
16432
|
+
if (!isAction_Base_JsonObject(wire) || wire.form !== "data" || !("type" in wire)) return notActionData();
|
|
16433
|
+
if (wire.type !== "request") return `An action endpoint takes a "request" wire, got "${String(wire.type)}".`;
|
|
16434
|
+
const problem = actionPayloadContextProblem("context" in wire ? wire.context : void 0);
|
|
16435
|
+
return problem != null ? CONTEXT_PROBLEM_SENTENCES[problem] : notActionData();
|
|
16436
|
+
}
|
|
16437
|
+
//#endregion
|
|
16438
|
+
//#region ../nice-action/src/ActionRuntime/actionRequestRefusal.ts
|
|
16439
|
+
function isNotServedRefusal(refusal) {
|
|
16440
|
+
return refusal.reason !== "malformed";
|
|
16441
|
+
}
|
|
16442
|
+
/**
|
|
16443
|
+
* A refusal as an `err` envelope's fields, and as a raw `404`'s: only a route this side does not
|
|
16444
|
+
* serve is given the id a client branches on.
|
|
16445
|
+
*/
|
|
16446
|
+
function refusalReplyFields(refusal) {
|
|
16447
|
+
return isNotServedRefusal(refusal) ? {
|
|
16448
|
+
message: refusal.message,
|
|
16449
|
+
id: "action_not_served",
|
|
16450
|
+
reason: refusal.reason
|
|
16451
|
+
} : { message: refusal.message };
|
|
16452
|
+
}
|
|
16453
|
+
/**
|
|
16454
|
+
* A request written by hand may send no `cuid`. It is given one at the door, so the log, the
|
|
16455
|
+
* handler and the reply all name the same request.
|
|
16456
|
+
*/
|
|
16457
|
+
function ensureRequestCuid(wire) {
|
|
16458
|
+
if (wire.context.cuid == null) wire.context.cuid = nanoid();
|
|
16459
|
+
}
|
|
16460
|
+
/** The refusal for a wire that is not a request this side can hydrate. */
|
|
16461
|
+
function refuseMalformedRequestWire(wire) {
|
|
16462
|
+
return {
|
|
16463
|
+
reason: "malformed",
|
|
16464
|
+
message: requestWireProblem(wire)
|
|
16465
|
+
};
|
|
16466
|
+
}
|
|
16467
|
+
/** The refusal for a request wire whose hydration threw. */
|
|
16468
|
+
function refuseUnhydratedRequestWire(thrown) {
|
|
16469
|
+
if (!err_nice_action.isExact(thrown)) return {
|
|
16470
|
+
reason: "malformed",
|
|
16471
|
+
message: "The request wire could not be read.",
|
|
16472
|
+
error: castNiceError(thrown)
|
|
16473
|
+
};
|
|
16474
|
+
return {
|
|
16475
|
+
reason: thrown.hasId("domain_no_handler") ? "unknown_domain" : thrown.hasId("hydration_action_id_not_found") ? "unknown_action" : "malformed",
|
|
16476
|
+
message: thrown.message,
|
|
16477
|
+
error: thrown
|
|
16478
|
+
};
|
|
16479
|
+
}
|
|
16480
|
+
/**
|
|
16481
|
+
* The refusal for a request whose domain or action this runtime does not have, found without
|
|
16482
|
+
* hydrating it. `undefined` when the route is served.
|
|
16483
|
+
*/
|
|
16484
|
+
function refuseUnservedRoute(runtime, wire) {
|
|
16485
|
+
const domain = runtime._domainForWire(wire);
|
|
16486
|
+
const error = domain == null ? err_nice_action.fromId("domain_no_handler", { domain: wire.domain }) : domain.actionSchema[wire.id] == null ? err_nice_action.fromId("hydration_action_id_not_found", {
|
|
16487
|
+
domain: wire.domain,
|
|
16488
|
+
actionId: wire.id
|
|
16489
|
+
}) : void 0;
|
|
16490
|
+
if (error == null) return void 0;
|
|
16491
|
+
return {
|
|
16492
|
+
reason: domain == null ? "unknown_domain" : "unknown_action",
|
|
16493
|
+
message: error.message,
|
|
16494
|
+
error
|
|
16495
|
+
};
|
|
16496
|
+
}
|
|
16497
|
+
/**
|
|
16498
|
+
* The failed result that answers a request this side does not serve, where a result is the only
|
|
16499
|
+
* reply the carrier has. Built as a wire: a request for an unknown route cannot be hydrated.
|
|
16500
|
+
*/
|
|
16501
|
+
function notServedResultWire(wire, refusal) {
|
|
16502
|
+
const { input: _input, inputHash: _inputHash, ...route } = wire;
|
|
16503
|
+
return {
|
|
16504
|
+
...route,
|
|
16505
|
+
type: "result",
|
|
16506
|
+
time: Date.now(),
|
|
16507
|
+
result: {
|
|
16508
|
+
ok: false,
|
|
16509
|
+
expected: false,
|
|
16510
|
+
error: err_nice_transport.fromId("action_not_served", {
|
|
16511
|
+
domain: wire.domain,
|
|
16512
|
+
actionId: wire.id,
|
|
16513
|
+
reason: refusal.reason
|
|
16514
|
+
}).toJsonObject()
|
|
16515
|
+
},
|
|
16516
|
+
outputHash: ""
|
|
16517
|
+
};
|
|
16518
|
+
}
|
|
16519
|
+
/**
|
|
16520
|
+
* The request/reply door: hydrate a request wire and dispatch it, or say why it was turned away.
|
|
16521
|
+
* A wire the runtime cannot serve is a refusal, never a rejection. A function and not a runtime
|
|
16522
|
+
* method, so that a client bundle does not carry it.
|
|
16523
|
+
*/
|
|
16524
|
+
async function admitRequestWire(runtime, wire, metadata) {
|
|
16525
|
+
let request;
|
|
16526
|
+
try {
|
|
16527
|
+
request = runtime._hydrateWireFromReceiver(wire, metadata);
|
|
16528
|
+
} catch (thrown) {
|
|
16529
|
+
return {
|
|
16530
|
+
admitted: false,
|
|
16531
|
+
refusal: refuseUnhydratedRequestWire(thrown)
|
|
16532
|
+
};
|
|
16533
|
+
}
|
|
16534
|
+
return {
|
|
16535
|
+
admitted: true,
|
|
16536
|
+
running: await runtime.handleActionPayload(request)
|
|
16537
|
+
};
|
|
16538
|
+
}
|
|
16539
|
+
/** A refused request's outcome, as the line a serve logger's reporter takes. */
|
|
16540
|
+
function refusalResultInfo(refusal, served) {
|
|
16541
|
+
return {
|
|
16542
|
+
ok: false,
|
|
16543
|
+
...served,
|
|
16544
|
+
error: refusal.error != null ? serveResultErrorInfo(refusal.error) : { message: refusal.message }
|
|
16545
|
+
};
|
|
16546
|
+
}
|
|
16547
|
+
//#endregion
|
|
16106
16548
|
//#region ../nice-action/src/ActionRuntime/Handler/PeerLink/Acceptor/ChannelAcceptor.ts
|
|
16107
16549
|
/** Validate + read a rehydrated binding's opaque lane slot back into the lane's shape. */
|
|
16108
16550
|
function readLaneBindingState(lane) {
|
|
@@ -16170,6 +16612,7 @@ var ChannelAcceptor = class extends PeerLink {
|
|
|
16170
16612
|
_maxKeyedStreams;
|
|
16171
16613
|
_resyncRequested = /* @__PURE__ */ new Set();
|
|
16172
16614
|
_logger;
|
|
16615
|
+
_sealer;
|
|
16173
16616
|
_transportLabel;
|
|
16174
16617
|
_pendingReports = /* @__PURE__ */ new Map();
|
|
16175
16618
|
constructor(options) {
|
|
@@ -16180,6 +16623,10 @@ var ChannelAcceptor = class extends PeerLink {
|
|
|
16180
16623
|
this._runtime = options.runtime;
|
|
16181
16624
|
this._serverTimeout = options.defaultTimeout ?? 1e4;
|
|
16182
16625
|
this._logger = options.logger;
|
|
16626
|
+
this._sealer = createFailureSealer({
|
|
16627
|
+
sealFailures: options.sealFailures,
|
|
16628
|
+
hasLogger: options.logger != null
|
|
16629
|
+
});
|
|
16183
16630
|
this._transportLabel = options.transportLabel ?? "ws";
|
|
16184
16631
|
this._persistedReceiver = options.persistedReceiver;
|
|
16185
16632
|
this._maxKeyedStreams = options.maxKeyedStreamsPerClient ?? 256;
|
|
@@ -16270,25 +16717,21 @@ var ChannelAcceptor = class extends PeerLink {
|
|
|
16270
16717
|
});
|
|
16271
16718
|
}
|
|
16272
16719
|
/** Report a served result back to the reporter stashed by {@link _logRequestIn} (no-op if none/not a result). */
|
|
16273
|
-
_reportServed(payload, bytes) {
|
|
16720
|
+
_reportServed(payload, sealed, bytes) {
|
|
16274
16721
|
if (payload.type !== "result") return;
|
|
16275
16722
|
const entry = this._pendingReports.get(payload.context.cuid);
|
|
16276
16723
|
if (entry == null) return;
|
|
16277
16724
|
this._pendingReports.delete(payload.context.cuid);
|
|
16278
|
-
const
|
|
16725
|
+
const served = {
|
|
16726
|
+
returnedVia: this._transportLabel,
|
|
16727
|
+
durationMs: Date.now() - entry.startedAt,
|
|
16728
|
+
bytes
|
|
16729
|
+
};
|
|
16279
16730
|
const outcome = payload.result;
|
|
16280
16731
|
entry.report(outcome.ok ? {
|
|
16281
16732
|
ok: true,
|
|
16282
|
-
|
|
16283
|
-
|
|
16284
|
-
bytes
|
|
16285
|
-
} : {
|
|
16286
|
-
ok: false,
|
|
16287
|
-
returnedVia: this._transportLabel,
|
|
16288
|
-
durationMs,
|
|
16289
|
-
bytes,
|
|
16290
|
-
error: serveResultErrorInfo(outcome.error)
|
|
16291
|
-
});
|
|
16733
|
+
...served
|
|
16734
|
+
} : failedResultInfo(outcome.error, sealed, served));
|
|
16292
16735
|
}
|
|
16293
16736
|
/**
|
|
16294
16737
|
* The codec for a connection: a per-connection session (cached) when a factory was provided, else
|
|
@@ -16352,6 +16795,7 @@ var ChannelAcceptor = class extends PeerLink {
|
|
|
16352
16795
|
const codec = this._codecFor(connection);
|
|
16353
16796
|
const wire = decodeActionFrame(frame, codec);
|
|
16354
16797
|
if (wire == null) return;
|
|
16798
|
+
if (wire.type === "request") ensureRequestCuid(wire);
|
|
16355
16799
|
if (level === "none") {
|
|
16356
16800
|
const encoding = typeof frame === "string" ? "json" : "binary";
|
|
16357
16801
|
this._connEncoding.set(connection, encoding);
|
|
@@ -16477,6 +16921,7 @@ var ChannelAcceptor = class extends PeerLink {
|
|
|
16477
16921
|
_emitIncomingFromReceiver(wire, reliability, arrivalOverride) {
|
|
16478
16922
|
const arrival = arrivalOverride ?? this._receiverMetadataByWire.get(wire);
|
|
16479
16923
|
this._receiverMetadataByWire.delete(wire);
|
|
16924
|
+
if (wire.type === "request" && this._refuseUnserved(wire, arrival, reliability)) return;
|
|
16480
16925
|
const securityLevel = arrival?.securityLevel;
|
|
16481
16926
|
this._emitIncoming(wire, {
|
|
16482
16927
|
receiver: this,
|
|
@@ -16488,6 +16933,53 @@ var ChannelAcceptor = class extends PeerLink {
|
|
|
16488
16933
|
});
|
|
16489
16934
|
}
|
|
16490
16935
|
/**
|
|
16936
|
+
* Answer a request for a domain or action the runtime does not have with a failed result. Nothing
|
|
16937
|
+
* past this point can: such a request cannot be hydrated, so its caller would wait out its
|
|
16938
|
+
* timeout. A refused reliable frame has been through the inbox, and its ack rides the answer.
|
|
16939
|
+
*/
|
|
16940
|
+
_refuseUnserved(wire, arrival, reliability) {
|
|
16941
|
+
const runtime = this._incomingRuntime;
|
|
16942
|
+
const refusal = runtime == null ? void 0 : refuseUnservedRoute(runtime, wire);
|
|
16943
|
+
const connection = arrival == null ? void 0 : this._liveArrivalConnection(arrival);
|
|
16944
|
+
if (refusal == null || connection == null) return false;
|
|
16945
|
+
const answer = notServedResultWire(wire, refusal);
|
|
16946
|
+
let frame;
|
|
16947
|
+
if (this._connEncoding.get(connection) === "json") frame = JSON.stringify(answer);
|
|
16948
|
+
else {
|
|
16949
|
+
const client = this.wireAcceptor.clientForConnection(connection);
|
|
16950
|
+
frame = this._codecFor(connection).outgoingWire?.(answer, reliability == null || client == null ? void 0 : this._replyAck(client, wire.domain, wire.id, reliability.streamKey));
|
|
16951
|
+
}
|
|
16952
|
+
if (frame == null) return false;
|
|
16953
|
+
this.wireAcceptor.sendTo(connection, frame);
|
|
16954
|
+
const pending = this._pendingReports.get(wire.context.cuid);
|
|
16955
|
+
if (pending != null) {
|
|
16956
|
+
this._pendingReports.delete(wire.context.cuid);
|
|
16957
|
+
pending.report({
|
|
16958
|
+
...refusalResultInfo(refusal, {
|
|
16959
|
+
returnedVia: this._transportLabel,
|
|
16960
|
+
durationMs: Date.now() - pending.startedAt
|
|
16961
|
+
}),
|
|
16962
|
+
bytes: wireFrameByteSize(frame)
|
|
16963
|
+
});
|
|
16964
|
+
}
|
|
16965
|
+
return true;
|
|
16966
|
+
}
|
|
16967
|
+
/** The cumulative ack a reply on this stream carries, when the stream is a reliable one. */
|
|
16968
|
+
_replyAck(client, domain, id, streamKey) {
|
|
16969
|
+
const streamId = reliableStreamId(client, domain, id, streamKey);
|
|
16970
|
+
const receiver = this._persistedReceiver?.hasStream(streamId) ? this._persistedReceiver : this._inbox.hasStream(streamId) ? this._inbox : void 0;
|
|
16971
|
+
if (receiver == null) return void 0;
|
|
16972
|
+
const ack = receiver.contiguousSeq(streamId);
|
|
16973
|
+
return streamKey == null ? {
|
|
16974
|
+
streamId,
|
|
16975
|
+
ack
|
|
16976
|
+
} : {
|
|
16977
|
+
streamId,
|
|
16978
|
+
ack,
|
|
16979
|
+
streamKey
|
|
16980
|
+
};
|
|
16981
|
+
}
|
|
16982
|
+
/**
|
|
16491
16983
|
* Log + emit each frame the receiver decided to deliver in this receive. Only the **first** (the frame
|
|
16492
16984
|
* actually received this call) carries the reliability facts for the *logger*; drained buffered frames
|
|
16493
16985
|
* were logged/seq'd on their own earlier arrivals, so they log without a (stale) seq. Every delivered
|
|
@@ -16755,8 +17247,12 @@ var ChannelAcceptor = class extends PeerLink {
|
|
|
16755
17247
|
const arrival = config.arrival ?? payload.context._getReceiverMetadata();
|
|
16756
17248
|
const connection = arrival == null ? this.wireAcceptor.connectionForClient(payload.context.originClient.stringId) : arrival.receiver === this ? this._liveArrivalConnection(arrival) : void 0;
|
|
16757
17249
|
if (connection == null) return false;
|
|
16758
|
-
const
|
|
16759
|
-
|
|
17250
|
+
const { sent, sealed } = payload.type === "result" ? this._sealer.seal(payload) : {
|
|
17251
|
+
sent: payload,
|
|
17252
|
+
sealed: false
|
|
17253
|
+
};
|
|
17254
|
+
const bytes = this._sendPayload(connection, sent, config.targetLocalRuntime.coordinate, arrival?.reliability);
|
|
17255
|
+
this._reportServed(payload, sealed, bytes);
|
|
16760
17256
|
return true;
|
|
16761
17257
|
}
|
|
16762
17258
|
async handleActionRequest(action, config) {
|
|
@@ -16814,23 +17310,7 @@ var ChannelAcceptor = class extends PeerLink {
|
|
|
16814
17310
|
/** Encode + send one payload; returns the encoded frame's size so a logger can report it. */
|
|
16815
17311
|
_sendPayload(connection, payload, localClient, answered) {
|
|
16816
17312
|
const encoding = this._connEncoding.get(connection) ?? "binary";
|
|
16817
|
-
|
|
16818
|
-
if (payload.type === "result") {
|
|
16819
|
-
const streamKey = (answered ?? payload.context.reliability)?.streamKey;
|
|
16820
|
-
const streamId = reliableStreamId(payload.context.originClient, payload.domain, payload.id, streamKey);
|
|
16821
|
-
const receiver = this._persistedReceiver?.hasStream(streamId) ? this._persistedReceiver : this._inbox.hasStream(streamId) ? this._inbox : void 0;
|
|
16822
|
-
if (receiver != null) {
|
|
16823
|
-
const ack = receiver.contiguousSeq(streamId);
|
|
16824
|
-
rel = streamKey == null ? {
|
|
16825
|
-
streamId,
|
|
16826
|
-
ack
|
|
16827
|
-
} : {
|
|
16828
|
-
streamId,
|
|
16829
|
-
ack,
|
|
16830
|
-
streamKey
|
|
16831
|
-
};
|
|
16832
|
-
}
|
|
16833
|
-
}
|
|
17313
|
+
const rel = payload.type === "result" ? this._replyAck(payload.context.originClient, payload.domain, payload.id, (answered ?? payload.context.reliability)?.streamKey) : void 0;
|
|
16834
17314
|
const frame = encoding === "json" ? JSON.stringify(payload.toJsonObject()) : this._codecFor(connection).outgoing({
|
|
16835
17315
|
action: payload,
|
|
16836
17316
|
localClient,
|
|
@@ -16895,6 +17375,7 @@ function createSecureChannelAcceptor(options) {
|
|
|
16895
17375
|
runtime: options.runtime,
|
|
16896
17376
|
defaultTimeout: options.defaultTimeout,
|
|
16897
17377
|
logger: options.logger,
|
|
17378
|
+
sealFailures: options.sealFailures,
|
|
16898
17379
|
wireTap: options.wireTap,
|
|
16899
17380
|
transportLabel: options.transportLabel,
|
|
16900
17381
|
persistedReceiver: options.persistedReceiver,
|
|
@@ -17120,44 +17601,45 @@ function createBinaryWireSessionFactory(domains, options) {
|
|
|
17120
17601
|
const cuidToCorr = /* @__PURE__ */ new Map();
|
|
17121
17602
|
let selfIdentity;
|
|
17122
17603
|
let peerIdentity;
|
|
17123
|
-
|
|
17124
|
-
|
|
17125
|
-
|
|
17126
|
-
|
|
17127
|
-
|
|
17128
|
-
|
|
17129
|
-
|
|
17130
|
-
|
|
17131
|
-
|
|
17132
|
-
|
|
17133
|
-
|
|
17134
|
-
|
|
17135
|
-
|
|
17136
|
-
|
|
17137
|
-
|
|
17138
|
-
|
|
17139
|
-
|
|
17140
|
-
|
|
17141
|
-
selfIdentity = json.context.originClient;
|
|
17142
|
-
wireIdentity = json.context.originClient;
|
|
17143
|
-
}
|
|
17144
|
-
} else {
|
|
17145
|
-
corr = cuidToCorr.get(json.context.cuid)?.value ?? -1;
|
|
17146
|
-
if (json.type === "result") cuidToCorr.delete(json.context.cuid);
|
|
17604
|
+
const packWire = (json, reliability) => {
|
|
17605
|
+
const routeKey = `${json.domain}:${json.id}`;
|
|
17606
|
+
const routeInt = routeToInt.get(routeKey);
|
|
17607
|
+
if (routeInt == null) throw new Error(`[binary-wire] Cannot pack unregistered action route: ${routeKey}`);
|
|
17608
|
+
const now = Date.now();
|
|
17609
|
+
pruneExpired(corrToCuid, now, ttlMs);
|
|
17610
|
+
pruneExpired(cuidToCorr, now, ttlMs);
|
|
17611
|
+
let corr;
|
|
17612
|
+
let wireIdentity;
|
|
17613
|
+
if (json.type === "request") {
|
|
17614
|
+
corr = outCounter++;
|
|
17615
|
+
corrToCuid.set(corr, {
|
|
17616
|
+
value: json.context.cuid,
|
|
17617
|
+
time: now
|
|
17618
|
+
});
|
|
17619
|
+
if (selfIdentity == null && isKnownIdentity(json.context.originClient)) {
|
|
17620
|
+
selfIdentity = json.context.originClient;
|
|
17621
|
+
wireIdentity = json.context.originClient;
|
|
17147
17622
|
}
|
|
17148
|
-
|
|
17149
|
-
|
|
17150
|
-
|
|
17151
|
-
|
|
17152
|
-
|
|
17153
|
-
|
|
17154
|
-
|
|
17155
|
-
|
|
17156
|
-
|
|
17157
|
-
|
|
17158
|
-
|
|
17159
|
-
|
|
17160
|
-
|
|
17623
|
+
} else {
|
|
17624
|
+
corr = cuidToCorr.get(json.context.cuid)?.value ?? -1;
|
|
17625
|
+
if (json.type === "result") cuidToCorr.delete(json.context.cuid);
|
|
17626
|
+
}
|
|
17627
|
+
const reliabilitySlot = encodeReliabilitySlot(reliability, json.type);
|
|
17628
|
+
const streamKey = reliability?.streamKey;
|
|
17629
|
+
const envelope = new Array(streamKey != null ? ENVELOPE_LENGTH_RELIABLE_KEYED : reliabilitySlot == null ? ENVELOPE_LENGTH : ENVELOPE_LENGTH_RELIABLE);
|
|
17630
|
+
envelope[ENVELOPE.route] = routeInt;
|
|
17631
|
+
envelope[ENVELOPE.type] = PayloadTypeToInt[json.type];
|
|
17632
|
+
envelope[ENVELOPE.corr] = corr;
|
|
17633
|
+
envelope[ENVELOPE.time] = json.time;
|
|
17634
|
+
envelope[ENVELOPE.originClient] = wireIdentity;
|
|
17635
|
+
envelope[ENVELOPE.payload] = extractWirePayload(json);
|
|
17636
|
+
if (reliabilitySlot != null) envelope[ENVELOPE.reliability] = reliabilitySlot;
|
|
17637
|
+
if (streamKey != null) envelope[ENVELOPE.streamKey] = streamKey;
|
|
17638
|
+
return pack(envelope);
|
|
17639
|
+
};
|
|
17640
|
+
return {
|
|
17641
|
+
outgoing: (input) => packWire(input.action.toJsonObject(), input.reliability),
|
|
17642
|
+
outgoingWire: packWire,
|
|
17161
17643
|
incoming: (frame) => {
|
|
17162
17644
|
let buffer;
|
|
17163
17645
|
if (frame instanceof ArrayBuffer) buffer = new Uint8Array(frame);
|
|
@@ -17290,11 +17772,18 @@ async function runExchange(session, inputs) {
|
|
|
17290
17772
|
return;
|
|
17291
17773
|
}
|
|
17292
17774
|
const outcome = await session.exchange(action.toJsonObject(), { signal: ac.signal });
|
|
17293
|
-
if (!outcome.ok && outcome.reason === "peer_error")
|
|
17294
|
-
|
|
17295
|
-
|
|
17296
|
-
|
|
17297
|
-
|
|
17775
|
+
if (!outcome.ok && outcome.reason === "peer_error") {
|
|
17776
|
+
if (outcome.id === "action_not_served") throw err_nice_transport.fromId("action_not_served", {
|
|
17777
|
+
domain: action.domain,
|
|
17778
|
+
actionId: action.id,
|
|
17779
|
+
reason: outcome.peerReason === "unknown_domain" ? "unknown_domain" : "unknown_action"
|
|
17780
|
+
});
|
|
17781
|
+
throw err_nice_transport.fromId("send_failed", {
|
|
17782
|
+
actionState: action.type,
|
|
17783
|
+
actionId: action.id,
|
|
17784
|
+
message: outcome.message
|
|
17785
|
+
});
|
|
17786
|
+
}
|
|
17298
17787
|
if (!outcome.ok || !isActionPayload_Result_JsonObject(outcome.wire)) throw err_nice_transport.fromId("invalid_action_response", { actionId: action.id });
|
|
17299
17788
|
runningAction._completeWithResult(action._domain.hydrateResultPayload(outcome.wire));
|
|
17300
17789
|
} catch (err) {
|
|
@@ -17929,9 +18418,14 @@ var ExchangeAcceptor = class {
|
|
|
17929
18418
|
_runtime;
|
|
17930
18419
|
_logger;
|
|
17931
18420
|
_transportLabel;
|
|
18421
|
+
_sealer;
|
|
17932
18422
|
constructor(config) {
|
|
17933
18423
|
this._runtime = config.runtime;
|
|
17934
18424
|
this._logger = config.logger;
|
|
18425
|
+
this._sealer = createFailureSealer({
|
|
18426
|
+
sealFailures: config.sealFailures,
|
|
18427
|
+
hasLogger: config.logger != null
|
|
18428
|
+
});
|
|
17935
18429
|
this._transportLabel = config.transportLabel ?? "http";
|
|
17936
18430
|
this._core = new WireExchangeAcceptor({
|
|
17937
18431
|
security: {
|
|
@@ -17953,46 +18447,82 @@ var ExchangeAcceptor = class {
|
|
|
17953
18447
|
}
|
|
17954
18448
|
/** Serve one opened `act` wire: validate → bind identity → log → run → return the result wire. */
|
|
17955
18449
|
async _onExchange(request) {
|
|
17956
|
-
if (!
|
|
18450
|
+
if (!isActionPayload_Request_JsonObject(request.wire)) return {
|
|
17957
18451
|
ok: false,
|
|
17958
|
-
message:
|
|
18452
|
+
message: refuseMalformedRequestWire(request.wire).message
|
|
17959
18453
|
};
|
|
17960
18454
|
const wire = request.wire;
|
|
17961
18455
|
const client = request.client;
|
|
17962
|
-
if (client != null
|
|
17963
|
-
|
|
18456
|
+
if (client != null) wire.context.originClient = client.toJsonObject();
|
|
18457
|
+
ensureRequestCuid(wire);
|
|
18458
|
+
const report = this._logger?.onRequest(actionServeRequestInfo(wire, {
|
|
17964
18459
|
transport: this._transportLabel,
|
|
17965
18460
|
securityLevel: request.securityLevel,
|
|
17966
18461
|
origin: client?.stringId
|
|
17967
|
-
}))
|
|
18462
|
+
}));
|
|
17968
18463
|
const startedAt = Date.now();
|
|
17969
|
-
const
|
|
18464
|
+
const returnedVia = request.encrypted ? `${this._transportLabel} (encrypted)` : this._transportLabel;
|
|
18465
|
+
const admission = await admitRequestWire(this._runtime, wire, {
|
|
17970
18466
|
receiver: this,
|
|
17971
18467
|
securityLevel: request.securityLevel,
|
|
17972
18468
|
originAuthenticated: client != null && request.securityLevel !== "none"
|
|
17973
|
-
})
|
|
17974
|
-
|
|
17975
|
-
|
|
17976
|
-
const returnedVia = request.encrypted ? `${this._transportLabel} (encrypted)` : this._transportLabel;
|
|
17977
|
-
report(result.result.ok ? {
|
|
17978
|
-
ok: true,
|
|
18469
|
+
});
|
|
18470
|
+
if (!admission.admitted) {
|
|
18471
|
+
report?.(refusalResultInfo(admission.refusal, {
|
|
17979
18472
|
returnedVia,
|
|
17980
18473
|
durationMs: Date.now() - startedAt
|
|
17981
|
-
}
|
|
18474
|
+
}));
|
|
18475
|
+
return {
|
|
17982
18476
|
ok: false,
|
|
17983
|
-
|
|
17984
|
-
|
|
17985
|
-
error: serveResultErrorInfo(result.result.error)
|
|
17986
|
-
});
|
|
18477
|
+
...refusalReplyFields(admission.refusal)
|
|
18478
|
+
};
|
|
17987
18479
|
}
|
|
18480
|
+
const result = await admission.running.waitForResultPayload();
|
|
18481
|
+
const { sent, sealed } = this._sealer.seal(result);
|
|
18482
|
+
const served = {
|
|
18483
|
+
returnedVia,
|
|
18484
|
+
durationMs: Date.now() - startedAt
|
|
18485
|
+
};
|
|
18486
|
+
report?.(result.result.ok ? {
|
|
18487
|
+
ok: true,
|
|
18488
|
+
...served
|
|
18489
|
+
} : failedResultInfo(result.result.error, sealed, served));
|
|
17988
18490
|
return {
|
|
17989
18491
|
ok: true,
|
|
17990
|
-
wire:
|
|
18492
|
+
wire: sent.toJsonObject()
|
|
17991
18493
|
};
|
|
17992
18494
|
}
|
|
17993
18495
|
};
|
|
17994
18496
|
//#endregion
|
|
17995
|
-
//#region ../nice-action/src/ActionRuntime/Handler/PeerLink/Acceptor/
|
|
18497
|
+
//#region ../nice-action/src/ActionRuntime/Handler/PeerLink/Acceptor/readBodyWithin.ts
|
|
18498
|
+
/**
|
|
18499
|
+
* A request's body as text, or `undefined` once it is over `maxBytes`. The declared length is
|
|
18500
|
+
* checked first, so an honest oversized body is never read; the read is then capped, since a
|
|
18501
|
+
* chunked body declares no length and a declared one can be understated.
|
|
18502
|
+
*/
|
|
18503
|
+
async function readBodyWithin(request, maxBytes) {
|
|
18504
|
+
if (Number(request.headers.get("Content-Length")) > maxBytes) return void 0;
|
|
18505
|
+
if (request.body == null) return "";
|
|
18506
|
+
const reader = request.body.getReader();
|
|
18507
|
+
const decoder = new TextDecoder();
|
|
18508
|
+
let text = "";
|
|
18509
|
+
let received = 0;
|
|
18510
|
+
for (;;) {
|
|
18511
|
+
const { done, value } = await reader.read();
|
|
18512
|
+
if (done) break;
|
|
18513
|
+
received += value.byteLength;
|
|
18514
|
+
if (received > maxBytes) {
|
|
18515
|
+
await reader.cancel();
|
|
18516
|
+
return;
|
|
18517
|
+
}
|
|
18518
|
+
text += decoder.decode(value, { stream: true });
|
|
18519
|
+
}
|
|
18520
|
+
return text + decoder.decode();
|
|
18521
|
+
}
|
|
18522
|
+
function isJsonContentType(request) {
|
|
18523
|
+
const contentType = request.headers.get("Content-Type");
|
|
18524
|
+
return contentType != null && contentType.split(";", 1)[0].trim().toLowerCase() === "application/json";
|
|
18525
|
+
}
|
|
17996
18526
|
/** Permissive defaults — fine for a public action endpoint; override (or disable) via `cors`. */
|
|
17997
18527
|
const DEFAULT_CORS_HEADERS = {
|
|
17998
18528
|
"Access-Control-Allow-Origin": "*",
|
|
@@ -18024,12 +18554,20 @@ function createActionFetchHandler(runtime, options = {}) {
|
|
|
18024
18554
|
const isActionPath = options.isActionPath ?? ((url) => url.pathname.endsWith("/action"));
|
|
18025
18555
|
const isWebSocketPath = options.isWebSocketPath ?? ((url) => url.pathname.endsWith("/ws"));
|
|
18026
18556
|
const transportLabel = options.transportLabel ?? "http";
|
|
18557
|
+
const requireJsonContentType = options.requireJsonContentType ?? true;
|
|
18558
|
+
const maxBodyBytes = options.maxBodyBytes ?? 1048576;
|
|
18559
|
+
if (!(maxBodyBytes > 0)) throw new Error("maxBodyBytes must be a positive number of bytes, or Infinity for no limit");
|
|
18027
18560
|
const exchangeAcceptor = options.security != null ? new ExchangeAcceptor({
|
|
18028
18561
|
runtime,
|
|
18029
18562
|
security: options.security,
|
|
18030
18563
|
logger: options.logger,
|
|
18031
|
-
transportLabel
|
|
18564
|
+
transportLabel,
|
|
18565
|
+
sealFailures: options.sealFailures
|
|
18032
18566
|
}) : void 0;
|
|
18567
|
+
const sealer = createFailureSealer({
|
|
18568
|
+
sealFailures: options.sealFailures,
|
|
18569
|
+
hasLogger: options.logger != null
|
|
18570
|
+
});
|
|
18033
18571
|
const withCors = (response) => {
|
|
18034
18572
|
if (options.cors === false) return response;
|
|
18035
18573
|
const headers = new Headers(response.headers);
|
|
@@ -18039,8 +18577,8 @@ function createActionFetchHandler(runtime, options = {}) {
|
|
|
18039
18577
|
headers
|
|
18040
18578
|
});
|
|
18041
18579
|
};
|
|
18042
|
-
const
|
|
18043
|
-
status
|
|
18580
|
+
const errorResponse = (status, message) => new Response(JSON.stringify({ error: message }), {
|
|
18581
|
+
status,
|
|
18044
18582
|
headers: { "Content-Type": "application/json" }
|
|
18045
18583
|
});
|
|
18046
18584
|
const envelopeReply = (reply) => new Response(encodeExchange(reply), {
|
|
@@ -18052,19 +18590,23 @@ function createActionFetchHandler(runtime, options = {}) {
|
|
|
18052
18590
|
message
|
|
18053
18591
|
});
|
|
18054
18592
|
return async (request) => {
|
|
18593
|
+
const originRefusal = refuseUnlistedOrigin(request, options.allowedOrigins);
|
|
18594
|
+
if (originRefusal != null) return withCors(originRefusal);
|
|
18055
18595
|
if (request.method === "OPTIONS") return withCors(new Response(null, { status: 204 }));
|
|
18056
18596
|
const url = new URL(request.url);
|
|
18057
18597
|
const isWebSocketUpgrade = options.isWebSocketUpgrade ?? ((req, u) => req.headers.get("Upgrade") === "websocket" && isWebSocketPath(u));
|
|
18058
18598
|
if (options.onWebSocketUpgrade != null && isWebSocketUpgrade(request, url)) return options.onWebSocketUpgrade(request, url);
|
|
18059
18599
|
if (request.method === "POST" && isActionPath(url)) {
|
|
18600
|
+
if (requireJsonContentType && !isJsonContentType(request)) return withCors(errorResponse(415, "an action POST needs the header \"Content-Type: application/json\""));
|
|
18601
|
+
const text = await readBodyWithin(request, maxBodyBytes);
|
|
18602
|
+
if (text == null) return withCors(errorResponse(413, `request body is over this endpoint's limit of ${maxBodyBytes} bytes (maxBodyBytes)`));
|
|
18060
18603
|
if (exchangeAcceptor != null) {
|
|
18061
|
-
const reply = await exchangeAcceptor.handlePost(
|
|
18604
|
+
const reply = await exchangeAcceptor.handlePost(text);
|
|
18062
18605
|
return withCors(new Response(reply, {
|
|
18063
18606
|
status: 200,
|
|
18064
18607
|
headers: { "Content-Type": "application/json" }
|
|
18065
18608
|
}));
|
|
18066
18609
|
}
|
|
18067
|
-
const text = await request.text();
|
|
18068
18610
|
const envelope = decodeExchangeRequest(text);
|
|
18069
18611
|
if (envelope?.k === "hs") return withCors(envelopeError("plain endpoint: no handshake here — connect with `{ carrier: httpCarrier(...), secure: false }`"));
|
|
18070
18612
|
if (envelope != null && "c" in envelope) return withCors(envelopeError("plain endpoint: cannot open an encrypted frame"));
|
|
@@ -18073,45 +18615,53 @@ function createActionFetchHandler(runtime, options = {}) {
|
|
|
18073
18615
|
else try {
|
|
18074
18616
|
body = JSON.parse(text);
|
|
18075
18617
|
} catch {
|
|
18076
|
-
return withCors(
|
|
18618
|
+
return withCors(errorResponse(400, "request body is not valid JSON"));
|
|
18077
18619
|
}
|
|
18078
|
-
const
|
|
18079
|
-
|
|
18620
|
+
const refuse = (refusal) => {
|
|
18621
|
+
const { message, ...named } = refusalReplyFields(refusal);
|
|
18622
|
+
if (envelope != null) return withCors(envelopeReply({
|
|
18623
|
+
k: "err",
|
|
18624
|
+
message,
|
|
18625
|
+
...named
|
|
18626
|
+
}));
|
|
18627
|
+
return withCors(new Response(JSON.stringify({
|
|
18628
|
+
error: message,
|
|
18629
|
+
...named
|
|
18630
|
+
}), {
|
|
18631
|
+
status: refusal.reason === "malformed" ? 400 : 404,
|
|
18632
|
+
headers: { "Content-Type": "application/json" }
|
|
18633
|
+
}));
|
|
18634
|
+
};
|
|
18635
|
+
if (!isActionPayload_Request_JsonObject(body)) return refuse(refuseMalformedRequestWire(body));
|
|
18636
|
+
ensureRequestCuid(body);
|
|
18637
|
+
const report = options.logger?.onRequest(actionServeRequestInfo(body, { transport: transportLabel }));
|
|
18080
18638
|
const startedAt = Date.now();
|
|
18081
|
-
|
|
18082
|
-
|
|
18083
|
-
|
|
18084
|
-
|
|
18085
|
-
|
|
18086
|
-
|
|
18087
|
-
|
|
18088
|
-
|
|
18089
|
-
|
|
18090
|
-
|
|
18091
|
-
returnedVia: transportLabel,
|
|
18092
|
-
durationMs: Date.now() - startedAt,
|
|
18093
|
-
error: serveResultErrorInfo(error)
|
|
18094
|
-
});
|
|
18095
|
-
return withCors(answerError(error.message));
|
|
18096
|
-
}
|
|
18097
|
-
throw error;
|
|
18639
|
+
const admission = await admitRequestWire(runtime, body, {
|
|
18640
|
+
receiver: runtime,
|
|
18641
|
+
securityLevel: "none"
|
|
18642
|
+
});
|
|
18643
|
+
if (!admission.admitted) {
|
|
18644
|
+
report?.(refusalResultInfo(admission.refusal, {
|
|
18645
|
+
returnedVia: transportLabel,
|
|
18646
|
+
durationMs: Date.now() - startedAt
|
|
18647
|
+
}));
|
|
18648
|
+
return refuse(admission.refusal);
|
|
18098
18649
|
}
|
|
18099
|
-
const result = await running.waitForResultPayload();
|
|
18100
|
-
|
|
18101
|
-
|
|
18650
|
+
const result = await admission.running.waitForResultPayload();
|
|
18651
|
+
const { sent, sealed } = sealer.seal(result);
|
|
18652
|
+
const served = {
|
|
18102
18653
|
returnedVia: transportLabel,
|
|
18103
18654
|
durationMs: Date.now() - startedAt
|
|
18104
|
-
}
|
|
18105
|
-
|
|
18106
|
-
|
|
18107
|
-
|
|
18108
|
-
|
|
18109
|
-
});
|
|
18655
|
+
};
|
|
18656
|
+
report?.(result.result.ok ? {
|
|
18657
|
+
ok: true,
|
|
18658
|
+
...served
|
|
18659
|
+
} : failedResultInfo(result.result.error, sealed, served));
|
|
18110
18660
|
if (envelope != null) return withCors(envelopeReply({
|
|
18111
18661
|
k: "act",
|
|
18112
|
-
w:
|
|
18662
|
+
w: sent.toJsonObject()
|
|
18113
18663
|
}));
|
|
18114
|
-
return withCors(
|
|
18664
|
+
return withCors(sent.toHttpResponse({ useErrorStatus: options.useErrorStatus }));
|
|
18115
18665
|
}
|
|
18116
18666
|
return withCors(new Response("Not found", { status: 404 }));
|
|
18117
18667
|
};
|
|
@@ -18359,6 +18909,7 @@ function serveChannel(runtimeOrChannel, channelOrOptions, legacyOptions) {
|
|
|
18359
18909
|
defaultTimeout: options.defaultTimeout,
|
|
18360
18910
|
resolveChannel,
|
|
18361
18911
|
logger: options.logger,
|
|
18912
|
+
sealFailures: options.sealFailures,
|
|
18362
18913
|
wireTap: options.wireTap,
|
|
18363
18914
|
transportLabel: carrier.carrierLabel,
|
|
18364
18915
|
persistedReceiver: options.reliableStore,
|
|
@@ -18370,6 +18921,7 @@ function serveChannel(runtimeOrChannel, channelOrOptions, legacyOptions) {
|
|
|
18370
18921
|
runtime,
|
|
18371
18922
|
defaultTimeout: options.defaultTimeout,
|
|
18372
18923
|
logger: options.logger,
|
|
18924
|
+
sealFailures: options.sealFailures,
|
|
18373
18925
|
wireTap: options.wireTap,
|
|
18374
18926
|
transportLabel: carrier.carrierLabel,
|
|
18375
18927
|
persistedReceiver: options.reliableStore,
|
|
@@ -18480,6 +19032,9 @@ function serveChannel(runtimeOrChannel, channelOrOptions, legacyOptions) {
|
|
|
18480
19032
|
});
|
|
18481
19033
|
}
|
|
18482
19034
|
const activeFetch = createActionFetchHandler(runtime, {
|
|
19035
|
+
allowedOrigins: options.allowedOrigins,
|
|
19036
|
+
requireJsonContentType: exchangeCarrier?.requireJsonContentType,
|
|
19037
|
+
maxBodyBytes: exchangeCarrier?.maxBodyBytes,
|
|
18483
19038
|
cors: exchangeCarrier?.cors,
|
|
18484
19039
|
onWebSocketUpgrade: upgraders.length === 0 ? void 0 : (request, url) => (upgraders.find((u) => u.isUpgrade(request, url)) ?? upgraders[0]).upgrade(request, url),
|
|
18485
19040
|
isWebSocketUpgrade: upgraders.length === 0 ? void 0 : (request, url) => upgraders.some((u) => u.isUpgrade(request, url)),
|
|
@@ -18487,6 +19042,7 @@ function serveChannel(runtimeOrChannel, channelOrOptions, legacyOptions) {
|
|
|
18487
19042
|
security: exchangeSecurity,
|
|
18488
19043
|
useErrorStatus: exchangeCarrier?.useErrorStatus,
|
|
18489
19044
|
logger: options.logger,
|
|
19045
|
+
sealFailures: options.sealFailures,
|
|
18490
19046
|
transportLabel: exchangeCarrier?.carrierLabel
|
|
18491
19047
|
});
|
|
18492
19048
|
const fetch = (request) => disposed ? Promise.resolve(new Response("serveChannel: server disposed", {
|
|
@@ -18569,7 +19125,9 @@ function httpAcceptorCarrier(options = {}) {
|
|
|
18569
19125
|
secure: options.secure,
|
|
18570
19126
|
isActionPath: options.isActionPath,
|
|
18571
19127
|
cors: options.cors,
|
|
18572
|
-
useErrorStatus: options.useErrorStatus
|
|
19128
|
+
useErrorStatus: options.useErrorStatus,
|
|
19129
|
+
requireJsonContentType: options.requireJsonContentType,
|
|
19130
|
+
maxBodyBytes: options.maxBodyBytes
|
|
18573
19131
|
};
|
|
18574
19132
|
}
|
|
18575
19133
|
//#endregion
|
|
@@ -24901,8 +25459,9 @@ var RealmServerEngine = class {
|
|
|
24901
25459
|
if (conn.bucket.breaches >= this._limits.maxBreachesBeforeDetach) this.detachConnection(conn.key, "repeated limit breaches", true);
|
|
24902
25460
|
}
|
|
24903
25461
|
/**
|
|
24904
|
-
* Send a rejection to one connection. The wire carries **only** the error's
|
|
24905
|
-
* `
|
|
25462
|
+
* Send a rejection to one connection. The wire carries **only** the error's
|
|
25463
|
+
* `toWireJsonObject()` (ids, user-provided error context, message; no stack, and the sealed
|
|
25464
|
+
* failure for anything that is not a rule's own `NiceError`) — never the realm's
|
|
24906
25465
|
* `serverContext` (`ctx`), which the engine never places on an error (the protocol contract
|
|
24907
25466
|
* secret-scrub, verified). Discipline this implies for realm authors: a rule/intent error's
|
|
24908
25467
|
* **context and message are wire-visible**, so they must not embed server secrets (`ctx` values,
|
|
@@ -26685,26 +27244,38 @@ function addressMatches(address, port, hosts) {
|
|
|
26685
27244
|
const host = normalize(address.slice(0, split));
|
|
26686
27245
|
return host === "*" || host === "0.0.0.0" || host === "::" || hosts.includes(host) || hosts.includes("0.0.0.0") || hosts.includes("::");
|
|
26687
27246
|
}
|
|
27247
|
+
/**
|
|
27248
|
+
* On Linux `comm` is the main thread's name, which a runtime may set: Node's reads `MainThread`.
|
|
27249
|
+
* The executable's own name is in `/proc`. Elsewhere, or for a process we may not read, `comm` stands.
|
|
27250
|
+
*/
|
|
27251
|
+
async function executableName(pid) {
|
|
27252
|
+
if (process.platform !== "linux") return void 0;
|
|
27253
|
+
return (0, node_fs_promises.readlink)(`/proc/${pid}/exe`).then(node_path.basename, () => void 0);
|
|
27254
|
+
}
|
|
26688
27255
|
async function processDetails(pid) {
|
|
26689
|
-
const [ps, cwd] = await Promise.all([
|
|
26690
|
-
|
|
26691
|
-
|
|
26692
|
-
|
|
26693
|
-
|
|
26694
|
-
|
|
26695
|
-
|
|
26696
|
-
|
|
26697
|
-
|
|
26698
|
-
|
|
26699
|
-
|
|
26700
|
-
|
|
26701
|
-
|
|
26702
|
-
|
|
26703
|
-
|
|
27256
|
+
const [executable, ps, cwd] = await Promise.all([
|
|
27257
|
+
executableName(pid),
|
|
27258
|
+
exec("ps", [
|
|
27259
|
+
"-p",
|
|
27260
|
+
String(pid),
|
|
27261
|
+
"-o",
|
|
27262
|
+
"ppid=",
|
|
27263
|
+
"-o",
|
|
27264
|
+
"comm="
|
|
27265
|
+
], { timeout: 5e3 }).catch(() => null),
|
|
27266
|
+
exec("lsof", [
|
|
27267
|
+
"-a",
|
|
27268
|
+
"-p",
|
|
27269
|
+
String(pid),
|
|
27270
|
+
"-d",
|
|
27271
|
+
"cwd",
|
|
27272
|
+
"-Fn"
|
|
27273
|
+
], { timeout: 5e3 }).catch(() => null)
|
|
27274
|
+
]);
|
|
26704
27275
|
const match = ps?.stdout.trim().match(/^(\d+)\s+(.+)$/);
|
|
26705
27276
|
return {
|
|
26706
27277
|
ppid: match ? Number(match[1]) : null,
|
|
26707
|
-
command: match?.[2],
|
|
27278
|
+
command: executable ?? match?.[2],
|
|
26708
27279
|
cwd: cwd?.stdout.split("\n").find((l) => l.startsWith("n"))?.slice(1) ?? null
|
|
26709
27280
|
};
|
|
26710
27281
|
}
|