@jini-ai/platform 0.7.3-next.2 → 0.7.4
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 +7 -0
- package/README.md +13 -0
- package/dist/download-lock.d.ts +3 -1
- package/dist/download-lock.js +4 -6
- 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 +62 -13
- 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/email-template.js +3 -7
- 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/purpose-scoped-mailer.d.ts +4 -0
- package/dist/mail/purpose-scoped-mailer.js +4 -3
- 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 +198 -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-top-footprint.js +1 -3
- 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 +12 -0
- package/dist/retention/preview-store.js +28 -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 +138 -6
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Read-only storage measurement for one folder tree. The host passes already-resolved absolute
|
|
3
|
+
* paths it wants totals for ("targets"); one walk attributes every file to the closest target that
|
|
4
|
+
* contains it, and everything else to `other`, so the parts always add up to the walked total.
|
|
5
|
+
*
|
|
6
|
+
* Rules:
|
|
7
|
+
* - Symlinks are never followed (a link into another site or the whole disk would inflate the total
|
|
8
|
+
* and could loop). Each skipped link is listed. A folder is enumerated through an anchored,
|
|
9
|
+
* no-follow directory handle whose identity must match the inspected folder; when that identity
|
|
10
|
+
* cannot be maintained (the folder was swapped for a link or another folder mid-walk), the folder
|
|
11
|
+
* is reported unknown and nothing it listed is counted.
|
|
12
|
+
* - A path that cannot be read is reported as unknown: the affected tallies get `bytes: null` and the
|
|
13
|
+
* path in `unknownPaths`, while `knownBytes` keeps the lower bound. An unreadable folder is never 0.
|
|
14
|
+
* - A missing path is a known zero, and a file that vanishes mid-walk is simply not counted.
|
|
15
|
+
* - Sizes are apparent sizes (`lstat().size`), the number an owner compares against their file
|
|
16
|
+
* manager; hard links are counted once per name.
|
|
17
|
+
* Nothing here writes, opens a database or deletes.
|
|
18
|
+
*/
|
|
19
|
+
import { constants as fsConstants } from 'node:fs';
|
|
20
|
+
import fs from 'node:fs/promises';
|
|
21
|
+
import path from 'node:path';
|
|
22
|
+
// Windows has neither flag; there the identity checks below are what catch a swapped folder.
|
|
23
|
+
const OPEN_DIRECTORY_NO_FOLLOW = fsConstants.O_RDONLY | (fsConstants.O_DIRECTORY ?? 0) | (fsConstants.O_NOFOLLOW ?? 0);
|
|
24
|
+
/** The Node adapter: opens each folder without following a link and, on Linux, reads it through the
|
|
25
|
+
* process's own descriptor link (`/proc/self/fd/N`), which stays bound to the opened folder. Elsewhere it
|
|
26
|
+
* reads by pathname and `stillOpenedDirectory()` re-checks the pathname's identity afterwards.
|
|
27
|
+
* @example await measureStorageTree({ root, targets }, { fs: nodeStorageTreeFs }); */
|
|
28
|
+
export const nodeStorageTreeFs = {
|
|
29
|
+
lstat: target => fs.lstat(target),
|
|
30
|
+
openDirectory: target => openNodeDirectory({ target }),
|
|
31
|
+
};
|
|
32
|
+
async function openNodeDirectory({ target }, _optional = {}) {
|
|
33
|
+
const handle = await fs.open(target, OPEN_DIRECTORY_NO_FOLLOW);
|
|
34
|
+
try {
|
|
35
|
+
const identity = await handle.stat();
|
|
36
|
+
if (!identity.isDirectory())
|
|
37
|
+
throw Object.assign(new Error('The opened path is not a folder.'), { code: 'ENOTDIR' });
|
|
38
|
+
const base = await descriptorPath({ fd: handle.fd, identity }) ?? target;
|
|
39
|
+
return {
|
|
40
|
+
identity,
|
|
41
|
+
list: () => fs.readdir(base),
|
|
42
|
+
lstatChild: name => fs.lstat(path.join(base, name)),
|
|
43
|
+
stillOpenedDirectory: async () => sameIdentity(await fs.lstat(target).catch(() => undefined), identity),
|
|
44
|
+
close: () => handle.close(),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
await handle.close();
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/** `/proc/self/fd/N` when it resolves to the opened folder, otherwise `undefined` (no procfs). */
|
|
53
|
+
async function descriptorPath({ fd, identity }, _optional = {}) {
|
|
54
|
+
const anchored = `/proc/self/fd/${fd}`;
|
|
55
|
+
const resolved = await fs.stat(anchored).catch(() => undefined);
|
|
56
|
+
return sameIdentity(resolved, identity) ? anchored : undefined;
|
|
57
|
+
}
|
|
58
|
+
function sameIdentity(a, b, _optional = {}) {
|
|
59
|
+
return a !== undefined && a.dev === b.dev && a.ino === b.ino;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Measures `root` once, attributing bytes to `targets`.
|
|
63
|
+
* @throws TypeError for a relative root or target, a repeated id or two targets naming one path.
|
|
64
|
+
* @throws RangeError for a target outside `root`.
|
|
65
|
+
* @complexity O(n · t) time for n entries and t targets, O(depth + t) extra space; one `lstat` per
|
|
66
|
+
* entry and one `readdir` per folder, sequential to keep disk pressure low on a serving host.
|
|
67
|
+
* @example await measureStorageTree({ root: siteDir, targets: [{ id: 'uploads', path: uploadsDir }] });
|
|
68
|
+
*/
|
|
69
|
+
export async function measureStorageTree({ root, targets }, { fs: treeFs = nodeStorageTreeFs } = {}) {
|
|
70
|
+
const checked = validateTargets({ root, targets });
|
|
71
|
+
const tallies = new Map(checked.map(target => [target.id, emptyTally()]));
|
|
72
|
+
const other = emptyTally();
|
|
73
|
+
const total = emptyTally();
|
|
74
|
+
const ownerOf = (entry) => {
|
|
75
|
+
// Targets are sorted longest path first, so the first container is the closest one.
|
|
76
|
+
const owner = checked.find(target => contains({ parent: target.path, child: entry }));
|
|
77
|
+
return owner ? tallies.get(owner.id) : other;
|
|
78
|
+
};
|
|
79
|
+
const markUnknown = (entry) => {
|
|
80
|
+
total.unknownPaths.push(entry);
|
|
81
|
+
ownerOf(entry).unknownPaths.push(entry);
|
|
82
|
+
// Anything nested inside an unreadable folder is unknown as well, not empty.
|
|
83
|
+
for (const target of checked) {
|
|
84
|
+
if (target.path !== entry && contains({ parent: entry, child: target.path }))
|
|
85
|
+
tallies.get(target.id).unknownPaths.push(entry);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
await walk({ root, fs: treeFs, visit: { ownerOf, markUnknown, total } });
|
|
89
|
+
return {
|
|
90
|
+
root,
|
|
91
|
+
total: freeze(total),
|
|
92
|
+
targets: Object.fromEntries([...tallies].map(([id, tally]) => [id, freeze(tally)])),
|
|
93
|
+
other: freeze(other),
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
async function walk({ root, fs: treeFs, visit }, _optional = {}) {
|
|
97
|
+
const folders = [];
|
|
98
|
+
const record = (entry, stats) => {
|
|
99
|
+
if (stats === 'missing')
|
|
100
|
+
return;
|
|
101
|
+
if (stats === 'unknown')
|
|
102
|
+
return visit.markUnknown(entry);
|
|
103
|
+
if (stats.isSymbolicLink()) {
|
|
104
|
+
visit.total.skippedSymlinks.push(entry);
|
|
105
|
+
visit.ownerOf(entry).skippedSymlinks.push(entry);
|
|
106
|
+
}
|
|
107
|
+
else if (stats.isDirectory()) {
|
|
108
|
+
folders.push({ entry, identity: stats });
|
|
109
|
+
}
|
|
110
|
+
else if (stats.isFile()) {
|
|
111
|
+
for (const tally of [visit.total, visit.ownerOf(entry)]) {
|
|
112
|
+
tally.knownBytes += stats.size;
|
|
113
|
+
tally.files += 1;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
record(root, await readStats({ read: () => treeFs.lstat(root) }));
|
|
118
|
+
for (let folder = folders.pop(); folder !== undefined; folder = folders.pop()) {
|
|
119
|
+
const children = await readFolder({ fs: treeFs, folder });
|
|
120
|
+
if (children === 'unknown') {
|
|
121
|
+
visit.markUnknown(folder.entry);
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
for (const [entry, stats] of children)
|
|
125
|
+
record(entry, stats);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/** Lists one folder through its anchored handle. Children are only returned once the handle is proven
|
|
129
|
+
* to be the inspected folder both before and after the reads; otherwise the whole folder is unknown. */
|
|
130
|
+
async function readFolder({ fs: treeFs, folder }, _optional = {}) {
|
|
131
|
+
let directory;
|
|
132
|
+
try {
|
|
133
|
+
directory = await treeFs.openDirectory(folder.entry);
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
return isMissing(error) ? [] : 'unknown';
|
|
137
|
+
}
|
|
138
|
+
try {
|
|
139
|
+
if (!sameIdentity(directory.identity, folder.identity))
|
|
140
|
+
return 'unknown';
|
|
141
|
+
const children = [];
|
|
142
|
+
for (const name of await directory.list()) {
|
|
143
|
+
children.push([path.join(folder.entry, name), await readStats({ read: () => directory.lstatChild(name) })]);
|
|
144
|
+
}
|
|
145
|
+
return (await directory.stillOpenedDirectory()) ? children : 'unknown';
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
return isMissing(error) ? [] : 'unknown';
|
|
149
|
+
}
|
|
150
|
+
finally {
|
|
151
|
+
await directory.close().catch(() => undefined);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
async function readStats({ read }, _optional = {}) {
|
|
155
|
+
try {
|
|
156
|
+
return await read();
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
return isMissing(error) ? 'missing' : 'unknown';
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
function validateTargets({ root, targets }, _optional = {}) {
|
|
163
|
+
if (!path.isAbsolute(root))
|
|
164
|
+
throw new TypeError(`The folder to measure must be an absolute path: ${root}`);
|
|
165
|
+
const byPath = new Map();
|
|
166
|
+
const ids = new Set();
|
|
167
|
+
const checked = targets.map(({ id, path: target }) => {
|
|
168
|
+
if (!path.isAbsolute(target))
|
|
169
|
+
throw new TypeError(`Storage target "${id}" must be an absolute path: ${target}`);
|
|
170
|
+
if (ids.has(id))
|
|
171
|
+
throw new TypeError(`Storage target "${id}" is listed twice.`);
|
|
172
|
+
const resolved = path.resolve(target);
|
|
173
|
+
const clash = byPath.get(resolved);
|
|
174
|
+
if (clash !== undefined)
|
|
175
|
+
throw new TypeError(`Storage targets "${clash}" and "${id}" name the same path: ${resolved}`);
|
|
176
|
+
if (!contains({ parent: path.resolve(root), child: resolved })) {
|
|
177
|
+
throw new RangeError(`Storage target "${id}" is outside the folder being measured: ${resolved}`);
|
|
178
|
+
}
|
|
179
|
+
ids.add(id);
|
|
180
|
+
byPath.set(resolved, id);
|
|
181
|
+
return { id, path: resolved };
|
|
182
|
+
});
|
|
183
|
+
return checked.sort((a, b) => b.path.length - a.path.length);
|
|
184
|
+
}
|
|
185
|
+
/** Segment-aware containment: `content.db-wal` is not inside `content.db`. */
|
|
186
|
+
function contains({ parent, child }, _optional = {}) {
|
|
187
|
+
const relative = path.relative(parent, child);
|
|
188
|
+
return relative === '' || (relative !== '..' && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative));
|
|
189
|
+
}
|
|
190
|
+
function isMissing(error, _optional = {}) {
|
|
191
|
+
return typeof error === 'object' && error !== null && error.code === 'ENOENT';
|
|
192
|
+
}
|
|
193
|
+
function emptyTally(_optional = {}) {
|
|
194
|
+
return { knownBytes: 0, files: 0, unknownPaths: [], skippedSymlinks: [] };
|
|
195
|
+
}
|
|
196
|
+
function freeze(tally, _optional = {}) {
|
|
197
|
+
return {
|
|
198
|
+
bytes: tally.unknownPaths.length > 0 ? null : tally.knownBytes,
|
|
199
|
+
knownBytes: tally.knownBytes,
|
|
200
|
+
files: tally.files,
|
|
201
|
+
unknownPaths: [...tally.unknownPaths],
|
|
202
|
+
skippedSymlinks: [...tally.skippedSymlinks],
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
//# sourceMappingURL=measure-tree.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { CleanupPreviewStore } from '@jini-ai/core/contracts/storage';
|
|
2
|
+
export declare function createCleanupPreviewStore({ randomToken, mono }: {
|
|
3
|
+
randomToken: (required: {
|
|
4
|
+
bytes: number;
|
|
5
|
+
}) => string;
|
|
6
|
+
mono: () => number;
|
|
7
|
+
}, { ttlMs }?: {
|
|
8
|
+
ttlMs?: number | undefined;
|
|
9
|
+
}): CleanupPreviewStore & {
|
|
10
|
+
size(required: Record<string, never>, optional?: Record<string, never>): number;
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=preview-store.d.ts.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export function createCleanupPreviewStore({ randomToken, mono }, { ttlMs = 900000 } = {}) {
|
|
2
|
+
const outstanding = new Map();
|
|
3
|
+
return {
|
|
4
|
+
/** Retained previews, including expired entries until the next put/take removes them. */
|
|
5
|
+
size(_required, _optional = {}) { return outstanding.size; },
|
|
6
|
+
put({ principal, kind, scope, payload }, _optional = {}) {
|
|
7
|
+
const at = mono();
|
|
8
|
+
for (const [key, entry] of outstanding)
|
|
9
|
+
if (entry.deadline <= at)
|
|
10
|
+
outstanding.delete(key);
|
|
11
|
+
const token = randomToken({ bytes: 16 });
|
|
12
|
+
const deadline = Math.min(at + ttlMs, payload.deadline ?? Infinity);
|
|
13
|
+
outstanding.set(JSON.stringify([principal, kind]), { token, scope, payload, deadline });
|
|
14
|
+
return { token, deadline };
|
|
15
|
+
},
|
|
16
|
+
take({ token, principal, kind, scope }, _optional = {}) {
|
|
17
|
+
const key = JSON.stringify([principal, kind]);
|
|
18
|
+
const entry = outstanding.get(key);
|
|
19
|
+
if (!entry || entry.token !== token || entry.scope !== scope)
|
|
20
|
+
return null;
|
|
21
|
+
outstanding.delete(key);
|
|
22
|
+
if (mono() >= entry.deadline)
|
|
23
|
+
return null;
|
|
24
|
+
return { payload: entry.payload, deadline: entry.deadline };
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=preview-store.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export declare function createStorageRoutes({ paths }: {
|
|
2
|
+
paths: {
|
|
3
|
+
report: string;
|
|
4
|
+
cleanup: string;
|
|
5
|
+
};
|
|
6
|
+
}, _optional?: {}): {
|
|
7
|
+
report: import("@jini-ai/core/contracts/server").JsonRouteSpec<Record<string, never>, object, {
|
|
8
|
+
measure: (required: Record<string, never>, optional: Record<string, never>) => Promise<object>;
|
|
9
|
+
}, undefined>;
|
|
10
|
+
cleanup: import("@jini-ai/core/contracts/server").JsonRouteSpec<{
|
|
11
|
+
dryRun?: boolean;
|
|
12
|
+
classes?: string[];
|
|
13
|
+
}, object, {
|
|
14
|
+
runOnce: (required: {
|
|
15
|
+
dryRun: boolean;
|
|
16
|
+
classes?: string[];
|
|
17
|
+
}, optional: Record<string, never>) => Promise<object>;
|
|
18
|
+
copy: {
|
|
19
|
+
invalidClass: string;
|
|
20
|
+
};
|
|
21
|
+
}, undefined>;
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=routes.d.ts.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { defineJsonRoute, err, ok } from '@jini-ai/core/contracts/server';
|
|
2
|
+
export function createStorageRoutes({ paths }, _optional = {}) {
|
|
3
|
+
return {
|
|
4
|
+
report: defineJsonRoute({
|
|
5
|
+
method: 'get', path: paths.report, parse: () => ok({ value: {} }),
|
|
6
|
+
handle: async ({ deps, authorize }) => {
|
|
7
|
+
await authorize({ permission: 'storage.manage' });
|
|
8
|
+
return ok({ value: await deps.measure({}, {}) });
|
|
9
|
+
},
|
|
10
|
+
}),
|
|
11
|
+
cleanup: defineJsonRoute({
|
|
12
|
+
method: 'post', path: paths.cleanup,
|
|
13
|
+
parse: raw => ok({ value: (raw.body ?? {}) }),
|
|
14
|
+
handle: async ({ input, deps, authorize }) => {
|
|
15
|
+
await authorize({ permission: 'storage.manage' });
|
|
16
|
+
if (input.classes?.some(kind => !['cache', 'derived', 'old-copy'].includes(kind)))
|
|
17
|
+
return err({ error: { code: 'INVALID_INPUT', message: deps.copy.invalidClass } });
|
|
18
|
+
// Measurement describes what exists; a sweep separately reports what it actually freed.
|
|
19
|
+
return ok({ value: await deps.runOnce({ dryRun: input.dryRun !== false, ...(input.classes === undefined ? {} : { classes: input.classes }) }, {}) });
|
|
20
|
+
},
|
|
21
|
+
}, { requireSameOrigin: true }),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=routes.js.map
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file A host-neutral storage retention runner: it schedules passes over host-supplied policies and
|
|
3
|
+
* never touches the filesystem itself. Every collaborator (clock, scheduler, error sink, policies) is
|
|
4
|
+
* injected; the host decides which policies exist, where their files live and whether scheduled
|
|
5
|
+
* passes may clean or only measure.
|
|
6
|
+
*
|
|
7
|
+
* Pass rules:
|
|
8
|
+
* - Passes are serialized. A request that matches the running pass's mode joins it; a request of the
|
|
9
|
+
* other mode waits for it and then runs its own pass (at most one waiting pass, joined the same way).
|
|
10
|
+
* So a dry run always gets a measurement-only result, even when it arrives during a cleanup, and a
|
|
11
|
+
* confirmed cleanup always gets the result of an actual sweep, even when it arrives during a dry run.
|
|
12
|
+
* - A dry run calls `measure()` only and never enters `sweep()`.
|
|
13
|
+
* - A failing policy is reported in plain words and the next policy still runs.
|
|
14
|
+
* - `stop()` clears the timer, cancels a waiting pass and resolves once the running pass has finished,
|
|
15
|
+
* so the host can close storage right after it.
|
|
16
|
+
*/
|
|
17
|
+
/** Daily, matching the plan's default pass cadence; hosts can pass their own `intervalMs`. */
|
|
18
|
+
export declare const RETENTION_DEFAULT_INTERVAL_MS: number;
|
|
19
|
+
/** The only data a runner may clean automatically. There is deliberately no `"content"` (owner data
|
|
20
|
+
* is removed only by an explicit owner action) and no `"history"` (chats are content). */
|
|
21
|
+
export type RetentionPolicyKind = 'cache' | 'derived' | 'old-copy';
|
|
22
|
+
/** `bytes: null` means the policy could not tell (for example an unreadable folder), never zero. */
|
|
23
|
+
export interface RetentionMeasurement {
|
|
24
|
+
readonly bytes: number | null;
|
|
25
|
+
readonly items?: number;
|
|
26
|
+
}
|
|
27
|
+
export interface RetentionSweepResult {
|
|
28
|
+
readonly freedBytes: number | null;
|
|
29
|
+
readonly removed: number;
|
|
30
|
+
}
|
|
31
|
+
export interface RetentionPolicy {
|
|
32
|
+
readonly id: string;
|
|
33
|
+
readonly kind: RetentionPolicyKind;
|
|
34
|
+
measure(): Promise<RetentionMeasurement>;
|
|
35
|
+
sweep(input: {
|
|
36
|
+
readonly now: number;
|
|
37
|
+
}): Promise<RetentionSweepResult>;
|
|
38
|
+
}
|
|
39
|
+
export type RetentionPolicyOutcome = {
|
|
40
|
+
readonly id: string;
|
|
41
|
+
readonly kind: RetentionPolicyKind;
|
|
42
|
+
readonly status: 'measured';
|
|
43
|
+
readonly measurement: RetentionMeasurement;
|
|
44
|
+
} | {
|
|
45
|
+
readonly id: string;
|
|
46
|
+
readonly kind: RetentionPolicyKind;
|
|
47
|
+
readonly status: 'swept';
|
|
48
|
+
readonly result: RetentionSweepResult;
|
|
49
|
+
} | {
|
|
50
|
+
readonly id: string;
|
|
51
|
+
readonly kind: RetentionPolicyKind;
|
|
52
|
+
readonly status: 'failed';
|
|
53
|
+
readonly message: string;
|
|
54
|
+
};
|
|
55
|
+
export type RetentionPassResult = {
|
|
56
|
+
readonly status: 'completed';
|
|
57
|
+
readonly dryRun: boolean;
|
|
58
|
+
readonly startedAt: number;
|
|
59
|
+
readonly finishedAt: number;
|
|
60
|
+
readonly policies: readonly RetentionPolicyOutcome[];
|
|
61
|
+
} | {
|
|
62
|
+
readonly status: 'stopped';
|
|
63
|
+
readonly dryRun: boolean;
|
|
64
|
+
};
|
|
65
|
+
export interface RetentionScheduler {
|
|
66
|
+
setInterval(callback: () => void, ms: number): unknown;
|
|
67
|
+
clearInterval(handle: unknown): void;
|
|
68
|
+
}
|
|
69
|
+
export interface RetentionRunnerRequired {
|
|
70
|
+
readonly policies: readonly RetentionPolicy[];
|
|
71
|
+
readonly clock: {
|
|
72
|
+
now(): number;
|
|
73
|
+
};
|
|
74
|
+
readonly scheduler: RetentionScheduler;
|
|
75
|
+
/** Receives plain-words errors; `policyId` is absent for pass-level failures (a scheduled pass that
|
|
76
|
+
* could not run, or a report that could not be delivered). */
|
|
77
|
+
readonly reportError: (error: Error, context: {
|
|
78
|
+
readonly policyId?: string;
|
|
79
|
+
}) => void;
|
|
80
|
+
}
|
|
81
|
+
export interface RetentionRunnerOptional {
|
|
82
|
+
readonly intervalMs?: number;
|
|
83
|
+
/** Scheduled (boot and timer) passes only measure unless the host explicitly opts in to cleaning. */
|
|
84
|
+
readonly scheduledDryRun?: boolean;
|
|
85
|
+
readonly onReport?: (report: RetentionPassResult) => void;
|
|
86
|
+
}
|
|
87
|
+
export interface RetentionRunner {
|
|
88
|
+
runOnce(input: {
|
|
89
|
+
readonly dryRun: boolean;
|
|
90
|
+
}): Promise<RetentionPassResult>;
|
|
91
|
+
start(): void;
|
|
92
|
+
stop(): Promise<void>;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Creates a runner over the given policies. Nothing runs until `start()` or `runOnce()`.
|
|
96
|
+
* @throws TypeError for a duplicate policy id or a kind outside cache/derived/old-copy (a JS caller
|
|
97
|
+
* can bypass the type, so the kind rule is enforced at runtime as well).
|
|
98
|
+
* @throws RangeError for an interval that is not a positive finite number.
|
|
99
|
+
* @complexity O(p) per pass in policies, run one at a time.
|
|
100
|
+
* @example createRetentionRunner({ policies, clock: Date, scheduler: globalThis, reportError }, { onReport });
|
|
101
|
+
*/
|
|
102
|
+
export declare function createRetentionRunner(required: RetentionRunnerRequired, { intervalMs, scheduledDryRun, onReport }?: RetentionRunnerOptional): RetentionRunner;
|
|
103
|
+
//# sourceMappingURL=runner.d.ts.map
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file A host-neutral storage retention runner: it schedules passes over host-supplied policies and
|
|
3
|
+
* never touches the filesystem itself. Every collaborator (clock, scheduler, error sink, policies) is
|
|
4
|
+
* injected; the host decides which policies exist, where their files live and whether scheduled
|
|
5
|
+
* passes may clean or only measure.
|
|
6
|
+
*
|
|
7
|
+
* Pass rules:
|
|
8
|
+
* - Passes are serialized. A request that matches the running pass's mode joins it; a request of the
|
|
9
|
+
* other mode waits for it and then runs its own pass (at most one waiting pass, joined the same way).
|
|
10
|
+
* So a dry run always gets a measurement-only result, even when it arrives during a cleanup, and a
|
|
11
|
+
* confirmed cleanup always gets the result of an actual sweep, even when it arrives during a dry run.
|
|
12
|
+
* - A dry run calls `measure()` only and never enters `sweep()`.
|
|
13
|
+
* - A failing policy is reported in plain words and the next policy still runs.
|
|
14
|
+
* - `stop()` clears the timer, cancels a waiting pass and resolves once the running pass has finished,
|
|
15
|
+
* so the host can close storage right after it.
|
|
16
|
+
*/
|
|
17
|
+
/** Daily, matching the plan's default pass cadence; hosts can pass their own `intervalMs`. */
|
|
18
|
+
export const RETENTION_DEFAULT_INTERVAL_MS = 24 * 60 * 60 * 1000;
|
|
19
|
+
const RETENTION_POLICY_KINDS = new Set(['cache', 'derived', 'old-copy']);
|
|
20
|
+
/**
|
|
21
|
+
* Creates a runner over the given policies. Nothing runs until `start()` or `runOnce()`.
|
|
22
|
+
* @throws TypeError for a duplicate policy id or a kind outside cache/derived/old-copy (a JS caller
|
|
23
|
+
* can bypass the type, so the kind rule is enforced at runtime as well).
|
|
24
|
+
* @throws RangeError for an interval that is not a positive finite number.
|
|
25
|
+
* @complexity O(p) per pass in policies, run one at a time.
|
|
26
|
+
* @example createRetentionRunner({ policies, clock: Date, scheduler: globalThis, reportError }, { onReport });
|
|
27
|
+
*/
|
|
28
|
+
export function createRetentionRunner(required, { intervalMs = RETENTION_DEFAULT_INTERVAL_MS, scheduledDryRun = true, onReport } = {}) {
|
|
29
|
+
const policies = validatePolicies({ policies: required.policies });
|
|
30
|
+
if (!Number.isFinite(intervalMs) || intervalMs <= 0) {
|
|
31
|
+
throw new RangeError(`The storage cleanup interval must be a positive number of milliseconds (got ${intervalMs}).`);
|
|
32
|
+
}
|
|
33
|
+
const queue = createPassQueue({ execute: dryRun => executePass({ ...required, policies, dryRun, onReport }) });
|
|
34
|
+
let timer;
|
|
35
|
+
const scheduledPass = () => {
|
|
36
|
+
queue.request({ dryRun: scheduledDryRun }).catch((error) => {
|
|
37
|
+
report({ reportError: required.reportError, error: new Error('A scheduled storage cleanup pass could not run.', { cause: error }) });
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
return {
|
|
41
|
+
runOnce: ({ dryRun }) => queue.request({ dryRun }),
|
|
42
|
+
start() {
|
|
43
|
+
if (queue.isStopped())
|
|
44
|
+
throw new Error('This storage cleanup runner was stopped; create a new one to start again.');
|
|
45
|
+
if (timer)
|
|
46
|
+
return;
|
|
47
|
+
timer = { handle: required.scheduler.setInterval(scheduledPass, intervalMs) };
|
|
48
|
+
scheduledPass();
|
|
49
|
+
},
|
|
50
|
+
async stop() {
|
|
51
|
+
if (timer)
|
|
52
|
+
required.scheduler.clearInterval(timer.handle);
|
|
53
|
+
await queue.stop();
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function validatePolicies({ policies }, _optional = {}) {
|
|
58
|
+
const seen = new Set();
|
|
59
|
+
for (const policy of policies) {
|
|
60
|
+
if (!RETENTION_POLICY_KINDS.has(policy.kind)) {
|
|
61
|
+
throw new TypeError(`Storage policy "${policy.id}" has kind "${String(policy.kind)}". Only cache, derived and old-copy data may be cleaned automatically.`);
|
|
62
|
+
}
|
|
63
|
+
if (seen.has(policy.id))
|
|
64
|
+
throw new TypeError(`Storage policy "${policy.id}" is listed twice.`);
|
|
65
|
+
seen.add(policy.id);
|
|
66
|
+
}
|
|
67
|
+
// A private copy: a host mutating its array later cannot change what a running pass iterates.
|
|
68
|
+
return [...policies];
|
|
69
|
+
}
|
|
70
|
+
function pendingPass({ dryRun }, _optional = {}) {
|
|
71
|
+
let resolve;
|
|
72
|
+
let reject;
|
|
73
|
+
const promise = new Promise((settle, fail) => { resolve = settle; reject = fail; });
|
|
74
|
+
return { dryRun, promise, resolve, reject };
|
|
75
|
+
}
|
|
76
|
+
/** The serialization core: one running pass, at most one waiting pass of the other mode.
|
|
77
|
+
* The running slot is published before `execute` is called, so a collaborator that synchronously
|
|
78
|
+
* requests another pass joins or queues behind this one instead of starting an overlapping pass. The
|
|
79
|
+
* queue advances whether the pass fulfils or rejects, so a failed pass never strands a waiter. */
|
|
80
|
+
function createPassQueue({ execute }, _optional = {}) {
|
|
81
|
+
let running;
|
|
82
|
+
let waiting;
|
|
83
|
+
let stopped = false;
|
|
84
|
+
const begin = (pass) => {
|
|
85
|
+
running = pass;
|
|
86
|
+
const advance = (settle) => {
|
|
87
|
+
running = undefined;
|
|
88
|
+
const next = waiting;
|
|
89
|
+
waiting = undefined;
|
|
90
|
+
if (next)
|
|
91
|
+
begin(next);
|
|
92
|
+
settle();
|
|
93
|
+
};
|
|
94
|
+
// The executor runs synchronously, so a synchronous throw becomes this pass's rejection.
|
|
95
|
+
new Promise(resolve => resolve(execute(pass.dryRun)))
|
|
96
|
+
.then(result => advance(() => pass.resolve(result)), (error) => advance(() => pass.reject(error)));
|
|
97
|
+
};
|
|
98
|
+
return {
|
|
99
|
+
isStopped: () => stopped,
|
|
100
|
+
request({ dryRun }) {
|
|
101
|
+
if (stopped)
|
|
102
|
+
return Promise.resolve({ status: 'stopped', dryRun });
|
|
103
|
+
if (!running) {
|
|
104
|
+
const pass = pendingPass({ dryRun });
|
|
105
|
+
begin(pass);
|
|
106
|
+
return pass.promise;
|
|
107
|
+
}
|
|
108
|
+
if (running.dryRun === dryRun)
|
|
109
|
+
return running.promise;
|
|
110
|
+
// The waiting pass is always the other mode from the running one, so a same-mode request joins it.
|
|
111
|
+
waiting ??= pendingPass({ dryRun });
|
|
112
|
+
return waiting.promise;
|
|
113
|
+
},
|
|
114
|
+
async stop() {
|
|
115
|
+
stopped = true;
|
|
116
|
+
const cancelled = waiting;
|
|
117
|
+
waiting = undefined;
|
|
118
|
+
cancelled?.resolve({ status: 'stopped', dryRun: cancelled.dryRun });
|
|
119
|
+
// The pass's own requester observes a failure; stop only waits for the pass to end.
|
|
120
|
+
if (running)
|
|
121
|
+
await running.promise.catch(() => undefined);
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
/** Runs one pass to completion. It never rejects: every failure becomes an outcome plus a report. */
|
|
126
|
+
async function executePass({ policies, clock, reportError, dryRun, onReport }, _optional = {}) {
|
|
127
|
+
const startedAt = clock.now();
|
|
128
|
+
const outcomes = [];
|
|
129
|
+
for (const policy of policies)
|
|
130
|
+
outcomes.push(await runPolicy({ policy, dryRun, now: startedAt, reportError }));
|
|
131
|
+
const result = { status: 'completed', dryRun, startedAt, finishedAt: clock.now(), policies: outcomes };
|
|
132
|
+
try {
|
|
133
|
+
onReport?.(result);
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
report({ reportError, error: new Error('Storage cleanup report could not be delivered.', { cause: error }) });
|
|
137
|
+
}
|
|
138
|
+
return result;
|
|
139
|
+
}
|
|
140
|
+
async function runPolicy({ policy, dryRun, now, reportError }, _optional = {}) {
|
|
141
|
+
const { id, kind } = policy;
|
|
142
|
+
try {
|
|
143
|
+
if (dryRun)
|
|
144
|
+
return { id, kind, status: 'measured', measurement: await policy.measure() };
|
|
145
|
+
return { id, kind, status: 'swept', result: await policy.sweep({ now }) };
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
// Fixed outcome text: a raw message can quote a path or a secret, so nothing from the error reaches
|
|
149
|
+
// the outcome; the host's error sink still receives the full error as `cause`.
|
|
150
|
+
const message = `Storage cleanup "${id}" failed while ${dryRun ? 'measuring' : 'cleaning up'}.`;
|
|
151
|
+
report({ reportError, error: new Error(message, { cause: error }), policyId: id });
|
|
152
|
+
return { id, kind, status: 'failed', message };
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
function report({ reportError, error, policyId }, _optional = {}) {
|
|
156
|
+
try {
|
|
157
|
+
reportError(error, policyId === undefined ? {} : { policyId });
|
|
158
|
+
}
|
|
159
|
+
catch {
|
|
160
|
+
// A broken error sink must not turn into a failed pass or an unhandled rejection on a timer. The
|
|
161
|
+
// injected reporter is the only outlet this runner has, so its own failure is dropped here.
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
//# sourceMappingURL=runner.js.map
|
|
@@ -5,4 +5,5 @@ export { VaultResealRefusedError, type VaultResealRefusalStep } from "./vault.re
|
|
|
5
5
|
export { InMemoryVaultRepo } from "./vault.repo.memory.js";
|
|
6
6
|
export { captureVaultArchive, prepareVaultArchiveRestore, type VaultArchiveEntry } from "./vault-archive.js";
|
|
7
7
|
export { matchingCredentialProviderIds, selectCredentialForProvider, suggestCredentialWorksFor, normalizeCredentialWorksFor, type CredentialProviderDescriptor, type MatchableCredential } from "./provider-matches.js";
|
|
8
|
+
export { createStoreKeyring, protectStorage, type StorageFailureSource } from "./store-vault-guards.js";
|
|
8
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -5,4 +5,5 @@ export { VaultResealRefusedError } from "./vault.reseal-refused.js";
|
|
|
5
5
|
export { InMemoryVaultRepo } from "./vault.repo.memory.js";
|
|
6
6
|
export { captureVaultArchive, prepareVaultArchiveRestore } from "./vault-archive.js";
|
|
7
7
|
export { matchingCredentialProviderIds, selectCredentialForProvider, suggestCredentialWorksFor, normalizeCredentialWorksFor } from "./provider-matches.js";
|
|
8
|
+
export { createStoreKeyring, protectStorage } from "./store-vault-guards.js";
|
|
8
9
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { KeyringPort } from "@jini-ai/core/contracts/vault";
|
|
2
|
+
/** The parts of a store vault's `required` input that crypto guards read. Both are read at call time,
|
|
3
|
+
* never captured, so a guard always sees the store's current keyring and translator. */
|
|
4
|
+
export interface StorageFailureSource {
|
|
5
|
+
keyring?: KeyringPort;
|
|
6
|
+
storageError: (required: {}, options?: {
|
|
7
|
+
error?: unknown;
|
|
8
|
+
}) => Error;
|
|
9
|
+
}
|
|
10
|
+
/** Only crypto errors become the feature's safe storage error; the original error is its argument.
|
|
11
|
+
* @throws whatever `source.storageError` returns, for any sync or async failure of `operation`.
|
|
12
|
+
* @complexity O(1) around one awaited operation.
|
|
13
|
+
*/
|
|
14
|
+
export declare function protectStorage<T>({ operation, source }: {
|
|
15
|
+
operation: () => Promise<T>;
|
|
16
|
+
source: Pick<StorageFailureSource, "storageError">;
|
|
17
|
+
}, _optional?: {}): Promise<T>;
|
|
18
|
+
/** Keyring port for a store vault. A missing keyring raises the storage error inside the guard, which
|
|
19
|
+
* then translates it once more, passing the first storage error back to the translator. Jini's vault
|
|
20
|
+
* service calls only `activeKey`; `derive` and `deriveSigningSecret` complete the port contract.
|
|
21
|
+
* @complexity O(1) per call; delegates all key work to the injected keyring.
|
|
22
|
+
*/
|
|
23
|
+
export declare function createStoreKeyring({ source }: {
|
|
24
|
+
source: StorageFailureSource;
|
|
25
|
+
}, _optional?: {}): KeyringPort;
|
|
26
|
+
//# sourceMappingURL=store-vault-guards.d.ts.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** Only crypto errors become the feature's safe storage error; the original error is its argument.
|
|
2
|
+
* @throws whatever `source.storageError` returns, for any sync or async failure of `operation`.
|
|
3
|
+
* @complexity O(1) around one awaited operation.
|
|
4
|
+
*/
|
|
5
|
+
export async function protectStorage({ operation, source }, _optional = {}) {
|
|
6
|
+
try {
|
|
7
|
+
return await operation();
|
|
8
|
+
}
|
|
9
|
+
catch (error) {
|
|
10
|
+
throw source.storageError({}, { error });
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
/** Keyring port for a store vault. A missing keyring raises the storage error inside the guard, which
|
|
14
|
+
* then translates it once more, passing the first storage error back to the translator. Jini's vault
|
|
15
|
+
* service calls only `activeKey`; `derive` and `deriveSigningSecret` complete the port contract.
|
|
16
|
+
* @complexity O(1) per call; delegates all key work to the injected keyring.
|
|
17
|
+
*/
|
|
18
|
+
export function createStoreKeyring({ source }, _optional = {}) {
|
|
19
|
+
const withKeyring = ({ use }) => protectStorage({ source, operation: () => {
|
|
20
|
+
if (!source.keyring)
|
|
21
|
+
throw source.storageError({});
|
|
22
|
+
return use({ keyring: source.keyring });
|
|
23
|
+
} });
|
|
24
|
+
return {
|
|
25
|
+
derive: input => withKeyring({ use: ({ keyring }) => keyring.derive(input) }),
|
|
26
|
+
deriveSigningSecret: input => withKeyring({ use: ({ keyring }) => keyring.deriveSigningSecret(input) }),
|
|
27
|
+
activeKey: () => withKeyring({ use: ({ keyring }) => keyring.activeKey({}) }),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=store-vault-guards.js.map
|
|
@@ -2,7 +2,7 @@ import type { KeyringPort, SecretSealerPort } from "@jini-ai/core/contracts/vaul
|
|
|
2
2
|
import { type VaultContext, type VaultIdentity, type VaultMeta, type VaultMetaParsers, type VaultCopyResult, type VaultDefaultQuery, type VaultOptions, type VaultQuery, type VaultPutRecord, type VaultRepoPort, type VaultSummary } from "@jini-ai/core/contracts/vault";
|
|
3
3
|
export interface VaultServiceDeps {
|
|
4
4
|
repo: VaultRepoPort;
|
|
5
|
-
keyring: KeyringPort
|
|
5
|
+
keyring: Pick<KeyringPort, "activeKey">;
|
|
6
6
|
sealer: SecretSealerPort;
|
|
7
7
|
metaParsers: VaultMetaParsers;
|
|
8
8
|
/** Host policy must throw on denial. No permissive default is provided. */
|
package/dist/secrets/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type { SealedSecret } from "./types.js";
|
|
2
|
-
export { AesGcmSecretSealer } from "./secret-sealer.aesgcm.js";
|
|
2
|
+
export { AesGcmSecretSealer, LegacyUnboundAesGcmSecretSealer, SecretOpenError, SECRET_OPEN_FAILED } from "./secret-sealer.aesgcm.js";
|
|
3
3
|
export { sealWithPassphrase, openWithPassphrase } from "./passphrase-envelope.js";
|
|
4
4
|
export type { PassphraseEnvelopeOptions } from "./passphrase-envelope.js";
|
|
5
5
|
export { EnvOrFileKeyring } from "./keyring.env.js";
|
package/dist/secrets/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { AesGcmSecretSealer } from "./secret-sealer.aesgcm.js";
|
|
1
|
+
export { AesGcmSecretSealer, LegacyUnboundAesGcmSecretSealer, SecretOpenError, SECRET_OPEN_FAILED } from "./secret-sealer.aesgcm.js";
|
|
2
2
|
export { sealWithPassphrase, openWithPassphrase } from "./passphrase-envelope.js";
|
|
3
3
|
export { EnvOrFileKeyring } from "./keyring.env.js";
|
|
4
4
|
// Canonical public names; the implementation bindings retain compatibility for direct consumers.
|