@mondaydotcomorg/monday-authorization 3.3.0-feature-bashanye-navigate-can-action-in-scope-to-graph-2d70b30 → 3.3.1-feature-bashanye-add-membership-create-delete-api-d00c165
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 +143 -11
- package/dist/attributions-service.d.ts +3 -2
- package/dist/attributions-service.d.ts.map +1 -1
- package/dist/attributions-service.js +1 -0
- package/dist/authorization-internal-service.d.ts +1 -1
- package/dist/authorization-internal-service.d.ts.map +1 -1
- package/dist/authorization-service.d.ts +5 -0
- package/dist/authorization-service.d.ts.map +1 -1
- package/dist/authorization-service.js +30 -26
- package/dist/clients/graph-api.d.ts +28 -0
- package/dist/clients/graph-api.d.ts.map +1 -0
- package/dist/clients/{graph-api.client.js → graph-api.js} +48 -40
- package/dist/clients/platform-api.d.ts +26 -0
- package/dist/clients/platform-api.d.ts.map +1 -0
- package/dist/clients/{platform-api.client.js → platform-api.js} +20 -20
- package/dist/constants.d.ts +1 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +2 -0
- package/dist/esm/attributions-service.d.ts +3 -2
- package/dist/esm/attributions-service.d.ts.map +1 -1
- package/dist/esm/attributions-service.mjs +1 -0
- package/dist/esm/authorization-internal-service.d.ts +1 -1
- package/dist/esm/authorization-internal-service.d.ts.map +1 -1
- package/dist/esm/authorization-service.d.ts +5 -0
- package/dist/esm/authorization-service.d.ts.map +1 -1
- package/dist/esm/authorization-service.mjs +31 -27
- package/dist/esm/clients/graph-api.d.ts +28 -0
- package/dist/esm/clients/graph-api.d.ts.map +1 -0
- package/dist/esm/clients/{graph-api.client.mjs → graph-api.mjs} +48 -40
- package/dist/esm/clients/platform-api.d.ts +26 -0
- package/dist/esm/clients/platform-api.d.ts.map +1 -0
- package/dist/esm/clients/{platform-api.client.mjs → platform-api.mjs} +21 -21
- package/dist/esm/constants.d.ts +1 -0
- package/dist/esm/constants.d.ts.map +1 -1
- package/dist/esm/constants.mjs +2 -1
- package/dist/esm/index.d.ts +7 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.mjs +9 -0
- package/dist/esm/memberships.d.ts +30 -0
- package/dist/esm/memberships.d.ts.map +1 -0
- package/dist/esm/memberships.mjs +98 -0
- package/dist/esm/metrics-service.d.ts +12 -0
- package/dist/esm/metrics-service.d.ts.map +1 -0
- package/dist/esm/metrics-service.mjs +54 -0
- package/dist/esm/prometheus-service.d.ts +1 -3
- package/dist/esm/prometheus-service.d.ts.map +1 -1
- package/dist/esm/prometheus-service.mjs +5 -58
- package/dist/esm/types/graph-api.types.d.ts +8 -7
- package/dist/esm/types/graph-api.types.d.ts.map +1 -1
- package/dist/esm/types/memberships.d.ts +42 -0
- package/dist/esm/types/memberships.d.ts.map +1 -0
- package/dist/esm/types/memberships.mjs +1 -0
- package/dist/esm/types/scoped-actions-contracts.d.ts +10 -1
- package/dist/esm/types/scoped-actions-contracts.d.ts.map +1 -1
- package/dist/esm/types/scoped-actions-contracts.mjs +9 -0
- package/dist/esm/utils/api-error-handler.d.ts +2 -0
- package/dist/esm/utils/api-error-handler.d.ts.map +1 -0
- package/dist/esm/utils/api-error-handler.mjs +18 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -0
- package/dist/memberships.d.ts +30 -0
- package/dist/memberships.d.ts.map +1 -0
- package/dist/memberships.js +100 -0
- package/dist/metrics-service.d.ts +12 -0
- package/dist/metrics-service.d.ts.map +1 -0
- package/dist/metrics-service.js +58 -0
- package/dist/prometheus-service.d.ts +1 -3
- package/dist/prometheus-service.d.ts.map +1 -1
- package/dist/prometheus-service.js +4 -59
- package/dist/types/graph-api.types.d.ts +8 -7
- package/dist/types/graph-api.types.d.ts.map +1 -1
- package/dist/types/memberships.d.ts +42 -0
- package/dist/types/memberships.d.ts.map +1 -0
- package/dist/types/memberships.js +1 -0
- package/dist/types/scoped-actions-contracts.d.ts +10 -1
- package/dist/types/scoped-actions-contracts.d.ts.map +1 -1
- package/dist/types/scoped-actions-contracts.js +9 -0
- package/dist/utils/api-error-handler.d.ts +2 -0
- package/dist/utils/api-error-handler.d.ts.map +1 -0
- package/dist/utils/api-error-handler.js +20 -0
- package/package.json +5 -2
- package/src/attributions-service.ts +93 -0
- package/src/authorization-attributes-service.ts +234 -0
- package/src/authorization-internal-service.ts +129 -0
- package/src/authorization-middleware.ts +51 -0
- package/src/authorization-service.ts +356 -0
- package/src/clients/graph-api.ts +170 -0
- package/src/clients/platform-api.ts +117 -0
- package/src/constants/sns.ts +5 -0
- package/src/constants.ts +23 -0
- package/src/index.ts +63 -0
- package/src/memberships.ts +111 -0
- package/src/metrics-service.ts +71 -0
- package/src/prometheus-service.ts +51 -0
- package/src/roles-service.ts +125 -0
- package/src/testKit/index.ts +69 -0
- package/src/types/authorization-attributes-contracts.ts +33 -0
- package/src/types/express.ts +8 -0
- package/src/types/general.ts +32 -0
- package/src/types/graph-api.types.ts +25 -0
- package/src/types/memberships.ts +47 -0
- package/src/types/roles.ts +42 -0
- package/src/types/scoped-actions-contracts.ts +57 -0
- package/src/utils/api-error-handler.ts +25 -0
- package/src/utils/authorization.utils.ts +47 -0
- package/dist/clients/graph-api.client.d.ts +0 -24
- package/dist/clients/graph-api.client.d.ts.map +0 -1
- package/dist/clients/platform-api.client.d.ts +0 -31
- package/dist/clients/platform-api.client.d.ts.map +0 -1
- package/dist/esm/clients/graph-api.client.d.ts +0 -24
- package/dist/esm/clients/graph-api.client.d.ts.map +0 -1
- package/dist/esm/clients/platform-api.client.d.ts +0 -31
- package/dist/esm/clients/platform-api.client.d.ts.map +0 -1
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { Api } from '@mondaydotcomorg/trident-backend-api';
|
|
2
|
+
import { getAttributionsFromApi } from './attributions-service.mjs';
|
|
3
|
+
import { ERROR_MESSAGES, DEFAULT_FETCH_OPTIONS, APP_NAME } from './constants.mjs';
|
|
4
|
+
import { handleApiError } from './utils/api-error-handler.mjs';
|
|
5
|
+
|
|
6
|
+
class MembershipsService {
|
|
7
|
+
static API_PATHS = {
|
|
8
|
+
UPSERT_RESOURCE_ATTRIBUTES: '/memberships/{accountId}',
|
|
9
|
+
DELETE_RESOURCE_ATTRIBUTES: '/memberships/{accountId}',
|
|
10
|
+
};
|
|
11
|
+
httpClient;
|
|
12
|
+
fetchOptions;
|
|
13
|
+
/**
|
|
14
|
+
* Public constructor to create the AuthorizationAttributesService instance.
|
|
15
|
+
* @param httpClient The HTTP client to use for API requests, if not provided, the default HTTP client from Api will be used.
|
|
16
|
+
* @param fetchOptions The fetch options to use for API requests, if not provided, the default fetch options will be used.
|
|
17
|
+
*/
|
|
18
|
+
constructor(httpClient, fetchOptions) {
|
|
19
|
+
if (!httpClient) {
|
|
20
|
+
httpClient = Api.getPart('httpClient');
|
|
21
|
+
if (!httpClient) {
|
|
22
|
+
throw new Error(ERROR_MESSAGES.HTTP_CLIENT_NOT_INITIALIZED);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (!fetchOptions) {
|
|
26
|
+
fetchOptions = DEFAULT_FETCH_OPTIONS;
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
fetchOptions = {
|
|
30
|
+
...DEFAULT_FETCH_OPTIONS,
|
|
31
|
+
...fetchOptions,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
this.httpClient = httpClient;
|
|
35
|
+
this.fetchOptions = fetchOptions;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Upsert memberships synchronously, performing http call to the authorization MS to assign the given memberships.
|
|
39
|
+
* @param accountId
|
|
40
|
+
* @param memberships - Array of memberships to upsert
|
|
41
|
+
* @returns MembershipCreateResponse - The affected (created and updated) memberships.
|
|
42
|
+
*/
|
|
43
|
+
async upsertMemberships(accountId, memberships) {
|
|
44
|
+
const attributionHeaders = getAttributionsFromApi();
|
|
45
|
+
try {
|
|
46
|
+
return await this.httpClient.fetch({
|
|
47
|
+
url: {
|
|
48
|
+
appName: APP_NAME,
|
|
49
|
+
path: MembershipsService.API_PATHS.UPSERT_RESOURCE_ATTRIBUTES.replace('{accountId}', accountId.toString()),
|
|
50
|
+
},
|
|
51
|
+
method: 'PUT',
|
|
52
|
+
query: {
|
|
53
|
+
useAStyleRoleId: 'true',
|
|
54
|
+
},
|
|
55
|
+
headers: {
|
|
56
|
+
'Content-Type': 'application/json',
|
|
57
|
+
...attributionHeaders,
|
|
58
|
+
},
|
|
59
|
+
body: JSON.stringify({ memberships }),
|
|
60
|
+
}, this.fetchOptions);
|
|
61
|
+
}
|
|
62
|
+
catch (err) {
|
|
63
|
+
return handleApiError(err, 'authorization', 'upsertMemberships');
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Delete memberships synchronously, performing http call to the authorization MS to delete the given memberships.
|
|
68
|
+
* @param accountId
|
|
69
|
+
* @param resource - The resource (resourceType, resourceId) to delete the attributes for.
|
|
70
|
+
* @param attributeKeys - Array of attribute keys to delete for the resource.
|
|
71
|
+
* @returns ResourceAttributeResponse - The affected (deleted) resource attributes assignments in the `attributes` field.
|
|
72
|
+
*/
|
|
73
|
+
async deleteMemberships(accountId, memberships) {
|
|
74
|
+
const attributionHeaders = getAttributionsFromApi();
|
|
75
|
+
try {
|
|
76
|
+
return await this.httpClient.fetch({
|
|
77
|
+
url: {
|
|
78
|
+
appName: APP_NAME,
|
|
79
|
+
path: MembershipsService.API_PATHS.DELETE_RESOURCE_ATTRIBUTES.replace('{accountId}', accountId.toString()),
|
|
80
|
+
},
|
|
81
|
+
method: 'DELETE',
|
|
82
|
+
query: {
|
|
83
|
+
useAStyleRoleId: 'true',
|
|
84
|
+
},
|
|
85
|
+
headers: {
|
|
86
|
+
'Content-Type': 'application/json',
|
|
87
|
+
...attributionHeaders,
|
|
88
|
+
},
|
|
89
|
+
body: JSON.stringify({ memberships }),
|
|
90
|
+
}, this.fetchOptions);
|
|
91
|
+
}
|
|
92
|
+
catch (err) {
|
|
93
|
+
return handleApiError(err, 'authorization', 'deleteMemberships');
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export { MembershipsService };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
type ApiType = 'platform' | 'graph' | 'authorization';
|
|
2
|
+
interface InitializeMetricsOptions {
|
|
3
|
+
serviceName: string;
|
|
4
|
+
host?: string;
|
|
5
|
+
port?: number;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare function initializeMetrics(options: InitializeMetricsOptions): void;
|
|
9
|
+
export declare function recordAuthorizationTiming(apiType: ApiType, duration: number, placement: string): void;
|
|
10
|
+
export declare function recordAuthorizationError(apiType: ApiType, statusCode: number, placement: string): void;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=metrics-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metrics-service.d.ts","sourceRoot":"","sources":["../../src/metrics-service.ts"],"names":[],"mappings":"AAGA,KAAK,OAAO,GAAG,UAAU,GAAG,OAAO,GAAG,eAAe,CAAC;AAEtD,UAAU,wBAAwB;IAChC,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAID,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,wBAAwB,GAAG,IAAI,CA4BzE;AAED,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAUrG;AAED,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CActG"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Metric } from '@mondaydotcomorg/monday-observability-kit';
|
|
2
|
+
import { logger } from './authorization-internal-service.mjs';
|
|
3
|
+
|
|
4
|
+
let initialized = false;
|
|
5
|
+
function initializeMetrics(options) {
|
|
6
|
+
if (initialized) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
const { serviceName } = options;
|
|
10
|
+
if (!serviceName) {
|
|
11
|
+
logger.warn({ tag: 'metrics-service' }, 'Metrics initialization skipped: serviceName is missing');
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const resolvedHost = options.host ?? process.env.DOGSTATSD_HOST ?? 'localhost';
|
|
15
|
+
const envPort = process.env.DOGSTATSD_PORT ? Number(process.env.DOGSTATSD_PORT) : undefined;
|
|
16
|
+
const resolvedPort = options.port ?? (Number.isFinite(envPort ?? NaN) ? envPort : undefined) ?? 8125;
|
|
17
|
+
const resolvedDisabled = options.disabled ?? ['test', 'development'].includes((process.env.NODE_ENV ?? '').toLowerCase());
|
|
18
|
+
try {
|
|
19
|
+
Metric.initialize({
|
|
20
|
+
serviceName,
|
|
21
|
+
host: resolvedHost,
|
|
22
|
+
port: resolvedPort,
|
|
23
|
+
disabled: resolvedDisabled,
|
|
24
|
+
});
|
|
25
|
+
initialized = true;
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
logger.warn({ tag: 'metrics-service', error }, 'Failed to initialize metrics');
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function recordAuthorizationTiming(apiType, duration, placement) {
|
|
32
|
+
if (!initialized) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
Metric.distribution(`authorization.authorizationCheck.${apiType}.${placement}.duration`, duration);
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
// ignore metric emission failures
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function recordAuthorizationError(apiType, statusCode, placement) {
|
|
43
|
+
if (!initialized) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
Metric.increment(`authorization.authorizationCheck.${apiType}.${placement}.error`, { statusCode: String(statusCode) }, 1);
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
// ignore metric emission failures
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export { initializeMetrics, recordAuthorizationError, recordAuthorizationTiming };
|
|
@@ -6,7 +6,5 @@ export declare const METRICS: {
|
|
|
6
6
|
};
|
|
7
7
|
export declare function setPrometheus(customPrometheus: any): void;
|
|
8
8
|
export declare function getMetricsManager(): any;
|
|
9
|
-
export declare function sendAuthorizationCheckResponseTimeMetric(resourceType: string, action: Action, isAuthorized: boolean, responseStatus: number, time: number
|
|
10
|
-
export declare function incrementAuthorizationSuccess(resourceType: string, action: Action, apiType: 'platform' | 'graph'): void;
|
|
11
|
-
export declare function incrementAuthorizationError(resourceType: string, action: Action, statusCode: number, apiType: 'platform' | 'graph'): void;
|
|
9
|
+
export declare function sendAuthorizationCheckResponseTimeMetric(resourceType: string, action: Action, isAuthorized: boolean, responseStatus: number, time: number): void;
|
|
12
10
|
//# sourceMappingURL=prometheus-service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prometheus-service.d.ts","sourceRoot":"","sources":["../../src/prometheus-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"prometheus-service.d.ts","sourceRoot":"","sources":["../../src/prometheus-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAKzC,eAAO,MAAM,OAAO;;;;CAInB,CAAC;AAQF,wBAAgB,aAAa,CAAC,gBAAgB,KAAA,QAa7C;AAED,wBAAgB,iBAAiB,QAEhC;AAED,wBAAgB,wCAAwC,CACtD,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,OAAO,EACrB,cAAc,EAAE,MAAM,EACtB,IAAI,EAAE,MAAM,QASb"}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
let prometheus = null;
|
|
2
2
|
let authorizationCheckResponseTimeMetric = null;
|
|
3
|
-
let authorizationSuccessMetric = null;
|
|
4
|
-
let authorizationErrorMetric = null;
|
|
5
3
|
const METRICS = {
|
|
6
4
|
AUTHORIZATION_CHECK: 'authorization_check',
|
|
7
5
|
AUTHORIZATION_CHECKS_PER_REQUEST: 'authorization_checks_per_request',
|
|
@@ -9,80 +7,29 @@ const METRICS = {
|
|
|
9
7
|
};
|
|
10
8
|
const authorizationCheckResponseTimeMetricConfig = {
|
|
11
9
|
name: METRICS.AUTHORIZATION_CHECK_RESPONSE_TIME,
|
|
12
|
-
labels: ['resourceType', 'action', 'isAuthorized', 'responseStatus'
|
|
10
|
+
labels: ['resourceType', 'action', 'isAuthorized', 'responseStatus'],
|
|
13
11
|
description: 'Authorization check response time summary',
|
|
14
12
|
};
|
|
15
13
|
function setPrometheus(customPrometheus) {
|
|
16
14
|
prometheus = customPrometheus;
|
|
17
15
|
if (!prometheus) {
|
|
18
|
-
authorizationCheckResponseTimeMetric = null;
|
|
19
|
-
authorizationSuccessMetric = null;
|
|
20
|
-
authorizationErrorMetric = null;
|
|
21
16
|
return;
|
|
22
17
|
}
|
|
23
18
|
const { METRICS_TYPES } = prometheus;
|
|
24
|
-
|
|
25
|
-
if (metricsManager) {
|
|
26
|
-
authorizationCheckResponseTimeMetric = metricsManager.addMetric(METRICS_TYPES.SUMMARY, authorizationCheckResponseTimeMetricConfig.name, authorizationCheckResponseTimeMetricConfig.labels, authorizationCheckResponseTimeMetricConfig.description);
|
|
27
|
-
initializeAdditionalMetrics();
|
|
28
|
-
}
|
|
19
|
+
authorizationCheckResponseTimeMetric = getMetricsManager().addMetric(METRICS_TYPES.SUMMARY, authorizationCheckResponseTimeMetricConfig.name, authorizationCheckResponseTimeMetricConfig.labels, authorizationCheckResponseTimeMetricConfig.description);
|
|
29
20
|
}
|
|
30
21
|
function getMetricsManager() {
|
|
31
22
|
return prometheus?.metricsManager;
|
|
32
23
|
}
|
|
33
|
-
function sendAuthorizationCheckResponseTimeMetric(resourceType, action, isAuthorized, responseStatus, time
|
|
24
|
+
function sendAuthorizationCheckResponseTimeMetric(resourceType, action, isAuthorized, responseStatus, time) {
|
|
34
25
|
try {
|
|
35
26
|
if (authorizationCheckResponseTimeMetric) {
|
|
36
|
-
authorizationCheckResponseTimeMetric
|
|
37
|
-
.labels(resourceType, action, isAuthorized, responseStatus, apiType)
|
|
38
|
-
.observe(time);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
catch (e) {
|
|
42
|
-
// ignore
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
const authorizationSuccessMetricConfig = {
|
|
46
|
-
name: 'authorization_success_total',
|
|
47
|
-
labels: ['resourceType', 'action', 'apiType'],
|
|
48
|
-
description: 'Total number of successful authorization checks',
|
|
49
|
-
};
|
|
50
|
-
const authorizationErrorMetricConfig = {
|
|
51
|
-
name: 'authorization_error_total',
|
|
52
|
-
labels: ['resourceType', 'action', 'statusCode', 'apiType'],
|
|
53
|
-
description: 'Total number of authorization errors',
|
|
54
|
-
};
|
|
55
|
-
function incrementAuthorizationSuccess(resourceType, action, apiType) {
|
|
56
|
-
try {
|
|
57
|
-
if (authorizationSuccessMetric) {
|
|
58
|
-
authorizationSuccessMetric.labels(resourceType, action, apiType).inc();
|
|
27
|
+
authorizationCheckResponseTimeMetric.labels(resourceType, action, isAuthorized, responseStatus).observe(time);
|
|
59
28
|
}
|
|
60
29
|
}
|
|
61
30
|
catch (e) {
|
|
62
31
|
// ignore
|
|
63
32
|
}
|
|
64
33
|
}
|
|
65
|
-
function incrementAuthorizationError(resourceType, action, statusCode, apiType) {
|
|
66
|
-
try {
|
|
67
|
-
if (authorizationErrorMetric) {
|
|
68
|
-
authorizationErrorMetric.labels(resourceType, action, statusCode, apiType).inc();
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
catch (e) {
|
|
72
|
-
// ignore
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
// Initialize additional metrics when prometheus is set
|
|
76
|
-
function initializeAdditionalMetrics() {
|
|
77
|
-
if (!prometheus) {
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
const { METRICS_TYPES } = prometheus;
|
|
81
|
-
const metricsManager = getMetricsManager();
|
|
82
|
-
if (metricsManager) {
|
|
83
|
-
authorizationSuccessMetric = metricsManager.addMetric(METRICS_TYPES.COUNTER, authorizationSuccessMetricConfig.name, authorizationSuccessMetricConfig.labels, authorizationSuccessMetricConfig.description);
|
|
84
|
-
authorizationErrorMetric = metricsManager.addMetric(METRICS_TYPES.COUNTER, authorizationErrorMetricConfig.name, authorizationErrorMetricConfig.labels, authorizationErrorMetricConfig.description);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
34
|
|
|
88
|
-
export { METRICS, getMetricsManager,
|
|
35
|
+
export { METRICS, getMetricsManager, sendAuthorizationCheckResponseTimeMetric, setPrometheus };
|
|
@@ -2,14 +2,15 @@ export type ResourceType = string;
|
|
|
2
2
|
export type ResourceId = number;
|
|
3
3
|
export type ActionName = string;
|
|
4
4
|
export type GraphIsAllowedDto = Record<ResourceType, Record<ResourceId, ActionName[]>>;
|
|
5
|
-
export
|
|
5
|
+
export interface GraphPermissionReason {
|
|
6
|
+
key: string;
|
|
7
|
+
additionalOptions?: Record<string, string>;
|
|
8
|
+
technicalReason?: number;
|
|
9
|
+
}
|
|
10
|
+
export interface GraphPermissionResult {
|
|
6
11
|
can: boolean;
|
|
7
|
-
reason
|
|
8
|
-
|
|
9
|
-
additionalOptions?: Record<string, string>;
|
|
10
|
-
technicalReason?: number;
|
|
11
|
-
};
|
|
12
|
-
};
|
|
12
|
+
reason?: GraphPermissionReason;
|
|
13
|
+
}
|
|
13
14
|
export type GraphPermissionResults = Record<ActionName, GraphPermissionResult>;
|
|
14
15
|
export type GraphIsAllowedResponse = Record<ResourceType, Record<string, GraphPermissionResults>>;
|
|
15
16
|
//# sourceMappingURL=graph-api.types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graph-api.types.d.ts","sourceRoot":"","sources":["../../../src/types/graph-api.types.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC;AAClC,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC;AAChC,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC;AAEhC,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC,UAAU,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC;AAEvF,MAAM,
|
|
1
|
+
{"version":3,"file":"graph-api.types.d.ts","sourceRoot":"","sources":["../../../src/types/graph-api.types.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC;AAClC,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC;AAChC,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC;AAEhC,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC,UAAU,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC;AAEvF,MAAM,WAAW,qBAAqB;IACpC,GAAG,EAAE,MAAM,CAAC;IACZ,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC3C,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,qBAAqB;IACpC,GAAG,EAAE,OAAO,CAAC;IACb,MAAM,CAAC,EAAE,qBAAqB,CAAC;CAChC;AAGD,MAAM,MAAM,sBAAsB,GAAG,MAAM,CAAC,UAAU,EAAE,qBAAqB,CAAC,CAAC;AAI/E,MAAM,MAAM,sBAAsB,GAAG,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export interface MembershipCreateRequest {
|
|
2
|
+
memberships: MembershipForCreate[];
|
|
3
|
+
}
|
|
4
|
+
export interface MembershipDeleteRequest {
|
|
5
|
+
memberships: MembershipForDelete[];
|
|
6
|
+
}
|
|
7
|
+
export interface MembershipForCreate {
|
|
8
|
+
entityId: number;
|
|
9
|
+
entityType: string;
|
|
10
|
+
resourceId: number;
|
|
11
|
+
resourceType: string;
|
|
12
|
+
roleId: number;
|
|
13
|
+
roleType?: string;
|
|
14
|
+
addedById: number;
|
|
15
|
+
}
|
|
16
|
+
export interface MembershipForDelete {
|
|
17
|
+
entityId?: number;
|
|
18
|
+
entityType: string;
|
|
19
|
+
resourceId?: number;
|
|
20
|
+
resourceType: string;
|
|
21
|
+
}
|
|
22
|
+
export interface MembershipCreateResponse {
|
|
23
|
+
memberships: Membership[];
|
|
24
|
+
}
|
|
25
|
+
export interface MembershipDeleteResponse {
|
|
26
|
+
memberships: Membership[];
|
|
27
|
+
}
|
|
28
|
+
export interface Membership {
|
|
29
|
+
id: number;
|
|
30
|
+
entityId: number;
|
|
31
|
+
entityType: string;
|
|
32
|
+
resourceId: number;
|
|
33
|
+
resourceType: string;
|
|
34
|
+
roleId: number;
|
|
35
|
+
roleType: string;
|
|
36
|
+
addedById: null | number | undefined;
|
|
37
|
+
hops: number;
|
|
38
|
+
isNewRecord: boolean;
|
|
39
|
+
previousValues: Partial<Membership>;
|
|
40
|
+
walVersion: number | null | undefined;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=memberships.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memberships.d.ts","sourceRoot":"","sources":["../../../src/types/memberships.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,uBAAuB;IACtC,WAAW,EAAE,mBAAmB,EAAE,CAAC;CACpC;AAED,MAAM,WAAW,uBAAuB;IACtC,WAAW,EAAE,mBAAmB,EAAE,CAAC;CACpC;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,wBAAwB;IACvC,WAAW,EAAE,UAAU,EAAE,CAAC;CAC3B;AAED,MAAM,WAAW,wBAAwB;IACvC,WAAW,EAAE,UAAU,EAAE,CAAC;CAC3B;AAED,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,IAAI,GAAG,MAAM,GAAG,SAAS,CAAC;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,OAAO,CAAC;IACrB,cAAc,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;IACpC,UAAU,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;CACvC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -21,7 +21,16 @@ export interface Translation {
|
|
|
21
21
|
export declare enum PermitTechnicalReason {
|
|
22
22
|
NO_REASON = 0,
|
|
23
23
|
NOT_ELIGIBLE = 1,
|
|
24
|
-
BY_ROLE_IN_SCOPE = 2
|
|
24
|
+
BY_ROLE_IN_SCOPE = 2,
|
|
25
|
+
/**
|
|
26
|
+
* NOT_APPLICABLE indicates that the permit was requested as part of the `permissions` parameter to the `getPermits`
|
|
27
|
+
* method, but would not otherwise be returned. This is done so that a cache in the monolith can serve
|
|
28
|
+
* two purposes: to mean both that a permit was requested and that it was received; at least: in the
|
|
29
|
+
* case of where a `permissions` parameter is passed to the `getPermits` method.
|
|
30
|
+
*/
|
|
31
|
+
NOT_APPLICABLE = 3,
|
|
32
|
+
BY_POLICY = 4,
|
|
33
|
+
BY_OVERRIDE = 5
|
|
25
34
|
}
|
|
26
35
|
export interface ScopedActionPermit {
|
|
27
36
|
can: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scoped-actions-contracts.d.ts","sourceRoot":"","sources":["../../../src/types/scoped-actions-contracts.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,mBAAmB;IAClC,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,MAAM,YAAY,GAAG,cAAc,GAAG,UAAU,GAAG,UAAU,GAAG,mBAAmB,GAAG,YAAY,CAAC;AAEzG,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;CAC1B;AAED,oBAAY,qBAAqB;IAC/B,SAAS,IAAI;IACb,YAAY,IAAI;IAChB,gBAAgB,IAAI;
|
|
1
|
+
{"version":3,"file":"scoped-actions-contracts.d.ts","sourceRoot":"","sources":["../../../src/types/scoped-actions-contracts.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,mBAAmB;IAClC,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,MAAM,YAAY,GAAG,cAAc,GAAG,UAAU,GAAG,UAAU,GAAG,mBAAmB,GAAG,YAAY,CAAC;AAEzG,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;CAC1B;AAED,oBAAY,qBAAqB;IAC/B,SAAS,IAAI;IACb,YAAY,IAAI;IAChB,gBAAgB,IAAI;IACpB;;;;;OAKG;IACH,cAAc,IAAI;IAClB,SAAS,IAAI;IACb,WAAW,IAAI;CAChB;AAED,MAAM,WAAW,kBAAkB;IACjC,GAAG,EAAE,OAAO,CAAC;IACb,MAAM,EAAE,WAAW,CAAC;IACpB,eAAe,EAAE,qBAAqB,CAAC;CACxC;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,YAAY,CAAC;CACrB;AAED,MAAM,WAAW,0BAA0B;IACzC,YAAY,EAAE,YAAY,CAAC;IAC3B,MAAM,EAAE,kBAAkB,CAAC;CAC5B"}
|
|
@@ -3,6 +3,15 @@ var PermitTechnicalReason;
|
|
|
3
3
|
PermitTechnicalReason[PermitTechnicalReason["NO_REASON"] = 0] = "NO_REASON";
|
|
4
4
|
PermitTechnicalReason[PermitTechnicalReason["NOT_ELIGIBLE"] = 1] = "NOT_ELIGIBLE";
|
|
5
5
|
PermitTechnicalReason[PermitTechnicalReason["BY_ROLE_IN_SCOPE"] = 2] = "BY_ROLE_IN_SCOPE";
|
|
6
|
+
/**
|
|
7
|
+
* NOT_APPLICABLE indicates that the permit was requested as part of the `permissions` parameter to the `getPermits`
|
|
8
|
+
* method, but would not otherwise be returned. This is done so that a cache in the monolith can serve
|
|
9
|
+
* two purposes: to mean both that a permit was requested and that it was received; at least: in the
|
|
10
|
+
* case of where a `permissions` parameter is passed to the `getPermits` method.
|
|
11
|
+
*/
|
|
12
|
+
PermitTechnicalReason[PermitTechnicalReason["NOT_APPLICABLE"] = 3] = "NOT_APPLICABLE";
|
|
13
|
+
PermitTechnicalReason[PermitTechnicalReason["BY_POLICY"] = 4] = "BY_POLICY";
|
|
14
|
+
PermitTechnicalReason[PermitTechnicalReason["BY_OVERRIDE"] = 5] = "BY_OVERRIDE";
|
|
6
15
|
})(PermitTechnicalReason || (PermitTechnicalReason = {}));
|
|
7
16
|
|
|
8
17
|
export { PermitTechnicalReason };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-error-handler.d.ts","sourceRoot":"","sources":["../../../src/utils/api-error-handler.ts"],"names":[],"mappings":"AAIA,wBAAgB,cAAc,CAC5B,GAAG,EAAE,OAAO,EACZ,OAAO,EAAE,UAAU,GAAG,OAAO,GAAG,eAAe,EAC/C,SAAS,EAAE,MAAM,GAChB,KAAK,CAgBP"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { HttpFetcherError } from '@mondaydotcomorg/monday-fetch-api';
|
|
2
|
+
import { logger, AuthorizationInternalService } from '../authorization-internal-service.mjs';
|
|
3
|
+
import { recordAuthorizationError } from '../metrics-service.mjs';
|
|
4
|
+
|
|
5
|
+
function handleApiError(err, apiType, placement) {
|
|
6
|
+
if (err instanceof HttpFetcherError) {
|
|
7
|
+
logger.error({ tag: `${apiType}-api`, status: err.status, error: err.message }, `${apiType.charAt(0).toUpperCase() + apiType.slice(1)} API ${placement} request failed`);
|
|
8
|
+
recordAuthorizationError(apiType, err.status, placement);
|
|
9
|
+
AuthorizationInternalService.throwOnHttpError(err.status, placement);
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
logger.error({ tag: `${apiType}-api`, error: err instanceof Error ? err.message : String(err) }, `${apiType.charAt(0).toUpperCase() + apiType.slice(1)} API ${placement} request failed`);
|
|
13
|
+
recordAuthorizationError(apiType, 500, placement);
|
|
14
|
+
throw err;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { handleApiError };
|
package/dist/index.d.ts
CHANGED
|
@@ -5,12 +5,19 @@ export interface InitOptions {
|
|
|
5
5
|
mondayFetchOptions?: MondayFetchOptions;
|
|
6
6
|
redisClient?: any;
|
|
7
7
|
grantedFeatureRedisExpirationInSeconds?: number;
|
|
8
|
+
metrics?: {
|
|
9
|
+
serviceName?: string;
|
|
10
|
+
host?: string;
|
|
11
|
+
port?: number;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
};
|
|
8
14
|
}
|
|
9
15
|
export declare function init(options?: InitOptions): Promise<void>;
|
|
10
16
|
export { authorizationCheckMiddleware, getAuthorizationMiddleware, skipAuthorizationMiddleware, } from './authorization-middleware';
|
|
11
17
|
export { AuthorizationService, AuthorizeResponse } from './authorization-service';
|
|
12
18
|
export { AuthorizationAttributesService } from './authorization-attributes-service';
|
|
13
19
|
export { RolesService } from './roles-service';
|
|
20
|
+
export { MembershipsService } from './memberships';
|
|
14
21
|
export { AuthorizationObject, Resource, BaseRequest, ResourceGetter, ContextGetter } from './types/general';
|
|
15
22
|
export { Translation, ScopedAction, ScopedActionResponseObject, ScopedActionPermit, } from './types/scoped-actions-contracts';
|
|
16
23
|
export { CustomRole, BasicRole, RoleType, RoleCreateRequest, RoleUpdateRequest, RolesResponse } from './types/roles';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAInE,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AAErC,MAAM,WAAW,WAAW;IAC1B,UAAU,CAAC,EAAE,GAAG,CAAC;IACjB,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;IACxC,WAAW,CAAC,EAAE,GAAG,CAAC;IAClB,sCAAsC,CAAC,EAAE,MAAM,CAAC;IAChD,OAAO,CAAC,EAAE;QACR,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,QAAQ,CAAC,EAAE,OAAO,CAAC;KACpB,CAAC;CACH;AAED,wBAAsB,IAAI,CAAC,OAAO,GAAE,WAAgB,iBAuBnD;AAED,OAAO,EACL,4BAA4B,EAC5B,0BAA0B,EAC1B,2BAA2B,GAC5B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAClF,OAAO,EAAE,8BAA8B,EAAE,MAAM,oCAAoC,CAAC;AACpF,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,QAAQ,EAAE,WAAW,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC5G,OAAO,EACL,WAAW,EACX,YAAY,EACZ,0BAA0B,EAC1B,kBAAkB,GACnB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAErH,OAAO,EAAE,OAAO,EAAE,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -2,16 +2,25 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2
2
|
|
|
3
3
|
const prometheusService = require('./prometheus-service.js');
|
|
4
4
|
const authorizationService = require('./authorization-service.js');
|
|
5
|
+
const metricsService = require('./metrics-service.js');
|
|
5
6
|
const testKit_index = require('./testKit/index.js');
|
|
6
7
|
const authorizationMiddleware = require('./authorization-middleware.js');
|
|
7
8
|
const authorizationAttributesService = require('./authorization-attributes-service.js');
|
|
8
9
|
const rolesService = require('./roles-service.js');
|
|
10
|
+
const memberships = require('./memberships.js');
|
|
9
11
|
const types_roles = require('./types/roles.js');
|
|
10
12
|
|
|
11
13
|
async function init(options = {}) {
|
|
12
14
|
if (options.prometheus) {
|
|
13
15
|
prometheusService.setPrometheus(options.prometheus);
|
|
14
16
|
}
|
|
17
|
+
const resolvedDisabled = options.metrics?.disabled ?? ['test', 'development'].includes((process.env.NODE_ENV ?? '').toLowerCase());
|
|
18
|
+
metricsService.initializeMetrics({
|
|
19
|
+
serviceName: options.metrics?.serviceName ?? process.env.APP_NAME ?? 'authorization-sdk',
|
|
20
|
+
host: options.metrics?.host,
|
|
21
|
+
port: options.metrics?.port,
|
|
22
|
+
disabled: resolvedDisabled,
|
|
23
|
+
});
|
|
15
24
|
if (options.mondayFetchOptions) {
|
|
16
25
|
authorizationService.setRequestFetchOptions(options.mondayFetchOptions);
|
|
17
26
|
}
|
|
@@ -29,6 +38,7 @@ exports.getAuthorizationMiddleware = authorizationMiddleware.getAuthorizationMid
|
|
|
29
38
|
exports.skipAuthorizationMiddleware = authorizationMiddleware.skipAuthorizationMiddleware;
|
|
30
39
|
exports.AuthorizationAttributesService = authorizationAttributesService.AuthorizationAttributesService;
|
|
31
40
|
exports.RolesService = rolesService.RolesService;
|
|
41
|
+
exports.MembershipsService = memberships.MembershipsService;
|
|
32
42
|
Object.defineProperty(exports, 'RoleType', {
|
|
33
43
|
enumerable: true,
|
|
34
44
|
get: () => types_roles.RoleType
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { FetcherConfig, HttpClient } from '@mondaydotcomorg/trident-backend-api';
|
|
2
|
+
import { RecursivePartial } from '@mondaydotcomorg/monday-fetch-api';
|
|
3
|
+
import { MembershipCreateResponse, MembershipDeleteResponse, MembershipForCreate, MembershipForDelete } from './types/memberships';
|
|
4
|
+
export declare class MembershipsService {
|
|
5
|
+
private static API_PATHS;
|
|
6
|
+
private httpClient;
|
|
7
|
+
private fetchOptions;
|
|
8
|
+
/**
|
|
9
|
+
* Public constructor to create the AuthorizationAttributesService instance.
|
|
10
|
+
* @param httpClient The HTTP client to use for API requests, if not provided, the default HTTP client from Api will be used.
|
|
11
|
+
* @param fetchOptions The fetch options to use for API requests, if not provided, the default fetch options will be used.
|
|
12
|
+
*/
|
|
13
|
+
constructor(httpClient?: HttpClient, fetchOptions?: RecursivePartial<FetcherConfig>);
|
|
14
|
+
/**
|
|
15
|
+
* Upsert memberships synchronously, performing http call to the authorization MS to assign the given memberships.
|
|
16
|
+
* @param accountId
|
|
17
|
+
* @param memberships - Array of memberships to upsert
|
|
18
|
+
* @returns MembershipCreateResponse - The affected (created and updated) memberships.
|
|
19
|
+
*/
|
|
20
|
+
upsertMemberships(accountId: number, memberships: MembershipForCreate[]): Promise<MembershipCreateResponse>;
|
|
21
|
+
/**
|
|
22
|
+
* Delete memberships synchronously, performing http call to the authorization MS to delete the given memberships.
|
|
23
|
+
* @param accountId
|
|
24
|
+
* @param resource - The resource (resourceType, resourceId) to delete the attributes for.
|
|
25
|
+
* @param attributeKeys - Array of attribute keys to delete for the resource.
|
|
26
|
+
* @returns ResourceAttributeResponse - The affected (deleted) resource attributes assignments in the `attributes` field.
|
|
27
|
+
*/
|
|
28
|
+
deleteMemberships(accountId: number, memberships: MembershipForDelete[]): Promise<MembershipDeleteResponse>;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=memberships.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memberships.d.ts","sourceRoot":"","sources":["../src/memberships.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,aAAa,EAAE,UAAU,EAAE,MAAM,sCAAsC,CAAC;AACtF,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAIrE,OAAO,EACL,wBAAwB,EACxB,wBAAwB,EACxB,mBAAmB,EACnB,mBAAmB,EACpB,MAAM,mBAAmB,CAAC;AAG3B,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,MAAM,CAAC,SAAS,CAGb;IACX,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,YAAY,CAAkC;IAEtD;;;;OAIG;gBACS,UAAU,CAAC,EAAE,UAAU,EAAE,YAAY,CAAC,EAAE,gBAAgB,CAAC,aAAa,CAAC;IAoBnF;;;;;OAKG;IACG,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,mBAAmB,EAAE,GAAG,OAAO,CAAC,wBAAwB,CAAC;IA0BjH;;;;;;OAMG;IACG,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,mBAAmB,EAAE,GAAG,OAAO,CAAC,wBAAwB,CAAC;CAyBlH"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
|
|
3
|
+
const tridentBackendApi = require('@mondaydotcomorg/trident-backend-api');
|
|
4
|
+
const attributionsService = require('./attributions-service.js');
|
|
5
|
+
const constants = require('./constants.js');
|
|
6
|
+
const utils_apiErrorHandler = require('./utils/api-error-handler.js');
|
|
7
|
+
|
|
8
|
+
class MembershipsService {
|
|
9
|
+
static API_PATHS = {
|
|
10
|
+
UPSERT_RESOURCE_ATTRIBUTES: '/memberships/{accountId}',
|
|
11
|
+
DELETE_RESOURCE_ATTRIBUTES: '/memberships/{accountId}',
|
|
12
|
+
};
|
|
13
|
+
httpClient;
|
|
14
|
+
fetchOptions;
|
|
15
|
+
/**
|
|
16
|
+
* Public constructor to create the AuthorizationAttributesService instance.
|
|
17
|
+
* @param httpClient The HTTP client to use for API requests, if not provided, the default HTTP client from Api will be used.
|
|
18
|
+
* @param fetchOptions The fetch options to use for API requests, if not provided, the default fetch options will be used.
|
|
19
|
+
*/
|
|
20
|
+
constructor(httpClient, fetchOptions) {
|
|
21
|
+
if (!httpClient) {
|
|
22
|
+
httpClient = tridentBackendApi.Api.getPart('httpClient');
|
|
23
|
+
if (!httpClient) {
|
|
24
|
+
throw new Error(constants.ERROR_MESSAGES.HTTP_CLIENT_NOT_INITIALIZED);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (!fetchOptions) {
|
|
28
|
+
fetchOptions = constants.DEFAULT_FETCH_OPTIONS;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
fetchOptions = {
|
|
32
|
+
...constants.DEFAULT_FETCH_OPTIONS,
|
|
33
|
+
...fetchOptions,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
this.httpClient = httpClient;
|
|
37
|
+
this.fetchOptions = fetchOptions;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Upsert memberships synchronously, performing http call to the authorization MS to assign the given memberships.
|
|
41
|
+
* @param accountId
|
|
42
|
+
* @param memberships - Array of memberships to upsert
|
|
43
|
+
* @returns MembershipCreateResponse - The affected (created and updated) memberships.
|
|
44
|
+
*/
|
|
45
|
+
async upsertMemberships(accountId, memberships) {
|
|
46
|
+
const attributionHeaders = attributionsService.getAttributionsFromApi();
|
|
47
|
+
try {
|
|
48
|
+
return await this.httpClient.fetch({
|
|
49
|
+
url: {
|
|
50
|
+
appName: constants.APP_NAME,
|
|
51
|
+
path: MembershipsService.API_PATHS.UPSERT_RESOURCE_ATTRIBUTES.replace('{accountId}', accountId.toString()),
|
|
52
|
+
},
|
|
53
|
+
method: 'PUT',
|
|
54
|
+
query: {
|
|
55
|
+
useAStyleRoleId: 'true',
|
|
56
|
+
},
|
|
57
|
+
headers: {
|
|
58
|
+
'Content-Type': 'application/json',
|
|
59
|
+
...attributionHeaders,
|
|
60
|
+
},
|
|
61
|
+
body: JSON.stringify({ memberships }),
|
|
62
|
+
}, this.fetchOptions);
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
return utils_apiErrorHandler.handleApiError(err, 'authorization', 'upsertMemberships');
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Delete memberships synchronously, performing http call to the authorization MS to delete the given memberships.
|
|
70
|
+
* @param accountId
|
|
71
|
+
* @param resource - The resource (resourceType, resourceId) to delete the attributes for.
|
|
72
|
+
* @param attributeKeys - Array of attribute keys to delete for the resource.
|
|
73
|
+
* @returns ResourceAttributeResponse - The affected (deleted) resource attributes assignments in the `attributes` field.
|
|
74
|
+
*/
|
|
75
|
+
async deleteMemberships(accountId, memberships) {
|
|
76
|
+
const attributionHeaders = attributionsService.getAttributionsFromApi();
|
|
77
|
+
try {
|
|
78
|
+
return await this.httpClient.fetch({
|
|
79
|
+
url: {
|
|
80
|
+
appName: constants.APP_NAME,
|
|
81
|
+
path: MembershipsService.API_PATHS.DELETE_RESOURCE_ATTRIBUTES.replace('{accountId}', accountId.toString()),
|
|
82
|
+
},
|
|
83
|
+
method: 'DELETE',
|
|
84
|
+
query: {
|
|
85
|
+
useAStyleRoleId: 'true',
|
|
86
|
+
},
|
|
87
|
+
headers: {
|
|
88
|
+
'Content-Type': 'application/json',
|
|
89
|
+
...attributionHeaders,
|
|
90
|
+
},
|
|
91
|
+
body: JSON.stringify({ memberships }),
|
|
92
|
+
}, this.fetchOptions);
|
|
93
|
+
}
|
|
94
|
+
catch (err) {
|
|
95
|
+
return utils_apiErrorHandler.handleApiError(err, 'authorization', 'deleteMemberships');
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
exports.MembershipsService = MembershipsService;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
type ApiType = 'platform' | 'graph' | 'authorization';
|
|
2
|
+
interface InitializeMetricsOptions {
|
|
3
|
+
serviceName: string;
|
|
4
|
+
host?: string;
|
|
5
|
+
port?: number;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare function initializeMetrics(options: InitializeMetricsOptions): void;
|
|
9
|
+
export declare function recordAuthorizationTiming(apiType: ApiType, duration: number, placement: string): void;
|
|
10
|
+
export declare function recordAuthorizationError(apiType: ApiType, statusCode: number, placement: string): void;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=metrics-service.d.ts.map
|