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

wyseman

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wyseman - npm Package Compare versions

Comparing version 1.0.10 to 1.0.11

29

lib/dbclient.js

@@ -15,2 +15,3 @@ //Low level connection to PostgreSQL database

const Format = require('pg-format') //String formatting/escaping
const RetryTimeout = 3000 //How long to wait for connection retry
var initialize = true //Next user should try to init DB if necessary

@@ -30,9 +31,9 @@

this.connecting = false
//this.log.debug('AAA', conf.listen, typeof(conf.listen))
if (conf.listen && !Array.isArray(conf.listen)) conf.listen = [conf.listen]
if (conf.listen) this.connect(() => { //Connect now so we can listen
if (conf.listen || conf.connect) this.connect(() => { //Connect now so we can listen
let q; while (q = this.queryQue.shift()) this.query(...q) //And process the queue
if (this.connectCB) this.connectCB()
})
this.log.trace("New database client:", conf.database)
this.log.trace("New database client:", conf)
}

@@ -48,7 +49,6 @@

// -----------------------------------------------------------------------------
newClient(discon = true) { //Get a fresh client for this connection
if (discon) this.disconnect()
newClient() { //Get a fresh client for this connection
this.client = new Client(this.config)
this.log.trace("New DB client config:", this.config)
if (this.config.listen) {
if (this.config.listen && this.queryQue.length <= 0) {
this.config.listen.forEach(listen=>{

@@ -59,3 +59,3 @@ this.log.debug("Listening on DB channel:", listen);

if (this.notifyCB) this.client.on('notification', msg => { //Handle callbacks: 3rd parameter tells if this notify was a result of one of my own queries (as opposed to someone else)
// this.log.trace("DB notification:", msg);
// this.log.trace("DBclient notification:", msg);
if (this.client) this.notifyCB(msg.channel, msg.payload, msg.processId == this.client.processID)

@@ -70,3 +70,3 @@ })

if (!this.client) this.newClient(false)
if (!this.client) this.newClient()

@@ -76,6 +76,13 @@ this.connecting = true

if (!err) {cb(); this.connecting = false; return} //Success
this.log.debug("DB connection error:", err.message);
this.log.debug("DB connection error:", err.message)
let dbname = this.client.connectionParameters.database //DB we tried to connect to
this.disconnect()
if (!this.config.schema && !this.config.retry) { //Let's retry in a couple seconds
this.config.retry = true
this.log.debug("Retrying:", this.config)
setTimeout(()=>{this.connect(cb)}, RetryTimeout)
return
}
if (!/database .* does not exist/.test(err.message)) {fatal(err.message); return} //Abort on anything other than DB does not exist error

@@ -119,3 +126,3 @@ if (!this.config.schema) {fatal('No schema found'); return} //No schema found to create

query(...args) { // Attempt a DB query. If not yet connected, queue the request and attempt to connect
this.log.trace("Query:", args[0], args[1])
this.log.trace("Query:", args[0].substr(0,256), args[1])
if (this.client && this.client._connected) { //If connection ready, run the query

@@ -122,0 +129,0 @@ this.client.query(...args)

@@ -76,9 +76,10 @@ //Manage the connection between a User Interface and the backend database

verifyClient: function(info, cb) {
log.debug("verifyClient:", info)
let { origin, req, secure } = info
, query = Url.parse(req.url, true).query
, { user, db, sign, date, token, pub } = query
, dbListen = db ? JSON.parse(Buffer(db,'hex').toString()) : null
log.debug("Checking client:", origin, "cb:", !!cb, "q:", query, "s:", secure, "IP:", req.connection.remoteAddress, "db:", dbListen)
, listen = db ? JSON.parse(Buffer.from(db,'hex').toString()) : null
log.debug("Checking client:", origin, "cb:", !!cb, "q:", query, "s:", secure, "IP:", req.connection.remoteAddress, "listen:", listen, typeof(listen))
if (user && token && pub)
validateToken(user, token, pub, dbListen, (valid)=>{
validateToken(user, token, pub, listen, (valid)=>{
cb(valid, 403, 'Invalid Login') //Tell websocket whether or not to connect

@@ -93,6 +94,7 @@ })

cb(false, 400, 'Invalid Date Stamp')
else validateSignature(user, sign, message, dbListen, (valid)=>{
else validateSignature(user, sign, message, listen, (valid)=>{
cb(valid, 403, 'Invalid Login') //Tell websocket whether or not to connect
})
} else if (user && !secure) {
Object.assign(dbConf, {user,listen}) //Tell later db connect our username and db listen options
cb(true) //On an insecure/debug web connection

@@ -103,7 +105,8 @@ } else

})
server.listen(port)
log.debug("Wyseman listening:", port)
if (port) server.listen(port)
wss.on('connection', (ws) => { //When connection from view is open
wss.on('connection', (ws) => { //When connection from view client is open
log.debug("WS Connected; User:", dbConf.user, dbConf)
if (!dbConf.user) return //Shouldn't be able to get here without a username
log.debug("DB Connect::", dbConf.user, dbConf)
ctx.db = new DbClient(dbConf, (channel, message, mine) => {

@@ -110,0 +113,0 @@ let data = JSON.parse(message)

{
"name": "wyseman",
"version": "1.0.10",
"version": "1.0.11",
"description": "PostgreSQL Schema Manager with Javascript, Ruby, TCL API",

@@ -31,10 +31,9 @@ "main": "lib/index.js",

"base64-js": "^1.3.0",
"pg": "^7.5.0",
"pg": "^7.9.0",
"pg-format": "^1.0.4",
"ws": "^6.1.2"
"ws": "^6.2.1"
},
"devDependencies": {
"mocha": "^5.2.0",
"wyselib": "^1.0.0"
"mocha": "^5.2.0"
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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