@feltdb/feltkit 0.3.30 → 0.3.31
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/dist/app.d.ts +27 -9
- package/dist/app.js +36 -2
- package/dist/app.js.map +1 -1
- package/dist/appboundry/build.js +2 -0
- package/dist/appboundry/build.js.map +1 -1
- package/dist/appboundry/guest.js +23 -1
- package/dist/appboundry/guest.js.map +1 -1
- package/dist/authorize.d.ts +24 -3
- package/dist/authorize.js.map +1 -1
- package/dist/docs.d.ts +1 -1
- package/dist/docs.js +1 -0
- package/dist/docs.js.map +1 -1
- package/dist/index.d.ts +5 -2
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/policy.d.ts +172 -0
- package/dist/policy.js +311 -0
- package/dist/policy.js.map +1 -0
- package/dist/runtime/activity.d.ts +16 -0
- package/dist/runtime/activity.js.map +1 -1
- package/dist/runtime/application-authority.d.ts +20 -1
- package/dist/runtime/application-authority.js +60 -12
- package/dist/runtime/application-authority.js.map +1 -1
- package/dist/runtime/assemble.d.ts +13 -0
- package/dist/runtime/assemble.js +29 -1
- package/dist/runtime/assemble.js.map +1 -1
- package/dist/runtime/content.d.ts +50 -0
- package/dist/runtime/content.js +98 -1
- package/dist/runtime/content.js.map +1 -1
- package/dist/runtime/context.d.ts +62 -11
- package/dist/runtime/contract.js +11 -2
- package/dist/runtime/contract.js.map +1 -1
- package/dist/runtime/data.d.ts +25 -0
- package/dist/runtime/data.js +92 -8
- package/dist/runtime/data.js.map +1 -1
- package/dist/runtime/image-variants.d.ts +48 -0
- package/dist/runtime/image-variants.js +295 -0
- package/dist/runtime/image-variants.js.map +1 -0
- package/dist/runtime/integrations.js +1 -3
- package/dist/runtime/integrations.js.map +1 -1
- package/dist/runtime/live.d.ts +10 -7
- package/dist/runtime/live.js +24 -12
- package/dist/runtime/live.js.map +1 -1
- package/dist/runtime/local-authority.d.ts +47 -5
- package/dist/runtime/local-authority.js +195 -13
- package/dist/runtime/local-authority.js.map +1 -1
- package/dist/runtime/policies.d.ts +89 -0
- package/dist/runtime/policies.js +152 -0
- package/dist/runtime/policies.js.map +1 -0
- package/dist/runtime/runtime.d.ts +19 -1
- package/dist/runtime/runtime.js +192 -4
- package/dist/runtime/runtime.js.map +1 -1
- package/dist/runtime/services-rules.d.ts +9 -0
- package/dist/runtime/services-rules.js +47 -1
- package/dist/runtime/services-rules.js.map +1 -1
- package/dist/runtime/services.d.ts +117 -9
- package/dist/runtime/services.js +154 -13
- package/dist/runtime/services.js.map +1 -1
- package/dist/server/admin.d.ts +21 -0
- package/dist/server/admin.js +114 -0
- package/dist/server/admin.js.map +1 -1
- package/dist/server/index.js +33 -6
- package/dist/server/index.js.map +1 -1
- package/dist/server/operators.d.ts +1 -0
- package/dist/server/operators.js +1 -1
- package/dist/server/operators.js.map +1 -1
- package/dist/testing/index.d.ts +11 -0
- package/dist/testing/index.js +7 -0
- package/dist/testing/index.js.map +1 -1
- package/docs/AGENT-OPERATIONS.md +1 -1
- package/docs/ARCHITECTURE.md +2 -1
- package/docs/GUARANTEES.md +80 -6
- package/docs/POLICIES.md +121 -0
- package/docs/README.md +3 -2
- package/docs/SECURITY.md +30 -0
- package/docs/TRANSACTIONS.md +4 -0
- package/package.json +11 -7
- package/skills/.claude-plugin/marketplace.json +1 -1
- package/skills/.claude-plugin/plugin.json +1 -1
- package/skills/feltkit-services/SKILL.md +1 -1
package/dist/runtime/assemble.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { isFeltKitApp, isFunctionDefinition } from "../app.js";
|
|
7
7
|
import { FeltKitError } from "../errors.js";
|
|
8
|
+
import { nameCollections } from "../policy.js";
|
|
8
9
|
export function assemble(namespaces) {
|
|
9
10
|
const apps = new Set();
|
|
10
11
|
const functions = new Map();
|
|
@@ -40,6 +41,33 @@ export function assemble(namespaces) {
|
|
|
40
41
|
throw new FeltKitError("CONFIGURATION", `Capability ${key} is exposed by both ${other} and ${name}.`);
|
|
41
42
|
capabilities.set(key, name);
|
|
42
43
|
}
|
|
43
|
-
return { app, functions, modules: Object.keys(namespaces).sort(), loadedAt: new Date().toISOString() };
|
|
44
|
+
return { app, functions, policies: resolvePolicies(app, functions), modules: Object.keys(namespaces).sort(), loadedAt: new Date().toISOString() };
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The application's declared policies, by function name. A policy that names a function the project
|
|
48
|
+
* does not export is refused: a rule that silently stops applying is the failure ownership exists to
|
|
49
|
+
* prevent (test/ownership.test.ts, "the defect").
|
|
50
|
+
*/
|
|
51
|
+
export function resolvePolicies(app, functions) {
|
|
52
|
+
const names = new Map();
|
|
53
|
+
for (const [name, fn] of functions)
|
|
54
|
+
names.set(fn, [...(names.get(fn) ?? []), name]);
|
|
55
|
+
return app.policies.map((rule) => {
|
|
56
|
+
const resolved = rule.functions.flatMap((fn) => {
|
|
57
|
+
const found = typeof fn === "string" ? (functions.has(fn) ? [fn] : []) : names.get(fn) ?? [];
|
|
58
|
+
if (found.length === 0) {
|
|
59
|
+
throw new FeltKitError("CONFIGURATION", `Policy ${rule.id} names a function that no module in feltkit/ exports. Export it, or remove it from the policy.`);
|
|
60
|
+
}
|
|
61
|
+
return found;
|
|
62
|
+
});
|
|
63
|
+
const { functions: _f, resource, when, ...rest } = rule;
|
|
64
|
+
return {
|
|
65
|
+
...rest,
|
|
66
|
+
...(when ? { when: when.map(nameCollections) } : {}),
|
|
67
|
+
functions: [...new Set(resolved)].sort(),
|
|
68
|
+
...(resource ? { resource: { collection: typeof resource.collection === "string" ? resource.collection : resource.collection.name, id: resource.id } } : {}),
|
|
69
|
+
source: "code",
|
|
70
|
+
};
|
|
71
|
+
});
|
|
44
72
|
}
|
|
45
73
|
//# sourceMappingURL=assemble.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assemble.js","sourceRoot":"","sources":["../../src/runtime/assemble.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH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,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACpD,SAAS,EAAE,CAAC,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,EAAE;YACxC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,UAAU,EAAE,OAAO,QAAQ,CAAC,UAAU,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,EAAE,EAAE,EAAE,QAAQ,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAC5J,MAAM,EAAE,MAAe;SACxB,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -21,6 +21,12 @@ export type FileLinkGrant = {
|
|
|
21
21
|
fileId: string;
|
|
22
22
|
expiresAt: number;
|
|
23
23
|
disposition: "attachment" | "inline";
|
|
24
|
+
/** The checksum of the content the link was issued for: other content behind the file is not served by it. */
|
|
25
|
+
checksum?: string;
|
|
26
|
+
/** A declared image variant (`services.files.variants`) to serve instead of the original. */
|
|
27
|
+
variant?: string;
|
|
28
|
+
/** A cacheable link (`files.link(id, { cache: true })`): served `private, max-age=<remaining>, immutable`. */
|
|
29
|
+
cache?: true;
|
|
24
30
|
} | {
|
|
25
31
|
kind: "upload";
|
|
26
32
|
expiresAt: number;
|
|
@@ -36,8 +42,34 @@ export type FileLinkGrant = {
|
|
|
36
42
|
maxBytes: number;
|
|
37
43
|
metadata?: Record<string, string | number | boolean>;
|
|
38
44
|
};
|
|
45
|
+
/** A cacheable link's token: the same scope (file, content, variant, caller, window…) gives the same token. */
|
|
46
|
+
export declare function derivedLinkToken(scope: readonly unknown[]): string;
|
|
39
47
|
/** Where file bytes are kept, one row per file. */
|
|
40
48
|
export declare const FILE_CONTENT_COLLECTION = "_feltkit_file_content";
|
|
49
|
+
/**
|
|
50
|
+
* Derived renditions of stored bytes (image variants), one row per source storage key and variant
|
|
51
|
+
* name. A row is derived content: produced from its source, released with it (`releaseVariants`),
|
|
52
|
+
* and never served except through a link to a file whose bytes it was derived from.
|
|
53
|
+
*/
|
|
54
|
+
export declare const FILE_VARIANT_COLLECTION = "_feltkit_file_variants";
|
|
55
|
+
export interface StoredVariant {
|
|
56
|
+
id: string;
|
|
57
|
+
/** The storage key of the bytes it was derived from. */
|
|
58
|
+
source: string;
|
|
59
|
+
variant: string;
|
|
60
|
+
/** Digest of the variant's spec and codec: a changed declaration derives it again. */
|
|
61
|
+
spec: string;
|
|
62
|
+
/** derived: `data` holds it. original: it could not be derived (reason), and the original is served. */
|
|
63
|
+
status: "derived" | "original";
|
|
64
|
+
reason?: string;
|
|
65
|
+
data?: string;
|
|
66
|
+
size?: number;
|
|
67
|
+
checksum?: string;
|
|
68
|
+
width?: number;
|
|
69
|
+
height?: number;
|
|
70
|
+
contentType?: string;
|
|
71
|
+
storedAt: number;
|
|
72
|
+
}
|
|
41
73
|
export declare class FileContent {
|
|
42
74
|
#private;
|
|
43
75
|
constructor(db: StateFirstDB);
|
|
@@ -78,11 +110,29 @@ export declare class FileContent {
|
|
|
78
110
|
* Idempotent: `true` when this call removed them, `false` when they were already gone.
|
|
79
111
|
*/
|
|
80
112
|
release(storageKey: string): Promise<boolean>;
|
|
113
|
+
/** The stored variant of `source` named `variant`, if any (whatever spec it was derived under). */
|
|
114
|
+
variant(source: string, variant: string): Promise<StoredVariant | null>;
|
|
115
|
+
/**
|
|
116
|
+
* Keep a derived variant (or the reason it could not be derived). Replaces a row derived under an
|
|
117
|
+
* older spec; if another request stored the same one first, that one is kept and returned.
|
|
118
|
+
*/
|
|
119
|
+
storeVariant(input: Omit<StoredVariant, "id" | "storedAt" | "data" | "size" | "checksum"> & {
|
|
120
|
+
bytes?: Uint8Array;
|
|
121
|
+
}): Promise<StoredVariant>;
|
|
122
|
+
/** A derived variant's bytes, verified against their digest. */
|
|
123
|
+
readVariant(row: StoredVariant): Uint8Array;
|
|
124
|
+
/** Remove every variant derived from `source` (its bytes are being released). Returns how many were removed. */
|
|
125
|
+
releaseVariants(source: string): Promise<number>;
|
|
81
126
|
/**
|
|
82
127
|
* Issue an opaque link token for `grant`. Only its SHA-256 is stored, so the stored row cannot
|
|
83
128
|
* be replayed as a link. The function that issues it has already authorized the caller.
|
|
84
129
|
*/
|
|
85
130
|
issueLink(grant: FileLinkGrant): Promise<string>;
|
|
131
|
+
/**
|
|
132
|
+
* Store the grant for a token the caller derived (a cacheable link: the same token for the same
|
|
133
|
+
* file, content, caller and window). Issuing it again is idempotent; only its digest is stored.
|
|
134
|
+
*/
|
|
135
|
+
issueDerivedLink(token: string, grant: FileLinkGrant): Promise<string>;
|
|
86
136
|
/**
|
|
87
137
|
* Resolve a link token. Unknown, expired and (for upload links) already-used tokens are all
|
|
88
138
|
* NOT_FOUND. An upload link is consumed here, before its bytes are read: it works once.
|
package/dist/runtime/content.js
CHANGED
|
@@ -1,13 +1,30 @@
|
|
|
1
|
-
import { createHash, randomBytes, randomUUID } from "node:crypto";
|
|
1
|
+
import { createHash, createHmac, randomBytes, randomUUID } from "node:crypto";
|
|
2
2
|
import { FeltKitError } from "../errors.js";
|
|
3
3
|
import { readAll } from "./paged-read.js";
|
|
4
4
|
/** Outstanding file links (download and upload), keyed by the SHA-256 of their token. */
|
|
5
5
|
export const FILE_LINK_COLLECTION = "_feltkit_file_links";
|
|
6
6
|
const LINK_PREFIX = "fkf_";
|
|
7
7
|
const digestOf = (token) => createHash("sha256").update(token).digest("hex");
|
|
8
|
+
/**
|
|
9
|
+
* The key cacheable link tokens are derived under: random per process, never stored. A token is
|
|
10
|
+
* HMAC(key, its scope), so it cannot be computed from anything in the database, and a restart
|
|
11
|
+
* issues new URLs (one more download per file, not a weaker link).
|
|
12
|
+
*/
|
|
13
|
+
const LINK_KEY = randomBytes(32);
|
|
14
|
+
/** A cacheable link's token: the same scope (file, content, variant, caller, window…) gives the same token. */
|
|
15
|
+
export function derivedLinkToken(scope) {
|
|
16
|
+
return LINK_PREFIX + createHmac("sha256", LINK_KEY).update(JSON.stringify(scope)).digest("base64url");
|
|
17
|
+
}
|
|
8
18
|
/** Where file bytes are kept, one row per file. */
|
|
9
19
|
export const FILE_CONTENT_COLLECTION = "_feltkit_file_content";
|
|
10
20
|
const PREFIX = "feltkit-content:";
|
|
21
|
+
/**
|
|
22
|
+
* Derived renditions of stored bytes (image variants), one row per source storage key and variant
|
|
23
|
+
* name. A row is derived content: produced from its source, released with it (`releaseVariants`),
|
|
24
|
+
* and never served except through a link to a file whose bytes it was derived from.
|
|
25
|
+
*/
|
|
26
|
+
export const FILE_VARIANT_COLLECTION = "_feltkit_file_variants";
|
|
27
|
+
const variantId = (source, variant) => createHash("sha256").update(`${source}\0${variant}`).digest("hex");
|
|
11
28
|
export class FileContent {
|
|
12
29
|
#db;
|
|
13
30
|
constructor(db) {
|
|
@@ -96,6 +113,68 @@ export class FileContent {
|
|
|
96
113
|
throw error;
|
|
97
114
|
}
|
|
98
115
|
}
|
|
116
|
+
/** The stored variant of `source` named `variant`, if any (whatever spec it was derived under). */
|
|
117
|
+
async variant(source, variant) {
|
|
118
|
+
const row = await this.#db.collection(FILE_VARIANT_COLLECTION).get(variantId(source, variant));
|
|
119
|
+
if (!row)
|
|
120
|
+
return null;
|
|
121
|
+
const { __version: _version, ...value } = row;
|
|
122
|
+
return value;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Keep a derived variant (or the reason it could not be derived). Replaces a row derived under an
|
|
126
|
+
* older spec; if another request stored the same one first, that one is kept and returned.
|
|
127
|
+
*/
|
|
128
|
+
async storeVariant(input) {
|
|
129
|
+
const id = variantId(input.source, input.variant);
|
|
130
|
+
const { bytes, ...rest } = input;
|
|
131
|
+
const value = {
|
|
132
|
+
...rest,
|
|
133
|
+
id,
|
|
134
|
+
...(bytes ? { data: Buffer.from(bytes).toString("base64"), size: bytes.byteLength, checksum: createHash("sha256").update(bytes).digest("hex") } : {}),
|
|
135
|
+
storedAt: Date.now(),
|
|
136
|
+
};
|
|
137
|
+
const rows = this.#db.collection(FILE_VARIANT_COLLECTION);
|
|
138
|
+
const existing = await rows.get(id);
|
|
139
|
+
try {
|
|
140
|
+
await this.#db.transaction({ operations: [existing ? { collection: FILE_VARIANT_COLLECTION, id, ifVersion: existing.__version, value: value } : { collection: FILE_VARIANT_COLLECTION, id, requireAbsent: true, value: value }] });
|
|
141
|
+
return value;
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
const now = await this.variant(input.source, input.variant);
|
|
145
|
+
if (now && now.spec === input.spec)
|
|
146
|
+
return now; // produced concurrently: the same derivation
|
|
147
|
+
throw error;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/** A derived variant's bytes, verified against their digest. */
|
|
151
|
+
readVariant(row) {
|
|
152
|
+
const bytes = new Uint8Array(Buffer.from(row.data ?? "", "base64"));
|
|
153
|
+
if (!row.checksum || createHash("sha256").update(bytes).digest("hex") !== row.checksum) {
|
|
154
|
+
throw new FeltKitError("INTERNAL", `Variant ${row.variant} failed its checksum; the stored bytes do not match the recorded digest.`);
|
|
155
|
+
}
|
|
156
|
+
return bytes;
|
|
157
|
+
}
|
|
158
|
+
/** Remove every variant derived from `source` (its bytes are being released). Returns how many were removed. */
|
|
159
|
+
async releaseVariants(source) {
|
|
160
|
+
const rows = (await readAll(this.#db, { collection: FILE_VARIANT_COLLECTION, where: [{ field: "source", eq: source }] }));
|
|
161
|
+
let removed = 0;
|
|
162
|
+
for (const row of rows) {
|
|
163
|
+
const remove = (version) => this.#db.transaction({ operations: [{ collection: FILE_VARIANT_COLLECTION, id: row.id, ifVersion: version }] });
|
|
164
|
+
try {
|
|
165
|
+
await remove(row.__version);
|
|
166
|
+
}
|
|
167
|
+
catch (error) {
|
|
168
|
+
// Derived again meanwhile: remove what is there now; gone already is the same outcome.
|
|
169
|
+
const now = await this.#db.collection(FILE_VARIANT_COLLECTION).get(row.id);
|
|
170
|
+
if (!now)
|
|
171
|
+
continue;
|
|
172
|
+
await remove(now.__version);
|
|
173
|
+
}
|
|
174
|
+
removed += 1;
|
|
175
|
+
}
|
|
176
|
+
return removed;
|
|
177
|
+
}
|
|
99
178
|
/**
|
|
100
179
|
* Issue an opaque link token for `grant`. Only its SHA-256 is stored, so the stored row cannot
|
|
101
180
|
* be replayed as a link. The function that issues it has already authorized the caller.
|
|
@@ -106,6 +185,24 @@ export class FileContent {
|
|
|
106
185
|
await this.#db.transaction({ operations: [{ collection: FILE_LINK_COLLECTION, id, requireAbsent: true, value: { id, ...grant } }] });
|
|
107
186
|
return token;
|
|
108
187
|
}
|
|
188
|
+
/**
|
|
189
|
+
* Store the grant for a token the caller derived (a cacheable link: the same token for the same
|
|
190
|
+
* file, content, caller and window). Issuing it again is idempotent; only its digest is stored.
|
|
191
|
+
*/
|
|
192
|
+
async issueDerivedLink(token, grant) {
|
|
193
|
+
const id = digestOf(token);
|
|
194
|
+
const rows = this.#db.collection(FILE_LINK_COLLECTION);
|
|
195
|
+
if (await rows.get(id))
|
|
196
|
+
return token;
|
|
197
|
+
try {
|
|
198
|
+
await this.#db.transaction({ operations: [{ collection: FILE_LINK_COLLECTION, id, requireAbsent: true, value: { id, ...grant } }] });
|
|
199
|
+
}
|
|
200
|
+
catch (error) {
|
|
201
|
+
if (!(await rows.get(id)))
|
|
202
|
+
throw error; // not a concurrent issue of the same link
|
|
203
|
+
}
|
|
204
|
+
return token;
|
|
205
|
+
}
|
|
109
206
|
/**
|
|
110
207
|
* Resolve a link token. Unknown, expired and (for upload links) already-used tokens are all
|
|
111
208
|
* NOT_FOUND. An upload link is consumed here, before its bytes are read: it works once.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content.js","sourceRoot":"","sources":["../../src/runtime/content.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,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M,CAAC;gBACP,MAAM,OAAO,EAAE,CAAC,CAAC,wCAAwC;YAC3D,CAAC;YACD,IAAI,GAAG,CAAC,SAAS,IAAI,GAAG;gBAAE,MAAM,OAAO,EAAE,CAAC;QAC5C,CAAC;QACD,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,GAAG,GAAyD,CAAC;QACpG,OAAQ,KAAyB,CAAC,EAAE,CAAC;QACrC,OAAO,KAAsB,CAAC;IAChC,CAAC;CACF"}
|
|
@@ -295,26 +295,61 @@ export interface ApplicationAuthority {
|
|
|
295
295
|
* application to do for them. Always the caller's own; a person, signed in.
|
|
296
296
|
*/
|
|
297
297
|
grants: {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
expiresAt: number | null;
|
|
302
|
-
status: string;
|
|
303
|
-
}>>;
|
|
298
|
+
/** The caller's active grants, to the executor (`agent: null`) and to each agent (`agent`: its AuthBoundry principal). */
|
|
299
|
+
list(): Promise<AuthorityGrant[]>;
|
|
300
|
+
/** `agent` (an agent's principal id): the grant is for that agent only; without it, for the application's executor. */
|
|
304
301
|
grant(input: {
|
|
305
302
|
capabilities: string[];
|
|
306
303
|
expiresAt?: number;
|
|
304
|
+
agent?: string;
|
|
305
|
+
}): Promise<AuthorityGrant>;
|
|
306
|
+
/** One of the caller's own grants, whichever agent it is for. */
|
|
307
|
+
revoke(id: string): Promise<void>;
|
|
308
|
+
};
|
|
309
|
+
/**
|
|
310
|
+
* The application's agents at its local authority (authority.local, per-agent delegation). Every
|
|
311
|
+
* `app.agent` is registered automatically at each start; these are for agents that arrive at run time
|
|
312
|
+
* (an external MCP agent's principal, say). Needs `feltkit.authority.agents` and a caller that is not an
|
|
313
|
+
* agent: registration is an operator's act, and an agent never registers itself. Registering grants
|
|
314
|
+
* nothing: a person must still grant the agent capabilities.
|
|
315
|
+
*/
|
|
316
|
+
agents: {
|
|
317
|
+
register(input: {
|
|
318
|
+
id: string;
|
|
319
|
+
name?: string;
|
|
307
320
|
}): Promise<{
|
|
308
321
|
id: string;
|
|
309
|
-
capabilities: string[];
|
|
310
|
-
expiresAt: number | null;
|
|
311
322
|
status: string;
|
|
312
323
|
}>;
|
|
324
|
+
list(): Promise<Array<{
|
|
325
|
+
id: string;
|
|
326
|
+
name: string | null;
|
|
327
|
+
status: string;
|
|
328
|
+
}>>;
|
|
329
|
+
/** Final: none of the agent's credentials work again, so none of its grants allow anything. */
|
|
313
330
|
revoke(id: string): Promise<void>;
|
|
314
331
|
};
|
|
332
|
+
/**
|
|
333
|
+
* `onBehalfOf` names the requester, in one of these forms (FRAME-GAP-11):
|
|
334
|
+
* "ada" an application principal id (no ":"): mapped through
|
|
335
|
+
* `authority.principal`, default `user:ada`, as `grants` maps the delegator
|
|
336
|
+
* "user:ada" an AuthBoundry principal (`<type>:<id>`, contains ":"): sent unchanged
|
|
337
|
+
* { person: "ada" } always an application principal id, mapped (for ids that contain ":")
|
|
338
|
+
* { principal: "user:ada" } always an AuthBoundry principal, unchanged (for a custom
|
|
339
|
+
* `authority.principal` whose principals have no ":")
|
|
340
|
+
* The decision's `onBehalfOf` is the AuthBoundry principal that was asked about.
|
|
341
|
+
*/
|
|
342
|
+
/**
|
|
343
|
+
* `agent` (local authority): decide as that registered agent, with its own credential, so only a
|
|
344
|
+
* grant to that agent allows it. A caller that is itself an agent (an `app.agent` handler, an agent
|
|
345
|
+
* session) always decides as itself: `agent` may only name itself, and the executor's grants never
|
|
346
|
+
* apply to it. Anyone else decides as the executor unless it names an agent. An agent that is not
|
|
347
|
+
* registered is a deny, never an error.
|
|
348
|
+
*/
|
|
315
349
|
decide(request: {
|
|
316
350
|
capability: string;
|
|
317
|
-
onBehalfOf?:
|
|
351
|
+
onBehalfOf?: OnBehalfOf;
|
|
352
|
+
agent?: string;
|
|
318
353
|
resource?: {
|
|
319
354
|
type: string;
|
|
320
355
|
id: string;
|
|
@@ -322,15 +357,31 @@ export interface ApplicationAuthority {
|
|
|
322
357
|
context?: Record<string, string>;
|
|
323
358
|
}): Promise<ApplicationAuthorityDecision>;
|
|
324
359
|
}
|
|
360
|
+
export interface AuthorityGrant {
|
|
361
|
+
id: string;
|
|
362
|
+
/** The agent it is for (AuthBoundry principal), or null: the application's executor. */
|
|
363
|
+
agent: string | null;
|
|
364
|
+
capabilities: string[];
|
|
365
|
+
expiresAt: number | null;
|
|
366
|
+
status: string;
|
|
367
|
+
}
|
|
368
|
+
/** Whom an authority decision is on behalf of (see `ApplicationAuthority.decide`). */
|
|
369
|
+
export type OnBehalfOf = string | {
|
|
370
|
+
person: string;
|
|
371
|
+
} | {
|
|
372
|
+
principal: string;
|
|
373
|
+
};
|
|
325
374
|
export interface ApplicationAuthorityDecision {
|
|
326
375
|
allowed: boolean;
|
|
327
376
|
outcome: "allow" | "deny" | "unavailable" | "invalid";
|
|
328
377
|
decisionId: string | null;
|
|
329
378
|
reason: string | null;
|
|
330
379
|
capability: string;
|
|
331
|
-
/** Who acts: the application's executor principal at AuthBoundry. */
|
|
380
|
+
/** Who acts: the application's executor principal at AuthBoundry, or the agent that decided (`agent`). */
|
|
332
381
|
executor: string;
|
|
333
|
-
/**
|
|
382
|
+
/** The agent the decision was made as (its AuthBoundry principal), or null: the executor. */
|
|
383
|
+
agent: string | null;
|
|
384
|
+
/** For whom (the requester, as the AuthBoundry principal asked about), when asked on behalf of someone. */
|
|
334
385
|
onBehalfOf: string | null;
|
|
335
386
|
/** The delegation that decided an on-behalf allow. */
|
|
336
387
|
delegationId: string | null;
|
package/dist/runtime/contract.js
CHANGED
|
@@ -37,6 +37,7 @@ import { SERVICE_NAMES, servicesContract } from "@appport/services";
|
|
|
37
37
|
import { FeltKitError } from "../errors.js";
|
|
38
38
|
import { ACTIVITY_COLLECTION } from "./activity.js";
|
|
39
39
|
import { AUDIT_COLLECTION } from "./audit.js";
|
|
40
|
+
import { DECISIONS_COLLECTION, POLICY_EVENTS_COLLECTION, POLICY_STATE_COLLECTION, POLICY_VERSIONS_COLLECTION } from "./policies.js";
|
|
40
41
|
import { ACCOUNTS_COLLECTION, ACCOUNT_EMAILS_COLLECTION } from "./accounts.js";
|
|
41
42
|
import { CHALLENGES_COLLECTION } from "./challenges.js";
|
|
42
43
|
import { INVITATIONS_COLLECTION, MEMBERSHIPS_COLLECTION, TENANTS_COLLECTION } from "./tenancy.js";
|
|
@@ -47,7 +48,7 @@ import { INVOCATIONS_COLLECTION } from "./invocations.js";
|
|
|
47
48
|
import { CREDENTIALS_COLLECTION } from "./credentials.js";
|
|
48
49
|
import { SAVED_MODELS } from "./decisions.js";
|
|
49
50
|
import { SESSIONS_COLLECTION } from "./sessions.js";
|
|
50
|
-
import { FILE_CONTENT_COLLECTION, FILE_LINK_COLLECTION } from "./content.js";
|
|
51
|
+
import { FILE_CONTENT_COLLECTION, FILE_LINK_COLLECTION, FILE_VARIANT_COLLECTION } from "./content.js";
|
|
51
52
|
import { OUTBOX_COLLECTION } from "./outbox.js";
|
|
52
53
|
import { compileStateContract } from "./state-contract.js";
|
|
53
54
|
/**
|
|
@@ -62,6 +63,12 @@ const PLATFORM_COLLECTIONS = {
|
|
|
62
63
|
[MIGRATIONS_COLLECTION]: ["kind", "from", "to", "changes", "migrations", "writes", "appliedAt", "by", "environment"],
|
|
63
64
|
// The audit trail (runtime/audit.ts): one record per committed mutation, in its transaction.
|
|
64
65
|
[AUDIT_COLLECTION]: ["at", "transactionId", "function", "via", "requestId", "principal", "tenantId", "authority", "writes", "effects"],
|
|
66
|
+
// Managed policies (runtime/policies.ts): immutable versions, the active pointer, append-only history.
|
|
67
|
+
[POLICY_VERSIONS_COLLECTION]: ["version", "rules", "digest", "note", "createdAt", "createdBy"],
|
|
68
|
+
[POLICY_STATE_COLLECTION]: ["active", "changedAt", "changedBy"],
|
|
69
|
+
[POLICY_EVENTS_COLLECTION]: ["at", "by", "action", "version"],
|
|
70
|
+
// Durable decision evidence: every refusal, and allows of policies marked evidence: "durable".
|
|
71
|
+
[DECISIONS_COLLECTION]: ["at", "function", "via", "requestId", "principal", "tenant", "outcome", "layer", "reason", "policyVersion", "matched", "unmet", "delegations", "argKeys"],
|
|
65
72
|
[OUTBOX_COLLECTION]: ["requestId", "function", "principalId", "effect", "state", "createdAt", "updatedAt", "attempts", "error", "result", "retriedBy"],
|
|
66
73
|
[ACTIVITY_COLLECTION]: [
|
|
67
74
|
"at", "kind", "name", "capability", "via", "requestId", "principal", "authority", "outcome", "error",
|
|
@@ -137,7 +144,9 @@ export function feltdbContract(app) {
|
|
|
137
144
|
// storedAt: when the bytes were stored (an orphan reclaim excludes bytes an upload in flight has not recorded yet).
|
|
138
145
|
collections.push({ name: FILE_CONTENT_COLLECTION, fields: [ID, ...["data", "size", "checksum", "storedAt"].map((field) => ({ name: field, type: "json", required: false, nullable: true }))] });
|
|
139
146
|
// File links (files.link / uploadLink): keyed by the token's digest.
|
|
140
|
-
collections.push({ name: FILE_LINK_COLLECTION, fields: [ID, ...["kind", "fileId", "expiresAt", "disposition", "principal", "name", "contentType", "maxBytes", "metadata"].map((field) => ({ name: field, type: "json", required: false, nullable: true }))] });
|
|
147
|
+
collections.push({ name: FILE_LINK_COLLECTION, fields: [ID, ...["kind", "fileId", "expiresAt", "disposition", "checksum", "variant", "cache", "principal", "name", "contentType", "maxBytes", "metadata"].map((field) => ({ name: field, type: "json", required: false, nullable: true }))] });
|
|
148
|
+
// Image variants (services.files.variants): derived from stored bytes, released with them.
|
|
149
|
+
collections.push({ name: FILE_VARIANT_COLLECTION, fields: [ID, ...["source", "variant", "spec", "status", "reason", "data", "size", "checksum", "width", "height", "contentType", "storedAt"].map((field) => ({ name: field, type: "json", required: false, nullable: true }))] });
|
|
141
150
|
}
|
|
142
151
|
collections.push(...FELTDB_AGENT_STATE_CONTRACT.collections);
|
|
143
152
|
const indexes = compiled.indexes.map(manifestIndex);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../../src/runtime/contract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;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c,CAAC,QAAwB;IACrD,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC;AAClD,CAAC"}
|
package/dist/runtime/data.d.ts
CHANGED
|
@@ -55,7 +55,19 @@ export interface WhereClause {
|
|
|
55
55
|
lte?: unknown;
|
|
56
56
|
gt?: unknown;
|
|
57
57
|
gte?: unknown;
|
|
58
|
+
/**
|
|
59
|
+
* Set membership (FeltDB's `in`): the field equals any of these values, with `eq`'s equality
|
|
60
|
+
* (strings, finite numbers, booleans, null; at most 256; an empty list matches nothing). Needs
|
|
61
|
+
* a FeltDB with set-membership queries (after 0.21.0). With an index whose fields are this field
|
|
62
|
+
* then the order (`indexes: [{ fields: ["authorId", "createdAt"], directions: ["asc", "desc"] }]`
|
|
63
|
+
* for `orderBy createdAt desc`), FeltDB pages it as a merge of one index range per value.
|
|
64
|
+
*/
|
|
65
|
+
in?: readonly unknown[];
|
|
58
66
|
}
|
|
67
|
+
/** FeltDB's limit on an `in` list. */
|
|
68
|
+
export declare const MAX_IN_VALUES = 256;
|
|
69
|
+
/** Refuses a malformed `in` clause before FeltDB sees it (INVALID_ARGUMENT, naming the field). */
|
|
70
|
+
export declare function checkWhere(where: readonly WhereClause[] | undefined): void;
|
|
59
71
|
export interface FindOptions {
|
|
60
72
|
orderBy?: OrderBy[];
|
|
61
73
|
limit?: number;
|
|
@@ -163,6 +175,19 @@ export declare const MIGRATIONS_COLLECTION = "_feltkit_migrations";
|
|
|
163
175
|
*/
|
|
164
176
|
export declare function ensureCollectionMarkers(db: StateFirstDB, names: Iterable<string>): Promise<void>;
|
|
165
177
|
export { CollectionResolver };
|
|
178
|
+
/** The embedded index FeltKit declares for an index with a "desc" direction (CollectionOptions.indexes). */
|
|
179
|
+
export declare function orderedIndexName(collection: string, index: {
|
|
180
|
+
name?: string;
|
|
181
|
+
fields: readonly string[];
|
|
182
|
+
}): string;
|
|
183
|
+
/**
|
|
184
|
+
* Declare to an embedded FeltDB (local, memory) every application index with a "desc" direction, with
|
|
185
|
+
* its directions: FeltDB's state contract declares index fields only (ascending), so without this a
|
|
186
|
+
* query ordered descending could not be served by the index (FeltDB's `in` merge and range plans need
|
|
187
|
+
* the index's own order to match the query's). Idempotent: an index this or an earlier process declared
|
|
188
|
+
* is left alone. Returns the names declared now.
|
|
189
|
+
*/
|
|
190
|
+
export declare function ensureOrderedIndexes(db: StateFirstDB, collections: Iterable<CollectionDefinition>): Promise<string[]>;
|
|
166
191
|
export declare function newId(): string;
|
|
167
192
|
export declare function equalityWhere(filter: Record<string, unknown> | undefined): WhereClause[];
|
|
168
193
|
/** Read-only access. Every collection read is recorded so subscribers can be invalidated. */
|