@syswatch/nestjs 1.0.0 → 1.0.1
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/index.d.mts +11 -4
- package/dist/index.d.ts +11 -4
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { ModuleMetadata, Type, DynamicModule, NestInterceptor, ExecutionContext, CallHandler } from '@nestjs/common';
|
|
1
|
+
import { ModuleMetadata, Type, OnModuleInit, DynamicModule, NestInterceptor, ExecutionContext, CallHandler, ExceptionFilter, ArgumentsHost } from '@nestjs/common';
|
|
2
2
|
import { SysWatchConfig, SysWatch } from '@syswatch/core';
|
|
3
3
|
import { Observable } from 'rxjs';
|
|
4
|
+
import { Response } from 'express';
|
|
4
5
|
|
|
5
6
|
type SysWatchModuleOptions = SysWatchConfig;
|
|
6
7
|
interface SysWatchOptionsFactory {
|
|
@@ -15,8 +16,9 @@ interface SysWatchModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
|
|
|
15
16
|
|
|
16
17
|
declare const SYSWATCH_OPTIONS = "SYSWATCH_OPTIONS";
|
|
17
18
|
|
|
18
|
-
declare class SysWatchService extends SysWatch {
|
|
19
|
+
declare class SysWatchService extends SysWatch implements OnModuleInit {
|
|
19
20
|
constructor(options: SysWatchModuleOptions);
|
|
21
|
+
onModuleInit(): Promise<void>;
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
declare class SysWatchModule {
|
|
@@ -30,7 +32,12 @@ declare class LoggerInterceptor implements NestInterceptor {
|
|
|
30
32
|
private readonly sysWatch;
|
|
31
33
|
constructor(sysWatch: SysWatchService);
|
|
32
34
|
intercept(context: ExecutionContext, next: CallHandler): Observable<any>;
|
|
33
|
-
private logRequest;
|
|
34
35
|
}
|
|
35
36
|
|
|
36
|
-
|
|
37
|
+
declare class LoggerException implements ExceptionFilter {
|
|
38
|
+
private readonly sysWatch;
|
|
39
|
+
constructor(sysWatch: SysWatchService);
|
|
40
|
+
catch(exception: any, host: ArgumentsHost): Promise<void | Response<any, Record<string, any>>>;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export { LoggerException, LoggerInterceptor, SYSWATCH_OPTIONS, SysWatchModule, type SysWatchModuleAsyncOptions, type SysWatchModuleOptions, type SysWatchOptionsFactory, SysWatchService };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { ModuleMetadata, Type, DynamicModule, NestInterceptor, ExecutionContext, CallHandler } from '@nestjs/common';
|
|
1
|
+
import { ModuleMetadata, Type, OnModuleInit, DynamicModule, NestInterceptor, ExecutionContext, CallHandler, ExceptionFilter, ArgumentsHost } from '@nestjs/common';
|
|
2
2
|
import { SysWatchConfig, SysWatch } from '@syswatch/core';
|
|
3
3
|
import { Observable } from 'rxjs';
|
|
4
|
+
import { Response } from 'express';
|
|
4
5
|
|
|
5
6
|
type SysWatchModuleOptions = SysWatchConfig;
|
|
6
7
|
interface SysWatchOptionsFactory {
|
|
@@ -15,8 +16,9 @@ interface SysWatchModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
|
|
|
15
16
|
|
|
16
17
|
declare const SYSWATCH_OPTIONS = "SYSWATCH_OPTIONS";
|
|
17
18
|
|
|
18
|
-
declare class SysWatchService extends SysWatch {
|
|
19
|
+
declare class SysWatchService extends SysWatch implements OnModuleInit {
|
|
19
20
|
constructor(options: SysWatchModuleOptions);
|
|
21
|
+
onModuleInit(): Promise<void>;
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
declare class SysWatchModule {
|
|
@@ -30,7 +32,12 @@ declare class LoggerInterceptor implements NestInterceptor {
|
|
|
30
32
|
private readonly sysWatch;
|
|
31
33
|
constructor(sysWatch: SysWatchService);
|
|
32
34
|
intercept(context: ExecutionContext, next: CallHandler): Observable<any>;
|
|
33
|
-
private logRequest;
|
|
34
35
|
}
|
|
35
36
|
|
|
36
|
-
|
|
37
|
+
declare class LoggerException implements ExceptionFilter {
|
|
38
|
+
private readonly sysWatch;
|
|
39
|
+
constructor(sysWatch: SysWatchService);
|
|
40
|
+
catch(exception: any, host: ArgumentsHost): Promise<void | Response<any, Record<string, any>>>;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export { LoggerException, LoggerInterceptor, SYSWATCH_OPTIONS, SysWatchModule, type SysWatchModuleAsyncOptions, type SysWatchModuleOptions, type SysWatchOptionsFactory, SysWatchService };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var I=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var M=Object.prototype.hasOwnProperty;var b=(r,t)=>{for(var e in t)I(r,e,{get:t[e],enumerable:!0})},N=(r,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of E(t))!M.call(r,s)&&s!==e&&I(r,s,{get:()=>t[s],enumerable:!(i=H(t,s))||i.enumerable});return r};var D=r=>N(I({},"__esModule",{value:!0}),r),d=(r,t,e,i)=>{for(var s=i>1?void 0:i?H(t,e):t,p=r.length-1,l;p>=0;p--)(l=r[p])&&(s=(i?l(t,e,s):l(s))||s);return i&&s&&I(t,e,s),s},y=(r,t)=>(e,i)=>t(e,i,r);var Y={};b(Y,{LoggerException:()=>O,LoggerInterceptor:()=>v,SYSWATCH_OPTIONS:()=>g,SysWatchModule:()=>m,SysWatchService:()=>n});module.exports=D(Y);var g="SYSWATCH_OPTIONS";var f=require("@nestjs/common"),_=require("@syswatch/core");var n=class extends _.SysWatch{constructor(t){super(t)}async onModuleInit(){await this.init().catch(t=>{f.Logger.error(t.message,"SysWatchService")})}};n=d([(0,f.Injectable)(),y(0,(0,f.Inject)(g))],n);var x=require("@nestjs/common");var m=class{static forRoot(t){return{module:m,providers:[{provide:g,useValue:t},n],exports:[n]}}static forRootAsync(t){return{module:m,imports:t.imports||[],providers:[...this.createAsyncProviders(t),n],exports:[n]}}static createAsyncProviders(t){return t.useExisting||t.useFactory?[this.createAsyncOptionsProvider(t)]:[this.createAsyncOptionsProvider(t),{provide:t.useClass,useClass:t.useClass}]}static createAsyncOptionsProvider(t){return t.useFactory?{provide:g,useFactory:t.useFactory,inject:t.inject||[]}:{provide:g,useFactory:async e=>await e.createSysWatchOptions(),inject:[t.useExisting||t.useClass]}}};m=d([(0,x.Global)(),(0,x.Module)({})],m);var S=require("@nestjs/common"),F=require("rxjs"),R=require("rxjs/operators");var v=class{constructor(t){this.sysWatch=t}intercept(t,e){if(!this.sysWatch||!this.sysWatch.log)return S.Logger.error("SysWatchService not injected. LoggerInterceptor will not log requests."),e.handle();let i=Date.now(),s=t.switchToHttp().getRequest(),p=s.method,l=s.route&&"path"in s.route?s.route.path:s.url,P=s.query,c=s.user?.id||s.user?.sub||s.user?._id,h=s?.id||s.headers?.["x-request-id"]||s.headers?.["x-correlation-id"];return e.handle().pipe((0,R.tap)(o=>{let a=t.switchToHttp().getResponse().statusCode,j=Date.now()-i,q=a.toString().startsWith("2"),C=a.toString().startsWith("4"),T=a.toString().startsWith("5"),A={...h&&{requestId:h},method:p,statusCode:a,url:l,queryParams:P,duration:j,...o&&!q&&{response:typeof o=="string"?o.slice(0,500):o}},w=typeof o=="object"&&!Array.isArray(o)&&"message"in o&&typeof o.message=="string";if(q)return this.sysWatch.log.success("http_request",{...c&&{userId:c},meta:A});C&&this.sysWatch.log.failure("http_request",{...w?{message:o.message}:{},...c&&{userId:c},meta:A}),T&&this.sysWatch.log.error("http_request",{...w?{message:o.message}:{},...c&&{userId:c},meta:A}),this.sysWatch.log.debug("http_request",{...c&&{userId:c},meta:A}),s.logged=!0}),(0,R.catchError)(o=>(0,F.throwError)(()=>o)))}};v=d([(0,S.Injectable)(),y(0,(0,S.Inject)(n))],v);var u=require("@nestjs/common");var O=class{constructor(t){this.sysWatch=t}async catch(t,e){if(!this.sysWatch||!this.sysWatch.log)return u.Logger.error("SysWatchService not injected. LoggerInterceptor will not log requests.");let i=e.switchToHttp(),s=i.getRequest(),p=i.getResponse();if(s.logged)return;let l=s.method,P=s.route&&"path"in s.route?s.route.path:s.url,c=s.query,h=s.user?.id||s.user?.sub||s.user?._id,o=s?.id||s.headers?.["x-request-id"]||s.headers?.["x-correlation-id"],W=t.getStatus?t.getStatus():500,a=t instanceof u.HttpException?t.getResponse():{message:"Internal server error"},j=W.toString().startsWith("4"),q=W.toString().startsWith("5"),C={...o&&{requestId:o},method:l,statusCode:W,url:P,queryParams:c,body:typeof a=="string"?a.slice(0,500):a,...t&&t instanceof Error&&!(t instanceof u.HttpException)?{error:t.message}:{}};return j&&await this.sysWatch.log.failure("http_request",{...typeof a=="object"&&!Array.isArray(a)&&"message"in a&&typeof a.message=="string"?{message:a.message}:{},...h&&{userId:h},meta:C}),q&&await this.sysWatch.log.error("http_request",{...t&&t instanceof Error&&t.message?{message:t.message}:{},...h&&{userId:h},meta:C}),p.status(W).json(a)}};O=d([(0,u.Catch)(),y(0,(0,u.Inject)(n))],O);0&&(module.exports={LoggerException,LoggerInterceptor,SYSWATCH_OPTIONS,SysWatchModule,SysWatchService});
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/constants.ts","../src/syswatch.service.ts","../src/syswatch.module.ts","../src/interceptors/logger.interceptor.ts"],"sourcesContent":["export * from \"./interfaces\";\nexport * from \"./constants\";\nexport * from \"./syswatch.service\";\nexport * from \"./syswatch.module\";\n\nexport * from \"./interceptors\";\n","export const SYSWATCH_OPTIONS = 'SYSWATCH_OPTIONS';\n","import { Inject, Injectable } from \"@nestjs/common\";\nimport { SysWatch } from \"@syswatch/core\";\nimport { SYSWATCH_OPTIONS } from \"./constants\";\nimport { SysWatchModuleOptions } from \"./interfaces\";\n\n@Injectable()\nexport class SysWatchService extends SysWatch {\n constructor(@Inject(SYSWATCH_OPTIONS) options: SysWatchModuleOptions) {\n super(options);\n }\n}\n","import { DynamicModule, Global, Module, Provider } from '@nestjs/common';\nimport { SysWatchService } from './syswatch.service';\nimport { SYSWATCH_OPTIONS } from './constants';\nimport { SysWatchModuleAsyncOptions, SysWatchModuleOptions, SysWatchOptionsFactory } from './interfaces';\n\n@Global()\n@Module({})\nexport class SysWatchModule {\n static forRoot(options: SysWatchModuleOptions): DynamicModule {\n return {\n module: SysWatchModule,\n providers: [\n {\n provide: SYSWATCH_OPTIONS,\n useValue: options,\n },\n SysWatchService,\n ],\n exports: [SysWatchService],\n };\n }\n\n static forRootAsync(options: SysWatchModuleAsyncOptions): DynamicModule {\n return {\n module: SysWatchModule,\n imports: options.imports || [],\n providers: [\n ...this.createAsyncProviders(options),\n SysWatchService,\n ],\n exports: [SysWatchService],\n };\n }\n\n private static createAsyncProviders(options: SysWatchModuleAsyncOptions): Provider[] {\n if (options.useExisting || options.useFactory) {\n return [this.createAsyncOptionsProvider(options)];\n }\n return [\n this.createAsyncOptionsProvider(options),\n {\n provide: options.useClass!,\n useClass: options.useClass!,\n },\n ];\n }\n\n private static createAsyncOptionsProvider(options: SysWatchModuleAsyncOptions): Provider {\n if (options.useFactory) {\n return {\n provide: SYSWATCH_OPTIONS,\n useFactory: options.useFactory,\n inject: options.inject || [],\n };\n }\n return {\n provide: SYSWATCH_OPTIONS,\n useFactory: async (optionsFactory: SysWatchOptionsFactory) =>\n await optionsFactory.createSysWatchOptions(),\n inject: [options.useExisting || options.useClass!],\n };\n }\n}\n","import {\n CallHandler,\n ExecutionContext,\n Injectable,\n NestInterceptor,\n HttpException,\n HttpStatus,\n Inject,\n Logger,\n} from \"@nestjs/common\";\nimport { Observable, throwError } from \"rxjs\";\nimport { catchError, tap } from \"rxjs/operators\";\nimport { SysWatchService } from \"../syswatch.service\";\n\n@Injectable()\nexport class LoggerInterceptor implements NestInterceptor {\n constructor(\n @Inject(SysWatchService) private readonly sysWatch: SysWatchService,\n ) {}\n\n intercept(context: ExecutionContext, next: CallHandler): Observable<any> {\n const request = context.switchToHttp().getRequest();\n const { method, url } = request;\n const start = Date.now();\n\n const userId: string | undefined =\n request[\"user\"]?.id || request[\"user\"]?.sub || request[\"user\"]?._id;\n\n const requestId =\n request.id ||\n request.headers[\"x-request-id\"] ||\n request.headers[\"x-correlation-id\"];\n\n return next.handle().pipe(\n tap(() => {\n const response = context.switchToHttp().getResponse();\n const statusCode = response.statusCode;\n const duration = Date.now() - start;\n\n this.logRequest({\n method,\n url,\n statusCode,\n duration,\n userId,\n requestId,\n });\n }),\n catchError((error) => {\n const duration = Date.now() - start;\n const statusCode =\n error instanceof HttpException\n ? error.getStatus()\n : HttpStatus.INTERNAL_SERVER_ERROR;\n\n this.logRequest({\n method,\n url,\n statusCode,\n duration,\n error,\n userId,\n requestId,\n });\n return throwError(() => error);\n }),\n );\n }\n\n private async logRequest({\n method,\n url,\n statusCode,\n duration,\n error,\n userId,\n requestId,\n }: {\n method: string;\n url: string;\n statusCode: number;\n duration: number;\n error?: any;\n userId?: string;\n requestId?: string;\n }) {\n if (!this.sysWatch || !this.sysWatch.log) {\n // Fail silently or warn if service is not injected correctly\n // This happens if the interceptor is instantiated manually without passing the service\n return Logger.error(\n \"SysWatchService not injected. LoggerInterceptor will not log requests.\",\n );\n }\n\n const message = `${method} ${url} ${statusCode} - ${duration}ms`;\n const meta = {\n method,\n url,\n statusCode,\n duration,\n slow: duration > 1000,\n ...(requestId && { requestId }),\n ...(error &&\n error instanceof Error && {\n error: error.message,\n exception: error.name,\n ...(\"code\" in error ? { code: error.code } : {}),\n ...(process.env.NODE_ENV !== \"production\"\n ? { stack: error.stack }\n : {}),\n }),\n };\n\n const statusCodeSuccess = statusCode.toString().startsWith(\"2\");\n const statusCodeFailure = statusCode.toString().startsWith(\"4\");\n const statusCodeError = statusCode.toString().startsWith(\"5\");\n\n if (statusCodeSuccess) {\n await this.sysWatch.log.success(\"http_request\", message, {\n ...(userId && { userId }),\n meta,\n });\n }\n if (statusCodeFailure) {\n await this.sysWatch.log.failure(\"http_request\", message, {\n ...(userId && { userId }),\n meta,\n });\n }\n if (statusCodeError) {\n await this.sysWatch.log.error(\"http_request\", message, {\n ...(userId && { userId }),\n meta,\n });\n }\n }\n}\n"],"mappings":"okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,uBAAAE,EAAA,qBAAAC,EAAA,mBAAAC,EAAA,oBAAAC,IAAA,eAAAC,EAAAN,GCAO,IAAMO,EAAmB,mBCAhC,IAAAC,EAAmC,0BACnCC,EAAyB,0BAKlB,IAAMC,EAAN,cAA8B,UAAS,CAC5C,YAAsCC,EAAgC,CACpE,MAAMA,CAAO,CACf,CACF,EAJaD,EAANE,EAAA,IADN,cAAW,EAEGC,EAAA,eAAOC,CAAgB,IADzBJ,GCNb,IAAAK,EAAwD,0BAOjD,IAAMC,EAAN,KAAqB,CAC1B,OAAO,QAAQC,EAA+C,CAC5D,MAAO,CACL,OAAQD,EACR,UAAW,CACT,CACE,QAASE,EACT,SAAUD,CACZ,EACAE,CACF,EACA,QAAS,CAACA,CAAe,CAC3B,CACF,CAEA,OAAO,aAAaF,EAAoD,CACtE,MAAO,CACL,OAAQD,EACR,QAASC,EAAQ,SAAW,CAAC,EAC7B,UAAW,CACT,GAAG,KAAK,qBAAqBA,CAAO,EACpCE,CACF,EACA,QAAS,CAACA,CAAe,CAC3B,CACF,CAEA,OAAe,qBAAqBF,EAAiD,CACnF,OAAIA,EAAQ,aAAeA,EAAQ,WAC1B,CAAC,KAAK,2BAA2BA,CAAO,CAAC,EAE3C,CACL,KAAK,2BAA2BA,CAAO,EACvC,CACE,QAASA,EAAQ,SACjB,SAAUA,EAAQ,QACpB,CACF,CACF,CAEA,OAAe,2BAA2BA,EAA+C,CACvF,OAAIA,EAAQ,WACH,CACL,QAASC,EACT,WAAYD,EAAQ,WACpB,OAAQA,EAAQ,QAAU,CAAC,CAC7B,EA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EAQG,CACD,GAAI,CAAC,KAAK,UAAY,CAAC,KAAK,SAAS,IAGnC,OAAO,SAAO,MACZ,wEACF,EAGF,IAAMI,EAAU,GAAGR,CAAM,IAAIC,CAAG,IAAII,CAAU,MAAMC,CAAQ,KACtDG,EAAO,CACX,OAAAT,EACA,IAAAC,EACA,WAAAI,EACA,SAAAC,EACA,KAAMA,EAAW,IACjB,GAAIF,GAAa,CAAE,UAAAA,CAAU,EAC7B,GAAIG,GACFA,aAAiB,OAAS,CACxB,MAAOA,EAAM,QACb,UAAWA,EAAM,KACjB,GAAI,SAAUA,EAAQ,CAAE,KAAMA,EAAM,IAAK,EAAI,CAAC,EAC9C,GAAI,QAAQ,IAAI,WAAa,aACzB,CAAE,MAAOA,EAAM,KAAM,EACrB,CAAC,CACP,CACJ,EAEMG,EAAoBL,EAAW,SAAS,EAAE,WAAW,GAAG,EACxDM,EAAoBN,EAAW,SAAS,EAAE,WAAW,GAAG,EACxDO,EAAkBP,EAAW,SAAS,EAAE,WAAW,GAAG,EAExDK,GACF,MAAM,KAAK,SAAS,IAAI,QAAQ,eAAgBF,EAAS,CACvD,GAAIL,GAAU,CAAE,OAAAA,CAAO,EACvB,KAAAM,CACF,CAAC,EAECE,GACF,MAAM,KAAK,SAAS,IAAI,QAAQ,eAAgBH,EAAS,CACvD,GAAIL,GAAU,CAAE,OAAAA,CAAO,EACvB,KAAAM,CACF,CAAC,EAECG,GACF,MAAM,KAAK,SAAS,IAAI,MAAM,eAAgBJ,EAAS,CACrD,GAAIL,GAAU,CAAE,OAAAA,CAAO,EACvB,KAAAM,CACF,CAAC,CAEL,CACF,EAzHad,EAANkB,EAAA,IADN,cAAW,EAGPC,EAAA,eAAOC,CAAe,IAFdpB","names":["index_exports","__export","LoggerInterceptor","SYSWATCH_OPTIONS","SysWatchModule","SysWatchService","__toCommonJS","SYSWATCH_OPTIONS","import_common","import_core","SysWatchService","options","__decorateClass","__decorateParam","SYSWATCH_OPTIONS","import_common","SysWatchModule","options","SYSWATCH_OPTIONS","SysWatchService","optionsFactory","__decorateClass","import_common","import_rxjs","import_operators","LoggerInterceptor","sysWatch","context","next","request","method","url","start","userId","requestId","statusCode","duration","error","message","meta","statusCodeSuccess","statusCodeFailure","statusCodeError","__decorateClass","__decorateParam","SysWatchService"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/constants.ts","../src/syswatch.service.ts","../src/syswatch.module.ts","../src/interceptors/logger.interceptor.ts","../src/exceptions/logger.exception.ts"],"sourcesContent":["export * from \"./interfaces\";\nexport * from \"./constants\";\nexport * from \"./syswatch.service\";\nexport * from \"./syswatch.module\";\n\nexport * from \"./interceptors\";\nexport * from \"./exceptions\";\n","export const SYSWATCH_OPTIONS = 'SYSWATCH_OPTIONS';\n","import { Inject, Injectable, Logger, OnModuleInit } from \"@nestjs/common\";\nimport { SysWatch } from \"@syswatch/core\";\nimport { SYSWATCH_OPTIONS } from \"./constants\";\nimport { SysWatchModuleOptions } from \"./interfaces\";\n\n@Injectable()\nexport class SysWatchService extends SysWatch implements OnModuleInit {\n constructor(@Inject(SYSWATCH_OPTIONS) options: SysWatchModuleOptions) {\n super(options);\n }\n\n async onModuleInit() {\n await this.init().catch((error) => {\n Logger.error(error.message, \"SysWatchService\");\n });\n }\n}\n","import { DynamicModule, Global, Module, Provider } from '@nestjs/common';\nimport { SysWatchService } from './syswatch.service';\nimport { SYSWATCH_OPTIONS } from './constants';\nimport { SysWatchModuleAsyncOptions, SysWatchModuleOptions, SysWatchOptionsFactory } from './interfaces';\n\n@Global()\n@Module({})\nexport class SysWatchModule {\n static forRoot(options: SysWatchModuleOptions): DynamicModule {\n return {\n module: SysWatchModule,\n providers: [\n {\n provide: SYSWATCH_OPTIONS,\n useValue: options,\n },\n SysWatchService,\n ],\n exports: [SysWatchService],\n };\n }\n\n static forRootAsync(options: SysWatchModuleAsyncOptions): DynamicModule {\n return {\n module: SysWatchModule,\n imports: options.imports || [],\n providers: [\n ...this.createAsyncProviders(options),\n SysWatchService,\n ],\n exports: [SysWatchService],\n };\n }\n\n private static createAsyncProviders(options: SysWatchModuleAsyncOptions): Provider[] {\n if (options.useExisting || options.useFactory) {\n return [this.createAsyncOptionsProvider(options)];\n }\n return [\n this.createAsyncOptionsProvider(options),\n {\n provide: options.useClass!,\n useClass: options.useClass!,\n },\n ];\n }\n\n private static createAsyncOptionsProvider(options: SysWatchModuleAsyncOptions): Provider {\n if (options.useFactory) {\n return {\n provide: SYSWATCH_OPTIONS,\n useFactory: options.useFactory,\n inject: options.inject || [],\n };\n }\n return {\n provide: SYSWATCH_OPTIONS,\n useFactory: async (optionsFactory: SysWatchOptionsFactory) =>\n await optionsFactory.createSysWatchOptions(),\n inject: [options.useExisting || options.useClass!],\n };\n }\n}\n","import {\n CallHandler,\n ExecutionContext,\n Injectable,\n NestInterceptor,\n Inject,\n Logger,\n} from \"@nestjs/common\";\nimport { Observable, throwError } from \"rxjs\";\nimport { catchError, tap } from \"rxjs/operators\";\nimport { SysWatchService } from \"../syswatch.service\";\nimport { Request, Response } from \"express\";\n\n@Injectable()\nexport class LoggerInterceptor implements NestInterceptor {\n constructor(\n @Inject(SysWatchService) private readonly sysWatch: SysWatchService,\n ) {}\n\n intercept(context: ExecutionContext, next: CallHandler): Observable<any> {\n if (!this.sysWatch || !this.sysWatch.log) {\n Logger.error(\n \"SysWatchService not injected. LoggerInterceptor will not log requests.\",\n );\n\n return next.handle();\n }\n\n const start = Date.now();\n\n const request = context.switchToHttp().getRequest<\n Request & {\n user?: {\n id: string | undefined;\n sub: string | undefined;\n _id: string | undefined;\n };\n id?: string;\n logged?: boolean;\n }\n >();\n\n const method = request.method;\n const url =\n request.route && \"path\" in request.route\n ? request.route.path\n : request.url;\n const queryParams = request.query;\n\n const userId: string | undefined =\n request[\"user\"]?.id || request[\"user\"]?.sub || request[\"user\"]?._id;\n\n const requestId =\n request?.[\"id\"] ||\n request.headers?.[\"x-request-id\"] ||\n request.headers?.[\"x-correlation-id\"];\n\n return next.handle().pipe(\n tap((body) => {\n const response = context.switchToHttp().getResponse<Response>();\n const statusCode = response.statusCode;\n const duration = Date.now() - start;\n\n const statusCodeSuccess = statusCode.toString().startsWith(\"2\");\n const statusCodeFailure = statusCode.toString().startsWith(\"4\");\n const statusCodeError = statusCode.toString().startsWith(\"5\");\n\n const meta = {\n ...(requestId && { requestId }),\n method,\n statusCode,\n url,\n queryParams,\n duration,\n ...(body &&\n !statusCodeSuccess && {\n response: typeof body === \"string\" ? body.slice(0, 500) : body,\n }),\n };\n\n const isValidBody =\n typeof body === \"object\" &&\n !Array.isArray(body) &&\n \"message\" in body &&\n typeof body.message === \"string\";\n\n if (statusCodeSuccess) {\n return this.sysWatch.log.success(\"http_request\", {\n ...(userId && { userId }),\n meta,\n });\n }\n\n if (statusCodeFailure) {\n this.sysWatch.log.failure(\"http_request\", {\n ...(isValidBody ? { message: body.message } : {}),\n ...(userId && { userId }),\n meta,\n });\n }\n\n if (statusCodeError) {\n this.sysWatch.log.error(\"http_request\", {\n ...(isValidBody ? { message: body.message } : {}),\n ...(userId && { userId }),\n meta,\n });\n }\n\n this.sysWatch.log.debug(\"http_request\", {\n ...(userId && { userId }),\n meta,\n });\n\n request[\"logged\"] = true;\n }),\n catchError((error) => {\n return throwError(() => error);\n }),\n );\n }\n}\n","import {\n ArgumentsHost,\n Catch,\n ExceptionFilter,\n HttpException,\n Inject,\n Logger,\n} from \"@nestjs/common\";\nimport { SysWatchService } from \"../syswatch.service\";\nimport { Request, Response } from \"express\";\n\n@Catch()\nexport class LoggerException implements ExceptionFilter {\n constructor(\n @Inject(SysWatchService) private readonly sysWatch: SysWatchService,\n ) {}\n\n async catch(exception: any, host: ArgumentsHost) {\n if (!this.sysWatch || !this.sysWatch.log) {\n return Logger.error(\n \"SysWatchService not injected. LoggerInterceptor will not log requests.\",\n );\n }\n\n const ctx = host.switchToHttp();\n\n const request = ctx.getRequest<\n Request & {\n user?: {\n id?: string;\n sub?: string;\n _id?: string;\n };\n id?: string;\n logged?: boolean;\n }\n >();\n\n const response = ctx.getResponse<Response>();\n\n if (request[\"logged\"]) return;\n\n const method = request.method;\n const url =\n request.route && \"path\" in request.route\n ? request.route.path\n : request.url;\n const queryParams = request.query;\n\n const userId: string | undefined =\n request[\"user\"]?.id || request[\"user\"]?.sub || request[\"user\"]?._id;\n const requestId =\n request?.[\"id\"] ||\n request.headers?.[\"x-request-id\"] ||\n request.headers?.[\"x-correlation-id\"];\n\n const status = exception.getStatus ? exception.getStatus() : 500;\n const body =\n exception instanceof HttpException\n ? exception.getResponse()\n : { message: \"Internal server error\" };\n\n const statusCodeFailure = status.toString().startsWith(\"4\");\n const statusCodeError = status.toString().startsWith(\"5\");\n\n const meta = {\n ...(requestId && { requestId }),\n method,\n statusCode: status,\n url,\n queryParams,\n body: typeof body === \"string\" ? body.slice(0, 500) : body,\n ...(exception &&\n exception instanceof Error &&\n !(exception instanceof HttpException)\n ? { error: exception.message }\n : {}),\n };\n\n if (statusCodeFailure) {\n await this.sysWatch.log.failure(\"http_request\", {\n ...(typeof body === \"object\" &&\n !Array.isArray(body) &&\n \"message\" in body &&\n typeof body.message === \"string\"\n ? { message: body.message }\n : {}),\n ...(userId && { userId }),\n meta,\n });\n }\n\n if (statusCodeError) {\n await this.sysWatch.log.error(\"http_request\", {\n ...(exception && exception instanceof Error && exception.message\n ? { message: exception.message }\n : {}),\n ...(userId && { userId }),\n meta,\n });\n }\n\n return response.status(status).json(body);\n }\n}\n"],"mappings":"okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qBAAAE,EAAA,sBAAAC,EAAA,qBAAAC,EAAA,mBAAAC,EAAA,oBAAAC,IAAA,eAAAC,EAAAP,GCAO,IAAMQ,EAAmB,mBCAhC,IAAAC,EAAyD,0BACzDC,EAAyB,0BAKlB,IAAMC,EAAN,cAA8B,UAAiC,CACpE,YAAsCC,EAAgC,CACpE,MAAMA,CAAO,CACf,CAEA,MAAM,cAAe,CACnB,MAAM,KAAK,KAAK,EAAE,MAAOC,GAAU,CACjC,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IL,GAAa,CAAE,UAAAA,CAAU,EAC7B,OAAAJ,EACA,WAAYK,EACZ,IAAAJ,EACA,YAAAC,EACA,KAAM,OAAOI,GAAS,SAAWA,EAAK,MAAM,EAAG,GAAG,EAAIA,EACtD,GAAIX,GACJA,aAAqB,OACrB,EAAEA,aAAqB,iBACnB,CAAE,MAAOA,EAAU,OAAQ,EAC3B,CAAC,CACP,EAEA,OAAIY,GACF,MAAM,KAAK,SAAS,IAAI,QAAQ,eAAgB,CAC9C,GAAI,OAAOD,GAAS,UACpB,CAAC,MAAM,QAAQA,CAAI,GACnB,YAAaA,GACb,OAAOA,EAAK,SAAY,SACpB,CAAE,QAASA,EAAK,OAAQ,EACxB,CAAC,EACL,GAAIH,GAAU,CAAE,OAAAA,CAAO,EACvB,KAAAM,CACF,CAAC,EAGCD,GACF,MAAM,KAAK,SAAS,IAAI,MAAM,eAAgB,CAC5C,GAAIb,GAAaA,aAAqB,OAASA,EAAU,QACrD,CAAE,QAASA,EAAU,OAAQ,EAC7B,CAAC,EACL,GAAIQ,GAAU,CAAE,OAAAA,CAAO,EACvB,KAAAM,CACF,CAAC,EAGIV,EAAS,OAAOM,CAAM,EAAE,KAAKC,CAAI,CAC1C,CACF,EA5Fab,EAANiB,EAAA,IADN,SAAM,EAGFC,EAAA,eAAOC,CAAe,IAFdnB","names":["index_exports","__export","LoggerException","LoggerInterceptor","SYSWATCH_OPTIONS","SysWatchModule","SysWatchService","__toCommonJS","SYSWATCH_OPTIONS","import_common","import_core","SysWatchService","options","error","__decorateClass","__decorateParam","SYSWATCH_OPTIONS","import_common","SysWatchModule","options","SYSWATCH_OPTIONS","SysWatchService","optionsFactory","__decorateClass","import_common","import_rxjs","import_operators","LoggerInterceptor","sysWatch","context","next","start","request","method","url","queryParams","userId","requestId","body","statusCode","duration","statusCodeSuccess","statusCodeFailure","statusCodeError","meta","isValidBody","error","__decorateClass","__decorateParam","SysWatchService","import_common","LoggerException","sysWatch","exception","host","ctx","request","response","method","url","queryParams","userId","requestId","status","body","statusCodeFailure","statusCodeError","meta","__decorateClass","__decorateParam","SysWatchService"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var R=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var c=(u,t,i,a)=>{for(var s=a>1?void 0:a?P(t,i):t,d=u.length-1,m;d>=0;d--)(m=u[d])&&(s=(a?m(t,i,s):m(s))||s);return a&&s&&R(t,i,s),s},h=(u,t)=>(i,a)=>t(i,a,u);var g="SYSWATCH_OPTIONS";import{Inject as j,Injectable as w,Logger as H}from"@nestjs/common";import{SysWatch as _}from"@syswatch/core";var o=class extends _{constructor(t){super(t)}async onModuleInit(){await this.init().catch(t=>{H.error(t.message,"SysWatchService")})}};o=c([w(),h(0,j(g))],o);import{Global as F,Module as T}from"@nestjs/common";var l=class{static forRoot(t){return{module:l,providers:[{provide:g,useValue:t},o],exports:[o]}}static forRootAsync(t){return{module:l,imports:t.imports||[],providers:[...this.createAsyncProviders(t),o],exports:[o]}}static createAsyncProviders(t){return t.useExisting||t.useFactory?[this.createAsyncOptionsProvider(t)]:[this.createAsyncOptionsProvider(t),{provide:t.useClass,useClass:t.useClass}]}static createAsyncOptionsProvider(t){return t.useFactory?{provide:g,useFactory:t.useFactory,inject:t.inject||[]}:{provide:g,useFactory:async i=>await i.createSysWatchOptions(),inject:[t.useExisting||t.useClass]}}};l=c([F(),T({})],l);import{Injectable as E,Inject as M,Logger as b}from"@nestjs/common";import{throwError as N}from"rxjs";import{catchError as D,tap as Y}from"rxjs/operators";var v=class{constructor(t){this.sysWatch=t}intercept(t,i){if(!this.sysWatch||!this.sysWatch.log)return b.error("SysWatchService not injected. LoggerInterceptor will not log requests."),i.handle();let a=Date.now(),s=t.switchToHttp().getRequest(),d=s.method,m=s.route&&"path"in s.route?s.route.path:s.url,q=s.query,n=s.user?.id||s.user?.sub||s.user?._id,p=s?.id||s.headers?.["x-request-id"]||s.headers?.["x-correlation-id"];return i.handle().pipe(Y(e=>{let r=t.switchToHttp().getResponse().statusCode,C=Date.now()-a,f=r.toString().startsWith("2"),S=r.toString().startsWith("4"),x=r.toString().startsWith("5"),W={...p&&{requestId:p},method:d,statusCode:r,url:m,queryParams:q,duration:C,...e&&!f&&{response:typeof e=="string"?e.slice(0,500):e}},A=typeof e=="object"&&!Array.isArray(e)&&"message"in e&&typeof e.message=="string";if(f)return this.sysWatch.log.success("http_request",{...n&&{userId:n},meta:W});S&&this.sysWatch.log.failure("http_request",{...A?{message:e.message}:{},...n&&{userId:n},meta:W}),x&&this.sysWatch.log.error("http_request",{...A?{message:e.message}:{},...n&&{userId:n},meta:W}),this.sysWatch.log.debug("http_request",{...n&&{userId:n},meta:W}),s.logged=!0}),D(e=>N(()=>e)))}};v=c([E(),h(0,M(o))],v);import{Catch as V,HttpException as I,Inject as B,Logger as G}from"@nestjs/common";var O=class{constructor(t){this.sysWatch=t}async catch(t,i){if(!this.sysWatch||!this.sysWatch.log)return G.error("SysWatchService not injected. LoggerInterceptor will not log requests.");let a=i.switchToHttp(),s=a.getRequest(),d=a.getResponse();if(s.logged)return;let m=s.method,q=s.route&&"path"in s.route?s.route.path:s.url,n=s.query,p=s.user?.id||s.user?.sub||s.user?._id,e=s?.id||s.headers?.["x-request-id"]||s.headers?.["x-correlation-id"],y=t.getStatus?t.getStatus():500,r=t instanceof I?t.getResponse():{message:"Internal server error"},C=y.toString().startsWith("4"),f=y.toString().startsWith("5"),S={...e&&{requestId:e},method:m,statusCode:y,url:q,queryParams:n,body:typeof r=="string"?r.slice(0,500):r,...t&&t instanceof Error&&!(t instanceof I)?{error:t.message}:{}};return C&&await this.sysWatch.log.failure("http_request",{...typeof r=="object"&&!Array.isArray(r)&&"message"in r&&typeof r.message=="string"?{message:r.message}:{},...p&&{userId:p},meta:S}),f&&await this.sysWatch.log.error("http_request",{...t&&t instanceof Error&&t.message?{message:t.message}:{},...p&&{userId:p},meta:S}),d.status(y).json(r)}};O=c([V(),h(0,B(o))],O);export{O as LoggerException,v as LoggerInterceptor,g as SYSWATCH_OPTIONS,l as SysWatchModule,o as SysWatchService};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/constants.ts","../src/syswatch.service.ts","../src/syswatch.module.ts","../src/interceptors/logger.interceptor.ts"],"sourcesContent":["export const SYSWATCH_OPTIONS = 'SYSWATCH_OPTIONS';\n","import { Inject, Injectable } from \"@nestjs/common\";\nimport { SysWatch } from \"@syswatch/core\";\nimport { SYSWATCH_OPTIONS } from \"./constants\";\nimport { SysWatchModuleOptions } from \"./interfaces\";\n\n@Injectable()\nexport class SysWatchService extends SysWatch {\n constructor(@Inject(SYSWATCH_OPTIONS) options: SysWatchModuleOptions) {\n super(options);\n }\n}\n","import { DynamicModule, Global, Module, Provider } from '@nestjs/common';\nimport { SysWatchService } from './syswatch.service';\nimport { SYSWATCH_OPTIONS } from './constants';\nimport { SysWatchModuleAsyncOptions, SysWatchModuleOptions, SysWatchOptionsFactory } from './interfaces';\n\n@Global()\n@Module({})\nexport class SysWatchModule {\n static forRoot(options: SysWatchModuleOptions): DynamicModule {\n return {\n module: SysWatchModule,\n providers: [\n {\n provide: SYSWATCH_OPTIONS,\n useValue: options,\n },\n SysWatchService,\n ],\n exports: [SysWatchService],\n };\n }\n\n static forRootAsync(options: SysWatchModuleAsyncOptions): DynamicModule {\n return {\n module: SysWatchModule,\n imports: options.imports || [],\n providers: [\n ...this.createAsyncProviders(options),\n SysWatchService,\n ],\n exports: [SysWatchService],\n };\n }\n\n private static createAsyncProviders(options: SysWatchModuleAsyncOptions): Provider[] {\n if (options.useExisting || options.useFactory) {\n return [this.createAsyncOptionsProvider(options)];\n }\n return [\n this.createAsyncOptionsProvider(options),\n {\n provide: options.useClass!,\n useClass: options.useClass!,\n },\n ];\n }\n\n private static createAsyncOptionsProvider(options: SysWatchModuleAsyncOptions): Provider {\n if (options.useFactory) {\n return {\n provide: SYSWATCH_OPTIONS,\n useFactory: options.useFactory,\n inject: options.inject || [],\n };\n }\n return {\n provide: SYSWATCH_OPTIONS,\n useFactory: async (optionsFactory: SysWatchOptionsFactory) =>\n await optionsFactory.createSysWatchOptions(),\n inject: [options.useExisting || options.useClass!],\n };\n }\n}\n","import {\n CallHandler,\n ExecutionContext,\n Injectable,\n NestInterceptor,\n HttpException,\n HttpStatus,\n Inject,\n Logger,\n} from \"@nestjs/common\";\nimport { Observable, throwError } from \"rxjs\";\nimport { catchError, tap } from \"rxjs/operators\";\nimport { SysWatchService } from \"../syswatch.service\";\n\n@Injectable()\nexport class LoggerInterceptor implements NestInterceptor {\n constructor(\n @Inject(SysWatchService) private readonly sysWatch: SysWatchService,\n ) {}\n\n intercept(context: ExecutionContext, next: CallHandler): Observable<any> {\n const request = context.switchToHttp().getRequest();\n const { method, url } = request;\n const start = Date.now();\n\n const userId: string | undefined =\n request[\"user\"]?.id || request[\"user\"]?.sub || request[\"user\"]?._id;\n\n const requestId =\n request.id ||\n request.headers[\"x-request-id\"] ||\n request.headers[\"x-correlation-id\"];\n\n return next.handle().pipe(\n tap(() => {\n const response = context.switchToHttp().getResponse();\n const statusCode = response.statusCode;\n const duration = Date.now() - start;\n\n this.logRequest({\n method,\n url,\n statusCode,\n duration,\n userId,\n requestId,\n });\n }),\n catchError((error) => {\n const duration = Date.now() - start;\n const statusCode =\n error instanceof HttpException\n ? error.getStatus()\n : HttpStatus.INTERNAL_SERVER_ERROR;\n\n this.logRequest({\n method,\n url,\n statusCode,\n duration,\n error,\n userId,\n requestId,\n });\n return throwError(() => error);\n }),\n );\n }\n\n private async logRequest({\n method,\n url,\n statusCode,\n duration,\n error,\n userId,\n requestId,\n }: {\n method: string;\n url: string;\n statusCode: number;\n duration: number;\n error?: any;\n userId?: string;\n requestId?: string;\n }) {\n if (!this.sysWatch || !this.sysWatch.log) {\n // Fail silently or warn if service is not injected correctly\n // This happens if the interceptor is instantiated manually without passing the service\n return Logger.error(\n \"SysWatchService not injected. LoggerInterceptor will not log requests.\",\n );\n }\n\n const message = `${method} ${url} ${statusCode} - ${duration}ms`;\n const meta = {\n method,\n url,\n statusCode,\n duration,\n slow: duration > 1000,\n ...(requestId && { requestId }),\n ...(error &&\n error instanceof Error && {\n error: error.message,\n exception: error.name,\n ...(\"code\" in error ? { code: error.code } : {}),\n ...(process.env.NODE_ENV !== \"production\"\n ? { stack: error.stack }\n : {}),\n }),\n };\n\n const statusCodeSuccess = statusCode.toString().startsWith(\"2\");\n const statusCodeFailure = statusCode.toString().startsWith(\"4\");\n const statusCodeError = statusCode.toString().startsWith(\"5\");\n\n if (statusCodeSuccess) {\n await this.sysWatch.log.success(\"http_request\", message, {\n ...(userId && { userId }),\n meta,\n });\n }\n if (statusCodeFailure) {\n await this.sysWatch.log.failure(\"http_request\", message, {\n ...(userId && { userId }),\n meta,\n });\n }\n if (statusCodeError) {\n await this.sysWatch.log.error(\"http_request\", message, {\n ...(userId && { userId }),\n meta,\n });\n }\n }\n}\n"],"mappings":"iOAAO,IAAMA,EAAmB,mBCAhC,OAAS,UAAAC,EAAQ,cAAAC,MAAkB,iBACnC,OAAS,YAAAC,MAAgB,iBAKlB,IAAMC,EAAN,cAA8BC,CAAS,CAC5C,YAAsCC,EAAgC,CACpE,MAAMA,CAAO,CACf,CACF,EAJaF,EAANG,EAAA,CADNC,EAAW,EAEGC,EAAA,EAAAC,EAAOC,CAAgB,IADzBP,GCNb,OAAwB,UAAAQ,EAAQ,UAAAC,MAAwB,iBAOjD,IAAMC,EAAN,KAAqB,CAC1B,OAAO,QAAQC,EAA+C,CAC5D,MAAO,CACL,OAAQD,EACR,UAAW,CACT,CACE,QAASE,EACT,SAAUD,CACZ,EACAE,CACF,EACA,QAAS,CAACA,CAAe,CAC3B,CACF,CAEA,OAAO,aAAaF,EAAoD,CACtE,MAAO,CACL,OAAQD,EACR,QAASC,EAAQ,SAAW,CAAC,EAC7B,UAAW,CACT,GAAG,KAAK,qB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ACF,CAAC,EAECE,GACF,MAAM,KAAK,SAAS,IAAI,QAAQ,eAAgBH,EAAS,CACvD,GAAIX,GAAU,CAAE,OAAAA,CAAO,EACvB,KAAAY,CACF,CAAC,EAECG,GACF,MAAM,KAAK,SAAS,IAAI,MAAM,eAAgBJ,EAAS,CACrD,GAAIX,GAAU,CAAE,OAAAA,CAAO,EACvB,KAAAY,CACF,CAAC,CAEL,CACF,EAzHapB,EAANwB,EAAA,CADNC,EAAW,EAGPC,EAAA,EAAAC,EAAOC,CAAe,IAFd5B","names":["SYSWATCH_OPTIONS","Inject","Injectable","SysWatch","SysWatchService","SysWatch","options","__decorateClass","Injectable","__decorateParam","Inject","SYSWATCH_OPTIONS","Global","Module","SysWatchModule","options","SYSWATCH_OPTIONS","SysWatchService","optionsFactory","__decorateClass","Global","Module","Injectable","HttpException","HttpStatus","Inject","Logger","throwError","catchError","tap","LoggerInterceptor","sysWatch","context","next","request","method","url","start","userId","requestId","tap","statusCode","duration","catchError","error","HttpException","HttpStatus","throwError","Logger","message","meta","statusCodeSuccess","statusCodeFailure","statusCodeError","__decorateClass","Injectable","__decorateParam","Inject","SysWatchService"]}
|
|
1
|
+
{"version":3,"sources":["../src/constants.ts","../src/syswatch.service.ts","../src/syswatch.module.ts","../src/interceptors/logger.interceptor.ts","../src/exceptions/logger.exception.ts"],"sourcesContent":["export const SYSWATCH_OPTIONS = 'SYSWATCH_OPTIONS';\n","import { Inject, Injectable, Logger, OnModuleInit } from \"@nestjs/common\";\nimport { SysWatch } from \"@syswatch/core\";\nimport { SYSWATCH_OPTIONS } from \"./constants\";\nimport { SysWatchModuleOptions } from \"./interfaces\";\n\n@Injectable()\nexport class SysWatchService extends SysWatch implements OnModuleInit {\n constructor(@Inject(SYSWATCH_OPTIONS) options: SysWatchModuleOptions) {\n super(options);\n }\n\n async onModuleInit() {\n await this.init().catch((error) => {\n Logger.error(error.message, \"SysWatchService\");\n });\n }\n}\n","import { DynamicModule, Global, Module, Provider } from '@nestjs/common';\nimport { SysWatchService } from './syswatch.service';\nimport { SYSWATCH_OPTIONS } from './constants';\nimport { SysWatchModuleAsyncOptions, SysWatchModuleOptions, SysWatchOptionsFactory } from './interfaces';\n\n@Global()\n@Module({})\nexport class SysWatchModule {\n static forRoot(options: SysWatchModuleOptions): DynamicModule {\n return {\n module: SysWatchModule,\n providers: [\n {\n provide: SYSWATCH_OPTIONS,\n useValue: options,\n },\n SysWatchService,\n ],\n exports: [SysWatchService],\n };\n }\n\n static forRootAsync(options: SysWatchModuleAsyncOptions): DynamicModule {\n return {\n module: SysWatchModule,\n imports: options.imports || [],\n providers: [\n ...this.createAsyncProviders(options),\n SysWatchService,\n ],\n exports: [SysWatchService],\n };\n }\n\n private static createAsyncProviders(options: SysWatchModuleAsyncOptions): Provider[] {\n if (options.useExisting || options.useFactory) {\n return [this.createAsyncOptionsProvider(options)];\n }\n return [\n this.createAsyncOptionsProvider(options),\n {\n provide: options.useClass!,\n useClass: options.useClass!,\n },\n ];\n }\n\n private static createAsyncOptionsProvider(options: SysWatchModuleAsyncOptions): Provider {\n if (options.useFactory) {\n return {\n provide: SYSWATCH_OPTIONS,\n useFactory: options.useFactory,\n inject: options.inject || [],\n };\n }\n return {\n provide: SYSWATCH_OPTIONS,\n useFactory: async (optionsFactory: SysWatchOptionsFactory) =>\n await optionsFactory.createSysWatchOptions(),\n inject: [options.useExisting || options.useClass!],\n };\n }\n}\n","import {\n CallHandler,\n ExecutionContext,\n Injectable,\n NestInterceptor,\n Inject,\n Logger,\n} from \"@nestjs/common\";\nimport { Observable, throwError } from \"rxjs\";\nimport { catchError, tap } from \"rxjs/operators\";\nimport { SysWatchService } from \"../syswatch.service\";\nimport { Request, Response } from \"express\";\n\n@Injectable()\nexport class LoggerInterceptor implements NestInterceptor {\n constructor(\n @Inject(SysWatchService) private readonly sysWatch: SysWatchService,\n ) {}\n\n intercept(context: ExecutionContext, next: CallHandler): Observable<any> {\n if (!this.sysWatch || !this.sysWatch.log) {\n Logger.error(\n \"SysWatchService not injected. LoggerInterceptor will not log requests.\",\n );\n\n return next.handle();\n }\n\n const start = Date.now();\n\n const request = context.switchToHttp().getRequest<\n Request & {\n user?: {\n id: string | undefined;\n sub: string | undefined;\n _id: string | undefined;\n };\n id?: string;\n logged?: boolean;\n }\n >();\n\n const method = request.method;\n const url =\n request.route && \"path\" in request.route\n ? request.route.path\n : request.url;\n const queryParams = request.query;\n\n const userId: string | undefined =\n request[\"user\"]?.id || request[\"user\"]?.sub || request[\"user\"]?._id;\n\n const requestId =\n request?.[\"id\"] ||\n request.headers?.[\"x-request-id\"] ||\n request.headers?.[\"x-correlation-id\"];\n\n return next.handle().pipe(\n tap((body) => {\n const response = context.switchToHttp().getResponse<Response>();\n const statusCode = response.statusCode;\n const duration = Date.now() - start;\n\n const statusCodeSuccess = statusCode.toString().startsWith(\"2\");\n const statusCodeFailure = statusCode.toString().startsWith(\"4\");\n const statusCodeError = statusCode.toString().startsWith(\"5\");\n\n const meta = {\n ...(requestId && { requestId }),\n method,\n statusCode,\n url,\n queryParams,\n duration,\n ...(body &&\n !statusCodeSuccess && {\n response: typeof body === \"string\" ? body.slice(0, 500) : body,\n }),\n };\n\n const isValidBody =\n typeof body === \"object\" &&\n !Array.isArray(body) &&\n \"message\" in body &&\n typeof body.message === \"string\";\n\n if (statusCodeSuccess) {\n return this.sysWatch.log.success(\"http_request\", {\n ...(userId && { userId }),\n meta,\n });\n }\n\n if (statusCodeFailure) {\n this.sysWatch.log.failure(\"http_request\", {\n ...(isValidBody ? { message: body.message } : {}),\n ...(userId && { userId }),\n meta,\n });\n }\n\n if (statusCodeError) {\n this.sysWatch.log.error(\"http_request\", {\n ...(isValidBody ? { message: body.message } : {}),\n ...(userId && { userId }),\n meta,\n });\n }\n\n this.sysWatch.log.debug(\"http_request\", {\n ...(userId && { userId }),\n meta,\n });\n\n request[\"logged\"] = true;\n }),\n catchError((error) => {\n return throwError(() => error);\n }),\n );\n }\n}\n","import {\n ArgumentsHost,\n Catch,\n ExceptionFilter,\n HttpException,\n Inject,\n Logger,\n} from \"@nestjs/common\";\nimport { SysWatchService } from \"../syswatch.service\";\nimport { Request, Response } from \"express\";\n\n@Catch()\nexport class LoggerException implements ExceptionFilter {\n constructor(\n @Inject(SysWatchService) private readonly sysWatch: SysWatchService,\n ) {}\n\n async catch(exception: any, host: ArgumentsHost) {\n if (!this.sysWatch || !this.sysWatch.log) {\n return Logger.error(\n \"SysWatchService not injected. LoggerInterceptor will not log requests.\",\n );\n }\n\n const ctx = host.switchToHttp();\n\n const request = ctx.getRequest<\n Request & {\n user?: {\n id?: string;\n sub?: string;\n _id?: string;\n };\n id?: string;\n logged?: boolean;\n }\n >();\n\n const response = ctx.getResponse<Response>();\n\n if (request[\"logged\"]) return;\n\n const method = request.method;\n const url =\n request.route && \"path\" in request.route\n ? request.route.path\n : request.url;\n const queryParams = request.query;\n\n const userId: string | undefined =\n request[\"user\"]?.id || request[\"user\"]?.sub || request[\"user\"]?._id;\n const requestId =\n request?.[\"id\"] ||\n request.headers?.[\"x-request-id\"] ||\n request.headers?.[\"x-correlation-id\"];\n\n const status = exception.getStatus ? exception.getStatus() : 500;\n const body =\n exception instanceof HttpException\n ? exception.getResponse()\n : { message: \"Internal server error\" };\n\n const statusCodeFailure = status.toString().startsWith(\"4\");\n const statusCodeError = status.toString().startsWith(\"5\");\n\n const meta = {\n ...(requestId && { requestId }),\n method,\n statusCode: status,\n url,\n queryParams,\n body: typeof body === \"string\" ? body.slice(0, 500) : body,\n ...(exception &&\n exception instanceof Error &&\n !(exception instanceof HttpException)\n ? { error: exception.message }\n : {}),\n };\n\n if (statusCodeFailure) {\n await this.sysWatch.log.failure(\"http_request\", {\n ...(typeof body === \"object\" &&\n !Array.isArray(body) &&\n \"message\" in body &&\n typeof body.message === \"string\"\n ? { message: body.message }\n : {}),\n ...(userId && { userId }),\n meta,\n });\n }\n\n if (statusCodeError) {\n await this.sysWatch.log.error(\"http_request\", {\n ...(exception && exception instanceof Error && exception.message\n ? { message: exception.message }\n : {}),\n ...(userId && { userId }),\n meta,\n });\n }\n\n return response.status(status).json(body);\n }\n}\n"],"mappings":"iOAAO,IAAMA,EAAmB,mBCAhC,OAAS,UAAAC,EAAQ,cAAAC,EAAY,UAAAC,MAA4B,iBACzD,OAAS,YAAAC,MAAgB,iBAKlB,IAAMC,EAAN,cAA8BC,CAAiC,CACpE,YAAsCC,EAAgC,CACpE,MAAMA,CAAO,CACf,CAEA,MAAM,cAAe,CACnB,MAAM,KAAK,KAAK,EAAE,MAAOC,GAAU,CACjCC,EAAO,MAAMD,EAAM,QAAS,iBAAiB,CAC/C,CAAC,CACH,CACF,EAVaH,EAANK,EAAA,CADNC,EAAW,EAEGC,EAAA,EAAAC,EAAOC,CAAgB,IADzBT,GCNb,OAAwB,UAAAU,EAAQ,UAAAC,MAAwB,iBAOjD,IAAMC,EAAN,KAAqB,CAC1B,OAAO,QAAQC,EAA+C,CAC5D,MAAO,CACL,OAAQD,EACR,UAAW,CACT,CACE,QAASE,EACT,SAAUD,CACZ,EACAE,CACF,EACA,QAAS,CAACA,CAAe,CAC3B,CACF,CAEA,OAAO,aAAaF,EAAoD,CACtE,MAAO,CACL,OAAQD,EACR,QAASC,EAAQ,SAAW,CAAC,EAC7B,UAAW,CACT,GAAG,KAAK,qBAAqBA,CAAO,EACpCE,CACF,EACA,QAAS,CAACA,CAAe,CAC3B,CACF,CAEA,OAAe,qBAAqBF,EAAiD,CACnF,OAAIA,EAAQ,aAAeA,EAAQ,WAC1B,CAAC,KAAK,2BAA2BA,CAAO,CAAC,EAE3C,CACL,KAAK,2BAA2BA,CAAO,EACvC,CACE,QAASA,EAAQ,SACjB,SAAUA,EAAQ,QACpB,CACF,CACF,CAEA,OAAe,2BAA2BA,EAA+C,CACvF,OAAIA,EAAQ,WACH,CACL,QAASC,EACT,WAAYD,EAAQ,WACpB,OAAQA,EAAQ,QAAU,CAAC,CAC7B,EAEK,CACL,QAASC,EACT,WAAY,MAAOE,GACjB,MAAMA,EAAe,sBAAs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AI,CAC1C,CACF,EA5Fad,EAANmB,EAAA,CADNC,EAAM,EAGFC,EAAA,EAAAC,EAAOC,CAAe,IAFdvB","names":["SYSWATCH_OPTIONS","Inject","Injectable","Logger","SysWatch","SysWatchService","SysWatch","options","error","Logger","__decorateClass","Injectable","__decorateParam","Inject","SYSWATCH_OPTIONS","Global","Module","SysWatchModule","options","SYSWATCH_OPTIONS","SysWatchService","optionsFactory","__decorateClass","Global","Module","Injectable","Inject","Logger","throwError","catchError","tap","LoggerInterceptor","sysWatch","context","next","Logger","start","request","method","url","queryParams","userId","requestId","tap","body","statusCode","duration","statusCodeSuccess","statusCodeFailure","statusCodeError","meta","isValidBody","catchError","error","throwError","__decorateClass","Injectable","__decorateParam","Inject","SysWatchService","Catch","HttpException","Inject","Logger","LoggerException","sysWatch","exception","host","Logger","ctx","request","response","method","url","queryParams","userId","requestId","status","body","HttpException","statusCodeFailure","statusCodeError","meta","__decorateClass","Catch","__decorateParam","Inject","SysWatchService"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@syswatch/nestjs",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "NestJS module for SysWatch SDK",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"@nestjs/common": "^10.0.0",
|
|
32
32
|
"@nestjs/core": "^10.0.0",
|
|
33
33
|
"@nestjs/platform-express": "^10.0.0",
|
|
34
|
-
"@syswatch/core": "
|
|
34
|
+
"@syswatch/core": "^1.0.5",
|
|
35
35
|
"@types/node": "^20.0.0",
|
|
36
36
|
"reflect-metadata": "^0.2.0",
|
|
37
37
|
"rxjs": "^7.8.1",
|