Socket
Socket
Sign inDemoInstall

@karhoo/lib-feature-flags

Package Overview
Dependencies
1
Maintainers
5
Versions
127
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @karhoo/lib-feature-flags

Feature flags 🚩 library for Karhoo web apps. It provides possibility to enable/disable certain feature per environment without redeployment πŸ™ƒ


Version published
Weekly downloads
96
increased by2300%
Maintainers
5
Created
Weekly downloads
Β 

Readme

Source
Karhoo logo

Karhoo Lib Feature Flags

This library was created in order to have a possibility to enable/disable certain feature per environment without redeployment.

License

Installation

npm i @karhoo/lib-feature-flags

Warnings

This library uses Promise, async/await and other modern JS features so currently it works only in modern browsers by default. For old browsers you must run babel on it.

Usage

In order to get Feature flags config you need to make request for remoteConfig:

import { FeatureFlags, RemoteConfig } from '@karhoo/lib-feature-flags'
import { getApi } from '@karhoo/demand-api'

const defaultOptions = { defaultValueForMissingKeys: false }

let flagsInstance

const initFlagsInstance = config => {
  const api = getApi({
  url: 'api',
  defaultRequestOptionsGetter: () => ({
    headers: {
      identifier: 'XXXX',
      referrer: 'https://example-referer.com/',
    },
  }),
})

  const { session, flags } = config
  const organisationId = 'organisationId'
  const remoteConfigFetcher = () =>
    api.flagsService.getLatestVersion({ organisationId, platform: 'web' }).then(data => {
      return data.body?flags || {}
    })

  flagsInstance = new FeatureFlags(new RemoteConfig(remoteConfigFetcher), flags || defaultOptions)
}

const getFlagsInstance = () => {
  return flagsInstance
}

After creating getFlagsInstances funtion you can use it, for example:

 if (someCondition && getFlagsInstance().isEnabled(MY_FEATURE))) {
   // do thomething...
 }

FeatureFlags

It takes config and has such functionality as enable/disable feature and isEnabled method that returns boolean for feature flag that is passed to it. By default it returns false if key is missing. This behavior can be changed by passing options to it.

FeatureProvider

FeatureProvider is a provider of FeatureFlags. Use it in your App component so that every component can use this functionality.

Feature component could be used for every feature that you want to have a possibility to enable/disable. Example of usage:

<Feature name="pageLogo"> <PageLogo /> </Feature>

ObjectConfig

It can be used if you want to use simple object as a config for feature toggling. It takes config and environment so different configs could be used per different environments.

Issues

Looking to contribute?

πŸ› Bugs

Please file an issue for bugs, missing documentation, or unexpected behavior with a label FEATURE_FLAGS

πŸ’‘ Feature Requests

Please file an issue to suggest new features with a label FEATURE_FLAGS. Vote on feature requests by adding a πŸ‘. This helps maintainers prioritize what to work on.

❓ Questions

For questions related to using the library, please re-visit a documentation first. If there are no answer, please create an issue with a label help needed and FEATURE_FLAGS.

Contributing

License

BSD-2-Clause

Keywords

FAQs

Last updated on 18 Jan 2024

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚑️ by Socket Inc