@api-client/core 0.12.9 → 0.12.11
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/browser.d.ts +1 -2
- package/build/src/browser.d.ts.map +1 -1
- package/build/src/browser.js +0 -1
- package/build/src/browser.js.map +1 -1
- package/build/src/exceptions/exception.d.ts +29 -1
- package/build/src/exceptions/exception.d.ts.map +1 -1
- package/build/src/exceptions/exception.js +37 -1
- package/build/src/exceptions/exception.js.map +1 -1
- package/build/src/index.d.ts +1 -2
- package/build/src/index.d.ts.map +1 -1
- package/build/src/index.js +0 -1
- package/build/src/index.js.map +1 -1
- package/build/src/mocking/lib/User.d.ts.map +1 -1
- package/build/src/mocking/lib/User.js +1 -0
- package/build/src/mocking/lib/User.js.map +1 -1
- package/build/src/models/store/User.d.ts +14 -0
- package/build/src/models/store/User.d.ts.map +1 -1
- package/build/src/models/store/User.js.map +1 -1
- package/build/src/proxy/HttpProjectProxy.d.ts.map +1 -1
- package/build/src/proxy/HttpProjectProxy.js +39 -43
- package/build/src/proxy/HttpProjectProxy.js.map +1 -1
- package/build/src/proxy/RequestProxy.d.ts.map +1 -1
- package/build/src/proxy/RequestProxy.js +11 -11
- package/build/src/proxy/RequestProxy.js.map +1 -1
- package/build/src/runtime/store/DataCatalogSdk.d.ts.map +1 -1
- package/build/src/runtime/store/DataCatalogSdk.js +49 -109
- package/build/src/runtime/store/DataCatalogSdk.js.map +1 -1
- package/build/src/runtime/store/FilesSdk.d.ts.map +1 -1
- package/build/src/runtime/store/FilesSdk.js +51 -115
- package/build/src/runtime/store/FilesSdk.js.map +1 -1
- package/build/src/runtime/store/HistorySdk.d.ts.map +1 -1
- package/build/src/runtime/store/HistorySdk.js +25 -70
- package/build/src/runtime/store/HistorySdk.js.map +1 -1
- package/build/src/runtime/store/OrganizationsSdk.d.ts +20 -1
- package/build/src/runtime/store/OrganizationsSdk.d.ts.map +1 -1
- package/build/src/runtime/store/OrganizationsSdk.js +103 -43
- package/build/src/runtime/store/OrganizationsSdk.js.map +1 -1
- package/build/src/runtime/store/RevisionsSdk.d.ts.map +1 -1
- package/build/src/runtime/store/RevisionsSdk.js +5 -10
- package/build/src/runtime/store/RevisionsSdk.js.map +1 -1
- package/build/src/runtime/store/RouteBuilder.d.ts +8 -0
- package/build/src/runtime/store/RouteBuilder.d.ts.map +1 -1
- package/build/src/runtime/store/RouteBuilder.js +12 -0
- package/build/src/runtime/store/RouteBuilder.js.map +1 -1
- package/build/src/runtime/store/SdkBase.d.ts +7 -5
- package/build/src/runtime/store/SdkBase.d.ts.map +1 -1
- package/build/src/runtime/store/SdkBase.js +45 -63
- package/build/src/runtime/store/SdkBase.js.map +1 -1
- package/build/src/runtime/store/SharedSdk.d.ts.map +1 -1
- package/build/src/runtime/store/SharedSdk.js +5 -14
- package/build/src/runtime/store/SharedSdk.js.map +1 -1
- package/build/src/runtime/store/TrashSdk.d.ts.map +1 -1
- package/build/src/runtime/store/TrashSdk.js +8 -28
- package/build/src/runtime/store/TrashSdk.js.map +1 -1
- package/build/src/runtime/store/UsersSdk.d.ts +2 -0
- package/build/src/runtime/store/UsersSdk.d.ts.map +1 -1
- package/build/src/runtime/store/UsersSdk.js +18 -11
- package/build/src/runtime/store/UsersSdk.js.map +1 -1
- package/package.json +1 -1
- package/src/exceptions/exception.ts +51 -4
- package/src/mocking/lib/User.ts +1 -0
- package/src/models/store/User.ts +16 -0
- package/src/proxy/HttpProjectProxy.ts +39 -43
- package/src/proxy/RequestProxy.ts +11 -11
- package/src/runtime/store/DataCatalogSdk.ts +49 -109
- package/src/runtime/store/FilesSdk.ts +51 -115
- package/src/runtime/store/HistorySdk.ts +25 -70
- package/src/runtime/store/OrganizationsSdk.ts +109 -44
- package/src/runtime/store/RevisionsSdk.ts +5 -10
- package/src/runtime/store/RouteBuilder.ts +14 -0
- package/src/runtime/store/SdkBase.ts +46 -65
- package/src/runtime/store/SharedSdk.ts +5 -14
- package/src/runtime/store/TrashSdk.ts +8 -28
- package/src/runtime/store/UsersSdk.ts +18 -11
- package/tests/unit/runtime/proxy/HttpProjectProxy.spec.ts +42 -40
- package/tests/unit/runtime/proxy/RequestProxy.spec.ts +11 -11
- package/build/src/runtime/store/Errors.d.ts +0 -51
- package/build/src/runtime/store/Errors.d.ts.map +0 -1
- package/build/src/runtime/store/Errors.js +0 -61
- package/build/src/runtime/store/Errors.js.map +0 -1
- package/src/runtime/store/Errors.ts +0 -98
|
@@ -7,11 +7,12 @@ import {
|
|
|
7
7
|
SdkOptions,
|
|
8
8
|
} from './SdkBase.js'
|
|
9
9
|
import { RouteBuilder } from './RouteBuilder.js'
|
|
10
|
-
import type { ContextListResult } from '../../events/BaseEvents.js'
|
|
10
|
+
import type { ContextListOptions, ContextListResult } from '../../events/BaseEvents.js'
|
|
11
11
|
import type { IOrganization, UserOrganizationGrantType } from '../../models/store/Organization.js'
|
|
12
12
|
import type { InvitationSchema } from '../../models/store/Invitation.js'
|
|
13
|
-
import { SdkError } from './Errors.js'
|
|
14
13
|
import type { PatchInfo } from '../../patch/types.js'
|
|
14
|
+
import type { IUser } from '../../models/store/User.js'
|
|
15
|
+
import { Exception } from '../../exceptions/exception.js'
|
|
15
16
|
|
|
16
17
|
export class OrganizationsSdk extends SdkBase {
|
|
17
18
|
/**
|
|
@@ -25,24 +26,19 @@ export class OrganizationsSdk extends SdkBase {
|
|
|
25
26
|
const E_PREFIX = 'Unable to list your organizations. '
|
|
26
27
|
if (result.status !== 200) {
|
|
27
28
|
this.logInvalidResponse(result)
|
|
28
|
-
|
|
29
|
-
if (!e) {
|
|
30
|
-
e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status)
|
|
31
|
-
e.response = result.body
|
|
32
|
-
}
|
|
33
|
-
throw e
|
|
29
|
+
throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
|
|
34
30
|
}
|
|
35
31
|
if (!result.body) {
|
|
36
|
-
throw new
|
|
32
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
|
|
37
33
|
}
|
|
38
34
|
let data: ContextListResult<IOrganization>
|
|
39
35
|
try {
|
|
40
36
|
data = JSON.parse(result.body)
|
|
41
37
|
} catch {
|
|
42
|
-
throw new
|
|
38
|
+
throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
|
|
43
39
|
}
|
|
44
40
|
if (!Array.isArray(data.items)) {
|
|
45
|
-
throw new
|
|
41
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
|
|
46
42
|
}
|
|
47
43
|
return data
|
|
48
44
|
}
|
|
@@ -63,19 +59,20 @@ export class OrganizationsSdk extends SdkBase {
|
|
|
63
59
|
this.inspectCommonStatusCodes(result)
|
|
64
60
|
const E_PREFIX = 'Unable to create an organization. '
|
|
65
61
|
if (result.status !== 200) {
|
|
66
|
-
|
|
62
|
+
this.logInvalidResponse(result)
|
|
63
|
+
throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
|
|
67
64
|
}
|
|
68
65
|
if (!result.body) {
|
|
69
|
-
throw new
|
|
66
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
|
|
70
67
|
}
|
|
71
68
|
let data: IOrganization
|
|
72
69
|
try {
|
|
73
70
|
data = JSON.parse(result.body)
|
|
74
71
|
} catch {
|
|
75
|
-
throw new
|
|
72
|
+
throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
|
|
76
73
|
}
|
|
77
74
|
if (!data.kind) {
|
|
78
|
-
throw new
|
|
75
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
|
|
79
76
|
}
|
|
80
77
|
return data
|
|
81
78
|
}
|
|
@@ -94,24 +91,19 @@ export class OrganizationsSdk extends SdkBase {
|
|
|
94
91
|
const E_PREFIX = 'Unable to list organization invitations. '
|
|
95
92
|
if (result.status !== 200) {
|
|
96
93
|
this.logInvalidResponse(result)
|
|
97
|
-
|
|
98
|
-
if (!e) {
|
|
99
|
-
e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status)
|
|
100
|
-
e.response = result.body
|
|
101
|
-
}
|
|
102
|
-
throw e
|
|
94
|
+
throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
|
|
103
95
|
}
|
|
104
96
|
if (!result.body) {
|
|
105
|
-
throw new
|
|
97
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
|
|
106
98
|
}
|
|
107
99
|
let data: ContextListResult<InvitationSchema>
|
|
108
100
|
try {
|
|
109
101
|
data = JSON.parse(result.body)
|
|
110
102
|
} catch {
|
|
111
|
-
throw new
|
|
103
|
+
throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
|
|
112
104
|
}
|
|
113
105
|
if (!Array.isArray(data.items)) {
|
|
114
|
-
throw new
|
|
106
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
|
|
115
107
|
}
|
|
116
108
|
return data
|
|
117
109
|
}
|
|
@@ -148,19 +140,20 @@ export class OrganizationsSdk extends SdkBase {
|
|
|
148
140
|
this.inspectCommonStatusCodes(result)
|
|
149
141
|
const E_PREFIX = 'Unable to create an invitation. '
|
|
150
142
|
if (result.status !== 200) {
|
|
151
|
-
|
|
143
|
+
this.logInvalidResponse(result)
|
|
144
|
+
throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
|
|
152
145
|
}
|
|
153
146
|
if (!result.body) {
|
|
154
|
-
throw new
|
|
147
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
|
|
155
148
|
}
|
|
156
149
|
let data: InvitationSchema
|
|
157
150
|
try {
|
|
158
151
|
data = JSON.parse(result.body)
|
|
159
152
|
} catch {
|
|
160
|
-
throw new
|
|
153
|
+
throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
|
|
161
154
|
}
|
|
162
155
|
if (!data.kind) {
|
|
163
|
-
throw new
|
|
156
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
|
|
164
157
|
}
|
|
165
158
|
return data
|
|
166
159
|
}
|
|
@@ -179,19 +172,20 @@ export class OrganizationsSdk extends SdkBase {
|
|
|
179
172
|
this.inspectCommonStatusCodes(result)
|
|
180
173
|
const E_PREFIX = 'Unable to find invitation by token. '
|
|
181
174
|
if (result.status !== 200) {
|
|
182
|
-
|
|
175
|
+
this.logInvalidResponse(result)
|
|
176
|
+
throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
|
|
183
177
|
}
|
|
184
178
|
if (!result.body) {
|
|
185
|
-
throw new
|
|
179
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
|
|
186
180
|
}
|
|
187
181
|
let data: InvitationSchema
|
|
188
182
|
try {
|
|
189
183
|
data = JSON.parse(result.body)
|
|
190
184
|
} catch {
|
|
191
|
-
throw new
|
|
185
|
+
throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
|
|
192
186
|
}
|
|
193
187
|
if (!data.kind) {
|
|
194
|
-
throw new
|
|
188
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
|
|
195
189
|
}
|
|
196
190
|
return data
|
|
197
191
|
}
|
|
@@ -209,19 +203,20 @@ export class OrganizationsSdk extends SdkBase {
|
|
|
209
203
|
this.inspectCommonStatusCodes(result)
|
|
210
204
|
const E_PREFIX = 'Unable to decline invitation. '
|
|
211
205
|
if (result.status !== 200) {
|
|
212
|
-
|
|
206
|
+
this.logInvalidResponse(result)
|
|
207
|
+
throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
|
|
213
208
|
}
|
|
214
209
|
if (!result.body) {
|
|
215
|
-
throw new
|
|
210
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
|
|
216
211
|
}
|
|
217
212
|
let data: InvitationSchema
|
|
218
213
|
try {
|
|
219
214
|
data = JSON.parse(result.body)
|
|
220
215
|
} catch {
|
|
221
|
-
throw new
|
|
216
|
+
throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
|
|
222
217
|
}
|
|
223
218
|
if (!data.kind) {
|
|
224
|
-
throw new
|
|
219
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
|
|
225
220
|
}
|
|
226
221
|
return data
|
|
227
222
|
}
|
|
@@ -239,19 +234,20 @@ export class OrganizationsSdk extends SdkBase {
|
|
|
239
234
|
this.inspectCommonStatusCodes(result)
|
|
240
235
|
const E_PREFIX = 'Unable to delete invitation. '
|
|
241
236
|
if (result.status !== 200) {
|
|
242
|
-
|
|
237
|
+
this.logInvalidResponse(result)
|
|
238
|
+
throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
|
|
243
239
|
}
|
|
244
240
|
if (!result.body) {
|
|
245
|
-
throw new
|
|
241
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
|
|
246
242
|
}
|
|
247
243
|
let data: InvitationSchema
|
|
248
244
|
try {
|
|
249
245
|
data = JSON.parse(result.body)
|
|
250
246
|
} catch {
|
|
251
|
-
throw new
|
|
247
|
+
throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
|
|
252
248
|
}
|
|
253
249
|
if (!data.kind) {
|
|
254
|
-
throw new
|
|
250
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
|
|
255
251
|
}
|
|
256
252
|
return data
|
|
257
253
|
}
|
|
@@ -280,19 +276,88 @@ export class OrganizationsSdk extends SdkBase {
|
|
|
280
276
|
this.inspectCommonStatusCodes(result)
|
|
281
277
|
const E_PREFIX = 'Unable to update invitation. '
|
|
282
278
|
if (result.status !== 200) {
|
|
283
|
-
|
|
279
|
+
this.logInvalidResponse(result)
|
|
280
|
+
throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
|
|
284
281
|
}
|
|
285
282
|
if (!result.body) {
|
|
286
|
-
throw new
|
|
283
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
|
|
287
284
|
}
|
|
288
285
|
let data: InvitationSchema
|
|
289
286
|
try {
|
|
290
287
|
data = JSON.parse(result.body)
|
|
291
288
|
} catch {
|
|
292
|
-
throw new
|
|
289
|
+
throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
|
|
293
290
|
}
|
|
294
291
|
if (!data.kind) {
|
|
295
|
-
throw new
|
|
292
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
|
|
293
|
+
}
|
|
294
|
+
return data
|
|
295
|
+
}
|
|
296
|
+
|
|
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
|
+
}
|
|
333
|
+
|
|
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 })
|
|
296
361
|
}
|
|
297
362
|
return data
|
|
298
363
|
}
|
|
@@ -8,8 +8,8 @@ import {
|
|
|
8
8
|
} from './SdkBase.js'
|
|
9
9
|
import { RouteBuilder } from './RouteBuilder.js'
|
|
10
10
|
import type { ContextListResult, ContextListOptions } from '../../events/BaseEvents.js'
|
|
11
|
-
import { SdkError } from './Errors.js'
|
|
12
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
|
/**
|
|
@@ -32,24 +32,19 @@ export class RevisionsSdk extends SdkBase {
|
|
|
32
32
|
const E_PREFIX = 'Unable to list revisions for a file. '
|
|
33
33
|
if (result.status !== 200) {
|
|
34
34
|
this.logInvalidResponse(result)
|
|
35
|
-
|
|
36
|
-
if (!e) {
|
|
37
|
-
e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status)
|
|
38
|
-
e.response = result.body
|
|
39
|
-
}
|
|
40
|
-
throw e
|
|
35
|
+
throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
|
|
41
36
|
}
|
|
42
37
|
if (!result.body) {
|
|
43
|
-
throw new
|
|
38
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
|
|
44
39
|
}
|
|
45
40
|
let data: ContextListResult<IRevision>
|
|
46
41
|
try {
|
|
47
42
|
data = JSON.parse(result.body)
|
|
48
43
|
} catch {
|
|
49
|
-
throw new
|
|
44
|
+
throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
|
|
50
45
|
}
|
|
51
46
|
if (!Array.isArray(data.items)) {
|
|
52
|
-
throw new
|
|
47
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
|
|
53
48
|
}
|
|
54
49
|
return data
|
|
55
50
|
}
|
|
@@ -162,10 +162,24 @@ export class RouteBuilder {
|
|
|
162
162
|
return `/v1/orgs/${oid}`
|
|
163
163
|
}
|
|
164
164
|
|
|
165
|
+
static organizationUsers(oid: string): string {
|
|
166
|
+
return `${this.organization(oid)}/users`
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
static organizationUser(oid: string, key: string): string {
|
|
170
|
+
return `${this.organization(oid)}/users/${key}`
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* @deprecated Use `organizationUsers` instead.
|
|
175
|
+
*/
|
|
165
176
|
static users(oid: string): string {
|
|
166
177
|
return `${this.organization(oid)}/users`
|
|
167
178
|
}
|
|
168
179
|
|
|
180
|
+
/**
|
|
181
|
+
* @deprecated Use `organizationUser` instead.
|
|
182
|
+
*/
|
|
169
183
|
static user(oid: string, key: string): string {
|
|
170
184
|
return `${this.organization(oid)}/users/${key}`
|
|
171
185
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/* eslint-disable no-console */
|
|
2
2
|
import { Headers } from '../../lib/headers/Headers.js'
|
|
3
3
|
import { Sdk } from './Sdk.js'
|
|
4
|
-
import { SdkError, IApiError } from './Errors.js'
|
|
5
4
|
import {
|
|
6
5
|
ContextDeleteRecord,
|
|
7
6
|
ContextListOptions,
|
|
8
7
|
ContextListResult,
|
|
9
8
|
IBulkOperationResult,
|
|
10
9
|
} from '../../events/BaseEvents.js'
|
|
10
|
+
import { Exception } from '../../exceptions/exception.js'
|
|
11
11
|
|
|
12
12
|
export interface SdkOptions {
|
|
13
13
|
/**
|
|
@@ -65,61 +65,59 @@ export class SdkBase {
|
|
|
65
65
|
protected inspectCommonStatusCodes(response: IStoreResponse): void {
|
|
66
66
|
const { status, body } = response
|
|
67
67
|
if (status === 404) {
|
|
68
|
-
|
|
69
|
-
if (
|
|
70
|
-
e
|
|
71
|
-
|
|
68
|
+
const e = this.createApiError('Not found', body)
|
|
69
|
+
if (e.status !== 404) {
|
|
70
|
+
e.setStatus(404)
|
|
71
|
+
}
|
|
72
|
+
if (e.code !== 'E_NOT_FOUND') {
|
|
73
|
+
e.setCode('E_NOT_FOUND')
|
|
72
74
|
}
|
|
73
75
|
throw e
|
|
74
76
|
}
|
|
75
77
|
if (status === 403) {
|
|
76
|
-
|
|
77
|
-
if (
|
|
78
|
-
e
|
|
79
|
-
|
|
78
|
+
const e = this.createApiError('You have no access to this resource', body)
|
|
79
|
+
if (e.status !== 403) {
|
|
80
|
+
e.setStatus(403)
|
|
81
|
+
}
|
|
82
|
+
if (e.code !== 'E_FORBIDDEN') {
|
|
83
|
+
e.setCode('E_FORBIDDEN')
|
|
80
84
|
}
|
|
81
85
|
throw e
|
|
82
86
|
}
|
|
83
87
|
if (status === 401) {
|
|
84
|
-
|
|
85
|
-
if (
|
|
86
|
-
e
|
|
87
|
-
|
|
88
|
+
const e = this.createApiError('Not authorized', body)
|
|
89
|
+
if (e.status !== 401) {
|
|
90
|
+
e.setStatus(401)
|
|
91
|
+
}
|
|
92
|
+
if (e.code !== 'E_UNAUTHORIZED') {
|
|
93
|
+
e.setCode('E_UNAUTHORIZED')
|
|
88
94
|
}
|
|
89
95
|
throw e
|
|
90
96
|
}
|
|
91
97
|
}
|
|
92
98
|
|
|
93
99
|
/**
|
|
94
|
-
*
|
|
100
|
+
* Creates an Exception from the response body.
|
|
101
|
+
* It reads the error details from the body.
|
|
102
|
+
*
|
|
103
|
+
* @param defaultMessage The default message to use if the body does not contain a message.
|
|
95
104
|
* @param body The message returned by the store.
|
|
96
|
-
* @returns The
|
|
105
|
+
* @returns The Exception or undefined when not an error.
|
|
97
106
|
*/
|
|
98
|
-
protected
|
|
107
|
+
protected createApiError(defaultMessage: string, body?: string): Exception {
|
|
99
108
|
if (!body) {
|
|
100
|
-
return
|
|
109
|
+
return new Exception(defaultMessage)
|
|
101
110
|
}
|
|
102
|
-
let data:
|
|
111
|
+
let data: Record<string, string | number>
|
|
103
112
|
try {
|
|
104
113
|
data = JSON.parse(body)
|
|
105
114
|
} catch {
|
|
106
|
-
return
|
|
115
|
+
return new Exception(defaultMessage)
|
|
107
116
|
}
|
|
108
|
-
if (data
|
|
109
|
-
return
|
|
117
|
+
if (!data || typeof data !== 'object' || !data.message) {
|
|
118
|
+
return new Exception(defaultMessage)
|
|
110
119
|
}
|
|
111
|
-
return
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
protected createGenericSdkError(body?: string): SdkError | undefined {
|
|
115
|
-
const info = this.readErrorResponse(body)
|
|
116
|
-
if (!info) {
|
|
117
|
-
return undefined
|
|
118
|
-
}
|
|
119
|
-
const e = new SdkError(info.message, info.code)
|
|
120
|
-
e.detail = info.detail
|
|
121
|
-
e.response = body
|
|
122
|
-
return e
|
|
120
|
+
return Exception.fromRawException(data, defaultMessage)
|
|
123
121
|
}
|
|
124
122
|
|
|
125
123
|
/**
|
|
@@ -141,25 +139,20 @@ export class SdkBase {
|
|
|
141
139
|
const E_PREFIX = 'Unable to delete in batch. '
|
|
142
140
|
if (result.status !== 200) {
|
|
143
141
|
this.logInvalidResponse(result)
|
|
144
|
-
|
|
145
|
-
if (!e) {
|
|
146
|
-
e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status)
|
|
147
|
-
e.response = result.body
|
|
148
|
-
}
|
|
149
|
-
throw e
|
|
142
|
+
throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
|
|
150
143
|
}
|
|
151
144
|
if (!result.body) {
|
|
152
|
-
throw new
|
|
145
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
|
|
153
146
|
}
|
|
154
147
|
|
|
155
148
|
let data: IBulkOperationResult<ContextDeleteRecord>
|
|
156
149
|
try {
|
|
157
150
|
data = JSON.parse(result.body)
|
|
158
151
|
} catch {
|
|
159
|
-
throw new
|
|
152
|
+
throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
|
|
160
153
|
}
|
|
161
154
|
if (!Array.isArray(data.items)) {
|
|
162
|
-
throw new
|
|
155
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
|
|
163
156
|
}
|
|
164
157
|
return data
|
|
165
158
|
}
|
|
@@ -177,12 +170,7 @@ export class SdkBase {
|
|
|
177
170
|
const E_PREFIX = 'Unable to delete the object. '
|
|
178
171
|
if (result.status !== 204) {
|
|
179
172
|
this.logInvalidResponse(result)
|
|
180
|
-
|
|
181
|
-
if (!e) {
|
|
182
|
-
e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status)
|
|
183
|
-
e.response = result.body
|
|
184
|
-
}
|
|
185
|
-
throw e
|
|
173
|
+
throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
|
|
186
174
|
}
|
|
187
175
|
}
|
|
188
176
|
|
|
@@ -198,24 +186,19 @@ export class SdkBase {
|
|
|
198
186
|
const E_PREFIX = 'Unable to list revisions for a file. '
|
|
199
187
|
if (result.status !== 200) {
|
|
200
188
|
this.logInvalidResponse(result)
|
|
201
|
-
|
|
202
|
-
if (!e) {
|
|
203
|
-
e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status)
|
|
204
|
-
e.response = result.body
|
|
205
|
-
}
|
|
206
|
-
throw e
|
|
189
|
+
throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
|
|
207
190
|
}
|
|
208
191
|
if (!result.body) {
|
|
209
|
-
throw new
|
|
192
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
|
|
210
193
|
}
|
|
211
194
|
let data: ContextListResult<unknown>
|
|
212
195
|
try {
|
|
213
196
|
data = JSON.parse(result.body)
|
|
214
197
|
} catch {
|
|
215
|
-
throw new
|
|
198
|
+
throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
|
|
216
199
|
}
|
|
217
200
|
if (!Array.isArray(data.items)) {
|
|
218
|
-
throw new
|
|
201
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
|
|
219
202
|
}
|
|
220
203
|
return data
|
|
221
204
|
}
|
|
@@ -223,15 +206,13 @@ export class SdkBase {
|
|
|
223
206
|
protected readResponseBody(response: IStoreResponse, errorPrefix: string): string {
|
|
224
207
|
if (response.status !== 200) {
|
|
225
208
|
this.logInvalidResponse(response)
|
|
226
|
-
|
|
227
|
-
if (!e) {
|
|
228
|
-
e = new SdkError(`${errorPrefix}${E_RESPONSE_STATUS}${response.status}`, response.status)
|
|
229
|
-
e.response = response.body
|
|
230
|
-
}
|
|
231
|
-
throw e
|
|
209
|
+
throw this.createApiError(`${errorPrefix}${E_RESPONSE_STATUS}${response.status}`, response.body)
|
|
232
210
|
}
|
|
233
211
|
if (!response.body) {
|
|
234
|
-
throw new
|
|
212
|
+
throw new Exception(`${errorPrefix}${E_RESPONSE_NO_VALUE}`, {
|
|
213
|
+
code: 'E_RESPONSE_NO_VALUE',
|
|
214
|
+
status: response.status,
|
|
215
|
+
})
|
|
235
216
|
}
|
|
236
217
|
return response.body
|
|
237
218
|
}
|
|
@@ -242,7 +223,7 @@ export class SdkBase {
|
|
|
242
223
|
try {
|
|
243
224
|
data = JSON.parse(body)
|
|
244
225
|
} catch {
|
|
245
|
-
throw new
|
|
226
|
+
throw new Exception(`${errorPrefix}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: response.status })
|
|
246
227
|
}
|
|
247
228
|
return data
|
|
248
229
|
}
|
|
@@ -8,9 +8,9 @@ import {
|
|
|
8
8
|
} from './SdkBase.js'
|
|
9
9
|
import { RouteBuilder } from './RouteBuilder.js'
|
|
10
10
|
import { IFile } from '../../models/store/File.js'
|
|
11
|
-
import { SdkError } from './Errors.js'
|
|
12
11
|
import { ListFileKind } from './FilesSdk.js'
|
|
13
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
|
/**
|
|
@@ -37,28 +37,19 @@ export class SharedSdk extends SdkBase {
|
|
|
37
37
|
const E_PREFIX = 'Unable to list organizations. '
|
|
38
38
|
if (result.status !== 200) {
|
|
39
39
|
this.logInvalidResponse(result)
|
|
40
|
-
|
|
41
|
-
if (!e) {
|
|
42
|
-
e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status)
|
|
43
|
-
e.response = result.body
|
|
44
|
-
}
|
|
45
|
-
throw e
|
|
40
|
+
throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
|
|
46
41
|
}
|
|
47
42
|
if (!result.body) {
|
|
48
|
-
throw new
|
|
43
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
|
|
49
44
|
}
|
|
50
45
|
let data: ContextListResult<IFile>
|
|
51
46
|
try {
|
|
52
47
|
data = JSON.parse(result.body)
|
|
53
48
|
} catch {
|
|
54
|
-
|
|
55
|
-
err.response = result.body
|
|
56
|
-
throw err
|
|
49
|
+
throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
|
|
57
50
|
}
|
|
58
51
|
if (!Array.isArray(data.items)) {
|
|
59
|
-
|
|
60
|
-
err.response = result.body
|
|
61
|
-
throw err
|
|
52
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
|
|
62
53
|
}
|
|
63
54
|
return data
|
|
64
55
|
}
|