@segmentstream/ontology 0.120.0 → 0.121.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.
@@ -1,8 +1,9 @@
1
1
  import { Effect } from "effect";
2
2
  import { missingPermission, permissionsOf, principalScopes } from "../permissions.js";
3
3
  import { PermissionDenied } from "../errors.js";
4
- import { MEMBER_ROLE, FEEDBACK_REPORTER_ROLE, toSnakeCase } from "../names.js";
5
- import { rolesOf } from "../runtime/principals.js";
4
+ import { FEEDBACK_REPORTER_ROLE, toSnakeCase } from "../names.js";
5
+ import { implicitRoleNames } from "../role.js";
6
+ import { rolesOf, workflowRoles } from "../runtime/principals.js";
6
7
  import { PIPELINE_WORKER_PROVIDER } from "../runtime/workload.js";
7
8
  import { WORKFLOW_USER_PROVIDER, workflowOfSubject } from "../runtime/workflow-users.js";
8
9
  /** Re-read user and roles in the same transaction that authorizes a storage operation. */
@@ -24,9 +25,10 @@ workflowPrincipal) {
24
25
  const users = yield* sql.unsafe(`SELECT kind::text, active, identity_provider, identity_subject FROM "user" WHERE id = $1::uuid FOR SHARE`, [principalId]);
25
26
  const user = users[0];
26
27
  const roles = yield* sql.unsafe(`SELECT role FROM "_user_roles" WHERE user_id = $1::uuid FOR SHARE`, [principalId]);
28
+ const reserved = implicitRoleNames(ontology.roles);
27
29
  const held = roles
28
30
  .map((row) => String(row.role))
29
- .filter((name) => toSnakeCase(name) !== FEEDBACK_REPORTER_ROLE);
31
+ .filter((name) => !(reserved.length > 0 && toSnakeCase(name) === FEEDBACK_REPORTER_ROLE));
30
32
  // Reuse human principal resolution rather than reconstructing implicit authority here. The
31
33
  // result rechecks required permissions and is the reader for scoped file reads; the caller's
32
34
  // consent-narrowed principal still governs the rest of the operation.
@@ -41,8 +43,9 @@ workflowPrincipal) {
41
43
  user?.kind === "service" &&
42
44
  user.identity_provider === PIPELINE_WORKER_PROVIDER &&
43
45
  user.identity_subject === `pipeline-workers:${execution.workspaceId}`;
44
- // A workflow's runs hold what member and the declared workflow's role grant. The database
45
- // must assign exactly that role: an extra or stale assignment widens nothing and is refused.
46
+ // A workflow's runs hold what the declared workflow's role grants (and the implicit member's,
47
+ // while the ontology declares one). The database must assign exactly that role: an extra or
48
+ // stale assignment widens nothing and is refused.
46
49
  const workflowUser = user?.kind === "service" && user.identity_provider === WORKFLOW_USER_PROVIDER;
47
50
  // The user's subject must be exactly the principal's, workspace id included.
48
51
  const workflow = workflowUser &&
@@ -55,7 +58,7 @@ workflowPrincipal) {
55
58
  execution === undefined &&
56
59
  held.length === 1 &&
57
60
  held[0] === workflow.role;
58
- const liveHeld = workflowUser && workflow ? [MEMBER_ROLE, workflow.role] : (member?.roles ?? held);
61
+ const liveHeld = workflowUser && workflow ? workflowRoles(ontology, workflow.role) : (member?.roles ?? held);
59
62
  const permissions = worker
60
63
  ? ["*:*"]
61
64
  : workflowUser && !declaredWorkflow
@@ -22,7 +22,10 @@ export declare const MAX_ACTION_TRIGGERS = 20;
22
22
  export interface TriggerRuns {
23
23
  /** The action the trigger runs, as its handle: `Lead.actions.notify`. */
24
24
  readonly runs?: AnyActionHandle;
25
- /** The declared role, other than `member`, the runs hold with member's; required with `runs`. */
25
+ /**
26
+ * The declared role the runs hold, required with `runs`: exactly its permissions, with the
27
+ * built-in `member`'s while the ontology declares one.
28
+ */
26
29
  readonly role?: string;
27
30
  }
28
31
  /**
@@ -264,8 +267,9 @@ export interface WorkflowOptions<S extends AnyInputSchema | undefined = undefine
264
267
  /** Required, like every declaration: what the workflow does and why. */
265
268
  readonly description: string;
266
269
  /**
267
- * The declared role, other than `member`, whose permissions the workflow's runs hold together
268
- * with member's. Its runs act as the workflow's own service user.
270
+ * The declared role whose permissions the workflow's runs hold: exactly its permissions, with
271
+ * the built-in `member`'s while the ontology declares one. Its runs act as the workflow's own
272
+ * service user.
269
273
  */
270
274
  readonly role: string;
271
275
  /** A `Schema.Struct` of the workflow's input. Omitted means `{}`. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@segmentstream/ontology",
3
- "version": "0.120.0",
3
+ "version": "0.121.0",
4
4
  "description": "Define a SegmentStream workspace app's ontology: entities, relationships, roles and actions, written with Effect.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "SegmentStream",