@taquito/http-utils 11.1.0 → 12.0.0-beta-RC.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/README.md CHANGED
@@ -1,20 +1,47 @@
1
1
  # Taquito HTTP Utilities package
2
+ *TypeDoc style documentation is available [here](https://tezostaquito.io/typedoc/modules/_taquito_http_utils.html)*
2
3
 
3
- `@taquito/http-utils` is an npm package that provides developers with http functionality for Taquito.
4
+ `@taquito/http-utils` is an npm package that provides developers with http functionality for Taquito.
4
5
 
5
- The `HttpBackend` class contains a `createRequest` method which accepts options to be passed for the HTTP request (url, method, timeout, json, query, headers, mimeType).
6
+ ## General Information
6
7
 
8
+ The `HttpBackend` class contains a `createRequest` method which accepts options to be passed for the HTTP request (url, method, timeout, json, query, headers, mimeType). This method will help users interact with the RPC with a more familiar HTTP format.
9
+
10
+ Parameters for `createRequest`:
11
+
12
+ `url`(string): RPC URL pointing to the Tezos node
13
+ `method`(string): HTTP method of the request
14
+ `timeout`(number): request timeout
15
+ `json`(boolean): Parse response into JSON when set to `true`; defaults to `true`
16
+ `query`(object): Query that we would like to pass as an HTTP request
17
+ `headers`(object): HTTP request header
18
+ `mimeType`(string): Sets the MIME type of the request; see [MIME types](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types)
19
+
20
+
21
+ ## Install
22
+ The package(s) need to be installed as follows
23
+ ```
24
+ npm install @taquito/http-utils
25
+ ```
26
+
27
+ ## Usage
28
+ Create an instance of `HttpBackend` and call it's member function `createRequest` to construct an HTTP request.
7
29
  ```ts
8
30
  import { HttpBackend } from '@taquito/http-utils';
9
31
 
10
- const http = new HttpBackend();
11
- ```
32
+ const httpBackend = new HttpBackend();
33
+ const response = httpBackend.createRequest<string>({
34
+ url: `/chains/${chain}/blocks/${block}/context/contracts/${address}/script`,
35
+ method: 'GET',
36
+ mimeType: "text; charset=utf-8",
37
+ json: false
38
+ });
12
39
 
13
- See the top-level [https://github.com/ecadlabs/taquito](https://github.com/ecadlabs/taquito) file for details on reporting issues, contributing and versioning.
40
+ ```
14
41
 
15
- ## API Documentation
42
+ ## Additional Info
43
+ See the top-level https://github.com/ecadlabs/taquito file for details on reporting issues, contributing, and versioning.
16
44
 
17
- TypeDoc style documentation is available on-line [here](https://tezostaquito.io/typedoc/modules/_taquito_http_utils.html)
18
45
 
19
46
  ## Disclaimer
20
47
 
@@ -13,18 +13,30 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
13
13
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
17
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
18
+ return new (P || (P = Promise))(function (resolve, reject) {
19
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
20
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
21
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
22
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
23
+ });
24
+ };
16
25
  Object.defineProperty(exports, "__esModule", { value: true });
17
26
  exports.HttpBackend = exports.HttpRequestFailed = exports.HttpResponseError = exports.VERSION = void 0;
18
- // tslint:disable: strict-type-predicates
19
- var isNode = typeof process !== 'undefined' && process.versions != null && process.versions.node != null;
20
- // tslint:enable: strict-type-predicates
21
- var XMLHttpRequestCTOR = isNode ? require('xhr2-cookies').XMLHttpRequest : XMLHttpRequest;
27
+ const axios_1 = require("axios");
22
28
  __exportStar(require("./status_code"), exports);
23
29
  var version_1 = require("./version");
24
30
  Object.defineProperty(exports, "VERSION", { enumerable: true, get: function () { return version_1.VERSION; } });
25
- var defaultTimeout = 30000;
26
- var HttpResponseError = /** @class */ (function () {
27
- function HttpResponseError(message, status, statusText, body, url) {
31
+ const defaultTimeout = 30000;
32
+ var ResponseType;
33
+ (function (ResponseType) {
34
+ ResponseType["TEXT"] = "text";
35
+ ResponseType["JSON"] = "json";
36
+ })(ResponseType || (ResponseType = {}));
37
+ class HttpResponseError extends Error {
38
+ constructor(message, status, statusText, body, url) {
39
+ super(message);
28
40
  this.message = message;
29
41
  this.status = status;
30
42
  this.statusText = statusText;
@@ -32,115 +44,100 @@ var HttpResponseError = /** @class */ (function () {
32
44
  this.url = url;
33
45
  this.name = 'HttpResponse';
34
46
  }
35
- return HttpResponseError;
36
- }());
47
+ }
37
48
  exports.HttpResponseError = HttpResponseError;
38
- var HttpRequestFailed = /** @class */ (function () {
39
- function HttpRequestFailed(url, innerEvent) {
49
+ class HttpRequestFailed extends Error {
50
+ constructor(url, innerEvent) {
51
+ super(`Request to ${url} failed`);
40
52
  this.url = url;
41
53
  this.innerEvent = innerEvent;
42
54
  this.name = 'HttpRequestFailed';
43
- this.message = "Request to " + url + " failed";
44
55
  }
45
- return HttpRequestFailed;
46
- }());
56
+ }
47
57
  exports.HttpRequestFailed = HttpRequestFailed;
48
- var HttpBackend = /** @class */ (function () {
49
- function HttpBackend() {
50
- }
51
- HttpBackend.prototype.serialize = function (obj) {
58
+ class HttpBackend {
59
+ serialize(obj) {
52
60
  if (!obj) {
53
61
  return '';
54
62
  }
55
- var str = [];
56
- var _loop_1 = function (p) {
63
+ const str = [];
64
+ for (const p in obj) {
65
+ // eslint-disable-next-line no-prototype-builtins
57
66
  if (obj.hasOwnProperty(p) && typeof obj[p] !== 'undefined') {
58
- var prop = typeof obj[p].toJSON === 'function' ? obj[p].toJSON() : obj[p];
67
+ const prop = typeof obj[p].toJSON === 'function' ? obj[p].toJSON() : obj[p];
59
68
  // query arguments can have no value so we need some way of handling that
60
69
  // example https://domain.com/query?all
61
70
  if (prop === null) {
62
71
  str.push(encodeURIComponent(p));
63
- return "continue";
72
+ continue;
64
73
  }
65
74
  // another use case is multiple arguments with the same name
66
75
  // they are passed as array
67
76
  if (Array.isArray(prop)) {
68
- prop.forEach(function (item) {
77
+ prop.forEach((item) => {
69
78
  str.push(encodeURIComponent(p) + '=' + encodeURIComponent(item));
70
79
  });
71
- return "continue";
80
+ continue;
72
81
  }
73
82
  str.push(encodeURIComponent(p) + '=' + encodeURIComponent(prop));
74
83
  }
75
- };
76
- for (var p in obj) {
77
- _loop_1(p);
78
84
  }
79
- var serialized = str.join('&');
85
+ const serialized = str.join('&');
80
86
  if (serialized) {
81
- return "?" + serialized;
87
+ return `?${serialized}`;
82
88
  }
83
89
  else {
84
90
  return '';
85
91
  }
86
- };
87
- HttpBackend.prototype.createXHR = function () {
88
- return new XMLHttpRequestCTOR();
89
- };
92
+ }
90
93
  /**
91
94
  *
92
95
  * @param options contains options to be passed for the HTTP request (url, method and timeout)
93
96
  */
94
- HttpBackend.prototype.createRequest = function (_a, data) {
95
- var _this = this;
96
- var url = _a.url, method = _a.method, timeout = _a.timeout, query = _a.query, _b = _a.headers, headers = _b === void 0 ? {} : _b, _c = _a.json, json = _c === void 0 ? true : _c, _d = _a.mimeType, mimeType = _d === void 0 ? undefined : _d;
97
- return new Promise(function (resolve, reject) {
98
- var request = _this.createXHR();
99
- request.open(method || 'GET', "" + url + _this.serialize(query));
97
+ createRequest({ url, method, timeout = defaultTimeout, query, headers = {}, json = true }, data) {
98
+ return __awaiter(this, void 0, void 0, function* () {
99
+ let resType;
100
+ let transformResponse = undefined;
100
101
  if (!headers['Content-Type']) {
101
- request.setRequestHeader('Content-Type', 'application/json');
102
+ headers['Content-Type'] = 'application/json';
103
+ }
104
+ if (!json) {
105
+ resType = ResponseType.TEXT;
106
+ transformResponse = [(v) => v];
102
107
  }
103
- if (mimeType) {
104
- request.overrideMimeType("" + mimeType);
108
+ else {
109
+ resType = ResponseType.JSON;
105
110
  }
106
- for (var k in headers) {
107
- request.setRequestHeader(k, headers[k]);
111
+ let response;
112
+ try {
113
+ response = yield axios_1.default.request({
114
+ url: url + this.serialize(query),
115
+ method: method !== null && method !== void 0 ? method : 'GET',
116
+ headers: headers,
117
+ responseType: resType,
118
+ transformResponse,
119
+ timeout: timeout,
120
+ data: data,
121
+ });
108
122
  }
109
- request.timeout = timeout || defaultTimeout;
110
- request.onload = function () {
111
- if (this.status >= 200 && this.status < 300) {
112
- if (json) {
113
- try {
114
- resolve(JSON.parse(request.response));
115
- }
116
- catch (ex) {
117
- reject(new Error("Unable to parse response: " + request.response));
118
- }
123
+ catch (err) {
124
+ if (err.response) {
125
+ let errorData;
126
+ if (typeof err.response.data === 'object') {
127
+ errorData = JSON.stringify(err.response.data);
119
128
  }
120
129
  else {
121
- resolve(request.response);
130
+ errorData = err.response.data;
122
131
  }
132
+ throw new HttpResponseError(`Http error response: (${err.response.status}) ${errorData}`, err.response.status, err.response.statusText, errorData, url + this.serialize(query));
123
133
  }
124
134
  else {
125
- reject(new HttpResponseError("Http error response: (" + this.status + ") " + request.response, this.status, request.statusText, request.response, url));
135
+ throw new Error(err);
126
136
  }
127
- };
128
- request.ontimeout = function () {
129
- reject(new Error("Request timed out after: " + request.timeout + "ms"));
130
- };
131
- request.onerror = function (err) {
132
- reject(new HttpRequestFailed(url, err));
133
- };
134
- if (data) {
135
- var dataStr = JSON.stringify(data);
136
- request.send(dataStr);
137
- }
138
- else {
139
- request.send();
140
137
  }
138
+ return response.data;
141
139
  });
142
- };
143
- return HttpBackend;
144
- }());
140
+ }
141
+ }
145
142
  exports.HttpBackend = HttpBackend;
146
143
  //# sourceMappingURL=taquito-http-utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"taquito-http-utils.js","sourceRoot":"","sources":["../../src/taquito-http-utils.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;AAIH,yCAAyC;AACzC,IAAM,MAAM,GACV,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,CAAC,QAAQ,IAAI,IAAI,IAAI,OAAO,CAAC,QAAQ,CAAC,IAAI,IAAI,IAAI,CAAC;AAC9F,wCAAwC;AAEx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AAQ,CAAC,IAAI,KAAK,QAAQ,EAAE;wBACzC,SAAS,GAAI,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;qBAChD;yBAAM;wBACL,SAAS,GAAG,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC;qBAC/B;oBAED,MAAM,IAAI,iBAAiB,CACzB,yBAAyB,GAAG,CAAC,QAAQ,CAAC,MAAM,KAAK,SAAS,EAAE,EAC5D,GAAG,CAAC,QAAQ,CAAC,MAAqB,EAClC,GAAG,CAAC,QAAQ,CAAC,UAAU,EACvB,SAAS,EACT,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAC5B,CAAA;iBACF;qBAAM;oBACL,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,CAAA;iBACrB;aACF;YAED,OAAO,QAAQ,CAAC,IAAI,CAAA;QACtB,CAAC;KAAA;CACF;AApGD,kCAoGC"}
@@ -2,10 +2,8 @@
2
2
  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
- /* tslint:disable */
6
5
  exports.VERSION = {
7
- "commitHash": "e1723ab725df70755b4cd73b75aa981f913d0d5c",
8
- "version": "11.1.0"
6
+ "commitHash": "5da8cec9c84c0ab7bc37c0eb09e68db1b3a8b1f0",
7
+ "version": "12.0.0-beta-RC.0"
9
8
  };
10
- /* tslint:enable */
11
9
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";;;AACA,2EAA2E;AAC3E,oBAAoB;AACP,QAAA,OAAO,GAAG;IACnB,YAAY,EAAE,0CAA0C;IACxD,SAAS,EAAE,QAAQ;CACtB,CAAC;AACF,mBAAmB"}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";;;AACA,2EAA2E;AAC9D,QAAA,OAAO,GAAG;IACnB,YAAY,EAAE,0CAA0C;IACxD,SAAS,EAAE,kBAAkB;CAChC,CAAC"}
@@ -1,3 +1,30 @@
1
+ import axios from 'axios';
2
+
3
+ /*! *****************************************************************************
4
+ Copyright (c) Microsoft Corporation.
5
+
6
+ Permission to use, copy, modify, and/or distribute this software for any
7
+ purpose with or without fee is hereby granted.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
+ PERFORMANCE OF THIS SOFTWARE.
16
+ ***************************************************************************** */
17
+
18
+ function __awaiter(thisArg, _arguments, P, generator) {
19
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
20
+ return new (P || (P = Promise))(function (resolve, reject) {
21
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
22
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
23
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
24
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
25
+ });
26
+ }
27
+
1
28
  /**
2
29
  * Hypertext Transfer Protocol (HTTP) response status codes.
3
30
  * @see {@link https://en.wikipedia.org/wiki/List_of_HTTP_status_codes}
@@ -319,24 +346,24 @@ var STATUS_CODE;
319
346
  })(STATUS_CODE || (STATUS_CODE = {}));
320
347
 
321
348
  // IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!
322
- /* tslint:disable */
323
- var VERSION = {
324
- "commitHash": "e1723ab725df70755b4cd73b75aa981f913d0d5c",
325
- "version": "11.1.0"
326
- };
327
- /* tslint:enable */
349
+ const VERSION = {
350
+ "commitHash": "5da8cec9c84c0ab7bc37c0eb09e68db1b3a8b1f0",
351
+ "version": "12.0.0-beta-RC.0"
352
+ };
328
353
 
329
354
  /**
330
355
  * @packageDocumentation
331
356
  * @module @taquito/http-utils
332
357
  */
333
- // tslint:disable: strict-type-predicates
334
- var isNode = typeof process !== 'undefined' && process.versions != null && process.versions.node != null;
335
- // tslint:enable: strict-type-predicates
336
- var XMLHttpRequestCTOR = isNode ? require('xhr2-cookies').XMLHttpRequest : XMLHttpRequest;
337
- var defaultTimeout = 30000;
338
- var HttpResponseError = /** @class */ (function () {
339
- function HttpResponseError(message, status, statusText, body, url) {
358
+ const defaultTimeout = 30000;
359
+ var ResponseType;
360
+ (function (ResponseType) {
361
+ ResponseType["TEXT"] = "text";
362
+ ResponseType["JSON"] = "json";
363
+ })(ResponseType || (ResponseType = {}));
364
+ class HttpResponseError extends Error {
365
+ constructor(message, status, statusText, body, url) {
366
+ super(message);
340
367
  this.message = message;
341
368
  this.status = status;
342
369
  this.statusText = statusText;
@@ -344,114 +371,99 @@ var HttpResponseError = /** @class */ (function () {
344
371
  this.url = url;
345
372
  this.name = 'HttpResponse';
346
373
  }
347
- return HttpResponseError;
348
- }());
349
- var HttpRequestFailed = /** @class */ (function () {
350
- function HttpRequestFailed(url, innerEvent) {
374
+ }
375
+ class HttpRequestFailed extends Error {
376
+ constructor(url, innerEvent) {
377
+ super(`Request to ${url} failed`);
351
378
  this.url = url;
352
379
  this.innerEvent = innerEvent;
353
380
  this.name = 'HttpRequestFailed';
354
- this.message = "Request to " + url + " failed";
355
- }
356
- return HttpRequestFailed;
357
- }());
358
- var HttpBackend = /** @class */ (function () {
359
- function HttpBackend() {
360
381
  }
361
- HttpBackend.prototype.serialize = function (obj) {
382
+ }
383
+ class HttpBackend {
384
+ serialize(obj) {
362
385
  if (!obj) {
363
386
  return '';
364
387
  }
365
- var str = [];
366
- var _loop_1 = function (p) {
388
+ const str = [];
389
+ for (const p in obj) {
390
+ // eslint-disable-next-line no-prototype-builtins
367
391
  if (obj.hasOwnProperty(p) && typeof obj[p] !== 'undefined') {
368
- var prop = typeof obj[p].toJSON === 'function' ? obj[p].toJSON() : obj[p];
392
+ const prop = typeof obj[p].toJSON === 'function' ? obj[p].toJSON() : obj[p];
369
393
  // query arguments can have no value so we need some way of handling that
370
394
  // example https://domain.com/query?all
371
395
  if (prop === null) {
372
396
  str.push(encodeURIComponent(p));
373
- return "continue";
397
+ continue;
374
398
  }
375
399
  // another use case is multiple arguments with the same name
376
400
  // they are passed as array
377
401
  if (Array.isArray(prop)) {
378
- prop.forEach(function (item) {
402
+ prop.forEach((item) => {
379
403
  str.push(encodeURIComponent(p) + '=' + encodeURIComponent(item));
380
404
  });
381
- return "continue";
405
+ continue;
382
406
  }
383
407
  str.push(encodeURIComponent(p) + '=' + encodeURIComponent(prop));
384
408
  }
385
- };
386
- for (var p in obj) {
387
- _loop_1(p);
388
409
  }
389
- var serialized = str.join('&');
410
+ const serialized = str.join('&');
390
411
  if (serialized) {
391
- return "?" + serialized;
412
+ return `?${serialized}`;
392
413
  }
393
414
  else {
394
415
  return '';
395
416
  }
396
- };
397
- HttpBackend.prototype.createXHR = function () {
398
- return new XMLHttpRequestCTOR();
399
- };
417
+ }
400
418
  /**
401
419
  *
402
420
  * @param options contains options to be passed for the HTTP request (url, method and timeout)
403
421
  */
404
- HttpBackend.prototype.createRequest = function (_a, data) {
405
- var _this = this;
406
- var url = _a.url, method = _a.method, timeout = _a.timeout, query = _a.query, _b = _a.headers, headers = _b === void 0 ? {} : _b, _c = _a.json, json = _c === void 0 ? true : _c, _d = _a.mimeType, mimeType = _d === void 0 ? undefined : _d;
407
- return new Promise(function (resolve, reject) {
408
- var request = _this.createXHR();
409
- request.open(method || 'GET', "" + url + _this.serialize(query));
422
+ createRequest({ url, method, timeout = defaultTimeout, query, headers = {}, json = true }, data) {
423
+ return __awaiter(this, void 0, void 0, function* () {
424
+ let resType;
425
+ let transformResponse = undefined;
410
426
  if (!headers['Content-Type']) {
411
- request.setRequestHeader('Content-Type', 'application/json');
427
+ headers['Content-Type'] = 'application/json';
412
428
  }
413
- if (mimeType) {
414
- request.overrideMimeType("" + mimeType);
429
+ if (!json) {
430
+ resType = ResponseType.TEXT;
431
+ transformResponse = [(v) => v];
415
432
  }
416
- for (var k in headers) {
417
- request.setRequestHeader(k, headers[k]);
433
+ else {
434
+ resType = ResponseType.JSON;
418
435
  }
419
- request.timeout = timeout || defaultTimeout;
420
- request.onload = function () {
421
- if (this.status >= 200 && this.status < 300) {
422
- if (json) {
423
- try {
424
- resolve(JSON.parse(request.response));
425
- }
426
- catch (ex) {
427
- reject(new Error("Unable to parse response: " + request.response));
428
- }
436
+ let response;
437
+ try {
438
+ response = yield axios.request({
439
+ url: url + this.serialize(query),
440
+ method: method !== null && method !== void 0 ? method : 'GET',
441
+ headers: headers,
442
+ responseType: resType,
443
+ transformResponse,
444
+ timeout: timeout,
445
+ data: data,
446
+ });
447
+ }
448
+ catch (err) {
449
+ if (err.response) {
450
+ let errorData;
451
+ if (typeof err.response.data === 'object') {
452
+ errorData = JSON.stringify(err.response.data);
429
453
  }
430
454
  else {
431
- resolve(request.response);
455
+ errorData = err.response.data;
432
456
  }
457
+ throw new HttpResponseError(`Http error response: (${err.response.status}) ${errorData}`, err.response.status, err.response.statusText, errorData, url + this.serialize(query));
433
458
  }
434
459
  else {
435
- reject(new HttpResponseError("Http error response: (" + this.status + ") " + request.response, this.status, request.statusText, request.response, url));
460
+ throw new Error(err);
436
461
  }
437
- };
438
- request.ontimeout = function () {
439
- reject(new Error("Request timed out after: " + request.timeout + "ms"));
440
- };
441
- request.onerror = function (err) {
442
- reject(new HttpRequestFailed(url, err));
443
- };
444
- if (data) {
445
- var dataStr = JSON.stringify(data);
446
- request.send(dataStr);
447
- }
448
- else {
449
- request.send();
450
462
  }
463
+ return response.data;
451
464
  });
452
- };
453
- return HttpBackend;
454
- }());
465
+ }
466
+ }
455
467
 
456
468
  export { HttpBackend, HttpRequestFailed, HttpResponseError, STATUS_CODE, VERSION };
457
- //# sourceMappingURL=taquito-http-utils.es5.js.map
469
+ //# sourceMappingURL=taquito-http-utils.es6.js.map