@pgds/api-interface 1.4.8 → 1.4.9
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.
|
@@ -13,6 +13,10 @@ interface RequestStore {
|
|
|
13
13
|
* Will be automatically be added to any requests made with the clients extending FairtrailClient.
|
|
14
14
|
**/
|
|
15
15
|
reqId: string;
|
|
16
|
+
/**
|
|
17
|
+
* User agent of the current request
|
|
18
|
+
*/
|
|
19
|
+
userAgent?: string;
|
|
16
20
|
}
|
|
17
21
|
type RequestContext = Request | string;
|
|
18
22
|
/**
|
package/lib/utils/asyncHooks.js
CHANGED
|
@@ -39,6 +39,7 @@ var constants_1 = require("../../constants");
|
|
|
39
39
|
var async_hooks_1 = require("async_hooks");
|
|
40
40
|
var ReqUser_1 = require("../models/ReqUser");
|
|
41
41
|
var uuid = __importStar(require("uuid"));
|
|
42
|
+
var USER_AGENT_HEADER = "user-agent";
|
|
42
43
|
function isRequest(reqContext) {
|
|
43
44
|
return !!reqContext && typeof reqContext === "object";
|
|
44
45
|
}
|
|
@@ -51,18 +52,20 @@ var asyncLocalStorage = new async_hooks_1.AsyncLocalStorage();
|
|
|
51
52
|
* @throws Any error thrown by the inputted function
|
|
52
53
|
*/
|
|
53
54
|
function runWithRequestContext(reqContext, fn) {
|
|
54
|
-
var _a, _b, _c, _d;
|
|
55
|
+
var _a, _b, _c, _d, _e;
|
|
55
56
|
var reqId = "";
|
|
56
57
|
var user = undefined;
|
|
58
|
+
var userAgent = undefined;
|
|
57
59
|
if (isRequest(reqContext)) {
|
|
58
60
|
reqId = (_c = (_b = (_a = reqContext.header) === null || _a === void 0 ? void 0 : _a.call(reqContext, constants_1.REQUEST_ID_HEADER)) !== null && _b !== void 0 ? _b : reqContext.getId()) !== null && _c !== void 0 ? _c : uuid.v4();
|
|
59
61
|
user = (_d = reqContext.user) !== null && _d !== void 0 ? _d : getFallbackUser(reqContext);
|
|
62
|
+
userAgent = (_e = reqContext.header) === null || _e === void 0 ? void 0 : _e.call(reqContext, USER_AGENT_HEADER);
|
|
60
63
|
}
|
|
61
64
|
else {
|
|
62
65
|
reqId = reqContext !== null && reqContext !== void 0 ? reqContext : uuid.v4();
|
|
63
66
|
}
|
|
64
67
|
return new Promise(function (resolve, reject) {
|
|
65
|
-
asyncLocalStorage.run({ reqId: reqId, user: user }, function () {
|
|
68
|
+
asyncLocalStorage.run({ reqId: reqId, user: user, userAgent: userAgent }, function () {
|
|
66
69
|
try {
|
|
67
70
|
resolve(fn());
|
|
68
71
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asyncHooks.js","sourceRoot":"","sources":["asyncHooks.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"asyncHooks.js","sourceRoot":"","sources":["asyncHooks.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmDA,sDA0BC;AAGD,kCAEC;AAlFD,6CAOyB;AACzB,2CAAgD;AAChD,6CAA4C;AAE5C,yCAA6B;AAE7B,IAAM,iBAAiB,GAAG,YAAY,CAAC;AAyBvC,SAAS,SAAS,CAAC,UAA0B;IAC3C,OAAO,CAAC,CAAC,UAAU,IAAI,OAAO,UAAU,KAAK,QAAQ,CAAC;AACxD,CAAC;AAED,IAAM,iBAAiB,GAAG,IAAI,+BAAiB,EAAgB,CAAC;AAEhE;;;;;;GAMG;AACH,SAAgB,qBAAqB,CACnC,UAA0B,EAC1B,EAA8B;;IAE9B,IAAI,KAAK,GAAG,EAAE,CAAC;IACf,IAAI,IAAI,GAAwB,SAAS,CAAC;IAC1C,IAAI,SAAS,GAAuB,SAAS,CAAC;IAE9C,IAAI,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC;QAC1B,KAAK,GAAG,MAAA,MAAA,MAAA,UAAU,CAAC,MAAM,2DAAG,6BAAiB,CAAC,mCAAI,UAAU,CAAC,KAAK,EAAE,mCAAI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