@intellegens/cornerstone-client 0.0.26 → 0.0.28
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/README.md +51 -11
- package/data/api/dto/ReadSelectedDefinitionDto.d.ts +18 -0
- package/data/api/dto/{ReadSelectedFilteringDefinition.d.ts → ReadSelectedFilteringDefinitionDto.d.ts} +3 -3
- package/data/api/dto/{ReadSelectedFilteringPropertyDefinition.d.ts → ReadSelectedFilteringPropertyDefinitionDto.d.ts} +1 -1
- package/data/api/dto/ReadSelectedOrderingDefinitionDto.d.ts +7 -0
- package/data/api/dto/{ReadSelectedOrderingPropertyDefinition.d.ts → ReadSelectedOrderingPropertyDefinitionDto.d.ts} +1 -1
- package/data/api/dto/{ReadSelectedPaginationDefinition.d.ts → ReadSelectedPaginationDefinitionDto.d.ts} +1 -1
- package/data/api/dto/index.d.ts +6 -6
- package/data/api/dto/index.js +6 -6
- package/data/auth/{Claim/index.d.ts → dto/ClaimDto.d.ts} +1 -1
- package/data/auth/dto/RegisterRequestDto.d.ts +4 -0
- package/data/auth/dto/RoleDto.d.ts +5 -0
- package/data/auth/dto/SignInRequestDto.d.ts +4 -0
- package/data/auth/dto/TokensDto.d.ts +4 -0
- package/data/auth/dto/TokensDto.js +1 -0
- package/data/auth/{User/index.d.ts → dto/UserDto.d.ts} +4 -4
- package/data/auth/dto/UserDto.js +1 -0
- package/data/auth/{UserInfo/index.d.ts → dto/UserInfoDto.d.ts} +3 -3
- package/data/auth/dto/UserInfoDto.js +1 -0
- package/data/auth/dto/index.d.ts +4 -0
- package/data/auth/dto/index.js +4 -0
- package/data/auth/index.d.ts +1 -4
- package/data/auth/index.js +1 -4
- package/data/index.d.ts +0 -1
- package/data/index.js +0 -1
- package/package.json +13 -7
- package/services/api/ApiCrudControllerClient/index.d.ts +9 -2
- package/services/api/ApiCrudControllerClient/index.js +15 -5
- package/services/api/ApiInitializationService/index.d.ts +11 -1
- package/services/api/ApiInitializationService/index.js +19 -4
- package/services/api/ApiReadControllerClient/index.d.ts +10 -3
- package/services/api/ApiReadControllerClient/index.js +18 -5
- package/services/api/HttpService/AngularHttpService.d.ts +9 -0
- package/services/api/HttpService/AngularHttpService.js +86 -0
- package/services/api/HttpService/AxiosHttpService.d.ts +10 -0
- package/services/api/HttpService/AxiosHttpService.js +53 -0
- package/services/api/HttpService/FetchHttpService.d.ts +7 -0
- package/services/api/HttpService/FetchHttpService.js +28 -0
- package/services/api/HttpService/HttpRequestConfig.d.ts +9 -0
- package/services/api/HttpService/HttpRequestConfig.js +1 -0
- package/services/api/HttpService/HttpResponse.d.ts +11 -0
- package/services/api/HttpService/HttpResponse.js +3 -0
- package/services/api/HttpService/IHttpService.d.ts +13 -0
- package/services/api/HttpService/IHttpService.js +3 -0
- package/services/api/HttpService/index.d.ts +11 -0
- package/services/api/HttpService/index.js +12 -0
- package/services/api/UserManagementControllerClient/index.d.ts +10 -3
- package/services/api/UserManagementControllerClient/index.js +18 -5
- package/services/api/index.d.ts +1 -0
- package/services/api/index.js +1 -0
- package/services/auth/client/AuthService/index.d.ts +3 -3
- package/services/auth/client/AuthorizationManagementControllerClient/index.d.ts +4 -4
- package/services/auth/client/AuthorizationManagementControllerClient/index.js +1 -1
- package/data/_generated/Cornerstone/Auth/API/DTOs/RegisterRequestDto.d.ts +0 -12
- package/data/_generated/Cornerstone/Auth/API/DTOs/RegisterRequestDto.js +0 -2
- package/data/_generated/Cornerstone/Auth/API/DTOs/SignInRequestDto.d.ts +0 -12
- package/data/_generated/Cornerstone/Auth/API/DTOs/SignInRequestDto.js +0 -2
- package/data/_generated/Cornerstone/Auth/API/DTOs/TokensDto.d.ts +0 -12
- package/data/_generated/Cornerstone/Auth/API/DTOs/TokensDto.js +0 -2
- package/data/_generated/cache.d.ts +0 -3
- package/data/_generated/cache.js +0 -2
- package/data/_generated/index.d.ts +0 -3
- package/data/_generated/index.js +0 -3
- package/data/api/dto/ReadSelectedDefinition.d.ts +0 -18
- package/data/api/dto/ReadSelectedOrderingDefinition.d.ts +0 -7
- package/data/auth/Role/index.d.ts +0 -5
- /package/data/api/dto/{ReadSelectedDefinition.js → ReadSelectedDefinitionDto.js} +0 -0
- /package/data/api/dto/{ReadSelectedFilteringDefinition.js → ReadSelectedFilteringDefinitionDto.js} +0 -0
- /package/data/api/dto/{ReadSelectedFilteringPropertyDefinition.js → ReadSelectedFilteringPropertyDefinitionDto.js} +0 -0
- /package/data/api/dto/{ReadSelectedOrderingDefinition.js → ReadSelectedOrderingDefinitionDto.js} +0 -0
- /package/data/api/dto/{ReadSelectedOrderingPropertyDefinition.js → ReadSelectedOrderingPropertyDefinitionDto.js} +0 -0
- /package/data/api/dto/{ReadSelectedPaginationDefinition.js → ReadSelectedPaginationDefinitionDto.js} +0 -0
- /package/data/auth/{Claim/index.js → dto/ClaimDto.js} +0 -0
- /package/data/auth/{Role/index.js → dto/RegisterRequestDto.js} +0 -0
- /package/data/auth/{User/index.js → dto/RoleDto.js} +0 -0
- /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
|
|
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
|
-
|
|
61
|
+
Base API URL is detected by checking the `CORNERSTONE-API-BASEURL` response header and the `./websettings.json` file.
|
|
51
62
|
|
|
52
|
-
- First,
|
|
53
|
-
- If the header is not found,
|
|
54
|
-
- If no API base URL is found,
|
|
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<
|
|
116
|
+
authService.whoAmI(): Promise<UserDto | undefined>
|
|
77
117
|
```
|
|
78
118
|
|
|
79
|
-
This method checks the current session and returns the
|
|
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<
|
|
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
|
|
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<
|
|
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 {
|
|
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
|
|
5
|
+
export type ReadSelectedFilteringDefinitionDto = {
|
|
6
6
|
/**
|
|
7
7
|
* Array of filtering property definitions to be applied.
|
|
8
8
|
*/
|
|
9
|
-
filters:
|
|
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
|
|
5
|
+
export type ReadSelectedFilteringPropertyDefinitionDto = Partial_ReadSelectedFilteringPropertyDefinition_IndependentProperties & Partial_ReadSelectedFilteringPropertyDefinition_TypedValueProperty & Partial_ReadSelectedFilteringPropertyDefinition_TypedComparisonOperators;
|
|
6
6
|
/**
|
|
7
7
|
* Defines independent properties
|
|
8
8
|
*/
|
|
@@ -2,7 +2,7 @@ import { ReadSelectedOrderingDirection } from '../..';
|
|
|
2
2
|
/**
|
|
3
3
|
* Defines the ordering property for a controller.
|
|
4
4
|
*/
|
|
5
|
-
export type
|
|
5
|
+
export type ReadSelectedOrderingPropertyDefinitionDto = {
|
|
6
6
|
/**
|
|
7
7
|
* Gets or sets the property path.
|
|
8
8
|
*/
|
package/data/api/dto/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './
|
|
5
|
-
export * from './
|
|
6
|
-
export * from './
|
|
1
|
+
export * from './ReadSelectedDefinitionDto';
|
|
2
|
+
export * from './ReadSelectedFilteringDefinitionDto';
|
|
3
|
+
export * from './ReadSelectedFilteringPropertyDefinitionDto';
|
|
4
|
+
export * from './ReadSelectedOrderingDefinitionDto';
|
|
5
|
+
export * from './ReadSelectedOrderingPropertyDefinitionDto';
|
|
6
|
+
export * from './ReadSelectedPaginationDefinitionDto';
|
package/data/api/dto/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './
|
|
5
|
-
export * from './
|
|
6
|
-
export * from './
|
|
1
|
+
export * from './ReadSelectedDefinitionDto';
|
|
2
|
+
export * from './ReadSelectedFilteringDefinitionDto';
|
|
3
|
+
export * from './ReadSelectedFilteringPropertyDefinitionDto';
|
|
4
|
+
export * from './ReadSelectedOrderingDefinitionDto';
|
|
5
|
+
export * from './ReadSelectedOrderingPropertyDefinitionDto';
|
|
6
|
+
export * from './ReadSelectedPaginationDefinitionDto';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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 {
|
|
11
|
+
* @param {ClaimDto[]} claims The claims associated with the user.
|
|
12
12
|
*/
|
|
13
|
-
export type
|
|
13
|
+
export type UserDto<TKey> = IIdentifiable<TKey> & {
|
|
14
14
|
email: string;
|
|
15
15
|
roles: string[];
|
|
16
|
-
claims:
|
|
16
|
+
claims: ClaimDto[];
|
|
17
17
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
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 `
|
|
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
|
|
11
|
+
export type UserInfoDto<TKey, TUser = UserDto<TKey>> = {
|
|
12
12
|
user: TUser;
|
|
13
13
|
accessTokenExpiry: Date;
|
|
14
14
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/data/auth/index.d.ts
CHANGED
package/data/auth/index.js
CHANGED
package/data/index.d.ts
CHANGED
package/data/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intellegens/cornerstone-client",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.28",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"clean": "node -e \"require('fs-extra').emptyDir('./dist');\"",
|
|
8
|
-
"test": "
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"
|
|
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": "
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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(
|
|
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
|
|
73
|
-
const apiHeader = currentUrlResponse.headers
|
|
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
|
|
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,
|
|
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:
|
|
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
|
|
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
|
|
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
|
|
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
|
+
}
|