@ulixee/commons
Advanced tools
Comparing version 0.0.1 to 0.0.2
10
cbor.js
@@ -1,9 +0,7 @@ | ||
const { decodeFirst, encodeCanonical } = require('cbor'); | ||
const { promisify } = require('util'); | ||
const { encodeOne, encodeCanonical, decodeFirst } = require('cbor'); | ||
const decodeFirstAsync = promisify(decodeFirst); | ||
module.exports = { | ||
decode: decodeFirstAsync, | ||
encode: encodeCanonical, | ||
encodeOne, | ||
encodeCanonical, | ||
decodeFirst, | ||
}; |
@@ -26,4 +26,5 @@ class UlixeeError extends Error { | ||
class InvalidSignatureError extends UlixeeError { | ||
constructor(message) { | ||
constructor(message, details = {}) { | ||
super(message, 'invalid::signature'); | ||
this.details = details; | ||
} | ||
@@ -88,2 +89,8 @@ } | ||
class ClientError extends UlixeeError { | ||
constructor(code, message) { | ||
super(message, code); | ||
} | ||
} | ||
module.exports = { | ||
@@ -100,2 +107,3 @@ APIError, | ||
InsufficientResourcesError, | ||
ClientError, | ||
}; |
@@ -8,10 +8,12 @@ const path = require('path'); | ||
const lockfileName = 'ulixee-lock.json'; | ||
const getDefaultLockFilePath = () => path.join(process.cwd(), lockfileName); | ||
const getDefaultLockfilePath = () => path.join(process.cwd(), lockfileName); | ||
class LockFile { | ||
constructor(filePath) { | ||
if (filePath) { | ||
class Lockfile { | ||
constructor(filePath, settings) { | ||
if (filePath === 'virtual') { | ||
this.lockfilePath = null; | ||
} else if (filePath) { | ||
this.lockfilePath = path.join(process.cwd(), filePath, lockfileName); | ||
} else { | ||
this.lockfilePath = getDefaultLockFilePath(); | ||
this.lockfilePath = getDefaultLockfilePath(); | ||
} | ||
@@ -21,11 +23,14 @@ this.datatypes = {}; | ||
this.version = '0.0.1'; | ||
this.settings = { | ||
escrowHost: '', | ||
ledgerHost: '', | ||
stakeHost: '', | ||
bootstrapPeers: [], | ||
decoderDirectory: 'decoder-scripts', | ||
publicNodes: [], | ||
}; | ||
this.load(); | ||
this.settings = Object.assign( | ||
{ | ||
escrowHost: '', | ||
ledgerHost: '', | ||
stakeHost: '', | ||
bootstrapPeers: [], | ||
decoderDirectory: 'decoder-scripts', | ||
publicNodes: [], | ||
}, | ||
settings, | ||
); | ||
if (this.lockfilePath) this.load(); | ||
} | ||
@@ -122,4 +127,13 @@ | ||
} | ||
randomPublicHost() { | ||
const randomIndex = Math.floor(Math.random() * this.settings.publicNodes.length); | ||
const publicHost = this.settings.publicNodes[randomIndex]; | ||
if (!publicHost) { | ||
throw new Error('No public nodes found. Use CLI to refresh the list of addresses.'); | ||
} | ||
return publicHost; | ||
} | ||
} | ||
module.exports = LockFile; | ||
module.exports = Lockfile; |
@@ -17,9 +17,14 @@ const { createLogger, transports, format } = require('winston'); | ||
const logMetaObject = get(info.metadata || {}, 'meta', {}); | ||
const logMeta = `${ | ||
Object.keys(logMetaObject).length ? `, ${JSON.stringify(logMetaObject, replacer, 2)}` : '' | ||
}`; | ||
return `${info.timestamp} ${meta.info.role || ''} [${info.label}] ${info.level}: ${ | ||
info.message | ||
}${logMeta}`; | ||
try { | ||
const logMeta = `${ | ||
Object.keys(logMetaObject).length ? `, ${JSON.stringify(logMetaObject, replacer, 2)}` : '' | ||
}`; | ||
return `${info.timestamp} ${meta.info.role || ''} [${info.label}] ${info.level}: ${ | ||
info.message | ||
}${logMeta}`; | ||
} catch (error) { | ||
console.log(new Error('error in printf:')); | ||
console.log(info); | ||
console.log(error); | ||
} | ||
}); | ||
@@ -26,0 +31,0 @@ |
{ | ||
"name": "@ulixee/commons", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Common utilities including crypto, network, logging, and others", | ||
@@ -17,3 +17,3 @@ "main": "index.js", | ||
}, | ||
"author": "blake", | ||
"author": "The World", | ||
"license": "ISC", | ||
@@ -41,3 +41,3 @@ "bugs": { | ||
"keywords": [], | ||
"gitHead": "a0d220a88e392b3916c87e6ef9c8a875bc5a278f" | ||
"gitHead": "fd922f15a16349e35ae70a7c6abf884d39db3a00" | ||
} |
21069
666