hapi-features

1.0.2 • Public • Published

hapi-features

Build Status Simple feature flags management for hapi.js

Installation

$ npm install hapi-features

Usage

To use this plugin just load it into your hapi.js server. Pass it your feature flags as the options property. It will add the plugins.features property to every request object.

server.register({
    register: index,
    options: {"feature_a":true, "feature_b":false}
}, function(err) {});

To update features while the server is running call the updateFeatures(features) methods

server.methods.updateFeatures({"new_conf": true});

Configuration

Simple true/false

Input:

{
  "feature_a": true,
  "feature_b": false
}

Output:

{
  "feature_a": true,
  "feature_b": false
}

Simple dependencies

Input:

{
  "feature_a": true,
  "feature_b": false,
  "true_dep_a": {
    "active": true,
    "required": [
      "feature_a"
    ]
  },
  "false_dep_a": {
    "active": false,
    "required": [
      "feature_a"
    ]
  },
  "true_dep_b": {
    "active": true,
    "required": [
      "feature_b"
    ]
  },
  "false_dep_b": {
    "active": false,
    "required": [
      "feature_b"
    ]
  },
  "true_dep_ab": {
    "active": true,
    "required": [
      "feature_a",
      "feature_b"
    ]
  },
  "false_dep_ab": {
    "active": false,
    "required": [
      "feature_a",
      "feature_b"
    ]
  }
}

Output:

{
  "feature_a": true,
  "feature_b": false,
  "true_dep_a": true,
  "false_dep_a": false,
  "true_dep_b": false,
  "false_dep_b": false,
  "true_dep_ab": false,
  "false_dep_ab": false
}

Nested dependencies

Input:

{
  "feature_a": true,
  "feature_b": false,
  "true_dep_a": {
    "active": true,
    "required": [
      "feature_a"
    ]
  },
  "true_dep_b": {
    "active": true,
    "required": [
      "feature_b"
    ]
  },
  "a_dep_a": {
    "active": true,
    "required": [
      "feature_a",
      "true_dep_a"
    ]
  },
  "a_dep_b": {
    "active": true,
    "required": [
      "feature_a",
      "true_dep_b"
    ]
  }
}

Output:

{
  "feature_a": true,
  "feature_b": false,
  "true_dep_a": true,
  "true_dep_b": false,
  "a_dep_a": true,
  "a_dep_b": false
}

Readme

Keywords

Package Sidebar

Install

npm i hapi-features

Weekly Downloads

0

Version

1.0.2

License

MIT

Last publish

Collaborators

  • gamingcoder