@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,291 @@
1
+ import { ApiCrudControllerClient, apiInitializationService } from '../../services';
2
+ import { ErrorCode } from '../../data';
3
+ import { fail, ok } from '../../utils/result';
4
+ /**
5
+ * Client for user management operations
6
+ *
7
+ * @export
8
+ * @class UserManagementControllerClient
9
+ * @template TKey - Type of the entity key (e.g., number, string, GUID, etc.)
10
+ * @template TUser - Data Transfer Object representing the user entity
11
+ */
12
+ export class UserManagementControllerClient extends ApiCrudControllerClient {
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) {
19
+ super(baseControllerPath, httpService);
20
+ }
21
+ /**
22
+ * Gets the roles assigned to a user
23
+ * @param id - The ID of the user
24
+ * @param {AbortSignal} [signal] - Optional cancellation signal
25
+ * @returns List of role names assigned to the user
26
+ */
27
+ async getUserRoles(id, signal) {
28
+ try {
29
+ const url = await apiInitializationService.getApiUrl(this.baseControllerPath, 'GetUserRoles', encodeURIComponent(String(id)));
30
+ const res = await this.httpService.request(url, {
31
+ method: 'GET',
32
+ credentials: 'include',
33
+ signal,
34
+ });
35
+ if (!res.ok) {
36
+ return fail(await res.json());
37
+ }
38
+ return ok(await res.json());
39
+ }
40
+ catch (err) {
41
+ console.error(err);
42
+ return fail({
43
+ error: {
44
+ code: ErrorCode.UnknownError,
45
+ message: 'Unknown error while fetching user roles',
46
+ metadata: {},
47
+ },
48
+ });
49
+ }
50
+ }
51
+ /**
52
+ * Gets the claims assigned to a user
53
+ * @param id - The ID of the user
54
+ * @param {AbortSignal} [signal] - Optional cancellation signal
55
+ * @returns List of claims assigned to the user
56
+ */
57
+ async getUserClaims(id, signal) {
58
+ try {
59
+ const url = await apiInitializationService.getApiUrl(this.baseControllerPath, 'GetUserClaims', encodeURIComponent(String(id)));
60
+ const res = await this.httpService.request(url, {
61
+ method: 'GET',
62
+ credentials: 'include',
63
+ signal,
64
+ });
65
+ if (!res.ok) {
66
+ return fail(await res.json());
67
+ }
68
+ return ok(await res.json());
69
+ }
70
+ catch (err) {
71
+ console.error(err);
72
+ return fail({
73
+ error: {
74
+ code: ErrorCode.UnknownError,
75
+ message: 'Unknown error while fetching user claims',
76
+ metadata: {},
77
+ },
78
+ });
79
+ }
80
+ }
81
+ /**
82
+ * Sets the roles for a user, replacing all existing roles
83
+ * @param id - The ID of the user
84
+ * @param roles - The list of role names to set
85
+ * @param {AbortSignal} [signal] - Optional cancellation signal
86
+ * @returns Promise that resolves when the roles are set successfully
87
+ */
88
+ async setUserRoles(id, roles, signal) {
89
+ try {
90
+ const url = await apiInitializationService.getApiUrl(this.baseControllerPath, 'SetUserRoles', encodeURIComponent(String(id)), 'roles');
91
+ const res = await this.httpService.request(url, {
92
+ method: 'PUT',
93
+ headers: {
94
+ 'Content-Type': 'application/json',
95
+ },
96
+ body: JSON.stringify(roles),
97
+ credentials: 'include',
98
+ signal,
99
+ });
100
+ if (!res.ok) {
101
+ return fail(await res.json());
102
+ }
103
+ return ok(undefined);
104
+ }
105
+ catch (err) {
106
+ console.error(err);
107
+ return fail({
108
+ error: {
109
+ code: ErrorCode.UnknownError,
110
+ message: 'Unknown error while setting user roles',
111
+ metadata: {},
112
+ },
113
+ });
114
+ }
115
+ }
116
+ /**
117
+ * Adds roles to a user
118
+ * @param id - The ID of the user
119
+ * @param roles - The list of role names to add
120
+ * @param {AbortSignal} [signal] - Optional cancellation signal
121
+ * @returns Promise that resolves when the roles are added successfully
122
+ */
123
+ async addRolesToUser(id, roles, signal) {
124
+ try {
125
+ const url = await apiInitializationService.getApiUrl(this.baseControllerPath, 'AddRolesToUser', encodeURIComponent(String(id)), 'roles', 'add');
126
+ const res = await this.httpService.request(url, {
127
+ method: 'POST',
128
+ headers: {
129
+ 'Content-Type': 'application/json',
130
+ },
131
+ body: JSON.stringify(roles),
132
+ credentials: 'include',
133
+ signal,
134
+ });
135
+ if (!res.ok) {
136
+ return fail(await res.json());
137
+ }
138
+ return ok(undefined);
139
+ }
140
+ catch (err) {
141
+ console.error(err);
142
+ return fail({
143
+ error: {
144
+ code: ErrorCode.UnknownError,
145
+ message: 'Unknown error while adding roles to user',
146
+ metadata: {},
147
+ },
148
+ });
149
+ }
150
+ }
151
+ /**
152
+ * Removes roles from a user
153
+ * @param id - The ID of the user
154
+ * @param roles - The list of role names to remove
155
+ * @param {AbortSignal} [signal] - Optional cancellation signal
156
+ * @returns Promise that resolves when the roles are removed successfully
157
+ */
158
+ async removeRolesFromUser(id, roles, signal) {
159
+ try {
160
+ const url = await apiInitializationService.getApiUrl(this.baseControllerPath, 'RemoveRolesFromUser', encodeURIComponent(String(id)), 'roles', 'remove');
161
+ const res = await this.httpService.request(url, {
162
+ method: 'POST',
163
+ headers: {
164
+ 'Content-Type': 'application/json',
165
+ },
166
+ body: JSON.stringify(roles),
167
+ credentials: 'include',
168
+ signal,
169
+ });
170
+ if (!res.ok) {
171
+ return fail(await res.json());
172
+ }
173
+ return ok(undefined);
174
+ }
175
+ catch (err) {
176
+ console.error(err);
177
+ return fail({
178
+ error: {
179
+ code: ErrorCode.UnknownError,
180
+ message: 'Unknown error while removing roles from user',
181
+ metadata: {},
182
+ },
183
+ });
184
+ }
185
+ }
186
+ /**
187
+ * Adds claims to a user
188
+ * @param id - The ID of the user
189
+ * @param claims - The list of claims to add
190
+ * @param {AbortSignal} [signal] - Optional cancellation signal
191
+ * @returns Promise that resolves when the claims are added successfully
192
+ */
193
+ async addUserClaims(id, claims, signal) {
194
+ try {
195
+ const url = await apiInitializationService.getApiUrl(this.baseControllerPath, 'AddUserClaims', encodeURIComponent(String(id)), 'claims', 'add');
196
+ const res = await this.httpService.request(url, {
197
+ method: 'POST',
198
+ headers: {
199
+ 'Content-Type': 'application/json',
200
+ },
201
+ body: JSON.stringify(claims),
202
+ credentials: 'include',
203
+ signal,
204
+ });
205
+ if (!res.ok) {
206
+ return fail(await res.json());
207
+ }
208
+ return ok(undefined);
209
+ }
210
+ catch (err) {
211
+ console.error(err);
212
+ return fail({
213
+ error: {
214
+ code: ErrorCode.UnknownError,
215
+ message: 'Unknown error while adding user claims',
216
+ metadata: {},
217
+ },
218
+ });
219
+ }
220
+ }
221
+ /**
222
+ * Removes claims from a user
223
+ * @param id - The ID of the user
224
+ * @param claims - The list of claims to remove
225
+ * @param {AbortSignal} [signal] - Optional cancellation signal
226
+ * @returns Promise that resolves when the claims are removed successfully
227
+ */
228
+ async removeUserClaims(id, claims, signal) {
229
+ try {
230
+ const url = await apiInitializationService.getApiUrl(this.baseControllerPath, 'RemoveUserClaims', encodeURIComponent(String(id)), 'claims', 'remove');
231
+ const res = await this.httpService.request(url, {
232
+ method: 'POST',
233
+ headers: {
234
+ 'Content-Type': 'application/json',
235
+ },
236
+ body: JSON.stringify(claims),
237
+ credentials: 'include',
238
+ signal,
239
+ });
240
+ if (!res.ok) {
241
+ return fail(await res.json());
242
+ }
243
+ return ok(undefined);
244
+ }
245
+ catch (err) {
246
+ console.error(err);
247
+ return fail({
248
+ error: {
249
+ code: ErrorCode.UnknownError,
250
+ message: 'Unknown error while removing user claims',
251
+ metadata: {},
252
+ },
253
+ });
254
+ }
255
+ }
256
+ /**
257
+ * Changes the password for a user
258
+ * @param id - The ID of the user
259
+ * @param newPassword - The new password to set
260
+ * @param {AbortSignal} [signal] - Optional cancellation signal
261
+ * @returns Promise that resolves when the password is changed successfully
262
+ */
263
+ async changePassword(id, newPassword, signal) {
264
+ try {
265
+ const url = await apiInitializationService.getApiUrl(this.baseControllerPath, 'ChangePassword', encodeURIComponent(String(id)));
266
+ const res = await this.httpService.request(url, {
267
+ method: 'POST',
268
+ headers: {
269
+ 'Content-Type': 'application/json',
270
+ },
271
+ body: JSON.stringify(newPassword),
272
+ credentials: 'include',
273
+ signal,
274
+ });
275
+ if (!res.ok) {
276
+ return fail(await res.json());
277
+ }
278
+ return ok(undefined);
279
+ }
280
+ catch (err) {
281
+ console.error(err);
282
+ return fail({
283
+ error: {
284
+ code: ErrorCode.UnknownError,
285
+ message: 'Unknown error while changing password',
286
+ metadata: {},
287
+ },
288
+ });
289
+ }
290
+ }
291
+ }
@@ -0,0 +1,75 @@
1
+ import { IHttpService } from '../..';
2
+ import { ApiResponseDto, EmptyMetadataDto, UserDto, UserInfoDto, RegisterRequestDto } from '../../../data';
3
+ export { UserDto, UserInfoDto };
4
+ /**
5
+ * AuthService class is responsible for managing user authentication operations.
6
+ * It supports login, logout, and checking the current user's details.
7
+ *
8
+ * @export
9
+ * @class AuthService
10
+ */
11
+ export declare class AuthService<TKey, TRegisterUser extends RegisterRequestDto = RegisterRequestDto, TUser extends UserDto<TKey> = UserDto<TKey>> {
12
+ protected readonly baseControllerPath: string;
13
+ /**
14
+ * Constructor
15
+ * @param baseControllerPath Base path to Auth API controller
16
+ * @param httpService HTTP service implementation to use for requests
17
+ */
18
+ constructor(baseControllerPath?: string, httpService?: IHttpService);
19
+ private readonly _httpService?;
20
+ /**
21
+ * Gets globally selected HTTP service
22
+ */
23
+ protected get httpService(): IHttpService;
24
+ /**
25
+ * Holds currently authenticated user's details
26
+ */
27
+ user: TUser | undefined;
28
+ /**
29
+ * Initializes the Authentication status by checking with the API if the current user is authenticated or not
30
+ *
31
+ * @async
32
+ * @return {Promise<void>} Resolves when initialization is complete.
33
+ */
34
+ initialize(): Promise<void>;
35
+ /**
36
+ * Checks if user is authenticated and retrieves the current user's details if they are
37
+ *
38
+ * @return {Promise<UserInfoDto<TKey, TUser>>} Currently logged in user's details
39
+ * @throws {Error} Error if fetch fails
40
+ */
41
+ whoAmI(): Promise<ApiResponseDto<UserInfoDto<TKey, TUser>, EmptyMetadataDto>>;
42
+ /**
43
+ * Authenticates a user using their username and password, and retrieves user's details
44
+ *
45
+ * @param {string} username Login credentials: username
46
+ * @param {string} password Login credentials: password
47
+ * @return {Promise<TUser>} Currently logged in user's details
48
+ * @throws {Error} Error if fetch fails
49
+ */
50
+ signIn(username: string, password: string): Promise<ApiResponseDto<TUser, EmptyMetadataDto>>;
51
+ /**
52
+ * Deauthenticates current user
53
+ *
54
+ * @return {Promise<void>}
55
+ * @throws {Error} Error if fetch fails
56
+ */
57
+ signOut(): Promise<ApiResponseDto<undefined, EmptyMetadataDto>>;
58
+ /**
59
+ * Registers a new user by sending user details to the API.
60
+ *
61
+ * @param {TRegisterUser} user User object containing registration data (e.g. username, password, and optionally firstName, lastName, etc.)
62
+ * @return {Promise<ApiResponseDto<TUser, EmptyMetadataDto>>} API response with registered user details or error info
63
+ * @throws {Error} Error if the request fails
64
+ */
65
+ register(user: TRegisterUser): Promise<ApiResponseDto<TUser, EmptyMetadataDto>>;
66
+ /**
67
+ * If any API response returns an "Unauthenticated" response, call this method
68
+ * to update local authentication state to unauthenticated
69
+ */
70
+ handleNoAuthApiResponse(): void;
71
+ /**
72
+ * True if a user is currently loaded (post whoAmI/signIn)
73
+ */
74
+ isAuthenticated(): boolean;
75
+ }
@@ -0,0 +1,200 @@
1
+ import { apiInitializationService } from '../..';
2
+ import { ErrorCode } from '../../../data';
3
+ import { fail, ok } from '../../../utils';
4
+ /**
5
+ * AuthService class is responsible for managing user authentication operations.
6
+ * It supports login, logout, and checking the current user's details.
7
+ *
8
+ * @export
9
+ * @class AuthService
10
+ */
11
+ export class AuthService {
12
+ baseControllerPath;
13
+ /**
14
+ * Constructor
15
+ * @param baseControllerPath Base path to Auth API controller
16
+ * @param httpService HTTP service implementation to use for requests
17
+ */
18
+ constructor(baseControllerPath = 'Auth', httpService) {
19
+ this.baseControllerPath = baseControllerPath;
20
+ this._httpService = httpService;
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
+ /**
32
+ * Holds currently authenticated user's details
33
+ */
34
+ user = undefined;
35
+ /**
36
+ * Initializes the Authentication status by checking with the API if the current user is authenticated or not
37
+ *
38
+ * @async
39
+ * @return {Promise<void>} Resolves when initialization is complete.
40
+ */
41
+ async initialize() {
42
+ // Check user's authentication status
43
+ await this.whoAmI();
44
+ }
45
+ /**
46
+ * Checks if user is authenticated and retrieves the current user's details if they are
47
+ *
48
+ * @return {Promise<UserInfoDto<TKey, TUser>>} Currently logged in user's details
49
+ * @throws {Error} Error if fetch fails
50
+ */
51
+ async whoAmI() {
52
+ try {
53
+ const url = await apiInitializationService.getApiUrl(this.baseControllerPath, '/whoami');
54
+ const res = await this.httpService.request(url, { credentials: 'include' });
55
+ if (!res.ok) {
56
+ this.user = undefined;
57
+ return fail(await res.json());
58
+ }
59
+ const response = ok(await res.json());
60
+ if (!response.ok) {
61
+ this.user = undefined;
62
+ return response;
63
+ }
64
+ this.user = response.result.user;
65
+ return response;
66
+ }
67
+ catch (err) {
68
+ console.error(err);
69
+ return fail({
70
+ error: {
71
+ code: ErrorCode.UnknownError,
72
+ message: 'Failed checking authentication status',
73
+ metadata: {},
74
+ },
75
+ });
76
+ }
77
+ }
78
+ /**
79
+ * Authenticates a user using their username and password, and retrieves user's details
80
+ *
81
+ * @param {string} username Login credentials: username
82
+ * @param {string} password Login credentials: password
83
+ * @return {Promise<TUser>} Currently logged in user's details
84
+ * @throws {Error} Error if fetch fails
85
+ */
86
+ async signIn(username, password) {
87
+ try {
88
+ const url = await apiInitializationService.getApiUrl(this.baseControllerPath, '/signin');
89
+ const res = await this.httpService.request(url, {
90
+ method: 'POST',
91
+ headers: { 'Content-Type': 'application/json' },
92
+ body: JSON.stringify({ username, password }),
93
+ credentials: 'include',
94
+ });
95
+ if (!res.ok) {
96
+ return fail(await res.json());
97
+ }
98
+ // TODO: Handle tokens if not using cookies
99
+ const whoAmIRes = await this.whoAmI();
100
+ if (!whoAmIRes.ok) {
101
+ return whoAmIRes;
102
+ }
103
+ return ok({
104
+ result: whoAmIRes.result.user,
105
+ metadata: whoAmIRes.metadata,
106
+ });
107
+ }
108
+ catch (err) {
109
+ console.error(err);
110
+ return fail({
111
+ error: {
112
+ code: ErrorCode.UnknownError,
113
+ message: 'Failed signing in',
114
+ metadata: {},
115
+ },
116
+ });
117
+ }
118
+ }
119
+ /**
120
+ * Deauthenticates current user
121
+ *
122
+ * @return {Promise<void>}
123
+ * @throws {Error} Error if fetch fails
124
+ */
125
+ async signOut() {
126
+ try {
127
+ const url = await apiInitializationService.getApiUrl(this.baseControllerPath, '/signout');
128
+ const res = await this.httpService.request(url, { credentials: 'include' });
129
+ if (!res.ok) {
130
+ return fail(await res.json());
131
+ }
132
+ this.user = undefined;
133
+ return ok(await res.json());
134
+ }
135
+ catch (err) {
136
+ console.error(err);
137
+ return fail({
138
+ error: {
139
+ code: ErrorCode.UnknownError,
140
+ message: 'Failed signing out',
141
+ metadata: {},
142
+ },
143
+ });
144
+ }
145
+ }
146
+ /**
147
+ * Registers a new user by sending user details to the API.
148
+ *
149
+ * @param {TRegisterUser} user User object containing registration data (e.g. username, password, and optionally firstName, lastName, etc.)
150
+ * @return {Promise<ApiResponseDto<TUser, EmptyMetadataDto>>} API response with registered user details or error info
151
+ * @throws {Error} Error if the request fails
152
+ */
153
+ async register(user) {
154
+ try {
155
+ const url = await apiInitializationService.getApiUrl(this.baseControllerPath, '/register');
156
+ const res = await this.httpService.request(url, {
157
+ method: 'POST',
158
+ headers: { 'Content-Type': 'application/json' },
159
+ body: JSON.stringify(user),
160
+ credentials: 'include',
161
+ });
162
+ if (!res.ok) {
163
+ return fail(await res.json());
164
+ }
165
+ // TODO: Handle tokens if not using cookies
166
+ const whoAmIRes = await this.whoAmI();
167
+ if (!whoAmIRes.ok) {
168
+ return whoAmIRes;
169
+ }
170
+ return ok({
171
+ result: whoAmIRes.result.user,
172
+ metadata: whoAmIRes.metadata,
173
+ });
174
+ }
175
+ catch (err) {
176
+ console.error(err);
177
+ return fail({
178
+ error: {
179
+ code: ErrorCode.UnknownError,
180
+ message: 'Failed registering user',
181
+ metadata: {},
182
+ },
183
+ });
184
+ }
185
+ }
186
+ /**
187
+ * If any API response returns an "Unauthenticated" response, call this method
188
+ * to update local authentication state to unauthenticated
189
+ */
190
+ handleNoAuthApiResponse() {
191
+ this.user = undefined;
192
+ }
193
+ // #region Client-side authorization helpers
194
+ /**
195
+ * True if a user is currently loaded (post whoAmI/signIn)
196
+ */
197
+ isAuthenticated() {
198
+ return !!this.user;
199
+ }
200
+ }
@@ -0,0 +1,48 @@
1
+ import { IHttpService } from '../..';
2
+ import { ApiResponseDto, EmptyMetadataDto, ReadMetadataDto, RoleDto } from '../../../data';
3
+ /**
4
+ * Client for authorization management operations
5
+ *
6
+ * @export
7
+ * @class AuthorizationManagementControllerClient
8
+ */
9
+ export declare class AuthorizationManagementControllerClient {
10
+ protected readonly baseControllerPath: string;
11
+ /**
12
+ * Constructor
13
+ * @param baseControllerPath Base path to API controller
14
+ * @param httpService HTTP service implementation to use for requests
15
+ */
16
+ constructor(baseControllerPath?: string, httpService?: IHttpService);
17
+ private readonly _httpService?;
18
+ /**
19
+ * Gets globally selected HTTP service
20
+ */
21
+ protected get httpService(): IHttpService;
22
+ /**
23
+ * Gets all roles in the system
24
+ * @param includeClaims - Whether to include claims in the response
25
+ * @param signal - Optional cancellation signal
26
+ * @returns List of all roles
27
+ */
28
+ getAllRoles(includeClaims: boolean, signal?: AbortSignal): Promise<ApiResponseDto<RoleDto[], ReadMetadataDto>>;
29
+ /**
30
+ * Gets a role with its claims
31
+ * @param roleName - The name of the role
32
+ * @param signal
33
+ * @returns The role with its claims
34
+ */
35
+ getRoleWithClaims(roleName: string, signal?: AbortSignal): Promise<ApiResponseDto<RoleDto, ReadMetadataDto>>;
36
+ /**
37
+ * Creates or updates a role
38
+ * @param roleDto - The role to create or update
39
+ * @returns The created or updated role
40
+ */
41
+ upsertRole(roleDto: RoleDto): Promise<ApiResponseDto<RoleDto, EmptyMetadataDto>>;
42
+ /**
43
+ * Deletes a role
44
+ * @param roleName - The name of the role to delete
45
+ * @returns Promise that resolves when the role is deleted successfully
46
+ */
47
+ deleteRole(roleName: string): Promise<ApiResponseDto<undefined, EmptyMetadataDto>>;
48
+ }