Socket
Socket
Sign inDemoInstall

@bespoken-sdk/store

Package Overview
Dependencies
49
Maintainers
2
Versions
37
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.13.7 to 0.13.8-alpha.0

index.js

70

lib/client.js
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"

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc