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

flagger-on

v0.11.0

Published

Enable / disable feature flags globally and / or rollout to a percentage of customers.

Downloads

2

Readme

🦩 flagger-on

Enable / disable feature flags globally and / or rollout to a percentage of customers.

Install

npm install flagger-on

Prerequisites

Requires DynamoDB (additional DB support coming...)

Usage

const f = new Flaggeron({
  namespace: "my_namepace",
  dynamodb: {
    apiVersion: "2012-08-10",
    region: "<your-region>",
  },
});

or with DAX

const f = new Flaggeron({
  namespace: 'my_namepace',
  dynamodb: {
    apiVersion: "2012-08-10",
    service = new AmazonDaxClient({
        endpoint: dax.endpoint,
        region: '<your-region>',
      });
  },
});

Setup DynamoDB

aws dynamodb create-table --table-name FeatureFlag \
  --key-schema AttributeName=pk,KeyType=HASH AttributeName=sk,KeyType=RANGE \
  --attribute-definitions AttributeName=pk,AttributeType=S AttributeName=sk,AttributeType=S \
  --billing-mod PAY_PER_REQUEST

See DynamoDB Setup for additional setup options .

API

getFlags(featureIdPrefix?: string)

Retrieves the set of flags in this namespace that match the feature prefix. If no prefix is specified all flags in this namespace are returned.

// Retrievs flags that match the feature prefix
// if the following features exist, my.feature.1, my.feature.2, all will be returned
f.getFlags('my.feature);

getFlagsForSubject(subjectId: string, featureIdPrefix?: string)

Retrieves the set of flags in this namespace for the given subject e.g. customer that match the feature prefix. If no prefix is specified all flags in this namespace are returned.

Flags are enabled per subject as defined by the rollout configuration. See createFlag and replaceFlag

// Retrievs flags for subject user-12345 that match the feature prefix
f.getFlagsForSubject("user-12345", "my.feature");

enable

Enables a feature flag

f.enableFlag((id: "my.feature.1"));

disable

Disables a feature flag

f.disableFlag("my.feature.1");

create

Creates a feature flag

config.rollout.percentage applies only to per subject rolouts e.g. customer (see getFlagForSubject)

f.createFlag({
  id: "my.feature.1",
  config: {
    rollout: {
      percentage: 100, // rollout to 100 percent of the subject population
    },
  },
  data: {
    // custom properties
    myProp: "my value",
  },
  enabled: true,
});

replace

Reaplce a feature flag

config.rollout.percentage applies only to per subject rolouts e.g. customer

f.replaceFlag({
  id: "my.feature.1",
  config: {
    rollout: {
      percentage: 80, // rollout to 80 percent of the subject population
    },
  },
  enabled: true,
});

delete

Deletes a feature flag

f.deleteFlag("my.feature.1");

DynamoDB setup

Create a DynamoDB Table with name FeatureFlag, partition key pk, and sort key sk

Setup via CLI

NOTE: consider provisioned capacity, rather than PAY_PER_REQUEST to keep costs low

aws dynamodb create-table --table-name FeatureFlag \
  --key-schema AttributeName=pk,KeyType=HASH AttributeName=sk,KeyType=RANGE \
  --attribute-definitions AttributeName=pk,AttributeType=S AttributeName=sk,AttributeType=S \
  --billing-mod PAY_PER_REQUEST

Setup via CDK

const table = new dynamodb.Table(this, "Table", {
      partitionKey: { name: 'pk', type: dynamodb.AttributeType.STRING },
      sortKey: { name: 'sk', type: dynamodb.AttributeType.STRING },
      tableName: 'FeatureFlag',
      billingMode: dynamodb.BillingMode.PAY_PER_REQUEST,
});

Dax Setup

Setup via CDK

const daxSecurityGroup = new ec2.SecurityGroup(this, "DaxSecurityGroup", {
  vpc: props.vpc,
  allowAllOutbound: true,
  securityGroupName: "dax-security-group",
});

daxSecurityGroup.connections.allowFromAnyIpv4(
  new ec2.Port({
    protocol: ec2.Protocol.TCP,
    fromPort: 8111,
    toPort: 8111,
    stringRepresentation: "DaxPort",
  })
);

const subnetGroup = new dax.CfnSubnetGroup(this, "DaxSubnetGroup", {
  subnetIds: props.vpc.privateSubnets.map((s) => s.subnetId),
  subnetGroupName: "my-dax-subnet-group",
});

const daxRole = new iam.Role(this, "DaxRole", {
  assumedBy: new iam.ServicePrincipal("dax.amazonaws.com"),
});
daxRole.addToPrincipalPolicy(
  new iam.PolicyStatement({
    effect: iam.Effect.ALLOW,
    actions: [
      "dynamodb:DescribeTable",
      "dynamodb:PutItem",
      "dynamodb:GetItem",
      "dynamodb:UpdateItem",
      "dynamodb:DeleteItem",
      "dynamodb:Query",
      "dynamodb:Scan",
      "dynamodb:BatchGetItem",
      "dynamodb:BatchWriteItem",
      "dynamodb:ConditionCheckItem",
    ],
    resources: [this.table.tableArn],
  })
);

new dax.CfnCluster(this, "DaxCluster", {
  iamRoleArn: daxRole.roleArn,
  clusterName: "my-dax-cluster",
  availabilityZones: props.vpc.availabilityZones,
  nodeType: "dax.t3.small",
  replicationFactor: props.vpc.availabilityZones.length,
  securityGroupIds: [daxSecurityGroup.securityGroupId],
  subnetGroupName: subnetGroup.subnetGroupName,
  sseSpecification: {
    sseEnabled: true,
  },
});

License

MIT