@expressots/core 1.9.1 → 2.1.0

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.
Files changed (39) hide show
  1. package/lib/CHANGELOG.md +60 -15
  2. package/lib/cjs/middleware/interfaces/cookie-parser.interface.js +2 -0
  3. package/lib/cjs/middleware/interfaces/cookie-session/cookie-session.interface.js +2 -0
  4. package/lib/cjs/middleware/interfaces/cookie-session/keygrip.interface.js +2 -0
  5. package/lib/cjs/middleware/middleware-resolver.js +4 -5
  6. package/lib/cjs/middleware/middleware-service.js +25 -0
  7. package/lib/cjs/types/middleware/index.d.ts +3 -0
  8. package/lib/cjs/types/middleware/index.d.ts.map +1 -1
  9. package/lib/cjs/types/middleware/interfaces/cookie-parser.interface.d.ts +10 -0
  10. package/lib/cjs/types/middleware/interfaces/cookie-parser.interface.d.ts.map +1 -0
  11. package/lib/cjs/types/middleware/interfaces/cookie-session/cookie-session.interface.d.ts +58 -0
  12. package/lib/cjs/types/middleware/interfaces/cookie-session/cookie-session.interface.d.ts.map +1 -0
  13. package/lib/cjs/types/middleware/interfaces/cookie-session/keygrip.interface.d.ts +28 -0
  14. package/lib/cjs/types/middleware/interfaces/cookie-session/keygrip.interface.d.ts.map +1 -0
  15. package/lib/cjs/types/middleware/middleware-service.d.ts +28 -0
  16. package/lib/cjs/types/middleware/middleware-service.d.ts.map +1 -1
  17. package/lib/esm/middleware/interfaces/cookie-parser.interface.js +2 -0
  18. package/lib/esm/middleware/interfaces/cookie-session/cookie-session.interface.js +2 -0
  19. package/lib/esm/middleware/interfaces/cookie-session/keygrip.interface.js +2 -0
  20. package/lib/esm/middleware/middleware-resolver.js +4 -5
  21. package/lib/esm/middleware/middleware-service.js +25 -0
  22. package/lib/esm/types/middleware/index.d.ts +3 -0
  23. package/lib/esm/types/middleware/index.d.ts.map +1 -1
  24. package/lib/esm/types/middleware/interfaces/cookie-parser.interface.d.ts +10 -0
  25. package/lib/esm/types/middleware/interfaces/cookie-parser.interface.d.ts.map +1 -0
  26. package/lib/esm/types/middleware/interfaces/cookie-session/cookie-session.interface.d.ts +58 -0
  27. package/lib/esm/types/middleware/interfaces/cookie-session/cookie-session.interface.d.ts.map +1 -0
  28. package/lib/esm/types/middleware/interfaces/cookie-session/keygrip.interface.d.ts +28 -0
  29. package/lib/esm/types/middleware/interfaces/cookie-session/keygrip.interface.d.ts.map +1 -0
  30. package/lib/esm/types/middleware/middleware-service.d.ts +28 -0
  31. package/lib/esm/types/middleware/middleware-service.d.ts.map +1 -1
  32. package/lib/package.json +2 -7
  33. package/package.json +2 -7
  34. package/lib/cjs/provider/logger/winston-logger.js +0 -131
  35. package/lib/cjs/types/provider/logger/winston-logger.d.ts +0 -46
  36. package/lib/cjs/types/provider/logger/winston-logger.d.ts.map +0 -1
  37. package/lib/esm/provider/logger/winston-logger.js +0 -132
  38. package/lib/esm/types/provider/logger/winston-logger.d.ts +0 -46
  39. package/lib/esm/types/provider/logger/winston-logger.d.ts.map +0 -1
package/lib/CHANGELOG.md CHANGED
@@ -1,39 +1,84 @@
1
1
 
2
2
 
3
- ## [1.9.0](https://github.com/expressots/expressots/compare/1.8.1...1.9.0) (2023-09-12)
4
-
3
+ ## [2.1.0](https://github.com/expressots/expressots/compare/2.0.0...2.1.0) (2023-09-16)
4
+
5
+
6
+ ### Features
7
+
8
+ * add cookie-parser middleware ([2fe9377](https://github.com/expressots/expressots/commit/2fe93776423355503211a0d96f2b1952e3bc6320))
9
+ * add cookie-parser middleware ([a53a0c2](https://github.com/expressots/expressots/commit/a53a0c2e23dafc188286cd0ff5a6145cf3416ad0))
10
+ * add cookie-session middleware ([323c2d3](https://github.com/expressots/expressots/commit/323c2d32c5e4a9c78f19fe47807f323139fb306a))
11
+ * add cookie-session middleware ([60ac1fa](https://github.com/expressots/expressots/commit/60ac1fa36b2a8388983be0ab8f2d8a1696089d78))
12
+
13
+
14
+ ### Bug Fixes
15
+
16
+ * create folder for interface and print pck name instead of curated name ([2a47508](https://github.com/expressots/expressots/commit/2a47508f5170950ddd8b471fffc8d43a8fb57e32))
17
+
18
+ ## [2.0.0](https://github.com/expressots/expressots/compare/1.9.1...2.0.0) (2023-09-14)
5
19
 
6
20
  ### Features
7
21
 
8
- * add pck resolver & remove chalk dependency ([6bbd415](https://github.com/expressots/expressots/commit/6bbd415937159e419116b6ade8f9852c3251fbf4))
9
- * bump vitest from 0.34.3 to 0.34.4 ([#92](https://github.com/expressots/expressots/issues/92)) ([89dc682](https://github.com/expressots/expressots/commit/89dc682c7047897f01fd7770591b6ffea689d137))
22
+ - add middleware resolver ([23b8d9f](https://github.com/expressots/expressots/commit/23b8d9ff8f0c8b4bb893f4fd0d7f39afcb7dd1cd))
23
+ - add app factory
24
+ - add services layer
25
+ - add middleware interfaces for cors, compression, bodyparser and generic middleware
26
+ - add configurable error handler
27
+ - separate expressjs from core library in its own library called adapter-express
28
+ - created provider mechanism to share resources between multiple adapters
29
+ - eliminate chalk, inversify utils dependencies
30
+ - create a logger system using stdout
10
31
 
32
+ ### Code Refactoring
11
33
 
12
- ### Bug Fixes
34
+ - refactor error handling
35
+ - remove winston lib for loggin ([5868bc9](https://github.com/expressots/expressots/commit/5868bc949f2242f0a9bfe5483642bb3878cc0156))
36
+ - removing unnecessary dependencies ([fdd43e0](https://github.com/expressots/expressots/commit/fdd43e0f280024b8e4b53f392ea56842a091898e))
13
37
 
14
- * disable console.spec to be refactored ([22a54bd](https://github.com/expressots/expressots/commit/22a54bdb7f0c2032d3b0e0f935ce48d73e665e84))
15
- * dto validator json structure per property ([a8fbe40](https://github.com/expressots/expressots/commit/a8fbe409647140e867f930a882fd395df45d6de7))
16
- * export console for testing ([d3f2c07](https://github.com/expressots/expressots/commit/d3f2c07ca2df0176fabed04172ce4ff684c91c9c))
17
- * opinionated template logger.error function ([073f4e1](https://github.com/expressots/expressots/commit/073f4e154732fa3fed9492ec772c36894bc3cf48))
18
- * replace dto interface for class opinionated template ([3e99d7c](https://github.com/expressots/expressots/commit/3e99d7c5492ff64701e754ec845a0410da442296))
19
- * use new report utility in usecases ([#91](https://github.com/expressots/expressots/issues/91)) ([d1477b2](https://github.com/expressots/expressots/commit/d1477b24f932e354fb55373e8e73fe9155289486))
38
+ ## [1.9.1](https://github.com/expressots/expressots/compare/1.9.0...1.9.1) (2023-09-14)
20
39
 
40
+ ### Bug Fixes
41
+
42
+ - add peer dependency @expressots/adapter-express ([874db40](https://github.com/expressots/expressots/commit/874db402af7bac8d5ac638fc206f3daf9f707fc3))
43
+ - change esm config to modeule interop ([32f04b5](https://github.com/expressots/expressots/commit/32f04b5bc7da6c515df70b0156f2f5cadd5526ac))
44
+ - change esm config to modeule interop ([978b168](https://github.com/expressots/expressots/commit/978b1685aa18c0573313ee96049159a1c95c4d87))
45
+ - opinionated template app provider services ([bcb55ca](https://github.com/expressots/expressots/commit/bcb55caf1e5a0ff053b5aaf89a79ef4537b38161))
46
+ - using adapter-express dependency ([84b0348](https://github.com/expressots/expressots/commit/84b03486193632b84e46e670bd44c6f8a01ebaa4))
21
47
 
22
48
  ### Code Refactoring
23
49
 
24
- * update type from any to number ([#90](https://github.com/expressots/expressots/issues/90)) ([5e34a44](https://github.com/expressots/expressots/commit/5e34a44d8bd353b8d3834f198f36bf73aa521845))
50
+ - create express adapter platform ([784beaa](https://github.com/expressots/expressots/commit/784beaaea9247e304abada8ebd33c673199e35f9))
51
+ - expose app base class for adapter ([36d8dec](https://github.com/expressots/expressots/commit/36d8dec0435a2456d1b9e1d5dca5bfb8956cfdea))
25
52
 
26
- ## [1.8.1](https://github.com/expressots/expressots/compare/1.8.0...1.8.1) (2023-09-10)
53
+ ## [1.9.0](https://github.com/expressots/expressots/compare/1.8.1...1.9.0) (2023-09-12)
27
54
 
55
+ ### Features
56
+
57
+ - add pck resolver & remove chalk dependency ([6bbd415](https://github.com/expressots/expressots/commit/6bbd415937159e419116b6ade8f9852c3251fbf4))
58
+ - bump vitest from 0.34.3 to 0.34.4 ([#92](https://github.com/expressots/expressots/issues/92)) ([89dc682](https://github.com/expressots/expressots/commit/89dc682c7047897f01fd7770591b6ffea689d137))
28
59
 
29
60
  ### Bug Fixes
30
61
 
31
- * add generic in memory db and virtual table analysis ([#86](https://github.com/expressots/expressots/issues/86)) ([29541f9](https://github.com/expressots/expressots/commit/29541f997e47c8ac5f8cafbb0195c34c904454f4))
62
+ - disable console.spec to be refactored ([22a54bd](https://github.com/expressots/expressots/commit/22a54bdb7f0c2032d3b0e0f935ce48d73e665e84))
63
+ - dto validator json structure per property ([a8fbe40](https://github.com/expressots/expressots/commit/a8fbe409647140e867f930a882fd395df45d6de7))
64
+ - export console for testing ([d3f2c07](https://github.com/expressots/expressots/commit/d3f2c07ca2df0176fabed04172ce4ff684c91c9c))
65
+ - opinionated template logger.error function ([073f4e1](https://github.com/expressots/expressots/commit/073f4e154732fa3fed9492ec772c36894bc3cf48))
66
+ - replace dto interface for class opinionated template ([3e99d7c](https://github.com/expressots/expressots/commit/3e99d7c5492ff64701e754ec845a0410da442296))
67
+ - use new report utility in usecases ([#91](https://github.com/expressots/expressots/issues/91)) ([d1477b2](https://github.com/expressots/expressots/commit/d1477b24f932e354fb55373e8e73fe9155289486))
68
+
69
+ ### Code Refactoring
70
+
71
+ - update type from any to number ([#90](https://github.com/expressots/expressots/issues/90)) ([5e34a44](https://github.com/expressots/expressots/commit/5e34a44d8bd353b8d3834f198f36bf73aa521845))
72
+
73
+ ## [1.8.1](https://github.com/expressots/expressots/compare/1.8.0...1.8.1) (2023-09-10)
74
+
75
+ ### Bug Fixes
32
76
 
77
+ - add generic in memory db and virtual table analysis ([#86](https://github.com/expressots/expressots/issues/86)) ([29541f9](https://github.com/expressots/expressots/commit/29541f997e47c8ac5f8cafbb0195c34c904454f4))
33
78
 
34
79
  ### Continuous Integrations
35
80
 
36
- * config test workflow and setup vitest ([#88](https://github.com/expressots/expressots/issues/88)) ([67316ce](https://github.com/expressots/expressots/commit/67316cece977f04f9750a5a5af6cd88dfc695e0d))
81
+ - config test workflow and setup vitest ([#88](https://github.com/expressots/expressots/issues/88)) ([67316ce](https://github.com/expressots/expressots/commit/67316cece977f04f9750a5a5af6cd88dfc695e0d))
37
82
 
38
83
  ## [1.8.0](https://github.com/expressots/expressots/compare/1.7.0...1.8.0) (2023-09-05)
39
84
 
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -17,6 +17,8 @@ class MiddlewareResolver {
17
17
  this.middlewareRegistry = {
18
18
  cors: "cors",
19
19
  compression: "compression",
20
+ cookieParser: "cookie-parser",
21
+ cookieSession: "cookie-session",
20
22
  // Add other middlewares
21
23
  };
22
24
  this.logger = new logger_service_1.Logger();
@@ -31,7 +33,7 @@ class MiddlewareResolver {
31
33
  getMiddleware(middlewareName, ...options) {
32
34
  const packageName = this.middlewareRegistry[middlewareName];
33
35
  if (!packageName) {
34
- console.error(`Middleware ${middlewareName} not found`);
36
+ this.logger.error(`Middleware ${packageName} not found`, "middleware-resolver");
35
37
  return null;
36
38
  }
37
39
  let hasMiddleware = "";
@@ -39,16 +41,13 @@ class MiddlewareResolver {
39
41
  hasMiddleware = require.resolve(packageName, { paths: [process.cwd()] });
40
42
  }
41
43
  catch (error) {
42
- this.logger.warn(`Middleware [${middlewareName}] not installed. Please install it using your package manager.`, "middleware-resolver");
44
+ this.logger.warn(`Middleware [${packageName}] not installed. Please install it using your package manager.`, "middleware-resolver");
43
45
  }
44
46
  if (hasMiddleware) {
45
47
  // eslint-disable-next-line @typescript-eslint/no-var-requires
46
48
  const middleware = require(hasMiddleware);
47
49
  return middleware(...options) || middleware.default(...options);
48
50
  }
49
- else {
50
- this.logger.warn(`Middleware [${middlewareName}] not installed. Please install it using your package manager.`, "middleware-resolver");
51
- }
52
51
  return null;
53
52
  }
54
53
  }
@@ -78,6 +78,31 @@ let Middleware = Middleware_1 = class Middleware {
78
78
  this.middlewares.push(middleware);
79
79
  }
80
80
  }
81
+ /**
82
+ * Adds Cookie Parser middleware to parse the cookie header and populate req.cookies with an object keyed by the cookie names.
83
+ *
84
+ * @param secret - A string or array used for signing cookies. This is optional and if not specified, the cookie-parser will not parse signed cookies.
85
+ * @param options - Optional configuration options for Cookie Parser.
86
+ */
87
+ addCookieParser(secret, options) {
88
+ const middleware = (0, middleware_resolver_1.middlewareResolver)("cookieParser", secret, options);
89
+ const middlewareExist = this.middlewareExists("cookieParser");
90
+ if (middleware && !middlewareExist) {
91
+ this.middlewares.push(middleware);
92
+ }
93
+ }
94
+ /**
95
+ * Adds Cookie Session middleware to enable cookie-based sessions.
96
+ *
97
+ * @param options - Optional configuration options for Cookie Session. Defines the behavior of cookie sessions like the name of the cookie, keys to sign the cookie, etc.
98
+ */
99
+ addCookieSession(options) {
100
+ const middleware = (0, middleware_resolver_1.middlewareResolver)("cookieSession", options);
101
+ const middlewareExist = this.middlewareExists("cookieSession");
102
+ if (middleware && !middlewareExist) {
103
+ this.middlewares.push(middleware);
104
+ }
105
+ }
81
106
  /**
82
107
  * Configures the error handling middleware for the application.
83
108
  *
@@ -2,4 +2,7 @@ export { IMiddleware, Middleware } from "./middleware-service";
2
2
  export { OptionsJson } from "./interfaces/body-parser.interface";
3
3
  export { CorsOptions } from "./interfaces/cors.interface";
4
4
  export { CompressionOptions } from "./interfaces/compression.interface";
5
+ export { CookieSessionOptions } from "./interfaces/cookie-session/cookie-session.interface";
6
+ export { Keygrip } from "./interfaces/cookie-session/keygrip.interface";
7
+ export { CookieParserOptions } from "./interfaces/cookie-parser.interface";
5
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/middleware/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/middleware/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AACxE,OAAO,EAAE,oBAAoB,EAAE,MAAM,sDAAsD,CAAC;AAC5F,OAAO,EAAE,OAAO,EAAE,MAAM,+CAA+C,CAAC;AACxE,OAAO,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC"}
@@ -0,0 +1,10 @@
1
+ interface CookieParserOptions {
2
+ /**
3
+ * A function used for decoding cookies.
4
+ * By default, `decodeURIComponent` is used.
5
+ * You can provide a custom decoding function here.
6
+ */
7
+ decode?(val: string): string;
8
+ }
9
+ export { CookieParserOptions };
10
+ //# sourceMappingURL=cookie-parser.interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cookie-parser.interface.d.ts","sourceRoot":"","sources":["../../../../../packages/core/src/middleware/interfaces/cookie-parser.interface.ts"],"names":[],"mappings":"AAAA,UAAU,mBAAmB;IAC3B;;;;OAIG;IACH,MAAM,CAAC,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CAC9B;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAC"}
@@ -0,0 +1,58 @@
1
+ import { Keygrip } from "./keygrip.interface";
2
+ interface CookieSessionOptions {
3
+ /**
4
+ * The name of the cookie to set, defaults to session.
5
+ */
6
+ name?: string | undefined;
7
+ /**
8
+ * The list of keys to use to sign & verify cookie values. Set cookies are always signed with keys[0], while the other keys are valid for verification, allowing for key rotation.
9
+ */
10
+ keys: Array<string> | Keygrip;
11
+ /**
12
+ * A string which will be used as single key if keys is not provided.
13
+ */
14
+ secret?: string | undefined;
15
+ /**
16
+ * a number representing the milliseconds from Date.now() for expiry.
17
+ */
18
+ maxAge?: number | undefined;
19
+ /**
20
+ * a Date object indicating the cookie's expiration date (expires at the end of session by default).
21
+ */
22
+ expires?: Date | undefined;
23
+ /**
24
+ * a string indicating the path of the cookie (/ by default).
25
+ */
26
+ path?: string | undefined;
27
+ /**
28
+ * a string indicating the domain of the cookie (no default).
29
+ */
30
+ domain?: string | undefined;
31
+ /**
32
+ * a boolean or string indicating whether the cookie is a "same site" cookie (false by default). This can be set to 'strict', 'lax', 'none', or true (which maps to 'strict').
33
+ */
34
+ sameSite?: "strict" | "lax" | "none" | boolean | undefined;
35
+ /**
36
+ * a boolean indicating whether the cookie is only to be sent over HTTPS (false by default for HTTP, true by default for HTTPS).
37
+ */
38
+ secure?: boolean | undefined;
39
+ /**
40
+ * a boolean indicating whether the cookie is only to be sent over HTTPS (use this if you handle SSL not in your node process).
41
+ */
42
+ secureProxy?: boolean | undefined;
43
+ /**
44
+ * a boolean indicating whether the cookie is only to be sent over HTTP(S), and not made available to client JavaScript (true by default).
45
+ */
46
+ httpOnly?: boolean | undefined;
47
+ /**
48
+ * a boolean indicating whether the cookie is to be signed (true by default). If this is true, another cookie of the same name with the .sig suffix appended will also be sent, with a 27-byte url-safe base64 SHA1 value representing the hash of cookie-name=cookie-value against the
49
+ * first Keygrip key. This signature key is used to detect tampering the next time a cookie is received.
50
+ */
51
+ signed?: boolean | undefined;
52
+ /**
53
+ * a boolean indicating whether to overwrite previously set cookies of the same name (true by default). If this is true, all cookies set during the same request with the same name (regardless of path or domain) are filtered out of the Set-Cookie header when setting this cookie.
54
+ */
55
+ overwrite?: boolean | undefined;
56
+ }
57
+ export { CookieSessionOptions };
58
+ //# sourceMappingURL=cookie-session.interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cookie-session.interface.d.ts","sourceRoot":"","sources":["../../../../../../packages/core/src/middleware/interfaces/cookie-session/cookie-session.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAE9C,UAAU,oBAAoB;IAC5B;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAE1B;;OAEG;IACH,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC;IAE9B;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAE5B;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAE5B;;OAEG;IACH,OAAO,CAAC,EAAE,IAAI,GAAG,SAAS,CAAC;IAE3B;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAE1B;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAE5B;;OAEG;IACH,QAAQ,CAAC,EAAE,QAAQ,GAAG,KAAK,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC;IAE3D;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAE7B;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAElC;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAE/B;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAE7B;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CACjC;AAED,OAAO,EAAE,oBAAoB,EAAE,CAAC"}
@@ -0,0 +1,28 @@
1
+ interface Keygrip {
2
+ /**
3
+ * Signs the provided data and returns the signature as a string.
4
+ * @param data Data to be signed.
5
+ * @returns Signature string.
6
+ */
7
+ sign(data: any): string;
8
+ /**
9
+ * Verifies the provided data against a given digest (signature).
10
+ * @param data Data to be verified.
11
+ * @param digest Signature to verify against.
12
+ * @returns True if the verification is successful, otherwise false.
13
+ */
14
+ verify(data: any, digest: string): boolean;
15
+ /**
16
+ * Retrieves the index of the provided data in relation to a given digest (signature).
17
+ * @param data Data to find the index for.
18
+ * @param digest Signature to search for.
19
+ * @returns Index of the data, or -1 if not found.
20
+ */
21
+ index(data: any, digest: string): number;
22
+ }
23
+ interface KeygripFunction {
24
+ new (keys: ReadonlyArray<string>, algorithm?: string, encoding?: string): Keygrip;
25
+ (keys: ReadonlyArray<string>, algorithm?: string, encoding?: string): Keygrip;
26
+ }
27
+ export { KeygripFunction as Keygrip };
28
+ //# sourceMappingURL=keygrip.interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keygrip.interface.d.ts","sourceRoot":"","sources":["../../../../../../packages/core/src/middleware/interfaces/cookie-session/keygrip.interface.ts"],"names":[],"mappings":"AACA,UAAU,OAAO;IACf;;;;OAIG;IAEH,IAAI,CAAC,IAAI,EAAE,GAAG,GAAG,MAAM,CAAC;IAExB;;;;;OAKG;IAEH,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC;IAE3C;;;;;OAKG;IAEH,KAAK,CAAC,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;CAC1C;AAGD,UAAU,eAAe;IACvB,KACE,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,EAC3B,SAAS,CAAC,EAAE,MAAM,EAClB,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC;IACX,CAAC,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,EAAE,SAAS,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CAC/E;AAGD,OAAO,EAAE,eAAe,IAAI,OAAO,EAAE,CAAC"}
@@ -2,7 +2,9 @@ import express from "express";
2
2
  import { OptionsJson } from "./interfaces/body-parser.interface";
3
3
  import { CompressionOptions } from "./interfaces/compression.interface";
4
4
  import { CorsOptions } from "./interfaces/cors.interface";
5
+ import { CookieParserOptions } from "./interfaces/cookie-parser.interface";
5
6
  import { ServeStaticOptions } from "./interfaces/serve-static.interface";
7
+ import { CookieSessionOptions } from "./interfaces/cookie-session/cookie-session.interface";
6
8
  type ExpressHandler = express.ErrorRequestHandler | express.RequestParamHandler | express.RequestHandler | undefined;
7
9
  /**
8
10
  * Interface for configuring and managing middlewares in the application.
@@ -28,6 +30,19 @@ interface IMiddleware {
28
30
  * @param options - Optional configuration options for Compression. Allows fine-tuning the compression behavior, such as setting the compression level, threshold, and filter functions to determine which requests should be compressed.
29
31
  */
30
32
  addCompression(options?: CompressionOptions): void;
33
+ /**
34
+ * Adds Cookie Parser middleware to parse the cookie header and populate req.cookies with an object keyed by the cookie names.
35
+ *
36
+ * @param secret - A string or array used for signing cookies. This is optional and if not specified, the cookie-parser will not parse signed cookies.
37
+ * @param options - Optional configuration options for Cookie Parser.
38
+ */
39
+ addCookieParser(secret?: string | Array<string> | undefined, options?: CookieParserOptions): void;
40
+ /**
41
+ * Adds Cookie Session middleware to enable cookie-based sessions.
42
+ *
43
+ * @param options - Optional configuration options for Cookie Session. Defines the behavior of cookie sessions like the name of the cookie, keys to sign the cookie, etc.
44
+ */
45
+ addCookieSession(options: CookieSessionOptions): void;
31
46
  /**
32
47
  * Configures the error handling middleware for the application.
33
48
  *
@@ -99,6 +114,19 @@ declare class Middleware implements IMiddleware {
99
114
  * @param options - Optional configuration options for Compression. Allows fine-tuning the compression behavior, such as setting the compression level, threshold, and filter functions to determine which requests should be compressed.
100
115
  */
101
116
  addCompression(options?: CompressionOptions): void;
117
+ /**
118
+ * Adds Cookie Parser middleware to parse the cookie header and populate req.cookies with an object keyed by the cookie names.
119
+ *
120
+ * @param secret - A string or array used for signing cookies. This is optional and if not specified, the cookie-parser will not parse signed cookies.
121
+ * @param options - Optional configuration options for Cookie Parser.
122
+ */
123
+ addCookieParser(secret?: string | Array<string> | undefined, options?: CookieParserOptions | undefined): void;
124
+ /**
125
+ * Adds Cookie Session middleware to enable cookie-based sessions.
126
+ *
127
+ * @param options - Optional configuration options for Cookie Session. Defines the behavior of cookie sessions like the name of the cookie, keys to sign the cookie, etc.
128
+ */
129
+ addCookieSession(options: CookieSessionOptions): void;
102
130
  /**
103
131
  * Configures the error handling middleware for the application.
104
132
  *
@@ -1 +1 @@
1
- {"version":3,"file":"middleware-service.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/middleware/middleware-service.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAI9B,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AACxE,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AAGzE,KAAK,cAAc,GACf,OAAO,CAAC,mBAAmB,GAC3B,OAAO,CAAC,mBAAmB,GAC3B,OAAO,CAAC,cAAc,GACtB,SAAS,CAAC;AAEd;;;GAGG;AACH,UAAU,WAAW;IACnB;;;;;OAKG;IACH,aAAa,CAAC,OAAO,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;IAE3C;;;;OAIG;IACH,OAAO,CAAC,OAAO,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;IAErC;;;;OAIG;IACH,cAAc,CAAC,OAAO,CAAC,EAAE,kBAAkB,GAAG,IAAI,CAAC;IAEnD;;;;OAIG;IACH,eAAe,CAAC,aAAa,CAAC,EAAE,cAAc,GAAG,IAAI,CAAC;IAEtD;;;;;;OAMG;IACH,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,IAAI,CAAC;IAE9D;;;;;OAKG;IACH,aAAa,CAAC,UAAU,EAAE,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC;IAExD;;;;OAIG;IACH,cAAc,IAAI,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;IAEhD;;;;OAIG;IACH,eAAe,IAAI,cAAc,CAAC;CACnC;AAED;;;;;;GAMG;AACH,cACM,UAAW,YAAW,WAAW;IACrC,OAAO,CAAC,WAAW,CAAqC;IACxD,OAAO,CAAC,YAAY,CAA6B;IACjD,OAAO,CAAC,MAAM,CAAwB;IAEtC;;;;;;OAMG;IACH,OAAO,CAAC,gBAAgB;IASxB;;;;OAIG;IACI,aAAa,CAAC,OAAO,CAAC,EAAE,WAAW,GAAG,IAAI;IAajD;;;;OAIG;IACH,OAAO,CAAC,OAAO,CAAC,EAAE,WAAW,GAAG,IAAI;IASpC;;;;OAIG;IACH,cAAc,CAAC,OAAO,CAAC,EAAE,kBAAkB,GAAG,IAAI;IAUlD;;;;OAIG;IACH,eAAe,CAAC,aAAa,CAAC,EAAE,cAAc,GAAG,IAAI;IAQrD;;;;;;OAMG;IACH,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,IAAI;IAa7D;;;;;OAKG;IACH,aAAa,CAAC,UAAU,EAAE,OAAO,CAAC,cAAc,GAAG,IAAI;IAavD;;;;OAIG;IACI,cAAc,IAAI,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC;IAItD;;;;OAIG;IACI,eAAe,IAAI,cAAc;CAGzC;AAED,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC"}
1
+ {"version":3,"file":"middleware-service.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/middleware/middleware-service.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -20,6 +20,8 @@ class MiddlewareResolver {
20
20
  middlewareRegistry = {
21
21
  cors: "cors",
22
22
  compression: "compression",
23
+ cookieParser: "cookie-parser",
24
+ cookieSession: "cookie-session",
23
25
  // Add other middlewares
24
26
  };
25
27
  /**
@@ -32,7 +34,7 @@ class MiddlewareResolver {
32
34
  getMiddleware(middlewareName, ...options) {
33
35
  const packageName = this.middlewareRegistry[middlewareName];
34
36
  if (!packageName) {
35
- console.error(`Middleware ${middlewareName} not found`);
37
+ this.logger.error(`Middleware ${packageName} not found`, "middleware-resolver");
36
38
  return null;
37
39
  }
38
40
  let hasMiddleware = "";
@@ -40,16 +42,13 @@ class MiddlewareResolver {
40
42
  hasMiddleware = require.resolve(packageName, { paths: [process.cwd()] });
41
43
  }
42
44
  catch (error) {
43
- this.logger.warn(`Middleware [${middlewareName}] not installed. Please install it using your package manager.`, "middleware-resolver");
45
+ this.logger.warn(`Middleware [${packageName}] not installed. Please install it using your package manager.`, "middleware-resolver");
44
46
  }
45
47
  if (hasMiddleware) {
46
48
  // eslint-disable-next-line @typescript-eslint/no-var-requires
47
49
  const middleware = require(hasMiddleware);
48
50
  return middleware(...options) || middleware.default(...options);
49
51
  }
50
- else {
51
- this.logger.warn(`Middleware [${middlewareName}] not installed. Please install it using your package manager.`, "middleware-resolver");
52
- }
53
52
  return null;
54
53
  }
55
54
  }
@@ -77,6 +77,31 @@ let Middleware = Middleware_1 = class Middleware {
77
77
  this.middlewares.push(middleware);
78
78
  }
79
79
  }
80
+ /**
81
+ * Adds Cookie Parser middleware to parse the cookie header and populate req.cookies with an object keyed by the cookie names.
82
+ *
83
+ * @param secret - A string or array used for signing cookies. This is optional and if not specified, the cookie-parser will not parse signed cookies.
84
+ * @param options - Optional configuration options for Cookie Parser.
85
+ */
86
+ addCookieParser(secret, options) {
87
+ const middleware = (0, middleware_resolver_1.middlewareResolver)("cookieParser", secret, options);
88
+ const middlewareExist = this.middlewareExists("cookieParser");
89
+ if (middleware && !middlewareExist) {
90
+ this.middlewares.push(middleware);
91
+ }
92
+ }
93
+ /**
94
+ * Adds Cookie Session middleware to enable cookie-based sessions.
95
+ *
96
+ * @param options - Optional configuration options for Cookie Session. Defines the behavior of cookie sessions like the name of the cookie, keys to sign the cookie, etc.
97
+ */
98
+ addCookieSession(options) {
99
+ const middleware = (0, middleware_resolver_1.middlewareResolver)("cookieSession", options);
100
+ const middlewareExist = this.middlewareExists("cookieSession");
101
+ if (middleware && !middlewareExist) {
102
+ this.middlewares.push(middleware);
103
+ }
104
+ }
80
105
  /**
81
106
  * Configures the error handling middleware for the application.
82
107
  *
@@ -2,4 +2,7 @@ export { IMiddleware, Middleware } from "./middleware-service";
2
2
  export { OptionsJson } from "./interfaces/body-parser.interface";
3
3
  export { CorsOptions } from "./interfaces/cors.interface";
4
4
  export { CompressionOptions } from "./interfaces/compression.interface";
5
+ export { CookieSessionOptions } from "./interfaces/cookie-session/cookie-session.interface";
6
+ export { Keygrip } from "./interfaces/cookie-session/keygrip.interface";
7
+ export { CookieParserOptions } from "./interfaces/cookie-parser.interface";
5
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/middleware/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/middleware/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AACxE,OAAO,EAAE,oBAAoB,EAAE,MAAM,sDAAsD,CAAC;AAC5F,OAAO,EAAE,OAAO,EAAE,MAAM,+CAA+C,CAAC;AACxE,OAAO,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC"}
@@ -0,0 +1,10 @@
1
+ interface CookieParserOptions {
2
+ /**
3
+ * A function used for decoding cookies.
4
+ * By default, `decodeURIComponent` is used.
5
+ * You can provide a custom decoding function here.
6
+ */
7
+ decode?(val: string): string;
8
+ }
9
+ export { CookieParserOptions };
10
+ //# sourceMappingURL=cookie-parser.interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cookie-parser.interface.d.ts","sourceRoot":"","sources":["../../../../../packages/core/src/middleware/interfaces/cookie-parser.interface.ts"],"names":[],"mappings":"AAAA,UAAU,mBAAmB;IAC3B;;;;OAIG;IACH,MAAM,CAAC,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CAC9B;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAC"}
@@ -0,0 +1,58 @@
1
+ import { Keygrip } from "./keygrip.interface";
2
+ interface CookieSessionOptions {
3
+ /**
4
+ * The name of the cookie to set, defaults to session.
5
+ */
6
+ name?: string | undefined;
7
+ /**
8
+ * The list of keys to use to sign & verify cookie values. Set cookies are always signed with keys[0], while the other keys are valid for verification, allowing for key rotation.
9
+ */
10
+ keys: Array<string> | Keygrip;
11
+ /**
12
+ * A string which will be used as single key if keys is not provided.
13
+ */
14
+ secret?: string | undefined;
15
+ /**
16
+ * a number representing the milliseconds from Date.now() for expiry.
17
+ */
18
+ maxAge?: number | undefined;
19
+ /**
20
+ * a Date object indicating the cookie's expiration date (expires at the end of session by default).
21
+ */
22
+ expires?: Date | undefined;
23
+ /**
24
+ * a string indicating the path of the cookie (/ by default).
25
+ */
26
+ path?: string | undefined;
27
+ /**
28
+ * a string indicating the domain of the cookie (no default).
29
+ */
30
+ domain?: string | undefined;
31
+ /**
32
+ * a boolean or string indicating whether the cookie is a "same site" cookie (false by default). This can be set to 'strict', 'lax', 'none', or true (which maps to 'strict').
33
+ */
34
+ sameSite?: "strict" | "lax" | "none" | boolean | undefined;
35
+ /**
36
+ * a boolean indicating whether the cookie is only to be sent over HTTPS (false by default for HTTP, true by default for HTTPS).
37
+ */
38
+ secure?: boolean | undefined;
39
+ /**
40
+ * a boolean indicating whether the cookie is only to be sent over HTTPS (use this if you handle SSL not in your node process).
41
+ */
42
+ secureProxy?: boolean | undefined;
43
+ /**
44
+ * a boolean indicating whether the cookie is only to be sent over HTTP(S), and not made available to client JavaScript (true by default).
45
+ */
46
+ httpOnly?: boolean | undefined;
47
+ /**
48
+ * a boolean indicating whether the cookie is to be signed (true by default). If this is true, another cookie of the same name with the .sig suffix appended will also be sent, with a 27-byte url-safe base64 SHA1 value representing the hash of cookie-name=cookie-value against the
49
+ * first Keygrip key. This signature key is used to detect tampering the next time a cookie is received.
50
+ */
51
+ signed?: boolean | undefined;
52
+ /**
53
+ * a boolean indicating whether to overwrite previously set cookies of the same name (true by default). If this is true, all cookies set during the same request with the same name (regardless of path or domain) are filtered out of the Set-Cookie header when setting this cookie.
54
+ */
55
+ overwrite?: boolean | undefined;
56
+ }
57
+ export { CookieSessionOptions };
58
+ //# sourceMappingURL=cookie-session.interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cookie-session.interface.d.ts","sourceRoot":"","sources":["../../../../../../packages/core/src/middleware/interfaces/cookie-session/cookie-session.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAE9C,UAAU,oBAAoB;IAC5B;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAE1B;;OAEG;IACH,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC;IAE9B;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAE5B;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAE5B;;OAEG;IACH,OAAO,CAAC,EAAE,IAAI,GAAG,SAAS,CAAC;IAE3B;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAE1B;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAE5B;;OAEG;IACH,QAAQ,CAAC,EAAE,QAAQ,GAAG,KAAK,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC;IAE3D;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAE7B;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAElC;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAE/B;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAE7B;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CACjC;AAED,OAAO,EAAE,oBAAoB,EAAE,CAAC"}
@@ -0,0 +1,28 @@
1
+ interface Keygrip {
2
+ /**
3
+ * Signs the provided data and returns the signature as a string.
4
+ * @param data Data to be signed.
5
+ * @returns Signature string.
6
+ */
7
+ sign(data: any): string;
8
+ /**
9
+ * Verifies the provided data against a given digest (signature).
10
+ * @param data Data to be verified.
11
+ * @param digest Signature to verify against.
12
+ * @returns True if the verification is successful, otherwise false.
13
+ */
14
+ verify(data: any, digest: string): boolean;
15
+ /**
16
+ * Retrieves the index of the provided data in relation to a given digest (signature).
17
+ * @param data Data to find the index for.
18
+ * @param digest Signature to search for.
19
+ * @returns Index of the data, or -1 if not found.
20
+ */
21
+ index(data: any, digest: string): number;
22
+ }
23
+ interface KeygripFunction {
24
+ new (keys: ReadonlyArray<string>, algorithm?: string, encoding?: string): Keygrip;
25
+ (keys: ReadonlyArray<string>, algorithm?: string, encoding?: string): Keygrip;
26
+ }
27
+ export { KeygripFunction as Keygrip };
28
+ //# sourceMappingURL=keygrip.interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keygrip.interface.d.ts","sourceRoot":"","sources":["../../../../../../packages/core/src/middleware/interfaces/cookie-session/keygrip.interface.ts"],"names":[],"mappings":"AACA,UAAU,OAAO;IACf;;;;OAIG;IAEH,IAAI,CAAC,IAAI,EAAE,GAAG,GAAG,MAAM,CAAC;IAExB;;;;;OAKG;IAEH,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC;IAE3C;;;;;OAKG;IAEH,KAAK,CAAC,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;CAC1C;AAGD,UAAU,eAAe;IACvB,KACE,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,EAC3B,SAAS,CAAC,EAAE,MAAM,EAClB,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC;IACX,CAAC,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,EAAE,SAAS,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CAC/E;AAGD,OAAO,EAAE,eAAe,IAAI,OAAO,EAAE,CAAC"}
@@ -2,7 +2,9 @@ import express from "express";
2
2
  import { OptionsJson } from "./interfaces/body-parser.interface";
3
3
  import { CompressionOptions } from "./interfaces/compression.interface";
4
4
  import { CorsOptions } from "./interfaces/cors.interface";
5
+ import { CookieParserOptions } from "./interfaces/cookie-parser.interface";
5
6
  import { ServeStaticOptions } from "./interfaces/serve-static.interface";
7
+ import { CookieSessionOptions } from "./interfaces/cookie-session/cookie-session.interface";
6
8
  type ExpressHandler = express.ErrorRequestHandler | express.RequestParamHandler | express.RequestHandler | undefined;
7
9
  /**
8
10
  * Interface for configuring and managing middlewares in the application.
@@ -28,6 +30,19 @@ interface IMiddleware {
28
30
  * @param options - Optional configuration options for Compression. Allows fine-tuning the compression behavior, such as setting the compression level, threshold, and filter functions to determine which requests should be compressed.
29
31
  */
30
32
  addCompression(options?: CompressionOptions): void;
33
+ /**
34
+ * Adds Cookie Parser middleware to parse the cookie header and populate req.cookies with an object keyed by the cookie names.
35
+ *
36
+ * @param secret - A string or array used for signing cookies. This is optional and if not specified, the cookie-parser will not parse signed cookies.
37
+ * @param options - Optional configuration options for Cookie Parser.
38
+ */
39
+ addCookieParser(secret?: string | Array<string> | undefined, options?: CookieParserOptions): void;
40
+ /**
41
+ * Adds Cookie Session middleware to enable cookie-based sessions.
42
+ *
43
+ * @param options - Optional configuration options for Cookie Session. Defines the behavior of cookie sessions like the name of the cookie, keys to sign the cookie, etc.
44
+ */
45
+ addCookieSession(options: CookieSessionOptions): void;
31
46
  /**
32
47
  * Configures the error handling middleware for the application.
33
48
  *
@@ -99,6 +114,19 @@ declare class Middleware implements IMiddleware {
99
114
  * @param options - Optional configuration options for Compression. Allows fine-tuning the compression behavior, such as setting the compression level, threshold, and filter functions to determine which requests should be compressed.
100
115
  */
101
116
  addCompression(options?: CompressionOptions): void;
117
+ /**
118
+ * Adds Cookie Parser middleware to parse the cookie header and populate req.cookies with an object keyed by the cookie names.
119
+ *
120
+ * @param secret - A string or array used for signing cookies. This is optional and if not specified, the cookie-parser will not parse signed cookies.
121
+ * @param options - Optional configuration options for Cookie Parser.
122
+ */
123
+ addCookieParser(secret?: string | Array<string> | undefined, options?: CookieParserOptions | undefined): void;
124
+ /**
125
+ * Adds Cookie Session middleware to enable cookie-based sessions.
126
+ *
127
+ * @param options - Optional configuration options for Cookie Session. Defines the behavior of cookie sessions like the name of the cookie, keys to sign the cookie, etc.
128
+ */
129
+ addCookieSession(options: CookieSessionOptions): void;
102
130
  /**
103
131
  * Configures the error handling middleware for the application.
104
132
  *
@@ -1 +1 @@
1
- {"version":3,"file":"middleware-service.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/middleware/middleware-service.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAI9B,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AACxE,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AAGzE,KAAK,cAAc,GACf,OAAO,CAAC,mBAAmB,GAC3B,OAAO,CAAC,mBAAmB,GAC3B,OAAO,CAAC,cAAc,GACtB,SAAS,CAAC;AAEd;;;GAGG;AACH,UAAU,WAAW;IACnB;;;;;OAKG;IACH,aAAa,CAAC,OAAO,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;IAE3C;;;;OAIG;IACH,OAAO,CAAC,OAAO,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;IAErC;;;;OAIG;IACH,cAAc,CAAC,OAAO,CAAC,EAAE,kBAAkB,GAAG,IAAI,CAAC;IAEnD;;;;OAIG;IACH,eAAe,CAAC,aAAa,CAAC,EAAE,cAAc,GAAG,IAAI,CAAC;IAEtD;;;;;;OAMG;IACH,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,IAAI,CAAC;IAE9D;;;;;OAKG;IACH,aAAa,CAAC,UAAU,EAAE,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC;IAExD;;;;OAIG;IACH,cAAc,IAAI,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;IAEhD;;;;OAIG;IACH,eAAe,IAAI,cAAc,CAAC;CACnC;AAED;;;;;;GAMG;AACH,cACM,UAAW,YAAW,WAAW;IACrC,OAAO,CAAC,WAAW,CAAqC;IACxD,OAAO,CAAC,YAAY,CAA6B;IACjD,OAAO,CAAC,MAAM,CAAwB;IAEtC;;;;;;OAMG;IACH,OAAO,CAAC,gBAAgB;IASxB;;;;OAIG;IACI,aAAa,CAAC,OAAO,CAAC,EAAE,WAAW,GAAG,IAAI;IAajD;;;;OAIG;IACH,OAAO,CAAC,OAAO,CAAC,EAAE,WAAW,GAAG,IAAI;IASpC;;;;OAIG;IACH,cAAc,CAAC,OAAO,CAAC,EAAE,kBAAkB,GAAG,IAAI;IAUlD;;;;OAIG;IACH,eAAe,CAAC,aAAa,CAAC,EAAE,cAAc,GAAG,IAAI;IAQrD;;;;;;OAMG;IACH,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,IAAI;IAa7D;;;;;OAKG;IACH,aAAa,CAAC,UAAU,EAAE,OAAO,CAAC,cAAc,GAAG,IAAI;IAavD;;;;OAIG;IACI,cAAc,IAAI,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC;IAItD;;;;OAIG;IACI,eAAe,IAAI,cAAc;CAGzC;AAED,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC"}
1
+ {"version":3,"file":"middleware-service.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/middleware/middleware-service.ts"],"names":[],"mappings":"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"}
package/lib/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@expressots/core",
3
- "version": "1.9.0",
3
+ "version": "2.1.0",
4
4
  "description": "Expressots - modern, fast, lightweight nodejs web framework (@core)",
5
5
  "author": "Richard Zampieri",
6
6
  "main": "./lib/cjs/index.js",
@@ -68,14 +68,9 @@
68
68
  "lint:fix": "eslint \"packages/**/*.ts\" --fix"
69
69
  },
70
70
  "dependencies": {
71
- "dotenv": "^16.0.3",
72
- "express": "^4.18.2",
73
71
  "inversify": "^6.0.1",
74
72
  "inversify-binding-decorators": "^4.0.0",
75
- "inversify-express-utils": "^6.4.3",
76
- "reflect-metadata": "^0.1.13",
77
- "winston": "^3.8.2",
78
- "winston-daily-rotate-file": "^4.7.1"
73
+ "reflect-metadata": "^0.1.13"
79
74
  },
80
75
  "devDependencies": {
81
76
  "@commitlint/cli": "^17.7.1",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@expressots/core",
3
- "version": "1.9.1",
3
+ "version": "2.1.0",
4
4
  "description": "Expressots - modern, fast, lightweight nodejs web framework (@core)",
5
5
  "author": "Richard Zampieri",
6
6
  "main": "./lib/cjs/index.js",
@@ -68,14 +68,9 @@
68
68
  "lint:fix": "eslint \"packages/**/*.ts\" --fix"
69
69
  },
70
70
  "dependencies": {
71
- "dotenv": "^16.0.3",
72
- "express": "^4.18.2",
73
71
  "inversify": "^6.0.1",
74
72
  "inversify-binding-decorators": "^4.0.0",
75
- "inversify-express-utils": "^6.4.3",
76
- "reflect-metadata": "^0.1.13",
77
- "winston": "^3.8.2",
78
- "winston-daily-rotate-file": "^4.7.1"
73
+ "reflect-metadata": "^0.1.13"
79
74
  },
80
75
  "devDependencies": {
81
76
  "@commitlint/cli": "^17.7.1",
@@ -1,131 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- var GeneralLogger_1;
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.log = exports.GeneralLogger = exports.LogLevel = void 0;
17
- const inversify_binding_decorators_1 = require("inversify-binding-decorators");
18
- const winston_1 = require("winston");
19
- const winston_daily_rotate_file_1 = __importDefault(require("winston-daily-rotate-file"));
20
- /**
21
- * LogLevel enumeration defines the available log levels.
22
- */
23
- var LogLevel;
24
- (function (LogLevel) {
25
- LogLevel[LogLevel["Debug"] = 0] = "Debug";
26
- LogLevel[LogLevel["Error"] = 1] = "Error";
27
- LogLevel[LogLevel["Info"] = 2] = "Info";
28
- })(LogLevel || (exports.LogLevel = LogLevel = {}));
29
- /**
30
- * GeneralLogger class is a utility class to manage logging within the application.
31
- */
32
- let GeneralLogger = GeneralLogger_1 = class GeneralLogger {
33
- constructor() {
34
- this.logger = (0, winston_1.createLogger)(this.createLoggerOptions());
35
- }
36
- /**
37
- * Creates a console transport for logging.
38
- * @returns {transports.ConsoleTransportInstance} A Winston console transport instance.
39
- */
40
- createConsoleTransport() {
41
- const consoleTransport = new winston_1.transports.Console({
42
- level: (process.env.ENVIRONMENT !== "Development" && "debug") || "debug",
43
- handleExceptions: false,
44
- handleRejections: true,
45
- });
46
- return consoleTransport;
47
- }
48
- /**
49
- * Creates a rotational file transport for logging.
50
- * @returns {DailyRotateFile} A Winston daily rotate file transport instance.
51
- */
52
- createRotationalFileTransport() {
53
- const rotationalFileTransport = new winston_daily_rotate_file_1.default({
54
- level: "error",
55
- filename: "logs/general-%DATE%.log",
56
- datePattern: "YYYY-MM-DD",
57
- zippedArchive: true,
58
- maxSize: "20m",
59
- maxFiles: "7d",
60
- silent: false,
61
- });
62
- return rotationalFileTransport;
63
- }
64
- /**
65
- * Creates a logger options object for Winston.
66
- * @returns {LoggerOptions} A Winston logger options object.
67
- */
68
- createLoggerOptions() {
69
- const loggerOptions = {
70
- transports: [
71
- this.createConsoleTransport(),
72
- this.createRotationalFileTransport(),
73
- ],
74
- defaultMeta: { service: "service-unknown" },
75
- format: winston_1.format.combine(winston_1.format.splat(), winston_1.format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }), winston_1.format.label({ label: "core-api" }), winston_1.format.printf(({ timestamp, level, message, service, label }) => {
76
- return `[${timestamp}] [${label}] [${service}] ${level}: ${message}`;
77
- })),
78
- };
79
- return loggerOptions;
80
- }
81
- /**
82
- * Retrieves the path and line number of the error.
83
- * @param error - An Error object containing error details.
84
- * @returns {string} A string containing the path and line number of the error.
85
- */
86
- getPathAndLine(error) {
87
- let pathLine = "";
88
- if (error.stack) {
89
- const callerLine = error.stack.split("\n")[1];
90
- const index = callerLine.indexOf("at ");
91
- pathLine = callerLine.substring(index + +2, callerLine.length);
92
- }
93
- return pathLine;
94
- }
95
- /**
96
- * Logs a message or error with the specified log level and service.
97
- * @param logLevel - The log level to use (Debug, Error, or Info).
98
- * @param content - The message or Error object to log.
99
- * @param service - The service name (optional) associated with the log.
100
- */
101
- log(logLevel, content, service) {
102
- let pathLine = "";
103
- let logMessageFormat = "";
104
- if (typeof content === "object") {
105
- pathLine = this.getPathAndLine(content);
106
- logMessageFormat = `${content.message} - (${content.name}) [file: %s]`;
107
- }
108
- else {
109
- logMessageFormat = content;
110
- }
111
- switch (logLevel) {
112
- case LogLevel.Debug:
113
- console.log(logMessageFormat, pathLine, { service });
114
- break;
115
- case LogLevel.Error:
116
- this.logger.error(logMessageFormat, pathLine, { service });
117
- break;
118
- case LogLevel.Info:
119
- this.logger.info(content, { service });
120
- break;
121
- }
122
- }
123
- };
124
- exports.GeneralLogger = GeneralLogger;
125
- exports.GeneralLogger = GeneralLogger = GeneralLogger_1 = __decorate([
126
- (0, inversify_binding_decorators_1.provide)(GeneralLogger_1),
127
- __metadata("design:paramtypes", [])
128
- ], GeneralLogger);
129
- const Log = new GeneralLogger();
130
- const log = Log.log.bind(Log);
131
- exports.log = log;
@@ -1,46 +0,0 @@
1
- /**
2
- * LogLevel enumeration defines the available log levels.
3
- */
4
- declare enum LogLevel {
5
- Debug = 0,
6
- Error = 1,
7
- Info = 2
8
- }
9
- /**
10
- * GeneralLogger class is a utility class to manage logging within the application.
11
- */
12
- declare class GeneralLogger {
13
- private logger;
14
- constructor();
15
- /**
16
- * Creates a console transport for logging.
17
- * @returns {transports.ConsoleTransportInstance} A Winston console transport instance.
18
- */
19
- private createConsoleTransport;
20
- /**
21
- * Creates a rotational file transport for logging.
22
- * @returns {DailyRotateFile} A Winston daily rotate file transport instance.
23
- */
24
- private createRotationalFileTransport;
25
- /**
26
- * Creates a logger options object for Winston.
27
- * @returns {LoggerOptions} A Winston logger options object.
28
- */
29
- private createLoggerOptions;
30
- /**
31
- * Retrieves the path and line number of the error.
32
- * @param error - An Error object containing error details.
33
- * @returns {string} A string containing the path and line number of the error.
34
- */
35
- private getPathAndLine;
36
- /**
37
- * Logs a message or error with the specified log level and service.
38
- * @param logLevel - The log level to use (Debug, Error, or Info).
39
- * @param content - The message or Error object to log.
40
- * @param service - The service name (optional) associated with the log.
41
- */
42
- log(logLevel: LogLevel, content: Error | string, service?: string): void;
43
- }
44
- declare const log: (logLevel: LogLevel, content: Error | string, service?: string) => void;
45
- export { LogLevel, GeneralLogger, log };
46
- //# sourceMappingURL=winston-logger.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"winston-logger.d.ts","sourceRoot":"","sources":["../../../../../packages/core/src/provider/logger/winston-logger.ts"],"names":[],"mappings":"AAUA;;GAEG;AACH,aAAK,QAAQ;IACX,KAAK,IAAA;IACL,KAAK,IAAA;IACL,IAAI,IAAA;CACL;AAED;;GAEG;AACH,cACM,aAAa;IACjB,OAAO,CAAC,MAAM,CAAS;;IAMvB;;;OAGG;IACH,OAAO,CAAC,sBAAsB;IAY9B;;;OAGG;IACH,OAAO,CAAC,6BAA6B;IAcrC;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IAoB3B;;;;OAIG;IACH,OAAO,CAAC,cAAc;IAYtB;;;;;OAKG;IACI,GAAG,CACR,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,KAAK,GAAG,MAAM,EACvB,OAAO,CAAC,EAAE,MAAM,GACf,IAAI;CAyBR;AAGD,QAAA,MAAM,GAAG,aA/BK,QAAQ,WACT,KAAK,GAAG,MAAM,YACb,MAAM,KACf,IA4BwB,CAAC;AAE9B,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,GAAG,EAAE,CAAC"}
@@ -1,132 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- var GeneralLogger_1;
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.log = exports.GeneralLogger = exports.LogLevel = void 0;
17
- const inversify_binding_decorators_1 = require("inversify-binding-decorators");
18
- const winston_1 = require("winston");
19
- const winston_daily_rotate_file_1 = __importDefault(require("winston-daily-rotate-file"));
20
- /**
21
- * LogLevel enumeration defines the available log levels.
22
- */
23
- var LogLevel;
24
- (function (LogLevel) {
25
- LogLevel[LogLevel["Debug"] = 0] = "Debug";
26
- LogLevel[LogLevel["Error"] = 1] = "Error";
27
- LogLevel[LogLevel["Info"] = 2] = "Info";
28
- })(LogLevel || (exports.LogLevel = LogLevel = {}));
29
- /**
30
- * GeneralLogger class is a utility class to manage logging within the application.
31
- */
32
- let GeneralLogger = GeneralLogger_1 = class GeneralLogger {
33
- logger;
34
- constructor() {
35
- this.logger = (0, winston_1.createLogger)(this.createLoggerOptions());
36
- }
37
- /**
38
- * Creates a console transport for logging.
39
- * @returns {transports.ConsoleTransportInstance} A Winston console transport instance.
40
- */
41
- createConsoleTransport() {
42
- const consoleTransport = new winston_1.transports.Console({
43
- level: (process.env.ENVIRONMENT !== "Development" && "debug") || "debug",
44
- handleExceptions: false,
45
- handleRejections: true,
46
- });
47
- return consoleTransport;
48
- }
49
- /**
50
- * Creates a rotational file transport for logging.
51
- * @returns {DailyRotateFile} A Winston daily rotate file transport instance.
52
- */
53
- createRotationalFileTransport() {
54
- const rotationalFileTransport = new winston_daily_rotate_file_1.default({
55
- level: "error",
56
- filename: "logs/general-%DATE%.log",
57
- datePattern: "YYYY-MM-DD",
58
- zippedArchive: true,
59
- maxSize: "20m",
60
- maxFiles: "7d",
61
- silent: false,
62
- });
63
- return rotationalFileTransport;
64
- }
65
- /**
66
- * Creates a logger options object for Winston.
67
- * @returns {LoggerOptions} A Winston logger options object.
68
- */
69
- createLoggerOptions() {
70
- const loggerOptions = {
71
- transports: [
72
- this.createConsoleTransport(),
73
- this.createRotationalFileTransport(),
74
- ],
75
- defaultMeta: { service: "service-unknown" },
76
- format: winston_1.format.combine(winston_1.format.splat(), winston_1.format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }), winston_1.format.label({ label: "core-api" }), winston_1.format.printf(({ timestamp, level, message, service, label }) => {
77
- return `[${timestamp}] [${label}] [${service}] ${level}: ${message}`;
78
- })),
79
- };
80
- return loggerOptions;
81
- }
82
- /**
83
- * Retrieves the path and line number of the error.
84
- * @param error - An Error object containing error details.
85
- * @returns {string} A string containing the path and line number of the error.
86
- */
87
- getPathAndLine(error) {
88
- let pathLine = "";
89
- if (error.stack) {
90
- const callerLine = error.stack.split("\n")[1];
91
- const index = callerLine.indexOf("at ");
92
- pathLine = callerLine.substring(index + +2, callerLine.length);
93
- }
94
- return pathLine;
95
- }
96
- /**
97
- * Logs a message or error with the specified log level and service.
98
- * @param logLevel - The log level to use (Debug, Error, or Info).
99
- * @param content - The message or Error object to log.
100
- * @param service - The service name (optional) associated with the log.
101
- */
102
- log(logLevel, content, service) {
103
- let pathLine = "";
104
- let logMessageFormat = "";
105
- if (typeof content === "object") {
106
- pathLine = this.getPathAndLine(content);
107
- logMessageFormat = `${content.message} - (${content.name}) [file: %s]`;
108
- }
109
- else {
110
- logMessageFormat = content;
111
- }
112
- switch (logLevel) {
113
- case LogLevel.Debug:
114
- console.log(logMessageFormat, pathLine, { service });
115
- break;
116
- case LogLevel.Error:
117
- this.logger.error(logMessageFormat, pathLine, { service });
118
- break;
119
- case LogLevel.Info:
120
- this.logger.info(content, { service });
121
- break;
122
- }
123
- }
124
- };
125
- exports.GeneralLogger = GeneralLogger;
126
- exports.GeneralLogger = GeneralLogger = GeneralLogger_1 = __decorate([
127
- (0, inversify_binding_decorators_1.provide)(GeneralLogger_1),
128
- __metadata("design:paramtypes", [])
129
- ], GeneralLogger);
130
- const Log = new GeneralLogger();
131
- const log = Log.log.bind(Log);
132
- exports.log = log;
@@ -1,46 +0,0 @@
1
- /**
2
- * LogLevel enumeration defines the available log levels.
3
- */
4
- declare enum LogLevel {
5
- Debug = 0,
6
- Error = 1,
7
- Info = 2
8
- }
9
- /**
10
- * GeneralLogger class is a utility class to manage logging within the application.
11
- */
12
- declare class GeneralLogger {
13
- private logger;
14
- constructor();
15
- /**
16
- * Creates a console transport for logging.
17
- * @returns {transports.ConsoleTransportInstance} A Winston console transport instance.
18
- */
19
- private createConsoleTransport;
20
- /**
21
- * Creates a rotational file transport for logging.
22
- * @returns {DailyRotateFile} A Winston daily rotate file transport instance.
23
- */
24
- private createRotationalFileTransport;
25
- /**
26
- * Creates a logger options object for Winston.
27
- * @returns {LoggerOptions} A Winston logger options object.
28
- */
29
- private createLoggerOptions;
30
- /**
31
- * Retrieves the path and line number of the error.
32
- * @param error - An Error object containing error details.
33
- * @returns {string} A string containing the path and line number of the error.
34
- */
35
- private getPathAndLine;
36
- /**
37
- * Logs a message or error with the specified log level and service.
38
- * @param logLevel - The log level to use (Debug, Error, or Info).
39
- * @param content - The message or Error object to log.
40
- * @param service - The service name (optional) associated with the log.
41
- */
42
- log(logLevel: LogLevel, content: Error | string, service?: string): void;
43
- }
44
- declare const log: (logLevel: LogLevel, content: Error | string, service?: string) => void;
45
- export { LogLevel, GeneralLogger, log };
46
- //# sourceMappingURL=winston-logger.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"winston-logger.d.ts","sourceRoot":"","sources":["../../../../../packages/core/src/provider/logger/winston-logger.ts"],"names":[],"mappings":"AAUA;;GAEG;AACH,aAAK,QAAQ;IACX,KAAK,IAAA;IACL,KAAK,IAAA;IACL,IAAI,IAAA;CACL;AAED;;GAEG;AACH,cACM,aAAa;IACjB,OAAO,CAAC,MAAM,CAAS;;IAMvB;;;OAGG;IACH,OAAO,CAAC,sBAAsB;IAY9B;;;OAGG;IACH,OAAO,CAAC,6BAA6B;IAcrC;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IAoB3B;;;;OAIG;IACH,OAAO,CAAC,cAAc;IAYtB;;;;;OAKG;IACI,GAAG,CACR,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,KAAK,GAAG,MAAM,EACvB,OAAO,CAAC,EAAE,MAAM,GACf,IAAI;CAyBR;AAGD,QAAA,MAAM,GAAG,aA/BK,QAAQ,WACT,KAAK,GAAG,MAAM,YACb,MAAM,KACf,IA4BwB,CAAC;AAE9B,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,GAAG,EAAE,CAAC"}