@browsercore/contracts 0.2.4 → 0.2.6

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
@@ -6,10 +6,19 @@
6
6
 
7
7
  The canonical interface package for the browsercore stack. Every protocol
8
8
  package, runtime adapter, and consumer depends on these contracts — they
9
- define how components communicate without coupling them to each other. This is
10
- now the single source of truth for **all** cross-package interfaces, including
11
- the `Platform` service contracts (events, time, telemetry, network, crypto,
12
- compression).
9
+ define how components communicate without coupling them to each other. As of
10
+ 0.2.5 this is the canonical single definition for `Transport`,
11
+ `CryptoProvider`, and `CompressionProvider` (the implementing packages
12
+ re-export them), plus the `Platform` service contracts (events, time,
13
+ telemetry, network). As of 0.2.6: every `Platform` bundle is **optional**
14
+ (capabilities are resolved, not faked), `Network.udp` is a **factory**
15
+ (`UdpSocketFactory`), `Clock` is **THE** time contract (superseding the five
16
+ sibling-local shapes), `TlsHandshakeEngine` is the contracts-level seam that
17
+ lets quic drive a TLS handshake without importing `@browsercore/tls`, and the
18
+ `ProxyConfig` family / `ProfileId` / `CookieJarConsumer` config types have
19
+ their canonical homes here (owning packages alias next wave). Deliberately
20
+ package-local surfaces that remain duplicated (e.g. the full `CookieJar`)
21
+ are documented as such at each definition.
13
22
 
14
23
  ## Why this package exists
15
24
 
@@ -21,8 +30,11 @@ cross-package interface here, a type error becomes a compile error the moment
21
30
  any package diverges.
22
31
 
23
32
  **Alternative implementations welcome.** The contracts define exactly what a
24
- component must satisfy — nothing more. Want to write a different TLS engine?
25
- Implement `TlsConnection`. A different transport? Implement `Transport`. A
33
+ component must satisfy — nothing more. Want to write a different transport?
34
+ Implement `Transport`. A different crypto backend? Implement
35
+ `CryptoProvider` (synchronous — WebCrypto cannot satisfy it; see
36
+ [docs/design-decisions.md](docs/design-decisions.md) for why that is
37
+ deliberate and what an async future would cost). A
26
38
  different runtime (Bun, Deno, Workers)? Implement the `Platform` service
27
39
  interfaces. The contracts are the spec; the packages are the reference
28
40
  implementations.
@@ -56,16 +68,85 @@ compression, events, telemetry, time) down through options.
56
68
 
57
69
  | Module | Purpose | Key exports |
58
70
  |---|---|---|
59
- | **Contracts** | Provider + connection interfaces that protocol packages implement | `CryptoProvider`, `CompressionProvider`, `Transport`, `DatagramTransport`, `TlsConnection`, `Http1Connection`, `Http2Connection`, `Http3Connection`, `QuicConnection`, `QuicStream`, `FetchClient`, `CookieJar`, `PacketCallback` |
60
- | **Platform** | The composition root + per-service bundles | `Platform`, `PlatformOptions`, `Network`, `Crypto`, `Compression` |
61
- | **Events** | EventTarget-backed emitter abstraction | `EventProvider`, `TypedEventEmitter<T>` |
62
- | **Time** | Clock + scheduler with composable deadlines | `Clock`, `Duration`, `Scheduler`, `Deadline`, `Time` |
71
+ | **Contracts** | Canonical provider interfaces — the single definitions the implementing packages re-export | `CryptoProvider`, `CompressionProvider`, `Transport`, `DatagramTransport`, `UdpSocketFactory`, `CookieJar`, `PacketCallback` |
72
+ | **Platform** | The composition root + per-service bundles — **every bundle optional** | `Platform`, `PlatformOptions`, `Network`, `Crypto`, `Compression` |
73
+ | **Events** | Structural emitter interface (a method surface, **not** EventTarget-backed) injected via `Platform.events` | `EventProvider`, `TypedEventEmitter<T>` |
74
+ | **Time** | THE canonical Clock (wall + monotonic + sleep + timers) and the Duration/Scheduler helpers | `Clock`, `TimerHandle`, `Time`, `Duration`, `Scheduler`, `Deadline` |
75
+ | **TLS Engine** | The quic↔tls handshake seam — protocol packages never import each other | `TlsHandshakeEngine`, `TlsHandshakeContext`, `ClientHelloConfig`, `ServerHello`, `Certificate`, `CipherSuite`, `NamedGroup`, `SignatureScheme`, `AeadAlgorithm`, `ProtocolVersion`, `KeyPair`, `TrafficSecrets`, `ApplicationTrafficSecrets`, `HandshakePhase`, `AlertLevel` |
76
+ | **Config** | Canonical configuration types (owning packages alias next wave) | `ProxyConfig`, `ProxyScheme`, `ProxyTarget`, `ProxyCredentials`, `CookieJarConsumer` |
63
77
  | **Telemetry** | OTel-aligned observability | `Logger`, `Tracer`, `Span`, `Metrics`, `Telemetry` |
64
- | **Models** | Shared data structures that cross package boundaries | `BrowserProfile`, `TlsProfile`, `Http1Profile`, `Http2Profile`, `Request`, `Response`, `Headers`, `Cookie`, `TransportState`, `CloseReason`, `ContentEncoding` |
78
+ | **Models** | Shared data structures that cross package boundaries | `BrowserProfile`, `TlsProfile`, `Http1Profile`, `Http2Profile`, `ProfileId`, `Request`, `Response`, `Headers`, `Cookie`, `TransportState`, `CloseReason`, `ContentEncoding` |
65
79
  | **Net** | Platform-agnostic TCP + DNS contracts for runtime portability | `Net`, `DnsResolver`, `Socket`, `ConnectOptions`, `IPAddress` |
66
- | **Options** | Configuration objects passed to each protocol package | `TlsOptions`, `Http1Options`, `Http2Options`, `Http3Options`, `QuicOptions`, `FetchClientOptions` |
67
80
  | **IANA Tables** | Canonical TLS wire code lookup tables (single source of truth) | `CIPHER_SUITE_CODES`, `NAMED_GROUP_CODES`, `SIGNATURE_SCHEME_CODES`, `VERSION_CODES` |
68
81
 
82
+ The former "Protocol Connection Contracts" (`TlsConnection`, `Http1Connection`,
83
+ `Http2Connection`, `Http3Connection`, `QuicConnection`, `QuicStream`,
84
+ `FetchClient`) and the Options layer (`TlsOptions` … `FetchClientOptions`) were
85
+ removed in 0.2.5: they had zero consumers — every consumer binds the
86
+ implementation-local types exported by the protocol packages themselves
87
+ (replaceability audit, 2026-11-16). `Transport` and `CryptoProvider` here are
88
+ now the canonical single definitions that `@browsercore/transport` and
89
+ `@browsercore/crypto` re-export.
90
+
91
+ ## Platform semantics (0.2.6)
92
+
93
+ **Every `Platform` bundle is optional** — `network?`, `crypto?`,
94
+ `compression?`, `events?`, `telemetry?`, `time?` — and every `Network`
95
+ member is optional (`tcp?`, `dns?`, `udp?`). A platform carries exactly the
96
+ capabilities its runtime has; nothing has to be faked. The contract is:
97
+
98
+ - **Consumers resolve what they use and throw typed errors naming the
99
+ missing capability.** `@browsercore/fetch`'s `proxyDialPlatform`
100
+ (`fetch/src/proxy.ts`) demonstrated the pattern while the fields were
101
+ still required — untouched bundles were throwing getters naming the
102
+ culprit. With optional bundles the same guarantee is expressed by
103
+ omitting the field, and consumers write
104
+ `platform.network?.tcp ?? throw missingCapability("platform.network.tcp")`.
105
+ - **Implementers may provide everything** — an implementation providing
106
+ more than a consumer requires (e.g. `browsersmith`'s `createPlatform()`)
107
+ always satisfies the interface. Optionality removes the obligation to
108
+ fake capabilities, never the permission to supply them.
109
+
110
+ **UDP is a factory, not an instance.** `Network.udp` is a
111
+ `UdpSocketFactory` — `connect(address)` returns a per-connection
112
+ `DatagramTransport`. The previous instance shape (`udp: DatagramTransport`)
113
+ forced the composition root to bind one socket at module-import time
114
+ (browsersmith's import-time `createSocket("udp4")` singleton —
115
+ replaceability audit, 2026-11-16). A factory binds sockets at connection
116
+ time, per connection, and lets UDP-less runtimes (Cloudflare Workers) omit
117
+ the capability instead of dead-binding a socket.
118
+
119
+ **`Clock` is THE time contract.** `now()` (wall, epoch ms),
120
+ `monotonic()` (monotonic ms — never `Date.now()` deltas for deadline math),
121
+ `sleep(ms)`, `setTimeout(ms, fn)` / `clearTimeout(handle)` with
122
+ `TimerHandle` an opaque `object` (not `NodeJS.Timeout` — runtime timer
123
+ tokens must not leak into published declarations). It supersedes the five
124
+ package-local sibling Clock shapes (tls/http1/http2/http3/quic), whose
125
+ `options.clock` seams migrate onto it in the next wave. `Time` remains as
126
+ the `Platform` bundle name aliasing `Clock`; `Duration`/`Scheduler`/
127
+ `Deadline` stay for duration-composed scheduling.
128
+
129
+ **`TlsHandshakeEngine` is the quic↔tls seam.** Protocol packages never
130
+ import each other (the no-hard-wires invariant); this interface —
131
+ `runHandshake` / `generateKeyShares` / `cipherSuiteToAead` plus the pure
132
+ handshake data types — is what `@browsercore/tls` implements and the
133
+ composition root injects into quic, replacing quic's direct tls imports
134
+ (the audit's single no-hard-wires violation). http3's fake-quic
135
+ compatibility test is the proof-of-concept for swapping a structural engine
136
+ implementation.
137
+
138
+ **Canonical config homes.** `ProxyConfig`/`ProxyScheme`/`ProxyTarget`/
139
+ `ProxyCredentials` (verbatim from `@browsercore/proxy`), `ProfileId` (the
140
+ ten built-in registry ids), and `CookieJarConsumer` (the minimal jar surface
141
+ fetch actually calls — `@browsercore/cookies`' full jar satisfies it
142
+ structurally) are defined here as canonical; the owning packages alias onto
143
+ them in the next wave.
144
+
145
+ Further rationale (why the sync crypto/compression contracts are deliberate,
146
+ why WebCrypto/CompressionStream are not valid backends, and what an async
147
+ future would cost) lives in
148
+ [docs/design-decisions.md](docs/design-decisions.md).
149
+
69
150
  ## Usage
70
151
 
71
152
  ### Importing types (compile-time only)
@@ -107,8 +188,11 @@ class MyCustomTransport implements Transport {
107
188
  3. **No Node built-ins.** Types reference only portable primitives:
108
189
  `string`, `number`, `Uint8Array`, `Promise`, `IterableIterator`.
109
190
 
110
- 4. **Branded types for IDs.** `ProfileId`, `StreamId`, `ConnectionId` etc.
111
- are opaque branded types, not bare `string`/`number`.
191
+ 4. **Branded types live in the implementing packages.** Opaque ID brands
192
+ (`TransportId` in transport, `ConnectionId` in quic, `CryptoSessionId` in
193
+ crypto) are defined per-package and stay assignable to the plain
194
+ `string`/`number` fields here. Contracts itself ships plain aliases —
195
+ `ProfileId` is a plain `string`, not a brand.
112
196
 
113
197
  5. **Discriminated unions for state.** `TransportState`, `CloseReason`,
114
198
  `TlsState` model every valid state explicitly — invalid combinations
@@ -119,3 +203,7 @@ class MyCustomTransport implements Transport {
119
203
  All type exports are erased by the TypeScript compiler. The only runtime
120
204
  exports are the IANA wire code tables and `Duration` factories — plain
121
205
  `const` objects with no dependencies, no side effects.
206
+
207
+ ## Contributing
208
+
209
+ Contributions are welcome — bug reports, reproductions, docs and code alike. Start with [CONTRIBUTING.md](CONTRIBUTING.md); the full guide lives in the [browsersmith repo](https://github.com/jverneuer/browsersmith/blob/main/CONTRIBUTING.md). First timer? Check the [`good first issue`](https://github.com/jverneuer/browsercore-contracts/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22) label. Security issues: [SECURITY.md](SECURITY.md), never a public issue.
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Canonical config types — the shared configuration vocabulary.
3
+ *
4
+ * Homes for pure-data configuration shapes that cross package boundaries
5
+ * (replaceability audit 2026-11-16, remediation item #3 groundwork:
6
+ * "contracts-ify fetch's public option types" — fetch's public API is welded
7
+ * to sibling concrete types; these canonical definitions let the next wave
8
+ * alias the owning packages onto them instead).
9
+ *
10
+ * Canonical-with-alias-next-wave: each family below is copied verbatim from
11
+ * the package that owns it today. That package re-exports the canonical type
12
+ * in the next wave (the rename-free adoption pattern transport/crypto
13
+ * performed for Transport/CryptoProvider in 0.2.5), so there is exactly one
14
+ * definition and zero drift.
15
+ *
16
+ * Litmus test: pure data, no behavior — if it has methods with logic, it is
17
+ * a contract, not a config, and does not belong here.
18
+ */
19
+ import type { Cookie } from "./models.js";
20
+ /**
21
+ * Proxy schemes.
22
+ *
23
+ * - `http` — HTTP CONNECT tunneling (RFC 9110 §9.3.6)
24
+ * - `socks5` — SOCKS5 with client-side DNS: the hostname is resolved locally
25
+ * and the resolved IP is sent on the wire
26
+ * - `socks5h` — SOCKS5 with remote DNS: the hostname is sent verbatim and
27
+ * the proxy resolves it (curl's `socks5h` semantics)
28
+ */
29
+ export type ProxyScheme = "http" | "socks5" | "socks5h";
30
+ /**
31
+ * A parsed, validated proxy endpoint.
32
+ *
33
+ * Produced by `@browsercore/proxy`'s `parseProxyUrl` or hand-assembled by the
34
+ * caller. All fields are readonly — configs are shared, never mutated.
35
+ *
36
+ * The `username`/`password` fields use an explicit `| undefined` so values
37
+ * parsed from URLs (where "absent" and "empty" genuinely differ) stay
38
+ * assignable under `exactOptionalPropertyTypes`.
39
+ */
40
+ export interface ProxyConfig {
41
+ /** Tunneling scheme. */
42
+ readonly scheme: ProxyScheme;
43
+ /** Proxy host (DNS name or IP literal). */
44
+ readonly host: string;
45
+ /** Proxy port, 1–65535. */
46
+ readonly port: number;
47
+ /** Proxy username, when the proxy requires authentication. */
48
+ readonly username?: string | undefined;
49
+ /** Proxy password, when the proxy requires authentication. */
50
+ readonly password?: string | undefined;
51
+ }
52
+ /**
53
+ * The destination requested through the proxy — what the client wants to
54
+ * reach, not the proxy itself.
55
+ */
56
+ export interface ProxyTarget {
57
+ /** Target host (DNS name or IP literal). */
58
+ readonly host: string;
59
+ /** Target port, 1–65535. */
60
+ readonly port: number;
61
+ }
62
+ /**
63
+ * Credentials for proxy authentication.
64
+ *
65
+ * Used verbatim as RFC 1929 username/password (SOCKS5) or Basic auth
66
+ * (HTTP CONNECT). Field length limits are enforced by the handshake, not
67
+ * by this type.
68
+ */
69
+ export interface ProxyCredentials {
70
+ readonly username: string;
71
+ readonly password: string;
72
+ }
73
+ /**
74
+ * `CookieJarConsumer` — the structural minimal surface a cookie-consuming
75
+ * client (fetch) actually needs from a jar.
76
+ *
77
+ * Derived from fetch's real call sites (`fetch/src/client.ts`):
78
+ * `applyCookies` calls `jar.getCookies(url)` to build the Cookie header and
79
+ * `storeCookies` calls `jar.setCookie(raw, url)` per Set-Cookie header —
80
+ * nothing else (no id, no clone, no clear/serialize). `@browsercore/cookies`'
81
+ * full `CookieJar` (with SameSite-context matching, removal, and
82
+ * (de)serialization) satisfies this interface structurally as a strict
83
+ * superset; fetch migrates its `options.cookieJar` onto this type next wave,
84
+ * dropping its direct `@browsercore/cookies` type dependency.
85
+ *
86
+ * Parameter order matches `@browsercore/cookies` (`setCookie(raw, url)`),
87
+ * NOT the legacy full `CookieJar` in `contracts.ts` (whose
88
+ * `setCookie(url, cookie)` order is flipped and reconciled separately).
89
+ */
90
+ export interface CookieJarConsumer {
91
+ /**
92
+ * All cookies that match the given URL, ordered per RFC 6265 §5.4
93
+ * (domain/path specificity, earlier-set first).
94
+ */
95
+ getCookies(url: string): readonly Cookie[];
96
+ /** Parse a raw Set-Cookie header value and store the resulting cookie. */
97
+ setCookie(raw: string, url: string): void;
98
+ }
99
+ //# sourceMappingURL=config.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**
2
+ * Canonical config types — the shared configuration vocabulary.
3
+ *
4
+ * Homes for pure-data configuration shapes that cross package boundaries
5
+ * (replaceability audit 2026-11-16, remediation item #3 groundwork:
6
+ * "contracts-ify fetch's public option types" — fetch's public API is welded
7
+ * to sibling concrete types; these canonical definitions let the next wave
8
+ * alias the owning packages onto them instead).
9
+ *
10
+ * Canonical-with-alias-next-wave: each family below is copied verbatim from
11
+ * the package that owns it today. That package re-exports the canonical type
12
+ * in the next wave (the rename-free adoption pattern transport/crypto
13
+ * performed for Transport/CryptoProvider in 0.2.5), so there is exactly one
14
+ * definition and zero drift.
15
+ *
16
+ * Litmus test: pure data, no behavior — if it has methods with logic, it is
17
+ * a contract, not a config, and does not belong here.
18
+ */
19
+ export {};
20
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG"}
@@ -4,16 +4,28 @@
4
4
  * Litmus test: "Could another package reasonably import this type?"
5
5
  * If yes → belongs here. If only one protocol touches it → stays in that package.
6
6
  */
7
- import type { ContentEncoding, Cookie, DatagramCloseReason, EcdhCurve, EcdhKeyPair, FetchOptions, FetchResponse, HashId, ProtocolFrame, Request, Response, TransportState, CloseReason, TlsState, UdpAddress, X25519KeyPair, MLKEM768KeyPair } from "./models.js";
7
+ import type { ContentEncoding, Cookie, DatagramCloseReason, EcdhCurve, EcdhKeyPair, HashId, ProtocolFrame, TransportState, CloseReason, UdpAddress, X25519KeyPair, MLKEM768KeyPair } from "./models.js";
8
+ import type { EventProvider } from "./events.js";
8
9
  /**
9
- * `CryptoProvider` — the injected cryptographic primitive surface.
10
- *
11
- * Implemented by: `@browsercore/crypto`
12
- *
13
- * Why here: Every protocol package needs crypto operations. The provider is
14
- * assembled into `Platform.crypto` by the composition root (`browsersmith`)
15
- * and threaded down through options — no protocol package imports
16
- * `node:crypto` or any runtime builtin directly.
10
+ * `CryptoProvider` — the canonical injected cryptographic primitive surface.
11
+ *
12
+ * Canonical definition (replaceability audit 2026-11-16): this is the single
13
+ * Transport/Crypto-level source of truth. `@browsercore/crypto` re-exports
14
+ * this exact type; `HashId` is a plain union here while the branded
15
+ * specializations (`Sha256Id`/`Sha384Id`, the `SHA_256`/`SHA_384` constants)
16
+ * stay in `@browsercore/crypto` and remain assignable to these parameters in
17
+ * both directions (verified by compile check).
18
+ *
19
+ * Implemented by: the composition root (`browsersmith`) assembles the
20
+ * Node-backed provider from `@browsercore/crypto` building blocks and injects
21
+ * it as `Platform.crypto.provider` — protocol packages (tls, quic, http2,
22
+ * fetch) never import `node:crypto` or any runtime builtin directly.
23
+ *
24
+ * All operations are synchronous by design — an async-only backend such as
25
+ * WebCrypto cannot implement this interface; it is NOT a valid backend.
26
+ * The full rationale (sync protocol state machines, pure-JS noble backends
27
+ * covering the surface including ML-KEM, the cost of an async future) is
28
+ * recorded in [docs/design-decisions.md](docs/design-decisions.md).
17
29
  */
18
30
  export interface CryptoProvider {
19
31
  randomBytes(length: number): Uint8Array;
@@ -59,15 +71,22 @@ export interface CryptoProvider {
59
71
  x25519MLKEM768SharedSecret(x25519SecretKey: Uint8Array, x25519PeerPublicKey: Uint8Array, mlkemSecretKey: Uint8Array, mlkemCiphertext: Uint8Array): Uint8Array;
60
72
  }
61
73
  /**
62
- * `CompressionProvider` — the injected compression surface.
74
+ * `CompressionProvider` — the canonical injected compression surface.
63
75
  *
64
- * Implemented by: `@browsercore/compression`
76
+ * Canonical definition (replaceability audit 2026-11-16): signature-identical
77
+ * to `@browsercore/compression`'s local copy — verified method-by-method; this
78
+ * interface is the single source of truth, the compression package keeps a
79
+ * compatible re-export.
65
80
  *
66
- * Why here: HTTP/1 and HTTP/2 both need compression. Provided via
67
- * `Platform.compression` and passed down through options — protocols never
68
- * bind to `node:zlib` directly. All operations are synchronous and
69
- * unit-testable. Portable across backends (node:zlib, WebCompressionStream,
70
- * wasm brotli).
81
+ * Implemented by: the composition root (`browsersmith`) assembles the
82
+ * node:zlib-backed provider and injects it as `Platform.compression` —
83
+ * HTTP/1 and HTTP/2 receive it through options and never bind to `node:zlib`
84
+ * directly.
85
+ *
86
+ * All operations are synchronous by design. An async-stream backend such as
87
+ * WebCompressionStream cannot implement this interface — it is NOT a valid
88
+ * backend (the former claim that it was has been corrected). The full
89
+ * rationale lives in [docs/design-decisions.md](docs/design-decisions.md).
71
90
  *
72
91
  * The async `encode/decode(ContentEncoding)` shape had zero consumers and is
73
92
  * dropped. This sync shape is the single source of truth.
@@ -91,41 +110,65 @@ export interface CompressionProvider {
91
110
  decompress(data: Uint8Array, encoding: ContentEncoding): Uint8Array;
92
111
  }
93
112
  /**
94
- * `Transport` — the injected reliable byte stream (TCP).
95
- *
96
- * Implemented by: `@browsercore/transport`
97
- *
98
- * Why here: TLS, HTTP/1, HTTP/2 all consume `Transport`. It is created by the
99
- * injected `Platform.network.tcp` adapter and passed down through options —
100
- * never constructed by the protocols themselves.
101
- *
102
- * Event methods (`on`/`once`) are typed narrowly for stream semantics
103
- * (`data`, `close`, `error`) rather than using the generic `EventProvider`:
104
- * a Transport is a typed stream, not a generic bus. The *transport package*
105
- * still receives its events via `Platform.events` internally; these methods
106
- * are the public stream surface for protocol consumers.
113
+ * `Transport` — the canonical injected reliable byte stream (TCP).
114
+ *
115
+ * Canonical definition (replaceability audit 2026-11-16): this is the shape
116
+ * `@browsercore/transport` implements and every protocol package consumes —
117
+ * `@browsercore/transport` re-exports this exact type instead of declaring a
118
+ * competing one. The former contracts-only variant (literal-event `on`/`once`
119
+ * overloads plus a `bytesTransferred` counter on the open state) was
120
+ * implemented by nobody and is gone.
121
+ *
122
+ * Implemented by: `@browsercore/transport`'s `TcpTransport` (via
123
+ * `Platform.network.tcp` + `connect()`), and `@browsercore/proxy`'s
124
+ * socket adapter for tunneled streams. Consumed by tls, http1, http2, fetch.
125
+ *
126
+ * Events: `on`/`once` are inherited from {@link EventProvider} — the broad
127
+ * `(event: string, listener: (...args: unknown[]) => void)` surface every
128
+ * implementation actually declares. Narrowing them to per-literal overloads
129
+ * here would reject those implementations under strict checks (verified by
130
+ * compile probe on this toolchain), so the typed 3-event overloads of the old
131
+ * contracts variant are deliberately not preserved. Consumers subscribe to
132
+ * `"data"`/`"close"`/`"error"` through the EventProvider surface.
133
+ *
134
+ * `id` is a plain string; the branded `TransportId` specialization lives in
135
+ * `@browsercore/transport` and assigns to/from this field.
107
136
  */
108
- export interface Transport {
137
+ export interface Transport extends EventProvider {
138
+ /** Opaque identifier for logging / correlation. */
109
139
  readonly id: string;
140
+ /** Current lifecycle state (see {@link TransportState}). */
110
141
  readonly state: TransportState;
142
+ /**
143
+ * Write bytes to the stream. Resolves when the data has been handed to the
144
+ * kernel (or buffered). Rejects if the transport is not open.
145
+ */
111
146
  write(data: Uint8Array): Promise<void>;
147
+ /**
148
+ * Read available data. Resolves with the next chunk of bytes, or rejects if
149
+ * the transport closes before any data arrives. For a streaming read API,
150
+ * subscribe to the `"data"` event instead.
151
+ */
112
152
  read(): Promise<Uint8Array>;
153
+ /**
154
+ * Gracefully close the transport. Resolves once the stream has closed.
155
+ * `reason` is recorded for observability.
156
+ */
113
157
  close(reason?: CloseReason): Promise<void>;
114
- on(event: "data", listener: (data: Uint8Array) => void): void;
115
- on(event: "close", listener: (reason: CloseReason) => void): void;
116
- on(event: "error", listener: (error: Error) => void): void;
117
- once(event: "data", listener: (data: Uint8Array) => void): void;
118
- once(event: "close", listener: (reason: CloseReason) => void): void;
119
- once(event: "error", listener: (error: Error) => void): void;
120
158
  }
121
159
  /**
122
- * `DatagramTransport` — the injected UDP datagram surface.
160
+ * `DatagramTransport` — the canonical injected UDP datagram surface.
161
+ *
162
+ * Canonical definition (replaceability audit 2026-11-16): signature-identical
163
+ * to `@browsercore/transport`'s local copy, which re-exports this one.
123
164
  *
124
- * Implemented by: `@browsercore/transport`
165
+ * One instance represents ONE datagram endpoint (a bound socket talking to a
166
+ * single peer addressing scheme). Do not share an instance across independent
167
+ * connections — obtain one per connection from a {@link UdpSocketFactory}
168
+ * (injected as `Platform.network.udp`).
125
169
  *
126
- * Why here: QUIC consumes `DatagramTransport`. Like `Transport`, it is
127
- * obtained from `Platform.network.udp` and passed down through options —
128
- * protocol packages never bind to a runtime socket directly.
170
+ * Implemented by: the composition root's UDP adapter (`browsersmith`,
171
+ * via `Platform.network.udp.connect()`). Consumed by `@browsercore/quic`.
129
172
  */
130
173
  export interface DatagramTransport {
131
174
  readonly id: string;
@@ -137,118 +180,46 @@ export interface DatagramTransport {
137
180
  close(reason?: DatagramCloseReason): Promise<void>;
138
181
  }
139
182
  /**
140
- * `TlsConnection` — the injected TLS connection surface.
141
- *
142
- * Implemented by: `@browsercore/tls`
143
- *
144
- * Why here: fetch consumes `TlsConnection`. The TLS package receives its
145
- * injected dependencies (transport, crypto, events) through `TlsOptions`,
146
- * which is populated from the `Platform` composition root.
147
- */
148
- export interface TlsConnection {
149
- readonly id: string;
150
- readonly state: TlsState;
151
- handshake(): Promise<void>;
152
- read(): Promise<Uint8Array>;
153
- write(data: Uint8Array): Promise<void>;
154
- close(): Promise<void>;
155
- }
156
- /**
157
- * `Http1Connection` — the injected HTTP/1 connection surface.
158
- *
159
- * Implemented by: `@browsercore/http1`
160
- *
161
- * Why here: fetch consumes `Http1Connection`. The package receives its
162
- * injected transport and profile through `Http1Options`.
163
- */
164
- export interface Http1Connection {
165
- readonly id: string;
166
- request(req: Request): Promise<Response>;
167
- close(): Promise<void>;
168
- }
169
- /**
170
- * `Http2Connection` — the injected HTTP/2 connection surface.
171
- *
172
- * Implemented by: `@browsercore/http2`
173
- *
174
- * Why here: fetch consumes `Http2Connection`. The package receives its
175
- * injected transport and profile through `Http2Options`.
176
- */
177
- export interface Http2Connection {
178
- readonly id: string;
179
- request(req: Request): Promise<Response>;
180
- close(): Promise<void>;
181
- goaway(): Promise<void>;
182
- }
183
- /**
184
- * `Http3Connection` — the injected HTTP/3 connection surface.
185
- *
186
- * Implemented by: `@browsercore/http3`
187
- *
188
- * Why here: fetch consumes `Http3Connection`. Built on top of
189
- * `QuicConnection`; receives its injected QUIC transport through
190
- * `Http3Options`.
191
- */
192
- export interface Http3Connection {
193
- readonly id: string;
194
- request(req: Request): Promise<Response>;
195
- close(): Promise<void>;
196
- goaway(streamId: bigint): Promise<void>;
197
- }
198
- /**
199
- * `QuicConnection` — the injected QUIC connection surface.
200
- *
201
- * Implemented by: `@browsercore/quic`
202
- *
203
- * Why here: HTTP/3 consumes `QuicConnection`. The package receives its
204
- * injected UDP transport and crypto through `QuicOptions`, populated from
205
- * `Platform`.
206
- */
207
- export interface QuicConnection {
208
- readonly id: string;
209
- handshake(): Promise<void>;
210
- openBidirectionalStream(): Promise<QuicStream>;
211
- acceptBidirectionalStream(): Promise<QuicStream>;
212
- openUnidirectionalStream(): Promise<QuicStream>;
213
- acceptUnidirectionalStream(): Promise<QuicStream>;
214
- close(errorCode: bigint, reason: string): Promise<void>;
215
- sendPathChallenge(data: Uint8Array): void;
216
- hasPendingPathChallenge(data: Uint8Array): boolean;
217
- }
218
- /**
219
- * `QuicStream` — an injected QUIC stream handle.
220
- *
221
- * Why here: `QuicConnection` returns `QuicStream`; HTTP/3 uses it for
222
- * request multiplexing. Streams are owned by the QUIC package and carry no
223
- * direct runtime dependency.
224
- */
225
- export interface QuicStream {
226
- readonly id: bigint;
227
- write(data: Uint8Array): Promise<void>;
228
- read(): Promise<Uint8Array>;
229
- close(): Promise<void>;
230
- }
231
- /**
232
- * `FetchClient` — the injected high-level fetch surface.
233
- *
234
- * Implemented by: `@browsercore/fetch`
235
- *
236
- * Why here: browsersmith consumes `FetchClient`. Assembled from the
237
- * protocol connections and injected services (`CookieJar`, transport, crypto)
238
- * via `FetchClientOptions`, which `browsersmith` populates from `Platform`.
183
+ * `UdpSocketFactory` — the canonical injected UDP entry point.
184
+ *
185
+ * Factory, deliberately NOT an instance: the old `Platform.network.udp` shape
186
+ * (`udp: DatagramTransport`) forced the composition root to bind ONE socket
187
+ * at module load — `browsersmith`'s adapter called `createSocket("udp4")` at
188
+ * import time and shared that singleton everywhere (replaceability audit
189
+ * 2026-11-16: "udp default = import-time-bound createSocket('udp4') singleton").
190
+ * A factory keeps socket creation at connection time, per connection: the
191
+ * consumer (`@browsercore/quic`) calls `connect()` when it opens a session and
192
+ * closes the returned {@link DatagramTransport} when the session ends. Nothing
193
+ * datagram-related happens merely because the platform module was imported —
194
+ * which is what makes a UDP-less runtime (e.g. Cloudflare Workers) able to
195
+ * omit the factory entirely instead of dead-binding a socket.
196
+ *
197
+ * Implemented by: the composition root (`browsersmith`, injected as
198
+ * `Platform.network.udp` — now optional). Consumed by `@browsercore/quic`.
239
199
  */
240
- export interface FetchClient {
241
- fetch(url: string, options?: FetchOptions): Promise<FetchResponse>;
242
- close(): Promise<void>;
200
+ export interface UdpSocketFactory {
201
+ /**
202
+ * Open a datagram endpoint for communicating with `address`.
203
+ * Resolves once the socket is ready to send/receive.
204
+ */
205
+ connect(address: UdpAddress): Promise<DatagramTransport>;
243
206
  }
244
207
  /**
245
- * `CookieJar` — the injected cookie storage surface.
208
+ * `CookieJar` — the full cookie storage surface.
246
209
  *
247
- * Implemented by: `@browsercore/cookies`
210
+ * Implemented by: `@browsercore/cookies` (its local `CookieJar` is the shape
211
+ * consumers actually bind; note its `setCookie` parameter order is
212
+ * `(raw, url)` — flipped relative to this interface. Reconciling the two
213
+ * is tracked separately from the Transport/CryptoProvider unification.)
248
214
  *
249
215
  * Why here: fetch and browsersmith both use `CookieJar`. Provided via
250
216
  * `FetchClientOptions.cookieJar`, populated from `Platform` or a custom
251
217
  * implementation — never hardcoded to a runtime store.
218
+ *
219
+ * Consumers that only READ cookies out of a jar (send `getCookies`, store
220
+ * `setCookie`) should depend on the narrower structural `CookieJarConsumer`
221
+ * (see `config.ts`) instead — `@browsercore/cookies`' full jar satisfies it
222
+ * as a strict superset.
252
223
  */
253
224
  export interface CookieJar {
254
225
  getCookies(url: string): readonly Cookie[];
@@ -1 +1 @@
1
- {"version":3,"file":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,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3D,IAAI,IAAI,OAAO,CAAC;QAAE,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;QAAC,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAA;KAAE,CAAC,CAAC;IAC1E,KAAK,CAAC,MAAM,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACtD;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,WAAW,gBAAgB;IAC7B;;;OAGG;IACH,OAAO,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;CAC5D;AAMD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,WAAW,SAAS;IACtB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAAC;IAC3C,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7C,KAAK,IAAI,IAAI,CAAC;IACd,SAAS,IAAI,MAAM,CAAC;IACpB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CACnC;AAWD;;;;;;GAMG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;AAE5D;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACpC,QAAQ,CAAC,QAAQ,CAAC,EAAE,cAAc,CAAC;CACtC"}
package/dist/events.d.ts CHANGED
@@ -33,8 +33,17 @@ export interface EventProvider {
33
33
  * Consumers define a map of event names to listener signatures and get
34
34
  * type-safe `emit`/`on` calls. This is the typed counterpart to the
35
35
  * untyped `EventProvider` — same injection pattern, stronger guarantees.
36
+ *
37
+ * The constraint uses `(...args: never[]) => void`: `never` is the bottom
38
+ * type, so by contravariance ANY listener signature satisfies it
39
+ * (`(x: number) => void`, `() => void`, …). The former `unknown[]`
40
+ * constraint rejected every map with typed parameters — i.e. the exact
41
+ * pattern this interface documents — while `any[]` (the original) is banned
42
+ * by the coding standards. `never[]` is the no-`any` way to say "any
43
+ * listener shape" (corrected with the 2026-11-16 test-rot fix; the tests
44
+ * had never been typechecked against this constraint).
36
45
  */
37
- export interface TypedEventEmitter<T extends Record<string, (...args: unknown[]) => void>> {
46
+ export interface TypedEventEmitter<T extends Record<string, (...args: never[]) => void>> {
38
47
  on<K extends keyof T>(event: K, listener: T[K]): void;
39
48
  once<K extends keyof T>(event: K, listener: T[K]): void;
40
49
  off<K extends keyof T>(event: K, listener: T[K]): void;