@devfellowship/access 0.1.0 → 0.2.1
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 +22 -0
- package/capabilities.json +223 -4
- package/db-surface.json +3 -2
- package/dist/bindings.d.ts +61 -0
- package/dist/bindings.js +88 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +2 -0
- package/dist/rules.generated.d.ts +14 -0
- package/dist/rules.generated.js +101 -0
- package/package.json +1 -1
- package/runtime.pin.json +2 -2
package/README.md
CHANGED
|
@@ -62,6 +62,28 @@ const decision = decideWrite(canInput, {
|
|
|
62
62
|
- **Fail closed.** A table input with no source, an absent or mistyped input, an evaluator error, no matching row, a COLLECT table, or an outcome that is not `allow`/`deny`/`ask` gives `deny` with a `reason`.
|
|
63
63
|
- `test/fixtures/task_create_points.dmn.json` is the pilot rule as a test fixture. The rule file itself lands in `dfl-flows-definitions` with the pilot (S2-T6).
|
|
64
64
|
|
|
65
|
+
## Rule bindings and the vendored rules (S2-T6)
|
|
66
|
+
|
|
67
|
+
`src/bindings.ts` says which capability runs which rule, with which inputs, where. The pilot (parent ADR-13, Q5 = A):
|
|
68
|
+
|
|
69
|
+
| capability | rule (manifest key) | inputs | scope |
|
|
70
|
+
|---|---|---|---|
|
|
71
|
+
| `work.task.create` | `task_create_points` | `role` from the verified caller (`verifiedRoleOf(iam.is_global_admin())`: `admin` or `member`), `points` from the body | the Smoke Lab business unit `SMOKE_LAB_WORK_BUSINESS_UNIT_ID` only |
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
import { bindingApplies, evaluateRule, ruleBindingOf, ruleRefOf, verifiedRoleOf } from "@devfellowship/access";
|
|
75
|
+
|
|
76
|
+
const binding = ruleBindingOf("work.task.create");
|
|
77
|
+
if (binding && bindingApplies(binding, { business_unit_id })) {
|
|
78
|
+
const d = evaluateRule({ rule: ruleRefOf("work.task.create")!, verified: { role: verifiedRoleOf(isAdmin) }, body });
|
|
79
|
+
// d.outcome: allow | ask (d.output.approver_role) | deny; d.decided_by: rule:<path>@<version>
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
The rule file is not fetched at run time. `scripts/vendor-rules.mjs <dfl-flows-definitions checkout>` copies each bound rule, at the commit of `runtime.pin.json` (`definitions.commit`), into `src/rules.generated.ts` with its version (the engine `dmnFileVersion`, the 7-char git blob id). CI (`access-package / corpus`) runs it with `--check` on the pinned checkout. A new binding: add the key to `VENDORED_KEYS`, re-pin the definitions commit, re-generate. The catalog entry of the capability names the same key (`rule`), from `COMMANDS` in `scripts/catalog-lib.mjs`; `test/bindings.test.mjs` checks that both agree.
|
|
84
|
+
|
|
85
|
+
IAM "Try it" (S4-T6B) runs the same binding: `POST /v1/access/explain` with a rule input evaluates `ruleRefOf(capability)` with the verified role of the subject and the given `points`.
|
|
86
|
+
|
|
65
87
|
## The capability catalog (S2-T2)
|
|
66
88
|
|
|
67
89
|
`capabilities.json` lists one capability name per MCP tool: `<domain>.<entity>.<verb>` (tool `work.create_task` -> `work.task.create`). The domain is the MCP host, the verb is the first word of the tool name, the entity is the rest. It ships in the package. `dfl-os-commands` reads it (`ACCESS_CATALOG_PATH`, or `<package>/capabilities.json`) for the IAM read endpoints (`catalog.available`).
|
package/capabilities.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "
|
|
2
|
+
"version": "861-beeea001",
|
|
3
3
|
"capabilities": [
|
|
4
4
|
{
|
|
5
5
|
"name": "academy.lessons.delete",
|
|
@@ -2620,6 +2620,18 @@
|
|
|
2620
2620
|
"table": "campaigns.company_profiles",
|
|
2621
2621
|
"relation": "table"
|
|
2622
2622
|
},
|
|
2623
|
+
{
|
|
2624
|
+
"name": "campaigns.contact.erase",
|
|
2625
|
+
"domain": "campaigns",
|
|
2626
|
+
"domain_group": "marketing",
|
|
2627
|
+
"kind": "tool",
|
|
2628
|
+
"mode": "write",
|
|
2629
|
+
"rule": null,
|
|
2630
|
+
"doors": [
|
|
2631
|
+
"mcp"
|
|
2632
|
+
],
|
|
2633
|
+
"tool": "campaigns.erase_contact"
|
|
2634
|
+
},
|
|
2623
2635
|
{
|
|
2624
2636
|
"name": "campaigns.contact.get",
|
|
2625
2637
|
"domain": "campaigns",
|
|
@@ -3512,6 +3524,18 @@
|
|
|
3512
3524
|
],
|
|
3513
3525
|
"tool": "campaigns.update_hypothesis"
|
|
3514
3526
|
},
|
|
3527
|
+
{
|
|
3528
|
+
"name": "campaigns.hypothesis_status.update",
|
|
3529
|
+
"domain": "campaigns",
|
|
3530
|
+
"domain_group": "marketing",
|
|
3531
|
+
"kind": "tool",
|
|
3532
|
+
"mode": "write",
|
|
3533
|
+
"rule": null,
|
|
3534
|
+
"doors": [
|
|
3535
|
+
"mcp"
|
|
3536
|
+
],
|
|
3537
|
+
"tool": "campaigns.update_hypothesis_status"
|
|
3538
|
+
},
|
|
3515
3539
|
{
|
|
3516
3540
|
"name": "campaigns.idea_source.create",
|
|
3517
3541
|
"domain": "campaigns",
|
|
@@ -6942,6 +6966,150 @@
|
|
|
6942
6966
|
],
|
|
6943
6967
|
"tool": "engineering.link_epic_to_plan"
|
|
6944
6968
|
},
|
|
6969
|
+
{
|
|
6970
|
+
"name": "engineering.flow.get",
|
|
6971
|
+
"domain": "engineering",
|
|
6972
|
+
"domain_group": "engineering",
|
|
6973
|
+
"kind": "tool",
|
|
6974
|
+
"mode": "read",
|
|
6975
|
+
"rule": null,
|
|
6976
|
+
"doors": [
|
|
6977
|
+
"mcp"
|
|
6978
|
+
],
|
|
6979
|
+
"tool": "engineering.get_flow"
|
|
6980
|
+
},
|
|
6981
|
+
{
|
|
6982
|
+
"name": "engineering.flow_heatmap.get",
|
|
6983
|
+
"domain": "engineering",
|
|
6984
|
+
"domain_group": "engineering",
|
|
6985
|
+
"kind": "tool",
|
|
6986
|
+
"mode": "read",
|
|
6987
|
+
"rule": null,
|
|
6988
|
+
"doors": [
|
|
6989
|
+
"mcp"
|
|
6990
|
+
],
|
|
6991
|
+
"tool": "engineering.get_flow_heatmap"
|
|
6992
|
+
},
|
|
6993
|
+
{
|
|
6994
|
+
"name": "engineering.flow_projections.audit",
|
|
6995
|
+
"domain": "engineering",
|
|
6996
|
+
"domain_group": "engineering",
|
|
6997
|
+
"kind": "tool",
|
|
6998
|
+
"mode": "read",
|
|
6999
|
+
"rule": null,
|
|
7000
|
+
"doors": [
|
|
7001
|
+
"mcp"
|
|
7002
|
+
],
|
|
7003
|
+
"tool": "engineering.audit_flow_projections"
|
|
7004
|
+
},
|
|
7005
|
+
{
|
|
7006
|
+
"name": "engineering.flow_run.create",
|
|
7007
|
+
"domain": "engineering",
|
|
7008
|
+
"domain_group": "engineering",
|
|
7009
|
+
"kind": "tool",
|
|
7010
|
+
"mode": "write",
|
|
7011
|
+
"rule": null,
|
|
7012
|
+
"doors": [
|
|
7013
|
+
"mcp"
|
|
7014
|
+
],
|
|
7015
|
+
"tool": "engineering.create_flow_run"
|
|
7016
|
+
},
|
|
7017
|
+
{
|
|
7018
|
+
"name": "engineering.flow_run.get",
|
|
7019
|
+
"domain": "engineering",
|
|
7020
|
+
"domain_group": "engineering",
|
|
7021
|
+
"kind": "tool",
|
|
7022
|
+
"mode": "read",
|
|
7023
|
+
"rule": null,
|
|
7024
|
+
"doors": [
|
|
7025
|
+
"mcp"
|
|
7026
|
+
],
|
|
7027
|
+
"tool": "engineering.get_flow_run"
|
|
7028
|
+
},
|
|
7029
|
+
{
|
|
7030
|
+
"name": "engineering.flow_run.wait",
|
|
7031
|
+
"domain": "engineering",
|
|
7032
|
+
"domain_group": "engineering",
|
|
7033
|
+
"kind": "tool",
|
|
7034
|
+
"mode": "read",
|
|
7035
|
+
"rule": null,
|
|
7036
|
+
"doors": [
|
|
7037
|
+
"mcp"
|
|
7038
|
+
],
|
|
7039
|
+
"tool": "engineering.wait_flow_run"
|
|
7040
|
+
},
|
|
7041
|
+
{
|
|
7042
|
+
"name": "engineering.flow_run_by_business_key.get",
|
|
7043
|
+
"domain": "engineering",
|
|
7044
|
+
"domain_group": "engineering",
|
|
7045
|
+
"kind": "tool",
|
|
7046
|
+
"mode": "read",
|
|
7047
|
+
"rule": null,
|
|
7048
|
+
"doors": [
|
|
7049
|
+
"mcp"
|
|
7050
|
+
],
|
|
7051
|
+
"tool": "engineering.get_flow_run_by_business_key"
|
|
7052
|
+
},
|
|
7053
|
+
{
|
|
7054
|
+
"name": "engineering.flow_run_events.list",
|
|
7055
|
+
"domain": "engineering",
|
|
7056
|
+
"domain_group": "engineering",
|
|
7057
|
+
"kind": "tool",
|
|
7058
|
+
"mode": "read",
|
|
7059
|
+
"rule": null,
|
|
7060
|
+
"doors": [
|
|
7061
|
+
"mcp"
|
|
7062
|
+
],
|
|
7063
|
+
"tool": "engineering.list_flow_run_events"
|
|
7064
|
+
},
|
|
7065
|
+
{
|
|
7066
|
+
"name": "engineering.flow_run_retry.dispatch",
|
|
7067
|
+
"domain": "engineering",
|
|
7068
|
+
"domain_group": "engineering",
|
|
7069
|
+
"kind": "tool",
|
|
7070
|
+
"mode": "write",
|
|
7071
|
+
"rule": null,
|
|
7072
|
+
"doors": [
|
|
7073
|
+
"mcp"
|
|
7074
|
+
],
|
|
7075
|
+
"tool": "engineering.dispatch_flow_run_retry"
|
|
7076
|
+
},
|
|
7077
|
+
{
|
|
7078
|
+
"name": "engineering.flow_runs.list",
|
|
7079
|
+
"domain": "engineering",
|
|
7080
|
+
"domain_group": "engineering",
|
|
7081
|
+
"kind": "tool",
|
|
7082
|
+
"mode": "read",
|
|
7083
|
+
"rule": null,
|
|
7084
|
+
"doors": [
|
|
7085
|
+
"mcp"
|
|
7086
|
+
],
|
|
7087
|
+
"tool": "engineering.list_flow_runs"
|
|
7088
|
+
},
|
|
7089
|
+
{
|
|
7090
|
+
"name": "engineering.flow_usage_report.get",
|
|
7091
|
+
"domain": "engineering",
|
|
7092
|
+
"domain_group": "engineering",
|
|
7093
|
+
"kind": "tool",
|
|
7094
|
+
"mode": "read",
|
|
7095
|
+
"rule": null,
|
|
7096
|
+
"doors": [
|
|
7097
|
+
"mcp"
|
|
7098
|
+
],
|
|
7099
|
+
"tool": "engineering.get_flow_usage_report"
|
|
7100
|
+
},
|
|
7101
|
+
{
|
|
7102
|
+
"name": "engineering.flows.list",
|
|
7103
|
+
"domain": "engineering",
|
|
7104
|
+
"domain_group": "engineering",
|
|
7105
|
+
"kind": "tool",
|
|
7106
|
+
"mode": "read",
|
|
7107
|
+
"rule": null,
|
|
7108
|
+
"doors": [
|
|
7109
|
+
"mcp"
|
|
7110
|
+
],
|
|
7111
|
+
"tool": "engineering.list_flows"
|
|
7112
|
+
},
|
|
6945
7113
|
{
|
|
6946
7114
|
"name": "engineering.handoff_document.get",
|
|
6947
7115
|
"domain": "engineering",
|
|
@@ -7198,6 +7366,18 @@
|
|
|
7198
7366
|
],
|
|
7199
7367
|
"tool": "engineering.record_schema_catalog"
|
|
7200
7368
|
},
|
|
7369
|
+
{
|
|
7370
|
+
"name": "engineering.schema_catalog_snapshot.delete",
|
|
7371
|
+
"domain": "engineering",
|
|
7372
|
+
"domain_group": "engineering",
|
|
7373
|
+
"kind": "tool",
|
|
7374
|
+
"mode": "write",
|
|
7375
|
+
"rule": null,
|
|
7376
|
+
"doors": [
|
|
7377
|
+
"mcp"
|
|
7378
|
+
],
|
|
7379
|
+
"tool": "engineering.delete_schema_catalog_snapshot"
|
|
7380
|
+
},
|
|
7201
7381
|
{
|
|
7202
7382
|
"name": "engineering.schema_catalog_snapshots.delete",
|
|
7203
7383
|
"domain": "engineering",
|
|
@@ -7406,6 +7586,18 @@
|
|
|
7406
7586
|
],
|
|
7407
7587
|
"tool": "engineering.find_similar_table"
|
|
7408
7588
|
},
|
|
7589
|
+
{
|
|
7590
|
+
"name": "engineering.slim_finding.record",
|
|
7591
|
+
"domain": "engineering",
|
|
7592
|
+
"domain_group": "engineering",
|
|
7593
|
+
"kind": "tool",
|
|
7594
|
+
"mode": "write",
|
|
7595
|
+
"rule": null,
|
|
7596
|
+
"doors": [
|
|
7597
|
+
"mcp"
|
|
7598
|
+
],
|
|
7599
|
+
"tool": "engineering.record_slim_finding"
|
|
7600
|
+
},
|
|
7409
7601
|
{
|
|
7410
7602
|
"name": "engineering.spec_run.comment",
|
|
7411
7603
|
"domain": "engineering",
|
|
@@ -11848,6 +12040,18 @@
|
|
|
11848
12040
|
],
|
|
11849
12041
|
"tool": "financing.ingest_hyperliquid_transfers"
|
|
11850
12042
|
},
|
|
12043
|
+
{
|
|
12044
|
+
"name": "financing.ingest_watermark.delete",
|
|
12045
|
+
"domain": "financing",
|
|
12046
|
+
"domain_group": "money",
|
|
12047
|
+
"kind": "tool",
|
|
12048
|
+
"mode": "write",
|
|
12049
|
+
"rule": null,
|
|
12050
|
+
"doors": [
|
|
12051
|
+
"mcp"
|
|
12052
|
+
],
|
|
12053
|
+
"tool": "financing.delete_ingest_watermark"
|
|
12054
|
+
},
|
|
11851
12055
|
{
|
|
11852
12056
|
"name": "financing.journal_entries.list",
|
|
11853
12057
|
"domain": "financing",
|
|
@@ -35479,13 +35683,15 @@
|
|
|
35479
35683
|
"name": "work.task.create",
|
|
35480
35684
|
"domain": "work",
|
|
35481
35685
|
"domain_group": "work",
|
|
35482
|
-
"kind": "
|
|
35686
|
+
"kind": "command",
|
|
35483
35687
|
"mode": "write",
|
|
35484
|
-
"rule":
|
|
35688
|
+
"rule": "task_create_points",
|
|
35485
35689
|
"doors": [
|
|
35690
|
+
"commands",
|
|
35486
35691
|
"mcp"
|
|
35487
35692
|
],
|
|
35488
|
-
"tool": "work.create_task"
|
|
35693
|
+
"tool": "work.create_task",
|
|
35694
|
+
"command": "POST /v1/tasks"
|
|
35489
35695
|
},
|
|
35490
35696
|
{
|
|
35491
35697
|
"name": "work.task.delete",
|
|
@@ -36654,6 +36860,19 @@
|
|
|
36654
36860
|
"table": "workflow_management.outbox_events",
|
|
36655
36861
|
"relation": "table"
|
|
36656
36862
|
},
|
|
36863
|
+
{
|
|
36864
|
+
"name": "workflow_management.pg_cron_jobs_ro.select",
|
|
36865
|
+
"domain": "workflow_management",
|
|
36866
|
+
"domain_group": "engineering",
|
|
36867
|
+
"kind": "table",
|
|
36868
|
+
"mode": "read",
|
|
36869
|
+
"rule": null,
|
|
36870
|
+
"doors": [
|
|
36871
|
+
"rest"
|
|
36872
|
+
],
|
|
36873
|
+
"table": "workflow_management.pg_cron_jobs_ro",
|
|
36874
|
+
"relation": "view"
|
|
36875
|
+
},
|
|
36657
36876
|
{
|
|
36658
36877
|
"name": "workflow_management.policy_registry.delete",
|
|
36659
36878
|
"domain": "workflow_management",
|
package/db-surface.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 1,
|
|
3
3
|
"source": "prod catalog (pg_class, pg_proc) by scripts/db-surface.sql, read-only; edge functions, migration_head and schemas from dfl-schema main",
|
|
4
|
-
"migration_head": "
|
|
4
|
+
"migration_head": "20261118201734",
|
|
5
5
|
"schemas": [
|
|
6
6
|
"academy",
|
|
7
7
|
"apps",
|
|
@@ -542,7 +542,8 @@
|
|
|
542
542
|
"work.project_stats",
|
|
543
543
|
"work.tools",
|
|
544
544
|
"work.transactions",
|
|
545
|
-
"work.v_epic_metrics"
|
|
545
|
+
"work.v_epic_metrics",
|
|
546
|
+
"workflow_management.pg_cron_jobs_ro"
|
|
546
547
|
],
|
|
547
548
|
"rpc": {
|
|
548
549
|
"apps.is_latest_deploy": "read",
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rule bindings: which capability runs which rule, with which inputs, where (S2-T6).
|
|
3
|
+
*
|
|
4
|
+
* A binding is the second level of a write (parent plan "Two levels on a write"): after the
|
|
5
|
+
* grant, the command evaluates the bound rule with `evaluateRule`. The rule file is a copy of
|
|
6
|
+
* dfl-flows-definitions at the pinned commit (src/rules.generated.ts), so the command, the
|
|
7
|
+
* gateway (S3) and IAM "Try it" (S4-T6B, `POST /v1/access/explain` with a rule input) run the
|
|
8
|
+
* same table at the same version, in their own process, without the engine on the hot path.
|
|
9
|
+
*
|
|
10
|
+
* The pilot binding (parent ADR-13, Q5 = A): `work.task.create` runs `task_create_points`.
|
|
11
|
+
* - input `role`: from the VERIFIED context only (`verifiedRoleOf`), never from the body;
|
|
12
|
+
* - input `points`: from the request body, a number;
|
|
13
|
+
* - scope: the Smoke Lab business unit only (Tainan, Q5 note: "a ideia aqui é apenas provar
|
|
14
|
+
* o ponto. essa rule nao será usada"). Outside the scope the binding does not apply.
|
|
15
|
+
*
|
|
16
|
+
* Pure: no I/O.
|
|
17
|
+
*/
|
|
18
|
+
import type { InputSource, RuleRef } from "./rule.js";
|
|
19
|
+
/** The rule key of the pilot (dfl-flows-definitions `policies/manifest.json`). */
|
|
20
|
+
export declare const TASK_CREATE_POINTS = "task_create_points";
|
|
21
|
+
/**
|
|
22
|
+
* The Smoke Lab business unit of the work domain (`public.business_units`, the table that
|
|
23
|
+
* `work.projects.business_unit_id` points at; tags smoke-lab, test, do-not-use). A test unit:
|
|
24
|
+
* real work never goes in it. Its strategy twin is `strategy.business_units`
|
|
25
|
+
* d32d7385-ae90-4e50-98f4-ac7f8cccb4bf (the CLAUDE_SMOKE fixture).
|
|
26
|
+
*/
|
|
27
|
+
export declare const SMOKE_LAB_WORK_BUSINESS_UNIT_ID = "4835b42f-f9c2-451c-bce7-502cce7dac49";
|
|
28
|
+
/** The role that the rule input `role` takes: from the verified caller, never from the body. */
|
|
29
|
+
export type VerifiedRole = "admin" | "member";
|
|
30
|
+
/** `admin` when the caller is a global admin (IAM level >= 80, `iam.is_global_admin()`), else `member`. */
|
|
31
|
+
export declare function verifiedRoleOf(isGlobalAdmin: boolean): VerifiedRole;
|
|
32
|
+
export interface RuleBinding {
|
|
33
|
+
/** The capability of the catalog, for example `work.task.create`. */
|
|
34
|
+
capability: string;
|
|
35
|
+
/** The manifest key of the rule. */
|
|
36
|
+
rule_key: string;
|
|
37
|
+
/** One source per input of the decision table (RuleRef.inputs). */
|
|
38
|
+
inputs: Readonly<Record<string, InputSource>>;
|
|
39
|
+
/**
|
|
40
|
+
* Where the binding applies. `business_unit_ids`: only a target in one of these business
|
|
41
|
+
* units. null: everywhere.
|
|
42
|
+
*/
|
|
43
|
+
scope: {
|
|
44
|
+
business_unit_ids: readonly string[];
|
|
45
|
+
} | null;
|
|
46
|
+
/** The role that approves an `ask` when the rule output names none. */
|
|
47
|
+
default_approver_role: string;
|
|
48
|
+
}
|
|
49
|
+
export declare const RULE_BINDINGS: Readonly<Record<string, RuleBinding>>;
|
|
50
|
+
/** The binding of a capability, or null when the capability has no rule. */
|
|
51
|
+
export declare function ruleBindingOf(capability: string): RuleBinding | null;
|
|
52
|
+
/** Does the binding apply to this target? A scoped binding needs a business unit in its list. */
|
|
53
|
+
export declare function bindingApplies(binding: RuleBinding, target: {
|
|
54
|
+
business_unit_id?: string | null;
|
|
55
|
+
}): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* The RuleRef of a capability (the vendored table plus the binding inputs), or null when the
|
|
58
|
+
* capability has no binding. Throws when a binding names a rule that is not vendored: a build
|
|
59
|
+
* error, never a silent allow.
|
|
60
|
+
*/
|
|
61
|
+
export declare function ruleRefOf(capability: string): RuleRef | null;
|
package/dist/bindings.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rule bindings: which capability runs which rule, with which inputs, where (S2-T6).
|
|
3
|
+
*
|
|
4
|
+
* A binding is the second level of a write (parent plan "Two levels on a write"): after the
|
|
5
|
+
* grant, the command evaluates the bound rule with `evaluateRule`. The rule file is a copy of
|
|
6
|
+
* dfl-flows-definitions at the pinned commit (src/rules.generated.ts), so the command, the
|
|
7
|
+
* gateway (S3) and IAM "Try it" (S4-T6B, `POST /v1/access/explain` with a rule input) run the
|
|
8
|
+
* same table at the same version, in their own process, without the engine on the hot path.
|
|
9
|
+
*
|
|
10
|
+
* The pilot binding (parent ADR-13, Q5 = A): `work.task.create` runs `task_create_points`.
|
|
11
|
+
* - input `role`: from the VERIFIED context only (`verifiedRoleOf`), never from the body;
|
|
12
|
+
* - input `points`: from the request body, a number;
|
|
13
|
+
* - scope: the Smoke Lab business unit only (Tainan, Q5 note: "a ideia aqui é apenas provar
|
|
14
|
+
* o ponto. essa rule nao será usada"). Outside the scope the binding does not apply.
|
|
15
|
+
*
|
|
16
|
+
* Pure: no I/O.
|
|
17
|
+
*/
|
|
18
|
+
import { VENDORED_RULES } from "./rules.generated.js";
|
|
19
|
+
/** The rule key of the pilot (dfl-flows-definitions `policies/manifest.json`). */
|
|
20
|
+
export const TASK_CREATE_POINTS = "task_create_points";
|
|
21
|
+
/**
|
|
22
|
+
* The Smoke Lab business unit of the work domain (`public.business_units`, the table that
|
|
23
|
+
* `work.projects.business_unit_id` points at; tags smoke-lab, test, do-not-use). A test unit:
|
|
24
|
+
* real work never goes in it. Its strategy twin is `strategy.business_units`
|
|
25
|
+
* d32d7385-ae90-4e50-98f4-ac7f8cccb4bf (the CLAUDE_SMOKE fixture).
|
|
26
|
+
*/
|
|
27
|
+
export const SMOKE_LAB_WORK_BUSINESS_UNIT_ID = "4835b42f-f9c2-451c-bce7-502cce7dac49";
|
|
28
|
+
/** `admin` when the caller is a global admin (IAM level >= 80, `iam.is_global_admin()`), else `member`. */
|
|
29
|
+
export function verifiedRoleOf(isGlobalAdmin) {
|
|
30
|
+
return isGlobalAdmin ? "admin" : "member";
|
|
31
|
+
}
|
|
32
|
+
export const RULE_BINDINGS = Object.freeze({
|
|
33
|
+
"work.task.create": Object.freeze({
|
|
34
|
+
capability: "work.task.create",
|
|
35
|
+
rule_key: TASK_CREATE_POINTS,
|
|
36
|
+
inputs: Object.freeze({
|
|
37
|
+
role: Object.freeze({
|
|
38
|
+
from: "verified",
|
|
39
|
+
path: "role",
|
|
40
|
+
type: "string",
|
|
41
|
+
}),
|
|
42
|
+
points: Object.freeze({
|
|
43
|
+
from: "body",
|
|
44
|
+
path: "points",
|
|
45
|
+
type: "number",
|
|
46
|
+
}),
|
|
47
|
+
}),
|
|
48
|
+
scope: Object.freeze({
|
|
49
|
+
business_unit_ids: Object.freeze([SMOKE_LAB_WORK_BUSINESS_UNIT_ID]),
|
|
50
|
+
}),
|
|
51
|
+
default_approver_role: "admin",
|
|
52
|
+
}),
|
|
53
|
+
});
|
|
54
|
+
/** The binding of a capability, or null when the capability has no rule. */
|
|
55
|
+
export function ruleBindingOf(capability) {
|
|
56
|
+
return Object.hasOwn(RULE_BINDINGS, capability)
|
|
57
|
+
? (RULE_BINDINGS[capability] ?? null)
|
|
58
|
+
: null;
|
|
59
|
+
}
|
|
60
|
+
/** Does the binding apply to this target? A scoped binding needs a business unit in its list. */
|
|
61
|
+
export function bindingApplies(binding, target) {
|
|
62
|
+
if (!binding.scope)
|
|
63
|
+
return true;
|
|
64
|
+
const bu = target.business_unit_id?.toLowerCase() ?? null;
|
|
65
|
+
return bu !== null && binding.scope.business_unit_ids.includes(bu);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The RuleRef of a capability (the vendored table plus the binding inputs), or null when the
|
|
69
|
+
* capability has no binding. Throws when a binding names a rule that is not vendored: a build
|
|
70
|
+
* error, never a silent allow.
|
|
71
|
+
*/
|
|
72
|
+
export function ruleRefOf(capability) {
|
|
73
|
+
const binding = ruleBindingOf(capability);
|
|
74
|
+
if (!binding)
|
|
75
|
+
return null;
|
|
76
|
+
const rule = Object.hasOwn(VENDORED_RULES, binding.rule_key)
|
|
77
|
+
? VENDORED_RULES[binding.rule_key]
|
|
78
|
+
: undefined;
|
|
79
|
+
if (!rule)
|
|
80
|
+
throw new Error(`binding ${capability} names rule '${binding.rule_key}', which is not vendored`);
|
|
81
|
+
return {
|
|
82
|
+
path: rule.path,
|
|
83
|
+
version: rule.version,
|
|
84
|
+
definition: rule.definition,
|
|
85
|
+
decision_id: rule.decision_id,
|
|
86
|
+
inputs: binding.inputs,
|
|
87
|
+
};
|
|
88
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export type { RuleBinding, VerifiedRole } from "./bindings.js";
|
|
2
|
+
export { bindingApplies, RULE_BINDINGS, ruleBindingOf, ruleRefOf, SMOKE_LAB_WORK_BUSINESS_UNIT_ID, TASK_CREATE_POINTS, verifiedRoleOf, } from "./bindings.js";
|
|
1
3
|
export { can, linesOf, MAX_OWNER_DEPTH, matchingLines } from "./can.js";
|
|
2
4
|
export { isValidCapability, isValidCapabilityPattern, matchesCapability, } from "./capability.js";
|
|
3
5
|
export { isLineActive, matchesScope } from "./line.js";
|
|
@@ -5,6 +7,8 @@ export type { ActorRow, ActorType, OwnerResolution, PrincipalReads, ResolvedPrin
|
|
|
5
7
|
export { resolvePrincipal } from "./principal.js";
|
|
6
8
|
export type { InputSource, RuleDecision, RuleReason, RuleRef, RuleRequest, VerifiedContext, WriteDecision, } from "./rule.js";
|
|
7
9
|
export { buildRuleInput, decideWrite, evaluateRule } from "./rule.js";
|
|
10
|
+
export type { VendoredRule } from "./rules.generated.js";
|
|
11
|
+
export { RULES_COMMIT, VENDORED_RULES } from "./rules.generated.js";
|
|
8
12
|
export type { DecisionTable, DmnDefinition, DmnResult, HitPolicy, InputClause, MatchedRule, OutputClause, } from "./runtime.js";
|
|
9
13
|
export { DmnError, evaluateDefinition } from "./runtime.js";
|
|
10
14
|
export type { CanInput, Decision, DecisionReason, Effect, Instant, Outcome, PermissionLine, Principal, ScopeKind, Target, } from "./types.js";
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
export { bindingApplies, RULE_BINDINGS, ruleBindingOf, ruleRefOf, SMOKE_LAB_WORK_BUSINESS_UNIT_ID, TASK_CREATE_POINTS, verifiedRoleOf, } from "./bindings.js";
|
|
1
2
|
export { can, linesOf, MAX_OWNER_DEPTH, matchingLines } from "./can.js";
|
|
2
3
|
export { isValidCapability, isValidCapabilityPattern, matchesCapability, } from "./capability.js";
|
|
3
4
|
export { isLineActive, matchesScope } from "./line.js";
|
|
4
5
|
export { resolvePrincipal } from "./principal.js";
|
|
5
6
|
export { buildRuleInput, decideWrite, evaluateRule } from "./rule.js";
|
|
7
|
+
export { RULES_COMMIT, VENDORED_RULES } from "./rules.generated.js";
|
|
6
8
|
export { DmnError, evaluateDefinition } from "./runtime.js";
|
|
@@ -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
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devfellowship/access",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
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
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
package/runtime.pin.json
CHANGED