@bespoken-sdk/store
Advanced tools
Comparing version 0.13.8-alpha.0 to 0.13.8-alpha.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 | ||
const Store = require('./store') | ||
const zlib = require('zlib') | ||
@@ -11,11 +10,18 @@ | ||
*/ | ||
class Client extends Store { | ||
class Client { | ||
/** | ||
* @returns {string} | ||
*/ | ||
static accessURL () { | ||
return process.env.STORE_URL ? process.env.STORE_URL : 'https://store.bespoken.io/store' | ||
} | ||
/** | ||
* @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}`) | ||
@@ -39,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 | ||
@@ -47,3 +53,3 @@ } | ||
streamResponse.data.on('end', () => { | ||
console.timeEnd('BESPOKEN-STORE FETCH') | ||
logger.timeEnd('FETCH') | ||
const jobJSON = JSON.parse(buffer.toString('utf-8')) | ||
@@ -61,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 | ||
@@ -72,11 +78,13 @@ } | ||
/** | ||
* @param {any} job | ||
* @param {string} key | ||
* @param {any} json | ||
* @returns {Promise<string>} The UUID assigned to the job | ||
*/ | ||
async save (job) { | ||
console.time('BESPOKEN-STORE SAVE') | ||
const url = `${this.accessURL()}/save?run=${job.run}` | ||
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) | ||
// Create a stream from the JSON | ||
const jsonStream = Readable.from(JSON.stringify(job)) | ||
const jsonStream = Readable.from(jsonString) | ||
const gzipStream = jsonStream.pipe(zlib.createGzip()) | ||
@@ -91,4 +99,3 @@ const response = await axios.post(url, gzipStream, { | ||
console.timeEnd('BESPOKEN-STORE SAVE') | ||
job.key = response.data.key | ||
logger.timeEnd('SAVE') | ||
return response.data.key | ||
@@ -98,9 +105,2 @@ } | ||
/** | ||
* @returns {string} | ||
*/ | ||
accessURL () { | ||
return process.env.STORE_URL ? process.env.STORE_URL : 'https://batch-tester.bespoken.io' | ||
} | ||
/** | ||
* @param {string} key | ||
@@ -110,21 +110,9 @@ * @returns {Promise<string>} | ||
async decrypt (key) { | ||
const url = `${this.accessURL()}/decrypt?key=${key}` | ||
const url = `${Client.accessURL()}/decrypt?key=${key}` | ||
logger.info('decrypt: ' + url) | ||
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,4 +9,3 @@ { | ||
"dependencies": { | ||
"@bespoken-sdk/shared": "^0.13.8-alpha.0+461fa06", | ||
"aws-sdk": "^2.718.0", | ||
"@bespoken-sdk/shared": "^0.13.8-alpha.1", | ||
"axios": "^0.21.4", | ||
@@ -22,4 +21,4 @@ "lodash": "^4.17.21" | ||
}, | ||
"version": "0.13.8-alpha.0+461fa06", | ||
"gitHead": "461fa06c84cc35c57a98a111162920815fa9cdce", | ||
"version": "0.13.8-alpha.1", | ||
"gitHead": "24252805557fa4f6ea8d969cbd32c957e261e856", | ||
"devDependencies": { | ||
@@ -26,0 +25,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
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
3
3
1
4479
5
134
- Removedaws-sdk@^2.718.0
- Removedavailable-typed-arrays@1.0.7(transitive)
- Removedaws-sdk@2.1692.0(transitive)
- Removedbase64-js@1.5.1(transitive)
- Removedbuffer@4.9.2(transitive)
- Removedcall-bind@1.0.7(transitive)
- Removeddefine-data-property@1.1.4(transitive)
- Removedes-define-property@1.0.0(transitive)
- Removedes-errors@1.3.0(transitive)
- Removedevents@1.1.1(transitive)
- Removedfor-each@0.3.3(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedget-intrinsic@1.2.4(transitive)
- Removedgopd@1.0.1(transitive)
- Removedhas-property-descriptors@1.0.2(transitive)
- Removedhas-proto@1.0.3(transitive)
- Removedhas-symbols@1.0.3(transitive)
- Removedhas-tostringtag@1.0.2(transitive)
- Removedhasown@2.0.2(transitive)
- Removedieee754@1.1.13(transitive)
- Removedinherits@2.0.4(transitive)
- Removedis-arguments@1.1.1(transitive)
- Removedis-callable@1.2.7(transitive)
- Removedis-generator-function@1.0.10(transitive)
- Removedis-typed-array@1.1.13(transitive)
- Removedisarray@1.0.0(transitive)
- Removedjmespath@0.16.0(transitive)
- Removedpossible-typed-array-names@1.0.0(transitive)
- Removedpunycode@1.3.2(transitive)
- Removedquerystring@0.2.0(transitive)
- Removedsax@1.2.1(transitive)
- Removedset-function-length@1.2.2(transitive)
- Removedurl@0.10.3(transitive)
- Removedutil@0.12.5(transitive)
- Removeduuid@8.0.0(transitive)
- Removedwhich-typed-array@1.1.15(transitive)
- Removedxml2js@0.6.2(transitive)
- Removedxmlbuilder@11.0.1(transitive)