@shivaedev/server 0.42.0 → 0.44.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 +18 -0
- package/README.md +4 -4
- package/dist/HostModels.d.ts +9 -0
- package/dist/HostModels.d.ts.map +1 -0
- package/dist/HostModels.js +27 -0
- package/dist/HostModels.js.map +1 -0
- package/dist/appDatabase.d.ts +1 -2
- package/dist/appDatabase.d.ts.map +1 -1
- package/dist/appDatabase.js +7 -10
- package/dist/appDatabase.js.map +1 -1
- package/dist/appDatabaseHttp.d.ts +68 -68
- package/dist/appDatabaseHttp.d.ts.map +1 -1
- package/dist/appHost.d.ts +34 -34
- package/dist/appHost.d.ts.map +1 -1
- package/dist/appHost.js +3 -2
- package/dist/appHost.js.map +1 -1
- package/dist/appHostHttp.d.ts +34 -34
- package/dist/appHostHttp.d.ts.map +1 -1
- package/dist/defaultChangesChannel.d.ts +4 -0
- package/dist/defaultChangesChannel.d.ts.map +1 -0
- package/dist/defaultChangesChannel.js +8 -0
- package/dist/defaultChangesChannel.js.map +1 -0
- package/dist/hostCrypto.d.ts +4 -0
- package/dist/hostCrypto.d.ts.map +1 -0
- package/dist/hostCrypto.js +6 -0
- package/dist/hostCrypto.js.map +1 -0
- package/dist/hostPreflight.d.ts +5 -4
- package/dist/hostPreflight.d.ts.map +1 -1
- package/dist/hostPreflight.js.map +1 -1
- package/dist/hostSensitiveKeys.d.ts +2 -7
- package/dist/hostSensitiveKeys.d.ts.map +1 -1
- package/dist/hostSensitiveKeys.js +5 -12
- package/dist/hostSensitiveKeys.js.map +1 -1
- package/dist/nativeClientOrigins.d.ts.map +1 -1
- package/dist/nativeClientOrigins.js +3 -1
- package/dist/nativeClientOrigins.js.map +1 -1
- package/dist/providedModules.d.ts +2 -1
- package/dist/providedModules.d.ts.map +1 -1
- package/dist/redactedHost.d.ts +1 -1
- package/dist/redactedHost.d.ts.map +1 -1
- package/dist/redactedHost.js +3 -14
- package/dist/redactedHost.js.map +1 -1
- package/dist/workerHost.d.ts +1 -1
- package/dist/workerHost.d.ts.map +1 -1
- package/dist/workerHost.js +3 -2
- package/dist/workerHost.js.map +1 -1
- package/package.json +11 -11
- package/src/HostModels.ts +30 -0
- package/src/appDatabase.ts +7 -11
- package/src/appHost.ts +7 -2
- package/src/defaultChangesChannel.ts +8 -0
- package/src/hostCrypto.ts +6 -0
- package/src/hostPreflight.ts +6 -5
- package/src/hostSensitiveKeys.ts +5 -13
- package/src/nativeClientOrigins.ts +4 -1
- package/src/providedModules.ts +5 -1
- package/src/redactedHost.ts +2 -18
- package/src/workerHost.ts +3 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
2
|
import { type Rpc, RpcGroup } from "effect/rpc";
|
|
3
|
-
import {
|
|
3
|
+
import { HostModels } from "#HostModels.ts";
|
|
4
4
|
export declare const hostSensitiveKeys: <TRpcs extends Rpc.Any>(options: {
|
|
5
5
|
readonly group?: RpcGroup.RpcGroup<TRpcs>;
|
|
6
6
|
readonly config?: {
|
|
@@ -10,11 +10,6 @@ export declare const hostSensitiveKeys: <TRpcs extends Rpc.Any>(options: {
|
|
|
10
10
|
complete: Effect.Effect<void, import("@shivaedev/errors/wireMask.ts").InvalidRedactionMask | import("@shivaedev/errors/schemaFieldScope.ts").SensitiveFieldConflict, never>;
|
|
11
11
|
forRpc: (tag: string | undefined) => (key: string) => boolean;
|
|
12
12
|
maskFailure: (tag: string | undefined, reason: "Fail" | "Die") => boolean;
|
|
13
|
-
models: {
|
|
14
|
-
declare: (model: {
|
|
15
|
-
readonly ast: Parameters<typeof schemaFieldKeys>[0];
|
|
16
|
-
}) => Effect.Effect<void, never, never>;
|
|
17
|
-
};
|
|
18
13
|
redactFailure: (tag: string | undefined, reason: "Fail" | "Die", value: unknown) => unknown;
|
|
19
|
-
}, import("@shivaedev/errors/wireMask.ts").InvalidRedactionMask | import("@shivaedev/errors/schemaFieldScope.ts").SensitiveFieldConflict,
|
|
14
|
+
}, import("@shivaedev/errors/wireMask.ts").InvalidRedactionMask | import("@shivaedev/errors/schemaFieldScope.ts").SensitiveFieldConflict, HostModels>;
|
|
20
15
|
//# sourceMappingURL=hostSensitiveKeys.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hostSensitiveKeys.d.ts","sourceRoot":"","sources":["../src/hostSensitiveKeys.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAc,MAAM,QAAQ,CAAC;AAC5C,OAAO,EAAE,KAAK,GAAG,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"hostSensitiveKeys.d.ts","sourceRoot":"","sources":["../src/hostSensitiveKeys.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAc,MAAM,QAAQ,CAAC;AAC5C,OAAO,EAAE,KAAK,GAAG,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEhD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,eAAO,MAAM,iBAAiB,GAAgC,KAAK,SAAS,GAAG,CAAC,GAAG;qBACjE,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC;sBACvB;QAAE,QAAQ,CAAC,aAAa,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;KAAE;2BASxC,MAAM;;kBASf,MAAM,GAAG,SAAS,WAElB,MAAM;uBAED,MAAM,GAAG,SAAS,UAAU,MAAM,GAAG,KAAK;yBACxC,MAAM,GAAG,SAAS,UAAU,MAAM,GAAG,KAAK,SAAS,OAAO;qJAE/E,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Effect, MutableRef } from "effect";
|
|
2
2
|
import { RpcGroup } from "effect/rpc";
|
|
3
|
-
import { schemaFieldKeys } from "@shivaedev/errors/schemaFieldScope.ts";
|
|
4
3
|
import { schemaSensitiveKeys } from "@shivaedev/errors/schemaSensitiveKeys.ts";
|
|
4
|
+
import { HostModels } from "#HostModels.ts";
|
|
5
5
|
export const hostSensitiveKeys = Effect.fnUntraced(function* (options) {
|
|
6
6
|
const configured = options.config?.sensitiveKeys ?? [];
|
|
7
7
|
function policy(extra) {
|
|
@@ -9,25 +9,18 @@ export const hostSensitiveKeys = Effect.fnUntraced(function* (options) {
|
|
|
9
9
|
}
|
|
10
10
|
// Model names only widen masking, so the configured policy already holds the startup's conflict verdict.
|
|
11
11
|
const current = MutableRef.make(yield* policy(configured));
|
|
12
|
-
const
|
|
12
|
+
const { fieldNames } = yield* HostModels;
|
|
13
13
|
function sensitive(key) {
|
|
14
|
-
return
|
|
14
|
+
return fieldNames.has(key) || MutableRef.get(current)(key);
|
|
15
15
|
}
|
|
16
16
|
return Object.assign(sensitive, {
|
|
17
17
|
// Repositories declare their models while the host builds them; complete recompiles every RPC's policy with their names, as config.sensitiveKeys.
|
|
18
|
-
complete: Effect.suspend(() => policy([...configured, ...
|
|
18
|
+
complete: Effect.suspend(() => policy([...configured, ...fieldNames])).pipe(Effect.map((completed) => MutableRef.set(current, completed)), Effect.asVoid),
|
|
19
19
|
forRpc: (tag) => {
|
|
20
20
|
const forTag = MutableRef.get(current).forRpc(tag);
|
|
21
|
-
return (key) =>
|
|
21
|
+
return (key) => fieldNames.has(key) || forTag(key);
|
|
22
22
|
},
|
|
23
23
|
maskFailure: (tag, reason) => MutableRef.get(current).maskFailure(tag, reason),
|
|
24
|
-
models: {
|
|
25
|
-
declare: (model) => Effect.sync(() => {
|
|
26
|
-
for (const key of schemaFieldKeys(model.ast, [])) {
|
|
27
|
-
models.add(key);
|
|
28
|
-
}
|
|
29
|
-
}),
|
|
30
|
-
},
|
|
31
24
|
redactFailure: (tag, reason, value) => MutableRef.get(current).redactFailure(tag, reason, value),
|
|
32
25
|
});
|
|
33
26
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hostSensitiveKeys.js","sourceRoot":"","sources":["../src/hostSensitiveKeys.ts"],"names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AAE;QAC/B,kJAAkJ;QAClJ,QAAQ,EAAE,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC,GAAG,UAAU,EAAE,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC,IAAI,CAC1E,MAAM,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC,EAC7D,MAAM,CAAC,MAAM,CACb;QACD,MAAM,EAAE,CAAC,GAAuB,EAAE,EAAE;YACnC,MAAM,MAAM,GAAG,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACnD,OAAO,CAAC,GAAW,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC;QAC5D,CAAC;QACD,WAAW,EAAE,CAAC,GAAuB,EAAE,MAAsB,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,WAAW,CAAC,GAAG,EAAE,MAAM,CAAC;QAClH,aAAa,EAAE,CAAC,GAAuB,EAAE,MAAsB,EAAE,KAAc,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC;KAC7I,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nativeClientOrigins.d.ts","sourceRoot":"","sources":["../src/nativeClientOrigins.ts"],"names":[],"mappings":"AACA,OAAO,EAA2B,UAAU,EAAyC,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"nativeClientOrigins.d.ts","sourceRoot":"","sources":["../src/nativeClientOrigins.ts"],"names":[],"mappings":"AACA,OAAO,EAA2B,UAAU,EAAyC,MAAM,aAAa,CAAC;AAMzG,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,EAAE,KAAK,EAAE,MAAM,GAAG,KAAK,EAAE,OAAO,GAAE,UAAU,CAAC,SAAkB,qDAsBlI"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Effect, Option } from "effect";
|
|
2
2
|
import { Headers, HttpMiddleware, HttpRouter, HttpServerRequest, HttpServerResponse } from "effect/http";
|
|
3
3
|
import * as HttpStatus from "effect/http/HttpStatus";
|
|
4
|
+
import { accountPreferenceHeaders } from "@shivaedev/identity/accountPreferenceHeaders.ts";
|
|
4
5
|
import { localTransport } from "@shivaedev/identity/server/adapters/local.ts";
|
|
5
6
|
import { SessionPolicy } from "@shivaedev/identity/server/SessionPolicy.ts";
|
|
6
7
|
export function nativeClientOrigins(trustedProxy, route, rpcPath = "/rpc") {
|
|
@@ -24,6 +25,7 @@ export function nativeClientOrigins(trustedProxy, route, rpcPath = "/rpc") {
|
|
|
24
25
|
return yield* withClientCors(effect, native, declared, auth);
|
|
25
26
|
})).layer;
|
|
26
27
|
}
|
|
28
|
+
const CLIENT_HEADERS = ["Authorization", "Content-Type"];
|
|
27
29
|
const withClientCors = Effect.fnUntraced(function* (effect, nativeOrigins, declared, auth) {
|
|
28
30
|
const request = yield* HttpServerRequest.HttpServerRequest;
|
|
29
31
|
const origin = request.headers.origin ?? "";
|
|
@@ -34,7 +36,7 @@ const withClientCors = Effect.fnUntraced(function* (effect, nativeOrigins, decla
|
|
|
34
36
|
}
|
|
35
37
|
const transport = native ? request.modify({ headers: Headers.remove(request.headers, "cookie") }) : request;
|
|
36
38
|
return yield* HttpMiddleware.cors({
|
|
37
|
-
allowedHeaders: [
|
|
39
|
+
allowedHeaders: auth ? [...CLIENT_HEADERS, ...Object.values(accountPreferenceHeaders)] : CLIENT_HEADERS,
|
|
38
40
|
allowedMethods: auth ? ["GET", "POST"] : ["POST"],
|
|
39
41
|
allowedOrigins: [origin],
|
|
40
42
|
credentials: credentialed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AAC,iBAAiB,EAAE,SAAS,CAAC,CAAC,CAAC;AACxF,CAAC,CAAC,CAAC"}
|
|
@@ -2,6 +2,7 @@ import type { Layer } from "effect";
|
|
|
2
2
|
import type { AnyModule } from "@shivaedev/contract/moduleHandlers.ts";
|
|
3
3
|
import type { AppModule } from "#AppModule.ts";
|
|
4
4
|
import type { appDatabase } from "#appDatabase.ts";
|
|
5
|
+
import type { hostCrypto } from "#hostCrypto.ts";
|
|
5
6
|
import type { hostHttpServices } from "#hostHttpServices.ts";
|
|
6
7
|
export interface OperationServicesNotProvided<TModule extends string, TOperation extends PropertyKey, TMissing> {
|
|
7
8
|
readonly missingServices: TMissing;
|
|
@@ -9,7 +10,7 @@ export interface OperationServicesNotProvided<TModule extends string, TOperation
|
|
|
9
10
|
readonly operation: TOperation;
|
|
10
11
|
readonly problem: "run or readPolicy uses services that no registration's services, ports or requestServices provide and the host does not provide";
|
|
11
12
|
}
|
|
12
|
-
type HostServices = Layer.Success<ReturnType<typeof appDatabase<never, never>>> | Layer.Success<typeof hostHttpServices>;
|
|
13
|
+
type HostServices = Layer.Success<ReturnType<typeof appDatabase<never, never>>> | Layer.Success<typeof hostCrypto> | Layer.Success<typeof hostHttpServices>;
|
|
13
14
|
type Field<TModule, TKey extends PropertyKey> = TModule extends unknown ? (TKey extends keyof TModule ? TModule[TKey] : never) : never;
|
|
14
15
|
type Provided<TModules extends readonly AppModule[]> = Layer.Success<Extract<Field<TModules[number], "services" | "ports" | "requestServices">, Layer.Any>> | HostServices;
|
|
15
16
|
type Unprovided<TDefined extends AnyModule, TProvided> = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"providedModules.d.ts","sourceRoot":"","sources":["../src/providedModules.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uCAAuC,CAAC;AACvE,OAAO,KAAK,EAAE,SAAS,EAAE,M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AI,OAAO,SAAS;IAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,QAAQ,SAAS,SAAS,CAAA;CAAE,GAC5G,KAAK,CAAC,UAAU,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC,GACtC,KAAK,CAAC;AAGT,MAAM,MAAM,eAAe,CAAC,QAAQ,SAAS,SAAS,SAAS,EAAE,IAAI,MAAM,SAAS,QAAQ,CAAC,QAAQ,CAAC,GACnG,OAAO,GACP,CAAC,cAAc,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GACrE,OAAO,GACP,cAAc,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC"}
|
package/dist/redactedHost.d.ts
CHANGED
|
@@ -7,5 +7,5 @@ export declare function redactedHost<TRpcs extends Rpc.Any, A, E, R>(options: {
|
|
|
7
7
|
readonly config?: {
|
|
8
8
|
readonly sensitiveKeys?: readonly string[];
|
|
9
9
|
};
|
|
10
|
-
}, host: (sensitive: HostSensitivePolicy) => Layer.Layer<A, E, R>): Layer.Layer<A, E | import("effect/Config").ConfigError | import("@shivaedev/errors/wireMask.ts").InvalidRedactionMask | import("@shivaedev/errors/schemaFieldScope.ts").SensitiveFieldConflict, Exclude<Exclude<Exclude<
|
|
10
|
+
}, host: (sensitive: HostSensitivePolicy) => Layer.Layer<A, E, R>): Layer.Layer<A, E | import("effect/Config").ConfigError | import("@shivaedev/errors/wireMask.ts").InvalidRedactionMask | import("@shivaedev/errors/schemaFieldScope.ts").SensitiveFieldConflict, import("./HostModels.ts").HostModels | Exclude<Exclude<Exclude<R, never>, never>, never>>;
|
|
11
11
|
//# sourceMappingURL=redactedHost.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redactedHost.d.ts","sourceRoot":"","sources":["../src/redactedHost.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"redactedHost.d.ts","sourceRoot":"","sources":["../src/redactedHost.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEhD,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAI1D,MAAM,MAAM,mBAAmB,GAAG,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,iBAAiB,CAAC,CAAC,CAAC;AAGvF,wBAAgB,YAAY,CAAC,KAAK,SAAS,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAC1D,OAAO,EAAE;IAAE,QAAQ,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;QAAE,QAAQ,CAAC,aAAa,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;KAAE,CAAA;CAAE,EACxH,IAAI,EAAE,CAAC,SAAS,EAAE,mBAAmB,KAAK,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,6RAW9D"}
|
package/dist/redactedHost.js
CHANGED
|
@@ -1,21 +1,10 @@
|
|
|
1
|
-
import { Effect, Layer
|
|
2
|
-
import { collectRepositoryModels, RepositoryModels } from "@shivaedev/sql/RepositoryModels.ts";
|
|
1
|
+
import { Effect, Layer } from "effect";
|
|
3
2
|
import { redactingDiagnostics } from "#adapters/redactingDiagnostics.ts";
|
|
4
3
|
import { hostSensitiveKeys } from "#hostSensitiveKeys.ts";
|
|
5
4
|
import { otlpTracing } from "#otlpTracing.ts";
|
|
6
5
|
import { RedactionPolicy } from "#RedactionPolicy.ts";
|
|
7
|
-
//
|
|
8
|
-
function maskedModels(sensitive) {
|
|
9
|
-
return Layer.effect(RepositoryModels, Effect.gen(function* () {
|
|
10
|
-
const collected = yield* RepositoryModels;
|
|
11
|
-
return RepositoryModels.of({
|
|
12
|
-
declare: (declared) => Effect.andThen(sensitive.models.declare(Schema.Struct(declared.model.fields)), collected.declare(declared)),
|
|
13
|
-
owned: collected.owned,
|
|
14
|
-
});
|
|
15
|
-
})).pipe(Layer.provide(collectRepositoryModels));
|
|
16
|
-
}
|
|
17
|
-
// Both hosts build their process inside one policy, so repositories declare their models to the same policy that masks every log, error report and exported span.
|
|
6
|
+
// Both hosts build their process inside one policy, so every log, error report and exported span masks the same names, including the fields their repositories' models declare.
|
|
18
7
|
export function redactedHost(options, host) {
|
|
19
|
-
return Layer.unwrap(Effect.map(hostSensitiveKeys(options), (sensitive) => host(sensitive).pipe(Layer.provide(redactingDiagnostics(sensitive)), Layer.provide(otlpTracing), Layer.provide(Layer.succeed(RedactionPolicy, sensitive))
|
|
8
|
+
return Layer.unwrap(Effect.map(hostSensitiveKeys(options), (sensitive) => host(sensitive).pipe(Layer.provide(redactingDiagnostics(sensitive)), Layer.provide(otlpTracing), Layer.provide(Layer.succeed(RedactionPolicy, sensitive)))));
|
|
20
9
|
}
|
|
21
10
|
//# sourceMappingURL=redactedHost.js.map
|
package/dist/redactedHost.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redactedHost.js","sourceRoot":"","sources":["../src/redactedHost.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"redactedHost.js","sourceRoot":"","sources":["../src/redactedHost.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAEvC,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAItD,gLAAgL;AAChL,MAAM,UAAU,YAAY,CAC3B,OAAwH,EACxH,IAA8D;IAE9D,OAAO,KAAK,CAAC,MAAM,CAClB,MAAM,CAAC,GAAG,CAAC,iBAAiB,CAAC,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,EAAE,CACpD,IAAI,CAAC,SAAS,CAAC,CAAC,IAAI,CACnB,KAAK,CAAC,OAAO,CAAC,oBAAoB,CAAC,SAAS,CAAC,CAAC,EAC9C,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,EAC1B,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,eAAe,EAAE,SAAS,CAAC,CAAC,CACxD,CACD,CACD,CAAC;AACH,CAAC"}
|
package/dist/workerHost.d.ts
CHANGED
|
@@ -7,5 +7,5 @@ export declare function workerHost<R, E, TRequirements, TServices, TServiceError
|
|
|
7
7
|
readonly config?: WorkerHostConfig;
|
|
8
8
|
readonly workers: Layer.Layer<R, E, TRequirements>;
|
|
9
9
|
readonly services: Layer.Layer<TServices, TServiceError, TServiceRequirements>;
|
|
10
|
-
}): Layer.Layer<"@shivaedev/contract/LiveServer" | R | TServices | import("@effect/sql-pg/PgClient").PgClient | import("@effect/sql-pg/PgPool").PgPool | import("effect/reactivity/Reactivity").Reactivity | import("effect/sql/SqlClient").SqlClient, E | TMigrationError | TServiceError | import("effect/Config").ConfigError | import("@shivaedev/errors/wireMask.ts").InvalidRedactionMask | import("effect/sql/Migrator").MigrationError | import("@shivaedev/sql/PostgresListenerError.ts").PostgresListenerError | import("effect/Schema").SchemaError | import("@shivaedev/errors/schemaFieldScope.ts").SensitiveFieldConflict | import("effect/sql/SqlError").SqlError, Exclude<Exclude<Exclude<Exclude<Exclude<Exclude<TServiceRequirements, "@shivaedev/contract/LiveServer" | import("@effect/sql-pg/PgClient").PgClient | import("@effect/sql-pg/PgPool").PgPool | import("effect/reactivity/Reactivity").Reactivity | import("effect/sql/SqlClient").SqlClient>, never>, never>, never>,
|
|
10
|
+
}): Layer.Layer<"@shivaedev/contract/LiveServer" | R | TServices | import("@effect/sql-pg/PgClient").PgClient | import("@effect/sql-pg/PgPool").PgPool | import("effect/reactivity/Reactivity").Reactivity | import("effect/sql/SqlClient").SqlClient, E | TMigrationError | TServiceError | import("effect/Config").ConfigError | import("@shivaedev/errors/wireMask.ts").InvalidRedactionMask | import("effect/sql/Migrator").MigrationError | import("@shivaedev/sql/PostgresListenerError.ts").PostgresListenerError | import("effect/Schema").SchemaError | import("@shivaedev/errors/schemaFieldScope.ts").SensitiveFieldConflict | import("effect/sql/SqlError").SqlError, Exclude<Exclude<Exclude<Exclude<Exclude<Exclude<TServiceRequirements, "@shivaedev/contract/LiveServer" | import("@effect/sql-pg/PgClient").PgClient | import("@effect/sql-pg/PgPool").PgPool | import("effect/reactivity/Reactivity").Reactivity | import("effect/sql/SqlClient").SqlClient>, never>, never>, never>, import("effect/crypto/Aead").Aead | import("effect/crypto/Cipher").Cipher | import("@shivaedev/sql/ColumnKey.ts").ColumnKey | import("effect/crypto/Digest").Digest | import("effect/crypto/Kdf").Kdf | import("effect/crypto/KeyAgreement").KeyAgreement | import("effect/crypto/KeyWrap").KeyWrap | import("effect/crypto/Mac").Mac | import("effect/crypto/SecureRandom").SecureRandom | import("effect/crypto/Signature").Signature>, import("#HostModels.ts").HostModels> | Exclude<Exclude<Exclude<Exclude<Exclude<Exclude<Exclude<TMigrations, import("effect/Scope").Scope>, "@shivaedev/contract/LiveServer" | import("@effect/sql-pg/PgClient").PgClient | import("@effect/sql-pg/PgPool").PgPool | import("effect/reactivity/Reactivity").Reactivity | import("effect/sql/SqlClient").SqlClient>, never>, never>, never>, import("effect/crypto/Aead").Aead | import("effect/crypto/Cipher").Cipher | import("@shivaedev/sql/ColumnKey.ts").ColumnKey | import("effect/crypto/Digest").Digest | import("effect/crypto/Kdf").Kdf | import("effect/crypto/KeyAgreement").KeyAgreement | import("effect/crypto/KeyWrap").KeyWrap | import("effect/crypto/Mac").Mac | import("effect/crypto/SecureRandom").SecureRandom | import("effect/crypto/Signature").Signature>, import("#HostModels.ts").HostModels> | Exclude<Exclude<Exclude<Exclude<Exclude<Exclude<Exclude<TRequirements, TServices>, "@shivaedev/contract/LiveServer" | import("@effect/sql-pg/PgClient").PgClient | import("@effect/sql-pg/PgPool").PgPool | import("effect/reactivity/Reactivity").Reactivity | import("effect/sql/SqlClient").SqlClient>, never>, never>, never>, import("effect/crypto/Aead").Aead | import("effect/crypto/Cipher").Cipher | import("@shivaedev/sql/ColumnKey.ts").ColumnKey | import("effect/crypto/Digest").Digest | import("effect/crypto/Kdf").Kdf | import("effect/crypto/KeyAgreement").KeyAgreement | import("effect/crypto/KeyWrap").KeyWrap | import("effect/crypto/Mac").Mac | import("effect/crypto/SecureRandom").SecureRandom | import("effect/crypto/Signature").Signature>, import("#HostModels.ts").HostModels>>;
|
|
11
11
|
//# sourceMappingURL=workerHost.d.ts.map
|
package/dist/workerHost.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workerHost.d.ts","sourceRoot":"","sources":["../src/workerHost.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"workerHost.d.ts","sourceRoot":"","sources":["../src/workerHost.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,EAAE,KAAK,kBAAkB,EAAe,KAAK,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAK5F,MAAM,WAAW,gBAAiB,SAAQ,cAAc;IACvD,QAAQ,CAAC,aAAa,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC3C;AAED,wBAAgB,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,aAAa,EAAE,SAAS,EAAE,aAAa,EAAE,oBAAoB,EAAE,WAAW,GAAG,KAAK,EAAE,eAAe,GAAG,KAAK,EAC3I,OAAO,EAAE,kBAAkB,CAAC,WAAW,EAAE,eAAe,CAAC,GAAG;IAC3D,QAAQ,CAAC,MAAM,CAAC,EAAE,gBAAgB,CAAC;IACnC,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,aAAa,CAAC,CAAC;IACnD,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC,KAAK,CAAC,SAAS,EAAE,aAAa,EAAE,oBAAoB,CAAC,CAAC;CAC/E,g9FAWD"}
|
package/dist/workerHost.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
|
|
2
1
|
import { Effect, Layer } from "effect";
|
|
3
2
|
import { appDatabase } from "#appDatabase.ts";
|
|
3
|
+
import { hostModels } from "#HostModels.ts";
|
|
4
|
+
import { hostCrypto } from "#hostCrypto.ts";
|
|
4
5
|
import { redactedHost } from "#redactedHost.ts";
|
|
5
6
|
export function workerHost(options) {
|
|
6
7
|
// A worker serves no RPC group, so its policy holds the built-in rules, config.sensitiveKeys and the models its repositories declare as they are built.
|
|
7
8
|
// The host announces readiness itself: an effect composed around the returned Layer runs outside its policy and exporter.
|
|
8
|
-
return redactedHost(options, () => Layer.effectDiscard(Effect.logInfo("Worker ready to take jobs")).pipe(Layer.provideMerge(options.workers), Layer.provideMerge(options.services), Layer.provideMerge(appDatabase(options)))).pipe(Layer.provide(
|
|
9
|
+
return redactedHost(options, () => Layer.effectDiscard(Effect.logInfo("Worker ready to take jobs")).pipe(Layer.provideMerge(options.workers), Layer.provideMerge(options.services), Layer.provideMerge(appDatabase(options)))).pipe(Layer.provide(hostCrypto), Layer.provide(hostModels()));
|
|
9
10
|
}
|
|
10
11
|
//# sourceMappingURL=workerHost.js.map
|
package/dist/workerHost.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workerHost.js","sourceRoot":"","sources":["../src/workerHost.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"workerHost.js","sourceRoot":"","sources":["../src/workerHost.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,EAA2B,WAAW,EAAuB,MAAM,iBAAiB,CAAC;AAC5F,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAMhD,MAAM,UAAU,UAAU,CACzB,OAIC;IAED,wJAAwJ;IACxJ,0HAA0H;IAC1H,OAAO,YAAY,CAAC,OAAO,EAAE,GAAG,EAAE,CACjC,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,OAAO,CAAC,2BAA2B,CAAC,CAAC,CAAC,IAAI,CACpE,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,EACnC,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC,QAAQ,CAAC,EACpC,KAAK,CAAC,YAAY,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CACxC,CACD,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC;AAChE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shivaedev/server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.44.0",
|
|
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"
|
|
@@ -50,23 +50,23 @@
|
|
|
50
50
|
"@shivaedev/contract": "0.58.0",
|
|
51
51
|
"@shivaedev/errors": "0.14.1",
|
|
52
52
|
"@shivaedev/http": "0.9.2",
|
|
53
|
-
"@shivaedev/identity": "0.
|
|
53
|
+
"@shivaedev/identity": "0.41.0",
|
|
54
54
|
"@shivaedev/local-postgres": "0.17.0",
|
|
55
|
-
"@shivaedev/sql": "0.
|
|
55
|
+
"@shivaedev/sql": "0.55.0"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@effect/platform-node": "4.1.4",
|
|
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.29.
|
|
63
|
-
"@shivaedev/jobs": "0.44.
|
|
64
|
-
"@shivaedev/quality": "0.
|
|
65
|
-
"@shivaedev/rate-limit": "0.8.
|
|
62
|
+
"@shivaedev/admin": "0.29.3",
|
|
63
|
+
"@shivaedev/jobs": "0.44.1",
|
|
64
|
+
"@shivaedev/quality": "0.84.0",
|
|
65
|
+
"@shivaedev/rate-limit": "0.8.1",
|
|
66
66
|
"@shivaedev/service": "0.9.2",
|
|
67
|
-
"@shivaedev/test-kits": "0.16.
|
|
68
|
-
"@shivaedev/test-sql": "0.26.
|
|
69
|
-
"@shivaedev/test-story": "0.52.
|
|
67
|
+
"@shivaedev/test-kits": "0.16.6",
|
|
68
|
+
"@shivaedev/test-sql": "0.26.1",
|
|
69
|
+
"@shivaedev/test-story": "0.52.5",
|
|
70
70
|
"@types/node": "24.19.2",
|
|
71
71
|
"better-auth": "1.7.23",
|
|
72
72
|
"effect": "4.1.4",
|
|
@@ -78,7 +78,7 @@
|
|
|
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.29.
|
|
81
|
+
"@shivaedev/admin": "0.29.3",
|
|
82
82
|
"better-auth": "1.7.23",
|
|
83
83
|
"effect": "4.1.4"
|
|
84
84
|
},
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Context, Effect, Layer, Schema } from "effect";
|
|
2
|
+
import { schemaFieldKeys } from "@shivaedev/errors/schemaFieldScope.ts";
|
|
3
|
+
import { collectRepositoryModels, type RepositoryModel, RepositoryModels } from "@shivaedev/sql/RepositoryModels.ts";
|
|
4
|
+
|
|
5
|
+
// The field names of every model the host's repositories declare, which its redaction policy masks.
|
|
6
|
+
export class HostModels extends Context.Service<HostModels, { readonly fieldNames: ReadonlySet<string> }>()("@shivaedev/server/HostModels") {}
|
|
7
|
+
|
|
8
|
+
function recordFields(fieldNames: Set<string>, { model }: RepositoryModel) {
|
|
9
|
+
return Effect.sync(() => {
|
|
10
|
+
for (const key of schemaFieldKeys(Schema.Struct(model.fields).ast, [])) {
|
|
11
|
+
fieldNames.add(key);
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Each host provides its own collector around everything it builds, including a deferred application Effect, so a
|
|
17
|
+
// repository built there reports its owned models and sensitive fields to the same host that serves and masks them.
|
|
18
|
+
export function hostModels() {
|
|
19
|
+
return Layer.effectContext(
|
|
20
|
+
Effect.gen(function* () {
|
|
21
|
+
const collected = yield* RepositoryModels;
|
|
22
|
+
const fieldNames = new Set<string>();
|
|
23
|
+
const models = RepositoryModels.of({
|
|
24
|
+
declare: (declared) => Effect.andThen(recordFields(fieldNames, declared), collected.declare(declared)),
|
|
25
|
+
owned: collected.owned,
|
|
26
|
+
});
|
|
27
|
+
return Context.make(HostModels, { fieldNames }).pipe(Context.add(RepositoryModels, models));
|
|
28
|
+
}),
|
|
29
|
+
).pipe(Layer.provide(Layer.fresh(collectRepositoryModels)));
|
|
30
|
+
}
|
package/src/appDatabase.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
|
|
2
1
|
import * as PgClient from "@effect/sql-pg/PgClient";
|
|
3
2
|
import { Clock, Config, Context, Effect, Layer, Option, Redacted } from "effect";
|
|
4
|
-
import { Digest } from "effect/crypto";
|
|
5
3
|
import * as Reactivity from "effect/reactivity/Reactivity";
|
|
6
4
|
import type { Rpc } from "effect/rpc";
|
|
7
5
|
import { liveServerLayer } from "@shivaedev/contract/live-server/layer.ts";
|
|
@@ -16,6 +14,9 @@ import type { AppHostFactory } from "#AppHostFactory.ts";
|
|
|
16
14
|
import type { AppHostInput } from "#AppHostInput.ts";
|
|
17
15
|
import { deferredHost, migratedHost } from "#appDatabaseHttp.ts";
|
|
18
16
|
import { appHostHttp } from "#appHostHttp.ts";
|
|
17
|
+
import { defaultChangesChannel } from "#defaultChangesChannel.ts";
|
|
18
|
+
import { hostModels } from "#HostModels.ts";
|
|
19
|
+
import { hostCrypto } from "#hostCrypto.ts";
|
|
19
20
|
import type { HostRouteRequirements } from "#hostOptions.ts";
|
|
20
21
|
import { hostPreflight } from "#hostPreflight.ts";
|
|
21
22
|
import { hostSensitiveKeys } from "#hostSensitiveKeys.ts";
|
|
@@ -90,12 +91,6 @@ export function appDatabase<R, E = never>(options: AppDatabaseOptions<R, E>) {
|
|
|
90
91
|
return worker.pipe(Layer.provideMerge(prepared));
|
|
91
92
|
}
|
|
92
93
|
|
|
93
|
-
const defaultChangesChannel = Effect.fnUntraced(function* (name: string) {
|
|
94
|
-
const digest = yield* Digest.Digest;
|
|
95
|
-
const hash = yield* digest.digestHex(Digest.sha256, new TextEncoder().encode(name));
|
|
96
|
-
return `changes_${hash.slice(0, 32)}`;
|
|
97
|
-
});
|
|
98
|
-
|
|
99
94
|
export const appHost: AppHostFactory = <
|
|
100
95
|
TRpcs extends Rpc.Any = never,
|
|
101
96
|
THandlers = never,
|
|
@@ -138,13 +133,14 @@ export const appHost: AppHostFactory = <
|
|
|
138
133
|
>,
|
|
139
134
|
) => {
|
|
140
135
|
const preflight = hostPreflight(options.preflight, "application" in options ? Effect.succeed(isSensitiveKey) : hostSensitiveKeys(options));
|
|
136
|
+
const hosted = Layer.merge(hostCrypto, hostModels());
|
|
141
137
|
if ("application" in options) {
|
|
142
|
-
return deferredHost(options.application, appDatabase(options)).pipe(Layer.provideMerge(preflight), Layer.provide(
|
|
138
|
+
return deferredHost(options.application, appDatabase(options)).pipe(Layer.provideMerge(preflight), Layer.provide(hosted));
|
|
143
139
|
}
|
|
144
140
|
return options.migrations === undefined
|
|
145
|
-
? appHostHttp(options).pipe(Layer.provideMerge(preflight), Layer.provide(
|
|
141
|
+
? appHostHttp(options).pipe(Layer.provideMerge(preflight), Layer.provide(hosted))
|
|
146
142
|
: migratedHost({ ...options, migrations: options.migrations }, appDatabase({ ...options, migrations: options.migrations })).pipe(
|
|
147
143
|
Layer.provideMerge(preflight),
|
|
148
|
-
Layer.provide(
|
|
144
|
+
Layer.provide(hosted),
|
|
149
145
|
);
|
|
150
146
|
};
|
package/src/appHost.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
|
|
2
1
|
import { Layer } from "effect";
|
|
3
2
|
import type { Rpc } from "effect/rpc";
|
|
4
3
|
import { appHostHttp } from "#appHostHttp.ts";
|
|
4
|
+
import { hostModels } from "#HostModels.ts";
|
|
5
|
+
import { hostCrypto } from "#hostCrypto.ts";
|
|
5
6
|
import type { HostCoreOptions, HostPolicy, HostRouteRequirements, HostRoutes } from "#hostOptions.ts";
|
|
6
7
|
import type { HostPreflight } from "#hostPreflight.ts";
|
|
7
8
|
import { hostPreflight } from "#hostPreflight.ts";
|
|
@@ -69,7 +70,11 @@ function buildHttpHost<
|
|
|
69
70
|
TRequestRequirements
|
|
70
71
|
>,
|
|
71
72
|
) {
|
|
72
|
-
return appHostHttp(options).pipe(
|
|
73
|
+
return appHostHttp(options).pipe(
|
|
74
|
+
Layer.provideMerge(hostPreflight(options.preflight, hostSensitiveKeys(options))),
|
|
75
|
+
Layer.provide(hostCrypto),
|
|
76
|
+
Layer.provide(hostModels()),
|
|
77
|
+
);
|
|
73
78
|
}
|
|
74
79
|
|
|
75
80
|
type HttpHostFactory = <
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { Digest } from "effect/crypto";
|
|
3
|
+
|
|
4
|
+
export const defaultChangesChannel = Effect.fnUntraced(function* (name: string) {
|
|
5
|
+
const digest = yield* Digest.Digest;
|
|
6
|
+
const hash = yield* digest.digestHex(Digest.sha256, new TextEncoder().encode(name));
|
|
7
|
+
return `changes_${hash.slice(0, 32)}`;
|
|
8
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
|
|
2
|
+
import { Layer } from "effect";
|
|
3
|
+
import { ColumnKey } from "@shivaedev/sql/ColumnKey.ts";
|
|
4
|
+
|
|
5
|
+
// The column key reads COLUMN_ENCRYPTION_KEY only when an encrypted field is first sealed or opened, so a host without encrypted fields needs no key.
|
|
6
|
+
export const hostCrypto = Layer.merge(NodeCrypto.layer, ColumnKey.fromConfig);
|
package/src/hostPreflight.ts
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
|
-
import type * as NodeCrypto from "@effect/platform-node/NodeCrypto";
|
|
2
1
|
import { Effect, Layer } from "effect";
|
|
3
2
|
import { redactingDiagnostics } from "#adapters/redactingDiagnostics.ts";
|
|
3
|
+
import type { HostModels } from "#HostModels.ts";
|
|
4
|
+
import type { hostCrypto } from "#hostCrypto.ts";
|
|
4
5
|
|
|
5
6
|
export type HostPreflight<TServices = never, TError = never, TRequirements = never> =
|
|
6
7
|
| { readonly preflight: Layer.Layer<TServices, TError, TRequirements> }
|
|
7
8
|
| ([TServices | TError | TRequirements] extends [never] ? { readonly preflight?: never } : never);
|
|
8
9
|
|
|
9
|
-
type HostCrypto = Layer.Success<typeof
|
|
10
|
+
type HostCrypto = Layer.Success<typeof hostCrypto>;
|
|
10
11
|
|
|
11
12
|
export type PreflightHost<THost extends Layer.Any, TServices, TError, TRequirements> = Layer.Layer<
|
|
12
13
|
Layer.Success<THost> | TServices,
|
|
13
14
|
Layer.Error<THost> | TError,
|
|
14
|
-
Exclude<Layer.Services<THost>, TServices | HostCrypto> | Exclude<TRequirements, HostCrypto>
|
|
15
|
+
Exclude<Layer.Services<THost>, TServices | HostCrypto | HostModels> | Exclude<TRequirements, HostCrypto>
|
|
15
16
|
>;
|
|
16
17
|
|
|
17
|
-
export function hostPreflight<TServices, TError, TRequirements, TSensitiveError>(
|
|
18
|
+
export function hostPreflight<TServices, TError, TRequirements, TSensitiveError, TSensitiveRequirements>(
|
|
18
19
|
startup: Layer.Layer<TServices, TError, TRequirements> | undefined,
|
|
19
|
-
sensitive: Effect.Effect<(key: string) => boolean, TSensitiveError>,
|
|
20
|
+
sensitive: Effect.Effect<(key: string) => boolean, TSensitiveError, TSensitiveRequirements>,
|
|
20
21
|
) {
|
|
21
22
|
return Layer.mergeAll(
|
|
22
23
|
Layer.empty,
|
package/src/hostSensitiveKeys.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Effect, MutableRef } from "effect";
|
|
2
2
|
import { type Rpc, RpcGroup } from "effect/rpc";
|
|
3
|
-
import { schemaFieldKeys } from "@shivaedev/errors/schemaFieldScope.ts";
|
|
4
3
|
import { schemaSensitiveKeys } from "@shivaedev/errors/schemaSensitiveKeys.ts";
|
|
4
|
+
import { HostModels } from "#HostModels.ts";
|
|
5
5
|
|
|
6
6
|
export const hostSensitiveKeys = Effect.fnUntraced(function* <TRpcs extends Rpc.Any>(options: {
|
|
7
7
|
readonly group?: RpcGroup.RpcGroup<TRpcs>;
|
|
@@ -13,29 +13,21 @@ export const hostSensitiveKeys = Effect.fnUntraced(function* <TRpcs extends Rpc.
|
|
|
13
13
|
}
|
|
14
14
|
// Model names only widen masking, so the configured policy already holds the startup's conflict verdict.
|
|
15
15
|
const current = MutableRef.make(yield* policy(configured));
|
|
16
|
-
const
|
|
16
|
+
const { fieldNames } = yield* HostModels;
|
|
17
17
|
function sensitive(key: string) {
|
|
18
|
-
return
|
|
18
|
+
return fieldNames.has(key) || MutableRef.get(current)(key);
|
|
19
19
|
}
|
|
20
20
|
return Object.assign(sensitive, {
|
|
21
21
|
// Repositories declare their models while the host builds them; complete recompiles every RPC's policy with their names, as config.sensitiveKeys.
|
|
22
|
-
complete: Effect.suspend(() => policy([...configured, ...
|
|
22
|
+
complete: Effect.suspend(() => policy([...configured, ...fieldNames])).pipe(
|
|
23
23
|
Effect.map((completed) => MutableRef.set(current, completed)),
|
|
24
24
|
Effect.asVoid,
|
|
25
25
|
),
|
|
26
26
|
forRpc: (tag: string | undefined) => {
|
|
27
27
|
const forTag = MutableRef.get(current).forRpc(tag);
|
|
28
|
-
return (key: string) =>
|
|
28
|
+
return (key: string) => fieldNames.has(key) || forTag(key);
|
|
29
29
|
},
|
|
30
30
|
maskFailure: (tag: string | undefined, reason: "Fail" | "Die") => MutableRef.get(current).maskFailure(tag, reason),
|
|
31
|
-
models: {
|
|
32
|
-
declare: (model: { readonly ast: Parameters<typeof schemaFieldKeys>[0] }) =>
|
|
33
|
-
Effect.sync(() => {
|
|
34
|
-
for (const key of schemaFieldKeys(model.ast, [])) {
|
|
35
|
-
models.add(key);
|
|
36
|
-
}
|
|
37
|
-
}),
|
|
38
|
-
},
|
|
39
31
|
redactFailure: (tag: string | undefined, reason: "Fail" | "Die", value: unknown) => MutableRef.get(current).redactFailure(tag, reason, value),
|
|
40
32
|
});
|
|
41
33
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Effect, Option } from "effect";
|
|
2
2
|
import { Headers, HttpMiddleware, HttpRouter, HttpServerRequest, HttpServerResponse } from "effect/http";
|
|
3
3
|
import * as HttpStatus from "effect/http/HttpStatus";
|
|
4
|
+
import { accountPreferenceHeaders } from "@shivaedev/identity/accountPreferenceHeaders.ts";
|
|
4
5
|
import { localTransport } from "@shivaedev/identity/server/adapters/local.ts";
|
|
5
6
|
import { SessionPolicy } from "@shivaedev/identity/server/SessionPolicy.ts";
|
|
6
7
|
|
|
@@ -28,6 +29,8 @@ export function nativeClientOrigins(trustedProxy: string | undefined, route: "au
|
|
|
28
29
|
).layer;
|
|
29
30
|
}
|
|
30
31
|
|
|
32
|
+
const CLIENT_HEADERS = ["Authorization", "Content-Type"];
|
|
33
|
+
|
|
31
34
|
const withClientCors = Effect.fnUntraced(function* <E, R>(
|
|
32
35
|
effect: Effect.Effect<HttpServerResponse.HttpServerResponse, E, R>,
|
|
33
36
|
nativeOrigins: readonly string[],
|
|
@@ -43,7 +46,7 @@ const withClientCors = Effect.fnUntraced(function* <E, R>(
|
|
|
43
46
|
}
|
|
44
47
|
const transport = native ? request.modify({ headers: Headers.remove(request.headers, "cookie") }) : request;
|
|
45
48
|
return yield* HttpMiddleware.cors({
|
|
46
|
-
allowedHeaders: [
|
|
49
|
+
allowedHeaders: auth ? [...CLIENT_HEADERS, ...Object.values(accountPreferenceHeaders)] : CLIENT_HEADERS,
|
|
47
50
|
allowedMethods: auth ? ["GET", "POST"] : ["POST"],
|
|
48
51
|
allowedOrigins: [origin],
|
|
49
52
|
credentials: credentialed,
|
package/src/providedModules.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { Layer } from "effect";
|
|
|
2
2
|
import type { AnyModule } from "@shivaedev/contract/moduleHandlers.ts";
|
|
3
3
|
import type { AppModule } from "#AppModule.ts";
|
|
4
4
|
import type { appDatabase } from "#appDatabase.ts";
|
|
5
|
+
import type { hostCrypto } from "#hostCrypto.ts";
|
|
5
6
|
import type { hostHttpServices } from "#hostHttpServices.ts";
|
|
6
7
|
|
|
7
8
|
export interface OperationServicesNotProvided<TModule extends string, TOperation extends PropertyKey, TMissing> {
|
|
@@ -11,7 +12,10 @@ export interface OperationServicesNotProvided<TModule extends string, TOperation
|
|
|
11
12
|
readonly problem: "run or readPolicy uses services that no registration's services, ports or requestServices provide and the host does not provide";
|
|
12
13
|
}
|
|
13
14
|
|
|
14
|
-
type HostServices =
|
|
15
|
+
type HostServices =
|
|
16
|
+
| Layer.Success<ReturnType<typeof appDatabase<never, never>>>
|
|
17
|
+
| Layer.Success<typeof hostCrypto>
|
|
18
|
+
| Layer.Success<typeof hostHttpServices>;
|
|
15
19
|
type Field<TModule, TKey extends PropertyKey> = TModule extends unknown ? (TKey extends keyof TModule ? TModule[TKey] : never) : never;
|
|
16
20
|
type Provided<TModules extends readonly AppModule[]> =
|
|
17
21
|
| Layer.Success<Extract<Field<TModules[number], "services" | "ports" | "requestServices">, Layer.Any>>
|
package/src/redactedHost.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { Effect, Layer
|
|
1
|
+
import { Effect, Layer } from "effect";
|
|
2
2
|
import type { Rpc, RpcGroup } from "effect/rpc";
|
|
3
|
-
import { collectRepositoryModels, RepositoryModels } from "@shivaedev/sql/RepositoryModels.ts";
|
|
4
3
|
import { redactingDiagnostics } from "#adapters/redactingDiagnostics.ts";
|
|
5
4
|
import { hostSensitiveKeys } from "#hostSensitiveKeys.ts";
|
|
6
5
|
import { otlpTracing } from "#otlpTracing.ts";
|
|
@@ -8,21 +7,7 @@ import { RedactionPolicy } from "#RedactionPolicy.ts";
|
|
|
8
7
|
|
|
9
8
|
export type HostSensitivePolicy = Effect.Success<ReturnType<typeof hostSensitiveKeys>>;
|
|
10
9
|
|
|
11
|
-
//
|
|
12
|
-
function maskedModels(sensitive: HostSensitivePolicy) {
|
|
13
|
-
return Layer.effect(
|
|
14
|
-
RepositoryModels,
|
|
15
|
-
Effect.gen(function* () {
|
|
16
|
-
const collected = yield* RepositoryModels;
|
|
17
|
-
return RepositoryModels.of({
|
|
18
|
-
declare: (declared) => Effect.andThen(sensitive.models.declare(Schema.Struct(declared.model.fields)), collected.declare(declared)),
|
|
19
|
-
owned: collected.owned,
|
|
20
|
-
});
|
|
21
|
-
}),
|
|
22
|
-
).pipe(Layer.provide(collectRepositoryModels));
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// Both hosts build their process inside one policy, so repositories declare their models to the same policy that masks every log, error report and exported span.
|
|
10
|
+
// Both hosts build their process inside one policy, so every log, error report and exported span masks the same names, including the fields their repositories' models declare.
|
|
26
11
|
export function redactedHost<TRpcs extends Rpc.Any, A, E, R>(
|
|
27
12
|
options: { readonly group?: RpcGroup.RpcGroup<TRpcs>; readonly config?: { readonly sensitiveKeys?: readonly string[] } },
|
|
28
13
|
host: (sensitive: HostSensitivePolicy) => Layer.Layer<A, E, R>,
|
|
@@ -33,7 +18,6 @@ export function redactedHost<TRpcs extends Rpc.Any, A, E, R>(
|
|
|
33
18
|
Layer.provide(redactingDiagnostics(sensitive)),
|
|
34
19
|
Layer.provide(otlpTracing),
|
|
35
20
|
Layer.provide(Layer.succeed(RedactionPolicy, sensitive)),
|
|
36
|
-
Layer.provide(maskedModels(sensitive)),
|
|
37
21
|
),
|
|
38
22
|
),
|
|
39
23
|
);
|