@api-client/core 0.12.11 → 0.12.13

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.
@@ -43,6 +43,12 @@ export class OrganizationsSdk extends SdkBase {
43
43
  return data
44
44
  }
45
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
+ */
46
52
  async create(orgName: string, request: SdkOptions = {}): Promise<IOrganization> {
47
53
  const { token } = request
48
54
  const url = this.sdk.getUrl(RouteBuilder.organizations())
@@ -77,288 +83,366 @@ export class OrganizationsSdk extends SdkBase {
77
83
  return data
78
84
  }
79
85
 
80
- /**
81
- * Lists all invitations for a given organization.
82
- * @param oid The organization ID.
83
- * @param request The request options.
84
- * @returns A promise that resolves to a list of invitations.
85
- */
86
- async listInvitations(oid: string, request: SdkOptions = {}): Promise<ContextListResult<InvitationSchema>> {
87
- const { token } = request
88
- const url = this.sdk.getUrl(RouteBuilder.invitations(oid))
89
- const result = await this.sdk.http.get(url.toString(), { token })
90
- this.inspectCommonStatusCodes(result)
91
- const E_PREFIX = 'Unable to list organization invitations. '
92
- if (result.status !== 200) {
93
- this.logInvalidResponse(result)
94
- throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
95
- }
96
- if (!result.body) {
97
- throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
98
- }
99
- let data: ContextListResult<InvitationSchema>
100
- try {
101
- data = JSON.parse(result.body)
102
- } catch {
103
- throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
104
- }
105
- if (!Array.isArray(data.items)) {
106
- throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
107
- }
108
- return data
109
- }
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
+ },
110
117
 
111
- /**
112
- * Creates an invitation for a user to join an organization.
113
- * @param oid The organization ID.
114
- * @param email The email address of the user to invite.
115
- * @param grant_type The type of grant for the user.
116
- * @param name The name of the user (optional).
117
- * @param request The request options.
118
- * @returns A promise that resolves to the created invitation.
119
- */
120
- async createInvitation(
121
- oid: string,
122
- email: string,
123
- grant_type: UserOrganizationGrantType,
124
- name?: string,
125
- request: SdkOptions = {}
126
- ): Promise<InvitationSchema> {
127
- const url = this.sdk.getUrl(RouteBuilder.invitations(oid))
128
- const body = {
129
- email,
130
- name,
131
- grant_type,
132
- }
133
- const result = await this.sdk.http.post(url.toString(), {
134
- body: JSON.stringify(body),
135
- token: request.token,
136
- headers: {
137
- 'Content-Type': 'application/json',
138
- },
139
- })
140
- this.inspectCommonStatusCodes(result)
141
- const E_PREFIX = 'Unable to create an invitation. '
142
- if (result.status !== 200) {
143
- this.logInvalidResponse(result)
144
- throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
145
- }
146
- if (!result.body) {
147
- throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
148
- }
149
- let data: InvitationSchema
150
- try {
151
- data = JSON.parse(result.body)
152
- } catch {
153
- throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
154
- }
155
- if (!data.kind) {
156
- throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
157
- }
158
- return data
159
- }
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
+ },
160
167
 
161
- /**
162
- * Finds an invitation by its token.
163
- * @param oid The organization ID.
164
- * @param token The invitation token.
165
- * @param request The request options.
166
- * @returns A promise that resolves to the found invitation.
167
- */
168
- async findInvitationByToken(oid: string, token: string, request: SdkOptions = {}): Promise<InvitationSchema> {
169
- const url = this.sdk.getUrl(RouteBuilder.findInvitation(oid))
170
- url.searchParams.append('token', token)
171
- const result = await this.sdk.http.get(url.toString(), request)
172
- this.inspectCommonStatusCodes(result)
173
- const E_PREFIX = 'Unable to find invitation by token. '
174
- if (result.status !== 200) {
175
- this.logInvalidResponse(result)
176
- throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
177
- }
178
- if (!result.body) {
179
- throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
180
- }
181
- let data: InvitationSchema
182
- try {
183
- data = JSON.parse(result.body)
184
- } catch {
185
- throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
186
- }
187
- if (!data.kind) {
188
- throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
189
- }
190
- return data
191
- }
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
+ },
192
199
 
193
- /**
194
- * Declines an invitation.
195
- * @param oid The organization ID.
196
- * @param id The invitation ID.
197
- * @param request The request options.
198
- * @returns A promise that resolves when the invitation is declined.
199
- */
200
- async declineInvitation(oid: string, id: string, request: SdkOptions = {}): Promise<InvitationSchema> {
201
- const url = this.sdk.getUrl(RouteBuilder.declineInvitation(oid, id))
202
- const result = await this.sdk.http.post(url.toString(), request)
203
- this.inspectCommonStatusCodes(result)
204
- const E_PREFIX = 'Unable to decline invitation. '
205
- if (result.status !== 200) {
206
- this.logInvalidResponse(result)
207
- throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
208
- }
209
- if (!result.body) {
210
- throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
211
- }
212
- let data: InvitationSchema
213
- try {
214
- data = JSON.parse(result.body)
215
- } catch {
216
- throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
217
- }
218
- if (!data.kind) {
219
- throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
220
- }
221
- return data
222
- }
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
+ },
223
230
 
224
- /**
225
- * Soft-deletes an invitation.
226
- * @param oid The organization ID.
227
- * @param id The invitation ID.
228
- * @param request The request options.
229
- * @returns A promise that resolves to the deleted invitation.
230
- */
231
- async deleteInvitation(oid: string, id: string, request: SdkOptions = {}): Promise<InvitationSchema> {
232
- const url = this.sdk.getUrl(RouteBuilder.invitation(oid, id))
233
- const result = await this.sdk.http.delete(url.toString(), request)
234
- this.inspectCommonStatusCodes(result)
235
- const E_PREFIX = 'Unable to delete invitation. '
236
- if (result.status !== 200) {
237
- this.logInvalidResponse(result)
238
- throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
239
- }
240
- if (!result.body) {
241
- throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
242
- }
243
- let data: InvitationSchema
244
- try {
245
- data = JSON.parse(result.body)
246
- } catch {
247
- throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
248
- }
249
- if (!data.kind) {
250
- throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
251
- }
252
- return data
253
- }
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
+ },
254
261
 
255
- /**
256
- * Patches an invitation. The server performs the patch validation.
257
- * The API only allows to patch some of the invitation properties:
258
- * - name
259
- * - expires_at
260
- * - grant_type
261
- * @param oid The organization ID.
262
- * @param id The invitation ID.
263
- * @param info The patch information.
264
- * @param request The request options.
265
- * @returns A promise that resolves to the patched invitation.
266
- */
267
- async patchInvitation(oid: string, id: string, info: PatchInfo, request: SdkOptions = {}): Promise<InvitationSchema> {
268
- const url = this.sdk.getUrl(RouteBuilder.invitation(oid, id))
269
- const result = await this.sdk.http.patch(url.toString(), {
270
- body: JSON.stringify(info),
271
- token: request.token,
272
- headers: {
273
- 'Content-Type': 'application/json',
274
- },
275
- })
276
- this.inspectCommonStatusCodes(result)
277
- const E_PREFIX = 'Unable to update invitation. '
278
- if (result.status !== 200) {
279
- this.logInvalidResponse(result)
280
- throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
281
- }
282
- if (!result.body) {
283
- throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
284
- }
285
- let data: InvitationSchema
286
- try {
287
- data = JSON.parse(result.body)
288
- } catch {
289
- throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
290
- }
291
- if (!data.kind) {
292
- throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
293
- }
294
- return data
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
+ },
295
303
  }
296
304
 
297
- /**
298
- * Lists users in the organization.
299
- *
300
- * @param oid The key of the organization we want to read the user from.
301
- * @param options Optional query options.
302
- * @param request Optional request options.
303
- */
304
- async listUsers(
305
- oid: string,
306
- options?: ContextListOptions,
307
- request: SdkOptions = {}
308
- ): Promise<ContextListResult<IUser>> {
309
- const { token } = request
310
- const url = this.sdk.getUrl(RouteBuilder.organizationUsers(oid))
311
- this.sdk.appendListOptions(url, options)
312
- const result = await this.sdk.http.get(url.toString(), { token })
313
- this.inspectCommonStatusCodes(result)
314
- const E_PREFIX = 'Unable to list projects. '
315
- if (result.status !== 200) {
316
- this.logInvalidResponse(result)
317
- throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
318
- }
319
- if (!result.body) {
320
- throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
321
- }
322
- let data: ContextListResult<IUser>
323
- try {
324
- data = JSON.parse(result.body)
325
- } catch {
326
- throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
327
- }
328
- if (!Array.isArray(data.items)) {
329
- throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
330
- }
331
- return data
332
- }
305
+ users = {
306
+ /**
307
+ * Lists users in the organization.
308
+ *
309
+ * @param oid The key of the organization we want to read the user from.
310
+ * @param options Optional query options.
311
+ * @param request Optional request options.
312
+ */
313
+ list: async (
314
+ oid: string,
315
+ options?: ContextListOptions,
316
+ request: SdkOptions = {}
317
+ ): Promise<ContextListResult<IUser>> => {
318
+ const { token } = request
319
+ const url = this.sdk.getUrl(RouteBuilder.organizationUsers(oid))
320
+ this.sdk.appendListOptions(url, options)
321
+ const result = await this.sdk.http.get(url.toString(), { token })
322
+ this.inspectCommonStatusCodes(result)
323
+ const E_PREFIX = 'Unable to list projects. '
324
+ if (result.status !== 200) {
325
+ this.logInvalidResponse(result)
326
+ throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
327
+ }
328
+ if (!result.body) {
329
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
330
+ }
331
+ let data: ContextListResult<IUser>
332
+ try {
333
+ data = JSON.parse(result.body)
334
+ } catch {
335
+ throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
336
+ }
337
+ if (!Array.isArray(data.items)) {
338
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
339
+ }
340
+ return data
341
+ },
333
342
 
334
- /**
335
- * Gets a user by its key in the organization.
336
- *
337
- * @param oid The key of the organization parent organization.
338
- * @param key The user key.
339
- * @param request Optional request options.
340
- * @returns The user object
341
- * @deprecated Use `organizations.readUser()` instead.
342
- */
343
- async getUser(oid: string, key: string, request: SdkOptions = {}): Promise<IUser> {
344
- const { token } = request
345
- const url = this.sdk.getUrl(RouteBuilder.organizationUser(oid, key))
346
- const result = await this.sdk.http.get(url.toString(), { token })
347
- this.inspectCommonStatusCodes(result)
348
- const E_PREFIX = 'Unable to read the user info. '
349
- if (result.status !== 200) {
350
- this.logInvalidResponse(result)
351
- throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
352
- }
353
- if (!result.body) {
354
- throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
355
- }
356
- let data: IUser
357
- try {
358
- data = JSON.parse(result.body)
359
- } catch {
360
- throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
361
- }
362
- return data
343
+ /**
344
+ * Gets a user by its key in the organization.
345
+ *
346
+ * @param oid The key of the organization parent organization.
347
+ * @param key The user key.
348
+ * @param request Optional request options.
349
+ * @returns The user object
350
+ */
351
+ read: async (oid: string, key: string, request: SdkOptions = {}): Promise<IUser> => {
352
+ const { token } = request
353
+ const url = this.sdk.getUrl(RouteBuilder.organizationUser(oid, key))
354
+ const result = await this.sdk.http.get(url.toString(), { token })
355
+ this.inspectCommonStatusCodes(result)
356
+ const E_PREFIX = 'Unable to read the user info. '
357
+ if (result.status !== 200) {
358
+ this.logInvalidResponse(result)
359
+ throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
360
+ }
361
+ if (!result.body) {
362
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
363
+ }
364
+ let data: IUser
365
+ try {
366
+ data = JSON.parse(result.body)
367
+ } catch {
368
+ throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
369
+ }
370
+ return data
371
+ },
372
+
373
+ /**
374
+ * Activates a user in the organization.
375
+ * If the user is already active the API will respond with an error.
376
+ * @param oid The key of the organization parent organization.
377
+ * @param key The user key.
378
+ */
379
+ activate: async (oid: string, key: string, request: SdkOptions = {}): Promise<IUser> => {
380
+ const { token } = request
381
+ const url = this.sdk.getUrl(RouteBuilder.organizationUserActivate(oid, key))
382
+ const result = await this.sdk.http.post(url.toString(), { token })
383
+ this.inspectCommonStatusCodes(result)
384
+ const E_PREFIX = 'Unable to activate the user. '
385
+ if (result.status !== 200) {
386
+ this.logInvalidResponse(result)
387
+ throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
388
+ }
389
+ if (!result.body) {
390
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
391
+ }
392
+ let data: IUser
393
+ try {
394
+ data = JSON.parse(result.body)
395
+ } catch {
396
+ throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
397
+ }
398
+ return data
399
+ },
400
+
401
+ /**
402
+ * Deactivates a user in the organization.
403
+ * If the user is already deactivated the API will respond with an error.
404
+ * @param oid The key of the organization parent organization.
405
+ * @param key The user key.
406
+ */
407
+ deactivate: async (oid: string, key: string, request: SdkOptions = {}): Promise<IUser> => {
408
+ const { token } = request
409
+ const url = this.sdk.getUrl(RouteBuilder.organizationUserDeactivate(oid, key))
410
+ const result = await this.sdk.http.post(url.toString(), { token })
411
+ this.inspectCommonStatusCodes(result)
412
+ const E_PREFIX = 'Unable to deactivate the user. '
413
+ if (result.status !== 200) {
414
+ this.logInvalidResponse(result)
415
+ throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
416
+ }
417
+ if (!result.body) {
418
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
419
+ }
420
+ let data: IUser
421
+ try {
422
+ data = JSON.parse(result.body)
423
+ } catch {
424
+ throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
425
+ }
426
+ return data
427
+ },
428
+
429
+ /**
430
+ * Deletes a user from the organization.
431
+ * @param oid The key of the organization parent organization.
432
+ * @param key The user
433
+ * @param request Optional request options.
434
+ * @returns A promise that resolves when the user is deleted.
435
+ */
436
+ delete: async (oid: string, key: string, request: SdkOptions = {}): Promise<void> => {
437
+ const { token } = request
438
+ const url = this.sdk.getUrl(RouteBuilder.organizationUser(oid, key))
439
+ const result = await this.sdk.http.delete(url.toString(), { token })
440
+ this.inspectCommonStatusCodes(result)
441
+ const E_PREFIX = 'Unable to delete the user. '
442
+ if (result.status !== 204) {
443
+ this.logInvalidResponse(result)
444
+ throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
445
+ }
446
+ },
363
447
  }
364
448
  }