mftsccs-node 0.2.19 → 0.2.20
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/bundle.js +1 -1
- package/dist/types/DataStructures/AccessControl/AccessControlModels.d.ts +12 -2
- package/dist/types/Services/AccessControl/APIClientService.d.ts +21 -1
- package/dist/types/Services/AccessControl/AccessControlCacheService.d.ts +14 -11
- package/dist/types/Services/AccessControl/AccessControlService.d.ts +91 -16
- package/dist/types/Services/AccessControl/index.d.ts +1 -1
- package/package.json +1 -1
|
@@ -46,10 +46,12 @@ export interface BulkAccessRequest {
|
|
|
46
46
|
}
|
|
47
47
|
/**
|
|
48
48
|
* Request model for bulk check access operations
|
|
49
|
+
* Mirrors C# BulkCheckAccessRequest
|
|
49
50
|
*/
|
|
50
51
|
export interface BulkCheckAccessRequest {
|
|
51
|
-
|
|
52
|
-
|
|
52
|
+
accessIds: number[];
|
|
53
|
+
permission: string;
|
|
54
|
+
entityId?: number | null;
|
|
53
55
|
}
|
|
54
56
|
/**
|
|
55
57
|
* Request model for access inheritance operations
|
|
@@ -65,6 +67,14 @@ export interface AccessInheritanceRequest {
|
|
|
65
67
|
export interface SuperAdminRequest {
|
|
66
68
|
accessId?: number | null;
|
|
67
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Request model for parent access inheritance operations
|
|
72
|
+
* Mirrors C# ParentAccessInheritanceRequest
|
|
73
|
+
*/
|
|
74
|
+
export interface ParentAccessInheritanceRequest {
|
|
75
|
+
parentAccessId: number;
|
|
76
|
+
childAccessId?: number | null;
|
|
77
|
+
}
|
|
68
78
|
/**
|
|
69
79
|
* Standard API response wrapper for access control endpoints
|
|
70
80
|
*/
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* This is the TypeScript equivalent of the C# APIClientService class.
|
|
8
8
|
*/
|
|
9
|
-
import { AccessRequest, AccessResult, AccessControlAPIResponse, BulkAccessRequest, BulkCheckAccessRequest, AccessInheritanceRequest, SuperAdminRequest } from '../../DataStructures/AccessControl/AccessControlModels';
|
|
9
|
+
import { AccessRequest, AccessResult, AccessControlAPIResponse, BulkAccessRequest, BulkCheckAccessRequest, AccessInheritanceRequest, SuperAdminRequest, ParentAccessInheritanceRequest } from '../../DataStructures/AccessControl/AccessControlModels';
|
|
10
10
|
export interface IAPIClientService {
|
|
11
11
|
assignAccessAsync(request: AccessRequest): Promise<AccessControlAPIResponse<AccessResult>>;
|
|
12
12
|
checkAccessAsync(request: AccessRequest): Promise<AccessControlAPIResponse<AccessResult>>;
|
|
@@ -20,6 +20,10 @@ export interface IAPIClientService {
|
|
|
20
20
|
assignSuperAdminAccessAsync(request: SuperAdminRequest): Promise<AccessControlAPIResponse>;
|
|
21
21
|
revokeSuperAdminAccessAsync(request: SuperAdminRequest): Promise<AccessControlAPIResponse>;
|
|
22
22
|
checkSuperAdminStatusAsync(accessId: number): Promise<AccessControlAPIResponse>;
|
|
23
|
+
setParentAccessInheritanceAsync(request: ParentAccessInheritanceRequest): Promise<AccessControlAPIResponse>;
|
|
24
|
+
removeParentAccessInheritanceAsync(accessId: number, parentAccessId?: number): Promise<AccessControlAPIResponse>;
|
|
25
|
+
hasParentAccessInheritanceAsync(accessId: number, parentAccessId?: number): Promise<AccessControlAPIResponse>;
|
|
26
|
+
getParentAccessIdAsync(accessId: number): Promise<AccessControlAPIResponse>;
|
|
23
27
|
}
|
|
24
28
|
export declare class APIClientService implements IAPIClientService {
|
|
25
29
|
private readonly baseUrl;
|
|
@@ -84,4 +88,20 @@ export declare class APIClientService implements IAPIClientService {
|
|
|
84
88
|
* Check super admin status
|
|
85
89
|
*/
|
|
86
90
|
checkSuperAdminStatusAsync(accessId: number): Promise<AccessControlAPIResponse>;
|
|
91
|
+
/**
|
|
92
|
+
* Set parent access inheritance link
|
|
93
|
+
*/
|
|
94
|
+
setParentAccessInheritanceAsync(request: ParentAccessInheritanceRequest): Promise<AccessControlAPIResponse>;
|
|
95
|
+
/**
|
|
96
|
+
* Remove parent access inheritance link
|
|
97
|
+
*/
|
|
98
|
+
removeParentAccessInheritanceAsync(accessId: number, parentAccessId?: number): Promise<AccessControlAPIResponse>;
|
|
99
|
+
/**
|
|
100
|
+
* Check if parent access inheritance link exists
|
|
101
|
+
*/
|
|
102
|
+
hasParentAccessInheritanceAsync(accessId: number, parentAccessId?: number): Promise<AccessControlAPIResponse>;
|
|
103
|
+
/**
|
|
104
|
+
* Get the parent access ID for a given access ID
|
|
105
|
+
*/
|
|
106
|
+
getParentAccessIdAsync(accessId: number): Promise<AccessControlAPIResponse>;
|
|
87
107
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* CacheService
|
|
3
3
|
*
|
|
4
|
-
* Thread-safe in-memory cache for access checks.
|
|
4
|
+
* Thread-safe in-memory cache for access checks with TTL-based expiration.
|
|
5
5
|
* Supports single and bulk queries with secondary indexes.
|
|
6
6
|
* Key format: "{accessId}:{permission}:{entityId}"
|
|
7
|
-
* Value: boolean
|
|
7
|
+
* Value: CacheEntry { value: boolean, expiresAt: number }
|
|
8
8
|
*
|
|
9
9
|
* This is the TypeScript equivalent of the C# CacheService class.
|
|
10
10
|
*/
|
|
@@ -25,16 +25,17 @@ export declare class CacheService implements ICacheService {
|
|
|
25
25
|
private readonly accessIndex;
|
|
26
26
|
private readonly entityIndex;
|
|
27
27
|
private static readonly superAdminCache;
|
|
28
|
+
private setCounter;
|
|
28
29
|
/**
|
|
29
30
|
* Generate a cache key from accessId, permission, and entityId
|
|
30
31
|
*/
|
|
31
32
|
private generateKey;
|
|
32
33
|
/**
|
|
33
|
-
* Get cached access. Returns true/false if present, null if not cached.
|
|
34
|
+
* Get cached access. Returns true/false if present and not expired, null if not cached or expired.
|
|
34
35
|
*/
|
|
35
36
|
get(accessId: number, permission: string, entityId?: number | null): boolean | null;
|
|
36
37
|
/**
|
|
37
|
-
* Set or update cached access
|
|
38
|
+
* Set or update cached access with TTL
|
|
38
39
|
*/
|
|
39
40
|
set(accessId: number, permission: string, entityId: number | null | undefined, hasAccess: boolean): void;
|
|
40
41
|
/**
|
|
@@ -46,25 +47,27 @@ export declare class CacheService implements ICacheService {
|
|
|
46
47
|
*/
|
|
47
48
|
clear(): void;
|
|
48
49
|
/**
|
|
49
|
-
*
|
|
50
|
+
* Sweep all expired entries from access cache, indexes, and super admin cache
|
|
51
|
+
*/
|
|
52
|
+
private sweepExpired;
|
|
53
|
+
/**
|
|
54
|
+
* Get all permissions for a specific accessId + entityId (excludes expired entries)
|
|
50
55
|
*/
|
|
51
56
|
getPermissionsByAccessAndEntity(accessId: number, entityId?: number | null): Map<string, boolean>;
|
|
52
57
|
/**
|
|
53
|
-
* Get all permissions for a specific accessId across all entities
|
|
54
|
-
* Returns a Map with key tuple (entityId, permission) and value hasAccess
|
|
58
|
+
* Get all permissions for a specific accessId across all entities (excludes expired entries)
|
|
55
59
|
*/
|
|
56
60
|
getPermissionsByAccess(accessId: number): Map<string, boolean>;
|
|
57
61
|
/**
|
|
58
|
-
* Get all permissions for a specific entity across all accessIds
|
|
59
|
-
* Returns a Map with key tuple (accessId, permission) and value hasAccess
|
|
62
|
+
* Get all permissions for a specific entity across all accessIds (excludes expired entries)
|
|
60
63
|
*/
|
|
61
64
|
getPermissionsByEntity(entityId: number): Map<string, boolean>;
|
|
62
65
|
/**
|
|
63
|
-
* Get cached super admin status for an entity
|
|
66
|
+
* Get cached super admin status for an entity (returns null if expired or not cached)
|
|
64
67
|
*/
|
|
65
68
|
getSuperAdmin(entityId: number): boolean | null;
|
|
66
69
|
/**
|
|
67
|
-
* Set super admin status for an entity
|
|
70
|
+
* Set super admin status for an entity with TTL
|
|
68
71
|
*/
|
|
69
72
|
setSuperAdmin(entityId: number, isSuperAdmin: boolean): void;
|
|
70
73
|
/**
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
* AccessControlService
|
|
3
3
|
*
|
|
4
4
|
* This service provides access control functionality including:
|
|
5
|
-
* -
|
|
5
|
+
* - 5-phase bulk access check with BFS inheritance graph traversal
|
|
6
6
|
* - Assign and revoke access permissions
|
|
7
7
|
* - Bulk operations for access management
|
|
8
8
|
* - Super admin checks with caching
|
|
9
|
-
* - Access inheritance management
|
|
9
|
+
* - Access inheritance management (including parent access inheritance)
|
|
10
10
|
*
|
|
11
|
-
* This is the TypeScript equivalent of the C# AccessControlService class.
|
|
11
|
+
* This is the TypeScript equivalent of the C# AccessControlService class (v3.4.0).
|
|
12
12
|
* All methods are static and can be called directly on the class.
|
|
13
13
|
*/
|
|
14
14
|
import { AccessResult, BulkAccessRequest } from '../../DataStructures/AccessControl/AccessControlModels';
|
|
@@ -18,8 +18,8 @@ export declare class AccessControlService {
|
|
|
18
18
|
private static apiClient;
|
|
19
19
|
private static initialize;
|
|
20
20
|
/**
|
|
21
|
-
* Check whether a user/entity has the specified permission.
|
|
22
|
-
*
|
|
21
|
+
* Check whether a user/entity has the specified permission on a single concept.
|
|
22
|
+
* Delegates to checkAccessBulk for full inheritance + group resolution.
|
|
23
23
|
*
|
|
24
24
|
* @param conceptId - The ID of the concept to check access for
|
|
25
25
|
* @param permission - The permission to check (PermissionSet flags)
|
|
@@ -27,9 +27,25 @@ export declare class AccessControlService {
|
|
|
27
27
|
* @returns Promise<boolean> - True if access is granted, false otherwise
|
|
28
28
|
*/
|
|
29
29
|
static checkAccess(conceptId: number, permission: PermissionSet, entityId?: number | null): Promise<boolean>;
|
|
30
|
+
/**
|
|
31
|
+
* 5-phase bulk access check algorithm.
|
|
32
|
+
* Matches the C# AccessControlService.CheckAccessBulk implementation.
|
|
33
|
+
*
|
|
34
|
+
* Phase 1: Super-admin short-circuit
|
|
35
|
+
* Phase 2: Fast-path classification (owner, public, type concepts)
|
|
36
|
+
* Phase 3: BFS inheritance graph resolution (3 sources)
|
|
37
|
+
* Phase 4: Bulk access decision resolution (cache + API)
|
|
38
|
+
* Phase 5: Grant-only merge per concept
|
|
39
|
+
*
|
|
40
|
+
* @param conceptIds - List of concept IDs to check
|
|
41
|
+
* @param permission - The permission to check (PermissionSet flags)
|
|
42
|
+
* @param entityId - Optional entity ID
|
|
43
|
+
* @returns Promise<Map<number, boolean>> - conceptId → hasAccess
|
|
44
|
+
*/
|
|
45
|
+
static checkAccessBulk(conceptIds: number[], permission: PermissionSet, entityId?: number | null): Promise<Map<number, boolean>>;
|
|
30
46
|
/**
|
|
31
47
|
* Get all conceptIds which have a certain permission for an entity.
|
|
32
|
-
*
|
|
48
|
+
* Delegates to checkAccessBulk for full inheritance support.
|
|
33
49
|
*
|
|
34
50
|
* @param permission - The permission to check (PermissionSet flags)
|
|
35
51
|
* @param conceptIdsFilter - List of concept IDs to filter
|
|
@@ -37,6 +53,32 @@ export declare class AccessControlService {
|
|
|
37
53
|
* @returns Promise<number[]> - Array of concept IDs that have the permission
|
|
38
54
|
*/
|
|
39
55
|
static getConceptIdsWithPermission(permission: PermissionSet, conceptIdsFilter: number[], entityId?: number | null): Promise<number[]>;
|
|
56
|
+
/**
|
|
57
|
+
* Resolve inheritance graph via 3-source BFS, depth-limited to MAX_BFS_DEPTH.
|
|
58
|
+
*
|
|
59
|
+
* Source 1: FreeSchema internal connections ("the_parent_access_inheritance")
|
|
60
|
+
* Source 2: Explicit parent access links (via Access API)
|
|
61
|
+
* Source 3: Concept-connection access inheritance
|
|
62
|
+
*
|
|
63
|
+
* @returns Map<number, number[]> — accessId → [self, parent1, grandparent1, ...]
|
|
64
|
+
*/
|
|
65
|
+
private static resolveBulkInheritanceGraph;
|
|
66
|
+
/**
|
|
67
|
+
* Resolve access decisions for all (accessId × subject) combinations.
|
|
68
|
+
* Probes cache first, then makes bulk API calls for misses.
|
|
69
|
+
*
|
|
70
|
+
* @returns Map with key "accessId:subjectId" → hasAccess
|
|
71
|
+
*/
|
|
72
|
+
private static resolveBulkDecisions;
|
|
73
|
+
/**
|
|
74
|
+
* Resolve all subjects for an entity: [null, entityId, ...groupIds]
|
|
75
|
+
*/
|
|
76
|
+
private static resolveSubjects;
|
|
77
|
+
/**
|
|
78
|
+
* Check if any grant exists across own chain + type chain for any subject.
|
|
79
|
+
* Grant-only model: any grant → ALLOW, no grants → DENY.
|
|
80
|
+
*/
|
|
81
|
+
private static hasAnyGrant;
|
|
40
82
|
/**
|
|
41
83
|
* Assign access permission to an entity
|
|
42
84
|
*
|
|
@@ -93,6 +135,37 @@ export declare class AccessControlService {
|
|
|
93
135
|
* @returns Promise<boolean> - True if successful, false otherwise
|
|
94
136
|
*/
|
|
95
137
|
static setAccessInheritanceStatus(conceptId: number, isEnabled: boolean, connectionTypeId?: number): Promise<boolean>;
|
|
138
|
+
/**
|
|
139
|
+
* Set parent access inheritance link for a concept
|
|
140
|
+
*
|
|
141
|
+
* @param conceptId - The child concept ID
|
|
142
|
+
* @param parentAccessId - The parent access ID to inherit from
|
|
143
|
+
* @returns Promise<number> - The new access ID, or existing access ID
|
|
144
|
+
*/
|
|
145
|
+
static setParentAccessInheritance(conceptId: number, parentAccessId: number): Promise<number>;
|
|
146
|
+
/**
|
|
147
|
+
* Remove parent access inheritance link
|
|
148
|
+
*
|
|
149
|
+
* @param conceptId - The child concept ID
|
|
150
|
+
* @param parentAccessId - Optional parent access ID (removes specific link or all)
|
|
151
|
+
* @returns Promise<string> - Status message
|
|
152
|
+
*/
|
|
153
|
+
static removeParentAccessInheritance(conceptId: number, parentAccessId?: number): Promise<string>;
|
|
154
|
+
/**
|
|
155
|
+
* Check if parent access inheritance link exists
|
|
156
|
+
*
|
|
157
|
+
* @param conceptId - The child concept ID
|
|
158
|
+
* @param parentAccessId - Optional parent access ID to check specific link
|
|
159
|
+
* @returns Promise<boolean> - True if link exists
|
|
160
|
+
*/
|
|
161
|
+
static hasParentAccessInheritance(conceptId: number, parentAccessId?: number): Promise<boolean>;
|
|
162
|
+
/**
|
|
163
|
+
* Get the parent access ID for a concept
|
|
164
|
+
*
|
|
165
|
+
* @param conceptId - The child concept ID
|
|
166
|
+
* @returns Promise<number | null> - Parent access ID or null
|
|
167
|
+
*/
|
|
168
|
+
static getParentAccessId(conceptId: number): Promise<number | null>;
|
|
96
169
|
/**
|
|
97
170
|
* Check if an entity is a super admin
|
|
98
171
|
* Uses caching for performance
|
|
@@ -116,19 +189,21 @@ export declare class AccessControlService {
|
|
|
116
189
|
*/
|
|
117
190
|
static revokeSuperAdmin(entityId: number): Promise<string>;
|
|
118
191
|
/**
|
|
119
|
-
*
|
|
192
|
+
* Parse boolean from API response data.
|
|
193
|
+
* Handles: raw boolean, string, object with known property names.
|
|
194
|
+
* Matches C# ParseBoolData helper.
|
|
120
195
|
*/
|
|
121
|
-
private static
|
|
196
|
+
private static parseBoolData;
|
|
122
197
|
/**
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
* @param permission - The permission to check (string)
|
|
127
|
-
* @param entityId - Optional entity ID
|
|
128
|
-
* @returns Promise<boolean> - True if access is granted, false otherwise
|
|
198
|
+
* Parse integer from API response data.
|
|
199
|
+
* Handles: raw number, string, object with known property names.
|
|
200
|
+
* Matches C# ParseIntData helper.
|
|
129
201
|
*/
|
|
130
|
-
private static
|
|
131
|
-
|
|
202
|
+
private static parseIntData;
|
|
203
|
+
/**
|
|
204
|
+
* Convert PermissionSet to string for API calls
|
|
205
|
+
*/
|
|
206
|
+
private static permissionSetToString;
|
|
132
207
|
/**
|
|
133
208
|
* Clear all access cache entries
|
|
134
209
|
*/
|
|
@@ -12,4 +12,4 @@ export { AccessControlService } from './AccessControlService';
|
|
|
12
12
|
export { CacheService, ICacheService } from './AccessControlCacheService';
|
|
13
13
|
export { APIClientService, IAPIClientService } from './APIClientService';
|
|
14
14
|
export { PermissionSet, getPermissionSetFromStrings, getStringsFromPermissionSet, isValidPermission } from './PermissionSet';
|
|
15
|
-
export { PermissionSet as PermissionSetEnum, AccessRequest, AccessResult, BulkAccessRequest, BulkAccessTarget, BulkCheckAccessRequest, AccessInheritanceRequest, SuperAdminRequest, AccessControlAPIResponse, AccessControlApiResponse, AddAccessByEntityRequest, AddPublicAccessToConcept, AddAccessByEntityBulkRequest, AddAccessByUserRequest, CheckAccessBulk, VALID_PERMISSIONS, isValidPermission as isValidPermissionFromModels } from '../../DataStructures/AccessControl/AccessControlModels';
|
|
15
|
+
export { PermissionSet as PermissionSetEnum, AccessRequest, AccessResult, BulkAccessRequest, BulkAccessTarget, BulkCheckAccessRequest, AccessInheritanceRequest, SuperAdminRequest, AccessControlAPIResponse, AccessControlApiResponse, AddAccessByEntityRequest, AddPublicAccessToConcept, AddAccessByEntityBulkRequest, AddAccessByUserRequest, CheckAccessBulk, ParentAccessInheritanceRequest, VALID_PERMISSIONS, isValidPermission as isValidPermissionFromModels } from '../../DataStructures/AccessControl/AccessControlModels';
|