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