@hadoku/service-kernel 0.1.30 → 0.1.32

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.
@@ -74,7 +74,7 @@ export function createEdgeAuth(config) {
74
74
  // nothing observable, which is worse than not having one.
75
75
  if (typeof headers['x-hadoku-tier'] !== 'string' || headers['x-hadoku-tier'] === '') {
76
76
  // identity-model-disable-next-line G5: LEGITIMATE: R8's dev carve-out, the game template's old
77
- // apps/server/src/edge-auth.ts, moved into cardtable's service-kernel package (templates/game and
77
+ // packages/game-server/src/edge-auth.ts, moved into cardtable's service-kernel package (templates/game and
78
78
  // bomberman import it, 880bf59b6; templates/tunnel-* and hadoku-wiki since 2026-11-11, which
79
79
  // retired their three template entries) on 2026-11-07 (cardtable 9bcdd8c82, 0d01c363e).
80
80
  // createEdgeAuth's sanitizeHeaders bare-local branch writes x-hadoku-tier = config.devTier() and
@@ -52,6 +52,14 @@ export interface BusyReport {
52
52
  count: number;
53
53
  runs: BusyRun[];
54
54
  }
55
+ /**
56
+ * How a request reached this server, read from the headers alone: `edge` when it carries the
57
+ * edge's seal header (claimed, not verified: a forged one still reads `edge`, and so still alerts),
58
+ * `tunnel` when Cloudflare proxied it but the edge did not (a direct hit on the tunnel hostname),
59
+ * `local` when nothing proxied it (a probe from this host). A remote caller cannot read as `local`:
60
+ * it cannot strip the headers Cloudflare adds after it.
61
+ */
62
+ export declare function arrivedVia(headers: Record<string, unknown>): 'edge' | 'tunnel' | 'local';
55
63
  export declare function isLocalProbe(req: Pick<Request, 'socket' | 'headers'>): boolean;
56
64
  /** `report` computes the app's own `BusyReport`; this adds the local-only gate and fail-safe. */
57
65
  export declare function busyHandler(report: () => BusyReport): RequestHandler;
@@ -16,11 +16,23 @@ const PROXIED_HEADERS = [
16
16
  'forwarded',
17
17
  'x-edge-auth',
18
18
  ];
19
+ /**
20
+ * How a request reached this server, read from the headers alone: `edge` when it carries the
21
+ * edge's seal header (claimed, not verified: a forged one still reads `edge`, and so still alerts),
22
+ * `tunnel` when Cloudflare proxied it but the edge did not (a direct hit on the tunnel hostname),
23
+ * `local` when nothing proxied it (a probe from this host). A remote caller cannot read as `local`:
24
+ * it cannot strip the headers Cloudflare adds after it.
25
+ */
26
+ export function arrivedVia(headers) {
27
+ if (headers['x-edge-auth'] !== undefined)
28
+ return 'edge';
29
+ return PROXIED_HEADERS.some((h) => headers[h] !== undefined) ? 'tunnel' : 'local';
30
+ }
19
31
  export function isLocalProbe(req) {
20
32
  const addr = req.socket?.remoteAddress;
21
33
  if (addr === undefined || !LOOPBACK.has(addr))
22
34
  return false;
23
- return !PROXIED_HEADERS.some((h) => req.headers[h] !== undefined);
35
+ return arrivedVia(req.headers) === 'local';
24
36
  }
25
37
  /** `report` computes the app's own `BusyReport`; this adds the local-only gate and fail-safe. */
26
38
  export function busyHandler(report) {
@@ -1,4 +1,4 @@
1
- export { busyHandler, isLocalProbe, type BusyReport, type BusyRun } from './busy.js';
1
+ export { arrivedVia, busyHandler, isLocalProbe, type BusyReport, type BusyRun } from './busy.js';
2
2
  export { bootClock } from './bootClock.js';
3
3
  export { closeConnections, sendThenFlush, type Closable, type Flushable } from './flush-sockets.js';
4
4
  export { allReleases, announceRelease, creditCounts, creditMark, creditsBody, creditsIn, CREDITS_TITLE, forDiscord, latestRelease, parseNotes, releaseEmbeds, showCredits, splitBody, type AnnounceOptions, type CreditCount, type Embed, type ReleaseNotes, type ReleaseOrdering, } from './announce.js';
@@ -1,4 +1,4 @@
1
- export { busyHandler, isLocalProbe } from "./busy.js";
1
+ export { arrivedVia, busyHandler, isLocalProbe } from "./busy.js";
2
2
  export { bootClock } from "./bootClock.js";
3
3
  export { closeConnections, sendThenFlush } from "./flush-sockets.js";
4
4
  export { allReleases, announceRelease, creditCounts, creditMark, creditsBody, creditsIn, CREDITS_TITLE, forDiscord, latestRelease, parseNotes, releaseEmbeds, showCredits, splitBody, } from "./announce.js";
@@ -3,7 +3,7 @@
3
3
  * platform half. Knows no game: the service id, the deployment site and the refusal surface are
4
4
  * all parameters, so an app that posts under `service: 'cardtable'` and one that posts under a
5
5
  * second game's id read apart in the same monitoring store. See the app's own adapter (this
6
- * wave's `apps/server/src/telemetry.ts`) for the one place those values get bound.
6
+ * wave's `packages/game-server/src/telemetry.ts`) for the one place those values get bound.
7
7
  *
8
8
  * Everything here is fire-and-forget. A post that fails is logged on stdout (pm2 keeps it), never
9
9
  * retried, and never delays the request that caused it. One event per (name, caller, incident
@@ -76,11 +76,11 @@ export declare function userAgentOf(headers: Headers): string | null;
76
76
  */
77
77
  export declare function callerContext(headers: Headers): TelemetryContext;
78
78
  /**
79
- * A seal below the edge refused a caller. With the edge in front this should
80
- * never fire: one means a direct hit on the tunnel host, or an edge rule wider
81
- * than this server's floor — both worth a look. `Surface` is an open string:
82
- * this module knows no game's surface names, so the app's own adapter narrows
83
- * it to a closed set.
79
+ * A seal below the edge refused a caller. `via` ({@link arrivedVia}) says which kind: `edge` is an
80
+ * edge rule wider than this server's floor and needs a look now; `tunnel` is a direct hit on the
81
+ * tunnel hostname and `local` a probe from this host, both refused as they should be (a public
82
+ * tunnel hostname is scanned daily). `Surface` is an open string: this module knows no game's
83
+ * surface names, so the app's own adapter narrows it to a closed set.
84
84
  */
85
85
  export declare function reportSealRefused<Surface extends string>(surface: Surface, headers: Headers, path: string | null): void;
86
86
  export interface FirstSeenOptions {
@@ -3,7 +3,7 @@
3
3
  * platform half. Knows no game: the service id, the deployment site and the refusal surface are
4
4
  * all parameters, so an app that posts under `service: 'cardtable'` and one that posts under a
5
5
  * second game's id read apart in the same monitoring store. See the app's own adapter (this
6
- * wave's `apps/server/src/telemetry.ts`) for the one place those values get bound.
6
+ * wave's `packages/game-server/src/telemetry.ts`) for the one place those values get bound.
7
7
  *
8
8
  * Everything here is fire-and-forget. A post that fails is logged on stdout (pm2 keeps it), never
9
9
  * retried, and never delays the request that caused it. One event per (name, caller, incident
@@ -11,6 +11,7 @@
11
11
  * scanner hammering the seal costs monitoring one row a minute, not one per request.
12
12
  */
13
13
  import { existsSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
14
+ import { arrivedVia } from "../lifecycle/busy.js";
14
15
  /** What `report` does before boot installs a sink, and in every test that installs none. */
15
16
  const NOOP = () => { };
16
17
  let installed = NOOP;
@@ -148,14 +149,14 @@ export function callerContext(headers) {
148
149
  };
149
150
  }
150
151
  /**
151
- * A seal below the edge refused a caller. With the edge in front this should
152
- * never fire: one means a direct hit on the tunnel host, or an edge rule wider
153
- * than this server's floor — both worth a look. `Surface` is an open string:
154
- * this module knows no game's surface names, so the app's own adapter narrows
155
- * it to a closed set.
152
+ * A seal below the edge refused a caller. `via` ({@link arrivedVia}) says which kind: `edge` is an
153
+ * edge rule wider than this server's floor and needs a look now; `tunnel` is a direct hit on the
154
+ * tunnel hostname and `local` a probe from this host, both refused as they should be (a public
155
+ * tunnel hostname is scanned daily). `Surface` is an open string: this module knows no game's
156
+ * surface names, so the app's own adapter narrows it to a closed set.
156
157
  */
157
158
  export function reportSealRefused(surface, headers, path) {
158
- report('seal-refused', { surface, path, ...callerContext(headers) });
159
+ report('seal-refused', { surface, path, via: arrivedVia(headers), ...callerContext(headers) });
159
160
  }
160
161
  /**
161
162
  * Middleware, mounted below the tier floor: the first request this server ever
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hadoku/service-kernel",
3
- "version": "0.1.30",
4
- "gitHead": "0e2c0614f2169adf001bfe53b2b475cf15642866",
3
+ "version": "0.1.32",
4
+ "gitHead": "103d8667e71b18c56446a9d5a884b551c079732c",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "description": "The server parts any game keeps: edge auth and the tier gate, base path and bundle check, health and the busy probe, lifecycle, the JSON logger, the state directory, telemetry and capacity, per-caller limits, the browser relays, the erase registry, and createGameServer, which boots a game from its config and plugins. Knows no game; the app binds its service id, prefix and env names. MIT; imports only node built-ins, express, socket.io and @wolffm/*.",