@feltdb/feltkit 0.3.30 → 0.3.32
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 +67 -11
- package/dist/app.js +58 -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/broker/assertion.d.ts +68 -0
- package/dist/broker/assertion.js +104 -0
- package/dist/broker/assertion.js.map +1 -0
- package/dist/broker/keys.d.ts +9 -0
- package/dist/broker/keys.js +47 -0
- package/dist/broker/keys.js.map +1 -0
- package/dist/broker/server.d.ts +54 -0
- package/dist/broker/server.js +305 -0
- package/dist/broker/server.js.map +1 -0
- package/dist/cli/broker.d.ts +11 -0
- package/dist/cli/broker.js +72 -0
- package/dist/cli/broker.js.map +1 -0
- package/dist/cli/deploy.js +6 -0
- package/dist/cli/deploy.js.map +1 -1
- package/dist/cli/main.js +123 -0
- package/dist/cli/main.js.map +1 -1
- package/dist/client/index.d.ts +8 -2
- package/dist/client/index.js +45 -1
- package/dist/client/index.js.map +1 -1
- package/dist/docs.d.ts +1 -1
- package/dist/docs.js +3 -0
- package/dist/docs.js.map +1 -1
- package/dist/extension/build.d.ts +50 -0
- package/dist/extension/build.js +205 -0
- package/dist/extension/build.js.map +1 -0
- package/dist/extension/client-shim.d.ts +7 -0
- package/dist/extension/client-shim.js +13 -0
- package/dist/extension/client-shim.js.map +1 -0
- package/dist/extension/connect-ui.d.ts +24 -0
- package/dist/extension/connect-ui.js +67 -0
- package/dist/extension/connect-ui.js.map +1 -0
- package/dist/extension/connection.d.ts +109 -0
- package/dist/extension/connection.js +190 -0
- package/dist/extension/connection.js.map +1 -0
- package/dist/extension/host-core.d.ts +36 -0
- package/dist/extension/host-core.js +50 -0
- package/dist/extension/host-core.js.map +1 -0
- package/dist/extension/host.d.ts +1 -0
- package/dist/extension/host.js +8 -0
- package/dist/extension/host.js.map +1 -0
- package/dist/extension/icons.d.ts +13 -0
- package/dist/extension/icons.js +75 -0
- package/dist/extension/icons.js.map +1 -0
- package/dist/extension/identity.d.ts +40 -0
- package/dist/extension/identity.js +110 -0
- package/dist/extension/identity.js.map +1 -0
- package/dist/extension/options.d.ts +1 -0
- package/dist/extension/options.js +57 -0
- package/dist/extension/options.js.map +1 -0
- package/dist/extension/service-worker.d.ts +1 -0
- package/dist/extension/service-worker.js +38 -0
- package/dist/extension/service-worker.js.map +1 -0
- package/dist/extension/validate.d.ts +7 -0
- package/dist/extension/validate.js +143 -0
- package/dist/extension/validate.js.map +1 -0
- package/dist/extension/zip.d.ts +7 -0
- package/dist/extension/zip.js +94 -0
- package/dist/extension/zip.js.map +1 -0
- package/dist/index.d.ts +6 -2
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/policy.d.ts +179 -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 +22 -3
- package/dist/runtime/application-authority.js +94 -20
- 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/authority-contract.d.ts +55 -0
- package/dist/runtime/authority-contract.js +60 -0
- package/dist/runtime/authority-contract.js.map +1 -0
- 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 +86 -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.d.ts +2 -0
- package/dist/runtime/integrations.js +10 -7
- package/dist/runtime/integrations.js.map +1 -1
- package/dist/runtime/invocations.d.ts +3 -0
- package/dist/runtime/invocations.js +1 -1
- package/dist/runtime/invocations.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 +80 -5
- package/dist/runtime/local-authority.js +259 -14
- 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/readiness.js +31 -1
- package/dist/runtime/readiness.js.map +1 -1
- package/dist/runtime/runtime.d.ts +21 -1
- package/dist/runtime/runtime.js +200 -7
- 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/oauth.d.ts +32 -2
- package/dist/server/oauth.js +130 -23
- package/dist/server/oauth.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/project.d.ts +3 -0
- package/dist/server/project.js +2 -2
- package/dist/server/project.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/CONNECTIONS.md +10 -3
- package/docs/EXTENSION-HOSTS.md +64 -5
- package/docs/GUARANTEES.md +82 -6
- package/docs/LOCAL-AUTHORITY.md +118 -0
- package/docs/POLICIES.md +121 -0
- package/docs/README.md +5 -2
- package/docs/SECURITY.md +69 -0
- package/docs/SIGN-IN-BROKER.md +77 -0
- package/docs/TRANSACTIONS.md +4 -0
- package/package.json +13 -9
- package/skills/.claude-plugin/marketplace.json +1 -1
- package/skills/.claude-plugin/plugin.json +1 -1
- package/skills/feltkit-agent/SKILL.md +1 -1
- package/skills/feltkit-build/SKILL.md +10 -0
- package/skills/feltkit-data/SKILL.md +13 -1
- package/skills/feltkit-services/SKILL.md +14 -1
package/dist/policy.d.ts
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import type { CollectionDefinition, FunctionDefinition } from "./app.js";
|
|
2
|
+
import type { Principal } from "./runtime/authority.js";
|
|
3
|
+
import type { DatabaseReader } from "./runtime/data.js";
|
|
4
|
+
type Primitive = string | number | boolean | null;
|
|
5
|
+
/** A comparison against a value: every operator given must hold. */
|
|
6
|
+
export interface Comparison {
|
|
7
|
+
eq?: Primitive;
|
|
8
|
+
ne?: Primitive;
|
|
9
|
+
in?: readonly Primitive[];
|
|
10
|
+
notIn?: readonly Primitive[];
|
|
11
|
+
lt?: number;
|
|
12
|
+
lte?: number;
|
|
13
|
+
gt?: number;
|
|
14
|
+
gte?: number;
|
|
15
|
+
}
|
|
16
|
+
/** A reference through another record: the field holds its id; that record's `field` is what is wanted. */
|
|
17
|
+
export type Via = {
|
|
18
|
+
collection: CollectionDefinition | string;
|
|
19
|
+
field: string;
|
|
20
|
+
};
|
|
21
|
+
/** Where a delegation condition finds the person the agent must be acting for (a resource field, optionally `via` a referenced record, or an argument). */
|
|
22
|
+
export type PersonRef = {
|
|
23
|
+
field: string;
|
|
24
|
+
via?: Via;
|
|
25
|
+
} | {
|
|
26
|
+
arg: string;
|
|
27
|
+
};
|
|
28
|
+
export type PolicyCondition =
|
|
29
|
+
/**
|
|
30
|
+
* The resource's `field` names the caller. With `via`, the field holds the id of a record in
|
|
31
|
+
* `via.collection` whose `via.field` names the caller (e.g. `createdBy` → participants.principalId).
|
|
32
|
+
*/
|
|
33
|
+
{
|
|
34
|
+
owner: string;
|
|
35
|
+
via?: Via;
|
|
36
|
+
}
|
|
37
|
+
/** The resource's `field` is a list that contains the caller. */
|
|
38
|
+
| {
|
|
39
|
+
sharedWith: string;
|
|
40
|
+
}
|
|
41
|
+
/** The resource's `field` compares as given (e.g. `{ field: "status", in: ["draft"] }`). */
|
|
42
|
+
| ({
|
|
43
|
+
field: string;
|
|
44
|
+
} & Comparison)
|
|
45
|
+
/** The validated argument compares as given (e.g. `{ arg: "amount", lte: 1000 }`). */
|
|
46
|
+
| ({
|
|
47
|
+
arg: string;
|
|
48
|
+
} & Comparison)
|
|
49
|
+
/** The caller's role in their current tenant (workspace) is one of these. */
|
|
50
|
+
| {
|
|
51
|
+
tenantRole: string | readonly string[];
|
|
52
|
+
}
|
|
53
|
+
/** The caller holds this application role. */
|
|
54
|
+
| {
|
|
55
|
+
role: string | readonly string[];
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The caller is not a person (an agent or service) and AuthBoundry allows the application's
|
|
59
|
+
* executor to exercise `capability` on behalf of the person named by `onBehalfOf` (a resource
|
|
60
|
+
* field or an argument): a delegation that exists, is in force, and covers the capability.
|
|
61
|
+
*/
|
|
62
|
+
| {
|
|
63
|
+
delegated: {
|
|
64
|
+
capability: string;
|
|
65
|
+
onBehalfOf: PersonRef;
|
|
66
|
+
};
|
|
67
|
+
} | {
|
|
68
|
+
any: readonly PolicyCondition[];
|
|
69
|
+
} | {
|
|
70
|
+
not: PolicyCondition;
|
|
71
|
+
};
|
|
72
|
+
export interface PolicyRule {
|
|
73
|
+
/** Stable id, named in every decision it takes part in. */
|
|
74
|
+
id: string;
|
|
75
|
+
description?: string;
|
|
76
|
+
effect: "allow" | "deny";
|
|
77
|
+
/** The functions it governs: definitions in code (rename-safe), "<module>:<export>" in managed policies. */
|
|
78
|
+
functions: readonly (FunctionDefinition | string)[];
|
|
79
|
+
/** Which callers it applies to (default: everyone, including anonymous). */
|
|
80
|
+
principals?: {
|
|
81
|
+
types?: readonly ("user" | "agent" | "service")[];
|
|
82
|
+
roles?: readonly string[];
|
|
83
|
+
anonymous?: boolean;
|
|
84
|
+
};
|
|
85
|
+
/** The record the call acts on, loaded through the call's reader by the argument holding its id. */
|
|
86
|
+
resource?: {
|
|
87
|
+
collection: CollectionDefinition | string;
|
|
88
|
+
id: string;
|
|
89
|
+
};
|
|
90
|
+
/** All must hold. */
|
|
91
|
+
when?: readonly PolicyCondition[];
|
|
92
|
+
/** Record allow decisions durably too (denials always are). For sensitive operations. */
|
|
93
|
+
evidence?: "durable";
|
|
94
|
+
}
|
|
95
|
+
/** A rule as stored and evaluated: functions and the collection by name. */
|
|
96
|
+
export interface ResolvedPolicyRule extends Omit<PolicyRule, "functions" | "resource"> {
|
|
97
|
+
functions: readonly string[];
|
|
98
|
+
resource?: {
|
|
99
|
+
collection: string;
|
|
100
|
+
id: string;
|
|
101
|
+
};
|
|
102
|
+
source: "code" | "managed";
|
|
103
|
+
}
|
|
104
|
+
export interface PolicySet {
|
|
105
|
+
/** "code:<digest>" for the declared policies, plus "+managed:<n>" when a managed version is active. */
|
|
106
|
+
version: string;
|
|
107
|
+
rules: readonly ResolvedPolicyRule[];
|
|
108
|
+
}
|
|
109
|
+
export interface PolicyRequest {
|
|
110
|
+
function: string;
|
|
111
|
+
principal: Principal | null;
|
|
112
|
+
args: Record<string, unknown>;
|
|
113
|
+
db: DatabaseReader;
|
|
114
|
+
/** Resolves a collection name for the reader. */
|
|
115
|
+
collection: (name: string) => CollectionDefinition | undefined;
|
|
116
|
+
/** Ask AuthBoundry for a delegated decision (absent where there is no authority: the condition does not hold). */
|
|
117
|
+
delegate?: (request: {
|
|
118
|
+
capability: string;
|
|
119
|
+
onBehalfOf: string;
|
|
120
|
+
}) => Promise<{
|
|
121
|
+
allowed: boolean;
|
|
122
|
+
decisionId: string | null;
|
|
123
|
+
delegationId: string | null;
|
|
124
|
+
authorityMode?: import("./runtime/authority-contract.js").AuthorityMode | null;
|
|
125
|
+
reason?: string;
|
|
126
|
+
}>;
|
|
127
|
+
}
|
|
128
|
+
export interface PolicyDecision {
|
|
129
|
+
allowed: boolean;
|
|
130
|
+
/** Was the call decided by a policy (named by an allow rule, or refused by a deny rule)? */
|
|
131
|
+
governed: boolean;
|
|
132
|
+
/** The rules whose conditions held: the deny that refused it, or the allow(s) that permitted it. */
|
|
133
|
+
matched: readonly string[];
|
|
134
|
+
/** Applicable allow rules whose conditions did not hold, with the first condition that failed. */
|
|
135
|
+
unmet: readonly {
|
|
136
|
+
rule: string;
|
|
137
|
+
condition: string;
|
|
138
|
+
}[];
|
|
139
|
+
policyVersion: string;
|
|
140
|
+
reason: string;
|
|
141
|
+
/** AuthBoundry decisions made for delegation conditions. */
|
|
142
|
+
/**
|
|
143
|
+
* `authorityMode`: how the decision was evaluated (evidence only; FK-16), null when it was not evaluated.
|
|
144
|
+
* `reason`: why a refusal was refused (e.g. per-agent delegation not installed vs. an unregistered agent).
|
|
145
|
+
*/
|
|
146
|
+
delegations: readonly {
|
|
147
|
+
capability: string;
|
|
148
|
+
onBehalfOf: string;
|
|
149
|
+
allowed: boolean;
|
|
150
|
+
decisionId: string | null;
|
|
151
|
+
delegationId: string | null;
|
|
152
|
+
authorityMode: import("./runtime/authority-contract.js").AuthorityMode | null;
|
|
153
|
+
reason?: string;
|
|
154
|
+
}[];
|
|
155
|
+
/** Whether this allow must be recorded durably. */
|
|
156
|
+
durable: boolean;
|
|
157
|
+
}
|
|
158
|
+
/** Validate a rule's shape (declaration time, and before a managed version is stored). Throws CONFIGURATION. */
|
|
159
|
+
export declare function checkPolicyRule(rule: {
|
|
160
|
+
id?: unknown;
|
|
161
|
+
effect?: unknown;
|
|
162
|
+
functions?: unknown;
|
|
163
|
+
when?: unknown;
|
|
164
|
+
resource?: unknown;
|
|
165
|
+
principals?: unknown;
|
|
166
|
+
}, where: string): void;
|
|
167
|
+
/** A short, stable text for a condition (decision evidence and diagnostics). */
|
|
168
|
+
export declare function describeCondition(condition: PolicyCondition): string;
|
|
169
|
+
/**
|
|
170
|
+
* Evaluate the policy set for one call. Never throws for a refusal: returns the decision (the
|
|
171
|
+
* runtime turns a refusal into FORBIDDEN / UNAUTHORIZED). Throws only for an invalid argument the
|
|
172
|
+
* resource needs.
|
|
173
|
+
*/
|
|
174
|
+
export declare function evaluatePolicies(set: PolicySet, request: PolicyRequest): Promise<PolicyDecision>;
|
|
175
|
+
/** A condition with every collection named (as stored and digested): code rules hold definitions. */
|
|
176
|
+
export declare function nameCollections(condition: PolicyCondition): PolicyCondition;
|
|
177
|
+
/** The collections a condition reads through `via` (validated against the application). */
|
|
178
|
+
export declare function viaCollections(condition: PolicyCondition): Array<CollectionDefinition | string>;
|
|
179
|
+
export {};
|
package/dist/policy.js
ADDED
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Declarative, input- and resource-aware application policy: `app.policy(rule)` and managed
|
|
3
|
+
* policies (versioned in FeltDB, changed without a redeploy).
|
|
4
|
+
*
|
|
5
|
+
* A policy is data: who (principal types, roles), what (functions), which resource (a record loaded
|
|
6
|
+
* by an argument, through the call's own reader), and when (conditions on the resource, the input,
|
|
7
|
+
* the caller's tenant role, and an agent's delegation). It is evaluated deterministically at the one
|
|
8
|
+
* execution boundary every interface goes through (HTTP, AppPort, MCP, agents, jobs, approved
|
|
9
|
+
* actions), after the role check, argument validation and declared ownership, before the
|
|
10
|
+
* application's `authorize` hook. Every layer must allow.
|
|
11
|
+
*
|
|
12
|
+
* Semantics (fixed, documented, tested):
|
|
13
|
+
* - A rule applies to a call when it names the function and the caller matches `principals`.
|
|
14
|
+
* - Deny overrides: an applicable deny rule whose conditions all hold refuses the call.
|
|
15
|
+
* - A function named by at least one allow rule is governed: it runs only if an applicable allow
|
|
16
|
+
* rule's conditions all hold. Otherwise it is refused (deny by default), naming why.
|
|
17
|
+
* - A function no policy names is not decided here (roles, ownership and the hook still apply).
|
|
18
|
+
* - A condition that cannot be evaluated (no resource, a missing field, an unavailable authority)
|
|
19
|
+
* does not hold: it never allows, and a deny rule that depends on it does not apply. So an
|
|
20
|
+
* unavailable authority refuses a delegated call rather than allowing it.
|
|
21
|
+
*
|
|
22
|
+
* Deterministic: no model is consulted. A delegation condition asks AuthBoundry (the owner of
|
|
23
|
+
* delegated authority), whose evaluation is itself deterministic; its decision id is evidence.
|
|
24
|
+
*
|
|
25
|
+
* Runtime-neutral (no Node APIs): the AppBoundry guest imports it.
|
|
26
|
+
*/
|
|
27
|
+
import { FeltKitError } from "./errors.js";
|
|
28
|
+
const KEYS = new Set(["owner", "sharedWith", "field", "arg", "tenantRole", "role", "delegated", "any", "not"]);
|
|
29
|
+
const OPS = ["eq", "ne", "in", "notIn", "lt", "lte", "gt", "gte"];
|
|
30
|
+
/** Validate a rule's shape (declaration time, and before a managed version is stored). Throws CONFIGURATION. */
|
|
31
|
+
export function checkPolicyRule(rule, where) {
|
|
32
|
+
const fail = (message) => {
|
|
33
|
+
throw new FeltKitError("CONFIGURATION", `${where}: ${message}`);
|
|
34
|
+
};
|
|
35
|
+
if (typeof rule.id !== "string" || !/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/.test(rule.id))
|
|
36
|
+
fail("a policy needs an id (letters, digits, . _ : -).");
|
|
37
|
+
if (rule.effect !== "allow" && rule.effect !== "deny")
|
|
38
|
+
fail(`policy ${String(rule.id)}: effect must be "allow" or "deny".`);
|
|
39
|
+
if (!Array.isArray(rule.functions) || rule.functions.length === 0)
|
|
40
|
+
fail(`policy ${String(rule.id)}: functions must name at least one function.`);
|
|
41
|
+
const resource = rule.resource;
|
|
42
|
+
if (resource !== undefined && (typeof resource?.id !== "string" || !resource.id || !resource.collection))
|
|
43
|
+
fail(`policy ${String(rule.id)}: resource needs a collection and the argument holding the record id.`);
|
|
44
|
+
const needsResource = (condition) => {
|
|
45
|
+
if ("owner" in condition || "sharedWith" in condition || "field" in condition)
|
|
46
|
+
return true;
|
|
47
|
+
if ("any" in condition)
|
|
48
|
+
return condition.any.some(needsResource);
|
|
49
|
+
if ("not" in condition)
|
|
50
|
+
return needsResource(condition.not);
|
|
51
|
+
if ("delegated" in condition)
|
|
52
|
+
return "field" in condition.delegated.onBehalfOf;
|
|
53
|
+
return false;
|
|
54
|
+
};
|
|
55
|
+
const check = (condition, path) => {
|
|
56
|
+
if (typeof condition !== "object" || condition === null)
|
|
57
|
+
fail(`policy ${String(rule.id)} ${path}: a condition is an object.`);
|
|
58
|
+
const c = condition;
|
|
59
|
+
const kind = Object.keys(c).find((k) => KEYS.has(k));
|
|
60
|
+
if (!kind)
|
|
61
|
+
fail(`policy ${String(rule.id)} ${path}: unknown condition ${JSON.stringify(condition)} (owner, sharedWith, field, arg, tenantRole, role, delegated, any, not).`);
|
|
62
|
+
if (kind === "any") {
|
|
63
|
+
if (!Array.isArray(c.any) || c.any.length === 0)
|
|
64
|
+
fail(`policy ${String(rule.id)} ${path}: any needs conditions.`);
|
|
65
|
+
c.any.forEach((x, i) => check(x, `${path}.any[${i}]`));
|
|
66
|
+
}
|
|
67
|
+
else if (kind === "not")
|
|
68
|
+
check(c.not, `${path}.not`);
|
|
69
|
+
else if (kind === "owner") {
|
|
70
|
+
if (typeof c.owner !== "string" || !c.owner)
|
|
71
|
+
fail(`policy ${String(rule.id)} ${path}: owner names a field.`);
|
|
72
|
+
const via = c.via;
|
|
73
|
+
if (via !== undefined && (!via || !via.collection || typeof via.field !== "string" || !via.field))
|
|
74
|
+
fail(`policy ${String(rule.id)} ${path}: owner.via is { collection, field }.`);
|
|
75
|
+
}
|
|
76
|
+
else if (kind === "field" || kind === "arg") {
|
|
77
|
+
if (typeof c[kind] !== "string" || !c[kind])
|
|
78
|
+
fail(`policy ${String(rule.id)} ${path}: ${kind} names a property.`);
|
|
79
|
+
if (!OPS.some((op) => op in c))
|
|
80
|
+
fail(`policy ${String(rule.id)} ${path}: ${kind} needs a comparison (${OPS.join(", ")}).`);
|
|
81
|
+
}
|
|
82
|
+
else if (kind === "delegated") {
|
|
83
|
+
const d = c.delegated;
|
|
84
|
+
if (typeof d?.capability !== "string" || !d.capability)
|
|
85
|
+
fail(`policy ${String(rule.id)} ${path}: delegated needs a capability.`);
|
|
86
|
+
const ref = d.onBehalfOf;
|
|
87
|
+
if (!ref || (typeof ref.field !== "string" && typeof ref.arg !== "string"))
|
|
88
|
+
fail(`policy ${String(rule.id)} ${path}: delegated.onBehalfOf is { field, via? } or { arg }.`);
|
|
89
|
+
const via = ref.via;
|
|
90
|
+
if (via !== undefined && (!via || !via.collection || typeof via.field !== "string" || !via.field))
|
|
91
|
+
fail(`policy ${String(rule.id)} ${path}: delegated.onBehalfOf.via is { collection, field }.`);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
const when = rule.when;
|
|
95
|
+
if (when !== undefined) {
|
|
96
|
+
if (!Array.isArray(when))
|
|
97
|
+
fail(`policy ${String(rule.id)}: when is a list of conditions.`);
|
|
98
|
+
when.forEach((c, i) => check(c, `when[${i}]`));
|
|
99
|
+
if (!resource && when.some(needsResource))
|
|
100
|
+
fail(`policy ${String(rule.id)}: a condition on the resource needs \`resource\` (the collection and the argument holding its id).`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
const viaName = (via) => (typeof via.collection === "string" ? via.collection : via.collection.name);
|
|
104
|
+
const viaText = (via) => (via ? ` via ${viaName(via)}.${via.field}` : "");
|
|
105
|
+
/** A short, stable text for a condition (decision evidence and diagnostics). */
|
|
106
|
+
export function describeCondition(condition) {
|
|
107
|
+
if ("owner" in condition)
|
|
108
|
+
return `owner(${condition.owner}${viaText(condition.via)})`;
|
|
109
|
+
if ("sharedWith" in condition)
|
|
110
|
+
return `sharedWith(${condition.sharedWith})`;
|
|
111
|
+
if ("tenantRole" in condition)
|
|
112
|
+
return `tenantRole(${[condition.tenantRole].flat().join("|")})`;
|
|
113
|
+
if ("role" in condition)
|
|
114
|
+
return `role(${[condition.role].flat().join("|")})`;
|
|
115
|
+
if ("delegated" in condition) {
|
|
116
|
+
const ref = condition.delegated.onBehalfOf;
|
|
117
|
+
return `delegated(${condition.delegated.capability} for ${"field" in ref ? `field ${ref.field}${viaText(ref.via)}` : `arg ${ref.arg}`})`;
|
|
118
|
+
}
|
|
119
|
+
if ("any" in condition)
|
|
120
|
+
return `any(${condition.any.map(describeCondition).join(", ")})`;
|
|
121
|
+
if ("not" in condition)
|
|
122
|
+
return `not(${describeCondition(condition.not)})`;
|
|
123
|
+
const subject = "field" in condition ? `field ${condition.field}` : `arg ${condition.arg}`;
|
|
124
|
+
const ops = OPS.filter((op) => op in condition).map((op) => `${op} ${JSON.stringify(condition[op])}`);
|
|
125
|
+
return `${subject} ${ops.join(" ")}`;
|
|
126
|
+
}
|
|
127
|
+
function compares(value, comparison) {
|
|
128
|
+
if (value === undefined)
|
|
129
|
+
return false;
|
|
130
|
+
if ("eq" in comparison && value !== comparison.eq)
|
|
131
|
+
return false;
|
|
132
|
+
if ("ne" in comparison && value === comparison.ne)
|
|
133
|
+
return false;
|
|
134
|
+
if (comparison.in && !comparison.in.includes(value))
|
|
135
|
+
return false;
|
|
136
|
+
if (comparison.notIn && comparison.notIn.includes(value))
|
|
137
|
+
return false;
|
|
138
|
+
for (const op of ["lt", "lte", "gt", "gte"]) {
|
|
139
|
+
const bound = comparison[op];
|
|
140
|
+
if (bound === undefined)
|
|
141
|
+
continue;
|
|
142
|
+
if (typeof value !== "number" || Number.isNaN(value))
|
|
143
|
+
return false;
|
|
144
|
+
if (op === "lt" && !(value < bound))
|
|
145
|
+
return false;
|
|
146
|
+
if (op === "lte" && !(value <= bound))
|
|
147
|
+
return false;
|
|
148
|
+
if (op === "gt" && !(value > bound))
|
|
149
|
+
return false;
|
|
150
|
+
if (op === "gte" && !(value >= bound))
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
155
|
+
function appliesTo(rule, request) {
|
|
156
|
+
if (!rule.functions.includes(request.function))
|
|
157
|
+
return false;
|
|
158
|
+
const who = rule.principals;
|
|
159
|
+
if (!who)
|
|
160
|
+
return true;
|
|
161
|
+
const principal = request.principal;
|
|
162
|
+
if (!principal)
|
|
163
|
+
return who.anonymous === true;
|
|
164
|
+
if (who.types && !who.types.includes(principal.type))
|
|
165
|
+
return false;
|
|
166
|
+
if (who.roles && !who.roles.some((role) => principal.roles.includes(role)))
|
|
167
|
+
return false;
|
|
168
|
+
return true;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Evaluate the policy set for one call. Never throws for a refusal: returns the decision (the
|
|
172
|
+
* runtime turns a refusal into FORBIDDEN / UNAUTHORIZED). Throws only for an invalid argument the
|
|
173
|
+
* resource needs.
|
|
174
|
+
*/
|
|
175
|
+
export async function evaluatePolicies(set, request) {
|
|
176
|
+
const applicable = set.rules.filter((rule) => appliesTo(rule, request));
|
|
177
|
+
const governedByAllow = set.rules.some((rule) => rule.effect === "allow" && rule.functions.includes(request.function));
|
|
178
|
+
const delegations = [];
|
|
179
|
+
const unmet = [];
|
|
180
|
+
const resources = new Map();
|
|
181
|
+
const loadResource = async (rule) => {
|
|
182
|
+
if (!rule.resource)
|
|
183
|
+
return null;
|
|
184
|
+
const id = request.args[rule.resource.id];
|
|
185
|
+
if (typeof id !== "string" || !id)
|
|
186
|
+
throw new FeltKitError("INVALID_ARGUMENT", `${request.function}: ${rule.resource.id} must be a record id (policy ${rule.id}).`);
|
|
187
|
+
const key = `${rule.resource.collection}/${id}`;
|
|
188
|
+
if (!resources.has(key)) {
|
|
189
|
+
const collection = request.collection(rule.resource.collection);
|
|
190
|
+
resources.set(key, collection ? (await request.db.get(collection, id)) : null);
|
|
191
|
+
}
|
|
192
|
+
return resources.get(key);
|
|
193
|
+
};
|
|
194
|
+
// A field's value, or (with `via`) the named field of the record it references; undefined if absent.
|
|
195
|
+
const follow = async (value, via) => {
|
|
196
|
+
if (!via)
|
|
197
|
+
return value;
|
|
198
|
+
if (typeof value !== "string" || !value)
|
|
199
|
+
return undefined;
|
|
200
|
+
const collection = request.collection(typeof via.collection === "string" ? via.collection : via.collection.name);
|
|
201
|
+
const linked = collection ? (await request.db.get(collection, value)) : null;
|
|
202
|
+
return linked ? linked[via.field] : undefined;
|
|
203
|
+
};
|
|
204
|
+
const holds = async (condition, rule, resource) => {
|
|
205
|
+
const principal = request.principal;
|
|
206
|
+
if ("any" in condition) {
|
|
207
|
+
for (const c of condition.any)
|
|
208
|
+
if (await holds(c, rule, resource))
|
|
209
|
+
return true;
|
|
210
|
+
return false;
|
|
211
|
+
}
|
|
212
|
+
if ("not" in condition)
|
|
213
|
+
return !(await holds(condition.not, rule, resource));
|
|
214
|
+
if ("owner" in condition) {
|
|
215
|
+
if (!principal || !resource)
|
|
216
|
+
return false;
|
|
217
|
+
return (await follow(resource[condition.owner], condition.via)) === principal.id;
|
|
218
|
+
}
|
|
219
|
+
if ("sharedWith" in condition) {
|
|
220
|
+
const list = resource?.[condition.sharedWith];
|
|
221
|
+
return Boolean(principal && Array.isArray(list) && list.includes(principal.id));
|
|
222
|
+
}
|
|
223
|
+
if ("tenantRole" in condition)
|
|
224
|
+
return Boolean(principal?.tenant && [condition.tenantRole].flat().includes(principal.tenant.role));
|
|
225
|
+
if ("role" in condition)
|
|
226
|
+
return Boolean(principal && [condition.role].flat().some((role) => principal.roles.includes(role)));
|
|
227
|
+
if ("delegated" in condition) {
|
|
228
|
+
// A person acts with their own authority; delegation is for agents and services.
|
|
229
|
+
if (!principal || principal.type === "user" || !request.delegate)
|
|
230
|
+
return false;
|
|
231
|
+
const ref = condition.delegated.onBehalfOf;
|
|
232
|
+
const person = "field" in ref ? (resource ? await follow(resource[ref.field], ref.via) : undefined) : request.args[ref.arg];
|
|
233
|
+
if (typeof person !== "string" || !person)
|
|
234
|
+
return false;
|
|
235
|
+
let answer;
|
|
236
|
+
try {
|
|
237
|
+
answer = await request.delegate({ capability: condition.delegated.capability, onBehalfOf: person });
|
|
238
|
+
}
|
|
239
|
+
catch {
|
|
240
|
+
answer = { allowed: false, decisionId: null, delegationId: null, authorityMode: null, reason: "authority unavailable" };
|
|
241
|
+
}
|
|
242
|
+
delegations.push({ capability: condition.delegated.capability, onBehalfOf: person, allowed: answer.allowed, decisionId: answer.decisionId, delegationId: answer.delegationId, authorityMode: answer.authorityMode ?? null, ...(!answer.allowed && answer.reason ? { reason: answer.reason } : {}) });
|
|
243
|
+
return answer.allowed;
|
|
244
|
+
}
|
|
245
|
+
if ("field" in condition)
|
|
246
|
+
return Boolean(resource) && compares(resource[condition.field], condition);
|
|
247
|
+
return compares(request.args[condition.arg], condition);
|
|
248
|
+
};
|
|
249
|
+
// Only allow rules report what they lacked: a deny rule that does not apply is not a reason.
|
|
250
|
+
const conditionsHold = async (rule) => {
|
|
251
|
+
const note = (condition) => { if (rule.effect === "allow")
|
|
252
|
+
unmet.push({ rule: rule.id, condition }); };
|
|
253
|
+
const resource = await loadResource(rule);
|
|
254
|
+
if (rule.resource && !resource) {
|
|
255
|
+
note(`resource ${rule.resource.collection} exists`);
|
|
256
|
+
return false;
|
|
257
|
+
}
|
|
258
|
+
for (const condition of rule.when ?? []) {
|
|
259
|
+
if (!(await holds(condition, rule, resource))) {
|
|
260
|
+
note(describeCondition(condition));
|
|
261
|
+
return false;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
return true;
|
|
265
|
+
};
|
|
266
|
+
const base = { policyVersion: set.version, delegations, unmet };
|
|
267
|
+
for (const rule of applicable.filter((r) => r.effect === "deny")) {
|
|
268
|
+
if (await conditionsHold(rule)) {
|
|
269
|
+
return { ...base, allowed: false, governed: true, matched: [rule.id], reason: `Refused by policy ${rule.id}${rule.description ? ` (${rule.description})` : ""}.`, durable: true };
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
if (!governedByAllow)
|
|
273
|
+
return { ...base, allowed: true, governed: false, matched: [], reason: "No policy governs this function.", durable: false };
|
|
274
|
+
const allowed = [];
|
|
275
|
+
for (const rule of applicable.filter((r) => r.effect === "allow")) {
|
|
276
|
+
if (await conditionsHold(rule))
|
|
277
|
+
allowed.push(rule);
|
|
278
|
+
}
|
|
279
|
+
if (allowed.length > 0) {
|
|
280
|
+
return { ...base, allowed: true, governed: true, matched: allowed.map((r) => r.id), reason: `Allowed by policy ${allowed.map((r) => r.id).join(", ")}.`, durable: allowed.some((r) => r.evidence === "durable") };
|
|
281
|
+
}
|
|
282
|
+
const why = unmet.length ? ` Unmet: ${unmet.map((u) => `${u.rule}: ${u.condition}`).join("; ")}.` : " No allow policy applies to this caller.";
|
|
283
|
+
return { ...base, allowed: false, governed: true, matched: [], reason: `No policy allows ${request.function} for this caller.${why}`, durable: true };
|
|
284
|
+
}
|
|
285
|
+
/** A condition with every collection named (as stored and digested): code rules hold definitions. */
|
|
286
|
+
export function nameCollections(condition) {
|
|
287
|
+
if ("any" in condition)
|
|
288
|
+
return { any: condition.any.map(nameCollections) };
|
|
289
|
+
if ("not" in condition)
|
|
290
|
+
return { not: nameCollections(condition.not) };
|
|
291
|
+
if ("owner" in condition && condition.via)
|
|
292
|
+
return { owner: condition.owner, via: { collection: viaName(condition.via), field: condition.via.field } };
|
|
293
|
+
if ("delegated" in condition && "field" in condition.delegated.onBehalfOf && condition.delegated.onBehalfOf.via) {
|
|
294
|
+
const ref = condition.delegated.onBehalfOf;
|
|
295
|
+
return { delegated: { capability: condition.delegated.capability, onBehalfOf: { field: ref.field, via: { collection: viaName(ref.via), field: ref.via.field } } } };
|
|
296
|
+
}
|
|
297
|
+
return condition;
|
|
298
|
+
}
|
|
299
|
+
/** The collections a condition reads through `via` (validated against the application). */
|
|
300
|
+
export function viaCollections(condition) {
|
|
301
|
+
if ("any" in condition)
|
|
302
|
+
return condition.any.flatMap(viaCollections);
|
|
303
|
+
if ("not" in condition)
|
|
304
|
+
return viaCollections(condition.not);
|
|
305
|
+
if ("owner" in condition && condition.via)
|
|
306
|
+
return [condition.via.collection];
|
|
307
|
+
if ("delegated" in condition && "field" in condition.delegated.onBehalfOf && condition.delegated.onBehalfOf.via)
|
|
308
|
+
return [condition.delegated.onBehalfOf.via.collection];
|
|
309
|
+
return [];
|
|
310
|
+
}
|
|
311
|
+
//# sourceMappingURL=policy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy.js","sourceRoot":"","sources":["../src/policy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AA+G3C,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;AAC/G,MAAM,GAAG,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,CAAU,CAAC;AAE3E,gHAAgH;AAChH,MAAM,UAAU,eAAe,CAAC,IAAuH,EAAE,KAAa;IACpK,MAAM,IAAI,GAAG,CAAC,OAAe,EAAS,EAAE;QACtC,MAAM,IAAI,YAAY,CAAC,eAAe,EAAE,GAAG,KAAK,KAAK,OAAO,EAAE,CAAC,CAAC;IAClE,CAAC,CAAC;IACF,IAAI,OAAO,IAAI,CAAC,EAAE,KAAK,QAAQ,IAAI,CAAC,qCAAqC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QAAE,IAAI,CAAC,kDAAkD,CAAC,CAAC;IAClJ,IAAI,IAAI,CAAC,MAAM,KAAK,OAAO,IAAI,IAAI,CAAC,MAAM,KAAK,MAAM;QAAE,IAAI,CAAC,UAAU,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,qCAAqC,CAAC,CAAC;IAC5H,IAAI,CAAC,KAAK,CAAC,O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ChH,MAAM,GAAG,GAAG,SAAS,CAAC,SAAS,CAAC,UAAU,CAAC;QAC3C,OAAO,EAAE,SAAS,EAAE,EAAE,UAAU,EAAE,SAAS,CAAC,SAAS,CAAC,UAAU,EAAE,UAAU,EAAE,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,UAAU,EAAE,OAAO,CAAC,GAAG,CAAC,GAAI,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,GAAI,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE,CAAC;IACxK,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,2FAA2F;AAC3F,MAAM,UAAU,cAAc,CAAC,SAA0B;IACvD,IAAI,KAAK,IAAI,SAAS;QAAE,OAAO,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;IACrE,IAAI,KAAK,IAAI,SAAS;QAAE,OAAO,cAAc,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IAC7D,IAAI,OAAO,IAAI,SAAS,IAAI,SAAS,CAAC,GAAG;QAAE,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IAC7E,IAAI,WAAW,IAAI,SAAS,IAAI,OAAO,IAAI,SAAS,CAAC,SAAS,CAAC,UAAU,IAAI,SAAS,CAAC,SAAS,CAAC,UAAU,CAAC,GAAG;QAAE,OAAO,CAAC,SAAS,CAAC,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IACxK,OAAO,EAAE,CAAC;AACZ,CAAC"}
|
|
@@ -61,6 +61,22 @@ export interface ActivityEntry {
|
|
|
61
61
|
allowed: boolean;
|
|
62
62
|
reason?: string;
|
|
63
63
|
};
|
|
64
|
+
/** The policies that governed the call (app.policy / managed): version, rules that held, conditions unmet, delegation decisions. */
|
|
65
|
+
policy?: {
|
|
66
|
+
version: string;
|
|
67
|
+
matched: string[];
|
|
68
|
+
unmet?: {
|
|
69
|
+
rule: string;
|
|
70
|
+
condition: string;
|
|
71
|
+
}[];
|
|
72
|
+
delegations?: {
|
|
73
|
+
capability: string;
|
|
74
|
+
onBehalfOf: string;
|
|
75
|
+
allowed: boolean;
|
|
76
|
+
decisionId: string | null;
|
|
77
|
+
delegationId: string | null;
|
|
78
|
+
}[];
|
|
79
|
+
};
|
|
64
80
|
};
|
|
65
81
|
outcome: "success" | "error" | "denied";
|
|
66
82
|
error?: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"activity.js","sourceRoot":"","sources":["../../src/runtime/activity.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAErD,+DAA+D;AAC/D,MAAM,WAAW,GAAG,GAAG,CAAC;AAGxB,MAAM,CAAC,MAAM,mBAAmB,GAAG,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"activity.js","sourceRoot":"","sources":["../../src/runtime/activity.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAErD,+DAA+D;AAC/D,MAAM,WAAW,GAAG,GAAG,CAAC;AAGxB,MAAM,CAAC,MAAM,mBAAmB,GAAG,mBAAmB,CAAC;AAiEvD,MAAM,OAAO,WAAW;IACb,GAAG,CAAe;IAClB,KAAK,CAA8B;IACnC,OAAO,CAAS;IAChB,UAAU,GAAG,IAAI,GAAG,EAAoB,CAAC;IACzC,SAAS,CAAmD;IACrE,WAAW,GAAG,CAAC,CAAC;IAChB,MAAM,GAAkB,OAAO,CAAC,OAAO,EAAE,CAAC;IAC1C,SAAS,GAA2C,IAAI,CAAC;IACzD;;;;OAIG;IACM,SAAS,GAAwG,EAAE,MAAM,EAAE,CAAC,E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M,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;gBACtD,CAAC;YACH,CAAC;YACD,IAAI,CAAC,WAAW,GAAG,CAAC,CAAC;YACrB,IAAI,CAAC,SAAS,CAAC,YAAY,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;YACvD,IAAI,CAAC,SAAS,CAAC,UAAU,GAAG,IAAI,CAAC;YACjC,OAAO,OAAO,CAAC;QACjB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,SAAS,CAAC,UAAU,GAAG,EAAE,EAAE,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,EAAE,OAAO,EAAG,KAAe,EAAE,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;YAClH,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF;AAED,MAAM,UAAU,YAAY,CAAC,KAAc;IACzC,IAAI,cAAc,CAAC,KAAK,CAAC;QAAE,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC;IAC/E,MAAM,CAAC,GAAG,KAA8C,CAAC;IACzD,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;AAC1I,CAAC"}
|
|
@@ -4,14 +4,17 @@
|
|
|
4
4
|
* as the asking principal and credentials resolved from custody for the one request.
|
|
5
5
|
*/
|
|
6
6
|
import { type AuthorityDecision } from "./authboundry.js";
|
|
7
|
-
import type { ApplicationAuthority } from "./context.js";
|
|
7
|
+
import type { ApplicationAuthority, OnBehalfOf } from "./context.js";
|
|
8
|
+
import type { AuthorityMode } from "./authority-contract.js";
|
|
9
|
+
import type { AgentResolution } from "./local-authority.js";
|
|
8
10
|
export interface AuthorityConfig {
|
|
9
11
|
url?: string | {
|
|
10
12
|
env: string;
|
|
11
13
|
development?: string;
|
|
12
14
|
};
|
|
13
|
-
local?:
|
|
15
|
+
local?: boolean | null | 0 | "" | {
|
|
14
16
|
dataDir?: string;
|
|
17
|
+
agentCallers?: "per-agent" | "executor-grants";
|
|
15
18
|
};
|
|
16
19
|
capabilities?: readonly string[];
|
|
17
20
|
principal?: (id: string) => string;
|
|
@@ -52,17 +55,33 @@ export interface AuthorityHost {
|
|
|
52
55
|
fetch?: typeof fetch;
|
|
53
56
|
/** The local authority's address while it runs (authority.local), used when no url resolves. */
|
|
54
57
|
localUrl?: () => Promise<string | null>;
|
|
58
|
+
/** The local authority's state (authority.local): a failed start is lasting until the application restarts. */
|
|
59
|
+
localState?: () => string;
|
|
55
60
|
/** A person's grants (authority.local). */
|
|
56
61
|
grants?: ApplicationAuthority["grants"];
|
|
57
|
-
/**
|
|
62
|
+
/** The application's agents (authority.local). */
|
|
63
|
+
agents?: ApplicationAuthority["agents"];
|
|
64
|
+
/** Who decides: the executor, an agent as itself, or a refusal; and how it is evaluated (runtime/local-authority.ts agentDecision). */
|
|
65
|
+
agentFor?: (requested: string | undefined) => Promise<AgentResolution>;
|
|
66
|
+
/** Records each decision (never a credential) as evidence, with how it was evaluated. */
|
|
58
67
|
record?: (entry: {
|
|
59
68
|
capability: string;
|
|
60
69
|
executor: string;
|
|
61
70
|
onBehalfOf: string | null;
|
|
62
71
|
decision: AuthorityDecision;
|
|
63
72
|
durationMs: number;
|
|
73
|
+
authorityMode: AuthorityMode | null;
|
|
64
74
|
}) => void | Promise<void>;
|
|
65
75
|
}
|
|
76
|
+
/** The AuthBoundry principal of an application principal (a person): `principal(id)` from the config, else `user:<id>`. */
|
|
77
|
+
export declare function authorityPrincipalOf(config: Pick<AuthorityConfig, "principal">, id: string): string;
|
|
78
|
+
/**
|
|
79
|
+
* The AuthBoundry principal `onBehalfOf` names, or null when it is malformed. A string with a ":" is
|
|
80
|
+
* already an AuthBoundry principal (`<type>:<id>`, e.g. `user:ada`) and is sent unchanged, so callers
|
|
81
|
+
* that map it themselves keep working; one without is an application principal id, mapped as
|
|
82
|
+
* `ctx.authority.grants` maps the delegator. `{ person }` and `{ principal }` say which explicitly.
|
|
83
|
+
*/
|
|
84
|
+
export declare function onBehalfOfPrincipal(config: Pick<AuthorityConfig, "principal">, value: OnBehalfOf): string | null;
|
|
66
85
|
/** Where the private authority's executor keeps its agent credential (authority.local; FeltKit custody, never a record). */
|
|
67
86
|
export declare const LOCAL_AGENT_REF = "credential-ref:authboundry-local-agent";
|
|
68
87
|
/** The configured AuthBoundry origin, or why there is none. Production never uses a development default. */
|