@mondaydotcomorg/monday-authorization 1.0.44-featureyoniadd-granted-feature-sdk-api.558 → 1.0.44-featureyoniadd-granted-feature-sdk-api.559
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.
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export interface InitOptions {
|
|
|
3
3
|
prometheus?: any;
|
|
4
4
|
mondayFetchOptions?: MondayFetchOptions;
|
|
5
5
|
redisClient?: any;
|
|
6
|
+
redisKeyExpirationInSeconds?: number;
|
|
6
7
|
}
|
|
7
8
|
export declare function init(options?: InitOptions): void;
|
|
8
9
|
export { authorizationCheckMiddleware, getAuthorizationMiddleware, skipAuthorizationMiddleware, } from './lib/authorization-middleware';
|
package/dist/index.js
CHANGED
|
@@ -11,7 +11,7 @@ function init(options = {}) {
|
|
|
11
11
|
authorization_service_1.setRequestFetchOptions(options.mondayFetchOptions);
|
|
12
12
|
}
|
|
13
13
|
if (options.redisClient) {
|
|
14
|
-
authorization_service_1.setRedisClient(options.redisClient);
|
|
14
|
+
authorization_service_1.setRedisClient(options.redisClient, options.redisKeyExpirationInSeconds);
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
exports.init = init;
|
|
@@ -5,7 +5,7 @@ export interface AuthorizeResponse {
|
|
|
5
5
|
unauthorizedIds?: number[];
|
|
6
6
|
}
|
|
7
7
|
export declare function setRequestFetchOptions(customMondayFetchOptions: MondayFetchOptions): void;
|
|
8
|
-
export declare function setRedisClient(client: any): void;
|
|
8
|
+
export declare function setRedisClient(client: any, redisKeyExpirationInSeconds?: number): void;
|
|
9
9
|
export declare class AuthorizationService {
|
|
10
10
|
static redisClient: any;
|
|
11
11
|
static cacheExpirationInSeconds: number;
|
|
@@ -36,15 +36,6 @@ const monday_fetch_1 = require("@mondaydotcomorg/monday-fetch");
|
|
|
36
36
|
const prometheus_service_1 = require("./prometheus-service");
|
|
37
37
|
const INTERNAL_APP_NAME = 'internal_ms';
|
|
38
38
|
const logger = MondayLogger.getLogger();
|
|
39
|
-
//
|
|
40
|
-
// const RedisClient = require('@mondaydotcomorg/monday-redis');
|
|
41
|
-
// const redis_options = {
|
|
42
|
-
// host: "https://top-secret-redis.com",
|
|
43
|
-
// port: 1234,
|
|
44
|
-
// password: "password" // Optional
|
|
45
|
-
// };
|
|
46
|
-
//
|
|
47
|
-
// const redisClient = new RedisClient(redis_options);
|
|
48
39
|
const defaultMondayFetchOptions = {
|
|
49
40
|
retries: 3,
|
|
50
41
|
callback: logOnFetchFail,
|
|
@@ -54,8 +45,11 @@ function setRequestFetchOptions(customMondayFetchOptions) {
|
|
|
54
45
|
mondayFetchOptions = Object.assign(Object.assign({}, defaultMondayFetchOptions), customMondayFetchOptions);
|
|
55
46
|
}
|
|
56
47
|
exports.setRequestFetchOptions = setRequestFetchOptions;
|
|
57
|
-
function setRedisClient(client) {
|
|
48
|
+
function setRedisClient(client, redisKeyExpirationInSeconds = 5 * 60) {
|
|
58
49
|
AuthorizationService.redisClient = client;
|
|
50
|
+
if (redisKeyExpirationInSeconds && redisKeyExpirationInSeconds > 0) {
|
|
51
|
+
AuthorizationService.cacheExpirationInSeconds = redisKeyExpirationInSeconds;
|
|
52
|
+
}
|
|
59
53
|
}
|
|
60
54
|
exports.setRedisClient = setRedisClient;
|
|
61
55
|
class AuthorizationService {
|
|
@@ -77,7 +71,8 @@ class AuthorizationService {
|
|
|
77
71
|
if (this.redisClient) {
|
|
78
72
|
let grantedFeatureValue = yield this.redisClient.get(this.getCachedKey(userId, featureName));
|
|
79
73
|
if (!(grantedFeatureValue === undefined || grantedFeatureValue === null)) {
|
|
80
|
-
|
|
74
|
+
// redis returns the value as string
|
|
75
|
+
return grantedFeatureValue === 'true';
|
|
81
76
|
}
|
|
82
77
|
}
|
|
83
78
|
let grantedFeatureValue = yield this.fetchIsUserGrantedWithFeature(featureName, accountId, userId);
|
|
@@ -98,7 +93,7 @@ class AuthorizationService {
|
|
|
98
93
|
});
|
|
99
94
|
}
|
|
100
95
|
static getCachedKey(userId, featureName) {
|
|
101
|
-
return
|
|
96
|
+
return `granted-feature-${featureName}-${userId}`;
|
|
102
97
|
}
|
|
103
98
|
static isAuthorizedSingular(accountId, userId, resources, action) {
|
|
104
99
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -154,7 +149,6 @@ class AuthorizationService {
|
|
|
154
149
|
}
|
|
155
150
|
}
|
|
156
151
|
exports.AuthorizationService = AuthorizationService;
|
|
157
|
-
AuthorizationService.cacheExpirationInSeconds = 5 * 60;
|
|
158
152
|
function createAuthorizationParams(resources, action) {
|
|
159
153
|
const params = {
|
|
160
154
|
authorizationObjects: resources.map((resource) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mondaydotcomorg/monday-authorization",
|
|
3
|
-
"version": "1.0.44-featureyoniadd-granted-feature-sdk-api.
|
|
3
|
+
"version": "1.0.44-featureyoniadd-granted-feature-sdk-api.559+451485bc",
|
|
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": "451485bcb0a7978d4418ba9a8da24215378f5516"
|
|
36
36
|
}
|