@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,200 @@
|
|
|
1
|
+
import { apiInitializationService } from '../../..';
|
|
2
|
+
import { ErrorCode } from '../../../../data';
|
|
3
|
+
import { fail, ok } from '../../../../utils';
|
|
4
|
+
/**
|
|
5
|
+
* AuthService class is responsible for managing user authentication operations.
|
|
6
|
+
* It supports login, logout, and checking the current user's details.
|
|
7
|
+
*
|
|
8
|
+
* @export
|
|
9
|
+
* @class AuthService
|
|
10
|
+
*/
|
|
11
|
+
export class AuthService {
|
|
12
|
+
baseControllerPath;
|
|
13
|
+
/**
|
|
14
|
+
* Constructor
|
|
15
|
+
* @param baseControllerPath Base path to Auth API controller
|
|
16
|
+
* @param httpService HTTP service implementation to use for requests
|
|
17
|
+
*/
|
|
18
|
+
constructor(baseControllerPath = 'Auth', httpService) {
|
|
19
|
+
this.baseControllerPath = baseControllerPath;
|
|
20
|
+
this._httpService = httpService;
|
|
21
|
+
}
|
|
22
|
+
// #region HTTP service
|
|
23
|
+
_httpService = undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Gets globally selected HTTP service
|
|
26
|
+
*/
|
|
27
|
+
get httpService() {
|
|
28
|
+
return this._httpService || apiInitializationService._getHttpService();
|
|
29
|
+
}
|
|
30
|
+
// #endregion
|
|
31
|
+
/**
|
|
32
|
+
* Holds currently authenticated user's details
|
|
33
|
+
*/
|
|
34
|
+
user = undefined;
|
|
35
|
+
/**
|
|
36
|
+
* Initializes the Authentication status by checking with the API if the current user is authenticated or not
|
|
37
|
+
*
|
|
38
|
+
* @async
|
|
39
|
+
* @return {Promise<void>} Resolves when initialization is complete.
|
|
40
|
+
*/
|
|
41
|
+
async initialize() {
|
|
42
|
+
// Check user's authentication status
|
|
43
|
+
await this.whoAmI();
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Checks if user is authenticated and retrieves the current user's details if they are
|
|
47
|
+
*
|
|
48
|
+
* @return {Promise<UserInfoDto<TKey, TUser>>} Currently logged in user's details
|
|
49
|
+
* @throws {Error} Error if fetch fails
|
|
50
|
+
*/
|
|
51
|
+
async whoAmI() {
|
|
52
|
+
try {
|
|
53
|
+
const url = await apiInitializationService.getApiUrl(this.baseControllerPath, '/whoami');
|
|
54
|
+
const res = await this.httpService.request(url, { credentials: 'include' });
|
|
55
|
+
if (!res.ok) {
|
|
56
|
+
this.user = undefined;
|
|
57
|
+
return fail(await res.json());
|
|
58
|
+
}
|
|
59
|
+
const response = ok(await res.json());
|
|
60
|
+
if (!response.ok) {
|
|
61
|
+
this.user = undefined;
|
|
62
|
+
return response;
|
|
63
|
+
}
|
|
64
|
+
this.user = response.result.user;
|
|
65
|
+
return response;
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
68
|
+
console.error(err);
|
|
69
|
+
return fail({
|
|
70
|
+
error: {
|
|
71
|
+
code: ErrorCode.UnknownError,
|
|
72
|
+
message: 'Failed checking authentication status',
|
|
73
|
+
metadata: {},
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Authenticates a user using their username and password, and retrieves user's details
|
|
80
|
+
*
|
|
81
|
+
* @param {string} username Login credentials: username
|
|
82
|
+
* @param {string} password Login credentials: password
|
|
83
|
+
* @return {Promise<TUser>} Currently logged in user's details
|
|
84
|
+
* @throws {Error} Error if fetch fails
|
|
85
|
+
*/
|
|
86
|
+
async signIn(username, password) {
|
|
87
|
+
try {
|
|
88
|
+
const url = await apiInitializationService.getApiUrl(this.baseControllerPath, '/signin');
|
|
89
|
+
const res = await this.httpService.request(url, {
|
|
90
|
+
method: 'POST',
|
|
91
|
+
headers: { 'Content-Type': 'application/json' },
|
|
92
|
+
body: JSON.stringify({ username, password }),
|
|
93
|
+
credentials: 'include',
|
|
94
|
+
});
|
|
95
|
+
if (!res.ok) {
|
|
96
|
+
return fail(await res.json());
|
|
97
|
+
}
|
|
98
|
+
// TODO: Handle tokens if not using cookies
|
|
99
|
+
const whoAmIRes = await this.whoAmI();
|
|
100
|
+
if (!whoAmIRes.ok) {
|
|
101
|
+
return whoAmIRes;
|
|
102
|
+
}
|
|
103
|
+
return ok({
|
|
104
|
+
result: whoAmIRes.result.user,
|
|
105
|
+
metadata: whoAmIRes.metadata,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
catch (err) {
|
|
109
|
+
console.error(err);
|
|
110
|
+
return fail({
|
|
111
|
+
error: {
|
|
112
|
+
code: ErrorCode.UnknownError,
|
|
113
|
+
message: 'Failed signing in',
|
|
114
|
+
metadata: {},
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Deauthenticates current user
|
|
121
|
+
*
|
|
122
|
+
* @return {Promise<void>}
|
|
123
|
+
* @throws {Error} Error if fetch fails
|
|
124
|
+
*/
|
|
125
|
+
async signOut() {
|
|
126
|
+
try {
|
|
127
|
+
const url = await apiInitializationService.getApiUrl(this.baseControllerPath, '/signout');
|
|
128
|
+
const res = await this.httpService.request(url, { credentials: 'include' });
|
|
129
|
+
if (!res.ok) {
|
|
130
|
+
return fail(await res.json());
|
|
131
|
+
}
|
|
132
|
+
this.user = undefined;
|
|
133
|
+
return ok(await res.json());
|
|
134
|
+
}
|
|
135
|
+
catch (err) {
|
|
136
|
+
console.error(err);
|
|
137
|
+
return fail({
|
|
138
|
+
error: {
|
|
139
|
+
code: ErrorCode.UnknownError,
|
|
140
|
+
message: 'Failed signing out',
|
|
141
|
+
metadata: {},
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Registers a new user by sending user details to the API.
|
|
148
|
+
*
|
|
149
|
+
* @param {TRegisterUser} user User object containing registration data (e.g. username, password, and optionally firstName, lastName, etc.)
|
|
150
|
+
* @return {Promise<ApiResponseDto<TUser, EmptyMetadataDto>>} API response with registered user details or error info
|
|
151
|
+
* @throws {Error} Error if the request fails
|
|
152
|
+
*/
|
|
153
|
+
async register(user) {
|
|
154
|
+
try {
|
|
155
|
+
const url = await apiInitializationService.getApiUrl(this.baseControllerPath, '/register');
|
|
156
|
+
const res = await this.httpService.request(url, {
|
|
157
|
+
method: 'POST',
|
|
158
|
+
headers: { 'Content-Type': 'application/json' },
|
|
159
|
+
body: JSON.stringify(user),
|
|
160
|
+
credentials: 'include',
|
|
161
|
+
});
|
|
162
|
+
if (!res.ok) {
|
|
163
|
+
return fail(await res.json());
|
|
164
|
+
}
|
|
165
|
+
// TODO: Handle tokens if not using cookies
|
|
166
|
+
const whoAmIRes = await this.whoAmI();
|
|
167
|
+
if (!whoAmIRes.ok) {
|
|
168
|
+
return whoAmIRes;
|
|
169
|
+
}
|
|
170
|
+
return ok({
|
|
171
|
+
result: whoAmIRes.result.user,
|
|
172
|
+
metadata: whoAmIRes.metadata,
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
catch (err) {
|
|
176
|
+
console.error(err);
|
|
177
|
+
return fail({
|
|
178
|
+
error: {
|
|
179
|
+
code: ErrorCode.UnknownError,
|
|
180
|
+
message: 'Failed registering user',
|
|
181
|
+
metadata: {},
|
|
182
|
+
},
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* If any API response returns an "Unauthenticated" response, call this method
|
|
188
|
+
* to update local authentication state to unauthenticated
|
|
189
|
+
*/
|
|
190
|
+
handleNoAuthApiResponse() {
|
|
191
|
+
this.user = undefined;
|
|
192
|
+
}
|
|
193
|
+
// #region Client-side authorization helpers
|
|
194
|
+
/**
|
|
195
|
+
* True if a user is currently loaded (post whoAmI/signIn)
|
|
196
|
+
*/
|
|
197
|
+
isAuthenticated() {
|
|
198
|
+
return !!this.user;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { IHttpService } from '../../..';
|
|
2
|
+
import { ApiResponseDto, EmptyMetadataDto, ReadMetadataDto, RoleDto } from '../../../../data';
|
|
3
|
+
/**
|
|
4
|
+
* Client for authorization management operations
|
|
5
|
+
*
|
|
6
|
+
* @export
|
|
7
|
+
* @class AuthorizationManagementControllerClient
|
|
8
|
+
*/
|
|
9
|
+
export declare class AuthorizationManagementControllerClient {
|
|
10
|
+
protected readonly baseControllerPath: string;
|
|
11
|
+
/**
|
|
12
|
+
* Constructor
|
|
13
|
+
* @param baseControllerPath Base path to API controller
|
|
14
|
+
* @param httpService HTTP service implementation to use for requests
|
|
15
|
+
*/
|
|
16
|
+
constructor(baseControllerPath?: string, httpService?: IHttpService);
|
|
17
|
+
private readonly _httpService?;
|
|
18
|
+
/**
|
|
19
|
+
* Gets globally selected HTTP service
|
|
20
|
+
*/
|
|
21
|
+
protected get httpService(): IHttpService;
|
|
22
|
+
/**
|
|
23
|
+
* Gets all roles in the system
|
|
24
|
+
* @param includeClaims - Whether to include claims in the response
|
|
25
|
+
* @param signal - Optional cancellation signal
|
|
26
|
+
* @returns List of all roles
|
|
27
|
+
*/
|
|
28
|
+
getAllRoles(includeClaims: boolean, signal?: AbortSignal): Promise<ApiResponseDto<RoleDto[], ReadMetadataDto>>;
|
|
29
|
+
/**
|
|
30
|
+
* Gets a role with its claims
|
|
31
|
+
* @param roleName - The name of the role
|
|
32
|
+
* @param signal
|
|
33
|
+
* @returns The role with its claims
|
|
34
|
+
*/
|
|
35
|
+
getRoleWithClaims(roleName: string, signal?: AbortSignal): Promise<ApiResponseDto<RoleDto, ReadMetadataDto>>;
|
|
36
|
+
/**
|
|
37
|
+
* Creates or updates a role
|
|
38
|
+
* @param roleDto - The role to create or update
|
|
39
|
+
* @returns The created or updated role
|
|
40
|
+
*/
|
|
41
|
+
upsertRole(roleDto: RoleDto): Promise<ApiResponseDto<RoleDto, EmptyMetadataDto>>;
|
|
42
|
+
/**
|
|
43
|
+
* Deletes a role
|
|
44
|
+
* @param roleName - The name of the role to delete
|
|
45
|
+
* @returns Promise that resolves when the role is deleted successfully
|
|
46
|
+
*/
|
|
47
|
+
deleteRole(roleName: string): Promise<ApiResponseDto<undefined, EmptyMetadataDto>>;
|
|
48
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/services/auth/client/AuthorizationManagementControllerClient/index.integration.test.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { beforeAll, beforeEach, describe, expect, it } from 'vitest';
|
|
2
|
+
import { AuthorizationManagementControllerClient } from '.';
|
|
3
|
+
import fetchOrig from 'node-fetch';
|
|
4
|
+
import fetchCookie from 'fetch-cookie';
|
|
5
|
+
import { CookieJar } from 'tough-cookie';
|
|
6
|
+
// Create a fetch instance that handles auth cookies
|
|
7
|
+
const jar = new CookieJar();
|
|
8
|
+
const cookieFetch = fetchCookie(fetchOrig, jar);
|
|
9
|
+
// Custom IHttpService implementation for tests
|
|
10
|
+
class CookieFetchHttpService {
|
|
11
|
+
async request(url, config) {
|
|
12
|
+
const response = await cookieFetch(url, {
|
|
13
|
+
method: config?.method || 'GET',
|
|
14
|
+
headers: config?.headers,
|
|
15
|
+
body: config?.body,
|
|
16
|
+
signal: config?.signal,
|
|
17
|
+
});
|
|
18
|
+
const headers = {};
|
|
19
|
+
response.headers.forEach((value, key) => {
|
|
20
|
+
headers[key] = value;
|
|
21
|
+
});
|
|
22
|
+
return {
|
|
23
|
+
ok: response.ok,
|
|
24
|
+
status: response.status,
|
|
25
|
+
statusText: response.statusText,
|
|
26
|
+
headers,
|
|
27
|
+
json: () => response.json(),
|
|
28
|
+
text: () => response.text(),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const credentials = {
|
|
33
|
+
username: 'admin@test.com',
|
|
34
|
+
password: 'Password1234!',
|
|
35
|
+
};
|
|
36
|
+
const baseUrl = 'http://localhost:5000/api';
|
|
37
|
+
describe('AuthorizationManagementControllerClient', () => {
|
|
38
|
+
let client;
|
|
39
|
+
let fetchService = new CookieFetchHttpService();
|
|
40
|
+
beforeAll(async () => {
|
|
41
|
+
await fetchService.request(`${baseUrl}/auth/signin`, {
|
|
42
|
+
method: 'POST',
|
|
43
|
+
headers: { 'Content-Type': 'application/json' },
|
|
44
|
+
body: JSON.stringify(credentials),
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
beforeEach(() => {
|
|
48
|
+
client = new AuthorizationManagementControllerClient('/AuthorizationManagement', fetchService);
|
|
49
|
+
});
|
|
50
|
+
it('should fetch all roles', async () => {
|
|
51
|
+
const result = (await client.getAllRoles(false));
|
|
52
|
+
expect(result.ok).toBe(true);
|
|
53
|
+
expect(result.result).toBeDefined();
|
|
54
|
+
});
|
|
55
|
+
it('should fetch all roles with claims', async () => {
|
|
56
|
+
const result = (await client.getAllRoles(true));
|
|
57
|
+
expect(result.ok).toBe(true);
|
|
58
|
+
expect(result.result).toBeDefined();
|
|
59
|
+
expect(result.result[0].claims).toBeDefined();
|
|
60
|
+
});
|
|
61
|
+
it('should return role with claims by name', async () => {
|
|
62
|
+
const newRole = { name: 'New Role Test Claims', claims: [{ type: 'Test Claim Type', value: 'Test Claim Value' }] };
|
|
63
|
+
const create = (await client.upsertRole(newRole));
|
|
64
|
+
expect(create.ok).toBe(true);
|
|
65
|
+
const result = (await client.getRoleWithClaims(newRole.name));
|
|
66
|
+
expect(result.ok).toBe(true);
|
|
67
|
+
expect(result.result).toBeDefined();
|
|
68
|
+
expect(result.result.claims).toBeDefined();
|
|
69
|
+
expect(result.result.name).toBe(newRole.name);
|
|
70
|
+
expect(result.result.claims.length).toBe(newRole.claims.length);
|
|
71
|
+
expect(result.result.claims).toEqual(newRole.claims);
|
|
72
|
+
});
|
|
73
|
+
it('should create a new role with claims', async () => {
|
|
74
|
+
const newRole = { name: 'New Role', claims: [{ type: 'Test Claim Type', value: 'Test Claim Value' }] };
|
|
75
|
+
const result = (await client.upsertRole(newRole));
|
|
76
|
+
expect(result.ok).toBe(true);
|
|
77
|
+
expect(result.result).toBeDefined();
|
|
78
|
+
expect(result.result.name).toBe(newRole.name);
|
|
79
|
+
expect(result.result.claims.length).toBe(newRole.claims.length);
|
|
80
|
+
expect(result.result.claims).toEqual(newRole.claims);
|
|
81
|
+
});
|
|
82
|
+
it('should delete role', async () => {
|
|
83
|
+
const role = { name: 'Temp Role', claims: [] };
|
|
84
|
+
const create = (await client.upsertRole(role));
|
|
85
|
+
expect(create.ok).toBe(true);
|
|
86
|
+
const deleteResult = await client.deleteRole(role.name);
|
|
87
|
+
expect(deleteResult.ok).toBe(true);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { apiInitializationService } from '../../..';
|
|
2
|
+
import { ErrorCode } from '../../../../data';
|
|
3
|
+
import { fail, ok } from '../../../../utils/result';
|
|
4
|
+
/**
|
|
5
|
+
* Client for authorization management operations
|
|
6
|
+
*
|
|
7
|
+
* @export
|
|
8
|
+
* @class AuthorizationManagementControllerClient
|
|
9
|
+
*/
|
|
10
|
+
export class AuthorizationManagementControllerClient {
|
|
11
|
+
baseControllerPath;
|
|
12
|
+
/**
|
|
13
|
+
* Constructor
|
|
14
|
+
* @param baseControllerPath Base path to API controller
|
|
15
|
+
* @param httpService HTTP service implementation to use for requests
|
|
16
|
+
*/
|
|
17
|
+
constructor(baseControllerPath = 'AuthorizationManagement', httpService) {
|
|
18
|
+
this.baseControllerPath = baseControllerPath;
|
|
19
|
+
this._httpService = httpService;
|
|
20
|
+
}
|
|
21
|
+
// #region HTTP service
|
|
22
|
+
_httpService = undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Gets globally selected HTTP service
|
|
25
|
+
*/
|
|
26
|
+
get httpService() {
|
|
27
|
+
return this._httpService || apiInitializationService._getHttpService();
|
|
28
|
+
}
|
|
29
|
+
// #endregion
|
|
30
|
+
/**
|
|
31
|
+
* Gets all roles in the system
|
|
32
|
+
* @param includeClaims - Whether to include claims in the response
|
|
33
|
+
* @param signal - Optional cancellation signal
|
|
34
|
+
* @returns List of all roles
|
|
35
|
+
*/
|
|
36
|
+
async getAllRoles(includeClaims, signal) {
|
|
37
|
+
try {
|
|
38
|
+
const url = await apiInitializationService.getApiUrl(this.baseControllerPath, `/GetAllRoles?includeClaims=${includeClaims}`);
|
|
39
|
+
const res = await this.httpService.request(url, {
|
|
40
|
+
credentials: 'include',
|
|
41
|
+
signal,
|
|
42
|
+
});
|
|
43
|
+
if (!res.ok) {
|
|
44
|
+
return fail(await res.json());
|
|
45
|
+
}
|
|
46
|
+
return ok(await res.json());
|
|
47
|
+
}
|
|
48
|
+
catch (err) {
|
|
49
|
+
console.error(err);
|
|
50
|
+
return fail({
|
|
51
|
+
error: {
|
|
52
|
+
code: ErrorCode.UnknownError,
|
|
53
|
+
message: 'Unknown error fetching all roles',
|
|
54
|
+
metadata: {},
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Gets a role with its claims
|
|
61
|
+
* @param roleName - The name of the role
|
|
62
|
+
* @param signal
|
|
63
|
+
* @returns The role with its claims
|
|
64
|
+
*/
|
|
65
|
+
async getRoleWithClaims(roleName, signal) {
|
|
66
|
+
try {
|
|
67
|
+
const url = await apiInitializationService.getApiUrl(this.baseControllerPath, `/GetRoleWithClaims/${encodeURIComponent(roleName)}`);
|
|
68
|
+
const res = await this.httpService.request(url, {
|
|
69
|
+
credentials: 'include',
|
|
70
|
+
signal,
|
|
71
|
+
});
|
|
72
|
+
if (!res.ok) {
|
|
73
|
+
return fail(await res.json());
|
|
74
|
+
}
|
|
75
|
+
return ok(await res.json());
|
|
76
|
+
}
|
|
77
|
+
catch (err) {
|
|
78
|
+
console.error(err);
|
|
79
|
+
return fail({
|
|
80
|
+
error: {
|
|
81
|
+
code: ErrorCode.UnknownError,
|
|
82
|
+
message: 'Unknown error fetching role with claims',
|
|
83
|
+
metadata: {},
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Creates or updates a role
|
|
90
|
+
* @param roleDto - The role to create or update
|
|
91
|
+
* @returns The created or updated role
|
|
92
|
+
*/
|
|
93
|
+
async upsertRole(roleDto) {
|
|
94
|
+
try {
|
|
95
|
+
const url = await apiInitializationService.getApiUrl(this.baseControllerPath, `/UpsertRole`);
|
|
96
|
+
const res = await this.httpService.request(url, {
|
|
97
|
+
method: 'PUT',
|
|
98
|
+
headers: {
|
|
99
|
+
'Content-Type': 'application/json',
|
|
100
|
+
},
|
|
101
|
+
body: JSON.stringify(roleDto),
|
|
102
|
+
credentials: 'include',
|
|
103
|
+
});
|
|
104
|
+
if (!res.ok) {
|
|
105
|
+
return fail(await res.json());
|
|
106
|
+
}
|
|
107
|
+
return ok(await res.json());
|
|
108
|
+
}
|
|
109
|
+
catch (err) {
|
|
110
|
+
console.error(err);
|
|
111
|
+
return fail({
|
|
112
|
+
error: {
|
|
113
|
+
code: ErrorCode.UnknownError,
|
|
114
|
+
message: 'Unknown error upserting role',
|
|
115
|
+
metadata: {},
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Deletes a role
|
|
122
|
+
* @param roleName - The name of the role to delete
|
|
123
|
+
* @returns Promise that resolves when the role is deleted successfully
|
|
124
|
+
*/
|
|
125
|
+
async deleteRole(roleName) {
|
|
126
|
+
try {
|
|
127
|
+
const url = await apiInitializationService.getApiUrl(this.baseControllerPath, `/DeleteRole/${encodeURIComponent(roleName)}`);
|
|
128
|
+
const res = await this.httpService.request(url, {
|
|
129
|
+
method: 'DELETE',
|
|
130
|
+
credentials: 'include',
|
|
131
|
+
});
|
|
132
|
+
if (!res.ok) {
|
|
133
|
+
return fail(await res.json());
|
|
134
|
+
}
|
|
135
|
+
return ok(undefined);
|
|
136
|
+
}
|
|
137
|
+
catch (err) {
|
|
138
|
+
console.error(err);
|
|
139
|
+
return fail({
|
|
140
|
+
error: {
|
|
141
|
+
code: ErrorCode.UnknownError,
|
|
142
|
+
message: `Unknown error while deleting the role ${roleName}`,
|
|
143
|
+
metadata: {},
|
|
144
|
+
},
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './client';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './client';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { IPolicy } from '../../data';
|
|
2
|
+
/**
|
|
3
|
+
* Checks if a policy is valid for the given parameters.
|
|
4
|
+
*
|
|
5
|
+
* @param policy Policy to check, either an instance or a class.
|
|
6
|
+
* @param params Parameters to pass to the policy check function.
|
|
7
|
+
* @returns A promise that resolves if the policy is valid, rejects otherwise.
|
|
8
|
+
*/
|
|
9
|
+
export declare function check<TParams extends unknown[]>(policy: IPolicy<TParams> | (new () => IPolicy<TParams>), ...params: TParams): Promise<boolean>;
|
|
10
|
+
/**
|
|
11
|
+
* Composes multiple policies into a single policy.
|
|
12
|
+
*
|
|
13
|
+
* @param composition Composition method, either 'AND' or 'OR'.
|
|
14
|
+
* @param policies Policies to compose.
|
|
15
|
+
* @returns A new policy that represents the composition of the policies.
|
|
16
|
+
*/
|
|
17
|
+
export declare function compose<TParams extends unknown[]>(composition: 'AND' | 'OR', ...policies: IPolicy<TParams>[]): IPolicy<TParams>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { PolicyBase } from '../../data';
|
|
2
|
+
/**
|
|
3
|
+
* Checks if a policy is valid for the given parameters.
|
|
4
|
+
*
|
|
5
|
+
* @param policy Policy to check, either an instance or a class.
|
|
6
|
+
* @param params Parameters to pass to the policy check function.
|
|
7
|
+
* @returns A promise that resolves if the policy is valid, rejects otherwise.
|
|
8
|
+
*/
|
|
9
|
+
export async function check(policy, ...params) {
|
|
10
|
+
// If passed an instance of a policy
|
|
11
|
+
if (policy instanceof PolicyBase) {
|
|
12
|
+
return policy.check(...params);
|
|
13
|
+
}
|
|
14
|
+
// If passed a policy class
|
|
15
|
+
else {
|
|
16
|
+
return new policy().check(...params);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Composes multiple policies into a single policy.
|
|
21
|
+
*
|
|
22
|
+
* @param composition Composition method, either 'AND' or 'OR'.
|
|
23
|
+
* @param policies Policies to compose.
|
|
24
|
+
* @returns A new policy that represents the composition of the policies.
|
|
25
|
+
*/
|
|
26
|
+
export function compose(composition, ...policies) {
|
|
27
|
+
return {
|
|
28
|
+
check: async (...params) => {
|
|
29
|
+
// Check all policies
|
|
30
|
+
if (composition === 'AND') {
|
|
31
|
+
const results = await Promise.allSettled(policies.map(policy => policy.check(...params)));
|
|
32
|
+
return results.every(result => result);
|
|
33
|
+
}
|
|
34
|
+
// Check any policies, exit as soon as any are true
|
|
35
|
+
else if (composition === 'OR') {
|
|
36
|
+
const results = await Promise.allSettled(policies.map(policy => policy.check(...params)));
|
|
37
|
+
return results.some(result => result);
|
|
38
|
+
}
|
|
39
|
+
// Invalid composition
|
|
40
|
+
else {
|
|
41
|
+
throw new Error('Invalid composition');
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
type TResultBase = {
|
|
2
|
+
readonly ok: boolean;
|
|
3
|
+
};
|
|
4
|
+
/**
|
|
5
|
+
* Represents a result of an operation.
|
|
6
|
+
* It can be either a success or an error.
|
|
7
|
+
*/
|
|
8
|
+
export type Result<TSuccess extends TResultBase, TError extends TResultBase> = TSuccess | TError;
|
|
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 declare function ok<TSuccess extends TResultBase, TError extends TResultBase>(arg?: Omit<TSuccess, 'ok'>): Result<TSuccess, TError>;
|
|
15
|
+
/**
|
|
16
|
+
* Creates an error result from the given argument.
|
|
17
|
+
* @param arg - The argument to create an error result from.
|
|
18
|
+
* @returns An error result.
|
|
19
|
+
*/
|
|
20
|
+
export declare function fail<TSuccess extends TResultBase, TError extends TResultBase>(arg: Omit<TError, 'ok'>): Result<TSuccess, TError>;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a success result from the given argument.
|
|
3
|
+
* @param arg - The argument to create a success result from.
|
|
4
|
+
* @returns A success result.
|
|
5
|
+
*/
|
|
6
|
+
export function ok(arg) {
|
|
7
|
+
return { ok: true, ...arg };
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Creates an error result from the given argument.
|
|
11
|
+
* @param arg - The argument to create an error result from.
|
|
12
|
+
* @returns An error result.
|
|
13
|
+
*/
|
|
14
|
+
export function fail(arg) {
|
|
15
|
+
return { ok: false, ...arg };
|
|
16
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ReadSelectedComparisonOperator, ReadSelectedLogicalOperator, ReadSelectedPropertyType, ReadSelectedSearchDefinitionDto } from '../../data';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a ReadSelectedSearchDefinitionDto ready to be used with the CollectionViewAdapter
|
|
4
|
+
*
|
|
5
|
+
* @param logicalOperator - specify `ReadSelectedLogicalOperator` that will apply to all ReadSelectedSearchPropertyDefinitionDto property definitions included in this search definition
|
|
6
|
+
* @param conditions - Variable number of condition objects containing:
|
|
7
|
+
* - propertyName: The property name from the DTO to search on
|
|
8
|
+
* - operator: The `ReadSelectedComparisonOperator` enum
|
|
9
|
+
* - value: The value to compare against
|
|
10
|
+
* - valueType: The `ReadSelectedPropertyType` being compared
|
|
11
|
+
*/
|
|
12
|
+
export declare function condition<T>(logicalOperator: ReadSelectedLogicalOperator, ...conditions: Array<{
|
|
13
|
+
propertyName: keyof T;
|
|
14
|
+
operator: ReadSelectedComparisonOperator;
|
|
15
|
+
value: unknown;
|
|
16
|
+
valueType: ReadSelectedPropertyType;
|
|
17
|
+
}>): ReadSelectedSearchDefinitionDto<T>;
|
|
18
|
+
/**
|
|
19
|
+
* Combines multiple ReadSelectedSearchDefinitionDto with AND logic
|
|
20
|
+
*/
|
|
21
|
+
export declare function and<T>(...definitions: ReadSelectedSearchDefinitionDto<T>[]): ReadSelectedSearchDefinitionDto<T>;
|
|
22
|
+
/**
|
|
23
|
+
* Combines multiple ReadSelectedSearchDefinitionDto with OR logic
|
|
24
|
+
*/
|
|
25
|
+
export declare function or<T>(...definitions: ReadSelectedSearchDefinitionDto<T>[]): ReadSelectedSearchDefinitionDto<T>;
|
|
26
|
+
/**
|
|
27
|
+
* 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`.
|
|
28
|
+
*/
|
|
29
|
+
export declare function searchTerm<T>(searchTerm: string, textSearchableProperties: (keyof T)[], numericSearchableProperties: (keyof T)[]): void | ReadSelectedSearchDefinitionDto<T>;
|
|
30
|
+
/**
|
|
31
|
+
* 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`.
|
|
32
|
+
*/
|
|
33
|
+
export declare function dateInterval<T>(fromDate: Date, toDate: Date, fromDateComparisonOperator: ReadSelectedComparisonOperator, toDateComparisonOperator: ReadSelectedComparisonOperator, valueType: ReadSelectedPropertyType, searchableProperty: keyof T): void | ReadSelectedSearchDefinitionDto<T>;
|
|
34
|
+
export declare function toPascalCase<T>(str: keyof T): keyof T;
|