@db3.ai/app 0.1.0-beta.1 → 0.1.0-beta.4
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 +68 -9
- 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
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { LogTransportOptions } from './LogTransportOptions';
|
|
1
2
|
import type { LoggerDriver } from './LoggerDriver';
|
|
2
3
|
import type { LogBindings, LogLevel } from './Logger';
|
|
3
4
|
|
|
@@ -25,6 +26,10 @@ export interface DevtoolsLogOptions {
|
|
|
25
26
|
* Application logging configuration.
|
|
26
27
|
*/
|
|
27
28
|
export interface LoggingOptions {
|
|
29
|
+
/** Explicit destinations replace default console/file/devtools selection. An empty array disables output. */
|
|
30
|
+
transports?: LogTransportOptions[];
|
|
31
|
+
/** Optional JSON log file retained outside the process/container. The operator owns rotation and retention. */
|
|
32
|
+
file?: string;
|
|
28
33
|
/** Injectable logging driver used by tests or alternate implementations. */
|
|
29
34
|
driver?: LoggerDriver;
|
|
30
35
|
/** Minimum emitted severity. Defaults to info, or silent in tests. */
|
|
@@ -39,8 +44,14 @@ export interface LoggingOptions {
|
|
|
39
44
|
bindings?: LogBindings;
|
|
40
45
|
/** Sensitive field paths removed before records reach any destination. */
|
|
41
46
|
redact?: false | string[];
|
|
42
|
-
/** Writes
|
|
47
|
+
/** Writes logs to standard output. Defaults to true. */
|
|
43
48
|
console?: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Console presentation only; files and devtools always retain structured JSON.
|
|
51
|
+
* Auto (the default) uses pretty output in development terminals and JSON
|
|
52
|
+
* elsewhere. Set PLATFORM_LOG_FORMAT to override the default process-wide.
|
|
53
|
+
*/
|
|
54
|
+
consoleFormat?: 'auto' | 'pretty' | 'json';
|
|
44
55
|
/**
|
|
45
56
|
* Streams logs to Platform devtools.
|
|
46
57
|
*
|
|
@@ -2,3 +2,7 @@ export * from './HttpExchange';
|
|
|
2
2
|
export * from './Logger';
|
|
3
3
|
export * from './LoggerDriver';
|
|
4
4
|
export * from './LoggingOptions';
|
|
5
|
+
export * from './EmailLogOptions';
|
|
6
|
+
export * from './DevelopmentConsoleOptions';
|
|
7
|
+
export * from './HttpExchangeMonitorOptions';
|
|
8
|
+
export * from './LogTransportOptions';
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# Development logging
|
|
2
|
+
|
|
3
|
+
Development terminals show a small live waiting area immediately on request arrival.
|
|
4
|
+
Completed requests move into permanent blocks in completion order, paired by
|
|
5
|
+
process, source and request ID. Each block contains method, URL, status, duration
|
|
6
|
+
and readable request/response bodies when capture is enabled:
|
|
7
|
+
|
|
8
|
+
```text
|
|
9
|
+
14:50:00 [http] POST → /api/v1/user 201 Created · 842 ms #req-1
|
|
10
|
+
> request
|
|
11
|
+
{"user":1234}
|
|
12
|
+
< response
|
|
13
|
+
{"id":1234,"created":true}
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
The waiting area displays elapsed time, labels requests slow after five seconds,
|
|
17
|
+
and shows at most five rows. It contracts on narrow terminals. Timeouts,
|
|
18
|
+
disconnects and process shutdown produce explicit terminal outcomes. Up to 1,000
|
|
19
|
+
pending requests retain context; eviction is reported and later responses still
|
|
20
|
+
print. Normal console/stdout/stderr messages in the same process appear above
|
|
21
|
+
pending rows. Closing the last logger restores the original stream methods,
|
|
22
|
+
removes timers/listeners and clears the waiting area without clearing history.
|
|
23
|
+
|
|
24
|
+
Install the shared capture adapter **before routes** on a Fastify server using
|
|
25
|
+
`app().log.logger` as its `loggerInstance`:
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { registerHttpExchangeMonitor } from '@db3.ai/app/logging';
|
|
29
|
+
|
|
30
|
+
registerHttpExchangeMonitor(server, {
|
|
31
|
+
exclude: request => request.url.startsWith('/private-reports/'),
|
|
32
|
+
});
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
The adapter only captures in development. `enabled: false` disables capture;
|
|
36
|
+
`maxBodyBytes` defaults to 16 KiB and is capped at 64 KiB per body. Credential
|
|
37
|
+
fields are recursively redacted. Streams and binary bodies show metadata and
|
|
38
|
+
are never consumed for logging. Exclusion controls body/header capture; disable
|
|
39
|
+
route logging separately if even its URL must not appear. Existing JSON and
|
|
40
|
+
devtools destinations retain the captured records.
|
|
41
|
+
|
|
42
|
+
Small JSON values stay inline; larger values are indented. Terminal previews
|
|
43
|
+
show at most 20 lines and 160 characters per line, with explicit omission markers.
|
|
44
|
+
Errors retain bounded stacks and causes. Headers and routine process metadata
|
|
45
|
+
stay out of the terminal presentation. Complete *captured* details remain in
|
|
46
|
+
configured JSON files and devtools; capture limits still apply there.
|
|
47
|
+
|
|
48
|
+
Production, tests and redirected/piped stdout keep newline-delimited JSON.
|
|
49
|
+
Override this with `log: { consoleFormat: 'pretty' }` or
|
|
50
|
+
`PLATFORM_LOG_FORMAT=pretty`; use `json` for raw records. Explicit app options take
|
|
51
|
+
precedence. `auto` restores environment/terminal detection. `NO_COLOR` or
|
|
52
|
+
`FORCE_COLOR=0` disables colours; `TERM=dumb` disables live redraws. Explicit
|
|
53
|
+
pretty output to a pipe is append-only. Files and devtools remain structured.
|
|
54
|
+
|
|
55
|
+
For a multi-process launcher, create **one** `DevelopmentConsole` from
|
|
56
|
+
`@db3.ai/app/logging`, pipe each child's stdout/stderr into separate
|
|
57
|
+
`console.createInput()` streams, and set child `PLATFORM_LOG_FORMAT=json`.
|
|
58
|
+
Call `endSource(child.pid)` after a direct child closes, then `close()` and
|
|
59
|
+
`await flush()` when all streams finish. The renderer cannot coordinate another
|
|
60
|
+
process writing directly to the same terminal. It does not close caller-owned
|
|
61
|
+
streams. Do not create a separate renderer for each child.
|
|
62
|
+
|
|
63
|
+
The shipped `examples/runDevelopmentLogs.ts` demonstrates concurrent requests,
|
|
64
|
+
payloads and interleaved client output without opening a listening socket.
|
|
65
|
+
Interactive development also enables the devtools transport automatically;
|
|
66
|
+
tests only enable network delivery when explicitly configured.
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
## Structured logging lab
|
|
70
|
+
|
|
71
|
+
From your independent app after [Installation](https://db3.ai/docs/installation):
|
|
72
|
+
|
|
73
|
+
```sh
|
|
74
|
+
mkdir -p examples
|
|
75
|
+
cp -R node_modules/@db3.ai/app/src/logging/examples/. examples/
|
|
76
|
+
npx tsx examples/runNoteLogs.ts
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
This captures the real Pino driver's output in a writable stream, with devtools HTTP delivery disabled. Expect three records: `Note saved`, `Summary failed`, and `Diagnostics enabled`. The first debug message is filtered, then changing `log.level` enables debug output. Changing it to silent suppresses later errors. The output omits unstable metadata and stack text only for readability.
|
|
80
|
+
|
|
81
|
+
The [Logging guide](https://db3.ai/docs/logging#testing) contains the exact consumer test. Save it as `tests/logging/runNoteLogs.test.ts` and run:
|
|
82
|
+
|
|
83
|
+
```sh
|
|
84
|
+
npx vitest run tests/logging/runNoteLogs.test.ts
|
|
85
|
+
npx tsc --noEmit --target ES2022 --module ESNext --moduleResolution Bundler --types node --skipLibCheck examples/*.ts
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
The test asserts structured context, error serialization, level changes and the absence of synthetic password/token/provider-key values. It uses the real logger, not a framework mock. This does not prove remote log ingestion or retention.
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { once } from 'node:events';
|
|
2
2
|
import { fileURLToPath } from 'node:url';
|
|
3
3
|
import { hostname } from 'node:os';
|
|
4
|
-
import pino, {
|
|
5
|
-
type DestinationStream,
|
|
6
|
-
type Logger as PinoLogger,
|
|
7
|
-
type TransportTargetOptions,
|
|
8
|
-
} from 'pino';
|
|
4
|
+
import pino, { type DestinationStream, type Logger as PinoLogger, type TransportTargetOptions } from 'pino';
|
|
9
5
|
import type ThreadStream from 'thread-stream';
|
|
10
6
|
|
|
11
7
|
import { isInteractiveDevelopmentEnvironment } from '../../devtools';
|
|
12
8
|
import type * as logging from '../contracts';
|
|
9
|
+
import type { Mail } from '../../mail';
|
|
10
|
+
import { EmailLogTransport } from '../transports/EmailLogTransport';
|
|
11
|
+
import { acquireDevelopmentConsole } from '../acquireDevelopmentConsole';
|
|
13
12
|
|
|
14
13
|
/**
|
|
15
14
|
* Pino worker transport lifecycle members present at runtime but omitted from
|
|
@@ -32,6 +31,8 @@ interface LoggingEnvironment {
|
|
|
32
31
|
PLATFORM_LOG_DEVTOOLS?: string;
|
|
33
32
|
PLATFORM_LOG_LEVEL?: string;
|
|
34
33
|
PLATFORM_LOG_SOURCE?: string;
|
|
34
|
+
PLATFORM_LOG_FILE?: string;
|
|
35
|
+
PLATFORM_LOG_FORMAT?: string;
|
|
35
36
|
npm_package_name?: string;
|
|
36
37
|
}
|
|
37
38
|
|
|
@@ -57,6 +58,8 @@ const defaultRedactions = [
|
|
|
57
58
|
export class PinoLoggerDriver implements logging.LoggerDriver {
|
|
58
59
|
readonly logger: PinoLogger;
|
|
59
60
|
readonly #transport: ManagedPinoTransport | null;
|
|
61
|
+
readonly #emails: { level: logging.LogLevel; stream: EmailLogTransport }[] = [];
|
|
62
|
+
readonly #console?: ReturnType<typeof acquireDevelopmentConsole>;
|
|
60
63
|
#closed = false;
|
|
61
64
|
#closing = false;
|
|
62
65
|
#closePromise: Promise<void> | null = null;
|
|
@@ -66,13 +69,25 @@ export class PinoLoggerDriver implements logging.LoggerDriver {
|
|
|
66
69
|
*
|
|
67
70
|
* @param options - Framework logging configuration.
|
|
68
71
|
* @param destination - Optional direct destination used by focused tests.
|
|
72
|
+
* @param mail - Application-owned mail service used by the email destination.
|
|
69
73
|
*/
|
|
70
74
|
constructor(
|
|
71
75
|
options: logging.LoggingOptions = {},
|
|
72
76
|
destination?: DestinationStream,
|
|
77
|
+
mail?: () => Mail,
|
|
73
78
|
) {
|
|
74
79
|
const environment = options.environment ?? process.env.NODE_ENV ?? 'development';
|
|
75
80
|
const level = resolveLogLevel(options, process.env);
|
|
81
|
+
if ((options.transports?.filter(transport => transport.type === 'console').length ?? 0) > 1) throw new Error('Configure at most one console log transport.');
|
|
82
|
+
for (const transport of options.transports ?? []) {
|
|
83
|
+
if (!['console', 'file', 'email', 'devtools'].includes(transport.type)) throw new Error('Unknown logging transport type.');
|
|
84
|
+
if (transport.level !== undefined && !isLogLevel(transport.level)) throw new Error('Invalid logging transport level.');
|
|
85
|
+
if (transport.type === 'email' && transport.level !== 'silent') {
|
|
86
|
+
if (!mail) throw new Error('Email logging requires an application Mail resolver.');
|
|
87
|
+
this.#emails.push({ level: transport.level ?? 'error', stream: new EmailLogTransport(transport, mail) });
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
76
91
|
const source = options.source
|
|
77
92
|
?? process.env.PLATFORM_LOG_SOURCE
|
|
78
93
|
?? process.env.npm_package_name
|
|
@@ -96,24 +111,38 @@ export class PinoLoggerDriver implements logging.LoggerDriver {
|
|
|
96
111
|
|
|
97
112
|
if (destination) {
|
|
98
113
|
this.#transport = null;
|
|
99
|
-
this.logger = pino(pinoOptions, destination);
|
|
114
|
+
this.logger = pino(pinoOptions, this.#destinations(destination));
|
|
100
115
|
return;
|
|
101
116
|
}
|
|
102
117
|
|
|
103
|
-
const
|
|
118
|
+
const format = options.consoleFormat ?? process.env.PLATFORM_LOG_FORMAT ?? 'auto';
|
|
119
|
+
if (!['auto', 'pretty', 'json'].includes(format)) throw new Error(`Invalid PLATFORM_LOG_FORMAT value "${format}". Use auto, pretty, or json.`);
|
|
120
|
+
const consoleTransport = options.transports?.find(transport => transport.type === 'console');
|
|
121
|
+
const consoleEnabled = options.transports ? Boolean(consoleTransport) : options.console !== false;
|
|
122
|
+
const pretty = consoleEnabled && consoleTransport?.level !== 'silent' && level !== 'silent' && (format === 'pretty' || (format === 'auto' && isInteractiveDevelopmentEnvironment(environment) && Boolean(process.stdout.isTTY)));
|
|
123
|
+
const targets = transportTargets(pretty ? { ...options, console: false, transports: options.transports?.filter(transport => transport.type !== 'console') } : options, level, environment, process.env);
|
|
124
|
+
if (pretty) {
|
|
125
|
+
this.#transport = targets.length ? pino.transport({ targets }) as ManagedPinoTransport : null;
|
|
126
|
+
this.#transport?.on('error', reportTransportError);
|
|
127
|
+
this.#console = acquireDevelopmentConsole();
|
|
128
|
+
const streams: pino.StreamEntry[] = [{ level: (consoleTransport?.level === 'silent' ? 'trace' : consoleTransport?.level) ?? level, stream: this.#console.console }];
|
|
129
|
+
if (this.#transport) streams.push({ level: 'trace', stream: this.#transport });
|
|
130
|
+
this.logger = pino(pinoOptions, this.#destinations(pino.multistream(streams)));
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
104
133
|
|
|
105
134
|
if (targets.length === 0) {
|
|
106
135
|
this.#transport = null;
|
|
107
136
|
this.logger = pino({
|
|
108
137
|
...pinoOptions,
|
|
109
|
-
level: 'silent',
|
|
110
|
-
});
|
|
138
|
+
level: this.#emails.length ? level : 'silent',
|
|
139
|
+
}, this.#emails.length ? this.#destinations({ /** Discards the disabled console destination. */ write() {} }) : undefined);
|
|
111
140
|
return;
|
|
112
141
|
}
|
|
113
142
|
|
|
114
|
-
if (targets.length === 1 && targets[0]?.target === 'pino/file') {
|
|
143
|
+
if (targets.length === 1 && targets[0]?.target === 'pino/file' && targets[0]?.options?.destination === 1 && targets[0]?.level === level) {
|
|
115
144
|
this.#transport = null;
|
|
116
|
-
this.logger = pino(pinoOptions);
|
|
145
|
+
this.logger = pino(pinoOptions, this.#destinations(process.stdout));
|
|
117
146
|
return;
|
|
118
147
|
}
|
|
119
148
|
|
|
@@ -121,7 +150,15 @@ export class PinoLoggerDriver implements logging.LoggerDriver {
|
|
|
121
150
|
targets,
|
|
122
151
|
}) as ManagedPinoTransport;
|
|
123
152
|
this.#transport.on('error', reportTransportError);
|
|
124
|
-
this.logger = pino(pinoOptions, this.#transport);
|
|
153
|
+
this.logger = pino(pinoOptions, this.#destinations(this.#transport));
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** Fans already serialized and redacted records out to ordinary destinations and operator email. */
|
|
157
|
+
#destinations(destination: DestinationStream): DestinationStream {
|
|
158
|
+
return this.#emails.length ? pino.multistream([
|
|
159
|
+
{ level: 'trace', stream: destination },
|
|
160
|
+
...this.#emails,
|
|
161
|
+
]) : destination;
|
|
125
162
|
}
|
|
126
163
|
|
|
127
164
|
/**
|
|
@@ -139,7 +176,8 @@ export class PinoLoggerDriver implements logging.LoggerDriver {
|
|
|
139
176
|
}
|
|
140
177
|
|
|
141
178
|
await new Promise<void>((resolve, reject) => {
|
|
142
|
-
this.logger
|
|
179
|
+
const destination = this.#transport ?? this.logger;
|
|
180
|
+
destination.flush((error?: Error) => {
|
|
143
181
|
if (error) {
|
|
144
182
|
reject(error);
|
|
145
183
|
return;
|
|
@@ -148,6 +186,8 @@ export class PinoLoggerDriver implements logging.LoggerDriver {
|
|
|
148
186
|
resolve();
|
|
149
187
|
});
|
|
150
188
|
});
|
|
189
|
+
await this.#console?.console.flush();
|
|
190
|
+
await Promise.all(this.#emails.map(email => email.stream.flush()));
|
|
151
191
|
} finally {
|
|
152
192
|
if (!this.#closing) {
|
|
153
193
|
this.#transport?.unref();
|
|
@@ -170,6 +210,7 @@ export class PinoLoggerDriver implements logging.LoggerDriver {
|
|
|
170
210
|
if (this.#closed) return;
|
|
171
211
|
|
|
172
212
|
this.#closing = true;
|
|
213
|
+
this.#console?.release();
|
|
173
214
|
await this.flush();
|
|
174
215
|
this.#closed = true;
|
|
175
216
|
|
|
@@ -224,17 +265,28 @@ function transportTargets(
|
|
|
224
265
|
if (level === 'silent') return [];
|
|
225
266
|
|
|
226
267
|
const targets: TransportTargetOptions[] = [];
|
|
268
|
+
if (options.transports) {
|
|
269
|
+
for (const transport of options.transports) {
|
|
270
|
+
const minimum = transport.level ?? level;
|
|
271
|
+
if (minimum === 'silent') continue;
|
|
272
|
+
if (transport.type === 'console') targets.push({ target: 'pino/file', level: minimum, options: { destination: 1 } });
|
|
273
|
+
if (transport.type === 'file') {
|
|
274
|
+
if (!transport.destination) throw new Error('File logging requires a destination.');
|
|
275
|
+
targets.push({ target: 'pino/file', level: minimum, options: { destination: transport.destination, mkdir: true } });
|
|
276
|
+
}
|
|
277
|
+
if (transport.type === 'devtools') targets.push({ target: devtoolsTransportTarget(), level: minimum, options: transport.options ?? {} });
|
|
278
|
+
}
|
|
279
|
+
return targets;
|
|
280
|
+
}
|
|
281
|
+
|
|
227
282
|
|
|
228
283
|
if (options.console !== false) {
|
|
229
|
-
targets.push({
|
|
230
|
-
target: 'pino/file',
|
|
231
|
-
level,
|
|
232
|
-
options: {
|
|
233
|
-
destination: 1,
|
|
234
|
-
},
|
|
235
|
-
});
|
|
284
|
+
targets.push({ target: 'pino/file', level, options: { destination: 1 } });
|
|
236
285
|
}
|
|
237
286
|
|
|
287
|
+
const file = options.file ?? env.PLATFORM_LOG_FILE;
|
|
288
|
+
if (file) targets.push({ target: 'pino/file', level, options: { destination: file, mkdir: true } });
|
|
289
|
+
|
|
238
290
|
if (devtoolsEnabled(options.devtools, environment, env)) {
|
|
239
291
|
targets.push({
|
|
240
292
|
target: devtoolsTransportTarget(),
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { pathToFileURL } from 'node:url';
|
|
2
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
3
|
+
import Fastify, { type FastifyBaseLogger } from 'fastify';
|
|
4
|
+
import { Log, registerHttpExchangeMonitor } from '@db3.ai/app/logging';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Demonstrates overlapping requests without a listening socket, database or provider.
|
|
8
|
+
* Run with tsx in a terminal to see pending rows turn into completed payload blocks.
|
|
9
|
+
*/
|
|
10
|
+
export async function runDevelopmentLogs(): Promise<void> {
|
|
11
|
+
const log = new Log({ environment: 'development', consoleFormat: 'pretty', devtools: false, source: 'demo' });
|
|
12
|
+
const server = Fastify({ loggerInstance: log.logger as FastifyBaseLogger });
|
|
13
|
+
registerHttpExchangeMonitor(server, { environment: 'development' });
|
|
14
|
+
server.post('/api/v1/user', async (request, reply) => {
|
|
15
|
+
await delay(1200);
|
|
16
|
+
reply.code(201);
|
|
17
|
+
return { id: 1234, name: 'Steve', created: true, input: request.body };
|
|
18
|
+
});
|
|
19
|
+
server.get('/api/v1/projects', async () => {
|
|
20
|
+
await delay(300);
|
|
21
|
+
return { projects: [{ id: 1, name: 'Example project' }], total: 1 };
|
|
22
|
+
});
|
|
23
|
+
try {
|
|
24
|
+
log.info('Development console ready');
|
|
25
|
+
await Promise.all([
|
|
26
|
+
server.inject({ method: 'POST', url: '/api/v1/user', payload: { user: 1234 } }),
|
|
27
|
+
server.inject('/api/v1/projects'),
|
|
28
|
+
delay(600).then(() => { console.log('Client rebuilt successfully'); }),
|
|
29
|
+
]);
|
|
30
|
+
} finally {
|
|
31
|
+
await server.close();
|
|
32
|
+
await log.close();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) await runDevelopmentLogs();
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { MailMessage } from '../mail';
|
|
2
|
+
import type { EmailLogOptions } from './contracts';
|
|
3
|
+
import { redactLogEmail } from './redactLogEmail';
|
|
4
|
+
|
|
5
|
+
/** Formats a redacted log record without copying arbitrary nested payloads or exception properties into email. */
|
|
6
|
+
export function formatLogEmail(record: Record<string, unknown>, options: EmailLogOptions): MailMessage {
|
|
7
|
+
const context = Object.fromEntries(Object.entries(record).filter(([key, value]) => key !== 'err' && (value === null || ['string', 'number', 'boolean'].includes(typeof value))));
|
|
8
|
+
const sections = [`Log context (JSON):\n${JSON.stringify(context, null, 2)}`];
|
|
9
|
+
let error = record.err;
|
|
10
|
+
if (typeof error === 'string') sections.push(`Exception: ${error}`);
|
|
11
|
+
for (let depth = 0; error && typeof error === 'object' && depth < 4; depth++) {
|
|
12
|
+
const value = error as Record<string, unknown>;
|
|
13
|
+
sections.push(`${depth ? 'Caused by' : 'Exception'}: ${String(value.type ?? value.name ?? 'Error')}\nMessage: ${String(value.message ?? 'Unavailable')}\nStack trace:\n${String(value.stack ?? 'Unavailable')}`);
|
|
14
|
+
error = value.cause;
|
|
15
|
+
}
|
|
16
|
+
const text = redactLogEmail(sections.join('\n\n'));
|
|
17
|
+
const subject = redactLogEmail(`${options.subjectPrefix ?? 'Application error'}: ${String(record.msg ?? 'Exception logged')}`).replace(/[\r\n]/g, ' ').slice(0, 200);
|
|
18
|
+
return { to: options.to, subject, text, html: `<pre style="white-space:pre-wrap">${escapeHtml(text)}</pre>` };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Escapes log text as inert HTML content in the email's preformatted body. */
|
|
22
|
+
function escapeHtml(text: string): string {
|
|
23
|
+
return text.replace(/[&<>"']/g, character => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[character]!);
|
|
24
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/** Terminal colour for each queue state verb at the start of a `[queue]` message. */
|
|
2
|
+
const STATES: Array<[RegExp, string]> = [
|
|
3
|
+
[/^(Claimed|Running|Dispatched)\b/, '34'],
|
|
4
|
+
[/^(Processed|Retried)\b/, '32'],
|
|
5
|
+
[/^(Released|Deferred)\b/, '33'],
|
|
6
|
+
[/^(Failed|Lost lease|Stopped fenced)\b/, '31'],
|
|
7
|
+
];
|
|
8
|
+
|
|
9
|
+
/** A job label such as `CollectKeywordRanksJob#5249`. */
|
|
10
|
+
const JOB_LABEL = /\b[A-Z][A-Za-z0-9_]*#\d+\b/g;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Colours the parts of a queue log message that are scanned most: the state
|
|
14
|
+
* verb after `[queue] ` (blue in progress, green done, yellow retrying, red
|
|
15
|
+
* failed) and job labels (bold magenta). Other messages are returned unchanged
|
|
16
|
+
* apart from job labels.
|
|
17
|
+
*
|
|
18
|
+
* @param message - Plain log message.
|
|
19
|
+
* @param paint - Wraps text in an SGR code, such as `'32'` or `'1;35'`.
|
|
20
|
+
* @returns The message with colour codes.
|
|
21
|
+
*/
|
|
22
|
+
export function highlightQueueMessage(message: string, paint: (text: string, code: string) => string): string {
|
|
23
|
+
let prefix = '';
|
|
24
|
+
let rest = message;
|
|
25
|
+
if (rest.startsWith('[queue] ')) {
|
|
26
|
+
prefix = '[queue] ';
|
|
27
|
+
rest = rest.slice(prefix.length);
|
|
28
|
+
for (const [pattern, code] of STATES) {
|
|
29
|
+
const match = pattern.exec(rest);
|
|
30
|
+
if (match) {
|
|
31
|
+
prefix += paint(match[0], code);
|
|
32
|
+
rest = rest.slice(match[0].length);
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return prefix + rest.replace(JOB_LABEL, label => paint(label, '1;35'));
|
|
38
|
+
}
|