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

automait

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

automait - npm Package Compare versions

Comparing version 1.2.1 to 1.3.0

3

lib/automait.js

@@ -17,4 +17,3 @@ module.exports = Automait

var loadTriggers = createTriggerLoader(this.plugins, this.logger)
loadTriggers(this.config.triggers)
createTriggerLoader(this.plugins, this.logger)()

@@ -21,0 +20,0 @@ Object.keys(this.plugins).forEach(function (name) {

module.exports = createTriggerLoader
var async = require('async')
, glob = require('glob')
function createTriggerLoader(plugins, logger) {
function loadTriggers(triggers) {
triggers = triggers.filter(function (trigger) {
return trigger.active && trigger.when && trigger.then
function loadTriggers() {
var triggers = []
, triggerDir = __dirname + '/../../../triggers/**/*.json'
glob(triggerDir, function (error, paths) {
paths.forEach(function (path) {
var triggerData = null
try {
triggerData = require(path)
} catch (e) {
throw new Error('Invalid trigger file at: ' + path)
}
if (!Array.isArray(triggerData)) {
triggerData = [ triggerData ]
}
triggers = triggers.concat(triggerData)
})
triggers = triggers.filter(function (trigger) {
return trigger.active && trigger.when && trigger.then
})
triggers.forEach(loadSingleTrigger)
})
triggers.forEach(loadSingleTrigger)
}

@@ -56,20 +74,30 @@

if (!conditions) return callback(true)
async.every(conditions
, function (cond, evCb) {
var plugin = plugins[cond.plugin]
, args = cond.action.input.slice(0)
async.every(conditions, checkCondition, callback)
}
function checkResult(error, result) {
if (error) {
logger.error('Error checking condition:', cond.plugin, cond.action)
return logger.error(error)
}
evCb(cond.action.equal === result)
}
function checkCondition(cond, evCb) {
// handle OR conditions
if (Array.isArray(cond)) {
return async.some(cond, checkCondition, evCb)
}
var plugin = plugins[cond.plugin]
, args = cond.action.input.slice(0)
args.push(checkResult)
plugin[cond.action.name].apply(plugin, args)
function checkResult(error, result) {
if (error) {
logger.error('Error checking condition:', cond.plugin, cond.action)
return logger.error(error)
}
, callback
)
var possibleValues = cond.action.equal
if (!Array.isArray(possibleValues)) {
possibleValues = [ possibleValues ]
}
evCb(possibleValues.indexOf(result) > -1)
}
args.push(checkResult)
if (!plugin[cond.action.name]) {
throw new Error('Plugin "' + cond.plugin + '" does not have an action called "' + cond.action.name + '"')
}
plugin[cond.action.name].apply(plugin, args)
}

@@ -76,0 +104,0 @@

{
"name": "automait",
"version": "1.2.1",
"version": "1.3.0",
"main": "index.js",

@@ -8,4 +8,5 @@ "license": "ISC",

"async": "^1.5.0",
"bunyan": "^1.5.1"
"bunyan": "^1.5.1",
"glob": "^7.1.2"
}
}
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