@zintrust/core 0.1.5 → 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/bin/z.d.ts
CHANGED
package/bin/z.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"z.d.ts","sourceRoot":"","sources":["../../bin/z.ts"],"names":[],"mappings":";AAEA;;;GAGG
|
|
1
|
+
{"version":3,"file":"z.d.ts","sourceRoot":"","sources":["../../bin/z.ts"],"names":[],"mappings":";AAEA;;;GAGG"}
|
package/bin/z.js
CHANGED
package/bin/zin.d.ts
CHANGED
package/bin/zin.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zin.d.ts","sourceRoot":"","sources":["../../bin/zin.ts"],"names":[],"mappings":";AAEA;;;GAGG
|
|
1
|
+
{"version":3,"file":"zin.d.ts","sourceRoot":"","sources":["../../bin/zin.ts"],"names":[],"mappings":";AAEA;;;GAGG"}
|
package/bin/zin.js
CHANGED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zintrust CLI - Main Entry Point (hashbang-free)
|
|
3
|
+
*
|
|
4
|
+
* This module contains the CLI implementation without a hashbang so that it can
|
|
5
|
+
* be imported by other bin shortcuts (zin/z/zt) without parse errors.
|
|
6
|
+
*/
|
|
7
|
+
export declare function run(): Promise<void>;
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=zintrust-main.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zintrust-main.d.ts","sourceRoot":"","sources":["../../bin/zintrust-main.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAgFH,wBAAsB,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,CAiCzC;AAED,OAAO,EAAE,CAAC"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zintrust CLI - Main Entry Point (hashbang-free)
|
|
3
|
+
*
|
|
4
|
+
* This module contains the CLI implementation without a hashbang so that it can
|
|
5
|
+
* be imported by other bin shortcuts (zin/z/zt) without parse errors.
|
|
6
|
+
*/
|
|
7
|
+
import fs from 'node:fs';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
import { fileURLToPath } from 'node:url';
|
|
10
|
+
const loadPackageVersionFast = () => {
|
|
11
|
+
try {
|
|
12
|
+
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
13
|
+
const packagePath = path.join(here, '../package.json');
|
|
14
|
+
const packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf8'));
|
|
15
|
+
return typeof packageJson.version === 'string' ? packageJson.version : '0.0.0';
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return '0.0.0';
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
const stripLeadingScriptArg = (rawArgs) => {
|
|
22
|
+
if (rawArgs.length === 0)
|
|
23
|
+
return rawArgs;
|
|
24
|
+
const first = rawArgs[0];
|
|
25
|
+
const looksLikeScript = typeof first === 'string' && (first.endsWith('.ts') || first.endsWith('.js'));
|
|
26
|
+
return looksLikeScript ? rawArgs.slice(1) : rawArgs;
|
|
27
|
+
};
|
|
28
|
+
const getArgsFromProcess = () => {
|
|
29
|
+
const rawArgs = process.argv.slice(2);
|
|
30
|
+
return { rawArgs, args: stripLeadingScriptArg(rawArgs) };
|
|
31
|
+
};
|
|
32
|
+
const isVersionRequest = (args) => {
|
|
33
|
+
return args.includes('-v') || args.includes('--version');
|
|
34
|
+
};
|
|
35
|
+
const printFancyVersion = (version) => {
|
|
36
|
+
const framework = 'Zintrust Framework';
|
|
37
|
+
const bannerWidth = 46;
|
|
38
|
+
const env = (process.env['NODE_ENV'] ?? 'development').toString();
|
|
39
|
+
const db = (process.env['DB_CONNECTION'] ?? 'sqlite').toString();
|
|
40
|
+
// Keep this dependency-free and fast; version flags should return instantly.
|
|
41
|
+
// (No logger, no config boot, no CLI registration.)
|
|
42
|
+
console.log('┌' + '─'.repeat(bannerWidth) + '┐');
|
|
43
|
+
console.log(`│ Framework: ${framework.padEnd(bannerWidth - 11)}│`);
|
|
44
|
+
console.log(`│ Version: ${version.padEnd(bannerWidth - 11)}│`);
|
|
45
|
+
console.log(`│ Env: ${env.padEnd(bannerWidth - 11)}│`);
|
|
46
|
+
console.log(`│ Database: ${db.padEnd(bannerWidth - 11)}│`);
|
|
47
|
+
console.log('└' + '─'.repeat(bannerWidth) + '┘');
|
|
48
|
+
console.log();
|
|
49
|
+
};
|
|
50
|
+
const shouldDebugArgs = (rawArgs) => {
|
|
51
|
+
return process.env['ZINTRUST_CLI_DEBUG_ARGS'] === '1' && rawArgs.includes('--verbose');
|
|
52
|
+
};
|
|
53
|
+
const handleCliFatal = async (error, context) => {
|
|
54
|
+
try {
|
|
55
|
+
const { Logger } = await import('../src/config/logger.js');
|
|
56
|
+
Logger.error(context, error);
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
// best-effort logging
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
const { ErrorHandler } = await import('../src/cli/ErrorHandler.js');
|
|
63
|
+
ErrorHandler.handle(error);
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
// best-effort error handling
|
|
67
|
+
}
|
|
68
|
+
process.exit(1);
|
|
69
|
+
};
|
|
70
|
+
export async function run() {
|
|
71
|
+
try {
|
|
72
|
+
// Fast path: print version and exit without bootstrapping the CLI.
|
|
73
|
+
// This keeps `zin -v` / `zin --version` snappy and avoids any debug output.
|
|
74
|
+
const { rawArgs: _rawArgs0, args: args0 } = getArgsFromProcess();
|
|
75
|
+
if (isVersionRequest(args0)) {
|
|
76
|
+
printFancyVersion(loadPackageVersionFast());
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const { EnvFileLoader } = await import('../src/cli/utils/EnvFileLoader.js');
|
|
80
|
+
EnvFileLoader.ensureLoaded();
|
|
81
|
+
const { CLI } = await import('../src/cli/CLI.js');
|
|
82
|
+
const cli = CLI.create();
|
|
83
|
+
// When executing via tsx (e.g. `npx tsx bin/zin.ts ...`), the script path can
|
|
84
|
+
// appear as the first element of `process.argv.slice(2)`. Commander expects
|
|
85
|
+
// args to start at the command name, so we strip a leading script path if present.
|
|
86
|
+
const { rawArgs, args } = getArgsFromProcess();
|
|
87
|
+
if (shouldDebugArgs(rawArgs)) {
|
|
88
|
+
try {
|
|
89
|
+
process.stderr.write(`[zintrust-cli] process.argv=${JSON.stringify(process.argv)}\n`);
|
|
90
|
+
process.stderr.write(`[zintrust-cli] rawArgs=${JSON.stringify(rawArgs)}\n`);
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
// ignore
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
await cli.run(args);
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
await handleCliFatal(error, 'CLI execution failed');
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
* Zintrust Microservices CLI
|
|
4
4
|
* Commands for generating, bundling, and managing microservices
|
|
5
5
|
*/
|
|
6
|
-
import { Logger } from '../src/config/logger';
|
|
7
|
-
import { MicroserviceGenerator } from '../src/microservices/MicroserviceGenerator';
|
|
8
|
-
import { MicroserviceManager } from '../src/microservices/MicroserviceManager';
|
|
9
|
-
import { ServiceBundler } from '../src/microservices/ServiceBundler';
|
|
10
|
-
import { readFileSync } from '../src/node-singletons/fs';
|
|
11
|
-
import { dirname, join } from '../src/node-singletons/path';
|
|
12
|
-
import { fileURLToPath } from '../src/node-singletons/url';
|
|
6
|
+
import { Logger } from '../src/config/logger.js';
|
|
7
|
+
import { MicroserviceGenerator } from '../src/microservices/MicroserviceGenerator.js';
|
|
8
|
+
import { MicroserviceManager } from '../src/microservices/MicroserviceManager.js';
|
|
9
|
+
import { ServiceBundler } from '../src/microservices/ServiceBundler.js';
|
|
10
|
+
import { readFileSync } from '../src/node-singletons/fs.js';
|
|
11
|
+
import { dirname, join } from '../src/node-singletons/path.js';
|
|
12
|
+
import { fileURLToPath } from '../src/node-singletons/url.js';
|
|
13
13
|
import { program } from 'commander';
|
|
14
14
|
const getStringOption = (options, key, fallback) => {
|
|
15
15
|
const value = options[key];
|
package/bin/zintrust.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
#!/usr/bin/env -S
|
|
1
|
+
#!/usr/bin/env -S node --import tsx
|
|
2
2
|
/**
|
|
3
3
|
* Zintrust CLI - Main Entry Point
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
*
|
|
5
|
+
* This bin script is a thin wrapper around the hashbang-free implementation in
|
|
6
|
+
* bin/zintrust-main.ts. Keeping the implementation hashbang-free allows other
|
|
7
|
+
* shortcuts (zin/z/zt) to import it without parse issues.
|
|
7
8
|
*/
|
|
8
9
|
export {};
|
|
9
10
|
//# sourceMappingURL=zintrust.d.ts.map
|
package/bin/zintrust.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zintrust.d.ts","sourceRoot":"","sources":["../../bin/zintrust.ts"],"names":[],"mappings":";AAEA
|
|
1
|
+
{"version":3,"file":"zintrust.d.ts","sourceRoot":"","sources":["../../bin/zintrust.ts"],"names":[],"mappings":";AAEA;;;;;;GAMG;AAKH,OAAO,EAAE,CAAC"}
|
package/bin/zintrust.js
CHANGED
|
@@ -1,90 +1,10 @@
|
|
|
1
|
-
#!/usr/bin/env
|
|
1
|
+
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
3
|
* Zintrust CLI - Main Entry Point
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
*
|
|
5
|
+
* This bin script is a thin wrapper around the hashbang-free implementation in
|
|
6
|
+
* bin/zintrust-main.ts. Keeping the implementation hashbang-free allows other
|
|
7
|
+
* shortcuts (zin/z/zt) to import it without parse issues.
|
|
7
8
|
*/
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
import { fileURLToPath } from 'node:url';
|
|
11
|
-
const loadPackageVersionFast = () => {
|
|
12
|
-
try {
|
|
13
|
-
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
14
|
-
const packagePath = path.join(here, '../package.json');
|
|
15
|
-
const packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf8'));
|
|
16
|
-
return typeof packageJson.version === 'string' ? packageJson.version : '0.0.0';
|
|
17
|
-
}
|
|
18
|
-
catch {
|
|
19
|
-
return '0.0.0';
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
const stripLeadingScriptArg = (rawArgs) => {
|
|
23
|
-
if (rawArgs.length === 0)
|
|
24
|
-
return rawArgs;
|
|
25
|
-
const first = rawArgs[0];
|
|
26
|
-
const looksLikeScript = typeof first === 'string' && (first.endsWith('.ts') || first.endsWith('.js'));
|
|
27
|
-
return looksLikeScript ? rawArgs.slice(1) : rawArgs;
|
|
28
|
-
};
|
|
29
|
-
const getArgsFromProcess = () => {
|
|
30
|
-
const rawArgs = process.argv.slice(2);
|
|
31
|
-
return { rawArgs, args: stripLeadingScriptArg(rawArgs) };
|
|
32
|
-
};
|
|
33
|
-
const isVersionRequest = (args) => {
|
|
34
|
-
return args.includes('-v') || args.includes('--version');
|
|
35
|
-
};
|
|
36
|
-
const shouldDebugArgs = (rawArgs) => {
|
|
37
|
-
return process.env['ZINTRUST_CLI_DEBUG_ARGS'] === '1' && rawArgs.includes('--verbose');
|
|
38
|
-
};
|
|
39
|
-
const handleCliFatal = async (error, context) => {
|
|
40
|
-
try {
|
|
41
|
-
const { Logger } = await import('../src/config/logger');
|
|
42
|
-
Logger.error(context, error);
|
|
43
|
-
}
|
|
44
|
-
catch {
|
|
45
|
-
// best-effort logging
|
|
46
|
-
}
|
|
47
|
-
try {
|
|
48
|
-
const { ErrorHandler } = await import('../src/cli/ErrorHandler');
|
|
49
|
-
ErrorHandler.handle(error);
|
|
50
|
-
}
|
|
51
|
-
catch {
|
|
52
|
-
// best-effort error handling
|
|
53
|
-
}
|
|
54
|
-
process.exit(1);
|
|
55
|
-
};
|
|
56
|
-
async function main() {
|
|
57
|
-
try {
|
|
58
|
-
// Fast path: print version and exit without bootstrapping the CLI.
|
|
59
|
-
// This keeps `zin -v` / `zin --version` snappy and avoids any debug output.
|
|
60
|
-
const { rawArgs: _rawArgs0, args: args0 } = getArgsFromProcess();
|
|
61
|
-
if (isVersionRequest(args0)) {
|
|
62
|
-
process.stdout.write(`${loadPackageVersionFast()}\n`);
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
const { EnvFileLoader } = await import('../src/cli/utils/EnvFileLoader');
|
|
66
|
-
EnvFileLoader.ensureLoaded();
|
|
67
|
-
const { CLI } = await import('../src/cli/CLI');
|
|
68
|
-
const cli = CLI.create();
|
|
69
|
-
// When executing via tsx (e.g. `npx tsx bin/zin.ts ...`), the script path can
|
|
70
|
-
// appear as the first element of `process.argv.slice(2)`. Commander expects
|
|
71
|
-
// args to start at the command name, so we strip a leading script path if present.
|
|
72
|
-
const { rawArgs, args } = getArgsFromProcess();
|
|
73
|
-
if (shouldDebugArgs(rawArgs)) {
|
|
74
|
-
try {
|
|
75
|
-
process.stderr.write(`[zintrust-cli] process.argv=${JSON.stringify(process.argv)}\n`);
|
|
76
|
-
process.stderr.write(`[zintrust-cli] rawArgs=${JSON.stringify(rawArgs)}\n`);
|
|
77
|
-
}
|
|
78
|
-
catch {
|
|
79
|
-
// ignore
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
await cli.run(args);
|
|
83
|
-
}
|
|
84
|
-
catch (error) {
|
|
85
|
-
await handleCliFatal(error, 'CLI execution failed');
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
await main().catch(async (error) => {
|
|
89
|
-
await handleCliFatal(error, 'CLI fatal error');
|
|
90
|
-
});
|
|
9
|
+
import { run } from './zintrust-main.js';
|
|
10
|
+
await run();
|
package/bin/zt.d.ts
CHANGED
package/bin/zt.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zt.d.ts","sourceRoot":"","sources":["../../bin/zt.ts"],"names":[],"mappings":";AAEA;;;GAGG
|
|
1
|
+
{"version":3,"file":"zt.d.ts","sourceRoot":"","sources":["../../bin/zt.ts"],"names":[],"mappings":";AAEA;;;GAGG"}
|
package/bin/zt.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zintrust/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "Production-grade TypeScript backend framework for JavaScript",
|
|
5
5
|
"homepage": "https://zintrust.com",
|
|
6
6
|
"repository": {
|
|
@@ -13,14 +13,24 @@
|
|
|
13
13
|
"type": "module",
|
|
14
14
|
"main": "src/index.js",
|
|
15
15
|
"types": "src/index.d.ts",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./src/index.d.ts",
|
|
19
|
+
"import": "./src/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./node": {
|
|
22
|
+
"types": "./src/node.d.ts",
|
|
23
|
+
"import": "./src/node.js"
|
|
24
|
+
},
|
|
25
|
+
"./package.json": "./package.json"
|
|
26
|
+
},
|
|
16
27
|
"dependencies": {
|
|
17
28
|
"bcrypt": "^6.0.0",
|
|
18
29
|
"better-sqlite3": "^12.5.0",
|
|
19
30
|
"chalk": "^5.6.2",
|
|
20
31
|
"commander": "^14.0.2",
|
|
21
32
|
"inquirer": "^13.1.0",
|
|
22
|
-
"jsonwebtoken": "^9.0.3"
|
|
23
|
-
"tsx": "^4.21.0"
|
|
33
|
+
"jsonwebtoken": "^9.0.3"
|
|
24
34
|
},
|
|
25
35
|
"overrides": {
|
|
26
36
|
"node-forge": "1.3.3",
|
package/public/index.html
CHANGED
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="UTF-8" />
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<meta
|
|
7
|
+
http-equiv="Content-Security-Policy"
|
|
8
|
+
content="script-src-elem 'self' 'unsafe-inline' https://cdn.tailwindcss.com; script-src 'self' 'unsafe-inline' https://cdn.tailwindcss.com;"
|
|
9
|
+
/>
|
|
6
10
|
<title>ZinTrust Documentation</title>
|
|
7
11
|
<link rel="icon" type="image/svg+xml" href="https://zintrust.com/zintrust.svg" />
|
|
8
12
|
<script src="https://cdn.tailwindcss.com"></script>
|
package/src/boot/Application.js
CHANGED
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
* Application - Framework core entry point
|
|
3
3
|
* Handles application lifecycle, booting, and environment
|
|
4
4
|
*/
|
|
5
|
-
import { appConfig } from '../config';
|
|
6
|
-
import { ServiceContainer } from '../container/ServiceContainer';
|
|
7
|
-
import { StartupHealthChecks } from '../health/StartupHealthChecks';
|
|
8
|
-
import { MiddlewareStack } from '../middleware/MiddlewareStack';
|
|
9
|
-
import { Router } from '../routing/Router';
|
|
10
|
-
import { FeatureFlags } from '../config/features';
|
|
11
|
-
import { Logger } from '../config/logger';
|
|
12
|
-
import { StartupConfigValidator } from '../config/StartupConfigValidator';
|
|
13
|
-
import * as path from '../node-singletons/path';
|
|
14
|
-
import { pathToFileURL } from '../node-singletons/url';
|
|
5
|
+
import { appConfig } from '../config/index.js';
|
|
6
|
+
import { ServiceContainer } from '../container/ServiceContainer.js';
|
|
7
|
+
import { StartupHealthChecks } from '../health/StartupHealthChecks.js';
|
|
8
|
+
import { MiddlewareStack } from '../middleware/MiddlewareStack.js';
|
|
9
|
+
import { Router } from '../routing/Router.js';
|
|
10
|
+
import { FeatureFlags } from '../config/features.js';
|
|
11
|
+
import { Logger } from '../config/logger.js';
|
|
12
|
+
import { StartupConfigValidator } from '../config/StartupConfigValidator.js';
|
|
13
|
+
import * as path from '../node-singletons/path.js';
|
|
14
|
+
import { pathToFileURL } from '../node-singletons/url.js';
|
|
15
15
|
const ShutdownManager = Object.freeze({
|
|
16
16
|
create() {
|
|
17
17
|
const hooks = [];
|
|
@@ -85,7 +85,7 @@ const registerRoutes = async (resolvedBasePath, router) => {
|
|
|
85
85
|
mod.registerRoutes(router);
|
|
86
86
|
return;
|
|
87
87
|
}
|
|
88
|
-
const { registerRoutes: registerFrameworkRoutes } = await import('../../routes/api');
|
|
88
|
+
const { registerRoutes: registerFrameworkRoutes } = await import('../../routes/api.js');
|
|
89
89
|
registerFrameworkRoutes(router);
|
|
90
90
|
}
|
|
91
91
|
catch (error) {
|
|
@@ -99,7 +99,7 @@ const initializeArtifactDirectories = async (resolvedBasePath) => {
|
|
|
99
99
|
return;
|
|
100
100
|
let nodeFs;
|
|
101
101
|
try {
|
|
102
|
-
nodeFs = await import('../node-singletons/fs');
|
|
102
|
+
nodeFs = await import('../node-singletons/fs.js');
|
|
103
103
|
}
|
|
104
104
|
catch {
|
|
105
105
|
return;
|
|
@@ -167,7 +167,7 @@ export const Application = Object.freeze({
|
|
|
167
167
|
// Register framework-level shutdown hooks for long-lived resources
|
|
168
168
|
// ConnectionManager may not be initialized; shutdownIfInitialized is safe
|
|
169
169
|
// Use dynamic import without top-level await to avoid transforming the module into an async module
|
|
170
|
-
import('../orm/ConnectionManager')
|
|
170
|
+
import('../orm/ConnectionManager.js')
|
|
171
171
|
.then(({ ConnectionManager }) => {
|
|
172
172
|
shutdownManager.add(async () => ConnectionManager.shutdownIfInitialized());
|
|
173
173
|
})
|
package/src/boot/Server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Server.d.ts","sourceRoot":"","sources":["../../../src/boot/Server.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AASjD,OAAO,KAAK,IAAI,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"Server.d.ts","sourceRoot":"","sources":["../../../src/boot/Server.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AASjD,OAAO,KAAK,IAAI,MAAM,uBAAuB,CAAC;AAK9C,MAAM,WAAW,OAAO;IACtB,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACxB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,aAAa,IAAI,IAAI,CAAC,MAAM,CAAC;CAC9B;AA6MD;;;GAGG;AACH,eAAO,MAAM,MAAM;IACjB;;OAEG;gBACS,YAAY,SAAS,MAAM,SAAS,MAAM,GAAG,OAAO;EA4ChE,CAAC;AAEH,eAAe,MAAM,CAAC"}
|
package/src/boot/Server.js
CHANGED
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
* Server - HTTP Server implementation
|
|
3
3
|
* Uses Node.js built-in HTTP server with no external dependencies
|
|
4
4
|
*/
|
|
5
|
-
import { esmDirname } from '../common/index';
|
|
6
|
-
import { appConfig } from '../config/app';
|
|
7
|
-
import { HTTP_HEADERS, MIME_TYPES } from '../config/constants';
|
|
8
|
-
import { Logger } from '../config/logger';
|
|
9
|
-
import { ErrorFactory } from '../exceptions/ZintrustError';
|
|
10
|
-
import { Request } from '../http/Request';
|
|
11
|
-
import { Response } from '../http/Response';
|
|
12
|
-
import * as fs from '../node-singletons/fs';
|
|
13
|
-
import * as http from '../node-singletons/http';
|
|
14
|
-
import * as path from '../node-singletons/path';
|
|
15
|
-
import { Router } from '../routing/Router';
|
|
5
|
+
import { esmDirname } from '../common/index.js';
|
|
6
|
+
import { appConfig } from '../config/app.js';
|
|
7
|
+
import { HTTP_HEADERS, MIME_TYPES } from '../config/constants.js';
|
|
8
|
+
import { Logger } from '../config/logger.js';
|
|
9
|
+
import { ErrorFactory } from '../exceptions/ZintrustError.js';
|
|
10
|
+
import { Request } from '../http/Request.js';
|
|
11
|
+
import { Response } from '../http/Response.js';
|
|
12
|
+
import * as fs from '../node-singletons/fs.js';
|
|
13
|
+
import * as http from '../node-singletons/http.js';
|
|
14
|
+
import * as path from '../node-singletons/path.js';
|
|
15
|
+
import { Router } from '../routing/Router.js';
|
|
16
16
|
const MIME_TYPES_MAP = {
|
|
17
17
|
'.html': MIME_TYPES.HTML,
|
|
18
18
|
'.js': MIME_TYPES.JS,
|
|
@@ -47,40 +47,42 @@ const getFrameworkPublicRoots = () => {
|
|
|
47
47
|
const packageRoot = findPackageRoot(thisDir);
|
|
48
48
|
return [
|
|
49
49
|
path.join(packageRoot, 'dist/public'),
|
|
50
|
-
path.join(packageRoot, 'docs-website/public'),
|
|
51
50
|
path.join(packageRoot, 'public'), // Fallback for shipped package
|
|
52
51
|
];
|
|
53
52
|
};
|
|
54
53
|
const getDocsPublicRoot = () => {
|
|
55
|
-
const isProduction = appConfig.isProduction();
|
|
56
54
|
// First try app-local roots (developer app override), then fall back to framework-shipped assets.
|
|
57
|
-
const appRoots =
|
|
58
|
-
? [path.join(process.cwd(), 'public')]
|
|
59
|
-
: [path.join(process.cwd(), 'docs-website/public')];
|
|
55
|
+
const appRoots = [path.join(process.cwd(), 'public')];
|
|
60
56
|
const candidates = [...appRoots, ...getFrameworkPublicRoots()];
|
|
57
|
+
const hasDocsEntrypoint = (root) => {
|
|
58
|
+
const directIndex = path.join(root, 'index.html');
|
|
59
|
+
return fs.existsSync(directIndex);
|
|
60
|
+
};
|
|
61
|
+
// Prefer a root that actually contains docs assets.
|
|
62
|
+
for (const candidate of candidates) {
|
|
63
|
+
if (fs.existsSync(candidate) && hasDocsEntrypoint(candidate))
|
|
64
|
+
return candidate;
|
|
65
|
+
}
|
|
66
|
+
// Fall back to the first existing directory.
|
|
61
67
|
for (const candidate of candidates) {
|
|
62
68
|
if (fs.existsSync(candidate))
|
|
63
69
|
return candidate;
|
|
64
70
|
}
|
|
65
|
-
return
|
|
71
|
+
return candidates[0];
|
|
66
72
|
};
|
|
67
|
-
const stripLeadingSlashes = (value) => value.replace(/^\/+/, '');
|
|
68
73
|
/**
|
|
69
74
|
* Map URL path to physical file path
|
|
70
75
|
*/
|
|
71
76
|
const mapStaticPath = (urlPath) => {
|
|
72
77
|
const publicRoot = getDocsPublicRoot();
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
return rest === '' ? publicRoot : path.join(publicRoot, rest);
|
|
82
|
-
}
|
|
83
|
-
return '';
|
|
78
|
+
const normalize = (p) => (p.startsWith('/') ? p.slice(1) : p);
|
|
79
|
+
// /doc acts as a mount for the docs/static site.
|
|
80
|
+
if (urlPath === '/doc' || urlPath === '/doc/')
|
|
81
|
+
return publicRoot;
|
|
82
|
+
if (urlPath.startsWith('/doc/'))
|
|
83
|
+
return path.join(publicRoot, normalize(urlPath.slice('/doc/'.length)));
|
|
84
|
+
// Also serve app-local static files from the same public root.
|
|
85
|
+
return path.join(publicRoot, normalize(urlPath));
|
|
84
86
|
};
|
|
85
87
|
/**
|
|
86
88
|
* Send static file to response
|
|
@@ -99,13 +101,6 @@ const sendStaticFile = (filePath, response) => {
|
|
|
99
101
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
100
102
|
const serveStatic = async (request, response) => {
|
|
101
103
|
const urlPath = request.getPath();
|
|
102
|
-
// Canonicalize docs base path (VitePress expects trailing slash for correct relative resolution)
|
|
103
|
-
if (urlPath === '/doc') {
|
|
104
|
-
response.setStatus(302);
|
|
105
|
-
response.setHeader('Location', '/doc/');
|
|
106
|
-
response.send('');
|
|
107
|
-
return true;
|
|
108
|
-
}
|
|
109
104
|
let filePath = mapStaticPath(urlPath);
|
|
110
105
|
if (!filePath)
|
|
111
106
|
return false;
|
|
@@ -146,8 +141,8 @@ const getContentSecurityPolicyForPath = (requestPath) => {
|
|
|
146
141
|
if (!requestPath.startsWith('/doc'))
|
|
147
142
|
return baseCsp;
|
|
148
143
|
return ("default-src 'self'; " +
|
|
149
|
-
"script-src 'self' 'unsafe-inline' 'unsafe-eval'; " +
|
|
150
|
-
"script-src-elem 'self' 'unsafe-inline'; " +
|
|
144
|
+
"script-src 'self' 'unsafe-inline' 'unsafe-eval' https://cdn.tailwindcss.com; " +
|
|
145
|
+
"script-src-elem 'self' 'unsafe-inline' https://cdn.tailwindcss.com; " +
|
|
151
146
|
"style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; " +
|
|
152
147
|
"style-src-elem 'self' 'unsafe-inline' https://fonts.googleapis.com; " +
|
|
153
148
|
"img-src 'self' data: https:; " +
|
|
@@ -209,11 +204,15 @@ export const Server = Object.freeze({
|
|
|
209
204
|
const serverPort = port ?? appConfig.port;
|
|
210
205
|
const serverHost = host ?? appConfig.host;
|
|
211
206
|
const httpServer = http.createServer(async (req, res) => handleRequest(app, req, res));
|
|
207
|
+
const sockets = new Set();
|
|
208
|
+
httpServer.on('connection', (socket) => {
|
|
209
|
+
sockets.add(socket);
|
|
210
|
+
socket.on('close', () => sockets.delete(socket));
|
|
211
|
+
});
|
|
212
212
|
return {
|
|
213
213
|
async listen() {
|
|
214
214
|
return new Promise((resolve) => {
|
|
215
215
|
httpServer.listen(serverPort, serverHost, () => {
|
|
216
|
-
Logger.info(`Zintrust server running at http://${serverHost}:${serverPort}`);
|
|
217
216
|
resolve();
|
|
218
217
|
});
|
|
219
218
|
});
|
|
@@ -224,6 +223,15 @@ export const Server = Object.freeze({
|
|
|
224
223
|
Logger.info('Zintrust server stopped');
|
|
225
224
|
resolve();
|
|
226
225
|
});
|
|
226
|
+
// Ensure keep-alive / hanging connections don't block shutdown
|
|
227
|
+
for (const socket of sockets) {
|
|
228
|
+
try {
|
|
229
|
+
socket.destroy();
|
|
230
|
+
}
|
|
231
|
+
catch {
|
|
232
|
+
// best-effort
|
|
233
|
+
}
|
|
234
|
+
}
|
|
227
235
|
});
|
|
228
236
|
},
|
|
229
237
|
getHttpServer() {
|