@mondaydotcomorg/monday-authorization 3.3.1-feature-bashanye-add-membership-create-delete-api-d00c165 → 3.3.1-fix-use-standard-env-var-for-metric-server-host-bd2a88a
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 +4 -125
- package/dist/authorization-service.js +1 -1
- package/dist/esm/authorization-service.mjs +1 -1
- package/dist/esm/index.d.ts +9 -7
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.mjs +14 -8
- package/dist/esm/metrics-service.d.ts +7 -4
- package/dist/esm/metrics-service.d.ts.map +1 -1
- package/dist/esm/metrics-service.mjs +32 -16
- package/dist/esm/utils/api-error-handler.d.ts +1 -1
- package/dist/esm/utils/api-error-handler.d.ts.map +1 -1
- package/dist/esm/utils/api-error-handler.mjs +4 -4
- package/dist/index.d.ts +9 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -9
- package/dist/metrics-service.d.ts +7 -4
- package/dist/metrics-service.d.ts.map +1 -1
- package/dist/metrics-service.js +32 -16
- package/dist/utils/api-error-handler.d.ts +1 -1
- package/dist/utils/api-error-handler.d.ts.map +1 -1
- package/dist/utils/api-error-handler.js +4 -4
- package/package.json +1 -1
- package/src/authorization-service.ts +1 -1
- package/src/index.ts +24 -16
- package/src/metrics-service.ts +43 -21
- package/src/utils/api-error-handler.ts +5 -9
- package/dist/esm/memberships.d.ts +0 -30
- package/dist/esm/memberships.d.ts.map +0 -1
- package/dist/esm/memberships.mjs +0 -98
- package/dist/esm/types/memberships.d.ts +0 -42
- package/dist/esm/types/memberships.d.ts.map +0 -1
- package/dist/esm/types/memberships.mjs +0 -1
- package/dist/memberships.d.ts +0 -30
- package/dist/memberships.d.ts.map +0 -1
- package/dist/memberships.js +0 -100
- package/dist/types/memberships.d.ts +0 -42
- package/dist/types/memberships.d.ts.map +0 -1
- package/dist/types/memberships.js +0 -1
- package/src/memberships.ts +0 -111
- package/src/types/memberships.ts +0 -47
package/src/index.ts
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
import { MondayFetchOptions } from '@mondaydotcomorg/monday-fetch';
|
|
2
2
|
import { setPrometheus } from './prometheus-service';
|
|
3
3
|
import { setIgniteClient, setRedisClient, setRequestFetchOptions } from './authorization-service';
|
|
4
|
-
import { initializeMetrics } from './metrics-service';
|
|
4
|
+
import { initializeMetrics, MetricsClient } from './metrics-service';
|
|
5
5
|
import * as TestKit from './testKit';
|
|
6
6
|
|
|
7
|
+
interface MetricsInitOptions {
|
|
8
|
+
client?: MetricsClient;
|
|
9
|
+
serviceName?: string;
|
|
10
|
+
host?: string;
|
|
11
|
+
port?: number;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
7
15
|
export interface InitOptions {
|
|
8
16
|
prometheus?: any;
|
|
9
17
|
mondayFetchOptions?: MondayFetchOptions;
|
|
10
18
|
redisClient?: any;
|
|
11
19
|
grantedFeatureRedisExpirationInSeconds?: number;
|
|
12
|
-
metrics?:
|
|
13
|
-
serviceName?: string;
|
|
14
|
-
host?: string;
|
|
15
|
-
port?: number;
|
|
16
|
-
disabled?: boolean;
|
|
17
|
-
};
|
|
20
|
+
metrics?: MetricsInitOptions;
|
|
18
21
|
}
|
|
19
22
|
|
|
20
23
|
export async function init(options: InitOptions = {}) {
|
|
@@ -22,14 +25,20 @@ export async function init(options: InitOptions = {}) {
|
|
|
22
25
|
setPrometheus(options.prometheus);
|
|
23
26
|
}
|
|
24
27
|
|
|
25
|
-
|
|
26
|
-
options.metrics
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
if (options.metrics) {
|
|
29
|
+
if (options.metrics.client) {
|
|
30
|
+
initializeMetrics({ client: options.metrics.client });
|
|
31
|
+
} else {
|
|
32
|
+
const resolvedDisabled =
|
|
33
|
+
options.metrics.disabled ?? ['test', 'development'].includes((process.env.NODE_ENV ?? '').toLowerCase());
|
|
34
|
+
initializeMetrics({
|
|
35
|
+
serviceName: options.metrics.serviceName ?? process.env.APP_NAME ?? 'authorization-sdk',
|
|
36
|
+
host: options.metrics.host,
|
|
37
|
+
port: options.metrics.port,
|
|
38
|
+
disabled: resolvedDisabled,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
33
42
|
|
|
34
43
|
if (options.mondayFetchOptions) {
|
|
35
44
|
setRequestFetchOptions(options.mondayFetchOptions);
|
|
@@ -50,7 +59,6 @@ export {
|
|
|
50
59
|
export { AuthorizationService, AuthorizeResponse } from './authorization-service';
|
|
51
60
|
export { AuthorizationAttributesService } from './authorization-attributes-service';
|
|
52
61
|
export { RolesService } from './roles-service';
|
|
53
|
-
export { MembershipsService } from './memberships';
|
|
54
62
|
export { AuthorizationObject, Resource, BaseRequest, ResourceGetter, ContextGetter } from './types/general';
|
|
55
63
|
export {
|
|
56
64
|
Translation,
|
package/src/metrics-service.ts
CHANGED
|
@@ -1,29 +1,37 @@
|
|
|
1
1
|
import { Metric } from '@mondaydotcomorg/monday-observability-kit';
|
|
2
2
|
import { logger } from './authorization-internal-service';
|
|
3
3
|
|
|
4
|
-
type ApiType = 'platform' | 'graph'
|
|
4
|
+
type ApiType = 'platform' | 'graph';
|
|
5
|
+
|
|
6
|
+
export type MetricsClient = Pick<typeof Metric, 'distribution' | 'increment'>;
|
|
5
7
|
|
|
6
8
|
interface InitializeMetricsOptions {
|
|
7
|
-
|
|
9
|
+
client?: MetricsClient;
|
|
10
|
+
serviceName?: string;
|
|
8
11
|
host?: string;
|
|
9
12
|
port?: number;
|
|
10
13
|
disabled?: boolean;
|
|
11
14
|
}
|
|
12
15
|
|
|
13
|
-
let
|
|
16
|
+
let metricsClient: MetricsClient | null = null;
|
|
14
17
|
|
|
15
18
|
export function initializeMetrics(options: InitializeMetricsOptions): void {
|
|
16
|
-
if (
|
|
19
|
+
if (metricsClient) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (options.client) {
|
|
24
|
+
metricsClient = options.client;
|
|
17
25
|
return;
|
|
18
26
|
}
|
|
19
27
|
|
|
20
28
|
const { serviceName } = options;
|
|
21
29
|
if (!serviceName) {
|
|
22
|
-
logger.warn({ tag: '
|
|
30
|
+
logger.warn({ tag: 'monday-authorization-sdk' }, 'Metrics initialization skipped: serviceName is missing');
|
|
23
31
|
return;
|
|
24
32
|
}
|
|
25
33
|
|
|
26
|
-
const resolvedHost = options.host ?? process.env.
|
|
34
|
+
const resolvedHost = options.host ?? process.env.HOST_IP ?? 'localhost';
|
|
27
35
|
const envPort = process.env.DOGSTATSD_PORT ? Number(process.env.DOGSTATSD_PORT) : undefined;
|
|
28
36
|
const resolvedPort = options.port ?? (Number.isFinite(envPort ?? NaN) ? envPort : undefined) ?? 8125;
|
|
29
37
|
const resolvedDisabled =
|
|
@@ -36,36 +44,50 @@ export function initializeMetrics(options: InitializeMetricsOptions): void {
|
|
|
36
44
|
port: resolvedPort,
|
|
37
45
|
disabled: resolvedDisabled,
|
|
38
46
|
});
|
|
39
|
-
|
|
47
|
+
metricsClient = Metric;
|
|
40
48
|
} catch (error) {
|
|
41
|
-
logger.warn({ tag: '
|
|
49
|
+
logger.warn({ tag: 'monday-authorization-sdk', error }, 'Failed to initialize metrics');
|
|
42
50
|
}
|
|
43
51
|
}
|
|
44
52
|
|
|
45
|
-
export function recordAuthorizationTiming(apiType: ApiType, duration: number
|
|
46
|
-
if (!
|
|
53
|
+
export function recordAuthorizationTiming(apiType: ApiType, duration: number): void {
|
|
54
|
+
if (!metricsClient) {
|
|
47
55
|
return;
|
|
48
56
|
}
|
|
49
57
|
|
|
50
58
|
try {
|
|
51
|
-
|
|
52
|
-
} catch {
|
|
53
|
-
|
|
59
|
+
metricsClient.distribution(`authorization.authorizationCheck.${apiType}.duration`, duration);
|
|
60
|
+
} catch (error) {
|
|
61
|
+
logger.warn(
|
|
62
|
+
{
|
|
63
|
+
tag: 'monday-authorization-sdk',
|
|
64
|
+
metric: 'authorizationCheckDuration',
|
|
65
|
+
apiType,
|
|
66
|
+
duration,
|
|
67
|
+
error,
|
|
68
|
+
},
|
|
69
|
+
'Failed to emit authorization timing metric'
|
|
70
|
+
);
|
|
54
71
|
}
|
|
55
72
|
}
|
|
56
73
|
|
|
57
|
-
export function recordAuthorizationError(apiType: ApiType, statusCode: number
|
|
58
|
-
if (!
|
|
74
|
+
export function recordAuthorizationError(apiType: ApiType, statusCode: number): void {
|
|
75
|
+
if (!metricsClient) {
|
|
59
76
|
return;
|
|
60
77
|
}
|
|
61
78
|
|
|
62
79
|
try {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
80
|
+
metricsClient.increment(`authorization.authorizationCheck.${apiType}.error`, { statusCode: String(statusCode) }, 1);
|
|
81
|
+
} catch (error) {
|
|
82
|
+
logger.warn(
|
|
83
|
+
{
|
|
84
|
+
tag: 'monday-authorization-sdk',
|
|
85
|
+
metric: 'authorizationCheckError',
|
|
86
|
+
apiType,
|
|
87
|
+
statusCode,
|
|
88
|
+
error,
|
|
89
|
+
},
|
|
90
|
+
'Failed to emit authorization error metric'
|
|
67
91
|
);
|
|
68
|
-
} catch {
|
|
69
|
-
// ignore metric emission failures
|
|
70
92
|
}
|
|
71
93
|
}
|
|
@@ -2,24 +2,20 @@ import { HttpFetcherError } from '@mondaydotcomorg/monday-fetch-api';
|
|
|
2
2
|
import { AuthorizationInternalService, logger } from '../authorization-internal-service';
|
|
3
3
|
import { recordAuthorizationError } from '../metrics-service';
|
|
4
4
|
|
|
5
|
-
export function handleApiError(
|
|
6
|
-
err: unknown,
|
|
7
|
-
apiType: 'platform' | 'graph' | 'authorization',
|
|
8
|
-
placement: string
|
|
9
|
-
): never {
|
|
5
|
+
export function handleApiError(err: unknown, apiType: 'platform' | 'graph', placement: string): never {
|
|
10
6
|
if (err instanceof HttpFetcherError) {
|
|
11
7
|
logger.error(
|
|
12
8
|
{ tag: `${apiType}-api`, status: err.status, error: err.message },
|
|
13
|
-
`${apiType.charAt(0).toUpperCase() + apiType.slice(1)} API
|
|
9
|
+
`${apiType.charAt(0).toUpperCase() + apiType.slice(1)} API authorization request failed`
|
|
14
10
|
);
|
|
15
|
-
recordAuthorizationError(apiType, err.status
|
|
11
|
+
recordAuthorizationError(apiType, err.status);
|
|
16
12
|
AuthorizationInternalService.throwOnHttpError(err.status, placement);
|
|
17
13
|
} else {
|
|
18
14
|
logger.error(
|
|
19
15
|
{ tag: `${apiType}-api`, error: err instanceof Error ? err.message : String(err) },
|
|
20
|
-
`${apiType.charAt(0).toUpperCase() + apiType.slice(1)} API
|
|
16
|
+
`${apiType.charAt(0).toUpperCase() + apiType.slice(1)} API authorization request failed`
|
|
21
17
|
);
|
|
22
|
-
recordAuthorizationError(apiType, 500
|
|
18
|
+
recordAuthorizationError(apiType, 500);
|
|
23
19
|
throw err;
|
|
24
20
|
}
|
|
25
21
|
}
|
|
@@ -1,30 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/dist/esm/memberships.mjs
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
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 };
|
|
@@ -1,42 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|
package/dist/memberships.d.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/dist/memberships.js
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
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;
|
|
@@ -1,42 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|