@zintrust/core 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/z.d.ts +7 -0
- package/bin/z.d.ts.map +1 -0
- package/bin/z.js +6 -0
- package/bin/zin.d.ts +7 -0
- package/bin/zin.d.ts.map +1 -0
- package/bin/zin.js +6 -0
- package/bin/zintrust-microservices.d.ts +7 -0
- package/bin/zintrust-microservices.d.ts.map +1 -0
- package/bin/zintrust-microservices.js +165 -0
- package/bin/zintrust.d.ts +9 -0
- package/bin/zintrust.d.ts.map +1 -0
- package/bin/zintrust.js +51 -0
- package/bin/zt.d.ts +7 -0
- package/bin/zt.d.ts.map +1 -0
- package/bin/zt.js +6 -0
- package/package.json +80 -0
- package/src/boot/Application.d.ts +31 -0
- package/src/boot/Application.d.ts.map +1 -0
- package/src/boot/Application.js +159 -0
- package/src/boot/Server.d.ts +23 -0
- package/src/boot/Server.d.ts.map +1 -0
- package/src/boot/Server.js +236 -0
- package/src/boot/bootstrap.d.ts +7 -0
- package/src/boot/bootstrap.d.ts.map +1 -0
- package/src/boot/bootstrap.js +64 -0
- package/src/builder/BundleOptimizer.d.ts +42 -0
- package/src/builder/BundleOptimizer.d.ts.map +1 -0
- package/src/builder/BundleOptimizer.js +356 -0
- package/src/cache/Cache.d.ts +26 -0
- package/src/cache/Cache.d.ts.map +1 -0
- package/src/cache/Cache.js +89 -0
- package/src/cache/CacheDriver.d.ts +28 -0
- package/src/cache/CacheDriver.d.ts.map +1 -0
- package/src/cache/CacheDriver.js +6 -0
- package/src/cache/drivers/KVDriver.d.ts +12 -0
- package/src/cache/drivers/KVDriver.d.ts.map +1 -0
- package/src/cache/drivers/KVDriver.js +54 -0
- package/src/cache/drivers/MemoryDriver.d.ts +12 -0
- package/src/cache/drivers/MemoryDriver.d.ts.map +1 -0
- package/src/cache/drivers/MemoryDriver.js +50 -0
- package/src/cache/drivers/MongoDriver.d.ts +17 -0
- package/src/cache/drivers/MongoDriver.d.ts.map +1 -0
- package/src/cache/drivers/MongoDriver.js +80 -0
- package/src/cache/drivers/RedisDriver.d.ts +12 -0
- package/src/cache/drivers/RedisDriver.d.ts.map +1 -0
- package/src/cache/drivers/RedisDriver.js +79 -0
- package/src/cli/BaseCommand.d.ts +39 -0
- package/src/cli/BaseCommand.d.ts.map +1 -0
- package/src/cli/BaseCommand.js +58 -0
- package/src/cli/CLI.d.ts +21 -0
- package/src/cli/CLI.d.ts.map +1 -0
- package/src/cli/CLI.js +203 -0
- package/src/cli/ErrorHandler.d.ts +23 -0
- package/src/cli/ErrorHandler.d.ts.map +1 -0
- package/src/cli/ErrorHandler.js +95 -0
- package/src/cli/PromptHelper.d.ts +47 -0
- package/src/cli/PromptHelper.d.ts.map +1 -0
- package/src/cli/PromptHelper.js +155 -0
- package/src/cli/commands/AddCommand.d.ts +15 -0
- package/src/cli/commands/AddCommand.d.ts.map +1 -0
- package/src/cli/commands/AddCommand.js +817 -0
- package/src/cli/commands/ConfigCommand.d.ts +15 -0
- package/src/cli/commands/ConfigCommand.d.ts.map +1 -0
- package/src/cli/commands/ConfigCommand.js +273 -0
- package/src/cli/commands/D1MigrateCommand.d.ts +15 -0
- package/src/cli/commands/D1MigrateCommand.d.ts.map +1 -0
- package/src/cli/commands/D1MigrateCommand.js +73 -0
- package/src/cli/commands/DebugCommand.d.ts +15 -0
- package/src/cli/commands/DebugCommand.d.ts.map +1 -0
- package/src/cli/commands/DebugCommand.js +52 -0
- package/src/cli/commands/FixCommand.d.ts +15 -0
- package/src/cli/commands/FixCommand.d.ts.map +1 -0
- package/src/cli/commands/FixCommand.js +80 -0
- package/src/cli/commands/KeyGenerateCommand.d.ts +9 -0
- package/src/cli/commands/KeyGenerateCommand.d.ts.map +1 -0
- package/src/cli/commands/KeyGenerateCommand.js +76 -0
- package/src/cli/commands/LogsCommand.d.ts +19 -0
- package/src/cli/commands/LogsCommand.d.ts.map +1 -0
- package/src/cli/commands/LogsCommand.js +185 -0
- package/src/cli/commands/MigrateCommand.d.ts +15 -0
- package/src/cli/commands/MigrateCommand.d.ts.map +1 -0
- package/src/cli/commands/MigrateCommand.js +56 -0
- package/src/cli/commands/NewCommand.d.ts +32 -0
- package/src/cli/commands/NewCommand.d.ts.map +1 -0
- package/src/cli/commands/NewCommand.js +280 -0
- package/src/cli/commands/PluginCommand.d.ts +9 -0
- package/src/cli/commands/PluginCommand.d.ts.map +1 -0
- package/src/cli/commands/PluginCommand.js +94 -0
- package/src/cli/commands/PrepareCommand.d.ts +8 -0
- package/src/cli/commands/PrepareCommand.d.ts.map +1 -0
- package/src/cli/commands/PrepareCommand.js +51 -0
- package/src/cli/commands/QACommand.d.ts +33 -0
- package/src/cli/commands/QACommand.d.ts.map +1 -0
- package/src/cli/commands/QACommand.js +490 -0
- package/src/cli/commands/SimulateCommand.d.ts +12 -0
- package/src/cli/commands/SimulateCommand.d.ts.map +1 -0
- package/src/cli/commands/SimulateCommand.js +79 -0
- package/src/cli/commands/StartCommand.d.ts +5 -0
- package/src/cli/commands/StartCommand.d.ts.map +1 -0
- package/src/cli/commands/StartCommand.js +227 -0
- package/src/cli/commands/index.d.ts +11 -0
- package/src/cli/commands/index.d.ts.map +1 -0
- package/src/cli/commands/index.js +10 -0
- package/src/cli/config/ConfigManager.d.ts +42 -0
- package/src/cli/config/ConfigManager.d.ts.map +1 -0
- package/src/cli/config/ConfigManager.js +175 -0
- package/src/cli/config/ConfigSchema.d.ts +195 -0
- package/src/cli/config/ConfigSchema.d.ts.map +1 -0
- package/src/cli/config/ConfigSchema.js +171 -0
- package/src/cli/config/ConfigValidator.d.ts +41 -0
- package/src/cli/config/ConfigValidator.d.ts.map +1 -0
- package/src/cli/config/ConfigValidator.js +200 -0
- package/src/cli/config/index.d.ts +8 -0
- package/src/cli/config/index.d.ts.map +1 -0
- package/src/cli/config/index.js +7 -0
- package/src/cli/debug/Dashboard.d.ts +34 -0
- package/src/cli/debug/Dashboard.d.ts.map +1 -0
- package/src/cli/debug/Dashboard.js +152 -0
- package/src/cli/index.d.ts +14 -0
- package/src/cli/index.d.ts.map +1 -0
- package/src/cli/index.js +14 -0
- package/src/cli/logger/Logger.d.ts +43 -0
- package/src/cli/logger/Logger.d.ts.map +1 -0
- package/src/cli/logger/Logger.js +137 -0
- package/src/cli/scaffolding/ControllerGenerator.d.ts +44 -0
- package/src/cli/scaffolding/ControllerGenerator.d.ts.map +1 -0
- package/src/cli/scaffolding/ControllerGenerator.js +540 -0
- package/src/cli/scaffolding/FactoryGenerator.d.ts +47 -0
- package/src/cli/scaffolding/FactoryGenerator.d.ts.map +1 -0
- package/src/cli/scaffolding/FactoryGenerator.js +356 -0
- package/src/cli/scaffolding/FeatureScaffolder.d.ts +40 -0
- package/src/cli/scaffolding/FeatureScaffolder.d.ts.map +1 -0
- package/src/cli/scaffolding/FeatureScaffolder.js +747 -0
- package/src/cli/scaffolding/FileGenerator.d.ts +31 -0
- package/src/cli/scaffolding/FileGenerator.d.ts.map +1 -0
- package/src/cli/scaffolding/FileGenerator.js +222 -0
- package/src/cli/scaffolding/MigrationGenerator.d.ts +35 -0
- package/src/cli/scaffolding/MigrationGenerator.d.ts.map +1 -0
- package/src/cli/scaffolding/MigrationGenerator.js +257 -0
- package/src/cli/scaffolding/ModelGenerator.d.ts +81 -0
- package/src/cli/scaffolding/ModelGenerator.d.ts.map +1 -0
- package/src/cli/scaffolding/ModelGenerator.js +249 -0
- package/src/cli/scaffolding/ProjectScaffolder.d.ts +66 -0
- package/src/cli/scaffolding/ProjectScaffolder.d.ts.map +1 -0
- package/src/cli/scaffolding/ProjectScaffolder.js +439 -0
- package/src/cli/scaffolding/RequestFactoryGenerator.d.ts +50 -0
- package/src/cli/scaffolding/RequestFactoryGenerator.d.ts.map +1 -0
- package/src/cli/scaffolding/RequestFactoryGenerator.js +465 -0
- package/src/cli/scaffolding/ResponseFactoryGenerator.d.ts +43 -0
- package/src/cli/scaffolding/ResponseFactoryGenerator.d.ts.map +1 -0
- package/src/cli/scaffolding/ResponseFactoryGenerator.js +321 -0
- package/src/cli/scaffolding/RouteGenerator.d.ts +66 -0
- package/src/cli/scaffolding/RouteGenerator.d.ts.map +1 -0
- package/src/cli/scaffolding/RouteGenerator.js +306 -0
- package/src/cli/scaffolding/SeederGenerator.d.ts +47 -0
- package/src/cli/scaffolding/SeederGenerator.d.ts.map +1 -0
- package/src/cli/scaffolding/SeederGenerator.js +286 -0
- package/src/cli/scaffolding/ServiceIntegrationTestGenerator.d.ts +40 -0
- package/src/cli/scaffolding/ServiceIntegrationTestGenerator.d.ts.map +1 -0
- package/src/cli/scaffolding/ServiceIntegrationTestGenerator.js +267 -0
- package/src/cli/scaffolding/ServiceRequestFactoryGenerator.d.ts +45 -0
- package/src/cli/scaffolding/ServiceRequestFactoryGenerator.d.ts.map +1 -0
- package/src/cli/scaffolding/ServiceRequestFactoryGenerator.js +397 -0
- package/src/cli/scaffolding/ServiceScaffolder.d.ts +45 -0
- package/src/cli/scaffolding/ServiceScaffolder.d.ts.map +1 -0
- package/src/cli/scaffolding/ServiceScaffolder.js +367 -0
- package/src/cli/scaffolding/TemplateEngine.d.ts +35 -0
- package/src/cli/scaffolding/TemplateEngine.d.ts.map +1 -0
- package/src/cli/scaffolding/TemplateEngine.js +379 -0
- package/src/cli/scaffolding/WorkflowGenerator.d.ts +31 -0
- package/src/cli/scaffolding/WorkflowGenerator.d.ts.map +1 -0
- package/src/cli/scaffolding/WorkflowGenerator.js +193 -0
- package/src/cli/scaffolding/index.d.ts +34 -0
- package/src/cli/scaffolding/index.d.ts.map +1 -0
- package/src/cli/scaffolding/index.js +18 -0
- package/src/cli/utils/DistPackager.d.ts +8 -0
- package/src/cli/utils/DistPackager.d.ts.map +1 -0
- package/src/cli/utils/DistPackager.js +94 -0
- package/src/cli/utils/EnvFileLoader.d.ts +21 -0
- package/src/cli/utils/EnvFileLoader.d.ts.map +1 -0
- package/src/cli/utils/EnvFileLoader.js +166 -0
- package/src/cli/utils/spawn.d.ts +11 -0
- package/src/cli/utils/spawn.d.ts.map +1 -0
- package/src/cli/utils/spawn.js +81 -0
- package/src/common/index.d.ts +87 -0
- package/src/common/index.d.ts.map +1 -0
- package/src/common/index.js +207 -0
- package/src/config/SecretsManager.d.ts +122 -0
- package/src/config/SecretsManager.d.ts.map +1 -0
- package/src/config/SecretsManager.js +328 -0
- package/src/config/app.d.ts +56 -0
- package/src/config/app.d.ts.map +1 -0
- package/src/config/app.js +77 -0
- package/src/config/cache.d.ts +76 -0
- package/src/config/cache.d.ts.map +1 -0
- package/src/config/cache.js +62 -0
- package/src/config/constants.d.ts +108 -0
- package/src/config/constants.d.ts.map +1 -0
- package/src/config/constants.js +64 -0
- package/src/config/database.d.ts +122 -0
- package/src/config/database.d.ts.map +1 -0
- package/src/config/database.js +89 -0
- package/src/config/env.d.ts +56 -0
- package/src/config/env.d.ts.map +1 -0
- package/src/config/env.js +133 -0
- package/src/config/features.d.ts +27 -0
- package/src/config/features.d.ts.map +1 -0
- package/src/config/features.js +49 -0
- package/src/config/index.d.ts +554 -0
- package/src/config/index.d.ts.map +1 -0
- package/src/config/index.js +31 -0
- package/src/config/logger.d.ts +17 -0
- package/src/config/logger.d.ts.map +1 -0
- package/src/config/logger.js +77 -0
- package/src/config/microservices.d.ts +88 -0
- package/src/config/microservices.d.ts.map +1 -0
- package/src/config/microservices.js +90 -0
- package/src/config/queue.d.ts +107 -0
- package/src/config/queue.d.ts.map +1 -0
- package/src/config/queue.js +74 -0
- package/src/config/security.d.ts +108 -0
- package/src/config/security.d.ts.map +1 -0
- package/src/config/security.js +134 -0
- package/src/config/storage.d.ts +105 -0
- package/src/config/storage.d.ts.map +1 -0
- package/src/config/storage.js +79 -0
- package/src/container/ServiceContainer.d.ts +25 -0
- package/src/container/ServiceContainer.d.ts.map +1 -0
- package/src/container/ServiceContainer.js +75 -0
- package/src/database/migrations/index.d.ts +2 -0
- package/src/database/migrations/index.d.ts.map +1 -0
- package/src/database/migrations/index.js +1 -0
- package/src/exceptions/ZintrustError.d.ts +88 -0
- package/src/exceptions/ZintrustError.d.ts.map +1 -0
- package/src/exceptions/ZintrustError.js +110 -0
- package/src/features/Auth.d.ts +20 -0
- package/src/features/Auth.d.ts.map +1 -0
- package/src/features/Auth.js +32 -0
- package/src/features/Queue.d.ts +21 -0
- package/src/features/Queue.d.ts.map +1 -0
- package/src/features/Queue.js +59 -0
- package/src/functions/cloudflare.d.ts +5 -0
- package/src/functions/cloudflare.d.ts.map +1 -0
- package/src/functions/cloudflare.js +34 -0
- package/src/functions/deno.d.ts +3 -0
- package/src/functions/deno.d.ts.map +1 -0
- package/src/functions/deno.js +31 -0
- package/src/functions/lambda.d.ts +2 -0
- package/src/functions/lambda.d.ts.map +1 -0
- package/src/functions/lambda.js +32 -0
- package/src/http/Controller.d.ts +20 -0
- package/src/http/Controller.d.ts.map +1 -0
- package/src/http/Controller.js +46 -0
- package/src/http/Kernel.d.ts +24 -0
- package/src/http/Kernel.d.ts.map +1 -0
- package/src/http/Kernel.js +72 -0
- package/src/http/Request.d.ts +36 -0
- package/src/http/Request.d.ts.map +1 -0
- package/src/http/Request.js +142 -0
- package/src/http/Response.d.ts +32 -0
- package/src/http/Response.d.ts.map +1 -0
- package/src/http/Response.js +70 -0
- package/src/index.d.ts +43 -0
- package/src/index.d.ts.map +1 -0
- package/src/index.js +37 -0
- package/src/microservices/MicroserviceBootstrap.d.ts +75 -0
- package/src/microservices/MicroserviceBootstrap.d.ts.map +1 -0
- package/src/microservices/MicroserviceBootstrap.js +285 -0
- package/src/microservices/MicroserviceGenerator.d.ts +27 -0
- package/src/microservices/MicroserviceGenerator.d.ts.map +1 -0
- package/src/microservices/MicroserviceGenerator.js +436 -0
- package/src/microservices/MicroserviceManager.d.ts +68 -0
- package/src/microservices/MicroserviceManager.d.ts.map +1 -0
- package/src/microservices/MicroserviceManager.js +266 -0
- package/src/microservices/PostgresAdapter.d.ts +90 -0
- package/src/microservices/PostgresAdapter.d.ts.map +1 -0
- package/src/microservices/PostgresAdapter.js +286 -0
- package/src/microservices/RequestTracingMiddleware.d.ts +41 -0
- package/src/microservices/RequestTracingMiddleware.d.ts.map +1 -0
- package/src/microservices/RequestTracingMiddleware.js +122 -0
- package/src/microservices/ServiceAuthMiddleware.d.ts +58 -0
- package/src/microservices/ServiceAuthMiddleware.d.ts.map +1 -0
- package/src/microservices/ServiceAuthMiddleware.js +240 -0
- package/src/microservices/ServiceBundler.d.ts +45 -0
- package/src/microservices/ServiceBundler.d.ts.map +1 -0
- package/src/microservices/ServiceBundler.js +297 -0
- package/src/microservices/ServiceHealthMonitor.d.ts +96 -0
- package/src/microservices/ServiceHealthMonitor.d.ts.map +1 -0
- package/src/microservices/ServiceHealthMonitor.js +379 -0
- package/src/middleware/CsrfMiddleware.d.ts +19 -0
- package/src/middleware/CsrfMiddleware.d.ts.map +1 -0
- package/src/middleware/CsrfMiddleware.js +121 -0
- package/src/middleware/MiddlewareStack.d.ts +27 -0
- package/src/middleware/MiddlewareStack.d.ts.map +1 -0
- package/src/middleware/MiddlewareStack.js +43 -0
- package/src/middleware/RateLimiter.d.ts +22 -0
- package/src/middleware/RateLimiter.d.ts.map +1 -0
- package/src/middleware/RateLimiter.js +72 -0
- package/src/middleware/SecurityMiddleware.d.ts +33 -0
- package/src/middleware/SecurityMiddleware.d.ts.map +1 -0
- package/src/middleware/SecurityMiddleware.js +106 -0
- package/src/middleware/index.d.ts +9 -0
- package/src/middleware/index.d.ts.map +1 -0
- package/src/middleware/index.js +8 -0
- package/src/node-singletons/child-process.d.ts +7 -0
- package/src/node-singletons/child-process.d.ts.map +1 -0
- package/src/node-singletons/child-process.js +6 -0
- package/src/node-singletons/crypto.d.ts +7 -0
- package/src/node-singletons/crypto.d.ts.map +1 -0
- package/src/node-singletons/crypto.js +6 -0
- package/src/node-singletons/events.d.ts +7 -0
- package/src/node-singletons/events.d.ts.map +1 -0
- package/src/node-singletons/events.js +6 -0
- package/src/node-singletons/fs.d.ts +12 -0
- package/src/node-singletons/fs.d.ts.map +1 -0
- package/src/node-singletons/fs.js +14 -0
- package/src/node-singletons/http.d.ts +8 -0
- package/src/node-singletons/http.d.ts.map +1 -0
- package/src/node-singletons/http.js +6 -0
- package/src/node-singletons/index.d.ts +30 -0
- package/src/node-singletons/index.d.ts.map +1 -0
- package/src/node-singletons/index.js +31 -0
- package/src/node-singletons/os.d.ts +9 -0
- package/src/node-singletons/os.d.ts.map +1 -0
- package/src/node-singletons/os.js +9 -0
- package/src/node-singletons/path.d.ts +7 -0
- package/src/node-singletons/path.d.ts.map +1 -0
- package/src/node-singletons/path.js +6 -0
- package/src/node-singletons/perf-hooks.d.ts +7 -0
- package/src/node-singletons/perf-hooks.d.ts.map +1 -0
- package/src/node-singletons/perf-hooks.js +6 -0
- package/src/node-singletons/readline.d.ts +10 -0
- package/src/node-singletons/readline.d.ts.map +1 -0
- package/src/node-singletons/readline.js +9 -0
- package/src/node-singletons/url.d.ts +7 -0
- package/src/node-singletons/url.d.ts.map +1 -0
- package/src/node-singletons/url.js +6 -0
- package/src/orm/ConnectionManager.d.ts +118 -0
- package/src/orm/ConnectionManager.d.ts.map +1 -0
- package/src/orm/ConnectionManager.js +401 -0
- package/src/orm/Database.d.ts +31 -0
- package/src/orm/Database.d.ts.map +1 -0
- package/src/orm/Database.js +163 -0
- package/src/orm/DatabaseAdapter.d.ts +96 -0
- package/src/orm/DatabaseAdapter.d.ts.map +1 -0
- package/src/orm/DatabaseAdapter.js +40 -0
- package/src/orm/Model.d.ts +91 -0
- package/src/orm/Model.d.ts.map +1 -0
- package/src/orm/Model.js +206 -0
- package/src/orm/QueryBuilder.d.ts +52 -0
- package/src/orm/QueryBuilder.d.ts.map +1 -0
- package/src/orm/QueryBuilder.js +134 -0
- package/src/orm/Relationships.d.ts +53 -0
- package/src/orm/Relationships.d.ts.map +1 -0
- package/src/orm/Relationships.js +98 -0
- package/src/orm/Schema.d.ts +123 -0
- package/src/orm/Schema.d.ts.map +1 -0
- package/src/orm/Schema.js +169 -0
- package/src/orm/adapters/D1Adapter.d.ts +15 -0
- package/src/orm/adapters/D1Adapter.d.ts.map +1 -0
- package/src/orm/adapters/D1Adapter.js +125 -0
- package/src/orm/adapters/MySQLAdapter.d.ts +16 -0
- package/src/orm/adapters/MySQLAdapter.d.ts.map +1 -0
- package/src/orm/adapters/MySQLAdapter.js +87 -0
- package/src/orm/adapters/PostgreSQLAdapter.d.ts +16 -0
- package/src/orm/adapters/PostgreSQLAdapter.d.ts.map +1 -0
- package/src/orm/adapters/PostgreSQLAdapter.js +87 -0
- package/src/orm/adapters/SQLServerAdapter.d.ts +16 -0
- package/src/orm/adapters/SQLServerAdapter.d.ts.map +1 -0
- package/src/orm/adapters/SQLServerAdapter.js +81 -0
- package/src/orm/adapters/SQLiteAdapter.d.ts +11 -0
- package/src/orm/adapters/SQLiteAdapter.d.ts.map +1 -0
- package/src/orm/adapters/SQLiteAdapter.js +131 -0
- package/src/performance/Benchmark.d.ts +87 -0
- package/src/performance/Benchmark.d.ts.map +1 -0
- package/src/performance/Benchmark.js +304 -0
- package/src/performance/CodeGenerationBenchmark.d.ts +23 -0
- package/src/performance/CodeGenerationBenchmark.d.ts.map +1 -0
- package/src/performance/CodeGenerationBenchmark.js +249 -0
- package/src/performance/Optimizer.d.ts +99 -0
- package/src/performance/Optimizer.d.ts.map +1 -0
- package/src/performance/Optimizer.js +396 -0
- package/src/performance/establish-baseline.d.ts +9 -0
- package/src/performance/establish-baseline.d.ts.map +1 -0
- package/src/performance/establish-baseline.js +55 -0
- package/src/profiling/MemoryProfiler.d.ts +32 -0
- package/src/profiling/MemoryProfiler.d.ts.map +1 -0
- package/src/profiling/MemoryProfiler.js +84 -0
- package/src/profiling/N1Detector.d.ts +16 -0
- package/src/profiling/N1Detector.d.ts.map +1 -0
- package/src/profiling/N1Detector.js +120 -0
- package/src/profiling/QueryLogger.d.ts +107 -0
- package/src/profiling/QueryLogger.d.ts.map +1 -0
- package/src/profiling/QueryLogger.js +148 -0
- package/src/profiling/RequestProfiler.d.ts +30 -0
- package/src/profiling/RequestProfiler.d.ts.map +1 -0
- package/src/profiling/RequestProfiler.js +94 -0
- package/src/profiling/types.d.ts +77 -0
- package/src/profiling/types.d.ts.map +1 -0
- package/src/profiling/types.js +5 -0
- package/src/routing/Router.d.ts +52 -0
- package/src/routing/Router.d.ts.map +1 -0
- package/src/routing/Router.js +191 -0
- package/src/runtime/PluginManager.d.ts +30 -0
- package/src/runtime/PluginManager.d.ts.map +1 -0
- package/src/runtime/PluginManager.js +197 -0
- package/src/runtime/PluginRegistry.d.ts +22 -0
- package/src/runtime/PluginRegistry.d.ts.map +1 -0
- package/src/runtime/PluginRegistry.js +93 -0
- package/src/runtime/RuntimeAdapter.d.ts +126 -0
- package/src/runtime/RuntimeAdapter.d.ts.map +1 -0
- package/src/runtime/RuntimeAdapter.js +127 -0
- package/src/runtime/RuntimeDetector.d.ts +15 -0
- package/src/runtime/RuntimeDetector.d.ts.map +1 -0
- package/src/runtime/RuntimeDetector.js +219 -0
- package/src/runtime/adapters/CloudflareAdapter.d.ts +43 -0
- package/src/runtime/adapters/CloudflareAdapter.d.ts.map +1 -0
- package/src/runtime/adapters/CloudflareAdapter.js +175 -0
- package/src/runtime/adapters/DenoAdapter.d.ts +30 -0
- package/src/runtime/adapters/DenoAdapter.d.ts.map +1 -0
- package/src/runtime/adapters/DenoAdapter.js +191 -0
- package/src/runtime/adapters/FargateAdapter.d.ts +40 -0
- package/src/runtime/adapters/FargateAdapter.d.ts.map +1 -0
- package/src/runtime/adapters/FargateAdapter.js +156 -0
- package/src/runtime/adapters/LambdaAdapter.d.ts +13 -0
- package/src/runtime/adapters/LambdaAdapter.d.ts.map +1 -0
- package/src/runtime/adapters/LambdaAdapter.js +302 -0
- package/src/runtime/adapters/NodeServerAdapter.d.ts +16 -0
- package/src/runtime/adapters/NodeServerAdapter.d.ts.map +1 -0
- package/src/runtime/adapters/NodeServerAdapter.js +199 -0
- package/src/scripts/TemplateSync.d.ts +7 -0
- package/src/scripts/TemplateSync.d.ts.map +1 -0
- package/src/scripts/TemplateSync.js +234 -0
- package/src/security/CsrfTokenManager.d.ts +28 -0
- package/src/security/CsrfTokenManager.d.ts.map +1 -0
- package/src/security/CsrfTokenManager.js +78 -0
- package/src/security/Encryptor.d.ts +15 -0
- package/src/security/Encryptor.d.ts.map +1 -0
- package/src/security/Encryptor.js +142 -0
- package/src/security/JwtManager.d.ts +41 -0
- package/src/security/JwtManager.d.ts.map +1 -0
- package/src/security/JwtManager.js +229 -0
- package/src/security/UrlValidator.d.ts +21 -0
- package/src/security/UrlValidator.d.ts.map +1 -0
- package/src/security/UrlValidator.js +42 -0
- package/src/security/XssProtection.d.ts +24 -0
- package/src/security/XssProtection.d.ts.map +1 -0
- package/src/security/XssProtection.js +133 -0
- package/src/templates/TemplateRegistry.d.ts +40 -0
- package/src/templates/TemplateRegistry.d.ts.map +1 -0
- package/src/templates/TemplateRegistry.js +78 -0
- package/src/templates/TemplateRegistry.ts +91 -0
- package/src/templates/adapters/MySQLAdapter.ts.tpl +97 -0
- package/src/templates/adapters/PostgreSQLAdapter.ts.tpl +101 -0
- package/src/templates/adapters/SQLServerAdapter.ts.tpl +95 -0
- package/src/templates/adapters/SQLiteAdapter.ts.tpl +189 -0
- package/src/templates/features/Auth.ts.tpl +40 -0
- package/src/templates/features/Queue.ts.tpl +75 -0
- package/src/templates/project/basic/.env.example.tpl +26 -0
- package/src/templates/project/basic/.env.tpl +164 -0
- package/src/templates/project/basic/README.md.tpl +13 -0
- package/src/templates/project/basic/app/Controllers/UserController.ts.tpl +155 -0
- package/src/templates/project/basic/app/Middleware/ProfilerMiddleware.ts.tpl +55 -0
- package/src/templates/project/basic/app/Middleware/index.ts.tpl +304 -0
- package/src/templates/project/basic/app/Models/Post.ts.tpl +30 -0
- package/src/templates/project/basic/app/Models/User.ts.tpl +53 -0
- package/src/templates/project/basic/config/SecretsManager.ts.tpl +453 -0
- package/src/templates/project/basic/config/app.ts.tpl +97 -0
- package/src/templates/project/basic/config/cache.ts.tpl +117 -0
- package/src/templates/project/basic/config/constants.ts.tpl +70 -0
- package/src/templates/project/basic/config/database.ts.tpl +152 -0
- package/src/templates/project/basic/config/env.ts.tpl +148 -0
- package/src/templates/project/basic/config/features.ts.tpl +57 -0
- package/src/templates/project/basic/config/index.ts.tpl +36 -0
- package/src/templates/project/basic/config/logger.ts.tpl +95 -0
- package/src/templates/project/basic/config/microservices.ts.tpl +104 -0
- package/src/templates/project/basic/config/queue.ts.tpl +134 -0
- package/src/templates/project/basic/config/security.ts.tpl +149 -0
- package/src/templates/project/basic/config/storage.ts.tpl +136 -0
- package/src/templates/project/basic/database/factories/.gitkeep.tpl +0 -0
- package/src/templates/project/basic/database/migrations/.gitkeep.tpl +0 -0
- package/src/templates/project/basic/database/migrations/index.ts.tpl +2 -0
- package/src/templates/project/basic/database/seeders/.gitkeep.tpl +0 -0
- package/src/templates/project/basic/package.json.tpl +22 -0
- package/src/templates/project/basic/routes/api.ts.tpl +135 -0
- package/src/templates/project/basic/src/index.ts.tpl +49 -0
- package/src/templates/project/basic/template.json +17 -0
- package/src/templates/project/basic/tsconfig.json.tpl +20 -0
- package/src/validation/ValidationError.d.ts +42 -0
- package/src/validation/ValidationError.d.ts.map +1 -0
- package/src/validation/ValidationError.js +53 -0
- package/src/validation/Validator.d.ts +60 -0
- package/src/validation/Validator.d.ts.map +1 -0
- package/src/validation/Validator.js +190 -0
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
# ============================================================================
|
|
2
|
+
# Zintrust Framework - Environment Configuration
|
|
3
|
+
# Generated from src/config/env.ts - All available configuration keys
|
|
4
|
+
# ============================================================================
|
|
5
|
+
|
|
6
|
+
# ============================================================================
|
|
7
|
+
# APPLICATION
|
|
8
|
+
# ============================================================================
|
|
9
|
+
|
|
10
|
+
# Environment: development | staging | production
|
|
11
|
+
NODE_ENV=development
|
|
12
|
+
|
|
13
|
+
# Server Configuration
|
|
14
|
+
HOST=127.0.0.1
|
|
15
|
+
APP_PORT=7777
|
|
16
|
+
APP_NAME={{projectName}}
|
|
17
|
+
APP_KEY=
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
# ============================================================================
|
|
21
|
+
# LOGGING
|
|
22
|
+
# ============================================================================
|
|
23
|
+
|
|
24
|
+
# Log Level: debug | info | warn | error
|
|
25
|
+
LOG_LEVEL=debug
|
|
26
|
+
DISABLE_LOGGING=true
|
|
27
|
+
LOG_CHANNEL=file
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
# ============================================================================
|
|
31
|
+
# DATABASE
|
|
32
|
+
# ============================================================================
|
|
33
|
+
|
|
34
|
+
# Database Connection Driver
|
|
35
|
+
# Options: sqlite | postgresql | mysql | sqlserver | d1
|
|
36
|
+
DB_CONNECTION=sqlite
|
|
37
|
+
|
|
38
|
+
# SQLite Configuration
|
|
39
|
+
DB_PATH=./storage/db.sqlite
|
|
40
|
+
|
|
41
|
+
# PostgreSQL Configuration
|
|
42
|
+
DB_HOST=localhost
|
|
43
|
+
DB_PORT=5432
|
|
44
|
+
DB_DATABASE=zintrust
|
|
45
|
+
DB_USERNAME=postgres
|
|
46
|
+
DB_PASSWORD=
|
|
47
|
+
DB_READ_HOSTS=
|
|
48
|
+
|
|
49
|
+
# ============================================================================
|
|
50
|
+
# CLOUDFLARE
|
|
51
|
+
# ============================================================================
|
|
52
|
+
|
|
53
|
+
D1_DATABASE_ID=
|
|
54
|
+
KV_NAMESPACE_ID=
|
|
55
|
+
|
|
56
|
+
# ============================================================================
|
|
57
|
+
# CACHE
|
|
58
|
+
# ============================================================================
|
|
59
|
+
|
|
60
|
+
# Cache Driver: memory | redis | memcached
|
|
61
|
+
CACHE_DRIVER=memory
|
|
62
|
+
|
|
63
|
+
# Redis Configuration
|
|
64
|
+
REDIS_HOST=localhost
|
|
65
|
+
REDIS_PORT=6379
|
|
66
|
+
REDIS_PASSWORD=
|
|
67
|
+
|
|
68
|
+
# MongoDB Cache Configuration
|
|
69
|
+
MONGO_URI=
|
|
70
|
+
MONGO_DB=zintrust_cache
|
|
71
|
+
|
|
72
|
+
# ============================================================================
|
|
73
|
+
# AWS
|
|
74
|
+
# ============================================================================
|
|
75
|
+
|
|
76
|
+
AWS_REGION=us-east-1
|
|
77
|
+
AWS_LAMBDA_FUNCTION_NAME=
|
|
78
|
+
AWS_LAMBDA_FUNCTION_VERSION=
|
|
79
|
+
AWS_EXECUTION_ENV=
|
|
80
|
+
LAMBDA_TASK_ROOT=
|
|
81
|
+
|
|
82
|
+
# ============================================================================
|
|
83
|
+
# MICROSERVICES
|
|
84
|
+
# ============================================================================
|
|
85
|
+
|
|
86
|
+
MICROSERVICES=
|
|
87
|
+
SERVICES=
|
|
88
|
+
MICROSERVICES_TRACING=false
|
|
89
|
+
MICROSERVICES_TRACING_RATE=1.0
|
|
90
|
+
DATABASE_ISOLATION=shared
|
|
91
|
+
SERVICE_API_KEY=
|
|
92
|
+
SERVICE_JWT_SECRET=
|
|
93
|
+
|
|
94
|
+
# ============================================================================
|
|
95
|
+
# SECURITY
|
|
96
|
+
# ============================================================================
|
|
97
|
+
|
|
98
|
+
DEBUG=false
|
|
99
|
+
ENABLE_MICROSERVICES=false
|
|
100
|
+
TOKEN_TTL=3600000
|
|
101
|
+
TOKEN_LENGTH=32
|
|
102
|
+
|
|
103
|
+
# JWT Secret for authentication
|
|
104
|
+
JWT_SECRET=
|
|
105
|
+
|
|
106
|
+
# Session Configuration
|
|
107
|
+
SESSION_DRIVER=cookie
|
|
108
|
+
SESSION_LIFETIME=7200
|
|
109
|
+
|
|
110
|
+
# CORS Configuration
|
|
111
|
+
CORS_ORIGINS=http://localhost:3000,http://localhost:5173
|
|
112
|
+
|
|
113
|
+
# ============================================================================
|
|
114
|
+
# DEPLOYMENT
|
|
115
|
+
# ============================================================================
|
|
116
|
+
|
|
117
|
+
ENVIRONMENT=development
|
|
118
|
+
REQUEST_TIMEOUT=30000
|
|
119
|
+
MAX_BODY_SIZE=10485760
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
# ============================================================================
|
|
123
|
+
# EXTERNAL SERVICES & CREDENTIALS
|
|
124
|
+
# ============================================================================
|
|
125
|
+
|
|
126
|
+
SONAR_ORGANIZATION="zintrust"
|
|
127
|
+
SONAR_PROJECT_ID="ZinTrust_ZinTrust"
|
|
128
|
+
SONAR_HOST_URL="https://sonarcloud.io"
|
|
129
|
+
SONAR_TOKEN=
|
|
130
|
+
|
|
131
|
+
# Cloudflare Workspace-Specific Credentials
|
|
132
|
+
CLOUDFLARE_API_TOKEN=
|
|
133
|
+
CLOUDFLARE_ACCOUNT_ID=""
|
|
134
|
+
|
|
135
|
+
CODECOV_TOKEN=
|
|
136
|
+
|
|
137
|
+
# Security Scanning
|
|
138
|
+
SNYK_TOKEN=
|
|
139
|
+
|
|
140
|
+
# Email (SendGrid)
|
|
141
|
+
SENDGRID_API_KEY=
|
|
142
|
+
|
|
143
|
+
# Payments (Stripe)
|
|
144
|
+
STRIPE_SECRET_KEY=
|
|
145
|
+
STRIPE_PUBLIC_KEY=
|
|
146
|
+
|
|
147
|
+
# Cloud Storage (AWS S3)
|
|
148
|
+
AWS_ACCESS_KEY_ID=
|
|
149
|
+
AWS_SECRET_ACCESS_KEY=
|
|
150
|
+
AWS_BUCKET=
|
|
151
|
+
|
|
152
|
+
# ============================================================================
|
|
153
|
+
# DEVELOPMENT
|
|
154
|
+
# ============================================================================
|
|
155
|
+
|
|
156
|
+
# Database Synchronization (auto-migrate on startup)
|
|
157
|
+
DB_SYNCHRONIZE=true
|
|
158
|
+
|
|
159
|
+
# Database Logging
|
|
160
|
+
DB_LOGGING=false
|
|
161
|
+
|
|
162
|
+
# Raw SQL Query Support (development only)
|
|
163
|
+
# WARNING: Only enable in development. Bypasses QueryBuilder safety.
|
|
164
|
+
USE_RAW_QRY=false
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* User Controller
|
|
3
|
+
* Example controller demonstrating request handling
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { User } from '@app/Models/User';
|
|
7
|
+
import { Logger } from '@config/logger';
|
|
8
|
+
import { type IRequest, type IResponse } from '@zintrust/core';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* User Controller Interface
|
|
12
|
+
*/
|
|
13
|
+
export interface IUserController {
|
|
14
|
+
index(req: IRequest, res: IResponse): Promise<void>;
|
|
15
|
+
show(req: IRequest, res: IResponse): Promise<void>;
|
|
16
|
+
create(req: IRequest, res: IResponse): Promise<void>;
|
|
17
|
+
store(req: IRequest, res: IResponse): Promise<void>;
|
|
18
|
+
edit(req: IRequest, res: IResponse): Promise<void>;
|
|
19
|
+
update(req: IRequest, res: IResponse): Promise<void>;
|
|
20
|
+
destroy(req: IRequest, res: IResponse): Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* User Controller Methods
|
|
25
|
+
*/
|
|
26
|
+
const userControllerMethods: IUserController = {
|
|
27
|
+
/**
|
|
28
|
+
* List all users
|
|
29
|
+
* GET /users
|
|
30
|
+
*/
|
|
31
|
+
async index(_req: IRequest, res: IResponse): Promise<void> {
|
|
32
|
+
try {
|
|
33
|
+
const users = await User.all();
|
|
34
|
+
res.json({ data: users });
|
|
35
|
+
} catch (error) {
|
|
36
|
+
Logger.error('Error fetching users:', error);
|
|
37
|
+
res.status(500).json({ error: 'Failed to fetch users' });
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Show a specific user
|
|
43
|
+
* GET /users/:id
|
|
44
|
+
*/
|
|
45
|
+
async show(req: IRequest, res: IResponse): Promise<void> {
|
|
46
|
+
try {
|
|
47
|
+
const id = req.params['id'];
|
|
48
|
+
const user = await User.find(id);
|
|
49
|
+
if (user === null) {
|
|
50
|
+
res.status(404).json({ error: 'User not found' });
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
res.json({ data: user });
|
|
54
|
+
} catch (error) {
|
|
55
|
+
Logger.error('Error fetching user:', error);
|
|
56
|
+
res.status(500).json({ error: 'Failed to fetch user' });
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Show create form
|
|
62
|
+
* GET /users/create
|
|
63
|
+
*/
|
|
64
|
+
async create(_req: IRequest, res: IResponse): Promise<void> {
|
|
65
|
+
res.json({ form: 'Create User Form' });
|
|
66
|
+
},
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Store a new user
|
|
70
|
+
* POST /users
|
|
71
|
+
*/
|
|
72
|
+
async store(req: IRequest, res: IResponse): Promise<void> {
|
|
73
|
+
try {
|
|
74
|
+
const body = req.body;
|
|
75
|
+
if (typeof body['name'] !== 'string' || !body['name']) {
|
|
76
|
+
res.status(422).json({ error: 'Name is required' });
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const user = User.create(body);
|
|
80
|
+
res.status(201).json({ message: 'User created', user });
|
|
81
|
+
} catch (error) {
|
|
82
|
+
Logger.error('Error creating user:', error);
|
|
83
|
+
res.status(500).json({ error: 'Failed to create user' });
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Show edit form
|
|
89
|
+
* GET /users/:id/edit
|
|
90
|
+
*/
|
|
91
|
+
async edit(_req: IRequest, res: IResponse): Promise<void> {
|
|
92
|
+
try {
|
|
93
|
+
res.json({ form: 'Edit User Form' });
|
|
94
|
+
} catch (error) {
|
|
95
|
+
Logger.error('Error loading edit form:', error);
|
|
96
|
+
res.status(500).json({ error: 'Failed to load edit form' });
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Update a user
|
|
102
|
+
* PUT /users/:id
|
|
103
|
+
*/
|
|
104
|
+
async update(req: IRequest, res: IResponse): Promise<void> {
|
|
105
|
+
try {
|
|
106
|
+
const id = req.params['id'];
|
|
107
|
+
const user = await User.find(id);
|
|
108
|
+
if (user === null) {
|
|
109
|
+
res.status(404).json({ error: 'User not found' });
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
const body = req.body;
|
|
113
|
+
user.fill(body);
|
|
114
|
+
await user.save();
|
|
115
|
+
res.json({ message: 'User updated', user });
|
|
116
|
+
} catch (error) {
|
|
117
|
+
Logger.error('Error updating user:', error);
|
|
118
|
+
res.status(500).json({ error: 'Failed to update user' });
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Delete a user
|
|
124
|
+
* DELETE /users/:id
|
|
125
|
+
*/
|
|
126
|
+
async destroy(req: IRequest, res: IResponse): Promise<void> {
|
|
127
|
+
try {
|
|
128
|
+
const id = req.params['id'];
|
|
129
|
+
const user = await User.find(id);
|
|
130
|
+
if (user === null) {
|
|
131
|
+
res.status(404).json({ error: 'User not found' });
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
await user.delete();
|
|
135
|
+
res.json({ message: 'User deleted' });
|
|
136
|
+
} catch (error) {
|
|
137
|
+
Logger.error('Error deleting user:', error);
|
|
138
|
+
res.status(500).json({ error: 'Failed to delete user' });
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* User Controller Factory
|
|
145
|
+
*/
|
|
146
|
+
export const UserController = {
|
|
147
|
+
/**
|
|
148
|
+
* Create a new user controller instance
|
|
149
|
+
*/
|
|
150
|
+
create(): IUserController {
|
|
151
|
+
return userControllerMethods;
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
export default UserController;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// @ts-nocheck - Example middleware - WIP
|
|
2
|
+
/**
|
|
3
|
+
* Profiler Middleware
|
|
4
|
+
* Enables request profiling when ENABLE_PROFILER environment variable is set
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { Logger } from '@config/logger';
|
|
8
|
+
import { type Middleware, RequestProfiler } from '@zintrust/core';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* ProfilerMiddleware wraps request execution with performance profiling
|
|
12
|
+
* Enabled via ENABLE_PROFILER=true environment variable
|
|
13
|
+
* Attaches profiling report to response headers
|
|
14
|
+
*/
|
|
15
|
+
export const ProfilerMiddleware: Middleware = async (req, res, next) => {
|
|
16
|
+
const isEnabled = process.env.ENABLE_PROFILER === 'true';
|
|
17
|
+
|
|
18
|
+
if (!isEnabled) {
|
|
19
|
+
// Pass through without profiling
|
|
20
|
+
await next();
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const profiler = RequestProfiler.create();
|
|
25
|
+
const queryLogger = profiler.getQueryLogger();
|
|
26
|
+
|
|
27
|
+
// Set up query logging if database is available
|
|
28
|
+
const db = req.context.db;
|
|
29
|
+
if (db !== undefined && db !== null && typeof db.onAfterQuery === 'function') {
|
|
30
|
+
db.onAfterQuery((sql: string, params: unknown[], duration: number) => {
|
|
31
|
+
queryLogger.logQuery(sql, params, duration, 'middleware-profiling');
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Capture request execution
|
|
36
|
+
const profile = await profiler.captureRequest(async () => next());
|
|
37
|
+
|
|
38
|
+
// Attach profile to response
|
|
39
|
+
res.locals.profile = profile;
|
|
40
|
+
|
|
41
|
+
// Add profiling report to response header
|
|
42
|
+
try {
|
|
43
|
+
const report = profiler.generateReport(profile);
|
|
44
|
+
res.setHeader('X-Profiler-Report', Buffer.from(report).toString('base64'));
|
|
45
|
+
res.setHeader('X-Profiler-Queries', profile.queriesExecuted.toString());
|
|
46
|
+
res.setHeader('X-Profiler-Duration', profile.duration.toString());
|
|
47
|
+
|
|
48
|
+
if (profile.n1Patterns.length > 0) {
|
|
49
|
+
res.setHeader('X-Profiler-N1-Patterns', profile.n1Patterns.length.toString());
|
|
50
|
+
}
|
|
51
|
+
} catch (error) {
|
|
52
|
+
// Silently fail if header encoding fails
|
|
53
|
+
Logger.error('Failed to encode profiler report header:', error);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type CsrfTokenManagerType,
|
|
3
|
+
type ICsrfTokenManager,
|
|
4
|
+
type IJwtManager,
|
|
5
|
+
type JwtAlgorithm,
|
|
6
|
+
type JwtManagerType,
|
|
7
|
+
type IRequest,
|
|
8
|
+
type IResponse,
|
|
9
|
+
XssProtection,
|
|
10
|
+
type ISchema,
|
|
11
|
+
type SchemaType,
|
|
12
|
+
Validator,
|
|
13
|
+
} from '@zintrust/core';
|
|
14
|
+
/**
|
|
15
|
+
* Example Middleware
|
|
16
|
+
* Common middleware patterns for Zintrust
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { Logger } from '@config/logger';
|
|
20
|
+
|
|
21
|
+
type JwtManagerInput = IJwtManager | JwtManagerType;
|
|
22
|
+
type CsrfManagerInput = ICsrfTokenManager | CsrfTokenManagerType;
|
|
23
|
+
|
|
24
|
+
const resolveJwtManager = (jwtManager: JwtManagerInput): IJwtManager =>
|
|
25
|
+
'verify' in jwtManager ? jwtManager : jwtManager.create();
|
|
26
|
+
|
|
27
|
+
const resolveCsrfManager = (csrfManager: CsrfManagerInput): ICsrfTokenManager =>
|
|
28
|
+
'validateToken' in csrfManager ? csrfManager : csrfManager.create();
|
|
29
|
+
|
|
30
|
+
type ValidationSchema = ISchema | SchemaType;
|
|
31
|
+
|
|
32
|
+
const resolveSchema = (schema: ValidationSchema): ISchema =>
|
|
33
|
+
'getRules' in schema ? schema : schema.create();
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Authentication Middleware
|
|
37
|
+
* Verify user is authenticated
|
|
38
|
+
*/
|
|
39
|
+
export const authMiddleware = async (
|
|
40
|
+
req: IRequest,
|
|
41
|
+
res: IResponse,
|
|
42
|
+
next: () => Promise<void>
|
|
43
|
+
): Promise<void> => {
|
|
44
|
+
const token = req.getHeader('authorization');
|
|
45
|
+
|
|
46
|
+
if (token === undefined || token === '') {
|
|
47
|
+
res.setStatus(401).json({ error: 'Unauthorized' });
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
await next();
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* CORS Middleware
|
|
56
|
+
* Handle CORS headers
|
|
57
|
+
*/
|
|
58
|
+
export const corsMiddleware = async (
|
|
59
|
+
req: IRequest,
|
|
60
|
+
res: IResponse,
|
|
61
|
+
next: () => Promise<void>
|
|
62
|
+
): Promise<void> => {
|
|
63
|
+
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
64
|
+
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, PATCH, DELETE, OPTIONS');
|
|
65
|
+
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
|
|
66
|
+
|
|
67
|
+
if (req.getMethod() === 'OPTIONS') {
|
|
68
|
+
res.setStatus(200).send('');
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
await next();
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* JSON Request Middleware
|
|
77
|
+
* Parse JSON request bodies
|
|
78
|
+
*/
|
|
79
|
+
export const jsonMiddleware = async (
|
|
80
|
+
req: IRequest,
|
|
81
|
+
res: IResponse,
|
|
82
|
+
next: () => Promise<void>
|
|
83
|
+
): Promise<void> => {
|
|
84
|
+
if (req.getMethod() === 'GET' || req.getMethod() === 'DELETE') {
|
|
85
|
+
await next();
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (req.isJson() === false) {
|
|
90
|
+
res.setStatus(415).json({ error: 'Content-Type must be application/json' });
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
await next();
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Logging Middleware
|
|
99
|
+
* Log all requests
|
|
100
|
+
*/
|
|
101
|
+
export const loggingMiddleware = async (
|
|
102
|
+
req: IRequest,
|
|
103
|
+
res: IResponse,
|
|
104
|
+
next: () => Promise<void>
|
|
105
|
+
): Promise<void> => {
|
|
106
|
+
const startTime = Date.now();
|
|
107
|
+
const method = req.getMethod();
|
|
108
|
+
const path = req.getPath();
|
|
109
|
+
|
|
110
|
+
Logger.info(`→ ${method} ${path}`);
|
|
111
|
+
|
|
112
|
+
await next();
|
|
113
|
+
|
|
114
|
+
const duration = Date.now() - startTime;
|
|
115
|
+
const status = res.getStatus();
|
|
116
|
+
Logger.info(`← ${status} ${method} ${path} (${duration}ms)`);
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Rate Limiting Middleware
|
|
121
|
+
* Simple in-memory rate limiting
|
|
122
|
+
*/
|
|
123
|
+
const requestCounts = new Map<string, number[]>();
|
|
124
|
+
|
|
125
|
+
export const rateLimitMiddleware = async (
|
|
126
|
+
req: IRequest,
|
|
127
|
+
res: IResponse,
|
|
128
|
+
next: () => Promise<void>
|
|
129
|
+
): Promise<void> => {
|
|
130
|
+
const ip = req.getRaw().socket.remoteAddress ?? 'unknown';
|
|
131
|
+
const now = Date.now();
|
|
132
|
+
const windowMs = 60 * 1000; // 1 minute
|
|
133
|
+
const maxRequests = 100;
|
|
134
|
+
|
|
135
|
+
if (requestCounts.has(ip) === false) {
|
|
136
|
+
requestCounts.set(ip, []);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const requests = requestCounts.get(ip) ?? [];
|
|
140
|
+
const recentRequests = requests.filter((time) => now - time < windowMs);
|
|
141
|
+
|
|
142
|
+
if (recentRequests.length >= maxRequests) {
|
|
143
|
+
res.setStatus(429).json({ error: 'Too many requests' });
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
recentRequests.push(now);
|
|
148
|
+
requestCounts.set(ip, recentRequests);
|
|
149
|
+
|
|
150
|
+
await next();
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Trailing Slash Middleware
|
|
155
|
+
* Redirect URLs with trailing slashes
|
|
156
|
+
*/
|
|
157
|
+
export const trailingSlashMiddleware = async (
|
|
158
|
+
req: IRequest,
|
|
159
|
+
res: IResponse,
|
|
160
|
+
next: () => Promise<void>
|
|
161
|
+
): Promise<void> => {
|
|
162
|
+
const path = req.getPath();
|
|
163
|
+
|
|
164
|
+
if (path.length > 1 && path.endsWith('/') === true) {
|
|
165
|
+
const withoutSlash = path.slice(0, -1);
|
|
166
|
+
res.redirect(withoutSlash, 301);
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
await next();
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* JWT Authentication Middleware
|
|
175
|
+
* Verify JWT token and extract claims
|
|
176
|
+
*/
|
|
177
|
+
export const jwtMiddleware = (jwtManager: JwtManagerInput, algorithm: JwtAlgorithm = 'HS256') => {
|
|
178
|
+
return async (req: IRequest, res: IResponse, next: () => Promise<void>): Promise<void> => {
|
|
179
|
+
const authHeader = req.getHeader('authorization');
|
|
180
|
+
|
|
181
|
+
if (authHeader === undefined || authHeader === '') {
|
|
182
|
+
res.setStatus(401).json({ error: 'Missing authorization header' });
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const authHeaderStr = Array.isArray(authHeader) ? authHeader[0] : authHeader;
|
|
187
|
+
const [scheme, token] = authHeaderStr.split(' ');
|
|
188
|
+
|
|
189
|
+
if (scheme !== 'Bearer' || token === undefined || token === '') {
|
|
190
|
+
res.setStatus(401).json({ error: 'Invalid authorization header format' });
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
try {
|
|
195
|
+
const payload = resolveJwtManager(jwtManager).verify(token, algorithm);
|
|
196
|
+
// Store in request context (TypeScript allows dynamic properties)
|
|
197
|
+
req.user = payload;
|
|
198
|
+
await next();
|
|
199
|
+
} catch (error) {
|
|
200
|
+
Logger.error('JWT verification failed:', error);
|
|
201
|
+
res.setStatus(401).json({ error: 'Invalid or expired token' });
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* CSRF Protection Middleware
|
|
208
|
+
* Validate CSRF tokens for state-changing requests
|
|
209
|
+
*/
|
|
210
|
+
export const csrfMiddleware = (csrfManager: CsrfManagerInput) => {
|
|
211
|
+
return async (req: IRequest, res: IResponse, next: () => Promise<void>): Promise<void> => {
|
|
212
|
+
const method = req.getMethod();
|
|
213
|
+
|
|
214
|
+
// Only validate on state-changing requests
|
|
215
|
+
if (['POST', 'PUT', 'PATCH', 'DELETE'].includes(method) === false) {
|
|
216
|
+
await next();
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const sessionId = req.sessionId ?? req.getHeader('x-session-id');
|
|
221
|
+
|
|
222
|
+
if (sessionId === undefined || sessionId === '') {
|
|
223
|
+
res.setStatus(400).json({ error: 'Missing session ID' });
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const csrfToken = req.getHeader('x-csrf-token');
|
|
228
|
+
|
|
229
|
+
if (csrfToken === undefined || csrfToken === '') {
|
|
230
|
+
res.setStatus(403).json({ error: 'Missing CSRF token' });
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const isValid = resolveCsrfManager(csrfManager).validateToken(
|
|
235
|
+
String(sessionId),
|
|
236
|
+
String(csrfToken)
|
|
237
|
+
);
|
|
238
|
+
|
|
239
|
+
if (isValid === false) {
|
|
240
|
+
res.setStatus(403).json({ error: 'Invalid or expired CSRF token' });
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
await next();
|
|
245
|
+
};
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Input Validation Middleware
|
|
250
|
+
* Validate request body against schema
|
|
251
|
+
*/
|
|
252
|
+
export const validationMiddleware = (schema: SchemaType) => {
|
|
253
|
+
return async (req: IRequest, res: IResponse, next: () => Promise<void>): Promise<void> => {
|
|
254
|
+
if (req.getMethod() === 'GET' || req.getMethod() === 'DELETE') {
|
|
255
|
+
await next();
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
try {
|
|
260
|
+
const body = req.body ?? {};
|
|
261
|
+
Validator.validate(body, resolveSchema(schema));
|
|
262
|
+
await next();
|
|
263
|
+
} catch (error: unknown) {
|
|
264
|
+
Logger.error('Validation error:', error);
|
|
265
|
+
const newError = error as Error & { toObject?: () => Record<string, unknown> };
|
|
266
|
+
if (
|
|
267
|
+
error !== undefined &&
|
|
268
|
+
'toObject' in newError &&
|
|
269
|
+
typeof newError.toObject === 'function'
|
|
270
|
+
) {
|
|
271
|
+
res.setStatus(422).json({ errors: newError.toObject() });
|
|
272
|
+
} else {
|
|
273
|
+
res.setStatus(400).json({ error: 'Invalid request body' });
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* XSS Protection Middleware
|
|
281
|
+
* Sanitize and escape user input
|
|
282
|
+
*/
|
|
283
|
+
export const xssProtectionMiddleware = async (
|
|
284
|
+
req: IRequest,
|
|
285
|
+
res: IResponse,
|
|
286
|
+
next: () => Promise<void>
|
|
287
|
+
): Promise<void> => {
|
|
288
|
+
// Add XSS protection headers
|
|
289
|
+
res.setHeader('X-Content-Type-Options', 'nosniff');
|
|
290
|
+
res.setHeader('X-Frame-Options', 'DENY');
|
|
291
|
+
res.setHeader('X-XSS-Protection', '1; mode=block');
|
|
292
|
+
|
|
293
|
+
// Sanitize request body if present
|
|
294
|
+
const body = req.body;
|
|
295
|
+
if (body !== undefined && body !== null && typeof body === 'object') {
|
|
296
|
+
for (const [key, value] of Object.entries(body)) {
|
|
297
|
+
if (typeof value === 'string') {
|
|
298
|
+
body[key] = XssProtection.escape(value);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
await next();
|
|
304
|
+
};
|