@shivaedev/server 0.14.0 → 0.16.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 CHANGED
@@ -1,5 +1,32 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.16.0 - 2026-11-01
4
+
5
+ ### Added
6
+
7
+ - Export Effect logs as trace events and ErrorReporter reports as error spans through the redacting Railway OTLP pipeline in appHost and worker Layers.
8
+ - Mount a same-origin browser error reporting route in appHost, with server redaction, bounded reports and per-client rate limiting.
9
+ - Generated starters enable Railway manual tracing for web and worker services and mount browser reporting by default.
10
+ - Add useBrowserErrors to forward uncaught browser errors and unhandled rejections to the host, removing listeners on unmount.
11
+
12
+ ### Fixed
13
+
14
+ - Mask complete RPC payload annotations before exporting logs and error reports, keeping sensitive error values out of Railway diagnostics even when the request uses public field names.
15
+
16
+ ## 0.15.0 - 2026-10-31
17
+
18
+ ### Added
19
+
20
+ - Accept `config.clock` on `appDatabase` and `appHost` for stories that explicitly exercise database lifecycle timers with their test clock. Application handlers and jobs keep their application clock.
21
+
22
+ ### Fixed
23
+
24
+ - Run application database pool maintenance and change-listener heartbeats, deadlines and renewal on the live clock so a running host can advance its story clock by days while retaining database access, worker writes and change hints.
25
+
26
+ ### Breaking
27
+
28
+ - Database lifecycle timers use the live clock instead of the caller's clock by default. Stories that advance time to exercise pool expiry, listener renewal or heartbeat deadlines must pass their native `yield* Clock.Clock` as `config.clock` to `appDatabase` or `appHost`.
29
+
3
30
  ## 0.14.0 - 2026-10-31
4
31
 
5
32
  ### Added
package/README.md CHANGED
@@ -142,7 +142,7 @@ const host = appHost({
142
142
 
143
143
  Construct Better Auth inside `application`, since its constructor starts schema validation. Keep validation enabled so a current migration ledger with missing auth columns still reports drift. The starter uses this form after its pre-deploy migrations.
144
144
 
145
- Set `OTEL_EXPORTER_OTLP_ENDPOINT` or `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT` to export `appHost`'s Effect spans over OTLP/HTTP. Without an endpoint, no exporter or export loop is built, even when service metadata is set. The `http/protobuf` default follows the [OpenTelemetry recommendation](https://opentelemetry.io/docs/specs/otel/protocol/exporter/#specify-protocol); unsupported protocols, including `grpc`, fail startup with a `ConfigError` naming the value. Header and resource-attribute values are `key=value` pairs with URL-encoded values. Configuration is read through Effect Config.
145
+ Railway tracing is the default error and trace destination. The starter enables tracing for both services in `.railway/railway.ts`; Railway injects the endpoint, authentication headers and service identity. `appHost` exports through the redacting Effect OTLP/HTTP pipeline. Leave exporter endpoints unset on Railway so its injected configuration takes effect. Without an endpoint, no exporter or export loop is built, even when service metadata is set. The `http/protobuf` default follows the [OpenTelemetry recommendation](https://opentelemetry.io/docs/specs/otel/protocol/exporter/#specify-protocol); unsupported protocols, including `grpc`, fail startup with a `ConfigError` naming the value. Header and resource-attribute values are `key=value` pairs with URL-encoded values. Configuration is read through Effect Config.
146
146
 
147
147
  The supported tracing variables and defaults are:
148
148
 
@@ -164,7 +164,29 @@ The supported tracing variables and defaults are:
164
164
 
165
165
  Timeouts fail through the HTTP client's typed transport-error channel and use the same warning path as other transport failures. Effect retains its native retry policy; the request timeout applies to each attempt. The batch defaults follow Effect's `OtlpTracer.layer`. Its options cannot express a separate batch-operation deadline or a queue capacity, so `OTEL_BSP_EXPORT_TIMEOUT` controls shutdown only and `OTEL_BSP_MAX_QUEUE_SIZE` is unsupported. Other `OTEL_BSP_*` variables are unsupported.
166
166
 
167
- On Railway, enable the per-service tracing setting separately for the web service and worker, and leave both exporter endpoint variables unset in your app's configuration. Railway documents that it injects the `OTEL_*` variables, including `OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf`, only when the app sets no endpoint of its own. The framework exports through Effect's own `effect/observability` OTLP tracer; eBPF auto-instrumentation is outside this path. For a worker, provide `otlpTracing` from `@shivaedev/server/otlpTracing.ts` to its application Layer. It batches ended Effect spans and flushes during scoped shutdown with a three-second bound by default. The first failed export logs a warning with the collector status and redacted response body, or the transport failure kind when no response arrives. Repeated failures stay quiet until a successful export. Collector connection failures and HTTP errors leave requests, jobs and shutdown successful.
167
+ For existing Railway services, enable manual tracing per service and environment, then redeploy. The starter does this through `tracing: { enabled: true, autoInstrumentation: false }` in its infrastructure configuration (Railway CLI 5.63.0 or newer). Railway documents that it injects the `OTEL_*` variables, including `OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf`, only when the app sets no endpoint of its own. The framework exports through Effect's own `effect/observability` OTLP tracer; eBPF auto-instrumentation is outside this path. For a worker, provide `otlpTracing` from `@shivaedev/server/otlpTracing.ts` to its application Layer. Railway accepts traces only: logs become `effect.log` spans with a `log` event, and Effect `ErrorReporter` reports become failed `effect.error` spans with exception events. Both use the same exporter and redaction as application spans; no OTLP logs endpoint is used. Exported diagnostic annotations mask the entire `rpc.payload`, since a request value can repeat a sensitive error field under a public payload key. The exporter batches ended Effect spans and flushes during scoped shutdown with a three-second bound by default. The first failed export logs a warning with the collector status and redacted response body, or the transport failure kind when no response arrives. Repeated failures stay quiet until a successful export. Collector connection failures and HTTP errors leave requests, jobs and shutdown successful.
168
+
169
+ `appHost` mounts `POST /_platform/errors`. Mount `useBrowserErrors` from `@shivaedev/react/client/adapters/useBrowserErrors.ts` once in the root component to forward uncaught browser errors and unhandled rejections, including before sign-in. The route accepts `{ kind: "error" | "unhandledrejection", message, stack?, url }`, returns 202, and reports through the same server redaction and `ErrorReporter` pipeline. It accepts at most 20 reports per minute per client IP per process, returning 429 afterwards. Railway's `x-real-ip` is used only from a configured trusted proxy; otherwise the socket peer identifies the client. Foreign origins return 403. Invalid JSON or reports over 16 KiB return 400. Limits reset with the process and are independent across replicas.
170
+
171
+ For local traces, run an OpenTelemetry Collector on loopback with an OTLP HTTP receiver and its `debug` exporter. Set `OTEL_EXPORTER_OTLP_ENDPOINT=http://127.0.0.1:4318` for the app and worker; the collector's console shows the redacted spans, diagnostic events and reported errors. A minimal collector configuration is:
172
+
173
+ ```yaml
174
+ receivers:
175
+ otlp:
176
+ protocols:
177
+ http:
178
+ endpoint: 127.0.0.1:4318
179
+ exporters:
180
+ debug:
181
+ verbosity: detailed
182
+ service:
183
+ pipelines:
184
+ traces:
185
+ receivers: [ otlp ]
186
+ exporters: [ debug ]
187
+ ```
188
+
189
+ Save the configuration as `otelcol.local.yaml` and run `otelcol --config=otelcol.local.yaml`. Start the web and worker processes with `OTEL_EXPORTER_OTLP_ENDPOINT=http://127.0.0.1:4318`, then read the collector console. Without an endpoint, local development and tests start with export disabled. Console logging remains available. Railway is the production sink; do not add another error service.
168
190
 
169
191
  Exported HTTP server spans use `{method} {route}` with `http.route` for matched RPC and router paths, including parameter templates; unmatched requests use the method alone. `appHost` continues incoming W3C `traceparent` context in RPC handling, including one sent by an edge proxy, whether or not an exporter is configured.
170
192
 
@@ -174,6 +196,8 @@ Set `config.maxConnections` on `appDatabase` or a migrated `appHost` to bound th
174
196
 
175
197
  The host defaults to `config.connectionTTL: "10 minutes"` and `config.idleTimeout: "1 minute"`. Both accept native Effect durations; `config.minConnections` controls the idle floor. Lifetime expiry replaces a query connection on its next checkout, allowing active queries and transactions to finish. The reserved change listener renews on the same lifetime, resynchronizes live subscribers across renewal and resumes committed hints, including with a separate listener URL. No PostgreSQL `idle_session_timeout` is set: an idle LISTEN session must stay alive until its owner renews it.
176
198
 
199
+ Database pool maintenance and change-listener heartbeats, deadlines, retries and renewal use the live clock. A story can advance its application clock by days while the host and job worker keep running; handlers and jobs still see the advanced application time. For stories about database lifecycle timers, pass the story's native `Clock.Clock` service as `config.clock` on `appDatabase` or `appHost`. This option applies to both application and separate listener pools; it does not change the application clock or migration wait timers.
200
+
177
201
  For a deployment behind a proxy, set `HOST=0.0.0.0` and `TRUSTED_PROXY` to a comma-separated list of proxy peer IPs or CIDR ranges (IPv4 or IPv6), or use `config.host` and `config.trustedProxy`. Only matching peers may supply `X-Forwarded-Host` and `X-Forwarded-Proto` (`http` or `https`) for the guard's same-origin check; the proxy must overwrite both headers and preserve Origin. A single authority is required, and comma-separated forwarding chains are refused. IPv4-mapped IPv6 peers match their IPv4 address. A session host bound to a non-loopback address refuses to boot without `TRUSTED_PROXY` or `config.trustedProxy`, with a typed `TrustedProxyRequired` error from `@shivaedev/server/TrustedProxyRequired.ts` naming both settings and how to supply proxy peer addresses or CIDR ranges. Local loopback hosts keep working without proxy trust; `policy: "loopback"` does not use proxy trust. Malformed addresses or ranges fail `appHost` startup with a typed `ConfigError`. The starter's Railway deployment works out of the box: its web configuration supplies `TRUSTED_PROXY=100.64.0.0/10` and `AUTH_CLIENT_IP_HEADER=x-real-ip`, so matching peers supply forwarded client IPs for auth and the HTTPS authority for RPC origin checks. Set `PUBLIC_URL` to the app's HTTPS URL for secure session cookies. NDJSON and the application's session Origin policy still apply. See the [deployment quickstart](https://github.com/ShivaeDev/platform/blob/main/docs/framework/quickstart.md#deploy).
178
202
 
179
203
  Build application handlers with `Api.application.toLayer(...)` (and `Api.application.of(...)` for an Effect-built handler map), then pass the full `Api` to the host and client. `Api.application` is the native RPC group without the reserved `$changes` stream; the host supplies that handler. The explicit `Api.omit("<namespace>.$changes")` form also works.
@@ -334,7 +358,7 @@ Import the module that defines the name; there is no package-root entry. Paths b
334
358
  | `setupDatabases.ts` | `setupDatabases()`: prepare the local development and test databases. |
335
359
  | `development.ts` | `development({ server, worker, conditions? })`, `runDevelopment(options)`: run the server, worker and Vite in watch mode. |
336
360
  | `rpc-server/publicConfigLayer.ts` | `publicConfigLayer(declaration, path?)`: serve a `publicConfig` declaration from native Config. |
337
- | `otlpTracing.ts` | `otlpTracing`: opt-in Effect OTLP trace export for worker Layers. |
361
+ | `otlpTracing.ts` | `otlpTracing`: redacting Railway OTLP export for worker spans, logs and error reports. |
338
362
  | `RedactionPolicy.ts` | `RedactionPolicy`: provide the app's diagnostic key predicate derived by errors. |
339
363
  | `redactingDiagnostics.ts`, `redactingTracer.ts`, `redactingRpcSerialization.ts` | `redactingDiagnostics(sensitive)`, `redactingTracer(sensitive)`, `redactingRpcSerialization(wire, sensitive, maskFailure?)`: compose native diagnostic and NDJSON boundaries. |
340
364
  | `runtime/makePlatform.ts` | `makePlatformRuntime(layer, { developmentCacheKey? })`. |
@@ -0,0 +1,3 @@
1
+ import { Layer } from "effect";
2
+ export declare const traceDiagnostics: Layer.Layer<never, never, never>;
3
+ //# sourceMappingURL=traceDiagnostics.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"traceDiagnostics.d.ts","sourceRoot":"","sources":["../../src/adapters/traceDiagnostics.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+C,KAAK,EAAsC,MAAM,QAAQ,CAAC;AAKhH,eAAO,MAAM,gBAAgB,kCA6C5B,CAAC"}
@@ -0,0 +1,47 @@
1
+ import { Clock, Context, Effect, ErrorReporter, Exit, Layer, Logger, Option, References, Tracer } from "effect";
2
+ import { redact, redactRecord } from "@shivaedev/errors/redact.ts";
3
+ import { RedactionPolicy, redactionForRpc } from "#RedactionPolicy.ts";
4
+ // Railway's receiver accepts traces only, so diagnostics use the same span exporter.
5
+ export const traceDiagnostics = Layer.unwrap(Effect.gen(function* () {
6
+ const tracer = yield* Tracer.Tracer;
7
+ const clock = yield* Clock.Clock;
8
+ const policy = yield* RedactionPolicy;
9
+ // Request values can repeat sensitive error fields under otherwise public payload keys.
10
+ function exportPolicy(fiber) {
11
+ const sensitive = redactionForRpc(policy, fiber.getRef(References.CurrentLogAnnotations)["rpc.method"]);
12
+ return (key) => key === "rpc.payload" || sensitive(key);
13
+ }
14
+ function span(name, fiber, timestamp) {
15
+ return tracer.span({
16
+ annotations: Context.empty(),
17
+ kind: "internal",
18
+ links: [],
19
+ name,
20
+ parent: Option.fromUndefinedOr(fiber.cache.span),
21
+ root: false,
22
+ sampled: true,
23
+ startTime: timestamp,
24
+ });
25
+ }
26
+ const logger = Logger.make((options) => {
27
+ const timestamp = clock.currentTimeNanosUnsafe();
28
+ const entry = span("effect.log", options.fiber, timestamp);
29
+ const annotations = options.fiber.getRef(References.CurrentLogAnnotations);
30
+ const sensitive = exportPolicy(options.fiber);
31
+ entry.event("log", timestamp, {
32
+ ...redactRecord(annotations, sensitive),
33
+ "log.message": redact(options.message, sensitive),
34
+ "log.severity": options.logLevel,
35
+ });
36
+ entry.end(timestamp, options.cause.reasons.length === 0 ? Exit.void : Exit.failCause(options.cause));
37
+ });
38
+ const reporter = ErrorReporter.make(({ attributes, cause, fiber, severity, timestamp }) => {
39
+ const entry = span("effect.error", fiber, timestamp);
40
+ for (const [key, value] of Object.entries(redactRecord({ ...fiber.getRef(References.CurrentLogAnnotations), ...attributes, "error.severity": severity }, exportPolicy(fiber)))) {
41
+ entry.attribute(key, value);
42
+ }
43
+ entry.end(timestamp, Exit.failCause(cause));
44
+ });
45
+ return Layer.merge(Logger.layer([logger], { mergeWithExisting: true }), ErrorReporter.layer([reporter], { mergeWithExisting: true }));
46
+ }));
47
+ //# sourceMappingURL=traceDiagnostics.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"traceDiagnostics.js","sourceRoot":"","sources":["../../src/adapters/traceDiagnostics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChH,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEvE,qFAAqF;AACrF,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,CAAC,MAAM,CAC3C,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IACnB,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC;IACpC,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC;IACjC,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,eAAe,CAAC;IACtC,w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Config, Layer, Redacted } from "effect";
2
+ import { Clock, Config, Layer, Redacted } from "effect";
3
3
  import * as Reactivity from "effect/reactivity/Reactivity";
4
4
  import { Migrator } from "effect/sql";
5
5
  import { type PostgresChangesOptions } from "@shivaedev/sql/postgresChanges.ts";
@@ -7,6 +7,7 @@ import { type PostgresOptions } from "@shivaedev/sql/postgresLayer.ts";
7
7
  import type { AppDatabaseOptions } from "#appHost.ts";
8
8
  export interface DatabaseConfig extends PostgresOptions {
9
9
  readonly changes?: Partial<Omit<PostgresChangesOptions, "client" | "listenerClient" | "connectionSetting" | "connectionTTL" | "resync">>;
10
+ readonly clock?: Clock.Clock;
10
11
  readonly databaseUrl?: Redacted.Redacted<string>;
11
12
  readonly listenDatabaseUrl?: Redacted.Redacted<string>;
12
13
  }
@@ -1 +1 @@
1
- {"version":3,"file":"appDatabase.d.ts","sourceRoot":"","sources":["../src/appDatabase.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,QAAQ,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAoC,KAAK,EAAU,QAAQ,EAAY,MAAM,QAAQ,CAAC;AACrG,OAAO,KAAK,UAAU,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAMtC,OAAO,EAAE,KAAK,sBAAsB,EAAmB,MAAM,mCAAmC,CAAC;AACjG,OAAO,EAAE,KAAK,eAAe,EAAiB,MAAM,iCAAiC,CAAC;AAEtF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEtD,MAAM,WAAW,cAAe,SAAQ,eAAe;IACtD,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,sBAAsB,EAAE,QAAQ,GAAG,gBAAgB,GAAG,mBAAmB,GAAG,eAAe,GAAG,QAAQ,CAAC,CAAC,CAAC;IACzI,QAAQ,CAAC,WAAW,CAAC,EAAE,QAAQ,CAAC,QAAQ,CAAC,MAAM,C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,CAAC,CAAC,shBAmD1E"}
@@ -1,6 +1,6 @@
1
1
  import { createHash } from "node:crypto";
2
2
  import * as PgClient from "@effect/sql-pg/PgClient";
3
- import { Config, Context, Duration, Effect, Fiber, Layer, Option, Redacted, Schedule } from "effect";
3
+ import { Clock, Config, Context, Duration, Effect, Fiber, Layer, Option, Redacted, Schedule } from "effect";
4
4
  import * as Reactivity from "effect/reactivity/Reactivity";
5
5
  import { Migrator } from "effect/sql";
6
6
  import { LiveServer } from "@shivaedev/contract/LiveServer.ts";
@@ -17,7 +17,8 @@ export function appDatabase(options) {
17
17
  "connectionTTL": options.config?.connectionTTL ?? "10 minutes",
18
18
  idleTimeout: options.config?.idleTimeout ?? "1 minute",
19
19
  };
20
- const pool = Layer.unwrap(Effect.map(options.config?.databaseUrl === undefined ? Config.Redacted("DATABASE_URL") : Effect.succeed(options.config.databaseUrl), (url) => postgresLayer(url, config)));
20
+ const clock = Layer.succeed(Clock.Clock, config.clock ?? Clock.Clock.defaultValue());
21
+ const pool = Layer.unwrap(Effect.map(options.config?.databaseUrl === undefined ? Config.Redacted("DATABASE_URL") : Effect.succeed(options.config.databaseUrl), (url) => postgresLayer(url, config).pipe(Layer.provide(clock))));
21
22
  const prepared = Layer.effectDiscard(prepareMigrations(options.migrations)).pipe(Layer.provideMerge(pool));
22
23
  const live = LiveServer.layer.pipe(Layer.provideMerge(Reactivity.layer));
23
24
  const migrations = options.migrations;
@@ -35,7 +36,7 @@ export function appDatabase(options) {
35
36
  const listenUrl = options.config?.listenDatabaseUrl ?? Option.getOrUndefined(yield* Config.Redacted("LISTEN_DATABASE_URL").pipe(Config.option));
36
37
  const listenerClient = listenUrl === undefined
37
38
  ? client
38
- : yield* Effect.map(Layer.build(postgresLayer(listenUrl, { ...config, maxConnections: 1, minConnections: 0 })), (context) => Context.get(context, PgClient.PgClient));
39
+ : yield* Effect.map(Layer.build(postgresLayer(listenUrl, { ...config, maxConnections: 1, minConnections: 0 }).pipe(Layer.provide(clock))), (context) => Context.get(context, PgClient.PgClient));
39
40
  let connectionSetting = options.config?.databaseUrl === undefined ? "DATABASE_URL" : "config.databaseUrl";
40
41
  if (listenUrl !== undefined) {
41
42
  connectionSetting = options.config?.listenDatabaseUrl === undefined ? "LISTEN_DATABASE_URL" : "config.listenDatabaseUrl";
@@ -48,14 +49,13 @@ export function appDatabase(options) {
48
49
  "connectionTTL": config.connectionTTL,
49
50
  listenerClient,
50
51
  resync: hints.resync(),
51
- });
52
+ }).pipe(Layer.provide(clock));
52
53
  })).pipe(Layer.provideMerge(base));
53
54
  }
54
55
  function prepareMigrations(migrations) {
55
56
  switch (migrations.mode) {
56
57
  case "check": {
57
- const schema = { ...migrations };
58
- delete schema.release;
58
+ const { release: _release, ...schema } = migrations;
59
59
  return assertPostgresMigrations(schema);
60
60
  }
61
61
  case "wait":
@@ -1 +1 @@
1
- {"version":3,"file":"appDatabase.js","sourceRoot":"","sources":["../src/appDatabase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,QAAQ,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AACrG,OAAO,KAAK,UAAU,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAC;AAC/D,OAAO,EAAE,wBAAwB,EAAE,sBAAsB,EAAE,MAAM,4CAA4C,CAAC;AAC9G,OAAO,EAAE,uBAAuB,EAAE,MAAM,2CAA2C,CAAC;AACpF,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAkC,yBAAyB,EAAE,MAAM,6CAA6C,CAAC;AACxH,OAAO,EAA+B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C,eAAe,GAAG,KAAK,EAEvB,WAAW,EAAE,MAAM,CAAC,MAAM,CACzB,kBAAkB,CACjB,KAAK,EACL,SAAS,EACT,aAAa,EACb,oBAAoB,EACpB,SAAS,EACT,aAAa,EACb,oBAAoB,EACpB,QAAQ,EACR,KAAK,EACL,KAAK,EACL,KAAK,EACL,WAAW,EACX,kBAAkB,CAClB,EACD,iBAAiB,EACjB,wBAAwB,CACxB,EACD,QAAQ,EAAE,UAAU,CAAC,OAAO,WAAW,CAAC,WAAW,EAAE,eAAe,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;whBAGtE"}
@@ -2,6 +2,7 @@ import * as NodeHttpServer from "@effect/platform-node/NodeHttpServer";
2
2
  import { Effect, Layer } from "effect";
3
3
  import { HttpRouter, HttpServer } from "effect/http";
4
4
  import { schemaSensitiveKeys } from "@shivaedev/errors/schemaSensitiveKeys.ts";
5
+ import { browserErrorRoute } from "#browserErrorRoute.ts";
5
6
  import { healthRoute } from "#healthRoute.ts";
6
7
  import { hostApplicationRoutes } from "#hostApplicationRoutes.ts";
7
8
  import { hostAssets } from "#hostAssets.ts";
@@ -21,7 +22,7 @@ export function appHostHttp(options) {
21
22
  const application = Layer.mergeAll(options.services ?? Layer.empty);
22
23
  const server = nodeHttpServer(host, options.config);
23
24
  const applicationRoutes = hostApplicationRoutes(options.routes, bodySize);
24
- const httpRoutes = Layer.mergeAll(routes, healthRoute, assets, applicationRoutes).pipe(Layer.provide(nativeClientOrigins(nativeOrigins, trustedProxy, false, options.rpcPath)), Layer.provide(nativeClientOrigins(nativeOrigins, trustedProxy, options.nativeOrigins === undefined ? "preflight" : true)));
25
+ const httpRoutes = Layer.mergeAll(routes, healthRoute, browserErrorRoute(trustedProxy), assets, applicationRoutes).pipe(Layer.provide(nativeClientOrigins(nativeOrigins, trustedProxy, false, options.rpcPath)), Layer.provide(nativeClientOrigins(nativeOrigins, trustedProxy, options.nativeOrigins === undefined ? "preflight" : true)));
25
26
  return Layer.unwrap(HttpRouter.toHttpEffect(httpRoutes).pipe(Effect.map((handler) => HttpServer.serve(handler).pipe(HttpServer.withLogAddress, Layer.provideMerge(server))))).pipe(Layer.provideMerge(application), Layer.provideMerge(NodeHttpServer.layerHttpServices));
26
27
  })).pipe(Layer.provide(redactingDiagnostics(sensitive)), Layer.provide(otlpTracing), Layer.provide(Layer.succeed(RedactionPolicy, sensitive)))));
27
28
  }
@@ -1 +1 @@
1
- {"version":3,"file":"appHostHttp.js","sourceRoot":"","sources":["../src/appHostHttp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,cAAc,MAAM,sCAAsC,CAAC;AACvE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAErD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AAI/E,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAEhE,MAAM,UAAU,WAAW,CAY1B,OAWqB;IAErB,OAAO,KAAK,CAAC,MAAM,CAClB,MAAM,CAAC,GAAG,CAAC,mBAAmB,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,MAAM,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,CAAC,KAAK,CAAC,YAAY,CAAC,WAAW,CAAC,EAAE,KAAK,CAAC,YAAY,CAAC,cAAc,CAAC,iBAAiB,CAAC,CAAC,CAAC;IAC/F,CAAC,CAAC,CACF,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,oBAAoB,CAAC,SAAS,CAAC,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,eAAe,EAAE,SAAS,CAAC,CAAC,CAAC,CAC5I,CACD,CAAC;AACH,CAAC;AAED,MAAM,UAAU,YAAY,CAc3B,OAaE,EACF,QAAsE;IAEtE,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,QAAQ,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC;IACjE,OAAO,WAAW,CAAC,EAAE,GAAG,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC;AAC3F,CAAC;AAED,MAAM,UAAU,YAAY,CAgB3B,WAkBC,EACD,QAAsE;IAEtE,OAAO,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC;AACpH,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { Layer } from "effect";
2
+ import { HttpRouter } from "effect/http";
3
+ export declare function browserErrorRoute(trustedProxy?: string): Layer.Layer<never, never, HttpRouter.HttpRouter>;
4
+ //# sourceMappingURL=browserErrorRoute.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browserErrorRoute.d.ts","sourceRoot":"","sources":["../src/browserErrorRoute.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0C,KAAK,EAAkB,MAAM,QAAQ,CAAC;AACvF,OAAO,EAAuB,UAAU,EAAyC,MAAM,aAAa,CAAC;AA6BrG,wBAAgB,iBAAiB,CAAC,YAAY,CAAC,EAAE,MAAM,oDAyBtD"}
@@ -0,0 +1,45 @@
1
+ import { ByteSize, Cause, Effect, ErrorReporter, Layer, Option, Schema } from "effect";
2
+ import { HttpIncomingMessage, HttpRouter, HttpServerRequest, HttpServerResponse } from "effect/http";
3
+ import * as HttpStatus from "effect/http/HttpStatus";
4
+ import { RateLimiter } from "effect/persistence";
5
+ import { localTransport, trustedProxyPeer } from "@shivaedev/identity/server/local.ts";
6
+ const BrowserErrorReport = Schema.Struct({
7
+ kind: Schema.Literals(["error", "unhandledrejection"]),
8
+ message: Schema.String,
9
+ stack: Schema.optional(Schema.String),
10
+ url: Schema.String,
11
+ });
12
+ const receiveReport = Effect.gen(function* () {
13
+ const parsed = yield* HttpServerRequest.schemaBodyJson(BrowserErrorReport).pipe(Effect.provideService(HttpIncomingMessage.MaxBodySize, ByteSize.kibibytes(16)), Effect.option);
14
+ if (Option.isNone(parsed)) {
15
+ return HttpServerResponse.empty({ status: HttpStatus.fromLiteral("BadRequest") });
16
+ }
17
+ const error = new Error(parsed.value.message);
18
+ error.name = "BrowserError";
19
+ if (parsed.value.stack !== undefined) {
20
+ error.stack = parsed.value.stack;
21
+ }
22
+ yield* ErrorReporter.report(Cause.die(error)).pipe(Effect.annotateLogs({ "browser.kind": parsed.value.kind, "url.full": parsed.value.url }));
23
+ return HttpServerResponse.empty({ status: HttpStatus.fromLiteral("Accepted") });
24
+ });
25
+ export function browserErrorRoute(trustedProxy) {
26
+ return HttpRouter.use((router) => Effect.gen(function* () {
27
+ const limiter = yield* RateLimiter.RateLimiter;
28
+ const allowed = localTransport(trustedProxy);
29
+ const trusted = trustedProxyPeer(trustedProxy);
30
+ yield* router.add("POST", "/_platform/errors", Effect.gen(function* () {
31
+ const request = yield* HttpServerRequest.HttpServerRequest;
32
+ if (!allowed(request)) {
33
+ return HttpServerResponse.empty({ status: HttpStatus.fromLiteral("Forbidden") });
34
+ }
35
+ const peer = Option.getOrElse(request.remoteAddress, () => "unknown");
36
+ const client = trusted(peer) ? (request.headers["x-real-ip"] ?? peer) : peer;
37
+ const accepted = yield* limiter.consume({ key: client, limit: 20, window: "1 minute" }).pipe(Effect.isSuccess);
38
+ if (!accepted) {
39
+ return HttpServerResponse.empty({ status: HttpStatus.fromLiteral("TooManyRequests") });
40
+ }
41
+ return yield* receiveReport;
42
+ }));
43
+ })).pipe(Layer.provide(RateLimiter.layer.pipe(Layer.provide(RateLimiter.layerStoreMemory))));
44
+ }
45
+ //# sourceMappingURL=browserErrorRoute.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browserErrorRoute.js","sourceRoot":"","sources":["../src/browserErrorRoute.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACvF,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACrG,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AAEvF,MAAM,kBAAkB,GAAG,MAAM,CAAC,MAAM,CAAC;IACxC,IAAI,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC,OAAO,EAAE,oBAAoB,CAAC,CAAC;IACtD,OAAO,EAAE,MAAM,CAAC,MAAM;IACtB,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC;IACrC,GAAG,EAAE,MAAM,CAAC,MAAM;CAClB,CAAC,CAAC;AAEH,MAAM,aAAa,GAAG,M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QAC7B,CAAC,CAAC,CACF,CAAC;IACH,CAAC,CAAC,CACF,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC;AAC5F,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"otlpTracing.d.ts","sourceRoot":"","sources":["../src/otlpTracing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAU,KAAK,EAAU,MAAM,QAAQ,CAAC;AAOvD,eAAO,MAAM,WAAW,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,WAAW,CAqD9D,CAAC"}
1
+ {"version":3,"file":"otlpTracing.d.ts","sourceRoot":"","sources":["../src/otlpTracing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAU,KAAK,EAAU,MAAM,QAAQ,CAAC;AASvD,eAAO,MAAM,WAAW,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,WAAW,CAyD9D,CAAC"}
@@ -1,7 +1,9 @@
1
1
  import { Config, Effect, Layer, Schema } from "effect";
2
2
  import { OtlpSerialization, OtlpTracer } from "effect/observability";
3
+ import { traceDiagnostics } from "#adapters/traceDiagnostics.ts";
3
4
  import { otlpHttpClient } from "#otlpHttpClient.ts";
4
5
  import { RedactionPolicy } from "#RedactionPolicy.ts";
6
+ import { redactingDiagnostics } from "#redactingDiagnostics.ts";
5
7
  import { redactingTracer } from "#redactingTracer.ts";
6
8
  import { safeOtlpSerialization } from "#safeOtlpSerialization.ts";
7
9
  export const otlpTracing = Layer.unwrap(Effect.gen(function* () {
@@ -30,6 +32,7 @@ export const otlpTracing = Layer.unwrap(Effect.gen(function* () {
30
32
  shutdownTimeout: Math.min(exportTimeout, requestTimeout),
31
33
  url: endpoint.toString(),
32
34
  }).pipe(Layer.provide(safeOtlpSerialization.pipe(Layer.provide(protocol === "http/protobuf" ? OtlpSerialization.layerProtobuf : OtlpSerialization.layerJson))), Layer.provide(otlpHttpClient(requestTimeout)));
33
- return redactingTracer(yield* RedactionPolicy).pipe(Layer.provideMerge(tracer));
35
+ const sensitive = yield* RedactionPolicy;
36
+ return redactingDiagnostics(sensitive).pipe(Layer.provideMerge(traceDiagnostics), Layer.provideMerge(redactingTracer(sensitive).pipe(Layer.provideMerge(tracer))));
34
37
  }));
35
38
  //# sourceMappingURL=otlpTracing.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"otlpTracing.js","sourceRoot":"","sources":["../src/otlpTracing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAElE,MAAM,CAAC,MAAM,WAAW,GAA2C,KAAK,CAAC,MAAM,CAC9E,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IACnB,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,oCAAoC,CAAC,CAAC,IAAI,CAC5E,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,CAClB,MAAM,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAC,IAAI,CAC7C,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;QAClB,GAAG,CAAC,QAAQ,GAAG,GAAG,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,YAAY,CAAC;QAC/D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AAW,EAAE,cAAc,EAAE;QACrD,eAAe,EAAE,IAAI,CAAC,GAAG,CAAC,aAAa,EAAE,cAAc,CAAC;QACxD,GAAG,EAAE,QAAQ,CAAC,QAAQ,EAAE;KACxB,CAAC,CAAC,IAAI,CACN,KAAK,CAAC,OAAO,CACZ,qBAAqB,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,KAAK,eAAe,CAAC,CAAC,CAAC,iBAAiB,CAAC,aAAa,CAAC,CAAC,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC,CACvI,EACD,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC,CAC7C,CAAC;IACF,MAAM,SAAS,GAAG,KAAK,CAAC,CAAC,eAAe,CAAC;IACzC,OAAO,oBAAoB,CAAC,SAAS,CAAC,CAAC,IAAI,CAC1C,KAAK,CAAC,YAAY,CAAC,gBAAgB,CAAC,EACpC,KAAK,CAAC,YAAY,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,CAC/E,CAAC;AACH,CAAC,CAAC,CACF,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shivaedev/server",
3
- "version": "0.14.0",
3
+ "version": "0.16.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"
@@ -49,21 +49,21 @@
49
49
  "@shivaedev/contract": "0.30.0",
50
50
  "@shivaedev/errors": "0.4.0",
51
51
  "@shivaedev/http": "0.3.1",
52
- "@shivaedev/identity": "0.13.0",
52
+ "@shivaedev/identity": "0.15.0",
53
53
  "@shivaedev/local-postgres": "0.8.0",
54
- "@shivaedev/sql": "0.28.0"
54
+ "@shivaedev/sql": "0.30.0"
55
55
  },
56
56
  "devDependencies": {
57
57
  "@effect/platform-node": "4.0.6",
58
58
  "@effect/sql-pg": "4.0.6",
59
59
  "@effect/vitest": "4.0.6",
60
60
  "@shivaedev/access": "0.3.4",
61
- "@shivaedev/admin": "0.16.0",
62
- "@shivaedev/jobs": "0.28.1",
63
- "@shivaedev/quality": "0.52.0",
61
+ "@shivaedev/admin": "0.16.2",
62
+ "@shivaedev/jobs": "0.28.3",
63
+ "@shivaedev/quality": "0.53.0",
64
64
  "@shivaedev/test": "0.12.0",
65
- "@shivaedev/test-sql": "0.15.1",
66
- "@shivaedev/test-story": "0.31.1",
65
+ "@shivaedev/test-sql": "0.15.3",
66
+ "@shivaedev/test-story": "0.31.3",
67
67
  "@types/node": "24.19.2",
68
68
  "better-auth": "1.7.12",
69
69
  "effect": "4.0.6",
@@ -0,0 +1,51 @@
1
+ import { Clock, Context, Effect, ErrorReporter, Exit, Layer, Logger, Option, References, Tracer } from "effect";
2
+ import { redact, redactRecord } from "@shivaedev/errors/redact.ts";
3
+ import { RedactionPolicy, redactionForRpc } from "#RedactionPolicy.ts";
4
+
5
+ // Railway's receiver accepts traces only, so diagnostics use the same span exporter.
6
+ export const traceDiagnostics = Layer.unwrap(
7
+ Effect.gen(function* () {
8
+ const tracer = yield* Tracer.Tracer;
9
+ const clock = yield* Clock.Clock;
10
+ const policy = yield* RedactionPolicy;
11
+ // Request values can repeat sensitive error fields under otherwise public payload keys.
12
+ function exportPolicy(fiber: Logger.Options<unknown>["fiber"]) {
13
+ const sensitive = redactionForRpc(policy, fiber.getRef(References.CurrentLogAnnotations)["rpc.method"]);
14
+ return (key: string) => key === "rpc.payload" || sensitive(key);
15
+ }
16
+ function span(name: string, fiber: Logger.Options<unknown>["fiber"], timestamp: bigint) {
17
+ return tracer.span({
18
+ annotations: Context.empty(),
19
+ kind: "internal",
20
+ links: [],
21
+ name,
22
+ parent: Option.fromUndefinedOr(fiber.cache.span),
23
+ root: false,
24
+ sampled: true,
25
+ startTime: timestamp,
26
+ });
27
+ }
28
+ const logger = Logger.make((options) => {
29
+ const timestamp = clock.currentTimeNanosUnsafe();
30
+ const entry = span("effect.log", options.fiber, timestamp);
31
+ const annotations = options.fiber.getRef(References.CurrentLogAnnotations);
32
+ const sensitive = exportPolicy(options.fiber);
33
+ entry.event("log", timestamp, {
34
+ ...redactRecord(annotations, sensitive),
35
+ "log.message": redact(options.message, sensitive),
36
+ "log.severity": options.logLevel,
37
+ });
38
+ entry.end(timestamp, options.cause.reasons.length === 0 ? Exit.void : Exit.failCause(options.cause));
39
+ });
40
+ const reporter = ErrorReporter.make(({ attributes, cause, fiber, severity, timestamp }) => {
41
+ const entry = span("effect.error", fiber, timestamp);
42
+ for (const [key, value] of Object.entries(
43
+ redactRecord({ ...fiber.getRef(References.CurrentLogAnnotations), ...attributes, "error.severity": severity }, exportPolicy(fiber)),
44
+ )) {
45
+ entry.attribute(key, value);
46
+ }
47
+ entry.end(timestamp, Exit.failCause(cause));
48
+ });
49
+ return Layer.merge(Logger.layer([logger], { mergeWithExisting: true }), ErrorReporter.layer([reporter], { mergeWithExisting: true }));
50
+ }),
51
+ );
@@ -1,6 +1,6 @@
1
1
  import { createHash } from "node:crypto";
2
2
  import * as PgClient from "@effect/sql-pg/PgClient";
3
- import { Config, Context, Duration, Effect, Fiber, Layer, Option, Redacted, Schedule } from "effect";
3
+ import { Clock, Config, Context, Duration, Effect, Fiber, Layer, Option, Redacted, Schedule } from "effect";
4
4
  import * as Reactivity from "effect/reactivity/Reactivity";
5
5
  import { Migrator } from "effect/sql";
6
6
  import { LiveServer } from "@shivaedev/contract/LiveServer.ts";
@@ -15,6 +15,7 @@ import type { AppDatabaseOptions } from "#appHost.ts";
15
15
 
16
16
  export interface DatabaseConfig extends PostgresOptions {
17
17
  readonly changes?: Partial<Omit<PostgresChangesOptions, "client" | "listenerClient" | "connectionSetting" | "connectionTTL" | "resync">>;
18
+ readonly clock?: Clock.Clock;
18
19
  readonly databaseUrl?: Redacted.Redacted<string>;
19
20
  readonly listenDatabaseUrl?: Redacted.Redacted<string>;
20
21
  }
@@ -25,9 +26,10 @@ export function appDatabase<R, E = never>(options: AppDatabaseOptions<R, E>) {
25
26
  "connectionTTL": options.config?.connectionTTL ?? "10 minutes",
26
27
  idleTimeout: options.config?.idleTimeout ?? "1 minute",
27
28
  } satisfies DatabaseConfig;
29
+ const clock = Layer.succeed(Clock.Clock, config.clock ?? Clock.Clock.defaultValue());
28
30
  const pool = Layer.unwrap(
29
31
  Effect.map(options.config?.databaseUrl === undefined ? Config.Redacted("DATABASE_URL") : Effect.succeed(options.config.databaseUrl), (url) =>
30
- postgresLayer(url, config),
32
+ postgresLayer(url, config).pipe(Layer.provide(clock)),
31
33
  ),
32
34
  );
33
35
  const prepared = Layer.effectDiscard(prepareMigrations(options.migrations)).pipe(Layer.provideMerge(pool));
@@ -50,8 +52,9 @@ export function appDatabase<R, E = never>(options: AppDatabaseOptions<R, E>) {
50
52
  const listenerClient =
51
53
  listenUrl === undefined
52
54
  ? client
53
- : yield* Effect.map(Layer.build(postgresLayer(listenUrl, { ...config, maxConnections: 1, minConnections: 0 })), (context) =>
54
- Context.get(context, PgClient.PgClient),
55
+ : yield* Effect.map(
56
+ Layer.build(postgresLayer(listenUrl, { ...config, maxConnections: 1, minConnections: 0 }).pipe(Layer.provide(clock))),
57
+ (context) => Context.get(context, PgClient.PgClient),
55
58
  );
56
59
  let connectionSetting = options.config?.databaseUrl === undefined ? "DATABASE_URL" : "config.databaseUrl";
57
60
  if (listenUrl !== undefined) {
@@ -65,7 +68,7 @@ export function appDatabase<R, E = never>(options: AppDatabaseOptions<R, E>) {
65
68
  "connectionTTL": config.connectionTTL,
66
69
  listenerClient,
67
70
  resync: hints.resync(),
68
- });
71
+ }).pipe(Layer.provide(clock));
69
72
  }),
70
73
  ).pipe(Layer.provideMerge(base));
71
74
  }
@@ -73,8 +76,7 @@ export function appDatabase<R, E = never>(options: AppDatabaseOptions<R, E>) {
73
76
  function prepareMigrations<R, E>(migrations: AppDatabaseOptions<R, E>["migrations"]) {
74
77
  switch (migrations.mode) {
75
78
  case "check": {
76
- const schema = { ...migrations };
77
- delete schema.release;
79
+ const { release: _release, ...schema } = migrations;
78
80
  return assertPostgresMigrations(schema);
79
81
  }
80
82
  case "wait":
@@ -6,6 +6,7 @@ import { schemaSensitiveKeys } from "@shivaedev/errors/schemaSensitiveKeys.ts";
6
6
  import type { SessionShape } from "@shivaedev/identity/server/session.ts";
7
7
  import type { appDatabase } from "#appDatabase.ts";
8
8
  import type { AppHttpHostOptions } from "#appHost.ts";
9
+ import { browserErrorRoute } from "#browserErrorRoute.ts";
9
10
  import { healthRoute } from "#healthRoute.ts";
10
11
  import { hostApplicationRoutes } from "#hostApplicationRoutes.ts";
11
12
  import { hostAssets } from "#hostAssets.ts";
@@ -55,7 +56,7 @@ export function appHostHttp<
55
56
  const application = Layer.mergeAll(options.services ?? Layer.empty);
56
57
  const server = nodeHttpServer(host, options.config);
57
58
  const applicationRoutes = hostApplicationRoutes(options.routes, bodySize);
58
- const httpRoutes = Layer.mergeAll(routes, healthRoute, assets, applicationRoutes).pipe(
59
+ const httpRoutes = Layer.mergeAll(routes, healthRoute, browserErrorRoute(trustedProxy), assets, applicationRoutes).pipe(
59
60
  Layer.provide(nativeClientOrigins(nativeOrigins, trustedProxy, false, options.rpcPath)),
60
61
  Layer.provide(nativeClientOrigins(nativeOrigins, trustedProxy, options.nativeOrigins === undefined ? "preflight" : true)),
61
62
  );
@@ -0,0 +1,56 @@
1
+ import { ByteSize, Cause, Effect, ErrorReporter, Layer, Option, Schema } from "effect";
2
+ import { HttpIncomingMessage, HttpRouter, HttpServerRequest, HttpServerResponse } from "effect/http";
3
+ import * as HttpStatus from "effect/http/HttpStatus";
4
+ import { RateLimiter } from "effect/persistence";
5
+ import { localTransport, trustedProxyPeer } from "@shivaedev/identity/server/local.ts";
6
+
7
+ const BrowserErrorReport = Schema.Struct({
8
+ kind: Schema.Literals(["error", "unhandledrejection"]),
9
+ message: Schema.String,
10
+ stack: Schema.optional(Schema.String),
11
+ url: Schema.String,
12
+ });
13
+
14
+ const receiveReport = Effect.gen(function* () {
15
+ const parsed = yield* HttpServerRequest.schemaBodyJson(BrowserErrorReport).pipe(
16
+ Effect.provideService(HttpIncomingMessage.MaxBodySize, ByteSize.kibibytes(16)),
17
+ Effect.option,
18
+ );
19
+ if (Option.isNone(parsed)) {
20
+ return HttpServerResponse.empty({ status: HttpStatus.fromLiteral("BadRequest") });
21
+ }
22
+ const error = new Error(parsed.value.message);
23
+ error.name = "BrowserError";
24
+ if (parsed.value.stack !== undefined) {
25
+ error.stack = parsed.value.stack;
26
+ }
27
+ yield* ErrorReporter.report(Cause.die(error)).pipe(Effect.annotateLogs({ "browser.kind": parsed.value.kind, "url.full": parsed.value.url }));
28
+ return HttpServerResponse.empty({ status: HttpStatus.fromLiteral("Accepted") });
29
+ });
30
+
31
+ export function browserErrorRoute(trustedProxy?: string) {
32
+ return HttpRouter.use((router) =>
33
+ Effect.gen(function* () {
34
+ const limiter = yield* RateLimiter.RateLimiter;
35
+ const allowed = localTransport(trustedProxy);
36
+ const trusted = trustedProxyPeer(trustedProxy);
37
+ yield* router.add(
38
+ "POST",
39
+ "/_platform/errors",
40
+ Effect.gen(function* () {
41
+ const request = yield* HttpServerRequest.HttpServerRequest;
42
+ if (!allowed(request)) {
43
+ return HttpServerResponse.empty({ status: HttpStatus.fromLiteral("Forbidden") });
44
+ }
45
+ const peer = Option.getOrElse(request.remoteAddress, () => "unknown");
46
+ const client = trusted(peer) ? (request.headers["x-real-ip"] ?? peer) : peer;
47
+ const accepted = yield* limiter.consume({ key: client, limit: 20, window: "1 minute" }).pipe(Effect.isSuccess);
48
+ if (!accepted) {
49
+ return HttpServerResponse.empty({ status: HttpStatus.fromLiteral("TooManyRequests") });
50
+ }
51
+ return yield* receiveReport;
52
+ }),
53
+ );
54
+ }),
55
+ ).pipe(Layer.provide(RateLimiter.layer.pipe(Layer.provide(RateLimiter.layerStoreMemory))));
56
+ }
@@ -1,7 +1,9 @@
1
1
  import { Config, Effect, Layer, Schema } from "effect";
2
2
  import { OtlpSerialization, OtlpTracer } from "effect/observability";
3
+ import { traceDiagnostics } from "#adapters/traceDiagnostics.ts";
3
4
  import { otlpHttpClient } from "#otlpHttpClient.ts";
4
5
  import { RedactionPolicy } from "#RedactionPolicy.ts";
6
+ import { redactingDiagnostics } from "#redactingDiagnostics.ts";
5
7
  import { redactingTracer } from "#redactingTracer.ts";
6
8
  import { safeOtlpSerialization } from "#safeOtlpSerialization.ts";
7
9
 
@@ -56,6 +58,10 @@ export const otlpTracing: Layer.Layer<never, Config.ConfigError> = Layer.unwrap(
56
58
  ),
57
59
  Layer.provide(otlpHttpClient(requestTimeout)),
58
60
  );
59
- return redactingTracer(yield* RedactionPolicy).pipe(Layer.provideMerge(tracer));
61
+ const sensitive = yield* RedactionPolicy;
62
+ return redactingDiagnostics(sensitive).pipe(
63
+ Layer.provideMerge(traceDiagnostics),
64
+ Layer.provideMerge(redactingTracer(sensitive).pipe(Layer.provideMerge(tracer))),
65
+ );
60
66
  }),
61
67
  );