@trayio/tray-client 3.8.0 → 3.9.0
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/dist/base/BaseClient.js +31 -39
- package/package.json +3 -3
package/dist/base/BaseClient.js
CHANGED
|
@@ -22,15 +22,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
26
|
exports.BaseHttpApiClient = void 0;
|
|
36
27
|
const E = __importStar(require("fp-ts/lib/Either"));
|
|
@@ -39,41 +30,42 @@ const Result_1 = require("@trayio/commons/result/Result");
|
|
|
39
30
|
const util_1 = require("util");
|
|
40
31
|
const BufferExtensions_1 = require("@trayio/commons/buffer/BufferExtensions");
|
|
41
32
|
class BaseHttpApiClient {
|
|
33
|
+
httpConfig;
|
|
34
|
+
httpClient;
|
|
35
|
+
serialization;
|
|
42
36
|
constructor(httpConfig, httpClient) {
|
|
43
37
|
this.httpConfig = httpConfig;
|
|
44
38
|
this.httpClient = httpClient;
|
|
45
39
|
this.serialization = new JsonSerialization_1.JsonSerialization();
|
|
46
40
|
}
|
|
47
|
-
execute(path, method, headers, token, pathParams, queryString, body) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
});
|
|
41
|
+
async execute(path, method, headers, token, pathParams, queryString, body) {
|
|
42
|
+
const url = this.httpConfig.baseUrl + path;
|
|
43
|
+
const JsonBody = this.serialization.serialize(body);
|
|
44
|
+
const populatedHeaders = this.addTokenHeader(headers, token);
|
|
45
|
+
const responseE = await this.httpClient.execute(method, url, {
|
|
46
|
+
headers: populatedHeaders,
|
|
47
|
+
pathParams,
|
|
48
|
+
queryString,
|
|
49
|
+
body: BufferExtensions_1.BufferExtensions.arrayBufferToReadable(JsonBody),
|
|
50
|
+
})();
|
|
51
|
+
const result = Result_1.ResultInternal.fromEitherWithSimpleError(responseE);
|
|
52
|
+
switch (result.isSuccess) {
|
|
53
|
+
case false:
|
|
54
|
+
return result;
|
|
55
|
+
case true:
|
|
56
|
+
const { statusCode } = result.value;
|
|
57
|
+
const responseArrayBufferE = await BufferExtensions_1.BufferExtensions.readableToArrayBuffer(result.value.body)();
|
|
58
|
+
if (E.isLeft(responseArrayBufferE)) {
|
|
59
|
+
return Result_1.Result.failure(new Error(`Error (${statusCode}): ${responseArrayBufferE.left}`));
|
|
60
|
+
}
|
|
61
|
+
if (result.value.statusCode >= 300) {
|
|
62
|
+
const errorBody = new util_1.TextDecoder().decode(responseArrayBufferE.right);
|
|
63
|
+
return Result_1.Result.failure(new Error(`Error (${statusCode}): ${errorBody}`));
|
|
64
|
+
}
|
|
65
|
+
const deserializedResponseE = this.serialization.deserialize(responseArrayBufferE.right);
|
|
66
|
+
const successResult = Result_1.ResultInternal.fromEitherWithSimpleErrorAndUnknown(deserializedResponseE);
|
|
67
|
+
return successResult;
|
|
68
|
+
}
|
|
77
69
|
}
|
|
78
70
|
executeWithoutInput(path, method, headers, token) {
|
|
79
71
|
return this.execute(path, method, headers, token, {}, {}, {});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trayio/tray-client",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.9.0",
|
|
4
4
|
"description": "A client for the Tray.io API",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./*": "./dist/*.js"
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"/dist"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@trayio/commons": "3.
|
|
29
|
-
"@trayio/tray-api": "3.
|
|
28
|
+
"@trayio/commons": "3.9.0",
|
|
29
|
+
"@trayio/tray-api": "3.9.0"
|
|
30
30
|
}
|
|
31
31
|
}
|