@claxedo/workspace-relay 0.7.0 → 0.8.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/dist/main.d.ts CHANGED
@@ -1,22 +1,20 @@
1
1
  import { type WorkspaceRelayBunDrainController } from "./bun";
2
2
  import { type WorkspaceRelayDirectory } from "./directory";
3
3
  import { type RelayHostPublicKey, type RevocationLookup, type WorkspaceRelayTarget } from "./server";
4
- import type { RelayKey } from "./auth";
4
+ import { type RelayKey } from "./auth";
5
5
  export { createCachedRevocationClient, createCachedTargetClient } from "./server";
6
6
  /**
7
- * W2c (2026-07-28-001): PostHog is the relay's error sink — one vendor
8
- * carries error tracking for every runtime behind one distinct_id space.
7
+ * PostHog is the relay's error sink — one vendor carries error tracking for
8
+ * every runtime behind one distinct_id space.
9
9
  *
10
10
  * Sending requires two independent opt-ins: `CLAXEDO_TELEMETRY_MODE=on` AND
11
11
  * `CLAXEDO_POSTHOG_KEY` (`POSTHOG_KEY` accepted as a fallback — the same
12
- * unprefixed name claxedo-server's posthog.ts already reads). Any other
13
- * combination → no `PostHog` client is ever constructed: zero SDK overhead,
14
- * zero network — a clean no-op safe to ship before the telemetry account
15
- * exists. Host defaults to `https://us.i.posthog.com` (the canonical ingest
16
- * host — NOT the legacy `app.posthog.com` default some SDKs ship). Release =
17
- * git SHA passed by the D11 deploy workflow (`CLAXEDO_RELEASE`; `GIT_SHA`
18
- * accepted as alias); captures are tagged unit=relay + deployment_mode
19
- * (absent → "self-host", mirroring D9's default).
12
+ * unprefixed name claxedo-server's posthog.ts reads). Any other combination
13
+ * constructs no `PostHog` client: zero SDK overhead, zero network. Host
14
+ * defaults to `https://us.i.posthog.com` (the ingest host, not the legacy
15
+ * `app.posthog.com` default some SDKs ship). Release is the git SHA from
16
+ * `CLAXEDO_RELEASE` (`GIT_SHA` accepted as alias); captures are tagged
17
+ * unit=relay + deployment_mode (absent → "local").
20
18
  *
21
19
  * `posthog-node` runs fine on Bun (`Bun.serve`), unlike the Cloudflare
22
20
  * Worker, which keeps it off its import graph entirely (see worker.ts).
@@ -122,17 +120,10 @@ export declare function loadRuntimeAccessKeyOrJwks(env: LoadRuntimeAccessKeyEnv)
122
120
  */
123
121
  export type LoadRelayHostKeyMaterialEnv = {
124
122
  /**
125
- * Used to gate the production fail-closed check for the RHT signing key.
126
- * If `production` and no signing key PEM is configured, the loader exits
127
- * with code 2 rather than silently generating an ephemeral key (which
128
- * would be different on every instance and break verification across a
129
- * multi-instance deploy).
130
- *
131
- * Note: T2's `validateProductionEnv` is the canonical home for top-level
132
- * env validation, but this check lives here because the loader already
133
- * inspects the signing-key env var and the failure mode is local. The
134
- * boot path could optionally re-route through `validateProductionEnv` in
135
- * a future refactor.
123
+ * Gates the production fail-closed check: with no signing-key PEM in
124
+ * `production` the loader exits 2 instead of generating an ephemeral key.
125
+ * The check lives here rather than in `validateProductionEnv` because the
126
+ * loader already inspects the signing-key env var.
136
127
  */
137
128
  NODE_ENV?: string | undefined;
138
129
  CLAXEDO_RELAY_HOST_SIGNING_KEY_PEM?: string | undefined;
@@ -148,7 +139,7 @@ export type RelayHostKeyMaterial = {
148
139
  };
149
140
  export declare function loadRelayHostKeyMaterial(env: LoadRelayHostKeyMaterialEnv): Promise<RelayHostKeyMaterial>;
150
141
  /**
151
- * T16: parse `CLAXEDO_RELAY_AUDIT_ACCEPT_SAMPLE_RATE` into a number in [0, 1].
142
+ * Parse `CLAXEDO_RELAY_AUDIT_ACCEPT_SAMPLE_RATE` into a number in [0, 1].
152
143
  * Falls back to a NODE_ENV-gated default (production: 0.1, dev/test: 1.0) if
153
144
  * unset, empty, or out of range. Exported for tests.
154
145
  */
@@ -158,7 +149,7 @@ export type ParseAuditAcceptSampleRateEnv = {
158
149
  };
159
150
  export declare function parseAuditAcceptSampleRate(env: ParseAuditAcceptSampleRateEnv): number;
160
151
  /**
161
- * T31: parse the `CLAXEDO_RELAY_METRICS_TOKEN` env var. Returns `undefined`
152
+ * Parse the `CLAXEDO_RELAY_METRICS_TOKEN` env var. Returns `undefined`
162
153
  * for missing/empty/whitespace-only values so the relay can fall back to its
163
154
  * loopback-only `/metrics` access policy.
164
155
  */
@@ -177,18 +168,28 @@ export declare function directHttpConcurrencyFromEnv(env: DirectHttpConcurrencyE
177
168
  export type ResolverClientCacheOptions = {
178
169
  targetCacheTtlMs?: number;
179
170
  revocationCacheTtlMs?: number;
171
+ /**
172
+ * Absolute URL of the control plane's host-generation lookup. Unset derives
173
+ * `<resolver base>/host-generation`, the route every resolver base serves
174
+ * next to `/target` and `/revocation`.
175
+ */
176
+ hostGenerationUrl?: string;
177
+ hostGenerationCacheTtlMs?: number;
180
178
  };
181
179
  export type ResolverClientCacheEnv = {
182
180
  CLAXEDO_RELAY_TARGET_CACHE_TTL_MS?: string | undefined;
183
181
  CLAXEDO_RELAY_REVOCATION_CACHE_TTL_MS?: string | undefined;
182
+ CLAXEDO_RELAY_HOST_GENERATION_URL?: string | undefined;
183
+ CLAXEDO_RELAY_HOST_GENERATION_CACHE_TTL_MS?: string | undefined;
184
184
  };
185
185
  export declare function resolverClientCacheOptionsFromEnv(env: ResolverClientCacheEnv): ResolverClientCacheOptions;
186
186
  export declare function createResolverClient(baseUrl: string, token: string | undefined, options?: ResolverClientCacheOptions): {
187
187
  target: (workspaceId: string, hostId: string) => Promise<WorkspaceRelayTarget | undefined>;
188
188
  revocation: RevocationLookup;
189
+ hostGeneration: import("./server").HostGenerationLookup;
189
190
  };
190
191
  /**
191
- * T9: graceful SIGTERM drain wiring.
192
+ * Graceful SIGTERM drain wiring.
192
193
  *
193
194
  * On `SIGTERM` (or `SIGINT` for local dev) the relay must:
194
195
  * 1. Flip the drain flag so `/health` reports 503 and Fly removes the
@@ -197,7 +198,7 @@ export declare function createResolverClient(baseUrl: string, token: string | un
197
198
  * 2. Wait up to `drainTimeoutMs` (default 30 s, override via
198
199
  * `CLAXEDO_RELAY_DRAIN_TIMEOUT_MS`) for the in-flight tunnel HTTP
199
200
  * response map to empty across every connected host tunnel.
200
- * 3. Release the directory's TTL sweep timer (T18 added `dispose()`) so
201
+ * 3. Release the directory's TTL sweep timer via `directory.dispose()` so
201
202
  * the process can exit cleanly without a dangling `setInterval`.
202
203
  * 4. Exit with code 0.
203
204
  *
@@ -219,6 +220,12 @@ export type ShutdownDrainHandlerOptions = {
219
220
  signals?: NodeJS.Signals[];
220
221
  /** Defaults to a no-op (we let Bun.serve get GC'd as part of process exit). */
221
222
  stopServer?: () => Promise<void> | void;
223
+ /**
224
+ * Upper bound on `stopServer`. A wedged socket close must not outlast the
225
+ * platform's kill timeout, or a graceful exit becomes a SIGKILL that skips
226
+ * `directory.dispose()`. Defaults to 5 s; tests override it to stay fast.
227
+ */
228
+ stopTimeoutMs?: number;
222
229
  };
223
230
  export type ShutdownDrainHandle = {
224
231
  trigger(): Promise<void>;
@@ -232,12 +239,14 @@ export type FatalProcessHandlerOptions = {
232
239
  log?: (message: string) => void;
233
240
  register?: boolean;
234
241
  /**
235
- * W2c: error-tracker hook, invoked (and awaited) before teardown so a fatal
242
+ * Error-tracker hook, invoked (and awaited) before teardown so a fatal
236
243
  * crash reaches PostHog before the process exits. Failures are logged and
237
244
  * never block the exit path. Defaults to none (tests, key-absent runs).
238
245
  */
239
246
  report?: (error: unknown, source: "uncaughtException" | "unhandledRejection") => void | Promise<void>;
240
247
  stopServer?: () => Promise<void> | void;
248
+ /** Upper bound on `stopServer`; see `ShutdownDrainHandlerOptions.stopTimeoutMs`. */
249
+ stopTimeoutMs?: number;
241
250
  };
242
251
  export type FatalProcessHandle = {
243
252
  trigger(error: unknown, source: "uncaughtException" | "unhandledRejection"): Promise<void>;