@procedures/client 0.18.1 → 0.19.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/CHANGELOG.md +29 -0
- package/README.md +20 -2
- package/dist/.tsbuildinfo +1 -1
- package/dist/adapters/port/transport.d.ts +10 -1
- package/dist/adapters/port/transport.d.ts.map +1 -1
- package/dist/adapters/port/transport.js +5 -1
- package/dist/adapters/port/transport.js.map +1 -1
- package/dist/adapters/websocket/client/transport.d.ts.map +1 -1
- package/dist/adapters/websocket/client/transport.js +8 -2
- package/dist/adapters/websocket/client/transport.js.map +1 -1
- package/dist/adapters/websocket/client/types.d.ts +3 -0
- package/dist/adapters/websocket/client/types.d.ts.map +1 -1
- package/dist/adapters/websocket/client/types.js.map +1 -1
- package/dist/browser.d.ts +2 -2
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +2 -2
- package/dist/browser.js.map +1 -1
- package/dist/server/procedure-server.d.ts +13 -8
- package/dist/server/procedure-server.d.ts.map +1 -1
- package/dist/server/procedure-server.js +15 -3
- package/dist/server/procedure-server.js.map +1 -1
- package/dist/server/request-auth.d.ts +16 -1
- package/dist/server/request-auth.d.ts.map +1 -1
- package/dist/server/request-auth.js +18 -0
- package/dist/server/request-auth.js.map +1 -1
- package/dist/server/types.d.ts +22 -6
- package/dist/server/types.d.ts.map +1 -1
- package/dist/server/types.js +6 -0
- package/dist/server/types.js.map +1 -1
- package/package.json +1 -1
- package/src/adapters/port/transport.ts +15 -2
- package/src/adapters/websocket/client/transport.ts +10 -3
- package/src/adapters/websocket/client/types.ts +3 -0
- package/src/browser.ts +2 -1
- package/src/server/procedure-server.ts +23 -9
- package/src/server/request-auth.ts +20 -1
- package/src/server/types.ts +23 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
# @procedures/client
|
|
2
2
|
|
|
3
|
+
## 0.19.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 5cb934d: Breaking: a `ProcedureServer` with a token or a request hook (`principalOf`) refuses a request without credentials (CLI-1). The error code is `UNAUTHORIZED`, and the hook does not run for it. Before, such a request skipped the token check and the request hook. Thus a face that set no credentials, for example a custom transport, went around the authentication.
|
|
8
|
+
|
|
9
|
+
New: the local marker `LOCAL_CREDENTIALS`, with `isLocalCredentials()` and its key `LOCAL_MARKER`. A local face sets it. Only a local request skips the token and the request hook.
|
|
10
|
+
|
|
11
|
+
The server examines a request in one of three ways:
|
|
12
|
+
|
|
13
|
+
- A local request skips the token and the request hook.
|
|
14
|
+
- A request without credentials gets `UNAUTHORIZED` when the server has a token or a request hook.
|
|
15
|
+
- A request with credentials goes through the request hook and the token check, as before.
|
|
16
|
+
|
|
17
|
+
- The local faces are MCP over stdio, an SDK transport of `McpServerTransport` and `PortTransport`. The peer of stdio is the parent process. Only the holder of the other end of a port can send to it.
|
|
18
|
+
- A network face never sets the marker: HTTP, WebSocket and MCP over Streamable HTTP. The key of the marker is a symbol. JSON, structured clone, a header, a cookie and a query cannot carry it.
|
|
19
|
+
- The calls of a WebSocket server to the `serve` handler of its client are not local. Their credentials are empty, so a `serve` server with a token refuses them.
|
|
20
|
+
- `PortTransport` has the new option `credentials`. Give `{}` for a port that a part outside the application can reach, for example a `Window`.
|
|
21
|
+
- The nested calls of a procedure do not go through the token check. They keep the principal of their caller.
|
|
22
|
+
|
|
23
|
+
Migration:
|
|
24
|
+
|
|
25
|
+
- A custom transport or face that sends no credentials to a server with a token or a request hook now gets `UNAUTHORIZED`. Set the credentials of its request (`requestCredentials()`), or `LOCAL_CREDENTIALS` for a face in this process.
|
|
26
|
+
- Code that calls `server.handle()` of a server with a token or a request hook gives `credentials: LOCAL_CREDENTIALS`.
|
|
27
|
+
- The site: no change. Its servers have no token and no request hook, and its workers serve over `PortTransport`, which sets the marker.
|
|
28
|
+
- MiniMongo: no change. `scripts/dev.ts` starts a server without a token and without a request hook. Its HTTP and WebSocket faces set the credentials of each request.
|
|
29
|
+
- Graph: no change. The procedure host (`packages/server/graph-host.ts`) has a request hook (`graphPrincipalOf` of `packages/server/graph-procedures.ts`) and no token. All its faces send credentials: HTTP, WebSocket and MCP over Streamable HTTP (`mcpFace`). No code of Graph calls `handle()` directly. The MCP host (`packages/mcp/src/host.ts`) operates over stdio, which is local.
|
|
30
|
+
- jarvis: no change. The loopback server and the remote server of `packages/http/src/procedures.ts` have a request hook (`principalOf`), and the remote server has a token. `makeProcedureHandler` mounts `procedureHandler`, which sends the credentials of each request. A test that calls `handle()` of such a server gives `LOCAL_CREDENTIALS`, or credentials with the token.
|
|
31
|
+
|
|
3
32
|
## 0.18.1
|
|
4
33
|
|
|
5
34
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -707,7 +707,7 @@ interface ProcedureServerOptions {
|
|
|
707
707
|
storage?: StorageConfig;
|
|
708
708
|
transports?: ServerTransport[];
|
|
709
709
|
events?: EventPublisherOptions | EventPublisher; // the remote events: refer to "Remote events"
|
|
710
|
-
token?: string; // the token that each
|
|
710
|
+
token?: string; // the token that each request presents, except a local request
|
|
711
711
|
principalOf?: PrincipalOf; // the request hook: refer to "The request hook"
|
|
712
712
|
authenticate?: (request: ServerRequest) => Principal | undefined | Promise<Principal | undefined>;
|
|
713
713
|
}
|
|
@@ -735,9 +735,27 @@ const server = new ProcedureServer({
|
|
|
735
735
|
- `principal`: the principal of the request, for example the user of a session cookie. The procedure reads it as `ctx.principal`, and its nested calls get the same principal.
|
|
736
736
|
- `narrowing`: a narrower capability that the request asks for. The server narrows the capability of the call with it. A request for more has no effect.
|
|
737
737
|
- An empty object accepts the request without a principal. Undefined, or an error, refuses the request with `UNAUTHORIZED`.
|
|
738
|
-
- `authenticate` operates after the hook and can read `request.principal`. A request
|
|
738
|
+
- `authenticate` operates after the hook and can read `request.principal`. A local request does not go through the hook.
|
|
739
739
|
- `hostPolicy({ principalOf })` gives the hook to each server of the policy.
|
|
740
740
|
|
|
741
|
+
#### Local requests
|
|
742
|
+
|
|
743
|
+
Each face sets the credentials of its requests, or the local marker `LOCAL_CREDENTIALS` (CLI-1). A local request comes from this application, so the token and the request hook do not apply to it.
|
|
744
|
+
|
|
745
|
+
- The local faces are MCP over stdio, an SDK transport of `McpServerTransport` and `PortTransport`. The peer of stdio is the parent process. Only the holder of the other end of a port can send to it.
|
|
746
|
+
- A network face never sets the marker: HTTP, WebSocket, and MCP over Streamable HTTP. The key of the marker is a symbol, so JSON, a header, a cookie or a query cannot carry it.
|
|
747
|
+
- A server with a token or a request hook refuses a request without credentials with `UNAUTHORIZED`. The hook does not operate for it. Before, such a request skipped the token and the hook.
|
|
748
|
+
- A call of the code of the application to `server.handle()` sets the marker itself:
|
|
749
|
+
|
|
750
|
+
```typescript
|
|
751
|
+
import { LOCAL_CREDENTIALS } from "@procedures/client";
|
|
752
|
+
|
|
753
|
+
await server.handle({ id: "1", method, payload, metadata: {}, credentials: LOCAL_CREDENTIALS });
|
|
754
|
+
```
|
|
755
|
+
|
|
756
|
+
- The nested calls of a procedure do not go through the token check again. They keep the principal of their caller.
|
|
757
|
+
- A `PortTransport` that a part outside the application can reach takes `credentials: {}`. Then the token applies. A `Window` is such a port.
|
|
758
|
+
|
|
741
759
|
#### Cookies and CSRF
|
|
742
760
|
|
|
743
761
|
A browser sends the cookies of a server by itself, also for a request that a page of another site starts. Thus a server that reads cookies trusts a request only from a named origin.
|