@zintrust/core 0.1.21 → 0.1.23
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 +1 -1
- package/bin/z.js +1 -1
- package/bin/zin.d.ts +1 -1
- package/bin/zin.js +1 -1
- package/bin/zintrust-main.d.ts +1 -1
- package/bin/zintrust-main.js +2 -2
- package/bin/zintrust-microservices.d.ts +1 -1
- package/bin/zintrust-microservices.js +1 -1
- package/bin/zintrust.d.ts +1 -1
- package/bin/zintrust.js +1 -1
- package/bin/zt.d.ts +1 -1
- package/bin/zt.js +1 -1
- package/package.json +2 -3
- package/public/index.html +3 -3
- package/routes/api.js +1 -1
- package/routes/health.d.ts +3 -4
- package/routes/health.d.ts.map +1 -1
- package/routes/health.js +3 -125
- package/src/boot/Application.d.ts.map +1 -1
- package/src/boot/Application.js +11 -22
- package/src/boot/bootstrap.d.ts +1 -1
- package/src/boot/bootstrap.js +48 -7
- package/src/builder/BundleOptimizer.d.ts +1 -1
- package/src/builder/BundleOptimizer.js +1 -1
- package/src/cache/drivers/KVRemoteDriver.d.ts +1 -1
- package/src/cache/drivers/KVRemoteDriver.js +1 -1
- package/src/cli/CLI.d.ts.map +1 -1
- package/src/cli/CLI.js +15 -1
- package/src/cli/ErrorHandler.js +3 -3
- package/src/cli/commands/AddCommand.d.ts +1 -1
- package/src/cli/commands/AddCommand.d.ts.map +1 -1
- package/src/cli/commands/AddCommand.js +1 -1
- package/src/cli/commands/DbSeedCommand.js +1 -1
- package/src/cli/commands/MakeMailTemplateCommand.js +2 -1
- package/src/cli/commands/MakeNotificationTemplateCommand.js +2 -1
- package/src/cli/commands/MigrateCommand.d.ts.map +1 -1
- package/src/cli/commands/MigrateCommand.js +1 -1
- package/src/cli/commands/MigrateWorkerCommand.d.ts +9 -0
- package/src/cli/commands/MigrateWorkerCommand.d.ts.map +1 -0
- package/src/cli/commands/MigrateWorkerCommand.js +182 -0
- package/src/cli/commands/NewCommand.d.ts +1 -1
- package/src/cli/commands/NewCommand.d.ts.map +1 -1
- package/src/cli/commands/NewCommand.js +21 -7
- package/src/cli/commands/PublishCommand.d.ts +5 -0
- package/src/cli/commands/PublishCommand.d.ts.map +1 -0
- package/src/cli/commands/PublishCommand.js +54 -0
- package/src/cli/commands/QACommand.js +4 -4
- package/src/cli/commands/ResourceControlCommand.d.ts +6 -0
- package/src/cli/commands/ResourceControlCommand.d.ts.map +1 -0
- package/src/cli/commands/ResourceControlCommand.js +43 -0
- package/src/cli/commands/SimulateCommand.d.ts +1 -1
- package/src/cli/commands/SimulateCommand.js +4 -4
- package/src/cli/commands/StartCommand.d.ts.map +1 -1
- package/src/cli/commands/StartCommand.js +19 -7
- package/src/cli/commands/UpgradeCommand.d.ts +1 -1
- package/src/cli/commands/UpgradeCommand.js +2 -2
- package/src/cli/commands/WorkerCommands.d.ts +17 -0
- package/src/cli/commands/WorkerCommands.d.ts.map +1 -0
- package/src/cli/commands/WorkerCommands.js +264 -0
- package/src/cli/commands/index.d.ts +2 -0
- package/src/cli/commands/index.d.ts.map +1 -1
- package/src/cli/commands/index.js +2 -0
- package/src/cli/config/ConfigSchema.d.ts +1 -1
- package/src/cli/config/ConfigSchema.d.ts.map +1 -1
- package/src/cli/config/ConfigSchema.js +4 -3
- package/src/cli/d1/D1SqlMigrations.d.ts.map +1 -1
- package/src/cli/d1/D1SqlMigrations.js +4 -3
- package/src/cli/scaffolding/ModelGenerator.d.ts +1 -1
- package/src/cli/scaffolding/ModelGenerator.d.ts.map +1 -1
- package/src/cli/scaffolding/ModelGenerator.js +10 -2
- package/src/cli/scaffolding/ProjectScaffolder.js +5 -5
- package/src/cli/scaffolding/RouteGenerator.d.ts.map +1 -1
- package/src/cli/scaffolding/RouteGenerator.js +21 -2
- package/src/cli/scaffolding/TemplateEngine.js +1 -1
- package/src/cli/utils/EnvFileLoader.d.ts.map +1 -1
- package/src/common/ExternalServiceUtils.d.ts +63 -0
- package/src/common/ExternalServiceUtils.d.ts.map +1 -0
- package/src/common/ExternalServiceUtils.js +116 -0
- package/src/common/HealthRoutes.d.ts +10 -0
- package/src/common/HealthRoutes.d.ts.map +1 -0
- package/src/common/HealthRoutes.js +114 -0
- package/src/config/SecretsManager.d.ts.map +1 -1
- package/src/config/SecretsManager.js +2 -1
- package/src/config/app.d.ts +2 -1
- package/src/config/app.d.ts.map +1 -1
- package/src/config/app.js +98 -52
- package/src/config/broadcast.d.ts.map +1 -1
- package/src/config/broadcast.js +2 -2
- package/src/config/cache.d.ts.map +1 -1
- package/src/config/cache.js +2 -2
- package/src/config/database.d.ts.map +1 -1
- package/src/config/database.js +24 -5
- package/src/config/env.d.ts +43 -1
- package/src/config/env.d.ts.map +1 -1
- package/src/config/env.js +68 -21
- package/src/config/index.d.ts +10 -1
- package/src/config/index.d.ts.map +1 -1
- package/src/config/index.js +1 -0
- package/src/config/mail.d.ts.map +1 -1
- package/src/config/mail.js +3 -3
- package/src/config/middleware.d.ts.map +1 -1
- package/src/config/middleware.js +1 -1
- package/src/config/notification.d.ts.map +1 -1
- package/src/config/notification.js +2 -2
- package/src/config/queue.d.ts +14 -0
- package/src/config/queue.d.ts.map +1 -1
- package/src/config/queue.js +61 -36
- package/src/config/security.js +2 -2
- package/src/config/storage.d.ts.map +1 -1
- package/src/config/storage.js +5 -5
- package/src/config/type.d.ts +122 -0
- package/src/config/type.d.ts.map +1 -1
- package/src/config/type.js +10 -1
- package/src/config/workers.d.ts +13 -0
- package/src/config/workers.d.ts.map +1 -0
- package/src/config/workers.js +173 -0
- package/src/database/Paginator.d.ts +37 -0
- package/src/database/Paginator.d.ts.map +1 -0
- package/src/database/Paginator.js +81 -0
- package/src/exceptions/ZintrustError.d.ts +5 -2
- package/src/exceptions/ZintrustError.d.ts.map +1 -1
- package/src/exceptions/ZintrustError.js +6 -2
- package/src/features/Auth.d.ts +1 -1
- package/src/features/Auth.d.ts.map +1 -1
- package/src/features/Auth.js +3 -2
- package/src/features/Queue.d.ts.map +1 -1
- package/src/features/Queue.js +0 -2
- package/src/index.d.ts +15 -5
- package/src/index.d.ts.map +1 -1
- package/src/index.js +24 -3
- package/src/microservices/MicroserviceBootstrap.d.ts.map +1 -1
- package/src/microservices/MicroserviceBootstrap.js +3 -1
- package/src/microservices/MicroserviceGenerator.js +4 -4
- package/src/microservices/MicroserviceManager.d.ts +1 -1
- package/src/microservices/MicroserviceManager.js +1 -1
- package/src/middleware/RateLimiter.d.ts.map +1 -1
- package/src/middleware/RateLimiter.js +4 -3
- package/src/migrations/MigrationLoader.d.ts +1 -1
- package/src/migrations/MigrationLoader.d.ts.map +1 -1
- package/src/migrations/Migrator.d.ts +3 -3
- package/src/migrations/Migrator.d.ts.map +1 -1
- package/src/migrations/Migrator.js +1 -1
- package/src/migrations/MigratorFactory.d.ts +1 -1
- package/src/migrations/MigratorFactory.d.ts.map +1 -1
- package/src/migrations/MigratorFactory.js +3 -3
- package/src/migrations/enum/index.d.ts +93 -0
- package/src/migrations/enum/index.d.ts.map +1 -0
- package/src/migrations/enum/index.js +92 -0
- package/src/migrations/schema/Blueprint.d.ts +1 -1
- package/src/migrations/schema/Blueprint.d.ts.map +1 -1
- package/src/migrations/schema/Blueprint.js +27 -25
- package/src/migrations/schema/Schema.d.ts +1 -1
- package/src/migrations/schema/Schema.d.ts.map +1 -1
- package/src/migrations/schema/Schema.js +4 -3
- package/src/migrations/schema/SchemaCompiler.d.ts +1 -1
- package/src/migrations/schema/SchemaCompiler.d.ts.map +1 -1
- package/src/migrations/schema/SchemaCompiler.js +99 -91
- package/src/migrations/schema/index.d.ts +4 -4
- package/src/migrations/schema/index.d.ts.map +1 -1
- package/src/migrations/schema/index.js +3 -3
- package/src/migrations/schema/types.d.ts +2 -1
- package/src/migrations/schema/types.d.ts.map +1 -1
- package/src/node-singletons/crypto.d.ts +1 -1
- package/src/node-singletons/crypto.d.ts.map +1 -1
- package/src/node-singletons/crypto.js +1 -1
- package/src/node-singletons/os.d.ts +10 -1
- package/src/node-singletons/os.d.ts.map +1 -1
- package/src/node-singletons/os.js +10 -1
- package/src/openapi/OpenApiGenerator.js +2 -2
- package/src/orm/ConnectionManager.d.ts +7 -5
- package/src/orm/ConnectionManager.d.ts.map +1 -1
- package/src/orm/ConnectionManager.js +249 -93
- package/src/orm/Database.d.ts +2 -1
- package/src/orm/Database.d.ts.map +1 -1
- package/src/orm/DatabaseAdapter.d.ts +3 -2
- package/src/orm/DatabaseAdapter.d.ts.map +1 -1
- package/src/orm/DatabaseAdapter.js +17 -0
- package/src/orm/Model.d.ts +8 -1
- package/src/orm/Model.d.ts.map +1 -1
- package/src/orm/Model.js +109 -26
- package/src/orm/QueryBuilder.d.ts +12 -2
- package/src/orm/QueryBuilder.d.ts.map +1 -1
- package/src/orm/QueryBuilder.js +438 -38
- package/src/orm/Relationships.d.ts +61 -1
- package/src/orm/Relationships.d.ts.map +1 -1
- package/src/orm/Relationships.js +190 -0
- package/src/orm/adapters/D1Adapter.d.ts.map +1 -1
- package/src/orm/adapters/D1Adapter.js +2 -1
- package/src/orm/adapters/D1RemoteAdapter.d.ts +1 -1
- package/src/orm/adapters/D1RemoteAdapter.d.ts.map +1 -1
- package/src/orm/adapters/D1RemoteAdapter.js +3 -2
- package/src/orm/adapters/MySQLAdapter.d.ts.map +1 -1
- package/src/orm/adapters/MySQLAdapter.js +2 -1
- package/src/orm/adapters/SQLServerAdapter.d.ts.map +1 -1
- package/src/orm/adapters/SQLServerAdapter.js +2 -1
- package/src/orm/adapters/SQLiteAdapter.d.ts.map +1 -1
- package/src/orm/adapters/SQLiteAdapter.js +2 -1
- package/src/orm/migrations/MigrationStore.d.ts.map +1 -1
- package/src/performance/Optimizer.d.ts.map +1 -1
- package/src/performance/Optimizer.js +57 -18
- package/src/profiling/RequestProfiler.d.ts.map +1 -1
- package/src/profiling/RequestProfiler.js +3 -1
- package/src/routing/CoreRoutes.d.ts +1 -1
- package/src/routing/CoreRoutes.d.ts.map +1 -1
- package/src/routing/CoreRoutes.js +2 -116
- package/src/routing/error.d.ts.map +1 -1
- package/src/routing/error.js +3 -2
- package/src/routing/publicRoot.d.ts.map +1 -1
- package/src/routing/publicRoot.js +4 -2
- package/src/runtime/PluginAutoImports.d.ts.map +1 -1
- package/src/runtime/PluginAutoImports.js +20 -4
- package/src/runtime/PluginManager.d.ts.map +1 -1
- package/src/runtime/PluginManager.js +23 -6
- package/src/runtime/RuntimeAdapter.d.ts +3 -3
- package/src/runtime/RuntimeAdapter.d.ts.map +1 -1
- package/src/runtime/StartupConfigFileRegistry.d.ts +15 -13
- package/src/runtime/StartupConfigFileRegistry.d.ts.map +1 -1
- package/src/runtime/StartupConfigFileRegistry.js +12 -12
- package/src/runtime/adapters/CloudflareAdapter.d.ts.map +1 -1
- package/src/runtime/adapters/CloudflareAdapter.js +1 -1
- package/src/runtime/adapters/DenoAdapter.d.ts.map +1 -1
- package/src/runtime/adapters/DenoAdapter.js +1 -1
- package/src/runtime/adapters/FargateAdapter.d.ts +2 -2
- package/src/runtime/adapters/FargateAdapter.d.ts.map +1 -1
- package/src/runtime/adapters/FargateAdapter.js +1 -1
- package/src/runtime/adapters/LambdaAdapter.d.ts +1 -1
- package/src/runtime/adapters/LambdaAdapter.d.ts.map +1 -1
- package/src/runtime/adapters/LambdaAdapter.js +6 -4
- package/src/runtime/adapters/NodeServerAdapter.js +1 -1
- package/src/scripts/GenerateEnvArtifacts.js +1 -1
- package/src/security/SignedRequest.js +1 -1
- package/src/security/StartupSecretValidation.d.ts.map +1 -1
- package/src/security/StartupSecretValidation.js +7 -1
- package/src/start.d.ts.map +1 -1
- package/src/start.js +0 -2
- package/src/templates/features/Auth.ts.tpl +4 -4
- package/src/templates/project/basic/README.md.tpl +1 -1
- package/src/templates/project/basic/app/Middleware/index.ts.tpl +1 -1
- package/src/templates/project/basic/config/notification.ts.tpl +1 -1
- package/src/templates/project/basic/routes/api.ts.tpl +1 -3
- package/src/templates/project/basic/src/index.ts.tpl +1 -1
- package/src/templates/project/basic/src/zintrust.plugins.ts.tpl +1 -1
- package/src/templates/project/basic/template.json +1 -1
- package/src/toolkit/Secrets/index.d.ts.map +1 -1
- package/src/toolkit/Secrets/index.js +13 -9
- package/src/toolkit/Secrets/providers/AwsSecretsManager.d.ts.map +1 -1
- package/src/toolkit/Secrets/providers/AwsSecretsManager.js +20 -7
- package/src/toolkit/Secrets/providers/CloudflareKv.d.ts.map +1 -1
- package/src/toolkit/Secrets/providers/CloudflareKv.js +19 -6
- package/src/tools/http/Http.js +1 -1
- package/src/tools/mail/drivers/Ses.d.ts.map +1 -1
- package/src/tools/mail/drivers/Ses.js +5 -4
- package/src/tools/mail/templates/index.js +2 -2
- package/src/tools/notification/drivers/Termii.d.ts.map +1 -1
- package/src/tools/notification/drivers/Termii.js +6 -17
- package/src/tools/notification/testingHelpers.d.ts.map +1 -1
- package/src/tools/queue/Queue.d.ts.map +1 -1
- package/src/tools/queue/Queue.js +3 -5
- package/src/tools/queue/drivers/Redis.d.ts.map +1 -1
- package/src/tools/queue/drivers/Redis.js +7 -1
- package/src/tools/storage/drivers/S3.d.ts.map +1 -1
- package/src/tools/storage/drivers/S3.js +16 -3
- package/src/routes/health.d.ts +0 -2
- package/src/routes/health.d.ts.map +0 -1
- package/src/routes/health.js +0 -1
- package/src/runtime/RuntimeDetector.d.ts +0 -15
- package/src/runtime/RuntimeDetector.d.ts.map +0 -1
- package/src/runtime/RuntimeDetector.js +0 -271
- package/src/templates/project/basic/routes/health.ts.tpl +0 -143
- package/src/templates/project/basic/routes/metrics.ts.tpl +0 -22
- package/src/workers/BroadcastWorker.d.ts +0 -22
- package/src/workers/BroadcastWorker.d.ts.map +0 -1
- package/src/workers/BroadcastWorker.js +0 -24
- package/src/workers/NotificationWorker.d.ts +0 -22
- package/src/workers/NotificationWorker.d.ts.map +0 -1
- package/src/workers/NotificationWorker.js +0 -23
- package/src/workers/createQueueWorker.d.ts +0 -24
- package/src/workers/createQueueWorker.d.ts.map +0 -1
- package/src/workers/createQueueWorker.js +0 -114
|
@@ -5,6 +5,25 @@
|
|
|
5
5
|
import { FileGenerator } from '../scaffolding/FileGenerator.js';
|
|
6
6
|
import { Logger } from '../../config/logger.js';
|
|
7
7
|
import * as path from '../../node-singletons/path.js';
|
|
8
|
+
// Escape characters that can cause issues when embedding JSON.stringify output
|
|
9
|
+
// into generated JavaScript source (e.g., inside <script> tags).
|
|
10
|
+
const unsafeCharMap = {
|
|
11
|
+
'<': '\\u003C',
|
|
12
|
+
'>': '\\u003E',
|
|
13
|
+
'/': '\\u002F',
|
|
14
|
+
'\\': '\\\\',
|
|
15
|
+
'\b': '\\b',
|
|
16
|
+
'\f': '\\f',
|
|
17
|
+
'\n': '\\n',
|
|
18
|
+
'\r': '\\r',
|
|
19
|
+
'\t': '\\t',
|
|
20
|
+
'\0': '\\0',
|
|
21
|
+
'\u2028': '\\u2028',
|
|
22
|
+
'\u2029': '\\u2029',
|
|
23
|
+
};
|
|
24
|
+
function escapeUnsafeChars(str) {
|
|
25
|
+
return str.replace(/[<>/\\\b\f\n\r\t\0\u2028\u2029]/g, (ch) => unsafeCharMap[ch] ?? ch);
|
|
26
|
+
}
|
|
8
27
|
/**
|
|
9
28
|
* Validate route options
|
|
10
29
|
*/
|
|
@@ -181,7 +200,7 @@ function buildMethodRoute(route, router, groupMiddlewareList) {
|
|
|
181
200
|
.filter((v) => v.trim() !== '')
|
|
182
201
|
.join(', ')}]`
|
|
183
202
|
: '';
|
|
184
|
-
const metaProp = `meta: { summary: ${JSON.stringify(summary)}, tags: [${JSON.stringify(tag)}] }`;
|
|
203
|
+
const metaProp = `meta: { summary: ${escapeUnsafeChars(JSON.stringify(summary))}, tags: [${escapeUnsafeChars(JSON.stringify(tag))}] }`;
|
|
185
204
|
const options = `{ ${[middlewareProp, metaProp].filter((v) => v !== '').join(', ')} }`;
|
|
186
205
|
return ` Router.${method}(${router}, '${routePath}', (req, res) => ${controllerVar}.${action}(req, res), ${options});\n`;
|
|
187
206
|
}
|
|
@@ -201,7 +220,7 @@ function buildResourceRoute(route, router, groupMiddlewareList) {
|
|
|
201
220
|
.filter((v) => v.trim() !== '')
|
|
202
221
|
.join(', ')}]`
|
|
203
222
|
: '';
|
|
204
|
-
const resourceMeta = (action, routePattern) => `meta: { summary: ${JSON.stringify(action.toUpperCase() + ' ' + routePattern)}, tags: [${JSON.stringify(tag)}] }`;
|
|
223
|
+
const resourceMeta = (action, routePattern) => `meta: { summary: ${escapeUnsafeChars(JSON.stringify(action.toUpperCase() + ' ' + routePattern))}, tags: [${escapeUnsafeChars(JSON.stringify(tag))}] }`;
|
|
205
224
|
const pathId = routePath + '/:id';
|
|
206
225
|
const optsParts = [
|
|
207
226
|
middlewareProp,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EnvFileLoader.d.ts","sourceRoot":"","sources":["../../../../src/cli/utils/EnvFileLoader.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"EnvFileLoader.d.ts","sourceRoot":"","sources":["../../../../src/cli/utils/EnvFileLoader.ts"],"names":[],"mappings":"AAgHA,KAAK,WAAW,GAAG;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B,CAAC;AAEF,KAAK,SAAS,GAAG;IACf,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,KAAK,YAAY,GAAG;IAClB,OAAO,CAAC,EAAE,aAAa,GAAG,YAAY,GAAG,SAAS,CAAC;IACnD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAsFF,eAAO,MAAM,aAAa;qBA7DH,WAAW,KAAQ,SAAS;wBA8B1B,SAAS;mCAEI,YAAY,KAAG,IAAI;oBA2BpC,SAAS;EAO5B,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared Utilities for External Service Drivers
|
|
3
|
+
* Common patterns for API calls, environment variable reading, and error handling
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Environment variable reader with fallback support
|
|
7
|
+
* Handles both Env.get() and process.env for maximum compatibility
|
|
8
|
+
*/
|
|
9
|
+
export declare const readEnvString: (key: string, fallback?: string) => string;
|
|
10
|
+
/**
|
|
11
|
+
* Validate required parameters for external service calls
|
|
12
|
+
*/
|
|
13
|
+
export declare const validateRequiredParams: (params: Record<string, unknown>, required: string[]) => void;
|
|
14
|
+
/**
|
|
15
|
+
* Create standardized API error response
|
|
16
|
+
*/
|
|
17
|
+
export declare const createApiError: (message: string, service: string) => Error;
|
|
18
|
+
/**
|
|
19
|
+
* Common fetch wrapper with error handling
|
|
20
|
+
*/
|
|
21
|
+
export declare const safeFetch: (url: string, options: RequestInit) => Promise<Response>;
|
|
22
|
+
/**
|
|
23
|
+
* Standard API response builder
|
|
24
|
+
*/
|
|
25
|
+
export declare const buildApiResponse: <T>(success: boolean, data?: T, error?: string) => {
|
|
26
|
+
success: boolean;
|
|
27
|
+
data?: T;
|
|
28
|
+
error?: string;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Health check utilities
|
|
32
|
+
*/
|
|
33
|
+
export declare const HealthUtils: {
|
|
34
|
+
/**
|
|
35
|
+
* Get process uptime safely
|
|
36
|
+
*/
|
|
37
|
+
getUptime(): number;
|
|
38
|
+
/**
|
|
39
|
+
* Get current timestamp
|
|
40
|
+
*/
|
|
41
|
+
getTimestamp(): string;
|
|
42
|
+
/**
|
|
43
|
+
* Check if in production
|
|
44
|
+
*/
|
|
45
|
+
isProduction(environment: string): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Build health response
|
|
48
|
+
*/
|
|
49
|
+
buildHealthResponse(status: "healthy" | "unhealthy" | "alive" | "ready" | "not_ready", environment: string, extra?: Record<string, unknown>): {
|
|
50
|
+
status: "unhealthy" | "ready" | "healthy" | "alive" | "not_ready";
|
|
51
|
+
timestamp: string;
|
|
52
|
+
environment: string;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Build error health response
|
|
56
|
+
*/
|
|
57
|
+
buildErrorResponse(status: "unhealthy" | "not_ready", environment: string, error: Error, extra?: Record<string, unknown>): {
|
|
58
|
+
status: "unhealthy" | "ready" | "healthy" | "alive" | "not_ready";
|
|
59
|
+
timestamp: string;
|
|
60
|
+
environment: string;
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
//# sourceMappingURL=ExternalServiceUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExternalServiceUtils.d.ts","sourceRoot":"","sources":["../../../src/common/ExternalServiceUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH;;;GAGG;AACH,eAAO,MAAM,aAAa,GAAI,KAAK,MAAM,EAAE,iBAAa,KAAG,MAS1D,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,sBAAsB,GACjC,QAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,UAAU,MAAM,EAAE,KACjB,IAWF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,cAAc,GAAI,SAAS,MAAM,EAAE,SAAS,MAAM,KAAG,KAEjE,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,SAAS,GAAU,KAAK,MAAM,EAAE,SAAS,WAAW,KAAG,OAAO,CAAC,QAAQ,CAcnF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,gBAAgB,GAAI,CAAC,EAChC,SAAS,OAAO,EAChB,OAAO,CAAC,EACR,QAAQ,MAAM,KACb;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAY9C,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,WAAW;IACtB;;OAEG;iBACU,MAAM;IAMnB;;OAEG;oBACa,MAAM;IAItB;;OAEG;8BACuB,MAAM,GAAG,OAAO;IAI1C;;OAEG;gCAEO,SAAS,GAAG,WAAW,GAAG,OAAO,GAAG,OAAO,GAAG,WAAW,eACpD,MAAM,UACX,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;;;;;IAYjC;;OAEG;+BAEO,WAAW,GAAG,WAAW,eACpB,MAAM,SACZ,KAAK,UACJ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;;;;;CASlC,CAAC"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared Utilities for External Service Drivers
|
|
3
|
+
* Common patterns for API calls, environment variable reading, and error handling
|
|
4
|
+
*/
|
|
5
|
+
import { Env } from '../config/env.js';
|
|
6
|
+
import { ErrorFactory } from '../exceptions/ZintrustError.js';
|
|
7
|
+
/**
|
|
8
|
+
* Environment variable reader with fallback support
|
|
9
|
+
* Handles both Env.get() and process.env for maximum compatibility
|
|
10
|
+
*/
|
|
11
|
+
export const readEnvString = (key, fallback = '') => {
|
|
12
|
+
const anyEnv = Env;
|
|
13
|
+
const fromEnv = typeof anyEnv.get === 'function' ? anyEnv.get(key, '') : '';
|
|
14
|
+
if (typeof fromEnv === 'string' && fromEnv.trim() !== '')
|
|
15
|
+
return fromEnv;
|
|
16
|
+
if (typeof process !== 'undefined') {
|
|
17
|
+
const raw = process.env?.[key];
|
|
18
|
+
if (typeof raw === 'string')
|
|
19
|
+
return raw;
|
|
20
|
+
}
|
|
21
|
+
return fromEnv ?? fallback;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Validate required parameters for external service calls
|
|
25
|
+
*/
|
|
26
|
+
export const validateRequiredParams = (params, required) => {
|
|
27
|
+
for (const param of required) {
|
|
28
|
+
const value = params[param];
|
|
29
|
+
if (value === null ||
|
|
30
|
+
value === undefined ||
|
|
31
|
+
(typeof value === 'string' && value.length === 0)) {
|
|
32
|
+
throw ErrorFactory.createValidationError(`${param} is required`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Create standardized API error response
|
|
38
|
+
*/
|
|
39
|
+
export const createApiError = (message, service) => {
|
|
40
|
+
return ErrorFactory.createValidationError(`${service} API error: ${message}`);
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Common fetch wrapper with error handling
|
|
44
|
+
*/
|
|
45
|
+
export const safeFetch = async (url, options) => {
|
|
46
|
+
try {
|
|
47
|
+
const response = await globalThis.fetch(url, options);
|
|
48
|
+
if (!response.ok) {
|
|
49
|
+
throw ErrorFactory.createValidationError(`HTTP ${response.status}: ${response.statusText}`);
|
|
50
|
+
}
|
|
51
|
+
return response;
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
throw ErrorFactory.createValidationError(error instanceof Error ? error.message : 'Unknown fetch error');
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Standard API response builder
|
|
59
|
+
*/
|
|
60
|
+
export const buildApiResponse = (success, data, error) => {
|
|
61
|
+
const response = { success };
|
|
62
|
+
if (data !== undefined) {
|
|
63
|
+
response.data = data;
|
|
64
|
+
}
|
|
65
|
+
if (error !== undefined) {
|
|
66
|
+
response.error = error;
|
|
67
|
+
}
|
|
68
|
+
return response;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Health check utilities
|
|
72
|
+
*/
|
|
73
|
+
export const HealthUtils = {
|
|
74
|
+
/**
|
|
75
|
+
* Get process uptime safely
|
|
76
|
+
*/
|
|
77
|
+
getUptime() {
|
|
78
|
+
return typeof process !== 'undefined' && typeof process.uptime === 'function'
|
|
79
|
+
? process.uptime()
|
|
80
|
+
: 0;
|
|
81
|
+
},
|
|
82
|
+
/**
|
|
83
|
+
* Get current timestamp
|
|
84
|
+
*/
|
|
85
|
+
getTimestamp() {
|
|
86
|
+
return new Date().toISOString();
|
|
87
|
+
},
|
|
88
|
+
/**
|
|
89
|
+
* Check if in production
|
|
90
|
+
*/
|
|
91
|
+
isProduction(environment) {
|
|
92
|
+
return environment === 'production';
|
|
93
|
+
},
|
|
94
|
+
/**
|
|
95
|
+
* Build health response
|
|
96
|
+
*/
|
|
97
|
+
buildHealthResponse(status, environment, extra) {
|
|
98
|
+
const base = {
|
|
99
|
+
status,
|
|
100
|
+
timestamp: HealthUtils.getTimestamp(),
|
|
101
|
+
environment,
|
|
102
|
+
...extra,
|
|
103
|
+
};
|
|
104
|
+
return base;
|
|
105
|
+
},
|
|
106
|
+
/**
|
|
107
|
+
* Build error health response
|
|
108
|
+
*/
|
|
109
|
+
buildErrorResponse(status, environment, error, extra) {
|
|
110
|
+
const isProd = HealthUtils.isProduction(environment);
|
|
111
|
+
return HealthUtils.buildHealthResponse(status, environment, {
|
|
112
|
+
error: isProd ? 'Service unavailable' : error.message,
|
|
113
|
+
...extra,
|
|
114
|
+
});
|
|
115
|
+
},
|
|
116
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared Health Route Handlers
|
|
3
|
+
* Extracted to eliminate duplication between CoreRoutes.ts and routes/health.ts
|
|
4
|
+
*/
|
|
5
|
+
import type { IRouter } from '../routing/Router';
|
|
6
|
+
/**
|
|
7
|
+
* Register all health routes
|
|
8
|
+
*/
|
|
9
|
+
export declare const registerHealthRoutes: (router: IRouter) => void;
|
|
10
|
+
//# sourceMappingURL=HealthRoutes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HealthRoutes.d.ts","sourceRoot":"","sources":["../../../src/common/HealthRoutes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AA+HhD;;GAEG;AACH,eAAO,MAAM,oBAAoB,GAAI,QAAQ,OAAO,KAAG,IAItD,CAAC"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared Health Route Handlers
|
|
3
|
+
* Extracted to eliminate duplication between CoreRoutes.ts and routes/health.ts
|
|
4
|
+
*/
|
|
5
|
+
import { appConfig } from '../config/app.js';
|
|
6
|
+
import { RuntimeHealthProbes } from '../health/RuntimeHealthProbes.js';
|
|
7
|
+
import { Router } from '../routing/Router.js';
|
|
8
|
+
import { HealthUtils } from './ExternalServiceUtils.js';
|
|
9
|
+
import { Env } from '../config/env.js';
|
|
10
|
+
import { Logger } from '../config/logger.js';
|
|
11
|
+
import { useDatabase } from '../orm/Database.js';
|
|
12
|
+
import { QueryBuilder } from '../orm/QueryBuilder.js';
|
|
13
|
+
/**
|
|
14
|
+
* Health check endpoint handler
|
|
15
|
+
*/
|
|
16
|
+
async function handleHealthRoute(_req, res) {
|
|
17
|
+
const environment = Env.NODE_ENV ?? 'development';
|
|
18
|
+
try {
|
|
19
|
+
const db = useDatabase();
|
|
20
|
+
const maybeIsConnected = db.isConnected;
|
|
21
|
+
const maybeConnect = db.connect;
|
|
22
|
+
if (typeof maybeIsConnected === 'function' && maybeIsConnected.call(db) === false) {
|
|
23
|
+
if (typeof maybeConnect === 'function') {
|
|
24
|
+
await maybeConnect.call(db);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
await QueryBuilder.ping(db);
|
|
28
|
+
const uptime = HealthUtils.getUptime();
|
|
29
|
+
res.json(HealthUtils.buildHealthResponse('healthy', environment, {
|
|
30
|
+
uptime,
|
|
31
|
+
database: 'connected',
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
Logger.error('Health check failed:', error);
|
|
36
|
+
res.setStatus(503).json(HealthUtils.buildErrorResponse('unhealthy', environment, error, {
|
|
37
|
+
database: 'disconnected',
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Liveness probe endpoint handler
|
|
43
|
+
*/
|
|
44
|
+
function handleHealthLiveRoute(_req, res) {
|
|
45
|
+
const uptime = HealthUtils.getUptime();
|
|
46
|
+
res.json(HealthUtils.buildHealthResponse('alive', Env.NODE_ENV ?? 'development', {
|
|
47
|
+
uptime,
|
|
48
|
+
}));
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Readiness probe endpoint handler
|
|
52
|
+
*/
|
|
53
|
+
async function handleHealthReadyRoute(_req, res) {
|
|
54
|
+
const startTime = Date.now();
|
|
55
|
+
const environment = appConfig.environment;
|
|
56
|
+
let databaseResponseTime = null;
|
|
57
|
+
let cacheResponseTime = null;
|
|
58
|
+
try {
|
|
59
|
+
const db = useDatabase();
|
|
60
|
+
const maybeIsConnected = db.isConnected;
|
|
61
|
+
const maybeConnect = db.connect;
|
|
62
|
+
if (typeof maybeIsConnected === 'function' && maybeIsConnected.call(db) === false) {
|
|
63
|
+
if (typeof maybeConnect === 'function') {
|
|
64
|
+
await maybeConnect.call(db);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
await QueryBuilder.ping(db);
|
|
68
|
+
databaseResponseTime = Date.now() - startTime;
|
|
69
|
+
cacheResponseTime = await RuntimeHealthProbes.pingKvCache(2000);
|
|
70
|
+
res.json(HealthUtils.buildHealthResponse('ready', environment, {
|
|
71
|
+
dependencies: {
|
|
72
|
+
database: {
|
|
73
|
+
status: 'ready',
|
|
74
|
+
responseTime: databaseResponseTime,
|
|
75
|
+
},
|
|
76
|
+
...(cacheResponseTime === null
|
|
77
|
+
? {}
|
|
78
|
+
: {
|
|
79
|
+
cache: {
|
|
80
|
+
status: 'ready',
|
|
81
|
+
responseTime: cacheResponseTime,
|
|
82
|
+
},
|
|
83
|
+
}),
|
|
84
|
+
},
|
|
85
|
+
}));
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
Logger.error('Readiness check failed:', error);
|
|
89
|
+
const responseTime = Date.now() - startTime;
|
|
90
|
+
const dependencies = {
|
|
91
|
+
database: {
|
|
92
|
+
status: databaseResponseTime === null ? 'unavailable' : 'ready',
|
|
93
|
+
responseTime: databaseResponseTime ?? responseTime,
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
if (RuntimeHealthProbes.getCacheDriverName() === 'kv') {
|
|
97
|
+
dependencies['cache'] = {
|
|
98
|
+
status: 'unavailable',
|
|
99
|
+
responseTime: cacheResponseTime ?? responseTime,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
res.setStatus(503).json(HealthUtils.buildErrorResponse('not_ready', environment, error, {
|
|
103
|
+
dependencies,
|
|
104
|
+
}));
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Register all health routes
|
|
109
|
+
*/
|
|
110
|
+
export const registerHealthRoutes = (router) => {
|
|
111
|
+
Router.get(router, '/health', handleHealthRoute);
|
|
112
|
+
Router.get(router, '/health/live', handleHealthLiveRoute);
|
|
113
|
+
Router.get(router, '/health/ready', handleHealthReadyRoute);
|
|
114
|
+
};
|
|
@@ -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;AAIH,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,6 +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
|
+
import { Env } from './env.js';
|
|
6
7
|
import { Logger } from './logger.js';
|
|
7
8
|
import { ErrorFactory } from '../exceptions/ZintrustError.js';
|
|
8
9
|
let instance;
|
|
@@ -242,7 +243,7 @@ async function getFromDenoEnv(key) {
|
|
|
242
243
|
*/
|
|
243
244
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
244
245
|
async function getFromEnv(key) {
|
|
245
|
-
const value =
|
|
246
|
+
const value = Env.get(key, '');
|
|
246
247
|
if (value === undefined || value === null || value === '') {
|
|
247
248
|
throw ErrorFactory.createNotFoundError(`Secret not found: ${key}`, { key });
|
|
248
249
|
}
|
package/src/config/app.d.ts
CHANGED
|
@@ -49,8 +49,9 @@ export declare const appConfig: Readonly<{
|
|
|
49
49
|
/**
|
|
50
50
|
* Max request body size
|
|
51
51
|
*/
|
|
52
|
-
readonly maxBodySize:
|
|
52
|
+
readonly maxBodySize: number;
|
|
53
53
|
readonly getSafeEnv: () => NodeJS.ProcessEnv;
|
|
54
|
+
readonly detectRuntime: () => string;
|
|
54
55
|
}>;
|
|
55
56
|
export { getSafeEnv };
|
|
56
57
|
export type AppConfig = typeof appConfig;
|
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;AAGH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../../../src/config/app.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAe,SAAS,EAAE,MAAM,cAAc,CAAC;AAoI3D,QAAA,MAAM,UAAU,QAAO,MAAM,CAAC,UAA2B,CAAC;AA2E1D,eAAO,MAAM,SAAS;IAjEpB;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;kCACc,OAAO;IAIxB;;OAEG;iCACa,OAAO;IAIvB;;OAEG;8BACU,OAAO;IAIpB;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;+BApEkB,MAAM,CAAC,UAAU;kCAhDd,MAAM;EA2HoB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,CAAC;AAEtB,MAAM,MAAM,SAAS,GAAG,OAAO,SAAS,CAAC"}
|
package/src/config/app.js
CHANGED
|
@@ -4,60 +4,113 @@
|
|
|
4
4
|
* Sealed namespace for immutability
|
|
5
5
|
*/
|
|
6
6
|
import { Env } from './env.js';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
};
|
|
7
|
+
// Cache getSafeEnv result at module load time to avoid repeated object creation
|
|
8
|
+
const anyEnv = Env;
|
|
10
9
|
const readEnvString = (key, defaultValue = '') => {
|
|
11
|
-
const anyEnv = Env;
|
|
12
10
|
if (typeof anyEnv.get === 'function') {
|
|
13
|
-
return anyEnv.get(key, defaultValue);
|
|
11
|
+
return anyEnv.get(key, defaultValue) ?? '';
|
|
12
|
+
}
|
|
13
|
+
if (typeof process !== 'undefined') {
|
|
14
|
+
const raw = process.env?.[key];
|
|
15
|
+
if (typeof raw === 'string' && raw !== '')
|
|
16
|
+
return raw;
|
|
14
17
|
}
|
|
15
|
-
|
|
16
|
-
const raw = proc?.env?.[key];
|
|
17
|
-
return raw ?? defaultValue;
|
|
18
|
+
return defaultValue;
|
|
18
19
|
};
|
|
19
|
-
const readEnvInt = (key, defaultValue) => {
|
|
20
|
-
const anyEnv = Env;
|
|
20
|
+
const readEnvInt = (key, defaultValue = 0) => {
|
|
21
21
|
if (typeof anyEnv.getInt === 'function') {
|
|
22
22
|
return anyEnv.getInt(key, defaultValue);
|
|
23
23
|
}
|
|
24
24
|
const raw = readEnvString(key, String(defaultValue));
|
|
25
25
|
const parsed = Number.parseInt(raw, 10);
|
|
26
|
-
return Number.
|
|
26
|
+
return Number.isFinite(parsed) ? parsed : defaultValue;
|
|
27
27
|
};
|
|
28
|
-
const readEnvBool = (key, defaultValue) => {
|
|
29
|
-
const anyEnv = Env;
|
|
28
|
+
const readEnvBool = (key, defaultValue = false) => {
|
|
30
29
|
if (typeof anyEnv.getBool === 'function') {
|
|
31
30
|
return anyEnv.getBool(key, defaultValue);
|
|
32
31
|
}
|
|
33
|
-
const raw = readEnvString(key,
|
|
32
|
+
const raw = readEnvString(key, '');
|
|
33
|
+
if (raw === '')
|
|
34
|
+
return defaultValue;
|
|
34
35
|
return raw.toLowerCase() === 'true' || raw === '1';
|
|
35
36
|
};
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
37
|
+
const readAppPort = () => {
|
|
38
|
+
if (typeof anyEnv.getInt === 'function') {
|
|
39
|
+
return anyEnv.getInt('PORT', anyEnv.getInt('APP_PORT', 3000));
|
|
40
|
+
}
|
|
41
|
+
if (typeof Env.PORT === 'number' && Number.isFinite(Env.PORT) && Env.PORT > 0) {
|
|
42
|
+
return Env.PORT;
|
|
43
|
+
}
|
|
44
|
+
const portRaw = readEnvString('PORT', readEnvString('APP_PORT', '3000'));
|
|
45
|
+
const parsed = Number.parseInt(portRaw, 10);
|
|
46
|
+
return Number.isFinite(parsed) ? parsed : 3000;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Check if running on AWS Lambda
|
|
50
|
+
*/
|
|
51
|
+
function isLambda() {
|
|
52
|
+
return (Env.getBool('LAMBDA_TASK_ROOT') === true ||
|
|
53
|
+
Env.getBool('AWS_LAMBDA_FUNCTION_NAME') === true ||
|
|
54
|
+
Env.getBool('AWS_EXECUTION_ENV') === true);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Check if running on Cloudflare Workers
|
|
58
|
+
*/
|
|
59
|
+
function isCloudflare() {
|
|
60
|
+
return globalThis.CF !== undefined;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Check if running on Deno
|
|
64
|
+
*/
|
|
65
|
+
function isDeno() {
|
|
66
|
+
return globalThis.Deno !== undefined;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Detect current runtime environment
|
|
70
|
+
*/
|
|
71
|
+
const detectRuntime = () => {
|
|
72
|
+
const explicit = Env.get('RUNTIME').trim();
|
|
73
|
+
if (explicit !== '' && explicit !== 'auto')
|
|
74
|
+
return explicit;
|
|
75
|
+
// Auto-detection logic
|
|
76
|
+
if (isLambda() === true) {
|
|
77
|
+
return 'lambda';
|
|
78
|
+
}
|
|
79
|
+
if (isCloudflare() === true) {
|
|
80
|
+
return 'cloudflare';
|
|
81
|
+
}
|
|
82
|
+
if (isDeno() === true) {
|
|
83
|
+
return 'deno';
|
|
84
|
+
}
|
|
85
|
+
// Default to nodejs for containers (Fargate, Docker, Cloud Run)
|
|
86
|
+
return 'nodejs';
|
|
87
|
+
};
|
|
88
|
+
const resolvedNodeEnv = readEnvString('NODE_ENV', 'development');
|
|
89
|
+
// Cache getSafeEnv result at module load time to avoid repeated object creation
|
|
90
|
+
const cachedSafeEnv = {
|
|
91
|
+
...(typeof process === 'undefined' ? {} : process.env),
|
|
92
|
+
NODE_ENV: resolvedNodeEnv,
|
|
93
|
+
MODE: resolvedNodeEnv,
|
|
94
|
+
npm_config_scripts_prepend_node_path: 'true',
|
|
56
95
|
};
|
|
96
|
+
const useRawQry = readEnvString('USE_RAW_QRY');
|
|
97
|
+
if (useRawQry !== '')
|
|
98
|
+
cachedSafeEnv.USE_RAW_QRY = useRawQry;
|
|
99
|
+
const serviceApiKey = readEnvString('SERVICE_API_KEY');
|
|
100
|
+
if (serviceApiKey !== '')
|
|
101
|
+
cachedSafeEnv.SERVICE_API_KEY = serviceApiKey;
|
|
102
|
+
const serviceJwtSecret = readEnvString('SERVICE_JWT_SECRET') || readEnvString('APP_KEY');
|
|
103
|
+
if (serviceJwtSecret !== '')
|
|
104
|
+
cachedSafeEnv.SERVICE_JWT_SECRET = serviceJwtSecret;
|
|
105
|
+
const baseUrl = readEnvString('BASE_URL');
|
|
106
|
+
if (baseUrl !== '')
|
|
107
|
+
cachedSafeEnv['BASE_URL'] = baseUrl;
|
|
108
|
+
if (typeof Env.SAFE_PATH === 'string' && Env.SAFE_PATH !== '') {
|
|
109
|
+
cachedSafeEnv['PATH'] = Env.SAFE_PATH;
|
|
110
|
+
}
|
|
111
|
+
const getSafeEnv = () => cachedSafeEnv;
|
|
57
112
|
const normalizeMode = () => {
|
|
58
|
-
const value = (
|
|
59
|
-
? Env.NODE_ENV
|
|
60
|
-
: readEnvString('NODE_ENV', 'development'));
|
|
113
|
+
const value = readEnvString('NODE_ENV', Env.NODE_ENV ?? 'development');
|
|
61
114
|
if (value === 'production' || value === 'pro' || value === 'prod')
|
|
62
115
|
return 'production';
|
|
63
116
|
if (value === 'testing' || value === 'test')
|
|
@@ -68,9 +121,7 @@ const appConfigObj = {
|
|
|
68
121
|
/**
|
|
69
122
|
* Application name
|
|
70
123
|
*/
|
|
71
|
-
name:
|
|
72
|
-
? Env.APP_NAME
|
|
73
|
-
: readEnvString('APP_NAME', 'ZinTrust'),
|
|
124
|
+
name: readEnvString('APP_NAME', Env.APP_NAME),
|
|
74
125
|
/**
|
|
75
126
|
* Application environment
|
|
76
127
|
*/
|
|
@@ -78,15 +129,11 @@ const appConfigObj = {
|
|
|
78
129
|
/**
|
|
79
130
|
* Application port
|
|
80
131
|
*/
|
|
81
|
-
port:
|
|
82
|
-
? Env.PORT
|
|
83
|
-
: readEnvInt('APP_PORT', 3000),
|
|
132
|
+
port: readAppPort(),
|
|
84
133
|
/**
|
|
85
134
|
* Application host
|
|
86
135
|
*/
|
|
87
|
-
host:
|
|
88
|
-
? Env.HOST
|
|
89
|
-
: readEnvString('HOST', 'localhost'),
|
|
136
|
+
host: readEnvString('HOST', Env.HOST),
|
|
90
137
|
/**
|
|
91
138
|
* Is development environment
|
|
92
139
|
*/
|
|
@@ -108,22 +155,21 @@ const appConfigObj = {
|
|
|
108
155
|
/**
|
|
109
156
|
* Application debug mode
|
|
110
157
|
*/
|
|
111
|
-
debug:
|
|
112
|
-
? Env.DEBUG
|
|
113
|
-
: readEnvBool('DEBUG', false),
|
|
158
|
+
debug: readEnvBool('DEBUG', Env.DEBUG),
|
|
114
159
|
/**
|
|
115
160
|
* Application timezone
|
|
116
161
|
*/
|
|
117
|
-
timezone: readEnvString('APP_TIMEZONE',
|
|
162
|
+
timezone: readEnvString('APP_TIMEZONE', Env.APP_TIMEZONE),
|
|
118
163
|
/**
|
|
119
164
|
* Request timeout (milliseconds)
|
|
120
165
|
*/
|
|
121
|
-
requestTimeout: readEnvInt('REQUEST_TIMEOUT',
|
|
166
|
+
requestTimeout: readEnvInt('REQUEST_TIMEOUT', Env.REQUEST_TIMEOUT),
|
|
122
167
|
/**
|
|
123
168
|
* Max request body size
|
|
124
169
|
*/
|
|
125
|
-
maxBodySize:
|
|
170
|
+
maxBodySize: readEnvInt('MAX_BODY_SIZE', Env.MAX_BODY_SIZE),
|
|
126
171
|
getSafeEnv,
|
|
172
|
+
detectRuntime,
|
|
127
173
|
};
|
|
128
174
|
export const appConfig = Object.freeze(appConfigObj);
|
|
129
175
|
export { getSafeEnv };
|
|
@@ -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,KAAK,EAEV,gBAAgB,EAEhB,0BAA0B,EAI3B,MAAM,cAAc,CAAC;AAItB,MAAM,MAAM,wBAAwB,GAAG,OAAO,CAAC;IAC7C,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,0BAA0B,CAAC,CAAC;CACrD,CAAC,CAAC;AAEH,KAAK,sBAAsB,GAAG;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,gBAAgB,CAAC;IAC1B,aAAa,EAAE,MAAM,MAAM,CAAC;IAC5B,eAAe,EAAE,CAAC,IAAI,CAAC,EAAE,MAAM,KAAK,0BAA0B,CAAC;CAChE,CAAC;AA0EF,QAAA,MAAM,qBAAqB,QAAO,sBAoDjC,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG,UAAU,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAqBvE,QAAA,MAAM,eAAe,EAAE,eAYrB,CAAC;AAEH,eAAe,eAAe,CAAC"}
|
package/src/config/broadcast.js
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
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 { StartupConfigFile, StartupConfigFileRegistry } from '../runtime/StartupConfigFileRegistry.js';
|
|
8
7
|
import { Env } from './env.js';
|
|
9
8
|
import { ErrorFactory } from '../exceptions/ZintrustError.js';
|
|
9
|
+
import { StartupConfigFile, StartupConfigFileRegistry } from '../runtime/StartupConfigFileRegistry.js';
|
|
10
10
|
const normalizeDriverName = (value) => value.trim().toLowerCase();
|
|
11
11
|
const hasOwn = (obj, key) => {
|
|
12
12
|
return Object.hasOwn(obj, key);
|
|
@@ -89,7 +89,7 @@ const createBroadcastConfig = () => {
|
|
|
89
89
|
pusher: getPusherConfig(),
|
|
90
90
|
redis: getRedisConfig(),
|
|
91
91
|
redishttps: getRedisHttpsConfig(),
|
|
92
|
-
...
|
|
92
|
+
...overrides.drivers,
|
|
93
93
|
};
|
|
94
94
|
},
|
|
95
95
|
/**
|
|
@@ -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,KAAK,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAIxE,MAAM,MAAM,oBAAoB,GAAG,OAAO,CAAC;IACzC,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,gBAAgB,CAAC,SAAS,CAAC,CAAC;IACrC,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,EAAE,MAAM,CAAC;CACb,CAAC,CAAC;AA0BH,QAAA,MAAM,iBAAiB,QAAO;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,gBAAgB,CAAC,SAAS,CAAC,CAAC;IACrC,SAAS,EAAE,CAAC,IAAI,CAAC,EAAE,MAAM,KAAK,iBAAiB,CAAC;IAChD,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,EAAE,MAAM,CAAC;CA4Fb,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG,UAAU,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAqB/D,eAAO,MAAM,WAAW,EAAE,WAYxB,CAAC"}
|