@intellegens/cornerstone-client 0.0.9999-alpha-41 → 0.0.9999-alpha-43

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 (233) hide show
  1. package/dist/adapters/collection-view-adapter.d.ts +123 -0
  2. package/dist/adapters/collection-view-adapter.integration.test.d.ts +1 -0
  3. package/dist/adapters/collection-view-adapter.integration.test.js +141 -0
  4. package/dist/adapters/collection-view-adapter.js +352 -0
  5. package/dist/adapters/index.d.ts +2 -2
  6. package/dist/adapters/index.js +2 -2
  7. package/dist/adapters/search-adapter.d.ts +83 -0
  8. package/dist/adapters/search-adapter.js +284 -0
  9. package/dist/data/api/dto/crud/crud-metadata-dto.js +1 -0
  10. package/dist/data/api/dto/crud/index.d.ts +1 -1
  11. package/dist/data/api/dto/crud/index.js +1 -1
  12. package/dist/data/api/dto/index.d.ts +1 -1
  13. package/dist/data/api/dto/index.js +1 -1
  14. package/dist/data/api/dto/property-path-dto.d.ts +4 -0
  15. package/dist/data/api/dto/property-path-dto.js +1 -0
  16. package/dist/data/api/dto/read/index.d.ts +10 -10
  17. package/dist/data/api/dto/read/index.js +10 -10
  18. package/dist/data/api/dto/read/read-metadata-dto.d.ts +8 -0
  19. package/dist/data/api/dto/read/read-metadata-dto.js +1 -0
  20. package/dist/data/api/dto/read/read-selected-definition-dto.d.ts +18 -0
  21. package/dist/data/api/dto/read/read-selected-definition-dto.js +1 -0
  22. package/dist/data/api/dto/read/read-selected-nested-collection-criteria-dto.d.ts +22 -0
  23. package/dist/data/api/dto/read/read-selected-nested-collection-criteria-dto.js +1 -0
  24. package/dist/data/api/dto/read/read-selected-nested-criteria-dto.d.ts +18 -0
  25. package/dist/data/api/dto/read/read-selected-nested-criteria-dto.js +1 -0
  26. package/dist/data/api/dto/read/read-selected-ordering-definition-dto.d.ts +7 -0
  27. package/dist/data/api/dto/read/read-selected-ordering-definition-dto.js +1 -0
  28. package/dist/data/api/dto/read/read-selected-ordering-property-definition-dto.d.ts +14 -0
  29. package/dist/data/api/dto/read/read-selected-ordering-property-definition-dto.js +1 -0
  30. package/dist/data/api/dto/read/read-selected-pagination-definition-dto.d.ts +13 -0
  31. package/dist/data/api/dto/read/read-selected-pagination-definition-dto.js +1 -0
  32. package/dist/data/api/dto/read/read-selected-search-definition-builder.d.ts +167 -0
  33. package/dist/data/api/dto/read/read-selected-search-definition-builder.js +267 -0
  34. package/dist/data/api/dto/read/read-selected-search-definition-dto.d.ts +33 -0
  35. package/dist/data/api/dto/read/read-selected-search-definition-dto.js +1 -0
  36. package/dist/data/api/dto/read/read-selected-search-property-definition-dto.d.ts +114 -0
  37. package/dist/data/api/dto/read/read-selected-search-property-definition-dto.js +1 -0
  38. package/dist/data/api/dto/read-options-dto.d.ts +8 -0
  39. package/dist/data/api/dto/read-options-dto.js +1 -0
  40. package/dist/data/api/dto/read-result-dto.d.ts +12 -0
  41. package/dist/data/api/dto/read-result-dto.js +1 -0
  42. package/dist/data/api/dto/read-result-metadata-dto.d.ts +8 -0
  43. package/dist/data/api/dto/read-result-metadata-dto.js +1 -0
  44. package/dist/data/api/dto/response/api-error-dto.d.ts +17 -0
  45. package/dist/data/api/dto/response/api-error-dto.js +1 -0
  46. package/dist/data/api/dto/response/api-error-response-dto.d.ts +11 -0
  47. package/dist/data/api/dto/response/api-error-response-dto.js +1 -0
  48. package/dist/data/api/dto/response/api-response-dto.d.ts +3 -0
  49. package/dist/data/api/dto/response/api-response-dto.js +1 -0
  50. package/dist/data/api/dto/response/api-success-response-dto.d.ts +13 -0
  51. package/dist/data/api/dto/response/api-success-response-dto.js +1 -0
  52. package/dist/data/api/dto/response/index.d.ts +5 -5
  53. package/dist/data/api/dto/response/index.js +5 -5
  54. package/dist/data/api/dto/response/metadata-dto.d.ts +25 -0
  55. package/dist/data/api/dto/response/metadata-dto.js +1 -0
  56. package/dist/data/api/enum/read/index.d.ts +5 -5
  57. package/dist/data/api/enum/read/index.js +5 -5
  58. package/dist/data/api/enum/read/read-selected-collection-operator.d.ts +16 -0
  59. package/dist/data/api/enum/read/read-selected-collection-operator.js +17 -0
  60. package/dist/data/api/enum/read/read-selected-comparison-operator.d.ts +69 -0
  61. package/dist/data/api/enum/read/read-selected-comparison-operator.js +76 -0
  62. package/dist/data/api/enum/read/read-selected-logical-operator.d.ts +15 -0
  63. package/dist/data/api/enum/read/read-selected-logical-operator.js +16 -0
  64. package/dist/data/api/enum/read/read-selected-ordering-direction.d.ts +13 -0
  65. package/dist/data/api/enum/read/read-selected-ordering-direction.js +14 -0
  66. package/dist/data/api/enum/read/read-selected-property-type.d.ts +66 -0
  67. package/dist/data/api/enum/read/read-selected-property-type.js +75 -0
  68. package/dist/data/api/enum/response/error-code.d.ts +14 -0
  69. package/dist/data/api/enum/response/error-code.js +15 -0
  70. package/dist/data/api/enum/response/index.d.ts +1 -1
  71. package/dist/data/api/enum/response/index.js +1 -1
  72. package/dist/data/api/interface/icommon-identifiable.d.ts +7 -0
  73. package/dist/data/api/interface/icommon-identifiable.js +1 -0
  74. package/dist/data/api/interface/iconcurrency-safe.d.ts +9 -0
  75. package/dist/data/api/interface/iconcurrency-safe.js +1 -0
  76. package/dist/data/api/interface/iidentifiable-secondary.d.ts +9 -0
  77. package/dist/data/api/interface/iidentifiable-secondary.js +1 -0
  78. package/dist/data/api/interface/iidentifiable.d.ts +11 -0
  79. package/dist/data/api/interface/iidentifiable.js +1 -0
  80. package/dist/data/api/interface/index.d.ts +4 -3
  81. package/dist/data/api/interface/index.js +4 -3
  82. package/dist/data/auth/dto/claim-dto.d.ts +4 -0
  83. package/dist/data/auth/dto/claim-dto.js +1 -0
  84. package/dist/data/auth/dto/index.d.ts +6 -5
  85. package/dist/data/auth/dto/index.js +6 -5
  86. package/dist/data/auth/dto/register-request-dto.d.ts +4 -0
  87. package/dist/data/auth/dto/register-request-dto.js +1 -0
  88. package/dist/data/auth/dto/role-dto.d.ts +5 -0
  89. package/dist/data/auth/dto/role-dto.js +1 -0
  90. package/dist/data/auth/dto/role-with-claims-dto.d.ts +5 -0
  91. package/dist/data/auth/dto/role-with-claims-dto.js +1 -0
  92. package/dist/data/auth/dto/sign-in-request-dto.d.ts +4 -0
  93. package/dist/data/auth/dto/sign-in-request-dto.js +1 -0
  94. package/dist/data/auth/dto/tokens-dto.d.ts +4 -0
  95. package/dist/data/auth/dto/tokens-dto.js +1 -0
  96. package/dist/data/auth/dto/user-dto.d.ts +16 -0
  97. package/dist/data/auth/dto/user-dto.js +1 -0
  98. package/dist/data/auth/dto/user-info-dto.d.ts +14 -0
  99. package/dist/data/auth/dto/user-info-dto.js +1 -0
  100. package/dist/services/api/api-crud-controller-client.d.ts +62 -0
  101. package/dist/services/api/api-crud-controller-client.integration.test.d.ts +1 -0
  102. package/dist/services/api/api-crud-controller-client.integration.test.js +34 -0
  103. package/dist/services/api/api-crud-controller-client.js +133 -0
  104. package/dist/services/api/api-initialization-service.d.ts +106 -0
  105. package/dist/services/api/api-initialization-service.js +207 -0
  106. package/dist/services/api/api-read-controller-client.d.ts +62 -0
  107. package/dist/services/api/api-read-controller-client.integration.test.d.ts +1 -0
  108. package/dist/services/api/api-read-controller-client.integration.test.js +59 -0
  109. package/dist/services/api/api-read-controller-client.js +129 -0
  110. package/dist/services/api/http-service/fetch-http-service.d.ts +7 -0
  111. package/dist/services/api/http-service/fetch-http-service.integration.test.d.ts +1 -0
  112. package/dist/services/api/http-service/fetch-http-service.integration.test.js +52 -0
  113. package/dist/services/api/http-service/fetch-http-service.js +29 -0
  114. package/dist/services/api/http-service/http-request-config.d.ts +10 -0
  115. package/dist/services/api/http-service/http-request-config.js +1 -0
  116. package/dist/services/api/http-service/http-response.d.ts +11 -0
  117. package/dist/services/api/http-service/http-response.js +3 -0
  118. package/dist/services/api/http-service/http-service.d.ts +5 -0
  119. package/dist/services/api/http-service/http-service.js +5 -0
  120. package/dist/services/api/http-service/ihttp-service.d.ts +13 -0
  121. package/dist/services/api/http-service/ihttp-service.js +3 -0
  122. package/dist/services/api/http-service/index.d.ts +5 -0
  123. package/dist/services/api/http-service/index.js +5 -0
  124. package/dist/services/api/index.d.ts +5 -5
  125. package/dist/services/api/index.js +5 -5
  126. package/dist/services/api/user-management-controller-client.d.ts +80 -0
  127. package/dist/services/api/user-management-controller-client.integration.test.d.ts +1 -0
  128. package/dist/services/api/user-management-controller-client.integration.test.js +60 -0
  129. package/dist/services/api/user-management-controller-client.js +291 -0
  130. package/dist/services/auth/client/auth-service.d.ts +75 -0
  131. package/dist/services/auth/client/auth-service.js +200 -0
  132. package/dist/services/auth/client/authorization-management-controller-client.d.ts +48 -0
  133. package/dist/services/auth/client/authorization-management-controller-client.integration.test.d.ts +1 -0
  134. package/dist/services/auth/client/authorization-management-controller-client.integration.test.js +89 -0
  135. package/dist/services/auth/client/authorization-management-controller-client.js +148 -0
  136. package/dist/services/auth/client/index.d.ts +2 -2
  137. package/dist/services/auth/client/index.js +2 -2
  138. package/dist/utils/authorization.d.ts +17 -0
  139. package/dist/utils/authorization.js +45 -0
  140. package/dist/utils/events.d.ts +19 -0
  141. package/dist/utils/events.js +12 -0
  142. package/dist/utils/index.d.ts +2 -0
  143. package/dist/utils/index.js +2 -0
  144. package/dist/utils/result.d.ts +21 -0
  145. package/dist/utils/result.js +16 -0
  146. package/dist/utils/search.d.ts +34 -0
  147. package/dist/utils/search.js +106 -0
  148. package/package.json +6 -6
  149. package/src/adapters/collection-view-adapter.integration.test.ts +172 -0
  150. package/src/adapters/collection-view-adapter.ts +458 -0
  151. package/src/adapters/index.ts +2 -2
  152. package/src/adapters/search-adapter.ts +374 -0
  153. package/src/data/api/dto/crud/crud-metadata-dto.ts +4 -0
  154. package/src/data/api/dto/crud/index.ts +1 -1
  155. package/src/data/api/dto/index.ts +1 -1
  156. package/src/data/api/dto/read/index.ts +10 -10
  157. package/src/data/api/dto/read/{ReadSelectedSearchDefinitionBuilder.ts → read-selected-search-definition-builder.ts} +4 -4
  158. package/src/data/api/dto/{ReadResultDto.ts → read-result-dto.ts} +1 -1
  159. package/src/data/api/dto/response/{ApiErrorDto.ts → api-error-dto.ts} +1 -1
  160. package/src/data/api/dto/response/index.ts +5 -5
  161. package/src/data/api/enum/read/index.ts +5 -5
  162. package/src/data/api/enum/response/{ErrorCode.ts → error-code.ts} +1 -0
  163. package/src/data/api/enum/response/index.ts +1 -1
  164. package/src/data/api/interface/{ICommonIdentifiable.ts → icommon-identifiable.ts} +1 -1
  165. package/src/data/api/interface/{IConcurrencySafe.ts → iconcurrency-safe.ts} +1 -1
  166. package/src/data/api/interface/{IIdentifiable.ts → iidentifiable.ts} +1 -1
  167. package/src/data/api/interface/index.ts +4 -3
  168. package/src/data/auth/dto/index.ts +6 -5
  169. package/src/data/auth/dto/role-with-claims-dto.ts +6 -0
  170. package/src/data/auth/dto/{UserDto.ts → user-dto.ts} +5 -6
  171. package/src/services/api/{ApiCrudControllerClient/index.integration.test.ts → api-crud-controller-client.integration.test.ts} +1 -1
  172. package/src/services/api/{ApiCrudControllerClient/index.ts → api-crud-controller-client.ts} +62 -7
  173. package/src/services/api/{ApiInitializationService/index.ts → api-initialization-service.ts} +2 -4
  174. package/src/services/api/{ApiReadControllerClient/index.integration.test.ts → api-read-controller-client.integration.test.ts} +1 -1
  175. package/src/services/api/{ApiReadControllerClient/index.ts → api-read-controller-client.ts} +55 -6
  176. package/src/services/api/{HttpService/FetchHttpService.integration.test.ts → http-service/fetch-http-service.integration.test.ts} +1 -1
  177. package/src/services/api/http-service/http-service.ts +6 -0
  178. package/src/services/api/http-service/index.ts +5 -0
  179. package/src/services/api/index.ts +5 -5
  180. package/src/services/api/{UserManagementControllerClient/index.integration.test.ts → user-management-controller-client.integration.test.ts} +1 -1
  181. package/src/services/api/user-management-controller-client.ts +322 -0
  182. package/src/services/auth/client/index.ts +2 -2
  183. package/src/utils/events.ts +29 -0
  184. package/src/utils/index.ts +2 -0
  185. package/demo/index.ts +0 -29
  186. package/demo/public_html/favicon.ico +0 -0
  187. package/demo/public_html/index.html +0 -105
  188. package/demo/public_html/websettings.json +0 -3
  189. package/src/adapters/CollectionViewAdapter/index.integration.test.ts +0 -197
  190. package/src/adapters/CollectionViewAdapter/index.ts +0 -477
  191. package/src/adapters/SearchAdapter/index.ts +0 -302
  192. package/src/services/api/HttpService/index.ts +0 -12
  193. package/src/services/api/UserManagementControllerClient/index.ts +0 -134
  194. /package/{src/data/api/dto/crud/CrudMetadataDto.ts → dist/data/api/dto/crud/crud-metadata-dto.d.ts} +0 -0
  195. /package/src/data/api/dto/{PropertyPathDto.ts → property-path-dto.ts} +0 -0
  196. /package/src/data/api/dto/read/{ReadMetadataDto.ts → read-metadata-dto.ts} +0 -0
  197. /package/src/data/api/dto/read/{ReadSelectedDefinitionDto.ts → read-selected-definition-dto.ts} +0 -0
  198. /package/src/data/api/dto/read/{ReadSelectedNestedCollectionCriteriaDto.ts → read-selected-nested-collection-criteria-dto.ts} +0 -0
  199. /package/src/data/api/dto/read/{ReadSelectedNestedCriteriaDto.ts → read-selected-nested-criteria-dto.ts} +0 -0
  200. /package/src/data/api/dto/read/{ReadSelectedOrderingDefinitionDto.ts → read-selected-ordering-definition-dto.ts} +0 -0
  201. /package/src/data/api/dto/read/{ReadSelectedOrderingPropertyDefinitionDto.ts → read-selected-ordering-property-definition-dto.ts} +0 -0
  202. /package/src/data/api/dto/read/{ReadSelectedPaginationDefinitionDto.ts → read-selected-pagination-definition-dto.ts} +0 -0
  203. /package/src/data/api/dto/read/{ReadSelectedSearchDefinitionDto.ts → read-selected-search-definition-dto.ts} +0 -0
  204. /package/src/data/api/dto/read/{ReadSelectedSearchPropertyDefinitionDto.ts → read-selected-search-property-definition-dto.ts} +0 -0
  205. /package/src/data/api/dto/{ReadOptionsDto.ts → read-options-dto.ts} +0 -0
  206. /package/src/data/api/dto/{ReadResultMetadataDto.ts → read-result-metadata-dto.ts} +0 -0
  207. /package/src/data/api/dto/response/{ApiErrorResponseDto.ts → api-error-response-dto.ts} +0 -0
  208. /package/src/data/api/dto/response/{ApiResponseDto.ts → api-response-dto.ts} +0 -0
  209. /package/src/data/api/dto/response/{ApiSuccessResponseDto.ts → api-success-response-dto.ts} +0 -0
  210. /package/src/data/api/dto/response/{MetadataDto.ts → metadata-dto.ts} +0 -0
  211. /package/src/data/api/enum/read/{ReadSelectedCollectionOperator.ts → read-selected-collection-operator.ts} +0 -0
  212. /package/src/data/api/enum/read/{ReadSelectedComparisonOperator.ts → read-selected-comparison-operator.ts} +0 -0
  213. /package/src/data/api/enum/read/{ReadSelectedLogicalOperator.ts → read-selected-logical-operator.ts} +0 -0
  214. /package/src/data/api/enum/read/{ReadSelectedOrderingDirection.ts → read-selected-ordering-direction.ts} +0 -0
  215. /package/src/data/api/enum/read/{ReadSelectedPropertyType.ts → read-selected-property-type.ts} +0 -0
  216. /package/src/data/api/interface/{IIdentifiableSecondary.ts → iidentifiable-secondary.ts} +0 -0
  217. /package/src/data/auth/dto/{ClaimDto.ts → claim-dto.ts} +0 -0
  218. /package/src/data/auth/dto/{RegisterRequestDto.ts → register-request-dto.ts} +0 -0
  219. /package/src/data/auth/dto/{RoleDto.ts → role-dto.ts} +0 -0
  220. /package/src/data/auth/dto/{SignInRequestDto.ts → sign-in-request-dto.ts} +0 -0
  221. /package/src/data/auth/dto/{TokensDto.ts → tokens-dto.ts} +0 -0
  222. /package/src/data/auth/dto/{UserInfoDto.ts → user-info-dto.ts} +0 -0
  223. /package/src/services/api/{HttpService → http-service}/README.md +0 -0
  224. /package/src/services/api/{HttpService/FetchHttpService.ts → http-service/fetch-http-service.ts} +0 -0
  225. /package/src/services/api/{HttpService/HttpRequestConfig.ts → http-service/http-request-config.ts} +0 -0
  226. /package/src/services/api/{HttpService/HttpResponse.ts → http-service/http-response.ts} +0 -0
  227. /package/src/services/api/{HttpService/IHttpService.ts → http-service/ihttp-service.ts} +0 -0
  228. /package/src/services/auth/client/{AuthService/index.ts → auth-service.ts} +0 -0
  229. /package/src/services/auth/client/{AuthorizationManagementControllerClient/index.integration.test.ts → authorization-management-controller-client.integration.test.ts} +0 -0
  230. /package/src/services/auth/client/{AuthorizationManagementControllerClient/index.ts → authorization-management-controller-client.ts} +0 -0
  231. /package/src/utils/{authorization/index.ts → authorization.ts} +0 -0
  232. /package/src/utils/{result/index.ts → result.ts} +0 -0
  233. /package/src/utils/{search/index.ts → search.ts} +0 -0
@@ -0,0 +1,5 @@
1
+ import { ClaimDto } from '../..';
2
+ export type RoleWithClaimsDto = {
3
+ name: string;
4
+ claims: ClaimDto[];
5
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ export type SignInRequestDto = {
2
+ username: string;
3
+ password: string;
4
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ export type TokensDto = {
2
+ accessToken?: string;
3
+ refreshToken?: string;
4
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,16 @@
1
+ import { ClaimDto, IIdentifiable, RoleWithClaimsDto } from '../..';
2
+ /**
3
+ * Represents a user with an identifier and email address.
4
+ *
5
+ * @template TKey The type of the user identifier.
6
+ *
7
+ * @param {TKey} id The unique identifier for the user.
8
+ * @param {string} email The email address associated with the user.
9
+ * @param {RoleWithClaimsDto[]} roles The roles (with their claims) associated with the user.
10
+ * @param {ClaimDto[]} userClaims The claims associated with the user.
11
+ */
12
+ export type UserDto<TKey> = IIdentifiable<TKey> & {
13
+ email: string;
14
+ roles: RoleWithClaimsDto[];
15
+ userClaims: ClaimDto[];
16
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,14 @@
1
+ import { UserDto } from '../..';
2
+ /**
3
+ * Represents user information along with access token expiry.
4
+ *
5
+ * @template TKey The type of the user identifier.
6
+ * @template TUser The type of the user object, defaulting to `UserDto<TKey>`.
7
+ *
8
+ * @param {TUser} user The user object containing user details.
9
+ * @param {Date} accessTokenExpiry The date and time when the access token will expire.
10
+ */
11
+ export type UserInfoDto<TKey, TUser = UserDto<TKey>> = {
12
+ user: TUser;
13
+ accessTokenExpiry: Date;
14
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,62 @@
1
+ import { ApiReadControllerClient, IApiReadControllerClient, IHttpService } from '../../services';
2
+ import { ApiResponseDto, EmptyMetadataDto, IIdentifiable } from '../../data';
3
+ /**
4
+ * Client for creating a new entity in a CRUD controller.
5
+ */
6
+ export interface ICreateClient<TKey, TResultDto extends IIdentifiable<TKey>, TInsertRequestDto> {
7
+ create(dto: TInsertRequestDto, signal?: AbortSignal): Promise<ApiResponseDto<TResultDto, EmptyMetadataDto>>;
8
+ }
9
+ /**
10
+ * Client for updating an existing entity in a CRUD controller.
11
+ */
12
+ export interface IUpdateClient<TKey, TResultDto extends IIdentifiable<TKey>, TUpdateRequestDto> {
13
+ update(id: TKey, dto: TUpdateRequestDto, signal?: AbortSignal): Promise<ApiResponseDto<TResultDto, EmptyMetadataDto>>;
14
+ }
15
+ /**
16
+ * Client for deleting an entity in a CRUD controller.
17
+ */
18
+ export interface IDeleteClient<TKey> {
19
+ delete(id: TKey, signal?: AbortSignal): Promise<ApiResponseDto<undefined, EmptyMetadataDto>>;
20
+ }
21
+ /**
22
+ * Client for managing CRUD operations on a controller.
23
+ */
24
+ export interface IApiCrudControllerClient<TKey, TResultDto extends IIdentifiable<TKey>, TSingleResultDto extends IIdentifiable<TKey>, TInsertRequestDto, TUpdateRequestDto> extends IApiReadControllerClient<TKey, TResultDto, TSingleResultDto>, ICreateClient<TKey, TSingleResultDto, TInsertRequestDto>, IUpdateClient<TKey, TSingleResultDto, TUpdateRequestDto>, IDeleteClient<TKey> {
25
+ }
26
+ /**
27
+ * Generic API client for consuming any Cornerstone CrudController
28
+ *
29
+ * @export
30
+ * @class ApiCrudControllerClient
31
+ * @template TKey - Type of the entity key (e.g., number, string, GUID, etc.)
32
+ * @template TDto - Data Transfer Object representing the entity
33
+ */
34
+ export declare class ApiCrudControllerClient<TKey, TResultDto extends IIdentifiable<TKey>, TSingleResultDto extends IIdentifiable<TKey>, TInsertRequestDto, TUpdateRequestDto> extends ApiReadControllerClient<TKey, TResultDto, TSingleResultDto> implements IApiCrudControllerClient<TKey, TResultDto, TSingleResultDto, TInsertRequestDto, TUpdateRequestDto> {
35
+ /**
36
+ * Constructor
37
+ * @param baseControllerPath Base path to API controller
38
+ * @param httpService HTTP service implementation to use for requests
39
+ */
40
+ constructor(baseControllerPath: string, httpService?: IHttpService);
41
+ /**
42
+ * Creates a new entity.
43
+ * @param dto - Insert request DTO
44
+ * @param {AbortSignal} [signal] - Optional cancellation signal
45
+ * @returns The created entity DTO
46
+ */
47
+ create(dto: TInsertRequestDto, signal?: AbortSignal): Promise<ApiResponseDto<TSingleResultDto, EmptyMetadataDto>>;
48
+ /**
49
+ * Updates an existing entity.
50
+ * @param id - The ID of the entity to update
51
+ * @param dto - Update request DTO
52
+ * @param {AbortSignal} [signal] - Optional cancellation signal
53
+ * @returns The updated entity DTO
54
+ */
55
+ update(id: TKey, dto: TUpdateRequestDto, signal?: AbortSignal): Promise<ApiResponseDto<TSingleResultDto, EmptyMetadataDto>>;
56
+ /**
57
+ * Deletes an entity by ID.
58
+ * @param id - The ID of the entity to delete
59
+ * @param {AbortSignal} [signal] - Optional cancellation signal
60
+ */
61
+ delete(id: TKey, signal?: AbortSignal): Promise<ApiResponseDto<undefined, EmptyMetadataDto>>;
62
+ }
@@ -0,0 +1,34 @@
1
+ import { beforeEach, describe, expect, it } from 'vitest';
2
+ import { ApiCrudControllerClient } from '.';
3
+ import { FetchHttpService } from '..';
4
+ describe('ApiCrudControllerClient', () => {
5
+ let client;
6
+ let fetchService;
7
+ const testId = 100;
8
+ beforeEach(() => {
9
+ fetchService = new FetchHttpService();
10
+ client = new ApiCrudControllerClient('/VehiclesSlim', fetchService);
11
+ });
12
+ it('should use injected HTTP service for create', async () => {
13
+ const newVehicle = { id: testId, brand: 'New Brand', model: 'New Model' };
14
+ const result = (await client.create(newVehicle));
15
+ expect(result.ok).toBe(true);
16
+ expect(result.result).toBeDefined();
17
+ expect(result.result.id).toBe(newVehicle.id);
18
+ expect(result.result.brand).toBe(newVehicle.brand);
19
+ expect(result.result.model).toBe(newVehicle.model);
20
+ });
21
+ it('should use injected HTTP service for update', async () => {
22
+ const updateVehicle = { id: testId, brand: 'Updated Brand', model: 'Updated Model' };
23
+ const result = (await client.update(testId, updateVehicle));
24
+ expect(result.ok).toBe(true);
25
+ expect(result.result).toBeDefined();
26
+ expect(result.result.id).toBe(updateVehicle.id);
27
+ expect(result.result.brand).toBe(updateVehicle.brand);
28
+ expect(result.result.model).toBe(updateVehicle.model);
29
+ });
30
+ it('should use injected HTTP service for delete', async () => {
31
+ const result = await client.delete(testId);
32
+ expect(result.ok).toBe(true);
33
+ });
34
+ });
@@ -0,0 +1,133 @@
1
+ import { apiInitializationService, ApiReadControllerClient } from '../../services';
2
+ import { ErrorCode } from '../../data';
3
+ import { fail, ok } from '../../utils/result';
4
+ function isAbortError(err) {
5
+ return err instanceof DOMException && err.name === 'AbortError';
6
+ }
7
+ /**
8
+ * Generic API client for consuming any Cornerstone CrudController
9
+ *
10
+ * @export
11
+ * @class ApiCrudControllerClient
12
+ * @template TKey - Type of the entity key (e.g., number, string, GUID, etc.)
13
+ * @template TDto - Data Transfer Object representing the entity
14
+ */
15
+ export class ApiCrudControllerClient extends ApiReadControllerClient {
16
+ /**
17
+ * Constructor
18
+ * @param baseControllerPath Base path to API controller
19
+ * @param httpService HTTP service implementation to use for requests
20
+ */
21
+ constructor(baseControllerPath, httpService) {
22
+ super(baseControllerPath, httpService);
23
+ }
24
+ /**
25
+ * Creates a new entity.
26
+ * @param dto - Insert request DTO
27
+ * @param {AbortSignal} [signal] - Optional cancellation signal
28
+ * @returns The created entity DTO
29
+ */
30
+ async create(dto, signal) {
31
+ try {
32
+ const url = await apiInitializationService.getApiUrl(this.baseControllerPath, `/Create`);
33
+ const res = await this.httpService.request(url, {
34
+ method: 'POST',
35
+ headers: { 'Content-Type': 'application/json' },
36
+ body: JSON.stringify(dto),
37
+ credentials: 'include',
38
+ signal,
39
+ });
40
+ if (!res.ok) {
41
+ return fail(await res.json());
42
+ }
43
+ return ok(await res.json());
44
+ }
45
+ catch (err) {
46
+ if (isAbortError(err)) {
47
+ return fail({
48
+ error: { code: ErrorCode.Aborted, message: 'Request was aborted', metadata: {} },
49
+ });
50
+ }
51
+ console.error(err);
52
+ return fail({
53
+ error: {
54
+ code: ErrorCode.UnknownError,
55
+ message: 'Unknown error occurred while creating the record.',
56
+ metadata: {},
57
+ },
58
+ });
59
+ }
60
+ }
61
+ /**
62
+ * Updates an existing entity.
63
+ * @param id - The ID of the entity to update
64
+ * @param dto - Update request DTO
65
+ * @param {AbortSignal} [signal] - Optional cancellation signal
66
+ * @returns The updated entity DTO
67
+ */
68
+ async update(id, dto, signal) {
69
+ try {
70
+ const url = await apiInitializationService.getApiUrl(this.baseControllerPath, `/Update?id=${encodeURIComponent(String(id))}`);
71
+ const res = await this.httpService.request(url, {
72
+ method: 'PUT',
73
+ headers: { 'Content-Type': 'application/json' },
74
+ body: JSON.stringify(dto),
75
+ credentials: 'include',
76
+ signal,
77
+ });
78
+ if (!res.ok) {
79
+ return fail(await res.json());
80
+ }
81
+ return ok(await res.json());
82
+ }
83
+ catch (err) {
84
+ if (isAbortError(err)) {
85
+ return fail({
86
+ error: { code: ErrorCode.Aborted, message: 'Request was aborted', metadata: {} },
87
+ });
88
+ }
89
+ console.error(err);
90
+ return fail({
91
+ error: {
92
+ code: ErrorCode.UnknownError,
93
+ message: `Unknown error occurred while updating the record with id ${id}`,
94
+ metadata: {},
95
+ },
96
+ });
97
+ }
98
+ }
99
+ /**
100
+ * Deletes an entity by ID.
101
+ * @param id - The ID of the entity to delete
102
+ * @param {AbortSignal} [signal] - Optional cancellation signal
103
+ */
104
+ async delete(id, signal) {
105
+ try {
106
+ const url = await apiInitializationService.getApiUrl(this.baseControllerPath, `/Delete?id=${encodeURIComponent(String(id))}`);
107
+ const res = await this.httpService.request(url, {
108
+ method: 'DELETE',
109
+ credentials: 'include',
110
+ signal,
111
+ });
112
+ if (!res.ok) {
113
+ return fail(await res.json());
114
+ }
115
+ return ok(await res.json());
116
+ }
117
+ catch (err) {
118
+ if (isAbortError(err)) {
119
+ return fail({
120
+ error: { code: ErrorCode.Aborted, message: 'Request was aborted', metadata: {} },
121
+ });
122
+ }
123
+ console.error(err);
124
+ return fail({
125
+ error: {
126
+ code: ErrorCode.UnknownError,
127
+ message: `Unknown error occurred while deleting the record with id ${id}`,
128
+ metadata: {},
129
+ },
130
+ });
131
+ }
132
+ }
133
+ }
@@ -0,0 +1,106 @@
1
+ import { IHttpService } from '../../services';
2
+ /**
3
+ * Generic shared settings interface - can represent any user-configured settings structure
4
+ * The actual properties depend on what users configure in their appsettings.json or environment variables
5
+ */
6
+ type ISharedSettings = {
7
+ [key: string]: unknown;
8
+ };
9
+ /**
10
+ * Central API configuration service, fetches and exposes Cornerstone API configuration
11
+ *
12
+ * @export
13
+ * @class ApiInitializationService
14
+ */
15
+ export declare class ApiInitializationService {
16
+ /**
17
+ * If API base URL detection was completed
18
+ * IMPORTANT: This property is not meant to be used in normal cases - when ever possible use the .getApiUrl(relativeEndpointPath: string) method instead.
19
+ */
20
+ _apiBaseUrlDetected: boolean;
21
+ /**
22
+ * If API base URL detection was completed, this property will hold the method by which detection was performed
23
+ * IMPORTANT: This property is not meant to be used in normal cases - when ever possible use the .getApiUrl(relativeEndpointPath: string) method instead.
24
+ */
25
+ _apiBaseUrlDetectionMethod: string | undefined;
26
+ /**
27
+ * If API base URL detection was completed, this property will hold the detected API base URL
28
+ * IMPORTANT: This property is not meant to be used in normal cases - when ever possible use the .getApiUrl(relativeEndpointPath: string) method instead.
29
+ */
30
+ _apiBaseUrl: string | undefined;
31
+ /**
32
+ * If API base URL detection has failed, this property will hold the error with which it has failed
33
+ * IMPORTANT: This property is not meant to be used in normal cases - when ever possible use the .getApiUrl(relativeEndpointPath: string) method instead.
34
+ */
35
+ _apiBaseError: Error | undefined;
36
+ appConfig?: ISharedSettings | undefined;
37
+ private _httpService;
38
+ private _apiBaseUrlPromise;
39
+ /**
40
+ * Initializes the API configuration
41
+ *
42
+ * This method calls all methods that need to be called during the API configuration phase:
43
+ * - Starts detection of API base URL.
44
+ * - Fetches shared settings from the server.
45
+ *
46
+ * @async
47
+ * @param httpService - HTTP service implementation to use for requests
48
+ * @param {AbortSignal} [signal] - Optional cancellation signal
49
+ * @return {Promise<void>} Resolves when initialization is complete.
50
+ */
51
+ initialize({ httpService, signal, }?: {
52
+ httpService?: IHttpService;
53
+ signal?: AbortSignal;
54
+ }): Promise<void>;
55
+ /**
56
+ * Gets configured HTTP service
57
+ * @returns
58
+ */
59
+ _getHttpService(): IHttpService;
60
+ /**
61
+ * Tries detecting API base URL by multiple methods
62
+ *
63
+ * - Checks the response headers of the current URL for the `CORNERSTONE-API-BASEURL` header.
64
+ * - Attempts to load the `websettings.json` file and looks for an `api` field.
65
+ * - Defaults to `undefined`.
66
+ *
67
+ * IMPORTANT: This method is not meant to be used in normal cases - when ever possible use the .getApiUrl(relativeEndpointPath: string) method instead.
68
+ *
69
+ * @async
70
+ * @param {AbortSignal} [signal] - Optional cancellation signal
71
+ * @return {Promise<string | undefined>} Returns detected API base URL
72
+ * @throws {Error} Throws error if either of the detection methods fails
73
+ */
74
+ _getApiBaseUrl(signal?: AbortSignal): Promise<string | undefined>;
75
+ /**
76
+ * Composes a full API URL for a provided endpoint path.
77
+ *
78
+ * @async
79
+ * @param relativeEndpointPathSections Relative endpoint path sections
80
+ * @return {Promise<string | undefined>} Returns the API endpoint's URL
81
+ * @throws {Error} Throws error if API base URL detection fails
82
+ */
83
+ getApiUrl(...relativeEndpointPathSections: string[]): Promise<string>;
84
+ /**
85
+ * Removes starting '/' character
86
+ * @param str String to remove the starting '/' character from
87
+ * @returns String with starting '/' character removed
88
+ */
89
+ private removeStartsWithSlashChar;
90
+ /**
91
+ * Removes ending '/' character
92
+ * @param str String to remove the ending '/' character from
93
+ * @returns String with ending '/' character removed
94
+ */
95
+ private removeEndsWithSlashChar;
96
+ /**
97
+ * Fetches initialization info (shared settings) from the server
98
+ * @returns Promise that resolves to shared settings or undefined if the request fails
99
+ */
100
+ private _getAppConfig;
101
+ }
102
+ /**
103
+ * Singleton instance of ApiInitializationService
104
+ */
105
+ export declare const apiInitializationService: ApiInitializationService;
106
+ export {};
@@ -0,0 +1,207 @@
1
+ import { fail, ok } from '../../utils';
2
+ import { defaultHttpService } from '../../services';
3
+ /**
4
+ * Central API configuration service, fetches and exposes Cornerstone API configuration
5
+ *
6
+ * @export
7
+ * @class ApiInitializationService
8
+ */
9
+ export class ApiInitializationService {
10
+ /**
11
+ * If API base URL detection was completed
12
+ * IMPORTANT: This property is not meant to be used in normal cases - when ever possible use the .getApiUrl(relativeEndpointPath: string) method instead.
13
+ */
14
+ _apiBaseUrlDetected = false;
15
+ // #region HTTP service
16
+ /**
17
+ * If API base URL detection was completed, this property will hold the method by which detection was performed
18
+ * IMPORTANT: This property is not meant to be used in normal cases - when ever possible use the .getApiUrl(relativeEndpointPath: string) method instead.
19
+ */
20
+ _apiBaseUrlDetectionMethod = undefined;
21
+ /**
22
+ * If API base URL detection was completed, this property will hold the detected API base URL
23
+ * IMPORTANT: This property is not meant to be used in normal cases - when ever possible use the .getApiUrl(relativeEndpointPath: string) method instead.
24
+ */
25
+ _apiBaseUrl = undefined;
26
+ // #endregion
27
+ // #region API Base URL detection
28
+ /**
29
+ * If API base URL detection has failed, this property will hold the error with which it has failed
30
+ * IMPORTANT: This property is not meant to be used in normal cases - when ever possible use the .getApiUrl(relativeEndpointPath: string) method instead.
31
+ */
32
+ _apiBaseError = undefined;
33
+ // #region config App
34
+ appConfig;
35
+ _httpService = defaultHttpService;
36
+ _apiBaseUrlPromise = undefined;
37
+ /**
38
+ * Initializes the API configuration
39
+ *
40
+ * This method calls all methods that need to be called during the API configuration phase:
41
+ * - Starts detection of API base URL.
42
+ * - Fetches shared settings from the server.
43
+ *
44
+ * @async
45
+ * @param httpService - HTTP service implementation to use for requests
46
+ * @param {AbortSignal} [signal] - Optional cancellation signal
47
+ * @return {Promise<void>} Resolves when initialization is complete.
48
+ */
49
+ async initialize({ httpService, signal, } = {}) {
50
+ // Store configuration
51
+ if (httpService !== undefined)
52
+ this._httpService = httpService;
53
+ // (Pre)detect API base URL
54
+ await this._getApiBaseUrl(signal);
55
+ // Initialize app config
56
+ await this._getAppConfig();
57
+ }
58
+ /**
59
+ * Gets configured HTTP service
60
+ * @returns
61
+ */
62
+ _getHttpService() {
63
+ return this._httpService;
64
+ }
65
+ /**
66
+ * Tries detecting API base URL by multiple methods
67
+ *
68
+ * - Checks the response headers of the current URL for the `CORNERSTONE-API-BASEURL` header.
69
+ * - Attempts to load the `websettings.json` file and looks for an `api` field.
70
+ * - Defaults to `undefined`.
71
+ *
72
+ * IMPORTANT: This method is not meant to be used in normal cases - when ever possible use the .getApiUrl(relativeEndpointPath: string) method instead.
73
+ *
74
+ * @async
75
+ * @param {AbortSignal} [signal] - Optional cancellation signal
76
+ * @return {Promise<string | undefined>} Returns detected API base URL
77
+ * @throws {Error} Throws error if either of the detection methods fails
78
+ */
79
+ async _getApiBaseUrl(signal) {
80
+ // Check if API already detected; don't reattempt detection
81
+ if (this._apiBaseUrlDetected)
82
+ return this._apiBaseUrl;
83
+ // Check if detection already in progress; don't allow multiple detections in parallel
84
+ if (this._apiBaseUrlPromise)
85
+ return this._apiBaseUrlPromise;
86
+ // Detect API base URL
87
+ return (this._apiBaseUrlPromise = new Promise((resolve, reject) => (async () => {
88
+ // Reset
89
+ this._apiBaseUrlDetected = false;
90
+ this._apiBaseUrlDetectionMethod = undefined;
91
+ this._apiBaseUrl = undefined;
92
+ this._apiBaseError = undefined;
93
+ // Check CORNERSTONE-API-BASEURL header for API base URL
94
+ try {
95
+ const currentUrlResponse = await this._httpService.request(window.location.href, {
96
+ method: 'GET',
97
+ signal,
98
+ });
99
+ const apiHeader = currentUrlResponse.headers['CORNERSTONE-API-BASEURL'] || currentUrlResponse.headers['cornerstone-api-baseurl'] || null;
100
+ if (apiHeader) {
101
+ this._apiBaseUrlDetected = true;
102
+ this._apiBaseUrlDetectionMethod = 'GET / Header:CORNERSTONE-API-BASEURL';
103
+ this._apiBaseUrl = apiHeader;
104
+ this._apiBaseError = undefined;
105
+ this._apiBaseUrlPromise = undefined;
106
+ return resolve(this._apiBaseUrl);
107
+ }
108
+ }
109
+ catch (err) {
110
+ this._apiBaseError = err instanceof Error ? err : new Error('Failed loading API base URL from response header!');
111
+ }
112
+ // Check ./websettings.json header for API base URL
113
+ try {
114
+ const webSettingsResponse = await this._httpService.request('./websettings.json', {
115
+ method: 'GET',
116
+ signal,
117
+ });
118
+ if (webSettingsResponse.status === 404)
119
+ return (this._apiBaseUrl = undefined);
120
+ const webSettings = await webSettingsResponse.json();
121
+ if (webSettings?.api) {
122
+ this._apiBaseUrlDetected = true;
123
+ this._apiBaseUrlDetectionMethod = 'GET websettings.json';
124
+ this._apiBaseUrl = webSettings.api;
125
+ this._apiBaseError = undefined;
126
+ this._apiBaseUrlPromise = undefined;
127
+ return resolve(this._apiBaseUrl);
128
+ }
129
+ }
130
+ catch (err) {
131
+ this._apiBaseError = err instanceof Error ? err : new Error('Failed loading API base URL from settings file!');
132
+ }
133
+ // Check if error caught during any of the detection methods
134
+ if (this._apiBaseError !== undefined) {
135
+ this._apiBaseUrlDetected = false;
136
+ this._apiBaseUrlDetectionMethod = undefined;
137
+ this._apiBaseUrl = undefined;
138
+ this._apiBaseUrlPromise = undefined;
139
+ return reject(this._apiBaseError);
140
+ }
141
+ // Default to no API found
142
+ this._apiBaseUrlDetected = true;
143
+ this._apiBaseUrlDetectionMethod = undefined;
144
+ this._apiBaseUrl = undefined;
145
+ this._apiBaseError = undefined;
146
+ this._apiBaseUrlPromise = undefined;
147
+ return resolve(this._apiBaseUrl);
148
+ })()));
149
+ }
150
+ /**
151
+ * Composes a full API URL for a provided endpoint path.
152
+ *
153
+ * @async
154
+ * @param relativeEndpointPathSections Relative endpoint path sections
155
+ * @return {Promise<string | undefined>} Returns the API endpoint's URL
156
+ * @throws {Error} Throws error if API base URL detection fails
157
+ */
158
+ async getApiUrl(...relativeEndpointPathSections) {
159
+ const apiBaseUrl = await this._getApiBaseUrl();
160
+ const domain = !apiBaseUrl ? '/' : `${this.removeEndsWithSlashChar(apiBaseUrl)}/`;
161
+ const path = relativeEndpointPathSections.map(section => this.removeStartsWithSlashChar(this.removeEndsWithSlashChar(section))).join('/');
162
+ return `${domain}${path}`;
163
+ }
164
+ /**
165
+ * Removes starting '/' character
166
+ * @param str String to remove the starting '/' character from
167
+ * @returns String with starting '/' character removed
168
+ */
169
+ removeStartsWithSlashChar(str) {
170
+ return !str.startsWith('/') ? str : str.substring(1);
171
+ }
172
+ // #endregion
173
+ /**
174
+ * Removes ending '/' character
175
+ * @param str String to remove the ending '/' character from
176
+ * @returns String with ending '/' character removed
177
+ */
178
+ removeEndsWithSlashChar(str) {
179
+ return !str.endsWith('/') ? str : str.substring(0, str.length - 1);
180
+ }
181
+ /**
182
+ * Fetches initialization info (shared settings) from the server
183
+ * @returns Promise that resolves to shared settings or undefined if the request fails
184
+ */
185
+ async _getAppConfig() {
186
+ try {
187
+ const response = await fetch(`${this._apiBaseUrl}/system/init`, { credentials: 'include' });
188
+ if (!response.ok) {
189
+ throw fail(await response.json());
190
+ }
191
+ const apiResponse = ok(await response.json());
192
+ if (!apiResponse.ok) {
193
+ throw apiResponse.error;
194
+ }
195
+ // Return the settings from the nested structure
196
+ this.appConfig = apiResponse.result.appSettings;
197
+ }
198
+ catch (error) {
199
+ console.error('Failed to get app config', error);
200
+ this.appConfig = undefined;
201
+ }
202
+ }
203
+ }
204
+ /**
205
+ * Singleton instance of ApiInitializationService
206
+ */
207
+ export const apiInitializationService = new ApiInitializationService();