@mondaydotcomorg/monday-authorization 1.1.9-featurebelkaauthz-sdk-update.2216 → 1.1.9-featurebelkaauthz-sdk-update.2218

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 @@
1
+ export declare function getAttributionsFromApi(): {};
@@ -0,0 +1,17 @@
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
+ // @ts-expect-error not an error
9
+ const { runtimeAttributions } = tridentContext;
10
+ const attributionsHeaders = Object.fromEntries(runtimeAttributions === null || runtimeAttributions === void 0 ? void 0 : runtimeAttributions.buildOutgoingHeaders('HTTP_INTERNAL'));
11
+ const attributionHeadersFromSdk = {};
12
+ Object.keys(attributionsHeaders).forEach(function (key) {
13
+ attributionHeadersFromSdk[`${key}${FROM_SDK_HEADER_SUFFIX}`] = attributionsHeaders[key];
14
+ });
15
+ return attributionHeadersFromSdk;
16
+ }
17
+ exports.getAttributionsFromApi = getAttributionsFromApi;
@@ -12,7 +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 authorization_service_1 = require("./authorization-service");
15
+ const attributions_service_1 = require("lib/attributions-service");
16
16
  class AuthorizationAttributesService {
17
17
  /**
18
18
  * Upsert resource attributes synchronously, performing http call to the authorization MS to assign the given attributes to the given resource.
@@ -25,10 +25,10 @@ class AuthorizationAttributesService {
25
25
  static upsertResourceAttributes(accountId, userId, resourceAttributeAssignments) {
26
26
  return __awaiter(this, void 0, void 0, function* () {
27
27
  const internalAuthToken = authorization_internal_service_1.AuthorizationInternalService.generateInternalAuthToken(accountId, userId);
28
- const attributionHeaders = (0, authorization_service_1.getAttributionsFromApi)();
28
+ const attributionHeaders = (0, attributions_service_1.getAttributionsFromApi)();
29
29
  const response = yield (0, monday_fetch_1.fetch)(this.getResourceAttributesUrl(accountId), {
30
30
  method: 'POST',
31
- headers: Object.assign({ Authorization: internalAuthToken, 'Content-Type': 'application/json', 'X-INTERNAL-CONTROLLER-CALLER-APP-NAME': (0, authorization_service_1.getCurrentAppName)() }, attributionHeaders),
31
+ headers: Object.assign({ Authorization: internalAuthToken, 'Content-Type': 'application/json' }, attributionHeaders),
32
32
  timeout: authorization_internal_service_1.AuthorizationInternalService.getRequestTimeout(),
33
33
  body: JSON.stringify({ resourceAttributeAssignments }),
34
34
  }, authorization_internal_service_1.AuthorizationInternalService.getRequestFetchOptions());
@@ -49,10 +49,10 @@ class AuthorizationAttributesService {
49
49
  return __awaiter(this, void 0, void 0, function* () {
50
50
  const internalAuthToken = authorization_internal_service_1.AuthorizationInternalService.generateInternalAuthToken(accountId, userId);
51
51
  const url = `${this.getResourceAttributesUrl(accountId)}/${resource.type}/${resource.id}`;
52
- const attributionHeaders = (0, authorization_service_1.getAttributionsFromApi)();
52
+ const attributionHeaders = (0, attributions_service_1.getAttributionsFromApi)();
53
53
  const response = yield (0, monday_fetch_1.fetch)(url, {
54
54
  method: 'DELETE',
55
- headers: Object.assign({ Authorization: internalAuthToken, 'Content-Type': 'application/json', 'X-INTERNAL-CONTROLLER-CALLER-APP-NAME': (0, authorization_service_1.getCurrentAppName)() }, attributionHeaders),
55
+ headers: Object.assign({ Authorization: internalAuthToken, 'Content-Type': 'application/json' }, attributionHeaders),
56
56
  timeout: authorization_internal_service_1.AuthorizationInternalService.getRequestTimeout(),
57
57
  body: JSON.stringify({ keys: attributeKeys }),
58
58
  }, authorization_internal_service_1.AuthorizationInternalService.getRequestFetchOptions());
@@ -27,8 +27,3 @@ export declare class AuthorizationService {
27
27
  private static isAuthorizedSingular;
28
28
  private static isAuthorizedMultiple;
29
29
  }
30
- export declare function getCurrentAppName(): string;
31
- export declare function getAttributions(): any;
32
- export declare function getAttributionsFromApi(): {
33
- [k: string]: any;
34
- };
@@ -9,15 +9,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.getAttributionsFromApi = exports.getAttributions = exports.getCurrentAppName = exports.AuthorizationService = exports.setRedisClient = exports.setRequestFetchOptions = void 0;
12
+ exports.AuthorizationService = exports.setRedisClient = exports.setRequestFetchOptions = void 0;
13
13
  const lodash_1 = require("lodash");
14
14
  const perf_hooks_1 = require("perf_hooks");
15
15
  const monday_fetch_1 = require("@mondaydotcomorg/monday-fetch");
16
- const trident_backend_api_1 = require("@mondaydotcomorg/trident-backend-api");
17
16
  const prometheus_service_1 = require("./prometheus-service");
18
17
  const authorization_internal_service_1 = require("./authorization-internal-service");
18
+ const attributions_service_1 = require("lib/attributions-service");
19
19
  const GRANTED_FEATURE_CACHE_EXPIRATION_SECONDS = 5 * 60;
20
- const APP_NAME_VARIABLE_KEY = 'APP_NAME';
21
20
  function setRequestFetchOptions(customMondayFetchOptions) {
22
21
  authorization_internal_service_1.AuthorizationInternalService.setRequestFetchOptions(customMondayFetchOptions);
23
22
  }
@@ -92,10 +91,10 @@ class AuthorizationService {
92
91
  const scopedActionsPayload = scopedActions.map(scopedAction => {
93
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 }
94
93
  });
95
- const attributionHeaders = getAttributionsFromApi();
94
+ const attributionHeaders = (0, attributions_service_1.getAttributionsFromApi)();
96
95
  const response = yield (0, monday_fetch_1.fetch)(getCanActionsInScopesUrl(), {
97
96
  method: 'POST',
98
- headers: Object.assign({ Authorization: internalAuthToken, 'Content-Type': 'application/json', 'X-INTERNAL-CONTROLLER-CALLER-APP-NAME': getCurrentAppName() }, attributionHeaders),
97
+ headers: Object.assign({ Authorization: internalAuthToken, 'Content-Type': 'application/json' }, attributionHeaders),
99
98
  timeout: authorization_internal_service_1.AuthorizationInternalService.getRequestTimeout(),
100
99
  body: JSON.stringify({
101
100
  user_id: userId,
@@ -124,10 +123,10 @@ class AuthorizationService {
124
123
  return __awaiter(this, void 0, void 0, function* () {
125
124
  const internalAuthToken = authorization_internal_service_1.AuthorizationInternalService.generateInternalAuthToken(accountId, userId);
126
125
  const startTime = perf_hooks_1.performance.now();
127
- const attributionHeaders = getAttributionsFromApi();
126
+ const attributionHeaders = (0, attributions_service_1.getAttributionsFromApi)();
128
127
  const response = yield (0, monday_fetch_1.fetch)(getAuthorizeUrl(), {
129
128
  method: 'POST',
130
- headers: Object.assign({ Authorization: internalAuthToken, 'Content-Type': 'application/json', 'X-INTERNAL-CONTROLLER-CALLER-APP-NAME': getCurrentAppName() }, attributionHeaders),
129
+ headers: Object.assign({ Authorization: internalAuthToken, 'Content-Type': 'application/json' }, attributionHeaders),
131
130
  timeout: authorization_internal_service_1.AuthorizationInternalService.getRequestTimeout(),
132
131
  body: JSON.stringify({
133
132
  user_id: userId,
@@ -184,54 +183,3 @@ function getAuthorizeUrl() {
184
183
  function getCanActionsInScopesUrl() {
185
184
  return `${process.env.MONDAY_INTERNAL_URL}/internal_ms/authorization/can_actions_in_scopes`;
186
185
  }
187
- function getCurrentAppName() {
188
- try {
189
- return getVariable(APP_NAME_VARIABLE_KEY);
190
- }
191
- catch (error) {
192
- authorization_internal_service_1.logger.warn('Failed to get app name environment variable for runtime attributions', { error: error });
193
- return 'MISSING';
194
- }
195
- }
196
- exports.getCurrentAppName = getCurrentAppName;
197
- function getAttributions() {
198
- var _a;
199
- let attributions = (_a = getVariable('runtime_attributions/valid_attributes', { silent: true })) === null || _a === void 0 ? void 0 : _a.attributions;
200
- return attributions;
201
- }
202
- exports.getAttributions = getAttributions;
203
- function getAttributionsFromApi() {
204
- const tridentContext = trident_backend_api_1.Api.getPart('context');
205
- // @ts-expect-error not an error
206
- const { runtimeAttributions } = tridentContext;
207
- const attributionsHeaders = Object.fromEntries(runtimeAttributions === null || runtimeAttributions === void 0 ? void 0 : runtimeAttributions.buildOutgoingHeaders('HTTP_INTERNAL'));
208
- // const attributionHeadersInternal = {};
209
- // Object.keys(attributionsHeaders).forEach(function (key) {
210
- // attributionHeadersInternal[`${key}_internal`] = attributionsHeaders[key];
211
- // });
212
- // let attributions = getVariable('runtime_attributions/valid_attributes', { silent: true });
213
- return attributionsHeaders;
214
- }
215
- exports.getAttributionsFromApi = getAttributionsFromApi;
216
- function getVariable(key, options = { silent: false }) {
217
- const result = tryJsonParse(getEnvVariable(key));
218
- if (result === undefined && !options.silent) {
219
- authorization_internal_service_1.logger.warn(`Configuration variable ${key} is undefined`);
220
- }
221
- return result;
222
- }
223
- function getEnvVariable(key) {
224
- const envVar = process.env[key] || process.env[key.toUpperCase()] || process.env[key.toLowerCase()];
225
- return envVar;
226
- }
227
- function tryJsonParse(value) {
228
- if (!value) {
229
- return value;
230
- }
231
- try {
232
- return JSON.parse(value);
233
- }
234
- catch (_err) {
235
- return value;
236
- }
237
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mondaydotcomorg/monday-authorization",
3
- "version": "1.1.9-featurebelkaauthz-sdk-update.2216+2b62de57a",
3
+ "version": "1.1.9-featurebelkaauthz-sdk-update.2218+6089f7fd7",
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": "2b62de57a2f9febf0252f64d25e11624a59bb765"
36
+ "gitHead": "6089f7fd700a4b48deb8d603fe433324bda9bf95"
37
37
  }