@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/build/src/sdk/GroupsSdk.d.ts +2 -0
- package/build/src/sdk/GroupsSdk.d.ts.map +1 -1
- package/build/src/sdk/GroupsSdk.js +64 -0
- package/build/src/sdk/GroupsSdk.js.map +1 -1
- package/build/src/sdk/RouteBuilder.d.ts +1 -0
- package/build/src/sdk/RouteBuilder.d.ts.map +1 -1
- package/build/src/sdk/RouteBuilder.js +3 -0
- package/build/src/sdk/RouteBuilder.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/sdk/GroupsSdk.ts +64 -0
- package/src/sdk/RouteBuilder.ts +4 -0
package/package.json
CHANGED
package/src/sdk/GroupsSdk.ts
CHANGED
|
@@ -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
|
}
|
package/src/sdk/RouteBuilder.ts
CHANGED
|
@@ -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
|
}
|