@intellegens/cornerstone-client 0.0.9999-alpha-3 → 0.0.9999-alpha-5
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 +27 -27
- package/services/api/ApiInitializationService/index.js +45 -41
- 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
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents available error codes to be returned as part of the ApiResponse object
|
|
3
|
+
*/
|
|
4
|
+
export declare enum ErrorCode {
|
|
5
|
+
InternalServerError = 500,
|
|
6
|
+
NotFound = 404,
|
|
7
|
+
BadRequest = 400,
|
|
8
|
+
NotImplemented = 501,
|
|
9
|
+
Unauthorized = 401,
|
|
10
|
+
GatewayTimeout = 504,
|
|
11
|
+
ValidationFailed = 422,
|
|
12
|
+
UnknownError = 599
|
|
13
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents available error codes to be returned as part of the ApiResponse object
|
|
3
|
+
*/
|
|
4
|
+
export var ErrorCode;
|
|
5
|
+
(function (ErrorCode) {
|
|
6
|
+
ErrorCode[ErrorCode["InternalServerError"] = 500] = "InternalServerError";
|
|
7
|
+
ErrorCode[ErrorCode["NotFound"] = 404] = "NotFound";
|
|
8
|
+
ErrorCode[ErrorCode["BadRequest"] = 400] = "BadRequest";
|
|
9
|
+
ErrorCode[ErrorCode["NotImplemented"] = 501] = "NotImplemented";
|
|
10
|
+
ErrorCode[ErrorCode["Unauthorized"] = 401] = "Unauthorized";
|
|
11
|
+
ErrorCode[ErrorCode["GatewayTimeout"] = 504] = "GatewayTimeout";
|
|
12
|
+
ErrorCode[ErrorCode["ValidationFailed"] = 422] = "ValidationFailed";
|
|
13
|
+
ErrorCode[ErrorCode["UnknownError"] = 599] = "UnknownError";
|
|
14
|
+
})(ErrorCode || (ErrorCode = {}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './ErrorCode';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './ErrorCode';
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ApiResponseDto, EmptyMetadataDto } from '../../../data/api/dto';
|
|
2
2
|
import { IIdentifiable } from '../../../data/api/interface';
|
|
3
3
|
import { IHttpService } from '../HttpService';
|
|
4
4
|
import { ApiReadControllerClient } from '../ApiReadControllerClient';
|
|
@@ -23,7 +23,7 @@ export declare class ApiCrudControllerClient<TKey, TDto extends IIdentifiable<TK
|
|
|
23
23
|
* @param {AbortSignal} [signal] - Optional cancellation signal
|
|
24
24
|
* @returns The created entity DTO
|
|
25
25
|
*/
|
|
26
|
-
createAsync(dto: TDto, signal?: AbortSignal): Promise<
|
|
26
|
+
createAsync(dto: TDto, signal?: AbortSignal): Promise<ApiResponseDto<TDto, EmptyMetadataDto>>;
|
|
27
27
|
/**
|
|
28
28
|
* Updates an existing entity.
|
|
29
29
|
* @param id - The ID of the entity to update
|
|
@@ -31,11 +31,11 @@ export declare class ApiCrudControllerClient<TKey, TDto extends IIdentifiable<TK
|
|
|
31
31
|
* @param {AbortSignal} [signal] - Optional cancellation signal
|
|
32
32
|
* @returns The updated entity DTO
|
|
33
33
|
*/
|
|
34
|
-
updateAsync(id: TKey, dto: TDto, signal?: AbortSignal): Promise<
|
|
34
|
+
updateAsync(id: TKey, dto: TDto, signal?: AbortSignal): Promise<ApiResponseDto<TDto, EmptyMetadataDto>>;
|
|
35
35
|
/**
|
|
36
36
|
* Deletes an entity by ID.
|
|
37
37
|
* @param id - The ID of the entity to delete
|
|
38
38
|
* @param {AbortSignal} [signal] - Optional cancellation signal
|
|
39
39
|
*/
|
|
40
|
-
deleteAsync(id: TKey, signal?: AbortSignal): Promise<
|
|
40
|
+
deleteAsync(id: TKey, signal?: AbortSignal): Promise<ApiResponseDto<null, EmptyMetadataDto>>;
|
|
41
41
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { apiInitializationService } from '../ApiInitializationService';
|
|
2
2
|
import { ApiReadControllerClient } from '../ApiReadControllerClient';
|
|
3
|
+
import { ErrorCode } from '../../../data';
|
|
4
|
+
import { fail } from '../../../utils/result';
|
|
3
5
|
/**
|
|
4
6
|
* Generic API client for consuming any Cornerstone CrudController
|
|
5
7
|
*
|
|
@@ -33,16 +35,20 @@ export class ApiCrudControllerClient extends ApiReadControllerClient {
|
|
|
33
35
|
credentials: 'include',
|
|
34
36
|
signal,
|
|
35
37
|
});
|
|
36
|
-
if (!res.ok)
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
throw new Error(error.message);
|
|
41
|
-
return { result, metadata };
|
|
38
|
+
if (!res.ok) {
|
|
39
|
+
return (await res.json());
|
|
40
|
+
}
|
|
41
|
+
return (await res.json());
|
|
42
42
|
}
|
|
43
43
|
catch (err) {
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
console.error(err);
|
|
45
|
+
return fail({
|
|
46
|
+
error: {
|
|
47
|
+
code: ErrorCode.UnknownError,
|
|
48
|
+
message: 'Unknown error occurred while creating the record.',
|
|
49
|
+
metadata: {},
|
|
50
|
+
},
|
|
51
|
+
});
|
|
46
52
|
}
|
|
47
53
|
}
|
|
48
54
|
/**
|
|
@@ -62,16 +68,20 @@ export class ApiCrudControllerClient extends ApiReadControllerClient {
|
|
|
62
68
|
credentials: 'include',
|
|
63
69
|
signal,
|
|
64
70
|
});
|
|
65
|
-
if (!res.ok)
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
throw new Error(error.message);
|
|
70
|
-
return { result, metadata };
|
|
71
|
+
if (!res.ok) {
|
|
72
|
+
return (await res.json());
|
|
73
|
+
}
|
|
74
|
+
return (await res.json());
|
|
71
75
|
}
|
|
72
76
|
catch (err) {
|
|
73
|
-
|
|
74
|
-
|
|
77
|
+
console.error(err);
|
|
78
|
+
return fail({
|
|
79
|
+
error: {
|
|
80
|
+
code: ErrorCode.UnknownError,
|
|
81
|
+
message: `Unknown error occurred while updating the record with id ${id}`,
|
|
82
|
+
metadata: {},
|
|
83
|
+
},
|
|
84
|
+
});
|
|
75
85
|
}
|
|
76
86
|
}
|
|
77
87
|
/**
|
|
@@ -82,17 +92,25 @@ export class ApiCrudControllerClient extends ApiReadControllerClient {
|
|
|
82
92
|
async deleteAsync(id, signal) {
|
|
83
93
|
try {
|
|
84
94
|
const url = await apiInitializationService.getApiUrlAsync(this.baseControllerPath, `/Delete?id=${encodeURIComponent(String(id))}`);
|
|
85
|
-
const
|
|
95
|
+
const res = await this.httpService.requestAsync(url, {
|
|
86
96
|
method: 'DELETE',
|
|
87
97
|
credentials: 'include',
|
|
88
98
|
signal,
|
|
89
99
|
});
|
|
90
|
-
if (!
|
|
91
|
-
|
|
100
|
+
if (!res.ok) {
|
|
101
|
+
return { ok: false, ...(await res.json()) };
|
|
102
|
+
}
|
|
103
|
+
return (await res.json());
|
|
92
104
|
}
|
|
93
105
|
catch (err) {
|
|
94
|
-
|
|
95
|
-
|
|
106
|
+
console.error(err);
|
|
107
|
+
return fail({
|
|
108
|
+
error: {
|
|
109
|
+
code: ErrorCode.UnknownError,
|
|
110
|
+
message: `Unknown error occurred while deleting the record with id ${id}`,
|
|
111
|
+
metadata: {},
|
|
112
|
+
},
|
|
113
|
+
});
|
|
96
114
|
}
|
|
97
115
|
}
|
|
98
116
|
}
|
|
@@ -13,29 +13,6 @@ import { IHttpService } from '../HttpService';
|
|
|
13
13
|
* @class ApiInitializationService
|
|
14
14
|
*/
|
|
15
15
|
export declare class ApiInitializationService {
|
|
16
|
-
/**
|
|
17
|
-
* Initializes the API configuration
|
|
18
|
-
*
|
|
19
|
-
* This method calls all methods that need to be called during the API configuration phase:
|
|
20
|
-
* - Starts detection of API base URL.
|
|
21
|
-
* - Fetches shared settings from the server.
|
|
22
|
-
*
|
|
23
|
-
* @async
|
|
24
|
-
* @param httpService - HTTP service implementation to use for requests
|
|
25
|
-
* @param {AbortSignal} [signal] - Optional cancellation signal
|
|
26
|
-
* @return {Promise<void>} Resolves when initialization is complete.
|
|
27
|
-
*/
|
|
28
|
-
initializeAsync({ httpService, signal }?: {
|
|
29
|
-
httpService?: IHttpService;
|
|
30
|
-
signal?: AbortSignal;
|
|
31
|
-
}): Promise<void>;
|
|
32
|
-
private _httpService;
|
|
33
|
-
/**
|
|
34
|
-
* Gets configured HTTP service
|
|
35
|
-
* @returns
|
|
36
|
-
*/
|
|
37
|
-
_getHttpService(): IHttpService;
|
|
38
|
-
private _apiBaseUrlPromise;
|
|
39
16
|
/**
|
|
40
17
|
* If API base URL detection was completed
|
|
41
18
|
* IMPORTANT: This property is not meant to be used in normal cases - when ever possible use the .getApiUrl(relativeEndpointPath: string) method instead.
|
|
@@ -56,6 +33,30 @@ export declare class ApiInitializationService {
|
|
|
56
33
|
* IMPORTANT: This property is not meant to be used in normal cases - when ever possible use the .getApiUrl(relativeEndpointPath: string) method instead.
|
|
57
34
|
*/
|
|
58
35
|
_apiBaseError: Error | undefined;
|
|
36
|
+
appConfig?: ISharedSettings | undefined;
|
|
37
|
+
private _httpService;
|
|
38
|
+
private _apiBaseUrlPromise;
|
|
39
|
+
/**
|
|
40
|
+
* Initializes the API configuration
|
|
41
|
+
*
|
|
42
|
+
* This method calls all methods that need to be called during the API configuration phase:
|
|
43
|
+
* - Starts detection of API base URL.
|
|
44
|
+
* - Fetches shared settings from the server.
|
|
45
|
+
*
|
|
46
|
+
* @async
|
|
47
|
+
* @param httpService - HTTP service implementation to use for requests
|
|
48
|
+
* @param {AbortSignal} [signal] - Optional cancellation signal
|
|
49
|
+
* @return {Promise<void>} Resolves when initialization is complete.
|
|
50
|
+
*/
|
|
51
|
+
initializeAsync({ httpService, signal, }?: {
|
|
52
|
+
httpService?: IHttpService;
|
|
53
|
+
signal?: AbortSignal;
|
|
54
|
+
}): Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* Gets configured HTTP service
|
|
57
|
+
* @returns
|
|
58
|
+
*/
|
|
59
|
+
_getHttpService(): IHttpService;
|
|
59
60
|
/**
|
|
60
61
|
* Tries detecting API base URL by multiple methods
|
|
61
62
|
*
|
|
@@ -92,11 +93,10 @@ export declare class ApiInitializationService {
|
|
|
92
93
|
* @returns String with ending '/' character removed
|
|
93
94
|
*/
|
|
94
95
|
private removeEndsWithSlashChar;
|
|
95
|
-
appConfig?: ISharedSettings | undefined;
|
|
96
96
|
/**
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
97
|
+
* Fetches initialization info (shared settings) from the server
|
|
98
|
+
* @returns Promise that resolves to shared settings or undefined if the request fails
|
|
99
|
+
*/
|
|
100
100
|
private _getAppConfigAsync;
|
|
101
101
|
}
|
|
102
102
|
/**
|
|
@@ -6,6 +6,33 @@ import { defaultHttpService } from '../HttpService';
|
|
|
6
6
|
* @class ApiInitializationService
|
|
7
7
|
*/
|
|
8
8
|
export class ApiInitializationService {
|
|
9
|
+
/**
|
|
10
|
+
* If API base URL detection was completed
|
|
11
|
+
* IMPORTANT: This property is not meant to be used in normal cases - when ever possible use the .getApiUrl(relativeEndpointPath: string) method instead.
|
|
12
|
+
*/
|
|
13
|
+
_apiBaseUrlDetected = false;
|
|
14
|
+
// #region HTTP service
|
|
15
|
+
/**
|
|
16
|
+
* If API base URL detection was completed, this property will hold the method by which detection was performed
|
|
17
|
+
* IMPORTANT: This property is not meant to be used in normal cases - when ever possible use the .getApiUrl(relativeEndpointPath: string) method instead.
|
|
18
|
+
*/
|
|
19
|
+
_apiBaseUrlDetectionMethod = undefined;
|
|
20
|
+
/**
|
|
21
|
+
* If API base URL detection was completed, this property will hold the detected API base URL
|
|
22
|
+
* IMPORTANT: This property is not meant to be used in normal cases - when ever possible use the .getApiUrl(relativeEndpointPath: string) method instead.
|
|
23
|
+
*/
|
|
24
|
+
_apiBaseUrl = undefined;
|
|
25
|
+
// #endregion
|
|
26
|
+
// #region API Base URL detection
|
|
27
|
+
/**
|
|
28
|
+
* If API base URL detection has failed, this property will hold the error with which it has failed
|
|
29
|
+
* IMPORTANT: This property is not meant to be used in normal cases - when ever possible use the .getApiUrl(relativeEndpointPath: string) method instead.
|
|
30
|
+
*/
|
|
31
|
+
_apiBaseError = undefined;
|
|
32
|
+
// #region config App
|
|
33
|
+
appConfig;
|
|
34
|
+
_httpService = defaultHttpService;
|
|
35
|
+
_apiBaseUrlPromise = undefined;
|
|
9
36
|
/**
|
|
10
37
|
* Initializes the API configuration
|
|
11
38
|
*
|
|
@@ -18,7 +45,7 @@ export class ApiInitializationService {
|
|
|
18
45
|
* @param {AbortSignal} [signal] - Optional cancellation signal
|
|
19
46
|
* @return {Promise<void>} Resolves when initialization is complete.
|
|
20
47
|
*/
|
|
21
|
-
async initializeAsync({ httpService, signal } = {}) {
|
|
48
|
+
async initializeAsync({ httpService, signal, } = {}) {
|
|
22
49
|
// Store configuration
|
|
23
50
|
if (httpService !== undefined)
|
|
24
51
|
this._httpService = httpService;
|
|
@@ -27,8 +54,6 @@ export class ApiInitializationService {
|
|
|
27
54
|
// Initialize app config
|
|
28
55
|
await this._getAppConfigAsync();
|
|
29
56
|
}
|
|
30
|
-
// #region HTTP service
|
|
31
|
-
_httpService = defaultHttpService;
|
|
32
57
|
/**
|
|
33
58
|
* Gets configured HTTP service
|
|
34
59
|
* @returns
|
|
@@ -36,29 +61,6 @@ export class ApiInitializationService {
|
|
|
36
61
|
_getHttpService() {
|
|
37
62
|
return this._httpService;
|
|
38
63
|
}
|
|
39
|
-
// #endregion
|
|
40
|
-
// #region API Base URL detection
|
|
41
|
-
_apiBaseUrlPromise = undefined;
|
|
42
|
-
/**
|
|
43
|
-
* If API base URL detection was completed
|
|
44
|
-
* IMPORTANT: This property is not meant to be used in normal cases - when ever possible use the .getApiUrl(relativeEndpointPath: string) method instead.
|
|
45
|
-
*/
|
|
46
|
-
_apiBaseUrlDetected = false;
|
|
47
|
-
/**
|
|
48
|
-
* If API base URL detection was completed, this property will hold the method by which detection was performed
|
|
49
|
-
* IMPORTANT: This property is not meant to be used in normal cases - when ever possible use the .getApiUrl(relativeEndpointPath: string) method instead.
|
|
50
|
-
*/
|
|
51
|
-
_apiBaseUrlDetectionMethod = undefined;
|
|
52
|
-
/**
|
|
53
|
-
* If API base URL detection was completed, this property will hold the detected API base URL
|
|
54
|
-
* IMPORTANT: This property is not meant to be used in normal cases - when ever possible use the .getApiUrl(relativeEndpointPath: string) method instead.
|
|
55
|
-
*/
|
|
56
|
-
_apiBaseUrl = undefined;
|
|
57
|
-
/**
|
|
58
|
-
* If API base URL detection has failed, this property will hold the error with which it has failed
|
|
59
|
-
* IMPORTANT: This property is not meant to be used in normal cases - when ever possible use the .getApiUrl(relativeEndpointPath: string) method instead.
|
|
60
|
-
*/
|
|
61
|
-
_apiBaseError = undefined;
|
|
62
64
|
/**
|
|
63
65
|
* Tries detecting API base URL by multiple methods
|
|
64
66
|
*
|
|
@@ -89,7 +91,10 @@ export class ApiInitializationService {
|
|
|
89
91
|
this._apiBaseError = undefined;
|
|
90
92
|
// Check CORNERSTONE-API-BASEURL header for API base URL
|
|
91
93
|
try {
|
|
92
|
-
const currentUrlResponse = await this._httpService.requestAsync(window.location.href, {
|
|
94
|
+
const currentUrlResponse = await this._httpService.requestAsync(window.location.href, {
|
|
95
|
+
method: 'GET',
|
|
96
|
+
signal,
|
|
97
|
+
});
|
|
93
98
|
const apiHeader = currentUrlResponse.headers['CORNERSTONE-API-BASEURL'] || currentUrlResponse.headers['cornerstone-api-baseurl'] || null;
|
|
94
99
|
if (apiHeader) {
|
|
95
100
|
this._apiBaseUrlDetected = true;
|
|
@@ -105,7 +110,10 @@ export class ApiInitializationService {
|
|
|
105
110
|
}
|
|
106
111
|
// Check ./websettings.json header for API base URL
|
|
107
112
|
try {
|
|
108
|
-
const webSettingsResponse = await this._httpService.requestAsync('./websettings.json', {
|
|
113
|
+
const webSettingsResponse = await this._httpService.requestAsync('./websettings.json', {
|
|
114
|
+
method: 'GET',
|
|
115
|
+
signal,
|
|
116
|
+
});
|
|
109
117
|
if (webSettingsResponse.status === 404)
|
|
110
118
|
return (this._apiBaseUrl = undefined);
|
|
111
119
|
const webSettings = await webSettingsResponse.json();
|
|
@@ -160,6 +168,7 @@ export class ApiInitializationService {
|
|
|
160
168
|
removeStartsWithSlashChar(str) {
|
|
161
169
|
return !str.startsWith('/') ? str : str.substring(1);
|
|
162
170
|
}
|
|
171
|
+
// #endregion
|
|
163
172
|
/**
|
|
164
173
|
* Removes ending '/' character
|
|
165
174
|
* @param str String to remove the ending '/' character from
|
|
@@ -168,27 +177,22 @@ export class ApiInitializationService {
|
|
|
168
177
|
removeEndsWithSlashChar(str) {
|
|
169
178
|
return !str.endsWith('/') ? str : str.substring(0, str.length - 1);
|
|
170
179
|
}
|
|
171
|
-
// #endregion
|
|
172
|
-
// #region config App
|
|
173
|
-
appConfig;
|
|
174
180
|
/**
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
181
|
+
* Fetches initialization info (shared settings) from the server
|
|
182
|
+
* @returns Promise that resolves to shared settings or undefined if the request fails
|
|
183
|
+
*/
|
|
178
184
|
async _getAppConfigAsync() {
|
|
179
185
|
try {
|
|
180
|
-
const response = await fetch(`${this._apiBaseUrl}/
|
|
181
|
-
if (!response.ok)
|
|
182
|
-
throw
|
|
183
|
-
const apiResponse = await response.json();
|
|
184
|
-
// Check if the API response indicates success
|
|
185
|
-
if (!apiResponse.success || !apiResponse.result) {
|
|
186
|
-
throw new Error(apiResponse.error?.message || 'Server returned unsuccessful response');
|
|
186
|
+
const response = await fetch(`${this._apiBaseUrl}/system/init`, { credentials: 'include' });
|
|
187
|
+
if (!response.ok) {
|
|
188
|
+
throw (await response.json());
|
|
187
189
|
}
|
|
190
|
+
const apiResponse = await response.json();
|
|
188
191
|
// Return the settings from the nested structure
|
|
189
192
|
this.appConfig = apiResponse.result.settings;
|
|
190
193
|
}
|
|
191
194
|
catch (error) {
|
|
195
|
+
console.error('Failed to get app config', error);
|
|
192
196
|
this.appConfig = undefined;
|
|
193
197
|
}
|
|
194
198
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ApiResponseDto, EmptyMetadataDto, ReadMetadataDto, ReadSelectedDefinitionDto } from '../../../data/api/dto';
|
|
2
2
|
import { IIdentifiable } from '../../../data/api/interface';
|
|
3
3
|
import { IHttpService } from '../HttpService';
|
|
4
4
|
/**
|
|
@@ -22,19 +22,19 @@ export declare class ApiReadControllerClient<TKey, TDto extends IIdentifiable<TK
|
|
|
22
22
|
* @param {AbortSignal} [signal] - Optional cancellation signal
|
|
23
23
|
* @returns {Promise<ApiSuccessResponseDto<TDto>[], ReadMetadataDto>>} List of all entities with metadata
|
|
24
24
|
*/
|
|
25
|
-
readAllAsync(signal?: AbortSignal): Promise<
|
|
25
|
+
readAllAsync(signal?: AbortSignal): Promise<ApiResponseDto<TDto[], ReadMetadataDto>>;
|
|
26
26
|
/**
|
|
27
27
|
* Fetches selected entities based on a filter definition.
|
|
28
28
|
* @param {any} definition - The filter definition object
|
|
29
29
|
* @param {AbortSignal} [signal] - Optional cancellation signal
|
|
30
30
|
* @returns {Promise<ApiSuccessResponseDto<TDto>[], ReadMetadataDto>>} The result of the read operation with metadata
|
|
31
31
|
*/
|
|
32
|
-
readSelectedAsync(definition: ReadSelectedDefinitionDto
|
|
32
|
+
readSelectedAsync(definition: ReadSelectedDefinitionDto<TDto>, signal?: AbortSignal): Promise<ApiResponseDto<TDto[], ReadMetadataDto>>;
|
|
33
33
|
/**
|
|
34
34
|
* Fetches a single entity by its ID.
|
|
35
35
|
* @param {TKey} id - The ID of the entity
|
|
36
36
|
* @param {AbortSignal} [signal] - Optional cancellation signal
|
|
37
37
|
* @returns {Promise<ApiSuccessResponseDto<TDto, EmptyMetadataDto>>} The requested entity
|
|
38
38
|
*/
|
|
39
|
-
readSingleAsync(id: TKey, signal?: AbortSignal): Promise<
|
|
39
|
+
readSingleAsync(id: TKey, signal?: AbortSignal): Promise<ApiResponseDto<TDto, EmptyMetadataDto>>;
|
|
40
40
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { apiInitializationService } from '../ApiInitializationService';
|
|
2
|
+
import { fail } from '../../../utils/result';
|
|
3
|
+
import { ErrorCode } from '../../../data';
|
|
2
4
|
/**
|
|
3
5
|
* Base client for read-only API controllers
|
|
4
6
|
*/
|
|
@@ -32,16 +34,20 @@ export class ApiReadControllerClient {
|
|
|
32
34
|
try {
|
|
33
35
|
const url = await apiInitializationService.getApiUrlAsync(this.baseControllerPath, `/ReadAll`);
|
|
34
36
|
const res = await this.httpService.requestAsync(url, { method: 'GET', credentials: 'include', signal });
|
|
35
|
-
if (!res.ok)
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
throw new Error(error.message);
|
|
40
|
-
return { result, metadata };
|
|
37
|
+
if (!res.ok) {
|
|
38
|
+
return fail(await res.json());
|
|
39
|
+
}
|
|
40
|
+
return (await res.json());
|
|
41
41
|
}
|
|
42
42
|
catch (err) {
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
console.error(err);
|
|
44
|
+
return fail({
|
|
45
|
+
error: {
|
|
46
|
+
code: ErrorCode.UnknownError,
|
|
47
|
+
message: 'Unknown error fetching all records',
|
|
48
|
+
metadata: {},
|
|
49
|
+
},
|
|
50
|
+
});
|
|
45
51
|
}
|
|
46
52
|
}
|
|
47
53
|
/**
|
|
@@ -60,16 +66,20 @@ export class ApiReadControllerClient {
|
|
|
60
66
|
credentials: 'include',
|
|
61
67
|
signal,
|
|
62
68
|
});
|
|
63
|
-
if (!res.ok)
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
throw new Error(error.message);
|
|
68
|
-
return { result, metadata };
|
|
69
|
+
if (!res.ok) {
|
|
70
|
+
return (await res.json());
|
|
71
|
+
}
|
|
72
|
+
return (await res.json());
|
|
69
73
|
}
|
|
70
74
|
catch (err) {
|
|
71
|
-
|
|
72
|
-
|
|
75
|
+
console.error(err);
|
|
76
|
+
return fail({
|
|
77
|
+
error: {
|
|
78
|
+
code: ErrorCode.UnknownError,
|
|
79
|
+
message: 'Unknown error fetching selected records',
|
|
80
|
+
metadata: {},
|
|
81
|
+
},
|
|
82
|
+
});
|
|
73
83
|
}
|
|
74
84
|
}
|
|
75
85
|
/**
|
|
@@ -82,16 +92,20 @@ export class ApiReadControllerClient {
|
|
|
82
92
|
try {
|
|
83
93
|
const url = await apiInitializationService.getApiUrlAsync(this.baseControllerPath, `/ReadSingle?id=${encodeURIComponent(String(id))}`);
|
|
84
94
|
const res = await this.httpService.requestAsync(url, { method: 'GET', credentials: 'include', signal });
|
|
85
|
-
if (!res.ok)
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
throw new Error(error.message);
|
|
90
|
-
return { result, metadata };
|
|
95
|
+
if (!res.ok) {
|
|
96
|
+
return (await res.json());
|
|
97
|
+
}
|
|
98
|
+
return (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 fetching record with id ${id}`,
|
|
106
|
+
metadata: {},
|
|
107
|
+
},
|
|
108
|
+
});
|
|
95
109
|
}
|
|
96
110
|
}
|
|
97
111
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ApiCrudControllerClient } from '../ApiCrudControllerClient';
|
|
2
2
|
import { IHttpService } from '../HttpService';
|
|
3
|
-
import {
|
|
3
|
+
import { ApiResponseDto, ClaimDto, EmptyMetadataDto, ReadMetadataDto, UserDto } from '../../../data';
|
|
4
4
|
/**
|
|
5
5
|
* Client for user management operations
|
|
6
6
|
*
|
|
@@ -22,20 +22,20 @@ export declare class UserManagementControllerClient<TKey, TUser extends UserDto<
|
|
|
22
22
|
* @param {AbortSignal} [signal] - Optional cancellation signal
|
|
23
23
|
* @returns List of role names assigned to the user
|
|
24
24
|
*/
|
|
25
|
-
getUserRolesAsync(id: TKey, signal?: AbortSignal): Promise<
|
|
25
|
+
getUserRolesAsync(id: TKey, signal?: AbortSignal): Promise<ApiResponseDto<string[], ReadMetadataDto>>;
|
|
26
26
|
/**
|
|
27
27
|
* Gets the claims assigned to a user
|
|
28
28
|
* @param id - The ID of the user
|
|
29
29
|
* @param {AbortSignal} [signal] - Optional cancellation signal
|
|
30
30
|
* @returns List of claims assigned to the user
|
|
31
31
|
*/
|
|
32
|
-
getUserClaimsAsync(id: TKey, signal?: AbortSignal): Promise<
|
|
32
|
+
getUserClaimsAsync(id: TKey, signal?: AbortSignal): Promise<ApiResponseDto<ClaimDto[], ReadMetadataDto>>;
|
|
33
33
|
/**
|
|
34
34
|
* Gets all available roles in the system
|
|
35
35
|
* @param {AbortSignal} [signal] - Optional cancellation signal
|
|
36
36
|
* @returns List of all role names
|
|
37
37
|
*/
|
|
38
|
-
getAllRolesAsync(signal?: AbortSignal): Promise<
|
|
38
|
+
getAllRolesAsync(signal?: AbortSignal): Promise<ApiResponseDto<string[], ReadMetadataDto>>;
|
|
39
39
|
/**
|
|
40
40
|
* Changes the password for a user
|
|
41
41
|
* @param id - The ID of the user
|
|
@@ -43,5 +43,5 @@ export declare class UserManagementControllerClient<TKey, TUser extends UserDto<
|
|
|
43
43
|
* @param {AbortSignal} [signal] - Optional cancellation signal
|
|
44
44
|
* @returns Promise that resolves when the password is changed successfully
|
|
45
45
|
*/
|
|
46
|
-
changePasswordAsync(id: TKey, newPassword: string, signal?: AbortSignal): Promise<
|
|
46
|
+
changePasswordAsync(id: TKey, newPassword: string, signal?: AbortSignal): Promise<ApiResponseDto<undefined, EmptyMetadataDto>>;
|
|
47
47
|
}
|