@sourceloop/feature-toggle / Exports
@sourceloop/feature-toggle¶
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
If you want to skip the check:
Multiple feature check with operator
Feature Check plus handler call
This particular handler_name will be matched with the one in handler
A good practice is to keep all feature strings in a separate enum file like this.
Install¶
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
- Add the
FeatureToggleComponent
to your Loopback4 Application (inapplication.ts
) where you need to check the features availability.
- Adding handlers to the extension points
- 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.