@marcopeg/utils
Advanced tools
Comparing version 1.2.0 to 1.3.0
@@ -8,3 +8,4 @@ /** | ||
const winston = require('winston') | ||
// const winston = require('winston') | ||
const log = require('./logger/verbose') | ||
@@ -16,3 +17,3 @@ const init = () => {} | ||
if (defaultValue) { | ||
winston.verbose(`${key}::default::${defaultValue}`) | ||
log(`${key}::default::${defaultValue}`) | ||
return defaultValue | ||
@@ -23,3 +24,3 @@ } | ||
} | ||
winston.verbose(`${key}::${process.env[key]}`) | ||
log(`${key}::${process.env[key]}`) | ||
return process.env[key] | ||
@@ -26,0 +27,0 @@ } |
/* global fetch */ | ||
const pause = require('./pause') | ||
const { isDev, get: getConfig } = require('./config') | ||
const { isDev } = require('./config') | ||
@@ -28,11 +28,10 @@ require('es6-promise').polyfill() | ||
try { | ||
const headers = config.headers || {} | ||
const res = await wrappedFetch(url, { | ||
...config, | ||
const headers = Object.assign({}, config.headers || {}, { | ||
'content-type': 'application/json', | ||
}) | ||
const options = Object.assign({}, config, { | ||
method: 'GET', | ||
headers: { | ||
...headers, | ||
'content-type': 'application/json', | ||
}, | ||
headers: headers, | ||
}) | ||
const res = await wrappedFetch(url, options) | ||
@@ -60,10 +59,9 @@ // status code error handling | ||
const getJSONAuth = (url, token, config = {}) => { | ||
const headers = config.headers || {} | ||
return getJSON(url, { | ||
...config, | ||
headers: { | ||
...headers, | ||
Authorization: `Bearer ${token}`, | ||
}, | ||
const headers = Object.assign({}, config.headers || {}, { | ||
Authorization: `Bearer ${token}`, | ||
}) | ||
const options = Object.assign({}, config, { | ||
headers: headers, | ||
}) | ||
return getJSON(url, options) | ||
} | ||
@@ -73,12 +71,11 @@ | ||
try { | ||
const headers = config.headers || {} | ||
const res = await wrappedFetch(url, { | ||
...config, | ||
const headers = Object.assign({}, config.headers || {}, { | ||
'content-type': 'application/json', | ||
}) | ||
const options = Object.assign({}, config, { | ||
method: 'POST', | ||
headers: { | ||
...headers, | ||
'content-type': 'application/json', | ||
}, | ||
headers: headers, | ||
body: JSON.stringify(data), | ||
}) | ||
const res = await wrappedFetch(url, options) | ||
@@ -106,10 +103,9 @@ // status code error handling | ||
const postJSONAuth = (url, token, data = {}, config = {}) => { | ||
const headers = config.headers || {} | ||
return postJSON(url, data, { | ||
...config, | ||
headers: { | ||
...headers, | ||
Authorization: `Bearer ${token}`, | ||
}, | ||
const headers = Object.assign({}, config.headers || {}, { | ||
Authorization: `Bearer ${token}`, | ||
}) | ||
const options = Object.assign({}, config, { | ||
headers: headers, | ||
}) | ||
return postJSON(url, data, options) | ||
} | ||
@@ -119,12 +115,11 @@ | ||
try { | ||
const headers = config.headers || {} | ||
const res = await wrappedFetch(url, { | ||
...config, | ||
const headers = Object.assign({}, config.headers || {}, { | ||
'content-type': 'application/json', | ||
}) | ||
const options = Object.assign({}, config, { | ||
method: 'PUT', | ||
headers: { | ||
...headers, | ||
'content-type': 'application/json', | ||
}, | ||
headers: headers, | ||
body: JSON.stringify(data), | ||
}) | ||
const res = await wrappedFetch(url, options) | ||
@@ -152,10 +147,9 @@ // status code error handling | ||
const putJSONAuth = (url, token, data = {}, config = {}) => { | ||
const headers = config.headers || {} | ||
return putJSON(url, data, { | ||
...config, | ||
headers: { | ||
...headers, | ||
Authorization: `Bearer ${token}`, | ||
}, | ||
const headers = Object.assign({}, config.headers || {}, { | ||
Authorization: `Bearer ${token}`, | ||
}) | ||
const options = Object.assign({}, config, { | ||
headers: headers, | ||
}) | ||
return putJSON(url, data, options) | ||
} | ||
@@ -172,2 +166,2 @@ | ||
module.exports = wrappedFetch | ||
module.exports = wrappedFetch |
{ | ||
"name": "@marcopeg/utils", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "Javascript utils for server and client projects", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12316
15
227