@mondaydotcomorg/monday-authorization 1.0.44-featureyoniadd-granted-feature-sdk-api.560 → 1.0.44-featureyuvalflexible-dependencies-types.283

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/README.md CHANGED
@@ -15,7 +15,7 @@ show is the action, post is the resource.
15
15
  ```
16
16
  yarn add @mondaydotcomorg/monday-authorization
17
17
  ```
18
-
18
+ First init the package in order for it to work properly <br>
19
19
  app.ts:
20
20
 
21
21
  ```ts
@@ -7,8 +7,8 @@ export interface AuthorizeResponse {
7
7
  export declare function setRequestFetchOptions(customMondayFetchOptions: MondayFetchOptions): void;
8
8
  export declare function setRedisClient(client: any, grantedFeatureRedisExpirationInSeconds?: number): void;
9
9
  export declare class AuthorizationService {
10
- static redisClient: any;
11
- static grantedFeatureRedisExpirationInSeconds: number;
10
+ static redisClient?: any;
11
+ static grantedFeatureRedisExpirationInSeconds?: number;
12
12
  /**
13
13
  * @deprecated use the second form with authorizationRequestObjects instead,
14
14
  * support of this function will be dropped gradually
@@ -17,7 +17,7 @@ export declare class AuthorizationService {
17
17
  static isAuthorized(accountId: number, userId: number, authorizationRequestObjects: AuthorizationObject[]): Promise<AuthorizeResponse>;
18
18
  static isUserGrantedWithFeature(accountId: number, userId: number, featureName: string): Promise<boolean>;
19
19
  private static fetchIsUserGrantedWithFeature;
20
- private static getCachedKey;
20
+ private static getCachedKeyName;
21
21
  private static isAuthorizedSingular;
22
22
  private static isAuthorizedMultiple;
23
23
  }
@@ -36,6 +36,7 @@ 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
+ const GRANTED_FEATURE_CACHE_EXPIRATION_SECONDS = 5 * 60;
39
40
  const defaultMondayFetchOptions = {
40
41
  retries: 3,
41
42
  callback: logOnFetchFail,
@@ -45,11 +46,15 @@ function setRequestFetchOptions(customMondayFetchOptions) {
45
46
  mondayFetchOptions = Object.assign(Object.assign({}, defaultMondayFetchOptions), customMondayFetchOptions);
46
47
  }
47
48
  exports.setRequestFetchOptions = setRequestFetchOptions;
48
- function setRedisClient(client, grantedFeatureRedisExpirationInSeconds = 5 * 60) {
49
+ function setRedisClient(client, grantedFeatureRedisExpirationInSeconds = GRANTED_FEATURE_CACHE_EXPIRATION_SECONDS) {
49
50
  AuthorizationService.redisClient = client;
50
51
  if (grantedFeatureRedisExpirationInSeconds && grantedFeatureRedisExpirationInSeconds > 0) {
51
52
  AuthorizationService.grantedFeatureRedisExpirationInSeconds = grantedFeatureRedisExpirationInSeconds;
52
53
  }
54
+ else {
55
+ logger.warn({ grantedFeatureRedisExpirationInSeconds }, 'Invalid input for grantedFeatureRedisExpirationInSeconds, must be positive number. using default ttl.');
56
+ AuthorizationService.grantedFeatureRedisExpirationInSeconds = GRANTED_FEATURE_CACHE_EXPIRATION_SECONDS;
57
+ }
53
58
  }
54
59
  exports.setRedisClient = setRedisClient;
55
60
  class AuthorizationService {
@@ -68,7 +73,7 @@ class AuthorizationService {
68
73
  }
69
74
  static isUserGrantedWithFeature(accountId, userId, featureName) {
70
75
  return __awaiter(this, void 0, void 0, function* () {
71
- let cachedKey = this.getCachedKey(userId, featureName);
76
+ let cachedKey = this.getCachedKeyName(userId, featureName);
72
77
  if (this.redisClient) {
73
78
  let grantedFeatureValue = yield this.redisClient.get(cachedKey);
74
79
  if (!(grantedFeatureValue === undefined || grantedFeatureValue === null)) {
@@ -93,7 +98,7 @@ class AuthorizationService {
93
98
  return authorizeResponsePromise.isAuthorized;
94
99
  });
95
100
  }
96
- static getCachedKey(userId, featureName) {
101
+ static getCachedKeyName(userId, featureName) {
97
102
  return `granted-feature-${featureName}-${userId}`;
98
103
  }
99
104
  static isAuthorizedSingular(accountId, userId, resources, action) {
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.560+aa13dbf4",
3
+ "version": "1.0.44-featureyuvalflexible-dependencies-types.283+83f3cbe7",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "license": "BSD-3-Clause",
@@ -11,7 +11,7 @@
11
11
  "dependencies": {
12
12
  "@mondaydotcomorg/monday-fetch": "^0.0.7",
13
13
  "@mondaydotcomorg/monday-jwt": "^2.0.4",
14
- "@mondaydotcomorg/monday-logger": "^3.0.7",
14
+ "@mondaydotcomorg/monday-logger": "^3.0.8-featureyuvalflexible-dependencies-types.283+83f3cbe7",
15
15
  "@types/express": "^4.17.12",
16
16
  "node-fetch": "^2.6.7",
17
17
  "ts-node": "^10.0.0"
@@ -21,7 +21,7 @@
21
21
  "@types/on-headers": "^1.0.0",
22
22
  "@types/supertest": "^2.0.11",
23
23
  "express": "^4.17.1",
24
- "ioredis": "^5.2.3",
24
+ "ioredis": "^5.2.4",
25
25
  "ioredis-mock": "^8.2.2",
26
26
  "mocha": "^9.0.1",
27
27
  "on-headers": "^1.0.2",
@@ -32,5 +32,5 @@
32
32
  "files": [
33
33
  "dist/"
34
34
  ],
35
- "gitHead": "aa13dbf433d5ef55c0b59c19fedab103d4d707b4"
35
+ "gitHead": "83f3cbe727ed46a5a36f35122b7ced4be22bbea2"
36
36
  }