@mondaydotcomorg/monday-authorization 1.0.53-featureyardenauthorization-sdk-can-action-in-scope-support.33 → 1.0.53-featureyardencan-action-in-scope-authorization-sdk.735
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,20 +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
|
-
|
|
97
|
-
return subjectsResponse[0].permit.isAllowed;
|
|
107
|
+
const scopedActions = [{ action, scope }];
|
|
108
|
+
const scopedActionResponseObjects = yield this.canActionInScopeMultiple(accountId, userId, scopedActions);
|
|
109
|
+
return scopedActionResponseObjects[0].permit.can;
|
|
98
110
|
});
|
|
99
111
|
}
|
|
100
|
-
|
|
101
|
-
static canActionInScopeMultiple(accountId, userId, subjects) {
|
|
112
|
+
static canActionInScopeMultiple(accountId, userId, scopedActions) {
|
|
102
113
|
return __awaiter(this, void 0, void 0, function* () {
|
|
103
114
|
const internalAuthToken = monday_jwt_1.signAuthorizationHeader({ appName: INTERNAL_APP_NAME, accountId, userId });
|
|
104
|
-
const
|
|
105
|
-
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 }
|
|
106
117
|
});
|
|
107
118
|
const response = yield monday_fetch_1.fetch(getCanActionsInScopesUrl(), {
|
|
108
119
|
method: 'POST',
|
|
@@ -110,30 +121,17 @@ class AuthorizationService {
|
|
|
110
121
|
timeout: getRequestTimeout(),
|
|
111
122
|
body: JSON.stringify({
|
|
112
123
|
user_id: userId,
|
|
113
|
-
|
|
124
|
+
scoped_actions: scopedActionsPayload,
|
|
114
125
|
}),
|
|
115
126
|
}, mondayFetchOptions);
|
|
116
127
|
if (!response.ok) {
|
|
117
128
|
logger.error({ status: response.status }, 'AuthorizationService: authorization request failed - canActionInScopeMultiple');
|
|
118
|
-
return
|
|
129
|
+
return scopedActions.map((scopedAction) => ({ scopedAction, permit: { can: false, reason: { key: 'internal error' } } }));
|
|
119
130
|
}
|
|
120
131
|
const responseBody = yield response.json();
|
|
121
132
|
return responseBody.result;
|
|
122
133
|
});
|
|
123
134
|
}
|
|
124
|
-
static fetchIsUserGrantedWithFeature(featureName, accountId, userId) {
|
|
125
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
126
|
-
let authorizationObject = {
|
|
127
|
-
action: featureName,
|
|
128
|
-
resource_type: 'feature',
|
|
129
|
-
};
|
|
130
|
-
let authorizeResponsePromise = yield this.isAuthorized(accountId, userId, [authorizationObject]);
|
|
131
|
-
return authorizeResponsePromise.isAuthorized;
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
static getCachedKeyName(userId, featureName) {
|
|
135
|
-
return `granted-feature-${featureName}-${userId}`;
|
|
136
|
-
}
|
|
137
135
|
static isAuthorizedSingular(accountId, userId, resources, action) {
|
|
138
136
|
return __awaiter(this, void 0, void 0, function* () {
|
|
139
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-featureyardencan-action-in-scope-authorization-sdk.735+978a4b6b6",
|
|
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": "978a4b6b68a8d6d3d6b3229978c88537d10feb45"
|
|
36
36
|
}
|