npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@coderofsalvation/jsreactor

v1.1.66

Published

backend-agnostic business rule engine (IFTTT) for javascript

Downloads

9

Readme

WARNING: this project is in BETA

An flexible rule-engine enhanced with jsonschema for quick userinterface-generation (think IFTTT). This is basically a wrapper for json-rules-engine enhanced with jsonschemas for user-interaction.

Current backend-adapters:

Installation

$ npm install @coderofsalvation/jsreactor --save
var BRE = require('jsreactor')

var myBackendAdapter = async (bre) => {
  /* this is optional
   * see [parse-server-jsreactor]() for an adapter-example
   * to persist rules / build schemas from/to a database e.g.
   */
}

var b = BRE(/* myBackendAdapter */ )
var inputChannel = require('@coderofsalvation/jsreactor/channel/Input)
new inputChannel(b)
b.init() // first init
    
b.run({foo:"bar"}) // data will be passed thru the business rules engine
                   // and conditionally triggers actions

jsreactor includes the following basic channels

Installing channels

Search for jsreactor-channel on npm, and then install it (e.g. npm install jsreactor-channel-sendgrid):

// optional: jsreactor's Server-channel is shipped with 
// express-compatible middleware
app.use( require('@coderofsalvation/jsreactor/channel/Server').middleware )

// include
require('glob').sync("node_modules/jsreactor-channel-**/index.js")
.map( (c) => {
    var channel = require( c )
    new channel({bre})
})

Put the above snippet before bre.init() and you're done

DEBUGGING

run DEBUG=json-rules-engine,bre node app.js to see more output

What are Channels?

A channel is basically an object which describes triggers and/or actions. For example, Twilio (the smsservice) can be seen as a channel with triggers (receive sms) and actions (send sms)

Creating a channel

copy channel/HelloWorld/index.js to mychannel.js

then in your cloud-code entrypoint-file (cloud/index.js e.g.) add it:

    // add the business rule engine + channels
    var BRE         = require('parse-server-business-rule-engine')
    var BREDatabase = require('parse-server-business-rule-engine/channel/Database')
++  var MyChannel   = require('./../mychannel`)
    
    // setup BRE
    var bre = new BRE( Parse )
    new BREDatabase({bre, classes:['User','School']})
++  new MyChannel({bre})

Rerouting logging

Many rules can mean many console.log()-calls in the wild. In case you want to reroute logging of rules use initLogger():

bre.initLogger = (f,rule) => (msg,opts) => {
    // f    = old log function (console.log with a bre prefix)
    // rule = current triggered rule
    // msg  = console.log(msg,... ) passed in a javascript action-block
    // opts = console.log(...,opts) second argument passed to console.log
    console.log(msg,{stream:"rule: "+rule.name})
}

Branching out

Triggers who set an input-array on the output, will automatically be processed in batch

input.output.input    = []
input.output.input[0] = {"email":"[email protected]"}
input.output.input[1] = {"email":"[email protected]"}

Environment variables

| name | default | comment | |-|-|-| |JSREACTOR_EDIT_URL | '%id%' | hint edit-links for error-reporting ('http://foo.com/%id%' => 'http://foo.com/l2343kl34'` ) |JSREACTOR_JAVASCRIPT_DOC | https://github.com/coderofsalvation/jsreactor/blob/master/doc/node/javascript.md | displays link to api reference in javascript editor |