syncano-server
Advanced tools
Comparing version 0.7.2-25 to 0.7.2-26
@@ -59,3 +59,4 @@ 'use strict'; | ||
var fetch = this.localFetch.bind(this); | ||
var fetch = this.fetch.bind(this); | ||
return fetch(this.url(endpoint), _extends({ | ||
@@ -62,0 +63,0 @@ method: 'POST', |
@@ -41,12 +41,2 @@ 'use strict'; | ||
}, { | ||
key: 'localFetch', | ||
value: function localFetch(url, options) { | ||
return (0, _nodeFetch2.default)(url, _extends({ | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'X-API-KEY': this.instance.token | ||
} | ||
}, options)).then(_utils.checkStatus); | ||
} | ||
}, { | ||
key: 'nonInstanceFetch', | ||
@@ -53,0 +43,0 @@ value: function nonInstanceFetch(url, options, headers) { |
@@ -26,6 +26,19 @@ 'use strict'; | ||
function parseJSON(response) { | ||
if (response.status === 202) { | ||
var mimetype = response.headers.get('Content-Type'); | ||
if (response.status === 204 || mimetype === null) { | ||
return Promise.resolve(); | ||
} | ||
return response.json(); | ||
// Parse JSON | ||
if (/^.*\/.*\+json/.test(mimetype) || /^application\/json/.test(mimetype)) { | ||
return response.json(); | ||
} | ||
// Parse XML and plain text | ||
if (/^text\/.*/.test(mimetype) || /^.*\/.*\+xml/.test(mimetype) || mimetype === 'text/plain') { | ||
return response.text(); | ||
} | ||
return response.arraybuffer(); | ||
} | ||
@@ -32,0 +45,0 @@ |
{ | ||
"name": "syncano-server", | ||
"version": "0.7.2-25", | ||
"version": "0.7.2-26", | ||
"description": "A library to intereact with the Syncano API on a server side", | ||
@@ -26,3 +26,3 @@ "main": "lib/index.js", | ||
"lint": "xo src/**/*.js test/**/*.js", | ||
"e2e": "mkdir e2e-tests || 1 && cross-env NODE_ENV=test mocha tests/e2e/*.js --reporter spec --require babel-register --timeout 30000 --slow 8000", | ||
"e2e": "mkdir e2e-tests || true && cross-env NODE_ENV=test mocha tests/e2e/*.js --reporter spec --require babel-register --timeout 30000 --slow 8000", | ||
"watch": "npm-run-all --parallel watch:*", | ||
@@ -43,3 +43,3 @@ "watch:lib": "npm run build:lib -- --watch", | ||
"dependencies": { | ||
"node-fetch": "^1.6.3" | ||
"node-fetch": "2.0.0-alpha.3" | ||
}, | ||
@@ -46,0 +46,0 @@ "devDependencies": { |
@@ -19,3 +19,4 @@ import QueryBuilder from './query-builder' | ||
client(endpoint, body = {}, options = {}) { | ||
const fetch = this.localFetch.bind(this) | ||
const fetch = this.fetch.bind(this) | ||
return fetch(this.url(endpoint), { | ||
@@ -22,0 +23,0 @@ method: 'POST', |
@@ -22,13 +22,2 @@ import nodeFetch from 'node-fetch' | ||
localFetch(url, options) { | ||
return nodeFetch(url, { | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'X-API-KEY': this.instance.token | ||
}, | ||
...options | ||
}) | ||
.then(checkStatus) | ||
} | ||
nonInstanceFetch(url, options, headers) { | ||
@@ -35,0 +24,0 @@ return nodeFetch(url, { |
@@ -16,6 +16,26 @@ import {getHost, SYNCANO_API_VERSION} from './settings' | ||
export function parseJSON(response) { | ||
if (response.status === 202) { | ||
const mimetype = response.headers.get('Content-Type') | ||
if (response.status === 204 || mimetype === null) { | ||
return Promise.resolve() | ||
} | ||
return response.json() | ||
// Parse JSON | ||
if ( | ||
/^.*\/.*\+json/.test(mimetype) || | ||
/^application\/json/.test(mimetype) | ||
) { | ||
return response.json() | ||
} | ||
// Parse XML and plain text | ||
if ( | ||
/^text\/.*/.test(mimetype) || | ||
/^.*\/.*\+xml/.test(mimetype) || | ||
mimetype === 'text/plain' | ||
) { | ||
return response.text() | ||
} | ||
return response.arraybuffer() | ||
} | ||
@@ -22,0 +42,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
536251
2070
+ Addedbabel-runtime@6.26.0(transitive)
+ Addedbuffer-to-arraybuffer@0.0.4(transitive)
+ Addedcore-js@2.6.12(transitive)
+ Addednode-fetch@2.0.0-alpha.3(transitive)
+ Addedregenerator-runtime@0.11.1(transitive)
- Removednode-fetch@1.7.3(transitive)
Updatednode-fetch@2.0.0-alpha.3