@mondaydotcomorg/monday-authorization 1.2.11 → 1.2.12

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.
Files changed (76) hide show
  1. package/dist/{lib/attributions-service.js → attributions-service.js} +11 -10
  2. package/dist/authorization-attributes-service.js +144 -0
  3. package/dist/{lib/authorization-internal-service.d.ts → authorization-internal-service.d.ts} +1 -1
  4. package/dist/authorization-internal-service.js +80 -0
  5. package/dist/{lib/authorization-middleware.d.ts → authorization-middleware.d.ts} +1 -1
  6. package/dist/authorization-middleware.js +48 -0
  7. package/dist/authorization-service.js +176 -0
  8. package/dist/constants/sns.js +9 -0
  9. package/dist/esm/attributions-service.d.ts +3 -0
  10. package/dist/esm/attributions-service.mjs +53 -0
  11. package/dist/esm/authorization-attributes-service.d.ts +44 -0
  12. package/dist/esm/authorization-attributes-service.mjs +138 -0
  13. package/dist/esm/authorization-internal-service.d.ts +13 -0
  14. package/dist/esm/authorization-internal-service.mjs +57 -0
  15. package/dist/esm/authorization-middleware.d.ts +6 -0
  16. package/dist/esm/authorization-middleware.mjs +39 -0
  17. package/dist/esm/authorization-service.d.ts +29 -0
  18. package/dist/esm/authorization-service.mjs +172 -0
  19. package/dist/esm/constants/sns.d.ts +3 -0
  20. package/dist/esm/constants/sns.mjs +5 -0
  21. package/dist/esm/index.d.ts +13 -0
  22. package/dist/esm/index.mjs +21 -0
  23. package/dist/esm/prometheus-service.mjs +49 -0
  24. package/dist/{lib → esm}/testKit/index.d.ts +2 -2
  25. package/dist/esm/testKit/index.mjs +44 -0
  26. package/dist/esm/types/authorization-attributes-contracts.mjs +7 -0
  27. package/dist/esm/types/express.mjs +1 -0
  28. package/dist/{lib → esm}/types/general.d.ts +6 -4
  29. package/dist/esm/types/general.mjs +1 -0
  30. package/dist/esm/types/scoped-actions-contracts.mjs +8 -0
  31. package/dist/index.d.ts +4 -4
  32. package/dist/index.js +19 -43
  33. package/dist/prometheus-service.d.ts +10 -0
  34. package/dist/{lib/prometheus-service.js → prometheus-service.js} +18 -14
  35. package/dist/testKit/index.d.ts +11 -0
  36. package/dist/testKit/index.js +48 -0
  37. package/dist/types/authorization-attributes-contracts.d.ts +27 -0
  38. package/dist/types/authorization-attributes-contracts.js +7 -0
  39. package/dist/types/express.d.ts +10 -0
  40. package/dist/types/express.js +1 -0
  41. package/dist/types/general.d.ts +32 -0
  42. package/dist/types/general.js +1 -0
  43. package/dist/types/scoped-actions-contracts.d.ts +38 -0
  44. package/dist/{lib/types → types}/scoped-actions-contracts.js +3 -5
  45. package/package.json +25 -28
  46. package/dist/index.js.map +0 -1
  47. package/dist/lib/attributions-service.js.map +0 -1
  48. package/dist/lib/authorization-attributes-service.js +0 -155
  49. package/dist/lib/authorization-attributes-service.js.map +0 -1
  50. package/dist/lib/authorization-internal-service.js +0 -79
  51. package/dist/lib/authorization-internal-service.js.map +0 -1
  52. package/dist/lib/authorization-middleware.js +0 -57
  53. package/dist/lib/authorization-middleware.js.map +0 -1
  54. package/dist/lib/authorization-service.js +0 -186
  55. package/dist/lib/authorization-service.js.map +0 -1
  56. package/dist/lib/constants/sns.js +0 -7
  57. package/dist/lib/constants/sns.js.map +0 -1
  58. package/dist/lib/prometheus-service.js.map +0 -1
  59. package/dist/lib/testKit/index.js +0 -59
  60. package/dist/lib/testKit/index.js.map +0 -1
  61. package/dist/lib/types/authorization-attributes-contracts.js +0 -9
  62. package/dist/lib/types/authorization-attributes-contracts.js.map +0 -1
  63. package/dist/lib/types/express.js +0 -2
  64. package/dist/lib/types/express.js.map +0 -1
  65. package/dist/lib/types/general.js +0 -3
  66. package/dist/lib/types/general.js.map +0 -1
  67. package/dist/lib/types/scoped-actions-contracts.js.map +0 -1
  68. package/dist/tsconfig.tsbuildinfo +0 -1
  69. package/dist/{lib/attributions-service.d.ts → attributions-service.d.ts} +0 -0
  70. package/dist/{lib/authorization-attributes-service.d.ts → authorization-attributes-service.d.ts} +0 -0
  71. package/dist/{lib/authorization-service.d.ts → authorization-service.d.ts} +1 -1
  72. /package/dist/{lib/constants → constants}/sns.d.ts +0 -0
  73. /package/dist/{lib → esm}/prometheus-service.d.ts +0 -0
  74. /package/dist/{lib → esm}/types/authorization-attributes-contracts.d.ts +0 -0
  75. /package/dist/{lib → esm}/types/express.d.ts +0 -0
  76. /package/dist/{lib → esm}/types/scoped-actions-contracts.d.ts +0 -0
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,8 @@
1
+ var PermitTechnicalReason;
2
+ (function (PermitTechnicalReason) {
3
+ PermitTechnicalReason[PermitTechnicalReason["NO_REASON"] = 0] = "NO_REASON";
4
+ PermitTechnicalReason[PermitTechnicalReason["NOT_ELIGIBLE"] = 1] = "NOT_ELIGIBLE";
5
+ PermitTechnicalReason[PermitTechnicalReason["BY_ROLE_IN_SCOPE"] = 2] = "BY_ROLE_IN_SCOPE";
6
+ })(PermitTechnicalReason || (PermitTechnicalReason = {}));
7
+
8
+ export { PermitTechnicalReason };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { MondayFetchOptions } from '@mondaydotcomorg/monday-fetch';
2
- import * as TestKit from './lib/testKit';
2
+ import * as TestKit from './testKit';
3
3
  export interface InitOptions {
4
4
  prometheus?: any;
5
5
  mondayFetchOptions?: MondayFetchOptions;
@@ -7,7 +7,7 @@ export interface InitOptions {
7
7
  grantedFeatureRedisExpirationInSeconds?: number;
8
8
  }
9
9
  export declare function init(options?: InitOptions): void;
10
- export { authorizationCheckMiddleware, getAuthorizationMiddleware, skipAuthorizationMiddleware, } from './lib/authorization-middleware';
11
- export { AuthorizationService } from './lib/authorization-service';
12
- export { AuthorizationAttributesService } from './lib/authorization-attributes-service';
10
+ export { authorizationCheckMiddleware, getAuthorizationMiddleware, skipAuthorizationMiddleware, } from './authorization-middleware';
11
+ export { AuthorizationService } from './authorization-service';
12
+ export { AuthorizationAttributesService } from './authorization-attributes-service';
13
13
  export { TestKit };
package/dist/index.js CHANGED
@@ -1,51 +1,27 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.TestKit = exports.AuthorizationAttributesService = exports.AuthorizationService = exports.skipAuthorizationMiddleware = exports.getAuthorizationMiddleware = exports.authorizationCheckMiddleware = void 0;
27
- exports.init = init;
28
- const prometheus_service_1 = require("./lib/prometheus-service");
29
- const authorization_service_1 = require("./lib/authorization-service");
30
- const TestKit = __importStar(require("./lib/testKit"));
31
- exports.TestKit = TestKit;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+
3
+ const prometheusService = require('./prometheus-service.js');
4
+ const authorizationService = require('./authorization-service.js');
5
+ const testKit_index = require('./testKit/index.js');
6
+ const authorizationMiddleware = require('./authorization-middleware.js');
7
+ const authorizationAttributesService = require('./authorization-attributes-service.js');
8
+
32
9
  function init(options = {}) {
33
10
  if (options.prometheus) {
34
- (0, prometheus_service_1.setPrometheus)(options.prometheus);
11
+ prometheusService.setPrometheus(options.prometheus);
35
12
  }
36
13
  if (options.mondayFetchOptions) {
37
- (0, authorization_service_1.setRequestFetchOptions)(options.mondayFetchOptions);
14
+ authorizationService.setRequestFetchOptions(options.mondayFetchOptions);
38
15
  }
39
16
  if (options.redisClient) {
40
- (0, authorization_service_1.setRedisClient)(options.redisClient, options.grantedFeatureRedisExpirationInSeconds);
17
+ authorizationService.setRedisClient(options.redisClient, options.grantedFeatureRedisExpirationInSeconds);
41
18
  }
42
19
  }
43
- var authorization_middleware_1 = require("./lib/authorization-middleware");
44
- Object.defineProperty(exports, "authorizationCheckMiddleware", { enumerable: true, get: function () { return authorization_middleware_1.authorizationCheckMiddleware; } });
45
- Object.defineProperty(exports, "getAuthorizationMiddleware", { enumerable: true, get: function () { return authorization_middleware_1.getAuthorizationMiddleware; } });
46
- Object.defineProperty(exports, "skipAuthorizationMiddleware", { enumerable: true, get: function () { return authorization_middleware_1.skipAuthorizationMiddleware; } });
47
- var authorization_service_2 = require("./lib/authorization-service");
48
- Object.defineProperty(exports, "AuthorizationService", { enumerable: true, get: function () { return authorization_service_2.AuthorizationService; } });
49
- var authorization_attributes_service_1 = require("./lib/authorization-attributes-service");
50
- Object.defineProperty(exports, "AuthorizationAttributesService", { enumerable: true, get: function () { return authorization_attributes_service_1.AuthorizationAttributesService; } });
51
- //# sourceMappingURL=index.js.map
20
+
21
+ exports.AuthorizationService = authorizationService.AuthorizationService;
22
+ exports.TestKit = testKit_index;
23
+ exports.authorizationCheckMiddleware = authorizationMiddleware.authorizationCheckMiddleware;
24
+ exports.getAuthorizationMiddleware = authorizationMiddleware.getAuthorizationMiddleware;
25
+ exports.skipAuthorizationMiddleware = authorizationMiddleware.skipAuthorizationMiddleware;
26
+ exports.AuthorizationAttributesService = authorizationAttributesService.AuthorizationAttributesService;
27
+ exports.init = init;
@@ -0,0 +1,10 @@
1
+ import { Action } from './types/general';
2
+ export declare const METRICS: {
3
+ AUTHORIZATION_CHECK: string;
4
+ AUTHORIZATION_CHECKS_PER_REQUEST: string;
5
+ AUTHORIZATION_CHECK_RESPONSE_TIME: string;
6
+ };
7
+ export declare function setPrometheus(customPrometheus: any): void;
8
+ export declare function getMetricsManager(): any;
9
+ export declare function sendAuthorizationChecksPerRequestMetric(responseStatus: any, amountOfAuthorizationObjects: any): void;
10
+ export declare function sendAuthorizationCheckResponseTimeMetric(resourceType: string, action: Action, isAuthorized: boolean, responseStatus: number, time: number): void;
@@ -1,25 +1,20 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.METRICS = void 0;
4
- exports.setPrometheus = setPrometheus;
5
- exports.getMetricsManager = getMetricsManager;
6
- exports.sendAuthorizationChecksPerRequestMetric = sendAuthorizationChecksPerRequestMetric;
7
- exports.sendAuthorizationCheckResponseTimeMetric = sendAuthorizationCheckResponseTimeMetric;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+
8
3
  let prometheus = null;
9
4
  let authorizationChecksPerRequestMetric = null;
10
5
  let authorizationCheckResponseTimeMetric = null;
11
- exports.METRICS = {
6
+ const METRICS = {
12
7
  AUTHORIZATION_CHECK: 'authorization_check',
13
8
  AUTHORIZATION_CHECKS_PER_REQUEST: 'authorization_checks_per_request',
14
9
  AUTHORIZATION_CHECK_RESPONSE_TIME: 'authorization_check_response_time',
15
10
  };
16
11
  const authorizationChecksPerRequestMetricConfig = {
17
- name: exports.METRICS.AUTHORIZATION_CHECKS_PER_REQUEST,
12
+ name: METRICS.AUTHORIZATION_CHECKS_PER_REQUEST,
18
13
  labels: ['responseStatus'],
19
14
  description: 'Authorization checks per request summary',
20
15
  };
21
16
  const authorizationCheckResponseTimeMetricConfig = {
22
- name: exports.METRICS.AUTHORIZATION_CHECK_RESPONSE_TIME,
17
+ name: METRICS.AUTHORIZATION_CHECK_RESPONSE_TIME,
23
18
  labels: ['resourceType', 'action', 'isAuthorized', 'responseStatus'],
24
19
  description: 'Authorization check response time summary',
25
20
  };
@@ -30,7 +25,7 @@ function setPrometheus(customPrometheus) {
30
25
  authorizationCheckResponseTimeMetric = getMetricsManager().addMetric(METRICS_TYPES.SUMMARY, authorizationCheckResponseTimeMetricConfig.name, authorizationCheckResponseTimeMetricConfig.labels, authorizationCheckResponseTimeMetricConfig.description);
31
26
  }
32
27
  function getMetricsManager() {
33
- return prometheus === null || prometheus === void 0 ? void 0 : prometheus.metricsManager;
28
+ return prometheus?.metricsManager;
34
29
  }
35
30
  function sendAuthorizationChecksPerRequestMetric(responseStatus, amountOfAuthorizationObjects) {
36
31
  try {
@@ -38,7 +33,9 @@ function sendAuthorizationChecksPerRequestMetric(responseStatus, amountOfAuthori
38
33
  authorizationChecksPerRequestMetric.labels(responseStatus).observe(amountOfAuthorizationObjects);
39
34
  }
40
35
  }
41
- catch (e) { }
36
+ catch (e) {
37
+ // ignore
38
+ }
42
39
  }
43
40
  function sendAuthorizationCheckResponseTimeMetric(resourceType, action, isAuthorized, responseStatus, time) {
44
41
  try {
@@ -46,6 +43,13 @@ function sendAuthorizationCheckResponseTimeMetric(resourceType, action, isAuthor
46
43
  authorizationCheckResponseTimeMetric.labels(resourceType, action, isAuthorized, responseStatus).observe(time);
47
44
  }
48
45
  }
49
- catch (e) { }
46
+ catch (e) {
47
+ // ignore
48
+ }
50
49
  }
51
- //# sourceMappingURL=prometheus-service.js.map
50
+
51
+ exports.METRICS = METRICS;
52
+ exports.getMetricsManager = getMetricsManager;
53
+ exports.sendAuthorizationCheckResponseTimeMetric = sendAuthorizationCheckResponseTimeMetric;
54
+ exports.sendAuthorizationChecksPerRequestMetric = sendAuthorizationChecksPerRequestMetric;
55
+ exports.setPrometheus = setPrometheus;
@@ -0,0 +1,11 @@
1
+ import { Action, BaseRequest, BaseResponse, ContextGetter, Resource, ResourceGetter } from '../types/general';
2
+ import type { NextFunction } from 'express';
3
+ export type TestPermittedAction = {
4
+ accountId: number;
5
+ userId: number;
6
+ resources: Resource[];
7
+ action: Action;
8
+ };
9
+ export declare const addTestPermittedAction: (accountId: number, userId: number, resources: Resource[], action: Action) => void;
10
+ export declare const clearTestPermittedActions: () => void;
11
+ export declare const getTestAuthorizationMiddleware: (action: Action, resourceGetter: ResourceGetter, contextGetter?: ContextGetter) => (request: BaseRequest, response: BaseResponse, next: NextFunction) => Promise<void>;
@@ -0,0 +1,48 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+
3
+ const authorizationMiddleware = require('../authorization-middleware.js');
4
+ const authorizationInternalService = require('../authorization-internal-service.js');
5
+
6
+ let testPermittedActions = [];
7
+ const addTestPermittedAction = (accountId, userId, resources, action) => {
8
+ testPermittedActions.push({ accountId, userId, resources, action });
9
+ };
10
+ const clearTestPermittedActions = () => {
11
+ testPermittedActions = [];
12
+ };
13
+ const isActionAuthorized = (accountId, userId, resources, action) => {
14
+ return {
15
+ isAuthorized: resources.every(_ => {
16
+ return testPermittedActions.some(combination => {
17
+ return (combination.accountId === accountId &&
18
+ combination.userId === userId &&
19
+ combination.action === action &&
20
+ combination.resources.some(combinationResource => {
21
+ return resources.some(resource => {
22
+ return (combinationResource.id === resource.id &&
23
+ combinationResource.type === resource.type &&
24
+ JSON.stringify(combinationResource.wrapperData) === JSON.stringify(resource.wrapperData));
25
+ });
26
+ }));
27
+ });
28
+ }),
29
+ };
30
+ };
31
+ const getTestAuthorizationMiddleware = (action, resourceGetter, contextGetter) => {
32
+ return async function authorizationMiddleware$1(request, response, next) {
33
+ contextGetter ||= authorizationMiddleware.defaultContextGetter;
34
+ const { userId, accountId } = contextGetter(request);
35
+ const resources = resourceGetter(request);
36
+ const { isAuthorized } = isActionAuthorized(accountId, userId, resources, action);
37
+ authorizationInternalService.AuthorizationInternalService.markAuthorized(request);
38
+ if (!isAuthorized) {
39
+ response.status(403).json({ message: 'Access denied' });
40
+ return;
41
+ }
42
+ next();
43
+ };
44
+ };
45
+
46
+ exports.addTestPermittedAction = addTestPermittedAction;
47
+ exports.clearTestPermittedActions = clearTestPermittedActions;
48
+ exports.getTestAuthorizationMiddleware = getTestAuthorizationMiddleware;
@@ -0,0 +1,27 @@
1
+ import { Resource } from './general';
2
+ export interface ResourceAttributeAssignment {
3
+ resourceType: Resource['type'];
4
+ resourceId: Resource['id'];
5
+ key: string;
6
+ value: string;
7
+ }
8
+ export interface ResourceAttributeResponse {
9
+ attributes: ResourceAttributeAssignment[];
10
+ }
11
+ export interface ResourceAttributeDelete {
12
+ resourceType: Resource['type'];
13
+ resourceId: Resource['id'];
14
+ key: string;
15
+ }
16
+ export declare enum ResourceAttributeOperationEnum {
17
+ UPSERT = "upsert",
18
+ DELETE = "delete"
19
+ }
20
+ interface UpsertResourceAttributeOperation extends ResourceAttributeAssignment {
21
+ operationType: ResourceAttributeOperationEnum.UPSERT;
22
+ }
23
+ interface DeleteResourceAttributeOperation extends ResourceAttributeDelete {
24
+ operationType: ResourceAttributeOperationEnum.DELETE;
25
+ }
26
+ export type ResourceAttributesOperation = UpsertResourceAttributeOperation | DeleteResourceAttributeOperation;
27
+ export {};
@@ -0,0 +1,7 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+
3
+ exports.ResourceAttributeOperationEnum = void 0;
4
+ (function (ResourceAttributeOperationEnum) {
5
+ ResourceAttributeOperationEnum["UPSERT"] = "upsert";
6
+ ResourceAttributeOperationEnum["DELETE"] = "delete";
7
+ })(exports.ResourceAttributeOperationEnum || (exports.ResourceAttributeOperationEnum = {}));
@@ -0,0 +1,10 @@
1
+ declare namespace Express {
2
+ interface Request {
3
+ payload: {
4
+ accountId: number;
5
+ userId: number;
6
+ };
7
+ authorizationCheckPerformed: boolean;
8
+ authorizationSkipPerformed: boolean;
9
+ }
10
+ }
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,32 @@
1
+ import type { Request, Response } from 'express';
2
+ export interface Resource {
3
+ id?: number;
4
+ type: string;
5
+ wrapperData?: object;
6
+ }
7
+ export type Action = string;
8
+ export interface Context {
9
+ accountId: number;
10
+ userId: number;
11
+ }
12
+ export interface AuthorizationObject {
13
+ resource_id?: Resource['id'];
14
+ resource_type: Resource['type'];
15
+ wrapper_data?: Resource['wrapperData'];
16
+ action: Action;
17
+ }
18
+ export interface AuthorizationParams {
19
+ authorizationObjects: AuthorizationObject[];
20
+ }
21
+ type BasicObject = {
22
+ [key: string]: string;
23
+ };
24
+ export type BaseParameters = BasicObject;
25
+ export type BaseResponseBody = BasicObject;
26
+ export type BaseBodyParameters = BasicObject;
27
+ export type BaseQueryParameters = BasicObject;
28
+ export type BaseRequest = Request<BaseParameters, BaseResponseBody, BaseBodyParameters, BaseQueryParameters>;
29
+ export type BaseResponse = Response<BaseResponseBody>;
30
+ export type ResourceGetter = (request: BaseRequest) => Resource[];
31
+ export type ContextGetter = (request: BaseRequest) => Context;
32
+ export {};
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,38 @@
1
+ export interface WorkspaceScope {
2
+ workspaceId: number;
3
+ }
4
+ export interface BoardScope {
5
+ boardId: number;
6
+ }
7
+ export interface PulseScope {
8
+ pulseId: number;
9
+ }
10
+ export interface AccountProductScope {
11
+ accountProductId: number;
12
+ }
13
+ export interface AccountScope {
14
+ accountId: number;
15
+ }
16
+ export type ScopeOptions = WorkspaceScope | BoardScope | PulseScope | AccountProductScope | AccountScope;
17
+ export interface Translation {
18
+ key: string;
19
+ [option: string]: string;
20
+ }
21
+ export declare enum PermitTechnicalReason {
22
+ NO_REASON = 0,
23
+ NOT_ELIGIBLE = 1,
24
+ BY_ROLE_IN_SCOPE = 2
25
+ }
26
+ export interface ScopedActionPermit {
27
+ can: boolean;
28
+ reason: Translation;
29
+ technicalReason: PermitTechnicalReason;
30
+ }
31
+ export interface ScopedAction {
32
+ action: string;
33
+ scope: ScopeOptions;
34
+ }
35
+ export interface ScopedActionResponseObject {
36
+ scopedAction: ScopedAction;
37
+ permit: ScopedActionPermit;
38
+ }
@@ -1,10 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+
3
3
  exports.PermitTechnicalReason = void 0;
4
- var PermitTechnicalReason;
5
4
  (function (PermitTechnicalReason) {
6
5
  PermitTechnicalReason[PermitTechnicalReason["NO_REASON"] = 0] = "NO_REASON";
7
6
  PermitTechnicalReason[PermitTechnicalReason["NOT_ELIGIBLE"] = 1] = "NOT_ELIGIBLE";
8
7
  PermitTechnicalReason[PermitTechnicalReason["BY_ROLE_IN_SCOPE"] = 2] = "BY_ROLE_IN_SCOPE";
9
- })(PermitTechnicalReason || (exports.PermitTechnicalReason = PermitTechnicalReason = {}));
10
- //# sourceMappingURL=scoped-actions-contracts.js.map
8
+ })(exports.PermitTechnicalReason || (exports.PermitTechnicalReason = {}));
package/package.json CHANGED
@@ -1,60 +1,57 @@
1
1
  {
2
2
  "name": "@mondaydotcomorg/monday-authorization",
3
- "version": "1.2.11",
3
+ "version": "1.2.12",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "license": "BSD-3-Clause",
7
- "jest": {
8
- "testEnvironment": "node",
9
- "testMatch": [
10
- "**/+(*.)+(spec|test).+(ts|js)?(x)"
11
- ],
12
- "transform": {
13
- "^.+\\.(ts|js|html)$": "ts-jest"
7
+ "exports": {
8
+ ".": {
9
+ "import": "./dist/esm/index.mjs",
10
+ "require": "./dist/index.js",
11
+ "types": "./dist/index.d.ts"
14
12
  },
15
- "moduleFileExtensions": [
16
- "ts",
17
- "js",
18
- "html"
19
- ],
20
- "coverageReporters": [
21
- "html"
22
- ]
13
+ "./package.json": "./package.json"
23
14
  },
24
15
  "scripts": {
25
- "test": "jest",
26
- "build": "tsc --build"
16
+ "test": "trident-library test",
17
+ "lint": "trident-library lint",
18
+ "build": "trident-library build",
19
+ "watch": "trident-library build -w"
27
20
  },
28
21
  "dependencies": {
29
22
  "@mondaydotcomorg/monday-fetch": "^0.0.7",
30
23
  "@mondaydotcomorg/monday-jwt": "^3.0.14",
31
24
  "@mondaydotcomorg/monday-logger": "^4.0.11",
32
25
  "@mondaydotcomorg/monday-sns": "^1.0.6",
33
- "@mondaydotcomorg/trident-backend-api": "^0.23.10",
34
- "@types/lodash": "^4.17.10",
26
+ "@mondaydotcomorg/trident-backend-api": "^0.24.3",
35
27
  "lodash": "^4.17.21",
36
28
  "node-fetch": "^2.6.7",
37
29
  "on-headers": "^1.0.2",
38
30
  "ts-node": "^10.0.0"
39
31
  },
40
32
  "devDependencies": {
33
+ "@mondaydotcomorg/trident-library": "^0.6.53",
41
34
  "@types/express": "^4.17.20",
42
- "@types/jest": "^27.4.1",
43
- "@types/mocha": "^8.2.2",
35
+ "@types/lodash": "^4.17.10",
44
36
  "@types/on-headers": "^1.0.0",
45
37
  "@types/supertest": "^2.0.11",
46
38
  "express": "^4.17.1",
47
39
  "ioredis": "^5.2.4",
48
40
  "ioredis-mock": "^8.2.2",
49
- "jest": "^27.5.1",
50
- "mocha": "^9.0.1",
51
41
  "supertest": "^6.1.3",
52
- "ts-jest": "^27.1.3",
53
- "tsconfig-paths": "^3.9.0",
54
- "typescript": "^5.1.6"
42
+ "typescript": "^5.2.2"
55
43
  },
56
44
  "files": [
57
45
  "dist/"
58
46
  ],
59
- "gitHead": "4db8fcacd3fe976b0e3fbc8e76d556f20f757d41"
47
+ "eslintConfig": {
48
+ "extends": "@mondaydotcomorg/trident-library",
49
+ "root": true
50
+ },
51
+ "trident": {
52
+ "build": {
53
+ "esmMjsRename": true
54
+ }
55
+ },
56
+ "gitHead": "6f9d0cc11ed13226cff1358f3782e314bb7d1248"
60
57
  }
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAWA,oBAWC;AArBD,iEAAyD;AACzD,uEAAqF;AACrF,uDAAyC;AA6BhC,0BAAO;AArBhB,SAAgB,IAAI,CAAC,UAAuB,EAAE;IAC5C,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;QACvB,IAAA,kCAAa,EAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IACp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awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.AuthorizationAttributesService = void 0;
16
- const chunk_1 = __importDefault(require("lodash/chunk"));
17
- const monday_fetch_1 = require("@mondaydotcomorg/monday-fetch");
18
- const authorization_internal_service_1 = require("./authorization-internal-service");
19
- const attributions_service_1 = require("./attributions-service");
20
- const trident_backend_api_1 = require("@mondaydotcomorg/trident-backend-api");
21
- const monday_sns_1 = require("@mondaydotcomorg/monday-sns");
22
- const sns_1 = require("./constants/sns");
23
- class AuthorizationAttributesService {
24
- /**
25
- * Upsert resource attributes synchronously, performing http call to the authorization MS to assign the given attributes to the given resource.
26
- * @param accountId
27
- * @param userId
28
- * @param resourceAttributeAssignments - Array of resource (resourceType, resourceId) and attribute (key, value) pairs to upsert in the authorization MS.
29
- * e.g. [{ resourceType: 'board', resourceId: 123, key: 'board_kind', value: 'private' }]
30
- * @returns ResourceAttributeResponse - The affected (created and updated_ resource attributes assignments in the `attributes` field.
31
- */
32
- static upsertResourceAttributes(accountId, userId, resourceAttributeAssignments) {
33
- return __awaiter(this, void 0, void 0, function* () {
34
- const internalAuthToken = authorization_internal_service_1.AuthorizationInternalService.generateInternalAuthToken(accountId, userId);
35
- const attributionHeaders = (0, attributions_service_1.getAttributionsFromApi)();
36
- const response = yield (0, monday_fetch_1.fetch)(this.getResourceAttributesUrl(accountId), {
37
- method: 'POST',
38
- headers: Object.assign({ Authorization: internalAuthToken, 'Content-Type': 'application/json' }, attributionHeaders),
39
- timeout: authorization_internal_service_1.AuthorizationInternalService.getRequestTimeout(),
40
- body: JSON.stringify({ resourceAttributeAssignments }),
41
- }, authorization_internal_service_1.AuthorizationInternalService.getRequestFetchOptions());
42
- const responseBody = yield response.json();
43
- authorization_internal_service_1.AuthorizationInternalService.throwOnHttpErrorIfNeeded(response, 'upsertResourceAttributesSync');
44
- return { attributes: responseBody['attributes'] };
45
- });
46
- }
47
- /**
48
- * Delete resource attributes assignments synchronously, performing http call to the authorization MS to delete the given attributes from the given singular resource.
49
- * @param accountId
50
- * @param userId
51
- * @param resource - The resource (resourceType, resourceId) to delete the attributes for.
52
- * @param attributeKeys - Array of attribute keys to delete for the resource.
53
- * @returns ResourceAttributeResponse - The affected (deleted) resource attributes assignments in the `attributes` field.
54
- */
55
- static deleteResourceAttributes(accountId, userId, resource, attributeKeys) {
56
- return __awaiter(this, void 0, void 0, function* () {
57
- const internalAuthToken = authorization_internal_service_1.AuthorizationInternalService.generateInternalAuthToken(accountId, userId);
58
- const url = `${this.getResourceAttributesUrl(accountId)}/${resource.type}/${resource.id}`;
59
- const attributionHeaders = (0, attributions_service_1.getAttributionsFromApi)();
60
- const response = yield (0, monday_fetch_1.fetch)(url, {
61
- method: 'DELETE',
62
- headers: Object.assign({ Authorization: internalAuthToken, 'Content-Type': 'application/json' }, attributionHeaders),
63
- timeout: authorization_internal_service_1.AuthorizationInternalService.getRequestTimeout(),
64
- body: JSON.stringify({ keys: attributeKeys }),
65
- }, authorization_internal_service_1.AuthorizationInternalService.getRequestFetchOptions());
66
- const responseBody = yield response.json();
67
- authorization_internal_service_1.AuthorizationInternalService.throwOnHttpErrorIfNeeded(response, 'deleteResourceAttributesSync');
68
- return { attributes: responseBody['attributes'] };
69
- });
70
- }
71
- /**
72
- * Async function, this function only send the updates request to SNS and return before the change actually took place
73
- * @param accountId
74
- * @param appName - App name of the calling app
75
- * @param callerActionIdentifier - action identifier
76
- * @param resourceAttributeOperations - Array of operations to do on resource attributes.
77
- * @return {Promise<ResourceAttributesOperation[]>} Array of sent operations
78
- * */
79
- static updateResourceAttributesAsync(accountId, appName, callerActionIdentifier, resourceAttributeOperations) {
80
- return __awaiter(this, void 0, void 0, function* () {
81
- const topicArn = this.getSnsTopicArn();
82
- const sendToSnsPromises = [];
83
- const operationChucks = (0, chunk_1.default)(resourceAttributeOperations, sns_1.ASYNC_RESOURCE_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE);
84
- for (const operationsChunk of operationChucks) {
85
- sendToSnsPromises.push(this.sendSingleSnsMessage(topicArn, accountId, appName, callerActionIdentifier, operationsChunk));
86
- }
87
- return (yield Promise.all(sendToSnsPromises)).flat();
88
- });
89
- }
90
- static sendSingleSnsMessage(topicArn, accountId, appName, callerActionIdentifier, operations) {
91
- return __awaiter(this, void 0, void 0, function* () {
92
- const payload = {
93
- kind: sns_1.RESOURCE_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND,
94
- payload: {
95
- accountId: accountId,
96
- callerAppName: appName,
97
- callerActionIdentifier: callerActionIdentifier,
98
- operations: operations,
99
- }
100
- };
101
- try {
102
- yield (0, monday_sns_1.sendToSns)(payload, topicArn);
103
- return operations;
104
- }
105
- catch (error) {
106
- authorization_internal_service_1.logger.error({ error, tag: this.LOG_TAG }, "Authorization resource attributes async update: failed to send operations to SNS");
107
- return [];
108
- }
109
- });
110
- }
111
- static getSnsTopicArn() {
112
- var _a;
113
- const arnFromApi = (_a = trident_backend_api_1.Api.getPart('configurationVariables')) === null || _a === void 0 ? void 0 : _a.get(sns_1.RESOURCE_ATTRIBUTES_SNS_ARN_SECRET_NAME).arn;
114
- if (arnFromApi) {
115
- return arnFromApi;
116
- }
117
- const jsonArnFromEnv = process.env[sns_1.RESOURCE_ATTRIBUTES_SNS_ARN_SECRET_NAME];
118
- const arnFromEnv = JSON.parse(jsonArnFromEnv).arn;
119
- if (arnFromEnv) {
120
- return arnFromEnv;
121
- }
122
- throw new Error('Unable to get sns topic arn from env variable');
123
- }
124
- static getResourceAttributesUrl(accountId) {
125
- return `${process.env.AUTHORIZATION_URL}/attributes/${accountId}/resource`;
126
- }
127
- /**
128
- * Checks we can contact the required SNS topic that used to send attribute updates to Authorization MS.
129
- * This function can be used as health check for services that updating resource attributes in async is crucial.
130
- * Note this function only verify the POD can contact AWS SDK and the topic exists, but the user still might get
131
- * errors when pushing for the SNS (e.g: in case the AWS role of the POD don't have permissions to push messages).
132
- * However, this is the best we can do without actually push dummy messages to the SNS.
133
- * @return {Promise<boolean>} - true if succeeded
134
- */
135
- static asyncResourceAttributesHealthCheck() {
136
- return __awaiter(this, void 0, void 0, function* () {
137
- try {
138
- const requestedTopicArn = this.getSnsTopicArn();
139
- const attributes = yield (0, monday_sns_1.getTopicAttributes)(requestedTopicArn);
140
- const isHealthy = !(!attributes || !("TopicArn" in attributes) || attributes.TopicArn !== requestedTopicArn);
141
- if (!isHealthy) {
142
- authorization_internal_service_1.logger.error({ requestedTopicArn, snsReturnedAttributes: attributes, tag: this.LOG_TAG }, "authorization-attributes-service failed in health check");
143
- }
144
- return isHealthy;
145
- }
146
- catch (error) {
147
- authorization_internal_service_1.logger.error({ error, tag: this.LOG_TAG }, "authorization-attributes-service got error during health check");
148
- return false;
149
- }
150
- });
151
- }
152
- }
153
- exports.AuthorizationAttributesService = AuthorizationAttributesService;
154
- AuthorizationAttributesService.LOG_TAG = "authorization_attributes";
155
- //# sourceMappingURL=authorization-attributes-service.js.map