@villedemontreal/correlation-id 5.3.2

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 (43) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +119 -0
  3. package/dist/src/config/configs.d.ts +16 -0
  4. package/dist/src/config/configs.js +26 -0
  5. package/dist/src/config/configs.js.map +1 -0
  6. package/dist/src/config/constants.d.ts +27 -0
  7. package/dist/src/config/constants.js +27 -0
  8. package/dist/src/config/constants.js.map +1 -0
  9. package/dist/src/config/init.d.ts +15 -0
  10. package/dist/src/config/init.js +34 -0
  11. package/dist/src/config/init.js.map +1 -0
  12. package/dist/src/index.d.ts +3 -0
  13. package/dist/src/index.js +25 -0
  14. package/dist/src/index.js.map +1 -0
  15. package/dist/src/middleware/correlationIdMiddleware.d.ts +8 -0
  16. package/dist/src/middleware/correlationIdMiddleware.js +43 -0
  17. package/dist/src/middleware/correlationIdMiddleware.js.map +1 -0
  18. package/dist/src/middleware/correlationIdMiddleware.test.d.ts +1 -0
  19. package/dist/src/middleware/correlationIdMiddleware.test.js +306 -0
  20. package/dist/src/middleware/correlationIdMiddleware.test.js.map +1 -0
  21. package/dist/src/services/correlationIdService.d.ts +68 -0
  22. package/dist/src/services/correlationIdService.js +166 -0
  23. package/dist/src/services/correlationIdService.js.map +1 -0
  24. package/dist/src/services/correlationIdService.test.d.ts +1 -0
  25. package/dist/src/services/correlationIdService.test.js +215 -0
  26. package/dist/src/services/correlationIdService.test.js.map +1 -0
  27. package/dist/src/utils/logger.d.ts +11 -0
  28. package/dist/src/utils/logger.js +54 -0
  29. package/dist/src/utils/logger.js.map +1 -0
  30. package/dist/src/utils/testingConfigurations.d.ts +9 -0
  31. package/dist/src/utils/testingConfigurations.js +18 -0
  32. package/dist/src/utils/testingConfigurations.js.map +1 -0
  33. package/package.json +62 -0
  34. package/src/config/configs.ts +26 -0
  35. package/src/config/constants.ts +40 -0
  36. package/src/config/init.ts +33 -0
  37. package/src/index.ts +9 -0
  38. package/src/middleware/correlationIdMiddleware.test.ts +335 -0
  39. package/src/middleware/correlationIdMiddleware.ts +45 -0
  40. package/src/services/correlationIdService.test.ts +255 -0
  41. package/src/services/correlationIdService.ts +255 -0
  42. package/src/utils/logger.ts +53 -0
  43. package/src/utils/testingConfigurations.ts +14 -0
@@ -0,0 +1,306 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const chai_1 = require("chai");
4
+ const express = require("express");
5
+ const http_header_fields_typed_1 = require("http-header-fields-typed");
6
+ const request = require("supertest");
7
+ const correlationIdService_1 = require("../services/correlationIdService");
8
+ const testingConfigurations_1 = require("../utils/testingConfigurations");
9
+ const correlationIdMiddleware_1 = require("./correlationIdMiddleware");
10
+ function delay(millis) {
11
+ return new Promise(resolve => setTimeout(() => {
12
+ resolve();
13
+ }, millis));
14
+ }
15
+ // ==========================================
16
+ // Set Testing configurations
17
+ // ==========================================
18
+ (0, testingConfigurations_1.setTestingConfigurations)();
19
+ const uuidMatcher = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
20
+ // ==========================================
21
+ // Correlation ID service
22
+ // ==========================================
23
+ // tslint:disable-next-line: max-func-body-length
24
+ describe('Correlation ID Middleware', () => {
25
+ it('should generate correlation id if it doesnt exists', async () => {
26
+ const app = express();
27
+ app.use((0, correlationIdMiddleware_1.createCorrelationIdMiddleware)());
28
+ app.get('/', (req, res) => {
29
+ const actual = correlationIdService_1.correlationIdService.getId();
30
+ chai_1.assert.match(actual, uuidMatcher);
31
+ res.end();
32
+ });
33
+ await request(app)
34
+ .get('/')
35
+ .send();
36
+ });
37
+ it('should get correlation id from incoming request', async () => {
38
+ const testId = 'correlation-id-123';
39
+ const app = express();
40
+ app.use((0, correlationIdMiddleware_1.createCorrelationIdMiddleware)());
41
+ app.get('/', (req, res) => {
42
+ const actual = correlationIdService_1.correlationIdService.getId();
43
+ chai_1.assert.strictEqual(actual, testId, 'getId() should return id from x-correlation-id header of inbound request');
44
+ res.end();
45
+ });
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 () => {
52
+ const testId = 'correlation-id-123';
53
+ let actual = '';
54
+ let actual2 = '';
55
+ const app = express();
56
+ app.use((0, correlationIdMiddleware_1.createCorrelationIdMiddleware)());
57
+ app.get('/', async (req, res, next) => {
58
+ actual = correlationIdService_1.correlationIdService.getId();
59
+ setTimeout(() => {
60
+ actual2 = correlationIdService_1.correlationIdService.getId();
61
+ res.end();
62
+ }, 250);
63
+ });
64
+ 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
+ chai_1.assert.isUndefined(correlationIdService_1.correlationIdService.getId());
70
+ chai_1.assert.strictEqual(actual, testId, 'getId() should return id from x-correlation-id header of inbound request');
71
+ 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 () => {
74
+ const testId = 'correlation-id-123';
75
+ let actual = '';
76
+ let actual2 = '';
77
+ const app = express();
78
+ app.use((0, correlationIdMiddleware_1.createCorrelationIdMiddleware)());
79
+ app.get('/', async (req, res, next) => {
80
+ try {
81
+ actual = correlationIdService_1.correlationIdService.getId();
82
+ await delay(250);
83
+ actual2 = correlationIdService_1.correlationIdService.getId();
84
+ }
85
+ catch (e) {
86
+ next(e);
87
+ }
88
+ finally {
89
+ res.end();
90
+ }
91
+ });
92
+ 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();
97
+ chai_1.assert.isUndefined(correlationIdService_1.correlationIdService.getId());
98
+ chai_1.assert.strictEqual(actual, testId, 'getId() should return id from x-correlation-id header of inbound request');
99
+ 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 () => {
102
+ const testId = 'correlation-id-123';
103
+ const testId2 = 'correlation-id-456';
104
+ let actual = '';
105
+ let actual2 = '';
106
+ let actual3 = '';
107
+ let actual4 = '';
108
+ let actual5 = '';
109
+ const app = express();
110
+ app.use((0, correlationIdMiddleware_1.createCorrelationIdMiddleware)());
111
+ app.get('/', async (req, res, next) => {
112
+ try {
113
+ actual = correlationIdService_1.correlationIdService.getId();
114
+ await delay(250);
115
+ 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();
120
+ actual3 = correlationIdService_1.correlationIdService.getId();
121
+ }
122
+ catch (e) {
123
+ next(e);
124
+ }
125
+ finally {
126
+ res.end();
127
+ }
128
+ });
129
+ app.get('/foo', async (req, res, next) => {
130
+ try {
131
+ actual4 = correlationIdService_1.correlationIdService.getId();
132
+ await delay(250);
133
+ actual5 = correlationIdService_1.correlationIdService.getId();
134
+ }
135
+ catch (e) {
136
+ next(e);
137
+ }
138
+ finally {
139
+ res.end();
140
+ }
141
+ });
142
+ 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();
147
+ chai_1.assert.isUndefined(correlationIdService_1.correlationIdService.getId());
148
+ chai_1.assert.strictEqual(actual, testId, 'getId() should return id from x-correlation-id header of inbound request');
149
+ chai_1.assert.strictEqual(actual2, testId, 'getId() should return id from x-correlation-id header of inbound request');
150
+ chai_1.assert.strictEqual(actual3, testId, 'getId() should return id from x-correlation-id header of inbound request');
151
+ chai_1.assert.strictEqual(actual4, testId2, 'getId() should return id from x-correlation-id header of inbound request');
152
+ chai_1.assert.strictEqual(actual5, testId2, 'getId() should return id from x-correlation-id header of inbound request');
153
+ });
154
+ // 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
+ }
199
+ });
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
+ });
219
+ it('should work with operations causing errors', async () => {
220
+ const testId = 'correlation-id-123';
221
+ let actual = '';
222
+ const app = express();
223
+ app.use((0, correlationIdMiddleware_1.createCorrelationIdMiddleware)());
224
+ app.get('/', (req, res, next) => {
225
+ actual = correlationIdService_1.correlationIdService.getId();
226
+ throw new Error('some error');
227
+ });
228
+ chai_1.assert.isUndefined(correlationIdService_1.correlationIdService.getId());
229
+ const result = await request(app)
230
+ .get('/')
231
+ .set(http_header_fields_typed_1.default.X_CORRELATION_ID, testId)
232
+ .send();
233
+ chai_1.assert.strictEqual(result.status, 500);
234
+ chai_1.assert.isUndefined(correlationIdService_1.correlationIdService.getId());
235
+ 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 () => {
238
+ const testId = 'correlation-id-123';
239
+ const filter = (req) => {
240
+ if (req.path.startsWith('/ok/')) {
241
+ return true;
242
+ }
243
+ return false;
244
+ };
245
+ const app = express();
246
+ app.use((0, correlationIdMiddleware_1.createCorrelationIdMiddleware)(filter));
247
+ app.get('/ok/1', (req, res) => {
248
+ const actual = correlationIdService_1.correlationIdService.getId();
249
+ chai_1.assert.strictEqual(actual, testId, 'getId() should return id from x-correlation-id header of inbound request');
250
+ res.end();
251
+ });
252
+ app.get('/ok/2', (req, res) => {
253
+ const actual = correlationIdService_1.correlationIdService.getId();
254
+ chai_1.assert.strictEqual(actual, testId, 'getId() should return id from x-correlation-id header of inbound request');
255
+ res.end();
256
+ });
257
+ app.get('/notok/1', (req, res) => {
258
+ const actual = correlationIdService_1.correlationIdService.getId();
259
+ chai_1.assert.isUndefined(actual);
260
+ res.end();
261
+ });
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 () => {
276
+ const testId = 'correlation-id-123';
277
+ const app = express();
278
+ app.use((0, correlationIdMiddleware_1.createCorrelationIdMiddleware)());
279
+ app.get('/', (req, res) => {
280
+ const info = correlationIdService_1.correlationIdService.getCidInfo(req);
281
+ chai_1.assert.strictEqual(info.current, testId);
282
+ chai_1.assert.strictEqual(info.receivedInRequest, testId);
283
+ chai_1.assert.isUndefined(info.generated);
284
+ res.end();
285
+ });
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 () => {
292
+ const app = express();
293
+ app.use((0, correlationIdMiddleware_1.createCorrelationIdMiddleware)());
294
+ app.get('/', (req, res) => {
295
+ const info = correlationIdService_1.correlationIdService.getCidInfo(req);
296
+ chai_1.assert.match(info.current, uuidMatcher);
297
+ chai_1.assert.strictEqual(info.current, info.generated);
298
+ chai_1.assert.isUndefined(info.receivedInRequest);
299
+ res.end();
300
+ });
301
+ await request(app)
302
+ .get('/')
303
+ .send();
304
+ });
305
+ });
306
+ //# sourceMappingURL=correlationIdMiddleware.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"correlationIdMiddleware.test.js","sourceRoot":"","sources":["../../../src/middleware/correlationIdMiddleware.test.ts"],"names":[],"mappings":";;AAAA,+BAA8B;AAC9B,mCAAmC;AACnC,uEAA6D;AAC7D,qCAAqC;AACrC,2EAAwE;AACxE,0EAA0E;AAC1E,uEAA0E;AAE1E,SAAS,KA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AAC;YACjD,aAAM,CAAC,WAAW,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;YAE3C,GAAG,CAAC,GAAG,EAAE,CAAC;QACZ,CAAC,CAAC,CAAC;QAEH,MAAM,OAAO,CAAC,GAAG,CAAC;aACf,GAAG,CAAC,GAAG,CAAC;aACR,IAAI,EAAE,CAAC;IACZ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,68 @@
1
+ import * as express from 'express';
2
+ /**
3
+ * CorrelationId type
4
+ */
5
+ export declare type CorrelationId = string;
6
+ /**
7
+ * Informations about the correlation ID.
8
+ */
9
+ export interface ICidInfo {
10
+ /**
11
+ * Current cid
12
+ */
13
+ current: string;
14
+ /**
15
+ * Cid received in the request (may be undefined)
16
+ */
17
+ receivedInRequest: string;
18
+ /**
19
+ * Cid generated (may be undefined)
20
+ */
21
+ generated: string;
22
+ }
23
+ /**
24
+ * CorrelationId service
25
+ */
26
+ export interface ICorrelationIdService {
27
+ /**
28
+ * Creates a new correlation ID that can then be passed to the
29
+ * "withId()" function.
30
+ */
31
+ createNewId(): CorrelationId;
32
+ /**
33
+ * Executes a function inside a context where the correlation ID is defined.
34
+ *
35
+ * @param work the function to run within the cid context.
36
+ * @param cid the correlation ID to use.
37
+ *
38
+ */
39
+ withId<T>(work: () => T, cid?: CorrelationId): T;
40
+ /**
41
+ * Executes a function inside a context where the correlation ID is defined.
42
+ * This is the promisified version of the `withId` method.
43
+ * @param work a callback to invoke with the submitted correlation ID
44
+ * @param cid the correlation ID to install be before invoking the submitted callback
45
+ *
46
+ * @deprecated `#withId` is preferable instead: if the wrapped operation
47
+ * is asynchronous it will still be properly scoped (correlation context) and
48
+ * can safely be awaited for outside of `#withId`.
49
+ */
50
+ withIdAsync<T>(work: () => Promise<T>, cid?: string): Promise<T>;
51
+ /**
52
+ * binds the current correlation context to the target
53
+ * @param target the target to bind to
54
+ * @returns either the submitted target (if it is an emitter) or a wrapped target (for a function)
55
+ * @remarks you might have to bind to an emitter in order to maitain
56
+ * the correlation context.
57
+ */
58
+ bind<T>(target: T): T;
59
+ /**
60
+ * Returns the correlation ID from the current context
61
+ */
62
+ getId(): CorrelationId;
63
+ /**
64
+ * Returns all correlation ID info
65
+ */
66
+ getCidInfo(req: express.Request): ICidInfo;
67
+ }
68
+ export declare let correlationIdService: ICorrelationIdService;
@@ -0,0 +1,166 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.correlationIdService = void 0;
4
+ const { AsyncLocalStorage } = require('async_hooks');
5
+ const cls = require("cls-hooked");
6
+ const events_1 = require("events");
7
+ const semver = require("semver");
8
+ const uuid_1 = require("uuid");
9
+ const constants_1 = require("../config/constants");
10
+ const oldEmitSlot = Symbol('kOriginalEmit');
11
+ const cidSlot = Symbol('kCorrelationId');
12
+ const storeSlot = Symbol('kCidStore');
13
+ /**
14
+ * CorrelationId service
15
+ */
16
+ class CorrelationIdServiceWithClsHooked {
17
+ constructor() {
18
+ this.store = cls.createNamespace('343c9880-fa2b-4212-a9f3-15f3cc09581d');
19
+ }
20
+ createNewId() {
21
+ return (0, uuid_1.v4)();
22
+ }
23
+ withId(work, cid) {
24
+ let cidClean = cid;
25
+ if (!cidClean) {
26
+ cidClean = this.createNewId();
27
+ }
28
+ return this.store.runAndReturn(() => {
29
+ this.store.set('correlator', cidClean);
30
+ return work();
31
+ });
32
+ }
33
+ async withIdAsync(work, cid) {
34
+ return new Promise((resolve, reject) => {
35
+ this.withId(() => {
36
+ try {
37
+ work()
38
+ .then(resolve)
39
+ .catch(reject);
40
+ }
41
+ catch (err) {
42
+ reject(err);
43
+ }
44
+ }, cid);
45
+ });
46
+ }
47
+ bind(target) {
48
+ if (target instanceof events_1.EventEmitter) {
49
+ return this.bindEmitter(target);
50
+ }
51
+ if (typeof target === 'function') {
52
+ return this.bindFunction(target);
53
+ }
54
+ return target;
55
+ }
56
+ getId() {
57
+ return this.store.get('correlator');
58
+ }
59
+ getCidInfo(req) {
60
+ return {
61
+ current: this.getId(),
62
+ receivedInRequest: req[constants_1.constants.requestExtraVariables.cidReceivedInRequest],
63
+ generated: req[constants_1.constants.requestExtraVariables.cidNew]
64
+ };
65
+ }
66
+ bindEmitter(emitter) {
67
+ // Note that we can't use the following line:
68
+ // this.store.bindEmitter(emitter);
69
+ // because this works only if bindEmitter is called before any
70
+ // call to the "on" method of the emitter, and I don't want to
71
+ // risk having ordering issues.
72
+ // Note however that patching an emitter might not work in 100% cases.
73
+ // patch emit method only once!
74
+ if (!emitter[oldEmitSlot]) {
75
+ emitter[oldEmitSlot] = emitter.emit;
76
+ emitter.emit = (...args) => {
77
+ // wrap the emit call within a new correlation context
78
+ // with the bound cid.
79
+ this.withId(() => {
80
+ // invoke original emit method
81
+ emitter[oldEmitSlot].apply(emitter, args);
82
+ }, emitter[cidSlot]);
83
+ };
84
+ }
85
+ // update the cid bound to the emitter
86
+ emitter[cidSlot] = this.getId();
87
+ return emitter;
88
+ }
89
+ // tslint:disable-next-line: ban-types
90
+ bindFunction(target) {
91
+ return this.store.bind(target);
92
+ }
93
+ }
94
+ // tslint:disable-next-line: max-classes-per-file
95
+ class CorrelationIdServiceWithAsyncLocalStorage {
96
+ constructor() {
97
+ this.storage = new AsyncLocalStorage();
98
+ }
99
+ createNewId() {
100
+ return (0, uuid_1.v4)();
101
+ }
102
+ withId(work, cid) {
103
+ const correlationId = cid || this.createNewId();
104
+ return this.storage.run({ correlationId }, work);
105
+ }
106
+ async withIdAsync(work, cid) {
107
+ return this.withId(work, cid);
108
+ }
109
+ bind(target) {
110
+ if (target instanceof events_1.EventEmitter) {
111
+ return this.bindEmitter(target);
112
+ }
113
+ if (typeof target === 'function') {
114
+ return this.bindFunction(target);
115
+ }
116
+ return target;
117
+ }
118
+ getId() {
119
+ const store = this.storage.getStore();
120
+ if (store) {
121
+ return store.correlationId;
122
+ }
123
+ return undefined;
124
+ }
125
+ getCidInfo(req) {
126
+ return {
127
+ current: this.getId(),
128
+ receivedInRequest: req[constants_1.constants.requestExtraVariables.cidReceivedInRequest],
129
+ generated: req[constants_1.constants.requestExtraVariables.cidNew]
130
+ };
131
+ }
132
+ bindEmitter(emitter) {
133
+ // patch emit method only once!
134
+ if (!emitter[oldEmitSlot]) {
135
+ emitter[oldEmitSlot] = emitter.emit;
136
+ emitter.emit = (...args) => {
137
+ // use the store that was bound to this emitter
138
+ const store = emitter[storeSlot];
139
+ if (store) {
140
+ this.storage.enterWith(store);
141
+ }
142
+ // invoke original emit method
143
+ emitter[oldEmitSlot].call(emitter, ...args);
144
+ };
145
+ }
146
+ // update the store bound to the emitter
147
+ emitter[storeSlot] = this.storage.getStore();
148
+ return emitter;
149
+ }
150
+ // tslint:disable-next-line: ban-types
151
+ bindFunction(target) {
152
+ const storage = this.storage;
153
+ const store = this.storage.getStore();
154
+ return function (...args) {
155
+ storage.enterWith(store);
156
+ return target.call(this, ...args);
157
+ };
158
+ }
159
+ }
160
+ function canUseAsyncLocalStorage() {
161
+ return semver.satisfies(process.versions.node, '>=13.10.0') && !!AsyncLocalStorage;
162
+ }
163
+ exports.correlationIdService = canUseAsyncLocalStorage()
164
+ ? new CorrelationIdServiceWithAsyncLocalStorage()
165
+ : new CorrelationIdServiceWithClsHooked();
166
+ //# sourceMappingURL=correlationIdService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"correlationIdService.js","sourceRoot":"","sources":["../../../src/services/correlationIdService.ts"],"names":[],"mappings":";;;AAAA,MAAM,EAAE,iBAAiB,EAAE,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;AACrD,kCAAkC;AAClC,mCAAsC;AAEtC,iCAAiC;AACjC,+BAAkC;AAClC,mDAAgD;AAChD,MAAM,WAAW,GAAG,MAAM,CAAC,eAAe,CAAC,CAAC;AAC5C,MAAM,OAAO,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;AACzC,MAAM,SAAS,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC;AA8EtC;;GAEG;AACH,MAAM,iCAA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