Update enums to be all caps (#12372)

- Make custom domain public (remove from lab)
- Use ALL_CAPS definition for enums
This commit is contained in:
Félix Malfait
2025-05-29 14:08:36 +02:00
committed by GitHub
parent 76d0be7f81
commit 4485e8e3db
165 changed files with 845 additions and 847 deletions
@@ -7,16 +7,13 @@ type FeatureFlagMetadata = {
};
export type PublicFeatureFlag = {
key: Extract<
FeatureFlagKey,
FeatureFlagKey.IsWorkflowEnabled | FeatureFlagKey.IsCustomDomainEnabled
>;
key: Extract<FeatureFlagKey, FeatureFlagKey.IS_WORKFLOW_ENABLED>;
metadata: FeatureFlagMetadata;
};
export const PUBLIC_FEATURE_FLAGS: PublicFeatureFlag[] = [
{
key: FeatureFlagKey.IsWorkflowEnabled,
key: FeatureFlagKey.IS_WORKFLOW_ENABLED,
metadata: {
label: 'Workflows',
description: 'Create custom workflows to automate your work.',
@@ -25,15 +22,9 @@ export const PUBLIC_FEATURE_FLAGS: PublicFeatureFlag[] = [
},
...(process.env.CLOUDFLARE_API_KEY
? [
{
key: FeatureFlagKey.IsCustomDomainEnabled as PublicFeatureFlag['key'],
metadata: {
label: 'Custom Domain',
description: 'Customize your workspace URL with your own domain.',
imagePath:
'https://twenty.com/images/lab/is-custom-domain-enabled.png',
},
},
// {
// Here you can add cloud only feature flags
// },
]
: []),
];
@@ -1,11 +1,10 @@
export enum FeatureFlagKey {
IsAirtableIntegrationEnabled = 'IS_AIRTABLE_INTEGRATION_ENABLED',
IsPostgreSQLIntegrationEnabled = 'IS_POSTGRESQL_INTEGRATION_ENABLED',
IsStripeIntegrationEnabled = 'IS_STRIPE_INTEGRATION_ENABLED',
IsCopilotEnabled = 'IS_COPILOT_ENABLED',
IsWorkflowEnabled = 'IS_WORKFLOW_ENABLED',
IsUniqueIndexesEnabled = 'IS_UNIQUE_INDEXES_ENABLED',
IsJsonFilterEnabled = 'IS_JSON_FILTER_ENABLED',
IsCustomDomainEnabled = 'IS_CUSTOM_DOMAIN_ENABLED',
IsPermissionsV2Enabled = 'IS_PERMISSIONS_V2_ENABLED',
IS_AIRTABLE_INTEGRATION_ENABLED = 'IS_AIRTABLE_INTEGRATION_ENABLED',
IS_POSTGRESQL_INTEGRATION_ENABLED = 'IS_POSTGRESQL_INTEGRATION_ENABLED',
IS_STRIPE_INTEGRATION_ENABLED = 'IS_STRIPE_INTEGRATION_ENABLED',
IS_COPILOT_ENABLED = 'IS_COPILOT_ENABLED',
IS_WORKFLOW_ENABLED = 'IS_WORKFLOW_ENABLED',
IS_UNIQUE_INDEXES_ENABLED = 'IS_UNIQUE_INDEXES_ENABLED',
IS_JSON_FILTER_ENABLED = 'IS_JSON_FILTER_ENABLED',
IS_PERMISSIONS_V2_ENABLED = 'IS_PERMISSIONS_V2_ENABLED',
}
@@ -36,7 +36,7 @@ describe('FeatureFlagService', () => {
};
const workspaceId = 'workspace-id';
const featureFlag = FeatureFlagKey.IsWorkflowEnabled;
const featureFlag = FeatureFlagKey.IS_WORKFLOW_ENABLED;
beforeEach(async () => {
jest.clearAllMocks();
@@ -121,13 +121,13 @@ describe('FeatureFlagService', () => {
// Prepare
mockWorkspaceFeatureFlagsMapCacheService.getWorkspaceFeatureFlagsMap.mockResolvedValue(
{
[FeatureFlagKey.IsWorkflowEnabled]: true,
[FeatureFlagKey.IsCopilotEnabled]: false,
[FeatureFlagKey.IS_WORKFLOW_ENABLED]: true,
[FeatureFlagKey.IS_COPILOT_ENABLED]: false,
},
);
const mockFeatureFlags = [
{ key: FeatureFlagKey.IsWorkflowEnabled, value: true },
{ key: FeatureFlagKey.IsCopilotEnabled, value: false },
{ key: FeatureFlagKey.IS_WORKFLOW_ENABLED, value: true },
{ key: FeatureFlagKey.IS_COPILOT_ENABLED, value: false },
];
// Act
@@ -145,8 +145,8 @@ describe('FeatureFlagService', () => {
it('should return a map of feature flags for a workspace', async () => {
// Prepare
const mockFeatureFlags = [
{ key: FeatureFlagKey.IsWorkflowEnabled, value: true, workspaceId },
{ key: FeatureFlagKey.IsCopilotEnabled, value: false, workspaceId },
{ key: FeatureFlagKey.IS_WORKFLOW_ENABLED, value: true, workspaceId },
{ key: FeatureFlagKey.IS_COPILOT_ENABLED, value: false, workspaceId },
];
mockFeatureFlagRepository.find.mockResolvedValue(mockFeatureFlags);
@@ -156,8 +156,8 @@ describe('FeatureFlagService', () => {
// Assert
expect(result).toEqual({
[FeatureFlagKey.IsWorkflowEnabled]: true,
[FeatureFlagKey.IsCopilotEnabled]: false,
[FeatureFlagKey.IS_WORKFLOW_ENABLED]: true,
[FeatureFlagKey.IS_COPILOT_ENABLED]: false,
});
});
});
@@ -166,8 +166,8 @@ describe('FeatureFlagService', () => {
it('should enable multiple feature flags for a workspace', async () => {
// Prepare
const keys = [
FeatureFlagKey.IsWorkflowEnabled,
FeatureFlagKey.IsCopilotEnabled,
FeatureFlagKey.IS_WORKFLOW_ENABLED,
FeatureFlagKey.IS_COPILOT_ENABLED,
];
mockFeatureFlagRepository.upsert.mockResolvedValue({});
@@ -212,7 +212,6 @@ describe('FeatureFlagService', () => {
// Assert
expect(result).toEqual(mockFeatureFlag);
expect(mockFeatureFlagRepository.save).toHaveBeenCalledWith({
// @ts-expect-error legacy noImplicitAny
key: FeatureFlagKey[featureFlag],
value,
workspaceId,
@@ -99,12 +99,9 @@ export class FeatureFlagService {
),
);
// @ts-expect-error legacy noImplicitAny
const featureFlagKey = FeatureFlagKey[featureFlag];
if (shouldBePublic) {
publicFeatureFlagValidator.assertIsPublicFeatureFlag(
featureFlagKey,
featureFlag,
new FeatureFlagException(
'Invalid feature flag key, flag is not public',
FeatureFlagExceptionCode.INVALID_FEATURE_FLAG_KEY,
@@ -114,7 +111,7 @@ export class FeatureFlagService {
const existingFeatureFlag = await this.featureFlagRepository.findOne({
where: {
key: featureFlagKey,
key: featureFlag,
workspaceId: workspaceId,
},
});
@@ -125,7 +122,7 @@ export class FeatureFlagService {
value,
}
: {
key: featureFlagKey,
key: featureFlag,
value,
workspaceId: workspaceId,
};
@@ -1,12 +1,12 @@
import { CustomException } from 'src/utils/custom-exception';
import { featureFlagValidator } from 'src/engine/core-modules/feature-flag/validates/feature-flag.validate';
import { CustomException } from 'src/utils/custom-exception';
describe('featureFlagValidator', () => {
describe('assertIsFeatureFlagKey', () => {
it('should not throw error if featureFlagKey is valid', () => {
expect(() =>
featureFlagValidator.assertIsFeatureFlagKey(
'IsWorkflowEnabled',
'IS_WORKFLOW_ENABLED',
new CustomException('Error', 'Error'),
),
).not.toThrow();