@mondaydotcomorg/monday-authorization 1.0.10 → 1.0.11

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.
@@ -22,7 +22,7 @@ function getAuthorizationMiddleware(action, resourceGetter, contextGetter) {
22
22
  contextGetter || (contextGetter = defaultContextGetter);
23
23
  const { userId, accountId } = contextGetter(request);
24
24
  const resources = resourceGetter(request);
25
- const isAuthorized = yield authorization_service_1.AuthorizationService.isAuthorized(accountId, userId, resources, action);
25
+ const { isAuthorized } = yield authorization_service_1.AuthorizationService.isAuthorized(accountId, userId, resources, action);
26
26
  authorization_internal_service_1.AuthorizationInternalService.markAuthorized(request);
27
27
  if (!isAuthorized) {
28
28
  response.status(403).json({ message: 'Access denied' });
@@ -1,4 +1,8 @@
1
1
  import { Action, Resource } from './types/general';
2
+ export interface AuthorizeResponse {
3
+ isAuthorized: boolean;
4
+ unauthorizedIds?: number[];
5
+ }
2
6
  export declare class AuthorizationService {
3
- static isAuthorized(accountId: number, userId: number, resources: Resource[], action: Action): Promise<boolean>;
7
+ static isAuthorized(accountId: number, userId: number, resources: Resource[], action: Action): Promise<AuthorizeResponse>;
4
8
  }
@@ -56,7 +56,7 @@ class AuthorizationService {
56
56
  }, { retries: 3, callback: logOnFetchFail });
57
57
  if (!response.ok) {
58
58
  logger.error({ status: response.status }, 'Authorization middleware: authorization request failed');
59
- return false;
59
+ return { isAuthorized: false };
60
60
  }
61
61
  const responseBody = yield response.json();
62
62
  const unauthorizedObjects = [];
@@ -69,9 +69,10 @@ class AuthorizationService {
69
69
  logger.info({
70
70
  resources: JSON.stringify(unauthorizedObjects),
71
71
  }, 'Authorization middleware: resource is unauthorized');
72
- return false;
72
+ const unauthorizedIds = unauthorizedObjects.map(obj => obj.resource_id);
73
+ return { isAuthorized: false, unauthorizedIds };
73
74
  }
74
- return true;
75
+ return { isAuthorized: true };
75
76
  });
76
77
  }
77
78
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mondaydotcomorg/monday-authorization",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "license": "BSD-3-Clause",
@@ -31,5 +31,5 @@
31
31
  "files": [
32
32
  "dist/"
33
33
  ],
34
- "gitHead": "27da993cbc76e1787a3a006ee5f78df9a1192ff9"
34
+ "gitHead": "5045f4bb75bdad8f142bf3d3bd65fa7a955bf39f"
35
35
  }