@zintrust/core 0.1.0 → 0.1.2
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 +214 -0
- package/bin/zintrust.d.ts.map +1 -1
- package/bin/zintrust.js +18 -1
- package/package.json +4 -34
- package/public/index.html +535 -0
- package/src/boot/Application.d.ts.map +1 -1
- package/src/boot/Application.js +46 -3
- package/src/boot/Server.d.ts.map +1 -1
- package/src/boot/Server.js +3 -4
- package/src/boot/bootstrap.js +77 -6
- package/src/builder/BundleOptimizer.d.ts.map +1 -1
- package/src/builder/BundleOptimizer.js +25 -29
- package/src/cache/Cache.d.ts.map +1 -1
- package/src/cache/Cache.js +4 -2
- package/src/cache/drivers/KVDriver.d.ts.map +1 -1
- package/src/cache/drivers/KVDriver.js +8 -7
- package/src/cache/drivers/MemoryDriver.d.ts.map +1 -1
- package/src/cache/drivers/MemoryDriver.js +5 -0
- package/src/cache/drivers/RedisDriver.js +1 -1
- package/src/cli/BaseCommand.d.ts +2 -2
- package/src/cli/BaseCommand.d.ts.map +1 -1
- package/src/cli/BaseCommand.js +2 -1
- package/src/cli/CLI.d.ts.map +1 -1
- package/src/cli/CLI.js +22 -18
- package/src/cli/ErrorHandler.d.ts.map +1 -1
- package/src/cli/ErrorHandler.js +2 -4
- package/src/cli/commands/AddCommand.d.ts +81 -0
- package/src/cli/commands/AddCommand.d.ts.map +1 -1
- package/src/cli/commands/AddCommand.js +24 -5
- package/src/cli/commands/ConfigCommand.d.ts.map +1 -1
- package/src/cli/commands/ConfigCommand.js +59 -25
- package/src/cli/commands/D1MigrateCommand.d.ts +4 -0
- package/src/cli/commands/D1MigrateCommand.d.ts.map +1 -1
- package/src/cli/commands/D1MigrateCommand.js +6 -4
- package/src/cli/commands/FixCommand.d.ts.map +1 -1
- package/src/cli/commands/FixCommand.js +3 -15
- package/src/cli/commands/LogsCleanupCommand.d.ts +6 -0
- package/src/cli/commands/LogsCleanupCommand.d.ts.map +1 -0
- package/src/cli/commands/LogsCleanupCommand.js +20 -0
- package/src/cli/commands/LogsCommand.d.ts.map +1 -1
- package/src/cli/commands/LogsCommand.js +4 -6
- package/src/cli/commands/MakeMailTemplateCommand.d.ts +10 -0
- package/src/cli/commands/MakeMailTemplateCommand.d.ts.map +1 -0
- package/src/cli/commands/MakeMailTemplateCommand.js +74 -0
- package/src/cli/commands/MakeNotificationTemplateCommand.d.ts +10 -0
- package/src/cli/commands/MakeNotificationTemplateCommand.d.ts.map +1 -0
- package/src/cli/commands/MakeNotificationTemplateCommand.js +113 -0
- package/src/cli/commands/MigrateCommand.d.ts.map +1 -1
- package/src/cli/commands/MigrateCommand.js +3 -3
- package/src/cli/commands/NewCommand.d.ts +4 -0
- package/src/cli/commands/NewCommand.d.ts.map +1 -1
- package/src/cli/commands/NewCommand.js +34 -19
- package/src/cli/commands/PluginCommand.d.ts.map +1 -1
- package/src/cli/commands/PluginCommand.js +8 -4
- package/src/cli/commands/PrepareCommand.d.ts.map +1 -1
- package/src/cli/commands/PrepareCommand.js +1 -1
- package/src/cli/commands/QACommand.d.ts.map +1 -1
- package/src/cli/commands/QACommand.js +16 -26
- package/src/cli/commands/SecretsCommand.d.ts +16 -0
- package/src/cli/commands/SecretsCommand.d.ts.map +1 -0
- package/src/cli/commands/SecretsCommand.js +91 -0
- package/src/cli/commands/StartCommand.d.ts.map +1 -1
- package/src/cli/commands/StartCommand.js +2 -2
- package/src/cli/commands/TemplatesCommand.d.ts +3 -0
- package/src/cli/commands/TemplatesCommand.d.ts.map +1 -0
- package/src/cli/commands/TemplatesCommand.js +65 -0
- package/src/cli/commands/index.d.ts +5 -0
- package/src/cli/commands/index.d.ts.map +1 -1
- package/src/cli/commands/index.js +5 -0
- package/src/cli/config/ConfigManager.js +1 -1
- package/src/cli/index.d.ts +2 -1
- package/src/cli/index.d.ts.map +1 -1
- package/src/cli/index.js +2 -1
- package/src/cli/scaffolding/ControllerGenerator.d.ts.map +1 -1
- package/src/cli/scaffolding/ControllerGenerator.js +11 -10
- package/src/cli/scaffolding/FeatureScaffolder.js +4 -4
- package/src/cli/scaffolding/FileGenerator.js +1 -1
- package/src/cli/scaffolding/MigrationGenerator.d.ts.map +1 -1
- package/src/cli/scaffolding/MigrationGenerator.js +10 -9
- package/src/cli/scaffolding/ModelGenerator.d.ts.map +1 -1
- package/src/cli/scaffolding/ModelGenerator.js +11 -10
- package/src/cli/scaffolding/ProjectScaffolder.d.ts.map +1 -1
- package/src/cli/scaffolding/ProjectScaffolder.js +61 -11
- package/src/cli/scaffolding/ResponseFactoryGenerator.d.ts.map +1 -1
- package/src/cli/scaffolding/ResponseFactoryGenerator.js +2 -1
- package/src/cli/scaffolding/RouteGenerator.d.ts.map +1 -1
- package/src/cli/scaffolding/RouteGenerator.js +15 -14
- package/src/cli/scaffolding/SeederGenerator.js +1 -1
- package/src/cli/scaffolding/ServiceIntegrationTestGenerator.d.ts.map +1 -1
- package/src/cli/scaffolding/ServiceIntegrationTestGenerator.js +7 -6
- package/src/cli/scaffolding/ServiceRequestFactoryGenerator.d.ts +1 -1
- package/src/cli/scaffolding/ServiceRequestFactoryGenerator.d.ts.map +1 -1
- package/src/cli/scaffolding/ServiceRequestFactoryGenerator.js +2 -2
- package/src/cli/scaffolding/ServiceScaffolder.d.ts.map +1 -1
- package/src/cli/scaffolding/ServiceScaffolder.js +13 -12
- package/src/cli/scaffolding/TemplateEngine.d.ts +10 -3
- package/src/cli/scaffolding/TemplateEngine.d.ts.map +1 -1
- package/src/cli/scaffolding/TemplateEngine.js +15 -285
- package/src/cli/scaffolding/TemplateGenerator.d.ts +40 -0
- package/src/cli/scaffolding/TemplateGenerator.d.ts.map +1 -0
- package/src/cli/scaffolding/TemplateGenerator.js +172 -0
- package/src/cli/scaffolding/index.d.ts +1 -0
- package/src/cli/scaffolding/index.d.ts.map +1 -1
- package/src/cli/scaffolding/index.js +1 -0
- package/src/cli/utils/spawn.js +1 -1
- package/src/common/AwsSigV4.d.ts +41 -0
- package/src/common/AwsSigV4.d.ts.map +1 -0
- package/src/common/AwsSigV4.js +69 -0
- package/src/common/index.d.ts +39 -0
- package/src/common/index.d.ts.map +1 -1
- package/src/common/index.js +101 -8
- package/src/common/uuid.d.ts +3 -0
- package/src/common/uuid.d.ts.map +1 -0
- package/src/common/uuid.js +30 -0
- package/src/config/FileLogWriter.d.ts +22 -0
- package/src/config/FileLogWriter.d.ts.map +1 -0
- package/src/config/FileLogWriter.js +192 -0
- package/src/config/SecretsManager.d.ts.map +1 -1
- package/src/config/SecretsManager.js +26 -0
- package/src/config/StartupConfigValidator.d.ts +15 -0
- package/src/config/StartupConfigValidator.d.ts.map +1 -0
- package/src/config/StartupConfigValidator.js +86 -0
- package/src/config/app.d.ts +2 -1
- package/src/config/app.d.ts.map +1 -1
- package/src/config/app.js +65 -15
- package/src/config/broadcast.d.ts +47 -0
- package/src/config/broadcast.d.ts.map +1 -0
- package/src/config/broadcast.js +54 -0
- package/src/config/cache.d.ts +13 -17
- package/src/config/cache.d.ts.map +1 -1
- package/src/config/cache.js +9 -11
- package/src/config/cloudflare.d.ts +26 -0
- package/src/config/cloudflare.d.ts.map +1 -0
- package/src/config/cloudflare.js +38 -0
- package/src/config/env.d.ts +6 -0
- package/src/config/env.d.ts.map +1 -1
- package/src/config/env.js +6 -0
- package/src/config/index.d.ts +52 -28
- package/src/config/index.d.ts.map +1 -1
- package/src/config/index.js +3 -0
- package/src/config/logger.d.ts +2 -0
- package/src/config/logger.d.ts.map +1 -1
- package/src/config/logger.js +270 -11
- package/src/config/logging/HttpLogger.d.ts +23 -0
- package/src/config/logging/HttpLogger.d.ts.map +1 -0
- package/src/config/logging/HttpLogger.js +93 -0
- package/src/config/logging/KvLogger.d.ts +22 -0
- package/src/config/logging/KvLogger.d.ts.map +1 -0
- package/src/config/logging/KvLogger.js +143 -0
- package/src/config/logging/SlackLogger.d.ts +23 -0
- package/src/config/logging/SlackLogger.d.ts.map +1 -0
- package/src/config/logging/SlackLogger.js +119 -0
- package/src/config/mail.d.ts +81 -0
- package/src/config/mail.d.ts.map +1 -0
- package/src/config/mail.js +73 -0
- package/src/config/middleware.d.ts +8 -0
- package/src/config/middleware.d.ts.map +1 -0
- package/src/config/middleware.js +18 -0
- package/src/config/notification.d.ts +62 -0
- package/src/config/notification.d.ts.map +1 -0
- package/src/config/notification.js +43 -0
- package/src/config/security.d.ts.map +1 -1
- package/src/config/security.js +2 -2
- package/src/config/startup.d.ts +23 -0
- package/src/config/startup.d.ts.map +1 -0
- package/src/config/startup.js +15 -0
- package/src/config/storage.d.ts +21 -35
- package/src/config/storage.d.ts.map +1 -1
- package/src/config/storage.js +57 -37
- package/src/database/migrations/index.d.ts +1 -1
- package/src/database/migrations/index.d.ts.map +1 -1
- package/src/database/migrations/index.js +2 -1
- package/src/features/Queue.js +1 -25
- package/src/functions/lambda.d.ts.map +1 -1
- package/src/functions/lambda.js +6 -1
- package/src/health/RuntimeHealthProbes.d.ts +13 -0
- package/src/health/RuntimeHealthProbes.d.ts.map +1 -0
- package/src/health/RuntimeHealthProbes.js +62 -0
- package/src/health/StartupHealthChecks.d.ts +26 -0
- package/src/health/StartupHealthChecks.d.ts.map +1 -0
- package/src/health/StartupHealthChecks.js +124 -0
- package/src/http/ErrorResponse.d.ts +28 -0
- package/src/http/ErrorResponse.d.ts.map +1 -0
- package/src/http/ErrorResponse.js +42 -0
- package/src/http/Kernel.d.ts +5 -0
- package/src/http/Kernel.d.ts.map +1 -1
- package/src/http/Kernel.js +96 -30
- package/src/http/Request.d.ts +1 -1
- package/src/http/Request.d.ts.map +1 -1
- package/src/http/RequestContext.d.ts +20 -0
- package/src/http/RequestContext.d.ts.map +1 -0
- package/src/http/RequestContext.js +77 -0
- package/src/index.d.ts +9 -1
- package/src/index.d.ts.map +1 -1
- package/src/index.js +8 -2
- package/src/microservices/MicroserviceBootstrap.d.ts.map +1 -1
- package/src/microservices/MicroserviceBootstrap.js +6 -5
- package/src/microservices/MicroserviceManager.d.ts.map +1 -1
- package/src/microservices/MicroserviceManager.js +7 -5
- package/src/microservices/PostgresAdapter.d.ts.map +1 -1
- package/src/microservices/PostgresAdapter.js +7 -4
- package/src/microservices/ServiceBundler.d.ts.map +1 -1
- package/src/microservices/ServiceBundler.js +3 -1
- package/src/microservices/ServiceHealthMonitor.d.ts.map +1 -1
- package/src/microservices/ServiceHealthMonitor.js +7 -3
- package/src/middleware/CsrfMiddleware.d.ts.map +1 -1
- package/src/middleware/CsrfMiddleware.js +2 -19
- package/src/middleware/ErrorHandlerMiddleware.d.ts +6 -0
- package/src/middleware/ErrorHandlerMiddleware.d.ts.map +1 -0
- package/src/middleware/ErrorHandlerMiddleware.js +33 -0
- package/src/middleware/LoggingMiddleware.d.ts +9 -0
- package/src/middleware/LoggingMiddleware.d.ts.map +1 -0
- package/src/middleware/LoggingMiddleware.js +36 -0
- package/src/middleware/index.d.ts +2 -0
- package/src/middleware/index.d.ts.map +1 -1
- package/src/middleware/index.js +2 -0
- package/src/node-singletons/async_hooks.d.ts +9 -0
- package/src/node-singletons/async_hooks.d.ts.map +1 -0
- package/src/node-singletons/async_hooks.js +8 -0
- package/src/node-singletons/fs.d.ts +2 -2
- package/src/node-singletons/fs.d.ts.map +1 -1
- package/src/node-singletons/fs.js +2 -2
- package/src/node-singletons/http.d.ts +1 -1
- package/src/node-singletons/http.d.ts.map +1 -1
- package/src/node-singletons/http.js +1 -1
- package/src/node-singletons/index.d.ts +4 -0
- package/src/node-singletons/index.d.ts.map +1 -1
- package/src/node-singletons/index.js +4 -0
- package/src/node-singletons/net.d.ts +9 -0
- package/src/node-singletons/net.d.ts.map +1 -0
- package/src/node-singletons/net.js +8 -0
- package/src/node-singletons/os.d.ts +3 -3
- package/src/node-singletons/os.d.ts.map +1 -1
- package/src/node-singletons/os.js +3 -4
- package/src/node-singletons/path.d.ts +3 -1
- package/src/node-singletons/path.d.ts.map +1 -1
- package/src/node-singletons/path.js +3 -1
- package/src/node-singletons/perf-hooks.d.ts +3 -1
- package/src/node-singletons/perf-hooks.d.ts.map +1 -1
- package/src/node-singletons/perf-hooks.js +3 -1
- package/src/node-singletons/process.d.ts +23 -0
- package/src/node-singletons/process.d.ts.map +1 -0
- package/src/node-singletons/process.js +8 -0
- package/src/node-singletons/readline.d.ts +3 -3
- package/src/node-singletons/readline.d.ts.map +1 -1
- package/src/node-singletons/readline.js +3 -4
- package/src/node-singletons/tls.d.ts +9 -0
- package/src/node-singletons/tls.d.ts.map +1 -0
- package/src/node-singletons/tls.js +8 -0
- package/src/node-singletons/url.d.ts +3 -1
- package/src/node-singletons/url.d.ts.map +1 -1
- package/src/node-singletons/url.js +3 -1
- package/src/orm/ConnectionManager.d.ts +6 -1
- package/src/orm/ConnectionManager.d.ts.map +1 -1
- package/src/orm/ConnectionManager.js +14 -0
- package/src/orm/DatabaseAdapter.d.ts +6 -0
- package/src/orm/DatabaseAdapter.d.ts.map +1 -1
- package/src/orm/QueryBuilder.d.ts +8 -1
- package/src/orm/QueryBuilder.d.ts.map +1 -1
- package/src/orm/QueryBuilder.js +188 -28
- package/src/orm/adapters/D1Adapter.d.ts.map +1 -1
- package/src/orm/adapters/D1Adapter.js +18 -12
- package/src/orm/adapters/MySQLAdapter.d.ts.map +1 -1
- package/src/orm/adapters/MySQLAdapter.js +4 -0
- package/src/orm/adapters/PostgreSQLAdapter.d.ts.map +1 -1
- package/src/orm/adapters/PostgreSQLAdapter.js +4 -0
- package/src/orm/adapters/SQLServerAdapter.d.ts.map +1 -1
- package/src/orm/adapters/SQLServerAdapter.js +4 -0
- package/src/orm/adapters/SQLiteAdapter.d.ts.map +1 -1
- package/src/orm/adapters/SQLiteAdapter.js +4 -0
- package/src/performance/Benchmark.d.ts.map +1 -1
- package/src/performance/Benchmark.js +3 -0
- package/src/performance/CodeGenerationBenchmark.js +3 -3
- package/src/performance/Optimizer.d.ts +1 -1
- package/src/performance/Optimizer.d.ts.map +1 -1
- package/src/performance/Optimizer.js +157 -80
- package/src/performance/establish-baseline.js +3 -3
- package/src/runtime/PluginManager.d.ts +3 -1
- package/src/runtime/PluginManager.d.ts.map +1 -1
- package/src/runtime/PluginManager.js +124 -28
- package/src/runtime/RuntimeDetector.d.ts.map +1 -1
- package/src/runtime/RuntimeDetector.js +47 -5
- package/src/runtime/adapters/CloudflareAdapter.js +2 -2
- package/src/runtime/adapters/DenoAdapter.js +9 -7
- package/src/runtime/adapters/FargateAdapter.d.ts.map +1 -1
- package/src/runtime/adapters/FargateAdapter.js +4 -3
- package/src/runtime/adapters/LambdaAdapter.d.ts.map +1 -1
- package/src/runtime/adapters/LambdaAdapter.js +4 -2
- package/src/runtime/adapters/NodeServerAdapter.d.ts.map +1 -1
- package/src/runtime/adapters/NodeServerAdapter.js +7 -6
- package/src/scheduler/ScheduleRunner.d.ts +18 -0
- package/src/scheduler/ScheduleRunner.d.ts.map +1 -0
- package/src/scheduler/ScheduleRunner.js +155 -0
- package/src/scheduler/index.d.ts +3 -0
- package/src/scheduler/index.d.ts.map +1 -0
- package/src/scheduler/index.js +1 -0
- package/src/scheduler/types.d.ts +16 -0
- package/src/scheduler/types.d.ts.map +1 -0
- package/src/scheduler/types.js +4 -0
- package/src/schedules/index.d.ts +2 -0
- package/src/schedules/index.d.ts.map +1 -0
- package/src/schedules/index.js +1 -0
- package/src/schedules/log-cleanup.d.ts +4 -0
- package/src/schedules/log-cleanup.d.ts.map +1 -0
- package/src/schedules/log-cleanup.js +18 -0
- package/src/scripts/GenerateEnvArtifacts.d.ts +13 -0
- package/src/scripts/GenerateEnvArtifacts.d.ts.map +1 -0
- package/src/scripts/GenerateEnvArtifacts.js +171 -0
- package/src/scripts/TemplateSync.js +109 -70
- package/src/security/CsrfTokenManager.js +1 -1
- package/src/security/Encryptor.js +1 -1
- package/src/security/Hash.d.ts +14 -0
- package/src/security/Hash.d.ts.map +1 -0
- package/src/security/Hash.js +81 -0
- package/src/security/StartupSecretValidation.d.ts +20 -0
- package/src/security/StartupSecretValidation.d.ts.map +1 -0
- package/src/security/StartupSecretValidation.js +61 -0
- package/src/security/UrlValidator.d.ts +0 -1
- package/src/security/UrlValidator.d.ts.map +1 -1
- package/src/security/UrlValidator.js +1 -2
- package/src/security/Xss.d.ts +14 -0
- package/src/security/Xss.d.ts.map +1 -0
- package/src/security/Xss.js +57 -0
- package/src/security/XssProtection.d.ts.map +1 -1
- package/src/security/XssProtection.js +150 -16
- package/src/templates/adapters/MySQLAdapter.ts.tpl +5 -0
- package/src/templates/adapters/PostgreSQLAdapter.ts.tpl +5 -0
- package/src/templates/adapters/SQLServerAdapter.ts.tpl +5 -0
- package/src/templates/adapters/SQLiteAdapter.ts.tpl +5 -0
- package/src/templates/features/Queue.ts.tpl +1 -29
- package/src/templates/project/basic/.env.example.tpl +48 -0
- package/src/templates/project/basic/.env.tpl +89 -94
- package/src/templates/project/basic/app/Toolkit/Broadcast/sendBroadcast.ts.tpl +7 -0
- package/src/templates/project/basic/app/Toolkit/Mail/sendWelcomeEmail.ts.tpl +30 -0
- package/src/templates/project/basic/app/Toolkit/Notification/sendSlackNotification.ts.tpl +10 -0
- package/src/templates/project/basic/app/Toolkit/Notification/sendSms.ts.tpl +13 -0
- package/src/templates/project/basic/config/FileLogWriter.ts.tpl +240 -0
- package/src/templates/project/basic/config/SecretsManager.ts.tpl +32 -1
- package/src/templates/project/basic/config/StartupConfigValidator.ts.tpl +151 -0
- package/src/templates/project/basic/config/app.ts.tpl +84 -15
- package/src/templates/project/basic/config/broadcast.ts.tpl +97 -0
- package/src/templates/project/basic/config/cache.ts.tpl +19 -23
- package/src/templates/project/basic/config/cloudflare.ts.tpl +57 -0
- package/src/templates/project/basic/config/env.ts.tpl +7 -1
- package/src/templates/project/basic/config/index.ts.tpl +3 -0
- package/src/templates/project/basic/config/logger.ts.tpl +301 -11
- package/src/templates/project/basic/config/logging/HttpLogger.ts.tpl +121 -0
- package/src/templates/project/basic/config/logging/KvLogger.ts.tpl +181 -0
- package/src/templates/project/basic/config/logging/SlackLogger.ts.tpl +156 -0
- package/src/templates/project/basic/config/mail.ts.tpl +141 -0
- package/src/templates/project/basic/config/middleware.ts.tpl +27 -0
- package/src/templates/project/basic/config/notification.ts.tpl +86 -0
- package/src/templates/project/basic/config/security.ts.tpl +4 -5
- package/src/templates/project/basic/config/startup.ts.tpl +27 -0
- package/src/templates/project/basic/config/storage.ts.tpl +77 -42
- package/src/templates/project/basic/database/migrations/index.ts.tpl +1 -1
- package/src/templates/project/basic/package.json.tpl +1 -1
- package/src/templates/project/basic/routes/api.ts.tpl +9 -37
- package/src/templates/project/basic/routes/broadcast.ts.tpl +32 -0
- package/src/templates/project/basic/routes/health.ts.tpl +134 -0
- package/src/templates/project/basic/src/index.ts.tpl +38 -11
- package/src/templates/project/basic/template.json +3 -0
- package/src/toolkit/Secrets/EnvFile.d.ts +15 -0
- package/src/toolkit/Secrets/EnvFile.d.ts.map +1 -0
- package/src/toolkit/Secrets/EnvFile.js +63 -0
- package/src/toolkit/Secrets/Manifest.d.ts +24 -0
- package/src/toolkit/Secrets/Manifest.d.ts.map +1 -0
- package/src/toolkit/Secrets/Manifest.js +71 -0
- package/src/toolkit/Secrets/index.d.ts +42 -0
- package/src/toolkit/Secrets/index.d.ts.map +1 -0
- package/src/toolkit/Secrets/index.js +119 -0
- package/src/toolkit/Secrets/providers/AwsSecretsManager.d.ts +14 -0
- package/src/toolkit/Secrets/providers/AwsSecretsManager.d.ts.map +1 -0
- package/src/toolkit/Secrets/providers/AwsSecretsManager.js +131 -0
- package/src/toolkit/Secrets/providers/CloudflareKv.d.ts +9 -0
- package/src/toolkit/Secrets/providers/CloudflareKv.d.ts.map +1 -0
- package/src/toolkit/Secrets/providers/CloudflareKv.js +73 -0
- package/src/tools/broadcast/Broadcast.d.ts +7 -0
- package/src/tools/broadcast/Broadcast.d.ts.map +1 -0
- package/src/tools/broadcast/Broadcast.js +37 -0
- package/src/tools/broadcast/drivers/BaseDriver.d.ts +5 -0
- package/src/tools/broadcast/drivers/BaseDriver.d.ts.map +1 -0
- package/src/tools/broadcast/drivers/BaseDriver.js +8 -0
- package/src/tools/broadcast/drivers/InMemory.d.ts +18 -0
- package/src/tools/broadcast/drivers/InMemory.d.ts.map +1 -0
- package/src/tools/broadcast/drivers/InMemory.js +16 -0
- package/src/tools/broadcast/drivers/Pusher.d.ts +8 -0
- package/src/tools/broadcast/drivers/Pusher.d.ts.map +1 -0
- package/src/tools/broadcast/drivers/Pusher.js +75 -0
- package/src/tools/broadcast/drivers/Redis.d.ts +19 -0
- package/src/tools/broadcast/drivers/Redis.d.ts.map +1 -0
- package/src/tools/broadcast/drivers/Redis.js +73 -0
- package/src/tools/broadcast/drivers/RedisHttps.d.ts +14 -0
- package/src/tools/broadcast/drivers/RedisHttps.d.ts.map +1 -0
- package/src/tools/broadcast/drivers/RedisHttps.js +50 -0
- package/src/tools/broadcast/index.d.ts +7 -0
- package/src/tools/broadcast/index.d.ts.map +1 -0
- package/src/tools/broadcast/index.js +6 -0
- package/src/tools/http/Http.d.ts +51 -0
- package/src/tools/http/Http.d.ts.map +1 -0
- package/src/tools/http/Http.js +171 -0
- package/src/tools/http/HttpResponse.d.ts +32 -0
- package/src/tools/http/HttpResponse.d.ts.map +1 -0
- package/src/tools/http/HttpResponse.js +80 -0
- package/src/tools/http/index.d.ts +15 -0
- package/src/tools/http/index.d.ts.map +1 -0
- package/src/tools/http/index.js +9 -0
- package/src/tools/mail/Mail.d.ts +22 -0
- package/src/tools/mail/Mail.d.ts.map +1 -0
- package/src/tools/mail/Mail.js +105 -0
- package/src/tools/mail/attachments.d.ts +23 -0
- package/src/tools/mail/attachments.d.ts.map +1 -0
- package/src/tools/mail/attachments.js +26 -0
- package/src/tools/mail/drivers/BaseDriver.d.ts +5 -0
- package/src/tools/mail/drivers/BaseDriver.d.ts.map +1 -0
- package/src/tools/mail/drivers/BaseDriver.js +8 -0
- package/src/tools/mail/drivers/Mailgun.d.ts +31 -0
- package/src/tools/mail/drivers/Mailgun.d.ts.map +1 -0
- package/src/tools/mail/drivers/Mailgun.js +81 -0
- package/src/tools/mail/drivers/SendGrid.d.ts +29 -0
- package/src/tools/mail/drivers/SendGrid.d.ts.map +1 -0
- package/src/tools/mail/drivers/SendGrid.js +57 -0
- package/src/tools/mail/drivers/Ses.d.ts +24 -0
- package/src/tools/mail/drivers/Ses.d.ts.map +1 -0
- package/src/tools/mail/drivers/Ses.js +116 -0
- package/src/tools/mail/drivers/Smtp.d.ts +38 -0
- package/src/tools/mail/drivers/Smtp.d.ts.map +1 -0
- package/src/tools/mail/drivers/Smtp.js +327 -0
- package/src/tools/mail/templates/index.d.ts +27 -0
- package/src/tools/mail/templates/index.d.ts.map +1 -0
- package/src/tools/mail/templates/index.js +35 -0
- package/src/tools/mail/templates/markdown/index.d.ts +17 -0
- package/src/tools/mail/templates/markdown/index.d.ts.map +1 -0
- package/src/tools/mail/templates/markdown/index.js +49 -0
- package/src/tools/mail/templates/markdown/registry.d.ts +15 -0
- package/src/tools/mail/templates/markdown/registry.d.ts.map +1 -0
- package/src/tools/mail/templates/markdown/registry.js +34 -0
- package/src/tools/mail/templates/markdown/validator.d.ts +16 -0
- package/src/tools/mail/templates/markdown/validator.d.ts.map +1 -0
- package/src/tools/mail/templates/markdown/validator.js +24 -0
- package/src/tools/mail/testing.d.ts +41 -0
- package/src/tools/mail/testing.d.ts.map +1 -0
- package/src/tools/mail/testing.js +34 -0
- package/src/tools/notification/Driver.d.ts +11 -0
- package/src/tools/notification/Driver.d.ts.map +1 -0
- package/src/tools/notification/Driver.js +1 -0
- package/src/tools/notification/Notification.d.ts +11 -0
- package/src/tools/notification/Notification.d.ts.map +1 -0
- package/src/tools/notification/Notification.js +11 -0
- package/src/tools/notification/Registry.d.ts +10 -0
- package/src/tools/notification/Registry.d.ts.map +1 -0
- package/src/tools/notification/Registry.js +22 -0
- package/src/tools/notification/Service.d.ts +6 -0
- package/src/tools/notification/Service.d.ts.map +1 -0
- package/src/tools/notification/Service.js +18 -0
- package/src/tools/notification/config.d.ts +5 -0
- package/src/tools/notification/config.d.ts.map +1 -0
- package/src/tools/notification/config.js +5 -0
- package/src/tools/notification/drivers/BaseDriver.d.ts +5 -0
- package/src/tools/notification/drivers/BaseDriver.d.ts.map +1 -0
- package/src/tools/notification/drivers/BaseDriver.js +8 -0
- package/src/tools/notification/drivers/Console.d.ts +7 -0
- package/src/tools/notification/drivers/Console.d.ts.map +1 -0
- package/src/tools/notification/drivers/Console.js +13 -0
- package/src/tools/notification/drivers/Slack.d.ts +16 -0
- package/src/tools/notification/drivers/Slack.d.ts.map +1 -0
- package/src/tools/notification/drivers/Slack.js +24 -0
- package/src/tools/notification/drivers/Termii.d.ts +10 -0
- package/src/tools/notification/drivers/Termii.d.ts.map +1 -0
- package/src/tools/notification/drivers/Termii.js +47 -0
- package/src/tools/notification/drivers/Twilio.d.ts +21 -0
- package/src/tools/notification/drivers/Twilio.d.ts.map +1 -0
- package/src/tools/notification/drivers/Twilio.js +48 -0
- package/src/tools/notification/templates/markdown/index.d.ts +15 -0
- package/src/tools/notification/templates/markdown/index.d.ts.map +1 -0
- package/src/tools/notification/templates/markdown/index.js +38 -0
- package/src/tools/notification/templates/markdown/registry.d.ts +15 -0
- package/src/tools/notification/templates/markdown/registry.d.ts.map +1 -0
- package/src/tools/notification/templates/markdown/registry.js +36 -0
- package/src/tools/notification/testing.d.ts +19 -0
- package/src/tools/notification/testing.d.ts.map +1 -0
- package/src/tools/notification/testing.js +35 -0
- package/src/tools/notification/testingHelpers.d.ts +12 -0
- package/src/tools/notification/testingHelpers.d.ts.map +1 -0
- package/src/tools/notification/testingHelpers.js +32 -0
- package/src/tools/queue/Queue.d.ts +23 -0
- package/src/tools/queue/Queue.d.ts.map +1 -0
- package/src/tools/queue/Queue.js +38 -0
- package/src/tools/queue/drivers/InMemory.d.ts +10 -0
- package/src/tools/queue/drivers/InMemory.d.ts.map +1 -0
- package/src/tools/queue/drivers/InMemory.js +55 -0
- package/src/tools/queue/drivers/Redis.d.ts +10 -0
- package/src/tools/queue/drivers/Redis.d.ts.map +1 -0
- package/src/tools/queue/drivers/Redis.js +91 -0
- package/src/tools/storage/drivers/Gcs.d.ts +20 -0
- package/src/tools/storage/drivers/Gcs.d.ts.map +1 -0
- package/src/tools/storage/drivers/Gcs.js +152 -0
- package/src/tools/storage/drivers/Local.d.ts +17 -0
- package/src/tools/storage/drivers/Local.d.ts.map +1 -0
- package/src/tools/storage/drivers/Local.js +63 -0
- package/src/tools/storage/drivers/R2.d.ts +20 -0
- package/src/tools/storage/drivers/R2.d.ts.map +1 -0
- package/src/tools/storage/drivers/R2.js +73 -0
- package/src/tools/storage/drivers/S3.d.ts +26 -0
- package/src/tools/storage/drivers/S3.d.ts.map +1 -0
- package/src/tools/storage/drivers/S3.js +258 -0
- package/src/tools/storage/index.d.ts +24 -0
- package/src/tools/storage/index.d.ts.map +1 -0
- package/src/tools/storage/index.js +112 -0
- package/src/tools/storage/testing.d.ts +23 -0
- package/src/tools/storage/testing.d.ts.map +1 -0
- package/src/tools/storage/testing.js +52 -0
- package/src/tools/templates/MarkdownRenderer.d.ts +14 -0
- package/src/tools/templates/MarkdownRenderer.d.ts.map +1 -0
- package/src/tools/templates/MarkdownRenderer.js +300 -0
- package/src/tools/templates/index.d.ts +5 -0
- package/src/tools/templates/index.d.ts.map +1 -0
- package/src/tools/templates/index.js +4 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP Endpoint Logger
|
|
3
|
+
* Sends logs to an external HTTP logging service.
|
|
4
|
+
*
|
|
5
|
+
* Enabled via env:
|
|
6
|
+
* - HTTP_LOG_ENABLED (default: false)
|
|
7
|
+
* - HTTP_LOG_ENDPOINT_URL
|
|
8
|
+
* - HTTP_LOG_BATCH_SIZE (default: 50)
|
|
9
|
+
* - HTTP_LOG_AUTH_TOKEN (optional)
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { delay } from '@common/index';
|
|
13
|
+
import { Env } from '@config/env';
|
|
14
|
+
import { ErrorFactory } from '@exceptions/ZintrustError';
|
|
15
|
+
import { HttpClient } from '@httpClient/Http';
|
|
16
|
+
|
|
17
|
+
export type HttpLogEvent = {
|
|
18
|
+
timestamp: string;
|
|
19
|
+
level: 'debug' | 'info' | 'warn' | 'error' | 'fatal';
|
|
20
|
+
message: string;
|
|
21
|
+
category?: string;
|
|
22
|
+
data?: unknown;
|
|
23
|
+
error?: string;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const isEnabled = (): boolean => Env.getBool('HTTP_LOG_ENABLED', false);
|
|
27
|
+
|
|
28
|
+
let buffer: HttpLogEvent[] = [];
|
|
29
|
+
let flushPromise: Promise<void> | undefined;
|
|
30
|
+
|
|
31
|
+
const postBatch = async (events: HttpLogEvent[]): Promise<void> => {
|
|
32
|
+
const endpoint = Env.get('HTTP_LOG_ENDPOINT_URL').trim();
|
|
33
|
+
if (endpoint.length === 0) {
|
|
34
|
+
throw ErrorFactory.createConfigError(
|
|
35
|
+
'HTTP_LOG_ENDPOINT_URL is required when HTTP logging is enabled'
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const token = Env.get('HTTP_LOG_AUTH_TOKEN').trim();
|
|
40
|
+
|
|
41
|
+
const builder = HttpClient.post(endpoint, {
|
|
42
|
+
sentAt: new Date().toISOString(),
|
|
43
|
+
count: events.length,
|
|
44
|
+
events,
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
if (token.length > 0) {
|
|
48
|
+
builder.withAuth(token, 'Bearer');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
await builder.send();
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const flushNow = async (): Promise<void> => {
|
|
55
|
+
const toSend = buffer;
|
|
56
|
+
buffer = [];
|
|
57
|
+
|
|
58
|
+
if (!isEnabled()) return;
|
|
59
|
+
if (toSend.length === 0) return;
|
|
60
|
+
|
|
61
|
+
const maxRetries = 3;
|
|
62
|
+
|
|
63
|
+
const attemptPost = async (attempt: number): Promise<void> => {
|
|
64
|
+
try {
|
|
65
|
+
await postBatch(toSend);
|
|
66
|
+
} catch {
|
|
67
|
+
if (attempt >= maxRetries) return;
|
|
68
|
+
const backoffMs = 100 * 2 ** attempt;
|
|
69
|
+
await delay(backoffMs);
|
|
70
|
+
await attemptPost(attempt + 1);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
await attemptPost(0);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const scheduleFlush = async (): Promise<void> => {
|
|
78
|
+
if (flushPromise !== undefined) return flushPromise;
|
|
79
|
+
|
|
80
|
+
const promise = new Promise<void>((resolve) => {
|
|
81
|
+
const run = async (): Promise<void> => {
|
|
82
|
+
try {
|
|
83
|
+
await flushNow();
|
|
84
|
+
} finally {
|
|
85
|
+
resolve(undefined);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
if (typeof globalThis.setTimeout !== 'function') {
|
|
90
|
+
void run();
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
globalThis.setTimeout(() => {
|
|
95
|
+
void run();
|
|
96
|
+
}, 0);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
flushPromise = promise.finally(() => {
|
|
100
|
+
flushPromise = undefined;
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
return flushPromise;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export const HttpLogger = Object.freeze({
|
|
107
|
+
async enqueue(event: HttpLogEvent): Promise<void> {
|
|
108
|
+
if (!isEnabled()) return Promise.resolve(); // NOSONAR
|
|
109
|
+
|
|
110
|
+
buffer.push(event);
|
|
111
|
+
|
|
112
|
+
const batchSize = Math.max(1, Env.getInt('HTTP_LOG_BATCH_SIZE', 50));
|
|
113
|
+
if (buffer.length >= batchSize) {
|
|
114
|
+
return scheduleFlush();
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return scheduleFlush();
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
export default HttpLogger;
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* KV Logger
|
|
3
|
+
* Writes batches of log events to a KV namespace (Cloudflare Workers compatible)
|
|
4
|
+
*
|
|
5
|
+
* Enabled via env:
|
|
6
|
+
* - KV_LOG_ENABLED (default: false)
|
|
7
|
+
* - KV_NAMESPACE (binding name; default: 'CACHE')
|
|
8
|
+
* - KV_LOG_RETENTION_DAYS (default: 30)
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { Cloudflare } from '@config/cloudflare';
|
|
12
|
+
import { Env } from '@config/env';
|
|
13
|
+
|
|
14
|
+
export type KvLogEvent = {
|
|
15
|
+
timestamp: string;
|
|
16
|
+
level: 'debug' | 'info' | 'warn' | 'error' | 'fatal';
|
|
17
|
+
message: string;
|
|
18
|
+
category?: string;
|
|
19
|
+
data?: unknown;
|
|
20
|
+
error?: string;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
type KVNamespace = NonNullable<ReturnType<typeof Cloudflare.getKVBinding>>;
|
|
24
|
+
|
|
25
|
+
type PutOptions = { expiration?: number; expirationTtl?: number; metadata?: unknown };
|
|
26
|
+
|
|
27
|
+
const getRetentionTtlSeconds = (): number => {
|
|
28
|
+
const days = Env.getInt('KV_LOG_RETENTION_DAYS', 30);
|
|
29
|
+
const safeDays = Number.isFinite(days) && days > 0 ? days : 30;
|
|
30
|
+
return safeDays * 24 * 60 * 60;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const getKvBindingName = (): string => {
|
|
34
|
+
const name = Env.get('KV_NAMESPACE', 'CACHE').trim();
|
|
35
|
+
return name.length > 0 ? name : 'CACHE';
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const isEnabled = (): boolean => Env.getBool('KV_LOG_ENABLED', false);
|
|
39
|
+
|
|
40
|
+
const safeRandom = (): string => {
|
|
41
|
+
try {
|
|
42
|
+
// Prefer crypto if available
|
|
43
|
+
const cryptoObj = (globalThis as unknown as { crypto?: Crypto }).crypto;
|
|
44
|
+
if (cryptoObj?.getRandomValues) {
|
|
45
|
+
const bytes = new Uint8Array(8);
|
|
46
|
+
cryptoObj.getRandomValues(bytes);
|
|
47
|
+
return Array.from(bytes)
|
|
48
|
+
.map((b) => b.toString(16).padStart(2, '0'))
|
|
49
|
+
.join('');
|
|
50
|
+
}
|
|
51
|
+
} catch {
|
|
52
|
+
// fall through
|
|
53
|
+
}
|
|
54
|
+
const generate = Math.random().toString(16).slice(2); // NOSONAR
|
|
55
|
+
const fallback = generate + Math.random().toString(16).slice(2); // NOSONAR this is not used for security
|
|
56
|
+
return fallback;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const buildKey = (timestampIso: string): string => {
|
|
60
|
+
const date = timestampIso.slice(0, 10);
|
|
61
|
+
const hour = timestampIso.slice(11, 13);
|
|
62
|
+
return `logs:${date}:${hour}:${safeRandom()}`;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
let buffer: KvLogEvent[] = [];
|
|
66
|
+
let flushTimer: ReturnType<typeof setTimeout> | undefined;
|
|
67
|
+
let flushPromise: Promise<void> | undefined;
|
|
68
|
+
|
|
69
|
+
const scheduleFlush = async (): Promise<void> => {
|
|
70
|
+
if (flushPromise !== undefined) return flushPromise;
|
|
71
|
+
|
|
72
|
+
// Fixed small batching window to reduce KV write volume.
|
|
73
|
+
const windowMs = 1000;
|
|
74
|
+
|
|
75
|
+
const promise = new Promise<void>((resolve) => {
|
|
76
|
+
const run = async (): Promise<void> => {
|
|
77
|
+
try {
|
|
78
|
+
await flushNow();
|
|
79
|
+
} finally {
|
|
80
|
+
resolve(undefined);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
if (typeof globalThis.setTimeout !== 'function') {
|
|
85
|
+
// microtask-ish
|
|
86
|
+
void run();
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
flushTimer = globalThis.setTimeout(() => {
|
|
91
|
+
flushTimer = undefined;
|
|
92
|
+
void run();
|
|
93
|
+
}, windowMs);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
flushPromise = promise.finally(() => {
|
|
97
|
+
flushPromise = undefined;
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
return flushPromise;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const getKv = (): KVNamespace | null => {
|
|
104
|
+
const bindingName = getKvBindingName();
|
|
105
|
+
return Cloudflare.getKVBinding(bindingName);
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const putBatch = async (kv: KVNamespace, events: KvLogEvent[]): Promise<void> => {
|
|
109
|
+
if (events.length === 0) return;
|
|
110
|
+
|
|
111
|
+
const timestamp = events.at(-1)?.timestamp ?? new Date().toISOString();
|
|
112
|
+
const key = buildKey(timestamp);
|
|
113
|
+
|
|
114
|
+
const payload = JSON.stringify({
|
|
115
|
+
version: 1,
|
|
116
|
+
createdAt: new Date().toISOString(),
|
|
117
|
+
count: events.length,
|
|
118
|
+
events,
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
const opts: PutOptions = { expirationTtl: getRetentionTtlSeconds() };
|
|
122
|
+
|
|
123
|
+
await kv.put(key, payload, opts);
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const flushNow = async (): Promise<void> => {
|
|
127
|
+
if (!isEnabled()) {
|
|
128
|
+
buffer = [];
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const kv = getKv();
|
|
133
|
+
if (kv === null) {
|
|
134
|
+
buffer = [];
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const toSend = buffer;
|
|
139
|
+
buffer = [];
|
|
140
|
+
|
|
141
|
+
try {
|
|
142
|
+
await putBatch(kv, toSend);
|
|
143
|
+
} catch {
|
|
144
|
+
// Best-effort: never throw from logging.
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
const flushSoon = async (): Promise<void> => {
|
|
149
|
+
if (flushPromise !== undefined) return flushPromise;
|
|
150
|
+
|
|
151
|
+
flushPromise = Promise.resolve()
|
|
152
|
+
.then(async () => flushNow())
|
|
153
|
+
.finally(() => {
|
|
154
|
+
flushPromise = undefined;
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
return flushPromise;
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
export const KvLogger = Object.freeze({
|
|
161
|
+
async enqueue(event: KvLogEvent): Promise<void> {
|
|
162
|
+
if (!isEnabled()) return Promise.resolve();
|
|
163
|
+
|
|
164
|
+
buffer.push(event);
|
|
165
|
+
|
|
166
|
+
// Basic size guard: flush if it gets too large
|
|
167
|
+
const maxBatch = 100;
|
|
168
|
+
if (buffer.length >= maxBatch) {
|
|
169
|
+
// Cancel scheduled flush and flush immediately
|
|
170
|
+
if (flushTimer !== undefined) {
|
|
171
|
+
globalThis.clearTimeout(flushTimer);
|
|
172
|
+
flushTimer = undefined;
|
|
173
|
+
}
|
|
174
|
+
return flushSoon();
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return scheduleFlush();
|
|
178
|
+
},
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
export default KvLogger;
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Slack Notification Logger
|
|
3
|
+
* Sends warn/error/fatal log events to a Slack incoming webhook.
|
|
4
|
+
*
|
|
5
|
+
* Enabled via env:
|
|
6
|
+
* - SLACK_LOG_ENABLED (default: false)
|
|
7
|
+
* - SLACK_LOG_WEBHOOK_URL
|
|
8
|
+
* - SLACK_LOG_LEVELS (comma-separated; default: "warn,error,fatal")
|
|
9
|
+
* - SLACK_LOG_BATCH_WINDOW_MS (default: 5000)
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { Env } from '@config/env';
|
|
13
|
+
import { ErrorFactory } from '@exceptions/ZintrustError';
|
|
14
|
+
import { HttpClient } from '@httpClient/Http';
|
|
15
|
+
|
|
16
|
+
export type SlackLogEvent = {
|
|
17
|
+
timestamp: string;
|
|
18
|
+
level: 'debug' | 'info' | 'warn' | 'error' | 'fatal';
|
|
19
|
+
message: string;
|
|
20
|
+
category?: string;
|
|
21
|
+
data?: unknown;
|
|
22
|
+
error?: string;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
type SlackPayload = {
|
|
26
|
+
text?: string;
|
|
27
|
+
attachments?: Array<{ color?: string; text: string }>;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const isEnabled = (): boolean => Env.getBool('SLACK_LOG_ENABLED', false);
|
|
31
|
+
|
|
32
|
+
const getLevels = (): Set<string> => {
|
|
33
|
+
const raw = Env.get('SLACK_LOG_LEVELS', 'warn,error,fatal');
|
|
34
|
+
return new Set(
|
|
35
|
+
raw
|
|
36
|
+
.split(',')
|
|
37
|
+
.map((s) => s.trim().toLowerCase())
|
|
38
|
+
.filter((s) => s.length > 0)
|
|
39
|
+
);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const levelToColor = (level: SlackLogEvent['level']): string => {
|
|
43
|
+
if (level === 'fatal' || level === 'error') return '#D50200';
|
|
44
|
+
if (level === 'warn') return '#D39E00';
|
|
45
|
+
return '#439FE0';
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const formatEventText = (ev: SlackLogEvent): string => {
|
|
49
|
+
const header = `*${ev.level.toUpperCase()}* ${ev.message}`;
|
|
50
|
+
const metaParts: string[] = [];
|
|
51
|
+
if (ev.category !== undefined) metaParts.push(`category=${ev.category}`);
|
|
52
|
+
metaParts.push(`ts=${ev.timestamp}`);
|
|
53
|
+
|
|
54
|
+
const meta = metaParts.length > 0 ? `\n_${metaParts.join(' ')}_` : '';
|
|
55
|
+
|
|
56
|
+
const err = ev.error === undefined ? '' : `\n*error:* ${String(ev.error)}`;
|
|
57
|
+
const data = ev.data === undefined ? '' : `\n*data:* \`${JSON.stringify(ev.data)}\``;
|
|
58
|
+
|
|
59
|
+
return `${header}${meta}${err}${data}`;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
let buffer: SlackLogEvent[] = [];
|
|
63
|
+
let flushPromise: Promise<void> | undefined;
|
|
64
|
+
let dedupeKeys = new Set<string>();
|
|
65
|
+
|
|
66
|
+
const dedupeKeyFor = (ev: SlackLogEvent): string => {
|
|
67
|
+
const base = `${ev.level}:${ev.message}:${ev.error ?? ''}`;
|
|
68
|
+
return base.length > 500 ? base.slice(0, 500) : base;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const sendBatch = async (events: SlackLogEvent[]): Promise<void> => {
|
|
72
|
+
const webhookUrl = Env.get('SLACK_LOG_WEBHOOK_URL').trim();
|
|
73
|
+
if (webhookUrl.length === 0) {
|
|
74
|
+
throw ErrorFactory.createConfigError(
|
|
75
|
+
'SLACK_LOG_WEBHOOK_URL is required when Slack logging is enabled'
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const lines = events.map((e) => formatEventText(e)).join('\n\n');
|
|
80
|
+
|
|
81
|
+
const payload: SlackPayload = {
|
|
82
|
+
attachments: [
|
|
83
|
+
{
|
|
84
|
+
color: levelToColor(events[0]?.level ?? 'warn'),
|
|
85
|
+
text: lines,
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
await HttpClient.post(webhookUrl, payload).send();
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const flushNow = async (): Promise<void> => {
|
|
94
|
+
const toSend = buffer;
|
|
95
|
+
buffer = [];
|
|
96
|
+
dedupeKeys = new Set<string>();
|
|
97
|
+
|
|
98
|
+
if (!isEnabled()) return;
|
|
99
|
+
if (toSend.length === 0) return;
|
|
100
|
+
|
|
101
|
+
try {
|
|
102
|
+
await sendBatch(toSend);
|
|
103
|
+
} catch {
|
|
104
|
+
// Best-effort: never throw from logging.
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const scheduleFlush = async (): Promise<void> => {
|
|
109
|
+
if (flushPromise !== undefined) return flushPromise;
|
|
110
|
+
|
|
111
|
+
const windowMs = Math.max(0, Env.getInt('SLACK_LOG_BATCH_WINDOW_MS', 5000));
|
|
112
|
+
|
|
113
|
+
const promise = new Promise<void>((resolve) => {
|
|
114
|
+
const run = async (): Promise<void> => {
|
|
115
|
+
try {
|
|
116
|
+
await flushNow();
|
|
117
|
+
} finally {
|
|
118
|
+
resolve(undefined);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
if (windowMs === 0 || typeof globalThis.setTimeout !== 'function') {
|
|
123
|
+
void run();
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
globalThis.setTimeout(() => {
|
|
128
|
+
void run();
|
|
129
|
+
}, windowMs);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
flushPromise = promise.finally(() => {
|
|
133
|
+
flushPromise = undefined;
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
return flushPromise;
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
export const SlackLogger = Object.freeze({
|
|
140
|
+
async enqueue(event: SlackLogEvent): Promise<void> {
|
|
141
|
+
if (!isEnabled()) return Promise.resolve();
|
|
142
|
+
|
|
143
|
+
const levels = getLevels();
|
|
144
|
+
if (!levels.has(event.level)) return Promise.resolve();
|
|
145
|
+
|
|
146
|
+
const key = dedupeKeyFor(event);
|
|
147
|
+
if (dedupeKeys.has(key)) return scheduleFlush();
|
|
148
|
+
|
|
149
|
+
dedupeKeys.add(key);
|
|
150
|
+
buffer.push(event);
|
|
151
|
+
|
|
152
|
+
return scheduleFlush();
|
|
153
|
+
},
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
export default SlackLogger;
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mail Configuration
|
|
3
|
+
* Runtime mail drivers and settings
|
|
4
|
+
* Sealed namespace for immutability
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { Env } from '@config/env';
|
|
8
|
+
|
|
9
|
+
export type MailDriverName = 'disabled' | 'sendgrid' | 'smtp' | 'ses' | 'mailgun';
|
|
10
|
+
|
|
11
|
+
export type DisabledMailDriverConfig = {
|
|
12
|
+
driver: 'disabled';
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type SendGridMailDriverConfig = {
|
|
16
|
+
driver: 'sendgrid';
|
|
17
|
+
apiKey: string;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export type MailgunMailDriverConfig = {
|
|
21
|
+
driver: 'mailgun';
|
|
22
|
+
apiKey: string;
|
|
23
|
+
domain: string;
|
|
24
|
+
baseUrl: string;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// Placeholders for future drivers (kept config-first)
|
|
28
|
+
export type SmtpMailDriverConfig = {
|
|
29
|
+
driver: 'smtp';
|
|
30
|
+
host: string;
|
|
31
|
+
port: number;
|
|
32
|
+
username: string;
|
|
33
|
+
password: string;
|
|
34
|
+
secure: boolean | 'starttls';
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export type SesMailDriverConfig = {
|
|
38
|
+
driver: 'ses';
|
|
39
|
+
region: string;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export type MailDriverConfig =
|
|
43
|
+
| DisabledMailDriverConfig
|
|
44
|
+
| SendGridMailDriverConfig
|
|
45
|
+
| MailgunMailDriverConfig
|
|
46
|
+
| SmtpMailDriverConfig
|
|
47
|
+
| SesMailDriverConfig;
|
|
48
|
+
|
|
49
|
+
type MailDrivers = {
|
|
50
|
+
disabled: DisabledMailDriverConfig;
|
|
51
|
+
sendgrid: SendGridMailDriverConfig;
|
|
52
|
+
mailgun: MailgunMailDriverConfig;
|
|
53
|
+
smtp: SmtpMailDriverConfig;
|
|
54
|
+
ses: SesMailDriverConfig;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
type MailConfigInput = {
|
|
58
|
+
default: MailDriverName;
|
|
59
|
+
from: {
|
|
60
|
+
address: string;
|
|
61
|
+
name: string;
|
|
62
|
+
};
|
|
63
|
+
drivers: MailDrivers;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const getMailDriver = (config: MailConfigInput): MailDriverConfig => {
|
|
67
|
+
const defaultDriver = config.default;
|
|
68
|
+
|
|
69
|
+
if (Object.hasOwn(config.drivers, defaultDriver)) {
|
|
70
|
+
const driverName = defaultDriver as keyof MailDrivers;
|
|
71
|
+
return config.drivers[driverName];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return config.drivers.disabled;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const mailConfigObj = {
|
|
78
|
+
/**
|
|
79
|
+
* Default mail driver
|
|
80
|
+
*/
|
|
81
|
+
default: (Env.get('MAIL_DRIVER', 'disabled') as MailDriverName) ?? 'disabled',
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Default "From" identity
|
|
85
|
+
*/
|
|
86
|
+
from: {
|
|
87
|
+
address: Env.get('MAIL_FROM_ADDRESS', ''),
|
|
88
|
+
name: Env.get('MAIL_FROM_NAME', ''),
|
|
89
|
+
},
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Driver configs
|
|
93
|
+
*/
|
|
94
|
+
drivers: {
|
|
95
|
+
disabled: {
|
|
96
|
+
driver: 'disabled' as const,
|
|
97
|
+
},
|
|
98
|
+
|
|
99
|
+
sendgrid: {
|
|
100
|
+
driver: 'sendgrid' as const,
|
|
101
|
+
apiKey: Env.get('SENDGRID_API_KEY', ''),
|
|
102
|
+
},
|
|
103
|
+
|
|
104
|
+
mailgun: {
|
|
105
|
+
driver: 'mailgun' as const,
|
|
106
|
+
apiKey: Env.get('MAILGUN_API_KEY', ''),
|
|
107
|
+
domain: Env.get('MAILGUN_DOMAIN', ''),
|
|
108
|
+
baseUrl: Env.get('MAILGUN_BASE_URL', 'https://api.mailgun.net').trim(),
|
|
109
|
+
},
|
|
110
|
+
|
|
111
|
+
smtp: {
|
|
112
|
+
driver: 'smtp' as const,
|
|
113
|
+
host: Env.get('MAIL_HOST', ''),
|
|
114
|
+
port: Env.getInt('MAIL_PORT', 587),
|
|
115
|
+
username: Env.get('MAIL_USERNAME', ''),
|
|
116
|
+
password: Env.get('MAIL_PASSWORD', ''),
|
|
117
|
+
secure: (() => {
|
|
118
|
+
const raw = Env.get('MAIL_SECURE', '').trim().toLowerCase();
|
|
119
|
+
if (raw === 'starttls') return 'starttls' as const;
|
|
120
|
+
if (raw === 'tls' || raw === 'ssl' || raw === 'smtps' || raw === 'implicit') return true;
|
|
121
|
+
if (raw === 'none' || raw === 'off' || raw === 'false' || raw === '0') return false;
|
|
122
|
+
return Env.getBool('MAIL_SECURE', false);
|
|
123
|
+
})(),
|
|
124
|
+
},
|
|
125
|
+
|
|
126
|
+
ses: {
|
|
127
|
+
driver: 'ses' as const,
|
|
128
|
+
region: Env.get('AWS_REGION', 'us-east-1'),
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Get selected driver config
|
|
134
|
+
*/
|
|
135
|
+
getDriver(): MailDriverConfig {
|
|
136
|
+
return getMailDriver(this);
|
|
137
|
+
},
|
|
138
|
+
} as const;
|
|
139
|
+
|
|
140
|
+
export const mailConfig = Object.freeze(mailConfigObj);
|
|
141
|
+
export type MailConfig = typeof mailConfig;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { CsrfMiddleware } from '@middleware/CsrfMiddleware';
|
|
2
|
+
import { ErrorHandlerMiddleware } from '@middleware/ErrorHandlerMiddleware';
|
|
3
|
+
import { LoggingMiddleware } from '@middleware/LoggingMiddleware';
|
|
4
|
+
import type { Middleware } from '@middleware/MiddlewareStack';
|
|
5
|
+
import { RateLimiter } from '@middleware/RateLimiter';
|
|
6
|
+
import { SecurityMiddleware } from '@middleware/SecurityMiddleware';
|
|
7
|
+
|
|
8
|
+
export type MiddlewareConfig = {
|
|
9
|
+
global: Middleware[];
|
|
10
|
+
route: Record<string, Middleware>;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const shared = Object.freeze({
|
|
14
|
+
log: LoggingMiddleware.create(),
|
|
15
|
+
error: ErrorHandlerMiddleware.create(),
|
|
16
|
+
security: SecurityMiddleware.create(),
|
|
17
|
+
rateLimit: RateLimiter.create(),
|
|
18
|
+
csrf: CsrfMiddleware.create(),
|
|
19
|
+
} satisfies Record<string, Middleware>);
|
|
20
|
+
|
|
21
|
+
const middlewareConfigObj: MiddlewareConfig = {
|
|
22
|
+
global: [shared.log, shared.error, shared.security, shared.rateLimit, shared.csrf],
|
|
23
|
+
route: shared,
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const middlewareConfig = Object.freeze(middlewareConfigObj);
|
|
27
|
+
export default middlewareConfig;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Notification Configuration
|
|
3
|
+
*
|
|
4
|
+
* Config-first mapping of notification providers.
|
|
5
|
+
* Keeps runtime driver selection in one place and uses Env for safe access.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { Env } from '@config/env';
|
|
9
|
+
|
|
10
|
+
export type KnownNotificationDriverName = 'console' | 'termii' | 'twilio' | 'slack';
|
|
11
|
+
|
|
12
|
+
export type ConsoleNotificationDriverConfig = { driver: 'console' };
|
|
13
|
+
|
|
14
|
+
export type TermiiNotificationDriverConfig = {
|
|
15
|
+
driver: 'termii';
|
|
16
|
+
apiKey: string;
|
|
17
|
+
sender: string;
|
|
18
|
+
endpoint: string;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export type TwilioNotificationDriverConfig = {
|
|
22
|
+
driver: 'twilio';
|
|
23
|
+
accountSid: string;
|
|
24
|
+
authToken: string;
|
|
25
|
+
fromNumber: string;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export type SlackNotificationDriverConfig = {
|
|
29
|
+
driver: 'slack';
|
|
30
|
+
webhookUrl: string;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export type KnownNotificationDriverConfig =
|
|
34
|
+
| ConsoleNotificationDriverConfig
|
|
35
|
+
| TermiiNotificationDriverConfig
|
|
36
|
+
| TwilioNotificationDriverConfig
|
|
37
|
+
| SlackNotificationDriverConfig;
|
|
38
|
+
|
|
39
|
+
type NotificationProviders = {
|
|
40
|
+
console: ConsoleNotificationDriverConfig;
|
|
41
|
+
termii: TermiiNotificationDriverConfig;
|
|
42
|
+
twilio: TwilioNotificationDriverConfig;
|
|
43
|
+
slack: SlackNotificationDriverConfig;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const notificationConfigObj = {
|
|
47
|
+
/**
|
|
48
|
+
* Normalized notification driver name.
|
|
49
|
+
*
|
|
50
|
+
* NOTE: This intentionally supports custom driver names (e.g. project-specific drivers),
|
|
51
|
+
* so it returns a string rather than a strict union.
|
|
52
|
+
*/
|
|
53
|
+
getDriverName(): string {
|
|
54
|
+
return Env.get('NOTIFICATION_DRIVER', 'console').trim().toLowerCase();
|
|
55
|
+
},
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Provider configs.
|
|
59
|
+
*/
|
|
60
|
+
providers: {
|
|
61
|
+
console: {
|
|
62
|
+
driver: 'console' as const,
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
termii: {
|
|
66
|
+
driver: 'termii' as const,
|
|
67
|
+
apiKey: Env.get('TERMII_API_KEY', ''),
|
|
68
|
+
sender: Env.get('TERMII_SENDER', 'Zintrust'),
|
|
69
|
+
endpoint: Env.get('TERMII_ENDPOINT', 'https://api.termii.com/sms/send'),
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
twilio: {
|
|
73
|
+
driver: 'twilio' as const,
|
|
74
|
+
accountSid: Env.get('TWILIO_ACCOUNT_SID', ''),
|
|
75
|
+
authToken: Env.get('TWILIO_AUTH_TOKEN', ''),
|
|
76
|
+
fromNumber: Env.get('TWILIO_FROM_NUMBER', ''),
|
|
77
|
+
},
|
|
78
|
+
|
|
79
|
+
slack: {
|
|
80
|
+
driver: 'slack' as const,
|
|
81
|
+
webhookUrl: Env.get('SLACK_WEBHOOK_URL', ''),
|
|
82
|
+
},
|
|
83
|
+
} satisfies NotificationProviders,
|
|
84
|
+
} as const;
|
|
85
|
+
|
|
86
|
+
export default Object.freeze(notificationConfigObj);
|