@sourceloop/feature-toggle / Exports / FeatureFlagActionProvider
Class: FeatureFlagActionProvider¶
Implements¶
Provider<FeatureFlagFn>
Table of contents¶
Constructors¶
Properties¶
Methods¶
- _getFeatureList
- _handleCustomFeatureLogic
- _isFeatureAllowed
- _shouldSkipFeatureCheck
- action
- getStrategy
- value
Constructors¶
constructor¶
• new FeatureFlagActionProvider(getMetadata, user?, handlerService?)
Parameters¶
| Name | Type |
|---|---|
getMetadata |
Getter<FeatureFlagMetadata> |
user? |
IAuthUserWithDisabledFeat |
handlerService? |
FeatureHandlerService |
Defined in¶
packages/feature-toggle/src/providers/feature-flag-action.provider.ts:36
Properties¶
filterStrategyMapping¶
• filterStrategyMapping: { filterType: FilterType ; strategy: FilterStrategy }[]
Defined in¶
packages/feature-toggle/src/providers/feature-flag-action.provider.ts:23
getMetadata¶
• Private Readonly getMetadata: Getter<FeatureFlagMetadata>
Defined in¶
packages/feature-toggle/src/providers/feature-flag-action.provider.ts:38
handlerService¶
• Private Optional Readonly handlerService: FeatureHandlerService
Defined in¶
packages/feature-toggle/src/providers/feature-flag-action.provider.ts:42
user¶
• Private Optional Readonly user: IAuthUserWithDisabledFeat
Defined in¶
packages/feature-toggle/src/providers/feature-flag-action.provider.ts:40
Methods¶
_getFeatureList¶
▸ Private _getFeatureList(metadata): string[]
The function _getFeatureList returns an array containing the feature key from the provided
FeatureFlagMetadata object.
Parameters¶
| Name | Type | Description |
|---|---|---|
metadata |
FeatureFlagMetadata |
The metadata parameter is of type FeatureFlagMetadata, which likely contains information about a feature flag such as its key, description, status, and any other relevant data related to feature flags. |
Returns¶
string[]
An array of strings containing the feature key from the provided FeatureFlagMetadata object.
Defined in¶
packages/feature-toggle/src/providers/feature-flag-action.provider.ts:97
_handleCustomFeatureLogic¶
▸ Private _handleCustomFeatureLogic(metadata): boolean | Promise<boolean>
The function _handleCustomFeatureLogic checks for a handler in the metadata options and calls
the handler service if available.
Parameters¶
| Name | Type | Description |
|---|---|---|
metadata |
FeatureFlagMetadata |
The metadata parameter is of type FeatureFlagMetadata and contains information about a specific feature flag, such as its options and configuration. |
Returns¶
boolean | Promise<boolean>
The method _handleCustomFeatureLogic is returning a boolean value or a Promise that
resolves to a boolean value. If the handler is defined in the metadata.options and this.user
is truthy, then it calls the handle method of handlerService with the metadata and
this.user as arguments. If handlerService is not null or
Defined in¶
packages/feature-toggle/src/providers/feature-flag-action.provider.ts:145
_isFeatureAllowed¶
▸ Private _isFeatureAllowed(featureList, disabledFeatures, metadata): boolean
The function _isFeatureAllowed determines if a feature is allowed based on a list of features,
disabled features, and feature flag metadata.
Parameters¶
| Name | Type | Description |
|---|---|---|
featureList |
string[] |
The featureList parameter is an array of strings that contains the list of features that you want to check for permission or enablement. |
disabledFeatures |
string[] |
The disabledFeatures parameter is an array of strings that contains the list of features that are currently disabled or not allowed. |
metadata |
FeatureFlagMetadata |
The metadata parameter in the _isFeatureAllowed function likely contains information related to feature flags, such as the options and operator used for filtering the feature list. It seems to be of type FeatureFlagMetadata. |
Returns¶
boolean
A boolean value is being returned from the _isFeatureAllowed function.
Defined in¶
packages/feature-toggle/src/providers/feature-flag-action.provider.ts:125
_shouldSkipFeatureCheck¶
▸ Private _shouldSkipFeatureCheck(featureList): boolean
The function _shouldSkipFeatureCheck checks if the first element of a feature list is '*' and
returns a boolean value.
Parameters¶
| Name | Type | Description |
|---|---|---|
featureList |
string[] |
FeatureList is an array of strings that contains a list of features. |
Returns¶
boolean
a boolean value, which is determined by whether the length of the featureList array is
greater than 0 and the first element of the array is equal to '*'.
Defined in¶
packages/feature-toggle/src/providers/feature-flag-action.provider.ts:109
action¶
▸ action(): Promise<boolean>
This TypeScript function checks if a user is allowed to access certain features based on feature flags and user settings.
Returns¶
Promise<boolean>
The action function returns a Promise<boolean>. The function first retrieves metadata
using this.getMetadata(), then checks if the metadata and user exist. If either is missing, it
returns true. It then proceeds to get a list of features, check if feature checking should be
skipped, and verify if the user has disabled features. If disabled features are not available, an
`InternalServerError
Defined in¶
packages/feature-toggle/src/providers/feature-flag-action.provider.ts:57
getStrategy¶
▸ getStrategy(operator): FilterStrategy
The getStrategy function returns a filtering strategy based on the specified operator or
defaults to an OR strategy.
Parameters¶
| Name | Type | Description |
|---|---|---|
operator |
undefined | FilterType |
The operator parameter in the getStrategy function is of type FilterType \| undefined. It is used to determine the filtering strategy based on the specified FilterType. If no operator is provided, the function will default to using the OR filter strategy. |
Returns¶
The getStrategy function returns a filtering strategy based on the operator specified
in the decorator. It uses the filterStrategyMapping array to map the FilterType to the
corresponding FilterStrategy. If the specified operator is found in the mapping, the
corresponding strategy is returned. If not found, it defaults to using the OrFilterStrategy.
Defined in¶
packages/feature-toggle/src/providers/feature-flag-action.provider.ts:167
value¶
▸ value(): FeatureFlagFn
Returns¶
Implementation of¶
Provider.value
Defined in¶
packages/feature-toggle/src/providers/feature-flag-action.provider.ts:44