@mondaydotcomorg/monday-authorization 1.0.23 → 1.0.25
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
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { MondayFetchOptions } from '@mondaydotcomorg/monday-fetch';
|
|
1
2
|
export interface InitOptions {
|
|
2
3
|
prometheus?: any;
|
|
4
|
+
mondayFetchOptions?: MondayFetchOptions;
|
|
3
5
|
}
|
|
4
6
|
export declare function init(options?: InitOptions): void;
|
|
5
7
|
export { authorizationCheckMiddleware, getAuthorizationMiddleware, skipAuthorizationMiddleware, } from './lib/authorization-middleware';
|
package/dist/index.js
CHANGED
|
@@ -2,15 +2,19 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AuthorizationService = exports.skipAuthorizationMiddleware = exports.getAuthorizationMiddleware = exports.authorizationCheckMiddleware = exports.init = void 0;
|
|
4
4
|
const prometheus_service_1 = require("./lib/prometheus-service");
|
|
5
|
+
const authorization_service_1 = require("./lib/authorization-service");
|
|
5
6
|
function init(options = {}) {
|
|
6
7
|
if (options.prometheus) {
|
|
7
8
|
prometheus_service_1.setPrometheus(options.prometheus);
|
|
8
9
|
}
|
|
10
|
+
if (options.mondayFetchOptions) {
|
|
11
|
+
authorization_service_1.setRequestFetchOptions(options.mondayFetchOptions);
|
|
12
|
+
}
|
|
9
13
|
}
|
|
10
14
|
exports.init = init;
|
|
11
15
|
var authorization_middleware_1 = require("./lib/authorization-middleware");
|
|
12
16
|
Object.defineProperty(exports, "authorizationCheckMiddleware", { enumerable: true, get: function () { return authorization_middleware_1.authorizationCheckMiddleware; } });
|
|
13
17
|
Object.defineProperty(exports, "getAuthorizationMiddleware", { enumerable: true, get: function () { return authorization_middleware_1.getAuthorizationMiddleware; } });
|
|
14
18
|
Object.defineProperty(exports, "skipAuthorizationMiddleware", { enumerable: true, get: function () { return authorization_middleware_1.skipAuthorizationMiddleware; } });
|
|
15
|
-
var
|
|
16
|
-
Object.defineProperty(exports, "AuthorizationService", { enumerable: true, get: function () { return
|
|
19
|
+
var authorization_service_2 = require("./lib/authorization-service");
|
|
20
|
+
Object.defineProperty(exports, "AuthorizationService", { enumerable: true, get: function () { return authorization_service_2.AuthorizationService; } });
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { MondayFetchOptions } from '@mondaydotcomorg/monday-fetch';
|
|
1
2
|
import { Action, Resource } from './types/general';
|
|
2
3
|
export interface AuthorizeResponse {
|
|
3
4
|
isAuthorized: boolean;
|
|
4
5
|
unauthorizedIds?: number[];
|
|
5
6
|
}
|
|
7
|
+
export declare function setRequestFetchOptions(customMondayFetchOptions: MondayFetchOptions): void;
|
|
6
8
|
export declare class AuthorizationService {
|
|
7
9
|
static isAuthorized(accountId: number, userId: number, resources: Resource[], action: Action): Promise<AuthorizeResponse>;
|
|
8
10
|
}
|
|
@@ -27,25 +27,31 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
27
27
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
28
|
});
|
|
29
29
|
};
|
|
30
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
31
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
32
|
-
};
|
|
33
30
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
-
exports.AuthorizationService = void 0;
|
|
31
|
+
exports.AuthorizationService = exports.setRequestFetchOptions = void 0;
|
|
35
32
|
const perf_hooks_1 = require("perf_hooks");
|
|
36
33
|
const monday_jwt_1 = require("@mondaydotcomorg/monday-jwt");
|
|
37
34
|
const MondayLogger = __importStar(require("@mondaydotcomorg/monday-logger"));
|
|
38
|
-
const monday_fetch_1 =
|
|
35
|
+
const monday_fetch_1 = require("@mondaydotcomorg/monday-fetch");
|
|
39
36
|
const prometheus_service_1 = require("./prometheus-service");
|
|
40
37
|
const INTERNAL_APP_NAME = 'internal_ms';
|
|
41
38
|
const logger = MondayLogger.getLogger();
|
|
39
|
+
const defaultMondayFetchOptions = {
|
|
40
|
+
retries: 3,
|
|
41
|
+
callback: logOnFetchFail,
|
|
42
|
+
};
|
|
43
|
+
let mondayFetchOptions = defaultMondayFetchOptions;
|
|
44
|
+
function setRequestFetchOptions(customMondayFetchOptions) {
|
|
45
|
+
mondayFetchOptions = Object.assign(Object.assign({}, defaultMondayFetchOptions), customMondayFetchOptions);
|
|
46
|
+
}
|
|
47
|
+
exports.setRequestFetchOptions = setRequestFetchOptions;
|
|
42
48
|
class AuthorizationService {
|
|
43
49
|
static isAuthorized(accountId, userId, resources, action) {
|
|
44
50
|
return __awaiter(this, void 0, void 0, function* () {
|
|
45
51
|
const internalAuthToken = monday_jwt_1.signAuthorizationHeader(INTERNAL_APP_NAME, accountId);
|
|
46
52
|
const { authorizationObjects } = createAuthorizationParams(resources, action);
|
|
47
53
|
const startTime = perf_hooks_1.performance.now();
|
|
48
|
-
const response = yield monday_fetch_1.
|
|
54
|
+
const response = yield monday_fetch_1.fetch(getUrl(), {
|
|
49
55
|
method: 'POST',
|
|
50
56
|
headers: { Authorization: internalAuthToken, 'Content-Type': 'application/json' },
|
|
51
57
|
timeout: getRequestTimeout(),
|
|
@@ -53,7 +59,7 @@ class AuthorizationService {
|
|
|
53
59
|
user_id: userId,
|
|
54
60
|
authorize_request_objects: authorizationObjects,
|
|
55
61
|
}),
|
|
56
|
-
},
|
|
62
|
+
}, mondayFetchOptions);
|
|
57
63
|
const endTime = perf_hooks_1.performance.now();
|
|
58
64
|
const time = endTime - startTime;
|
|
59
65
|
const responseStatus = response.status;
|
|
@@ -79,7 +85,9 @@ class AuthorizationService {
|
|
|
79
85
|
logger.info({
|
|
80
86
|
resources: JSON.stringify(unauthorizedObjects),
|
|
81
87
|
}, 'AuthorizationService: resource is unauthorized');
|
|
82
|
-
const unauthorizedIds = unauthorizedObjects
|
|
88
|
+
const unauthorizedIds = unauthorizedObjects
|
|
89
|
+
.filter(obj => !!obj.resource_id)
|
|
90
|
+
.map(obj => obj.resource_id);
|
|
83
91
|
return { isAuthorized: false, unauthorizedIds };
|
|
84
92
|
}
|
|
85
93
|
return { isAuthorized: true };
|
|
@@ -103,8 +111,13 @@ function createAuthorizationParams(resources, action) {
|
|
|
103
111
|
};
|
|
104
112
|
return params;
|
|
105
113
|
}
|
|
106
|
-
function logOnFetchFail(
|
|
107
|
-
|
|
114
|
+
function logOnFetchFail(retriesLeft, error, response) {
|
|
115
|
+
if (retriesLeft == 0) {
|
|
116
|
+
logger.error({ retriesLeft, error }, 'Authorization attempt failed due to network issues');
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
logger.info({ retriesLeft, error }, 'Authorization attempt failed due to network issues, trying again');
|
|
120
|
+
}
|
|
108
121
|
}
|
|
109
122
|
function getUrl() {
|
|
110
123
|
return `${process.env.MONDAY_INTERNAL_URL}/internal_ms/authorization/authorize`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mondaydotcomorg/monday-authorization",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.25",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"license": "BSD-3-Clause",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"build": "tsc --build"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@mondaydotcomorg/monday-fetch": "^0.0.
|
|
12
|
+
"@mondaydotcomorg/monday-fetch": "^0.0.5",
|
|
13
13
|
"@mondaydotcomorg/monday-jwt": "^2.0.4",
|
|
14
14
|
"@mondaydotcomorg/monday-logger": "^2.1.2",
|
|
15
15
|
"@types/express": "^4.17.12",
|
|
@@ -30,5 +30,5 @@
|
|
|
30
30
|
"files": [
|
|
31
31
|
"dist/"
|
|
32
32
|
],
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "ea2002a445123ec7a0ee09b7b2e61c67327666cd"
|
|
34
34
|
}
|