@api-client/core 0.14.4 → 0.14.5

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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@api-client/core",
3
3
  "description": "The API Client's core client library. Works in NodeJS and in a ES enabled browser.",
4
- "version": "0.14.4",
4
+ "version": "0.14.5",
5
5
  "license": "Apache-2.0",
6
6
  "exports": {
7
7
  "./browser.js": {
@@ -147,4 +147,68 @@ export class GroupsSdk extends SdkBase {
147
147
  throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
148
148
  }
149
149
  }
150
+
151
+ async addUsers(oid: string, gid: string, uids: string[], request: SdkOptions = {}): Promise<GroupSchema> {
152
+ const { token } = request
153
+ const url = this.sdk.getUrl(RouteBuilder.groupUsers(oid, gid))
154
+ const body = JSON.stringify({ ids: uids })
155
+ const result = await this.sdk.http.post(url.toString(), {
156
+ token,
157
+ body,
158
+ headers: {
159
+ 'content-type': 'application/json',
160
+ },
161
+ })
162
+ this.inspectCommonStatusCodes(result)
163
+ const E_PREFIX = 'Unable to add users to a group. '
164
+ if (result.status !== 200) {
165
+ this.logInvalidResponse(result)
166
+ throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
167
+ }
168
+ if (!result.body) {
169
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
170
+ }
171
+ let data: GroupSchema
172
+ try {
173
+ data = JSON.parse(result.body)
174
+ } catch {
175
+ throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
176
+ }
177
+ if (!data.key) {
178
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
179
+ }
180
+ return data
181
+ }
182
+
183
+ async removeUsers(oid: string, gid: string, uids: string[], request: SdkOptions = {}): Promise<GroupSchema> {
184
+ const { token } = request
185
+ const url = this.sdk.getUrl(RouteBuilder.groupUsers(oid, gid))
186
+ const body = JSON.stringify({ ids: uids })
187
+ const result = await this.sdk.http.delete(url.toString(), {
188
+ token,
189
+ body,
190
+ headers: {
191
+ 'content-type': 'application/json',
192
+ },
193
+ })
194
+ this.inspectCommonStatusCodes(result)
195
+ const E_PREFIX = 'Unable to remove users from a group. '
196
+ if (result.status !== 200) {
197
+ this.logInvalidResponse(result)
198
+ throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
199
+ }
200
+ if (!result.body) {
201
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
202
+ }
203
+ let data: GroupSchema
204
+ try {
205
+ data = JSON.parse(result.body)
206
+ } catch {
207
+ throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
208
+ }
209
+ if (!data.key) {
210
+ throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
211
+ }
212
+ return data
213
+ }
150
214
  }
@@ -295,4 +295,8 @@ export class RouteBuilder {
295
295
  static group(oid: string, gid: string): string {
296
296
  return `/v1/orgs/${oid}/groups/${gid}`
297
297
  }
298
+
299
+ static groupUsers(oid: string, gid: string): string | undefined {
300
+ return `/v1/orgs/${oid}/groups/${gid}/users`
301
+ }
298
302
  }