@api-client/core 0.12.12 → 0.12.14

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 (177) hide show
  1. package/build/src/browser.d.ts +3 -3
  2. package/build/src/browser.d.ts.map +1 -1
  3. package/build/src/browser.js +2 -2
  4. package/build/src/browser.js.map +1 -1
  5. package/build/src/index.d.ts +3 -3
  6. package/build/src/index.d.ts.map +1 -1
  7. package/build/src/index.js +2 -2
  8. package/build/src/index.js.map +1 -1
  9. package/build/src/mocking/lib/User.d.ts +2 -0
  10. package/build/src/mocking/lib/User.d.ts.map +1 -1
  11. package/build/src/mocking/lib/User.js +6 -0
  12. package/build/src/mocking/lib/User.js.map +1 -1
  13. package/build/src/models/store/User.d.ts +23 -2
  14. package/build/src/models/store/User.d.ts.map +1 -1
  15. package/build/src/models/store/User.js.map +1 -1
  16. package/build/src/proxy/HttpProjectProxy.js +1 -1
  17. package/build/src/proxy/HttpProjectProxy.js.map +1 -1
  18. package/build/src/sdk/AuthSdk.d.ts.map +1 -0
  19. package/build/src/sdk/AuthSdk.js.map +1 -0
  20. package/build/src/{runtime/store → sdk}/DataCatalogSdk.d.ts +5 -5
  21. package/build/src/sdk/DataCatalogSdk.d.ts.map +1 -0
  22. package/build/src/{runtime/store → sdk}/DataCatalogSdk.js +2 -2
  23. package/build/src/sdk/DataCatalogSdk.js.map +1 -0
  24. package/build/src/{runtime/store → sdk}/FilesSdk.d.ts +7 -7
  25. package/build/src/sdk/FilesSdk.d.ts.map +1 -0
  26. package/build/src/{runtime/store → sdk}/FilesSdk.js +2 -2
  27. package/build/src/sdk/FilesSdk.js.map +1 -0
  28. package/build/src/{runtime/store → sdk}/HistorySdk.d.ts +2 -2
  29. package/build/src/sdk/HistorySdk.d.ts.map +1 -0
  30. package/build/src/{runtime/store → sdk}/HistorySdk.js +2 -2
  31. package/build/src/sdk/HistorySdk.js.map +1 -0
  32. package/build/src/sdk/Http.d.ts.map +1 -0
  33. package/build/src/sdk/Http.js.map +1 -0
  34. package/build/src/sdk/HttpNode.d.ts.map +1 -0
  35. package/build/src/{runtime/store → sdk}/HttpNode.js +1 -2
  36. package/build/src/sdk/HttpNode.js.map +1 -0
  37. package/build/src/{runtime/store → sdk}/HttpWeb.d.ts +1 -1
  38. package/build/src/sdk/HttpWeb.d.ts.map +1 -0
  39. package/build/src/{runtime/store → sdk}/HttpWeb.js +1 -1
  40. package/build/src/sdk/HttpWeb.js.map +1 -0
  41. package/build/src/sdk/OrganizationsSdk.d.ts +125 -0
  42. package/build/src/sdk/OrganizationsSdk.d.ts.map +1 -0
  43. package/build/src/sdk/OrganizationsSdk.js +457 -0
  44. package/build/src/sdk/OrganizationsSdk.js.map +1 -0
  45. package/build/src/{runtime/store → sdk}/ProjectExecutionsSdk.d.ts +2 -2
  46. package/build/src/sdk/ProjectExecutionsSdk.d.ts.map +1 -0
  47. package/build/src/{runtime/store → sdk}/ProjectExecutionsSdk.js +1 -1
  48. package/build/src/sdk/ProjectExecutionsSdk.js.map +1 -0
  49. package/build/src/{runtime/store → sdk}/RevisionsSdk.d.ts +2 -2
  50. package/build/src/sdk/RevisionsSdk.d.ts.map +1 -0
  51. package/build/src/{runtime/store → sdk}/RevisionsSdk.js +1 -1
  52. package/build/src/sdk/RevisionsSdk.js.map +1 -0
  53. package/build/src/{runtime/store → sdk}/RouteBuilder.d.ts +3 -0
  54. package/build/src/sdk/RouteBuilder.d.ts.map +1 -0
  55. package/build/src/{runtime/store → sdk}/RouteBuilder.js +9 -0
  56. package/build/src/sdk/RouteBuilder.js.map +1 -0
  57. package/build/src/{runtime/store → sdk}/Sdk.d.ts +1 -1
  58. package/build/src/sdk/Sdk.d.ts.map +1 -0
  59. package/build/src/sdk/Sdk.js.map +1 -0
  60. package/build/src/{runtime/store → sdk}/SdkBase.d.ts +3 -3
  61. package/build/src/sdk/SdkBase.d.ts.map +1 -0
  62. package/build/src/{runtime/store → sdk}/SdkBase.js +1 -1
  63. package/build/src/sdk/SdkBase.js.map +1 -0
  64. package/build/src/{runtime/store → sdk}/SharedSdk.d.ts +2 -2
  65. package/build/src/sdk/SharedSdk.d.ts.map +1 -0
  66. package/build/src/{runtime/store → sdk}/SharedSdk.js +1 -1
  67. package/build/src/sdk/SharedSdk.js.map +1 -0
  68. package/build/src/sdk/StoreSdkNode.d.ts.map +1 -0
  69. package/build/src/sdk/StoreSdkNode.js.map +1 -0
  70. package/build/src/sdk/StoreSdkWeb.d.ts.map +1 -0
  71. package/build/src/sdk/StoreSdkWeb.js.map +1 -0
  72. package/build/src/{runtime/store → sdk}/TrashSdk.d.ts +2 -2
  73. package/build/src/sdk/TrashSdk.d.ts.map +1 -0
  74. package/build/src/{runtime/store → sdk}/TrashSdk.js +1 -1
  75. package/build/src/sdk/TrashSdk.js.map +1 -0
  76. package/build/src/{runtime/store → sdk}/UsersSdk.d.ts +1 -21
  77. package/build/src/sdk/UsersSdk.d.ts.map +1 -0
  78. package/build/src/sdk/UsersSdk.js +35 -0
  79. package/build/src/sdk/UsersSdk.js.map +1 -0
  80. package/build/src/sdk/WsClient.d.ts.map +1 -0
  81. package/build/src/sdk/WsClient.js.map +1 -0
  82. package/build/src/sdk/WsClientNode.d.ts.map +1 -0
  83. package/build/src/sdk/WsClientNode.js.map +1 -0
  84. package/build/src/sdk/WsClientWeb.d.ts.map +1 -0
  85. package/build/src/sdk/WsClientWeb.js.map +1 -0
  86. package/data/models/example-generator-api.json +14 -14
  87. package/package.json +3 -1
  88. package/src/mocking/lib/User.ts +6 -0
  89. package/src/models/store/User.ts +23 -2
  90. package/src/proxy/HttpProjectProxy.ts +1 -1
  91. package/src/{runtime/store → sdk}/DataCatalogSdk.ts +7 -7
  92. package/src/{runtime/store → sdk}/FilesSdk.ts +8 -8
  93. package/src/{runtime/store → sdk}/HistorySdk.ts +3 -3
  94. package/src/{runtime/store → sdk}/HttpNode.ts +1 -2
  95. package/src/{runtime/store → sdk}/HttpWeb.ts +2 -2
  96. package/src/sdk/OrganizationsSdk.ts +479 -0
  97. package/src/{runtime/store → sdk}/ProjectExecutionsSdk.ts +2 -2
  98. package/src/{runtime/store → sdk}/RevisionsSdk.ts +3 -3
  99. package/src/{runtime/store → sdk}/RouteBuilder.ts +12 -0
  100. package/src/{runtime/store → sdk}/Sdk.ts +1 -1
  101. package/src/{runtime/store → sdk}/SdkBase.ts +3 -3
  102. package/src/{runtime/store → sdk}/SharedSdk.ts +3 -3
  103. package/src/{runtime/store → sdk}/TrashSdk.ts +3 -3
  104. package/src/sdk/UsersSdk.ts +112 -0
  105. package/tests/unit/mocking/current/User.spec.ts +1 -1
  106. package/tests/unit/models/File/setDeleted.spec.ts +6 -0
  107. package/tests/unit/models/File/setLastModified.spec.ts +6 -0
  108. package/build/src/runtime/store/AuthSdk.d.ts.map +0 -1
  109. package/build/src/runtime/store/AuthSdk.js.map +0 -1
  110. package/build/src/runtime/store/DataCatalogSdk.d.ts.map +0 -1
  111. package/build/src/runtime/store/DataCatalogSdk.js.map +0 -1
  112. package/build/src/runtime/store/FilesSdk.d.ts.map +0 -1
  113. package/build/src/runtime/store/FilesSdk.js.map +0 -1
  114. package/build/src/runtime/store/HistorySdk.d.ts.map +0 -1
  115. package/build/src/runtime/store/HistorySdk.js.map +0 -1
  116. package/build/src/runtime/store/Http.d.ts.map +0 -1
  117. package/build/src/runtime/store/Http.js.map +0 -1
  118. package/build/src/runtime/store/HttpNode.d.ts.map +0 -1
  119. package/build/src/runtime/store/HttpNode.js.map +0 -1
  120. package/build/src/runtime/store/HttpWeb.d.ts.map +0 -1
  121. package/build/src/runtime/store/HttpWeb.js.map +0 -1
  122. package/build/src/runtime/store/OrganizationsSdk.d.ts +0 -86
  123. package/build/src/runtime/store/OrganizationsSdk.d.ts.map +0 -1
  124. package/build/src/runtime/store/OrganizationsSdk.js +0 -343
  125. package/build/src/runtime/store/OrganizationsSdk.js.map +0 -1
  126. package/build/src/runtime/store/ProjectExecutionsSdk.d.ts.map +0 -1
  127. package/build/src/runtime/store/ProjectExecutionsSdk.js.map +0 -1
  128. package/build/src/runtime/store/RevisionsSdk.d.ts.map +0 -1
  129. package/build/src/runtime/store/RevisionsSdk.js.map +0 -1
  130. package/build/src/runtime/store/RouteBuilder.d.ts.map +0 -1
  131. package/build/src/runtime/store/RouteBuilder.js.map +0 -1
  132. package/build/src/runtime/store/Sdk.d.ts.map +0 -1
  133. package/build/src/runtime/store/Sdk.js.map +0 -1
  134. package/build/src/runtime/store/SdkBase.d.ts.map +0 -1
  135. package/build/src/runtime/store/SdkBase.js.map +0 -1
  136. package/build/src/runtime/store/SharedSdk.d.ts.map +0 -1
  137. package/build/src/runtime/store/SharedSdk.js.map +0 -1
  138. package/build/src/runtime/store/StoreSdkNode.d.ts.map +0 -1
  139. package/build/src/runtime/store/StoreSdkNode.js.map +0 -1
  140. package/build/src/runtime/store/StoreSdkWeb.d.ts.map +0 -1
  141. package/build/src/runtime/store/StoreSdkWeb.js.map +0 -1
  142. package/build/src/runtime/store/TrashSdk.d.ts.map +0 -1
  143. package/build/src/runtime/store/TrashSdk.js.map +0 -1
  144. package/build/src/runtime/store/UsersSdk.d.ts.map +0 -1
  145. package/build/src/runtime/store/UsersSdk.js +0 -104
  146. package/build/src/runtime/store/UsersSdk.js.map +0 -1
  147. package/build/src/runtime/store/WsClient.d.ts.map +0 -1
  148. package/build/src/runtime/store/WsClient.js.map +0 -1
  149. package/build/src/runtime/store/WsClientNode.d.ts.map +0 -1
  150. package/build/src/runtime/store/WsClientNode.js.map +0 -1
  151. package/build/src/runtime/store/WsClientWeb.d.ts.map +0 -1
  152. package/build/src/runtime/store/WsClientWeb.js.map +0 -1
  153. package/src/runtime/store/OrganizationsSdk.ts +0 -364
  154. package/src/runtime/store/UsersSdk.ts +0 -186
  155. /package/build/src/{runtime/store → sdk}/AuthSdk.d.ts +0 -0
  156. /package/build/src/{runtime/store → sdk}/AuthSdk.js +0 -0
  157. /package/build/src/{runtime/store → sdk}/Http.d.ts +0 -0
  158. /package/build/src/{runtime/store → sdk}/Http.js +0 -0
  159. /package/build/src/{runtime/store → sdk}/HttpNode.d.ts +0 -0
  160. /package/build/src/{runtime/store → sdk}/Sdk.js +0 -0
  161. /package/build/src/{runtime/store → sdk}/StoreSdkNode.d.ts +0 -0
  162. /package/build/src/{runtime/store → sdk}/StoreSdkNode.js +0 -0
  163. /package/build/src/{runtime/store → sdk}/StoreSdkWeb.d.ts +0 -0
  164. /package/build/src/{runtime/store → sdk}/StoreSdkWeb.js +0 -0
  165. /package/build/src/{runtime/store → sdk}/WsClient.d.ts +0 -0
  166. /package/build/src/{runtime/store → sdk}/WsClient.js +0 -0
  167. /package/build/src/{runtime/store → sdk}/WsClientNode.d.ts +0 -0
  168. /package/build/src/{runtime/store → sdk}/WsClientNode.js +0 -0
  169. /package/build/src/{runtime/store → sdk}/WsClientWeb.d.ts +0 -0
  170. /package/build/src/{runtime/store → sdk}/WsClientWeb.js +0 -0
  171. /package/src/{runtime/store → sdk}/AuthSdk.ts +0 -0
  172. /package/src/{runtime/store → sdk}/Http.ts +0 -0
  173. /package/src/{runtime/store → sdk}/StoreSdkNode.ts +0 -0
  174. /package/src/{runtime/store → sdk}/StoreSdkWeb.ts +0 -0
  175. /package/src/{runtime/store → sdk}/WsClient.ts +0 -0
  176. /package/src/{runtime/store → sdk}/WsClientNode.ts +0 -0
  177. /package/src/{runtime/store → sdk}/WsClientWeb.ts +0 -0
@@ -0,0 +1,479 @@
1
+ import {
2
+ SdkBase,
3
+ E_RESPONSE_STATUS,
4
+ E_RESPONSE_NO_VALUE,
5
+ E_INVALID_JSON,
6
+ E_RESPONSE_UNKNOWN,
7
+ SdkOptions,
8
+ } from './SdkBase.js'
9
+ import { RouteBuilder } from './RouteBuilder.js'
10
+ import type { ContextListOptions, ContextListResult } from '../events/BaseEvents.js'
11
+ import type { IOrganization, UserOrganizationGrantType } from '../models/store/Organization.js'
12
+ import type { InvitationSchema } from '../models/store/Invitation.js'
13
+ import type { PatchInfo } from '../patch/types.js'
14
+ import type { IUser } from '../models/store/User.js'
15
+ import { Exception } from '../exceptions/exception.js'
16
+
17
+ export class OrganizationsSdk extends SdkBase {
18
+ /**
19
+ * Lists all user organizations.
20
+ */
21
+ async list(request: SdkOptions = {}): Promise<ContextListResult<IOrganization>> {
22
+ const { token } = request
23
+ const url = this.sdk.getUrl(RouteBuilder.organizations())
24
+ const result = await this.sdk.http.get(url.toString(), { token })
25
+ this.inspectCommonStatusCodes(result)
26
+ const E_PREFIX = 'Unable to list your organizations. '
27
+ if (result.status !== 200) {
28
+ this.logInvalidResponse(result)
29
+ throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
30
+ }
31
+ if (!result.body) {
32
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
33
+ }
34
+ let data: ContextListResult<IOrganization>
35
+ try {
36
+ data = JSON.parse(result.body)
37
+ } catch {
38
+ throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
39
+ }
40
+ if (!Array.isArray(data.items)) {
41
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
42
+ }
43
+ return data
44
+ }
45
+
46
+ /**
47
+ * Creates a new organization.
48
+ * @param orgName The name of the organization to create.
49
+ * @param request The request options.
50
+ * @returns A promise that resolves to the created organization.
51
+ */
52
+ async create(orgName: string, request: SdkOptions = {}): Promise<IOrganization> {
53
+ const { token } = request
54
+ const url = this.sdk.getUrl(RouteBuilder.organizations())
55
+ const body = {
56
+ name: orgName,
57
+ }
58
+ const result = await this.sdk.http.post(url.toString(), {
59
+ body: JSON.stringify(body),
60
+ token,
61
+ headers: {
62
+ 'Content-Type': 'application/json',
63
+ },
64
+ })
65
+ this.inspectCommonStatusCodes(result)
66
+ const E_PREFIX = 'Unable to create an organization. '
67
+ if (result.status !== 200) {
68
+ this.logInvalidResponse(result)
69
+ throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
70
+ }
71
+ if (!result.body) {
72
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
73
+ }
74
+ let data: IOrganization
75
+ try {
76
+ data = JSON.parse(result.body)
77
+ } catch {
78
+ throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
79
+ }
80
+ if (!data.kind) {
81
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
82
+ }
83
+ return data
84
+ }
85
+
86
+ invitations = {
87
+ /**
88
+ * Lists all invitations for a given organization.
89
+ * @param oid The organization ID.
90
+ * @param request The request options.
91
+ * @returns A promise that resolves to a list of invitations.
92
+ */
93
+ list: async (oid: string, request: SdkOptions = {}): Promise<ContextListResult<InvitationSchema>> => {
94
+ const { token } = request
95
+ const url = this.sdk.getUrl(RouteBuilder.invitations(oid))
96
+ const result = await this.sdk.http.get(url.toString(), { token })
97
+ this.inspectCommonStatusCodes(result)
98
+ const E_PREFIX = 'Unable to list organization invitations. '
99
+ if (result.status !== 200) {
100
+ this.logInvalidResponse(result)
101
+ throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
102
+ }
103
+ if (!result.body) {
104
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
105
+ }
106
+ let data: ContextListResult<InvitationSchema>
107
+ try {
108
+ data = JSON.parse(result.body)
109
+ } catch {
110
+ throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
111
+ }
112
+ if (!Array.isArray(data.items)) {
113
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
114
+ }
115
+ return data
116
+ },
117
+
118
+ /**
119
+ * Creates an invitation for a user to join an organization.
120
+ * @param oid The organization ID.
121
+ * @param email The email address of the user to invite.
122
+ * @param grant_type The type of grant for the user.
123
+ * @param name The name of the user (optional).
124
+ * @param request The request options.
125
+ * @returns A promise that resolves to the created invitation.
126
+ */
127
+ create: async (
128
+ oid: string,
129
+ email: string,
130
+ grant_type: UserOrganizationGrantType,
131
+ name?: string,
132
+ request: SdkOptions = {}
133
+ ): Promise<InvitationSchema> => {
134
+ const url = this.sdk.getUrl(RouteBuilder.invitations(oid))
135
+ const body = {
136
+ email,
137
+ name,
138
+ grant_type,
139
+ }
140
+ const result = await this.sdk.http.post(url.toString(), {
141
+ body: JSON.stringify(body),
142
+ token: request.token,
143
+ headers: {
144
+ 'Content-Type': 'application/json',
145
+ },
146
+ })
147
+ this.inspectCommonStatusCodes(result)
148
+ const E_PREFIX = 'Unable to create an invitation. '
149
+ if (result.status !== 200) {
150
+ this.logInvalidResponse(result)
151
+ throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
152
+ }
153
+ if (!result.body) {
154
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
155
+ }
156
+ let data: InvitationSchema
157
+ try {
158
+ data = JSON.parse(result.body)
159
+ } catch {
160
+ throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
161
+ }
162
+ if (!data.kind) {
163
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
164
+ }
165
+ return data
166
+ },
167
+
168
+ /**
169
+ * Finds an invitation by its token.
170
+ * @param oid The organization ID.
171
+ * @param token The invitation token.
172
+ * @param request The request options.
173
+ * @returns A promise that resolves to the found invitation.
174
+ */
175
+ findByToken: async (oid: string, token: string, request: SdkOptions = {}): Promise<InvitationSchema> => {
176
+ const url = this.sdk.getUrl(RouteBuilder.findInvitation(oid))
177
+ url.searchParams.append('token', token)
178
+ const result = await this.sdk.http.get(url.toString(), request)
179
+ this.inspectCommonStatusCodes(result)
180
+ const E_PREFIX = 'Unable to find invitation by token. '
181
+ if (result.status !== 200) {
182
+ this.logInvalidResponse(result)
183
+ throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
184
+ }
185
+ if (!result.body) {
186
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
187
+ }
188
+ let data: InvitationSchema
189
+ try {
190
+ data = JSON.parse(result.body)
191
+ } catch {
192
+ throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
193
+ }
194
+ if (!data.kind) {
195
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
196
+ }
197
+ return data
198
+ },
199
+
200
+ /**
201
+ * Declines an invitation.
202
+ * @param oid The organization ID.
203
+ * @param id The invitation ID.
204
+ * @param request The request options.
205
+ * @returns A promise that resolves when the invitation is declined.
206
+ */
207
+ decline: async (oid: string, id: string, request: SdkOptions = {}): Promise<InvitationSchema> => {
208
+ const url = this.sdk.getUrl(RouteBuilder.declineInvitation(oid, id))
209
+ const result = await this.sdk.http.post(url.toString(), request)
210
+ this.inspectCommonStatusCodes(result)
211
+ const E_PREFIX = 'Unable to decline invitation. '
212
+ if (result.status !== 200) {
213
+ this.logInvalidResponse(result)
214
+ throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
215
+ }
216
+ if (!result.body) {
217
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
218
+ }
219
+ let data: InvitationSchema
220
+ try {
221
+ data = JSON.parse(result.body)
222
+ } catch {
223
+ throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
224
+ }
225
+ if (!data.kind) {
226
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
227
+ }
228
+ return data
229
+ },
230
+
231
+ /**
232
+ * Soft-deletes an invitation.
233
+ * @param oid The organization ID.
234
+ * @param id The invitation ID.
235
+ * @param request The request options.
236
+ * @returns A promise that resolves to the deleted invitation.
237
+ */
238
+ delete: async (oid: string, id: string, request: SdkOptions = {}): Promise<InvitationSchema> => {
239
+ const url = this.sdk.getUrl(RouteBuilder.invitation(oid, id))
240
+ const result = await this.sdk.http.delete(url.toString(), request)
241
+ this.inspectCommonStatusCodes(result)
242
+ const E_PREFIX = 'Unable to delete invitation. '
243
+ if (result.status !== 200) {
244
+ this.logInvalidResponse(result)
245
+ throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
246
+ }
247
+ if (!result.body) {
248
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
249
+ }
250
+ let data: InvitationSchema
251
+ try {
252
+ data = JSON.parse(result.body)
253
+ } catch {
254
+ throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
255
+ }
256
+ if (!data.kind) {
257
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
258
+ }
259
+ return data
260
+ },
261
+
262
+ /**
263
+ * Patches an invitation. The server performs the patch validation.
264
+ * The API only allows to patch some of the invitation properties:
265
+ * - name
266
+ * - expires_at
267
+ * - grant_type
268
+ * @param oid The organization ID.
269
+ * @param id The invitation ID.
270
+ * @param info The patch information.
271
+ * @param request The request options.
272
+ * @returns A promise that resolves to the patched invitation.
273
+ */
274
+ patch: async (oid: string, id: string, info: PatchInfo, request: SdkOptions = {}): Promise<InvitationSchema> => {
275
+ const url = this.sdk.getUrl(RouteBuilder.invitation(oid, id))
276
+ const result = await this.sdk.http.patch(url.toString(), {
277
+ body: JSON.stringify(info),
278
+ token: request.token,
279
+ headers: {
280
+ 'Content-Type': 'application/json',
281
+ },
282
+ })
283
+ this.inspectCommonStatusCodes(result)
284
+ const E_PREFIX = 'Unable to update invitation. '
285
+ if (result.status !== 200) {
286
+ this.logInvalidResponse(result)
287
+ throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
288
+ }
289
+ if (!result.body) {
290
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
291
+ }
292
+ let data: InvitationSchema
293
+ try {
294
+ data = JSON.parse(result.body)
295
+ } catch {
296
+ throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
297
+ }
298
+ if (!data.kind) {
299
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
300
+ }
301
+ return data
302
+ },
303
+
304
+ /**
305
+ * Resends an invitation.
306
+ * @param oid The organization ID.
307
+ * @param id The invitation ID.
308
+ * @param request The request options.
309
+ * @returns A promise that resolves to the updated invitation.
310
+ */
311
+ resend: async (oid: string, id: string, request: SdkOptions = {}): Promise<InvitationSchema> => {
312
+ const url = this.sdk.getUrl(RouteBuilder.resendInvitation(oid, id))
313
+ const result = await this.sdk.http.put(url.toString(), request)
314
+ this.inspectCommonStatusCodes(result)
315
+ const E_PREFIX = 'Unable to resend invitation. '
316
+ if (result.status !== 200) {
317
+ this.logInvalidResponse(result)
318
+ throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
319
+ }
320
+ if (!result.body) {
321
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
322
+ }
323
+ let data: InvitationSchema
324
+ try {
325
+ data = JSON.parse(result.body)
326
+ } catch {
327
+ throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
328
+ }
329
+ if (!data.kind) {
330
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
331
+ }
332
+ return data
333
+ },
334
+ }
335
+
336
+ users = {
337
+ /**
338
+ * Lists users in the organization.
339
+ *
340
+ * @param oid The key of the organization we want to read the user from.
341
+ * @param options Optional query options.
342
+ * @param request Optional request options.
343
+ */
344
+ list: async (
345
+ oid: string,
346
+ options?: ContextListOptions,
347
+ request: SdkOptions = {}
348
+ ): Promise<ContextListResult<IUser>> => {
349
+ const { token } = request
350
+ const url = this.sdk.getUrl(RouteBuilder.organizationUsers(oid))
351
+ this.sdk.appendListOptions(url, options)
352
+ const result = await this.sdk.http.get(url.toString(), { token })
353
+ this.inspectCommonStatusCodes(result)
354
+ const E_PREFIX = 'Unable to list projects. '
355
+ if (result.status !== 200) {
356
+ this.logInvalidResponse(result)
357
+ throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
358
+ }
359
+ if (!result.body) {
360
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
361
+ }
362
+ let data: ContextListResult<IUser>
363
+ try {
364
+ data = JSON.parse(result.body)
365
+ } catch {
366
+ throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
367
+ }
368
+ if (!Array.isArray(data.items)) {
369
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
370
+ }
371
+ return data
372
+ },
373
+
374
+ /**
375
+ * Gets a user by its key in the organization.
376
+ *
377
+ * @param oid The key of the organization parent organization.
378
+ * @param key The user key.
379
+ * @param request Optional request options.
380
+ * @returns The user object
381
+ */
382
+ read: async (oid: string, key: string, request: SdkOptions = {}): Promise<IUser> => {
383
+ const { token } = request
384
+ const url = this.sdk.getUrl(RouteBuilder.organizationUser(oid, key))
385
+ const result = await this.sdk.http.get(url.toString(), { token })
386
+ this.inspectCommonStatusCodes(result)
387
+ const E_PREFIX = 'Unable to read the user info. '
388
+ if (result.status !== 200) {
389
+ this.logInvalidResponse(result)
390
+ throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
391
+ }
392
+ if (!result.body) {
393
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
394
+ }
395
+ let data: IUser
396
+ try {
397
+ data = JSON.parse(result.body)
398
+ } catch {
399
+ throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
400
+ }
401
+ return data
402
+ },
403
+
404
+ /**
405
+ * Activates a user in the organization.
406
+ * If the user is already active the API will respond with an error.
407
+ * @param oid The key of the organization parent organization.
408
+ * @param key The user key.
409
+ */
410
+ activate: async (oid: string, key: string, request: SdkOptions = {}): Promise<IUser> => {
411
+ const { token } = request
412
+ const url = this.sdk.getUrl(RouteBuilder.organizationUserActivate(oid, key))
413
+ const result = await this.sdk.http.post(url.toString(), { token })
414
+ this.inspectCommonStatusCodes(result)
415
+ const E_PREFIX = 'Unable to activate the user. '
416
+ if (result.status !== 200) {
417
+ this.logInvalidResponse(result)
418
+ throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
419
+ }
420
+ if (!result.body) {
421
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
422
+ }
423
+ let data: IUser
424
+ try {
425
+ data = JSON.parse(result.body)
426
+ } catch {
427
+ throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
428
+ }
429
+ return data
430
+ },
431
+
432
+ /**
433
+ * Deactivates a user in the organization.
434
+ * If the user is already deactivated the API will respond with an error.
435
+ * @param oid The key of the organization parent organization.
436
+ * @param key The user key.
437
+ */
438
+ deactivate: async (oid: string, key: string, request: SdkOptions = {}): Promise<IUser> => {
439
+ const { token } = request
440
+ const url = this.sdk.getUrl(RouteBuilder.organizationUserDeactivate(oid, key))
441
+ const result = await this.sdk.http.post(url.toString(), { token })
442
+ this.inspectCommonStatusCodes(result)
443
+ const E_PREFIX = 'Unable to deactivate the user. '
444
+ if (result.status !== 200) {
445
+ this.logInvalidResponse(result)
446
+ throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
447
+ }
448
+ if (!result.body) {
449
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
450
+ }
451
+ let data: IUser
452
+ try {
453
+ data = JSON.parse(result.body)
454
+ } catch {
455
+ throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
456
+ }
457
+ return data
458
+ },
459
+
460
+ /**
461
+ * Deletes a user from the organization.
462
+ * @param oid The key of the organization parent organization.
463
+ * @param key The user
464
+ * @param request Optional request options.
465
+ * @returns A promise that resolves when the user is deleted.
466
+ */
467
+ delete: async (oid: string, key: string, request: SdkOptions = {}): Promise<void> => {
468
+ const { token } = request
469
+ const url = this.sdk.getUrl(RouteBuilder.organizationUser(oid, key))
470
+ const result = await this.sdk.http.delete(url.toString(), { token })
471
+ this.inspectCommonStatusCodes(result)
472
+ const E_PREFIX = 'Unable to delete the user. '
473
+ if (result.status !== 204) {
474
+ this.logInvalidResponse(result)
475
+ throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
476
+ }
477
+ },
478
+ }
479
+ }
@@ -6,8 +6,8 @@ import {
6
6
  ContextListResult,
7
7
  IBulkOperationResult,
8
8
  IProjectExecutionListOptions,
9
- } from '../../events/BaseEvents.js'
10
- import { IProjectExecution, Kind as ProjectExecutionKind } from '../../models/ProjectExecution.js'
9
+ } from '../events/BaseEvents.js'
10
+ import { IProjectExecution, Kind as ProjectExecutionKind } from '../models/ProjectExecution.js'
11
11
 
12
12
  export class ProjectExecutionSdk extends SdkBase {
13
13
  /**
@@ -7,9 +7,9 @@ import {
7
7
  SdkOptions,
8
8
  } from './SdkBase.js'
9
9
  import { RouteBuilder } from './RouteBuilder.js'
10
- import type { ContextListResult, ContextListOptions } from '../../events/BaseEvents.js'
11
- import type { IRevision } from '../../models/store/Revision.js'
12
- import { Exception } from '../../exceptions/exception.js'
10
+ import type { ContextListResult, ContextListOptions } from '../events/BaseEvents.js'
11
+ import type { IRevision } from '../models/store/Revision.js'
12
+ import { Exception } from '../exceptions/exception.js'
13
13
 
14
14
  export class RevisionsSdk extends SdkBase {
15
15
  /**
@@ -170,6 +170,14 @@ export class RouteBuilder {
170
170
  return `${this.organization(oid)}/users/${key}`
171
171
  }
172
172
 
173
+ static organizationUserDeactivate(oid: string, key: string): string {
174
+ return `${this.organization(oid)}/users/${key}/deactivate`
175
+ }
176
+
177
+ static organizationUserActivate(oid: string, key: string): string {
178
+ return `${this.organization(oid)}/users/${key}/activate`
179
+ }
180
+
173
181
  /**
174
182
  * @deprecated Use `organizationUsers` instead.
175
183
  */
@@ -200,6 +208,10 @@ export class RouteBuilder {
200
208
  return `${this.invitation(oid, id)}/decline`
201
209
  }
202
210
 
211
+ static resendInvitation(oid: string, id: string): string {
212
+ return `${this.invitation(oid, id)}/resend`
213
+ }
214
+
203
215
  /**
204
216
  * @deprecated Not used anymore
205
217
  */
@@ -5,7 +5,7 @@ import { FilesSdk } from './FilesSdk.js'
5
5
  import { UsersSdk } from './UsersSdk.js'
6
6
  import { HistorySdk } from './HistorySdk.js'
7
7
  import { SharedSdk } from './SharedSdk.js'
8
- import { ContextListOptions } from '../../events/BaseEvents.js'
8
+ import type { ContextListOptions } from '../events/BaseEvents.js'
9
9
  import { RevisionsSdk } from './RevisionsSdk.js'
10
10
  import { TrashSdk } from './TrashSdk.js'
11
11
  import { ProjectExecutionSdk } from './ProjectExecutionsSdk.js'
@@ -1,13 +1,13 @@
1
1
  /* eslint-disable no-console */
2
- import { Headers } from '../../lib/headers/Headers.js'
2
+ import { Headers } from '../lib/headers/Headers.js'
3
3
  import { Sdk } from './Sdk.js'
4
4
  import {
5
5
  ContextDeleteRecord,
6
6
  ContextListOptions,
7
7
  ContextListResult,
8
8
  IBulkOperationResult,
9
- } from '../../events/BaseEvents.js'
10
- import { Exception } from '../../exceptions/exception.js'
9
+ } from '../events/BaseEvents.js'
10
+ import { Exception } from '../exceptions/exception.js'
11
11
 
12
12
  export interface SdkOptions {
13
13
  /**
@@ -7,10 +7,10 @@ import {
7
7
  SdkOptions,
8
8
  } from './SdkBase.js'
9
9
  import { RouteBuilder } from './RouteBuilder.js'
10
- import { IFile } from '../../models/store/File.js'
10
+ import { IFile } from '../models/store/File.js'
11
11
  import { ListFileKind } from './FilesSdk.js'
12
- import { ContextListOptions, ContextListResult } from '../../events/BaseEvents.js'
13
- import { Exception } from '../../exceptions/exception.js'
12
+ import { ContextListOptions, ContextListResult } from '../events/BaseEvents.js'
13
+ import { Exception } from '../exceptions/exception.js'
14
14
 
15
15
  export class SharedSdk extends SdkBase {
16
16
  /**
@@ -7,9 +7,9 @@ import {
7
7
  type SdkOptions,
8
8
  } from './SdkBase.js'
9
9
  import { RouteBuilder } from './RouteBuilder.js'
10
- import type { ContextListOptions, ContextListResult } from '../../events/BaseEvents.js'
11
- import type { TrashEntry } from '../../models/TrashEntry.js'
12
- import { Exception } from '../../exceptions/exception.js'
10
+ import type { ContextListOptions, ContextListResult } from '../events/BaseEvents.js'
11
+ import type { TrashEntry } from '../models/TrashEntry.js'
12
+ import { Exception } from '../exceptions/exception.js'
13
13
 
14
14
  export class TrashSdk extends SdkBase {
15
15
  /**