@shivaedev/server 0.22.0 → 0.23.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 +11 -0
- package/README.md +35 -0
- package/dist/AppHostFactory.d.ts +2 -2
- package/dist/AppHostFactory.d.ts.map +1 -1
- package/dist/appHost.d.ts +3 -6
- package/dist/appHost.d.ts.map +1 -1
- package/dist/appHost.js +2 -2
- package/dist/appHost.js.map +1 -1
- package/dist/appHostHttp.d.ts +129 -75
- package/dist/appHostHttp.d.ts.map +1 -1
- package/dist/appHostHttp.js +5 -5
- package/dist/appHostHttp.js.map +1 -1
- package/dist/hostOptions.d.ts +11 -2
- package/dist/hostOptions.d.ts.map +1 -1
- package/dist/hostRpcRoutes.d.ts +18 -9
- package/dist/hostRpcRoutes.d.ts.map +1 -1
- package/dist/hostRpcRoutes.js +6 -3
- package/dist/hostRpcRoutes.js.map +1 -1
- package/dist/hostSensitiveKeys.d.ts +12 -0
- package/dist/hostSensitiveKeys.d.ts.map +1 -0
- package/dist/hostSensitiveKeys.js +8 -0
- package/dist/hostSensitiveKeys.js.map +1 -0
- package/dist/hostVersionLayer.d.ts +2 -0
- package/dist/hostVersionLayer.d.ts.map +1 -0
- package/dist/hostVersionLayer.js +8 -0
- package/dist/hostVersionLayer.js.map +1 -0
- package/package.json +10 -10
- package/src/AppHostFactory.ts +8 -8
- package/src/appHost.ts +21 -23
- package/src/appHostHttp.ts +5 -5
- package/src/hostOptions.ts +10 -6
- package/src/hostRpcRoutes.ts +7 -2
- package/src/hostSensitiveKeys.ts +11 -0
- package/src/hostVersionLayer.ts +8 -0
package/src/hostRpcRoutes.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { ByteSize, Effect, Layer } from "effect";
|
|
|
2
2
|
import { HttpEffect, HttpIncomingMessage, HttpRouter, HttpServerRequest, HttpServerResponse } from "effect/http";
|
|
3
3
|
import * as HttpStatus from "effect/http/HttpStatus";
|
|
4
4
|
import { type Rpc, type RpcGroup, RpcSerialization } from "effect/rpc";
|
|
5
|
+
import { HostVersion } from "@shivaedev/contract/HostVersion.ts";
|
|
5
6
|
import { validateReadPolicies } from "@shivaedev/contract/validateReadPolicies.ts";
|
|
6
7
|
import type { schemaSensitiveKeys } from "@shivaedev/errors/schemaSensitiveKeys.ts";
|
|
7
8
|
import { localRpcGuard } from "@shivaedev/identity/server/adapters/local.ts";
|
|
@@ -14,6 +15,7 @@ import { hostChanges } from "#hostChanges.ts";
|
|
|
14
15
|
import type { HostPolicy } from "#hostOptions.ts";
|
|
15
16
|
import { hostRpc, rpcCacheControl } from "#hostRpc.ts";
|
|
16
17
|
import type { hostTransport } from "#hostTransport.ts";
|
|
18
|
+
import { hostVersionLayer } from "#hostVersionLayer.ts";
|
|
17
19
|
import { redactingRpcSerialization } from "#redactingRpcSerialization.ts";
|
|
18
20
|
import { rpcRequestTracing } from "#rpcRequestTracing.ts";
|
|
19
21
|
import { socketRpc } from "#socketRpc.ts";
|
|
@@ -23,6 +25,7 @@ type BuiltRoutes<TRpcs extends Rpc.Any, THandlers, TError, TRequirements> = Retu
|
|
|
23
25
|
typeof buildRpcRoutes<TRpcs, THandlers, TError, TRequirements>
|
|
24
26
|
>;
|
|
25
27
|
type RouteOptions<TRpcs extends Rpc.Any, THandlers, TError, TRequirements> = {
|
|
28
|
+
readonly config?: { readonly buildVersion?: string };
|
|
26
29
|
readonly group: RpcGroup.RpcGroup<TRpcs>;
|
|
27
30
|
readonly handlers: Layer.Layer<THandlers, TError, TRequirements>;
|
|
28
31
|
readonly rpcPath?: HttpRouter.PathInput;
|
|
@@ -63,9 +66,10 @@ function buildRpcRoutes<TRpcs extends Rpc.Any, THandlers, TError, TRequirements>
|
|
|
63
66
|
Effect.gen(function* () {
|
|
64
67
|
yield* validateReadPolicies(options.group);
|
|
65
68
|
const wire = redactingRpcSerialization(yield* RpcSerialization.RpcSerialization, sensitive);
|
|
66
|
-
const
|
|
69
|
+
const group = options.group.merge(HostVersion.application);
|
|
70
|
+
const handler = yield* hostRpc(group).pipe(Effect.provideService(RpcSerialization.RpcSerialization, wire));
|
|
67
71
|
const guarded = Effect.flatMap(UnixSocketRequest, (unix) => (unix ? handler : localRpcGuard(handler, trustedProxy, nativeOrigins)));
|
|
68
|
-
const websocket = yield* hostRpc(
|
|
72
|
+
const websocket = yield* hostRpc(group, true).pipe(Effect.provideService(RpcSerialization.RpcSerialization, wire));
|
|
69
73
|
yield* router.add(
|
|
70
74
|
"OPTIONS",
|
|
71
75
|
options.rpcPath ?? "/rpc",
|
|
@@ -98,6 +102,7 @@ function buildRpcRoutes<TRpcs extends Rpc.Any, THandlers, TError, TRequirements>
|
|
|
98
102
|
}),
|
|
99
103
|
).pipe(
|
|
100
104
|
Layer.provide(Layer.merge(middleware, hostChanges(options.group).pipe(Layer.provideMerge(options.handlers)))),
|
|
105
|
+
Layer.provide(hostVersionLayer(options.config?.buildVersion)),
|
|
101
106
|
Layer.provide(RpcSerialization.layerNdjson),
|
|
102
107
|
);
|
|
103
108
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type Rpc, RpcGroup } from "effect/rpc";
|
|
2
|
+
import { schemaSensitiveKeys } from "@shivaedev/errors/schemaSensitiveKeys.ts";
|
|
3
|
+
|
|
4
|
+
export function hostSensitiveKeys<TRpcs extends Rpc.Any>(options: {
|
|
5
|
+
readonly group?: RpcGroup.RpcGroup<TRpcs>;
|
|
6
|
+
readonly config?: { readonly sensitiveKeys?: readonly string[] };
|
|
7
|
+
}) {
|
|
8
|
+
return options.group === undefined
|
|
9
|
+
? schemaSensitiveKeys(RpcGroup.make(), options.config?.sensitiveKeys)
|
|
10
|
+
: schemaSensitiveKeys(options.group, options.config?.sensitiveKeys);
|
|
11
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Stream } from "effect";
|
|
2
|
+
import { HostVersion } from "@shivaedev/contract/HostVersion.ts";
|
|
3
|
+
|
|
4
|
+
export function hostVersionLayer(version: string | undefined) {
|
|
5
|
+
return HostVersion.application.toLayer({
|
|
6
|
+
"platform.hostVersion.watch": () => (version === undefined ? Stream.never : Stream.concat(Stream.succeed(version), Stream.never)),
|
|
7
|
+
});
|
|
8
|
+
}
|