@fabernovel/heart-core
Advanced tools
Comparing version 1.4.0 to 1.5.0
@@ -0,1 +1,5 @@ | ||
## [1.5.0] - 2019-06-13 | ||
### Added | ||
- Added support for POST request with 'Content-Type: application/x-www-form-urlencoded' | ||
## [1.4.0] - 2019-06-13 | ||
@@ -2,0 +6,0 @@ ### Added |
@@ -5,2 +5,5 @@ import { HeadersInit } from 'node-fetch'; | ||
private static POST; | ||
static HEADER_CONTENT_TYPE: string; | ||
static HEADER_CONTENT_TYPE_JSON: string; | ||
static HEADER_CONTENT_TYPE_X_WWW_FORM_URLENCODED: string; | ||
private static BASE_HEADER; | ||
@@ -7,0 +10,0 @@ static get(url: string, headers?: HeadersInit | { |
@@ -12,2 +12,3 @@ "use strict"; | ||
const node_fetch_1 = require("node-fetch"); | ||
const querystring_1 = require("querystring"); | ||
class Request { | ||
@@ -24,6 +25,19 @@ static get(url, headers = {}) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let bodyString = ''; | ||
headers = Object.assign({}, Request.BASE_HEADER, headers); | ||
switch (headers[Request.HEADER_CONTENT_TYPE]) { | ||
case Request.HEADER_CONTENT_TYPE_JSON: | ||
bodyString = JSON.stringify(body); | ||
break; | ||
case Request.HEADER_CONTENT_TYPE_X_WWW_FORM_URLENCODED: | ||
bodyString = querystring_1.stringify(body); | ||
break; | ||
default: | ||
return Promise.reject({ error: 'invalid-header', message: 'Unsupported header Content-Type' }); | ||
break; | ||
} | ||
return yield node_fetch_1.default(url, { | ||
method: Request.POST, | ||
body: JSON.stringify(body), | ||
headers: Object.assign({}, Request.BASE_HEADER, headers) | ||
body: bodyString, | ||
headers | ||
}).then((res) => res.json()); | ||
@@ -35,5 +49,8 @@ }); | ||
Request.POST = 'POST'; | ||
Request.HEADER_CONTENT_TYPE = 'Content-Type'; | ||
Request.HEADER_CONTENT_TYPE_JSON = 'application/json'; | ||
Request.HEADER_CONTENT_TYPE_X_WWW_FORM_URLENCODED = 'application/x-www-form-urlencoded'; | ||
Request.BASE_HEADER = { | ||
'Content-Type': 'application/json' | ||
[Request.HEADER_CONTENT_TYPE]: Request.HEADER_CONTENT_TYPE_JSON | ||
}; | ||
exports.default = Request; |
/** | ||
* Define a report that is common to every heart-* analysis module. | ||
* | ||
* /!\ WARNING /!\ | ||
* Don't change the Report class structure: it's a central point in the exchanges between Heart modules. | ||
*/ | ||
@@ -4,0 +7,0 @@ export default class Report { |
@@ -5,2 +5,5 @@ "use strict"; | ||
* Define a report that is common to every heart-* analysis module. | ||
* | ||
* /!\ WARNING /!\ | ||
* Don't change the Report class structure: it's a central point in the exchanges between Heart modules. | ||
*/ | ||
@@ -7,0 +10,0 @@ class Report { |
{ | ||
"name": "@fabernovel/heart-core", | ||
"version": "1.4.0", | ||
"version": "1.5.0", | ||
"description": "Centralize helpful code needed by the others @fabernovel/heart-* modules", | ||
@@ -5,0 +5,0 @@ "homepage": "https://gitlab.com/fabernovel/heart/heart-core", |
# Description | ||
_Heart Core_ centralize helpful code needed by the others @fabernovel/heart-* packages. | ||
_Heart Core_ centralize helpful code needed by the _Heart_ modules. |
25366
510