@segmentstream/ontology 0.99.0 → 0.99.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/dist/analyze.js CHANGED
@@ -8,7 +8,7 @@ import { CONNECTION_KEY, isConnection } from "./connection.js";
8
8
  import { isEntity } from "./entity.js";
9
9
  import { QUERY_METRICS_ROUTE, LEGACY_MEMBER_NAME, ENTITY_ID, GENERATED_ACTIONS, GENERATED_UPSERT_PREFIX, HISTORY_SUFFIX, MCP_METRIC_TOOLS, MCP_READ_TOOLS, MCP_TOOL_NAME_MAX_LENGTH, MEMBER_ROLE, FEEDBACK_REPORTER_ROLE, mcpToolName, RESERVED_ENTITY_NAMES, RESERVED_MEMBER_NAMES, RESERVED_RELATIONSHIP_NAMES, SNAKE_CASE_NAME, SYSTEM_PROPERTIES, humanize, isSystemProperty, toCamelCase, } from "./names.js";
10
10
  import { REFERENCE_ANNOTATION, propertyDefinition, propertyOptionNames, unknownPropertyOptions, referenceTarget, } from "./property.js";
11
- import { generatedActionPermissions, grants, isAllowed, normalizePermission, parsePermission, parseWorkflowPermission, permissionOf, READ_VERB, rolesGranting, USER_IDENTITY_VERBS, USER_MEMBER_VERBS, WILDCARD, wildcardEntityCovers, } from "./permissions.js";
11
+ import { EXPLICIT_GRANT_ENTITIES, generatedActionPermissions, grants, isAllowed, normalizePermission, parsePermission, parseWorkflowPermission, permissionOf, READ_VERB, rolesGranting, USER_IDENTITY_VERBS, USER_MEMBER_VERBS, WILDCARD, wildcardEntityCovers, } from "./permissions.js";
12
12
  import { ON_DELETE, isRelationship } from "./relationship.js";
13
13
  import { isRole, member, role } from "./role.js";
14
14
  import { CHANNEL_PROVIDERS, DEFAULT_SIGN_IN_POLICY, SIGN_UP_CHANNELS, SIGN_UP_CHAT_CHANNELS, isSignInPolicy, isSignUpChannel, } from "./sign-in.js";
@@ -2298,6 +2298,44 @@ function unknownPermission(value, { entity, verb }, verbs) {
2298
2298
  }
2299
2299
  return `${value} is not a permission of this ontology; ${entity} has ${[...own].join(", ")}.`;
2300
2300
  }
2301
+ /**
2302
+ * What `*:*` grants, naming only what it leaves out that the role does not grant by name: the
2303
+ * entities in {@link EXPLICIT_GRANT_ENTITIES} without an `<entity>:*`, administering users without
2304
+ * `user:*`, and workflows without `workflow:*:*`.
2305
+ */
2306
+ function wildcardWarning(permissions) {
2307
+ const whole = new Set(permissions.flatMap((value) => {
2308
+ const parsed = parsePermission(value);
2309
+ return parsed !== undefined && parsed.verb === WILDCARD ? [parsed.entity] : [];
2310
+ }));
2311
+ const workflows = permissions.some((value) => {
2312
+ const workflow = parseWorkflowPermission(value);
2313
+ return workflow?.workflow === WILDCARD && workflow.verb === WILDCARD;
2314
+ });
2315
+ const entities = [...EXPLICIT_GRANT_ENTITIES].filter((entity) => !whole.has(entity));
2316
+ const left = [
2317
+ ...(entities.length === 0
2318
+ ? []
2319
+ : [
2320
+ `${listed(entities)}, which only a permission naming ${entities.length === 1 ? "it" : "them"} grants`,
2321
+ ]),
2322
+ ...(whole.has("user")
2323
+ ? []
2324
+ : [
2325
+ `administering users (${USER_MEMBER_VERBS.map((verb) => `user:${verb}`).join(", ")} ` +
2326
+ "and user's authored actions), which only user:<verb> or user:* grants",
2327
+ ]),
2328
+ ...(workflows ? [] : ["workflows, which only workflow:<workflow>:<verb> grants"]),
2329
+ ];
2330
+ const except = left.length === 0
2331
+ ? ""
2332
+ : `, except ${left.length === 1 ? left[0] : `${left.slice(0, -1).join("; ")}; and ${left.at(-1)}`}`;
2333
+ return `*:* grants every entity and action, including those added later${except}.`;
2334
+ }
2335
+ /** `a`, `a and b`, `a, b and c`. */
2336
+ function listed(names) {
2337
+ return names.length === 1 ? names[0] : `${names.slice(0, -1).join(", ")} and ${names.at(-1)}`;
2338
+ }
2301
2339
  function checkRolePermissions(candidate, verbs, workflows, report) {
2302
2340
  const builtIn = candidate.name === MEMBER_ROLE;
2303
2341
  const path = builtIn ? "member.permissions" : `roles.${candidate.name}.permissions`;
@@ -2327,10 +2365,7 @@ function checkRolePermissions(candidate, verbs, workflows, report) {
2327
2365
  return;
2328
2366
  }
2329
2367
  if (parsed.entity === WILDCARD && parsed.verb === WILDCARD) {
2330
- report("wildcard-permission", at, "*:* grants every entity and action, including those added later, except agent_chat, " +
2331
- "agent_review, app_feedback, app_feedback_file, user_identity and " +
2332
- `administering users (${USER_MEMBER_VERBS.map((verb) => `user:${verb}`).join(", ")} ` +
2333
- "and user's authored actions), which only user:<verb> or user:* grants.", "warning");
2368
+ report("wildcard-permission", at, wildcardWarning(permissions), "warning");
2334
2369
  return;
2335
2370
  }
2336
2371
  const problem = unknownPermission(`${parsed.entity}:${parsed.verb}`, parsed, verbs);
@@ -73,17 +73,26 @@ export function feedbackRoles(options, files, roles, report) {
73
73
  }
74
74
  });
75
75
  }
76
- const resolved = roles.map((candidate) => !builders.has(candidate.name)
77
- ? candidate
78
- : role(candidate.name, {
76
+ const resolved = roles.map((candidate) => {
77
+ if (!builders.has(candidate.name)) {
78
+ return candidate;
79
+ }
80
+ const entries = roleEntries(Array.isArray(candidate.permissions) ? candidate.permissions : [], candidate.scopes ?? []);
81
+ // A builder reads and answers every item: add what the role does not already hold unscoped.
82
+ // A scoped grant of the same permission is widened, since the unscoped one covers it.
83
+ const unscoped = new Set(entries.flatMap((entry) => (typeof entry === "string" ? [normalizePermission(entry)] : [])));
84
+ return role(candidate.name, {
79
85
  description: candidate.description,
80
86
  permissions: [
81
- ...roleEntries(Array.isArray(candidate.permissions) ? candidate.permissions : [], candidate.scopes ?? []),
82
- "app_feedback:read",
83
- "app_feedback:respond",
84
- ...(files ? ["app_feedback_file:read"] : []),
87
+ ...entries,
88
+ ...[
89
+ "app_feedback:read",
90
+ "app_feedback:respond",
91
+ ...(files ? ["app_feedback_file:read"] : []),
92
+ ].filter((permission) => !unscoped.has(permission)),
85
93
  ],
86
- }));
94
+ });
95
+ });
87
96
  const own = { reporter: { $me: [] } };
88
97
  resolved.push(role(FEEDBACK_REPORTER_ROLE, {
89
98
  description: "Implicit feedback authority of authenticated human members; never assigned.",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@segmentstream/ontology",
3
- "version": "0.99.0",
3
+ "version": "0.99.1",
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",
@@ -69,6 +69,7 @@
69
69
  "files": [
70
70
  "dist",
71
71
  "README.md",
72
+ "CHANGELOG.md",
72
73
  "LICENSE",
73
74
  "NOTICE"
74
75
  ],