@intellegens/cornerstone-client 0.0.25 → 0.0.27

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 (90) hide show
  1. package/README.md +51 -11
  2. package/data/api/dto/ReadSelectedDefinitionDto.d.ts +18 -0
  3. package/data/api/dto/{ReadSelectedFilteringDefinition.d.ts → ReadSelectedFilteringDefinitionDto.d.ts} +4 -4
  4. package/data/api/dto/ReadSelectedFilteringPropertyDefinitionDto.d.ts +107 -0
  5. package/data/api/dto/ReadSelectedOrderingDefinitionDto.d.ts +7 -0
  6. package/data/api/dto/{ReadSelectedOrderingPropertyDefinition.d.ts → ReadSelectedOrderingPropertyDefinitionDto.d.ts} +2 -2
  7. package/data/api/dto/ReadSelectedOrderingPropertyDefinitionDto.js +1 -0
  8. package/data/api/dto/{ReadSelectedPaginationDefinition.js → ReadSelectedPaginationDefinitionDto.d.ts} +4 -4
  9. package/data/api/dto/ReadSelectedPaginationDefinitionDto.js +1 -0
  10. package/data/api/dto/index.d.ts +6 -6
  11. package/data/api/dto/index.js +6 -6
  12. package/data/api/enum/ReadSelectedComparisonOperator.d.ts +29 -1
  13. package/data/api/enum/ReadSelectedComparisonOperator.js +28 -2
  14. package/data/api/enum/ReadSelectedPropertyType.d.ts +38 -2
  15. package/data/api/enum/ReadSelectedPropertyType.js +37 -2
  16. package/data/api/interface/IIdentifiable.d.ts +3 -3
  17. package/data/api/interface/IIdentifiableByGuid.d.ts +3 -3
  18. package/data/api/interface/IOptionallyIdentifiable.d.ts +3 -3
  19. package/data/auth/{Claim/index.d.ts → dto/ClaimDto.d.ts} +2 -2
  20. package/data/auth/dto/ClaimDto.js +1 -0
  21. package/data/auth/dto/RegisterRequestDto.d.ts +4 -0
  22. package/data/auth/dto/RegisterRequestDto.js +1 -0
  23. package/data/auth/dto/RoleDto.d.ts +5 -0
  24. package/data/auth/dto/RoleDto.js +1 -0
  25. package/data/auth/dto/SignInRequestDto.d.ts +4 -0
  26. package/data/auth/dto/SignInRequestDto.js +1 -0
  27. package/data/auth/dto/TokensDto.d.ts +4 -0
  28. package/data/auth/dto/TokensDto.js +1 -0
  29. package/data/auth/{User/index.d.ts → dto/UserDto.d.ts} +4 -4
  30. package/data/auth/dto/UserDto.js +1 -0
  31. package/data/auth/{UserInfo/index.d.ts → dto/UserInfoDto.d.ts} +3 -3
  32. package/data/auth/dto/UserInfoDto.js +1 -0
  33. package/data/auth/dto/index.d.ts +4 -0
  34. package/data/auth/dto/index.js +4 -0
  35. package/data/auth/index.d.ts +1 -4
  36. package/data/auth/index.js +1 -4
  37. package/data/index.d.ts +0 -1
  38. package/data/index.js +0 -1
  39. package/package.json +13 -7
  40. package/services/api/ApiCrudControllerClient/index.d.ts +9 -2
  41. package/services/api/ApiCrudControllerClient/index.js +15 -5
  42. package/services/api/ApiInitializationService/index.d.ts +11 -1
  43. package/services/api/ApiInitializationService/index.js +19 -4
  44. package/services/api/ApiReadControllerClient/index.d.ts +10 -3
  45. package/services/api/ApiReadControllerClient/index.js +18 -5
  46. package/services/api/HttpService/AngularHttpService.d.ts +9 -0
  47. package/services/api/HttpService/AngularHttpService.js +86 -0
  48. package/services/api/HttpService/AxiosHttpService.d.ts +10 -0
  49. package/services/api/HttpService/AxiosHttpService.js +53 -0
  50. package/services/api/HttpService/FetchHttpService.d.ts +7 -0
  51. package/services/api/HttpService/FetchHttpService.js +28 -0
  52. package/services/api/HttpService/HttpRequestConfig.d.ts +9 -0
  53. package/services/api/HttpService/HttpRequestConfig.js +1 -0
  54. package/services/api/HttpService/HttpResponse.d.ts +11 -0
  55. package/services/api/HttpService/HttpResponse.js +3 -0
  56. package/services/api/HttpService/IHttpService.d.ts +13 -0
  57. package/services/api/HttpService/IHttpService.js +3 -0
  58. package/services/api/HttpService/index.d.ts +11 -0
  59. package/services/api/HttpService/index.js +12 -0
  60. package/services/api/UserManagementControllerClient/index.d.ts +10 -3
  61. package/services/api/UserManagementControllerClient/index.js +18 -5
  62. package/services/api/index.d.ts +1 -0
  63. package/services/api/index.js +1 -0
  64. package/services/auth/client/AuthService/index.d.ts +3 -3
  65. package/services/auth/client/AuthorizationManagementControllerClient/index.d.ts +4 -4
  66. package/services/auth/client/AuthorizationManagementControllerClient/index.js +1 -1
  67. package/data/_generated/Cornerstone/Auth/API/DTOs/RegisterRequestDto.d.ts +0 -12
  68. package/data/_generated/Cornerstone/Auth/API/DTOs/RegisterRequestDto.js +0 -2
  69. package/data/_generated/Cornerstone/Auth/API/DTOs/SignInRequestDto.d.ts +0 -12
  70. package/data/_generated/Cornerstone/Auth/API/DTOs/SignInRequestDto.js +0 -2
  71. package/data/_generated/Cornerstone/Auth/API/DTOs/TokensDto.d.ts +0 -12
  72. package/data/_generated/Cornerstone/Auth/API/DTOs/TokensDto.js +0 -2
  73. package/data/_generated/cache.d.ts +0 -3
  74. package/data/_generated/cache.js +0 -2
  75. package/data/_generated/index.d.ts +0 -3
  76. package/data/_generated/index.js +0 -3
  77. package/data/api/dto/ReadSelectedDefinition.d.ts +0 -18
  78. package/data/api/dto/ReadSelectedDefinition.js +0 -17
  79. package/data/api/dto/ReadSelectedFilteringDefinition.js +0 -13
  80. package/data/api/dto/ReadSelectedFilteringPropertyDefinition.d.ts +0 -22
  81. package/data/api/dto/ReadSelectedFilteringPropertyDefinition.js +0 -21
  82. package/data/api/dto/ReadSelectedOrderingDefinition.d.ts +0 -7
  83. package/data/api/dto/ReadSelectedOrderingDefinition.js +0 -6
  84. package/data/api/dto/ReadSelectedOrderingPropertyDefinition.js +0 -14
  85. package/data/api/dto/ReadSelectedPaginationDefinition.d.ts +0 -13
  86. package/data/auth/Role/index.d.ts +0 -5
  87. /package/data/{auth/Claim/index.js → api/dto/ReadSelectedDefinitionDto.js} +0 -0
  88. /package/data/{auth/Role/index.js → api/dto/ReadSelectedFilteringDefinitionDto.js} +0 -0
  89. /package/data/{auth/User/index.js → api/dto/ReadSelectedFilteringPropertyDefinitionDto.js} +0 -0
  90. /package/data/{auth/UserInfo/index.js → api/dto/ReadSelectedOrderingDefinitionDto.js} +0 -0
@@ -0,0 +1,4 @@
1
+ export * from './ClaimDto';
2
+ export * from './UserDto';
3
+ export * from './UserInfoDto';
4
+ export * from './RoleDto';
@@ -1,4 +1 @@
1
- export * from './Claim';
2
- export * from './Role';
3
- export * from './User';
4
- export * from './UserInfo';
1
+ export * from './dto';
@@ -1,4 +1 @@
1
- export * from './Claim';
2
- export * from './Role';
3
- export * from './User';
4
- export * from './UserInfo';
1
+ export * from './dto';
package/data/index.d.ts CHANGED
@@ -1,3 +1,2 @@
1
- export * from './_generated';
2
1
  export * from './auth';
3
2
  export * from './api';
package/data/index.js CHANGED
@@ -1,3 +1,2 @@
1
- export * from './_generated';
2
1
  export * from './auth';
3
2
  export * from './api';
package/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "name": "@intellegens/cornerstone-client",
3
- "version": "0.0.25",
3
+ "version": "0.0.27",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "clean": "node -e \"require('fs-extra').emptyDir('./dist');\"",
8
- "test": "echo \"Error: no test specified\" && exit 1",
9
- "build": "npm run clean && npm run transpile-types && tsc && tsc-alias",
10
- "demo": "npm run build && npx vite build && npx tsx ./demo",
11
- "transpile-types": "cd ../utils/cli && npm run cli zod-gen -- --input '../../client/src/data/_jsonschema' --output '../../client/src/data/_generated'"
8
+ "test": "jest",
9
+ "test:watch": "jest --watch",
10
+ "test:coverage": "jest --coverage",
11
+ "build": "npm run clean && tsc && tsc-alias",
12
+ "demo": "npm run build && npx vite build && npx tsx ./demo"
12
13
  },
13
14
  "author": "",
14
15
  "license": "MIT",
@@ -16,19 +17,24 @@
16
17
  "devDependencies": {
17
18
  "@eslint/js": "^9.21.0",
18
19
  "@types/express": "^5.0.0",
20
+ "@types/jest": "^29.5.12",
19
21
  "@types/node": "^22.13.9",
20
22
  "eslint": "^9.21.0",
21
23
  "eslint-config-prettier": "^10.0.1",
22
24
  "express": "^4.21.2",
23
25
  "fs-extra": "^11.3.0",
24
26
  "globals": "^16.0.0",
27
+ "jest": "^29.7.0",
28
+ "jest-environment-jsdom": "^29.7.0",
25
29
  "prettier": "^3.5.2",
30
+ "ts-jest": "^29.1.2",
26
31
  "tsc-alias": "^1.8.11",
27
32
  "typescript-eslint": "^8.26.0",
28
- "vite": "^6.2.0",
33
+ "vite": "6.3.4",
29
34
  "zod": "^3.24.2"
30
35
  },
31
36
  "dependencies": {
32
- "http-proxy-middleware": "^3.0.3"
37
+ "http-proxy-middleware": "^3.0.3",
38
+ "typescript": "^5.4.5"
33
39
  }
34
40
  }
@@ -1,14 +1,21 @@
1
- import { ApiReadControllerClient } from '../..';
1
+ import { ApiReadControllerClient } from '../ApiReadControllerClient';
2
2
  import { IIdentifiable } from '../../../data';
3
+ import { IHttpService } from '../HttpService';
3
4
  /**
4
5
  * Generic API client for consuming any Cornerstone CrudController
5
6
  *
6
7
  * @export
7
- * @class ApiReadControllerClient
8
+ * @class ApiCrudControllerClient
8
9
  * @template TKey - Type of the entity key (e.g., number, string, GUID, etc.)
9
10
  * @template TDto - Data Transfer Object representing the entity
10
11
  */
11
12
  export declare class ApiCrudControllerClient<TKey, TDto extends IIdentifiable<TKey>> extends ApiReadControllerClient<TKey, TDto> {
13
+ /**
14
+ * Constructor
15
+ * @param baseControllerPath Base path to API controller
16
+ * @param httpService HTTP service implementation to use for requests
17
+ */
18
+ constructor(baseControllerPath: string, httpService?: IHttpService);
12
19
  /**
13
20
  * Creates a new entity.
14
21
  * @param dto - Insert request DTO
@@ -1,13 +1,23 @@
1
- import { apiInitializationService, ApiReadControllerClient } from '../..';
1
+ import { apiInitializationService } from '../ApiInitializationService';
2
+ import { ApiReadControllerClient } from '../ApiReadControllerClient';
3
+ import { defaultHttpService } from '../HttpService';
2
4
  /**
3
5
  * Generic API client for consuming any Cornerstone CrudController
4
6
  *
5
7
  * @export
6
- * @class ApiReadControllerClient
8
+ * @class ApiCrudControllerClient
7
9
  * @template TKey - Type of the entity key (e.g., number, string, GUID, etc.)
8
10
  * @template TDto - Data Transfer Object representing the entity
9
11
  */
10
12
  export class ApiCrudControllerClient extends ApiReadControllerClient {
13
+ /**
14
+ * Constructor
15
+ * @param baseControllerPath Base path to API controller
16
+ * @param httpService HTTP service implementation to use for requests
17
+ */
18
+ constructor(baseControllerPath, httpService = defaultHttpService) {
19
+ super(baseControllerPath, httpService);
20
+ }
11
21
  /**
12
22
  * Creates a new entity.
13
23
  * @param dto - Insert request DTO
@@ -16,7 +26,7 @@ export class ApiCrudControllerClient extends ApiReadControllerClient {
16
26
  async create(dto) {
17
27
  try {
18
28
  const url = await apiInitializationService.getApiUrl(this.baseControllerPath, `/Create`);
19
- const response = await fetch(url, {
29
+ const response = await this.httpService.request(url, {
20
30
  method: 'POST',
21
31
  headers: { 'Content-Type': 'application/json' },
22
32
  body: JSON.stringify(dto),
@@ -39,7 +49,7 @@ export class ApiCrudControllerClient extends ApiReadControllerClient {
39
49
  async update(id, dto) {
40
50
  try {
41
51
  const url = await apiInitializationService.getApiUrl(this.baseControllerPath, `/Update?id=${encodeURIComponent(String(id))}`);
42
- const response = await fetch(url, {
52
+ const response = await this.httpService.request(url, {
43
53
  method: 'PUT',
44
54
  headers: { 'Content-Type': 'application/json' },
45
55
  body: JSON.stringify(dto),
@@ -60,7 +70,7 @@ export class ApiCrudControllerClient extends ApiReadControllerClient {
60
70
  async delete(id) {
61
71
  try {
62
72
  const url = await apiInitializationService.getApiUrl(this.baseControllerPath, `/Delete?id=${encodeURIComponent(String(id))}`);
63
- const response = await fetch(url, {
73
+ const response = await this.httpService.request(url, {
64
74
  method: 'DELETE',
65
75
  credentials: 'include',
66
76
  });
@@ -1,3 +1,4 @@
1
+ import { IHttpService } from '../HttpService';
1
2
  /**
2
3
  * Central API configuration service, fetches and exposes Cornerstone API configuration
3
4
  *
@@ -12,9 +13,18 @@ export declare class ApiInitializationService {
12
13
  * - Starts detection of API base URL.
13
14
  *
14
15
  * @async
16
+ * @param httpService - HTTP service implementation to use for requests
15
17
  * @return {Promise<void>} Resolves when initialization is complete.
16
18
  */
17
- initialize(): Promise<void>;
19
+ initialize({ httpService }?: {
20
+ httpService?: IHttpService;
21
+ }): Promise<void>;
22
+ private _httpService;
23
+ /**
24
+ * Gets configured HTTP service
25
+ * @returns
26
+ */
27
+ _getHttpService(): IHttpService;
18
28
  private _apiBaseUrlPromise;
19
29
  /**
20
30
  * If API base URL detection was completed
@@ -1,3 +1,4 @@
1
+ import { defaultHttpService } from '../HttpService';
1
2
  /**
2
3
  * Central API configuration service, fetches and exposes Cornerstone API configuration
3
4
  *
@@ -12,12 +13,26 @@ export class ApiInitializationService {
12
13
  * - Starts detection of API base URL.
13
14
  *
14
15
  * @async
16
+ * @param httpService - HTTP service implementation to use for requests
15
17
  * @return {Promise<void>} Resolves when initialization is complete.
16
18
  */
17
- async initialize() {
19
+ async initialize({ httpService } = {}) {
20
+ // Store configuration
21
+ if (httpService !== undefined)
22
+ this._httpService = httpService;
18
23
  // (Pre)detect API base URL
19
24
  await this._getApiBaseUrl();
20
25
  }
26
+ // #region HTTP service
27
+ _httpService = defaultHttpService;
28
+ /**
29
+ * Gets configured HTTP service
30
+ * @returns
31
+ */
32
+ _getHttpService() {
33
+ return this._httpService;
34
+ }
35
+ // #endregion
21
36
  // #region API Base URL detection
22
37
  _apiBaseUrlPromise = undefined;
23
38
  /**
@@ -69,8 +84,8 @@ export class ApiInitializationService {
69
84
  this._apiBaseError = undefined;
70
85
  // Check CORNERSTONE-API-BASEURL header for API base URL
71
86
  try {
72
- const currentUrlResponse = await fetch(window.location.href, { method: 'GET' });
73
- const apiHeader = currentUrlResponse.headers.get('CORNERSTONE-API-BASEURL');
87
+ const currentUrlResponse = await this._httpService.request(window.location.href, { method: 'GET' });
88
+ const apiHeader = currentUrlResponse.headers['CORNERSTONE-API-BASEURL'] || currentUrlResponse.headers['cornerstone-api-baseurl'] || null;
74
89
  if (apiHeader) {
75
90
  this._apiBaseUrlDetected = true;
76
91
  this._apiBaseUrlDetectionMethod = 'GET / Header:CORNERSTONE-API-BASEURL';
@@ -85,7 +100,7 @@ export class ApiInitializationService {
85
100
  }
86
101
  // Check ./websettings.json header for API base URL
87
102
  try {
88
- const webSettingsResponse = await fetch('./websettings.json', { method: 'GET' });
103
+ const webSettingsResponse = await this._httpService.request('./websettings.json', { method: 'GET' });
89
104
  if (webSettingsResponse.status === 404)
90
105
  return (this._apiBaseUrl = undefined);
91
106
  const webSettings = await webSettingsResponse.json();
@@ -1,4 +1,5 @@
1
- import { IIdentifiable, ReadSelectedDefinition } from '../../../data';
1
+ import { IIdentifiable, ReadSelectedDefinitionDto } from '../../../data';
2
+ import { IHttpService } from '../HttpService';
2
3
  /**
3
4
  * Generic API client for consuming any Cornerstone ReadController
4
5
  *
@@ -12,14 +13,20 @@ export declare class ApiReadControllerClient<TKey, TDto extends IIdentifiable<TK
12
13
  /**
13
14
  * Constructor
14
15
  * @param baseControllerPath Base path to API controller
16
+ * @param httpService HTTP service implementation to use for requests
15
17
  */
16
- constructor(baseControllerPath: string);
18
+ constructor(baseControllerPath: string, httpService?: IHttpService);
19
+ private _httpService?;
20
+ /**
21
+ * Gets globally selected HTTP service
22
+ */
23
+ protected get httpService(): IHttpService;
17
24
  /**
18
25
  * Fetches selected entities based on a filter definition.
19
26
  * @param {any} definition - The filter definition object
20
27
  * @returns {Promise<TDto[]>} List of entities that match the selection criteria
21
28
  */
22
- readSelected(definition: ReadSelectedDefinition): Promise<TDto[]>;
29
+ readSelected(definition: ReadSelectedDefinitionDto): Promise<TDto[]>;
23
30
  /**
24
31
  * Fetches a single entity by its ID.
25
32
  * @param {TKey} id - The ID of the entity
@@ -1,4 +1,5 @@
1
- import { apiInitializationService } from '../..';
1
+ import { apiInitializationService } from '../ApiInitializationService';
2
+ import { defaultHttpService } from '../HttpService';
2
3
  /**
3
4
  * Generic API client for consuming any Cornerstone ReadController
4
5
  *
@@ -12,10 +13,22 @@ export class ApiReadControllerClient {
12
13
  /**
13
14
  * Constructor
14
15
  * @param baseControllerPath Base path to API controller
16
+ * @param httpService HTTP service implementation to use for requests
15
17
  */
16
- constructor(baseControllerPath) {
18
+ constructor(baseControllerPath, httpService = defaultHttpService) {
17
19
  this.baseControllerPath = baseControllerPath;
20
+ this._httpService = httpService;
18
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
+ // #region API
19
32
  /**
20
33
  * Fetches selected entities based on a filter definition.
21
34
  * @param {any} definition - The filter definition object
@@ -24,7 +37,7 @@ export class ApiReadControllerClient {
24
37
  async readSelected(definition) {
25
38
  try {
26
39
  const url = await apiInitializationService.getApiUrl(this.baseControllerPath, `/ReadSelected`);
27
- const response = await fetch(url, {
40
+ const response = await this.httpService.request(url, {
28
41
  method: 'POST',
29
42
  headers: { 'Content-Type': 'application/json' },
30
43
  body: JSON.stringify(definition),
@@ -46,7 +59,7 @@ export class ApiReadControllerClient {
46
59
  async readSingle(id) {
47
60
  try {
48
61
  const url = await apiInitializationService.getApiUrl(this.baseControllerPath, `/ReadSingle?id=${encodeURIComponent(String(id))}`);
49
- const response = await fetch(url, { credentials: 'include' });
62
+ const response = await this.httpService.request(url, { method: 'GET', credentials: 'include' });
50
63
  if (!response.ok)
51
64
  throw new Error('Failed to fetch single record');
52
65
  return response.json();
@@ -62,7 +75,7 @@ export class ApiReadControllerClient {
62
75
  async readAll() {
63
76
  try {
64
77
  const url = await apiInitializationService.getApiUrl(this.baseControllerPath, `/ReadAll`);
65
- const response = await fetch(url, { credentials: 'include' });
78
+ const response = await this.httpService.request(url, { method: 'GET', credentials: 'include' });
66
79
  if (!response.ok)
67
80
  throw new Error('Failed to fetch all records');
68
81
  return response.json();
@@ -0,0 +1,9 @@
1
+ import { IHttpService, HttpRequestConfig, HttpResponse } from './index';
2
+ /**
3
+ * Angular HttpClient-based HTTP service implementation
4
+ */
5
+ export declare class AngularHttpService implements IHttpService {
6
+ private httpClient;
7
+ constructor(httpClient: any);
8
+ request<T = any>(url: string, config?: HttpRequestConfig): Promise<HttpResponse<T>>;
9
+ }
@@ -0,0 +1,86 @@
1
+ // Ignore eslint any error in this file
2
+ /* eslint-disable @typescript-eslint/no-explicit-any */
3
+ /**
4
+ * Angular HttpClient-based HTTP service implementation
5
+ */
6
+ export class AngularHttpService {
7
+ httpClient;
8
+ constructor(httpClient) {
9
+ if (!httpClient) {
10
+ throw new Error('Angular HttpClient instance is required');
11
+ }
12
+ this.httpClient = httpClient;
13
+ }
14
+ async request(url, config) {
15
+ try {
16
+ const method = config?.method || 'GET';
17
+ const headers = config?.headers || {};
18
+ const body = config?.body;
19
+ const withCredentials = config?.credentials === 'include';
20
+ const options = {
21
+ headers,
22
+ withCredentials,
23
+ observe: 'response',
24
+ responseType: 'json',
25
+ };
26
+ let response;
27
+ switch (method.toUpperCase()) {
28
+ case 'GET':
29
+ response = await this.httpClient.get(url, options).toPromise();
30
+ break;
31
+ case 'POST':
32
+ response = await this.httpClient.post(url, body ? JSON.parse(body) : null, options).toPromise();
33
+ break;
34
+ case 'PUT':
35
+ response = await this.httpClient.put(url, body ? JSON.parse(body) : null, options).toPromise();
36
+ break;
37
+ case 'DELETE':
38
+ response = await this.httpClient.delete(url, options).toPromise();
39
+ break;
40
+ case 'PATCH':
41
+ response = await this.httpClient.patch(url, body ? JSON.parse(body) : null, options).toPromise();
42
+ break;
43
+ default:
44
+ throw new Error(`Unsupported HTTP method: ${method}`);
45
+ }
46
+ // Convert Angular HttpResponse headers to plain object
47
+ const responseHeaders = {};
48
+ if (response.headers) {
49
+ response.headers.keys().forEach((key) => {
50
+ responseHeaders[key] = response.headers.get(key);
51
+ });
52
+ }
53
+ return {
54
+ ok: response.status >= 200 && response.status < 300,
55
+ status: response.status,
56
+ statusText: response.statusText || 'OK',
57
+ headers: responseHeaders,
58
+ json: async () => response.body,
59
+ text: async () => (typeof response.body === 'string' ? response.body : JSON.stringify(response.body)),
60
+ };
61
+ }
62
+ catch (error) {
63
+ if (error.status !== undefined) {
64
+ // Angular HttpErrorResponse
65
+ const errorHeaders = {};
66
+ if (error.headers) {
67
+ error.headers.keys().forEach((key) => {
68
+ errorHeaders[key] = error.headers.get(key);
69
+ });
70
+ }
71
+ return {
72
+ ok: false,
73
+ status: error.status,
74
+ statusText: error.statusText || 'Error',
75
+ headers: errorHeaders,
76
+ json: async () => error.error,
77
+ text: async () => (typeof error.error === 'string' ? error.error : JSON.stringify(error.error)),
78
+ };
79
+ }
80
+ else {
81
+ // Other errors
82
+ throw error;
83
+ }
84
+ }
85
+ }
86
+ }
@@ -0,0 +1,10 @@
1
+ import { IHttpService, HttpRequestConfig, HttpResponse } from './index';
2
+ /**
3
+ * Axios-based HTTP service implementation
4
+ * Note: This requires axios to be installed as a dependency
5
+ */
6
+ export declare class AxiosHttpService implements IHttpService {
7
+ private readonly axios;
8
+ constructor(axiosInstance?: any);
9
+ request<T = any>(url: string, config?: HttpRequestConfig): Promise<HttpResponse<T>>;
10
+ }
@@ -0,0 +1,53 @@
1
+ // Ignore eslint any error in this file
2
+ /* eslint-disable @typescript-eslint/no-explicit-any */
3
+ /**
4
+ * Axios-based HTTP service implementation
5
+ * Note: This requires axios to be installed as a dependency
6
+ */
7
+ export class AxiosHttpService {
8
+ axios;
9
+ constructor(axiosInstance) {
10
+ if (!axiosInstance) {
11
+ throw new Error('Axios instance is required');
12
+ }
13
+ this.axios = axiosInstance;
14
+ }
15
+ async request(url, config) {
16
+ try {
17
+ const axiosConfig = {
18
+ url,
19
+ method: config?.method || 'GET',
20
+ headers: config?.headers,
21
+ data: config?.body,
22
+ withCredentials: config?.credentials === 'include',
23
+ };
24
+ const response = await this.axios(axiosConfig);
25
+ return {
26
+ ok: response.status >= 200 && response.status < 300,
27
+ status: response.status,
28
+ statusText: response.statusText,
29
+ headers: response.headers,
30
+ json: async () => response.data,
31
+ text: async () => (typeof response.data === 'string' ? response.data : JSON.stringify(response.data)),
32
+ };
33
+ }
34
+ catch (error) {
35
+ if (error.response) {
36
+ // The request was made and the server responded with a status code
37
+ // that falls out of the range of 2xx
38
+ return {
39
+ ok: false,
40
+ status: error.response.status,
41
+ statusText: error.response.statusText,
42
+ headers: error.response.headers,
43
+ json: async () => error.response.data,
44
+ text: async () => (typeof error.response.data === 'string' ? error.response.data : JSON.stringify(error.response.data)),
45
+ };
46
+ }
47
+ else {
48
+ // Something happened in setting up the request that triggered an Error
49
+ throw error;
50
+ }
51
+ }
52
+ }
53
+ }
@@ -0,0 +1,7 @@
1
+ import { HttpRequestConfig, HttpResponse, IHttpService } from '../../../services';
2
+ /**
3
+ * Default HTTP service implementation using the Fetch API
4
+ */
5
+ export declare class FetchHttpService implements IHttpService {
6
+ request<T = any>(url: string, config?: HttpRequestConfig): Promise<HttpResponse<T>>;
7
+ }
@@ -0,0 +1,28 @@
1
+ // Ignore eslint any error in this file
2
+ /* eslint-disable @typescript-eslint/no-explicit-any */
3
+ /**
4
+ * Default HTTP service implementation using the Fetch API
5
+ */
6
+ export class FetchHttpService {
7
+ async request(url, config) {
8
+ const response = await fetch(url, {
9
+ method: config?.method || 'GET',
10
+ headers: config?.headers,
11
+ body: config?.body,
12
+ credentials: config?.credentials || 'include',
13
+ });
14
+ // Convert Headers to a plain object
15
+ const headers = {};
16
+ response.headers.forEach((value, key) => {
17
+ headers[key] = value;
18
+ });
19
+ return {
20
+ ok: response.ok,
21
+ status: response.status,
22
+ statusText: response.statusText,
23
+ headers,
24
+ json: () => response.json(),
25
+ text: () => response.text(),
26
+ };
27
+ }
28
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * HTTP request configuration interface
3
+ */
4
+ export interface HttpRequestConfig {
5
+ method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
6
+ headers?: Record<string, string>;
7
+ body?: string;
8
+ credentials?: RequestCredentials;
9
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,11 @@
1
+ /**
2
+ * HTTP response interface
3
+ */
4
+ export interface HttpResponse<T = any> {
5
+ ok: boolean;
6
+ status: number;
7
+ statusText: string;
8
+ headers: Record<string, string>;
9
+ json(): Promise<T>;
10
+ text(): Promise<string>;
11
+ }
@@ -0,0 +1,3 @@
1
+ // Ignore eslint any error in this file
2
+ /* eslint-disable @typescript-eslint/no-explicit-any */
3
+ export {};
@@ -0,0 +1,13 @@
1
+ import { HttpRequestConfig, HttpResponse } from '../../../services';
2
+ /**
3
+ * Abstract HTTP service interface that can be implemented by different HTTP clients
4
+ */
5
+ export interface IHttpService {
6
+ /**
7
+ * Performs an HTTP request
8
+ * @param url - The URL to make the request to
9
+ * @param config - Request configuration
10
+ * @returns Promise that resolves to the HTTP response
11
+ */
12
+ request<T = any>(url: string, config?: HttpRequestConfig): Promise<HttpResponse<T>>;
13
+ }
@@ -0,0 +1,3 @@
1
+ // Ignore eslint any error in this file
2
+ /* eslint-disable @typescript-eslint/no-explicit-any */
3
+ export {};
@@ -0,0 +1,11 @@
1
+ import { FetchHttpService } from './FetchHttpService';
2
+ /**
3
+ * Default HTTP service instance
4
+ */
5
+ export declare const defaultHttpService: FetchHttpService;
6
+ export * from './AxiosHttpService';
7
+ export * from './AngularHttpService';
8
+ export * from './FetchHttpService';
9
+ export * from './HttpRequestConfig';
10
+ export * from './HttpResponse';
11
+ export * from './IHttpService';
@@ -0,0 +1,12 @@
1
+ import { FetchHttpService } from './FetchHttpService';
2
+ /**
3
+ * Default HTTP service instance
4
+ */
5
+ export const defaultHttpService = new FetchHttpService();
6
+ // Export additional HTTP service implementations
7
+ export * from './AxiosHttpService';
8
+ export * from './AngularHttpService';
9
+ export * from './FetchHttpService';
10
+ export * from './HttpRequestConfig';
11
+ export * from './HttpResponse';
12
+ export * from './IHttpService';
@@ -1,5 +1,6 @@
1
- import { ApiCrudControllerClient } from '../..';
2
- import { User } from '../../../data';
1
+ import { ApiCrudControllerClient } from '../ApiCrudControllerClient';
2
+ import { IHttpService } from '../HttpService';
3
+ import { UserDto } from '../../../data';
3
4
  /**
4
5
  * Client for user management operations
5
6
  *
@@ -8,7 +9,13 @@ import { User } from '../../../data';
8
9
  * @template TKey - Type of the entity key (e.g., number, string, GUID, etc.)
9
10
  * @template TUser - Data Transfer Object representing the user entity
10
11
  */
11
- export declare class UserManagementControllerClient<TKey, TUser extends User<TKey>> extends ApiCrudControllerClient<TKey, TUser> {
12
+ export declare class UserManagementControllerClient<TKey, TUser extends UserDto<TKey>> extends ApiCrudControllerClient<TKey, TUser> {
13
+ /**
14
+ * Constructor
15
+ * @param baseControllerPath Base path to API controller
16
+ * @param httpService HTTP service implementation to use for requests
17
+ */
18
+ constructor(baseControllerPath: string, httpService?: IHttpService);
12
19
  /**
13
20
  * Gets the roles assigned to a user
14
21
  * @param id - The ID of the user