@stigmer/server 3.27.1 → 3.28.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.
Files changed (245) hide show
  1. package/README.md +2 -0
  2. package/dist/authorization/authorizer.d.ts +7 -5
  3. package/dist/authorization/authorizer.d.ts.map +1 -1
  4. package/dist/authorization/authorizer.js +7 -5
  5. package/dist/authorization/authorizer.js.map +1 -1
  6. package/dist/authorization/derived-tuples.d.ts +3 -1
  7. package/dist/authorization/derived-tuples.d.ts.map +1 -1
  8. package/dist/authorization/derived-tuples.js +52 -2
  9. package/dist/authorization/derived-tuples.js.map +1 -1
  10. package/dist/authorization/evaluator.d.ts +9 -10
  11. package/dist/authorization/evaluator.d.ts.map +1 -1
  12. package/dist/authorization/evaluator.js.map +1 -1
  13. package/dist/authorization/list-read-scope.d.ts.map +1 -1
  14. package/dist/authorization/list-read-scope.js +29 -18
  15. package/dist/authorization/list-read-scope.js.map +1 -1
  16. package/dist/authorization/model/bindings.d.ts +41 -0
  17. package/dist/authorization/model/bindings.d.ts.map +1 -0
  18. package/dist/authorization/model/bindings.js +89 -0
  19. package/dist/authorization/model/bindings.js.map +1 -0
  20. package/dist/authorization/model/data/authorization-model.json +3114 -0
  21. package/dist/authorization/model/default-of.d.ts +2 -2
  22. package/dist/authorization/model/execution-viewer.d.ts +3 -0
  23. package/dist/authorization/model/execution-viewer.d.ts.map +1 -0
  24. package/dist/authorization/model/execution-viewer.js +50 -0
  25. package/dist/authorization/model/execution-viewer.js.map +1 -0
  26. package/dist/authorization/model/index.d.ts +33 -21
  27. package/dist/authorization/model/index.d.ts.map +1 -1
  28. package/dist/authorization/model/index.js +74 -52
  29. package/dist/authorization/model/index.js.map +1 -1
  30. package/dist/authorization/model/openfga-json.d.ts +18 -0
  31. package/dist/authorization/model/openfga-json.d.ts.map +1 -0
  32. package/dist/authorization/model/openfga-json.js +266 -0
  33. package/dist/authorization/model/openfga-json.js.map +1 -0
  34. package/dist/authorization/model/rewrite.d.ts +39 -67
  35. package/dist/authorization/model/rewrite.d.ts.map +1 -1
  36. package/dist/authorization/model/rewrite.js +1 -117
  37. package/dist/authorization/model/rewrite.js.map +1 -1
  38. package/dist/authorization/strict-json.d.ts +20 -0
  39. package/dist/authorization/strict-json.d.ts.map +1 -0
  40. package/dist/authorization/strict-json.js +45 -0
  41. package/dist/authorization/strict-json.js.map +1 -0
  42. package/dist/boot/compose.d.ts.map +1 -1
  43. package/dist/boot/compose.js +9 -7
  44. package/dist/boot/compose.js.map +1 -1
  45. package/dist/boot/list-indexes.d.ts.map +1 -1
  46. package/dist/boot/list-indexes.js +6 -0
  47. package/dist/boot/list-indexes.js.map +1 -1
  48. package/dist/domain/iampolicy/list-index.d.ts +2 -0
  49. package/dist/domain/iampolicy/list-index.d.ts.map +1 -0
  50. package/dist/domain/iampolicy/list-index.js +32 -0
  51. package/dist/domain/iampolicy/list-index.js.map +1 -0
  52. package/dist/domain/iampolicy/resource-store.d.ts.map +1 -1
  53. package/dist/domain/iampolicy/resource-store.js +24 -11
  54. package/dist/domain/iampolicy/resource-store.js.map +1 -1
  55. package/dist/domain/workflowexecution/list-index.d.ts +1 -1
  56. package/dist/extensions/list-read-scope.d.ts +20 -3
  57. package/dist/extensions/list-read-scope.d.ts.map +1 -1
  58. package/dist/extensions/list-read-scope.js +22 -2
  59. package/dist/extensions/list-read-scope.js.map +1 -1
  60. package/dist/index.d.ts +8 -8
  61. package/dist/index.d.ts.map +1 -1
  62. package/dist/index.js +20 -5
  63. package/dist/index.js.map +1 -1
  64. package/package.json +7 -6
  65. package/src/authorization/README.md +48 -39
  66. package/src/authorization/__tests__/authorizer.test.ts +5 -14
  67. package/src/authorization/__tests__/derived-tuples.test.ts +192 -17
  68. package/src/authorization/__tests__/evaluator.test.ts +53 -160
  69. package/src/authorization/__tests__/facts.test.ts +5 -11
  70. package/src/authorization/__tests__/list-read-scope.measure.test.ts +424 -62
  71. package/src/authorization/__tests__/list-read-scope.test.ts +15 -14
  72. package/src/authorization/__tests__/organization-directory.test.ts +2 -2
  73. package/src/authorization/__tests__/store-test-kit.ts +246 -0
  74. package/src/authorization/__tests__/store-tests.test.ts +91 -223
  75. package/src/authorization/__tests__/support.ts +30 -2
  76. package/src/authorization/__tests__/throwaway-model.ts +75 -0
  77. package/src/authorization/__tests__/wire-permissions.test.ts +141 -107
  78. package/src/authorization/authorizer.ts +7 -5
  79. package/src/authorization/derived-tuples.ts +105 -16
  80. package/src/authorization/evaluator.ts +8 -10
  81. package/src/authorization/list-read-scope.ts +37 -22
  82. package/src/authorization/model/__tests__/openfga-json.test.ts +353 -0
  83. package/src/authorization/model/__tests__/registry.test.ts +102 -276
  84. package/src/authorization/model/bindings.ts +131 -0
  85. package/src/authorization/model/data/authorization-model.json +3114 -0
  86. package/src/authorization/model/default-of.ts +2 -2
  87. package/src/authorization/model/execution-viewer.ts +56 -0
  88. package/src/authorization/model/index.ts +81 -72
  89. package/src/authorization/model/openfga-json.ts +310 -0
  90. package/src/authorization/model/rewrite.ts +39 -188
  91. package/src/authorization/strict-json.ts +52 -0
  92. package/src/boot/__tests__/list-indexes.test.ts +4 -0
  93. package/src/boot/compose.ts +9 -7
  94. package/src/boot/list-indexes.ts +6 -0
  95. package/src/domain/iampolicy/__tests__/resource-store.test.ts +65 -5
  96. package/src/domain/iampolicy/list-index.ts +33 -0
  97. package/src/domain/iampolicy/resource-store.ts +24 -11
  98. package/src/extensions/__tests__/built-in-authorization-composed.test.ts +3 -6
  99. package/src/extensions/list-read-scope.ts +32 -4
  100. package/src/index.ts +20 -44
  101. package/dist/authorization/model/agent.d.ts +0 -2
  102. package/dist/authorization/model/agent.d.ts.map +0 -1
  103. package/dist/authorization/model/agent.js +0 -43
  104. package/dist/authorization/model/agent.js.map +0 -1
  105. package/dist/authorization/model/agent_channel.d.ts +0 -2
  106. package/dist/authorization/model/agent_channel.d.ts.map +0 -1
  107. package/dist/authorization/model/agent_channel.js +0 -39
  108. package/dist/authorization/model/agent_channel.js.map +0 -1
  109. package/dist/authorization/model/agent_execution.d.ts +0 -2
  110. package/dist/authorization/model/agent_execution.d.ts.map +0 -1
  111. package/dist/authorization/model/agent_execution.js +0 -25
  112. package/dist/authorization/model/agent_execution.js.map +0 -1
  113. package/dist/authorization/model/agent_instance.d.ts +0 -2
  114. package/dist/authorization/model/agent_instance.d.ts.map +0 -1
  115. package/dist/authorization/model/agent_instance.js +0 -48
  116. package/dist/authorization/model/agent_instance.js.map +0 -1
  117. package/dist/authorization/model/agent_share.d.ts +0 -2
  118. package/dist/authorization/model/agent_share.d.ts.map +0 -1
  119. package/dist/authorization/model/agent_share.js +0 -29
  120. package/dist/authorization/model/agent_share.js.map +0 -1
  121. package/dist/authorization/model/api_key.d.ts +0 -2
  122. package/dist/authorization/model/api_key.d.ts.map +0 -1
  123. package/dist/authorization/model/api_key.js +0 -27
  124. package/dist/authorization/model/api_key.js.map +0 -1
  125. package/dist/authorization/model/artifact.d.ts +0 -2
  126. package/dist/authorization/model/artifact.d.ts.map +0 -1
  127. package/dist/authorization/model/artifact.js +0 -27
  128. package/dist/authorization/model/artifact.js.map +0 -1
  129. package/dist/authorization/model/channel_app.d.ts +0 -2
  130. package/dist/authorization/model/channel_app.d.ts.map +0 -1
  131. package/dist/authorization/model/channel_app.js +0 -28
  132. package/dist/authorization/model/channel_app.js.map +0 -1
  133. package/dist/authorization/model/environment.d.ts +0 -2
  134. package/dist/authorization/model/environment.d.ts.map +0 -1
  135. package/dist/authorization/model/environment.js +0 -33
  136. package/dist/authorization/model/environment.js.map +0 -1
  137. package/dist/authorization/model/execution_context.d.ts +0 -2
  138. package/dist/authorization/model/execution_context.d.ts.map +0 -1
  139. package/dist/authorization/model/execution_context.js +0 -19
  140. package/dist/authorization/model/execution_context.js.map +0 -1
  141. package/dist/authorization/model/iam_policy.d.ts +0 -2
  142. package/dist/authorization/model/iam_policy.d.ts.map +0 -1
  143. package/dist/authorization/model/iam_policy.js +0 -31
  144. package/dist/authorization/model/iam_policy.js.map +0 -1
  145. package/dist/authorization/model/identity_account.d.ts +0 -2
  146. package/dist/authorization/model/identity_account.d.ts.map +0 -1
  147. package/dist/authorization/model/identity_account.js +0 -25
  148. package/dist/authorization/model/identity_account.js.map +0 -1
  149. package/dist/authorization/model/mcp_server.d.ts +0 -2
  150. package/dist/authorization/model/mcp_server.d.ts.map +0 -1
  151. package/dist/authorization/model/mcp_server.js +0 -38
  152. package/dist/authorization/model/mcp_server.js.map +0 -1
  153. package/dist/authorization/model/memory.d.ts +0 -2
  154. package/dist/authorization/model/memory.d.ts.map +0 -1
  155. package/dist/authorization/model/memory.js +0 -26
  156. package/dist/authorization/model/memory.js.map +0 -1
  157. package/dist/authorization/model/oauth_app.d.ts +0 -2
  158. package/dist/authorization/model/oauth_app.d.ts.map +0 -1
  159. package/dist/authorization/model/oauth_app.js +0 -31
  160. package/dist/authorization/model/oauth_app.js.map +0 -1
  161. package/dist/authorization/model/organization.d.ts +0 -2
  162. package/dist/authorization/model/organization.d.ts.map +0 -1
  163. package/dist/authorization/model/organization.js +0 -58
  164. package/dist/authorization/model/organization.js.map +0 -1
  165. package/dist/authorization/model/platform_client.d.ts +0 -2
  166. package/dist/authorization/model/platform_client.d.ts.map +0 -1
  167. package/dist/authorization/model/platform_client.js +0 -31
  168. package/dist/authorization/model/platform_client.js.map +0 -1
  169. package/dist/authorization/model/plugin.d.ts +0 -2
  170. package/dist/authorization/model/plugin.d.ts.map +0 -1
  171. package/dist/authorization/model/plugin.js +0 -45
  172. package/dist/authorization/model/plugin.js.map +0 -1
  173. package/dist/authorization/model/schedule.d.ts +0 -2
  174. package/dist/authorization/model/schedule.d.ts.map +0 -1
  175. package/dist/authorization/model/schedule.js +0 -34
  176. package/dist/authorization/model/schedule.js.map +0 -1
  177. package/dist/authorization/model/session.d.ts +0 -2
  178. package/dist/authorization/model/session.d.ts.map +0 -1
  179. package/dist/authorization/model/session.js +0 -38
  180. package/dist/authorization/model/session.js.map +0 -1
  181. package/dist/authorization/model/skill.d.ts +0 -2
  182. package/dist/authorization/model/skill.d.ts.map +0 -1
  183. package/dist/authorization/model/skill.js +0 -39
  184. package/dist/authorization/model/skill.js.map +0 -1
  185. package/dist/authorization/model/workflow.d.ts +0 -2
  186. package/dist/authorization/model/workflow.d.ts.map +0 -1
  187. package/dist/authorization/model/workflow.js +0 -39
  188. package/dist/authorization/model/workflow.js.map +0 -1
  189. package/dist/authorization/model/workflow_execution.d.ts +0 -2
  190. package/dist/authorization/model/workflow_execution.d.ts.map +0 -1
  191. package/dist/authorization/model/workflow_execution.js +0 -33
  192. package/dist/authorization/model/workflow_execution.js.map +0 -1
  193. package/dist/authorization/model/workflow_instance.d.ts +0 -2
  194. package/dist/authorization/model/workflow_instance.d.ts.map +0 -1
  195. package/dist/authorization/model/workflow_instance.js +0 -96
  196. package/dist/authorization/model/workflow_instance.js.map +0 -1
  197. package/dist/authorization/store-test-kit.d.ts +0 -62
  198. package/dist/authorization/store-test-kit.d.ts.map +0 -1
  199. package/dist/authorization/store-test-kit.js +0 -265
  200. package/dist/authorization/store-test-kit.js.map +0 -1
  201. package/src/authorization/__tests__/fixtures/fga/agent-channel-owner.fga.yaml +0 -112
  202. package/src/authorization/__tests__/fixtures/fga/agent-instance-creation.fga.yaml +0 -177
  203. package/src/authorization/__tests__/fixtures/fga/agent-share-owner.fga.yaml +0 -109
  204. package/src/authorization/__tests__/fixtures/fga/artifact-org-and-owner.fga.yaml +0 -128
  205. package/src/authorization/__tests__/fixtures/fga/blueprint-private-visibility.fga.yaml +0 -318
  206. package/src/authorization/__tests__/fixtures/fga/channel-app-owner.fga.yaml +0 -125
  207. package/src/authorization/__tests__/fixtures/fga/channel-participation.fga.yaml +0 -201
  208. package/src/authorization/__tests__/fixtures/fga/channel-session-visibility.fga.yaml +0 -187
  209. package/src/authorization/__tests__/fixtures/fga/default-instance-inheritance.fga.yaml +0 -214
  210. package/src/authorization/__tests__/fixtures/fga/mcp-server-authoring.fga.yaml +0 -129
  211. package/src/authorization/__tests__/fixtures/fga/memory-subject-only.fga.yaml +0 -72
  212. package/src/authorization/__tests__/fixtures/fga/org-admin-owner-inheritance.fga.yaml +0 -308
  213. package/src/authorization/__tests__/fixtures/fga/org-shared-environment.fga.yaml +0 -144
  214. package/src/authorization/__tests__/fixtures/fga/platform-visibility.fga.yaml +0 -199
  215. package/src/authorization/__tests__/fixtures/fga/provider-standing-viewer.fga.yaml +0 -40
  216. package/src/authorization/__tests__/fixtures/fga/reserved-label-writer.fga.yaml +0 -41
  217. package/src/authorization/__tests__/fixtures/fga/schedule-owner.fga.yaml +0 -113
  218. package/src/authorization/__tests__/fixtures/fga/schedule-session-visibility.fga.yaml +0 -214
  219. package/src/authorization/__tests__/fixtures/fga/session-personal-resource.fga.yaml +0 -117
  220. package/src/authorization/__tests__/fixtures/fga/workflow-execution-sharing.fga.yaml +0 -190
  221. package/src/authorization/model/agent.ts +0 -64
  222. package/src/authorization/model/agent_channel.ts +0 -57
  223. package/src/authorization/model/agent_execution.ts +0 -33
  224. package/src/authorization/model/agent_instance.ts +0 -66
  225. package/src/authorization/model/agent_share.ts +0 -40
  226. package/src/authorization/model/api_key.ts +0 -28
  227. package/src/authorization/model/artifact.ts +0 -38
  228. package/src/authorization/model/channel_app.ts +0 -39
  229. package/src/authorization/model/environment.ts +0 -48
  230. package/src/authorization/model/execution_context.ts +0 -20
  231. package/src/authorization/model/iam_policy.ts +0 -42
  232. package/src/authorization/model/identity_account.ts +0 -26
  233. package/src/authorization/model/mcp_server.ts +0 -59
  234. package/src/authorization/model/memory.ts +0 -27
  235. package/src/authorization/model/oauth_app.ts +0 -43
  236. package/src/authorization/model/organization.ts +0 -59
  237. package/src/authorization/model/platform_client.ts +0 -43
  238. package/src/authorization/model/plugin.ts +0 -66
  239. package/src/authorization/model/schedule.ts +0 -49
  240. package/src/authorization/model/session.ts +0 -50
  241. package/src/authorization/model/skill.ts +0 -60
  242. package/src/authorization/model/workflow.ts +0 -60
  243. package/src/authorization/model/workflow_execution.ts +0 -46
  244. package/src/authorization/model/workflow_instance.ts +0 -125
  245. package/src/authorization/store-test-kit.ts +0 -395
@@ -14,8 +14,8 @@
14
14
  * resolves the blueprint's `viewer` on — one read serves both. Which spec
15
15
  * field names the blueprint is `kind_meta`'s to say (the instance kind's
16
16
  * `additional_parents` entry for the blueprint kind), never restated
17
- * here; an instance kind without that entry is a transcript bug and
18
- * throws at first use rather than deriving nothing.
17
+ * here; an instance kind without that entry is a binding bug
18
+ * (bindings.ts) and throws at first use rather than deriving nothing.
19
19
  *
20
20
  * A user-created instance points at a blueprint whose pointer names a
21
21
  * different row (or none), so the rule derives nothing for it and its
@@ -0,0 +1,3 @@
1
+ import type { DerivedRelation } from "./rewrite.js";
2
+ export declare const executionViewer: DerivedRelation;
3
+ //# sourceMappingURL=execution-viewer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execution-viewer.d.ts","sourceRoot":"","sources":["../../../src/authorization/model/execution-viewer.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD,eAAO,MAAM,eAAe,EAAE,eAiC7B,CAAC"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * The `execution_viewer` derived rule of a workflow instance. The model
3
+ * (fga/model/agentic/workflow_instance.fga) keeps the instance's RUN
4
+ * history audience apart from `viewer`, so making an instance
5
+ * org-runnable never exposes other people's run inputs and outputs;
6
+ * workflow_execution reads it through `execution_viewer from
7
+ * workflow_instance`.
8
+ *
9
+ * It is derived from `spec.execution_visibility`, which `kind_meta`
10
+ * cannot express: `organization` derives
11
+ * `#execution_viewer@organization:<org>#viewer`, the organization's full
12
+ * read audience (the relation also admits `#member`, the legacy shape),
13
+ * and `private` or unset derives nothing, so each run stays its
14
+ * triggerer's. Pure over the row; no related row is read.
15
+ */
16
+ import { isMessage } from "@bufbuild/protobuf";
17
+ import { WorkflowInstanceSchema } from "@stigmer/protos/ai/stigmer/agentic/workflowinstance/v1/api_pb";
18
+ import { WorkflowExecutionVisibility } from "@stigmer/protos/ai/stigmer/agentic/workflowinstance/v1/spec_pb";
19
+ export const executionViewer = (object, row) => {
20
+ if (!isMessage(row, WorkflowInstanceSchema)) {
21
+ return Promise.resolve([]);
22
+ }
23
+ const level = row.spec?.executionVisibility ?? WorkflowExecutionVisibility.unspecified;
24
+ switch (level) {
25
+ case WorkflowExecutionVisibility.organization: {
26
+ const org = row.metadata?.org ?? "";
27
+ return Promise.resolve(org === ""
28
+ ? []
29
+ : [
30
+ {
31
+ object,
32
+ relation: "execution_viewer",
33
+ subject: {
34
+ form: "userset",
35
+ object: { type: "organization", id: org },
36
+ relation: "viewer",
37
+ },
38
+ },
39
+ ]);
40
+ }
41
+ case WorkflowExecutionVisibility.private:
42
+ case WorkflowExecutionVisibility.unspecified:
43
+ return Promise.resolve([]);
44
+ default: {
45
+ const exhaustive = level;
46
+ throw new Error(`unknown execution visibility: ${String(exhaustive)}`);
47
+ }
48
+ }
49
+ };
50
+ //# sourceMappingURL=execution-viewer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execution-viewer.js","sourceRoot":"","sources":["../../../src/authorization/model/execution-viewer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C,OAAO,EAAE,sBAAsB,EAAE,MAAM,+DAA+D,CAAC;AACvG,OAAO,EAAE,2BAA2B,EAAE,MAAM,gEAAgE,CAAC;AAI7G,MAAM,CAAC,MAAM,eAAe,GAAoB,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE;IAC9D,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,sBAAsB,CAAC,EAAE,CAAC;QAC5C,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAC7B,CAAC;IACD,MAAM,KAAK,GACT,GAAG,CAAC,IAAI,EAAE,mBAAmB,IAAI,2BAA2B,CAAC,WAAW,CAAC;IAC3E,QAAQ,KAAK,EAAE,CAAC;QACd,KAAK,2BAA2B,CAAC,YAAY,CAAC,CAAC,CAAC;YAC9C,MAAM,GAAG,GAAG,GAAG,CAAC,QAAQ,EAAE,GAAG,IAAI,EAAE,CAAC;YACpC,OAAO,OAAO,CAAC,OAAO,CACpB,GAAG,KAAK,EAAE;gBACR,CAAC,CAAC,EAAE;gBACJ,CAAC,CAAC;oBACE;wBACE,MAAM;wBACN,QAAQ,EAAE,kBAAkB;wBAC5B,OAAO,EAAE;4BACP,IAAI,EAAE,SAAS;4BACf,MAAM,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,EAAE,EAAE,GAAG,EAAE;4BACzC,QAAQ,EAAE,QAAQ;yBACnB;qBACF;iBACF,CACN,CAAC;QACJ,CAAC;QACD,KAAK,2BAA2B,CAAC,OAAO,CAAC;QACzC,KAAK,2BAA2B,CAAC,WAAW;YAC1C,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QAC7B,OAAO,CAAC,CAAC,CAAC;YACR,MAAM,UAAU,GAAU,KAAK,CAAC;YAChC,MAAM,IAAI,KAAK,CAAC,iCAAiC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;QACzE,CAAC;IACH,CAAC;AACH,CAAC,CAAC"}
@@ -1,26 +1,31 @@
1
1
  /**
2
- * The built-in model — every kind declaration open source evaluates,
3
- * registered once in the order the cloud's `fga.mod` files them, and
4
- * reached by kind (the driver's `AuthzCheck.resourceKind`) or by FGA type
5
- * name (an object reference inside a tuple). A kind with no declaration
6
- * is one this edition does not evaluate: as a check TARGET that is a
7
- * registry gap the evaluator throws on (the driver refuses unserved kinds
8
- * before any evaluation, so the throw is a backstop); reached through a
9
- * tuple it is simply an object with no relations.
2
+ * The built-in model: every type of the authorization model, reached by
3
+ * kind (the driver's `AuthzCheck.resourceKind`) or by FGA type name (an
4
+ * object reference inside a tuple), in `fga.mod` order.
10
5
  *
11
- * `newModel` exists for tests that need a throwaway model (a cycle, a
12
- * chain past the depth bound) and for the cloud's drift test, which
13
- * builds a model from the live `.fga` files and compares.
6
+ * It is built at module load from the one set of bytes every edition
7
+ * reads: data/authorization-model.json, OpenFGA's JSON compiled from the
8
+ * `.fga` files under fga/model (`make gen-authorization-model`), which the
9
+ * engine suites under fga/tests also run against. The reader
10
+ * (openfga-json.ts) turns it into the evaluator's vocabulary, and the
11
+ * binding table (bindings.ts) adds what JSON cannot carry: each kind's row
12
+ * schema and its derived rules. A model this server cannot evaluate, or a
13
+ * type and a binding that disagree, fails the load, so it fails the boot
14
+ * and every test that imports the model, never an answer.
15
+ *
16
+ * The model declares every type, whichever edition serves it. Which kinds
17
+ * an edition evaluates is the tier's question, answered before any
18
+ * evaluation (authorizer.ts, `kindServedByEdition`): open source refuses a
19
+ * check that targets `team`, `identity_provider`, `invitation` or
20
+ * `platform`, and a tuple that names one resolves over tuples alone, since
21
+ * this edition stores no row of those kinds.
14
22
  *
15
- * Registered: every kind of the open-source tier — the twenty-four
16
- * `kind_meta.tier: open_source` members — and nothing else. The three
17
- * files `fga.mod` lists that have no declaration here (`platform`,
18
- * `identity_provider`, `invitation`) are kinds this edition does not
19
- * serve: a check that targets one is refused by the
20
- * driver, and a tuple that names one (`identity_provider#platform_user`)
21
- * resolves to nobody. The registry test pins the list against the tier.
23
+ * `newModel` exists for tests that need a throwaway model (a cycle, a
24
+ * chain past the depth bound).
22
25
  */
23
- import type { ApiResourceKind } from "@stigmer/protos/ai/stigmer/commons/apiresource/apiresourcekind/api_resource_kind_pb";
26
+ import { ApiResourceKind } from "@stigmer/protos/ai/stigmer/commons/apiresource/apiresourcekind/api_resource_kind_pb";
27
+ import type { KindBinding } from "./bindings.js";
28
+ import type { ModelType } from "./openfga-json.js";
24
29
  import type { KindDeclaration } from "./rewrite.js";
25
30
  export interface Model {
26
31
  /** In registry order. */
@@ -29,8 +34,15 @@ export interface Model {
29
34
  byType(type: string): KindDeclaration | undefined;
30
35
  }
31
36
  export declare function newModel(declarations: ReadonlyArray<KindDeclaration>): Model;
32
- /** The declarations this edition evaluates, in `fga.mod` order. */
37
+ /**
38
+ * Joins the compiled model's types with their bindings, in the model's
39
+ * order. Refuses a type that names no `ApiResourceKind`, a type with no
40
+ * binding, a binding with no type, and a derived rule for a relation the
41
+ * type does not define.
42
+ */
43
+ export declare function bindModel(types: ReadonlyArray<ModelType>, bindings: ReadonlyMap<ApiResourceKind, KindBinding>): ReadonlyArray<KindDeclaration>;
44
+ /** Every type of the authorization model, in `fga.mod` order. */
33
45
  export declare const builtInModel: Model;
34
- /** The built-in model's declaration for a kind, or undefined for a kind it does not evaluate. */
46
+ /** The built-in model's declaration for a kind, or undefined for a kind the model does not define. */
35
47
  export declare function declarationFor(kind: ApiResourceKind): KindDeclaration | undefined;
36
48
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/authorization/model/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qFAAqF,CAAC;AAoB3H,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAQpD,MAAM,WAAW,KAAK;IACpB,yBAAyB;IACzB,QAAQ,CAAC,YAAY,EAAE,aAAa,CAAC,eAAe,CAAC,CAAC;IACtD,MAAM,CAAC,IAAI,EAAE,eAAe,GAAG,eAAe,GAAG,SAAS,CAAC;IAC3D,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS,CAAC;CACnD;AAED,wBAAgB,QAAQ,CAAC,YAAY,EAAE,aAAa,CAAC,eAAe,CAAC,GAAG,KAAK,CAe5E;AAED,mEAAmE;AACnE,eAAO,MAAM,YAAY,EAAE,KAyBzB,CAAC;AAEH,iGAAiG;AACjG,wBAAgB,cAAc,CAC5B,IAAI,EAAE,eAAe,GACpB,eAAe,GAAG,SAAS,CAE7B"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/authorization/model/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,qFAAqF,CAAC;AAGtH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAGjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD,OAAO,KAAK,EAAmB,eAAe,EAAE,MAAM,cAAc,CAAC;AAErE,MAAM,WAAW,KAAK;IACpB,yBAAyB;IACzB,QAAQ,CAAC,YAAY,EAAE,aAAa,CAAC,eAAe,CAAC,CAAC;IACtD,MAAM,CAAC,IAAI,EAAE,eAAe,GAAG,eAAe,GAAG,SAAS,CAAC;IAC3D,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS,CAAC;CACnD;AAED,wBAAgB,QAAQ,CAAC,YAAY,EAAE,aAAa,CAAC,eAAe,CAAC,GAAG,KAAK,CAe5E;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CACvB,KAAK,EAAE,aAAa,CAAC,SAAS,CAAC,EAC/B,QAAQ,EAAE,WAAW,CAAC,eAAe,EAAE,WAAW,CAAC,GAClD,aAAa,CAAC,eAAe,CAAC,CAoChC;AAED,iEAAiE;AACjE,eAAO,MAAM,YAAY,EAAE,KAE1B,CAAC;AAEF,sGAAsG;AACtG,wBAAgB,cAAc,CAC5B,IAAI,EAAE,eAAe,GACpB,eAAe,GAAG,SAAS,CAE7B"}
@@ -1,27 +1,33 @@
1
- import { agentDeclaration } from "./agent.js";
2
- import { agentChannelDeclaration } from "./agent_channel.js";
3
- import { agentExecutionDeclaration } from "./agent_execution.js";
4
- import { agentInstanceDeclaration } from "./agent_instance.js";
5
- import { agentShareDeclaration } from "./agent_share.js";
6
- import { apiKeyDeclaration } from "./api_key.js";
7
- import { artifactDeclaration } from "./artifact.js";
8
- import { channelAppDeclaration } from "./channel_app.js";
9
- import { environmentDeclaration } from "./environment.js";
10
- import { executionContextDeclaration } from "./execution_context.js";
11
- import { iamPolicyDeclaration } from "./iam_policy.js";
12
- import { identityAccountDeclaration } from "./identity_account.js";
13
- import { mcpServerDeclaration } from "./mcp_server.js";
14
- import { memoryDeclaration } from "./memory.js";
15
- import { oauthAppDeclaration } from "./oauth_app.js";
16
- import { organizationDeclaration } from "./organization.js";
17
- import { platformClientDeclaration } from "./platform_client.js";
18
- import { pluginDeclaration } from "./plugin.js";
19
- import { scheduleDeclaration } from "./schedule.js";
20
- import { sessionDeclaration } from "./session.js";
21
- import { skillDeclaration } from "./skill.js";
22
- import { workflowDeclaration } from "./workflow.js";
23
- import { workflowExecutionDeclaration } from "./workflow_execution.js";
24
- import { workflowInstanceDeclaration } from "./workflow_instance.js";
1
+ /**
2
+ * The built-in model: every type of the authorization model, reached by
3
+ * kind (the driver's `AuthzCheck.resourceKind`) or by FGA type name (an
4
+ * object reference inside a tuple), in `fga.mod` order.
5
+ *
6
+ * It is built at module load from the one set of bytes every edition
7
+ * reads: data/authorization-model.json, OpenFGA's JSON compiled from the
8
+ * `.fga` files under fga/model (`make gen-authorization-model`), which the
9
+ * engine suites under fga/tests also run against. The reader
10
+ * (openfga-json.ts) turns it into the evaluator's vocabulary, and the
11
+ * binding table (bindings.ts) adds what JSON cannot carry: each kind's row
12
+ * schema and its derived rules. A model this server cannot evaluate, or a
13
+ * type and a binding that disagree, fails the load, so it fails the boot
14
+ * and every test that imports the model, never an answer.
15
+ *
16
+ * The model declares every type, whichever edition serves it. Which kinds
17
+ * an edition evaluates is the tier's question, answered before any
18
+ * evaluation (authorizer.ts, `kindServedByEdition`): open source refuses a
19
+ * check that targets `team`, `identity_provider`, `invitation` or
20
+ * `platform`, and a tuple that names one resolves over tuples alone, since
21
+ * this edition stores no row of those kinds.
22
+ *
23
+ * `newModel` exists for tests that need a throwaway model (a cycle, a
24
+ * chain past the depth bound).
25
+ */
26
+ import { ApiResourceKind } from "@stigmer/protos/ai/stigmer/commons/apiresource/apiresourcekind/api_resource_kind_pb";
27
+ import { kindByEnumName } from "../../pipeline/apiresource-meta.js";
28
+ import { KIND_BINDINGS } from "./bindings.js";
29
+ import compiledModel from "./data/authorization-model.json" with { type: "json" };
30
+ import { readOpenFgaModel } from "./openfga-json.js";
25
31
  export function newModel(declarations) {
26
32
  const byKind = new Map();
27
33
  const byType = new Map();
@@ -38,34 +44,50 @@ export function newModel(declarations) {
38
44
  byType: (type) => byType.get(type),
39
45
  };
40
46
  }
41
- /** The declarations this edition evaluates, in `fga.mod` order. */
42
- export const builtInModel = newModel([
43
- identityAccountDeclaration,
44
- iamPolicyDeclaration,
45
- apiKeyDeclaration,
46
- oauthAppDeclaration,
47
- platformClientDeclaration,
48
- organizationDeclaration,
49
- agentDeclaration,
50
- agentChannelDeclaration,
51
- agentShareDeclaration,
52
- channelAppDeclaration,
53
- agentInstanceDeclaration,
54
- agentExecutionDeclaration,
55
- artifactDeclaration,
56
- environmentDeclaration,
57
- executionContextDeclaration,
58
- mcpServerDeclaration,
59
- memoryDeclaration,
60
- scheduleDeclaration,
61
- sessionDeclaration,
62
- skillDeclaration,
63
- workflowDeclaration,
64
- workflowInstanceDeclaration,
65
- workflowExecutionDeclaration,
66
- pluginDeclaration,
67
- ]);
68
- /** The built-in model's declaration for a kind, or undefined for a kind it does not evaluate. */
47
+ /**
48
+ * Joins the compiled model's types with their bindings, in the model's
49
+ * order. Refuses a type that names no `ApiResourceKind`, a type with no
50
+ * binding, a binding with no type, and a derived rule for a relation the
51
+ * type does not define.
52
+ */
53
+ export function bindModel(types, bindings) {
54
+ const bound = new Set();
55
+ const declarations = types.map((entry) => {
56
+ const kind = kindByEnumName(entry.type);
57
+ if (kind === ApiResourceKind.api_resource_kind_unknown) {
58
+ throw new Error(`${entry.source}: type '${entry.type}' names no ApiResourceKind`);
59
+ }
60
+ const binding = bindings.get(kind);
61
+ if (binding === undefined) {
62
+ throw new Error(`${entry.source}: type '${entry.type}' has no binding (model/bindings.ts)`);
63
+ }
64
+ bound.add(kind);
65
+ const derived = new Map();
66
+ for (const [relation, rule] of Object.entries(binding.derived ?? {})) {
67
+ if (!entry.relations.has(relation)) {
68
+ throw new Error(`model/bindings.ts: a derived rule for '${entry.type}#${relation}', which ${entry.source} does not define`);
69
+ }
70
+ derived.set(relation, rule);
71
+ }
72
+ return {
73
+ kind,
74
+ type: entry.type,
75
+ schema: binding.schema,
76
+ source: entry.source,
77
+ relations: entry.relations,
78
+ derived,
79
+ };
80
+ });
81
+ for (const kind of bindings.keys()) {
82
+ if (!bound.has(kind)) {
83
+ throw new Error(`model/bindings.ts: a binding for '${ApiResourceKind[kind]}', which the model does not define`);
84
+ }
85
+ }
86
+ return declarations;
87
+ }
88
+ /** Every type of the authorization model, in `fga.mod` order. */
89
+ export const builtInModel = newModel(bindModel(readOpenFgaModel(compiledModel), KIND_BINDINGS));
90
+ /** The built-in model's declaration for a kind, or undefined for a kind the model does not define. */
69
91
  export function declarationFor(kind) {
70
92
  return builtInModel.byKind(kind);
71
93
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/authorization/model/index.ts"],"names":[],"mappings":"AAwBA,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,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5B,IAAqB;IAErB,OAAO,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AACnC,CAAC"}
@@ -0,0 +1,18 @@
1
+ import type { Rewrite } from "./rewrite.js";
2
+ /** The only schema version this reader accepts: the modular DSL's. */
3
+ export declare const SUPPORTED_SCHEMA_VERSION = "1.2";
4
+ /** One type of the compiled model, in the evaluator's vocabulary. */
5
+ export interface ModelType {
6
+ /** The FGA type name: an `ApiResourceKind` member name (`agent`, `identity_account`). */
7
+ readonly type: string;
8
+ /** The `.fga` file the type is defined in, relative to the server package (`fga/model/agentic/agent.fga`). */
9
+ readonly source: string;
10
+ /** Every relation the type defines, sorted by name. */
11
+ readonly relations: ReadonlyMap<string, Rewrite>;
12
+ }
13
+ /**
14
+ * Reads a parsed compiled model. `where` names the file in every message.
15
+ * Throws on anything the module header says is refused or re-asserted.
16
+ */
17
+ export declare function readOpenFgaModel(value: unknown, where?: string): ReadonlyArray<ModelType>;
18
+ //# sourceMappingURL=openfga-json.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openfga-json.d.ts","sourceRoot":"","sources":["../../../src/authorization/model/openfga-json.ts"],"names":[],"mappings":"AA+CA,OAAO,KAAK,EAAE,OAAO,EAAe,MAAM,cAAc,CAAC;AAEzD,sEAAsE;AACtE,eAAO,MAAM,wBAAwB,QAAQ,CAAC;AAE9C,qEAAqE;AACrE,MAAM,WAAW,SAAS;IACxB,yFAAyF;IACzF,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,8GAA8G;IAC9G,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,uDAAuD;IACvD,QAAQ,CAAC,SAAS,EAAE,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClD;AAKD;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,OAAO,EACd,KAAK,SAA6B,GACjC,aAAa,CAAC,SAAS,CAAC,CAwB1B"}
@@ -0,0 +1,266 @@
1
+ /**
2
+ * The reader of the compiled authorization model: OpenFGA's own JSON
3
+ * (data/authorization-model.json, written by `make gen-authorization-model`
4
+ * from the `.fga` files under fga/model) turned into the evaluator's
5
+ * vocabulary (rewrite.ts), one entry per type in the file's order.
6
+ *
7
+ * The file is OpenFGA's format, not this server's, so it is read as
8
+ * `unknown` and refused loudly (strict-json.ts): every key the compiled
9
+ * model carries is listed below, and any other key, at any depth, is a
10
+ * thrown fault naming where. It runs when model/index.ts loads, so a model
11
+ * this server cannot evaluate fails the boot and every test that imports
12
+ * the model, never an answer.
13
+ *
14
+ * What is accepted, which is what the compiled model uses:
15
+ * - `schema_version` "1.2" and `type_definitions`;
16
+ * - per type: `type`, `relations`, and `metadata.{module, relations,
17
+ * source_info.file}`;
18
+ * - per relation's metadata: `directly_related_user_types[]`, each an
19
+ * object type (`{type}`) or a userset (`{type, relation}`);
20
+ * - per rewrite node: `this`, `computedUserset.relation`,
21
+ * `tupleToUserset.{tupleset,computedUserset}.relation`, `union.child`
22
+ * and `intersection.child`, nested to any depth (the evaluator
23
+ * recurses through any nesting).
24
+ *
25
+ * What is refused by name, because the evaluator does not implement it
26
+ * and the day the model needs it is a design act: `difference` (`but
27
+ * not`), conditions (a `conditions` map, or a type reference carrying
28
+ * `condition`), wildcards (`type:*`), a `computedUserset` that names
29
+ * another object, and any schema version but 1.2.
30
+ *
31
+ * What is re-asserted, though OpenFGA's validator proved it when the file
32
+ * was compiled, because the file is committed data and a hand edit must
33
+ * fail here rather than in an answer: every computed target and tupleset
34
+ * is a relation of its own type; every subject type names a declared type,
35
+ * and a userset subject a relation that type declares; and a relation
36
+ * lists direct subject types exactly when its rewrite has a `this` node,
37
+ * which is where the evaluator reads that list from.
38
+ *
39
+ * Relations come out sorted by name (the canonical file sorts keys; the
40
+ * evaluator only looks relations up). A union's or an intersection's
41
+ * children keep the file's order: the evaluator short-circuits in that
42
+ * order, so it is what the cost of a check rides on.
43
+ *
44
+ * The reader imports nothing but the vocabulary and the strict-read
45
+ * helpers, so the reader and the evaluator stay a self-contained pair.
46
+ */
47
+ import { list, record, text } from "../strict-json.js";
48
+ /** The only schema version this reader accepts: the modular DSL's. */
49
+ export const SUPPORTED_SCHEMA_VERSION = "1.2";
50
+ /** Where the `.fga` files live, relative to the server package; `source_info.file` is relative to it. */
51
+ const MODEL_SOURCE_DIR = "fga/model";
52
+ /**
53
+ * Reads a parsed compiled model. `where` names the file in every message.
54
+ * Throws on anything the module header says is refused or re-asserted.
55
+ */
56
+ export function readOpenFgaModel(value, where = "authorization-model.json") {
57
+ const root = record(value, where, ["schema_version", "type_definitions", "conditions"]);
58
+ if (root["conditions"] !== undefined) {
59
+ throw new Error(`${where}: conditions are not evaluated by this server`);
60
+ }
61
+ const version = text(root["schema_version"], `${where}: schema_version`);
62
+ if (version !== SUPPORTED_SCHEMA_VERSION) {
63
+ throw new Error(`${where}: schema_version '${version}' is not ${SUPPORTED_SCHEMA_VERSION}, the only version this server reads`);
64
+ }
65
+ const types = [];
66
+ const seen = new Set();
67
+ list(root["type_definitions"], `${where}: type_definitions`).forEach((entry, index) => {
68
+ const parsed = readType(entry, `${where}: type_definitions[${index}]`);
69
+ if (seen.has(parsed.type)) {
70
+ throw new Error(`${where}: type '${parsed.type}' is defined twice`);
71
+ }
72
+ seen.add(parsed.type);
73
+ types.push(parsed);
74
+ });
75
+ assertReferencesResolve(types, where);
76
+ return types;
77
+ }
78
+ function readType(value, where) {
79
+ const entry = record(value, where, ["type", "relations", "metadata"]);
80
+ const type = text(entry["type"], `${where}.type`);
81
+ const at = `${where} (${type})`;
82
+ const metadata = record(entry["metadata"], `${at}.metadata`, [
83
+ "module",
84
+ "relations",
85
+ "source_info",
86
+ ]);
87
+ text(metadata["module"], `${at}.metadata.module`);
88
+ const sourceInfo = record(metadata["source_info"], `${at}.metadata.source_info`, ["file"]);
89
+ const file = text(sourceInfo["file"], `${at}.metadata.source_info.file`);
90
+ const directTypes = readDirectTypes(metadata["relations"], `${at}.metadata.relations`);
91
+ const rewrites = entry["relations"] === undefined ? {} : record(entry["relations"], `${at}.relations`);
92
+ for (const relation of directTypes.keys()) {
93
+ if (!(relation in rewrites)) {
94
+ throw new Error(`${at}.metadata.relations.${relation}: metadata for a relation ${type} does not define`);
95
+ }
96
+ }
97
+ const relations = new Map();
98
+ for (const name of Object.keys(rewrites).sort()) {
99
+ const subjects = directTypes.get(name);
100
+ const rewrite = readRewrite(rewrites[name], `${at}.relations.${name}`, subjects);
101
+ const hasThis = containsThis(rewrite);
102
+ if (hasThis && subjects === undefined) {
103
+ throw new Error(`${at}.relations.${name}: a direct relation with no directly_related_user_types`);
104
+ }
105
+ if (!hasThis && subjects !== undefined) {
106
+ throw new Error(`${at}.relations.${name}: directly_related_user_types on a relation with no direct node`);
107
+ }
108
+ relations.set(name, rewrite);
109
+ }
110
+ return { type, source: `${MODEL_SOURCE_DIR}/${file}`, relations };
111
+ }
112
+ /** Each relation's direct subject types; a relation whose metadata is `{}` lists none and is absent. */
113
+ function readDirectTypes(value, where) {
114
+ const out = new Map();
115
+ if (value === undefined) {
116
+ return out;
117
+ }
118
+ for (const [relation, meta] of Object.entries(record(value, where))) {
119
+ const entry = record(meta, `${where}.${relation}`, ["directly_related_user_types"]);
120
+ if (entry["directly_related_user_types"] === undefined) {
121
+ continue;
122
+ }
123
+ const at = `${where}.${relation}.directly_related_user_types`;
124
+ out.set(relation, list(entry["directly_related_user_types"], at).map((item, index) => readSubjectType(item, `${at}[${index}]`)));
125
+ }
126
+ return out;
127
+ }
128
+ function readSubjectType(value, where) {
129
+ const entry = record(value, where, ["type", "relation", "wildcard", "condition"]);
130
+ if (entry["wildcard"] !== undefined) {
131
+ throw new Error(`${where}: wildcard subject types are not evaluated by this server`);
132
+ }
133
+ if (entry["condition"] !== undefined) {
134
+ throw new Error(`${where}: conditional subject types are not evaluated by this server`);
135
+ }
136
+ const type = text(entry["type"], `${where}.type`);
137
+ return entry["relation"] === undefined
138
+ ? { form: "object", type }
139
+ : { form: "userset", type, relation: text(entry["relation"], `${where}.relation`) };
140
+ }
141
+ /**
142
+ * One rewrite node. `subjects` is the relation's direct list, which a
143
+ * `this` node takes; it is checked against the node's presence by the
144
+ * caller.
145
+ */
146
+ function readRewrite(value, where, subjects) {
147
+ const node = record(value, where, [
148
+ "this",
149
+ "computedUserset",
150
+ "tupleToUserset",
151
+ "union",
152
+ "intersection",
153
+ "difference",
154
+ ]);
155
+ const keys = Object.keys(node);
156
+ if (keys.length !== 1) {
157
+ throw new Error(`${where}: a rewrite node has exactly one form, found ${keys.length}`);
158
+ }
159
+ const form = keys[0];
160
+ switch (form) {
161
+ case "this":
162
+ record(node["this"], `${where}.this`, []);
163
+ return { node: "this", subjects: subjects ?? [] };
164
+ case "computedUserset":
165
+ return { node: "computed", relation: localRelation(node["computedUserset"], `${where}.computedUserset`) };
166
+ case "tupleToUserset": {
167
+ const ttu = record(node["tupleToUserset"], `${where}.tupleToUserset`, [
168
+ "tupleset",
169
+ "computedUserset",
170
+ ]);
171
+ return {
172
+ node: "from",
173
+ tupleset: localRelation(ttu["tupleset"], `${where}.tupleToUserset.tupleset`),
174
+ relation: localRelation(ttu["computedUserset"], `${where}.tupleToUserset.computedUserset`),
175
+ };
176
+ }
177
+ case "union":
178
+ case "intersection": {
179
+ const operator = record(node[form], `${where}.${form}`, ["child"]);
180
+ const members = list(operator["child"], `${where}.${form}.child`).map((child, index) => readRewrite(child, `${where}.${form}.child[${index}]`, subjects));
181
+ if (members.length === 0) {
182
+ throw new Error(`${where}.${form}: an operator with no children`);
183
+ }
184
+ return { node: form, members };
185
+ }
186
+ case "difference":
187
+ throw new Error(`${where}: 'but not' (difference) is not evaluated by this server`);
188
+ default:
189
+ throw new Error(`${where}: unknown rewrite form '${String(form)}'`);
190
+ }
191
+ }
192
+ /** An `ObjectRelation` naming a relation of the same object: `object` must be unset. */
193
+ function localRelation(value, where) {
194
+ const entry = record(value, where, ["relation", "object"]);
195
+ if (entry["object"] !== undefined) {
196
+ throw new Error(`${where}: a relation on another object is not evaluated by this server`);
197
+ }
198
+ return text(entry["relation"], `${where}.relation`);
199
+ }
200
+ function containsThis(rewrite) {
201
+ switch (rewrite.node) {
202
+ case "this":
203
+ return true;
204
+ case "computed":
205
+ case "from":
206
+ return false;
207
+ case "union":
208
+ case "intersection":
209
+ return rewrite.members.some(containsThis);
210
+ default: {
211
+ const exhaustive = rewrite;
212
+ throw new Error(`unknown rewrite node: ${JSON.stringify(exhaustive)}`);
213
+ }
214
+ }
215
+ }
216
+ /** The cross-type re-assertions of the module header. */
217
+ function assertReferencesResolve(types, where) {
218
+ const byType = new Map(types.map((entry) => [entry.type, entry]));
219
+ for (const entry of types) {
220
+ for (const [name, rewrite] of entry.relations) {
221
+ const at = `${where}: ${entry.type}#${name}`;
222
+ walk(rewrite, (node) => {
223
+ switch (node.node) {
224
+ case "computed":
225
+ if (!entry.relations.has(node.relation)) {
226
+ throw new Error(`${at}: names relation '${node.relation}', which ${entry.type} does not define`);
227
+ }
228
+ return;
229
+ case "from":
230
+ if (!entry.relations.has(node.tupleset)) {
231
+ throw new Error(`${at}: names tupleset '${node.tupleset}', which ${entry.type} does not define`);
232
+ }
233
+ return;
234
+ case "this":
235
+ for (const subject of node.subjects) {
236
+ const target = byType.get(subject.type);
237
+ if (target === undefined) {
238
+ throw new Error(`${at}: admits subject type '${subject.type}', which the model does not define`);
239
+ }
240
+ if (subject.form === "userset" && !target.relations.has(subject.relation)) {
241
+ throw new Error(`${at}: admits '${subject.type}#${subject.relation}', which ${subject.type} does not define`);
242
+ }
243
+ }
244
+ return;
245
+ case "union":
246
+ case "intersection":
247
+ return;
248
+ default: {
249
+ const exhaustive = node;
250
+ throw new Error(`unknown rewrite node: ${JSON.stringify(exhaustive)}`);
251
+ }
252
+ }
253
+ });
254
+ }
255
+ }
256
+ }
257
+ /** Visits every node of a rewrite, depth first, in order. */
258
+ function walk(rewrite, visit) {
259
+ visit(rewrite);
260
+ if (rewrite.node === "union" || rewrite.node === "intersection") {
261
+ for (const member of rewrite.members) {
262
+ walk(member, visit);
263
+ }
264
+ }
265
+ }
266
+ //# sourceMappingURL=openfga-json.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openfga-json.js","sourceRoot":"","sources":["../../../src/authorization/model/openfga-json.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAGvD,sEAAsE;AACtE,MAAM,CAAC,MAAM,wBAAwB,GAAG,KAAK,CAAC;AAY9C,yGAAyG;AACzG,MAAM,gBAAgB,GAAG,WAAW,CAAC;AAErC;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAC9B,KAAc,EACd,KAAK,GAAG,0BAA0B;IAElC,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,CAAC,gBAAgB,EAAE,kBAAkB,EAAE,YAAY,CAAC,CAAC,CAAC;IACxF,IAAI,IAAI,CAAC,YAAY,CAAC,KAAK,SAAS,EAAE,CAAC;QACrC,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,+CAA+C,CAAC,CAAC;IAC3E,CAAC;IACD,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,EAAE,GAAG,KAAK,kBAAkB,CAAC,CAAC;IACzE,IAAI,OAAO,KAAK,wBAAwB,EAAE,CAAC;QACzC,MAAM,IAAI,KAAK,CACb,GAAG,KAAK,qBAAqB,OAAO,YAAY,wBAAwB,sCAAsC,CAC/G,CAAC;IACJ,CAAC;IAED,MAAM,KAAK,GAAgB,EAAE,CAAC;IAC9B,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,EAAE,GAAG,KAAK,oBAAoB,CAAC,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;QACpF,MAAM,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