@mondaydotcomorg/monday-authorization 3.5.1 → 3.5.3-feat-shaime-support-entity-attributes-in-authorization-sdk-127d99a
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-ms-service.d.ts +90 -0
- package/dist/authorization-attributes-ms-service.d.ts.map +1 -0
- package/dist/authorization-attributes-ms-service.js +351 -0
- package/dist/authorization-attributes-service.d.ts +26 -47
- package/dist/authorization-attributes-service.d.ts.map +1 -1
- package/dist/authorization-attributes-service.js +33 -171
- package/dist/authorization-attributes-sns-service.d.ts +90 -0
- package/dist/authorization-attributes-sns-service.d.ts.map +1 -0
- package/dist/authorization-attributes-sns-service.js +217 -0
- 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 +18 -0
- package/dist/base-attribute-assignment.d.ts.map +1 -0
- package/dist/base-attribute-assignment.js +43 -0
- package/dist/constants/sns.d.ts +12 -2
- package/dist/constants/sns.d.ts.map +1 -1
- package/dist/constants/sns.js +22 -2
- package/dist/entity-attribute-assignment.d.ts +14 -0
- package/dist/entity-attribute-assignment.d.ts.map +1 -0
- package/dist/entity-attribute-assignment.js +24 -0
- package/dist/entity-attributes-constants.d.ts +7 -0
- package/dist/entity-attributes-constants.d.ts.map +1 -0
- package/dist/entity-attributes-constants.js +9 -0
- package/dist/errors/argument-error.d.ts +4 -0
- package/dist/errors/argument-error.d.ts.map +1 -0
- package/dist/errors/argument-error.js +11 -0
- package/dist/esm/authorization-attributes-ms-service.d.ts +90 -0
- package/dist/esm/authorization-attributes-ms-service.d.ts.map +1 -0
- package/dist/esm/authorization-attributes-ms-service.mjs +349 -0
- package/dist/esm/authorization-attributes-service.d.ts +26 -47
- package/dist/esm/authorization-attributes-service.d.ts.map +1 -1
- package/dist/esm/authorization-attributes-service.mjs +33 -167
- package/dist/esm/authorization-attributes-sns-service.d.ts +90 -0
- package/dist/esm/authorization-attributes-sns-service.d.ts.map +1 -0
- package/dist/esm/authorization-attributes-sns-service.mjs +211 -0
- 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 +18 -0
- package/dist/esm/base-attribute-assignment.d.ts.map +1 -0
- package/dist/esm/base-attribute-assignment.mjs +41 -0
- package/dist/esm/constants/sns.d.ts +12 -2
- package/dist/esm/constants/sns.d.ts.map +1 -1
- package/dist/esm/constants/sns.mjs +17 -3
- package/dist/esm/entity-attribute-assignment.d.ts +14 -0
- package/dist/esm/entity-attribute-assignment.d.ts.map +1 -0
- package/dist/esm/entity-attribute-assignment.mjs +22 -0
- package/dist/esm/entity-attributes-constants.d.ts +7 -0
- package/dist/esm/entity-attributes-constants.d.ts.map +1 -0
- package/dist/esm/entity-attributes-constants.mjs +7 -0
- package/dist/esm/errors/argument-error.d.ts +4 -0
- package/dist/esm/errors/argument-error.d.ts.map +1 -0
- package/dist/esm/errors/argument-error.mjs +9 -0
- package/dist/esm/index.d.ts +9 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.mjs +7 -0
- package/dist/esm/prometheus-service.d.ts +1 -2
- package/dist/esm/prometheus-service.d.ts.map +1 -1
- package/dist/esm/resource-attribute-assignment.d.ts +24 -0
- package/dist/esm/resource-attribute-assignment.d.ts.map +1 -0
- package/dist/esm/resource-attribute-assignment.mjs +34 -0
- package/dist/esm/resource-attributes-constants.d.ts +15 -0
- package/dist/esm/resource-attributes-constants.d.ts.map +1 -0
- package/dist/esm/resource-attributes-constants.mjs +25 -0
- 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 +27 -12
- package/dist/esm/types/authorization-attributes-contracts.d.ts.map +1 -1
- package/dist/esm/types/authorization-attributes-contracts.mjs +6 -6
- package/dist/esm/types/authorization-attributes-service.interface.d.ts +56 -0
- package/dist/esm/types/authorization-attributes-service.interface.d.ts.map +1 -0
- package/dist/esm/types/authorization-attributes-service.interface.mjs +1 -0
- package/dist/esm/types/general.d.ts +1 -2
- package/dist/esm/types/general.d.ts.map +1 -1
- package/dist/esm/utils/validation.d.ts +45 -0
- package/dist/esm/utils/validation.d.ts.map +1 -0
- package/dist/esm/utils/validation.mjs +117 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -0
- package/dist/prometheus-service.d.ts +1 -2
- package/dist/prometheus-service.d.ts.map +1 -1
- package/dist/resource-attribute-assignment.d.ts +24 -0
- package/dist/resource-attribute-assignment.d.ts.map +1 -0
- package/dist/resource-attribute-assignment.js +36 -0
- package/dist/resource-attributes-constants.d.ts +15 -0
- package/dist/resource-attributes-constants.d.ts.map +1 -0
- package/dist/resource-attributes-constants.js +28 -0
- 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 +27 -12
- package/dist/types/authorization-attributes-contracts.d.ts.map +1 -1
- package/dist/types/authorization-attributes-contracts.js +5 -5
- package/dist/types/authorization-attributes-service.interface.d.ts +56 -0
- package/dist/types/authorization-attributes-service.interface.d.ts.map +1 -0
- package/dist/types/authorization-attributes-service.interface.js +1 -0
- package/dist/types/general.d.ts +1 -2
- package/dist/types/general.d.ts.map +1 -1
- package/dist/utils/validation.d.ts +45 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +119 -0
- package/package.json +3 -2
- package/src/authorization-attributes-ms-service.ts +513 -0
- package/src/authorization-attributes-service.ts +35 -222
- package/src/authorization-attributes-sns-service.ts +312 -0
- package/src/authorization-middleware.ts +2 -2
- package/src/authorization-service.ts +4 -4
- package/src/base-attribute-assignment.ts +55 -0
- package/src/constants/sns.ts +19 -2
- package/src/entity-attribute-assignment.ts +21 -0
- package/src/entity-attributes-constants.ts +7 -0
- package/src/errors/argument-error.ts +7 -0
- package/src/index.ts +9 -0
- package/src/prometheus-service.ts +1 -3
- package/src/resource-attribute-assignment.ts +43 -0
- package/src/resource-attributes-constants.ts +35 -0
- package/src/testKit/index.ts +5 -5
- package/src/types/authorization-attributes-contracts.ts +36 -11
- package/src/types/authorization-attributes-service.interface.ts +101 -0
- package/src/types/general.ts +3 -2
- package/src/utils/validation.ts +114 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { ValidationUtils } from './utils/validation';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Base class for attribute assignments (Resource or Entity)
|
|
5
|
+
* Provides common validation and functionality
|
|
6
|
+
*/
|
|
7
|
+
export abstract class BaseAttributeAssignment<TId extends number, TType extends string> {
|
|
8
|
+
public readonly id: TId;
|
|
9
|
+
public readonly type: TType;
|
|
10
|
+
public readonly attributeKey: string;
|
|
11
|
+
public readonly attributeValue: string;
|
|
12
|
+
|
|
13
|
+
constructor(
|
|
14
|
+
id: TId,
|
|
15
|
+
type: string,
|
|
16
|
+
attributeKey: string,
|
|
17
|
+
attributeValue: string,
|
|
18
|
+
validTypes: readonly string[],
|
|
19
|
+
idFieldName: string,
|
|
20
|
+
typeFieldName: string
|
|
21
|
+
) {
|
|
22
|
+
// Validate id
|
|
23
|
+
ValidationUtils.validateInteger(id, idFieldName);
|
|
24
|
+
|
|
25
|
+
// Validate type
|
|
26
|
+
this.type = ValidationUtils.validateEnum(type, validTypes as readonly TType[], typeFieldName) as TType;
|
|
27
|
+
|
|
28
|
+
// Validate attributeKey
|
|
29
|
+
ValidationUtils.validateString(attributeKey, 'attributeKey');
|
|
30
|
+
|
|
31
|
+
// Validate attributeValue
|
|
32
|
+
ValidationUtils.validateString(attributeValue, 'attributeValue');
|
|
33
|
+
|
|
34
|
+
this.id = id;
|
|
35
|
+
this.attributeKey = attributeKey;
|
|
36
|
+
this.attributeValue = attributeValue;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Compares two assignments for equality
|
|
41
|
+
* @param other Another assignment instance
|
|
42
|
+
* @returns true if all properties are equal
|
|
43
|
+
*/
|
|
44
|
+
equals(other: BaseAttributeAssignment<TId, TType>): boolean {
|
|
45
|
+
if (!(other instanceof this.constructor)) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
return (
|
|
49
|
+
this.id === other.id &&
|
|
50
|
+
this.type === other.type &&
|
|
51
|
+
this.attributeKey === other.attributeKey &&
|
|
52
|
+
this.attributeValue === other.attributeValue
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
}
|
package/src/constants/sns.ts
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
1
|
+
export enum SnsTopicType {
|
|
2
|
+
RESOURCE = 'resource',
|
|
3
|
+
ENTITY = 'entity',
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
// Resource SNS constants
|
|
7
|
+
export const RESOURCE_SNS_ARN_ENV_VAR_NAME = 'SHARED_AUTHORIZATION_SNS_ENDPOINT_RESOURCE_ATTRIBUTES';
|
|
8
|
+
export const RESOURCE_SNS_DEV_TEST_NAME =
|
|
3
9
|
'arn:aws:sns:us-east-1:000000000000:monday-authorization-resource-attributes-sns-local';
|
|
10
|
+
|
|
11
|
+
// Entity SNS constants
|
|
12
|
+
export const ENTITY_SNS_ARN_ENV_VAR_NAME = 'SHARED_AUTHORIZATION_SNS_ENDPOINT_ENTITY_ATTRIBUTES';
|
|
13
|
+
export const ENTITY_SNS_DEV_TEST_NAME =
|
|
14
|
+
'arn:aws:sns:us-east-1:000000000000:monday-authorization-entity-attributes-sns-local';
|
|
4
15
|
export const RESOURCE_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND = 'resourceAttributeModification';
|
|
16
|
+
export const ENTITY_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND = 'entityAttributeModification';
|
|
5
17
|
export const ASYNC_RESOURCE_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE = 100;
|
|
18
|
+
export const ASYNC_ENTITY_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE = 100;
|
|
19
|
+
|
|
20
|
+
// Legacy exports for backward compatibility
|
|
21
|
+
export const SNS_ARN_ENV_VAR_NAME = RESOURCE_SNS_ARN_ENV_VAR_NAME;
|
|
22
|
+
export const SNS_DEV_TEST_NAME = RESOURCE_SNS_DEV_TEST_NAME;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ENTITY_TYPES, EntityType } from './entity-attributes-constants';
|
|
2
|
+
import { BaseAttributeAssignment } from './base-attribute-assignment';
|
|
3
|
+
|
|
4
|
+
export class EntityAttributeAssignment extends BaseAttributeAssignment<number, EntityType> {
|
|
5
|
+
public readonly entityId: number;
|
|
6
|
+
public readonly entityType: EntityType;
|
|
7
|
+
|
|
8
|
+
constructor(entityId: number, entityType: string, attributeKey: string, attributeValue: string) {
|
|
9
|
+
super(entityId, entityType, attributeKey, attributeValue, Object.values(ENTITY_TYPES), 'entityId', 'entityType');
|
|
10
|
+
this.entityId = entityId;
|
|
11
|
+
this.entityType = this.type;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Compares two assignments for equality
|
|
15
|
+
* @param other Another EntityAttributeAssignment instance
|
|
16
|
+
* @returns true if all properties are equal
|
|
17
|
+
*/
|
|
18
|
+
equals(other: EntityAttributeAssignment): boolean {
|
|
19
|
+
return super.equals(other);
|
|
20
|
+
}
|
|
21
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -58,6 +58,15 @@ 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';
|
|
61
70
|
export { RolesService } from './roles-service';
|
|
62
71
|
export { MembershipsService } from './memberships';
|
|
63
72
|
export { AuthorizationObject, Resource, BaseRequest, ResourceGetter, ContextGetter } from './types/general';
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { Action } from './types/general';
|
|
2
|
-
|
|
3
1
|
let prometheus: any = null;
|
|
4
2
|
let authorizationCheckResponseTimeMetric: any = null;
|
|
5
3
|
|
|
@@ -36,7 +34,7 @@ export function getMetricsManager() {
|
|
|
36
34
|
|
|
37
35
|
export function sendAuthorizationCheckResponseTimeMetric(
|
|
38
36
|
resourceType: string,
|
|
39
|
-
action:
|
|
37
|
+
action: string,
|
|
40
38
|
isAuthorized: boolean,
|
|
41
39
|
responseStatus: number,
|
|
42
40
|
time: number
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { RESOURCE_TYPES, ResourceType } from './resource-attributes-constants';
|
|
2
|
+
import { BaseAttributeAssignment } from './base-attribute-assignment';
|
|
3
|
+
|
|
4
|
+
export class ResourceAttributeAssignment extends BaseAttributeAssignment<number, ResourceType> {
|
|
5
|
+
public readonly resourceId: number;
|
|
6
|
+
public readonly resourceType: ResourceType;
|
|
7
|
+
|
|
8
|
+
constructor(resourceId: number, resourceType: string, attributeKey: string, attributeValue: string) {
|
|
9
|
+
super(
|
|
10
|
+
resourceId,
|
|
11
|
+
resourceType,
|
|
12
|
+
attributeKey,
|
|
13
|
+
attributeValue,
|
|
14
|
+
Object.values(RESOURCE_TYPES),
|
|
15
|
+
'resourceId',
|
|
16
|
+
'resourceType'
|
|
17
|
+
);
|
|
18
|
+
this.resourceId = resourceId;
|
|
19
|
+
this.resourceType = this.type;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Converts the assignment to a plain object with camelCase keys
|
|
24
|
+
* @returns Plain object with camelCase keys: { resourceId, resourceType, key, value }
|
|
25
|
+
*/
|
|
26
|
+
toPlainObject(): { resourceId: number; resourceType: string; key: string; value: string } {
|
|
27
|
+
return {
|
|
28
|
+
resourceId: this.resourceId,
|
|
29
|
+
resourceType: this.resourceType,
|
|
30
|
+
key: this.attributeKey,
|
|
31
|
+
value: this.attributeValue,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Compares two assignments for equality
|
|
37
|
+
* @param other Another ResourceAttributeAssignment instance
|
|
38
|
+
* @returns true if all properties are equal
|
|
39
|
+
*/
|
|
40
|
+
equals(other: ResourceAttributeAssignment): boolean {
|
|
41
|
+
return super.equals(other);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export const RESOURCE_ATTRIBUTES_CONSTANTS = {
|
|
2
|
+
ACCOUNT_RESOURCE_ATTRIBUTES: {
|
|
3
|
+
ENABLE_MEMBERS_INVITE_FROM_NON_AUTH_DOMAIN: 'enable_members_invite_from_non_auth_domain',
|
|
4
|
+
},
|
|
5
|
+
WORKSPACE_RESOURCE_ATTRIBUTES: {
|
|
6
|
+
IS_DEFAULT_WORKSPACE: 'is_default_workspace',
|
|
7
|
+
},
|
|
8
|
+
BOARD_RESOURCE_ATTRIBUTES: {
|
|
9
|
+
IS_SYNCABLE_CHILD_ENTITY: 'is_syncable_child_entity',
|
|
10
|
+
SYSTEM_ENTITY_TYPE: 'system_entity_type',
|
|
11
|
+
},
|
|
12
|
+
} as const;
|
|
13
|
+
|
|
14
|
+
export type ResourceType =
|
|
15
|
+
| 'account'
|
|
16
|
+
| 'account_product'
|
|
17
|
+
| 'workspace'
|
|
18
|
+
| 'board'
|
|
19
|
+
| 'item'
|
|
20
|
+
| 'team'
|
|
21
|
+
| 'overview'
|
|
22
|
+
| 'document'
|
|
23
|
+
| 'crm';
|
|
24
|
+
|
|
25
|
+
export const RESOURCE_TYPES = {
|
|
26
|
+
ACCOUNT: 'account',
|
|
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>;
|
package/src/testKit/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { 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: string;
|
|
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: string) => {
|
|
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: string) => {
|
|
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: string,
|
|
50
50
|
resourceGetter: ResourceGetter,
|
|
51
51
|
contextGetter?: ContextGetter
|
|
52
52
|
) => {
|
|
@@ -1,33 +1,58 @@
|
|
|
1
1
|
import { Resource } from './general';
|
|
2
|
+
import type { EntityType } from '../entity-attributes-constants';
|
|
3
|
+
import type { ResourceType } from '../resource-attributes-constants';
|
|
2
4
|
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
export type { EntityType, ResourceType };
|
|
6
|
+
|
|
7
|
+
interface AttributeAssignment {
|
|
6
8
|
key: string;
|
|
7
9
|
value: string;
|
|
8
10
|
}
|
|
9
11
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
+
// Resource Attribute Assignment - matching API contract
|
|
13
|
+
export interface ResourceAttributeAssignment extends AttributeAssignment {
|
|
14
|
+
resourceId: number;
|
|
15
|
+
resourceType: ResourceType;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Entity Attribute Assignment - matching API contract
|
|
19
|
+
// Note: For validation, use the EntityAttributeAssignment class from '../entity-attribute-assignment'
|
|
20
|
+
export interface EntityAttributeAssignment extends AttributeAssignment {
|
|
21
|
+
entityId: number;
|
|
22
|
+
entityType: EntityType;
|
|
12
23
|
}
|
|
13
24
|
|
|
25
|
+
// Legacy types for backward compatibility
|
|
14
26
|
export interface ResourceAttributeDelete {
|
|
15
27
|
resourceType: Resource['type'];
|
|
16
28
|
resourceId: Resource['id'];
|
|
17
29
|
key: string;
|
|
18
30
|
}
|
|
19
31
|
|
|
20
|
-
export
|
|
32
|
+
export interface EntityAttributeDelete {
|
|
33
|
+
entityType: EntityType;
|
|
34
|
+
entityId: number;
|
|
35
|
+
key: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export enum AttributeOperation {
|
|
21
39
|
UPSERT = 'upsert',
|
|
22
40
|
DELETE = 'delete',
|
|
23
41
|
}
|
|
24
42
|
|
|
25
|
-
|
|
26
|
-
|
|
43
|
+
// Response types
|
|
44
|
+
export interface ResourceAttributeResponse {
|
|
45
|
+
attributes: ResourceAttributeAssignment[];
|
|
27
46
|
}
|
|
28
47
|
|
|
29
|
-
interface
|
|
30
|
-
|
|
48
|
+
export interface EntityAttributeResponse {
|
|
49
|
+
attributes: EntityAttributeAssignment[];
|
|
31
50
|
}
|
|
32
51
|
|
|
33
|
-
export
|
|
52
|
+
export interface ResourceAttributeOperation extends ResourceAttributeAssignment {
|
|
53
|
+
operationType: AttributeOperation;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface EntityAttributeOperation extends EntityAttributeAssignment {
|
|
57
|
+
operationType: AttributeOperation;
|
|
58
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ResourceAttributeAssignment as ResourceAttributeAssignmentContract,
|
|
3
|
+
EntityAttributeAssignment as EntityAttributeAssignmentContract,
|
|
4
|
+
EntityType,
|
|
5
|
+
ResourceAttributeOperation,
|
|
6
|
+
EntityAttributeOperation,
|
|
7
|
+
} from './authorization-attributes-contracts';
|
|
8
|
+
import { ResourceAttributeAssignment } from '../resource-attribute-assignment';
|
|
9
|
+
import { EntityAttributeAssignment } from '../entity-attribute-assignment';
|
|
10
|
+
import { Resource } from './general';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Resource type compatible with both MS and SNS services
|
|
14
|
+
*/
|
|
15
|
+
export interface CompatibleResource {
|
|
16
|
+
resourceType?: string;
|
|
17
|
+
resourceId?: number;
|
|
18
|
+
type?: string;
|
|
19
|
+
id?: number;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Interface for authorization attributes operations.
|
|
24
|
+
* Both MS (direct) and SNS (async) services implement this interface.
|
|
25
|
+
*/
|
|
26
|
+
export interface IAuthorizationAttributesService {
|
|
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
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Deletes resource attributes.
|
|
41
|
+
* For MS service: returns Promise<void>
|
|
42
|
+
* For SNS service: requires appName and callerActionIdentifier, returns Promise<ResourceAttributesOperation[]>
|
|
43
|
+
*/
|
|
44
|
+
deleteResourceAttributes(
|
|
45
|
+
accountId: number,
|
|
46
|
+
resource: CompatibleResource | Resource,
|
|
47
|
+
attributeKeys: string[],
|
|
48
|
+
appName?: string,
|
|
49
|
+
callerActionIdentifier?: string
|
|
50
|
+
): Promise<void | ResourceAttributeOperation[]>;
|
|
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[]>;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Deletes entity attributes.
|
|
66
|
+
* For MS service: returns Promise<void>
|
|
67
|
+
* For SNS service: requires appName and callerActionIdentifier, returns Promise<EntityAttributesOperation[]>
|
|
68
|
+
*/
|
|
69
|
+
deleteEntityAttributes(
|
|
70
|
+
accountId: number,
|
|
71
|
+
entityType: EntityType | string,
|
|
72
|
+
entityId: number,
|
|
73
|
+
attributeKeys: string[],
|
|
74
|
+
appName?: string,
|
|
75
|
+
callerActionIdentifier?: string
|
|
76
|
+
): Promise<void | EntityAttributeOperation[]>;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Updates resource attributes (batch operations).
|
|
80
|
+
* For MS service: may throw error or delegate to upsert/delete
|
|
81
|
+
* For SNS service: returns Promise<ResourceAttributesOperation[]>
|
|
82
|
+
*/
|
|
83
|
+
updateResourceAttributes(
|
|
84
|
+
accountId: number,
|
|
85
|
+
appName: string,
|
|
86
|
+
callerActionIdentifier: string,
|
|
87
|
+
resourceAttributeOperations: ResourceAttributeOperation[]
|
|
88
|
+
): Promise<ResourceAttributeOperation[]>;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Updates entity attributes (batch operations).
|
|
92
|
+
* For MS service: may throw error or delegate to upsert/delete
|
|
93
|
+
* For SNS service: returns Promise<EntityAttributesOperation[]>
|
|
94
|
+
*/
|
|
95
|
+
updateEntityAttributes(
|
|
96
|
+
accountId: number,
|
|
97
|
+
appName: string,
|
|
98
|
+
callerActionIdentifier: string,
|
|
99
|
+
entityAttributeOperations: EntityAttributeOperation[]
|
|
100
|
+
): Promise<EntityAttributeOperation[]>;
|
|
101
|
+
}
|
package/src/types/general.ts
CHANGED
|
@@ -5,16 +5,17 @@ export interface Resource {
|
|
|
5
5
|
type: string;
|
|
6
6
|
wrapperData?: object;
|
|
7
7
|
}
|
|
8
|
-
|
|
8
|
+
|
|
9
9
|
export interface Context {
|
|
10
10
|
accountId: number;
|
|
11
11
|
userId: number;
|
|
12
12
|
}
|
|
13
|
+
|
|
13
14
|
export interface AuthorizationObject {
|
|
14
15
|
resource_id?: Resource['id'];
|
|
15
16
|
resource_type: Resource['type'];
|
|
16
17
|
wrapper_data?: Resource['wrapperData'];
|
|
17
|
-
action:
|
|
18
|
+
action: string;
|
|
18
19
|
}
|
|
19
20
|
export interface AuthorizationParams {
|
|
20
21
|
authorizationObjects: AuthorizationObject[];
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { ArgumentError } from '../errors/argument-error';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Utility class for common validation operations using Zod
|
|
6
|
+
*/
|
|
7
|
+
export class ValidationUtils {
|
|
8
|
+
/**
|
|
9
|
+
* Validates that a value is an integer
|
|
10
|
+
* @param value The value to validate
|
|
11
|
+
* @param fieldName The name of the field for error messages
|
|
12
|
+
* @throws ArgumentError if value is not an integer
|
|
13
|
+
*/
|
|
14
|
+
static validateInteger(value: any, fieldName: string): void {
|
|
15
|
+
const schema = z.number().int();
|
|
16
|
+
try {
|
|
17
|
+
schema.parse(value);
|
|
18
|
+
} catch (error) {
|
|
19
|
+
if (error instanceof z.ZodError) {
|
|
20
|
+
throw new ArgumentError(`${fieldName} must be an integer, got: ${value}`);
|
|
21
|
+
}
|
|
22
|
+
throw error;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Validates that a value is a non-empty string
|
|
28
|
+
* @param value The value to validate
|
|
29
|
+
* @param fieldName The name of the field for error messages
|
|
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;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Validates that a value is an array and optionally checks minimum length
|
|
49
|
+
* @param value The value to validate
|
|
50
|
+
* @param fieldName The name of the field for error messages
|
|
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;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Validates that a value is one of the allowed enum values
|
|
72
|
+
* @param value The value to validate
|
|
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
|
|
77
|
+
*/
|
|
78
|
+
static validateEnum<T extends string>(value: string, validValues: readonly T[], fieldName: string): T {
|
|
79
|
+
const schema = z.enum(validValues as [T, ...T[]]);
|
|
80
|
+
try {
|
|
81
|
+
return schema.parse(value) as T;
|
|
82
|
+
} catch (error) {
|
|
83
|
+
if (error instanceof z.ZodError) {
|
|
84
|
+
throw new ArgumentError(`${fieldName} must be one of [${validValues.join(', ')}], got: ${value}`);
|
|
85
|
+
}
|
|
86
|
+
throw error;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Validates that all items in an array are strings
|
|
92
|
+
* @param value Array to validate
|
|
93
|
+
* @param fieldName The name of the field for error messages
|
|
94
|
+
* @throws ArgumentError if any item is not a string
|
|
95
|
+
*/
|
|
96
|
+
static validateStringArray(value: any[], fieldName: string): void {
|
|
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;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|