@flowdular/sdk 0.2.4 → 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.
Files changed (908) hide show
  1. package/.ai/agents/sandbox/business-manager.md +5 -1
  2. package/.ai/blueprints/author-spec/README.md +1 -1
  3. package/.ai/blueprints/author-spec/spec-requirements.yaml +44 -0
  4. package/.ai/blueprints/author-spec/steps.yaml +5 -5
  5. package/.ai/blueprints/author-spec/templates/module.yaml +99 -3
  6. package/.ai/blueprints/edit-module/gates.yaml +4 -0
  7. package/.ai/blueprints/edit-module/required-files.yaml +9 -0
  8. package/.ai/blueprints/new-module/gates.yaml +4 -0
  9. package/.ai/blueprints/new-module/spec-requirements.yaml +2 -2
  10. package/.ai/blueprints/release/gates.yaml +4 -0
  11. package/.ai/platform-capabilities.md +128 -0
  12. package/.ai/policies/capabilities.yaml +100 -0
  13. package/.ai/policies/path-ownership.yaml +5 -2
  14. package/.ai/policies/task-budgets.yaml +5 -3
  15. package/.ai/references/catalog/module.json +4 -4
  16. package/.ai/references/catalog/package.json +2 -2
  17. package/.ai/references/catalog/spec/module.yaml +5 -3
  18. package/.ai/references/catalog/src/platform.ts +2 -0
  19. package/.ai/references/catalog/src/services/catalog-service.ts +89 -1
  20. package/.ai/references/catalog/src/services/data-classes.ts +47 -0
  21. package/.ai/references/catalog/src/services/database-repository.ts +98 -1
  22. package/.ai/references/catalog/src/services/repository.ts +22 -1
  23. package/.ai/references/catalog/tests/data-classes.test.ts +157 -0
  24. package/.ai/references/catalog.provenance.json +12 -10
  25. package/.ai/skills/README.md +10 -0
  26. package/.ai/skills/agent-tool-design/SKILL.md +1 -2
  27. package/.ai/skills/auth-security-review/SKILL.md +1 -1
  28. package/.ai/skills/business-agent-design/SKILL.md +0 -1
  29. package/.ai/skills/deploy-operate/SKILL.md +114 -0
  30. package/.ai/skills/module-new/SKILL.md +29 -3
  31. package/.ai/skills/module-update/SKILL.md +9 -3
  32. package/.ai/skills/perf-audit/SKILL.md +0 -1
  33. package/.ai/skills/release-eject-pr/SKILL.md +0 -1
  34. package/.ai/skills/spec-interview/SKILL.md +120 -0
  35. package/.ai/skills/test-hardening/SKILL.md +1 -0
  36. package/.ai/skills/ux-design/SKILL.md +34 -3
  37. package/.ai/skills/variables/SKILL.md +0 -2
  38. package/.ai/skills/workflow-development/SKILL.md +0 -1
  39. package/AGENTS.md +4 -0
  40. package/docs/agent-contract.md +2 -2
  41. package/docs/design-system.md +185 -31
  42. package/modules/access/migrations/0001_access_core.down.sql +1 -0
  43. package/modules/access/migrations/0001_access_core.up.sql +28 -0
  44. package/modules/access/migrations/README.md +3 -0
  45. package/modules/access/module.json +33 -0
  46. package/modules/access/package.json +43 -0
  47. package/modules/access/spec/module.yaml +225 -0
  48. package/modules/access/src/acl/permissions.ts +6 -0
  49. package/modules/access/src/api/endpoints.ts +244 -0
  50. package/modules/access/src/client/ActivityView.tsrx +245 -0
  51. package/modules/access/src/client/AttestationsView.tsrx +176 -0
  52. package/modules/access/src/client/ReviewView.tsrx +586 -0
  53. package/modules/access/src/client/api.ts +132 -0
  54. package/modules/access/src/client/contribution.tsrx +41 -0
  55. package/modules/access/src/client/index.ts +41 -0
  56. package/modules/access/src/client/navigation.ts +57 -0
  57. package/modules/access/src/client/presentation.ts +69 -0
  58. package/modules/access/src/client/state.ts +72 -0
  59. package/modules/access/src/domain/types.ts +189 -0
  60. package/modules/access/src/index.ts +38 -0
  61. package/modules/access/src/platform.ts +60 -0
  62. package/modules/access/src/server/index.ts +42 -0
  63. package/modules/access/src/server/runtime.ts +105 -0
  64. package/modules/access/src/services/access-service.ts +298 -0
  65. package/modules/access/src/services/audit-window.ts +78 -0
  66. package/modules/access/src/services/auth-directory.ts +72 -0
  67. package/modules/access/src/services/changes.ts +91 -0
  68. package/modules/access/src/services/data-classes.ts +28 -0
  69. package/modules/access/src/services/database-repository.ts +185 -0
  70. package/modules/access/src/services/directory.ts +102 -0
  71. package/modules/access/src/services/index.ts +33 -0
  72. package/modules/access/src/services/list-exports.ts +150 -0
  73. package/modules/access/src/services/migration.ts +54 -0
  74. package/modules/access/src/services/repository.ts +30 -0
  75. package/modules/access/src/services/review.ts +178 -0
  76. package/modules/access/translations/en.json +155 -0
  77. package/modules/access/translations/pl.json +155 -0
  78. package/modules/agents/migrations/0022_credential_rotation_inventory.down.sql +2 -0
  79. package/modules/agents/migrations/0022_credential_rotation_inventory.up.sql +7 -0
  80. package/modules/agents/migrations/0023_agents_retention_indexes.down.sql +2 -0
  81. package/modules/agents/migrations/0023_agents_retention_indexes.up.sql +9 -0
  82. package/modules/agents/migrations/0024_agent_meter_refusals.down.sql +3 -0
  83. package/modules/agents/migrations/0024_agent_meter_refusals.up.sql +22 -0
  84. package/modules/agents/migrations/0025_agent_list_indexes.down.sql +3 -0
  85. package/modules/agents/migrations/0025_agent_list_indexes.up.sql +11 -0
  86. package/modules/agents/module.json +30 -4
  87. package/modules/agents/package.json +2 -1
  88. package/modules/agents/spec/module.yaml +63 -5
  89. package/modules/agents/src/api/endpoints.ts +291 -33
  90. package/modules/agents/src/cli/commands.json +11 -0
  91. package/modules/agents/src/cli/index.ts +45 -0
  92. package/modules/agents/src/client/AgentDashboardWidget.tsrx +19 -11
  93. package/modules/agents/src/client/AgentDefinitionList.tsrx +53 -10
  94. package/modules/agents/src/client/AgentPlaygroundView.tsrx +4 -4
  95. package/modules/agents/src/client/AgentProceduresView.tsrx +2 -2
  96. package/modules/agents/src/client/AgentRunsView.tsrx +143 -40
  97. package/modules/agents/src/client/AgentsView.tsrx +109 -33
  98. package/modules/agents/src/client/api.ts +99 -21
  99. package/modules/agents/src/client/state.ts +97 -0
  100. package/modules/agents/src/domain/types.ts +44 -4
  101. package/modules/agents/src/platform.ts +42 -0
  102. package/modules/agents/src/server/action-execution.ts +201 -106
  103. package/modules/agents/src/server/runtime.ts +32 -0
  104. package/modules/agents/src/services/agent-service.ts +158 -30
  105. package/modules/agents/src/services/credential-rotation.ts +185 -0
  106. package/modules/agents/src/services/credential-vault.ts +71 -46
  107. package/modules/agents/src/services/data-classes.ts +176 -0
  108. package/modules/agents/src/services/database-repository.ts +393 -101
  109. package/modules/agents/src/services/metering.ts +111 -0
  110. package/modules/agents/src/services/migration.ts +109 -0
  111. package/modules/agents/src/services/module-agent-preflight.ts +17 -9
  112. package/modules/agents/src/services/notifications.ts +98 -0
  113. package/modules/agents/src/services/provider-repository.ts +9 -18
  114. package/modules/agents/src/services/provider-service.ts +1 -9
  115. package/modules/agents/src/services/reports.ts +107 -0
  116. package/modules/agents/src/services/repository.ts +86 -6
  117. package/modules/agents/src/services/usage-service.ts +2 -0
  118. package/modules/agents/src/services/worker.ts +114 -4
  119. package/modules/agents/src/settings.ts +14 -3
  120. package/modules/agents/translations/en.json +14 -4
  121. package/modules/agents/translations/pl.json +14 -4
  122. package/modules/approvals/migrations/0001_approvals_core.down.sql +3 -0
  123. package/modules/approvals/migrations/0001_approvals_core.up.sql +78 -0
  124. package/modules/approvals/migrations/0002_approvals_expiry_routing_role.down.sql +2 -0
  125. package/modules/approvals/migrations/0002_approvals_expiry_routing_role.up.sql +19 -0
  126. package/modules/approvals/migrations/0003_approvals_retention_indexes.down.sql +6 -0
  127. package/modules/approvals/migrations/0003_approvals_retention_indexes.up.sql +14 -0
  128. package/modules/approvals/migrations/0004_approvals_inbox_keyset_indexes.down.sql +5 -0
  129. package/modules/approvals/migrations/0004_approvals_inbox_keyset_indexes.up.sql +12 -0
  130. package/modules/approvals/migrations/README.md +3 -0
  131. package/modules/approvals/module.json +34 -0
  132. package/modules/approvals/package.json +43 -0
  133. package/modules/approvals/spec/module.yaml +318 -0
  134. package/modules/approvals/src/acl/permissions.ts +7 -0
  135. package/modules/approvals/src/api/endpoints.ts +457 -0
  136. package/modules/approvals/src/client/ApprovalRequestDrawer.tsrx +138 -0
  137. package/modules/approvals/src/client/ApprovalsView.tsrx +562 -0
  138. package/modules/approvals/src/client/PendingCountWidget.tsrx +52 -0
  139. package/modules/approvals/src/client/api.ts +203 -0
  140. package/modules/approvals/src/client/approvals.css +51 -0
  141. package/modules/approvals/src/client/contribution.tsrx +44 -0
  142. package/modules/approvals/src/client/index.ts +26 -0
  143. package/modules/approvals/src/client/navigation.ts +39 -0
  144. package/modules/approvals/src/client/pending-count.ts +26 -0
  145. package/modules/approvals/src/client/presentation.ts +52 -0
  146. package/modules/approvals/src/client/state.ts +141 -0
  147. package/modules/approvals/src/domain/capability.ts +95 -0
  148. package/modules/approvals/src/domain/types.ts +154 -0
  149. package/modules/approvals/src/index.ts +52 -0
  150. package/modules/approvals/src/platform.ts +128 -0
  151. package/modules/approvals/src/server/index.ts +42 -0
  152. package/modules/approvals/src/server/runtime.ts +181 -0
  153. package/modules/approvals/src/services/approvals-service.ts +557 -0
  154. package/modules/approvals/src/services/callbacks.ts +75 -0
  155. package/modules/approvals/src/services/data-classes.ts +167 -0
  156. package/modules/approvals/src/services/database-repository.ts +724 -0
  157. package/modules/approvals/src/services/eligibility.ts +121 -0
  158. package/modules/approvals/src/services/expiry-runner.ts +81 -0
  159. package/modules/approvals/src/services/index.ts +31 -0
  160. package/modules/approvals/src/services/migration.ts +222 -0
  161. package/modules/approvals/src/services/notifications.ts +95 -0
  162. package/modules/approvals/src/services/repository.ts +161 -0
  163. package/modules/approvals/src/services/service-error.ts +70 -0
  164. package/modules/approvals/src/settings.ts +102 -0
  165. package/modules/approvals/translations/en.json +104 -0
  166. package/modules/approvals/translations/pl.json +104 -0
  167. package/modules/audit/migrations/0001_audit_core.down.sql +8 -0
  168. package/modules/audit/migrations/0001_audit_core.up.sql +107 -0
  169. package/modules/audit/migrations/0002_audit_sweep_routing_role.down.sql +2 -0
  170. package/modules/audit/migrations/0002_audit_sweep_routing_role.up.sql +21 -0
  171. package/modules/audit/migrations/0003_audit_export_request.down.sql +12 -0
  172. package/modules/audit/migrations/0003_audit_export_request.up.sql +40 -0
  173. package/modules/audit/migrations/0004_audit_hold_seal_erasure.down.sql +17 -0
  174. package/modules/audit/migrations/0004_audit_hold_seal_erasure.up.sql +192 -0
  175. package/modules/audit/migrations/0005_audit_event_format.down.sql +17 -0
  176. package/modules/audit/migrations/0005_audit_event_format.up.sql +60 -0
  177. package/modules/audit/migrations/0006_audit_own_class_walks.down.sql +3 -0
  178. package/modules/audit/migrations/0006_audit_own_class_walks.up.sql +14 -0
  179. package/modules/audit/migrations/README.md +3 -0
  180. package/modules/audit/module.json +32 -0
  181. package/modules/audit/package.json +49 -0
  182. package/modules/audit/spec/module.yaml +809 -0
  183. package/modules/audit/src/acl/permissions.ts +7 -0
  184. package/modules/audit/src/api/endpoints.ts +315 -0
  185. package/modules/audit/src/cli/commands.json +95 -0
  186. package/modules/audit/src/cli/index.ts +658 -0
  187. package/modules/audit/src/client/DataClassesView.tsrx +420 -0
  188. package/modules/audit/src/client/ExportsView.tsrx +256 -0
  189. package/modules/audit/src/client/HoldsView.tsrx +604 -0
  190. package/modules/audit/src/client/SweepsView.tsrx +251 -0
  191. package/modules/audit/src/client/api.ts +185 -0
  192. package/modules/audit/src/client/contribution.tsrx +52 -0
  193. package/modules/audit/src/client/index.ts +23 -0
  194. package/modules/audit/src/client/navigation.ts +74 -0
  195. package/modules/audit/src/client/presentation.ts +105 -0
  196. package/modules/audit/src/client/state.ts +86 -0
  197. package/modules/audit/src/domain/data-classes.ts +16 -0
  198. package/modules/audit/src/domain/types.ts +339 -0
  199. package/modules/audit/src/index.ts +76 -0
  200. package/modules/audit/src/platform.ts +44 -0
  201. package/modules/audit/src/server/index.ts +177 -0
  202. package/modules/audit/src/server/runtime.ts +303 -0
  203. package/modules/audit/src/services/anchor-key.ts +143 -0
  204. package/modules/audit/src/services/anchor-rotation.ts +147 -0
  205. package/modules/audit/src/services/audit-runners.ts +278 -0
  206. package/modules/audit/src/services/backup-guard.ts +95 -0
  207. package/modules/audit/src/services/database-repository.ts +1946 -0
  208. package/modules/audit/src/services/declared-classes.ts +64 -0
  209. package/modules/audit/src/services/erasure-port.ts +126 -0
  210. package/modules/audit/src/services/erasure-service.ts +770 -0
  211. package/modules/audit/src/services/export-directory.ts +106 -0
  212. package/modules/audit/src/services/export-service.ts +714 -0
  213. package/modules/audit/src/services/hold-service.ts +295 -0
  214. package/modules/audit/src/services/index.ts +17 -0
  215. package/modules/audit/src/services/migration.ts +658 -0
  216. package/modules/audit/src/services/own-classes.ts +318 -0
  217. package/modules/audit/src/services/platform-version.ts +23 -0
  218. package/modules/audit/src/services/repository.ts +495 -0
  219. package/modules/audit/src/services/retention-service.ts +191 -0
  220. package/modules/audit/src/services/seal-service.ts +769 -0
  221. package/modules/audit/src/services/service-error.ts +61 -0
  222. package/modules/audit/src/services/subject-keys.ts +90 -0
  223. package/modules/audit/src/services/sweep-service.ts +298 -0
  224. package/modules/audit/src/services/zip.ts +217 -0
  225. package/modules/audit/src/settings.ts +69 -0
  226. package/modules/audit/translations/en.json +210 -0
  227. package/modules/audit/translations/pl.json +210 -0
  228. package/modules/auth/README.md +77 -29
  229. package/modules/auth/migrations/0016_external_identities.up.sql +16 -0
  230. package/modules/auth/migrations/0017_mfa_key_id.up.sql +8 -0
  231. package/modules/auth/migrations/0018_retire_bundled_module_scopes.up.sql +29 -0
  232. package/modules/auth/migrations/0019_notifications_member_scopes.up.sql +44 -0
  233. package/modules/auth/migrations/0020_identity_providers.up.sql +61 -0
  234. package/modules/auth/migrations/0021_membership_status.up.sql +19 -0
  235. package/modules/auth/migrations/0022_auth_provider_scopes.up.sql +45 -0
  236. package/modules/auth/migrations/0023_enterprise_module_scopes.down.sql +19 -0
  237. package/modules/auth/migrations/0023_enterprise_module_scopes.up.sql +71 -0
  238. package/modules/auth/migrations/0024_approvals_member_scopes.down.sql +22 -0
  239. package/modules/auth/migrations/0024_approvals_member_scopes.up.sql +48 -0
  240. package/modules/auth/migrations/0025_audit_holds_owner_scope.down.sql +21 -0
  241. package/modules/auth/migrations/0025_audit_holds_owner_scope.up.sql +47 -0
  242. package/modules/auth/migrations/0026_auth_export_keyset_indexes.down.sql +6 -0
  243. package/modules/auth/migrations/0026_auth_export_keyset_indexes.up.sql +15 -0
  244. package/modules/auth/migrations/0027_workflow_automation_profile_scopes.down.sql +34 -0
  245. package/modules/auth/migrations/0027_workflow_automation_profile_scopes.up.sql +72 -0
  246. package/modules/auth/migrations/0028_auth_member_search_prefix_indexes.down.sql +6 -0
  247. package/modules/auth/migrations/0028_auth_member_search_prefix_indexes.up.sql +21 -0
  248. package/modules/auth/migrations/0029_reports_exports_access_scopes.down.sql +22 -0
  249. package/modules/auth/migrations/0029_reports_exports_access_scopes.up.sql +56 -0
  250. package/modules/auth/migrations/0030_auth_membership_keyset_index.down.sql +4 -0
  251. package/modules/auth/migrations/0030_auth_membership_keyset_index.up.sql +10 -0
  252. package/modules/auth/migrations/0031_membership_scope_backfills_under_rls.down.sql +4 -0
  253. package/modules/auth/migrations/0031_membership_scope_backfills_under_rls.up.sql +31 -0
  254. package/modules/auth/migrations/0032_audit_actor_service.down.sql +9 -0
  255. package/modules/auth/migrations/0032_audit_actor_service.up.sql +10 -0
  256. package/modules/auth/migrations/0033_auth_account_keyset_indexes.down.sql +5 -0
  257. package/modules/auth/migrations/0033_auth_account_keyset_indexes.up.sql +23 -0
  258. package/modules/auth/module.json +3 -3
  259. package/modules/auth/package.json +2 -1
  260. package/modules/auth/spec/module.yaml +372 -3
  261. package/modules/auth/src/acl/scopes.ts +50 -6
  262. package/modules/auth/src/cli/commands.json +11 -0
  263. package/modules/auth/src/cli/greenfield.ts +2 -2
  264. package/modules/auth/src/cli/index.ts +14 -0
  265. package/modules/auth/src/cli/secrets.ts +114 -0
  266. package/modules/auth/src/client/AuthenticationCore.tsrx +61 -8
  267. package/modules/auth/src/client/api.ts +72 -6
  268. package/modules/auth/src/client/contribution.tsrx +23 -0
  269. package/modules/auth/src/client/index.ts +6 -0
  270. package/modules/auth/src/client/providers/IdentityProviderForm.tsrx +191 -0
  271. package/modules/auth/src/client/providers/IdentityProvidersView.tsrx +358 -0
  272. package/modules/auth/src/client/providers/api.ts +128 -0
  273. package/modules/auth/src/client/providers/provider-columns.tsrx +60 -0
  274. package/modules/auth/src/client/providers/state.ts +35 -0
  275. package/modules/auth/src/client/security/SecurityView.tsrx +9 -1
  276. package/modules/auth/src/client/state.ts +15 -1
  277. package/modules/auth/src/domain/types.ts +55 -0
  278. package/modules/auth/src/index.ts +11 -1
  279. package/modules/auth/src/middleware/authentication.ts +4 -0
  280. package/modules/auth/src/server/endpoints.ts +467 -171
  281. package/modules/auth/src/server/http.ts +3 -2
  282. package/modules/auth/src/server/index.ts +22 -1
  283. package/modules/auth/src/server/membership-endpoints.ts +62 -0
  284. package/modules/auth/src/server/mfa-enforcement.ts +156 -0
  285. package/modules/auth/src/server/oidc.ts +389 -0
  286. package/modules/auth/src/server/provider-endpoints.ts +246 -0
  287. package/modules/auth/src/server/provider-host.ts +77 -0
  288. package/modules/auth/src/server/runtime.ts +231 -55
  289. package/modules/auth/src/services/auth-service-error.ts +7 -2
  290. package/modules/auth/src/services/auth-service.ts +948 -51
  291. package/modules/auth/src/services/data-classes.ts +236 -0
  292. package/modules/auth/src/services/database-repository.ts +853 -71
  293. package/modules/auth/src/services/identity-provider-service.ts +571 -0
  294. package/modules/auth/src/services/mail-delivery.ts +16 -16
  295. package/modules/auth/src/services/mail-message.ts +54 -0
  296. package/modules/auth/src/services/mail-port.ts +24 -0
  297. package/modules/auth/src/services/mail-smtp.ts +85 -0
  298. package/modules/auth/src/services/mfa-rotation.ts +144 -0
  299. package/modules/auth/src/services/migration.ts +810 -0
  300. package/modules/auth/src/services/password.ts +14 -0
  301. package/modules/auth/src/services/provider-secret-rotation.ts +169 -0
  302. package/modules/auth/src/services/provider-secrets.ts +136 -0
  303. package/modules/auth/src/services/repository.ts +321 -5
  304. package/modules/auth/src/services/session-sweep-runner.ts +73 -0
  305. package/modules/auth/src/services/settings-store.ts +10 -83
  306. package/modules/auth/src/services/totp.ts +88 -62
  307. package/modules/auth/src/services/validation.ts +194 -7
  308. package/modules/auth/src/settings.ts +18 -0
  309. package/modules/auth/translations/en.json +84 -1
  310. package/modules/auth/translations/pl.json +84 -1
  311. package/modules/automations/migrations/0005_secret_rotation_inventory.down.sql +1 -0
  312. package/modules/automations/migrations/0005_secret_rotation_inventory.up.sql +6 -0
  313. package/modules/automations/migrations/0006_automations_list_sort_indexes.down.sql +4 -0
  314. package/modules/automations/migrations/0006_automations_list_sort_indexes.up.sql +11 -0
  315. package/modules/automations/module.json +24 -6
  316. package/modules/automations/package.json +4 -1
  317. package/modules/automations/spec/module.yaml +81 -7
  318. package/modules/automations/src/api/endpoints.ts +202 -28
  319. package/modules/automations/src/cli/commands.json +17 -0
  320. package/modules/automations/src/cli/index.ts +114 -0
  321. package/modules/automations/src/client/AutomationScheduleForm.tsrx +77 -19
  322. package/modules/automations/src/client/AutomationSchedulesView.tsrx +144 -40
  323. package/modules/automations/src/client/AutomationTriggersView.tsrx +131 -32
  324. package/modules/automations/src/client/api.ts +62 -19
  325. package/modules/automations/src/client/presentation.ts +20 -2
  326. package/modules/automations/src/client/state.ts +84 -0
  327. package/modules/automations/src/domain/cadence.ts +99 -3
  328. package/modules/automations/src/domain/cron.ts +366 -0
  329. package/modules/automations/src/domain/time-zone.ts +61 -0
  330. package/modules/automations/src/platform.ts +38 -4
  331. package/modules/automations/src/server/index.ts +11 -0
  332. package/modules/automations/src/server/runtime.ts +46 -22
  333. package/modules/{automations-workflows-integration/src/server/adapter.ts → automations/src/server/workflow-target.ts} +13 -14
  334. package/modules/{automations-workflows-integration/src/server/tools.ts → automations/src/server/workflow-tools.ts} +0 -0
  335. package/modules/automations/src/services/data-classes.ts +62 -0
  336. package/modules/automations/src/services/database-repository.ts +152 -38
  337. package/modules/automations/src/services/migration.ts +119 -9
  338. package/modules/automations/src/services/repository.ts +52 -1
  339. package/modules/automations/src/services/schedule-runner.ts +84 -0
  340. package/modules/automations/src/services/schedule-service.ts +152 -26
  341. package/modules/automations/src/services/secret-rotation.ts +176 -0
  342. package/modules/automations/src/services/secret-vault.ts +68 -41
  343. package/modules/automations/src/services/trigger-service.ts +13 -10
  344. package/modules/automations/translations/en.json +15 -2
  345. package/modules/automations/translations/pl.json +15 -2
  346. package/modules/connectors/migrations/0001_connectors_core.down.sql +3 -0
  347. package/modules/connectors/migrations/0001_connectors_core.up.sql +72 -0
  348. package/modules/connectors/migrations/0002_connectors_call_keys.down.sql +3 -0
  349. package/modules/connectors/migrations/0002_connectors_call_keys.up.sql +18 -0
  350. package/modules/connectors/migrations/README.md +3 -0
  351. package/modules/connectors/module.json +28 -0
  352. package/modules/{automations-workflows-integration → connectors}/package.json +27 -26
  353. package/modules/connectors/spec/module.yaml +447 -0
  354. package/modules/connectors/src/acl/permissions.ts +6 -0
  355. package/modules/connectors/src/agent/tools.ts +180 -0
  356. package/modules/connectors/src/api/endpoints.ts +572 -0
  357. package/modules/connectors/src/client/ConnectorCallsView.tsrx +358 -0
  358. package/modules/connectors/src/client/ConnectorForm.tsrx +424 -0
  359. package/modules/connectors/src/client/ConnectorsView.tsrx +711 -0
  360. package/modules/connectors/src/client/api.ts +281 -0
  361. package/modules/connectors/src/client/consent.ts +48 -0
  362. package/modules/connectors/src/client/contribution.tsrx +37 -0
  363. package/modules/connectors/src/client/index.ts +22 -0
  364. package/modules/connectors/src/client/navigation.ts +42 -0
  365. package/modules/connectors/src/client/presentation.ts +38 -0
  366. package/modules/connectors/src/client/state.ts +175 -0
  367. package/modules/connectors/src/domain/calls.ts +70 -0
  368. package/modules/connectors/src/domain/definitions.ts +190 -0
  369. package/modules/connectors/src/domain/http-json.ts +68 -0
  370. package/modules/connectors/src/domain/types.ts +185 -0
  371. package/modules/connectors/src/index.ts +64 -0
  372. package/modules/connectors/src/platform.ts +56 -0
  373. package/modules/connectors/src/server/index.ts +66 -0
  374. package/modules/connectors/src/server/runtime.ts +163 -0
  375. package/modules/connectors/src/services/call-service.ts +903 -0
  376. package/modules/connectors/src/services/connectors-service.ts +653 -0
  377. package/modules/connectors/src/services/credential-vault.ts +188 -0
  378. package/modules/connectors/src/services/data-classes.ts +158 -0
  379. package/modules/connectors/src/services/database-repository.ts +897 -0
  380. package/modules/connectors/src/services/egress.ts +261 -0
  381. package/modules/connectors/src/services/index.ts +19 -0
  382. package/modules/connectors/src/services/migration.ts +166 -0
  383. package/modules/connectors/src/services/repository.ts +175 -0
  384. package/modules/connectors/src/services/service-error.ts +46 -0
  385. package/modules/connectors/src/settings.ts +69 -0
  386. package/modules/connectors/translations/en.json +191 -0
  387. package/modules/connectors/translations/pl.json +191 -0
  388. package/modules/directory/migrations/0001_directory_core.down.sql +5 -0
  389. package/modules/directory/migrations/0001_directory_core.up.sql +111 -0
  390. package/modules/directory/migrations/README.md +3 -0
  391. package/modules/directory/module.json +27 -0
  392. package/modules/directory/package.json +46 -0
  393. package/modules/directory/spec/module.yaml +351 -0
  394. package/modules/directory/src/acl/permissions.ts +7 -0
  395. package/modules/directory/src/api/endpoints.ts +478 -0
  396. package/modules/directory/src/api/scim-endpoints.ts +516 -0
  397. package/modules/directory/src/client/GroupMappingsView.tsrx +430 -0
  398. package/modules/directory/src/client/ProvisioningLogView.tsrx +248 -0
  399. package/modules/directory/src/client/ScimTokensView.tsrx +587 -0
  400. package/modules/directory/src/client/api.ts +222 -0
  401. package/modules/directory/src/client/contribution.tsrx +46 -0
  402. package/modules/directory/src/client/index.ts +22 -0
  403. package/modules/directory/src/client/navigation.ts +57 -0
  404. package/modules/directory/src/client/presentation.ts +143 -0
  405. package/modules/directory/src/client/state.ts +173 -0
  406. package/modules/directory/src/domain/scim.ts +346 -0
  407. package/modules/directory/src/domain/types.ts +166 -0
  408. package/modules/directory/src/index.ts +44 -0
  409. package/modules/directory/src/platform.ts +43 -0
  410. package/modules/directory/src/server/index.ts +17 -0
  411. package/modules/directory/src/server/runtime.ts +124 -0
  412. package/modules/directory/src/services/auth-port.ts +127 -0
  413. package/modules/directory/src/services/data-classes.ts +41 -0
  414. package/modules/directory/src/services/database-repository.ts +1067 -0
  415. package/modules/directory/src/services/directory-service.ts +311 -0
  416. package/modules/directory/src/services/index.ts +43 -0
  417. package/modules/directory/src/services/migration.ts +146 -0
  418. package/modules/directory/src/services/provisioning-service.ts +1420 -0
  419. package/modules/directory/src/services/rate-limiter.ts +103 -0
  420. package/modules/directory/src/services/repository.ts +208 -0
  421. package/modules/directory/src/services/service-error.ts +42 -0
  422. package/modules/directory/src/services/token-service.ts +215 -0
  423. package/modules/directory/src/settings.ts +86 -0
  424. package/modules/directory/translations/en.json +185 -0
  425. package/modules/directory/translations/pl.json +185 -0
  426. package/modules/documents/migrations/0001_documents_core.down.sql +1 -0
  427. package/modules/documents/migrations/0001_documents_core.up.sql +35 -0
  428. package/modules/documents/migrations/0002_documents_files_page.down.sql +1 -0
  429. package/modules/documents/migrations/0002_documents_files_page.up.sql +6 -0
  430. package/modules/documents/migrations/README.md +3 -0
  431. package/modules/documents/module.json +28 -0
  432. package/modules/documents/package.json +49 -0
  433. package/modules/documents/spec/module.yaml +247 -0
  434. package/modules/documents/src/acl/permissions.ts +6 -0
  435. package/modules/documents/src/api/endpoints.ts +401 -0
  436. package/modules/documents/src/client/DocumentUploader.tsrx +148 -0
  437. package/modules/documents/src/client/DocumentsView.tsrx +540 -0
  438. package/modules/documents/src/client/api.ts +209 -0
  439. package/modules/documents/src/client/contribution.tsrx +29 -0
  440. package/modules/documents/src/client/download.ts +70 -0
  441. package/modules/documents/src/client/index.ts +22 -0
  442. package/modules/documents/src/client/navigation.ts +25 -0
  443. package/modules/documents/src/client/presentation.ts +110 -0
  444. package/modules/documents/src/client/state.ts +117 -0
  445. package/modules/documents/src/domain/attachments.ts +84 -0
  446. package/modules/documents/src/domain/types.ts +80 -0
  447. package/modules/documents/src/index.ts +46 -0
  448. package/modules/documents/src/platform.ts +61 -0
  449. package/modules/documents/src/server/index.ts +30 -0
  450. package/modules/documents/src/server/runtime.ts +107 -0
  451. package/modules/documents/src/services/attachments.ts +39 -0
  452. package/modules/documents/src/services/data-classes.ts +25 -0
  453. package/modules/documents/src/services/database-repository.ts +259 -0
  454. package/modules/documents/src/services/documents-service.ts +586 -0
  455. package/modules/documents/src/services/index.ts +18 -0
  456. package/modules/documents/src/services/migration.ts +82 -0
  457. package/modules/documents/src/services/repository.ts +48 -0
  458. package/modules/documents/src/settings.ts +107 -0
  459. package/modules/documents/translations/en.json +111 -0
  460. package/modules/documents/translations/pl.json +111 -0
  461. package/modules/exports/migrations/0001_exports_core.down.sql +2 -0
  462. package/modules/exports/migrations/0001_exports_core.up.sql +28 -0
  463. package/modules/exports/migrations/0002_exports_job_routing_role.down.sql +4 -0
  464. package/modules/exports/migrations/0002_exports_job_routing_role.up.sql +21 -0
  465. package/modules/exports/migrations/README.md +3 -0
  466. package/modules/exports/module.json +28 -0
  467. package/modules/exports/package.json +44 -0
  468. package/modules/exports/spec/module.yaml +229 -0
  469. package/modules/exports/src/acl/permissions.ts +6 -0
  470. package/modules/exports/src/api/endpoints.ts +211 -0
  471. package/modules/exports/src/client/ExportsView.tsrx +327 -0
  472. package/modules/exports/src/client/api.ts +133 -0
  473. package/modules/exports/src/client/contribution.tsrx +31 -0
  474. package/modules/exports/src/client/index.ts +20 -0
  475. package/modules/exports/src/client/navigation.ts +25 -0
  476. package/modules/exports/src/client/presentation.ts +53 -0
  477. package/modules/exports/src/client/state.ts +56 -0
  478. package/modules/exports/src/domain/lists.ts +29 -0
  479. package/modules/exports/src/domain/types.ts +120 -0
  480. package/modules/exports/src/index.ts +41 -0
  481. package/modules/exports/src/platform.ts +80 -0
  482. package/modules/exports/src/server/index.ts +51 -0
  483. package/modules/exports/src/server/runtime.ts +160 -0
  484. package/modules/exports/src/services/data-classes.ts +56 -0
  485. package/modules/exports/src/services/database-repository.ts +405 -0
  486. package/modules/exports/src/services/export-runner.ts +123 -0
  487. package/modules/exports/src/services/export-service.ts +356 -0
  488. package/modules/exports/src/services/index.ts +6 -0
  489. package/modules/exports/src/services/list-registry.ts +105 -0
  490. package/modules/exports/src/services/migration.ts +89 -0
  491. package/modules/exports/src/services/repository.ts +97 -0
  492. package/modules/exports/src/settings.ts +70 -0
  493. package/modules/exports/translations/en.json +69 -0
  494. package/modules/exports/translations/pl.json +69 -0
  495. package/modules/import/migrations/0001_import_core.down.sql +6 -0
  496. package/modules/import/migrations/0001_import_core.up.sql +61 -0
  497. package/modules/import/migrations/0002_import_job_routing_role.down.sql +4 -0
  498. package/modules/import/migrations/0002_import_job_routing_role.up.sql +20 -0
  499. package/modules/import/migrations/0003_import_jobs_export_index.down.sql +1 -0
  500. package/modules/import/migrations/0003_import_jobs_export_index.up.sql +7 -0
  501. package/modules/import/migrations/0004_import_jobs_traceparent.down.sql +1 -0
  502. package/modules/import/migrations/0004_import_jobs_traceparent.up.sql +7 -0
  503. package/modules/import/migrations/README.md +3 -0
  504. package/modules/import/module.json +37 -0
  505. package/modules/import/package.json +50 -0
  506. package/modules/import/spec/module.yaml +335 -0
  507. package/modules/import/src/acl/permissions.ts +6 -0
  508. package/modules/import/src/api/endpoints.ts +400 -0
  509. package/modules/import/src/client/ImportJobDrawer.tsrx +229 -0
  510. package/modules/import/src/client/ImportsView.tsrx +455 -0
  511. package/modules/import/src/client/NewImportForm.tsrx +274 -0
  512. package/modules/import/src/client/api.ts +243 -0
  513. package/modules/import/src/client/contribution.tsrx +29 -0
  514. package/modules/import/src/client/index.ts +23 -0
  515. package/modules/import/src/client/navigation.ts +25 -0
  516. package/modules/import/src/client/presentation.ts +59 -0
  517. package/modules/import/src/client/state.ts +43 -0
  518. package/modules/import/src/domain/csv.ts +258 -0
  519. package/modules/import/src/domain/ports.ts +157 -0
  520. package/modules/import/src/domain/types.ts +179 -0
  521. package/modules/import/src/index.ts +58 -0
  522. package/modules/import/src/platform.ts +60 -0
  523. package/modules/import/src/server/index.ts +49 -0
  524. package/modules/import/src/server/runtime.ts +158 -0
  525. package/modules/import/src/services/csv-source.ts +121 -0
  526. package/modules/import/src/services/data-classes.ts +63 -0
  527. package/modules/import/src/services/database-repository.ts +780 -0
  528. package/modules/import/src/services/import-runner.ts +127 -0
  529. package/modules/import/src/services/import-service.ts +872 -0
  530. package/modules/import/src/services/index.ts +6 -0
  531. package/modules/import/src/services/migration.ts +156 -0
  532. package/modules/import/src/services/port-registry.ts +158 -0
  533. package/modules/import/src/services/repository.ts +147 -0
  534. package/modules/import/src/settings.ts +70 -0
  535. package/modules/import/translations/en.json +175 -0
  536. package/modules/import/translations/pl.json +175 -0
  537. package/modules/metering/migrations/0001_metering_core.down.sql +6 -0
  538. package/modules/metering/migrations/0001_metering_core.up.sql +119 -0
  539. package/modules/metering/migrations/0002_metering_bucket_export.down.sql +3 -0
  540. package/modules/metering/migrations/0002_metering_bucket_export.up.sql +5 -0
  541. package/modules/metering/migrations/README.md +3 -0
  542. package/modules/metering/module.json +46 -0
  543. package/modules/metering/package.json +50 -0
  544. package/modules/metering/spec/module.yaml +269 -0
  545. package/modules/metering/src/acl/permissions.ts +5 -0
  546. package/modules/metering/src/api/endpoints.ts +104 -0
  547. package/modules/metering/src/cli/commands.json +28 -0
  548. package/modules/metering/src/cli/index.ts +246 -0
  549. package/modules/metering/src/client/LimitsView.tsrx +170 -0
  550. package/modules/metering/src/client/UsageSummaryWidget.tsrx +63 -0
  551. package/modules/metering/src/client/UsageView.tsrx +205 -0
  552. package/modules/metering/src/client/api.ts +91 -0
  553. package/modules/metering/src/client/contribution.tsrx +42 -0
  554. package/modules/metering/src/client/index.ts +26 -0
  555. package/modules/metering/src/client/navigation.ts +54 -0
  556. package/modules/metering/src/client/presentation.ts +63 -0
  557. package/modules/metering/src/client/state.ts +31 -0
  558. package/modules/metering/src/domain/meters.ts +100 -0
  559. package/modules/metering/src/domain/types.ts +71 -0
  560. package/modules/metering/src/index.ts +51 -0
  561. package/modules/metering/src/platform.ts +84 -0
  562. package/modules/metering/src/server/index.ts +40 -0
  563. package/modules/metering/src/server/runtime.ts +165 -0
  564. package/modules/metering/src/services/data-classes.ts +34 -0
  565. package/modules/metering/src/services/database-repository.ts +574 -0
  566. package/modules/metering/src/services/index.ts +9 -0
  567. package/modules/metering/src/services/meter-registry.ts +145 -0
  568. package/modules/metering/src/services/metering-service.ts +441 -0
  569. package/modules/metering/src/services/migration.ts +183 -0
  570. package/modules/metering/src/services/notifications.ts +75 -0
  571. package/modules/metering/src/services/reports.ts +105 -0
  572. package/modules/metering/src/services/repository.ts +132 -0
  573. package/modules/metering/src/services/service-error.ts +46 -0
  574. package/modules/metering/src/settings.ts +47 -0
  575. package/modules/metering/translations/en.json +68 -0
  576. package/modules/metering/translations/pl.json +68 -0
  577. package/modules/notifications/migrations/0001_notifications_core.down.sql +1 -0
  578. package/modules/notifications/migrations/0001_notifications_core.up.sql +26 -0
  579. package/modules/notifications/migrations/0002_notifications_preferences.down.sql +1 -0
  580. package/modules/notifications/migrations/0002_notifications_preferences.up.sql +17 -0
  581. package/modules/notifications/migrations/0003_notifications_webhook_subscriptions.down.sql +1 -0
  582. package/modules/notifications/migrations/0003_notifications_webhook_subscriptions.up.sql +30 -0
  583. package/modules/notifications/migrations/0004_notifications_deliveries.down.sql +1 -0
  584. package/modules/notifications/migrations/0004_notifications_deliveries.up.sql +35 -0
  585. package/modules/notifications/migrations/0005_notifications_delivery_routing_role.down.sql +2 -0
  586. package/modules/notifications/migrations/0005_notifications_delivery_routing_role.up.sql +17 -0
  587. package/modules/notifications/migrations/0006_notifications_delivery_title.down.sql +1 -0
  588. package/modules/notifications/migrations/0006_notifications_delivery_title.up.sql +11 -0
  589. package/modules/notifications/migrations/0007_notifications_secret_rotation_inventory.down.sql +2 -0
  590. package/modules/notifications/migrations/0007_notifications_secret_rotation_inventory.up.sql +19 -0
  591. package/modules/notifications/migrations/0008_notifications_delivery_claim.down.sql +8 -0
  592. package/modules/notifications/migrations/0008_notifications_delivery_claim.up.sql +19 -0
  593. package/modules/notifications/migrations/0009_notifications_kind_approvals.down.sql +16 -0
  594. package/modules/notifications/migrations/0009_notifications_kind_approvals.up.sql +18 -0
  595. package/modules/notifications/migrations/0010_notifications_kind_meter_threshold.down.sql +16 -0
  596. package/modules/notifications/migrations/0010_notifications_kind_meter_threshold.up.sql +18 -0
  597. package/modules/notifications/migrations/0011_notifications_retention_keyset.down.sql +5 -0
  598. package/modules/notifications/migrations/0011_notifications_retention_keyset.up.sql +15 -0
  599. package/modules/notifications/migrations/0012_notifications_email_channel.down.sql +12 -0
  600. package/modules/notifications/migrations/0012_notifications_email_channel.up.sql +38 -0
  601. package/modules/notifications/migrations/0013_notifications_list_pages.down.sql +5 -0
  602. package/modules/notifications/migrations/0013_notifications_list_pages.up.sql +13 -0
  603. package/modules/notifications/migrations/README.md +3 -0
  604. package/modules/notifications/module.json +32 -0
  605. package/modules/notifications/package.json +49 -0
  606. package/modules/notifications/spec/module.yaml +718 -0
  607. package/modules/notifications/src/acl/permissions.ts +11 -0
  608. package/modules/notifications/src/api/endpoints.ts +814 -0
  609. package/modules/notifications/src/cli/commands.json +17 -0
  610. package/modules/notifications/src/cli/index.ts +126 -0
  611. package/modules/notifications/src/client/DeliveriesView.tsrx +483 -0
  612. package/modules/notifications/src/client/FactList.tsrx +24 -0
  613. package/modules/notifications/src/client/NotificationPreferencesView.tsrx +240 -0
  614. package/modules/notifications/src/client/NotificationsInboxView.tsrx +592 -0
  615. package/modules/notifications/src/client/UnreadCountWidget.tsrx +62 -0
  616. package/modules/notifications/src/client/WebhookForm.tsrx +297 -0
  617. package/modules/notifications/src/client/WebhooksView.tsrx +637 -0
  618. package/modules/notifications/src/client/api.ts +382 -0
  619. package/modules/notifications/src/client/contribution.tsrx +83 -0
  620. package/modules/notifications/src/client/inbox.ts +41 -0
  621. package/modules/notifications/src/client/index.ts +29 -0
  622. package/modules/notifications/src/client/navigation.ts +92 -0
  623. package/modules/notifications/src/client/notifications.css +70 -0
  624. package/modules/notifications/src/client/presentation.ts +81 -0
  625. package/modules/notifications/src/client/state.ts +246 -0
  626. package/modules/notifications/src/client/unread-count.ts +26 -0
  627. package/modules/notifications/src/domain/locale.ts +47 -0
  628. package/modules/notifications/src/domain/publish.ts +46 -0
  629. package/modules/notifications/src/domain/types.ts +186 -0
  630. package/modules/notifications/src/index.ts +62 -0
  631. package/modules/notifications/src/platform.ts +85 -0
  632. package/modules/notifications/src/server/index.ts +82 -0
  633. package/modules/notifications/src/server/runtime.ts +251 -0
  634. package/modules/notifications/src/services/data-classes.ts +139 -0
  635. package/modules/notifications/src/services/database-repository.ts +1334 -0
  636. package/modules/notifications/src/services/delivery-payload.ts +93 -0
  637. package/modules/notifications/src/services/delivery-runner.ts +170 -0
  638. package/modules/notifications/src/services/delivery-service.ts +811 -0
  639. package/modules/notifications/src/services/egress.ts +239 -0
  640. package/modules/notifications/src/services/email-channel.ts +93 -0
  641. package/modules/notifications/src/services/index.ts +23 -0
  642. package/modules/notifications/src/services/migration.ts +572 -0
  643. package/modules/notifications/src/services/notifications-service.ts +297 -0
  644. package/modules/notifications/src/services/paging.ts +60 -0
  645. package/modules/notifications/src/services/publish-service.ts +133 -0
  646. package/modules/notifications/src/services/repository.ts +342 -0
  647. package/modules/notifications/src/services/secret-rotation.ts +177 -0
  648. package/modules/notifications/src/services/secret-vault.ts +168 -0
  649. package/modules/notifications/src/services/service-error.ts +67 -0
  650. package/modules/notifications/src/services/signature.ts +81 -0
  651. package/modules/notifications/src/services/webhook-service.ts +307 -0
  652. package/modules/notifications/src/settings.ts +130 -0
  653. package/modules/notifications/translations/en.json +255 -0
  654. package/modules/notifications/translations/pl.json +255 -0
  655. package/modules/profile/module.json +3 -3
  656. package/modules/profile/package.json +1 -1
  657. package/modules/profile/spec/module.yaml +3 -3
  658. package/modules/profile/src/services/database-repository.ts +3 -13
  659. package/modules/reports/module.json +28 -0
  660. package/modules/reports/package.json +42 -0
  661. package/modules/reports/spec/module.yaml +231 -0
  662. package/modules/reports/src/acl/permissions.ts +5 -0
  663. package/modules/reports/src/api/endpoints.ts +72 -0
  664. package/modules/reports/src/client/ReportsSummaryWidget.tsrx +52 -0
  665. package/modules/reports/src/client/ReportsView.tsrx +246 -0
  666. package/modules/reports/src/client/api.ts +65 -0
  667. package/modules/reports/src/client/contribution.tsrx +36 -0
  668. package/modules/reports/src/client/index.ts +18 -0
  669. package/modules/reports/src/client/navigation.ts +39 -0
  670. package/modules/reports/src/client/presentation.ts +123 -0
  671. package/modules/reports/src/client/state.ts +28 -0
  672. package/modules/reports/src/domain/providers.ts +115 -0
  673. package/modules/reports/src/domain/types.ts +44 -0
  674. package/modules/reports/src/index.ts +47 -0
  675. package/modules/reports/src/platform.ts +37 -0
  676. package/modules/reports/src/server/index.ts +21 -0
  677. package/modules/reports/src/server/runtime.ts +40 -0
  678. package/modules/reports/src/services/index.ts +17 -0
  679. package/modules/reports/src/services/provider-registry.ts +144 -0
  680. package/modules/reports/src/services/range.ts +65 -0
  681. package/modules/reports/src/services/reports-service.ts +316 -0
  682. package/modules/reports/src/services/service-error.ts +26 -0
  683. package/modules/reports/src/settings.ts +49 -0
  684. package/modules/reports/translations/en.json +35 -0
  685. package/modules/reports/translations/pl.json +35 -0
  686. package/modules/sandbox/module.json +4 -4
  687. package/modules/sandbox/package.json +1 -1
  688. package/modules/sandbox/spec/module.yaml +3 -3
  689. package/modules/sandbox/src/services/database-repository.ts +14 -23
  690. package/modules/sandbox/src/services/directory.ts +16 -0
  691. package/modules/sandbox/src/services/sandbox-service.ts +13 -11
  692. package/modules/search/migrations/0001_search_core.down.sql +1 -0
  693. package/modules/search/migrations/0001_search_core.up.sql +22 -0
  694. package/modules/search/migrations/0002_search_recent_export.down.sql +3 -0
  695. package/modules/search/migrations/0002_search_recent_export.up.sql +5 -0
  696. package/modules/search/migrations/README.md +3 -0
  697. package/modules/search/module.json +28 -0
  698. package/modules/search/package.json +43 -0
  699. package/modules/search/spec/module.yaml +177 -0
  700. package/modules/search/src/acl/permissions.ts +5 -0
  701. package/modules/search/src/api/endpoints.ts +221 -0
  702. package/modules/search/src/client/SearchView.tsrx +346 -0
  703. package/modules/search/src/client/api.ts +157 -0
  704. package/modules/search/src/client/contribution.tsrx +31 -0
  705. package/modules/search/src/client/index.ts +17 -0
  706. package/modules/search/src/client/navigation.ts +97 -0
  707. package/modules/search/src/client/search.css +56 -0
  708. package/modules/search/src/client/state.ts +113 -0
  709. package/modules/search/src/domain/data-classes.ts +73 -0
  710. package/modules/search/src/domain/providers.ts +88 -0
  711. package/modules/search/src/domain/types.ts +56 -0
  712. package/modules/search/src/index.ts +46 -0
  713. package/modules/search/src/platform.ts +42 -0
  714. package/modules/search/src/server/index.ts +25 -0
  715. package/modules/search/src/server/runtime.ts +123 -0
  716. package/modules/search/src/services/database-repository.ts +163 -0
  717. package/modules/search/src/services/index.ts +21 -0
  718. package/modules/search/src/services/migration.ts +65 -0
  719. package/modules/search/src/services/provider-registry.ts +137 -0
  720. package/modules/search/src/services/repository.ts +43 -0
  721. package/modules/search/src/services/search-service.ts +442 -0
  722. package/modules/search/src/services/service-error.ts +35 -0
  723. package/modules/search/src/settings.ts +68 -0
  724. package/modules/search/translations/en.json +45 -0
  725. package/modules/search/translations/pl.json +45 -0
  726. package/modules/system/module.json +2 -2
  727. package/modules/system/package.json +1 -1
  728. package/modules/system/spec/module.yaml +30 -3
  729. package/modules/system/src/client/FlagsPanel.tsrx +127 -0
  730. package/modules/system/src/client/ModuleSettingRow.tsrx +17 -7
  731. package/modules/system/src/client/ModuleSettingsSection.tsrx +10 -71
  732. package/modules/system/src/client/ModulesView.tsrx +91 -65
  733. package/modules/system/src/client/flags.ts +35 -0
  734. package/modules/system/src/client/index.ts +8 -0
  735. package/modules/system/src/client/navigation.ts +8 -0
  736. package/modules/system/src/client/settings-state.ts +159 -0
  737. package/modules/system/src/client/state.ts +2 -0
  738. package/modules/system/src/domain/time-zone.ts +105 -0
  739. package/modules/system/src/index.ts +12 -0
  740. package/modules/system/src/platform.ts +5 -1
  741. package/modules/system/src/server/endpoints.ts +72 -21
  742. package/modules/system/src/settings.ts +28 -0
  743. package/modules/system/translations/en.json +17 -0
  744. package/modules/system/translations/pl.json +17 -0
  745. package/modules/users/module.json +30 -4
  746. package/modules/users/package.json +4 -1
  747. package/modules/users/spec/module.yaml +290 -7
  748. package/modules/users/src/api/endpoints.ts +228 -15
  749. package/modules/users/src/client/InviteMemberForm.tsrx +2 -2
  750. package/modules/users/src/client/MemberDrawer.tsrx +142 -26
  751. package/modules/users/src/client/UserAccountForm.tsrx +2 -2
  752. package/modules/users/src/client/UsersView.tsrx +432 -71
  753. package/modules/users/src/client/api.ts +106 -12
  754. package/modules/users/src/client/contribution.tsrx +5 -0
  755. package/modules/users/src/client/member-columns.tsrx +22 -9
  756. package/modules/users/src/client/state.ts +172 -7
  757. package/modules/users/src/domain/lists.ts +9 -0
  758. package/modules/users/src/index.ts +11 -0
  759. package/modules/users/src/platform.ts +50 -1
  760. package/modules/users/src/services/member-export.ts +51 -0
  761. package/modules/users/src/services/member-import.ts +249 -0
  762. package/modules/users/src/services/member-search.ts +145 -0
  763. package/modules/users/src/services/users-service.ts +117 -4
  764. package/modules/users/translations/en.json +57 -8
  765. package/modules/users/translations/pl.json +57 -8
  766. package/modules/workflows/migrations/0004_payload_rotation_inventory.up.sql +17 -0
  767. package/modules/workflows/migrations/0005_workflows_human_approval.up.sql +28 -0
  768. package/modules/workflows/migrations/0006_workflows_retention_indexes.up.sql +11 -0
  769. package/modules/workflows/migrations/0007_workflows_erasure_subject_indexes.up.sql +17 -0
  770. package/modules/workflows/migrations/0008_workflows_subject_account.up.sql +24 -0
  771. package/modules/workflows/migrations/0009_workflows_definition_list_indexes.up.sql +9 -0
  772. package/modules/workflows/module.json +34 -6
  773. package/modules/workflows/package.json +2 -1
  774. package/modules/workflows/spec/module.yaml +26 -9
  775. package/modules/workflows/src/api/endpoints.ts +131 -25
  776. package/modules/workflows/src/cli/commands.json +17 -0
  777. package/modules/workflows/src/cli/index.ts +114 -0
  778. package/modules/workflows/src/client/WorkflowExecutionHistory.tsrx +36 -27
  779. package/modules/workflows/src/client/WorkflowInspector.tsrx +116 -0
  780. package/modules/workflows/src/client/WorkflowNodePalette.tsrx +1 -0
  781. package/modules/workflows/src/client/WorkflowsView.tsrx +236 -99
  782. package/modules/workflows/src/client/api.ts +54 -34
  783. package/modules/workflows/src/client/canvas-model.ts +12 -0
  784. package/modules/workflows/src/client/state.ts +95 -0
  785. package/modules/workflows/src/domain/events.ts +25 -11
  786. package/modules/workflows/src/domain/graph.ts +135 -1
  787. package/modules/workflows/src/domain/types.ts +91 -4
  788. package/modules/workflows/src/platform.ts +12 -0
  789. package/modules/workflows/src/server/runtime.ts +78 -5
  790. package/modules/workflows/src/services/approvals.ts +62 -0
  791. package/modules/workflows/src/services/cursors.ts +37 -0
  792. package/modules/workflows/src/services/data-classes.ts +232 -0
  793. package/modules/workflows/src/services/database-repository.ts +660 -171
  794. package/modules/workflows/src/services/migration.ts +240 -0
  795. package/modules/workflows/src/services/notifications.ts +98 -0
  796. package/modules/workflows/src/services/payload-codec.ts +51 -28
  797. package/modules/workflows/src/services/payload-rotation.ts +171 -0
  798. package/modules/workflows/src/services/repository.ts +123 -8
  799. package/modules/workflows/src/services/simulation.ts +7 -0
  800. package/modules/workflows/src/services/worker.ts +446 -25
  801. package/modules/workflows/src/services/workflows-service.ts +264 -103
  802. package/modules/workflows/translations/en.json +12 -4
  803. package/modules/workflows/translations/pl.json +12 -4
  804. package/modules.json +48 -4
  805. package/package.json +64 -6
  806. package/packages/client/package.json +1 -0
  807. package/packages/client/src/ApplicationShell.tsrx +43 -0
  808. package/packages/client/src/contributions.ts +55 -0
  809. package/packages/client/src/i18n/locales/en.json +5 -0
  810. package/packages/client/src/i18n/locales/pl.json +5 -0
  811. package/packages/client/src/index.ts +13 -1
  812. package/packages/client/src/routing.ts +22 -0
  813. package/packages/client/src/shell/CommandPalette.tsrx +223 -11
  814. package/packages/client/src/shell/command-search.ts +126 -0
  815. package/packages/client/src/shell/command.ts +30 -0
  816. package/packages/client/src/shell/navigation.ts +12 -0
  817. package/packages/client/src/shell/palette-keys.ts +27 -0
  818. package/packages/client/src/shell/shell.css +7 -0
  819. package/packages/contracts/schemas/module-spec.schema.json +287 -1
  820. package/packages/contracts/schemas/module.schema.json +25 -0
  821. package/packages/contracts/src/index.ts +144 -1
  822. package/packages/database/src/backup.ts +179 -0
  823. package/packages/database/src/decoders.ts +25 -0
  824. package/packages/database/src/index.ts +17 -0
  825. package/packages/database/src/record-history.ts +5 -14
  826. package/packages/harness/src/index.ts +2 -0
  827. package/packages/harness/src/runtime.ts +218 -1
  828. package/packages/harness/src/tool-adapters.ts +19 -1
  829. package/packages/kernel/src/acl.ts +179 -0
  830. package/packages/kernel/src/capability-registry.ts +69 -2
  831. package/packages/kernel/src/data-class-registry.ts +354 -0
  832. package/packages/kernel/src/index.ts +65 -4
  833. package/packages/kernel/src/keyring.ts +208 -0
  834. package/packages/kernel/src/module-compatibility.ts +35 -4
  835. package/packages/kernel/src/module-registry.ts +49 -2
  836. package/packages/kernel/src/module-settings.ts +189 -27
  837. package/packages/server/package.json +2 -1
  838. package/packages/server/src/composition.ts +38 -0
  839. package/packages/server/src/endpoint.ts +104 -47
  840. package/packages/server/src/export/csv.ts +34 -0
  841. package/packages/server/src/export/definition.ts +346 -0
  842. package/packages/server/src/export/index.ts +61 -0
  843. package/packages/server/src/export/run.ts +116 -0
  844. package/packages/server/src/index.ts +155 -0
  845. package/packages/server/src/jobs/index.ts +93 -0
  846. package/packages/server/src/jobs/runner.ts +486 -0
  847. package/packages/server/src/log.ts +291 -0
  848. package/packages/server/src/mail/config.ts +184 -0
  849. package/packages/server/src/mail/contracts.ts +251 -0
  850. package/packages/server/src/mail/index.ts +31 -0
  851. package/packages/server/src/mail/port.ts +101 -0
  852. package/packages/server/src/mail/smtp.ts +191 -0
  853. package/packages/server/src/mail/template.ts +105 -0
  854. package/packages/server/src/metrics.ts +447 -0
  855. package/packages/server/src/pagination.ts +246 -0
  856. package/packages/server/src/trace/context.ts +103 -0
  857. package/packages/server/src/trace/egress.ts +66 -0
  858. package/packages/server/src/trace/error-sink.ts +296 -0
  859. package/packages/server/src/trace/exporter.ts +295 -0
  860. package/packages/server/src/trace/index.ts +60 -0
  861. package/packages/server/src/trace/job-sink.ts +172 -0
  862. package/packages/server/src/trace/tracer.ts +338 -0
  863. package/packages/server/src/web.ts +5 -1
  864. package/packages/storage/package.json +40 -0
  865. package/packages/storage/src/config.ts +189 -0
  866. package/packages/storage/src/content-type.ts +124 -0
  867. package/packages/storage/src/contracts.ts +112 -0
  868. package/packages/storage/src/envelope.ts +189 -0
  869. package/packages/storage/src/index.ts +43 -0
  870. package/packages/storage/src/local.ts +75 -0
  871. package/packages/storage/src/port.ts +251 -0
  872. package/packages/storage/src/read-token.ts +130 -0
  873. package/packages/storage/src/s3.ts +144 -0
  874. package/packages/storage/src/scanner.ts +22 -0
  875. package/packages/storage/src/sigv4.ts +104 -0
  876. package/packages/storage/src/store.ts +13 -0
  877. package/packages/ui/package.json +1 -0
  878. package/packages/ui/src/components/Button.tsrx +3 -0
  879. package/packages/ui/src/components/ConfirmDialog.tsrx +13 -2
  880. package/packages/ui/src/components/DateField.tsrx +92 -0
  881. package/packages/ui/src/components/DatePicker.tsrx +525 -0
  882. package/packages/ui/src/components/DateRangeField.tsrx +93 -0
  883. package/packages/ui/src/components/Drawer.tsrx +10 -1
  884. package/packages/ui/src/components/FileUpload.tsrx +158 -0
  885. package/packages/ui/src/components/Pagination.tsrx +130 -0
  886. package/packages/ui/src/components/Select.tsrx +78 -0
  887. package/packages/ui/src/components/Table.tsrx +498 -81
  888. package/packages/ui/src/components/Tabs.tsrx +53 -0
  889. package/packages/ui/src/components/ToastHost.tsrx +48 -0
  890. package/packages/ui/src/components/calendar.ts +243 -0
  891. package/packages/ui/src/components/date-field.ts +62 -0
  892. package/packages/ui/src/components/file-upload.ts +49 -0
  893. package/packages/ui/src/components/focus-trap.ts +62 -0
  894. package/packages/ui/src/components/pagination.ts +68 -0
  895. package/packages/ui/src/components/table-sorting.ts +49 -0
  896. package/packages/ui/src/components/tabs.ts +61 -0
  897. package/packages/ui/src/components/toast-store.ts +116 -0
  898. package/packages/ui/src/icons/Icon.tsrx +5 -0
  899. package/packages/ui/src/index.ts +45 -0
  900. package/packages/ui/src/styles/components.css +598 -0
  901. package/modules/automations-workflows-integration/module.json +0 -27
  902. package/modules/automations-workflows-integration/spec/module.yaml +0 -93
  903. package/modules/automations-workflows-integration/src/index.ts +0 -14
  904. package/modules/automations-workflows-integration/src/platform.ts +0 -24
  905. package/modules/automations-workflows-integration/src/server/index.ts +0 -11
  906. package/modules/automations-workflows-integration/translations/en.json +0 -21
  907. package/modules/automations-workflows-integration/translations/pl.json +0 -21
  908. package/modules/workflows/src/services/cursor-codec.ts +0 -62
@@ -451,12 +451,674 @@ REVOKE SELECT ON auth_mfa_challenges FROM coreloom_background;
451
451
  GRANT SELECT (token_hash, tenant_id, account_id, expires_at, used_at) ON auth_mfa_challenges TO coreloom_background;
452
452
  `;
453
453
 
454
+ export const AUTH_MIGRATION_016_EXTERNAL_IDENTITIES = `-- An external provider asserts an identity about an account, not about one of
455
+ -- its workspaces, and it does so before a workspace is chosen. The row carries
456
+ -- no tenant column and no policy, exactly like the enrolled factor tables; the
457
+ -- membership tables remain the only place the workspace boundary is expressed.
458
+ -- The (provider, subject) pair is the identity the provider promises to keep
459
+ -- stable, so it is the primary key; the address it reports is not.
460
+ CREATE TABLE IF NOT EXISTS auth_external_identities (
461
+ provider TEXT NOT NULL,
462
+ subject TEXT NOT NULL,
463
+ account_id TEXT NOT NULL REFERENCES auth_accounts(id) ON DELETE CASCADE,
464
+ created_at BIGINT NOT NULL,
465
+ last_seen_at BIGINT NOT NULL,
466
+ PRIMARY KEY (provider, subject)
467
+ );
468
+ CREATE INDEX IF NOT EXISTS auth_external_identities_account_idx
469
+ ON auth_external_identities (account_id, provider, subject);
470
+ `;
471
+
472
+ export const AUTH_MIGRATION_017_MFA_KEY_ID = `-- The TOTP envelope in secret_ciphertext names no key, so rotating
473
+ -- FD_AUTH_MFA_KEY could only be recovered by re-enrolling every account. This
474
+ -- column records the key that sealed the row. A row written before it keeps
475
+ -- NULL and is opened by trying the ring in order until auth secrets-rotate
476
+ -- re-seals it; the envelope bytes themselves are unchanged. The factor belongs
477
+ -- to the account, not to one of its workspaces, so the table carries no tenant
478
+ -- column and no policy, exactly as 0015 created it.
479
+ ALTER TABLE auth_mfa_totp ADD COLUMN IF NOT EXISTS key_id TEXT;
480
+ `;
481
+
482
+ export const AUTH_MIGRATION_018_RETIRE_BUNDLED_MODULE_SCOPES = `-- The parties and catalog modules no longer ship, and their read and manage
483
+ -- scopes are still granted to memberships created while they did. A grant that
484
+ -- nothing declares is a grant nobody reviews, so both pairs are retired here.
485
+ --
486
+ -- Row security is forced on both tables, and a migration role that is not a
487
+ -- superuser is subject to it like any other, so a plain statement would reach
488
+ -- no row on a real deployment. The force flag is lifted for the owner and put
489
+ -- back inside the same transaction; a role that does not own these tables
490
+ -- fails here loudly instead of leaving the grants in place. Nothing else runs
491
+ -- against them while the migration lock is held.
492
+ ALTER TABLE auth_membership_scopes NO FORCE ROW LEVEL SECURITY;
493
+ DELETE FROM auth_membership_scopes
494
+ WHERE scope IN ('parties.records.read', 'parties.records.manage', 'catalog.items.read', 'catalog.items.manage');
495
+ ALTER TABLE auth_membership_scopes FORCE ROW LEVEL SECURITY;
496
+ -- A role row grants too: assigning a role replaces the membership scopes with
497
+ -- the list it carries, so a retired scope left in one comes back on the next
498
+ -- assignment. Only rows that still name one are rewritten, and their order is
499
+ -- preserved.
500
+ ALTER TABLE auth_roles NO FORCE ROW LEVEL SECURITY;
501
+ UPDATE auth_roles
502
+ SET scopes_json = COALESCE(
503
+ (SELECT json_agg(entry.scope ORDER BY entry.position)::text
504
+ FROM json_array_elements_text(auth_roles.scopes_json::json)
505
+ WITH ORDINALITY AS entry(scope, position)
506
+ WHERE entry.scope NOT IN ('parties.records.read', 'parties.records.manage', 'catalog.items.read', 'catalog.items.manage')),
507
+ '[]')
508
+ WHERE scopes_json LIKE '%"parties.records.%'
509
+ OR scopes_json LIKE '%"catalog.items.%';
510
+ ALTER TABLE auth_roles FORCE ROW LEVEL SECURITY;
511
+ `;
512
+
513
+ export const AUTH_MIGRATION_019_NOTIFICATIONS_MEMBER_SCOPES = `-- notifications.core declares five permissions. Owners receive all five through
514
+ -- auth sync-scopes, which module enable runs; members receive none, because the
515
+ -- member defaults live in acl/scopes.ts and a built-in role row is seeded once,
516
+ -- with ON CONFLICT DO NOTHING, when the workspace is created. So a workspace
517
+ -- that already exists would never see the three member scopes. This grants them.
518
+ --
519
+ -- Row security is forced on both tables, and a migration role that is not a
520
+ -- superuser is subject to it like any other, so a plain statement would reach
521
+ -- no row on a real deployment. The force flag is lifted for the owner and put
522
+ -- back inside the same transaction; a role that does not own these tables fails
523
+ -- here loudly instead of leaving the grants missing. Nothing else runs against
524
+ -- them while the migration lock is held.
525
+ ALTER TABLE auth_membership_scopes NO FORCE ROW LEVEL SECURITY;
526
+ INSERT INTO auth_membership_scopes (account_id, tenant_id, scope)
527
+ SELECT account_id, tenant_id, scope
528
+ FROM auth_memberships
529
+ CROSS JOIN unnest(ARRAY['notifications.inbox.read', 'notifications.inbox.manage', 'notifications.webhooks.read']) AS granted(scope)
530
+ WHERE auth_memberships.role = 'member'
531
+ ON CONFLICT DO NOTHING;
532
+ ALTER TABLE auth_membership_scopes FORCE ROW LEVEL SECURITY;
533
+ -- A role row grants too: assigning a role replaces the membership scopes with
534
+ -- the list it carries, so a scope missing from the built-in member row would be
535
+ -- taken away again at the next assignment. The scopes already held keep their
536
+ -- order and the missing ones are appended in the order acl/scopes.ts declares
537
+ -- them, which is the order a freshly seeded workspace writes.
538
+ ALTER TABLE auth_roles NO FORCE ROW LEVEL SECURITY;
539
+ UPDATE auth_roles
540
+ SET scopes_json = (
541
+ SELECT json_agg(entry.scope ORDER BY entry.origin, entry.position)::text
542
+ FROM (
543
+ SELECT 0 AS origin, held.position, held.scope
544
+ FROM json_array_elements_text(auth_roles.scopes_json::json)
545
+ WITH ORDINALITY AS held(scope, position)
546
+ UNION ALL
547
+ SELECT 1 AS origin, added.position, added.scope
548
+ FROM unnest(ARRAY['notifications.inbox.read', 'notifications.inbox.manage', 'notifications.webhooks.read'])
549
+ WITH ORDINALITY AS added(scope, position)
550
+ WHERE added.scope NOT IN (
551
+ SELECT existing.scope
552
+ FROM json_array_elements_text(auth_roles.scopes_json::json) AS existing(scope))
553
+ ) AS entry
554
+ )
555
+ WHERE builtin = 1 AND key = 'member';
556
+ ALTER TABLE auth_roles FORCE ROW LEVEL SECURITY;
557
+ `;
558
+
559
+ export const AUTH_MIGRATION_020_IDENTITY_PROVIDERS = `-- A workspace may offer OIDC providers of its own beside the platform providers
560
+ -- FD_AUTH_OIDC_PROVIDERS configures at boot. Such a provider is workspace data,
561
+ -- so the row carries the tenant column and the forced policy every
562
+ -- workspace-owned table carries. The client secret is stored only as the sealed
563
+ -- envelope the auth keyring writes, beside the id of the key that sealed it, so
564
+ -- auth secrets-rotate re-seals these rows exactly as it re-seals enrolled
565
+ -- factors. The discovery endpoints are stored because they are what discovery
566
+ -- answered when the issuer was verified, not administrator input; keeping them
567
+ -- means a sign-in costs no outbound discovery request.
568
+ CREATE TABLE IF NOT EXISTS auth_identity_providers (
569
+ id TEXT PRIMARY KEY,
570
+ tenant_id TEXT NOT NULL REFERENCES auth_tenants(id) ON DELETE CASCADE,
571
+ key TEXT NOT NULL,
572
+ label TEXT NOT NULL,
573
+ issuer TEXT NOT NULL,
574
+ authorization_endpoint TEXT NOT NULL,
575
+ token_endpoint TEXT NOT NULL,
576
+ user_info_endpoint TEXT NOT NULL,
577
+ client_id TEXT NOT NULL,
578
+ client_secret_ciphertext TEXT NOT NULL,
579
+ client_secret_key_id TEXT NOT NULL,
580
+ client_secret_fingerprint TEXT NOT NULL,
581
+ scopes_json TEXT NOT NULL,
582
+ jit_enabled INTEGER NOT NULL DEFAULT 0,
583
+ allowed_domains_json TEXT NOT NULL DEFAULT '[]',
584
+ jit_role TEXT NOT NULL DEFAULT 'member',
585
+ status TEXT NOT NULL CHECK (status IN ('active', 'disabled')),
586
+ created_at BIGINT NOT NULL,
587
+ updated_at BIGINT NOT NULL,
588
+ UNIQUE (tenant_id, key)
589
+ );
590
+ CREATE INDEX IF NOT EXISTS auth_identity_providers_tenant_idx
591
+ ON auth_identity_providers (tenant_id, key, id);
592
+ ALTER TABLE auth_identity_providers ENABLE ROW LEVEL SECURITY;
593
+ ALTER TABLE auth_identity_providers FORCE ROW LEVEL SECURITY;
594
+ CREATE POLICY auth_identity_providers_tenant_policy ON auth_identity_providers
595
+ USING (tenant_id = current_setting('coreloom.tenant_id', true))
596
+ WITH CHECK (tenant_id = current_setting('coreloom.tenant_id', true));
597
+
598
+ -- A platform provider asserts an identity about an account before any workspace
599
+ -- is chosen, and keeps binding without one. A tenant-owned provider asserts it
600
+ -- inside its own workspace only, so the binding carries that workspace and the
601
+ -- pair (provider, subject) is unique per workspace rather than globally. The
602
+ -- primary key 0016 put on the pair would let one workspace's binding block
603
+ -- another's, so it goes and two partial unique indexes take its place.
604
+ ALTER TABLE auth_external_identities
605
+ ADD COLUMN IF NOT EXISTS tenant_id TEXT REFERENCES auth_tenants(id) ON DELETE CASCADE;
606
+ ALTER TABLE auth_external_identities
607
+ DROP CONSTRAINT IF EXISTS auth_external_identities_pkey;
608
+ CREATE UNIQUE INDEX IF NOT EXISTS auth_external_identities_platform_idx
609
+ ON auth_external_identities (provider, subject) WHERE tenant_id IS NULL;
610
+ CREATE UNIQUE INDEX IF NOT EXISTS auth_external_identities_workspace_idx
611
+ ON auth_external_identities (tenant_id, provider, subject) WHERE tenant_id IS NOT NULL;
612
+ -- The workspace rows are workspace data and the policy scopes them to their
613
+ -- tenant; the platform rows carry no workspace and stay readable under the
614
+ -- identity context that has always written them.
615
+ ALTER TABLE auth_external_identities ENABLE ROW LEVEL SECURITY;
616
+ ALTER TABLE auth_external_identities FORCE ROW LEVEL SECURITY;
617
+ CREATE POLICY auth_external_identities_tenant_policy ON auth_external_identities
618
+ USING (tenant_id IS NULL OR tenant_id = current_setting('coreloom.tenant_id', true))
619
+ WITH CHECK (tenant_id IS NULL OR tenant_id = current_setting('coreloom.tenant_id', true));
620
+ `;
621
+
622
+ export const AUTH_MIGRATION_022_AUTH_PROVIDER_SCOPES = `-- auth.core declares auth.providers.read and auth.providers.manage for the
623
+ -- workspace identity providers screen. A module's scopes reach existing owners
624
+ -- through auth sync-scopes, which module enable runs, but auth.core is not a
625
+ -- module a deployment enables, and the built-in role rows are seeded once, with
626
+ -- ON CONFLICT DO NOTHING, when a workspace is created. So a workspace that
627
+ -- already exists would never see either scope. This grants them.
628
+ --
629
+ -- Row security is forced on both tables, and a migration role that is not a
630
+ -- superuser is subject to it like any other, so a plain statement would reach
631
+ -- no row on a real deployment. The force flag is lifted for the owner and put
632
+ -- back inside the same transaction; a role that does not own these tables fails
633
+ -- here loudly instead of leaving the grants missing. Nothing else runs against
634
+ -- them while the migration lock is held.
635
+ ALTER TABLE auth_membership_scopes NO FORCE ROW LEVEL SECURITY;
636
+ INSERT INTO auth_membership_scopes (account_id, tenant_id, scope)
637
+ SELECT account_id, tenant_id, scope
638
+ FROM auth_memberships
639
+ CROSS JOIN unnest(ARRAY['auth.providers.read', 'auth.providers.manage']) AS granted(scope)
640
+ WHERE auth_memberships.role = 'owner'
641
+ ON CONFLICT DO NOTHING;
642
+ ALTER TABLE auth_membership_scopes FORCE ROW LEVEL SECURITY;
643
+ -- A role row grants too: assigning a role replaces the membership scopes with
644
+ -- the list it carries, so a scope missing from the built-in owner row would be
645
+ -- taken away again at the next assignment. The scopes already held keep their
646
+ -- order and the missing ones are appended in the order acl/scopes.ts declares
647
+ -- them, which is the order a freshly seeded workspace writes.
648
+ ALTER TABLE auth_roles NO FORCE ROW LEVEL SECURITY;
649
+ UPDATE auth_roles
650
+ SET scopes_json = (
651
+ SELECT json_agg(entry.scope ORDER BY entry.origin, entry.position)::text
652
+ FROM (
653
+ SELECT 0 AS origin, held.position, held.scope
654
+ FROM json_array_elements_text(auth_roles.scopes_json::json)
655
+ WITH ORDINALITY AS held(scope, position)
656
+ UNION ALL
657
+ SELECT 1 AS origin, added.position, added.scope
658
+ FROM unnest(ARRAY['auth.providers.read', 'auth.providers.manage'])
659
+ WITH ORDINALITY AS added(scope, position)
660
+ WHERE added.scope NOT IN (
661
+ SELECT existing.scope
662
+ FROM json_array_elements_text(auth_roles.scopes_json::json) AS existing(scope))
663
+ ) AS entry
664
+ )
665
+ WHERE builtin = 1 AND key = 'owner';
666
+ ALTER TABLE auth_roles FORCE ROW LEVEL SECURITY;
667
+ `;
668
+
669
+ export const AUTH_MIGRATION_021_MEMBERSHIP_STATUS = `-- Membership status is per workspace: disabling a member in one workspace
670
+ -- revokes that membership's sessions and tokens and refuses its sign-in, and
671
+ -- leaves the person's other memberships untouched. The account status column
672
+ -- stays what it was, the deployment operator's platform-level block.
673
+ ALTER TABLE auth_memberships ADD COLUMN IF NOT EXISTS status TEXT NOT NULL DEFAULT 'active';
674
+ DO $$
675
+ BEGIN
676
+ IF NOT EXISTS (
677
+ SELECT 1 FROM pg_constraint WHERE conname = 'auth_memberships_status_check'
678
+ ) THEN
679
+ ALTER TABLE auth_memberships ADD CONSTRAINT auth_memberships_status_check
680
+ CHECK (status IN ('active', 'disabled'));
681
+ END IF;
682
+ END
683
+ $$;
684
+ -- A session cookie, a bearer token and an email address name no workspace, so
685
+ -- the routing read decides which membership answers for them. A disabled
686
+ -- membership must not be that answer, which is a column this role now reads.
687
+ GRANT SELECT (status) ON auth_memberships TO coreloom_background;
688
+ `;
689
+
690
+ export const AUTH_MIGRATION_023_ENTERPRISE_MODULE_SCOPES = `-- directory.core, audit.core, approvals.core, documents.core, metering.core,
691
+ -- import.core, search.core and connectors.core declare sixteen permissions
692
+ -- between them. Owners receive a module's scopes through auth sync-scopes,
693
+ -- which module enable runs, so only where that module is enabled; members
694
+ -- receive none, because the member defaults live in acl/scopes.ts and a
695
+ -- built-in role row is seeded once, with ON CONFLICT DO NOTHING, when the
696
+ -- workspace is created. So a workspace that already exists would see neither
697
+ -- the owner defaults of a module it never enabled nor any member default. This
698
+ -- grants both, in the order acl/scopes.ts declares them.
699
+ --
700
+ -- Row security is forced on both tables, and a migration role that is not a
701
+ -- superuser is subject to it like any other, so a plain statement would reach
702
+ -- no row on a real deployment. The force flag is lifted for the owner and put
703
+ -- back inside the same transaction; a role that does not own these tables fails
704
+ -- here loudly instead of leaving the grants missing. Nothing else runs against
705
+ -- them while the migration lock is held.
706
+ ALTER TABLE auth_membership_scopes NO FORCE ROW LEVEL SECURITY;
707
+ INSERT INTO auth_membership_scopes (account_id, tenant_id, scope)
708
+ SELECT account_id, tenant_id, scope
709
+ FROM auth_memberships
710
+ CROSS JOIN unnest(ARRAY['directory.tokens.read', 'directory.tokens.manage', 'directory.provisioning.read', 'audit.registry.read', 'audit.retention.manage', 'approvals.requests.read', 'approvals.requests.decide', 'approvals.requests.manage', 'documents.files.read', 'documents.files.manage', 'metering.usage.read', 'import.jobs.read', 'import.jobs.manage', 'search.records.read', 'connectors.instances.read', 'connectors.instances.manage']) AS granted(scope)
711
+ WHERE auth_memberships.role = 'owner'
712
+ ON CONFLICT DO NOTHING;
713
+ INSERT INTO auth_membership_scopes (account_id, tenant_id, scope)
714
+ SELECT account_id, tenant_id, scope
715
+ FROM auth_memberships
716
+ CROSS JOIN unnest(ARRAY['documents.files.read', 'documents.files.manage', 'search.records.read', 'connectors.instances.read']) AS granted(scope)
717
+ WHERE auth_memberships.role = 'member'
718
+ ON CONFLICT DO NOTHING;
719
+ ALTER TABLE auth_membership_scopes FORCE ROW LEVEL SECURITY;
720
+ -- A role row grants too: assigning a role replaces the membership scopes with
721
+ -- the list it carries, so a scope missing from a built-in row would be taken
722
+ -- away again at the next assignment. The scopes already held keep their order
723
+ -- and the missing ones are appended in the order acl/scopes.ts declares them,
724
+ -- which is the order a freshly seeded workspace writes.
725
+ ALTER TABLE auth_roles NO FORCE ROW LEVEL SECURITY;
726
+ UPDATE auth_roles
727
+ SET scopes_json = (
728
+ SELECT json_agg(entry.scope ORDER BY entry.origin, entry.position)::text
729
+ FROM (
730
+ SELECT 0 AS origin, held.position, held.scope
731
+ FROM json_array_elements_text(auth_roles.scopes_json::json)
732
+ WITH ORDINALITY AS held(scope, position)
733
+ UNION ALL
734
+ SELECT 1 AS origin, added.position, added.scope
735
+ FROM unnest(ARRAY['directory.tokens.read', 'directory.tokens.manage', 'directory.provisioning.read', 'audit.registry.read', 'audit.retention.manage', 'approvals.requests.read', 'approvals.requests.decide', 'approvals.requests.manage', 'documents.files.read', 'documents.files.manage', 'metering.usage.read', 'import.jobs.read', 'import.jobs.manage', 'search.records.read', 'connectors.instances.read', 'connectors.instances.manage'])
736
+ WITH ORDINALITY AS added(scope, position)
737
+ WHERE added.scope NOT IN (
738
+ SELECT existing.scope
739
+ FROM json_array_elements_text(auth_roles.scopes_json::json) AS existing(scope))
740
+ ) AS entry
741
+ )
742
+ WHERE builtin = 1 AND key = 'owner';
743
+ UPDATE auth_roles
744
+ SET scopes_json = (
745
+ SELECT json_agg(entry.scope ORDER BY entry.origin, entry.position)::text
746
+ FROM (
747
+ SELECT 0 AS origin, held.position, held.scope
748
+ FROM json_array_elements_text(auth_roles.scopes_json::json)
749
+ WITH ORDINALITY AS held(scope, position)
750
+ UNION ALL
751
+ SELECT 1 AS origin, added.position, added.scope
752
+ FROM unnest(ARRAY['documents.files.read', 'documents.files.manage', 'search.records.read', 'connectors.instances.read'])
753
+ WITH ORDINALITY AS added(scope, position)
754
+ WHERE added.scope NOT IN (
755
+ SELECT existing.scope
756
+ FROM json_array_elements_text(auth_roles.scopes_json::json) AS existing(scope))
757
+ ) AS entry
758
+ )
759
+ WHERE builtin = 1 AND key = 'member';
760
+ ALTER TABLE auth_roles FORCE ROW LEVEL SECURITY;
761
+ `;
762
+
763
+ export const AUTH_MIGRATION_024_APPROVALS_MEMBER_SCOPES = `-- approvals.core resolves the deciders of a request from the workspace roles,
764
+ -- so a member has to read the requests that name them and record a decision on
765
+ -- them. 0023 granted the three approval scopes to owners alone, which was the
766
+ -- member default at the time; acl/scopes.ts now carries approvals.requests.read
767
+ -- and approvals.requests.decide among the member defaults, and a built-in role
768
+ -- row is seeded once, with ON CONFLICT DO NOTHING, when the workspace is
769
+ -- created. So a workspace that already exists would never see either. This
770
+ -- grants both to its members, in the order acl/scopes.ts declares them. Owners
771
+ -- keep what 0023 gave them and are not touched here.
772
+ --
773
+ -- Row security is forced on both tables, and a migration role that is not a
774
+ -- superuser is subject to it like any other, so a plain statement would reach
775
+ -- no row on a real deployment. The force flag is lifted for the owner and put
776
+ -- back inside the same transaction; a role that does not own these tables fails
777
+ -- here loudly instead of leaving the grants missing. Nothing else runs against
778
+ -- them while the migration lock is held.
779
+ ALTER TABLE auth_membership_scopes NO FORCE ROW LEVEL SECURITY;
780
+ INSERT INTO auth_membership_scopes (account_id, tenant_id, scope)
781
+ SELECT account_id, tenant_id, scope
782
+ FROM auth_memberships
783
+ CROSS JOIN unnest(ARRAY['approvals.requests.read', 'approvals.requests.decide']) AS granted(scope)
784
+ WHERE auth_memberships.role = 'member'
785
+ ON CONFLICT DO NOTHING;
786
+ ALTER TABLE auth_membership_scopes FORCE ROW LEVEL SECURITY;
787
+ -- A role row grants too: assigning a role replaces the membership scopes with
788
+ -- the list it carries, so a scope missing from the built-in member row would be
789
+ -- taken away again at the next assignment. The scopes already held keep their
790
+ -- order and the missing ones are appended in the order acl/scopes.ts declares
791
+ -- them, which is the order a freshly seeded workspace writes.
792
+ ALTER TABLE auth_roles NO FORCE ROW LEVEL SECURITY;
793
+ UPDATE auth_roles
794
+ SET scopes_json = (
795
+ SELECT json_agg(entry.scope ORDER BY entry.origin, entry.position)::text
796
+ FROM (
797
+ SELECT 0 AS origin, held.position, held.scope
798
+ FROM json_array_elements_text(auth_roles.scopes_json::json)
799
+ WITH ORDINALITY AS held(scope, position)
800
+ UNION ALL
801
+ SELECT 1 AS origin, added.position, added.scope
802
+ FROM unnest(ARRAY['approvals.requests.read', 'approvals.requests.decide'])
803
+ WITH ORDINALITY AS added(scope, position)
804
+ WHERE added.scope NOT IN (
805
+ SELECT existing.scope
806
+ FROM json_array_elements_text(auth_roles.scopes_json::json) AS existing(scope))
807
+ ) AS entry
808
+ )
809
+ WHERE builtin = 1 AND key = 'member';
810
+ ALTER TABLE auth_roles FORCE ROW LEVEL SECURITY;
811
+ `;
812
+
813
+ export const AUTH_MIGRATION_025_AUDIT_HOLDS_OWNER_SCOPE = `-- audit.core declares audit.holds.manage, and D-AUDIT-HOLD-PERMISSION keeps it
814
+ -- with owners: only an owner places or lifts a legal hold. The permission was
815
+ -- declared after 0023 backfilled the enterprise module scopes, so an existing
816
+ -- workspace carries it on neither its owner memberships nor its built-in owner
817
+ -- role row. auth sync-scopes grants a module's declared scopes when the module
818
+ -- is enabled, and audit.core was already enabled when this one appeared, so
819
+ -- that path does not reach it either. This grants it to every owner
820
+ -- membership and appends it to the built-in owner role row. Members receive
821
+ -- nothing here: D-AUDIT-PERMISSIONS keeps every audit permission owner-only.
822
+ --
823
+ -- Row security is forced on both tables, and a migration role that is not a
824
+ -- superuser is subject to it like any other, so a plain statement would reach
825
+ -- no row on a real deployment. The force flag is lifted for the owner and put
826
+ -- back inside the same transaction; a role that does not own these tables fails
827
+ -- here loudly instead of leaving the grants missing. Nothing else runs against
828
+ -- them while the migration lock is held.
829
+ ALTER TABLE auth_membership_scopes NO FORCE ROW LEVEL SECURITY;
830
+ INSERT INTO auth_membership_scopes (account_id, tenant_id, scope)
831
+ SELECT account_id, tenant_id, scope
832
+ FROM auth_memberships
833
+ CROSS JOIN unnest(ARRAY['audit.holds.manage']) AS granted(scope)
834
+ WHERE auth_memberships.role = 'owner'
835
+ ON CONFLICT DO NOTHING;
836
+ ALTER TABLE auth_membership_scopes FORCE ROW LEVEL SECURITY;
837
+ -- A role row grants too: assigning a role replaces the membership scopes with
838
+ -- the list it carries, so a scope missing from the built-in owner row would be
839
+ -- taken away again at the next assignment. The scopes already held keep their
840
+ -- order and the missing one is appended.
841
+ ALTER TABLE auth_roles NO FORCE ROW LEVEL SECURITY;
842
+ UPDATE auth_roles
843
+ SET scopes_json = (
844
+ SELECT json_agg(entry.scope ORDER BY entry.origin, entry.position)::text
845
+ FROM (
846
+ SELECT 0 AS origin, held.position, held.scope
847
+ FROM json_array_elements_text(auth_roles.scopes_json::json)
848
+ WITH ORDINALITY AS held(scope, position)
849
+ UNION ALL
850
+ SELECT 1 AS origin, added.position, added.scope
851
+ FROM unnest(ARRAY['audit.holds.manage'])
852
+ WITH ORDINALITY AS added(scope, position)
853
+ WHERE added.scope NOT IN (
854
+ SELECT existing.scope
855
+ FROM json_array_elements_text(auth_roles.scopes_json::json) AS existing(scope))
856
+ ) AS entry
857
+ )
858
+ WHERE builtin = 1 AND key = 'owner';
859
+ ALTER TABLE auth_roles FORCE ROW LEVEL SECURITY;
860
+ `;
861
+
862
+ export const AUTH_MIGRATION_026_AUTH_EXPORT_KEYSET_INDEXES = `-- The three data class export walks page one workspace by keyset:
863
+ -- WHERE tenant_id = $1 AND id > $2 ORDER BY id LIMIT $3. No index ordered that
864
+ -- pair, so every page sorted the whole workspace again: auth_sessions carried
865
+ -- (account_id, expires_at), (expires_at) and a unique (id); auth_api_tokens
866
+ -- (tenant_id, revoked_at, created_at DESC); auth_audit
867
+ -- (tenant_id, occurred_at DESC, id DESC). These three turn each page into an
868
+ -- index range scan of exactly the rows it returns, which is what makes an
869
+ -- export of a large workspace linear in the rows it carries rather than
870
+ -- quadratic in them.
871
+ CREATE INDEX IF NOT EXISTS auth_sessions_tenant_keyset_idx
872
+ ON auth_sessions (tenant_id, id);
873
+ CREATE INDEX IF NOT EXISTS auth_api_tokens_tenant_keyset_idx
874
+ ON auth_api_tokens (tenant_id, id);
875
+ CREATE INDEX IF NOT EXISTS auth_audit_tenant_keyset_idx
876
+ ON auth_audit (tenant_id, id);
877
+ `;
878
+
879
+ export const AUTH_MIGRATION_027_WORKFLOW_AUTOMATION_PROFILE_SCOPES = `-- workflows.core, automations.core and profile.core declare eleven permissions
880
+ -- between them, and owners hold every permission an enabled module declares.
881
+ -- All three were already enabled when the owner defaults gained them, so auth
882
+ -- sync-scopes does not reach an existing workspace: it grants a module's scopes
883
+ -- when the module is enabled and to the workspaces that exist at that moment.
884
+ -- The seed lists in acl/scopes.ts reach a workspace created from now on and no
885
+ -- earlier one. This grants the eleven to every owner membership and appends
886
+ -- them to the built-in owner role row. Members receive profile.self.manage
887
+ -- alone, because every member manages their own profile, language, password
888
+ -- and sessions, while the workflow and automation permissions stay with owners.
889
+ --
890
+ -- Row security is forced on both tables, and a migration role that is not a
891
+ -- superuser is subject to it like any other, so a plain statement would reach
892
+ -- no row on a real deployment. The force flag is lifted for the owner and put
893
+ -- back inside the same transaction; a role that does not own these tables fails
894
+ -- here loudly instead of leaving the grants missing. Nothing else runs against
895
+ -- them while the migration lock is held.
896
+ ALTER TABLE auth_membership_scopes NO FORCE ROW LEVEL SECURITY;
897
+ INSERT INTO auth_membership_scopes (account_id, tenant_id, scope)
898
+ SELECT account_id, tenant_id, scope
899
+ FROM auth_memberships
900
+ CROSS JOIN unnest(ARRAY['workflows.definitions.read', 'workflows.definitions.manage', 'workflows.definitions.publish', 'workflows.runs.read', 'workflows.runs.execute', 'workflows.runs.cancel', 'automations.schedules.read', 'automations.schedules.manage', 'automations.triggers.read', 'automations.triggers.manage', 'profile.self.manage']) AS granted(scope)
901
+ WHERE auth_memberships.role = 'owner'
902
+ ON CONFLICT DO NOTHING;
903
+ INSERT INTO auth_membership_scopes (account_id, tenant_id, scope)
904
+ SELECT account_id, tenant_id, scope
905
+ FROM auth_memberships
906
+ CROSS JOIN unnest(ARRAY['profile.self.manage']) AS granted(scope)
907
+ WHERE auth_memberships.role = 'member'
908
+ ON CONFLICT DO NOTHING;
909
+ ALTER TABLE auth_membership_scopes FORCE ROW LEVEL SECURITY;
910
+ -- A role row grants too: assigning a role replaces the membership scopes with
911
+ -- the list it carries, so a scope missing from a built-in row would be taken
912
+ -- away again at the next assignment. The scopes already held keep their order
913
+ -- and the missing ones are appended in the order acl/scopes.ts declares them,
914
+ -- which is the order a freshly seeded workspace writes.
915
+ ALTER TABLE auth_roles NO FORCE ROW LEVEL SECURITY;
916
+ UPDATE auth_roles
917
+ SET scopes_json = (
918
+ SELECT json_agg(entry.scope ORDER BY entry.origin, entry.position)::text
919
+ FROM (
920
+ SELECT 0 AS origin, held.position, held.scope
921
+ FROM json_array_elements_text(auth_roles.scopes_json::json)
922
+ WITH ORDINALITY AS held(scope, position)
923
+ UNION ALL
924
+ SELECT 1 AS origin, added.position, added.scope
925
+ FROM unnest(ARRAY['workflows.definitions.read', 'workflows.definitions.manage', 'workflows.definitions.publish', 'workflows.runs.read', 'workflows.runs.execute', 'workflows.runs.cancel', 'automations.schedules.read', 'automations.schedules.manage', 'automations.triggers.read', 'automations.triggers.manage', 'profile.self.manage'])
926
+ WITH ORDINALITY AS added(scope, position)
927
+ WHERE added.scope NOT IN (
928
+ SELECT existing.scope
929
+ FROM json_array_elements_text(auth_roles.scopes_json::json) AS existing(scope))
930
+ ) AS entry
931
+ )
932
+ WHERE builtin = 1 AND key = 'owner';
933
+ UPDATE auth_roles
934
+ SET scopes_json = (
935
+ SELECT json_agg(entry.scope ORDER BY entry.origin, entry.position)::text
936
+ FROM (
937
+ SELECT 0 AS origin, held.position, held.scope
938
+ FROM json_array_elements_text(auth_roles.scopes_json::json)
939
+ WITH ORDINALITY AS held(scope, position)
940
+ UNION ALL
941
+ SELECT 1 AS origin, added.position, added.scope
942
+ FROM unnest(ARRAY['profile.self.manage'])
943
+ WITH ORDINALITY AS added(scope, position)
944
+ WHERE added.scope NOT IN (
945
+ SELECT existing.scope
946
+ FROM json_array_elements_text(auth_roles.scopes_json::json) AS existing(scope))
947
+ ) AS entry
948
+ )
949
+ WHERE builtin = 1 AND key = 'member';
950
+ ALTER TABLE auth_roles FORCE ROW LEVEL SECURITY;
951
+ `;
952
+
953
+ export const AUTH_MIGRATION_028_AUTH_MEMBER_SEARCH_PREFIX_INDEXES = `-- Member search matched a display name anywhere, LIKE '%term%', which no index
954
+ -- can answer: every keystroke read the workspace and sorted it before the LIMIT
955
+ -- cut it. Both branches are prefixes now, and these indexes turn each branch
956
+ -- into a range scan of the rows it returns. The ordering is still a sort, over
957
+ -- the rows the prefix matched rather than over the workspace.
958
+ --
959
+ -- The operator class is the load-bearing part. A btree over text in any
960
+ -- collation but C orders by that collation, while LIKE 'term%' is a range in
961
+ -- byte order, so an index in the database's default collation is ignored on a
962
+ -- deployment created with a locale and the workspace scan comes back unnoticed.
963
+ -- text_pattern_ops states the byte order the prefix needs, so the same plan
964
+ -- holds under every collation. The unique index on email_normalized stays the
965
+ -- key it is; it answers equality, and under C collation the prefix as well.
966
+ --
967
+ -- Neither index carries a workspace column because auth_accounts carries none.
968
+ -- A search reaches an account through auth_memberships, whose policy and
969
+ -- primary key bind the workspace to it.
970
+ CREATE INDEX IF NOT EXISTS auth_accounts_display_name_prefix_idx
971
+ ON auth_accounts (lower(display_name) text_pattern_ops);
972
+ CREATE INDEX IF NOT EXISTS auth_accounts_email_prefix_idx
973
+ ON auth_accounts (email_normalized text_pattern_ops);
974
+ `;
975
+
976
+ export const AUTH_MIGRATION_029_REPORTS_EXPORTS_ACCESS_SCOPES = `-- reports.core, exports.core and access.core declare five permissions between
977
+ -- them, and owners hold every permission an enabled module declares. All three
978
+ -- were already enabled when the owner defaults gained them, so auth sync-scopes
979
+ -- does not reach an existing workspace: it grants a module's scopes when the
980
+ -- module is enabled and to the workspaces that exist at that moment. The seed
981
+ -- lists in acl/scopes.ts reach a workspace created from now on and no earlier
982
+ -- one. This grants the five to every owner membership and appends them to the
983
+ -- built-in owner role row.
984
+ --
985
+ -- Members receive none of them. D-REPORTS-AUDIENCE keeps the workspace report
986
+ -- with owners because it composes spend, usage and volume across modules;
987
+ -- D-OWNERS-ONLY keeps both access review permissions with owners because the
988
+ -- review names every scope, token and provider of the workspace; and
989
+ -- D-EXPORTS-PERMISSIONS states what starting an export and opening a file
990
+ -- require of the live principal rather than granting a role anything, so the
991
+ -- two export permissions stay owner defaults and a workspace that wants a
992
+ -- member to export assigns a role carrying them.
993
+ --
994
+ -- Row security is forced on both tables, and a migration role that is not a
995
+ -- superuser is subject to it like any other, so a plain statement would reach
996
+ -- no row on a real deployment. The force flag is lifted for the owner and put
997
+ -- back inside the same transaction; a role that does not own these tables fails
998
+ -- here loudly instead of leaving the grants missing. Nothing else runs against
999
+ -- them while the migration lock is held.
1000
+ ALTER TABLE auth_membership_scopes NO FORCE ROW LEVEL SECURITY;
1001
+ INSERT INTO auth_membership_scopes (account_id, tenant_id, scope)
1002
+ SELECT account_id, tenant_id, scope
1003
+ FROM auth_memberships
1004
+ CROSS JOIN unnest(ARRAY['reports.workspace.read', 'exports.lists.read', 'exports.lists.manage', 'access.review.read', 'access.review.manage']) AS granted(scope)
1005
+ WHERE auth_memberships.role = 'owner'
1006
+ ON CONFLICT DO NOTHING;
1007
+ ALTER TABLE auth_membership_scopes FORCE ROW LEVEL SECURITY;
1008
+ -- A role row grants too: assigning a role replaces the membership scopes with
1009
+ -- the list it carries, so a scope missing from the built-in owner row would be
1010
+ -- taken away again at the next assignment. The scopes already held keep their
1011
+ -- order and the missing ones are appended in the order acl/scopes.ts declares
1012
+ -- them, which is the order a freshly seeded workspace writes.
1013
+ ALTER TABLE auth_roles NO FORCE ROW LEVEL SECURITY;
1014
+ UPDATE auth_roles
1015
+ SET scopes_json = (
1016
+ SELECT json_agg(entry.scope ORDER BY entry.origin, entry.position)::text
1017
+ FROM (
1018
+ SELECT 0 AS origin, held.position, held.scope
1019
+ FROM json_array_elements_text(auth_roles.scopes_json::json)
1020
+ WITH ORDINALITY AS held(scope, position)
1021
+ UNION ALL
1022
+ SELECT 1 AS origin, added.position, added.scope
1023
+ FROM unnest(ARRAY['reports.workspace.read', 'exports.lists.read', 'exports.lists.manage', 'access.review.read', 'access.review.manage'])
1024
+ WITH ORDINALITY AS added(scope, position)
1025
+ WHERE added.scope NOT IN (
1026
+ SELECT existing.scope
1027
+ FROM json_array_elements_text(auth_roles.scopes_json::json) AS existing(scope))
1028
+ ) AS entry
1029
+ )
1030
+ WHERE builtin = 1 AND key = 'owner';
1031
+ ALTER TABLE auth_roles FORCE ROW LEVEL SECURITY;
1032
+ `;
1033
+
1034
+ export const AUTH_MIGRATION_030_AUTH_MEMBERSHIP_KEYSET_INDEX = `-- The paged member read walks one workspace by keyset:
1035
+ -- WHERE tenant_id = $1 AND account_id > $2 ORDER BY account_id LIMIT $3. The
1036
+ -- primary key of auth_memberships is (account_id, tenant_id), which leads with
1037
+ -- the account, so that walk is a scan over every workspace's rows after the
1038
+ -- cursor with the workspace applied as a filter. This index leads with the
1039
+ -- workspace, which turns each page into an index range scan of exactly the
1040
+ -- rows it returns and makes the walk linear in the members it carries rather
1041
+ -- than in the deployment.
1042
+ CREATE INDEX IF NOT EXISTS auth_memberships_tenant_keyset_idx
1043
+ ON auth_memberships (tenant_id, account_id);
1044
+ `;
1045
+
1046
+ export const AUTH_MIGRATION_031_MEMBERSHIP_SCOPE_BACKFILLS_UNDER_RLS = `-- The scope backfills 0019, 0022, 0023, 0024, 0025, 0027 and 0029 grant the
1047
+ -- permissions a module declares to the memberships that existed when the
1048
+ -- module was enabled. Each lifted the force flag on auth_membership_scopes and
1049
+ -- on auth_roles, but selected the memberships from auth_memberships, which
1050
+ -- forces row security as well (0001). A migrator that is not a superuser is
1051
+ -- subject to that policy and holds no tenant setting, so on a PostgreSQL
1052
+ -- deployment every one of those selects matched nothing and no membership
1053
+ -- gained a scope; PGlite runs as a superuser and did not notice. The built-in
1054
+ -- role rows those migrations rewrote were read from auth_roles under its own
1055
+ -- lifted flag and are correct.
1056
+ --
1057
+ -- Applied migrations are immutable, so this repeats the seven membership
1058
+ -- grants with the force flag lifted on the source table as well, inside the
1059
+ -- same transaction, on the same conflict rule. A scope a workspace granted
1060
+ -- since, by assigning a role that names it, is left in place.
1061
+ ALTER TABLE auth_memberships NO FORCE ROW LEVEL SECURITY;
1062
+ ALTER TABLE auth_membership_scopes NO FORCE ROW LEVEL SECURITY;
1063
+ INSERT INTO auth_membership_scopes (account_id, tenant_id, scope)
1064
+ SELECT account_id, tenant_id, scope
1065
+ FROM auth_memberships
1066
+ CROSS JOIN unnest(ARRAY['auth.providers.read', 'auth.providers.manage', 'directory.tokens.read', 'directory.tokens.manage', 'directory.provisioning.read', 'audit.registry.read', 'audit.retention.manage', 'approvals.requests.read', 'approvals.requests.decide', 'approvals.requests.manage', 'documents.files.read', 'documents.files.manage', 'metering.usage.read', 'import.jobs.read', 'import.jobs.manage', 'search.records.read', 'connectors.instances.read', 'connectors.instances.manage', 'audit.holds.manage', 'workflows.definitions.read', 'workflows.definitions.manage', 'workflows.definitions.publish', 'workflows.runs.read', 'workflows.runs.execute', 'workflows.runs.cancel', 'automations.schedules.read', 'automations.schedules.manage', 'automations.triggers.read', 'automations.triggers.manage', 'profile.self.manage', 'reports.workspace.read', 'exports.lists.read', 'exports.lists.manage', 'access.review.read', 'access.review.manage']) AS granted(scope)
1067
+ WHERE auth_memberships.role = 'owner'
1068
+ ON CONFLICT DO NOTHING;
1069
+ INSERT INTO auth_membership_scopes (account_id, tenant_id, scope)
1070
+ SELECT account_id, tenant_id, scope
1071
+ FROM auth_memberships
1072
+ CROSS JOIN unnest(ARRAY['notifications.inbox.read', 'notifications.inbox.manage', 'notifications.webhooks.read', 'documents.files.read', 'documents.files.manage', 'search.records.read', 'connectors.instances.read', 'approvals.requests.read', 'approvals.requests.decide', 'profile.self.manage']) AS granted(scope)
1073
+ WHERE auth_memberships.role = 'member'
1074
+ ON CONFLICT DO NOTHING;
1075
+ ALTER TABLE auth_membership_scopes FORCE ROW LEVEL SECURITY;
1076
+ ALTER TABLE auth_memberships FORCE ROW LEVEL SECURITY;
1077
+ `;
1078
+
1079
+ export const AUTH_MIGRATION_032_AUDIT_ACTOR_SERVICE = `-- The kernel actor model has three kinds: a user, an agent run and a service
1080
+ -- configured by a user. 0014 admitted the first two, so an operator command
1081
+ -- and an identity provider were recorded as users. This admits the service
1082
+ -- kind and stores the configuring user beside it, the way the record history
1083
+ -- tables do; null where the row is no service, or where the configuring user
1084
+ -- is not stored, as an identity provider's is not.
1085
+ ALTER TABLE auth_audit DROP CONSTRAINT IF EXISTS auth_audit_actor_kind_check;
1086
+ ALTER TABLE auth_audit ADD CONSTRAINT auth_audit_actor_kind_check
1087
+ CHECK (actor_kind IN ('user', 'agent', 'service'));
1088
+ ALTER TABLE auth_audit ADD COLUMN IF NOT EXISTS configured_by_json TEXT NULL;
1089
+ `;
1090
+
454
1091
  /* The scope backfills carry no schema, so they have nothing to adopt. They also
455
1092
  reach no rows: row security is forced on both tables they read, and the
456
1093
  migration role is subject to it like any other, so the SELECT they insert
457
1094
  from is empty on every PostgreSQL database. They stay because a migration id
458
1095
  is immutable history; a workspace receives these scopes when it is created,
459
1096
  from the static role lists in acl/scopes.ts. */
1097
+ export const AUTH_MIGRATION_033_AUTH_ACCOUNT_KEYSET_INDEXES = `-- The sorted member listing pages one workspace by display name or by address:
1098
+ -- ORDER BY lower(a.display_name), a.id (or a.email_normalized, a.id) with a
1099
+ -- keyset predicate on the same pair and a LIMIT, over auth_memberships joined
1100
+ -- to auth_accounts for the workspace. Both sort columns live on auth_accounts,
1101
+ -- which carries no tenant column, so the (tenant_id, sort column, id) index a
1102
+ -- keyset page normally rests on cannot exist on one table. These indexes go
1103
+ -- where the sort expressions are. For a workspace that holds most of the
1104
+ -- deployment's accounts the planner walks the index in order, joins each
1105
+ -- account to its membership through the primary key (account_id, tenant_id)
1106
+ -- and stops at the LIMIT, so a page costs the rows it answers. For a small
1107
+ -- workspace it reads the membership rows through 0030's (tenant_id,
1108
+ -- account_id) index and sorts that workspace alone, which is bounded by the
1109
+ -- workspace and never by the deployment. Neither plan reads the deployment's
1110
+ -- accounts and sorts them.
1111
+ --
1112
+ -- 0028's prefix index over lower(display_name) carries text_pattern_ops,
1113
+ -- whose byte order is the ORDER BY order under the C collation only, so the
1114
+ -- sort needs its own index in the database collation. The address is already
1115
+ -- unique, and id follows it here so both keysets have the same shape.
1116
+ CREATE INDEX IF NOT EXISTS auth_accounts_display_name_keyset_idx
1117
+ ON auth_accounts (lower(display_name), id);
1118
+ CREATE INDEX IF NOT EXISTS auth_accounts_email_keyset_idx
1119
+ ON auth_accounts (email_normalized, id);
1120
+ `;
1121
+
460
1122
  export const databaseMigrations: readonly DatabaseMigration[] = [
461
1123
  {
462
1124
  id: '0001_auth_core',
@@ -588,4 +1250,152 @@ export const databaseMigrations: readonly DatabaseMigration[] = [
588
1250
  ],
589
1251
  ),
590
1252
  },
1253
+ {
1254
+ id: '0016_external_identities',
1255
+ sql: { postgresql: AUTH_MIGRATION_016_EXTERNAL_IDENTITIES },
1256
+ inspectExisting: (database) =>
1257
+ migrationObjectState([
1258
+ () => database.schema.hasTable('auth_external_identities'),
1259
+ () => database.schema.hasIndex('auth_external_identities_account_idx'),
1260
+ ]),
1261
+ },
1262
+ {
1263
+ id: '0017_mfa_key_id',
1264
+ sql: { postgresql: AUTH_MIGRATION_017_MFA_KEY_ID },
1265
+ inspectExisting: (database) =>
1266
+ migrationObjectState([
1267
+ () => database.schema.hasColumn('auth_mfa_totp', 'key_id'),
1268
+ ]),
1269
+ },
1270
+ /* A data-only retirement: there is no schema object to prove, and a probe
1271
+ over the rows would report a fresh database as adopted. It cannot predate
1272
+ the ledger either, so it declares no inspectExisting. */
1273
+ {
1274
+ id: '0018_retire_bundled_module_scopes',
1275
+ sql: { postgresql: AUTH_MIGRATION_018_RETIRE_BUNDLED_MODULE_SCOPES },
1276
+ },
1277
+ /* Data-only like 0018, and for the same reason it declares no
1278
+ inspectExisting: a probe over the rows would report a fresh database, which
1279
+ receives these scopes from acl/scopes.ts, as adopted. */
1280
+ {
1281
+ id: '0019_notifications_member_scopes',
1282
+ sql: { postgresql: AUTH_MIGRATION_019_NOTIFICATIONS_MEMBER_SCOPES },
1283
+ },
1284
+ {
1285
+ id: '0020_identity_providers',
1286
+ sql: { postgresql: AUTH_MIGRATION_020_IDENTITY_PROVIDERS },
1287
+ inspectExisting: (database) =>
1288
+ postgresTenantTableState(
1289
+ database,
1290
+ 'auth_identity_providers',
1291
+ 'auth_identity_providers_tenant_policy',
1292
+ [
1293
+ () => database.schema.hasIndex('auth_identity_providers_tenant_idx'),
1294
+ () =>
1295
+ database.schema.hasColumn('auth_external_identities', 'tenant_id'),
1296
+ () =>
1297
+ database.schema.hasIndex('auth_external_identities_workspace_idx'),
1298
+ ],
1299
+ ),
1300
+ },
1301
+ {
1302
+ id: '0021_membership_status',
1303
+ sql: { postgresql: AUTH_MIGRATION_021_MEMBERSHIP_STATUS },
1304
+ inspectExisting: (database) =>
1305
+ migrationObjectState([
1306
+ () => database.schema.hasColumn('auth_memberships', 'status'),
1307
+ ]),
1308
+ },
1309
+ /* Data-only like 0018 and 0019, and for the same reason it declares no
1310
+ inspectExisting: a probe over the rows would report a fresh database, which
1311
+ receives these scopes from acl/scopes.ts, as adopted. */
1312
+ {
1313
+ id: '0022_auth_provider_scopes',
1314
+ sql: { postgresql: AUTH_MIGRATION_022_AUTH_PROVIDER_SCOPES },
1315
+ },
1316
+ /* Data-only like 0018, 0019 and 0022, and for the same reason it declares no
1317
+ inspectExisting: a probe over the rows would report a fresh database, which
1318
+ receives these scopes from acl/scopes.ts, as adopted. */
1319
+ {
1320
+ id: '0023_enterprise_module_scopes',
1321
+ sql: { postgresql: AUTH_MIGRATION_023_ENTERPRISE_MODULE_SCOPES },
1322
+ },
1323
+ /* Data-only like 0018, 0019, 0022 and 0023, and for the same reason it
1324
+ declares no inspectExisting: a probe over the rows would report a fresh
1325
+ database, which receives these scopes from acl/scopes.ts, as adopted. */
1326
+ {
1327
+ id: '0024_approvals_member_scopes',
1328
+ sql: { postgresql: AUTH_MIGRATION_024_APPROVALS_MEMBER_SCOPES },
1329
+ },
1330
+ /* Data-only like 0018, 0019, 0022, 0023 and 0024, and for the same reason it
1331
+ declares no inspectExisting: a probe over the rows would report a fresh
1332
+ database, which receives this scope from acl/scopes.ts, as adopted. */
1333
+ {
1334
+ id: '0025_audit_holds_owner_scope',
1335
+ sql: { postgresql: AUTH_MIGRATION_025_AUDIT_HOLDS_OWNER_SCOPE },
1336
+ },
1337
+ {
1338
+ id: '0026_auth_export_keyset_indexes',
1339
+ sql: { postgresql: AUTH_MIGRATION_026_AUTH_EXPORT_KEYSET_INDEXES },
1340
+ inspectExisting: (database) =>
1341
+ migrationObjectState([
1342
+ () => database.schema.hasIndex('auth_sessions_tenant_keyset_idx'),
1343
+ () => database.schema.hasIndex('auth_api_tokens_tenant_keyset_idx'),
1344
+ () => database.schema.hasIndex('auth_audit_tenant_keyset_idx'),
1345
+ ]),
1346
+ },
1347
+ /* Data-only like 0018, 0019, 0022, 0023, 0024 and 0025, and for the same
1348
+ reason it declares no inspectExisting: a probe over the rows would report a
1349
+ fresh database, which receives these scopes from acl/scopes.ts, as adopted. */
1350
+ {
1351
+ id: '0027_workflow_automation_profile_scopes',
1352
+ sql: { postgresql: AUTH_MIGRATION_027_WORKFLOW_AUTOMATION_PROFILE_SCOPES },
1353
+ },
1354
+ {
1355
+ id: '0028_auth_member_search_prefix_indexes',
1356
+ sql: { postgresql: AUTH_MIGRATION_028_AUTH_MEMBER_SEARCH_PREFIX_INDEXES },
1357
+ inspectExisting: (database) =>
1358
+ migrationObjectState([
1359
+ () => database.schema.hasIndex('auth_accounts_display_name_prefix_idx'),
1360
+ () => database.schema.hasIndex('auth_accounts_email_prefix_idx'),
1361
+ ]),
1362
+ },
1363
+ /* Data-only like 0018, 0019, 0022, 0023, 0024, 0025 and 0027, and for the same
1364
+ reason it declares no inspectExisting: a probe over the rows would report a
1365
+ fresh database, which receives these scopes from acl/scopes.ts, as adopted. */
1366
+ {
1367
+ id: '0029_reports_exports_access_scopes',
1368
+ sql: { postgresql: AUTH_MIGRATION_029_REPORTS_EXPORTS_ACCESS_SCOPES },
1369
+ },
1370
+ {
1371
+ id: '0030_auth_membership_keyset_index',
1372
+ sql: { postgresql: AUTH_MIGRATION_030_AUTH_MEMBERSHIP_KEYSET_INDEX },
1373
+ inspectExisting: (database) =>
1374
+ migrationObjectState([
1375
+ () => database.schema.hasIndex('auth_memberships_tenant_keyset_idx'),
1376
+ ]),
1377
+ },
1378
+ {
1379
+ id: '0031_membership_scope_backfills_under_rls',
1380
+ sql: {
1381
+ postgresql: AUTH_MIGRATION_031_MEMBERSHIP_SCOPE_BACKFILLS_UNDER_RLS,
1382
+ },
1383
+ },
1384
+ {
1385
+ id: '0032_audit_actor_service',
1386
+ sql: { postgresql: AUTH_MIGRATION_032_AUDIT_ACTOR_SERVICE },
1387
+ inspectExisting: (database) =>
1388
+ migrationObjectState([
1389
+ () => database.schema.hasColumn('auth_audit', 'configured_by_json'),
1390
+ ]),
1391
+ },
1392
+ {
1393
+ id: '0033_auth_account_keyset_indexes',
1394
+ sql: { postgresql: AUTH_MIGRATION_033_AUTH_ACCOUNT_KEYSET_INDEXES },
1395
+ inspectExisting: (database) =>
1396
+ migrationObjectState([
1397
+ () => database.schema.hasIndex('auth_accounts_display_name_keyset_idx'),
1398
+ () => database.schema.hasIndex('auth_accounts_email_keyset_idx'),
1399
+ ]),
1400
+ },
591
1401
  ];