@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,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The framework rate limiter lives in @facilis.dev/core, where the authorized-handler wrapper uses
|
|
3
|
+
* it (D-152). This module keeps the framework-owned token endpoint's import path stable and
|
|
4
|
+
* re-exports exactly the same implementation, so both surfaces share one bounded limiter type.
|
|
5
|
+
*/
|
|
6
|
+
export { createFixedWindowRateLimiter, MAX_WINDOWS, type FixedWindowRateLimiter, type RateLimitDecision, type RateLimitWindow, } from "@facilis.dev/core";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The framework rate limiter lives in @facilis.dev/core, where the authorized-handler wrapper uses
|
|
3
|
+
* it (D-152). This module keeps the framework-owned token endpoint's import path stable and
|
|
4
|
+
* re-exports exactly the same implementation, so both surfaces share one bounded limiter type.
|
|
5
|
+
*/
|
|
6
|
+
export { createFixedWindowRateLimiter, MAX_WINDOWS, } from "@facilis.dev/core";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { LocaleCatalogs } from "@facilis.dev/core";
|
|
2
|
+
export interface RevisionSnapshot {
|
|
3
|
+
readonly revision: string;
|
|
4
|
+
readonly generatedAt: string;
|
|
5
|
+
readonly catalogs: LocaleCatalogs;
|
|
6
|
+
readonly configContent: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Compute the manifest revision on demand (SPEC §6.5: no watchers required).
|
|
10
|
+
*
|
|
11
|
+
* Inputs: raw facilis.config.ts source, db/schema.ts + its relative imports, the
|
|
12
|
+
* AST-pass route metadata (the facilis-owned part of the OpenAPI document) and the
|
|
13
|
+
* locale catalogues. No block package ships (D-131); block manifests default to [].
|
|
14
|
+
*/
|
|
15
|
+
export declare function getRevisionSnapshot(): Promise<RevisionSnapshot>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { computeRevision } from "@facilis.dev/core";
|
|
2
|
+
import routeMetadata from "#facilis/openapi-meta";
|
|
3
|
+
import { configPath, projectRoot } from "#facilis/config";
|
|
4
|
+
import { collectLocaleCatalogs, collectSchemaFiles, readTextFile } from "./project-files.js";
|
|
5
|
+
/**
|
|
6
|
+
* Compute the manifest revision on demand (SPEC §6.5: no watchers required).
|
|
7
|
+
*
|
|
8
|
+
* Inputs: raw facilis.config.ts source, db/schema.ts + its relative imports, the
|
|
9
|
+
* AST-pass route metadata (the facilis-owned part of the OpenAPI document) and the
|
|
10
|
+
* locale catalogues. No block package ships (D-131); block manifests default to [].
|
|
11
|
+
*/
|
|
12
|
+
export async function getRevisionSnapshot() {
|
|
13
|
+
const [configSource, schemaFiles, catalogs] = await Promise.all([
|
|
14
|
+
readTextFile(configPath),
|
|
15
|
+
collectSchemaFiles(projectRoot),
|
|
16
|
+
collectLocaleCatalogs(projectRoot),
|
|
17
|
+
]);
|
|
18
|
+
const configContent = configSource ?? "";
|
|
19
|
+
const revision = await computeRevision({
|
|
20
|
+
configContent,
|
|
21
|
+
schemaFiles,
|
|
22
|
+
openApiSpec: routeMetadata,
|
|
23
|
+
localeCatalogs: catalogs,
|
|
24
|
+
});
|
|
25
|
+
return { revision, generatedAt: new Date().toISOString(), catalogs, configContent };
|
|
26
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Split a migration file into executable statements.
|
|
3
|
+
*
|
|
4
|
+
* drizzle-kit emits `--> statement-breakpoint` between statements; plain SQL files
|
|
5
|
+
* fall back to end-of-line semicolons. Splitting is intentionally conservative: a
|
|
6
|
+
* statement is never rewritten, only separated.
|
|
7
|
+
*/
|
|
8
|
+
export declare function splitSqlStatements(source: string): string[];
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const STATEMENT_BREAKPOINT = /-->\s*statement-breakpoint\s*/i;
|
|
2
|
+
/**
|
|
3
|
+
* Split a migration file into executable statements.
|
|
4
|
+
*
|
|
5
|
+
* drizzle-kit emits `--> statement-breakpoint` between statements; plain SQL files
|
|
6
|
+
* fall back to end-of-line semicolons. Splitting is intentionally conservative: a
|
|
7
|
+
* statement is never rewritten, only separated.
|
|
8
|
+
*/
|
|
9
|
+
export function splitSqlStatements(source) {
|
|
10
|
+
const normalized = source.replace(/\r\n/g, "\n");
|
|
11
|
+
const chunks = normalized.includes("--> statement-breakpoint")
|
|
12
|
+
? normalized.split(STATEMENT_BREAKPOINT)
|
|
13
|
+
: normalized.split(/;\s*(?:\n|$)/);
|
|
14
|
+
return chunks.map((chunk) => chunk.trim()).filter(isExecutable);
|
|
15
|
+
}
|
|
16
|
+
function isExecutable(statement) {
|
|
17
|
+
if (statement.length === 0)
|
|
18
|
+
return false;
|
|
19
|
+
return statement.split("\n").some((line) => {
|
|
20
|
+
const trimmed = line.trim();
|
|
21
|
+
return trimmed.length > 0 && !trimmed.startsWith("--");
|
|
22
|
+
});
|
|
23
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { FacilisConfig, FacilisHandlerEvent, FacilisLogger } from "@facilis.dev/core";
|
|
2
|
+
import { type CompleteLoginInput, type CompleteLoginResult, type FetchLike, type OidcDeps, type PublicSsoProvider, type SamlValidatorFactory, type SystemRunner } from "@facilis.dev/auth";
|
|
3
|
+
/**
|
|
4
|
+
* SSO runtime glue between the framework route and @facilis.dev/auth (D-120).
|
|
5
|
+
*
|
|
6
|
+
* Everything environment-dependent lives here: the public origin (callback/ACS URL), the
|
|
7
|
+
* failure redirect, the provider list and the flow dependency bundle. The route stays a thin
|
|
8
|
+
* method+path dispatcher, which also makes this layer unit-testable without Nitro.
|
|
9
|
+
*/
|
|
10
|
+
/** Every table an SSO login can touch; must match the route's declared `dbTables`. */
|
|
11
|
+
export declare const SSO_ROUTE_TABLES: readonly ["auth_sso_states", "auth_identities", "users", "user_roles", "sessions"];
|
|
12
|
+
export declare const SSO_ROUTE_PREFIX = "/api/auth/sso";
|
|
13
|
+
export interface SsoRequestContext {
|
|
14
|
+
readonly event: FacilisHandlerEvent;
|
|
15
|
+
readonly config: FacilisConfig;
|
|
16
|
+
readonly system: SystemRunner;
|
|
17
|
+
readonly log: FacilisLogger;
|
|
18
|
+
readonly environment?: Readonly<Record<string, string | undefined>>;
|
|
19
|
+
/** Test seam: replaced by tests so no network is touched. */
|
|
20
|
+
readonly fetch?: FetchLike;
|
|
21
|
+
readonly now?: () => number;
|
|
22
|
+
readonly oidc?: OidcDeps;
|
|
23
|
+
readonly samlValidatorFactory?: SamlValidatorFactory;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The deployment origin used in the IdP redirect URI/ACS URL.
|
|
27
|
+
*
|
|
28
|
+
* `FACILIS_PUBLIC_ORIGIN` wins; otherwise the request URL/Host is used, which works for a
|
|
29
|
+
* direct dev server. A deploy behind a proxy MUST set the variable: the callback URL registered
|
|
30
|
+
* at the IdP has to match the public origin, and the proxy may rewrite Host.
|
|
31
|
+
*/
|
|
32
|
+
export declare function resolvePublicOrigin(event: FacilisHandlerEvent, environment?: Readonly<Record<string, string | undefined>>): string;
|
|
33
|
+
/** The public provider list: ids, labels, kinds and the framework start URLs; no secrets. */
|
|
34
|
+
export declare function listSsoProviders(config: FacilisConfig, environment?: Readonly<Record<string, string | undefined>>): PublicSsoProvider[];
|
|
35
|
+
/** The redirect target for any failed start/callback, carrying only the safe error code. */
|
|
36
|
+
export declare function ssoFailureLocation(config: FacilisConfig, error: unknown): string;
|
|
37
|
+
export declare function startSsoLogin(context: SsoRequestContext, providerId: string, redirectTo: string | null): Promise<{
|
|
38
|
+
readonly redirectUrl: string;
|
|
39
|
+
}>;
|
|
40
|
+
export declare function completeSsoLogin(context: SsoRequestContext, providerId: string, input: CompleteLoginInput): Promise<CompleteLoginResult>;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { completeLogin, failureRedirectPath, publicProviderList, ssoErrorCode, SsoError, startLogin, } from "@facilis.dev/auth";
|
|
2
|
+
/**
|
|
3
|
+
* SSO runtime glue between the framework route and @facilis.dev/auth (D-120).
|
|
4
|
+
*
|
|
5
|
+
* Everything environment-dependent lives here: the public origin (callback/ACS URL), the
|
|
6
|
+
* failure redirect, the provider list and the flow dependency bundle. The route stays a thin
|
|
7
|
+
* method+path dispatcher, which also makes this layer unit-testable without Nitro.
|
|
8
|
+
*/
|
|
9
|
+
/** Every table an SSO login can touch; must match the route's declared `dbTables`. */
|
|
10
|
+
export const SSO_ROUTE_TABLES = [
|
|
11
|
+
"auth_sso_states",
|
|
12
|
+
"auth_identities",
|
|
13
|
+
"users",
|
|
14
|
+
"user_roles",
|
|
15
|
+
"sessions",
|
|
16
|
+
];
|
|
17
|
+
export const SSO_ROUTE_PREFIX = "/api/auth/sso";
|
|
18
|
+
/** A header/URL-derived origin is attacker-controlled: accept only a plain host[:port]. */
|
|
19
|
+
const HOST_PATTERN = /^[A-Za-z0-9.-]+(?::\d{1,5})?$/;
|
|
20
|
+
/**
|
|
21
|
+
* The deployment origin used in the IdP redirect URI/ACS URL.
|
|
22
|
+
*
|
|
23
|
+
* `FACILIS_PUBLIC_ORIGIN` wins; otherwise the request URL/Host is used, which works for a
|
|
24
|
+
* direct dev server. A deploy behind a proxy MUST set the variable: the callback URL registered
|
|
25
|
+
* at the IdP has to match the public origin, and the proxy may rewrite Host.
|
|
26
|
+
*/
|
|
27
|
+
export function resolvePublicOrigin(event, environment = process.env) {
|
|
28
|
+
const configured = environment["FACILIS_PUBLIC_ORIGIN"]?.trim();
|
|
29
|
+
if (configured !== undefined && configured.length > 0) {
|
|
30
|
+
let origin;
|
|
31
|
+
try {
|
|
32
|
+
origin = new URL(configured);
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
throw new SsoError("sso_internal_error", "FACILIS_PUBLIC_ORIGIN is not a URL", {
|
|
36
|
+
cause: error,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
if (origin.protocol !== "https:" && origin.protocol !== "http:") {
|
|
40
|
+
throw new SsoError("sso_internal_error", "FACILIS_PUBLIC_ORIGIN must be http(s)");
|
|
41
|
+
}
|
|
42
|
+
if (origin.search !== "" || origin.hash !== "") {
|
|
43
|
+
throw new SsoError("sso_internal_error", "FACILIS_PUBLIC_ORIGIN must not carry a query or hash");
|
|
44
|
+
}
|
|
45
|
+
// A preview or sub-path deployment lives under a base path (/preview/<port> in the IDE);
|
|
46
|
+
// keep it so the callback/ACS URL is the one the IdP actually has to accept.
|
|
47
|
+
const basePath = origin.pathname.replace(/\/+$/, "");
|
|
48
|
+
return `${origin.origin}${basePath}`;
|
|
49
|
+
}
|
|
50
|
+
const rawUrl = event.req.url;
|
|
51
|
+
if (typeof rawUrl === "string") {
|
|
52
|
+
try {
|
|
53
|
+
return new URL(rawUrl).origin;
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
// Nitro can hand a path-only URL to the handler; fall through to the Host header.
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const host = event.req.headers.get("host");
|
|
60
|
+
if (host === null || !HOST_PATTERN.test(host)) {
|
|
61
|
+
throw new SsoError("sso_internal_error", "cannot resolve the request origin");
|
|
62
|
+
}
|
|
63
|
+
const forwarded = event.req.headers.get("x-forwarded-proto");
|
|
64
|
+
const protocol = forwarded === "https" ? "https" : "http";
|
|
65
|
+
return `${protocol}://${host}`;
|
|
66
|
+
}
|
|
67
|
+
/** The public provider list: ids, labels, kinds and the framework start URLs; no secrets. */
|
|
68
|
+
export function listSsoProviders(config, environment = process.env) {
|
|
69
|
+
return publicProviderList(config.auth.sso, environment);
|
|
70
|
+
}
|
|
71
|
+
/** The redirect target for any failed start/callback, carrying only the safe error code. */
|
|
72
|
+
export function ssoFailureLocation(config, error) {
|
|
73
|
+
return failureRedirectPath(config.auth.sso.failureRedirect, ssoErrorCode(error));
|
|
74
|
+
}
|
|
75
|
+
function flowDeps(context) {
|
|
76
|
+
return {
|
|
77
|
+
sso: context.config.auth.sso,
|
|
78
|
+
defaultRole: context.config.auth.defaultRole,
|
|
79
|
+
verificationEnabled: context.config.auth.verification.enabled,
|
|
80
|
+
publicOrigin: resolvePublicOrigin(context.event, context.environment ?? process.env),
|
|
81
|
+
system: context.system,
|
|
82
|
+
audit: (input) => context.log.audit(input),
|
|
83
|
+
warn: (message, data) => context.log.warn(message, data),
|
|
84
|
+
...(context.fetch === undefined ? {} : { fetch: context.fetch }),
|
|
85
|
+
...(context.now === undefined ? {} : { now: context.now }),
|
|
86
|
+
...(context.environment === undefined ? {} : { environment: context.environment }),
|
|
87
|
+
...(context.oidc === undefined ? {} : { oidc: context.oidc }),
|
|
88
|
+
...(context.samlValidatorFactory === undefined
|
|
89
|
+
? {}
|
|
90
|
+
: { samlValidatorFactory: context.samlValidatorFactory }),
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
export function startSsoLogin(context, providerId, redirectTo) {
|
|
94
|
+
return startLogin(flowDeps(context), { providerId, redirectTo });
|
|
95
|
+
}
|
|
96
|
+
export function completeSsoLogin(context, providerId, input) {
|
|
97
|
+
return completeLogin(flowDeps(context), providerId, input);
|
|
98
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Process-level state shared by the dev endpoints.
|
|
3
|
+
*
|
|
4
|
+
* Boot time is captured when the Nitro worker imports this module, which is exactly the
|
|
5
|
+
* "server is up" moment `/__facilis/health` reports (SPEC §6.3/§6.7).
|
|
6
|
+
*/
|
|
7
|
+
export declare const bootedAt: string;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Process-level state shared by the dev endpoints.
|
|
3
|
+
*
|
|
4
|
+
* Boot time is captured when the Nitro worker imports this module, which is exactly the
|
|
5
|
+
* "server is up" moment `/__facilis/health` reports (SPEC §6.3/§6.7).
|
|
6
|
+
*/
|
|
7
|
+
export const bootedAt = new Date().toISOString();
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type StorageEncryptionKeys } from "@facilis.dev/storage";
|
|
2
|
+
export type EncryptionKeyResolution = {
|
|
3
|
+
readonly keys: StorageEncryptionKeys;
|
|
4
|
+
} | {
|
|
5
|
+
readonly keys: null;
|
|
6
|
+
readonly problem: "missing" | "invalid";
|
|
7
|
+
readonly message: string;
|
|
8
|
+
};
|
|
9
|
+
export declare function resolveEncryptionKeys(env: NodeJS.ProcessEnv): EncryptionKeyResolution;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { isValidEncryptionKeyId } from "@facilis.dev/storage";
|
|
2
|
+
/**
|
|
3
|
+
* Resolve the optional at-rest encryption keys from the environment (D-117).
|
|
4
|
+
*
|
|
5
|
+
* The active key encrypts new blobs; retired keys only decrypt blobs whose header names
|
|
6
|
+
* them, which is what makes rotation possible without rewriting content-addressed bodies.
|
|
7
|
+
* Values are base64 (recommended) or 64-character hex, and must decode to 32 bytes.
|
|
8
|
+
*/
|
|
9
|
+
const KEY_ENV = "FACILIS_STORAGE_ENCRYPTION_KEY";
|
|
10
|
+
const KEY_ID_ENV = "FACILIS_STORAGE_ENCRYPTION_KEY_ID";
|
|
11
|
+
const RETIRED_KEYS_ENV = "FACILIS_STORAGE_ENCRYPTION_RETIRED_KEYS";
|
|
12
|
+
const DEFAULT_KEY_ID = "primary";
|
|
13
|
+
const KEY_BYTES = 32;
|
|
14
|
+
export function resolveEncryptionKeys(env) {
|
|
15
|
+
const rawKey = readEnv(env, KEY_ENV);
|
|
16
|
+
if (rawKey === undefined) {
|
|
17
|
+
return {
|
|
18
|
+
keys: null,
|
|
19
|
+
problem: "missing",
|
|
20
|
+
message: "Set FACILIS_STORAGE_ENCRYPTION_KEY (base64 or hex, 32 bytes) because storage.encryption.enabled is true.",
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
const keyId = readEnv(env, KEY_ID_ENV) ?? DEFAULT_KEY_ID;
|
|
24
|
+
if (!isValidEncryptionKeyId(keyId)) {
|
|
25
|
+
return invalid("FACILIS_STORAGE_ENCRYPTION_KEY_ID must match [A-Za-z0-9._-]{1,64}.");
|
|
26
|
+
}
|
|
27
|
+
const activeKey = decodeKey(rawKey);
|
|
28
|
+
if (activeKey === null) {
|
|
29
|
+
return invalid("FACILIS_STORAGE_ENCRYPTION_KEY must be a base64 or hex 32-byte key.");
|
|
30
|
+
}
|
|
31
|
+
// Null-prototype record: key ids are validated, but __proto__ must still never become an
|
|
32
|
+
// inherited value instead of an own key.
|
|
33
|
+
const keys = Object.create(null);
|
|
34
|
+
keys[keyId] = activeKey;
|
|
35
|
+
const retiredRaw = readEnv(env, RETIRED_KEYS_ENV);
|
|
36
|
+
if (retiredRaw !== undefined) {
|
|
37
|
+
let parsed;
|
|
38
|
+
try {
|
|
39
|
+
parsed = JSON.parse(retiredRaw);
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return invalid("FACILIS_STORAGE_ENCRYPTION_RETIRED_KEYS must be a JSON object of key id to key.");
|
|
43
|
+
}
|
|
44
|
+
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
45
|
+
return invalid("FACILIS_STORAGE_ENCRYPTION_RETIRED_KEYS must be a JSON object of key id to key.");
|
|
46
|
+
}
|
|
47
|
+
for (const [retiredId, value] of Object.entries(parsed)) {
|
|
48
|
+
if (!isValidEncryptionKeyId(retiredId)) {
|
|
49
|
+
return invalid('Retired encryption key id "' + retiredId + '" is not a valid key id.');
|
|
50
|
+
}
|
|
51
|
+
if (Object.hasOwn(keys, retiredId)) {
|
|
52
|
+
return invalid('Encryption key id "' + retiredId + '" is both active and retired.');
|
|
53
|
+
}
|
|
54
|
+
if (typeof value !== "string") {
|
|
55
|
+
return invalid('Retired encryption key "' + retiredId + '" must be a string.');
|
|
56
|
+
}
|
|
57
|
+
const decoded = decodeKey(value);
|
|
58
|
+
if (decoded === null) {
|
|
59
|
+
return invalid('Retired encryption key "' + retiredId + '" must be 32 bytes.');
|
|
60
|
+
}
|
|
61
|
+
keys[retiredId] = decoded;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return { keys: { activeKeyId: keyId, keys } };
|
|
65
|
+
}
|
|
66
|
+
function decodeKey(value) {
|
|
67
|
+
const trimmed = value.trim();
|
|
68
|
+
if (/^[0-9a-fA-F]{64}$/.test(trimmed)) {
|
|
69
|
+
return new Uint8Array(Buffer.from(trimmed, "hex"));
|
|
70
|
+
}
|
|
71
|
+
if (!/^[A-Za-z0-9+/]+={0,2}$/.test(trimmed))
|
|
72
|
+
return null;
|
|
73
|
+
const decoded = Buffer.from(trimmed, "base64");
|
|
74
|
+
return decoded.length === KEY_BYTES ? new Uint8Array(decoded) : null;
|
|
75
|
+
}
|
|
76
|
+
function readEnv(env, name) {
|
|
77
|
+
const value = env[name]?.trim();
|
|
78
|
+
return value === undefined || value.length === 0 ? undefined : value;
|
|
79
|
+
}
|
|
80
|
+
function invalid(message) {
|
|
81
|
+
return { keys: null, problem: "invalid", message };
|
|
82
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type FacilisConfig, type ManifestWarning, type StorageApi } from "@facilis.dev/core";
|
|
2
|
+
import { type StorageDriver, type StorageEncryptionKeys } from "@facilis.dev/storage";
|
|
3
|
+
/**
|
|
4
|
+
* Resolve the binary-storage runtime from the project config + environment (D-053).
|
|
5
|
+
*
|
|
6
|
+
* The environment, not the config, holds credentials and the token secret, so the
|
|
7
|
+
* committed facilis.config.ts never carries a secret. Every refusal is a manifest warning
|
|
8
|
+
* and yields a null storage: the app keeps booting and only the file routes answer
|
|
9
|
+
* `storage_unavailable`, exactly like the database target (D-068).
|
|
10
|
+
*/
|
|
11
|
+
export interface ResolvedStorage {
|
|
12
|
+
readonly storage: StorageApi | null;
|
|
13
|
+
readonly warnings: readonly ManifestWarning[];
|
|
14
|
+
}
|
|
15
|
+
export interface ResolveStorageDeps {
|
|
16
|
+
/** Test seam: build the low-level driver without touching the filesystem or the network. */
|
|
17
|
+
readonly createDriver?: (config: FacilisConfig["storage"], rootDir: string) => StorageDriver;
|
|
18
|
+
/** Test seam: the HMAC secret (defaults to FACILIS_STORAGE_SECRET / a per-boot random). */
|
|
19
|
+
readonly secret?: string;
|
|
20
|
+
/** Test seam: the dev fallback secret. */
|
|
21
|
+
readonly randomSecret?: () => string;
|
|
22
|
+
/** Test seam: skip the environment and use this key ring (D-117). */
|
|
23
|
+
readonly encryptionKeys?: StorageEncryptionKeys;
|
|
24
|
+
}
|
|
25
|
+
export declare function resolveStorage(config: FacilisConfig | null, env: NodeJS.ProcessEnv, projectRoot: string, deps?: ResolveStorageDeps): ResolvedStorage;
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { randomBytes } from "node:crypto";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { DEFAULT_STORAGE_CONFIG, } from "@facilis.dev/core";
|
|
4
|
+
import { buildSignedDownloadUrl, createEncryptedStorage, createLocalStorage, createS3Storage, verifyDownloadToken, } from "@facilis.dev/storage";
|
|
5
|
+
import { isProductionEnvironment } from "./env.js";
|
|
6
|
+
import { resolveEncryptionKeys } from "./storage-keys.js";
|
|
7
|
+
const SECRET_ENV = "FACILIS_STORAGE_SECRET";
|
|
8
|
+
const S3_KEY_ENV = "FACILIS_S3_ACCESS_KEY_ID";
|
|
9
|
+
const S3_SECRET_ENV = "FACILIS_S3_SECRET_ACCESS_KEY";
|
|
10
|
+
const S3_SESSION_ENV = "FACILIS_S3_SESSION_TOKEN";
|
|
11
|
+
const LOCAL_ROOT = join(".facilis", "binary");
|
|
12
|
+
export function resolveStorage(config, env, projectRoot, deps = {}) {
|
|
13
|
+
const storageConfig = config?.storage ?? DEFAULT_STORAGE_CONFIG;
|
|
14
|
+
const production = isProductionEnvironment(env);
|
|
15
|
+
const warnings = [];
|
|
16
|
+
if (storageConfig.driver === "local" && production) {
|
|
17
|
+
return {
|
|
18
|
+
storage: null,
|
|
19
|
+
warnings: [
|
|
20
|
+
warning("storage_local_in_production", 'Production refuses the local file driver: set storage.driver to "s3" and an S3-compatible bucket.'),
|
|
21
|
+
],
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
if (storageConfig.driver === "s3" &&
|
|
25
|
+
(readEnv(env, S3_KEY_ENV) === undefined || readEnv(env, S3_SECRET_ENV) === undefined)) {
|
|
26
|
+
return {
|
|
27
|
+
storage: null,
|
|
28
|
+
warnings: [
|
|
29
|
+
warning("storage_s3_credentials_missing", "S3 storage needs FACILIS_S3_ACCESS_KEY_ID and FACILIS_S3_SECRET_ACCESS_KEY."),
|
|
30
|
+
],
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
const secret = readSecret(env, deps);
|
|
34
|
+
if (secret === null) {
|
|
35
|
+
return {
|
|
36
|
+
storage: null,
|
|
37
|
+
warnings: [
|
|
38
|
+
warning("storage_secret_missing", "Set FACILIS_STORAGE_SECRET in production: signed download tokens need a stable secret across restarts and instances."),
|
|
39
|
+
],
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
let encryptionKeys = null;
|
|
43
|
+
if (storageConfig.encryption.enabled) {
|
|
44
|
+
if (deps.encryptionKeys !== undefined) {
|
|
45
|
+
encryptionKeys = deps.encryptionKeys;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
const resolved = resolveEncryptionKeys(env);
|
|
49
|
+
if (resolved.keys === null) {
|
|
50
|
+
return {
|
|
51
|
+
storage: null,
|
|
52
|
+
warnings: [
|
|
53
|
+
warning(resolved.problem === "missing"
|
|
54
|
+
? "storage_encryption_key_missing"
|
|
55
|
+
: "storage_encryption_key_invalid", resolved.message),
|
|
56
|
+
],
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
encryptionKeys = resolved.keys;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
const baseDriver = deps.createDriver?.(storageConfig, projectRoot) ??
|
|
64
|
+
createDriver(storageConfig, env, projectRoot);
|
|
65
|
+
const driver = encryptionKeys === null
|
|
66
|
+
? baseDriver
|
|
67
|
+
: createEncryptedStorage({ driver: baseDriver, keys: encryptionKeys });
|
|
68
|
+
return { storage: createStorageApi(driver, secret, storageConfig), warnings };
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
return {
|
|
72
|
+
storage: null,
|
|
73
|
+
warnings: [
|
|
74
|
+
warning("storage_boot_failed", `Binary storage could not start: ${describe(error)}`),
|
|
75
|
+
],
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function createDriver(config, env, projectRoot) {
|
|
80
|
+
if (config.driver === "local") {
|
|
81
|
+
return createLocalStorage({ rootDir: join(projectRoot, LOCAL_ROOT) });
|
|
82
|
+
}
|
|
83
|
+
const accessKeyId = readEnv(env, S3_KEY_ENV);
|
|
84
|
+
const secretAccessKey = readEnv(env, S3_SECRET_ENV);
|
|
85
|
+
// Config validation already requires bucket/region; the guard keeps a hand-edited or
|
|
86
|
+
// older virtual config from reaching the driver with nulls.
|
|
87
|
+
if (config.bucket === null ||
|
|
88
|
+
config.region === null ||
|
|
89
|
+
accessKeyId === undefined ||
|
|
90
|
+
secretAccessKey === undefined) {
|
|
91
|
+
throw new Error("S3 storage requires storage.bucket, storage.region, FACILIS_S3_ACCESS_KEY_ID and FACILIS_S3_SECRET_ACCESS_KEY");
|
|
92
|
+
}
|
|
93
|
+
const sessionToken = readEnv(env, S3_SESSION_ENV);
|
|
94
|
+
return createS3Storage({
|
|
95
|
+
bucket: config.bucket,
|
|
96
|
+
region: config.region,
|
|
97
|
+
accessKeyId,
|
|
98
|
+
secretAccessKey,
|
|
99
|
+
...(sessionToken === undefined ? {} : { sessionToken }),
|
|
100
|
+
...(config.endpoint === null ? {} : { endpoint: config.endpoint }),
|
|
101
|
+
...(config.forcePathStyle === null ? {} : { forcePathStyle: config.forcePathStyle }),
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
function createStorageApi(driver, secret, config) {
|
|
105
|
+
const signing = isSigningDriver(driver) ? driver : null;
|
|
106
|
+
const api = {
|
|
107
|
+
kind: driver.driver,
|
|
108
|
+
available: true,
|
|
109
|
+
maxUploadBytes: config.maxUploadBytes,
|
|
110
|
+
put: (bytes) => driver.put(bytes),
|
|
111
|
+
get: (hash) => driver.get(hash),
|
|
112
|
+
exists: (hash) => driver.exists(hash),
|
|
113
|
+
delete: (hash) => driver.delete(hash),
|
|
114
|
+
buildDownloadUrl: (fileId, options) => buildSignedDownloadUrl({
|
|
115
|
+
fileId,
|
|
116
|
+
secret,
|
|
117
|
+
expiresInSeconds: options?.expiresInSeconds ?? config.tokenTtlSeconds,
|
|
118
|
+
...(options?.tenantId === undefined ? {} : { tenantId: options.tenantId }),
|
|
119
|
+
...(options?.subject === undefined ? {} : { subject: options.subject }),
|
|
120
|
+
}),
|
|
121
|
+
verifyDownloadToken: (token, fileId) => {
|
|
122
|
+
const payload = verifyDownloadToken(token, secret);
|
|
123
|
+
return payload === null || payload.fileId !== fileId ? null : payload;
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
if (signing !== null) {
|
|
127
|
+
api.presignedGetUrl = (hash, options) => signing.signedGetUrl(hash, options);
|
|
128
|
+
}
|
|
129
|
+
return api;
|
|
130
|
+
}
|
|
131
|
+
function isSigningDriver(driver) {
|
|
132
|
+
return typeof driver.signedGetUrl === "function";
|
|
133
|
+
}
|
|
134
|
+
function readSecret(env, deps) {
|
|
135
|
+
if (deps.secret !== undefined)
|
|
136
|
+
return deps.secret.length === 0 ? null : deps.secret;
|
|
137
|
+
const fromEnv = readEnv(env, SECRET_ENV);
|
|
138
|
+
if (fromEnv !== undefined)
|
|
139
|
+
return fromEnv;
|
|
140
|
+
if (isProductionEnvironment(env))
|
|
141
|
+
return null;
|
|
142
|
+
// Dev tokens only need to live for the boot (five-minute TTL); a per-boot secret keeps
|
|
143
|
+
// the zero-config dev path working without writing a secret to the project.
|
|
144
|
+
return (deps.randomSecret ?? (() => randomBytes(32).toString("hex")))();
|
|
145
|
+
}
|
|
146
|
+
function readEnv(env, name) {
|
|
147
|
+
const value = env[name]?.trim();
|
|
148
|
+
return value === undefined || value.length === 0 ? undefined : value;
|
|
149
|
+
}
|
|
150
|
+
function warning(code, message) {
|
|
151
|
+
return { code, message };
|
|
152
|
+
}
|
|
153
|
+
function describe(error) {
|
|
154
|
+
return error instanceof Error ? error.message : String(error);
|
|
155
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type FacilisDb } from "@facilis.dev/db";
|
|
2
|
+
import type { ManifestWarning } from "@facilis.dev/core";
|
|
3
|
+
/**
|
|
4
|
+
* Boot step: provision `facilis_system` after the app role (D-099).
|
|
5
|
+
*
|
|
6
|
+
* A failure is a manifest warning, never a failed boot: without the role every sudo call
|
|
7
|
+
* fails closed at SET ROLE, so the app degrades to "no escalation" instead of crashing.
|
|
8
|
+
*/
|
|
9
|
+
export declare function provisionSystemRole(db: FacilisDb, warnings: ManifestWarning[]): Promise<void>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ensureSystemRole } from "@facilis.dev/db";
|
|
2
|
+
/**
|
|
3
|
+
* Boot step: provision `facilis_system` after the app role (D-099).
|
|
4
|
+
*
|
|
5
|
+
* A failure is a manifest warning, never a failed boot: without the role every sudo call
|
|
6
|
+
* fails closed at SET ROLE, so the app degrades to "no escalation" instead of crashing.
|
|
7
|
+
*/
|
|
8
|
+
export async function provisionSystemRole(db, warnings) {
|
|
9
|
+
try {
|
|
10
|
+
await ensureSystemRole(db);
|
|
11
|
+
}
|
|
12
|
+
catch (error) {
|
|
13
|
+
warnings.push({
|
|
14
|
+
code: "system_role_failed",
|
|
15
|
+
message: `Could not provision the system role: ${describe(error)}`,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function describe(error) {
|
|
20
|
+
return error instanceof Error ? error.message : String(error);
|
|
21
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ManifestWarning, TasksApi } from "@facilis.dev/core";
|
|
2
|
+
import type { FacilisDb } from "@facilis.dev/db";
|
|
3
|
+
/** The booted task runtime carried by BootstrapState (D-135). */
|
|
4
|
+
export interface TasksRuntime {
|
|
5
|
+
readonly api: TasksApi;
|
|
6
|
+
}
|
|
7
|
+
export interface BootTasksOptions {
|
|
8
|
+
readonly db: FacilisDb;
|
|
9
|
+
readonly tenantId: string;
|
|
10
|
+
/** Session-wide manifest warnings; boot pushes into it instead of throwing. */
|
|
11
|
+
readonly warnings: ManifestWarning[];
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Boots the manual-task runtime (D-135, docs/WORKFLOWS.md §7).
|
|
15
|
+
*
|
|
16
|
+
* Never throws: without the table the API is unavailable with a manifest warning, because a
|
|
17
|
+
* reload-durable task needs rows (there is deliberately no in-memory mode). The returned
|
|
18
|
+
* runtime is carried by BootstrapState and exposed as ctx.tasks.
|
|
19
|
+
*/
|
|
20
|
+
export declare function bootTasks(options: BootTasksOptions): Promise<TasksRuntime | null>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { createDbTaskStore, isTasksTableAvailable } from "./db-store.js";
|
|
2
|
+
import { createTasksApi } from "./runtime.js";
|
|
3
|
+
/**
|
|
4
|
+
* Boots the manual-task runtime (D-135, docs/WORKFLOWS.md §7).
|
|
5
|
+
*
|
|
6
|
+
* Never throws: without the table the API is unavailable with a manifest warning, because a
|
|
7
|
+
* reload-durable task needs rows (there is deliberately no in-memory mode). The returned
|
|
8
|
+
* runtime is carried by BootstrapState and exposed as ctx.tasks.
|
|
9
|
+
*/
|
|
10
|
+
export async function bootTasks(options) {
|
|
11
|
+
const { db, tenantId, warnings } = options;
|
|
12
|
+
try {
|
|
13
|
+
if (!(await isTasksTableAvailable(db))) {
|
|
14
|
+
warnings.push({
|
|
15
|
+
code: "tasks_table_missing",
|
|
16
|
+
message: "facilis_tasks is missing; manual tasks are disabled. Re-export the table from db/schema.ts and apply the framework migration.",
|
|
17
|
+
});
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
return { api: createTasksApi(createDbTaskStore({ db, tenantId })) };
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
warnings.push({
|
|
24
|
+
code: "tasks_boot_failed",
|
|
25
|
+
message: "Manual tasks are disabled: " + describe(error),
|
|
26
|
+
});
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function describe(error) {
|
|
31
|
+
return error instanceof Error ? error.message : String(error);
|
|
32
|
+
}
|