first1-test
Advanced tools
Comparing version 1.0.18 to 1.0.19
66
index.js
@@ -6,14 +6,49 @@ const fetch = require('node-fetch') | ||
const FETCHERS = { | ||
const _FETCHERS = { | ||
notificationApi: { | ||
options: { | ||
key: process.env.NOTIFICATION_API_KEY | ||
withOptions: function () { | ||
return getFetchOptions() | ||
}, | ||
fetch: async function (options) { | ||
const defaultOptions = this.withOptions() | ||
const mergeOptions = { ...defaultOptions, options } | ||
return fetch(options.url, mergeOptions) | ||
.then(response => response.json()) | ||
.catch(error => console.log(error)) | ||
} | ||
}, | ||
v3Api: { | ||
withOptions: function (query, variables) { | ||
return { | ||
method: 'POST', | ||
body: JSON.stringify({ query, variables }), | ||
headers: { 'Content-Type': 'application/graphql' } | ||
} | ||
}, | ||
fetch: async function (query, variables) { | ||
const options = this.withOptions(query, variables) | ||
const url = process.env.GRAPHQL_URL | ||
return fetch(url, options) | ||
.then(response => response.json()) | ||
.catch(error => console.log(error)) | ||
} | ||
}, | ||
harvestApi: { | ||
withOptions: function () { | ||
return getFetchOptions(this.options) | ||
return getFetchOptions({ | ||
headers: { | ||
'Content-Type': 'application/x-www-form-urlencoded', | ||
Authorization: `Basic ${process.env.HARVEST_KEY}` | ||
} | ||
}) | ||
}, | ||
fetch: async function (url) { | ||
const options = this.withOptions() | ||
const response = await fetch(url, options) | ||
return response.json() | ||
console.log('url: ', url) | ||
const defaultOptions = this.withOptions() | ||
return fetch(`https://harvest.greenhouse.io/v1/${url}`, defaultOptions) | ||
.then(response => response.json()) | ||
.catch(error => console.log(error)) | ||
} | ||
@@ -25,13 +60,10 @@ } | ||
const notificationApi = async (url, body) => { | ||
return FETCHERS.notificationApi.fetch(url) | ||
const getExportObject = () => { | ||
const exported = {} | ||
for (const item in _FETCHERS) { | ||
exported[item] = (...arg) => _FETCHERS[item].fetch(...arg) | ||
} | ||
return exported | ||
} | ||
const runTest = async () => { | ||
const r = await notificationApi('https://jsonplaceholder.typicode.com/todos/1') | ||
console.log('Test:notificationApi ', r) | ||
} | ||
runTest() | ||
exports.notificationApi = notificationApi | ||
module.exports = getExportObject() |
{ | ||
"name": "first1-test", | ||
"version": "1.0.18", | ||
"version": "1.0.19", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
10
utils.js
const hasBody = (method) => { | ||
const hasBody = ({ method, body }) => { | ||
const methodWithBody = ['POST', 'PUT', 'DELETE'] | ||
return methodWithBody.includes(method) | ||
return body && methodWithBody.includes(method) | ||
} | ||
@@ -11,7 +11,5 @@ | ||
method: method || 'GET', | ||
body: hasBody(method) ? JSON.stringify(body) : null, | ||
body: hasBody(options) ? body : null, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
// Authorization: s`Bearer ${process.env.NOTIFICATION_API_KEY}`, | ||
// Authorization: s`Bearer ${key}`, | ||
...headers | ||
@@ -22,6 +20,4 @@ } | ||
return fetchOptions | ||
// const response = await fetch(url, options); | ||
// return response.json(); | ||
} | ||
exports.getFetchOptions = getFetchOptions |
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances 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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
3652
6
101
3
3