@intellegens/cornerstone-client 0.0.0-experimental-upgrade-20260302-1

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 (251) hide show
  1. package/README.md +256 -0
  2. package/demo/index.ts +29 -0
  3. package/demo/public_html/favicon.ico +0 -0
  4. package/demo/public_html/index.html +106 -0
  5. package/demo/public_html/websettings.json +3 -0
  6. package/dist/adapters/CollectionViewAdapter/index.d.ts +198 -0
  7. package/dist/adapters/CollectionViewAdapter/index.integration.test.d.ts +1 -0
  8. package/dist/adapters/CollectionViewAdapter/index.integration.test.js +163 -0
  9. package/dist/adapters/CollectionViewAdapter/index.js +381 -0
  10. package/dist/adapters/SearchAdapter/index.d.ts +55 -0
  11. package/dist/adapters/SearchAdapter/index.js +233 -0
  12. package/dist/adapters/index.d.ts +2 -0
  13. package/dist/adapters/index.js +2 -0
  14. package/dist/data/api/dto/PropertyPathDto.d.ts +4 -0
  15. package/dist/data/api/dto/PropertyPathDto.js +1 -0
  16. package/dist/data/api/dto/ReadOptionsDto.d.ts +8 -0
  17. package/dist/data/api/dto/ReadOptionsDto.js +1 -0
  18. package/dist/data/api/dto/ReadResultDto.d.ts +12 -0
  19. package/dist/data/api/dto/ReadResultDto.js +1 -0
  20. package/dist/data/api/dto/ReadResultMetadataDto.d.ts +8 -0
  21. package/dist/data/api/dto/ReadResultMetadataDto.js +1 -0
  22. package/dist/data/api/dto/crud/CrudMetadataDto.d.ts +4 -0
  23. package/dist/data/api/dto/crud/CrudMetadataDto.js +1 -0
  24. package/dist/data/api/dto/crud/index.d.ts +1 -0
  25. package/dist/data/api/dto/crud/index.js +1 -0
  26. package/dist/data/api/dto/index.d.ts +4 -0
  27. package/dist/data/api/dto/index.js +4 -0
  28. package/dist/data/api/dto/read/ReadMetadataDto.d.ts +8 -0
  29. package/dist/data/api/dto/read/ReadMetadataDto.js +1 -0
  30. package/dist/data/api/dto/read/ReadSelectedDefinitionDto.d.ts +18 -0
  31. package/dist/data/api/dto/read/ReadSelectedDefinitionDto.js +1 -0
  32. package/dist/data/api/dto/read/ReadSelectedNestedCollectionCriteriaDto.d.ts +22 -0
  33. package/dist/data/api/dto/read/ReadSelectedNestedCollectionCriteriaDto.js +1 -0
  34. package/dist/data/api/dto/read/ReadSelectedNestedCriteriaDto.d.ts +18 -0
  35. package/dist/data/api/dto/read/ReadSelectedNestedCriteriaDto.js +1 -0
  36. package/dist/data/api/dto/read/ReadSelectedOrderingDefinitionDto.d.ts +7 -0
  37. package/dist/data/api/dto/read/ReadSelectedOrderingDefinitionDto.js +1 -0
  38. package/dist/data/api/dto/read/ReadSelectedOrderingPropertyDefinitionDto.d.ts +14 -0
  39. package/dist/data/api/dto/read/ReadSelectedOrderingPropertyDefinitionDto.js +1 -0
  40. package/dist/data/api/dto/read/ReadSelectedPaginationDefinitionDto.d.ts +13 -0
  41. package/dist/data/api/dto/read/ReadSelectedPaginationDefinitionDto.js +1 -0
  42. package/dist/data/api/dto/read/ReadSelectedSearchDefinitionBuilder.d.ts +167 -0
  43. package/dist/data/api/dto/read/ReadSelectedSearchDefinitionBuilder.js +267 -0
  44. package/dist/data/api/dto/read/ReadSelectedSearchDefinitionDto.d.ts +33 -0
  45. package/dist/data/api/dto/read/ReadSelectedSearchDefinitionDto.js +1 -0
  46. package/dist/data/api/dto/read/ReadSelectedSearchPropertyDefinitionDto.d.ts +114 -0
  47. package/dist/data/api/dto/read/ReadSelectedSearchPropertyDefinitionDto.js +1 -0
  48. package/dist/data/api/dto/read/index.d.ts +10 -0
  49. package/dist/data/api/dto/read/index.js +10 -0
  50. package/dist/data/api/dto/response/ApiErrorDto.d.ts +17 -0
  51. package/dist/data/api/dto/response/ApiErrorDto.js +1 -0
  52. package/dist/data/api/dto/response/ApiErrorResponseDto.d.ts +11 -0
  53. package/dist/data/api/dto/response/ApiErrorResponseDto.js +1 -0
  54. package/dist/data/api/dto/response/ApiResponseDto.d.ts +3 -0
  55. package/dist/data/api/dto/response/ApiResponseDto.js +1 -0
  56. package/dist/data/api/dto/response/ApiSuccessResponseDto.d.ts +13 -0
  57. package/dist/data/api/dto/response/ApiSuccessResponseDto.js +1 -0
  58. package/dist/data/api/dto/response/EmptyMetadataDto.d.ts +4 -0
  59. package/dist/data/api/dto/response/EmptyMetadataDto.js +1 -0
  60. package/dist/data/api/dto/response/MetadataDto.d.ts +25 -0
  61. package/dist/data/api/dto/response/MetadataDto.js +1 -0
  62. package/dist/data/api/dto/response/index.d.ts +5 -0
  63. package/dist/data/api/dto/response/index.js +5 -0
  64. package/dist/data/api/enum/index.d.ts +2 -0
  65. package/dist/data/api/enum/index.js +2 -0
  66. package/dist/data/api/enum/read/ReadSelectedCollectionOperator.d.ts +16 -0
  67. package/dist/data/api/enum/read/ReadSelectedCollectionOperator.js +17 -0
  68. package/dist/data/api/enum/read/ReadSelectedComparisonOperator.d.ts +69 -0
  69. package/dist/data/api/enum/read/ReadSelectedComparisonOperator.js +76 -0
  70. package/dist/data/api/enum/read/ReadSelectedLogicalOperator.d.ts +15 -0
  71. package/dist/data/api/enum/read/ReadSelectedLogicalOperator.js +16 -0
  72. package/dist/data/api/enum/read/ReadSelectedOrderingDirection.d.ts +13 -0
  73. package/dist/data/api/enum/read/ReadSelectedOrderingDirection.js +14 -0
  74. package/dist/data/api/enum/read/ReadSelectedPropertyType.d.ts +66 -0
  75. package/dist/data/api/enum/read/ReadSelectedPropertyType.js +75 -0
  76. package/dist/data/api/enum/read/index.d.ts +5 -0
  77. package/dist/data/api/enum/read/index.js +5 -0
  78. package/dist/data/api/enum/response/ApiErrorCodes.d.ts +7 -0
  79. package/dist/data/api/enum/response/ApiErrorCodes.js +8 -0
  80. package/dist/data/api/enum/response/ErrorCode.d.ts +13 -0
  81. package/dist/data/api/enum/response/ErrorCode.js +14 -0
  82. package/dist/data/api/enum/response/index.d.ts +1 -0
  83. package/dist/data/api/enum/response/index.js +1 -0
  84. package/dist/data/api/index.d.ts +3 -0
  85. package/dist/data/api/index.js +3 -0
  86. package/dist/data/api/interface/ICommonIdentifiable.d.ts +7 -0
  87. package/dist/data/api/interface/ICommonIdentifiable.js +1 -0
  88. package/dist/data/api/interface/IConcurrencySafe.d.ts +9 -0
  89. package/dist/data/api/interface/IConcurrencySafe.js +2 -0
  90. package/dist/data/api/interface/IIdentifiable.d.ts +11 -0
  91. package/dist/data/api/interface/IIdentifiable.js +1 -0
  92. package/dist/data/api/interface/IIdentifiableSecondary.d.ts +9 -0
  93. package/dist/data/api/interface/IIdentifiableSecondary.js +1 -0
  94. package/dist/data/api/interface/index.d.ts +3 -0
  95. package/dist/data/api/interface/index.js +3 -0
  96. package/dist/data/auth/dto/ClaimDto.d.ts +4 -0
  97. package/dist/data/auth/dto/ClaimDto.js +1 -0
  98. package/dist/data/auth/dto/RegisterRequestDto.d.ts +4 -0
  99. package/dist/data/auth/dto/RegisterRequestDto.js +1 -0
  100. package/dist/data/auth/dto/RoleDto.d.ts +5 -0
  101. package/dist/data/auth/dto/RoleDto.js +1 -0
  102. package/dist/data/auth/dto/SignInRequestDto.d.ts +4 -0
  103. package/dist/data/auth/dto/SignInRequestDto.js +1 -0
  104. package/dist/data/auth/dto/TokensDto.d.ts +4 -0
  105. package/dist/data/auth/dto/TokensDto.js +1 -0
  106. package/dist/data/auth/dto/UserDto.d.ts +17 -0
  107. package/dist/data/auth/dto/UserDto.js +1 -0
  108. package/dist/data/auth/dto/UserInfoDto.d.ts +14 -0
  109. package/dist/data/auth/dto/UserInfoDto.js +1 -0
  110. package/dist/data/auth/dto/index.d.ts +5 -0
  111. package/dist/data/auth/dto/index.js +5 -0
  112. package/dist/data/auth/index.d.ts +2 -0
  113. package/dist/data/auth/index.js +2 -0
  114. package/dist/data/auth/policy.d.ts +52 -0
  115. package/dist/data/auth/policy.js +44 -0
  116. package/dist/data/index.d.ts +2 -0
  117. package/dist/data/index.js +2 -0
  118. package/dist/index.d.ts +4 -0
  119. package/dist/index.js +4 -0
  120. package/dist/services/api/ApiCrudControllerClient/index.d.ts +41 -0
  121. package/dist/services/api/ApiCrudControllerClient/index.integration.test.d.ts +1 -0
  122. package/dist/services/api/ApiCrudControllerClient/index.integration.test.js +34 -0
  123. package/dist/services/api/ApiCrudControllerClient/index.js +116 -0
  124. package/dist/services/api/ApiInitializationService/index.d.ts +106 -0
  125. package/dist/services/api/ApiInitializationService/index.js +208 -0
  126. package/dist/services/api/ApiReadControllerClient/index.d.ts +40 -0
  127. package/dist/services/api/ApiReadControllerClient/index.integration.test.d.ts +1 -0
  128. package/dist/services/api/ApiReadControllerClient/index.integration.test.js +59 -0
  129. package/dist/services/api/ApiReadControllerClient/index.js +111 -0
  130. package/dist/services/api/HttpService/FetchHttpService.d.ts +7 -0
  131. package/dist/services/api/HttpService/FetchHttpService.integration.test.d.ts +1 -0
  132. package/dist/services/api/HttpService/FetchHttpService.integration.test.js +52 -0
  133. package/dist/services/api/HttpService/FetchHttpService.js +29 -0
  134. package/dist/services/api/HttpService/HttpRequestConfig.d.ts +10 -0
  135. package/dist/services/api/HttpService/HttpRequestConfig.js +1 -0
  136. package/dist/services/api/HttpService/HttpResponse.d.ts +11 -0
  137. package/dist/services/api/HttpService/HttpResponse.js +3 -0
  138. package/dist/services/api/HttpService/IHttpService.d.ts +13 -0
  139. package/dist/services/api/HttpService/IHttpService.js +3 -0
  140. package/dist/services/api/HttpService/index.d.ts +9 -0
  141. package/dist/services/api/HttpService/index.js +10 -0
  142. package/dist/services/api/UserManagementControllerClient/index.d.ts +41 -0
  143. package/dist/services/api/UserManagementControllerClient/index.integration.test.d.ts +1 -0
  144. package/dist/services/api/UserManagementControllerClient/index.integration.test.js +60 -0
  145. package/dist/services/api/UserManagementControllerClient/index.js +117 -0
  146. package/dist/services/api/index.d.ts +5 -0
  147. package/dist/services/api/index.js +5 -0
  148. package/dist/services/auth/client/AuthService/index.d.ts +75 -0
  149. package/dist/services/auth/client/AuthService/index.js +200 -0
  150. package/dist/services/auth/client/AuthorizationManagementControllerClient/index.d.ts +48 -0
  151. package/dist/services/auth/client/AuthorizationManagementControllerClient/index.integration.test.d.ts +1 -0
  152. package/dist/services/auth/client/AuthorizationManagementControllerClient/index.integration.test.js +89 -0
  153. package/dist/services/auth/client/AuthorizationManagementControllerClient/index.js +148 -0
  154. package/dist/services/auth/client/index.d.ts +2 -0
  155. package/dist/services/auth/client/index.js +2 -0
  156. package/dist/services/auth/index.d.ts +1 -0
  157. package/dist/services/auth/index.js +1 -0
  158. package/dist/services/index.d.ts +2 -0
  159. package/dist/services/index.js +2 -0
  160. package/dist/utils/authorization/index.d.ts +17 -0
  161. package/dist/utils/authorization/index.js +45 -0
  162. package/dist/utils/index.d.ts +2 -0
  163. package/dist/utils/index.js +2 -0
  164. package/dist/utils/result/index.d.ts +21 -0
  165. package/dist/utils/result/index.js +16 -0
  166. package/dist/utils/search/index.d.ts +34 -0
  167. package/dist/utils/search/index.js +106 -0
  168. package/package.json +45 -0
  169. package/src/adapters/CollectionViewAdapter/index.integration.test.ts +197 -0
  170. package/src/adapters/CollectionViewAdapter/index.ts +477 -0
  171. package/src/adapters/SearchAdapter/index.ts +302 -0
  172. package/src/adapters/index.ts +2 -0
  173. package/src/data/api/dto/PropertyPathDto.ts +4 -0
  174. package/src/data/api/dto/ReadOptionsDto.ts +8 -0
  175. package/src/data/api/dto/ReadResultDto.ts +13 -0
  176. package/src/data/api/dto/ReadResultMetadataDto.ts +8 -0
  177. package/src/data/api/dto/crud/CrudMetadataDto.ts +4 -0
  178. package/src/data/api/dto/crud/index.ts +1 -0
  179. package/src/data/api/dto/index.ts +4 -0
  180. package/src/data/api/dto/read/ReadMetadataDto.ts +8 -0
  181. package/src/data/api/dto/read/ReadSelectedDefinitionDto.ts +21 -0
  182. package/src/data/api/dto/read/ReadSelectedNestedCollectionCriteriaDto.ts +25 -0
  183. package/src/data/api/dto/read/ReadSelectedNestedCriteriaDto.ts +20 -0
  184. package/src/data/api/dto/read/ReadSelectedOrderingDefinitionDto.ts +8 -0
  185. package/src/data/api/dto/read/ReadSelectedOrderingPropertyDefinitionDto.ts +16 -0
  186. package/src/data/api/dto/read/ReadSelectedPaginationDefinitionDto.ts +13 -0
  187. package/src/data/api/dto/read/ReadSelectedSearchDefinitionBuilder.ts +348 -0
  188. package/src/data/api/dto/read/ReadSelectedSearchDefinitionDto.ts +43 -0
  189. package/src/data/api/dto/read/ReadSelectedSearchPropertyDefinitionDto.ts +186 -0
  190. package/src/data/api/dto/read/index.ts +10 -0
  191. package/src/data/api/dto/response/ApiErrorDto.ts +21 -0
  192. package/src/data/api/dto/response/ApiErrorResponseDto.ts +13 -0
  193. package/src/data/api/dto/response/ApiResponseDto.ts +7 -0
  194. package/src/data/api/dto/response/ApiSuccessResponseDto.ts +13 -0
  195. package/src/data/api/dto/response/MetadataDto.ts +24 -0
  196. package/src/data/api/dto/response/index.ts +5 -0
  197. package/src/data/api/enum/index.ts +2 -0
  198. package/src/data/api/enum/read/ReadSelectedCollectionOperator.ts +17 -0
  199. package/src/data/api/enum/read/ReadSelectedComparisonOperator.ts +96 -0
  200. package/src/data/api/enum/read/ReadSelectedLogicalOperator.ts +16 -0
  201. package/src/data/api/enum/read/ReadSelectedOrderingDirection.ts +13 -0
  202. package/src/data/api/enum/read/ReadSelectedPropertyType.ts +96 -0
  203. package/src/data/api/enum/read/index.ts +5 -0
  204. package/src/data/api/enum/response/ErrorCode.ts +13 -0
  205. package/src/data/api/enum/response/index.ts +1 -0
  206. package/src/data/api/index.ts +3 -0
  207. package/src/data/api/interface/ICommonIdentifiable.ts +9 -0
  208. package/src/data/api/interface/IConcurrencySafe.ts +9 -0
  209. package/src/data/api/interface/IIdentifiable.ts +12 -0
  210. package/src/data/api/interface/IIdentifiableSecondary.ts +9 -0
  211. package/src/data/api/interface/index.ts +3 -0
  212. package/src/data/auth/dto/ClaimDto.ts +4 -0
  213. package/src/data/auth/dto/RegisterRequestDto.ts +4 -0
  214. package/src/data/auth/dto/RoleDto.ts +6 -0
  215. package/src/data/auth/dto/SignInRequestDto.ts +4 -0
  216. package/src/data/auth/dto/TokensDto.ts +4 -0
  217. package/src/data/auth/dto/UserDto.ts +18 -0
  218. package/src/data/auth/dto/UserInfoDto.ts +15 -0
  219. package/src/data/auth/dto/index.ts +5 -0
  220. package/src/data/auth/index.ts +2 -0
  221. package/src/data/auth/policy.ts +63 -0
  222. package/src/data/index.ts +2 -0
  223. package/src/index.ts +4 -0
  224. package/src/services/api/ApiCrudControllerClient/index.integration.test.ts +46 -0
  225. package/src/services/api/ApiCrudControllerClient/index.ts +135 -0
  226. package/src/services/api/ApiInitializationService/index.ts +254 -0
  227. package/src/services/api/ApiReadControllerClient/index.integration.test.ts +71 -0
  228. package/src/services/api/ApiReadControllerClient/index.ts +137 -0
  229. package/src/services/api/HttpService/FetchHttpService.integration.test.ts +65 -0
  230. package/src/services/api/HttpService/FetchHttpService.ts +34 -0
  231. package/src/services/api/HttpService/HttpRequestConfig.ts +10 -0
  232. package/src/services/api/HttpService/HttpResponse.ts +14 -0
  233. package/src/services/api/HttpService/IHttpService.ts +17 -0
  234. package/src/services/api/HttpService/README.md +106 -0
  235. package/src/services/api/HttpService/index.ts +12 -0
  236. package/src/services/api/UserManagementControllerClient/index.integration.test.ts +69 -0
  237. package/src/services/api/UserManagementControllerClient/index.ts +134 -0
  238. package/src/services/api/index.ts +5 -0
  239. package/src/services/auth/client/AuthService/index.ts +233 -0
  240. package/src/services/auth/client/AuthorizationManagementControllerClient/index.integration.test.ts +110 -0
  241. package/src/services/auth/client/AuthorizationManagementControllerClient/index.ts +165 -0
  242. package/src/services/auth/client/index.ts +2 -0
  243. package/src/services/auth/index.ts +1 -0
  244. package/src/services/index.ts +2 -0
  245. package/src/utils/authorization/index.ts +47 -0
  246. package/src/utils/index.ts +2 -0
  247. package/src/utils/result/index.ts +25 -0
  248. package/src/utils/search/index.ts +150 -0
  249. package/tsconfig.json +19 -0
  250. package/vitest-setup.ts +43 -0
  251. package/vitest.config.ts +59 -0
package/README.md ADDED
@@ -0,0 +1,256 @@
1
+ # Cornerstone TypeScript WebClient Services
2
+
3
+ This project includes services for easy communication from a Cornerstone client application to the Cornerstone API.
4
+
5
+ ## Getting started
6
+
7
+ 1. Install dependencies:
8
+
9
+ ```bash
10
+ pnpm install
11
+ ```
12
+
13
+ 2. Build the project:
14
+
15
+ ```bash
16
+ pnpm run build
17
+ ```
18
+
19
+ 3. Run Client demo HTTP server:
20
+
21
+ ```bash
22
+ pnpm run demo
23
+ ```
24
+
25
+ 4. Open
26
+
27
+ http://localhost:3000
28
+
29
+ ## API reference
30
+
31
+ ### API Initialization service
32
+
33
+ This service provides a centralized way to initialize API configuration for a Cornerstone client application, including automatic API base URL detection and shared settings fetching:
34
+
35
+ ```ts
36
+ import { ApiInitializationService } from '@intellegens/cornerstone-client';
37
+ const apiInitializationService = new ApiInitializationService();
38
+ await apiInitializationService.initializeAsync();
39
+ ```
40
+
41
+ or use the existing singleton instance
42
+
43
+ ```ts
44
+ import { apiInitializationService } from '@intellegens/cornerstone-client';
45
+ await apiInitializationService.initializeAsync();
46
+ ```
47
+
48
+ #### Key Features
49
+
50
+ - **API Base URL Detection**: Automatically detects the API base URL through multiple methods
51
+ - **Shared Settings Management**: Fetches and caches server-side configuration that's safe to share with clients
52
+ - **HTTP Service Configuration**: Allows customization of the global HTTP service
53
+ - **Automatic Initialization**: Handles both API detection and configuration fetching in a single call
54
+
55
+ It also provides a way of customizing global defaults for Cornerstone client application:
56
+
57
+ - `httpService` Configures a default HTTP Service to be used across the application, unless specified otherwise (See [HTTP Service Abstraction](#http-service-abstraction))
58
+
59
+ ```ts
60
+ import { apiInitializationService, FetchHttpService } from '@intellegens/cornerstone-client';
61
+ await apiInitializationService.initializeAsync({
62
+ httpService: new FetchHttpService(),
63
+ });
64
+ ```
65
+
66
+ #### API base URL detection
67
+
68
+ Base API URL is detected by checking the `CORNERSTONE-API-BASEURL` response header and the `./websettings.json` file.
69
+
70
+ - First, Cornerstone client checks the response headers of the current URL for the `CORNERSTONE-API-BASEURL` header.
71
+ - If the header is not found, Cornerstone client attempts to load the `websettings.json` file and looks for an `api` field.
72
+ - If no API base URL is found, Cornerstone client defaults to `undefined`.
73
+
74
+ Before, or after the base API URL has been detected, you can get any API endpoint URL by calling:
75
+
76
+ ```ts
77
+ const fetchUrl = `${await apiInitializationService.getApiUrlAsync('/my/endpoint')}`;
78
+ ```
79
+
80
+ #### Shared Settings Access
81
+
82
+ After initialization, you can access server-side configuration that's been shared with the client:
83
+
84
+ ```ts
85
+ // Get cached app settings
86
+ const settings = apiInitializationService.appConfig;
87
+ ```
88
+
89
+ The app shared settings contain only client-safe configuration properties as defined by the server-side `AppSettingsShared` class, plus any additional runtime settings. Sensitive server-only settings are never exposed to clients.
90
+
91
+ ### ~~System Service~~ (Deprecated)
92
+
93
+ > **Note**: The SystemService has been deprecated and its functionality has been integrated into the ApiInitializationService. Use `apiInitializationService.appConfig` instead of the SystemService methods.
94
+
95
+ The System Service functionality is now handled directly by the ApiInitializationService during initialization. The service automatically fetches and caches shared configuration settings from the server's `/api/system/init` endpoint.
96
+
97
+ #### Migration Guide
98
+
99
+ **Old approach:**
100
+
101
+ ```ts
102
+ import { systemService } from '@intellegens/cornerstone-client';
103
+
104
+ // Initialize and fetch shared settings
105
+ await systemService.initializeAsync();
106
+
107
+ // Get cached settings
108
+ const settings = systemService.getInitializationInfo();
109
+ ```
110
+
111
+ **New approach:**
112
+
113
+ ```ts
114
+ import { apiInitializationService } from '@intellegens/cornerstone-client';
115
+
116
+ // Initialize (automatically fetches shared settings)
117
+ await apiInitializationService.initializeAsync();
118
+
119
+ // Get cached settings
120
+ const settings = apiInitializationService.appConfig;
121
+ ```
122
+
123
+ #### Key Features
124
+
125
+ - **Automatic Integration**: Settings are fetched during API initialization
126
+ - **Type Safety**: Supports generic typed settings interfaces
127
+ - **Error Handling**: Gracefully handles network errors and returns undefined for failed requests
128
+ - **Server Integration**: Works seamlessly with Cornerstone server-side configuration system
129
+
130
+ ### HTTP Service Abstraction
131
+
132
+ The Cornerstone client provides a flexible HTTP service abstraction that allows you to use different HTTP libraries (Fetch API, Angular HttpClient) with the same API clients. This abstraction provides consistent behavior across different HTTP implementations while maintaining framework independence.
133
+
134
+ #### Key Features
135
+
136
+ - **Pluggable HTTP implementations** - Switch between Fetch and Angular HttpClient
137
+ - **Consistent interface** - All HTTP services implement the same `IHttpService` interface
138
+ - **Framework agnostic** - Use the same API clients in React, Angular, Vue, or any other framework
139
+ - **Easy testing** - Mock HTTP requests easily for unit testing
140
+ - **Runtime switching** - Change HTTP service implementations at runtime
141
+
142
+ #### Quick Example
143
+
144
+ ```ts
145
+ import { ApiReadControllerClient, FetchHttpService } from '@intellegens/cornerstone-client';
146
+
147
+ // Using default Fetch implementation
148
+ const client = new ApiReadControllerClient('/api/users');
149
+ ```
150
+
151
+ For detailed documentation, examples, and advanced usage, see: [HTTP Service Documentation](./src/services/api/HttpService/README.md)
152
+
153
+ ### Auth Service
154
+
155
+ This service provides authentication methods for managing user sessions in a Cornerstone client application.
156
+
157
+ ```ts
158
+ import { AuthService } from './index.js';
159
+ const authService = new AuthService();
160
+ await authService.initialize();
161
+ const user = authService.user;
162
+ ```
163
+
164
+ #### Methods
165
+
166
+ ##### Who Am I
167
+
168
+ ```ts
169
+ authService.whoAmI(): Promise<UserDto | undefined>
170
+ ```
171
+
172
+ 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.
173
+
174
+ ##### Sign in
175
+
176
+ ```ts
177
+ authService.signin(username: string, password: string): Promise<UserDto | undefined>
178
+ ```
179
+
180
+ 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.
181
+
182
+ ##### Sign out
183
+
184
+ ```ts
185
+ authService.logout(): Promise<UserDto | undefined>
186
+ ```
187
+
188
+ 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
189
+
190
+ ### CollectionViewAdapter
191
+
192
+ TS class for handling sorting, filtering and paginating collections
193
+
194
+ Note that the collection is fetched on a page by page basis. Page size determines the number of items returned for display.
195
+
196
+ ```typescript
197
+ ngOnInit() {
198
+ this._adapter = new CollectionViewAdapter<number, ExampleDto>(
199
+ 'Example', // controller name
200
+ (isLoading, data) => {
201
+ // data: ExampleDto[]
202
+ // handle as needed
203
+ },
204
+ this._options, // pass along initial options CollectionViewAdapterOptions<TDto>
205
+ );
206
+ }
207
+ ```
208
+
209
+ ### utils
210
+
211
+ Helper functions for constructing `ReadSelectedSearchDefinitionDto`.
212
+
213
+ Example usage:
214
+
215
+ ```typescript
216
+ const search = condition(
217
+ ReadSelectedLogicalOperator.Or,
218
+ { path: 'clients', operator: ReadSelectedComparisonOperator.Contains, value: 'search-term', valueType: ReadSelectedPropertyType.String },
219
+ { path: 'suppliers', operator: ReadSelectedComparisonOperator.Contains, value: 'search-term', valueType: ReadSelectedPropertyType.String },
220
+ { path: 'facilities', operator: ReadSelectedComparisonOperator.Contains, value: 'search-term', valueType: ReadSelectedPropertyType.String },
221
+ );
222
+
223
+ const dateRange = condition(
224
+ ReadSelectedLogicalOperator.And,
225
+ {
226
+ path: 'createdDate',
227
+ operator: ReadSelectedComparisonOperator.GreaterOrEqual,
228
+ value: new Date('2024-01-01'),
229
+ valueType: ReadSelectedPropertyType.DateTime,
230
+ },
231
+ {
232
+ path: 'createdDate',
233
+ operator: ReadSelectedComparisonOperator.LessOrEqual,
234
+ value: new Date('2024-12-31'),
235
+ valueType: ReadSelectedPropertyType.DateTime,
236
+ },
237
+ );
238
+
239
+ const definition = and(search, dateRange);
240
+ ```
241
+
242
+ Functions `searchTerm` and `dateInterval` have been prepared to simplify usage for these common needs:
243
+
244
+ ```typescript
245
+ const definition = and(
246
+ searchTerm('search-term', textSearchablePaths, numericSearchablePaths),
247
+ dateInterval(
248
+ from,
249
+ to,
250
+ ReadSelectedComparisonOperator.GreaterOrEqual,
251
+ ReadSelectedComparisonOperator.LessOrEqual,
252
+ ReadSelectedPropertyType.DateTimeOffset,
253
+ 'exampleColumnName',
254
+ ),
255
+ );
256
+ ```
package/demo/index.ts ADDED
@@ -0,0 +1,29 @@
1
+ import express from 'express';
2
+ import { createProxyMiddleware } from 'http-proxy-middleware';
3
+
4
+ const HTTP_PORT = 3000;
5
+ const API_PORT = 5235;
6
+
7
+ const app = express();
8
+
9
+ // config proxy for api calls
10
+ app.use(
11
+ createProxyMiddleware({
12
+ pathFilter: '/api',
13
+ target: `http://localhost:${API_PORT}`,
14
+ changeOrigin: true,
15
+ logger: console,
16
+ }),
17
+ );
18
+ app.use(
19
+ express.static('./demo/public_html', {
20
+ setHeaders: function (res) {
21
+ if (Math.random() > 0.5) res.set('CORNERSTONE-API-BASEURL', `/api`);
22
+ },
23
+ }),
24
+ );
25
+ app.listen(HTTP_PORT, () => {
26
+ console.log();
27
+ console.log(`Demo App listening on: http://localhost:${HTTP_PORT}`);
28
+ console.log(`... API requests proxied to: http://localhost:${API_PORT}/api`);
29
+ });
Binary file
@@ -0,0 +1,106 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <!-- HEAD -->
4
+ <head>
5
+ <meta charset="UTF-8" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
+ <title>Cornerstone Test Client</title>
8
+
9
+ <!-- General styling -->
10
+ <style>
11
+ html {
12
+ font-family: monospace;
13
+ }
14
+ .comment {
15
+ color: gray;
16
+ }
17
+ </style>
18
+ </head>
19
+
20
+ <!-- BODY -->
21
+ <body>
22
+ <!-- API base URL detection demo template-->
23
+ <div>
24
+ <h2>API Detection Demo</h2>
25
+ <pre class="comment">
26
+ This demo will randomly initialize client configuration from one of:
27
+ - Response CORNERSTONE-API-BASEURL header
28
+ - A settings file: websettings.json
29
+ </pre>
30
+
31
+ <span>Detected API base URL as: <strong id="api-base-url"></strong> via method <strong id="api-base-url-method"></strong></span>
32
+ </pre>
33
+ </div>
34
+ <!-- API base URL detection demo JS -->
35
+ <script type="module">
36
+ import { apiService } from './index.js';
37
+ document.getElementById('api-base-url').innerText = await apiService._getApiBaseUrl();
38
+ document.getElementById('api-base-url-method').innerText = apiService._apiBaseUrlDetectionMethod;
39
+ </script>
40
+
41
+ <!-- Auth demo template -->
42
+ <hr />
43
+ <div>
44
+ <h2>Auth Demo</h2>
45
+ <pre class="comment">
46
+ This demo will allow you to interact with the authentication API by:
47
+ - Checking the authentication status
48
+ - Authenticating with a username and password
49
+ - Deauthenticating
50
+ </pre>
51
+ <div>
52
+ <div>
53
+ Check your current authentication status:
54
+ <button id="whoAmI">Who am I?</button>
55
+ </div>
56
+ <div>
57
+ Authenticate using your credentials:
58
+ <input type="text" name="username" id="username" placeholder="Username" value="admin@test.com" />
59
+ <input type="password" name="password" id="password" placeholder="Password" value="Test1234!" />
60
+ <button id="signin">Sign in</button>
61
+ </div>
62
+ <div>
63
+ Deauthenticate:
64
+ <button id="signout">Sign out</button>
65
+ </div>
66
+ </div>
67
+ <div id="authentication-info" style="margin-top: 10px"></div>
68
+ </div>
69
+ <!-- API base URL detection demo JS -->
70
+ <script type="module">
71
+ import { authService } from './index.js';
72
+ // whoAmI demo functionality
73
+ document.getElementById('whoAmI').addEventListener('click', async () => {
74
+ const authInfoEl = document.getElementById('authentication-info');
75
+ try {
76
+ const user = await authService.whoAmI();
77
+ authInfoEl.innerText = `You are authenticated as: ${JSON.stringify(user)}`;
78
+ } catch (err) {
79
+ authInfoEl.innerText = 'You are not authenticated!';
80
+ }
81
+ });
82
+ // login demo functionality
83
+ document.getElementById('signin').addEventListener('click', async () => {
84
+ const authInfoEl = document.getElementById('authentication-info');
85
+ const username = document.getElementById('username').value;
86
+ const password = document.getElementById('password').value;
87
+ try {
88
+ const user = await authService.signin(username, password);
89
+ authInfoEl.innerText = `Signed in in successfully as: ${JSON.stringify(user)}`;
90
+ } catch (err) {
91
+ authInfoEl.innerText = `Failed signing in: ${err.message}`;
92
+ }
93
+ });
94
+ // logout demo functionality
95
+ document.getElementById('signout').addEventListener('click', async () => {
96
+ const authInfoEl = document.getElementById('authentication-info');
97
+ try {
98
+ await authService.signout();
99
+ authInfoEl.innerText = `Successfully signed out`;
100
+ } catch (err) {
101
+ authInfoEl.innerText = `Failed signing out: ${err.message}`;
102
+ }
103
+ });
104
+ </script>
105
+ </body>
106
+ </html>
@@ -0,0 +1,3 @@
1
+ {
2
+ "api": "/api"
3
+ }
@@ -0,0 +1,198 @@
1
+ import { IIdentifiable, PropertyPathDto, ReadSelectedOrderingDirection, ReadSelectedSearchDefinitionDto } from '../../data';
2
+ /**
3
+ * Used with CollectionViewAdapter, a simplified configuration object for handling reading/writing from/to ReadSelectedDefinitionDto.
4
+ *
5
+ * @template TDto The type of the collection being sorted/filtered/paginated.
6
+ *
7
+ * @property {object} pagination - Pagination configuration
8
+ * @property {boolean} pagination.useTotalItemCount - Used for last page related logic of the paginator.
9
+ * Set to true if the total count for the collection is available; false assumes the last page is not known
10
+ * and adapts the pagination display accordingly.
11
+ * @property {number} [pagination.pageSize] - Number of items/rows to be fetched for the current page.
12
+ * @property {number} [pagination.pageNumber] - Current page index (skips fetching `(n-1) * pageSize` items/rows).
13
+ *
14
+ * @property {object} ordering - Ordering configuration
15
+ * @property {string[]} [ordering.orderByPath] - Array of column/property names that are sortable.
16
+ * @property {ReadSelectedOrderingDirection} [ordering.orderDirection] - Enum for ascending/descending sort order.
17
+ *
18
+ * @property {object} search - Search configuration
19
+ * @property {(keyof TDto)[]} [search.textSearchableProperties] - Array of column/property names that are searchable where the value type is string.
20
+ * @property {(keyof TDto)[]} [search.numericSearchableProperties] - Array of column/property names that are searchable where the value type is number.
21
+ * @property {ReadSelectedSearchDefinitionDto<TDto>} [search.searchDefinition] - The search definition by which the collection will be filtered.
22
+ */
23
+ export type CollectionViewAdapterOptions<TDto> = {
24
+ pagination: {
25
+ useTotalItemCount: boolean;
26
+ pageSize?: number;
27
+ pageNumber?: number;
28
+ };
29
+ ordering: {
30
+ maxActiveOrderingColumns: number;
31
+ orderByPaths: {
32
+ orderByPath: PropertyPathDto;
33
+ orderDirection: ReadSelectedOrderingDirection;
34
+ }[];
35
+ };
36
+ search: {
37
+ textSearchableProperties?: (keyof TDto)[];
38
+ numericSearchableProperties?: (keyof TDto)[];
39
+ searchDefinition?: ReadSelectedSearchDefinitionDto<TDto>;
40
+ };
41
+ };
42
+ /**
43
+ * TS class for handling ordering, filtering and paginating collections
44
+ *
45
+ * @param controllerName - specify the target endpoint controller name.
46
+ * @param dataChangedCallback - Function invoked whenever the data changes.
47
+ * Receives a loading state flag and the updated data collection.
48
+ * @param options - Optional settings of type CollectionViewAdapter to customize the behavior of the adapter.
49
+ */
50
+ export declare class CollectionViewAdapter<TKey, TDto extends IIdentifiable<TKey>, TDetailsDto extends IIdentifiable<TKey>> {
51
+ private _readClient;
52
+ private _isLoading;
53
+ private _pageData;
54
+ private _selectedItems;
55
+ private _defaultOptions;
56
+ private _initialOptions;
57
+ private _currentOptions;
58
+ constructor(controllerName: string, dataChangedCallback: (isLoading: boolean, data: TDto[] | undefined, error: string | undefined) => void, options?: CollectionViewAdapterOptions<TDto>);
59
+ /**
60
+ * Allows for adding any filtering criteria. Label is required to distinguish custom search categories (e.g. searchTerm, dateRange, anyCustom ...)
61
+ */
62
+ setSearchDefinition(searchDefinition: ReadSelectedSearchDefinitionDto<TDto>): Promise<TDto[]>;
63
+ /**
64
+ * Compares two PropertyPathDto arrays for equality
65
+ */
66
+ private _arePropertyPathsEqual;
67
+ /**
68
+ * Public method for ordering the collection by property path / column name.
69
+ *
70
+ * @param propertyPath - must match camel-cased property/column name being sorted
71
+ * @param orderDirection - use `ReadSelectedOrderingDirection` enum choices
72
+ */
73
+ setOrdering(propertyPath: PropertyPathDto, orderDirection: ReadSelectedOrderingDirection): Promise<TDto[]>;
74
+ /**
75
+ * Returns the property name of the current columns/properties on which ordering is applied, along with the `ReadSelectedOrderingDirection` direction
76
+ */
77
+ getCurrentOrdering(): {
78
+ orderByPath: PropertyPathDto;
79
+ orderDirection: ReadSelectedOrderingDirection;
80
+ }[];
81
+ /**
82
+ * Returns the current page's page number
83
+ */
84
+ get currentPage(): number | undefined;
85
+ /**
86
+ * Sets the current page to `pageNumber` and triggers data re-fetch
87
+ *
88
+ * @param pageNumber
89
+ */
90
+ jumpToPage(pageNumber: number): Promise<TDto[]>;
91
+ /**
92
+ * Returns the currently set page size value
93
+ */
94
+ get pageSize(): number | undefined;
95
+ /**
96
+ * Page size dictates the number of items or rows being fetched in a single API call
97
+ *
98
+ * @param pageSize
99
+ */
100
+ setPageSize(pageSize: number): Promise<TDto[]>;
101
+ /**
102
+ * Refreshes the data by re-fetching the current page
103
+ */
104
+ refreshData(): Promise<TDto[]>;
105
+ private _totalItemCount;
106
+ /**
107
+ * Returns the total count value of the collection.
108
+ *
109
+ * If `CollectionViewAdapterOptions` has set `pagination.useTotalItemCount` to `true`, the API will return this value along with the collection and it will be set automatically.
110
+ * Else this adapter will attempt to dynamically calculate this value via `_calculateTotal()`.
111
+ */
112
+ get totalItemCount(): number;
113
+ /**
114
+ * Callback function invoked whenever data changes.
115
+ * Receives a loading state flag and the updated data collection.
116
+ */
117
+ private readonly _dataChangedCallback;
118
+ /**
119
+ * Timeout reference used to debounce calls to `_fetchCurrentPageData`.
120
+ */
121
+ private _fetchCurrentPageDataTimeout?;
122
+ /**
123
+ * Queue of pending promises waiting for `_fetchCurrentPageData` to resolve or reject.
124
+ */
125
+ private _fetchCurrentPageDataPromises;
126
+ /**
127
+ * Tracks the current in-flight request controller to allow cancellation when a new fetch starts.
128
+ */
129
+ private _currentAbortController?;
130
+ /**
131
+ * Fetches the current page of data with debouncing support.
132
+ * Consolidates multiple concurrent calls into a single execution,
133
+ * resolving all queued promises with the same result.
134
+ *
135
+ * @returns A promise resolving to the fetched page of data.
136
+ */
137
+ private _fetchCurrentPageData;
138
+ /**
139
+ * Executes the actual data fetch operation after debounce delay.
140
+ * Updates the loading state, triggers data change callbacks,
141
+ * and handles total item count calculation if pagination is enabled.
142
+ *
143
+ * @returns A promise resolving to the fetched page of data.
144
+ */
145
+ private _fetchCurrentPageDataDebounced;
146
+ /**
147
+ * Takes current `CollectionViewAdapterOptions` and parses to `ReadSelectedDefinitionDto` which the cornerstone API expects.
148
+ *
149
+ * @returns - `ReadSelectedDefinitionDto` object
150
+ */
151
+ private _parseOptionsToDefinition;
152
+ /**
153
+ * Calculates the total item count given pagination inputs.
154
+ *
155
+ * For example, with 10 items per page, on page 2 with 3 items, total = 13.
156
+ * If the total cannot be inferred (e.g., a full page is returned), the previous total is returned unchanged.
157
+ *
158
+ * @param pageSize - Number of items per page
159
+ * @param currentPageNumber - Current page number (1-based)
160
+ * @param itemsOnCurrentPageCount - Number of items in the fetched page
161
+ * @param previousTotal - Previous known total to preserve when indeterminate
162
+ * @returns The computed total item count
163
+ */
164
+ private _calculateTotal;
165
+ /**
166
+ * Selects or deselects an item based on its ID.
167
+ * @param item - The item to select or deselect.
168
+ */
169
+ toggleItemSelected(item: TDto): void;
170
+ clearSelectedItems(): void;
171
+ selectItems(item: TDto): void;
172
+ deselectItem(item: TDto): void;
173
+ /**
174
+ * Returns the currently selected items
175
+ */
176
+ get selectedItems(): TDto[];
177
+ /**
178
+ * Checks if an item is currently selected
179
+ * @param item - The item to check
180
+ */
181
+ isItemSelected(item: TDto): boolean;
182
+ /**
183
+ * Selects all items on the current page
184
+ */
185
+ selectAllItemsOnCurrentPage(): void;
186
+ /**
187
+ * Deselects all items on the current page
188
+ */
189
+ deselectAllItemsOnCurrentPage(): void;
190
+ /**
191
+ * Checks if all items on the current page are selected
192
+ */
193
+ areAllItemsOnCurrentPageSelected(): boolean;
194
+ /**
195
+ * Checks if some (but not all) items on the current page are selected
196
+ */
197
+ areSomeItemsOnCurrentPageSelected(): boolean;
198
+ }