@mondaydotcomorg/monday-authorization 3.5.3-feat-shaime-support-entity-attributes-in-authorization-sdk-a77c130 → 3.6.0-feat-shaime-support-entity-attributes-1-4c8e283
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/authorization-attributes-service.d.ts +47 -26
- package/dist/authorization-attributes-service.d.ts.map +1 -1
- package/dist/authorization-attributes-service.js +172 -33
- package/dist/authorization-middleware.d.ts +2 -2
- package/dist/authorization-middleware.d.ts.map +1 -1
- package/dist/authorization-service.d.ts +3 -3
- package/dist/authorization-service.d.ts.map +1 -1
- package/dist/base-attribute-assignment.d.ts +6 -5
- package/dist/base-attribute-assignment.d.ts.map +1 -1
- package/dist/base-attribute-assignment.js +8 -17
- package/dist/constants/sns.d.ts +2 -12
- package/dist/constants/sns.d.ts.map +1 -1
- package/dist/constants/sns.js +2 -22
- package/dist/entity-attribute-assignment.d.ts +4 -8
- package/dist/entity-attribute-assignment.d.ts.map +1 -1
- package/dist/entity-attribute-assignment.js +5 -4
- package/dist/entity-attributes-constants.d.ts +6 -6
- package/dist/entity-attributes-constants.d.ts.map +1 -1
- package/dist/entity-attributes-constants.js +7 -5
- package/dist/errors/argument-error.d.ts.map +1 -1
- package/dist/errors/argument-error.js +0 -1
- package/dist/esm/authorization-attributes-service.d.ts +47 -26
- package/dist/esm/authorization-attributes-service.d.ts.map +1 -1
- package/dist/esm/authorization-attributes-service.mjs +168 -33
- package/dist/esm/authorization-middleware.d.ts +2 -2
- package/dist/esm/authorization-middleware.d.ts.map +1 -1
- package/dist/esm/authorization-service.d.ts +3 -3
- package/dist/esm/authorization-service.d.ts.map +1 -1
- package/dist/esm/base-attribute-assignment.d.ts +6 -5
- package/dist/esm/base-attribute-assignment.d.ts.map +1 -1
- package/dist/esm/base-attribute-assignment.mjs +4 -17
- package/dist/esm/constants/sns.d.ts +2 -12
- package/dist/esm/constants/sns.d.ts.map +1 -1
- package/dist/esm/constants/sns.mjs +3 -17
- package/dist/esm/entity-attribute-assignment.d.ts +4 -8
- package/dist/esm/entity-attribute-assignment.d.ts.map +1 -1
- package/dist/esm/entity-attribute-assignment.mjs +5 -4
- package/dist/esm/entity-attributes-constants.d.ts +6 -6
- package/dist/esm/entity-attributes-constants.d.ts.map +1 -1
- package/dist/esm/entity-attributes-constants.mjs +8 -6
- package/dist/esm/errors/argument-error.d.ts.map +1 -1
- package/dist/esm/errors/argument-error.mjs +0 -1
- package/dist/esm/index.d.ts +0 -9
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.mjs +0 -7
- package/dist/esm/prometheus-service.d.ts +2 -1
- package/dist/esm/prometheus-service.d.ts.map +1 -1
- package/dist/esm/resource-attribute-assignment.d.ts +4 -8
- package/dist/esm/resource-attribute-assignment.d.ts.map +1 -1
- package/dist/esm/resource-attribute-assignment.mjs +3 -2
- package/dist/esm/resource-attributes-constants.d.ts +21 -11
- package/dist/esm/resource-attributes-constants.d.ts.map +1 -1
- package/dist/esm/resource-attributes-constants.mjs +17 -14
- package/dist/esm/testKit/index.d.ts +4 -4
- package/dist/esm/testKit/index.d.ts.map +1 -1
- package/dist/esm/types/authorization-attributes-contracts.d.ts +5 -4
- package/dist/esm/types/authorization-attributes-contracts.d.ts.map +1 -1
- package/dist/esm/types/authorization-attributes-service.interface.d.ts +7 -20
- package/dist/esm/types/authorization-attributes-service.interface.d.ts.map +1 -1
- package/dist/esm/types/general.d.ts +2 -1
- package/dist/esm/types/general.d.ts.map +1 -1
- package/dist/esm/utils/assigment-schema.d.ts +29 -0
- package/dist/esm/utils/assigment-schema.d.ts.map +1 -0
- package/dist/esm/utils/assigment-schema.mjs +29 -0
- package/dist/esm/utils/validation.d.ts +13 -38
- package/dist/esm/utils/validation.d.ts.map +1 -1
- package/dist/esm/utils/validation.mjs +38 -97
- package/dist/index.d.ts +0 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -15
- package/dist/prometheus-service.d.ts +2 -1
- package/dist/prometheus-service.d.ts.map +1 -1
- package/dist/resource-attribute-assignment.d.ts +4 -8
- package/dist/resource-attribute-assignment.d.ts.map +1 -1
- package/dist/resource-attribute-assignment.js +3 -2
- package/dist/resource-attributes-constants.d.ts +21 -11
- package/dist/resource-attributes-constants.d.ts.map +1 -1
- package/dist/resource-attributes-constants.js +16 -13
- package/dist/testKit/index.d.ts +4 -4
- package/dist/testKit/index.d.ts.map +1 -1
- package/dist/types/authorization-attributes-contracts.d.ts +5 -4
- package/dist/types/authorization-attributes-contracts.d.ts.map +1 -1
- package/dist/types/authorization-attributes-service.interface.d.ts +7 -20
- package/dist/types/authorization-attributes-service.interface.d.ts.map +1 -1
- package/dist/types/general.d.ts +2 -1
- package/dist/types/general.d.ts.map +1 -1
- package/dist/utils/assigment-schema.d.ts +29 -0
- package/dist/utils/assigment-schema.d.ts.map +1 -0
- package/dist/utils/assigment-schema.js +36 -0
- package/dist/utils/validation.d.ts +13 -38
- package/dist/utils/validation.d.ts.map +1 -1
- package/dist/utils/validation.js +42 -97
- package/package.json +3 -3
- package/src/authorization-attributes-service.ts +223 -35
- package/src/authorization-middleware.ts +2 -2
- package/src/authorization-service.ts +4 -4
- package/src/base-attribute-assignment.ts +10 -35
- package/src/constants/sns.ts +2 -19
- package/src/entity-attribute-assignment.ts +9 -6
- package/src/entity-attributes-constants.ts +6 -6
- package/src/errors/argument-error.ts +0 -1
- package/src/index.ts +0 -9
- package/src/prometheus-service.ts +3 -1
- package/src/resource-attribute-assignment.ts +11 -13
- package/src/resource-attributes-constants.ts +15 -23
- package/src/testKit/index.ts +5 -5
- package/src/types/authorization-attributes-contracts.ts +5 -5
- package/src/types/authorization-attributes-service.interface.ts +12 -38
- package/src/types/general.ts +2 -3
- package/src/utils/assigment-schema.ts +29 -0
- package/src/utils/validation.ts +41 -92
- package/dist/authorization-attributes-ms-service.d.ts +0 -90
- package/dist/authorization-attributes-ms-service.d.ts.map +0 -1
- package/dist/authorization-attributes-ms-service.js +0 -352
- package/dist/authorization-attributes-sns-service.d.ts +0 -90
- package/dist/authorization-attributes-sns-service.d.ts.map +0 -1
- package/dist/authorization-attributes-sns-service.js +0 -217
- package/dist/esm/authorization-attributes-ms-service.d.ts +0 -90
- package/dist/esm/authorization-attributes-ms-service.d.ts.map +0 -1
- package/dist/esm/authorization-attributes-ms-service.mjs +0 -350
- package/dist/esm/authorization-attributes-sns-service.d.ts +0 -90
- package/dist/esm/authorization-attributes-sns-service.d.ts.map +0 -1
- package/dist/esm/authorization-attributes-sns-service.mjs +0 -211
- package/src/authorization-attributes-ms-service.ts +0 -514
- package/src/authorization-attributes-sns-service.ts +0 -312
package/src/index.ts
CHANGED
|
@@ -58,15 +58,6 @@ export {
|
|
|
58
58
|
} from './authorization-middleware';
|
|
59
59
|
export { AuthorizationService, AuthorizeResponse } from './authorization-service';
|
|
60
60
|
export { AuthorizationAttributesService } from './authorization-attributes-service';
|
|
61
|
-
export { AuthorizationAttributesSnsService } from './authorization-attributes-sns-service';
|
|
62
|
-
export { AuthorizationAttributesMsService } from './authorization-attributes-ms-service';
|
|
63
|
-
export { IAuthorizationAttributesService } from './types/authorization-attributes-service.interface';
|
|
64
|
-
export { ResourceAttributeAssignment } from './resource-attribute-assignment';
|
|
65
|
-
export { RESOURCE_TYPES, RESOURCE_ATTRIBUTES_CONSTANTS } from './resource-attributes-constants';
|
|
66
|
-
export { EntityAttributeAssignment } from './entity-attribute-assignment';
|
|
67
|
-
export { ENTITY_TYPES } from './entity-attributes-constants';
|
|
68
|
-
export { ArgumentError } from './errors/argument-error';
|
|
69
|
-
export type { EntityType } from './entity-attributes-constants';
|
|
70
61
|
export { RolesService } from './roles-service';
|
|
71
62
|
export { MembershipsService } from './memberships';
|
|
72
63
|
export { AuthorizationObject, Resource, BaseRequest, ResourceGetter, ContextGetter } from './types/general';
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Action } from './types/general';
|
|
2
|
+
|
|
1
3
|
let prometheus: any = null;
|
|
2
4
|
let authorizationCheckResponseTimeMetric: any = null;
|
|
3
5
|
|
|
@@ -34,7 +36,7 @@ export function getMetricsManager() {
|
|
|
34
36
|
|
|
35
37
|
export function sendAuthorizationCheckResponseTimeMetric(
|
|
36
38
|
resourceType: string,
|
|
37
|
-
action:
|
|
39
|
+
action: Action,
|
|
38
40
|
isAuthorized: boolean,
|
|
39
41
|
responseStatus: number,
|
|
40
42
|
time: number
|
|
@@ -1,25 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ResourceType } from './resource-attributes-constants';
|
|
2
2
|
import { BaseAttributeAssignment } from './base-attribute-assignment';
|
|
3
|
+
import { ResourceAttributeAssignment as ResourceAttributeAssignmentContract } from './types/authorization-attributes-contracts';
|
|
4
|
+
import { ValidationUtils } from './utils/validation';
|
|
3
5
|
|
|
4
|
-
export class ResourceAttributeAssignment extends BaseAttributeAssignment<
|
|
6
|
+
export class ResourceAttributeAssignment extends BaseAttributeAssignment<
|
|
7
|
+
ResourceType,
|
|
8
|
+
ResourceAttributeAssignmentContract
|
|
9
|
+
> {
|
|
5
10
|
public readonly resourceId: number;
|
|
6
11
|
public readonly resourceType: ResourceType;
|
|
7
12
|
|
|
8
|
-
constructor(resourceId: number, resourceType:
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
resourceType,
|
|
12
|
-
attributeKey,
|
|
13
|
-
attributeValue,
|
|
14
|
-
Object.values(RESOURCE_TYPES),
|
|
15
|
-
'resourceId',
|
|
16
|
-
'resourceType'
|
|
17
|
-
);
|
|
13
|
+
constructor(resourceId: number, resourceType: ResourceType, attributeKey: string, attributeValue: string) {
|
|
14
|
+
ValidationUtils.validateResourceAssignment({ resourceId, resourceType, key: attributeKey, value: attributeValue });
|
|
15
|
+
super(resourceId, resourceType, attributeKey, attributeValue);
|
|
18
16
|
this.resourceId = resourceId;
|
|
19
17
|
this.resourceType = this.type;
|
|
20
18
|
}
|
|
21
19
|
|
|
22
|
-
toDataTransferObject() {
|
|
20
|
+
toDataTransferObject(): ResourceAttributeAssignmentContract {
|
|
23
21
|
return {
|
|
24
22
|
resourceId: this.resourceId,
|
|
25
23
|
resourceType: this.resourceType,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const RESOURCE_ATTRIBUTES_CONSTANTS = {
|
|
1
|
+
export const RESOURCE_ATTRIBUTES_CONSTANTS = Object.freeze({
|
|
2
2
|
ACCOUNT_RESOURCE_ATTRIBUTES: {
|
|
3
3
|
ENABLE_MEMBERS_INVITE_FROM_NON_AUTH_DOMAIN: 'enable_members_invite_from_non_auth_domain',
|
|
4
4
|
},
|
|
@@ -9,27 +9,19 @@ export const RESOURCE_ATTRIBUTES_CONSTANTS = {
|
|
|
9
9
|
IS_SYNCABLE_CHILD_ENTITY: 'is_syncable_child_entity',
|
|
10
10
|
SYSTEM_ENTITY_TYPE: 'system_entity_type',
|
|
11
11
|
},
|
|
12
|
-
}
|
|
12
|
+
});
|
|
13
13
|
|
|
14
|
-
export
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
14
|
+
export enum ResourceType {
|
|
15
|
+
Account = 'account',
|
|
16
|
+
AccountProduct = 'account_product',
|
|
17
|
+
Workspace = 'workspace',
|
|
18
|
+
Board = 'board',
|
|
19
|
+
Item = 'item',
|
|
20
|
+
Team = 'team',
|
|
21
|
+
Overview = 'overview',
|
|
22
|
+
Document = 'document',
|
|
23
|
+
Crm = 'crm',
|
|
24
|
+
}
|
|
24
25
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
ACCOUNT_PRODUCT: 'account_product',
|
|
28
|
-
WORKSPACE: 'workspace',
|
|
29
|
-
BOARD: 'board',
|
|
30
|
-
ITEM: 'item',
|
|
31
|
-
TEAM: 'team',
|
|
32
|
-
OVERVIEW: 'overview',
|
|
33
|
-
DOCUMENT: 'document',
|
|
34
|
-
CRM: 'crm',
|
|
35
|
-
} as Record<string, ResourceType>;
|
|
26
|
+
// Define the array of strings and use 'as const' to make its contents literal types
|
|
27
|
+
export const RESOURCE_TYPES = Object.freeze(Object.values(ResourceType));
|
package/src/testKit/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseRequest, BaseResponse, ContextGetter, Resource, ResourceGetter } from '../types/general';
|
|
1
|
+
import { Action, BaseRequest, BaseResponse, ContextGetter, Resource, ResourceGetter } from '../types/general';
|
|
2
2
|
import { defaultContextGetter } from '../authorization-middleware';
|
|
3
3
|
import { AuthorizationInternalService } from '../authorization-internal-service';
|
|
4
4
|
import type { NextFunction } from 'express';
|
|
@@ -7,11 +7,11 @@ export type TestPermittedAction = {
|
|
|
7
7
|
accountId: number;
|
|
8
8
|
userId: number;
|
|
9
9
|
resources: Resource[];
|
|
10
|
-
action:
|
|
10
|
+
action: Action;
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
let testPermittedActions: TestPermittedAction[] = [];
|
|
14
|
-
export const addTestPermittedAction = (accountId: number, userId: number, resources: Resource[], action:
|
|
14
|
+
export const addTestPermittedAction = (accountId: number, userId: number, resources: Resource[], action: Action) => {
|
|
15
15
|
testPermittedActions.push({ accountId, userId, resources, action });
|
|
16
16
|
};
|
|
17
17
|
|
|
@@ -19,7 +19,7 @@ export const clearTestPermittedActions = () => {
|
|
|
19
19
|
testPermittedActions = [];
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
-
const isActionAuthorized = (accountId: number, userId: number, resources: Resource[], action:
|
|
22
|
+
const isActionAuthorized = (accountId: number, userId: number, resources: Resource[], action: Action) => {
|
|
23
23
|
// If no resources to check, deny access
|
|
24
24
|
if (resources.length === 0) {
|
|
25
25
|
return { isAuthorized: false };
|
|
@@ -46,7 +46,7 @@ const isActionAuthorized = (accountId: number, userId: number, resources: Resour
|
|
|
46
46
|
};
|
|
47
47
|
|
|
48
48
|
export const getTestAuthorizationMiddleware = (
|
|
49
|
-
action:
|
|
49
|
+
action: Action,
|
|
50
50
|
resourceGetter: ResourceGetter,
|
|
51
51
|
contextGetter?: ContextGetter
|
|
52
52
|
) => {
|
|
@@ -2,9 +2,7 @@ import { Resource } from './general';
|
|
|
2
2
|
import type { EntityType } from '../entity-attributes-constants';
|
|
3
3
|
import type { ResourceType } from '../resource-attributes-constants';
|
|
4
4
|
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
interface AttributeAssignment {
|
|
5
|
+
export interface AttributeAssignment {
|
|
8
6
|
key: string;
|
|
9
7
|
value: string;
|
|
10
8
|
}
|
|
@@ -49,10 +47,12 @@ export interface EntityAttributeResponse {
|
|
|
49
47
|
attributes: EntityAttributeAssignment[];
|
|
50
48
|
}
|
|
51
49
|
|
|
52
|
-
export interface
|
|
50
|
+
export interface ResourceAttributeUpsertOperation extends ResourceAttributeAssignment {
|
|
53
51
|
operationType: AttributeOperation;
|
|
54
52
|
}
|
|
53
|
+
export type ResourceAttributeDeleteOperation = Omit<ResourceAttributeUpsertOperation, 'value'>;
|
|
55
54
|
|
|
56
|
-
export interface
|
|
55
|
+
export interface EntityAttributeUpsertOperation extends EntityAttributeAssignment {
|
|
57
56
|
operationType: AttributeOperation;
|
|
58
57
|
}
|
|
58
|
+
export type EntityAttributeDeleteOperation = Omit<EntityAttributeUpsertOperation, 'value'>;
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
+
import { EntityType } from '../entity-attributes-constants';
|
|
1
2
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
EntityAttributeOperation,
|
|
3
|
+
ResourceAttributeDeleteOperation,
|
|
4
|
+
EntityAttributeDeleteOperation,
|
|
5
|
+
ResourceAttributeUpsertOperation,
|
|
6
|
+
EntityAttributeUpsertOperation,
|
|
7
7
|
} from './authorization-attributes-contracts';
|
|
8
|
-
import { ResourceAttributeAssignment } from '../resource-attribute-assignment';
|
|
9
|
-
import { EntityAttributeAssignment } from '../entity-attribute-assignment';
|
|
10
8
|
import { Resource } from './general';
|
|
11
9
|
|
|
12
10
|
/**
|
|
@@ -23,19 +21,7 @@ export interface CompatibleResource {
|
|
|
23
21
|
* Interface for authorization attributes operations.
|
|
24
22
|
* Both MS (direct) and SNS (async) services implement this interface.
|
|
25
23
|
*/
|
|
26
|
-
export interface
|
|
27
|
-
/**
|
|
28
|
-
* Upserts resource attributes.
|
|
29
|
-
* For MS service: returns Promise<void>
|
|
30
|
-
* For SNS service: requires appName and callerActionIdentifier, returns Promise<ResourceAttributesOperation[]>
|
|
31
|
-
*/
|
|
32
|
-
upsertResourceAttributes(
|
|
33
|
-
accountId: number,
|
|
34
|
-
resourceAttributeAssignments: ResourceAttributeAssignment[] | ResourceAttributeAssignmentContract[],
|
|
35
|
-
appName?: string,
|
|
36
|
-
callerActionIdentifier?: string
|
|
37
|
-
): Promise<void | ResourceAttributeOperation[]>;
|
|
38
|
-
|
|
24
|
+
export interface AuthorizationAttributesService {
|
|
39
25
|
/**
|
|
40
26
|
* Deletes resource attributes.
|
|
41
27
|
* For MS service: returns Promise<void>
|
|
@@ -47,19 +33,7 @@ export interface IAuthorizationAttributesService {
|
|
|
47
33
|
attributeKeys: string[],
|
|
48
34
|
appName?: string,
|
|
49
35
|
callerActionIdentifier?: string
|
|
50
|
-
): Promise<void |
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Upserts entity attributes.
|
|
54
|
-
* For MS service: returns Promise<void>
|
|
55
|
-
* For SNS service: requires appName and callerActionIdentifier, returns Promise<EntityAttributesOperation[]>
|
|
56
|
-
*/
|
|
57
|
-
upsertEntityAttributes(
|
|
58
|
-
accountId: number,
|
|
59
|
-
entityAttributeAssignments: EntityAttributeAssignment[] | EntityAttributeAssignmentContract[],
|
|
60
|
-
appName?: string,
|
|
61
|
-
callerActionIdentifier?: string
|
|
62
|
-
): Promise<void | EntityAttributeOperation[]>;
|
|
36
|
+
): Promise<void | ResourceAttributeDeleteOperation[]>;
|
|
63
37
|
|
|
64
38
|
/**
|
|
65
39
|
* Deletes entity attributes.
|
|
@@ -73,7 +47,7 @@ export interface IAuthorizationAttributesService {
|
|
|
73
47
|
attributeKeys: string[],
|
|
74
48
|
appName?: string,
|
|
75
49
|
callerActionIdentifier?: string
|
|
76
|
-
): Promise<void |
|
|
50
|
+
): Promise<void | EntityAttributeDeleteOperation[]>;
|
|
77
51
|
|
|
78
52
|
/**
|
|
79
53
|
* Updates resource attributes (batch operations).
|
|
@@ -84,8 +58,8 @@ export interface IAuthorizationAttributesService {
|
|
|
84
58
|
accountId: number,
|
|
85
59
|
appName: string,
|
|
86
60
|
callerActionIdentifier: string,
|
|
87
|
-
resourceAttributeOperations:
|
|
88
|
-
): Promise<
|
|
61
|
+
resourceAttributeOperations: ResourceAttributeUpsertOperation[]
|
|
62
|
+
): Promise<ResourceAttributeUpsertOperation[]>;
|
|
89
63
|
|
|
90
64
|
/**
|
|
91
65
|
* Updates entity attributes (batch operations).
|
|
@@ -96,6 +70,6 @@ export interface IAuthorizationAttributesService {
|
|
|
96
70
|
accountId: number,
|
|
97
71
|
appName: string,
|
|
98
72
|
callerActionIdentifier: string,
|
|
99
|
-
entityAttributeOperations:
|
|
100
|
-
): Promise<
|
|
73
|
+
entityAttributeOperations: EntityAttributeUpsertOperation[]
|
|
74
|
+
): Promise<EntityAttributeUpsertOperation[]>;
|
|
101
75
|
}
|
package/src/types/general.ts
CHANGED
|
@@ -5,17 +5,16 @@ export interface Resource {
|
|
|
5
5
|
type: string;
|
|
6
6
|
wrapperData?: object;
|
|
7
7
|
}
|
|
8
|
-
|
|
8
|
+
export type Action = string;
|
|
9
9
|
export interface Context {
|
|
10
10
|
accountId: number;
|
|
11
11
|
userId: number;
|
|
12
12
|
}
|
|
13
|
-
|
|
14
13
|
export interface AuthorizationObject {
|
|
15
14
|
resource_id?: Resource['id'];
|
|
16
15
|
resource_type: Resource['type'];
|
|
17
16
|
wrapper_data?: Resource['wrapperData'];
|
|
18
|
-
action:
|
|
17
|
+
action: Action;
|
|
19
18
|
}
|
|
20
19
|
export interface AuthorizationParams {
|
|
21
20
|
authorizationObjects: AuthorizationObject[];
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import Ajv from 'ajv';
|
|
2
|
+
import { EntityType } from '../entity-attributes-constants';
|
|
3
|
+
import { ResourceType } from '../resource-attributes-constants';
|
|
4
|
+
|
|
5
|
+
const ajv = new Ajv({ allErrors: true });
|
|
6
|
+
|
|
7
|
+
export const entityAssignmentSchema = ajv.compile({
|
|
8
|
+
type: 'object',
|
|
9
|
+
properties: {
|
|
10
|
+
entityId: { type: 'number', multipleOf: 1 },
|
|
11
|
+
entityType: { type: 'string', enum: Object.values(EntityType) },
|
|
12
|
+
key: { type: 'string', minLength: 1 },
|
|
13
|
+
value: { type: 'string', minLength: 1 },
|
|
14
|
+
},
|
|
15
|
+
required: ['entityId', 'entityType', 'attributeKey', 'attributeValue'],
|
|
16
|
+
additionalProperties: false,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export const resourceAssignmentSchema = ajv.compile({
|
|
20
|
+
type: 'object',
|
|
21
|
+
properties: {
|
|
22
|
+
id: { type: 'number', multipleOf: 1 },
|
|
23
|
+
type: { type: 'string', enum: Object.values(ResourceType) },
|
|
24
|
+
key: { type: 'string', minLength: 1 },
|
|
25
|
+
value: { type: 'string', minLength: 1 },
|
|
26
|
+
},
|
|
27
|
+
required: ['id', 'type', 'attributeKey', 'attributeValue'],
|
|
28
|
+
additionalProperties: false,
|
|
29
|
+
});
|
package/src/utils/validation.ts
CHANGED
|
@@ -1,114 +1,63 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import Ajv, { ValidateFunction } from 'ajv';
|
|
2
2
|
import { ArgumentError } from '../errors/argument-error';
|
|
3
|
+
import { ResourceAttributeAssignment, EntityAttributeAssignment } from '../types/authorization-attributes-contracts';
|
|
4
|
+
import { entityAssignmentSchema, resourceAssignmentSchema } from './assigment-schema';
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
|
-
* Utility class for common validation operations using
|
|
7
|
+
* Utility class for common validation operations using AJV
|
|
6
8
|
*/
|
|
7
9
|
export class ValidationUtils {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
throw error;
|
|
10
|
+
private static ajv = new Ajv({ allErrors: true });
|
|
11
|
+
|
|
12
|
+
private static integerValidator: ValidateFunction = this.ajv.compile({ type: 'number', multipleOf: 1 });
|
|
13
|
+
private static stringValidator: ValidateFunction = this.ajv.compile({ type: 'string', minLength: 1 });
|
|
14
|
+
private static stringArrayValidator: ValidateFunction = this.ajv.compile({
|
|
15
|
+
type: 'array',
|
|
16
|
+
items: { type: 'string' },
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
public static validateInteger(value: number): void {
|
|
20
|
+
const valid = this.integerValidator(value);
|
|
21
|
+
if (!valid) {
|
|
22
|
+
throw new ArgumentError('Invalid integer');
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
* @throws ArgumentError if value is not a string or is empty
|
|
31
|
-
*/
|
|
32
|
-
static validateString(value: any, fieldName: string): void {
|
|
33
|
-
const schema = z.string().min(1);
|
|
34
|
-
try {
|
|
35
|
-
schema.parse(value);
|
|
36
|
-
} catch (error) {
|
|
37
|
-
if (error instanceof z.ZodError) {
|
|
38
|
-
if (typeof value !== 'string') {
|
|
39
|
-
throw new ArgumentError(`${fieldName} must be a string, got: ${typeof value}`);
|
|
40
|
-
}
|
|
41
|
-
throw new ArgumentError(`${fieldName} must be a non-empty string`);
|
|
42
|
-
}
|
|
43
|
-
throw error;
|
|
26
|
+
public static validateString(value: string): void {
|
|
27
|
+
const valid = this.stringValidator(value);
|
|
28
|
+
if (!valid) {
|
|
29
|
+
throw new ArgumentError('Invalid string');
|
|
44
30
|
}
|
|
45
31
|
}
|
|
46
32
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
* @param minLength Minimum required length (default: 0)
|
|
52
|
-
* @returns The validated array
|
|
53
|
-
* @throws ArgumentError if value is not an array or doesn't meet minimum length
|
|
54
|
-
*/
|
|
55
|
-
static validateArray<T>(value: any, fieldName: string, minLength = 0): T[] {
|
|
56
|
-
const schema = z.array(z.any()).min(minLength);
|
|
57
|
-
try {
|
|
58
|
-
return schema.parse(value) as T[];
|
|
59
|
-
} catch (error) {
|
|
60
|
-
if (error instanceof z.ZodError) {
|
|
61
|
-
if (!Array.isArray(value)) {
|
|
62
|
-
throw new ArgumentError(`${fieldName} must be an array`);
|
|
63
|
-
}
|
|
64
|
-
throw new ArgumentError(`${fieldName} must have at least ${minLength} items`);
|
|
65
|
-
}
|
|
66
|
-
throw error;
|
|
33
|
+
public static validateStringArray(value: string[]): void {
|
|
34
|
+
const valid = this.stringArrayValidator(value);
|
|
35
|
+
if (!valid) {
|
|
36
|
+
throw new ArgumentError('Invalid string array');
|
|
67
37
|
}
|
|
68
38
|
}
|
|
69
39
|
|
|
70
40
|
/**
|
|
71
|
-
* Validates
|
|
72
|
-
*
|
|
73
|
-
* @param validValues Array of valid values
|
|
74
|
-
* @param fieldName The name of the field for error messages
|
|
75
|
-
* @returns The validated value as the enum type
|
|
76
|
-
* @throws ArgumentError if value is not in validValues
|
|
41
|
+
* Validates an attribute assignment object using a single AJV schema.
|
|
42
|
+
* Preserves legacy error messages for each field.
|
|
77
43
|
*/
|
|
78
|
-
static
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
throw error;
|
|
44
|
+
static validateResourceAssignment(resource: ResourceAttributeAssignment): void {
|
|
45
|
+
const valid = resourceAssignmentSchema(resource);
|
|
46
|
+
if (!valid) {
|
|
47
|
+
const errorMessages = (resourceAssignmentSchema.errors || [])
|
|
48
|
+
.map(err => err.message || 'validation failed')
|
|
49
|
+
.join(', ');
|
|
50
|
+
throw new ArgumentError(`Invalid resource attribute assignment: ${errorMessages}`);
|
|
87
51
|
}
|
|
88
52
|
}
|
|
89
53
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
const schema = z.array(z.string());
|
|
98
|
-
try {
|
|
99
|
-
schema.parse(value);
|
|
100
|
-
} catch (error) {
|
|
101
|
-
if (error instanceof z.ZodError) {
|
|
102
|
-
const zodError = error as z.ZodError;
|
|
103
|
-
const firstError = zodError.issues[0];
|
|
104
|
-
// Check if it's an array item validation error
|
|
105
|
-
if (firstError.path.length > 0 && typeof firstError.path[0] === 'number') {
|
|
106
|
-
const index = firstError.path[0];
|
|
107
|
-
throw new ArgumentError(`All ${fieldName} must be strings, but item at index ${index} is not`);
|
|
108
|
-
}
|
|
109
|
-
throw new ArgumentError(`${fieldName} must be an array`);
|
|
110
|
-
}
|
|
111
|
-
throw error;
|
|
54
|
+
static validateEntityAssignment(entity: EntityAttributeAssignment): void {
|
|
55
|
+
const valid = entityAssignmentSchema(entity);
|
|
56
|
+
if (!valid) {
|
|
57
|
+
const errorMessages = (entityAssignmentSchema.errors || [])
|
|
58
|
+
.map(err => err.message || 'validation failed')
|
|
59
|
+
.join(', ');
|
|
60
|
+
throw new ArgumentError(`Invalid entity attribute assignment: ${errorMessages}`);
|
|
112
61
|
}
|
|
113
62
|
}
|
|
114
63
|
}
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { ResourceAttributeAssignment } from './resource-attribute-assignment';
|
|
2
|
-
import { EntityAttributeAssignment } from './entity-attribute-assignment';
|
|
3
|
-
import { EntityType, ResourceAttributeOperation, EntityAttributeOperation } from './types/authorization-attributes-contracts';
|
|
4
|
-
import { IAuthorizationAttributesService } from './types/authorization-attributes-service.interface';
|
|
5
|
-
import { Resource } from './types/general';
|
|
6
|
-
/**
|
|
7
|
-
* Service class for managing resource attributes in the authorization microservice.
|
|
8
|
-
* Provides synchronous HTTP operations to create/update and delete attributes on resources.
|
|
9
|
-
*/
|
|
10
|
-
export declare class AuthorizationAttributesMsService implements IAuthorizationAttributesService {
|
|
11
|
-
private static LOG_TAG;
|
|
12
|
-
private static httpClient;
|
|
13
|
-
/**
|
|
14
|
-
* Creates or updates resource attributes synchronously.
|
|
15
|
-
* @param accountId The account ID
|
|
16
|
-
* @param resourceAttributeAssignments Array of ResourceAttributeAssignment objects
|
|
17
|
-
* @returns Promise<void>
|
|
18
|
-
*/
|
|
19
|
-
upsertResourceAttributes(accountId: number, resourceAttributeAssignments: ResourceAttributeAssignment[], _appName?: string, _callerActionIdentifier?: string): Promise<void>;
|
|
20
|
-
/**
|
|
21
|
-
* Deletes specific attributes from a resource synchronously.
|
|
22
|
-
* @param accountId The account ID
|
|
23
|
-
* @param resource Object with resourceType (string) and resourceId (number)
|
|
24
|
-
* @param attributeKeys Array of attribute key strings to delete
|
|
25
|
-
* @returns Promise<void>
|
|
26
|
-
*/
|
|
27
|
-
deleteResourceAttributes(accountId: number, resource: Resource, attributeKeys: string[], _appName?: string, _callerActionIdentifier?: string): Promise<void>;
|
|
28
|
-
/**
|
|
29
|
-
* Creates or updates entity attributes synchronously.
|
|
30
|
-
* @param accountId The account ID
|
|
31
|
-
* @param entityAttributeAssignments Array of EntityAttributeAssignment objects
|
|
32
|
-
* @returns Promise<void>
|
|
33
|
-
*/
|
|
34
|
-
upsertEntityAttributes(accountId: number, entityAttributeAssignments: EntityAttributeAssignment[], _appName?: string, _callerActionIdentifier?: string): Promise<void>;
|
|
35
|
-
/**
|
|
36
|
-
* Deletes specific attributes from an entity synchronously.
|
|
37
|
-
* @param accountId The account ID
|
|
38
|
-
* @param entityType The entity type
|
|
39
|
-
* @param entityId The entity ID
|
|
40
|
-
* @param attributeKeys Array of attribute key strings to delete
|
|
41
|
-
* @returns Promise<void>
|
|
42
|
-
*/
|
|
43
|
-
deleteEntityAttributes(accountId: number, entityType: EntityType | string, entityId: number, attributeKeys: string[], _appName?: string, _callerActionIdentifier?: string): Promise<void>;
|
|
44
|
-
/**
|
|
45
|
-
* Updates resource attributes (batch operations).
|
|
46
|
-
* Note: MS service does not support batch operations directly.
|
|
47
|
-
* This method processes operations sequentially using upsert/delete methods.
|
|
48
|
-
* @param accountId The account ID
|
|
49
|
-
* @param appName App name (required for interface compatibility, but not used in MS service)
|
|
50
|
-
* @param callerActionIdentifier Action identifier (required for interface compatibility, but not used in MS service)
|
|
51
|
-
* @param resourceAttributeOperations Array of operations to perform
|
|
52
|
-
* @returns Promise<ResourceAttributesOperation[]> Array of processed operations
|
|
53
|
-
*/
|
|
54
|
-
updateResourceAttributes(accountId: number, _appName: string, _callerActionIdentifier: string, resourceAttributeOperations: ResourceAttributeOperation[]): Promise<ResourceAttributeOperation[]>;
|
|
55
|
-
/**
|
|
56
|
-
* Updates entity attributes (batch operations).
|
|
57
|
-
* Note: MS service does not support batch operations directly.
|
|
58
|
-
* This method processes operations sequentially using upsert/delete methods.
|
|
59
|
-
* @param accountId The account ID
|
|
60
|
-
* @param appName App name (required for interface compatibility, but not used in MS service)
|
|
61
|
-
* @param callerActionIdentifier Action identifier (required for interface compatibility, but not used in MS service)
|
|
62
|
-
* @param entityAttributeOperations Array of operations to perform
|
|
63
|
-
* @returns Promise<EntityAttributesOperation[]> Array of processed operations
|
|
64
|
-
*/
|
|
65
|
-
updateEntityAttributes(accountId: number, _appName: string, _callerActionIdentifier: string, entityAttributeOperations: EntityAttributeOperation[]): Promise<EntityAttributeOperation[]>;
|
|
66
|
-
/**
|
|
67
|
-
* Replaces path template parameters with actual values
|
|
68
|
-
* @param template Path template with placeholders like {accountId}
|
|
69
|
-
* @param params Object with parameter names and values
|
|
70
|
-
* @returns Path with all placeholders replaced
|
|
71
|
-
*/
|
|
72
|
-
private static replacePathParams;
|
|
73
|
-
/**
|
|
74
|
-
* Generic helper for executing delete requests
|
|
75
|
-
*/
|
|
76
|
-
private static executeDeleteRequest;
|
|
77
|
-
/**
|
|
78
|
-
* Gets request headers including Authorization, Content-Type, and optional attribution headers
|
|
79
|
-
*/
|
|
80
|
-
private static getRequestHeaders;
|
|
81
|
-
/**
|
|
82
|
-
* Validates that all messages are instances of the specified message class
|
|
83
|
-
*/
|
|
84
|
-
private static validateMessages;
|
|
85
|
-
/**
|
|
86
|
-
* Generic helper for executing upsert requests
|
|
87
|
-
*/
|
|
88
|
-
private static executeUpsertRequest;
|
|
89
|
-
}
|
|
90
|
-
//# sourceMappingURL=authorization-attributes-ms-service.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"authorization-attributes-ms-service.d.ts","sourceRoot":"","sources":["../src/authorization-attributes-ms-service.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,2BAA2B,EAAE,MAAM,iCAAiC,CAAC;AAC9E,OAAO,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAC;AAC1E,OAAO,EAEL,UAAU,EACV,0BAA0B,EAC1B,wBAAwB,EACzB,MAAM,4CAA4C,CAAC;AAMpD,OAAO,EAAE,+BAA+B,EAAE,MAAM,oDAAoD,CAAC;AACrG,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAW3C;;;GAGG;AACH,qBAAa,gCAAiC,YAAW,+BAA+B;IACtF,OAAO,CAAC,MAAM,CAAC,OAAO,CAAiC;IACvD,OAAO,CAAC,MAAM,CAAC,UAAU,CAAqD;IAC9E;;;;;OAKG;IACG,wBAAwB,CAC5B,SAAS,EAAE,MAAM,EACjB,4BAA4B,EAAE,2BAA2B,EAAE,EAC3D,QAAQ,CAAC,EAAE,MAAM,EACjB,uBAAuB,CAAC,EAAE,MAAM,GAC/B,OAAO,CAAC,IAAI,CAAC;IAYhB;;;;;;OAMG;IACG,wBAAwB,CAC5B,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,QAAQ,EAClB,aAAa,EAAE,MAAM,EAAE,EACvB,QAAQ,CAAC,EAAE,MAAM,EACjB,uBAAuB,CAAC,EAAE,MAAM,GAC/B,OAAO,CAAC,IAAI,CAAC;IAyBhB;;;;;OAKG;IACG,sBAAsB,CAC1B,SAAS,EAAE,MAAM,EACjB,0BAA0B,EAAE,yBAAyB,EAAE,EACvD,QAAQ,CAAC,EAAE,MAAM,EACjB,uBAAuB,CAAC,EAAE,MAAM,GAC/B,OAAO,CAAC,IAAI,CAAC;IAYhB;;;;;;;OAOG;IACG,sBAAsB,CAC1B,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,UAAU,GAAG,MAAM,EAC/B,QAAQ,EAAE,MAAM,EAChB,aAAa,EAAE,MAAM,EAAE,EACvB,QAAQ,CAAC,EAAE,MAAM,EACjB,uBAAuB,CAAC,EAAE,MAAM,GAC/B,OAAO,CAAC,IAAI,CAAC;IAoBhB;;;;;;;;;OASG;IACG,wBAAwB,CAC5B,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,uBAAuB,EAAE,MAAM,EAC/B,2BAA2B,EAAE,0BAA0B,EAAE,GACxD,OAAO,CAAC,0BAA0B,EAAE,CAAC;IAoCxC;;;;;;;;;OASG;IACG,sBAAsB,CAC1B,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,uBAAuB,EAAE,MAAM,EAC/B,yBAAyB,EAAE,wBAAwB,EAAE,GACpD,OAAO,CAAC,wBAAwB,EAAE,CAAC;IAiBtC;;;;;OAKG;IACH,OAAO,CAAC,MAAM,CAAC,iBAAiB;IAQhC;;OAEG;mBACkB,oBAAoB;IA0EzC;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,iBAAiB;IA+ChC;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAsD/B;;OAEG;mBACkB,oBAAoB;CA2E1C"}
|