@mondaydotcomorg/monday-authorization 1.2.6 → 1.2.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.
- package/dist/lib/attributions-service.js +45 -10
- package/package.json +2 -2
|
@@ -2,18 +2,53 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getAttributionsFromApi = void 0;
|
|
4
4
|
const trident_backend_api_1 = require("@mondaydotcomorg/trident-backend-api");
|
|
5
|
+
const authorization_internal_service_1 = require("./authorization-internal-service");
|
|
6
|
+
const APP_NAME_VARIABLE_KEY = 'APP_NAME';
|
|
7
|
+
const APP_NAME_HEADER_NAME = 'x-caller-app-name-from-sdk';
|
|
5
8
|
const FROM_SDK_HEADER_SUFFIX = `-from-sdk`;
|
|
9
|
+
let didSendFailureLogOnce = false;
|
|
6
10
|
function getAttributionsFromApi() {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
11
|
+
let callerAppNameFromSdk = {
|
|
12
|
+
[APP_NAME_HEADER_NAME]: tryJsonParse(getEnvVariable(APP_NAME_VARIABLE_KEY)),
|
|
13
|
+
};
|
|
14
|
+
try {
|
|
15
|
+
const tridentContext = trident_backend_api_1.Api.getPart('context');
|
|
16
|
+
if (!tridentContext) {
|
|
17
|
+
return callerAppNameFromSdk;
|
|
18
|
+
}
|
|
19
|
+
const { runtimeAttributions } = tridentContext;
|
|
20
|
+
let runtimeAttributionsOutgoingHeaders = runtimeAttributions === null || runtimeAttributions === void 0 ? void 0 : runtimeAttributions.buildOutgoingHeaders('HTTP_INTERNAL');
|
|
21
|
+
if (!runtimeAttributionsOutgoingHeaders) {
|
|
22
|
+
return callerAppNameFromSdk;
|
|
23
|
+
}
|
|
24
|
+
const attributionsHeaders = Object.fromEntries(runtimeAttributionsOutgoingHeaders);
|
|
25
|
+
const attributionHeadersFromSdk = {};
|
|
26
|
+
Object.keys(attributionsHeaders).forEach(function (key) {
|
|
27
|
+
attributionHeadersFromSdk[`${key}${FROM_SDK_HEADER_SUFFIX}`] = attributionsHeaders[key];
|
|
28
|
+
});
|
|
29
|
+
return attributionHeadersFromSdk;
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
if (!didSendFailureLogOnce) {
|
|
33
|
+
authorization_internal_service_1.logger.warn({ tag: 'authorization-service', error }, 'Failed to generate attributions headers from the API. Unexpected error while extracting headers. It may be caused by out of date Trident version.');
|
|
34
|
+
didSendFailureLogOnce = true;
|
|
35
|
+
}
|
|
36
|
+
return callerAppNameFromSdk;
|
|
10
37
|
}
|
|
11
|
-
const { runtimeAttributions } = tridentContext;
|
|
12
|
-
const attributionsHeaders = Object.fromEntries(runtimeAttributions === null || runtimeAttributions === void 0 ? void 0 : runtimeAttributions.buildOutgoingHeaders('HTTP_INTERNAL'));
|
|
13
|
-
const attributionHeadersFromSdk = {};
|
|
14
|
-
Object.keys(attributionsHeaders).forEach(function (key) {
|
|
15
|
-
attributionHeadersFromSdk[`${key}${FROM_SDK_HEADER_SUFFIX}`] = attributionsHeaders[key];
|
|
16
|
-
});
|
|
17
|
-
return attributionHeadersFromSdk;
|
|
18
38
|
}
|
|
19
39
|
exports.getAttributionsFromApi = getAttributionsFromApi;
|
|
40
|
+
function getEnvVariable(key) {
|
|
41
|
+
const envVar = process.env[key] || process.env[key.toUpperCase()] || process.env[key.toLowerCase()];
|
|
42
|
+
return envVar;
|
|
43
|
+
}
|
|
44
|
+
function tryJsonParse(value) {
|
|
45
|
+
if (!value) {
|
|
46
|
+
return value;
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
return JSON.parse(value);
|
|
50
|
+
}
|
|
51
|
+
catch (_err) {
|
|
52
|
+
return value;
|
|
53
|
+
}
|
|
54
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mondaydotcomorg/monday-authorization",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.7",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"license": "BSD-3-Clause",
|
|
@@ -33,5 +33,5 @@
|
|
|
33
33
|
"files": [
|
|
34
34
|
"dist/"
|
|
35
35
|
],
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "28c91ae70b102828d704a290cb9f4ad1bed5b17e"
|
|
37
37
|
}
|