@facilis.dev/nitro 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +18 -2
- package/dist/config.d.ts +30 -0
- package/dist/config.js +112 -0
- package/dist/constants.d.ts +24 -0
- package/dist/constants.js +24 -0
- package/dist/facade.d.ts +37 -0
- package/dist/facade.js +121 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +14 -0
- package/dist/middleware/context.d.ts +5 -0
- package/dist/middleware/context.js +86 -0
- package/dist/middleware/cors.d.ts +10 -0
- package/dist/middleware/cors.js +34 -0
- package/dist/middleware/session.d.ts +9 -0
- package/dist/middleware/session.js +18 -0
- package/dist/module.d.ts +7 -0
- package/dist/module.js +234 -0
- package/dist/rolldown-parser.d.ts +3 -0
- package/dist/rolldown-parser.js +66 -0
- package/dist/route-metadata.d.ts +22 -0
- package/dist/route-metadata.js +161 -0
- package/dist/routes/dev-query.post.d.ts +10 -0
- package/dist/routes/dev-query.post.js +49 -0
- package/dist/routes/dev-schema.get.d.ts +9 -0
- package/dist/routes/dev-schema.get.js +34 -0
- package/dist/routes/dev-view.post.d.ts +11 -0
- package/dist/routes/dev-view.post.js +61 -0
- package/dist/routes/health.get.d.ts +8 -0
- package/dist/routes/health.get.js +18 -0
- package/dist/routes/manifest-revision.get.d.ts +8 -0
- package/dist/routes/manifest-revision.get.js +26 -0
- package/dist/routes/manifest.get.d.ts +8 -0
- package/dist/routes/manifest.get.js +68 -0
- package/dist/routes/openapi.get.d.ts +8 -0
- package/dist/routes/openapi.get.js +29 -0
- package/dist/routes/sso.d.ts +2 -0
- package/dist/routes/sso.js +216 -0
- package/dist/routes/token.post.d.ts +10 -0
- package/dist/routes/token.post.js +75 -0
- package/dist/runtime/boot-runtimes.d.ts +21 -0
- package/dist/runtime/boot-runtimes.js +38 -0
- package/dist/runtime/bootstrap.d.ts +47 -0
- package/dist/runtime/bootstrap.js +214 -0
- package/dist/runtime/config.d.ts +27 -0
- package/dist/runtime/config.js +44 -0
- package/dist/runtime/cors-policy.d.ts +16 -0
- package/dist/runtime/cors-policy.js +88 -0
- package/dist/runtime/db-bootstrap.d.ts +9 -0
- package/dist/runtime/db-bootstrap.js +87 -0
- package/dist/runtime/db-target.d.ts +21 -0
- package/dist/runtime/db-target.js +52 -0
- package/dist/runtime/dev-db-persistence.d.ts +39 -0
- package/dist/runtime/dev-db-persistence.js +124 -0
- package/dist/runtime/dev-query.d.ts +38 -0
- package/dist/runtime/dev-query.js +87 -0
- package/dist/runtime/env.d.ts +9 -0
- package/dist/runtime/env.js +14 -0
- package/dist/runtime/http-guard.d.ts +16 -0
- package/dist/runtime/http-guard.js +42 -0
- package/dist/runtime/http.d.ts +11 -0
- package/dist/runtime/http.js +18 -0
- package/dist/runtime/jobs/boot.d.ts +20 -0
- package/dist/runtime/jobs/boot.js +77 -0
- package/dist/runtime/jobs/contracts.d.ts +161 -0
- package/dist/runtime/jobs/contracts.js +1 -0
- package/dist/runtime/jobs/db-store.d.ts +21 -0
- package/dist/runtime/jobs/db-store.js +210 -0
- package/dist/runtime/jobs/definitions.d.ts +14 -0
- package/dist/runtime/jobs/definitions.js +31 -0
- package/dist/runtime/jobs/engine-support.d.ts +22 -0
- package/dist/runtime/jobs/engine-support.js +32 -0
- package/dist/runtime/jobs/engine.d.ts +6 -0
- package/dist/runtime/jobs/engine.js +261 -0
- package/dist/runtime/jobs/executor.d.ts +11 -0
- package/dist/runtime/jobs/executor.js +27 -0
- package/dist/runtime/jobs/memory-store.d.ts +7 -0
- package/dist/runtime/jobs/memory-store.js +183 -0
- package/dist/runtime/jobs/row-mapping.d.ts +28 -0
- package/dist/runtime/jobs/row-mapping.js +61 -0
- package/dist/runtime/jobs/runtime.d.ts +24 -0
- package/dist/runtime/jobs/runtime.js +86 -0
- package/dist/runtime/logging/audit-chain.d.ts +54 -0
- package/dist/runtime/logging/audit-chain.js +102 -0
- package/dist/runtime/logging/bootstrap-logging.d.ts +28 -0
- package/dist/runtime/logging/bootstrap-logging.js +26 -0
- package/dist/runtime/logging/entry.d.ts +14 -0
- package/dist/runtime/logging/entry.js +85 -0
- package/dist/runtime/logging/file-sink.d.ts +24 -0
- package/dist/runtime/logging/file-sink.js +128 -0
- package/dist/runtime/logging/log-settings.d.ts +52 -0
- package/dist/runtime/logging/log-settings.js +93 -0
- package/dist/runtime/logging/log-sink.d.ts +18 -0
- package/dist/runtime/logging/log-sink.js +22 -0
- package/dist/runtime/logging/redact.d.ts +31 -0
- package/dist/runtime/logging/redact.js +106 -0
- package/dist/runtime/logging/runtime.d.ts +25 -0
- package/dist/runtime/logging/runtime.js +114 -0
- package/dist/runtime/logging/sudo-bridge.d.ts +13 -0
- package/dist/runtime/logging/sudo-bridge.js +38 -0
- package/dist/runtime/manifest-data.d.ts +28 -0
- package/dist/runtime/manifest-data.js +70 -0
- package/dist/runtime/manifest-response.d.ts +45 -0
- package/dist/runtime/manifest-response.js +50 -0
- package/dist/runtime/manifest-sections.d.ts +20 -0
- package/dist/runtime/manifest-sections.js +59 -0
- package/dist/runtime/manifest-service.d.ts +16 -0
- package/dist/runtime/manifest-service.js +66 -0
- package/dist/runtime/project-config.d.ts +8 -0
- package/dist/runtime/project-config.js +22 -0
- package/dist/runtime/project-files.d.ts +12 -0
- package/dist/runtime/project-files.js +99 -0
- package/dist/runtime/rate-limit.d.ts +6 -0
- package/dist/runtime/rate-limit.js +6 -0
- package/dist/runtime/revision-service.d.ts +15 -0
- package/dist/runtime/revision-service.js +26 -0
- package/dist/runtime/sql.d.ts +8 -0
- package/dist/runtime/sql.js +23 -0
- package/dist/runtime/sso.d.ts +40 -0
- package/dist/runtime/sso.js +98 -0
- package/dist/runtime/state.d.ts +7 -0
- package/dist/runtime/state.js +7 -0
- package/dist/runtime/storage-keys.d.ts +9 -0
- package/dist/runtime/storage-keys.js +82 -0
- package/dist/runtime/storage-target.d.ts +25 -0
- package/dist/runtime/storage-target.js +155 -0
- package/dist/runtime/system-role.d.ts +9 -0
- package/dist/runtime/system-role.js +21 -0
- package/dist/runtime/tasks/boot.d.ts +20 -0
- package/dist/runtime/tasks/boot.js +32 -0
- package/dist/runtime/tasks/contracts.d.ts +70 -0
- package/dist/runtime/tasks/contracts.js +1 -0
- package/dist/runtime/tasks/db-store.d.ts +18 -0
- package/dist/runtime/tasks/db-store.js +139 -0
- package/dist/runtime/tasks/row-mapping.d.ts +11 -0
- package/dist/runtime/tasks/row-mapping.js +69 -0
- package/dist/runtime/tasks/runtime.d.ts +7 -0
- package/dist/runtime/tasks/runtime.js +162 -0
- package/dist/runtime/tasks/tasks-test-harness.d.ts +16 -0
- package/dist/runtime/tasks/tasks-test-harness.js +70 -0
- package/dist/runtime/tenant.d.ts +10 -0
- package/dist/runtime/tenant.js +13 -0
- package/dist/runtime/workflows/boot.d.ts +25 -0
- package/dist/runtime/workflows/boot.js +75 -0
- package/dist/runtime/workflows/contracts.d.ts +96 -0
- package/dist/runtime/workflows/contracts.js +1 -0
- package/dist/runtime/workflows/db-store.d.ts +18 -0
- package/dist/runtime/workflows/db-store.js +128 -0
- package/dist/runtime/workflows/definitions.d.ts +14 -0
- package/dist/runtime/workflows/definitions.js +50 -0
- package/dist/runtime/workflows/dispatch.d.ts +4 -0
- package/dist/runtime/workflows/dispatch.js +119 -0
- package/dist/runtime/workflows/row-mapping.d.ts +5 -0
- package/dist/runtime/workflows/row-mapping.js +38 -0
- package/dist/runtime/workflows/runner.d.ts +15 -0
- package/dist/runtime/workflows/runner.js +89 -0
- package/dist/runtime/workflows/runtime.d.ts +14 -0
- package/dist/runtime/workflows/runtime.js +129 -0
- package/dist/runtime/workflows/steps.d.ts +14 -0
- package/dist/runtime/workflows/steps.js +49 -0
- package/dist/runtime/workflows/support.d.ts +20 -0
- package/dist/runtime/workflows/support.js +36 -0
- package/dist/runtime/workflows/transitions.d.ts +8 -0
- package/dist/runtime/workflows/transitions.js +184 -0
- package/dist/runtime/workflows/workflows-test-harness.d.ts +62 -0
- package/dist/runtime/workflows/workflows-test-harness.js +178 -0
- package/dist/session-cookie.d.ts +13 -0
- package/dist/session-cookie.js +48 -0
- package/dist/storage.d.ts +50 -0
- package/dist/storage.js +118 -0
- package/dist/types.d.ts +44 -0
- package/dist/types.js +1 -0
- package/dist/virtual-ids.d.ts +17 -0
- package/dist/virtual-ids.js +17 -0
- package/dist/vite.d.ts +22 -0
- package/dist/vite.js +135 -0
- package/package.json +61 -4
- package/src/config.ts +120 -0
- package/src/constants.ts +24 -0
- package/src/facade.ts +153 -0
- package/src/index.ts +44 -0
- package/src/middleware/context.ts +106 -0
- package/src/middleware/cors.ts +42 -0
- package/src/middleware/session.ts +23 -0
- package/src/module.ts +278 -0
- package/src/rolldown-parser.ts +79 -0
- package/src/route-metadata-test-harness.ts +62 -0
- package/src/route-metadata.ts +194 -0
- package/src/routes/dev-query.post.ts +53 -0
- package/src/routes/dev-schema.get.ts +43 -0
- package/src/routes/dev-view.post.ts +66 -0
- package/src/routes/health.get.ts +26 -0
- package/src/routes/manifest-revision.get.ts +38 -0
- package/src/routes/manifest.get.ts +111 -0
- package/src/routes/openapi.get.ts +34 -0
- package/src/routes/sso.ts +247 -0
- package/src/routes/token.post.ts +89 -0
- package/src/runtime/boot-runtimes.ts +69 -0
- package/src/runtime/bootstrap.ts +300 -0
- package/src/runtime/config.ts +60 -0
- package/src/runtime/cors-policy.ts +107 -0
- package/src/runtime/db-bootstrap.ts +99 -0
- package/src/runtime/db-target.ts +87 -0
- package/src/runtime/dev-db-persistence.ts +146 -0
- package/src/runtime/dev-query.ts +124 -0
- package/src/runtime/env.ts +18 -0
- package/src/runtime/http-guard.ts +50 -0
- package/src/runtime/http.ts +30 -0
- package/src/runtime/jobs/boot.ts +97 -0
- package/src/runtime/jobs/contracts.ts +165 -0
- package/src/runtime/jobs/db-store-test-harness.ts +98 -0
- package/src/runtime/jobs/db-store.ts +273 -0
- package/src/runtime/jobs/definitions.ts +42 -0
- package/src/runtime/jobs/engine-support.ts +44 -0
- package/src/runtime/jobs/engine.ts +296 -0
- package/src/runtime/jobs/executor.ts +37 -0
- package/src/runtime/jobs/memory-store.ts +222 -0
- package/src/runtime/jobs/row-mapping.ts +67 -0
- package/src/runtime/jobs/runtime.ts +110 -0
- package/src/runtime/logging/audit-chain.ts +135 -0
- package/src/runtime/logging/bootstrap-logging.ts +62 -0
- package/src/runtime/logging/entry.ts +99 -0
- package/src/runtime/logging/file-sink.ts +157 -0
- package/src/runtime/logging/log-settings.ts +166 -0
- package/src/runtime/logging/log-sink.ts +31 -0
- package/src/runtime/logging/redact.ts +108 -0
- package/src/runtime/logging/runtime.ts +163 -0
- package/src/runtime/logging/sudo-bridge.ts +41 -0
- package/src/runtime/manifest-data.ts +103 -0
- package/src/runtime/manifest-response.ts +95 -0
- package/src/runtime/manifest-sections.ts +79 -0
- package/src/runtime/manifest-service.ts +83 -0
- package/src/runtime/project-config.ts +25 -0
- package/src/runtime/project-files.ts +103 -0
- package/src/runtime/rate-limit.ts +12 -0
- package/src/runtime/revision-service.ts +38 -0
- package/src/runtime/sql.ts +24 -0
- package/src/runtime/sso.ts +153 -0
- package/src/runtime/state.ts +7 -0
- package/src/runtime/storage-keys.ts +95 -0
- package/src/runtime/storage-target.ts +238 -0
- package/src/runtime/system-role.ts +26 -0
- package/src/runtime/tasks/boot.ts +49 -0
- package/src/runtime/tasks/contracts.ts +77 -0
- package/src/runtime/tasks/db-store.ts +191 -0
- package/src/runtime/tasks/row-mapping.ts +75 -0
- package/src/runtime/tasks/runtime.ts +192 -0
- package/src/runtime/tasks/tasks-test-harness.ts +92 -0
- package/src/runtime/tenant.ts +15 -0
- package/src/runtime/workflows/boot.ts +97 -0
- package/src/runtime/workflows/contracts.ts +114 -0
- package/src/runtime/workflows/db-store.ts +156 -0
- package/src/runtime/workflows/definitions.ts +75 -0
- package/src/runtime/workflows/dispatch.ts +148 -0
- package/src/runtime/workflows/row-mapping.ts +54 -0
- package/src/runtime/workflows/runner.ts +105 -0
- package/src/runtime/workflows/runtime.ts +161 -0
- package/src/runtime/workflows/steps.ts +74 -0
- package/src/runtime/workflows/support.ts +60 -0
- package/src/runtime/workflows/transitions.ts +259 -0
- package/src/runtime/workflows/workflows-test-harness.ts +238 -0
- package/src/session-cookie.ts +69 -0
- package/src/storage.ts +173 -0
- package/src/types.ts +51 -0
- package/src/virtual-ids.ts +18 -0
- package/src/virtual-modules.d.ts +53 -0
- package/src/vite.ts +175 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { resolve as resolvePath } from "node:path";
|
|
2
|
+
|
|
3
|
+
import { isLogLevel, type LogLevel } from "@facilis.dev/core";
|
|
4
|
+
|
|
5
|
+
import { isProductionEnvironment } from "../env.ts";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Log destination resolution (D-119, SPEC §8.7).
|
|
9
|
+
*
|
|
10
|
+
* Where entries go is a deployment concern, so it comes from the environment and never from
|
|
11
|
+
* `facilis.config.ts`: a generated project must not be able to redirect an operator's audit
|
|
12
|
+
* trail. Every invalid value falls back to its documented default and yields a warning, so a
|
|
13
|
+
* typo degrades the sink instead of breaking the boot.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
export const LOG_SINK_MODES = ["auto", "stdout", "file", "both"] as const;
|
|
17
|
+
export type LogSinkMode = (typeof LOG_SINK_MODES)[number];
|
|
18
|
+
|
|
19
|
+
export const LOG_SINK_ENV = "FACILIS_LOG_SINK";
|
|
20
|
+
export const LOG_DIR_ENV = "FACILIS_LOG_DIR";
|
|
21
|
+
export const LOG_MAX_BYTES_ENV = "FACILIS_LOG_MAX_BYTES";
|
|
22
|
+
export const LOG_KEEP_ENV = "FACILIS_LOG_KEEP";
|
|
23
|
+
export const LOG_LEVEL_ENV = "FACILIS_LOG_LEVEL";
|
|
24
|
+
|
|
25
|
+
/** 10 MiB keeps a dev log bounded while the IDE editor can still read it comfortably. */
|
|
26
|
+
export const DEFAULT_LOG_MAX_BYTES = 10 * 1024 * 1024;
|
|
27
|
+
export const DEFAULT_LOG_KEEP = 5;
|
|
28
|
+
export const DEFAULT_LOG_DIR_SEGMENTS = [".facilis", "logs"] as const;
|
|
29
|
+
const MAX_LOG_MAX_BYTES = 1024 * 1024 * 1024;
|
|
30
|
+
const MAX_LOG_KEEP = 1000;
|
|
31
|
+
|
|
32
|
+
export interface LogSinkSelection {
|
|
33
|
+
readonly stdout: boolean;
|
|
34
|
+
readonly file: boolean;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface ResolvedLogSettings {
|
|
38
|
+
/** The configured mode, kept for diagnostics (`auto` stays `auto`). */
|
|
39
|
+
readonly mode: LogSinkMode;
|
|
40
|
+
readonly sinks: LogSinkSelection;
|
|
41
|
+
/** Absolute directory of the JSONL files (only used when `sinks.file` is true). */
|
|
42
|
+
readonly dir: string;
|
|
43
|
+
readonly maxBytes: number;
|
|
44
|
+
readonly keep: number;
|
|
45
|
+
/** Environment override for `logging.level`; null keeps the project config. */
|
|
46
|
+
readonly level: LogLevel | null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Shaped like `ManifestWarning` so the bootstrap can forward it unchanged. */
|
|
50
|
+
export interface LogSettingsWarning {
|
|
51
|
+
readonly code: string;
|
|
52
|
+
readonly message: string;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface ResolvedLogSettingsResult {
|
|
56
|
+
readonly settings: ResolvedLogSettings;
|
|
57
|
+
readonly warnings: readonly LogSettingsWarning[];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface ResolveLogSettingsInput {
|
|
61
|
+
readonly env: NodeJS.ProcessEnv;
|
|
62
|
+
readonly projectRoot: string;
|
|
63
|
+
/** Test seam: override the NODE_ENV-derived production detection. */
|
|
64
|
+
readonly production?: boolean;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function resolveLogSettings(input: ResolveLogSettingsInput): ResolvedLogSettingsResult {
|
|
68
|
+
const warnings: LogSettingsWarning[] = [];
|
|
69
|
+
const production = input.production ?? isProductionEnvironment(input.env);
|
|
70
|
+
const mode = parseSinkMode(readEnv(input.env, LOG_SINK_ENV), warnings);
|
|
71
|
+
const dirValue = readEnv(input.env, LOG_DIR_ENV);
|
|
72
|
+
const dir =
|
|
73
|
+
dirValue === undefined
|
|
74
|
+
? resolvePath(input.projectRoot, ...DEFAULT_LOG_DIR_SEGMENTS)
|
|
75
|
+
: resolvePath(input.projectRoot, dirValue);
|
|
76
|
+
const maxBytes = parseBoundedInteger(
|
|
77
|
+
input.env,
|
|
78
|
+
LOG_MAX_BYTES_ENV,
|
|
79
|
+
DEFAULT_LOG_MAX_BYTES,
|
|
80
|
+
1,
|
|
81
|
+
MAX_LOG_MAX_BYTES,
|
|
82
|
+
warnings,
|
|
83
|
+
);
|
|
84
|
+
const keep = parseBoundedInteger(
|
|
85
|
+
input.env,
|
|
86
|
+
LOG_KEEP_ENV,
|
|
87
|
+
DEFAULT_LOG_KEEP,
|
|
88
|
+
0,
|
|
89
|
+
MAX_LOG_KEEP,
|
|
90
|
+
warnings,
|
|
91
|
+
);
|
|
92
|
+
const level = parseLevel(input.env, warnings);
|
|
93
|
+
return {
|
|
94
|
+
settings: { mode, sinks: sinkSelection(mode, production), dir, maxBytes, keep, level },
|
|
95
|
+
warnings,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function isLogSinkMode(value: string): value is LogSinkMode {
|
|
100
|
+
return (LOG_SINK_MODES as readonly string[]).includes(value);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function sinkSelection(mode: LogSinkMode, production: boolean): LogSinkSelection {
|
|
104
|
+
switch (mode) {
|
|
105
|
+
case "stdout":
|
|
106
|
+
return { stdout: true, file: false };
|
|
107
|
+
case "file":
|
|
108
|
+
return { stdout: false, file: true };
|
|
109
|
+
case "both":
|
|
110
|
+
return { stdout: true, file: true };
|
|
111
|
+
case "auto":
|
|
112
|
+
// Dev is where the IDE workflow lives: files need no setup. Production defaults to
|
|
113
|
+
// stdout because a deploy without writable disk still has a log platform.
|
|
114
|
+
return production ? { stdout: true, file: false } : { stdout: false, file: true };
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function parseSinkMode(raw: string | undefined, warnings: LogSettingsWarning[]): LogSinkMode {
|
|
119
|
+
if (raw === undefined) return "auto";
|
|
120
|
+
if (!isLogSinkMode(raw)) {
|
|
121
|
+
warnings.push(
|
|
122
|
+
warning(`${LOG_SINK_ENV}="${raw}" is not one of ${LOG_SINK_MODES.join("|")}; using "auto".`),
|
|
123
|
+
);
|
|
124
|
+
return "auto";
|
|
125
|
+
}
|
|
126
|
+
return raw;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function parseBoundedInteger(
|
|
130
|
+
env: NodeJS.ProcessEnv,
|
|
131
|
+
name: string,
|
|
132
|
+
fallback: number,
|
|
133
|
+
min: number,
|
|
134
|
+
max: number,
|
|
135
|
+
warnings: LogSettingsWarning[],
|
|
136
|
+
): number {
|
|
137
|
+
const raw = readEnv(env, name);
|
|
138
|
+
if (raw === undefined) return fallback;
|
|
139
|
+
const value = Number(raw);
|
|
140
|
+
if (!Number.isSafeInteger(value) || value < min || value > max) {
|
|
141
|
+
warnings.push(
|
|
142
|
+
warning(`${name}="${raw}" is not an integer in [${min}, ${max}]; using ${fallback}.`),
|
|
143
|
+
);
|
|
144
|
+
return fallback;
|
|
145
|
+
}
|
|
146
|
+
return value;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function parseLevel(env: NodeJS.ProcessEnv, warnings: LogSettingsWarning[]): LogLevel | null {
|
|
150
|
+
const raw = readEnv(env, LOG_LEVEL_ENV);
|
|
151
|
+
if (raw === undefined) return null;
|
|
152
|
+
if (!isLogLevel(raw)) {
|
|
153
|
+
warnings.push(warning(`${LOG_LEVEL_ENV}="${raw}" is not a log level; keeping logging.level.`));
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
return raw;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function readEnv(env: NodeJS.ProcessEnv, name: string): string | undefined {
|
|
160
|
+
const value = env[name]?.trim();
|
|
161
|
+
return value === undefined || value.length === 0 ? undefined : value;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function warning(message: string): LogSettingsWarning {
|
|
165
|
+
return { code: "logging_env_invalid", message };
|
|
166
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { LogEntry } from "@facilis.dev/core";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A destination for one serialized log entry (D-119).
|
|
5
|
+
*
|
|
6
|
+
* `append` throws when the destination is not writable; the runtime decides whether that is
|
|
7
|
+
* fatal (audit) or best-effort (access/error/app).
|
|
8
|
+
*/
|
|
9
|
+
export const LOG_STREAMS = ["access", "audit", "error", "app"] as const;
|
|
10
|
+
export type LogStream = (typeof LOG_STREAMS)[number];
|
|
11
|
+
|
|
12
|
+
export interface LogSink {
|
|
13
|
+
append(stream: LogStream, entry: LogEntry): void;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* One JSON object per line on stdout, for the deploy's log platform. Stdout audit lines stay
|
|
18
|
+
* plain entries (no chain fields): the hash chain belongs to the file record, WORM/retention
|
|
19
|
+
* is the platform's job (O-014).
|
|
20
|
+
*/
|
|
21
|
+
export function createStdoutLogSink(write: (line: string) => void = writeToStdout): LogSink {
|
|
22
|
+
return {
|
|
23
|
+
append(_stream, entry) {
|
|
24
|
+
write(`${JSON.stringify(entry)}\n`);
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function writeToStdout(line: string): void {
|
|
30
|
+
process.stdout.write(line);
|
|
31
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Redaction and caps for logger-provided data (D-119).
|
|
3
|
+
*
|
|
4
|
+
* `data`/`details` is the only arbitrary payload a route can hand the pipeline, so it is the
|
|
5
|
+
* one place a secret could leak. Keys are matched case-insensitively against the names a
|
|
6
|
+
* credential commonly travels under; values are additionally capped so one huge or deeply
|
|
7
|
+
* nested object cannot blow up a JSONL line. Headers and bodies are never passed in here in
|
|
8
|
+
* the first place: the pipeline logs shapes, not requests.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export const REDACTED = "[redacted]";
|
|
12
|
+
export const CIRCULAR = "[circular]";
|
|
13
|
+
export const MAX_DEPTH_PLACEHOLDER = "[max-depth]";
|
|
14
|
+
export const UNSERIALIZABLE = "[unserializable]";
|
|
15
|
+
|
|
16
|
+
export const MAX_REDACT_DEPTH = 6;
|
|
17
|
+
export const MAX_REDACT_ARRAY = 50;
|
|
18
|
+
export const MAX_REDACT_STRING = 1000;
|
|
19
|
+
|
|
20
|
+
const SENSITIVE_KEY_PATTERN =
|
|
21
|
+
/token|secret|password|cookie|authorization|set-cookie|api[-_]?key|credential|samlresponse|samlrequest|assertion|email|sessionid/i;
|
|
22
|
+
|
|
23
|
+
/** True when a key names something that must never reach the sink in clear text. */
|
|
24
|
+
export function isSensitiveKey(key: string): boolean {
|
|
25
|
+
return SENSITIVE_KEY_PATTERN.test(key);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Truncates a string to `max` characters; never appends a marker (it would exceed the cap). */
|
|
29
|
+
export function capString(value: string, max: number = MAX_REDACT_STRING): string {
|
|
30
|
+
return value.length <= max ? value : value.slice(0, max);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Recursively redacts and caps an arbitrary value.
|
|
35
|
+
*
|
|
36
|
+
* Accepted output types are the JSON ones (plus stringified bigints and ISO dates); anything
|
|
37
|
+
* else is replaced with a placeholder rather than serialized by an arbitrary method. Cycles
|
|
38
|
+
* become `[circular]`, cycles are detected along the current path only, so a shared value is
|
|
39
|
+
* emitted twice instead of being mistaken for a cycle.
|
|
40
|
+
*/
|
|
41
|
+
export function redactUnknown(value: unknown): unknown {
|
|
42
|
+
return redact(value, 0, new WeakSet<object>());
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Redacts a `data`/`details` record; returns undefined when the value is not a plain object. */
|
|
46
|
+
export function redactRecord(
|
|
47
|
+
value: Record<string, unknown> | undefined,
|
|
48
|
+
): Record<string, unknown> | undefined {
|
|
49
|
+
if (value === undefined) return undefined;
|
|
50
|
+
const redacted = redactUnknown(value);
|
|
51
|
+
return isPlainObject(redacted) ? redacted : undefined;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function redact(value: unknown, depth: number, seen: WeakSet<object>): unknown {
|
|
55
|
+
if (value === null || typeof value === "boolean" || typeof value === "number") return value;
|
|
56
|
+
if (typeof value === "string") return capString(value);
|
|
57
|
+
if (typeof value === "bigint") return value.toString();
|
|
58
|
+
if (value === undefined || typeof value === "symbol" || typeof value === "function") {
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
if (typeof value !== "object") return UNSERIALIZABLE;
|
|
62
|
+
if (value instanceof Date) return value.toISOString();
|
|
63
|
+
if (seen.has(value)) return CIRCULAR;
|
|
64
|
+
if (depth >= MAX_REDACT_DEPTH) return MAX_DEPTH_PLACEHOLDER;
|
|
65
|
+
|
|
66
|
+
seen.add(value);
|
|
67
|
+
try {
|
|
68
|
+
if (Array.isArray(value)) {
|
|
69
|
+
return value.slice(0, MAX_REDACT_ARRAY).map((item) => redact(item, depth + 1, seen));
|
|
70
|
+
}
|
|
71
|
+
if (value instanceof Error) {
|
|
72
|
+
return {
|
|
73
|
+
name: capString(value.name),
|
|
74
|
+
message: capString(value.message),
|
|
75
|
+
...(value.stack === undefined ? {} : { stack: capString(value.stack) }),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
if (value instanceof Map) {
|
|
79
|
+
const entries = Array.from(value, ([key, item]) => [String(key), item] as const);
|
|
80
|
+
return redact(Object.fromEntries(entries), depth + 1, seen);
|
|
81
|
+
}
|
|
82
|
+
if (value instanceof Set) {
|
|
83
|
+
return redact([...value], depth + 1, seen);
|
|
84
|
+
}
|
|
85
|
+
if (!isPlainObject(value)) return UNSERIALIZABLE;
|
|
86
|
+
|
|
87
|
+
const redacted: Record<string, unknown> = {};
|
|
88
|
+
for (const [key, item] of Object.entries(value)) {
|
|
89
|
+
if (isSensitiveKey(key)) {
|
|
90
|
+
redacted[key] = REDACTED;
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
const next = redact(item, depth + 1, seen);
|
|
94
|
+
// `undefined` is dropped: JSON.stringify would drop it too, and keeping it would make
|
|
95
|
+
// the output shape depend on the serializer.
|
|
96
|
+
if (next !== undefined) redacted[key] = next;
|
|
97
|
+
}
|
|
98
|
+
return redacted;
|
|
99
|
+
} finally {
|
|
100
|
+
seen.delete(value);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function isPlainObject(value: unknown): value is Record<string, unknown> {
|
|
105
|
+
if (value === null || typeof value !== "object") return false;
|
|
106
|
+
const prototype = Object.getPrototypeOf(value);
|
|
107
|
+
return prototype === Object.prototype || prototype === null;
|
|
108
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import {
|
|
2
|
+
logLevelEnabled,
|
|
3
|
+
type AppLogEntry,
|
|
4
|
+
type AuditLogEntry,
|
|
5
|
+
type FacilisLogger,
|
|
6
|
+
type FacilisLoggingApi,
|
|
7
|
+
type FacilisLoggingConfig,
|
|
8
|
+
type FacilisLogRequestMeta,
|
|
9
|
+
type LogEntry,
|
|
10
|
+
type LogLevel,
|
|
11
|
+
} from "@facilis.dev/core";
|
|
12
|
+
|
|
13
|
+
import { sanitizeEntry } from "./entry.ts";
|
|
14
|
+
import { createFileLogSink } from "./file-sink.ts";
|
|
15
|
+
import { createStdoutLogSink, type LogSink, type LogStream } from "./log-sink.ts";
|
|
16
|
+
import type { LogSettingsWarning, ResolvedLogSettings } from "./log-settings.ts";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The logging runtime behind `event.context.facilis.logging` (D-119).
|
|
20
|
+
*
|
|
21
|
+
* `record` is the one pipeline: it filters by the project's logging config, redacts/caps and
|
|
22
|
+
* writes to the env-selected sinks. Audit is never filtered and never best-effort: a failed
|
|
23
|
+
* audit write throws so sudo refuses to escalate (D-099), while a broken access/error/app sink
|
|
24
|
+
* only drops entries and reports once.
|
|
25
|
+
*/
|
|
26
|
+
export interface LoggingRuntimeOptions {
|
|
27
|
+
readonly config: FacilisLoggingConfig;
|
|
28
|
+
readonly settings: ResolvedLogSettings;
|
|
29
|
+
/** Test/deployment seam: collect stdout lines instead of writing to the process stream. */
|
|
30
|
+
readonly writeStdout?: (line: string) => void;
|
|
31
|
+
/** Test seam: fixed clock. */
|
|
32
|
+
readonly now?: () => Date;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface LoggingRuntime extends FacilisLoggingApi {
|
|
36
|
+
readonly config: FacilisLoggingConfig;
|
|
37
|
+
readonly settings: ResolvedLogSettings;
|
|
38
|
+
/** Non-fatal setup problems the bootstrap forwards to the manifest. */
|
|
39
|
+
readonly warnings: readonly LogSettingsWarning[];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
interface LogIdentity {
|
|
43
|
+
readonly userId?: string;
|
|
44
|
+
readonly sessionHash?: string;
|
|
45
|
+
readonly tenantId?: string;
|
|
46
|
+
readonly ip?: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function createLoggingRuntime(options: LoggingRuntimeOptions): LoggingRuntime {
|
|
50
|
+
const warnings: LogSettingsWarning[] = [];
|
|
51
|
+
let file: LogSink | null = null;
|
|
52
|
+
if (options.settings.sinks.file) {
|
|
53
|
+
const setup = createFileLogSink({
|
|
54
|
+
dir: options.settings.dir,
|
|
55
|
+
maxBytes: options.settings.maxBytes,
|
|
56
|
+
keep: options.settings.keep,
|
|
57
|
+
});
|
|
58
|
+
warnings.push(...setup.warnings);
|
|
59
|
+
file = setup.sink;
|
|
60
|
+
}
|
|
61
|
+
const stdout: LogSink | null = options.settings.sinks.stdout
|
|
62
|
+
? createStdoutLogSink(options.writeStdout)
|
|
63
|
+
: null;
|
|
64
|
+
const now = options.now ?? (() => new Date());
|
|
65
|
+
let reportedWriteFailure = false;
|
|
66
|
+
|
|
67
|
+
const reportWriteFailure = (error: unknown): void => {
|
|
68
|
+
if (reportedWriteFailure) return;
|
|
69
|
+
reportedWriteFailure = true;
|
|
70
|
+
// One line per process: a broken sink would otherwise flood the terminal with the very
|
|
71
|
+
// entries it cannot store. Audit does not come through here: it fails the request instead.
|
|
72
|
+
// oxlint-disable-next-line no-console -- operator fallback for the best-effort streams.
|
|
73
|
+
console.error("facilis: log sink is not writable; dropping access/error/app entries", error);
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const write = (stream: LogStream, entry: LogEntry): void => {
|
|
77
|
+
try {
|
|
78
|
+
file?.append(stream, entry);
|
|
79
|
+
stdout?.append(stream, entry);
|
|
80
|
+
} catch (error) {
|
|
81
|
+
if (stream === "audit") throw error;
|
|
82
|
+
reportWriteFailure(error);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const accepts = (entry: LogEntry): boolean => {
|
|
87
|
+
switch (entry.kind) {
|
|
88
|
+
case "audit":
|
|
89
|
+
// Never filtered: an audit trail with holes is not an audit trail.
|
|
90
|
+
return true;
|
|
91
|
+
case "access":
|
|
92
|
+
return options.config.access && logLevelEnabled(options.config.level, entry.level);
|
|
93
|
+
case "error":
|
|
94
|
+
return options.config.errors;
|
|
95
|
+
case "app":
|
|
96
|
+
return logLevelEnabled(options.config.level, entry.level);
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const record = (entry: LogEntry): void => {
|
|
101
|
+
if (!accepts(entry)) return;
|
|
102
|
+
write(entry.kind, sanitizeEntry(entry));
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const logger = (meta: FacilisLogRequestMeta): FacilisLogger => {
|
|
106
|
+
const identity = buildIdentity(meta);
|
|
107
|
+
const app =
|
|
108
|
+
(level: LogLevel) =>
|
|
109
|
+
(message: string, data?: Record<string, unknown>): void => {
|
|
110
|
+
const entry: AppLogEntry = {
|
|
111
|
+
kind: "app",
|
|
112
|
+
ts: now().toISOString(),
|
|
113
|
+
level,
|
|
114
|
+
requestId: meta.requestId,
|
|
115
|
+
message,
|
|
116
|
+
method: meta.method,
|
|
117
|
+
path: meta.path,
|
|
118
|
+
...(data === undefined ? {} : { data }),
|
|
119
|
+
...identity,
|
|
120
|
+
};
|
|
121
|
+
record(entry);
|
|
122
|
+
};
|
|
123
|
+
return {
|
|
124
|
+
debug: app("debug"),
|
|
125
|
+
info: app("info"),
|
|
126
|
+
warn: app("warn"),
|
|
127
|
+
error: app("error"),
|
|
128
|
+
audit: (input) => {
|
|
129
|
+
// The actor is derived, never caller-supplied: "anonymous" is the session-less case
|
|
130
|
+
// (a public route or a boot-time event), not a claim about identity.
|
|
131
|
+
const actor = meta.userId === undefined ? "anonymous" : `user:${meta.userId}`;
|
|
132
|
+
const entry: AuditLogEntry = {
|
|
133
|
+
kind: "audit",
|
|
134
|
+
ts: now().toISOString(),
|
|
135
|
+
level: "info",
|
|
136
|
+
event: input.operation,
|
|
137
|
+
actor,
|
|
138
|
+
requestId: meta.requestId,
|
|
139
|
+
method: meta.method,
|
|
140
|
+
path: meta.path,
|
|
141
|
+
...(input.outcome === undefined ? {} : { outcome: input.outcome }),
|
|
142
|
+
...(input.errorCode === undefined ? {} : { errorCode: input.errorCode }),
|
|
143
|
+
...(input.reason === undefined ? {} : { reason: input.reason }),
|
|
144
|
+
...(input.tables === undefined ? {} : { tables: input.tables }),
|
|
145
|
+
...(input.details === undefined ? {} : { details: input.details }),
|
|
146
|
+
...identity,
|
|
147
|
+
};
|
|
148
|
+
record(entry);
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
return { record, logger, config: options.config, settings: options.settings, warnings };
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function buildIdentity(meta: FacilisLogRequestMeta): LogIdentity {
|
|
157
|
+
return {
|
|
158
|
+
...(meta.userId === undefined ? {} : { userId: meta.userId }),
|
|
159
|
+
...(meta.sessionHash === undefined ? {} : { sessionHash: meta.sessionHash }),
|
|
160
|
+
...(meta.tenantId === undefined ? {} : { tenantId: meta.tenantId }),
|
|
161
|
+
...(meta.ip === undefined ? {} : { ip: meta.ip }),
|
|
162
|
+
};
|
|
163
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { setSudoAuditSink, type SudoAuditEvent } from "@facilis.dev/db";
|
|
2
|
+
import type { AuditLogEntry, FacilisLoggingApi } from "@facilis.dev/core";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Bridge the db package's sudo trail into the audit stream (D-099, D-119).
|
|
6
|
+
*
|
|
7
|
+
* The sudo event is the framework's own security record; it becomes one more `audit` entry
|
|
8
|
+
* instead of a parallel `facilis:sudo` stdout protocol. Fail-closed is preserved: the bridge
|
|
9
|
+
* calls `record` synchronously, and a throwing audit sink propagates out of `writeSudoAudit`
|
|
10
|
+
* so sudo refuses to escalate untraced.
|
|
11
|
+
*/
|
|
12
|
+
export function toSudoAuditEntry(event: SudoAuditEvent): AuditLogEntry {
|
|
13
|
+
return {
|
|
14
|
+
kind: "audit",
|
|
15
|
+
ts: event.at,
|
|
16
|
+
level: "info",
|
|
17
|
+
event: `sudo:${event.event}`,
|
|
18
|
+
actor: event.actor,
|
|
19
|
+
operation: event.operation,
|
|
20
|
+
reason: event.reason,
|
|
21
|
+
tables: event.tables,
|
|
22
|
+
...(event.observedTables === undefined ? {} : { observedTables: event.observedTables }),
|
|
23
|
+
roles: event.roles,
|
|
24
|
+
...(event.actorUserId === undefined ? {} : { userId: event.actorUserId }),
|
|
25
|
+
...(event.sessionHash === undefined ? {} : { sessionHash: event.sessionHash }),
|
|
26
|
+
...(event.tenantId === undefined ? {} : { tenantId: event.tenantId }),
|
|
27
|
+
...(event.requestId === undefined ? {} : { requestId: event.requestId }),
|
|
28
|
+
...(event.method === undefined ? {} : { method: event.method }),
|
|
29
|
+
...(event.route === undefined ? {} : { path: event.route }),
|
|
30
|
+
...(event.outcome === undefined ? {} : { outcome: event.outcome }),
|
|
31
|
+
...(event.errorCode === undefined ? {} : { errorCode: event.errorCode }),
|
|
32
|
+
...(event.durationMs === undefined ? {} : { durationMs: event.durationMs }),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Replaces the process-wide sudo sink once, at boot, with the audit stream. */
|
|
37
|
+
export function installSudoAuditBridge(logging: FacilisLoggingApi): void {
|
|
38
|
+
setSudoAuditSink((event) => {
|
|
39
|
+
logging.record(toSudoAuditEntry(event));
|
|
40
|
+
});
|
|
41
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { buildManifest } from "@facilis.dev/core";
|
|
2
|
+
import type {
|
|
3
|
+
BlockManifest,
|
|
4
|
+
FacilisConfig,
|
|
5
|
+
FacilisManifest,
|
|
6
|
+
LocaleCatalogs,
|
|
7
|
+
ManifestWarning,
|
|
8
|
+
RouteMeta,
|
|
9
|
+
SchemaSnapshot,
|
|
10
|
+
} from "@facilis.dev/core";
|
|
11
|
+
|
|
12
|
+
import type { RouteMetadata, RouteMetadataMap } from "../types.ts";
|
|
13
|
+
|
|
14
|
+
export interface ManifestDataSources {
|
|
15
|
+
readonly config: FacilisConfig;
|
|
16
|
+
readonly routeMetadata: RouteMetadataMap;
|
|
17
|
+
/** Omitted when the schema could not be introspected; `schemaFailure` explains why. */
|
|
18
|
+
readonly schema?: SchemaSnapshot;
|
|
19
|
+
readonly schemaFailure?: ManifestWarning;
|
|
20
|
+
readonly catalogs?: LocaleCatalogs;
|
|
21
|
+
readonly blocks?: readonly BlockManifest[];
|
|
22
|
+
readonly coreVersion?: string;
|
|
23
|
+
readonly nitroVersion?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface ManifestDataResult {
|
|
27
|
+
readonly manifest: FacilisManifest;
|
|
28
|
+
readonly warnings: readonly ManifestWarning[];
|
|
29
|
+
/** True when a section failed and the response is a 200 partial (SPEC §6.4). */
|
|
30
|
+
readonly partial: boolean;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Pure assembler joining the toolchain outputs (AST pass, schema snapshot, locale
|
|
35
|
+
* files) into the FacilisManifest contract. Kept free of fs/db access so the route
|
|
36
|
+
* handlers stay thin and this logic is unit-testable.
|
|
37
|
+
*/
|
|
38
|
+
export function buildManifestData(sources: ManifestDataSources): ManifestDataResult {
|
|
39
|
+
const routes = flattenRouteMetadata(sources.routeMetadata);
|
|
40
|
+
const manifest = buildManifest({
|
|
41
|
+
config: sources.config,
|
|
42
|
+
routes: routes.map(toRouteMeta),
|
|
43
|
+
schema: sources.schema,
|
|
44
|
+
catalogs: sources.catalogs,
|
|
45
|
+
blocks: sources.blocks === undefined ? undefined : sortBlocks(sources.blocks),
|
|
46
|
+
coreVersion: sources.coreVersion,
|
|
47
|
+
nitroVersion: sources.nitroVersion,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const warnings: ManifestWarning[] = routes.flatMap((route) => route.warnings);
|
|
51
|
+
if (sources.schemaFailure !== undefined) warnings.push(sources.schemaFailure);
|
|
52
|
+
|
|
53
|
+
return { manifest, warnings, partial: sources.schemaFailure !== undefined };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Deterministic order: path first, then HTTP method (visualizers and diffs depend on it). */
|
|
57
|
+
export function flattenRouteMetadata(metadata: RouteMetadataMap): readonly RouteMetadata[] {
|
|
58
|
+
const routes: RouteMetadata[] = [];
|
|
59
|
+
for (const path of Object.keys(metadata).toSorted((left, right) => left.localeCompare(right))) {
|
|
60
|
+
const operations = metadata[path];
|
|
61
|
+
if (operations === undefined) continue;
|
|
62
|
+
for (const method of Object.keys(operations).toSorted((left, right) =>
|
|
63
|
+
left.localeCompare(right),
|
|
64
|
+
)) {
|
|
65
|
+
const route = operations[method];
|
|
66
|
+
if (route !== undefined) routes.push(route);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return routes;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function toRouteMeta(route: RouteMetadata): RouteMeta {
|
|
73
|
+
return {
|
|
74
|
+
method: route.method,
|
|
75
|
+
path: route.path,
|
|
76
|
+
summary: route.description,
|
|
77
|
+
description: route.description,
|
|
78
|
+
permission: route.permission,
|
|
79
|
+
...(route.crossSite === true ? { crossSite: true } : {}),
|
|
80
|
+
// A resolved false is published (the derogation is off); an unreadable flag stays unknown.
|
|
81
|
+
...(route.unresolved.includes("rawSql") ? {} : { rawSql: route.rawSql === true }),
|
|
82
|
+
dbTables: route.dbTables,
|
|
83
|
+
dbColumns: route.dbColumns,
|
|
84
|
+
security: deriveSecurity(route),
|
|
85
|
+
sourceFile: route.sourceFile,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* SPEC §7.3 security classification. A value the AST pass could not read is
|
|
91
|
+
* "unknown", never "public": guessing would weaken the Studio's security view.
|
|
92
|
+
*/
|
|
93
|
+
function deriveSecurity(route: RouteMetadata): RouteMeta["security"] {
|
|
94
|
+
if (route.unresolved.includes("permission")) return "unknown";
|
|
95
|
+
const permission = route.permission;
|
|
96
|
+
if (permission === undefined) return "public";
|
|
97
|
+
if (typeof permission === "string") return permission.length === 0 ? "public" : "required";
|
|
98
|
+
return permission.length === 0 ? "public" : "required";
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function sortBlocks(blocks: readonly BlockManifest[]): readonly BlockManifest[] {
|
|
102
|
+
return [...blocks].toSorted((left, right) => left.name.localeCompare(right.name));
|
|
103
|
+
}
|