grm-shared-library 1.1.39 → 1.1.40

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.
@@ -20,5 +20,7 @@ __exportStar(require("./dtos/contact-person.dto"), exports);
20
20
  __exportStar(require("./interfaces/map-location"), exports);
21
21
  __exportStar(require("./interfaces/map-address"), exports);
22
22
  __exportStar(require("./interfaces/contact-person"), exports);
23
+ __exportStar(require("./interfaces/access-validation.interface"), exports);
23
24
  __exportStar(require("./constants/service.const"), exports);
25
+ __exportStar(require("./services"), exports);
24
26
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/modules/common/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0DAAwC;AACxC,yDAAuC;AACvC,4DAA0C;AAC1C,4DAA0C;AAC1C,2DAAyC;AACzC,8DAA4C;AAC5C,4DAA0C"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/modules/common/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0DAAwC;AACxC,yDAAuC;AACvC,4DAA0C;AAC1C,4DAA0C;AAC1C,2DAAyC;AACzC,8DAA4C;AAC5C,2EAAyD;AACzD,4DAA0C;AAC1C,6CAA2B"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=access-validation.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"access-validation.interface.js","sourceRoot":"","sources":["../../../../../src/modules/common/interfaces/access-validation.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AccessValidationService = void 0;
4
+ const common_1 = require("@nestjs/common");
5
+ /**
6
+ * Service for validating access control across microservices
7
+ * Provides centralized validation logic to ensure consistency
8
+ */
9
+ class AccessValidationService {
10
+ /**
11
+ * Validates if a user has access to perform list operations
12
+ * @param accessScope - The access scope for the user
13
+ * @param pluralEntityName - The name of the entities being accessed (for error messages)
14
+ */
15
+ validateListAccess(accessScope, pluralEntityName = 'entities') {
16
+ if (accessScope.isSuperAdmin) {
17
+ return;
18
+ }
19
+ if (accessScope.organizationFilter || accessScope.controlCentreFilter) {
20
+ return;
21
+ }
22
+ throw new common_1.ForbiddenException(`Access denied: Insufficient permissions to access ${pluralEntityName}`);
23
+ }
24
+ /**
25
+ * Validates if a user has access to a specific entity
26
+ * @param accessScope - The access scope for the user
27
+ * @param entity - The entity to check access for
28
+ * @param entityName - The name of the entity (for error messages)
29
+ */
30
+ validateEntityAccess(accessScope, entity, entityName = 'Entity') {
31
+ if (accessScope.isSuperAdmin) {
32
+ return;
33
+ }
34
+ if (accessScope.organizationFilter && entity.organizationId === accessScope.organizationFilter) {
35
+ return;
36
+ }
37
+ if (accessScope.controlCentreFilter && entity.controlCentreId === accessScope.controlCentreFilter) {
38
+ return;
39
+ }
40
+ throw new common_1.ForbiddenException(`Access denied: Insufficient permissions to access this ${entityName.toLowerCase()}`);
41
+ }
42
+ /**
43
+ * Validates if a user can create an entity with the specified organization/control centre
44
+ * @param accessScope - The access scope for the user
45
+ * @param createDto - The DTO containing organizationId/controlCentreId
46
+ * @param entityName - The name of the entity (for error messages)
47
+ */
48
+ validateCreateAccess(accessScope, createDto, entityName = 'entity') {
49
+ if (accessScope.isSuperAdmin) {
50
+ return;
51
+ }
52
+ // Check organization level access
53
+ if (createDto.organizationId) {
54
+ if (accessScope.organizationFilter && createDto.organizationId !== accessScope.organizationFilter) {
55
+ throw new common_1.ForbiddenException(`Cannot create ${entityName} for this organization`);
56
+ }
57
+ }
58
+ // Check control centre level access
59
+ if (createDto.controlCentreId) {
60
+ if (accessScope.controlCentreFilter && createDto.controlCentreId !== accessScope.controlCentreFilter) {
61
+ throw new common_1.ForbiddenException(`Cannot create ${entityName} for this control centre`);
62
+ }
63
+ }
64
+ // Ensure user has at least organization or control centre level access
65
+ if (!accessScope.organizationFilter && !accessScope.controlCentreFilter) {
66
+ throw new common_1.ForbiddenException(`Insufficient permissions to create ${entityName}`);
67
+ }
68
+ }
69
+ /**
70
+ * Validates if a user has access to update entities
71
+ * @param accessScope - The access scope for the user
72
+ * @param entityName - The name of the entity (for error messages)
73
+ */
74
+ validateUpdateAccess(accessScope, entityName = 'entity') {
75
+ if (accessScope.isSuperAdmin) {
76
+ return;
77
+ }
78
+ // Ensure user has at least organization or control centre level access
79
+ if (!accessScope.organizationFilter && !accessScope.controlCentreFilter) {
80
+ throw new common_1.ForbiddenException(`Insufficient permissions to update ${entityName}`);
81
+ }
82
+ }
83
+ /**
84
+ * Validates if a user has access to delete entities
85
+ * @param accessScope - The access scope for the user
86
+ * @param entityName - The name of the entity (for error messages)
87
+ */
88
+ validateDeleteAccess(accessScope, entityName = 'entity') {
89
+ if (accessScope.isSuperAdmin) {
90
+ return;
91
+ }
92
+ // Ensure user has at least organization or control centre level access
93
+ if (!accessScope.organizationFilter && !accessScope.controlCentreFilter) {
94
+ throw new common_1.ForbiddenException(`Insufficient permissions to delete ${entityName}`);
95
+ }
96
+ }
97
+ /**
98
+ * Validates if a user can update an entity with the specified organization/control centre changes
99
+ * @param accessScope - The access scope for the user
100
+ * @param existingEntity - The existing entity
101
+ * @param updateDto - The DTO containing updated organizationId/controlCentreId
102
+ * @param entityName - The name of the entity (for error messages)
103
+ */
104
+ validateUpdateEntityAccess(accessScope, existingEntity, updateDto, entityName = 'entity') {
105
+ // First validate access to the existing entity
106
+ this.validateEntityAccess(accessScope, existingEntity, entityName);
107
+ // Then validate update permissions
108
+ this.validateUpdateAccess(accessScope, entityName);
109
+ // If organization is being changed, validate access to new organization
110
+ if (updateDto.organizationId && updateDto.organizationId !== existingEntity.organizationId) {
111
+ if (accessScope.organizationFilter && updateDto.organizationId !== accessScope.organizationFilter) {
112
+ throw new common_1.ForbiddenException(`Cannot move ${entityName} to this organization`);
113
+ }
114
+ }
115
+ // If control centre is being changed, validate access to new control centre
116
+ if (updateDto.controlCentreId && updateDto.controlCentreId !== existingEntity.controlCentreId) {
117
+ if (accessScope.controlCentreFilter && updateDto.controlCentreId !== accessScope.controlCentreFilter) {
118
+ throw new common_1.ForbiddenException(`Cannot move ${entityName} to this control centre`);
119
+ }
120
+ }
121
+ }
122
+ }
123
+ exports.AccessValidationService = AccessValidationService;
124
+ //# sourceMappingURL=access-validation.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"access-validation.service.js","sourceRoot":"","sources":["../../../../../src/modules/common/services/access-validation.service.ts"],"names":[],"mappings":";;;AAAA,2CAAoD;AAIpD;;;GAGG;AACH,MAAa,uBAAuB;IAEhC;;;;OAIG;IACH,kBAAkB,CAAC,WAAwB,EAAE,mBAA2B,UAAU;QAC9E,IAAI,WAAW,CAAC,YAAY,EAAE,CAAC;YAC3B,OAAO;QACX,CAAC;QAED,IAAI,WAAW,CAAC,kBAAkB,IAAI,WAAW,CAAC,mBAAmB,EAAE,CAAC;YACpE,OAAO;QACX,CAAC;QAED,MAAM,IAAI,2BAAkB,CAAC,qDAAqD,gBAAgB,EAAE,CAAC,CAAC;IAC1G,CAAC;IAED;;;;;OAKG;IACH,oBAAoB,CAChB,WAAwB,EACxB,MAAS,EACT,aAAqB,QAAQ;QAE7B,IAAI,WAAW,CAAC,YAAY,EAAE,CAAC;YAC3B,OAAO;QACX,CAAC;QAED,IAAI,WAAW,CAAC,kBAAkB,IAAI,MAAM,CAAC,cAAc,KAAK,WAAW,CAAC,kBAAkB,EAAE,CAAC;YAC7F,OAAO;QACX,CAAC;QAED,IAAI,WAAW,CAAC,mBAAmB,IAAI,MAAM,CAAC,eAAe,KAAK,WAAW,CAAC,mBAAmB,EAAE,CAAC;YAChG,OAAO;QACX,CAAC;QAED,MAAM,IAAI,2BAAkB,CAAC,0DAA0D,UAAU,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;IACvH,CAAC;IAED;;;;;OAKG;IACH,oBAAoB,CAChB,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vE,IAAI,CAAC,WAAW,CAAC,kBAAkB,IAAI,CAAC,WAAW,CAAC,mBAAmB,EAAE,CAAC;YACtE,MAAM,IAAI,2BAAkB,CAAC,sCAAsC,UAAU,EAAE,CAAC,CAAC;QACrF,CAAC;IACL,CAAC;IAED;;;;;;OAMG;IACH,0BAA0B,CACtB,WAAwB,EACxB,cAAiB,EACjB,SAAY,EACZ,aAAqB,QAAQ;QAE7B,+CAA+C;QAC/C,IAAI,CAAC,oBAAoB,CAAC,WAAW,EAAE,cAAc,EAAE,UAAU,CAAC,CAAC;QAEnE,mCAAmC;QACnC,IAAI,CAAC,oBAAoB,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;QAEnD,wEAAwE;QACxE,IAAI,SAAS,CAAC,cAAc,IAAI,SAAS,CAAC,cAAc,KAAK,cAAc,CAAC,cAAc,EAAE,CAAC;YACzF,IAAI,WAAW,CAAC,kBAAkB,IAAI,SAAS,CAAC,cAAc,KAAK,WAAW,CAAC,kBAAkB,EAAE,CAAC;gBAChG,MAAM,IAAI,2BAAkB,CAAC,eAAe,UAAU,uBAAuB,CAAC,CAAC;YACnF,CAAC;QACL,CAAC;QAED,4EAA4E;QAC5E,IAAI,SAAS,CAAC,eAAe,IAAI,SAAS,CAAC,eAAe,KAAK,cAAc,CAAC,eAAe,EAAE,CAAC;YAC5F,IAAI,WAAW,CAAC,mBAAmB,IAAI,SAAS,CAAC,eAAe,KAAK,WAAW,CAAC,mBAAmB,EAAE,CAAC;gBACnG,MAAM,IAAI,2BAAkB,CAAC,eAAe,UAAU,yBAAyB,CAAC,CAAC;YACrF,CAAC;QACL,CAAC;IACL,CAAC;CACJ;AAjJD,0DAiJC"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./access-validation.service"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/modules/common/services/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8DAA4C"}
@@ -4,5 +4,7 @@ export * from './dtos/contact-person.dto';
4
4
  export * from './interfaces/map-location';
5
5
  export * from './interfaces/map-address';
6
6
  export * from './interfaces/contact-person';
7
+ export * from './interfaces/access-validation.interface';
7
8
  export * from './constants/service.const';
9
+ export * from './services';
8
10
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/modules/common/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,0BAA0B,CAAC;AACzC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,2BAA2B,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/modules/common/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,0BAA0B,CAAC;AACzC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,0CAA0C,CAAC;AACzD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,YAAY,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=access-validation.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"access-validation.interface.js","sourceRoot":"","sources":["../../../../../src/modules/common/interfaces/access-validation.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,120 @@
1
+ import { ForbiddenException } from '@nestjs/common';
2
+ /**
3
+ * Service for validating access control across microservices
4
+ * Provides centralized validation logic to ensure consistency
5
+ */
6
+ export class AccessValidationService {
7
+ /**
8
+ * Validates if a user has access to perform list operations
9
+ * @param accessScope - The access scope for the user
10
+ * @param pluralEntityName - The name of the entities being accessed (for error messages)
11
+ */
12
+ validateListAccess(accessScope, pluralEntityName = 'entities') {
13
+ if (accessScope.isSuperAdmin) {
14
+ return;
15
+ }
16
+ if (accessScope.organizationFilter || accessScope.controlCentreFilter) {
17
+ return;
18
+ }
19
+ throw new ForbiddenException(`Access denied: Insufficient permissions to access ${pluralEntityName}`);
20
+ }
21
+ /**
22
+ * Validates if a user has access to a specific entity
23
+ * @param accessScope - The access scope for the user
24
+ * @param entity - The entity to check access for
25
+ * @param entityName - The name of the entity (for error messages)
26
+ */
27
+ validateEntityAccess(accessScope, entity, entityName = 'Entity') {
28
+ if (accessScope.isSuperAdmin) {
29
+ return;
30
+ }
31
+ if (accessScope.organizationFilter && entity.organizationId === accessScope.organizationFilter) {
32
+ return;
33
+ }
34
+ if (accessScope.controlCentreFilter && entity.controlCentreId === accessScope.controlCentreFilter) {
35
+ return;
36
+ }
37
+ throw new ForbiddenException(`Access denied: Insufficient permissions to access this ${entityName.toLowerCase()}`);
38
+ }
39
+ /**
40
+ * Validates if a user can create an entity with the specified organization/control centre
41
+ * @param accessScope - The access scope for the user
42
+ * @param createDto - The DTO containing organizationId/controlCentreId
43
+ * @param entityName - The name of the entity (for error messages)
44
+ */
45
+ validateCreateAccess(accessScope, createDto, entityName = 'entity') {
46
+ if (accessScope.isSuperAdmin) {
47
+ return;
48
+ }
49
+ // Check organization level access
50
+ if (createDto.organizationId) {
51
+ if (accessScope.organizationFilter && createDto.organizationId !== accessScope.organizationFilter) {
52
+ throw new ForbiddenException(`Cannot create ${entityName} for this organization`);
53
+ }
54
+ }
55
+ // Check control centre level access
56
+ if (createDto.controlCentreId) {
57
+ if (accessScope.controlCentreFilter && createDto.controlCentreId !== accessScope.controlCentreFilter) {
58
+ throw new ForbiddenException(`Cannot create ${entityName} for this control centre`);
59
+ }
60
+ }
61
+ // Ensure user has at least organization or control centre level access
62
+ if (!accessScope.organizationFilter && !accessScope.controlCentreFilter) {
63
+ throw new ForbiddenException(`Insufficient permissions to create ${entityName}`);
64
+ }
65
+ }
66
+ /**
67
+ * Validates if a user has access to update entities
68
+ * @param accessScope - The access scope for the user
69
+ * @param entityName - The name of the entity (for error messages)
70
+ */
71
+ validateUpdateAccess(accessScope, entityName = 'entity') {
72
+ if (accessScope.isSuperAdmin) {
73
+ return;
74
+ }
75
+ // Ensure user has at least organization or control centre level access
76
+ if (!accessScope.organizationFilter && !accessScope.controlCentreFilter) {
77
+ throw new ForbiddenException(`Insufficient permissions to update ${entityName}`);
78
+ }
79
+ }
80
+ /**
81
+ * Validates if a user has access to delete entities
82
+ * @param accessScope - The access scope for the user
83
+ * @param entityName - The name of the entity (for error messages)
84
+ */
85
+ validateDeleteAccess(accessScope, entityName = 'entity') {
86
+ if (accessScope.isSuperAdmin) {
87
+ return;
88
+ }
89
+ // Ensure user has at least organization or control centre level access
90
+ if (!accessScope.organizationFilter && !accessScope.controlCentreFilter) {
91
+ throw new ForbiddenException(`Insufficient permissions to delete ${entityName}`);
92
+ }
93
+ }
94
+ /**
95
+ * Validates if a user can update an entity with the specified organization/control centre changes
96
+ * @param accessScope - The access scope for the user
97
+ * @param existingEntity - The existing entity
98
+ * @param updateDto - The DTO containing updated organizationId/controlCentreId
99
+ * @param entityName - The name of the entity (for error messages)
100
+ */
101
+ validateUpdateEntityAccess(accessScope, existingEntity, updateDto, entityName = 'entity') {
102
+ // First validate access to the existing entity
103
+ this.validateEntityAccess(accessScope, existingEntity, entityName);
104
+ // Then validate update permissions
105
+ this.validateUpdateAccess(accessScope, entityName);
106
+ // If organization is being changed, validate access to new organization
107
+ if (updateDto.organizationId && updateDto.organizationId !== existingEntity.organizationId) {
108
+ if (accessScope.organizationFilter && updateDto.organizationId !== accessScope.organizationFilter) {
109
+ throw new ForbiddenException(`Cannot move ${entityName} to this organization`);
110
+ }
111
+ }
112
+ // If control centre is being changed, validate access to new control centre
113
+ if (updateDto.controlCentreId && updateDto.controlCentreId !== existingEntity.controlCentreId) {
114
+ if (accessScope.controlCentreFilter && updateDto.controlCentreId !== accessScope.controlCentreFilter) {
115
+ throw new ForbiddenException(`Cannot move ${entityName} to this control centre`);
116
+ }
117
+ }
118
+ }
119
+ }
120
+ //# sourceMappingURL=access-validation.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"access-validation.service.js","sourceRoot":"","sources":["../../../../../src/modules/common/services/access-validation.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAIpD;;;GAGG;AACH,MAAM,OAAO,uBAAuB;IAEhC;;;;OAIG;IACH,kBAAkB,CAAC,WAAwB,EAAE,mBAA2B,UAAU;QAC9E,IAAI,WAAW,CAAC,YAAY,EAAE,CAAC;YAC3B,OAAO;QACX,CAAC;QAED,IAAI,WAAW,CAAC,kBAAkB,IAAI,WAAW,CAAC,mBAAmB,EAAE,CAAC;YACpE,OAAO;QACX,CAAC;QAED,MAAM,IAAI,kBAAkB,CAAC,qDAAqD,gBAAgB,EAAE,CAAC,CAAC;IAC1G,CAAC;IAED;;;;;OAKG;IACH,oBAAoB,CAChB,WAAwB,EACxB,MAAS,EACT,aAAqB,QAAQ;QAE7B,IAAI,WAAW,CAAC,YAAY,EAAE,CAAC;YAC3B,OAAO;QACX,CAAC;QAED,IAAI,WAAW,CAAC,kBAAkB,IAAI,MA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AE,CAAC;gBACnG,MAAM,IAAI,kBAAkB,CAAC,eAAe,UAAU,yBAAyB,CAAC,CAAC;YACrF,CAAC;QACL,CAAC;IACL,CAAC;CACJ"}
@@ -0,0 +1,2 @@
1
+ export * from './access-validation.service';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/modules/common/services/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC"}
@@ -4,4 +4,6 @@ export * from './dtos/contact-person.dto';
4
4
  export * from './interfaces/map-location';
5
5
  export * from './interfaces/map-address';
6
6
  export * from './interfaces/contact-person';
7
+ export * from './interfaces/access-validation.interface';
7
8
  export * from './constants/service.const';
9
+ export * from './services';
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Interface for entities that can be checked for access control
3
+ */
4
+ export interface EntityAccessCheck {
5
+ organizationId?: number;
6
+ controlCentreId?: number;
7
+ }
8
+ /**
9
+ * Interface for create DTOs that need access validation
10
+ */
11
+ export interface CreateEntityAccessCheck {
12
+ organizationId?: number;
13
+ controlCentreId?: number;
14
+ }
15
+ /**
16
+ * Interface for update DTOs that need access validation
17
+ */
18
+ export interface UpdateEntityAccessCheck {
19
+ organizationId?: number;
20
+ controlCentreId?: number;
21
+ }
@@ -0,0 +1,48 @@
1
+ import { AccessScope } from '../../user/interfaces/access-scope';
2
+ import { EntityAccessCheck, CreateEntityAccessCheck, UpdateEntityAccessCheck } from '../interfaces/access-validation.interface';
3
+ /**
4
+ * Service for validating access control across microservices
5
+ * Provides centralized validation logic to ensure consistency
6
+ */
7
+ export declare class AccessValidationService {
8
+ /**
9
+ * Validates if a user has access to perform list operations
10
+ * @param accessScope - The access scope for the user
11
+ * @param pluralEntityName - The name of the entities being accessed (for error messages)
12
+ */
13
+ validateListAccess(accessScope: AccessScope, pluralEntityName?: string): void;
14
+ /**
15
+ * Validates if a user has access to a specific entity
16
+ * @param accessScope - The access scope for the user
17
+ * @param entity - The entity to check access for
18
+ * @param entityName - The name of the entity (for error messages)
19
+ */
20
+ validateEntityAccess<T extends EntityAccessCheck>(accessScope: AccessScope, entity: T, entityName?: string): void;
21
+ /**
22
+ * Validates if a user can create an entity with the specified organization/control centre
23
+ * @param accessScope - The access scope for the user
24
+ * @param createDto - The DTO containing organizationId/controlCentreId
25
+ * @param entityName - The name of the entity (for error messages)
26
+ */
27
+ validateCreateAccess<T extends CreateEntityAccessCheck>(accessScope: AccessScope, createDto: T, entityName?: string): void;
28
+ /**
29
+ * Validates if a user has access to update entities
30
+ * @param accessScope - The access scope for the user
31
+ * @param entityName - The name of the entity (for error messages)
32
+ */
33
+ validateUpdateAccess(accessScope: AccessScope, entityName?: string): void;
34
+ /**
35
+ * Validates if a user has access to delete entities
36
+ * @param accessScope - The access scope for the user
37
+ * @param entityName - The name of the entity (for error messages)
38
+ */
39
+ validateDeleteAccess(accessScope: AccessScope, entityName?: string): void;
40
+ /**
41
+ * Validates if a user can update an entity with the specified organization/control centre changes
42
+ * @param accessScope - The access scope for the user
43
+ * @param existingEntity - The existing entity
44
+ * @param updateDto - The DTO containing updated organizationId/controlCentreId
45
+ * @param entityName - The name of the entity (for error messages)
46
+ */
47
+ validateUpdateEntityAccess<T extends EntityAccessCheck, U extends UpdateEntityAccessCheck>(accessScope: AccessScope, existingEntity: T, updateDto: U, entityName?: string): void;
48
+ }
@@ -0,0 +1 @@
1
+ export * from './access-validation.service';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "grm-shared-library",
3
- "version": "1.1.39",
3
+ "version": "1.1.40",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "types": "dist/types/index.d.ts",