@taquito/http-utils 18.0.0-RC.0 → 19.0.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/lib/errors.js +16 -3
- package/dist/lib/status_code.js +1 -2
- package/dist/lib/taquito-http-utils.js +49 -43
- package/dist/lib/version.js +2 -3
- package/dist/taquito-http-utils.es6.js +469 -667
- package/dist/taquito-http-utils.es6.js.map +1 -1
- package/dist/taquito-http-utils.umd.js +473 -675
- package/dist/taquito-http-utils.umd.js.map +1 -1
- package/dist/types/errors.d.ts +33 -24
- package/dist/types/status_code.d.ts +318 -318
- package/dist/types/taquito-http-utils.d.ts +30 -30
- package/dist/types/version.d.ts +4 -4
- package/package.json +27 -28
- package/signature.json +4 -6
- package/dist/lib/errors.js.map +0 -1
- package/dist/lib/fetch-adapter.js +0 -229
- package/dist/lib/fetch-adapter.js.map +0 -1
- package/dist/lib/status_code.js.map +0 -1
- package/dist/lib/taquito-http-utils.js.map +0 -1
- package/dist/lib/version.js.map +0 -1
- package/dist/types/fetch-adapter.d.ts +0 -7
package/dist/lib/errors.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HttpResponseError = exports.HttpRequestFailed = void 0;
|
|
3
|
+
exports.HttpTimeoutError = exports.HttpResponseError = exports.HttpRequestFailed = void 0;
|
|
4
4
|
const core_1 = require("@taquito/core");
|
|
5
5
|
/**
|
|
6
6
|
* @category Error
|
|
@@ -29,8 +29,21 @@ class HttpResponseError extends core_1.NetworkError {
|
|
|
29
29
|
this.statusText = statusText;
|
|
30
30
|
this.body = body;
|
|
31
31
|
this.url = url;
|
|
32
|
-
this.name = '
|
|
32
|
+
this.name = 'HttpResponseError';
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
exports.HttpResponseError = HttpResponseError;
|
|
36
|
-
|
|
36
|
+
/**
|
|
37
|
+
* @category Error
|
|
38
|
+
* @description Error
|
|
39
|
+
*/
|
|
40
|
+
class HttpTimeoutError extends core_1.NetworkError {
|
|
41
|
+
constructor(timeout, url) {
|
|
42
|
+
super();
|
|
43
|
+
this.timeout = timeout;
|
|
44
|
+
this.url = url;
|
|
45
|
+
this.name = 'HttpTimeoutError';
|
|
46
|
+
this.message = `HTTP request timeout of ${timeout}ms exceeded`;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.HttpTimeoutError = HttpTimeoutError;
|
package/dist/lib/status_code.js
CHANGED
|
@@ -319,5 +319,4 @@ var STATUS_CODE;
|
|
|
319
319
|
* to require agreement to Terms of Service before granting full Internet access via a Wi-Fi hotspot).
|
|
320
320
|
*/
|
|
321
321
|
STATUS_CODE[STATUS_CODE["NETWORK_AUTHENTICATION_REQUIRED"] = 511] = "NETWORK_AUTHENTICATION_REQUIRED";
|
|
322
|
-
})(STATUS_CODE
|
|
323
|
-
//# sourceMappingURL=status_code.js.map
|
|
322
|
+
})(STATUS_CODE || (exports.STATUS_CODE = STATUS_CODE = {}));
|
|
@@ -5,7 +5,11 @@
|
|
|
5
5
|
*/
|
|
6
6
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
7
|
if (k2 === undefined) k2 = k;
|
|
8
|
-
Object.
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
9
13
|
}) : (function(o, m, k, k2) {
|
|
10
14
|
if (k2 === undefined) k2 = k;
|
|
11
15
|
o[k2] = m[k];
|
|
@@ -24,23 +28,22 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
24
28
|
};
|
|
25
29
|
var _a;
|
|
26
30
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
-
exports.HttpBackend = exports.HttpResponseError = exports.HttpRequestFailed = exports.VERSION = void 0;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
exports.HttpBackend = exports.HttpTimeoutError = exports.HttpResponseError = exports.HttpRequestFailed = exports.VERSION = void 0;
|
|
32
|
+
let fetch = globalThis === null || globalThis === void 0 ? void 0 : globalThis.fetch;
|
|
33
|
+
// Will only use browser fetch if we are in a browser environment,
|
|
34
|
+
// default to the more stable node-fetch otherwise
|
|
31
35
|
const isNode = typeof process !== 'undefined' && !!((_a = process === null || process === void 0 ? void 0 : process.versions) === null || _a === void 0 ? void 0 : _a.node);
|
|
32
|
-
|
|
36
|
+
if (isNode) {
|
|
37
|
+
fetch = require('node-fetch');
|
|
38
|
+
}
|
|
39
|
+
const errors_1 = require("./errors");
|
|
33
40
|
__exportStar(require("./status_code"), exports);
|
|
34
41
|
var version_1 = require("./version");
|
|
35
42
|
Object.defineProperty(exports, "VERSION", { enumerable: true, get: function () { return version_1.VERSION; } });
|
|
36
43
|
var errors_2 = require("./errors");
|
|
37
44
|
Object.defineProperty(exports, "HttpRequestFailed", { enumerable: true, get: function () { return errors_2.HttpRequestFailed; } });
|
|
38
45
|
Object.defineProperty(exports, "HttpResponseError", { enumerable: true, get: function () { return errors_2.HttpResponseError; } });
|
|
39
|
-
|
|
40
|
-
(function (ResponseType) {
|
|
41
|
-
ResponseType["TEXT"] = "text";
|
|
42
|
-
ResponseType["JSON"] = "json";
|
|
43
|
-
})(ResponseType || (ResponseType = {}));
|
|
46
|
+
Object.defineProperty(exports, "HttpTimeoutError", { enumerable: true, get: function () { return errors_2.HttpTimeoutError; } });
|
|
44
47
|
class HttpBackend {
|
|
45
48
|
constructor(timeout = 30000) {
|
|
46
49
|
this.timeout = timeout;
|
|
@@ -82,53 +85,56 @@ class HttpBackend {
|
|
|
82
85
|
/**
|
|
83
86
|
*
|
|
84
87
|
* @param options contains options to be passed for the HTTP request (url, method and timeout)
|
|
85
|
-
* @throws {@link HttpRequestFailed} | {@link HttpResponseError}
|
|
88
|
+
* @throws {@link HttpRequestFailed} | {@link HttpResponseError} | {@link HttpTimeoutError}
|
|
86
89
|
*/
|
|
87
90
|
createRequest({ url, method, timeout = this.timeout, query, headers = {}, json = true }, data) {
|
|
88
91
|
return __awaiter(this, void 0, void 0, function* () {
|
|
92
|
+
// Serializes query params
|
|
89
93
|
const urlWithQuery = url + this.serialize(query);
|
|
90
|
-
|
|
91
|
-
let transformResponse = undefined;
|
|
94
|
+
// Adds default header entry if there aren't any Content-Type header
|
|
92
95
|
if (!headers['Content-Type']) {
|
|
93
96
|
headers['Content-Type'] = 'application/json';
|
|
94
97
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
resType = ResponseType.JSON;
|
|
101
|
-
}
|
|
98
|
+
// Creates a new AbortController instance to handle timeouts
|
|
99
|
+
const controller = new AbortController();
|
|
100
|
+
const t = setTimeout(() => controller.abort(), timeout);
|
|
102
101
|
try {
|
|
103
|
-
const response = yield
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
transformResponse,
|
|
109
|
-
timeout: timeout,
|
|
110
|
-
data: data,
|
|
111
|
-
adapter,
|
|
102
|
+
const response = yield fetch(urlWithQuery, {
|
|
103
|
+
method,
|
|
104
|
+
headers,
|
|
105
|
+
body: JSON.stringify(data),
|
|
106
|
+
signal: controller.signal,
|
|
112
107
|
});
|
|
113
|
-
|
|
108
|
+
if (typeof response === 'undefined') {
|
|
109
|
+
throw new Error('Response is undefined');
|
|
110
|
+
}
|
|
111
|
+
// Handle responses with status code >= 400
|
|
112
|
+
if (response.status >= 400) {
|
|
113
|
+
const errorData = yield response.text();
|
|
114
|
+
throw new errors_1.HttpResponseError(`Http error response: (${response.status}) ${errorData}`, response.status, response.statusText, errorData, urlWithQuery);
|
|
115
|
+
}
|
|
116
|
+
if (json) {
|
|
117
|
+
return response.json();
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
return response.text();
|
|
121
|
+
}
|
|
114
122
|
}
|
|
115
|
-
catch (
|
|
116
|
-
if (
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
else {
|
|
122
|
-
errorData = err.response.data;
|
|
123
|
-
}
|
|
124
|
-
throw new errors_1.HttpResponseError(`Http error response: (${err.response.status}) ${errorData}`, err.response.status, err.response.statusText, errorData, urlWithQuery);
|
|
123
|
+
catch (e) {
|
|
124
|
+
if (e instanceof Error && e.name === 'AbortError') {
|
|
125
|
+
throw new errors_1.HttpTimeoutError(timeout, urlWithQuery);
|
|
126
|
+
}
|
|
127
|
+
else if (e instanceof errors_1.HttpResponseError) {
|
|
128
|
+
throw e;
|
|
125
129
|
}
|
|
126
130
|
else {
|
|
127
|
-
throw new errors_1.HttpRequestFailed(String(method), urlWithQuery,
|
|
131
|
+
throw new errors_1.HttpRequestFailed(String(method), urlWithQuery, e);
|
|
128
132
|
}
|
|
129
133
|
}
|
|
134
|
+
finally {
|
|
135
|
+
clearTimeout(t);
|
|
136
|
+
}
|
|
130
137
|
});
|
|
131
138
|
}
|
|
132
139
|
}
|
|
133
140
|
exports.HttpBackend = HttpBackend;
|
|
134
|
-
//# sourceMappingURL=taquito-http-utils.js.map
|
package/dist/lib/version.js
CHANGED
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.VERSION = void 0;
|
|
4
4
|
// IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!
|
|
5
5
|
exports.VERSION = {
|
|
6
|
-
"commitHash": "
|
|
7
|
-
"version": "
|
|
6
|
+
"commitHash": "801b9525f497845e778696ccac8df3a7b0f299d8",
|
|
7
|
+
"version": "19.0.0"
|
|
8
8
|
};
|
|
9
|
-
//# sourceMappingURL=version.js.map
|