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

flagsup-js

v1.2.3

Published

``` yarn add flagsup-js ``` or ``` npm install flagsup-js ``` ### Integration - Docs: [Integration doc](https://confluence.teko.vn/display/PS/User+guide+for+setting+up+feature+flags) - Init client ``` import FlagSup from 'flagsup-js'; FlagSup.init(

Downloads

720

Readme

Installation

yarn add flagsup-js

or

npm install flagsup-js

Integration

  • Docs: Integration doc
  • Init client
    import FlagSup from 'flagsup-js';
    FlagSup.init({
      target: "https://flagsup.tekoapis.com",
      userId: "5f8e4768e00e4d12ba69ed3e7bf3e893" // optional, use IAM ID // pragma: whitelist secret
    })
  • To get flag status (and experiment info if available) for a specific user using User IAM ID
    • batchEvaluateFlags(<flag_key_list>, [<default_status>, <default_treatment>, <default_exp_id>, <default_branch_id>])
    • evaluateFlag(<flag_key_list>, [<default_status>, <default_treatment>, <default_exp_id>, <default_branch_id>])
  • To get flag status when user is not logged in (note: this will disable canary release, black/white list, experiment)
    • batchGetFlags(<flag_key_list>, [<default_status>])
    • getFlag(<flag_key>, [<default_status>])
  • Integrate with Tracker-js sdk for experiment metrics tracking
    • Use batchEvaluateFlags to fetch all experiment flags
    • Calls track("setLabelProp", FlagSup.getTrackerLabel(), FlagSup.getTrackerContent()) to store experiment branches info

Example

import React, { useEffect } from 'react';
import FlagSup from 'flagsup-js';

const App = () => {

  useEffect(() => {
    // Log user in with IAM
    // ...

    // Initialisation, provide FlagSup SDK with target domain and userId from IAM (if available)
    FlagSup.init({
      target: "https://flagsup.tekoapis.com",
      userId: "5f8e4768e00e4d12ba69ed3e7bf3e893", // optional // pragma: whitelist secret
      useCacheRefresh: true, // optional, whether to use batch to refresh cache
      refreshInterval: refreshInterval, // optional, set refresh interval (secs) for cache
    })
    // Use getFlag() and batchGetFlags() for flows without/before getting user IAM ID

    // Option 1: Get flags with User ID

    // Fetch multiple flag values for the logged in user. Response is cached in memory for subsequent calls. 
    // Refresh every `refreshInterval`
    FlagSup.batchEvaluateFlags(
      ['flag01', 'flag03'], // Flags to evaluate
      false, // Default status
      "default_treatment", // Default treatment, for experiment only
      0, // Default experiment ID, for experiment only
      0, // Default experiment branch ID, for experiment only
    ).then((flags) => {
      console.log(flags)
    });

    // (Optional) Update tracker JS SDK with experiment branch IDs
    track("setLabelProp", FlagSup.getTrackerLabel(), FlagSup.getTrackerContent())

    // Fetch a flag value for the logged in user. Response is cached in memory for subsequent calls.
    // Refresh every `refreshInterval`
    FlagSup.evaluateFlag(
      'flag01', // flag to evaluate
      false, // Default status
      "default_treatment", // Default treatment, for experiment only
      0, // Default experiment ID, for experiment only
      0, // Default experiment branch ID, for experiment only
    ).then((flag) => {
      console.log(flag);
      if (flag.enabled) {
        // Flow when flag is enabled
      }
      else {
        // Flow when flag is disabled
      }
    });

    // Option 2: Get flags without User ID
    // Note: it is recommended to use this ONLY when you don't have user IAM ID

    // Fetch multiple flag values. Response is cached in memory for subsequent calls. Refresh with 
    // To reduce network overhead, call this to fetch all flags when your app initialise
    FlagSup.batchGetFlags(
      ['flag01', 'flag02'], // Flags to evaluate
      false, // Default status
    ).then((flags) => {
      console.log(flags)
    });

    // Fetch a single flag value. Response is cached in memory for subsequent calls.
    FlagSup.getFlag(
      'flag01', // Flags to evaluate
      false, // Default status
    ).then((flag) => {
      console.log(flag);
      if (flag.enabled) {
        // Flow when flag is enabled
      }
      else {
        // Flow when flag is disabled
      }
    });

    // Flags are cached locally. To flush, use FlagSup.flushFlags()
  }, [])

  return (
    <div className="App">
    </div>
  );
}

export default App;