@db3.ai/app 0.1.0-beta.1 → 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/README.md +75 -17
- package/agent-instructions.md +76 -0
- package/dist/ai/AIErrors.d.ts +7 -1
- package/dist/ai/AIErrors.js +8 -1
- package/dist/ai/AIFailover.d.ts +10 -0
- package/dist/ai/AIFailover.js +3 -2
- package/dist/ai/AIProviderAdmission.d.ts +101 -0
- package/dist/ai/AIProviderAdmission.js +336 -0
- package/dist/ai/AIRateLimiter.d.ts +11 -2
- package/dist/ai/AIRateLimiter.js +125 -10
- package/dist/ai/AIRequestTrackingError.d.ts +22 -0
- package/dist/ai/AIRequestTrackingError.js +33 -0
- package/dist/ai/Agent.d.ts +7 -7
- package/dist/ai/Agent.js +84 -56
- package/dist/ai/Ai.d.ts +11 -3
- package/dist/ai/Ai.js +94 -44
- package/dist/ai/OpenAIProviderError.js +1 -1
- package/dist/ai/ProviderSseObserver.d.ts +19 -0
- package/dist/ai/ProviderSseObserver.js +98 -0
- package/dist/ai/aiServiceTier.d.ts +5 -0
- package/dist/ai/aiServiceTier.js +14 -0
- package/dist/ai/chunkEmbeddingText.d.ts +14 -0
- package/dist/ai/chunkEmbeddingText.js +147 -0
- package/dist/ai/contracts/AI.d.ts +16 -0
- package/dist/ai/contracts/AIRequestErrorDiagnostics.d.ts +12 -0
- package/dist/ai/contracts/AIRequestErrorDiagnostics.js +1 -0
- package/dist/ai/contracts/AIServiceTier.d.ts +2 -0
- package/dist/ai/contracts/AIServiceTier.js +1 -0
- package/dist/ai/contracts/Agent.d.ts +3 -0
- package/dist/ai/contracts/EmbeddingTextChunk.d.ts +25 -0
- package/dist/ai/contracts/EmbeddingTextChunk.js +1 -0
- package/dist/ai/contracts/Pricing.d.ts +7 -1
- package/dist/ai/contracts/Providers.d.ts +2 -0
- package/dist/ai/contracts/index.d.ts +2 -0
- package/dist/ai/contracts/index.js +1 -0
- package/dist/ai/index.d.ts +8 -2
- package/dist/ai/index.js +5 -2
- package/dist/ai/{Models.d.ts → modelPricing.d.ts} +2 -2
- package/dist/ai/{Models.js → modelPricing.js} +38 -4
- package/dist/apps/AppInstallation.d.ts +21 -0
- package/dist/apps/AppInstallation.js +16 -0
- package/dist/apps/AppRouteError.d.ts +6 -0
- package/dist/apps/AppRouteError.js +10 -0
- package/dist/apps/AppService.d.ts +24 -0
- package/dist/apps/AppService.js +21 -0
- package/dist/apps/Apps.d.ts +59 -0
- package/dist/apps/Apps.js +566 -0
- package/dist/apps/appsPlugin.d.ts +3 -0
- package/dist/apps/appsPlugin.js +36 -0
- package/dist/apps/commands/disableApp.d.ts +2 -0
- package/dist/apps/commands/disableApp.js +5 -0
- package/dist/apps/commands/enableApp.d.ts +2 -0
- package/dist/apps/commands/enableApp.js +5 -0
- package/dist/apps/commands/index.d.ts +10 -0
- package/dist/apps/commands/index.js +27 -0
- package/dist/apps/commands/installApp.d.ts +2 -0
- package/dist/apps/commands/installApp.js +5 -0
- package/dist/apps/commands/listApps.d.ts +2 -0
- package/dist/apps/commands/listApps.js +5 -0
- package/dist/apps/commands/makeAppMigration.d.ts +2 -0
- package/dist/apps/commands/makeAppMigration.js +9 -0
- package/dist/apps/commands/rollbackApp.d.ts +2 -0
- package/dist/apps/commands/rollbackApp.js +5 -0
- package/dist/apps/commands/uninstallApp.d.ts +2 -0
- package/dist/apps/commands/uninstallApp.js +5 -0
- package/dist/apps/contracts/AppAction.d.ts +2 -0
- package/dist/apps/contracts/AppAction.js +1 -0
- package/dist/apps/contracts/AppDefinition.d.ts +45 -0
- package/dist/apps/contracts/AppDefinition.js +1 -0
- package/dist/apps/contracts/AppDescription.d.ts +32 -0
- package/dist/apps/contracts/AppDescription.js +1 -0
- package/dist/apps/contracts/AppManifest.d.ts +30 -0
- package/dist/apps/contracts/AppManifest.js +1 -0
- package/dist/apps/contracts/AppNavigation.d.ts +9 -0
- package/dist/apps/contracts/AppNavigation.js +1 -0
- package/dist/apps/contracts/AppNavigationBadge.d.ts +6 -0
- package/dist/apps/contracts/AppNavigationBadge.js +1 -0
- package/dist/apps/contracts/AppNavigationContext.d.ts +8 -0
- package/dist/apps/contracts/AppNavigationContext.js +1 -0
- package/dist/apps/contracts/AppNavigationResult.d.ts +12 -0
- package/dist/apps/contracts/AppNavigationResult.js +1 -0
- package/dist/apps/contracts/AppRoute.d.ts +19 -0
- package/dist/apps/contracts/AppRoute.js +1 -0
- package/dist/apps/contracts/DiscoveredApp.d.ts +10 -0
- package/dist/apps/contracts/DiscoveredApp.js +1 -0
- package/dist/apps/contracts/InstalledApps.d.ts +3 -0
- package/dist/apps/contracts/InstalledApps.js +1 -0
- package/dist/apps/contracts/index.d.ts +11 -0
- package/dist/apps/contracts/index.js +1 -0
- package/dist/apps/defineApp.d.ts +7 -0
- package/dist/apps/defineApp.js +8 -0
- package/dist/apps/discoverApps.d.ts +3 -0
- package/dist/apps/discoverApps.js +62 -0
- package/dist/apps/fastify.d.ts +1 -0
- package/dist/apps/fastify.js +1 -0
- package/dist/apps/index.d.ts +7 -0
- package/dist/apps/index.js +7 -0
- package/dist/apps/normalizeAppNavigation.d.ts +3 -0
- package/dist/apps/normalizeAppNavigation.js +30 -0
- package/dist/apps/registerAppRoutes.d.ts +6 -0
- package/dist/apps/registerAppRoutes.js +52 -0
- package/dist/apps/validateAppDefinitions.d.ts +3 -0
- package/dist/apps/validateAppDefinitions.js +65 -0
- package/dist/apps/vite.d.ts +1 -0
- package/dist/apps/vite.js +1 -0
- package/dist/apps/writeAppTypes.d.ts +2 -0
- package/dist/apps/writeAppTypes.js +13 -0
- package/dist/auth/Auth.d.ts +18 -0
- package/dist/auth/Auth.js +89 -13
- package/dist/auth/PasswordLoginAttempt.d.ts +50 -0
- package/dist/auth/PasswordLoginAttempt.js +60 -0
- package/dist/auth/PasswordSuspendedError.d.ts +10 -0
- package/dist/auth/PasswordSuspendedError.js +13 -0
- package/dist/auth/contracts/PasswordAuthProviderOptions.d.ts +26 -0
- package/dist/auth/contracts/PasswordAuthProviderOptions.js +1 -0
- package/dist/auth/contracts/PasswordSuspension.d.ts +7 -0
- package/dist/auth/contracts/PasswordSuspension.js +1 -0
- package/dist/auth/contracts/PasswordSuspensionOptions.d.ts +10 -0
- package/dist/auth/contracts/PasswordSuspensionOptions.js +1 -0
- package/dist/auth/contracts/index.d.ts +3 -0
- package/dist/auth/contracts/index.js +3 -0
- package/dist/auth/index.d.ts +2 -0
- package/dist/auth/index.js +2 -0
- package/dist/auth/providers/PasswordAuthProvider.d.ts +19 -23
- package/dist/auth/providers/PasswordAuthProvider.js +96 -8
- package/dist/auth/providers/resolveAuthProviders.js +1 -0
- package/dist/cli/Cli.d.ts +2 -0
- package/dist/cli/Cli.js +8 -0
- package/dist/cli/commands/repl.js +2 -1
- package/dist/cli/contracts/CliCommand.d.ts +2 -0
- package/dist/cli/contracts/CliCommandInfo.d.ts +12 -0
- package/dist/cli/contracts/CliCommandInfo.js +1 -0
- package/dist/cli/contracts/index.d.ts +1 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +1 -0
- package/dist/cli/listDb3Commands.d.ts +8 -0
- package/dist/cli/listDb3Commands.js +10 -0
- package/dist/cli/runDb3.d.ts +3 -6
- package/dist/cli/runDb3.js +5 -59
- package/dist/cli/withDb3Cli.d.ts +4 -0
- package/dist/cli/withDb3Cli.js +60 -0
- package/dist/db/ActiveQueryBuilder.d.ts +8 -0
- package/dist/db/ActiveQueryBuilder.js +11 -0
- package/dist/db/ActiveRecord.d.ts +6 -0
- package/dist/db/ActiveRecord.js +8 -0
- package/dist/db/connection.js +14 -2
- package/dist/db/fields/TimestampField.d.ts +1 -1
- package/dist/db/fields/TimestampField.js +7 -12
- package/dist/db/migrations/DatabaseMigrationManager.d.ts +3 -1
- package/dist/db/migrations/DatabaseMigrationManager.js +9 -3
- package/dist/db/migrations/contracts/DatabaseMigration.d.ts +7 -0
- package/dist/db/migrations/index.d.ts +1 -1
- package/dist/db/migrations/index.js +1 -1
- package/dist/db/migrations/{KnexMigrationRenderer.d.ts → renderKnexMigration.d.ts} +4 -3
- package/dist/db/migrations/{KnexMigrationRenderer.js → renderKnexMigration.js} +7 -6
- package/dist/flows/FlowCompiler.js +1 -1
- package/dist/flows/Flows.js +1 -1
- package/dist/flows/index.d.ts +1 -1
- package/dist/flows/index.js +1 -1
- package/dist/health/Health.d.ts +41 -0
- package/dist/health/Health.js +153 -0
- package/dist/health/contracts/Health.d.ts +36 -0
- package/dist/health/contracts/Health.js +1 -0
- package/dist/health/contracts/HealthHttp.d.ts +15 -0
- package/dist/health/contracts/HealthHttp.js +1 -0
- package/dist/health/contracts/index.d.ts +2 -0
- package/dist/health/contracts/index.js +1 -0
- package/dist/health/databaseHealthCheck.d.ts +15 -0
- package/dist/health/databaseHealthCheck.js +18 -0
- package/dist/health/fastify.d.ts +13 -0
- package/dist/health/fastify.js +44 -0
- package/dist/health/index.d.ts +3 -0
- package/dist/health/index.js +2 -0
- package/dist/in-app/InApp.d.ts +33 -0
- package/dist/in-app/InApp.js +191 -0
- package/dist/in-app/InAppError.d.ts +6 -0
- package/dist/in-app/InAppError.js +10 -0
- package/dist/in-app/InAppRecord.d.ts +36 -0
- package/dist/in-app/InAppRecord.js +24 -0
- package/dist/in-app/contracts/InAppInbox.d.ts +45 -0
- package/dist/in-app/contracts/InAppInbox.js +1 -0
- package/dist/in-app/contracts/InAppMessage.d.ts +22 -0
- package/dist/in-app/contracts/InAppMessage.js +1 -0
- package/dist/in-app/contracts/InAppScope.d.ts +17 -0
- package/dist/in-app/contracts/InAppScope.js +1 -0
- package/dist/in-app/contracts/index.d.ts +3 -0
- package/dist/in-app/contracts/index.js +3 -0
- package/dist/in-app/index.d.ts +4 -0
- package/dist/in-app/index.js +4 -0
- package/dist/in-app/validation.d.ts +21 -0
- package/dist/in-app/validation.js +50 -0
- package/dist/index.d.ts +2 -14
- package/dist/index.js +2 -5
- package/dist/logging/DevelopmentConsole.d.ts +42 -0
- package/dist/logging/DevelopmentConsole.js +162 -0
- package/dist/logging/Log.d.ts +3 -1
- package/dist/logging/Log.js +5 -2
- package/dist/logging/PrettyLogFormatter.d.ts +16 -0
- package/dist/logging/PrettyLogFormatter.js +151 -0
- package/dist/logging/acquireDevelopmentConsole.d.ts +6 -0
- package/dist/logging/acquireDevelopmentConsole.js +21 -0
- package/dist/logging/contracts/DevelopmentConsoleOptions.d.ts +16 -0
- package/dist/logging/contracts/DevelopmentConsoleOptions.js +1 -0
- package/dist/logging/contracts/EmailLogOptions.d.ts +8 -0
- package/dist/logging/contracts/EmailLogOptions.js +1 -0
- package/dist/logging/contracts/HttpExchangeMonitorOptions.d.ts +12 -0
- package/dist/logging/contracts/HttpExchangeMonitorOptions.js +1 -0
- package/dist/logging/contracts/LogTransportOptions.d.ts +19 -0
- package/dist/logging/contracts/LogTransportOptions.js +1 -0
- package/dist/logging/contracts/LoggingOptions.d.ts +12 -1
- package/dist/logging/contracts/index.d.ts +4 -0
- package/dist/logging/contracts/index.js +4 -0
- package/dist/logging/drivers/PinoLoggerDriver.d.ts +3 -1
- package/dist/logging/drivers/PinoLoggerDriver.js +75 -16
- package/dist/logging/formatLogEmail.d.ts +4 -0
- package/dist/logging/formatLogEmail.js +21 -0
- package/dist/logging/highlightQueueMessage.d.ts +11 -0
- package/dist/logging/highlightQueueMessage.js +36 -0
- package/dist/logging/httpBodyCapture.d.ts +24 -0
- package/dist/logging/httpBodyCapture.js +321 -0
- package/dist/logging/index.d.ts +2 -0
- package/dist/logging/index.js +2 -0
- package/dist/logging/redactLogEmail.d.ts +2 -0
- package/dist/logging/redactLogEmail.js +12 -0
- package/dist/logging/registerHttpExchangeMonitor.d.ts +10 -0
- package/dist/logging/registerHttpExchangeMonitor.js +43 -0
- package/dist/logging/transports/EmailLogTransport.d.ts +18 -0
- package/dist/logging/transports/EmailLogTransport.js +47 -0
- package/dist/mail/Mail.d.ts +2 -0
- package/dist/mail/Mail.js +3 -0
- package/dist/mail/MailDeliveryError.d.ts +9 -0
- package/dist/mail/MailDeliveryError.js +16 -0
- package/dist/mail/index.d.ts +1 -0
- package/dist/mail/index.js +1 -0
- package/dist/mail/transports/MailgunTransport.js +2 -0
- package/dist/mail/transports/ResendTransport.d.ts +3 -2
- package/dist/mail/transports/ResendTransport.js +22 -14
- package/dist/media/MediaManager.d.ts +4 -2
- package/dist/media/MediaManager.js +40 -8
- package/dist/network/BlockedUrlError.d.ts +16 -0
- package/dist/network/BlockedUrlError.js +19 -0
- package/dist/network/assertPublicUrl.d.ts +22 -0
- package/dist/network/assertPublicUrl.js +67 -0
- package/dist/network/contracts/GuardedFetch.d.ts +35 -0
- package/dist/network/contracts/GuardedFetch.js +1 -0
- package/dist/network/contracts/PublicUrlOptions.d.ts +17 -0
- package/dist/network/contracts/PublicUrlOptions.js +1 -0
- package/dist/network/contracts/index.d.ts +2 -0
- package/dist/network/contracts/index.js +2 -0
- package/dist/network/guardedFetch.d.ts +29 -0
- package/dist/network/guardedFetch.js +133 -0
- package/dist/network/index.d.ts +6 -0
- package/dist/network/index.js +6 -0
- package/dist/network/playwright/GuardedBrowserProxy.d.ts +32 -0
- package/dist/network/playwright/GuardedBrowserProxy.js +172 -0
- package/dist/network/playwright/contracts/GuardedBrowserContextOptions.d.ts +37 -0
- package/dist/network/playwright/contracts/GuardedBrowserContextOptions.js +1 -0
- package/dist/network/playwright/contracts/index.d.ts +1 -0
- package/dist/network/playwright/contracts/index.js +1 -0
- package/dist/network/playwright/index.d.ts +2 -0
- package/dist/network/playwright/index.js +2 -0
- package/dist/network/playwright/newGuardedBrowserContext.d.ts +21 -0
- package/dist/network/playwright/newGuardedBrowserContext.js +86 -0
- package/dist/network/privateNetworkAddresses.d.ts +44 -0
- package/dist/network/privateNetworkAddresses.js +157 -0
- package/dist/network/publicAddressLookup.d.ts +26 -0
- package/dist/network/publicAddressLookup.js +42 -0
- package/dist/notifications/Notifications.d.ts +27 -0
- package/dist/notifications/Notifications.js +99 -0
- package/dist/notifications/contracts/Notification.d.ts +56 -0
- package/dist/notifications/contracts/Notification.js +1 -0
- package/dist/notifications/contracts/NotificationDelivery.d.ts +11 -0
- package/dist/notifications/contracts/NotificationDelivery.js +1 -0
- package/dist/notifications/contracts/index.d.ts +2 -0
- package/dist/notifications/contracts/index.js +2 -0
- package/dist/notifications/index.d.ts +2 -0
- package/dist/notifications/index.js +2 -0
- package/dist/queue/JobRunAttempt.d.ts +16 -0
- package/dist/queue/JobRunAttempt.js +17 -0
- package/dist/queue/JobRunEvent.d.ts +15 -0
- package/dist/queue/JobRunEvent.js +16 -0
- package/dist/queue/JobRunStoppedError.d.ts +6 -0
- package/dist/queue/JobRunStoppedError.js +10 -0
- package/dist/queue/Queue.d.ts +19 -4
- package/dist/queue/Queue.js +122 -9
- package/dist/queue/QueueTerminalError.d.ts +9 -0
- package/dist/queue/QueueTerminalError.js +12 -0
- package/dist/queue/QueueWorker.d.ts +12 -5
- package/dist/queue/QueueWorker.js +94 -9
- package/dist/queue/QueueWorkerReporter.d.ts +17 -0
- package/dist/queue/QueueWorkerReporter.js +71 -0
- package/dist/queue/QueueableJob.d.ts +2 -2
- package/dist/queue/RunnableJob.d.ts +78 -0
- package/dist/queue/RunnableJob.js +284 -0
- package/dist/queue/console.d.ts +8 -0
- package/dist/queue/console.js +53 -19
- package/dist/queue/contracts/QueueDriver.d.ts +8 -0
- package/dist/queue/contracts/QueueJobRunner.d.ts +4 -0
- package/dist/queue/contracts/QueueJobRunner.js +1 -0
- package/dist/queue/contracts/QueuePayload.d.ts +1 -1
- package/dist/queue/contracts/QueueSelection.d.ts +11 -0
- package/dist/queue/contracts/QueueSelection.js +1 -0
- package/dist/queue/contracts/QueueService.d.ts +18 -4
- package/dist/queue/contracts/QueueWorkerLifecycle.d.ts +2 -2
- package/dist/queue/contracts/QueueWorkerSnapshot.d.ts +14 -0
- package/dist/queue/contracts/QueueWorkerSnapshot.js +1 -0
- package/dist/queue/contracts/QueueableJob.d.ts +7 -3
- package/dist/queue/contracts/QueueableJobContract.d.ts +12 -0
- package/dist/queue/contracts/QueueableJobContract.js +1 -0
- package/dist/queue/contracts/index.d.ts +4 -0
- package/dist/queue/contracts/index.js +2 -0
- package/dist/queue/drivers/DatabaseQueueDriver.d.ts +4 -0
- package/dist/queue/drivers/DatabaseQueueDriver.js +27 -3
- package/dist/queue/drivers/RedisQueueDriver.d.ts +7 -0
- package/dist/queue/drivers/RedisQueueDriver.js +37 -0
- package/dist/queue/index.d.ts +5 -0
- package/dist/queue/index.js +5 -0
- package/dist/queue/jobEnvelopeHasPrefix.d.ts +3 -0
- package/dist/queue/jobEnvelopeHasPrefix.js +4 -0
- package/dist/scheduler/ScheduledEvent.d.ts +8 -4
- package/dist/scheduler/ScheduledEvent.js +17 -3
- package/dist/scheduler/ScheduledJob.d.ts +1 -1
- package/dist/scheduler/Scheduler.d.ts +5 -0
- package/dist/scheduler/Scheduler.js +92 -28
- package/dist/scheduler/SchedulerCheckpointRecord.d.ts +16 -0
- package/dist/scheduler/SchedulerCheckpointRecord.js +53 -0
- package/dist/scheduler/SchedulerWorker.d.ts +3 -5
- package/dist/scheduler/SchedulerWorker.js +58 -14
- package/dist/scheduler/console.js +3 -1
- package/dist/scheduler/contracts/Schedule.d.ts +19 -0
- package/dist/scheduler/contracts/Schedule.js +1 -0
- package/dist/scheduler/contracts/Scheduler.d.ts +18 -6
- package/dist/scheduler/contracts/SchedulerCheckpoint.d.ts +23 -0
- package/dist/scheduler/contracts/SchedulerCheckpoint.js +1 -0
- package/dist/scheduler/contracts/SchedulerConsole.d.ts +5 -0
- package/dist/scheduler/contracts/SchedulerWorker.d.ts +6 -1
- package/dist/scheduler/contracts/index.d.ts +2 -0
- package/dist/scheduler/contracts/index.js +2 -0
- package/dist/scheduler/index.d.ts +1 -0
- package/dist/scheduler/index.js +1 -0
- package/dist/server/App.d.ts +36 -4
- package/dist/server/App.js +57 -7
- package/dist/server/contracts/HttpErrorHandlerOptions.d.ts +29 -0
- package/dist/server/contracts/HttpErrorHandlerOptions.js +1 -0
- package/dist/server/contracts/index.d.ts +1 -0
- package/dist/server/contracts/index.js +1 -0
- package/dist/server/index.d.ts +4 -0
- package/dist/server/index.js +4 -0
- package/dist/server/publicServerErrorMessage.d.ts +11 -0
- package/dist/server/publicServerErrorMessage.js +16 -0
- package/dist/server/registerBrowserJsonFormatting.d.ts +16 -0
- package/dist/server/registerBrowserJsonFormatting.js +100 -0
- package/dist/server/registerHttpErrorHandler.d.ts +20 -0
- package/dist/server/registerHttpErrorHandler.js +93 -0
- package/dist/ssr/vite/contracts/ViteSsrOptions.d.ts +2 -0
- package/dist/ssr/vite/fastifyViteSsr.js +4 -3
- package/dist/storage/drivers/FlystorageDisk.js +2 -2
- package/dist/storage/index.d.ts +2 -2
- package/dist/storage/index.js +2 -2
- package/dist/websocket/WebSocketChannels.d.ts +18 -0
- package/dist/websocket/WebSocketChannels.js +129 -0
- package/dist/websocket/WebSocketConnection.d.ts +25 -0
- package/dist/websocket/WebSocketConnection.js +244 -0
- package/dist/websocket/WebSockets.d.ts +41 -0
- package/dist/websocket/WebSockets.js +194 -0
- package/dist/websocket/client/WebSocketClient.d.ts +21 -0
- package/dist/websocket/client/WebSocketClient.js +230 -0
- package/dist/websocket/client/index.d.ts +3 -0
- package/dist/websocket/client/index.js +1 -0
- package/dist/websocket/contracts/WebSocketChannel.d.ts +20 -0
- package/dist/websocket/contracts/WebSocketChannel.js +1 -0
- package/dist/websocket/contracts/WebSocketClient.d.ts +45 -0
- package/dist/websocket/contracts/WebSocketClient.js +1 -0
- package/dist/websocket/contracts/WebSocketEndpoint.d.ts +43 -0
- package/dist/websocket/contracts/WebSocketEndpoint.js +1 -0
- package/dist/websocket/contracts/WebSocketOptions.d.ts +48 -0
- package/dist/websocket/contracts/WebSocketOptions.js +1 -0
- package/dist/websocket/contracts/WebSocketPresence.d.ts +6 -0
- package/dist/websocket/contracts/WebSocketPresence.js +1 -0
- package/dist/websocket/contracts/WebSocketServiceOptions.d.ts +12 -0
- package/dist/websocket/contracts/WebSocketServiceOptions.js +1 -0
- package/dist/websocket/contracts/index.d.ts +6 -0
- package/dist/websocket/contracts/index.js +1 -0
- package/dist/websocket/defineChannel.d.ts +8 -0
- package/dist/websocket/defineChannel.js +13 -0
- package/dist/websocket/defineWebSocket.d.ts +14 -0
- package/dist/websocket/defineWebSocket.js +4 -0
- package/dist/websocket/fastify.d.ts +11 -0
- package/dist/websocket/fastify.js +38 -0
- package/dist/websocket/index.d.ts +5 -0
- package/dist/websocket/index.js +4 -0
- package/package.json +108 -7
- package/src/ai/AIErrors.ts +10 -0
- package/src/ai/AIFailover.ts +3 -2
- package/src/ai/AIProviderAdmission.ts +329 -0
- package/src/ai/AIRateLimiter.ts +134 -10
- package/src/ai/AIRequestTrackingError.ts +37 -0
- package/src/ai/Agent.ts +85 -71
- package/src/ai/Ai.ts +104 -48
- package/src/ai/OpenAIProviderError.ts +1 -1
- package/src/ai/ProviderSseObserver.ts +89 -0
- package/src/ai/README.md +216 -11
- package/src/ai/aiServiceTier.ts +14 -0
- package/src/ai/chunkEmbeddingText.ts +137 -0
- package/src/ai/contracts/AI.ts +17 -0
- package/src/ai/contracts/AIRequestErrorDiagnostics.ts +12 -0
- package/src/ai/contracts/AIServiceTier.ts +2 -0
- package/src/ai/contracts/Agent.ts +3 -0
- package/src/ai/contracts/EmbeddingTextChunk.ts +26 -0
- package/src/ai/contracts/Pricing.ts +7 -1
- package/src/ai/contracts/Providers.ts +2 -0
- package/src/ai/contracts/index.ts +2 -0
- package/src/ai/examples/prepareDocumentEmbeddings.ts +20 -0
- package/src/ai/index.ts +9 -2
- package/src/ai/{Models.ts → modelPricing.ts} +37 -4
- package/src/apps/AppInstallation.ts +25 -0
- package/src/apps/AppRouteError.ts +8 -0
- package/src/apps/AppService.ts +30 -0
- package/src/apps/Apps.ts +508 -0
- package/src/apps/README.md +354 -0
- package/src/apps/appsPlugin.ts +34 -0
- package/src/apps/commands/disableApp.ts +6 -0
- package/src/apps/commands/enableApp.ts +6 -0
- package/src/apps/commands/index.ts +29 -0
- package/src/apps/commands/installApp.ts +6 -0
- package/src/apps/commands/listApps.ts +6 -0
- package/src/apps/commands/makeAppMigration.ts +9 -0
- package/src/apps/commands/rollbackApp.ts +6 -0
- package/src/apps/commands/uninstallApp.ts +6 -0
- package/src/apps/contracts/AppAction.ts +2 -0
- package/src/apps/contracts/AppDefinition.ts +49 -0
- package/src/apps/contracts/AppDescription.ts +27 -0
- package/src/apps/contracts/AppManifest.ts +32 -0
- package/src/apps/contracts/AppNavigation.ts +10 -0
- package/src/apps/contracts/AppNavigationBadge.ts +6 -0
- package/src/apps/contracts/AppNavigationContext.ts +6 -0
- package/src/apps/contracts/AppNavigationResult.ts +9 -0
- package/src/apps/contracts/AppRoute.ts +18 -0
- package/src/apps/contracts/DiscoveredApp.ts +11 -0
- package/src/apps/contracts/InstalledApps.ts +2 -0
- package/src/apps/contracts/index.ts +11 -0
- package/src/apps/defineApp.ts +10 -0
- package/src/apps/discoverApps.ts +56 -0
- package/src/apps/fastify.ts +1 -0
- package/src/apps/index.ts +7 -0
- package/src/apps/normalizeAppNavigation.ts +29 -0
- package/src/apps/registerAppRoutes.ts +48 -0
- package/src/apps/validateAppDefinitions.ts +52 -0
- package/src/apps/vite.ts +1 -0
- package/src/apps/writeAppTypes.ts +14 -0
- package/src/auth/Auth.ts +89 -23
- package/src/auth/PasswordLoginAttempt.ts +72 -0
- package/src/auth/PasswordSuspendedError.ts +13 -0
- package/src/auth/README.md +94 -4
- package/src/auth/contracts/PasswordAuthProviderOptions.ts +30 -0
- package/src/auth/contracts/PasswordSuspension.ts +7 -0
- package/src/auth/contracts/PasswordSuspensionOptions.ts +10 -0
- package/src/auth/contracts/index.ts +3 -0
- package/src/auth/examples/runPasswordAuth.ts +6 -6
- package/src/auth/index.ts +2 -0
- package/src/auth/providers/PasswordAuthProvider.ts +96 -30
- package/src/auth/providers/resolveAuthProviders.ts +1 -0
- package/src/cli/Cli.ts +9 -0
- package/src/cli/README.md +19 -0
- package/src/cli/commands/repl.ts +2 -1
- package/src/cli/contracts/CliCommand.ts +2 -0
- package/src/cli/contracts/CliCommandInfo.ts +13 -0
- package/src/cli/contracts/index.ts +1 -0
- package/src/cli/index.ts +1 -0
- package/src/cli/listDb3Commands.ts +12 -0
- package/src/cli/runDb3.ts +5 -51
- package/src/cli/withDb3Cli.ts +55 -0
- package/src/db/ActiveQueryBuilder.ts +12 -0
- package/src/db/ActiveRecord.ts +9 -0
- package/src/db/README.md +45 -1
- package/src/db/connection.ts +12 -1
- package/src/db/examples/FieldNote.ts +7 -13
- package/src/db/examples/KnowledgeNote.ts +7 -13
- package/src/db/examples/runNoteMigrations.ts +11 -11
- package/src/db/fields/TimestampField.ts +8 -17
- package/src/db/migrations/DatabaseMigrationManager.ts +12 -4
- package/src/db/migrations/contracts/DatabaseMigration.ts +9 -0
- package/src/db/migrations/index.ts +1 -1
- package/src/db/migrations/{KnexMigrationRenderer.ts → renderKnexMigration.ts} +8 -14
- package/src/flows/FlowCompiler.ts +1 -1
- package/src/flows/Flows.ts +1 -1
- package/src/flows/index.ts +1 -1
- package/src/health/Health.ts +163 -0
- package/src/health/README.md +46 -0
- package/src/health/contracts/Health.ts +47 -0
- package/src/health/contracts/HealthHttp.ts +19 -0
- package/src/health/contracts/index.ts +2 -0
- package/src/health/databaseHealthCheck.ts +21 -0
- package/src/health/fastify.ts +49 -0
- package/src/health/index.ts +3 -0
- package/src/in-app/InApp.ts +173 -0
- package/src/in-app/InAppError.ts +8 -0
- package/src/in-app/InAppRecord.ts +41 -0
- package/src/in-app/README.md +193 -0
- package/src/in-app/contracts/InAppInbox.ts +51 -0
- package/src/in-app/contracts/InAppMessage.ts +19 -0
- package/src/in-app/contracts/InAppScope.ts +12 -0
- package/src/in-app/contracts/index.ts +3 -0
- package/src/in-app/examples/sendReportReady.ts +14 -0
- package/src/in-app/index.ts +4 -0
- package/src/in-app/validation.ts +49 -0
- package/src/index.ts +2 -22
- package/src/logging/DevelopmentConsole.ts +154 -0
- package/src/logging/Log.ts +5 -2
- package/src/logging/PrettyLogFormatter.ts +165 -0
- package/src/logging/README.md +52 -109
- package/src/logging/acquireDevelopmentConsole.ts +19 -0
- package/src/logging/contracts/DevelopmentConsoleOptions.ts +13 -0
- package/src/logging/contracts/EmailLogOptions.ts +9 -0
- package/src/logging/contracts/HttpExchangeMonitorOptions.ts +13 -0
- package/src/logging/contracts/LogTransportOptions.ts +10 -0
- package/src/logging/contracts/LoggingOptions.ts +12 -1
- package/src/logging/contracts/index.ts +4 -0
- package/src/logging/development/README.md +88 -0
- package/src/logging/drivers/PinoLoggerDriver.ts +72 -20
- package/src/logging/examples/runDevelopmentLogs.ts +36 -0
- package/src/logging/formatLogEmail.ts +24 -0
- package/src/logging/highlightQueueMessage.ts +38 -0
- package/src/logging/httpBodyCapture.ts +393 -0
- package/src/logging/index.ts +2 -0
- package/src/logging/redactLogEmail.ts +12 -0
- package/src/logging/registerHttpExchangeMonitor.ts +45 -0
- package/src/logging/transports/EmailLogTransport.ts +46 -0
- package/src/mail/Mail.ts +5 -0
- package/src/mail/MailDeliveryError.ts +8 -0
- package/src/mail/README.md +11 -1
- package/src/mail/index.ts +1 -0
- package/src/mail/transports/MailgunTransport.ts +2 -0
- package/src/mail/transports/ResendTransport.ts +24 -22
- package/src/media/MediaManager.ts +31 -10
- package/src/media/README.md +4 -0
- package/src/media/examples/runPrivateFiles.ts +2 -2
- package/src/network/BlockedUrlError.ts +19 -0
- package/src/network/README.md +133 -0
- package/src/network/assertPublicUrl.ts +77 -0
- package/src/network/contracts/GuardedFetch.ts +40 -0
- package/src/network/contracts/PublicUrlOptions.ts +17 -0
- package/src/network/contracts/index.ts +2 -0
- package/src/network/examples/runGuardedFetch.ts +35 -0
- package/src/network/guardedFetch.ts +150 -0
- package/src/network/index.ts +6 -0
- package/src/network/playwright/GuardedBrowserProxy.ts +172 -0
- package/src/network/playwright/contracts/GuardedBrowserContextOptions.ts +43 -0
- package/src/network/playwright/contracts/index.ts +1 -0
- package/src/network/playwright/index.ts +2 -0
- package/src/network/playwright/newGuardedBrowserContext.ts +74 -0
- package/src/network/privateNetworkAddresses.ts +166 -0
- package/src/network/publicAddressLookup.ts +49 -0
- package/src/notifications/Notifications.ts +105 -0
- package/src/notifications/README.md +59 -0
- package/src/notifications/contracts/Notification.ts +65 -0
- package/src/notifications/contracts/NotificationDelivery.ts +11 -0
- package/src/notifications/contracts/index.ts +2 -0
- package/src/notifications/examples/ReportReadyNotification.ts +31 -0
- package/src/notifications/index.ts +2 -0
- package/src/queue/JobRunAttempt.ts +17 -0
- package/src/queue/JobRunEvent.ts +16 -0
- package/src/queue/JobRunStoppedError.ts +8 -0
- package/src/queue/Queue.ts +112 -11
- package/src/queue/QueueTerminalError.ts +12 -0
- package/src/queue/QueueWorker.ts +86 -7
- package/src/queue/QueueWorkerReporter.ts +59 -0
- package/src/queue/QueueableJob.ts +2 -2
- package/src/queue/README.md +142 -1
- package/src/queue/RunnableJob.ts +272 -0
- package/src/queue/console.ts +54 -21
- package/src/queue/contracts/QueueDriver.ts +9 -0
- package/src/queue/contracts/QueueJobRunner.ts +4 -0
- package/src/queue/contracts/QueuePayload.ts +1 -1
- package/src/queue/contracts/QueueSelection.ts +11 -0
- package/src/queue/contracts/QueueService.ts +19 -4
- package/src/queue/contracts/QueueWorkerLifecycle.ts +2 -2
- package/src/queue/contracts/QueueWorkerSnapshot.ts +15 -0
- package/src/queue/contracts/QueueableJob.ts +7 -3
- package/src/queue/contracts/QueueableJobContract.ts +13 -0
- package/src/queue/contracts/index.ts +6 -0
- package/src/queue/drivers/DatabaseQueueDriver.ts +25 -3
- package/src/queue/drivers/RedisQueueDriver.ts +36 -0
- package/src/queue/examples/runQueueSelection.ts +34 -0
- package/src/queue/index.ts +7 -0
- package/src/queue/jobEnvelopeHasPrefix.ts +6 -0
- package/src/scheduler/README.md +50 -9
- package/src/scheduler/ScheduledEvent.ts +20 -5
- package/src/scheduler/ScheduledJob.ts +1 -1
- package/src/scheduler/Scheduler.ts +73 -27
- package/src/scheduler/SchedulerCheckpointRecord.ts +51 -0
- package/src/scheduler/SchedulerWorker.ts +54 -19
- package/src/scheduler/console.ts +3 -1
- package/src/scheduler/contracts/Schedule.ts +22 -0
- package/src/scheduler/contracts/Scheduler.ts +21 -6
- package/src/scheduler/contracts/SchedulerCheckpoint.ts +23 -0
- package/src/scheduler/contracts/SchedulerConsole.ts +5 -0
- package/src/scheduler/contracts/SchedulerWorker.ts +6 -1
- package/src/scheduler/contracts/index.ts +2 -0
- package/src/scheduler/examples/runSchedulerWindow.ts +54 -0
- package/src/scheduler/index.ts +1 -0
- package/src/server/App.ts +73 -10
- package/src/server/README.md +95 -2
- package/src/server/contracts/HttpErrorHandlerOptions.ts +29 -0
- package/src/server/contracts/index.ts +1 -0
- package/src/server/examples/createFirstServer.ts +5 -3
- package/src/server/index.ts +4 -0
- package/src/server/publicServerErrorMessage.ts +17 -0
- package/src/server/registerBrowserJsonFormatting.ts +94 -0
- package/src/server/registerHttpErrorHandler.ts +96 -0
- package/src/ssr/README.md +6 -0
- package/src/ssr/vite/contracts/ViteSsrOptions.ts +2 -0
- package/src/ssr/vite/fastifyViteSsr.ts +4 -3
- package/src/storage/drivers/FlystorageDisk.ts +2 -2
- package/src/storage/index.ts +2 -2
- package/src/websocket/README.md +458 -0
- package/src/websocket/WebSocketChannels.ts +99 -0
- package/src/websocket/WebSocketConnection.ts +162 -0
- package/src/websocket/WebSockets.ts +157 -0
- package/src/websocket/client/WebSocketClient.ts +188 -0
- package/src/websocket/client/index.ts +3 -0
- package/src/websocket/contracts/WebSocketChannel.ts +23 -0
- package/src/websocket/contracts/WebSocketClient.ts +48 -0
- package/src/websocket/contracts/WebSocketEndpoint.ts +46 -0
- package/src/websocket/contracts/WebSocketOptions.ts +50 -0
- package/src/websocket/contracts/WebSocketPresence.ts +6 -0
- package/src/websocket/contracts/WebSocketServiceOptions.ts +12 -0
- package/src/websocket/contracts/index.ts +6 -0
- package/src/websocket/defineChannel.ts +14 -0
- package/src/websocket/defineWebSocket.ts +15 -0
- package/src/websocket/examples/board/LiveBoard.ts +97 -0
- package/src/websocket/examples/board/SummarizeBoardJob.ts +52 -0
- package/src/websocket/examples/board/boardSnapshot.ts +16 -0
- package/src/websocket/examples/board/createBoardClient.ts +43 -0
- package/src/websocket/examples/board/createBoardStore.ts +58 -0
- package/src/websocket/examples/board/registerBoardRoutes.ts +31 -0
- package/src/websocket/examples/createChannelSync.ts +66 -0
- package/src/websocket/examples/deploymentEndpoint.ts +13 -0
- package/src/websocket/examples/deploymentSnapshot.ts +36 -0
- package/src/websocket/examples/resourceChannels.ts +18 -0
- package/src/websocket/examples/userEndpoint.ts +27 -0
- package/src/websocket/fastify.ts +39 -0
- package/src/websocket/index.ts +5 -0
- package/templates/AGENTS.md +33 -2
- /package/dist/flows/{FlowValueValidator.d.ts → flowValueValidator.d.ts} +0 -0
- /package/dist/flows/{FlowValueValidator.js → flowValueValidator.js} +0 -0
- /package/dist/storage/{mime.d.ts → mimeTypeFromPath.d.ts} +0 -0
- /package/dist/storage/{mime.js → mimeTypeFromPath.js} +0 -0
- /package/dist/storage/{contents.d.ts → storageContentsToBuffer.d.ts} +0 -0
- /package/dist/storage/{contents.js → storageContentsToBuffer.js} +0 -0
- /package/src/flows/{FlowValueValidator.ts → flowValueValidator.ts} +0 -0
- /package/src/storage/{mime.ts → mimeTypeFromPath.ts} +0 -0
- /package/src/storage/{contents.ts → storageContentsToBuffer.ts} +0 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { listApps } from './listApps.js';
|
|
2
|
+
import { installApp } from './installApp.js';
|
|
3
|
+
import { enableApp } from './enableApp.js';
|
|
4
|
+
import { disableApp } from './disableApp.js';
|
|
5
|
+
import { uninstallApp } from './uninstallApp.js';
|
|
6
|
+
import { rollbackApp } from './rollbackApp.js';
|
|
7
|
+
import { makeAppMigration } from './makeAppMigration.js';
|
|
8
|
+
export { listApps, installApp, enableApp, disableApp, uninstallApp, makeAppMigration, rollbackApp };
|
|
9
|
+
/** CLI adapters for the same app-management operations used by programmatic and visual clients. */
|
|
10
|
+
export declare const appsCommands: import("../../cli/index.js").CliCommand[];
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { defineCommand } from '../../cli/index.js';
|
|
2
|
+
import { listApps } from './listApps.js';
|
|
3
|
+
import { installApp } from './installApp.js';
|
|
4
|
+
import { enableApp } from './enableApp.js';
|
|
5
|
+
import { disableApp } from './disableApp.js';
|
|
6
|
+
import { uninstallApp } from './uninstallApp.js';
|
|
7
|
+
import { rollbackApp } from './rollbackApp.js';
|
|
8
|
+
import { makeAppMigration } from './makeAppMigration.js';
|
|
9
|
+
export { listApps, installApp, enableApp, disableApp, uninstallApp, makeAppMigration, rollbackApp };
|
|
10
|
+
/** CLI adapters for the same app-management operations used by programmatic and visual clients. */
|
|
11
|
+
export const appsCommands = [
|
|
12
|
+
defineCommand({ name: 'apps:list', description: 'Inspect app definitions and installation state.', handle: listApps }),
|
|
13
|
+
defineCommand({
|
|
14
|
+
name: 'apps:make-migration', description: 'Generate a local app migration without changing the database.',
|
|
15
|
+
parameters: [{ name: 'id', required: true }, { name: 'name', required: false }],
|
|
16
|
+
/** Delegates development source generation to the app-owned migration manager. */
|
|
17
|
+
handle: parameters => makeAppMigration(parameters.id, parameters.name),
|
|
18
|
+
}),
|
|
19
|
+
...[
|
|
20
|
+
['install', installApp], ['enable', enableApp], ['disable', disableApp], ['uninstall', uninstallApp], ['rollback', rollbackApp],
|
|
21
|
+
].map(([action, operation]) => defineCommand({
|
|
22
|
+
name: `apps:${action}`, description: `${action} a registered app in a stopped maintenance process.`,
|
|
23
|
+
parameters: [{ name: 'id', required: true }],
|
|
24
|
+
/** Maps CLI input to the normal service action. */
|
|
25
|
+
handle: parameters => operation(parameters.id),
|
|
26
|
+
})),
|
|
27
|
+
];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { app } from '../../server/index.js';
|
|
2
|
+
/** Generates a frozen app-owned migration and snapshot in development, without applying DDL. */
|
|
3
|
+
export async function makeAppMigration(id, name) {
|
|
4
|
+
await app().apps.load(id);
|
|
5
|
+
const manager = app().apps.migrations(id);
|
|
6
|
+
if (!manager)
|
|
7
|
+
throw new Error(`App "${id}" has no database definition.`);
|
|
8
|
+
return manager.makeMigration({ name });
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { App } from '../../server/App.js';
|
|
2
|
+
import type { ActiveRecordClass } from '../../db/index.js';
|
|
3
|
+
import type { AppManifest } from './AppManifest.js';
|
|
4
|
+
import type { AppRoute } from './AppRoute.js';
|
|
5
|
+
import type { QueueableJobClass } from '../../queue/index.js';
|
|
6
|
+
import type { Schedule } from '../../scheduler/index.js';
|
|
7
|
+
import type { AppNavigation } from './AppNavigation.js';
|
|
8
|
+
import type { AppNavigationContext } from './AppNavigationContext.js';
|
|
9
|
+
/** Explicit contributions of one local or npm-distributed app. Importing it has no runtime effects. */
|
|
10
|
+
export interface AppDefinition<TService = unknown> {
|
|
11
|
+
manifest: AppManifest;
|
|
12
|
+
/** Creates one public service in the host runtime; never create a second framework App. */
|
|
13
|
+
create(host: App): TService;
|
|
14
|
+
/** App-owned models and immutable migration assets, resolved relative to the defining module. */
|
|
15
|
+
database?: {
|
|
16
|
+
models: readonly ActiveRecordClass[];
|
|
17
|
+
/** Directory containing migrations/ and schema.snapshot.json, in source or a published package. */
|
|
18
|
+
directory: URL;
|
|
19
|
+
};
|
|
20
|
+
/** Retry-safe app-owned setup after migrations have succeeded. */
|
|
21
|
+
afterInstall?(host: App): void | Promise<void>;
|
|
22
|
+
routes?: readonly AppRoute<TService>[];
|
|
23
|
+
/** Serializable job classes with explicit names beneath this app's id, such as social.review. */
|
|
24
|
+
jobs?: readonly QueueableJobClass[];
|
|
25
|
+
/** Synchronously declares recurring work for the enabled app during each process boot. */
|
|
26
|
+
schedule?(schedule: Schedule, service: TService): void;
|
|
27
|
+
/** Computes viewer-specific navigation. Undefined uses manifest links; null hides the app. */
|
|
28
|
+
navigation?(context: AppNavigationContext, service: TService): AppNavigation | null | undefined | Promise<AppNavigation | null | undefined>;
|
|
29
|
+
/** Starts resources after dependency services exist. Use defer immediately for failure-safe cleanup. */
|
|
30
|
+
start?(context: AppStartContext<TService>): void | Promise<void>;
|
|
31
|
+
/** Checks app-specific outstanding work before uninstall; throwing leaves the installation intact. */
|
|
32
|
+
beforeUninstall?(host: App): void | Promise<void>;
|
|
33
|
+
}
|
|
34
|
+
/** Resource ownership during startup. Cleanup runs in reverse registration order, including on failure. */
|
|
35
|
+
export interface AppStartContext<TService> {
|
|
36
|
+
host: App;
|
|
37
|
+
service: TService;
|
|
38
|
+
defer(cleanup: () => void | Promise<void>): void;
|
|
39
|
+
}
|
|
40
|
+
/** Explicit host composition, keyed by the matching manifest identifier. */
|
|
41
|
+
export type AppDefinitions = Readonly<Record<string, AppDefinition<any>>>;
|
|
42
|
+
/** Optional public service types inferred from the host's actual composition. */
|
|
43
|
+
export type AppServices<TDefinitions extends AppDefinitions> = {
|
|
44
|
+
readonly [K in keyof TDefinitions]: TDefinitions[K] extends AppDefinition<infer TService> ? TService | undefined : never;
|
|
45
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { AppManifest } from './AppManifest.js';
|
|
2
|
+
import type { ScheduledTaskDefinition } from '../../scheduler/index.js';
|
|
3
|
+
/** Durable installation state. Enabled installations become available only after a successful boot. */
|
|
4
|
+
export type AppInstallationState = 'enabled' | 'disabled' | 'uninstalled' | 'failed';
|
|
5
|
+
/** Inspectable app structure without constructors, secrets or filesystem paths. */
|
|
6
|
+
export interface AppDescription {
|
|
7
|
+
manifest: AppManifest;
|
|
8
|
+
registered: boolean;
|
|
9
|
+
state: AppInstallationState | 'available';
|
|
10
|
+
ready: boolean;
|
|
11
|
+
installedVersion: string | null;
|
|
12
|
+
models: {
|
|
13
|
+
name: string;
|
|
14
|
+
table: string;
|
|
15
|
+
}[];
|
|
16
|
+
routes: {
|
|
17
|
+
method: string;
|
|
18
|
+
path: string;
|
|
19
|
+
}[];
|
|
20
|
+
/** Stable durable job names owned by this app. */
|
|
21
|
+
jobs: string[];
|
|
22
|
+
/** Runtime declarations collected during boot; empty before the first boot. */
|
|
23
|
+
schedules: ScheduledTaskDefinition[];
|
|
24
|
+
}
|
|
25
|
+
/** Browser renderer contract. The host supplies its own component type and routing implementation. */
|
|
26
|
+
export interface AppClientDefinition<TComponent> {
|
|
27
|
+
id: string;
|
|
28
|
+
/** Statically discoverable lazy import, allowing bundlers to keep server code out of browser assets. */
|
|
29
|
+
load(): Promise<{
|
|
30
|
+
default: TComponent;
|
|
31
|
+
}>;
|
|
32
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { AppNavigationBadge } from './AppNavigationBadge.js';
|
|
2
|
+
/** Browser-safe description of an app, shared by runtime, navigation and visual tools. */
|
|
3
|
+
export interface AppManifest {
|
|
4
|
+
/** Stable lowercase identifier; also owns the database and route namespaces. */
|
|
5
|
+
id: string;
|
|
6
|
+
name: string;
|
|
7
|
+
/** Stable semantic release version, for example 1.2.0. */
|
|
8
|
+
version: string;
|
|
9
|
+
description?: string;
|
|
10
|
+
/** Plain text glyph or emoji. Render as text, never as HTML. */
|
|
11
|
+
icon?: string;
|
|
12
|
+
/** Public service contract generation, independent of package release version. */
|
|
13
|
+
apiVersion?: number;
|
|
14
|
+
/** Required app identifiers mapped to their exact public API generation. */
|
|
15
|
+
requires?: Readonly<Record<string, number>>;
|
|
16
|
+
/** Optional integrations; absent apps are allowed, incompatible installed apps are not. */
|
|
17
|
+
optional?: Readonly<Record<string, number>>;
|
|
18
|
+
/** Default destinations beneath /apps/{id}; a runtime navigation provider may replace these per viewer. */
|
|
19
|
+
navigation?: readonly AppMenuItem[];
|
|
20
|
+
}
|
|
21
|
+
/** One app-owned navigation item; nesting is deliberately limited to one level. */
|
|
22
|
+
export interface AppMenuItem {
|
|
23
|
+
id: string;
|
|
24
|
+
label: string;
|
|
25
|
+
/** Empty string opens the app's main view; otherwise a simple relative path. */
|
|
26
|
+
path: string;
|
|
27
|
+
badge?: AppNavigationBadge;
|
|
28
|
+
/** Optional plain-text information about this destination. */
|
|
29
|
+
description?: string;
|
|
30
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { AppMenuItem } from './AppManifest.js';
|
|
2
|
+
import type { AppNavigationBadge } from './AppNavigationBadge.js';
|
|
3
|
+
/** One app's current navigation contribution. Return null from the provider to hide the app for this viewer. */
|
|
4
|
+
export interface AppNavigation {
|
|
5
|
+
items: readonly AppMenuItem[];
|
|
6
|
+
badge?: AppNavigationBadge;
|
|
7
|
+
/** Short, plain-text information beneath the app's name. */
|
|
8
|
+
description?: string;
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Request-scoped identity supplied by the host after authentication and scope authorization. Never store it on an app singleton. */
|
|
2
|
+
export interface AppNavigationContext {
|
|
3
|
+
readonly actor: {
|
|
4
|
+
readonly id: string;
|
|
5
|
+
};
|
|
6
|
+
/** Optional organisation already authorized by the host; apps must still enforce their own data permissions. */
|
|
7
|
+
readonly organisationId?: string;
|
|
8
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AppNavigation } from './AppNavigation.js';
|
|
2
|
+
/** Browser-safe contributions for one viewer. Results are request-scoped and must not be cached across users. */
|
|
3
|
+
export interface AppNavigationResult {
|
|
4
|
+
/** Registry-owned identity and public metadata attached to each successful contribution. */
|
|
5
|
+
apps: Array<AppNavigation & {
|
|
6
|
+
appId: string;
|
|
7
|
+
name: string;
|
|
8
|
+
icon?: string;
|
|
9
|
+
}>;
|
|
10
|
+
/** Apps whose providers failed or returned invalid data. Their links are omitted without exposing error details. */
|
|
11
|
+
unavailable: string[];
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Transport-neutral authenticated request passed to an app-owned route. */
|
|
2
|
+
export interface AppRouteContext<TService> {
|
|
3
|
+
service: TService;
|
|
4
|
+
/** Identity established by the host adapter; never taken from a request body. */
|
|
5
|
+
actor: {
|
|
6
|
+
id: string;
|
|
7
|
+
};
|
|
8
|
+
body: unknown;
|
|
9
|
+
params: Readonly<Record<string, string>>;
|
|
10
|
+
query: Readonly<Record<string, unknown>>;
|
|
11
|
+
}
|
|
12
|
+
/** One route mounted beneath /api/apps/{appId}; authorization remains mandatory in the adapter. */
|
|
13
|
+
export interface AppRoute<TService = unknown> {
|
|
14
|
+
method: 'GET' | 'POST' | 'PATCH' | 'PUT' | 'DELETE';
|
|
15
|
+
path: string;
|
|
16
|
+
/** HTTP success status; defaults to 200. */
|
|
17
|
+
status?: number;
|
|
18
|
+
handle(context: AppRouteContext<TService>): unknown | Promise<unknown>;
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AppManifest } from './AppManifest.js';
|
|
2
|
+
/** Metadata-only discovery result; reading it does not import the app's server or browser code. */
|
|
3
|
+
export interface DiscoveredApp {
|
|
4
|
+
manifest: AppManifest;
|
|
5
|
+
directory: string;
|
|
6
|
+
entry: string;
|
|
7
|
+
client?: string;
|
|
8
|
+
/** Direct npm dependency, absent for an in-project apps/{id} directory. */
|
|
9
|
+
packageName?: string;
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type { AppManifest, AppMenuItem } from './AppManifest.js';
|
|
2
|
+
export type { AppDefinition, AppDefinitions, AppServices, AppStartContext } from './AppDefinition.js';
|
|
3
|
+
export type { AppRoute, AppRouteContext } from './AppRoute.js';
|
|
4
|
+
export type { AppDescription, AppInstallationState, AppClientDefinition } from './AppDescription.js';
|
|
5
|
+
export type { DiscoveredApp } from './DiscoveredApp.js';
|
|
6
|
+
export type { InstalledApps } from './InstalledApps.js';
|
|
7
|
+
export type { AppAction } from './AppAction.js';
|
|
8
|
+
export type { AppNavigation } from './AppNavigation.js';
|
|
9
|
+
export type { AppNavigationBadge } from './AppNavigationBadge.js';
|
|
10
|
+
export type { AppNavigationContext } from './AppNavigationContext.js';
|
|
11
|
+
export type { AppNavigationResult } from './AppNavigationResult.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AppDefinition } from './contracts/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Defines an app without installing, connecting or registering it globally.
|
|
4
|
+
* @param definition - Public service, metadata and app-owned contributions.
|
|
5
|
+
* @returns Definition preserving the inferred public service type.
|
|
6
|
+
*/
|
|
7
|
+
export declare function defineApp<TService>(definition: AppDefinition<TService>): AppDefinition<TService>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Defines an app without installing, connecting or registering it globally.
|
|
3
|
+
* @param definition - Public service, metadata and app-owned contributions.
|
|
4
|
+
* @returns Definition preserving the inferred public service type.
|
|
5
|
+
*/
|
|
6
|
+
export function defineApp(definition) {
|
|
7
|
+
return definition;
|
|
8
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { existsSync, readFileSync, readdirSync } from 'node:fs';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
4
|
+
import { validateAppDefinitions } from './validateAppDefinitions.js';
|
|
5
|
+
/** Discovers local apps and opted-in direct npm dependencies without executing their code. */
|
|
6
|
+
export function discoverApps(directory) {
|
|
7
|
+
const found = [];
|
|
8
|
+
const root = join(directory, 'apps');
|
|
9
|
+
if (existsSync(root)) {
|
|
10
|
+
for (const item of readdirSync(root, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
11
|
+
if (item.isDirectory() && existsSync(join(root, item.name, 'manifest.json')))
|
|
12
|
+
found.push(readApp(join(root, item.name), item.name));
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
const packageFile = join(directory, 'package.json');
|
|
16
|
+
if (existsSync(packageFile)) {
|
|
17
|
+
const host = JSON.parse(readFileSync(packageFile, 'utf8'));
|
|
18
|
+
const require = createRequire(packageFile);
|
|
19
|
+
for (const name of Object.keys({ ...host.dependencies, ...host.optionalDependencies }).sort()) {
|
|
20
|
+
let file;
|
|
21
|
+
try {
|
|
22
|
+
file = require.resolve(`${name}/package.json`);
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
continue;
|
|
26
|
+
} // Packages must export package.json to opt into metadata-only discovery.
|
|
27
|
+
const metadata = JSON.parse(readFileSync(file, 'utf8'));
|
|
28
|
+
if (metadata.db3?.app !== true)
|
|
29
|
+
continue;
|
|
30
|
+
found.push(readApp(dirname(file), basename(name), name, metadata.db3));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const definitions = Object.create(null);
|
|
34
|
+
for (const app of found) {
|
|
35
|
+
const id = app.manifest.id;
|
|
36
|
+
if (Object.hasOwn(definitions, id))
|
|
37
|
+
throw new Error(`Duplicate app "${id}". Keep either the local folder or the npm package.`);
|
|
38
|
+
definitions[id] = { manifest: app.manifest, create: () => undefined };
|
|
39
|
+
}
|
|
40
|
+
validateAppDefinitions(definitions, [...Object.getOwnPropertyNames(Object.prototype), 'then', 'toJSON']);
|
|
41
|
+
return found;
|
|
42
|
+
}
|
|
43
|
+
/** Reads one conventional root manifest and resolves entries contained in that app's directory. */
|
|
44
|
+
function readApp(directory, id, packageName, entries) {
|
|
45
|
+
const manifest = JSON.parse(readFileSync(join(directory, 'manifest.json'), 'utf8'));
|
|
46
|
+
if (manifest.id !== undefined && manifest.id !== id)
|
|
47
|
+
throw new Error(`App folder "${id}" disagrees with manifest identifier "${manifest.id}".`);
|
|
48
|
+
const entry = containedEntry(directory, entries?.entry ?? 'App.ts');
|
|
49
|
+
const clientPath = entries?.client ?? 'client/index.ts';
|
|
50
|
+
const client = containedEntry(directory, clientPath);
|
|
51
|
+
return { manifest: { ...manifest, id }, directory, entry, ...(existsSync(client) ? { client } : {}), ...(packageName ? { packageName } : {}) };
|
|
52
|
+
}
|
|
53
|
+
/** Rejects entry paths that escape the package or local app root. */
|
|
54
|
+
function containedEntry(directory, entry) {
|
|
55
|
+
if (typeof entry !== 'string' || isAbsolute(entry))
|
|
56
|
+
throw new Error('App entries must be relative paths.');
|
|
57
|
+
const target = resolve(directory, entry);
|
|
58
|
+
const path = relative(directory, target);
|
|
59
|
+
if (!path || path === '..' || path.startsWith(`..${sep}`) || isAbsolute(path))
|
|
60
|
+
throw new Error('App entries must remain inside their app directory.');
|
|
61
|
+
return target;
|
|
62
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { registerAppRoutes } from './registerAppRoutes.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { registerAppRoutes } from './registerAppRoutes.js';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from './contracts/index.js';
|
|
2
|
+
export { defineApp } from './defineApp.js';
|
|
3
|
+
export { Apps } from './Apps.js';
|
|
4
|
+
export { AppRouteError } from './AppRouteError.js';
|
|
5
|
+
export { AppService } from './AppService.js';
|
|
6
|
+
export { discoverApps } from './discoverApps.js';
|
|
7
|
+
export { writeAppTypes } from './writeAppTypes.js';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from './contracts/index.js';
|
|
2
|
+
export { defineApp } from './defineApp.js';
|
|
3
|
+
export { Apps } from './Apps.js';
|
|
4
|
+
export { AppRouteError } from './AppRouteError.js';
|
|
5
|
+
export { AppService } from './AppService.js';
|
|
6
|
+
export { discoverApps } from './discoverApps.js';
|
|
7
|
+
export { writeAppTypes } from './writeAppTypes.js';
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** Validates a contribution and copies only supported, browser-safe fields into the response. */
|
|
2
|
+
export function normalizeAppNavigation(value) {
|
|
3
|
+
if (!value || !Array.isArray(value.items))
|
|
4
|
+
throw new Error('Navigation must provide an items array.');
|
|
5
|
+
const ids = new Set();
|
|
6
|
+
return {
|
|
7
|
+
...details(value),
|
|
8
|
+
items: value.items.map(item => {
|
|
9
|
+
if (!item || typeof item.id !== 'string' || !item.id.trim() || ids.has(item.id) || typeof item.label !== 'string' || !item.label.trim() || typeof item.path !== 'string' || !/^(?:[a-z0-9-]+(?:\/[a-z0-9-]+)*)?$/.test(item.path))
|
|
10
|
+
throw new Error('Invalid or duplicate navigation item.');
|
|
11
|
+
ids.add(item.id);
|
|
12
|
+
return { id: item.id, label: item.label, path: item.path, ...details(item) };
|
|
13
|
+
}),
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/** Copies optional display information without passing through arbitrary provider data. */
|
|
17
|
+
function details(value) {
|
|
18
|
+
const result = {};
|
|
19
|
+
if (value.description !== undefined) {
|
|
20
|
+
if (typeof value.description !== 'string')
|
|
21
|
+
throw new Error('Navigation descriptions must be plain text.');
|
|
22
|
+
result.description = value.description;
|
|
23
|
+
}
|
|
24
|
+
if (value.badge !== undefined) {
|
|
25
|
+
if (!value.badge || !Number.isSafeInteger(value.badge.count) || value.badge.count < 0 || typeof value.badge.label !== 'string' || !value.badge.label.trim())
|
|
26
|
+
throw new Error('Navigation badges require a non-negative integer count and an accessible label.');
|
|
27
|
+
result.badge = { count: value.badge.count, label: value.badge.label };
|
|
28
|
+
}
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { FastifyInstance, FastifyRequest } from 'fastify';
|
|
2
|
+
import type { Apps } from './Apps.js';
|
|
3
|
+
/** Mounts dynamic app routes behind mandatory host authorization; newly installed apps become reachable immediately. */
|
|
4
|
+
export declare function registerAppRoutes(server: FastifyInstance, apps: Apps<any>, authorize: (request: FastifyRequest, appId: string) => Promise<{
|
|
5
|
+
id: string;
|
|
6
|
+
}>): void;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { AppRouteError } from './AppRouteError.js';
|
|
2
|
+
/** Mounts dynamic app routes behind mandatory host authorization; newly installed apps become reachable immediately. */
|
|
3
|
+
export function registerAppRoutes(server, apps, authorize) {
|
|
4
|
+
for (const url of ['/api/apps/:appId', '/api/apps/:appId/*']) {
|
|
5
|
+
server.route({
|
|
6
|
+
method: ['GET', 'POST', 'PATCH', 'PUT', 'DELETE'], url,
|
|
7
|
+
/** Drains in-flight requests before lifecycle changes and passes only a verified actor to app code. */
|
|
8
|
+
handler: async (request, reply) => {
|
|
9
|
+
try {
|
|
10
|
+
return await apps.run(async () => {
|
|
11
|
+
const { appId, '*': suffix = '' } = request.params;
|
|
12
|
+
const service = apps.get(appId);
|
|
13
|
+
if (service === undefined)
|
|
14
|
+
return reply.code(404).send({ message: 'App is unavailable.' });
|
|
15
|
+
const candidates = apps.routes().filter(item => item.appId === appId && item.route.method === request.method).sort((a, b) => (a.route.path.match(/:/g)?.length ?? 0) - (b.route.path.match(/:/g)?.length ?? 0));
|
|
16
|
+
for (const { route } of candidates) {
|
|
17
|
+
const params = matchPath(route.path, `/${suffix}`);
|
|
18
|
+
if (!params)
|
|
19
|
+
continue;
|
|
20
|
+
const actor = await authorize(request, appId);
|
|
21
|
+
if (!actor?.id)
|
|
22
|
+
throw new AppRouteError(401, 'Please sign in.');
|
|
23
|
+
const result = await route.handle({ service, actor, body: request.body, params, query: request.query });
|
|
24
|
+
return reply.code(route.status ?? 200).send(result);
|
|
25
|
+
}
|
|
26
|
+
return reply.code(404).send({ message: 'App route not found.' });
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
if (error instanceof AppRouteError)
|
|
31
|
+
return reply.code(error.statusCode).send({ message: error.message });
|
|
32
|
+
throw error;
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/** Matches validated route segments and captures named parameters without evaluating arbitrary regular expressions. */
|
|
39
|
+
function matchPath(pattern, path) {
|
|
40
|
+
const expected = pattern.split('/');
|
|
41
|
+
const actual = path.split('/');
|
|
42
|
+
if (expected.length !== actual.length)
|
|
43
|
+
return;
|
|
44
|
+
const params = Object.create(null);
|
|
45
|
+
for (let index = 0; index < expected.length; index++) {
|
|
46
|
+
if (expected[index].startsWith(':') && actual[index])
|
|
47
|
+
params[expected[index].slice(1)] = actual[index];
|
|
48
|
+
else if (expected[index] !== actual[index])
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
return params;
|
|
52
|
+
}
|