Skip to content

Commit

Permalink
feat(infra): translation manager feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
p-fernandez committed Oct 2, 2023
1 parent 4991111 commit b4c1c7f
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 2 deletions.
1 change: 1 addition & 0 deletions apps/api/src/.env.development
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ VERCEL_BASE_URL=https://api.vercel.com

FF_IS_TOPIC_NOTIFICATION_ENABLED=true
FF_IS_DISTRIBUTED_LOCK_LOGGING_ENABLED=false
IS_TRANSLATION_MANAGER_ENABLED=false

STORE_NOTIFICATION_CONTENT=

Expand Down
1 change: 1 addition & 0 deletions apps/api/src/.env.production
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ VERCEL_BASE_URL=https://api.vercel.com

FF_IS_TOPIC_NOTIFICATION_ENABLED=true
FF_IS_DISTRIBUTED_LOCK_LOGGING_ENABLED=false
IS_TRANSLATION_MANAGER_ENABLED=false

STORE_NOTIFICATION_CONTENT=

Expand Down
1 change: 1 addition & 0 deletions apps/api/src/.env.test
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ VERCEL_BASE_URL=https://api.vercel.com

FF_IS_TOPIC_NOTIFICATION_ENABLED=true
IS_MULTI_PROVIDER_CONFIGURATION_ENABLED=true
IS_TRANSLATION_MANAGER_ENABLED=false

STORE_NOTIFICATION_CONTENT=true

Expand Down
1 change: 1 addition & 0 deletions apps/api/src/.example.env
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ VERCEL_REDIRECT_URI=http://localhost:4200/auth/login
VERCEL_BASE_URL=https://api.vercel.com

FF_IS_TOPIC_NOTIFICATION_ENABLED=true
IS_TRANSLATION_MANAGER_ENABLED=false

STORE_NOTIFICATION_CONTENT=true

Expand Down
4 changes: 4 additions & 0 deletions apps/web/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,7 @@ export const IS_MULTI_PROVIDER_CONFIGURATION_ENABLED = isCypress
export const IS_MULTI_TENANCY_ENABLED = isCypress
? window._env_.IS_MULTI_TENANCY_ENABLED || process.env.IS_MULTI_TENANCY_ENABLED || 'true'
: window._env_.IS_MULTI_TENANCY_ENABLED || process.env.IS_MULTI_TENANCY_ENABLED || 'false';

export const IS_TRANSLATION_MANAGER_ENABLED = isCypress
? window._env_.IS_TRANSLATION_MANAGER_ENABLED || process.env.IS_TRANSLATION_MANAGER_ENABLED || 'true'
: window._env_.IS_TRANSLATION_MANAGER_ENABLED || process.env.IS_TRANSLATION_MANAGER_ENABLED || 'false';
11 changes: 11 additions & 0 deletions apps/web/src/hooks/useFeatureFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
IS_TEMPLATE_STORE_ENABLED,
IS_MULTI_PROVIDER_CONFIGURATION_ENABLED,
IS_MULTI_TENANCY_ENABLED,
IS_TRANSLATION_MANAGER_ENABLED,
} from '../config';

const prepareBooleanStringFeatureFlag = (value: string | undefined, defaultValue: boolean): boolean => {
Expand Down Expand Up @@ -50,3 +51,13 @@ export const useIsMultiTenancyEnabled = (): boolean => {

return isMultiTenancyEnabled ?? defaultValue;
};

export const useIsTranslationManagerEnabled = (): boolean => {
const value = IS_TRANSLATION_MANAGER_ENABLED;
const fallbackValue = false;
const defaultValue = prepareBooleanStringFeatureFlag(value, fallbackValue);

const isTranslationManagerEnabled = useGetFlagByKey<boolean>(FeatureFlagsKeysEnum.IS_TRANSLATION_MANAGER_ENABLED);

return isTranslationManagerEnabled ?? defaultValue;
};
5 changes: 3 additions & 2 deletions libs/shared/src/types/feature-flags/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
export enum FeatureFlagsKeysEnum {
IS_TEMPLATE_STORE_ENABLED = 'IS_TEMPLATE_STORE_ENABLED',
IS_TOPIC_NOTIFICATION_ENABLED = 'IS_TOPIC_NOTIFICATION_ENABLED',
IS_MULTI_PROVIDER_CONFIGURATION_ENABLED = 'IS_MULTI_PROVIDER_CONFIGURATION_ENABLED',
IS_MULTI_TENANCY_ENABLED = 'IS_MULTI_TENANCY_ENABLED',
IS_TEMPLATE_STORE_ENABLED = 'IS_TEMPLATE_STORE_ENABLED',
IS_TOPIC_NOTIFICATION_ENABLED = 'IS_TOPIC_NOTIFICATION_ENABLED',
IS_TRANSLATION_MANAGER_ENABLED = 'IS_TRANSLATION_MANAGER_ENABLED',
}

export enum SystemCriticalFlagsEnum {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
GetIsMultiProviderConfigurationEnabled,
GetIsTemplateStoreEnabled,
GetIsTopicNotificationEnabled,
GetIsTranslationManagerEnabled,
} from './index';
import { FeatureFlagCommand } from './get-feature-flag.command';
import { FeatureFlagsService } from '../../services';
Expand Down Expand Up @@ -106,6 +107,32 @@ describe('Get Feature Flag', () => {
expect(result).toEqual(false);
});
});

describe('IS_TRANSLATION_MANAGER_ENABLED', () => {
it('should return default hardcoded value when no SDK env is set and no feature flag is set', async () => {
process.env.IS_TRANSLATION_MANAGER_ENABLED = '';

const getIsTranslationManagerEnabled =
new GetIsTranslationManagerEnabled(new FeatureFlagsService());

const result = await getIsTranslationManagerEnabled.execute(
featureFlagCommand
);
expect(result).toEqual(true);
});

it('should return env variable value when no SDK env is set but the feature flag is set', async () => {
process.env.IS_TRANSLATION_MANAGER_ENABLED = 'false';

const getIsTranslationManagerEnabled =
new GetIsTranslationManagerEnabled(new FeatureFlagsService());

const result = await getIsTranslationManagerEnabled.execute(
featureFlagCommand
);
expect(result).toEqual(false);
});
});
});

describe('SDK key environment variable is set', () => {
Expand Down Expand Up @@ -166,6 +193,21 @@ describe('Get Feature Flag', () => {
expect(result).toEqual(true);
});
});

describe('IS_TRANSLATION_MANAGER_ENABLED', () => {
it(`should get the feature flag value stored in Launch Darkly (enabled)
when the SDK key env variable is set regardless of the feature flag set`, async () => {
process.env.IS_TRANSLATION_MANAGER_ENABLED = 'false';

const getIsTranslationManagerEnabled =
new GetIsTranslationManagerEnabled(new FeatureFlagsService());

const result = await getIsTranslationManagerEnabled.execute(
featureFlagCommand
);
expect(result).toEqual(true);
});
});
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Injectable } from '@nestjs/common';
import { FeatureFlagsKeysEnum } from '@novu/shared';

import {
GetFeatureFlagCommand,
FeatureFlagCommand,
} from './get-feature-flag.command';
import { GetFeatureFlag } from './get-feature-flag.use-case';

@Injectable()
export class GetIsTranslationManagerEnabled extends GetFeatureFlag {
async execute(featureFlagCommand: FeatureFlagCommand): Promise<boolean> {
const value = process.env.IS_TRANSLATION_MANAGER_ENABLED;
const fallbackValue = false;
const defaultValue = this.prepareBooleanStringFeatureFlag(
value,
fallbackValue
);
const key = FeatureFlagsKeysEnum.IS_TRANSLATION_MANAGER_ENABLED;

const command = this.buildCommand(key, defaultValue, featureFlagCommand);

return await this.featureFlagsService.getWithContext(command);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export { GetIsInMemoryClusterModeEnabled } from './get-is-in-memory-cluster-mode
export { GetIsMultiProviderConfigurationEnabled } from './get-is-multi-provider-configuration-enabled.use-case';
export { GetIsTemplateStoreEnabled } from './get-is-template-store-enabled.use-case';
export { GetIsTopicNotificationEnabled } from './get-is-topic-notification-enabled.use-case';
export { GetIsTranslationManagerEnabled } from './get-is-translation-manager-enabled.use-case';

0 comments on commit b4c1c7f

Please sign in to comment.