New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

cloud-feature-toggles

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cloud-feature-toggles

Cloud based feature toggles

latest
Source
npmnpm
Version
1.1.0
Version published
Maintainers
1
Created
Source

cloud-feature-toggles

Simple implementation of feature toggles that are powered by cloud services.

Features

This module encapsulates all calls to check if a certain feature toggle is enabled. Furthermore, developers can choose a specific cloud service that hosts the feature toggles. Currently the following cloud services are supported:

  • AWS
    • S3
    • DynamoDB
  • Azure

Options

Object to be passed into module instantiation:

  • aws - contains all configurations of cloud services under AWS
    • region - AWS region (e.g. ap-southeast-1)
    • s3 - use this if you want to use AWS S3 to host your feature toggles
      • bucket - name of S3 bucket that hosts your feature toggles
    • dynamoDB - use this if you want to use AWS DynamoDB to host your feature toggles
      • tableName - name of DynamoDB table that hosts your feature toggles

Feature toggle representation

JSON format that represents the feature toggle:

{
  "id": "MY_FEATURE_TOGGLE"
  "isEnabled": true
}

Note: For AWS S3 the attribute id is optional as the name of the file would be the name of the feature toggle i.e. MY_FEATURE_TOGGLE

Usage (AWS S3)

// instantiate module with options object
const cloudFeatureToggles = require('cloud-feature-toggles')({
  aws: {
    region: '<REGION>', // e.g. ap-southeast-1
    s3: {
      bucket: '<FEATURE_TOGGLES_BUCKET>'  // e.g. my-feature-toggles
    }
  }
});

Usage (AWS DynamoDB)

// instantiate module with options object
const cloudFeatureToggles = require('cloud-feature-toggles')({
  aws: {
    region: '<REGION>', // e.g. ap-southeast-1
    dynamoDB: {
      tableName: '<FEATURE_TOGGLES_TABLE_NAME>'  // e.g. my-feature-toggles
    }
  }
});

isEnabled(featureToggle)

Note: featureToggle is case sensitive

const main = async() => {
  // use isEnabled method to check if MY_FEATURE_TOGGLE is enabled
  // note the await keyword
  if (await cloudFeatureToggles.isEnabled('MY_FEATURE_TOGGLE')) {
    // continue with MY_FEATURE flow
  } else {
    // continue with normal flow
  }
}

main();

Notes

  • This module primarily uses aws-sdk to connect to S3
  • Hence, if this is used in AWS environment (i.e. Lambda or EC2), do make sure that an IAM role with the appropriate policies is attached (i.e. S3 read access)
  • If your application is in a non-AWS environment (e.g. Azure), it might be better to utilise Azure Blob Storage to host your feature toggles
    • Support for this feature will be COMING SOON

Keywords

cloud

FAQs

Package last updated on 24 Mar 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts