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

silo_rules-engine

v4.6.1

Published

Backbone Rules Engine Silo

Downloads

15

Readme

Rules Engine Silo

Introduction

To enable a more flexible configuration of the backend, Use-Case and especially customer-specific logic can be kept outside of standard code by creating rules: event-handlers for specific scenarios.

Getting Started

Authentication

For authentication with gcloud functionality, like google cloud storage for images, please run the following command from your dev machine:

gcloud auth application-default login

And allow it to connect to your sstid.com account.

This will authenticate any app running locally, (e.g. from VSCode) to use your user account to authenticate. To give permissions to a user account go to https://console.cloud.google.com/iam-admin/iam?project=backbone-168621 and add the approrpiate roles.

These are the required roles at this time:

  • File Storage : Storage Object Admin role (or Storage Admin role)

Rules

The Rules Engine uses a case-insensitive folder-structure based organization of rules, which are loaded from the rules folder at startup. Directly in the root of that folder, you can have generic rules, per event, that apply to all use cases, and all customers. The filenames should match the verb, namespace, relation, and optionally status and action value of the events (message queue messages) they handle.

Additionally, the rules folder can contain folders, again preferably with the same naming scheme of the events they apply to. These event folders should contain zero or more files named for the Use-Cases they apply to, or the specific functionality they implement.

e.g.:

  • rules
    • create_security_user_success.js
    • CREATE_SECURITY_USER_SUCCESS
      • rex.js
      • strategicRfid.js
      • rex
        • disney.js
    • CREATE_REX_RMA_SUCCESS
      • rex.js
      • rex
        • autoPlus.js
        • disney.js
      • preventDuplicates.js

The rules engine will automatically build a workflow by comparing the incomming userContext with the rules, and will build a pipeline by expanding the incomming verb as follows:

  • get
    • willGet, get, got (executed synchronously)
    • get_..._..._success (executed asynchronously after completing the above successfully)
  • create
    • willCreate, create, created (executed in order, synchronously)
    • create_..._..._success (executed asynchronously after completing the above successfully)
  • update
    • willUpdate, update, updated (executed in order, synchronously)
    • update_..._..._success (executed asynchronously after completing the above successfully)
  • remove
    • willRemove, remove, removed (executed in order, synchronously)
    • remove_..._..._success (executed asynchronously after completing the above successfully)
  • count
    • willCount, count, counted (executed in order, synchronously)
    • count_..._..._success (executed asynchronously after completing the above successfully)

Create your own Rules

Apart from being organized in the described folder/file structure, rules are expected to have the following effective outline:

/**
 * @typedef Rule
 * @property {string} verb e.g. 'willGet', 'get', 'got', 'willCreate', 'create', 'created', etc
 * @property {string} [namespace] e.g. 'item', applies to all namespaces if not provided
 * @property {string} [relation] e.g. 'type', applies to all relations if not provided
 * @property {Object[]} [excludeNamespaceRelations] if no namespace/relations defined, these relations will be excluded
 * @property {string} excludeNamespaceRelations.namespace
 * @property {string} excludeNamespaceRelations.relation
 * @property {'success'|'fail'} [status]
 * @property {string} [action] e.g. 'heartbeat', 'content', etc
 * @property {number} priority smaller numbers mean lower priority. Rules with higher priority for the same verb get executed first
 * @property {string} description
 * @property {string[]} [useCaseNames] e.g. 'Lot Management' or `REX` or 'FLAIR'
 * @property {string[]} [excludeUseCases] not applicable if useCaseNames are provided
 * @property {string[]} [tenantNames] e.g. `Kefi` or 'Office Depot'
 * @property {string[]} [excludeTenantNames] not applicable if tenantNames are provided
 * @property {function[]} [prerequisites]   See exsting rules for examples
 * @property {function} logic  //the actual logic
  * /

Notes:

  • The response from logic is optional, if no response is returned, the input message is automatically used as result
  • aborting
    • Throwing an error in logic or prerequisite code will abort the entire workflow
    • Returning an object in the form of { abort: { message: 'your reason to abort goes here' } } will end stop a prerequisite sub-workflow, but allows continueing the rest of the workflow.

Build and Test

Unit tests

Unit test files must be named *.unit.js for the testing tool to pick them up. To execute all unit tests, you can run npm run test or npm run test:unit.

Integration tests

Integration test files must be named *.integration.js for the testing tool to pick them up. To execute all integration tests, you can run npm run test:integration

All tests

To execute all tests, run npm run test:all If you'd like to see code coverage reports, pass true after any test command: npm run test:unit true

#Contribute

Git Repository: https://sstdev.visualstudio.com/DefaultCollection/Backbone/_git/silo_rules-engine