@zintrust/core 0.1.40 → 0.1.41
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 +8 -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 +23 -5
- 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 +353 -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 +82 -34
- package/src/cli/ErrorHandler.js +1 -1
- 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/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 +216 -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/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/QueueRecoveryCommand.d.ts +6 -0
- package/src/cli/commands/QueueRecoveryCommand.d.ts.map +1 -0
- package/src/cli/commands/QueueRecoveryCommand.js +513 -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/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/d1/D1SqlMigrations.d.ts.map +1 -1
- package/src/cli/d1/D1SqlMigrations.js +3 -0
- 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/utils/EnvFileLoader.js +16 -15
- package/src/cli/workers/QueueWorkRunner.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 +39 -13
- 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/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 +48 -0
- 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 +156 -17
- 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/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 +25 -53
- package/src/index.d.ts.map +1 -1
- package/src/index.js +30 -14
- 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/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/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/adapters/D1RemoteAdapter.d.ts.map +1 -1
- package/src/orm/adapters/D1RemoteAdapter.js +14 -1
- 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 +143 -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 +147 -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 +35 -0
- package/src/orm/adapters/SqlServerProxyAdapter.d.ts +3 -0
- package/src/orm/adapters/SqlServerProxyAdapter.d.ts.map +1 -0
- package/src/orm/adapters/SqlServerProxyAdapter.js +146 -0
- 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/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 +25 -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/d1/ZintrustD1Proxy.d.ts +2 -0
- package/src/proxy/d1/ZintrustD1Proxy.d.ts.map +1 -0
- package/src/proxy/d1/ZintrustD1Proxy.js +1 -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/kv/ZintrustKvProxy.d.ts +2 -0
- package/src/proxy/kv/ZintrustKvProxy.d.ts.map +1 -0
- package/src/proxy/kv/ZintrustKvProxy.js +1 -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 +14 -0
- package/src/proxy/mysql/MySqlProxyServer.d.ts.map +1 -0
- package/src/proxy/mysql/MySqlProxyServer.js +169 -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 +14 -0
- package/src/proxy/postgres/PostgresProxyServer.d.ts.map +1 -0
- package/src/proxy/postgres/PostgresProxyServer.js +140 -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 +289 -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 +14 -0
- package/src/proxy/sqlserver/SqlServerProxyServer.d.ts.map +1 -0
- package/src/proxy/sqlserver/SqlServerProxyServer.js +168 -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/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/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/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/project/basic/src/zintrust.plugins.wg.ts.tpl +8 -0
- package/src/tools/mail/drivers/Smtp.d.ts.map +1 -1
- package/src/tools/mail/drivers/Smtp.js +223 -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 +88 -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 +205 -0
- package/src/tools/queue/JobStateTracker.d.ts +131 -0
- package/src/tools/queue/JobStateTracker.d.ts.map +1 -0
- package/src/tools/queue/JobStateTracker.js +387 -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 +148 -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,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime Services
|
|
3
|
+
* Adapter layer for env/crypto/timers/fs/fetch across Node and Workers
|
|
4
|
+
* Sealed namespace for immutability
|
|
5
|
+
*/
|
|
6
|
+
import { Cloudflare } from '../config/cloudflare.js';
|
|
7
|
+
import { Env } from '../config/env.js';
|
|
8
|
+
import { ErrorFactory } from '../exceptions/ZintrustError.js';
|
|
9
|
+
import { randomUUID as nodeRandomUUID, randomBytes } from '../node-singletons/crypto.js';
|
|
10
|
+
import * as nodeFs from '../node-singletons/fs.js';
|
|
11
|
+
export const detectCloudflareWorkers = () => {
|
|
12
|
+
return Cloudflare.getWorkersEnv() !== null;
|
|
13
|
+
};
|
|
14
|
+
export const detectRuntimePlatform = () => {
|
|
15
|
+
if (detectCloudflareWorkers())
|
|
16
|
+
return 'cloudflare';
|
|
17
|
+
return 'nodejs';
|
|
18
|
+
};
|
|
19
|
+
export const RUNTIME_PLATFORM = detectRuntimePlatform();
|
|
20
|
+
const normalizeEnvValue = (value) => {
|
|
21
|
+
if (value === null || value === undefined)
|
|
22
|
+
return '';
|
|
23
|
+
if (typeof value === 'string')
|
|
24
|
+
return value;
|
|
25
|
+
if (typeof value === 'number' || typeof value === 'boolean' || typeof value === 'bigint') {
|
|
26
|
+
return String(value);
|
|
27
|
+
}
|
|
28
|
+
return '';
|
|
29
|
+
};
|
|
30
|
+
const readEnvFromRecord = (record, key) => {
|
|
31
|
+
return normalizeEnvValue(record[key]);
|
|
32
|
+
};
|
|
33
|
+
const createWorkersEnvReader = () => {
|
|
34
|
+
return {
|
|
35
|
+
get(key, defaultValue = '') {
|
|
36
|
+
const env = Cloudflare.getWorkersEnv() ?? {};
|
|
37
|
+
const value = readEnvFromRecord(env, key);
|
|
38
|
+
return value === '' ? defaultValue : value;
|
|
39
|
+
},
|
|
40
|
+
getInt(key, defaultValue = 0) {
|
|
41
|
+
const raw = this.get(key, String(defaultValue));
|
|
42
|
+
const parsed = Number.parseInt(raw, 10);
|
|
43
|
+
return Number.isFinite(parsed) ? parsed : defaultValue;
|
|
44
|
+
},
|
|
45
|
+
getFloat(key, defaultValue = 0) {
|
|
46
|
+
const raw = this.get(key, String(defaultValue));
|
|
47
|
+
const parsed = Number.parseFloat(raw);
|
|
48
|
+
return Number.isFinite(parsed) ? parsed : defaultValue;
|
|
49
|
+
},
|
|
50
|
+
getBool(key, defaultValue = false) {
|
|
51
|
+
const raw = this.get(key, defaultValue ? 'true' : 'false').toLowerCase();
|
|
52
|
+
if (raw === '')
|
|
53
|
+
return defaultValue;
|
|
54
|
+
return raw === 'true' || raw === '1';
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
const createNodeEnvReader = () => {
|
|
59
|
+
return {
|
|
60
|
+
get: (key, defaultValue) => Env.get(key, defaultValue),
|
|
61
|
+
getInt: (key, defaultValue) => Env.getInt(key, defaultValue ?? 0),
|
|
62
|
+
getFloat: (key, defaultValue) => Env.getFloat(key, defaultValue ?? 0),
|
|
63
|
+
getBool: (key, defaultValue) => Env.getBool(key, defaultValue),
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
const getWebCrypto = () => {
|
|
67
|
+
if (globalThis.crypto === undefined) {
|
|
68
|
+
throw ErrorFactory.createConfigError('WebCrypto is not available in this runtime');
|
|
69
|
+
}
|
|
70
|
+
return globalThis.crypto;
|
|
71
|
+
};
|
|
72
|
+
const fillRandomValues = (webCrypto, array) => {
|
|
73
|
+
if (typeof webCrypto.getRandomValues === 'function') {
|
|
74
|
+
return webCrypto.getRandomValues(array);
|
|
75
|
+
}
|
|
76
|
+
if (array instanceof BigInt64Array || array instanceof BigUint64Array) {
|
|
77
|
+
throw ErrorFactory.createConfigError('BigInt typed arrays require WebCrypto support');
|
|
78
|
+
}
|
|
79
|
+
const bytes = randomBytes(array.byteLength);
|
|
80
|
+
const view = new Uint8Array(array.buffer, array.byteOffset, array.byteLength);
|
|
81
|
+
view.set(bytes);
|
|
82
|
+
return array;
|
|
83
|
+
};
|
|
84
|
+
const createNodeCrypto = () => {
|
|
85
|
+
const webCrypto = getWebCrypto();
|
|
86
|
+
if (webCrypto.subtle === undefined) {
|
|
87
|
+
throw ErrorFactory.createConfigError('WebCrypto subtle is not available in Node runtime');
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
subtle: webCrypto.subtle,
|
|
91
|
+
getRandomValues: (array) => {
|
|
92
|
+
return fillRandomValues(webCrypto, array);
|
|
93
|
+
},
|
|
94
|
+
randomUUID: () => {
|
|
95
|
+
if (typeof webCrypto.randomUUID === 'function')
|
|
96
|
+
return webCrypto.randomUUID();
|
|
97
|
+
return nodeRandomUUID();
|
|
98
|
+
},
|
|
99
|
+
randomBytes: (size) => randomBytes(size),
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
const createWorkersCrypto = () => {
|
|
103
|
+
const webCrypto = getWebCrypto();
|
|
104
|
+
if (webCrypto.subtle === undefined) {
|
|
105
|
+
throw ErrorFactory.createConfigError('WebCrypto subtle is not available in Workers runtime');
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
subtle: webCrypto.subtle,
|
|
109
|
+
getRandomValues: (array) => webCrypto.getRandomValues(array),
|
|
110
|
+
randomUUID: () => {
|
|
111
|
+
if (typeof webCrypto.randomUUID === 'function')
|
|
112
|
+
return webCrypto.randomUUID();
|
|
113
|
+
return nodeRandomUUID();
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
const createNodeFs = () => {
|
|
118
|
+
return {
|
|
119
|
+
supported: true,
|
|
120
|
+
readFileSync: (path, encoding) => nodeFs.readFileSync(path, encoding),
|
|
121
|
+
readdirSync: (path) => nodeFs.readdirSync(path),
|
|
122
|
+
existsSync: (path) => nodeFs.existsSync(path),
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
const createWorkersFs = () => {
|
|
126
|
+
const unsupported = () => {
|
|
127
|
+
throw ErrorFactory.createConfigError('Filesystem access is not supported in Workers runtime');
|
|
128
|
+
};
|
|
129
|
+
return {
|
|
130
|
+
supported: false,
|
|
131
|
+
readFileSync: () => unsupported(),
|
|
132
|
+
readdirSync: () => unsupported(),
|
|
133
|
+
existsSync: () => false,
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
const createTimers = () => ({
|
|
137
|
+
setTimeout: globalThis.setTimeout.bind(globalThis),
|
|
138
|
+
clearTimeout: globalThis.clearTimeout.bind(globalThis),
|
|
139
|
+
setInterval: globalThis.setInterval.bind(globalThis),
|
|
140
|
+
clearInterval: globalThis.clearInterval.bind(globalThis),
|
|
141
|
+
});
|
|
142
|
+
export const RuntimeServices = Object.freeze({
|
|
143
|
+
create(platform) {
|
|
144
|
+
if (platform === 'cloudflare') {
|
|
145
|
+
return {
|
|
146
|
+
platform,
|
|
147
|
+
env: createWorkersEnvReader(),
|
|
148
|
+
crypto: createWorkersCrypto(),
|
|
149
|
+
timers: createTimers(),
|
|
150
|
+
fs: createWorkersFs(),
|
|
151
|
+
fetch: globalThis.fetch.bind(globalThis),
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
return {
|
|
155
|
+
platform,
|
|
156
|
+
env: createNodeEnvReader(),
|
|
157
|
+
crypto: createNodeCrypto(),
|
|
158
|
+
timers: createTimers(),
|
|
159
|
+
fs: createNodeFs(),
|
|
160
|
+
fetch: globalThis.fetch.bind(globalThis),
|
|
161
|
+
};
|
|
162
|
+
},
|
|
163
|
+
});
|
|
164
|
+
export default RuntimeServices;
|
|
@@ -9,12 +9,12 @@ export declare const StartupConfigFile: {
|
|
|
9
9
|
readonly Storage: "config/storage.ts";
|
|
10
10
|
readonly Workers: "config/workers.ts";
|
|
11
11
|
};
|
|
12
|
-
export type
|
|
12
|
+
export type StartupConfigFileTypes = typeof StartupConfigFile.Broadcast | typeof StartupConfigFile.Cache | typeof StartupConfigFile.Database | typeof StartupConfigFile.Mail | typeof StartupConfigFile.Middleware | typeof StartupConfigFile.Notification | typeof StartupConfigFile.Queue | typeof StartupConfigFile.Storage | typeof StartupConfigFile.Workers;
|
|
13
13
|
export declare const StartupConfigFileRegistry: Readonly<{
|
|
14
|
-
preload(files: readonly
|
|
14
|
+
preload(files: readonly StartupConfigFileTypes[]): Promise<void>;
|
|
15
15
|
isPreloaded(): boolean;
|
|
16
|
-
get<T>(file:
|
|
17
|
-
has(file:
|
|
16
|
+
get<T>(file: StartupConfigFileTypes): T | undefined;
|
|
17
|
+
has(file: StartupConfigFileTypes): boolean;
|
|
18
18
|
/** Intended for tests only. */
|
|
19
19
|
clear(): void;
|
|
20
20
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StartupConfigFileRegistry.d.ts","sourceRoot":"","sources":["../../../src/runtime/StartupConfigFileRegistry.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"StartupConfigFileRegistry.d.ts","sourceRoot":"","sources":["../../../src/runtime/StartupConfigFileRegistry.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,iBAAiB;;;;;;;;;;CAUpB,CAAC;AAEX,MAAM,MAAM,sBAAsB,GAC9B,OAAO,iBAAiB,CAAC,SAAS,GAClC,OAAO,iBAAiB,CAAC,KAAK,GAC9B,OAAO,iBAAiB,CAAC,QAAQ,GACjC,OAAO,iBAAiB,CAAC,IAAI,GAC7B,OAAO,iBAAiB,CAAC,UAAU,GACnC,OAAO,iBAAiB,CAAC,YAAY,GACrC,OAAO,iBAAiB,CAAC,KAAK,GAC9B,OAAO,iBAAiB,CAAC,OAAO,GAChC,OAAO,iBAAiB,CAAC,OAAO,CAAC;AAarC,eAAO,MAAM,yBAAyB;mBACf,SAAS,sBAAsB,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;mBAqBvD,OAAO;QAIlB,CAAC,QAAQ,sBAAsB,GAAG,CAAC,GAAG,SAAS;cAIzC,sBAAsB,GAAG,OAAO;IAI1C,+BAA+B;aACtB,IAAI;EAIb,CAAC;AAEH,eAAe,yBAAyB,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import useFileLoader from './useFileLoader.js';
|
|
2
|
+
// NOTE runtime config loader
|
|
2
3
|
export const StartupConfigFile = {
|
|
3
4
|
Broadcast: 'config/broadcast.ts',
|
|
4
5
|
Cache: 'config/cache.ts',
|
|
@@ -12,9 +13,20 @@ export const StartupConfigFile = {
|
|
|
12
13
|
};
|
|
13
14
|
const cache = new Map();
|
|
14
15
|
let preloaded = false;
|
|
16
|
+
const getWorkersStartupOverrides = () => {
|
|
17
|
+
if (typeof globalThis === 'undefined')
|
|
18
|
+
return undefined;
|
|
19
|
+
const globalAny = globalThis;
|
|
20
|
+
return globalAny.__zintrustStartupConfigOverrides;
|
|
21
|
+
};
|
|
15
22
|
export const StartupConfigFileRegistry = Object.freeze({
|
|
16
23
|
async preload(files) {
|
|
17
24
|
const tasks = files.map(async (file) => {
|
|
25
|
+
const overrides = getWorkersStartupOverrides();
|
|
26
|
+
if (overrides?.has(file) === true) {
|
|
27
|
+
cache.set(file, overrides.get(file));
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
18
30
|
const loader = useFileLoader(file);
|
|
19
31
|
if (!loader.exists()) {
|
|
20
32
|
cache.delete(file);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WorkerAdapterImports.d.ts","sourceRoot":"","sources":["../../../src/runtime/WorkerAdapterImports.ts"],"names":[],"mappings":"AAeA,eAAO,MAAM,oBAAoB;;;EAG/B,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Worker-only adapter auto-imports for bundler-based runtimes (e.g. Cloudflare Workers).
|
|
2
|
+
// Keep this list limited to database adapters needed by runtime config.
|
|
3
|
+
// These imports resolve against the host project (developer working directory)
|
|
4
|
+
// via the @/ alias configured by the ZinTrust app templates.
|
|
5
|
+
const tryImportOptional = async () => {
|
|
6
|
+
try {
|
|
7
|
+
await import('../zintrust.plugins.wg.js');
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
// Log and swallow errors since these are optional imports that may not exist in all projects.
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
const ready = await tryImportOptional();
|
|
14
|
+
export const WorkerAdapterImports = Object.freeze({
|
|
15
|
+
loaded: true,
|
|
16
|
+
ready,
|
|
17
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
type WorkersModule = typeof import('../../packages/workers/src/index.js');
|
|
2
|
+
type QueueMonitorModule = typeof import('../../packages/queue-monitor/src/index.js');
|
|
3
|
+
export declare const loadWorkersModule: () => Promise<WorkersModule>;
|
|
4
|
+
export declare const loadQueueMonitorModule: () => Promise<QueueMonitorModule>;
|
|
5
|
+
export {};
|
|
6
|
+
//# sourceMappingURL=WorkersModule.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WorkersModule.d.ts","sourceRoot":"","sources":["../../../src/runtime/WorkersModule.ts"],"names":[],"mappings":"AAOA,KAAK,aAAa,GAAG,cAAc,mBAAmB,CAAC,CAAC;AACxD,KAAK,kBAAkB,GAAG,cAAc,yBAAyB,CAAC,CAAC;AA8PnE,eAAO,MAAM,iBAAiB,QAAa,OAAO,CAAC,aAAa,CAiB/D,CAAC;AA2CF,eAAO,MAAM,sBAAsB,QAAa,OAAO,CAAC,kBAAkB,CAiBzE,CAAC"}
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import * as Common from '../common/index.js';
|
|
2
|
+
import { Logger } from '../config/logger.js';
|
|
3
|
+
import * as fs from '../node-singletons/fs.js';
|
|
4
|
+
import { createRequire } from '../node-singletons/module.js';
|
|
5
|
+
import * as path from '../node-singletons/path.js';
|
|
6
|
+
import { pathToFileURL } from '../node-singletons/url.js';
|
|
7
|
+
const KNOWN_EXTENSIONS = ['.js', '.mjs', '.cjs', '.json', '.node'];
|
|
8
|
+
const isNodeRuntime = () => typeof process !== 'undefined' && Boolean(process.versions?.node);
|
|
9
|
+
const listJsFilesRecursive = (dir) => {
|
|
10
|
+
const out = [];
|
|
11
|
+
const stack = [dir];
|
|
12
|
+
while (stack.length > 0) {
|
|
13
|
+
const current = stack.pop();
|
|
14
|
+
if (current === undefined)
|
|
15
|
+
continue;
|
|
16
|
+
let entries;
|
|
17
|
+
try {
|
|
18
|
+
entries = fs.readdirSync(current, { withFileTypes: true });
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
for (const entry of entries) {
|
|
24
|
+
const full = path.join(current, entry.name);
|
|
25
|
+
if (entry.isDirectory()) {
|
|
26
|
+
stack.push(full);
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
if (entry.isFile() && full.endsWith('.js')) {
|
|
30
|
+
out.push(full);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return out;
|
|
35
|
+
};
|
|
36
|
+
const shouldConsiderSpecifier = (specifier) => {
|
|
37
|
+
if (!specifier.startsWith('./') && !specifier.startsWith('../'))
|
|
38
|
+
return false;
|
|
39
|
+
if (specifier.includes('?') || specifier.includes('#'))
|
|
40
|
+
return false;
|
|
41
|
+
const lower = specifier.toLowerCase();
|
|
42
|
+
return !KNOWN_EXTENSIONS.some((ext) => lower.endsWith(ext));
|
|
43
|
+
};
|
|
44
|
+
const resolveSpecifier = (filePath, specifier) => {
|
|
45
|
+
if (!shouldConsiderSpecifier(specifier))
|
|
46
|
+
return null;
|
|
47
|
+
const baseDir = path.dirname(filePath);
|
|
48
|
+
const resolved = path.resolve(baseDir, specifier);
|
|
49
|
+
try {
|
|
50
|
+
if (fs.statSync(resolved).isDirectory()) {
|
|
51
|
+
const indexJs = path.join(resolved, 'index.js');
|
|
52
|
+
if (fs.existsSync(indexJs))
|
|
53
|
+
return `${specifier.endsWith('/') ? specifier.slice(0, -1) : specifier}/index.js`;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
// ignore stat errors
|
|
58
|
+
}
|
|
59
|
+
if (fs.existsSync(`${resolved}.js`))
|
|
60
|
+
return `${specifier}.js`;
|
|
61
|
+
return null;
|
|
62
|
+
};
|
|
63
|
+
const patchImportsInFile = (filePath) => {
|
|
64
|
+
let text;
|
|
65
|
+
try {
|
|
66
|
+
text = fs.readFileSync(filePath, 'utf8');
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return 0;
|
|
70
|
+
}
|
|
71
|
+
let replacements = 0;
|
|
72
|
+
const rewrite = (match, quote, specifier) => {
|
|
73
|
+
const next = resolveSpecifier(filePath, specifier);
|
|
74
|
+
if (next === null)
|
|
75
|
+
return match;
|
|
76
|
+
replacements += 1;
|
|
77
|
+
return match.replace(`${quote}${specifier}${quote}`, `${quote}${next}${quote}`);
|
|
78
|
+
};
|
|
79
|
+
const updated = text
|
|
80
|
+
.replaceAll(/\bfrom\s+(['"])(\.[^'"]+)\1/g, rewrite)
|
|
81
|
+
.replaceAll(/\bimport\s+(['"])(\.[^'"]+)\1/g, rewrite)
|
|
82
|
+
.replaceAll(/\bimport\s*\(\s*(['"])(\.[^'"]+)\1\s*\)/g, rewrite);
|
|
83
|
+
if (updated !== text) {
|
|
84
|
+
try {
|
|
85
|
+
fs.writeFileSync(filePath, updated, 'utf8');
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
return 0;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return replacements;
|
|
92
|
+
};
|
|
93
|
+
const patchPackageDist = (packageName) => {
|
|
94
|
+
if (!isNodeRuntime())
|
|
95
|
+
return { replacements: 0, filesChanged: 0 };
|
|
96
|
+
let entryPath;
|
|
97
|
+
try {
|
|
98
|
+
const require = createRequire(import.meta.url);
|
|
99
|
+
entryPath = require.resolve(packageName);
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
return { replacements: 0, filesChanged: 0 };
|
|
103
|
+
}
|
|
104
|
+
const distDir = path.dirname(entryPath);
|
|
105
|
+
if (!fs.existsSync(distDir))
|
|
106
|
+
return { replacements: 0, filesChanged: 0 };
|
|
107
|
+
const files = listJsFilesRecursive(distDir);
|
|
108
|
+
let replacements = 0;
|
|
109
|
+
let filesChanged = 0;
|
|
110
|
+
for (const file of files) {
|
|
111
|
+
const changes = patchImportsInFile(file);
|
|
112
|
+
if (changes > 0) {
|
|
113
|
+
replacements += changes;
|
|
114
|
+
filesChanged += 1;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return { replacements, filesChanged };
|
|
118
|
+
};
|
|
119
|
+
const patchWorkersDist = () => patchPackageDist('@zintrust/workers');
|
|
120
|
+
const patchQueueMonitorDist = () => patchPackageDist('@zintrust/queue-monitor');
|
|
121
|
+
const resolveLocalModuleUrl = (packageDir) => {
|
|
122
|
+
if (!isNodeRuntime())
|
|
123
|
+
return null;
|
|
124
|
+
const root = process.cwd();
|
|
125
|
+
const mode = (process.env['NODE_ENV'] ?? 'development').toString().trim().toLowerCase();
|
|
126
|
+
const isProductionMode = mode === 'production' || mode === 'pro' || mode === 'prod';
|
|
127
|
+
const runFromSource = typeof Common.runFromSource === 'function' ? Common.runFromSource() : false;
|
|
128
|
+
const preferSource = runFromSource || !isProductionMode;
|
|
129
|
+
const candidates = preferSource
|
|
130
|
+
? [
|
|
131
|
+
path.join(root, 'packages', packageDir, 'src', 'index.ts'),
|
|
132
|
+
path.join(root, 'dist', 'packages', packageDir, 'src', 'index.js'),
|
|
133
|
+
]
|
|
134
|
+
: [
|
|
135
|
+
path.join(root, 'dist', 'packages', packageDir, 'src', 'index.js'),
|
|
136
|
+
path.join(root, 'packages', packageDir, 'src', 'index.ts'),
|
|
137
|
+
];
|
|
138
|
+
for (const candidate of candidates) {
|
|
139
|
+
if (fs.existsSync(candidate)) {
|
|
140
|
+
return pathToFileURL(candidate).href;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return null;
|
|
144
|
+
};
|
|
145
|
+
const importLocalModule = async (packageDir, packageName) => {
|
|
146
|
+
const url = resolveLocalModuleUrl(packageDir);
|
|
147
|
+
if (url === null || url === '' || url === undefined)
|
|
148
|
+
return null;
|
|
149
|
+
try {
|
|
150
|
+
return (await import(url));
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
Logger.warn(`Failed to import local ${packageName} fallback`, error);
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
const importLocalWorkersModule = async () => importLocalModule('workers', '@zintrust/workers');
|
|
158
|
+
const importLocalQueueMonitorModule = async () => importLocalModule('queue-monitor', '@zintrust/queue-monitor');
|
|
159
|
+
let workersModulePromise;
|
|
160
|
+
let patchAttempted = false;
|
|
161
|
+
let patchAfterFailureAttempted = false;
|
|
162
|
+
let queueMonitorModulePromise;
|
|
163
|
+
let queueMonitorPatchAfterFailureAttempted = false;
|
|
164
|
+
const applyInitialPatches = () => {
|
|
165
|
+
if (patchAttempted)
|
|
166
|
+
return;
|
|
167
|
+
patchAttempted = true;
|
|
168
|
+
const workersPatch = patchWorkersDist();
|
|
169
|
+
if (workersPatch.filesChanged > 0) {
|
|
170
|
+
Logger.warn('Rewrote @zintrust/workers ESM specifiers before import', workersPatch);
|
|
171
|
+
}
|
|
172
|
+
const monitorPatch = patchQueueMonitorDist();
|
|
173
|
+
if (monitorPatch.filesChanged > 0) {
|
|
174
|
+
Logger.warn('Rewrote @zintrust/queue-monitor ESM specifiers before import', monitorPatch);
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
const shouldRetryAfterFailure = (error) => {
|
|
178
|
+
if (patchAfterFailureAttempted)
|
|
179
|
+
return false;
|
|
180
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
181
|
+
const code = error?.code;
|
|
182
|
+
return code === 'ERR_MODULE_NOT_FOUND' && message.includes('@zintrust/workers');
|
|
183
|
+
};
|
|
184
|
+
const handleImportFailure = async (error) => {
|
|
185
|
+
if (shouldRetryAfterFailure(error)) {
|
|
186
|
+
patchAfterFailureAttempted = true;
|
|
187
|
+
const { replacements, filesChanged } = patchWorkersDist();
|
|
188
|
+
if (filesChanged > 0) {
|
|
189
|
+
Logger.warn('Rewrote @zintrust/workers ESM specifiers after import failure', {
|
|
190
|
+
filesChanged,
|
|
191
|
+
replacements,
|
|
192
|
+
});
|
|
193
|
+
workersModulePromise = import('@zintrust/workers');
|
|
194
|
+
return workersModulePromise;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
const localFallback = await importLocalWorkersModule();
|
|
198
|
+
if (localFallback) {
|
|
199
|
+
workersModulePromise = Promise.resolve(localFallback);
|
|
200
|
+
return localFallback;
|
|
201
|
+
}
|
|
202
|
+
throw error;
|
|
203
|
+
};
|
|
204
|
+
const tryLocalFallback = async () => {
|
|
205
|
+
const localFallback = await importLocalWorkersModule();
|
|
206
|
+
if (localFallback) {
|
|
207
|
+
workersModulePromise = Promise.resolve(localFallback);
|
|
208
|
+
return localFallback;
|
|
209
|
+
}
|
|
210
|
+
return null;
|
|
211
|
+
};
|
|
212
|
+
export const loadWorkersModule = async () => {
|
|
213
|
+
applyInitialPatches();
|
|
214
|
+
if (workersModulePromise === undefined) {
|
|
215
|
+
const localFallback = await tryLocalFallback();
|
|
216
|
+
if (localFallback) {
|
|
217
|
+
return localFallback;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
workersModulePromise ??= import('@zintrust/workers');
|
|
221
|
+
try {
|
|
222
|
+
return await workersModulePromise;
|
|
223
|
+
}
|
|
224
|
+
catch (error) {
|
|
225
|
+
return handleImportFailure(error);
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
const shouldRetryQueueMonitorAfterFailure = (error) => {
|
|
229
|
+
if (queueMonitorPatchAfterFailureAttempted)
|
|
230
|
+
return false;
|
|
231
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
232
|
+
const code = error?.code;
|
|
233
|
+
return code === 'ERR_MODULE_NOT_FOUND' && message.includes('@zintrust/queue-monitor');
|
|
234
|
+
};
|
|
235
|
+
const handleQueueMonitorImportFailure = async (error) => {
|
|
236
|
+
if (shouldRetryQueueMonitorAfterFailure(error)) {
|
|
237
|
+
queueMonitorPatchAfterFailureAttempted = true;
|
|
238
|
+
const { replacements, filesChanged } = patchQueueMonitorDist();
|
|
239
|
+
if (filesChanged > 0) {
|
|
240
|
+
Logger.warn('Rewrote @zintrust/queue-monitor ESM specifiers after import failure', {
|
|
241
|
+
filesChanged,
|
|
242
|
+
replacements,
|
|
243
|
+
});
|
|
244
|
+
queueMonitorModulePromise = import('@zintrust/queue-monitor');
|
|
245
|
+
return queueMonitorModulePromise;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
const localFallback = await importLocalQueueMonitorModule();
|
|
249
|
+
if (localFallback) {
|
|
250
|
+
queueMonitorModulePromise = Promise.resolve(localFallback);
|
|
251
|
+
return localFallback;
|
|
252
|
+
}
|
|
253
|
+
throw error;
|
|
254
|
+
};
|
|
255
|
+
const tryQueueMonitorLocalFallback = async () => {
|
|
256
|
+
const localFallback = await importLocalQueueMonitorModule();
|
|
257
|
+
if (localFallback) {
|
|
258
|
+
queueMonitorModulePromise = Promise.resolve(localFallback);
|
|
259
|
+
return localFallback;
|
|
260
|
+
}
|
|
261
|
+
return null;
|
|
262
|
+
};
|
|
263
|
+
export const loadQueueMonitorModule = async () => {
|
|
264
|
+
applyInitialPatches();
|
|
265
|
+
if (queueMonitorModulePromise === undefined) {
|
|
266
|
+
const localFallback = await tryQueueMonitorLocalFallback();
|
|
267
|
+
if (localFallback) {
|
|
268
|
+
return localFallback;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
queueMonitorModulePromise ??= import('@zintrust/queue-monitor');
|
|
272
|
+
try {
|
|
273
|
+
return await queueMonitorModulePromise;
|
|
274
|
+
}
|
|
275
|
+
catch (error) {
|
|
276
|
+
return handleQueueMonitorImportFailure(error);
|
|
277
|
+
}
|
|
278
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CloudflareAdapter.d.ts","sourceRoot":"","sources":["../../../../src/runtime/adapters/CloudflareAdapter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"CloudflareAdapter.d.ts","sourceRoot":"","sources":["../../../../src/runtime/adapters/CloudflareAdapter.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EACV,aAAa,EAGb,cAAc,EACf,MAAM,yBAAyB,CAAC;AAGjC;;;;GAIG;AACH,eAAO,MAAM,iBAAiB;IAC5B;;OAEG;mBACY,aAAa,GAAG,cAAc;IAwD7C;;;OAGG;qBACc,OAAO;IAKxB;;;OAGG;qBACc,MAAM,GAAG,OAAO;EAIjC,CAAC;AAwJH;;;;GAIG;AACH,MAAM,WAAW,iBAAkB,SAAQ,OAAO;IAChD,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC;IACjC,EAAE,CAAC,EAAE;QACH,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,eAAe,CAAC,EAAE,MAAM,CAAC;KAC1B,CAAC;CACH"}
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
* Runtime adapter for Cloudflare Workers
|
|
3
3
|
*/
|
|
4
4
|
import { appConfig } from '../../config/index.js';
|
|
5
|
+
import { Cloudflare } from '../../config/cloudflare.js';
|
|
6
|
+
import { Env } from '../../config/env.js';
|
|
5
7
|
import { Logger } from '../../config/logger.js';
|
|
6
8
|
import { createMockHttpObjects, ErrorResponse, HttpResponse } from '../RuntimeAdapter.js';
|
|
7
9
|
/**
|
|
@@ -14,6 +16,10 @@ export const CloudflareAdapter = Object.freeze({
|
|
|
14
16
|
* Create a new Cloudflare adapter instance
|
|
15
17
|
*/
|
|
16
18
|
create(config) {
|
|
19
|
+
const workersEnv = Cloudflare.getWorkersEnv();
|
|
20
|
+
if (workersEnv !== null) {
|
|
21
|
+
Env.setSource(() => workersEnv);
|
|
22
|
+
}
|
|
17
23
|
const logger = config.logger ?? createDefaultLogger();
|
|
18
24
|
return {
|
|
19
25
|
platform: 'cloudflare',
|
|
@@ -70,6 +76,7 @@ async function handleCloudflareRequest(adapter, config, logger, event) {
|
|
|
70
76
|
const platformRequest = adapter.parseRequest(request);
|
|
71
77
|
// Read request body
|
|
72
78
|
const body = request.method !== 'GET' && request.method !== 'HEAD' ? await request.text() : null;
|
|
79
|
+
platformRequest.body = body;
|
|
73
80
|
// Create mock Node.js request/response objects
|
|
74
81
|
const { req, res, responseData } = createMockHttpObjects(platformRequest);
|
|
75
82
|
// Set request timeout
|
|
@@ -100,7 +107,11 @@ async function handleCloudflareRequest(adapter, config, logger, event) {
|
|
|
100
107
|
return response.toResponse();
|
|
101
108
|
}
|
|
102
109
|
catch (error) {
|
|
103
|
-
|
|
110
|
+
const err = error;
|
|
111
|
+
Logger.error('Cloudflare handler error', err);
|
|
112
|
+
if (typeof err?.stack === 'string' && err.stack.trim() !== '') {
|
|
113
|
+
Logger.error('Cloudflare handler stack', err.stack);
|
|
114
|
+
}
|
|
104
115
|
const errorResponse = ErrorResponse.create(500, 'Internal Server Error', appConfig.isDevelopment() ? { message: error.message } : undefined);
|
|
105
116
|
return errorResponse.toResponse();
|
|
106
117
|
}
|
|
@@ -121,6 +132,7 @@ function parseCloudflareRequest(event) {
|
|
|
121
132
|
headers,
|
|
122
133
|
query: Object.fromEntries(url.searchParams.entries()),
|
|
123
134
|
remoteAddr: headers['cf-connecting-ip']?.toString() || '0.0.0.0',
|
|
135
|
+
signal: event.signal,
|
|
124
136
|
};
|
|
125
137
|
}
|
|
126
138
|
/**
|
|
@@ -137,11 +149,16 @@ function formatCloudflareResponse(response) {
|
|
|
137
149
|
headers.set(key, value);
|
|
138
150
|
}
|
|
139
151
|
}
|
|
140
|
-
let body =
|
|
152
|
+
let body = null;
|
|
141
153
|
if (response.body !== null && response.body !== undefined) {
|
|
142
154
|
if (typeof response.body === 'string') {
|
|
143
155
|
body = response.body;
|
|
144
156
|
}
|
|
157
|
+
else if (typeof ReadableStream !== 'undefined' &&
|
|
158
|
+
(response.body instanceof ReadableStream ||
|
|
159
|
+
response.body?.constructor?.name === 'ReadableStream')) {
|
|
160
|
+
body = response.body;
|
|
161
|
+
}
|
|
145
162
|
else {
|
|
146
163
|
body = response.body.toString();
|
|
147
164
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type RuntimeMode = 'cloudflare-workers' | 'containers' | 'node-server';
|
|
2
|
+
export declare const isNodeRuntime: () => boolean;
|
|
3
|
+
export declare const getRuntimeMode: () => RuntimeMode;
|
|
4
|
+
export declare const detectRuntime: () => {
|
|
5
|
+
isCloudflare: boolean;
|
|
6
|
+
isNode: boolean;
|
|
7
|
+
isDeno: boolean;
|
|
8
|
+
isBun: boolean;
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=detectRuntime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detectRuntime.d.ts","sourceRoot":"","sources":["../../../src/runtime/detectRuntime.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,WAAW,GAAG,oBAAoB,GAAG,YAAY,GAAG,aAAa,CAAC;AAE9E,eAAO,MAAM,aAAa,QAAO,OAUhC,CAAC;AAUF,eAAO,MAAM,cAAc,QAAO,WA6BjC,CAAC;AAEF,eAAO,MAAM,aAAa,QAAO;IAC/B,YAAY,EAAE,OAAO,CAAC;IACtB,MAAM,EAAE,OAAO,CAAC;IAChB,MAAM,EAAE,OAAO,CAAC;IAChB,KAAK,EAAE,OAAO,CAAC;CAwBhB,CAAC"}
|