@zintrust/core 0.1.22 → 0.1.24
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.d.ts.map +1 -1
- package/src/cli/commands/DbSeedCommand.js +7 -39
- 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 +12 -55
- 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 +136 -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 +9 -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.js +7 -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/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/DatabaseCliUtils.d.ts +20 -0
- package/src/cli/utils/DatabaseCliUtils.d.ts.map +1 -0
- package/src/cli/utils/DatabaseCliUtils.js +54 -0
- 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 +1 -1
- 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 +1 -1
- package/src/config/type.d.ts +111 -0
- package/src/config/type.d.ts.map +1 -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/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 +1 -1
- package/src/orm/ConnectionManager.d.ts.map +1 -1
- package/src/orm/ConnectionManager.js +37 -19
- package/src/orm/Model.d.ts +8 -1
- package/src/orm/Model.d.ts.map +1 -1
- package/src/orm/Model.js +85 -24
- 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/D1RemoteAdapter.d.ts +1 -1
- package/src/orm/adapters/D1RemoteAdapter.js +1 -1
- package/src/performance/Optimizer.d.ts.map +1 -1
- package/src/performance/Optimizer.js +2 -4
- 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 +8 -4
- package/src/runtime/PluginManager.d.ts.map +1 -1
- package/src/runtime/PluginManager.js +11 -6
- package/src/runtime/RuntimeAdapter.d.ts +3 -3
- package/src/runtime/RuntimeAdapter.d.ts.map +1 -1
- package/src/runtime/StartupConfigFileRegistry.d.ts +2 -1
- package/src/runtime/StartupConfigFileRegistry.d.ts.map +1 -1
- package/src/runtime/StartupConfigFileRegistry.js +2 -1
- 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 +8 -7
- package/src/toolkit/Secrets/providers/CloudflareKv.d.ts.map +1 -1
- package/src/toolkit/Secrets/providers/CloudflareKv.js +7 -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 +4 -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,
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { CommandOptions, IBaseCommand } from '../BaseCommand';
|
|
2
|
+
import type { DatabaseConfig as OrmDatabaseConfig } from '../../orm/DatabaseAdapter';
|
|
3
|
+
export type ConnectionConfig = {
|
|
4
|
+
driver: string;
|
|
5
|
+
host?: string;
|
|
6
|
+
port?: number;
|
|
7
|
+
database?: string;
|
|
8
|
+
username?: string;
|
|
9
|
+
password?: string;
|
|
10
|
+
};
|
|
11
|
+
export declare const mapConnectionToOrmConfig: (conn: ConnectionConfig) => OrmDatabaseConfig;
|
|
12
|
+
export declare const parseRollbackSteps: (options: CommandOptions) => number;
|
|
13
|
+
export declare const confirmProductionRun: (params: {
|
|
14
|
+
cmd: IBaseCommand;
|
|
15
|
+
interactive: boolean;
|
|
16
|
+
message: string;
|
|
17
|
+
destructive?: boolean;
|
|
18
|
+
force?: boolean;
|
|
19
|
+
}) => Promise<boolean>;
|
|
20
|
+
//# sourceMappingURL=DatabaseCliUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DatabaseCliUtils.d.ts","sourceRoot":"","sources":["../../../../src/cli/utils/DatabaseCliUtils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGrE,OAAO,KAAK,EAAE,cAAc,IAAI,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEhF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,eAAO,MAAM,wBAAwB,GAAI,MAAM,gBAAgB,KAAG,iBAkCjE,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAAI,SAAS,cAAc,KAAG,MAG5D,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAAU,QAAQ;IACjD,GAAG,EAAE,YAAY,CAAC;IAClB,WAAW,EAAE,OAAO,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,KAAG,OAAO,CAAC,OAAO,CAalB,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { PromptHelper } from '../PromptHelper.js';
|
|
2
|
+
import { Env } from '../../config/env.js';
|
|
3
|
+
export const mapConnectionToOrmConfig = (conn) => {
|
|
4
|
+
switch (conn.driver) {
|
|
5
|
+
case 'sqlite':
|
|
6
|
+
return { driver: 'sqlite', database: conn.database ?? ':memory:' };
|
|
7
|
+
case 'postgresql':
|
|
8
|
+
return {
|
|
9
|
+
driver: 'postgresql',
|
|
10
|
+
host: conn.host,
|
|
11
|
+
port: conn.port,
|
|
12
|
+
database: conn.database,
|
|
13
|
+
username: conn.username,
|
|
14
|
+
password: conn.password,
|
|
15
|
+
};
|
|
16
|
+
case 'mysql':
|
|
17
|
+
return {
|
|
18
|
+
driver: 'mysql',
|
|
19
|
+
host: conn.host,
|
|
20
|
+
port: conn.port,
|
|
21
|
+
database: conn.database,
|
|
22
|
+
username: conn.username,
|
|
23
|
+
password: conn.password,
|
|
24
|
+
};
|
|
25
|
+
case 'sqlserver':
|
|
26
|
+
return {
|
|
27
|
+
driver: 'sqlserver',
|
|
28
|
+
host: conn.host,
|
|
29
|
+
port: conn.port,
|
|
30
|
+
database: conn.database,
|
|
31
|
+
username: conn.username,
|
|
32
|
+
password: conn.password,
|
|
33
|
+
};
|
|
34
|
+
default:
|
|
35
|
+
return { driver: 'sqlite', database: ':memory:' };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
export const parseRollbackSteps = (options) => {
|
|
39
|
+
const stepRaw = typeof options['step'] === 'string' ? options['step'] : '1';
|
|
40
|
+
return Math.max(1, Number.parseInt(stepRaw, 10) || 1);
|
|
41
|
+
};
|
|
42
|
+
export const confirmProductionRun = async (params) => {
|
|
43
|
+
if (Env.NODE_ENV !== 'production')
|
|
44
|
+
return true;
|
|
45
|
+
if (params.force === true)
|
|
46
|
+
return true;
|
|
47
|
+
const prompt = params.destructive === true ? `${params.message} (destructive)` : params.message;
|
|
48
|
+
const confirmed = await PromptHelper.confirm(prompt, false, params.interactive);
|
|
49
|
+
if (!confirmed) {
|
|
50
|
+
params.cmd.warn('Cancelled.');
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
return true;
|
|
54
|
+
};
|
|
@@ -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"}
|