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

@sourceloop/feature-toggle

Package Overview
Dependencies
Maintainers
8
Versions
74
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sourceloop/feature-toggle

Package for feature toggle.

latest
Source
npmnpm
Version
6.0.6
Version published
Weekly downloads
1K
-4.19%
Maintainers
8
Weekly downloads
 
Created
Source

@sourceloop/feature-toggle

LoopBack

A simple loopback-next extension for checking the disabled features. Here a new decorator is introduced it has a simplistic approach to check if a particular feature is allowed or not to that user.

Working and Flow

This extension provides a method level decorator @featureFlag that takes the name of the feature that needs to be checked as metadata and verifies if that particular feature is allowed or not. What it expects is that a list of disabled features is saved for the current user of the type IAuthUserWithDisabledFeat and compares that with the one passed in the metadata of the decorator. The metadata also accepts an optional options that has a handler name parameter. If that handler name is provided that using an extendion point HandlerService appropriate handler is called. All the handlers must implement FeatureHandler interface.

Only feature check

 @featureFlag({featureKey: 'feature_key'})

If you want to skip the check:

@featureFlag({featureKey: '*'})

Multiple feature check with operator

@featureFlag({
    featureKey: ['feature_key1', 'feature_key2'],
    options: {
      operator: 'AND' | 'OR'
    },
  })

Feature Check plus handler call

@featureFlag({
    featureKey: 'feature_key',
    options: {
      handler: 'handler_name',
    },
  })

This particular handler_name will be matched with the one in handler

@injectable(asFeatureHandler)
export class MyHandler implements FeatureHandler {
  handlerName = 'handler_name';

  handle(): void {
    // your logic here
  }
}

A good practice is to keep all feature strings in a separate enum file like this.

export enum FEATUREKEY {
  CALENDAR = '1',
  CHAT = '2',
  CONTRACT = '3',
}

Install

npm install @sourceloop/feature-toggle

Basic Use

Setup

In order to use this component into your application follow the easy steps given below.

  • While authentication save the list of disabled features for that particular user. Like this
authUser.disabledFeatures = ['1', '3'];
  • Add the FeatureToggleComponent to your Loopback4 Application (in application.ts) where you need to check the features availability.
// import the FeatureToggleComponent
import {FeatureToggleComponent} from '@sourceloop/feature-toggle';

// add Component for FeatureToggle
this.component(FeatureToggleComponent);
  • Adding handlers to the extension points
this.add(createBindingFromClass(MyHandler));
  • Then add the decorator over all the APIs where feature needs to be checked. As shown above.

Feedback

If you've noticed a bug or have a question or have a feature request, search the issue tracker to see if someone else in the community has already created a ticket. If not, go ahead and make one! All feature requests are welcome. Implementation time may vary. Feel free to contribute the same, if you can. If you think this extension is useful, please star it. Appreciation really helps in keeping this project alive.

Contributing

Please read CONTRIBUTING.md for details on the process for submitting pull requests to us.

Code of conduct

Code of conduct guidelines here.

License

MIT

Keywords

loopback-extension

FAQs

Package last updated on 09 Mar 2026

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