@zintrust/core 0.1.1 → 0.1.3
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 +3 -3
- package/bin/zintrust.d.ts.map +1 -1
- package/bin/zintrust.js +18 -1
- package/package.json +15 -1
- 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 +6 -4
- package/src/cache/drivers/KVDriver.d.ts.map +1 -1
- package/src/cache/drivers/KVDriver.js +6 -6
- 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 +11 -4
- package/src/cli/commands/AddCommand.js +1 -1
- package/src/cli/commands/ConfigCommand.d.ts.map +1 -1
- package/src/cli/commands/ConfigCommand.js +34 -4
- 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 +4 -3
- package/src/cli/commands/FixCommand.d.ts.map +1 -1
- package/src/cli/commands/FixCommand.js +3 -16
- 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 +1 -1
- 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/NewCommand.d.ts +4 -0
- package/src/cli/commands/NewCommand.d.ts.map +1 -1
- package/src/cli/commands/NewCommand.js +33 -20
- 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 +11 -20
- 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.js +1 -1
- package/src/cli/scaffolding/FeatureScaffolder.js +4 -4
- package/src/cli/scaffolding/FileGenerator.js +1 -1
- package/src/cli/scaffolding/ModelGenerator.js +1 -1
- 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 +3 -2
- package/src/cli/scaffolding/RouteGenerator.js +1 -1
- package/src/cli/scaffolding/ServiceIntegrationTestGenerator.js +1 -1
- package/src/cli/scaffolding/ServiceScaffolder.js +2 -2
- 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 +37 -11
- 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/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/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/MicroserviceManager.d.ts.map +1 -1
- package/src/microservices/MicroserviceManager.js +9 -6
- package/src/microservices/PostgresAdapter.d.ts.map +1 -1
- package/src/microservices/PostgresAdapter.js +3 -1
- package/src/microservices/ServiceBundler.d.ts.map +1 -1
- package/src/microservices/ServiceBundler.js +6 -4
- package/src/microservices/ServiceHealthMonitor.js +2 -2
- 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/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 +150 -75
- 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 -6
- package/src/runtime/adapters/CloudflareAdapter.js +2 -2
- package/src/runtime/adapters/FargateAdapter.d.ts.map +1 -1
- package/src/runtime/adapters/FargateAdapter.js +2 -1
- 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 +2 -1
- 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 +155 -17
- 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 +44 -21
- 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 +11 -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/routes/storage.ts.tpl +42 -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 +49 -0
- package/src/tools/http/Http.d.ts.map +1 -0
- package/src/tools/http/Http.js +169 -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/LocalSignedUrl.d.ts +12 -0
- package/src/tools/storage/LocalSignedUrl.d.ts.map +1 -0
- package/src/tools/storage/LocalSignedUrl.js +108 -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 +18 -0
- package/src/tools/storage/drivers/Local.d.ts.map +1 -0
- package/src/tools/storage/drivers/Local.js +89 -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 +111 -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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NodeServerAdapter.d.ts","sourceRoot":"","sources":["../../../../src/runtime/adapters/NodeServerAdapter.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,aAAa,EAGb,cAAc,EACf,MAAM,yBAAyB,CAAC;AAEjC;;;;GAIG;AACH,eAAO,MAAM,iBAAiB;IAC5B;;OAEG;mBACY,aAAa,GAAG,cAAc,GAAG;QAC9C,WAAW,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;QACzD,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;KACvB;
|
|
1
|
+
{"version":3,"file":"NodeServerAdapter.d.ts","sourceRoot":"","sources":["../../../../src/runtime/adapters/NodeServerAdapter.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,aAAa,EAGb,cAAc,EACf,MAAM,yBAAyB,CAAC;AAEjC;;;;GAIG;AACH,eAAO,MAAM,iBAAiB;IAC5B;;OAEG;mBACY,aAAa,GAAG,cAAc,GAAG;QAC9C,WAAW,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;QACzD,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;KACvB;EAoED,CAAC"}
|
|
@@ -16,8 +16,9 @@ export const NodeServerAdapter = Object.freeze({
|
|
|
16
16
|
const state = {};
|
|
17
17
|
return {
|
|
18
18
|
platform: 'nodejs',
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
19
20
|
async handle(_event, _context) {
|
|
20
|
-
|
|
21
|
+
throw ErrorFactory.createConfigError('Node.js adapter requires startServer() method. Use RuntimeDetector for automatic initialization.');
|
|
21
22
|
},
|
|
22
23
|
/**
|
|
23
24
|
* Start HTTP server for Node.js environments
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ScheduleRunner
|
|
3
|
+
* Lightweight, zero-dependency schedule runner for long-running runtimes
|
|
4
|
+
*/
|
|
5
|
+
import type { ISchedule, IScheduleKernel } from './types';
|
|
6
|
+
type ScheduleRunner = {
|
|
7
|
+
register: (schedule: ISchedule) => void;
|
|
8
|
+
start: (kernel?: IScheduleKernel) => void;
|
|
9
|
+
stop: (timeoutMs?: number) => Promise<void>;
|
|
10
|
+
list: () => ISchedule[];
|
|
11
|
+
runOnce: (name: string, kernel?: IScheduleKernel) => Promise<void>;
|
|
12
|
+
};
|
|
13
|
+
export declare const create: () => Readonly<ScheduleRunner>;
|
|
14
|
+
declare const _default: {
|
|
15
|
+
create: () => Readonly<ScheduleRunner>;
|
|
16
|
+
};
|
|
17
|
+
export default _default;
|
|
18
|
+
//# sourceMappingURL=ScheduleRunner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ScheduleRunner.d.ts","sourceRoot":"","sources":["../../../src/scheduler/ScheduleRunner.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAgBnE,KAAK,cAAc,GAAG;IACpB,QAAQ,EAAE,CAAC,QAAQ,EAAE,SAAS,KAAK,IAAI,CAAC;IACxC,KAAK,EAAE,CAAC,MAAM,CAAC,EAAE,eAAe,KAAK,IAAI,CAAC;IAC1C,IAAI,EAAE,CAAC,SAAS,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5C,IAAI,EAAE,MAAM,SAAS,EAAE,CAAC;IACxB,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,eAAe,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACpE,CAAC;AAoKF,eAAO,MAAM,MAAM,QAAO,QAAQ,CAAC,cAAc,CAuBhD,CAAC;;kBAvBwB,QAAQ,CAAC,cAAc,CAAC;;AAyBlD,wBAA0B"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ScheduleRunner
|
|
3
|
+
* Lightweight, zero-dependency schedule runner for long-running runtimes
|
|
4
|
+
*/
|
|
5
|
+
import { Logger } from '../config/logger';
|
|
6
|
+
import { ErrorFactory } from '../exceptions/ZintrustError';
|
|
7
|
+
const createRegister = (runner, invokeHandler) => (schedule) => {
|
|
8
|
+
if (runner.schedules.has(schedule.name)) {
|
|
9
|
+
Logger.warn(`Schedule replaced: ${schedule.name}`);
|
|
10
|
+
}
|
|
11
|
+
const state = {
|
|
12
|
+
schedule,
|
|
13
|
+
isRunning: false,
|
|
14
|
+
};
|
|
15
|
+
runner.schedules.set(schedule.name, state);
|
|
16
|
+
// If schedules are already started, register should take effect immediately.
|
|
17
|
+
if (runner.started && schedule.enabled !== false) {
|
|
18
|
+
if (schedule.runOnStart === true) {
|
|
19
|
+
void invokeHandler(state, runner.kernel);
|
|
20
|
+
}
|
|
21
|
+
if (typeof schedule.intervalMs === 'number' && schedule.intervalMs > 0) {
|
|
22
|
+
state.intervalId = globalThis.setInterval(() => {
|
|
23
|
+
void invokeHandler(state, runner.kernel);
|
|
24
|
+
}, schedule.intervalMs);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
const createInvokeHandler = () => async (state, kernel) => {
|
|
29
|
+
if (state.isRunning) {
|
|
30
|
+
Logger.info(`Skipping overlapping run for schedule: ${state.schedule.name}`);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
state.isRunning = true;
|
|
34
|
+
try {
|
|
35
|
+
const handlerPromise = Promise.resolve()
|
|
36
|
+
.then(async () => state.schedule.handler(kernel))
|
|
37
|
+
.then(() => {
|
|
38
|
+
state.lastRunAt = Date.now();
|
|
39
|
+
})
|
|
40
|
+
.catch((error) => {
|
|
41
|
+
Logger.error(`Schedule '${state.schedule.name}' failed:`, error);
|
|
42
|
+
})
|
|
43
|
+
.then(() => undefined);
|
|
44
|
+
state.runningPromise = handlerPromise;
|
|
45
|
+
await handlerPromise;
|
|
46
|
+
}
|
|
47
|
+
finally {
|
|
48
|
+
state.isRunning = false;
|
|
49
|
+
state.runningPromise = undefined;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
const createStart = (runner, invokeHandler) => (kernel) => {
|
|
53
|
+
if (runner.started)
|
|
54
|
+
return;
|
|
55
|
+
runner.started = true;
|
|
56
|
+
runner.kernel = kernel;
|
|
57
|
+
for (const [, state] of runner.schedules) {
|
|
58
|
+
const { schedule } = state;
|
|
59
|
+
if (schedule.enabled === false)
|
|
60
|
+
continue;
|
|
61
|
+
if (schedule.runOnStart === true) {
|
|
62
|
+
// fire-and-forget (handled by invokeHandler which logs errors)
|
|
63
|
+
void invokeHandler(state, kernel);
|
|
64
|
+
}
|
|
65
|
+
if (typeof schedule.intervalMs === 'number' && schedule.intervalMs > 0) {
|
|
66
|
+
const id = globalThis.setInterval(() => {
|
|
67
|
+
// fire and forget invocation; overlapping runs are protected inside
|
|
68
|
+
void invokeHandler(state, kernel);
|
|
69
|
+
}, schedule.intervalMs);
|
|
70
|
+
state.intervalId = id;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
const createStop = (runner) => async () => {
|
|
75
|
+
if (!runner.started)
|
|
76
|
+
return;
|
|
77
|
+
runner.started = false;
|
|
78
|
+
runner.kernel = undefined;
|
|
79
|
+
// Clear intervals
|
|
80
|
+
for (const [, state] of runner.schedules) {
|
|
81
|
+
if (state.intervalId !== undefined) {
|
|
82
|
+
globalThis.clearInterval(state.intervalId);
|
|
83
|
+
state.intervalId = undefined;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
// Await running handlers (runningPromise is guaranteed not to reject)
|
|
87
|
+
const running = [];
|
|
88
|
+
for (const [, state] of runner.schedules) {
|
|
89
|
+
if (state.isRunning && state.runningPromise !== undefined) {
|
|
90
|
+
running.push(state.runningPromise);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (running.length > 0) {
|
|
94
|
+
await Promise.all(running);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
const withTimeout = async (promise, timeoutMs) => {
|
|
98
|
+
const ms = typeof timeoutMs === 'number' ? timeoutMs : 0;
|
|
99
|
+
if (ms <= 0) {
|
|
100
|
+
await promise;
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
let timeoutId;
|
|
104
|
+
try {
|
|
105
|
+
await Promise.race([
|
|
106
|
+
promise,
|
|
107
|
+
new Promise((resolve) => {
|
|
108
|
+
timeoutId = globalThis.setTimeout(() => {
|
|
109
|
+
Logger.error('ScheduleRunner.stop() timed out; continuing shutdown', {
|
|
110
|
+
timeoutMs: ms,
|
|
111
|
+
});
|
|
112
|
+
resolve();
|
|
113
|
+
}, ms);
|
|
114
|
+
}),
|
|
115
|
+
]);
|
|
116
|
+
}
|
|
117
|
+
finally {
|
|
118
|
+
if (timeoutId !== undefined)
|
|
119
|
+
globalThis.clearTimeout(timeoutId);
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
const createStopWithTimeout = (stop) => async (timeoutMs) => {
|
|
123
|
+
await withTimeout(stop(), timeoutMs);
|
|
124
|
+
};
|
|
125
|
+
const createList = (runner) => () => Array.from(runner.schedules.values()).map((s) => s.schedule);
|
|
126
|
+
const createRunOnce = (runner, invokeHandler) => async (name, kernel) => {
|
|
127
|
+
const state = runner.schedules.get(name);
|
|
128
|
+
if (state === undefined)
|
|
129
|
+
throw ErrorFactory.createNotFoundError(`Schedule not found: ${name}`);
|
|
130
|
+
if (state.schedule.enabled === false)
|
|
131
|
+
return;
|
|
132
|
+
await invokeHandler(state, kernel ?? runner.kernel);
|
|
133
|
+
};
|
|
134
|
+
export const create = () => {
|
|
135
|
+
const runner = {
|
|
136
|
+
schedules: new Map(),
|
|
137
|
+
started: false,
|
|
138
|
+
kernel: undefined,
|
|
139
|
+
};
|
|
140
|
+
const invokeHandler = createInvokeHandler();
|
|
141
|
+
const register = createRegister(runner, invokeHandler);
|
|
142
|
+
const start = createStart(runner, invokeHandler);
|
|
143
|
+
const stopRaw = createStop(runner);
|
|
144
|
+
const stop = createStopWithTimeout(stopRaw);
|
|
145
|
+
const list = createList(runner);
|
|
146
|
+
const runOnce = createRunOnce(runner, invokeHandler);
|
|
147
|
+
return Object.freeze({
|
|
148
|
+
register,
|
|
149
|
+
start,
|
|
150
|
+
stop,
|
|
151
|
+
list,
|
|
152
|
+
runOnce,
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
export default { create };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/scheduler/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAC3E,YAAY,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { create as createScheduleRunner } from './ScheduleRunner';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scheduler types
|
|
3
|
+
*/
|
|
4
|
+
export type IScheduleKernel = Readonly<{
|
|
5
|
+
getContainer?: () => unknown;
|
|
6
|
+
getRouter?: () => unknown;
|
|
7
|
+
}>;
|
|
8
|
+
export type IScheduleHandler = (kernel?: IScheduleKernel) => Promise<void> | void;
|
|
9
|
+
export type ISchedule = {
|
|
10
|
+
name: string;
|
|
11
|
+
intervalMs?: number;
|
|
12
|
+
handler: IScheduleHandler;
|
|
13
|
+
enabled?: boolean;
|
|
14
|
+
runOnStart?: boolean;
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/scheduler/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,MAAM,eAAe,GAAG,QAAQ,CAAC;IACrC,YAAY,CAAC,EAAE,MAAM,OAAO,CAAC;IAC7B,SAAS,CAAC,EAAE,MAAM,OAAO,CAAC;CAC3B,CAAC,CAAC;AAEH,MAAM,MAAM,gBAAgB,GAAG,CAAC,MAAM,CAAC,EAAE,eAAe,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;AAElF,MAAM,MAAM,SAAS,GAAG;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,gBAAgB,CAAC;IAC1B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/schedules/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,wBAAwB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as logCleanup } from './log-cleanup';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log-cleanup.d.ts","sourceRoot":"","sources":["../../../src/schedules/log-cleanup.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAIlD,QAAA,MAAM,kBAAkB,EAAE,SAYzB,CAAC;AAEF,eAAe,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Env } from '../config/env';
|
|
2
|
+
import { Logger, cleanLogsOnce } from '../config/logger';
|
|
3
|
+
const intervalMs = Env.getInt('LOG_CLEANUP_INTERVAL_MS', 3600000);
|
|
4
|
+
const LogCleanupSchedule = {
|
|
5
|
+
name: 'log.cleanup',
|
|
6
|
+
intervalMs: intervalMs,
|
|
7
|
+
handler: async () => {
|
|
8
|
+
try {
|
|
9
|
+
await cleanLogsOnce();
|
|
10
|
+
}
|
|
11
|
+
catch (err) {
|
|
12
|
+
Logger.error('Log cleanup schedule failed', err);
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
enabled: Env.getBool('LOG_CLEANUP_ENABLED', Env.getBool('LOG_TO_FILE', false)),
|
|
16
|
+
runOnStart: false,
|
|
17
|
+
};
|
|
18
|
+
export default LogCleanupSchedule;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GenerateEnvArtifacts
|
|
3
|
+
* - Generates env.d.ts and .env.example from the framework's Env usage.
|
|
4
|
+
*
|
|
5
|
+
* Goals:
|
|
6
|
+
* - Developer convenience (discoverable env keys)
|
|
7
|
+
* - Keep env.d.ts + .env.example in sync with src/config usage
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* tsx src/scripts/GenerateEnvArtifacts.ts
|
|
11
|
+
*/
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=GenerateEnvArtifacts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GenerateEnvArtifacts.d.ts","sourceRoot":"","sources":["../../../src/scripts/GenerateEnvArtifacts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG"}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GenerateEnvArtifacts
|
|
3
|
+
* - Generates env.d.ts and .env.example from the framework's Env usage.
|
|
4
|
+
*
|
|
5
|
+
* Goals:
|
|
6
|
+
* - Developer convenience (discoverable env keys)
|
|
7
|
+
* - Keep env.d.ts + .env.example in sync with src/config usage
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* tsx src/scripts/GenerateEnvArtifacts.ts
|
|
11
|
+
*/
|
|
12
|
+
import { Logger } from '../config/logger';
|
|
13
|
+
import { ErrorFactory } from '../exceptions/ZintrustError';
|
|
14
|
+
import fs from '../node-singletons/fs';
|
|
15
|
+
import * as path from '../node-singletons/path';
|
|
16
|
+
const ROOT_DIR = path.resolve(process.cwd());
|
|
17
|
+
const GENERATED_MARKER = 'Generated by src/scripts/GenerateEnvArtifacts.ts';
|
|
18
|
+
const walkDir = (dirAbs) => {
|
|
19
|
+
const out = [];
|
|
20
|
+
const entries = fs.readdirSync(dirAbs, { withFileTypes: true });
|
|
21
|
+
for (const entry of entries) {
|
|
22
|
+
if (entry.name === 'node_modules' || entry.name === 'dist' || entry.name === 'coverage')
|
|
23
|
+
continue;
|
|
24
|
+
const abs = path.join(dirAbs, entry.name);
|
|
25
|
+
if (entry.isDirectory()) {
|
|
26
|
+
out.push(...walkDir(abs));
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
if (entry.isFile() && entry.name.endsWith('.ts'))
|
|
30
|
+
out.push(abs);
|
|
31
|
+
}
|
|
32
|
+
return out;
|
|
33
|
+
};
|
|
34
|
+
const readText = (fileAbs) => fs.readFileSync(fileAbs, 'utf8');
|
|
35
|
+
const uniq = (arr) => Array.from(new Set(arr));
|
|
36
|
+
const parseEnvUsages = (content) => {
|
|
37
|
+
const out = [];
|
|
38
|
+
// Avoid catastrophic backtracking by not using complex regexes to parse arbitrary JS.
|
|
39
|
+
// Instead scan for Env.<method>(...), handle quotes/escapes and balanced parentheses in linear time.
|
|
40
|
+
const extractArgs = (parenIdx) => {
|
|
41
|
+
let i = parenIdx;
|
|
42
|
+
if (content[i] !== '(')
|
|
43
|
+
return { args: '', endIdx: i + 1 };
|
|
44
|
+
i++; // move past '('
|
|
45
|
+
const start = i;
|
|
46
|
+
let depth = 1;
|
|
47
|
+
// Skip a quoted string starting at idx (idx points at the opening quote).
|
|
48
|
+
const skipQuoted = (idx) => {
|
|
49
|
+
let newIdx = idx;
|
|
50
|
+
const quote = content[newIdx];
|
|
51
|
+
newIdx++;
|
|
52
|
+
while (newIdx < content.length) {
|
|
53
|
+
if (content[newIdx] === '\\') {
|
|
54
|
+
newIdx += 2;
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
if (content[newIdx] === quote) {
|
|
58
|
+
return newIdx + 1;
|
|
59
|
+
}
|
|
60
|
+
newIdx++;
|
|
61
|
+
}
|
|
62
|
+
return newIdx;
|
|
63
|
+
};
|
|
64
|
+
while (i < content.length && depth > 0) {
|
|
65
|
+
const ch = content[i];
|
|
66
|
+
if (ch === "'" || ch === '"') {
|
|
67
|
+
i = skipQuoted(i);
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (ch === '(') {
|
|
71
|
+
depth++;
|
|
72
|
+
i++;
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (ch === ')') {
|
|
76
|
+
depth--;
|
|
77
|
+
if (depth === 0) {
|
|
78
|
+
return { args: content.slice(start, i), endIdx: i + 1 };
|
|
79
|
+
}
|
|
80
|
+
i++;
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
i++;
|
|
84
|
+
}
|
|
85
|
+
// unbalanced or EOF: return what we have
|
|
86
|
+
return { args: content.slice(start, i), endIdx: i };
|
|
87
|
+
};
|
|
88
|
+
const methods = ['get', 'getInt', 'getBool'];
|
|
89
|
+
for (const method of methods) {
|
|
90
|
+
const token = `Env.${method}(`;
|
|
91
|
+
let idx = content.indexOf(token, 0);
|
|
92
|
+
while (idx !== -1) {
|
|
93
|
+
const parenIdx = idx + token.length - 1; // position of '('
|
|
94
|
+
const { args, endIdx } = extractArgs(parenIdx);
|
|
95
|
+
// args looks like: ['KEY'[, defaultVal]]
|
|
96
|
+
const keyMatch = /^\s*['"]([A-Z0-9_]+)['"]/.exec(args);
|
|
97
|
+
if (keyMatch) {
|
|
98
|
+
const key = keyMatch[1];
|
|
99
|
+
const rest = args.slice(keyMatch[0].length);
|
|
100
|
+
const restTrimmed = rest.replace(/^\s*,\s*/, '').trim();
|
|
101
|
+
const defaultValue = restTrimmed.length > 0 ? restTrimmed : undefined;
|
|
102
|
+
out.push({ key, defaultValue });
|
|
103
|
+
}
|
|
104
|
+
idx = content.indexOf(token, endIdx);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return out;
|
|
108
|
+
};
|
|
109
|
+
const renderEnvDts = (keys) => {
|
|
110
|
+
const sortedKeys = keys.toSorted((a, b) => a.localeCompare(b));
|
|
111
|
+
const lines = sortedKeys.map((k) => ` ${k}?: string | undefined;`).join('\n');
|
|
112
|
+
return `declare namespace NodeJS {\n interface ProcessEnv {\n NODE_ENV: 'development' | 'production' | 'testing' | undefined;\n\n${lines}\n }\n}\n`;
|
|
113
|
+
};
|
|
114
|
+
const renderEnvExample = (keys) => {
|
|
115
|
+
const header = `# Zintrust Framework - Environment Configuration\n# Generated by src/scripts/GenerateEnvArtifacts.ts\n# Copy this file to .env and configure for your environment\n\n`;
|
|
116
|
+
const sortedKeys = keys.toSorted((a, b) => a.localeCompare(b));
|
|
117
|
+
const body = sortedKeys
|
|
118
|
+
.filter((k) => k !== 'NODE_ENV')
|
|
119
|
+
.map((k) => `${k}=`)
|
|
120
|
+
.join('\n');
|
|
121
|
+
return header + `NODE_ENV=development\n` + body + `\n`;
|
|
122
|
+
};
|
|
123
|
+
const renderEnvKeys = (keys) => {
|
|
124
|
+
const sortedKeys = keys.toSorted((a, b) => a.localeCompare(b));
|
|
125
|
+
return sortedKeys.join('\n') + '\n';
|
|
126
|
+
};
|
|
127
|
+
const writeIfChanged = (fileAbs, next) => {
|
|
128
|
+
const prev = fs.existsSync(fileAbs) ? fs.readFileSync(fileAbs, 'utf8') : '';
|
|
129
|
+
if (prev === next)
|
|
130
|
+
return;
|
|
131
|
+
fs.writeFileSync(fileAbs, next, 'utf8');
|
|
132
|
+
};
|
|
133
|
+
const shouldOverwriteEnvExample = (envExampleAbs) => {
|
|
134
|
+
if (!fs.existsSync(envExampleAbs))
|
|
135
|
+
return true;
|
|
136
|
+
const prev = fs.readFileSync(envExampleAbs, 'utf8');
|
|
137
|
+
return prev.includes(GENERATED_MARKER);
|
|
138
|
+
};
|
|
139
|
+
const main = () => {
|
|
140
|
+
try {
|
|
141
|
+
const configDir = path.join(ROOT_DIR, 'src', 'config');
|
|
142
|
+
const configFiles = walkDir(configDir);
|
|
143
|
+
const usages = configFiles.flatMap((f) => parseEnvUsages(readText(f)));
|
|
144
|
+
const keys = uniq(usages.map((u) => u.key));
|
|
145
|
+
if (keys.length === 0) {
|
|
146
|
+
throw ErrorFactory.createTryCatchError('No Env.get usages found under src/config');
|
|
147
|
+
}
|
|
148
|
+
// env.d.ts
|
|
149
|
+
const envDtsPath = path.join(ROOT_DIR, 'env.d.ts');
|
|
150
|
+
writeIfChanged(envDtsPath, renderEnvDts(keys));
|
|
151
|
+
// .env.example (non-destructive by default)
|
|
152
|
+
const envExamplePath = path.join(ROOT_DIR, '.env.example');
|
|
153
|
+
const generatedExamplePath = path.join(ROOT_DIR, '.env.example.generated');
|
|
154
|
+
const renderedExample = renderEnvExample(keys);
|
|
155
|
+
if (shouldOverwriteEnvExample(envExamplePath)) {
|
|
156
|
+
writeIfChanged(envExamplePath, renderedExample);
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
writeIfChanged(generatedExamplePath, renderedExample);
|
|
160
|
+
}
|
|
161
|
+
// .env.keys (for quick discovery / tooling)
|
|
162
|
+
const envKeysPath = path.join(ROOT_DIR, '.env.keys');
|
|
163
|
+
writeIfChanged(envKeysPath, renderEnvKeys(keys));
|
|
164
|
+
Logger.info(`✓ Generated env artifacts (keys: ${keys.length})`);
|
|
165
|
+
}
|
|
166
|
+
catch (error) {
|
|
167
|
+
Logger.error('GenerateEnvArtifacts failed', error);
|
|
168
|
+
process.exit(1);
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
main();
|