@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.
Files changed (48) hide show
  1. package/adapters/CollectionViewAdapter/index.d.ts +36 -30
  2. package/adapters/CollectionViewAdapter/index.js +63 -42
  3. package/data/api/dto/read/ReadSelectedDefinitionDto.d.ts +2 -2
  4. package/data/api/dto/read/ReadSelectedNestedCollectionCriteriaDto.d.ts +22 -0
  5. package/data/api/dto/read/ReadSelectedNestedCollectionCriteriaDto.js +1 -0
  6. package/data/api/dto/read/ReadSelectedNestedCriteriaDto.d.ts +18 -0
  7. package/data/api/dto/read/ReadSelectedNestedCriteriaDto.js +1 -0
  8. package/data/api/dto/read/ReadSelectedOrderingPropertyDefinitionDto.d.ts +2 -2
  9. package/data/api/dto/read/ReadSelectedSearchDefinitionDto.d.ts +23 -8
  10. package/data/api/dto/read/ReadSelectedSearchPropertyDefinitionDto.d.ts +14 -7
  11. package/data/api/dto/read/index.d.ts +2 -0
  12. package/data/api/dto/read/index.js +2 -0
  13. package/data/api/dto/response/ApiErrorDto.d.ts +12 -3
  14. package/data/api/dto/response/ApiErrorResponseDto.d.ts +11 -0
  15. package/data/api/dto/response/ApiErrorResponseDto.js +1 -0
  16. package/data/api/dto/response/ApiResponseDto.d.ts +3 -15
  17. package/data/api/dto/response/ApiSuccessResponseDto.d.ts +2 -1
  18. package/data/api/dto/response/MetadataDto.d.ts +25 -0
  19. package/data/api/dto/response/MetadataDto.js +1 -0
  20. package/data/api/dto/response/index.d.ts +2 -1
  21. package/data/api/dto/response/index.js +2 -1
  22. package/data/api/enum/read/ReadSelectedCollectionOperator.d.ts +16 -0
  23. package/data/api/enum/read/ReadSelectedCollectionOperator.js +17 -0
  24. package/data/api/enum/read/index.d.ts +1 -0
  25. package/data/api/enum/read/index.js +1 -0
  26. package/data/api/enum/response/ErrorCode.d.ts +13 -0
  27. package/data/api/enum/response/ErrorCode.js +14 -0
  28. package/data/api/enum/response/index.d.ts +1 -1
  29. package/data/api/enum/response/index.js +1 -1
  30. package/package.json +1 -1
  31. package/services/api/ApiCrudControllerClient/index.d.ts +4 -4
  32. package/services/api/ApiCrudControllerClient/index.js +39 -21
  33. package/services/api/ApiInitializationService/index.d.ts +27 -27
  34. package/services/api/ApiInitializationService/index.js +45 -41
  35. package/services/api/ApiReadControllerClient/index.d.ts +4 -4
  36. package/services/api/ApiReadControllerClient/index.js +38 -24
  37. package/services/api/UserManagementControllerClient/index.d.ts +5 -5
  38. package/services/api/UserManagementControllerClient/index.js +51 -29
  39. package/services/auth/client/AuthService/index.d.ts +4 -4
  40. package/services/auth/client/AuthService/index.js +44 -27
  41. package/services/auth/client/AuthorizationManagementControllerClient/index.d.ts +7 -5
  42. package/services/auth/client/AuthorizationManagementControllerClient/index.js +57 -31
  43. package/utils/index.d.ts +2 -37
  44. package/utils/index.js +2 -106
  45. package/utils/result/index.d.ts +21 -0
  46. package/utils/result/index.js +16 -0
  47. package/utils/search/index.d.ts +34 -0
  48. package/utils/search/index.js +106 -0
@@ -1,3 +1,4 @@
1
+ export * from './ReadSelectedCollectionOperator';
1
2
  export * from './ReadSelectedComparisonOperator';
2
3
  export * from './ReadSelectedLogicalOperator';
3
4
  export * from './ReadSelectedOrderingDirection';
@@ -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 './ApiErrorCodes';
1
+ export * from './ErrorCode';
@@ -1 +1 @@
1
- export * from './ApiErrorCodes';
1
+ export * from './ErrorCode';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intellegens/cornerstone-client",
3
- "version": "0.0.9999-alpha-3",
3
+ "version": "0.0.9999-alpha-5",
4
4
  "private": false,
5
5
  "publishable": true,
6
6
  "main": "./index.js",
@@ -1,4 +1,4 @@
1
- import { ApiSuccessResponseDto, EmptyMetadataDto } from '../../../data/api/dto';
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<ApiSuccessResponseDto<TDto, EmptyMetadataDto>>;
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<ApiSuccessResponseDto<TDto, EmptyMetadataDto>>;
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<void>;
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
- throw undefined;
38
- const { success, result, metadata, error } = (await res.json());
39
- if (!success)
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
- // TODO: Extract error from well-formed response
45
- throw err instanceof Error ? err : new Error('Unknown error creating record');
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
- throw undefined;
67
- const { success, result, metadata, error } = (await res.json());
68
- if (!success)
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
- // TODO: Extract error from well-formed response
74
- throw err instanceof Error ? err : new Error('Unknown error updating record');
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 response = await this.httpService.requestAsync(url, {
95
+ const res = await this.httpService.requestAsync(url, {
86
96
  method: 'DELETE',
87
97
  credentials: 'include',
88
98
  signal,
89
99
  });
90
- if (!response.ok)
91
- throw undefined;
100
+ if (!res.ok) {
101
+ return { ok: false, ...(await res.json()) };
102
+ }
103
+ return (await res.json());
92
104
  }
93
105
  catch (err) {
94
- // TODO: Extract error from well-formed response
95
- throw err instanceof Error ? err : new Error('Unknown error deleting record');
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
- * Fetches initialization info (shared settings) from the server
98
- * @returns Promise that resolves to shared settings or undefined if the request fails
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, { method: 'GET', signal });
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', { method: 'GET', signal });
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
- * Fetches initialization info (shared settings) from the server
176
- * @returns Promise that resolves to shared settings or undefined if the request fails
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}/api/system/init`, { credentials: 'include' });
181
- if (!response.ok)
182
- throw new Error('Failed to get app config');
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 { ApiSuccessResponseDto, EmptyMetadataDto, ReadMetadataDto, ReadSelectedDefinitionDto } from '../../../data/api/dto';
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<ApiSuccessResponseDto<TDto[], ReadMetadataDto>>;
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, signal?: AbortSignal): Promise<ApiSuccessResponseDto<TDto[], ReadMetadataDto>>;
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<ApiSuccessResponseDto<TDto, EmptyMetadataDto>>;
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
- throw undefined;
37
- const { success, result, metadata, error } = (await res.json());
38
- if (!success)
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
- // TODO: Extract error from well-formed response
44
- throw err instanceof Error ? err : new Error('Unknown error fetching all records');
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
- throw undefined;
65
- const { success, result, metadata, error } = (await res.json());
66
- if (!success)
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
- // TODO: Extract error from well-formed response
72
- throw err instanceof Error ? err : new Error('Unknown error fetching selected records');
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
- throw undefined;
87
- const { success, result, metadata, error } = (await res.json());
88
- if (!success)
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
- // TODO: Extract error from well-formed response
94
- throw err instanceof Error ? err : new Error('Unknown error fetching single record');
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 { UserDto, ClaimDto, ReadMetadataDto, ApiSuccessResponseDto } from '../../../data';
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<ApiSuccessResponseDto<string[], ReadMetadataDto>>;
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<ApiSuccessResponseDto<ClaimDto[], ReadMetadataDto>>;
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<ApiSuccessResponseDto<string[], ReadMetadataDto>>;
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<void>;
46
+ changePasswordAsync(id: TKey, newPassword: string, signal?: AbortSignal): Promise<ApiResponseDto<undefined, EmptyMetadataDto>>;
47
47
  }