@villedemontreal/correlation-id 5.3.6 → 5.3.7

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 (38) hide show
  1. package/dist/config/configs.d.ts +16 -0
  2. package/dist/config/configs.js +15 -0
  3. package/dist/config/configs.js.map +1 -0
  4. package/dist/scripts/index.d.ts +2 -0
  5. package/dist/scripts/index.js +14 -0
  6. package/dist/scripts/index.js.map +1 -0
  7. package/dist/scripts/lint.d.ts +6 -0
  8. package/dist/scripts/lint.js +31 -0
  9. package/dist/scripts/lint.js.map +1 -0
  10. package/dist/scripts/lintFix.d.ts +6 -0
  11. package/dist/scripts/lintFix.js +40 -0
  12. package/dist/scripts/lintFix.js.map +1 -0
  13. package/dist/src/config/configs.d.ts +1 -1
  14. package/dist/src/config/configs.js.map +1 -1
  15. package/dist/src/config/constants.d.ts +1 -1
  16. package/dist/src/config/constants.js +1 -1
  17. package/dist/src/config/constants.js.map +1 -1
  18. package/dist/src/config/init.js.map +1 -1
  19. package/dist/src/middleware/correlationIdMiddleware.d.ts +1 -1
  20. package/dist/src/middleware/correlationIdMiddleware.js +1 -1
  21. package/dist/src/middleware/correlationIdMiddleware.js.map +1 -1
  22. package/dist/src/middleware/correlationIdMiddleware.test.js +112 -135
  23. package/dist/src/middleware/correlationIdMiddleware.test.js.map +1 -1
  24. package/dist/src/services/correlationIdService.d.ts +1 -1
  25. package/dist/src/services/correlationIdService.js +27 -16
  26. package/dist/src/services/correlationIdService.js.map +1 -1
  27. package/dist/src/services/correlationIdService.test.js +98 -79
  28. package/dist/src/services/correlationIdService.test.js.map +1 -1
  29. package/dist/src/utils/logger.js.map +1 -1
  30. package/package.json +10 -8
  31. package/src/config/configs.ts +4 -2
  32. package/src/config/constants.ts +2 -2
  33. package/src/config/init.ts +1 -1
  34. package/src/middleware/correlationIdMiddleware.test.ts +111 -77
  35. package/src/middleware/correlationIdMiddleware.ts +3 -3
  36. package/src/services/correlationIdService.test.ts +27 -19
  37. package/src/services/correlationIdService.ts +5 -7
  38. package/src/utils/logger.ts +8 -1
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Configurations for the application.
3
+ */
4
+ declare class Configs {
5
+ /**
6
+ * Absolute path to the root of the project.
7
+ */
8
+ root: string;
9
+ /**
10
+ * Absolute path to a directory to use for tests.
11
+ */
12
+ dataDirPath: string;
13
+ constructor();
14
+ }
15
+ export declare const configs: Configs;
16
+ export {};
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.configs = void 0;
4
+ const path = require("path");
5
+ /**
6
+ * Configurations for the application.
7
+ */
8
+ class Configs {
9
+ constructor() {
10
+ this.root = path.normalize(`${__dirname}/..`);
11
+ this.dataDirPath = `${this.root}/test-data`;
12
+ }
13
+ }
14
+ exports.configs = new Configs();
15
+ //# sourceMappingURL=configs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"configs.js","sourceRoot":"","sources":["../../config/configs.ts"],"names":[],"mappings":";;;AAAA,6BAA6B;AAE7B;;GAEG;AACH,MAAM,OAAO;IAWX;QACE,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,SAAS,KAAK,CAAC,CAAC;QAC9C,IAAI,CAAC,WAAW,GAAG,GAAG,IAAI,CAAC,IAAI,YAAY,CAAC;IAC9C,CAAC;CACF;AAEY,QAAA,OAAO,GAAY,IAAI,OAAO,EAAE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { LintScript } from './lint';
2
+ export { LintFixScript } from './lintFix';
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LintFixScript = exports.LintScript = void 0;
4
+ // ==========================================
5
+ // All scripts must be included here!
6
+ //
7
+ // The scripting library uses this index to quickly
8
+ // find all the scripts available in the application.
9
+ // ==========================================
10
+ var lint_1 = require("./lint");
11
+ Object.defineProperty(exports, "LintScript", { enumerable: true, get: function () { return lint_1.LintScript; } });
12
+ var lintFix_1 = require("./lintFix");
13
+ Object.defineProperty(exports, "LintFixScript", { enumerable: true, get: function () { return lintFix_1.LintFixScript; } });
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../scripts/index.ts"],"names":[],"mappings":";;;AAAA,6CAA6C;AAC7C,qCAAqC;AACrC,EAAE;AACF,mDAAmD;AACnD,qDAAqD;AACrD,6CAA6C;AAC7C,+BAAoC;AAA3B,kGAAA,UAAU,OAAA;AACnB,qCAA0C;AAAjC,wGAAA,aAAa,OAAA"}
@@ -0,0 +1,6 @@
1
+ import { ScriptBase } from '@villedemontreal/scripting/dist/src';
2
+ export declare class LintScript extends ScriptBase {
3
+ get name(): string;
4
+ get description(): string;
5
+ protected main(): Promise<void>;
6
+ }
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.LintScript = void 0;
13
+ const src_1 = require("@villedemontreal/scripting/dist/src");
14
+ const path_1 = require("path");
15
+ const configs_1 = require("../config/configs");
16
+ class LintScript extends src_1.ScriptBase {
17
+ get name() {
18
+ return 'lint';
19
+ }
20
+ get description() {
21
+ return `Run the ESLint validation (including ESLint and Prettier rules).`;
22
+ }
23
+ main() {
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ const projectRoot = (0, path_1.resolve)(`${configs_1.configs.root}/..`);
26
+ yield this.invokeShellCommand(`${projectRoot}/node_modules/.bin/eslint`, [projectRoot]);
27
+ });
28
+ }
29
+ }
30
+ exports.LintScript = LintScript;
31
+ //# sourceMappingURL=lint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lint.js","sourceRoot":"","sources":["../../scripts/lint.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6DAAiE;AACjE,+BAA+B;AAC/B,+CAA4C;AAC5C,MAAa,UAAW,SAAQ,gBAAU;IACxC,IAAI,IAAI;QACN,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,IAAI,WAAW;QACb,OAAO,kEAAkE,CAAC;IAC5E,CAAC;IAEe,IAAI;;YAClB,MAAM,WAAW,GAAG,IAAA,cAAO,EAAC,GAAG,iBAAO,CAAC,IAAI,KAAK,CAAC,CAAC;YAClD,MAAM,IAAI,CAAC,kBAAkB,CAAC,GAAG,WAAW,2BAA2B,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC;QAC1F,CAAC;KAAA;CACF;AAbD,gCAaC"}
@@ -0,0 +1,6 @@
1
+ import { ScriptBase } from '@villedemontreal/scripting/dist/src';
2
+ export declare class LintFixScript extends ScriptBase {
3
+ get name(): string;
4
+ get description(): string;
5
+ protected main(): Promise<void>;
6
+ }
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.LintFixScript = void 0;
13
+ const src_1 = require("@villedemontreal/scripting/dist/src");
14
+ const path_1 = require("path");
15
+ const configs_1 = require("../config/configs");
16
+ class LintFixScript extends src_1.ScriptBase {
17
+ get name() {
18
+ return 'lint-fix';
19
+ }
20
+ get description() {
21
+ return `Fix the code using ESLint and Prettier rules).`;
22
+ }
23
+ main() {
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ const projectRoot = (0, path_1.resolve)(`${configs_1.configs.root}/..`);
26
+ this.logger.info(`Fixing using Prettier rules`);
27
+ yield this.invokeShellCommand(`${projectRoot}/node_modules/.bin/prettier`, [
28
+ '--write',
29
+ projectRoot,
30
+ ]);
31
+ this.logger.info(`Fixing using ESLint rules`);
32
+ yield this.invokeShellCommand(`${projectRoot}/node_modules/.bin/eslint`, [
33
+ '--fix',
34
+ projectRoot,
35
+ ]);
36
+ });
37
+ }
38
+ }
39
+ exports.LintFixScript = LintFixScript;
40
+ //# sourceMappingURL=lintFix.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lintFix.js","sourceRoot":"","sources":["../../scripts/lintFix.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6DAAiE;AACjE,+BAA+B;AAC/B,+CAA4C;AAE5C,MAAa,aAAc,SAAQ,gBAAU;IAC3C,IAAI,IAAI;QACN,OAAO,UAAU,CAAC;IACpB,CAAC;IAED,IAAI,WAAW;QACb,OAAO,gDAAgD,CAAC;IAC1D,CAAC;IAEe,IAAI;;YAClB,MAAM,WAAW,GAAG,IAAA,cAAO,EAAC,GAAG,iBAAO,CAAC,IAAI,KAAK,CAAC,CAAC;YAClD,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAC;YAChD,MAAM,IAAI,CAAC,kBAAkB,CAAC,GAAG,WAAW,6BAA6B,EAAE;gBACzE,SAAS;gBACT,WAAW;aACZ,CAAC,CAAC;YAEH,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC;YAC9C,MAAM,IAAI,CAAC,kBAAkB,CAAC,GAAG,WAAW,2BAA2B,EAAE;gBACvE,OAAO;gBACP,WAAW;aACZ,CAAC,CAAC;QACL,CAAC;KAAA;CACF;AAvBD,sCAuBC"}
@@ -13,4 +13,4 @@ export declare class Configs {
13
13
  */
14
14
  get loggerCreator(): (name: string) => ILogger;
15
15
  }
16
- export declare let configs: Configs;
16
+ export declare const configs: Configs;
@@ -1 +1 @@
1
- {"version":3,"file":"configs.js","sourceRoot":"","sources":["../../../src/config/configs.ts"],"names":[],"mappings":";;;AAEA;;GAEG;AACH,MAAa,OAAO;IAGlB;;OAEG;IACI,gBAAgB,CAAC,aAAwC;QAC9D,IAAI,CAAC,gBAAgB,GAAG,aAAa,CAAC;IACxC,CAAC;IAED;;OAEG;IACH,IAAI,aAAa;QACf,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE;YAC1B,MAAM,IAAI,KAAK,CAAC,gGAAgG,CAAC,CAAC;SACnH;QACD,OAAO,IAAI,CAAC,gBAAgB,CAAC;IAC/B,CAAC;CACF;AAnBD,0BAmBC;AACU,QAAA,OAAO,GAAY,IAAI,OAAO,EAAE,CAAC"}
1
+ {"version":3,"file":"configs.js","sourceRoot":"","sources":["../../../src/config/configs.ts"],"names":[],"mappings":";;;AAEA;;GAEG;AACH,MAAa,OAAO;IAGlB;;OAEG;IACI,gBAAgB,CAAC,aAAwC;QAC9D,IAAI,CAAC,gBAAgB,GAAG,aAAa,CAAC;IACxC,CAAC;IAED;;OAEG;IACH,IAAI,aAAa;QACf,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE;YAC1B,MAAM,IAAI,KAAK,CACb,gGAAgG,CACjG,CAAC;SACH;QACD,OAAO,IAAI,CAAC,gBAAgB,CAAC;IAC/B,CAAC;CACF;AArBD,0BAqBC;AACY,QAAA,OAAO,GAAY,IAAI,OAAO,EAAE,CAAC"}
@@ -24,4 +24,4 @@ export declare class Constants {
24
24
  cidNew: string;
25
25
  };
26
26
  }
27
- export declare let constants: Constants;
27
+ export declare const constants: Constants;
@@ -18,7 +18,7 @@ class Constants {
18
18
  get requestExtraVariables() {
19
19
  return {
20
20
  cidReceivedInRequest: '_cidReceivedInRequest',
21
- cidNew: '_cidNew'
21
+ cidNew: '_cidNew',
22
22
  };
23
23
  }
24
24
  }
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/config/constants.ts"],"names":[],"mappings":";;;AAAA,iDAAgD;AAChD,6BAA6B;AAE7B;;GAEG;AACH,MAAa,SAAS;IAgBpB;QACE,oCAAoC;QACpC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,SAAS,GAAG,WAAW,CAAC,CAAC;QACvD,IAAI,CAAC,OAAO,GAAG,oBAAO,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,IAAI,qBAAqB;QACvB,OAAO;YACL,oBAAoB,EAAE,uBAAuB;YAC7C,MAAM,EAAE,SAAS;SAClB,CAAC;IACJ,CAAC;CACF;AA/BD,8BA+BC;AAEU,QAAA,SAAS,GAAc,IAAI,SAAS,EAAE,CAAC"}
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/config/constants.ts"],"names":[],"mappings":";;;AAAA,iDAAgD;AAChD,6BAA6B;AAE7B;;GAEG;AACH,MAAa,SAAS;IAgBpB;QACE,oCAAoC;QACpC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,SAAS,GAAG,WAAW,CAAC,CAAC;QACvD,IAAI,CAAC,OAAO,GAAG,oBAAO,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,IAAI,qBAAqB;QACvB,OAAO;YACL,oBAAoB,EAAE,uBAAuB;YAC7C,MAAM,EAAE,SAAS;SAClB,CAAC;IACJ,CAAC;CACF;AA/BD,8BA+BC;AAEY,QAAA,SAAS,GAAc,IAAI,SAAS,EAAE,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"init.js","sourceRoot":"","sources":["../../../src/config/init.ts"],"names":[],"mappings":";;;AACA,uCAAoC;AAEpC,IAAI,WAAW,GAAY,KAAK,CAAC;AAEjC;;GAEG;AACH,SAAgB,IAAI,CAAC,aAAwC;IAC3D,IAAI,CAAC,aAAa,EAAE;QAClB,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;KACpD;IACD,iBAAO,CAAC,gBAAgB,CAAC,aAAa,CAAC,CAAC;IAExC,6CAA6C;IAC7C,uCAAuC;IACvC,4CAA4C;IAC5C,6CAA6C;IAC7C,WAAW,GAAG,IAAI,CAAC;AACrB,CAAC;AAXD,oBAWC;AAED;;;;;;;;GAQG;AACH,SAAgB,QAAQ;IACtB,OAAO,WAAW,CAAC;AACrB,CAAC;AAFD,4BAEC"}
1
+ {"version":3,"file":"init.js","sourceRoot":"","sources":["../../../src/config/init.ts"],"names":[],"mappings":";;;AACA,uCAAoC;AAEpC,IAAI,WAAW,GAAG,KAAK,CAAC;AAExB;;GAEG;AACH,SAAgB,IAAI,CAAC,aAAwC;IAC3D,IAAI,CAAC,aAAa,EAAE;QAClB,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;KACpD;IACD,iBAAO,CAAC,gBAAgB,CAAC,aAAa,CAAC,CAAC;IAExC,6CAA6C;IAC7C,uCAAuC;IACvC,4CAA4C;IAC5C,6CAA6C;IAC7C,WAAW,GAAG,IAAI,CAAC;AACrB,CAAC;AAXD,oBAWC;AAED;;;;;;;;GAQG;AACH,SAAgB,QAAQ;IACtB,OAAO,WAAW,CAAC;AACrB,CAAC;AAFD,4BAEC"}
@@ -5,4 +5,4 @@ import * as express from 'express';
5
5
  * @param filter a filter which is going to be called with the request to see if a
6
6
  * colleration id scope must be managed or not.
7
7
  */
8
- export declare let createCorrelationIdMiddleware: (filter?: (req: express.Request) => boolean) => (req: express.Request, res: express.Response, next: express.NextFunction) => void;
8
+ export declare const createCorrelationIdMiddleware: (filter?: (req: express.Request) => boolean) => (req: express.Request, res: express.Response, next: express.NextFunction) => void;
@@ -10,7 +10,7 @@ const correlationIdService_1 = require("../services/correlationIdService");
10
10
  * @param filter a filter which is going to be called with the request to see if a
11
11
  * colleration id scope must be managed or not.
12
12
  */
13
- let createCorrelationIdMiddleware = (filter) => {
13
+ const createCorrelationIdMiddleware = (filter) => {
14
14
  const correlationIdMiddleware = (req, res, next) => {
15
15
  if (filter && !filter(req)) {
16
16
  next();
@@ -1 +1 @@
1
- {"version":3,"file":"correlationIdMiddleware.js","sourceRoot":"","sources":["../../../src/middleware/correlationIdMiddleware.ts"],"names":[],"mappings":";;;AACA,uEAA6D;AAC7D,mDAAgD;AAChD,2EAAwE;AAExE;;;;;GAKG;AACI,IAAI,6BAA6B,GAAG,CACzC,MAA0C,EAC2C,EAAE;IACvF,MAAM,uBAAuB,GAAG,CAC9B,GAAoB,EACpB,GAAqB,EACrB,IAA0B,EACpB,EAAE;QACR,IAAI,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE;YAC1B,IAAI,EAAE,CAAC;SACR;aAAM;YACL,6CAA6C;YAC7C,kDAAkD;YAClD,oDAAoD;YACpD,EAAE;YACF,kCAAkC;YAClC,6CAA6C;YAC7C,IAAI,aAAa,GAAG,GAAG,CAAC,GAAG,CAAC,kCAAqB,CAAC,gBAAgB,CAAC,CAAC;YACpE,IAAI,CAAC,aAAa,EAAE;gBAClB,aAAa,GAAG,2CAAoB,CAAC,WAAW,EAAE,CAAC;gBACnD,GAAG,CAAC,qBAAS,CAAC,qBAAqB,CAAC,MAAM,CAAC,GAAG,aAAa,CAAC;aAC7D;iBAAM;gBACL,GAAG,CAAC,qBAAS,CAAC,qBAAqB,CAAC,oBAAoB,CAAC,GAAG,aAAa,CAAC;aAC3E;YACD,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE;gBACpB,GAAG,CAAC,GAAG,CAAC,kCAAqB,CAAC,gBAAgB,EAAE,aAAa,CAAC,CAAC;aAChE;YACD,2CAAoB,CAAC,MAAM,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;SAClD;IACH,CAAC,CAAC;IAEF,OAAO,uBAAuB,CAAC;AACjC,CAAC,CAAC;AAhCS,QAAA,6BAA6B,iCAgCtC"}
1
+ {"version":3,"file":"correlationIdMiddleware.js","sourceRoot":"","sources":["../../../src/middleware/correlationIdMiddleware.ts"],"names":[],"mappings":";;;AACA,uEAA6D;AAC7D,mDAAgD;AAChD,2EAAwE;AAExE;;;;;GAKG;AACI,MAAM,6BAA6B,GAAG,CAC3C,MAA0C,EAC2C,EAAE;IACvF,MAAM,uBAAuB,GAAG,CAC9B,GAAoB,EACpB,GAAqB,EACrB,IAA0B,EACpB,EAAE;QACR,IAAI,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE;YAC1B,IAAI,EAAE,CAAC;SACR;aAAM;YACL,6CAA6C;YAC7C,kDAAkD;YAClD,oDAAoD;YACpD,EAAE;YACF,kCAAkC;YAClC,6CAA6C;YAC7C,IAAI,aAAa,GAAG,GAAG,CAAC,GAAG,CAAC,kCAAqB,CAAC,gBAAgB,CAAC,CAAC;YACpE,IAAI,CAAC,aAAa,EAAE;gBAClB,aAAa,GAAG,2CAAoB,CAAC,WAAW,EAAE,CAAC;gBACnD,GAAG,CAAC,qBAAS,CAAC,qBAAqB,CAAC,MAAM,CAAC,GAAG,aAAa,CAAC;aAC7D;iBAAM;gBACL,GAAG,CAAC,qBAAS,CAAC,qBAAqB,CAAC,oBAAoB,CAAC,GAAG,aAAa,CAAC;aAC3E;YACD,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE;gBACpB,GAAG,CAAC,GAAG,CAAC,kCAAqB,CAAC,gBAAgB,EAAE,aAAa,CAAC,CAAC;aAChE;YACD,2CAAoB,CAAC,MAAM,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;SAClD;IACH,CAAC,CAAC;IAEF,OAAO,uBAAuB,CAAC;AACjC,CAAC,CAAC;AAhCW,QAAA,6BAA6B,iCAgCxC"}
@@ -1,4 +1,13 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  const chai_1 = require("chai");
4
13
  const express = require("express");
@@ -8,7 +17,7 @@ const correlationIdService_1 = require("../services/correlationIdService");
8
17
  const testingConfigurations_1 = require("../utils/testingConfigurations");
9
18
  const correlationIdMiddleware_1 = require("./correlationIdMiddleware");
10
19
  function delay(millis) {
11
- return new Promise(resolve => setTimeout(() => {
20
+ return new Promise((resolve) => setTimeout(() => {
12
21
  resolve();
13
22
  }, millis));
14
23
  }
@@ -22,7 +31,7 @@ const uuidMatcher = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{1
22
31
  // ==========================================
23
32
  // tslint:disable-next-line: max-func-body-length
24
33
  describe('Correlation ID Middleware', () => {
25
- it('should generate correlation id if it doesnt exists', async () => {
34
+ it('should generate correlation id if it doesnt exists', () => __awaiter(void 0, void 0, void 0, function* () {
26
35
  const app = express();
27
36
  app.use((0, correlationIdMiddleware_1.createCorrelationIdMiddleware)());
28
37
  app.get('/', (req, res) => {
@@ -30,11 +39,9 @@ describe('Correlation ID Middleware', () => {
30
39
  chai_1.assert.match(actual, uuidMatcher);
31
40
  res.end();
32
41
  });
33
- await request(app)
34
- .get('/')
35
- .send();
36
- });
37
- it('should get correlation id from incoming request', async () => {
42
+ yield request(app).get('/').send();
43
+ }));
44
+ it('should get correlation id from incoming request', () => __awaiter(void 0, void 0, void 0, function* () {
38
45
  const testId = 'correlation-id-123';
39
46
  const app = express();
40
47
  app.use((0, correlationIdMiddleware_1.createCorrelationIdMiddleware)());
@@ -43,43 +50,37 @@ describe('Correlation ID Middleware', () => {
43
50
  chai_1.assert.strictEqual(actual, testId, 'getId() should return id from x-correlation-id header of inbound request');
44
51
  res.end();
45
52
  });
46
- await request(app)
47
- .get('/')
48
- .set(http_header_fields_typed_1.default.X_CORRELATION_ID, testId)
49
- .send();
50
- });
51
- it('should maintain correlation id with async callbacks', async () => {
53
+ yield request(app).get('/').set(http_header_fields_typed_1.default.X_CORRELATION_ID, testId).send();
54
+ }));
55
+ it('should maintain correlation id with async callbacks', () => __awaiter(void 0, void 0, void 0, function* () {
52
56
  const testId = 'correlation-id-123';
53
57
  let actual = '';
54
58
  let actual2 = '';
55
59
  const app = express();
56
60
  app.use((0, correlationIdMiddleware_1.createCorrelationIdMiddleware)());
57
- app.get('/', async (req, res, next) => {
61
+ app.get('/', (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
58
62
  actual = correlationIdService_1.correlationIdService.getId();
59
63
  setTimeout(() => {
60
64
  actual2 = correlationIdService_1.correlationIdService.getId();
61
65
  res.end();
62
66
  }, 250);
63
- });
67
+ }));
64
68
  chai_1.assert.isUndefined(correlationIdService_1.correlationIdService.getId());
65
- await request(app)
66
- .get('/')
67
- .set(http_header_fields_typed_1.default.X_CORRELATION_ID, testId)
68
- .send();
69
+ yield request(app).get('/').set(http_header_fields_typed_1.default.X_CORRELATION_ID, testId).send();
69
70
  chai_1.assert.isUndefined(correlationIdService_1.correlationIdService.getId());
70
71
  chai_1.assert.strictEqual(actual, testId, 'getId() should return id from x-correlation-id header of inbound request');
71
72
  chai_1.assert.strictEqual(actual2, testId, 'getId() should return id from x-correlation-id header of inbound request');
72
- });
73
- it('should maintain correlation id with async/await operations', async () => {
73
+ }));
74
+ it('should maintain correlation id with async/await operations', () => __awaiter(void 0, void 0, void 0, function* () {
74
75
  const testId = 'correlation-id-123';
75
76
  let actual = '';
76
77
  let actual2 = '';
77
78
  const app = express();
78
79
  app.use((0, correlationIdMiddleware_1.createCorrelationIdMiddleware)());
79
- app.get('/', async (req, res, next) => {
80
+ app.get('/', (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
80
81
  try {
81
82
  actual = correlationIdService_1.correlationIdService.getId();
82
- await delay(250);
83
+ yield delay(250);
83
84
  actual2 = correlationIdService_1.correlationIdService.getId();
84
85
  }
85
86
  catch (e) {
@@ -88,17 +89,14 @@ describe('Correlation ID Middleware', () => {
88
89
  finally {
89
90
  res.end();
90
91
  }
91
- });
92
+ }));
92
93
  chai_1.assert.isUndefined(correlationIdService_1.correlationIdService.getId());
93
- await request(app)
94
- .get('/')
95
- .set(http_header_fields_typed_1.default.X_CORRELATION_ID, testId)
96
- .send();
94
+ yield request(app).get('/').set(http_header_fields_typed_1.default.X_CORRELATION_ID, testId).send();
97
95
  chai_1.assert.isUndefined(correlationIdService_1.correlationIdService.getId());
98
96
  chai_1.assert.strictEqual(actual, testId, 'getId() should return id from x-correlation-id header of inbound request');
99
97
  chai_1.assert.strictEqual(actual2, testId, 'getId() should return id from x-correlation-id header of inbound request');
100
- });
101
- it('should keep correlation ids in nested requests', async () => {
98
+ }));
99
+ it('should keep correlation ids in nested requests', () => __awaiter(void 0, void 0, void 0, function* () {
102
100
  const testId = 'correlation-id-123';
103
101
  const testId2 = 'correlation-id-456';
104
102
  let actual = '';
@@ -108,15 +106,12 @@ describe('Correlation ID Middleware', () => {
108
106
  let actual5 = '';
109
107
  const app = express();
110
108
  app.use((0, correlationIdMiddleware_1.createCorrelationIdMiddleware)());
111
- app.get('/', async (req, res, next) => {
109
+ app.get('/', (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
112
110
  try {
113
111
  actual = correlationIdService_1.correlationIdService.getId();
114
- await delay(250);
112
+ yield delay(250);
115
113
  actual2 = correlationIdService_1.correlationIdService.getId();
116
- await request(app)
117
- .get('/foo')
118
- .set(http_header_fields_typed_1.default.X_CORRELATION_ID, testId2)
119
- .send();
114
+ yield request(app).get('/foo').set(http_header_fields_typed_1.default.X_CORRELATION_ID, testId2).send();
120
115
  actual3 = correlationIdService_1.correlationIdService.getId();
121
116
  }
122
117
  catch (e) {
@@ -125,11 +120,11 @@ describe('Correlation ID Middleware', () => {
125
120
  finally {
126
121
  res.end();
127
122
  }
128
- });
129
- app.get('/foo', async (req, res, next) => {
123
+ }));
124
+ app.get('/foo', (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
130
125
  try {
131
126
  actual4 = correlationIdService_1.correlationIdService.getId();
132
- await delay(250);
127
+ yield delay(250);
133
128
  actual5 = correlationIdService_1.correlationIdService.getId();
134
129
  }
135
130
  catch (e) {
@@ -138,85 +133,81 @@ describe('Correlation ID Middleware', () => {
138
133
  finally {
139
134
  res.end();
140
135
  }
141
- });
136
+ }));
142
137
  chai_1.assert.isUndefined(correlationIdService_1.correlationIdService.getId());
143
- await request(app)
144
- .get('/')
145
- .set(http_header_fields_typed_1.default.X_CORRELATION_ID, testId)
146
- .send();
138
+ yield request(app).get('/').set(http_header_fields_typed_1.default.X_CORRELATION_ID, testId).send();
147
139
  chai_1.assert.isUndefined(correlationIdService_1.correlationIdService.getId());
148
140
  chai_1.assert.strictEqual(actual, testId, 'getId() should return id from x-correlation-id header of inbound request');
149
141
  chai_1.assert.strictEqual(actual2, testId, 'getId() should return id from x-correlation-id header of inbound request');
150
142
  chai_1.assert.strictEqual(actual3, testId, 'getId() should return id from x-correlation-id header of inbound request');
151
143
  chai_1.assert.strictEqual(actual4, testId2, 'getId() should return id from x-correlation-id header of inbound request');
152
144
  chai_1.assert.strictEqual(actual5, testId2, 'getId() should return id from x-correlation-id header of inbound request');
153
- });
145
+ }));
154
146
  // tslint:disable: no-console
155
- it('should keep correlation ids separated in parallel requests', async function () {
156
- this.timeout(5000);
157
- const testId = 'correlation-id-123';
158
- const testId2 = 'correlation-id-456';
159
- let actual = '';
160
- let actual2 = '';
161
- let actual4 = '';
162
- let actual5 = '';
163
- let unlock;
164
- const lock = new Promise(async (resolve, reject) => {
165
- unlock = resolve;
166
- });
167
- const app = express();
168
- app.use((0, correlationIdMiddleware_1.createCorrelationIdMiddleware)());
169
- app.get('/', async (req, res, next) => {
170
- try {
171
- actual = correlationIdService_1.correlationIdService.getId();
172
- console.log('start of req1', actual);
173
- await lock;
174
- actual2 = correlationIdService_1.correlationIdService.getId();
175
- console.log('end of req1', actual2);
176
- }
177
- catch (e) {
178
- next(e);
179
- }
180
- finally {
181
- res.end();
182
- }
183
- });
184
- app.get('/foo', async (req, res, next) => {
185
- try {
186
- actual4 = correlationIdService_1.correlationIdService.getId();
187
- console.log('start of req2', actual4);
188
- unlock();
189
- await this.timeout(200);
190
- actual5 = correlationIdService_1.correlationIdService.getId();
191
- console.log('end of req2', actual5);
192
- }
193
- catch (e) {
194
- next(e);
195
- }
196
- finally {
197
- res.end();
198
- }
147
+ it('should keep correlation ids separated in parallel requests', function () {
148
+ return __awaiter(this, void 0, void 0, function* () {
149
+ this.timeout(5000);
150
+ const testId = 'correlation-id-123';
151
+ const testId2 = 'correlation-id-456';
152
+ let actual = '';
153
+ let actual2 = '';
154
+ let actual4 = '';
155
+ let actual5 = '';
156
+ let unlock;
157
+ const lock = new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
158
+ unlock = resolve;
159
+ }));
160
+ const app = express();
161
+ app.use((0, correlationIdMiddleware_1.createCorrelationIdMiddleware)());
162
+ app.get('/', (req, res, next) => __awaiter(this, void 0, void 0, function* () {
163
+ try {
164
+ actual = correlationIdService_1.correlationIdService.getId();
165
+ console.log('start of req1', actual);
166
+ yield lock;
167
+ actual2 = correlationIdService_1.correlationIdService.getId();
168
+ console.log('end of req1', actual2);
169
+ }
170
+ catch (e) {
171
+ next(e);
172
+ }
173
+ finally {
174
+ res.end();
175
+ }
176
+ }));
177
+ app.get('/foo', (req, res, next) => __awaiter(this, void 0, void 0, function* () {
178
+ try {
179
+ actual4 = correlationIdService_1.correlationIdService.getId();
180
+ console.log('start of req2', actual4);
181
+ unlock();
182
+ yield this.timeout(200);
183
+ actual5 = correlationIdService_1.correlationIdService.getId();
184
+ console.log('end of req2', actual5);
185
+ }
186
+ catch (e) {
187
+ next(e);
188
+ }
189
+ finally {
190
+ res.end();
191
+ }
192
+ }));
193
+ console.log('send req1');
194
+ chai_1.assert.isUndefined(correlationIdService_1.correlationIdService.getId());
195
+ const req1 = request(app).get('/').set(http_header_fields_typed_1.default.X_CORRELATION_ID, testId).send();
196
+ console.log('send req2');
197
+ chai_1.assert.isUndefined(correlationIdService_1.correlationIdService.getId());
198
+ const req2 = request(app)
199
+ .get('/foo')
200
+ .set(http_header_fields_typed_1.default.X_CORRELATION_ID, testId2)
201
+ .send();
202
+ yield Promise.all([req1, req2]);
203
+ chai_1.assert.isUndefined(correlationIdService_1.correlationIdService.getId());
204
+ chai_1.assert.strictEqual(actual, testId, 'getId() should return id from x-correlation-id header of inbound request');
205
+ chai_1.assert.strictEqual(actual2, testId, 'getId() should return id from x-correlation-id header of inbound request');
206
+ chai_1.assert.strictEqual(actual4, testId2, 'getId() should return id from x-correlation-id header of inbound request');
207
+ chai_1.assert.strictEqual(actual5, testId2, 'getId() should return id from x-correlation-id header of inbound request');
199
208
  });
200
- console.log('send req1');
201
- chai_1.assert.isUndefined(correlationIdService_1.correlationIdService.getId());
202
- const req1 = request(app)
203
- .get('/')
204
- .set(http_header_fields_typed_1.default.X_CORRELATION_ID, testId)
205
- .send();
206
- console.log('send req2');
207
- chai_1.assert.isUndefined(correlationIdService_1.correlationIdService.getId());
208
- const req2 = request(app)
209
- .get('/foo')
210
- .set(http_header_fields_typed_1.default.X_CORRELATION_ID, testId2)
211
- .send();
212
- await Promise.all([req1, req2]);
213
- chai_1.assert.isUndefined(correlationIdService_1.correlationIdService.getId());
214
- chai_1.assert.strictEqual(actual, testId, 'getId() should return id from x-correlation-id header of inbound request');
215
- chai_1.assert.strictEqual(actual2, testId, 'getId() should return id from x-correlation-id header of inbound request');
216
- chai_1.assert.strictEqual(actual4, testId2, 'getId() should return id from x-correlation-id header of inbound request');
217
- chai_1.assert.strictEqual(actual5, testId2, 'getId() should return id from x-correlation-id header of inbound request');
218
209
  });
219
- it('should work with operations causing errors', async () => {
210
+ it('should work with operations causing errors', () => __awaiter(void 0, void 0, void 0, function* () {
220
211
  const testId = 'correlation-id-123';
221
212
  let actual = '';
222
213
  const app = express();
@@ -226,15 +217,15 @@ describe('Correlation ID Middleware', () => {
226
217
  throw new Error('some error');
227
218
  });
228
219
  chai_1.assert.isUndefined(correlationIdService_1.correlationIdService.getId());
229
- const result = await request(app)
220
+ const result = yield request(app)
230
221
  .get('/')
231
222
  .set(http_header_fields_typed_1.default.X_CORRELATION_ID, testId)
232
223
  .send();
233
224
  chai_1.assert.strictEqual(result.status, 500);
234
225
  chai_1.assert.isUndefined(correlationIdService_1.correlationIdService.getId());
235
226
  chai_1.assert.strictEqual(actual, testId, 'getId() should return id from x-correlation-id header of inbound request');
236
- });
237
- it('a filter can be specified', async () => {
227
+ }));
228
+ it('a filter can be specified', () => __awaiter(void 0, void 0, void 0, function* () {
238
229
  const testId = 'correlation-id-123';
239
230
  const filter = (req) => {
240
231
  if (req.path.startsWith('/ok/')) {
@@ -259,20 +250,11 @@ describe('Correlation ID Middleware', () => {
259
250
  chai_1.assert.isUndefined(actual);
260
251
  res.end();
261
252
  });
262
- await request(app)
263
- .get('/ok/1')
264
- .set(http_header_fields_typed_1.default.X_CORRELATION_ID, testId)
265
- .send();
266
- await request(app)
267
- .get('/ok/2')
268
- .set(http_header_fields_typed_1.default.X_CORRELATION_ID, testId)
269
- .send();
270
- await request(app)
271
- .get('/notok/1')
272
- .set(http_header_fields_typed_1.default.X_CORRELATION_ID, testId)
273
- .send();
274
- });
275
- it('getCidInfo() cid received', async () => {
253
+ yield request(app).get('/ok/1').set(http_header_fields_typed_1.default.X_CORRELATION_ID, testId).send();
254
+ yield request(app).get('/ok/2').set(http_header_fields_typed_1.default.X_CORRELATION_ID, testId).send();
255
+ yield request(app).get('/notok/1').set(http_header_fields_typed_1.default.X_CORRELATION_ID, testId).send();
256
+ }));
257
+ it('getCidInfo() cid received', () => __awaiter(void 0, void 0, void 0, function* () {
276
258
  const testId = 'correlation-id-123';
277
259
  const app = express();
278
260
  app.use((0, correlationIdMiddleware_1.createCorrelationIdMiddleware)());
@@ -283,12 +265,9 @@ describe('Correlation ID Middleware', () => {
283
265
  chai_1.assert.isUndefined(info.generated);
284
266
  res.end();
285
267
  });
286
- await request(app)
287
- .get('/')
288
- .set(http_header_fields_typed_1.default.X_CORRELATION_ID, testId)
289
- .send();
290
- });
291
- it('getCidInfo() cid generated', async () => {
268
+ yield request(app).get('/').set(http_header_fields_typed_1.default.X_CORRELATION_ID, testId).send();
269
+ }));
270
+ it('getCidInfo() cid generated', () => __awaiter(void 0, void 0, void 0, function* () {
292
271
  const app = express();
293
272
  app.use((0, correlationIdMiddleware_1.createCorrelationIdMiddleware)());
294
273
  app.get('/', (req, res) => {
@@ -298,9 +277,7 @@ describe('Correlation ID Middleware', () => {
298
277
  chai_1.assert.isUndefined(info.receivedInRequest);
299
278
  res.end();
300
279
  });
301
- await request(app)
302
- .get('/')
303
- .send();
304
- });
280
+ yield request(app).get('/').send();
281
+ }));
305
282
  });
306
283
  //# sourceMappingURL=correlationIdMiddleware.test.js.map