@bespoken-sdk/store
Advanced tools
Comparing version 0.12.1 to 0.13.1
const _ = require('lodash') | ||
const axios = require('axios').default | ||
const DTO = require('./dto') | ||
const logger = require('@bespoken-sdk/shared/lib/logger')('STORE') | ||
const Readable = require('stream').Readable | ||
@@ -12,9 +12,16 @@ const zlib = require('zlib') | ||
/** | ||
* @returns {string} | ||
*/ | ||
static accessURL () { | ||
return process.env.STORE_URL ? process.env.STORE_URL : 'https://batch.bespoken.io/batch' | ||
} | ||
/** | ||
* @param {string} run | ||
* @returns {Promise<DTO>} | ||
* @returns {Promise<any>} | ||
*/ | ||
async fetch (run) { | ||
console.time('BESPOKEN-STORE FETCH') | ||
const url = `${this.accessURL()}/fetch?run=${run}` | ||
console.info(`BESPOKEN-STORE FETCH run: ${run} url: ${url}`) | ||
logger.time('FETCH') | ||
const url = `${Client.accessURL()}/fetch?run=${run}` | ||
logger.info(`FETCH run: ${run} url: ${url}`) | ||
@@ -38,3 +45,3 @@ const streamResponse = await axios.get(url, { | ||
if (bufferLength !== previousLength) { | ||
console.info(`BESPOKEN-STORE FETCH downloaded: ${bufferLength}M`) | ||
logger.info(`FETCH downloaded: ${bufferLength}M`) | ||
previousLength = bufferLength | ||
@@ -46,3 +53,3 @@ } | ||
streamResponse.data.on('end', () => { | ||
console.timeEnd('BESPOKEN-STORE FETCH') | ||
logger.timeEnd('FETCH') | ||
const jobJSON = JSON.parse(buffer.toString('utf-8')) | ||
@@ -60,8 +67,8 @@ resolve(jobJSON) | ||
async filter (runName, limit = 10) { | ||
console.time('BESPOKEN-STORE FILTER') | ||
const url = `${this.accessURL()}/filter?run=${runName}&limit=${limit}` | ||
logger.time('FILTER') | ||
const url = `${Client.accessURL()}/filter?run=${runName}&limit=${limit}` | ||
const response = await axios.get(url) | ||
const jobs = response.data.jobs | ||
console.timeEnd('BESPOKEN-STORE FILTER') | ||
logger.timeEnd('FILTER') | ||
return jobs | ||
@@ -75,4 +82,4 @@ } | ||
async save (job) { | ||
console.time('BESPOKEN-STORE SAVE') | ||
const url = `${this.accessURL()}/save?run=${job.run}` | ||
logger.time('SAVE') | ||
const url = `${Client.accessURL()}/save?run=${job.run}` | ||
@@ -90,3 +97,3 @@ // Create a stream from the JSON | ||
console.timeEnd('BESPOKEN-STORE SAVE') | ||
logger.timeEnd('SAVE') | ||
job.key = response.data.key | ||
@@ -97,9 +104,2 @@ return response.data.key | ||
/** | ||
* @returns {string} | ||
*/ | ||
accessURL () { | ||
return process.env.STORE_URL ? process.env.STORE_URL : 'https://batch-tester.bespoken.io' | ||
} | ||
/** | ||
* @param {string} key | ||
@@ -109,21 +109,8 @@ * @returns {Promise<string>} | ||
async decrypt (key) { | ||
const url = `${this.accessURL()}/decrypt?key=${key}` | ||
const url = `${Client.accessURL()}/decrypt?key=${key}` | ||
const response = await axios.get(url) | ||
return response.data.decryptedKey | ||
} | ||
/** | ||
* @param {DTO} dto | ||
* @param {number} index | ||
* @returns {string} | ||
*/ | ||
logURL (dto, index) { | ||
if (!dto.key) { | ||
return 'N/A' | ||
} | ||
return `${this.accessURL()}/log?run=${dto.key}&index=${index}` | ||
} | ||
} | ||
module.exports = Client |
@@ -9,3 +9,3 @@ { | ||
"dependencies": { | ||
"@bespoken-sdk/shared": "^0.12.1", | ||
"@bespoken-sdk/shared": "^0.13.1", | ||
"axios": "^0.21.4", | ||
@@ -21,4 +21,4 @@ "lodash": "^4.17.21" | ||
}, | ||
"version": "0.12.1", | ||
"gitHead": "4c23a3a20a4ae00c5e0879d29f431eab266df7c9", | ||
"version": "0.13.1", | ||
"gitHead": "19f3720e80ac959b83557edb773a0c2a15ec8e4b", | ||
"devDependencies": { | ||
@@ -25,0 +25,0 @@ "@types/node": "^16.10.1" |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
3
11467
6
131
+ Added@bespoken-sdk/shared@0.13.8(transitive)
- Removed@bespoken-sdk/shared@0.12.1(transitive)
Updated@bespoken-sdk/shared@^0.13.1