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:
@ -61,13 +61,13 @@ describe('ClientConfigService', () => {
|
||||
IS_MULTIWORKSPACE_ENABLED: true,
|
||||
IS_EMAIL_VERIFICATION_REQUIRED: true,
|
||||
DEFAULT_SUBDOMAIN: 'app',
|
||||
NODE_ENV: NodeEnvironment.development,
|
||||
SUPPORT_DRIVER: SupportDriver.Front,
|
||||
NODE_ENV: NodeEnvironment.DEVELOPMENT,
|
||||
SUPPORT_DRIVER: SupportDriver.FRONT,
|
||||
SUPPORT_FRONT_CHAT_ID: 'chat-123',
|
||||
SENTRY_ENVIRONMENT: 'development',
|
||||
APP_VERSION: '1.0.0',
|
||||
SENTRY_FRONT_DSN: 'https://sentry.example.com',
|
||||
CAPTCHA_DRIVER: CaptchaDriverType.GoogleRecaptcha,
|
||||
CAPTCHA_DRIVER: CaptchaDriverType.GOOGLE_RECAPTCHA,
|
||||
CAPTCHA_SITE_KEY: 'site-key-123',
|
||||
CHROME_EXTENSION_ID: 'extension-123',
|
||||
MUTATION_MAXIMUM_AFFECTED_RECORDS: 1000,
|
||||
@ -120,7 +120,7 @@ describe('ClientConfigService', () => {
|
||||
frontDomain: 'app.twenty.com',
|
||||
debugMode: true,
|
||||
support: {
|
||||
supportDriver: 'Front',
|
||||
supportDriver: 'FRONT',
|
||||
supportFrontChatId: 'chat-123',
|
||||
},
|
||||
sentry: {
|
||||
@ -129,7 +129,7 @@ describe('ClientConfigService', () => {
|
||||
dsn: 'https://sentry.example.com',
|
||||
},
|
||||
captcha: {
|
||||
provider: 'GoogleRecaptcha',
|
||||
provider: 'GOOGLE_RECAPTCHA',
|
||||
siteKey: 'site-key-123',
|
||||
},
|
||||
chromeExtensionId: 'extension-123',
|
||||
@ -152,7 +152,7 @@ describe('ClientConfigService', () => {
|
||||
jest
|
||||
.spyOn(twentyConfigService, 'get')
|
||||
.mockImplementation((key: string) => {
|
||||
if (key === 'NODE_ENV') return NodeEnvironment.production;
|
||||
if (key === 'NODE_ENV') return NodeEnvironment.PRODUCTION;
|
||||
if (key === 'IS_BILLING_ENABLED') return false;
|
||||
|
||||
return undefined;
|
||||
@ -191,14 +191,14 @@ describe('ClientConfigService', () => {
|
||||
|
||||
const result = await service.getClientConfig();
|
||||
|
||||
expect(result.support.supportDriver).toBe(SupportDriver.None);
|
||||
expect(result.support.supportDriver).toBe(SupportDriver.NONE);
|
||||
});
|
||||
|
||||
it('should handle billing enabled with feature flags', async () => {
|
||||
jest
|
||||
.spyOn(twentyConfigService, 'get')
|
||||
.mockImplementation((key: string) => {
|
||||
if (key === 'NODE_ENV') return NodeEnvironment.production;
|
||||
if (key === 'NODE_ENV') return NodeEnvironment.PRODUCTION;
|
||||
if (key === 'IS_BILLING_ENABLED') return true;
|
||||
|
||||
return undefined;
|
||||
@ -209,44 +209,4 @@ describe('ClientConfigService', () => {
|
||||
expect(result.canManageFeatureFlags).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('transformEnum', () => {
|
||||
it('should transform enum by direct key match', () => {
|
||||
const result = (service as any).transformEnum(
|
||||
'GoogleRecaptcha',
|
||||
CaptchaDriverType,
|
||||
);
|
||||
|
||||
expect(result).toBe(CaptchaDriverType.GoogleRecaptcha);
|
||||
});
|
||||
|
||||
it('should transform enum by value match', () => {
|
||||
const result = (service as any).transformEnum(
|
||||
'google-recaptcha',
|
||||
CaptchaDriverType,
|
||||
);
|
||||
|
||||
expect(result).toBe('GoogleRecaptcha');
|
||||
});
|
||||
|
||||
it('should transform SupportDriver enum correctly', () => {
|
||||
const result = (service as any).transformEnum('front', SupportDriver);
|
||||
|
||||
expect(result).toBe('Front');
|
||||
});
|
||||
|
||||
it('should throw error for unknown enum value', () => {
|
||||
expect(() => {
|
||||
(service as any).transformEnum('unknown-value', CaptchaDriverType);
|
||||
}).toThrow(
|
||||
'Unknown enum value: unknown-value. Available keys: GoogleRecaptcha, Turnstile. Available values: google-recaptcha, turnstile',
|
||||
);
|
||||
});
|
||||
|
||||
it('should handle direct key match for SupportDriver', () => {
|
||||
const result = (service as any).transformEnum('Front', SupportDriver);
|
||||
|
||||
expect(result).toBe(SupportDriver.Front);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -3,7 +3,6 @@ import { Injectable } from '@nestjs/common';
|
||||
import { NodeEnvironment } from 'src/engine/core-modules/twenty-config/interfaces/node-environment.interface';
|
||||
import { SupportDriver } from 'src/engine/core-modules/twenty-config/interfaces/support.interface';
|
||||
|
||||
import { CaptchaDriverType } from 'src/engine/core-modules/captcha/interfaces';
|
||||
import { ClientConfig } from 'src/engine/core-modules/client-config/client-config.entity';
|
||||
import { DomainManagerService } from 'src/engine/core-modules/domain-manager/services/domain-manager.service';
|
||||
import { PUBLIC_FEATURE_FLAGS } from 'src/engine/core-modules/feature-flag/constants/public-feature-flag.const';
|
||||
@ -57,11 +56,9 @@ export class ClientConfigService {
|
||||
frontDomain: this.domainManagerService.getFrontUrl().hostname,
|
||||
debugMode:
|
||||
this.twentyConfigService.get('NODE_ENV') ===
|
||||
NodeEnvironment.development,
|
||||
NodeEnvironment.DEVELOPMENT,
|
||||
support: {
|
||||
supportDriver: supportDriver
|
||||
? this.transformEnum(supportDriver, SupportDriver)
|
||||
: SupportDriver.None,
|
||||
supportDriver: supportDriver ? supportDriver : SupportDriver.NONE,
|
||||
supportFrontChatId: this.twentyConfigService.get(
|
||||
'SUPPORT_FRONT_CHAT_ID',
|
||||
),
|
||||
@ -72,9 +69,7 @@ export class ClientConfigService {
|
||||
dsn: this.twentyConfigService.get('SENTRY_FRONT_DSN'),
|
||||
},
|
||||
captcha: {
|
||||
provider: captchaProvider
|
||||
? this.transformEnum(captchaProvider, CaptchaDriverType)
|
||||
: undefined,
|
||||
provider: captchaProvider ? captchaProvider : undefined,
|
||||
siteKey: this.twentyConfigService.get('CAPTCHA_SITE_KEY'),
|
||||
},
|
||||
chromeExtensionId: this.twentyConfigService.get('CHROME_EXTENSION_ID'),
|
||||
@ -89,7 +84,7 @@ export class ClientConfigService {
|
||||
analyticsEnabled: this.twentyConfigService.get('ANALYTICS_ENABLED'),
|
||||
canManageFeatureFlags:
|
||||
this.twentyConfigService.get('NODE_ENV') ===
|
||||
NodeEnvironment.development ||
|
||||
NodeEnvironment.DEVELOPMENT ||
|
||||
this.twentyConfigService.get('IS_BILLING_ENABLED'),
|
||||
publicFeatureFlags: PUBLIC_FEATURE_FLAGS,
|
||||
isMicrosoftMessagingEnabled: this.twentyConfigService.get(
|
||||
@ -111,34 +106,4 @@ export class ClientConfigService {
|
||||
|
||||
return clientConfig;
|
||||
}
|
||||
|
||||
// GraphQL enum values are in PascalCase, but the config values are in kebab-case
|
||||
// This function transforms the config values, the same way GraphQL does
|
||||
private transformEnum<T extends Record<string, string>>(
|
||||
value: string,
|
||||
enumObject: T,
|
||||
): T[keyof T] {
|
||||
const directMatch = Object.keys(enumObject).find(
|
||||
(key) => key === value,
|
||||
) as keyof T;
|
||||
|
||||
if (directMatch) {
|
||||
return enumObject[directMatch];
|
||||
}
|
||||
|
||||
const valueMatch = Object.entries(enumObject).find(
|
||||
([, enumValue]) => enumValue === value,
|
||||
);
|
||||
|
||||
if (valueMatch) {
|
||||
return valueMatch[0] as T[keyof T];
|
||||
}
|
||||
|
||||
const availableKeys = Object.keys(enumObject);
|
||||
const availableValues = Object.values(enumObject);
|
||||
|
||||
throw new Error(
|
||||
`Unknown enum value: ${value}. Available keys: ${availableKeys.join(', ')}. Available values: ${availableValues.join(', ')}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user