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

@ghg/amplifier

v0.42.0

Published

## Installation

Downloads

29

Readme

Greenhouse Amplifier

Installation

$ yarn add @ghg/amplifier

Quick example

import Amplifier, { addPluginToBuilderOptions } from '@ghg/amplifier';

import BeerPlugin from '@fake-organization/beer-amplifier-plugin';

addPluginToBuilderOptions(BeerPlugin);

const amplifier = Amplifier.Builder()
  .setName('Amplifier example');

amplifier.withWeatherVariableTemperature('temperatureNoordBrabant', {
  country: 'nl',
  cities: ['Eindhoven', 'Valkenswaard'],
});

amplifier.withTimeVariableisWeekend('isWeekend');

amplifier.withBeerService('BeerService');

amplifier.withRule('Time for a "biertje"')
  .when('temperatureNoordBrabant >= 25 && isWeekend')
  .do('BeerService.bringMeBeer()');

Internal supported plugins

This module ships with some interal plugins

  • Xandr (Appnexus)
  • DV360
  • Facebook
  • Google Sheet
  • Google Trends
  • LemonPI (Product store)
  • Outmoove
  • Time
  • Weather

External plugins

The amplifier also support externally developed plugins. Plugins published with -amplifier-plugin in the package name will be loaded by the PluginManager. These plugins need to extend the the Plugin module eg.

import { Plugin } from '@ghg/amplifier';

export default class SamplePlugin extends Plugin {
  // required environment variables
  static requiredEnvVariables = ['BAR'];

  // required variables in requirements
  static requiredVariables = ['foo'];

  getName({ name }) {
    return name;
  }

  getFoo() {
    return this.options.foo;
  }

  getBar() {
    return process.env.BAR;
  }
}

Rules Manger

Explanation of the rule manager. An important part of the Amplifier is the rule manager, rules can be included in the amplifier by adding them to the rules property. Rules are object with an condition that need to be met before the consequence will be executed. Both have access to the R API and the execution context

Flow control API (R)

The first argument of both condition and its corresponding consequence is the R Flow Control API. This api controls the flow of the rules.

Below are the functions available via the Flow Control API.

If you look at the below rule example.

  {
    "name": "transaction minimum",
    "priority": 3,
    "on" : true,
    "condition": function(R) {
      R.when(this.transactionTotal < 500);
    },
    "consequence": function(R) {
      this.result = false;
      R.stop();
    }
  }

R.when

This function is used to pass the condition expression that we want to evaluate. In the above expression we pass the expression to check whether the transactionTotal attribute of the fact in context is below 500 or not. If the expression passed to R.when evaluates to true, then the condition will execute. Else the rule engine will move to next rule or may terminate if there are no rules left to apply.

R.next

This function is used inside consequence functions. This is used to instruct the rule engine to start applying the next rule on the fact if any.

R.stop

This function is used inside consequence functions to instruct the Rule Engine to stop processing the fact. If this function is called, even if rules are left to be applied, the rule engine will not apply rest of rules on the fact. It is used mostly when we arrive a conclusion on a particular fact and there is no need of any further process on it to generate a result.

As you can see above example, when the transaction is less than 500, we no longer need to process the rule. So stores false in result attribute and calls the stop immediately inside consequence.

R.restart

This function is used inside consequence functions to instruct the rule engine to begin applying the Rules on the fact from first. This function is also internally used by the Rule engine when the fact object is modified by a consequence function and it needs to go through all the rules once again. Using the ignoreFactChanges: true option when initializing a new rule engine will turn off this functionality.

Execution context

argument of both condition and its corresponding consequence is the execution context and will include the resolved variables and services. Note: consequence are async condition are not.