@sipgate/integration-bridge 1.0.22 → 1.0.23
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.
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import { NextFunction, Response } from 'express';
|
|
2
3
|
import { BridgeRequest } from '../models';
|
|
4
|
+
import { AsyncLocalStorage } from 'async_hooks';
|
|
5
|
+
export declare const playtypusUserIdStorage: AsyncLocalStorage<string>;
|
|
3
6
|
export declare function extractHeaderMiddleware(req: BridgeRequest<any>, res: Response, next: NextFunction): void;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.extractHeaderMiddleware = void 0;
|
|
3
|
+
exports.extractHeaderMiddleware = exports.playtypusUserIdStorage = void 0;
|
|
4
|
+
const async_hooks_1 = require("async_hooks");
|
|
4
5
|
const DEFAULT_LOCALE = 'de-DE';
|
|
6
|
+
exports.playtypusUserIdStorage = new async_hooks_1.AsyncLocalStorage();
|
|
5
7
|
function extractHeaderMiddleware(req, res, next) {
|
|
6
8
|
const userId = req.get('x-user-id') || '';
|
|
7
9
|
const apiKey = req.get('x-provider-key') || '';
|
|
@@ -13,7 +15,7 @@ function extractHeaderMiddleware(req, res, next) {
|
|
|
13
15
|
apiUrl,
|
|
14
16
|
locale,
|
|
15
17
|
};
|
|
16
|
-
next();
|
|
18
|
+
exports.playtypusUserIdStorage.run(userId, () => next());
|
|
17
19
|
}
|
|
18
20
|
exports.extractHeaderMiddleware = extractHeaderMiddleware;
|
|
19
21
|
//# sourceMappingURL=extract-header.middleware.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extract-header.middleware.js","sourceRoot":"","sources":["../../src/middlewares/extract-header.middleware.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"extract-header.middleware.js","sourceRoot":"","sources":["../../src/middlewares/extract-header.middleware.ts"],"names":[],"mappings":";;;AAEA,6CAAgD;AAEhD,MAAM,cAAc,GAAG,OAAO,CAAC;AAElB,QAAA,sBAAsB,GAAG,IAAI,+BAAiB,EAAU,CAAC;AAEtE,SAAgB,uBAAuB,CACrC,GAAuB,EACvB,GAAa,EACb,IAAkB;IAElB,MAAM,MAAM,GAAG,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC;IAC1C,MAAM,MAAM,GAAG,GAAG,CAAC,GAAG,CAAC,gBAAgB,CAAC,IAAI,EAAE,CAAC;IAC/C,MAAM,MAAM,GAAG,GAAG,CAAC,GAAG,CAAC,gBAAgB,CAAC,IAAI,EAAE,CAAC;IAC/C,MAAM,MAAM,GAAG,GAAG,CAAC,GAAG,CAAC,mBAAmB,CAAC,IAAI,cAAc,CAAC;IAE9D,GAAG,CAAC,cAAc,GAAG;QACnB,MAAM;QACN,MAAM;QACN,MAAM;QACN,MAAM;KACP,CAAC;IAEF,8BAAsB,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC;AACnD,CAAC;AAlBD,0DAkBC"}
|
package/dist/util/logger.util.js
CHANGED
|
@@ -1,16 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.warnLogger = exports.errorLogger = exports.infoLogger = void 0;
|
|
4
|
-
const anonymize_key_1 = require("./anonymize-key");
|
|
5
4
|
const api_1 = require("@opentelemetry/api");
|
|
6
|
-
|
|
5
|
+
const anonymize_key_1 = require("./anonymize-key");
|
|
6
|
+
const middlewares_1 = require("../middlewares");
|
|
7
|
+
function addMessageToTraceSpan(method, message, args = []) {
|
|
7
8
|
const span = api_1.trace.getSpan(api_1.context.active());
|
|
8
|
-
if (span) {
|
|
9
|
-
|
|
10
|
-
message,
|
|
11
|
-
args: args ? args.map((arg) => JSON.stringify(arg)).join(',') : '',
|
|
12
|
-
});
|
|
9
|
+
if (!span) {
|
|
10
|
+
return;
|
|
13
11
|
}
|
|
12
|
+
const data = args;
|
|
13
|
+
const userId = middlewares_1.playtypusUserIdStorage.getStore();
|
|
14
|
+
if (userId) {
|
|
15
|
+
data.push({ platypusUserId: userId });
|
|
16
|
+
}
|
|
17
|
+
span.addEvent(method, {
|
|
18
|
+
message,
|
|
19
|
+
args: (data === null || data === void 0 ? void 0 : data.length) !== 0
|
|
20
|
+
? data.map((arg) => JSON.stringify(arg)).join(',')
|
|
21
|
+
: '',
|
|
22
|
+
});
|
|
14
23
|
}
|
|
15
24
|
/**
|
|
16
25
|
* Logging function equivalent to console.log
|
|
@@ -20,7 +29,7 @@ function addMessageToTraceSpan(method, message, args) {
|
|
|
20
29
|
* @param args additional data, will be stringified and appended
|
|
21
30
|
*/
|
|
22
31
|
const infoLogger = (source, message, apiKey, ...args) => {
|
|
23
|
-
addMessageToTraceSpan('log', message, args);
|
|
32
|
+
addMessageToTraceSpan('log', message, [...args]);
|
|
24
33
|
logger(console.info, source, message, apiKey, ...args);
|
|
25
34
|
};
|
|
26
35
|
exports.infoLogger = infoLogger;
|
|
@@ -32,7 +41,7 @@ exports.infoLogger = infoLogger;
|
|
|
32
41
|
* @param args additional data, will be stringified and appended
|
|
33
42
|
*/
|
|
34
43
|
const errorLogger = (source, message, apiKey, ...args) => {
|
|
35
|
-
addMessageToTraceSpan('error', message, args);
|
|
44
|
+
addMessageToTraceSpan('error', message, [...args]);
|
|
36
45
|
logger(console.error, source, message, apiKey, ...args);
|
|
37
46
|
};
|
|
38
47
|
exports.errorLogger = errorLogger;
|
|
@@ -44,7 +53,7 @@ exports.errorLogger = errorLogger;
|
|
|
44
53
|
* @param args additional data, will be stringified and appended
|
|
45
54
|
*/
|
|
46
55
|
const warnLogger = (source, message, apiKey, ...args) => {
|
|
47
|
-
addMessageToTraceSpan('warn', message, args);
|
|
56
|
+
addMessageToTraceSpan('warn', message, [...args]);
|
|
48
57
|
logger(console.warn, source, message, apiKey, ...args);
|
|
49
58
|
};
|
|
50
59
|
exports.warnLogger = warnLogger;
|
|
@@ -52,21 +61,25 @@ const logger = (logFn, source, message, apiKey, ...args) => {
|
|
|
52
61
|
// eslint-disable-next-line no-console
|
|
53
62
|
const anonymizedApiKey = apiKey ? (0, anonymize_key_1.anonymizeKey)(apiKey) : undefined;
|
|
54
63
|
const formatedMessage = constructLogMessage(anonymizedApiKey ? `[${anonymizedApiKey}]` : undefined, `[${source}]`, message);
|
|
55
|
-
if (process.env.NODE_ENV
|
|
64
|
+
if (process.env.NODE_ENV === 'development') {
|
|
56
65
|
logFn(formatedMessage, ...args);
|
|
66
|
+
return;
|
|
57
67
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}));
|
|
68
|
+
const data = Object.assign({}, args);
|
|
69
|
+
const userId = middlewares_1.playtypusUserIdStorage.getStore();
|
|
70
|
+
if (userId) {
|
|
71
|
+
data.platypusUserId = userId;
|
|
63
72
|
}
|
|
73
|
+
logFn(JSON.stringify({
|
|
74
|
+
message: formatedMessage,
|
|
75
|
+
data,
|
|
76
|
+
}));
|
|
64
77
|
};
|
|
65
78
|
const constructLogMessage = (...args) => `${args
|
|
66
79
|
.flat()
|
|
67
|
-
.filter((item) => item
|
|
80
|
+
.filter((item) => item !== undefined)
|
|
68
81
|
.map((item) => {
|
|
69
|
-
if (Array.isArray(item) && item.length
|
|
82
|
+
if (Array.isArray(item) && item.length === 0)
|
|
70
83
|
return;
|
|
71
84
|
return typeof item !== 'string' ? JSON.stringify(item) : item;
|
|
72
85
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.util.js","sourceRoot":"","sources":["../../src/util/logger.util.ts"],"names":[],"mappings":";;;AAAA,mDAA+C;AAC/C,
|
|
1
|
+
{"version":3,"file":"logger.util.js","sourceRoot":"","sources":["../../src/util/logger.util.ts"],"names":[],"mappings":";;;AAAA,4CAAoD;AAEpD,mD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