@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,1633 @@
|
|
|
1
|
+
import { capabilityContracts, Conflict, Forbidden, InvalidCursor, InvalidInput, NotFound, ProviderForbidden, RateLimited, Unauthorized, Unavailable, serviceContracts, } from "@eloxiv/contracts";
|
|
2
|
+
import { Context, Deferred, Effect, Exit, Layer, Redacted, Schema } from "effect";
|
|
3
|
+
import { HttpRouter, HttpServerRequest, HttpServerResponse } from "effect/http";
|
|
4
|
+
import { SqlClient } from "effect/sql";
|
|
5
|
+
import { createHash, createHmac, randomBytes } from "node:crypto";
|
|
6
|
+
import { connectionsConfig, KernelConfig } from "../Config.js";
|
|
7
|
+
import { canonicalJson } from "../Hash.js";
|
|
8
|
+
import { redactSecrets } from "../Redact.js";
|
|
9
|
+
import { Identity } from "../Identity.js";
|
|
10
|
+
import { asModuleCode } from "../KernelModule.js";
|
|
11
|
+
import { Notifications } from "../Notifications.js";
|
|
12
|
+
import { toWebHeaders } from "../surfaces/headers.js";
|
|
13
|
+
import { connectScopes, } from "./Connector.js";
|
|
14
|
+
import { checkDestination, pinnedFetch } from "./Destinations.js";
|
|
15
|
+
import { discoverClient, fetchJson } from "./Discovery.js";
|
|
16
|
+
import { ConnectionMetering, defaultConnectionLimits } from "./Metering.js";
|
|
17
|
+
import { SECRETS_MANAGE, Secrets } from "./Secrets.js";
|
|
18
|
+
import { channelSpend } from "../agent/Channels.js";
|
|
19
|
+
export const CONNECTIONS_MANAGE = "eloxiv.connections.manage";
|
|
20
|
+
/** A channel with no settings row: the agent answers, may act, without a budget, one conversation per thread. */
|
|
21
|
+
export const CHANNEL_DEFAULTS = { enabled: true, scope: "act", dailyTokens: null, memory: "thread" };
|
|
22
|
+
export const CALLBACK_PATH = "/connections/callback";
|
|
23
|
+
export const AUTHORIZE_PATH = "/connections/authorize";
|
|
24
|
+
/** The adapter seam for external custody. The default keeps tokens in the kernel's Secrets. */
|
|
25
|
+
export class TokenCustody extends Context.Service()("@eloxiv/kernel/TokenCustody") {
|
|
26
|
+
static secrets = Layer.effect(TokenCustody, Effect.gen(function* () {
|
|
27
|
+
const secrets = yield* Secrets;
|
|
28
|
+
const scope = (connection) => ({
|
|
29
|
+
kind: "connection",
|
|
30
|
+
orgId: connection.orgId,
|
|
31
|
+
connectionId: connection.id,
|
|
32
|
+
});
|
|
33
|
+
const name = (which) => (which === "access" ? "access_token" : "refresh_token");
|
|
34
|
+
return TokenCustody.of({
|
|
35
|
+
load: (connection, which, access) => secrets.read(scope(connection), name(which), access).pipe(Effect.map((secret) => secret.value), Effect.catchTag("SecretNotFound", () => Effect.succeed(undefined)), Effect.mapError((e) => new Unavailable({ message: e.message, retryAfterMs: null }))),
|
|
36
|
+
save: (connection, tokens, access) => Effect.gen(function* () {
|
|
37
|
+
yield* secrets.put(scope(connection), "access_token", tokens.accessToken, access);
|
|
38
|
+
if (tokens.refreshToken !== undefined) {
|
|
39
|
+
yield* secrets.put(scope(connection), "refresh_token", tokens.refreshToken, access);
|
|
40
|
+
}
|
|
41
|
+
}).pipe(Effect.mapError((e) => new Unavailable({ message: e.message, retryAfterMs: null }))),
|
|
42
|
+
remove: (connection, access) => secrets.delete(scope(connection), undefined, access).pipe(Effect.asVoid),
|
|
43
|
+
});
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
46
|
+
// ---------------------------------------------------------------------------------------------------------------
|
|
47
|
+
/** The connectors an app installs (registry items of kind `connector`), with their deployment settings. */
|
|
48
|
+
export class Connectors extends Context.Service()("@eloxiv/kernel/Connectors") {
|
|
49
|
+
static layer = (connectors) => Layer.succeed(Connectors, { connectors: new Map(connectors.map((c) => [c.name, c])) });
|
|
50
|
+
}
|
|
51
|
+
const COLUMNS = `id, org_id AS "orgId", owner_id AS "ownerId", provider, account_id AS "accountId",
|
|
52
|
+
account_label AS "accountLabel", scopes, status, status_reason AS "statusReason",
|
|
53
|
+
access_expires_at AS "accessExpiresAt", token_version AS "tokenVersion", shared, endpoint, auth,
|
|
54
|
+
oauth_client AS "oauthClient", options, tools, created_at AS "createdAt", updated_at AS "updatedAt"`;
|
|
55
|
+
const iso = (value) => (value instanceof Date ? value.toISOString() : String(value));
|
|
56
|
+
const epoch = (value) => value === null || value === undefined
|
|
57
|
+
? undefined
|
|
58
|
+
: value instanceof Date
|
|
59
|
+
? value.getTime()
|
|
60
|
+
: typeof value === "string"
|
|
61
|
+
? Date.parse(value)
|
|
62
|
+
: undefined;
|
|
63
|
+
const toConnection = (row) => ({
|
|
64
|
+
id: row.id,
|
|
65
|
+
orgId: row.orgId,
|
|
66
|
+
ownerId: row.ownerId,
|
|
67
|
+
provider: row.provider,
|
|
68
|
+
accountId: row.accountId,
|
|
69
|
+
accountLabel: row.accountLabel,
|
|
70
|
+
scopes: [...row.scopes],
|
|
71
|
+
status: row.status,
|
|
72
|
+
statusReason: row.statusReason,
|
|
73
|
+
shared: row.shared,
|
|
74
|
+
endpoint: row.endpoint,
|
|
75
|
+
auth: row.auth?.kind ?? "oauth",
|
|
76
|
+
tools: row.tools === null ? null : [...row.tools],
|
|
77
|
+
createdAt: iso(row.createdAt),
|
|
78
|
+
updatedAt: iso(row.updatedAt),
|
|
79
|
+
});
|
|
80
|
+
const sha = (value) => createHash("sha256").update(value, "utf8").digest("hex");
|
|
81
|
+
export class Connections extends Context.Service()("@eloxiv/kernel/Connections") {
|
|
82
|
+
static layer = Layer.effect(Connections, Effect.gen(function* () {
|
|
83
|
+
const sql = yield* SqlClient.SqlClient;
|
|
84
|
+
const config = yield* KernelConfig;
|
|
85
|
+
const settings = connectionsConfig(config);
|
|
86
|
+
const identity = yield* Identity;
|
|
87
|
+
const custody = yield* TokenCustody;
|
|
88
|
+
const metering = yield* ConnectionMetering;
|
|
89
|
+
const notifications = yield* Notifications;
|
|
90
|
+
const { connectors } = yield* Connectors;
|
|
91
|
+
const secrets = yield* Secrets;
|
|
92
|
+
/** Where a destination someone chose may be: https to a public address, or a host the deployment allows. */
|
|
93
|
+
const policy = { allow: settings.outboundAllow };
|
|
94
|
+
// A destination someone chose is sent pinned: to the addresses its check resolved (Destinations.ts).
|
|
95
|
+
const pinned = pinnedFetch(policy);
|
|
96
|
+
// Refreshes run in the service's scope (see `refreshShared`), so a caller's interruption cannot cut one short.
|
|
97
|
+
const scope = yield* Effect.scope;
|
|
98
|
+
// ... and with the service's own context: never a caller's (its transaction, which a rollback would take the
|
|
99
|
+
// refresh's rotated refresh token with).
|
|
100
|
+
const serviceContext = yield* Effect.context();
|
|
101
|
+
const callbackUrl = `${config.baseUrl}${CALLBACK_PATH}`;
|
|
102
|
+
const authSecret = Redacted.value(config.authSecret);
|
|
103
|
+
const settingsOf = (name) => config.connectors?.[name] ?? {};
|
|
104
|
+
const connectorOf = (name) => connectors.get(name);
|
|
105
|
+
const normalize = (connector, scopes) => [...new Set(scopes.map((s) => (connector.normalizeScope ?? ((x) => x))(s)))].sort();
|
|
106
|
+
const limitsOf = (connector) => ({
|
|
107
|
+
...defaultConnectionLimits,
|
|
108
|
+
...connector.limits,
|
|
109
|
+
});
|
|
110
|
+
/** Audit a lifecycle event of the kernel's own (callback, needs-reauth, refresh failure). */
|
|
111
|
+
const audit = (action, actorUserId, orgId, outcome, detail, errorTag = null) => sql `INSERT INTO eloxiv.audit_log
|
|
112
|
+
(id, invocation_id, action, surface, actor_user_id, org_id, outcome, input_hash, idempotency_key, error_tag, detail)
|
|
113
|
+
VALUES (${crypto.randomUUID()}, ${crypto.randomUUID()}, ${action}, 'http', ${actorUserId}, ${orgId}, ${outcome},
|
|
114
|
+
${sha(canonicalJson(detail))}, NULL, ${errorTag}, ${JSON.stringify(detail)}::jsonb)`.pipe(Effect.asVoid, Effect.orDie);
|
|
115
|
+
const row = (connectionId) => sql `SELECT ${sql.unsafe(COLUMNS)} FROM eloxiv.connection WHERE id = ${connectionId}`.pipe(Effect.orDie, Effect.map((rows) => rows[0]));
|
|
116
|
+
// ------------------------------------------------------------------------------------------- consent
|
|
117
|
+
const SCOPE_OF_CAPABILITY = (connector, names) =>
|
|
118
|
+
// Scopes asked for only by incremental consent, when an operation needs them, are left out.
|
|
119
|
+
names.flatMap((name) => connectScopes(connector.capabilities[name]));
|
|
120
|
+
const safeReturnTo = (returnTo) => {
|
|
121
|
+
if (returnTo === undefined)
|
|
122
|
+
return null;
|
|
123
|
+
return returnTarget(config, returnTo);
|
|
124
|
+
};
|
|
125
|
+
const manages = (actor) => actor.permissions.includes(CONNECTIONS_MANAGE);
|
|
126
|
+
const clientFor = (connector, current) => Effect.gen(function* () {
|
|
127
|
+
if (connector.endpoint === undefined) {
|
|
128
|
+
try {
|
|
129
|
+
return { client: connector.oauth(settingsOf(connector.name)), resource: undefined, discovered: false };
|
|
130
|
+
}
|
|
131
|
+
catch (e) {
|
|
132
|
+
return yield* new InvalidInput({ message: e instanceof Error ? e.message : String(e) });
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
const stored = current?.oauthClient;
|
|
136
|
+
if (current === undefined || stored === null || stored === undefined) {
|
|
137
|
+
return yield* new InvalidInput({ message: "This Connection has no OAuth client: add it with auth oauth" });
|
|
138
|
+
}
|
|
139
|
+
let clientSecret = "";
|
|
140
|
+
if (stored.clientSecret !== null) {
|
|
141
|
+
const ref = stored.clientSecret;
|
|
142
|
+
const scope = ref.scope === "connection"
|
|
143
|
+
? { kind: "connection", orgId: current.orgId, connectionId: current.id }
|
|
144
|
+
: ref.scope === "user"
|
|
145
|
+
? { kind: "user", orgId: current.orgId, userId: current.ownerId }
|
|
146
|
+
: { kind: "org", orgId: current.orgId };
|
|
147
|
+
// The secret's own destinations, as they are now: it goes only to a token endpoint they allow.
|
|
148
|
+
const tokenOrigin = new URL(stored.tokenUrl).origin;
|
|
149
|
+
const [meta] = yield* sql `
|
|
150
|
+
SELECT allowed_origins AS "allowedOrigins" FROM eloxiv.secret
|
|
151
|
+
WHERE org_id = ${current.orgId} AND scope_kind = ${scope.kind}
|
|
152
|
+
AND subject = ${scope.kind === "org" ? "" : scope.kind === "user" ? scope.userId : scope.connectionId}
|
|
153
|
+
AND name = ${ref.name}`.pipe(Effect.orDie);
|
|
154
|
+
if (meta?.allowedOrigins != null && !meta.allowedOrigins.includes(tokenOrigin)) {
|
|
155
|
+
return yield* new InvalidInput({ message: `The OAuth client's secret may not be sent to ${tokenOrigin}` });
|
|
156
|
+
}
|
|
157
|
+
clientSecret = yield* secrets
|
|
158
|
+
.read(scope, ref.name, { actorUserId: null, purpose: "connection.client" })
|
|
159
|
+
.pipe(Effect.map((s) => s.value), Effect.mapError(() => new InvalidInput({ message: "The OAuth client's secret is gone" })));
|
|
160
|
+
}
|
|
161
|
+
return {
|
|
162
|
+
client: {
|
|
163
|
+
authorizeUrl: stored.authorizeUrl,
|
|
164
|
+
tokenUrl: stored.tokenUrl,
|
|
165
|
+
clientId: stored.clientId,
|
|
166
|
+
clientSecret,
|
|
167
|
+
baseScopes: stored.scopes,
|
|
168
|
+
},
|
|
169
|
+
resource: stored.resource,
|
|
170
|
+
discovered: true,
|
|
171
|
+
};
|
|
172
|
+
});
|
|
173
|
+
const start = (actor, request) => Effect.gen(function* () {
|
|
174
|
+
let provider = request.provider;
|
|
175
|
+
let existing;
|
|
176
|
+
if (request.connectionId !== undefined) {
|
|
177
|
+
existing = yield* row(request.connectionId);
|
|
178
|
+
const allowed = existing !== undefined &&
|
|
179
|
+
existing.orgId === actor.orgId &&
|
|
180
|
+
(existing.shared ? manages(actor) : existing.ownerId === actor.userId);
|
|
181
|
+
if (!allowed) {
|
|
182
|
+
return yield* new Forbidden({
|
|
183
|
+
action: "connections.reconnect",
|
|
184
|
+
message: "Not one of your Connections in this organisation (a shared one needs eloxiv.connections.manage)",
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
provider = existing.provider;
|
|
188
|
+
}
|
|
189
|
+
const shared = existing?.shared ?? request.shared === true;
|
|
190
|
+
if (shared && !manages(actor)) {
|
|
191
|
+
return yield* new Forbidden({
|
|
192
|
+
action: "connections.connect",
|
|
193
|
+
message: `Connecting for the organisation needs the ${CONNECTIONS_MANAGE} permission`,
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
const connector = provider === undefined ? undefined : connectorOf(provider);
|
|
197
|
+
if (connector === undefined) {
|
|
198
|
+
return yield* new InvalidInput({
|
|
199
|
+
message: `No connector ${provider ?? ""} is installed (installed: ${[...connectors.keys()].join(", ") || "none"})`,
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
if (connector.endpoint !== undefined && existing === undefined) {
|
|
203
|
+
return yield* new InvalidInput({ message: `${connector.name} Connections are added with connections.add` });
|
|
204
|
+
}
|
|
205
|
+
if (existing !== undefined && existing.auth !== null && existing.auth.kind !== "oauth") {
|
|
206
|
+
return yield* new InvalidInput({
|
|
207
|
+
message: "This Connection does not use OAuth: add it again (connections.add) to change how it authenticates",
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
for (const name of request.capabilities ?? []) {
|
|
211
|
+
if (connector.capabilities[name] === undefined) {
|
|
212
|
+
return yield* new InvalidInput({ message: `${connector.name} does not provide ${name}` });
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
const returnTo = safeReturnTo(request.returnTo);
|
|
216
|
+
if (returnTo === undefined) {
|
|
217
|
+
return yield* new InvalidInput({ message: "returnTo must be a path or a URL on a trusted origin" });
|
|
218
|
+
}
|
|
219
|
+
const { client } = yield* clientFor(connector, existing);
|
|
220
|
+
// Scopes named outright must be ones the connector declares: its base scopes and every capability's, those
|
|
221
|
+
// it leaves to incremental consent included. An endpoint connector's are its authorization server's to say.
|
|
222
|
+
if (connector.endpoint === undefined && request.scopes !== undefined && request.scopes.length > 0) {
|
|
223
|
+
const declared = new Set(normalize(connector, [
|
|
224
|
+
...client.baseScopes,
|
|
225
|
+
...Object.values(connector.capabilities).flatMap((c) => c === undefined
|
|
226
|
+
? []
|
|
227
|
+
: Object.values(c.scopes).flat()),
|
|
228
|
+
]));
|
|
229
|
+
const undeclared = normalize(connector, request.scopes).filter((scope) => !declared.has(scope));
|
|
230
|
+
if (undeclared.length > 0) {
|
|
231
|
+
return yield* new InvalidInput({
|
|
232
|
+
message: `${connector.name} does not declare the scopes ${undeclared.join(", ")}`,
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
// Incremental consent: ask again for what the Connection holds, plus what is new.
|
|
237
|
+
const scopes = normalize(connector, [
|
|
238
|
+
...client.baseScopes,
|
|
239
|
+
...(existing?.status === "disconnected" ? [] : (existing?.scopes ?? [])),
|
|
240
|
+
...SCOPE_OF_CAPABILITY(connector, request.capabilities ?? []),
|
|
241
|
+
...(request.scopes ?? []),
|
|
242
|
+
]);
|
|
243
|
+
return yield* recordFlow(actor, connector.name, existing?.id ?? null, scopes, returnTo, shared);
|
|
244
|
+
});
|
|
245
|
+
const recordFlow = (actor, provider, connectionId, scopes, returnTo, shared) => Effect.gen(function* () {
|
|
246
|
+
const flowId = `cf_${randomBytes(18).toString("base64url")}`;
|
|
247
|
+
const [flow] = yield* sql `
|
|
248
|
+
INSERT INTO eloxiv.connection_flow (id, org_id, user_id, provider, connection_id, scopes, return_to,
|
|
249
|
+
expires_at, shared)
|
|
250
|
+
VALUES (${flowId}, ${actor.orgId}, ${actor.userId}, ${provider}, ${connectionId},
|
|
251
|
+
${scopes}, ${returnTo}, now() + make_interval(secs => ${settings.flowTtlS}), ${shared})
|
|
252
|
+
RETURNING expires_at AS "expiresAt"`.pipe(Effect.orDie);
|
|
253
|
+
return {
|
|
254
|
+
flowId,
|
|
255
|
+
authorizeUrl: `${config.baseUrl}${AUTHORIZE_PATH}?flow=${encodeURIComponent(flowId)}`,
|
|
256
|
+
scopes,
|
|
257
|
+
expiresAt: iso(flow.expiresAt),
|
|
258
|
+
};
|
|
259
|
+
});
|
|
260
|
+
/** The person signed in on this request (a browser session only) and their session. */
|
|
261
|
+
const browserSession = (headers, action) => identity.authenticateCall(headers, "http").pipe(Effect.mapError(() => new Forbidden({ action, message: "Sign in to the app in this browser first" })), Effect.flatMap((call) => call.credential.kind === "session" && !call.session.agent
|
|
262
|
+
? Effect.succeed(call)
|
|
263
|
+
: Effect.fail(new Forbidden({ action, message: "Consent needs the person's own signed-in session" }))));
|
|
264
|
+
/** RFC 7636 verifier, derived from the kernel's secret and the state: nothing secret is stored. */
|
|
265
|
+
const verifierFor = (flowId, state) => createHmac("sha256", authSecret).update(`eloxiv-pkce:${flowId}:${state}`).digest("base64url");
|
|
266
|
+
/**
|
|
267
|
+
* `body`, a write of the flow, in a transaction that holds the person's session and is valid at its commit
|
|
268
|
+
* (Identity.whileSignedIn): a sign-out either waits for the write or commits first and nothing is written.
|
|
269
|
+
*/
|
|
270
|
+
const whileSignedIn = (call, action, body) => sql.withTransaction(identity.whileSignedIn(call.credential.id ?? "", call.actor.userId, body)).pipe(Effect.catchTag("SqlError", (e) => Effect.die(e)), Effect.catchTag("Unauthenticated", () => Effect.fail(new Forbidden({ action, message: "The session this consent was given in has ended: sign in again" }))));
|
|
271
|
+
const authorize = (headers, flowId) => Effect.gen(function* () {
|
|
272
|
+
const action = "connections.authorize";
|
|
273
|
+
const call = yield* browserSession(headers, action);
|
|
274
|
+
const state = randomBytes(32).toString("base64url");
|
|
275
|
+
// The flow's binding to this session is written only while the session holds.
|
|
276
|
+
const flow = yield* whileSignedIn(call, action, Effect.gen(function* () {
|
|
277
|
+
const [bound] = yield* sql `
|
|
278
|
+
UPDATE eloxiv.connection_flow SET state_hash = ${sha(state)}, session_hash = ${sha(call.session.id)},
|
|
279
|
+
authorized_at = now()
|
|
280
|
+
WHERE id = ${flowId} AND user_id = ${call.actor.userId} AND completed_at IS NULL AND expires_at > now()
|
|
281
|
+
RETURNING org_id AS "orgId", user_id AS "userId", provider, scopes, connection_id AS "connectionId"`;
|
|
282
|
+
if (bound === undefined) {
|
|
283
|
+
return yield* new Forbidden({ action, message: "This consent link is not yours, was used, or expired" });
|
|
284
|
+
}
|
|
285
|
+
// Still a member of the organisation the consent was started in.
|
|
286
|
+
yield* identity
|
|
287
|
+
.resolve({ kind: "user", userId: bound.userId, orgId: bound.orgId })
|
|
288
|
+
.pipe(Effect.mapError(() => new Forbidden({ action, message: "Not a member of the organisation" })));
|
|
289
|
+
return bound;
|
|
290
|
+
}));
|
|
291
|
+
const connector = connectorOf(flow.provider);
|
|
292
|
+
if (connector === undefined)
|
|
293
|
+
return yield* new InvalidInput({ message: `No connector ${flow.provider}` });
|
|
294
|
+
const current = flow.connectionId === null ? undefined : yield* row(flow.connectionId);
|
|
295
|
+
const { client, resource } = yield* clientFor(connector, current);
|
|
296
|
+
const url = new URL(client.authorizeUrl);
|
|
297
|
+
const params = {
|
|
298
|
+
client_id: client.clientId,
|
|
299
|
+
response_type: "code",
|
|
300
|
+
redirect_uri: callbackUrl,
|
|
301
|
+
scope: flow.scopes.join(client.scopeSeparator ?? " "),
|
|
302
|
+
state,
|
|
303
|
+
...(client.pkce === false
|
|
304
|
+
? {}
|
|
305
|
+
: {
|
|
306
|
+
code_challenge: createHash("sha256").update(verifierFor(flowId, state), "ascii").digest("base64url"),
|
|
307
|
+
code_challenge_method: "S256",
|
|
308
|
+
}),
|
|
309
|
+
...(resource === undefined ? {} : { resource }),
|
|
310
|
+
...client.authorizeParams,
|
|
311
|
+
};
|
|
312
|
+
if (flow.scopes.length === 0)
|
|
313
|
+
delete params["scope"];
|
|
314
|
+
for (const [key, value] of Object.entries(params))
|
|
315
|
+
url.searchParams.set(key, value);
|
|
316
|
+
return url.toString();
|
|
317
|
+
});
|
|
318
|
+
const staticTokenRequest = (client, body) => Effect.tryPromise({
|
|
319
|
+
try: async (signal) => {
|
|
320
|
+
const response = await fetch(client.tokenUrl, {
|
|
321
|
+
signal,
|
|
322
|
+
method: "POST",
|
|
323
|
+
headers: { "content-type": "application/x-www-form-urlencoded", accept: "application/json" },
|
|
324
|
+
body: new URLSearchParams({ ...body, client_id: client.clientId, client_secret: client.clientSecret }),
|
|
325
|
+
});
|
|
326
|
+
const text = await response.text();
|
|
327
|
+
let json = {};
|
|
328
|
+
try {
|
|
329
|
+
json = JSON.parse(text);
|
|
330
|
+
}
|
|
331
|
+
catch {
|
|
332
|
+
json = {};
|
|
333
|
+
}
|
|
334
|
+
return { status: response.status, json };
|
|
335
|
+
},
|
|
336
|
+
catch: (e) => new Unavailable({ message: `The token endpoint is unreachable: ${String(e)}`, retryAfterMs: null }),
|
|
337
|
+
});
|
|
338
|
+
/**
|
|
339
|
+
* A token request. To a discovered client's token endpoint: through the destination policy, naming the
|
|
340
|
+
* `resource`, with the client secret only when the client has one; a refused destination answers like a refused
|
|
341
|
+
* grant (400), so a refresh to it needs reauthorisation.
|
|
342
|
+
*/
|
|
343
|
+
const tokenRequest = (resolved, body) => resolved.discovered
|
|
344
|
+
? fetchJson(policy, resolved.client.tokenUrl, {
|
|
345
|
+
method: "POST",
|
|
346
|
+
form: {
|
|
347
|
+
...body,
|
|
348
|
+
client_id: resolved.client.clientId,
|
|
349
|
+
...(resolved.client.clientSecret === "" ? {} : { client_secret: resolved.client.clientSecret }),
|
|
350
|
+
...(resolved.resource === undefined ? {} : { resource: resolved.resource }),
|
|
351
|
+
},
|
|
352
|
+
}).pipe(Effect.catchTag("InvalidInput", (e) => Effect.succeed({ status: 400, json: { error: e.message } })))
|
|
353
|
+
: staticTokenRequest(resolved.client, body);
|
|
354
|
+
/**
|
|
355
|
+
* The tokens of a consent the kernel did not keep (its session ended while the code was exchanged): revoked at
|
|
356
|
+
* the provider (RFC 7009) only where that ends no more than them (the connector says its revocation ends only
|
|
357
|
+
* that token) and no active Connection holds the same provider account (whose grant a revocation could end:
|
|
358
|
+
* a consent completed in another session, or before); otherwise discarded, unused. What became of them: the
|
|
359
|
+
* callback's record says.
|
|
360
|
+
*/
|
|
361
|
+
const discardTokens = (client, provider, accountId, tokens) => Effect.gen(function* () {
|
|
362
|
+
if (client.revocation?.revokes !== "that token") {
|
|
363
|
+
return "discarded: the provider's revocation would end more than this consent";
|
|
364
|
+
}
|
|
365
|
+
const held = yield* sql `SELECT 1 FROM eloxiv.connection
|
|
366
|
+
WHERE provider = ${provider} AND account_id = ${accountId} AND status = 'active' LIMIT 1`.pipe(Effect.orDie);
|
|
367
|
+
if (held.length > 0)
|
|
368
|
+
return "discarded: an active Connection holds the same provider account";
|
|
369
|
+
yield* revokeAtProvider(client.revocation.url, client, tokens);
|
|
370
|
+
return "revoked at the provider";
|
|
371
|
+
});
|
|
372
|
+
/**
|
|
373
|
+
* Revoke tokens at the provider (RFC 7009), refresh token first (revoking it ends the grant at most providers),
|
|
374
|
+
* each at most a few seconds; best effort, logged when it fails.
|
|
375
|
+
*/
|
|
376
|
+
const revokeAtProvider = (revokeUrl, client, tokens) => Effect.gen(function* () {
|
|
377
|
+
const revoke = (token, hint) => Effect.tryPromise({
|
|
378
|
+
try: (signal) => fetch(revokeUrl, {
|
|
379
|
+
signal,
|
|
380
|
+
method: "POST",
|
|
381
|
+
headers: { "content-type": "application/x-www-form-urlencoded" },
|
|
382
|
+
body: new URLSearchParams({
|
|
383
|
+
token,
|
|
384
|
+
token_type_hint: hint,
|
|
385
|
+
client_id: client.clientId,
|
|
386
|
+
client_secret: client.clientSecret,
|
|
387
|
+
}),
|
|
388
|
+
}).then((response) => response.status),
|
|
389
|
+
catch: (e) => e,
|
|
390
|
+
}).pipe(Effect.timeout("5 seconds"), Effect.flatMap((status) => status === 200
|
|
391
|
+
? Effect.void
|
|
392
|
+
: Effect.logWarning(`Connections: the provider answered ${status} to a revocation`)), Effect.catchCause((cause) => Effect.logWarning("Connections: a token's revocation failed", cause)));
|
|
393
|
+
if (tokens.refreshToken !== undefined)
|
|
394
|
+
yield* revoke(tokens.refreshToken, "refresh_token");
|
|
395
|
+
yield* revoke(tokens.accessToken, "access_token");
|
|
396
|
+
});
|
|
397
|
+
const tokenSet = (client, json) => {
|
|
398
|
+
const accessToken = json["access_token"];
|
|
399
|
+
if (typeof accessToken !== "string" || accessToken.length === 0)
|
|
400
|
+
return undefined;
|
|
401
|
+
const expiresIn = Number(json["expires_in"]);
|
|
402
|
+
const separator = client.scopeSeparator === "," ? /\s*,\s*/u : /\s+/u;
|
|
403
|
+
return {
|
|
404
|
+
accessToken,
|
|
405
|
+
refreshToken: typeof json["refresh_token"] === "string" ? json["refresh_token"] : undefined,
|
|
406
|
+
expiresAt: Number.isFinite(expiresIn) && expiresIn > 0 ? new Date(Date.now() + expiresIn * 1000) : null,
|
|
407
|
+
scopes: typeof json["scope"] === "string"
|
|
408
|
+
? json["scope"]
|
|
409
|
+
.split(separator)
|
|
410
|
+
.map((s) => s.trim())
|
|
411
|
+
.filter((s) => s.length > 0)
|
|
412
|
+
: undefined,
|
|
413
|
+
};
|
|
414
|
+
};
|
|
415
|
+
const callback = (headers, params) => Effect.gen(function* () {
|
|
416
|
+
const action = "connections.callback";
|
|
417
|
+
const state = params.get("state") ?? "";
|
|
418
|
+
const call = yield* browserSession(headers, action);
|
|
419
|
+
// Single use: the state is consumed before anything else, from the session it was bound to, while that
|
|
420
|
+
// session holds (a sign-out committed first leaves the state unused and is refused).
|
|
421
|
+
const consumed = yield* whileSignedIn(call, action, sql `
|
|
422
|
+
UPDATE eloxiv.connection_flow SET completed_at = now()
|
|
423
|
+
WHERE state_hash = ${sha(state)} AND session_hash = ${sha(call.session.id)} AND completed_at IS NULL
|
|
424
|
+
AND authorized_at IS NOT NULL AND expires_at > now()
|
|
425
|
+
RETURNING id, org_id AS "orgId", user_id AS "userId", provider, connection_id AS "connectionId", scopes,
|
|
426
|
+
return_to AS "returnTo", shared`).pipe(Effect.tapError((e) => audit(action, call.actor.userId, call.actor.orgId, "denied", { reason: "session" }, e._tag)));
|
|
427
|
+
const [flow] = consumed;
|
|
428
|
+
if (flow === undefined) {
|
|
429
|
+
yield* audit(action, call.actor.userId, null, "denied", { reason: "state" }, "Forbidden");
|
|
430
|
+
return yield* new Forbidden({
|
|
431
|
+
action,
|
|
432
|
+
message: "This sign-in response is not for this session, was already used, or expired",
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
const fail = (message, errorTag = "InvalidInput", more = {}) => Effect.gen(function* () {
|
|
436
|
+
yield* audit(action, flow.userId, flow.orgId, "failed", { flow: flow.id, provider: flow.provider, message, ...more }, errorTag);
|
|
437
|
+
return yield* errorTag === "Forbidden"
|
|
438
|
+
? new Forbidden({ action, message })
|
|
439
|
+
: new InvalidInput({ message });
|
|
440
|
+
});
|
|
441
|
+
const providerError = params.get("error");
|
|
442
|
+
if (providerError !== null)
|
|
443
|
+
return yield* fail(`The provider refused consent (${tokenErrorCode(providerError, 400)})`);
|
|
444
|
+
const code = params.get("code");
|
|
445
|
+
if (code === null)
|
|
446
|
+
return yield* fail("The provider sent no authorization code");
|
|
447
|
+
const owner = yield* identity
|
|
448
|
+
.resolve({ kind: "user", userId: flow.userId, orgId: flow.orgId })
|
|
449
|
+
.pipe(Effect.catchTag("Forbidden", () => Effect.succeed(undefined)));
|
|
450
|
+
if (owner === undefined)
|
|
451
|
+
return yield* fail("Not a member of the organisation", "Forbidden");
|
|
452
|
+
if (flow.shared && !owner.permissions.includes(CONNECTIONS_MANAGE)) {
|
|
453
|
+
return yield* fail(`Connecting for the organisation needs the ${CONNECTIONS_MANAGE} permission`, "Forbidden");
|
|
454
|
+
}
|
|
455
|
+
const connector = connectorOf(flow.provider);
|
|
456
|
+
if (connector === undefined)
|
|
457
|
+
return yield* fail(`No connector ${flow.provider}`);
|
|
458
|
+
const flowConnection = flow.connectionId === null ? undefined : yield* row(flow.connectionId);
|
|
459
|
+
const resolved = yield* clientFor(connector, flowConnection).pipe(Effect.catchTag("InvalidInput", (e) => fail(e.message)));
|
|
460
|
+
const exchanged = yield* tokenRequest(resolved, {
|
|
461
|
+
grant_type: "authorization_code",
|
|
462
|
+
code,
|
|
463
|
+
redirect_uri: callbackUrl,
|
|
464
|
+
...(resolved.client.pkce === false ? {} : { code_verifier: verifierFor(flow.id, state) }),
|
|
465
|
+
}).pipe(Effect.catchTag("Unavailable", (e) => Effect.succeed({ status: 503, json: { error: e.message } })));
|
|
466
|
+
const tokens = exchanged.status === 200 ? tokenSet(resolved.client, exchanged.json) : undefined;
|
|
467
|
+
if (tokens === undefined) {
|
|
468
|
+
return yield* fail(`The provider refused the code (${tokenErrorCode(exchanged.json["error"], exchanged.status)})`);
|
|
469
|
+
}
|
|
470
|
+
// An endpoint Connection's account is its endpoint (recorded when it was added); a provider's is whoever the
|
|
471
|
+
// connector identifies. Connector code is registry code: it runs without the kernel's services.
|
|
472
|
+
const account = connector.endpoint !== undefined
|
|
473
|
+
? flowConnection === undefined
|
|
474
|
+
? { _tag: "NotFound" }
|
|
475
|
+
: { id: flowConnection.accountId, label: flowConnection.accountLabel }
|
|
476
|
+
: yield* asModuleCode(Effect.suspend(() => connector.identify(tokens.accessToken, settingsOf(connector.name)))).pipe(Effect.catch((e) => Effect.succeed(e)));
|
|
477
|
+
if ("_tag" in account)
|
|
478
|
+
return yield* fail(`The account could not be identified: ${account._tag}`);
|
|
479
|
+
const granted = normalize(connector, tokens.scopes ?? flow.scopes);
|
|
480
|
+
// The provider's answer came after network calls: the person's session must hold again now, locked until
|
|
481
|
+
// the credentials commit and valid at the commit (a sign-out waits for them, or committed first and they
|
|
482
|
+
// are discarded: nothing is saved).
|
|
483
|
+
const connectionId = yield* sql
|
|
484
|
+
.withTransaction(identity.whileSignedIn(call.credential.id ?? "", call.actor.userId, Effect.gen(function* () {
|
|
485
|
+
const [current] = flow.shared
|
|
486
|
+
? yield* sql `
|
|
487
|
+
SELECT ${sql.unsafe(COLUMNS)} FROM eloxiv.connection
|
|
488
|
+
WHERE org_id = ${flow.orgId} AND shared AND provider = ${flow.provider}
|
|
489
|
+
AND account_id = ${account.id} FOR UPDATE`
|
|
490
|
+
: yield* sql `
|
|
491
|
+
SELECT ${sql.unsafe(COLUMNS)} FROM eloxiv.connection
|
|
492
|
+
WHERE org_id = ${flow.orgId} AND NOT shared AND owner_id = ${flow.userId}
|
|
493
|
+
AND provider = ${flow.provider} AND account_id = ${account.id} FOR UPDATE`;
|
|
494
|
+
if (flow.connectionId !== null && current?.id !== flow.connectionId) {
|
|
495
|
+
return { refused: "The provider signed in a different account than this Connection's" };
|
|
496
|
+
}
|
|
497
|
+
const scopes = current === undefined || current.status === "disconnected"
|
|
498
|
+
? granted
|
|
499
|
+
: normalize(connector, [...current.scopes, ...granted]);
|
|
500
|
+
const id = current?.id ?? `conn_${randomBytes(16).toString("hex")}`;
|
|
501
|
+
if (current === undefined) {
|
|
502
|
+
yield* sql `INSERT INTO eloxiv.connection (id, org_id, owner_id, provider, account_id, account_label, scopes,
|
|
503
|
+
status, access_expires_at, token_version, refreshed_at, shared)
|
|
504
|
+
VALUES (${id}, ${flow.orgId}, ${flow.userId}, ${flow.provider}, ${account.id},
|
|
505
|
+
${account.label}, ${scopes}, 'active', ${tokens.expiresAt}, 1, now(), ${flow.shared})`;
|
|
506
|
+
}
|
|
507
|
+
else {
|
|
508
|
+
yield* sql `UPDATE eloxiv.connection SET account_label = ${account.label}, scopes = ${scopes},
|
|
509
|
+
status = 'active', status_reason = NULL, access_expires_at = ${tokens.expiresAt},
|
|
510
|
+
token_version = token_version + 1, refreshed_at = now(), updated_at = now()
|
|
511
|
+
WHERE id = ${id}`;
|
|
512
|
+
}
|
|
513
|
+
const access = {
|
|
514
|
+
actorUserId: flow.userId,
|
|
515
|
+
purpose: "connection.consent",
|
|
516
|
+
surface: "http",
|
|
517
|
+
};
|
|
518
|
+
yield* custody.save({ id, orgId: flow.orgId }, { accessToken: tokens.accessToken, refreshToken: tokens.refreshToken }, access);
|
|
519
|
+
yield* audit(action, flow.userId, flow.orgId, "succeeded", {
|
|
520
|
+
connectionId: id,
|
|
521
|
+
provider: flow.provider,
|
|
522
|
+
scopes,
|
|
523
|
+
upgraded: current !== undefined,
|
|
524
|
+
shared: flow.shared,
|
|
525
|
+
});
|
|
526
|
+
return { id };
|
|
527
|
+
})))
|
|
528
|
+
.pipe(Effect.map((saved) => saved), Effect.catchTag("Unauthenticated", () => Effect.succeed({
|
|
529
|
+
refused: "The session this consent was given in has ended: sign in again",
|
|
530
|
+
sessionEnded: true,
|
|
531
|
+
})), Effect.orDie);
|
|
532
|
+
if ("refused" in connectionId) {
|
|
533
|
+
// Tokens the provider issued for a consent the kernel did not keep: revoked there only where that ends
|
|
534
|
+
// nothing else, else discarded (`discardTokens`); the record says which.
|
|
535
|
+
const tokensWent = connectionId.sessionEnded === true
|
|
536
|
+
? yield* discardTokens(resolved.client, flow.provider, account.id, tokens)
|
|
537
|
+
: "discarded: the consent was refused";
|
|
538
|
+
return yield* fail(connectionId.refused, "Forbidden", { tokens: tokensWent });
|
|
539
|
+
}
|
|
540
|
+
tokenCache.delete(connectionId.id);
|
|
541
|
+
return { connectionId: connectionId.id, returnTo: flow.returnTo };
|
|
542
|
+
});
|
|
543
|
+
// ---------------------------------------------------------------------------------------------- use
|
|
544
|
+
/** Access tokens decrypted once per token version (each read audited), checked against the row on every use. */
|
|
545
|
+
const tokenCache = new Map();
|
|
546
|
+
const inflight = new Map();
|
|
547
|
+
const notFound = (connectionId) => new NotFound({ message: "No such Connection", id: connectionId });
|
|
548
|
+
const refusedUse = (connectionId, message) => new ProviderForbidden({ message, connectionId, missingScopes: [], consent: null });
|
|
549
|
+
/** Whether `userId` (and, when given, `module`) holds a grant of the shared Connection. */
|
|
550
|
+
const granted = (connectionId, orgId, userId, module) => sql `
|
|
551
|
+
SELECT
|
|
552
|
+
EXISTS (SELECT 1 FROM eloxiv.connection_grant g WHERE g.connection_id = ${connectionId} AND (
|
|
553
|
+
g.grantee_kind = 'org'
|
|
554
|
+
OR (g.grantee_kind = 'user' AND g.grantee_id = ${userId})
|
|
555
|
+
OR (g.grantee_kind = 'group' AND g.grantee_id IN (
|
|
556
|
+
SELECT group_id FROM eloxiv.group_member WHERE org_id = ${orgId} AND user_id = ${userId}))
|
|
557
|
+
)) AS member,
|
|
558
|
+
EXISTS (SELECT 1 FROM eloxiv.connection_grant g WHERE g.connection_id = ${connectionId}
|
|
559
|
+
AND g.grantee_kind = 'module' AND g.grantee_id = ${module ?? ""}) AS module`.pipe(Effect.orDie, Effect.map(([answer]) => ({ member: answer?.member === true, module: answer?.module === true })));
|
|
560
|
+
/** Whether `userId` is a member of `orgId` now (read from the directory on every use). */
|
|
561
|
+
const isMember = (userId, orgId) => identity.resolve({ kind: "user", userId, orgId }).pipe(Effect.as(true), Effect.catchTag("Forbidden", () => Effect.succeed(false)));
|
|
562
|
+
/**
|
|
563
|
+
* The Connection, usable by `by` now: active and in their organisation; a personal one only by its owner while
|
|
564
|
+
* the owner is a member; a shared one only by a member it is granted to (themselves, a group of theirs, or
|
|
565
|
+
* everyone) and, from a module's handler, only if it is granted to that module too.
|
|
566
|
+
*/
|
|
567
|
+
const usable = (connectionId, by) => Effect.gen(function* () {
|
|
568
|
+
const current = yield* row(connectionId);
|
|
569
|
+
if (current === undefined || current.status === "disconnected")
|
|
570
|
+
return yield* notFound(connectionId);
|
|
571
|
+
if (by !== undefined && by.orgId !== current.orgId) {
|
|
572
|
+
return yield* refusedUse(connectionId, "The Connection belongs to another organisation");
|
|
573
|
+
}
|
|
574
|
+
if (current.shared) {
|
|
575
|
+
if (by !== undefined) {
|
|
576
|
+
// Credential membership: the user's, re-checked on every use.
|
|
577
|
+
if (!(yield* isMember(by.userId, current.orgId))) {
|
|
578
|
+
return yield* refusedUse(connectionId, "Not a member of the Connection's organisation");
|
|
579
|
+
}
|
|
580
|
+
const grants = yield* granted(connectionId, current.orgId, by.userId, by.module);
|
|
581
|
+
if (!grants.member) {
|
|
582
|
+
return yield* refusedUse(connectionId, "The shared Connection is not granted to you");
|
|
583
|
+
}
|
|
584
|
+
if (by.module !== undefined && !grants.module) {
|
|
585
|
+
return yield* refusedUse(connectionId, `The shared Connection is not granted to the ${by.module} module`);
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
else {
|
|
590
|
+
if (by !== undefined && by.userId !== current.ownerId) {
|
|
591
|
+
return yield* refusedUse(connectionId, "Only the Connection's owner may use it");
|
|
592
|
+
}
|
|
593
|
+
// Credential membership: re-checked on every use (ledger "credential membership cutover").
|
|
594
|
+
if (!(yield* isMember(current.ownerId, current.orgId))) {
|
|
595
|
+
return yield* refusedUse(connectionId, "The Connection's owner is no longer a member of its organisation");
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
if (current.status === "needs-reauth") {
|
|
599
|
+
return yield* new Unauthorized({
|
|
600
|
+
message: `The Connection needs reauthorisation${current.statusReason === null ? "" : `: ${current.statusReason}`}`,
|
|
601
|
+
connectionId,
|
|
602
|
+
reauthorize: true,
|
|
603
|
+
});
|
|
604
|
+
}
|
|
605
|
+
return current;
|
|
606
|
+
});
|
|
607
|
+
/** Mark the Connection as needing reauthorisation (once) and notify its owner. */
|
|
608
|
+
const needsReauth = (connectionId, reason) => Effect.gen(function* () {
|
|
609
|
+
tokenCache.delete(connectionId);
|
|
610
|
+
const [marked] = yield* sql `
|
|
611
|
+
UPDATE eloxiv.connection SET status = 'needs-reauth', status_reason = ${reason}, updated_at = now()
|
|
612
|
+
WHERE id = ${connectionId} AND status = 'active'
|
|
613
|
+
RETURNING org_id AS "orgId", owner_id AS "ownerId", provider, token_version AS "tokenVersion"`.pipe(Effect.orDie);
|
|
614
|
+
if (marked === undefined)
|
|
615
|
+
return;
|
|
616
|
+
yield* audit("eloxiv.connections.needs-reauth", null, marked.orgId, "succeeded", {
|
|
617
|
+
connectionId,
|
|
618
|
+
provider: marked.provider,
|
|
619
|
+
reason,
|
|
620
|
+
});
|
|
621
|
+
const connector = connectorOf(marked.provider);
|
|
622
|
+
yield* notifications
|
|
623
|
+
.send({
|
|
624
|
+
orgId: marked.orgId,
|
|
625
|
+
recipients: [marked.ownerId],
|
|
626
|
+
category: "connections",
|
|
627
|
+
title: `Reconnect ${connector?.displayName ?? marked.provider}`,
|
|
628
|
+
body: `Your ${connector?.displayName ?? marked.provider} connection stopped working (${reason}). Reconnect it to resume.`,
|
|
629
|
+
key: `connection-reauth:${connectionId}:${marked.tokenVersion}`,
|
|
630
|
+
})
|
|
631
|
+
.pipe(Effect.catch((e) => Effect.logWarning("Connections: could not notify the owner of a Connection needing reauthorisation", e)));
|
|
632
|
+
});
|
|
633
|
+
/**
|
|
634
|
+
* Refresh under the Connection's lock. `observed` is the token version the caller saw: if the row has moved
|
|
635
|
+
* on, another caller refreshed already and its token is used instead.
|
|
636
|
+
*/
|
|
637
|
+
const refreshLocked = (connectionId, observed) => Effect.gen(function* () {
|
|
638
|
+
const outcome = yield* sql
|
|
639
|
+
.withTransaction(Effect.gen(function* () {
|
|
640
|
+
yield* sql `SELECT pg_advisory_xact_lock(hashtextextended(${`eloxiv.connection-refresh:${connectionId}`}, 0))`;
|
|
641
|
+
const [current] = yield* sql `
|
|
642
|
+
SELECT ${sql.unsafe(COLUMNS)} FROM eloxiv.connection WHERE id = ${connectionId} FOR UPDATE`;
|
|
643
|
+
if (current === undefined || current.status === "disconnected")
|
|
644
|
+
return { _tag: "missing" };
|
|
645
|
+
if (current.status === "needs-reauth") {
|
|
646
|
+
return { _tag: "reauth", reason: current.statusReason ?? "needs reauthorisation" };
|
|
647
|
+
}
|
|
648
|
+
const access = { actorUserId: null, purpose: "connection.refresh" };
|
|
649
|
+
if (current.tokenVersion !== observed) {
|
|
650
|
+
const token = yield* custody.load(current, "access", access);
|
|
651
|
+
if (token !== undefined) {
|
|
652
|
+
return {
|
|
653
|
+
_tag: "ok",
|
|
654
|
+
token,
|
|
655
|
+
version: current.tokenVersion,
|
|
656
|
+
refreshed: false,
|
|
657
|
+
expires: current.accessExpiresAt,
|
|
658
|
+
};
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
const connector = connectorOf(current.provider);
|
|
662
|
+
if (connector === undefined)
|
|
663
|
+
return { _tag: "reauth", reason: `no connector ${current.provider}` };
|
|
664
|
+
if (current.auth !== null && current.auth.kind !== "oauth") {
|
|
665
|
+
return { _tag: "reauth", reason: "the endpoint refused the Connection's credential" };
|
|
666
|
+
}
|
|
667
|
+
const refreshToken = yield* custody.load(current, "refresh", access);
|
|
668
|
+
if (refreshToken === undefined)
|
|
669
|
+
return { _tag: "reauth", reason: "no refresh token" };
|
|
670
|
+
const resolved = yield* Effect.result(clientFor(connector, current));
|
|
671
|
+
if (resolved._tag === "Failure")
|
|
672
|
+
return { _tag: "reauth", reason: resolved.failure.message };
|
|
673
|
+
const client = resolved.success.client;
|
|
674
|
+
const answer = yield* tokenRequest(resolved.success, {
|
|
675
|
+
grant_type: "refresh_token",
|
|
676
|
+
refresh_token: refreshToken,
|
|
677
|
+
});
|
|
678
|
+
// The connector reads an answer whose status does not say what it means (Slack's `200 { ok: false }`).
|
|
679
|
+
const judged = client.tokenError?.({ status: answer.status, json: answer.json });
|
|
680
|
+
const tokens = answer.status === 200 && judged === undefined ? tokenSet(client, answer.json) : undefined;
|
|
681
|
+
if (tokens === undefined) {
|
|
682
|
+
// Kept as the Connection's reason, audited and sent to its owner: only a standard error code, never
|
|
683
|
+
// the provider's own text (which can echo the refresh token or the client's secret).
|
|
684
|
+
const error = tokenErrorCode(judged?.error ?? answer.json["error"], answer.status);
|
|
685
|
+
// invalid_grant (revoked, expired, rotated away) and a refused client cannot recover by retrying.
|
|
686
|
+
const permanent = judged === undefined ? answer.status === 400 || answer.status === 401 : judged.kind === "reauth";
|
|
687
|
+
if (permanent)
|
|
688
|
+
return { _tag: "reauth", reason: `the provider refused the refresh (${error})` };
|
|
689
|
+
return yield* new Unavailable({ message: `Refreshing failed (${error})`, retryAfterMs: null });
|
|
690
|
+
}
|
|
691
|
+
// Rotation-safe: a rotated refresh token is stored in this transaction, under the lock.
|
|
692
|
+
yield* custody.save(current, { accessToken: tokens.accessToken, refreshToken: tokens.refreshToken }, access);
|
|
693
|
+
const scopes = tokens.scopes === undefined
|
|
694
|
+
? current.scopes
|
|
695
|
+
: normalize(connector, [...current.scopes, ...tokens.scopes]);
|
|
696
|
+
const [updated] = yield* sql `
|
|
697
|
+
UPDATE eloxiv.connection SET token_version = token_version + 1, access_expires_at = ${tokens.expiresAt},
|
|
698
|
+
refreshed_at = now(), scopes = ${scopes}, updated_at = now()
|
|
699
|
+
WHERE id = ${connectionId} RETURNING token_version AS "tokenVersion"`;
|
|
700
|
+
return {
|
|
701
|
+
_tag: "ok",
|
|
702
|
+
token: tokens.accessToken,
|
|
703
|
+
version: updated.tokenVersion,
|
|
704
|
+
refreshed: true,
|
|
705
|
+
expires: tokens.expiresAt,
|
|
706
|
+
};
|
|
707
|
+
}))
|
|
708
|
+
.pipe(Effect.catchTag("SqlError", (e) => Effect.die(e)));
|
|
709
|
+
if (outcome._tag === "missing")
|
|
710
|
+
return yield* notFound(connectionId);
|
|
711
|
+
if (outcome._tag === "reauth") {
|
|
712
|
+
yield* needsReauth(connectionId, outcome.reason);
|
|
713
|
+
return yield* new Unauthorized({
|
|
714
|
+
message: `Refreshing the Connection failed (${outcome.reason}); it needs reauthorisation`,
|
|
715
|
+
connectionId,
|
|
716
|
+
reauthorize: true,
|
|
717
|
+
});
|
|
718
|
+
}
|
|
719
|
+
tokenCache.set(connectionId, { version: outcome.version, token: outcome.token });
|
|
720
|
+
return outcome;
|
|
721
|
+
});
|
|
722
|
+
/**
|
|
723
|
+
* One refresh per Connection at a time in this process; the database lock does the same across processes.
|
|
724
|
+
* The refresh runs in its own fiber, in the service's scope, and every caller (the one that started it
|
|
725
|
+
* too) only awaits its outcome: interrupting a caller at any point never cancels the refresh half-way (a
|
|
726
|
+
* rotated refresh token is stored or the transaction rolls back) and never leaves the entry behind. The
|
|
727
|
+
* entry is cleared and every waiter answered when the refresh ends, whatever its outcome; a refresh that
|
|
728
|
+
* hangs ends as Unavailable after `refreshTimeoutMs` (60 s by default). It runs in the service's context, not
|
|
729
|
+
* the caller's: a caller inside a transaction that rolls back does not take the refresh with it.
|
|
730
|
+
*/
|
|
731
|
+
const refreshShared = (connectionId, observed) => Effect.uninterruptibleMask((restore) => Effect.suspend(() => {
|
|
732
|
+
const running = inflight.get(connectionId);
|
|
733
|
+
if (running !== undefined)
|
|
734
|
+
return restore(Deferred.await(running));
|
|
735
|
+
const deferred = Deferred.makeUnsafe();
|
|
736
|
+
inflight.set(connectionId, deferred);
|
|
737
|
+
const refresh = refreshLocked(connectionId, observed).pipe(Effect.map((outcome) => outcome.token), Effect.timeoutOrElse({
|
|
738
|
+
duration: settings.refreshTimeoutMs,
|
|
739
|
+
orElse: () => Effect.fail(new Unavailable({ message: "Refreshing the Connection timed out", retryAfterMs: null })),
|
|
740
|
+
}), Effect.onExit((exit) => Effect.sync(() => {
|
|
741
|
+
if (inflight.get(connectionId) === deferred)
|
|
742
|
+
inflight.delete(connectionId);
|
|
743
|
+
}).pipe(Effect.andThen(Deferred.done(deferred, exit)))));
|
|
744
|
+
return Effect.forkIn(refresh.pipe(Effect.updateContext(() => serviceContext)), scope).pipe(Effect.andThen(restore(Deferred.await(deferred))));
|
|
745
|
+
}));
|
|
746
|
+
/** A valid access token: refreshed first when it expires within the skew. */
|
|
747
|
+
const accessToken = (current) => Effect.gen(function* () {
|
|
748
|
+
const expires = epoch(current.accessExpiresAt);
|
|
749
|
+
if (expires !== undefined && expires - Date.now() < settings.refreshSkewS * 1000) {
|
|
750
|
+
const token = yield* refreshShared(current.id, current.tokenVersion);
|
|
751
|
+
return { token, version: tokenCache.get(current.id)?.version ?? current.tokenVersion + 1 };
|
|
752
|
+
}
|
|
753
|
+
const cached = tokenCache.get(current.id);
|
|
754
|
+
if (cached !== undefined && cached.version === current.tokenVersion)
|
|
755
|
+
return cached;
|
|
756
|
+
const token = yield* custody.load(current, "access", {
|
|
757
|
+
actorUserId: current.ownerId,
|
|
758
|
+
purpose: "connection.request",
|
|
759
|
+
});
|
|
760
|
+
if (token === undefined)
|
|
761
|
+
return yield* refreshShared(current.id, -1).pipe(Effect.map((t) => ({ token: t, version: -1 })));
|
|
762
|
+
const entry = { token, version: current.tokenVersion };
|
|
763
|
+
tokenCache.set(current.id, entry);
|
|
764
|
+
return entry;
|
|
765
|
+
});
|
|
766
|
+
/** Decrypted secrets an endpoint Connection sends, once per secret version (each read audited). */
|
|
767
|
+
const secretCache = new Map();
|
|
768
|
+
/**
|
|
769
|
+
* The credential of a Connection authenticating with a secret: the secret it names, read from Secrets (a secret
|
|
770
|
+
* of its owner, or of the organisation for a shared one), refused when it is gone or when the secret's own
|
|
771
|
+
* destinations do not include the Connection's endpoint.
|
|
772
|
+
*/
|
|
773
|
+
const secretCredential = (current, auth) => Effect.gen(function* () {
|
|
774
|
+
const scope = auth.scope === "user"
|
|
775
|
+
? { kind: "user", orgId: current.orgId, userId: current.ownerId }
|
|
776
|
+
: { kind: "org", orgId: current.orgId };
|
|
777
|
+
const subject = scope.kind === "user" ? scope.userId : "";
|
|
778
|
+
const [meta] = yield* sql `
|
|
779
|
+
SELECT version, allowed_origins AS "allowedOrigins" FROM eloxiv.secret
|
|
780
|
+
WHERE org_id = ${current.orgId} AND scope_kind = ${scope.kind} AND subject = ${subject}
|
|
781
|
+
AND name = ${auth.name}`.pipe(Effect.orDie);
|
|
782
|
+
if (meta === undefined) {
|
|
783
|
+
yield* needsReauth(current.id, `the secret ${auth.name} it sends is gone`);
|
|
784
|
+
return yield* new Unauthorized({
|
|
785
|
+
message: `The secret ${auth.name} this Connection sends is gone`,
|
|
786
|
+
connectionId: current.id,
|
|
787
|
+
reauthorize: true,
|
|
788
|
+
});
|
|
789
|
+
}
|
|
790
|
+
const origin = new URL(current.endpoint ?? "").origin;
|
|
791
|
+
if (meta.allowedOrigins !== null && !meta.allowedOrigins.includes(origin)) {
|
|
792
|
+
return yield* refusedUse(current.id, `The secret ${auth.name} may not be sent to ${origin}`);
|
|
793
|
+
}
|
|
794
|
+
const key = `${current.id}:${auth.scope}:${auth.name}`;
|
|
795
|
+
const cached = secretCache.get(key);
|
|
796
|
+
if (cached !== undefined && cached.version === meta.version) {
|
|
797
|
+
return { header: auth.header, value: `${auth.prefix}${cached.value}`, version: 0 };
|
|
798
|
+
}
|
|
799
|
+
const read = yield* secrets
|
|
800
|
+
.read(scope, auth.name, { actorUserId: current.ownerId, purpose: "connection.request" })
|
|
801
|
+
.pipe(Effect.mapError(() => new Unauthorized({
|
|
802
|
+
message: `The secret ${auth.name} this Connection sends cannot be read`,
|
|
803
|
+
connectionId: current.id,
|
|
804
|
+
reauthorize: true,
|
|
805
|
+
})));
|
|
806
|
+
secretCache.set(key, { version: read.metadata.version, value: read.value });
|
|
807
|
+
return { header: auth.header, value: `${auth.prefix}${read.value}`, version: 0 };
|
|
808
|
+
});
|
|
809
|
+
/** What the Connection's requests carry: its OAuth access token, the secret it names, or nothing. */
|
|
810
|
+
const credentialOf = (current) => {
|
|
811
|
+
const auth = current.auth;
|
|
812
|
+
if (auth?.kind === "none")
|
|
813
|
+
return Effect.succeed(undefined);
|
|
814
|
+
if (auth?.kind === "secret")
|
|
815
|
+
return secretCredential(current, auth);
|
|
816
|
+
return accessToken(current).pipe(Effect.map((t) => ({ header: "authorization", value: `Bearer ${t.token}`, version: t.version })));
|
|
817
|
+
};
|
|
818
|
+
/**
|
|
819
|
+
* The origins a Connection's credential is sent to: those its connector declares (`apiOrigins`), or, for an
|
|
820
|
+
* endpoint Connection, its endpoint's alone.
|
|
821
|
+
*/
|
|
822
|
+
const originsOf = (connector, current) => {
|
|
823
|
+
const origins = new Set();
|
|
824
|
+
const declared = connector.endpoint !== undefined ? [current.endpoint ?? ""] : connector.apiOrigins(settingsOf(connector.name));
|
|
825
|
+
for (const origin of declared) {
|
|
826
|
+
try {
|
|
827
|
+
origins.add(new URL(origin).origin);
|
|
828
|
+
}
|
|
829
|
+
catch {
|
|
830
|
+
// Not a URL: allows nothing.
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
return origins;
|
|
834
|
+
};
|
|
835
|
+
const REDIRECTS = new Set([301, 302, 303, 307, 308]);
|
|
836
|
+
const MAX_REDIRECTS = 5;
|
|
837
|
+
/** The most an endpoint Connection's answer may hold (its endpoint is someone's choice, not the operator's). */
|
|
838
|
+
const MAX_ENDPOINT_BYTES = 8 * 1024 * 1024;
|
|
839
|
+
/** Request headers a connector's request never sets: the credential's, cookies, and those the transport owns. */
|
|
840
|
+
const RESERVED = new Set([
|
|
841
|
+
"authorization",
|
|
842
|
+
"cookie",
|
|
843
|
+
"host",
|
|
844
|
+
"proxy-authorization",
|
|
845
|
+
"content-length",
|
|
846
|
+
"connection",
|
|
847
|
+
]);
|
|
848
|
+
/**
|
|
849
|
+
* `raw`: a raw provider request's read (`read`) or write (`write`), whose answer past its bound is its own
|
|
850
|
+
* error; otherwise the bound is an outage of the endpoint's.
|
|
851
|
+
*/
|
|
852
|
+
const readBody = (response, limit, raw) => Effect.tryPromise({
|
|
853
|
+
try: async () => {
|
|
854
|
+
if (limit === undefined || response.body === null)
|
|
855
|
+
return new Uint8Array(await response.arrayBuffer());
|
|
856
|
+
const reader = response.body.getReader();
|
|
857
|
+
const chunks = [];
|
|
858
|
+
let size = 0;
|
|
859
|
+
for (;;) {
|
|
860
|
+
const { done, value } = await reader.read();
|
|
861
|
+
if (done)
|
|
862
|
+
break;
|
|
863
|
+
size += value.byteLength;
|
|
864
|
+
if (size > limit) {
|
|
865
|
+
await reader.cancel().catch(() => undefined);
|
|
866
|
+
throw new Error("too large");
|
|
867
|
+
}
|
|
868
|
+
chunks.push(value);
|
|
869
|
+
}
|
|
870
|
+
const bytes = new Uint8Array(size);
|
|
871
|
+
let at = 0;
|
|
872
|
+
for (const chunk of chunks) {
|
|
873
|
+
bytes.set(chunk, at);
|
|
874
|
+
at += chunk.byteLength;
|
|
875
|
+
}
|
|
876
|
+
return bytes;
|
|
877
|
+
},
|
|
878
|
+
catch: (e) => e instanceof Error && e.message === "too large"
|
|
879
|
+
? raw === "read"
|
|
880
|
+
? // A raw read's answer past its bound: the request asked for too much (narrow it), not an outage.
|
|
881
|
+
new InvalidInput({
|
|
882
|
+
message: `The provider's answer is larger than ${limit} bytes: ask for less (fields, a page size)`,
|
|
883
|
+
})
|
|
884
|
+
: raw === "write"
|
|
885
|
+
? // A raw write's answer past its bound: the provider answered, so it acted. Not a refusal, which a
|
|
886
|
+
// caller would take as "nothing happened" and repeat: it may have happened (never `dispatched:
|
|
887
|
+
// false`), so the effect is `unknown` and never run again.
|
|
888
|
+
new Unavailable({
|
|
889
|
+
message: `The provider answered the write, but its answer is larger than ${limit} bytes: it may have been made`,
|
|
890
|
+
retryAfterMs: null,
|
|
891
|
+
})
|
|
892
|
+
: new Unavailable({ message: `The answer is larger than ${limit} bytes`, retryAfterMs: null })
|
|
893
|
+
: new Unavailable({
|
|
894
|
+
message: `The provider's answer could not be read: ${String(e)}`,
|
|
895
|
+
retryAfterMs: null,
|
|
896
|
+
}),
|
|
897
|
+
});
|
|
898
|
+
/**
|
|
899
|
+
* One request with the Connection's credential. It goes only to an origin the Connection declares: a request
|
|
900
|
+
* elsewhere is refused before anything is sent. Redirects are followed here, at most five, with the credential
|
|
901
|
+
* only while they stay on a declared origin (a pre-authenticated download URL on another host gets the request
|
|
902
|
+
* without it). For an endpoint Connection (`endpoint`) and a raw provider request (`request.bounded`), every hop
|
|
903
|
+
* passes the outbound destination policy first and is sent pinned, and the answer is bounded.
|
|
904
|
+
*/
|
|
905
|
+
const send = (request, credential, origins, endpoint) => Effect.gen(function* () {
|
|
906
|
+
const guarded = endpoint || request.bounded !== undefined;
|
|
907
|
+
const limit = request.bounded?.maxResponseBytes ?? (endpoint ? MAX_ENDPOINT_BYTES : undefined);
|
|
908
|
+
let url;
|
|
909
|
+
try {
|
|
910
|
+
url = new URL(request.url);
|
|
911
|
+
}
|
|
912
|
+
catch {
|
|
913
|
+
return yield* new InvalidInput({ message: "The connector asked for a URL that is not absolute" });
|
|
914
|
+
}
|
|
915
|
+
if (!origins.has(url.origin)) {
|
|
916
|
+
return yield* new InvalidInput({
|
|
917
|
+
message: `The connector asked to send the Connection's credential to ${url.origin}, which it does not declare`,
|
|
918
|
+
});
|
|
919
|
+
}
|
|
920
|
+
let method = request.method;
|
|
921
|
+
let body = request.body;
|
|
922
|
+
const base = { accept: "application/json" };
|
|
923
|
+
for (const [name, value] of Object.entries(request.headers ?? {})) {
|
|
924
|
+
const lower = name.toLowerCase();
|
|
925
|
+
if (RESERVED.has(lower) || lower === credential?.header)
|
|
926
|
+
continue;
|
|
927
|
+
base[lower] = value;
|
|
928
|
+
}
|
|
929
|
+
if (request.json !== undefined) {
|
|
930
|
+
body = JSON.stringify(request.json);
|
|
931
|
+
base["content-type"] = "application/json";
|
|
932
|
+
}
|
|
933
|
+
let target = url;
|
|
934
|
+
for (let hop = 0;; hop++) {
|
|
935
|
+
if (guarded)
|
|
936
|
+
yield* checkDestination(policy, target.href);
|
|
937
|
+
const headers = { ...base };
|
|
938
|
+
if (credential !== undefined && origins.has(target.origin))
|
|
939
|
+
headers[credential.header] = credential.value;
|
|
940
|
+
const sent = target;
|
|
941
|
+
const response = yield* Effect.tryPromise({
|
|
942
|
+
try: (signal) => (guarded ? pinned : fetch)(sent, {
|
|
943
|
+
method,
|
|
944
|
+
headers,
|
|
945
|
+
redirect: "manual",
|
|
946
|
+
signal,
|
|
947
|
+
...(body === undefined ? {} : { body }),
|
|
948
|
+
}),
|
|
949
|
+
catch: (e) => new Unavailable({ message: `The provider is unreachable: ${String(e)}`, retryAfterMs: null }),
|
|
950
|
+
});
|
|
951
|
+
const location = response.headers.get("location");
|
|
952
|
+
// A raw provider request follows no redirect: only the URL its connector's scope checked is reached, so a
|
|
953
|
+
// redirect could take it (and a 307 or 308 a write's body) to a path the scope does not open, with the
|
|
954
|
+
// credential still on a declared origin. Nothing of the target is read or returned.
|
|
955
|
+
if (request.bounded !== undefined && response.status >= 300 && response.status < 400) {
|
|
956
|
+
yield* Effect.promise(() => response.body?.cancel().catch(() => undefined) ?? Promise.resolve());
|
|
957
|
+
const message = `The provider redirected a raw request (HTTP ${response.status}); raw requests follow no redirect`;
|
|
958
|
+
// A read changed nothing; a write's provider answered, and whether it acted cannot be told: may have.
|
|
959
|
+
return yield* method === "GET"
|
|
960
|
+
? new InvalidInput({ message })
|
|
961
|
+
: new Unavailable({ message, retryAfterMs: null });
|
|
962
|
+
}
|
|
963
|
+
if (REDIRECTS.has(response.status) && location !== null && hop < MAX_REDIRECTS) {
|
|
964
|
+
// A redirect's body is never read: cancelled, so an endless one costs nothing.
|
|
965
|
+
yield* Effect.promise(() => response.body?.cancel().catch(() => undefined) ?? Promise.resolve());
|
|
966
|
+
try {
|
|
967
|
+
target = new URL(location, target);
|
|
968
|
+
}
|
|
969
|
+
catch {
|
|
970
|
+
return yield* new Unavailable({
|
|
971
|
+
message: "The provider redirected to a URL that does not parse",
|
|
972
|
+
retryAfterMs: null,
|
|
973
|
+
});
|
|
974
|
+
}
|
|
975
|
+
if (response.status === 303 ||
|
|
976
|
+
((response.status === 301 || response.status === 302) && method === "POST")) {
|
|
977
|
+
method = "GET";
|
|
978
|
+
body = undefined;
|
|
979
|
+
delete base["content-type"];
|
|
980
|
+
}
|
|
981
|
+
continue;
|
|
982
|
+
}
|
|
983
|
+
const bytes = yield* readBody(response, limit, request.bounded === undefined ? undefined : method === "GET" ? "read" : "write");
|
|
984
|
+
const text = new TextDecoder().decode(bytes);
|
|
985
|
+
let json;
|
|
986
|
+
try {
|
|
987
|
+
json = text.length === 0 ? undefined : JSON.parse(text);
|
|
988
|
+
}
|
|
989
|
+
catch {
|
|
990
|
+
json = undefined;
|
|
991
|
+
}
|
|
992
|
+
return { status: response.status, headers: response.headers, text, json, bytes };
|
|
993
|
+
}
|
|
994
|
+
});
|
|
995
|
+
const failureOf = (connector, response) => {
|
|
996
|
+
const classified = connector.classify?.(response);
|
|
997
|
+
if (classified !== undefined)
|
|
998
|
+
return classified;
|
|
999
|
+
const s = response.status;
|
|
1000
|
+
if (s === 401)
|
|
1001
|
+
return "unauthorized";
|
|
1002
|
+
// RFC 6750: a resource server names a missing scope with `error="insufficient_scope"`.
|
|
1003
|
+
if (s === 403) {
|
|
1004
|
+
return /error="?insufficient_scope/u.test(response.headers.get("www-authenticate") ?? "")
|
|
1005
|
+
? "insufficient-scope"
|
|
1006
|
+
: "forbidden";
|
|
1007
|
+
}
|
|
1008
|
+
if (s === 404)
|
|
1009
|
+
return "not-found";
|
|
1010
|
+
if (s === 409 || s === 412)
|
|
1011
|
+
return "conflict";
|
|
1012
|
+
if (s === 410)
|
|
1013
|
+
return "invalid-cursor";
|
|
1014
|
+
if (s === 429)
|
|
1015
|
+
return "rate-limited";
|
|
1016
|
+
if (s === 400 || s === 422)
|
|
1017
|
+
return "invalid-input";
|
|
1018
|
+
return "unavailable";
|
|
1019
|
+
};
|
|
1020
|
+
/**
|
|
1021
|
+
* What a provider's failure answer says, for an error a caller gets: redacted of the credential the request
|
|
1022
|
+
* carried (`known`) and of anything that looks like one, since an answer can echo what it was sent.
|
|
1023
|
+
*/
|
|
1024
|
+
const describe = (response, known = []) => {
|
|
1025
|
+
const json = response.json;
|
|
1026
|
+
const error = json?.error;
|
|
1027
|
+
const detail = typeof error === "string"
|
|
1028
|
+
? error
|
|
1029
|
+
: typeof error?.message === "string"
|
|
1030
|
+
? error.message
|
|
1031
|
+
: response.text.slice(0, 200);
|
|
1032
|
+
return `HTTP ${response.status}${detail ? `: ${redactSecrets(detail, known)}` : ""}`;
|
|
1033
|
+
};
|
|
1034
|
+
/** The credential values a request carried, to redact from what its answer says. */
|
|
1035
|
+
const knownOf = (credential) => credential === undefined ? [] : [credential.value, credential.value.replace(/^Bearer\s+/iu, "")];
|
|
1036
|
+
const perform = (connectionId, by, required, request,
|
|
1037
|
+
/**
|
|
1038
|
+
* The request does something others see (an external operation): after a 5xx the provider may have acted,
|
|
1039
|
+
* so it is not sent again here; the caller reconciles. A 429 (refused, nothing done) is still retried.
|
|
1040
|
+
*/
|
|
1041
|
+
atMostOnce = false) => Effect.gen(function* () {
|
|
1042
|
+
let refreshed = false;
|
|
1043
|
+
let attempt = 0;
|
|
1044
|
+
let deadline;
|
|
1045
|
+
for (;;) {
|
|
1046
|
+
// Checked now, to fail fast and find the connector's limits ...
|
|
1047
|
+
const first = yield* usable(connectionId, by);
|
|
1048
|
+
const connector = connectorOf(first.provider);
|
|
1049
|
+
if (connector === undefined)
|
|
1050
|
+
return yield* notFound(connectionId);
|
|
1051
|
+
const limits = limitsOf(connector);
|
|
1052
|
+
deadline ??= Date.now() + limits.maxWaitMs;
|
|
1053
|
+
// ... and again once Metering admits the request, with the credential loaded then, just before it is sent:
|
|
1054
|
+
// a grant revoked, a member gone or a secret replaced while it waited for a slot or its quota is honoured.
|
|
1055
|
+
const { current, credential, response } = yield* metering.admit(connectionId, limits, deadline, Effect.gen(function* () {
|
|
1056
|
+
const current = yield* usable(connectionId, by);
|
|
1057
|
+
const credential = yield* credentialOf(current);
|
|
1058
|
+
const response = yield* send(request, credential, originsOf(connector, current), connector.endpoint !== undefined);
|
|
1059
|
+
return { current, credential, response };
|
|
1060
|
+
}));
|
|
1061
|
+
// A 2xx is a success unless the connector reads a failure in its body (Slack's `200 { ok: false }`).
|
|
1062
|
+
const failure = response.status < 400 ? connector.classifySuccess?.(response) : failureOf(connector, response);
|
|
1063
|
+
if (failure === undefined)
|
|
1064
|
+
return response;
|
|
1065
|
+
switch (failure) {
|
|
1066
|
+
case "unauthorized": {
|
|
1067
|
+
// A secret, or no credential, cannot be refreshed: the endpoint refused it, so the Connection needs
|
|
1068
|
+
// attention (the secret replaced, or OAuth set up) and later calls fail fast.
|
|
1069
|
+
if (credential === undefined || (current.auth !== null && current.auth.kind !== "oauth")) {
|
|
1070
|
+
yield* needsReauth(connectionId, "the endpoint refused the Connection's credential");
|
|
1071
|
+
return yield* new Unauthorized({
|
|
1072
|
+
message: `The endpoint refused the Connection's credential (${describe(response, knownOf(credential))})`,
|
|
1073
|
+
connectionId,
|
|
1074
|
+
reauthorize: true,
|
|
1075
|
+
});
|
|
1076
|
+
}
|
|
1077
|
+
if (refreshed) {
|
|
1078
|
+
yield* needsReauth(connectionId, "the provider refused a freshly refreshed token");
|
|
1079
|
+
return yield* new Unauthorized({
|
|
1080
|
+
message: `The provider refused the Connection's credential after a refresh (${describe(response, knownOf(credential))})`,
|
|
1081
|
+
connectionId,
|
|
1082
|
+
reauthorize: true,
|
|
1083
|
+
});
|
|
1084
|
+
}
|
|
1085
|
+
refreshed = true;
|
|
1086
|
+
yield* refreshShared(connectionId, credential.version);
|
|
1087
|
+
continue;
|
|
1088
|
+
}
|
|
1089
|
+
case "rate-limited":
|
|
1090
|
+
case "unavailable": {
|
|
1091
|
+
const retryAfter = response.headers.get("retry-after");
|
|
1092
|
+
const honoured = response.status === 429 || response.status === 503 || failure === "rate-limited";
|
|
1093
|
+
if (!honoured)
|
|
1094
|
+
return yield* new Unavailable({
|
|
1095
|
+
message: describe(response, knownOf(credential)),
|
|
1096
|
+
retryAfterMs: null,
|
|
1097
|
+
});
|
|
1098
|
+
if (atMostOnce && failure === "unavailable") {
|
|
1099
|
+
return yield* new Unavailable({
|
|
1100
|
+
message: describe(response, knownOf(credential)),
|
|
1101
|
+
retryAfterMs: null,
|
|
1102
|
+
});
|
|
1103
|
+
}
|
|
1104
|
+
const cooldown = yield* metering.backoff(connectionId, response.status, retryAfter, attempt);
|
|
1105
|
+
attempt++;
|
|
1106
|
+
if (attempt >= limits.maxAttempts) {
|
|
1107
|
+
const until = cooldown.until === null ? Date.now() : Date.parse(cooldown.until);
|
|
1108
|
+
if (failure === "unavailable") {
|
|
1109
|
+
return yield* new Unavailable({
|
|
1110
|
+
message: describe(response, knownOf(credential)),
|
|
1111
|
+
retryAfterMs: Math.max(0, until - Date.now()),
|
|
1112
|
+
});
|
|
1113
|
+
}
|
|
1114
|
+
return yield* new RateLimited({
|
|
1115
|
+
message: `The provider kept limiting this Connection (${describe(response, knownOf(credential))})`,
|
|
1116
|
+
reason: "max-attempts",
|
|
1117
|
+
retryAfterMs: Math.max(0, until - Date.now()),
|
|
1118
|
+
retryAt: new Date(until).toISOString(),
|
|
1119
|
+
});
|
|
1120
|
+
}
|
|
1121
|
+
continue;
|
|
1122
|
+
}
|
|
1123
|
+
case "insufficient-scope":
|
|
1124
|
+
case "forbidden": {
|
|
1125
|
+
const granted = new Set(current.scopes);
|
|
1126
|
+
const wanted = normalize(connector, required);
|
|
1127
|
+
let missing = wanted.filter((scope) => !granted.has(scope));
|
|
1128
|
+
if (missing.length === 0 && failure === "insufficient-scope")
|
|
1129
|
+
missing = wanted;
|
|
1130
|
+
return yield* new ProviderForbidden({
|
|
1131
|
+
message: `The provider refused the operation (${describe(response, knownOf(credential))})`,
|
|
1132
|
+
connectionId,
|
|
1133
|
+
missingScopes: missing,
|
|
1134
|
+
consent: missing.length === 0 ? null : { action: "connections.reconnect", connectionId, scopes: missing },
|
|
1135
|
+
});
|
|
1136
|
+
}
|
|
1137
|
+
case "not-found":
|
|
1138
|
+
return yield* new NotFound({ message: describe(response, knownOf(credential)), id: null });
|
|
1139
|
+
case "conflict":
|
|
1140
|
+
return yield* new Conflict({ message: describe(response, knownOf(credential)) });
|
|
1141
|
+
case "invalid-cursor":
|
|
1142
|
+
return yield* new InvalidCursor({ message: describe(response, knownOf(credential)) });
|
|
1143
|
+
case "invalid-input":
|
|
1144
|
+
return yield* new InvalidInput({ message: describe(response, knownOf(credential)) });
|
|
1145
|
+
default:
|
|
1146
|
+
// A classification outside ProviderFailure (connector code is untyped at run time) ends the request:
|
|
1147
|
+
// falling through would send it again, for ever.
|
|
1148
|
+
return yield* new Unavailable({ message: describe(response, knownOf(credential)), retryAfterMs: null });
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
});
|
|
1152
|
+
const http = (connectionId, by, scopes) => ({
|
|
1153
|
+
request: (request) => perform(connectionId, by, scopes, request),
|
|
1154
|
+
});
|
|
1155
|
+
const contracts = new Map(serviceContracts.map((contract) => [contract.name, contract]));
|
|
1156
|
+
const capability = (connectionId, name, by) => Effect.gen(function* () {
|
|
1157
|
+
const current = yield* usable(connectionId, by);
|
|
1158
|
+
const connector = connectorOf(current.provider);
|
|
1159
|
+
const definition = connector?.capabilities[name];
|
|
1160
|
+
if (connector === undefined || definition === undefined) {
|
|
1161
|
+
return yield* new InvalidInput({ message: `${current.provider} does not provide ${name}` });
|
|
1162
|
+
}
|
|
1163
|
+
const contract = contracts.get(capabilityContracts[name]);
|
|
1164
|
+
const connectorSettings = settingsOf(connector.name);
|
|
1165
|
+
// Connector code is registry code: its operations run without the kernel's services, and the HTTP they
|
|
1166
|
+
// are handed runs with the context the capability was bound in, outside any transaction of the caller's (a
|
|
1167
|
+
// read-only action's, where the audited credential read could not be written, or any other a provider
|
|
1168
|
+
// request would hold open).
|
|
1169
|
+
const full = Context.omit(sql.transactionService)(yield* Effect.context());
|
|
1170
|
+
const operations = {};
|
|
1171
|
+
for (const [operation, spec] of Object.entries(contract.operations)) {
|
|
1172
|
+
const required = (spec.scopes ?? []).flatMap((scope) => definition.scopes[scope] ?? []);
|
|
1173
|
+
const atMostOnce = spec.effect === "external";
|
|
1174
|
+
operations[operation] = (input) => {
|
|
1175
|
+
const implementation = definition.make({
|
|
1176
|
+
request: (request) => Effect.updateContext(perform(connectionId, by, required, request, atMostOnce), () => full),
|
|
1177
|
+
}, connectorSettings, { endpoint: current.endpoint, options: current.options ?? undefined });
|
|
1178
|
+
// A ToolSource Connection exposes only the tools it allows: others are neither listed nor called.
|
|
1179
|
+
const allowed = name === "tools" && current.tools !== null ? new Set(current.tools) : undefined;
|
|
1180
|
+
if (allowed !== undefined && operation === "callTool") {
|
|
1181
|
+
const tool = input?.name;
|
|
1182
|
+
if (typeof tool !== "string" || !allowed.has(tool)) {
|
|
1183
|
+
return Effect.fail(refusedUse(connectionId, `The tool ${String(tool)} is not one this Connection exposes`));
|
|
1184
|
+
}
|
|
1185
|
+
}
|
|
1186
|
+
const run = implementation[operation];
|
|
1187
|
+
if (run === undefined) {
|
|
1188
|
+
return Effect.fail(new InvalidInput({ message: `${connector.name} does not implement ${operation}` }));
|
|
1189
|
+
}
|
|
1190
|
+
// What the connector answers is checked against the contract's output: a malformed answer is refused
|
|
1191
|
+
// as Unavailable, not passed on (or left to fail later as a defect).
|
|
1192
|
+
const output = Schema.decodeUnknownEffect(Schema.toType(spec.output));
|
|
1193
|
+
return asModuleCode(Effect.suspend(() => run(input))).pipe(Effect.map((value) => allowed !== undefined && operation === "listTools"
|
|
1194
|
+
? {
|
|
1195
|
+
...value,
|
|
1196
|
+
tools: value.tools.filter((t) => allowed.has(t.name)),
|
|
1197
|
+
}
|
|
1198
|
+
: value), Effect.flatMap((value) => output(value).pipe(Effect.mapError((e) => new Unavailable({
|
|
1199
|
+
message: `${connector.name} answered ${name}.${operation} with a value the contract refuses: ${String(e).slice(0, 300)}`,
|
|
1200
|
+
retryAfterMs: null,
|
|
1201
|
+
})))));
|
|
1202
|
+
};
|
|
1203
|
+
}
|
|
1204
|
+
return { connectionId, flags: definition.flags, operations };
|
|
1205
|
+
});
|
|
1206
|
+
const refresh = (connectionId) => Effect.gen(function* () {
|
|
1207
|
+
const current = yield* usable(connectionId, undefined);
|
|
1208
|
+
const outcome = yield* refreshLocked(connectionId, current.tokenVersion);
|
|
1209
|
+
return {
|
|
1210
|
+
refreshed: outcome.refreshed,
|
|
1211
|
+
expiresAt: outcome.expires === null || outcome.expires === undefined ? null : iso(outcome.expires),
|
|
1212
|
+
};
|
|
1213
|
+
});
|
|
1214
|
+
// ------------------------------------------------------------------------------------------ lifecycle
|
|
1215
|
+
/** The SQL condition: a grant of the shared Connection `c` to `userId` (themselves, a group of theirs, everyone). */
|
|
1216
|
+
const memberGrant = (orgId, userId) => sql `EXISTS (
|
|
1217
|
+
SELECT 1 FROM eloxiv.connection_grant g WHERE g.connection_id = c.id AND (
|
|
1218
|
+
g.grantee_kind = 'org' OR (g.grantee_kind = 'user' AND g.grantee_id = ${userId})
|
|
1219
|
+
OR (g.grantee_kind = 'group' AND g.grantee_id IN (
|
|
1220
|
+
SELECT group_id FROM eloxiv.group_member WHERE org_id = ${orgId} AND user_id = ${userId}))))`;
|
|
1221
|
+
const list = (actor) => sql `
|
|
1222
|
+
SELECT ${sql.unsafe(COLUMNS)} FROM eloxiv.connection c
|
|
1223
|
+
WHERE org_id = ${actor.orgId} AND status <> 'disconnected'
|
|
1224
|
+
AND (${manages(actor)} OR (NOT shared AND owner_id = ${actor.userId})
|
|
1225
|
+
OR (shared AND ${memberGrant(actor.orgId, actor.userId)}))
|
|
1226
|
+
ORDER BY created_at, id`.pipe(Effect.orDie, Effect.map((rows) => rows.map(toConnection)));
|
|
1227
|
+
const usableBy = (actor, module) => sql `
|
|
1228
|
+
SELECT ${sql.unsafe(COLUMNS)} FROM eloxiv.connection c
|
|
1229
|
+
WHERE org_id = ${actor.orgId} AND status <> 'disconnected'
|
|
1230
|
+
AND ((NOT shared AND owner_id = ${actor.userId})
|
|
1231
|
+
OR (shared AND ${memberGrant(actor.orgId, actor.userId)} AND EXISTS (
|
|
1232
|
+
SELECT 1 FROM eloxiv.connection_grant g WHERE g.connection_id = c.id
|
|
1233
|
+
AND g.grantee_kind = 'module' AND g.grantee_id = ${module})))
|
|
1234
|
+
ORDER BY created_at, id`.pipe(Effect.orDie, Effect.map((rows) => rows.map(toConnection)));
|
|
1235
|
+
const disconnect = (actor, connectionId) => Effect.gen(function* () {
|
|
1236
|
+
const current = yield* row(connectionId);
|
|
1237
|
+
if (current === undefined || current.orgId !== actor.orgId || current.status === "disconnected") {
|
|
1238
|
+
return yield* new InvalidInput({ message: "No such Connection in this organisation" });
|
|
1239
|
+
}
|
|
1240
|
+
if ((current.shared || current.ownerId !== actor.userId) && !manages(actor)) {
|
|
1241
|
+
return yield* new Forbidden({
|
|
1242
|
+
action: "connections.disconnect",
|
|
1243
|
+
message: `Disconnecting a shared Connection, or another member's, needs the ${CONNECTIONS_MANAGE} permission`,
|
|
1244
|
+
});
|
|
1245
|
+
}
|
|
1246
|
+
yield* sql `UPDATE eloxiv.connection SET status = 'disconnected', status_reason = 'disconnected',
|
|
1247
|
+
token_version = token_version + 1, updated_at = now() WHERE id = ${connectionId}`.pipe(Effect.orDie);
|
|
1248
|
+
const access = { actorUserId: actor.userId, purpose: "connection.disconnect" };
|
|
1249
|
+
yield* custody.remove(current, access);
|
|
1250
|
+
// A discovered client's secret is the Connection's too, whatever custody keeps its tokens.
|
|
1251
|
+
yield* secrets.delete({ kind: "connection", orgId: current.orgId, connectionId }, undefined, access);
|
|
1252
|
+
yield* sql `DELETE FROM eloxiv.connection_grant WHERE connection_id = ${connectionId}`.pipe(Effect.orDie);
|
|
1253
|
+
tokenCache.delete(connectionId);
|
|
1254
|
+
});
|
|
1255
|
+
// ------------------------------------------------------------------------------- endpoint Connections
|
|
1256
|
+
/** Header names a secret may be sent in: a token, and none the transport or cookies own. */
|
|
1257
|
+
const HEADER = /^[a-z0-9][a-z0-9-]{0,63}$/u;
|
|
1258
|
+
/** A secret the caller names for an endpoint Connection: theirs for a personal one, the organisation's for a shared one. */
|
|
1259
|
+
const namedSecret = (actor, ref, shared, origin) => Effect.gen(function* () {
|
|
1260
|
+
if (shared ? ref.scope !== "org" : ref.scope !== "user") {
|
|
1261
|
+
return yield* new InvalidInput({
|
|
1262
|
+
message: shared
|
|
1263
|
+
? "A shared Connection sends a secret of the organisation (scope org)"
|
|
1264
|
+
: "A personal Connection sends a secret of your own (scope user)",
|
|
1265
|
+
});
|
|
1266
|
+
}
|
|
1267
|
+
if (ref.scope === "org" && !actor.permissions.includes(SECRETS_MANAGE)) {
|
|
1268
|
+
return yield* new Forbidden({
|
|
1269
|
+
action: "connections.add",
|
|
1270
|
+
message: `Using an organisation secret needs the ${SECRETS_MANAGE} permission`,
|
|
1271
|
+
});
|
|
1272
|
+
}
|
|
1273
|
+
const subject = ref.scope === "user" ? actor.userId : "";
|
|
1274
|
+
const [meta] = yield* sql `
|
|
1275
|
+
SELECT allowed_origins AS "allowedOrigins" FROM eloxiv.secret
|
|
1276
|
+
WHERE org_id = ${actor.orgId} AND scope_kind = ${ref.scope} AND subject = ${subject} AND name = ${ref.name}`.pipe(Effect.orDie);
|
|
1277
|
+
if (meta === undefined) {
|
|
1278
|
+
return yield* new InvalidInput({ message: `There is no ${ref.scope} secret ${ref.name}: put it first` });
|
|
1279
|
+
}
|
|
1280
|
+
if (meta.allowedOrigins !== null && !meta.allowedOrigins.includes(origin)) {
|
|
1281
|
+
return yield* new InvalidInput({ message: `The secret ${ref.name} may not be sent to ${origin}` });
|
|
1282
|
+
}
|
|
1283
|
+
});
|
|
1284
|
+
const add = (actor, request) => Effect.gen(function* () {
|
|
1285
|
+
const connector = connectorOf(request.provider);
|
|
1286
|
+
if (connector?.endpoint === undefined) {
|
|
1287
|
+
return yield* new InvalidInput({ message: `${request.provider} is not an installed endpoint connector` });
|
|
1288
|
+
}
|
|
1289
|
+
const spec = connector.endpoint;
|
|
1290
|
+
const shared = request.shared === true;
|
|
1291
|
+
if (shared && !manages(actor)) {
|
|
1292
|
+
return yield* new Forbidden({
|
|
1293
|
+
action: "connections.add",
|
|
1294
|
+
message: `Adding a Connection for the organisation needs the ${CONNECTIONS_MANAGE} permission`,
|
|
1295
|
+
});
|
|
1296
|
+
}
|
|
1297
|
+
if (!spec.auth.includes(request.auth.kind)) {
|
|
1298
|
+
return yield* new InvalidInput({
|
|
1299
|
+
message: `${connector.name} does not authenticate with ${request.auth.kind}`,
|
|
1300
|
+
});
|
|
1301
|
+
}
|
|
1302
|
+
// The endpoint: https to a public address (or an allowed host), checked now and on every request.
|
|
1303
|
+
const url = yield* checkDestination(policy, request.endpoint);
|
|
1304
|
+
if (url.search !== "" || url.hash !== "") {
|
|
1305
|
+
return yield* new InvalidInput({ message: "The endpoint must not have a query or a fragment" });
|
|
1306
|
+
}
|
|
1307
|
+
const endpoint = url.pathname === "/" ? url.origin : `${url.origin}${url.pathname.replace(/\/+$/u, "")}`;
|
|
1308
|
+
let options = null;
|
|
1309
|
+
if (spec.options !== undefined) {
|
|
1310
|
+
options = yield* Schema.decodeUnknownEffect(spec.options)(request.options ?? {}).pipe(Effect.mapError((e) => new InvalidInput({ message: `${connector.name} options: ${String(e).slice(0, 300)}` })));
|
|
1311
|
+
}
|
|
1312
|
+
else if (request.options !== undefined) {
|
|
1313
|
+
return yield* new InvalidInput({ message: `${connector.name} takes no options` });
|
|
1314
|
+
}
|
|
1315
|
+
if (request.tools !== undefined && connector.capabilities.tools === undefined) {
|
|
1316
|
+
return yield* new InvalidInput({ message: `${connector.name} offers no tools` });
|
|
1317
|
+
}
|
|
1318
|
+
const returnTo = safeReturnTo(request.returnTo);
|
|
1319
|
+
if (returnTo === undefined) {
|
|
1320
|
+
return yield* new InvalidInput({ message: "returnTo must be a path or a URL on a trusted origin" });
|
|
1321
|
+
}
|
|
1322
|
+
let auth;
|
|
1323
|
+
let client = null;
|
|
1324
|
+
let registeredSecret;
|
|
1325
|
+
if (request.auth.kind === "none") {
|
|
1326
|
+
auth = { kind: "none" };
|
|
1327
|
+
}
|
|
1328
|
+
else if (request.auth.kind === "secret") {
|
|
1329
|
+
const header = (request.auth.header ?? "authorization").toLowerCase();
|
|
1330
|
+
if (!HEADER.test(header) || (header !== "authorization" && RESERVED.has(header))) {
|
|
1331
|
+
return yield* new InvalidInput({ message: `A secret cannot be sent in the ${header} header` });
|
|
1332
|
+
}
|
|
1333
|
+
yield* namedSecret(actor, request.auth, shared, url.origin);
|
|
1334
|
+
auth = {
|
|
1335
|
+
kind: "secret",
|
|
1336
|
+
scope: request.auth.scope,
|
|
1337
|
+
name: request.auth.name,
|
|
1338
|
+
header,
|
|
1339
|
+
prefix: request.auth.prefix ?? (header === "authorization" ? "Bearer " : ""),
|
|
1340
|
+
};
|
|
1341
|
+
}
|
|
1342
|
+
else {
|
|
1343
|
+
const given = request.auth.clientSecret;
|
|
1344
|
+
const discovered = yield* discoverClient(policy, endpoint, {
|
|
1345
|
+
callbackUrl,
|
|
1346
|
+
clientName: `Eloxiv (${new URL(config.baseUrl).host})`,
|
|
1347
|
+
clientId: request.auth.clientId,
|
|
1348
|
+
hasSecret: given !== undefined,
|
|
1349
|
+
scopes: request.auth.scopes,
|
|
1350
|
+
defaultScopes: spec.defaultScopes,
|
|
1351
|
+
}).pipe(Effect.mapError((e) => (e._tag === "Unavailable" ? new InvalidInput({ message: e.message }) : e)));
|
|
1352
|
+
// A client secret goes to the token endpoint the metadata names, not to the endpoint itself: that origin is
|
|
1353
|
+
// the one its destinations must allow (and they are checked again before every exchange and refresh).
|
|
1354
|
+
if (given !== undefined)
|
|
1355
|
+
yield* namedSecret(actor, given, shared, new URL(discovered.client.tokenUrl).origin);
|
|
1356
|
+
registeredSecret = discovered.clientSecret;
|
|
1357
|
+
auth = { kind: "oauth" };
|
|
1358
|
+
client = {
|
|
1359
|
+
...discovered.client,
|
|
1360
|
+
clientSecret: given !== undefined
|
|
1361
|
+
? given
|
|
1362
|
+
: registeredSecret !== undefined
|
|
1363
|
+
? { scope: "connection", name: "client_secret" }
|
|
1364
|
+
: null,
|
|
1365
|
+
};
|
|
1366
|
+
}
|
|
1367
|
+
const label = request.label ?? url.host;
|
|
1368
|
+
const tools = request.tools === undefined ? null : [...new Set(request.tools)];
|
|
1369
|
+
const pending = auth.kind === "oauth";
|
|
1370
|
+
const saved = yield* sql
|
|
1371
|
+
.withTransaction(Effect.gen(function* () {
|
|
1372
|
+
const [current] = shared
|
|
1373
|
+
? yield* sql `SELECT id FROM eloxiv.connection WHERE org_id = ${actor.orgId} AND shared
|
|
1374
|
+
AND provider = ${connector.name} AND account_id = ${endpoint} FOR UPDATE`
|
|
1375
|
+
: yield* sql `SELECT id FROM eloxiv.connection WHERE org_id = ${actor.orgId} AND NOT shared
|
|
1376
|
+
AND owner_id = ${actor.userId} AND provider = ${connector.name} AND account_id = ${endpoint} FOR UPDATE`;
|
|
1377
|
+
const id = current?.id ?? `conn_${randomBytes(16).toString("hex")}`;
|
|
1378
|
+
const status = pending ? "needs-reauth" : "active";
|
|
1379
|
+
const reason = pending ? "consent pending" : null;
|
|
1380
|
+
if (current === undefined) {
|
|
1381
|
+
yield* sql `INSERT INTO eloxiv.connection (id, org_id, owner_id, provider, account_id, account_label, scopes,
|
|
1382
|
+
status, status_reason, token_version, shared, endpoint, auth, oauth_client, options, tools)
|
|
1383
|
+
VALUES (${id}, ${actor.orgId}, ${actor.userId}, ${connector.name}, ${endpoint}, ${label},
|
|
1384
|
+
${client?.scopes ?? []}, ${status}, ${reason}, 1, ${shared}, ${endpoint}, ${JSON.stringify(auth)}::jsonb,
|
|
1385
|
+
${client === null ? null : JSON.stringify(client)}::jsonb, ${JSON.stringify(options)}::jsonb, ${tools})`;
|
|
1386
|
+
}
|
|
1387
|
+
else {
|
|
1388
|
+
// Its credential changes: what the old one was granted no longer applies.
|
|
1389
|
+
yield* sql `UPDATE eloxiv.connection SET account_label = ${label}, scopes = ${client?.scopes ?? []},
|
|
1390
|
+
status = ${status}, status_reason = ${reason}, token_version = token_version + 1,
|
|
1391
|
+
access_expires_at = NULL, auth = ${JSON.stringify(auth)}::jsonb,
|
|
1392
|
+
oauth_client = ${client === null ? null : JSON.stringify(client)}::jsonb,
|
|
1393
|
+
options = ${JSON.stringify(options)}::jsonb, tools = ${tools}, updated_at = now()
|
|
1394
|
+
WHERE id = ${id}`;
|
|
1395
|
+
}
|
|
1396
|
+
const access = { actorUserId: actor.userId, purpose: "connection.add" };
|
|
1397
|
+
yield* custody.remove({ id, orgId: actor.orgId }, access);
|
|
1398
|
+
yield* secrets.delete({ kind: "connection", orgId: actor.orgId, connectionId: id }, undefined, access);
|
|
1399
|
+
if (registeredSecret !== undefined) {
|
|
1400
|
+
yield* secrets
|
|
1401
|
+
.put({ kind: "connection", orgId: actor.orgId, connectionId: id }, "client_secret", registeredSecret, access)
|
|
1402
|
+
.pipe(Effect.orDie);
|
|
1403
|
+
}
|
|
1404
|
+
return id;
|
|
1405
|
+
}))
|
|
1406
|
+
.pipe(Effect.orDie);
|
|
1407
|
+
tokenCache.delete(saved);
|
|
1408
|
+
const current = (yield* row(saved));
|
|
1409
|
+
const consent = pending
|
|
1410
|
+
? yield* recordFlow(actor, connector.name, saved, current.scopes, returnTo, shared)
|
|
1411
|
+
: null;
|
|
1412
|
+
return { connection: toConnection(current), consent };
|
|
1413
|
+
});
|
|
1414
|
+
// ------------------------------------------------------------------------------------------ grants
|
|
1415
|
+
const sharedOf = (actor, connectionId, action) => Effect.gen(function* () {
|
|
1416
|
+
if (!manages(actor)) {
|
|
1417
|
+
return yield* new Forbidden({
|
|
1418
|
+
action,
|
|
1419
|
+
message: `Granting Connections needs the ${CONNECTIONS_MANAGE} permission`,
|
|
1420
|
+
});
|
|
1421
|
+
}
|
|
1422
|
+
const current = yield* row(connectionId);
|
|
1423
|
+
if (current === undefined || current.orgId !== actor.orgId || current.status === "disconnected") {
|
|
1424
|
+
return yield* new InvalidInput({ message: "No such Connection in this organisation" });
|
|
1425
|
+
}
|
|
1426
|
+
if (!current.shared) {
|
|
1427
|
+
return yield* new InvalidInput({
|
|
1428
|
+
message: "Only a shared Connection is granted; a personal one is its owner's",
|
|
1429
|
+
});
|
|
1430
|
+
}
|
|
1431
|
+
return current;
|
|
1432
|
+
});
|
|
1433
|
+
const granteeKey = (grantee) => ({
|
|
1434
|
+
kind: grantee.kind,
|
|
1435
|
+
id: grantee.kind === "org" ? "" : grantee.id,
|
|
1436
|
+
});
|
|
1437
|
+
const toGrant = (g) => ({
|
|
1438
|
+
connectionId: g.connectionId,
|
|
1439
|
+
grantee: (g.kind === "org" ? { kind: "org" } : { kind: g.kind, id: g.id }),
|
|
1440
|
+
grantedBy: g.grantedBy,
|
|
1441
|
+
createdAt: iso(g.createdAt),
|
|
1442
|
+
});
|
|
1443
|
+
const grant = (actor, connectionId, grantee) => Effect.gen(function* () {
|
|
1444
|
+
yield* sharedOf(actor, connectionId, "connections.grant");
|
|
1445
|
+
const key = granteeKey(grantee);
|
|
1446
|
+
if (key.kind === "user" && !(yield* isMember(key.id, actor.orgId))) {
|
|
1447
|
+
return yield* new InvalidInput({ message: "Not a member of this organisation" });
|
|
1448
|
+
}
|
|
1449
|
+
if (key.kind === "group") {
|
|
1450
|
+
const [group] = yield* sql `SELECT 1 FROM eloxiv.org_group WHERE org_id = ${actor.orgId} AND id = ${key.id}`.pipe(Effect.orDie);
|
|
1451
|
+
if (group === undefined)
|
|
1452
|
+
return yield* new InvalidInput({ message: "No such group in this organisation" });
|
|
1453
|
+
}
|
|
1454
|
+
if (key.kind === "module" && !/^[a-z][a-z0-9_-]{0,62}$/u.test(key.id)) {
|
|
1455
|
+
return yield* new InvalidInput({ message: "A module is named by lower case letters, digits, _ and -" });
|
|
1456
|
+
}
|
|
1457
|
+
yield* sql `INSERT INTO eloxiv.connection_grant (connection_id, org_id, grantee_kind, grantee_id, granted_by)
|
|
1458
|
+
VALUES (${connectionId}, ${actor.orgId}, ${key.kind}, ${key.id}, ${actor.userId}) ON CONFLICT DO NOTHING`.pipe(Effect.orDie);
|
|
1459
|
+
const [stored] = yield* sql `
|
|
1460
|
+
SELECT connection_id AS "connectionId", grantee_kind AS kind, grantee_id AS id, granted_by AS "grantedBy",
|
|
1461
|
+
created_at AS "createdAt"
|
|
1462
|
+
FROM eloxiv.connection_grant WHERE connection_id = ${connectionId} AND grantee_kind = ${key.kind}
|
|
1463
|
+
AND grantee_id = ${key.id}`.pipe(Effect.orDie);
|
|
1464
|
+
return toGrant(stored);
|
|
1465
|
+
});
|
|
1466
|
+
const revoke = (actor, connectionId, grantee) => Effect.gen(function* () {
|
|
1467
|
+
yield* sharedOf(actor, connectionId, "connections.revoke");
|
|
1468
|
+
const key = granteeKey(grantee);
|
|
1469
|
+
yield* sql `DELETE FROM eloxiv.connection_grant WHERE connection_id = ${connectionId}
|
|
1470
|
+
AND grantee_kind = ${key.kind} AND grantee_id = ${key.id}`.pipe(Effect.orDie);
|
|
1471
|
+
});
|
|
1472
|
+
const grants = (actor, connectionId) => Effect.gen(function* () {
|
|
1473
|
+
yield* sharedOf(actor, connectionId, "connections.grants");
|
|
1474
|
+
const rows = yield* sql `
|
|
1475
|
+
SELECT connection_id AS "connectionId", grantee_kind AS kind, grantee_id AS id, granted_by AS "grantedBy",
|
|
1476
|
+
created_at AS "createdAt"
|
|
1477
|
+
FROM eloxiv.connection_grant WHERE connection_id = ${connectionId} ORDER BY created_at, grantee_kind, grantee_id`.pipe(Effect.orDie);
|
|
1478
|
+
return rows.map(toGrant);
|
|
1479
|
+
});
|
|
1480
|
+
// ------------------------------------------------------------------------------------------- channels
|
|
1481
|
+
/** A channel Connection the actor may configure: their own, or (with the permission) the organisation's. */
|
|
1482
|
+
const configurable = (actor, connectionId, action) => Effect.gen(function* () {
|
|
1483
|
+
const current = yield* row(connectionId);
|
|
1484
|
+
if (current === undefined || current.orgId !== actor.orgId || current.status === "disconnected") {
|
|
1485
|
+
return yield* new InvalidInput({ message: "No such Connection in this organisation" });
|
|
1486
|
+
}
|
|
1487
|
+
if ((current.shared || current.ownerId !== actor.userId) && !manages(actor)) {
|
|
1488
|
+
return yield* new Forbidden({
|
|
1489
|
+
action,
|
|
1490
|
+
message: `Configuring a shared Connection's channels, or another member's, needs the ${CONNECTIONS_MANAGE} permission`,
|
|
1491
|
+
});
|
|
1492
|
+
}
|
|
1493
|
+
return current;
|
|
1494
|
+
});
|
|
1495
|
+
const CHANNEL_COLUMNS = `s.connection_id AS "connectionId", s.channel_id AS "channelId", s.enabled, s.scope,
|
|
1496
|
+
s.daily_tokens AS "dailyTokens", s.memory`;
|
|
1497
|
+
/**
|
|
1498
|
+
* Each channel with what its messages spent (and reserved) today, as its budget counts it: read in a transaction
|
|
1499
|
+
* of its own (the run records as the agent module's system actor), outside the call's, which may be read-only.
|
|
1500
|
+
*/
|
|
1501
|
+
const withUsage = (orgId, rows) => Effect.updateContext(sql.withTransaction(Effect.forEach(rows, (row) => channelSpend(sql, orgId, row.connectionId, row.channelId).pipe(Effect.map((usedToday) => ({ ...row, usedToday }))))), (context) => Context.omit(sql.transactionService)(context)).pipe(Effect.orDie);
|
|
1502
|
+
const channels = (actor, connectionId) => Effect.gen(function* () {
|
|
1503
|
+
yield* configurable(actor, connectionId, "connections.channels");
|
|
1504
|
+
const rows = yield* sql `SELECT ${sql.unsafe(CHANNEL_COLUMNS)} FROM eloxiv.channel_setting s
|
|
1505
|
+
WHERE s.connection_id = ${connectionId} ORDER BY s.channel_id`.pipe(Effect.orDie);
|
|
1506
|
+
return yield* withUsage(actor.orgId, rows);
|
|
1507
|
+
});
|
|
1508
|
+
const setChannel = (actor, input) => Effect.gen(function* () {
|
|
1509
|
+
const connection = yield* configurable(actor, input.connectionId, "connections.setChannel");
|
|
1510
|
+
if (!/^[A-Za-z0-9._:-]{1,200}$/u.test(input.channelId)) {
|
|
1511
|
+
return yield* new InvalidInput({ message: "A channel id is letters, digits, ., _, : and -" });
|
|
1512
|
+
}
|
|
1513
|
+
yield* sql `INSERT INTO eloxiv.channel_setting (connection_id, channel_id, org_id, enabled, scope, daily_tokens,
|
|
1514
|
+
memory)
|
|
1515
|
+
VALUES (${input.connectionId}, ${input.channelId}, ${connection.orgId},
|
|
1516
|
+
${input.enabled ?? CHANNEL_DEFAULTS.enabled}, ${input.scope ?? CHANNEL_DEFAULTS.scope},
|
|
1517
|
+
${input.dailyTokens === undefined ? CHANNEL_DEFAULTS.dailyTokens : input.dailyTokens},
|
|
1518
|
+
${input.memory ?? CHANNEL_DEFAULTS.memory})
|
|
1519
|
+
ON CONFLICT (connection_id, channel_id) DO UPDATE SET
|
|
1520
|
+
enabled = CASE WHEN ${input.enabled === undefined} THEN eloxiv.channel_setting.enabled ELSE EXCLUDED.enabled END,
|
|
1521
|
+
scope = CASE WHEN ${input.scope === undefined} THEN eloxiv.channel_setting.scope ELSE EXCLUDED.scope END,
|
|
1522
|
+
daily_tokens = CASE WHEN ${input.dailyTokens === undefined} THEN eloxiv.channel_setting.daily_tokens
|
|
1523
|
+
ELSE EXCLUDED.daily_tokens END,
|
|
1524
|
+
memory = CASE WHEN ${input.memory === undefined} THEN eloxiv.channel_setting.memory ELSE EXCLUDED.memory END,
|
|
1525
|
+
updated_at = now()`.pipe(Effect.orDie);
|
|
1526
|
+
const rows = yield* sql `SELECT ${sql.unsafe(CHANNEL_COLUMNS)} FROM eloxiv.channel_setting s
|
|
1527
|
+
WHERE s.connection_id = ${input.connectionId} AND s.channel_id = ${input.channelId}`.pipe(Effect.orDie);
|
|
1528
|
+
return (yield* withUsage(connection.orgId, rows))[0];
|
|
1529
|
+
});
|
|
1530
|
+
return Connections.of({
|
|
1531
|
+
channels,
|
|
1532
|
+
setChannel,
|
|
1533
|
+
connectors,
|
|
1534
|
+
start,
|
|
1535
|
+
list,
|
|
1536
|
+
usableBy,
|
|
1537
|
+
add,
|
|
1538
|
+
grant,
|
|
1539
|
+
revoke,
|
|
1540
|
+
grants,
|
|
1541
|
+
disconnect,
|
|
1542
|
+
authorize,
|
|
1543
|
+
callback,
|
|
1544
|
+
get: (connectionId) => row(connectionId).pipe(Effect.map((r) => (r === undefined ? undefined : toConnection(r)))),
|
|
1545
|
+
http: (connectionId, by, scopes) => http(connectionId, by, scopes),
|
|
1546
|
+
capability,
|
|
1547
|
+
refresh,
|
|
1548
|
+
});
|
|
1549
|
+
}));
|
|
1550
|
+
}
|
|
1551
|
+
/**
|
|
1552
|
+
* Where the browser may be sent after consent: `returnTo` resolved against the kernel's own URL exactly as a
|
|
1553
|
+
* browser resolves a `Location` (tabs and newlines dropped, backslashes read as slashes, `//host` taken as a
|
|
1554
|
+
* host), as an absolute http(s) URL whose origin is the kernel's or a trusted origin; otherwise `undefined`.
|
|
1555
|
+
* Comparing the resolved origin, not the text, is what refuses `/\evil.example`, `//evil.example` and
|
|
1556
|
+
* `/<tab>/evil.example`.
|
|
1557
|
+
*/
|
|
1558
|
+
export const returnTarget = (config, returnTo) => {
|
|
1559
|
+
let url;
|
|
1560
|
+
try {
|
|
1561
|
+
url = new URL(returnTo, config.baseUrl);
|
|
1562
|
+
}
|
|
1563
|
+
catch {
|
|
1564
|
+
return undefined;
|
|
1565
|
+
}
|
|
1566
|
+
if (url.protocol !== "http:" && url.protocol !== "https:")
|
|
1567
|
+
return undefined;
|
|
1568
|
+
if (url.username !== "" || url.password !== "")
|
|
1569
|
+
return undefined;
|
|
1570
|
+
const origins = new Set();
|
|
1571
|
+
for (const origin of [config.baseUrl, ...config.trustedOrigins]) {
|
|
1572
|
+
try {
|
|
1573
|
+
origins.add(new URL(origin).origin);
|
|
1574
|
+
}
|
|
1575
|
+
catch {
|
|
1576
|
+
// Not a URL: trusts nothing.
|
|
1577
|
+
}
|
|
1578
|
+
}
|
|
1579
|
+
return origins.has(url.origin) ? url.toString() : undefined;
|
|
1580
|
+
};
|
|
1581
|
+
/**
|
|
1582
|
+
* A token endpoint's error as a fixed code, else its status: never its own text, which can echo the refresh token or
|
|
1583
|
+
* the client's secret. A code is lower-case letters and underscores only (RFC 6749's `invalid_grant`, a provider's
|
|
1584
|
+
* own `invalid_refresh_token`): what an echoed credential, with its digits and separators, never is.
|
|
1585
|
+
*/
|
|
1586
|
+
export const tokenErrorCode = (error, status) => typeof error === "string" && /^[a-z]+(?:_[a-z]+)*$/u.test(error) && error.length <= 64 ? error : `HTTP ${status}`;
|
|
1587
|
+
const page = (title, message, status) => HttpServerResponse.fromWeb(new Response(`<!doctype html><html><head><meta charset="utf-8"><title>${escape(title)}</title></head><body><h1>${escape(title)}</h1><p>${escape(message)}</p></body></html>`, {
|
|
1588
|
+
status,
|
|
1589
|
+
headers: {
|
|
1590
|
+
"content-type": "text/html; charset=utf-8",
|
|
1591
|
+
"cache-control": "no-store",
|
|
1592
|
+
"content-security-policy": "default-src 'none'; frame-ancestors 'none'",
|
|
1593
|
+
"referrer-policy": "no-referrer",
|
|
1594
|
+
},
|
|
1595
|
+
}));
|
|
1596
|
+
const escape = (text) => text.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """);
|
|
1597
|
+
const redirect = (location) => HttpServerResponse.fromWeb(new Response(null, {
|
|
1598
|
+
status: 302,
|
|
1599
|
+
headers: { location, "cache-control": "no-store", "referrer-policy": "no-referrer" },
|
|
1600
|
+
}));
|
|
1601
|
+
/** The OAuth client flow's kernel routes: `GET /connections/authorize` and `GET /connections/callback`. */
|
|
1602
|
+
export const ConnectionRoutes = Layer.unwrap(Effect.gen(function* () {
|
|
1603
|
+
const connections = yield* Connections;
|
|
1604
|
+
const config = yield* KernelConfig;
|
|
1605
|
+
return Layer.mergeAll(HttpRouter.add("GET", AUTHORIZE_PATH, (request) => Effect.gen(function* () {
|
|
1606
|
+
const flow = new URL(request.url, "http://kernel").searchParams.get("flow") ?? "";
|
|
1607
|
+
const exit = yield* connections.authorize(toWebHeaders(request.headers), flow).pipe(Effect.exit);
|
|
1608
|
+
if (Exit.isSuccess(exit))
|
|
1609
|
+
return redirect(exit.value);
|
|
1610
|
+
const error = exit.cause.reasons.find((r) => r._tag === "Fail");
|
|
1611
|
+
if (error === undefined || error._tag !== "Fail")
|
|
1612
|
+
return yield* Effect.failCause(exit.cause);
|
|
1613
|
+
return page("Cannot connect", error.error.message, error.error._tag === "Forbidden" ? 403 : 400);
|
|
1614
|
+
})), HttpRouter.add("GET", CALLBACK_PATH, (request) => Effect.gen(function* () {
|
|
1615
|
+
const params = new URL(request.url, "http://kernel").searchParams;
|
|
1616
|
+
const exit = yield* connections.callback(toWebHeaders(request.headers), params).pipe(Effect.exit);
|
|
1617
|
+
if (Exit.isSuccess(exit)) {
|
|
1618
|
+
const { connectionId, returnTo } = exit.value;
|
|
1619
|
+
// Checked again when used: a flow recorded before a change of trusted origins sends nobody elsewhere.
|
|
1620
|
+
const allowed = returnTo === null ? undefined : returnTarget(config, returnTo);
|
|
1621
|
+
if (allowed === undefined)
|
|
1622
|
+
return page("Connected", "You can close this window.", 200);
|
|
1623
|
+
const target = new URL(allowed);
|
|
1624
|
+
target.searchParams.set("connection", connectionId);
|
|
1625
|
+
return redirect(target.toString());
|
|
1626
|
+
}
|
|
1627
|
+
const error = exit.cause.reasons.find((r) => r._tag === "Fail");
|
|
1628
|
+
if (error === undefined || error._tag !== "Fail")
|
|
1629
|
+
return yield* Effect.failCause(exit.cause);
|
|
1630
|
+
return page("Connection failed", error.error.message, error.error._tag === "Forbidden" ? 403 : 400);
|
|
1631
|
+
})));
|
|
1632
|
+
}));
|
|
1633
|
+
//# sourceMappingURL=Connections.js.map
|