@feltdb/feltkit 0.3.29 → 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 +101 -11
- package/dist/app.js +131 -3
- 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-tenancy.d.ts +2 -2
- package/dist/appboundry/guest-tenancy.js.map +1 -1
- package/dist/appboundry/guest.js +27 -2
- package/dist/appboundry/guest.js.map +1 -1
- package/dist/appboundry/host.js +3 -0
- package/dist/appboundry/host.js.map +1 -1
- package/dist/authorize.d.ts +47 -4
- package/dist/authorize.js +37 -0
- package/dist/authorize.js.map +1 -1
- package/dist/cli/deploy-appboundry.d.ts +1 -1
- package/dist/cli/deploy-appboundry.js.map +1 -1
- package/dist/cli/deploy.js.map +1 -1
- package/dist/cli/main.js +27 -1
- package/dist/cli/main.js.map +1 -1
- package/dist/cli/skills.js.map +1 -1
- package/dist/client/index.js.map +1 -1
- package/dist/dashboard/assets/index-9rMS3yBm.js +15 -0
- package/dist/dashboard/assets/index-DkiYTUMR.css +1 -0
- package/dist/dashboard/index.html +2 -2
- package/dist/docs.d.ts +1 -1
- package/dist/docs.js +4 -0
- package/dist/docs.js.map +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/event-stage.js.map +1 -1
- package/dist/execution.d.ts +186 -0
- package/dist/execution.js +105 -0
- package/dist/execution.js.map +1 -0
- package/dist/index.d.ts +10 -2
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/measure/index.js.map +1 -1
- package/dist/platform/approvals.js.map +1 -1
- package/dist/platform/artifacts.js.map +1 -1
- package/dist/platform/changes.d.ts +54 -54
- package/dist/platform/changes.js.map +1 -1
- package/dist/platform/deployments.d.ts +32 -32
- package/dist/platform/exec.js.map +1 -1
- package/dist/platform/platform.js.map +1 -1
- package/dist/platform/releases.js.map +1 -1
- package/dist/platform/server.js.map +1 -1
- package/dist/platform/workspaces.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/react/auth.d.ts +10 -10
- package/dist/react/auth.js +1 -1
- package/dist/react/auth.js.map +1 -1
- package/dist/react/context.d.ts +1 -1
- package/dist/react/index.js.map +1 -1
- package/dist/runtime/accounts.js.map +1 -1
- package/dist/runtime/activity.d.ts +17 -1
- package/dist/runtime/activity.js.map +1 -1
- package/dist/runtime/agent.d.ts +3 -3
- package/dist/runtime/agent.js +9 -3
- package/dist/runtime/agent.js.map +1 -1
- package/dist/runtime/application-authority.d.ts +33 -3
- package/dist/runtime/application-authority.js +74 -14
- 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/audit.js.map +1 -1
- package/dist/runtime/authboundry.d.ts +17 -0
- package/dist/runtime/authboundry.js +8 -1
- package/dist/runtime/authboundry.js.map +1 -1
- package/dist/runtime/authority.d.ts +10 -0
- package/dist/runtime/authority.js +17 -0
- package/dist/runtime/authority.js.map +1 -1
- package/dist/runtime/backup-environment.js.map +1 -1
- package/dist/runtime/backup.js.map +1 -1
- package/dist/runtime/changes.js.map +1 -1
- package/dist/runtime/claims.js.map +1 -1
- package/dist/runtime/collections.js.map +1 -1
- package/dist/runtime/content.d.ts +77 -2
- package/dist/runtime/content.js +153 -6
- package/dist/runtime/content.js.map +1 -1
- package/dist/runtime/context.d.ts +207 -3
- package/dist/runtime/contract.js +16 -3
- package/dist/runtime/contract.js.map +1 -1
- package/dist/runtime/credentials.d.ts +31 -2
- package/dist/runtime/credentials.js +55 -3
- package/dist/runtime/credentials.js.map +1 -1
- package/dist/runtime/crypto-token.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/decisions.js.map +1 -1
- package/dist/runtime/deployment.js.map +1 -1
- package/dist/runtime/execution-host.d.ts +54 -0
- package/dist/runtime/execution-host.js +54 -0
- package/dist/runtime/execution-host.js.map +1 -0
- package/dist/runtime/generation.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/instance.js.map +1 -1
- package/dist/runtime/integrations.d.ts +8 -6
- package/dist/runtime/integrations.js +46 -5
- package/dist/runtime/integrations.js.map +1 -1
- package/dist/runtime/invocations.d.ts +313 -0
- package/dist/runtime/invocations.js +493 -0
- package/dist/runtime/invocations.js.map +1 -0
- 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/loader.js.map +1 -1
- package/dist/runtime/local-authority.d.ts +92 -0
- package/dist/runtime/local-authority.js +396 -0
- package/dist/runtime/local-authority.js.map +1 -0
- package/dist/runtime/oauth-credentials.d.ts +40 -3
- package/dist/runtime/oauth-credentials.js +133 -25
- package/dist/runtime/oauth-credentials.js.map +1 -1
- package/dist/runtime/outbox.js +3 -0
- package/dist/runtime/outbox.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/projects.d.ts +1 -1
- package/dist/runtime/readiness.js +11 -0
- package/dist/runtime/readiness.js.map +1 -1
- package/dist/runtime/runtime.d.ts +66 -5
- package/dist/runtime/runtime.js +328 -18
- 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 +154 -9
- package/dist/runtime/services.js +343 -14
- package/dist/runtime/services.js.map +1 -1
- package/dist/runtime/sessions.js.map +1 -1
- package/dist/runtime/state-contract.js.map +1 -1
- package/dist/runtime/storage-check.js.map +1 -1
- package/dist/runtime/targets.d.ts +1 -1
- package/dist/runtime/tenancy.js.map +1 -1
- package/dist/runtime/transactions.d.ts +15 -0
- package/dist/runtime/transactions.js +5 -0
- package/dist/runtime/transactions.js.map +1 -1
- package/dist/schema.js.map +1 -1
- package/dist/server/admin.d.ts +72 -51
- package/dist/server/admin.js +125 -0
- package/dist/server/admin.js.map +1 -1
- package/dist/server/components.js.map +1 -1
- package/dist/server/index.js +72 -6
- package/dist/server/index.js.map +1 -1
- package/dist/server/management.js.map +1 -1
- package/dist/server/mcp.d.ts +59 -37
- package/dist/server/mcp.js +24 -1
- package/dist/server/mcp.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/server/ports.d.ts +7 -0
- package/dist/server/ports.js +17 -0
- package/dist/server/ports.js.map +1 -1
- package/dist/server/production.js.map +1 -1
- package/dist/server/project.js.map +1 -1
- package/dist/server/session-http.js.map +1 -1
- package/dist/server/tenancy.js.map +1 -1
- package/dist/surfaces.d.ts +153 -0
- package/dist/surfaces.js +228 -0
- package/dist/surfaces.js.map +1 -0
- 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/CONNECTIONS.md +151 -0
- package/docs/EXECUTION.md +271 -0
- package/docs/GUARANTEES.md +134 -8
- package/docs/INVOCATIONS.md +170 -0
- package/docs/POLICIES.md +121 -0
- package/docs/README.md +6 -2
- package/docs/SECURITY.md +30 -0
- package/docs/TRANSACTIONS.md +4 -0
- package/package.json +27 -19
- 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/dashboard/assets/index-BehzsQOa.css +0 -1
- package/dist/dashboard/assets/index-UuZ63NA6.js +0 -15
package/dist/runtime/live.js
CHANGED
|
@@ -72,19 +72,29 @@ export function keyedValues(definition, record) {
|
|
|
72
72
|
return out;
|
|
73
73
|
}
|
|
74
74
|
/**
|
|
75
|
-
* The
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
75
|
+
* The predicates that stand for a read, or null when none can (the read then counts as reading the
|
|
76
|
+
* whole collection). A record matching the read matches every one of its clauses, so any single keyed
|
|
77
|
+
* clause is a sound over-approximation: an equality is one predicate; a set membership (`in`) is one
|
|
78
|
+
* predicate per value (the record matches one of them). The most selective is preferred: `id`, then
|
|
79
|
+
* any other keyed equality, then a keyed `in`, then the tenant field (which every record of the
|
|
80
|
+
* tenant shares).
|
|
79
81
|
*/
|
|
80
82
|
export function representative(definition, clauses) {
|
|
81
83
|
const keyed = keyedFields(definition);
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
+
const candidates = [];
|
|
85
|
+
for (const c of clauses) {
|
|
86
|
+
if (!keyed.has(c.field))
|
|
87
|
+
continue;
|
|
88
|
+
if ("eq" in c && c.eq !== undefined && scalar(c.eq)) {
|
|
89
|
+
candidates.push({ rank: c.field === "id" ? 0 : c.field === definition.tenant?.field ? 3 : 1, field: c.field, predicates: [{ field: c.field, value: c.eq }] });
|
|
90
|
+
}
|
|
91
|
+
else if (Array.isArray(c.in) && c.in.length > 0 && c.in.every(scalar)) {
|
|
92
|
+
candidates.push({ rank: c.field === definition.tenant?.field ? 3 : 2, field: c.field, predicates: [...new Map(c.in.map((v) => [JSON.stringify(v ?? null), { field: c.field, value: v }])).values()] });
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (!candidates.length)
|
|
84
96
|
return null;
|
|
85
|
-
|
|
86
|
-
const best = [...usable].sort((a, b) => rank(a.field) - rank(b.field) || a.field.localeCompare(b.field))[0];
|
|
87
|
-
return { field: best.field, value: best.eq };
|
|
97
|
+
return [...candidates].sort((a, b) => a.rank - b.rank || a.field.localeCompare(b.field))[0].predicates;
|
|
88
98
|
}
|
|
89
99
|
/** The opaque key for `collection.field = value`. Equal inputs give equal keys within one process. */
|
|
90
100
|
export function liveKey(collection, field, value) {
|
|
@@ -118,9 +128,10 @@ export class ReadSet extends Set {
|
|
|
118
128
|
this.#whole.add(collection);
|
|
119
129
|
return super.add(collection);
|
|
120
130
|
}
|
|
121
|
-
/** A read of `collection` limited to `predicate` (null: the whole collection). */
|
|
131
|
+
/** A read of `collection` limited to `predicate` (several: any of them; null or none: the whole collection). */
|
|
122
132
|
record(collection, predicate) {
|
|
123
|
-
|
|
133
|
+
const predicates = predicate === null ? [] : Array.isArray(predicate) ? predicate : [predicate];
|
|
134
|
+
if (!predicates.length) {
|
|
124
135
|
this.add(collection);
|
|
125
136
|
return;
|
|
126
137
|
}
|
|
@@ -134,7 +145,8 @@ export class ReadSet extends Set {
|
|
|
134
145
|
let map = this.#predicates.get(collection);
|
|
135
146
|
if (!map)
|
|
136
147
|
this.#predicates.set(collection, (map = new Map()));
|
|
137
|
-
|
|
148
|
+
for (const p of predicates)
|
|
149
|
+
map.set(`${p.field}\u0000${JSON.stringify(p.value ?? null)}`, p);
|
|
138
150
|
}
|
|
139
151
|
/**
|
|
140
152
|
* The read set as `reads` reports it: every collection name (clients that know only names keep
|
package/dist/runtime/live.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"live.js","sourceRoot":"","sources":["../../src/runtime/live.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAEtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEjD,MAAM,WAAW,GAAG,WAAW,CAAC,EAAE,CAAC,CAAC;AAiBpC,MAAM,UAAU,GAAG,IAAI,OAAO,EAA6C,CAAC;AAE5E,6FAA6F;AAC7F,MAAM,UAAU,WAAW,CAAC,UAAgC;IAC1D,MAAM,MAAM,GAAG,UAAU,CAAC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EAAE,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;QACpF,OAAO,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC;IACtE,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { Principal } from "./authority.js";
|
|
2
|
+
import type { FeltKitRuntime } from "./runtime.js";
|
|
3
|
+
import type { AuthorityGrant } from "./context.js";
|
|
4
|
+
import { authorityPrincipalOf } from "./application-authority.js";
|
|
5
|
+
export declare const LOCAL_ADMIN_REF = "credential-ref:authboundry-local-admin";
|
|
6
|
+
export interface Grant {
|
|
7
|
+
id: string;
|
|
8
|
+
/** The agent the grant is for (its AuthBoundry principal), or null: the application's executor. */
|
|
9
|
+
agent?: string | null;
|
|
10
|
+
capabilities: string[];
|
|
11
|
+
/** Epoch ms, or null (until revoked). */
|
|
12
|
+
expiresAt: number | null;
|
|
13
|
+
status: string;
|
|
14
|
+
}
|
|
15
|
+
export interface LocalAuthorityStatus {
|
|
16
|
+
/** deferred: the test environment starts it on first use (a decision or a grant), not with the application. */
|
|
17
|
+
state: "off" | "external" | "deferred" | "running" | "failed";
|
|
18
|
+
url: string | null;
|
|
19
|
+
dataDir: string | null;
|
|
20
|
+
error: string | null;
|
|
21
|
+
}
|
|
22
|
+
/** The AuthBoundry principal of a FeltKit agent principal: its id when it has a ":", else `agent:<id>`. */
|
|
23
|
+
export declare function authorityAgentId(id: string): string;
|
|
24
|
+
/** Where an agent's credential is kept (custody, never a record). */
|
|
25
|
+
export declare const agentCredentialRef: (agent: string) => string;
|
|
26
|
+
/** The permission that registers, lists and revokes the application's agents at its local authority (an operator's). */
|
|
27
|
+
export declare const AGENTS_PERMISSION = "feltkit.authority.agents";
|
|
28
|
+
export { authorityPrincipalOf };
|
|
29
|
+
/**
|
|
30
|
+
* Every capability the application asks AuthBoundry about: its own (`authority.capabilities`) and one per
|
|
31
|
+
* operation of each integration people connect themselves (the operation's `authority`, default
|
|
32
|
+
* `<integration>.<operation>`), so a person can grant or withhold each one.
|
|
33
|
+
*/
|
|
34
|
+
export declare function applicationCapabilities(runtime: FeltKitRuntime): string[];
|
|
35
|
+
export declare class LocalAuthorityHost {
|
|
36
|
+
#private;
|
|
37
|
+
constructor(runtime: FeltKitRuntime);
|
|
38
|
+
get status(): LocalAuthorityStatus;
|
|
39
|
+
/** The private AuthBoundry's address, once it runs (started on first use where deferred). */
|
|
40
|
+
url(): Promise<string | null>;
|
|
41
|
+
/**
|
|
42
|
+
* With the application: start it when this application asks for a local authority and none is
|
|
43
|
+
* configured elsewhere. The test environment defers it to first use: most tests never ask.
|
|
44
|
+
*/
|
|
45
|
+
start(): Promise<void>;
|
|
46
|
+
/** Running (or failed, once): what a decision or a grant waits for. */
|
|
47
|
+
ensure(): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Who an authority decision is made as (`ctx.authority.decide`), for `caller`:
|
|
50
|
+
* - an agent caller decides as itself, always (naming another agent, or the executor, is refused);
|
|
51
|
+
* - anyone else decides as the executor, unless it names a registered agent (`agent`).
|
|
52
|
+
* null: the executor. An agent decision needs the local authority (only it holds agents' credentials);
|
|
53
|
+
* with a hosted AuthBoundry an agent caller decides as the executor, as before, and naming one is refused.
|
|
54
|
+
*/
|
|
55
|
+
agentDecision(caller: Principal | null, requested: string | undefined): Promise<null | {
|
|
56
|
+
principal: string;
|
|
57
|
+
credential: string;
|
|
58
|
+
} | {
|
|
59
|
+
refused: "deny" | "unavailable" | "invalid";
|
|
60
|
+
reason: string;
|
|
61
|
+
}>;
|
|
62
|
+
/**
|
|
63
|
+
* The application's agents at its local authority (`ctx.authority.agents`): an operator's, never an
|
|
64
|
+
* agent's. Registering an agent grants it nothing: a person must still grant it capabilities.
|
|
65
|
+
*/
|
|
66
|
+
agentsFor(principal: Principal | null, requestId: string): {
|
|
67
|
+
register: (input: {
|
|
68
|
+
id: string;
|
|
69
|
+
name?: string;
|
|
70
|
+
}) => Promise<{
|
|
71
|
+
id: string;
|
|
72
|
+
status: string;
|
|
73
|
+
}>;
|
|
74
|
+
list: () => Promise<Array<{
|
|
75
|
+
id: string;
|
|
76
|
+
name: string | null;
|
|
77
|
+
status: string;
|
|
78
|
+
}>>;
|
|
79
|
+
revoke: (agent: string) => Promise<void>;
|
|
80
|
+
};
|
|
81
|
+
close(): Promise<void>;
|
|
82
|
+
/** A person's grants (`ctx.authority.grants`), for the caller only. */
|
|
83
|
+
grantsFor(principal: Principal | null, requestId: string): {
|
|
84
|
+
list: () => Promise<AuthorityGrant[]>;
|
|
85
|
+
grant: (input: {
|
|
86
|
+
capabilities: string[];
|
|
87
|
+
expiresAt?: number;
|
|
88
|
+
agent?: string;
|
|
89
|
+
}) => Promise<AuthorityGrant>;
|
|
90
|
+
revoke: (id: string) => Promise<void>;
|
|
91
|
+
};
|
|
92
|
+
}
|
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A private AuthBoundry for this application (`authority: { local: true }`), so the people who use it
|
|
3
|
+
* never set AuthBoundry up. When no AuthBoundry address is configured, FeltKit starts one through
|
|
4
|
+
* `@authboundry/local` (installed with the application; loaded only in this mode): on loopback, with its
|
|
5
|
+
* state beside the application's, its administrator's secret generated once and kept in FeltKit's
|
|
6
|
+
* custody, and the application check credential kept there too. Decisions then go to it exactly as they
|
|
7
|
+
* would to a hosted AuthBoundry (runtime/authboundry.ts): same contract, same fail-closed rules.
|
|
8
|
+
*
|
|
9
|
+
* It also gives application code a person's grants (`ctx.authority.grants`): what that person allows the
|
|
10
|
+
* application's executor, or one of its agents, to do for them. Only for the person asking: the
|
|
11
|
+
* delegator is always the caller, never an argument.
|
|
12
|
+
*
|
|
13
|
+
* Several agents (per-agent delegation, @authboundry/local after 0.1.0): every `app.agent` is registered
|
|
14
|
+
* as an AuthBoundry agent of the application at each start (`agent:<id>` unless its id already has a
|
|
15
|
+
* ":"), and so is every agent the application registered at run time (`ctx.authority.agents.register`,
|
|
16
|
+
* an operator action) that the authority still lists as active. Each agent's credential is kept in
|
|
17
|
+
* FeltKit's custody (`credential-ref:authboundry-local-agent:<agent>`), never in a record. A person's
|
|
18
|
+
* grant may name the agent it is for; an agent decides only as itself, with its own credential, so a
|
|
19
|
+
* grant to one agent never allows another or the executor.
|
|
20
|
+
*/
|
|
21
|
+
import { randomBytes } from "node:crypto";
|
|
22
|
+
import { grantsPermission } from "@appport/authorization";
|
|
23
|
+
import { FeltKitError } from "../errors.js";
|
|
24
|
+
import { authorityApplication, authorityPrincipalOf, authorityUrl, LOCAL_AGENT_REF } from "./application-authority.js";
|
|
25
|
+
import { OAuthCredentials } from "./oauth-credentials.js";
|
|
26
|
+
export const LOCAL_ADMIN_REF = "credential-ref:authboundry-local-admin";
|
|
27
|
+
const secretId = (ref) => ref.replace(/^credential-ref:/, "");
|
|
28
|
+
/** The AuthBoundry principal of a FeltKit agent principal: its id when it has a ":", else `agent:<id>`. */
|
|
29
|
+
export function authorityAgentId(id) {
|
|
30
|
+
return id.includes(":") ? id : `agent:${id}`;
|
|
31
|
+
}
|
|
32
|
+
/** Where an agent's credential is kept (custody, never a record). */
|
|
33
|
+
export const agentCredentialRef = (agent) => `credential-ref:authboundry-local-agent:${agent}`;
|
|
34
|
+
/** AuthBoundry agent ids: letters, digits, . _ : - (as @authboundry/local requires). */
|
|
35
|
+
const AGENT_ID = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/;
|
|
36
|
+
/** The permission that registers, lists and revokes the application's agents at its local authority (an operator's). */
|
|
37
|
+
export const AGENTS_PERMISSION = "feltkit.authority.agents";
|
|
38
|
+
const NEEDS_AGENTS = "Per-agent delegation needs @authboundry/local with registerAgent (after 0.1.0, authboundry 001ce42)";
|
|
39
|
+
export { authorityPrincipalOf };
|
|
40
|
+
/**
|
|
41
|
+
* Every capability the application asks AuthBoundry about: its own (`authority.capabilities`) and one per
|
|
42
|
+
* operation of each integration people connect themselves (the operation's `authority`, default
|
|
43
|
+
* `<integration>.<operation>`), so a person can grant or withhold each one.
|
|
44
|
+
*/
|
|
45
|
+
export function applicationCapabilities(runtime) {
|
|
46
|
+
const out = new Set(runtime.app.options.authority?.capabilities ?? []);
|
|
47
|
+
for (const i of runtime.integrations.definitions()) {
|
|
48
|
+
if (!OAuthCredentials.personal(i))
|
|
49
|
+
continue;
|
|
50
|
+
for (const [name, op] of Object.entries(i.operations))
|
|
51
|
+
out.add(op.authority ?? `${i.name}.${name}`);
|
|
52
|
+
}
|
|
53
|
+
return [...out];
|
|
54
|
+
}
|
|
55
|
+
export class LocalAuthorityHost {
|
|
56
|
+
#runtime;
|
|
57
|
+
#authority = null;
|
|
58
|
+
#status = { state: "off", url: null, dataDir: null, error: null };
|
|
59
|
+
#starting = null;
|
|
60
|
+
/** AuthBoundry agents registered in this process (their credentials are the authority's, renewed by it). */
|
|
61
|
+
#agents = new Set();
|
|
62
|
+
constructor(runtime) {
|
|
63
|
+
this.#runtime = runtime;
|
|
64
|
+
}
|
|
65
|
+
get status() {
|
|
66
|
+
return this.#status;
|
|
67
|
+
}
|
|
68
|
+
/** The private AuthBoundry's address, once it runs (started on first use where deferred). */
|
|
69
|
+
async url() {
|
|
70
|
+
await this.ensure();
|
|
71
|
+
return this.#authority?.url ?? null;
|
|
72
|
+
}
|
|
73
|
+
#dataDir() {
|
|
74
|
+
const config = this.#runtime.app.options.authority;
|
|
75
|
+
const local = typeof config.local === "object" ? config.local : {};
|
|
76
|
+
if (local.dataDir)
|
|
77
|
+
return local.dataDir;
|
|
78
|
+
if (process.env.FELTKIT_AUTHORITY_DIR)
|
|
79
|
+
return process.env.FELTKIT_AUTHORITY_DIR;
|
|
80
|
+
const env = this.#runtime.environment;
|
|
81
|
+
// Beside the state: the test environment's temporary state, or a volume given as FELTKIT_STATE_DIR.
|
|
82
|
+
if (env.storage.kind === "local" && (env.name === "test" || (!env.development && process.env.FELTKIT_STATE_DIR)))
|
|
83
|
+
return `${env.storage.path}.authority`;
|
|
84
|
+
return `${env.runtimeDir}/authority`;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* With the application: start it when this application asks for a local authority and none is
|
|
88
|
+
* configured elsewhere. The test environment defers it to first use: most tests never ask.
|
|
89
|
+
*/
|
|
90
|
+
async start() {
|
|
91
|
+
const config = this.#runtime.app.options.authority;
|
|
92
|
+
if (!config?.local)
|
|
93
|
+
return;
|
|
94
|
+
const external = config.url ? authorityUrl(config, this.#runtime.environment.production) : null;
|
|
95
|
+
if (external) {
|
|
96
|
+
this.#status = { state: "external", url: external, dataDir: null, error: null };
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (this.#runtime.environment.name === "test") {
|
|
100
|
+
this.#status = { state: "deferred", url: null, dataDir: null, error: null };
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
await this.ensure();
|
|
104
|
+
}
|
|
105
|
+
/** Running (or failed, once): what a decision or a grant waits for. */
|
|
106
|
+
async ensure() {
|
|
107
|
+
const config = this.#runtime.app.options.authority;
|
|
108
|
+
if (!config?.local || this.#status.state === "external")
|
|
109
|
+
return;
|
|
110
|
+
await (this.#starting ??= this.#run());
|
|
111
|
+
}
|
|
112
|
+
async #run() {
|
|
113
|
+
const config = this.#runtime.app.options.authority;
|
|
114
|
+
const dataDir = this.#dataDir();
|
|
115
|
+
try {
|
|
116
|
+
const capabilities = applicationCapabilities(this.#runtime);
|
|
117
|
+
if (!capabilities.length)
|
|
118
|
+
throw new FeltKitError("CONFIGURATION", "authority.local needs authority.capabilities: every capability the application asks AuthBoundry about.");
|
|
119
|
+
const custody = this.#runtime.credentials;
|
|
120
|
+
if (!custody.writable)
|
|
121
|
+
throw new FeltKitError("CONFIGURATION", "A local authority keeps its secrets in FeltKit's credential vault, which this environment can't write.", { hint: "Opt in to the vault: FELTKIT_CREDENTIAL_VAULT=1 (or =database) with FELTKIT_CREDENTIAL_VAULT_KEY." });
|
|
122
|
+
const read = (ref) => custody.withSecret({ reference: { secretId: secretId(ref) } }, (s) => s.value).catch(() => null);
|
|
123
|
+
let adminSecret = await read(LOCAL_ADMIN_REF);
|
|
124
|
+
if (!adminSecret) {
|
|
125
|
+
adminSecret = randomBytes(32).toString("base64url");
|
|
126
|
+
await custody.store({ reference: { secretId: secretId(LOCAL_ADMIN_REF), tenantId: this.#runtime.services.scope.tenantId, kind: "authority-admin" }, value: adminSecret });
|
|
127
|
+
}
|
|
128
|
+
const checkCredential = await read(config.checkCredential);
|
|
129
|
+
// The executor's agent credential: the one this application kept, if it still authenticates.
|
|
130
|
+
const agentRef = config.executor.credential ?? LOCAL_AGENT_REF;
|
|
131
|
+
const agentCredential = await read(agentRef);
|
|
132
|
+
const keepAgent = (value) => custody.store({ reference: { secretId: secretId(agentRef), tenantId: this.#runtime.services.scope.tenantId, kind: "authority-agent" }, value });
|
|
133
|
+
let mod;
|
|
134
|
+
try {
|
|
135
|
+
const name = "@authboundry/local";
|
|
136
|
+
mod = (await import(name));
|
|
137
|
+
}
|
|
138
|
+
catch {
|
|
139
|
+
throw new FeltKitError("CONFIGURATION", "authority.local needs @authboundry/local: npm install @authboundry/local.");
|
|
140
|
+
}
|
|
141
|
+
// Every app.agent, as an AuthBoundry agent of the application, with the credential kept for it.
|
|
142
|
+
const tenantId = this.#runtime.services.scope.tenantId;
|
|
143
|
+
const keepFor = (agent) => (value) => custody.store({ reference: { secretId: secretId(agentCredentialRef(agent)), tenantId, kind: "authority-agent" }, value });
|
|
144
|
+
const appAgents = [];
|
|
145
|
+
// (registered after the start, one by one: see #registerAgents)
|
|
146
|
+
for (const definition of this.#runtime.app.agents.values()) {
|
|
147
|
+
const id = authorityAgentId(definition.principal.id);
|
|
148
|
+
if (id === config.executor.principal || !AGENT_ID.test(id)) {
|
|
149
|
+
this.#runtime.logger.warn(`app.agent("${definition.name}") is not registered with the local authority: ${id === config.executor.principal ? "its principal is the executor's" : `"${id}" is not an AuthBoundry agent id (letters, digits, . _ : -)`}. Its decisions are denied.`);
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
appAgents.push({ id, name: definition.principal.displayName ?? definition.name, credential: await read(agentCredentialRef(id)), onCredential: keepFor(id) });
|
|
153
|
+
}
|
|
154
|
+
const authority = await mod.startLocalAuthority({
|
|
155
|
+
dataDir,
|
|
156
|
+
application: { id: authorityApplication(config, this.#runtime.environment.production, this.#runtime.app.name), name: this.#runtime.app.options.description ?? this.#runtime.app.name, capabilities },
|
|
157
|
+
executor: { id: config.executor.principal, name: this.#runtime.app.name },
|
|
158
|
+
adminSecret,
|
|
159
|
+
checkCredential,
|
|
160
|
+
agentCredential,
|
|
161
|
+
// A renewed agent credential goes to custody (never a record or a log).
|
|
162
|
+
onAgentCredential: (value) => keepAgent(value),
|
|
163
|
+
logger: { info: (m) => this.#runtime.logger.info(m), warn: (m) => this.#runtime.logger.warn(m) },
|
|
164
|
+
});
|
|
165
|
+
if (authority.issuedCheckCredential) {
|
|
166
|
+
try {
|
|
167
|
+
await custody.store({ reference: { secretId: secretId(config.checkCredential), tenantId: this.#runtime.services.scope.tenantId, kind: "authority-check" }, value: authority.checkCredential });
|
|
168
|
+
}
|
|
169
|
+
catch (error) {
|
|
170
|
+
await authority.close();
|
|
171
|
+
throw new FeltKitError("CONFIGURATION", `The local authority's check credential could not be kept: ${error.message}`);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
if (authority.issuedAgentCredential) {
|
|
175
|
+
try {
|
|
176
|
+
await keepAgent(authority.agentCredential);
|
|
177
|
+
}
|
|
178
|
+
catch (error) {
|
|
179
|
+
await authority.close();
|
|
180
|
+
throw new FeltKitError("CONFIGURATION", `The executor's agent credential could not be kept: ${error.message}`);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
await this.#registerAgents(authority, appAgents, read, keepFor);
|
|
184
|
+
this.#authority = authority;
|
|
185
|
+
this.#status = { state: "running", url: authority.url, dataDir, error: null };
|
|
186
|
+
this.#runtime.activity.record({ kind: "system", name: "authority.local.started", via: "runtime", requestId: `req_${randomBytes(8).toString("hex")}`, principal: null, outcome: "success", durationMs: 0, detail: { url: authority.url, dataDir, issuedCheckCredential: authority.issuedCheckCredential, issuedAgentCredential: authority.issuedAgentCredential, agentCredentialId: authority.agentCredentialId } });
|
|
187
|
+
}
|
|
188
|
+
catch (error) {
|
|
189
|
+
// Fail closed: without an authority every decision is "unavailable"; readiness says why.
|
|
190
|
+
this.#status = { state: "failed", url: null, dataDir, error: error.message };
|
|
191
|
+
this.#runtime.logger.warn(`The local authority did not start: ${error.message}`);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* After a start: keep the credentials the `agents` option issued, and register again every other agent
|
|
196
|
+
* the authority lists as active (registered at run time earlier; the authority's credential registry is
|
|
197
|
+
* in memory). A failure is the agent's alone: its decisions are denied, and the log says why.
|
|
198
|
+
*/
|
|
199
|
+
async #registerAgents(authority, appAgents, read, keepFor) {
|
|
200
|
+
this.#agents.clear();
|
|
201
|
+
if (typeof authority.registerAgent !== "function") {
|
|
202
|
+
if (appAgents.length)
|
|
203
|
+
this.#runtime.logger.warn(`${NEEDS_AGENTS}; the installed one has none, so the decisions of ${appAgents.map((a) => a.id).join(", ")} are denied.`);
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
// One at a time, each on its own: an agent that cannot be registered (revoked, say) is denied, and nothing else.
|
|
207
|
+
const register = async (input) => {
|
|
208
|
+
try {
|
|
209
|
+
const registered = await authority.registerAgent({ ...input, onCredential: keepFor(input.id) });
|
|
210
|
+
if (registered.issuedAgentCredential)
|
|
211
|
+
await keepFor(input.id)(registered.agentCredential);
|
|
212
|
+
this.#agents.add(input.id);
|
|
213
|
+
}
|
|
214
|
+
catch (error) {
|
|
215
|
+
this.#runtime.logger.warn(`Agent ${input.id} is not registered with the local authority: ${error.message}. Its decisions are denied.`);
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
for (const agent of appAgents)
|
|
219
|
+
await register({ id: agent.id, name: agent.name, credential: agent.credential });
|
|
220
|
+
// Agents registered at run time earlier: the authority keeps them, but its credential registry is in memory.
|
|
221
|
+
for (const agent of (await authority.agents?.().catch(() => [])) ?? []) {
|
|
222
|
+
if (agent.executor || agent.status !== "active" || this.#agents.has(agent.id))
|
|
223
|
+
continue;
|
|
224
|
+
await register({ id: agent.id, ...(agent.name ? { name: agent.name } : {}), credential: await read(agentCredentialRef(agent.id)) });
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Who an authority decision is made as (`ctx.authority.decide`), for `caller`:
|
|
229
|
+
* - an agent caller decides as itself, always (naming another agent, or the executor, is refused);
|
|
230
|
+
* - anyone else decides as the executor, unless it names a registered agent (`agent`).
|
|
231
|
+
* null: the executor. An agent decision needs the local authority (only it holds agents' credentials);
|
|
232
|
+
* with a hosted AuthBoundry an agent caller decides as the executor, as before, and naming one is refused.
|
|
233
|
+
*/
|
|
234
|
+
async agentDecision(caller, requested) {
|
|
235
|
+
const config = this.#runtime.app.options.authority;
|
|
236
|
+
if (requested !== undefined && (typeof requested !== "string" || !requested.trim()))
|
|
237
|
+
return { refused: "invalid", reason: "agent must be an agent id." };
|
|
238
|
+
const own = caller?.type === "agent" ? authorityAgentId(caller.id) : null;
|
|
239
|
+
const wanted = requested === undefined ? null : authorityAgentId(requested);
|
|
240
|
+
if (own && wanted && wanted !== own)
|
|
241
|
+
return { refused: "deny", reason: `An agent decides only as itself (${own}), never as ${wanted}.` };
|
|
242
|
+
const target = own ?? wanted;
|
|
243
|
+
if (!target)
|
|
244
|
+
return null;
|
|
245
|
+
if (!config?.local || this.#status.state === "external") {
|
|
246
|
+
if (!wanted)
|
|
247
|
+
return null; // hosted: an agent caller is the executor, as before (GUARANTEES "Application authority")
|
|
248
|
+
return { refused: "unavailable", reason: "Decisions as an agent need the local authority (authority.local), which holds each agent's credential." };
|
|
249
|
+
}
|
|
250
|
+
await this.ensure();
|
|
251
|
+
const authority = this.#authority;
|
|
252
|
+
if (!authority)
|
|
253
|
+
return { refused: "unavailable", reason: `The local authority is not running${this.#status.error ? `: ${this.#status.error}` : ""}.` };
|
|
254
|
+
if (typeof authority.registerAgent !== "function" || typeof authority.agentCredentialOf !== "function")
|
|
255
|
+
return { refused: "unavailable", reason: `${NEEDS_AGENTS}.` };
|
|
256
|
+
const credential = this.#agents.has(target) ? authority.agentCredentialOf(target) : null;
|
|
257
|
+
if (!credential)
|
|
258
|
+
return { refused: "deny", reason: `${target} is not an agent registered with this application's authority.` };
|
|
259
|
+
return { principal: target, credential };
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* The application's agents at its local authority (`ctx.authority.agents`): an operator's, never an
|
|
263
|
+
* agent's. Registering an agent grants it nothing: a person must still grant it capabilities.
|
|
264
|
+
*/
|
|
265
|
+
agentsFor(principal, requestId) {
|
|
266
|
+
const config = this.#runtime.app.options.authority;
|
|
267
|
+
const need = async () => {
|
|
268
|
+
if (!config?.local)
|
|
269
|
+
throw new FeltKitError("FAILED_PRECONDITION", "Agents are registered here only with a local authority (authority.local); with a hosted AuthBoundry, register them there.");
|
|
270
|
+
if (this.#status.state === "external")
|
|
271
|
+
throw new FeltKitError("UNAVAILABLE", "This environment uses a hosted AuthBoundry (AUTHBOUNDRY_URL); register agents there.");
|
|
272
|
+
if (!principal)
|
|
273
|
+
throw new FeltKitError("UNAUTHORIZED", "Managing agents needs a signed-in operator.");
|
|
274
|
+
if (principal.type === "agent")
|
|
275
|
+
throw new FeltKitError("FORBIDDEN", "An agent never registers or revokes agents, itself included: an operator does.");
|
|
276
|
+
if (!grantsPermission(this.#runtime.authority.permissionsFor(principal), AGENTS_PERMISSION))
|
|
277
|
+
throw new FeltKitError("FORBIDDEN", `Managing the application's agents needs ${AGENTS_PERMISSION}.`);
|
|
278
|
+
await this.ensure();
|
|
279
|
+
const authority = this.#authority;
|
|
280
|
+
if (!authority)
|
|
281
|
+
throw new FeltKitError("UNAVAILABLE", `The local authority is not running${this.#status.error ? `: ${this.#status.error}` : ""}.`);
|
|
282
|
+
if (typeof authority.registerAgent !== "function" || typeof authority.revokeAgent !== "function" || typeof authority.agents !== "function")
|
|
283
|
+
throw new FeltKitError("FAILED_PRECONDITION", `${NEEDS_AGENTS}.`);
|
|
284
|
+
return authority;
|
|
285
|
+
};
|
|
286
|
+
const record = (name, detail) => this.#runtime.activity.record({ kind: "auth", name, via: "runtime", requestId, principal: principal ? { id: principal.id, type: principal.type, roles: principal.roles } : null, outcome: "success", durationMs: 0, detail });
|
|
287
|
+
const tenantId = this.#runtime.services.scope.tenantId;
|
|
288
|
+
const keepFor = (agent) => (value) => this.#runtime.credentials.store({ reference: { secretId: secretId(agentCredentialRef(agent)), tenantId, kind: "authority-agent" }, value });
|
|
289
|
+
return {
|
|
290
|
+
register: async (input) => {
|
|
291
|
+
const authority = await need();
|
|
292
|
+
if (!input || typeof input.id !== "string")
|
|
293
|
+
throw new FeltKitError("INVALID_ARGUMENT", "register() needs the agent's principal id.");
|
|
294
|
+
const id = authorityAgentId(input.id);
|
|
295
|
+
if (!AGENT_ID.test(id))
|
|
296
|
+
throw new FeltKitError("INVALID_ARGUMENT", `"${id}" is not an agent id: letters, digits, . _ : -`);
|
|
297
|
+
if (id === config.executor.principal)
|
|
298
|
+
throw new FeltKitError("INVALID_ARGUMENT", "That is the application's executor, not an agent.");
|
|
299
|
+
if (/^user:/.test(id) || id === authorityPrincipalOf(config, input.id))
|
|
300
|
+
throw new FeltKitError("INVALID_ARGUMENT", "A person is never registered as an agent.");
|
|
301
|
+
const held = await this.#runtime.credentials.withSecret({ reference: { secretId: secretId(agentCredentialRef(id)) } }, (v) => v.value).catch(() => null);
|
|
302
|
+
const registered = await authority.registerAgent({ id, ...(input.name ? { name: input.name } : {}), credential: held, onCredential: keepFor(id) }).catch((error) => {
|
|
303
|
+
throw new FeltKitError(error?.code === "AGENT_NOT_ACTIVE" ? "FAILED_PRECONDITION" : error?.code === "INVALID" ? "INVALID_ARGUMENT" : "UNAVAILABLE", `Agent ${id} was not registered: ${error?.message ?? String(error)}`);
|
|
304
|
+
});
|
|
305
|
+
if (registered.issuedAgentCredential)
|
|
306
|
+
await keepFor(id)(registered.agentCredential);
|
|
307
|
+
this.#agents.add(id);
|
|
308
|
+
record("authority.agent.register", { agent: id, issuedAgentCredential: registered.issuedAgentCredential });
|
|
309
|
+
return { id, status: registered.status };
|
|
310
|
+
},
|
|
311
|
+
list: async () => {
|
|
312
|
+
const authority = await need();
|
|
313
|
+
return (await authority.agents()).filter((a) => !a.executor).map((a) => ({ id: a.id, name: a.name, status: a.status }));
|
|
314
|
+
},
|
|
315
|
+
revoke: async (agent) => {
|
|
316
|
+
const authority = await need();
|
|
317
|
+
const id = authorityAgentId(String(agent ?? ""));
|
|
318
|
+
if (!(await authority.agents()).some((a) => a.id === id && !a.executor))
|
|
319
|
+
throw new FeltKitError("NOT_FOUND", `No agent ${id}.`);
|
|
320
|
+
await authority.revokeAgent(id);
|
|
321
|
+
this.#agents.delete(id);
|
|
322
|
+
record("authority.agent.revoke", { agent: id });
|
|
323
|
+
},
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
async close() {
|
|
327
|
+
await this.#starting?.catch(() => undefined);
|
|
328
|
+
const authority = this.#authority;
|
|
329
|
+
this.#authority = null;
|
|
330
|
+
if (authority)
|
|
331
|
+
await authority.close();
|
|
332
|
+
}
|
|
333
|
+
/** A person's grants (`ctx.authority.grants`), for the caller only. */
|
|
334
|
+
grantsFor(principal, requestId) {
|
|
335
|
+
const config = this.#runtime.app.options.authority;
|
|
336
|
+
const need = async () => {
|
|
337
|
+
if (!config?.local)
|
|
338
|
+
throw new FeltKitError("FAILED_PRECONDITION", "Grants are managed here only with a local authority (authority.local); with a hosted AuthBoundry, people grant there.");
|
|
339
|
+
if (this.#status.state === "external")
|
|
340
|
+
throw new FeltKitError("UNAVAILABLE", "This environment uses a hosted AuthBoundry (AUTHBOUNDRY_URL); people grant there.");
|
|
341
|
+
if (!principal || principal.type !== "user")
|
|
342
|
+
throw new FeltKitError("FORBIDDEN", "Only a signed-in person grants authority, and only their own.");
|
|
343
|
+
await this.ensure();
|
|
344
|
+
if (!this.#authority)
|
|
345
|
+
throw new FeltKitError("UNAVAILABLE", `The local authority is not running${this.#status.error ? `: ${this.#status.error}` : ""}.`);
|
|
346
|
+
return { authority: this.#authority, delegator: authorityPrincipalOf(config, principal.id) };
|
|
347
|
+
};
|
|
348
|
+
const record = (name, outcome, detail) => this.#runtime.activity.record({ kind: "auth", name, via: "runtime", requestId, principal: principal ? { id: principal.id, type: principal.type, roles: principal.roles } : null, outcome, durationMs: 0, detail });
|
|
349
|
+
const executor = config?.executor.principal;
|
|
350
|
+
const own = (g) => ({ id: g.id, agent: g.agent && g.agent !== executor ? g.agent : null, capabilities: g.capabilities, expiresAt: g.expiresAt, status: g.status });
|
|
351
|
+
// The caller's grants to the executor and, where the authority has per-agent delegation, to every agent.
|
|
352
|
+
const mine = async (authority, delegator) => {
|
|
353
|
+
const all = new Map((await authority.delegations(delegator)).map((g) => [g.id, g]));
|
|
354
|
+
if (typeof authority.registerAgent === "function")
|
|
355
|
+
for (const g of await authority.delegations(delegator, { agent: "*" }))
|
|
356
|
+
all.set(g.id, g);
|
|
357
|
+
return [...all.values()];
|
|
358
|
+
};
|
|
359
|
+
return {
|
|
360
|
+
list: async () => {
|
|
361
|
+
const { authority, delegator } = await need();
|
|
362
|
+
return (await mine(authority, delegator)).filter((g) => g.status === "active").map(own);
|
|
363
|
+
},
|
|
364
|
+
grant: async (input) => {
|
|
365
|
+
const { authority, delegator } = await need();
|
|
366
|
+
const known = applicationCapabilities(this.#runtime);
|
|
367
|
+
const unknown = input.capabilities.filter((c) => !known.includes(c));
|
|
368
|
+
if (!input.capabilities.length || unknown.length)
|
|
369
|
+
throw new FeltKitError("INVALID_ARGUMENT", unknown.length ? `Not capabilities of this application: ${unknown.join(", ")}.` : "Grant at least one capability.");
|
|
370
|
+
if (input.expiresAt !== undefined && !(input.expiresAt > Date.now()))
|
|
371
|
+
throw new FeltKitError("INVALID_ARGUMENT", "expiresAt must be in the future.");
|
|
372
|
+
const agent = input.agent === undefined ? undefined : authorityAgentId(String(input.agent));
|
|
373
|
+
if (agent !== undefined && typeof authority.registerAgent !== "function")
|
|
374
|
+
throw new FeltKitError("FAILED_PRECONDITION", `${NEEDS_AGENTS}; the installed one grants to the executor only.`);
|
|
375
|
+
if (agent !== undefined && agent === executor)
|
|
376
|
+
throw new FeltKitError("INVALID_ARGUMENT", "That is the application's executor: grant without agent.");
|
|
377
|
+
const g = await authority.grant({ delegator, capabilities: input.capabilities, ...(input.expiresAt ? { expiresAt: input.expiresAt } : {}), ...(agent ? { agent } : {}) }).catch((error) => {
|
|
378
|
+
if (error?.code === "UNKNOWN_AGENT" || error?.code === "AGENT_NOT_ACTIVE")
|
|
379
|
+
throw new FeltKitError("NOT_FOUND", `No active agent ${agent} of this application.`);
|
|
380
|
+
throw error;
|
|
381
|
+
});
|
|
382
|
+
record("authority.grant", "success", { grant: g.id, ...(agent ? { agent } : {}), capabilities: g.capabilities, expiresAt: g.expiresAt });
|
|
383
|
+
return own(g);
|
|
384
|
+
},
|
|
385
|
+
revoke: async (id) => {
|
|
386
|
+
const { authority, delegator } = await need();
|
|
387
|
+
// Only the caller's own (to the executor or to any agent): another person's grant does not exist for them.
|
|
388
|
+
if (!(await mine(authority, delegator)).some((g) => g.id === id))
|
|
389
|
+
throw new FeltKitError("NOT_FOUND", `No grant ${id}.`);
|
|
390
|
+
await authority.revoke(id);
|
|
391
|
+
record("authority.revoke", "success", { grant: id });
|
|
392
|
+
},
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
//# sourceMappingURL=local-authority.js.map
|