@stigmer/outbound 0.1.3 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -5,7 +5,7 @@ The rules a Stigmer process follows when it dials a URL a user supplied, shared
5
5
  Three entry points:
6
6
 
7
7
  - `@stigmer/outbound/egress`: which addresses a process refuses to dial (`blockedReason`, two postures, `strict` for managed cloud processes and `relaxed` for a machine that belongs to the user), the check that applies a policy to a URL after resolving every address it has (`checkEgress`), and the fetch that applies it to every redirect hop and bounds every response body (`guardedFetch`). A process composes one guarded fetch at its root and hands it to every module that dials; the modules hold no `fetch` of their own.
8
- - `@stigmer/outbound/dial`: the pinned dialer (`pinnedFetch`), whose every socket opens to an address the policy judged at connect time, and `nodeGuardedFetch`, the guarded fetch over it that a server composes at its root. The check alone would leave a window: a name can resolve to a public address for the check and a private one for the socket. This entry stands apart because importing it loads undici, which registers itself as the process's dispatcher; a server already carries undici, while a process that does not would change every `fetch` it makes by importing the egress rules.
8
+ - `@stigmer/outbound/dial`: the pinned dialer (`pinnedFetch`), whose every socket opens to an address the policy judged at connect time, and `nodeGuardedFetch`, the guarded fetch over it that a server composes at its root. The check alone would leave a window: a name can resolve to a public address for the check and a private one for the socket. This entry stands apart because importing it loads undici, which registers itself as the process's dispatcher; a server already carries undici, while a process that does not would change every `fetch` it makes by importing the egress rules. undici is an optional peer of this library: a process that imports `/dial` installs `undici` beside it, at the version this package's `peerDependencies` names, and runs on Node 22.19 or newer on 22.x, or 23.8 or newer (the entry refuses an older Node at load, with one sentence naming the version). The other entries need only the family floor in `package.json` (Node 22.13, or 23.4), so a process that never imports `/dial` (the runner) installs no undici and meets no undici floor.
9
9
  - `@stigmer/outbound/mcp-oauth`: how an MCP endpoint's authentication is read without a credential (`isOAuthChallenge`, the complete `initializeRequest`, `probeEndpointAuth`) and how its login server is found (`resolveAuthorizationServers` over RFC 9728, `readAuthorizationServerMetadata` over RFC 8414 with the issuer's path and OpenID's document).
10
10
 
11
11
  ## Why one library
@@ -14,7 +14,7 @@ Each rule here was first written where it was first needed: the address classifi
14
14
 
15
15
  ## Shape
16
16
 
17
- Pure over injected `fetch` and `lookup`; the Node-bound modules are `egress/node-lookup.ts` and the dialer, `dial/pinned-fetch.ts`, which is the library's one runtime dependency (undici, pinned to the exact version the server already resolves) and its one module with side effects. Every function that can fail on the network returns a value (`EgressCheck`, `EndpointAuthOutcome`, `MetadataRead`) rather than throwing, so a caller renders its own sentence; `EgressError` wraps a refusal for the guarded fetch. `OutboundFetch` is the fetch shape consumers take (`(url: string | URL, init?) => Promise<Response>`); the global `fetch` satisfies it.
17
+ Pure over injected `fetch` and `lookup`; the Node-bound modules are `egress/node-lookup.ts` and the dialer, `dial/pinned-fetch.ts`, which is the only module that loads undici (an optional peer, pinned to the exact version the server declares) and the library's one module with side effects. Every function that can fail on the network returns a value (`EgressCheck`, `EndpointAuthOutcome`, `MetadataRead`) rather than throwing, so a caller renders its own sentence; `EgressError` wraps a refusal for the guarded fetch. `OutboundFetch` is the fetch shape consumers take (`(url: string | URL, init?) => Promise<Response>`); the global `fetch` satisfies it.
18
18
 
19
19
  Published in lockstep with the other `backend/libs/ts` libraries by `scripts/publish-libs.mjs`; the server and runner link it with `file:` and pin the release version at stamp time.
20
20
 
package/dial/index.d.ts CHANGED
@@ -4,7 +4,10 @@
4
4
  * fetch over it that a process composes at its root. Importing this entry
5
5
  * loads undici, which registers itself as the process's dispatcher; the
6
6
  * module header of `pinned-fetch.ts` says why that keeps it off the other
7
- * entries.
7
+ * entries. undici is an optional peer: the process that imports this entry
8
+ * declares it, and `runtime-floor.ts`, imported first, refuses a Node below
9
+ * undici's floor before undici loads.
8
10
  */
11
+ import "./runtime-floor.js";
9
12
  export { nodeGuardedFetch, pinnedFetch, type NodeGuardedFetchOptions, type PinnedFetchOptions } from "./pinned-fetch.js";
10
13
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/dial/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,KAAK,uBAAuB,EAAE,KAAK,kBAAkB,EAAE,MAAM,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/dial/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,oBAAoB,CAAC;AAE5B,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,KAAK,uBAAuB,EAAE,KAAK,kBAAkB,EAAE,MAAM,mBAAmB,CAAC"}
package/dial/index.js CHANGED
@@ -4,7 +4,10 @@
4
4
  * fetch over it that a process composes at its root. Importing this entry
5
5
  * loads undici, which registers itself as the process's dispatcher; the
6
6
  * module header of `pinned-fetch.ts` says why that keeps it off the other
7
- * entries.
7
+ * entries. undici is an optional peer: the process that imports this entry
8
+ * declares it, and `runtime-floor.ts`, imported first, refuses a Node below
9
+ * undici's floor before undici loads.
8
10
  */
11
+ import "./runtime-floor.js";
9
12
  export { nodeGuardedFetch, pinnedFetch } from "./pinned-fetch.js";
10
13
  //# sourceMappingURL=index.js.map
package/dial/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/dial/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAyD,MAAM,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/dial/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,oBAAoB,CAAC;AAE5B,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAyD,MAAM,mBAAmB,CAAC"}
@@ -4,12 +4,15 @@
4
4
  *
5
5
  * Importing this module loads undici, and undici registers itself as the
6
6
  * process's dispatcher on import (the slot Node's built-in `fetch` reads)
7
- * when nothing registered one first. A Stigmer server process already
8
- * carries undici from its Kubernetes client, so nothing changes there; a
9
- * process without it (the runner) would change every `fetch` it makes by
10
- * importing this. That is why the dialer is its own entry,
11
- * `@stigmer/outbound/dial`, on neither the root barrel nor `./egress`, and
12
- * why `package.json` lists it as the library's one module with side effects.
7
+ * when nothing registered one first. A Stigmer server process carries
8
+ * undici anyway (its Kubernetes client depends on it), so nothing changes
9
+ * there; a process without it (the runner) would change every `fetch` it
10
+ * makes by importing this, and would need undici's higher Node floor. That
11
+ * is why the dialer is its own entry, `@stigmer/outbound/dial`, on neither
12
+ * the root barrel nor `./egress`; why `package.json` lists it as the
13
+ * library's one module with side effects; and why undici is an optional
14
+ * peer, declared by the process that composes this entry (the server,
15
+ * Enterprise), whose floor `runtime-floor.ts` states at load.
13
16
  *
14
17
  * Why it exists: the guarded fetch (`../egress/fetch.ts`) checks a URL's
15
18
  * addresses and then asks a `fetch` to dial its hostname, which resolves
@@ -1 +1 @@
1
- {"version":3,"file":"pinned-fetch.d.ts","sourceRoot":"","sources":["../src/dial/pinned-fetch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AACH,OAAO,EAAQ,KAAK,cAAc,EAAE,MAAM,UAAU,CAAC;AAIrD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAA+B,KAAK,QAAQ,EAAuB,MAAM,oBAAoB,CAAC;AACrG,OAAO,EAAgB,KAAK,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGtE,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC;CAC3B;AAED,MAAM,WAAW,uBAAuB;IACtC,6FAA6F;IAC7F,QAAQ,CAAC,SAAS,CAAC,EAAE,aAAa,CAAC;IACnC,kFAAkF;IAClF,QAAQ,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC;IAC3B,8EAA8E;IAC9E,QAAQ,CA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,CAAC,MAAM,EAAE,YAAY,EAAE,OAAO,GAAE,uBAA4B,GAAG,aAAa,CAQ3G;AAED,oGAAoG;AACpG,wBAAgB,WAAW,CAAC,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,kBAAkB,GAAG,aAAa,CAuC5F;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,QAAQ,GAAG,cAAc,CAepF"}
@@ -4,12 +4,15 @@
4
4
  *
5
5
  * Importing this module loads undici, and undici registers itself as the
6
6
  * process's dispatcher on import (the slot Node's built-in `fetch` reads)
7
- * when nothing registered one first. A Stigmer server process already
8
- * carries undici from its Kubernetes client, so nothing changes there; a
9
- * process without it (the runner) would change every `fetch` it makes by
10
- * importing this. That is why the dialer is its own entry,
11
- * `@stigmer/outbound/dial`, on neither the root barrel nor `./egress`, and
12
- * why `package.json` lists it as the library's one module with side effects.
7
+ * when nothing registered one first. A Stigmer server process carries
8
+ * undici anyway (its Kubernetes client depends on it), so nothing changes
9
+ * there; a process without it (the runner) would change every `fetch` it
10
+ * makes by importing this, and would need undici's higher Node floor. That
11
+ * is why the dialer is its own entry, `@stigmer/outbound/dial`, on neither
12
+ * the root barrel nor `./egress`; why `package.json` lists it as the
13
+ * library's one module with side effects; and why undici is an optional
14
+ * peer, declared by the process that composes this entry (the server,
15
+ * Enterprise), whose floor `runtime-floor.ts` states at load.
13
16
  *
14
17
  * Why it exists: the guarded fetch (`../egress/fetch.ts`) checks a URL's
15
18
  * addresses and then asks a `fetch` to dial its hostname, which resolves
@@ -1 +1 @@
1
- {"version":3,"file":"pinned-fetch.js","sourceRoot":"","sources":["../src/dial/pinned-fetch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AACH,OAAO,EAAE,IAAI,EAAuB,MAAM,UAAU,CAAC;AAErD,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,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,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACxC,IAAI,EAAE,UAAU,CAAC,IAAI,EAAE,IAAI,CAAC;QAC5B,QAAQ,EAAE,IAAI,EAAE,QAAQ;QACxB,MAAM,EAAE,IAAI,EAAE,MAAM;KACrB,CAAC;AACJ,CAAC;AAED,SAAS,UAAU,CAAC,IAAyB;IAC3C,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IACrD,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,YAAY,eAAe,IAAI,IAAI,YAAY,UAAU,IAAI,IAAI,YAAY,WAAW,EAAE,CAAC;QAC7H,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,IAAI,SAAS,CAAC,0EAA0E,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC;AACzH,CAAC"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * The Node floor of `@stigmer/outbound/dial`, checked when the entry loads.
3
+ *
4
+ * The library's other entries run on the family floor its `package.json`
5
+ * declares (Node 22.13, or 23.4); only this entry loads undici, whose own
6
+ * floor is higher. undici is an optional peer, so nothing in the library's
7
+ * manifest states that floor any more, and a process on an older Node would
8
+ * meet it as undici's crash at load (on 23.4 to 23.7, a missing
9
+ * `createZstdDecompress`). So the entry states it itself: `./index.ts`
10
+ * imports this module first, and ESM evaluates a module's imports in source
11
+ * order, so the check runs before `pinned-fetch.ts` loads undici and a Node
12
+ * below the floor gets one sentence naming the version to install.
13
+ *
14
+ * The 22.x floor is undici's declared `engines` lower bound; 23.x needs 23.8,
15
+ * where `zlib` gained what undici loads. A missing undici is left to Node's
16
+ * own resolution error, which already names the package.
17
+ *
18
+ * Proven by __tests__/dial-runtime-floor.test.ts, which pins the 22.x floor
19
+ * to the installed undici's declared one.
20
+ */
21
+ /** The lowest Node each line this entry runs on accepts; any line above the last runs. */
22
+ export declare const DIAL_NODE_FLOOR: {
23
+ /** Node 22 from 22.19, undici's declared floor. */
24
+ readonly line22: {
25
+ readonly major: 22;
26
+ readonly minor: 19;
27
+ };
28
+ /** Node 23 from 23.8; every later major. */
29
+ readonly above22: {
30
+ readonly major: 23;
31
+ readonly minor: 8;
32
+ };
33
+ };
34
+ /** The sentence a process on `version` (as `process.versions.node` gives it) is refused with, or `undefined` when it may load the entry. */
35
+ export declare function dialRuntimeRefusal(version: string): string | undefined;
36
+ //# sourceMappingURL=runtime-floor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-floor.d.ts","sourceRoot":"","sources":["../src/dial/runtime-floor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,0FAA0F;AAC1F,eAAO,MAAM,eAAe;IAC1B,mDAAmD;;;;;IAEnD,4CAA4C;;;;;CAEpC,CAAC;AAEX,4IAA4I;AAC5I,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CActE"}
@@ -0,0 +1,45 @@
1
+ /**
2
+ * The Node floor of `@stigmer/outbound/dial`, checked when the entry loads.
3
+ *
4
+ * The library's other entries run on the family floor its `package.json`
5
+ * declares (Node 22.13, or 23.4); only this entry loads undici, whose own
6
+ * floor is higher. undici is an optional peer, so nothing in the library's
7
+ * manifest states that floor any more, and a process on an older Node would
8
+ * meet it as undici's crash at load (on 23.4 to 23.7, a missing
9
+ * `createZstdDecompress`). So the entry states it itself: `./index.ts`
10
+ * imports this module first, and ESM evaluates a module's imports in source
11
+ * order, so the check runs before `pinned-fetch.ts` loads undici and a Node
12
+ * below the floor gets one sentence naming the version to install.
13
+ *
14
+ * The 22.x floor is undici's declared `engines` lower bound; 23.x needs 23.8,
15
+ * where `zlib` gained what undici loads. A missing undici is left to Node's
16
+ * own resolution error, which already names the package.
17
+ *
18
+ * Proven by __tests__/dial-runtime-floor.test.ts, which pins the 22.x floor
19
+ * to the installed undici's declared one.
20
+ */
21
+ /** The lowest Node each line this entry runs on accepts; any line above the last runs. */
22
+ export const DIAL_NODE_FLOOR = {
23
+ /** Node 22 from 22.19, undici's declared floor. */
24
+ line22: { major: 22, minor: 19 },
25
+ /** Node 23 from 23.8; every later major. */
26
+ above22: { major: 23, minor: 8 },
27
+ };
28
+ /** The sentence a process on `version` (as `process.versions.node` gives it) is refused with, or `undefined` when it may load the entry. */
29
+ export function dialRuntimeRefusal(version) {
30
+ const [major = Number.NaN, minor = Number.NaN] = version.split(".").map(Number);
31
+ const { line22, above22 } = DIAL_NODE_FLOOR;
32
+ const allowed = major === line22.major
33
+ ? minor >= line22.minor
34
+ : major === above22.major
35
+ ? minor >= above22.minor
36
+ : major > above22.major;
37
+ if (allowed)
38
+ return undefined;
39
+ return (`@stigmer/outbound/dial needs Node ${line22.major}.${line22.minor} or newer on ${line22.major}.x, ` +
40
+ `or ${above22.major}.${above22.minor} or newer; this is ${version}.`);
41
+ }
42
+ const refusal = dialRuntimeRefusal(process.versions.node);
43
+ if (refusal !== undefined)
44
+ throw new Error(refusal);
45
+ //# sourceMappingURL=runtime-floor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-floor.js","sourceRoot":"","sources":["../src/dial/runtime-floor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,0FAA0F;AAC1F,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,mDAAmD;IACnD,MAAM,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE;IAChC,4CAA4C;IAC5C,OAAO,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE;CACxB,CAAC;AAEX,4IAA4I;AAC5I,MAAM,UAAU,kBAAkB,CAAC,OAAe;IAChD,MAAM,CAAC,KAAK,GAAG,MAAM,CAAC,GAAG,EAAE,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAChF,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,eAAe,CAAC;IAC5C,MAAM,OAAO,GACX,KAAK,KAAK,MAAM,CAAC,KAAK;QACpB,CAAC,CAAC,KAAK,IAAI,MAAM,CAAC,KAAK;QACvB,CAAC,CAAC,KAAK,KAAK,OAAO,CAAC,KAAK;YACvB,CAAC,CAAC,KAAK,IAAI,OAAO,CAAC,KAAK;YACxB,CAAC,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;IAC9B,IAAI,OAAO;QAAE,OAAO,SAAS,CAAC;IAC9B,OAAO,CACL,qCAAqC,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,KAAK,gBAAgB,MAAM,CAAC,KAAK,MAAM;QACnG,MAAM,OAAO,CAAC,KAAK,IAAI,OAAO,CAAC,KAAK,sBAAsB,OAAO,GAAG,CACrE,CAAC;AACJ,CAAC;AAED,MAAM,OAAO,GAAG,kBAAkB,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AAC1D,IAAI,OAAO,KAAK,SAAS;IAAE,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stigmer/outbound",
3
- "version": "0.1.3",
3
+ "version": "0.3.0",
4
4
  "description": "The rules Stigmer's TypeScript processes dial a user-supplied endpoint by, shared by the control plane, the runner and the catalogue audit: the egress address policy, its guarded fetch and the pinned dialer under it, and the way an MCP endpoint's authentication is read (the OAuth-challenge rule, the complete initialize handshake, the RFC 9728 / RFC 8414 / OpenID resolution of its login server)",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -13,7 +13,7 @@
13
13
  "directory": "backend/libs/ts/outbound"
14
14
  },
15
15
  "engines": {
16
- "node": "^22.19.0 || >=23.8.0"
16
+ "node": "^22.13.0 || >=23.4.0"
17
17
  },
18
18
  "keywords": [
19
19
  "stigmer",
@@ -46,7 +46,12 @@
46
46
  "default": "./dial/index.js"
47
47
  }
48
48
  },
49
- "dependencies": {
49
+ "peerDependencies": {
50
50
  "undici": "8.12.3"
51
+ },
52
+ "peerDependenciesMeta": {
53
+ "undici": {
54
+ "optional": true
55
+ }
51
56
  }
52
57
  }
package/src/dial/index.ts CHANGED
@@ -4,6 +4,10 @@
4
4
  * fetch over it that a process composes at its root. Importing this entry
5
5
  * loads undici, which registers itself as the process's dispatcher; the
6
6
  * module header of `pinned-fetch.ts` says why that keeps it off the other
7
- * entries.
7
+ * entries. undici is an optional peer: the process that imports this entry
8
+ * declares it, and `runtime-floor.ts`, imported first, refuses a Node below
9
+ * undici's floor before undici loads.
8
10
  */
11
+ import "./runtime-floor.js";
12
+
9
13
  export { nodeGuardedFetch, pinnedFetch, type NodeGuardedFetchOptions, type PinnedFetchOptions } from "./pinned-fetch.js";
@@ -4,12 +4,15 @@
4
4
  *
5
5
  * Importing this module loads undici, and undici registers itself as the
6
6
  * process's dispatcher on import (the slot Node's built-in `fetch` reads)
7
- * when nothing registered one first. A Stigmer server process already
8
- * carries undici from its Kubernetes client, so nothing changes there; a
9
- * process without it (the runner) would change every `fetch` it makes by
10
- * importing this. That is why the dialer is its own entry,
11
- * `@stigmer/outbound/dial`, on neither the root barrel nor `./egress`, and
12
- * why `package.json` lists it as the library's one module with side effects.
7
+ * when nothing registered one first. A Stigmer server process carries
8
+ * undici anyway (its Kubernetes client depends on it), so nothing changes
9
+ * there; a process without it (the runner) would change every `fetch` it
10
+ * makes by importing this, and would need undici's higher Node floor. That
11
+ * is why the dialer is its own entry, `@stigmer/outbound/dial`, on neither
12
+ * the root barrel nor `./egress`; why `package.json` lists it as the
13
+ * library's one module with side effects; and why undici is an optional
14
+ * peer, declared by the process that composes this entry (the server,
15
+ * Enterprise), whose floor `runtime-floor.ts` states at load.
13
16
  *
14
17
  * Why it exists: the guarded fetch (`../egress/fetch.ts`) checks a URL's
15
18
  * addresses and then asks a `fetch` to dial its hostname, which resolves
@@ -0,0 +1,48 @@
1
+ /**
2
+ * The Node floor of `@stigmer/outbound/dial`, checked when the entry loads.
3
+ *
4
+ * The library's other entries run on the family floor its `package.json`
5
+ * declares (Node 22.13, or 23.4); only this entry loads undici, whose own
6
+ * floor is higher. undici is an optional peer, so nothing in the library's
7
+ * manifest states that floor any more, and a process on an older Node would
8
+ * meet it as undici's crash at load (on 23.4 to 23.7, a missing
9
+ * `createZstdDecompress`). So the entry states it itself: `./index.ts`
10
+ * imports this module first, and ESM evaluates a module's imports in source
11
+ * order, so the check runs before `pinned-fetch.ts` loads undici and a Node
12
+ * below the floor gets one sentence naming the version to install.
13
+ *
14
+ * The 22.x floor is undici's declared `engines` lower bound; 23.x needs 23.8,
15
+ * where `zlib` gained what undici loads. A missing undici is left to Node's
16
+ * own resolution error, which already names the package.
17
+ *
18
+ * Proven by __tests__/dial-runtime-floor.test.ts, which pins the 22.x floor
19
+ * to the installed undici's declared one.
20
+ */
21
+
22
+ /** The lowest Node each line this entry runs on accepts; any line above the last runs. */
23
+ export const DIAL_NODE_FLOOR = {
24
+ /** Node 22 from 22.19, undici's declared floor. */
25
+ line22: { major: 22, minor: 19 },
26
+ /** Node 23 from 23.8; every later major. */
27
+ above22: { major: 23, minor: 8 },
28
+ } as const;
29
+
30
+ /** The sentence a process on `version` (as `process.versions.node` gives it) is refused with, or `undefined` when it may load the entry. */
31
+ export function dialRuntimeRefusal(version: string): string | undefined {
32
+ const [major = Number.NaN, minor = Number.NaN] = version.split(".").map(Number);
33
+ const { line22, above22 } = DIAL_NODE_FLOOR;
34
+ const allowed =
35
+ major === line22.major
36
+ ? minor >= line22.minor
37
+ : major === above22.major
38
+ ? minor >= above22.minor
39
+ : major > above22.major;
40
+ if (allowed) return undefined;
41
+ return (
42
+ `@stigmer/outbound/dial needs Node ${line22.major}.${line22.minor} or newer on ${line22.major}.x, ` +
43
+ `or ${above22.major}.${above22.minor} or newer; this is ${version}.`
44
+ );
45
+ }
46
+
47
+ const refusal = dialRuntimeRefusal(process.versions.node);
48
+ if (refusal !== undefined) throw new Error(refusal);