@intellegens/cornerstone-client 0.0.26 → 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 (76) 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} +3 -3
  4. package/data/api/dto/{ReadSelectedFilteringPropertyDefinition.d.ts → ReadSelectedFilteringPropertyDefinitionDto.d.ts} +1 -1
  5. package/data/api/dto/ReadSelectedOrderingDefinitionDto.d.ts +7 -0
  6. package/data/api/dto/{ReadSelectedOrderingPropertyDefinition.d.ts → ReadSelectedOrderingPropertyDefinitionDto.d.ts} +1 -1
  7. package/data/api/dto/{ReadSelectedPaginationDefinition.d.ts → ReadSelectedPaginationDefinitionDto.d.ts} +1 -1
  8. package/data/api/dto/index.d.ts +6 -6
  9. package/data/api/dto/index.js +6 -6
  10. package/data/auth/{Claim/index.d.ts → dto/ClaimDto.d.ts} +1 -1
  11. package/data/auth/dto/RegisterRequestDto.d.ts +4 -0
  12. package/data/auth/dto/RoleDto.d.ts +5 -0
  13. package/data/auth/dto/SignInRequestDto.d.ts +4 -0
  14. package/data/auth/dto/TokensDto.d.ts +4 -0
  15. package/data/auth/dto/TokensDto.js +1 -0
  16. package/data/auth/{User/index.d.ts → dto/UserDto.d.ts} +4 -4
  17. package/data/auth/dto/UserDto.js +1 -0
  18. package/data/auth/{UserInfo/index.d.ts → dto/UserInfoDto.d.ts} +3 -3
  19. package/data/auth/dto/UserInfoDto.js +1 -0
  20. package/data/auth/dto/index.d.ts +4 -0
  21. package/data/auth/dto/index.js +4 -0
  22. package/data/auth/index.d.ts +1 -4
  23. package/data/auth/index.js +1 -4
  24. package/data/index.d.ts +0 -1
  25. package/data/index.js +0 -1
  26. package/package.json +13 -7
  27. package/services/api/ApiCrudControllerClient/index.d.ts +9 -2
  28. package/services/api/ApiCrudControllerClient/index.js +15 -5
  29. package/services/api/ApiInitializationService/index.d.ts +11 -1
  30. package/services/api/ApiInitializationService/index.js +19 -4
  31. package/services/api/ApiReadControllerClient/index.d.ts +10 -3
  32. package/services/api/ApiReadControllerClient/index.js +18 -5
  33. package/services/api/HttpService/AngularHttpService.d.ts +9 -0
  34. package/services/api/HttpService/AngularHttpService.js +86 -0
  35. package/services/api/HttpService/AxiosHttpService.d.ts +10 -0
  36. package/services/api/HttpService/AxiosHttpService.js +53 -0
  37. package/services/api/HttpService/FetchHttpService.d.ts +7 -0
  38. package/services/api/HttpService/FetchHttpService.js +28 -0
  39. package/services/api/HttpService/HttpRequestConfig.d.ts +9 -0
  40. package/services/api/HttpService/HttpRequestConfig.js +1 -0
  41. package/services/api/HttpService/HttpResponse.d.ts +11 -0
  42. package/services/api/HttpService/HttpResponse.js +3 -0
  43. package/services/api/HttpService/IHttpService.d.ts +13 -0
  44. package/services/api/HttpService/IHttpService.js +3 -0
  45. package/services/api/HttpService/index.d.ts +11 -0
  46. package/services/api/HttpService/index.js +12 -0
  47. package/services/api/UserManagementControllerClient/index.d.ts +10 -3
  48. package/services/api/UserManagementControllerClient/index.js +18 -5
  49. package/services/api/index.d.ts +1 -0
  50. package/services/api/index.js +1 -0
  51. package/services/auth/client/AuthService/index.d.ts +3 -3
  52. package/services/auth/client/AuthorizationManagementControllerClient/index.d.ts +4 -4
  53. package/services/auth/client/AuthorizationManagementControllerClient/index.js +1 -1
  54. package/data/_generated/Cornerstone/Auth/API/DTOs/RegisterRequestDto.d.ts +0 -12
  55. package/data/_generated/Cornerstone/Auth/API/DTOs/RegisterRequestDto.js +0 -2
  56. package/data/_generated/Cornerstone/Auth/API/DTOs/SignInRequestDto.d.ts +0 -12
  57. package/data/_generated/Cornerstone/Auth/API/DTOs/SignInRequestDto.js +0 -2
  58. package/data/_generated/Cornerstone/Auth/API/DTOs/TokensDto.d.ts +0 -12
  59. package/data/_generated/Cornerstone/Auth/API/DTOs/TokensDto.js +0 -2
  60. package/data/_generated/cache.d.ts +0 -3
  61. package/data/_generated/cache.js +0 -2
  62. package/data/_generated/index.d.ts +0 -3
  63. package/data/_generated/index.js +0 -3
  64. package/data/api/dto/ReadSelectedDefinition.d.ts +0 -18
  65. package/data/api/dto/ReadSelectedOrderingDefinition.d.ts +0 -7
  66. package/data/auth/Role/index.d.ts +0 -5
  67. /package/data/api/dto/{ReadSelectedDefinition.js → ReadSelectedDefinitionDto.js} +0 -0
  68. /package/data/api/dto/{ReadSelectedFilteringDefinition.js → ReadSelectedFilteringDefinitionDto.js} +0 -0
  69. /package/data/api/dto/{ReadSelectedFilteringPropertyDefinition.js → ReadSelectedFilteringPropertyDefinitionDto.js} +0 -0
  70. /package/data/api/dto/{ReadSelectedOrderingDefinition.js → ReadSelectedOrderingDefinitionDto.js} +0 -0
  71. /package/data/api/dto/{ReadSelectedOrderingPropertyDefinition.js → ReadSelectedOrderingPropertyDefinitionDto.js} +0 -0
  72. /package/data/api/dto/{ReadSelectedPaginationDefinition.js → ReadSelectedPaginationDefinitionDto.js} +0 -0
  73. /package/data/auth/{Claim/index.js → dto/ClaimDto.js} +0 -0
  74. /package/data/auth/{Role/index.js → dto/RegisterRequestDto.js} +0 -0
  75. /package/data/auth/{User/index.js → dto/RoleDto.js} +0 -0
  76. /package/data/auth/{UserInfo/index.js → dto/SignInRequestDto.js} +0 -0
package/README.md CHANGED
@@ -28,9 +28,9 @@ http://localhost:3000
28
28
 
29
29
  ## API reference
30
30
 
31
- ### API Service
31
+ ### API Initialization service
32
32
 
33
- This service provides way to load API configuration for a Cornerstone client application.
33
+ This service provides way to load API configuration for a Cornerstone client application:
34
34
 
35
35
  ```ts
36
36
  import { ApiInitializationService } from '@intellegens/cornerstone-client';
@@ -45,18 +45,58 @@ import { apiInitializationService } from '@intellegens/cornerstone-client';
45
45
  await apiInitializationService.initialize();
46
46
  ```
47
47
 
48
+ It also provides a way of customizing global defaults for Cornerstone client application:
49
+
50
+ - `httpService` Configures a default HTTP Service to be used across the application, unless specified otherwise (See [HTTP Service Abstraction](#http-service-abstraction))
51
+
52
+ ```ts
53
+ import { apiInitializationService, FetchHttpService } from '@intellegens/cornerstone-client';
54
+ await apiInitializationService.initialize({
55
+ httpService: new FetchHttpService(),
56
+ });
57
+ ```
58
+
48
59
  #### API base URL detection
49
60
 
50
- Detected by checking the `CORNERSTONE-API-BASEURL` response header and the `websettings.json` file.
61
+ Base API URL is detected by checking the `CORNERSTONE-API-BASEURL` response header and the `./websettings.json` file.
51
62
 
52
- - First, it checks the response headers of the current URL for the `CORNERSTONE-API-BASEURL` header.
53
- - If the header is not found, it attempts to load the `websettings.json` file and looks for an `api` field.
54
- - If no API base URL is found, it defaults to `undefined`.
63
+ - First, Cornerstone client checks the response headers of the current URL for the `CORNERSTONE-API-BASEURL` header.
64
+ - If the header is not found, Cornerstone client attempts to load the `websettings.json` file and looks for an `api` field.
65
+ - If no API base URL is found, Cornerstone client defaults to `undefined`.
66
+
67
+ Before, or after the base API URL has been detected, you can get any API endpoint URL by calling:
55
68
 
56
69
  ```ts
57
70
  const fetchUrl = `${await apiInitializationService.getApiUrl('/my/endpoint')}`;
58
71
  ```
59
72
 
73
+ ### HTTP Service Abstraction
74
+
75
+ The Cornerstone client provides a flexible HTTP service abstraction that allows you to use different HTTP libraries (Fetch API, Axios, Angular HttpClient) with the same API clients. This abstraction provides consistent behavior across different HTTP implementations while maintaining framework independence.
76
+
77
+ #### Key Features
78
+
79
+ - **Pluggable HTTP implementations** - Switch between Fetch, Axios, and Angular HttpClient
80
+ - **Consistent interface** - All HTTP services implement the same `IHttpService` interface
81
+ - **Framework agnostic** - Use the same API clients in React, Angular, Vue, or any other framework
82
+ - **Easy testing** - Mock HTTP requests easily for unit testing
83
+ - **Runtime switching** - Change HTTP service implementations at runtime
84
+
85
+ #### Quick Example
86
+
87
+ ```ts
88
+ import { ApiReadControllerClient, FetchHttpService, AxiosHttpService } from '@intellegens/cornerstone-client';
89
+
90
+ // Using default Fetch implementation
91
+ const client = new ApiReadControllerClient('/api/users');
92
+
93
+ // Or specify a custom HTTP service
94
+ const axiosService = new AxiosHttpService(axiosInstance);
95
+ const clientWithAxios = new ApiReadControllerClient('/api/users', axiosService);
96
+ ```
97
+
98
+ For detailed documentation, examples, and advanced usage, see: [HTTP Service Documentation](./src/services/api/HttpService/README.md)
99
+
60
100
  ### Auth Service
61
101
 
62
102
  This service provides authentication methods for managing user sessions in a Cornerstone client application.
@@ -73,23 +113,23 @@ const user = authService.user;
73
113
  ##### Who Am I
74
114
 
75
115
  ```ts
76
- authService.whoAmI(): Promise<User | undefined>
116
+ authService.whoAmI(): Promise<UserDto | undefined>
77
117
  ```
78
118
 
79
- This method checks the current session and returns the User object for the logged-in user. If no user is logged in, it returns undefined.
119
+ This method checks the current session and returns the UserDto object for the logged-in user. If no user is logged in, it returns undefined.
80
120
 
81
121
  ##### Sign in
82
122
 
83
123
  ```ts
84
- authService.signin(username: string, password: string): Promise<User | undefined>
124
+ authService.signin(username: string, password: string): Promise<UserDto | undefined>
85
125
  ```
86
126
 
87
- This method logs the user in by sending the provided username and password to the API. If the login is successful, it returns the authenticated User object.
127
+ This method logs the user in by sending the provided username and password to the API. If the login is successful, it returns the authenticated UserDto object.
88
128
 
89
129
  ##### Sign out
90
130
 
91
131
  ```ts
92
- authService.logout(): Promise<User | undefined>
132
+ authService.logout(): Promise<UserDto | undefined>
93
133
  ```
94
134
 
95
135
  This method logs the user out by sending a request to the API to end the session. It returns undefined if the logout is successful
@@ -0,0 +1,18 @@
1
+ import { ReadSelectedPaginationDefinitionDto, ReadSelectedOrderingDefinitionDto, ReadSelectedFilteringDefinitionDto } from '../..';
2
+ /**
3
+ * Defines the selection criteria for a controller to fetch multiple records
4
+ */
5
+ export type ReadSelectedDefinitionDto = {
6
+ /**
7
+ * Pagination definition
8
+ */
9
+ paginationDefinition?: ReadSelectedPaginationDefinitionDto;
10
+ /**
11
+ * Ordering definition
12
+ */
13
+ orderingDefinition?: ReadSelectedOrderingDefinitionDto;
14
+ /**
15
+ * Filtering definition
16
+ */
17
+ filteringDefinition?: ReadSelectedFilteringDefinitionDto;
18
+ };
@@ -1,12 +1,12 @@
1
- import { ReadSelectedFilteringPropertyDefinition, ReadSelectedLogicalOperator } from '../..';
1
+ import { ReadSelectedFilteringPropertyDefinitionDto, ReadSelectedLogicalOperator } from '../..';
2
2
  /**
3
3
  * Defines the filtering options for a controller, including the logical operator and an array of property definitions.
4
4
  */
5
- export type ReadSelectedFilteringDefinition = {
5
+ export type ReadSelectedFilteringDefinitionDto = {
6
6
  /**
7
7
  * Array of filtering property definitions to be applied.
8
8
  */
9
- filters: ReadSelectedFilteringPropertyDefinition[];
9
+ filters: ReadSelectedFilteringPropertyDefinitionDto[];
10
10
  /**
11
11
  * Logical operator to be used when applying the filters.
12
12
  */
@@ -2,7 +2,7 @@ import { ReadSelectedComparisonOperator, ReadSelectedPropertyType } from '../..'
2
2
  /**
3
3
  * Defines a property used for filtering in a controller.
4
4
  */
5
- export type ReadSelectedFilteringPropertyDefinition = Partial_ReadSelectedFilteringPropertyDefinition_IndependentProperties & Partial_ReadSelectedFilteringPropertyDefinition_TypedValueProperty & Partial_ReadSelectedFilteringPropertyDefinition_TypedComparisonOperators;
5
+ export type ReadSelectedFilteringPropertyDefinitionDto = Partial_ReadSelectedFilteringPropertyDefinition_IndependentProperties & Partial_ReadSelectedFilteringPropertyDefinition_TypedValueProperty & Partial_ReadSelectedFilteringPropertyDefinition_TypedComparisonOperators;
6
6
  /**
7
7
  * Defines independent properties
8
8
  */
@@ -0,0 +1,7 @@
1
+ import { ReadSelectedOrderingPropertyDefinitionDto } from '../..';
2
+ /**
3
+ * Represents the ordering definition for a controller.
4
+ */
5
+ export type ReadSelectedOrderingDefinitionDto = {
6
+ order: ReadSelectedOrderingPropertyDefinitionDto[];
7
+ };
@@ -2,7 +2,7 @@ import { ReadSelectedOrderingDirection } from '../..';
2
2
  /**
3
3
  * Defines the ordering property for a controller.
4
4
  */
5
- export type ReadSelectedOrderingPropertyDefinition = {
5
+ export type ReadSelectedOrderingPropertyDefinitionDto = {
6
6
  /**
7
7
  * Gets or sets the property path.
8
8
  */
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Defines the pagination parameters for a controller.
3
3
  */
4
- export type ReadSelectedPaginationDefinition = {
4
+ export type ReadSelectedPaginationDefinitionDto = {
5
5
  /**
6
6
  * Pagination offset
7
7
  */
@@ -1,6 +1,6 @@
1
- export * from './ReadSelectedDefinition';
2
- export * from './ReadSelectedFilteringDefinition';
3
- export * from './ReadSelectedFilteringPropertyDefinition';
4
- export * from './ReadSelectedOrderingDefinition';
5
- export * from './ReadSelectedOrderingPropertyDefinition';
6
- export * from './ReadSelectedPaginationDefinition';
1
+ export * from './ReadSelectedDefinitionDto';
2
+ export * from './ReadSelectedFilteringDefinitionDto';
3
+ export * from './ReadSelectedFilteringPropertyDefinitionDto';
4
+ export * from './ReadSelectedOrderingDefinitionDto';
5
+ export * from './ReadSelectedOrderingPropertyDefinitionDto';
6
+ export * from './ReadSelectedPaginationDefinitionDto';
@@ -1,6 +1,6 @@
1
- export * from './ReadSelectedDefinition';
2
- export * from './ReadSelectedFilteringDefinition';
3
- export * from './ReadSelectedFilteringPropertyDefinition';
4
- export * from './ReadSelectedOrderingDefinition';
5
- export * from './ReadSelectedOrderingPropertyDefinition';
6
- export * from './ReadSelectedPaginationDefinition';
1
+ export * from './ReadSelectedDefinitionDto';
2
+ export * from './ReadSelectedFilteringDefinitionDto';
3
+ export * from './ReadSelectedFilteringPropertyDefinitionDto';
4
+ export * from './ReadSelectedOrderingDefinitionDto';
5
+ export * from './ReadSelectedOrderingPropertyDefinitionDto';
6
+ export * from './ReadSelectedPaginationDefinitionDto';
@@ -1,4 +1,4 @@
1
- export type Claim = {
1
+ export type ClaimDto = {
2
2
  type: string;
3
3
  value: string;
4
4
  };
@@ -0,0 +1,4 @@
1
+ export type RegisterRequestDto = {
2
+ username: string;
3
+ password: string;
4
+ };
@@ -0,0 +1,5 @@
1
+ import { ClaimDto } from '../..';
2
+ export type RoleDto = {
3
+ name: string;
4
+ claims: ClaimDto[];
5
+ };
@@ -0,0 +1,4 @@
1
+ export type SignInRequestDto = {
2
+ username: string;
3
+ password: string;
4
+ };
@@ -0,0 +1,4 @@
1
+ export type TokensDto = {
2
+ accessToken?: string;
3
+ refreshToken?: string;
4
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -1,4 +1,4 @@
1
- import { Claim } from '../..';
1
+ import { ClaimDto } from '../..';
2
2
  import { IIdentifiable } from '../..';
3
3
  /**
4
4
  * Represents a user with an identifier and email address.
@@ -8,10 +8,10 @@ import { IIdentifiable } from '../..';
8
8
  * @param {TKey} id The unique identifier for the user.
9
9
  * @param {string} email The email address associated with the user.
10
10
  * @param {string[]} roles The roles associated with the user.
11
- * @param {Claim[]} claims The claims associated with the user.
11
+ * @param {ClaimDto[]} claims The claims associated with the user.
12
12
  */
13
- export type User<TKey> = IIdentifiable<TKey> & {
13
+ export type UserDto<TKey> = IIdentifiable<TKey> & {
14
14
  email: string;
15
15
  roles: string[];
16
- claims: Claim[];
16
+ claims: ClaimDto[];
17
17
  };
@@ -0,0 +1 @@
1
+ export {};
@@ -1,14 +1,14 @@
1
- import { User } from '../..';
1
+ import { UserDto } from '../..';
2
2
  /**
3
3
  * Represents user information along with access token expiry.
4
4
  *
5
5
  * @template TKey The type of the user identifier.
6
- * @template TUser The type of the user object, defaulting to `User<TKey>`.
6
+ * @template TUser The type of the user object, defaulting to `UserDto<TKey>`.
7
7
  *
8
8
  * @param {TUser} user The user object containing user details.
9
9
  * @param {Date} accessTokenExpiry The date and time when the access token will expire.
10
10
  */
11
- export type UserInfo<TKey, TUser = User<TKey>> = {
11
+ export type UserInfoDto<TKey, TUser = UserDto<TKey>> = {
12
12
  user: TUser;
13
13
  accessTokenExpiry: Date;
14
14
  };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ export * from './ClaimDto';
2
+ export * from './UserDto';
3
+ export * from './UserInfoDto';
4
+ export * from './RoleDto';
@@ -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.26",
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
+ }