@zintrust/core 0.1.19 → 0.1.21
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 +10 -10
- package/bin/zintrust-main.d.ts.map +1 -1
- package/bin/zintrust-main.js +9 -0
- package/package.json +3 -2
- package/public/error-pages/404.html +145 -0
- package/public/error-pages/500.html +266 -0
- package/public/error-pages/error.css +628 -0
- package/public/error-pages/error.js +428 -0
- package/public/zintrust.svg +30 -0
- package/routes/api.d.ts.map +1 -1
- package/routes/api.js +41 -17
- package/routes/metrics.d.ts +9 -0
- package/routes/metrics.d.ts.map +1 -0
- package/routes/metrics.js +20 -0
- package/routes/openapi.d.ts +9 -0
- package/routes/openapi.d.ts.map +1 -0
- package/routes/openapi.js +76 -0
- package/src/boot/Application.d.ts +2 -2
- package/src/boot/Application.d.ts.map +1 -1
- package/src/boot/Application.js +66 -13
- package/src/boot/Server.d.ts +3 -2
- package/src/boot/Server.d.ts.map +1 -1
- package/src/boot/Server.js +39 -165
- package/src/boot/bootstrap.js +2 -0
- package/src/cache/Cache.d.ts +1 -1
- package/src/cache/Cache.d.ts.map +1 -1
- package/src/cache/CacheDriver.d.ts +4 -0
- package/src/cache/CacheDriver.d.ts.map +1 -1
- package/src/cache/drivers/KVDriver.d.ts +1 -1
- package/src/cache/drivers/KVDriver.d.ts.map +1 -1
- package/src/cache/drivers/MemoryDriver.d.ts +1 -1
- package/src/cache/drivers/MemoryDriver.d.ts.map +1 -1
- package/src/cache/drivers/MemoryDriver.js +16 -0
- package/src/cache/drivers/MongoDriver.d.ts +1 -1
- package/src/cache/drivers/MongoDriver.d.ts.map +1 -1
- package/src/cache/drivers/RedisDriver.d.ts +1 -1
- package/src/cache/drivers/RedisDriver.d.ts.map +1 -1
- package/src/cli/CLI.d.ts.map +1 -1
- package/src/cli/CLI.js +10 -4
- package/src/cli/commands/AddCommand.d.ts +2 -2
- package/src/cli/commands/AddCommand.d.ts.map +1 -1
- package/src/cli/commands/AddCommand.js +135 -58
- package/src/cli/commands/ConfigCommand.d.ts +1 -1
- package/src/cli/commands/ConfigCommand.d.ts.map +1 -1
- package/src/cli/commands/CreateCommand.d.ts +15 -0
- package/src/cli/commands/CreateCommand.d.ts.map +1 -0
- package/src/cli/commands/CreateCommand.js +143 -0
- package/src/cli/commands/D1MigrateCommand.d.ts +1 -1
- package/src/cli/commands/D1MigrateCommand.d.ts.map +1 -1
- package/src/cli/commands/D1MigrateCommand.js +16 -20
- package/src/cli/commands/DbSeedCommand.d.ts +9 -0
- package/src/cli/commands/DbSeedCommand.d.ts.map +1 -0
- package/src/cli/commands/DbSeedCommand.js +171 -0
- package/src/cli/commands/DebugCommand.d.ts +1 -1
- package/src/cli/commands/DebugCommand.d.ts.map +1 -1
- package/src/cli/commands/FixCommand.d.ts +1 -1
- package/src/cli/commands/FixCommand.d.ts.map +1 -1
- package/src/cli/commands/JwtDevCommand.d.ts +8 -0
- package/src/cli/commands/JwtDevCommand.d.ts.map +1 -0
- package/src/cli/commands/JwtDevCommand.js +114 -0
- package/src/cli/commands/KeyGenerateCommand.d.ts +1 -1
- package/src/cli/commands/KeyGenerateCommand.d.ts.map +1 -1
- package/src/cli/commands/LogsCommand.d.ts +2 -2
- package/src/cli/commands/LogsCommand.d.ts.map +1 -1
- package/src/cli/commands/LogsCommand.js +36 -2
- package/src/cli/commands/MakeMailTemplateCommand.d.ts +1 -1
- package/src/cli/commands/MakeMailTemplateCommand.d.ts.map +1 -1
- package/src/cli/commands/MakeNotificationTemplateCommand.d.ts +1 -1
- package/src/cli/commands/MakeNotificationTemplateCommand.d.ts.map +1 -1
- package/src/cli/commands/MigrateCommand.d.ts +1 -1
- package/src/cli/commands/MigrateCommand.d.ts.map +1 -1
- package/src/cli/commands/MigrateCommand.js +324 -35
- package/src/cli/commands/NewCommand.d.ts +1 -1
- package/src/cli/commands/NewCommand.d.ts.map +1 -1
- package/src/cli/commands/NewCommand.js +12 -4
- package/src/cli/commands/PluginCommand.d.ts +1 -1
- package/src/cli/commands/PluginCommand.d.ts.map +1 -1
- package/src/cli/commands/PrepareCommand.d.ts +1 -1
- package/src/cli/commands/PrepareCommand.d.ts.map +1 -1
- package/src/cli/commands/QACommand.d.ts +2 -2
- package/src/cli/commands/QACommand.d.ts.map +1 -1
- package/src/cli/commands/RoutesCommand.d.ts +10 -0
- package/src/cli/commands/RoutesCommand.d.ts.map +1 -0
- package/src/cli/commands/RoutesCommand.js +242 -0
- package/src/cli/commands/SimulateCommand.d.ts +1 -1
- package/src/cli/commands/SimulateCommand.d.ts.map +1 -1
- package/src/cli/commands/index.d.ts +3 -0
- package/src/cli/commands/index.d.ts.map +1 -1
- package/src/cli/commands/index.js +3 -0
- package/src/cli/config/ConfigManager.d.ts +1 -1
- package/src/cli/config/ConfigManager.d.ts.map +1 -1
- package/src/cli/config/ConfigValidator.d.ts +1 -1
- package/src/cli/config/ConfigValidator.d.ts.map +1 -1
- package/src/cli/config/ConfigValidator.js +1 -1
- package/src/cli/d1/D1SqlMigrations.d.ts +20 -0
- package/src/cli/d1/D1SqlMigrations.d.ts.map +1 -0
- package/src/cli/d1/D1SqlMigrations.js +229 -0
- package/src/cli/d1/WranglerConfig.d.ts +4 -0
- package/src/cli/d1/WranglerConfig.d.ts.map +1 -0
- package/src/cli/d1/WranglerConfig.js +122 -0
- package/src/cli/d1/WranglerD1.d.ts +11 -0
- package/src/cli/d1/WranglerD1.d.ts.map +1 -0
- package/src/cli/d1/WranglerD1.js +16 -0
- package/src/cli/scaffolding/ControllerGenerator.d.ts.map +1 -1
- package/src/cli/scaffolding/ControllerGenerator.js +76 -26
- package/src/cli/scaffolding/FactoryGenerator.d.ts.map +1 -1
- package/src/cli/scaffolding/FactoryGenerator.js +3 -1
- package/src/cli/scaffolding/GovernanceScaffolder.d.ts +23 -0
- package/src/cli/scaffolding/GovernanceScaffolder.d.ts.map +1 -0
- package/src/cli/scaffolding/GovernanceScaffolder.js +327 -0
- package/src/cli/scaffolding/MigrationGenerator.d.ts +10 -0
- package/src/cli/scaffolding/MigrationGenerator.d.ts.map +1 -1
- package/src/cli/scaffolding/MigrationGenerator.js +137 -51
- package/src/cli/scaffolding/ModelGenerator.js +1 -1
- package/src/cli/scaffolding/ProjectScaffolder.d.ts.map +1 -1
- package/src/cli/scaffolding/ProjectScaffolder.js +36 -4
- package/src/cli/scaffolding/RouteGenerator.d.ts.map +1 -1
- package/src/cli/scaffolding/RouteGenerator.js +79 -43
- package/src/cli/scaffolding/SeederGenerator.d.ts +5 -0
- package/src/cli/scaffolding/SeederGenerator.d.ts.map +1 -1
- package/src/cli/scaffolding/SeederGenerator.js +63 -15
- package/src/cli/scaffolding/ServiceScaffolder.d.ts.map +1 -1
- package/src/cli/scaffolding/ServiceScaffolder.js +28 -7
- package/src/cli/scaffolding/index.d.ts +2 -0
- package/src/cli/scaffolding/index.d.ts.map +1 -1
- package/src/cli/scaffolding/index.js +1 -0
- package/src/common/index.d.ts +8 -0
- package/src/common/index.d.ts.map +1 -1
- package/src/common/index.js +28 -0
- package/src/common/utility.d.ts +38 -0
- package/src/common/utility.d.ts.map +1 -0
- package/src/common/utility.js +101 -0
- package/src/config/FileLogWriter.d.ts +2 -1
- package/src/config/FileLogWriter.d.ts.map +1 -1
- package/src/config/FileLogWriter.js +83 -2
- package/src/config/app.d.ts.map +1 -1
- package/src/config/app.js +3 -1
- package/src/config/broadcast.d.ts +14 -28
- package/src/config/broadcast.d.ts.map +1 -1
- package/src/config/broadcast.js +69 -35
- package/src/config/cache.d.ts +13 -45
- package/src/config/cache.d.ts.map +1 -1
- package/src/config/cache.js +69 -25
- package/src/config/cloudflare.d.ts +1 -1
- package/src/config/cloudflare.d.ts.map +1 -1
- package/src/config/database.d.ts +22 -64
- package/src/config/database.d.ts.map +1 -1
- package/src/config/database.js +191 -37
- package/src/config/env.d.ts +12 -0
- package/src/config/env.d.ts.map +1 -1
- package/src/config/env.js +14 -0
- package/src/config/index.d.ts +33 -137
- package/src/config/index.d.ts.map +1 -1
- package/src/config/logging/KvLogger.js +1 -1
- package/src/config/logging/SlackLogger.js +2 -2
- package/src/config/mail.d.ts +19 -55
- package/src/config/mail.d.ts.map +1 -1
- package/src/config/mail.js +63 -21
- package/src/config/middleware.d.ts +44 -1
- package/src/config/middleware.d.ts.map +1 -1
- package/src/config/middleware.js +157 -5
- package/src/config/notification.d.ts +14 -27
- package/src/config/notification.d.ts.map +1 -1
- package/src/config/notification.js +82 -36
- package/src/config/queue.d.ts +21 -51
- package/src/config/queue.d.ts.map +1 -1
- package/src/config/queue.js +72 -27
- package/src/config/security.d.ts +1 -1
- package/src/config/security.js +1 -1
- package/src/config/storage.d.ts +27 -34
- package/src/config/storage.d.ts.map +1 -1
- package/src/config/storage.js +97 -56
- package/src/config/type.d.ts +13 -2
- package/src/config/type.d.ts.map +1 -1
- package/src/events/EventDispatcher.d.ts.map +1 -1
- package/src/events/EventDispatcher.js +6 -4
- package/src/exceptions/ZintrustError.d.ts +7 -0
- package/src/exceptions/ZintrustError.d.ts.map +1 -1
- package/src/exceptions/ZintrustError.js +56 -0
- package/src/features/Auth.d.ts +1 -1
- package/src/features/Auth.d.ts.map +1 -1
- package/src/features/Auth.js +3 -3
- package/src/features/Queue.js +1 -1
- package/src/functions/cloudflare.d.ts.map +1 -1
- package/src/functions/cloudflare.js +3 -14
- package/src/functions/deno.d.ts.map +1 -1
- package/src/functions/deno.js +3 -14
- package/src/functions/lambda.d.ts.map +1 -1
- package/src/functions/lambda.js +3 -14
- package/src/health/StartupHealthChecks.js +1 -1
- package/src/http/Controller.d.ts +2 -2
- package/src/http/Controller.d.ts.map +1 -1
- package/src/http/FileUpload.d.ts +68 -0
- package/src/http/FileUpload.d.ts.map +1 -0
- package/src/http/FileUpload.js +120 -0
- package/src/http/Kernel.d.ts +5 -5
- package/src/http/Kernel.d.ts.map +1 -1
- package/src/http/Kernel.js +139 -23
- package/src/http/Request.d.ts +20 -1
- package/src/http/Request.d.ts.map +1 -1
- package/src/http/Request.js +23 -0
- package/src/http/RequestContext.d.ts +6 -0
- package/src/http/RequestContext.d.ts.map +1 -1
- package/src/http/RequestContext.js +77 -1
- package/src/http/Response.d.ts +1 -1
- package/src/http/Response.d.ts.map +1 -1
- package/src/http/ValidationHelper.d.ts +78 -0
- package/src/http/ValidationHelper.d.ts.map +1 -0
- package/src/http/ValidationHelper.js +121 -0
- package/src/http/error-pages/ErrorPageRenderer.d.ts +17 -0
- package/src/http/error-pages/ErrorPageRenderer.d.ts.map +1 -0
- package/src/http/error-pages/ErrorPageRenderer.js +88 -0
- package/src/http/middleware/BodyParsingMiddleware.d.ts +12 -0
- package/src/http/middleware/BodyParsingMiddleware.d.ts.map +1 -0
- package/src/http/middleware/BodyParsingMiddleware.js +251 -0
- package/src/http/middleware/FileUploadMiddleware.d.ts +12 -0
- package/src/http/middleware/FileUploadMiddleware.d.ts.map +1 -0
- package/src/http/middleware/FileUploadMiddleware.js +74 -0
- package/src/http/parsers/BodyParsers.d.ts +32 -0
- package/src/http/parsers/BodyParsers.d.ts.map +1 -0
- package/src/http/parsers/BodyParsers.js +159 -0
- package/src/http/parsers/MultipartParser.d.ts +33 -0
- package/src/http/parsers/MultipartParser.d.ts.map +1 -0
- package/src/http/parsers/MultipartParser.js +156 -0
- package/src/http/parsers/MultipartParserRegistry.d.ts +34 -0
- package/src/http/parsers/MultipartParserRegistry.d.ts.map +1 -0
- package/src/http/parsers/MultipartParserRegistry.js +20 -0
- package/src/http/validated.d.ts +12 -0
- package/src/http/validated.d.ts.map +1 -0
- package/src/http/validated.js +41 -0
- package/src/index.d.ts +73 -12
- package/src/index.d.ts.map +1 -1
- package/src/index.js +60 -5
- package/src/microservices/PostgresAdapter.d.ts.map +1 -1
- package/src/microservices/PostgresAdapter.js +0 -1
- package/src/microservices/RequestTracingMiddleware.d.ts +2 -2
- package/src/microservices/RequestTracingMiddleware.d.ts.map +1 -1
- package/src/microservices/RequestTracingMiddleware.js +3 -0
- package/src/microservices/ServiceAuthMiddleware.d.ts +2 -2
- package/src/microservices/ServiceAuthMiddleware.d.ts.map +1 -1
- package/src/middleware/AuthMiddleware.d.ts +10 -0
- package/src/middleware/AuthMiddleware.d.ts.map +1 -0
- package/src/middleware/AuthMiddleware.js +16 -0
- package/src/middleware/CsrfMiddleware.d.ts +11 -1
- package/src/middleware/CsrfMiddleware.d.ts.map +1 -1
- package/src/middleware/CsrfMiddleware.js +33 -0
- package/src/middleware/JwtAuthMiddleware.d.ts +11 -0
- package/src/middleware/JwtAuthMiddleware.d.ts.map +1 -0
- package/src/middleware/JwtAuthMiddleware.js +73 -0
- package/src/middleware/LoggingMiddleware.d.ts.map +1 -1
- package/src/middleware/LoggingMiddleware.js +8 -3
- package/src/middleware/MiddlewareStack.d.ts +2 -2
- package/src/middleware/MiddlewareStack.d.ts.map +1 -1
- package/src/middleware/RateLimiter.d.ts +2 -2
- package/src/middleware/RateLimiter.d.ts.map +1 -1
- package/src/middleware/SanitizeBodyMiddleware.d.ts +12 -0
- package/src/middleware/SanitizeBodyMiddleware.d.ts.map +1 -0
- package/src/middleware/SanitizeBodyMiddleware.js +31 -0
- package/src/middleware/SecurityMiddleware.d.ts +1 -1
- package/src/middleware/SecurityMiddleware.d.ts.map +1 -1
- package/src/middleware/SessionMiddleware.d.ts +1 -1
- package/src/middleware/SessionMiddleware.d.ts.map +1 -1
- package/src/middleware/ValidationMiddleware.d.ts +25 -0
- package/src/middleware/ValidationMiddleware.d.ts.map +1 -0
- package/src/middleware/ValidationMiddleware.js +251 -0
- package/src/migrations/MigrationDiscovery.d.ts +5 -0
- package/src/migrations/MigrationDiscovery.d.ts.map +1 -0
- package/src/migrations/MigrationDiscovery.js +16 -0
- package/src/migrations/MigrationLoader.d.ts +5 -0
- package/src/migrations/MigrationLoader.d.ts.map +1 -0
- package/src/migrations/MigrationLoader.js +43 -0
- package/src/migrations/MigrationLock.d.ts +4 -0
- package/src/migrations/MigrationLock.d.ts.map +1 -0
- package/src/migrations/MigrationLock.js +33 -0
- package/src/migrations/Migrator.d.ts +23 -0
- package/src/migrations/Migrator.d.ts.map +1 -0
- package/src/migrations/Migrator.js +4 -0
- package/src/migrations/MigratorFactory.d.ts +25 -0
- package/src/migrations/MigratorFactory.d.ts.map +1 -0
- package/src/migrations/MigratorFactory.js +339 -0
- package/src/migrations/schema/Blueprint.d.ts +5 -0
- package/src/migrations/schema/Blueprint.d.ts.map +1 -0
- package/src/migrations/schema/Blueprint.js +189 -0
- package/src/migrations/schema/Schema.d.ts +8 -0
- package/src/migrations/schema/Schema.d.ts.map +1 -0
- package/src/migrations/schema/Schema.js +141 -0
- package/src/migrations/schema/SchemaCompiler.d.ts +20 -0
- package/src/migrations/schema/SchemaCompiler.d.ts.map +1 -0
- package/src/migrations/schema/SchemaCompiler.js +262 -0
- package/src/migrations/schema/index.d.ts +5 -0
- package/src/migrations/schema/index.d.ts.map +1 -0
- package/src/migrations/schema/index.js +3 -0
- package/src/migrations/schema/types.d.ts +86 -0
- package/src/migrations/schema/types.d.ts.map +1 -0
- package/src/migrations/schema/types.js +1 -0
- package/src/migrations/types.d.ts +45 -0
- package/src/migrations/types.d.ts.map +1 -0
- package/src/migrations/types.js +1 -0
- package/src/node-singletons/crypto.d.ts +1 -1
- package/src/node-singletons/crypto.d.ts.map +1 -1
- package/src/node-singletons/crypto.js +1 -1
- 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 +1 -1
- package/src/node-singletons/util.d.ts +6 -0
- package/src/node-singletons/util.d.ts.map +1 -0
- package/src/node-singletons/util.js +5 -0
- package/src/node.d.ts +3 -1
- package/src/node.d.ts.map +1 -1
- package/src/node.js +6 -2
- package/src/observability/OpenTelemetry.d.ts +62 -0
- package/src/observability/OpenTelemetry.d.ts.map +1 -0
- package/src/observability/OpenTelemetry.js +167 -0
- package/src/observability/PrometheusMetrics.d.ts +25 -0
- package/src/observability/PrometheusMetrics.d.ts.map +1 -0
- package/src/observability/PrometheusMetrics.js +114 -0
- package/src/openapi/OpenApiGenerator.d.ts +68 -0
- package/src/openapi/OpenApiGenerator.d.ts.map +1 -0
- package/src/openapi/OpenApiGenerator.js +287 -0
- package/src/orm/Database.d.ts +5 -2
- package/src/orm/Database.d.ts.map +1 -1
- package/src/orm/Database.js +219 -63
- package/src/orm/DatabaseAdapter.d.ts +14 -0
- package/src/orm/DatabaseAdapter.d.ts.map +1 -1
- package/src/orm/DatabaseAdapterRegistry.d.ts.map +1 -1
- package/src/orm/DatabaseAdapterRegistry.js +3 -1
- package/src/orm/DatabaseRuntimeRegistration.d.ts.map +1 -1
- package/src/orm/DatabaseRuntimeRegistration.js +12 -0
- package/src/orm/Model.d.ts +30 -2
- package/src/orm/Model.d.ts.map +1 -1
- package/src/orm/Model.js +255 -62
- package/src/orm/QueryBuilder.d.ts +22 -1
- package/src/orm/QueryBuilder.d.ts.map +1 -1
- package/src/orm/QueryBuilder.js +406 -99
- package/src/orm/Relationships.d.ts +7 -1
- package/src/orm/Relationships.d.ts.map +1 -1
- package/src/orm/Relationships.js +18 -0
- package/src/orm/SchemaCompiler.d.ts +9 -0
- package/src/orm/SchemaCompiler.d.ts.map +1 -0
- package/src/orm/SchemaCompiler.js +145 -0
- package/src/orm/adapters/D1Adapter.d.ts +1 -1
- package/src/orm/adapters/D1Adapter.d.ts.map +1 -1
- package/src/orm/adapters/MySQLAdapter.d.ts +1 -1
- package/src/orm/adapters/MySQLAdapter.d.ts.map +1 -1
- package/src/orm/adapters/MySQLAdapter.js +88 -69
- package/src/orm/adapters/PostgreSQLAdapter.d.ts +1 -1
- package/src/orm/adapters/PostgreSQLAdapter.d.ts.map +1 -1
- package/src/orm/adapters/PostgreSQLAdapter.js +88 -69
- package/src/orm/adapters/SQLServerAdapter.d.ts +1 -1
- package/src/orm/adapters/SQLServerAdapter.d.ts.map +1 -1
- package/src/orm/adapters/SQLiteAdapter.d.ts +1 -1
- package/src/orm/adapters/SQLiteAdapter.d.ts.map +1 -1
- package/src/orm/adapters/SQLiteAdapter.js +59 -3
- package/src/orm/maintenance/SqliteMaintenance.d.ts +5 -0
- package/src/orm/maintenance/SqliteMaintenance.d.ts.map +1 -0
- package/src/orm/maintenance/SqliteMaintenance.js +14 -0
- package/src/orm/migrations/MigrationStore.d.ts +38 -0
- package/src/orm/migrations/MigrationStore.d.ts.map +1 -0
- package/src/orm/migrations/MigrationStore.js +157 -0
- package/src/performance/CodeGenerationBenchmark.d.ts.map +1 -1
- package/src/performance/Optimizer.d.ts +7 -6
- package/src/performance/Optimizer.d.ts.map +1 -1
- package/src/performance/Optimizer.js +170 -55
- package/src/profiling/MemoryProfiler.d.ts +1 -1
- package/src/profiling/MemoryProfiler.d.ts.map +1 -1
- package/src/profiling/N1Detector.d.ts +1 -1
- package/src/profiling/N1Detector.d.ts.map +1 -1
- package/src/profiling/QueryLogger.d.ts +1 -1
- package/src/profiling/QueryLogger.d.ts.map +1 -1
- package/src/profiling/RequestProfiler.d.ts +3 -3
- package/src/profiling/RequestProfiler.d.ts.map +1 -1
- package/src/routes/metrics.d.ts +2 -0
- package/src/routes/metrics.d.ts.map +1 -0
- package/src/routes/metrics.js +1 -0
- package/src/routing/CoreRoutes.d.ts +12 -0
- package/src/routing/CoreRoutes.d.ts.map +1 -0
- package/src/routing/CoreRoutes.js +151 -0
- package/src/routing/RouteRegistry.d.ts +39 -0
- package/src/routing/RouteRegistry.d.ts.map +1 -0
- package/src/routing/RouteRegistry.js +44 -0
- package/src/routing/Router.d.ts +26 -9
- package/src/routing/Router.d.ts.map +1 -1
- package/src/routing/Router.js +79 -35
- package/src/routing/common.d.ts +15 -0
- package/src/routing/common.d.ts.map +1 -0
- package/src/routing/common.js +47 -0
- package/src/routing/doc.d.ts +27 -0
- package/src/routing/doc.d.ts.map +1 -0
- package/src/routing/doc.js +110 -0
- package/src/routing/error.d.ts +21 -0
- package/src/routing/error.d.ts.map +1 -0
- package/src/routing/error.js +126 -0
- package/src/routing/errorPages.d.ts +14 -0
- package/src/routing/errorPages.d.ts.map +1 -0
- package/src/routing/errorPages.js +103 -0
- package/src/routing/publicRoot.d.ts +27 -0
- package/src/routing/publicRoot.d.ts.map +1 -0
- package/src/routing/publicRoot.js +110 -0
- package/src/runtime/PluginAutoImports.d.ts +21 -0
- package/src/runtime/PluginAutoImports.d.ts.map +1 -0
- package/src/runtime/PluginAutoImports.js +59 -0
- package/src/runtime/PluginManager.d.ts +1 -5
- package/src/runtime/PluginManager.d.ts.map +1 -1
- package/src/runtime/PluginManager.js +25 -18
- package/src/runtime/RuntimeDetector.d.ts +1 -1
- package/src/runtime/RuntimeDetector.d.ts.map +1 -1
- package/src/runtime/StartupConfigFileRegistry.d.ts +20 -0
- package/src/runtime/StartupConfigFileRegistry.d.ts.map +1 -0
- package/src/runtime/StartupConfigFileRegistry.js +44 -0
- package/src/runtime/adapters/CloudflareAdapter.d.ts +1 -1
- package/src/runtime/adapters/CloudflareAdapter.d.ts.map +1 -1
- package/src/runtime/adapters/CloudflareAdapter.js +1 -1
- package/src/runtime/adapters/DenoAdapter.d.ts +1 -1
- package/src/runtime/adapters/DenoAdapter.d.ts.map +1 -1
- package/src/runtime/adapters/DenoAdapter.js +1 -1
- package/src/runtime/adapters/LambdaAdapter.d.ts +1 -1
- package/src/runtime/adapters/LambdaAdapter.d.ts.map +1 -1
- package/src/runtime/adapters/LambdaAdapter.js +1 -1
- package/src/runtime/adapters/NodeServerAdapter.d.ts +1 -1
- package/src/runtime/adapters/NodeServerAdapter.d.ts.map +1 -1
- package/src/runtime/getKernel.d.ts +9 -0
- package/src/runtime/getKernel.d.ts.map +1 -0
- package/src/runtime/getKernel.js +27 -0
- package/src/runtime/useFileLoader.d.ts +26 -0
- package/src/runtime/useFileLoader.d.ts.map +1 -0
- package/src/runtime/useFileLoader.js +188 -0
- package/src/scripts/TemplateImportsCheck.js +40 -0
- package/src/scripts/TemplateSync.js +90 -24
- package/src/security/Encryptor.d.ts.map +1 -1
- package/src/security/Encryptor.js +64 -7
- package/src/security/JwtManager.d.ts +1 -0
- package/src/security/JwtManager.d.ts.map +1 -1
- package/src/security/JwtManager.js +33 -0
- package/src/security/Sanitizer.d.ts +76 -0
- package/src/security/Sanitizer.d.ts.map +1 -0
- package/src/security/Sanitizer.js +412 -0
- package/src/security/TokenRevocation.d.ts +7 -0
- package/src/security/TokenRevocation.d.ts.map +1 -0
- package/src/security/TokenRevocation.js +57 -0
- package/src/security/XssProtection.d.ts.map +1 -1
- package/src/security/XssProtection.js +62 -14
- package/src/seeders/SeederDiscovery.d.ts +5 -0
- package/src/seeders/SeederDiscovery.d.ts.map +1 -0
- package/src/seeders/SeederDiscovery.js +21 -0
- package/src/seeders/SeederLoader.d.ts +5 -0
- package/src/seeders/SeederLoader.d.ts.map +1 -0
- package/src/seeders/SeederLoader.js +60 -0
- package/src/seeders/types.d.ts +18 -0
- package/src/seeders/types.d.ts.map +1 -0
- package/src/seeders/types.js +1 -0
- package/src/session/SessionManager.js +1 -1
- package/src/templates/adapters/MySQLAdapter.ts.tpl +109 -85
- package/src/templates/adapters/PostgreSQLAdapter.ts.tpl +129 -88
- package/src/templates/adapters/SQLServerAdapter.ts.tpl +5 -9
- package/src/templates/adapters/SQLiteAdapter.ts.tpl +78 -11
- package/src/templates/features/Queue.ts.tpl +3 -2
- package/src/templates/project/basic/app/Controllers/AuthController.ts.tpl +217 -0
- package/src/templates/project/basic/app/Controllers/UserController.ts.tpl +1 -12
- package/src/templates/project/basic/app/Types/controller.ts.tpl +46 -0
- package/src/templates/project/basic/config/FileLogWriter.ts.tpl +5 -236
- package/src/templates/project/basic/config/SecretsManager.ts.tpl +10 -447
- package/src/templates/project/basic/config/StartupConfigValidator.ts.tpl +9 -268
- package/src/templates/project/basic/config/app.ts.tpl +13 -153
- package/src/templates/project/basic/config/broadcast.ts.tpl +29 -126
- package/src/templates/project/basic/config/cache.ts.tpl +12 -70
- package/src/templates/project/basic/config/cloudflare.ts.tpl +4 -39
- package/src/templates/project/basic/config/constants.ts.tpl +9 -65
- package/src/templates/project/basic/config/database.ts.tpl +66 -123
- package/src/templates/project/basic/config/env.ts.tpl +5 -169
- package/src/templates/project/basic/config/features.ts.tpl +6 -54
- package/src/templates/project/basic/config/index.ts.tpl +8 -23
- package/src/templates/project/basic/config/logging/HttpLogger.ts.tpl +7 -114
- package/src/templates/project/basic/config/mail.ts.tpl +9 -62
- package/src/templates/project/basic/config/microservices.ts.tpl +11 -97
- package/src/templates/project/basic/config/middleware.ts.tpl +25 -43
- package/src/templates/project/basic/config/notification.ts.tpl +13 -114
- package/src/templates/project/basic/config/queue.ts.tpl +9 -40
- package/src/templates/project/basic/config/security.ts.tpl +11 -163
- package/src/templates/project/basic/config/startup.ts.tpl +10 -21
- package/src/templates/project/basic/config/storage.ts.tpl +57 -137
- package/src/templates/project/basic/config/type.ts.tpl +32 -451
- package/src/templates/project/basic/database/factories/UserFactory.ts.tpl +80 -0
- package/src/templates/project/basic/database/migrations/create_tasks_table.ts.tpl +28 -0
- package/src/templates/project/basic/database/migrations/create_users_table.ts.tpl +29 -0
- package/src/templates/project/basic/database/seeders/DatabaseSeeder.ts.tpl +19 -0
- package/src/templates/project/basic/database/seeders/UserSeeder.ts.tpl +18 -0
- package/src/templates/project/basic/database/seeders/index.ts.tpl +2 -0
- package/src/templates/project/basic/routes/api.ts.tpl +71 -33
- package/src/templates/project/basic/routes/metrics.ts.tpl +22 -0
- package/src/templates/project/basic/src/index.ts.tpl +3 -0
- package/src/templates/project/basic/tsconfig.json.tpl +12 -11
- package/src/testing/TestEnvironment.d.ts +40 -0
- package/src/testing/TestEnvironment.d.ts.map +1 -0
- package/src/testing/TestEnvironment.js +141 -0
- package/src/testing/TestHttp.d.ts +29 -0
- package/src/testing/TestHttp.d.ts.map +1 -0
- package/src/testing/TestHttp.js +96 -0
- package/src/testing/index.d.ts +5 -0
- package/src/testing/index.d.ts.map +1 -0
- package/src/testing/index.js +2 -0
- package/src/time/DateTime.d.ts +181 -0
- package/src/time/DateTime.d.ts.map +1 -0
- package/src/time/DateTime.js +300 -0
- package/src/time/index.d.ts +7 -0
- package/src/time/index.d.ts.map +1 -0
- package/src/time/index.js +5 -0
- package/src/tools/http/Http.d.ts.map +1 -1
- package/src/tools/http/Http.js +4 -0
- package/src/tools/mail/drivers/Smtp.js +1 -1
- package/src/tools/queue/drivers/InMemory.d.ts +1 -1
- package/src/tools/queue/drivers/InMemory.d.ts.map +1 -1
- package/src/tools/queue/drivers/InMemory.js +1 -1
- package/src/tools/queue/drivers/Redis.d.ts +1 -1
- package/src/tools/queue/drivers/Redis.d.ts.map +1 -1
- package/src/tools/queue/drivers/Redis.js +1 -1
- package/src/validation/ValidationError.d.ts.map +1 -1
- package/src/validation/ValidationError.js +4 -2
- package/src/validation/Validator.d.ts +49 -16
- package/src/validation/Validator.d.ts.map +1 -1
- package/src/validation/Validator.js +307 -5
- package/src/common/uuid.d.ts +0 -3
- package/src/common/uuid.d.ts.map +0 -1
- package/src/common/uuid.js +0 -30
- package/src/templates/project/basic/.env.example.tpl +0 -74
- package/src/templates/project/basic/.env.tpl +0 -166
- package/src/templates/project/basic/config/logging/KvLogger.ts.tpl +0 -181
- package/src/templates/project/basic/config/logging/SlackLogger.ts.tpl +0 -156
- package/src/templates/project/basic/database/migrations/index.ts.tpl +0 -2
|
@@ -1,451 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* Secrets Manager (template)
|
|
3
|
+
*
|
|
4
|
+
* Keep this file declarative:
|
|
5
|
+
* - Core owns runtime secrets logic.
|
|
5
6
|
*/
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
SetSecretOptions,
|
|
8
|
+
export {
|
|
9
|
+
SECRETS,
|
|
10
|
+
SecretsManager,
|
|
11
|
+
getDatabaseCredentials,
|
|
12
|
+
getJwtSecrets,
|
|
13
13
|
} from '@zintrust/core';
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
let instance: SecretsManagerInstance | undefined;
|
|
17
|
-
|
|
18
|
-
function pruneCache(
|
|
19
|
-
cache: Map<string, { value: string; expiresAt: number }>,
|
|
20
|
-
maxEntries: number
|
|
21
|
-
): void {
|
|
22
|
-
if (cache.size <= maxEntries) return;
|
|
23
|
-
|
|
24
|
-
const now = Date.now();
|
|
25
|
-
for (const [key, entry] of cache.entries()) {
|
|
26
|
-
if (entry.expiresAt <= now) cache.delete(key);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// If still large, drop oldest entries (Map preserves insertion order)
|
|
30
|
-
while (cache.size > maxEntries) {
|
|
31
|
-
const next = cache.keys().next();
|
|
32
|
-
if (next.done === true) break;
|
|
33
|
-
cache.delete(next.value);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Get secret value from appropriate backend
|
|
39
|
-
*/
|
|
40
|
-
async function runGetSecret(
|
|
41
|
-
config: SecretConfig,
|
|
42
|
-
cache: Map<string, { value: string; expiresAt: number }>,
|
|
43
|
-
key: string,
|
|
44
|
-
options?: GetSecretOptions
|
|
45
|
-
): Promise<string> {
|
|
46
|
-
// Check cache first
|
|
47
|
-
const cached = cache.get(key);
|
|
48
|
-
if (cached !== undefined && cached.expiresAt > Date.now()) {
|
|
49
|
-
return cached.value;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// Opportunistic cleanup if cache has grown
|
|
53
|
-
pruneCache(cache, 500);
|
|
54
|
-
|
|
55
|
-
let value: string;
|
|
56
|
-
|
|
57
|
-
switch (config.platform) {
|
|
58
|
-
case 'aws':
|
|
59
|
-
value = await getFromAWSSecretsManager(key);
|
|
60
|
-
break;
|
|
61
|
-
case 'cloudflare':
|
|
62
|
-
value = await getFromCloudflareKV(config, key);
|
|
63
|
-
break;
|
|
64
|
-
case 'deno':
|
|
65
|
-
value = await getFromDenoEnv(key);
|
|
66
|
-
break;
|
|
67
|
-
case 'local':
|
|
68
|
-
default:
|
|
69
|
-
value = await getFromEnv(key);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// Cache the value
|
|
73
|
-
const ttl = options?.cacheTtl ?? 3600000; // 1 hour default
|
|
74
|
-
cache.set(key, {
|
|
75
|
-
value,
|
|
76
|
-
expiresAt: Date.now() + ttl,
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
pruneCache(cache, 500);
|
|
80
|
-
|
|
81
|
-
return value;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Set secret value
|
|
86
|
-
*/
|
|
87
|
-
async function runSetSecret(
|
|
88
|
-
config: SecretConfig,
|
|
89
|
-
cache: Map<string, { value: string; expiresAt: number }>,
|
|
90
|
-
key: string,
|
|
91
|
-
value: string,
|
|
92
|
-
options?: SetSecretOptions
|
|
93
|
-
): Promise<void> {
|
|
94
|
-
switch (config.platform) {
|
|
95
|
-
case 'aws':
|
|
96
|
-
await setInAWSSecretsManager(key, value, options);
|
|
97
|
-
break;
|
|
98
|
-
case 'cloudflare':
|
|
99
|
-
await setInCloudflareKV(config, key, value, options);
|
|
100
|
-
break;
|
|
101
|
-
case 'deno':
|
|
102
|
-
throw ErrorFactory.createConfigError('Cannot set secrets in Deno environment');
|
|
103
|
-
case 'local':
|
|
104
|
-
default:
|
|
105
|
-
throw ErrorFactory.createConfigError('Cannot set secrets in local environment');
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// Invalidate cache
|
|
109
|
-
cache.delete(key);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Delete secret
|
|
114
|
-
*/
|
|
115
|
-
async function runDeleteSecret(
|
|
116
|
-
config: SecretConfig,
|
|
117
|
-
cache: Map<string, { value: string; expiresAt: number }>,
|
|
118
|
-
key: string
|
|
119
|
-
): Promise<void> {
|
|
120
|
-
switch (config.platform) {
|
|
121
|
-
case 'aws':
|
|
122
|
-
await deleteFromAWSSecretsManager(key);
|
|
123
|
-
break;
|
|
124
|
-
case 'cloudflare':
|
|
125
|
-
await deleteFromCloudflareKV(config, key);
|
|
126
|
-
break;
|
|
127
|
-
case 'deno':
|
|
128
|
-
case 'local':
|
|
129
|
-
default:
|
|
130
|
-
throw ErrorFactory.createConfigError('Cannot delete secrets in this environment');
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// Invalidate cache
|
|
134
|
-
cache.delete(key);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* SecretsManager implementation
|
|
139
|
-
* Refactored to Functional Object pattern
|
|
140
|
-
*/
|
|
141
|
-
const SecretsManagerImpl = {
|
|
142
|
-
/**
|
|
143
|
-
* Create a new secrets manager instance
|
|
144
|
-
*/
|
|
145
|
-
create(config: SecretConfig): SecretsManagerInstance {
|
|
146
|
-
const cache: Map<string, { value: string; expiresAt: number }> = new Map();
|
|
147
|
-
|
|
148
|
-
return {
|
|
149
|
-
/**
|
|
150
|
-
* Get secret value from appropriate backend
|
|
151
|
-
*/
|
|
152
|
-
async getSecret(key: string, options?: GetSecretOptions): Promise<string> {
|
|
153
|
-
return runGetSecret(config, cache, key, options);
|
|
154
|
-
},
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Set secret value
|
|
158
|
-
*/
|
|
159
|
-
async setSecret(key: string, value: string, options?: SetSecretOptions): Promise<void> {
|
|
160
|
-
return runSetSecret(config, cache, key, value, options);
|
|
161
|
-
},
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* Delete secret
|
|
165
|
-
*/
|
|
166
|
-
async deleteSecret(key: string): Promise<void> {
|
|
167
|
-
return runDeleteSecret(config, cache, key);
|
|
168
|
-
},
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* Rotate secret (trigger new secret generation)
|
|
172
|
-
*/
|
|
173
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
174
|
-
async rotateSecret(_key: string): Promise<void> {
|
|
175
|
-
if (config.platform === 'aws') {
|
|
176
|
-
// AWS Secrets Manager supports automatic rotation
|
|
177
|
-
throw ErrorFactory.createConfigError('Secret rotation not implemented');
|
|
178
|
-
}
|
|
179
|
-
throw ErrorFactory.createConfigError('Secret rotation not supported on this platform');
|
|
180
|
-
},
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Get all secrets matching pattern
|
|
184
|
-
*/
|
|
185
|
-
async listSecrets(pattern?: string): Promise<string[]> {
|
|
186
|
-
switch (config.platform) {
|
|
187
|
-
case 'aws':
|
|
188
|
-
return listFromAWSSecretsManager(pattern);
|
|
189
|
-
case 'cloudflare':
|
|
190
|
-
return listFromCloudflareKV(config, pattern);
|
|
191
|
-
case 'deno':
|
|
192
|
-
case 'local':
|
|
193
|
-
default:
|
|
194
|
-
return [];
|
|
195
|
-
}
|
|
196
|
-
},
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* Clear cache (useful after rotation)
|
|
200
|
-
*/
|
|
201
|
-
clearCache(key?: string): void {
|
|
202
|
-
if (key === undefined) {
|
|
203
|
-
cache.clear();
|
|
204
|
-
} else {
|
|
205
|
-
cache.delete(key);
|
|
206
|
-
}
|
|
207
|
-
},
|
|
208
|
-
};
|
|
209
|
-
},
|
|
210
|
-
};
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* AWS Secrets Manager integration
|
|
214
|
-
*/
|
|
215
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
216
|
-
async function getFromAWSSecretsManager(key: string): Promise<string> {
|
|
217
|
-
try {
|
|
218
|
-
Logger.debug(`[AWS] Getting secret: ${key}`);
|
|
219
|
-
throw ErrorFactory.createConfigError('AWS SDK not available in core - use wrapper module');
|
|
220
|
-
} catch (error) {
|
|
221
|
-
throw ErrorFactory.createTryCatchError(
|
|
222
|
-
`Failed to retrieve secret from AWS: ${(error as Error).message}`,
|
|
223
|
-
error
|
|
224
|
-
);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
229
|
-
async function setInAWSSecretsManager(
|
|
230
|
-
key: string,
|
|
231
|
-
_value: string,
|
|
232
|
-
_options?: SetSecretOptions
|
|
233
|
-
): Promise<void> {
|
|
234
|
-
Logger.info(`[AWS] Setting secret: ${key}`);
|
|
235
|
-
throw ErrorFactory.createConfigError('AWS SDK not available in core - use wrapper module');
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
239
|
-
async function deleteFromAWSSecretsManager(key: string): Promise<void> {
|
|
240
|
-
Logger.info(`[AWS] Deleting secret: ${key}`);
|
|
241
|
-
throw ErrorFactory.createConfigError('AWS SDK not available in core - use wrapper module');
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
245
|
-
async function listFromAWSSecretsManager(pattern?: string): Promise<string[]> {
|
|
246
|
-
Logger.info(`[AWS] Listing secrets with pattern: ${pattern ?? '*'}`);
|
|
247
|
-
return [];
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
/**
|
|
251
|
-
* Cloudflare KV integration
|
|
252
|
-
*/
|
|
253
|
-
async function getFromCloudflareKV(config: SecretConfig, key: string): Promise<string> {
|
|
254
|
-
if (config.kv === undefined) {
|
|
255
|
-
throw ErrorFactory.createConfigError('Cloudflare KV namespace not configured');
|
|
256
|
-
}
|
|
257
|
-
const value = await config.kv.get(key);
|
|
258
|
-
if (value === null || value === '') {
|
|
259
|
-
throw ErrorFactory.createNotFoundError(`Secret not found: ${key}`, { key });
|
|
260
|
-
}
|
|
261
|
-
return value;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
async function setInCloudflareKV(
|
|
265
|
-
config: SecretConfig,
|
|
266
|
-
key: string,
|
|
267
|
-
value: string,
|
|
268
|
-
options?: SetSecretOptions
|
|
269
|
-
): Promise<void> {
|
|
270
|
-
if (config.kv === undefined) {
|
|
271
|
-
throw ErrorFactory.createConfigError('Cloudflare KV namespace not configured');
|
|
272
|
-
}
|
|
273
|
-
const ttl = options?.expirationTtl;
|
|
274
|
-
await config.kv.put(key, value, { expirationTtl: ttl });
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
async function deleteFromCloudflareKV(config: SecretConfig, key: string): Promise<void> {
|
|
278
|
-
if (config.kv === undefined) {
|
|
279
|
-
throw ErrorFactory.createConfigError('Cloudflare KV namespace not configured');
|
|
280
|
-
}
|
|
281
|
-
await config.kv.delete(key);
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
async function listFromCloudflareKV(config: SecretConfig, pattern?: string): Promise<string[]> {
|
|
285
|
-
if (config.kv === undefined) {
|
|
286
|
-
throw ErrorFactory.createConfigError('Cloudflare KV namespace not configured');
|
|
287
|
-
}
|
|
288
|
-
const result = await config.kv.list({ prefix: pattern });
|
|
289
|
-
return result.keys.map((k: { name: string }) => k.name);
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
/**
|
|
293
|
-
* Deno environment integration
|
|
294
|
-
*/
|
|
295
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
296
|
-
async function getFromDenoEnv(key: string): Promise<string> {
|
|
297
|
-
const value = (
|
|
298
|
-
globalThis as unknown as Record<string, { env?: { get?: (key: string) => string } }>
|
|
299
|
-
)['Deno']?.env?.get?.(key);
|
|
300
|
-
if (value === undefined || value === null || value === '') {
|
|
301
|
-
throw ErrorFactory.createNotFoundError(`Secret not found: ${key}`, { key });
|
|
302
|
-
}
|
|
303
|
-
return value;
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
/**
|
|
307
|
-
* Local environment variables (Node.js)
|
|
308
|
-
*/
|
|
309
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
310
|
-
async function getFromEnv(key: string): Promise<string> {
|
|
311
|
-
const value = process.env[key];
|
|
312
|
-
if (value === undefined || value === null || value === '') {
|
|
313
|
-
throw ErrorFactory.createNotFoundError(`Secret not found: ${key}`, { key });
|
|
314
|
-
}
|
|
315
|
-
return value;
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
/**
|
|
319
|
-
* SecretsManager - Unified interface for retrieving secrets
|
|
320
|
-
* Sealed namespace for immutability
|
|
321
|
-
*/
|
|
322
|
-
export const SecretsManager = Object.freeze({
|
|
323
|
-
/**
|
|
324
|
-
* Get or create singleton instance
|
|
325
|
-
*/
|
|
326
|
-
getInstance(config?: SecretConfig): SecretsManagerInstance {
|
|
327
|
-
if (instance === undefined && config !== undefined) {
|
|
328
|
-
instance = SecretsManagerImpl.create(config);
|
|
329
|
-
}
|
|
330
|
-
if (instance === undefined) {
|
|
331
|
-
throw ErrorFactory.createConfigError(
|
|
332
|
-
'SecretsManager not initialized. Call getInstance(config) first.'
|
|
333
|
-
);
|
|
334
|
-
}
|
|
335
|
-
return instance;
|
|
336
|
-
},
|
|
337
|
-
|
|
338
|
-
/**
|
|
339
|
-
* Get secret value from appropriate backend
|
|
340
|
-
*/
|
|
341
|
-
async getSecret(key: string, options?: GetSecretOptions): Promise<string> {
|
|
342
|
-
return this.getInstance().getSecret(key, options);
|
|
343
|
-
},
|
|
344
|
-
|
|
345
|
-
/**
|
|
346
|
-
* Set secret value
|
|
347
|
-
*/
|
|
348
|
-
async setSecret(key: string, value: string, options?: SetSecretOptions): Promise<void> {
|
|
349
|
-
return this.getInstance().setSecret(key, value, options);
|
|
350
|
-
},
|
|
351
|
-
|
|
352
|
-
/**
|
|
353
|
-
* Delete secret
|
|
354
|
-
*/
|
|
355
|
-
async deleteSecret(key: string): Promise<void> {
|
|
356
|
-
return this.getInstance().deleteSecret(key);
|
|
357
|
-
},
|
|
358
|
-
|
|
359
|
-
/**
|
|
360
|
-
* Rotate secret (trigger new secret generation)
|
|
361
|
-
*/
|
|
362
|
-
async rotateSecret(key: string): Promise<void> {
|
|
363
|
-
return this.getInstance().rotateSecret(key);
|
|
364
|
-
},
|
|
365
|
-
|
|
366
|
-
/**
|
|
367
|
-
* Get all secrets matching pattern
|
|
368
|
-
*/
|
|
369
|
-
async listSecrets(pattern?: string): Promise<string[]> {
|
|
370
|
-
return this.getInstance().listSecrets(pattern);
|
|
371
|
-
},
|
|
372
|
-
|
|
373
|
-
/**
|
|
374
|
-
* Clear cache (useful after rotation)
|
|
375
|
-
*/
|
|
376
|
-
clearCache(key?: string): void {
|
|
377
|
-
this.getInstance().clearCache(key);
|
|
378
|
-
},
|
|
379
|
-
});
|
|
380
|
-
|
|
381
|
-
/**
|
|
382
|
-
* Predefined secret keys
|
|
383
|
-
* Sealed namespace for immutability
|
|
384
|
-
*/
|
|
385
|
-
export const SECRETS = Object.freeze({
|
|
386
|
-
// Database credentials
|
|
387
|
-
DB_USERNAME: 'db/username',
|
|
388
|
-
// Secret identifier only (not a credential value)
|
|
389
|
-
DB_PASSWORD: 'db/password', // NOSONAR (typescript:S2068) - secret key name, not hardcoded password
|
|
390
|
-
DB_HOST: 'db/host',
|
|
391
|
-
DB_PORT: 'db/port',
|
|
392
|
-
DB_DATABASE: 'db/database',
|
|
393
|
-
|
|
394
|
-
// API keys
|
|
395
|
-
JWT_SECRET: 'jwt/secret',
|
|
396
|
-
JWT_REFRESH_SECRET: 'jwt/refresh-secret',
|
|
397
|
-
|
|
398
|
-
// Encryption
|
|
399
|
-
ENCRYPTION_KEY: 'encryption/key',
|
|
400
|
-
ENCRYPTION_IV: 'encryption/iv',
|
|
401
|
-
|
|
402
|
-
// Third-party APIs
|
|
403
|
-
STRIPE_API_KEY: 'stripe/api-key',
|
|
404
|
-
STRIPE_WEBHOOK_SECRET: 'stripe/webhook-secret',
|
|
405
|
-
SENDGRID_API_KEY: 'sendgrid/api-key',
|
|
406
|
-
GITHUB_TOKEN: 'github/token',
|
|
407
|
-
|
|
408
|
-
// Session/CSRF
|
|
409
|
-
SESSION_SECRET: 'session/secret',
|
|
410
|
-
CSRF_SECRET: 'csrf/secret',
|
|
411
|
-
} as const);
|
|
412
|
-
|
|
413
|
-
/**
|
|
414
|
-
* Helper to get database credentials using secrets manager
|
|
415
|
-
*/
|
|
416
|
-
export async function getDatabaseCredentials(): Promise<DatabaseCredentials> {
|
|
417
|
-
const manager = SecretsManager.getInstance();
|
|
418
|
-
|
|
419
|
-
return {
|
|
420
|
-
username: await manager.getSecret(SECRETS.DB_USERNAME),
|
|
421
|
-
password: await manager.getSecret(SECRETS.DB_PASSWORD),
|
|
422
|
-
host: await manager.getSecret(SECRETS.DB_HOST),
|
|
423
|
-
port: Number.parseInt(await manager.getSecret(SECRETS.DB_PORT), 10),
|
|
424
|
-
database: await manager.getSecret(SECRETS.DB_DATABASE),
|
|
425
|
-
};
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
/**
|
|
429
|
-
* Helper to get JWT secrets
|
|
430
|
-
*/
|
|
431
|
-
export async function getJwtSecrets(): Promise<JwtSecrets> {
|
|
432
|
-
const manager = SecretsManager.getInstance();
|
|
433
|
-
|
|
434
|
-
return {
|
|
435
|
-
secret: await manager.getSecret(SECRETS.JWT_SECRET),
|
|
436
|
-
refreshSecret: await manager.getSecret(SECRETS.JWT_REFRESH_SECRET),
|
|
437
|
-
};
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
export interface DatabaseCredentials {
|
|
441
|
-
username: string;
|
|
442
|
-
password: string;
|
|
443
|
-
host: string;
|
|
444
|
-
port: number;
|
|
445
|
-
database: string;
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
export interface JwtSecrets {
|
|
449
|
-
secret: string;
|
|
450
|
-
refreshSecret: string;
|
|
451
|
-
}
|
|
14
|
+
export type { DatabaseCredentials, JwtSecrets } from '@zintrust/core';
|