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

@near-wallet/feature-flags

v0.1.0

Published

This package enables the use of feature flags across NEAR Wallet. These feature flags serve as code guards around functionality being implemented, enabling developers to iterate on more complex features while still being able to deploy small changes. Feat

Downloads

42

Readme

NEAR Wallet Feature Flags

This package enables the use of feature flags across NEAR Wallet. These feature flags serve as code guards around functionality being implemented, enabling developers to iterate on more complex features while still being able to deploy small changes. Feature flags are enabled per environment, allowing finer granularity on how the functionality is rolled out.

Getting started

Modifying feature flags requires the use of the flag binary, installed by running:

yarn binstall

This creates the flag binary under /usr/local/bin/flag. Running the binary prompts the user for the intended action, currently one of:

  • Creating a new feature flag and setting the environments in which it should be enabled.
  • Modifying an existing feature flag to be enabled or disabled in the desired environments.
  • Deleting an existing feature flag.

Running the flag binary requires a features/ directory along the current path, the closest of which will be used by the binary. flag is responsible for both generating and modifying the files in this directory, so it is crucial that no changes are made to this directory's contents outside the flag binary once configured.

Using Feature Flags

In order to use this package, a features/ directory must be created at the appropriate level (e.g. the project root) with the following files:

  • environments.json: The valid environments for the application, in the form of "ENV_NAME": "env_value".
  • flags.json: The set of flags enabled per environment. During initial configuration this should be an empty JSON file.
  • features.js: Module responsible for initializing and exporting the feature flags for use in the target project.

The features.js module is responsible for initializing the proxy object via the initFeatureFlags method exported from this package. This method requires three parameters:

  • currentEnvironment: The environment against which flags should be validated. The provided value must be a valid value in environments.json or an exception will be thrown.
  • environments: The set of valid environments, specified in environments.json.
  • flagState: The set of defined feature flags, specified in flags.json.

Once configured, the proxy object returned from initFeatureFlags is used to check the state of a feature by referring to the flag name, e.g. const isFeatureXEnabled = Features.FEATURE_X. The proxy object will throw an exception if the flag does not exist.

Examples

The following outlines initial example templates for the required files mentioned above. This code is required to correctly set up the Features proxy object for use in a project.

features/environments.json

{
  "TESTNET": "testnet",
  "MAINNET": "mainnet"
}

features/flags.json

{}

features/features.js

const { initFeatureFlags } = require('@near-wallet/feature-flags');

const Environments = require('./environments.json');
const Flags = require('./environments.json');

const Features = initFeatureFlags({
    currentEnvironment: process.env.NEAR_WALLET_ENV, // this can be any environment-derived value so long as it matches a value from environments.json
    environments: Environments,
    flagState: Flags,
});

module.exports = {
    Features,
};