@zintrust/core 0.1.40 → 0.1.42
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/zintrust-main.d.ts.map +1 -1
- package/bin/zintrust-main.js +22 -1
- package/package.json +24 -4
- package/public/error-pages/404.html +2 -2
- package/src/auth/Auth.js +1 -1
- package/src/boot/Application.d.ts +1 -16
- package/src/boot/Application.d.ts.map +1 -1
- package/src/boot/Application.js +2 -290
- package/src/boot/Server.d.ts +1 -1
- package/src/boot/Server.d.ts.map +1 -1
- package/src/boot/bootstrap.js +50 -16
- package/src/boot/registry/registerRoute.d.ts +6 -0
- package/src/boot/registry/registerRoute.d.ts.map +1 -0
- package/src/boot/registry/registerRoute.js +96 -0
- package/src/boot/registry/runtime.d.ts +15 -0
- package/src/boot/registry/runtime.d.ts.map +1 -0
- package/src/boot/registry/runtime.js +364 -0
- package/src/boot/registry/type.d.ts +25 -0
- package/src/boot/registry/type.d.ts.map +1 -0
- package/src/boot/registry/type.js +1 -0
- package/src/boot/registry/worker.d.ts +6 -0
- package/src/boot/registry/worker.d.ts.map +1 -0
- package/src/boot/registry/worker.js +35 -0
- package/src/cache/drivers/KVRemoteDriver.d.ts.map +1 -1
- package/src/cache/drivers/KVRemoteDriver.js +14 -1
- package/src/cli/CLI.d.ts.map +1 -1
- package/src/cli/CLI.js +94 -34
- package/src/cli/ErrorHandler.js +1 -1
- package/src/cli/commands/ConfigCommand.d.ts.map +1 -1
- package/src/cli/commands/ConfigCommand.js +3 -5
- package/src/cli/commands/ContainerProxiesCommand.d.ts +5 -0
- package/src/cli/commands/ContainerProxiesCommand.d.ts.map +1 -0
- package/src/cli/commands/ContainerProxiesCommand.js +77 -0
- package/src/cli/commands/ContainerWorkersCommand.d.ts +5 -0
- package/src/cli/commands/ContainerWorkersCommand.d.ts.map +1 -0
- package/src/cli/commands/ContainerWorkersCommand.js +57 -0
- package/src/cli/commands/D1LearnCommand.d.ts +9 -0
- package/src/cli/commands/D1LearnCommand.d.ts.map +1 -0
- package/src/cli/commands/D1LearnCommand.js +143 -0
- package/src/cli/commands/D1MigrateCommand.d.ts.map +1 -1
- package/src/cli/commands/D1MigrateCommand.js +55 -16
- package/src/cli/commands/DeployCommand.d.ts +16 -0
- package/src/cli/commands/DeployCommand.d.ts.map +1 -0
- package/src/cli/commands/DeployCommand.js +110 -0
- package/src/cli/commands/DeployContainerProxiesCommand.d.ts +5 -0
- package/src/cli/commands/DeployContainerProxiesCommand.d.ts.map +1 -0
- package/src/cli/commands/DeployContainerProxiesCommand.js +27 -0
- package/src/cli/commands/DeployContainerWorkersCommand.d.ts +5 -0
- package/src/cli/commands/DeployContainerWorkersCommand.d.ts.map +1 -0
- package/src/cli/commands/DeployContainerWorkersCommand.js +27 -0
- package/src/cli/commands/DockerComposeCommandUtils.d.ts +3 -0
- package/src/cli/commands/DockerComposeCommandUtils.d.ts.map +1 -0
- package/src/cli/commands/DockerComposeCommandUtils.js +34 -0
- package/src/cli/commands/DoctorArchitectureCommand.d.ts +5 -0
- package/src/cli/commands/DoctorArchitectureCommand.d.ts.map +1 -0
- package/src/cli/commands/DoctorArchitectureCommand.js +54 -0
- package/src/cli/commands/InitContainerCommand.d.ts +5 -0
- package/src/cli/commands/InitContainerCommand.d.ts.map +1 -0
- package/src/cli/commands/InitContainerCommand.js +231 -0
- package/src/cli/commands/InitEcosystemCommand.d.ts +6 -0
- package/src/cli/commands/InitEcosystemCommand.d.ts.map +1 -0
- package/src/cli/commands/InitEcosystemCommand.js +51 -0
- package/src/cli/commands/InitProducerCommand.d.ts +5 -0
- package/src/cli/commands/InitProducerCommand.d.ts.map +1 -0
- package/src/cli/commands/InitProducerCommand.js +47 -0
- package/src/cli/commands/InitProxyCommand.d.ts +5 -0
- package/src/cli/commands/InitProxyCommand.d.ts.map +1 -0
- package/src/cli/commands/InitProxyCommand.js +442 -0
- package/src/cli/commands/MigrateCommand.d.ts.map +1 -1
- package/src/cli/commands/MigrateCommand.js +78 -36
- package/src/cli/commands/MigrateWorkerCommand.d.ts.map +1 -1
- package/src/cli/commands/MigrateWorkerCommand.js +36 -2
- package/src/cli/commands/MongoDBProxyCommand.d.ts +5 -0
- package/src/cli/commands/MongoDBProxyCommand.d.ts.map +1 -0
- package/src/cli/commands/MongoDBProxyCommand.js +98 -0
- package/src/cli/commands/MySqlProxyCommand.d.ts +6 -0
- package/src/cli/commands/MySqlProxyCommand.d.ts.map +1 -0
- package/src/cli/commands/MySqlProxyCommand.js +32 -0
- package/src/cli/commands/PostgresProxyCommand.d.ts +6 -0
- package/src/cli/commands/PostgresProxyCommand.d.ts.map +1 -0
- package/src/cli/commands/PostgresProxyCommand.js +32 -0
- package/src/cli/commands/ProxyCommand.d.ts +12 -0
- package/src/cli/commands/ProxyCommand.d.ts.map +1 -0
- package/src/cli/commands/ProxyCommand.js +80 -0
- package/src/cli/commands/ProxyCommandUtils.d.ts +6 -0
- package/src/cli/commands/ProxyCommandUtils.d.ts.map +1 -0
- package/src/cli/commands/ProxyCommandUtils.js +38 -0
- package/src/cli/commands/PutCommand.d.ts +6 -0
- package/src/cli/commands/PutCommand.d.ts.map +1 -0
- package/src/cli/commands/PutCommand.js +173 -0
- package/src/cli/commands/QueueRecoveryCommand.d.ts +6 -0
- package/src/cli/commands/QueueRecoveryCommand.d.ts.map +1 -0
- package/src/cli/commands/QueueRecoveryCommand.js +612 -0
- package/src/cli/commands/RedisProxyCommand.d.ts +6 -0
- package/src/cli/commands/RedisProxyCommand.d.ts.map +1 -0
- package/src/cli/commands/RedisProxyCommand.js +53 -0
- package/src/cli/commands/ScheduleListCommand.d.ts +6 -0
- package/src/cli/commands/ScheduleListCommand.d.ts.map +1 -0
- package/src/cli/commands/ScheduleListCommand.js +62 -0
- package/src/cli/commands/ScheduleRunCommand.d.ts +6 -0
- package/src/cli/commands/ScheduleRunCommand.d.ts.map +1 -0
- package/src/cli/commands/ScheduleRunCommand.js +32 -0
- package/src/cli/commands/ScheduleStartCommand.d.ts +6 -0
- package/src/cli/commands/ScheduleStartCommand.d.ts.map +1 -0
- package/src/cli/commands/ScheduleStartCommand.js +40 -0
- package/src/cli/commands/SecretsCommand.d.ts.map +1 -1
- package/src/cli/commands/SecretsCommand.js +2 -2
- package/src/cli/commands/SmtpProxyCommand.d.ts +6 -0
- package/src/cli/commands/SmtpProxyCommand.d.ts.map +1 -0
- package/src/cli/commands/SmtpProxyCommand.js +56 -0
- package/src/cli/commands/SqlProxyCommandUtils.d.ts +46 -0
- package/src/cli/commands/SqlProxyCommandUtils.d.ts.map +1 -0
- package/src/cli/commands/SqlProxyCommandUtils.js +48 -0
- package/src/cli/commands/SqlServerProxyCommand.d.ts +5 -0
- package/src/cli/commands/SqlServerProxyCommand.d.ts.map +1 -0
- package/src/cli/commands/SqlServerProxyCommand.js +85 -0
- package/src/cli/commands/StartCommand.d.ts.map +1 -1
- package/src/cli/commands/StartCommand.js +132 -17
- package/src/cli/commands/WorkerCommands.d.ts +1 -0
- package/src/cli/commands/WorkerCommands.d.ts.map +1 -1
- package/src/cli/commands/WorkerCommands.js +140 -6
- package/src/cli/commands/index.d.ts +2 -0
- package/src/cli/commands/index.d.ts.map +1 -1
- package/src/cli/commands/index.js +2 -0
- package/src/cli/commands/runner/index.d.ts +2 -2
- package/src/cli/commands/runner/index.d.ts.map +1 -1
- package/src/cli/commands/runner/index.js +15 -4
- package/src/cli/commands/schedule/ScheduleCliSupport.d.ts +6 -0
- package/src/cli/commands/schedule/ScheduleCliSupport.d.ts.map +1 -0
- package/src/cli/commands/schedule/ScheduleCliSupport.js +55 -0
- package/src/cli/config/ConfigManager.d.ts.map +1 -1
- package/src/cli/config/ConfigManager.js +8 -1
- package/src/cli/d1/D1SqlMigrations.d.ts.map +1 -1
- package/src/cli/d1/D1SqlMigrations.js +14 -1
- package/src/cli/d1/WranglerConfig.d.ts.map +1 -1
- package/src/cli/d1/WranglerConfig.js +34 -2
- package/src/cli/index.d.ts +4 -0
- package/src/cli/index.d.ts.map +1 -1
- package/src/cli/index.js +4 -0
- package/src/cli/scaffolding/ProjectScaffolder.d.ts.map +1 -1
- package/src/cli/scaffolding/ProjectScaffolder.js +2 -0
- package/src/cli/scaffolding/ServiceScaffolder.d.ts.map +1 -1
- package/src/cli/scaffolding/ServiceScaffolder.js +1 -0
- package/src/cli/services/VersionChecker.d.ts.map +1 -1
- package/src/cli/services/VersionChecker.js +5 -1
- package/src/cli/utils/DatabaseCliUtils.d.ts.map +1 -1
- package/src/cli/utils/DatabaseCliUtils.js +6 -1
- package/src/cli/utils/EnvFileLoader.d.ts.map +1 -1
- package/src/cli/utils/EnvFileLoader.js +35 -15
- package/src/cli/workers/QueueWorkRunner.js +1 -1
- package/src/cli.d.ts +5 -0
- package/src/cli.d.ts.map +1 -0
- package/src/cli.js +4 -0
- package/src/collections/index.d.ts +2 -2
- package/src/collections/index.d.ts.map +1 -1
- package/src/collections/index.js +1 -1
- package/src/common/HealthRoutes.d.ts.map +1 -1
- package/src/common/HealthRoutes.js +50 -2
- package/src/common/RemoteSignedJson.d.ts +1 -0
- package/src/common/RemoteSignedJson.d.ts.map +1 -1
- package/src/common/RemoteSignedJson.js +81 -29
- package/src/common/index.d.ts +1 -0
- package/src/common/index.d.ts.map +1 -1
- package/src/common/index.js +12 -1
- package/src/common/utility.d.ts.map +1 -1
- package/src/common/utility.js +2 -6
- package/src/config/FileLogWriter.d.ts.map +1 -1
- package/src/config/FileLogWriter.js +21 -6
- package/src/config/app.d.ts +4 -0
- package/src/config/app.d.ts.map +1 -1
- package/src/config/app.js +4 -0
- package/src/config/cache.d.ts.map +1 -1
- package/src/config/cache.js +22 -2
- package/src/config/cloudflare.d.ts +5 -1
- package/src/config/cloudflare.d.ts.map +1 -1
- package/src/config/cloudflare.js +67 -8
- package/src/config/database.d.ts.map +1 -1
- package/src/config/database.js +48 -13
- package/src/config/env.d.ts +87 -2
- package/src/config/env.d.ts.map +1 -1
- package/src/config/env.js +158 -19
- package/src/config/index.d.ts +1 -0
- package/src/config/index.d.ts.map +1 -1
- package/src/config/mail.d.ts.map +1 -1
- package/src/config/mail.js +16 -10
- package/src/config/middleware.d.ts +5 -0
- package/src/config/middleware.d.ts.map +1 -1
- package/src/config/middleware.js +19 -1
- package/src/config/queue.d.ts.map +1 -1
- package/src/config/queue.js +70 -9
- package/src/config/redis.d.ts.map +1 -1
- package/src/config/redis.js +48 -13
- package/src/config/storage.d.ts.map +1 -1
- package/src/config/storage.js +1 -0
- package/src/config/type.d.ts +18 -0
- package/src/config/type.d.ts.map +1 -1
- package/src/config/workers.d.ts.map +1 -1
- package/src/config/workers.js +122 -16
- package/src/functions/cloudflare.d.ts.map +1 -1
- package/src/functions/cloudflare.js +55 -1
- package/src/health/StartupHealthChecks.js +1 -1
- package/src/helper/index.d.ts +225 -0
- package/src/helper/index.d.ts.map +1 -0
- package/src/helper/index.js +347 -0
- package/src/http/FileUpload.d.ts +3 -2
- package/src/http/FileUpload.d.ts.map +1 -1
- package/src/http/Kernel.d.ts.map +1 -1
- package/src/http/Kernel.js +2 -1
- package/src/http/error-pages/ErrorPageRenderer.d.ts +4 -0
- package/src/http/error-pages/ErrorPageRenderer.d.ts.map +1 -1
- package/src/http/error-pages/ErrorPageRenderer.js +141 -1
- package/src/http/middleware/BodyParsingMiddleware.d.ts.map +1 -1
- package/src/http/middleware/BodyParsingMiddleware.js +33 -6
- package/src/index.d.ts +26 -57
- package/src/index.d.ts.map +1 -1
- package/src/index.js +32 -18
- package/src/microservices/ServiceAuthMiddleware.d.ts.map +1 -1
- package/src/microservices/ServiceAuthMiddleware.js +12 -4
- package/src/middleware/CsrfMiddleware.d.ts.map +1 -1
- package/src/middleware/CsrfMiddleware.js +30 -16
- package/src/middleware/ErrorHandlerMiddleware.d.ts.map +1 -1
- package/src/middleware/ErrorHandlerMiddleware.js +2 -1
- package/src/migrations/MigrationDiscovery.d.ts.map +1 -1
- package/src/migrations/MigrationDiscovery.js +2 -1
- package/src/migrations/MigrationLoader.js +1 -1
- package/src/migrations/schema/SchemaCompiler.d.ts.map +1 -1
- package/src/migrations/schema/SchemaCompiler.js +6 -3
- 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 +1 -1
- package/src/node-singletons/fs.d.ts.map +1 -1
- package/src/node-singletons/path.d.ts +1 -1
- package/src/node-singletons/path.d.ts.map +1 -1
- package/src/node-singletons/path.js +1 -1
- package/src/node-singletons/stream.d.ts +11 -0
- package/src/node-singletons/stream.d.ts.map +1 -0
- package/src/node-singletons/stream.js +8 -0
- package/src/observability/OpenTelemetry.d.ts +7 -0
- package/src/observability/OpenTelemetry.d.ts.map +1 -1
- package/src/observability/OpenTelemetry.js +49 -2
- package/src/orm/Database.d.ts +4 -0
- package/src/orm/Database.d.ts.map +1 -1
- package/src/orm/Database.js +80 -9
- package/src/orm/DatabaseAdapter.d.ts +1 -0
- package/src/orm/DatabaseAdapter.d.ts.map +1 -1
- package/src/orm/DatabaseRuntimeRegistration.d.ts.map +1 -1
- package/src/orm/DatabaseRuntimeRegistration.js +2 -0
- package/src/orm/QueryBuilder.d.ts +1 -0
- package/src/orm/QueryBuilder.d.ts.map +1 -1
- package/src/orm/QueryBuilder.js +33 -3
- package/src/orm/SchemaCompiler.d.ts.map +1 -1
- package/src/orm/SchemaCompiler.js +6 -3
- package/src/orm/SchemaStatemenWriter.d.ts +15 -0
- package/src/orm/SchemaStatemenWriter.d.ts.map +1 -0
- package/src/orm/SchemaStatemenWriter.js +78 -0
- package/src/orm/adapters/D1Adapter.d.ts.map +1 -1
- package/src/orm/adapters/D1Adapter.js +52 -2
- package/src/orm/adapters/D1RemoteAdapter.d.ts.map +1 -1
- package/src/orm/adapters/D1RemoteAdapter.js +150 -89
- package/src/orm/adapters/MongoDBProxyAdapter.d.ts +3 -0
- package/src/orm/adapters/MongoDBProxyAdapter.d.ts.map +1 -0
- package/src/orm/adapters/MongoDBProxyAdapter.js +128 -0
- package/src/orm/adapters/MySQLProxyAdapter.d.ts +11 -0
- package/src/orm/adapters/MySQLProxyAdapter.d.ts.map +1 -0
- package/src/orm/adapters/MySQLProxyAdapter.js +162 -0
- package/src/orm/adapters/PostgreSQLProxyAdapter.d.ts +11 -0
- package/src/orm/adapters/PostgreSQLProxyAdapter.d.ts.map +1 -0
- package/src/orm/adapters/PostgreSQLProxyAdapter.js +163 -0
- package/src/orm/adapters/ProxyCache.d.ts +9 -0
- package/src/orm/adapters/ProxyCache.d.ts.map +1 -0
- package/src/orm/adapters/ProxyCache.js +24 -0
- package/src/orm/adapters/ProxySignedRequest.d.ts +11 -0
- package/src/orm/adapters/ProxySignedRequest.d.ts.map +1 -0
- package/src/orm/adapters/ProxySignedRequest.js +30 -0
- package/src/orm/adapters/ProxySigningPath.d.ts +3 -0
- package/src/orm/adapters/ProxySigningPath.d.ts.map +1 -0
- package/src/orm/adapters/ProxySigningPath.js +25 -0
- package/src/orm/adapters/SqlProxyAdapterUtils.d.ts +19 -0
- package/src/orm/adapters/SqlProxyAdapterUtils.d.ts.map +1 -0
- package/src/orm/adapters/SqlProxyAdapterUtils.js +36 -0
- package/src/orm/adapters/SqlProxyRegistryMode.d.ts +12 -0
- package/src/orm/adapters/SqlProxyRegistryMode.d.ts.map +1 -0
- package/src/orm/adapters/SqlProxyRegistryMode.js +24 -0
- package/src/orm/adapters/SqlServerProxyAdapter.d.ts +6 -0
- package/src/orm/adapters/SqlServerProxyAdapter.d.ts.map +1 -0
- package/src/orm/adapters/SqlServerProxyAdapter.js +154 -0
- package/src/orm/migrations/MigrationStore.js +1 -1
- package/src/performance/Optimizer.d.ts +1 -0
- package/src/performance/Optimizer.d.ts.map +1 -1
- package/src/performance/Optimizer.js +21 -8
- package/src/proxy/ErrorHandler.d.ts +11 -0
- package/src/proxy/ErrorHandler.d.ts.map +1 -0
- package/src/proxy/ErrorHandler.js +7 -0
- package/src/proxy/PoolManager.d.ts +8 -0
- package/src/proxy/PoolManager.d.ts.map +1 -0
- package/src/proxy/PoolManager.js +18 -0
- package/src/proxy/ProxyBackend.d.ts +18 -0
- package/src/proxy/ProxyBackend.d.ts.map +1 -0
- package/src/proxy/ProxyBackend.js +1 -0
- package/src/proxy/ProxyConfig.d.ts +12 -0
- package/src/proxy/ProxyConfig.d.ts.map +1 -0
- package/src/proxy/ProxyConfig.js +1 -0
- package/src/proxy/ProxyRegistry.d.ts +10 -0
- package/src/proxy/ProxyRegistry.d.ts.map +1 -0
- package/src/proxy/ProxyRegistry.js +11 -0
- package/src/proxy/ProxyRequestParsing.d.ts +9 -0
- package/src/proxy/ProxyRequestParsing.d.ts.map +1 -0
- package/src/proxy/ProxyRequestParsing.js +16 -0
- package/src/proxy/ProxyServer.d.ts +21 -0
- package/src/proxy/ProxyServer.d.ts.map +1 -0
- package/src/proxy/ProxyServer.js +84 -0
- package/src/proxy/ProxyServerUtils.d.ts +37 -0
- package/src/proxy/ProxyServerUtils.d.ts.map +1 -0
- package/src/proxy/ProxyServerUtils.js +42 -0
- package/src/proxy/ProxySigningConfigResolver.d.ts +22 -0
- package/src/proxy/ProxySigningConfigResolver.d.ts.map +1 -0
- package/src/proxy/ProxySigningConfigResolver.js +24 -0
- package/src/proxy/ProxySigningRequest.d.ts +12 -0
- package/src/proxy/ProxySigningRequest.d.ts.map +1 -0
- package/src/proxy/ProxySigningRequest.js +31 -0
- package/src/proxy/RequestValidator.d.ts +15 -0
- package/src/proxy/RequestValidator.d.ts.map +1 -0
- package/src/proxy/RequestValidator.js +26 -0
- package/src/proxy/SigningService.d.ts +39 -0
- package/src/proxy/SigningService.d.ts.map +1 -0
- package/src/proxy/SigningService.js +107 -0
- package/src/proxy/SqlPayloadValidator.d.ts +13 -0
- package/src/proxy/SqlPayloadValidator.d.ts.map +1 -0
- package/src/proxy/SqlPayloadValidator.js +14 -0
- package/src/proxy/SqlProxyDbOverrides.d.ts +17 -0
- package/src/proxy/SqlProxyDbOverrides.d.ts.map +1 -0
- package/src/proxy/SqlProxyDbOverrides.js +1 -0
- package/src/proxy/SqlProxyServerDeps.d.ts +12 -0
- package/src/proxy/SqlProxyServerDeps.d.ts.map +1 -0
- package/src/proxy/SqlProxyServerDeps.js +9 -0
- package/src/proxy/StatementPayloadValidator.d.ts +13 -0
- package/src/proxy/StatementPayloadValidator.d.ts.map +1 -0
- package/src/proxy/StatementPayloadValidator.js +18 -0
- package/src/proxy/StatementRegistryLoader.d.ts +2 -0
- package/src/proxy/StatementRegistryLoader.d.ts.map +1 -0
- package/src/proxy/StatementRegistryLoader.js +36 -0
- package/src/proxy/StatementRegistryResolver.d.ts +15 -0
- package/src/proxy/StatementRegistryResolver.d.ts.map +1 -0
- package/src/proxy/StatementRegistryResolver.js +34 -0
- package/src/proxy/d1/ZintrustD1Proxy.d.ts +3 -0
- package/src/proxy/d1/ZintrustD1Proxy.d.ts.map +1 -0
- package/src/proxy/d1/ZintrustD1Proxy.js +2 -0
- package/src/proxy/d1/register.d.ts +2 -0
- package/src/proxy/d1/register.d.ts.map +1 -0
- package/src/proxy/d1/register.js +5 -0
- package/src/proxy/isMutatingSql.d.ts +2 -0
- package/src/proxy/isMutatingSql.d.ts.map +1 -0
- package/src/proxy/isMutatingSql.js +12 -0
- package/src/proxy/kv/ZintrustKvProxy.d.ts +3 -0
- package/src/proxy/kv/ZintrustKvProxy.d.ts.map +1 -0
- package/src/proxy/kv/ZintrustKvProxy.js +2 -0
- package/src/proxy/kv/register.d.ts +2 -0
- package/src/proxy/kv/register.d.ts.map +1 -0
- package/src/proxy/kv/register.js +5 -0
- package/src/proxy/mongodb/MongoDBProxyServer.d.ts +33 -0
- package/src/proxy/mongodb/MongoDBProxyServer.d.ts.map +1 -0
- package/src/proxy/mongodb/MongoDBProxyServer.js +202 -0
- package/src/proxy/mongodb/register.d.ts +2 -0
- package/src/proxy/mongodb/register.d.ts.map +1 -0
- package/src/proxy/mongodb/register.js +5 -0
- package/src/proxy/mysql/MySqlProxyServer.d.ts +8 -0
- package/src/proxy/mysql/MySqlProxyServer.d.ts.map +1 -0
- package/src/proxy/mysql/MySqlProxyServer.js +202 -0
- package/src/proxy/mysql/register.d.ts +2 -0
- package/src/proxy/mysql/register.d.ts.map +1 -0
- package/src/proxy/mysql/register.js +5 -0
- package/src/proxy/postgres/PostgresProxyServer.d.ts +8 -0
- package/src/proxy/postgres/PostgresProxyServer.d.ts.map +1 -0
- package/src/proxy/postgres/PostgresProxyServer.js +178 -0
- package/src/proxy/postgres/register.d.ts +2 -0
- package/src/proxy/postgres/register.d.ts.map +1 -0
- package/src/proxy/postgres/register.js +5 -0
- package/src/proxy/redis/RedisProxyServer.d.ts +12 -0
- package/src/proxy/redis/RedisProxyServer.d.ts.map +1 -0
- package/src/proxy/redis/RedisProxyServer.js +192 -0
- package/src/proxy/redis/register.d.ts +2 -0
- package/src/proxy/redis/register.d.ts.map +1 -0
- package/src/proxy/redis/register.js +5 -0
- package/src/proxy/smtp/SmtpProxyServer.d.ts +19 -0
- package/src/proxy/smtp/SmtpProxyServer.d.ts.map +1 -0
- package/src/proxy/smtp/SmtpProxyServer.js +290 -0
- package/src/proxy/smtp/register.d.ts +2 -0
- package/src/proxy/smtp/register.d.ts.map +1 -0
- package/src/proxy/smtp/register.js +5 -0
- package/src/proxy/sqlserver/SqlServerProxyServer.d.ts +8 -0
- package/src/proxy/sqlserver/SqlServerProxyServer.d.ts.map +1 -0
- package/src/proxy/sqlserver/SqlServerProxyServer.js +203 -0
- package/src/proxy/sqlserver/register.d.ts +2 -0
- package/src/proxy/sqlserver/register.d.ts.map +1 -0
- package/src/proxy/sqlserver/register.js +5 -0
- package/src/proxy.d.ts +4 -0
- package/src/proxy.d.ts.map +1 -0
- package/src/proxy.js +3 -0
- package/src/routes/doc.d.ts.map +1 -1
- package/src/routes/doc.js +16 -2
- package/src/routes/error.d.ts +5 -4
- package/src/routes/error.d.ts.map +1 -1
- package/src/routes/error.js +15 -13
- package/src/routes/errorPages.d.ts +2 -0
- package/src/routes/errorPages.d.ts.map +1 -1
- package/src/routes/errorPages.js +144 -4
- package/src/runtime/PluginAutoImports.d.ts +1 -0
- package/src/runtime/PluginAutoImports.d.ts.map +1 -1
- package/src/runtime/PluginAutoImports.js +94 -9
- package/src/runtime/RuntimeAdapter.d.ts +8 -9
- package/src/runtime/RuntimeAdapter.d.ts.map +1 -1
- package/src/runtime/RuntimeAdapter.js +120 -34
- package/src/runtime/RuntimeServices.d.ts +47 -0
- package/src/runtime/RuntimeServices.d.ts.map +1 -0
- package/src/runtime/RuntimeServices.js +164 -0
- package/src/runtime/StartupConfigFileRegistry.d.ts +4 -4
- package/src/runtime/StartupConfigFileRegistry.d.ts.map +1 -1
- package/src/runtime/StartupConfigFileRegistry.js +12 -0
- package/src/runtime/WorkerAdapterImports.d.ts +5 -0
- package/src/runtime/WorkerAdapterImports.d.ts.map +1 -0
- package/src/runtime/WorkerAdapterImports.js +17 -0
- package/src/runtime/WorkersModule.d.ts +6 -0
- package/src/runtime/WorkersModule.d.ts.map +1 -0
- package/src/runtime/WorkersModule.js +278 -0
- package/src/runtime/adapters/CloudflareAdapter.d.ts.map +1 -1
- package/src/runtime/adapters/CloudflareAdapter.js +19 -2
- package/src/runtime/adapters/DenoAdapter.js +1 -0
- package/src/runtime/adapters/FargateAdapter.js +1 -1
- package/src/runtime/adapters/LambdaAdapter.js +1 -1
- package/src/runtime/adapters/NodeServerAdapter.js +1 -1
- package/src/runtime/detectRuntime.d.ts +10 -0
- package/src/runtime/detectRuntime.d.ts.map +1 -0
- package/src/runtime/detectRuntime.js +57 -0
- package/src/runtime/useFileLoader.d.ts.map +1 -1
- package/src/runtime/useFileLoader.js +16 -0
- package/src/scheduler/Schedule.d.ts +36 -0
- package/src/scheduler/Schedule.d.ts.map +1 -0
- package/src/scheduler/Schedule.js +197 -0
- package/src/scheduler/ScheduleHttpGateway.d.ts +8 -0
- package/src/scheduler/ScheduleHttpGateway.d.ts.map +1 -0
- package/src/scheduler/ScheduleHttpGateway.js +196 -0
- package/src/scheduler/ScheduleRunner.d.ts +6 -0
- package/src/scheduler/ScheduleRunner.d.ts.map +1 -1
- package/src/scheduler/ScheduleRunner.js +166 -29
- package/src/scheduler/SchedulerRuntime.d.ts +15 -0
- package/src/scheduler/SchedulerRuntime.d.ts.map +1 -0
- package/src/scheduler/SchedulerRuntime.js +79 -0
- package/src/scheduler/cron/Cron.d.ts +19 -0
- package/src/scheduler/cron/Cron.d.ts.map +1 -0
- package/src/scheduler/cron/Cron.js +200 -0
- package/src/scheduler/leader/SchedulerLeader.d.ts +14 -0
- package/src/scheduler/leader/SchedulerLeader.d.ts.map +1 -0
- package/src/scheduler/leader/SchedulerLeader.js +187 -0
- package/src/scheduler/state/ScheduleStateStore.d.ts +27 -0
- package/src/scheduler/state/ScheduleStateStore.d.ts.map +1 -0
- package/src/scheduler/state/ScheduleStateStore.js +27 -0
- package/src/scheduler/types.d.ts +10 -0
- package/src/scheduler/types.d.ts.map +1 -1
- package/src/schedules/index.d.ts +1 -0
- package/src/schedules/index.d.ts.map +1 -1
- package/src/schedules/index.js +1 -0
- package/src/schedules/job-tracking-cleanup.d.ts +4 -0
- package/src/schedules/job-tracking-cleanup.d.ts.map +1 -0
- package/src/schedules/job-tracking-cleanup.js +116 -0
- package/src/schedules/log-cleanup.d.ts +1 -2
- package/src/schedules/log-cleanup.d.ts.map +1 -1
- package/src/schedules/log-cleanup.js +12 -15
- package/src/scripts/TemplateImportsCheck.js +2 -2
- package/src/scripts/TemplateSync.js +3 -4
- package/src/security/CsrfTokenManager.d.ts.map +1 -1
- package/src/security/CsrfTokenManager.js +12 -0
- package/src/security/Hash.d.ts +1 -1
- package/src/security/Hash.d.ts.map +1 -1
- package/src/security/Hash.js +31 -36
- package/src/security/Sanitizer.d.ts.map +1 -1
- package/src/security/Sanitizer.js +1 -9
- package/src/security/SignedRequest.d.ts.map +1 -1
- package/src/security/SignedRequest.js +2 -2
- package/src/seeders/SeederLoader.js +1 -1
- package/src/session/SessionManager.d.ts +3 -0
- package/src/session/SessionManager.d.ts.map +1 -1
- package/src/session/SessionManager.js +49 -10
- package/src/sockets/CloudflareSocket.d.ts +24 -0
- package/src/sockets/CloudflareSocket.d.ts.map +1 -0
- package/src/sockets/CloudflareSocket.js +259 -0
- package/src/start.d.ts.map +1 -1
- package/src/start.js +1 -8
- package/src/templates/docker/docker-compose.ecosystem.yml.tpl +301 -0
- package/src/templates/docker/docker-compose.schedules.yml.tpl +84 -0
- package/src/templates/project/basic/app/Schedules/index.ts.tpl +0 -0
- package/src/templates/project/basic/config/database.ts.tpl +1 -1
- package/src/templates/project/basic/src/zintrust.plugins.wg.ts.tpl +8 -0
- package/src/toolkit/Secrets/Manifest.d.ts.map +1 -1
- package/src/toolkit/Secrets/Manifest.js +5 -7
- package/src/tools/mail/drivers/Smtp.d.ts.map +1 -1
- package/src/tools/mail/drivers/Smtp.js +229 -18
- package/src/tools/mail/index.d.ts.map +1 -1
- package/src/tools/mail/index.js +5 -4
- package/src/tools/mail/template-loader.d.ts.map +1 -1
- package/src/tools/mail/template-loader.js +197 -29
- package/src/tools/mail/templates/auth-password-reset.d.ts +3 -0
- package/src/tools/mail/templates/auth-password-reset.d.ts.map +1 -0
- package/src/tools/mail/templates/auth-password-reset.js +231 -0
- package/src/tools/mail/templates/auth-welcome.d.ts +3 -0
- package/src/tools/mail/templates/auth-welcome.d.ts.map +1 -0
- package/src/tools/mail/templates/auth-welcome.js +236 -0
- package/src/tools/mail/templates/general.d.ts +3 -0
- package/src/tools/mail/templates/general.d.ts.map +1 -0
- package/src/tools/mail/templates/general.js +109 -0
- package/src/tools/mail/templates/index.js +2 -2
- package/src/tools/mail/templates/job-completed.d.ts +3 -0
- package/src/tools/mail/templates/job-completed.d.ts.map +1 -0
- package/src/tools/mail/templates/job-completed.js +188 -0
- package/src/tools/mail/templates/notifications-new-comment.d.ts +3 -0
- package/src/tools/mail/templates/notifications-new-comment.d.ts.map +1 -0
- package/src/tools/mail/templates/notifications-new-comment.js +228 -0
- package/src/tools/mail/templates/password-reset.d.ts +3 -0
- package/src/tools/mail/templates/password-reset.d.ts.map +1 -0
- package/src/tools/mail/templates/password-reset.js +221 -0
- package/src/tools/mail/templates/performance-report.d.ts +3 -0
- package/src/tools/mail/templates/performance-report.d.ts.map +1 -0
- package/src/tools/mail/templates/performance-report.js +258 -0
- package/src/tools/mail/templates/welcome.d.ts +3 -0
- package/src/tools/mail/templates/welcome.d.ts.map +1 -0
- package/src/tools/mail/templates/welcome.js +187 -0
- package/src/tools/mail/templates/worker-alert.d.ts +3 -0
- package/src/tools/mail/templates/worker-alert.d.ts.map +1 -0
- package/src/tools/mail/templates/worker-alert.js +229 -0
- package/src/tools/notification/Notification.js +1 -1
- package/src/tools/notification/testingHelpers.js +6 -5
- package/src/tools/queue/AdvancedQueue.js +2 -6
- package/src/tools/queue/IdempotencyManager.d.ts +6 -0
- package/src/tools/queue/IdempotencyManager.d.ts.map +1 -0
- package/src/tools/queue/IdempotencyManager.js +36 -0
- package/src/tools/queue/JobHeartbeatStore.d.ts +16 -0
- package/src/tools/queue/JobHeartbeatStore.d.ts.map +1 -0
- package/src/tools/queue/JobHeartbeatStore.js +67 -0
- package/src/tools/queue/JobReconciliationRunner.d.ts +16 -0
- package/src/tools/queue/JobReconciliationRunner.d.ts.map +1 -0
- package/src/tools/queue/JobReconciliationRunner.js +56 -0
- package/src/tools/queue/JobRecoveryDaemon.d.ts +27 -0
- package/src/tools/queue/JobRecoveryDaemon.d.ts.map +1 -0
- package/src/tools/queue/JobRecoveryDaemon.js +303 -0
- package/src/tools/queue/JobStateTracker.d.ts +140 -0
- package/src/tools/queue/JobStateTracker.d.ts.map +1 -0
- package/src/tools/queue/JobStateTracker.js +409 -0
- package/src/tools/queue/JobStateTrackerDbPersistence.d.ts +12 -0
- package/src/tools/queue/JobStateTrackerDbPersistence.d.ts.map +1 -0
- package/src/tools/queue/JobStateTrackerDbPersistence.js +239 -0
- package/src/tools/queue/Queue.d.ts.map +1 -1
- package/src/tools/queue/Queue.js +160 -16
- package/src/tools/queue/QueueDataRedactor.d.ts +6 -0
- package/src/tools/queue/QueueDataRedactor.d.ts.map +1 -0
- package/src/tools/queue/QueueDataRedactor.js +45 -0
- package/src/tools/queue/QueueExtensions.d.ts.map +1 -1
- package/src/tools/queue/QueueExtensions.js +2 -1
- package/src/tools/queue/QueueReliabilityMetrics.d.ts +38 -0
- package/src/tools/queue/QueueReliabilityMetrics.d.ts.map +1 -0
- package/src/tools/queue/QueueReliabilityMetrics.js +131 -0
- package/src/tools/queue/QueueReliabilityOrchestrator.d.ts +7 -0
- package/src/tools/queue/QueueReliabilityOrchestrator.d.ts.map +1 -0
- package/src/tools/queue/QueueReliabilityOrchestrator.js +59 -0
- package/src/tools/queue/QueueRuntimeRegistration.d.ts +1 -9
- package/src/tools/queue/QueueRuntimeRegistration.d.ts.map +1 -1
- package/src/tools/queue/QueueRuntimeRegistration.js +75 -4
- package/src/tools/queue/QueueTracing.d.ts +32 -0
- package/src/tools/queue/QueueTracing.d.ts.map +1 -0
- package/src/tools/queue/QueueTracing.js +151 -0
- package/src/tools/queue/StalledJobMonitor.d.ts +5 -0
- package/src/tools/queue/StalledJobMonitor.d.ts.map +1 -0
- package/src/tools/queue/StalledJobMonitor.js +21 -0
- package/src/tools/queue/TimeoutManager.d.ts +14 -0
- package/src/tools/queue/TimeoutManager.d.ts.map +1 -0
- package/src/tools/queue/TimeoutManager.js +77 -0
- package/src/tools/queue/drivers/Redis.d.ts +1 -0
- package/src/tools/queue/drivers/Redis.d.ts.map +1 -1
- package/src/tools/queue/drivers/Redis.js +1 -0
- package/src/tools/queue/index.d.ts +10 -0
- package/src/tools/queue/index.d.ts.map +1 -1
- package/src/tools/queue/index.js +10 -0
- package/src/tools/storage/drivers/R2.d.ts +13 -0
- package/src/tools/storage/drivers/R2.d.ts.map +1 -1
- package/src/tools/storage/drivers/R2.js +29 -0
- package/src/zintrust.plugins.d.ts +9 -0
- package/src/zintrust.plugins.d.ts.map +1 -0
- package/src/zintrust.plugins.js +7 -0
- package/src/zintrust.plugins.wg.d.ts +9 -0
- package/src/zintrust.plugins.wg.d.ts.map +1 -0
- package/src/zintrust.plugins.wg.js +7 -0
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
import { Env } from '../../config/env.js';
|
|
2
|
+
import { Logger } from '../../config/logger.js';
|
|
3
|
+
import { ErrorFactory } from '../../exceptions/ZintrustError.js';
|
|
4
|
+
import { isNonEmptyString, isObject } from '../../helper/index.js';
|
|
5
|
+
import { SmtpDriver, } from '../../tools/mail/drivers/Smtp.js';
|
|
6
|
+
import { ErrorHandler } from '../ErrorHandler.js';
|
|
7
|
+
import { createProxyServer } from '../ProxyServer.js';
|
|
8
|
+
import { resolveProxySigningConfig } from '../ProxySigningConfigResolver.js';
|
|
9
|
+
import { extractSigningHeaders, verifyProxySignatureIfNeeded } from '../ProxySigningRequest.js';
|
|
10
|
+
import { RequestValidator } from '../RequestValidator.js';
|
|
11
|
+
import { SigningService } from '../SigningService.js';
|
|
12
|
+
const normalizeSecure = (value) => {
|
|
13
|
+
if (value === true || value === false)
|
|
14
|
+
return value;
|
|
15
|
+
if (typeof value === 'string') {
|
|
16
|
+
const raw = value.trim().toLowerCase();
|
|
17
|
+
if (raw === '')
|
|
18
|
+
return undefined;
|
|
19
|
+
if (raw === 'starttls')
|
|
20
|
+
return 'starttls';
|
|
21
|
+
if (['tls', 'ssl', 'smtps', 'implicit', 'true', '1', 'yes', 'y'].includes(raw))
|
|
22
|
+
return true;
|
|
23
|
+
if (['false', '0', 'no', 'n'].includes(raw))
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
return undefined;
|
|
27
|
+
};
|
|
28
|
+
const resolveProxyConfig = (overrides = {}) => {
|
|
29
|
+
const host = overrides.host ?? Env.get('SMTP_PROXY_HOST', Env.HOST ?? '127.0.0.1');
|
|
30
|
+
const port = overrides.port ?? Env.getInt('SMTP_PROXY_PORT', Env.PORT ?? 8794);
|
|
31
|
+
const maxBodyBytes = overrides.maxBodyBytes ?? Env.getInt('SMTP_PROXY_MAX_BODY_BYTES', Env.MAX_BODY_SIZE ?? 131072);
|
|
32
|
+
return { host, port, maxBodyBytes };
|
|
33
|
+
};
|
|
34
|
+
const resolveSmtpConfig = (overrides = {}) => {
|
|
35
|
+
const host = overrides.smtpHost ?? Env.get('MAIL_HOST', '');
|
|
36
|
+
const port = overrides.smtpPort ?? Env.getInt('MAIL_PORT', 587);
|
|
37
|
+
const username = overrides.smtpUsername ?? Env.get('MAIL_USERNAME', '');
|
|
38
|
+
const password = overrides.smtpPassword ?? Env.get('MAIL_PASSWORD', '');
|
|
39
|
+
const secureRaw = overrides.smtpSecure ?? Env.get('MAIL_SECURE', '');
|
|
40
|
+
const secure = normalizeSecure(secureRaw) ?? false;
|
|
41
|
+
return { host, port, username, password, secure };
|
|
42
|
+
};
|
|
43
|
+
const resolveSigningConfig = (overrides = {}) => resolveProxySigningConfig(overrides, {
|
|
44
|
+
keyIdEnvVar: 'SMTP_PROXY_KEY_ID',
|
|
45
|
+
secretEnvVar: 'SMTP_PROXY_SECRET',
|
|
46
|
+
requireEnvVar: 'SMTP_PROXY_REQUIRE_SIGNING',
|
|
47
|
+
windowEnvVar: 'SMTP_PROXY_SIGNING_WINDOW_MS',
|
|
48
|
+
});
|
|
49
|
+
const resolveConfig = (overrides = {}) => {
|
|
50
|
+
const proxyConfig = resolveProxyConfig(overrides);
|
|
51
|
+
const smtpConfig = resolveSmtpConfig(overrides);
|
|
52
|
+
const signingConfig = resolveSigningConfig(overrides);
|
|
53
|
+
return {
|
|
54
|
+
host: proxyConfig.host,
|
|
55
|
+
port: proxyConfig.port,
|
|
56
|
+
maxBodyBytes: proxyConfig.maxBodyBytes,
|
|
57
|
+
smtp: smtpConfig,
|
|
58
|
+
signing: {
|
|
59
|
+
keyId: signingConfig.keyId,
|
|
60
|
+
secret: signingConfig.secret,
|
|
61
|
+
require: signingConfig.requireSigning,
|
|
62
|
+
windowMs: signingConfig.signingWindowMs,
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
const validateSmtpConfig = (config) => {
|
|
67
|
+
if (config.host.trim() === '') {
|
|
68
|
+
throw ErrorFactory.createConfigError('SMTP proxy missing MAIL_HOST');
|
|
69
|
+
}
|
|
70
|
+
if (!Number.isFinite(config.port) || config.port <= 0) {
|
|
71
|
+
throw ErrorFactory.createConfigError('SMTP proxy MAIL_PORT must be a positive integer');
|
|
72
|
+
}
|
|
73
|
+
const username = config.username ?? '';
|
|
74
|
+
const password = config.password ?? '';
|
|
75
|
+
if ((username.trim() !== '' && password.trim() === '') ||
|
|
76
|
+
(username.trim() === '' && password.trim() !== '')) {
|
|
77
|
+
throw ErrorFactory.createConfigError('SMTP proxy requires both MAIL_USERNAME and MAIL_PASSWORD');
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
const verifySignatureIfNeeded = async (req, body, config) => {
|
|
81
|
+
const headers = extractSigningHeaders(req);
|
|
82
|
+
if (SigningService.shouldVerify(config.signing, headers)) {
|
|
83
|
+
const verified = await verifyProxySignatureIfNeeded(req, body, config.signing);
|
|
84
|
+
if (!verified.ok) {
|
|
85
|
+
const normalizedSigning = typeof SigningService['normalizeConfig'] === 'function'
|
|
86
|
+
? SigningService['normalizeConfig'](config.signing)
|
|
87
|
+
: config.signing;
|
|
88
|
+
Logger.warn('[SmtpProxy] Signing verification failed', {
|
|
89
|
+
code: 'INVALID_SIGNATURE',
|
|
90
|
+
message: verified.error?.message ?? 'Invalid signature',
|
|
91
|
+
keyId: headers['x-zt-key-id'],
|
|
92
|
+
expectedKeyId: normalizedSigning.keyId,
|
|
93
|
+
requireSigning: normalizedSigning.require,
|
|
94
|
+
});
|
|
95
|
+
return {
|
|
96
|
+
ok: false,
|
|
97
|
+
error: {
|
|
98
|
+
status: verified.error?.status ?? 401,
|
|
99
|
+
message: verified.error?.message ?? 'Unauthorized',
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return { ok: true };
|
|
105
|
+
};
|
|
106
|
+
const isRecord = (value) => isObject(value);
|
|
107
|
+
const parseAttachment = (value) => {
|
|
108
|
+
if (!isRecord(value)) {
|
|
109
|
+
return {
|
|
110
|
+
ok: false,
|
|
111
|
+
error: { code: 'VALIDATION_ERROR', message: 'attachments must be objects' },
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
const filename = value['filename'];
|
|
115
|
+
const contentBase64 = value['contentBase64'];
|
|
116
|
+
if (!isNonEmptyString(filename)) {
|
|
117
|
+
return {
|
|
118
|
+
ok: false,
|
|
119
|
+
error: { code: 'VALIDATION_ERROR', message: 'attachment filename is required' },
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
if (!isNonEmptyString(contentBase64)) {
|
|
123
|
+
return {
|
|
124
|
+
ok: false,
|
|
125
|
+
error: { code: 'VALIDATION_ERROR', message: 'attachment contentBase64 is required' },
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
const content = Buffer.from(contentBase64, 'base64');
|
|
129
|
+
return { ok: true, value: { filename, content } };
|
|
130
|
+
};
|
|
131
|
+
const parseTo = (value) => {
|
|
132
|
+
if (typeof value === 'string' || Array.isArray(value)) {
|
|
133
|
+
return { ok: true, value: value };
|
|
134
|
+
}
|
|
135
|
+
return {
|
|
136
|
+
ok: false,
|
|
137
|
+
error: { code: 'VALIDATION_ERROR', message: 'to must be a string or array' },
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
const parseFrom = (value) => {
|
|
141
|
+
if (!isRecord(value)) {
|
|
142
|
+
return { ok: false, error: { code: 'VALIDATION_ERROR', message: 'from is required' } };
|
|
143
|
+
}
|
|
144
|
+
const email = value['email'];
|
|
145
|
+
const name = value['name'];
|
|
146
|
+
if (!isNonEmptyString(email)) {
|
|
147
|
+
return { ok: false, error: { code: 'VALIDATION_ERROR', message: 'from.email is required' } };
|
|
148
|
+
}
|
|
149
|
+
return {
|
|
150
|
+
ok: true,
|
|
151
|
+
value: {
|
|
152
|
+
email,
|
|
153
|
+
name: isNonEmptyString(name) ? name : undefined,
|
|
154
|
+
},
|
|
155
|
+
};
|
|
156
|
+
};
|
|
157
|
+
const parseHtml = (value) => {
|
|
158
|
+
if (value === undefined)
|
|
159
|
+
return { ok: true, value: undefined };
|
|
160
|
+
if (typeof value === 'string')
|
|
161
|
+
return { ok: true, value };
|
|
162
|
+
return { ok: false, error: { code: 'VALIDATION_ERROR', message: 'html must be a string' } };
|
|
163
|
+
};
|
|
164
|
+
const parseAttachments = (value) => {
|
|
165
|
+
if (value === undefined)
|
|
166
|
+
return { ok: true, value: undefined };
|
|
167
|
+
if (!Array.isArray(value)) {
|
|
168
|
+
return {
|
|
169
|
+
ok: false,
|
|
170
|
+
error: { code: 'VALIDATION_ERROR', message: 'attachments must be an array' },
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
const attachments = [];
|
|
174
|
+
for (const entry of value) {
|
|
175
|
+
const parsed = parseAttachment(entry);
|
|
176
|
+
if (!parsed.ok)
|
|
177
|
+
return parsed;
|
|
178
|
+
attachments.push(parsed.value);
|
|
179
|
+
}
|
|
180
|
+
return { ok: true, value: attachments };
|
|
181
|
+
};
|
|
182
|
+
const parseMessagePayload = (payload) => {
|
|
183
|
+
const messageRaw = payload['message'];
|
|
184
|
+
if (!isRecord(messageRaw)) {
|
|
185
|
+
return { ok: false, error: { code: 'VALIDATION_ERROR', message: 'message is required' } };
|
|
186
|
+
}
|
|
187
|
+
const toParsed = parseTo(messageRaw['to']);
|
|
188
|
+
if (!toParsed.ok)
|
|
189
|
+
return toParsed;
|
|
190
|
+
const fromParsed = parseFrom(messageRaw['from']);
|
|
191
|
+
if (!fromParsed.ok)
|
|
192
|
+
return fromParsed;
|
|
193
|
+
const subject = messageRaw['subject'];
|
|
194
|
+
if (typeof subject !== 'string' || subject.trim() === '') {
|
|
195
|
+
return { ok: false, error: { code: 'VALIDATION_ERROR', message: 'subject is required' } };
|
|
196
|
+
}
|
|
197
|
+
const text = messageRaw['text'];
|
|
198
|
+
if (typeof text !== 'string' || text.trim() === '') {
|
|
199
|
+
return { ok: false, error: { code: 'VALIDATION_ERROR', message: 'text is required' } };
|
|
200
|
+
}
|
|
201
|
+
const htmlParsed = parseHtml(messageRaw['html']);
|
|
202
|
+
if (!htmlParsed.ok)
|
|
203
|
+
return htmlParsed;
|
|
204
|
+
const attachmentsParsed = parseAttachments(messageRaw['attachments']);
|
|
205
|
+
if (!attachmentsParsed.ok)
|
|
206
|
+
return attachmentsParsed;
|
|
207
|
+
return {
|
|
208
|
+
ok: true,
|
|
209
|
+
value: {
|
|
210
|
+
to: toParsed.value,
|
|
211
|
+
from: fromParsed.value,
|
|
212
|
+
subject,
|
|
213
|
+
text,
|
|
214
|
+
html: htmlParsed.value,
|
|
215
|
+
attachments: attachmentsParsed.value,
|
|
216
|
+
},
|
|
217
|
+
};
|
|
218
|
+
};
|
|
219
|
+
const createBackend = (config) => ({
|
|
220
|
+
name: 'smtp',
|
|
221
|
+
handle: async (request) => {
|
|
222
|
+
const methodError = RequestValidator.requirePost(request.method);
|
|
223
|
+
Logger.info('[SmtpProxy] Received request', { path: request.path, method: request.method });
|
|
224
|
+
if (methodError) {
|
|
225
|
+
return ErrorHandler.toProxyError(405, methodError.code, methodError.message);
|
|
226
|
+
}
|
|
227
|
+
if (request.path !== '/zin/smtp/send') {
|
|
228
|
+
Logger.warn('[SmtpProxy] 404 Not Found', { path: request.path });
|
|
229
|
+
return ErrorHandler.toProxyError(404, 'NOT_FOUND', 'Unknown endpoint');
|
|
230
|
+
}
|
|
231
|
+
const parsed = RequestValidator.parseJson(request.body);
|
|
232
|
+
if (!parsed.ok) {
|
|
233
|
+
return ErrorHandler.toProxyError(400, parsed.error.code, parsed.error.message);
|
|
234
|
+
}
|
|
235
|
+
const messageValidation = parseMessagePayload(parsed.value);
|
|
236
|
+
if (!messageValidation.ok) {
|
|
237
|
+
return ErrorHandler.toProxyError(400, messageValidation.error.code, messageValidation.error.message);
|
|
238
|
+
}
|
|
239
|
+
try {
|
|
240
|
+
Logger.info('[SmtpProxy] Sending email via SmtpDriver', { to: messageValidation.value.to });
|
|
241
|
+
await SmtpDriver.send(config.smtp, messageValidation.value);
|
|
242
|
+
Logger.info('[SmtpProxy] Email sent successfully');
|
|
243
|
+
return { status: 200, body: { ok: true } };
|
|
244
|
+
}
|
|
245
|
+
catch (error) {
|
|
246
|
+
Logger.error('[SmtpProxy] Failed to send email', error);
|
|
247
|
+
return ErrorHandler.toProxyError(500, 'SMTP_PROXY_ERROR', String(error));
|
|
248
|
+
}
|
|
249
|
+
},
|
|
250
|
+
async health() {
|
|
251
|
+
try {
|
|
252
|
+
validateSmtpConfig(config.smtp);
|
|
253
|
+
await Promise.resolve();
|
|
254
|
+
return { status: 200, body: { status: 'healthy' } };
|
|
255
|
+
}
|
|
256
|
+
catch (error) {
|
|
257
|
+
return ErrorHandler.toProxyError(503, 'UNHEALTHY', String(error));
|
|
258
|
+
}
|
|
259
|
+
},
|
|
260
|
+
});
|
|
261
|
+
const createVerifier = (config) => async (req, body) => {
|
|
262
|
+
const verified = await verifySignatureIfNeeded(req, body, config);
|
|
263
|
+
if (!verified.ok && verified.error) {
|
|
264
|
+
return { ok: false, status: verified.error.status, message: verified.error.message };
|
|
265
|
+
}
|
|
266
|
+
return { ok: true };
|
|
267
|
+
};
|
|
268
|
+
export const SmtpProxyServer = Object.freeze({
|
|
269
|
+
async start(overrides = {}) {
|
|
270
|
+
const config = resolveConfig(overrides);
|
|
271
|
+
validateSmtpConfig(config.smtp);
|
|
272
|
+
try {
|
|
273
|
+
Logger.info(`SMTP proxy config: proxyHost=${config.host} proxyPort=${config.port} smtpHost=${String(config.smtp.host)} smtpPort=${String(config.smtp.port)} smtpUser=${String(config.smtp.username ?? '')}`);
|
|
274
|
+
}
|
|
275
|
+
catch {
|
|
276
|
+
// noop
|
|
277
|
+
}
|
|
278
|
+
const backend = createBackend(config);
|
|
279
|
+
const server = createProxyServer({
|
|
280
|
+
host: config.host,
|
|
281
|
+
port: config.port,
|
|
282
|
+
maxBodyBytes: config.maxBodyBytes,
|
|
283
|
+
backend,
|
|
284
|
+
verify: createVerifier(config),
|
|
285
|
+
});
|
|
286
|
+
await server.start();
|
|
287
|
+
Logger.info(`SMTP proxy listening on http://${config.host}:${config.port}`);
|
|
288
|
+
},
|
|
289
|
+
});
|
|
290
|
+
export default SmtpProxyServer;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../../../src/proxy/smtp/register.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type BaseProxyOverrides } from '../ProxyServerUtils';
|
|
2
|
+
import type { SqlProxyDatabaseOverrides } from '../SqlProxyDbOverrides';
|
|
3
|
+
type ProxyOverrides = BaseProxyOverrides & SqlProxyDatabaseOverrides;
|
|
4
|
+
export declare const SqlServerProxyServer: Readonly<{
|
|
5
|
+
start(overrides?: ProxyOverrides): Promise<void>;
|
|
6
|
+
}>;
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=SqlServerProxyServer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SqlServerProxyServer.d.ts","sourceRoot":"","sources":["../../../../src/proxy/sqlserver/SqlServerProxyServer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,KAAK,EAA0B,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AAepG,KAAK,cAAc,GAAG,kBAAkB,GAAG,yBAAyB,CAAC;AAmOrE,eAAO,MAAM,oBAAoB;sBACR,cAAc,GAAQ,OAAO,CAAC,IAAI,CAAC;EAwC1D,CAAC"}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import * as Deps from '../SqlProxyServerDeps.js';
|
|
2
|
+
const resolveDatabaseConfig = (overrides = {}) => {
|
|
3
|
+
const dbHost = overrides.dbHost ?? Deps.Env.get('DB_HOST_MSSQL', Deps.Env.get('DB_HOST', '127.0.0.1'));
|
|
4
|
+
const dbPort = overrides.dbPort ?? Deps.Env.getInt('DB_PORT_MSSQL', 1433);
|
|
5
|
+
const dbName = overrides.dbName ?? Deps.Env.get('DB_DATABASE_MSSQL', 'zintrust');
|
|
6
|
+
const dbUser = overrides.dbUser ?? Deps.Env.get('DB_USERNAME_MSSQL', 'sa');
|
|
7
|
+
const dbPass = overrides.dbPass ?? Deps.Env.get('DB_PASSWORD_MSSQL', '');
|
|
8
|
+
const connectionLimit = overrides.connectionLimit ?? Deps.Env.getInt('SQLSERVER_PROXY_POOL_LIMIT', 10);
|
|
9
|
+
return { dbHost, dbPort, dbName, dbUser, dbPass, connectionLimit };
|
|
10
|
+
};
|
|
11
|
+
const resolveConfig = (overrides = {}) => {
|
|
12
|
+
const proxyConfig = Deps.resolveBaseConfig(overrides, 'SQLSERVER');
|
|
13
|
+
const dbConfig = resolveDatabaseConfig(overrides);
|
|
14
|
+
const signingConfig = Deps.resolveBaseSigningConfig(overrides, 'SQLSERVER');
|
|
15
|
+
const poolConfig = {
|
|
16
|
+
server: dbConfig.dbHost,
|
|
17
|
+
port: dbConfig.dbPort,
|
|
18
|
+
database: dbConfig.dbName,
|
|
19
|
+
user: dbConfig.dbUser,
|
|
20
|
+
password: dbConfig.dbPass,
|
|
21
|
+
pool: {
|
|
22
|
+
max: dbConfig.connectionLimit,
|
|
23
|
+
min: 0,
|
|
24
|
+
idleTimeoutMillis: 30000,
|
|
25
|
+
},
|
|
26
|
+
options: {
|
|
27
|
+
encrypt: false,
|
|
28
|
+
trustServerCertificate: true,
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
return {
|
|
32
|
+
host: proxyConfig.host,
|
|
33
|
+
port: proxyConfig.port,
|
|
34
|
+
maxBodyBytes: proxyConfig.maxBodyBytes,
|
|
35
|
+
poolConfig,
|
|
36
|
+
signing: {
|
|
37
|
+
keyId: signingConfig.keyId,
|
|
38
|
+
secret: signingConfig.secret,
|
|
39
|
+
require: signingConfig.requireSigning,
|
|
40
|
+
windowMs: signingConfig.signingWindowMs,
|
|
41
|
+
},
|
|
42
|
+
statements: Deps.loadStatementRegistry('SQLSERVER'),
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
const validateQueryPayload = (payload) => {
|
|
46
|
+
const base = Deps.validateSqlPayload(payload);
|
|
47
|
+
if (!base.valid) {
|
|
48
|
+
return { valid: false, error: base.error };
|
|
49
|
+
}
|
|
50
|
+
if (base.sql.trim() === '') {
|
|
51
|
+
return { valid: false, error: { code: 'VALIDATION_ERROR', message: 'sql is required' } };
|
|
52
|
+
}
|
|
53
|
+
return { valid: true, sql: base.sql, params: base.params };
|
|
54
|
+
};
|
|
55
|
+
const getSqlModule = async () => {
|
|
56
|
+
const mod = await import('mssql');
|
|
57
|
+
return mod;
|
|
58
|
+
};
|
|
59
|
+
const createPool = async (config) => {
|
|
60
|
+
const mod = await getSqlModule();
|
|
61
|
+
const connect = mod['connect'];
|
|
62
|
+
return connect(config);
|
|
63
|
+
};
|
|
64
|
+
const executeQuery = async (pool, sqlQuery, params) => {
|
|
65
|
+
const requestFunc = pool['request'];
|
|
66
|
+
const request = requestFunc();
|
|
67
|
+
params.forEach((param, index) => {
|
|
68
|
+
const inputFunc = request['input'];
|
|
69
|
+
inputFunc(`param${index}`, param);
|
|
70
|
+
});
|
|
71
|
+
const queryFunc = request['query'];
|
|
72
|
+
return queryFunc(sqlQuery);
|
|
73
|
+
};
|
|
74
|
+
const handleEndpoint = (path, result) => {
|
|
75
|
+
const rows = result['recordset'];
|
|
76
|
+
const rowsAffected = result['rowsAffected'];
|
|
77
|
+
if (path === '/zin/sqlserver/query') {
|
|
78
|
+
return { status: 200, body: { rows, rowCount: rowsAffected[0] ?? 0 } };
|
|
79
|
+
}
|
|
80
|
+
if (path === '/zin/sqlserver/queryOne') {
|
|
81
|
+
const firstRow = Array.isArray(rows) ? rows[0] : null;
|
|
82
|
+
return { status: 200, body: { row: firstRow ?? null } };
|
|
83
|
+
}
|
|
84
|
+
if (path === '/zin/sqlserver/exec') {
|
|
85
|
+
return {
|
|
86
|
+
status: 200,
|
|
87
|
+
body: {
|
|
88
|
+
ok: true,
|
|
89
|
+
meta: { changes: rowsAffected[0] ?? 0 },
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
if (path === '/zin/sqlserver/statement') {
|
|
94
|
+
// Statement endpoint returns query-shaped response for non-mutating SQL.
|
|
95
|
+
return { status: 200, body: { rows, rowCount: rowsAffected[0] ?? 0 } };
|
|
96
|
+
}
|
|
97
|
+
return Deps.ErrorHandler.toProxyError(404, 'NOT_FOUND', 'Unknown endpoint');
|
|
98
|
+
};
|
|
99
|
+
const toMutatingStatementResponse = (result) => {
|
|
100
|
+
const rowsAffected = result['rowsAffected'];
|
|
101
|
+
return {
|
|
102
|
+
status: 200,
|
|
103
|
+
body: {
|
|
104
|
+
ok: true,
|
|
105
|
+
meta: { changes: rowsAffected[0] ?? 0 },
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
const handleStatementRequest = async (pool, statements, requestPath, payload) => {
|
|
110
|
+
const resolved = Deps.resolveStatementOrError(statements, payload);
|
|
111
|
+
if (!resolved.ok)
|
|
112
|
+
return resolved.response;
|
|
113
|
+
try {
|
|
114
|
+
const result = await executeQuery(pool, resolved.value.sql, resolved.value.params);
|
|
115
|
+
if (!resolved.value.mutating)
|
|
116
|
+
return handleEndpoint('/zin/sqlserver/statement', result);
|
|
117
|
+
return toMutatingStatementResponse(result);
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
Deps.Logger.error('[SqlServerProxyServer] Statement execution failed', {
|
|
121
|
+
path: requestPath,
|
|
122
|
+
statementId: resolved.value.statementId,
|
|
123
|
+
mutating: resolved.value.mutating,
|
|
124
|
+
paramsCount: resolved.value.params.length,
|
|
125
|
+
error: error instanceof Error ? error.message : String(error),
|
|
126
|
+
});
|
|
127
|
+
return Deps.ErrorHandler.toProxyError(500, 'SQLSERVER_ERROR', String(error));
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
const handleSqlRequest = async (pool, requestPath, payload) => {
|
|
131
|
+
const sqlValidation = validateQueryPayload(payload);
|
|
132
|
+
if (!sqlValidation.valid) {
|
|
133
|
+
const error = sqlValidation.error ?? {
|
|
134
|
+
code: 'VALIDATION_ERROR',
|
|
135
|
+
message: 'Invalid SQL payload',
|
|
136
|
+
};
|
|
137
|
+
return Deps.ErrorHandler.toProxyError(400, error.code, error.message);
|
|
138
|
+
}
|
|
139
|
+
try {
|
|
140
|
+
const result = await executeQuery(pool, sqlValidation.sql ?? '', sqlValidation.params ?? []);
|
|
141
|
+
return handleEndpoint(requestPath, result);
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
return Deps.ErrorHandler.toProxyError(500, 'SQLSERVER_ERROR', String(error));
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
const handleProxyRequest = async (pool, statements, request) => {
|
|
148
|
+
const validationError = Deps.validateProxyRequest(request);
|
|
149
|
+
if (validationError !== null)
|
|
150
|
+
return validationError;
|
|
151
|
+
const parsed = Deps.parseJsonBody(request.body);
|
|
152
|
+
if ('status' in parsed)
|
|
153
|
+
return parsed;
|
|
154
|
+
if (request.path === '/zin/sqlserver/statement') {
|
|
155
|
+
return handleStatementRequest(pool, statements, request.path, parsed.value);
|
|
156
|
+
}
|
|
157
|
+
return handleSqlRequest(pool, request.path, parsed.value);
|
|
158
|
+
};
|
|
159
|
+
const createBackend = (pool, statements) => ({
|
|
160
|
+
name: 'sqlserver',
|
|
161
|
+
handle: async (request) => handleProxyRequest(pool, statements, request),
|
|
162
|
+
health: async () => {
|
|
163
|
+
try {
|
|
164
|
+
await executeQuery(pool, 'SELECT 1', []);
|
|
165
|
+
return { status: 200, body: { status: 'healthy' } };
|
|
166
|
+
}
|
|
167
|
+
catch (error) {
|
|
168
|
+
return Deps.ErrorHandler.toProxyError(503, 'UNHEALTHY', String(error));
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
shutdown: async () => {
|
|
172
|
+
const closeFunc = pool['close'];
|
|
173
|
+
await closeFunc();
|
|
174
|
+
},
|
|
175
|
+
});
|
|
176
|
+
export const SqlServerProxyServer = Object.freeze({
|
|
177
|
+
async start(overrides = {}) {
|
|
178
|
+
const config = resolveConfig(overrides);
|
|
179
|
+
try {
|
|
180
|
+
Deps.Logger.info(`SQL Server proxy config: proxyHost=${config.host} proxyPort=${config.port} dbHost=${String(config.poolConfig['server'])} dbPort=${String(config.poolConfig['port'])} dbName=${String(config.poolConfig['database'])} dbUser=${String(config.poolConfig['user'])}`);
|
|
181
|
+
}
|
|
182
|
+
catch {
|
|
183
|
+
// noop - logging must not block startup
|
|
184
|
+
}
|
|
185
|
+
const pool = await createPool(config.poolConfig);
|
|
186
|
+
const backend = createBackend(pool, config.statements);
|
|
187
|
+
const proxy = Deps.createProxyServer({
|
|
188
|
+
host: config.host,
|
|
189
|
+
port: config.port,
|
|
190
|
+
maxBodyBytes: config.maxBodyBytes,
|
|
191
|
+
backend,
|
|
192
|
+
verify: async (req, body) => {
|
|
193
|
+
const verified = await Deps.verifyRequestSignature(req, body, config, 'SqlServerProxyServer');
|
|
194
|
+
if (!verified.ok && verified.error) {
|
|
195
|
+
return { ok: false, status: verified.error.status, message: verified.error.message };
|
|
196
|
+
}
|
|
197
|
+
return { ok: true };
|
|
198
|
+
},
|
|
199
|
+
});
|
|
200
|
+
await proxy.start();
|
|
201
|
+
Deps.Logger.info(`✓ SQL Server proxy listening on ${config.host}:${config.port}`);
|
|
202
|
+
},
|
|
203
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../../../src/proxy/sqlserver/register.ts"],"names":[],"mappings":""}
|
package/src/proxy.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../../src/proxy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC"}
|
package/src/proxy.js
ADDED
package/src/routes/doc.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"doc.d.ts","sourceRoot":"","sources":["../../../src/routes/doc.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAInD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAIhD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD;;GAEG;AAEH,OAAO,EACL,eAAe,EACf,oBAAoB,EACpB,uBAAuB,EACvB,4BAA4B,EAC5B,aAAa,EACb,kBAAkB,GACnB,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"doc.d.ts","sourceRoot":"","sources":["../../../src/routes/doc.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAInD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAIhD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD;;GAEG;AAEH,OAAO,EACL,eAAe,EACf,oBAAoB,EACpB,uBAAuB,EACvB,4BAA4B,EAC5B,aAAa,EACb,kBAAkB,GACnB,MAAM,yBAAyB,CAAC;AAkCjC;;GAEG;AACH,eAAO,MAAM,0BAA0B,GAAI,UAAU,SAAS,KAAG,IAWhE,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,2BAA2B,GACtC,SAAS,MAAM,EACf,UAAU,SAAS,KAClB,OAAO,CAAC,OAAO,CAgDjB,CAAC;AASF,eAAO,MAAM,iBAAiB,GAAI,QAAQ,OAAO,KAAG,IAMnD,CAAC;;gCANwC,OAAO,KAAG,IAAI;2CA5EH,SAAS,KAAG,IAAI;2CAiB1D,MAAM,YACL,SAAS,KAClB,OAAO,CAAC,OAAO,CAAC;;AAiEnB,wBAIE"}
|
package/src/routes/doc.js
CHANGED
|
@@ -16,8 +16,22 @@ export { MIME_TYPES_MAP } from './common.js';
|
|
|
16
16
|
*/
|
|
17
17
|
// Backward-compatible re-exports
|
|
18
18
|
export { findPackageRoot, findPackageRootAsync, getFrameworkPublicRoots, getFrameworkPublicRootsAsync, getPublicRoot, getPublicRootAsync, } from './publicRoot.js';
|
|
19
|
+
const PUBLIC_ROOT_CACHE_TTL_MS = 3000000000; //50 minutes, effectively caching for the duration of typical dev sessions
|
|
20
|
+
let cachedPublicRoot = null;
|
|
21
|
+
const getCachedPublicRootAsync = async () => {
|
|
22
|
+
const now = Date.now();
|
|
23
|
+
if (cachedPublicRoot !== null && cachedPublicRoot.expiresAt > now) {
|
|
24
|
+
return cachedPublicRoot.value;
|
|
25
|
+
}
|
|
26
|
+
const resolved = await getPublicRootAsync();
|
|
27
|
+
cachedPublicRoot = {
|
|
28
|
+
value: resolved,
|
|
29
|
+
expiresAt: now + PUBLIC_ROOT_CACHE_TTL_MS,
|
|
30
|
+
};
|
|
31
|
+
return resolved;
|
|
32
|
+
};
|
|
19
33
|
const mapStaticPathAsync = async (urlPath) => {
|
|
20
|
-
const publicRoot = await
|
|
34
|
+
const publicRoot = await getCachedPublicRootAsync();
|
|
21
35
|
const normalize = (p) => (p.startsWith('/') ? p.slice(1) : p);
|
|
22
36
|
if (urlPath === '/doc' || urlPath === '/doc/')
|
|
23
37
|
return publicRoot;
|
|
@@ -94,7 +108,7 @@ const handleDocRequest = async (req, res) => {
|
|
|
94
108
|
const urlPath = req.getPath();
|
|
95
109
|
if (await serveDocumentationFileAsync(urlPath, res))
|
|
96
110
|
return;
|
|
97
|
-
ErrorRouting.handleNotFound(req, res);
|
|
111
|
+
await ErrorRouting.handleNotFound(req, res);
|
|
98
112
|
};
|
|
99
113
|
export const registerDocRoutes = (router) => {
|
|
100
114
|
// Root docs entrypoints.
|
package/src/routes/error.d.ts
CHANGED
|
@@ -10,12 +10,13 @@ import type * as http from '../node-singletons/http';
|
|
|
10
10
|
* Debug routes to always render 404/500 responses.
|
|
11
11
|
*/
|
|
12
12
|
export declare const registerErrorRoutes: (router: IRouter) => void;
|
|
13
|
-
|
|
13
|
+
type ErrorRoutingApi = {
|
|
14
14
|
getPublicRoot: () => string;
|
|
15
15
|
registerErrorRoutes: (router: IRouter) => void;
|
|
16
|
-
handleNotFound: (request: IRequest, response: IResponse, requestId?: string) => void
|
|
17
|
-
handleInternalServerErrorWithWrappers: (request: IRequest, response: IResponse, error: unknown, requestId?: string) => void
|
|
16
|
+
handleNotFound: (request: IRequest, response: IResponse, requestId?: string) => Promise<void>;
|
|
17
|
+
handleInternalServerErrorWithWrappers: (request: IRequest, response: IResponse, error: unknown, requestId?: string) => Promise<void>;
|
|
18
18
|
handleInternalServerErrorRaw: (res: http.ServerResponse) => void;
|
|
19
|
-
}
|
|
19
|
+
};
|
|
20
|
+
export declare const ErrorRouting: ErrorRoutingApi;
|
|
20
21
|
export default ErrorRouting;
|
|
21
22
|
//# sourceMappingURL=error.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../../src/routes/error.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../../src/routes/error.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAUH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAKnD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,KAAK,KAAK,IAAI,MAAM,uBAAuB,CAAC;AA0KnD;;GAEG;AACH,eAAO,MAAM,mBAAmB,GAAI,QAAQ,OAAO,KAAG,IAGrD,CAAC;AAEF,KAAK,eAAe,GAAG;IACrB,aAAa,EAAE,MAAM,MAAM,CAAC;IAC5B,mBAAmB,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;IAC/C,cAAc,EAAE,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9F,qCAAqC,EAAE,CACrC,OAAO,EAAE,QAAQ,EACjB,QAAQ,EAAE,SAAS,EACnB,KAAK,EAAE,OAAO,EACd,SAAS,CAAC,EAAE,MAAM,KACf,OAAO,CAAC,IAAI,CAAC,CAAC;IACnB,4BAA4B,EAAE,CAAC,GAAG,EAAE,IAAI,CAAC,cAAc,KAAK,IAAI,CAAC;CAClE,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,eAMzB,CAAC;AAEH,eAAe,YAAY,CAAC"}
|