@intellegens/cornerstone-client 0.0.0-experimental-upgrade-20260302-1
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/README.md +256 -0
- package/demo/index.ts +29 -0
- package/demo/public_html/favicon.ico +0 -0
- package/demo/public_html/index.html +106 -0
- package/demo/public_html/websettings.json +3 -0
- package/dist/adapters/CollectionViewAdapter/index.d.ts +198 -0
- package/dist/adapters/CollectionViewAdapter/index.integration.test.d.ts +1 -0
- package/dist/adapters/CollectionViewAdapter/index.integration.test.js +163 -0
- package/dist/adapters/CollectionViewAdapter/index.js +381 -0
- package/dist/adapters/SearchAdapter/index.d.ts +55 -0
- package/dist/adapters/SearchAdapter/index.js +233 -0
- package/dist/adapters/index.d.ts +2 -0
- package/dist/adapters/index.js +2 -0
- package/dist/data/api/dto/PropertyPathDto.d.ts +4 -0
- package/dist/data/api/dto/PropertyPathDto.js +1 -0
- package/dist/data/api/dto/ReadOptionsDto.d.ts +8 -0
- package/dist/data/api/dto/ReadOptionsDto.js +1 -0
- package/dist/data/api/dto/ReadResultDto.d.ts +12 -0
- package/dist/data/api/dto/ReadResultDto.js +1 -0
- package/dist/data/api/dto/ReadResultMetadataDto.d.ts +8 -0
- package/dist/data/api/dto/ReadResultMetadataDto.js +1 -0
- package/dist/data/api/dto/crud/CrudMetadataDto.d.ts +4 -0
- package/dist/data/api/dto/crud/CrudMetadataDto.js +1 -0
- package/dist/data/api/dto/crud/index.d.ts +1 -0
- package/dist/data/api/dto/crud/index.js +1 -0
- package/dist/data/api/dto/index.d.ts +4 -0
- package/dist/data/api/dto/index.js +4 -0
- package/dist/data/api/dto/read/ReadMetadataDto.d.ts +8 -0
- package/dist/data/api/dto/read/ReadMetadataDto.js +1 -0
- package/dist/data/api/dto/read/ReadSelectedDefinitionDto.d.ts +18 -0
- package/dist/data/api/dto/read/ReadSelectedDefinitionDto.js +1 -0
- package/dist/data/api/dto/read/ReadSelectedNestedCollectionCriteriaDto.d.ts +22 -0
- package/dist/data/api/dto/read/ReadSelectedNestedCollectionCriteriaDto.js +1 -0
- package/dist/data/api/dto/read/ReadSelectedNestedCriteriaDto.d.ts +18 -0
- package/dist/data/api/dto/read/ReadSelectedNestedCriteriaDto.js +1 -0
- package/dist/data/api/dto/read/ReadSelectedOrderingDefinitionDto.d.ts +7 -0
- package/dist/data/api/dto/read/ReadSelectedOrderingDefinitionDto.js +1 -0
- package/dist/data/api/dto/read/ReadSelectedOrderingPropertyDefinitionDto.d.ts +14 -0
- package/dist/data/api/dto/read/ReadSelectedOrderingPropertyDefinitionDto.js +1 -0
- package/dist/data/api/dto/read/ReadSelectedPaginationDefinitionDto.d.ts +13 -0
- package/dist/data/api/dto/read/ReadSelectedPaginationDefinitionDto.js +1 -0
- package/dist/data/api/dto/read/ReadSelectedSearchDefinitionBuilder.d.ts +167 -0
- package/dist/data/api/dto/read/ReadSelectedSearchDefinitionBuilder.js +267 -0
- package/dist/data/api/dto/read/ReadSelectedSearchDefinitionDto.d.ts +33 -0
- package/dist/data/api/dto/read/ReadSelectedSearchDefinitionDto.js +1 -0
- package/dist/data/api/dto/read/ReadSelectedSearchPropertyDefinitionDto.d.ts +114 -0
- package/dist/data/api/dto/read/ReadSelectedSearchPropertyDefinitionDto.js +1 -0
- package/dist/data/api/dto/read/index.d.ts +10 -0
- package/dist/data/api/dto/read/index.js +10 -0
- package/dist/data/api/dto/response/ApiErrorDto.d.ts +17 -0
- package/dist/data/api/dto/response/ApiErrorDto.js +1 -0
- package/dist/data/api/dto/response/ApiErrorResponseDto.d.ts +11 -0
- package/dist/data/api/dto/response/ApiErrorResponseDto.js +1 -0
- package/dist/data/api/dto/response/ApiResponseDto.d.ts +3 -0
- package/dist/data/api/dto/response/ApiResponseDto.js +1 -0
- package/dist/data/api/dto/response/ApiSuccessResponseDto.d.ts +13 -0
- package/dist/data/api/dto/response/ApiSuccessResponseDto.js +1 -0
- package/dist/data/api/dto/response/EmptyMetadataDto.d.ts +4 -0
- package/dist/data/api/dto/response/EmptyMetadataDto.js +1 -0
- package/dist/data/api/dto/response/MetadataDto.d.ts +25 -0
- package/dist/data/api/dto/response/MetadataDto.js +1 -0
- package/dist/data/api/dto/response/index.d.ts +5 -0
- package/dist/data/api/dto/response/index.js +5 -0
- package/dist/data/api/enum/index.d.ts +2 -0
- package/dist/data/api/enum/index.js +2 -0
- package/dist/data/api/enum/read/ReadSelectedCollectionOperator.d.ts +16 -0
- package/dist/data/api/enum/read/ReadSelectedCollectionOperator.js +17 -0
- package/dist/data/api/enum/read/ReadSelectedComparisonOperator.d.ts +69 -0
- package/dist/data/api/enum/read/ReadSelectedComparisonOperator.js +76 -0
- package/dist/data/api/enum/read/ReadSelectedLogicalOperator.d.ts +15 -0
- package/dist/data/api/enum/read/ReadSelectedLogicalOperator.js +16 -0
- package/dist/data/api/enum/read/ReadSelectedOrderingDirection.d.ts +13 -0
- package/dist/data/api/enum/read/ReadSelectedOrderingDirection.js +14 -0
- package/dist/data/api/enum/read/ReadSelectedPropertyType.d.ts +66 -0
- package/dist/data/api/enum/read/ReadSelectedPropertyType.js +75 -0
- package/dist/data/api/enum/read/index.d.ts +5 -0
- package/dist/data/api/enum/read/index.js +5 -0
- package/dist/data/api/enum/response/ApiErrorCodes.d.ts +7 -0
- package/dist/data/api/enum/response/ApiErrorCodes.js +8 -0
- package/dist/data/api/enum/response/ErrorCode.d.ts +13 -0
- package/dist/data/api/enum/response/ErrorCode.js +14 -0
- package/dist/data/api/enum/response/index.d.ts +1 -0
- package/dist/data/api/enum/response/index.js +1 -0
- package/dist/data/api/index.d.ts +3 -0
- package/dist/data/api/index.js +3 -0
- package/dist/data/api/interface/ICommonIdentifiable.d.ts +7 -0
- package/dist/data/api/interface/ICommonIdentifiable.js +1 -0
- package/dist/data/api/interface/IConcurrencySafe.d.ts +9 -0
- package/dist/data/api/interface/IConcurrencySafe.js +2 -0
- package/dist/data/api/interface/IIdentifiable.d.ts +11 -0
- package/dist/data/api/interface/IIdentifiable.js +1 -0
- package/dist/data/api/interface/IIdentifiableSecondary.d.ts +9 -0
- package/dist/data/api/interface/IIdentifiableSecondary.js +1 -0
- package/dist/data/api/interface/index.d.ts +3 -0
- package/dist/data/api/interface/index.js +3 -0
- package/dist/data/auth/dto/ClaimDto.d.ts +4 -0
- package/dist/data/auth/dto/ClaimDto.js +1 -0
- package/dist/data/auth/dto/RegisterRequestDto.d.ts +4 -0
- package/dist/data/auth/dto/RegisterRequestDto.js +1 -0
- package/dist/data/auth/dto/RoleDto.d.ts +5 -0
- package/dist/data/auth/dto/RoleDto.js +1 -0
- package/dist/data/auth/dto/SignInRequestDto.d.ts +4 -0
- package/dist/data/auth/dto/SignInRequestDto.js +1 -0
- package/dist/data/auth/dto/TokensDto.d.ts +4 -0
- package/dist/data/auth/dto/TokensDto.js +1 -0
- package/dist/data/auth/dto/UserDto.d.ts +17 -0
- package/dist/data/auth/dto/UserDto.js +1 -0
- package/dist/data/auth/dto/UserInfoDto.d.ts +14 -0
- package/dist/data/auth/dto/UserInfoDto.js +1 -0
- package/dist/data/auth/dto/index.d.ts +5 -0
- package/dist/data/auth/dto/index.js +5 -0
- package/dist/data/auth/index.d.ts +2 -0
- package/dist/data/auth/index.js +2 -0
- package/dist/data/auth/policy.d.ts +52 -0
- package/dist/data/auth/policy.js +44 -0
- package/dist/data/index.d.ts +2 -0
- package/dist/data/index.js +2 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/services/api/ApiCrudControllerClient/index.d.ts +41 -0
- package/dist/services/api/ApiCrudControllerClient/index.integration.test.d.ts +1 -0
- package/dist/services/api/ApiCrudControllerClient/index.integration.test.js +34 -0
- package/dist/services/api/ApiCrudControllerClient/index.js +116 -0
- package/dist/services/api/ApiInitializationService/index.d.ts +106 -0
- package/dist/services/api/ApiInitializationService/index.js +208 -0
- package/dist/services/api/ApiReadControllerClient/index.d.ts +40 -0
- package/dist/services/api/ApiReadControllerClient/index.integration.test.d.ts +1 -0
- package/dist/services/api/ApiReadControllerClient/index.integration.test.js +59 -0
- package/dist/services/api/ApiReadControllerClient/index.js +111 -0
- package/dist/services/api/HttpService/FetchHttpService.d.ts +7 -0
- package/dist/services/api/HttpService/FetchHttpService.integration.test.d.ts +1 -0
- package/dist/services/api/HttpService/FetchHttpService.integration.test.js +52 -0
- package/dist/services/api/HttpService/FetchHttpService.js +29 -0
- package/dist/services/api/HttpService/HttpRequestConfig.d.ts +10 -0
- package/dist/services/api/HttpService/HttpRequestConfig.js +1 -0
- package/dist/services/api/HttpService/HttpResponse.d.ts +11 -0
- package/dist/services/api/HttpService/HttpResponse.js +3 -0
- package/dist/services/api/HttpService/IHttpService.d.ts +13 -0
- package/dist/services/api/HttpService/IHttpService.js +3 -0
- package/dist/services/api/HttpService/index.d.ts +9 -0
- package/dist/services/api/HttpService/index.js +10 -0
- package/dist/services/api/UserManagementControllerClient/index.d.ts +41 -0
- package/dist/services/api/UserManagementControllerClient/index.integration.test.d.ts +1 -0
- package/dist/services/api/UserManagementControllerClient/index.integration.test.js +60 -0
- package/dist/services/api/UserManagementControllerClient/index.js +117 -0
- package/dist/services/api/index.d.ts +5 -0
- package/dist/services/api/index.js +5 -0
- package/dist/services/auth/client/AuthService/index.d.ts +75 -0
- package/dist/services/auth/client/AuthService/index.js +200 -0
- package/dist/services/auth/client/AuthorizationManagementControllerClient/index.d.ts +48 -0
- package/dist/services/auth/client/AuthorizationManagementControllerClient/index.integration.test.d.ts +1 -0
- package/dist/services/auth/client/AuthorizationManagementControllerClient/index.integration.test.js +89 -0
- package/dist/services/auth/client/AuthorizationManagementControllerClient/index.js +148 -0
- package/dist/services/auth/client/index.d.ts +2 -0
- package/dist/services/auth/client/index.js +2 -0
- package/dist/services/auth/index.d.ts +1 -0
- package/dist/services/auth/index.js +1 -0
- package/dist/services/index.d.ts +2 -0
- package/dist/services/index.js +2 -0
- package/dist/utils/authorization/index.d.ts +17 -0
- package/dist/utils/authorization/index.js +45 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/result/index.d.ts +21 -0
- package/dist/utils/result/index.js +16 -0
- package/dist/utils/search/index.d.ts +34 -0
- package/dist/utils/search/index.js +106 -0
- package/package.json +45 -0
- package/src/adapters/CollectionViewAdapter/index.integration.test.ts +197 -0
- package/src/adapters/CollectionViewAdapter/index.ts +477 -0
- package/src/adapters/SearchAdapter/index.ts +302 -0
- package/src/adapters/index.ts +2 -0
- package/src/data/api/dto/PropertyPathDto.ts +4 -0
- package/src/data/api/dto/ReadOptionsDto.ts +8 -0
- package/src/data/api/dto/ReadResultDto.ts +13 -0
- package/src/data/api/dto/ReadResultMetadataDto.ts +8 -0
- package/src/data/api/dto/crud/CrudMetadataDto.ts +4 -0
- package/src/data/api/dto/crud/index.ts +1 -0
- package/src/data/api/dto/index.ts +4 -0
- package/src/data/api/dto/read/ReadMetadataDto.ts +8 -0
- package/src/data/api/dto/read/ReadSelectedDefinitionDto.ts +21 -0
- package/src/data/api/dto/read/ReadSelectedNestedCollectionCriteriaDto.ts +25 -0
- package/src/data/api/dto/read/ReadSelectedNestedCriteriaDto.ts +20 -0
- package/src/data/api/dto/read/ReadSelectedOrderingDefinitionDto.ts +8 -0
- package/src/data/api/dto/read/ReadSelectedOrderingPropertyDefinitionDto.ts +16 -0
- package/src/data/api/dto/read/ReadSelectedPaginationDefinitionDto.ts +13 -0
- package/src/data/api/dto/read/ReadSelectedSearchDefinitionBuilder.ts +348 -0
- package/src/data/api/dto/read/ReadSelectedSearchDefinitionDto.ts +43 -0
- package/src/data/api/dto/read/ReadSelectedSearchPropertyDefinitionDto.ts +186 -0
- package/src/data/api/dto/read/index.ts +10 -0
- package/src/data/api/dto/response/ApiErrorDto.ts +21 -0
- package/src/data/api/dto/response/ApiErrorResponseDto.ts +13 -0
- package/src/data/api/dto/response/ApiResponseDto.ts +7 -0
- package/src/data/api/dto/response/ApiSuccessResponseDto.ts +13 -0
- package/src/data/api/dto/response/MetadataDto.ts +24 -0
- package/src/data/api/dto/response/index.ts +5 -0
- package/src/data/api/enum/index.ts +2 -0
- package/src/data/api/enum/read/ReadSelectedCollectionOperator.ts +17 -0
- package/src/data/api/enum/read/ReadSelectedComparisonOperator.ts +96 -0
- package/src/data/api/enum/read/ReadSelectedLogicalOperator.ts +16 -0
- package/src/data/api/enum/read/ReadSelectedOrderingDirection.ts +13 -0
- package/src/data/api/enum/read/ReadSelectedPropertyType.ts +96 -0
- package/src/data/api/enum/read/index.ts +5 -0
- package/src/data/api/enum/response/ErrorCode.ts +13 -0
- package/src/data/api/enum/response/index.ts +1 -0
- package/src/data/api/index.ts +3 -0
- package/src/data/api/interface/ICommonIdentifiable.ts +9 -0
- package/src/data/api/interface/IConcurrencySafe.ts +9 -0
- package/src/data/api/interface/IIdentifiable.ts +12 -0
- package/src/data/api/interface/IIdentifiableSecondary.ts +9 -0
- package/src/data/api/interface/index.ts +3 -0
- package/src/data/auth/dto/ClaimDto.ts +4 -0
- package/src/data/auth/dto/RegisterRequestDto.ts +4 -0
- package/src/data/auth/dto/RoleDto.ts +6 -0
- package/src/data/auth/dto/SignInRequestDto.ts +4 -0
- package/src/data/auth/dto/TokensDto.ts +4 -0
- package/src/data/auth/dto/UserDto.ts +18 -0
- package/src/data/auth/dto/UserInfoDto.ts +15 -0
- package/src/data/auth/dto/index.ts +5 -0
- package/src/data/auth/index.ts +2 -0
- package/src/data/auth/policy.ts +63 -0
- package/src/data/index.ts +2 -0
- package/src/index.ts +4 -0
- package/src/services/api/ApiCrudControllerClient/index.integration.test.ts +46 -0
- package/src/services/api/ApiCrudControllerClient/index.ts +135 -0
- package/src/services/api/ApiInitializationService/index.ts +254 -0
- package/src/services/api/ApiReadControllerClient/index.integration.test.ts +71 -0
- package/src/services/api/ApiReadControllerClient/index.ts +137 -0
- package/src/services/api/HttpService/FetchHttpService.integration.test.ts +65 -0
- package/src/services/api/HttpService/FetchHttpService.ts +34 -0
- package/src/services/api/HttpService/HttpRequestConfig.ts +10 -0
- package/src/services/api/HttpService/HttpResponse.ts +14 -0
- package/src/services/api/HttpService/IHttpService.ts +17 -0
- package/src/services/api/HttpService/README.md +106 -0
- package/src/services/api/HttpService/index.ts +12 -0
- package/src/services/api/UserManagementControllerClient/index.integration.test.ts +69 -0
- package/src/services/api/UserManagementControllerClient/index.ts +134 -0
- package/src/services/api/index.ts +5 -0
- package/src/services/auth/client/AuthService/index.ts +233 -0
- package/src/services/auth/client/AuthorizationManagementControllerClient/index.integration.test.ts +110 -0
- package/src/services/auth/client/AuthorizationManagementControllerClient/index.ts +165 -0
- package/src/services/auth/client/index.ts +2 -0
- package/src/services/auth/index.ts +1 -0
- package/src/services/index.ts +2 -0
- package/src/utils/authorization/index.ts +47 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/result/index.ts +25 -0
- package/src/utils/search/index.ts +150 -0
- package/tsconfig.json +19 -0
- package/vitest-setup.ts +43 -0
- package/vitest.config.ts +59 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { apiInitializationService, IHttpService } from '@services';
|
|
2
|
+
import { ApiErrorResponseDto, ApiResponseDto, ApiSuccessResponseDto, EmptyMetadataDto, ErrorCode, ReadMetadataDto, RoleDto } from '@data';
|
|
3
|
+
import { fail, ok } from '@utils/result';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Client for authorization management operations
|
|
7
|
+
*
|
|
8
|
+
* @export
|
|
9
|
+
* @class AuthorizationManagementControllerClient
|
|
10
|
+
*/
|
|
11
|
+
export class AuthorizationManagementControllerClient {
|
|
12
|
+
/**
|
|
13
|
+
* Constructor
|
|
14
|
+
* @param baseControllerPath Base path to API controller
|
|
15
|
+
* @param httpService HTTP service implementation to use for requests
|
|
16
|
+
*/
|
|
17
|
+
constructor(
|
|
18
|
+
protected readonly baseControllerPath: string = 'AuthorizationManagement',
|
|
19
|
+
httpService?: IHttpService,
|
|
20
|
+
) {
|
|
21
|
+
this._httpService = httpService;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// #region HTTP service
|
|
25
|
+
private readonly _httpService?: IHttpService = undefined;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Gets globally selected HTTP service
|
|
29
|
+
*/
|
|
30
|
+
protected get httpService(): IHttpService {
|
|
31
|
+
return this._httpService || apiInitializationService._getHttpService();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// #endregion
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Gets all roles in the system
|
|
38
|
+
* @param includeClaims - Whether to include claims in the response
|
|
39
|
+
* @param signal - Optional cancellation signal
|
|
40
|
+
* @returns List of all roles
|
|
41
|
+
*/
|
|
42
|
+
public async getAllRoles(includeClaims: boolean, signal?: AbortSignal): Promise<ApiResponseDto<RoleDto[], ReadMetadataDto>> {
|
|
43
|
+
try {
|
|
44
|
+
const url = await apiInitializationService.getApiUrl(this.baseControllerPath, `/GetAllRoles?includeClaims=${includeClaims}`);
|
|
45
|
+
const res = await this.httpService.request(url, {
|
|
46
|
+
credentials: 'include',
|
|
47
|
+
signal,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
if (!res.ok) {
|
|
51
|
+
return fail<ApiSuccessResponseDto<RoleDto[], ReadMetadataDto>, ApiErrorResponseDto>(await res.json());
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return ok<ApiSuccessResponseDto<RoleDto[], ReadMetadataDto>, ApiErrorResponseDto>(await res.json());
|
|
55
|
+
} catch (err) {
|
|
56
|
+
console.error(err);
|
|
57
|
+
|
|
58
|
+
return fail<ApiSuccessResponseDto<RoleDto[], ReadMetadataDto>, ApiErrorResponseDto>({
|
|
59
|
+
error: {
|
|
60
|
+
code: ErrorCode.UnknownError,
|
|
61
|
+
message: 'Unknown error fetching all roles',
|
|
62
|
+
metadata: {} as EmptyMetadataDto,
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Gets a role with its claims
|
|
70
|
+
* @param roleName - The name of the role
|
|
71
|
+
* @param signal
|
|
72
|
+
* @returns The role with its claims
|
|
73
|
+
*/
|
|
74
|
+
public async getRoleWithClaims(roleName: string, signal?: AbortSignal): Promise<ApiResponseDto<RoleDto, ReadMetadataDto>> {
|
|
75
|
+
try {
|
|
76
|
+
const url = await apiInitializationService.getApiUrl(this.baseControllerPath, `/GetRoleWithClaims/${encodeURIComponent(roleName)}`);
|
|
77
|
+
const res = await this.httpService.request(url, {
|
|
78
|
+
credentials: 'include',
|
|
79
|
+
signal,
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
if (!res.ok) {
|
|
83
|
+
return fail<ApiSuccessResponseDto<RoleDto, ReadMetadataDto>, ApiErrorResponseDto>(await res.json());
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return ok<ApiSuccessResponseDto<RoleDto, ReadMetadataDto>, ApiErrorResponseDto>(await res.json());
|
|
87
|
+
} catch (err) {
|
|
88
|
+
console.error(err);
|
|
89
|
+
|
|
90
|
+
return fail<ApiSuccessResponseDto<RoleDto, ReadMetadataDto>, ApiErrorResponseDto>({
|
|
91
|
+
error: {
|
|
92
|
+
code: ErrorCode.UnknownError,
|
|
93
|
+
message: 'Unknown error fetching role with claims',
|
|
94
|
+
metadata: {} as EmptyMetadataDto,
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Creates or updates a role
|
|
102
|
+
* @param roleDto - The role to create or update
|
|
103
|
+
* @returns The created or updated role
|
|
104
|
+
*/
|
|
105
|
+
public async upsertRole(roleDto: RoleDto): Promise<ApiResponseDto<RoleDto, EmptyMetadataDto>> {
|
|
106
|
+
try {
|
|
107
|
+
const url = await apiInitializationService.getApiUrl(this.baseControllerPath, `/UpsertRole`);
|
|
108
|
+
const res = await this.httpService.request(url, {
|
|
109
|
+
method: 'PUT',
|
|
110
|
+
headers: {
|
|
111
|
+
'Content-Type': 'application/json',
|
|
112
|
+
},
|
|
113
|
+
body: JSON.stringify(roleDto),
|
|
114
|
+
credentials: 'include',
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
if (!res.ok) {
|
|
118
|
+
return fail<ApiSuccessResponseDto<RoleDto, EmptyMetadataDto>, ApiErrorResponseDto>(await res.json());
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return ok<ApiSuccessResponseDto<RoleDto, EmptyMetadataDto>, ApiErrorResponseDto>(await res.json());
|
|
122
|
+
} catch (err) {
|
|
123
|
+
console.error(err);
|
|
124
|
+
|
|
125
|
+
return fail<ApiSuccessResponseDto<RoleDto, EmptyMetadataDto>, ApiErrorResponseDto>({
|
|
126
|
+
error: {
|
|
127
|
+
code: ErrorCode.UnknownError,
|
|
128
|
+
message: 'Unknown error upserting role',
|
|
129
|
+
metadata: {} as EmptyMetadataDto,
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Deletes a role
|
|
137
|
+
* @param roleName - The name of the role to delete
|
|
138
|
+
* @returns Promise that resolves when the role is deleted successfully
|
|
139
|
+
*/
|
|
140
|
+
public async deleteRole(roleName: string): Promise<ApiResponseDto<undefined, EmptyMetadataDto>> {
|
|
141
|
+
try {
|
|
142
|
+
const url = await apiInitializationService.getApiUrl(this.baseControllerPath, `/DeleteRole/${encodeURIComponent(roleName)}`);
|
|
143
|
+
const res = await this.httpService.request(url, {
|
|
144
|
+
method: 'DELETE',
|
|
145
|
+
credentials: 'include',
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
if (!res.ok) {
|
|
149
|
+
return fail<ApiSuccessResponseDto<undefined, EmptyMetadataDto>, ApiErrorResponseDto>(await res.json());
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return ok<ApiSuccessResponseDto<undefined, EmptyMetadataDto>, ApiErrorResponseDto>(undefined);
|
|
153
|
+
} catch (err) {
|
|
154
|
+
console.error(err);
|
|
155
|
+
|
|
156
|
+
return fail<ApiSuccessResponseDto<undefined, EmptyMetadataDto>, ApiErrorResponseDto>({
|
|
157
|
+
error: {
|
|
158
|
+
code: ErrorCode.UnknownError,
|
|
159
|
+
message: `Unknown error while deleting the role ${roleName}`,
|
|
160
|
+
metadata: {} as EmptyMetadataDto,
|
|
161
|
+
},
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './client';
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { IPolicy, PolicyBase } from '@data';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Checks if a policy is valid for the given parameters.
|
|
5
|
+
*
|
|
6
|
+
* @param policy Policy to check, either an instance or a class.
|
|
7
|
+
* @param params Parameters to pass to the policy check function.
|
|
8
|
+
* @returns A promise that resolves if the policy is valid, rejects otherwise.
|
|
9
|
+
*/
|
|
10
|
+
export async function check<TParams extends unknown[]>(policy: IPolicy<TParams> | (new () => IPolicy<TParams>), ...params: TParams): Promise<boolean> {
|
|
11
|
+
// If passed an instance of a policy
|
|
12
|
+
if (policy instanceof PolicyBase) {
|
|
13
|
+
return (policy as IPolicy<TParams>).check(...params);
|
|
14
|
+
}
|
|
15
|
+
// If passed a policy class
|
|
16
|
+
else {
|
|
17
|
+
return new (policy as new () => IPolicy<TParams>)().check(...params);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Composes multiple policies into a single policy.
|
|
23
|
+
*
|
|
24
|
+
* @param composition Composition method, either 'AND' or 'OR'.
|
|
25
|
+
* @param policies Policies to compose.
|
|
26
|
+
* @returns A new policy that represents the composition of the policies.
|
|
27
|
+
*/
|
|
28
|
+
export function compose<TParams extends unknown[]>(composition: 'AND' | 'OR', ...policies: IPolicy<TParams>[]): IPolicy<TParams> {
|
|
29
|
+
return {
|
|
30
|
+
check: async (...params: TParams): Promise<boolean> => {
|
|
31
|
+
// Check all policies
|
|
32
|
+
if (composition === 'AND') {
|
|
33
|
+
const results = await Promise.allSettled(policies.map(policy => policy.check(...params)));
|
|
34
|
+
return results.every(result => result);
|
|
35
|
+
}
|
|
36
|
+
// Check any policies, exit as soon as any are true
|
|
37
|
+
else if (composition === 'OR') {
|
|
38
|
+
const results = await Promise.allSettled(policies.map(policy => policy.check(...params)));
|
|
39
|
+
return results.some(result => result);
|
|
40
|
+
}
|
|
41
|
+
// Invalid composition
|
|
42
|
+
else {
|
|
43
|
+
throw new Error('Invalid composition');
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
type TResultBase = { readonly ok: boolean };
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Represents a result of an operation.
|
|
5
|
+
* It can be either a success or an error.
|
|
6
|
+
*/
|
|
7
|
+
export type Result<TSuccess extends TResultBase, TError extends TResultBase> = TSuccess | TError;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Creates a success result from the given argument.
|
|
11
|
+
* @param arg - The argument to create a success result from.
|
|
12
|
+
* @returns A success result.
|
|
13
|
+
*/
|
|
14
|
+
export function ok<TSuccess extends TResultBase, TError extends TResultBase>(arg?: Omit<TSuccess, 'ok'>): Result<TSuccess, TError> {
|
|
15
|
+
return {ok: true, ...arg} as TSuccess;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Creates an error result from the given argument.
|
|
20
|
+
* @param arg - The argument to create an error result from.
|
|
21
|
+
* @returns An error result.
|
|
22
|
+
*/
|
|
23
|
+
export function fail<TSuccess extends TResultBase, TError extends TResultBase>(arg: Omit<TError, 'ok'>): Result<TSuccess, TError> {
|
|
24
|
+
return {ok: false, ...arg} as TError;
|
|
25
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ReadSelectedComparisonOperator,
|
|
3
|
+
ReadSelectedLogicalOperator,
|
|
4
|
+
ReadSelectedPropertyType,
|
|
5
|
+
ReadSelectedSearchDefinitionDto,
|
|
6
|
+
ReadSelectedSearchPropertyDefinitionDto,
|
|
7
|
+
} from '@data';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Creates a ReadSelectedSearchDefinitionDto ready to be used with the CollectionViewAdapter
|
|
11
|
+
*
|
|
12
|
+
* @param logicalOperator - specify `ReadSelectedLogicalOperator` that will apply to all ReadSelectedSearchPropertyDefinitionDto property definitions included in this search definition
|
|
13
|
+
* @param conditions - Variable number of condition objects containing:
|
|
14
|
+
* - propertyName: The property name from the DTO to search on
|
|
15
|
+
* - operator: The `ReadSelectedComparisonOperator` enum
|
|
16
|
+
* - value: The value to compare against
|
|
17
|
+
* - valueType: The `ReadSelectedPropertyType` being compared
|
|
18
|
+
*/
|
|
19
|
+
export function condition<T>(
|
|
20
|
+
logicalOperator: ReadSelectedLogicalOperator,
|
|
21
|
+
...conditions: Array<{
|
|
22
|
+
propertyName: keyof T;
|
|
23
|
+
operator: ReadSelectedComparisonOperator;
|
|
24
|
+
value: unknown;
|
|
25
|
+
valueType: ReadSelectedPropertyType;
|
|
26
|
+
}>
|
|
27
|
+
): ReadSelectedSearchDefinitionDto<T> {
|
|
28
|
+
return {
|
|
29
|
+
logicalOperator: logicalOperator,
|
|
30
|
+
propertyCriteria: conditions.map(
|
|
31
|
+
condition =>
|
|
32
|
+
({
|
|
33
|
+
propertyName: toPascalCase(condition.propertyName),
|
|
34
|
+
comparisonOperator: condition.operator,
|
|
35
|
+
valueType: condition.valueType,
|
|
36
|
+
value: condition.value,
|
|
37
|
+
}) as ReadSelectedSearchPropertyDefinitionDto<T, keyof T>,
|
|
38
|
+
),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Combines multiple ReadSelectedSearchDefinitionDto with AND logic
|
|
44
|
+
*/
|
|
45
|
+
export function and<T>(...definitions: ReadSelectedSearchDefinitionDto<T>[]): ReadSelectedSearchDefinitionDto<T> {
|
|
46
|
+
return {
|
|
47
|
+
logicalOperator: ReadSelectedLogicalOperator.And,
|
|
48
|
+
searches: definitions,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Combines multiple ReadSelectedSearchDefinitionDto with OR logic
|
|
54
|
+
*/
|
|
55
|
+
export function or<T>(...definitions: ReadSelectedSearchDefinitionDto<T>[]): ReadSelectedSearchDefinitionDto<T> {
|
|
56
|
+
return {
|
|
57
|
+
logicalOperator: ReadSelectedLogicalOperator.Or,
|
|
58
|
+
searches: definitions,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Preset implementation for filtering by searchTerm. String types will search by provided `textSearchableProperties` with `ReadSelectedComparisonOperator.Contains`. Numeric types will search by provided `numericSearchableProperties`, `parseInt` the search term and use `ReadSelectedComparisonOperator.Equal`.
|
|
64
|
+
*/
|
|
65
|
+
export function searchTerm<T>(
|
|
66
|
+
searchTerm: string,
|
|
67
|
+
textSearchableProperties: (keyof T)[],
|
|
68
|
+
numericSearchableProperties: (keyof T)[],
|
|
69
|
+
): void | ReadSelectedSearchDefinitionDto<T> {
|
|
70
|
+
let comparisonOperator: ReadSelectedComparisonOperator;
|
|
71
|
+
let valueType: ReadSelectedPropertyType;
|
|
72
|
+
let searchableProperties: (keyof T)[];
|
|
73
|
+
let searchValue: string | number;
|
|
74
|
+
try {
|
|
75
|
+
const numericValue = parseInt(searchTerm);
|
|
76
|
+
|
|
77
|
+
if (!Number.isNaN(numericValue) && String(numericValue) === searchTerm.trim()) {
|
|
78
|
+
comparisonOperator = ReadSelectedComparisonOperator.Equal;
|
|
79
|
+
valueType = ReadSelectedPropertyType.Int;
|
|
80
|
+
searchableProperties = numericSearchableProperties;
|
|
81
|
+
searchValue = numericValue;
|
|
82
|
+
} else {
|
|
83
|
+
comparisonOperator = ReadSelectedComparisonOperator.Contains;
|
|
84
|
+
valueType = ReadSelectedPropertyType.String;
|
|
85
|
+
searchableProperties = textSearchableProperties;
|
|
86
|
+
searchValue = searchTerm;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const searchConditions = searchableProperties.map(propertyName => ({
|
|
90
|
+
propertyName: toPascalCase(propertyName),
|
|
91
|
+
operator: comparisonOperator,
|
|
92
|
+
value: searchValue,
|
|
93
|
+
valueType: valueType,
|
|
94
|
+
}));
|
|
95
|
+
|
|
96
|
+
return condition(ReadSelectedLogicalOperator.Or, ...searchConditions);
|
|
97
|
+
} catch {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Preset implementation for filtering a date range. User may select desired `ReadSelectedComparisonOperator` and `ReadSelectedPropertyType` for the from and to dates. Valid object property must be provided for `searchableProperty`.
|
|
104
|
+
*/
|
|
105
|
+
export function dateInterval<T>(
|
|
106
|
+
fromDate: Date,
|
|
107
|
+
toDate: Date,
|
|
108
|
+
fromDateComparisonOperator: ReadSelectedComparisonOperator,
|
|
109
|
+
toDateComparisonOperator: ReadSelectedComparisonOperator,
|
|
110
|
+
valueType: ReadSelectedPropertyType,
|
|
111
|
+
searchableProperty: keyof T,
|
|
112
|
+
): void | ReadSelectedSearchDefinitionDto<T> {
|
|
113
|
+
try {
|
|
114
|
+
if (
|
|
115
|
+
!(
|
|
116
|
+
valueType === ReadSelectedPropertyType.DateOnly ||
|
|
117
|
+
valueType === ReadSelectedPropertyType.DateTime ||
|
|
118
|
+
valueType === ReadSelectedPropertyType.DateTimeOffset
|
|
119
|
+
)
|
|
120
|
+
) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return condition(
|
|
125
|
+
ReadSelectedLogicalOperator.And,
|
|
126
|
+
{
|
|
127
|
+
propertyName: toPascalCase(searchableProperty),
|
|
128
|
+
operator: fromDateComparisonOperator,
|
|
129
|
+
value: fromDate,
|
|
130
|
+
valueType: valueType,
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
propertyName: toPascalCase(searchableProperty),
|
|
134
|
+
operator: toDateComparisonOperator,
|
|
135
|
+
value: toDate,
|
|
136
|
+
valueType: valueType,
|
|
137
|
+
},
|
|
138
|
+
);
|
|
139
|
+
} catch {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export function toPascalCase<T>(str: keyof T): keyof T {
|
|
145
|
+
if (typeof str !== 'string') {
|
|
146
|
+
return str;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return (str.charAt(0).toUpperCase() + str.slice(1)) as keyof T;
|
|
150
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../../tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "./dist",
|
|
5
|
+
"paths": {
|
|
6
|
+
"@": ["./src"],
|
|
7
|
+
"@/*": ["./src/*"],
|
|
8
|
+
"@adapters": ["./src/adapters"],
|
|
9
|
+
"@adapters/*": ["./src/adapters/*"],
|
|
10
|
+
"@data": ["./src/data"],
|
|
11
|
+
"@data/*": ["./src/data/*"],
|
|
12
|
+
"@services": ["./src/services"],
|
|
13
|
+
"@services/*": ["./src/services/*"],
|
|
14
|
+
"@utils": ["./src/utils"],
|
|
15
|
+
"@utils/*": ["./src/utils/*"]
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"include": ["src/**/*.ts"]
|
|
19
|
+
}
|
package/vitest-setup.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { vi } from 'vitest';
|
|
2
|
+
import fetch from 'node-fetch';
|
|
3
|
+
|
|
4
|
+
// Global fetch mock for Vitest integration tests.
|
|
5
|
+
// Purpose:
|
|
6
|
+
// - Provide deterministic configuration for app/service initialization that loads `websettings.json`
|
|
7
|
+
// - Only fetch requests for `websettings.json` are mocked; all other network requests are real
|
|
8
|
+
//
|
|
9
|
+
// Any fetch request that targets `websettings.json` (typically during app or service init) will receive a mocked response.
|
|
10
|
+
// All other requests are forwarded to the real `node-fetch` implementation, so real network requests are still possible in tests.
|
|
11
|
+
|
|
12
|
+
const MOCKED_WEBSETTINGS_JSON = {
|
|
13
|
+
api: 'http://localhost:5000/api',
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// Use new Headers() to simulate Fetch API Headers behavior.
|
|
17
|
+
// This ensures compatibility with code that uses headers.forEach() for iteration.
|
|
18
|
+
const MOCKED_RESPONSE_HEADERS = new Headers({
|
|
19
|
+
'Content-Type': 'application/json',
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const mockFetch = vi.fn(async (url: string, config?: RequestInit) => {
|
|
23
|
+
if (url.includes('websettings.json')) {
|
|
24
|
+
return {
|
|
25
|
+
ok: true,
|
|
26
|
+
status: 200,
|
|
27
|
+
statusText: 'OK',
|
|
28
|
+
|
|
29
|
+
// Minimal Headers mock for compatibility with project code.
|
|
30
|
+
headers: MOCKED_RESPONSE_HEADERS,
|
|
31
|
+
|
|
32
|
+
// Mocked JSON payload returned by fetch().json()
|
|
33
|
+
json: vi.fn<() => Promise<any>>().mockResolvedValue(MOCKED_WEBSETTINGS_JSON),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Forward all non-config requests to the real fetch implementation.
|
|
38
|
+
// `any` cast is intentional to avoid RequestInit type mismatches in Node.
|
|
39
|
+
return fetch(url, config as any);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// Override global fetch for all tests
|
|
43
|
+
global.fetch = mockFetch as any;
|
package/vitest.config.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { defineConfig } from 'vitest/config';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import tsconfigPaths from 'vite-tsconfig-paths';
|
|
4
|
+
|
|
5
|
+
const aliasConfig = {
|
|
6
|
+
'@': path.resolve(__dirname, './src'),
|
|
7
|
+
'@adapters': path.resolve(__dirname, './src/adapters'),
|
|
8
|
+
'@data': path.resolve(__dirname, './src/data'),
|
|
9
|
+
'@data/*': path.resolve(__dirname, './src/data/*'),
|
|
10
|
+
'@services': path.resolve(__dirname, './src/services'),
|
|
11
|
+
'@utils': path.resolve(__dirname, './src/utils'),
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export default defineConfig({
|
|
15
|
+
plugins: [tsconfigPaths()],
|
|
16
|
+
test: {
|
|
17
|
+
projects: [
|
|
18
|
+
{
|
|
19
|
+
resolve: {
|
|
20
|
+
alias: aliasConfig,
|
|
21
|
+
},
|
|
22
|
+
test: {
|
|
23
|
+
name: 'unit',
|
|
24
|
+
environment: 'jsdom',
|
|
25
|
+
testTimeout: 60000,
|
|
26
|
+
include: ['./**/*.unit.test.{ts,tsx,js}', '**/*.unit.test.{ts,tsx,js}'],
|
|
27
|
+
exclude: ['**/node_modules/**', '**/dist/**'],
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
resolve: {
|
|
32
|
+
alias: aliasConfig,
|
|
33
|
+
},
|
|
34
|
+
test: {
|
|
35
|
+
name: 'integration',
|
|
36
|
+
environment: 'jsdom',
|
|
37
|
+
testTimeout: 60000,
|
|
38
|
+
globalSetup: [path.resolve(__dirname, '../../vitest-setup-integration.ts')],
|
|
39
|
+
setupFiles: [path.resolve(__dirname, './vitest-setup.ts')],
|
|
40
|
+
include: ['./**/*.integration.test.{ts,tsx,js}', '**/*.integration.test.{ts,tsx,js}'],
|
|
41
|
+
exclude: ['**/node_modules/**', '**/dist/**'],
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
resolve: {
|
|
46
|
+
alias: aliasConfig,
|
|
47
|
+
},
|
|
48
|
+
test: {
|
|
49
|
+
name: 'debug',
|
|
50
|
+
testTimeout: 60000,
|
|
51
|
+
globalSetup: [path.resolve(__dirname, '../../vitest-setup-integration.ts')],
|
|
52
|
+
setupFiles: [path.resolve(__dirname, './vitest-setup.ts')],
|
|
53
|
+
include: ['./**/*.{test,spec,debug}.{js,ts}'],
|
|
54
|
+
exclude: ['**/node_modules/**', '**/dist/**'],
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
},
|
|
59
|
+
});
|