@zintrust/core 0.1.4 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/z.d.ts +2 -2
- package/bin/z.d.ts.map +1 -1
- package/bin/z.js +3 -2
- package/bin/zin.d.ts +2 -2
- package/bin/zin.d.ts.map +1 -1
- package/bin/zin.js +3 -2
- package/bin/zintrust-main.d.ts +9 -0
- package/bin/zintrust-main.d.ts.map +1 -0
- package/bin/zintrust-main.js +101 -0
- package/bin/zintrust-microservices.js +7 -7
- package/bin/zintrust.d.ts +5 -4
- package/bin/zintrust.d.ts.map +1 -1
- package/bin/zintrust.js +7 -87
- package/bin/zt.d.ts +2 -2
- package/bin/zt.d.ts.map +1 -1
- package/bin/zt.js +3 -2
- package/package.json +13 -3
- package/public/index.html +4 -0
- package/src/boot/Application.js +13 -13
- package/src/boot/Server.d.ts.map +1 -1
- package/src/boot/Server.js +47 -39
- package/src/boot/bootstrap.js +71 -36
- package/src/builder/BundleOptimizer.js +3 -3
- package/src/cache/Cache.js +6 -6
- package/src/cache/drivers/KVDriver.js +2 -2
- package/src/cache/drivers/MongoDriver.js +3 -3
- package/src/cache/drivers/RedisDriver.js +3 -3
- package/src/cli/BaseCommand.d.ts +2 -0
- package/src/cli/BaseCommand.d.ts.map +1 -1
- package/src/cli/BaseCommand.js +12 -2
- package/src/cli/CLI.js +23 -23
- package/src/cli/ErrorHandler.d.ts.map +1 -1
- package/src/cli/ErrorHandler.js +14 -8
- package/src/cli/commands/AddCommand.js +15 -15
- package/src/cli/commands/ConfigCommand.js +6 -6
- package/src/cli/commands/D1MigrateCommand.js +6 -6
- package/src/cli/commands/DebugCommand.js +3 -3
- package/src/cli/commands/FixCommand.js +5 -5
- package/src/cli/commands/KeyGenerateCommand.js +5 -5
- package/src/cli/commands/LogsCleanupCommand.js +2 -2
- package/src/cli/commands/LogsCommand.js +6 -6
- package/src/cli/commands/MakeMailTemplateCommand.d.ts.map +1 -1
- package/src/cli/commands/MakeMailTemplateCommand.js +8 -7
- package/src/cli/commands/MakeNotificationTemplateCommand.d.ts.map +1 -1
- package/src/cli/commands/MakeNotificationTemplateCommand.js +8 -7
- package/src/cli/commands/MigrateCommand.js +2 -2
- package/src/cli/commands/NewCommand.js +11 -11
- package/src/cli/commands/PluginCommand.js +3 -3
- package/src/cli/commands/PrepareCommand.js +6 -6
- package/src/cli/commands/QACommand.js +8 -8
- package/src/cli/commands/SecretsCommand.js +3 -3
- package/src/cli/commands/SimulateCommand.js +6 -6
- package/src/cli/commands/StartCommand.js +7 -7
- package/src/cli/commands/TemplatesCommand.js +5 -5
- package/src/cli/commands/index.js +12 -12
- package/src/cli/config/ConfigManager.js +5 -5
- package/src/cli/config/ConfigValidator.js +1 -1
- package/src/cli/config/index.js +3 -3
- package/src/cli/debug/Dashboard.js +3 -3
- package/src/cli/index.js +10 -10
- package/src/cli/logger/Logger.js +2 -2
- package/src/cli/scaffolding/ControllerGenerator.d.ts.map +1 -1
- package/src/cli/scaffolding/ControllerGenerator.js +48 -64
- package/src/cli/scaffolding/FactoryGenerator.js +6 -6
- package/src/cli/scaffolding/FeatureScaffolder.js +8 -8
- package/src/cli/scaffolding/FileGenerator.js +4 -4
- package/src/cli/scaffolding/MigrationGenerator.js +4 -4
- package/src/cli/scaffolding/ModelGenerator.js +5 -5
- package/src/cli/scaffolding/ProjectScaffolder.d.ts.map +1 -1
- package/src/cli/scaffolding/ProjectScaffolder.js +78 -15
- package/src/cli/scaffolding/RequestFactoryGenerator.js +5 -5
- package/src/cli/scaffolding/ResponseFactoryGenerator.js +5 -5
- package/src/cli/scaffolding/RouteGenerator.js +4 -4
- package/src/cli/scaffolding/SeederGenerator.js +7 -7
- package/src/cli/scaffolding/ServiceIntegrationTestGenerator.js +5 -5
- package/src/cli/scaffolding/ServiceRequestFactoryGenerator.js +4 -4
- package/src/cli/scaffolding/ServiceScaffolder.d.ts.map +1 -1
- package/src/cli/scaffolding/ServiceScaffolder.js +24 -23
- package/src/cli/scaffolding/TemplateEngine.d.ts.map +1 -1
- package/src/cli/scaffolding/TemplateEngine.js +0 -2
- package/src/cli/scaffolding/TemplateGenerator.js +4 -4
- package/src/cli/scaffolding/WorkflowGenerator.js +4 -4
- package/src/cli/scaffolding/index.js +16 -16
- package/src/cli/utils/DistPackager.js +4 -4
- package/src/cli/utils/EnvFileLoader.js +2 -2
- package/src/cli/utils/spawn.d.ts.map +1 -1
- package/src/cli/utils/spawn.js +18 -7
- package/src/common/AwsSigV4.js +1 -1
- package/src/common/index.js +5 -5
- package/src/common/uuid.js +2 -2
- package/src/config/FileLogWriter.js +4 -4
- package/src/config/SecretsManager.d.ts +1 -42
- package/src/config/SecretsManager.d.ts.map +1 -1
- package/src/config/SecretsManager.js +2 -2
- package/src/config/StartupConfigValidator.d.ts +1 -9
- package/src/config/StartupConfigValidator.d.ts.map +1 -1
- package/src/config/StartupConfigValidator.js +115 -22
- package/src/config/app.d.ts +1 -1
- package/src/config/app.d.ts.map +1 -1
- package/src/config/app.js +1 -1
- package/src/config/broadcast.d.ts +1 -26
- package/src/config/broadcast.d.ts.map +1 -1
- package/src/config/broadcast.js +1 -1
- package/src/config/cache.d.ts +1 -22
- package/src/config/cache.d.ts.map +1 -1
- package/src/config/cache.js +1 -1
- package/src/config/cloudflare.d.ts +1 -13
- package/src/config/cloudflare.d.ts.map +1 -1
- package/src/config/database.d.ts +2 -47
- package/src/config/database.d.ts.map +1 -1
- package/src/config/database.js +1 -1
- package/src/config/env.d.ts.map +1 -1
- package/src/config/env.js +6 -2
- package/src/config/features.js +2 -2
- package/src/config/index.d.ts +10 -287
- package/src/config/index.d.ts.map +1 -1
- package/src/config/index.js +16 -16
- package/src/config/logger.d.ts.map +1 -1
- package/src/config/logger.js +10 -8
- package/src/config/logging/HttpLogger.js +4 -4
- package/src/config/logging/KvLogger.js +2 -2
- package/src/config/logging/SlackLogger.js +3 -3
- package/src/config/mail.d.ts +1 -27
- package/src/config/mail.d.ts.map +1 -1
- package/src/config/mail.js +1 -1
- package/src/config/microservices.js +1 -1
- package/src/config/middleware.d.ts +2 -6
- package/src/config/middleware.d.ts.map +1 -1
- package/src/config/middleware.js +5 -5
- package/src/config/notification.d.ts +0 -21
- package/src/config/notification.d.ts.map +1 -1
- package/src/config/notification.js +1 -1
- package/src/config/queue.d.ts +1 -39
- package/src/config/queue.d.ts.map +1 -1
- package/src/config/queue.js +1 -1
- package/src/config/security.d.ts +12 -0
- package/src/config/security.d.ts.map +1 -1
- package/src/config/security.js +17 -5
- package/src/config/startup.d.ts +2 -0
- package/src/config/startup.d.ts.map +1 -1
- package/src/config/startup.js +2 -1
- package/src/config/storage.d.ts +1 -48
- package/src/config/storage.d.ts.map +1 -1
- package/src/config/storage.js +1 -1
- package/src/config/type.d.ts +335 -0
- package/src/config/type.d.ts.map +1 -0
- package/src/config/type.js +1 -0
- package/src/container/ServiceContainer.js +1 -1
- package/src/exceptions/ZintrustError.js +1 -1
- package/src/features/Queue.js +2 -2
- package/src/functions/cloudflare.js +4 -4
- package/src/functions/deno.js +4 -4
- package/src/functions/lambda.js +4 -4
- package/src/health/RuntimeHealthProbes.js +3 -3
- package/src/health/StartupHealthChecks.js +9 -9
- package/src/http/Kernel.js +10 -10
- package/src/http/RequestContext.js +2 -2
- package/src/http/Response.js +1 -1
- package/src/index.d.ts +36 -1
- package/src/index.d.ts.map +1 -1
- package/src/index.js +69 -36
- package/src/microservices/MicroserviceBootstrap.js +5 -5
- package/src/microservices/MicroserviceGenerator.js +10 -10
- package/src/microservices/MicroserviceManager.js +4 -4
- package/src/microservices/PostgresAdapter.js +3 -3
- package/src/microservices/RequestTracingMiddleware.js +3 -3
- package/src/microservices/ServiceAuthMiddleware.js +3 -3
- package/src/microservices/ServiceBundler.js +3 -3
- package/src/microservices/ServiceHealthMonitor.js +2 -2
- package/src/middleware/CsrfMiddleware.js +3 -3
- package/src/middleware/ErrorHandlerMiddleware.js +4 -4
- package/src/middleware/LoggingMiddleware.js +3 -3
- package/src/middleware/RateLimiter.js +1 -1
- package/src/middleware/index.js +6 -6
- package/src/node-singletons/http.d.ts +2 -2
- package/src/node-singletons/http.d.ts.map +1 -1
- package/src/node-singletons/http.js +1 -1
- package/src/node-singletons/index.js +14 -14
- package/src/node-singletons/path.d.ts +1 -1
- package/src/node.d.ts +5 -0
- package/src/node.d.ts.map +1 -0
- package/src/node.js +4 -0
- package/src/orm/ConnectionManager.js +3 -3
- package/src/orm/Database.js +8 -8
- package/src/orm/Model.js +5 -5
- package/src/orm/QueryBuilder.js +1 -1
- package/src/orm/Relationships.js +1 -1
- package/src/orm/adapters/D1Adapter.js +5 -5
- package/src/orm/adapters/MySQLAdapter.d.ts.map +1 -1
- package/src/orm/adapters/MySQLAdapter.js +4 -6
- package/src/orm/adapters/PostgreSQLAdapter.d.ts.map +1 -1
- package/src/orm/adapters/PostgreSQLAdapter.js +4 -6
- package/src/orm/adapters/SQLServerAdapter.d.ts.map +1 -1
- package/src/orm/adapters/SQLServerAdapter.js +4 -6
- package/src/orm/adapters/SQLiteAdapter.d.ts.map +1 -1
- package/src/orm/adapters/SQLiteAdapter.js +5 -7
- package/src/performance/CodeGenerationBenchmark.js +5 -5
- package/src/performance/Optimizer.js +3 -3
- package/src/performance/establish-baseline.js +4 -4
- package/src/profiling/RequestProfiler.js +4 -4
- package/src/runtime/PluginManager.js +8 -8
- package/src/runtime/RuntimeDetector.d.ts.map +1 -1
- package/src/runtime/RuntimeDetector.js +22 -12
- package/src/runtime/adapters/CloudflareAdapter.js +3 -3
- package/src/runtime/adapters/DenoAdapter.js +2 -2
- package/src/runtime/adapters/FargateAdapter.js +4 -4
- package/src/runtime/adapters/LambdaAdapter.js +4 -4
- package/src/runtime/adapters/NodeServerAdapter.js +4 -4
- package/src/scheduler/ScheduleRunner.js +2 -2
- package/src/scheduler/index.js +1 -1
- package/src/schedules/index.js +1 -1
- package/src/schedules/log-cleanup.js +2 -2
- package/src/scripts/GenerateEnvArtifacts.js +4 -4
- package/src/scripts/TemplateSync.js +8 -6
- package/src/security/CsrfTokenManager.js +2 -2
- package/src/security/Encryptor.js +3 -3
- package/src/security/Hash.js +2 -2
- package/src/security/JwtManager.js +2 -2
- package/src/security/StartupSecretValidation.js +4 -4
- package/src/security/UrlValidator.js +1 -1
- package/src/security/Xss.js +1 -1
- package/src/security/XssProtection.d.ts.map +1 -1
- package/src/security/XssProtection.js +8 -3
- package/src/templates/adapters/MySQLAdapter.ts.tpl +0 -2
- package/src/templates/adapters/PostgreSQLAdapter.ts.tpl +0 -3
- package/src/templates/adapters/SQLServerAdapter.ts.tpl +0 -2
- package/src/templates/adapters/SQLiteAdapter.ts.tpl +0 -2
- package/src/templates/project/basic/.env.tpl +8 -1
- package/src/templates/project/basic/app/Controllers/UserController.ts.tpl +3 -2
- package/src/templates/project/basic/app/Middleware/ProfilerMiddleware.ts.tpl +3 -2
- package/src/templates/project/basic/app/Middleware/index.ts.tpl +8 -14
- package/src/templates/project/basic/app/Models/Post.ts.tpl +2 -1
- package/src/templates/project/basic/app/Models/User.ts.tpl +1 -1
- package/src/templates/project/basic/app/Toolkit/Broadcast/sendBroadcast.ts.tpl +1 -1
- package/src/templates/project/basic/app/Toolkit/Mail/sendWelcomeEmail.ts.tpl +1 -1
- package/src/templates/project/basic/app/Toolkit/Notification/sendSlackNotification.ts.tpl +1 -1
- package/src/templates/project/basic/app/Toolkit/Notification/sendSms.ts.tpl +1 -1
- package/src/templates/project/basic/config/FileLogWriter.ts.tpl +2 -4
- package/src/templates/project/basic/config/SecretsManager.ts.tpl +6 -39
- package/src/templates/project/basic/config/StartupConfigValidator.ts.tpl +154 -37
- package/src/templates/project/basic/config/app.ts.tpl +1 -5
- package/src/templates/project/basic/config/broadcast.ts.tpl +6 -36
- package/src/templates/project/basic/config/cache.ts.tpl +1 -42
- package/src/templates/project/basic/config/cloudflare.ts.tpl +1 -15
- package/src/templates/project/basic/config/database.ts.tpl +5 -51
- package/src/templates/project/basic/config/env.ts.tpl +6 -7
- package/src/templates/project/basic/config/features.ts.tpl +1 -1
- package/src/templates/project/basic/config/index.ts.tpl +1 -1
- package/src/templates/project/basic/config/logger.ts.tpl +3 -1
- package/src/templates/project/basic/config/logging/HttpLogger.ts.tpl +1 -1
- package/src/templates/project/basic/config/logging/KvLogger.ts.tpl +1 -1
- package/src/templates/project/basic/config/logging/SlackLogger.ts.tpl +1 -1
- package/src/templates/project/basic/config/mail.ts.tpl +1 -57
- package/src/templates/project/basic/config/microservices.ts.tpl +1 -1
- package/src/templates/project/basic/config/middleware.ts.tpl +2 -6
- package/src/templates/project/basic/config/notification.ts.tpl +1 -36
- package/src/templates/project/basic/config/queue.ts.tpl +1 -49
- package/src/templates/project/basic/config/security.ts.tpl +13 -1
- package/src/templates/project/basic/config/startup.ts.tpl +2 -0
- package/src/templates/project/basic/config/storage.ts.tpl +6 -54
- package/src/templates/project/basic/config/type.ts.tpl +414 -0
- package/src/templates/project/basic/package.json.tpl +1 -0
- package/src/templates/project/basic/routes/api.ts.tpl +1 -1
- package/src/templates/project/basic/routes/broadcast.ts.tpl +1 -1
- package/src/templates/project/basic/routes/health.ts.tpl +1 -1
- package/src/templates/project/basic/routes/storage.ts.tpl +1 -1
- package/src/templates/project/basic/src/index.ts.tpl +49 -41
- package/src/templates/project/basic/template.json +1 -1
- package/src/templates/project/basic/tsconfig.json.tpl +3 -1
- package/src/toolkit/Secrets/EnvFile.js +3 -3
- package/src/toolkit/Secrets/Manifest.js +3 -3
- package/src/toolkit/Secrets/index.js +5 -5
- package/src/toolkit/Secrets/providers/AwsSecretsManager.js +2 -2
- package/src/toolkit/Secrets/providers/CloudflareKv.js +1 -1
- package/src/tools/broadcast/Broadcast.js +6 -6
- package/src/tools/broadcast/drivers/BaseDriver.js +1 -1
- package/src/tools/broadcast/drivers/Pusher.d.ts +1 -1
- package/src/tools/broadcast/drivers/Pusher.d.ts.map +1 -1
- package/src/tools/broadcast/drivers/Pusher.js +2 -2
- package/src/tools/broadcast/drivers/Redis.js +1 -1
- package/src/tools/broadcast/drivers/RedisHttps.js +3 -3
- package/src/tools/broadcast/index.js +6 -6
- package/src/tools/http/Http.js +4 -4
- package/src/tools/http/HttpResponse.js +1 -1
- package/src/tools/http/index.js +2 -2
- package/src/tools/mail/Mail.js +8 -8
- package/src/tools/mail/attachments.js +1 -1
- package/src/tools/mail/drivers/BaseDriver.js +1 -1
- package/src/tools/mail/drivers/Mailgun.js +1 -1
- package/src/tools/mail/drivers/SendGrid.js +1 -1
- package/src/tools/mail/drivers/Ses.js +2 -2
- package/src/tools/mail/drivers/Smtp.js +4 -4
- package/src/tools/mail/templates/markdown/index.js +3 -3
- package/src/tools/mail/templates/markdown/registry.js +5 -5
- package/src/tools/mail/templates/markdown/validator.js +1 -1
- package/src/tools/mail/testing.js +1 -1
- package/src/tools/notification/Notification.js +1 -1
- package/src/tools/notification/Registry.js +3 -3
- package/src/tools/notification/Service.js +3 -3
- package/src/tools/notification/config.js +1 -1
- package/src/tools/notification/drivers/BaseDriver.js +1 -1
- package/src/tools/notification/drivers/Slack.js +1 -1
- package/src/tools/notification/drivers/Termii.js +1 -1
- package/src/tools/notification/drivers/Twilio.js +1 -1
- package/src/tools/notification/templates/markdown/index.js +3 -3
- package/src/tools/notification/templates/markdown/registry.js +5 -5
- package/src/tools/notification/testing.js +1 -1
- package/src/tools/notification/testingHelpers.js +2 -2
- package/src/tools/queue/Queue.js +1 -1
- package/src/tools/queue/drivers/InMemory.js +1 -1
- package/src/tools/queue/drivers/Redis.js +2 -2
- package/src/tools/storage/LocalSignedUrl.js +2 -2
- package/src/tools/storage/drivers/Gcs.js +1 -1
- package/src/tools/storage/drivers/Local.js +5 -5
- package/src/tools/storage/drivers/R2.js +2 -2
- package/src/tools/storage/drivers/S3.js +3 -3
- package/src/tools/storage/index.js +6 -6
- package/src/tools/storage/testing.js +1 -1
- package/src/tools/templates/MarkdownRenderer.js +2 -2
- package/src/tools/templates/index.js +1 -1
- package/src/validation/Validator.js +3 -3
package/src/common/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { ErrorFactory } from '../exceptions/ZintrustError';
|
|
2
|
-
import * as fs from '../node-singletons/fs';
|
|
3
|
-
import * as path from '../node-singletons/path';
|
|
4
|
-
import { fileURLToPath } from '../node-singletons/url';
|
|
5
|
-
export { AwsSigV4 } from './AwsSigV4';
|
|
1
|
+
import { ErrorFactory } from '../exceptions/ZintrustError.js';
|
|
2
|
+
import * as fs from '../node-singletons/fs.js';
|
|
3
|
+
import * as path from '../node-singletons/path.js';
|
|
4
|
+
import { fileURLToPath } from '../node-singletons/url.js';
|
|
5
|
+
export { AwsSigV4 } from './AwsSigV4.js';
|
|
6
6
|
// Mutable FileChecker used to abstract FS checks for easier testing/mocking
|
|
7
7
|
export const FileChecker = {
|
|
8
8
|
exists(filePath) {
|
package/src/common/uuid.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ErrorFactory } from '../exceptions/ZintrustError';
|
|
1
|
+
import { ErrorFactory } from '../exceptions/ZintrustError.js';
|
|
2
2
|
export const generateUuid = () => {
|
|
3
3
|
if (typeof globalThis?.crypto?.randomUUID === 'function')
|
|
4
4
|
return globalThis.crypto.randomUUID();
|
|
@@ -15,7 +15,7 @@ export async function generateSecureJobId(errMsg = 'Secure crypto API not availa
|
|
|
15
15
|
}
|
|
16
16
|
// Node fallback for environments without Web Crypto
|
|
17
17
|
try {
|
|
18
|
-
const nodeCrypto = await import('../node-singletons/crypto');
|
|
18
|
+
const nodeCrypto = await import('../node-singletons/crypto.js');
|
|
19
19
|
return nodeCrypto.randomBytes(16).toString('hex');
|
|
20
20
|
}
|
|
21
21
|
catch (error) {
|
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
* Provides best-effort file logging with daily + size-based rotation.
|
|
5
5
|
* This module imports Node built-ins and should be loaded only in Node environments.
|
|
6
6
|
*/
|
|
7
|
-
import { ensureDirSafe } from '../common/index';
|
|
8
|
-
import { Env } from './env';
|
|
9
|
-
import * as fs from '../node-singletons/fs';
|
|
10
|
-
import * as path from '../node-singletons/path';
|
|
7
|
+
import { ensureDirSafe } from '../common/index.js';
|
|
8
|
+
import { Env } from './env.js';
|
|
9
|
+
import * as fs from '../node-singletons/fs.js';
|
|
10
|
+
import * as path from '../node-singletons/path.js';
|
|
11
11
|
const getCwdSafe = () => {
|
|
12
12
|
try {
|
|
13
13
|
if (typeof process === 'undefined' || typeof process.cwd !== 'function')
|
|
@@ -3,39 +3,7 @@
|
|
|
3
3
|
* Abstracts secrets retrieval across different cloud platforms
|
|
4
4
|
* Supports: AWS Secrets Manager, Parameter Store, Cloudflare KV, Deno env
|
|
5
5
|
*/
|
|
6
|
-
|
|
7
|
-
get(key: string): Promise<string | null>;
|
|
8
|
-
put(key: string, value: string, options?: {
|
|
9
|
-
expirationTtl?: number;
|
|
10
|
-
}): Promise<void>;
|
|
11
|
-
delete(key: string): Promise<void>;
|
|
12
|
-
list(options?: {
|
|
13
|
-
prefix?: string;
|
|
14
|
-
}): Promise<{
|
|
15
|
-
keys: {
|
|
16
|
-
name: string;
|
|
17
|
-
}[];
|
|
18
|
-
}>;
|
|
19
|
-
}
|
|
20
|
-
export interface SecretConfig {
|
|
21
|
-
platform: 'aws' | 'cloudflare' | 'deno' | 'local';
|
|
22
|
-
region?: string;
|
|
23
|
-
kv?: CloudflareKV;
|
|
24
|
-
}
|
|
25
|
-
export interface SecretValue {
|
|
26
|
-
key: string;
|
|
27
|
-
value: string;
|
|
28
|
-
expiresAt?: number;
|
|
29
|
-
rotationEnabled?: boolean;
|
|
30
|
-
}
|
|
31
|
-
interface SecretsManagerInstance {
|
|
32
|
-
getSecret(key: string, options?: GetSecretOptions): Promise<string>;
|
|
33
|
-
setSecret(key: string, value: string, options?: SetSecretOptions): Promise<void>;
|
|
34
|
-
deleteSecret(key: string): Promise<void>;
|
|
35
|
-
rotateSecret(key: string): Promise<void>;
|
|
36
|
-
listSecrets(pattern?: string): Promise<string[]>;
|
|
37
|
-
clearCache(key?: string): void;
|
|
38
|
-
}
|
|
6
|
+
import type { GetSecretOptions, SecretConfig, SecretsManagerInstance, SetSecretOptions } from './type';
|
|
39
7
|
/**
|
|
40
8
|
* SecretsManager - Unified interface for retrieving secrets
|
|
41
9
|
* Sealed namespace for immutability
|
|
@@ -91,14 +59,6 @@ export declare const SECRETS: Readonly<{
|
|
|
91
59
|
readonly SESSION_SECRET: "session/secret";
|
|
92
60
|
readonly CSRF_SECRET: "csrf/secret";
|
|
93
61
|
}>;
|
|
94
|
-
export interface GetSecretOptions {
|
|
95
|
-
cacheTtl?: number;
|
|
96
|
-
throwIfMissing?: boolean;
|
|
97
|
-
}
|
|
98
|
-
export interface SetSecretOptions {
|
|
99
|
-
expirationTtl?: number;
|
|
100
|
-
metadata?: Record<string, unknown>;
|
|
101
|
-
}
|
|
102
62
|
/**
|
|
103
63
|
* Helper to get database credentials using secrets manager
|
|
104
64
|
*/
|
|
@@ -118,5 +78,4 @@ export interface JwtSecrets {
|
|
|
118
78
|
secret: string;
|
|
119
79
|
refreshSecret: string;
|
|
120
80
|
}
|
|
121
|
-
export {};
|
|
122
81
|
//# sourceMappingURL=SecretsManager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SecretsManager.d.ts","sourceRoot":"","sources":["../../../src/config/SecretsManager.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"SecretsManager.d.ts","sourceRoot":"","sources":["../../../src/config/SecretsManager.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EACV,gBAAgB,EAChB,YAAY,EACZ,sBAAsB,EACtB,gBAAgB,EACjB,MAAM,cAAc,CAAC;AAiTtB;;;GAGG;AACH,eAAO,MAAM,cAAc;IACzB;;OAEG;yBACkB,YAAY,GAAG,sBAAsB;IAY1D;;OAEG;mBACkB,MAAM,YAAY,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC;IAIzE;;OAEG;mBACkB,MAAM,SAAS,MAAM,YAAY,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;IAItF;;OAEG;sBACqB,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI9C;;OAEG;sBACqB,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI9C;;OAEG;0BACyB,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAItD;;OAEG;qBACc,MAAM,GAAG,IAAI;EAG9B,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;EA0BT,CAAC;AAEZ;;GAEG;AACH,wBAAsB,sBAAsB,IAAI,OAAO,CAAC,mBAAmB,CAAC,CAU3E;AAED;;GAEG;AACH,wBAAsB,aAAa,IAAI,OAAO,CAAC,UAAU,CAAC,CAOzD;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,MAAM,CAAC;CACvB"}
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* Abstracts secrets retrieval across different cloud platforms
|
|
4
4
|
* Supports: AWS Secrets Manager, Parameter Store, Cloudflare KV, Deno env
|
|
5
5
|
*/
|
|
6
|
-
import { Logger } from './logger';
|
|
7
|
-
import { ErrorFactory } from '../exceptions/ZintrustError';
|
|
6
|
+
import { Logger } from './logger.js';
|
|
7
|
+
import { ErrorFactory } from '../exceptions/ZintrustError.js';
|
|
8
8
|
let instance;
|
|
9
9
|
function pruneCache(cache, maxEntries) {
|
|
10
10
|
if (cache.size <= maxEntries)
|
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
key: string;
|
|
3
|
-
value: unknown;
|
|
4
|
-
message: string;
|
|
5
|
-
};
|
|
6
|
-
export type StartupConfigValidationResult = {
|
|
7
|
-
valid: boolean;
|
|
8
|
-
errors: StartupConfigValidationError[];
|
|
9
|
-
};
|
|
1
|
+
import type { StartupConfigValidationResult } from './type';
|
|
10
2
|
export declare const StartupConfigValidator: Readonly<{
|
|
11
3
|
validate(): StartupConfigValidationResult;
|
|
12
4
|
assertValid(): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StartupConfigValidator.d.ts","sourceRoot":"","sources":["../../../src/config/StartupConfigValidator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"StartupConfigValidator.d.ts","sourceRoot":"","sources":["../../../src/config/StartupConfigValidator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAgC,6BAA6B,EAAE,MAAM,cAAc,CAAC;AAiPhG,eAAO,MAAM,sBAAsB;gBACrB,6BAA6B;mBAc1B,IAAI;EAQnB,CAAC;AAEH,eAAe,sBAAsB,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { appConfig } from './app';
|
|
2
|
-
import { ErrorFactory } from '../exceptions/ZintrustError';
|
|
1
|
+
import { appConfig } from './app.js';
|
|
2
|
+
import { ErrorFactory } from '../exceptions/ZintrustError.js';
|
|
3
3
|
const isSensitiveKey = (key) => {
|
|
4
4
|
const normalized = key.toLowerCase();
|
|
5
5
|
return (normalized.includes('password') ||
|
|
@@ -45,33 +45,126 @@ const getEnvString = (key, defaultValue) => {
|
|
|
45
45
|
const env = proc?.env ?? {};
|
|
46
46
|
return env[key] ?? defaultValue;
|
|
47
47
|
};
|
|
48
|
+
const getEnvOptionalString = (key) => {
|
|
49
|
+
const proc = getProcessLike();
|
|
50
|
+
const env = proc?.env ?? {};
|
|
51
|
+
const value = env[key];
|
|
52
|
+
if (typeof value !== 'string')
|
|
53
|
+
return undefined;
|
|
54
|
+
const trimmed = value.trim();
|
|
55
|
+
return trimmed === '' ? undefined : trimmed;
|
|
56
|
+
};
|
|
57
|
+
const getEnvBoolLoose = (key, defaultValue) => {
|
|
58
|
+
const raw = getEnvOptionalString(key);
|
|
59
|
+
if (raw === undefined)
|
|
60
|
+
return defaultValue;
|
|
61
|
+
const normalized = raw.toLowerCase();
|
|
62
|
+
return normalized === 'true' || normalized === '1' || normalized === 'yes' || normalized === 'on';
|
|
63
|
+
};
|
|
48
64
|
const getEnvInt = (key, defaultValue) => {
|
|
49
65
|
const raw = getEnvString(key, String(defaultValue));
|
|
50
66
|
return Number.parseInt(raw, 10);
|
|
51
67
|
};
|
|
68
|
+
const requireEnvString = (errors, key, options = {}) => {
|
|
69
|
+
const value = getEnvOptionalString(key) ??
|
|
70
|
+
(options.aliases ?? []).reduce((found, alias) => {
|
|
71
|
+
if (found !== undefined)
|
|
72
|
+
return found;
|
|
73
|
+
return getEnvOptionalString(alias);
|
|
74
|
+
}, undefined);
|
|
75
|
+
if (value === undefined) {
|
|
76
|
+
pushError(errors, key, value, options.requiredMessage ?? `${key} is required`);
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
if (options.minLength !== undefined && value.length < options.minLength) {
|
|
80
|
+
pushError(errors, key, value, options.minLengthMessage ?? `${key} must be at least ${options.minLength} characters`);
|
|
81
|
+
}
|
|
82
|
+
return value;
|
|
83
|
+
};
|
|
84
|
+
const validateSqliteDbFileRequired = (errors, dbConnection) => {
|
|
85
|
+
// sqlite convenience: accept DB_DATABASE or DB_PATH
|
|
86
|
+
if ((dbConnection ?? '').toLowerCase() !== 'sqlite')
|
|
87
|
+
return;
|
|
88
|
+
const dbFile = getEnvOptionalString('DB_DATABASE') ?? getEnvOptionalString('DB_PATH');
|
|
89
|
+
if (dbFile === undefined) {
|
|
90
|
+
pushError(errors, 'DB_DATABASE', dbFile, 'DB_DATABASE (or DB_PATH) is required for sqlite');
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
const validateStrictRequiredEnv = (errors) => {
|
|
94
|
+
const requireEnv = getEnvBoolLoose('STARTUP_REQUIRE_ENV', false);
|
|
95
|
+
if (!requireEnv)
|
|
96
|
+
return;
|
|
97
|
+
requireEnvString(errors, 'NODE_ENV');
|
|
98
|
+
requireEnvString(errors, 'APP_NAME');
|
|
99
|
+
requireEnvString(errors, 'HOST');
|
|
100
|
+
const portRaw = requireEnvString(errors, 'PORT', {
|
|
101
|
+
aliases: ['APP_PORT'],
|
|
102
|
+
requiredMessage: 'PORT (or APP_PORT) is required',
|
|
103
|
+
});
|
|
104
|
+
if (portRaw !== undefined) {
|
|
105
|
+
const port = Number.parseInt(portRaw, 10);
|
|
106
|
+
validateIntRange(errors, 'PORT', port, 1, 65535);
|
|
107
|
+
}
|
|
108
|
+
const dbConnection = requireEnvString(errors, 'DB_CONNECTION');
|
|
109
|
+
requireEnvString(errors, 'APP_KEY', { minLength: 16 });
|
|
110
|
+
requireEnvString(errors, 'LOG_LEVEL');
|
|
111
|
+
requireEnvString(errors, 'LOG_CHANNEL');
|
|
112
|
+
validateSqliteDbFileRequired(errors, dbConnection);
|
|
113
|
+
};
|
|
114
|
+
const validateNodeEnv = (errors) => {
|
|
115
|
+
const nodeEnv = getEnvString('NODE_ENV', 'development');
|
|
116
|
+
validateEnum(errors, 'NODE_ENV', nodeEnv, ['development', 'production', 'testing', 'test']);
|
|
117
|
+
};
|
|
118
|
+
const validatePort = (errors) => {
|
|
119
|
+
// Port can be provided as PORT or APP_PORT. In non-strict mode we keep defaults.
|
|
120
|
+
const portFromPort = getEnvOptionalString('PORT');
|
|
121
|
+
const portFromAppPort = getEnvOptionalString('APP_PORT');
|
|
122
|
+
const portRaw = portFromPort ?? portFromAppPort;
|
|
123
|
+
if (portRaw === undefined) {
|
|
124
|
+
const appPort = getEnvInt('APP_PORT', 3000);
|
|
125
|
+
validateIntRange(errors, 'APP_PORT', appPort, 1, 65535);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
const parsed = Number.parseInt(portRaw, 10);
|
|
129
|
+
const key = portFromPort === undefined ? 'APP_PORT' : 'PORT';
|
|
130
|
+
validateIntRange(errors, key, parsed, 1, 65535);
|
|
131
|
+
};
|
|
132
|
+
const validateLogging = (errors) => {
|
|
133
|
+
const logFormat = getEnvString('LOG_FORMAT', 'text');
|
|
134
|
+
validateEnum(errors, 'LOG_FORMAT', logFormat, ['text', 'json']);
|
|
135
|
+
const logLevel = getEnvString('LOG_LEVEL', 'debug');
|
|
136
|
+
validateEnum(errors, 'LOG_LEVEL', logLevel, ['debug', 'info', 'warn', 'error']);
|
|
137
|
+
// Optional (but validated when provided): LOG_CHANNEL (starter apps often use this)
|
|
138
|
+
const logChannel = getEnvOptionalString('LOG_CHANNEL');
|
|
139
|
+
if (logChannel !== undefined) {
|
|
140
|
+
validateEnum(errors, 'LOG_CHANNEL', logChannel, ['console', 'file', 'all']);
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
const validateRotationAndTimeout = (errors) => {
|
|
144
|
+
const logRotationSize = getEnvInt('LOG_ROTATION_SIZE', 10485760);
|
|
145
|
+
validatePositiveInt(errors, 'LOG_ROTATION_SIZE', logRotationSize);
|
|
146
|
+
const logRotationDays = getEnvInt('LOG_ROTATION_DAYS', 7);
|
|
147
|
+
validatePositiveInt(errors, 'LOG_ROTATION_DAYS', logRotationDays);
|
|
148
|
+
const startupHealthTimeoutMs = getEnvInt('STARTUP_HEALTH_TIMEOUT_MS', 2500);
|
|
149
|
+
validatePositiveInt(errors, 'STARTUP_HEALTH_TIMEOUT_MS', startupHealthTimeoutMs);
|
|
150
|
+
};
|
|
151
|
+
const validateProductionAppKey = (errors) => {
|
|
152
|
+
if (!appConfig.isProduction())
|
|
153
|
+
return;
|
|
154
|
+
const appKey = getEnvString('APP_KEY', '');
|
|
155
|
+
if (appKey.trim().length < 16) {
|
|
156
|
+
pushError(errors, 'APP_KEY', appKey, 'APP_KEY must be set and at least 16 characters in production');
|
|
157
|
+
}
|
|
158
|
+
};
|
|
52
159
|
export const StartupConfigValidator = Object.freeze({
|
|
53
160
|
validate() {
|
|
54
161
|
const errors = [];
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const logLevel = getEnvString('LOG_LEVEL', 'debug');
|
|
62
|
-
validateEnum(errors, 'LOG_LEVEL', logLevel, ['debug', 'info', 'warn', 'error']);
|
|
63
|
-
const logRotationSize = getEnvInt('LOG_ROTATION_SIZE', 10485760);
|
|
64
|
-
validatePositiveInt(errors, 'LOG_ROTATION_SIZE', logRotationSize);
|
|
65
|
-
const logRotationDays = getEnvInt('LOG_ROTATION_DAYS', 7);
|
|
66
|
-
validatePositiveInt(errors, 'LOG_ROTATION_DAYS', logRotationDays);
|
|
67
|
-
const startupHealthTimeoutMs = getEnvInt('STARTUP_HEALTH_TIMEOUT_MS', 2500);
|
|
68
|
-
validatePositiveInt(errors, 'STARTUP_HEALTH_TIMEOUT_MS', startupHealthTimeoutMs);
|
|
69
|
-
if (appConfig.isProduction()) {
|
|
70
|
-
const appKey = getEnvString('APP_KEY', '');
|
|
71
|
-
if (appKey.trim().length < 16) {
|
|
72
|
-
pushError(errors, 'APP_KEY', appKey, 'APP_KEY must be set and at least 16 characters in production');
|
|
73
|
-
}
|
|
74
|
-
}
|
|
162
|
+
validateStrictRequiredEnv(errors);
|
|
163
|
+
validateNodeEnv(errors);
|
|
164
|
+
validatePort(errors);
|
|
165
|
+
validateLogging(errors);
|
|
166
|
+
validateRotationAndTimeout(errors);
|
|
167
|
+
validateProductionAppKey(errors);
|
|
75
168
|
return { valid: errors.length === 0, errors };
|
|
76
169
|
},
|
|
77
170
|
assertValid() {
|
package/src/config/app.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Core application settings
|
|
4
4
|
* Sealed namespace for immutability
|
|
5
5
|
*/
|
|
6
|
-
type StartMode
|
|
6
|
+
import type { StartMode } from './type';
|
|
7
7
|
declare const getSafeEnv: () => NodeJS.ProcessEnv;
|
|
8
8
|
export declare const appConfig: Readonly<{
|
|
9
9
|
/**
|
package/src/config/app.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../../../src/config/app.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../../../src/config/app.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAA4B,SAAS,EAAE,MAAM,cAAc,CAAC;AAsCxE,QAAA,MAAM,UAAU,QAAO,MAAM,CAAC,UAuB7B,CAAC;AA0FF,eAAO,MAAM,SAAS;IA5EpB;;OAEG;;IAMH;;OAEG;;IAGH;;OAEG;;IAMH;;OAEG;;IAMH;;OAEG;kCACc,OAAO;IAIxB;;OAEG;iCACa,OAAO;IAIvB;;OAEG;8BACU,OAAO;IAIpB;;OAEG;;IAMH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;+BA3GkB,MAAM,CAAC,UAAU;EAiHY,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,CAAC;AAEtB,MAAM,MAAM,SAAS,GAAG,OAAO,SAAS,CAAC"}
|
package/src/config/app.js
CHANGED
|
@@ -4,32 +4,7 @@
|
|
|
4
4
|
* Centralizes broadcast driver selection and provider env mappings.
|
|
5
5
|
* Driver selection must be dynamic (tests may mutate process.env).
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
|
-
export type InMemoryBroadcastDriverConfig = {
|
|
9
|
-
driver: 'inmemory';
|
|
10
|
-
};
|
|
11
|
-
export type PusherBroadcastDriverConfig = {
|
|
12
|
-
driver: 'pusher';
|
|
13
|
-
appId: string;
|
|
14
|
-
key: string;
|
|
15
|
-
secret: string;
|
|
16
|
-
cluster: string;
|
|
17
|
-
useTLS: boolean;
|
|
18
|
-
};
|
|
19
|
-
export type RedisBroadcastDriverConfig = {
|
|
20
|
-
driver: 'redis';
|
|
21
|
-
host: string;
|
|
22
|
-
port: number;
|
|
23
|
-
password: string;
|
|
24
|
-
channelPrefix: string;
|
|
25
|
-
};
|
|
26
|
-
export type RedisHttpsBroadcastDriverConfig = {
|
|
27
|
-
driver: 'redishttps';
|
|
28
|
-
endpoint: string;
|
|
29
|
-
token: string;
|
|
30
|
-
channelPrefix: string;
|
|
31
|
-
};
|
|
32
|
-
export type KnownBroadcastDriverConfig = InMemoryBroadcastDriverConfig | PusherBroadcastDriverConfig | RedisBroadcastDriverConfig | RedisHttpsBroadcastDriverConfig;
|
|
7
|
+
import { KnownBroadcastDriverConfig } from './type';
|
|
33
8
|
declare const _default: Readonly<{
|
|
34
9
|
/**
|
|
35
10
|
* Normalized broadcast driver name.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"broadcast.d.ts","sourceRoot":"","sources":["../../../src/config/broadcast.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"broadcast.d.ts","sourceRoot":"","sources":["../../../src/config/broadcast.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EACL,0BAA0B,EAI3B,MAAM,cAAc,CAAC;;IA6BpB;;;;OAIG;kCACc,MAAM;IAIvB;;;OAGG;oCACgB,0BAA0B;;AAW/C,wBAAiD"}
|
package/src/config/broadcast.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Centralizes broadcast driver selection and provider env mappings.
|
|
5
5
|
* Driver selection must be dynamic (tests may mutate process.env).
|
|
6
6
|
*/
|
|
7
|
-
import { Env } from './env';
|
|
7
|
+
import { Env } from './env.js';
|
|
8
8
|
const normalizeDriverName = (value) => value.trim().toLowerCase();
|
|
9
9
|
const getPusherConfig = () => ({
|
|
10
10
|
driver: 'pusher',
|
package/src/config/cache.d.ts
CHANGED
|
@@ -3,27 +3,7 @@
|
|
|
3
3
|
* Caching drivers and settings
|
|
4
4
|
* Sealed namespace for immutability
|
|
5
5
|
*/
|
|
6
|
-
|
|
7
|
-
driver: 'memory';
|
|
8
|
-
ttl: number;
|
|
9
|
-
};
|
|
10
|
-
type RedisCacheDriverConfig = {
|
|
11
|
-
driver: 'redis';
|
|
12
|
-
host: string;
|
|
13
|
-
port: number;
|
|
14
|
-
ttl: number;
|
|
15
|
-
};
|
|
16
|
-
type MongoCacheDriverConfig = {
|
|
17
|
-
driver: 'mongodb';
|
|
18
|
-
uri: string;
|
|
19
|
-
db: string;
|
|
20
|
-
ttl: number;
|
|
21
|
-
};
|
|
22
|
-
type KvCacheDriverConfig = {
|
|
23
|
-
driver: 'kv';
|
|
24
|
-
ttl: number;
|
|
25
|
-
};
|
|
26
|
-
type CacheDriverConfig = MemoryCacheDriverConfig | RedisCacheDriverConfig | MongoCacheDriverConfig | KvCacheDriverConfig;
|
|
6
|
+
import { CacheDriverConfig } from './type';
|
|
27
7
|
export declare const cacheConfig: Readonly<{
|
|
28
8
|
/**
|
|
29
9
|
* Default cache driver
|
|
@@ -68,5 +48,4 @@ export declare const cacheConfig: Readonly<{
|
|
|
68
48
|
ttl: number;
|
|
69
49
|
}>;
|
|
70
50
|
export type CacheConfig = typeof cacheConfig;
|
|
71
|
-
export {};
|
|
72
51
|
//# sourceMappingURL=cache.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../../src/config/cache.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../../src/config/cache.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAoB,iBAAiB,EAAgB,MAAM,cAAc,CAAC;AA+DjF,eAAO,MAAM,WAAW;IAjDtB;;OAEG;;IAGH;;OAEG;;;;;;;;;;;;;;;;;;;;;;;IAwBH;;OAEG;iBACU,iBAAiB;IAI9B;;OAEG;;IAGH;;OAEG;;EAImD,CAAC;AACzD,MAAM,MAAM,WAAW,GAAG,OAAO,WAAW,CAAC"}
|
package/src/config/cache.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Caching drivers and settings
|
|
4
4
|
* Sealed namespace for immutability
|
|
5
5
|
*/
|
|
6
|
-
import { Env } from './env';
|
|
6
|
+
import { Env } from './env.js';
|
|
7
7
|
const getCacheDriver = (config) => {
|
|
8
8
|
const defaultDriver = config.default;
|
|
9
9
|
if (Object.hasOwn(config.drivers, defaultDriver)) {
|
|
@@ -4,23 +4,11 @@
|
|
|
4
4
|
* Centralizes access to Workers bindings via globalThis.env.
|
|
5
5
|
* This keeps runtime-specific globals out of adapters/drivers.
|
|
6
6
|
*/
|
|
7
|
+
import { KVNamespace, WorkersEnv } from './type';
|
|
7
8
|
import type { DatabaseConfig, ID1Database } from '../orm/DatabaseAdapter';
|
|
8
|
-
export type WorkersEnv = Record<string, unknown>;
|
|
9
|
-
type KVNamespace = {
|
|
10
|
-
get(key: string, options?: {
|
|
11
|
-
type: 'text' | 'json' | 'arrayBuffer' | 'stream';
|
|
12
|
-
}): Promise<unknown>;
|
|
13
|
-
put(key: string, value: string | ReadableStream | ArrayBuffer | FormData, options?: {
|
|
14
|
-
expiration?: number;
|
|
15
|
-
expirationTtl?: number;
|
|
16
|
-
metadata?: unknown;
|
|
17
|
-
}): Promise<void>;
|
|
18
|
-
delete(key: string): Promise<void>;
|
|
19
|
-
};
|
|
20
9
|
export declare const Cloudflare: Readonly<{
|
|
21
10
|
getWorkersEnv: () => WorkersEnv | null;
|
|
22
11
|
getD1Binding: (config: DatabaseConfig) => ID1Database | null;
|
|
23
12
|
getKVBinding: (bindingName?: string) => KVNamespace | null;
|
|
24
13
|
}>;
|
|
25
|
-
export {};
|
|
26
14
|
//# sourceMappingURL=cloudflare.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cloudflare.d.ts","sourceRoot":"","sources":["../../../src/config/cloudflare.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"cloudflare.d.ts","sourceRoot":"","sources":["../../../src/config/cloudflare.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AA8BxE,eAAO,MAAM,UAAU;yBA5BG,UAAU,GAAG,IAAI;2BAOb,cAAc,KAAG,WAAW,GAAG,IAAI;4CAanB,WAAW,GAAG,IAAI;EAY9D,CAAC"}
|
package/src/config/database.d.ts
CHANGED
|
@@ -3,56 +3,12 @@
|
|
|
3
3
|
* Database connections and pooling settings
|
|
4
4
|
* Sealed namespace for immutability
|
|
5
5
|
*/
|
|
6
|
-
|
|
7
|
-
driver: 'sqlite';
|
|
8
|
-
database: string;
|
|
9
|
-
migrations: string;
|
|
10
|
-
};
|
|
11
|
-
type PostgresqlConnectionConfig = {
|
|
12
|
-
driver: 'postgresql';
|
|
13
|
-
host: string;
|
|
14
|
-
port: number;
|
|
15
|
-
database: string;
|
|
16
|
-
username: string;
|
|
17
|
-
password: string;
|
|
18
|
-
ssl: boolean;
|
|
19
|
-
pooling: {
|
|
20
|
-
enabled: boolean;
|
|
21
|
-
min: number;
|
|
22
|
-
max: number;
|
|
23
|
-
idleTimeout: number;
|
|
24
|
-
connectionTimeout: number;
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
type MysqlConnectionConfig = {
|
|
28
|
-
driver: 'mysql';
|
|
29
|
-
host: string;
|
|
30
|
-
port: number;
|
|
31
|
-
database: string;
|
|
32
|
-
username: string;
|
|
33
|
-
password: string;
|
|
34
|
-
pooling: {
|
|
35
|
-
enabled: boolean;
|
|
36
|
-
min: number;
|
|
37
|
-
max: number;
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
type DatabaseConnections = {
|
|
41
|
-
sqlite: SqliteConnectionConfig;
|
|
42
|
-
postgresql: PostgresqlConnectionConfig;
|
|
43
|
-
mysql: MysqlConnectionConfig;
|
|
44
|
-
};
|
|
45
|
-
type DatabaseConnectionName = keyof DatabaseConnections;
|
|
46
|
-
type DatabaseConnectionConfig = DatabaseConnections[DatabaseConnectionName];
|
|
47
|
-
type DatabaseConfigShape = {
|
|
48
|
-
default: DatabaseConnectionName;
|
|
49
|
-
connections: DatabaseConnections;
|
|
50
|
-
};
|
|
6
|
+
import { DatabaseConfigShape, DatabaseConnectionConfig } from './type';
|
|
51
7
|
export declare const databaseConfig: Readonly<{
|
|
52
8
|
/**
|
|
53
9
|
* Default database connection
|
|
54
10
|
*/
|
|
55
|
-
default: keyof DatabaseConnections;
|
|
11
|
+
default: keyof import("./type").DatabaseConnections;
|
|
56
12
|
/**
|
|
57
13
|
* Database connections
|
|
58
14
|
*/
|
|
@@ -118,5 +74,4 @@ export declare const databaseConfig: Readonly<{
|
|
|
118
74
|
};
|
|
119
75
|
}>;
|
|
120
76
|
export type DatabaseConfig = typeof databaseConfig;
|
|
121
|
-
export {};
|
|
122
77
|
//# sourceMappingURL=database.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../../src/config/database.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../../src/config/database.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EACL,mBAAmB,EACnB,wBAAwB,EAEzB,MAAM,cAAc,CAAC;AA6FtB,eAAO,MAAM,cAAc;IA5EzB;;OAEG;;IAGH;;OAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAsCH;;OAEG;wBACiB,mBAAmB,GAAG,wBAAwB;IAIlE;;OAEG;;;;;IAMH;;OAEG;;;;;IAMH;;OAEG;;;;EAMyD,CAAC;AAC/D,MAAM,MAAM,cAAc,GAAG,OAAO,cAAc,CAAC"}
|
package/src/config/database.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Database connections and pooling settings
|
|
4
4
|
* Sealed namespace for immutability
|
|
5
5
|
*/
|
|
6
|
-
import { Env } from './env';
|
|
6
|
+
import { Env } from './env.js';
|
|
7
7
|
const isDatabaseConnectionName = (value) => {
|
|
8
8
|
return value === 'sqlite' || value === 'postgresql' || value === 'mysql';
|
|
9
9
|
};
|
package/src/config/env.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../../src/config/env.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;
|
|
1
|
+
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../../src/config/env.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AA+CH,eAAO,MAAM,GAAG;eA/BE,MAAM,iBAAiB,MAAM,KAAG,MAAM;kBAMnC,MAAM,iBAAiB,MAAM,KAAG,MAAM;mBASrC,MAAM,iBAAiB,OAAO,KAAG,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;eAiFP,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO;;;;;;;;;EAkCxF,CAAC"}
|
package/src/config/env.js
CHANGED
|
@@ -27,6 +27,8 @@ const getInt = (key, defaultValue) => {
|
|
|
27
27
|
const value = env[key];
|
|
28
28
|
if (value === undefined || value === null)
|
|
29
29
|
return defaultValue ?? 0;
|
|
30
|
+
if (typeof value === 'string' && value.trim() === '')
|
|
31
|
+
return defaultValue ?? 0;
|
|
30
32
|
return Number.parseInt(value, 10);
|
|
31
33
|
};
|
|
32
34
|
const getBool = (key, defaultValue) => {
|
|
@@ -53,7 +55,8 @@ export const Env = Object.freeze({
|
|
|
53
55
|
getBool,
|
|
54
56
|
// Core
|
|
55
57
|
NODE_ENV: get('NODE_ENV', 'development'),
|
|
56
|
-
PORT
|
|
58
|
+
// Prefer PORT, fallback to APP_PORT for compatibility
|
|
59
|
+
PORT: getInt('PORT', getInt('APP_PORT', 3000)),
|
|
57
60
|
HOST: get('HOST', 'localhost'),
|
|
58
61
|
APP_NAME: get('APP_NAME', 'ZinTrust'),
|
|
59
62
|
APP_KEY: get('APP_KEY', ''),
|
|
@@ -61,7 +64,8 @@ export const Env = Object.freeze({
|
|
|
61
64
|
DB_CONNECTION: get('DB_CONNECTION', 'sqlite'),
|
|
62
65
|
DB_HOST: get('DB_HOST', 'localhost'),
|
|
63
66
|
DB_PORT: getInt('DB_PORT', 5432),
|
|
64
|
-
|
|
67
|
+
// Accept DB_PATH as an alias for sqlite file path (many env templates use it).
|
|
68
|
+
DB_DATABASE: get('DB_DATABASE', get('DB_PATH', 'zintrust')),
|
|
65
69
|
DB_USERNAME: get('DB_USERNAME', 'postgres'),
|
|
66
70
|
DB_PASSWORD: get('DB_PASSWORD', ''),
|
|
67
71
|
DB_READ_HOSTS: get('DB_READ_HOSTS', ''),
|
package/src/config/features.js
CHANGED