Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@bespoken-sdk/store

Package Overview
Dependencies
Maintainers
2
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bespoken-sdk/store - npm Package Compare versions

Comparing version 0.13.8-alpha.0 to 0.13.8-alpha.1

70

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

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc