@procedures/client 0.19.0 → 0.21.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/src/index.ts CHANGED
@@ -4,37 +4,23 @@
4
4
  * Protocol-agnostic RPC client with middleware composition
5
5
  * and transport adapters.
6
6
  *
7
- * This entry point is for Node. It exports the browser-safe entry point
8
- * ("@procedures/client/browser"). It also exports the server transports, which use `http` and
9
- * `ws`, but these exports are deprecated (CLI-6 step 1). Their entry is "@procedures/client/node".
10
- * The next MINOR removes them from this entry, so the root imports no `http` and no `ws`.
7
+ * This entry point exports the browser-safe entry point ("@procedures/client/browser"), the URL
8
+ * strategies of the server and the browser checks of the server. It imports no Node built-in, no
9
+ * `ws` and no `express`, and its declarations name none of them (CLI-6, CLI-61). Thus a browser
10
+ * bundle can import it too. The server transports and the procedure faces of Node have the entry
11
+ * "@procedures/client/node".
11
12
  *
12
- * The `WebSocketTransport` of this entry uses the global `WebSocket`, because some applications
13
- * bundle this entry for a browser. The Node entry "@procedures/client/node" has a
14
- * `WebSocketTransport` whose sockets are of the `ws` package: a drop ends them at once.
13
+ * The `WebSocketTransport` of this entry uses the global `WebSocket`. The Node entry
14
+ * "@procedures/client/node" has a `WebSocketTransport` whose sockets are of the `ws` package: a
15
+ * drop ends them at once.
15
16
  */
16
17
 
17
18
  export * from "./browser.js";
18
19
 
19
20
  // ============================================================================
20
- // Server Transports (Node only)
21
+ // The URL strategies and the browser checks of the server (browser-safe)
21
22
  // ============================================================================
22
23
  export { defaultServerUrlStrategy, rpcServerUrlStrategy } from "./adapters/http/server/strategies.js";
23
- // Deprecated (CLI-6 step 1): import these from "@procedures/client/node". The next MINOR removes
24
- // them from the root. ./server/index.ts holds the deprecated aliases, so an editor marks each old
25
- // import, and each alias is the same class or type as the export of ./node.
26
- export { HttpServerTransport } from "./server/index.js";
27
- export type {
28
- HttpServerTransportOptions,
29
- HttpUrlStrategy,
30
- } from "./server/index.js";
31
- export { WebSocketServerTransport } from "./server/index.js";
24
+ export type { RoutedRequest } from "./adapters/http/server/strategies.js";
32
25
  export { checkBrowserRequest, hasAmbientCredentials, isLoopbackHost, isLoopbackAddress, hostNameOf } from "./server/browser-guard.js";
33
- export type { BrowserGuardOptions, GuardedRequest, GuardResult } from "./server/browser-guard.js";
34
- // Deprecated (CLI-6 step 1): import these from "@procedures/client/node"
35
- export type {
36
- WebSocketServerTransportOptions,
37
- WebSocketAuthHandler,
38
- WebSocketConnectionHandler,
39
- WebSocketMessage,
40
- } from "./server/index.js";
26
+ export type { BrowserGuardOptions, GuardedHeaders, GuardedRequest, GuardResult } from "./server/browser-guard.js";
package/src/node.ts CHANGED
@@ -19,10 +19,9 @@
19
19
  * (CLI-31). `urlAddressing()` is the default, and `bodyPathAddressing()` reads the path from the
20
20
  * body of a single endpoint.
21
21
  *
22
- * The server transports are in this entry too (CLI-6): `HttpServerTransport`, the Express shim
23
- * over `procedureHandler`, and `WebSocketServerTransport`. The root and `./server` also export
24
- * them, but these exports are deprecated. The next MINOR removes them, so the root imports no
25
- * `http` and no `ws`.
22
+ * The server transports are in this entry only (CLI-6): `HttpServerTransport`, the Express shim
23
+ * over `procedureHandler`, and `WebSocketServerTransport`. Thus the root and `./server` import no
24
+ * `http`, no `ws` and no `express`.
26
25
  */
27
26
 
28
27
  export { WebSocketTransport } from "./adapters/websocket/client/node.js";
@@ -36,12 +35,12 @@ export type { ProcedureHandlerOptions, NodeProcedureHandler, NodeUrlStrategy, Ur
36
35
  export type { CorsOptions, CredentialedCorsOptions } from "./adapters/http/server/cors.js";
37
36
  // The credentialed CORS of the trusted origins of a host, for a route of the app (CLI-49)
38
37
  export { credentialedCors } from "./adapters/http/server/cors.js";
39
- export type { RoutedRequest } from "./adapters/http/server/strategies.js";
38
+ export type { RoutedRequest, UrlStrategyRequest } from "./adapters/http/server/strategies.js";
40
39
  export { defaultServerUrlStrategy, rpcServerUrlStrategy } from "./adapters/http/server/strategies.js";
41
40
  // The addressing of a request: the URL (the default), or the path in the body of a single endpoint (CLI-31)
42
41
  export { urlAddressing, bodyPathAddressing } from "./adapters/http/server/addressing.js";
43
42
  export type { Addressing, CallAddress, UrlAddressingOptions, BodyPathAddressingOptions } from "./adapters/http/server/addressing.js";
44
- // The server transports (CLI-6): the root and ./server export them only until the next MINOR
43
+ // The server transports (CLI-6): only this entry exports them
45
44
  export { HttpServerTransport } from "./adapters/http/server/transport.js";
46
45
  export type { HttpServerTransportOptions, HttpUrlStrategy } from "./adapters/http/server/types.js";
47
46
  export { upgradeHandler } from "./adapters/websocket/server/upgrade.js";
@@ -22,8 +22,6 @@
22
22
  * Each refusal is the error `FORBIDDEN` of wire v1, with the status 403 and a reason (CLI-4).
23
23
  */
24
24
 
25
- import type { IncomingHttpHeaders } from "node:http";
26
-
27
25
  const LOOPBACK_NAMES = new Set(["localhost", "127.0.0.1", "::1", "[::1]"]);
28
26
 
29
27
  /** The options of the browser checks of a server transport. */
@@ -48,10 +46,24 @@ export interface BrowserGuardOptions {
48
46
  allowGet?: boolean | undefined;
49
47
  }
50
48
 
51
- /** The parts of an incoming request that the checks read. */
49
+ /**
50
+ * The headers of a request, by lower-case name. The type is structural, so the root names no Node
51
+ * module (CLI-61). `IncomingHttpHeaders` of `node:http` agrees with it.
52
+ */
53
+ export interface GuardedHeaders {
54
+ readonly [name: string]: string | string[] | undefined;
55
+ readonly host?: string | undefined;
56
+ readonly origin?: string | undefined;
57
+ readonly cookie?: string | undefined;
58
+ readonly "content-type"?: string | undefined;
59
+ readonly "content-length"?: string | undefined;
60
+ readonly "transfer-encoding"?: string | undefined;
61
+ }
62
+
63
+ /** The parts of an incoming request that the checks read. An `IncomingMessage` of `node:http` agrees with it. */
52
64
  export interface GuardedRequest {
53
65
  method?: string | undefined;
54
- headers: IncomingHttpHeaders;
66
+ headers: GuardedHeaders;
55
67
  socket?: { localAddress?: string | undefined } | undefined;
56
68
  }
57
69
 
@@ -121,7 +133,7 @@ function isJsonType(contentType: string | undefined): boolean {
121
133
  }
122
134
 
123
135
  /** True when the request has a body: a `Content-Length` above 0, or a chunked body. */
124
- function hasBody(headers: IncomingHttpHeaders): boolean {
136
+ function hasBody(headers: GuardedHeaders): boolean {
125
137
  const length = Number(headers["content-length"] ?? 0);
126
138
  return length > 0 || headers["transfer-encoding"] !== undefined;
127
139
  }
@@ -130,7 +142,7 @@ function hasBody(headers: IncomingHttpHeaders): boolean {
130
142
  * True when a request carries ambient credentials: a `Cookie` header, which a browser sends by
131
143
  * itself, also for a request that another site starts.
132
144
  */
133
- export function hasAmbientCredentials(headers: IncomingHttpHeaders): boolean {
145
+ export function hasAmbientCredentials(headers: GuardedHeaders): boolean {
134
146
  const cookie = headers.cookie;
135
147
  return typeof cookie === "string" && cookie.trim() !== "";
136
148
  }
@@ -143,7 +155,7 @@ export function hasAmbientCredentials(headers: IncomingHttpHeaders): boolean {
143
155
  *
144
156
  * @internal
145
157
  */
146
- export function needsNamedOrigin(mode: "always" | "cookies" | undefined, headers: IncomingHttpHeaders, cookiesNamed: boolean): boolean {
158
+ export function needsNamedOrigin(mode: "always" | "cookies" | undefined, headers: GuardedHeaders, cookiesNamed: boolean): boolean {
147
159
  return mode === "always" || (hasAmbientCredentials(headers) && (cookiesNamed || mode !== undefined));
148
160
  }
149
161
 
@@ -11,8 +11,8 @@
11
11
  * - Handler registry with pattern matching
12
12
  * - Graceful shutdown
13
13
  *
14
- * The server transports have the entry `@procedures/client/node` (CLI-6). This entry still
15
- * exports them as deprecated aliases. The next MINOR removes the aliases.
14
+ * The server transports have the entry `@procedures/client/node` (CLI-6). This entry imports no
15
+ * Node built-in, no `ws` and no `express`, and its declarations name none of them (CLI-61).
16
16
  *
17
17
  * @example
18
18
  * ```typescript
@@ -38,19 +38,6 @@
38
38
  * ```
39
39
  */
40
40
 
41
- import { HttpServerTransport as NodeHttpServerTransport } from "../adapters/http/server/transport.js";
42
- import type {
43
- HttpServerTransportOptions as NodeHttpServerTransportOptions,
44
- HttpUrlStrategy as NodeHttpUrlStrategy,
45
- } from "../adapters/http/server/types.js";
46
- import { WebSocketServerTransport as NodeWebSocketServerTransport } from "../adapters/websocket/server/transport.js";
47
- import type {
48
- WebSocketServerTransportOptions as NodeWebSocketServerTransportOptions,
49
- WebSocketAuthHandler as NodeWebSocketAuthHandler,
50
- WebSocketConnectionHandler as NodeWebSocketConnectionHandler,
51
- WebSocketMessage as NodeWebSocketMessage,
52
- } from "../adapters/websocket/server/types.js";
53
-
54
41
  export { Server } from "./server.js";
55
42
  export type { ServerOptions } from "./server.js";
56
43
 
@@ -77,78 +64,4 @@ export {
77
64
  } from "./types.js";
78
65
 
79
66
  export { defaultServerUrlStrategy, rpcServerUrlStrategy } from "../adapters/http/server/strategies.js";
80
-
81
- // ============================================================================
82
- // The server transports: deprecated here (CLI-6 step 1)
83
- // ============================================================================
84
- // Their entry is `@procedures/client/node`. This entry and the root (which re-exports these
85
- // names from this module) give them through deprecated aliases until the next MINOR, so an
86
- // editor marks each old import. Each alias is the same class or type as the export of ./node.
87
-
88
- /**
89
- * The HTTP server transport of Express, a shim over `procedureHandler`.
90
- *
91
- * @deprecated Import it from `@procedures/client/node`. The root and `@procedures/client/server` stop exporting it in the next MINOR (CLI-6).
92
- */
93
- export const HttpServerTransport: typeof NodeHttpServerTransport = NodeHttpServerTransport;
94
- /**
95
- * The HTTP server transport of Express, a shim over `procedureHandler`.
96
- *
97
- * @deprecated Import it from `@procedures/client/node`. The root and `@procedures/client/server` stop exporting it in the next MINOR (CLI-6).
98
- */
99
- export type HttpServerTransport = NodeHttpServerTransport;
100
-
101
- /**
102
- * The options of `HttpServerTransport`.
103
- *
104
- * @deprecated Import it from `@procedures/client/node`. The root and `@procedures/client/server` stop exporting it in the next MINOR (CLI-6).
105
- */
106
- export type HttpServerTransportOptions = NodeHttpServerTransportOptions;
107
-
108
- /**
109
- * The URL strategy of `HttpServerTransport`: it gives the method of an Express request.
110
- *
111
- * @deprecated Import it from `@procedures/client/node`. The root and `@procedures/client/server` stop exporting it in the next MINOR (CLI-6).
112
- */
113
- export type HttpUrlStrategy = NodeHttpUrlStrategy;
114
-
115
- /**
116
- * The WebSocket server transport, on the `ws` package.
117
- *
118
- * @deprecated Import it from `@procedures/client/node`. The root and `@procedures/client/server` stop exporting it in the next MINOR (CLI-6).
119
- */
120
- export const WebSocketServerTransport: typeof NodeWebSocketServerTransport = NodeWebSocketServerTransport;
121
- /**
122
- * The WebSocket server transport, on the `ws` package.
123
- *
124
- * @deprecated Import it from `@procedures/client/node`. The root and `@procedures/client/server` stop exporting it in the next MINOR (CLI-6).
125
- */
126
- export type WebSocketServerTransport = NodeWebSocketServerTransport;
127
-
128
- /**
129
- * The options of `WebSocketServerTransport`.
130
- *
131
- * @deprecated Import it from `@procedures/client/node`. The root and `@procedures/client/server` stop exporting it in the next MINOR (CLI-6).
132
- */
133
- export type WebSocketServerTransportOptions = NodeWebSocketServerTransportOptions;
134
-
135
- /**
136
- * The authentication handler of `WebSocketServerTransport`, for each upgrade request.
137
- *
138
- * @deprecated Import it from `@procedures/client/node`. The root and `@procedures/client/server` stop exporting it in the next MINOR (CLI-6).
139
- */
140
- export type WebSocketAuthHandler = NodeWebSocketAuthHandler;
141
-
142
- /**
143
- * The connection handler of `WebSocketServerTransport`, for each new connection.
144
- *
145
- * @deprecated Import it from `@procedures/client/node`. The root and `@procedures/client/server` stop exporting it in the next MINOR (CLI-6).
146
- */
147
- export type WebSocketConnectionHandler = NodeWebSocketConnectionHandler;
148
-
149
- /**
150
- * The RPC message of `WebSocketServerTransport`.
151
- *
152
- * @deprecated Import it from `@procedures/client/node`. The root and `@procedures/client/server` stop exporting it in the next MINOR (CLI-6).
153
- */
154
- export type WebSocketMessage<TReq = unknown> = NodeWebSocketMessage<TReq>;
67
+ export type { RoutedRequest } from "../adapters/http/server/strategies.js";