@mondaydotcomorg/monday-authorization 1.1.9-featuremosheauthorizationesm.3696 → 1.1.9-featureorcomonday-jwt-ts.472

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 (61) hide show
  1. package/CHANGELOG.md +0 -15
  2. package/README.md +0 -57
  3. package/dist/index.d.ts +2 -5
  4. package/dist/index.js +14 -18
  5. package/dist/lib/authorization-internal-service.d.ts +6 -0
  6. package/dist/lib/authorization-internal-service.js +17 -0
  7. package/dist/{authorization-middleware.d.ts → lib/authorization-middleware.d.ts} +2 -3
  8. package/dist/lib/authorization-middleware.js +54 -0
  9. package/dist/{authorization-service.d.ts → lib/authorization-service.d.ts} +2 -3
  10. package/dist/lib/authorization-service.js +233 -0
  11. package/dist/{prometheus-service.js → lib/prometheus-service.js} +12 -17
  12. package/dist/lib/types/express.js +1 -0
  13. package/dist/{types → lib/types}/general.d.ts +4 -6
  14. package/dist/lib/types/general.js +2 -0
  15. package/dist/{types → lib/types}/scoped-actions-contracts.js +4 -3
  16. package/package.json +11 -32
  17. package/dist/attributions-service.d.ts +0 -3
  18. package/dist/attributions-service.js +0 -55
  19. package/dist/authorization-attributes-service.d.ts +0 -44
  20. package/dist/authorization-attributes-service.js +0 -144
  21. package/dist/authorization-internal-service.d.ts +0 -13
  22. package/dist/authorization-internal-service.js +0 -80
  23. package/dist/authorization-middleware.js +0 -48
  24. package/dist/authorization-service.js +0 -176
  25. package/dist/constants/sns.d.ts +0 -3
  26. package/dist/constants/sns.js +0 -9
  27. package/dist/esm/attributions-service.d.ts +0 -3
  28. package/dist/esm/attributions-service.mjs +0 -53
  29. package/dist/esm/authorization-attributes-service.d.ts +0 -44
  30. package/dist/esm/authorization-attributes-service.mjs +0 -138
  31. package/dist/esm/authorization-internal-service.d.ts +0 -13
  32. package/dist/esm/authorization-internal-service.mjs +0 -57
  33. package/dist/esm/authorization-middleware.d.ts +0 -6
  34. package/dist/esm/authorization-middleware.mjs +0 -39
  35. package/dist/esm/authorization-service.d.ts +0 -29
  36. package/dist/esm/authorization-service.mjs +0 -172
  37. package/dist/esm/constants/sns.d.ts +0 -3
  38. package/dist/esm/constants/sns.mjs +0 -5
  39. package/dist/esm/index.d.ts +0 -13
  40. package/dist/esm/index.mjs +0 -21
  41. package/dist/esm/prometheus-service.mjs +0 -49
  42. package/dist/esm/testKit/index.d.ts +0 -11
  43. package/dist/esm/testKit/index.mjs +0 -44
  44. package/dist/esm/types/authorization-attributes-contracts.d.ts +0 -27
  45. package/dist/esm/types/authorization-attributes-contracts.mjs +0 -7
  46. package/dist/esm/types/express.mjs +0 -1
  47. package/dist/esm/types/general.d.ts +0 -32
  48. package/dist/esm/types/general.mjs +0 -1
  49. package/dist/esm/types/scoped-actions-contracts.mjs +0 -8
  50. package/dist/prometheus-service.d.ts +0 -10
  51. package/dist/testKit/index.d.ts +0 -11
  52. package/dist/testKit/index.js +0 -48
  53. package/dist/types/authorization-attributes-contracts.d.ts +0 -27
  54. package/dist/types/authorization-attributes-contracts.js +0 -7
  55. package/dist/types/express.d.ts +0 -10
  56. package/dist/types/express.js +0 -1
  57. package/dist/types/general.js +0 -1
  58. package/dist/types/scoped-actions-contracts.d.ts +0 -38
  59. /package/dist/{esm → lib}/prometheus-service.d.ts +0 -0
  60. /package/dist/{esm → lib}/types/express.d.ts +0 -0
  61. /package/dist/{esm → lib}/types/scoped-actions-contracts.d.ts +0 -0
@@ -1,11 +0,0 @@
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>;
@@ -1,44 +0,0 @@
1
- import { defaultContextGetter } from '../authorization-middleware.mjs';
2
- import { AuthorizationInternalService } from '../authorization-internal-service.mjs';
3
-
4
- let testPermittedActions = [];
5
- const addTestPermittedAction = (accountId, userId, resources, action) => {
6
- testPermittedActions.push({ accountId, userId, resources, action });
7
- };
8
- const clearTestPermittedActions = () => {
9
- testPermittedActions = [];
10
- };
11
- const isActionAuthorized = (accountId, userId, resources, action) => {
12
- return {
13
- isAuthorized: resources.every(_ => {
14
- return testPermittedActions.some(combination => {
15
- return (combination.accountId === accountId &&
16
- combination.userId === userId &&
17
- combination.action === action &&
18
- combination.resources.some(combinationResource => {
19
- return resources.some(resource => {
20
- return (combinationResource.id === resource.id &&
21
- combinationResource.type === resource.type &&
22
- JSON.stringify(combinationResource.wrapperData) === JSON.stringify(resource.wrapperData));
23
- });
24
- }));
25
- });
26
- }),
27
- };
28
- };
29
- const getTestAuthorizationMiddleware = (action, resourceGetter, contextGetter) => {
30
- return async function authorizationMiddleware(request, response, next) {
31
- contextGetter ||= defaultContextGetter;
32
- const { userId, accountId } = contextGetter(request);
33
- const resources = resourceGetter(request);
34
- const { isAuthorized } = isActionAuthorized(accountId, userId, resources, action);
35
- AuthorizationInternalService.markAuthorized(request);
36
- if (!isAuthorized) {
37
- response.status(403).json({ message: 'Access denied' });
38
- return;
39
- }
40
- next();
41
- };
42
- };
43
-
44
- export { addTestPermittedAction, clearTestPermittedActions, getTestAuthorizationMiddleware };
@@ -1,27 +0,0 @@
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 {};
@@ -1,7 +0,0 @@
1
- var ResourceAttributeOperationEnum;
2
- (function (ResourceAttributeOperationEnum) {
3
- ResourceAttributeOperationEnum["UPSERT"] = "upsert";
4
- ResourceAttributeOperationEnum["DELETE"] = "delete";
5
- })(ResourceAttributeOperationEnum || (ResourceAttributeOperationEnum = {}));
6
-
7
- export { ResourceAttributeOperationEnum };
@@ -1 +0,0 @@
1
-
@@ -1,32 +0,0 @@
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 {};
@@ -1 +0,0 @@
1
-
@@ -1,8 +0,0 @@
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 };
@@ -1,10 +0,0 @@
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,11 +0,0 @@
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>;
@@ -1,48 +0,0 @@
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;
@@ -1,27 +0,0 @@
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 {};
@@ -1,7 +0,0 @@
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 = {}));
@@ -1,10 +0,0 @@
1
- declare namespace Express {
2
- interface Request {
3
- payload: {
4
- accountId: number;
5
- userId: number;
6
- };
7
- authorizationCheckPerformed: boolean;
8
- authorizationSkipPerformed: boolean;
9
- }
10
- }
@@ -1 +0,0 @@
1
-
@@ -1 +0,0 @@
1
-
@@ -1,38 +0,0 @@
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
- }
File without changes
File without changes