@jini-ai/platform 0.7.3-next.1 → 0.7.3-next.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/README.md +13 -0
- package/dist/download-lock.d.ts +3 -1
- package/dist/download-lock.js +4 -4
- package/dist/download-maintenance.js +6 -6
- package/dist/download-state.js +17 -14
- package/dist/download-store.d.ts +34 -10
- package/dist/download-store.js +24 -20
- package/dist/download-target.d.ts +6 -2
- package/dist/download-target.js +7 -7
- package/dist/download-transfer.js +18 -12
- package/dist/download.js +4 -4
- package/dist/fetch-with-timeout.d.ts +0 -53
- package/dist/fetch-with-timeout.js +56 -6
- package/dist/fs/directory-running-lock.d.ts +4 -0
- package/dist/fs/directory-running-lock.js +8 -1
- package/dist/fs/directory-workspace.d.ts +2 -1
- package/dist/fs/directory-workspace.js +2 -2
- package/dist/fs/durable-json.d.ts +3 -16
- package/dist/fs/durable-json.js +4 -2
- package/dist/fs/guarded-reader.d.ts +10 -0
- package/dist/fs/guarded-reader.js +34 -1
- package/dist/fs/index.d.ts +4 -0
- package/dist/fs/index.js +4 -0
- package/dist/fs/leased-directory-move.d.ts +49 -0
- package/dist/fs/leased-directory-move.js +31 -0
- package/dist/fs/owned-temp-root.d.ts +74 -0
- package/dist/fs/owned-temp-root.js +203 -0
- package/dist/fs/recent-directories.d.ts +2 -1
- package/dist/fs/resolve-directory-target.d.ts +33 -0
- package/dist/fs/resolve-directory-target.js +58 -0
- package/dist/fs/staged-file.d.ts +40 -0
- package/dist/fs/staged-file.js +75 -0
- package/dist/fs/strict-containment.d.ts +14 -0
- package/dist/fs/strict-containment.js +14 -0
- package/dist/image/png-encode.d.ts +41 -0
- package/dist/image/png-encode.js +96 -0
- package/dist/index.d.ts +3 -1
- package/dist/mail/email-template-agent-tools.d.ts +150 -0
- package/dist/mail/email-template-agent-tools.js +86 -0
- package/dist/mail/email-template-tool-registrations.d.ts +73 -0
- package/dist/mail/email-template-tool-registrations.js +66 -0
- package/dist/mail/feedback-route.d.ts +50 -0
- package/dist/mail/feedback-route.js +46 -0
- package/dist/mail/feedback-setup.d.ts +44 -0
- package/dist/mail/feedback-setup.js +53 -0
- package/dist/mail/feedback-sources.d.ts +67 -0
- package/dist/mail/feedback-sources.js +42 -0
- package/dist/mail/index.d.ts +10 -1
- package/dist/mail/index.js +4 -0
- package/dist/mail/mail-status.d.ts +32 -0
- package/dist/mail/mail-status.js +2 -0
- package/dist/mail/positional-purpose-gate.d.ts +14 -0
- package/dist/mail/positional-purpose-gate.js +18 -0
- package/dist/mail/purpose-gate-probe.d.ts +18 -0
- package/dist/mail/purpose-gate-probe.js +22 -0
- package/dist/mail/resolve-mailer.d.ts +13 -1
- package/dist/mail/resolve-mailer.js +11 -5
- package/dist/mail/sql/activity.repo.d.ts +20 -0
- package/dist/mail/sql/activity.repo.js +133 -0
- package/dist/mail/sql/attempts.repo.d.ts +17 -0
- package/dist/mail/sql/attempts.repo.js +32 -0
- package/dist/mail/sql/capture.repo.d.ts +69 -0
- package/dist/mail/sql/capture.repo.js +119 -0
- package/dist/mail/sql/feedback-inbox.repo.d.ts +12 -0
- package/dist/mail/sql/feedback-inbox.repo.js +32 -0
- package/dist/mail/sql/index.d.ts +12 -0
- package/dist/mail/sql/index.js +12 -0
- package/dist/mail/sql/ledger.repo.d.ts +29 -0
- package/dist/mail/sql/ledger.repo.js +57 -0
- package/dist/mail/sql/retention.d.ts +23 -0
- package/dist/mail/sql/retention.js +53 -0
- package/dist/mail/sql/site-feedback-route.d.ts +18 -0
- package/dist/mail/sql/site-feedback-route.js +22 -0
- package/dist/mail/sql/suppression-admin.repo.d.ts +11 -0
- package/dist/mail/sql/suppression-admin.repo.js +76 -0
- package/dist/mail/sql/suppression.repo.d.ts +10 -0
- package/dist/mail/sql/suppression.repo.js +33 -0
- package/dist/mail/test-send.d.ts +147 -0
- package/dist/mail/test-send.js +201 -0
- package/dist/mail/use-readiness.d.ts +104 -0
- package/dist/mail/use-readiness.js +140 -0
- package/dist/object-store/local-fs.js +34 -1
- package/dist/object-store/site/artifact-provider.d.ts +65 -0
- package/dist/object-store/site/artifact-provider.js +37 -0
- package/dist/object-store/site/registry.d.ts +110 -0
- package/dist/object-store/site/registry.js +93 -0
- package/dist/object-store/site/setting.d.ts +34 -0
- package/dist/object-store/site/setting.js +32 -0
- package/dist/process-probes.d.ts +11 -4
- package/dist/process-probes.js +3 -3
- package/dist/process-top-footprint.d.ts +1 -1
- package/dist/process.d.ts +3 -17
- package/dist/process.js +3 -2
- package/dist/retention/index.d.ts +6 -0
- package/dist/retention/index.js +6 -0
- package/dist/retention/measure-tree.d.ts +68 -0
- package/dist/retention/measure-tree.js +205 -0
- package/dist/retention/preview-store.d.ts +10 -0
- package/dist/retention/preview-store.js +26 -0
- package/dist/retention/routes.d.ts +23 -0
- package/dist/retention/routes.js +24 -0
- package/dist/retention/runner.d.ts +103 -0
- package/dist/retention/runner.js +164 -0
- package/dist/secrets/credential-sets/index.d.ts +1 -0
- package/dist/secrets/credential-sets/index.js +1 -0
- package/dist/secrets/credential-sets/store-vault-guards.d.ts +26 -0
- package/dist/secrets/credential-sets/store-vault-guards.js +30 -0
- package/dist/secrets/credential-sets/vault.service.d.ts +1 -1
- package/dist/secrets/index.d.ts +1 -1
- package/dist/secrets/index.js +1 -1
- package/dist/secrets/keyring.env.d.ts +1 -1
- package/dist/secrets/keyring.env.js +3 -5
- package/dist/secrets/keyring.memory.d.ts +4 -1
- package/dist/secrets/keyring.memory.js +4 -1
- package/dist/secrets/legacy-codecs.d.ts +381 -0
- package/dist/secrets/legacy-codecs.js +468 -0
- package/dist/secrets/legacy-owner.d.ts +3 -11
- package/dist/secrets/root-key/ensure.d.ts +154 -0
- package/dist/secrets/root-key/ensure.js +328 -0
- package/dist/secrets/root-key/files.d.ts +104 -0
- package/dist/secrets/root-key/files.js +166 -0
- package/dist/secrets/root-key/material.d.ts +132 -0
- package/dist/secrets/root-key/material.js +116 -0
- package/dist/secrets/root-key/ordered-keyring.d.ts +157 -0
- package/dist/secrets/root-key/ordered-keyring.js +104 -0
- package/dist/secrets/root-key/reconcile.d.ts +50 -0
- package/dist/secrets/root-key/reconcile.js +147 -0
- package/dist/secrets/root-key/site-keyring-errors.d.ts +78 -0
- package/dist/secrets/root-key/site-keyring-errors.js +37 -0
- package/dist/secrets/root-key/sources.d.ts +79 -0
- package/dist/secrets/root-key/sources.js +119 -0
- package/dist/secrets/secret-sealer.aesgcm.d.ts +50 -2
- package/dist/secrets/secret-sealer.aesgcm.js +107 -19
- package/dist/web/tool-registrations.d.ts +67 -0
- package/dist/web/tool-registrations.js +44 -0
- package/package.json +139 -7
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { type ParsedRootKeyHex as ParsedSiteKeyHex, type RootKeyStatus as SiteKeyStatus, type RootKeyReveal as SiteKeyReveal } from "../keyring.env.js";
|
|
2
|
+
export interface SiteKeySource {
|
|
3
|
+
readonly kind: string;
|
|
4
|
+
readonly path?: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* One {@link SiteKeySource}'s raw material from `env`/the filesystem — `undefined` when that source
|
|
8
|
+
* has none. The ONE place both `keyring.env.ts`'s `EnvOrFileKeyring.resolveSiteKeyFromSources` and
|
|
9
|
+
* `site-key-ensure.ts`'s `ensureSiteKey` read a source's material, so the "a blank env var counts
|
|
10
|
+
* as unset" rule below can never drift between the two (it did, briefly — A3a found it duplicated
|
|
11
|
+
* and inconsistent, each side reading the env case slightly differently).
|
|
12
|
+
*
|
|
13
|
+
* A env-kind source whose var IS set but blank or whitespace-only is treated as ABSENT, not
|
|
14
|
+
* present-but-invalid: `development/scripts/start.mjs`'s own `clearBlankSiteKeyEnv` exists for the
|
|
15
|
+
* exact same reason — a spawned child (the desktop app's own boot path) can pass a blank value
|
|
16
|
+
* through, and an operator's shell profile can just as easily a blank site-key variable with nothing
|
|
17
|
+
* after it. Either way the var must fall through to the next source exactly as if it had never been
|
|
18
|
+
* set, not be reported as a broken/invalid key. A file-kind source's content is NOT trimmed or
|
|
19
|
+
* blank-checked here — a real file that exists and is empty is a genuinely broken on-disk state
|
|
20
|
+
* ({@link parseSiteKeyHex}'s own `"empty"` rejection), distinct from an env var nobody set a value
|
|
21
|
+
* for.
|
|
22
|
+
*
|
|
23
|
+
* @complexity O(1) env read, or one `existsSync` plus a file read for a file-kind source.
|
|
24
|
+
*/
|
|
25
|
+
export interface SiteKeySourceMaterial {
|
|
26
|
+
readonly raw: string;
|
|
27
|
+
readonly envVarName?: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* `.site-meta.json`'s raw parsed object under `siteDir`, or `undefined` when the file is missing,
|
|
31
|
+
* unreadable, not valid JSON, or not a JSON object. The one shared parse every field-specific
|
|
32
|
+
* reader in this module ({@link resolveSiteKeyId}, {@link resolveSiteKeyFingerprint}) builds on, so
|
|
33
|
+
* a corrupt-file/non-object verdict can never drift between them — and the one
|
|
34
|
+
* `site-key-ensure.ts`'s own fingerprint-stamp reconciliation imports (site-key plan §A.4), since
|
|
35
|
+
* that module depends on this one, never the reverse (this file's own header).
|
|
36
|
+
*
|
|
37
|
+
* Never throws — same never-throws contract every reader built on it shares.
|
|
38
|
+
*
|
|
39
|
+
* @complexity O(1) — one small, bounded-size file read.
|
|
40
|
+
*/
|
|
41
|
+
export declare function readSiteMetaJson({ filePath, readFileSync }: {
|
|
42
|
+
filePath: string;
|
|
43
|
+
readFileSync: (filePath: string, encoding: "utf8") => string;
|
|
44
|
+
}, _optional?: {}): Record<string, unknown> | undefined;
|
|
45
|
+
export declare function readSiteKeySourceMaterial({ source, env, fs, resolveSiteKeyEnv }: {
|
|
46
|
+
source: SiteKeySource;
|
|
47
|
+
env: Record<string, string | undefined>;
|
|
48
|
+
fs: {
|
|
49
|
+
existsSync(path: string): boolean;
|
|
50
|
+
readFileSync(path: string, encoding: "utf8"): string;
|
|
51
|
+
};
|
|
52
|
+
resolveSiteKeyEnv: (required: {
|
|
53
|
+
env: Record<string, string | undefined>;
|
|
54
|
+
}) => {
|
|
55
|
+
kind: "ok";
|
|
56
|
+
value: string;
|
|
57
|
+
varName: string;
|
|
58
|
+
} | {
|
|
59
|
+
kind: "absent";
|
|
60
|
+
};
|
|
61
|
+
}, _optional?: Record<string, never>): SiteKeySourceMaterial | undefined;
|
|
62
|
+
/** The first source in `sources` that has ANY material — present-but-invalid still counts and
|
|
63
|
+
* stops the scan (site-key plan §A.2: adopting silently past a broken source would still be
|
|
64
|
+
* wrong, the same reasoning `keyring.env.ts`'s own env-then-file resolution already follows). */
|
|
65
|
+
export declare function findFirstPresentMaterial({ sources, env, readRawSiteKeyMaterial }: {
|
|
66
|
+
sources: readonly SiteKeySource[];
|
|
67
|
+
env: Record<string, string | undefined>;
|
|
68
|
+
readRawSiteKeyMaterial: (source: SiteKeySource, env: Record<string, string | undefined>) => string | undefined;
|
|
69
|
+
}, _optional?: {}): string | undefined;
|
|
70
|
+
/** The first source in the list holding ANY material, with that material's verdict. */
|
|
71
|
+
interface PresentSiteKey {
|
|
72
|
+
readonly source: SiteKeySource;
|
|
73
|
+
readonly material: SiteKeySourceMaterial;
|
|
74
|
+
readonly parsed: ParsedSiteKeyHex;
|
|
75
|
+
}
|
|
76
|
+
/** Status/reveal share the first-present rule with derivation. Never mint, never cache, never
|
|
77
|
+
* silently skip a broken source: that could select a key the operator did not intend.
|
|
78
|
+
* @complexity O(sources), with one small env/file read per attempted source.
|
|
79
|
+
*/
|
|
80
|
+
export declare function firstPresentSiteKey(input: {
|
|
81
|
+
sources: readonly SiteKeySource[];
|
|
82
|
+
env: Record<string, string | undefined>;
|
|
83
|
+
readSiteKeySourceMaterial: InspectSiteKeyMaterialOptions["readSiteKeySourceMaterial"];
|
|
84
|
+
}, _optional?: {}): PresentSiteKey | undefined;
|
|
85
|
+
export interface InspectSiteKeyMaterialOptions {
|
|
86
|
+
sources: readonly SiteKeySource[];
|
|
87
|
+
env: () => Record<string, string | undefined>;
|
|
88
|
+
siteKeyFilePathFrom: (required: {
|
|
89
|
+
sources: readonly SiteKeySource[];
|
|
90
|
+
}) => string | undefined;
|
|
91
|
+
readSiteKeySourceMaterial: (required: {
|
|
92
|
+
source: SiteKeySource;
|
|
93
|
+
env: Record<string, string | undefined>;
|
|
94
|
+
}) => SiteKeySourceMaterial | undefined;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Read-only snapshot over the same explicit sources derivation uses. Re-read on every call so
|
|
98
|
+
* status and recovery never report cached material. A present invalid source refuses resolution;
|
|
99
|
+
* it never falls through to another key. Nothing here generates, replaces or repairs a file.
|
|
100
|
+
*/
|
|
101
|
+
export declare function inspectSiteKeyMaterial(options: InspectSiteKeyMaterialOptions, _optional?: {}): SiteKeyStatus;
|
|
102
|
+
/**
|
|
103
|
+
* Like {@link inspectSiteKeyMaterial}, but includes the raw key value when one is active — backs
|
|
104
|
+
* the admin "site key" panel's explicit, permission-gated Reveal action (owner: "i want that
|
|
105
|
+
* token to be visible to admins or else when it breaks they have no idea whats going on" —
|
|
106
|
+
* fingerprint-only was the ORIGINAL brief; this supersedes it). Never called on page load, only
|
|
107
|
+
* from a dedicated route the operator must click through — see `server/inbound/admin-http/routes/
|
|
108
|
+
* system/site-key.ts`'s `POST .../reveal`.
|
|
109
|
+
*
|
|
110
|
+
* Reads whichever source is currently active (env or file, same precedence as `resolveSiteKey`),
|
|
111
|
+
* so an admin can confirm the value in this UI matches what they set in their host's secrets/their shell,
|
|
112
|
+
* not only the file-backed case.
|
|
113
|
+
*/
|
|
114
|
+
export declare function revealSiteKeyMaterial(options: InspectSiteKeyMaterialOptions, _optional?: {}): SiteKeyReveal;
|
|
115
|
+
/**
|
|
116
|
+
* This site's own id from its `.site-meta.json`: `siteId` (a randomUUID minted by init-site), else
|
|
117
|
+
* the first-boot `siteKeyId` (the boot completes the file with `siteId` = that same id, so the name
|
|
118
|
+
* holds across that first restart). Undefined when the file is missing or holds neither. Shared by
|
|
119
|
+
* the server's site identity (`deps.ts`'s `siteIdentityFor`) and `host deploy config`, which carries
|
|
120
|
+
* it to the deployed server as the host's site-id environment variable, so both name the same site the same way.
|
|
121
|
+
* @complexity O(1), one small file read.
|
|
122
|
+
*/
|
|
123
|
+
export declare function readSiteMetaId({ siteDir, readSiteMetaJson, idField, fallbackIdField }: {
|
|
124
|
+
siteDir: string;
|
|
125
|
+
readSiteMetaJson: (required: {
|
|
126
|
+
siteDir: string;
|
|
127
|
+
}) => Record<string, unknown> | undefined;
|
|
128
|
+
idField: string;
|
|
129
|
+
fallbackIdField: string;
|
|
130
|
+
}, _optional?: {}): string | undefined;
|
|
131
|
+
export {};
|
|
132
|
+
//# sourceMappingURL=material.d.ts.map
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { parseRootKeyHex as parseSiteKeyHex, fingerprintRootKeyHex as fingerprintSiteKeyHex } from "../keyring.env.js";
|
|
2
|
+
import { orFallbackSync } from "@jini-ai/core/errors/idioms";
|
|
3
|
+
/**
|
|
4
|
+
* `.site-meta.json`'s raw parsed object under `siteDir`, or `undefined` when the file is missing,
|
|
5
|
+
* unreadable, not valid JSON, or not a JSON object. The one shared parse every field-specific
|
|
6
|
+
* reader in this module ({@link resolveSiteKeyId}, {@link resolveSiteKeyFingerprint}) builds on, so
|
|
7
|
+
* a corrupt-file/non-object verdict can never drift between them — and the one
|
|
8
|
+
* `site-key-ensure.ts`'s own fingerprint-stamp reconciliation imports (site-key plan §A.4), since
|
|
9
|
+
* that module depends on this one, never the reverse (this file's own header).
|
|
10
|
+
*
|
|
11
|
+
* Never throws — same never-throws contract every reader built on it shares.
|
|
12
|
+
*
|
|
13
|
+
* @complexity O(1) — one small, bounded-size file read.
|
|
14
|
+
*/
|
|
15
|
+
export function readSiteMetaJson({ filePath, readFileSync }, _optional = {}) {
|
|
16
|
+
const raw = orFallbackSync({ work: () => readFileSync(filePath, "utf8"), fallback: undefined, step: "Read site key metadata" });
|
|
17
|
+
if (raw === undefined)
|
|
18
|
+
return undefined;
|
|
19
|
+
let parsed;
|
|
20
|
+
try {
|
|
21
|
+
parsed = JSON.parse(raw);
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) ? parsed : undefined;
|
|
27
|
+
}
|
|
28
|
+
export function readSiteKeySourceMaterial({ source, env, fs, resolveSiteKeyEnv }, _optional = {}) {
|
|
29
|
+
if (source.kind === "env") {
|
|
30
|
+
const resolved = resolveSiteKeyEnv({ env });
|
|
31
|
+
return resolved.kind === "ok" ? { raw: resolved.value, envVarName: resolved.varName } : undefined;
|
|
32
|
+
}
|
|
33
|
+
return source.path !== undefined && fs.existsSync(source.path) ? { raw: fs.readFileSync(source.path, "utf8") } : undefined;
|
|
34
|
+
}
|
|
35
|
+
/** The first source in `sources` that has ANY material — present-but-invalid still counts and
|
|
36
|
+
* stops the scan (site-key plan §A.2: adopting silently past a broken source would still be
|
|
37
|
+
* wrong, the same reasoning `keyring.env.ts`'s own env-then-file resolution already follows). */
|
|
38
|
+
export function findFirstPresentMaterial({ sources, env, readRawSiteKeyMaterial }, _optional = {}) {
|
|
39
|
+
for (const source of sources) {
|
|
40
|
+
const raw = readRawSiteKeyMaterial(source, env);
|
|
41
|
+
if (raw !== undefined)
|
|
42
|
+
return raw;
|
|
43
|
+
}
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
/** Status/reveal share the first-present rule with derivation. Never mint, never cache, never
|
|
47
|
+
* silently skip a broken source: that could select a key the operator did not intend.
|
|
48
|
+
* @complexity O(sources), with one small env/file read per attempted source.
|
|
49
|
+
*/
|
|
50
|
+
export function firstPresentSiteKey(input, _optional = {}) {
|
|
51
|
+
for (const source of input.sources) {
|
|
52
|
+
const material = input.readSiteKeySourceMaterial({ source, env: input.env });
|
|
53
|
+
if (material !== undefined)
|
|
54
|
+
return { source, material, parsed: parseSiteKeyHex({ raw: material.raw }) };
|
|
55
|
+
}
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Read-only snapshot over the same explicit sources derivation uses. Re-read on every call so
|
|
60
|
+
* status and recovery never report cached material. A present invalid source refuses resolution;
|
|
61
|
+
* it never falls through to another key. Nothing here generates, replaces or repairs a file.
|
|
62
|
+
*/
|
|
63
|
+
export function inspectSiteKeyMaterial(options, _optional = {}) {
|
|
64
|
+
const { hex: _hex, ...status } = readSiteKeyReveal(options);
|
|
65
|
+
return status;
|
|
66
|
+
}
|
|
67
|
+
/** One read behind both status functions; {@link inspectSiteKeyMaterial} drops `hex` from it. */
|
|
68
|
+
function readSiteKeyReveal(options, _optional = {}) {
|
|
69
|
+
// No write target for a local site with unreadable metadata; legacy shared files are read-only.
|
|
70
|
+
const keyFilePath = options.siteKeyFilePathFrom({ sources: options.sources }) ?? "";
|
|
71
|
+
const present = firstPresentSiteKey({ sources: options.sources, env: options.env(), readSiteKeySourceMaterial: options.readSiteKeySourceMaterial });
|
|
72
|
+
return siteKeyRevealOf({ present, keyFilePath });
|
|
73
|
+
}
|
|
74
|
+
/** The reveal shape (key order is part of the HTTP response) for whatever source is present;
|
|
75
|
+
* `envVarName` only for the env source. The `invalid`/`reason` pair both status functions spread
|
|
76
|
+
* onto an inactive result — present together or not at all. */
|
|
77
|
+
function siteKeyRevealOf(input) {
|
|
78
|
+
const { present, keyFilePath } = input;
|
|
79
|
+
if (present === undefined)
|
|
80
|
+
return { active: false, source: "none", keyFilePath };
|
|
81
|
+
const source = present.source.kind === "env" ? "env" : "file";
|
|
82
|
+
const provenance = present.source.kind === "env" ? { envVarName: present.material.envVarName } : {};
|
|
83
|
+
if (present.parsed.ok) {
|
|
84
|
+
return { active: true, source, hex: present.parsed.hex, fingerprint: fingerprintSiteKeyHex({ hex: present.parsed.hex }), keyFilePath, ...provenance };
|
|
85
|
+
}
|
|
86
|
+
return { active: false, source, invalid: true, reason: present.parsed.reason, keyFilePath, ...provenance };
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Like {@link inspectSiteKeyMaterial}, but includes the raw key value when one is active — backs
|
|
90
|
+
* the admin "site key" panel's explicit, permission-gated Reveal action (owner: "i want that
|
|
91
|
+
* token to be visible to admins or else when it breaks they have no idea whats going on" —
|
|
92
|
+
* fingerprint-only was the ORIGINAL brief; this supersedes it). Never called on page load, only
|
|
93
|
+
* from a dedicated route the operator must click through — see `server/inbound/admin-http/routes/
|
|
94
|
+
* system/site-key.ts`'s `POST .../reveal`.
|
|
95
|
+
*
|
|
96
|
+
* Reads whichever source is currently active (env or file, same precedence as `resolveSiteKey`),
|
|
97
|
+
* so an admin can confirm the value in this UI matches what they set in their host's secrets/their shell,
|
|
98
|
+
* not only the file-backed case.
|
|
99
|
+
*/
|
|
100
|
+
export function revealSiteKeyMaterial(options, _optional = {}) {
|
|
101
|
+
return readSiteKeyReveal(options);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* This site's own id from its `.site-meta.json`: `siteId` (a randomUUID minted by init-site), else
|
|
105
|
+
* the first-boot `siteKeyId` (the boot completes the file with `siteId` = that same id, so the name
|
|
106
|
+
* holds across that first restart). Undefined when the file is missing or holds neither. Shared by
|
|
107
|
+
* the server's site identity (`deps.ts`'s `siteIdentityFor`) and `host deploy config`, which carries
|
|
108
|
+
* it to the deployed server as the host's site-id environment variable, so both name the same site the same way.
|
|
109
|
+
* @complexity O(1), one small file read.
|
|
110
|
+
*/
|
|
111
|
+
export function readSiteMetaId({ siteDir, readSiteMetaJson, idField, fallbackIdField }, _optional = {}) {
|
|
112
|
+
const meta = readSiteMetaJson({ siteDir });
|
|
113
|
+
const id = typeof meta?.[idField] === "string" && meta[idField] !== "" ? meta[idField] : meta?.[fallbackIdField];
|
|
114
|
+
return typeof id === "string" && id !== "" ? id : undefined;
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=material.js.map
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import type { KeyringPort } from '@jini-ai/core/contracts/vault';
|
|
2
|
+
import { createSiteKeyringErrors } from './site-keyring-errors.js';
|
|
3
|
+
import { fingerprintRootKeyHex, type parseRootKeyHex, type generateFileRootKey } from "../keyring.env.js";
|
|
4
|
+
import { inspectSiteKeyMaterial, revealSiteKeyMaterial, type SiteKeySource, type SiteKeySourceMaterial } from "./material.js";
|
|
5
|
+
export declare function createOrderedSiteKeyring(required: {
|
|
6
|
+
sources: readonly SiteKeySource[];
|
|
7
|
+
keyId: string;
|
|
8
|
+
hkdfSalt: string | Uint8Array;
|
|
9
|
+
env: () => Record<string, string | undefined>;
|
|
10
|
+
readSourceMaterial: (required: {
|
|
11
|
+
source: SiteKeySource;
|
|
12
|
+
env: Record<string, string | undefined>;
|
|
13
|
+
}) => SiteKeySourceMaterial | undefined;
|
|
14
|
+
describeSource: (source: SiteKeySource) => string;
|
|
15
|
+
unusableSiteKeyError: (required: {
|
|
16
|
+
source: SiteKeySource;
|
|
17
|
+
rejection: {
|
|
18
|
+
reason: "empty" | "not-hex" | "odd-length" | "too-short";
|
|
19
|
+
hexDigits: number;
|
|
20
|
+
};
|
|
21
|
+
}) => Error;
|
|
22
|
+
}, optional?: {
|
|
23
|
+
FixedSiteKeyKeyring?: new (required: {
|
|
24
|
+
hex: string;
|
|
25
|
+
hkdfSalt: string | Uint8Array;
|
|
26
|
+
}, optional?: {
|
|
27
|
+
keyId?: string;
|
|
28
|
+
}) => KeyringPort;
|
|
29
|
+
}): {
|
|
30
|
+
activeKey: (_required?: {}, _optional?: {}) => Promise<{
|
|
31
|
+
keyId: string;
|
|
32
|
+
}>;
|
|
33
|
+
deriveSigningSecret: (input: {
|
|
34
|
+
workspaceId: string;
|
|
35
|
+
subscriptionId: string;
|
|
36
|
+
version: number;
|
|
37
|
+
}) => Promise<Uint8Array<ArrayBufferLike>>;
|
|
38
|
+
derive: (input: {
|
|
39
|
+
workspaceId: string;
|
|
40
|
+
purpose: string;
|
|
41
|
+
info: string;
|
|
42
|
+
}) => Promise<Uint8Array<ArrayBufferLike>>;
|
|
43
|
+
};
|
|
44
|
+
export declare function isNoSiteKeyError({ error }: {
|
|
45
|
+
error: unknown;
|
|
46
|
+
}, _optional?: Record<string, never>): boolean;
|
|
47
|
+
export declare function createExclusiveSiteKeyGenerator(required: {
|
|
48
|
+
fs: Pick<typeof import("node:fs"), "mkdirSync" | "writeFileSync">;
|
|
49
|
+
randomBytes: (size: number) => Buffer;
|
|
50
|
+
directoryMode: number;
|
|
51
|
+
fileMode: number;
|
|
52
|
+
alreadyExistsError: (required: {
|
|
53
|
+
keyFilePath: string;
|
|
54
|
+
}) => Error;
|
|
55
|
+
}, _optional?: {}): ({ keyFilePath }: {
|
|
56
|
+
keyFilePath: string;
|
|
57
|
+
}, _optional?: {}) => {
|
|
58
|
+
hex: string;
|
|
59
|
+
fingerprint: string;
|
|
60
|
+
keyFilePath: string;
|
|
61
|
+
};
|
|
62
|
+
export declare function bindSiteKeyrings(required: Omit<Parameters<typeof createOrderedSiteKeyring>[0], 'sources' | 'keyId' | 'unusableSiteKeyError'> & Parameters<typeof createSiteKeyringErrors>[0] & {
|
|
63
|
+
defaultKeyId: string;
|
|
64
|
+
FixedSiteKeyKeyring: new (required: {
|
|
65
|
+
hex: string;
|
|
66
|
+
hkdfSalt: string | Uint8Array;
|
|
67
|
+
}, optional?: {
|
|
68
|
+
keyId?: string;
|
|
69
|
+
}) => KeyringPort;
|
|
70
|
+
InMemoryKeyring: new (required: {
|
|
71
|
+
hkdfSalt: string | Uint8Array;
|
|
72
|
+
}, optional?: {
|
|
73
|
+
keyId?: string;
|
|
74
|
+
}) => KeyringPort & {
|
|
75
|
+
activeKey(): ReturnType<KeyringPort['activeKey']>;
|
|
76
|
+
};
|
|
77
|
+
SiteKeyFileAlreadyExistsError: abstract new (...args: never[]) => Error;
|
|
78
|
+
parseSiteKeyHex: typeof parseRootKeyHex;
|
|
79
|
+
fingerprintSiteKeyHex: typeof fingerprintRootKeyHex;
|
|
80
|
+
generateFileSiteKey: typeof generateFileRootKey;
|
|
81
|
+
prepareDirectory(required: {
|
|
82
|
+
keyFilePath: string;
|
|
83
|
+
}): void;
|
|
84
|
+
siteKeyFilePathFrom: Parameters<typeof inspectSiteKeyMaterial>[0]['siteKeyFilePathFrom'];
|
|
85
|
+
}, _optional?: {}): {
|
|
86
|
+
InMemoryKeyring: new (required?: Record<string, never>, optional?: {
|
|
87
|
+
keyId?: string;
|
|
88
|
+
}) => KeyringPort & {
|
|
89
|
+
activeKey(): ReturnType<KeyringPort["activeKey"]>;
|
|
90
|
+
};
|
|
91
|
+
FixedSiteKeyKeyring: new (required: {
|
|
92
|
+
hex: string;
|
|
93
|
+
}, optional?: {
|
|
94
|
+
keyId?: string;
|
|
95
|
+
}) => KeyringPort & {
|
|
96
|
+
activeKey(): ReturnType<KeyringPort["activeKey"]>;
|
|
97
|
+
};
|
|
98
|
+
EnvOrFileKeyring: new (options: {
|
|
99
|
+
keyId?: string;
|
|
100
|
+
sources: readonly SiteKeySource[];
|
|
101
|
+
}, deps?: {
|
|
102
|
+
env?: () => Record<string, string | undefined>;
|
|
103
|
+
}) => KeyringPort & {
|
|
104
|
+
activeKey(): ReturnType<KeyringPort["activeKey"]>;
|
|
105
|
+
};
|
|
106
|
+
UnusableSiteKeyError: {
|
|
107
|
+
new (input: {
|
|
108
|
+
source: "env" | "file";
|
|
109
|
+
reason: import("../keyring.env.js").RootKeyRejection;
|
|
110
|
+
message: string;
|
|
111
|
+
}): {
|
|
112
|
+
readonly source: "env" | "file";
|
|
113
|
+
readonly reason: import("../keyring.env.js").RootKeyRejection;
|
|
114
|
+
name: string;
|
|
115
|
+
message: string;
|
|
116
|
+
stack?: string;
|
|
117
|
+
cause?: unknown;
|
|
118
|
+
};
|
|
119
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
120
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
121
|
+
stackTraceLimit: number;
|
|
122
|
+
};
|
|
123
|
+
SiteKeyFileAlreadyExistsError: {
|
|
124
|
+
new (input: {
|
|
125
|
+
keyFilePath: string;
|
|
126
|
+
}): {
|
|
127
|
+
name: string;
|
|
128
|
+
message: string;
|
|
129
|
+
stack?: string;
|
|
130
|
+
cause?: unknown;
|
|
131
|
+
};
|
|
132
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
133
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
134
|
+
stackTraceLimit: number;
|
|
135
|
+
};
|
|
136
|
+
isNoSiteKeyError: typeof isNoSiteKeyError;
|
|
137
|
+
parseSiteKeyHex: typeof parseRootKeyHex;
|
|
138
|
+
fingerprintSiteKeyHex: typeof fingerprintRootKeyHex;
|
|
139
|
+
inspectSiteKeyMaterial: (options: {
|
|
140
|
+
sources: readonly SiteKeySource[];
|
|
141
|
+
}, deps?: {
|
|
142
|
+
env?: () => Record<string, string | undefined>;
|
|
143
|
+
}) => ReturnType<typeof inspectSiteKeyMaterial> & {
|
|
144
|
+
readonly envVarName?: string;
|
|
145
|
+
};
|
|
146
|
+
revealSiteKeyMaterial: (options: {
|
|
147
|
+
sources: readonly SiteKeySource[];
|
|
148
|
+
}, deps?: {
|
|
149
|
+
env?: () => Record<string, string | undefined>;
|
|
150
|
+
}) => ReturnType<typeof revealSiteKeyMaterial> & {
|
|
151
|
+
readonly envVarName?: string;
|
|
152
|
+
};
|
|
153
|
+
generateFileSiteKey: (options: {
|
|
154
|
+
keyFilePath: string;
|
|
155
|
+
}, _optional?: {}) => import("../keyring.env.js").GeneratedFileRootKey;
|
|
156
|
+
};
|
|
157
|
+
//# sourceMappingURL=ordered-keyring.d.ts.map
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { createSiteKeyringErrors } from './site-keyring-errors.js';
|
|
2
|
+
import { dirname } from "node:path";
|
|
3
|
+
import { FixedRootKeyKeyring, fingerprintRootKeyHex } from "../keyring.env.js";
|
|
4
|
+
import { firstPresentSiteKey, inspectSiteKeyMaterial, revealSiteKeyMaterial } from "./material.js";
|
|
5
|
+
export function createOrderedSiteKeyring(required, optional = {}) {
|
|
6
|
+
return {
|
|
7
|
+
activeKey: async (_required = {}, _optional = {}) => ({ keyId: required.keyId }),
|
|
8
|
+
deriveSigningSecret: async (input) => { return await resolveKeyring(required, optional.FixedSiteKeyKeyring ?? FixedRootKeyKeyring).deriveSigningSecret(input); },
|
|
9
|
+
derive: async (input) => { return await resolveKeyring(required, optional.FixedSiteKeyKeyring ?? FixedRootKeyKeyring).derive(input); },
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
/** Ordered site sources are host policy. Reread them for each derive so recovery takes effect
|
|
13
|
+
* immediately; a present invalid source throws before trying any other source.
|
|
14
|
+
* @complexity O(sources), with one small env/file read per attempted source.
|
|
15
|
+
*/
|
|
16
|
+
function resolveKeyring(required, FixedSiteKeyKeyring) {
|
|
17
|
+
// Present-but-invalid wins and throws: falling through could seal data under a different
|
|
18
|
+
// key than the operator configured. Ordered sources are readers only; ensureSiteKey owns minting.
|
|
19
|
+
const present = firstPresentSiteKey({ sources: required.sources, env: required.env(), readSiteKeySourceMaterial: required.readSourceMaterial });
|
|
20
|
+
if (present === undefined) {
|
|
21
|
+
throw new Error(`no site key: none of the configured sources resolved (${required.sources.map(required.describeSource).join(", ")})`);
|
|
22
|
+
}
|
|
23
|
+
if (present.parsed.ok)
|
|
24
|
+
return new FixedSiteKeyKeyring({ hex: present.parsed.hex, hkdfSalt: required.hkdfSalt }, { keyId: required.keyId });
|
|
25
|
+
throw required.unusableSiteKeyError({ source: present.source, rejection: present.parsed });
|
|
26
|
+
}
|
|
27
|
+
export function isNoSiteKeyError({ error }, _optional = {}) {
|
|
28
|
+
return error instanceof Error && (error.message === "no site key" || error.message.startsWith("no site key: none of the configured sources resolved ("));
|
|
29
|
+
}
|
|
30
|
+
export function createExclusiveSiteKeyGenerator(required, _optional = {}) {
|
|
31
|
+
return function generateFileSiteKey({ keyFilePath }, _optional = {}) {
|
|
32
|
+
required.fs.mkdirSync(dirname(keyFilePath), { recursive: true, mode: required.directoryMode });
|
|
33
|
+
const generated = required.randomBytes(32);
|
|
34
|
+
const hex = generated.toString("hex");
|
|
35
|
+
required.fs.mkdirSync(dirname(keyFilePath), { recursive: true, mode: required.directoryMode });
|
|
36
|
+
try {
|
|
37
|
+
required.fs.writeFileSync(keyFilePath, hex, { mode: required.fileMode, flag: "wx" });
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
if (isAlreadyExistsError({ err: error }))
|
|
41
|
+
throw required.alreadyExistsError({ keyFilePath });
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
44
|
+
return { hex, fingerprint: fingerprintRootKeyHex({ hex }), keyFilePath };
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/** Whether a failed exclusive create failed BECAUSE the path was taken (`EEXIST`), as opposed to a
|
|
48
|
+
* genuine I/O or permission fault that must keep propagating. `ELOOP` is the same answer wearing a
|
|
49
|
+
* different errno: a symlink chain the kernel refused to follow is still "something is there". */
|
|
50
|
+
function isAlreadyExistsError({ err }, _optional = {}) {
|
|
51
|
+
if (typeof err !== "object" || err === null || !("code" in err))
|
|
52
|
+
return false;
|
|
53
|
+
const code = err.code;
|
|
54
|
+
return code === "EEXIST" || code === "ELOOP";
|
|
55
|
+
}
|
|
56
|
+
export function bindSiteKeyrings(required, _optional = {}) {
|
|
57
|
+
const errors = createSiteKeyringErrors(required);
|
|
58
|
+
const InMemoryKeyring = class InMemoryKeyring extends required.InMemoryKeyring {
|
|
59
|
+
constructor(_required = {}, optional = {}) { super({ hkdfSalt: required.hkdfSalt }, optional); }
|
|
60
|
+
};
|
|
61
|
+
const FixedSiteKeyKeyring = class FixedSiteKeyKeyring {
|
|
62
|
+
keyring;
|
|
63
|
+
constructor({ hex }, { keyId = required.defaultKeyId } = {}) { this.keyring = new required.FixedSiteKeyKeyring({ hex, hkdfSalt: required.hkdfSalt }, { keyId }); }
|
|
64
|
+
activeKey() { return this.keyring.activeKey({}); }
|
|
65
|
+
deriveSigningSecret(input) { return this.keyring.deriveSigningSecret(input); }
|
|
66
|
+
derive(input) { return this.keyring.derive(input); }
|
|
67
|
+
};
|
|
68
|
+
const EnvOrFileKeyring = class EnvOrFileKeyring {
|
|
69
|
+
keyring;
|
|
70
|
+
constructor(options, deps = {}) {
|
|
71
|
+
this.keyring = createOrderedSiteKeyring({ ...required, sources: options.sources, keyId: options.keyId ?? required.defaultKeyId, env: deps.env ?? required.env, unusableSiteKeyError: errors.unusableSiteKeyError }, { FixedSiteKeyKeyring: required.FixedSiteKeyKeyring });
|
|
72
|
+
}
|
|
73
|
+
activeKey() { return this.keyring.activeKey(); }
|
|
74
|
+
async deriveSigningSecret(input) { try {
|
|
75
|
+
return await this.keyring.deriveSigningSecret(input);
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
return errors.rethrowKeyringError({ error });
|
|
79
|
+
} }
|
|
80
|
+
async derive(input) { try {
|
|
81
|
+
return await this.keyring.derive(input);
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
return errors.rethrowKeyringError({ error });
|
|
85
|
+
} }
|
|
86
|
+
};
|
|
87
|
+
return { InMemoryKeyring, FixedSiteKeyKeyring, EnvOrFileKeyring, UnusableSiteKeyError: errors.UnusableSiteKeyError, SiteKeyFileAlreadyExistsError: errors.SiteKeyFileAlreadyExistsError, isNoSiteKeyError,
|
|
88
|
+
parseSiteKeyHex: required.parseSiteKeyHex, fingerprintSiteKeyHex: required.fingerprintSiteKeyHex,
|
|
89
|
+
inspectSiteKeyMaterial: (options, deps = {}) => inspectSiteKeyMaterial({ ...required, ...options, env: deps.env ?? required.env, readSiteKeySourceMaterial: required.readSourceMaterial }),
|
|
90
|
+
revealSiteKeyMaterial: (options, deps = {}) => revealSiteKeyMaterial({ ...required, ...options, env: deps.env ?? required.env, readSiteKeySourceMaterial: required.readSourceMaterial }),
|
|
91
|
+
generateFileSiteKey: (options, _optional = {}) => {
|
|
92
|
+
required.prepareDirectory(options);
|
|
93
|
+
try {
|
|
94
|
+
return required.generateFileSiteKey(options);
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
if (error instanceof required.SiteKeyFileAlreadyExistsError || isAlreadyExistsError({ err: error }))
|
|
98
|
+
throw new errors.SiteKeyFileAlreadyExistsError(options);
|
|
99
|
+
throw error;
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=ordered-keyring.js.map
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { type RootKeyRejection } from "../keyring.env.js";
|
|
2
|
+
type Empty = Record<string, never>;
|
|
3
|
+
/** Reads one key source's raw material, or undefined when absent. Called lazily, in source order. */
|
|
4
|
+
export type RootKeyMaterialRead = (required: Empty, _optional?: Empty) => string | undefined;
|
|
5
|
+
/** The meta-file stamp as read at reconciliation time. `write` merges into the SAME parsed object. */
|
|
6
|
+
export type RootKeyStampRead = {
|
|
7
|
+
readonly kind: "no-meta";
|
|
8
|
+
} | {
|
|
9
|
+
readonly kind: "meta";
|
|
10
|
+
readonly fingerprint: string | undefined;
|
|
11
|
+
readonly write: (required: {
|
|
12
|
+
fingerprint: string;
|
|
13
|
+
}, _optional?: Empty) => void;
|
|
14
|
+
};
|
|
15
|
+
export interface RootKeyReconcilePorts {
|
|
16
|
+
/** Raw per-site file material (undefined = absent). Read exactly once, first. */
|
|
17
|
+
readonly readPerSite: RootKeyMaterialRead;
|
|
18
|
+
/** Every OTHER source, in the host's precedence order. */
|
|
19
|
+
readonly others: readonly RootKeyMaterialRead[];
|
|
20
|
+
/** The stamped fingerprint as resolved BEFORE any write (host: resolveSiteKeyFingerprint). */
|
|
21
|
+
readonly stampedFingerprint: string | undefined;
|
|
22
|
+
/** Key-dependent-data scan. The reconciler memoizes it: at most one call per reconcile. */
|
|
23
|
+
readonly hasDependentData: (required: Empty, _optional?: Empty) => Promise<boolean>;
|
|
24
|
+
/** Move the per-site file aside only if it still holds `expectedContent`. Never deletes. */
|
|
25
|
+
readonly moveAside: (required: {
|
|
26
|
+
expectedContent: string;
|
|
27
|
+
}, _optional?: Empty) => void;
|
|
28
|
+
/** Exclusive create of the per-site file; returns the trimmed bytes actually on disk (race winner). */
|
|
29
|
+
readonly createExclusive: (required: {
|
|
30
|
+
hex: string;
|
|
31
|
+
}, _optional?: Empty) => string;
|
|
32
|
+
/** Fresh random key hex. */
|
|
33
|
+
readonly mint: (required: Empty, _optional?: Empty) => string;
|
|
34
|
+
/** Read the stamp again AFTER the key file has settled (host: readSiteMetaJson). */
|
|
35
|
+
readonly readStamp: (required: Empty, _optional?: Empty) => RootKeyStampRead;
|
|
36
|
+
}
|
|
37
|
+
export type RootKeyReconcileResult = {
|
|
38
|
+
readonly action: "noop" | "adopt" | "mint" | "mismatch";
|
|
39
|
+
readonly fingerprint: string;
|
|
40
|
+
} | {
|
|
41
|
+
readonly action: "invalid";
|
|
42
|
+
readonly reason: RootKeyRejection;
|
|
43
|
+
} | {
|
|
44
|
+
readonly action: "refuse";
|
|
45
|
+
};
|
|
46
|
+
export declare function reconcileRootKey({ ports }: {
|
|
47
|
+
ports: RootKeyReconcilePorts;
|
|
48
|
+
}, _optional?: Empty): Promise<RootKeyReconcileResult>;
|
|
49
|
+
export {};
|
|
50
|
+
//# sourceMappingURL=reconcile.d.ts.map
|