@cryptexlabs/codex-nodejs-common 0.16.6 → 0.16.8

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/lib/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cryptexlabs/codex-nodejs-common",
3
- "version": "0.16.5",
3
+ "version": "0.16.7",
4
4
  "description": "Common code for Codex framework",
5
5
  "main": "lib/src/index.js",
6
6
  "type": "commonjs",
@@ -22,9 +22,11 @@
22
22
  "@nestjs/platform-ws": "8.0.6",
23
23
  "@nestjs/swagger": "5.0.9",
24
24
  "@nestjs/websockets": "8.0.6",
25
+ "@types/i18n": "0.12.0",
25
26
  "axios": "^1.7.7",
26
27
  "class-transformer": "^0.5.1",
27
28
  "class-validator": "^0.14.1",
29
+ "i18n": "^0.15.3",
28
30
  "rxjs": "^7.1.0"
29
31
  },
30
32
  "resolutions": {
@@ -37,7 +39,6 @@
37
39
  "@cryptexlabs/merge-anything": "^6.0.6",
38
40
  "@types/express": "4.17.8",
39
41
  "@types/express-serve-static-core": "4.17.24",
40
- "@types/i18n": "0.12.0",
41
42
  "@types/joi": "14.3.4",
42
43
  "@types/jsonwebtoken": "8.5.5",
43
44
  "@types/node": "20",
@@ -46,8 +47,6 @@
46
47
  "express": "4.17.1",
47
48
  "fastq": "1.13.0",
48
49
  "glob": "9.3.5",
49
- "i18n": "0.13.2",
50
- "install-peers-cli": "2.2.0",
51
50
  "joi": "17.3.0",
52
51
  "js-yaml": "3.14.1",
53
52
  "jsonwebtoken": "8.5.1",
@@ -67,6 +66,7 @@
67
66
  "@types/supertest": "2.0.10",
68
67
  "@types/uuid": "8.3.1",
69
68
  "husky": "4.3.6",
69
+ "install-peers-cli": "2.2.0",
70
70
  "jest": "28.1.0",
71
71
  "nodemon": "2.0.6",
72
72
  "prettier": "2.2.1",
@@ -18,3 +18,4 @@ export * from "./pagination-config.interface";
18
18
  export * from "./xray-config.interface";
19
19
  export * from "./logging-config.interface";
20
20
  export * from "./redis-config.interface";
21
+ export * from "./telemetry-config.interface";
@@ -34,4 +34,5 @@ __exportStar(require("./pagination-config.interface"), exports);
34
34
  __exportStar(require("./xray-config.interface"), exports);
35
35
  __exportStar(require("./logging-config.interface"), exports);
36
36
  __exportStar(require("./redis-config.interface"), exports);
37
+ __exportStar(require("./telemetry-config.interface"), exports);
37
38
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/config/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8EAA4D;AAC5D,mDAAiC;AACjC,wDAAsC;AACtC,gEAA8C;AAC9C,8DAA4C;AAC5C,0DAAwC;AACxC,yDAAuC;AACvC,wDAAsC;AACtC,4DAA0C;AAC1C,kDAAgC;AAChC,0DAAwC;AACxC,uDAAqC;AACrC,yDAAuC;AACvC,8DAA4C;AAC5C,4DAA0C;AAC1C,gEAA8C;AAC9C,gEAA8C;AAC9C,0DAAwC;AACxC,6DAA2C;AAC3C,2DAAyC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/config/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8EAA4D;AAC5D,mDAAiC;AACjC,wDAAsC;AACtC,gEAA8C;AAC9C,8DAA4C;AAC5C,0DAAwC;AACxC,yDAAuC;AACvC,wDAAsC;AACtC,4DAA0C;AAC1C,kDAAgC;AAChC,0DAAwC;AACxC,uDAAqC;AACrC,yDAAuC;AACvC,8DAA4C;AAC5C,4DAA0C;AAC1C,gEAA8C;AAC9C,gEAA8C;AAC9C,0DAAwC;AACxC,6DAA2C;AAC3C,2DAAyC;AACzC,+DAA6C"}
@@ -3,6 +3,5 @@ import { Context } from "../context";
3
3
  export declare class FriendlyHttpException extends HttpException {
4
4
  readonly context: Context;
5
5
  readonly userMessage: string;
6
- readonly stack: string;
7
- constructor(response: string | Record<string, any>, context: Context, userMessage: string, status: HttpStatus, stack: string);
6
+ constructor(response: string | Record<string, any>, context: Context, userMessage: string, status: HttpStatus, customStack?: string);
8
7
  }
@@ -3,11 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FriendlyHttpException = void 0;
4
4
  const common_1 = require("@nestjs/common");
5
5
  class FriendlyHttpException extends common_1.HttpException {
6
- constructor(response, context, userMessage, status, stack) {
6
+ constructor(response, context, userMessage, status, customStack) {
7
7
  super(response, status);
8
8
  this.context = context;
9
9
  this.userMessage = userMessage;
10
- this.stack = stack;
10
+ if (customStack) {
11
+ this.stack = customStack;
12
+ }
13
+ else {
14
+ Error.captureStackTrace(this, this.constructor);
15
+ }
11
16
  }
12
17
  }
13
18
  exports.FriendlyHttpException = FriendlyHttpException;
@@ -1 +1 @@
1
- {"version":3,"file":"friendly-http-exception.js","sourceRoot":"","sources":["../../../src/exception/friendly-http-exception.ts"],"names":[],"mappings":";;;AAAA,2CAA2D;AAG3D,MAAa,qBAAsB,SAAQ,sBAAa;IACtD,YACE,QAAsC,EACtB,OAAgB,EAChB,WAAmB,EACnC,MAAkB,EAEF,KAAa;QAE7B,KAAK,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QANR,YAAO,GAAP,OAAO,CAAS;QAChB,gBAAW,GAAX,WAAW,CAAQ;QAGnB,UAAK,GAAL,KAAK,CAAQ;IAG/B,CAAC;CACF;AAXD,sDAWC"}
1
+ {"version":3,"file":"friendly-http-exception.js","sourceRoot":"","sources":["../../../src/exception/friendly-http-exception.ts"],"names":[],"mappings":";;;AAAA,2CAA2D;AAG3D,MAAa,qBAAsB,SAAQ,sBAAa;IACtD,YACE,QAAsC,EACtB,OAAgB,EAChB,WAAmB,EACnC,MAAkB,EAElB,WAAoB;QAEpB,KAAK,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QANR,YAAO,GAAP,OAAO,CAAS;QAChB,gBAAW,GAAX,WAAW,CAAQ;QAMnC,IAAI,WAAW,EAAE,CAAC;YAChB,IAAI,CAAC,KAAK,GAAG,WAAW,CAAC;QAC3B,CAAC;aAAM,CAAC;YACN,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;QAClD,CAAC;IACH,CAAC;CACF;AAhBD,sDAgBC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cryptexlabs/codex-nodejs-common",
3
- "version": "0.16.6",
3
+ "version": "0.16.8",
4
4
  "description": "Common code for Codex framework",
5
5
  "main": "lib/src/index.js",
6
6
  "type": "commonjs",
@@ -22,9 +22,11 @@
22
22
  "@nestjs/platform-ws": "8.0.6",
23
23
  "@nestjs/swagger": "5.0.9",
24
24
  "@nestjs/websockets": "8.0.6",
25
+ "@types/i18n": "0.12.0",
25
26
  "axios": "^1.7.7",
26
27
  "class-transformer": "^0.5.1",
27
28
  "class-validator": "^0.14.1",
29
+ "i18n": "^0.15.3",
28
30
  "rxjs": "^7.1.0"
29
31
  },
30
32
  "resolutions": {
@@ -37,7 +39,6 @@
37
39
  "@cryptexlabs/merge-anything": "^6.0.6",
38
40
  "@types/express": "4.17.8",
39
41
  "@types/express-serve-static-core": "4.17.24",
40
- "@types/i18n": "0.12.0",
41
42
  "@types/joi": "14.3.4",
42
43
  "@types/jsonwebtoken": "8.5.5",
43
44
  "@types/node": "20",
@@ -46,8 +47,6 @@
46
47
  "express": "4.17.1",
47
48
  "fastq": "1.13.0",
48
49
  "glob": "9.3.5",
49
- "i18n": "0.13.2",
50
- "install-peers-cli": "2.2.0",
51
50
  "joi": "17.3.0",
52
51
  "js-yaml": "3.14.1",
53
52
  "jsonwebtoken": "8.5.1",
@@ -67,6 +66,7 @@
67
66
  "@types/supertest": "2.0.10",
68
67
  "@types/uuid": "8.3.1",
69
68
  "husky": "4.3.6",
69
+ "install-peers-cli": "2.2.0",
70
70
  "jest": "28.1.0",
71
71
  "nodemon": "2.0.6",
72
72
  "prettier": "2.2.1",
@@ -18,3 +18,4 @@ export * from "./pagination-config.interface";
18
18
  export * from "./xray-config.interface";
19
19
  export * from "./logging-config.interface";
20
20
  export * from "./redis-config.interface";
21
+ export * from "./telemetry-config.interface";
@@ -0,0 +1,99 @@
1
+ import { FriendlyHttpException } from "./friendly-http-exception";
2
+ import { HttpStatus, LoggerService } from "@nestjs/common";
3
+ import { Context } from "../context";
4
+ import { Locale, MessageContextInterface } from "@cryptexlabs/codex-data-model";
5
+ import { DefaultConfig } from "../config";
6
+ import { instance, mock, when } from "ts-mockito";
7
+
8
+ describe("FriendlyHttpException", () => {
9
+ let mockContext: Context;
10
+
11
+ beforeEach(() => {
12
+ const mockConfig = mock(DefaultConfig);
13
+ const config = instance(mockConfig);
14
+ when(mockConfig.logLevels).thenReturn(["info"]);
15
+ when(mockConfig.appName).thenReturn("test-app");
16
+ when(mockConfig.appVersion).thenReturn("1.0.0");
17
+ when(mockConfig.environmentName).thenReturn("test");
18
+ when(mockConfig.clientId).thenReturn("test-client");
19
+
20
+ const mockLogger = mock<LoggerService>();
21
+ const logger = instance(mockLogger);
22
+
23
+ const mockMessageContext = mock<MessageContextInterface>();
24
+ const messageContext = instance(mockMessageContext);
25
+
26
+ mockContext = new Context(
27
+ "test-correlation-id",
28
+ logger,
29
+ config,
30
+ {
31
+ id: "client-id",
32
+ name: "client-name",
33
+ version: "1.0.0",
34
+ variant: "test",
35
+ },
36
+ new Locale("en", "US"),
37
+ messageContext
38
+ );
39
+ });
40
+
41
+ describe("stack trace handling", () => {
42
+ it("should capture stack trace automatically when no custom stack is provided", () => {
43
+ const exception = new FriendlyHttpException(
44
+ "Test error message",
45
+ mockContext,
46
+ "User friendly message",
47
+ HttpStatus.BAD_REQUEST
48
+ );
49
+
50
+ expect(exception.stack).toBeDefined();
51
+ expect(typeof exception.stack).toBe("string");
52
+ expect(exception.stack).toContain("FriendlyHttpException");
53
+ });
54
+
55
+ it("should use custom stack when provided", () => {
56
+ const customStack = "CustomStack\nLine1\nLine2";
57
+
58
+ const exception = new FriendlyHttpException(
59
+ "Test error message",
60
+ mockContext,
61
+ "User friendly message",
62
+ HttpStatus.BAD_REQUEST,
63
+ customStack
64
+ );
65
+
66
+ expect(exception.stack).toBe(customStack);
67
+ });
68
+
69
+ it("should have stack property accessible for logging", () => {
70
+ const exception = new FriendlyHttpException(
71
+ "Test error message",
72
+ mockContext,
73
+ "User friendly message",
74
+ HttpStatus.INTERNAL_SERVER_ERROR
75
+ );
76
+
77
+ expect(exception.stack).toBeDefined();
78
+ expect(exception.name).toBe("FriendlyHttpException");
79
+ });
80
+
81
+ it("should preserve other exception properties", () => {
82
+ const userMessage = "Something went wrong";
83
+ const response = "Developer error message";
84
+ const status = HttpStatus.NOT_FOUND;
85
+
86
+ const exception = new FriendlyHttpException(
87
+ response,
88
+ mockContext,
89
+ userMessage,
90
+ status
91
+ );
92
+
93
+ expect(exception.userMessage).toBe(userMessage);
94
+ expect(exception.context).toBe(mockContext);
95
+ expect(exception.getStatus()).toBe(status);
96
+ expect(exception.message).toBe(response);
97
+ });
98
+ });
99
+ });
@@ -8,8 +8,13 @@ export class FriendlyHttpException extends HttpException {
8
8
  public readonly userMessage: string,
9
9
  status: HttpStatus,
10
10
 
11
- public readonly stack: string
11
+ customStack?: string
12
12
  ) {
13
13
  super(response, status);
14
+ if (customStack) {
15
+ this.stack = customStack;
16
+ } else {
17
+ Error.captureStackTrace(this, this.constructor);
18
+ }
14
19
  }
15
20
  }