@devfellowship/access 0.2.1 → 0.3.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/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": "20261118201734",
4
+ "migration_head": "20261122204500",
5
5
  "schemas": [
6
6
  "academy",
7
7
  "apps",
@@ -19,6 +19,7 @@
19
19
  "payments",
20
20
  "proposals",
21
21
  "public",
22
+ "quiz",
22
23
  "review_request",
23
24
  "skill_evals",
24
25
  "social_proof",
@@ -112,6 +113,7 @@
112
113
  "documents.signer",
113
114
  "documents.template",
114
115
  "documents.template_variable",
116
+ "engineering.github_refresh_tokens",
115
117
  "engineering.merge_challenges",
116
118
  "engineering.schema_catalog_snapshots",
117
119
  "engineering.ux_map_annotations",
@@ -307,6 +309,12 @@
307
309
  "public.tools",
308
310
  "public.transactions",
309
311
  "public.world_objects",
312
+ "quiz.answers",
313
+ "quiz.interview_dispatch",
314
+ "quiz.options",
315
+ "quiz.questions",
316
+ "quiz.quizzes",
317
+ "quiz.responses",
310
318
  "review_request.assessment_answers",
311
319
  "review_request.assessment_item_bindings",
312
320
  "review_request.assessment_items",
@@ -344,6 +352,8 @@
344
352
  "strategy.channels",
345
353
  "strategy.channels_history",
346
354
  "strategy.competitor_ads",
355
+ "strategy.competitor_changes",
356
+ "strategy.competitor_keywords",
347
357
  "strategy.competitor_ratings",
348
358
  "strategy.competitors",
349
359
  "strategy.competitors_history",
@@ -360,6 +370,7 @@
360
370
  "strategy.empathy_maps",
361
371
  "strategy.empathy_maps_history",
362
372
  "strategy.entities",
373
+ "strategy.entity_channels",
363
374
  "strategy.entity_events",
364
375
  "strategy.entity_pricing_plans",
365
376
  "strategy.expense_categories",
@@ -370,11 +381,13 @@
370
381
  "strategy.industries",
371
382
  "strategy.insight_curated_links",
372
383
  "strategy.insight_evidence",
384
+ "strategy.intel_runs",
373
385
  "strategy.key_activities",
374
386
  "strategy.key_activities_history",
375
387
  "strategy.key_activity_resources",
376
388
  "strategy.key_partners",
377
389
  "strategy.key_partners_history",
390
+ "strategy.keyword_exploration",
378
391
  "strategy.keyword_metrics",
379
392
  "strategy.keyword_relations",
380
393
  "strategy.keyword_slug_aliases",
@@ -466,6 +479,8 @@
466
479
  "workflow_management.delegated_grants",
467
480
  "workflow_management.outbox_events",
468
481
  "workflow_management.policy_registry",
482
+ "workflow_management.process_links",
483
+ "workflow_management.process_nodes",
469
484
  "workflow_management.proxy_idempotency_cache",
470
485
  "workflow_management.proxy_secret_bindings",
471
486
  "workflow_management.timer_schedules",
@@ -760,6 +775,7 @@
760
775
  "financial.update_updated_at",
761
776
  "financial.wallets_enforce_leaf_account",
762
777
  "financial.wallets_track_binding_change",
778
+ "iam.mcp_oauth_grants_client_token_guard",
763
779
  "key_management.update_updated_at_column",
764
780
  "lesson_studio.guard_project_owner_change",
765
781
  "lesson_studio.update_updated_at_column",
@@ -792,6 +808,7 @@
792
808
  "public.update_phase_timestamp",
793
809
  "public.update_updated_at_column",
794
810
  "public.update_version_before_insert",
811
+ "quiz.touch_interview_dispatch_updated_at",
795
812
  "review_request.set_answer_audit",
796
813
  "review_request.set_created_by",
797
814
  "review_request.set_updated_at",
@@ -895,7 +912,6 @@
895
912
  "dfl-revenue-roll-recurring",
896
913
  "dfl-revenue-spedy-webhook",
897
914
  "dfl-revenue-woovi-webhook",
898
- "dfl-seo-fetch-metrics",
899
915
  "dfl-telemetry-send",
900
916
  "end-impersonate",
901
917
  "env-vars",
package/dist/index.d.ts CHANGED
@@ -4,7 +4,7 @@ export { can, linesOf, MAX_OWNER_DEPTH, matchingLines } from "./can.js";
4
4
  export { isValidCapability, isValidCapabilityPattern, matchesCapability, } from "./capability.js";
5
5
  export { isLineActive, matchesScope } from "./line.js";
6
6
  export type { ActorRow, ActorType, OwnerResolution, PrincipalReads, ResolvedPrincipal, } from "./principal.js";
7
- export { resolvePrincipal } from "./principal.js";
7
+ export { AGENT_ROLE_CAPABILITY_PREFIX, agentRoleOf, resolvePrincipal, } from "./principal.js";
8
8
  export type { InputSource, RuleDecision, RuleReason, RuleRef, RuleRequest, VerifiedContext, WriteDecision, } from "./rule.js";
9
9
  export { buildRuleInput, decideWrite, evaluateRule } from "./rule.js";
10
10
  export type { VendoredRule } from "./rules.generated.js";
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@ export { bindingApplies, RULE_BINDINGS, ruleBindingOf, ruleRefOf, SMOKE_LAB_WORK
2
2
  export { can, linesOf, MAX_OWNER_DEPTH, matchingLines } from "./can.js";
3
3
  export { isValidCapability, isValidCapabilityPattern, matchesCapability, } from "./capability.js";
4
4
  export { isLineActive, matchesScope } from "./line.js";
5
- export { resolvePrincipal } from "./principal.js";
5
+ export { AGENT_ROLE_CAPABILITY_PREFIX, agentRoleOf, resolvePrincipal, } from "./principal.js";
6
6
  export { buildRuleInput, decideWrite, evaluateRule } from "./rule.js";
7
7
  export { RULES_COMMIT, VENDORED_RULES } from "./rules.generated.js";
8
8
  export { DmnError, evaluateDefinition } from "./runtime.js";
@@ -13,6 +13,16 @@
13
13
  * gateway, an in-memory snapshot in the tests).
14
14
  */
15
15
  import type { PermissionLine, Principal } from "./types.js";
16
+ /**
17
+ * The capability family that gives an AGENT a role (S2-T5, Q 18e7e16f = A, "M2"; S9 ADR-5).
18
+ * An in-force allow line `agents.role.<role_id>` with scope `all` on an agent actor makes
19
+ * `<role_id>` one of the agent's role ids, so the role lines (`principal_role_id = <role_id>`)
20
+ * apply to it. It writes nothing to `iam.user_roles`: that table keeps one human role per user.
21
+ * A person or a service never gets a role this way.
22
+ */
23
+ export declare const AGENT_ROLE_CAPABILITY_PREFIX = "agents.role.";
24
+ /** The role id of an agent-role line, or null when the line is not one. */
25
+ export declare function agentRoleOf(line: PermissionLine): string | null;
16
26
  /** `public.actors.type`. */
17
27
  export type ActorType = "human" | "agent" | "service";
18
28
  /** One row of `public.actors`. */
@@ -46,4 +56,4 @@ export interface ResolvedPrincipal<L extends PermissionLine = PermissionLine> {
46
56
  lines: L[];
47
57
  }
48
58
  /** Null when the actor is not visible to the caller. */
49
- export declare function resolvePrincipal<L extends PermissionLine>(reads: PrincipalReads<L>, actorId: string): Promise<ResolvedPrincipal<L> | null>;
59
+ export declare function resolvePrincipal<L extends PermissionLine>(reads: PrincipalReads<L>, actorId: string, now?: Date): Promise<ResolvedPrincipal<L> | null>;
package/dist/principal.js CHANGED
@@ -13,14 +13,39 @@
13
13
  * gateway, an in-memory snapshot in the tests).
14
14
  */
15
15
  import { MAX_OWNER_DEPTH } from "./can.js";
16
+ import { matchesCapability } from "./capability.js";
17
+ import { isLineActive } from "./line.js";
18
+ /**
19
+ * The capability family that gives an AGENT a role (S2-T5, Q 18e7e16f = A, "M2"; S9 ADR-5).
20
+ * An in-force allow line `agents.role.<role_id>` with scope `all` on an agent actor makes
21
+ * `<role_id>` one of the agent's role ids, so the role lines (`principal_role_id = <role_id>`)
22
+ * apply to it. It writes nothing to `iam.user_roles`: that table keeps one human role per user.
23
+ * A person or a service never gets a role this way.
24
+ */
25
+ export const AGENT_ROLE_CAPABILITY_PREFIX = "agents.role.";
26
+ /** The role id of an agent-role line, or null when the line is not one. */
27
+ export function agentRoleOf(line) {
28
+ if (line.effect !== "allow" || line.scope_kind !== "all")
29
+ return null;
30
+ if (!line.capability.startsWith(AGENT_ROLE_CAPABILITY_PREFIX))
31
+ return null;
32
+ const id = line.capability.slice(AGENT_ROLE_CAPABILITY_PREFIX.length);
33
+ return AGENT_ROLE_ID.test(id) ? id : null;
34
+ }
35
+ /**
36
+ * An agent role id always starts with `agent-`, so a human bundle (`admin`, `superadmin`) can
37
+ * never be given to an agent through a line.
38
+ */
39
+ const AGENT_ROLE_ID = /^agent-[a-z0-9][a-z0-9_-]{0,80}$/;
16
40
  const KIND = {
17
41
  human: "person",
18
42
  agent: "agent",
19
43
  service: "service",
20
44
  };
21
45
  /** Null when the actor is not visible to the caller. */
22
- export async function resolvePrincipal(reads, actorId) {
46
+ export async function resolvePrincipal(reads, actorId, now = new Date()) {
23
47
  const layers = [];
48
+ const principals = new Map();
24
49
  const seen = new Set();
25
50
  const build = async (id, depth) => {
26
51
  const actor = await reads.readActor(id);
@@ -39,6 +64,7 @@ export async function resolvePrincipal(reads, actorId) {
39
64
  kind: KIND[actor.type] ?? "service",
40
65
  role_ids: roleIds,
41
66
  };
67
+ principals.set(id, principal);
42
68
  if (actor.type !== "agent")
43
69
  return principal;
44
70
  const owners = (await reads.readActorOwners(id)).filter((o) => o !== id);
@@ -69,5 +95,55 @@ export async function resolvePrincipal(reads, actorId) {
69
95
  const actorIds = layers.map((l) => l.actor.id);
70
96
  const roleIds = [...new Set(layers.flatMap((l) => l.role_ids))];
71
97
  const lines = await reads.readLines(actorIds, roleIds);
72
- return { principal, layers, lines };
98
+ // Agent roles (M2): an in-force `agents.role.<id>` allow line on an agent layer adds the role
99
+ // id to that layer. The role lines are read in one more read. No nesting: a line read through
100
+ // a role never adds a role.
101
+ const extraByActor = new Map();
102
+ for (const layer of layers) {
103
+ if (layer.actor.type !== "agent")
104
+ continue;
105
+ const extra = new Set();
106
+ for (const l of lines) {
107
+ if (l.principal_actor_id !== layer.actor.id || !isLineActive(l, now))
108
+ continue;
109
+ const role = agentRoleOf(l);
110
+ if (role !== null && !layer.role_ids.includes(role))
111
+ extra.add(role);
112
+ }
113
+ // Deny wins over membership: an active deny or ask line of the same actor that matches
114
+ // `agents.role.<id>` (the exact line or a pattern such as `agents.*`, of any scope) drops
115
+ // that role. An admin suspends a role of an agent with one deny line.
116
+ for (const role of [...extra]) {
117
+ const name = `${AGENT_ROLE_CAPABILITY_PREFIX}${role}`;
118
+ const blocked = lines.some((l) => l.principal_actor_id === layer.actor.id &&
119
+ l.effect !== "allow" &&
120
+ isLineActive(l, now) &&
121
+ matchesCapability(l.capability, name));
122
+ if (blocked)
123
+ extra.delete(role);
124
+ }
125
+ if (extra.size > 0)
126
+ extraByActor.set(layer.actor.id, [...extra].sort());
127
+ }
128
+ if (extraByActor.size === 0)
129
+ return { principal, layers, lines };
130
+ const newRoleIds = [
131
+ ...new Set([...extraByActor.values()].flat().filter((r) => !roleIds.includes(r))),
132
+ ].sort();
133
+ const roleLines = newRoleIds.length > 0 ? await reads.readLines([], newRoleIds) : [];
134
+ for (const layer of layers) {
135
+ const extra = extraByActor.get(layer.actor.id);
136
+ if (!extra)
137
+ continue;
138
+ layer.role_ids = [...layer.role_ids, ...extra];
139
+ const p = principals.get(layer.actor.id);
140
+ if (p)
141
+ p.role_ids = layer.role_ids;
142
+ }
143
+ const have = new Set(lines.map((l) => l.id));
144
+ return {
145
+ principal,
146
+ layers,
147
+ lines: [...lines, ...roleLines.filter((l) => !have.has(l.id))],
148
+ };
73
149
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devfellowship/access",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
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",