@api-client/core 0.12.10 → 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 +0 -1
- 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 +0 -1
- 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/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.map +1 -1
- package/build/src/runtime/store/OrganizationsSdk.js +46 -50
- 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/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.map +1 -1
- package/build/src/runtime/store/UsersSdk.js +12 -11
- package/build/src/runtime/store/UsersSdk.js.map +1 -1
- package/data/models/example-generator-api.json +8 -8
- package/package.json +1 -1
- package/src/exceptions/exception.ts +51 -4
- 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 +46 -50
- package/src/runtime/store/RevisionsSdk.ts +5 -10
- 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 +12 -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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Exception } from '../../exceptions/exception.js';
|
|
2
2
|
export const E_INVALID_JSON = 'Invalid JSON response.';
|
|
3
3
|
export const E_RESPONSE_NO_VALUE = 'The response has no value.';
|
|
4
4
|
export const E_RESPONSE_STATUS = 'Invalid response status: ';
|
|
@@ -32,60 +32,59 @@ export class SdkBase {
|
|
|
32
32
|
inspectCommonStatusCodes(response) {
|
|
33
33
|
const { status, body } = response;
|
|
34
34
|
if (status === 404) {
|
|
35
|
-
|
|
36
|
-
if (
|
|
37
|
-
e
|
|
38
|
-
|
|
35
|
+
const e = this.createApiError('Not found', body);
|
|
36
|
+
if (e.status !== 404) {
|
|
37
|
+
e.setStatus(404);
|
|
38
|
+
}
|
|
39
|
+
if (e.code !== 'E_NOT_FOUND') {
|
|
40
|
+
e.setCode('E_NOT_FOUND');
|
|
39
41
|
}
|
|
40
42
|
throw e;
|
|
41
43
|
}
|
|
42
44
|
if (status === 403) {
|
|
43
|
-
|
|
44
|
-
if (
|
|
45
|
-
e
|
|
46
|
-
|
|
45
|
+
const e = this.createApiError('You have no access to this resource', body);
|
|
46
|
+
if (e.status !== 403) {
|
|
47
|
+
e.setStatus(403);
|
|
48
|
+
}
|
|
49
|
+
if (e.code !== 'E_FORBIDDEN') {
|
|
50
|
+
e.setCode('E_FORBIDDEN');
|
|
47
51
|
}
|
|
48
52
|
throw e;
|
|
49
53
|
}
|
|
50
54
|
if (status === 401) {
|
|
51
|
-
|
|
52
|
-
if (
|
|
53
|
-
e
|
|
54
|
-
|
|
55
|
+
const e = this.createApiError('Not authorized', body);
|
|
56
|
+
if (e.status !== 401) {
|
|
57
|
+
e.setStatus(401);
|
|
58
|
+
}
|
|
59
|
+
if (e.code !== 'E_UNAUTHORIZED') {
|
|
60
|
+
e.setCode('E_UNAUTHORIZED');
|
|
55
61
|
}
|
|
56
62
|
throw e;
|
|
57
63
|
}
|
|
58
64
|
}
|
|
59
65
|
/**
|
|
60
|
-
*
|
|
66
|
+
* Creates an Exception from the response body.
|
|
67
|
+
* It reads the error details from the body.
|
|
68
|
+
*
|
|
69
|
+
* @param defaultMessage The default message to use if the body does not contain a message.
|
|
61
70
|
* @param body The message returned by the store.
|
|
62
|
-
* @returns The
|
|
71
|
+
* @returns The Exception or undefined when not an error.
|
|
63
72
|
*/
|
|
64
|
-
|
|
73
|
+
createApiError(defaultMessage, body) {
|
|
65
74
|
if (!body) {
|
|
66
|
-
return
|
|
75
|
+
return new Exception(defaultMessage);
|
|
67
76
|
}
|
|
68
77
|
let data;
|
|
69
78
|
try {
|
|
70
79
|
data = JSON.parse(body);
|
|
71
80
|
}
|
|
72
81
|
catch {
|
|
73
|
-
return
|
|
82
|
+
return new Exception(defaultMessage);
|
|
74
83
|
}
|
|
75
|
-
if (data
|
|
76
|
-
return
|
|
84
|
+
if (!data || typeof data !== 'object' || !data.message) {
|
|
85
|
+
return new Exception(defaultMessage);
|
|
77
86
|
}
|
|
78
|
-
return
|
|
79
|
-
}
|
|
80
|
-
createGenericSdkError(body) {
|
|
81
|
-
const info = this.readErrorResponse(body);
|
|
82
|
-
if (!info) {
|
|
83
|
-
return undefined;
|
|
84
|
-
}
|
|
85
|
-
const e = new SdkError(info.message, info.code);
|
|
86
|
-
e.detail = info.detail;
|
|
87
|
-
e.response = body;
|
|
88
|
-
return e;
|
|
87
|
+
return Exception.fromRawException(data, defaultMessage);
|
|
89
88
|
}
|
|
90
89
|
/**
|
|
91
90
|
* A generic (common) method to batch-delete object from the store.
|
|
@@ -102,25 +101,20 @@ export class SdkBase {
|
|
|
102
101
|
const E_PREFIX = 'Unable to delete in batch. ';
|
|
103
102
|
if (result.status !== 200) {
|
|
104
103
|
this.logInvalidResponse(result);
|
|
105
|
-
|
|
106
|
-
if (!e) {
|
|
107
|
-
e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status);
|
|
108
|
-
e.response = result.body;
|
|
109
|
-
}
|
|
110
|
-
throw e;
|
|
104
|
+
throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body);
|
|
111
105
|
}
|
|
112
106
|
if (!result.body) {
|
|
113
|
-
throw new
|
|
107
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status });
|
|
114
108
|
}
|
|
115
109
|
let data;
|
|
116
110
|
try {
|
|
117
111
|
data = JSON.parse(result.body);
|
|
118
112
|
}
|
|
119
113
|
catch {
|
|
120
|
-
throw new
|
|
114
|
+
throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status });
|
|
121
115
|
}
|
|
122
116
|
if (!Array.isArray(data.items)) {
|
|
123
|
-
throw new
|
|
117
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status });
|
|
124
118
|
}
|
|
125
119
|
return data;
|
|
126
120
|
}
|
|
@@ -137,12 +131,7 @@ export class SdkBase {
|
|
|
137
131
|
const E_PREFIX = 'Unable to delete the object. ';
|
|
138
132
|
if (result.status !== 204) {
|
|
139
133
|
this.logInvalidResponse(result);
|
|
140
|
-
|
|
141
|
-
if (!e) {
|
|
142
|
-
e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status);
|
|
143
|
-
e.response = result.body;
|
|
144
|
-
}
|
|
145
|
-
throw e;
|
|
134
|
+
throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body);
|
|
146
135
|
}
|
|
147
136
|
}
|
|
148
137
|
async genericList(url, options, request = {}) {
|
|
@@ -153,40 +142,33 @@ export class SdkBase {
|
|
|
153
142
|
const E_PREFIX = 'Unable to list revisions for a file. ';
|
|
154
143
|
if (result.status !== 200) {
|
|
155
144
|
this.logInvalidResponse(result);
|
|
156
|
-
|
|
157
|
-
if (!e) {
|
|
158
|
-
e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status);
|
|
159
|
-
e.response = result.body;
|
|
160
|
-
}
|
|
161
|
-
throw e;
|
|
145
|
+
throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body);
|
|
162
146
|
}
|
|
163
147
|
if (!result.body) {
|
|
164
|
-
throw new
|
|
148
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status });
|
|
165
149
|
}
|
|
166
150
|
let data;
|
|
167
151
|
try {
|
|
168
152
|
data = JSON.parse(result.body);
|
|
169
153
|
}
|
|
170
154
|
catch {
|
|
171
|
-
throw new
|
|
155
|
+
throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status });
|
|
172
156
|
}
|
|
173
157
|
if (!Array.isArray(data.items)) {
|
|
174
|
-
throw new
|
|
158
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status });
|
|
175
159
|
}
|
|
176
160
|
return data;
|
|
177
161
|
}
|
|
178
162
|
readResponseBody(response, errorPrefix) {
|
|
179
163
|
if (response.status !== 200) {
|
|
180
164
|
this.logInvalidResponse(response);
|
|
181
|
-
|
|
182
|
-
if (!e) {
|
|
183
|
-
e = new SdkError(`${errorPrefix}${E_RESPONSE_STATUS}${response.status}`, response.status);
|
|
184
|
-
e.response = response.body;
|
|
185
|
-
}
|
|
186
|
-
throw e;
|
|
165
|
+
throw this.createApiError(`${errorPrefix}${E_RESPONSE_STATUS}${response.status}`, response.body);
|
|
187
166
|
}
|
|
188
167
|
if (!response.body) {
|
|
189
|
-
throw new
|
|
168
|
+
throw new Exception(`${errorPrefix}${E_RESPONSE_NO_VALUE}`, {
|
|
169
|
+
code: 'E_RESPONSE_NO_VALUE',
|
|
170
|
+
status: response.status,
|
|
171
|
+
});
|
|
190
172
|
}
|
|
191
173
|
return response.body;
|
|
192
174
|
}
|
|
@@ -197,7 +179,7 @@ export class SdkBase {
|
|
|
197
179
|
data = JSON.parse(body);
|
|
198
180
|
}
|
|
199
181
|
catch {
|
|
200
|
-
throw new
|
|
182
|
+
throw new Exception(`${errorPrefix}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: response.status });
|
|
201
183
|
}
|
|
202
184
|
return data;
|
|
203
185
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SdkBase.js","sourceRoot":"","sources":["../../../../src/runtime/store/SdkBase.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAa,MAAM,aAAa,CAAA;AAgCjD,MAAM,CAAC,MAAM,cAAc,GAAG,wBAAwB,CAAA;AACtD,MAAM,CAAC,MAAM,mBAAmB,GAAG,4BAA4B,CAAA;AAC/D,MAAM,CAAC,MAAM,iBAAiB,GAAG,2BAA2B,CAAA;AAC5D,MAAM,CAAC,MAAM,kBAAkB,GAAG,mCAAmC,CAAA;AACrE,MAAM,CAAC,MAAM,mBAAmB,GAAG,wCAAwC,CAAA;AAE3E,MAAM,OAAO,OAAO;IACC;IAAnB,YAAmB,GAAQ;QAAR,QAAG,GAAH,GAAG,CAAK;IAAG,CAAC;IAErB,kBAAkB,CAAC,QAAwB;QACnD,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC;YACpB,OAAM;QACR,CAAC;QACD,IAAI,QAAQ,CAAC,IAAI,EAAE,CAAC;YAClB,IAAI,CAAC;gBACH,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;gBACtC,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;oBACjB,OAAO,CAAC,IAAI,CAAC,oBAAoB,IAAI,CAAC,OAAO,EAAE,CAAC,CAAA;gBAClD,CAAC;YACH,CAAC;YAAC,MAAM,CAAC;gBACP,IAAI;YACN,CAAC;QACH,CAAC;IACH,CAAC;IAED;;;OAGG;IACO,wBAAwB,CAAC,QAAwB;QACzD,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,QAAQ,CAAA;QACjC,IAAI,MAAM,KAAK,GAAG,EAAE,CAAC;YACnB,IAAI,CAAC,GAAG,IAAI,CAAC,qBAAqB,C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A;QACzD,IAAI,IAAa,CAAA;QACjB,IAAI,CAAC;YACH,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;QACzB,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,IAAI,KAAK,CAAC,GAAG,WAAW,GAAG,cAAc,GAAG,CAAC,CAAA;QACrD,CAAC;QACD,OAAO,IAAI,CAAA;IACb,CAAC;CACF","sourcesContent":["/* eslint-disable no-console */\nimport { Headers } from '../../lib/headers/Headers.js'\nimport { Sdk } from './Sdk.js'\nimport { SdkError, IApiError } from './Errors.js'\nimport {\n ContextDeleteRecord,\n ContextListOptions,\n ContextListResult,\n IBulkOperationResult,\n} from '../../events/BaseEvents.js'\n\nexport interface SdkOptions {\n /**\n * Uses the provided token for authentication.\n */\n token?: string\n}\n\nexport interface IStoreRequestOptions extends SdkOptions {\n method?: 'GET' | 'POST' | 'PATCH' | 'PUT' | 'DELETE'\n headers?: Record<string, string>\n body?: string\n /**\n * If there's retry logic involved, this flag tells the engine\n * that the retry logic was triggered.\n */\n retry?: boolean\n}\n\nexport interface IStoreResponse {\n status: number\n headers: Headers\n body?: string\n}\n\nexport const E_INVALID_JSON = 'Invalid JSON response.'\nexport const E_RESPONSE_NO_VALUE = 'The response has no value.'\nexport const E_RESPONSE_STATUS = 'Invalid response status: '\nexport const E_RESPONSE_UNKNOWN = 'Unknown response from the server.'\nexport const E_RESPONSE_LOCATION = 'The response has no \"location\" header.'\n\nexport class SdkBase {\n constructor(public sdk: Sdk) {}\n\n protected logInvalidResponse(response: IStoreResponse): void {\n if (this.sdk.silent) {\n return\n }\n if (response.body) {\n try {\n const data = JSON.parse(response.body)\n if (data.message) {\n console.warn(`[Store message]: ${data.message}`)\n }\n } catch {\n // .\n }\n }\n }\n\n /**\n * Throws unified message for a common error status codes.\n * It handles 404, 403, and 401 status codes.\n */\n protected inspectCommonStatusCodes(response: IStoreResponse): void {\n const { status, body } = response\n if (status === 404) {\n let e = this.createGenericSdkError(body)\n if (!e) {\n e = new SdkError(`Not found.`, status)\n e.response = body\n }\n throw e\n }\n if (status === 403) {\n let e = this.createGenericSdkError(body)\n if (!e) {\n e = new SdkError(`You have no access to this resource.`, status)\n e.response = body\n }\n throw e\n }\n if (status === 401) {\n let e = this.createGenericSdkError(body)\n if (!e) {\n e = new SdkError(`Not authorized.`, status)\n e.response = body\n }\n throw e\n }\n }\n\n /**\n * Reads the response as ApiError\n * @param body The message returned by the store.\n * @returns The error schema or undefined when not an error;\n */\n protected readErrorResponse(body?: string): IApiError | undefined {\n if (!body) {\n return undefined\n }\n let data: IApiError\n try {\n data = JSON.parse(body)\n } catch {\n return undefined\n }\n if (data.error && data.message) {\n return data as IApiError\n }\n return undefined\n }\n\n protected createGenericSdkError(body?: string): SdkError | undefined {\n const info = this.readErrorResponse(body)\n if (!info) {\n return undefined\n }\n const e = new SdkError(info.message, info.code)\n e.detail = info.detail\n e.response = body\n return e\n }\n\n /**\n * A generic (common) method to batch-delete object from the store.\n *\n * @param url The URL object to make the request.\n * @param keys The list of keys to delete\n * @param request Optional request options.\n * @returns THe list of context delete records.\n */\n protected async genericBatchDelete(\n url: URL,\n keys: string[],\n request: SdkOptions = {}\n ): Promise<IBulkOperationResult<ContextDeleteRecord>> {\n const { token } = request\n const result = await this.sdk.http.post(url.toString(), { token, body: JSON.stringify(keys) })\n this.inspectCommonStatusCodes(result)\n const E_PREFIX = 'Unable to delete in batch. '\n if (result.status !== 200) {\n this.logInvalidResponse(result)\n let e = this.createGenericSdkError(result.body)\n if (!e) {\n e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status)\n e.response = result.body\n }\n throw e\n }\n if (!result.body) {\n throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`)\n }\n\n let data: IBulkOperationResult<ContextDeleteRecord>\n try {\n data = JSON.parse(result.body)\n } catch {\n throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`)\n }\n if (!Array.isArray(data.items)) {\n throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`)\n }\n return data\n }\n\n /**\n * Generic (common) function to delete an entity in the store.\n *\n * @param url The URL to make the DELETE request to.\n * @param request Optional request options.\n */\n protected async genericDelete(url: URL, request: SdkOptions = {}): Promise<void> {\n const { token } = request\n const result = await this.sdk.http.delete(url.toString(), { token })\n this.inspectCommonStatusCodes(result)\n const E_PREFIX = 'Unable to delete the object. '\n if (result.status !== 204) {\n this.logInvalidResponse(result)\n let e = this.createGenericSdkError(result.body)\n if (!e) {\n e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status)\n e.response = result.body\n }\n throw e\n }\n }\n\n protected async genericList(\n url: URL,\n options: ContextListOptions,\n request: SdkOptions = {}\n ): Promise<ContextListResult<unknown>> {\n const { token } = request\n this.sdk.appendListOptions(url, options)\n const result = await this.sdk.http.get(url.toString(), { token })\n this.inspectCommonStatusCodes(result)\n const E_PREFIX = 'Unable to list revisions for a file. '\n if (result.status !== 200) {\n this.logInvalidResponse(result)\n let e = this.createGenericSdkError(result.body)\n if (!e) {\n e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status)\n e.response = result.body\n }\n throw e\n }\n if (!result.body) {\n throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`)\n }\n let data: ContextListResult<unknown>\n try {\n data = JSON.parse(result.body)\n } catch {\n throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`)\n }\n if (!Array.isArray(data.items)) {\n throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`)\n }\n return data\n }\n\n protected readResponseBody(response: IStoreResponse, errorPrefix: string): string {\n if (response.status !== 200) {\n this.logInvalidResponse(response)\n let e = this.createGenericSdkError(response.body)\n if (!e) {\n e = new SdkError(`${errorPrefix}${E_RESPONSE_STATUS}${response.status}`, response.status)\n e.response = response.body\n }\n throw e\n }\n if (!response.body) {\n throw new Error(`${errorPrefix}${E_RESPONSE_NO_VALUE}`)\n }\n return response.body\n }\n\n protected readResponseJSON(response: IStoreResponse, errorPrefix: string): unknown {\n const body = this.readResponseBody(response, errorPrefix)\n let data: unknown\n try {\n data = JSON.parse(body)\n } catch {\n throw new Error(`${errorPrefix}${E_INVALID_JSON}.`)\n }\n return data\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"SdkBase.js","sourceRoot":"","sources":["../../../../src/runtime/store/SdkBase.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAA;AA0BzD,MAAM,CAAC,MAAM,cAAc,GAAG,wBAAwB,CAAA;AACtD,MAAM,CAAC,MAAM,mBAAmB,GAAG,4BAA4B,CAAA;AAC/D,MAAM,CAAC,MAAM,iBAAiB,GAAG,2BAA2B,CAAA;AAC5D,MAAM,CAAC,MAAM,kBAAkB,GAAG,mCAAmC,CAAA;AACrE,MAAM,CAAC,MAAM,mBAAmB,GAAG,wCAAwC,CAAA;AAE3E,MAAM,OAAO,OAAO;IACC;IAAnB,YAAmB,GAAQ;QAAR,QAAG,GAAH,GAAG,CAAK;IAAG,CAAC;IAErB,kBAAkB,CAAC,QAAwB;QACnD,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC;YACpB,OAAM;QACR,CAAC;QACD,IAAI,QAAQ,CAAC,IAAI,EAAE,CAAC;YAClB,IAAI,CAAC;gBACH,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;gBACtC,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;oBACjB,OAAO,CAAC,IAAI,CAAC,oBAAoB,IAAI,CAAC,OAAO,EAAE,CAAC,CAAA;gBAClD,CAAC;YACH,CAAC;YAAC,MAAM,CAAC;gBACP,IAAI;YACN,CAAC;QACH,CAAC;IACH,CAAC;IAED;;;OAGG;IACO,wBAAwB,CAAC,QAAwB;QACzD,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,QAAQ,CAAA;QACjC,IA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BAAgB,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAA;QAC7G,CAAC;QACD,OAAO,IAAI,CAAA;IACb,CAAC;CACF","sourcesContent":["/* eslint-disable no-console */\nimport { Headers } from '../../lib/headers/Headers.js'\nimport { Sdk } from './Sdk.js'\nimport {\n ContextDeleteRecord,\n ContextListOptions,\n ContextListResult,\n IBulkOperationResult,\n} from '../../events/BaseEvents.js'\nimport { Exception } from '../../exceptions/exception.js'\n\nexport interface SdkOptions {\n /**\n * Uses the provided token for authentication.\n */\n token?: string\n}\n\nexport interface IStoreRequestOptions extends SdkOptions {\n method?: 'GET' | 'POST' | 'PATCH' | 'PUT' | 'DELETE'\n headers?: Record<string, string>\n body?: string\n /**\n * If there's retry logic involved, this flag tells the engine\n * that the retry logic was triggered.\n */\n retry?: boolean\n}\n\nexport interface IStoreResponse {\n status: number\n headers: Headers\n body?: string\n}\n\nexport const E_INVALID_JSON = 'Invalid JSON response.'\nexport const E_RESPONSE_NO_VALUE = 'The response has no value.'\nexport const E_RESPONSE_STATUS = 'Invalid response status: '\nexport const E_RESPONSE_UNKNOWN = 'Unknown response from the server.'\nexport const E_RESPONSE_LOCATION = 'The response has no \"location\" header.'\n\nexport class SdkBase {\n constructor(public sdk: Sdk) {}\n\n protected logInvalidResponse(response: IStoreResponse): void {\n if (this.sdk.silent) {\n return\n }\n if (response.body) {\n try {\n const data = JSON.parse(response.body)\n if (data.message) {\n console.warn(`[Store message]: ${data.message}`)\n }\n } catch {\n // .\n }\n }\n }\n\n /**\n * Throws unified message for a common error status codes.\n * It handles 404, 403, and 401 status codes.\n */\n protected inspectCommonStatusCodes(response: IStoreResponse): void {\n const { status, body } = response\n if (status === 404) {\n const e = this.createApiError('Not found', body)\n if (e.status !== 404) {\n e.setStatus(404)\n }\n if (e.code !== 'E_NOT_FOUND') {\n e.setCode('E_NOT_FOUND')\n }\n throw e\n }\n if (status === 403) {\n const e = this.createApiError('You have no access to this resource', body)\n if (e.status !== 403) {\n e.setStatus(403)\n }\n if (e.code !== 'E_FORBIDDEN') {\n e.setCode('E_FORBIDDEN')\n }\n throw e\n }\n if (status === 401) {\n const e = this.createApiError('Not authorized', body)\n if (e.status !== 401) {\n e.setStatus(401)\n }\n if (e.code !== 'E_UNAUTHORIZED') {\n e.setCode('E_UNAUTHORIZED')\n }\n throw e\n }\n }\n\n /**\n * Creates an Exception from the response body.\n * It reads the error details from the body.\n *\n * @param defaultMessage The default message to use if the body does not contain a message.\n * @param body The message returned by the store.\n * @returns The Exception or undefined when not an error.\n */\n protected createApiError(defaultMessage: string, body?: string): Exception {\n if (!body) {\n return new Exception(defaultMessage)\n }\n let data: Record<string, string | number>\n try {\n data = JSON.parse(body)\n } catch {\n return new Exception(defaultMessage)\n }\n if (!data || typeof data !== 'object' || !data.message) {\n return new Exception(defaultMessage)\n }\n return Exception.fromRawException(data, defaultMessage)\n }\n\n /**\n * A generic (common) method to batch-delete object from the store.\n *\n * @param url The URL object to make the request.\n * @param keys The list of keys to delete\n * @param request Optional request options.\n * @returns THe list of context delete records.\n */\n protected async genericBatchDelete(\n url: URL,\n keys: string[],\n request: SdkOptions = {}\n ): Promise<IBulkOperationResult<ContextDeleteRecord>> {\n const { token } = request\n const result = await this.sdk.http.post(url.toString(), { token, body: JSON.stringify(keys) })\n this.inspectCommonStatusCodes(result)\n const E_PREFIX = 'Unable to delete in batch. '\n if (result.status !== 200) {\n this.logInvalidResponse(result)\n throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)\n }\n if (!result.body) {\n throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })\n }\n\n let data: IBulkOperationResult<ContextDeleteRecord>\n try {\n data = JSON.parse(result.body)\n } catch {\n throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })\n }\n if (!Array.isArray(data.items)) {\n throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })\n }\n return data\n }\n\n /**\n * Generic (common) function to delete an entity in the store.\n *\n * @param url The URL to make the DELETE request to.\n * @param request Optional request options.\n */\n protected async genericDelete(url: URL, request: SdkOptions = {}): Promise<void> {\n const { token } = request\n const result = await this.sdk.http.delete(url.toString(), { token })\n this.inspectCommonStatusCodes(result)\n const E_PREFIX = 'Unable to delete the object. '\n if (result.status !== 204) {\n this.logInvalidResponse(result)\n throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)\n }\n }\n\n protected async genericList(\n url: URL,\n options: ContextListOptions,\n request: SdkOptions = {}\n ): Promise<ContextListResult<unknown>> {\n const { token } = request\n this.sdk.appendListOptions(url, options)\n const result = await this.sdk.http.get(url.toString(), { token })\n this.inspectCommonStatusCodes(result)\n const E_PREFIX = 'Unable to list revisions for a file. '\n if (result.status !== 200) {\n this.logInvalidResponse(result)\n throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)\n }\n if (!result.body) {\n throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })\n }\n let data: ContextListResult<unknown>\n try {\n data = JSON.parse(result.body)\n } catch {\n throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })\n }\n if (!Array.isArray(data.items)) {\n throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })\n }\n return data\n }\n\n protected readResponseBody(response: IStoreResponse, errorPrefix: string): string {\n if (response.status !== 200) {\n this.logInvalidResponse(response)\n throw this.createApiError(`${errorPrefix}${E_RESPONSE_STATUS}${response.status}`, response.body)\n }\n if (!response.body) {\n throw new Exception(`${errorPrefix}${E_RESPONSE_NO_VALUE}`, {\n code: 'E_RESPONSE_NO_VALUE',\n status: response.status,\n })\n }\n return response.body\n }\n\n protected readResponseJSON(response: IStoreResponse, errorPrefix: string): unknown {\n const body = this.readResponseBody(response, errorPrefix)\n let data: unknown\n try {\n data = JSON.parse(body)\n } catch {\n throw new Exception(`${errorPrefix}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: response.status })\n }\n return data\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SharedSdk.d.ts","sourceRoot":"","sources":["../../../../src/runtime/store/SharedSdk.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EAKP,UAAU,EACX,MAAM,cAAc,CAAA;AAErB,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAA;
|
|
1
|
+
{"version":3,"file":"SharedSdk.d.ts","sourceRoot":"","sources":["../../../../src/runtime/store/SharedSdk.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EAKP,UAAU,EACX,MAAM,cAAc,CAAA;AAErB,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAA;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAA;AAGlF,qBAAa,SAAU,SAAQ,OAAO;IACpC;;;;;;OAMG;IACG,IAAI,CACR,YAAY,EAAE,MAAM,EACpB,KAAK,CAAC,EAAE,YAAY,EAAE,EACtB,OAAO,CAAC,EAAE,kBAAkB,EAC5B,OAAO,GAAE,UAAe,GACvB,OAAO,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC;CA4BrC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SdkBase, E_RESPONSE_STATUS, E_RESPONSE_NO_VALUE, E_INVALID_JSON, E_RESPONSE_UNKNOWN, } from './SdkBase.js';
|
|
2
2
|
import { RouteBuilder } from './RouteBuilder.js';
|
|
3
|
-
import {
|
|
3
|
+
import { Exception } from '../../exceptions/exception.js';
|
|
4
4
|
export class SharedSdk extends SdkBase {
|
|
5
5
|
/**
|
|
6
6
|
* Lists shared with the user files.
|
|
@@ -21,29 +21,20 @@ export class SharedSdk extends SdkBase {
|
|
|
21
21
|
const E_PREFIX = 'Unable to list organizations. ';
|
|
22
22
|
if (result.status !== 200) {
|
|
23
23
|
this.logInvalidResponse(result);
|
|
24
|
-
|
|
25
|
-
if (!e) {
|
|
26
|
-
e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status);
|
|
27
|
-
e.response = result.body;
|
|
28
|
-
}
|
|
29
|
-
throw e;
|
|
24
|
+
throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body);
|
|
30
25
|
}
|
|
31
26
|
if (!result.body) {
|
|
32
|
-
throw new
|
|
27
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status });
|
|
33
28
|
}
|
|
34
29
|
let data;
|
|
35
30
|
try {
|
|
36
31
|
data = JSON.parse(result.body);
|
|
37
32
|
}
|
|
38
33
|
catch {
|
|
39
|
-
|
|
40
|
-
err.response = result.body;
|
|
41
|
-
throw err;
|
|
34
|
+
throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status });
|
|
42
35
|
}
|
|
43
36
|
if (!Array.isArray(data.items)) {
|
|
44
|
-
|
|
45
|
-
err.response = result.body;
|
|
46
|
-
throw err;
|
|
37
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status });
|
|
47
38
|
}
|
|
48
39
|
return data;
|
|
49
40
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SharedSdk.js","sourceRoot":"","sources":["../../../../src/runtime/store/SharedSdk.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,iBAAiB,EACjB,mBAAmB,EACnB,cAAc,EACd,kBAAkB,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AC1B,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAA;YAC/B,MAAM,IAAI,CAAC,cAAc,CAAC,GAAG,QAAQ,GAAG,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;QAC3F,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;YACjB,MAAM,IAAI,SAAS,CAAC,GAAG,QAAQ,GAAG,mBAAmB,EAAE,EAAE,EAAE,IAAI,EAAE,qBAAqB,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAA;QAClH,CAAC;QACD,IAAI,IAA8B,CAAA;QAClC,IAAI,CAAC;YACH,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;QAChC,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,IAAI,SAAS,CAAC,GAAG,QAAQ,GAAG,cAAc,EAAE,EAAE,EAAE,IAAI,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAA;QACxG,CAAC;QACD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YAC/B,MAAM,IAAI,SAAS,CAAC,GAAG,QAAQ,GAAG,kBAAkB,EAAE,EAAE,EAAE,IAAI,EAAE,oBAAoB,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAA;QAChH,CAAC;QACD,OAAO,IAAI,CAAA;IACb,CAAC;CACF","sourcesContent":["import {\n SdkBase,\n E_RESPONSE_STATUS,\n E_RESPONSE_NO_VALUE,\n E_INVALID_JSON,\n E_RESPONSE_UNKNOWN,\n SdkOptions,\n} from './SdkBase.js'\nimport { RouteBuilder } from './RouteBuilder.js'\nimport { IFile } from '../../models/store/File.js'\nimport { ListFileKind } from './FilesSdk.js'\nimport { ContextListOptions, ContextListResult } from '../../events/BaseEvents.js'\nimport { Exception } from '../../exceptions/exception.js'\n\nexport class SharedSdk extends SdkBase {\n /**\n * Lists shared with the user files.\n *\n * @param kinds the list of kinds to list.\n * @param options Optional query options.\n * @param request Optional request options.\n */\n async list(\n organization: string,\n kinds?: ListFileKind[],\n options?: ContextListOptions,\n request: SdkOptions = {}\n ): Promise<ContextListResult<IFile>> {\n const { token } = request\n const url = this.sdk.getUrl(RouteBuilder.shared(organization))\n this.sdk.appendListOptions(url, options)\n if (Array.isArray(kinds)) {\n kinds.forEach((k) => url.searchParams.append('kind', k))\n }\n const result = await this.sdk.http.get(url.toString(), { token })\n this.inspectCommonStatusCodes(result)\n const E_PREFIX = 'Unable to list organizations. '\n if (result.status !== 200) {\n this.logInvalidResponse(result)\n throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)\n }\n if (!result.body) {\n throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })\n }\n let data: ContextListResult<IFile>\n try {\n data = JSON.parse(result.body)\n } catch {\n throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })\n }\n if (!Array.isArray(data.items)) {\n throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })\n }\n return data\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TrashSdk.d.ts","sourceRoot":"","sources":["../../../../src/runtime/store/TrashSdk.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EAKP,KAAK,UAAU,EAChB,MAAM,cAAc,CAAA;AAErB,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAA;
|
|
1
|
+
{"version":3,"file":"TrashSdk.d.ts","sourceRoot":"","sources":["../../../../src/runtime/store/TrashSdk.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EAKP,KAAK,UAAU,EAChB,MAAM,cAAc,CAAA;AAErB,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAA;AACvF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAA;AAG5D,qBAAa,QAAS,SAAQ,OAAO;IACnC;;;OAGG;IACG,IAAI,CACR,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,kBAAkB,EAC3B,OAAO,GAAE,UAAe,GACvB,OAAO,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC;IA0BzC;;;;;;OAMG;IACG,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,GAAE,UAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IAa5E,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,GAAE,UAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IAYnF;;;OAGG;IACG,KAAK,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,GAAE,UAAe,GAAG,OAAO,CAAC,IAAI,CAAC;CAW3E"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SdkBase, E_RESPONSE_STATUS, E_RESPONSE_NO_VALUE, E_INVALID_JSON, E_RESPONSE_UNKNOWN, } from './SdkBase.js';
|
|
2
2
|
import { RouteBuilder } from './RouteBuilder.js';
|
|
3
|
-
import {
|
|
3
|
+
import { Exception } from '../../exceptions/exception.js';
|
|
4
4
|
export class TrashSdk extends SdkBase {
|
|
5
5
|
/**
|
|
6
6
|
* Lists trashed entires.
|
|
@@ -15,25 +15,20 @@ export class TrashSdk extends SdkBase {
|
|
|
15
15
|
const E_PREFIX = 'Unable to list trash. ';
|
|
16
16
|
if (result.status !== 200) {
|
|
17
17
|
this.logInvalidResponse(result);
|
|
18
|
-
|
|
19
|
-
if (!e) {
|
|
20
|
-
e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status);
|
|
21
|
-
e.response = result.body;
|
|
22
|
-
}
|
|
23
|
-
throw e;
|
|
18
|
+
throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body);
|
|
24
19
|
}
|
|
25
20
|
if (!result.body) {
|
|
26
|
-
throw new
|
|
21
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status });
|
|
27
22
|
}
|
|
28
23
|
let data;
|
|
29
24
|
try {
|
|
30
25
|
data = JSON.parse(result.body);
|
|
31
26
|
}
|
|
32
27
|
catch {
|
|
33
|
-
throw new
|
|
28
|
+
throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status });
|
|
34
29
|
}
|
|
35
30
|
if (!Array.isArray(data.items)) {
|
|
36
|
-
throw new
|
|
31
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status });
|
|
37
32
|
}
|
|
38
33
|
return data;
|
|
39
34
|
}
|
|
@@ -53,12 +48,7 @@ export class TrashSdk extends SdkBase {
|
|
|
53
48
|
const E_PREFIX = 'Unable to delete trash. ';
|
|
54
49
|
if (result.status !== 204) {
|
|
55
50
|
this.logInvalidResponse(result);
|
|
56
|
-
|
|
57
|
-
if (!e) {
|
|
58
|
-
e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status);
|
|
59
|
-
e.response = result.body;
|
|
60
|
-
}
|
|
61
|
-
throw e;
|
|
51
|
+
throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body);
|
|
62
52
|
}
|
|
63
53
|
}
|
|
64
54
|
async restore(oid, keys, request = {}) {
|
|
@@ -69,12 +59,7 @@ export class TrashSdk extends SdkBase {
|
|
|
69
59
|
const E_PREFIX = 'Unable to restore from trash. ';
|
|
70
60
|
if (result.status !== 204) {
|
|
71
61
|
this.logInvalidResponse(result);
|
|
72
|
-
|
|
73
|
-
if (!e) {
|
|
74
|
-
e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status);
|
|
75
|
-
e.response = result.body;
|
|
76
|
-
}
|
|
77
|
-
throw e;
|
|
62
|
+
throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body);
|
|
78
63
|
}
|
|
79
64
|
}
|
|
80
65
|
/**
|
|
@@ -89,12 +74,7 @@ export class TrashSdk extends SdkBase {
|
|
|
89
74
|
const E_PREFIX = 'Unable to empty trash. ';
|
|
90
75
|
if (result.status !== 204) {
|
|
91
76
|
this.logInvalidResponse(result);
|
|
92
|
-
|
|
93
|
-
if (!e) {
|
|
94
|
-
e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status);
|
|
95
|
-
e.response = result.body;
|
|
96
|
-
}
|
|
97
|
-
throw e;
|
|
77
|
+
throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body);
|
|
98
78
|
}
|
|
99
79
|
}
|
|
100
80
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TrashSdk.js","sourceRoot":"","sources":["../../../../src/runtime/store/TrashSdk.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,iBAAiB,EACjB,mBAAmB,EACnB,cAAc,EACd,kBAAkB,GAEnB,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"TrashSdk.js","sourceRoot":"","sources":["../../../../src/runtime/store/TrashSdk.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,iBAAiB,EACjB,mBAAmB,EACnB,cAAc,EACd,kBAAkB,GAEnB,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA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BAAwB,CAAC,MAAM,CAAC,CAAA;QACrC,MAAM,QAAQ,GAAG,yBAAyB,CAAA;QAC1C,IAAI,MAAM,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;YAC1B,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAA;YAC/B,MAAM,IAAI,CAAC,cAAc,CAAC,GAAG,QAAQ,GAAG,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;QAC3F,CAAC;IACH,CAAC;CACF","sourcesContent":["import {\n SdkBase,\n E_RESPONSE_STATUS,\n E_RESPONSE_NO_VALUE,\n E_INVALID_JSON,\n E_RESPONSE_UNKNOWN,\n type SdkOptions,\n} from './SdkBase.js'\nimport { RouteBuilder } from './RouteBuilder.js'\nimport type { ContextListOptions, ContextListResult } from '../../events/BaseEvents.js'\nimport type { TrashEntry } from '../../models/TrashEntry.js'\nimport { Exception } from '../../exceptions/exception.js'\n\nexport class TrashSdk extends SdkBase {\n /**\n * Lists trashed entires.\n * @param options The list query options.\n */\n async list(\n oid: string,\n options: ContextListOptions,\n request: SdkOptions = {}\n ): Promise<ContextListResult<TrashEntry>> {\n const { token } = request\n const url = this.sdk.getUrl(RouteBuilder.trash(oid))\n this.sdk.appendListOptions(url, options)\n const result = await this.sdk.http.get(url.toString(), { token })\n this.inspectCommonStatusCodes(result)\n const E_PREFIX = 'Unable to list trash. '\n if (result.status !== 200) {\n this.logInvalidResponse(result)\n throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)\n }\n if (!result.body) {\n throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })\n }\n let data: ContextListResult<TrashEntry>\n try {\n data = JSON.parse(result.body)\n } catch {\n throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })\n }\n if (!Array.isArray(data.items)) {\n throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })\n }\n return data\n }\n\n /**\n * Permanently deletes a number of files in a batch operation.\n *\n * @param oid The parent organization\n * @param keys The list of trash entry keys to delete.\n * @param request Optional request options.\n */\n async delete(oid: string, keys: string[], request: SdkOptions = {}): Promise<void> {\n const path = RouteBuilder.trashBatchDelete(oid)\n const url = this.sdk.getUrl(path)\n const { token } = request\n const result = await this.sdk.http.delete(url.toString(), { token, body: JSON.stringify({ ids: keys }) })\n this.inspectCommonStatusCodes(result)\n const E_PREFIX = 'Unable to delete trash. '\n if (result.status !== 204) {\n this.logInvalidResponse(result)\n throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)\n }\n }\n\n async restore(oid: string, keys: string[], request: SdkOptions = {}): Promise<void> {\n const url = this.sdk.getUrl(RouteBuilder.trashBatchRestore(oid))\n const { token } = request\n const result = await this.sdk.http.post(url.toString(), { token, body: JSON.stringify({ ids: keys }) })\n this.inspectCommonStatusCodes(result)\n const E_PREFIX = 'Unable to restore from trash. '\n if (result.status !== 204) {\n this.logInvalidResponse(result)\n throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)\n }\n }\n\n /**\n * Empties the trash for the user in the given organization.\n * @param organization The organization key to remove trash for.\n */\n async empty(organization: string, request: SdkOptions = {}): Promise<void> {\n const { token } = request\n const url = this.sdk.getUrl(RouteBuilder.trashEmpty(organization))\n const result = await this.sdk.http.delete(url.toString(), { token })\n this.inspectCommonStatusCodes(result)\n const E_PREFIX = 'Unable to empty trash. '\n if (result.status !== 204) {\n this.logInvalidResponse(result)\n throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)\n }\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UsersSdk.d.ts","sourceRoot":"","sources":["../../../../src/runtime/store/UsersSdk.ts"],"names":[],"mappings":"AAA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,uBAAuB,CAAA;IAC/B;;OAEG;IACH,cAAc,EAAE,MAAM,CAAA;IACtB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAA;CACnB;AAED,qBAAa,QAAS,SAAQ,OAAO;IACnC;;;OAGG;IACG,EAAE,CAAC,OAAO,GAAE,UAAe,GAAG,OAAO,CAAC,KAAK,CAAC;IAyBlD;;;;;;;OAOG;IACG,IAAI,CACR,cAAc,EAAE,MAAM,EACtB,OAAO,CAAC,EAAE,kBAAkB,EAC5B,OAAO,GAAE,UAAe,GACvB,OAAO,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC;IA4BpC;;;;;;;;OAQG;IACG,IAAI,CAAC,cAAc,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,UAAe,GAAG,OAAO,CAAC,KAAK,CAAC;CAuB1F"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { SdkBase, E_RESPONSE_STATUS, E_RESPONSE_NO_VALUE, E_INVALID_JSON, E_RESPONSE_UNKNOWN, } from './SdkBase.js';
|
|
2
2
|
import { RouteBuilder } from './RouteBuilder.js';
|
|
3
|
+
import { Exception } from '../../exceptions/exception.js';
|
|
3
4
|
export class UsersSdk extends SdkBase {
|
|
4
5
|
/**
|
|
5
6
|
* Reads the current user.
|
|
@@ -13,20 +14,20 @@ export class UsersSdk extends SdkBase {
|
|
|
13
14
|
const E_PREFIX = 'Unable to read a user. ';
|
|
14
15
|
if (result.status !== 200) {
|
|
15
16
|
this.logInvalidResponse(result);
|
|
16
|
-
throw
|
|
17
|
+
throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body);
|
|
17
18
|
}
|
|
18
19
|
if (!result.body) {
|
|
19
|
-
throw new
|
|
20
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status });
|
|
20
21
|
}
|
|
21
22
|
let data;
|
|
22
23
|
try {
|
|
23
24
|
data = JSON.parse(result.body);
|
|
24
25
|
}
|
|
25
26
|
catch {
|
|
26
|
-
throw new
|
|
27
|
+
throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status });
|
|
27
28
|
}
|
|
28
29
|
if (!data.key) {
|
|
29
|
-
throw new
|
|
30
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status });
|
|
30
31
|
}
|
|
31
32
|
return data;
|
|
32
33
|
}
|
|
@@ -49,20 +50,20 @@ export class UsersSdk extends SdkBase {
|
|
|
49
50
|
const E_PREFIX = 'Unable to list projects. ';
|
|
50
51
|
if (result.status !== 200) {
|
|
51
52
|
this.logInvalidResponse(result);
|
|
52
|
-
throw
|
|
53
|
+
throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body);
|
|
53
54
|
}
|
|
54
55
|
if (!result.body) {
|
|
55
|
-
throw new
|
|
56
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status });
|
|
56
57
|
}
|
|
57
58
|
let data;
|
|
58
59
|
try {
|
|
59
60
|
data = JSON.parse(result.body);
|
|
60
61
|
}
|
|
61
62
|
catch {
|
|
62
|
-
throw new
|
|
63
|
+
throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status });
|
|
63
64
|
}
|
|
64
65
|
if (!Array.isArray(data.items)) {
|
|
65
|
-
throw new
|
|
66
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status });
|
|
66
67
|
}
|
|
67
68
|
return data;
|
|
68
69
|
}
|
|
@@ -85,17 +86,17 @@ export class UsersSdk extends SdkBase {
|
|
|
85
86
|
const E_PREFIX = 'Unable to read the user info. ';
|
|
86
87
|
if (result.status !== 200) {
|
|
87
88
|
this.logInvalidResponse(result);
|
|
88
|
-
throw
|
|
89
|
+
throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body);
|
|
89
90
|
}
|
|
90
91
|
if (!result.body) {
|
|
91
|
-
throw new
|
|
92
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status });
|
|
92
93
|
}
|
|
93
94
|
let data;
|
|
94
95
|
try {
|
|
95
96
|
data = JSON.parse(result.body);
|
|
96
97
|
}
|
|
97
98
|
catch {
|
|
98
|
-
throw new
|
|
99
|
+
throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status });
|
|
99
100
|
}
|
|
100
101
|
return data;
|
|
101
102
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UsersSdk.js","sourceRoot":"","sources":["../../../../src/runtime/store/UsersSdk.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,iBAAiB,EACjB,mBAAmB,EACnB,cAAc,EACd,kBAAkB,GAEnB,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AA0EhD,MAAM,OAAO,QAAS,SAAQ,OAAO;IACnC;;;OAGG;IACH,KAAK,CAAC,EAAE,CAAC,UAAsB,EAAE;QAC/B,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAA;QACzB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,CAAC,OAAO,EAAE,CAAC,CAAA;QACnD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,CAAA;QACjE,IAAI,CAAC,wBAAwB,CAAC,MAAM,CAAC,CAAA;QACrC,MAAM,QAAQ,GAAG,yBAAyB,CAAA;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;QACnE,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,CAAA;QACjE,IAAI,CAAC,wBAAwB,CAAC,MAAM,CAAC,CAAA;QACrC,MAAM,QAAQ,GAAG,gCAAgC,CAAA;QACjD,IAAI,MAAM,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;YAC1B,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAA;YAC/B,MAAM,IAAI,KAAK,CAAC,GAAG,QAAQ,GAAG,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,CAAA;QACpE,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,GAAG,QAAQ,GAAG,mBAAmB,EAAE,CAAC,CAAA;QACtD,CAAC;QACD,IAAI,IAAW,CAAA;QACf,IAAI,CAAC;YACH,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;QAChC,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,IAAI,KAAK,CAAC,GAAG,QAAQ,GAAG,cAAc,GAAG,CAAC,CAAA;QAClD,CAAC;QACD,OAAO,IAAI,CAAA;IACb,CAAC;CACF","sourcesContent":["import {\n SdkBase,\n E_RESPONSE_STATUS,\n E_RESPONSE_NO_VALUE,\n E_INVALID_JSON,\n E_RESPONSE_UNKNOWN,\n SdkOptions,\n} from './SdkBase.js'\nimport { RouteBuilder } from './RouteBuilder.js'\nimport { IUser } from '../../models/store/User.js'\nimport { ContextListResult, ContextListOptions } from '../../events/BaseEvents.js'\n\nexport interface IJwtInfo {\n /**\n * The information about the user that is read from the JWT.\n */\n data: IJwtUser\n /**\n * The name of the provider.\n */\n provider: string\n}\n\nexport interface IJwtUser {\n /**\n * The provider's unique ID.\n */\n id: string\n /**\n * The user's email address.\n */\n email: string\n /**\n * true, if the provider has verified the email address.\n */\n email_verified: boolean\n /**\n * The user's full name.\n */\n name: string\n /**\n * If present, a URL to user's profile picture\n */\n picture?: string\n given_name?: string\n family_name?: string\n /**\n * If present, the host domain of the user's GSuite email address.\n * Google specific.\n */\n hd?: string\n}\n\nexport interface IRegistrationInfo {\n reason: 'new-organization' | 'existing-organization'\n /**\n * The decoded JWT user information.\n * Used to create a user account.\n */\n user: IJwtInfo\n}\n\nexport interface IOrganizationRegistrationInfo extends IRegistrationInfo {\n reason: 'new-organization'\n /**\n * The name of the organization to create for the user.\n */\n organizationName: string\n}\n\nexport interface IOrganizationAddUserInfo extends IRegistrationInfo {\n reason: 'existing-organization'\n /**\n * Set when adding a user to an existing organization.\n */\n organizationId: string\n /**\n * The invitation code used to invite the user.\n */\n invitation: string\n}\n\nexport class UsersSdk extends SdkBase {\n /**\n * Reads the current user.\n * @param request Optional request options.\n */\n async me(request: SdkOptions = {}): Promise<IUser> {\n const { token } = request\n const url = this.sdk.getUrl(RouteBuilder.usersMe())\n const result = await this.sdk.http.get(url.toString(), { token })\n this.inspectCommonStatusCodes(result)\n const E_PREFIX = 'Unable to read a user. '\n if (result.status !== 200) {\n this.logInvalidResponse(result)\n throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`)\n }\n if (!result.body) {\n throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`)\n }\n let data: IUser\n try {\n data = JSON.parse(result.body)\n } catch {\n throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`)\n }\n if (!data.key) {\n throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`)\n }\n return data\n }\n\n /**\n * Lists users in the store\n *\n * @param organizationId The key of the organization we want to read the user from.\n * @param options Optional query options.\n * @param request Optional request options.\n * @deprecated Use `organizations.listUsers()` instead.\n */\n async list(\n organizationId: string,\n options?: ContextListOptions,\n request: SdkOptions = {}\n ): Promise<ContextListResult<IUser>> {\n // eslint-disable-next-line no-console\n console.warn('The `users.list` method is deprecated. Use `organizations.listUsers()` instead.')\n const { token } = request\n const url = this.sdk.getUrl(RouteBuilder.users(organizationId))\n this.sdk.appendListOptions(url, options)\n const result = await this.sdk.http.get(url.toString(), { token })\n this.inspectCommonStatusCodes(result)\n const E_PREFIX = 'Unable to list projects. '\n if (result.status !== 200) {\n this.logInvalidResponse(result)\n throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`)\n }\n if (!result.body) {\n throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`)\n }\n let data: ContextListResult<IUser>\n try {\n data = JSON.parse(result.body)\n } catch {\n throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`)\n }\n if (!Array.isArray(data.items)) {\n throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`)\n }\n return data\n }\n\n /**\n * Reads a user information from the store.\n *\n * @param organizationId The key of the organization we want to read the user from.\n * @param key The user key.\n * @param request Optional request options.\n * @returns The user object\n * @deprecated Use `organizations.getUser()` instead.\n */\n async read(organizationId: string, key: string, request: SdkOptions = {}): Promise<IUser> {\n // eslint-disable-next-line no-console\n console.warn('The `users.read` method is deprecated. Use `organizations.getUser()` instead.')\n const { token } = request\n const url = this.sdk.getUrl(RouteBuilder.user(organizationId, key))\n const result = await this.sdk.http.get(url.toString(), { token })\n this.inspectCommonStatusCodes(result)\n const E_PREFIX = 'Unable to read the user info. '\n if (result.status !== 200) {\n this.logInvalidResponse(result)\n throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`)\n }\n if (!result.body) {\n throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`)\n }\n let data: IUser\n try {\n data = JSON.parse(result.body)\n } catch {\n throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`)\n }\n return data\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"UsersSdk.js","sourceRoot":"","sources":["../../../../src/runtime/store/UsersSdk.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OA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,GAAG,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,CAAA;QACjE,IAAI,CAAC,wBAAwB,CAAC,MAAM,CAAC,CAAA;QACrC,MAAM,QAAQ,GAAG,gCAAgC,CAAA;QACjD,IAAI,MAAM,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;YAC1B,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAA;YAC/B,MAAM,IAAI,CAAC,cAAc,CAAC,GAAG,QAAQ,GAAG,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;QAC3F,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;YACjB,MAAM,IAAI,SAAS,CAAC,GAAG,QAAQ,GAAG,mBAAmB,EAAE,EAAE,EAAE,IAAI,EAAE,qBAAqB,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAA;QAClH,CAAC;QACD,IAAI,IAAW,CAAA;QACf,IAAI,CAAC;YACH,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;QAChC,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,IAAI,SAAS,CAAC,GAAG,QAAQ,GAAG,cAAc,EAAE,EAAE,EAAE,IAAI,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAA;QACxG,CAAC;QACD,OAAO,IAAI,CAAA;IACb,CAAC;CACF","sourcesContent":["import {\n SdkBase,\n E_RESPONSE_STATUS,\n E_RESPONSE_NO_VALUE,\n E_INVALID_JSON,\n E_RESPONSE_UNKNOWN,\n SdkOptions,\n} from './SdkBase.js'\nimport { RouteBuilder } from './RouteBuilder.js'\nimport { IUser } from '../../models/store/User.js'\nimport { ContextListResult, ContextListOptions } from '../../events/BaseEvents.js'\nimport { Exception } from '../../exceptions/exception.js'\n\nexport interface IJwtInfo {\n /**\n * The information about the user that is read from the JWT.\n */\n data: IJwtUser\n /**\n * The name of the provider.\n */\n provider: string\n}\n\nexport interface IJwtUser {\n /**\n * The provider's unique ID.\n */\n id: string\n /**\n * The user's email address.\n */\n email: string\n /**\n * true, if the provider has verified the email address.\n */\n email_verified: boolean\n /**\n * The user's full name.\n */\n name: string\n /**\n * If present, a URL to user's profile picture\n */\n picture?: string\n given_name?: string\n family_name?: string\n /**\n * If present, the host domain of the user's GSuite email address.\n * Google specific.\n */\n hd?: string\n}\n\nexport interface IRegistrationInfo {\n reason: 'new-organization' | 'existing-organization'\n /**\n * The decoded JWT user information.\n * Used to create a user account.\n */\n user: IJwtInfo\n}\n\nexport interface IOrganizationRegistrationInfo extends IRegistrationInfo {\n reason: 'new-organization'\n /**\n * The name of the organization to create for the user.\n */\n organizationName: string\n}\n\nexport interface IOrganizationAddUserInfo extends IRegistrationInfo {\n reason: 'existing-organization'\n /**\n * Set when adding a user to an existing organization.\n */\n organizationId: string\n /**\n * The invitation code used to invite the user.\n */\n invitation: string\n}\n\nexport class UsersSdk extends SdkBase {\n /**\n * Reads the current user.\n * @param request Optional request options.\n */\n async me(request: SdkOptions = {}): Promise<IUser> {\n const { token } = request\n const url = this.sdk.getUrl(RouteBuilder.usersMe())\n const result = await this.sdk.http.get(url.toString(), { token })\n this.inspectCommonStatusCodes(result)\n const E_PREFIX = 'Unable to read a user. '\n if (result.status !== 200) {\n this.logInvalidResponse(result)\n throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)\n }\n if (!result.body) {\n throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })\n }\n let data: IUser\n try {\n data = JSON.parse(result.body)\n } catch {\n throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })\n }\n if (!data.key) {\n throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })\n }\n return data\n }\n\n /**\n * Lists users in the store\n *\n * @param organizationId The key of the organization we want to read the user from.\n * @param options Optional query options.\n * @param request Optional request options.\n * @deprecated Use `organizations.listUsers()` instead.\n */\n async list(\n organizationId: string,\n options?: ContextListOptions,\n request: SdkOptions = {}\n ): Promise<ContextListResult<IUser>> {\n // eslint-disable-next-line no-console\n console.warn('The `users.list` method is deprecated. Use `organizations.listUsers()` instead.')\n const { token } = request\n const url = this.sdk.getUrl(RouteBuilder.users(organizationId))\n this.sdk.appendListOptions(url, options)\n const result = await this.sdk.http.get(url.toString(), { token })\n this.inspectCommonStatusCodes(result)\n const E_PREFIX = 'Unable to list projects. '\n if (result.status !== 200) {\n this.logInvalidResponse(result)\n throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)\n }\n if (!result.body) {\n throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })\n }\n let data: ContextListResult<IUser>\n try {\n data = JSON.parse(result.body)\n } catch {\n throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })\n }\n if (!Array.isArray(data.items)) {\n throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })\n }\n return data\n }\n\n /**\n * Reads a user information from the store.\n *\n * @param organizationId The key of the organization we want to read the user from.\n * @param key The user key.\n * @param request Optional request options.\n * @returns The user object\n * @deprecated Use `organizations.getUser()` instead.\n */\n async read(organizationId: string, key: string, request: SdkOptions = {}): Promise<IUser> {\n // eslint-disable-next-line no-console\n console.warn('The `users.read` method is deprecated. Use `organizations.getUser()` instead.')\n const { token } = request\n const url = this.sdk.getUrl(RouteBuilder.user(organizationId, key))\n const result = await this.sdk.http.get(url.toString(), { token })\n this.inspectCommonStatusCodes(result)\n const E_PREFIX = 'Unable to read the user info. '\n if (result.status !== 200) {\n this.logInvalidResponse(result)\n throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)\n }\n if (!result.body) {\n throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })\n }\n let data: IUser\n try {\n data = JSON.parse(result.body)\n } catch {\n throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })\n }\n return data\n }\n}\n"]}
|