@devfellowship/access 0.0.0-stage → 0.2.0
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/README.md +152 -2
- package/capabilities.json +37309 -0
- package/db-surface.json +920 -0
- package/dist/bindings.d.ts +61 -0
- package/dist/bindings.js +88 -0
- package/dist/can.d.ts +25 -0
- package/dist/can.js +113 -0
- package/dist/capability.d.ts +20 -0
- package/dist/capability.js +51 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +8 -0
- package/dist/line.d.ts +22 -0
- package/dist/line.js +46 -0
- package/dist/principal.d.ts +49 -0
- package/dist/principal.js +73 -0
- package/dist/rule.d.ts +103 -0
- package/dist/rule.js +191 -0
- package/dist/rules.generated.d.ts +14 -0
- package/dist/rules.generated.js +101 -0
- package/dist/runtime.d.ts +20 -0
- package/dist/runtime.js +19 -0
- package/dist/types.d.ts +86 -0
- package/dist/types.js +8 -0
- package/package.json +63 -5
- package/parity.json +663 -0
- package/runtime.pin.json +26 -0
package/dist/rule.d.ts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Level 2 of a write: the rule (parent plan ADR-5, ADR-16; S2-T3).
|
|
3
|
+
*
|
|
4
|
+
* A rule is a decision table of dfl-flows-definitions (`policies/**.dmn.json`).
|
|
5
|
+
* Its output field `outcome` says `allow`, `deny` or `ask`.
|
|
6
|
+
*
|
|
7
|
+
* The inputs of a rule come ONLY from two sources, named per input in the
|
|
8
|
+
* rule binding (`RuleRef.inputs`):
|
|
9
|
+
* - `verified`: the context that the caller built from the verified token and
|
|
10
|
+
* from rows it read with the user's own token (for example the global role);
|
|
11
|
+
* - `body`: the request body.
|
|
12
|
+
* A body field is read only when the binding names it with `from: "body"`.
|
|
13
|
+
* A `role` (or any other field) that the client puts in the body is ignored
|
|
14
|
+
* when the binding reads that input from `verified` (fixes parent F22).
|
|
15
|
+
*
|
|
16
|
+
* Fail closed: a missing binding, a missing or mistyped input, an evaluation
|
|
17
|
+
* error, no matching rule, or an output that is not `allow`/`deny`/`ask`
|
|
18
|
+
* gives `deny` (parent F23: no rule match must never mean "no objection").
|
|
19
|
+
*
|
|
20
|
+
* Pure: no I/O, no clock read, no input mutation.
|
|
21
|
+
*/
|
|
22
|
+
import { type DmnDefinition } from "./runtime.js";
|
|
23
|
+
import type { CanInput, Decision, Outcome } from "./types.js";
|
|
24
|
+
/** Where one rule input comes from. */
|
|
25
|
+
export interface InputSource {
|
|
26
|
+
from: "verified" | "body";
|
|
27
|
+
/** A dotted path in the source, for example `role` or `task.points`. */
|
|
28
|
+
path: string;
|
|
29
|
+
/** When set, a value of another type is refused (deny). */
|
|
30
|
+
type?: "string" | "number" | "boolean";
|
|
31
|
+
}
|
|
32
|
+
/** One rule, as the caller loaded it from dfl-flows-definitions at a pinned commit. */
|
|
33
|
+
export interface RuleRef {
|
|
34
|
+
/** Repo path of the rule file, for example `policies/work/task_create_points.dmn.json`. */
|
|
35
|
+
path: string;
|
|
36
|
+
/** The file version: the short git blob id (the engine loader `dmnFileVersion`). */
|
|
37
|
+
version: string;
|
|
38
|
+
definition: DmnDefinition;
|
|
39
|
+
decision_id: string;
|
|
40
|
+
/** One source per input expression of the decision table. A table input without a source: deny. */
|
|
41
|
+
inputs: Readonly<Record<string, InputSource>>;
|
|
42
|
+
/** The output field that holds the outcome. Default `outcome`. */
|
|
43
|
+
outcome_field?: string;
|
|
44
|
+
}
|
|
45
|
+
/** What the caller knows from the verified token and from rows read with the user's token. */
|
|
46
|
+
export type VerifiedContext = Readonly<Record<string, unknown>>;
|
|
47
|
+
export interface RuleRequest {
|
|
48
|
+
rule: RuleRef;
|
|
49
|
+
verified: VerifiedContext;
|
|
50
|
+
/** The request body, as the client sent it. Untrusted. */
|
|
51
|
+
body: unknown;
|
|
52
|
+
}
|
|
53
|
+
export type RuleReason =
|
|
54
|
+
/** The matched rule row gave this outcome. */
|
|
55
|
+
"rule_allow" | "rule_deny" | "rule_ask"
|
|
56
|
+
/** No rule row matched: deny. */
|
|
57
|
+
| "rule_no_match"
|
|
58
|
+
/** A table input has no source in the binding: deny. */
|
|
59
|
+
| "rule_binding_invalid"
|
|
60
|
+
/** A bound input is absent or has the wrong type: deny. */
|
|
61
|
+
| "rule_input_invalid"
|
|
62
|
+
/** The evaluator threw: deny. */
|
|
63
|
+
| "rule_error"
|
|
64
|
+
/** The output is not one of allow/deny/ask, or the table is not single-hit: deny. */
|
|
65
|
+
| "rule_output_invalid";
|
|
66
|
+
export interface RuleDecision {
|
|
67
|
+
outcome: Outcome;
|
|
68
|
+
/** `rule:<path>@<version>` (parent ADR-7), also on a fail-closed deny. */
|
|
69
|
+
decided_by: string;
|
|
70
|
+
reason: RuleReason;
|
|
71
|
+
/** The id of the matched rule row, when one matched. */
|
|
72
|
+
rule_row?: string;
|
|
73
|
+
/** The full output of the matched row (for example `approver_role` on ask). */
|
|
74
|
+
output?: Record<string, unknown>;
|
|
75
|
+
/** The input the table saw. Built from the binding only. */
|
|
76
|
+
input?: Record<string, unknown>;
|
|
77
|
+
/** Why a fail-closed deny happened, for the log. */
|
|
78
|
+
detail?: string;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Build the input of the decision table from the binding only.
|
|
82
|
+
* Throws `RuleInputError` when a table input has no source, or a bound value
|
|
83
|
+
* is absent or has the wrong type (an `optional` table input may be absent: null).
|
|
84
|
+
*/
|
|
85
|
+
export declare function buildRuleInput(request: RuleRequest): Record<string, unknown>;
|
|
86
|
+
/** Evaluate one rule. Never throws: every failure is a deny with a reason. */
|
|
87
|
+
export declare function evaluateRule(request: RuleRequest): RuleDecision;
|
|
88
|
+
export interface WriteDecision {
|
|
89
|
+
outcome: Outcome;
|
|
90
|
+
/** The value for `mcp_tool_calls.decided_by`: the stricter level; the rule on a tie. */
|
|
91
|
+
decided_by: string | null;
|
|
92
|
+
/** Level 1: the grant. */
|
|
93
|
+
grant: Decision;
|
|
94
|
+
/** Level 2: the rule. Absent when the grant denied or the write has no rule. */
|
|
95
|
+
rule?: RuleDecision;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* The two levels of a write (parent plan "Two levels on a write"):
|
|
99
|
+
* 1. the grant, `can()`; a deny stops here (the rule is not evaluated);
|
|
100
|
+
* 2. the rule, when the write has one.
|
|
101
|
+
* The stricter outcome wins: deny over ask over allow.
|
|
102
|
+
*/
|
|
103
|
+
export declare function decideWrite(grant: CanInput, rule?: RuleRequest): WriteDecision;
|
package/dist/rule.js
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Level 2 of a write: the rule (parent plan ADR-5, ADR-16; S2-T3).
|
|
3
|
+
*
|
|
4
|
+
* A rule is a decision table of dfl-flows-definitions (`policies/**.dmn.json`).
|
|
5
|
+
* Its output field `outcome` says `allow`, `deny` or `ask`.
|
|
6
|
+
*
|
|
7
|
+
* The inputs of a rule come ONLY from two sources, named per input in the
|
|
8
|
+
* rule binding (`RuleRef.inputs`):
|
|
9
|
+
* - `verified`: the context that the caller built from the verified token and
|
|
10
|
+
* from rows it read with the user's own token (for example the global role);
|
|
11
|
+
* - `body`: the request body.
|
|
12
|
+
* A body field is read only when the binding names it with `from: "body"`.
|
|
13
|
+
* A `role` (or any other field) that the client puts in the body is ignored
|
|
14
|
+
* when the binding reads that input from `verified` (fixes parent F22).
|
|
15
|
+
*
|
|
16
|
+
* Fail closed: a missing binding, a missing or mistyped input, an evaluation
|
|
17
|
+
* error, no matching rule, or an output that is not `allow`/`deny`/`ask`
|
|
18
|
+
* gives `deny` (parent F23: no rule match must never mean "no objection").
|
|
19
|
+
*
|
|
20
|
+
* Pure: no I/O, no clock read, no input mutation.
|
|
21
|
+
*/
|
|
22
|
+
import { can } from "./can.js";
|
|
23
|
+
import { evaluateDefinition } from "./runtime.js";
|
|
24
|
+
const OUTCOMES = new Set(["allow", "deny", "ask"]);
|
|
25
|
+
const RANK = { allow: 0, ask: 1, deny: 2 };
|
|
26
|
+
function isRecord(value) {
|
|
27
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
28
|
+
}
|
|
29
|
+
/** Own properties only: a path never reaches `__proto__`, `constructor` or a prototype field. */
|
|
30
|
+
function readPath(source, path) {
|
|
31
|
+
let current = source;
|
|
32
|
+
for (const part of path.split(".")) {
|
|
33
|
+
if (!isRecord(current) || !Object.hasOwn(current, part))
|
|
34
|
+
return undefined;
|
|
35
|
+
current = current[part];
|
|
36
|
+
}
|
|
37
|
+
return current;
|
|
38
|
+
}
|
|
39
|
+
function writePath(target, path, value) {
|
|
40
|
+
const parts = path.split(".");
|
|
41
|
+
let current = target;
|
|
42
|
+
for (const part of parts.slice(0, -1)) {
|
|
43
|
+
const next = Object.hasOwn(current, part) ? current[part] : undefined;
|
|
44
|
+
if (isRecord(next)) {
|
|
45
|
+
current = next;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
const created = {};
|
|
49
|
+
current[part] = created;
|
|
50
|
+
current = created;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
current[parts[parts.length - 1]] = value;
|
|
54
|
+
}
|
|
55
|
+
class RuleInputError extends Error {
|
|
56
|
+
reason;
|
|
57
|
+
constructor(reason, message) {
|
|
58
|
+
super(message);
|
|
59
|
+
this.reason = reason;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Build the input of the decision table from the binding only.
|
|
64
|
+
* Throws `RuleInputError` when a table input has no source, or a bound value
|
|
65
|
+
* is absent or has the wrong type (an `optional` table input may be absent: null).
|
|
66
|
+
*/
|
|
67
|
+
export function buildRuleInput(request) {
|
|
68
|
+
const { rule, verified, body } = request;
|
|
69
|
+
const decision = rule.definition.decisions.find((d) => d.id === rule.decision_id);
|
|
70
|
+
if (!decision) {
|
|
71
|
+
throw new RuleInputError("rule_binding_invalid", `decision '${rule.decision_id}' is not in ${rule.path}`);
|
|
72
|
+
}
|
|
73
|
+
const input = {};
|
|
74
|
+
for (const clause of decision.decision_table.inputs) {
|
|
75
|
+
const expression = clause.expression.trim();
|
|
76
|
+
const source = Object.hasOwn(rule.inputs, expression)
|
|
77
|
+
? rule.inputs[expression]
|
|
78
|
+
: undefined;
|
|
79
|
+
if (!source || (source.from !== "verified" && source.from !== "body")) {
|
|
80
|
+
throw new RuleInputError("rule_binding_invalid", `input '${expression}' has no source`);
|
|
81
|
+
}
|
|
82
|
+
const raw = readPath(source.from === "verified" ? verified : body, source.path);
|
|
83
|
+
if (raw === undefined || raw === null) {
|
|
84
|
+
if (clause.optional === true) {
|
|
85
|
+
writePath(input, expression, null);
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
throw new RuleInputError("rule_input_invalid", `input '${expression}' (${source.from}.${source.path}) is absent`);
|
|
89
|
+
}
|
|
90
|
+
if (source.type && typeof raw !== source.type) {
|
|
91
|
+
throw new RuleInputError("rule_input_invalid", `input '${expression}' (${source.from}.${source.path}) is not a ${source.type}`);
|
|
92
|
+
}
|
|
93
|
+
if (source.type === "number" && !Number.isFinite(raw)) {
|
|
94
|
+
throw new RuleInputError("rule_input_invalid", `input '${expression}' (${source.from}.${source.path}) is not a finite number`);
|
|
95
|
+
}
|
|
96
|
+
writePath(input, expression, raw);
|
|
97
|
+
}
|
|
98
|
+
return input;
|
|
99
|
+
}
|
|
100
|
+
/** Evaluate one rule. Never throws: every failure is a deny with a reason. */
|
|
101
|
+
export function evaluateRule(request) {
|
|
102
|
+
const { rule } = request;
|
|
103
|
+
const decided_by = `rule:${rule.path}@${rule.version}`;
|
|
104
|
+
let input;
|
|
105
|
+
try {
|
|
106
|
+
input = buildRuleInput(request);
|
|
107
|
+
}
|
|
108
|
+
catch (e) {
|
|
109
|
+
if (e instanceof RuleInputError) {
|
|
110
|
+
return {
|
|
111
|
+
outcome: "deny",
|
|
112
|
+
decided_by,
|
|
113
|
+
reason: e.reason,
|
|
114
|
+
detail: e.message,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
outcome: "deny",
|
|
119
|
+
decided_by,
|
|
120
|
+
reason: "rule_error",
|
|
121
|
+
detail: String(e),
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
let result;
|
|
125
|
+
try {
|
|
126
|
+
result = evaluateDefinition(rule.definition, rule.decision_id, input);
|
|
127
|
+
}
|
|
128
|
+
catch (e) {
|
|
129
|
+
return {
|
|
130
|
+
outcome: "deny",
|
|
131
|
+
decided_by,
|
|
132
|
+
reason: "rule_error",
|
|
133
|
+
input,
|
|
134
|
+
detail: e instanceof Error ? e.message : String(e),
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
if (!isRecord(result.output)) {
|
|
138
|
+
return {
|
|
139
|
+
outcome: "deny",
|
|
140
|
+
decided_by,
|
|
141
|
+
reason: "rule_output_invalid",
|
|
142
|
+
input,
|
|
143
|
+
detail: "an access rule must use hit policy FIRST or UNIQUE",
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
const row = result.matched_rules[0];
|
|
147
|
+
if (!row) {
|
|
148
|
+
return { outcome: "deny", decided_by, reason: "rule_no_match", input };
|
|
149
|
+
}
|
|
150
|
+
const value = result.output[rule.outcome_field ?? "outcome"];
|
|
151
|
+
if (typeof value !== "string" || !OUTCOMES.has(value)) {
|
|
152
|
+
return {
|
|
153
|
+
outcome: "deny",
|
|
154
|
+
decided_by,
|
|
155
|
+
reason: "rule_output_invalid",
|
|
156
|
+
rule_row: row.rule_id,
|
|
157
|
+
output: result.output,
|
|
158
|
+
input,
|
|
159
|
+
detail: `output '${rule.outcome_field ?? "outcome"}' is ${JSON.stringify(value)}`,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
const outcome = value;
|
|
163
|
+
return {
|
|
164
|
+
outcome,
|
|
165
|
+
decided_by,
|
|
166
|
+
reason: `rule_${outcome}`,
|
|
167
|
+
rule_row: row.rule_id,
|
|
168
|
+
output: result.output,
|
|
169
|
+
input,
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* The two levels of a write (parent plan "Two levels on a write"):
|
|
174
|
+
* 1. the grant, `can()`; a deny stops here (the rule is not evaluated);
|
|
175
|
+
* 2. the rule, when the write has one.
|
|
176
|
+
* The stricter outcome wins: deny over ask over allow.
|
|
177
|
+
*/
|
|
178
|
+
export function decideWrite(grant, rule) {
|
|
179
|
+
const g = can(grant);
|
|
180
|
+
if (g.outcome === "deny" || !rule) {
|
|
181
|
+
return { outcome: g.outcome, decided_by: g.decided_by, grant: g };
|
|
182
|
+
}
|
|
183
|
+
const r = evaluateRule(rule);
|
|
184
|
+
const ruleWins = RANK[r.outcome] >= RANK[g.outcome];
|
|
185
|
+
return {
|
|
186
|
+
outcome: ruleWins ? r.outcome : g.outcome,
|
|
187
|
+
decided_by: ruleWins ? r.decided_by : g.decided_by,
|
|
188
|
+
grant: g,
|
|
189
|
+
rule: r,
|
|
190
|
+
};
|
|
191
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { DmnDefinition } from "./runtime.js";
|
|
2
|
+
export interface VendoredRule {
|
|
3
|
+
/** The manifest key (policies/manifest.json), for example `task_create_points`. */
|
|
4
|
+
key: string;
|
|
5
|
+
/** The repo path of the rule file. */
|
|
6
|
+
path: string;
|
|
7
|
+
decision_id: string;
|
|
8
|
+
/** The engine `dmnFileVersion` of the file: 7 hex chars of its git blob SHA-1. */
|
|
9
|
+
version: string;
|
|
10
|
+
definition: DmnDefinition;
|
|
11
|
+
}
|
|
12
|
+
/** The definitions commit the rules come from (runtime.pin.json `definitions.commit`). */
|
|
13
|
+
export declare const RULES_COMMIT = "07e257fd43160f44c9d784de0db64d961977e2c9";
|
|
14
|
+
export declare const VENDORED_RULES: Readonly<Record<string, VendoredRule>>;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/** The definitions commit the rules come from (runtime.pin.json `definitions.commit`). */
|
|
2
|
+
export const RULES_COMMIT = "07e257fd43160f44c9d784de0db64d961977e2c9";
|
|
3
|
+
export const VENDORED_RULES = {
|
|
4
|
+
"task_create_points": {
|
|
5
|
+
"key": "task_create_points",
|
|
6
|
+
"path": "policies/work/task_create_points.dmn.json",
|
|
7
|
+
"decision_id": "task_create_points",
|
|
8
|
+
"version": "d8aa81c",
|
|
9
|
+
"definition": {
|
|
10
|
+
"id": "dmn_task_create_points",
|
|
11
|
+
"name": "Task Create Points Policy",
|
|
12
|
+
"namespace": "https://dfl.dev/dmn/policies/work",
|
|
13
|
+
"decisions": [
|
|
14
|
+
{
|
|
15
|
+
"id": "task_create_points",
|
|
16
|
+
"name": "Task Create Points",
|
|
17
|
+
"decision_table": {
|
|
18
|
+
"id": "dt_task_create_points",
|
|
19
|
+
"name": "Task Create Points Table",
|
|
20
|
+
"hit_policy": "FIRST",
|
|
21
|
+
"inputs": [
|
|
22
|
+
{
|
|
23
|
+
"id": "input_role",
|
|
24
|
+
"label": "Caller global role (verified)",
|
|
25
|
+
"expression": "role",
|
|
26
|
+
"type_ref": "string"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"id": "input_points",
|
|
30
|
+
"label": "Points of the new task (body)",
|
|
31
|
+
"expression": "points",
|
|
32
|
+
"type_ref": "number"
|
|
33
|
+
}
|
|
34
|
+
],
|
|
35
|
+
"outputs": [
|
|
36
|
+
{
|
|
37
|
+
"id": "output_outcome",
|
|
38
|
+
"label": "Outcome",
|
|
39
|
+
"name": "outcome",
|
|
40
|
+
"type_ref": "string"
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"id": "output_approver_role",
|
|
44
|
+
"label": "Approver role",
|
|
45
|
+
"name": "approver_role",
|
|
46
|
+
"type_ref": "string"
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
"id": "output_reason",
|
|
50
|
+
"label": "Reason",
|
|
51
|
+
"name": "reason",
|
|
52
|
+
"type_ref": "string"
|
|
53
|
+
}
|
|
54
|
+
],
|
|
55
|
+
"rules": [
|
|
56
|
+
{
|
|
57
|
+
"id": "rule_admin_free",
|
|
58
|
+
"input_entries": [
|
|
59
|
+
"\"admin\"",
|
|
60
|
+
"-"
|
|
61
|
+
],
|
|
62
|
+
"output_entries": [
|
|
63
|
+
"allow",
|
|
64
|
+
null,
|
|
65
|
+
"Admins create any task"
|
|
66
|
+
],
|
|
67
|
+
"description": "Admins are free"
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
"id": "rule_up_to_30",
|
|
71
|
+
"input_entries": [
|
|
72
|
+
"-",
|
|
73
|
+
"<= 30"
|
|
74
|
+
],
|
|
75
|
+
"output_entries": [
|
|
76
|
+
"allow",
|
|
77
|
+
null,
|
|
78
|
+
"Up to 30 points is free"
|
|
79
|
+
],
|
|
80
|
+
"description": "Up to 30 points: allow"
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
"id": "rule_above_30",
|
|
84
|
+
"input_entries": [
|
|
85
|
+
"-",
|
|
86
|
+
"> 30"
|
|
87
|
+
],
|
|
88
|
+
"output_entries": [
|
|
89
|
+
"ask",
|
|
90
|
+
"admin",
|
|
91
|
+
"Above 30 points: an admin approves"
|
|
92
|
+
],
|
|
93
|
+
"description": "Above 30 points: ask an admin"
|
|
94
|
+
}
|
|
95
|
+
]
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
]
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The pinned decision runtime (S2-T3, parent ADR-16).
|
|
3
|
+
*
|
|
4
|
+
* The one S-FEEL evaluator of the fleet is `@devfellowship/dmn`
|
|
5
|
+
* (dfl-flows-engine `packages/dmn`). The engine run path and the
|
|
6
|
+
* dfl-flows-definitions CI (`dmn-runner`) use the same package, so this
|
|
7
|
+
* package, the engine and the definitions CI evaluate a table the same way.
|
|
8
|
+
*
|
|
9
|
+
* The plan first said "copy `dfl-flows-engine/ts/src/engine/dmn` by SHA until
|
|
10
|
+
* the Flows master ships the runtime as a package". The package exists
|
|
11
|
+
* (`@devfellowship/dmn@0.1.0`, plan 20261111-flows-engine-criticals C3), and
|
|
12
|
+
* the engine directory is now only a re-export of it. So the pin is the exact
|
|
13
|
+
* npm version plus the record in `runtime.pin.json` (tarball integrity and the
|
|
14
|
+
* SHA-256 of each installed `dist` file). `test/pin.test.mjs` fails when the
|
|
15
|
+
* installed files differ from that record. Re-pin: README "Re-pin the runtime".
|
|
16
|
+
*
|
|
17
|
+
* This file is the only import of the runtime in this package.
|
|
18
|
+
*/
|
|
19
|
+
export type { DecisionTable, DmnDefinition, DmnResult, HitPolicy, InputClause, MatchedRule, OutputClause, } from "@devfellowship/dmn";
|
|
20
|
+
export { DmnError, evaluateDefinition } from "@devfellowship/dmn";
|
package/dist/runtime.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The pinned decision runtime (S2-T3, parent ADR-16).
|
|
3
|
+
*
|
|
4
|
+
* The one S-FEEL evaluator of the fleet is `@devfellowship/dmn`
|
|
5
|
+
* (dfl-flows-engine `packages/dmn`). The engine run path and the
|
|
6
|
+
* dfl-flows-definitions CI (`dmn-runner`) use the same package, so this
|
|
7
|
+
* package, the engine and the definitions CI evaluate a table the same way.
|
|
8
|
+
*
|
|
9
|
+
* The plan first said "copy `dfl-flows-engine/ts/src/engine/dmn` by SHA until
|
|
10
|
+
* the Flows master ships the runtime as a package". The package exists
|
|
11
|
+
* (`@devfellowship/dmn@0.1.0`, plan 20261111-flows-engine-criticals C3), and
|
|
12
|
+
* the engine directory is now only a re-export of it. So the pin is the exact
|
|
13
|
+
* npm version plus the record in `runtime.pin.json` (tarball integrity and the
|
|
14
|
+
* SHA-256 of each installed `dist` file). `test/pin.test.mjs` fails when the
|
|
15
|
+
* installed files differ from that record. Re-pin: README "Re-pin the runtime".
|
|
16
|
+
*
|
|
17
|
+
* This file is the only import of the runtime in this package.
|
|
18
|
+
*/
|
|
19
|
+
export { DmnError, evaluateDefinition } from "@devfellowship/dmn";
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types of the fleet access decision.
|
|
3
|
+
*
|
|
4
|
+
* A `PermissionLine` mirrors one row of `iam.permissions` (dfl-schema
|
|
5
|
+
* `20261116160200_iam_permissions.sql`). The caller reads the rows with the
|
|
6
|
+
* user's own token and passes them in; this package does no I/O.
|
|
7
|
+
*/
|
|
8
|
+
/** The effect of one permission line. Deny wins over ask; ask wins over allow. */
|
|
9
|
+
export type Effect = "allow" | "deny" | "ask";
|
|
10
|
+
/** Where a line applies: everywhere, in one business unit, or on one item. */
|
|
11
|
+
export type ScopeKind = "all" | "business_unit" | "item";
|
|
12
|
+
/** A timestamp as Postgres/PostgREST returns it (ISO string) or as a Date. */
|
|
13
|
+
export type Instant = string | Date;
|
|
14
|
+
/** One row of `iam.permissions`. Extra columns are allowed and ignored. */
|
|
15
|
+
export interface PermissionLine {
|
|
16
|
+
id: string;
|
|
17
|
+
/** A person, an agent or a service (`public.actors.id`). */
|
|
18
|
+
principal_actor_id?: string | null;
|
|
19
|
+
/** A role bundle line (`iam.roles.id`). */
|
|
20
|
+
principal_role_id?: string | null;
|
|
21
|
+
effect: Effect;
|
|
22
|
+
/** An exact capability (`work.task.create`) or a pattern (`work.*`). */
|
|
23
|
+
capability: string;
|
|
24
|
+
scope_kind: ScopeKind;
|
|
25
|
+
/** Required when `scope_kind` is not `all`. */
|
|
26
|
+
scope_id?: string | null;
|
|
27
|
+
/** A line at or after this instant is ignored. Null: no expiry. */
|
|
28
|
+
expires_at?: Instant | null;
|
|
29
|
+
/** A revoked line is ignored. A revoke keeps the row for history. */
|
|
30
|
+
revoked_at?: Instant | null;
|
|
31
|
+
}
|
|
32
|
+
/** Who asks. An agent always carries its owner. */
|
|
33
|
+
export interface Principal {
|
|
34
|
+
actor_id: string;
|
|
35
|
+
kind: "person" | "agent" | "service";
|
|
36
|
+
/** The role bundles of the principal (`iam.roles.id`). */
|
|
37
|
+
role_ids?: readonly string[];
|
|
38
|
+
/** The owner of an agent. Required when `kind` is `agent`. */
|
|
39
|
+
owner?: Principal | null;
|
|
40
|
+
}
|
|
41
|
+
/** What the request touches. Pass both ids when an item lives in a business unit. */
|
|
42
|
+
export interface Target {
|
|
43
|
+
business_unit_id?: string | null;
|
|
44
|
+
item_id?: string | null;
|
|
45
|
+
}
|
|
46
|
+
export type Outcome = "allow" | "deny" | "ask";
|
|
47
|
+
export type DecisionReason =
|
|
48
|
+
/** A deny line matched. */
|
|
49
|
+
"deny_line"
|
|
50
|
+
/** An ask line matched and no deny line did. */
|
|
51
|
+
| "ask_line"
|
|
52
|
+
/** An allow line matched and no deny or ask line did. */
|
|
53
|
+
| "allow_line"
|
|
54
|
+
/** No active line matched: default deny. */
|
|
55
|
+
| "no_match"
|
|
56
|
+
/** An agent was limited by its owner's decision. */
|
|
57
|
+
| "owner_cap"
|
|
58
|
+
/** An agent came without an owner: deny. */
|
|
59
|
+
| "owner_missing"
|
|
60
|
+
/** The owner chain is longer than `MAX_OWNER_DEPTH`: deny. */
|
|
61
|
+
| "owner_depth_exceeded"
|
|
62
|
+
/** The requested capability is not a valid name: deny. */
|
|
63
|
+
| "invalid_capability";
|
|
64
|
+
export interface Decision {
|
|
65
|
+
outcome: Outcome;
|
|
66
|
+
/**
|
|
67
|
+
* The value for `mcp_tool_calls.decided_by` (parent ADR-7):
|
|
68
|
+
* `permission:<uuid>`, `owner_cap`, or null when no line decided (default deny).
|
|
69
|
+
*/
|
|
70
|
+
decided_by: string | null;
|
|
71
|
+
reason: DecisionReason;
|
|
72
|
+
/** The line that decided, when one did. */
|
|
73
|
+
line?: PermissionLine;
|
|
74
|
+
/** For an agent: the decision of its owner, which capped it. */
|
|
75
|
+
owner?: Decision;
|
|
76
|
+
}
|
|
77
|
+
export interface CanInput {
|
|
78
|
+
principal: Principal;
|
|
79
|
+
/** An exact capability name, for example `work.task.create`. */
|
|
80
|
+
capability: string;
|
|
81
|
+
target?: Target;
|
|
82
|
+
/** The permission lines of the principal, its roles, and (for an agent) its owner chain. */
|
|
83
|
+
lines: readonly PermissionLine[];
|
|
84
|
+
/** The decision instant. Passed in, so the function stays pure. */
|
|
85
|
+
now: Date;
|
|
86
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types of the fleet access decision.
|
|
3
|
+
*
|
|
4
|
+
* A `PermissionLine` mirrors one row of `iam.permissions` (dfl-schema
|
|
5
|
+
* `20261116160200_iam_permissions.sql`). The caller reads the rows with the
|
|
6
|
+
* user's own token and passes them in; this package does no I/O.
|
|
7
|
+
*/
|
|
8
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,64 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@devfellowship/access",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "The one fleet access decision: can() over iam.permissions lines (deny wins, capability patterns, scope, expiry, agent never above its owner). Pure functions, no I/O.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./capabilities.json": "./capabilities.json",
|
|
14
|
+
"./parity.json": "./parity.json",
|
|
15
|
+
"./package.json": "./package.json"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"README.md",
|
|
20
|
+
"runtime.pin.json",
|
|
21
|
+
"capabilities.json",
|
|
22
|
+
"db-surface.json",
|
|
23
|
+
"parity.json"
|
|
24
|
+
],
|
|
25
|
+
"sideEffects": false,
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=18"
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "rm -rf dist && tsc -p tsconfig.json",
|
|
31
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
32
|
+
"test": "npm run build && node --test test/*.test.mjs",
|
|
33
|
+
"lint": "biome check src test scripts package.json tsconfig.json runtime.pin.json",
|
|
34
|
+
"test:corpus": "node scripts/corpus.mjs",
|
|
35
|
+
"pin:runtime": "node scripts/pin-runtime.mjs",
|
|
36
|
+
"catalog": "node scripts/build-catalog.mjs",
|
|
37
|
+
"catalog:check": "node scripts/build-catalog.mjs --check",
|
|
38
|
+
"db-surface": "node scripts/refresh-db-surface.mjs"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@biomejs/biome": "^2.6.8",
|
|
42
|
+
"js-yaml": "4.1.0",
|
|
43
|
+
"typescript": "^5.7.2"
|
|
44
|
+
},
|
|
45
|
+
"keywords": [
|
|
46
|
+
"authorization",
|
|
47
|
+
"access",
|
|
48
|
+
"permissions",
|
|
49
|
+
"devfellowship"
|
|
50
|
+
],
|
|
51
|
+
"repository": {
|
|
52
|
+
"type": "git",
|
|
53
|
+
"url": "git+https://github.com/devfellowship/dfl-services.git",
|
|
54
|
+
"directory": "packages/access"
|
|
55
|
+
},
|
|
56
|
+
"publishConfig": {
|
|
57
|
+
"access": "public",
|
|
58
|
+
"registry": "https://registry.npmjs.org/"
|
|
59
|
+
},
|
|
60
|
+
"license": "MIT",
|
|
61
|
+
"dependencies": {
|
|
62
|
+
"@devfellowship/dmn": "0.1.0"
|
|
63
|
+
}
|
|
64
|
+
}
|