@veritree/services 2.18.1-5 → 2.18.1-7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/helpers/api.js +20 -16
package/package.json
CHANGED
package/src/helpers/api.js
CHANGED
|
@@ -11,12 +11,7 @@ import { getSession } from "./session";
|
|
|
11
11
|
function addVersionArg(url) {
|
|
12
12
|
if (!url || url.includes("_result=1")) return url;
|
|
13
13
|
|
|
14
|
-
const version =
|
|
15
|
-
process && process.env
|
|
16
|
-
? process.env.API_VERITREE_VERSION
|
|
17
|
-
? process.env.API_VERITREE_VERSION
|
|
18
|
-
: "5.0.0"
|
|
19
|
-
: "5.0.0" || "5.0.0";
|
|
14
|
+
const version = "5.0.0";
|
|
20
15
|
const urlHasArgs = url.includes("?");
|
|
21
16
|
const urlVersionArg = urlHasArgs ? `&_v=${version}` : `?_v=${version}`;
|
|
22
17
|
|
|
@@ -65,12 +60,7 @@ function getConfig(method, data, as) {
|
|
|
65
60
|
|
|
66
61
|
export default class Api {
|
|
67
62
|
constructor(resource) {
|
|
68
|
-
this.baseUrl =
|
|
69
|
-
process && process.env
|
|
70
|
-
? process.env.API_VERITREE_URL
|
|
71
|
-
? `${process.env.API_VERITREE_URL}/api`
|
|
72
|
-
: null
|
|
73
|
-
: null;
|
|
63
|
+
this.baseUrl = null;
|
|
74
64
|
this.resource = resource ? resource : "";
|
|
75
65
|
this.orgId = null;
|
|
76
66
|
this.orgType = null;
|
|
@@ -216,15 +206,29 @@ export default class Api {
|
|
|
216
206
|
const config = getConfig(method, data, as);
|
|
217
207
|
const response = await fetch(url, config);
|
|
218
208
|
|
|
219
|
-
|
|
209
|
+
// console.log(response);
|
|
210
|
+
|
|
211
|
+
return new Promise(async (resolve, reject) => {
|
|
220
212
|
if (response.ok && response.status === 204) {
|
|
221
213
|
resolve();
|
|
222
214
|
return;
|
|
223
215
|
}
|
|
224
216
|
|
|
225
|
-
response.
|
|
226
|
-
|
|
227
|
-
|
|
217
|
+
const isJSON = response.headers.get('content-type').includes('json');
|
|
218
|
+
|
|
219
|
+
if(isJSON) {
|
|
220
|
+
response.json().then((json) => {
|
|
221
|
+
response.ok ? resolve(json) : reject(json);
|
|
222
|
+
});
|
|
223
|
+
} else {
|
|
224
|
+
const buff = await response.arrayBuffer().then(Buffer.from)
|
|
225
|
+
|
|
226
|
+
try {
|
|
227
|
+
resolve(buff.toString());
|
|
228
|
+
} catch (err) {
|
|
229
|
+
reject();
|
|
230
|
+
}
|
|
231
|
+
}
|
|
228
232
|
});
|
|
229
233
|
}
|
|
230
234
|
|