@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
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Action } from './types/general';
|
|
1
2
|
export declare const METRICS: {
|
|
2
3
|
AUTHORIZATION_CHECK: string;
|
|
3
4
|
AUTHORIZATION_CHECKS_PER_REQUEST: string;
|
|
@@ -5,5 +6,5 @@ export declare const METRICS: {
|
|
|
5
6
|
};
|
|
6
7
|
export declare function setPrometheus(customPrometheus: any): void;
|
|
7
8
|
export declare function getMetricsManager(): any;
|
|
8
|
-
export declare function sendAuthorizationCheckResponseTimeMetric(resourceType: string, action:
|
|
9
|
+
export declare function sendAuthorizationCheckResponseTimeMetric(resourceType: string, action: Action, isAuthorized: boolean, responseStatus: number, time: number): void;
|
|
9
10
|
//# sourceMappingURL=prometheus-service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prometheus-service.d.ts","sourceRoot":"","sources":["../../src/prometheus-service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"prometheus-service.d.ts","sourceRoot":"","sources":["../../src/prometheus-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAKzC,eAAO,MAAM,OAAO;;;;CAInB,CAAC;AAQF,wBAAgB,aAAa,CAAC,gBAAgB,KAAA,QAa7C;AAED,wBAAgB,iBAAiB,QAEhC;AAED,wBAAgB,wCAAwC,CACtD,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,OAAO,EACrB,cAAc,EAAE,MAAM,EACtB,IAAI,EAAE,MAAM,QASb"}
|
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
import { ResourceType } from './resource-attributes-constants';
|
|
2
2
|
import { BaseAttributeAssignment } from './base-attribute-assignment';
|
|
3
|
-
|
|
3
|
+
import { ResourceAttributeAssignment as ResourceAttributeAssignmentContract } from './types/authorization-attributes-contracts';
|
|
4
|
+
export declare class ResourceAttributeAssignment extends BaseAttributeAssignment<ResourceType, ResourceAttributeAssignmentContract> {
|
|
4
5
|
readonly resourceId: number;
|
|
5
6
|
readonly resourceType: ResourceType;
|
|
6
|
-
constructor(resourceId: number, resourceType:
|
|
7
|
-
toDataTransferObject():
|
|
8
|
-
resourceId: number;
|
|
9
|
-
resourceType: ResourceType;
|
|
10
|
-
key: string;
|
|
11
|
-
value: string;
|
|
12
|
-
};
|
|
7
|
+
constructor(resourceId: number, resourceType: ResourceType, attributeKey: string, attributeValue: string);
|
|
8
|
+
toDataTransferObject(): ResourceAttributeAssignmentContract;
|
|
13
9
|
/**
|
|
14
10
|
* Compares two assignments for equality
|
|
15
11
|
* @param other Another ResourceAttributeAssignment instance
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource-attribute-assignment.d.ts","sourceRoot":"","sources":["../../src/resource-attribute-assignment.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"resource-attribute-assignment.d.ts","sourceRoot":"","sources":["../../src/resource-attribute-assignment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AACtE,OAAO,EAAE,2BAA2B,IAAI,mCAAmC,EAAE,MAAM,4CAA4C,CAAC;AAGhI,qBAAa,2BAA4B,SAAQ,uBAAuB,CACtE,YAAY,EACZ,mCAAmC,CACpC;IACC,SAAgB,UAAU,EAAE,MAAM,CAAC;IACnC,SAAgB,YAAY,EAAE,YAAY,CAAC;gBAE/B,UAAU,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM;IAOxG,oBAAoB,IAAI,mCAAmC;IAQ3D;;;;OAIG;IACH,MAAM,CAAC,KAAK,EAAE,2BAA2B,GAAG,OAAO;CAGpD"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { RESOURCE_TYPES } from './resource-attributes-constants.mjs';
|
|
2
1
|
import { BaseAttributeAssignment } from './base-attribute-assignment.mjs';
|
|
2
|
+
import { ValidationUtils } from './utils/validation.mjs';
|
|
3
3
|
|
|
4
4
|
class ResourceAttributeAssignment extends BaseAttributeAssignment {
|
|
5
5
|
resourceId;
|
|
6
6
|
resourceType;
|
|
7
7
|
constructor(resourceId, resourceType, attributeKey, attributeValue) {
|
|
8
|
-
|
|
8
|
+
ValidationUtils.validateResourceAssignment({ resourceId, resourceType, key: attributeKey, value: attributeValue });
|
|
9
|
+
super(resourceId, resourceType, attributeKey, attributeValue);
|
|
9
10
|
this.resourceId = resourceId;
|
|
10
11
|
this.resourceType = this.type;
|
|
11
12
|
}
|
|
@@ -1,15 +1,25 @@
|
|
|
1
|
-
export declare const RESOURCE_ATTRIBUTES_CONSTANTS: {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
export declare const RESOURCE_ATTRIBUTES_CONSTANTS: Readonly<{
|
|
2
|
+
ACCOUNT_RESOURCE_ATTRIBUTES: {
|
|
3
|
+
ENABLE_MEMBERS_INVITE_FROM_NON_AUTH_DOMAIN: string;
|
|
4
4
|
};
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
WORKSPACE_RESOURCE_ATTRIBUTES: {
|
|
6
|
+
IS_DEFAULT_WORKSPACE: string;
|
|
7
7
|
};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
BOARD_RESOURCE_ATTRIBUTES: {
|
|
9
|
+
IS_SYNCABLE_CHILD_ENTITY: string;
|
|
10
|
+
SYSTEM_ENTITY_TYPE: string;
|
|
11
11
|
};
|
|
12
|
-
}
|
|
13
|
-
export
|
|
14
|
-
|
|
12
|
+
}>;
|
|
13
|
+
export declare enum ResourceType {
|
|
14
|
+
Account = "account",
|
|
15
|
+
AccountProduct = "account_product",
|
|
16
|
+
Workspace = "workspace",
|
|
17
|
+
Board = "board",
|
|
18
|
+
Item = "item",
|
|
19
|
+
Team = "team",
|
|
20
|
+
Overview = "overview",
|
|
21
|
+
Document = "document",
|
|
22
|
+
Crm = "crm"
|
|
23
|
+
}
|
|
24
|
+
export declare const RESOURCE_TYPES: readonly ResourceType[];
|
|
15
25
|
//# sourceMappingURL=resource-attributes-constants.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource-attributes-constants.d.ts","sourceRoot":"","sources":["../../src/resource-attributes-constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,6BAA6B;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"resource-attributes-constants.d.ts","sourceRoot":"","sources":["../../src/resource-attributes-constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,6BAA6B;;;;;;;;;;;EAWxC,CAAC;AAEH,oBAAY,YAAY;IACtB,OAAO,YAAY;IACnB,cAAc,oBAAoB;IAClC,SAAS,cAAc;IACvB,KAAK,UAAU;IACf,IAAI,SAAS;IACb,IAAI,SAAS;IACb,QAAQ,aAAa;IACrB,QAAQ,aAAa;IACrB,GAAG,QAAQ;CACZ;AAGD,eAAO,MAAM,cAAc,yBAA6C,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const RESOURCE_ATTRIBUTES_CONSTANTS = {
|
|
1
|
+
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,17 +9,20 @@ 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
|
-
};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
12
|
+
});
|
|
13
|
+
var ResourceType;
|
|
14
|
+
(function (ResourceType) {
|
|
15
|
+
ResourceType["Account"] = "account";
|
|
16
|
+
ResourceType["AccountProduct"] = "account_product";
|
|
17
|
+
ResourceType["Workspace"] = "workspace";
|
|
18
|
+
ResourceType["Board"] = "board";
|
|
19
|
+
ResourceType["Item"] = "item";
|
|
20
|
+
ResourceType["Team"] = "team";
|
|
21
|
+
ResourceType["Overview"] = "overview";
|
|
22
|
+
ResourceType["Document"] = "document";
|
|
23
|
+
ResourceType["Crm"] = "crm";
|
|
24
|
+
})(ResourceType || (ResourceType = {}));
|
|
25
|
+
// Define the array of strings and use 'as const' to make its contents literal types
|
|
26
|
+
const RESOURCE_TYPES = Object.freeze(Object.values(ResourceType));
|
|
24
27
|
|
|
25
|
-
export { RESOURCE_ATTRIBUTES_CONSTANTS, RESOURCE_TYPES };
|
|
28
|
+
export { RESOURCE_ATTRIBUTES_CONSTANTS, RESOURCE_TYPES, ResourceType };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { BaseRequest, BaseResponse, ContextGetter, Resource, ResourceGetter } from '../types/general';
|
|
1
|
+
import { Action, BaseRequest, BaseResponse, ContextGetter, Resource, ResourceGetter } from '../types/general';
|
|
2
2
|
import type { NextFunction } from 'express';
|
|
3
3
|
export type TestPermittedAction = {
|
|
4
4
|
accountId: number;
|
|
5
5
|
userId: number;
|
|
6
6
|
resources: Resource[];
|
|
7
|
-
action:
|
|
7
|
+
action: Action;
|
|
8
8
|
};
|
|
9
|
-
export declare const addTestPermittedAction: (accountId: number, userId: number, resources: Resource[], action:
|
|
9
|
+
export declare const addTestPermittedAction: (accountId: number, userId: number, resources: Resource[], action: Action) => void;
|
|
10
10
|
export declare const clearTestPermittedActions: () => void;
|
|
11
|
-
export declare const getTestAuthorizationMiddleware: (action:
|
|
11
|
+
export declare const getTestAuthorizationMiddleware: (action: Action, resourceGetter: ResourceGetter, contextGetter?: ContextGetter) => (request: BaseRequest, response: BaseResponse, next: NextFunction) => Promise<void>;
|
|
12
12
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/testKit/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,aAAa,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/testKit/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,YAAY,EAAE,aAAa,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAG9G,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C,MAAM,MAAM,mBAAmB,GAAG;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,QAAQ,EAAE,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAGF,eAAO,MAAM,sBAAsB,GAAI,WAAW,MAAM,EAAE,QAAQ,MAAM,EAAE,WAAW,QAAQ,EAAE,EAAE,QAAQ,MAAM,SAE9G,CAAC;AAEF,eAAO,MAAM,yBAAyB,YAErC,CAAC;AA4BF,eAAO,MAAM,8BAA8B,GACzC,QAAQ,MAAM,EACd,gBAAgB,cAAc,EAC9B,gBAAgB,aAAa,MAG3B,SAAS,WAAW,EACpB,UAAU,YAAY,EACtB,MAAM,YAAY,KACjB,OAAO,CAAC,IAAI,CAYhB,CAAC"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Resource } from './general';
|
|
2
2
|
import type { EntityType } from '../entity-attributes-constants';
|
|
3
3
|
import type { ResourceType } from '../resource-attributes-constants';
|
|
4
|
-
export
|
|
5
|
-
interface AttributeAssignment {
|
|
4
|
+
export interface AttributeAssignment {
|
|
6
5
|
key: string;
|
|
7
6
|
value: string;
|
|
8
7
|
}
|
|
@@ -34,10 +33,12 @@ export interface ResourceAttributeResponse {
|
|
|
34
33
|
export interface EntityAttributeResponse {
|
|
35
34
|
attributes: EntityAttributeAssignment[];
|
|
36
35
|
}
|
|
37
|
-
export interface
|
|
36
|
+
export interface ResourceAttributeUpsertOperation extends ResourceAttributeAssignment {
|
|
38
37
|
operationType: AttributeOperation;
|
|
39
38
|
}
|
|
40
|
-
export
|
|
39
|
+
export type ResourceAttributeDeleteOperation = Omit<ResourceAttributeUpsertOperation, 'value'>;
|
|
40
|
+
export interface EntityAttributeUpsertOperation extends EntityAttributeAssignment {
|
|
41
41
|
operationType: AttributeOperation;
|
|
42
42
|
}
|
|
43
|
+
export type EntityAttributeDeleteOperation = Omit<EntityAttributeUpsertOperation, 'value'>;
|
|
43
44
|
//# sourceMappingURL=authorization-attributes-contracts.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authorization-attributes-contracts.d.ts","sourceRoot":"","sources":["../../../src/types/authorization-attributes-contracts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAErE,
|
|
1
|
+
{"version":3,"file":"authorization-attributes-contracts.d.ts","sourceRoot":"","sources":["../../../src/types/authorization-attributes-contracts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAErE,MAAM,WAAW,mBAAmB;IAClC,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;CACf;AAGD,MAAM,WAAW,2BAA4B,SAAQ,mBAAmB;IACtE,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,YAAY,CAAC;CAC5B;AAID,MAAM,WAAW,yBAA0B,SAAQ,mBAAmB;IACpE,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,UAAU,CAAC;CACxB;AAGD,MAAM,WAAW,uBAAuB;IACtC,YAAY,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC/B,UAAU,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC3B,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,qBAAqB;IACpC,UAAU,EAAE,UAAU,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;CACb;AAED,oBAAY,kBAAkB;IAC5B,MAAM,WAAW;IACjB,MAAM,WAAW;CAClB;AAGD,MAAM,WAAW,yBAAyB;IACxC,UAAU,EAAE,2BAA2B,EAAE,CAAC;CAC3C;AAED,MAAM,WAAW,uBAAuB;IACtC,UAAU,EAAE,yBAAyB,EAAE,CAAC;CACzC;AAED,MAAM,WAAW,gCAAiC,SAAQ,2BAA2B;IACnF,aAAa,EAAE,kBAAkB,CAAC;CACnC;AACD,MAAM,MAAM,gCAAgC,GAAG,IAAI,CAAC,gCAAgC,EAAE,OAAO,CAAC,CAAC;AAE/F,MAAM,WAAW,8BAA+B,SAAQ,yBAAyB;IAC/E,aAAa,EAAE,kBAAkB,CAAC;CACnC;AACD,MAAM,MAAM,8BAA8B,GAAG,IAAI,CAAC,8BAA8B,EAAE,OAAO,CAAC,CAAC"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { EntityAttributeAssignment } from '../entity-attribute-assignment';
|
|
1
|
+
import { EntityType } from '../entity-attributes-constants';
|
|
2
|
+
import { ResourceAttributeDeleteOperation, EntityAttributeDeleteOperation, ResourceAttributeUpsertOperation, EntityAttributeUpsertOperation } from './authorization-attributes-contracts';
|
|
4
3
|
import { Resource } from './general';
|
|
5
4
|
/**
|
|
6
5
|
* Resource type compatible with both MS and SNS services
|
|
@@ -15,42 +14,30 @@ export interface CompatibleResource {
|
|
|
15
14
|
* Interface for authorization attributes operations.
|
|
16
15
|
* Both MS (direct) and SNS (async) services implement this interface.
|
|
17
16
|
*/
|
|
18
|
-
export interface
|
|
19
|
-
/**
|
|
20
|
-
* Upserts resource attributes.
|
|
21
|
-
* For MS service: returns Promise<void>
|
|
22
|
-
* For SNS service: requires appName and callerActionIdentifier, returns Promise<ResourceAttributesOperation[]>
|
|
23
|
-
*/
|
|
24
|
-
upsertResourceAttributes(accountId: number, resourceAttributeAssignments: ResourceAttributeAssignment[] | ResourceAttributeAssignmentContract[], appName?: string, callerActionIdentifier?: string): Promise<void | ResourceAttributeOperation[]>;
|
|
17
|
+
export interface AuthorizationAttributesService {
|
|
25
18
|
/**
|
|
26
19
|
* Deletes resource attributes.
|
|
27
20
|
* For MS service: returns Promise<void>
|
|
28
21
|
* For SNS service: requires appName and callerActionIdentifier, returns Promise<ResourceAttributesOperation[]>
|
|
29
22
|
*/
|
|
30
|
-
deleteResourceAttributes(accountId: number, resource: CompatibleResource | Resource, attributeKeys: string[], appName?: string, callerActionIdentifier?: string): Promise<void |
|
|
31
|
-
/**
|
|
32
|
-
* Upserts entity attributes.
|
|
33
|
-
* For MS service: returns Promise<void>
|
|
34
|
-
* For SNS service: requires appName and callerActionIdentifier, returns Promise<EntityAttributesOperation[]>
|
|
35
|
-
*/
|
|
36
|
-
upsertEntityAttributes(accountId: number, entityAttributeAssignments: EntityAttributeAssignment[] | EntityAttributeAssignmentContract[], appName?: string, callerActionIdentifier?: string): Promise<void | EntityAttributeOperation[]>;
|
|
23
|
+
deleteResourceAttributes(accountId: number, resource: CompatibleResource | Resource, attributeKeys: string[], appName?: string, callerActionIdentifier?: string): Promise<void | ResourceAttributeDeleteOperation[]>;
|
|
37
24
|
/**
|
|
38
25
|
* Deletes entity attributes.
|
|
39
26
|
* For MS service: returns Promise<void>
|
|
40
27
|
* For SNS service: requires appName and callerActionIdentifier, returns Promise<EntityAttributesOperation[]>
|
|
41
28
|
*/
|
|
42
|
-
deleteEntityAttributes(accountId: number, entityType: EntityType | string, entityId: number, attributeKeys: string[], appName?: string, callerActionIdentifier?: string): Promise<void |
|
|
29
|
+
deleteEntityAttributes(accountId: number, entityType: EntityType | string, entityId: number, attributeKeys: string[], appName?: string, callerActionIdentifier?: string): Promise<void | EntityAttributeDeleteOperation[]>;
|
|
43
30
|
/**
|
|
44
31
|
* Updates resource attributes (batch operations).
|
|
45
32
|
* For MS service: may throw error or delegate to upsert/delete
|
|
46
33
|
* For SNS service: returns Promise<ResourceAttributesOperation[]>
|
|
47
34
|
*/
|
|
48
|
-
updateResourceAttributes(accountId: number, appName: string, callerActionIdentifier: string, resourceAttributeOperations:
|
|
35
|
+
updateResourceAttributes(accountId: number, appName: string, callerActionIdentifier: string, resourceAttributeOperations: ResourceAttributeUpsertOperation[]): Promise<ResourceAttributeUpsertOperation[]>;
|
|
49
36
|
/**
|
|
50
37
|
* Updates entity attributes (batch operations).
|
|
51
38
|
* For MS service: may throw error or delegate to upsert/delete
|
|
52
39
|
* For SNS service: returns Promise<EntityAttributesOperation[]>
|
|
53
40
|
*/
|
|
54
|
-
updateEntityAttributes(accountId: number, appName: string, callerActionIdentifier: string, entityAttributeOperations:
|
|
41
|
+
updateEntityAttributes(accountId: number, appName: string, callerActionIdentifier: string, entityAttributeOperations: EntityAttributeUpsertOperation[]): Promise<EntityAttributeUpsertOperation[]>;
|
|
55
42
|
}
|
|
56
43
|
//# sourceMappingURL=authorization-attributes-service.interface.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authorization-attributes-service.interface.d.ts","sourceRoot":"","sources":["../../../src/types/authorization-attributes-service.interface.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"authorization-attributes-service.interface.d.ts","sourceRoot":"","sources":["../../../src/types/authorization-attributes-service.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,EACL,gCAAgC,EAChC,8BAA8B,EAC9B,gCAAgC,EAChC,8BAA8B,EAC/B,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAED;;;GAGG;AACH,MAAM,WAAW,8BAA8B;IAC7C;;;;OAIG;IACH,wBAAwB,CACtB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,kBAAkB,GAAG,QAAQ,EACvC,aAAa,EAAE,MAAM,EAAE,EACvB,OAAO,CAAC,EAAE,MAAM,EAChB,sBAAsB,CAAC,EAAE,MAAM,GAC9B,OAAO,CAAC,IAAI,GAAG,gCAAgC,EAAE,CAAC,CAAC;IAEtD;;;;OAIG;IACH,sBAAsB,CACpB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,UAAU,GAAG,MAAM,EAC/B,QAAQ,EAAE,MAAM,EAChB,aAAa,EAAE,MAAM,EAAE,EACvB,OAAO,CAAC,EAAE,MAAM,EAChB,sBAAsB,CAAC,EAAE,MAAM,GAC9B,OAAO,CAAC,IAAI,GAAG,8BAA8B,EAAE,CAAC,CAAC;IAEpD;;;;OAIG;IACH,wBAAwB,CACtB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,sBAAsB,EAAE,MAAM,EAC9B,2BAA2B,EAAE,gCAAgC,EAAE,GAC9D,OAAO,CAAC,gCAAgC,EAAE,CAAC,CAAC;IAE/C;;;;OAIG;IACH,sBAAsB,CACpB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,sBAAsB,EAAE,MAAM,EAC9B,yBAAyB,EAAE,8BAA8B,EAAE,GAC1D,OAAO,CAAC,8BAA8B,EAAE,CAAC,CAAC;CAC9C"}
|
|
@@ -4,6 +4,7 @@ export interface Resource {
|
|
|
4
4
|
type: string;
|
|
5
5
|
wrapperData?: object;
|
|
6
6
|
}
|
|
7
|
+
export type Action = string;
|
|
7
8
|
export interface Context {
|
|
8
9
|
accountId: number;
|
|
9
10
|
userId: number;
|
|
@@ -12,7 +13,7 @@ export interface AuthorizationObject {
|
|
|
12
13
|
resource_id?: Resource['id'];
|
|
13
14
|
resource_type: Resource['type'];
|
|
14
15
|
wrapper_data?: Resource['wrapperData'];
|
|
15
|
-
action:
|
|
16
|
+
action: Action;
|
|
16
17
|
}
|
|
17
18
|
export interface AuthorizationParams {
|
|
18
19
|
authorizationObjects: AuthorizationObject[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"general.d.ts","sourceRoot":"","sources":["../../../src/types/general.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEjD,MAAM,WAAW,QAAQ;IACvB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;
|
|
1
|
+
{"version":3,"file":"general.d.ts","sourceRoot":"","sources":["../../../src/types/general.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEjD,MAAM,WAAW,QAAQ;IACvB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AACD,MAAM,MAAM,MAAM,GAAG,MAAM,CAAC;AAC5B,MAAM,WAAW,OAAO;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;CAChB;AACD,MAAM,WAAW,mBAAmB;IAClC,WAAW,CAAC,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC7B,aAAa,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IAChC,YAAY,CAAC,EAAE,QAAQ,CAAC,aAAa,CAAC,CAAC;IACvC,MAAM,EAAE,MAAM,CAAC;CAChB;AACD,MAAM,WAAW,mBAAmB;IAClC,oBAAoB,EAAE,mBAAmB,EAAE,CAAC;CAC7C;AAED,KAAK,WAAW,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,CAAC;AAE9C,MAAM,MAAM,cAAc,GAAG,WAAW,CAAC;AACzC,MAAM,MAAM,gBAAgB,GAAG,WAAW,CAAC;AAC3C,MAAM,MAAM,kBAAkB,GAAG,WAAW,CAAC;AAC7C,MAAM,MAAM,mBAAmB,GAAG,WAAW,CAAC;AAC9C,MAAM,MAAM,WAAW,GAAG,OAAO,CAAC,cAAc,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,mBAAmB,CAAC,CAAC;AAC7G,MAAM,MAAM,YAAY,GAAG,QAAQ,CAAC,gBAAgB,CAAC,CAAC;AACtD,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,EAAE,WAAW,KAAK,QAAQ,EAAE,CAAC;AAClE,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,EAAE,WAAW,KAAK,OAAO,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export declare const entityAssignmentSchema: import("ajv").ValidateFunction<{
|
|
2
|
+
entityId: any;
|
|
3
|
+
entityType: any;
|
|
4
|
+
attributeKey: any;
|
|
5
|
+
attributeValue: any;
|
|
6
|
+
} & {
|
|
7
|
+
entityId: any;
|
|
8
|
+
} & {
|
|
9
|
+
entityType: any;
|
|
10
|
+
} & {
|
|
11
|
+
attributeKey: any;
|
|
12
|
+
} & {
|
|
13
|
+
attributeValue: any;
|
|
14
|
+
}>;
|
|
15
|
+
export declare const resourceAssignmentSchema: import("ajv").ValidateFunction<{
|
|
16
|
+
id: any;
|
|
17
|
+
type: any;
|
|
18
|
+
attributeKey: any;
|
|
19
|
+
attributeValue: any;
|
|
20
|
+
} & {
|
|
21
|
+
id: any;
|
|
22
|
+
} & {
|
|
23
|
+
type: any;
|
|
24
|
+
} & {
|
|
25
|
+
attributeKey: any;
|
|
26
|
+
} & {
|
|
27
|
+
attributeValue: any;
|
|
28
|
+
}>;
|
|
29
|
+
//# sourceMappingURL=assigment-schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assigment-schema.d.ts","sourceRoot":"","sources":["../../../src/utils/assigment-schema.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;EAUjC,CAAC;AAEH,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;EAUnC,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import Ajv from 'ajv';
|
|
2
|
+
import { EntityType } from '../entity-attributes-constants.mjs';
|
|
3
|
+
import { ResourceType } from '../resource-attributes-constants.mjs';
|
|
4
|
+
|
|
5
|
+
const ajv = new Ajv({ allErrors: true });
|
|
6
|
+
const entityAssignmentSchema = ajv.compile({
|
|
7
|
+
type: 'object',
|
|
8
|
+
properties: {
|
|
9
|
+
entityId: { type: 'number', multipleOf: 1 },
|
|
10
|
+
entityType: { type: 'string', enum: Object.values(EntityType) },
|
|
11
|
+
key: { type: 'string', minLength: 1 },
|
|
12
|
+
value: { type: 'string', minLength: 1 },
|
|
13
|
+
},
|
|
14
|
+
required: ['entityId', 'entityType', 'attributeKey', 'attributeValue'],
|
|
15
|
+
additionalProperties: false,
|
|
16
|
+
});
|
|
17
|
+
const resourceAssignmentSchema = ajv.compile({
|
|
18
|
+
type: 'object',
|
|
19
|
+
properties: {
|
|
20
|
+
id: { type: 'number', multipleOf: 1 },
|
|
21
|
+
type: { type: 'string', enum: Object.values(ResourceType) },
|
|
22
|
+
key: { type: 'string', minLength: 1 },
|
|
23
|
+
value: { type: 'string', minLength: 1 },
|
|
24
|
+
},
|
|
25
|
+
required: ['id', 'type', 'attributeKey', 'attributeValue'],
|
|
26
|
+
additionalProperties: false,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
export { entityAssignmentSchema, resourceAssignmentSchema };
|
|
@@ -1,45 +1,20 @@
|
|
|
1
|
+
import { ResourceAttributeAssignment, EntityAttributeAssignment } from '../types/authorization-attributes-contracts';
|
|
1
2
|
/**
|
|
2
|
-
* Utility class for common validation operations using
|
|
3
|
+
* Utility class for common validation operations using AJV
|
|
3
4
|
*/
|
|
4
5
|
export declare class ValidationUtils {
|
|
6
|
+
private static ajv;
|
|
7
|
+
private static integerValidator;
|
|
8
|
+
private static stringValidator;
|
|
9
|
+
private static stringArrayValidator;
|
|
10
|
+
static validateInteger(value: number): void;
|
|
11
|
+
static validateString(value: string): void;
|
|
12
|
+
static validateStringArray(value: string[]): void;
|
|
5
13
|
/**
|
|
6
|
-
* Validates
|
|
7
|
-
*
|
|
8
|
-
* @param fieldName The name of the field for error messages
|
|
9
|
-
* @throws ArgumentError if value is not an integer
|
|
14
|
+
* Validates an attribute assignment object using a single AJV schema.
|
|
15
|
+
* Preserves legacy error messages for each field.
|
|
10
16
|
*/
|
|
11
|
-
static
|
|
12
|
-
|
|
13
|
-
* Validates that a value is a non-empty string
|
|
14
|
-
* @param value The value to validate
|
|
15
|
-
* @param fieldName The name of the field for error messages
|
|
16
|
-
* @throws ArgumentError if value is not a string or is empty
|
|
17
|
-
*/
|
|
18
|
-
static validateString(value: any, fieldName: string): void;
|
|
19
|
-
/**
|
|
20
|
-
* Validates that a value is an array and optionally checks minimum length
|
|
21
|
-
* @param value The value to validate
|
|
22
|
-
* @param fieldName The name of the field for error messages
|
|
23
|
-
* @param minLength Minimum required length (default: 0)
|
|
24
|
-
* @returns The validated array
|
|
25
|
-
* @throws ArgumentError if value is not an array or doesn't meet minimum length
|
|
26
|
-
*/
|
|
27
|
-
static validateArray<T>(value: any, fieldName: string, minLength?: number): T[];
|
|
28
|
-
/**
|
|
29
|
-
* Validates that a value is one of the allowed enum values
|
|
30
|
-
* @param value The value to validate
|
|
31
|
-
* @param validValues Array of valid values
|
|
32
|
-
* @param fieldName The name of the field for error messages
|
|
33
|
-
* @returns The validated value as the enum type
|
|
34
|
-
* @throws ArgumentError if value is not in validValues
|
|
35
|
-
*/
|
|
36
|
-
static validateEnum<T extends string>(value: string, validValues: readonly T[], fieldName: string): T;
|
|
37
|
-
/**
|
|
38
|
-
* Validates that all items in an array are strings
|
|
39
|
-
* @param value Array to validate
|
|
40
|
-
* @param fieldName The name of the field for error messages
|
|
41
|
-
* @throws ArgumentError if any item is not a string
|
|
42
|
-
*/
|
|
43
|
-
static validateStringArray(value: any[], fieldName: string): void;
|
|
17
|
+
static validateResourceAssignment(resource: ResourceAttributeAssignment): void;
|
|
18
|
+
static validateEntityAssignment(entity: EntityAttributeAssignment): void;
|
|
44
19
|
}
|
|
45
20
|
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../../src/utils/validation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../../src/utils/validation.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,2BAA2B,EAAE,yBAAyB,EAAE,MAAM,6CAA6C,CAAC;AAGrH;;GAEG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,MAAM,CAAC,GAAG,CAAgC;IAElD,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAAyE;IACxG,OAAO,CAAC,MAAM,CAAC,eAAe,CAAwE;IACtG,OAAO,CAAC,MAAM,CAAC,oBAAoB,CAGhC;WAEW,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;WAOpC,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;WAOnC,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI;IAOxD;;;OAGG;IACH,MAAM,CAAC,0BAA0B,CAAC,QAAQ,EAAE,2BAA2B,GAAG,IAAI;IAU9E,MAAM,CAAC,wBAAwB,CAAC,MAAM,EAAE,yBAAyB,GAAG,IAAI;CASzE"}
|
|
@@ -1,115 +1,56 @@
|
|
|
1
|
-
import
|
|
1
|
+
import Ajv from 'ajv';
|
|
2
2
|
import { ArgumentError } from '../errors/argument-error.mjs';
|
|
3
|
+
import { resourceAssignmentSchema, entityAssignmentSchema } from './assigment-schema.mjs';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
|
-
* Utility class for common validation operations using
|
|
6
|
+
* Utility class for common validation operations using AJV
|
|
6
7
|
*/
|
|
7
8
|
class ValidationUtils {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
catch (error) {
|
|
20
|
-
if (error instanceof z.ZodError) {
|
|
21
|
-
throw new ArgumentError(`${fieldName} must be an integer, got: ${value}`);
|
|
22
|
-
}
|
|
23
|
-
throw error;
|
|
9
|
+
static ajv = new Ajv({ allErrors: true });
|
|
10
|
+
static integerValidator = this.ajv.compile({ type: 'number', multipleOf: 1 });
|
|
11
|
+
static stringValidator = this.ajv.compile({ type: 'string', minLength: 1 });
|
|
12
|
+
static stringArrayValidator = this.ajv.compile({
|
|
13
|
+
type: 'array',
|
|
14
|
+
items: { type: 'string' },
|
|
15
|
+
});
|
|
16
|
+
static validateInteger(value) {
|
|
17
|
+
const valid = this.integerValidator(value);
|
|
18
|
+
if (!valid) {
|
|
19
|
+
throw new ArgumentError('Invalid integer');
|
|
24
20
|
}
|
|
25
21
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
* @throws ArgumentError if value is not a string or is empty
|
|
31
|
-
*/
|
|
32
|
-
static validateString(value, fieldName) {
|
|
33
|
-
const schema = z.string().min(1);
|
|
34
|
-
try {
|
|
35
|
-
schema.parse(value);
|
|
36
|
-
}
|
|
37
|
-
catch (error) {
|
|
38
|
-
if (error instanceof z.ZodError) {
|
|
39
|
-
if (typeof value !== 'string') {
|
|
40
|
-
throw new ArgumentError(`${fieldName} must be a string, got: ${typeof value}`);
|
|
41
|
-
}
|
|
42
|
-
throw new ArgumentError(`${fieldName} must be a non-empty string`);
|
|
43
|
-
}
|
|
44
|
-
throw error;
|
|
22
|
+
static validateString(value) {
|
|
23
|
+
const valid = this.stringValidator(value);
|
|
24
|
+
if (!valid) {
|
|
25
|
+
throw new ArgumentError('Invalid string');
|
|
45
26
|
}
|
|
46
27
|
}
|
|
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(value, fieldName, minLength = 0) {
|
|
56
|
-
const schema = z.array(z.any()).min(minLength);
|
|
57
|
-
try {
|
|
58
|
-
return schema.parse(value);
|
|
59
|
-
}
|
|
60
|
-
catch (error) {
|
|
61
|
-
if (error instanceof z.ZodError) {
|
|
62
|
-
if (!Array.isArray(value)) {
|
|
63
|
-
throw new ArgumentError(`${fieldName} must be an array`);
|
|
64
|
-
}
|
|
65
|
-
throw new ArgumentError(`${fieldName} must have at least ${minLength} items`);
|
|
66
|
-
}
|
|
67
|
-
throw error;
|
|
28
|
+
static validateStringArray(value) {
|
|
29
|
+
const valid = this.stringArrayValidator(value);
|
|
30
|
+
if (!valid) {
|
|
31
|
+
throw new ArgumentError('Invalid string array');
|
|
68
32
|
}
|
|
69
33
|
}
|
|
70
34
|
/**
|
|
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
|
|
35
|
+
* Validates an attribute assignment object using a single AJV schema.
|
|
36
|
+
* Preserves legacy error messages for each field.
|
|
77
37
|
*/
|
|
78
|
-
static
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
throw new ArgumentError(`${fieldName} must be one of [${validValues.join(', ')}], got: ${value}`);
|
|
86
|
-
}
|
|
87
|
-
throw error;
|
|
38
|
+
static validateResourceAssignment(resource) {
|
|
39
|
+
const valid = resourceAssignmentSchema(resource);
|
|
40
|
+
if (!valid) {
|
|
41
|
+
const errorMessages = (resourceAssignmentSchema.errors || [])
|
|
42
|
+
.map(err => err.message || 'validation failed')
|
|
43
|
+
.join(', ');
|
|
44
|
+
throw new ArgumentError(`Invalid resource attribute assignment: ${errorMessages}`);
|
|
88
45
|
}
|
|
89
46
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
const schema = z.array(z.string());
|
|
98
|
-
try {
|
|
99
|
-
schema.parse(value);
|
|
100
|
-
}
|
|
101
|
-
catch (error) {
|
|
102
|
-
if (error instanceof z.ZodError) {
|
|
103
|
-
const zodError = error;
|
|
104
|
-
const firstError = zodError.issues[0];
|
|
105
|
-
// Check if it's an array item validation error
|
|
106
|
-
if (firstError.path.length > 0 && typeof firstError.path[0] === 'number') {
|
|
107
|
-
const index = firstError.path[0];
|
|
108
|
-
throw new ArgumentError(`All ${fieldName} must be strings, but item at index ${index} is not`);
|
|
109
|
-
}
|
|
110
|
-
throw new ArgumentError(`${fieldName} must be an array`);
|
|
111
|
-
}
|
|
112
|
-
throw error;
|
|
47
|
+
static validateEntityAssignment(entity) {
|
|
48
|
+
const valid = entityAssignmentSchema(entity);
|
|
49
|
+
if (!valid) {
|
|
50
|
+
const errorMessages = (entityAssignmentSchema.errors || [])
|
|
51
|
+
.map(err => err.message || 'validation failed')
|
|
52
|
+
.join(', ');
|
|
53
|
+
throw new ArgumentError(`Invalid entity attribute assignment: ${errorMessages}`);
|
|
113
54
|
}
|
|
114
55
|
}
|
|
115
56
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -19,15 +19,6 @@ export declare function init(options?: InitOptions): Promise<void>;
|
|
|
19
19
|
export { authorizationCheckMiddleware, getAuthorizationMiddleware, skipAuthorizationMiddleware, } from './authorization-middleware';
|
|
20
20
|
export { AuthorizationService, AuthorizeResponse } from './authorization-service';
|
|
21
21
|
export { AuthorizationAttributesService } from './authorization-attributes-service';
|
|
22
|
-
export { AuthorizationAttributesSnsService } from './authorization-attributes-sns-service';
|
|
23
|
-
export { AuthorizationAttributesMsService } from './authorization-attributes-ms-service';
|
|
24
|
-
export { IAuthorizationAttributesService } from './types/authorization-attributes-service.interface';
|
|
25
|
-
export { ResourceAttributeAssignment } from './resource-attribute-assignment';
|
|
26
|
-
export { RESOURCE_TYPES, RESOURCE_ATTRIBUTES_CONSTANTS } from './resource-attributes-constants';
|
|
27
|
-
export { EntityAttributeAssignment } from './entity-attribute-assignment';
|
|
28
|
-
export { ENTITY_TYPES } from './entity-attributes-constants';
|
|
29
|
-
export { ArgumentError } from './errors/argument-error';
|
|
30
|
-
export type { EntityType } from './entity-attributes-constants';
|
|
31
22
|
export { RolesService } from './roles-service';
|
|
32
23
|
export { MembershipsService } from './memberships';
|
|
33
24
|
export { AuthorizationObject, Resource, BaseRequest, ResourceGetter, ContextGetter } from './types/general';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAGnE,OAAO,EAAqB,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACrE,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AAErC,UAAU,kBAAkB;IAC1B,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,WAAW;IAC1B,UAAU,CAAC,EAAE,GAAG,CAAC;IACjB,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;IACxC,WAAW,CAAC,EAAE,GAAG,CAAC;IAClB,sCAAsC,CAAC,EAAE,MAAM,CAAC;IAChD,OAAO,CAAC,EAAE,kBAAkB,CAAC;CAC9B;AAED,wBAAsB,IAAI,CAAC,OAAO,GAAE,WAAgB,iBA6BnD;AAED,OAAO,EACL,4BAA4B,EAC5B,0BAA0B,EAC1B,2BAA2B,GAC5B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAClF,OAAO,EAAE,8BAA8B,EAAE,MAAM,oCAAoC,CAAC;AACpF,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAGnE,OAAO,EAAqB,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACrE,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AAErC,UAAU,kBAAkB;IAC1B,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,WAAW;IAC1B,UAAU,CAAC,EAAE,GAAG,CAAC;IACjB,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;IACxC,WAAW,CAAC,EAAE,GAAG,CAAC;IAClB,sCAAsC,CAAC,EAAE,MAAM,CAAC;IAChD,OAAO,CAAC,EAAE,kBAAkB,CAAC;CAC9B;AAED,wBAAsB,IAAI,CAAC,OAAO,GAAE,WAAgB,iBA6BnD;AAED,OAAO,EACL,4BAA4B,EAC5B,0BAA0B,EAC1B,2BAA2B,GAC5B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAClF,OAAO,EAAE,8BAA8B,EAAE,MAAM,oCAAoC,CAAC;AACpF,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,QAAQ,EAAE,WAAW,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC5G,OAAO,EACL,WAAW,EACX,YAAY,EACZ,0BAA0B,EAC1B,kBAAkB,GACnB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAErH,OAAO,EAAE,OAAO,EAAE,CAAC"}
|