lamassu-server/lib/plugin-helper.js
2017-04-15 20:33:54 +03:00

23 lines
542 B
JavaScript

const _ = require('lodash/fp')
module.exports = {
load,
TICKER: 'ticker',
EXCHANGE: 'exchange',
WALLET: 'wallet',
SMS: 'sms',
EMAIL: 'email'
}
function load (type, pluginCode) {
const me = module.exports
if (!_.includes(type, [me.TICKER, me.EXCHANGE, me.WALLET, me.SMS, me.EMAIL])) {
throw new Error(`Unallowed plugin type: ${type}`)
}
if (pluginCode.search(/[a-z0-9\-]/) === -1) {
throw new Error(`Unallowed plugin name: ${pluginCode}`)
}
return require(`./plugins/${type}/${pluginCode}/${pluginCode}`)
}