@shivaedev/server 0.40.0 → 0.41.1
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 +14 -0
- package/README.md +5 -7
- package/dist/boundedRpcSocket.d.ts +1 -1
- package/dist/boundedRpcSocket.d.ts.map +1 -1
- package/dist/boundedRpcSocket.js +21 -11
- package/dist/boundedRpcSocket.js.map +1 -1
- package/dist/hostRpcRoutes.js +1 -1
- package/dist/hostRpcRoutes.js.map +1 -1
- package/package.json +10 -10
- package/src/boundedRpcSocket.ts +34 -11
- package/src/hostRpcRoutes.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.41.1 - 2026-11-21
|
|
4
|
+
|
|
5
|
+
### Changed
|
|
6
|
+
|
|
7
|
+
- Update `@shivaedev/admin` from 0.28.2 to 0.28.3.
|
|
8
|
+
- Update `@shivaedev/contract` from 0.55.0 to 0.56.0.
|
|
9
|
+
- Update `@shivaedev/identity` from 0.38.1 to 0.38.2.
|
|
10
|
+
|
|
11
|
+
## 0.41.0 - 2026-11-21
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
|
|
15
|
+
- when the host closes an RPC socket because a message exceeds `maxBodySize` or `MAX_BODY_SIZE`, it logs one warning with the limit, the message size and the RPC path, annotated as `rpc.maxBodySize`, `rpc.messageSize` and `url.path`, and none of the message's content. The size is `unknown` when the Node listener's WebSocket server refuses the message before the host reads it.
|
|
16
|
+
|
|
3
17
|
## 0.40.0 - 2026-11-21
|
|
4
18
|
|
|
5
19
|
### Added
|
package/README.md
CHANGED
|
@@ -250,13 +250,13 @@ Set `config.socketPath` to serve the application over a Unix socket instead of t
|
|
|
250
250
|
|
|
251
251
|
Unix clients can call HTTP RPC and subscribe through WebSocket RPC over the same socket path. Unix requests use filesystem access for transport admission; session middleware and query read policies still apply. TCP keeps its loopback, origin and proxy checks.
|
|
252
252
|
|
|
253
|
-
RPC request bodies are limited to 1 MiB by default. Set `MAX_BODY_SIZE` to a byte count or override it with `config.maxBodySize`, a nonnegative safe integer. An oversized NDJSON body, fixed-length or chunked, returns a 4xx before any RPC handler runs. The same byte limit applies to each WebSocket RPC message, including binary messages and the combined payload of continuation frames. An oversized message closes the connection with code 1009 before any RPC in that message runs; native Effect socket clients receive a typed `SocketError` with a `SocketCloseError` reason. The limit includes bearer authentication frames, and zero refuses every nonempty message. This limit applies to the host's RPC route.
|
|
253
|
+
RPC request bodies are limited to 1 MiB by default. Set `MAX_BODY_SIZE` to a byte count or override it with `config.maxBodySize`, a nonnegative safe integer. An oversized NDJSON body, fixed-length or chunked, returns a 4xx before any RPC handler runs. The same byte limit applies to each WebSocket RPC message, including binary messages and the combined payload of continuation frames. The limit is per message and the same for every RPC on the socket; no operation has a limit of its own. An oversized message closes the whole connection with code 1009 before any RPC in that message runs, so every call in flight on it fails; native Effect socket clients receive a typed `SocketError` with a `SocketCloseError` reason. The host logs one warning for each refusal with the limit, the message size and the RPC path, annotated as `rpc.maxBodySize`, `rpc.messageSize` and `url.path`, and never any of the message's content. The size is `unknown` when the Node listener's WebSocket server refuses the message as it arrives, before the host reads it. The limit includes bearer authentication frames, and zero refuses every nonempty message. This limit applies to the host's RPC route.
|
|
254
254
|
|
|
255
255
|
For a native Node HTTP route outside RPC, read the request body with `readBoundedBody` from [`@shivaedev/http`](https://github.com/ShivaeDev/platform/tree/main/packages/http#readme), which rejects oversized bodies with a typed 413 failure.
|
|
256
256
|
|
|
257
257
|
On TCP, ordinary POST RPC uses `localRpcGuard` from `@shivaedev/identity/server/adapters/local.ts`: it requires a loopback peer and Host, same-origin or absent Origin, and the NDJSON content type. The WebSocket upgrade uses the same loopback, origin and trusted-proxy checks without an HTTP body content type. Session lookup uses the upgrade's transport headers; RPC message headers cannot replace its cookie or Origin. Session middleware revalidates authenticated streams at `streamRevalidationInterval` and ends revoked subscriptions with typed `Unauthorized`. Cookie-authenticated sockets remain open; later protected calls use the same session checks. Automatic live subscriptions reload the session before each hint and use its current roles and grants for the query policy and any pushed query result. A policy denial keeps an established subscription open; delivery resumes on the next authorized hint. POST RPC refuses `$changes` subscriptions with the contract’s typed `WebSocketRequired` error and a message saying they need the WebSocket protocol. The host applies `RequestTracing` last to every served RPC, including loopback RPC, so it wraps authentication and handlers without a per-contract tracing declaration. Existing tracing declarations run once at that outermost boundary. With a session policy, contracts declare `Authenticated` and `MaybeAuthenticated` as needed; the host supplies their implementations. For `AuthenticatedUser`, merge `authenticatedUserLayer()` from `@shivaedev/identity/server/session.ts` beside the handlers. Declared errors retain their Schema types. Applications still own resource authorization and use `rpcBoundary` when they need to map unexpected failures.
|
|
258
258
|
|
|
259
|
-
Native clients that cannot set upgrade headers use `makeClient`'s `bearerToken` option from `@shivaedev/contract/
|
|
259
|
+
Native clients that cannot set upgrade headers use `makeClient`'s `bearerToken` option from `@shivaedev/contract/makeClient.ts`. On session hosts, `GET /rpc?auth=frame` requires a first text frame shaped as `{"_tag":"Authenticate","token":"<credential>"}` within five seconds, with at most 8192 characters. The host consumes that frame before starting native RPC and supplies its bearer as the socket's transport Authorization header. The existing session provider, identity middleware, Origin policy and query read policies apply to every call and live read. RPC message headers cannot replace the authenticated credential. Configure bearer admission on the session provider and the WebView Origin through `nativeOrigins`. A long-lived bearer is never placed in a URL.
|
|
260
260
|
|
|
261
261
|
Invalid, expired, malformed, oversized or missing first-frame credentials close the socket with code 1008 and reason `Authentication required`; session-provider failures close it with code 1011 and reason `Authentication unavailable`. The host checks the bearer socket's session at `streamRevalidationInterval`, including when no subscription is active, and closes it with code 1008 when the session is revoked, expires or changes identity. The session remains subject to the same per-call and per-hint checks as cookie sessions.
|
|
262
262
|
|
|
@@ -394,16 +394,14 @@ export const Server = appHost({
|
|
|
394
394
|
|
|
395
395
|
`publicConfigLayer` reads `Config.schema` from the host's native ConfigProvider when the handler Layer builds. Missing or invalid required fields fail startup with a typed `ConfigError`. An optional second argument supplies a native Config path: `publicConfigLayer(PublicConfig, "PUBLIC")` reads `PUBLIC_INSTALL_URL` with the default environment provider. Only schema-declared fields are loaded and serialized; other server values never enter this response. The generated query has no session middleware, so it can supply public configuration before sign-in. Merge it alongside authenticated contracts rather than applying authentication to the merged group.
|
|
396
396
|
|
|
397
|
-
On the client,
|
|
397
|
+
On the client, put the contract in the record of the same `makeClient` as the other contracts, on the shared WebSocket:
|
|
398
398
|
|
|
399
399
|
```ts
|
|
400
|
-
import { makeClient } from "@shivaedev/contract/
|
|
400
|
+
import { makeClient } from "@shivaedev/contract/makeClient.ts";
|
|
401
401
|
import { useQuery } from "@shivaedev/react/client/resultState.ts";
|
|
402
402
|
import { PublicConfig } from "./public-config.ts";
|
|
403
403
|
|
|
404
|
-
const {
|
|
405
|
-
url: new URL("/rpc", window.location.href).href,
|
|
406
|
-
});
|
|
404
|
+
const { config } = makeClient({ config: PublicConfig }).api;
|
|
407
405
|
|
|
408
406
|
export function usePublicConfig() {
|
|
409
407
|
return useQuery(config.get.query());
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
2
|
import { HttpServerRequest } from "effect/http";
|
|
3
|
-
export declare const boundedRpcSocket: (limit: number) => Effect.Effect<HttpServerRequest.HttpServerRequest, never, HttpServerRequest.HttpServerRequest>;
|
|
3
|
+
export declare const boundedRpcSocket: (limit: number, route: string) => Effect.Effect<HttpServerRequest.HttpServerRequest, never, HttpServerRequest.HttpServerRequest>;
|
|
4
4
|
//# sourceMappingURL=boundedRpcSocket.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"boundedRpcSocket.d.ts","sourceRoot":"","sources":["../src/boundedRpcSocket.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"boundedRpcSocket.d.ts","sourceRoot":"","sources":["../src/boundedRpcSocket.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAa,MAAM,QAAQ,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGhD,eAAO,MAAM,gBAAgB,kIAmB3B,CAAC"}
|
package/dist/boundedRpcSocket.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Effect } from "effect";
|
|
1
|
+
import { Effect, Predicate } from "effect";
|
|
2
2
|
import { HttpServerRequest } from "effect/http";
|
|
3
3
|
import * as Socket from "effect/socket/Socket";
|
|
4
|
-
export const boundedRpcSocket = Effect.fnUntraced(function* (limit) {
|
|
4
|
+
export const boundedRpcSocket = Effect.fnUntraced(function* (limit, route) {
|
|
5
5
|
const request = yield* HttpServerRequest.HttpServerRequest;
|
|
6
6
|
const upgrade = Effect.map(request.upgrade, (socket) => ({
|
|
7
7
|
...socket,
|
|
@@ -10,15 +10,7 @@ export const boundedRpcSocket = Effect.fnUntraced(function* (limit) {
|
|
|
10
10
|
const writer = yield* socket.writer;
|
|
11
11
|
return {
|
|
12
12
|
...reader,
|
|
13
|
-
pull:
|
|
14
|
-
if (frames.every((frame) => (typeof frame === "string" ? Buffer.byteLength(frame) : frame.byteLength) <= limit)) {
|
|
15
|
-
return Effect.succeed(frames);
|
|
16
|
-
}
|
|
17
|
-
const reason = new Socket.SocketCloseError({ closeReason: "RPC frame exceeds maxBodySize", code: 1009 });
|
|
18
|
-
return writer
|
|
19
|
-
.write(new Socket.CloseEvent(reason.code, reason.closeReason))
|
|
20
|
-
.pipe(Effect.andThen(Effect.fail(new Socket.SocketError({ reason }))));
|
|
21
|
-
}),
|
|
13
|
+
pull: boundedPull(reader.pull, writer, limit, route),
|
|
22
14
|
};
|
|
23
15
|
}),
|
|
24
16
|
}));
|
|
@@ -26,4 +18,22 @@ export const boundedRpcSocket = Effect.fnUntraced(function* (limit) {
|
|
|
26
18
|
get: (target, key, receiver) => (key === "upgrade" ? upgrade : Reflect.get(target, key, receiver)),
|
|
27
19
|
});
|
|
28
20
|
});
|
|
21
|
+
function boundedPull(pull, writer, limit, route) {
|
|
22
|
+
return pull.pipe(Effect.tapError((error) => (payloadRefused(error) ? refused(limit, route, undefined) : Effect.void)), Effect.flatMap((frames) => {
|
|
23
|
+
const size = frames.map((frame) => (typeof frame === "string" ? Buffer.byteLength(frame) : frame.byteLength)).find((bytes) => bytes > limit);
|
|
24
|
+
if (size === undefined) {
|
|
25
|
+
return Effect.succeed(frames);
|
|
26
|
+
}
|
|
27
|
+
const reason = new Socket.SocketCloseError({ closeReason: "RPC frame exceeds maxBodySize", code: 1009 });
|
|
28
|
+
return refused(limit, route, size).pipe(Effect.andThen(writer.write(new Socket.CloseEvent(reason.code, reason.closeReason))), Effect.andThen(Effect.fail(new Socket.SocketError({ reason }))));
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
31
|
+
function refused(limit, route, size) {
|
|
32
|
+
return Effect.logWarning(`An RPC message of ${size === undefined ? "unknown size" : `${size} bytes`} exceeded the ${limit}-byte body limit at ${route}, so the host closed the socket with code 1009. Raise maxBodySize or MAX_BODY_SIZE if the application sends larger messages.`).pipe(Effect.annotateLogs({ "rpc.maxBodySize": limit, "rpc.messageSize": size ?? "unknown", "url.path": route }));
|
|
33
|
+
}
|
|
34
|
+
// ws enforces the same limit as maxPayload and closes with 1009 before the frame reaches this reader; it reports no size.
|
|
35
|
+
function payloadRefused(error) {
|
|
36
|
+
const cause = error.reason._tag === "SocketReadError" ? error.reason.cause : undefined;
|
|
37
|
+
return (Predicate.hasProperty(cause, "error") && Predicate.hasProperty(cause.error, "code") && cause.error.code === "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");
|
|
38
|
+
}
|
|
29
39
|
//# sourceMappingURL=boundedRpcSocket.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"boundedRpcSocket.js","sourceRoot":"","sources":["../src/boundedRpcSocket.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"boundedRp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,EAAE,KAAa,EAAE,IAAwB;IACtE,OAAO,MAAM,CAAC,UAAU,CACvB,qBAAqB,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,GAAG,IAAI,QAAQ,iBAAiB,KAAK,uBAAuB,KAAK,8HAA8H,CAC1P,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,iBAAiB,EAAE,KAAK,EAAE,iBAAiB,EAAE,IAAI,IAAI,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;AACpH,CAAC;AAED,0HAA0H;AAC1H,SAAS,cAAc,CAAC,KAAyB;IAChD,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,KAAK,iBAAiB,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;IACvF,OAAO,CACN,SAAS,CAAC,WAAW,CAAC,KAAK,EAAE,OAAO,CAAC,IAAI,SAAS,CAAC,WAAW,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,IAAI,KAAK,mCAAmC,CAC/I,CAAC;AACH,CAAC"}
|
package/dist/hostRpcRoutes.js
CHANGED
|
@@ -44,7 +44,7 @@ function buildRpcRoutes(options, { bodySize, trustedProxy, nativeOrigins }, sens
|
|
|
44
44
|
yield* router.add("OPTIONS", options.rpcPath ?? "/rpc", HttpServerResponse.text("Local same-origin requests only", {
|
|
45
45
|
status: HttpStatus.fromLiteral("Forbidden"),
|
|
46
46
|
}));
|
|
47
|
-
yield* router.add("GET", options.rpcPath ?? "/rpc", () => boundedRpcSocket(bodySize).pipe(Effect.flatMap((request) => socketRpc(websocket, options, trustedProxy, nativeOrigins).pipe(Effect.provideService(HttpServerRequest.HttpServerRequest, request), Effect.provideService(RpcSerialization.RpcSerialization, wire)))));
|
|
47
|
+
yield* router.add("GET", options.rpcPath ?? "/rpc", () => boundedRpcSocket(bodySize, options.rpcPath ?? "/rpc").pipe(Effect.flatMap((request) => socketRpc(websocket, options, trustedProxy, nativeOrigins).pipe(Effect.provideService(HttpServerRequest.HttpServerRequest, request), Effect.provideService(RpcSerialization.RpcSerialization, wire)))));
|
|
48
48
|
yield* router.add("POST", options.rpcPath ?? "/rpc", () => boundedRpcRequest().pipe(Effect.flatMap((request) => guarded.pipe(Effect.provideService(HttpIncomingMessage.MaxBodySize, ByteSize.bytes(bodySize)), Effect.provideService(HttpServerRequest.HttpServerRequest, request), Effect.provideService(RpcSerialization.RpcSerialization, wire), HttpEffect.withPreResponseHandler(rpcCacheControl)))));
|
|
49
49
|
})).pipe(Layer.provide(Layer.merge(middleware, servedHandlers(options.group, options.handlers, options.config?.buildVersion))), Layer.provide(RpcSerialization.layerNdjson));
|
|
50
50
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hostRpcRoutes.js","sourceRoot":"","sources":["../src/hostRpcRoutes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,UAAU,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjH,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAA2B,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACvE,OAAO,EAAE,oBAAoB,EAAE,MAAM,6CAA6C,CAAC;AAEnF,OAAO,EAAE,aAAa,EAAE,MAAM,8CAA8C,CAAC;AAE7E,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,uCAAuC,CAAC;AACpG,OAAO,EAAE,oBAAoB,EAAE,MAAM,oDAAoD,CAAC;AAC1F,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,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iB,EAAE,OAAO,CAAC,EACnE,MAAM,CAAC,cAAc,CAAC,gBAAgB,CAAC,gBAAgB,EAAE,IAAI,CAAC,CAC9D,CACD,CACD,CACD,CAAC;QACF,KAAK,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,OAAO,IAAI,MAAM,EAAE,GAAG,EAAE,CACzD,iBAAiB,EAAE,CAAC,IAAI,CACvB,MAAM,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAC1B,OAAO,CAAC,IAAI,CACX,MAAM,CAAC,cAAc,CAAC,mBAAmB,CAAC,WAAW,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,EAChF,MAAM,CAAC,cAAc,CAAC,iBAAiB,CAAC,iBAAiB,EAAE,OAAO,CAAC,EACnE,MAAM,CAAC,cAAc,CAAC,gBAAgB,CAAC,gBAAgB,EAAE,IAAI,CAAC,EAC9D,UAAU,CAAC,sBAAsB,CAAC,eAAe,CAAC,CAClD,CACD,CACD,CACD,CAAC;IACH,CAAC,CAAC,CACF,CAAC,IAAI,CACL,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,UAAU,EAAE,cAAc,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,EACrH,KAAK,CAAC,OAAO,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAC3C,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shivaedev/server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.41.1",
|
|
4
4
|
"description": "The Effect application host: HTTP and RPC serving, health, OTLP export, database and migrations, and development mode",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"effect"
|
|
@@ -47,10 +47,10 @@
|
|
|
47
47
|
],
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"@shivaedev/changes": "0.14.1",
|
|
50
|
-
"@shivaedev/contract": "0.
|
|
50
|
+
"@shivaedev/contract": "0.56.0",
|
|
51
51
|
"@shivaedev/errors": "0.14.1",
|
|
52
52
|
"@shivaedev/http": "0.9.2",
|
|
53
|
-
"@shivaedev/identity": "0.38.
|
|
53
|
+
"@shivaedev/identity": "0.38.2",
|
|
54
54
|
"@shivaedev/local-postgres": "0.17.0",
|
|
55
55
|
"@shivaedev/sql": "0.54.0"
|
|
56
56
|
},
|
|
@@ -59,16 +59,16 @@
|
|
|
59
59
|
"@effect/sql-pg": "4.1.4",
|
|
60
60
|
"@effect/vitest": "4.1.4",
|
|
61
61
|
"@shivaedev/access": "0.7.0",
|
|
62
|
-
"@shivaedev/admin": "0.28.
|
|
62
|
+
"@shivaedev/admin": "0.28.3",
|
|
63
63
|
"@shivaedev/jobs": "0.44.0",
|
|
64
|
-
"@shivaedev/quality": "0.
|
|
64
|
+
"@shivaedev/quality": "0.83.1",
|
|
65
65
|
"@shivaedev/rate-limit": "0.8.0",
|
|
66
66
|
"@shivaedev/service": "0.9.2",
|
|
67
|
-
"@shivaedev/test-kits": "0.16.
|
|
67
|
+
"@shivaedev/test-kits": "0.16.2",
|
|
68
68
|
"@shivaedev/test-sql": "0.26.0",
|
|
69
|
-
"@shivaedev/test-story": "0.52.
|
|
69
|
+
"@shivaedev/test-story": "0.52.2",
|
|
70
70
|
"@types/node": "24.19.2",
|
|
71
|
-
"better-auth": "1.7.
|
|
71
|
+
"better-auth": "1.7.23",
|
|
72
72
|
"effect": "4.1.4",
|
|
73
73
|
"pg-boss": "12.38.2",
|
|
74
74
|
"typescript": "7.0.2",
|
|
@@ -78,8 +78,8 @@
|
|
|
78
78
|
"@effect/platform-node": "4.1.4",
|
|
79
79
|
"@effect/sql-pg": "4.1.4",
|
|
80
80
|
"@effect/vitest": "4.1.4",
|
|
81
|
-
"@shivaedev/admin": "0.28.
|
|
82
|
-
"better-auth": "1.7.
|
|
81
|
+
"@shivaedev/admin": "0.28.3",
|
|
82
|
+
"better-auth": "1.7.23",
|
|
83
83
|
"effect": "4.1.4"
|
|
84
84
|
},
|
|
85
85
|
"peerDependenciesMeta": {
|
package/src/boundedRpcSocket.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Effect } from "effect";
|
|
1
|
+
import { Effect, Predicate } from "effect";
|
|
2
2
|
import { HttpServerRequest } from "effect/http";
|
|
3
3
|
import * as Socket from "effect/socket/Socket";
|
|
4
4
|
|
|
5
|
-
export const boundedRpcSocket = Effect.fnUntraced(function* (limit: number) {
|
|
5
|
+
export const boundedRpcSocket = Effect.fnUntraced(function* (limit: number, route: string) {
|
|
6
6
|
const request = yield* HttpServerRequest.HttpServerRequest;
|
|
7
7
|
const upgrade = Effect.map(
|
|
8
8
|
request.upgrade,
|
|
@@ -13,15 +13,7 @@ export const boundedRpcSocket = Effect.fnUntraced(function* (limit: number) {
|
|
|
13
13
|
const writer = yield* socket.writer;
|
|
14
14
|
return {
|
|
15
15
|
...reader,
|
|
16
|
-
pull:
|
|
17
|
-
if (frames.every((frame) => (typeof frame === "string" ? Buffer.byteLength(frame) : frame.byteLength) <= limit)) {
|
|
18
|
-
return Effect.succeed(frames);
|
|
19
|
-
}
|
|
20
|
-
const reason = new Socket.SocketCloseError({ closeReason: "RPC frame exceeds maxBodySize", code: 1009 });
|
|
21
|
-
return writer
|
|
22
|
-
.write(new Socket.CloseEvent(reason.code, reason.closeReason))
|
|
23
|
-
.pipe(Effect.andThen(Effect.fail(new Socket.SocketError({ reason }))));
|
|
24
|
-
}),
|
|
16
|
+
pull: boundedPull(reader.pull, writer, limit, route),
|
|
25
17
|
};
|
|
26
18
|
}),
|
|
27
19
|
}),
|
|
@@ -30,3 +22,34 @@ export const boundedRpcSocket = Effect.fnUntraced(function* (limit: number) {
|
|
|
30
22
|
get: (target, key, receiver) => (key === "upgrade" ? upgrade : Reflect.get(target, key, receiver)),
|
|
31
23
|
});
|
|
32
24
|
});
|
|
25
|
+
|
|
26
|
+
function boundedPull(pull: Socket.Reader["pull"], writer: Effect.Success<Socket.Socket["writer"]>, limit: number, route: string) {
|
|
27
|
+
return pull.pipe(
|
|
28
|
+
Effect.tapError((error) => (payloadRefused(error) ? refused(limit, route, undefined) : Effect.void)),
|
|
29
|
+
Effect.flatMap((frames) => {
|
|
30
|
+
const size = frames.map((frame) => (typeof frame === "string" ? Buffer.byteLength(frame) : frame.byteLength)).find((bytes) => bytes > limit);
|
|
31
|
+
if (size === undefined) {
|
|
32
|
+
return Effect.succeed(frames);
|
|
33
|
+
}
|
|
34
|
+
const reason = new Socket.SocketCloseError({ closeReason: "RPC frame exceeds maxBodySize", code: 1009 });
|
|
35
|
+
return refused(limit, route, size).pipe(
|
|
36
|
+
Effect.andThen(writer.write(new Socket.CloseEvent(reason.code, reason.closeReason))),
|
|
37
|
+
Effect.andThen(Effect.fail(new Socket.SocketError({ reason }))),
|
|
38
|
+
);
|
|
39
|
+
}),
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function refused(limit: number, route: string, size: number | undefined) {
|
|
44
|
+
return Effect.logWarning(
|
|
45
|
+
`An RPC message of ${size === undefined ? "unknown size" : `${size} bytes`} exceeded the ${limit}-byte body limit at ${route}, so the host closed the socket with code 1009. Raise maxBodySize or MAX_BODY_SIZE if the application sends larger messages.`,
|
|
46
|
+
).pipe(Effect.annotateLogs({ "rpc.maxBodySize": limit, "rpc.messageSize": size ?? "unknown", "url.path": route }));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// ws enforces the same limit as maxPayload and closes with 1009 before the frame reaches this reader; it reports no size.
|
|
50
|
+
function payloadRefused(error: Socket.SocketError) {
|
|
51
|
+
const cause = error.reason._tag === "SocketReadError" ? error.reason.cause : undefined;
|
|
52
|
+
return (
|
|
53
|
+
Predicate.hasProperty(cause, "error") && Predicate.hasProperty(cause.error, "code") && cause.error.code === "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH"
|
|
54
|
+
);
|
|
55
|
+
}
|
package/src/hostRpcRoutes.ts
CHANGED
|
@@ -104,7 +104,7 @@ function buildRpcRoutes<TRpcs extends Rpc.Any, THandlers, TError, TRequirements,
|
|
|
104
104
|
}),
|
|
105
105
|
);
|
|
106
106
|
yield* router.add("GET", options.rpcPath ?? "/rpc", () =>
|
|
107
|
-
boundedRpcSocket(bodySize).pipe(
|
|
107
|
+
boundedRpcSocket(bodySize, options.rpcPath ?? "/rpc").pipe(
|
|
108
108
|
Effect.flatMap((request) =>
|
|
109
109
|
socketRpc(websocket, options, trustedProxy, nativeOrigins).pipe(
|
|
110
110
|
Effect.provideService(HttpServerRequest.HttpServerRequest, request),
|