@mondaydotcomorg/monday-authorization 1.2.5 → 1.2.6
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.
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAttributionsFromApi = void 0;
|
|
4
|
+
const trident_backend_api_1 = require("@mondaydotcomorg/trident-backend-api");
|
|
5
|
+
const FROM_SDK_HEADER_SUFFIX = `-from-sdk`;
|
|
6
|
+
function getAttributionsFromApi() {
|
|
7
|
+
const tridentContext = trident_backend_api_1.Api.getPart('context');
|
|
8
|
+
if (!tridentContext) {
|
|
9
|
+
return {};
|
|
10
|
+
}
|
|
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
|
+
}
|
|
19
|
+
exports.getAttributionsFromApi = getAttributionsFromApi;
|
|
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.AuthorizationAttributesService = void 0;
|
|
13
13
|
const monday_fetch_1 = require("@mondaydotcomorg/monday-fetch");
|
|
14
14
|
const authorization_internal_service_1 = require("./authorization-internal-service");
|
|
15
|
+
const attributions_service_1 = require("./attributions-service");
|
|
15
16
|
class AuthorizationAttributesService {
|
|
16
17
|
/**
|
|
17
18
|
* Upsert resource attributes synchronously, performing http call to the authorization MS to assign the given attributes to the given resource.
|
|
@@ -24,9 +25,10 @@ class AuthorizationAttributesService {
|
|
|
24
25
|
static upsertResourceAttributes(accountId, userId, resourceAttributeAssignments) {
|
|
25
26
|
return __awaiter(this, void 0, void 0, function* () {
|
|
26
27
|
const internalAuthToken = authorization_internal_service_1.AuthorizationInternalService.generateInternalAuthToken(accountId, userId);
|
|
28
|
+
const attributionHeaders = (0, attributions_service_1.getAttributionsFromApi)();
|
|
27
29
|
const response = yield (0, monday_fetch_1.fetch)(this.getResourceAttributesUrl(accountId), {
|
|
28
30
|
method: 'POST',
|
|
29
|
-
headers: { Authorization: internalAuthToken, 'Content-Type': 'application/json' },
|
|
31
|
+
headers: Object.assign({ Authorization: internalAuthToken, 'Content-Type': 'application/json' }, attributionHeaders),
|
|
30
32
|
timeout: authorization_internal_service_1.AuthorizationInternalService.getRequestTimeout(),
|
|
31
33
|
body: JSON.stringify({ resourceAttributeAssignments }),
|
|
32
34
|
}, authorization_internal_service_1.AuthorizationInternalService.getRequestFetchOptions());
|
|
@@ -47,9 +49,10 @@ class AuthorizationAttributesService {
|
|
|
47
49
|
return __awaiter(this, void 0, void 0, function* () {
|
|
48
50
|
const internalAuthToken = authorization_internal_service_1.AuthorizationInternalService.generateInternalAuthToken(accountId, userId);
|
|
49
51
|
const url = `${this.getResourceAttributesUrl(accountId)}/${resource.type}/${resource.id}`;
|
|
52
|
+
const attributionHeaders = (0, attributions_service_1.getAttributionsFromApi)();
|
|
50
53
|
const response = yield (0, monday_fetch_1.fetch)(url, {
|
|
51
54
|
method: 'DELETE',
|
|
52
|
-
headers: { Authorization: internalAuthToken, 'Content-Type': 'application/json' },
|
|
55
|
+
headers: Object.assign({ Authorization: internalAuthToken, 'Content-Type': 'application/json' }, attributionHeaders),
|
|
53
56
|
timeout: authorization_internal_service_1.AuthorizationInternalService.getRequestTimeout(),
|
|
54
57
|
body: JSON.stringify({ keys: attributeKeys }),
|
|
55
58
|
}, authorization_internal_service_1.AuthorizationInternalService.getRequestFetchOptions());
|
|
@@ -15,6 +15,7 @@ const perf_hooks_1 = require("perf_hooks");
|
|
|
15
15
|
const monday_fetch_1 = require("@mondaydotcomorg/monday-fetch");
|
|
16
16
|
const prometheus_service_1 = require("./prometheus-service");
|
|
17
17
|
const authorization_internal_service_1 = require("./authorization-internal-service");
|
|
18
|
+
const attributions_service_1 = require("./attributions-service");
|
|
18
19
|
const GRANTED_FEATURE_CACHE_EXPIRATION_SECONDS = 5 * 60;
|
|
19
20
|
function setRequestFetchOptions(customMondayFetchOptions) {
|
|
20
21
|
authorization_internal_service_1.AuthorizationInternalService.setRequestFetchOptions(customMondayFetchOptions);
|
|
@@ -90,9 +91,10 @@ class AuthorizationService {
|
|
|
90
91
|
const scopedActionsPayload = scopedActions.map(scopedAction => {
|
|
91
92
|
return Object.assign(Object.assign({}, scopedAction), { scope: (0, lodash_1.mapKeys)(scopedAction.scope, (_, key) => (0, lodash_1.snakeCase)(key)) }); // for example: { workspaceId: 1 } => { workspace_id: 1 }
|
|
92
93
|
});
|
|
94
|
+
const attributionHeaders = (0, attributions_service_1.getAttributionsFromApi)();
|
|
93
95
|
const response = yield (0, monday_fetch_1.fetch)(getCanActionsInScopesUrl(), {
|
|
94
96
|
method: 'POST',
|
|
95
|
-
headers: { Authorization: internalAuthToken, 'Content-Type': 'application/json' },
|
|
97
|
+
headers: Object.assign({ Authorization: internalAuthToken, 'Content-Type': 'application/json' }, attributionHeaders),
|
|
96
98
|
timeout: authorization_internal_service_1.AuthorizationInternalService.getRequestTimeout(),
|
|
97
99
|
body: JSON.stringify({
|
|
98
100
|
user_id: userId,
|
|
@@ -101,11 +103,11 @@ class AuthorizationService {
|
|
|
101
103
|
}, authorization_internal_service_1.AuthorizationInternalService.getRequestFetchOptions());
|
|
102
104
|
authorization_internal_service_1.AuthorizationInternalService.throwOnHttpErrorIfNeeded(response, 'canActionInScopeMultiple');
|
|
103
105
|
const responseBody = yield response.json();
|
|
104
|
-
const camelCaseKeys =
|
|
106
|
+
const camelCaseKeys = obj => Object.fromEntries(Object.entries(obj).map(([key, value]) => [(0, lodash_1.camelCase)(key), value]));
|
|
105
107
|
const scopedActionsResponseObjects = responseBody.result.map(responseObject => {
|
|
106
108
|
const { scopedAction, permit } = responseObject;
|
|
107
109
|
const { scope } = scopedAction;
|
|
108
|
-
const transformKeys =
|
|
110
|
+
const transformKeys = obj => camelCaseKeys(obj);
|
|
109
111
|
return Object.assign(Object.assign({}, responseObject), { scopedAction: Object.assign(Object.assign({}, scopedAction), { scope: transformKeys(scope) }), permit: transformKeys(permit) });
|
|
110
112
|
});
|
|
111
113
|
return scopedActionsResponseObjects;
|
|
@@ -121,9 +123,10 @@ class AuthorizationService {
|
|
|
121
123
|
return __awaiter(this, void 0, void 0, function* () {
|
|
122
124
|
const internalAuthToken = authorization_internal_service_1.AuthorizationInternalService.generateInternalAuthToken(accountId, userId);
|
|
123
125
|
const startTime = perf_hooks_1.performance.now();
|
|
126
|
+
const attributionHeaders = (0, attributions_service_1.getAttributionsFromApi)();
|
|
124
127
|
const response = yield (0, monday_fetch_1.fetch)(getAuthorizeUrl(), {
|
|
125
128
|
method: 'POST',
|
|
126
|
-
headers: { Authorization: internalAuthToken, 'Content-Type': 'application/json' },
|
|
129
|
+
headers: Object.assign({ Authorization: internalAuthToken, 'Content-Type': 'application/json' }, attributionHeaders),
|
|
127
130
|
timeout: authorization_internal_service_1.AuthorizationInternalService.getRequestTimeout(),
|
|
128
131
|
body: JSON.stringify({
|
|
129
132
|
user_id: userId,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mondaydotcomorg/monday-authorization",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.6",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"license": "BSD-3-Clause",
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"@mondaydotcomorg/monday-fetch": "^0.0.7",
|
|
13
13
|
"@mondaydotcomorg/monday-jwt": "^3.0.10",
|
|
14
14
|
"@mondaydotcomorg/monday-logger": "^3.0.10",
|
|
15
|
+
"@mondaydotcomorg/trident-backend-api": "^0.21.0",
|
|
15
16
|
"node-fetch": "^2.6.7",
|
|
16
17
|
"on-headers": "^1.0.2",
|
|
17
18
|
"ts-node": "^10.0.0"
|
|
@@ -32,5 +33,5 @@
|
|
|
32
33
|
"files": [
|
|
33
34
|
"dist/"
|
|
34
35
|
],
|
|
35
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "cbf1fb90ca3bda14aaf1581c05d3af92eb659e1d"
|
|
36
37
|
}
|