# Usage of ows-features

ows-features is mainly used in OA, Workstation, Vector API, front-end repositories and micro-services. ows-feature when defined can be user-specific or vendor-specific. It is recommended that whenever a new feature is added it should have enabled value as 0 and control as 1.

ows-feature with only global on/off is defined as follows:

```text
- name: {feature name}
  variants:
    enabled: 0
    control: 1
```

ows-feature can be forcefully enabled for vendor\_id\(s\)/user\_id\(s\) in following manner. ows-feature specifying vendor\_id/user\_id is defined as follows:

```text
- name: {feature name}
  variants:
    enabled: 0
    control: 1
  force:
    enabled:
      user_ids:
        - oa:{user_id}
        - alw:{user_id}
      vendor_ids:
        - {vendor id}
```

## Usage of ows-feature in PHP codebase

### Steps to use an ows-feature in OA/Workstation:

1. Include the namespace

   ```text
    use Orchard\OwsClient\Service\Features;
   ```

2. Initiate Features class as below:

   ```text
    $featuresService = new Features(
        {aws configuration array which includes key, secret, region},
        {Sender name for calling the microservice (Oa|Alw)},
        {Environment (APPLICATION_ENV)},
        {Using SSL true|false}
    );
   ```

   For example:

   ```text
    $awsConfigs = Yaml::parse(APPLICATION_PATH . '/configs/aws.yml');
    $featuresService = new Features(
        $awsConfigs['global_params'],
        'Alw',
        APPLICATION_ENV,
        false
    );
   ```

   Reference Link: [Click Here](https://github.com/theorchard/orchard/blob/master/application/modules/alw/controllers/LoginController.php#L38)

3. Check whether feature is enabled or not for particular user.

   ```text
    $featuresService->isFeatureVariantActive({feature name}, {variant enabled|control});
   ```

   For example:

   ```text
    $testFeatureEnabled = $featuresService->isFeatureVariantActive(
        'testFeature',
        'enabled'
    );
   ```

   isFeatureVariantActive\(\) method returns boolean value i.e. whether the given variant is active or not. There are some other methods exists in php-owsclient that checks wheather feature variant is active for orchard user context / vendor context.

## Usage of ows-feature in Vector API

### Steps to use an ows-feature:

1. Include the namespace

   ```text
    use Orchard\OwsClient\Service\Features;
   ```

2. Initiate Features class as below:

   ```text
    $featuresService = new Features(
        {aws configuration array which includes key, secret, region},
        {Sender name for calling the microservice (Oa|Alw)},
        {Environment (APPLICATION_ENV)},
        {Using SSL true|false}
    );
   ```

3. Check whether feature is enabled or not for particular user.

   ```text
    $featuresService->isOrchardUserFeatureVariantActive({feature name}, {variant enabled|control}, {user id override used for features (`oa:<id>`)});
   ```

   isOrchardUserFeatureVariantActive\(\) method returns boolean value i.e. whether the given variant is active or not. This method internally checks whether the feature flag is enabled or not for particular user. User id i.e. 'orchard-user-id' is already set in Zend registry.

## Usage of ows-feature in ows-metadata

### Steps to use an ows-feature:

1. Check whether feature is enabled or not.

   ```text
    $this->serviceHandle->getFeatureFlagState({feature name});
   ```

   getFeatureFlagState\(\) method returns enabled or control as per status of feature flag.

## Usage of ows-feature in front-end repositories

### Steps to use an ows-feature:

1. Add constant in constants.js file.

   ```text
    export const USER_FEATURES = {
        {constant name}: {feature name}
    };
   ```

2. Add a method in user-features.js file to get feature's status as:

   ```text
    export const {name of function} = () =>
        isActiveFeatureVariant({feature name defined in constants.js}, {variant constant as defined in constants.js VARIANT_ENABLED | VARIANT_CONTROL});
   ```

   Above method returns boolean value i.e. whether the given variant is active or not.

