@mondaydotcomorg/monday-authorization 1.0.53-featuregallisupportprivatekeysigning.160 → 1.0.53-featureyardenauthorization-sdk-can-action-in-scope-support.33
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.
|
@@ -4,6 +4,27 @@ export interface AuthorizeResponse {
|
|
|
4
4
|
isAuthorized: boolean;
|
|
5
5
|
unauthorizedIds?: number[];
|
|
6
6
|
}
|
|
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
|
+
}
|
|
7
28
|
export declare function setRequestFetchOptions(customMondayFetchOptions: MondayFetchOptions): void;
|
|
8
29
|
export declare function setRedisClient(client: any, grantedFeatureRedisExpirationInSeconds?: number): void;
|
|
9
30
|
export declare class AuthorizationService {
|
|
@@ -16,6 +37,8 @@ export declare class AuthorizationService {
|
|
|
16
37
|
static isAuthorized(accountId: number, userId: number, resources: Resource[], action: Action): Promise<AuthorizeResponse>;
|
|
17
38
|
static isAuthorized(accountId: number, userId: number, authorizationRequestObjects: AuthorizationObject[]): Promise<AuthorizeResponse>;
|
|
18
39
|
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[]>;
|
|
19
42
|
private static fetchIsUserGrantedWithFeature;
|
|
20
43
|
private static getCachedKeyName;
|
|
21
44
|
private static isAuthorizedSingular;
|
|
@@ -30,6 +30,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
30
30
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
31
|
exports.AuthorizationService = exports.setRedisClient = exports.setRequestFetchOptions = void 0;
|
|
32
32
|
const perf_hooks_1 = require("perf_hooks");
|
|
33
|
+
const lodash_1 = require("lodash");
|
|
33
34
|
const monday_jwt_1 = require("@mondaydotcomorg/monday-jwt");
|
|
34
35
|
const MondayLogger = __importStar(require("@mondaydotcomorg/monday-logger"));
|
|
35
36
|
const monday_fetch_1 = require("@mondaydotcomorg/monday-fetch");
|
|
@@ -88,6 +89,38 @@ class AuthorizationService {
|
|
|
88
89
|
return grantedFeatureValue;
|
|
89
90
|
});
|
|
90
91
|
}
|
|
92
|
+
static canActionInScope(accountId, userId, action, scope) {
|
|
93
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
const subjects = [{ action, scope }];
|
|
95
|
+
const subjectsResponse = this.canActionInScopeMultiple(accountId, userId, subjects);
|
|
96
|
+
console.log(subjectsResponse);
|
|
97
|
+
return subjectsResponse[0].permit.isAllowed;
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
;
|
|
101
|
+
static canActionInScopeMultiple(accountId, userId, subjects) {
|
|
102
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
103
|
+
const internalAuthToken = monday_jwt_1.signAuthorizationHeader({ appName: INTERNAL_APP_NAME, accountId, userId });
|
|
104
|
+
const subjectsPayload = subjects.map((subject) => {
|
|
105
|
+
return Object.assign(Object.assign({}, subject), { scope: lodash_1.mapKeys(subject.scope, (_, key) => lodash_1.snakeCase(key)) }); // for example: { workspaceId: 1 } => { workspace_id: 1 }
|
|
106
|
+
});
|
|
107
|
+
const response = yield monday_fetch_1.fetch(getCanActionsInScopesUrl(), {
|
|
108
|
+
method: 'POST',
|
|
109
|
+
headers: { Authorization: internalAuthToken, 'Content-Type': 'application/json' },
|
|
110
|
+
timeout: getRequestTimeout(),
|
|
111
|
+
body: JSON.stringify({
|
|
112
|
+
user_id: userId,
|
|
113
|
+
subjects: subjectsPayload,
|
|
114
|
+
}),
|
|
115
|
+
}, mondayFetchOptions);
|
|
116
|
+
if (!response.ok) {
|
|
117
|
+
logger.error({ status: response.status }, 'AuthorizationService: authorization request failed - canActionInScopeMultiple');
|
|
118
|
+
return subjects.map((subject) => ({ subject, permit: { isAllowed: false, reason: { key: 'internal error' } } }));
|
|
119
|
+
}
|
|
120
|
+
const responseBody = yield response.json();
|
|
121
|
+
return responseBody.result;
|
|
122
|
+
});
|
|
123
|
+
}
|
|
91
124
|
static fetchIsUserGrantedWithFeature(featureName, accountId, userId) {
|
|
92
125
|
return __awaiter(this, void 0, void 0, function* () {
|
|
93
126
|
let authorizationObject = {
|
|
@@ -111,7 +144,7 @@ class AuthorizationService {
|
|
|
111
144
|
return __awaiter(this, void 0, void 0, function* () {
|
|
112
145
|
const internalAuthToken = monday_jwt_1.signAuthorizationHeader({ appName: INTERNAL_APP_NAME, accountId, userId });
|
|
113
146
|
const startTime = perf_hooks_1.performance.now();
|
|
114
|
-
const response = yield monday_fetch_1.fetch(
|
|
147
|
+
const response = yield monday_fetch_1.fetch(getAuthorizeUrl(), {
|
|
115
148
|
method: 'POST',
|
|
116
149
|
headers: { Authorization: internalAuthToken, 'Content-Type': 'application/json' },
|
|
117
150
|
timeout: getRequestTimeout(),
|
|
@@ -179,9 +212,12 @@ function logOnFetchFail(retriesLeft, error) {
|
|
|
179
212
|
logger.info({ retriesLeft, error }, 'Authorization attempt failed due to network issues, trying again');
|
|
180
213
|
}
|
|
181
214
|
}
|
|
182
|
-
function
|
|
215
|
+
function getAuthorizeUrl() {
|
|
183
216
|
return `${process.env.MONDAY_INTERNAL_URL}/internal_ms/authorization/authorize`;
|
|
184
217
|
}
|
|
218
|
+
function getCanActionsInScopesUrl() {
|
|
219
|
+
return `${process.env.MONDAY_INTERNAL_URL}/internal_ms/authorization/can_actions_in_scopes`;
|
|
220
|
+
}
|
|
185
221
|
function getRequestTimeout() {
|
|
186
222
|
const isDevEnv = process.env.NODE_ENV === 'development';
|
|
187
223
|
return isDevEnv ? 60000 : 2000;
|
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-featureyardenauthorization-sdk-can-action-in-scope-support.33+745f13086",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"license": "BSD-3-Clause",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@mondaydotcomorg/monday-fetch": "^0.0.7",
|
|
13
|
-
"@mondaydotcomorg/monday-jwt": "^3.0.
|
|
13
|
+
"@mondaydotcomorg/monday-jwt": "^3.0.5",
|
|
14
14
|
"@mondaydotcomorg/monday-logger": "^3.0.10",
|
|
15
15
|
"@types/express": "^4.17.12",
|
|
16
16
|
"node-fetch": "^2.6.7",
|
|
@@ -32,5 +32,5 @@
|
|
|
32
32
|
"files": [
|
|
33
33
|
"dist/"
|
|
34
34
|
],
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "745f130861b3f765819255e1a91fbaa3824fde05"
|
|
36
36
|
}
|