@intellegens/cornerstone-client 0.0.9999-alpha-3 → 0.0.9999-alpha-4
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/adapters/CollectionViewAdapter/index.d.ts +36 -30
- package/adapters/CollectionViewAdapter/index.js +63 -42
- package/data/api/dto/read/ReadSelectedDefinitionDto.d.ts +2 -2
- package/data/api/dto/read/ReadSelectedNestedCollectionCriteriaDto.d.ts +22 -0
- package/data/api/dto/read/ReadSelectedNestedCollectionCriteriaDto.js +1 -0
- package/data/api/dto/read/ReadSelectedNestedCriteriaDto.d.ts +18 -0
- package/data/api/dto/read/ReadSelectedNestedCriteriaDto.js +1 -0
- package/data/api/dto/read/ReadSelectedOrderingPropertyDefinitionDto.d.ts +2 -2
- package/data/api/dto/read/ReadSelectedSearchDefinitionDto.d.ts +23 -8
- package/data/api/dto/read/ReadSelectedSearchPropertyDefinitionDto.d.ts +14 -7
- package/data/api/dto/read/index.d.ts +2 -0
- package/data/api/dto/read/index.js +2 -0
- package/data/api/dto/response/ApiErrorDto.d.ts +12 -3
- package/data/api/dto/response/ApiErrorResponseDto.d.ts +11 -0
- package/data/api/dto/response/ApiErrorResponseDto.js +1 -0
- package/data/api/dto/response/ApiResponseDto.d.ts +3 -15
- package/data/api/dto/response/ApiSuccessResponseDto.d.ts +2 -1
- package/data/api/dto/response/MetadataDto.d.ts +25 -0
- package/data/api/dto/response/MetadataDto.js +1 -0
- package/data/api/dto/response/index.d.ts +2 -1
- package/data/api/dto/response/index.js +2 -1
- package/data/api/enum/read/ReadSelectedCollectionOperator.d.ts +16 -0
- package/data/api/enum/read/ReadSelectedCollectionOperator.js +17 -0
- package/data/api/enum/read/index.d.ts +1 -0
- package/data/api/enum/read/index.js +1 -0
- package/data/api/enum/response/ErrorCode.d.ts +13 -0
- package/data/api/enum/response/ErrorCode.js +14 -0
- package/data/api/enum/response/index.d.ts +1 -1
- package/data/api/enum/response/index.js +1 -1
- package/package.json +1 -1
- package/services/api/ApiCrudControllerClient/index.d.ts +4 -4
- package/services/api/ApiCrudControllerClient/index.js +39 -21
- package/services/api/ApiInitializationService/index.d.ts +26 -26
- package/services/api/ApiInitializationService/index.js +43 -39
- package/services/api/ApiReadControllerClient/index.d.ts +4 -4
- package/services/api/ApiReadControllerClient/index.js +38 -24
- package/services/api/UserManagementControllerClient/index.d.ts +5 -5
- package/services/api/UserManagementControllerClient/index.js +51 -29
- package/services/auth/client/AuthService/index.d.ts +4 -4
- package/services/auth/client/AuthService/index.js +44 -27
- package/services/auth/client/AuthorizationManagementControllerClient/index.d.ts +7 -5
- package/services/auth/client/AuthorizationManagementControllerClient/index.js +57 -31
- package/utils/index.d.ts +2 -37
- package/utils/index.js +2 -106
- package/utils/result/index.d.ts +21 -0
- package/utils/result/index.js +16 -0
- package/utils/search/index.d.ts +34 -0
- package/utils/search/index.js +106 -0
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { ApiCrudControllerClient } from '../ApiCrudControllerClient';
|
|
2
2
|
import { apiInitializationService } from '../ApiInitializationService';
|
|
3
|
+
import { ErrorCode } from '../../../data';
|
|
4
|
+
import { fail, ok } from '../../../utils/result';
|
|
3
5
|
/**
|
|
4
6
|
* Client for user management operations
|
|
5
7
|
*
|
|
@@ -31,16 +33,20 @@ export class UserManagementControllerClient extends ApiCrudControllerClient {
|
|
|
31
33
|
credentials: 'include',
|
|
32
34
|
signal,
|
|
33
35
|
});
|
|
34
|
-
if (!res.ok)
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
throw new Error(error.message);
|
|
39
|
-
return { result, metadata };
|
|
36
|
+
if (!res.ok) {
|
|
37
|
+
return fail(await res.json());
|
|
38
|
+
}
|
|
39
|
+
return ok(await res.json());
|
|
40
40
|
}
|
|
41
41
|
catch (err) {
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
console.error(err);
|
|
43
|
+
return fail({
|
|
44
|
+
error: {
|
|
45
|
+
code: ErrorCode.UnknownError,
|
|
46
|
+
message: 'Unknown error while fetching user roles',
|
|
47
|
+
metadata: {},
|
|
48
|
+
},
|
|
49
|
+
});
|
|
44
50
|
}
|
|
45
51
|
}
|
|
46
52
|
/**
|
|
@@ -57,16 +63,20 @@ export class UserManagementControllerClient extends ApiCrudControllerClient {
|
|
|
57
63
|
credentials: 'include',
|
|
58
64
|
signal,
|
|
59
65
|
});
|
|
60
|
-
if (!res.ok)
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
throw new Error(error.message);
|
|
65
|
-
return { result, metadata };
|
|
66
|
+
if (!res.ok) {
|
|
67
|
+
return fail(await res.json());
|
|
68
|
+
}
|
|
69
|
+
return ok(await res.json());
|
|
66
70
|
}
|
|
67
71
|
catch (err) {
|
|
68
|
-
|
|
69
|
-
|
|
72
|
+
console.error(err);
|
|
73
|
+
return fail({
|
|
74
|
+
error: {
|
|
75
|
+
code: ErrorCode.UnknownError,
|
|
76
|
+
message: 'Unknown error while fetching user claims',
|
|
77
|
+
metadata: {},
|
|
78
|
+
},
|
|
79
|
+
});
|
|
70
80
|
}
|
|
71
81
|
}
|
|
72
82
|
/**
|
|
@@ -82,16 +92,20 @@ export class UserManagementControllerClient extends ApiCrudControllerClient {
|
|
|
82
92
|
credentials: 'include',
|
|
83
93
|
signal,
|
|
84
94
|
});
|
|
85
|
-
if (!res.ok)
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
throw new Error(error.message);
|
|
90
|
-
return { result, metadata };
|
|
95
|
+
if (!res.ok) {
|
|
96
|
+
return fail(await res.json());
|
|
97
|
+
}
|
|
98
|
+
return ok(await res.json());
|
|
91
99
|
}
|
|
92
100
|
catch (err) {
|
|
93
|
-
|
|
94
|
-
|
|
101
|
+
console.error(err);
|
|
102
|
+
return fail({
|
|
103
|
+
error: {
|
|
104
|
+
code: ErrorCode.UnknownError,
|
|
105
|
+
message: 'Unknown error while fetching all roles',
|
|
106
|
+
metadata: {},
|
|
107
|
+
},
|
|
108
|
+
});
|
|
95
109
|
}
|
|
96
110
|
}
|
|
97
111
|
/**
|
|
@@ -104,7 +118,7 @@ export class UserManagementControllerClient extends ApiCrudControllerClient {
|
|
|
104
118
|
async changePasswordAsync(id, newPassword, signal) {
|
|
105
119
|
try {
|
|
106
120
|
const url = await apiInitializationService.getApiUrlAsync(this.baseControllerPath, 'ChangePassword', encodeURIComponent(String(id)));
|
|
107
|
-
const
|
|
121
|
+
const res = await this.httpService.requestAsync(url, {
|
|
108
122
|
method: 'POST',
|
|
109
123
|
headers: {
|
|
110
124
|
'Content-Type': 'application/json',
|
|
@@ -113,12 +127,20 @@ export class UserManagementControllerClient extends ApiCrudControllerClient {
|
|
|
113
127
|
credentials: 'include',
|
|
114
128
|
signal,
|
|
115
129
|
});
|
|
116
|
-
if (!
|
|
117
|
-
|
|
130
|
+
if (!res.ok) {
|
|
131
|
+
return fail(await res.json());
|
|
132
|
+
}
|
|
133
|
+
return ok(undefined);
|
|
118
134
|
}
|
|
119
135
|
catch (err) {
|
|
120
|
-
|
|
121
|
-
|
|
136
|
+
console.error(err);
|
|
137
|
+
return fail({
|
|
138
|
+
error: {
|
|
139
|
+
code: ErrorCode.UnknownError,
|
|
140
|
+
message: 'Unknown error while changing password',
|
|
141
|
+
metadata: {},
|
|
142
|
+
},
|
|
143
|
+
});
|
|
122
144
|
}
|
|
123
145
|
}
|
|
124
146
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ApiResponseDto, EmptyMetadataDto, UserDto, UserInfoDto } from '../../../../data';
|
|
2
2
|
export { UserDto, UserInfoDto };
|
|
3
3
|
/**
|
|
4
4
|
* AuthService class is responsible for managing user authentication operations.
|
|
@@ -25,7 +25,7 @@ export declare class AuthService<TKey, TUser extends UserDto<TKey> = UserDto<TKe
|
|
|
25
25
|
* @return {Promise<UserInfoDto<TKey, TUser>>} Currently logged in user's details
|
|
26
26
|
* @throws {Error} Error if fetch fails
|
|
27
27
|
*/
|
|
28
|
-
whoAmIAsync(): Promise<
|
|
28
|
+
whoAmIAsync(): Promise<ApiResponseDto<UserInfoDto<TKey, TUser>, EmptyMetadataDto>>;
|
|
29
29
|
/**
|
|
30
30
|
* Authenticates a user using their username and password, and retrieves user's details
|
|
31
31
|
*
|
|
@@ -34,14 +34,14 @@ export declare class AuthService<TKey, TUser extends UserDto<TKey> = UserDto<TKe
|
|
|
34
34
|
* @return {Promise<TUser>} Currently logged in user's details
|
|
35
35
|
* @throws {Error} Error if fetch fails
|
|
36
36
|
*/
|
|
37
|
-
signinAsync(username: string, password: string): Promise<
|
|
37
|
+
signinAsync(username: string, password: string): Promise<ApiResponseDto<TUser, EmptyMetadataDto>>;
|
|
38
38
|
/**
|
|
39
39
|
* Deauthenticates current user
|
|
40
40
|
*
|
|
41
41
|
* @return {Promise<void>}
|
|
42
42
|
* @throws {Error} Error if fetch fails
|
|
43
43
|
*/
|
|
44
|
-
signoutAsync(): Promise<
|
|
44
|
+
signoutAsync(): Promise<ApiResponseDto<undefined, EmptyMetadataDto>>;
|
|
45
45
|
/**
|
|
46
46
|
* If any API response returns an "Unauthenticated" response, call this method
|
|
47
47
|
* to update local authentication state to unauthenticated
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { apiInitializationService } from '../../..';
|
|
2
|
+
import { ErrorCode } from '../../../../data';
|
|
3
|
+
import { fail, ok } from '../../../../utils';
|
|
2
4
|
/**
|
|
3
5
|
* AuthService class is responsible for managing user authentication operations.
|
|
4
6
|
* It supports login, logout, and checking the current user's details.
|
|
@@ -31,23 +33,21 @@ export class AuthService {
|
|
|
31
33
|
try {
|
|
32
34
|
const url = await apiInitializationService.getApiUrlAsync('/auth/whoami');
|
|
33
35
|
const res = await fetch(url, { credentials: 'include' });
|
|
34
|
-
if (!res.ok
|
|
36
|
+
if (!res.ok) {
|
|
35
37
|
this.user = undefined;
|
|
36
|
-
|
|
38
|
+
return fail(await res.json());
|
|
37
39
|
}
|
|
38
|
-
|
|
39
|
-
this.user = undefined;
|
|
40
|
-
return { result: this.user, metadata: {} };
|
|
41
|
-
}
|
|
42
|
-
const { success, result, metadata, error } = (await res.json());
|
|
43
|
-
if (!success)
|
|
44
|
-
throw new Error(error.message);
|
|
45
|
-
this.user = result.user;
|
|
46
|
-
return { result: { user: this.user, accessTokenExpiry: result.accessTokenExpiry }, metadata };
|
|
40
|
+
return (await res.json());
|
|
47
41
|
}
|
|
48
42
|
catch (err) {
|
|
49
|
-
|
|
50
|
-
|
|
43
|
+
console.error(err);
|
|
44
|
+
return fail({
|
|
45
|
+
error: {
|
|
46
|
+
code: ErrorCode.UnknownError,
|
|
47
|
+
message: 'Failed checking authentication status',
|
|
48
|
+
metadata: {},
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
/**
|
|
@@ -67,18 +67,28 @@ export class AuthService {
|
|
|
67
67
|
body: JSON.stringify({ username, password }),
|
|
68
68
|
credentials: 'include',
|
|
69
69
|
});
|
|
70
|
-
if (!res.ok)
|
|
71
|
-
|
|
70
|
+
if (!res.ok) {
|
|
71
|
+
return fail(await res.json());
|
|
72
|
+
}
|
|
72
73
|
// TODO: Handle tokens if not using cookies
|
|
73
|
-
const
|
|
74
|
-
if (
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
return {
|
|
74
|
+
const whoamIRes = await this.whoAmIAsync();
|
|
75
|
+
if (!whoamIRes.ok) {
|
|
76
|
+
return whoamIRes;
|
|
77
|
+
}
|
|
78
|
+
return ok({
|
|
79
|
+
result: whoamIRes.result.user,
|
|
80
|
+
metadata: whoamIRes.metadata
|
|
81
|
+
});
|
|
78
82
|
}
|
|
79
83
|
catch (err) {
|
|
80
|
-
|
|
81
|
-
|
|
84
|
+
console.error(err);
|
|
85
|
+
return fail({
|
|
86
|
+
error: {
|
|
87
|
+
code: ErrorCode.UnknownError,
|
|
88
|
+
message: 'Failed signing in',
|
|
89
|
+
metadata: {},
|
|
90
|
+
},
|
|
91
|
+
});
|
|
82
92
|
}
|
|
83
93
|
}
|
|
84
94
|
/**
|
|
@@ -91,14 +101,21 @@ export class AuthService {
|
|
|
91
101
|
try {
|
|
92
102
|
const url = await apiInitializationService.getApiUrlAsync('/auth/signout');
|
|
93
103
|
const res = await fetch(url, { credentials: 'include' });
|
|
94
|
-
if (!res.ok)
|
|
95
|
-
|
|
104
|
+
if (!res.ok) {
|
|
105
|
+
return fail(await res.json());
|
|
106
|
+
}
|
|
96
107
|
this.user = undefined;
|
|
97
|
-
return;
|
|
108
|
+
return ok(await res.json());
|
|
98
109
|
}
|
|
99
110
|
catch (err) {
|
|
100
|
-
|
|
101
|
-
|
|
111
|
+
console.error(err);
|
|
112
|
+
return fail({
|
|
113
|
+
error: {
|
|
114
|
+
code: ErrorCode.UnknownError,
|
|
115
|
+
message: 'Failed signing out',
|
|
116
|
+
metadata: {},
|
|
117
|
+
},
|
|
118
|
+
});
|
|
102
119
|
}
|
|
103
120
|
}
|
|
104
121
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ApiResponseDto, EmptyMetadataDto, ReadMetadataDto, RoleDto } from '../../../../data';
|
|
2
2
|
/**
|
|
3
3
|
* Client for authorization management operations
|
|
4
4
|
*
|
|
@@ -15,25 +15,27 @@ export declare class AuthorizationManagementControllerClient {
|
|
|
15
15
|
/**
|
|
16
16
|
* Gets all roles in the system
|
|
17
17
|
* @param includeClaims - Whether to include claims in the response
|
|
18
|
+
* @param signal - Optional cancellation signal
|
|
18
19
|
* @returns List of all roles
|
|
19
20
|
*/
|
|
20
|
-
getAllRolesAsync(includeClaims: boolean): Promise<
|
|
21
|
+
getAllRolesAsync(includeClaims: boolean, signal?: AbortSignal): Promise<ApiResponseDto<RoleDto[], ReadMetadataDto>>;
|
|
21
22
|
/**
|
|
22
23
|
* Gets a role with its claims
|
|
23
24
|
* @param roleName - The name of the role
|
|
25
|
+
* @param signal
|
|
24
26
|
* @returns The role with its claims
|
|
25
27
|
*/
|
|
26
|
-
getRoleWithClaimsAsync(roleName: string): Promise<
|
|
28
|
+
getRoleWithClaimsAsync(roleName: string, signal?: AbortSignal): Promise<ApiResponseDto<RoleDto, ReadMetadataDto>>;
|
|
27
29
|
/**
|
|
28
30
|
* Creates or updates a role
|
|
29
31
|
* @param roleDto - The role to create or update
|
|
30
32
|
* @returns The created or updated role
|
|
31
33
|
*/
|
|
32
|
-
upsertRoleAsync(roleDto: RoleDto): Promise<
|
|
34
|
+
upsertRoleAsync(roleDto: RoleDto): Promise<ApiResponseDto<RoleDto, EmptyMetadataDto>>;
|
|
33
35
|
/**
|
|
34
36
|
* Deletes a role
|
|
35
37
|
* @param roleName - The name of the role to delete
|
|
36
38
|
* @returns Promise that resolves when the role is deleted successfully
|
|
37
39
|
*/
|
|
38
|
-
deleteRoleAsync(roleName: string): Promise<
|
|
40
|
+
deleteRoleAsync(roleName: string): Promise<ApiResponseDto<undefined, EmptyMetadataDto>>;
|
|
39
41
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { apiInitializationService } from '../../..';
|
|
2
|
+
import { ErrorCode } from '../../../../data';
|
|
3
|
+
import { fail, ok } from '../../../../utils/result';
|
|
2
4
|
/**
|
|
3
5
|
* Client for authorization management operations
|
|
4
6
|
*
|
|
@@ -17,47 +19,59 @@ export class AuthorizationManagementControllerClient {
|
|
|
17
19
|
/**
|
|
18
20
|
* Gets all roles in the system
|
|
19
21
|
* @param includeClaims - Whether to include claims in the response
|
|
22
|
+
* @param signal - Optional cancellation signal
|
|
20
23
|
* @returns List of all roles
|
|
21
24
|
*/
|
|
22
|
-
async getAllRolesAsync(includeClaims) {
|
|
25
|
+
async getAllRolesAsync(includeClaims, signal) {
|
|
23
26
|
try {
|
|
24
27
|
const url = await apiInitializationService.getApiUrlAsync(this.baseControllerPath, `/GetAllRoles?includeClaims=${includeClaims}`);
|
|
25
28
|
const res = await fetch(url, {
|
|
26
29
|
credentials: 'include',
|
|
30
|
+
signal,
|
|
27
31
|
});
|
|
28
|
-
if (!res.ok)
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
throw new Error(error.message);
|
|
33
|
-
return { result, metadata };
|
|
32
|
+
if (!res.ok) {
|
|
33
|
+
return fail(await res.json());
|
|
34
|
+
}
|
|
35
|
+
return ok(await res.json());
|
|
34
36
|
}
|
|
35
37
|
catch (err) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
console.error(err);
|
|
39
|
+
return fail({
|
|
40
|
+
error: {
|
|
41
|
+
code: ErrorCode.UnknownError,
|
|
42
|
+
message: 'Unknown error fetching all roles',
|
|
43
|
+
metadata: {},
|
|
44
|
+
},
|
|
45
|
+
});
|
|
38
46
|
}
|
|
39
47
|
}
|
|
40
48
|
/**
|
|
41
49
|
* Gets a role with its claims
|
|
42
50
|
* @param roleName - The name of the role
|
|
51
|
+
* @param signal
|
|
43
52
|
* @returns The role with its claims
|
|
44
53
|
*/
|
|
45
|
-
async getRoleWithClaimsAsync(roleName) {
|
|
54
|
+
async getRoleWithClaimsAsync(roleName, signal) {
|
|
46
55
|
try {
|
|
47
56
|
const url = await apiInitializationService.getApiUrlAsync(this.baseControllerPath, `/GetRoleWithClaims/${encodeURIComponent(roleName)}`);
|
|
48
57
|
const res = await fetch(url, {
|
|
49
58
|
credentials: 'include',
|
|
59
|
+
signal,
|
|
50
60
|
});
|
|
51
|
-
if (!res.ok)
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
throw new Error(error.message);
|
|
56
|
-
return { result, metadata };
|
|
61
|
+
if (!res.ok) {
|
|
62
|
+
return fail(await res.json());
|
|
63
|
+
}
|
|
64
|
+
return ok(await res.json());
|
|
57
65
|
}
|
|
58
66
|
catch (err) {
|
|
59
|
-
|
|
60
|
-
|
|
67
|
+
console.error(err);
|
|
68
|
+
return fail({
|
|
69
|
+
error: {
|
|
70
|
+
code: ErrorCode.UnknownError,
|
|
71
|
+
message: 'Unknown error fetching role with claims',
|
|
72
|
+
metadata: {},
|
|
73
|
+
},
|
|
74
|
+
});
|
|
61
75
|
}
|
|
62
76
|
}
|
|
63
77
|
/**
|
|
@@ -76,16 +90,20 @@ export class AuthorizationManagementControllerClient {
|
|
|
76
90
|
body: JSON.stringify(roleDto),
|
|
77
91
|
credentials: 'include',
|
|
78
92
|
});
|
|
79
|
-
if (!res.ok)
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
throw new Error(error.message);
|
|
84
|
-
return { result, metadata };
|
|
93
|
+
if (!res.ok) {
|
|
94
|
+
return fail(await res.json());
|
|
95
|
+
}
|
|
96
|
+
return ok(await res.json());
|
|
85
97
|
}
|
|
86
98
|
catch (err) {
|
|
87
|
-
|
|
88
|
-
|
|
99
|
+
console.error(err);
|
|
100
|
+
return fail({
|
|
101
|
+
error: {
|
|
102
|
+
code: ErrorCode.UnknownError,
|
|
103
|
+
message: 'Unknown error upserting role',
|
|
104
|
+
metadata: {},
|
|
105
|
+
},
|
|
106
|
+
});
|
|
89
107
|
}
|
|
90
108
|
}
|
|
91
109
|
/**
|
|
@@ -96,16 +114,24 @@ export class AuthorizationManagementControllerClient {
|
|
|
96
114
|
async deleteRoleAsync(roleName) {
|
|
97
115
|
try {
|
|
98
116
|
const url = await apiInitializationService.getApiUrlAsync(this.baseControllerPath, `/DeleteRole/${encodeURIComponent(roleName)}`);
|
|
99
|
-
const
|
|
117
|
+
const res = await fetch(url, {
|
|
100
118
|
method: 'DELETE',
|
|
101
119
|
credentials: 'include',
|
|
102
120
|
});
|
|
103
|
-
if (!
|
|
104
|
-
|
|
121
|
+
if (!res.ok) {
|
|
122
|
+
return fail(await res.json());
|
|
123
|
+
}
|
|
124
|
+
return ok(undefined);
|
|
105
125
|
}
|
|
106
126
|
catch (err) {
|
|
107
|
-
|
|
108
|
-
|
|
127
|
+
console.error(err);
|
|
128
|
+
return fail({
|
|
129
|
+
error: {
|
|
130
|
+
code: ErrorCode.UnknownError,
|
|
131
|
+
message: `Unknown error while deleting the role ${roleName}`,
|
|
132
|
+
metadata: {},
|
|
133
|
+
},
|
|
134
|
+
});
|
|
109
135
|
}
|
|
110
136
|
}
|
|
111
137
|
}
|
package/utils/index.d.ts
CHANGED
|
@@ -1,37 +1,2 @@
|
|
|
1
|
-
|
|
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
|
-
* - path: 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(logicalOperator: ReadSelectedLogicalOperator, ...conditions: Array<{
|
|
13
|
-
path: PropertyPathDto;
|
|
14
|
-
operator: ReadSelectedComparisonOperator;
|
|
15
|
-
value: any;
|
|
16
|
-
valueType: ReadSelectedPropertyType;
|
|
17
|
-
}>): ReadSelectedSearchDefinitionDto;
|
|
18
|
-
/**
|
|
19
|
-
* Combines multiple ReadSelectedSearchDefinitionDto with AND logic
|
|
20
|
-
*/
|
|
21
|
-
export declare function and(...definitions: ReadSelectedSearchDefinitionDto[]): ReadSelectedSearchDefinitionDto;
|
|
22
|
-
/**
|
|
23
|
-
* Combines multiple ReadSelectedSearchDefinitionDto with OR logic
|
|
24
|
-
*/
|
|
25
|
-
export declare function or(...definitions: ReadSelectedSearchDefinitionDto[]): ReadSelectedSearchDefinitionDto;
|
|
26
|
-
/**
|
|
27
|
-
* Preset implementation for filtering by `searchTerm`. String types will search by provided `textSearchablePaths` with `ReadSelectedComparisonOperator.Contains`. Numeric types will search by provided `numericSearchablePaths`, `parseInt` the search term and use `ReadSelectedComparisonOperator.Equal`.
|
|
28
|
-
*/
|
|
29
|
-
export declare function searchTerm(searchTerm: string, textSearchablePaths: string[][], numericSearchablePaths: string[][]): void | ReadSelectedSearchDefinitionDto;
|
|
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 `searchablePath`.
|
|
32
|
-
*/
|
|
33
|
-
export declare function dateInterval(fromDate: Date, toDate: Date, fromDateComparisonOperator: ReadSelectedComparisonOperator, toDateComparisonOperator: ReadSelectedComparisonOperator, valueType: ReadSelectedPropertyType, searchablePath: PropertyPathDto): void | ReadSelectedSearchDefinitionDto;
|
|
34
|
-
/**
|
|
35
|
-
* Converts the camel case used on the TS client to Pascal case expected by the API
|
|
36
|
-
*/
|
|
37
|
-
export declare function toPascalCase(str: PropertyPathDto): PropertyPathDto;
|
|
1
|
+
export * from './result';
|
|
2
|
+
export * from './search';
|
package/utils/index.js
CHANGED
|
@@ -1,106 +1,2 @@
|
|
|
1
|
-
|
|
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
|
-
* - path: 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 function condition(logicalOperator, ...conditions) {
|
|
13
|
-
return {
|
|
14
|
-
logicalOperator: logicalOperator,
|
|
15
|
-
propertyCriteria: conditions.map(condition => ({
|
|
16
|
-
propertyPath: toPascalCase(condition.path),
|
|
17
|
-
comparisonOperator: condition.operator,
|
|
18
|
-
valueType: condition.valueType,
|
|
19
|
-
value: condition.value,
|
|
20
|
-
})),
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Combines multiple ReadSelectedSearchDefinitionDto with AND logic
|
|
25
|
-
*/
|
|
26
|
-
export function and(...definitions) {
|
|
27
|
-
return {
|
|
28
|
-
logicalOperator: ReadSelectedLogicalOperator.And,
|
|
29
|
-
nestedSearchCriteria: definitions,
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Combines multiple ReadSelectedSearchDefinitionDto with OR logic
|
|
34
|
-
*/
|
|
35
|
-
export function or(...definitions) {
|
|
36
|
-
return {
|
|
37
|
-
logicalOperator: ReadSelectedLogicalOperator.Or,
|
|
38
|
-
nestedSearchCriteria: definitions,
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Preset implementation for filtering by `searchTerm`. String types will search by provided `textSearchablePaths` with `ReadSelectedComparisonOperator.Contains`. Numeric types will search by provided `numericSearchablePaths`, `parseInt` the search term and use `ReadSelectedComparisonOperator.Equal`.
|
|
43
|
-
*/
|
|
44
|
-
export function searchTerm(searchTerm, textSearchablePaths, numericSearchablePaths) {
|
|
45
|
-
let comparisonOperator;
|
|
46
|
-
let valueType;
|
|
47
|
-
let searchablePaths;
|
|
48
|
-
let searchValue;
|
|
49
|
-
try {
|
|
50
|
-
const numericValue = parseInt(searchTerm);
|
|
51
|
-
if (!Number.isNaN(numericValue) && String(numericValue) === searchTerm.trim()) {
|
|
52
|
-
comparisonOperator = ReadSelectedComparisonOperator.Equal;
|
|
53
|
-
valueType = ReadSelectedPropertyType.Int;
|
|
54
|
-
searchablePaths = numericSearchablePaths;
|
|
55
|
-
searchValue = numericValue;
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
comparisonOperator = ReadSelectedComparisonOperator.Contains;
|
|
59
|
-
valueType = ReadSelectedPropertyType.String;
|
|
60
|
-
searchablePaths = textSearchablePaths;
|
|
61
|
-
searchValue = searchTerm;
|
|
62
|
-
}
|
|
63
|
-
const searchConditions = searchablePaths.map(path => ({
|
|
64
|
-
path: toPascalCase(path),
|
|
65
|
-
operator: comparisonOperator,
|
|
66
|
-
value: searchValue,
|
|
67
|
-
valueType: valueType,
|
|
68
|
-
}));
|
|
69
|
-
return condition(ReadSelectedLogicalOperator.Or, ...searchConditions);
|
|
70
|
-
}
|
|
71
|
-
catch {
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* 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 `searchablePath`.
|
|
77
|
-
*/
|
|
78
|
-
export function dateInterval(fromDate, toDate, fromDateComparisonOperator, toDateComparisonOperator, valueType, searchablePath) {
|
|
79
|
-
try {
|
|
80
|
-
if (!(valueType === ReadSelectedPropertyType.DateOnly ||
|
|
81
|
-
valueType === ReadSelectedPropertyType.DateTime ||
|
|
82
|
-
valueType === ReadSelectedPropertyType.DateTimeOffset)) {
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
return condition(ReadSelectedLogicalOperator.And, {
|
|
86
|
-
path: toPascalCase(searchablePath),
|
|
87
|
-
operator: fromDateComparisonOperator,
|
|
88
|
-
value: fromDate,
|
|
89
|
-
valueType: valueType,
|
|
90
|
-
}, {
|
|
91
|
-
path: toPascalCase(searchablePath),
|
|
92
|
-
operator: toDateComparisonOperator,
|
|
93
|
-
value: toDate,
|
|
94
|
-
valueType: valueType,
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
catch {
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Converts the camel case used on the TS client to Pascal case expected by the API
|
|
103
|
-
*/
|
|
104
|
-
export function toPascalCase(str) {
|
|
105
|
-
return str.map(part => part.charAt(0).toUpperCase() + part.slice(1));
|
|
106
|
-
}
|
|
1
|
+
export * from './result';
|
|
2
|
+
export * from './search';
|
|
@@ -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
|
+
}
|