@eloxiv/kernel 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
package/src/Sync.ts
ADDED
|
@@ -0,0 +1,1478 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sync (decision 5: Zero). zero-cache calls this endpoint to resolve named
|
|
3
|
+
* queries into ZQL. The kernel runs the module's query, then adds the policy
|
|
4
|
+
* filter compiled from Cedar for the `read` action (decision 2), so each client
|
|
5
|
+
* receives only the rows its user may read: policy-scoped partial sync.
|
|
6
|
+
*
|
|
7
|
+
* zero-cache transforms a connected replica's queries once and keeps running
|
|
8
|
+
* them, so nothing that can change while the replica is connected is bound
|
|
9
|
+
* into the filter. The filter is compiled symbolically, as for row-level
|
|
10
|
+
* security: the acting user and organisation are bound (they are the
|
|
11
|
+
* replica's), and every directory test (membership of the organisation, a
|
|
12
|
+
* group, a role, a permission, the email) and every sharing grant (to the
|
|
13
|
+
* user, its groups, its organisation, or a link it redeemed) becomes a
|
|
14
|
+
* subquery zero-cache evaluates live against the replicated directory facts
|
|
15
|
+
* (`eloxiv.sync_fact`) and grants (`eloxiv.share_grant`,
|
|
16
|
+
* `eloxiv.share_redemption`). A change reaches every connected replica as soon
|
|
17
|
+
* as zero-cache replicates the transaction that made it: no row written after a
|
|
18
|
+
* revocation commits is sent, and rows already synced are removed, without a
|
|
19
|
+
* new transform.
|
|
20
|
+
*
|
|
21
|
+
* Queries that reach related tables (`related()`, `whereExists()`) are
|
|
22
|
+
* authorised per child: every subquery gets its own entity's read filter, so a
|
|
23
|
+
* parent the caller may read never brings in a child it may not, and a filter
|
|
24
|
+
* on children counts only children the caller may read.
|
|
25
|
+
*/
|
|
26
|
+
import { Cause, Data, Effect, Exit, Layer, Option, Redacted, Schema } from "effect"
|
|
27
|
+
import { lockDirectoryShared } from "./db/DirectoryLock.ts"
|
|
28
|
+
import { HttpRouter, HttpServerResponse } from "effect/http"
|
|
29
|
+
import { SqlClient } from "effect/sql"
|
|
30
|
+
import {
|
|
31
|
+
createSchema,
|
|
32
|
+
mustGetQuery,
|
|
33
|
+
number,
|
|
34
|
+
string,
|
|
35
|
+
table,
|
|
36
|
+
type AnyQueryRegistry,
|
|
37
|
+
type Schema as ZeroSchema,
|
|
38
|
+
} from "@rocicorp/zero"
|
|
39
|
+
import { queryInternalsTag } from "@rocicorp/zero/bindings"
|
|
40
|
+
import { handleQueryRequest } from "@rocicorp/zero/server"
|
|
41
|
+
import { httpConfig, KernelConfig, machineConfig } from "./Config.ts"
|
|
42
|
+
import { Identity, ORG_HEADER } from "./Identity.ts"
|
|
43
|
+
import { Invocation } from "./Invocation.ts"
|
|
44
|
+
import { toWebHeaders } from "./surfaces/headers.ts"
|
|
45
|
+
import { boundedWebRequest, clientAddress, proxyHops, readBody, refusalResponse } from "./surfaces/request.ts"
|
|
46
|
+
import type { Actor, AnyEntity, EntityField } from "@eloxiv/contracts"
|
|
47
|
+
import {
|
|
48
|
+
CLIENT_VERSION_HEADER,
|
|
49
|
+
DEV_ZERO_API_KEY,
|
|
50
|
+
Forbidden,
|
|
51
|
+
InvocationError,
|
|
52
|
+
UnknownAction,
|
|
53
|
+
ZERO_API_KEY_HEADER,
|
|
54
|
+
} from "@eloxiv/contracts"
|
|
55
|
+
import { createHash, timingSafeEqual } from "node:crypto"
|
|
56
|
+
import { fileEntity, FILES_MODULE } from "./files/FileTable.ts"
|
|
57
|
+
import {
|
|
58
|
+
compileSymbolic,
|
|
59
|
+
organisationField,
|
|
60
|
+
toZql,
|
|
61
|
+
UnsupportedPolicy,
|
|
62
|
+
type Pred,
|
|
63
|
+
type References,
|
|
64
|
+
type ZqlBindings,
|
|
65
|
+
type ZqlExpressionBuilder,
|
|
66
|
+
} from "./policy/Compiler.ts"
|
|
67
|
+
import { PolicySet } from "./policy/Policy.ts"
|
|
68
|
+
import { rowContext } from "./policy/Row.ts"
|
|
69
|
+
import { referencesOfModule } from "./policy/Rls.ts"
|
|
70
|
+
import { isKernelModule, isKernelProvided } from "./KernelModule.ts"
|
|
71
|
+
import { Registry } from "./Registry.ts"
|
|
72
|
+
|
|
73
|
+
export const SYNC_QUERY_PATH = "/zero/query"
|
|
74
|
+
export const SYNC_MUTATE_PATH = "/zero/mutate"
|
|
75
|
+
|
|
76
|
+
export interface SyncConfig {
|
|
77
|
+
/** The app's sync schema (`eloxiv.sync.ts`): Zero tables generated from its modules' entities. */
|
|
78
|
+
readonly schema: ZeroSchema
|
|
79
|
+
/** Named queries; each one's entity is the one whose table it reads (and each child's, its own). */
|
|
80
|
+
readonly queries: AnyQueryRegistry | object
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** The module's query cannot be authorised; it is refused, never served unfiltered. */
|
|
84
|
+
export class UnsupportedQuery extends Error {
|
|
85
|
+
override readonly name = "UnsupportedQuery"
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Zero names of the kernel's live tables, which sync filters reach but clients never receive. */
|
|
89
|
+
export const SYNC_ORG_TABLE = "eloxivSyncOrg"
|
|
90
|
+
export const SYNC_FACT_TABLE = "eloxivSyncFact"
|
|
91
|
+
export const SHARE_GRANT_TABLE = "eloxivShareGrant"
|
|
92
|
+
export const SHARE_REDEMPTION_TABLE = "eloxivShareRedemption"
|
|
93
|
+
|
|
94
|
+
const kernelSyncTables = createSchema({
|
|
95
|
+
tables: [
|
|
96
|
+
table(SYNC_ORG_TABLE).from("eloxiv.sync_org").columns({ id: string(), scope: number() }).primaryKey("id"),
|
|
97
|
+
table(SYNC_FACT_TABLE)
|
|
98
|
+
.from("eloxiv.sync_fact")
|
|
99
|
+
.columns({
|
|
100
|
+
scope: number(),
|
|
101
|
+
orgId: string().from("org_id"),
|
|
102
|
+
userId: string().from("user_id"),
|
|
103
|
+
kind: string(),
|
|
104
|
+
value: string(),
|
|
105
|
+
})
|
|
106
|
+
.primaryKey("orgId", "userId", "kind", "value"),
|
|
107
|
+
table(SHARE_GRANT_TABLE)
|
|
108
|
+
.from("eloxiv.share_grant")
|
|
109
|
+
.columns({
|
|
110
|
+
id: string(),
|
|
111
|
+
resourceType: string().from("resource_type"),
|
|
112
|
+
resourceId: string().from("resource_id"),
|
|
113
|
+
granteeKind: string().from("grantee_kind"),
|
|
114
|
+
granteeId: string().from("grantee_id"),
|
|
115
|
+
orgId: string().from("org_id").optional(),
|
|
116
|
+
permission: string(),
|
|
117
|
+
expiresAt: number().from("expires_at").optional(),
|
|
118
|
+
})
|
|
119
|
+
.primaryKey("id"),
|
|
120
|
+
table(SHARE_REDEMPTION_TABLE)
|
|
121
|
+
.from("eloxiv.share_redemption")
|
|
122
|
+
.columns({ grantId: string().from("grant_id"), userId: string().from("user_id") })
|
|
123
|
+
.primaryKey("grantId", "userId"),
|
|
124
|
+
],
|
|
125
|
+
}).tables
|
|
126
|
+
|
|
127
|
+
/** The app's sync schema with the kernel's live tables, so the filters' subqueries map to them. */
|
|
128
|
+
export const withKernelTables = (schema: ZeroSchema): ZeroSchema => ({
|
|
129
|
+
...schema,
|
|
130
|
+
tables: { ...schema.tables, ...kernelSyncTables },
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
type Condition = Record<string, unknown>
|
|
134
|
+
|
|
135
|
+
const literal = (column: string, value: string): Condition => ({
|
|
136
|
+
type: "simple",
|
|
137
|
+
op: "=",
|
|
138
|
+
left: { type: "column", name: column },
|
|
139
|
+
right: { type: "literal", value },
|
|
140
|
+
})
|
|
141
|
+
const all = (...conditions: ReadonlyArray<Condition>): Condition => ({ type: "and", conditions })
|
|
142
|
+
const any = (...conditions: ReadonlyArray<Condition>): Condition => ({ type: "or", conditions })
|
|
143
|
+
|
|
144
|
+
/** EXISTS a row of `table` correlated with the record, matching `where`: never sent to the client. */
|
|
145
|
+
const permissionExists = (
|
|
146
|
+
parentField: ReadonlyArray<string>,
|
|
147
|
+
childField: ReadonlyArray<string>,
|
|
148
|
+
tableName: string,
|
|
149
|
+
alias: string,
|
|
150
|
+
where: Condition | undefined,
|
|
151
|
+
): Condition => ({
|
|
152
|
+
type: "correlatedSubquery",
|
|
153
|
+
op: "EXISTS",
|
|
154
|
+
related: {
|
|
155
|
+
system: "permissions",
|
|
156
|
+
correlation: { parentField, childField },
|
|
157
|
+
subquery: { table: tableName, alias, ...(where === undefined ? {} : { where }) },
|
|
158
|
+
},
|
|
159
|
+
})
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* A live directory test for one replica: "the acting user is a member of the acting organisation" (`member`)
|
|
163
|
+
* or holds `value` as a group, role, permission or email there (`like`: the email matches a pattern). Zero
|
|
164
|
+
* joins on columns only, so the condition reaches the facts from the record through its organisation's
|
|
165
|
+
* `sync_org` row and the constant `scope`. It is a permission subquery: zero-cache evaluates it on its replica
|
|
166
|
+
* and sends none of its rows to the client.
|
|
167
|
+
*/
|
|
168
|
+
export const directoryFact = (
|
|
169
|
+
orgField: string,
|
|
170
|
+
actor: Pick<Actor, "userId" | "orgId">,
|
|
171
|
+
kind: "member" | "group" | "role" | "permission" | "email" | "session",
|
|
172
|
+
value: string,
|
|
173
|
+
n: number,
|
|
174
|
+
op: "=" | "LIKE" = "=",
|
|
175
|
+
): Condition =>
|
|
176
|
+
permissionExists(
|
|
177
|
+
[orgField],
|
|
178
|
+
["id"],
|
|
179
|
+
SYNC_ORG_TABLE,
|
|
180
|
+
`zsubq_eloxiv_org_${n}`,
|
|
181
|
+
permissionExists(
|
|
182
|
+
["scope"],
|
|
183
|
+
["scope"],
|
|
184
|
+
SYNC_FACT_TABLE,
|
|
185
|
+
`zsubq_eloxiv_fact_${n}`,
|
|
186
|
+
all(literal("orgId", actor.orgId), literal("userId", actor.userId), literal("kind", kind), {
|
|
187
|
+
type: "simple",
|
|
188
|
+
op,
|
|
189
|
+
left: { type: "column", name: "value" },
|
|
190
|
+
right: { type: "literal", value },
|
|
191
|
+
}),
|
|
192
|
+
),
|
|
193
|
+
)
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* A live test that the acting user is in the group a record's `field` names (`principal in resource.<attr>`),
|
|
197
|
+
* in the acting organisation: the record's column is correlated with the fact's value directly. Like
|
|
198
|
+
* `directoryFact`, a permission subquery whose rows are never sent to the client.
|
|
199
|
+
*/
|
|
200
|
+
export const groupFieldFact = (field: string, actor: Pick<Actor, "userId" | "orgId">, n: number): Condition =>
|
|
201
|
+
permissionExists(
|
|
202
|
+
[field],
|
|
203
|
+
["value"],
|
|
204
|
+
SYNC_FACT_TABLE,
|
|
205
|
+
`zsubq_eloxiv_group_${n}`,
|
|
206
|
+
all(literal("orgId", actor.orgId), literal("userId", actor.userId), literal("kind", "group")),
|
|
207
|
+
)
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* A live test that the acting user holds the role or permission a record's `field` names
|
|
211
|
+
* (`principal.roles.contains(resource.<attr>)`), in the acting organisation: the record's column is correlated
|
|
212
|
+
* with the fact's value, as for `groupFieldFact`. A permission subquery whose rows are never sent to the client.
|
|
213
|
+
*/
|
|
214
|
+
export const directoryFieldFact = (
|
|
215
|
+
field: string,
|
|
216
|
+
kind: "role" | "permission",
|
|
217
|
+
actor: Pick<Actor, "userId" | "orgId">,
|
|
218
|
+
n: number,
|
|
219
|
+
): Condition =>
|
|
220
|
+
permissionExists(
|
|
221
|
+
[field],
|
|
222
|
+
["value"],
|
|
223
|
+
SYNC_FACT_TABLE,
|
|
224
|
+
`zsubq_eloxiv_${kind}_${n}`,
|
|
225
|
+
all(literal("orgId", actor.orgId), literal("userId", actor.userId), literal("kind", kind)),
|
|
226
|
+
)
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* A live test that the acting principal holds a grant with `permission` on the record (`resource.<sharing
|
|
230
|
+
* attribute>.contains(principal)`): a grant to the user, to a group it is in in the acting organisation, to the
|
|
231
|
+
* acting organisation, or a link of the acting organisation it redeemed; not expired when the query was
|
|
232
|
+
* transformed (the kernel deletes grants as they expire, which reaches connected replicas live). A grant counts
|
|
233
|
+
* only where the record's organisation (`orgField`), the grant's and the acting organisation are one.
|
|
234
|
+
*/
|
|
235
|
+
export const sharedFact = (
|
|
236
|
+
entity: AnyEntity,
|
|
237
|
+
orgField: string,
|
|
238
|
+
permission: string,
|
|
239
|
+
actor: Pick<Actor, "userId" | "orgId">,
|
|
240
|
+
n: number,
|
|
241
|
+
now: number,
|
|
242
|
+
): Condition =>
|
|
243
|
+
all(
|
|
244
|
+
literal(orgField, actor.orgId),
|
|
245
|
+
permissionExists(
|
|
246
|
+
[entity.primaryKey],
|
|
247
|
+
["resourceId"],
|
|
248
|
+
SHARE_GRANT_TABLE,
|
|
249
|
+
`zsubq_eloxiv_share_${n}`,
|
|
250
|
+
all(
|
|
251
|
+
literal("resourceType", entity.cedarType),
|
|
252
|
+
literal("permission", permission),
|
|
253
|
+
literal("orgId", actor.orgId),
|
|
254
|
+
any(
|
|
255
|
+
{
|
|
256
|
+
type: "simple",
|
|
257
|
+
op: "IS",
|
|
258
|
+
left: { type: "column", name: "expiresAt" },
|
|
259
|
+
right: { type: "literal", value: null },
|
|
260
|
+
},
|
|
261
|
+
{
|
|
262
|
+
type: "simple",
|
|
263
|
+
op: ">",
|
|
264
|
+
left: { type: "column", name: "expiresAt" },
|
|
265
|
+
right: { type: "literal", value: now },
|
|
266
|
+
},
|
|
267
|
+
),
|
|
268
|
+
any(
|
|
269
|
+
all(literal("granteeKind", "user"), literal("granteeId", actor.userId)),
|
|
270
|
+
all(literal("granteeKind", "org"), literal("granteeId", actor.orgId)),
|
|
271
|
+
all(
|
|
272
|
+
literal("granteeKind", "group"),
|
|
273
|
+
literal("orgId", actor.orgId),
|
|
274
|
+
permissionExists(
|
|
275
|
+
["granteeId"],
|
|
276
|
+
["value"],
|
|
277
|
+
SYNC_FACT_TABLE,
|
|
278
|
+
`zsubq_eloxiv_share_group_${n}`,
|
|
279
|
+
all(literal("orgId", actor.orgId), literal("userId", actor.userId), literal("kind", "group")),
|
|
280
|
+
),
|
|
281
|
+
),
|
|
282
|
+
all(
|
|
283
|
+
literal("granteeKind", "link"),
|
|
284
|
+
literal("orgId", actor.orgId),
|
|
285
|
+
permissionExists(
|
|
286
|
+
["id"],
|
|
287
|
+
["grantId"],
|
|
288
|
+
SHARE_REDEMPTION_TABLE,
|
|
289
|
+
`zsubq_eloxiv_share_link_${n}`,
|
|
290
|
+
literal("userId", actor.userId),
|
|
291
|
+
),
|
|
292
|
+
),
|
|
293
|
+
),
|
|
294
|
+
),
|
|
295
|
+
),
|
|
296
|
+
)
|
|
297
|
+
|
|
298
|
+
interface ZeroColumn {
|
|
299
|
+
readonly type?: string
|
|
300
|
+
readonly optional?: boolean
|
|
301
|
+
readonly serverName?: string
|
|
302
|
+
}
|
|
303
|
+
interface ZeroTable {
|
|
304
|
+
readonly name: string
|
|
305
|
+
readonly serverName?: string
|
|
306
|
+
readonly columns: Readonly<Record<string, ZeroColumn>>
|
|
307
|
+
readonly primaryKey: ReadonlyArray<string>
|
|
308
|
+
readonly uniqueKeys?: ReadonlyArray<ReadonlyArray<string>>
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
const qualifiedName = (table: { readonly name: string; readonly serverName?: string | undefined }) => {
|
|
312
|
+
const name = table.serverName ?? table.name
|
|
313
|
+
return name.includes(".") ? name : `public.${name}`
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/** The Zero table (by client name) of the app's schema that reads `entity`'s table. */
|
|
317
|
+
const zeroTableOf = (schema: ZeroSchema, entity: AnyEntity): string | undefined => {
|
|
318
|
+
const expected = `${entity.table.schema}.${entity.table.name}`
|
|
319
|
+
for (const [name, t] of Object.entries(schema.tables as unknown as Readonly<Record<string, ZeroTable>>)) {
|
|
320
|
+
if (qualifiedName(t) === expected) return name
|
|
321
|
+
}
|
|
322
|
+
return undefined
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* Bindings of a symbolic read filter for one replica: its actor, and live tests of the directory, of sharing
|
|
327
|
+
* grants and of referenced records, each relative to the entity it is evaluated on.
|
|
328
|
+
*/
|
|
329
|
+
export const liveBindings = (
|
|
330
|
+
actor: Pick<Actor, "userId" | "orgId">,
|
|
331
|
+
schema: ZeroSchema,
|
|
332
|
+
now = Date.now(),
|
|
333
|
+
/**
|
|
334
|
+
* The person's session the replica was transformed for: every query then also needs its live fact (`session`,
|
|
335
|
+
* recorded by the query endpoint while the session holds, deleted when the kernel ends it).
|
|
336
|
+
*/
|
|
337
|
+
sessionId?: string,
|
|
338
|
+
) => {
|
|
339
|
+
let n = 0
|
|
340
|
+
const orgFieldOf = (entity: AnyEntity) => {
|
|
341
|
+
const field = organisationField(entity)
|
|
342
|
+
if (field === undefined) {
|
|
343
|
+
throw new UnsupportedQuery(
|
|
344
|
+
`${entity.cedarType} has no organisation column, so its directory tests cannot be synced`,
|
|
345
|
+
)
|
|
346
|
+
}
|
|
347
|
+
return field
|
|
348
|
+
}
|
|
349
|
+
const bindings: ZqlBindings<any> = {
|
|
350
|
+
actor: actor.userId,
|
|
351
|
+
org: actor.orgId,
|
|
352
|
+
directory: (entity, kind, value) => directoryFact(orgFieldOf(entity), actor, kind, value, n++),
|
|
353
|
+
groupField: (_entity, field) => groupFieldFact(field, actor, n++),
|
|
354
|
+
directoryField: (_entity, kind, field) => directoryFieldFact(field, kind, actor, n++),
|
|
355
|
+
shared: (entity, permission) => sharedFact(entity, orgFieldOf(entity), permission, actor, n++, now),
|
|
356
|
+
principalAttr: (entity, attribute, op, value) =>
|
|
357
|
+
directoryFact(orgFieldOf(entity), actor, attribute, value, n++, op === "eq" ? "=" : "LIKE"),
|
|
358
|
+
reference: (_entity, field, target, inner) => {
|
|
359
|
+
const zeroTable = zeroTableOf(schema, target)
|
|
360
|
+
if (zeroTable === undefined) {
|
|
361
|
+
throw new UnsupportedQuery(
|
|
362
|
+
`The sync schema has no table for ${target.cedarType}, which a read policy references`,
|
|
363
|
+
)
|
|
364
|
+
}
|
|
365
|
+
return permissionExists([field], [target.primaryKey], zeroTable, `zsubq_eloxiv_ref_${n++}`, inner)
|
|
366
|
+
},
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* The live test every query's rows pass, on a row whose organisation is in `orgField`: the person is a member of
|
|
370
|
+
* the acting organisation, and the session the replica was transformed for has not ended. Every scope function
|
|
371
|
+
* (`scopeQuery`, `scopeFileQuery`) tests it through here (sync-scope-session.test.ts checks that each does).
|
|
372
|
+
*/
|
|
373
|
+
const memberOn = (orgField: string): Condition =>
|
|
374
|
+
sessionId === undefined
|
|
375
|
+
? directoryFact(orgField, actor, "member", "", n++)
|
|
376
|
+
: all(
|
|
377
|
+
directoryFact(orgField, actor, "member", "", n++),
|
|
378
|
+
directoryFact(orgField, actor, "session", sessionId, n++),
|
|
379
|
+
)
|
|
380
|
+
const member = (entity: AnyEntity): Condition => memberOn(orgFieldOf(entity))
|
|
381
|
+
return { bindings, member, memberOn }
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/** An entity's compiled read filter and the entities it may reference. */
|
|
385
|
+
export interface ReadFilter {
|
|
386
|
+
readonly pred: Pred
|
|
387
|
+
readonly references: References
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
interface ScopeContext {
|
|
391
|
+
readonly schema: ZeroSchema
|
|
392
|
+
/** The registered entity reading this table (server name `schema.table`), if any. */
|
|
393
|
+
readonly entityOfTable: (qualified: string) => AnyEntity | undefined
|
|
394
|
+
/** The entity's symbolic read filter. */
|
|
395
|
+
readonly readFilter: (entity: AnyEntity) => ReadFilter
|
|
396
|
+
readonly live: ReturnType<typeof liveBindings>
|
|
397
|
+
readonly eb: ZqlExpressionBuilder<any>
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/** The entity's read filter, live for this replica, including its membership test. */
|
|
401
|
+
const filterCondition = (entity: AnyEntity, context: ScopeContext): Condition => {
|
|
402
|
+
const filter = context.readFilter(entity)
|
|
403
|
+
try {
|
|
404
|
+
return context.eb.and(
|
|
405
|
+
context.live.member(entity),
|
|
406
|
+
toZql(filter.pred, entity, context.eb, context.live.bindings, filter.references),
|
|
407
|
+
)
|
|
408
|
+
} catch (error) {
|
|
409
|
+
if (error instanceof UnsupportedPolicy) throw new UnsupportedQuery(error.message)
|
|
410
|
+
throw error
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
type Ast = Record<string, any>
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* Authorise a subquery (a `related()` child or a `whereExists()` condition): its table must be a registered
|
|
418
|
+
* entity's, and its rows are filtered by that entity's read policy, recursively for its own children.
|
|
419
|
+
*/
|
|
420
|
+
const authoriseSubquery = (subquery: Ast, name: string, context: ScopeContext): Ast => {
|
|
421
|
+
const zeroTable = (context.schema.tables as unknown as Readonly<Record<string, ZeroTable>>)[String(subquery["table"])]
|
|
422
|
+
if (zeroTable === undefined) {
|
|
423
|
+
throw new UnsupportedQuery(
|
|
424
|
+
`Query ${name} reaches ${String(subquery["table"])}, which the sync schema does not declare`,
|
|
425
|
+
)
|
|
426
|
+
}
|
|
427
|
+
const entity = context.entityOfTable(qualifiedName(zeroTable))
|
|
428
|
+
if (entity === undefined) {
|
|
429
|
+
throw new UnsupportedQuery(
|
|
430
|
+
`Query ${name} reaches ${qualifiedName(zeroTable)}, which no entity contract governs, so it is refused`,
|
|
431
|
+
)
|
|
432
|
+
}
|
|
433
|
+
const own = authoriseChildren(subquery, name, context)
|
|
434
|
+
return { ...own, where: context.eb.and(own["where"], filterCondition(entity, context)) }
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
/** A condition with every correlated subquery in it authorised. */
|
|
438
|
+
const authoriseCondition = (condition: Ast | undefined, name: string, context: ScopeContext): Ast | undefined => {
|
|
439
|
+
if (condition === undefined) return undefined
|
|
440
|
+
if (condition["type"] === "and" || condition["type"] === "or") {
|
|
441
|
+
return {
|
|
442
|
+
...condition,
|
|
443
|
+
conditions: (condition["conditions"] as ReadonlyArray<Ast>).map((c) => authoriseCondition(c, name, context)),
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
if (condition["type"] === "correlatedSubquery") {
|
|
447
|
+
const related = condition["related"] as Ast
|
|
448
|
+
if (related["system"] === "permissions") {
|
|
449
|
+
throw new UnsupportedQuery(`Query ${name} carries a permission subquery; only the kernel adds those`)
|
|
450
|
+
}
|
|
451
|
+
return { ...condition, related: { ...related, subquery: authoriseSubquery(related["subquery"], name, context) } }
|
|
452
|
+
}
|
|
453
|
+
return condition
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/** A query (or subquery) AST with its `related()` children and its `whereExists()` subqueries authorised. */
|
|
457
|
+
const authoriseChildren = (ast: Ast, name: string, context: ScopeContext): Ast => {
|
|
458
|
+
const related = ast["related"] as ReadonlyArray<Ast> | undefined
|
|
459
|
+
const result: Ast = { ...ast }
|
|
460
|
+
if (related !== undefined) {
|
|
461
|
+
const children: Array<Ast> = []
|
|
462
|
+
for (const child of related) {
|
|
463
|
+
if (child["system"] === "permissions") {
|
|
464
|
+
throw new UnsupportedQuery(`Query ${name} carries a permission subquery; only the kernel adds those`)
|
|
465
|
+
}
|
|
466
|
+
children.push({ ...child, subquery: authoriseSubquery(child["subquery"], name, context) })
|
|
467
|
+
}
|
|
468
|
+
result["related"] = children
|
|
469
|
+
}
|
|
470
|
+
const where = authoriseCondition(ast["where"], name, context)
|
|
471
|
+
if (where === undefined) delete result["where"]
|
|
472
|
+
else result["where"] = where
|
|
473
|
+
return result
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
/**
|
|
477
|
+
* Scope a module's named query to what the actor may read: the entity's compiled read filter on the query's own
|
|
478
|
+
* table, and each related table's own entity's read filter on its rows (`related()`, `whereExists()`). Every
|
|
479
|
+
* filter is bound to the replica's actor and organisation, and its directory tests, grants and references are
|
|
480
|
+
* evaluated live (`liveBindings`). Only the kernel's own permission subqueries reach kernel tables; a query
|
|
481
|
+
* that reaches any table no entity governs is refused.
|
|
482
|
+
*
|
|
483
|
+
* Returns the query zero-cache runs (its AST, carried the way Zero's query transform reads it).
|
|
484
|
+
*/
|
|
485
|
+
export const scopeQuery = (
|
|
486
|
+
built: any,
|
|
487
|
+
name: string,
|
|
488
|
+
schema: ZeroSchema,
|
|
489
|
+
options: {
|
|
490
|
+
readonly readFilter: (entity: AnyEntity) => ReadFilter
|
|
491
|
+
readonly entityOfTable: (qualified: string) => AnyEntity | undefined
|
|
492
|
+
readonly live: ReturnType<typeof liveBindings>
|
|
493
|
+
},
|
|
494
|
+
) => {
|
|
495
|
+
// The policy applied is the policy of the table the query actually reads (decision 9: nothing declares it
|
|
496
|
+
// beside the query): resolve the query's Zero table to its database table through the app's Zero schema, and
|
|
497
|
+
// that table to the entity whose table it is.
|
|
498
|
+
const zeroTable = (schema.tables as Record<string, { readonly serverName?: string; readonly name: string }>)[
|
|
499
|
+
String(built.ast?.table ?? "")
|
|
500
|
+
]
|
|
501
|
+
if (zeroTable === undefined)
|
|
502
|
+
throw new UnsupportedQuery(`Query ${name} reads a table the sync schema does not declare`)
|
|
503
|
+
const qualified = qualifiedName(zeroTable)
|
|
504
|
+
const entity = options.entityOfTable(qualified)
|
|
505
|
+
if (entity === undefined) {
|
|
506
|
+
throw new UnsupportedQuery(`Query ${name} reads ${qualified}, which no entity contract governs, so it is refused`)
|
|
507
|
+
}
|
|
508
|
+
// Zero's own expression builder (its `and`, `or` and `not` are independent of the table).
|
|
509
|
+
let eb: ZqlExpressionBuilder<any> | undefined
|
|
510
|
+
built.where((e: ZqlExpressionBuilder<any>) => {
|
|
511
|
+
eb = e
|
|
512
|
+
return e.and()
|
|
513
|
+
})
|
|
514
|
+
const context: ScopeContext = {
|
|
515
|
+
schema,
|
|
516
|
+
entityOfTable: options.entityOfTable,
|
|
517
|
+
readFilter: options.readFilter,
|
|
518
|
+
live: options.live,
|
|
519
|
+
eb: eb!,
|
|
520
|
+
}
|
|
521
|
+
const authorised = authoriseChildren(built.ast as Ast, name, context)
|
|
522
|
+
const ast = isolateSubqueryOrs(
|
|
523
|
+
{ ...authorised, where: eb!.and(authorised["where"], filterCondition(entity, context)) },
|
|
524
|
+
schema,
|
|
525
|
+
)
|
|
526
|
+
return { [queryInternalsTag]: true, ast }
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
/** The kernel's file metadata table (the Files contract), as the sync schema names it on the server. */
|
|
530
|
+
export const FILE_TABLE = "eloxiv.file"
|
|
531
|
+
|
|
532
|
+
/** Does the query read `qualified` (through the app's Zero schema)? */
|
|
533
|
+
const readsTable = (built: any, schema: ZeroSchema, qualified: string) => {
|
|
534
|
+
const zeroTable = (schema.tables as Record<string, { readonly serverName?: string; readonly name: string }>)[
|
|
535
|
+
String(built.ast?.table ?? "")
|
|
536
|
+
]
|
|
537
|
+
return zeroTable !== undefined && qualifiedName(zeroTable) === qualified
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
/**
|
|
541
|
+
* Scope a named query over the kernel's file metadata (`eloxiv.file`, the Files contract) to what the replica's
|
|
542
|
+
* actor may read: files of the acting organisation, not deleted, that are either staged and uploaded by the
|
|
543
|
+
* actor, or attached to a record of an entity that declares `files` and that the actor may read, by that entity's
|
|
544
|
+
* read filter, evaluated live through a permission subquery on the entity's own sync table (never sent to the
|
|
545
|
+
* client). A file whose entity's table is not in the app's sync schema is never synced (fail closed). Children
|
|
546
|
+
* of the query (`related()`, `whereExists()`) are authorised as everywhere else.
|
|
547
|
+
*/
|
|
548
|
+
export const scopeFileQuery = (
|
|
549
|
+
built: any,
|
|
550
|
+
name: string,
|
|
551
|
+
schema: ZeroSchema,
|
|
552
|
+
options: {
|
|
553
|
+
readonly readFilter: (entity: AnyEntity) => ReadFilter
|
|
554
|
+
readonly entityOfTable: (qualified: string) => AnyEntity | undefined
|
|
555
|
+
readonly live: ReturnType<typeof liveBindings>
|
|
556
|
+
readonly actor: Pick<Actor, "userId" | "orgId">
|
|
557
|
+
readonly fileEntities: ReadonlyArray<AnyEntity>
|
|
558
|
+
},
|
|
559
|
+
) => {
|
|
560
|
+
const zeroTable = (schema.tables as Record<string, { readonly serverName?: string; readonly name: string }>)[
|
|
561
|
+
String(built.ast?.table ?? "")
|
|
562
|
+
]
|
|
563
|
+
if (zeroTable === undefined || qualifiedName(zeroTable) !== FILE_TABLE) {
|
|
564
|
+
throw new UnsupportedQuery(`Query ${name} is registered as file metadata but does not read ${FILE_TABLE}`)
|
|
565
|
+
}
|
|
566
|
+
let eb: ZqlExpressionBuilder<any> | undefined
|
|
567
|
+
built.where((e: ZqlExpressionBuilder<any>) => {
|
|
568
|
+
eb = e
|
|
569
|
+
return e.and()
|
|
570
|
+
})
|
|
571
|
+
const context: ScopeContext = {
|
|
572
|
+
schema,
|
|
573
|
+
entityOfTable: options.entityOfTable,
|
|
574
|
+
readFilter: options.readFilter,
|
|
575
|
+
live: options.live,
|
|
576
|
+
eb: eb!,
|
|
577
|
+
}
|
|
578
|
+
const actor = options.actor
|
|
579
|
+
const attached: Array<Condition> = []
|
|
580
|
+
let n = 0
|
|
581
|
+
for (const entity of options.fileEntities) {
|
|
582
|
+
const table = zeroTableOf(schema, entity)
|
|
583
|
+
if (table === undefined) continue
|
|
584
|
+
attached.push(
|
|
585
|
+
all(
|
|
586
|
+
literal("ownerType", entity.cedarType),
|
|
587
|
+
permissionExists(
|
|
588
|
+
["ownerId"],
|
|
589
|
+
[entity.primaryKey],
|
|
590
|
+
table,
|
|
591
|
+
`zsubq_eloxiv_file_${n++}`,
|
|
592
|
+
filterCondition(entity, context),
|
|
593
|
+
),
|
|
594
|
+
),
|
|
595
|
+
)
|
|
596
|
+
}
|
|
597
|
+
const staged = all(
|
|
598
|
+
{ type: "simple", op: "IS", left: { type: "column", name: "ownerType" }, right: { type: "literal", value: null } },
|
|
599
|
+
literal("uploadedBy", actor.userId),
|
|
600
|
+
)
|
|
601
|
+
const filter = all(
|
|
602
|
+
literal("orgId", actor.orgId),
|
|
603
|
+
// The same live test as every query's (membership, and the replica's session not ended): staged files too.
|
|
604
|
+
options.live.memberOn("orgId"),
|
|
605
|
+
{ type: "simple", op: "!=", left: { type: "column", name: "state" }, right: { type: "literal", value: "deleted" } },
|
|
606
|
+
any(staged, ...attached),
|
|
607
|
+
)
|
|
608
|
+
const authorised = authoriseChildren(built.ast as Ast, name, context)
|
|
609
|
+
const ast = isolateSubqueryOrs({ ...authorised, where: eb!.and(authorised["where"], filter) }, schema)
|
|
610
|
+
return { [queryInternalsTag]: true, ast }
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
const holdsSubquery = (condition: Ast): boolean =>
|
|
614
|
+
condition["type"] === "correlatedSubquery" ||
|
|
615
|
+
((condition["type"] === "and" || condition["type"] === "or") &&
|
|
616
|
+
(condition["conditions"] as ReadonlyArray<Ast>).some(holdsSubquery))
|
|
617
|
+
|
|
618
|
+
/**
|
|
619
|
+
* The query with each OR that holds a subquery moved into a subquery of its own, unless it is the whole condition
|
|
620
|
+
* of its (sub)query: `EXISTS (the same table, by primary key, WHERE the OR)`, a permission subquery, which holds
|
|
621
|
+
* for a row exactly when the OR does. Identical siblings of an AND or an OR are kept once.
|
|
622
|
+
*
|
|
623
|
+
* zero-cache runs an OR that holds a subquery as a fan-out and a fan-in, and passes every filter signal down each
|
|
624
|
+
* of its branches to everything after it in the pipeline, so a pipeline holding several such ORs (in a row, or
|
|
625
|
+
* nested) does work multiplying their branch counts for every row. A read filter compiled from nested `if`s
|
|
626
|
+
* holds dozens: one generated case took zero-cache 125 s to hydrate three rows (the sync property's seed
|
|
627
|
+
* 672188315). Isolated, each OR is the only one in its pipeline, and the work adds up instead.
|
|
628
|
+
*/
|
|
629
|
+
export const isolateSubqueryOrs = (ast: Ast, schema: ZeroSchema): Ast => {
|
|
630
|
+
let n = 0
|
|
631
|
+
const tables = schema.tables as unknown as Readonly<Record<string, { readonly primaryKey: ReadonlyArray<string> }>>
|
|
632
|
+
const dedupe = (conditions: ReadonlyArray<Ast>): ReadonlyArray<Ast> => [
|
|
633
|
+
...new Map(conditions.map((c) => [JSON.stringify(c), c] as const)).values(),
|
|
634
|
+
]
|
|
635
|
+
/** A (sub)query with its condition, and its children's, isolated. */
|
|
636
|
+
const query = (q: Ast): Ast => {
|
|
637
|
+
const result: Ast = { ...q }
|
|
638
|
+
if (q["where"] !== undefined) result["where"] = root(q["where"], String(q["table"]))
|
|
639
|
+
const related = q["related"] as ReadonlyArray<Ast> | undefined
|
|
640
|
+
if (related !== undefined) {
|
|
641
|
+
result["related"] = related.map((r) => Object.assign({}, r, { subquery: query(r["subquery"]) }))
|
|
642
|
+
}
|
|
643
|
+
return result
|
|
644
|
+
}
|
|
645
|
+
/** A (sub)query's whole condition: an OR there runs alone in its pipeline and stays. */
|
|
646
|
+
const root = (condition: Ast, table: string): Ast =>
|
|
647
|
+
condition["type"] === "or" && holdsSubquery(condition)
|
|
648
|
+
? {
|
|
649
|
+
...condition,
|
|
650
|
+
conditions: dedupe((condition["conditions"] as ReadonlyArray<Ast>).map((c) => inner(c, table))),
|
|
651
|
+
}
|
|
652
|
+
: inner(condition, table)
|
|
653
|
+
const inner = (condition: Ast, table: string): Ast => {
|
|
654
|
+
switch (condition["type"]) {
|
|
655
|
+
case "correlatedSubquery": {
|
|
656
|
+
const related = condition["related"] as Ast
|
|
657
|
+
return { ...condition, related: { ...related, subquery: query(related["subquery"]) } }
|
|
658
|
+
}
|
|
659
|
+
case "and":
|
|
660
|
+
return {
|
|
661
|
+
...condition,
|
|
662
|
+
conditions: dedupe((condition["conditions"] as ReadonlyArray<Ast>).map((c) => inner(c, table))),
|
|
663
|
+
}
|
|
664
|
+
case "or": {
|
|
665
|
+
if (!holdsSubquery(condition)) return { ...condition, conditions: dedupe(condition["conditions"]) }
|
|
666
|
+
const key = tables[table]?.primaryKey
|
|
667
|
+
// (A table the schema has no key for keeps its OR where it is.)
|
|
668
|
+
if (key === undefined || key.length === 0) {
|
|
669
|
+
return {
|
|
670
|
+
...condition,
|
|
671
|
+
conditions: dedupe((condition["conditions"] as ReadonlyArray<Ast>).map((c) => inner(c, table))),
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
return permissionExists(key, key, table, `zsubq_eloxiv_or_${n++}`, root(condition, table))
|
|
675
|
+
}
|
|
676
|
+
default:
|
|
677
|
+
return condition
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
return query(ast)
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
/**
|
|
684
|
+
* Check the app's Zero schema against the entity contracts before serving it. The schema is generated from the
|
|
685
|
+
* entities (decision 9), so a mismatch means a stale or edited generated file. The compiled read filter names
|
|
686
|
+
* entity fields and zero-cache evaluates them on the Zero columns of the same name: a column that reads a
|
|
687
|
+
* different database column (`.from(...)`) would make the filter test the wrong data. So every Zero table that
|
|
688
|
+
* reads an entity's table must be exactly what the generator writes for it: the entity syncs, every column is a
|
|
689
|
+
* synced field that reads the field's column with its type and nullability, every synced field and the primary
|
|
690
|
+
* key are there, and the organisation column the live directory tests go through exists. Returns the problems
|
|
691
|
+
* found (empty when the schema is safe to serve).
|
|
692
|
+
*/
|
|
693
|
+
export const syncSchemaProblems = (
|
|
694
|
+
schema: ZeroSchema,
|
|
695
|
+
entities: ReadonlyArray<AnyEntity>,
|
|
696
|
+
options: {
|
|
697
|
+
/** Postgres schemas of modules (the kernel-provided ones) whose tables an app adds all or none of. */
|
|
698
|
+
readonly optionalSchemas?: ReadonlySet<string>
|
|
699
|
+
} = {},
|
|
700
|
+
): ReadonlyArray<string> => {
|
|
701
|
+
const problems: Array<string> = []
|
|
702
|
+
const tables = schema.tables as unknown as Readonly<Record<string, ZeroTable>>
|
|
703
|
+
const zeroNameOf = (qualified: string) => Object.entries(tables).find(([, t]) => qualifiedName(t) === qualified)?.[0]
|
|
704
|
+
for (const reserved of Object.keys(kernelSyncTables)) {
|
|
705
|
+
if (reserved in tables) problems.push(`Sync table ${reserved} is reserved for the kernel's live tables`)
|
|
706
|
+
}
|
|
707
|
+
for (const [zeroName, table] of Object.entries(tables)) {
|
|
708
|
+
const entity = entities.find((e) => `${e.table.schema}.${e.table.name}` === qualifiedName(table))
|
|
709
|
+
if (entity === undefined) continue
|
|
710
|
+
if (entity.sync === false) {
|
|
711
|
+
problems.push(`Sync table ${zeroName} reads ${entity.cedarType}, which does not sync (sync: false)`)
|
|
712
|
+
continue
|
|
713
|
+
}
|
|
714
|
+
if (organisationField(entity) === undefined) {
|
|
715
|
+
problems.push(
|
|
716
|
+
`Sync table ${zeroName} reads ${entity.cedarType}, which has no organisation column (an Eloxiv::Org policy attribute): its read filter's directory tests are evaluated through it`,
|
|
717
|
+
)
|
|
718
|
+
}
|
|
719
|
+
const columns = entity.columns as Readonly<Record<string, string>>
|
|
720
|
+
const storage = entity.storage as Readonly<Record<string, EntityField>>
|
|
721
|
+
// Policy-relevant fields first, with the messages a tampered mapping is reported with.
|
|
722
|
+
const policyFields = new Set<string>([entity.primaryKey])
|
|
723
|
+
for (const attribute of Object.values(entity.policyAttributes)) {
|
|
724
|
+
if (attribute.kind === "column") policyFields.add(attribute.field)
|
|
725
|
+
}
|
|
726
|
+
for (const field of policyFields) {
|
|
727
|
+
const column = table.columns[field]
|
|
728
|
+
if (column === undefined) {
|
|
729
|
+
problems.push(`Sync table ${zeroName} has no column for ${entity.cedarType} policy field ${field}`)
|
|
730
|
+
continue
|
|
731
|
+
}
|
|
732
|
+
const reads = column.serverName ?? field
|
|
733
|
+
if (reads !== columns[field]) {
|
|
734
|
+
problems.push(
|
|
735
|
+
`Sync table ${zeroName} maps ${entity.cedarType} policy field ${field} to column ${reads}, but the entity stores it in ${columns[field]}`,
|
|
736
|
+
)
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
// Then everything else the generator writes.
|
|
740
|
+
const synced = new Set(entity.sync.fields)
|
|
741
|
+
for (const [field, column] of Object.entries(table.columns)) {
|
|
742
|
+
const declared = storage[field]
|
|
743
|
+
if (declared === undefined || !synced.has(field)) {
|
|
744
|
+
problems.push(`Sync table ${zeroName} has column ${field}, which ${entity.cedarType} does not sync`)
|
|
745
|
+
continue
|
|
746
|
+
}
|
|
747
|
+
const reads = column.serverName ?? field
|
|
748
|
+
if (!policyFields.has(field) && reads !== declared.column) {
|
|
749
|
+
problems.push(
|
|
750
|
+
`Sync table ${zeroName} maps ${entity.cedarType} field ${field} to column ${reads}, but the entity stores it in ${declared.column}`,
|
|
751
|
+
)
|
|
752
|
+
}
|
|
753
|
+
if (column.type !== declared.type) {
|
|
754
|
+
problems.push(
|
|
755
|
+
`Sync table ${zeroName} types ${entity.cedarType} field ${field} as ${String(column.type)}, but the entity's column is ${String(declared.type)}`,
|
|
756
|
+
)
|
|
757
|
+
}
|
|
758
|
+
if (Boolean(column.optional) !== declared.nullable) {
|
|
759
|
+
problems.push(
|
|
760
|
+
`Sync table ${zeroName} makes ${entity.cedarType} field ${field} ${column.optional ? "optional" : "required"}, but its column ${declared.nullable ? "admits" : "never holds"} NULL`,
|
|
761
|
+
)
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
for (const field of synced) {
|
|
765
|
+
if (!(field in table.columns) && !policyFields.has(field)) {
|
|
766
|
+
problems.push(`Sync table ${zeroName} has no column for ${entity.cedarType} field ${field}, which it syncs`)
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
if (table.primaryKey.length !== 1 || table.primaryKey[0] !== entity.primaryKey) {
|
|
770
|
+
problems.push(
|
|
771
|
+
`Sync table ${zeroName}'s primary key is ${table.primaryKey.join(", ")}, but ${entity.cedarType}'s is ${entity.primaryKey}`,
|
|
772
|
+
)
|
|
773
|
+
}
|
|
774
|
+
// Unique keys: the entity's, among the fields it syncs.
|
|
775
|
+
const expectedKeys = new Set(
|
|
776
|
+
entity.uniqueKeys.filter((key) => key.every((field) => synced.has(field))).map((key) => key.join(", ")),
|
|
777
|
+
)
|
|
778
|
+
const actualKeys = new Set((table.uniqueKeys ?? []).map((key) => key.join(", ")))
|
|
779
|
+
for (const key of actualKeys) {
|
|
780
|
+
if (!expectedKeys.has(key))
|
|
781
|
+
problems.push(`Sync table ${zeroName} has unique key ${key}, which ${entity.cedarType} has not`)
|
|
782
|
+
}
|
|
783
|
+
for (const key of expectedKeys) {
|
|
784
|
+
if (!actualKeys.has(key))
|
|
785
|
+
problems.push(`Sync table ${zeroName} has no unique key ${key}, which ${entity.cedarType} declares`)
|
|
786
|
+
}
|
|
787
|
+
// Relationships: the entity's Drizzle relations, and the sharing grants.
|
|
788
|
+
const expected = expectedRelationships(entity, entities, zeroNameOf)
|
|
789
|
+
const actual =
|
|
790
|
+
(schema.relationships as unknown as Readonly<Record<string, Readonly<Record<string, ReadonlyArray<Hop>>>>>)[
|
|
791
|
+
zeroName
|
|
792
|
+
] ?? {}
|
|
793
|
+
for (const [name, hops] of Object.entries(actual)) {
|
|
794
|
+
const want = expected.get(name)
|
|
795
|
+
if (want === undefined) {
|
|
796
|
+
problems.push(`Sync table ${zeroName} has relationship ${name}, which ${entity.cedarType} does not declare`)
|
|
797
|
+
continue
|
|
798
|
+
}
|
|
799
|
+
const hop = hops.length === 1 ? hops[0]! : undefined
|
|
800
|
+
if (
|
|
801
|
+
hop === undefined ||
|
|
802
|
+
hop.cardinality !== want.cardinality ||
|
|
803
|
+
hop.destSchema !== want.destSchema ||
|
|
804
|
+
hop.sourceField.join(",") !== want.sourceField.join(",") ||
|
|
805
|
+
hop.destField.join(",") !== want.destField.join(",")
|
|
806
|
+
) {
|
|
807
|
+
problems.push(
|
|
808
|
+
`Sync table ${zeroName}'s relationship ${name} joins ${hops.map((h) => `${h.sourceField.join(", ")} to ${h.destField.join(", ")} of ${h.destSchema}`).join(" then ")}, but ${entity.cedarType} declares ${want.sourceField.join(", ")} to ${want.destField.join(", ")} of ${want.destSchema} (${want.cardinality})`,
|
|
809
|
+
)
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
for (const name of expected.keys()) {
|
|
813
|
+
if (!(name in actual))
|
|
814
|
+
problems.push(`Sync table ${zeroName} has no relationship ${name}, which ${entity.cedarType} declares`)
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
// Every synced entity has its table: an app's schema composes all of its modules' generated tables. A
|
|
818
|
+
// kernel-provided module's tables are the app's choice (it adds them with the module), but all of them or none.
|
|
819
|
+
const present = new Set(Object.values(tables).map(qualifiedName))
|
|
820
|
+
const has = (entity: AnyEntity) => present.has(`${entity.table.schema}.${entity.table.name}`)
|
|
821
|
+
for (const entity of entities) {
|
|
822
|
+
if (entity.sync === false || has(entity)) continue
|
|
823
|
+
const optional = options.optionalSchemas?.has(entity.table.schema) === true
|
|
824
|
+
const anyOfModule = entities.some(
|
|
825
|
+
(other) => other.table.schema === entity.table.schema && other.sync !== false && has(other),
|
|
826
|
+
)
|
|
827
|
+
if (optional && !anyOfModule) continue
|
|
828
|
+
problems.push(
|
|
829
|
+
`The sync schema has no table for ${entity.cedarType}, which syncs (as ${entity.sync.name}): regenerate it (eloxiv generate)`,
|
|
830
|
+
)
|
|
831
|
+
}
|
|
832
|
+
return problems
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
interface Hop {
|
|
836
|
+
readonly sourceField: ReadonlyArray<string>
|
|
837
|
+
readonly destField: ReadonlyArray<string>
|
|
838
|
+
readonly destSchema: string
|
|
839
|
+
readonly cardinality: "one" | "many"
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
/**
|
|
843
|
+
* The relationships the generator writes for an entity's Zero table, by name: its Drizzle relations to other
|
|
844
|
+
* synced entities' tables (a `many` joins the inverse `one` of the referenced entity back), and `shares` to the
|
|
845
|
+
* kernel's grants when it has a sharing attribute.
|
|
846
|
+
*/
|
|
847
|
+
const expectedRelationships = (
|
|
848
|
+
entity: AnyEntity,
|
|
849
|
+
entities: ReadonlyArray<AnyEntity>,
|
|
850
|
+
zeroNameOf: (qualified: string) => string | undefined,
|
|
851
|
+
): ReadonlyMap<string, Hop> => {
|
|
852
|
+
const expected = new Map<string, Hop>()
|
|
853
|
+
const own = `${entity.table.schema}.${entity.table.name}`
|
|
854
|
+
for (const relation of entity.relationships) {
|
|
855
|
+
const destSchema = zeroNameOf(relation.table)
|
|
856
|
+
if (destSchema === undefined) continue
|
|
857
|
+
if (relation.cardinality === "one") {
|
|
858
|
+
expected.set(relation.name, {
|
|
859
|
+
sourceField: relation.fields,
|
|
860
|
+
destField: relation.references,
|
|
861
|
+
destSchema,
|
|
862
|
+
cardinality: "one",
|
|
863
|
+
})
|
|
864
|
+
continue
|
|
865
|
+
}
|
|
866
|
+
const target = entities.find((e) => `${e.table.schema}.${e.table.name}` === relation.table)
|
|
867
|
+
const inverse = target?.relationships.find(
|
|
868
|
+
// The `one` back to this table, of the same relation name when the `many` has one (Drizzle pairs them so).
|
|
869
|
+
(r): r is Extract<typeof r, { cardinality: "one" }> =>
|
|
870
|
+
r.cardinality === "one" && r.table === own && r.relationName === relation.relationName,
|
|
871
|
+
)
|
|
872
|
+
if (inverse !== undefined) {
|
|
873
|
+
expected.set(relation.name, {
|
|
874
|
+
sourceField: inverse.references,
|
|
875
|
+
destField: inverse.fields,
|
|
876
|
+
destSchema,
|
|
877
|
+
cardinality: "many",
|
|
878
|
+
})
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
const grants = zeroNameOf("eloxiv.share_grant")
|
|
882
|
+
if (grants !== undefined && Object.values(entity.policyAttributes).some((a) => a.kind === "sharing")) {
|
|
883
|
+
expected.set("shares", {
|
|
884
|
+
sourceField: [entity.primaryKey],
|
|
885
|
+
destField: ["resourceId"],
|
|
886
|
+
destSchema: grants,
|
|
887
|
+
cardinality: "many",
|
|
888
|
+
})
|
|
889
|
+
}
|
|
890
|
+
return expected
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
/** The sync query endpoint; refuses to start when the Zero schema does not match the entity contracts. */
|
|
894
|
+
export const SyncEndpoint = (sync: SyncConfig) =>
|
|
895
|
+
Layer.unwrap(
|
|
896
|
+
Effect.gen(function* () {
|
|
897
|
+
const registry = yield* Registry
|
|
898
|
+
const registered = [...registry.entities.values()]
|
|
899
|
+
// The kernel's file metadata (the Files contract) is checked as its generated table declares it, when the
|
|
900
|
+
// app installs Files; like a kernel-provided module's tables, an app's schema may leave it out.
|
|
901
|
+
const files = registry.modules.some((m) => m.contract.name === FILES_MODULE)
|
|
902
|
+
const problems = syncSchemaProblems(
|
|
903
|
+
sync.schema,
|
|
904
|
+
[...registered.map((e) => e.entity), ...(files ? [fileEntity] : [])],
|
|
905
|
+
{
|
|
906
|
+
optionalSchemas: new Set([
|
|
907
|
+
...registered
|
|
908
|
+
.filter((e) => isKernelProvided(e.module) || isKernelModule(e.module))
|
|
909
|
+
.map((e) => e.entity.table.schema),
|
|
910
|
+
...(files ? [fileEntity.table.schema] : []),
|
|
911
|
+
]),
|
|
912
|
+
},
|
|
913
|
+
)
|
|
914
|
+
if (problems.length > 0) {
|
|
915
|
+
return yield* Effect.die(
|
|
916
|
+
new Error(`The sync schema does not match the entity contracts:\n${problems.join("\n")}`),
|
|
917
|
+
)
|
|
918
|
+
}
|
|
919
|
+
return syncQueryRoute(sync)
|
|
920
|
+
}),
|
|
921
|
+
)
|
|
922
|
+
|
|
923
|
+
const syncQueryRoute = (sync: SyncConfig) => {
|
|
924
|
+
const schema = withKernelTables(sync.schema)
|
|
925
|
+
// Each entity's read filter, compiled with the principal unknown (as for row-level security), per version of
|
|
926
|
+
// the policy set: a changed policy set never serves a filter compiled from the old one.
|
|
927
|
+
const filters = new Map<string, ReadFilter>()
|
|
928
|
+
return HttpRouter.add("POST", SYNC_QUERY_PATH, (request) =>
|
|
929
|
+
Effect.gen(function* () {
|
|
930
|
+
const identity = yield* Identity
|
|
931
|
+
const registry = yield* Registry
|
|
932
|
+
const policies = yield* (yield* PolicySet).current
|
|
933
|
+
const byTable = new Map<string, AnyEntity>()
|
|
934
|
+
for (const { entity } of registry.entities.values())
|
|
935
|
+
byTable.set(`${entity.table.schema}.${entity.table.name}`, entity)
|
|
936
|
+
const readFilter = (entity: AnyEntity): ReadFilter => {
|
|
937
|
+
const key = `${policies.version}\u0000${entity.cedarType}`
|
|
938
|
+
const cached = filters.get(key)
|
|
939
|
+
if (cached !== undefined) return cached
|
|
940
|
+
const registered = registry.entities.get(entity.cedarType)!
|
|
941
|
+
const references = referencesOfModule(registered.module.contract)
|
|
942
|
+
const namespace = registered.module.contract.cedarNamespace
|
|
943
|
+
try {
|
|
944
|
+
const pred = compileSymbolic({
|
|
945
|
+
policies: policies.text,
|
|
946
|
+
action: { type: `${namespace}::Action`, id: "read" },
|
|
947
|
+
entity,
|
|
948
|
+
references,
|
|
949
|
+
context: rowContext("old"),
|
|
950
|
+
})
|
|
951
|
+
if (filters.size > 10_000) filters.clear()
|
|
952
|
+
const filter = { pred, references }
|
|
953
|
+
filters.set(key, filter)
|
|
954
|
+
return filter
|
|
955
|
+
} catch (error) {
|
|
956
|
+
if (error instanceof UnsupportedPolicy) throw new UnsupportedQuery(error.message)
|
|
957
|
+
throw error
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
const config = yield* KernelConfig
|
|
961
|
+
const sql = yield* SqlClient.SqlClient
|
|
962
|
+
// zero-cache's key before anything else, as for pushes.
|
|
963
|
+
const from = zeroCaller(toWebHeaders(request.headers), config)
|
|
964
|
+
if (from === "unconfigured") return zeroUnconfigured()
|
|
965
|
+
if (from === "refused") return zeroRefused()
|
|
966
|
+
const caller = yield* identity.authenticateSession(toWebHeaders(request.headers)).pipe(Effect.option)
|
|
967
|
+
if (caller._tag === "None") return HttpServerResponse.text("Unauthorized", { status: 401 })
|
|
968
|
+
const actor = { value: caller.value.actor }
|
|
969
|
+
// The connection's client group and user, as zero-cache names them (patches/@rocicorp__zero, under its key).
|
|
970
|
+
// A transform whose credential is another person's than the user the connection advertised is refused
|
|
971
|
+
// (zero-cache checks that only on the answer). Otherwise it claims the group for the person and the
|
|
972
|
+
// organisation they act in, if no one holds it yet: every replica's queries are transformed when it connects,
|
|
973
|
+
// so its group is the person's from its first connection (an erasure purges it: privacy/ZeroCvr.ts), with no
|
|
974
|
+
// push of the replica's own (a push refused after a sign-out would drop the connection before the sign-out's
|
|
975
|
+
// withdrawal reached it). A transform for a group another person or organisation holds is refused, so a
|
|
976
|
+
// group's queries are only ever its owner's. The claim and that check run under the session's hold, below:
|
|
977
|
+
// recorded only if the session still holds when they commit, never by a transform that resumes after a
|
|
978
|
+
// sign-out.
|
|
979
|
+
let claim: { readonly shard: string; readonly group: string; readonly orgId: string } | undefined
|
|
980
|
+
if (from === "zero-cache") {
|
|
981
|
+
const params = new URL(request.url, "http://kernel").searchParams
|
|
982
|
+
const attested = zeroAttested(params)
|
|
983
|
+
if (attested !== undefined && attested.userId !== actor.value.userId) {
|
|
984
|
+
return HttpServerResponse.text("The connection is another person's", { status: 403 })
|
|
985
|
+
}
|
|
986
|
+
if (attested?.clientGroupID !== undefined) {
|
|
987
|
+
const appId = config.zeroAppId ?? "zero"
|
|
988
|
+
const shard = params.get("schema") ?? ""
|
|
989
|
+
const group = attested.clientGroupID
|
|
990
|
+
if (
|
|
991
|
+
params.get("appID") !== appId ||
|
|
992
|
+
!shard.startsWith(`${appId}_`) ||
|
|
993
|
+
!/^\d+$/.test(shard.slice(appId.length + 1)) ||
|
|
994
|
+
!/^[A-Za-z0-9_-]{1,100}$/u.test(group)
|
|
995
|
+
) {
|
|
996
|
+
return HttpServerResponse.text("The transform names no client group of zero-cache's", { status: 403 })
|
|
997
|
+
}
|
|
998
|
+
claim = { shard, group, orgId: actor.value.orgId }
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
const sessionId = caller.value.sessionId
|
|
1002
|
+
// The session's live fact, which every query transformed here also tests: recorded while the session holds
|
|
1003
|
+
// (a sign-out either waits for it, or committed first and nothing is recorded), and deleted when the kernel ends
|
|
1004
|
+
// the session (Identity.endSession). Facts of this person's sessions that ended otherwise (expired) go too.
|
|
1005
|
+
// In 0216's order: the organisation's directory lock (shared: a change of its sign-in methods waits for this
|
|
1006
|
+
// write, or committed first and is read below), the person's fact lock, then the session's hold.
|
|
1007
|
+
const recorded = yield* sql
|
|
1008
|
+
.withTransaction(
|
|
1009
|
+
Effect.gen(function* () {
|
|
1010
|
+
yield* lockDirectoryShared(sql, actor.value.orgId)
|
|
1011
|
+
yield* sql`SELECT pg_advisory_xact_lock(hashtextextended(${`eloxiv.sync-facts:${actor.value.userId}`}, 0))`
|
|
1012
|
+
return yield* identity.whileSignedIn(
|
|
1013
|
+
sessionId,
|
|
1014
|
+
actor.value.userId,
|
|
1015
|
+
Effect.gen(function* () {
|
|
1016
|
+
yield* sql`DELETE FROM eloxiv.sync_fact f WHERE f.user_id = ${actor.value.userId} AND f.kind = 'session'
|
|
1017
|
+
AND NOT EXISTS (SELECT 1 FROM auth.session s WHERE s.id = f.value AND s."expiresAt" > clock_timestamp())`
|
|
1018
|
+
// Under those locks, the organisation's methods as they now are: a session it no longer admits gets no
|
|
1019
|
+
// fact (the transform's authentication read them before).
|
|
1020
|
+
const [admitted] = yield* sql<{ admitted: boolean }>`
|
|
1021
|
+
SELECT eloxiv.session_admitted_in(${actor.value.orgId}, ${sessionId}) AS admitted`
|
|
1022
|
+
if (admitted?.admitted !== true) return yield* new NotAdmitted()
|
|
1023
|
+
yield* sql`INSERT INTO eloxiv.sync_fact (org_id, user_id, kind, value)
|
|
1024
|
+
VALUES (${actor.value.orgId}, ${actor.value.userId}, 'session', ${sessionId}) ON CONFLICT DO NOTHING`
|
|
1025
|
+
if (claim === undefined) return
|
|
1026
|
+
const claimed =
|
|
1027
|
+
claim.orgId === ""
|
|
1028
|
+
? []
|
|
1029
|
+
: yield* sql<{ mine: boolean }>`
|
|
1030
|
+
INSERT INTO eloxiv.sync_client_group (shard, client_group_id, org_id, user_id)
|
|
1031
|
+
VALUES (${claim.shard}, ${claim.group}, ${claim.orgId}, ${actor.value.userId})
|
|
1032
|
+
ON CONFLICT (shard, client_group_id) DO NOTHING RETURNING true AS mine`
|
|
1033
|
+
if (claimed.length > 0) return
|
|
1034
|
+
const [owner] = yield* sql<{ userId: string; orgId: string }>`
|
|
1035
|
+
SELECT user_id AS "userId", org_id AS "orgId" FROM eloxiv.sync_client_group
|
|
1036
|
+
WHERE shard = ${claim.shard} AND client_group_id = ${claim.group}`
|
|
1037
|
+
if (owner !== undefined && (owner.userId !== actor.value.userId || owner.orgId !== claim.orgId)) {
|
|
1038
|
+
return yield* new ForeignGroup()
|
|
1039
|
+
}
|
|
1040
|
+
}),
|
|
1041
|
+
)
|
|
1042
|
+
}),
|
|
1043
|
+
)
|
|
1044
|
+
.pipe(
|
|
1045
|
+
Effect.as("recorded" as const),
|
|
1046
|
+
Effect.catchTag("ForeignGroup", () => Effect.succeed("foreign" as const)),
|
|
1047
|
+
Effect.catchTag("NotAdmitted", () => Effect.succeed("not admitted" as const)),
|
|
1048
|
+
Effect.option,
|
|
1049
|
+
)
|
|
1050
|
+
if (recorded._tag === "None") return HttpServerResponse.text("Unauthorized", { status: 401 })
|
|
1051
|
+
if (recorded.value === "not admitted") {
|
|
1052
|
+
return HttpServerResponse.text("The organisation does not admit how this session was signed in", {
|
|
1053
|
+
status: 403,
|
|
1054
|
+
})
|
|
1055
|
+
}
|
|
1056
|
+
if (recorded.value === "foreign") {
|
|
1057
|
+
return HttpServerResponse.text("The client group belongs to another person", { status: 403 })
|
|
1058
|
+
}
|
|
1059
|
+
// Zero reads the body itself: it is handed one read within the kernel's limits, never the open stream.
|
|
1060
|
+
const limits = httpConfig(config)
|
|
1061
|
+
const web = yield* boundedWebRequest(
|
|
1062
|
+
request,
|
|
1063
|
+
{ maxBytes: limits.maxBodyBytes, timeoutMs: limits.bodyTimeoutMs },
|
|
1064
|
+
clientAddress(request, proxyHops(machineConfig(config))),
|
|
1065
|
+
)
|
|
1066
|
+
if (web._tag !== "Request") return refusalResponse(web)
|
|
1067
|
+
const result = yield* Effect.promise(() =>
|
|
1068
|
+
handleQueryRequest({
|
|
1069
|
+
schema,
|
|
1070
|
+
request: web.request,
|
|
1071
|
+
userID: actor.value.userId,
|
|
1072
|
+
handler: (name, args) => {
|
|
1073
|
+
const query = mustGetQuery(sync.queries as any, name) as any
|
|
1074
|
+
const built = query.fn({ args, ctx: { userId: actor.value.userId, orgId: actor.value.orgId } })
|
|
1075
|
+
// File metadata (the Files contract): the query reads the kernel's file table, and each file is
|
|
1076
|
+
// filtered by its record's read policy.
|
|
1077
|
+
if (readsTable(built, schema, FILE_TABLE)) {
|
|
1078
|
+
return scopeFileQuery(built, name, schema, {
|
|
1079
|
+
readFilter,
|
|
1080
|
+
entityOfTable: (qualified) => byTable.get(qualified),
|
|
1081
|
+
live: liveBindings(actor.value, schema, Date.now(), sessionId),
|
|
1082
|
+
actor: actor.value,
|
|
1083
|
+
fileEntities: [...registry.entities.values()]
|
|
1084
|
+
.map((r) => r.entity)
|
|
1085
|
+
.filter((entity) => entity.files !== undefined),
|
|
1086
|
+
}) as any
|
|
1087
|
+
}
|
|
1088
|
+
return scopeQuery(built, name, schema, {
|
|
1089
|
+
readFilter,
|
|
1090
|
+
entityOfTable: (qualified) => byTable.get(qualified),
|
|
1091
|
+
live: liveBindings(actor.value, schema, Date.now(), sessionId),
|
|
1092
|
+
}) as any
|
|
1093
|
+
},
|
|
1094
|
+
}),
|
|
1095
|
+
)
|
|
1096
|
+
return yield* HttpServerResponse.json(result)
|
|
1097
|
+
}),
|
|
1098
|
+
)
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1101
|
+
/** Zero's internal mutation that deletes results a client has received. */
|
|
1102
|
+
const CLEANUP_MUTATION = "_zero_cleanupResults"
|
|
1103
|
+
|
|
1104
|
+
/** What the kernel forwards of a push's headers to the invocation path: the credential and what the client named. */
|
|
1105
|
+
const FORWARDED_HEADERS = ["authorization", ORG_HEADER, CLIENT_VERSION_HEADER] as const
|
|
1106
|
+
|
|
1107
|
+
const PushBody = Schema.Struct({
|
|
1108
|
+
clientGroupID: Schema.String,
|
|
1109
|
+
mutations: Schema.Array(
|
|
1110
|
+
Schema.Struct({
|
|
1111
|
+
type: Schema.String,
|
|
1112
|
+
// Zero's own cleanup requests carry id 0; every other mutation is numbered from 1 per client.
|
|
1113
|
+
id: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
|
|
1114
|
+
clientID: Schema.String,
|
|
1115
|
+
name: Schema.String,
|
|
1116
|
+
args: Schema.Array(Schema.Unknown),
|
|
1117
|
+
}),
|
|
1118
|
+
),
|
|
1119
|
+
pushVersion: Schema.Number,
|
|
1120
|
+
})
|
|
1121
|
+
type PushMutation = (typeof PushBody.Type)["mutations"][number]
|
|
1122
|
+
|
|
1123
|
+
/** Zero's cleanup arguments (zero-cache 1.11's `ackMutationResponses` and `deleteClientMutations`). */
|
|
1124
|
+
const CleanupArgs = Schema.Union([
|
|
1125
|
+
Schema.Struct({
|
|
1126
|
+
type: Schema.optionalKey(Schema.Literal("single")),
|
|
1127
|
+
clientGroupID: Schema.String,
|
|
1128
|
+
clientID: Schema.String,
|
|
1129
|
+
upToMutationID: Schema.Number,
|
|
1130
|
+
}),
|
|
1131
|
+
Schema.Struct({
|
|
1132
|
+
type: Schema.Literal("bulk"),
|
|
1133
|
+
clientGroupID: Schema.String,
|
|
1134
|
+
clientIDs: Schema.Array(Schema.String).check(Schema.isMinLength(1)),
|
|
1135
|
+
}),
|
|
1136
|
+
])
|
|
1137
|
+
|
|
1138
|
+
/** Where a mutation stands in its client's order (`eloxiv_setup.zero_push_status`), before anything of it runs. */
|
|
1139
|
+
type PushOrder = "next" | "processed" | "out-of-order" | "foreign"
|
|
1140
|
+
|
|
1141
|
+
type PushStatus = "applied" | "processed" | "out-of-order" | "foreign"
|
|
1142
|
+
|
|
1143
|
+
/** A transform's client group is another person's (or organisation's): nothing of the transform is recorded. */
|
|
1144
|
+
class ForeignGroup extends Data.TaggedError("ForeignGroup")<{}> {}
|
|
1145
|
+
/** The organisation no longer admits how the transform's session was signed in (Directory `setSignInMethods`). */
|
|
1146
|
+
class NotAdmitted extends Data.TaggedError("NotAdmitted")<{}> {}
|
|
1147
|
+
|
|
1148
|
+
/** A refusal's bookkeeping found the mutation out of order, or the client another user's: it is rolled back. */
|
|
1149
|
+
class Unsequenced extends Data.TaggedError("Unsequenced")<{ readonly status: "out-of-order" | "foreign" }> {}
|
|
1150
|
+
|
|
1151
|
+
const pushFailed = (
|
|
1152
|
+
reason: "oooMutation" | "parse" | "unsupportedPushVersion",
|
|
1153
|
+
message: string,
|
|
1154
|
+
mutationIDs: ReadonlyArray<PushMutation>,
|
|
1155
|
+
) =>
|
|
1156
|
+
HttpServerResponse.json({
|
|
1157
|
+
kind: "PushFailed",
|
|
1158
|
+
origin: "server",
|
|
1159
|
+
reason,
|
|
1160
|
+
message,
|
|
1161
|
+
mutationIDs: mutationIDs.map((m) => ({ clientID: m.clientID, id: m.id })),
|
|
1162
|
+
})
|
|
1163
|
+
|
|
1164
|
+
const refused = (message: string) => HttpServerResponse.json({ _tag: "PushRefused", message }, { status: 403 })
|
|
1165
|
+
|
|
1166
|
+
/**
|
|
1167
|
+
* Sync's push endpoint (the Sync contract's `mutate`): zero-cache forwards each client's optimistic writes here.
|
|
1168
|
+
* Every mutation runs, in order, as the action it names (only an action that declares an optimistic effect),
|
|
1169
|
+
* through the one invocation path as the signed-in person, on surface `sync`, with the client and its mutation id
|
|
1170
|
+
* as the idempotency key. A mutation's place in its client's order is decided first, writing nothing
|
|
1171
|
+
* (`eloxiv_setup.zero_push_status`): one out of order, or through another user's client, is refused before any
|
|
1172
|
+
* stage of the call runs, and a retry of one answered before only replays its receipt, skipping consent and
|
|
1173
|
+
* business approval (stages that commit on their own), so neither leaves anything behind. Inside the action's
|
|
1174
|
+
* transaction, before its idempotency claim, the client's last mutation id advances (`eloxiv_setup.zero_push`),
|
|
1175
|
+
* so its rows and its confirmation commit, and reach the replica, together. A refused mutation (any
|
|
1176
|
+
* invocation error: Forbidden, InvalidInput, ApprovalRequired, ConsentRequired, ActionFailed, ...) advances the
|
|
1177
|
+
* client's last mutation id in a transaction of its own with the error recorded as its result, so the replica
|
|
1178
|
+
* drops the prediction and the caller's promise rejects with the error. Successful outputs are never recorded.
|
|
1179
|
+
*/
|
|
1180
|
+
export const SyncMutateEndpoint = HttpRouter.add("POST", SYNC_MUTATE_PATH, (request) =>
|
|
1181
|
+
Effect.gen(function* () {
|
|
1182
|
+
const identity = yield* Identity
|
|
1183
|
+
const invocation = yield* Invocation
|
|
1184
|
+
const registry = yield* Registry
|
|
1185
|
+
const sql = yield* SqlClient.SqlClient
|
|
1186
|
+
const config = yield* KernelConfig
|
|
1187
|
+
// Only the credential zero-cache forwards (a bearer token, never a cookie a browser would attach to a request
|
|
1188
|
+
// another site makes) and what the client named.
|
|
1189
|
+
const headers = toWebHeaders(request.headers)
|
|
1190
|
+
// zero-cache's key before anything else: without it where it is required, nothing of the push is looked at.
|
|
1191
|
+
const from = zeroCaller(headers, config)
|
|
1192
|
+
if (from === "unconfigured") return zeroUnconfigured()
|
|
1193
|
+
if (from === "refused") return zeroRefused()
|
|
1194
|
+
const forwarded = new Headers()
|
|
1195
|
+
for (const name of FORWARDED_HEADERS) {
|
|
1196
|
+
const value = headers.get(name)
|
|
1197
|
+
if (value !== null) forwarded.set(name, value)
|
|
1198
|
+
}
|
|
1199
|
+
// A push comes from a replica, and only a signed-in person has one (as for the query endpoint).
|
|
1200
|
+
const actor = forwarded.has("authorization")
|
|
1201
|
+
? yield* identity.authenticate(forwarded).pipe(Effect.option)
|
|
1202
|
+
: Option.none()
|
|
1203
|
+
if (actor._tag === "None") return HttpServerResponse.text("Unauthorized", { status: 401 })
|
|
1204
|
+
const userId = actor.value.userId
|
|
1205
|
+
const limits = httpConfig(config)
|
|
1206
|
+
const body = yield* readBody(request, { maxBytes: limits.maxBodyBytes, timeoutMs: limits.bodyTimeoutMs })
|
|
1207
|
+
if (body._tag !== "Read") return refusalResponse(body)
|
|
1208
|
+
const params = new URL(request.url, "http://kernel").searchParams
|
|
1209
|
+
// The shard zero-cache keeps for this kernel's app: never a schema a caller names.
|
|
1210
|
+
const appId = config.zeroAppId ?? "zero"
|
|
1211
|
+
const shard = params.get("schema") ?? ""
|
|
1212
|
+
if (
|
|
1213
|
+
params.get("appID") !== appId ||
|
|
1214
|
+
!shard.startsWith(`${appId}_`) ||
|
|
1215
|
+
!/^\d+$/.test(shard.slice(appId.length + 1))
|
|
1216
|
+
) {
|
|
1217
|
+
return yield* refused(`The push names shard ${JSON.stringify(shard)}, which is not zero-cache's for app ${appId}`)
|
|
1218
|
+
}
|
|
1219
|
+
let parsed: typeof PushBody.Type
|
|
1220
|
+
try {
|
|
1221
|
+
parsed = Schema.decodeUnknownSync(PushBody)(JSON.parse(new TextDecoder().decode(body.bytes)))
|
|
1222
|
+
} catch (error) {
|
|
1223
|
+
return yield* pushFailed("parse", `The push could not be read: ${String(error)}`, [])
|
|
1224
|
+
}
|
|
1225
|
+
if (parsed.pushVersion !== 1) {
|
|
1226
|
+
return yield* pushFailed(
|
|
1227
|
+
"unsupportedPushVersion",
|
|
1228
|
+
`Unsupported push version ${parsed.pushVersion}`,
|
|
1229
|
+
parsed.mutations,
|
|
1230
|
+
)
|
|
1231
|
+
}
|
|
1232
|
+
const group = parsed.clientGroupID
|
|
1233
|
+
if (!/^[A-Za-z0-9_-]{1,100}$/u.test(group)) {
|
|
1234
|
+
return yield* pushFailed("parse", "The push names no client group of zero-cache's", parsed.mutations)
|
|
1235
|
+
}
|
|
1236
|
+
// Whose client group this is (an erasure purges its client view records: privacy/ZeroCvr.ts). A push zero-cache
|
|
1237
|
+
// forwarded (its API key) names the connection's client group and the user it connected as (zero-cache's own
|
|
1238
|
+
// word, patches/@rocicorp__zero): one whose credential is another person's than that user is refused before
|
|
1239
|
+
// anything is recorded (zero-cache would refuse it only after, on the answer); otherwise it claims the group for
|
|
1240
|
+
// the person and the organisation they act in, unless someone claimed it first. Any push for a group someone
|
|
1241
|
+
// else claimed is refused; one without the key claims nothing.
|
|
1242
|
+
const orgId = actor.value.orgId
|
|
1243
|
+
const attested = from === "zero-cache" ? zeroAttested(params) : undefined
|
|
1244
|
+
if (attested !== undefined) {
|
|
1245
|
+
if (attested.userId !== userId) return yield* refused("The connection is another person's")
|
|
1246
|
+
if (attested.clientGroupID !== undefined && attested.clientGroupID !== group) {
|
|
1247
|
+
return yield* refused("The push names another client group than its connection's")
|
|
1248
|
+
}
|
|
1249
|
+
}
|
|
1250
|
+
const owned =
|
|
1251
|
+
attested !== undefined && orgId !== ""
|
|
1252
|
+
? yield* sql<{ mine: boolean }>`
|
|
1253
|
+
INSERT INTO eloxiv.sync_client_group (shard, client_group_id, org_id, user_id)
|
|
1254
|
+
VALUES (${shard}, ${group}, ${orgId}, ${userId})
|
|
1255
|
+
ON CONFLICT (shard, client_group_id) DO UPDATE SET seen_at = now()
|
|
1256
|
+
WHERE eloxiv.sync_client_group.org_id = EXCLUDED.org_id
|
|
1257
|
+
AND eloxiv.sync_client_group.user_id = EXCLUDED.user_id
|
|
1258
|
+
RETURNING true AS mine`.pipe(Effect.orDie)
|
|
1259
|
+
: yield* sql<{ mine: boolean }>`
|
|
1260
|
+
SELECT user_id = ${userId} AND (${orgId} = '' OR org_id = ${orgId}) AS mine FROM eloxiv.sync_client_group
|
|
1261
|
+
WHERE shard = ${shard} AND client_group_id = ${group}
|
|
1262
|
+
UNION ALL SELECT true WHERE NOT EXISTS (
|
|
1263
|
+
SELECT 1 FROM eloxiv.sync_client_group WHERE shard = ${shard} AND client_group_id = ${group})`.pipe(
|
|
1264
|
+
Effect.orDie,
|
|
1265
|
+
)
|
|
1266
|
+
if (owned[0]?.mine !== true) return yield* refused("The client group belongs to another person")
|
|
1267
|
+
// A cleanup names its client group; it may only be the push's own (zero-cache sends it in that group's push).
|
|
1268
|
+
for (const m of parsed.mutations) {
|
|
1269
|
+
if (m.name !== CLEANUP_MUTATION) continue
|
|
1270
|
+
const args = Schema.decodeUnknownOption(CleanupArgs)(m.args[0])
|
|
1271
|
+
if (args._tag === "Some" && args.value.clientGroupID !== group) {
|
|
1272
|
+
return yield* refused(
|
|
1273
|
+
`A cleanup of client group ${JSON.stringify(args.value.clientGroupID)} in a push of ${JSON.stringify(group)}`,
|
|
1274
|
+
)
|
|
1275
|
+
}
|
|
1276
|
+
}
|
|
1277
|
+
const advance = (m: PushMutation, result: unknown) =>
|
|
1278
|
+
sql<{ status: PushStatus }>`SELECT eloxiv_setup.zero_push(${shard}, ${group}, ${m.clientID}, ${m.id}, ${userId},
|
|
1279
|
+
${result === null ? null : JSON.stringify(result)}::json) AS status`.pipe(
|
|
1280
|
+
Effect.orDie,
|
|
1281
|
+
Effect.map(([row]) => row!.status),
|
|
1282
|
+
)
|
|
1283
|
+
const orderOf = (m: PushMutation) =>
|
|
1284
|
+
sql<{ order: PushOrder }>`SELECT eloxiv_setup.zero_push_status(${shard}, ${group}, ${m.clientID}, ${m.id},
|
|
1285
|
+
${userId}) AS order`.pipe(
|
|
1286
|
+
Effect.orDie,
|
|
1287
|
+
Effect.map(([row]) => row!.order),
|
|
1288
|
+
)
|
|
1289
|
+
const responses: Array<{
|
|
1290
|
+
readonly id: { readonly clientID: string; readonly id: number }
|
|
1291
|
+
readonly result: unknown
|
|
1292
|
+
}> = []
|
|
1293
|
+
for (const [index, m] of parsed.mutations.entries()) {
|
|
1294
|
+
if (m.name === CLEANUP_MUTATION) {
|
|
1295
|
+
// Results the client has received: only its own user's clients', and never a reason to fail the push.
|
|
1296
|
+
const args = Schema.decodeUnknownOption(CleanupArgs)(m.args[0])
|
|
1297
|
+
if (args._tag === "Some") {
|
|
1298
|
+
const value = args.value
|
|
1299
|
+
const clients = "clientIDs" in value ? [...value.clientIDs] : [value.clientID]
|
|
1300
|
+
const upTo = "upToMutationID" in value ? value.upToMutationID : null
|
|
1301
|
+
yield* sql`SELECT eloxiv_setup.zero_cleanup(${shard}, ${value.clientGroupID}, ${clients}, ${upTo}, ${userId})`.pipe(
|
|
1302
|
+
Effect.catchCause((cause) => Effect.logWarning("Could not clean up a client's mutation results", cause)),
|
|
1303
|
+
)
|
|
1304
|
+
}
|
|
1305
|
+
continue
|
|
1306
|
+
}
|
|
1307
|
+
if (m.id < 1) {
|
|
1308
|
+
return yield* pushFailed(
|
|
1309
|
+
"parse",
|
|
1310
|
+
`Mutation ${m.id} of ${m.clientID} has no place in an order`,
|
|
1311
|
+
parsed.mutations.slice(index),
|
|
1312
|
+
)
|
|
1313
|
+
}
|
|
1314
|
+
const id = { clientID: m.clientID, id: m.id }
|
|
1315
|
+
const outOfOrder = () =>
|
|
1316
|
+
pushFailed("oooMutation", `Mutation ${m.id} of ${m.clientID} is out of order`, parsed.mutations.slice(index))
|
|
1317
|
+
// Its place in the order, before anything of the call runs.
|
|
1318
|
+
const order = yield* orderOf(m)
|
|
1319
|
+
if (order === "foreign") return yield* refused("The client belongs to another user")
|
|
1320
|
+
if (order === "out-of-order") return yield* outOfOrder()
|
|
1321
|
+
const registered = registry.actions.get(m.name)
|
|
1322
|
+
// Only actions that declare an optimistic effect are mutators.
|
|
1323
|
+
const mutator = m.type === "custom" && registered !== undefined && registered.contract.optimistic !== undefined
|
|
1324
|
+
if (order === "processed") {
|
|
1325
|
+
// Answered before: a confirmed call replays its receipt; anything else (it was refused) ran nothing.
|
|
1326
|
+
if (!mutator) {
|
|
1327
|
+
responses.push({ id, result: { error: "alreadyProcessed" } })
|
|
1328
|
+
continue
|
|
1329
|
+
}
|
|
1330
|
+
const replay = yield* Effect.exit(
|
|
1331
|
+
invocation.invoke({
|
|
1332
|
+
action: m.name,
|
|
1333
|
+
input: { encoded: m.args[0] },
|
|
1334
|
+
surface: "sync",
|
|
1335
|
+
headers: forwarded,
|
|
1336
|
+
idempotencyKey: `zero:${group}:${m.clientID}:${m.id}`,
|
|
1337
|
+
sequence: { kind: "replay" },
|
|
1338
|
+
}),
|
|
1339
|
+
)
|
|
1340
|
+
if (Exit.isFailure(replay) && Option.isNone(Cause.findErrorOption(replay.cause))) {
|
|
1341
|
+
return yield* Effect.failCause(replay.cause)
|
|
1342
|
+
}
|
|
1343
|
+
responses.push({ id, result: Exit.isSuccess(replay) ? {} : { error: "alreadyProcessed" } })
|
|
1344
|
+
continue
|
|
1345
|
+
}
|
|
1346
|
+
const reject = (error: InvocationError) =>
|
|
1347
|
+
Effect.gen(function* () {
|
|
1348
|
+
const encoded = Schema.encodeSync(InvocationError)(error)
|
|
1349
|
+
const result = { error: "app", message: invocationMessage(error), details: encoded }
|
|
1350
|
+
// Out of order or foreign, nothing of this transaction may stay (a new client's binding included).
|
|
1351
|
+
const status = yield* sql
|
|
1352
|
+
.withTransaction(
|
|
1353
|
+
advance(m, result).pipe(
|
|
1354
|
+
Effect.flatMap((status) =>
|
|
1355
|
+
status === "applied" || status === "processed"
|
|
1356
|
+
? Effect.succeed(status)
|
|
1357
|
+
: Effect.fail(new Unsequenced({ status })),
|
|
1358
|
+
),
|
|
1359
|
+
),
|
|
1360
|
+
)
|
|
1361
|
+
.pipe(
|
|
1362
|
+
Effect.catchTag("Unsequenced", (e) => Effect.succeed(e.status)),
|
|
1363
|
+
Effect.orDie,
|
|
1364
|
+
)
|
|
1365
|
+
return { status, result }
|
|
1366
|
+
})
|
|
1367
|
+
/** The answer to a refusal whose bookkeeping found `status` (the order can move between the check and it). */
|
|
1368
|
+
const refusal = (error: InvocationError) =>
|
|
1369
|
+
Effect.gen(function* () {
|
|
1370
|
+
const { status, result } = yield* reject(error)
|
|
1371
|
+
if (status === "foreign") return yield* refused("The client belongs to another user")
|
|
1372
|
+
if (status === "out-of-order") return yield* outOfOrder()
|
|
1373
|
+
responses.push({ id, result: status === "applied" ? result : { error: "alreadyProcessed" } })
|
|
1374
|
+
return undefined
|
|
1375
|
+
})
|
|
1376
|
+
if (!mutator) {
|
|
1377
|
+
const stop = yield* refusal(new UnknownAction({ action: m.name, message: `No action ${m.name}` }))
|
|
1378
|
+
if (stop !== undefined) return stop
|
|
1379
|
+
continue
|
|
1380
|
+
}
|
|
1381
|
+
// The client's next mutation. Its place is taken in the call's own transaction; if the order moved on since
|
|
1382
|
+
// the check (another push for the same client), the call is refused and nothing of it commits.
|
|
1383
|
+
let moved: PushStatus | undefined
|
|
1384
|
+
const advanceInCall = advance(m, null).pipe(
|
|
1385
|
+
Effect.flatMap((status) =>
|
|
1386
|
+
status === "applied"
|
|
1387
|
+
? Effect.void
|
|
1388
|
+
: Effect.sync(() => void (moved = status)).pipe(
|
|
1389
|
+
Effect.andThen(
|
|
1390
|
+
Effect.fail(
|
|
1391
|
+
new Forbidden({
|
|
1392
|
+
action: m.name,
|
|
1393
|
+
message: `Mutation ${m.id} of client ${m.clientID} moved in its order`,
|
|
1394
|
+
}),
|
|
1395
|
+
),
|
|
1396
|
+
),
|
|
1397
|
+
),
|
|
1398
|
+
),
|
|
1399
|
+
)
|
|
1400
|
+
const exit = yield* Effect.exit(
|
|
1401
|
+
invocation.invoke({
|
|
1402
|
+
action: m.name,
|
|
1403
|
+
input: { encoded: m.args[0] },
|
|
1404
|
+
surface: "sync",
|
|
1405
|
+
headers: forwarded,
|
|
1406
|
+
idempotencyKey: `zero:${group}:${m.clientID}:${m.id}`,
|
|
1407
|
+
sequence: { kind: "next", advance: advanceInCall },
|
|
1408
|
+
}),
|
|
1409
|
+
)
|
|
1410
|
+
if (Exit.isSuccess(exit)) {
|
|
1411
|
+
responses.push({ id, result: {} })
|
|
1412
|
+
continue
|
|
1413
|
+
}
|
|
1414
|
+
const failure = Cause.findErrorOption(exit.cause)
|
|
1415
|
+
if (Option.isNone(failure)) return yield* Effect.failCause(exit.cause)
|
|
1416
|
+
if (moved === "foreign") return yield* refused("The client belongs to another user")
|
|
1417
|
+
if (moved === "out-of-order") return yield* outOfOrder()
|
|
1418
|
+
if (moved === "processed") {
|
|
1419
|
+
responses.push({ id, result: { error: "alreadyProcessed" } })
|
|
1420
|
+
continue
|
|
1421
|
+
}
|
|
1422
|
+
const stop = yield* refusal(failure.value)
|
|
1423
|
+
if (stop !== undefined) return stop
|
|
1424
|
+
}
|
|
1425
|
+
return yield* HttpServerResponse.json({ kind: "MutateResponse", userID: userId, mutations: responses })
|
|
1426
|
+
}),
|
|
1427
|
+
)
|
|
1428
|
+
|
|
1429
|
+
/** A refusal's message for the replica's error (the error itself travels encoded, as the result's details). */
|
|
1430
|
+
const invocationMessage = (error: InvocationError): string =>
|
|
1431
|
+
"message" in error && typeof error.message === "string" ? error.message : error._tag
|
|
1432
|
+
|
|
1433
|
+
/**
|
|
1434
|
+
* Who made a call to the sync endpoints: zero-cache (its API key), a direct caller (development without a configured
|
|
1435
|
+
* key only), or no one to answer: the key is missing or wrong where it is required (production, or whenever
|
|
1436
|
+
* `ELOXIV_ZERO_API_KEY` is set), or production has none configured.
|
|
1437
|
+
*/
|
|
1438
|
+
const zeroCaller = (
|
|
1439
|
+
headers: Headers,
|
|
1440
|
+
config: Parameters<typeof zeroApiKeyOf>[0],
|
|
1441
|
+
): "zero-cache" | "direct" | "refused" | "unconfigured" => {
|
|
1442
|
+
const key = zeroApiKeyOf(config)
|
|
1443
|
+
if (key === undefined) return "unconfigured"
|
|
1444
|
+
if (sameSecret(headers.get(ZERO_API_KEY_HEADER), key)) return "zero-cache"
|
|
1445
|
+
return config.environment === "production" || config.zeroApiKey !== undefined ? "refused" : "direct"
|
|
1446
|
+
}
|
|
1447
|
+
|
|
1448
|
+
const zeroUnconfigured = () =>
|
|
1449
|
+
HttpServerResponse.text("zero-cache's API key (ELOXIV_ZERO_API_KEY) is not configured", { status: 503 })
|
|
1450
|
+
const zeroRefused = () => HttpServerResponse.text("Only zero-cache calls this endpoint (its API key)", { status: 401 })
|
|
1451
|
+
|
|
1452
|
+
/**
|
|
1453
|
+
* What zero-cache says of the connection a call is for (patches/@rocicorp__zero: `userID`, the user it connected as;
|
|
1454
|
+
* `clientGroupID`), on a call that carries its key; undefined when it names no user (an unpatched zero-cache).
|
|
1455
|
+
*/
|
|
1456
|
+
const zeroAttested = (
|
|
1457
|
+
params: URLSearchParams,
|
|
1458
|
+
): { readonly userId: string; readonly clientGroupID: string | undefined } | undefined => {
|
|
1459
|
+
const userId = params.get("userID")
|
|
1460
|
+
if (userId === null) return undefined
|
|
1461
|
+
return { userId, clientGroupID: params.get("clientGroupID") ?? undefined }
|
|
1462
|
+
}
|
|
1463
|
+
|
|
1464
|
+
/** zero-cache's API key: the configured one, else outside production the development one; none in production. */
|
|
1465
|
+
export const zeroApiKeyOf = (config: {
|
|
1466
|
+
readonly zeroApiKey?: Redacted.Redacted | undefined
|
|
1467
|
+
readonly environment?: "production" | "development" | undefined
|
|
1468
|
+
}): string | undefined =>
|
|
1469
|
+
config.zeroApiKey !== undefined
|
|
1470
|
+
? Redacted.value(config.zeroApiKey)
|
|
1471
|
+
: config.environment === "production"
|
|
1472
|
+
? undefined
|
|
1473
|
+
: DEV_ZERO_API_KEY
|
|
1474
|
+
|
|
1475
|
+
/** Whether `given` is `key`, compared in constant time. */
|
|
1476
|
+
const sameSecret = (given: string | null, key: string): boolean =>
|
|
1477
|
+
given !== null &&
|
|
1478
|
+
timingSafeEqual(createHash("sha256").update(given).digest(), createHash("sha256").update(key).digest())
|