@bespoken-sdk/store
Advanced tools
Comparing version 0.13.7 to 0.13.8-alpha.0
const _ = require('lodash') | ||
const axios = require('axios').default | ||
const logger = require('@bespoken-sdk/shared/lib/logger')('STORE') | ||
const DTO = require('./dto') | ||
const Readable = require('stream').Readable | ||
const Store = require('./store') | ||
const zlib = require('zlib') | ||
@@ -10,18 +11,11 @@ | ||
*/ | ||
class Client { | ||
class Client extends Store { | ||
/** | ||
* @returns {string} | ||
*/ | ||
static accessURL () { | ||
return process.env.STORE_URL ? process.env.STORE_URL : 'https://store.bespoken.io/store' | ||
} | ||
/** | ||
* @param {string} run | ||
* @returns {Promise<any>} | ||
* @returns {Promise<DTO>} | ||
*/ | ||
async fetch (run) { | ||
logger.time('FETCH') | ||
const url = `${Client.accessURL()}/fetch?run=${run}` | ||
logger.info(`FETCH run: ${run} url: ${url}`) | ||
console.time('BESPOKEN-STORE FETCH') | ||
const url = `${this.accessURL()}/fetch?run=${run}` | ||
console.info(`BESPOKEN-STORE FETCH run: ${run} url: ${url}`) | ||
@@ -45,3 +39,3 @@ const streamResponse = await axios.get(url, { | ||
if (bufferLength !== previousLength) { | ||
logger.info(`FETCH downloaded: ${bufferLength}M`) | ||
console.info(`BESPOKEN-STORE FETCH downloaded: ${bufferLength}M`) | ||
previousLength = bufferLength | ||
@@ -53,3 +47,3 @@ } | ||
streamResponse.data.on('end', () => { | ||
logger.timeEnd('FETCH') | ||
console.timeEnd('BESPOKEN-STORE FETCH') | ||
const jobJSON = JSON.parse(buffer.toString('utf-8')) | ||
@@ -67,8 +61,8 @@ resolve(jobJSON) | ||
async filter (runName, limit = 10) { | ||
logger.time('FILTER') | ||
const url = `${Client.accessURL()}/filter?run=${runName}&limit=${limit}` | ||
console.time('BESPOKEN-STORE FILTER') | ||
const url = `${this.accessURL()}/filter?run=${runName}&limit=${limit}` | ||
const response = await axios.get(url) | ||
const jobs = response.data.jobs | ||
logger.timeEnd('FILTER') | ||
console.timeEnd('BESPOKEN-STORE FILTER') | ||
return jobs | ||
@@ -78,13 +72,11 @@ } | ||
/** | ||
* @param {string} key | ||
* @param {any} json | ||
* @param {any} job | ||
* @returns {Promise<string>} The UUID assigned to the job | ||
*/ | ||
async save (key, json) { | ||
logger.time('SAVE') | ||
const url = `${Client.accessURL()}/save?key=${key}` | ||
logger.info('URL for saving: ' + url) | ||
const jsonString = JSON.stringify(json) | ||
async save (job) { | ||
console.time('BESPOKEN-STORE SAVE') | ||
const url = `${this.accessURL()}/save?run=${job.run}` | ||
// Create a stream from the JSON | ||
const jsonStream = Readable.from(jsonString) | ||
const jsonStream = Readable.from(JSON.stringify(job)) | ||
const gzipStream = jsonStream.pipe(zlib.createGzip()) | ||
@@ -99,3 +91,4 @@ const response = await axios.post(url, gzipStream, { | ||
logger.timeEnd('SAVE') | ||
console.timeEnd('BESPOKEN-STORE SAVE') | ||
job.key = response.data.key | ||
return response.data.key | ||
@@ -105,2 +98,9 @@ } | ||
/** | ||
* @returns {string} | ||
*/ | ||
accessURL () { | ||
return process.env.STORE_URL ? process.env.STORE_URL : 'https://batch-tester.bespoken.io' | ||
} | ||
/** | ||
* @param {string} key | ||
@@ -110,9 +110,21 @@ * @returns {Promise<string>} | ||
async decrypt (key) { | ||
const url = `${Client.accessURL()}/decrypt?key=${key}` | ||
logger.info('decrypt: ' + url) | ||
const url = `${this.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,4 @@ { | ||
"dependencies": { | ||
"@bespoken-sdk/shared": "^0.13.7", | ||
"@bespoken-sdk/shared": "^0.13.8-alpha.0+461fa06", | ||
"aws-sdk": "^2.718.0", | ||
"axios": "^0.21.4", | ||
@@ -21,4 +22,4 @@ "lodash": "^4.17.21" | ||
}, | ||
"version": "0.13.7", | ||
"gitHead": "a697b922287a6d55e8e94923e072f98fef2806c5", | ||
"version": "0.13.8-alpha.0+461fa06", | ||
"gitHead": "461fa06c84cc35c57a98a111162920815fa9cdce", | ||
"devDependencies": { | ||
@@ -25,0 +26,0 @@ "@types/node": "^16.10.1" |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
15970
12
581
4
5
3
+ Addedaws-sdk@^2.718.0
+ Addedavailable-typed-arrays@1.0.7(transitive)
+ Addedaws-sdk@2.1692.0(transitive)
+ Addedbase64-js@1.5.1(transitive)
+ Addedbuffer@4.9.2(transitive)
+ Addedcall-bind@1.0.7(transitive)
+ Addeddefine-data-property@1.1.4(transitive)
+ Addedes-define-property@1.0.0(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedevents@1.1.1(transitive)
+ Addedfor-each@0.3.3(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-intrinsic@1.2.4(transitive)
+ Addedgopd@1.0.1(transitive)
+ Addedhas-property-descriptors@1.0.2(transitive)
+ Addedhas-proto@1.0.3(transitive)
+ Addedhas-symbols@1.0.3(transitive)
+ Addedhas-tostringtag@1.0.2(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedieee754@1.1.13(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedis-arguments@1.1.1(transitive)
+ Addedis-callable@1.2.7(transitive)
+ Addedis-generator-function@1.0.10(transitive)
+ Addedis-typed-array@1.1.13(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedjmespath@0.16.0(transitive)
+ Addedpossible-typed-array-names@1.0.0(transitive)
+ Addedpunycode@1.3.2(transitive)
+ Addedquerystring@0.2.0(transitive)
+ Addedsax@1.2.1(transitive)
+ Addedset-function-length@1.2.2(transitive)
+ Addedurl@0.10.3(transitive)
+ Addedutil@0.12.5(transitive)
+ Addeduuid@8.0.0(transitive)
+ Addedwhich-typed-array@1.1.15(transitive)
+ Addedxml2js@0.6.2(transitive)
+ Addedxmlbuilder@11.0.1(transitive)