1.0.2 • Published 10 years ago

hapi-features v1.0.2

Weekly downloads
1
License
MIT
Repository
github
Last release
10 years ago

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
}