@eloxiv/kernel 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +6 -2
- package/dist/AccountMail.d.ts +40 -0
- package/dist/AccountMail.d.ts.map +1 -0
- package/dist/AccountMail.js +169 -0
- package/dist/AccountMail.js.map +1 -0
- package/dist/AppConfig.d.ts +72 -0
- package/dist/AppConfig.d.ts.map +1 -0
- package/dist/AppConfig.js +87 -0
- package/dist/AppConfig.js.map +1 -0
- package/dist/Approvals.d.ts +132 -0
- package/dist/Approvals.d.ts.map +1 -0
- package/dist/Approvals.js +342 -0
- package/dist/Approvals.js.map +1 -0
- package/dist/Audit.d.ts +93 -0
- package/dist/Audit.d.ts.map +1 -0
- package/dist/Audit.js +275 -0
- package/dist/Audit.js.map +1 -0
- package/dist/AuthSeam.d.ts +58 -0
- package/dist/AuthSeam.d.ts.map +1 -0
- package/dist/AuthSeam.js +101 -0
- package/dist/AuthSeam.js.map +1 -0
- package/dist/Authority.d.ts +160 -0
- package/dist/Authority.d.ts.map +1 -0
- package/dist/Authority.js +325 -0
- package/dist/Authority.js.map +1 -0
- package/dist/Avatars.d.ts +26 -0
- package/dist/Avatars.d.ts.map +1 -0
- package/dist/Avatars.js +140 -0
- package/dist/Avatars.js.map +1 -0
- package/dist/Base64url.d.ts +9 -0
- package/dist/Base64url.d.ts.map +1 -0
- package/dist/Base64url.js +26 -0
- package/dist/Base64url.js.map +1 -0
- package/dist/BasePath.d.ts +39 -0
- package/dist/BasePath.d.ts.map +1 -0
- package/dist/BasePath.js +70 -0
- package/dist/BasePath.js.map +1 -0
- package/dist/CallActed.d.ts +10 -0
- package/dist/CallActed.d.ts.map +1 -0
- package/dist/CallActed.js +10 -0
- package/dist/CallActed.js.map +1 -0
- package/dist/Config.d.ts +459 -0
- package/dist/Config.d.ts.map +1 -0
- package/dist/Config.js +415 -0
- package/dist/Config.js.map +1 -0
- package/dist/DeliveryPolicy.d.ts +20 -0
- package/dist/DeliveryPolicy.d.ts.map +1 -0
- package/dist/DeliveryPolicy.js +35 -0
- package/dist/DeliveryPolicy.js.map +1 -0
- package/dist/DesktopSignIn.d.ts +24 -0
- package/dist/DesktopSignIn.d.ts.map +1 -0
- package/dist/DesktopSignIn.js +148 -0
- package/dist/DesktopSignIn.js.map +1 -0
- package/dist/Directory.d.ts +179 -0
- package/dist/Directory.d.ts.map +1 -0
- package/dist/Directory.js +1184 -0
- package/dist/Directory.js.map +1 -0
- package/dist/Flags.d.ts +59 -0
- package/dist/Flags.d.ts.map +1 -0
- package/dist/Flags.js +195 -0
- package/dist/Flags.js.map +1 -0
- package/dist/Gate.d.ts +42 -0
- package/dist/Gate.d.ts.map +1 -0
- package/dist/Gate.js +132 -0
- package/dist/Gate.js.map +1 -0
- package/dist/Hash.d.ts +4 -0
- package/dist/Hash.d.ts.map +1 -0
- package/dist/Hash.js +16 -0
- package/dist/Hash.js.map +1 -0
- package/dist/Identity.d.ts +327 -0
- package/dist/Identity.d.ts.map +1 -0
- package/dist/Identity.js +1232 -0
- package/dist/Identity.js.map +1 -0
- package/dist/IntervalJob.d.ts +40 -0
- package/dist/IntervalJob.d.ts.map +1 -0
- package/dist/IntervalJob.js +76 -0
- package/dist/IntervalJob.js.map +1 -0
- package/dist/Invocation.d.ts +210 -0
- package/dist/Invocation.d.ts.map +1 -0
- package/dist/Invocation.js +1680 -0
- package/dist/Invocation.js.map +1 -0
- package/dist/KernelHandlers.d.ts +19 -0
- package/dist/KernelHandlers.d.ts.map +1 -0
- package/dist/KernelHandlers.js +15 -0
- package/dist/KernelHandlers.js.map +1 -0
- package/dist/KernelModule.d.ts +65 -0
- package/dist/KernelModule.d.ts.map +1 -0
- package/dist/KernelModule.js +116 -0
- package/dist/KernelModule.js.map +1 -0
- package/dist/MemberRoutes.d.ts +6 -0
- package/dist/MemberRoutes.d.ts.map +1 -0
- package/dist/MemberRoutes.js +107 -0
- package/dist/MemberRoutes.js.map +1 -0
- package/dist/Module.d.ts +479 -0
- package/dist/Module.d.ts.map +1 -0
- package/dist/Module.js +30 -0
- package/dist/Module.js.map +1 -0
- package/dist/ModuleIdentity.d.ts +17 -0
- package/dist/ModuleIdentity.d.ts.map +1 -0
- package/dist/ModuleIdentity.js +106 -0
- package/dist/ModuleIdentity.js.map +1 -0
- package/dist/Notifications.d.ts +107 -0
- package/dist/Notifications.d.ts.map +1 -0
- package/dist/Notifications.js +475 -0
- package/dist/Notifications.js.map +1 -0
- package/dist/Outbox.d.ts +146 -0
- package/dist/Outbox.d.ts.map +1 -0
- package/dist/Outbox.js +518 -0
- package/dist/Outbox.js.map +1 -0
- package/dist/Privacy.d.ts +50 -0
- package/dist/Privacy.d.ts.map +1 -0
- package/dist/Privacy.js +167 -0
- package/dist/Privacy.js.map +1 -0
- package/dist/Progress.d.ts +42 -0
- package/dist/Progress.d.ts.map +1 -0
- package/dist/Progress.js +215 -0
- package/dist/Progress.js.map +1 -0
- package/dist/QuerySurface.d.ts +73 -0
- package/dist/QuerySurface.d.ts.map +1 -0
- package/dist/QuerySurface.js +440 -0
- package/dist/QuerySurface.js.map +1 -0
- package/dist/QueryViews.d.ts +70 -0
- package/dist/QueryViews.d.ts.map +1 -0
- package/dist/QueryViews.js +94 -0
- package/dist/QueryViews.js.map +1 -0
- package/dist/Readiness.d.ts +40 -0
- package/dist/Readiness.d.ts.map +1 -0
- package/dist/Readiness.js +203 -0
- package/dist/Readiness.js.map +1 -0
- package/dist/Redact.d.ts +11 -0
- package/dist/Redact.d.ts.map +1 -0
- package/dist/Redact.js +21 -0
- package/dist/Redact.js.map +1 -0
- package/dist/Registry.d.ts +117 -0
- package/dist/Registry.d.ts.map +1 -0
- package/dist/Registry.js +297 -0
- package/dist/Registry.js.map +1 -0
- package/dist/Release.d.ts +205 -0
- package/dist/Release.d.ts.map +1 -0
- package/dist/Release.js +880 -0
- package/dist/Release.js.map +1 -0
- package/dist/Retention.d.ts +43 -0
- package/dist/Retention.d.ts.map +1 -0
- package/dist/Retention.js +124 -0
- package/dist/Retention.js.map +1 -0
- package/dist/Scheduler.d.ts +56 -0
- package/dist/Scheduler.d.ts.map +1 -0
- package/dist/Scheduler.js +470 -0
- package/dist/Scheduler.js.map +1 -0
- package/dist/Server.d.ts +341 -0
- package/dist/Server.d.ts.map +1 -0
- package/dist/Server.js +1106 -0
- package/dist/Server.js.map +1 -0
- package/dist/Sessions.d.ts +38 -0
- package/dist/Sessions.d.ts.map +1 -0
- package/dist/Sessions.js +45 -0
- package/dist/Sessions.js.map +1 -0
- package/dist/Settings.d.ts +63 -0
- package/dist/Settings.d.ts.map +1 -0
- package/dist/Settings.js +219 -0
- package/dist/Settings.js.map +1 -0
- package/dist/Sharing.d.ts +99 -0
- package/dist/Sharing.d.ts.map +1 -0
- package/dist/Sharing.js +315 -0
- package/dist/Sharing.js.map +1 -0
- package/dist/Sync.d.ts +188 -0
- package/dist/Sync.d.ts.map +1 -0
- package/dist/Sync.js +1100 -0
- package/dist/Sync.js.map +1 -0
- package/dist/Telemetry.d.ts +154 -0
- package/dist/Telemetry.d.ts.map +1 -0
- package/dist/Telemetry.js +536 -0
- package/dist/Telemetry.js.map +1 -0
- package/dist/Versioning.d.ts +98 -0
- package/dist/Versioning.d.ts.map +1 -0
- package/dist/Versioning.js +387 -0
- package/dist/Versioning.js.map +1 -0
- package/dist/WorkItems.d.ts +67 -0
- package/dist/WorkItems.d.ts.map +1 -0
- package/dist/WorkItems.js +211 -0
- package/dist/WorkItems.js.map +1 -0
- package/dist/Workflows.d.ts +78 -0
- package/dist/Workflows.d.ts.map +1 -0
- package/dist/Workflows.js +478 -0
- package/dist/Workflows.js.map +1 -0
- package/dist/agent/Admission.d.ts +22 -0
- package/dist/agent/Admission.d.ts.map +1 -0
- package/dist/agent/Admission.js +34 -0
- package/dist/agent/Admission.js.map +1 -0
- package/dist/agent/Channels.d.ts +15 -0
- package/dist/agent/Channels.d.ts.map +1 -0
- package/dist/agent/Channels.js +50 -0
- package/dist/agent/Channels.js.map +1 -0
- package/dist/agent/Context.d.ts +73 -0
- package/dist/agent/Context.d.ts.map +1 -0
- package/dist/agent/Context.js +338 -0
- package/dist/agent/Context.js.map +1 -0
- package/dist/agent/Http.d.ts +18 -0
- package/dist/agent/Http.d.ts.map +1 -0
- package/dist/agent/Http.js +410 -0
- package/dist/agent/Http.js.map +1 -0
- package/dist/agent/Metering.d.ts +162 -0
- package/dist/agent/Metering.d.ts.map +1 -0
- package/dist/agent/Metering.js +315 -0
- package/dist/agent/Metering.js.map +1 -0
- package/dist/agent/ModelSetup.d.ts +10 -0
- package/dist/agent/ModelSetup.d.ts.map +1 -0
- package/dist/agent/ModelSetup.js +331 -0
- package/dist/agent/ModelSetup.js.map +1 -0
- package/dist/agent/Models.d.ts +197 -0
- package/dist/agent/Models.d.ts.map +1 -0
- package/dist/agent/Models.js +489 -0
- package/dist/agent/Models.js.map +1 -0
- package/dist/agent/Processors.d.ts +102 -0
- package/dist/agent/Processors.d.ts.map +1 -0
- package/dist/agent/Processors.js +80 -0
- package/dist/agent/Processors.js.map +1 -0
- package/dist/agent/Queue.d.ts +21 -0
- package/dist/agent/Queue.d.ts.map +1 -0
- package/dist/agent/Queue.js +64 -0
- package/dist/agent/Queue.js.map +1 -0
- package/dist/agent/Receipts.d.ts +41 -0
- package/dist/agent/Receipts.d.ts.map +1 -0
- package/dist/agent/Receipts.js +142 -0
- package/dist/agent/Receipts.js.map +1 -0
- package/dist/agent/Resources.d.ts +68 -0
- package/dist/agent/Resources.d.ts.map +1 -0
- package/dist/agent/Resources.js +207 -0
- package/dist/agent/Resources.js.map +1 -0
- package/dist/agent/Run.d.ts +178 -0
- package/dist/agent/Run.d.ts.map +1 -0
- package/dist/agent/Run.js +2896 -0
- package/dist/agent/Run.js.map +1 -0
- package/dist/agent/Runtime.d.ts +79 -0
- package/dist/agent/Runtime.d.ts.map +1 -0
- package/dist/agent/Runtime.js +366 -0
- package/dist/agent/Runtime.js.map +1 -0
- package/dist/agent/Settings.d.ts +126 -0
- package/dist/agent/Settings.d.ts.map +1 -0
- package/dist/agent/Settings.js +44 -0
- package/dist/agent/Settings.js.map +1 -0
- package/dist/agent/Skills.d.ts +73 -0
- package/dist/agent/Skills.d.ts.map +1 -0
- package/dist/agent/Skills.js +95 -0
- package/dist/agent/Skills.js.map +1 -0
- package/dist/agent/Store.d.ts +37 -0
- package/dist/agent/Store.d.ts.map +1 -0
- package/dist/agent/Store.js +50 -0
- package/dist/agent/Store.js.map +1 -0
- package/dist/agent/ToolSearch.d.ts +37 -0
- package/dist/agent/ToolSearch.d.ts.map +1 -0
- package/dist/agent/ToolSearch.js +119 -0
- package/dist/agent/ToolSearch.js.map +1 -0
- package/dist/agent/index.d.ts +37 -0
- package/dist/agent/index.d.ts.map +1 -0
- package/dist/agent/index.js +44 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/agent/module.d.ts +12889 -0
- package/dist/agent/module.d.ts.map +1 -0
- package/dist/agent/module.js +1550 -0
- package/dist/agent/module.js.map +1 -0
- package/dist/appState/Sweep.d.ts +21 -0
- package/dist/appState/Sweep.d.ts.map +1 -0
- package/dist/appState/Sweep.js +46 -0
- package/dist/appState/Sweep.js.map +1 -0
- package/dist/appState/module.d.ts +1710 -0
- package/dist/appState/module.d.ts.map +1 -0
- package/dist/appState/module.js +344 -0
- package/dist/appState/module.js.map +1 -0
- package/dist/audit/module.d.ts +158 -0
- package/dist/audit/module.d.ts.map +1 -0
- package/dist/audit/module.js +72 -0
- package/dist/audit/module.js.map +1 -0
- package/dist/auth/AuthProvider.d.ts +224 -0
- package/dist/auth/AuthProvider.d.ts.map +1 -0
- package/dist/auth/AuthProvider.js +104 -0
- package/dist/auth/AuthProvider.js.map +1 -0
- package/dist/auth/BetterAuthProvider.d.ts +40 -0
- package/dist/auth/BetterAuthProvider.d.ts.map +1 -0
- package/dist/auth/BetterAuthProvider.js +458 -0
- package/dist/auth/BetterAuthProvider.js.map +1 -0
- package/dist/auth/Methods.d.ts +7 -0
- package/dist/auth/Methods.d.ts.map +1 -0
- package/dist/auth/Methods.js +7 -0
- package/dist/auth/Methods.js.map +1 -0
- package/dist/auth/SessionTokens.d.ts +23 -0
- package/dist/auth/SessionTokens.d.ts.map +1 -0
- package/dist/auth/SessionTokens.js +150 -0
- package/dist/auth/SessionTokens.js.map +1 -0
- package/dist/collab/Collab.d.ts +105 -0
- package/dist/collab/Collab.d.ts.map +1 -0
- package/dist/collab/Collab.js +475 -0
- package/dist/collab/Collab.js.map +1 -0
- package/dist/collab/Housekeeping.d.ts +38 -0
- package/dist/collab/Housekeeping.d.ts.map +1 -0
- package/dist/collab/Housekeeping.js +146 -0
- package/dist/collab/Housekeeping.js.map +1 -0
- package/dist/collab/LiveCopy.d.ts +7 -0
- package/dist/collab/LiveCopy.d.ts.map +1 -0
- package/dist/collab/LiveCopy.js +79 -0
- package/dist/collab/LiveCopy.js.map +1 -0
- package/dist/collab/Socket.d.ts +19 -0
- package/dist/collab/Socket.d.ts.map +1 -0
- package/dist/collab/Socket.js +323 -0
- package/dist/collab/Socket.js.map +1 -0
- package/dist/collab/Store.d.ts +42 -0
- package/dist/collab/Store.d.ts.map +1 -0
- package/dist/collab/Store.js +59 -0
- package/dist/collab/Store.js.map +1 -0
- package/dist/collab/Ydoc.d.ts +88 -0
- package/dist/collab/Ydoc.d.ts.map +1 -0
- package/dist/collab/Ydoc.js +314 -0
- package/dist/collab/Ydoc.js.map +1 -0
- package/dist/collab/derive/bundle.gen.d.ts +2 -0
- package/dist/collab/derive/bundle.gen.d.ts.map +1 -0
- package/dist/collab/derive/bundle.gen.js +3 -0
- package/dist/collab/derive/bundle.gen.js.map +1 -0
- package/dist/collab/derive/entry.d.ts +3 -0
- package/dist/collab/derive/entry.d.ts.map +1 -0
- package/dist/collab/derive/entry.js +35 -0
- package/dist/collab/derive/entry.js.map +1 -0
- package/dist/collab/derive/polyfill.d.ts +3 -0
- package/dist/collab/derive/polyfill.d.ts.map +1 -0
- package/dist/collab/derive/polyfill.js +17 -0
- package/dist/collab/derive/polyfill.js.map +1 -0
- package/dist/collab/module.d.ts +305 -0
- package/dist/collab/module.d.ts.map +1 -0
- package/dist/collab/module.js +161 -0
- package/dist/collab/module.js.map +1 -0
- package/dist/connections/Connections.d.ts +199 -0
- package/dist/connections/Connections.d.ts.map +1 -0
- package/dist/connections/Connections.js +1633 -0
- package/dist/connections/Connections.js.map +1 -0
- package/dist/connections/Connector.d.ts +213 -0
- package/dist/connections/Connector.d.ts.map +1 -0
- package/dist/connections/Connector.js +55 -0
- package/dist/connections/Connector.js.map +1 -0
- package/dist/connections/Crypto.d.ts +55 -0
- package/dist/connections/Crypto.d.ts.map +1 -0
- package/dist/connections/Crypto.js +100 -0
- package/dist/connections/Crypto.js.map +1 -0
- package/dist/connections/Destinations.d.ts +63 -0
- package/dist/connections/Destinations.d.ts.map +1 -0
- package/dist/connections/Destinations.js +338 -0
- package/dist/connections/Destinations.js.map +1 -0
- package/dist/connections/Discovery.d.ts +53 -0
- package/dist/connections/Discovery.d.ts.map +1 -0
- package/dist/connections/Discovery.js +209 -0
- package/dist/connections/Discovery.js.map +1 -0
- package/dist/connections/EffectKinds.d.ts +17 -0
- package/dist/connections/EffectKinds.d.ts.map +1 -0
- package/dist/connections/EffectKinds.js +26 -0
- package/dist/connections/EffectKinds.js.map +1 -0
- package/dist/connections/Effects.d.ts +49 -0
- package/dist/connections/Effects.d.ts.map +1 -0
- package/dist/connections/Effects.js +347 -0
- package/dist/connections/Effects.js.map +1 -0
- package/dist/connections/Metering.d.ts +40 -0
- package/dist/connections/Metering.d.ts.map +1 -0
- package/dist/connections/Metering.js +142 -0
- package/dist/connections/Metering.js.map +1 -0
- package/dist/connections/ProviderApi.d.ts +47 -0
- package/dist/connections/ProviderApi.d.ts.map +1 -0
- package/dist/connections/ProviderApi.js +103 -0
- package/dist/connections/ProviderApi.js.map +1 -0
- package/dist/connections/Secrets.d.ts +78 -0
- package/dist/connections/Secrets.d.ts.map +1 -0
- package/dist/connections/Secrets.js +342 -0
- package/dist/connections/Secrets.js.map +1 -0
- package/dist/connections/Sync.d.ts +85 -0
- package/dist/connections/Sync.d.ts.map +1 -0
- package/dist/connections/Sync.js +201 -0
- package/dist/connections/Sync.js.map +1 -0
- package/dist/connections/module.d.ts +1061 -0
- package/dist/connections/module.d.ts.map +1 -0
- package/dist/connections/module.js +485 -0
- package/dist/connections/module.js.map +1 -0
- package/dist/data/Corpus.d.ts +79 -0
- package/dist/data/Corpus.d.ts.map +1 -0
- package/dist/data/Corpus.js +343 -0
- package/dist/data/Corpus.js.map +1 -0
- package/dist/data/Datasets.d.ts +88 -0
- package/dist/data/Datasets.d.ts.map +1 -0
- package/dist/data/Datasets.js +375 -0
- package/dist/data/Datasets.js.map +1 -0
- package/dist/data/Programs.d.ts +58 -0
- package/dist/data/Programs.d.ts.map +1 -0
- package/dist/data/Programs.js +197 -0
- package/dist/data/Programs.js.map +1 -0
- package/dist/data/module.d.ts +210 -0
- package/dist/data/module.d.ts.map +1 -0
- package/dist/data/module.js +140 -0
- package/dist/data/module.js.map +1 -0
- package/dist/db/Bootstrap.d.ts +508 -0
- package/dist/db/Bootstrap.d.ts.map +1 -0
- package/dist/db/Bootstrap.js +2368 -0
- package/dist/db/Bootstrap.js.map +1 -0
- package/dist/db/Catalog.d.ts +10 -0
- package/dist/db/Catalog.d.ts.map +1 -0
- package/dist/db/Catalog.js +9 -0
- package/dist/db/Catalog.js.map +1 -0
- package/dist/db/Conflicts.d.ts +18 -0
- package/dist/db/Conflicts.d.ts.map +1 -0
- package/dist/db/Conflicts.js +29 -0
- package/dist/db/Conflicts.js.map +1 -0
- package/dist/db/DirectoryLock.d.ts +16 -0
- package/dist/db/DirectoryLock.d.ts.map +1 -0
- package/dist/db/DirectoryLock.js +15 -0
- package/dist/db/DirectoryLock.js.map +1 -0
- package/dist/db/HandlerGate.d.ts +28 -0
- package/dist/db/HandlerGate.d.ts.map +1 -0
- package/dist/db/HandlerGate.js +76 -0
- package/dist/db/HandlerGate.js.map +1 -0
- package/dist/db/Host.d.ts +94 -0
- package/dist/db/Host.d.ts.map +1 -0
- package/dist/db/Host.js +189 -0
- package/dist/db/Host.js.map +1 -0
- package/dist/db/KernelSchema.d.ts +52 -0
- package/dist/db/KernelSchema.d.ts.map +1 -0
- package/dist/db/KernelSchema.js +4313 -0
- package/dist/db/KernelSchema.js.map +1 -0
- package/dist/db/MigrationCheck.d.ts +38 -0
- package/dist/db/MigrationCheck.d.ts.map +1 -0
- package/dist/db/MigrationCheck.js +180 -0
- package/dist/db/MigrationCheck.js.map +1 -0
- package/dist/db/QueryViewCheck.d.ts +172 -0
- package/dist/db/QueryViewCheck.d.ts.map +1 -0
- package/dist/db/QueryViewCheck.js +967 -0
- package/dist/db/QueryViewCheck.js.map +1 -0
- package/dist/db/ReadOnly.d.ts +13 -0
- package/dist/db/ReadOnly.d.ts.map +1 -0
- package/dist/db/ReadOnly.js +16 -0
- package/dist/db/ReadOnly.js.map +1 -0
- package/dist/db/Scram.d.ts +5 -0
- package/dist/db/Scram.d.ts.map +1 -0
- package/dist/db/Scram.js +17 -0
- package/dist/db/Scram.js.map +1 -0
- package/dist/db/SqlState.d.ts +36 -0
- package/dist/db/SqlState.d.ts.map +1 -0
- package/dist/db/SqlState.js +64 -0
- package/dist/db/SqlState.js.map +1 -0
- package/dist/db/Startup.d.ts +18 -0
- package/dist/db/Startup.d.ts.map +1 -0
- package/dist/db/Startup.js +22 -0
- package/dist/db/Startup.js.map +1 -0
- package/dist/db/ZeroDdl.d.ts +85 -0
- package/dist/db/ZeroDdl.d.ts.map +1 -0
- package/dist/db/ZeroDdl.js +240 -0
- package/dist/db/ZeroDdl.js.map +1 -0
- package/dist/db/ZeroPush.d.ts +7 -0
- package/dist/db/ZeroPush.d.ts.map +1 -0
- package/dist/db/ZeroPush.js +126 -0
- package/dist/db/ZeroPush.js.map +1 -0
- package/dist/devices/Devices.d.ts +130 -0
- package/dist/devices/Devices.d.ts.map +1 -0
- package/dist/devices/Devices.js +769 -0
- package/dist/devices/Devices.js.map +1 -0
- package/dist/devices/Flow.d.ts +47 -0
- package/dist/devices/Flow.d.ts.map +1 -0
- package/dist/devices/Flow.js +131 -0
- package/dist/devices/Flow.js.map +1 -0
- package/dist/devices/Http.d.ts +6 -0
- package/dist/devices/Http.d.ts.map +1 -0
- package/dist/devices/Http.js +103 -0
- package/dist/devices/Http.js.map +1 -0
- package/dist/devices/module.d.ts +1313 -0
- package/dist/devices/module.d.ts.map +1 -0
- package/dist/devices/module.js +266 -0
- package/dist/devices/module.js.map +1 -0
- package/dist/durable/Cluster.d.ts +13 -0
- package/dist/durable/Cluster.d.ts.map +1 -0
- package/dist/durable/Cluster.js +57 -0
- package/dist/durable/Cluster.js.map +1 -0
- package/dist/durable/Definition.d.ts +215 -0
- package/dist/durable/Definition.d.ts.map +1 -0
- package/dist/durable/Definition.js +18 -0
- package/dist/durable/Definition.js.map +1 -0
- package/dist/durable/Schedule.d.ts +46 -0
- package/dist/durable/Schedule.d.ts.map +1 -0
- package/dist/durable/Schedule.js +120 -0
- package/dist/durable/Schedule.js.map +1 -0
- package/dist/durable/Trust.d.ts +90 -0
- package/dist/durable/Trust.d.ts.map +1 -0
- package/dist/durable/Trust.js +61 -0
- package/dist/durable/Trust.js.map +1 -0
- package/dist/enterprise/Routes.d.ts +32 -0
- package/dist/enterprise/Routes.d.ts.map +1 -0
- package/dist/enterprise/Routes.js +448 -0
- package/dist/enterprise/Routes.js.map +1 -0
- package/dist/enterprise/WorkOs.d.ts +42 -0
- package/dist/enterprise/WorkOs.d.ts.map +1 -0
- package/dist/enterprise/WorkOs.js +109 -0
- package/dist/enterprise/WorkOs.js.map +1 -0
- package/dist/files/FileTable.d.ts +937 -0
- package/dist/files/FileTable.d.ts.map +1 -0
- package/dist/files/FileTable.js +79 -0
- package/dist/files/FileTable.js.map +1 -0
- package/dist/files/Files.d.ts +169 -0
- package/dist/files/Files.d.ts.map +1 -0
- package/dist/files/Files.js +1232 -0
- package/dist/files/Files.js.map +1 -0
- package/dist/files/Http.d.ts +13 -0
- package/dist/files/Http.d.ts.map +1 -0
- package/dist/files/Http.js +30 -0
- package/dist/files/Http.js.map +1 -0
- package/dist/files/LocalStorage.d.ts +7 -0
- package/dist/files/LocalStorage.d.ts.map +1 -0
- package/dist/files/LocalStorage.js +284 -0
- package/dist/files/LocalStorage.js.map +1 -0
- package/dist/files/Providers.d.ts +64 -0
- package/dist/files/Providers.d.ts.map +1 -0
- package/dist/files/Providers.js +245 -0
- package/dist/files/Providers.js.map +1 -0
- package/dist/files/S3Storage.d.ts +27 -0
- package/dist/files/S3Storage.d.ts.map +1 -0
- package/dist/files/S3Storage.js +301 -0
- package/dist/files/S3Storage.js.map +1 -0
- package/dist/files/SigV4.d.ts +65 -0
- package/dist/files/SigV4.d.ts.map +1 -0
- package/dist/files/SigV4.js +152 -0
- package/dist/files/SigV4.js.map +1 -0
- package/dist/files/Sniff.d.ts +50 -0
- package/dist/files/Sniff.d.ts.map +1 -0
- package/dist/files/Sniff.js +223 -0
- package/dist/files/Sniff.js.map +1 -0
- package/dist/files/Storage.d.ts +75 -0
- package/dist/files/Storage.d.ts.map +1 -0
- package/dist/files/Storage.js +70 -0
- package/dist/files/Storage.js.map +1 -0
- package/dist/files/module.d.ts +666 -0
- package/dist/files/module.d.ts.map +1 -0
- package/dist/files/module.js +217 -0
- package/dist/files/module.js.map +1 -0
- package/dist/flags/module.d.ts +966 -0
- package/dist/flags/module.d.ts.map +1 -0
- package/dist/flags/module.js +146 -0
- package/dist/flags/module.js.map +1 -0
- package/dist/inbox/Flow.d.ts +49 -0
- package/dist/inbox/Flow.d.ts.map +1 -0
- package/dist/inbox/Flow.js +425 -0
- package/dist/inbox/Flow.js.map +1 -0
- package/dist/inbox/System.d.ts +11 -0
- package/dist/inbox/System.d.ts.map +1 -0
- package/dist/inbox/System.js +26 -0
- package/dist/inbox/System.js.map +1 -0
- package/dist/inbox/approvals.d.ts +1548 -0
- package/dist/inbox/approvals.d.ts.map +1 -0
- package/dist/inbox/approvals.js +268 -0
- package/dist/inbox/approvals.js.map +1 -0
- package/dist/inbox/consent.d.ts +1213 -0
- package/dist/inbox/consent.d.ts.map +1 -0
- package/dist/inbox/consent.js +281 -0
- package/dist/inbox/consent.js.map +1 -0
- package/dist/inbox/index.d.ts +2231 -0
- package/dist/inbox/index.d.ts.map +1 -0
- package/dist/inbox/index.js +22 -0
- package/dist/inbox/index.js.map +1 -0
- package/dist/inbox/notifications.d.ts +2743 -0
- package/dist/inbox/notifications.d.ts.map +1 -0
- package/dist/inbox/notifications.js +362 -0
- package/dist/inbox/notifications.js.map +1 -0
- package/dist/inbox/tables.d.ts +1992 -0
- package/dist/inbox/tables.d.ts.map +1 -0
- package/dist/inbox/tables.js +149 -0
- package/dist/inbox/tables.js.map +1 -0
- package/dist/inbox/workItems.d.ts +1188 -0
- package/dist/inbox/workItems.d.ts.map +1 -0
- package/dist/inbox/workItems.js +158 -0
- package/dist/inbox/workItems.js.map +1 -0
- package/dist/index.d.ts +152 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +154 -0
- package/dist/index.js.map +1 -0
- package/dist/ingestion/Chunk.d.ts +15 -0
- package/dist/ingestion/Chunk.d.ts.map +1 -0
- package/dist/ingestion/Chunk.js +49 -0
- package/dist/ingestion/Chunk.js.map +1 -0
- package/dist/ingestion/Extract.d.ts +69 -0
- package/dist/ingestion/Extract.d.ts.map +1 -0
- package/dist/ingestion/Extract.js +376 -0
- package/dist/ingestion/Extract.js.map +1 -0
- package/dist/ingestion/ExtractChild.d.ts +2 -0
- package/dist/ingestion/ExtractChild.d.ts.map +1 -0
- package/dist/ingestion/ExtractChild.js +54 -0
- package/dist/ingestion/ExtractChild.js.map +1 -0
- package/dist/ingestion/ExtractPool.d.ts +38 -0
- package/dist/ingestion/ExtractPool.d.ts.map +1 -0
- package/dist/ingestion/ExtractPool.js +203 -0
- package/dist/ingestion/ExtractPool.js.map +1 -0
- package/dist/ingestion/Ingestion.d.ts +183 -0
- package/dist/ingestion/Ingestion.d.ts.map +1 -0
- package/dist/ingestion/Ingestion.js +650 -0
- package/dist/ingestion/Ingestion.js.map +1 -0
- package/dist/ingestion/Isolated.d.ts +18 -0
- package/dist/ingestion/Isolated.d.ts.map +1 -0
- package/dist/ingestion/Isolated.js +15 -0
- package/dist/ingestion/Isolated.js.map +1 -0
- package/dist/ingestion/Markup.d.ts +29 -0
- package/dist/ingestion/Markup.d.ts.map +1 -0
- package/dist/ingestion/Markup.js +111 -0
- package/dist/ingestion/Markup.js.map +1 -0
- package/dist/ingestion/Pdf.d.ts +6 -0
- package/dist/ingestion/Pdf.d.ts.map +1 -0
- package/dist/ingestion/Pdf.js +192 -0
- package/dist/ingestion/Pdf.js.map +1 -0
- package/dist/ingestion/Runs.d.ts +59 -0
- package/dist/ingestion/Runs.d.ts.map +1 -0
- package/dist/ingestion/Runs.js +128 -0
- package/dist/ingestion/Runs.js.map +1 -0
- package/dist/ingestion/Scrub.d.ts +16 -0
- package/dist/ingestion/Scrub.d.ts.map +1 -0
- package/dist/ingestion/Scrub.js +15 -0
- package/dist/ingestion/Scrub.js.map +1 -0
- package/dist/ingestion/Zip.d.ts +19 -0
- package/dist/ingestion/Zip.d.ts.map +1 -0
- package/dist/ingestion/Zip.js +85 -0
- package/dist/ingestion/Zip.js.map +1 -0
- package/dist/ingestion/module.d.ts +111 -0
- package/dist/ingestion/module.d.ts.map +1 -0
- package/dist/ingestion/module.js +51 -0
- package/dist/ingestion/module.js.map +1 -0
- package/dist/ingress/Definition.d.ts +146 -0
- package/dist/ingress/Definition.d.ts.map +1 -0
- package/dist/ingress/Definition.js +12 -0
- package/dist/ingress/Definition.js.map +1 -0
- package/dist/ingress/Ingress.d.ts +61 -0
- package/dist/ingress/Ingress.d.ts.map +1 -0
- package/dist/ingress/Ingress.js +929 -0
- package/dist/ingress/Ingress.js.map +1 -0
- package/dist/ingress/Verifiers.d.ts +43 -0
- package/dist/ingress/Verifiers.d.ts.map +1 -0
- package/dist/ingress/Verifiers.js +137 -0
- package/dist/ingress/Verifiers.js.map +1 -0
- package/dist/machine/MachineIdentity.d.ts +34 -0
- package/dist/machine/MachineIdentity.d.ts.map +1 -0
- package/dist/machine/MachineIdentity.js +200 -0
- package/dist/machine/MachineIdentity.js.map +1 -0
- package/dist/machine/Managed.d.ts +40 -0
- package/dist/machine/Managed.d.ts.map +1 -0
- package/dist/machine/Managed.js +163 -0
- package/dist/machine/Managed.js.map +1 -0
- package/dist/machine/OAuth.d.ts +11 -0
- package/dist/machine/OAuth.d.ts.map +1 -0
- package/dist/machine/OAuth.js +913 -0
- package/dist/machine/OAuth.js.map +1 -0
- package/dist/machine/Pages.d.ts +64 -0
- package/dist/machine/Pages.d.ts.map +1 -0
- package/dist/machine/Pages.js +54 -0
- package/dist/machine/Pages.js.map +1 -0
- package/dist/machine/Tokens.d.ts +25 -0
- package/dist/machine/Tokens.d.ts.map +1 -0
- package/dist/machine/Tokens.js +62 -0
- package/dist/machine/Tokens.js.map +1 -0
- package/dist/make/Credentials.d.ts +8 -0
- package/dist/make/Credentials.d.ts.map +1 -0
- package/dist/make/Credentials.js +29 -0
- package/dist/make/Credentials.js.map +1 -0
- package/dist/make/Example.d.ts +159 -0
- package/dist/make/Example.d.ts.map +1 -0
- package/dist/make/Example.js +94 -0
- package/dist/make/Example.js.map +1 -0
- package/dist/make/Execute.d.ts +151 -0
- package/dist/make/Execute.d.ts.map +1 -0
- package/dist/make/Execute.js +316 -0
- package/dist/make/Execute.js.map +1 -0
- package/dist/make/Http.d.ts +17 -0
- package/dist/make/Http.d.ts.map +1 -0
- package/dist/make/Http.js +63 -0
- package/dist/make/Http.js.map +1 -0
- package/dist/make/Lifecycle.d.ts +167 -0
- package/dist/make/Lifecycle.d.ts.map +1 -0
- package/dist/make/Lifecycle.js +580 -0
- package/dist/make/Lifecycle.js.map +1 -0
- package/dist/make/Manifest.d.ts +61 -0
- package/dist/make/Manifest.d.ts.map +1 -0
- package/dist/make/Manifest.js +792 -0
- package/dist/make/Manifest.js.map +1 -0
- package/dist/make/Repair.d.ts +111 -0
- package/dist/make/Repair.d.ts.map +1 -0
- package/dist/make/Repair.js +236 -0
- package/dist/make/Repair.js.map +1 -0
- package/dist/make/Runtime.d.ts +144 -0
- package/dist/make/Runtime.d.ts.map +1 -0
- package/dist/make/Runtime.js +309 -0
- package/dist/make/Runtime.js.map +1 -0
- package/dist/make/Session.d.ts +19 -0
- package/dist/make/Session.d.ts.map +1 -0
- package/dist/make/Session.js +27 -0
- package/dist/make/Session.js.map +1 -0
- package/dist/make/SqlGuard.d.ts +48 -0
- package/dist/make/SqlGuard.d.ts.map +1 -0
- package/dist/make/SqlGuard.js +333 -0
- package/dist/make/SqlGuard.js.map +1 -0
- package/dist/make/Subscribe.d.ts +18 -0
- package/dist/make/Subscribe.d.ts.map +1 -0
- package/dist/make/Subscribe.js +175 -0
- package/dist/make/Subscribe.js.map +1 -0
- package/dist/make/Validate.d.ts +47 -0
- package/dist/make/Validate.d.ts.map +1 -0
- package/dist/make/Validate.js +222 -0
- package/dist/make/Validate.js.map +1 -0
- package/dist/make/ViewStep.d.ts +27 -0
- package/dist/make/ViewStep.d.ts.map +1 -0
- package/dist/make/ViewStep.js +43 -0
- package/dist/make/ViewStep.js.map +1 -0
- package/dist/make/module.d.ts +808 -0
- package/dist/make/module.d.ts.map +1 -0
- package/dist/make/module.js +232 -0
- package/dist/make/module.js.map +1 -0
- package/dist/notifications/Decide.d.ts +29 -0
- package/dist/notifications/Decide.d.ts.map +1 -0
- package/dist/notifications/Decide.js +395 -0
- package/dist/notifications/Decide.js.map +1 -0
- package/dist/notifications/Providers.d.ts +110 -0
- package/dist/notifications/Providers.d.ts.map +1 -0
- package/dist/notifications/Providers.js +404 -0
- package/dist/notifications/Providers.js.map +1 -0
- package/dist/notifications/Push.d.ts +189 -0
- package/dist/notifications/Push.d.ts.map +1 -0
- package/dist/notifications/Push.js +457 -0
- package/dist/notifications/Push.js.map +1 -0
- package/dist/notifications/Smtp.d.ts +74 -0
- package/dist/notifications/Smtp.d.ts.map +1 -0
- package/dist/notifications/Smtp.js +344 -0
- package/dist/notifications/Smtp.js.map +1 -0
- package/dist/policy/CedarSchema.d.ts +47 -0
- package/dist/policy/CedarSchema.d.ts.map +1 -0
- package/dist/policy/CedarSchema.js +115 -0
- package/dist/policy/CedarSchema.js.map +1 -0
- package/dist/policy/Compiler.d.ts +364 -0
- package/dist/policy/Compiler.d.ts.map +1 -0
- package/dist/policy/Compiler.js +1311 -0
- package/dist/policy/Compiler.js.map +1 -0
- package/dist/policy/Policy.d.ts +70 -0
- package/dist/policy/Policy.d.ts.map +1 -0
- package/dist/policy/Policy.js +114 -0
- package/dist/policy/Policy.js.map +1 -0
- package/dist/policy/Rls.d.ts +110 -0
- package/dist/policy/Rls.d.ts.map +1 -0
- package/dist/policy/Rls.js +314 -0
- package/dist/policy/Rls.js.map +1 -0
- package/dist/policy/Row.d.ts +17 -0
- package/dist/policy/Row.d.ts.map +1 -0
- package/dist/policy/Row.js +3 -0
- package/dist/policy/Row.js.map +1 -0
- package/dist/privacy/Flow.d.ts +20 -0
- package/dist/privacy/Flow.d.ts.map +1 -0
- package/dist/privacy/Flow.js +193 -0
- package/dist/privacy/Flow.js.map +1 -0
- package/dist/privacy/Inventory.d.ts +110 -0
- package/dist/privacy/Inventory.d.ts.map +1 -0
- package/dist/privacy/Inventory.js +1704 -0
- package/dist/privacy/Inventory.js.map +1 -0
- package/dist/privacy/Sources.d.ts +86 -0
- package/dist/privacy/Sources.d.ts.map +1 -0
- package/dist/privacy/Sources.js +598 -0
- package/dist/privacy/Sources.js.map +1 -0
- package/dist/privacy/Visits.d.ts +21 -0
- package/dist/privacy/Visits.d.ts.map +1 -0
- package/dist/privacy/Visits.js +279 -0
- package/dist/privacy/Visits.js.map +1 -0
- package/dist/privacy/ZeroCvr.d.ts +15 -0
- package/dist/privacy/ZeroCvr.d.ts.map +1 -0
- package/dist/privacy/ZeroCvr.js +63 -0
- package/dist/privacy/ZeroCvr.js.map +1 -0
- package/dist/privacy/module.d.ts +2505 -0
- package/dist/privacy/module.d.ts.map +1 -0
- package/dist/privacy/module.js +228 -0
- package/dist/privacy/module.js.map +1 -0
- package/dist/progress/module.d.ts +1572 -0
- package/dist/progress/module.d.ts.map +1 -0
- package/dist/progress/module.js +139 -0
- package/dist/progress/module.js.map +1 -0
- package/dist/proposals/module.d.ts +275 -0
- package/dist/proposals/module.d.ts.map +1 -0
- package/dist/proposals/module.js +269 -0
- package/dist/proposals/module.js.map +1 -0
- package/dist/query/module.d.ts +91 -0
- package/dist/query/module.d.ts.map +1 -0
- package/dist/query/module.js +50 -0
- package/dist/query/module.js.map +1 -0
- package/dist/records/Access.d.ts +26 -0
- package/dist/records/Access.d.ts.map +1 -0
- package/dist/records/Access.js +43 -0
- package/dist/records/Access.js.map +1 -0
- package/dist/records/References.d.ts +18 -0
- package/dist/records/References.d.ts.map +1 -0
- package/dist/records/References.js +47 -0
- package/dist/records/References.js.map +1 -0
- package/dist/runtime/bun.d.ts +29 -0
- package/dist/runtime/bun.d.ts.map +1 -0
- package/dist/runtime/bun.js +71 -0
- package/dist/runtime/bun.js.map +1 -0
- package/dist/runtime/idle.d.ts +5 -0
- package/dist/runtime/idle.d.ts.map +1 -0
- package/dist/runtime/idle.js +61 -0
- package/dist/runtime/idle.js.map +1 -0
- package/dist/runtime/node.d.ts +36 -0
- package/dist/runtime/node.d.ts.map +1 -0
- package/dist/runtime/node.js +86 -0
- package/dist/runtime/node.js.map +1 -0
- package/dist/runtime/resolve.d.ts +8 -0
- package/dist/runtime/resolve.d.ts.map +1 -0
- package/dist/runtime/resolve.js +136 -0
- package/dist/runtime/resolve.js.map +1 -0
- package/dist/sandbox/Sandbox.d.ts +86 -0
- package/dist/sandbox/Sandbox.d.ts.map +1 -0
- package/dist/sandbox/Sandbox.js +246 -0
- package/dist/sandbox/Sandbox.js.map +1 -0
- package/dist/sandbox/worker.d.ts +93 -0
- package/dist/sandbox/worker.d.ts.map +1 -0
- package/dist/sandbox/worker.js +503 -0
- package/dist/sandbox/worker.js.map +1 -0
- package/dist/scheduler/Automations.d.ts +99 -0
- package/dist/scheduler/Automations.d.ts.map +1 -0
- package/dist/scheduler/Automations.js +247 -0
- package/dist/scheduler/Automations.js.map +1 -0
- package/dist/scheduler/History.d.ts +61 -0
- package/dist/scheduler/History.d.ts.map +1 -0
- package/dist/scheduler/History.js +154 -0
- package/dist/scheduler/History.js.map +1 -0
- package/dist/scheduler/module.d.ts +2365 -0
- package/dist/scheduler/module.d.ts.map +1 -0
- package/dist/scheduler/module.js +370 -0
- package/dist/scheduler/module.js.map +1 -0
- package/dist/search/RecordLock.d.ts +22 -0
- package/dist/search/RecordLock.d.ts.map +1 -0
- package/dist/search/RecordLock.js +21 -0
- package/dist/search/RecordLock.js.map +1 -0
- package/dist/search/Search.d.ts +63 -0
- package/dist/search/Search.d.ts.map +1 -0
- package/dist/search/Search.js +424 -0
- package/dist/search/Search.js.map +1 -0
- package/dist/search/Sources.d.ts +56 -0
- package/dist/search/Sources.d.ts.map +1 -0
- package/dist/search/Sources.js +121 -0
- package/dist/search/Sources.js.map +1 -0
- package/dist/search/module.d.ts +72 -0
- package/dist/search/module.d.ts.map +1 -0
- package/dist/search/module.js +44 -0
- package/dist/search/module.js.map +1 -0
- package/dist/settings/module.d.ts +677 -0
- package/dist/settings/module.d.ts.map +1 -0
- package/dist/settings/module.js +103 -0
- package/dist/settings/module.js.map +1 -0
- package/dist/sharing/module.d.ts +1105 -0
- package/dist/sharing/module.d.ts.map +1 -0
- package/dist/sharing/module.js +295 -0
- package/dist/sharing/module.js.map +1 -0
- package/dist/spaces/module.d.ts +1787 -0
- package/dist/spaces/module.d.ts.map +1 -0
- package/dist/spaces/module.js +248 -0
- package/dist/spaces/module.js.map +1 -0
- package/dist/surfaces/Agent.d.ts +89 -0
- package/dist/surfaces/Agent.d.ts.map +1 -0
- package/dist/surfaces/Agent.js +112 -0
- package/dist/surfaces/Agent.js.map +1 -0
- package/dist/surfaces/CookieGuard.d.ts +77 -0
- package/dist/surfaces/CookieGuard.d.ts.map +1 -0
- package/dist/surfaces/CookieGuard.js +373 -0
- package/dist/surfaces/CookieGuard.js.map +1 -0
- package/dist/surfaces/Http.d.ts +15 -0
- package/dist/surfaces/Http.d.ts.map +1 -0
- package/dist/surfaces/Http.js +250 -0
- package/dist/surfaces/Http.js.map +1 -0
- package/dist/surfaces/Mcp.d.ts +90 -0
- package/dist/surfaces/Mcp.d.ts.map +1 -0
- package/dist/surfaces/Mcp.js +443 -0
- package/dist/surfaces/Mcp.js.map +1 -0
- package/dist/surfaces/Rpc.d.ts +15 -0
- package/dist/surfaces/Rpc.d.ts.map +1 -0
- package/dist/surfaces/Rpc.js +68 -0
- package/dist/surfaces/Rpc.js.map +1 -0
- package/dist/surfaces/headers.d.ts +9 -0
- package/dist/surfaces/headers.d.ts.map +1 -0
- package/dist/surfaces/headers.js +15 -0
- package/dist/surfaces/headers.js.map +1 -0
- package/dist/surfaces/request.d.ts +68 -0
- package/dist/surfaces/request.d.ts.map +1 -0
- package/dist/surfaces/request.js +130 -0
- package/dist/surfaces/request.js.map +1 -0
- package/dist/telemetry/module.d.ts +74 -0
- package/dist/telemetry/module.d.ts.map +1 -0
- package/dist/telemetry/module.js +77 -0
- package/dist/telemetry/module.js.map +1 -0
- package/dist/versioning/module.d.ts +231 -0
- package/dist/versioning/module.d.ts.map +1 -0
- package/dist/versioning/module.js +151 -0
- package/dist/versioning/module.js.map +1 -0
- package/package.json +71 -3
- package/src/AccountMail.ts +218 -0
- package/src/AppConfig.ts +148 -0
- package/src/Approvals.ts +555 -0
- package/src/Audit.ts +381 -0
- package/src/AuthSeam.ts +136 -0
- package/src/Authority.ts +577 -0
- package/src/Avatars.ts +172 -0
- package/src/Base64url.ts +23 -0
- package/src/BasePath.ts +80 -0
- package/src/CallActed.ts +10 -0
- package/src/Config.ts +857 -0
- package/src/DeliveryPolicy.ts +52 -0
- package/src/DesktopSignIn.ts +181 -0
- package/src/Directory.ts +1792 -0
- package/src/Flags.ts +281 -0
- package/src/Gate.ts +159 -0
- package/src/Hash.ts +14 -0
- package/src/Identity.ts +1811 -0
- package/src/IntervalJob.ts +96 -0
- package/src/Invocation.ts +2387 -0
- package/src/KernelHandlers.ts +29 -0
- package/src/KernelModule.ts +165 -0
- package/src/MemberRoutes.ts +146 -0
- package/src/Module.ts +573 -0
- package/src/ModuleIdentity.ts +134 -0
- package/src/Notifications.ts +665 -0
- package/src/Outbox.ts +761 -0
- package/src/Privacy.ts +265 -0
- package/src/Progress.ts +360 -0
- package/src/QuerySurface.ts +559 -0
- package/src/QueryViews.ts +165 -0
- package/src/Readiness.ts +284 -0
- package/src/Redact.ts +22 -0
- package/src/Registry.ts +399 -0
- package/src/Release.ts +1197 -0
- package/src/Retention.ts +167 -0
- package/src/Scheduler.ts +657 -0
- package/src/Server.ts +1838 -0
- package/src/Sessions.ts +56 -0
- package/src/Settings.ts +312 -0
- package/src/Sharing.ts +525 -0
- package/src/Sync.ts +1478 -0
- package/src/Telemetry.ts +754 -0
- package/src/Versioning.ts +588 -0
- package/src/WorkItems.ts +367 -0
- package/src/Workflows.ts +746 -0
- package/src/agent/Admission.ts +37 -0
- package/src/agent/Channels.ts +58 -0
- package/src/agent/Context.ts +430 -0
- package/src/agent/Http.ts +523 -0
- package/src/agent/Metering.ts +625 -0
- package/src/agent/ModelSetup.ts +414 -0
- package/src/agent/Models.ts +850 -0
- package/src/agent/Processors.ts +156 -0
- package/src/agent/Queue.ts +97 -0
- package/src/agent/Receipts.ts +192 -0
- package/src/agent/Resources.ts +376 -0
- package/src/agent/Run.ts +3762 -0
- package/src/agent/Runtime.ts +635 -0
- package/src/agent/Settings.ts +171 -0
- package/src/agent/Skills.ts +118 -0
- package/src/agent/Store.ts +73 -0
- package/src/agent/ToolSearch.ts +152 -0
- package/src/agent/index.ts +68 -0
- package/src/agent/migrations/agent/0000_agent.sql +162 -0
- package/src/agent/migrations/agent/0001_model_call.sql +33 -0
- package/src/agent/migrations/agent/0002_device.sql +2 -0
- package/src/agent/migrations/agent/0003_authority.sql +1 -0
- package/src/agent/migrations/agent/0004_budget_alert.sql +2 -0
- package/src/agent/migrations/agent/0005_feedback.sql +13 -0
- package/src/agent/migrations/agent/0095_run_options.sql +3 -0
- package/src/agent/migrations/agent/0096_conversation_meta.sql +7 -0
- package/src/agent/migrations/agent/0097_submission.sql +26 -0
- package/src/agent/migrations/agent/0098_threads.sql +21 -0
- package/src/agent/migrations/agent/0099_submission_refused.sql +4 -0
- package/src/agent/migrations/agent/0142_teams.sql +19 -0
- package/src/agent/module.ts +1793 -0
- package/src/appState/Sweep.ts +66 -0
- package/src/appState/migrations/0000_app_state.sql +35 -0
- package/src/appState/module.ts +418 -0
- package/src/audit/migrations/README.md +1 -0
- package/src/audit/module.ts +95 -0
- package/src/auth/AuthProvider.ts +293 -0
- package/src/auth/BetterAuthProvider.ts +476 -0
- package/src/auth/Methods.ts +7 -0
- package/src/auth/SessionTokens.ts +156 -0
- package/src/collab/Collab.ts +708 -0
- package/src/collab/Housekeeping.ts +193 -0
- package/src/collab/LiveCopy.ts +98 -0
- package/src/collab/Socket.ts +380 -0
- package/src/collab/Store.ts +105 -0
- package/src/collab/Ydoc.ts +337 -0
- package/src/collab/derive/bundle.gen.ts +2 -0
- package/src/collab/derive/entry.ts +34 -0
- package/src/collab/derive/polyfill.ts +15 -0
- package/src/collab/migrations/.gitkeep +0 -0
- package/src/collab/module.ts +237 -0
- package/src/connections/Connections.ts +2315 -0
- package/src/connections/Connector.ts +304 -0
- package/src/connections/Crypto.ts +134 -0
- package/src/connections/Destinations.ts +351 -0
- package/src/connections/Discovery.ts +251 -0
- package/src/connections/EffectKinds.ts +30 -0
- package/src/connections/Effects.ts +541 -0
- package/src/connections/Metering.ts +205 -0
- package/src/connections/ProviderApi.ts +137 -0
- package/src/connections/Secrets.ts +581 -0
- package/src/connections/Sync.ts +318 -0
- package/src/connections/migrations/.gitkeep +0 -0
- package/src/connections/module.ts +584 -0
- package/src/data/Corpus.ts +434 -0
- package/src/data/Datasets.ts +479 -0
- package/src/data/Programs.ts +285 -0
- package/src/data/migrations/README.md +1 -0
- package/src/data/module.ts +177 -0
- package/src/db/Bootstrap.ts +2832 -0
- package/src/db/Catalog.ts +10 -0
- package/src/db/Conflicts.ts +42 -0
- package/src/db/DirectoryLock.ts +19 -0
- package/src/db/HandlerGate.ts +107 -0
- package/src/db/Host.ts +250 -0
- package/src/db/KernelSchema.ts +4422 -0
- package/src/db/MigrationCheck.ts +221 -0
- package/src/db/QueryViewCheck.ts +1035 -0
- package/src/db/ReadOnly.ts +23 -0
- package/src/db/Scram.ts +20 -0
- package/src/db/SqlState.ts +77 -0
- package/src/db/Startup.ts +25 -0
- package/src/db/ZeroDdl.ts +272 -0
- package/src/db/ZeroPush.ts +128 -0
- package/src/db/schema.snapshot.json +13831 -0
- package/src/devices/Devices.ts +1219 -0
- package/src/devices/Flow.ts +198 -0
- package/src/devices/Http.ts +212 -0
- package/src/devices/migrations/0000_devices.sql +53 -0
- package/src/devices/migrations/0001_parent_run.sql +2 -0
- package/src/devices/migrations/0002_authority.sql +1 -0
- package/src/devices/migrations/0003_follow_up.sql +4 -0
- package/src/devices/migrations/0004_commands.sql +30 -0
- package/src/devices/migrations/0005_command_cancel.sql +7 -0
- package/src/devices/module.ts +313 -0
- package/src/durable/Cluster.ts +90 -0
- package/src/durable/Definition.ts +244 -0
- package/src/durable/Schedule.ts +155 -0
- package/src/durable/Trust.ts +149 -0
- package/src/enterprise/Routes.ts +501 -0
- package/src/enterprise/WorkOs.ts +133 -0
- package/src/files/FileTable.ts +84 -0
- package/src/files/Files.ts +1652 -0
- package/src/files/Http.ts +46 -0
- package/src/files/LocalStorage.ts +348 -0
- package/src/files/Providers.ts +356 -0
- package/src/files/S3Storage.ts +403 -0
- package/src/files/SigV4.ts +222 -0
- package/src/files/Sniff.ts +218 -0
- package/src/files/Storage.ts +143 -0
- package/src/files/migrations/README.md +1 -0
- package/src/files/module.ts +282 -0
- package/src/flags/migrations/0000_flags.sql +20 -0
- package/src/flags/module.ts +178 -0
- package/src/inbox/Flow.ts +548 -0
- package/src/inbox/System.ts +33 -0
- package/src/inbox/approvals.ts +335 -0
- package/src/inbox/consent.ts +331 -0
- package/src/inbox/index.ts +24 -0
- package/src/inbox/migrations/approvals/0000_approvals.sql +36 -0
- package/src/inbox/migrations/approvals/0001_provenance.sql +1 -0
- package/src/inbox/migrations/approvals/0002_withdrawn.sql +3 -0
- package/src/inbox/migrations/approvals/0003_title.sql +11 -0
- package/src/inbox/migrations/consent/0000_consent.sql +31 -0
- package/src/inbox/migrations/consent/0001_consent_revoked.sql +3 -0
- package/src/inbox/migrations/consent/0002_permission_request.sql +1 -0
- package/src/inbox/migrations/consent/0003_title.sql +11 -0
- package/src/inbox/migrations/inbox/0000_work_items.sql +31 -0
- package/src/inbox/migrations/notifications/0000_notifications.sql +66 -0
- package/src/inbox/notifications.ts +471 -0
- package/src/inbox/tables.ts +163 -0
- package/src/inbox/workItems.ts +199 -0
- package/src/index.ts +229 -0
- package/src/ingestion/Chunk.ts +49 -0
- package/src/ingestion/Extract.ts +387 -0
- package/src/ingestion/ExtractChild.ts +67 -0
- package/src/ingestion/ExtractPool.ts +270 -0
- package/src/ingestion/Ingestion.ts +929 -0
- package/src/ingestion/Isolated.ts +26 -0
- package/src/ingestion/Markup.ts +117 -0
- package/src/ingestion/Pdf.ts +167 -0
- package/src/ingestion/Runs.ts +192 -0
- package/src/ingestion/Scrub.ts +22 -0
- package/src/ingestion/Zip.ts +87 -0
- package/src/ingestion/migrations/README.md +1 -0
- package/src/ingestion/module.ts +65 -0
- package/src/ingress/Definition.ts +158 -0
- package/src/ingress/Ingress.ts +1220 -0
- package/src/ingress/Verifiers.ts +166 -0
- package/src/machine/MachineIdentity.ts +310 -0
- package/src/machine/Managed.ts +228 -0
- package/src/machine/OAuth.ts +1140 -0
- package/src/machine/Pages.ts +139 -0
- package/src/machine/Tokens.ts +75 -0
- package/src/make/Credentials.ts +36 -0
- package/src/make/Example.ts +104 -0
- package/src/make/Execute.ts +534 -0
- package/src/make/Http.ts +71 -0
- package/src/make/Lifecycle.ts +911 -0
- package/src/make/Manifest.ts +884 -0
- package/src/make/Repair.ts +262 -0
- package/src/make/Runtime.ts +494 -0
- package/src/make/Session.ts +33 -0
- package/src/make/SqlGuard.ts +362 -0
- package/src/make/Subscribe.ts +282 -0
- package/src/make/Validate.ts +247 -0
- package/src/make/ViewStep.ts +64 -0
- package/src/make/migrations/README.md +1 -0
- package/src/make/module.ts +261 -0
- package/src/notifications/Decide.ts +483 -0
- package/src/notifications/Providers.ts +532 -0
- package/src/notifications/Push.ts +594 -0
- package/src/notifications/Smtp.ts +379 -0
- package/src/policy/CedarSchema.ts +156 -0
- package/src/policy/Compiler.ts +1627 -0
- package/src/policy/Policy.ts +178 -0
- package/src/policy/Rls.ts +460 -0
- package/src/policy/Row.ts +15 -0
- package/src/privacy/Flow.ts +283 -0
- package/src/privacy/Inventory.ts +2414 -0
- package/src/privacy/Sources.ts +831 -0
- package/src/privacy/Visits.ts +339 -0
- package/src/privacy/ZeroCvr.ts +66 -0
- package/src/privacy/migrations/0000_privacy.sql +48 -0
- package/src/privacy/module.ts +280 -0
- package/src/progress/migrations/0000_progress.sql +27 -0
- package/src/progress/migrations/0001_notify.sql +1 -0
- package/src/progress/module.ts +161 -0
- package/src/proposals/migrations/README.md +1 -0
- package/src/proposals/module.ts +338 -0
- package/src/query/migrations/README.md +1 -0
- package/src/query/module.ts +66 -0
- package/src/records/Access.ts +97 -0
- package/src/records/References.ts +65 -0
- package/src/runtime/bun.ts +131 -0
- package/src/runtime/idle.ts +88 -0
- package/src/runtime/node.ts +140 -0
- package/src/runtime/resolve.ts +141 -0
- package/src/sandbox/Sandbox.ts +330 -0
- package/src/sandbox/worker.ts +577 -0
- package/src/scheduler/Automations.ts +319 -0
- package/src/scheduler/History.ts +231 -0
- package/src/scheduler/migrations/0000_schedules.sql +11 -0
- package/src/scheduler/migrations/0001_resumed_at.sql +1 -0
- package/src/scheduler/migrations/0002_origin.sql +3 -0
- package/src/scheduler/migrations/0003_authority.sql +1 -0
- package/src/scheduler/migrations/0004_operate.sql +18 -0
- package/src/scheduler/module.ts +445 -0
- package/src/search/RecordLock.ts +25 -0
- package/src/search/Search.ts +563 -0
- package/src/search/Sources.ts +157 -0
- package/src/search/migrations/README.md +1 -0
- package/src/search/module.ts +49 -0
- package/src/settings/migrations/0000_settings.sql +15 -0
- package/src/settings/module.ts +126 -0
- package/src/sharing/migrations/0000_access_requests.sql +17 -0
- package/src/sharing/module.ts +351 -0
- package/src/spaces/migrations/0000_spaces.sql +35 -0
- package/src/spaces/module.ts +287 -0
- package/src/surfaces/Agent.ts +224 -0
- package/src/surfaces/CookieGuard.ts +433 -0
- package/src/surfaces/Http.ts +341 -0
- package/src/surfaces/Mcp.ts +585 -0
- package/src/surfaces/Rpc.ts +101 -0
- package/src/surfaces/headers.ts +16 -0
- package/src/surfaces/request.ts +173 -0
- package/src/telemetry/migrations/.gitkeep +0 -0
- package/src/telemetry/module.ts +94 -0
- package/src/versioning/migrations/.gitkeep +0 -0
- package/src/versioning/module.ts +194 -0
|
@@ -0,0 +1,1680 @@
|
|
|
1
|
+
import { declaredEntityNames, RECEIPT_VERSION, ActionFailed, isNoOp, exposedOn, ApprovalRequired, ConsentRequired, CLIENT_VERSION_HEADER, ClientOutdated, Forbidden, ProviderForbidden, IdempotencyConflict, InvalidInput, isRecordKeyNonce, newRecordKeyNonce, recordKey, Unauthenticated, UnknownAction, TrackEvent as TrackEventSchema, ACTION_INVOKED_EVENT, AUDIT_CHANGED_IDS, } from "@eloxiv/contracts";
|
|
2
|
+
import { Cause, Context, Effect, Exit, Layer, Metric, Option, Schema } from "effect";
|
|
3
|
+
import { executeMake } from "./make/Execute.js";
|
|
4
|
+
import { MakeRuntime, VERSION_BUSY } from "./make/Runtime.js";
|
|
5
|
+
import { SqlClient, SqlError } from "effect/sql";
|
|
6
|
+
import { CLIENT_ADDRESS_HEADER } from "./surfaces/headers.js";
|
|
7
|
+
import { Approvals, isAgentOrigin } from "./Approvals.js";
|
|
8
|
+
import { Authority, bindDeferred, credentialLinks, deferrable, extend, recordOf } from "./Authority.js";
|
|
9
|
+
import { Audit } from "./Audit.js";
|
|
10
|
+
import { canonicalJson, sha256 } from "./Hash.js";
|
|
11
|
+
import { CallerAuthority, CallerCredential, Identity, SYSTEM_ACTOR, } from "./Identity.js";
|
|
12
|
+
import { scopeAllows } from "./machine/Tokens.js";
|
|
13
|
+
import { asModuleCode, isKernelProvided } from "./KernelModule.js";
|
|
14
|
+
import { MAX_EFFECT_DELAY_DAYS, } from "./Module.js";
|
|
15
|
+
import { Connections } from "./connections/Connections.js";
|
|
16
|
+
import { EFFECT_SCHEDULED, isExternal, operationOf, readsOnly } from "./connections/EffectKinds.js";
|
|
17
|
+
import { CallActed } from "./CallActed.js";
|
|
18
|
+
/**
|
|
19
|
+
* Test hooks of the invocation path (fault injection): `afterCommit` runs once a call's transaction has committed
|
|
20
|
+
* and before it is answered; a failure there is a call whose commit took effect but whose answer was lost, so it is
|
|
21
|
+
* answered `ActionFailed` with `effect: "unknown"`, as a failure while committing is.
|
|
22
|
+
*/
|
|
23
|
+
export const InvocationHooks = Context.Reference("@eloxiv/kernel/InvocationHooks", { defaultValue: () => ({ afterCommit: () => Effect.void }) });
|
|
24
|
+
import { CONNECTIONS_MODULE as CONNECTIONS_MODULE_NAME } from "./connections/module.js";
|
|
25
|
+
import { Notifications } from "./Notifications.js";
|
|
26
|
+
import { toSql } from "./policy/Compiler.js";
|
|
27
|
+
import { Outbox } from "./Outbox.js";
|
|
28
|
+
import { Policy } from "./policy/Policy.js";
|
|
29
|
+
import { scopedToDeclaration } from "./policy/Rls.js";
|
|
30
|
+
import { readOnly } from "./db/ReadOnly.js";
|
|
31
|
+
import { isLockConflictError, retryingConflicts } from "./db/Conflicts.js";
|
|
32
|
+
import { CONSTRAINT_CONFLICT_MESSAGE, CONSTRAINT_CONFLICTS, sqlStateOf } from "./db/SqlState.js";
|
|
33
|
+
import { readOwnView } from "./QueryViews.js";
|
|
34
|
+
import { readReference } from "./records/References.js";
|
|
35
|
+
import { handlerGate } from "./db/HandlerGate.js";
|
|
36
|
+
import { Registry } from "./Registry.js";
|
|
37
|
+
import { WorkItems } from "./WorkItems.js";
|
|
38
|
+
import { Sharing } from "./Sharing.js";
|
|
39
|
+
import { sharingModule } from "./sharing/module.js";
|
|
40
|
+
import { compareVersions, ReleaseSettings } from "./Release.js";
|
|
41
|
+
import { Flags } from "./Flags.js";
|
|
42
|
+
import { KernelActionHandlers } from "./KernelHandlers.js";
|
|
43
|
+
import { Files } from "./files/Files.js";
|
|
44
|
+
import { Ingestion } from "./ingestion/Ingestion.js";
|
|
45
|
+
import { Settings } from "./Settings.js";
|
|
46
|
+
import { Progress } from "./Progress.js";
|
|
47
|
+
import { Analytics, ErrorCapture, invocationMetrics } from "./Telemetry.js";
|
|
48
|
+
import { Versioning } from "./Versioning.js";
|
|
49
|
+
export class ActionPrechecks extends Context.Service()("@eloxiv/kernel/ActionPrechecks") {
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The format of stored receipts. A receipt stored under any other format is not replayed (the retry is an
|
|
53
|
+
* IdempotencyConflict), so changing what a receipt holds invalidates old ones without a migration.
|
|
54
|
+
*/
|
|
55
|
+
const RECEIPT_FORMAT = 2;
|
|
56
|
+
/** The API transports: what a person's client calls on, and what an agent session's bearer may also be shown to. */
|
|
57
|
+
const API_SURFACES = new Set(["rpc", "http", "cli", "sync"]);
|
|
58
|
+
/** Every string or number value in an encoded output (not object keys), as strings. */
|
|
59
|
+
const valuesIn = (value, into = new Set()) => {
|
|
60
|
+
if (typeof value === "string" || typeof value === "number")
|
|
61
|
+
into.add(String(value));
|
|
62
|
+
else if (Array.isArray(value))
|
|
63
|
+
for (const item of value)
|
|
64
|
+
valuesIn(item, into);
|
|
65
|
+
else if (typeof value === "object" && value !== null)
|
|
66
|
+
for (const item of Object.values(value))
|
|
67
|
+
valuesIn(item, into);
|
|
68
|
+
return into;
|
|
69
|
+
};
|
|
70
|
+
const quoteIdent = (name) => `"${name.replaceAll('"', '""')}"`;
|
|
71
|
+
const tableOf = (entity) => `${quoteIdent(entity.table.schema)}.${quoteIdent(entity.table.name)}`;
|
|
72
|
+
const pkColumn = (entity) => entity.columns[entity.primaryKey];
|
|
73
|
+
/**
|
|
74
|
+
* The input an action's handler receives. For an action predicting an insert (`optimistic.insert`), the input
|
|
75
|
+
* field naming the record's key holds the record's primary key instead: `recordKey` of the key the caller named
|
|
76
|
+
* (or of a fresh one), for the acting user and organisation and the entity written. A key that is not one is
|
|
77
|
+
* refused.
|
|
78
|
+
*/
|
|
79
|
+
const withRecordKey = (registered, input, actor) => {
|
|
80
|
+
const effect = registered.contract.optimistic;
|
|
81
|
+
if (effect?.kind !== "insert" || registered.writes === undefined)
|
|
82
|
+
return { ok: true, input };
|
|
83
|
+
const fields = input;
|
|
84
|
+
const named = fields[effect.key];
|
|
85
|
+
if (named !== undefined && !isRecordKeyNonce(named)) {
|
|
86
|
+
return { ok: false, message: `${effect.key} must be 1 to 128 letters, digits, _ or -` };
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
ok: true,
|
|
90
|
+
input: { ...fields, [effect.key]: recordKey(actor, registered.writes.cedarType, named ?? newRecordKeyNonce()) },
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
const hashOf = (value) => Effect.promise(() => {
|
|
94
|
+
try {
|
|
95
|
+
return sha256(canonicalJson(value));
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
return Promise.resolve("unhashable");
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
export class Invocation extends Context.Service()("@eloxiv/kernel/Invocation") {
|
|
102
|
+
static layer = Layer.effect(Invocation, Effect.gen(function* () {
|
|
103
|
+
const sql = yield* SqlClient.SqlClient;
|
|
104
|
+
const registry = yield* Registry;
|
|
105
|
+
const invocationHooks = yield* InvocationHooks;
|
|
106
|
+
const consentInstalled = registry.modules.some((module) => module.contract.name === "consent");
|
|
107
|
+
const identity = yield* Identity;
|
|
108
|
+
const authority = yield* Authority;
|
|
109
|
+
const policy = yield* Policy;
|
|
110
|
+
const approvals = yield* Approvals;
|
|
111
|
+
const audit = yield* Audit;
|
|
112
|
+
const outbox = yield* Outbox;
|
|
113
|
+
const workItems = yield* WorkItems;
|
|
114
|
+
// What the kernel's own modules' handlers may use: every service built before the invocation path.
|
|
115
|
+
const kernelContext = yield* Effect.context();
|
|
116
|
+
const notifications = yield* Notifications;
|
|
117
|
+
const sharing = yield* Sharing;
|
|
118
|
+
const release = yield* Effect.serviceOption(ReleaseSettings);
|
|
119
|
+
const minClientVersion = Option.isSome(release) ? release.value.minClientVersion : undefined;
|
|
120
|
+
const kernelHandlers = yield* Effect.serviceOption(KernelActionHandlers);
|
|
121
|
+
const settingsService = yield* Effect.serviceOption(Settings);
|
|
122
|
+
const filesService = yield* Effect.serviceOption(Files);
|
|
123
|
+
const ingestionService = yield* Effect.serviceOption(Ingestion);
|
|
124
|
+
const flagsService = yield* Effect.serviceOption(Flags);
|
|
125
|
+
const connectionsService = yield* Effect.serviceOption(Connections);
|
|
126
|
+
const progressService = yield* Effect.serviceOption(Progress);
|
|
127
|
+
const versioning = yield* Effect.serviceOption(Versioning);
|
|
128
|
+
const analytics = yield* Effect.serviceOption(Analytics);
|
|
129
|
+
const analyticsOn = Option.isSome(analytics) && analytics.value.enabled;
|
|
130
|
+
const errors = yield* Effect.serviceOption(ErrorCapture);
|
|
131
|
+
const capture = (invocationId) => Option.isSome(errors) ? errors.value.capture("Defect", invocationId) : Effect.void;
|
|
132
|
+
// MAKE modules (when the app installs the kernel's make module): looked up by name, run in the sandbox.
|
|
133
|
+
const makeRuntime = yield* Effect.serviceOption(MakeRuntime);
|
|
134
|
+
const prechecks = yield* Effect.serviceOption(ActionPrechecks);
|
|
135
|
+
const missing = (what) => Effect.die(new Error(`The kernel's ${what} service is not provided`));
|
|
136
|
+
/**
|
|
137
|
+
* A handler's Connections (`ctx.connections`): the kernel's own operations, run with the kernel's context and
|
|
138
|
+
* never the handler's, so their statements use a connection of their own (not the call's transaction, where
|
|
139
|
+
* the module's role could not read a Connection) and a provider request holds no transaction open. Connector
|
|
140
|
+
* code inside them still runs as module code (`Connections.capability`). Only the caller's own Connections.
|
|
141
|
+
*/
|
|
142
|
+
const outside = (effect) => Effect.updateContext(effect, () => kernelContext);
|
|
143
|
+
/**
|
|
144
|
+
* The effects a call scheduled: recorded (with the event that starts their delivery) with the kernel's own
|
|
145
|
+
* writes, after the handler's are checked, in the call's transaction.
|
|
146
|
+
*/
|
|
147
|
+
const effectBuffer = (actor, registered, invocationId, idempotencyKey, asserted) => {
|
|
148
|
+
const pending = [];
|
|
149
|
+
/** Effects of the caller's to cancel, with the call's writes: in its transaction, so both commit or neither. */
|
|
150
|
+
const cancels = [];
|
|
151
|
+
/**
|
|
152
|
+
* What a scheduled effect is delivered (and its module told) under: the call's authority, bound to the work it
|
|
153
|
+
* queues, which runs once; the delivery asserts it again, with the Connection it goes through as a link.
|
|
154
|
+
*/
|
|
155
|
+
const authorityOf = () => bindDeferred(recordOf(asserted), "once");
|
|
156
|
+
/** The places taken in the call: each effect's name, or its number in the order it was scheduled. */
|
|
157
|
+
const places = new Set();
|
|
158
|
+
let unnamed = 0;
|
|
159
|
+
/**
|
|
160
|
+
* An effect's place in the call, taken synchronously before anything else runs (so effects scheduled
|
|
161
|
+
* concurrently never take the same one): its name, or the next number. A name given twice is refused.
|
|
162
|
+
*/
|
|
163
|
+
const claim = (name) => {
|
|
164
|
+
const place = name === undefined ? `#${unnamed++}` : `name:${name}`;
|
|
165
|
+
if (places.has(place))
|
|
166
|
+
return undefined;
|
|
167
|
+
places.add(place);
|
|
168
|
+
return place;
|
|
169
|
+
};
|
|
170
|
+
/**
|
|
171
|
+
* An effect's id: with an idempotency key, derived from it and the effect's place, so the call and its
|
|
172
|
+
* replays name the same effects (the receipt lists them) and no two effects of a call share one; without
|
|
173
|
+
* one, random.
|
|
174
|
+
*/
|
|
175
|
+
const idOf = (place) => idempotencyKey === undefined
|
|
176
|
+
? Effect.succeed(`eff_${crypto.randomUUID()}`)
|
|
177
|
+
: Effect.promise(() => sha256(canonicalJson([actor.orgId, actor.userId, registered.contract.name, idempotencyKey, place]))).pipe(Effect.map((hash) => `eff_${hash.slice(0, 40)}`));
|
|
178
|
+
const apply = Effect.forEach(pending, ({ id, effect }) => Effect.gen(function* () {
|
|
179
|
+
// One to run later waits like a rate-limited one (the claim refuses it before `not_before`), and says
|
|
180
|
+
// why while it waits (`waiting.reason`).
|
|
181
|
+
const later = effect.notBefore ?? null;
|
|
182
|
+
yield* sql `INSERT INTO eloxiv.connection_effect (id, org_id, owner_id, module, action, invocation_id,
|
|
183
|
+
connection_id, capability, operation, input, on_done, authority, not_before, error)
|
|
184
|
+
VALUES (${id}, ${actor.orgId}, ${actor.userId}, ${registered.module.contract.name},
|
|
185
|
+
${registered.contract.name}, ${invocationId}, ${effect.connectionId}, ${effect.capability},
|
|
186
|
+
${effect.operation}, ${JSON.stringify(effect.input ?? null)}::jsonb, ${effect.onDone ?? null},
|
|
187
|
+
${JSON.stringify(authorityOf())}::jsonb, ${later}::timestamptz,
|
|
188
|
+
${later === null ? null : "Scheduled"})`;
|
|
189
|
+
yield* outbox.publish({
|
|
190
|
+
invocationId,
|
|
191
|
+
type: EFFECT_SCHEDULED,
|
|
192
|
+
module: CONNECTIONS_MODULE_NAME,
|
|
193
|
+
orgId: actor.orgId,
|
|
194
|
+
payload: { effectId: id },
|
|
195
|
+
});
|
|
196
|
+
}), { discard: true }).pipe(Effect.orDie,
|
|
197
|
+
// The cancellations, last: the delivery's claim takes only a pending row under its lock, so each effect is
|
|
198
|
+
// either cancelled with this call or already running, and then the call fails and nothing of it commits.
|
|
199
|
+
Effect.andThen(Effect.forEach(cancels, (effectId) => sql `
|
|
200
|
+
UPDATE eloxiv.connection_effect SET state = 'failed', error = 'Cancelled', input = NULL, result = NULL,
|
|
201
|
+
not_before = NULL, updated_at = now(), finished_at = now()
|
|
202
|
+
WHERE id = ${effectId} AND org_id = ${actor.orgId} AND owner_id = ${actor.userId} AND state = 'pending'
|
|
203
|
+
RETURNING id`.pipe(Effect.orDie, Effect.flatMap((rows) => rows.length > 0
|
|
204
|
+
? Effect.void
|
|
205
|
+
: Effect.fail(new InvalidInput({
|
|
206
|
+
message: `Effect ${effectId} started before the call could cancel it: nothing was changed`,
|
|
207
|
+
})))), { discard: true })));
|
|
208
|
+
return { pending, apply, claim, idOf, cancels };
|
|
209
|
+
};
|
|
210
|
+
const connectionsApi = (actor, registered, buffer, asserted,
|
|
211
|
+
/** Told before a direct operation that changes the account's data runs: a rollback does not undo it. */
|
|
212
|
+
acting) => {
|
|
213
|
+
/** On the caller's behalf: only under the call's own capability (its transaction, its person). */
|
|
214
|
+
const held = authority.bound(asserted, actor);
|
|
215
|
+
const action = registered.contract.name;
|
|
216
|
+
const declared = registered.contract.connections ?? {};
|
|
217
|
+
const allowed = (capability, operation) => declared[capability]?.includes(operation) === true;
|
|
218
|
+
if (Option.isNone(connectionsService)) {
|
|
219
|
+
return {
|
|
220
|
+
list: () => missing("Connections"),
|
|
221
|
+
capability: () => missing("Connections"),
|
|
222
|
+
schedule: () => missing("Connections"),
|
|
223
|
+
effect: () => missing("Connections"),
|
|
224
|
+
cancel: () => missing("Connections"),
|
|
225
|
+
effects: () => missing("Connections"),
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
const service = connectionsService.value;
|
|
229
|
+
// The module's handler uses it: a shared Connection must be granted to this module too.
|
|
230
|
+
const by = { userId: actor.userId, orgId: actor.orgId, module: registered.module.contract.name };
|
|
231
|
+
const refused = (connectionId, message) => Effect.fail(new ProviderForbidden({ message, connectionId, missingScopes: [], consent: null }));
|
|
232
|
+
return {
|
|
233
|
+
list: () => held.pipe(Effect.andThen(outside(service.usableBy(actor, registered.module.contract.name)))),
|
|
234
|
+
capability: (connectionId, name) => held
|
|
235
|
+
.pipe(Effect.andThen(outside(service.capability(connectionId, name, by))))
|
|
236
|
+
.pipe(Effect.map((bound) => Object.fromEntries(Object.entries(bound.operations).map(([operation, run]) => [
|
|
237
|
+
operation,
|
|
238
|
+
(input) => !allowed(name, operation)
|
|
239
|
+
? refused(connectionId, `${action} does not declare ${name}.${operation} (connections)`)
|
|
240
|
+
: isExternal(name, operation)
|
|
241
|
+
? refused(connectionId, `${name}.${operation} has effects others see: ${action} schedules it (ctx.connections.schedule)`)
|
|
242
|
+
: readsOnly(name, operation)
|
|
243
|
+
? outside(run(input))
|
|
244
|
+
: Effect.sync(acting).pipe(Effect.andThen(outside(run(input)))),
|
|
245
|
+
])))),
|
|
246
|
+
schedule: (effect) => Effect.gen(function* () {
|
|
247
|
+
yield* held;
|
|
248
|
+
// The effect's place first, before anything that waits.
|
|
249
|
+
if (effect.name !== undefined && !/^[A-Za-z0-9._:-]{1,100}$/u.test(effect.name)) {
|
|
250
|
+
return yield* new InvalidInput({ message: `An effect's name is letters, digits, ., _, : and -` });
|
|
251
|
+
}
|
|
252
|
+
const place = buffer.claim(effect.name);
|
|
253
|
+
if (place === undefined) {
|
|
254
|
+
return yield* new InvalidInput({ message: `${action} names two effects ${effect.name}` });
|
|
255
|
+
}
|
|
256
|
+
if (!allowed(effect.capability, effect.operation)) {
|
|
257
|
+
return yield* new Forbidden({
|
|
258
|
+
action,
|
|
259
|
+
message: `${action} does not declare ${effect.capability}.${effect.operation} (connections)`,
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
const operation = operationOf(effect.capability, effect.operation);
|
|
263
|
+
const input = yield* Schema.decodeUnknownEffect(operation.input)(effect.input).pipe(Effect.mapError((e) => new InvalidInput({ message: `${effect.capability}.${effect.operation}: ${String(e)}` })));
|
|
264
|
+
if (effect.notBefore !== undefined) {
|
|
265
|
+
const when = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2}(\.\d{1,9})?)?(Z|[+-]\d{2}:\d{2})$/u.test(effect.notBefore)
|
|
266
|
+
? Date.parse(effect.notBefore)
|
|
267
|
+
: Number.NaN;
|
|
268
|
+
if (Number.isNaN(when)) {
|
|
269
|
+
return yield* new InvalidInput({ message: "notBefore must be an ISO instant with its offset" });
|
|
270
|
+
}
|
|
271
|
+
if (when > Date.now() + MAX_EFFECT_DELAY_DAYS * 86_400_000) {
|
|
272
|
+
return yield* new InvalidInput({
|
|
273
|
+
message: `An effect can be scheduled at most ${MAX_EFFECT_DELAY_DAYS} days ahead`,
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
if (effect.onDone !== undefined) {
|
|
278
|
+
const done = registry.actions.get(effect.onDone);
|
|
279
|
+
if (done === undefined || done.module !== registered.module) {
|
|
280
|
+
return yield* Effect.die(new Error(`${effect.onDone} is not an action of ${registered.module.contract.name}`));
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
// A Connection the caller may use from this module: refused now rather than failing after commit.
|
|
284
|
+
const usableNow = yield* outside(service.usableBy(actor, registered.module.contract.name));
|
|
285
|
+
if (!usableNow.some((c) => c.id === effect.connectionId)) {
|
|
286
|
+
return yield* new Forbidden({ action, message: "The Connection is not one you may use here" });
|
|
287
|
+
}
|
|
288
|
+
const id = yield* buffer.idOf(place);
|
|
289
|
+
if (buffer.pending.some((p) => p.id === id))
|
|
290
|
+
return yield* Effect.die(new Error(`Effect ${id} twice`));
|
|
291
|
+
buffer.pending.push({ id, effect: { ...effect, input } });
|
|
292
|
+
return { effectId: id };
|
|
293
|
+
}),
|
|
294
|
+
effect: (effectId) => held.pipe(Effect.andThen(outside(sql `
|
|
295
|
+
SELECT id, state, result, reconciled, told_at IS NOT NULL AS told, result_cleared AS cleared,
|
|
296
|
+
CASE WHEN state IN ('pending', 'running') THEN NULL ELSE error END AS error,
|
|
297
|
+
CASE WHEN state = 'pending' AND not_before IS NOT NULL
|
|
298
|
+
THEN json_build_object('reason', coalesce(error, 'RateLimited'), 'retryAt',
|
|
299
|
+
to_char(not_before AT TIME ZONE 'UTC', 'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"'))
|
|
300
|
+
END AS waiting
|
|
301
|
+
FROM eloxiv.connection_effect
|
|
302
|
+
WHERE id = ${effectId} AND org_id = ${actor.orgId} AND owner_id = ${actor.userId}`.pipe(Effect.orDie))), Effect.map(([row]) => row)),
|
|
303
|
+
// Committed at once on the kernel's own connection: the claim (`Effects.ts`) takes only a `pending` row
|
|
304
|
+
// under its lock, so an effect is either cancelled here or run there, never both.
|
|
305
|
+
effects: (filter) => held.pipe(Effect.andThen(outside(sql `
|
|
306
|
+
SELECT id, module, action, capability, operation, state, attempts,
|
|
307
|
+
CASE WHEN state = 'pending' AND not_before IS NOT NULL
|
|
308
|
+
THEN json_build_object('reason', coalesce(error, 'RateLimited'), 'retryAt',
|
|
309
|
+
to_char(not_before AT TIME ZONE 'UTC', 'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"'))
|
|
310
|
+
END AS waiting,
|
|
311
|
+
CASE WHEN state IN ('pending', 'running') THEN NULL ELSE error END AS error, reported,
|
|
312
|
+
to_char(created_at AT TIME ZONE 'UTC', 'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"') AS "createdAt",
|
|
313
|
+
to_char(finished_at AT TIME ZONE 'UTC', 'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"') AS "finishedAt"
|
|
314
|
+
FROM eloxiv.connection_effect
|
|
315
|
+
WHERE org_id = ${actor.orgId} AND owner_id = ${actor.userId}
|
|
316
|
+
AND (${filter?.ids === undefined} OR id = ANY(${[...(filter?.ids ?? [])]}::text[]))
|
|
317
|
+
ORDER BY created_at DESC, id LIMIT 100`.pipe(Effect.orDie)))),
|
|
318
|
+
// Whether it can be cancelled now (the caller's, pending); the cancellation itself is written with the call's
|
|
319
|
+
// own writes, in its transaction (`effectBuffer`), so a call that fails or rolls back cancels nothing.
|
|
320
|
+
cancel: (effectId) => held.pipe(Effect.andThen(outside(sql `
|
|
321
|
+
SELECT id FROM eloxiv.connection_effect
|
|
322
|
+
WHERE id = ${effectId} AND org_id = ${actor.orgId} AND owner_id = ${actor.userId} AND state = 'pending'`.pipe(Effect.orDie))), Effect.map((rows) => {
|
|
323
|
+
if (rows.length === 0)
|
|
324
|
+
return false;
|
|
325
|
+
if (!buffer.cancels.includes(effectId))
|
|
326
|
+
buffer.cancels.push(effectId);
|
|
327
|
+
return true;
|
|
328
|
+
})),
|
|
329
|
+
};
|
|
330
|
+
};
|
|
331
|
+
/**
|
|
332
|
+
* Version skew (the Release contract): a write from a client that declares a version older than the
|
|
333
|
+
* minimum (or one that is not a version) is refused before anything else runs. Clients that declare no
|
|
334
|
+
* version, internal callers and read-only actions are not gated.
|
|
335
|
+
*/
|
|
336
|
+
const checkClientVersion = (action, request) => {
|
|
337
|
+
if (minClientVersion === undefined || request.headers === undefined)
|
|
338
|
+
return Effect.void;
|
|
339
|
+
const declared = request.headers.get(CLIENT_VERSION_HEADER);
|
|
340
|
+
if (declared === null)
|
|
341
|
+
return Effect.void;
|
|
342
|
+
const order = compareVersions(declared, minClientVersion);
|
|
343
|
+
if (order !== undefined && order >= 0)
|
|
344
|
+
return Effect.void;
|
|
345
|
+
return Effect.fail(new ClientOutdated({
|
|
346
|
+
action,
|
|
347
|
+
clientVersion: declared,
|
|
348
|
+
minClientVersion,
|
|
349
|
+
message: `This client (version ${declared}) is older than the oldest version this server accepts writes from ` +
|
|
350
|
+
`(${minClientVersion}). Reload or upgrade the app, then try again; reading still works.`,
|
|
351
|
+
}));
|
|
352
|
+
};
|
|
353
|
+
const entitiesByTable = new Map();
|
|
354
|
+
for (const { entity } of registry.entities.values())
|
|
355
|
+
entitiesByTable.set(`${entity.table.schema}.${entity.table.name}`, entity);
|
|
356
|
+
/**
|
|
357
|
+
* The call's lineage for its audit record, from what the kernel decided: never a header but the client version
|
|
358
|
+
* (bounded), never the person's sign-in session (`deferrable` drops it) and never a person's id.
|
|
359
|
+
*/
|
|
360
|
+
const lineageOf = (request, origin, credential, chain, basis) => ({
|
|
361
|
+
origin,
|
|
362
|
+
credential: request.identity !== undefined ? "identity" : credential.kind,
|
|
363
|
+
// The person's membership is the record's own actor and organisation: not repeated (with their id) here.
|
|
364
|
+
authority: deferrable(chain)
|
|
365
|
+
.filter((link) => link.kind !== "membership")
|
|
366
|
+
.map((link) => ({ kind: link.kind, id: link.id })),
|
|
367
|
+
agentRun: request.identity !== undefined ? (request.agentRun ?? null) : null,
|
|
368
|
+
approval: request.identity !== undefined ? (request.approval ?? null) : null,
|
|
369
|
+
consent: basis === undefined || (basis.request === undefined && basis.permission === undefined)
|
|
370
|
+
? null
|
|
371
|
+
: { request: basis.request ?? null, permission: basis.permission ?? null },
|
|
372
|
+
clientVersion: request.headers?.get(CLIENT_VERSION_HEADER)?.slice(0, 64) ?? null,
|
|
373
|
+
});
|
|
374
|
+
/**
|
|
375
|
+
* What an untargeted writing call wrote (backlog 2): the records of its declared entities it inserted, and those it
|
|
376
|
+
* updated that it did not insert. Only rows it wrote: one row-level security kept it from is not in the log.
|
|
377
|
+
*/
|
|
378
|
+
const writtenOf = (actor, registered, log) => Effect.gen(function* () {
|
|
379
|
+
const contract = registered.contract;
|
|
380
|
+
if (contract.writes === undefined || contract.target !== undefined)
|
|
381
|
+
return undefined;
|
|
382
|
+
const declared = new Set(declaredEntityNames(contract).map((name) => registered.module.contract.entities[name]));
|
|
383
|
+
const byEntity = new Map();
|
|
384
|
+
for (const write of log) {
|
|
385
|
+
const entity = entitiesByTable.get(`${write.schema}.${write.table}`);
|
|
386
|
+
if (entity === undefined || !declared.has(entity) || write.pk === null)
|
|
387
|
+
continue;
|
|
388
|
+
const entry = byEntity.get(entity) ?? { inserted: new Set(), updated: new Set() };
|
|
389
|
+
if (write.op === "INSERT")
|
|
390
|
+
entry.inserted.add(write.pk);
|
|
391
|
+
else if (write.op === "UPDATE")
|
|
392
|
+
entry.updated.add(write.pk);
|
|
393
|
+
byEntity.set(entity, entry);
|
|
394
|
+
}
|
|
395
|
+
// Only rows the caller may read: an action may write wider than its caller reads (row-level security lets a
|
|
396
|
+
// statement through on the action's permission or the read permission), and a count of the rest would
|
|
397
|
+
// say how many records there are that they cannot see. A read policy that cannot be compiled counts none.
|
|
398
|
+
let inserted = 0;
|
|
399
|
+
let updated = 0;
|
|
400
|
+
for (const [entity, entry] of byEntity) {
|
|
401
|
+
for (const pk of entry.inserted)
|
|
402
|
+
entry.updated.delete(pk);
|
|
403
|
+
const readAction = { type: registered.cedarAction.type, id: "read" };
|
|
404
|
+
const read = yield* (registered.module.make !== undefined && Option.isSome(makeRuntime)
|
|
405
|
+
? makeRuntime.value.filterFor(registered.module, actor, readAction, entity, "old")
|
|
406
|
+
: policy.filterFor(actor, readAction, entity, "old")).pipe(Effect.orElseSucceed(() => ({ kind: "false" })));
|
|
407
|
+
inserted += (yield* satisfying(registered, entity, read, [...entry.inserted], false).pipe(Effect.orDie))
|
|
408
|
+
.size;
|
|
409
|
+
updated += (yield* satisfying(registered, entity, read, [...entry.updated], false).pipe(Effect.orDie)).size;
|
|
410
|
+
}
|
|
411
|
+
return { inserted, updated };
|
|
412
|
+
});
|
|
413
|
+
/** Where a call came from, for its receipt: ids only (Receipt.ts `ReceiptProvenance`). */
|
|
414
|
+
const provenanceFor = (request, invocationId, key, origin) => {
|
|
415
|
+
const runId = request.identity !== undefined ? (request.agentRun?.runId ?? null) : null;
|
|
416
|
+
const causationId = request.identity !== undefined ? (request.approval ?? runId ?? request.execution ?? null) : null;
|
|
417
|
+
return { correlationId: causationId ?? invocationId, causationId, runId, idempotencyKey: key, origin };
|
|
418
|
+
};
|
|
419
|
+
/** What the call's write log changed, by entity: counts and ids (bounded), never values. */
|
|
420
|
+
const changesOf = (log) => {
|
|
421
|
+
const byEntity = new Map();
|
|
422
|
+
for (const write of log) {
|
|
423
|
+
const entity = entitiesByTable.get(`${write.schema}.${write.table}`);
|
|
424
|
+
if (entity === undefined)
|
|
425
|
+
continue;
|
|
426
|
+
const entry = byEntity.get(entity.cedarType) ?? { inserted: 0, updated: 0, deleted: 0, ids: new Set() };
|
|
427
|
+
if (write.op === "INSERT")
|
|
428
|
+
entry.inserted++;
|
|
429
|
+
else if (write.op === "DELETE")
|
|
430
|
+
entry.deleted++;
|
|
431
|
+
else
|
|
432
|
+
entry.updated++;
|
|
433
|
+
if (write.pk !== null)
|
|
434
|
+
entry.ids.add(write.pk);
|
|
435
|
+
byEntity.set(entity.cedarType, entry);
|
|
436
|
+
}
|
|
437
|
+
return [...byEntity].map(([entity, e]) => ({
|
|
438
|
+
entity,
|
|
439
|
+
inserted: e.inserted,
|
|
440
|
+
updated: e.updated,
|
|
441
|
+
deleted: e.deleted,
|
|
442
|
+
ids: [...e.ids].slice(0, AUDIT_CHANGED_IDS),
|
|
443
|
+
truncated: e.ids.size > AUDIT_CHANGED_IDS,
|
|
444
|
+
}));
|
|
445
|
+
};
|
|
446
|
+
const writeAudit = (context, outcome, errorTag, completion) =>
|
|
447
|
+
// A refusal or failure of a caller the kernel could not identify (no credential, an action it does not have,
|
|
448
|
+
// input that does not decode) is bounded per action and address (Audit.denied); an action name it does not
|
|
449
|
+
// have is counted under one name, so a caller cannot spread its records over names it makes up.
|
|
450
|
+
(outcome === "denied" || outcome === "failed") && context.actor === undefined
|
|
451
|
+
? audit.denied({
|
|
452
|
+
invocationId: context.invocationId,
|
|
453
|
+
action: context.action,
|
|
454
|
+
bucket: registry.actions.has(context.action) ? context.action : "(an action the kernel does not have)",
|
|
455
|
+
outcome,
|
|
456
|
+
surface: context.surface,
|
|
457
|
+
actorUserId: null,
|
|
458
|
+
orgId: null,
|
|
459
|
+
errorTag: errorTag ?? "Unknown",
|
|
460
|
+
address: context.address,
|
|
461
|
+
inputHash: context.inputHash,
|
|
462
|
+
idempotencyKey: context.idempotencyKey,
|
|
463
|
+
})
|
|
464
|
+
: audit.record({
|
|
465
|
+
invocationId: context.invocationId,
|
|
466
|
+
action: context.action,
|
|
467
|
+
surface: context.surface,
|
|
468
|
+
actorUserId: context.actor?.userId ?? null,
|
|
469
|
+
orgId: context.actor?.orgId ?? null,
|
|
470
|
+
outcome,
|
|
471
|
+
inputHash: context.inputHash,
|
|
472
|
+
idempotencyKey: context.idempotencyKey ?? null,
|
|
473
|
+
errorTag: errorTag ?? null,
|
|
474
|
+
affected: completion?.affected ?? null,
|
|
475
|
+
requested: completion?.requested ?? null,
|
|
476
|
+
completion: completion?.completion ?? null,
|
|
477
|
+
...(context.detail === undefined ? {} : { detail: context.detail }),
|
|
478
|
+
...(context.lineage === undefined ? {} : { lineage: context.lineage }),
|
|
479
|
+
...(outcome === "succeeded" && context.changes !== undefined && context.changes.length > 0
|
|
480
|
+
? { changes: context.changes }
|
|
481
|
+
: {}),
|
|
482
|
+
});
|
|
483
|
+
const forbidden = (action, message) => new Forbidden({ action, message });
|
|
484
|
+
/** The actions a permission of the vocabulary names (for `permission:<id>` scopes). */
|
|
485
|
+
const permissionActions = (permission) => registry.permissions.get(permission)?.actions;
|
|
486
|
+
/**
|
|
487
|
+
* The action's compiled filter for `entity`; a policy that cannot be compiled denies (fail closed). Like
|
|
488
|
+
* row-level security, the action's policy grants nothing on an entity it does not declare, and an
|
|
489
|
+
* organisation-wide action only records of the acting organisation.
|
|
490
|
+
*/
|
|
491
|
+
const filterFor = (actor, registered, entity, row = "old") =>
|
|
492
|
+
// A MAKE module's actions are compiled from its own policy alone.
|
|
493
|
+
(registered.module.make !== undefined && Option.isSome(makeRuntime)
|
|
494
|
+
? makeRuntime.value.filterFor(registered.module, actor, registered.cedarAction, entity, row)
|
|
495
|
+
: policy.filterFor(actor, registered.cedarAction, entity, row)).pipe(Effect.map((pred) => entity === undefined
|
|
496
|
+
? pred
|
|
497
|
+
: scopedToDeclaration(registered.module.contract, registered.contract, entity, pred, actor.orgId)), Effect.mapError((e) => forbidden(registered.contract.name, `Policy cannot be compiled into a filter: ${e.message}`)));
|
|
498
|
+
/**
|
|
499
|
+
* Run `effect` as the module's runtime role, where row-level security applies, and make sure it is
|
|
500
|
+
* still that role afterwards (a handler that switched roles is refused).
|
|
501
|
+
*/
|
|
502
|
+
const asModule = (registered, effect) => Effect.gen(function* () {
|
|
503
|
+
yield* sql.unsafe(`SET LOCAL ROLE ${quoteIdent(registered.module.role)}`).pipe(Effect.orDie);
|
|
504
|
+
const result = yield* effect;
|
|
505
|
+
const [role] = yield* sql `SELECT current_user AS role`.pipe(Effect.orDie);
|
|
506
|
+
if (role?.role !== registered.module.role) {
|
|
507
|
+
return yield* forbidden(registered.contract.name, "The handler changed its database role");
|
|
508
|
+
}
|
|
509
|
+
yield* sql.unsafe(`RESET ROLE`).pipe(Effect.orDie);
|
|
510
|
+
return result;
|
|
511
|
+
});
|
|
512
|
+
/** The `pks` of `entity` that exist and satisfy `pred`, optionally locked. Runs as the module's role. */
|
|
513
|
+
const satisfying = (registered, entity, pred, pks, lock) => Effect.gen(function* () {
|
|
514
|
+
if (pks.length === 0)
|
|
515
|
+
return new Set();
|
|
516
|
+
const filter = toSql(pred, entity, "r", 2, policy.referencesOf(entity));
|
|
517
|
+
const rows = yield* asModule(registered, sql
|
|
518
|
+
.unsafe(`SELECT r.${quoteIdent(pkColumn(entity))}::text AS pk FROM ${tableOf(entity)} r
|
|
519
|
+
WHERE r.${quoteIdent(pkColumn(entity))}::text = ANY($1) AND ${filter.text}${lock ? " FOR UPDATE OF r" : ""}`, [[...new Set(pks)], ...filter.params])
|
|
520
|
+
.pipe(Effect.orDie));
|
|
521
|
+
return new Set(rows.map((r) => r.pk));
|
|
522
|
+
});
|
|
523
|
+
/** Do all `pks` of `entity` exist and satisfy `pred`? */
|
|
524
|
+
const allSatisfy = (registered, entity, pred, pks, lock) => satisfying(registered, entity, pred, pks, lock).pipe(Effect.map((found) => found.size === new Set(pks).size));
|
|
525
|
+
const targetEntity = (registered) => registered.contract.target === undefined
|
|
526
|
+
? undefined
|
|
527
|
+
: registered.module.contract.entities[registered.contract.target.entity];
|
|
528
|
+
/** The declared target ids: the target field holds one id or a list of ids. */
|
|
529
|
+
const targetIds = (registered, input) => {
|
|
530
|
+
const field = registered.contract.target?.field;
|
|
531
|
+
if (field === undefined)
|
|
532
|
+
return undefined;
|
|
533
|
+
const value = input?.[field];
|
|
534
|
+
const one = (v) => (typeof v === "string" || typeof v === "number" ? String(v) : undefined);
|
|
535
|
+
if (Array.isArray(value)) {
|
|
536
|
+
const ids = value.map(one).filter((id) => id !== undefined);
|
|
537
|
+
return ids.length === value.length ? [...new Set(ids)] : undefined;
|
|
538
|
+
}
|
|
539
|
+
const id = one(value);
|
|
540
|
+
return id === undefined ? undefined : [id];
|
|
541
|
+
};
|
|
542
|
+
/**
|
|
543
|
+
* Before the handler: lock the declared targets the caller may act on. An exact action fails unless that
|
|
544
|
+
* is every target; a best-effort action continues with the permitted subset.
|
|
545
|
+
*/
|
|
546
|
+
const authoriseTargets = (actor, registered, input) => Effect.gen(function* () {
|
|
547
|
+
const entity = targetEntity(registered);
|
|
548
|
+
if (entity === undefined)
|
|
549
|
+
return undefined;
|
|
550
|
+
const requested = targetIds(registered, input);
|
|
551
|
+
if (requested === undefined)
|
|
552
|
+
return yield* new InvalidInput({ message: `Missing target ${registered.contract.target.field}` });
|
|
553
|
+
const pred = yield* filterFor(actor, registered, entity);
|
|
554
|
+
const permitted = yield* satisfying(registered, entity, pred, requested, true);
|
|
555
|
+
const bestEffort = registered.contract.bestEffort;
|
|
556
|
+
if (!bestEffort && permitted.size !== requested.length) {
|
|
557
|
+
return yield* forbidden(registered.contract.name, "The caller may not act on this record");
|
|
558
|
+
}
|
|
559
|
+
// What row-level security admits as an exact action's inserts and updates (`eloxiv_ctx.is_target`).
|
|
560
|
+
if (!bestEffort && requested.length > 0) {
|
|
561
|
+
yield* sql
|
|
562
|
+
.unsafe(`INSERT INTO eloxiv.invocation_target (pk) SELECT unnest($1::text[]) ON CONFLICT DO NOTHING`, [
|
|
563
|
+
[...requested],
|
|
564
|
+
])
|
|
565
|
+
.pipe(Effect.orDie);
|
|
566
|
+
}
|
|
567
|
+
return { entity, requested, permitted, bestEffort };
|
|
568
|
+
});
|
|
569
|
+
/**
|
|
570
|
+
* After the handler: authorise every row the transaction wrote, and check the declared targets were
|
|
571
|
+
* affected exactly (best effort: report how many were).
|
|
572
|
+
*/
|
|
573
|
+
const authoriseWrites = (actor, registered, targets, revertDeletes) => Effect.gen(function* () {
|
|
574
|
+
const name = registered.contract.name;
|
|
575
|
+
const log = yield* sql `
|
|
576
|
+
DELETE FROM eloxiv.invocation_write WHERE xid = pg_current_xact_id()
|
|
577
|
+
RETURNING id, table_schema AS schema, table_name AS "table", pk, op, row`.pipe(Effect.orDie);
|
|
578
|
+
const byEntity = new Map();
|
|
579
|
+
const affected = new Set();
|
|
580
|
+
const inserted = new Set();
|
|
581
|
+
// In the order the writes were made (a revert's delete allowance is taken by the first delete of its row).
|
|
582
|
+
for (const write of [...log].sort((a, b) => Number(a.id) - Number(b.id))) {
|
|
583
|
+
const entity = entitiesByTable.get(`${write.schema}.${write.table}`);
|
|
584
|
+
if (entity === undefined || write.pk === null) {
|
|
585
|
+
return yield* forbidden(name, `Write to ${write.schema}.${write.table}, which no entity contract governs`);
|
|
586
|
+
}
|
|
587
|
+
const isTarget = targets !== undefined && targets.entity === entity;
|
|
588
|
+
if (isTarget && !targets.permitted.has(write.pk)) {
|
|
589
|
+
return yield* forbidden(name, "The action changed a record other than its declared targets");
|
|
590
|
+
}
|
|
591
|
+
if (write.op === "DELETE") {
|
|
592
|
+
// Without a target, only the DELETE each `ctx.history.revert` issued (of a record its group created): the
|
|
593
|
+
// exact write-log entry it made, which is gone if a savepoint rolled it back. Any other delete is refused.
|
|
594
|
+
if (!isTarget && revertDeletes?.has(String(write.id)) !== true) {
|
|
595
|
+
return yield* forbidden(name, "The action deleted a record it was not authorised to act on");
|
|
596
|
+
}
|
|
597
|
+
affected.add(write.pk);
|
|
598
|
+
continue;
|
|
599
|
+
}
|
|
600
|
+
if (isTarget)
|
|
601
|
+
affected.add(write.pk);
|
|
602
|
+
if (write.op === "INSERT")
|
|
603
|
+
inserted.add(`${entity.cedarType}\u0000${write.pk}`);
|
|
604
|
+
byEntity.set(entity, (byEntity.get(entity) ?? new Set()).add(write.pk));
|
|
605
|
+
}
|
|
606
|
+
// Records this call inserted that still exist (candidates for the receipt's `created`).
|
|
607
|
+
const created = [];
|
|
608
|
+
for (const [entity, pks] of byEntity) {
|
|
609
|
+
// Rows inserted and then deleted again in the same call no longer exist; only surviving rows are checked.
|
|
610
|
+
const surviving = (yield* asModule(registered, sql
|
|
611
|
+
.unsafe(`SELECT r.${quoteIdent(pkColumn(entity))}::text AS pk FROM ${tableOf(entity)} r WHERE r.${quoteIdent(pkColumn(entity))}::text = ANY($1)`, [[...pks]])
|
|
612
|
+
.pipe(Effect.orDie))).map((r) => r.pk);
|
|
613
|
+
// The rows as the action left them: its policy for the new row.
|
|
614
|
+
const pred = yield* filterFor(actor, registered, entity, "new");
|
|
615
|
+
if (!(yield* allSatisfy(registered, entity, pred, surviving, false))) {
|
|
616
|
+
return yield* forbidden(name, "A record written by the action does not satisfy the action's policy");
|
|
617
|
+
}
|
|
618
|
+
for (const pk of surviving) {
|
|
619
|
+
if (inserted.has(`${entity.cedarType}\u0000${pk}`))
|
|
620
|
+
created.push({ entity: entity.cedarType, pk });
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
let completion;
|
|
624
|
+
if (targets !== undefined) {
|
|
625
|
+
if (!targets.bestEffort && affected.size !== targets.requested.length) {
|
|
626
|
+
return yield* forbidden(name, "The action did not affect its declared target");
|
|
627
|
+
}
|
|
628
|
+
completion = {
|
|
629
|
+
affected: affected.size,
|
|
630
|
+
requested: targets.requested.length,
|
|
631
|
+
completion: affected.size === targets.requested.length ? "complete" : "partial",
|
|
632
|
+
};
|
|
633
|
+
}
|
|
634
|
+
return { created, completion, log };
|
|
635
|
+
});
|
|
636
|
+
/** The database refused the statement for lack of privilege or a row-level security check. */
|
|
637
|
+
const refused = (e) => SqlError.isSqlError(e) &&
|
|
638
|
+
(e.reason._tag === "AuthorizationError" ||
|
|
639
|
+
// read_only_sql_transaction: a write inside a read-only scope (a read-only action or a view read).
|
|
640
|
+
e.reason.cause?.code === "25006");
|
|
641
|
+
/** The identity step: a surface's credentials, or an internal caller's execution identity (resolved now). */
|
|
642
|
+
const authenticateRequest = (request) => {
|
|
643
|
+
// Work asked for with a scoped credential stays within its scope (work with none recorded never acts), and the
|
|
644
|
+
// system's work within the scope it was narrowed to (an agent run's tools).
|
|
645
|
+
const kept = request.identity?.kind === "user" ? request.identity.authority : undefined;
|
|
646
|
+
const scope = request.identity?.kind === "system"
|
|
647
|
+
? request.identity.scope == null
|
|
648
|
+
? null
|
|
649
|
+
: [...request.identity.scope]
|
|
650
|
+
: typeof kept === "object" && kept.scope !== null
|
|
651
|
+
? [...kept.scope]
|
|
652
|
+
: null;
|
|
653
|
+
return request.identity !== undefined
|
|
654
|
+
? request.agentSession !== undefined
|
|
655
|
+
? identity
|
|
656
|
+
.resolveAgentSession(request.agentSession, request.identity)
|
|
657
|
+
.pipe(Effect.map((resolved) => ({ ...resolved, credential: { ...resolved.credential, scope } })))
|
|
658
|
+
: identity.resolve(request.identity).pipe(Effect.map((actor) => ({
|
|
659
|
+
actor,
|
|
660
|
+
credential: { kind: "session", id: null, scope },
|
|
661
|
+
// Work an agent set up keeps the agent's origin (and consent binds to its session).
|
|
662
|
+
session: request.identity?.kind === "user" && request.identity.agentSession !== undefined
|
|
663
|
+
? { id: `agent:${request.identity.agentSession}`, agent: true }
|
|
664
|
+
: undefined,
|
|
665
|
+
})))
|
|
666
|
+
: identity.authenticateCall(request.headers, request.surface);
|
|
667
|
+
};
|
|
668
|
+
/**
|
|
669
|
+
* The chain of authorities a call acts under (Authority): for deferred work, the chain it recorded and the agent
|
|
670
|
+
* session it is made through; for a call with a credential, the credential and the chain the session it is was
|
|
671
|
+
* issued under (a device turn's).
|
|
672
|
+
*/
|
|
673
|
+
const chainOf = (request, credential) => {
|
|
674
|
+
if (request.identity !== undefined) {
|
|
675
|
+
// A person's identity that does not say what it acts under is work queued before chains were recorded (or
|
|
676
|
+
// a caller that forgot to say): it fails closed. Trusted kernel code that acts with no link says so.
|
|
677
|
+
const kept = request.identity.kind === "user" ? (request.identity.authority ?? "unrecorded") : undefined;
|
|
678
|
+
if (kept === "unrecorded")
|
|
679
|
+
return "unrecorded";
|
|
680
|
+
const through = request.agentSession === undefined ? [] : [{ kind: "agent-session", id: request.agentSession }];
|
|
681
|
+
return extend(kept?.chain ?? [], through);
|
|
682
|
+
}
|
|
683
|
+
return credentialLinks(credential);
|
|
684
|
+
};
|
|
685
|
+
/** Where a call comes from, decided by the kernel from the surface and the credential: never by a header. */
|
|
686
|
+
const originOf = (request, session) =>
|
|
687
|
+
// An agent surface (agent tools, MCP) or an agent session makes the call an agent's, whatever identity it was
|
|
688
|
+
// given: `AgentTools.execute({ caller: { identity } })` with no agent session is still an agent's call, so the
|
|
689
|
+
// handler's `ctx.origin` agrees with what consent and the tool groups treat as one (`agentCall`), and guards
|
|
690
|
+
// that refuse agents (consent and business-approval decisions) hold for it.
|
|
691
|
+
isAgentOrigin(request.surface, session)
|
|
692
|
+
? "agent"
|
|
693
|
+
: // A call a MAKE module's code makes inside another call keeps that call's origin.
|
|
694
|
+
request.identity !== undefined && "provenance" in request && request.provenance !== undefined
|
|
695
|
+
? request.provenance.origin
|
|
696
|
+
: request.identity !== undefined && request.agentSession === undefined
|
|
697
|
+
? // A person's own call, deferred (an approval executing it), stays theirs.
|
|
698
|
+
request.identity.kind === "user" && request.identity.origin === "person"
|
|
699
|
+
? "person"
|
|
700
|
+
: "system"
|
|
701
|
+
: "person";
|
|
702
|
+
/**
|
|
703
|
+
* What deferring the call must keep (a business approval records it and executes the call with it): its
|
|
704
|
+
* origin, the reference it was the agent's under, its credential's scope and its whole chain of authorities.
|
|
705
|
+
*/
|
|
706
|
+
const provenanceOf = (request, origin, session, credential, chain) => {
|
|
707
|
+
const agent = agentCall(request, origin, session);
|
|
708
|
+
const reference = session?.agentSessionId ??
|
|
709
|
+
(session?.id.startsWith("agent:") === true ? session.id.slice("agent:".length) : session?.id) ??
|
|
710
|
+
`surface:${request.surface}`;
|
|
711
|
+
return {
|
|
712
|
+
origin: agent ? "agent" : origin,
|
|
713
|
+
...(agent ? { agentSession: reference } : {}),
|
|
714
|
+
// What an approval executes later rests on: never the call's own session (`deferrable`).
|
|
715
|
+
authority: { scope: credential.scope === null ? null : [...credential.scope], chain: deferrable(chain) },
|
|
716
|
+
// An agent run's call keeps its edit group: its changes, once approved, belong to the run like any other.
|
|
717
|
+
...(request.identity !== undefined && request.editGroup !== undefined
|
|
718
|
+
? { editGroup: request.editGroup }
|
|
719
|
+
: {}),
|
|
720
|
+
};
|
|
721
|
+
};
|
|
722
|
+
/** Is this an agent's call (what consent holds, and disabled tool groups refuse)? */
|
|
723
|
+
const agentCall = (request, origin, session) => origin === "agent" || isAgentOrigin(request.surface, session);
|
|
724
|
+
/**
|
|
725
|
+
* Is the action offered to this caller on this surface? Its exposure on the surface, and for an agent session's
|
|
726
|
+
* credential on an API transport (a browser agent's WebMCP bearer over HTTP or RPC) also its agent exposure: what
|
|
727
|
+
* the agent's tool list hides, the agent's own credential does not reach through another transport.
|
|
728
|
+
*/
|
|
729
|
+
const offered = (contract, surface, session) => exposedOn(contract, surface) &&
|
|
730
|
+
(session?.agent !== true || !API_SURFACES.has(surface) || contract.exposure.agent);
|
|
731
|
+
const toolGroupDisabled = (registered) => `Agents may not call this action: its tool group ${registered.disabledForAgents} is disabled in this app`;
|
|
732
|
+
/**
|
|
733
|
+
* Does the action's policy deny `actor` whatever the input: a constant FALSE for records as they stand and as
|
|
734
|
+
* the action would leave them (or, for an action that declares no entity, anything but a constant TRUE)?
|
|
735
|
+
*/
|
|
736
|
+
const deniedFor = (actor, registered) => Effect.gen(function* () {
|
|
737
|
+
const primary = registered.writes ?? targetEntity(registered);
|
|
738
|
+
const pred = yield* filterFor(actor, registered, primary);
|
|
739
|
+
if (primary === undefined)
|
|
740
|
+
return pred.kind !== "true";
|
|
741
|
+
return pred.kind === "false" && (yield* filterFor(actor, registered, primary, "new")).kind === "false";
|
|
742
|
+
});
|
|
743
|
+
const reach = (request) => Effect.gen(function* () {
|
|
744
|
+
const { actor, credential, session } = yield* authenticateRequest(request);
|
|
745
|
+
const origin = originOf(request, session);
|
|
746
|
+
const agent = agentCall(request, origin, session);
|
|
747
|
+
const actions = [];
|
|
748
|
+
const consider = (registered) => Effect.gen(function* () {
|
|
749
|
+
const name = registered.contract.name;
|
|
750
|
+
if (!scopeAllows(credential.scope, name, permissionActions))
|
|
751
|
+
return;
|
|
752
|
+
if (!offered(registered.contract, request.surface, session))
|
|
753
|
+
return;
|
|
754
|
+
if (agent && registered.disabledForAgents !== undefined)
|
|
755
|
+
return;
|
|
756
|
+
// A policy that cannot be compiled denies the call; it hides the action too.
|
|
757
|
+
const denied = yield* deniedFor(actor, registered).pipe(Effect.orElseSucceed(() => true));
|
|
758
|
+
if (!denied)
|
|
759
|
+
actions.push(name);
|
|
760
|
+
});
|
|
761
|
+
for (const registered of registry.actions.values())
|
|
762
|
+
yield* consider(registered);
|
|
763
|
+
// The MAKE modules installed in the caller's organisation, at the version each runs now (one read: a
|
|
764
|
+
// rollback shows at once), by the same checks (`invoke` looks them up by name and refuses another
|
|
765
|
+
// organisation's). Never one named as an app action, and never another organisation's.
|
|
766
|
+
if (Option.isSome(makeRuntime)) {
|
|
767
|
+
for (const registered of yield* makeRuntime.value.actionsIn(actor.orgId)) {
|
|
768
|
+
if (registry.actions.has(registered.contract.name))
|
|
769
|
+
continue;
|
|
770
|
+
if (registered.module.make?.orgId !== actor.orgId)
|
|
771
|
+
continue;
|
|
772
|
+
yield* consider(registered);
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
return { actor, origin, actions: actions.sort() };
|
|
776
|
+
}).pipe(Effect.withSpan("Invocation.reach", { attributes: { surface: request.surface } }));
|
|
777
|
+
const execute = (registered, actor, invocationId, input, origin, context, asserted, held) => Effect.gen(function* () {
|
|
778
|
+
const name = registered.contract.name;
|
|
779
|
+
const events = [];
|
|
780
|
+
// This attempt's deletes by `ctx.history.revert` (their write-log entries), and the group each record it
|
|
781
|
+
// changed was reverted for: a run again after a conflict starts with none.
|
|
782
|
+
const revertDeletes = new Set();
|
|
783
|
+
const revertGroups = new Map();
|
|
784
|
+
// Work items and notifications the handler asks for are applied after its writes are checked.
|
|
785
|
+
const items = workItems.buffer(registered.module.contract.name, actor.orgId, asserted);
|
|
786
|
+
const notify = notifications.buffer(actor.orgId);
|
|
787
|
+
// External effects the handler schedules: recorded with the kernel's writes, delivered after commit.
|
|
788
|
+
const effects = effectBuffer(actor, registered, invocationId, context.idempotencyKey, asserted);
|
|
789
|
+
// The sharing operations for this actor; only the kernel's own sharing module may find a record's managers.
|
|
790
|
+
const sharingApi = sharing.forActor(actor, registered.module.role);
|
|
791
|
+
const { managersOf: _managers, askManagers: _ask, ...publicSharing } = sharingApi;
|
|
792
|
+
// The role the handler runs as: its module's, or the kernel's own for a kernel module's handlers.
|
|
793
|
+
const handlerRole = registered.kernel && !(Option.isSome(kernelHandlers) && kernelHandlers.value.find(registered.module, name))
|
|
794
|
+
? undefined
|
|
795
|
+
: registered.module.role;
|
|
796
|
+
const moduleName = registered.module.contract.name;
|
|
797
|
+
const progress = Option.isSome(progressService)
|
|
798
|
+
? progressService.value.buffer(actor, moduleName, invocationId)
|
|
799
|
+
: undefined;
|
|
800
|
+
// A module's events are declared in its manifest and checked here (the telemetry module relays clients'
|
|
801
|
+
// declared `client.*` events); they are queued once the call commits.
|
|
802
|
+
const track = (event) => Effect.gen(function* () {
|
|
803
|
+
const decoded = yield* Schema.decodeUnknownEffect(TrackEventSchema)(event).pipe(Effect.mapError(() => new InvalidInput({ message: "An analytics event is an event name and properties" })));
|
|
804
|
+
if (Option.isNone(analytics))
|
|
805
|
+
return;
|
|
806
|
+
const prepared = yield* analytics.value.prepare(moduleName, actor, decoded);
|
|
807
|
+
if (prepared !== null && actor.userId !== SYSTEM_ACTOR)
|
|
808
|
+
context.events.push(prepared);
|
|
809
|
+
});
|
|
810
|
+
// The handler's own statements wait while a helper switches the connection's role (db-tx.md, guarantee 2).
|
|
811
|
+
const gate = handlerGate(sql);
|
|
812
|
+
const ungated = {
|
|
813
|
+
actor,
|
|
814
|
+
invocationId,
|
|
815
|
+
sql,
|
|
816
|
+
queryView: (id, limit) => readOwnView(sql, registered.module, id, limit),
|
|
817
|
+
// A module emits only the events its manifest declares, encoded by the declared payload schema: never
|
|
818
|
+
// another module's (which would start that module's triggers as if it had emitted them).
|
|
819
|
+
emit: (event, payload) => {
|
|
820
|
+
const declared = Object.values(registered.module.contract.events).find((e) => e.type === event.type);
|
|
821
|
+
return declared === undefined
|
|
822
|
+
? Effect.die(new Error(`Module ${moduleName} emitted ${event.type}, an event its manifest does not declare`))
|
|
823
|
+
: Effect.sync(() => void events.push({ event: declared, payload }));
|
|
824
|
+
},
|
|
825
|
+
origin,
|
|
826
|
+
authority: recordOf(asserted),
|
|
827
|
+
workItems: items.api,
|
|
828
|
+
notify: notify.api,
|
|
829
|
+
settings: Option.isSome(settingsService) ? settingsService.value.api : { get: () => missing("Settings") },
|
|
830
|
+
flags: Option.isSome(flagsService) ? flagsService.value.api(actor) : { isEnabled: () => missing("Flags") },
|
|
831
|
+
sharing: registered.module === sharingModule ? sharingApi : publicSharing,
|
|
832
|
+
files: Option.isSome(filesService)
|
|
833
|
+
? filesService.value.forHandler(actor, registered.module.contract.name, handlerRole, invocationId)
|
|
834
|
+
: { attach: () => missing("Files"), list: () => missing("Files") },
|
|
835
|
+
ingestion: Option.isSome(ingestionService)
|
|
836
|
+
? ingestionService.value.forHandler(actor, registered.module.contract.name, handlerRole, invocationId, asserted)
|
|
837
|
+
: {
|
|
838
|
+
submit: () => missing("Ingestion"),
|
|
839
|
+
current: () => missing("Ingestion"),
|
|
840
|
+
basis: () => missing("Ingestion"),
|
|
841
|
+
collect: () => missing("Ingestion"),
|
|
842
|
+
collection: () => missing("Ingestion"),
|
|
843
|
+
datasets: {
|
|
844
|
+
stage: () => missing("Ingestion"),
|
|
845
|
+
rows: () => missing("Ingestion"),
|
|
846
|
+
query: () => missing("Ingestion"),
|
|
847
|
+
list: () => missing("Ingestion"),
|
|
848
|
+
drop: () => missing("Ingestion"),
|
|
849
|
+
},
|
|
850
|
+
runs: {
|
|
851
|
+
open: () => missing("Ingestion"),
|
|
852
|
+
claim: () => missing("Ingestion"),
|
|
853
|
+
complete: () => missing("Ingestion"),
|
|
854
|
+
report: () => missing("Ingestion"),
|
|
855
|
+
inventory: () => missing("Ingestion"),
|
|
856
|
+
finish: () => missing("Ingestion"),
|
|
857
|
+
},
|
|
858
|
+
},
|
|
859
|
+
progress: progress?.api ?? {
|
|
860
|
+
start: () => Effect.succeed(`pt_${crypto.randomUUID()}`),
|
|
861
|
+
update: () => Effect.void,
|
|
862
|
+
complete: () => Effect.void,
|
|
863
|
+
fail: () => Effect.void,
|
|
864
|
+
},
|
|
865
|
+
analytics: { track },
|
|
866
|
+
history: Option.isSome(versioning)
|
|
867
|
+
? versioning.value.api(sql, registered.module, actor, name, {
|
|
868
|
+
deleted: (writeId) => void revertDeletes.add(writeId),
|
|
869
|
+
reverted: (record, group) => void revertGroups.set(record, group),
|
|
870
|
+
})
|
|
871
|
+
: {
|
|
872
|
+
restore: () => Effect.fail(new InvalidInput({ message: "Record history is not available" })),
|
|
873
|
+
revert: () => Effect.fail(new InvalidInput({ message: "Record history is not available" })),
|
|
874
|
+
},
|
|
875
|
+
connections: connectionsApi(actor, registered, effects, asserted, () => void (context.acted ??= "provider")),
|
|
876
|
+
// Read as the owner's role under its row-level security, filtered by its read policy for the caller,
|
|
877
|
+
// in one statement (the handler's role never changes between its own); the entity is the registered one
|
|
878
|
+
// of that Cedar type, never the table the value passed names.
|
|
879
|
+
references: {
|
|
880
|
+
read: (entity, id) => readReference(sql, registry, policy, actor, entity.cedarType, id),
|
|
881
|
+
},
|
|
882
|
+
};
|
|
883
|
+
// Only the helpers that switch the connection's role (or assert on it as the kernel) are run exclusively. The
|
|
884
|
+
// rest buffer until the handler returns (notify, progress, analytics), read through definer functions
|
|
885
|
+
// (settings, flags), or read as the handler's own role or in one statement (queryView, references): they stay
|
|
886
|
+
// outside the gate, so a handler that calls them while it reads a stream of its own never waits on it.
|
|
887
|
+
const base = {
|
|
888
|
+
...ungated,
|
|
889
|
+
workItems: gate.api(ungated.workItems),
|
|
890
|
+
sharing: gate.api(ungated.sharing),
|
|
891
|
+
connections: gate.api(ungated.connections),
|
|
892
|
+
files: gate.api(ungated.files),
|
|
893
|
+
ingestion: gate.api({
|
|
894
|
+
...ungated.ingestion,
|
|
895
|
+
runs: gate.api(ungated.ingestion.runs),
|
|
896
|
+
datasets: gate.api(ungated.ingestion.datasets),
|
|
897
|
+
}),
|
|
898
|
+
history: gate.api(ungated.history),
|
|
899
|
+
};
|
|
900
|
+
// A read-only action changes nothing: its SQL runs in a read-only scope, and what the context would buffer to
|
|
901
|
+
// apply after the handler (events, work items, notifications, progress, external effects) is refused, so a
|
|
902
|
+
// read never leaves a side effect, nor one per retry of it (a read batch's reader retries lost answers).
|
|
903
|
+
const readOnlyRefusal = (what) => () => Effect.die(new Error(`${name} is read-only: it may not ${what}`));
|
|
904
|
+
const ctx = !registered.contract.hints.readOnly
|
|
905
|
+
? base
|
|
906
|
+
: {
|
|
907
|
+
...base,
|
|
908
|
+
emit: readOnlyRefusal("emit events"),
|
|
909
|
+
workItems: {
|
|
910
|
+
...base.workItems,
|
|
911
|
+
put: readOnlyRefusal("put work items"),
|
|
912
|
+
close: readOnlyRefusal("close work items"),
|
|
913
|
+
retitle: readOnlyRefusal("retitle work items"),
|
|
914
|
+
},
|
|
915
|
+
notify: { ...base.notify, send: readOnlyRefusal("send notifications") },
|
|
916
|
+
progress: {
|
|
917
|
+
start: readOnlyRefusal("start progress"),
|
|
918
|
+
update: readOnlyRefusal("report progress"),
|
|
919
|
+
complete: readOnlyRefusal("report progress"),
|
|
920
|
+
fail: readOnlyRefusal("report progress"),
|
|
921
|
+
},
|
|
922
|
+
connections: { ...base.connections, schedule: readOnlyRefusal("schedule external effects") },
|
|
923
|
+
};
|
|
924
|
+
const denied = (e) => forbidden(name, `The database refused a change the action is not authorised for: ${SqlError.isSqlError(e) && e.reason.cause instanceof Error ? e.reason.cause.message : String(e)}`);
|
|
925
|
+
// Execute as the module's runtime role: its own schema only, plain DML, under row-level security. An
|
|
926
|
+
// action hinted read-only runs its handler in a read-only scope, so the hint surfaces publish holds.
|
|
927
|
+
//
|
|
928
|
+
// The handler bound when the registry was built. The kernel's own modules served by kernel services
|
|
929
|
+
// (`KernelActionHandlers`: query, settings, flags) run the kernel's function, as the module's role. The
|
|
930
|
+
// kernel's own modules defined with `defineKernelModule` are kernel code on the kernel's tables: they run
|
|
931
|
+
// as the kernel's role, with the kernel's services, and authorise what they touch themselves. Every other
|
|
932
|
+
// handler is module code and runs without the kernel's services.
|
|
933
|
+
const kernelHandler = Option.isSome(kernelHandlers)
|
|
934
|
+
? kernelHandlers.value.find(registered.module, name)
|
|
935
|
+
: undefined;
|
|
936
|
+
const kernelModule = kernelHandler === undefined && registered.kernel;
|
|
937
|
+
const call = Effect.suspend(() => registered.handler(input, ctx));
|
|
938
|
+
const handler = kernelHandler !== undefined
|
|
939
|
+
? kernelHandler(input, ctx, {
|
|
940
|
+
auditDetail: (detail) => Effect.sync(() => void (context.detail = detail)),
|
|
941
|
+
asserted,
|
|
942
|
+
credential: held,
|
|
943
|
+
})
|
|
944
|
+
: kernelModule
|
|
945
|
+
? Effect.provide(call, kernelContext).pipe(Effect.provideService(CallerCredential, held), Effect.provideService(CallerAuthority, asserted),
|
|
946
|
+
// A kernel module's handler about to commit outside the call (MAKE's setup): it may have acted.
|
|
947
|
+
Effect.provideService(CallActed, { mark: Effect.sync(() => void (context.acted ??= "setup")) }))
|
|
948
|
+
: asModuleCode(call);
|
|
949
|
+
const run = kernelModule ? (_, effect) => effect : asModule;
|
|
950
|
+
// A kernel handler's unexpected failure is logged, never returned: its message may carry what the
|
|
951
|
+
// kernel holds (a token, a secret), which the caller must not see.
|
|
952
|
+
const unexpected = (defect) => capture(invocationId).pipe(Effect.andThen(unexpectedFailure(defect)));
|
|
953
|
+
const unexpectedFailure = (defect) =>
|
|
954
|
+
// A constraint conflict may name a record the caller cannot read: a fixed message, the detail logged.
|
|
955
|
+
sqlStateOf(defect, CONSTRAINT_CONFLICTS) !== undefined
|
|
956
|
+
? Effect.logWarning(`${name} hit a constraint`, defect).pipe(Effect.as(new ActionFailed({ action: name, message: CONSTRAINT_CONFLICT_MESSAGE })))
|
|
957
|
+
: kernelModule
|
|
958
|
+
? Effect.logError(`The kernel's ${name} handler failed unexpectedly`, defect).pipe(Effect.as(new ActionFailed({
|
|
959
|
+
action: name,
|
|
960
|
+
message: `The action failed unexpectedly (invocation ${invocationId})`,
|
|
961
|
+
})))
|
|
962
|
+
: Effect.succeed(new ActionFailed({ action: name, message: String(defect) }));
|
|
963
|
+
const output = yield* run(registered, gate.around(registered.contract.hints.readOnly ? readOnly(sql, handler) : handler).pipe(Effect.mapError((e) => (refused(e) ? denied(e) : e)),
|
|
964
|
+
// A lock conflict the database reported to a statement of the handler's (a deadlock, a serialisation
|
|
965
|
+
// failure) aborted the call's transaction: it stays a defect, which the transaction's retry runs again
|
|
966
|
+
// (`retryingConflicts`), rather than becoming the handler's failure.
|
|
967
|
+
Effect.catchDefect((defect) => isLockConflictError(defect)
|
|
968
|
+
? Effect.die(defect)
|
|
969
|
+
: refused(defect)
|
|
970
|
+
? Effect.fail(denied(defect))
|
|
971
|
+
: Effect.flatMap(unexpected(defect), Effect.fail))));
|
|
972
|
+
const kernelWrites = Effect.all([items.apply, notify.apply, progress?.apply ?? Effect.void, effects.apply], {
|
|
973
|
+
discard: true,
|
|
974
|
+
}).pipe(Effect.mapError((e) => new ActionFailed({ action: name, message: e.message })));
|
|
975
|
+
return {
|
|
976
|
+
output,
|
|
977
|
+
events,
|
|
978
|
+
kernelWrites,
|
|
979
|
+
effectIds: effects.pending.map((p) => p.id),
|
|
980
|
+
revertDeletes,
|
|
981
|
+
revertGroups,
|
|
982
|
+
};
|
|
983
|
+
});
|
|
984
|
+
/** Run `effect` outside the current transaction: on its own connection, committed on its own. */
|
|
985
|
+
const outsideTransaction = (effect) => Effect.updateContext(effect, (context) => Context.omit(sql.transactionService)(context));
|
|
986
|
+
/** Run `effect` in a kernel transaction of its own (a database failure of the transaction is a defect). */
|
|
987
|
+
const inTransaction = (effect) => sql.withTransaction(effect).pipe(Effect.catchIf((e) => SqlError.isSqlError(e), (e) => Effect.die(e)));
|
|
988
|
+
/**
|
|
989
|
+
* Execute a MAKE module's action (`make/Execute.ts`): its code in the sandbox, its statements on a session of
|
|
990
|
+
* its own runtime role, and everything the call leaves (its rows, its idempotency claim and receipt, its audit
|
|
991
|
+
* record, its events and its one-time consent's use) committed once, in that session's transaction. It runs
|
|
992
|
+
* inside the kernel transaction that holds the call's authority (asserted, its links locked, its consent
|
|
993
|
+
* locked), which commits after it; its other kernel statements run outside that one, each on its own (a setting
|
|
994
|
+
* is read in a transaction of its own), and the expiry check and the guard (`InvocationRequest.guard`) are held
|
|
995
|
+
* from just before its commit until it is answered. `nested`: called by another MAKE call's code (it runs only
|
|
996
|
+
* if an interpreter is free at once). `taken`: the idempotency key is another call's, answered as a replay.
|
|
997
|
+
*/
|
|
998
|
+
const executeMakeAction = (registered, actor, context, decoded, encoded, key, provenance, options,
|
|
999
|
+
/** What the call acts under: the read-only calls its code makes act under it too (Authority). */
|
|
1000
|
+
acting,
|
|
1001
|
+
/**
|
|
1002
|
+
* The call's authority, asserted in the kernel transaction that encloses the module's (its links held until
|
|
1003
|
+
* that one commits), and the one-time consents it uses up, recorded in the module's transaction.
|
|
1004
|
+
*/
|
|
1005
|
+
held) => Effect.gen(function* () {
|
|
1006
|
+
const runtime = Option.getOrThrow(makeRuntime);
|
|
1007
|
+
const module = registered.module;
|
|
1008
|
+
const contract = registered.contract;
|
|
1009
|
+
const name = contract.name;
|
|
1010
|
+
const session = yield* runtime.session(module);
|
|
1011
|
+
const events = [];
|
|
1012
|
+
const identity = actor.userId === SYSTEM_ACTOR
|
|
1013
|
+
? { kind: "system", orgId: actor.orgId, ...(acting.scope === null ? {} : { scope: [...acting.scope] }) }
|
|
1014
|
+
: { kind: "user", userId: actor.userId, orgId: actor.orgId, authority: acting };
|
|
1015
|
+
const failedWith = (e) => e._tag === "Forbidden"
|
|
1016
|
+
? e
|
|
1017
|
+
: new ActionFailed({ action: name, message: `${e._tag}: ${"message" in e ? e.message : ""}` });
|
|
1018
|
+
const encodeOutput = (value) => asModuleCode(Schema.encodeUnknownEffect(contract.output)(value));
|
|
1019
|
+
let finished;
|
|
1020
|
+
const outcome = yield* executeMake({
|
|
1021
|
+
module,
|
|
1022
|
+
action: contract,
|
|
1023
|
+
actor,
|
|
1024
|
+
origin: provenance.origin,
|
|
1025
|
+
invocationId: context.invocationId,
|
|
1026
|
+
input: decoded,
|
|
1027
|
+
encodedInput: encoded,
|
|
1028
|
+
session,
|
|
1029
|
+
kernel: sql,
|
|
1030
|
+
autonomous: outsideTransaction,
|
|
1031
|
+
filterFor: (entity, row) => filterFor(actor, registered, entity, row),
|
|
1032
|
+
references: runtime.referencesOf(module),
|
|
1033
|
+
emit: (event, payload) => Effect.sync(() => void events.push({ event, payload })),
|
|
1034
|
+
// Another module's read-only action, through this same path, as the caller and with the call's own
|
|
1035
|
+
// provenance (its origin and agent session), in a read-only transaction of its own: it writes nothing, so
|
|
1036
|
+
// whether this call then commits changes nothing of it. Never a kernel module's action (governance:
|
|
1037
|
+
// approvals, consent, MAKE itself, sharing, settings ...), nor one that needs the person's consent.
|
|
1038
|
+
call: (action, input) => Effect.gen(function* () {
|
|
1039
|
+
const target = registry.actions.get(action) ?? (yield* runtime.lookup(action));
|
|
1040
|
+
if (target === undefined)
|
|
1041
|
+
return yield* forbidden(name, `No action ${action}`);
|
|
1042
|
+
if (isKernelProvided(target.module) || target.kernel) {
|
|
1043
|
+
return yield* forbidden(name, `${action} is the kernel's; a module's code cannot call it`);
|
|
1044
|
+
}
|
|
1045
|
+
if (!target.contract.hints.readOnly) {
|
|
1046
|
+
return yield* forbidden(name, `${action} writes; a module's code calls only read-only actions`);
|
|
1047
|
+
}
|
|
1048
|
+
if (target.contract.consent) {
|
|
1049
|
+
return yield* forbidden(name, `${action} needs the person's consent; a module's code cannot call it`);
|
|
1050
|
+
}
|
|
1051
|
+
const called = yield* outsideTransaction(invoke({ action, input: { encoded: input }, surface: "internal", identity, provenance })).pipe(Effect.mapError(failedWith));
|
|
1052
|
+
return called.encoded;
|
|
1053
|
+
}),
|
|
1054
|
+
// A setting, for the caller, read as the module's runtime role (as a built-in handler reads it), in a
|
|
1055
|
+
// kernel transaction of its own with the call's invocation context.
|
|
1056
|
+
setting: (key) => Option.isNone(settingsService)
|
|
1057
|
+
? Effect.fail(new ActionFailed({ action: name, message: "This app has no settings" }))
|
|
1058
|
+
: inTransaction(Effect.gen(function* () {
|
|
1059
|
+
yield* sql `INSERT INTO eloxiv.invocation_context (actor, org, action)
|
|
1060
|
+
VALUES (${actor.userId}, ${actor.orgId}, ${name})`.pipe(Effect.orDie);
|
|
1061
|
+
yield* sql.unsafe(`SET LOCAL ROLE ${quoteIdent(module.role)}`).pipe(Effect.orDie);
|
|
1062
|
+
const value = yield* settingsService.value.api.get(key);
|
|
1063
|
+
yield* sql.unsafe(`RESET ROLE`).pipe(Effect.orDie);
|
|
1064
|
+
yield* sql `DELETE FROM eloxiv.invocation_context WHERE xid = pg_current_xact_id()`.pipe(Effect.orDie);
|
|
1065
|
+
return value;
|
|
1066
|
+
})),
|
|
1067
|
+
nested: options.nested,
|
|
1068
|
+
// The guard (an agent run's cancellation) holds what it reads from just before the commit until the
|
|
1069
|
+
// commit is answered, in a kernel transaction: a failure of it rolls the call back.
|
|
1070
|
+
// Before the module's commit, the check at commit (Authority.confirm): the call's links that expire still
|
|
1071
|
+
// hold by the clock and its session is not revoked (their rows are held since the assertion, by the
|
|
1072
|
+
// enclosing kernel transaction, and the revocation's lock from here to that transaction's commit).
|
|
1073
|
+
atCommit: (commit) => inTransaction(authority.confirm(held.asserted).pipe(Effect.andThen(options.guard ?? Effect.void),
|
|
1074
|
+
// From here the module's transaction commits: a failure now may come after it took effect.
|
|
1075
|
+
Effect.andThen(Effect.sync(() => void (context.acted ??= "committing"))), Effect.andThen(commit))),
|
|
1076
|
+
commit: {
|
|
1077
|
+
idempotency: key === undefined ? undefined : { key, requestHash: context.inputHash },
|
|
1078
|
+
consumes: held.consumes,
|
|
1079
|
+
finish: (result) => Effect.gen(function* () {
|
|
1080
|
+
const completion = result.completion;
|
|
1081
|
+
// Best effort: the kernel, not the handler, reports what was affected.
|
|
1082
|
+
const output = contract.bestEffort && completion !== undefined
|
|
1083
|
+
? { ...result.output, ...completion }
|
|
1084
|
+
: result.output;
|
|
1085
|
+
const encodedOutput = yield* encodeOutput(output).pipe(Effect.mapError((e) => new ActionFailed({ action: name, message: `The output does not encode: ${String(e)}` })));
|
|
1086
|
+
const named = valuesIn(encodedOutput);
|
|
1087
|
+
// Its events are written by the module's commit (`make_finish`), which then adds to this receipt a
|
|
1088
|
+
// reference to every outbox row the invocation committed (migration 0235), as an ordinary call's.
|
|
1089
|
+
const receipt = {
|
|
1090
|
+
version: RECEIPT_VERSION,
|
|
1091
|
+
action: name,
|
|
1092
|
+
invocationId: context.invocationId,
|
|
1093
|
+
outcome: "succeeded",
|
|
1094
|
+
targets: targetIds(registered, decoded) ?? [],
|
|
1095
|
+
created: result.created
|
|
1096
|
+
.filter((r) => r.entity === registered.writes?.cedarType && named.has(r.pk))
|
|
1097
|
+
.map((r) => r.pk),
|
|
1098
|
+
...(isNoOp(encodedOutput) ? { noop: encodedOutput } : {}),
|
|
1099
|
+
completion: contract.bestEffort ? (completion ?? null) : null,
|
|
1100
|
+
...(provenance.receipt === undefined ? {} : { provenance: provenance.receipt }),
|
|
1101
|
+
};
|
|
1102
|
+
const encodedEvents = [];
|
|
1103
|
+
for (const { event, payload } of events) {
|
|
1104
|
+
const encodedPayload = yield* asModuleCode(Schema.encodeUnknownEffect(event.payload)(payload)).pipe(Effect.mapError((e) => new ActionFailed({ action: name, message: String(e) })));
|
|
1105
|
+
encodedEvents.push({ type: event.type, payload: encodedPayload });
|
|
1106
|
+
}
|
|
1107
|
+
finished = {
|
|
1108
|
+
invocationId: context.invocationId,
|
|
1109
|
+
replayed: false,
|
|
1110
|
+
output,
|
|
1111
|
+
envelope: { kind: "output", output },
|
|
1112
|
+
encoded: { kind: "output", output: encodedOutput },
|
|
1113
|
+
};
|
|
1114
|
+
return {
|
|
1115
|
+
surface: context.surface,
|
|
1116
|
+
inputHash: context.inputHash,
|
|
1117
|
+
idempotencyKey: key ?? null,
|
|
1118
|
+
completion: completion ?? null,
|
|
1119
|
+
receipt: key === undefined ? null : receipt,
|
|
1120
|
+
receiptFormat: RECEIPT_FORMAT,
|
|
1121
|
+
events: encodedEvents,
|
|
1122
|
+
};
|
|
1123
|
+
}),
|
|
1124
|
+
},
|
|
1125
|
+
});
|
|
1126
|
+
if (outcome.kind === "taken")
|
|
1127
|
+
return { kind: "taken" };
|
|
1128
|
+
return { kind: "done", result: finished };
|
|
1129
|
+
});
|
|
1130
|
+
const body = (request, context) => Effect.gen(function* () {
|
|
1131
|
+
const registered = registry.actions.get(request.action) ??
|
|
1132
|
+
(Option.isSome(makeRuntime) ? yield* makeRuntime.value.lookup(request.action) : undefined);
|
|
1133
|
+
if (!registered)
|
|
1134
|
+
return yield* new UnknownAction({ action: request.action, message: `No action ${request.action}` });
|
|
1135
|
+
const contract = registered.contract;
|
|
1136
|
+
if (!contract.hints.readOnly)
|
|
1137
|
+
yield* checkClientVersion(contract.name, request);
|
|
1138
|
+
// Normalise input to both forms; hash the canonical encoded form.
|
|
1139
|
+
// The action's schemas are the module's: module code, like its handler. Every problem of the input is
|
|
1140
|
+
// reported at once, so a caller (an agent above all) fixes them in one retry rather than one per retry.
|
|
1141
|
+
const decodeInput = (value) => asModuleCode(Schema.decodeUnknownEffect(contract.input)(value, { errors: "all" }));
|
|
1142
|
+
const encodeInput = (value) => asModuleCode(Schema.encodeUnknownEffect(contract.input)(value));
|
|
1143
|
+
const invalid = (e) => new InvalidInput({ message: String(e) });
|
|
1144
|
+
const decoded = "decoded" in request.input
|
|
1145
|
+
? request.input.decoded
|
|
1146
|
+
: yield* decodeInput(request.input.encoded).pipe(Effect.mapError(invalid));
|
|
1147
|
+
const encoded = yield* encodeInput(decoded).pipe(Effect.mapError(invalid));
|
|
1148
|
+
context.inputHash = yield* hashOf(encoded);
|
|
1149
|
+
// 1. Identity: credentials from a surface, or an internal caller's execution identity (resolved now).
|
|
1150
|
+
const authenticate = authenticateRequest(request);
|
|
1151
|
+
// An execution identity names who the call acts as even when resolving it is refused (a requester who
|
|
1152
|
+
// left the organisation): the audit record says whose call was refused.
|
|
1153
|
+
if (request.identity !== undefined) {
|
|
1154
|
+
context.actor = {
|
|
1155
|
+
userId: request.identity.kind === "user" ? request.identity.userId : SYSTEM_ACTOR,
|
|
1156
|
+
orgId: request.identity.orgId,
|
|
1157
|
+
email: "",
|
|
1158
|
+
roles: [],
|
|
1159
|
+
groups: [],
|
|
1160
|
+
permissions: [],
|
|
1161
|
+
};
|
|
1162
|
+
}
|
|
1163
|
+
const authenticated = yield* authenticate;
|
|
1164
|
+
const { actor, credential } = authenticated;
|
|
1165
|
+
const session = request.identity !== undefined && request.provenance !== undefined
|
|
1166
|
+
? request.provenance.session
|
|
1167
|
+
: authenticated.session;
|
|
1168
|
+
context.actor = actor;
|
|
1169
|
+
// Deferred or indirect work acts only while every authority it depends on holds (asserted again, with the
|
|
1170
|
+
// rows locked, inside the call's transaction): refused here before any stage records anything.
|
|
1171
|
+
const recorded = chainOf(request, credential);
|
|
1172
|
+
// Recurring work (a schedule's run) may not rest on a one-time consent.
|
|
1173
|
+
const recurringWork = request.identity?.kind === "user" &&
|
|
1174
|
+
typeof request.identity.authority === "object" &&
|
|
1175
|
+
request.identity.authority.recurring === true;
|
|
1176
|
+
yield* authority.check({ chain: recorded, who: actor, scope: credential.scope, recurring: recurringWork });
|
|
1177
|
+
const chain = recorded === "unrecorded" ? [] : recorded;
|
|
1178
|
+
// A MAKE module is installed for the organisation that made and approved it, and serves only its members.
|
|
1179
|
+
const make = registered.module.make;
|
|
1180
|
+
if (make !== undefined && make.orgId !== actor.orgId) {
|
|
1181
|
+
return yield* forbidden(contract.name, "This module is not installed in your organisation");
|
|
1182
|
+
}
|
|
1183
|
+
// Where the call comes from, decided by the kernel: never by a header.
|
|
1184
|
+
const origin = originOf(request, session);
|
|
1185
|
+
context.origin = origin;
|
|
1186
|
+
context.lineage = lineageOf(request, origin, credential, chain, undefined);
|
|
1187
|
+
// A machine credential's scope narrows what it may call; it never widens the policy.
|
|
1188
|
+
if (!scopeAllows(credential.scope, contract.name, permissionActions)) {
|
|
1189
|
+
return yield* forbidden(contract.name, "The credential is not scoped to this action");
|
|
1190
|
+
}
|
|
1191
|
+
// A surface the action is not offered on (its exposure) does not run it, whoever calls.
|
|
1192
|
+
if (!exposedOn(contract, request.surface)) {
|
|
1193
|
+
return yield* forbidden(contract.name, `This action is not offered on the ${request.surface} surface`);
|
|
1194
|
+
}
|
|
1195
|
+
// An agent session's credential reaches only what the agent surface offers, on whichever API transport.
|
|
1196
|
+
if (!offered(contract, request.surface, session)) {
|
|
1197
|
+
return yield* forbidden(contract.name, "This action is not offered to agents");
|
|
1198
|
+
}
|
|
1199
|
+
// An agent tool group the app disabled: no agent reaches its actions, on any surface.
|
|
1200
|
+
if (agentCall(request, origin, session) && registered.disabledForAgents !== undefined) {
|
|
1201
|
+
return yield* forbidden(contract.name, toolGroupDisabled(registered));
|
|
1202
|
+
}
|
|
1203
|
+
// 2. Policy: a constant FALSE (for records as they stand and as the action would leave them) denies
|
|
1204
|
+
// before anything runs.
|
|
1205
|
+
const denies = (current) => deniedFor(current, registered);
|
|
1206
|
+
if (yield* denies(actor))
|
|
1207
|
+
return yield* forbidden(contract.name, "Policy denies this action");
|
|
1208
|
+
// 3. Consent or business approval. Without the consent module (allowed only for the kernel-provided
|
|
1209
|
+
// scheduler's actions), an agent's call that needs consent cannot be held for the person: it is refused.
|
|
1210
|
+
if (contract.consent && !consentInstalled && agentCall(request, origin, session)) {
|
|
1211
|
+
return yield* forbidden(contract.name, "An agent's call to this action needs the person's consent, and this app has no consent module");
|
|
1212
|
+
}
|
|
1213
|
+
// A sequenced call (sync's push) never reaches a MAKE action: its writes commit in its module's own
|
|
1214
|
+
// transaction, not the kernel's one the sequence advances in.
|
|
1215
|
+
if (request.sequence !== undefined && make !== undefined) {
|
|
1216
|
+
return yield* forbidden(contract.name, "A MAKE action cannot be written through sync");
|
|
1217
|
+
}
|
|
1218
|
+
// A replay commits nothing but its own record: it never reaches a stage that holds calls.
|
|
1219
|
+
const replayOnly = request.sequence?.kind === "replay";
|
|
1220
|
+
// What would make the call fail anyway is refused before it is held (an approved call's execution is
|
|
1221
|
+
// checked by its handler).
|
|
1222
|
+
const precheck = Option.isSome(prechecks) ? prechecks.value.checks.get(contract.name) : undefined;
|
|
1223
|
+
const executingApproved = request.identity !== undefined && request.approval !== undefined;
|
|
1224
|
+
if (precheck !== undefined && !replayOnly && !executingApproved)
|
|
1225
|
+
yield* precheck(actor, decoded);
|
|
1226
|
+
const approval = replayOnly
|
|
1227
|
+
? { _tag: "Approved" }
|
|
1228
|
+
: yield* approvals.check({
|
|
1229
|
+
actor,
|
|
1230
|
+
action: contract.name,
|
|
1231
|
+
title: contract.title,
|
|
1232
|
+
input: encoded,
|
|
1233
|
+
inputHash: context.inputHash,
|
|
1234
|
+
surface: request.surface,
|
|
1235
|
+
session,
|
|
1236
|
+
idempotencyKey: request.idempotencyKey,
|
|
1237
|
+
consent: contract.consent,
|
|
1238
|
+
consentEachCall: contract.consentEachCall,
|
|
1239
|
+
provenance: provenanceOf(request, origin, session, credential, chain),
|
|
1240
|
+
// A request it records is created under the call's whole chain, the person's session included,
|
|
1241
|
+
// asserted in the transaction that records it; what it records (`provenance`) drops the session.
|
|
1242
|
+
held: { chain, who: actor, scope: credential.scope, recurring: recurringWork },
|
|
1243
|
+
approval: request.identity !== undefined ? request.approval : undefined,
|
|
1244
|
+
});
|
|
1245
|
+
if (approval._tag === "Pending") {
|
|
1246
|
+
return yield* new ApprovalRequired({
|
|
1247
|
+
action: contract.name,
|
|
1248
|
+
approvalId: approval.approvalId,
|
|
1249
|
+
message: approval.reason,
|
|
1250
|
+
});
|
|
1251
|
+
}
|
|
1252
|
+
if (approval._tag === "ConsentPending") {
|
|
1253
|
+
return yield* new ConsentRequired({
|
|
1254
|
+
action: contract.name,
|
|
1255
|
+
consentId: approval.consentId,
|
|
1256
|
+
message: approval.reason,
|
|
1257
|
+
});
|
|
1258
|
+
}
|
|
1259
|
+
if (approval._tag === "Refused")
|
|
1260
|
+
return yield* forbidden(contract.name, approval.reason);
|
|
1261
|
+
// What the call acts under: its chain, and the consent that let an agent's call through (Authority). A
|
|
1262
|
+
// one-time consent it runs under is used up as it commits (`consume`, after its idempotency claim).
|
|
1263
|
+
const basis = approval._tag === "Approved" ? approval.consent : undefined;
|
|
1264
|
+
const consents = basis?.request === undefined ? [] : [basis.request];
|
|
1265
|
+
const acting = extend(chain.filter((link) => !(link.kind === "consent-request" && consents.includes(link.id))), basis?.permission === undefined ? [] : [{ kind: "consent-permission", id: basis.permission }]);
|
|
1266
|
+
context.lineage = lineageOf(request, origin, credential, acting, basis);
|
|
1267
|
+
const encodeOutput = (value) => asModuleCode(Schema.encodeUnknownEffect(contract.output)(value));
|
|
1268
|
+
const key = request.idempotencyKey;
|
|
1269
|
+
// An insert a client may predict (its optimistic effect): the record's key is derived from the key the
|
|
1270
|
+
// caller named, or a fresh one, for this actor, on every surface, so the client's prediction and the
|
|
1271
|
+
// handler arrive at the same record and no caller ever chooses a record's key outright.
|
|
1272
|
+
const keyed = withRecordKey(registered, decoded, actor);
|
|
1273
|
+
if (!keyed.ok)
|
|
1274
|
+
return yield* new InvalidInput({ message: keyed.message });
|
|
1275
|
+
const input = keyed.input;
|
|
1276
|
+
// A MAKE action (see `executeMakeAction`): its writes commit in its module's own transaction, inside the
|
|
1277
|
+
// kernel transaction that holds its authority. A top-level call is admitted within its organisation's bounds
|
|
1278
|
+
// before it takes any connection or interpreter; a nested one runs within its caller's.
|
|
1279
|
+
if (make !== undefined) {
|
|
1280
|
+
const guard = request.identity !== undefined ? request.guard : undefined;
|
|
1281
|
+
const nested = request.identity !== undefined && request.provenance !== undefined;
|
|
1282
|
+
// The call's authority, held by a kernel transaction that encloses the module's: asserted (its links
|
|
1283
|
+
// locked FOR SHARE, in the global order, before anything else of the call), its one-time consent used up
|
|
1284
|
+
// (locked FOR UPDATE here, its use recorded in the module's transaction, so it commits with the call), its
|
|
1285
|
+
// clock read again before the module's commit; this transaction commits after the module's, so a
|
|
1286
|
+
// revocation waits for the call, or is seen by it. A key another call holds rolls it back (nothing used).
|
|
1287
|
+
// A lock conflict that aborted it before the module's commit runs it again (after the module committed,
|
|
1288
|
+
// nothing in this transaction can conflict: it only commits).
|
|
1289
|
+
const taken = { _tag: "MakeKeyTaken" };
|
|
1290
|
+
const run = retryingConflicts(sql.withTransaction(Effect.gen(function* () {
|
|
1291
|
+
// A run again after a conflict rolled the last one back: it has not begun committing.
|
|
1292
|
+
if (context.acted === "committing")
|
|
1293
|
+
context.acted = undefined;
|
|
1294
|
+
let asserted = yield* authority.assert({
|
|
1295
|
+
chain: acting,
|
|
1296
|
+
who: actor,
|
|
1297
|
+
scope: credential.scope,
|
|
1298
|
+
recurring: recurringWork,
|
|
1299
|
+
});
|
|
1300
|
+
// A cancelled run's call never starts (and the guard is held again over the commit).
|
|
1301
|
+
if (guard !== undefined)
|
|
1302
|
+
yield* guard;
|
|
1303
|
+
if (consents.length > 0) {
|
|
1304
|
+
asserted = yield* authority.consume(asserted, consents, {
|
|
1305
|
+
invocationId: context.invocationId,
|
|
1306
|
+
recordedBy: "make",
|
|
1307
|
+
});
|
|
1308
|
+
}
|
|
1309
|
+
// The module's version, held (shared) until this transaction commits, which is after the module's:
|
|
1310
|
+
// a version change waits for the call, and a call the change overtook while it was admitted or
|
|
1311
|
+
// waited runs nothing of the version it looked up. A nested call never waits for it.
|
|
1312
|
+
const runtime = Option.getOrThrow(makeRuntime);
|
|
1313
|
+
const current = yield* runtime.holdVersion(registered.module.contract.name, { wait: !nested });
|
|
1314
|
+
if (current === VERSION_BUSY) {
|
|
1315
|
+
return yield* new ActionFailed({
|
|
1316
|
+
action: contract.name,
|
|
1317
|
+
message: `${registered.module.contract.name} is changing version; try again shortly`,
|
|
1318
|
+
});
|
|
1319
|
+
}
|
|
1320
|
+
if (current?.make?.hash !== make.hash || current.make.orgId !== make.orgId) {
|
|
1321
|
+
return yield* new ActionFailed({
|
|
1322
|
+
action: contract.name,
|
|
1323
|
+
message: `${registered.module.contract.name} changed version while this call waited; call it again`,
|
|
1324
|
+
});
|
|
1325
|
+
}
|
|
1326
|
+
const executed = yield* executeMakeAction(registered, actor, context, decoded, encoded, key, {
|
|
1327
|
+
origin,
|
|
1328
|
+
session,
|
|
1329
|
+
receipt: key === undefined ? undefined : provenanceFor(request, context.invocationId, key, origin),
|
|
1330
|
+
}, { nested, guard }, { scope: credential.scope === null ? null : [...credential.scope], chain: acting }, { asserted, consumes: consents });
|
|
1331
|
+
if (executed.kind === "taken")
|
|
1332
|
+
return yield* Effect.fail(taken);
|
|
1333
|
+
return executed;
|
|
1334
|
+
}))).pipe(Effect.catchIf((e) => e === taken, () => Effect.succeed({ kind: "taken" })), Effect.catchIf((e) => SqlError.isSqlError(e), (e) => Effect.die(e)));
|
|
1335
|
+
const executed = nested
|
|
1336
|
+
? yield* run
|
|
1337
|
+
: yield* Option.getOrThrow(makeRuntime).admit(registered.module, actor, contract.name, run);
|
|
1338
|
+
if (executed.kind === "done")
|
|
1339
|
+
return executed.result;
|
|
1340
|
+
// The key is another call's (which has committed): answered below with its receipt.
|
|
1341
|
+
}
|
|
1342
|
+
// 4-7. Idempotency, execute, record checks, audit and outbox in one transaction (a MAKE draft, preview or view
|
|
1343
|
+
// step, which runs untrusted code in the sandbox, admitted first, before its transaction takes a connection:
|
|
1344
|
+
// see `MakeRuntime.admitLifecycle`).
|
|
1345
|
+
const admitted = (effect) => Option.isSome(makeRuntime) &&
|
|
1346
|
+
isKernelProvided(registered.module) &&
|
|
1347
|
+
(contract.name === "make.draft" || contract.name === "make.preview" || contract.name === "make.renderView")
|
|
1348
|
+
? makeRuntime.value.admitLifecycle(actor, contract.name, effect)
|
|
1349
|
+
: effect;
|
|
1350
|
+
// A lock conflict the database resolved by aborting this transaction (it rolled back whole) runs it again.
|
|
1351
|
+
return yield* admitted(retryingConflicts(sql.withTransaction(Effect.gen(function* () {
|
|
1352
|
+
// A run again after a conflict rolled the last one back: it has not begun committing.
|
|
1353
|
+
if (context.acted === "committing")
|
|
1354
|
+
context.acted = undefined;
|
|
1355
|
+
// Authority: every link of the call's chain (and the person's membership) holds, its row locked,
|
|
1356
|
+
// before the call reads or writes any protected data (and before its invocation context is set:
|
|
1357
|
+
// consent links are read as that module). The capability it returns is what the handler runs with.
|
|
1358
|
+
// Links first, then the rows they protect (the lock order: the run's row the guard holds included).
|
|
1359
|
+
let asserted = yield* authority.assert({
|
|
1360
|
+
chain: acting,
|
|
1361
|
+
who: actor,
|
|
1362
|
+
scope: credential.scope,
|
|
1363
|
+
recurring: recurringWork,
|
|
1364
|
+
});
|
|
1365
|
+
if (request.identity !== undefined && request.guard !== undefined)
|
|
1366
|
+
yield* request.guard;
|
|
1367
|
+
if (request.sequence?.kind === "next")
|
|
1368
|
+
yield* request.sequence.advance;
|
|
1369
|
+
// The context row-level security reads: who acts, where, for which action (not forgeable by modules).
|
|
1370
|
+
const group = request.identity !== undefined ? (request.editGroup ?? null) : null;
|
|
1371
|
+
const setContext = sql `INSERT INTO eloxiv.invocation_context
|
|
1372
|
+
(actor, org, action, agent_run, agent_conversation, agent_message, namespace)
|
|
1373
|
+
VALUES (${actor.userId}, ${actor.orgId}, ${contract.name}, ${group?.runId ?? null},
|
|
1374
|
+
${group?.conversationId ?? null}, ${group?.messageId ?? null},
|
|
1375
|
+
${registered.module.contract.cedarNamespace})
|
|
1376
|
+
ON CONFLICT (xid) DO UPDATE SET actor = EXCLUDED.actor, org = EXCLUDED.org, action = EXCLUDED.action,
|
|
1377
|
+
agent_run = EXCLUDED.agent_run, agent_conversation = EXCLUDED.agent_conversation,
|
|
1378
|
+
agent_message = EXCLUDED.agent_message, namespace = EXCLUDED.namespace`.pipe(Effect.orDie);
|
|
1379
|
+
yield* setContext;
|
|
1380
|
+
const clearContext = Effect.all([
|
|
1381
|
+
sql `DELETE FROM eloxiv.invocation_context WHERE xid = pg_current_xact_id()`,
|
|
1382
|
+
sql `DELETE FROM eloxiv.invocation_target WHERE xid = pg_current_xact_id()`,
|
|
1383
|
+
]).pipe(Effect.asVoid, Effect.orDie);
|
|
1384
|
+
if (key !== undefined) {
|
|
1385
|
+
const claimed = yield* sql `
|
|
1386
|
+
INSERT INTO eloxiv.idempotency_key (org_id, actor_user_id, action, key, request_hash, invocation_id)
|
|
1387
|
+
VALUES (${actor.orgId}, ${actor.userId}, ${contract.name}, ${key}, ${context.inputHash}, ${context.invocationId})
|
|
1388
|
+
ON CONFLICT DO NOTHING RETURNING 1 AS claimed`.pipe(Effect.orDie);
|
|
1389
|
+
if (claimed.length === 0) {
|
|
1390
|
+
const [previous] = yield* sql `
|
|
1391
|
+
SELECT request_hash AS "requestHash", receipt, receipt_format AS "receiptFormat"
|
|
1392
|
+
FROM eloxiv.idempotency_key
|
|
1393
|
+
WHERE org_id = ${actor.orgId} AND actor_user_id = ${actor.userId} AND action = ${contract.name} AND key = ${key}`.pipe(Effect.orDie);
|
|
1394
|
+
if (!previous || previous.requestHash !== context.inputHash) {
|
|
1395
|
+
return yield* new IdempotencyConflict({
|
|
1396
|
+
key,
|
|
1397
|
+
message: "The idempotency key was used with a different request",
|
|
1398
|
+
});
|
|
1399
|
+
}
|
|
1400
|
+
if (previous.receipt === null || previous.receiptFormat !== RECEIPT_FORMAT) {
|
|
1401
|
+
return yield* new IdempotencyConflict({
|
|
1402
|
+
key,
|
|
1403
|
+
message: "The idempotency key's receipt was stored in an older format; use a new key",
|
|
1404
|
+
});
|
|
1405
|
+
}
|
|
1406
|
+
// This call may have waited on the first execution's claim: authenticate again (the same user, still
|
|
1407
|
+
// a member of the same organisation) and re-check the action's policy immediately before release.
|
|
1408
|
+
const { actor: current, credential: currentCredential } = yield* authenticate;
|
|
1409
|
+
if (!scopeAllows(currentCredential.scope, contract.name, permissionActions)) {
|
|
1410
|
+
return yield* forbidden(contract.name, "The credential is not scoped to this action");
|
|
1411
|
+
}
|
|
1412
|
+
if (current.userId !== actor.userId || current.orgId !== actor.orgId) {
|
|
1413
|
+
return yield* forbidden(contract.name, "The caller's identity changed");
|
|
1414
|
+
}
|
|
1415
|
+
if (yield* denies(current))
|
|
1416
|
+
return yield* forbidden(contract.name, "Policy denies this action");
|
|
1417
|
+
// A deferred call's credentials still hold, and are held until this replay is released.
|
|
1418
|
+
// A replay returns the receipt, never the output: see `InvocationReceipt` for what it may hold.
|
|
1419
|
+
const replay = { kind: "replay", receipt: previous.receipt };
|
|
1420
|
+
yield* writeAudit(context, "replayed", undefined, previous.receipt.completion ?? undefined);
|
|
1421
|
+
yield* clearContext;
|
|
1422
|
+
yield* authority.confirm(asserted);
|
|
1423
|
+
return {
|
|
1424
|
+
invocationId: context.invocationId,
|
|
1425
|
+
replayed: true,
|
|
1426
|
+
output: undefined,
|
|
1427
|
+
envelope: replay,
|
|
1428
|
+
encoded: replay,
|
|
1429
|
+
};
|
|
1430
|
+
}
|
|
1431
|
+
}
|
|
1432
|
+
if (replayOnly) {
|
|
1433
|
+
return yield* new IdempotencyConflict({
|
|
1434
|
+
key: key ?? "",
|
|
1435
|
+
message: "The call was already answered and left no receipt to replay",
|
|
1436
|
+
});
|
|
1437
|
+
}
|
|
1438
|
+
if (make !== undefined) {
|
|
1439
|
+
// A MAKE action never runs here: its call ran (and committed) above, or its key is another's.
|
|
1440
|
+
return yield* new IdempotencyConflict({
|
|
1441
|
+
key: key ?? "",
|
|
1442
|
+
message: "The idempotency key is in use; try again",
|
|
1443
|
+
});
|
|
1444
|
+
}
|
|
1445
|
+
// The call runs (it is not a replay): the one-time consent it runs under is used up with it, and the
|
|
1446
|
+
// context is set again (the consent module's tables are written as that module).
|
|
1447
|
+
if (consents.length > 0) {
|
|
1448
|
+
asserted = yield* authority.consume(asserted, consents, {
|
|
1449
|
+
invocationId: context.invocationId,
|
|
1450
|
+
recordedBy: "this transaction",
|
|
1451
|
+
});
|
|
1452
|
+
yield* setContext;
|
|
1453
|
+
}
|
|
1454
|
+
const capability = asserted;
|
|
1455
|
+
const executed = yield* Effect.gen(function* () {
|
|
1456
|
+
const targets = yield* authoriseTargets(actor, registered, input);
|
|
1457
|
+
// Still holding by the clock now, after any wait for the targets (the rows are held since the
|
|
1458
|
+
// assertion).
|
|
1459
|
+
yield* authority.recheck(capability);
|
|
1460
|
+
const ran = yield* execute(registered, actor, context.invocationId, input, origin, context, capability, {
|
|
1461
|
+
kind: credential.kind,
|
|
1462
|
+
id: credential.id,
|
|
1463
|
+
session: session?.id ?? null,
|
|
1464
|
+
});
|
|
1465
|
+
const checked = yield* authoriseWrites(actor, registered, targets, ran.revertDeletes);
|
|
1466
|
+
context.changes = changesOf(checked.log);
|
|
1467
|
+
// Counted while the session still acts as the caller: row-level security reads with it.
|
|
1468
|
+
const written = yield* writtenOf(actor, registered, checked.log);
|
|
1469
|
+
// Record history (the Versioning contract): a version per changed record of a history entity.
|
|
1470
|
+
if (Option.isSome(versioning) && versioning.value.byTable.size > 0) {
|
|
1471
|
+
yield* versioning.value.record(sql, checked.log, {
|
|
1472
|
+
orgId: actor.orgId,
|
|
1473
|
+
actorUserId: actor.userId,
|
|
1474
|
+
action: contract.name,
|
|
1475
|
+
invocationId: context.invocationId,
|
|
1476
|
+
editGroup: group,
|
|
1477
|
+
revertGroups: ran.revertGroups,
|
|
1478
|
+
});
|
|
1479
|
+
}
|
|
1480
|
+
// The kernel's own writes for the handler (work items, notifications), as the system actor.
|
|
1481
|
+
yield* ran.kernelWrites;
|
|
1482
|
+
// Work-item titles copied from records this call wrote follow them.
|
|
1483
|
+
yield* workItems.followRecords(registered.module.contract.name, actor.orgId, checked.log);
|
|
1484
|
+
return {
|
|
1485
|
+
output: ran.output,
|
|
1486
|
+
events: ran.events,
|
|
1487
|
+
...checked,
|
|
1488
|
+
requested: targets?.requested,
|
|
1489
|
+
effectIds: ran.effectIds,
|
|
1490
|
+
written,
|
|
1491
|
+
};
|
|
1492
|
+
});
|
|
1493
|
+
const { events, created, completion, written } = executed;
|
|
1494
|
+
// Best effort: the kernel, not the handler, reports what was affected; an untargeted write that
|
|
1495
|
+
// reports what it wrote, likewise.
|
|
1496
|
+
const output = contract.bestEffort && completion !== undefined
|
|
1497
|
+
? { ...executed.output, ...completion }
|
|
1498
|
+
: contract.reportsWritten && written !== undefined
|
|
1499
|
+
? { ...executed.output, written }
|
|
1500
|
+
: executed.output;
|
|
1501
|
+
// An output that does not match the action's contract fails the call, which rolls back whole: its
|
|
1502
|
+
// writes, its events and the effects it scheduled. Why it does not match is logged, never returned
|
|
1503
|
+
// (the output may hold what the handler read).
|
|
1504
|
+
const encodedOutput = yield* encodeOutput(output).pipe(Effect.catch((e) => Effect.logError(`The output of ${contract.name} does not match its contract`, e).pipe(Effect.andThen(Effect.fail(new ActionFailed({
|
|
1505
|
+
action: contract.name,
|
|
1506
|
+
message: "The action's output does not match its contract; nothing it did was kept",
|
|
1507
|
+
}))))));
|
|
1508
|
+
yield* writeAudit(context, "succeeded", undefined, completion);
|
|
1509
|
+
// The events, in the call's transaction.
|
|
1510
|
+
for (const { event, payload } of events) {
|
|
1511
|
+
const encodedPayload = yield* asModuleCode(Schema.encodeUnknownEffect(event.payload)(payload)).pipe(Effect.orDie);
|
|
1512
|
+
yield* outbox.publish({
|
|
1513
|
+
invocationId: context.invocationId,
|
|
1514
|
+
type: event.type,
|
|
1515
|
+
module: registered.module.contract.name,
|
|
1516
|
+
orgId: actor.orgId,
|
|
1517
|
+
payload: encodedPayload,
|
|
1518
|
+
});
|
|
1519
|
+
}
|
|
1520
|
+
if (key !== undefined) {
|
|
1521
|
+
// The receipt names, by reference (never their payload), every event the call committed: those its
|
|
1522
|
+
// handler emitted and those the kernel published for it (a file's upload, a scheduled effect).
|
|
1523
|
+
const published = (yield* sql `
|
|
1524
|
+
SELECT id::text AS id, type, module FROM eloxiv.outbox
|
|
1525
|
+
WHERE invocation_id = ${context.invocationId} ORDER BY seq`.pipe(Effect.orDie)).map((row) => ({
|
|
1526
|
+
specversion: "1.0",
|
|
1527
|
+
id: row.id,
|
|
1528
|
+
source: `/modules/${row.module}`,
|
|
1529
|
+
type: row.type,
|
|
1530
|
+
}));
|
|
1531
|
+
// Only what the caller already had: the target ids it supplied; ids of records of the action's
|
|
1532
|
+
// entity this call inserted *and* its output named; best-effort counts (never which targets);
|
|
1533
|
+
// what an untargeted write wrote (counts); the events it committed and where it came from (ids).
|
|
1534
|
+
const named = valuesIn(encodedOutput);
|
|
1535
|
+
const receipt = {
|
|
1536
|
+
version: RECEIPT_VERSION,
|
|
1537
|
+
action: contract.name,
|
|
1538
|
+
invocationId: context.invocationId,
|
|
1539
|
+
outcome: "succeeded",
|
|
1540
|
+
targets: executed.requested ?? [],
|
|
1541
|
+
created: created
|
|
1542
|
+
.filter((r) => r.entity === registered.writes?.cedarType && named.has(r.pk))
|
|
1543
|
+
.map((r) => r.pk),
|
|
1544
|
+
...(executed.effectIds.length === 0 ? {} : { effects: executed.effectIds }),
|
|
1545
|
+
...(isNoOp(encodedOutput) ? { noop: encodedOutput } : {}),
|
|
1546
|
+
completion: contract.bestEffort ? (completion ?? null) : null,
|
|
1547
|
+
events: published,
|
|
1548
|
+
provenance: provenanceFor(request, context.invocationId, key, origin),
|
|
1549
|
+
...(written === undefined ? {} : { written }),
|
|
1550
|
+
};
|
|
1551
|
+
yield* sql `UPDATE eloxiv.idempotency_key
|
|
1552
|
+
SET receipt = ${JSON.stringify(receipt)}::jsonb, receipt_format = ${RECEIPT_FORMAT}
|
|
1553
|
+
WHERE org_id = ${actor.orgId} AND actor_user_id = ${actor.userId} AND action = ${contract.name} AND key = ${key}`.pipe(Effect.orDie);
|
|
1554
|
+
}
|
|
1555
|
+
yield* clearContext;
|
|
1556
|
+
// The check at commit, the transaction's last statement: the call's session and tokens still valid
|
|
1557
|
+
// by the clock, its session not revoked (Authority.confirm). Otherwise it commits nothing.
|
|
1558
|
+
yield* authority.confirm(capability);
|
|
1559
|
+
// From here the transaction commits: a failure now may come after the commit took effect.
|
|
1560
|
+
context.acted ??= "committing";
|
|
1561
|
+
return {
|
|
1562
|
+
invocationId: context.invocationId,
|
|
1563
|
+
replayed: false,
|
|
1564
|
+
output,
|
|
1565
|
+
envelope: { kind: "output", output },
|
|
1566
|
+
encoded: { kind: "output", output: encodedOutput },
|
|
1567
|
+
...(executed.effectIds.length === 0 ? {} : { effects: executed.effectIds }),
|
|
1568
|
+
};
|
|
1569
|
+
}))));
|
|
1570
|
+
});
|
|
1571
|
+
const invoke = (request) => Effect.gen(function* () {
|
|
1572
|
+
const started = Date.now();
|
|
1573
|
+
const context = {
|
|
1574
|
+
invocationId: crypto.randomUUID(),
|
|
1575
|
+
action: request.action,
|
|
1576
|
+
surface: request.surface,
|
|
1577
|
+
inputHash: yield* hashOf("decoded" in request.input ? request.input.decoded : request.input.encoded),
|
|
1578
|
+
idempotencyKey: request.idempotencyKey,
|
|
1579
|
+
actor: undefined,
|
|
1580
|
+
// The client address the kernel's HTTP layer determined (CookieGuard), for bounding anonymous refusals.
|
|
1581
|
+
address: request.identity === undefined ? (request.headers.get(CLIENT_ADDRESS_HEADER) ?? undefined) : undefined,
|
|
1582
|
+
events: [],
|
|
1583
|
+
};
|
|
1584
|
+
const exit = yield* Effect.exit(body(request, context).pipe(Effect.catchTag("SqlError", (e) => Effect.die(e)), Effect.tap((result) => result.replayed
|
|
1585
|
+
? Effect.void
|
|
1586
|
+
: invocationHooks.afterCommit({ action: request.action, idempotencyKey: request.idempotencyKey }))));
|
|
1587
|
+
// Telemetry: the span's attributes (ids and tags only), the call's metrics.
|
|
1588
|
+
const outcomeOf = Exit.isSuccess(exit)
|
|
1589
|
+
? exit.value.replayed
|
|
1590
|
+
? "replayed"
|
|
1591
|
+
: "succeeded"
|
|
1592
|
+
: Cause.hasInterruptsOnly(exit.cause)
|
|
1593
|
+
? "interrupted"
|
|
1594
|
+
: "failed";
|
|
1595
|
+
const errorTag = Exit.isFailure(exit)
|
|
1596
|
+
? Option.match(Cause.findErrorOption(exit.cause), {
|
|
1597
|
+
onNone: () => "Defect",
|
|
1598
|
+
onSome: (e) => e._tag,
|
|
1599
|
+
})
|
|
1600
|
+
: undefined;
|
|
1601
|
+
// Declared values only: a name the caller sent that no module registered is `unknown`.
|
|
1602
|
+
const registered = registry.actions.get(request.action);
|
|
1603
|
+
const action = registered === undefined ? "unknown" : request.action;
|
|
1604
|
+
yield* Effect.annotateCurrentSpan({
|
|
1605
|
+
"eloxiv.outcome": outcomeOf,
|
|
1606
|
+
...(errorTag === undefined ? {} : { "eloxiv.error_tag": errorTag }),
|
|
1607
|
+
...(context.origin === undefined ? {} : { "eloxiv.origin": context.origin }),
|
|
1608
|
+
"eloxiv.module": registered === undefined ? "unknown" : registered.module.contract.name,
|
|
1609
|
+
});
|
|
1610
|
+
const series = { action, surface: request.surface, outcome: outcomeOf };
|
|
1611
|
+
yield* Metric.update(Metric.withAttributes(invocationMetrics.calls, series), 1);
|
|
1612
|
+
yield* Metric.update(Metric.withAttributes(invocationMetrics.duration, series), Date.now() - started);
|
|
1613
|
+
if (Exit.isSuccess(exit)) {
|
|
1614
|
+
// Product analytics, now the call has committed: the kernel's own event for a person's or their
|
|
1615
|
+
// agent's call, and what the handler asked for. Consent is checked when they leave.
|
|
1616
|
+
if (analyticsOn && Option.isSome(analytics) && context.actor !== undefined && context.origin !== "system") {
|
|
1617
|
+
const actor = context.actor;
|
|
1618
|
+
if (!exit.value.replayed && actor.userId !== SYSTEM_ACTOR) {
|
|
1619
|
+
const own = yield* analytics.value
|
|
1620
|
+
.prepare("eloxiv", actor, {
|
|
1621
|
+
event: ACTION_INVOKED_EVENT,
|
|
1622
|
+
properties: {
|
|
1623
|
+
action: request.action,
|
|
1624
|
+
surface: request.surface,
|
|
1625
|
+
origin: context.origin ?? "person",
|
|
1626
|
+
duration_ms: Date.now() - started,
|
|
1627
|
+
},
|
|
1628
|
+
})
|
|
1629
|
+
.pipe(Effect.orElseSucceed(() => null));
|
|
1630
|
+
if (own !== null)
|
|
1631
|
+
yield* analytics.value.enqueue(own);
|
|
1632
|
+
}
|
|
1633
|
+
for (const event of context.events)
|
|
1634
|
+
yield* analytics.value.enqueue(event);
|
|
1635
|
+
}
|
|
1636
|
+
return exit.value;
|
|
1637
|
+
}
|
|
1638
|
+
if (Cause.hasInterruptsOnly(exit.cause))
|
|
1639
|
+
return yield* Effect.failCause(exit.cause);
|
|
1640
|
+
const failure = Cause.findErrorOption(exit.cause);
|
|
1641
|
+
if (Option.isNone(failure)) {
|
|
1642
|
+
// A defect outside the handler (the kernel's own code, the database): the caller and error telemetry get
|
|
1643
|
+
// its tag and the invocation's id only, and the kernel's log its cause under that id (a database refusal
|
|
1644
|
+
// such as a module role the kernel's role may no longer take), so an operator can find what failed.
|
|
1645
|
+
yield* Effect.logError(`The call of ${request.action} failed unexpectedly (invocation ${context.invocationId})`, exit.cause);
|
|
1646
|
+
yield* capture(context.invocationId);
|
|
1647
|
+
}
|
|
1648
|
+
const found = Option.isSome(failure)
|
|
1649
|
+
? failure.value
|
|
1650
|
+
: new ActionFailed({
|
|
1651
|
+
action: request.action,
|
|
1652
|
+
message: `The call failed unexpectedly (invocation ${context.invocationId})`,
|
|
1653
|
+
});
|
|
1654
|
+
// A failure says what the call may have done (C-011): nothing kept, or possibly something. The kernel decides
|
|
1655
|
+
// it from what it saw, whatever a handler's own `ActionFailed` said.
|
|
1656
|
+
const error = found._tag === "ActionFailed"
|
|
1657
|
+
? new ActionFailed({
|
|
1658
|
+
action: found.action,
|
|
1659
|
+
message: found.message,
|
|
1660
|
+
effect: context.acted === undefined ? "none" : "unknown",
|
|
1661
|
+
})
|
|
1662
|
+
: found;
|
|
1663
|
+
// The transaction (if any) has rolled back with any audit row it held: record the failure exactly once.
|
|
1664
|
+
const outcome = error._tag === "Forbidden" || error._tag === "Unauthenticated" || error._tag === "ClientOutdated"
|
|
1665
|
+
? "denied"
|
|
1666
|
+
: error._tag === "ApprovalRequired" || error._tag === "ConsentRequired"
|
|
1667
|
+
? "approval-required"
|
|
1668
|
+
: "failed";
|
|
1669
|
+
yield* writeAudit(context, outcome, error._tag);
|
|
1670
|
+
return yield* Effect.fail(error);
|
|
1671
|
+
}).pipe(Effect.withSpan("Invocation.invoke", {
|
|
1672
|
+
attributes: { "eloxiv.action": request.action, "eloxiv.surface": request.surface },
|
|
1673
|
+
}));
|
|
1674
|
+
const receiptFor = (asserted, action, key) => authority.bound(asserted, asserted.who).pipe(Effect.andThen(sql `SELECT receipt FROM eloxiv.idempotency_key
|
|
1675
|
+
WHERE org_id = ${asserted.who.orgId} AND actor_user_id = ${asserted.who.userId} AND action = ${action}
|
|
1676
|
+
AND key = ${key} AND receipt IS NOT NULL`), Effect.map(([row]) => row?.receipt ?? null), Effect.orDie);
|
|
1677
|
+
return Invocation.of({ invoke, reach, receiptFor });
|
|
1678
|
+
}));
|
|
1679
|
+
}
|
|
1680
|
+
//# sourceMappingURL=Invocation.js.map
|