@mondaydotcomorg/monday-authorization 1.0.53-featureyardenauthorization-sdk-can-action-in-scope-support.34 → 1.0.53
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.
|
@@ -1,30 +1,10 @@
|
|
|
1
1
|
import { MondayFetchOptions } from '@mondaydotcomorg/monday-fetch';
|
|
2
2
|
import { Action, AuthorizationObject, Resource } from './types/general';
|
|
3
|
+
import { ScopedAction, ScopedActionResponseObject, ScopeOptions } from 'lib/types/scoped-actions-contracts';
|
|
3
4
|
export interface AuthorizeResponse {
|
|
4
5
|
isAuthorized: boolean;
|
|
5
6
|
unauthorizedIds?: number[];
|
|
6
7
|
}
|
|
7
|
-
export interface ScopeOptions {
|
|
8
|
-
workspaceId?: number;
|
|
9
|
-
accountProductId?: number;
|
|
10
|
-
boardId?: number;
|
|
11
|
-
pulseId?: number;
|
|
12
|
-
}
|
|
13
|
-
export interface Translation {
|
|
14
|
-
key: string;
|
|
15
|
-
[option: string]: string;
|
|
16
|
-
}
|
|
17
|
-
export interface SubjectRequestObject {
|
|
18
|
-
action: string;
|
|
19
|
-
scope: ScopeOptions;
|
|
20
|
-
}
|
|
21
|
-
export interface SubjectResponseObject {
|
|
22
|
-
subject: SubjectRequestObject;
|
|
23
|
-
permit: {
|
|
24
|
-
isAllowed: boolean;
|
|
25
|
-
reason: Translation;
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
8
|
export declare function setRequestFetchOptions(customMondayFetchOptions: MondayFetchOptions): void;
|
|
29
9
|
export declare function setRedisClient(client: any, grantedFeatureRedisExpirationInSeconds?: number): void;
|
|
30
10
|
export declare class AuthorizationService {
|
|
@@ -37,10 +17,10 @@ export declare class AuthorizationService {
|
|
|
37
17
|
static isAuthorized(accountId: number, userId: number, resources: Resource[], action: Action): Promise<AuthorizeResponse>;
|
|
38
18
|
static isAuthorized(accountId: number, userId: number, authorizationRequestObjects: AuthorizationObject[]): Promise<AuthorizeResponse>;
|
|
39
19
|
static isUserGrantedWithFeature(accountId: number, userId: number, featureName: string): Promise<boolean>;
|
|
40
|
-
static canActionInScope(accountId: number, userId: number, action: string, scope: ScopeOptions): Promise<boolean>;
|
|
41
|
-
static canActionInScopeMultiple(accountId: number, userId: number, subjects: SubjectRequestObject[]): Promise<SubjectResponseObject[]>;
|
|
42
20
|
private static fetchIsUserGrantedWithFeature;
|
|
43
21
|
private static getCachedKeyName;
|
|
22
|
+
static canActionInScope(accountId: number, userId: number, action: string, scope: ScopeOptions): Promise<boolean>;
|
|
23
|
+
static canActionInScopeMultiple(accountId: number, userId: number, scopedActions: ScopedAction[]): Promise<ScopedActionResponseObject[]>;
|
|
44
24
|
private static isAuthorizedSingular;
|
|
45
25
|
private static isAuthorizedMultiple;
|
|
46
26
|
}
|
|
@@ -29,8 +29,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
29
29
|
};
|
|
30
30
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
31
|
exports.AuthorizationService = exports.setRedisClient = exports.setRequestFetchOptions = void 0;
|
|
32
|
-
const perf_hooks_1 = require("perf_hooks");
|
|
33
32
|
const lodash_1 = require("lodash");
|
|
33
|
+
const perf_hooks_1 = require("perf_hooks");
|
|
34
34
|
const monday_jwt_1 = require("@mondaydotcomorg/monday-jwt");
|
|
35
35
|
const MondayLogger = __importStar(require("@mondaydotcomorg/monday-logger"));
|
|
36
36
|
const monday_fetch_1 = require("@mondaydotcomorg/monday-fetch");
|
|
@@ -89,19 +89,31 @@ class AuthorizationService {
|
|
|
89
89
|
return grantedFeatureValue;
|
|
90
90
|
});
|
|
91
91
|
}
|
|
92
|
+
static fetchIsUserGrantedWithFeature(featureName, accountId, userId) {
|
|
93
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
let authorizationObject = {
|
|
95
|
+
action: featureName,
|
|
96
|
+
resource_type: 'feature',
|
|
97
|
+
};
|
|
98
|
+
let authorizeResponsePromise = yield this.isAuthorized(accountId, userId, [authorizationObject]);
|
|
99
|
+
return authorizeResponsePromise.isAuthorized;
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
static getCachedKeyName(userId, featureName) {
|
|
103
|
+
return `granted-feature-${featureName}-${userId}`;
|
|
104
|
+
}
|
|
92
105
|
static canActionInScope(accountId, userId, action, scope) {
|
|
93
106
|
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
-
const
|
|
95
|
-
const
|
|
96
|
-
return
|
|
107
|
+
const scopedActions = [{ action, scope }];
|
|
108
|
+
const scopedActionResponseObjects = yield this.canActionInScopeMultiple(accountId, userId, scopedActions);
|
|
109
|
+
return scopedActionResponseObjects[0].permit.can;
|
|
97
110
|
});
|
|
98
111
|
}
|
|
99
|
-
|
|
100
|
-
static canActionInScopeMultiple(accountId, userId, subjects) {
|
|
112
|
+
static canActionInScopeMultiple(accountId, userId, scopedActions) {
|
|
101
113
|
return __awaiter(this, void 0, void 0, function* () {
|
|
102
114
|
const internalAuthToken = monday_jwt_1.signAuthorizationHeader({ appName: INTERNAL_APP_NAME, accountId, userId });
|
|
103
|
-
const
|
|
104
|
-
return Object.assign(Object.assign({},
|
|
115
|
+
const scopedActionsPayload = scopedActions.map((scopedAction) => {
|
|
116
|
+
return Object.assign(Object.assign({}, scopedAction), { scope: lodash_1.mapKeys(scopedAction.scope, (_, key) => lodash_1.snakeCase(key)) }); // for example: { workspaceId: 1 } => { workspace_id: 1 }
|
|
105
117
|
});
|
|
106
118
|
const response = yield monday_fetch_1.fetch(getCanActionsInScopesUrl(), {
|
|
107
119
|
method: 'POST',
|
|
@@ -109,30 +121,17 @@ class AuthorizationService {
|
|
|
109
121
|
timeout: getRequestTimeout(),
|
|
110
122
|
body: JSON.stringify({
|
|
111
123
|
user_id: userId,
|
|
112
|
-
|
|
124
|
+
scoped_actions: scopedActionsPayload,
|
|
113
125
|
}),
|
|
114
126
|
}, mondayFetchOptions);
|
|
115
127
|
if (!response.ok) {
|
|
116
128
|
logger.error({ status: response.status }, 'AuthorizationService: authorization request failed - canActionInScopeMultiple');
|
|
117
|
-
return
|
|
129
|
+
return scopedActions.map((scopedAction) => ({ scopedAction, permit: { can: false, reason: { key: 'internal error' } } }));
|
|
118
130
|
}
|
|
119
131
|
const responseBody = yield response.json();
|
|
120
132
|
return responseBody.result;
|
|
121
133
|
});
|
|
122
134
|
}
|
|
123
|
-
static fetchIsUserGrantedWithFeature(featureName, accountId, userId) {
|
|
124
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
125
|
-
let authorizationObject = {
|
|
126
|
-
action: featureName,
|
|
127
|
-
resource_type: 'feature',
|
|
128
|
-
};
|
|
129
|
-
let authorizeResponsePromise = yield this.isAuthorized(accountId, userId, [authorizationObject]);
|
|
130
|
-
return authorizeResponsePromise.isAuthorized;
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
static getCachedKeyName(userId, featureName) {
|
|
134
|
-
return `granted-feature-${featureName}-${userId}`;
|
|
135
|
-
}
|
|
136
135
|
static isAuthorizedSingular(accountId, userId, resources, action) {
|
|
137
136
|
return __awaiter(this, void 0, void 0, function* () {
|
|
138
137
|
const { authorizationObjects } = createAuthorizationParams(resources, action);
|
|
@@ -0,0 +1,32 @@
|
|
|
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 declare type ScopeOptions = WorkspaceScope | BoardScope | PulseScope | AccountProductScope | AccountScope;
|
|
17
|
+
export interface Translation {
|
|
18
|
+
key: string;
|
|
19
|
+
[option: string]: string;
|
|
20
|
+
}
|
|
21
|
+
export interface ScopedActionPermit {
|
|
22
|
+
can: boolean;
|
|
23
|
+
reason: Translation;
|
|
24
|
+
}
|
|
25
|
+
export interface ScopedAction {
|
|
26
|
+
action: string;
|
|
27
|
+
scope: ScopeOptions;
|
|
28
|
+
}
|
|
29
|
+
export interface ScopedActionResponseObject {
|
|
30
|
+
scopedAction: ScopedAction;
|
|
31
|
+
permit: ScopedActionPermit;
|
|
32
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mondaydotcomorg/monday-authorization",
|
|
3
|
-
"version": "1.0.53
|
|
3
|
+
"version": "1.0.53",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"license": "BSD-3-Clause",
|
|
@@ -32,5 +32,5 @@
|
|
|
32
32
|
"files": [
|
|
33
33
|
"dist/"
|
|
34
34
|
],
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "8df5fda8931cf804959647805c4ffe8bf550e9a4"
|
|
36
36
|
}
|