@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
|
@@ -6,6 +6,22 @@
|
|
|
6
6
|
import { Logger } from './logger';
|
|
7
7
|
import { ErrorFactory } from '../exceptions/ZintrustError';
|
|
8
8
|
let instance;
|
|
9
|
+
function pruneCache(cache, maxEntries) {
|
|
10
|
+
if (cache.size <= maxEntries)
|
|
11
|
+
return;
|
|
12
|
+
const now = Date.now();
|
|
13
|
+
for (const [key, entry] of cache.entries()) {
|
|
14
|
+
if (entry.expiresAt <= now)
|
|
15
|
+
cache.delete(key);
|
|
16
|
+
}
|
|
17
|
+
// If still large, drop oldest entries (Map preserves insertion order)
|
|
18
|
+
while (cache.size > maxEntries) {
|
|
19
|
+
const next = cache.keys().next();
|
|
20
|
+
if (next.done === true)
|
|
21
|
+
break;
|
|
22
|
+
cache.delete(next.value);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
9
25
|
/**
|
|
10
26
|
* Get secret value from appropriate backend
|
|
11
27
|
*/
|
|
@@ -15,6 +31,8 @@ async function runGetSecret(config, cache, key, options) {
|
|
|
15
31
|
if (cached !== undefined && cached.expiresAt > Date.now()) {
|
|
16
32
|
return cached.value;
|
|
17
33
|
}
|
|
34
|
+
// Opportunistic cleanup if cache has grown
|
|
35
|
+
pruneCache(cache, 500);
|
|
18
36
|
let value;
|
|
19
37
|
switch (config.platform) {
|
|
20
38
|
case 'aws':
|
|
@@ -36,6 +54,7 @@ async function runGetSecret(config, cache, key, options) {
|
|
|
36
54
|
value,
|
|
37
55
|
expiresAt: Date.now() + ttl,
|
|
38
56
|
});
|
|
57
|
+
pruneCache(cache, 500);
|
|
39
58
|
return value;
|
|
40
59
|
}
|
|
41
60
|
/**
|
|
@@ -109,6 +128,7 @@ const SecretsManagerImpl = {
|
|
|
109
128
|
/**
|
|
110
129
|
* Rotate secret (trigger new secret generation)
|
|
111
130
|
*/
|
|
131
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
112
132
|
async rotateSecret(_key) {
|
|
113
133
|
if (config.platform === 'aws') {
|
|
114
134
|
// AWS Secrets Manager supports automatic rotation
|
|
@@ -148,6 +168,7 @@ const SecretsManagerImpl = {
|
|
|
148
168
|
/**
|
|
149
169
|
* AWS Secrets Manager integration
|
|
150
170
|
*/
|
|
171
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
151
172
|
async function getFromAWSSecretsManager(key) {
|
|
152
173
|
try {
|
|
153
174
|
Logger.debug(`[AWS] Getting secret: ${key}`);
|
|
@@ -157,14 +178,17 @@ async function getFromAWSSecretsManager(key) {
|
|
|
157
178
|
throw ErrorFactory.createTryCatchError(`Failed to retrieve secret from AWS: ${error.message}`, error);
|
|
158
179
|
}
|
|
159
180
|
}
|
|
181
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
160
182
|
async function setInAWSSecretsManager(key, _value, _options) {
|
|
161
183
|
Logger.info(`[AWS] Setting secret: ${key}`);
|
|
162
184
|
throw ErrorFactory.createConfigError('AWS SDK not available in core - use wrapper module');
|
|
163
185
|
}
|
|
186
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
164
187
|
async function deleteFromAWSSecretsManager(key) {
|
|
165
188
|
Logger.info(`[AWS] Deleting secret: ${key}`);
|
|
166
189
|
throw ErrorFactory.createConfigError('AWS SDK not available in core - use wrapper module');
|
|
167
190
|
}
|
|
191
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
168
192
|
async function listFromAWSSecretsManager(pattern) {
|
|
169
193
|
Logger.info(`[AWS] Listing secrets with pattern: ${pattern ?? '*'}`);
|
|
170
194
|
return [];
|
|
@@ -205,6 +229,7 @@ async function listFromCloudflareKV(config, pattern) {
|
|
|
205
229
|
/**
|
|
206
230
|
* Deno environment integration
|
|
207
231
|
*/
|
|
232
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
208
233
|
async function getFromDenoEnv(key) {
|
|
209
234
|
const value = globalThis['Deno']?.env?.get?.(key);
|
|
210
235
|
if (value === undefined || value === null || value === '') {
|
|
@@ -215,6 +240,7 @@ async function getFromDenoEnv(key) {
|
|
|
215
240
|
/**
|
|
216
241
|
* Local environment variables (Node.js)
|
|
217
242
|
*/
|
|
243
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
218
244
|
async function getFromEnv(key) {
|
|
219
245
|
const value = process.env[key];
|
|
220
246
|
if (value === undefined || value === null || value === '') {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type StartupConfigValidationError = {
|
|
2
|
+
key: string;
|
|
3
|
+
value: unknown;
|
|
4
|
+
message: string;
|
|
5
|
+
};
|
|
6
|
+
export type StartupConfigValidationResult = {
|
|
7
|
+
valid: boolean;
|
|
8
|
+
errors: StartupConfigValidationError[];
|
|
9
|
+
};
|
|
10
|
+
export declare const StartupConfigValidator: Readonly<{
|
|
11
|
+
validate(): StartupConfigValidationResult;
|
|
12
|
+
assertValid(): void;
|
|
13
|
+
}>;
|
|
14
|
+
export default StartupConfigValidator;
|
|
15
|
+
//# sourceMappingURL=StartupConfigValidator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StartupConfigValidator.d.ts","sourceRoot":"","sources":["../../../src/config/StartupConfigValidator.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,4BAA4B,GAAG;IACzC,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,OAAO,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,6BAA6B,GAAG;IAC1C,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,4BAA4B,EAAE,CAAC;CACxC,CAAC;AAwFF,eAAO,MAAM,sBAAsB;gBACrB,6BAA6B;mBAuC1B,IAAI;EAQnB,CAAC;AAEH,eAAe,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { appConfig } from './app';
|
|
2
|
+
import { ErrorFactory } from '../exceptions/ZintrustError';
|
|
3
|
+
const isSensitiveKey = (key) => {
|
|
4
|
+
const normalized = key.toLowerCase();
|
|
5
|
+
return (normalized.includes('password') ||
|
|
6
|
+
normalized.includes('secret') ||
|
|
7
|
+
normalized.includes('token') ||
|
|
8
|
+
normalized.includes('key') ||
|
|
9
|
+
normalized.includes('authorization'));
|
|
10
|
+
};
|
|
11
|
+
const redactValue = (key, value) => {
|
|
12
|
+
return isSensitiveKey(key) ? '<redacted>' : value;
|
|
13
|
+
};
|
|
14
|
+
const pushError = (errors, key, value, message) => {
|
|
15
|
+
errors.push({ key, value: redactValue(key, value), message });
|
|
16
|
+
};
|
|
17
|
+
const validateEnum = (errors, key, value, allowed) => {
|
|
18
|
+
if (!allowed.includes(value)) {
|
|
19
|
+
pushError(errors, key, value, `${key} must be one of: ${allowed.join(', ')}`);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const validateIntRange = (errors, key, value, min, max) => {
|
|
23
|
+
if (Number.isNaN(value)) {
|
|
24
|
+
pushError(errors, key, value, `${key} must be a valid integer`);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (value < min || value > max) {
|
|
28
|
+
pushError(errors, key, value, `${key} must be between ${min} and ${max}`);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const validatePositiveInt = (errors, key, value) => {
|
|
32
|
+
if (Number.isNaN(value)) {
|
|
33
|
+
pushError(errors, key, value, `${key} must be a valid integer`);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (value <= 0) {
|
|
37
|
+
pushError(errors, key, value, `${key} must be greater than 0`);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const getProcessLike = () => {
|
|
41
|
+
return typeof process === 'undefined' ? undefined : process;
|
|
42
|
+
};
|
|
43
|
+
const getEnvString = (key, defaultValue) => {
|
|
44
|
+
const proc = getProcessLike();
|
|
45
|
+
const env = proc?.env ?? {};
|
|
46
|
+
return env[key] ?? defaultValue;
|
|
47
|
+
};
|
|
48
|
+
const getEnvInt = (key, defaultValue) => {
|
|
49
|
+
const raw = getEnvString(key, String(defaultValue));
|
|
50
|
+
return Number.parseInt(raw, 10);
|
|
51
|
+
};
|
|
52
|
+
export const StartupConfigValidator = Object.freeze({
|
|
53
|
+
validate() {
|
|
54
|
+
const errors = [];
|
|
55
|
+
const nodeEnv = getEnvString('NODE_ENV', 'development');
|
|
56
|
+
validateEnum(errors, 'NODE_ENV', nodeEnv, ['development', 'production', 'testing', 'test']);
|
|
57
|
+
const appPort = getEnvInt('APP_PORT', 3000);
|
|
58
|
+
validateIntRange(errors, 'APP_PORT', appPort, 1, 65535);
|
|
59
|
+
const logFormat = getEnvString('LOG_FORMAT', 'text');
|
|
60
|
+
validateEnum(errors, 'LOG_FORMAT', logFormat, ['text', 'json']);
|
|
61
|
+
const logLevel = getEnvString('LOG_LEVEL', 'debug');
|
|
62
|
+
validateEnum(errors, 'LOG_LEVEL', logLevel, ['debug', 'info', 'warn', 'error']);
|
|
63
|
+
const logRotationSize = getEnvInt('LOG_ROTATION_SIZE', 10485760);
|
|
64
|
+
validatePositiveInt(errors, 'LOG_ROTATION_SIZE', logRotationSize);
|
|
65
|
+
const logRotationDays = getEnvInt('LOG_ROTATION_DAYS', 7);
|
|
66
|
+
validatePositiveInt(errors, 'LOG_ROTATION_DAYS', logRotationDays);
|
|
67
|
+
const startupHealthTimeoutMs = getEnvInt('STARTUP_HEALTH_TIMEOUT_MS', 2500);
|
|
68
|
+
validatePositiveInt(errors, 'STARTUP_HEALTH_TIMEOUT_MS', startupHealthTimeoutMs);
|
|
69
|
+
if (appConfig.isProduction()) {
|
|
70
|
+
const appKey = getEnvString('APP_KEY', '');
|
|
71
|
+
if (appKey.trim().length < 16) {
|
|
72
|
+
pushError(errors, 'APP_KEY', appKey, 'APP_KEY must be set and at least 16 characters in production');
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return { valid: errors.length === 0, errors };
|
|
76
|
+
},
|
|
77
|
+
assertValid() {
|
|
78
|
+
const result = StartupConfigValidator.validate();
|
|
79
|
+
if (result.valid)
|
|
80
|
+
return;
|
|
81
|
+
throw ErrorFactory.createConfigError('Invalid startup configuration', {
|
|
82
|
+
errors: result.errors,
|
|
83
|
+
});
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
export default StartupConfigValidator;
|
package/src/config/app.d.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Core application settings
|
|
4
4
|
* Sealed namespace for immutability
|
|
5
5
|
*/
|
|
6
|
+
type StartMode = 'development' | 'production' | 'testing';
|
|
6
7
|
declare const getSafeEnv: () => NodeJS.ProcessEnv;
|
|
7
8
|
export declare const appConfig: Readonly<{
|
|
8
9
|
/**
|
|
@@ -12,7 +13,7 @@ export declare const appConfig: Readonly<{
|
|
|
12
13
|
/**
|
|
13
14
|
* Application environment
|
|
14
15
|
*/
|
|
15
|
-
readonly environment:
|
|
16
|
+
readonly environment: StartMode;
|
|
16
17
|
/**
|
|
17
18
|
* Application port
|
|
18
19
|
*/
|
package/src/config/app.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../../../src/config/app.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../../../src/config/app.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAOH,KAAK,SAAS,GAAG,aAAa,GAAG,YAAY,GAAG,SAAS,CAAC;AAsC1D,QAAA,MAAM,UAAU,QAAO,MAAM,CAAC,UAuB7B,CAAC;AA0FF,eAAO,MAAM,SAAS;IA5EpB;;OAEG;;IAMH;;OAEG;;IAGH;;OAEG;;IAMH;;OAEG;;IAMH;;OAEG;kCACc,OAAO;IAIxB;;OAEG;iCACa,OAAO;IAIvB;;OAEG;8BACU,OAAO;IAIpB;;OAEG;;IAMH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;+BA3GkB,MAAM,CAAC,UAAU;EAiHY,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,CAAC;AAEtB,MAAM,MAAM,SAAS,GAAG,OAAO,SAAS,CAAC"}
|
package/src/config/app.js
CHANGED
|
@@ -4,39 +4,87 @@
|
|
|
4
4
|
* Sealed namespace for immutability
|
|
5
5
|
*/
|
|
6
6
|
import { Env } from './env';
|
|
7
|
+
const getProcessLike = () => {
|
|
8
|
+
return typeof process === 'undefined' ? undefined : process;
|
|
9
|
+
};
|
|
10
|
+
const readEnvString = (key, defaultValue = '') => {
|
|
11
|
+
const anyEnv = Env;
|
|
12
|
+
if (typeof anyEnv.get === 'function') {
|
|
13
|
+
return anyEnv.get(key, defaultValue);
|
|
14
|
+
}
|
|
15
|
+
const proc = getProcessLike();
|
|
16
|
+
const raw = proc?.env?.[key];
|
|
17
|
+
return raw ?? defaultValue;
|
|
18
|
+
};
|
|
19
|
+
const readEnvInt = (key, defaultValue) => {
|
|
20
|
+
const anyEnv = Env;
|
|
21
|
+
if (typeof anyEnv.getInt === 'function') {
|
|
22
|
+
return anyEnv.getInt(key, defaultValue);
|
|
23
|
+
}
|
|
24
|
+
const raw = readEnvString(key, String(defaultValue));
|
|
25
|
+
const parsed = Number.parseInt(raw, 10);
|
|
26
|
+
return Number.isNaN(parsed) ? defaultValue : parsed;
|
|
27
|
+
};
|
|
28
|
+
const readEnvBool = (key, defaultValue) => {
|
|
29
|
+
const anyEnv = Env;
|
|
30
|
+
if (typeof anyEnv.getBool === 'function') {
|
|
31
|
+
return anyEnv.getBool(key, defaultValue);
|
|
32
|
+
}
|
|
33
|
+
const raw = readEnvString(key, defaultValue ? 'true' : 'false');
|
|
34
|
+
return raw.toLowerCase() === 'true' || raw === '1';
|
|
35
|
+
};
|
|
7
36
|
const getSafeEnv = () => {
|
|
8
37
|
const baseEnv = typeof process === 'undefined' ? {} : process.env;
|
|
9
38
|
return {
|
|
10
39
|
...baseEnv,
|
|
11
40
|
// Ensure required keys exist (env.d.ts augments ProcessEnv with required fields)
|
|
12
|
-
NODE_ENV: baseEnv.NODE_ENV ??
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
41
|
+
NODE_ENV: baseEnv.NODE_ENV ??
|
|
42
|
+
readEnvString('NODE_ENV', 'development'),
|
|
43
|
+
USE_RAW_QRY: baseEnv.USE_RAW_QRY ?? (readEnvString('USE_RAW_QRY', '') || undefined),
|
|
44
|
+
SERVICE_API_KEY: baseEnv.SERVICE_API_KEY ?? readEnvString('SERVICE_API_KEY', ''),
|
|
45
|
+
SERVICE_JWT_SECRET: baseEnv.SERVICE_JWT_SECRET ?? readEnvString('SERVICE_JWT_SECRET', ''),
|
|
46
|
+
BASE_URL: baseEnv['BASE_URL'] ?? readEnvString('BASE_URL', ''),
|
|
47
|
+
MODE: baseEnv['MODE'] ?? readEnvString('MODE', ''),
|
|
18
48
|
// Hardening for child-process usage
|
|
19
|
-
PATH: Env.SAFE_PATH
|
|
49
|
+
PATH: typeof Env.SAFE_PATH === 'string'
|
|
50
|
+
? Env.SAFE_PATH
|
|
51
|
+
: (baseEnv['PATH'] ?? ''),
|
|
20
52
|
npm_config_scripts_prepend_node_path: 'true',
|
|
21
53
|
};
|
|
22
54
|
};
|
|
55
|
+
const normalizeMode = () => {
|
|
56
|
+
const value = (typeof Env.NODE_ENV === 'string'
|
|
57
|
+
? Env.NODE_ENV
|
|
58
|
+
: readEnvString('NODE_ENV', 'development'));
|
|
59
|
+
if (value === 'production' || value === 'pro' || value === 'prod')
|
|
60
|
+
return 'production';
|
|
61
|
+
if (value === 'testing' || value === 'test')
|
|
62
|
+
return 'testing';
|
|
63
|
+
return 'development';
|
|
64
|
+
};
|
|
23
65
|
const appConfigObj = {
|
|
24
66
|
/**
|
|
25
67
|
* Application name
|
|
26
68
|
*/
|
|
27
|
-
name: Env.APP_NAME
|
|
69
|
+
name: typeof Env.APP_NAME === 'string'
|
|
70
|
+
? Env.APP_NAME
|
|
71
|
+
: readEnvString('APP_NAME', 'ZinTrust'),
|
|
28
72
|
/**
|
|
29
73
|
* Application environment
|
|
30
74
|
*/
|
|
31
|
-
environment:
|
|
75
|
+
environment: normalizeMode(),
|
|
32
76
|
/**
|
|
33
77
|
* Application port
|
|
34
78
|
*/
|
|
35
|
-
port: Env.PORT
|
|
79
|
+
port: typeof Env.PORT === 'number'
|
|
80
|
+
? Env.PORT
|
|
81
|
+
: readEnvInt('APP_PORT', 3000),
|
|
36
82
|
/**
|
|
37
83
|
* Application host
|
|
38
84
|
*/
|
|
39
|
-
host: Env.HOST
|
|
85
|
+
host: typeof Env.HOST === 'string'
|
|
86
|
+
? Env.HOST
|
|
87
|
+
: readEnvString('HOST', 'localhost'),
|
|
40
88
|
/**
|
|
41
89
|
* Is development environment
|
|
42
90
|
*/
|
|
@@ -58,19 +106,21 @@ const appConfigObj = {
|
|
|
58
106
|
/**
|
|
59
107
|
* Application debug mode
|
|
60
108
|
*/
|
|
61
|
-
debug: Env.DEBUG
|
|
109
|
+
debug: typeof Env.DEBUG === 'boolean'
|
|
110
|
+
? Env.DEBUG
|
|
111
|
+
: readEnvBool('DEBUG', false),
|
|
62
112
|
/**
|
|
63
113
|
* Application timezone
|
|
64
114
|
*/
|
|
65
|
-
timezone:
|
|
115
|
+
timezone: readEnvString('APP_TIMEZONE', 'UTC'),
|
|
66
116
|
/**
|
|
67
117
|
* Request timeout (milliseconds)
|
|
68
118
|
*/
|
|
69
|
-
requestTimeout:
|
|
119
|
+
requestTimeout: readEnvInt('REQUEST_TIMEOUT', 30000),
|
|
70
120
|
/**
|
|
71
121
|
* Max request body size
|
|
72
122
|
*/
|
|
73
|
-
maxBodySize:
|
|
123
|
+
maxBodySize: readEnvString('MAX_BODY_SIZE', '10mb'),
|
|
74
124
|
getSafeEnv,
|
|
75
125
|
};
|
|
76
126
|
export const appConfig = Object.freeze(appConfigObj);
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Broadcast Configuration
|
|
3
|
+
*
|
|
4
|
+
* Centralizes broadcast driver selection and provider env mappings.
|
|
5
|
+
* Driver selection must be dynamic (tests may mutate process.env).
|
|
6
|
+
*/
|
|
7
|
+
export type KnownBroadcastDriverName = 'inmemory' | 'pusher' | 'redis' | 'redishttps';
|
|
8
|
+
export type InMemoryBroadcastDriverConfig = {
|
|
9
|
+
driver: 'inmemory';
|
|
10
|
+
};
|
|
11
|
+
export type PusherBroadcastDriverConfig = {
|
|
12
|
+
driver: 'pusher';
|
|
13
|
+
appId: string;
|
|
14
|
+
key: string;
|
|
15
|
+
secret: string;
|
|
16
|
+
cluster: string;
|
|
17
|
+
useTLS: boolean;
|
|
18
|
+
};
|
|
19
|
+
export type RedisBroadcastDriverConfig = {
|
|
20
|
+
driver: 'redis';
|
|
21
|
+
host: string;
|
|
22
|
+
port: number;
|
|
23
|
+
password: string;
|
|
24
|
+
channelPrefix: string;
|
|
25
|
+
};
|
|
26
|
+
export type RedisHttpsBroadcastDriverConfig = {
|
|
27
|
+
driver: 'redishttps';
|
|
28
|
+
endpoint: string;
|
|
29
|
+
token: string;
|
|
30
|
+
channelPrefix: string;
|
|
31
|
+
};
|
|
32
|
+
export type KnownBroadcastDriverConfig = InMemoryBroadcastDriverConfig | PusherBroadcastDriverConfig | RedisBroadcastDriverConfig | RedisHttpsBroadcastDriverConfig;
|
|
33
|
+
declare const _default: Readonly<{
|
|
34
|
+
/**
|
|
35
|
+
* Normalized broadcast driver name.
|
|
36
|
+
*
|
|
37
|
+
* NOTE: Allows custom driver names (project-specific drivers), so returns string.
|
|
38
|
+
*/
|
|
39
|
+
readonly getDriverName: () => string;
|
|
40
|
+
/**
|
|
41
|
+
* Get a config object for the currently selected driver.
|
|
42
|
+
* Defaults to inmemory for unknown/unsupported names.
|
|
43
|
+
*/
|
|
44
|
+
readonly getDriverConfig: () => KnownBroadcastDriverConfig;
|
|
45
|
+
}>;
|
|
46
|
+
export default _default;
|
|
47
|
+
//# sourceMappingURL=broadcast.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"broadcast.d.ts","sourceRoot":"","sources":["../../../src/config/broadcast.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,MAAM,MAAM,wBAAwB,GAAG,UAAU,GAAG,QAAQ,GAAG,OAAO,GAAG,YAAY,CAAC;AAEtF,MAAM,MAAM,6BAA6B,GAAG;IAC1C,MAAM,EAAE,UAAU,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,2BAA2B,GAAG;IACxC,MAAM,EAAE,QAAQ,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG;IACvC,MAAM,EAAE,OAAO,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,+BAA+B,GAAG;IAC5C,MAAM,EAAE,YAAY,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAClC,6BAA6B,GAC7B,2BAA2B,GAC3B,0BAA0B,GAC1B,+BAA+B,CAAC;;IA6BlC;;;;OAIG;kCACc,MAAM;IAIvB;;;OAGG;oCACgB,0BAA0B;;AAW/C,wBAAiD"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Broadcast Configuration
|
|
3
|
+
*
|
|
4
|
+
* Centralizes broadcast driver selection and provider env mappings.
|
|
5
|
+
* Driver selection must be dynamic (tests may mutate process.env).
|
|
6
|
+
*/
|
|
7
|
+
import { Env } from './env';
|
|
8
|
+
const normalizeDriverName = (value) => value.trim().toLowerCase();
|
|
9
|
+
const getPusherConfig = () => ({
|
|
10
|
+
driver: 'pusher',
|
|
11
|
+
appId: Env.get('PUSHER_APP_ID', ''),
|
|
12
|
+
key: Env.get('PUSHER_APP_KEY', ''),
|
|
13
|
+
secret: Env.get('PUSHER_APP_SECRET', ''),
|
|
14
|
+
cluster: Env.get('PUSHER_APP_CLUSTER', ''),
|
|
15
|
+
useTLS: Env.getBool('PUSHER_USE_TLS', true),
|
|
16
|
+
});
|
|
17
|
+
const getRedisConfig = () => ({
|
|
18
|
+
driver: 'redis',
|
|
19
|
+
host: Env.get('BROADCAST_REDIS_HOST', Env.get('REDIS_HOST', 'localhost')),
|
|
20
|
+
port: Env.getInt('BROADCAST_REDIS_PORT', Env.getInt('REDIS_PORT', 6379)),
|
|
21
|
+
password: Env.get('BROADCAST_REDIS_PASSWORD', Env.get('REDIS_PASSWORD', '')),
|
|
22
|
+
channelPrefix: Env.get('BROADCAST_CHANNEL_PREFIX', 'broadcast:'),
|
|
23
|
+
});
|
|
24
|
+
const getRedisHttpsConfig = () => ({
|
|
25
|
+
driver: 'redishttps',
|
|
26
|
+
endpoint: Env.get('REDIS_HTTPS_ENDPOINT', ''),
|
|
27
|
+
token: Env.get('REDIS_HTTPS_TOKEN', ''),
|
|
28
|
+
channelPrefix: Env.get('BROADCAST_CHANNEL_PREFIX', 'broadcast:'),
|
|
29
|
+
});
|
|
30
|
+
const broadcastConfigObj = {
|
|
31
|
+
/**
|
|
32
|
+
* Normalized broadcast driver name.
|
|
33
|
+
*
|
|
34
|
+
* NOTE: Allows custom driver names (project-specific drivers), so returns string.
|
|
35
|
+
*/
|
|
36
|
+
getDriverName() {
|
|
37
|
+
return normalizeDriverName(Env.get('BROADCAST_DRIVER', 'inmemory'));
|
|
38
|
+
},
|
|
39
|
+
/**
|
|
40
|
+
* Get a config object for the currently selected driver.
|
|
41
|
+
* Defaults to inmemory for unknown/unsupported names.
|
|
42
|
+
*/
|
|
43
|
+
getDriverConfig() {
|
|
44
|
+
const driver = this.getDriverName();
|
|
45
|
+
if (driver === 'pusher')
|
|
46
|
+
return getPusherConfig();
|
|
47
|
+
if (driver === 'redis')
|
|
48
|
+
return getRedisConfig();
|
|
49
|
+
if (driver === 'redishttps')
|
|
50
|
+
return getRedisHttpsConfig();
|
|
51
|
+
return { driver: 'inmemory' };
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
export default Object.freeze(broadcastConfigObj);
|
package/src/config/cache.d.ts
CHANGED
|
@@ -11,21 +11,19 @@ type RedisCacheDriverConfig = {
|
|
|
11
11
|
driver: 'redis';
|
|
12
12
|
host: string;
|
|
13
13
|
port: number;
|
|
14
|
-
password: string | undefined;
|
|
15
|
-
database: number;
|
|
16
14
|
ttl: number;
|
|
17
15
|
};
|
|
18
|
-
type
|
|
19
|
-
driver: '
|
|
20
|
-
|
|
16
|
+
type MongoCacheDriverConfig = {
|
|
17
|
+
driver: 'mongodb';
|
|
18
|
+
uri: string;
|
|
19
|
+
db: string;
|
|
21
20
|
ttl: number;
|
|
22
21
|
};
|
|
23
|
-
type
|
|
24
|
-
driver: '
|
|
25
|
-
path: string;
|
|
22
|
+
type KvCacheDriverConfig = {
|
|
23
|
+
driver: 'kv';
|
|
26
24
|
ttl: number;
|
|
27
25
|
};
|
|
28
|
-
type CacheDriverConfig = MemoryCacheDriverConfig | RedisCacheDriverConfig |
|
|
26
|
+
type CacheDriverConfig = MemoryCacheDriverConfig | RedisCacheDriverConfig | MongoCacheDriverConfig | KvCacheDriverConfig;
|
|
29
27
|
export declare const cacheConfig: Readonly<{
|
|
30
28
|
/**
|
|
31
29
|
* Default cache driver
|
|
@@ -43,18 +41,16 @@ export declare const cacheConfig: Readonly<{
|
|
|
43
41
|
driver: "redis";
|
|
44
42
|
host: string;
|
|
45
43
|
port: number;
|
|
46
|
-
password: string;
|
|
47
|
-
database: number;
|
|
48
44
|
ttl: number;
|
|
49
45
|
};
|
|
50
|
-
|
|
51
|
-
driver: "
|
|
52
|
-
|
|
46
|
+
mongodb: {
|
|
47
|
+
driver: "mongodb";
|
|
48
|
+
uri: string;
|
|
49
|
+
db: string;
|
|
53
50
|
ttl: number;
|
|
54
51
|
};
|
|
55
|
-
|
|
56
|
-
driver: "
|
|
57
|
-
path: string;
|
|
52
|
+
kv: {
|
|
53
|
+
driver: "kv";
|
|
58
54
|
ttl: number;
|
|
59
55
|
};
|
|
60
56
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../../src/config/cache.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,KAAK,uBAAuB,GAAG;IAC7B,MAAM,EAAE,QAAQ,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,KAAK,sBAAsB,GAAG;IAC5B,MAAM,EAAE,OAAO,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../../src/config/cache.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,KAAK,uBAAuB,GAAG;IAC7B,MAAM,EAAE,QAAQ,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,KAAK,sBAAsB,GAAG;IAC5B,MAAM,EAAE,OAAO,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,KAAK,sBAAsB,GAAG;IAC5B,MAAM,EAAE,SAAS,CAAC;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,KAAK,mBAAmB,GAAG;IACzB,MAAM,EAAE,IAAI,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,KAAK,iBAAiB,GAClB,uBAAuB,GACvB,sBAAsB,GACtB,sBAAsB,GACtB,mBAAmB,CAAC;AA2ExB,eAAO,MAAM,WAAW;IAjDtB;;OAEG;;IAGH;;OAEG;;;;;;;;;;;;;;;;;;;;;;;IAwBH;;OAEG;iBACU,iBAAiB;IAI9B;;OAEG;;IAGH;;OAEG;;EAImD,CAAC;AACzD,MAAM,MAAM,WAAW,GAAG,OAAO,WAAW,CAAC"}
|
package/src/config/cache.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import { Env } from './env';
|
|
7
7
|
const getCacheDriver = (config) => {
|
|
8
8
|
const defaultDriver = config.default;
|
|
9
|
-
if (Object.
|
|
9
|
+
if (Object.hasOwn(config.drivers, defaultDriver)) {
|
|
10
10
|
const driverName = defaultDriver;
|
|
11
11
|
return config.drivers[driverName];
|
|
12
12
|
}
|
|
@@ -29,19 +29,17 @@ const cacheConfigObj = {
|
|
|
29
29
|
driver: 'redis',
|
|
30
30
|
host: Env.get('REDIS_HOST', 'localhost'),
|
|
31
31
|
port: Env.getInt('REDIS_PORT', 6379),
|
|
32
|
-
password: Env.get('REDIS_PASSWORD'),
|
|
33
|
-
database: Env.getInt('REDIS_DB', 0),
|
|
34
32
|
ttl: Env.getInt('CACHE_REDIS_TTL', 3600),
|
|
35
33
|
},
|
|
36
|
-
|
|
37
|
-
driver: '
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
mongodb: {
|
|
35
|
+
driver: 'mongodb',
|
|
36
|
+
uri: Env.get('MONGO_URI'),
|
|
37
|
+
db: Env.get('MONGO_DB', 'zintrust_cache'),
|
|
38
|
+
ttl: Env.getInt('CACHE_MONGO_TTL', 3600),
|
|
40
39
|
},
|
|
41
|
-
|
|
42
|
-
driver: '
|
|
43
|
-
|
|
44
|
-
ttl: Env.getInt('CACHE_FILE_TTL', 3600),
|
|
40
|
+
kv: {
|
|
41
|
+
driver: 'kv',
|
|
42
|
+
ttl: Env.getInt('CACHE_KV_TTL', 3600),
|
|
45
43
|
},
|
|
46
44
|
},
|
|
47
45
|
/**
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cloudflare Workers Environment Access
|
|
3
|
+
*
|
|
4
|
+
* Centralizes access to Workers bindings via globalThis.env.
|
|
5
|
+
* This keeps runtime-specific globals out of adapters/drivers.
|
|
6
|
+
*/
|
|
7
|
+
import type { DatabaseConfig, ID1Database } from '../orm/DatabaseAdapter';
|
|
8
|
+
export type WorkersEnv = Record<string, unknown>;
|
|
9
|
+
type KVNamespace = {
|
|
10
|
+
get(key: string, options?: {
|
|
11
|
+
type: 'text' | 'json' | 'arrayBuffer' | 'stream';
|
|
12
|
+
}): Promise<unknown>;
|
|
13
|
+
put(key: string, value: string | ReadableStream | ArrayBuffer | FormData, options?: {
|
|
14
|
+
expiration?: number;
|
|
15
|
+
expirationTtl?: number;
|
|
16
|
+
metadata?: unknown;
|
|
17
|
+
}): Promise<void>;
|
|
18
|
+
delete(key: string): Promise<void>;
|
|
19
|
+
};
|
|
20
|
+
export declare const Cloudflare: Readonly<{
|
|
21
|
+
getWorkersEnv: () => WorkersEnv | null;
|
|
22
|
+
getD1Binding: (config: DatabaseConfig) => ID1Database | null;
|
|
23
|
+
getKVBinding: (bindingName?: string) => KVNamespace | null;
|
|
24
|
+
}>;
|
|
25
|
+
export {};
|
|
26
|
+
//# sourceMappingURL=cloudflare.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cloudflare.d.ts","sourceRoot":"","sources":["../../../src/config/cloudflare.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAExE,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEjD,KAAK,WAAW,GAAG;IACjB,GAAG,CACD,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,aAAa,GAAG,QAAQ,CAAA;KAAE,GAC7D,OAAO,CAAC,OAAO,CAAC,CAAC;IACpB,GAAG,CACD,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,GAAG,cAAc,GAAG,WAAW,GAAG,QAAQ,EACvD,OAAO,CAAC,EAAE;QAAE,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,aAAa,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,GAC5E,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACpC,CAAC;AA8BF,eAAO,MAAM,UAAU;yBA5BG,UAAU,GAAG,IAAI;2BAOb,cAAc,KAAG,WAAW,GAAG,IAAI;4CAanB,WAAW,GAAG,IAAI;EAY9D,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cloudflare Workers Environment Access
|
|
3
|
+
*
|
|
4
|
+
* Centralizes access to Workers bindings via globalThis.env.
|
|
5
|
+
* This keeps runtime-specific globals out of adapters/drivers.
|
|
6
|
+
*/
|
|
7
|
+
const getWorkersEnv = () => {
|
|
8
|
+
const env = globalThis.env;
|
|
9
|
+
if (env === undefined || env === null)
|
|
10
|
+
return null;
|
|
11
|
+
if (typeof env !== 'object')
|
|
12
|
+
return null;
|
|
13
|
+
return env;
|
|
14
|
+
};
|
|
15
|
+
const getD1Binding = (config) => {
|
|
16
|
+
if (config.d1 !== undefined && config.d1 !== null)
|
|
17
|
+
return config.d1;
|
|
18
|
+
const env = getWorkersEnv();
|
|
19
|
+
const envDb = env === null ? undefined : env['DB'];
|
|
20
|
+
if (envDb !== undefined)
|
|
21
|
+
return envDb;
|
|
22
|
+
const globalDb = globalThis.DB;
|
|
23
|
+
if (globalDb !== undefined)
|
|
24
|
+
return globalDb;
|
|
25
|
+
return null;
|
|
26
|
+
};
|
|
27
|
+
const getKVBinding = (bindingName = 'CACHE') => {
|
|
28
|
+
const env = getWorkersEnv();
|
|
29
|
+
if (env === null)
|
|
30
|
+
return null;
|
|
31
|
+
const kv = env[bindingName];
|
|
32
|
+
return kv ?? null;
|
|
33
|
+
};
|
|
34
|
+
export const Cloudflare = Object.freeze({
|
|
35
|
+
getWorkersEnv,
|
|
36
|
+
getD1Binding,
|
|
37
|
+
getKVBinding,
|
|
38
|
+
});
|
package/src/config/env.d.ts
CHANGED
|
@@ -48,8 +48,14 @@ export declare const Env: Readonly<{
|
|
|
48
48
|
ENVIRONMENT: string;
|
|
49
49
|
REQUEST_TIMEOUT: number;
|
|
50
50
|
MAX_BODY_SIZE: number;
|
|
51
|
+
SHUTDOWN_TIMEOUT: number;
|
|
51
52
|
LOG_LEVEL: "debug" | "info" | "warn" | "error";
|
|
53
|
+
LOG_FORMAT: string;
|
|
52
54
|
DISABLE_LOGGING: boolean;
|
|
55
|
+
LOG_HTTP_REQUEST: boolean;
|
|
56
|
+
LOG_TO_FILE: boolean;
|
|
57
|
+
LOG_ROTATION_SIZE: number;
|
|
58
|
+
LOG_ROTATION_DAYS: number;
|
|
53
59
|
NODE_BIN_DIR: string;
|
|
54
60
|
SAFE_PATH: string;
|
|
55
61
|
}>;
|
package/src/config/env.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../../src/config/env.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAkDH,eAAO,MAAM,GAAG;eA9BE,MAAM,iBAAiB,MAAM,KAAG,MAAM;kBAMnC,MAAM,iBAAiB,MAAM,KAAG,MAAM;mBAQrC,MAAM,iBAAiB,OAAO,KAAG,OAAO
|
|
1
|
+
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../../src/config/env.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAkDH,eAAO,MAAM,GAAG;eA9BE,MAAM,iBAAiB,MAAM,KAAG,MAAM;kBAMnC,MAAM,iBAAiB,MAAM,KAAG,MAAM;mBAQrC,MAAM,iBAAiB,OAAO,KAAG,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;eA+EP,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO;;;;;;;;;EAkCxF,CAAC"}
|
package/src/config/env.js
CHANGED
|
@@ -98,9 +98,15 @@ export const Env = Object.freeze({
|
|
|
98
98
|
ENVIRONMENT: get('ENVIRONMENT', 'development'),
|
|
99
99
|
REQUEST_TIMEOUT: getInt('REQUEST_TIMEOUT', 30000),
|
|
100
100
|
MAX_BODY_SIZE: getInt('MAX_BODY_SIZE', 10485760),
|
|
101
|
+
SHUTDOWN_TIMEOUT: getInt('SHUTDOWN_TIMEOUT', 10000),
|
|
101
102
|
// Logging
|
|
102
103
|
LOG_LEVEL: get('LOG_LEVEL', getDefaultLogLevel()),
|
|
104
|
+
LOG_FORMAT: get('LOG_FORMAT', 'text'),
|
|
103
105
|
DISABLE_LOGGING: getBool('DISABLE_LOGGING', false),
|
|
106
|
+
LOG_HTTP_REQUEST: getBool('LOG_HTTP_REQUEST', false),
|
|
107
|
+
LOG_TO_FILE: getBool('LOG_TO_FILE', false),
|
|
108
|
+
LOG_ROTATION_SIZE: getInt('LOG_ROTATION_SIZE', 10485760),
|
|
109
|
+
LOG_ROTATION_DAYS: getInt('LOG_ROTATION_DAYS', 7),
|
|
104
110
|
// Paths (safely constructed for Node.js environments)
|
|
105
111
|
NODE_BIN_DIR: (() => {
|
|
106
112
|
try {
|