@best/api-db
Advanced tools
Comparing version 5.0.4 to 5.1.0
@@ -13,3 +13,4 @@ "use strict"; | ||
const types_1 = require("../../types"); | ||
const node_fetch_1 = __importDefault(require("node-fetch")); | ||
const https_1 = __importDefault(require("https")); | ||
const https_proxy_agent_1 = __importDefault(require("https-proxy-agent")); | ||
/** | ||
@@ -24,15 +25,41 @@ * An implementation for a REST-based DB adapter. | ||
} | ||
request(url, options, payload) { | ||
return new Promise((resolve, reject) => { | ||
// The 'https' library does not natively support requests over a proxy. | ||
// We can still add proxy support by setting `options.agent` to an instance of `https-proxy-agent` agent. | ||
// More details on what an agent is responsible for can be found here: https://nodejs.org/docs/latest-v14.x/api/http.html#http_class_http_agent | ||
const proxy = process.env.HTTP_PROXY; | ||
if (proxy) { | ||
// @ts-ignore | ||
options.agent = new https_proxy_agent_1.default(proxy); | ||
} | ||
const req = https_1.default.request(url, options, (response) => { | ||
let responseBody = ''; | ||
response.on('data', (chunk) => { | ||
responseBody += chunk; | ||
}); | ||
response.on('end', () => { | ||
resolve({ ok: true, body: responseBody }); | ||
}); | ||
}); | ||
req.on('error', (error) => { | ||
reject({ ok: false, error }); | ||
}); | ||
req.write(payload); | ||
req.end(); | ||
}); | ||
} | ||
async saveSnapshots(snapshots, projectName) { | ||
const requestUrl = `${this.config.uri}/api/v1/${projectName}/snapshots`; | ||
const response = await node_fetch_1.default(requestUrl, { | ||
method: 'post', | ||
body: JSON.stringify(snapshots), | ||
const payload = JSON.stringify(snapshots); | ||
const options = { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'Authorization': `Bearer ${this.config.token}` | ||
}, | ||
}); | ||
// Log the response body for troubleshooting purposes | ||
} | ||
}; | ||
const response = await this.request(requestUrl, options, payload); | ||
if (!response.ok) { | ||
console.error(await response.text()); | ||
console.error(response.error); | ||
return false; | ||
@@ -39,0 +66,0 @@ } |
@@ -8,5 +8,5 @@ { | ||
}, | ||
"version": "5.0.4", | ||
"version": "5.1.0", | ||
"dependencies": { | ||
"node-fetch": "~2.6.1", | ||
"https-proxy-agent": "^5.0.0", | ||
"pg": "^8.4.1", | ||
@@ -16,3 +16,2 @@ "sqlite": "^3.0.3" | ||
"devDependencies": { | ||
"@types/node-fetch": "2.5.12", | ||
"@types/pg": "^7.4.14" | ||
@@ -19,0 +18,0 @@ }, |
Network access
Supply chain riskThis module accesses the network.
Found 2 instances 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
33021
1
776
8
2
+ Addedhttps-proxy-agent@^5.0.0
+ Addedagent-base@6.0.2(transitive)
+ Addeddebug@4.4.0(transitive)
+ Addedhttps-proxy-agent@5.0.1(transitive)
- Removednode-fetch@~2.6.1
- Removednode-fetch@2.6.13(transitive)
- Removedtr46@0.0.3(transitive)
- Removedwebidl-conversions@3.0.1(transitive)
- Removedwhatwg-url@5.0.0(transitive)