@zintrust/core 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/bin/zintrust.d.ts.map +1 -1
- package/bin/zintrust.js +18 -1
- package/package.json +1 -1
- package/src/boot/Application.d.ts.map +1 -1
- package/src/boot/Application.js +46 -3
- package/src/boot/Server.d.ts.map +1 -1
- package/src/boot/Server.js +3 -4
- package/src/boot/bootstrap.js +77 -6
- package/src/builder/BundleOptimizer.d.ts.map +1 -1
- package/src/builder/BundleOptimizer.js +6 -4
- package/src/cache/drivers/KVDriver.d.ts.map +1 -1
- package/src/cache/drivers/KVDriver.js +6 -6
- package/src/cache/drivers/RedisDriver.js +1 -1
- package/src/cli/BaseCommand.d.ts +2 -2
- package/src/cli/BaseCommand.d.ts.map +1 -1
- package/src/cli/BaseCommand.js +2 -1
- package/src/cli/CLI.d.ts.map +1 -1
- package/src/cli/CLI.js +11 -4
- package/src/cli/commands/AddCommand.js +1 -1
- package/src/cli/commands/ConfigCommand.d.ts.map +1 -1
- package/src/cli/commands/ConfigCommand.js +34 -4
- package/src/cli/commands/D1MigrateCommand.d.ts +4 -0
- package/src/cli/commands/D1MigrateCommand.d.ts.map +1 -1
- package/src/cli/commands/D1MigrateCommand.js +4 -3
- package/src/cli/commands/FixCommand.d.ts.map +1 -1
- package/src/cli/commands/FixCommand.js +3 -16
- package/src/cli/commands/LogsCleanupCommand.d.ts +6 -0
- package/src/cli/commands/LogsCleanupCommand.d.ts.map +1 -0
- package/src/cli/commands/LogsCleanupCommand.js +20 -0
- package/src/cli/commands/LogsCommand.d.ts.map +1 -1
- package/src/cli/commands/LogsCommand.js +1 -1
- package/src/cli/commands/MakeMailTemplateCommand.d.ts +10 -0
- package/src/cli/commands/MakeMailTemplateCommand.d.ts.map +1 -0
- package/src/cli/commands/MakeMailTemplateCommand.js +74 -0
- package/src/cli/commands/MakeNotificationTemplateCommand.d.ts +10 -0
- package/src/cli/commands/MakeNotificationTemplateCommand.d.ts.map +1 -0
- package/src/cli/commands/MakeNotificationTemplateCommand.js +113 -0
- package/src/cli/commands/NewCommand.d.ts +4 -0
- package/src/cli/commands/NewCommand.d.ts.map +1 -1
- package/src/cli/commands/NewCommand.js +33 -20
- package/src/cli/commands/PluginCommand.d.ts.map +1 -1
- package/src/cli/commands/PluginCommand.js +8 -4
- package/src/cli/commands/PrepareCommand.d.ts.map +1 -1
- package/src/cli/commands/PrepareCommand.js +1 -1
- package/src/cli/commands/QACommand.d.ts.map +1 -1
- package/src/cli/commands/QACommand.js +11 -20
- package/src/cli/commands/SecretsCommand.d.ts +16 -0
- package/src/cli/commands/SecretsCommand.d.ts.map +1 -0
- package/src/cli/commands/SecretsCommand.js +91 -0
- package/src/cli/commands/StartCommand.d.ts.map +1 -1
- package/src/cli/commands/StartCommand.js +2 -2
- package/src/cli/commands/TemplatesCommand.d.ts +3 -0
- package/src/cli/commands/TemplatesCommand.d.ts.map +1 -0
- package/src/cli/commands/TemplatesCommand.js +65 -0
- package/src/cli/commands/index.d.ts +5 -0
- package/src/cli/commands/index.d.ts.map +1 -1
- package/src/cli/commands/index.js +5 -0
- package/src/cli/config/ConfigManager.js +1 -1
- package/src/cli/index.d.ts +2 -1
- package/src/cli/index.d.ts.map +1 -1
- package/src/cli/index.js +2 -1
- package/src/cli/scaffolding/ControllerGenerator.js +1 -1
- package/src/cli/scaffolding/FeatureScaffolder.js +4 -4
- package/src/cli/scaffolding/FileGenerator.js +1 -1
- package/src/cli/scaffolding/ModelGenerator.js +1 -1
- package/src/cli/scaffolding/ProjectScaffolder.d.ts.map +1 -1
- package/src/cli/scaffolding/ProjectScaffolder.js +61 -11
- package/src/cli/scaffolding/ResponseFactoryGenerator.d.ts.map +1 -1
- package/src/cli/scaffolding/ResponseFactoryGenerator.js +3 -2
- package/src/cli/scaffolding/RouteGenerator.js +1 -1
- package/src/cli/scaffolding/ServiceIntegrationTestGenerator.js +1 -1
- package/src/cli/scaffolding/ServiceScaffolder.js +2 -2
- package/src/cli/scaffolding/TemplateGenerator.d.ts +40 -0
- package/src/cli/scaffolding/TemplateGenerator.d.ts.map +1 -0
- package/src/cli/scaffolding/TemplateGenerator.js +172 -0
- package/src/cli/scaffolding/index.d.ts +1 -0
- package/src/cli/scaffolding/index.d.ts.map +1 -1
- package/src/cli/scaffolding/index.js +1 -0
- package/src/cli/utils/spawn.js +1 -1
- package/src/common/AwsSigV4.d.ts +41 -0
- package/src/common/AwsSigV4.d.ts.map +1 -0
- package/src/common/AwsSigV4.js +69 -0
- package/src/common/index.d.ts +39 -0
- package/src/common/index.d.ts.map +1 -1
- package/src/common/index.js +101 -8
- package/src/common/uuid.d.ts +3 -0
- package/src/common/uuid.d.ts.map +1 -0
- package/src/common/uuid.js +30 -0
- package/src/config/FileLogWriter.d.ts +22 -0
- package/src/config/FileLogWriter.d.ts.map +1 -0
- package/src/config/FileLogWriter.js +192 -0
- package/src/config/SecretsManager.d.ts.map +1 -1
- package/src/config/SecretsManager.js +37 -11
- package/src/config/StartupConfigValidator.d.ts +15 -0
- package/src/config/StartupConfigValidator.d.ts.map +1 -0
- package/src/config/StartupConfigValidator.js +86 -0
- package/src/config/app.d.ts +2 -1
- package/src/config/app.d.ts.map +1 -1
- package/src/config/app.js +65 -15
- package/src/config/broadcast.d.ts +47 -0
- package/src/config/broadcast.d.ts.map +1 -0
- package/src/config/broadcast.js +54 -0
- package/src/config/cache.d.ts +13 -17
- package/src/config/cache.d.ts.map +1 -1
- package/src/config/cache.js +9 -11
- package/src/config/cloudflare.d.ts +26 -0
- package/src/config/cloudflare.d.ts.map +1 -0
- package/src/config/cloudflare.js +38 -0
- package/src/config/env.d.ts +6 -0
- package/src/config/env.d.ts.map +1 -1
- package/src/config/env.js +6 -0
- package/src/config/index.d.ts +52 -28
- package/src/config/index.d.ts.map +1 -1
- package/src/config/index.js +3 -0
- package/src/config/logger.d.ts +2 -0
- package/src/config/logger.d.ts.map +1 -1
- package/src/config/logger.js +270 -11
- package/src/config/logging/HttpLogger.d.ts +23 -0
- package/src/config/logging/HttpLogger.d.ts.map +1 -0
- package/src/config/logging/HttpLogger.js +93 -0
- package/src/config/logging/KvLogger.d.ts +22 -0
- package/src/config/logging/KvLogger.d.ts.map +1 -0
- package/src/config/logging/KvLogger.js +143 -0
- package/src/config/logging/SlackLogger.d.ts +23 -0
- package/src/config/logging/SlackLogger.d.ts.map +1 -0
- package/src/config/logging/SlackLogger.js +119 -0
- package/src/config/mail.d.ts +81 -0
- package/src/config/mail.d.ts.map +1 -0
- package/src/config/mail.js +73 -0
- package/src/config/middleware.d.ts +8 -0
- package/src/config/middleware.d.ts.map +1 -0
- package/src/config/middleware.js +18 -0
- package/src/config/notification.d.ts +62 -0
- package/src/config/notification.d.ts.map +1 -0
- package/src/config/notification.js +43 -0
- package/src/config/security.d.ts.map +1 -1
- package/src/config/security.js +2 -2
- package/src/config/startup.d.ts +23 -0
- package/src/config/startup.d.ts.map +1 -0
- package/src/config/startup.js +15 -0
- package/src/config/storage.d.ts +21 -35
- package/src/config/storage.d.ts.map +1 -1
- package/src/config/storage.js +57 -37
- package/src/database/migrations/index.d.ts +1 -1
- package/src/database/migrations/index.d.ts.map +1 -1
- package/src/database/migrations/index.js +2 -1
- package/src/features/Queue.js +1 -25
- package/src/health/RuntimeHealthProbes.d.ts +13 -0
- package/src/health/RuntimeHealthProbes.d.ts.map +1 -0
- package/src/health/RuntimeHealthProbes.js +62 -0
- package/src/health/StartupHealthChecks.d.ts +26 -0
- package/src/health/StartupHealthChecks.d.ts.map +1 -0
- package/src/health/StartupHealthChecks.js +124 -0
- package/src/http/ErrorResponse.d.ts +28 -0
- package/src/http/ErrorResponse.d.ts.map +1 -0
- package/src/http/ErrorResponse.js +42 -0
- package/src/http/Kernel.d.ts +5 -0
- package/src/http/Kernel.d.ts.map +1 -1
- package/src/http/Kernel.js +96 -30
- package/src/http/RequestContext.d.ts +20 -0
- package/src/http/RequestContext.d.ts.map +1 -0
- package/src/http/RequestContext.js +77 -0
- package/src/index.d.ts +9 -1
- package/src/index.d.ts.map +1 -1
- package/src/index.js +8 -2
- package/src/microservices/MicroserviceManager.d.ts.map +1 -1
- package/src/microservices/MicroserviceManager.js +9 -6
- package/src/microservices/PostgresAdapter.d.ts.map +1 -1
- package/src/microservices/PostgresAdapter.js +3 -1
- package/src/microservices/ServiceBundler.d.ts.map +1 -1
- package/src/microservices/ServiceBundler.js +6 -4
- package/src/microservices/ServiceHealthMonitor.js +2 -2
- package/src/middleware/CsrfMiddleware.d.ts.map +1 -1
- package/src/middleware/CsrfMiddleware.js +2 -19
- package/src/middleware/ErrorHandlerMiddleware.d.ts +6 -0
- package/src/middleware/ErrorHandlerMiddleware.d.ts.map +1 -0
- package/src/middleware/ErrorHandlerMiddleware.js +33 -0
- package/src/middleware/LoggingMiddleware.d.ts +9 -0
- package/src/middleware/LoggingMiddleware.d.ts.map +1 -0
- package/src/middleware/LoggingMiddleware.js +36 -0
- package/src/middleware/index.d.ts +2 -0
- package/src/middleware/index.d.ts.map +1 -1
- package/src/middleware/index.js +2 -0
- package/src/node-singletons/async_hooks.d.ts +9 -0
- package/src/node-singletons/async_hooks.d.ts.map +1 -0
- package/src/node-singletons/async_hooks.js +8 -0
- package/src/node-singletons/fs.d.ts +2 -2
- package/src/node-singletons/fs.d.ts.map +1 -1
- package/src/node-singletons/fs.js +2 -2
- package/src/node-singletons/http.d.ts +1 -1
- package/src/node-singletons/http.d.ts.map +1 -1
- package/src/node-singletons/http.js +1 -1
- package/src/node-singletons/index.d.ts +4 -0
- package/src/node-singletons/index.d.ts.map +1 -1
- package/src/node-singletons/index.js +4 -0
- package/src/node-singletons/net.d.ts +9 -0
- package/src/node-singletons/net.d.ts.map +1 -0
- package/src/node-singletons/net.js +8 -0
- package/src/node-singletons/os.d.ts +3 -3
- package/src/node-singletons/os.d.ts.map +1 -1
- package/src/node-singletons/os.js +3 -4
- package/src/node-singletons/path.d.ts +3 -1
- package/src/node-singletons/path.d.ts.map +1 -1
- package/src/node-singletons/path.js +3 -1
- package/src/node-singletons/perf-hooks.d.ts +3 -1
- package/src/node-singletons/perf-hooks.d.ts.map +1 -1
- package/src/node-singletons/perf-hooks.js +3 -1
- package/src/node-singletons/process.d.ts +23 -0
- package/src/node-singletons/process.d.ts.map +1 -0
- package/src/node-singletons/process.js +8 -0
- package/src/node-singletons/readline.d.ts +3 -3
- package/src/node-singletons/readline.d.ts.map +1 -1
- package/src/node-singletons/readline.js +3 -4
- package/src/node-singletons/tls.d.ts +9 -0
- package/src/node-singletons/tls.d.ts.map +1 -0
- package/src/node-singletons/tls.js +8 -0
- package/src/node-singletons/url.d.ts +3 -1
- package/src/node-singletons/url.d.ts.map +1 -1
- package/src/node-singletons/url.js +3 -1
- package/src/orm/ConnectionManager.d.ts +6 -1
- package/src/orm/ConnectionManager.d.ts.map +1 -1
- package/src/orm/ConnectionManager.js +14 -0
- package/src/orm/DatabaseAdapter.d.ts +6 -0
- package/src/orm/DatabaseAdapter.d.ts.map +1 -1
- package/src/orm/QueryBuilder.d.ts +8 -1
- package/src/orm/QueryBuilder.d.ts.map +1 -1
- package/src/orm/QueryBuilder.js +188 -28
- package/src/orm/adapters/D1Adapter.d.ts.map +1 -1
- package/src/orm/adapters/D1Adapter.js +18 -12
- package/src/orm/adapters/MySQLAdapter.d.ts.map +1 -1
- package/src/orm/adapters/MySQLAdapter.js +4 -0
- package/src/orm/adapters/PostgreSQLAdapter.d.ts.map +1 -1
- package/src/orm/adapters/PostgreSQLAdapter.js +4 -0
- package/src/orm/adapters/SQLServerAdapter.d.ts.map +1 -1
- package/src/orm/adapters/SQLServerAdapter.js +4 -0
- package/src/orm/adapters/SQLiteAdapter.d.ts.map +1 -1
- package/src/orm/adapters/SQLiteAdapter.js +4 -0
- package/src/performance/CodeGenerationBenchmark.js +3 -3
- package/src/performance/Optimizer.d.ts +1 -1
- package/src/performance/Optimizer.d.ts.map +1 -1
- package/src/performance/Optimizer.js +150 -75
- package/src/performance/establish-baseline.js +3 -3
- package/src/runtime/PluginManager.d.ts +3 -1
- package/src/runtime/PluginManager.d.ts.map +1 -1
- package/src/runtime/PluginManager.js +124 -28
- package/src/runtime/RuntimeDetector.d.ts.map +1 -1
- package/src/runtime/RuntimeDetector.js +47 -6
- package/src/runtime/adapters/CloudflareAdapter.js +2 -2
- package/src/runtime/adapters/FargateAdapter.d.ts.map +1 -1
- package/src/runtime/adapters/FargateAdapter.js +2 -1
- package/src/runtime/adapters/LambdaAdapter.d.ts.map +1 -1
- package/src/runtime/adapters/LambdaAdapter.js +4 -2
- package/src/runtime/adapters/NodeServerAdapter.d.ts.map +1 -1
- package/src/runtime/adapters/NodeServerAdapter.js +2 -1
- package/src/scheduler/ScheduleRunner.d.ts +18 -0
- package/src/scheduler/ScheduleRunner.d.ts.map +1 -0
- package/src/scheduler/ScheduleRunner.js +155 -0
- package/src/scheduler/index.d.ts +3 -0
- package/src/scheduler/index.d.ts.map +1 -0
- package/src/scheduler/index.js +1 -0
- package/src/scheduler/types.d.ts +16 -0
- package/src/scheduler/types.d.ts.map +1 -0
- package/src/scheduler/types.js +4 -0
- package/src/schedules/index.d.ts +2 -0
- package/src/schedules/index.d.ts.map +1 -0
- package/src/schedules/index.js +1 -0
- package/src/schedules/log-cleanup.d.ts +4 -0
- package/src/schedules/log-cleanup.d.ts.map +1 -0
- package/src/schedules/log-cleanup.js +18 -0
- package/src/scripts/GenerateEnvArtifacts.d.ts +13 -0
- package/src/scripts/GenerateEnvArtifacts.d.ts.map +1 -0
- package/src/scripts/GenerateEnvArtifacts.js +171 -0
- package/src/scripts/TemplateSync.js +109 -70
- package/src/security/CsrfTokenManager.js +1 -1
- package/src/security/Encryptor.js +1 -1
- package/src/security/Hash.d.ts +14 -0
- package/src/security/Hash.d.ts.map +1 -0
- package/src/security/Hash.js +81 -0
- package/src/security/StartupSecretValidation.d.ts +20 -0
- package/src/security/StartupSecretValidation.d.ts.map +1 -0
- package/src/security/StartupSecretValidation.js +61 -0
- package/src/security/UrlValidator.d.ts +0 -1
- package/src/security/UrlValidator.d.ts.map +1 -1
- package/src/security/UrlValidator.js +1 -2
- package/src/security/Xss.d.ts +14 -0
- package/src/security/Xss.d.ts.map +1 -0
- package/src/security/Xss.js +57 -0
- package/src/security/XssProtection.d.ts.map +1 -1
- package/src/security/XssProtection.js +150 -16
- package/src/templates/adapters/MySQLAdapter.ts.tpl +5 -0
- package/src/templates/adapters/PostgreSQLAdapter.ts.tpl +5 -0
- package/src/templates/adapters/SQLServerAdapter.ts.tpl +5 -0
- package/src/templates/adapters/SQLiteAdapter.ts.tpl +5 -0
- package/src/templates/features/Queue.ts.tpl +1 -29
- package/src/templates/project/basic/.env.example.tpl +48 -0
- package/src/templates/project/basic/.env.tpl +89 -94
- package/src/templates/project/basic/app/Toolkit/Broadcast/sendBroadcast.ts.tpl +7 -0
- package/src/templates/project/basic/app/Toolkit/Mail/sendWelcomeEmail.ts.tpl +30 -0
- package/src/templates/project/basic/app/Toolkit/Notification/sendSlackNotification.ts.tpl +10 -0
- package/src/templates/project/basic/app/Toolkit/Notification/sendSms.ts.tpl +13 -0
- package/src/templates/project/basic/config/FileLogWriter.ts.tpl +240 -0
- package/src/templates/project/basic/config/SecretsManager.ts.tpl +44 -21
- package/src/templates/project/basic/config/StartupConfigValidator.ts.tpl +151 -0
- package/src/templates/project/basic/config/app.ts.tpl +84 -15
- package/src/templates/project/basic/config/broadcast.ts.tpl +97 -0
- package/src/templates/project/basic/config/cache.ts.tpl +19 -23
- package/src/templates/project/basic/config/cloudflare.ts.tpl +57 -0
- package/src/templates/project/basic/config/env.ts.tpl +7 -1
- package/src/templates/project/basic/config/index.ts.tpl +3 -0
- package/src/templates/project/basic/config/logger.ts.tpl +301 -11
- package/src/templates/project/basic/config/logging/HttpLogger.ts.tpl +121 -0
- package/src/templates/project/basic/config/logging/KvLogger.ts.tpl +181 -0
- package/src/templates/project/basic/config/logging/SlackLogger.ts.tpl +156 -0
- package/src/templates/project/basic/config/mail.ts.tpl +141 -0
- package/src/templates/project/basic/config/middleware.ts.tpl +27 -0
- package/src/templates/project/basic/config/notification.ts.tpl +86 -0
- package/src/templates/project/basic/config/security.ts.tpl +4 -5
- package/src/templates/project/basic/config/startup.ts.tpl +27 -0
- package/src/templates/project/basic/config/storage.ts.tpl +77 -42
- package/src/templates/project/basic/database/migrations/index.ts.tpl +1 -1
- package/src/templates/project/basic/package.json.tpl +1 -1
- package/src/templates/project/basic/routes/api.ts.tpl +9 -37
- package/src/templates/project/basic/routes/broadcast.ts.tpl +32 -0
- package/src/templates/project/basic/routes/health.ts.tpl +134 -0
- package/src/templates/project/basic/src/index.ts.tpl +38 -11
- package/src/templates/project/basic/template.json +3 -0
- package/src/toolkit/Secrets/EnvFile.d.ts +15 -0
- package/src/toolkit/Secrets/EnvFile.d.ts.map +1 -0
- package/src/toolkit/Secrets/EnvFile.js +63 -0
- package/src/toolkit/Secrets/Manifest.d.ts +24 -0
- package/src/toolkit/Secrets/Manifest.d.ts.map +1 -0
- package/src/toolkit/Secrets/Manifest.js +71 -0
- package/src/toolkit/Secrets/index.d.ts +42 -0
- package/src/toolkit/Secrets/index.d.ts.map +1 -0
- package/src/toolkit/Secrets/index.js +119 -0
- package/src/toolkit/Secrets/providers/AwsSecretsManager.d.ts +14 -0
- package/src/toolkit/Secrets/providers/AwsSecretsManager.d.ts.map +1 -0
- package/src/toolkit/Secrets/providers/AwsSecretsManager.js +131 -0
- package/src/toolkit/Secrets/providers/CloudflareKv.d.ts +9 -0
- package/src/toolkit/Secrets/providers/CloudflareKv.d.ts.map +1 -0
- package/src/toolkit/Secrets/providers/CloudflareKv.js +73 -0
- package/src/tools/broadcast/Broadcast.d.ts +7 -0
- package/src/tools/broadcast/Broadcast.d.ts.map +1 -0
- package/src/tools/broadcast/Broadcast.js +37 -0
- package/src/tools/broadcast/drivers/BaseDriver.d.ts +5 -0
- package/src/tools/broadcast/drivers/BaseDriver.d.ts.map +1 -0
- package/src/tools/broadcast/drivers/BaseDriver.js +8 -0
- package/src/tools/broadcast/drivers/InMemory.d.ts +18 -0
- package/src/tools/broadcast/drivers/InMemory.d.ts.map +1 -0
- package/src/tools/broadcast/drivers/InMemory.js +16 -0
- package/src/tools/broadcast/drivers/Pusher.d.ts +8 -0
- package/src/tools/broadcast/drivers/Pusher.d.ts.map +1 -0
- package/src/tools/broadcast/drivers/Pusher.js +75 -0
- package/src/tools/broadcast/drivers/Redis.d.ts +19 -0
- package/src/tools/broadcast/drivers/Redis.d.ts.map +1 -0
- package/src/tools/broadcast/drivers/Redis.js +73 -0
- package/src/tools/broadcast/drivers/RedisHttps.d.ts +14 -0
- package/src/tools/broadcast/drivers/RedisHttps.d.ts.map +1 -0
- package/src/tools/broadcast/drivers/RedisHttps.js +50 -0
- package/src/tools/broadcast/index.d.ts +7 -0
- package/src/tools/broadcast/index.d.ts.map +1 -0
- package/src/tools/broadcast/index.js +6 -0
- package/src/tools/http/Http.d.ts +51 -0
- package/src/tools/http/Http.d.ts.map +1 -0
- package/src/tools/http/Http.js +171 -0
- package/src/tools/http/HttpResponse.d.ts +32 -0
- package/src/tools/http/HttpResponse.d.ts.map +1 -0
- package/src/tools/http/HttpResponse.js +80 -0
- package/src/tools/http/index.d.ts +15 -0
- package/src/tools/http/index.d.ts.map +1 -0
- package/src/tools/http/index.js +9 -0
- package/src/tools/mail/Mail.d.ts +22 -0
- package/src/tools/mail/Mail.d.ts.map +1 -0
- package/src/tools/mail/Mail.js +105 -0
- package/src/tools/mail/attachments.d.ts +23 -0
- package/src/tools/mail/attachments.d.ts.map +1 -0
- package/src/tools/mail/attachments.js +26 -0
- package/src/tools/mail/drivers/BaseDriver.d.ts +5 -0
- package/src/tools/mail/drivers/BaseDriver.d.ts.map +1 -0
- package/src/tools/mail/drivers/BaseDriver.js +8 -0
- package/src/tools/mail/drivers/Mailgun.d.ts +31 -0
- package/src/tools/mail/drivers/Mailgun.d.ts.map +1 -0
- package/src/tools/mail/drivers/Mailgun.js +81 -0
- package/src/tools/mail/drivers/SendGrid.d.ts +29 -0
- package/src/tools/mail/drivers/SendGrid.d.ts.map +1 -0
- package/src/tools/mail/drivers/SendGrid.js +57 -0
- package/src/tools/mail/drivers/Ses.d.ts +24 -0
- package/src/tools/mail/drivers/Ses.d.ts.map +1 -0
- package/src/tools/mail/drivers/Ses.js +116 -0
- package/src/tools/mail/drivers/Smtp.d.ts +38 -0
- package/src/tools/mail/drivers/Smtp.d.ts.map +1 -0
- package/src/tools/mail/drivers/Smtp.js +327 -0
- package/src/tools/mail/templates/index.d.ts +27 -0
- package/src/tools/mail/templates/index.d.ts.map +1 -0
- package/src/tools/mail/templates/index.js +35 -0
- package/src/tools/mail/templates/markdown/index.d.ts +17 -0
- package/src/tools/mail/templates/markdown/index.d.ts.map +1 -0
- package/src/tools/mail/templates/markdown/index.js +49 -0
- package/src/tools/mail/templates/markdown/registry.d.ts +15 -0
- package/src/tools/mail/templates/markdown/registry.d.ts.map +1 -0
- package/src/tools/mail/templates/markdown/registry.js +34 -0
- package/src/tools/mail/templates/markdown/validator.d.ts +16 -0
- package/src/tools/mail/templates/markdown/validator.d.ts.map +1 -0
- package/src/tools/mail/templates/markdown/validator.js +24 -0
- package/src/tools/mail/testing.d.ts +41 -0
- package/src/tools/mail/testing.d.ts.map +1 -0
- package/src/tools/mail/testing.js +34 -0
- package/src/tools/notification/Driver.d.ts +11 -0
- package/src/tools/notification/Driver.d.ts.map +1 -0
- package/src/tools/notification/Driver.js +1 -0
- package/src/tools/notification/Notification.d.ts +11 -0
- package/src/tools/notification/Notification.d.ts.map +1 -0
- package/src/tools/notification/Notification.js +11 -0
- package/src/tools/notification/Registry.d.ts +10 -0
- package/src/tools/notification/Registry.d.ts.map +1 -0
- package/src/tools/notification/Registry.js +22 -0
- package/src/tools/notification/Service.d.ts +6 -0
- package/src/tools/notification/Service.d.ts.map +1 -0
- package/src/tools/notification/Service.js +18 -0
- package/src/tools/notification/config.d.ts +5 -0
- package/src/tools/notification/config.d.ts.map +1 -0
- package/src/tools/notification/config.js +5 -0
- package/src/tools/notification/drivers/BaseDriver.d.ts +5 -0
- package/src/tools/notification/drivers/BaseDriver.d.ts.map +1 -0
- package/src/tools/notification/drivers/BaseDriver.js +8 -0
- package/src/tools/notification/drivers/Console.d.ts +7 -0
- package/src/tools/notification/drivers/Console.d.ts.map +1 -0
- package/src/tools/notification/drivers/Console.js +13 -0
- package/src/tools/notification/drivers/Slack.d.ts +16 -0
- package/src/tools/notification/drivers/Slack.d.ts.map +1 -0
- package/src/tools/notification/drivers/Slack.js +24 -0
- package/src/tools/notification/drivers/Termii.d.ts +10 -0
- package/src/tools/notification/drivers/Termii.d.ts.map +1 -0
- package/src/tools/notification/drivers/Termii.js +47 -0
- package/src/tools/notification/drivers/Twilio.d.ts +21 -0
- package/src/tools/notification/drivers/Twilio.d.ts.map +1 -0
- package/src/tools/notification/drivers/Twilio.js +48 -0
- package/src/tools/notification/templates/markdown/index.d.ts +15 -0
- package/src/tools/notification/templates/markdown/index.d.ts.map +1 -0
- package/src/tools/notification/templates/markdown/index.js +38 -0
- package/src/tools/notification/templates/markdown/registry.d.ts +15 -0
- package/src/tools/notification/templates/markdown/registry.d.ts.map +1 -0
- package/src/tools/notification/templates/markdown/registry.js +36 -0
- package/src/tools/notification/testing.d.ts +19 -0
- package/src/tools/notification/testing.d.ts.map +1 -0
- package/src/tools/notification/testing.js +35 -0
- package/src/tools/notification/testingHelpers.d.ts +12 -0
- package/src/tools/notification/testingHelpers.d.ts.map +1 -0
- package/src/tools/notification/testingHelpers.js +32 -0
- package/src/tools/queue/Queue.d.ts +23 -0
- package/src/tools/queue/Queue.d.ts.map +1 -0
- package/src/tools/queue/Queue.js +38 -0
- package/src/tools/queue/drivers/InMemory.d.ts +10 -0
- package/src/tools/queue/drivers/InMemory.d.ts.map +1 -0
- package/src/tools/queue/drivers/InMemory.js +55 -0
- package/src/tools/queue/drivers/Redis.d.ts +10 -0
- package/src/tools/queue/drivers/Redis.d.ts.map +1 -0
- package/src/tools/queue/drivers/Redis.js +91 -0
- package/src/tools/storage/drivers/Gcs.d.ts +20 -0
- package/src/tools/storage/drivers/Gcs.d.ts.map +1 -0
- package/src/tools/storage/drivers/Gcs.js +152 -0
- package/src/tools/storage/drivers/Local.d.ts +17 -0
- package/src/tools/storage/drivers/Local.d.ts.map +1 -0
- package/src/tools/storage/drivers/Local.js +63 -0
- package/src/tools/storage/drivers/R2.d.ts +20 -0
- package/src/tools/storage/drivers/R2.d.ts.map +1 -0
- package/src/tools/storage/drivers/R2.js +73 -0
- package/src/tools/storage/drivers/S3.d.ts +26 -0
- package/src/tools/storage/drivers/S3.d.ts.map +1 -0
- package/src/tools/storage/drivers/S3.js +258 -0
- package/src/tools/storage/index.d.ts +24 -0
- package/src/tools/storage/index.d.ts.map +1 -0
- package/src/tools/storage/index.js +112 -0
- package/src/tools/storage/testing.d.ts +23 -0
- package/src/tools/storage/testing.d.ts.map +1 -0
- package/src/tools/storage/testing.js +52 -0
- package/src/tools/templates/MarkdownRenderer.d.ts +14 -0
- package/src/tools/templates/MarkdownRenderer.d.ts.map +1 -0
- package/src/tools/templates/MarkdownRenderer.js +300 -0
- package/src/tools/templates/index.d.ts +5 -0
- package/src/tools/templates/index.d.ts.map +1 -0
- package/src/tools/templates/index.js +4 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { ErrorFactory } from '../../../exceptions/ZintrustError';
|
|
2
|
+
import { fsPromises as fs } from '../../../node-singletons/fs';
|
|
3
|
+
import * as path from '../../../node-singletons/path';
|
|
4
|
+
export const LocalDriver = Object.freeze({
|
|
5
|
+
async put(config, key, content) {
|
|
6
|
+
const root = config.root;
|
|
7
|
+
if (!root || root.trim() === '') {
|
|
8
|
+
throw ErrorFactory.createConfigError('Local storage root is not configured');
|
|
9
|
+
}
|
|
10
|
+
const fullPath = path.join(root, key);
|
|
11
|
+
const dir = path.dirname(fullPath);
|
|
12
|
+
await fs.mkdir(dir, { recursive: true });
|
|
13
|
+
if (typeof content === 'string') {
|
|
14
|
+
await fs.writeFile(fullPath, content, 'utf8');
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
await fs.writeFile(fullPath, content);
|
|
18
|
+
}
|
|
19
|
+
return fullPath;
|
|
20
|
+
},
|
|
21
|
+
async get(config, key) {
|
|
22
|
+
const fullPath = path.join(config.root, key);
|
|
23
|
+
try {
|
|
24
|
+
return await fs.readFile(fullPath);
|
|
25
|
+
}
|
|
26
|
+
catch (err) {
|
|
27
|
+
throw ErrorFactory.createNotFoundError('Local storage: file not found', { key, error: err });
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
async exists(config, key) {
|
|
31
|
+
const fullPath = path.join(config.root, key);
|
|
32
|
+
try {
|
|
33
|
+
await fs.access(fullPath);
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
async delete(config, key) {
|
|
41
|
+
const fullPath = path.join(config.root, key);
|
|
42
|
+
try {
|
|
43
|
+
await fs.unlink(fullPath);
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
// ignore not found
|
|
47
|
+
void err; // NOSONAR
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
url(config, key) {
|
|
51
|
+
if (config?.url === undefined || config.url.trim() === '')
|
|
52
|
+
return undefined;
|
|
53
|
+
return `${config.url.replace(/\/$/, '')}/${key}`;
|
|
54
|
+
},
|
|
55
|
+
tempUrl(config, key, _options) {
|
|
56
|
+
const url = LocalDriver.url(config, key);
|
|
57
|
+
if (url === undefined) {
|
|
58
|
+
throw ErrorFactory.createConfigError('Local storage: url is not configured (set STORAGE_URL)');
|
|
59
|
+
}
|
|
60
|
+
return url;
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
export default LocalDriver;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type R2Config = {
|
|
2
|
+
bucket: string;
|
|
3
|
+
region?: string;
|
|
4
|
+
accessKeyId: string;
|
|
5
|
+
secretAccessKey: string;
|
|
6
|
+
endpoint?: string;
|
|
7
|
+
};
|
|
8
|
+
export declare const R2Driver: Readonly<{
|
|
9
|
+
put(config: R2Config, key: string, content: string | Buffer): Promise<string>;
|
|
10
|
+
get(config: R2Config, key: string): Promise<Buffer>;
|
|
11
|
+
exists(config: R2Config, key: string): Promise<boolean>;
|
|
12
|
+
delete(config: R2Config, key: string): Promise<void>;
|
|
13
|
+
url(config: R2Config, key: string): string;
|
|
14
|
+
tempUrl(config: R2Config, key: string, options?: {
|
|
15
|
+
expiresIn?: number;
|
|
16
|
+
method?: "GET" | "PUT";
|
|
17
|
+
}): string;
|
|
18
|
+
}>;
|
|
19
|
+
export default R2Driver;
|
|
20
|
+
//# sourceMappingURL=R2.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"R2.d.ts","sourceRoot":"","sources":["../../../../../src/tools/storage/drivers/R2.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,QAAQ,GAAG;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,eAAO,MAAM,QAAQ;gBACD,QAAQ,OAAO,MAAM,WAAW,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;gBAkBjE,QAAQ,OAAO,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;mBAapC,QAAQ,OAAO,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;mBAaxC,QAAQ,OAAO,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;gBAa9C,QAAQ,OAAO,MAAM,GAAG,MAAM;oBAQhC,QAAQ,OACX,MAAM,YACD;QAAE,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,KAAK,GAAG,KAAK,CAAA;KAAE,GACvD,MAAM;EAgBT,CAAC;AAEH,eAAe,QAAQ,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { ErrorFactory } from '../../../exceptions/ZintrustError';
|
|
2
|
+
import { S3Driver } from '../drivers/S3';
|
|
3
|
+
export const R2Driver = Object.freeze({
|
|
4
|
+
async put(config, key, content) {
|
|
5
|
+
if (typeof config.endpoint !== 'string' || config.endpoint.trim() === '') {
|
|
6
|
+
throw ErrorFactory.createConfigError('R2: missing endpoint');
|
|
7
|
+
}
|
|
8
|
+
// Delegate to S3Driver using path-style endpoint
|
|
9
|
+
const s3Config = {
|
|
10
|
+
bucket: config.bucket,
|
|
11
|
+
region: config.region ?? 'auto',
|
|
12
|
+
accessKeyId: config.accessKeyId,
|
|
13
|
+
secretAccessKey: config.secretAccessKey,
|
|
14
|
+
endpoint: config.endpoint,
|
|
15
|
+
usePathStyle: true,
|
|
16
|
+
};
|
|
17
|
+
return S3Driver.put(s3Config, key, content);
|
|
18
|
+
},
|
|
19
|
+
async get(config, key) {
|
|
20
|
+
const s3Config = {
|
|
21
|
+
bucket: config.bucket,
|
|
22
|
+
region: config.region ?? 'auto',
|
|
23
|
+
accessKeyId: config.accessKeyId,
|
|
24
|
+
secretAccessKey: config.secretAccessKey,
|
|
25
|
+
endpoint: config.endpoint,
|
|
26
|
+
usePathStyle: true,
|
|
27
|
+
};
|
|
28
|
+
return S3Driver.get(s3Config, key);
|
|
29
|
+
},
|
|
30
|
+
async exists(config, key) {
|
|
31
|
+
const s3Config = {
|
|
32
|
+
bucket: config.bucket,
|
|
33
|
+
region: config.region ?? 'auto',
|
|
34
|
+
accessKeyId: config.accessKeyId,
|
|
35
|
+
secretAccessKey: config.secretAccessKey,
|
|
36
|
+
endpoint: config.endpoint,
|
|
37
|
+
usePathStyle: true,
|
|
38
|
+
};
|
|
39
|
+
return S3Driver.exists(s3Config, key);
|
|
40
|
+
},
|
|
41
|
+
async delete(config, key) {
|
|
42
|
+
const s3Config = {
|
|
43
|
+
bucket: config.bucket,
|
|
44
|
+
region: config.region ?? 'auto',
|
|
45
|
+
accessKeyId: config.accessKeyId,
|
|
46
|
+
secretAccessKey: config.secretAccessKey,
|
|
47
|
+
endpoint: config.endpoint,
|
|
48
|
+
usePathStyle: true,
|
|
49
|
+
};
|
|
50
|
+
return S3Driver.delete(s3Config, key);
|
|
51
|
+
},
|
|
52
|
+
url(config, key) {
|
|
53
|
+
if (config.endpoint !== undefined && config.endpoint.trim() !== '') {
|
|
54
|
+
return `${config.endpoint.replace(/\/$/, '')}/${config.bucket}/${key}`;
|
|
55
|
+
}
|
|
56
|
+
return `https://${config.bucket}.r2.cloudflarestorage.com/${key}`;
|
|
57
|
+
},
|
|
58
|
+
tempUrl(config, key, options) {
|
|
59
|
+
if (typeof config.endpoint !== 'string' || config.endpoint.trim() === '') {
|
|
60
|
+
throw ErrorFactory.createConfigError('R2: missing endpoint');
|
|
61
|
+
}
|
|
62
|
+
const s3Config = {
|
|
63
|
+
bucket: config.bucket,
|
|
64
|
+
region: config.region ?? 'auto',
|
|
65
|
+
accessKeyId: config.accessKeyId,
|
|
66
|
+
secretAccessKey: config.secretAccessKey,
|
|
67
|
+
endpoint: config.endpoint,
|
|
68
|
+
usePathStyle: true,
|
|
69
|
+
};
|
|
70
|
+
return S3Driver.tempUrl(s3Config, key, options);
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
export default R2Driver;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export type S3Config = {
|
|
2
|
+
bucket: string;
|
|
3
|
+
region: string;
|
|
4
|
+
accessKeyId: string;
|
|
5
|
+
secretAccessKey: string;
|
|
6
|
+
endpoint?: string;
|
|
7
|
+
usePathStyle?: boolean;
|
|
8
|
+
};
|
|
9
|
+
export type GS3Cred = {
|
|
10
|
+
accessKeyId: string;
|
|
11
|
+
secretAccessKey: string;
|
|
12
|
+
sessionToken: string | undefined;
|
|
13
|
+
};
|
|
14
|
+
export declare const S3Driver: Readonly<{
|
|
15
|
+
put(config: S3Config, key: string, content: string | Buffer): Promise<string>;
|
|
16
|
+
get(config: S3Config, key: string): Promise<Buffer>;
|
|
17
|
+
exists(config: S3Config, key: string): Promise<boolean>;
|
|
18
|
+
delete(config: S3Config, key: string): Promise<void>;
|
|
19
|
+
url(config: S3Config, key: string): string;
|
|
20
|
+
tempUrl(config: S3Config, key: string, options?: {
|
|
21
|
+
expiresIn?: number;
|
|
22
|
+
method?: "GET" | "PUT";
|
|
23
|
+
}): string;
|
|
24
|
+
}>;
|
|
25
|
+
export default S3Driver;
|
|
26
|
+
//# sourceMappingURL=S3.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"S3.d.ts","sourceRoot":"","sources":["../../../../../src/tools/storage/drivers/S3.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,QAAQ,GAAG;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;CAClC,CAAC;AAwGF,eAAO,MAAM,QAAQ;gBACD,QAAQ,OAAO,MAAM,WAAW,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;gBA8CjE,QAAQ,OAAO,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;mBA0CpC,QAAQ,OAAO,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;mBAkCxC,QAAQ,OAAO,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;gBAoC9C,QAAQ,OAAO,MAAM,GAAG,MAAM;oBAOhC,QAAQ,OACX,MAAM,YACD;QAAE,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,KAAK,GAAG,KAAK,CAAA;KAAE,GACvD,MAAM;EAqDT,CAAC;AAEH,eAAe,QAAQ,CAAC"}
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import { AwsSigV4 } from '../../../common/index';
|
|
2
|
+
import { ErrorFactory } from '../../../exceptions/ZintrustError';
|
|
3
|
+
import { createHash, createHmac } from '../../../node-singletons/crypto';
|
|
4
|
+
const sha256Hex = (data) => createHash('sha256').update(data).digest('hex');
|
|
5
|
+
const buildAuthorization = (params) => {
|
|
6
|
+
const canonicalUri = params.path;
|
|
7
|
+
const canonicalQueryString = '';
|
|
8
|
+
const headers = {
|
|
9
|
+
host: params.host,
|
|
10
|
+
'x-amz-date': params.amzDate,
|
|
11
|
+
'x-amz-content-sha256': params.payloadHash,
|
|
12
|
+
};
|
|
13
|
+
if (params.credentials.sessionToken !== undefined)
|
|
14
|
+
headers['x-amz-security-token'] = params.credentials.sessionToken;
|
|
15
|
+
return AwsSigV4.buildAuthorization({
|
|
16
|
+
method: params.method,
|
|
17
|
+
canonicalUri,
|
|
18
|
+
canonicalQueryString,
|
|
19
|
+
headers,
|
|
20
|
+
payloadHash: params.payloadHash,
|
|
21
|
+
region: params.region,
|
|
22
|
+
service: 's3',
|
|
23
|
+
amzDate: params.amzDate,
|
|
24
|
+
dateStamp: params.dateStamp,
|
|
25
|
+
credentials: params.credentials,
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
const buildHostAndPath = (config, key) => {
|
|
29
|
+
const endpoint = config.endpoint?.trim() ?? '';
|
|
30
|
+
if (endpoint !== '') {
|
|
31
|
+
// if endpoint provided, prefer path-style
|
|
32
|
+
const host = endpoint.replace(/^https?:\/\//, '').replace(/\/$/, '');
|
|
33
|
+
const path = `/${config.bucket}/${key}`;
|
|
34
|
+
return { host, path, url: `${endpoint.replace(/\/$/, '')}/${config.bucket}/${key}` };
|
|
35
|
+
}
|
|
36
|
+
const host = `${config.bucket}.s3.${config.region}.amazonaws.com`;
|
|
37
|
+
const path = `/${key}`;
|
|
38
|
+
const url = `https://${host}${path}`;
|
|
39
|
+
return { host, path, url };
|
|
40
|
+
};
|
|
41
|
+
const awsEncodeURIComponent = (value) => encodeURIComponent(value).replaceAll(/[!'()*]/g, (c) => `%${c.codePointAt(0)?.toString(16).toUpperCase()}`);
|
|
42
|
+
const encodePathSegments = (key) => key
|
|
43
|
+
.split('/')
|
|
44
|
+
.map((seg) => awsEncodeURIComponent(seg))
|
|
45
|
+
.join('/');
|
|
46
|
+
const buildCanonicalQueryString = (params) => {
|
|
47
|
+
const entries = Object.entries(params)
|
|
48
|
+
.filter(([, v]) => v !== '')
|
|
49
|
+
.map(([k, v]) => [awsEncodeURIComponent(k), awsEncodeURIComponent(v)])
|
|
50
|
+
.sort((a, b) => a[0].localeCompare(b[0]));
|
|
51
|
+
return entries.map(([k, v]) => `${k}=${v}`).join('&');
|
|
52
|
+
};
|
|
53
|
+
const getCredentials = (config) => {
|
|
54
|
+
const accessKeyId = config.accessKeyId ?? process.env['AWS_ACCESS_KEY_ID'] ?? '';
|
|
55
|
+
const secretAccessKey = config.secretAccessKey ?? process.env['AWS_SECRET_ACCESS_KEY'] ?? '';
|
|
56
|
+
const sessionToken = process.env['AWS_SESSION_TOKEN'] ?? undefined;
|
|
57
|
+
if (accessKeyId.trim() === '' || secretAccessKey.trim() === '') {
|
|
58
|
+
throw ErrorFactory.createConfigError('S3: missing AWS credentials');
|
|
59
|
+
}
|
|
60
|
+
return { accessKeyId, secretAccessKey, sessionToken };
|
|
61
|
+
};
|
|
62
|
+
const validateExpiresIn = (expiresIn) => {
|
|
63
|
+
if (!Number.isFinite(expiresIn) || expiresIn <= 0) {
|
|
64
|
+
throw ErrorFactory.createValidationError('S3: expiresIn must be a positive number', {
|
|
65
|
+
expiresIn,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
if (expiresIn > 604800) {
|
|
69
|
+
throw ErrorFactory.createValidationError('S3: expiresIn exceeds maximum (604800 seconds)', {
|
|
70
|
+
expiresIn,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
export const S3Driver = Object.freeze({
|
|
75
|
+
async put(config, key, content) {
|
|
76
|
+
const { accessKeyId, secretAccessKey, sessionToken } = getCredentials(config);
|
|
77
|
+
const { host, path, url } = buildHostAndPath(config, key);
|
|
78
|
+
const now = new Date();
|
|
79
|
+
const { amzDate, dateStamp } = AwsSigV4.toAmzDate(now);
|
|
80
|
+
const body = typeof content === 'string' ? content : Buffer.from(content);
|
|
81
|
+
const payloadHash = sha256Hex(body);
|
|
82
|
+
const { authorization } = buildAuthorization({
|
|
83
|
+
method: 'PUT',
|
|
84
|
+
host,
|
|
85
|
+
region: config.region,
|
|
86
|
+
amzDate,
|
|
87
|
+
dateStamp,
|
|
88
|
+
credentials: { accessKeyId, secretAccessKey, sessionToken },
|
|
89
|
+
payloadHash,
|
|
90
|
+
path,
|
|
91
|
+
});
|
|
92
|
+
const headers = {
|
|
93
|
+
'x-amz-date': amzDate,
|
|
94
|
+
'x-amz-content-sha256': payloadHash,
|
|
95
|
+
Authorization: authorization,
|
|
96
|
+
};
|
|
97
|
+
if (sessionToken !== undefined)
|
|
98
|
+
headers['x-amz-security-token'] = sessionToken;
|
|
99
|
+
const res = await fetch(`https://${host}${path}`, {
|
|
100
|
+
method: 'PUT',
|
|
101
|
+
headers,
|
|
102
|
+
body,
|
|
103
|
+
});
|
|
104
|
+
if (!res.ok) {
|
|
105
|
+
const text = await res.text();
|
|
106
|
+
throw ErrorFactory.createConnectionError(`S3 put failed (${res.status})`, {
|
|
107
|
+
status: res.status,
|
|
108
|
+
body: text,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
return url;
|
|
112
|
+
},
|
|
113
|
+
async get(config, key) {
|
|
114
|
+
const { accessKeyId, secretAccessKey, sessionToken } = getCredentials(config);
|
|
115
|
+
const { host, path } = buildHostAndPath(config, key);
|
|
116
|
+
const now = new Date();
|
|
117
|
+
const { amzDate, dateStamp } = AwsSigV4.toAmzDate(now);
|
|
118
|
+
const payloadHash = sha256Hex('');
|
|
119
|
+
const { authorization } = buildAuthorization({
|
|
120
|
+
method: 'GET',
|
|
121
|
+
host,
|
|
122
|
+
region: config.region,
|
|
123
|
+
amzDate,
|
|
124
|
+
dateStamp,
|
|
125
|
+
credentials: { accessKeyId, secretAccessKey, sessionToken },
|
|
126
|
+
payloadHash,
|
|
127
|
+
path,
|
|
128
|
+
});
|
|
129
|
+
const headers = {
|
|
130
|
+
'x-amz-date': amzDate,
|
|
131
|
+
'x-amz-content-sha256': payloadHash,
|
|
132
|
+
Authorization: authorization,
|
|
133
|
+
};
|
|
134
|
+
if (sessionToken !== undefined)
|
|
135
|
+
headers['x-amz-security-token'] = sessionToken;
|
|
136
|
+
const res = await fetch(`https://${host}${path}`, {
|
|
137
|
+
method: 'GET',
|
|
138
|
+
headers,
|
|
139
|
+
});
|
|
140
|
+
if (!res.ok) {
|
|
141
|
+
const text = await res.text();
|
|
142
|
+
throw ErrorFactory.createNotFoundError('S3 get failed', { status: res.status, body: text });
|
|
143
|
+
}
|
|
144
|
+
const buf = Buffer.from(await res.arrayBuffer());
|
|
145
|
+
return buf;
|
|
146
|
+
},
|
|
147
|
+
async exists(config, key) {
|
|
148
|
+
try {
|
|
149
|
+
const { accessKeyId, secretAccessKey, sessionToken } = getCredentials(config);
|
|
150
|
+
const { host, path } = buildHostAndPath(config, key);
|
|
151
|
+
const now = new Date();
|
|
152
|
+
const { amzDate, dateStamp } = AwsSigV4.toAmzDate(now);
|
|
153
|
+
const payloadHash = sha256Hex('');
|
|
154
|
+
const { authorization } = buildAuthorization({
|
|
155
|
+
method: 'HEAD',
|
|
156
|
+
host,
|
|
157
|
+
region: config.region,
|
|
158
|
+
amzDate,
|
|
159
|
+
dateStamp,
|
|
160
|
+
credentials: { accessKeyId, secretAccessKey, sessionToken },
|
|
161
|
+
payloadHash,
|
|
162
|
+
path,
|
|
163
|
+
});
|
|
164
|
+
const headers = {
|
|
165
|
+
'x-amz-date': amzDate,
|
|
166
|
+
'x-amz-content-sha256': payloadHash,
|
|
167
|
+
Authorization: authorization,
|
|
168
|
+
};
|
|
169
|
+
if (sessionToken !== undefined)
|
|
170
|
+
headers['x-amz-security-token'] = sessionToken;
|
|
171
|
+
const res = await fetch(`https://${host}${path}`, { method: 'HEAD', headers });
|
|
172
|
+
return res.ok;
|
|
173
|
+
}
|
|
174
|
+
catch {
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
async delete(config, key) {
|
|
179
|
+
const { accessKeyId, secretAccessKey, sessionToken } = getCredentials(config);
|
|
180
|
+
const { host, path } = buildHostAndPath(config, key);
|
|
181
|
+
const now = new Date();
|
|
182
|
+
const { amzDate, dateStamp } = AwsSigV4.toAmzDate(now);
|
|
183
|
+
const payloadHash = sha256Hex('');
|
|
184
|
+
const { authorization } = buildAuthorization({
|
|
185
|
+
method: 'DELETE',
|
|
186
|
+
host,
|
|
187
|
+
region: config.region,
|
|
188
|
+
amzDate,
|
|
189
|
+
dateStamp,
|
|
190
|
+
credentials: { accessKeyId, secretAccessKey, sessionToken },
|
|
191
|
+
payloadHash,
|
|
192
|
+
path,
|
|
193
|
+
});
|
|
194
|
+
const headers = {
|
|
195
|
+
'x-amz-date': amzDate,
|
|
196
|
+
'x-amz-content-sha256': payloadHash,
|
|
197
|
+
Authorization: authorization,
|
|
198
|
+
};
|
|
199
|
+
if (sessionToken !== undefined)
|
|
200
|
+
headers['x-amz-security-token'] = sessionToken;
|
|
201
|
+
const res = await fetch(`https://${host}${path}`, { method: 'DELETE', headers });
|
|
202
|
+
if (!res.ok) {
|
|
203
|
+
const text = await res.text();
|
|
204
|
+
throw ErrorFactory.createConnectionError(`S3 delete failed (${res.status})`, {
|
|
205
|
+
status: res.status,
|
|
206
|
+
body: text,
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
},
|
|
210
|
+
url(config, key) {
|
|
211
|
+
const endpoint = config.endpoint?.trim() ?? '';
|
|
212
|
+
if (endpoint !== '')
|
|
213
|
+
return `${endpoint.replace(/\/$/, '')}/${config.bucket}/${key}`;
|
|
214
|
+
return `https://${config.bucket}.s3.${config.region}.amazonaws.com/${key}`;
|
|
215
|
+
},
|
|
216
|
+
tempUrl(config, key, options) {
|
|
217
|
+
const { accessKeyId, secretAccessKey, sessionToken } = getCredentials(config);
|
|
218
|
+
const expiresIn = options?.expiresIn ?? 900;
|
|
219
|
+
validateExpiresIn(expiresIn);
|
|
220
|
+
const method = options?.method ?? 'GET';
|
|
221
|
+
const encodedKey = encodePathSegments(key);
|
|
222
|
+
const { host, path } = buildHostAndPath(config, encodedKey);
|
|
223
|
+
const now = new Date();
|
|
224
|
+
const { amzDate, dateStamp } = AwsSigV4.toAmzDate(now);
|
|
225
|
+
const algorithm = 'AWS4-HMAC-SHA256';
|
|
226
|
+
const credentialScope = `${dateStamp}/${config.region}/s3/aws4_request`;
|
|
227
|
+
const credential = `${accessKeyId}/${credentialScope}`;
|
|
228
|
+
const queryParams = {
|
|
229
|
+
'X-Amz-Algorithm': algorithm,
|
|
230
|
+
'X-Amz-Credential': credential,
|
|
231
|
+
'X-Amz-Date': amzDate,
|
|
232
|
+
'X-Amz-Expires': String(Math.floor(expiresIn)),
|
|
233
|
+
'X-Amz-SignedHeaders': 'host',
|
|
234
|
+
};
|
|
235
|
+
if (sessionToken !== undefined)
|
|
236
|
+
queryParams['X-Amz-Security-Token'] = sessionToken;
|
|
237
|
+
const canonicalQueryString = buildCanonicalQueryString(queryParams);
|
|
238
|
+
const canonicalRequest = [
|
|
239
|
+
method,
|
|
240
|
+
path,
|
|
241
|
+
canonicalQueryString,
|
|
242
|
+
`host:${host}\n`,
|
|
243
|
+
'host',
|
|
244
|
+
'UNSIGNED-PAYLOAD',
|
|
245
|
+
].join('\n');
|
|
246
|
+
const stringToSign = [algorithm, amzDate, credentialScope, sha256Hex(canonicalRequest)].join('\n');
|
|
247
|
+
const signingKey = AwsSigV4.deriveSigningKey({
|
|
248
|
+
secretAccessKey,
|
|
249
|
+
dateStamp,
|
|
250
|
+
region: config.region,
|
|
251
|
+
service: 's3',
|
|
252
|
+
});
|
|
253
|
+
const signature = createHmac('sha256', signingKey).update(stringToSign).digest('hex');
|
|
254
|
+
const baseUrl = `https://${host}${path}`;
|
|
255
|
+
return `${baseUrl}?${canonicalQueryString}&X-Amz-Signature=${signature}`;
|
|
256
|
+
},
|
|
257
|
+
});
|
|
258
|
+
export default S3Driver;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { GcsDriver } from '../../tools/storage/drivers/Gcs';
|
|
2
|
+
import { LocalDriver } from './drivers/Local';
|
|
3
|
+
import { R2Driver } from './drivers/R2';
|
|
4
|
+
import { S3Driver } from './drivers/S3';
|
|
5
|
+
export type DiskName = 'local' | 's3' | 'gcs' | 'r2';
|
|
6
|
+
export type StorageDisk = {
|
|
7
|
+
driver: typeof LocalDriver | typeof S3Driver | typeof R2Driver | typeof GcsDriver;
|
|
8
|
+
config: unknown;
|
|
9
|
+
};
|
|
10
|
+
type TempUrlOptions = {
|
|
11
|
+
expiresIn?: number;
|
|
12
|
+
method?: 'GET' | 'PUT';
|
|
13
|
+
};
|
|
14
|
+
export declare const Storage: Readonly<{
|
|
15
|
+
getDisk(name?: string): StorageDisk;
|
|
16
|
+
put(disk: string | undefined, path: string, contents: string | Buffer): Promise<string>;
|
|
17
|
+
get(disk: string | undefined, path: string): Promise<Buffer>;
|
|
18
|
+
exists(disk: string | undefined, path: string): Promise<boolean>;
|
|
19
|
+
delete(disk: string | undefined, path: string): Promise<void>;
|
|
20
|
+
url(disk: string | undefined, path: string): string;
|
|
21
|
+
tempUrl(disk: string | undefined, path: string, options?: TempUrlOptions): string;
|
|
22
|
+
}>;
|
|
23
|
+
export default Storage;
|
|
24
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/tools/storage/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAE/C,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,IAAI,GAAG,KAAK,GAAG,IAAI,CAAC;AAErD,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,EAAE,OAAO,WAAW,GAAG,OAAO,QAAQ,GAAG,OAAO,QAAQ,GAAG,OAAO,SAAS,CAAC;IAClF,MAAM,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF,KAAK,cAAc,GAAG;IAAE,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,KAAK,GAAG,KAAK,CAAA;CAAE,CAAC;AAsCrE,eAAO,MAAM,OAAO;mBACH,MAAM,GAAG,WAAW;cAqBnB,MAAM,GAAG,SAAS,QAAQ,MAAM,YAAY,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;cAW7E,MAAM,GAAG,SAAS,QAAQ,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;iBAW/C,MAAM,GAAG,SAAS,QAAQ,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;iBASnD,MAAM,GAAG,SAAS,QAAQ,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;cASzD,MAAM,GAAG,SAAS,QAAQ,MAAM,GAAG,MAAM;kBAYrC,MAAM,GAAG,SAAS,QAAQ,MAAM,YAAY,cAAc,GAAG,MAAM;EAiBjF,CAAC;AAEH,eAAe,OAAO,CAAC"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { storageConfig } from '../../config/storage';
|
|
2
|
+
import { ErrorFactory } from '../../exceptions/ZintrustError';
|
|
3
|
+
// import { GcsDriver } from './drivers/Gcs';
|
|
4
|
+
import { GcsDriver } from '../../tools/storage/drivers/Gcs';
|
|
5
|
+
import { LocalDriver } from './drivers/Local';
|
|
6
|
+
import { R2Driver } from './drivers/R2';
|
|
7
|
+
import { S3Driver } from './drivers/S3';
|
|
8
|
+
const normalizers = {
|
|
9
|
+
local: (raw) => ({
|
|
10
|
+
root: String(raw['root'] ?? ''),
|
|
11
|
+
url: typeof raw['url'] === 'string' ? raw['url'] : undefined,
|
|
12
|
+
}),
|
|
13
|
+
s3: (raw) => ({
|
|
14
|
+
bucket: String(raw['bucket'] ?? ''),
|
|
15
|
+
region: String(raw['region'] ?? ''),
|
|
16
|
+
accessKeyId: String(raw['accessKeyId'] ?? raw['key'] ?? ''),
|
|
17
|
+
secretAccessKey: String(raw['secretAccessKey'] ?? raw['secret'] ?? ''),
|
|
18
|
+
endpoint: typeof raw['endpoint'] === 'string' ? raw['endpoint'] : undefined,
|
|
19
|
+
usePathStyle: Boolean(raw['usePathStyle'] ?? raw['usePathStyleUrl'] ?? false),
|
|
20
|
+
}),
|
|
21
|
+
r2: (raw) => ({
|
|
22
|
+
bucket: String(raw['bucket'] ?? ''),
|
|
23
|
+
region: typeof raw['region'] === 'string' ? raw['region'] : undefined,
|
|
24
|
+
accessKeyId: String(raw['accessKeyId'] ?? raw['key'] ?? ''),
|
|
25
|
+
secretAccessKey: String(raw['secretAccessKey'] ?? raw['secret'] ?? ''),
|
|
26
|
+
endpoint: typeof raw['endpoint'] === 'string' ? raw['endpoint'] : undefined,
|
|
27
|
+
url: typeof raw['url'] === 'string' ? raw['url'] : undefined,
|
|
28
|
+
}),
|
|
29
|
+
gcs: (raw) => ({
|
|
30
|
+
bucket: String(raw['bucket'] ?? ''),
|
|
31
|
+
projectId: typeof raw['projectId'] === 'string' ? raw['projectId'] : undefined,
|
|
32
|
+
keyFile: typeof raw['keyFile'] === 'string' ? raw['keyFile'] : undefined,
|
|
33
|
+
url: typeof raw['url'] === 'string' ? raw['url'] : undefined,
|
|
34
|
+
}),
|
|
35
|
+
};
|
|
36
|
+
const normalizeDiskConfig = (driverName, raw) => {
|
|
37
|
+
return normalizers[driverName]?.(raw) ?? raw;
|
|
38
|
+
};
|
|
39
|
+
export const Storage = Object.freeze({
|
|
40
|
+
getDisk(name) {
|
|
41
|
+
const diskName = name ?? storageConfig.default;
|
|
42
|
+
// disk is config object; dispatch based on requested name
|
|
43
|
+
const drivers = storageConfig.drivers;
|
|
44
|
+
const config = drivers[diskName];
|
|
45
|
+
if (config === undefined)
|
|
46
|
+
throw ErrorFactory.createValidationError('Storage: unknown disk', { disk: diskName });
|
|
47
|
+
const driverName = String(config['driver'] ?? '');
|
|
48
|
+
if (driverName === 'local')
|
|
49
|
+
return { driver: LocalDriver, config: normalizeDiskConfig('local', config) };
|
|
50
|
+
if (driverName === 's3')
|
|
51
|
+
return { driver: S3Driver, config: normalizeDiskConfig('s3', config) };
|
|
52
|
+
if (driverName === 'r2')
|
|
53
|
+
return { driver: R2Driver, config: normalizeDiskConfig('r2', config) };
|
|
54
|
+
if (driverName === 'gcs')
|
|
55
|
+
return { driver: GcsDriver, config: normalizeDiskConfig('gcs', config) };
|
|
56
|
+
throw ErrorFactory.createValidationError('Storage: unsupported disk driver', {
|
|
57
|
+
driver: config['driver'],
|
|
58
|
+
});
|
|
59
|
+
},
|
|
60
|
+
async put(disk, path, contents) {
|
|
61
|
+
const d = Storage.getDisk(disk);
|
|
62
|
+
const driver = d.driver;
|
|
63
|
+
if (typeof driver.put !== 'function') {
|
|
64
|
+
throw ErrorFactory.createConfigError('Storage: driver is missing put()');
|
|
65
|
+
}
|
|
66
|
+
return driver.put(d.config, path, contents);
|
|
67
|
+
},
|
|
68
|
+
async get(disk, path) {
|
|
69
|
+
const d = Storage.getDisk(disk);
|
|
70
|
+
const driver = d.driver;
|
|
71
|
+
if (typeof driver.get !== 'function') {
|
|
72
|
+
throw ErrorFactory.createConfigError('Storage: driver is missing get()');
|
|
73
|
+
}
|
|
74
|
+
return Promise.resolve(driver.get(d.config, path));
|
|
75
|
+
},
|
|
76
|
+
async exists(disk, path) {
|
|
77
|
+
const d = Storage.getDisk(disk);
|
|
78
|
+
const driver = d.driver;
|
|
79
|
+
if (typeof driver.exists !== 'function')
|
|
80
|
+
return true;
|
|
81
|
+
return Boolean(await Promise.resolve(driver.exists(d.config, path)));
|
|
82
|
+
},
|
|
83
|
+
async delete(disk, path) {
|
|
84
|
+
const d = Storage.getDisk(disk);
|
|
85
|
+
const driver = d.driver;
|
|
86
|
+
if (typeof driver.delete !== 'function')
|
|
87
|
+
return;
|
|
88
|
+
await Promise.resolve(driver.delete(d.config, path));
|
|
89
|
+
},
|
|
90
|
+
url(disk, path) {
|
|
91
|
+
const d = Storage.getDisk(disk);
|
|
92
|
+
const driver = d.driver;
|
|
93
|
+
const url = typeof driver.url === 'function' ? driver.url(d.config, path) : undefined;
|
|
94
|
+
if (typeof url !== 'string' || url.trim() === '') {
|
|
95
|
+
throw ErrorFactory.createConfigError('Storage: driver cannot build url()');
|
|
96
|
+
}
|
|
97
|
+
return url;
|
|
98
|
+
},
|
|
99
|
+
tempUrl(disk, path, options) {
|
|
100
|
+
const d = Storage.getDisk(disk);
|
|
101
|
+
const driver = d.driver;
|
|
102
|
+
if (typeof driver.tempUrl === 'function') {
|
|
103
|
+
return driver.tempUrl(d.config, path, options);
|
|
104
|
+
}
|
|
105
|
+
const url = typeof driver.url === 'function' ? driver.url(d.config, path) : undefined;
|
|
106
|
+
if (typeof url !== 'string' || url.trim() === '') {
|
|
107
|
+
throw ErrorFactory.createConfigError('Storage: driver does not support tempUrl()');
|
|
108
|
+
}
|
|
109
|
+
return url;
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
export default Storage;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export type FakePut = {
|
|
2
|
+
disk: string;
|
|
3
|
+
path: string;
|
|
4
|
+
contents: Buffer;
|
|
5
|
+
};
|
|
6
|
+
export declare const FakeStorage: Readonly<{
|
|
7
|
+
_puts: Array<FakePut>;
|
|
8
|
+
put(disk: string, path: string, contents: Buffer): Promise<void>;
|
|
9
|
+
get(disk: string, path: string): Buffer<ArrayBufferLike>;
|
|
10
|
+
exists(disk: string, path: string): boolean;
|
|
11
|
+
delete(disk: string, path: string): Promise<void>;
|
|
12
|
+
url(disk: string, path: string): string;
|
|
13
|
+
tempUrl(disk: string, path: string, options?: {
|
|
14
|
+
expiresIn?: number;
|
|
15
|
+
method?: "GET" | "PUT";
|
|
16
|
+
}): string;
|
|
17
|
+
assertExists(disk: string, path: string): void;
|
|
18
|
+
assertMissing(disk: string, path: string): void;
|
|
19
|
+
getPuts(): FakePut[];
|
|
20
|
+
reset(): void;
|
|
21
|
+
}>;
|
|
22
|
+
export default FakeStorage;
|
|
23
|
+
//# sourceMappingURL=testing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../../../../src/tools/storage/testing.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,OAAO,GAAG;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAIF,eAAO,MAAM,WAAW;WACT,KAAK,CAAC,OAAO,CAAC;cAEX,MAAM,QAAQ,MAAM,YAAY,MAAM;cAM5C,MAAM,QAAQ,MAAM;iBAMjB,MAAM,QAAQ,MAAM;iBAId,MAAM,QAAQ,MAAM;cAW7B,MAAM,QAAQ,MAAM;kBAKhB,MAAM,QAAQ,MAAM,YAAY;QAAE,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,KAAK,GAAG,KAAK,CAAA;KAAE;uBAOzE,MAAM,QAAQ,MAAM;wBAMnB,MAAM,QAAQ,MAAM;;;EAgBxC,CAAC;AAEH,eAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { ErrorFactory } from '../../exceptions/ZintrustError';
|
|
2
|
+
export const FakeStorage = Object.freeze({
|
|
3
|
+
_puts: [],
|
|
4
|
+
async put(disk, path, contents) {
|
|
5
|
+
this._puts.push({ disk, path, contents });
|
|
6
|
+
// emulate async write
|
|
7
|
+
return Promise.resolve(); // NOSONAR
|
|
8
|
+
},
|
|
9
|
+
get(disk, path) {
|
|
10
|
+
const found = this._puts.find((p) => p.disk === disk && p.path === path);
|
|
11
|
+
if (!found)
|
|
12
|
+
throw ErrorFactory.createNotFoundError(`FakeStorage: ${disk}:${path} not found`);
|
|
13
|
+
return found.contents;
|
|
14
|
+
},
|
|
15
|
+
exists(disk, path) {
|
|
16
|
+
return this._puts.some((p) => p.disk === disk && p.path === path);
|
|
17
|
+
},
|
|
18
|
+
async delete(disk, path) {
|
|
19
|
+
// mutate the internal array rather than replacing the property (object is frozen)
|
|
20
|
+
this._puts.splice(0, this._puts.length, ...this._puts.filter((p) => !(p.disk === disk && p.path === path)));
|
|
21
|
+
return Promise.resolve(); // NOSONAR
|
|
22
|
+
},
|
|
23
|
+
// url builder is a convenience: returns a pseudo-url for testing
|
|
24
|
+
url(disk, path) {
|
|
25
|
+
return `fake://${disk}/${path}`;
|
|
26
|
+
},
|
|
27
|
+
// tempUrl builder is a convenience: matches the real API shape
|
|
28
|
+
tempUrl(disk, path, options) {
|
|
29
|
+
const expiresIn = options?.expiresIn ?? 900;
|
|
30
|
+
const method = options?.method ?? 'GET';
|
|
31
|
+
return `fake://${disk}/${path}?expiresIn=${expiresIn}&method=${method}`;
|
|
32
|
+
},
|
|
33
|
+
// Test assertions
|
|
34
|
+
assertExists(disk, path) {
|
|
35
|
+
if (!this._puts.some((p) => p.disk === disk && p.path === path)) {
|
|
36
|
+
throw ErrorFactory.createValidationError(`Expected ${disk}:${path} to exist in FakeStorage`);
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
assertMissing(disk, path) {
|
|
40
|
+
if (this._puts.some((p) => p.disk === disk && p.path === path)) {
|
|
41
|
+
throw ErrorFactory.createValidationError(`Expected ${disk}:${path} to be missing in FakeStorage`);
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
getPuts() {
|
|
45
|
+
return this._puts.slice();
|
|
46
|
+
},
|
|
47
|
+
reset() {
|
|
48
|
+
// clear the array in-place
|
|
49
|
+
this._puts.length = 0;
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
export default FakeStorage;
|