@solidxai/core 0.1.10-beta.12 → 0.1.10-beta.15
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/dist/helpers/bootstrap.helper.d.ts +1 -0
- package/dist/helpers/bootstrap.helper.d.ts.map +1 -1
- package/dist/helpers/bootstrap.helper.js +6 -3
- package/dist/helpers/bootstrap.helper.js.map +1 -1
- package/dist/winston.logger.d.ts +5 -0
- package/dist/winston.logger.d.ts.map +1 -1
- package/dist/winston.logger.js +6 -4
- package/dist/winston.logger.js.map +1 -1
- package/package.json +1 -1
- package/src/helpers/bootstrap.helper.ts +13 -6
- package/src/winston.logger.ts +5 -7
|
@@ -8,6 +8,7 @@ export interface SolidBootstrapOptions {
|
|
|
8
8
|
globalPrefix?: string;
|
|
9
9
|
swagger?: SolidSwaggerOptions | false;
|
|
10
10
|
permissionsPolicyOverrides?: Partial<PermissionsPolicyConfig>;
|
|
11
|
+
verboseBootstrap?: boolean;
|
|
11
12
|
}
|
|
12
13
|
export declare function bootstrapSolidApp(appModuleFactory: () => Promise<any>, options?: SolidBootstrapOptions): Promise<void>;
|
|
13
14
|
export declare function bootstrapSolidCli(appModuleFactory: () => Promise<any>): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap.helper.d.ts","sourceRoot":"","sources":["../../src/helpers/bootstrap.helper.ts"],"names":[],"mappings":"AAcA,OAAO,EAAmE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAyB7H,MAAM,WAAW,mBAAmB;IAClC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,qBAAqB;IAEpC,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB,OAAO,CAAC,EAAE,mBAAmB,GAAG,KAAK,CAAC;IAEtC,0BAA0B,CAAC,EAAE,OAAO,CAAC,uBAAuB,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"bootstrap.helper.d.ts","sourceRoot":"","sources":["../../src/helpers/bootstrap.helper.ts"],"names":[],"mappings":"AAcA,OAAO,EAAmE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAyB7H,MAAM,WAAW,mBAAmB;IAClC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,qBAAqB;IAEpC,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB,OAAO,CAAC,EAAE,mBAAmB,GAAG,KAAK,CAAC;IAEtC,0BAA0B,CAAC,EAAE,OAAO,CAAC,uBAAuB,CAAC,CAAC;IAE9D,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAcD,wBAAsB,iBAAiB,CACrC,gBAAgB,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,EACpC,OAAO,GAAE,qBAA0B,GAClC,OAAO,CAAC,IAAI,CAAC,CAwHf;AAgBD,wBAAsB,iBAAiB,CACrC,gBAAgB,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,GACnC,OAAO,CAAC,IAAI,CAAC,CAwCf"}
|
|
@@ -36,10 +36,11 @@ function registerGlobalProcessHandlers() {
|
|
|
36
36
|
}
|
|
37
37
|
async function bootstrapSolidApp(appModuleFactory, options = {}) {
|
|
38
38
|
registerGlobalProcessHandlers();
|
|
39
|
-
const { globalPrefix = 'api', swagger = {}, permissionsPolicyOverrides = {} } = options;
|
|
39
|
+
const { globalPrefix = 'api', swagger = {}, permissionsPolicyOverrides = {}, verboseBootstrap = false } = options;
|
|
40
|
+
const startTime = Date.now();
|
|
40
41
|
const appModule = await appModuleFactory();
|
|
41
42
|
const app = await core_1.NestFactory.create(appModule, {
|
|
42
|
-
logger: nest_winston_1.WinstonModule.createLogger(winston_logger_1.
|
|
43
|
+
logger: nest_winston_1.WinstonModule.createLogger({ ...(0, winston_logger_1.createWinstonLoggerConfig)(), level: verboseBootstrap ? 'debug' : 'error' }),
|
|
43
44
|
});
|
|
44
45
|
const apiEnabled = (0, environment_helper_1.parseBooleanEnv)('API_ENABLED', true);
|
|
45
46
|
if (!apiEnabled) {
|
|
@@ -67,7 +68,6 @@ async function bootstrapSolidApp(appModuleFactory, options = {}) {
|
|
|
67
68
|
res.setHeader('Permissions-Policy', (0, security_helper_1.buildPermissionsPolicyHeader)(permissionsPolicyOverrides));
|
|
68
69
|
next();
|
|
69
70
|
});
|
|
70
|
-
app.useLogger(app.get(nest_winston_1.WINSTON_MODULE_NEST_PROVIDER));
|
|
71
71
|
const port = process.env.PORT || 3000;
|
|
72
72
|
if (globalPrefix) {
|
|
73
73
|
app.setGlobalPrefix(globalPrefix);
|
|
@@ -111,6 +111,9 @@ async function bootstrapSolidApp(appModuleFactory, options = {}) {
|
|
|
111
111
|
types.setTypeParser(types.builtins.INT8, (val) => parseInt(val));
|
|
112
112
|
app.useWebSocketAdapter(new platform_ws_1.WsAdapter(app));
|
|
113
113
|
await app.listen(port);
|
|
114
|
+
app.useLogger(app.get(nest_winston_1.WINSTON_MODULE_NEST_PROVIDER));
|
|
115
|
+
const elapsed = ((Date.now() - startTime) / 1000).toFixed(2);
|
|
116
|
+
app.get(nest_winston_1.WINSTON_MODULE_NEST_PROVIDER).log(`\x1b[32mServer started on port ${port} in ${elapsed}s\x1b[0m`, 'Bootstrap');
|
|
114
117
|
}
|
|
115
118
|
async function bootstrapSolidCli(appModuleFactory) {
|
|
116
119
|
registerGlobalProcessHandlers();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap.helper.js","sourceRoot":"","sources":["../../src/helpers/bootstrap.helper.ts"],"names":[],"mappings":";;;;;AAkEA,8CAsHC;AAgBD,8CA0CC;AAlPD,2CAAgD;AAChD,uCAA2C;AAC3C,qDAAgD;AAChD,6CAAiE;AAEjE,oDAA4B;AAC5B,4CAAo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C;AAClB,CAAC","sourcesContent":["import { ValidationPipe } from '@nestjs/common';\nimport { NestFactory } from '@nestjs/core';\nimport { WsAdapter } from '@nestjs/platform-ws';\nimport { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';\nimport { NextFunction, Request, Response } from 'express';\nimport helmet from 'helmet';\nimport qs from 'qs';\nimport { existsSync } from 'fs';\nimport { resolve } from 'path';\nimport { WINSTON_MODULE_NEST_PROVIDER, WinstonModule } from 'nest-winston';\nimport { CommandFactory } from 'nest-commander';\nimport { WinstonLoggerConfig } from '../winston.logger';\nimport { WrapResponseInterceptor } from '../interceptors/wrap-response.interceptor';\nimport { buildDefaultCorsOptions } from './cors.helper';\nimport { buildDefaultSecurityHeaderOptions, buildPermissionsPolicyHeader, PermissionsPolicyConfig } from './security.helper';\nimport { parseBooleanEnv } from './environment.helper';\n\n// ---- Shared process handlers ----\n\nfunction registerGlobalProcessHandlers() {\n process.on('unhandledRejection', (reason, promise) => {\n console.error('Unhandled Rejection at:', promise, 'reason:', reason);\n });\n\n process.on('uncaughtException', (err) => {\n console.error('Uncaught Exception thrown:', err);\n });\n\n // Suppress pg deprecation warning caused by TypeORM's internal query scheduling\n process.on('warning', (warning) => {\n if (warning.name === 'DeprecationWarning' && (warning.message.includes('client.query()') || warning.message.includes('punycode'))) {\n return;\n }\n console.warn(warning);\n });\n}\n\n// ---- HTTP server bootstrap ----\n\nexport interface SolidSwaggerOptions {\n title?: string;\n description?: string;\n version?: string;\n}\n\nexport interface SolidBootstrapOptions {\n /** Global API prefix. Defaults to 'api'. Set to '' to disable. */\n globalPrefix?: string;\n /** Swagger configuration. Set to false to disable Swagger entirely. */\n swagger?: SolidSwaggerOptions | false;\n /** Permissions-Policy header overrides (merged with defaults). */\n permissionsPolicyOverrides?: Partial<PermissionsPolicyConfig>;\n}\n\n/**\n * Bootstraps a SolidX NestJS HTTP application with sensible defaults:\n * security headers, CORS, Winston logger, ValidationPipe,\n * WrapResponseInterceptor, qs deep query parsing, Swagger, and the\n * pg BIGINT type parser.\n *\n * @example\n * // main.ts\n * bootstrapSolidApp(() => AppModule.forRoot(), {\n * swagger: { title: 'My API', description: 'My API description' },\n * });\n */\nexport async function bootstrapSolidApp(\n appModuleFactory: () => Promise<any>,\n options: SolidBootstrapOptions = {},\n): Promise<void> {\n registerGlobalProcessHandlers();\n\n const { globalPrefix = 'api', swagger = {}, permissionsPolicyOverrides = {} } = options;\n\n const appModule = await appModuleFactory();\n const app = await NestFactory.create(appModule, {\n logger: WinstonModule.createLogger(WinstonLoggerConfig),\n });\n\n const apiEnabled = parseBooleanEnv('API_ENABLED', true);\n\n if (!apiEnabled) {\n await app.init();\n app\n .get(WINSTON_MODULE_NEST_PROVIDER)\n .log('API server disabled via API_ENABLED=false. Skipping HTTP listen.', 'Bootstrap');\n return;\n }\n\n // Health check at root path\n const server = app.getHttpAdapter().getInstance();\n server.get('/', (_req, res) => res.status(200).send('SOLID OK'));\n\n // Security headers\n app.use(helmet(buildDefaultSecurityHeaderOptions()));\n\n // Nest's Swagger UI HTML injects inline styles; keep CSP strict elsewhere.\n const isSwaggerPath = (path: string) =>\n path === '/docs' ||\n path === '/docs/' ||\n path.startsWith('/docs/') ||\n path === '/docs-json' ||\n path === '/docs-yaml';\n\n app.use((req: Request, res: Response, next: NextFunction) => {\n if (isSwaggerPath(req.path)) {\n res.removeHeader('Content-Security-Policy');\n }\n next();\n });\n\n // Permissions-Policy header\n app.use((_req: Request, res: Response, next: NextFunction) => {\n res.setHeader('Permissions-Policy', buildPermissionsPolicyHeader(permissionsPolicyOverrides));\n next();\n });\n\n // Winston logger\n app.useLogger(app.get(WINSTON_MODULE_NEST_PROVIDER));\n\n const port = process.env.PORT || 3000;\n\n if (globalPrefix) {\n app.setGlobalPrefix(globalPrefix);\n }\n\n // qs-based deep query parsing (dot notation, nested objects, arrays)\n app.use((req: Request, _res: Response, next: NextFunction) => {\n if (req.query) {\n req.query = qs.parse(req.url.split('?')[1], {\n allowDots: true,\n depth: 20,\n arrayLimit: 100,\n });\n }\n next();\n });\n\n // Global ValidationPipe\n app.useGlobalPipes(\n new ValidationPipe({\n transform: true,\n transformOptions: { enableImplicitConversion: true },\n }),\n );\n\n // Swagger\n if (swagger !== false) {\n const { title = process.env.SOLID_APP_NAME, description = process.env.SOLID_APP_DESCRIPTION, version = '1.0' } = swagger;\n const swaggerConfig = new DocumentBuilder()\n .setTitle(title)\n .setDescription(description)\n .setVersion(version)\n .setExternalDoc('Postman Collection', '/docs-json')\n .addBearerAuth(\n {\n description: 'Please enter token in following format: Bearer <JWT>',\n name: 'Authorization',\n bearerFormat: 'Bearer',\n scheme: 'Bearer',\n type: 'http',\n in: 'Header',\n },\n 'jwt',\n )\n .build();\n const document = SwaggerModule.createDocument(app, swaggerConfig);\n SwaggerModule.setup('/docs', app, document);\n }\n\n // Global interceptor\n app.useGlobalInterceptors(new WrapResponseInterceptor());\n\n // CORS\n app.enableCors(buildDefaultCorsOptions());\n\n // Fix pg returning BIGINT columns as strings\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const types = require('pg').types;\n types.setTypeParser(types.builtins.INT8, (val: string) => parseInt(val));\n\n app.useWebSocketAdapter(new WsAdapter(app));\n\n await app.listen(port);\n}\n\n// ---- CLI bootstrap ----\n\n/**\n * Bootstraps a SolidX NestJS CLI application using nest-commander.\n * Handles verbose flag stripping, project root validation, and clean process exit.\n *\n * @example\n * // main-cli.ts\n * #!/usr/bin/env node\n * import { bootstrapSolidCli } from '@solidxai/core';\n * import { AppModule } from './app.module';\n *\n * bootstrapSolidCli(() => AppModule.forRoot());\n */\nexport async function bootstrapSolidCli(\n appModuleFactory: () => Promise<any>,\n): Promise<void> {\n registerGlobalProcessHandlers();\n\n process.on('exit', (code) => {\n if (code !== 0) {\n console.error(`Exiting with error status code: ${code}`);\n }\n });\n\n // Validate that cwd is a valid Solid API project\n const packageJsonPath = resolve(process.cwd(), 'package.json');\n if (!existsSync(packageJsonPath)) {\n console.error('Does not seem to be a valid solid-api project.');\n console.error('Exit reason: missing package.json in the current directory.');\n process.exit(1);\n }\n\n // Strip --verbose / -v before nest-commander processes argv\n const showLogs = process.argv.includes('--verbose') || process.argv.includes('-v');\n for (const flag of ['--verbose', '-v']) {\n const idx = process.argv.indexOf(flag);\n if (idx !== -1) process.argv.splice(idx, 1);\n }\n\n const appModule = await appModuleFactory();\n process.env.SOLID_CLI_RUNNING = 'true';\n\n // @ts-ignore\n const app = await CommandFactory.createWithoutRunning(appModule, {\n logger: showLogs ? ['debug', 'error', 'fatal', 'log', 'verbose', 'warn'] : false,\n });\n\n try {\n await CommandFactory.runApplication(app);\n } catch (e) {\n console.error('CLI exited abruptly due to an error:', e);\n process.exit(1);\n }\n\n process.exit(0);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"bootstrap.helper.js","sourceRoot":"","sources":["../../src/helpers/bootstrap.helper.ts"],"names":[],"mappings":";;;;;AAoEA,8CA2HC;AAgBD,8CA0CC;AAzPD,2CAAgD;AAChD,uCAA2C;AAC3C,qDAAgD;AAChD,6CAAiE;AAEjE,oDAA4B;AAC5B,4CAAoB;AACpB,2BAAgC;AAChC,+BAA+B;AAC/B,+CAA2E;AAC3E,mDAAgD;AAChD,sDAA8D;AAC9D,yFAAoF;AACpF,+CAAwD;AACxD,uDAA6H;AAC7H,6DAAuD;AAIvD,SAAS,6BAA6B;IACpC,OAAO,CAAC,EAAE,CAAC,oBAAoB,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE;QACnD,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;IACvE,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,EAAE,CAAC,mBAAmB,EAAE,CAAC,GAAG,EAAE,EAAE;QACtC,OAAO,CAAC,KAAK,CAAC,4BAA4B,EAAE,GAAG,CAAC,CAAC;IACnD,CAAC,CAAC,CAAC;IAGH,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,OAAO,EAAE,EAA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AAC,CAAC;QAC7E,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAGD,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IACnF,KAAK,MAAM,IAAI,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,EAAE,CAAC;QACvC,MAAM,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACvC,IAAI,GAAG,KAAK,CAAC,CAAC;YAAE,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;IAC9C,CAAC;IAED,MAAM,SAAS,GAAG,MAAM,gBAAgB,EAAE,CAAC;IAC3C,OAAO,CAAC,GAAG,CAAC,iBAAiB,GAAG,MAAM,CAAC;IAGvC,MAAM,GAAG,GAAG,MAAM,+BAAc,CAAC,oBAAoB,CAAC,SAAS,EAAE;QAC/D,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK;KACjF,CAAC,CAAC;IAEH,IAAI,CAAC;QACH,MAAM,+BAAc,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;IAC3C,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,CAAC,KAAK,CAAC,sCAAsC,EAAE,CAAC,CAAC,CAAC;QACzD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC","sourcesContent":["import { ValidationPipe } from '@nestjs/common';\nimport { NestFactory } from '@nestjs/core';\nimport { WsAdapter } from '@nestjs/platform-ws';\nimport { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';\nimport { NextFunction, Request, Response } from 'express';\nimport helmet from 'helmet';\nimport qs from 'qs';\nimport { existsSync } from 'fs';\nimport { resolve } from 'path';\nimport { WINSTON_MODULE_NEST_PROVIDER, WinstonModule } from 'nest-winston';\nimport { CommandFactory } from 'nest-commander';\nimport { createWinstonLoggerConfig } from '../winston.logger';\nimport { WrapResponseInterceptor } from '../interceptors/wrap-response.interceptor';\nimport { buildDefaultCorsOptions } from './cors.helper';\nimport { buildDefaultSecurityHeaderOptions, buildPermissionsPolicyHeader, PermissionsPolicyConfig } from './security.helper';\nimport { parseBooleanEnv } from './environment.helper';\n\n// ---- Shared process handlers ----\n\nfunction registerGlobalProcessHandlers() {\n process.on('unhandledRejection', (reason, promise) => {\n console.error('Unhandled Rejection at:', promise, 'reason:', reason);\n });\n\n process.on('uncaughtException', (err) => {\n console.error('Uncaught Exception thrown:', err);\n });\n\n // Suppress pg deprecation warning caused by TypeORM's internal query scheduling\n process.on('warning', (warning) => {\n if (warning.name === 'DeprecationWarning' && (warning.message.includes('client.query()') || warning.message.includes('punycode'))) {\n return;\n }\n console.warn(warning);\n });\n}\n\n// ---- HTTP server bootstrap ----\n\nexport interface SolidSwaggerOptions {\n title?: string;\n description?: string;\n version?: string;\n}\n\nexport interface SolidBootstrapOptions {\n /** Global API prefix. Defaults to 'api'. Set to '' to disable. */\n globalPrefix?: string;\n /** Swagger configuration. Set to false to disable Swagger entirely. */\n swagger?: SolidSwaggerOptions | false;\n /** Permissions-Policy header overrides (merged with defaults). */\n permissionsPolicyOverrides?: Partial<PermissionsPolicyConfig>;\n /** Show full NestJS init logs during bootstrap (route mapping, module deps, pollers). Defaults to false. */\n verboseBootstrap?: boolean;\n}\n\n/**\n * Bootstraps a SolidX NestJS HTTP application with sensible defaults:\n * security headers, CORS, Winston logger, ValidationPipe,\n * WrapResponseInterceptor, qs deep query parsing, Swagger, and the\n * pg BIGINT type parser.\n *\n * @example\n * // main.ts\n * bootstrapSolidApp(() => AppModule.forRoot(), {\n * swagger: { title: 'My API', description: 'My API description' },\n * });\n */\nexport async function bootstrapSolidApp(\n appModuleFactory: () => Promise<any>,\n options: SolidBootstrapOptions = {},\n): Promise<void> {\n registerGlobalProcessHandlers();\n\n const { globalPrefix = 'api', swagger = {}, permissionsPolicyOverrides = {}, verboseBootstrap = false } = options;\n\n const startTime = Date.now();\n const appModule = await appModuleFactory();\n const app = await NestFactory.create(appModule, {\n logger: WinstonModule.createLogger({ ...createWinstonLoggerConfig(), level: verboseBootstrap ? 'debug' : 'error' }),\n });\n\n const apiEnabled = parseBooleanEnv('API_ENABLED', true);\n\n if (!apiEnabled) {\n await app.init();\n app\n .get(WINSTON_MODULE_NEST_PROVIDER)\n .log('API server disabled via API_ENABLED=false. Skipping HTTP listen.', 'Bootstrap');\n return;\n }\n\n // Health check at root path\n const server = app.getHttpAdapter().getInstance();\n server.get('/', (_req, res) => res.status(200).send('SOLID OK'));\n\n // Security headers\n app.use(helmet(buildDefaultSecurityHeaderOptions()));\n\n // Nest's Swagger UI HTML injects inline styles; keep CSP strict elsewhere.\n const isSwaggerPath = (path: string) =>\n path === '/docs' ||\n path === '/docs/' ||\n path.startsWith('/docs/') ||\n path === '/docs-json' ||\n path === '/docs-yaml';\n\n app.use((req: Request, res: Response, next: NextFunction) => {\n if (isSwaggerPath(req.path)) {\n res.removeHeader('Content-Security-Policy');\n }\n next();\n });\n\n // Permissions-Policy header\n app.use((_req: Request, res: Response, next: NextFunction) => {\n res.setHeader('Permissions-Policy', buildPermissionsPolicyHeader(permissionsPolicyOverrides));\n next();\n });\n\n const port = process.env.PORT || 3000;\n\n if (globalPrefix) {\n app.setGlobalPrefix(globalPrefix);\n }\n\n // qs-based deep query parsing (dot notation, nested objects, arrays)\n app.use((req: Request, _res: Response, next: NextFunction) => {\n if (req.query) {\n req.query = qs.parse(req.url.split('?')[1], {\n allowDots: true,\n depth: 20,\n arrayLimit: 100,\n });\n }\n next();\n });\n\n // Global ValidationPipe\n app.useGlobalPipes(\n new ValidationPipe({\n transform: true,\n transformOptions: { enableImplicitConversion: true },\n }),\n );\n\n // Swagger\n if (swagger !== false) {\n const { title = process.env.SOLID_APP_NAME, description = process.env.SOLID_APP_DESCRIPTION, version = '1.0' } = swagger;\n const swaggerConfig = new DocumentBuilder()\n .setTitle(title)\n .setDescription(description)\n .setVersion(version)\n .setExternalDoc('Postman Collection', '/docs-json')\n .addBearerAuth(\n {\n description: 'Please enter token in following format: Bearer <JWT>',\n name: 'Authorization',\n bearerFormat: 'Bearer',\n scheme: 'Bearer',\n type: 'http',\n in: 'Header',\n },\n 'jwt',\n )\n .build();\n const document = SwaggerModule.createDocument(app, swaggerConfig);\n SwaggerModule.setup('/docs', app, document);\n }\n\n // Global interceptor\n app.useGlobalInterceptors(new WrapResponseInterceptor());\n\n // CORS\n app.enableCors(buildDefaultCorsOptions());\n\n // Fix pg returning BIGINT columns as strings\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const types = require('pg').types;\n types.setTypeParser(types.builtins.INT8, (val: string) => parseInt(val));\n\n app.useWebSocketAdapter(new WsAdapter(app));\n\n await app.listen(port);\n\n // Wire up Winston as the runtime logger only AFTER listen — this suppresses all\n // framework init noise (route mapping, module deps, onModuleInit) during boot.\n app.useLogger(app.get(WINSTON_MODULE_NEST_PROVIDER));\n\n const elapsed = ((Date.now() - startTime) / 1000).toFixed(2);\n app.get(WINSTON_MODULE_NEST_PROVIDER).log(`\\x1b[32mServer started on port ${port} in ${elapsed}s\\x1b[0m`, 'Bootstrap');\n}\n\n// ---- CLI bootstrap ----\n\n/**\n * Bootstraps a SolidX NestJS CLI application using nest-commander.\n * Handles verbose flag stripping, project root validation, and clean process exit.\n *\n * @example\n * // main-cli.ts\n * #!/usr/bin/env node\n * import { bootstrapSolidCli } from '@solidxai/core';\n * import { AppModule } from './app.module';\n *\n * bootstrapSolidCli(() => AppModule.forRoot());\n */\nexport async function bootstrapSolidCli(\n appModuleFactory: () => Promise<any>,\n): Promise<void> {\n registerGlobalProcessHandlers();\n\n process.on('exit', (code) => {\n if (code !== 0) {\n console.error(`Exiting with error status code: ${code}`);\n }\n });\n\n // Validate that cwd is a valid Solid API project\n const packageJsonPath = resolve(process.cwd(), 'package.json');\n if (!existsSync(packageJsonPath)) {\n console.error('Does not seem to be a valid solid-api project.');\n console.error('Exit reason: missing package.json in the current directory.');\n process.exit(1);\n }\n\n // Strip --verbose / -v before nest-commander processes argv\n const showLogs = process.argv.includes('--verbose') || process.argv.includes('-v');\n for (const flag of ['--verbose', '-v']) {\n const idx = process.argv.indexOf(flag);\n if (idx !== -1) process.argv.splice(idx, 1);\n }\n\n const appModule = await appModuleFactory();\n process.env.SOLID_CLI_RUNNING = 'true';\n\n // @ts-ignore\n const app = await CommandFactory.createWithoutRunning(appModule, {\n logger: showLogs ? ['debug', 'error', 'fatal', 'log', 'verbose', 'warn'] : false,\n });\n\n try {\n await CommandFactory.runApplication(app);\n } catch (e) {\n console.error('CLI exited abruptly due to an error:', e);\n process.exit(1);\n }\n\n process.exit(0);\n}\n"]}
|
package/dist/winston.logger.d.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { Logger as TypeORMLogger, QueryRunner } from 'typeorm';
|
|
2
2
|
import { Logger } from 'winston';
|
|
3
3
|
import * as winston from 'winston';
|
|
4
|
+
export declare const createWinstonLoggerConfig: () => {
|
|
5
|
+
level: string;
|
|
6
|
+
format: winston.Logform.Format;
|
|
7
|
+
transports: (winston.transports.ConsoleTransportInstance | winston.transports.FileTransportInstance)[];
|
|
8
|
+
};
|
|
4
9
|
export declare const WinstonLoggerConfig: {
|
|
5
10
|
level: string;
|
|
6
11
|
format: winston.Logform.Format;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"winston.logger.d.ts","sourceRoot":"","sources":["../src/winston.logger.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,IAAI,aAAa,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAC/D,OAAO,EAA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HANGED
|
@@ -45,14 +45,14 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
45
45
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
46
46
|
};
|
|
47
47
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
-
exports.WinstonTypeORMLogger = exports.WinstonLoggerConfig = void 0;
|
|
48
|
+
exports.WinstonTypeORMLogger = exports.WinstonLoggerConfig = exports.createWinstonLoggerConfig = void 0;
|
|
49
49
|
const winston_1 = require("winston");
|
|
50
50
|
const common_1 = require("@nestjs/common");
|
|
51
51
|
const nest_winston_1 = require("nest-winston");
|
|
52
52
|
const winston = __importStar(require("winston"));
|
|
53
53
|
const disallow_in_production_decorator_1 = require("./decorators/disallow-in-production.decorator");
|
|
54
|
-
|
|
55
|
-
level: process.env.LOG_LEVEL || (process.env.ENV === disallow_in_production_decorator_1.Environment.Production ? '
|
|
54
|
+
const createWinstonLoggerConfig = () => ({
|
|
55
|
+
level: process.env.LOG_LEVEL || (process.env.ENV === disallow_in_production_decorator_1.Environment.Production ? 'warn' : 'info'),
|
|
56
56
|
format: winston.format.combine(winston.format.timestamp(), winston.format.errors({ stack: true }), winston.format.printf(({ level, message, timestamp }) => {
|
|
57
57
|
if (!message) {
|
|
58
58
|
return `[${timestamp}] ${level.toUpperCase()}: (No message provided)`;
|
|
@@ -73,7 +73,9 @@ exports.WinstonLoggerConfig = {
|
|
|
73
73
|
level: 'error',
|
|
74
74
|
}),
|
|
75
75
|
],
|
|
76
|
-
};
|
|
76
|
+
});
|
|
77
|
+
exports.createWinstonLoggerConfig = createWinstonLoggerConfig;
|
|
78
|
+
exports.WinstonLoggerConfig = (0, exports.createWinstonLoggerConfig)();
|
|
77
79
|
let WinstonTypeORMLogger = class WinstonTypeORMLogger {
|
|
78
80
|
constructor(logger) {
|
|
79
81
|
this.logger = logger;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"winston.logger.js","sourceRoot":"","sources":["../src/winston.logger.ts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AAI,CAAC,iBAAiB,OAAO,EAAE,CAAC,CAAC;IACjD,CAAC;IAED,YAAY,CAAC,OAAe,EAAE,WAAyB;QACnD,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,OAAO,EAAE,CAAC,CAAC;IAC9C,CAAC;IAED,GAAG,CAAC,KAAwC,EAAE,OAAY;QACtD,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC;IAChC,CAAC;CACJ,CAAA;AA5BY,oDAAoB;+BAApB,oBAAoB;IAChB,WAAA,IAAA,eAAM,EAAC,sCAAuB,CAAC,CAAA;qCAA0B,gBAAM;GADnE,oBAAoB,CA4BhC","sourcesContent":["\nimport { Logger as TypeORMLogger, QueryRunner } from 'typeorm';\nimport { Logger } from 'winston';\nimport { Inject } from '@nestjs/common';\nimport { WINSTON_MODULE_PROVIDER } from 'nest-winston';\nimport * as winston from 'winston';\nimport { Environment } from './decorators/disallow-in-production.decorator';\n\nexport const createWinstonLoggerConfig = () => ({\n level: process.env.LOG_LEVEL || (process.env.ENV === Environment.Production ? 'warn' : 'info'),\n format: winston.format.combine(\n winston.format.timestamp(),\n winston.format.errors({ stack: true }),\n winston.format.printf(({ level, message, timestamp }) => {\n if (!message) {\n return `[${timestamp}] ${level.toUpperCase()}: (No message provided)`;\n }\n return `[${timestamp}] ${level.toUpperCase()}: ${message}`;\n }),\n ),\n transports: [\n new winston.transports.Console({\n format: winston.format.combine(\n winston.format.printf(({ level, message, timestamp }) => {\n return `[${timestamp}] ${level.toUpperCase()}: ${message}`;\n }),\n ),\n }),\n new winston.transports.File({\n filename: 'logs/application.log',\n }),\n new winston.transports.File({\n filename: 'logs/error.log',\n level: 'error',\n }),\n ],\n});\n\nexport const WinstonLoggerConfig = createWinstonLoggerConfig();\n\nexport class WinstonTypeORMLogger implements TypeORMLogger {\n constructor(@Inject(WINSTON_MODULE_PROVIDER) private readonly logger: Logger) { }\n\n logQuery(query: string, parameters?: any[], queryRunner?: QueryRunner): void {\n if (Boolean(process.env.DEFAULT_DATABASE_LOGGING)) {\n this.logger.info(`Query: ${query} Parameters: ${parameters}`);\n }\n }\n\n logQueryError(error: string, query: string, parameters?: any[], queryRunner?: QueryRunner): void {\n this.logger.error(`Query failed: ${error} | Query: ${query} | Parameters: ${parameters}`);\n }\n\n logQuerySlow(time: number, query: string, parameters?: any[], queryRunner?: QueryRunner): void {\n this.logger.warn(`Slow query: ${time}ms | Query: ${query} | Parameters: ${parameters}`);\n }\n\n logSchemaBuild(message: string, queryRunner?: QueryRunner): void {\n this.logger.info(`Schema Build: ${message}`);\n }\n\n logMigration(message: string, queryRunner?: QueryRunner): void {\n this.logger.info(`Migration: ${message}`);\n }\n\n log(level: 'log' | 'info' | 'warn' | 'error', message: any): void {\n this.logger[level](message);\n }\n}"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solidxai/core",
|
|
3
|
-
"version": "0.1.10-beta.
|
|
3
|
+
"version": "0.1.10-beta.15",
|
|
4
4
|
"description": "This module is a NestJS module containing all the required core providers required by a Solid application",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -9,7 +9,7 @@ import { existsSync } from 'fs';
|
|
|
9
9
|
import { resolve } from 'path';
|
|
10
10
|
import { WINSTON_MODULE_NEST_PROVIDER, WinstonModule } from 'nest-winston';
|
|
11
11
|
import { CommandFactory } from 'nest-commander';
|
|
12
|
-
import {
|
|
12
|
+
import { createWinstonLoggerConfig } from '../winston.logger';
|
|
13
13
|
import { WrapResponseInterceptor } from '../interceptors/wrap-response.interceptor';
|
|
14
14
|
import { buildDefaultCorsOptions } from './cors.helper';
|
|
15
15
|
import { buildDefaultSecurityHeaderOptions, buildPermissionsPolicyHeader, PermissionsPolicyConfig } from './security.helper';
|
|
@@ -50,6 +50,8 @@ export interface SolidBootstrapOptions {
|
|
|
50
50
|
swagger?: SolidSwaggerOptions | false;
|
|
51
51
|
/** Permissions-Policy header overrides (merged with defaults). */
|
|
52
52
|
permissionsPolicyOverrides?: Partial<PermissionsPolicyConfig>;
|
|
53
|
+
/** Show full NestJS init logs during bootstrap (route mapping, module deps, pollers). Defaults to false. */
|
|
54
|
+
verboseBootstrap?: boolean;
|
|
53
55
|
}
|
|
54
56
|
|
|
55
57
|
/**
|
|
@@ -70,11 +72,12 @@ export async function bootstrapSolidApp(
|
|
|
70
72
|
): Promise<void> {
|
|
71
73
|
registerGlobalProcessHandlers();
|
|
72
74
|
|
|
73
|
-
const { globalPrefix = 'api', swagger = {}, permissionsPolicyOverrides = {} } = options;
|
|
75
|
+
const { globalPrefix = 'api', swagger = {}, permissionsPolicyOverrides = {}, verboseBootstrap = false } = options;
|
|
74
76
|
|
|
77
|
+
const startTime = Date.now();
|
|
75
78
|
const appModule = await appModuleFactory();
|
|
76
79
|
const app = await NestFactory.create(appModule, {
|
|
77
|
-
logger: WinstonModule.createLogger(
|
|
80
|
+
logger: WinstonModule.createLogger({ ...createWinstonLoggerConfig(), level: verboseBootstrap ? 'debug' : 'error' }),
|
|
78
81
|
});
|
|
79
82
|
|
|
80
83
|
const apiEnabled = parseBooleanEnv('API_ENABLED', true);
|
|
@@ -115,9 +118,6 @@ export async function bootstrapSolidApp(
|
|
|
115
118
|
next();
|
|
116
119
|
});
|
|
117
120
|
|
|
118
|
-
// Winston logger
|
|
119
|
-
app.useLogger(app.get(WINSTON_MODULE_NEST_PROVIDER));
|
|
120
|
-
|
|
121
121
|
const port = process.env.PORT || 3000;
|
|
122
122
|
|
|
123
123
|
if (globalPrefix) {
|
|
@@ -182,6 +182,13 @@ export async function bootstrapSolidApp(
|
|
|
182
182
|
app.useWebSocketAdapter(new WsAdapter(app));
|
|
183
183
|
|
|
184
184
|
await app.listen(port);
|
|
185
|
+
|
|
186
|
+
// Wire up Winston as the runtime logger only AFTER listen — this suppresses all
|
|
187
|
+
// framework init noise (route mapping, module deps, onModuleInit) during boot.
|
|
188
|
+
app.useLogger(app.get(WINSTON_MODULE_NEST_PROVIDER));
|
|
189
|
+
|
|
190
|
+
const elapsed = ((Date.now() - startTime) / 1000).toFixed(2);
|
|
191
|
+
app.get(WINSTON_MODULE_NEST_PROVIDER).log(`\x1b[32mServer started on port ${port} in ${elapsed}s\x1b[0m`, 'Bootstrap');
|
|
185
192
|
}
|
|
186
193
|
|
|
187
194
|
// ---- CLI bootstrap ----
|
package/src/winston.logger.ts
CHANGED
|
@@ -6,8 +6,8 @@ import { WINSTON_MODULE_PROVIDER } from 'nest-winston';
|
|
|
6
6
|
import * as winston from 'winston';
|
|
7
7
|
import { Environment } from './decorators/disallow-in-production.decorator';
|
|
8
8
|
|
|
9
|
-
export const
|
|
10
|
-
level: process.env.LOG_LEVEL || (process.env.ENV === Environment.Production ? '
|
|
9
|
+
export const createWinstonLoggerConfig = () => ({
|
|
10
|
+
level: process.env.LOG_LEVEL || (process.env.ENV === Environment.Production ? 'warn' : 'info'),
|
|
11
11
|
format: winston.format.combine(
|
|
12
12
|
winston.format.timestamp(),
|
|
13
13
|
winston.format.errors({ stack: true }),
|
|
@@ -21,8 +21,6 @@ export const WinstonLoggerConfig = {
|
|
|
21
21
|
transports: [
|
|
22
22
|
new winston.transports.Console({
|
|
23
23
|
format: winston.format.combine(
|
|
24
|
-
// winston.format.colorize(),
|
|
25
|
-
// winston.format.timestamp(),
|
|
26
24
|
winston.format.printf(({ level, message, timestamp }) => {
|
|
27
25
|
return `[${timestamp}] ${level.toUpperCase()}: ${message}`;
|
|
28
26
|
}),
|
|
@@ -30,15 +28,15 @@ export const WinstonLoggerConfig = {
|
|
|
30
28
|
}),
|
|
31
29
|
new winston.transports.File({
|
|
32
30
|
filename: 'logs/application.log',
|
|
33
|
-
// format: winston.format.json(),
|
|
34
31
|
}),
|
|
35
32
|
new winston.transports.File({
|
|
36
33
|
filename: 'logs/error.log',
|
|
37
34
|
level: 'error',
|
|
38
|
-
// format: winston.format.json(),
|
|
39
35
|
}),
|
|
40
36
|
],
|
|
41
|
-
};
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
export const WinstonLoggerConfig = createWinstonLoggerConfig();
|
|
42
40
|
|
|
43
41
|
export class WinstonTypeORMLogger implements TypeORMLogger {
|
|
44
42
|
constructor(@Inject(WINSTON_MODULE_PROVIDER) private readonly logger: Logger) { }
|