@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,65 @@
|
|
|
1
|
+
import { normalizeAppNavigation } from './normalizeAppNavigation.js';
|
|
2
|
+
import { isQueueableJobClass, queueableJobName } from '../queue/index.js';
|
|
3
|
+
/** Validates names, contribution ownership and dependency order before any app code is started. */
|
|
4
|
+
export function validateAppDefinitions(definitions, reserved) {
|
|
5
|
+
const ids = Object.keys(definitions);
|
|
6
|
+
const tables = new Set();
|
|
7
|
+
for (const id of ids) {
|
|
8
|
+
const definition = definitions[id];
|
|
9
|
+
const manifest = definition.manifest;
|
|
10
|
+
if (!/^[a-z][a-z0-9_]{0,39}$/.test(id) || /^db3(?:_|$)/.test(id) || reserved.includes(id) || manifest.id !== id)
|
|
11
|
+
throw new Error(`Invalid or reserved app identifier "${id}".`);
|
|
12
|
+
if (!manifest.name?.trim() || !/^\d+\.\d+\.\d+$/.test(manifest.version) || !Number.isSafeInteger(manifest.apiVersion ?? 1) || (manifest.apiVersion ?? 1) < 1)
|
|
13
|
+
throw new Error(`Invalid app manifest for "${id}"; use a stable x.y.z release and a positive API generation.`);
|
|
14
|
+
if (typeof definition.create !== 'function')
|
|
15
|
+
throw new Error(`App "${id}" must create a public service.`);
|
|
16
|
+
const jobs = new Set();
|
|
17
|
+
for (const Job of definition.jobs ?? []) {
|
|
18
|
+
if (!isQueueableJobClass(Job) || !Job.jobName?.startsWith(`${id}.`) || jobs.has(queueableJobName(Job)))
|
|
19
|
+
throw new Error(`Invalid or duplicate job in "${id}"; declare a stable ${id}. jobName.`);
|
|
20
|
+
jobs.add(queueableJobName(Job));
|
|
21
|
+
}
|
|
22
|
+
for (const Model of definition.database?.models ?? []) {
|
|
23
|
+
if (!Model.table.startsWith(`${id}_`) || tables.has(Model.table))
|
|
24
|
+
throw new Error(`App "${id}" cannot own table "${Model.table}".`);
|
|
25
|
+
tables.add(Model.table);
|
|
26
|
+
}
|
|
27
|
+
const paths = new Set();
|
|
28
|
+
for (const route of definition.routes ?? []) {
|
|
29
|
+
const key = `${route.method} ${route.path}`;
|
|
30
|
+
if (!['GET', 'POST', 'PUT', 'PATCH', 'DELETE'].includes(route.method) || !/^\/(?:[a-zA-Z0-9_:-]+(?:\/[a-zA-Z0-9_:-]+)*)?$/.test(route.path) || paths.has(key) || typeof route.handle !== 'function')
|
|
31
|
+
throw new Error(`Invalid or duplicate route "${key}" in "${id}".`);
|
|
32
|
+
paths.add(key);
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
normalizeAppNavigation({ items: manifest.navigation ?? [] });
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
throw new Error(`Invalid navigation in "${id}".`);
|
|
39
|
+
}
|
|
40
|
+
for (const [dependency, generation] of Object.entries({ ...manifest.requires, ...manifest.optional })) {
|
|
41
|
+
if (!/^[a-z][a-z0-9_]{0,39}$/.test(dependency) || reserved.includes(dependency) || dependency === id || !Number.isSafeInteger(generation) || generation < 1)
|
|
42
|
+
throw new Error(`Invalid dependency "${dependency}" in "${id}".`);
|
|
43
|
+
if (manifest.requires?.[dependency] !== undefined && manifest.optional?.[dependency] !== undefined)
|
|
44
|
+
throw new Error(`Dependency "${dependency}" is both required and optional in "${id}".`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const visiting = new Set();
|
|
48
|
+
const ordered = new Set();
|
|
49
|
+
/** Topologically orders available dependencies and rejects composition cycles. */
|
|
50
|
+
function visit(id) {
|
|
51
|
+
if (ordered.has(id))
|
|
52
|
+
return;
|
|
53
|
+
if (visiting.has(id))
|
|
54
|
+
throw new Error(`App dependency cycle at "${id}".`);
|
|
55
|
+
visiting.add(id);
|
|
56
|
+
for (const dependency of Object.keys({ ...definitions[id].manifest.requires, ...definitions[id].manifest.optional })) {
|
|
57
|
+
if (definitions[dependency])
|
|
58
|
+
visit(dependency);
|
|
59
|
+
}
|
|
60
|
+
visiting.delete(id);
|
|
61
|
+
ordered.add(id);
|
|
62
|
+
}
|
|
63
|
+
ids.forEach(visit);
|
|
64
|
+
return [...ordered];
|
|
65
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { appsPlugin } from './appsPlugin.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { appsPlugin } from './appsPlugin.js';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { mkdir, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { dirname, join, relative } from 'node:path';
|
|
3
|
+
import { discoverApps } from './discoverApps.js';
|
|
4
|
+
/** Regenerates optional app().social types from discovery during development and builds, without loading server code. */
|
|
5
|
+
export async function writeAppTypes(directory) {
|
|
6
|
+
const target = join(directory, '.db3/apps.d.ts');
|
|
7
|
+
const properties = discoverApps(directory).map(app => {
|
|
8
|
+
const specifier = app.packageName ?? `./${relative(dirname(target), app.entry).replaceAll('\\', '/').replace(/\.ts$/, '.js')}`;
|
|
9
|
+
return `\t\treadonly ${app.manifest.id}?: InstanceType<typeof import(${JSON.stringify(specifier)}).default>;`;
|
|
10
|
+
});
|
|
11
|
+
await mkdir(dirname(target), { recursive: true });
|
|
12
|
+
await writeFile(target, `// Generated by DB3 app discovery. Do not edit.\nimport '@db3.ai/app/apps/contracts';\ndeclare module '@db3.ai/app/apps/contracts' {\n\tinterface InstalledApps {\n${properties.join('\n')}\n\t}\n}\n`);
|
|
13
|
+
}
|
package/dist/auth/Auth.d.ts
CHANGED
|
@@ -246,6 +246,7 @@ export declare const AUTH_USER_CONTEXT_KEY = "auth.user";
|
|
|
246
246
|
* Authentication service for the current app/request scope.
|
|
247
247
|
*/
|
|
248
248
|
export declare class Auth<TIdentity extends UserIdentity = UserIdentity> {
|
|
249
|
+
#private;
|
|
249
250
|
private fallbackAuthenticatedUser;
|
|
250
251
|
private fallbackAuthenticatedToken;
|
|
251
252
|
private readonly db;
|
|
@@ -404,6 +405,8 @@ export declare class Auth<TIdentity extends UserIdentity = UserIdentity> {
|
|
|
404
405
|
setPasswordProvider(user: TIdentity, password: string): Promise<AuthProvider>;
|
|
405
406
|
/**
|
|
406
407
|
* Changes a user's password provider after verifying the current password.
|
|
408
|
+
* Password replacement, recovery-link invalidation and revocation of every
|
|
409
|
+
* bearer session (including the current session) commit together.
|
|
407
410
|
*
|
|
408
411
|
* @param user - User whose password should change.
|
|
409
412
|
* @param currentPassword - Current plaintext password for verification.
|
|
@@ -432,6 +435,8 @@ export declare class Auth<TIdentity extends UserIdentity = UserIdentity> {
|
|
|
432
435
|
createPasswordResetToken(user: TIdentity, options?: PasswordResetTokenOptions): Promise<IssuedPasswordResetToken<TIdentity>>;
|
|
433
436
|
/**
|
|
434
437
|
* Resets the password provider using a valid password reset token.
|
|
438
|
+
* Serializes recovery for an account and atomically invalidates every existing
|
|
439
|
+
* session and recovery link. Failed validation leaves credentials unchanged.
|
|
435
440
|
*
|
|
436
441
|
* @param input - Reset token, new password, and optional identity value.
|
|
437
442
|
* @returns Identity whose password changed, or null when redemption fails.
|
|
@@ -460,6 +465,19 @@ export declare class Auth<TIdentity extends UserIdentity = UserIdentity> {
|
|
|
460
465
|
* @returns Active, non-expired sessions ordered newest first.
|
|
461
466
|
*/
|
|
462
467
|
tokensFor(user: TIdentity): Promise<AuthToken[]>;
|
|
468
|
+
/**
|
|
469
|
+
* Revokes all bearer sessions for an account, including the current device.
|
|
470
|
+
*
|
|
471
|
+
* Apps must authorize the supplied account before calling this method. Tokens
|
|
472
|
+
* are rejected on subsequent requests; already-running requests can finish.
|
|
473
|
+
* Revoked rows are retained for audit. New sign-ins remain possible.
|
|
474
|
+
*
|
|
475
|
+
* @param user - Authorized account whose sessions should end.
|
|
476
|
+
* @returns Number of previously unrevoked token rows changed, including expired rows.
|
|
477
|
+
* @example
|
|
478
|
+
* await app.auth.revokeAllTokens(authenticatedUser);
|
|
479
|
+
*/
|
|
480
|
+
revokeAllTokens(user: TIdentity): Promise<number>;
|
|
463
481
|
/**
|
|
464
482
|
* Revokes one bearer session owned by a user.
|
|
465
483
|
*
|
package/dist/auth/Auth.js
CHANGED
|
@@ -334,6 +334,8 @@ export class Auth {
|
|
|
334
334
|
}
|
|
335
335
|
/**
|
|
336
336
|
* Changes a user's password provider after verifying the current password.
|
|
337
|
+
* Password replacement, recovery-link invalidation and revocation of every
|
|
338
|
+
* bearer session (including the current session) commit together.
|
|
337
339
|
*
|
|
338
340
|
* @param user - User whose password should change.
|
|
339
341
|
* @param currentPassword - Current plaintext password for verification.
|
|
@@ -341,9 +343,21 @@ export class Auth {
|
|
|
341
343
|
* @returns True when the password was changed.
|
|
342
344
|
*/
|
|
343
345
|
async changePasswordProvider(user, currentPassword, nextPassword) {
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
346
|
+
const userId = this.userPrimaryKey(user);
|
|
347
|
+
if (!userId)
|
|
348
|
+
return false;
|
|
349
|
+
const changed = await this.db.knex.transaction(transaction => ActiveRecord.withDb(transaction, async () => {
|
|
350
|
+
const lockedUser = await this.#lockIdentity(userId, transaction);
|
|
351
|
+
if (!lockedUser)
|
|
352
|
+
return false;
|
|
353
|
+
if (!await this.passwordProvider().changePassword(lockedUser, currentPassword, nextPassword))
|
|
354
|
+
return false;
|
|
355
|
+
await this.#invalidatePasswordRecovery(userId, transaction);
|
|
356
|
+
return true;
|
|
357
|
+
}));
|
|
358
|
+
if (changed)
|
|
359
|
+
this.#forgetRevokedUser(userId);
|
|
360
|
+
return changed;
|
|
347
361
|
}
|
|
348
362
|
/**
|
|
349
363
|
* Authenticates through a non-password provider and stores the user on success.
|
|
@@ -417,6 +431,8 @@ export class Auth {
|
|
|
417
431
|
}
|
|
418
432
|
/**
|
|
419
433
|
* Resets the password provider using a valid password reset token.
|
|
434
|
+
* Serializes recovery for an account and atomically invalidates every existing
|
|
435
|
+
* session and recovery link. Failed validation leaves credentials unchanged.
|
|
420
436
|
*
|
|
421
437
|
* @param input - Reset token, new password, and optional identity value.
|
|
422
438
|
* @returns Identity whose password changed, or null when redemption fails.
|
|
@@ -433,18 +449,55 @@ export class Auth {
|
|
|
433
449
|
if (!tokenRecord || !tokenRecord.isUsable()) {
|
|
434
450
|
return null;
|
|
435
451
|
}
|
|
436
|
-
|
|
437
|
-
if (!user) {
|
|
438
|
-
return null;
|
|
439
|
-
}
|
|
440
|
-
if (!await this.passwordResetIdentityMatches(input, user)) {
|
|
452
|
+
if (!tokenRecord.userId)
|
|
441
453
|
return null;
|
|
454
|
+
const user = await this.db.knex.transaction(transaction => ActiveRecord.withDb(transaction, async () => {
|
|
455
|
+
const lockedUser = await this.#lockIdentity(tokenRecord.userId, transaction);
|
|
456
|
+
if (!lockedUser)
|
|
457
|
+
return null;
|
|
458
|
+
// A locking read sees a competing redemption's committed state after
|
|
459
|
+
// waiting for the account lock, including under repeatable-read SQL.
|
|
460
|
+
const row = await this.PasswordResetTokenModel.query(transaction)
|
|
461
|
+
.where('id', tokenRecord.id).toKnex().forUpdate().first();
|
|
462
|
+
const current = row ? this.PasswordResetTokenModel.fromDb(row, transaction) : null;
|
|
463
|
+
if (!current?.isUsable() || !await this.passwordResetIdentityMatches(input, lockedUser))
|
|
464
|
+
return null;
|
|
465
|
+
await this.passwordProvider().recoverPassword(lockedUser, input.password);
|
|
466
|
+
await this.#invalidatePasswordRecovery(tokenRecord.userId, transaction);
|
|
467
|
+
return lockedUser;
|
|
468
|
+
}));
|
|
469
|
+
if (user) {
|
|
470
|
+
user.setDb(this.db.knex);
|
|
471
|
+
this.#forgetRevokedUser(this.userPrimaryKey(user));
|
|
442
472
|
}
|
|
443
|
-
await this.setPasswordProvider(user, input.password);
|
|
444
|
-
tokenRecord.markUsed();
|
|
445
|
-
await tokenRecord.save();
|
|
446
473
|
return user;
|
|
447
474
|
}
|
|
475
|
+
/** Locks the account row to serialize concurrent password replacements. */
|
|
476
|
+
async #lockIdentity(userId, transaction) {
|
|
477
|
+
const row = await this.IdentityModel.query(transaction)
|
|
478
|
+
.where(this.IdentityModel.primaryKey, userId).toKnex().forUpdate().first();
|
|
479
|
+
return row ? this.IdentityModel.fromDb(row, transaction) : null;
|
|
480
|
+
}
|
|
481
|
+
/** Invalidates recovery links and sessions within the password transaction. */
|
|
482
|
+
async #invalidatePasswordRecovery(userId, transaction) {
|
|
483
|
+
await this.PasswordResetTokenModel.query(transaction)
|
|
484
|
+
.where('userId', userId).whereNull('usedAt').patch({ usedAt: new Date() });
|
|
485
|
+
await this.#revokeTokens(userId, transaction);
|
|
486
|
+
}
|
|
487
|
+
/** Applies session revocation on the owning connection or password transaction. */
|
|
488
|
+
async #revokeTokens(userId, connection) {
|
|
489
|
+
return this.TokenModel.query(connection)
|
|
490
|
+
.where('userId', userId).whereNull('revokedAt').patch({ revokedAt: new Date() });
|
|
491
|
+
}
|
|
492
|
+
/** Discards cached bearer authentication after committed account revocation. */
|
|
493
|
+
#forgetRevokedUser(userId) {
|
|
494
|
+
if (this.requestContext?.active) {
|
|
495
|
+
const key = `${AUTH_TOKEN_CONTEXT_KEY_PREFIX}.${this.TokenModel.table}.revision`;
|
|
496
|
+
this.requestContext.set(key, (this.requestContext.get(key) ?? 0) + 1);
|
|
497
|
+
}
|
|
498
|
+
if (this.user && this.userPrimaryKey(this.user) === userId)
|
|
499
|
+
this.logout();
|
|
500
|
+
}
|
|
448
501
|
/**
|
|
449
502
|
* Creates a bearer token for an already-authenticated identity.
|
|
450
503
|
*
|
|
@@ -521,6 +574,26 @@ export class Auth {
|
|
|
521
574
|
.all();
|
|
522
575
|
return tokens.filter(token => token.isActive());
|
|
523
576
|
}
|
|
577
|
+
/**
|
|
578
|
+
* Revokes all bearer sessions for an account, including the current device.
|
|
579
|
+
*
|
|
580
|
+
* Apps must authorize the supplied account before calling this method. Tokens
|
|
581
|
+
* are rejected on subsequent requests; already-running requests can finish.
|
|
582
|
+
* Revoked rows are retained for audit. New sign-ins remain possible.
|
|
583
|
+
*
|
|
584
|
+
* @param user - Authorized account whose sessions should end.
|
|
585
|
+
* @returns Number of previously unrevoked token rows changed, including expired rows.
|
|
586
|
+
* @example
|
|
587
|
+
* await app.auth.revokeAllTokens(authenticatedUser);
|
|
588
|
+
*/
|
|
589
|
+
async revokeAllTokens(user) {
|
|
590
|
+
const userId = this.userPrimaryKey(user);
|
|
591
|
+
if (!userId)
|
|
592
|
+
return 0;
|
|
593
|
+
const count = await this.#revokeTokens(userId, this.db.knex);
|
|
594
|
+
this.#forgetRevokedUser(userId);
|
|
595
|
+
return count;
|
|
596
|
+
}
|
|
524
597
|
/**
|
|
525
598
|
* Revokes one bearer session owned by a user.
|
|
526
599
|
*
|
|
@@ -564,7 +637,9 @@ export class Auth {
|
|
|
564
637
|
* @returns Request-context cache key.
|
|
565
638
|
*/
|
|
566
639
|
tokenContextKey(tokenHash) {
|
|
567
|
-
|
|
640
|
+
const prefix = `${AUTH_TOKEN_CONTEXT_KEY_PREFIX}.${this.TokenModel.table}`;
|
|
641
|
+
const revision = this.requestContext?.get(`${prefix}.revision`) ?? 0;
|
|
642
|
+
return `${prefix}.${revision}.${tokenHash}`;
|
|
568
643
|
}
|
|
569
644
|
/**
|
|
570
645
|
* Authenticates a pre-hashed bearer token against persistent auth records.
|
|
@@ -838,7 +913,8 @@ export class Auth {
|
|
|
838
913
|
if (inputIdentity === undefined || inputIdentity === null || inputIdentity === '') {
|
|
839
914
|
return true;
|
|
840
915
|
}
|
|
841
|
-
const inputUser = await this.
|
|
916
|
+
const inputUser = await this.IdentityModel.query()
|
|
917
|
+
.where(identityField, inputIdentity).first();
|
|
842
918
|
return inputUser?.get(this.IdentityModel.primaryKey) === user.get(this.IdentityModel.primaryKey);
|
|
843
919
|
}
|
|
844
920
|
/**
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { ActiveRecord, type FieldBuilder } from '../db/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Durable failed-password state for any submitted identity, known or unknown.
|
|
4
|
+
*
|
|
5
|
+
* The unique normalized identity digest provides a database-wide serialization
|
|
6
|
+
* point without requiring an account. The normalized submitted email is also
|
|
7
|
+
* retained so operators can investigate attempts against known or unknown users.
|
|
8
|
+
* This table is intentionally independent of users and authentication providers.
|
|
9
|
+
*/
|
|
10
|
+
export declare class PasswordLoginAttempt extends ActiveRecord {
|
|
11
|
+
static table: string;
|
|
12
|
+
/** Defines the identity key, failure counter and persistent suspension. */
|
|
13
|
+
static fields(field: FieldBuilder): {
|
|
14
|
+
id: import("../db/index.js").UlidField;
|
|
15
|
+
identityHash: import("../db/index.js").StringField;
|
|
16
|
+
identity: import("../db/index.js").StringField;
|
|
17
|
+
failedAttempts: import("../db/index.js").IntegerField;
|
|
18
|
+
suspendedAt: import("../db/index.js").TimestampField;
|
|
19
|
+
suspensionId: import("../db/index.js").StringField;
|
|
20
|
+
createdAt: import("../db/index.js").TimestampField;
|
|
21
|
+
updatedAt: import("../db/index.js").TimestampField;
|
|
22
|
+
};
|
|
23
|
+
id: string | null;
|
|
24
|
+
identityHash: string;
|
|
25
|
+
/** Readable submitted identity, populated on the next attempt for legacy rows. */
|
|
26
|
+
identity: string | null;
|
|
27
|
+
failedAttempts: number;
|
|
28
|
+
suspendedAt: Date | null;
|
|
29
|
+
/** Unique occurrence identifier, cleared only by verified password recovery. */
|
|
30
|
+
suspensionId: string | null;
|
|
31
|
+
/**
|
|
32
|
+
* Derives an exact stable key unaffected by the database's email collation.
|
|
33
|
+
* @param identity - Submitted email or configured password identity.
|
|
34
|
+
* @returns SHA-256 of the trimmed, lowercase identity.
|
|
35
|
+
*/
|
|
36
|
+
static identityKey(identity: string): string;
|
|
37
|
+
/**
|
|
38
|
+
* Serializes one verification or recovery with every operation for this identity.
|
|
39
|
+
*
|
|
40
|
+
* The unique-key upsert handles concurrent first attempts. Locking reads see
|
|
41
|
+
* the latest committed state, including under repeatable-read isolation.
|
|
42
|
+
* Nested use during recovery participates through a transaction savepoint.
|
|
43
|
+
*
|
|
44
|
+
* Records the normalized identity and latest activity even when already suspended.
|
|
45
|
+
* @param identity - Password identity, whether or not registered.
|
|
46
|
+
* @param callback - Operation that may update and save the locked attempt row.
|
|
47
|
+
* @returns Callback result after its state commits.
|
|
48
|
+
*/
|
|
49
|
+
static withIdentityLock<TResult>(identity: string, callback: (attempt: PasswordLoginAttempt) => Promise<TResult>): Promise<TResult>;
|
|
50
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { ActiveRecord } from '../db/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Durable failed-password state for any submitted identity, known or unknown.
|
|
5
|
+
*
|
|
6
|
+
* The unique normalized identity digest provides a database-wide serialization
|
|
7
|
+
* point without requiring an account. The normalized submitted email is also
|
|
8
|
+
* retained so operators can investigate attempts against known or unknown users.
|
|
9
|
+
* This table is intentionally independent of users and authentication providers.
|
|
10
|
+
*/
|
|
11
|
+
export class PasswordLoginAttempt extends ActiveRecord {
|
|
12
|
+
static table = 'auth_password_login_attempts';
|
|
13
|
+
/** Defines the identity key, failure counter and persistent suspension. */
|
|
14
|
+
static fields(field) {
|
|
15
|
+
return {
|
|
16
|
+
id: field.ulid(),
|
|
17
|
+
identityHash: field.string({ column: 'identity_hash', required: true, unique: true, length: 64, maxLength: 64, comment: 'SHA-256 of the normalized submitted identity; not tied to account existence.' }),
|
|
18
|
+
identity: field.string({ length: 255, maxLength: 255, comment: 'Normalized submitted email or configured identity; null for legacy digest-only rows until their next attempt.' }),
|
|
19
|
+
failedAttempts: field.integer({ column: 'failed_attempts', required: true, unsigned: true, min: 0, default: 0, comment: 'Consecutive wrong passwords for this identity.' }),
|
|
20
|
+
suspendedAt: field.timestamp({ column: 'suspended_at', comment: 'When password recovery became required; no automatic expiry.' }),
|
|
21
|
+
suspensionId: field.string({ column: 'suspension_id', length: 36, maxLength: 36, comment: 'Unique suspension occurrence; prevents delayed recovery notices from referring to a later suspension.' }),
|
|
22
|
+
createdAt: field.timestamp({ column: 'created_at', auto: 'create' }),
|
|
23
|
+
updatedAt: field.timestamp({ column: 'updated_at', auto: 'both', index: true, comment: 'Latest password sign-in or recovery activity, including refused suspended attempts.' }),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Derives an exact stable key unaffected by the database's email collation.
|
|
28
|
+
* @param identity - Submitted email or configured password identity.
|
|
29
|
+
* @returns SHA-256 of the trimmed, lowercase identity.
|
|
30
|
+
*/
|
|
31
|
+
static identityKey(identity) {
|
|
32
|
+
return createHash('sha256').update(identity.trim().toLowerCase()).digest('hex');
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Serializes one verification or recovery with every operation for this identity.
|
|
36
|
+
*
|
|
37
|
+
* The unique-key upsert handles concurrent first attempts. Locking reads see
|
|
38
|
+
* the latest committed state, including under repeatable-read isolation.
|
|
39
|
+
* Nested use during recovery participates through a transaction savepoint.
|
|
40
|
+
*
|
|
41
|
+
* Records the normalized identity and latest activity even when already suspended.
|
|
42
|
+
* @param identity - Password identity, whether or not registered.
|
|
43
|
+
* @param callback - Operation that may update and save the locked attempt row.
|
|
44
|
+
* @returns Callback result after its state commits.
|
|
45
|
+
*/
|
|
46
|
+
static async withIdentityLock(identity, callback) {
|
|
47
|
+
return this.getDb().transaction(transaction => ActiveRecord.withDb(transaction, async () => {
|
|
48
|
+
const identityHash = this.identityKey(identity);
|
|
49
|
+
const candidate = this.create({ identityHash, identity: identity.trim().toLowerCase() });
|
|
50
|
+
// Framework-level upsert requires Knex; the fields still own every value
|
|
51
|
+
// and column conversion. Updating activity takes an exclusive key lock;
|
|
52
|
+
// INSERT IGNORE would take shared locks and can deadlock on FOR UPDATE.
|
|
53
|
+
await transaction(this.table).insert(await candidate.getDataForDb()).onConflict(this.getFields().identityHash.column).merge([this.getFields().identity.column, this.getFields().updatedAt.column]);
|
|
54
|
+
const attempt = await this.where('identityHash', identityHash).forUpdate().first();
|
|
55
|
+
if (!attempt)
|
|
56
|
+
throw new Error('Unable to lock password login state.');
|
|
57
|
+
return callback(attempt);
|
|
58
|
+
}));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { PasswordSuspension } from './contracts/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Password sign-in for the submitted identity requires email recovery.
|
|
4
|
+
* The same error is used for existing and unknown emails, with no account data.
|
|
5
|
+
*/
|
|
6
|
+
export declare class PasswordSuspendedError extends Error {
|
|
7
|
+
readonly suspension: PasswordSuspension | null;
|
|
8
|
+
/** Creates a generic refusal, optionally carrying a newly committed transition for server use. */
|
|
9
|
+
constructor(suspension?: PasswordSuspension | null);
|
|
10
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Password sign-in for the submitted identity requires email recovery.
|
|
3
|
+
* The same error is used for existing and unknown emails, with no account data.
|
|
4
|
+
*/
|
|
5
|
+
export class PasswordSuspendedError extends Error {
|
|
6
|
+
suspension;
|
|
7
|
+
/** Creates a generic refusal, optionally carrying a newly committed transition for server use. */
|
|
8
|
+
constructor(suspension = null) {
|
|
9
|
+
super('Too many sign-in attempts. Use password recovery to continue.');
|
|
10
|
+
this.suspension = suspension;
|
|
11
|
+
this.name = 'PasswordSuspendedError';
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { AuthProvider } from '../AuthProvider.js';
|
|
2
|
+
import type { UserIdentity, UserIdentityModel } from '../UserIdentity.js';
|
|
3
|
+
import type { PasswordHash } from '../passwordHash.js';
|
|
4
|
+
import type { PasswordSuspensionOptions } from './PasswordSuspensionOptions.js';
|
|
5
|
+
/**
|
|
6
|
+
* Construction options for the password auth provider.
|
|
7
|
+
*/
|
|
8
|
+
export interface PasswordAuthProviderOptions<TIdentity extends UserIdentity = UserIdentity> {
|
|
9
|
+
/**
|
|
10
|
+
* User identity model configured for the host app.
|
|
11
|
+
*/
|
|
12
|
+
identityModel: UserIdentityModel<TIdentity>;
|
|
13
|
+
/**
|
|
14
|
+
* Provider-link model configured for the auth service.
|
|
15
|
+
*/
|
|
16
|
+
providerModel?: typeof AuthProvider;
|
|
17
|
+
/**
|
|
18
|
+
* Password hashing service used to verify stored hashes.
|
|
19
|
+
*/
|
|
20
|
+
passwordHash?: PasswordHash;
|
|
21
|
+
/**
|
|
22
|
+
* Failed-password suspension by normalized identity, including unknown identities.
|
|
23
|
+
* Enabled after 20 attempts by default; `false` disables it.
|
|
24
|
+
*/
|
|
25
|
+
suspension?: PasswordSuspensionOptions | false;
|
|
26
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Identifies a newly committed suspension so an application can enqueue recovery notices. */
|
|
2
|
+
export interface PasswordSuspension {
|
|
3
|
+
/** Attempt-state record, equally available for registered and unknown identities. */
|
|
4
|
+
attemptId: string;
|
|
5
|
+
/** Unique suspension occurrence; changes after recovery and a later suspension. */
|
|
6
|
+
suspensionId: string;
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Persistent suspension policy for submitted password identities.
|
|
3
|
+
*
|
|
4
|
+
* Known and unknown emails share the same threshold. Only completed password
|
|
5
|
+
* recovery clears suspension; this policy deliberately has no timed unlock.
|
|
6
|
+
*/
|
|
7
|
+
export interface PasswordSuspensionOptions {
|
|
8
|
+
/** Consecutive failures before recovery is required. Defaults to 20. */
|
|
9
|
+
maxFailedAttempts?: number;
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/auth/index.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ export * from './Auth.js';
|
|
|
2
2
|
export * from './AuthProvider.js';
|
|
3
3
|
export * from './AuthToken.js';
|
|
4
4
|
export * from './contracts/index.js';
|
|
5
|
+
export * from './PasswordSuspendedError.js';
|
|
6
|
+
export * from './PasswordLoginAttempt.js';
|
|
5
7
|
export * from './PasswordResetToken.js';
|
|
6
8
|
export * from './passwordHash.js';
|
|
7
9
|
export * from './providers/index.js';
|
package/dist/auth/index.js
CHANGED
|
@@ -2,6 +2,8 @@ export * from './Auth.js';
|
|
|
2
2
|
export * from './AuthProvider.js';
|
|
3
3
|
export * from './AuthToken.js';
|
|
4
4
|
export * from './contracts/index.js';
|
|
5
|
+
export * from './PasswordSuspendedError.js';
|
|
6
|
+
export * from './PasswordLoginAttempt.js';
|
|
5
7
|
export * from './PasswordResetToken.js';
|
|
6
8
|
export * from './passwordHash.js';
|
|
7
9
|
export * from './providers/index.js';
|
|
@@ -1,25 +1,7 @@
|
|
|
1
1
|
import { AuthProvider } from '../AuthProvider.js';
|
|
2
2
|
import type * as auth from '../contracts/index.js';
|
|
3
3
|
import type { PasswordCredentials } from '../Auth.js';
|
|
4
|
-
import type { UserIdentity
|
|
5
|
-
import { type PasswordHash } from '../passwordHash.js';
|
|
6
|
-
/**
|
|
7
|
-
* Construction options for the password auth provider.
|
|
8
|
-
*/
|
|
9
|
-
export interface PasswordAuthProviderOptions<TIdentity extends UserIdentity = UserIdentity> {
|
|
10
|
-
/**
|
|
11
|
-
* User identity model configured for the host app.
|
|
12
|
-
*/
|
|
13
|
-
identityModel: UserIdentityModel<TIdentity>;
|
|
14
|
-
/**
|
|
15
|
-
* Provider-link model configured for the auth service.
|
|
16
|
-
*/
|
|
17
|
-
providerModel?: typeof AuthProvider;
|
|
18
|
-
/**
|
|
19
|
-
* Password hashing service used to verify stored hashes.
|
|
20
|
-
*/
|
|
21
|
-
passwordHash?: PasswordHash;
|
|
22
|
-
}
|
|
4
|
+
import type { UserIdentity } from '../UserIdentity.js';
|
|
23
5
|
/**
|
|
24
6
|
* Provider driver for first-party email and password authentication.
|
|
25
7
|
*
|
|
@@ -28,6 +10,7 @@ export interface PasswordAuthProviderOptions<TIdentity extends UserIdentity = Us
|
|
|
28
10
|
* plus a valid password hash stored on `auth_providers`.
|
|
29
11
|
*/
|
|
30
12
|
export declare class PasswordAuthProvider<TIdentity extends UserIdentity = UserIdentity> implements auth.AuthProviderDriver<PasswordCredentials, TIdentity> {
|
|
13
|
+
#private;
|
|
31
14
|
readonly provider = "password";
|
|
32
15
|
private readonly IdentityModel;
|
|
33
16
|
private readonly ProviderModel;
|
|
@@ -37,14 +20,27 @@ export declare class PasswordAuthProvider<TIdentity extends UserIdentity = UserI
|
|
|
37
20
|
*
|
|
38
21
|
* @param options - Password provider dependencies configured at app startup.
|
|
39
22
|
*/
|
|
40
|
-
constructor(options: PasswordAuthProviderOptions<TIdentity>);
|
|
23
|
+
constructor(options: auth.PasswordAuthProviderOptions<TIdentity>);
|
|
41
24
|
/**
|
|
42
|
-
* Verifies
|
|
25
|
+
* Verifies credentials under the identity's durable attempt lock.
|
|
43
26
|
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
27
|
+
* Unknown identities receive the same failed-attempt accounting and password
|
|
28
|
+
* hashing work as existing accounts. Suspension persists until verified
|
|
29
|
+
* password recovery; a correct password cannot clear a suspended identity.
|
|
30
|
+
*
|
|
31
|
+
* @param input - Submitted password credentials.
|
|
32
|
+
* @returns Verified provider profile, or null for an invalid password.
|
|
33
|
+
* @throws {PasswordSuspendedError} When this identity needs password recovery.
|
|
46
34
|
*/
|
|
47
35
|
verify(input: PasswordCredentials): Promise<auth.AuthProviderProfile | null>;
|
|
36
|
+
/**
|
|
37
|
+
* Replaces a verified owner's password and clears suspension atomically.
|
|
38
|
+
* Called by Auth only after a usable, identity-matched recovery token is locked.
|
|
39
|
+
* @param user - Account whose email recovery proof was verified.
|
|
40
|
+
* @param password - Replacement plaintext password.
|
|
41
|
+
* @returns Saved password provider.
|
|
42
|
+
*/
|
|
43
|
+
recoverPassword(user: TIdentity, password: string): Promise<AuthProvider>;
|
|
48
44
|
/**
|
|
49
45
|
* Creates or replaces the password provider for a user.
|
|
50
46
|
*
|