rename core-module environment to twenty-config (#11445)
closes https://github.com/twentyhq/core-team-issues/issues/759
This commit is contained in:
@ -8,7 +8,6 @@ import { HEALTH_INDICATORS } from 'src/engine/core-modules/admin-panel/constants
|
||||
import { SystemHealth } from 'src/engine/core-modules/admin-panel/dtos/system-health.dto';
|
||||
import { AdminPanelHealthServiceStatus } from 'src/engine/core-modules/admin-panel/enums/admin-panel-health-service-status.enum';
|
||||
import { QueueMetricsTimeRange } from 'src/engine/core-modules/admin-panel/enums/queue-metrics-time-range.enum';
|
||||
import { EnvironmentService } from 'src/engine/core-modules/environment/environment.service';
|
||||
import { HEALTH_ERROR_MESSAGES } from 'src/engine/core-modules/health/constants/health-error-messages.constants';
|
||||
import { HealthIndicatorId } from 'src/engine/core-modules/health/enums/health-indicator-id.enum';
|
||||
import { AppHealthIndicator } from 'src/engine/core-modules/health/indicators/app.health';
|
||||
@ -18,6 +17,7 @@ import { RedisHealthIndicator } from 'src/engine/core-modules/health/indicators/
|
||||
import { WorkerHealthIndicator } from 'src/engine/core-modules/health/indicators/worker.health';
|
||||
import { MessageQueue } from 'src/engine/core-modules/message-queue/message-queue.constants';
|
||||
import { RedisClientService } from 'src/engine/core-modules/redis-client/redis-client.service';
|
||||
import { TwentyConfigService } from 'src/engine/core-modules/twenty-config/twenty-config.service';
|
||||
|
||||
jest.mock('bullmq');
|
||||
|
||||
@ -29,7 +29,7 @@ describe('AdminPanelHealthService', () => {
|
||||
let connectedAccountHealth: jest.Mocked<ConnectedAccountHealth>;
|
||||
let appHealth: jest.Mocked<AppHealthIndicator>;
|
||||
let redisClient: jest.Mocked<RedisClientService>;
|
||||
let environmentService: jest.Mocked<EnvironmentService>;
|
||||
let twentyConfigService: jest.Mocked<TwentyConfigService>;
|
||||
let loggerSpy: jest.SpyInstance;
|
||||
|
||||
beforeEach(async () => {
|
||||
@ -41,7 +41,7 @@ describe('AdminPanelHealthService', () => {
|
||||
redisClient = {
|
||||
getClient: jest.fn().mockReturnValue({} as Redis),
|
||||
} as any;
|
||||
environmentService = { get: jest.fn() } as any;
|
||||
twentyConfigService = { get: jest.fn() } as any;
|
||||
|
||||
(Queue as unknown as jest.Mock) = jest.fn().mockImplementation(() => ({
|
||||
getMetrics: jest.fn(),
|
||||
@ -58,7 +58,7 @@ describe('AdminPanelHealthService', () => {
|
||||
{ provide: ConnectedAccountHealth, useValue: connectedAccountHealth },
|
||||
{ provide: AppHealthIndicator, useValue: appHealth },
|
||||
{ provide: RedisClientService, useValue: redisClient },
|
||||
{ provide: EnvironmentService, useValue: environmentService },
|
||||
{ provide: TwentyConfigService, useValue: twentyConfigService },
|
||||
],
|
||||
}).compile();
|
||||
|
||||
|
||||
@ -10,17 +10,17 @@ import {
|
||||
} from 'src/engine/core-modules/auth/auth.exception';
|
||||
import { LoginTokenService } from 'src/engine/core-modules/auth/token/services/login-token.service';
|
||||
import { DomainManagerService } from 'src/engine/core-modules/domain-manager/services/domain-manager.service';
|
||||
import { EnvironmentService } from 'src/engine/core-modules/environment/environment.service';
|
||||
import { TwentyConfigService } from 'src/engine/core-modules/twenty-config/twenty-config.service';
|
||||
import { User } from 'src/engine/core-modules/user/user.entity';
|
||||
|
||||
const UserFindOneMock = jest.fn();
|
||||
const LoginTokenServiceGenerateLoginTokenMock = jest.fn();
|
||||
const EnvironmentServiceGetAllMock = jest.fn();
|
||||
const TwentyConfigServiceGetAllMock = jest.fn();
|
||||
|
||||
jest.mock(
|
||||
'../../environment/constants/environment-variables-group-metadata',
|
||||
'src/engine/core-modules/twenty-config/constants/config-variables-group-metadata',
|
||||
() => ({
|
||||
ENVIRONMENT_VARIABLES_GROUP_METADATA: {
|
||||
CONFIG_VARIABLES_GROUP_METADATA: {
|
||||
SERVER_CONFIG: {
|
||||
position: 100,
|
||||
description: 'Server config description',
|
||||
@ -69,9 +69,9 @@ describe('AdminPanelService', () => {
|
||||
},
|
||||
},
|
||||
{
|
||||
provide: EnvironmentService,
|
||||
provide: TwentyConfigService,
|
||||
useValue: {
|
||||
getAll: EnvironmentServiceGetAllMock,
|
||||
getAll: TwentyConfigServiceGetAllMock,
|
||||
},
|
||||
},
|
||||
],
|
||||
@ -157,9 +157,9 @@ describe('AdminPanelService', () => {
|
||||
expect(UserFindOneMock).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
describe('getEnvironmentVariablesGrouped', () => {
|
||||
it('should correctly group and sort environment variables', () => {
|
||||
EnvironmentServiceGetAllMock.mockReturnValue({
|
||||
describe('getConfigVariablesGrouped', () => {
|
||||
it('should correctly group and sort config variables', () => {
|
||||
TwentyConfigServiceGetAllMock.mockReturnValue({
|
||||
SERVER_URL: {
|
||||
value: 'http://localhost',
|
||||
metadata: {
|
||||
@ -179,7 +179,7 @@ describe('AdminPanelService', () => {
|
||||
metadata: {
|
||||
group: 'SERVER_CONFIG',
|
||||
description: 'API Key',
|
||||
sensitive: true,
|
||||
isSensitive: true,
|
||||
},
|
||||
},
|
||||
OTHER_VAR: {
|
||||
@ -191,7 +191,7 @@ describe('AdminPanelService', () => {
|
||||
},
|
||||
});
|
||||
|
||||
const result = service.getEnvironmentVariablesGrouped();
|
||||
const result = service.getConfigVariablesGrouped();
|
||||
|
||||
expect(result).toEqual({
|
||||
groups: [
|
||||
@ -204,13 +204,13 @@ describe('AdminPanelService', () => {
|
||||
name: 'API_KEY',
|
||||
value: 'secret-key',
|
||||
description: 'API Key',
|
||||
sensitive: true,
|
||||
isSensitive: true,
|
||||
},
|
||||
{
|
||||
name: 'SERVER_URL',
|
||||
value: 'http://localhost',
|
||||
description: 'Server URL',
|
||||
sensitive: false,
|
||||
isSensitive: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
@ -223,7 +223,7 @@ describe('AdminPanelService', () => {
|
||||
name: 'RATE_LIMIT_TTL',
|
||||
value: '60',
|
||||
description: 'Rate limit TTL',
|
||||
sensitive: false,
|
||||
isSensitive: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
@ -236,7 +236,7 @@ describe('AdminPanelService', () => {
|
||||
name: 'OTHER_VAR',
|
||||
value: 'other',
|
||||
description: 'Other var',
|
||||
sensitive: false,
|
||||
isSensitive: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
@ -248,10 +248,10 @@ describe('AdminPanelService', () => {
|
||||
expect(result.groups[2].name).toBe('OTHER');
|
||||
});
|
||||
|
||||
it('should handle empty environment variables', () => {
|
||||
EnvironmentServiceGetAllMock.mockReturnValue({});
|
||||
it('should handle empty config variables', () => {
|
||||
TwentyConfigServiceGetAllMock.mockReturnValue({});
|
||||
|
||||
const result = service.getEnvironmentVariablesGrouped();
|
||||
const result = service.getConfigVariablesGrouped();
|
||||
|
||||
expect(result).toEqual({
|
||||
groups: [],
|
||||
@ -259,7 +259,7 @@ describe('AdminPanelService', () => {
|
||||
});
|
||||
|
||||
it('should handle variables with undefined metadata fields', () => {
|
||||
EnvironmentServiceGetAllMock.mockReturnValue({
|
||||
TwentyConfigServiceGetAllMock.mockReturnValue({
|
||||
TEST_VAR: {
|
||||
value: 'test',
|
||||
metadata: {
|
||||
@ -268,13 +268,13 @@ describe('AdminPanelService', () => {
|
||||
},
|
||||
});
|
||||
|
||||
const result = service.getEnvironmentVariablesGrouped();
|
||||
const result = service.getConfigVariablesGrouped();
|
||||
|
||||
expect(result.groups[0].variables[0]).toEqual({
|
||||
name: 'TEST_VAR',
|
||||
value: 'test',
|
||||
description: undefined,
|
||||
sensitive: false,
|
||||
isSensitive: false,
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -287,7 +287,7 @@ describe('AdminPanelService', () => {
|
||||
mockEnvironmentGet.mockReset();
|
||||
mockAxiosGet.mockReset();
|
||||
jest.spyOn(axios, 'get').mockImplementation(mockAxiosGet);
|
||||
service['environmentService'].get = mockEnvironmentGet;
|
||||
service['twentyConfigService'].get = mockEnvironmentGet;
|
||||
});
|
||||
|
||||
it('should return current and latest version when everything works', async () => {
|
||||
|
||||
@ -3,7 +3,7 @@ import { Args, Mutation, Query, Resolver } from '@nestjs/graphql';
|
||||
|
||||
import { AdminPanelHealthService } from 'src/engine/core-modules/admin-panel/admin-panel-health.service';
|
||||
import { AdminPanelService } from 'src/engine/core-modules/admin-panel/admin-panel.service';
|
||||
import { EnvironmentVariablesOutput } from 'src/engine/core-modules/admin-panel/dtos/environment-variables.output';
|
||||
import { ConfigVariablesOutput } from 'src/engine/core-modules/admin-panel/dtos/config-variables.output';
|
||||
import { ImpersonateInput } from 'src/engine/core-modules/admin-panel/dtos/impersonate.input';
|
||||
import { ImpersonateOutput } from 'src/engine/core-modules/admin-panel/dtos/impersonate.output';
|
||||
import { SystemHealth } from 'src/engine/core-modules/admin-panel/dtos/system-health.dto';
|
||||
@ -17,7 +17,6 @@ import { FeatureFlagException } from 'src/engine/core-modules/feature-flag/featu
|
||||
import { FeatureFlagService } from 'src/engine/core-modules/feature-flag/services/feature-flag.service';
|
||||
import { UserInputError } from 'src/engine/core-modules/graphql/utils/graphql-errors.util';
|
||||
import { HealthIndicatorId } from 'src/engine/core-modules/health/enums/health-indicator-id.enum';
|
||||
import { WorkerHealthIndicator } from 'src/engine/core-modules/health/indicators/worker.health';
|
||||
import { MessageQueue } from 'src/engine/core-modules/message-queue/message-queue.constants';
|
||||
import { AdminPanelGuard } from 'src/engine/guards/admin-panel-guard';
|
||||
import { ImpersonateGuard } from 'src/engine/guards/impersonate-guard';
|
||||
@ -33,7 +32,6 @@ export class AdminPanelResolver {
|
||||
constructor(
|
||||
private adminService: AdminPanelService,
|
||||
private adminPanelHealthService: AdminPanelHealthService,
|
||||
private workerHealthIndicator: WorkerHealthIndicator,
|
||||
private featureFlagService: FeatureFlagService,
|
||||
) {}
|
||||
|
||||
@ -76,9 +74,9 @@ export class AdminPanelResolver {
|
||||
}
|
||||
|
||||
@UseGuards(WorkspaceAuthGuard, UserAuthGuard, AdminPanelGuard)
|
||||
@Query(() => EnvironmentVariablesOutput)
|
||||
async getEnvironmentVariablesGrouped(): Promise<EnvironmentVariablesOutput> {
|
||||
return this.adminService.getEnvironmentVariablesGrouped();
|
||||
@Query(() => ConfigVariablesOutput)
|
||||
async getConfigVariablesGrouped(): Promise<ConfigVariablesOutput> {
|
||||
return this.adminService.getConfigVariablesGrouped();
|
||||
}
|
||||
|
||||
@UseGuards(WorkspaceAuthGuard, UserAuthGuard, AdminPanelGuard)
|
||||
|
||||
@ -5,9 +5,9 @@ import axios from 'axios';
|
||||
import semver from 'semver';
|
||||
import { Repository } from 'typeorm';
|
||||
|
||||
import { EnvironmentVariable } from 'src/engine/core-modules/admin-panel/dtos/environment-variable.dto';
|
||||
import { EnvironmentVariablesGroupData } from 'src/engine/core-modules/admin-panel/dtos/environment-variables-group.dto';
|
||||
import { EnvironmentVariablesOutput } from 'src/engine/core-modules/admin-panel/dtos/environment-variables.output';
|
||||
import { ConfigVariable } from 'src/engine/core-modules/admin-panel/dtos/config-variable.dto';
|
||||
import { ConfigVariablesGroupData } from 'src/engine/core-modules/admin-panel/dtos/config-variables-group.dto';
|
||||
import { ConfigVariablesOutput } from 'src/engine/core-modules/admin-panel/dtos/config-variables.output';
|
||||
import { UserLookup } from 'src/engine/core-modules/admin-panel/dtos/user-lookup.entity';
|
||||
import { VersionInfo } from 'src/engine/core-modules/admin-panel/dtos/version-info.dto';
|
||||
import {
|
||||
@ -16,11 +16,11 @@ import {
|
||||
} from 'src/engine/core-modules/auth/auth.exception';
|
||||
import { LoginTokenService } from 'src/engine/core-modules/auth/token/services/login-token.service';
|
||||
import { DomainManagerService } from 'src/engine/core-modules/domain-manager/services/domain-manager.service';
|
||||
import { ENVIRONMENT_VARIABLES_GROUP_METADATA } from 'src/engine/core-modules/environment/constants/environment-variables-group-metadata';
|
||||
import { EnvironmentVariablesGroup } from 'src/engine/core-modules/environment/enums/environment-variables-group.enum';
|
||||
import { EnvironmentService } from 'src/engine/core-modules/environment/environment.service';
|
||||
import { FeatureFlagKey } from 'src/engine/core-modules/feature-flag/enums/feature-flag-key.enum';
|
||||
import { FeatureFlag } from 'src/engine/core-modules/feature-flag/feature-flag.entity';
|
||||
import { CONFIG_VARIABLES_GROUP_METADATA } from 'src/engine/core-modules/twenty-config/constants/config-variables-group-metadata';
|
||||
import { ConfigVariablesGroup } from 'src/engine/core-modules/twenty-config/enums/config-variables-group.enum';
|
||||
import { TwentyConfigService } from 'src/engine/core-modules/twenty-config/twenty-config.service';
|
||||
import { User } from 'src/engine/core-modules/user/user.entity';
|
||||
import { userValidator } from 'src/engine/core-modules/user/user.validate';
|
||||
|
||||
@ -28,7 +28,7 @@ import { userValidator } from 'src/engine/core-modules/user/user.validate';
|
||||
export class AdminPanelService {
|
||||
constructor(
|
||||
private readonly loginTokenService: LoginTokenService,
|
||||
private readonly environmentService: EnvironmentService,
|
||||
private readonly twentyConfigService: TwentyConfigService,
|
||||
private readonly domainManagerService: DomainManagerService,
|
||||
@InjectRepository(User, 'core')
|
||||
private readonly userRepository: Repository<User>,
|
||||
@ -123,21 +123,18 @@ export class AdminPanelService {
|
||||
};
|
||||
}
|
||||
|
||||
getEnvironmentVariablesGrouped(): EnvironmentVariablesOutput {
|
||||
const rawEnvVars = this.environmentService.getAll();
|
||||
const groupedData = new Map<
|
||||
EnvironmentVariablesGroup,
|
||||
EnvironmentVariable[]
|
||||
>();
|
||||
getConfigVariablesGrouped(): ConfigVariablesOutput {
|
||||
const rawEnvVars = this.twentyConfigService.getAll();
|
||||
const groupedData = new Map<ConfigVariablesGroup, ConfigVariable[]>();
|
||||
|
||||
for (const [varName, { value, metadata }] of Object.entries(rawEnvVars)) {
|
||||
const { group, description } = metadata;
|
||||
|
||||
const envVar: EnvironmentVariable = {
|
||||
const envVar: ConfigVariable = {
|
||||
name: varName,
|
||||
description,
|
||||
value: String(value),
|
||||
sensitive: metadata.sensitive ?? false,
|
||||
isSensitive: metadata.isSensitive ?? false,
|
||||
};
|
||||
|
||||
if (!groupedData.has(group)) {
|
||||
@ -147,20 +144,17 @@ export class AdminPanelService {
|
||||
groupedData.get(group)?.push(envVar);
|
||||
}
|
||||
|
||||
const groups: EnvironmentVariablesGroupData[] = Array.from(
|
||||
groupedData.entries(),
|
||||
)
|
||||
const groups: ConfigVariablesGroupData[] = Array.from(groupedData.entries())
|
||||
.sort((a, b) => {
|
||||
const positionA = ENVIRONMENT_VARIABLES_GROUP_METADATA[a[0]].position;
|
||||
const positionB = ENVIRONMENT_VARIABLES_GROUP_METADATA[b[0]].position;
|
||||
const positionA = CONFIG_VARIABLES_GROUP_METADATA[a[0]].position;
|
||||
const positionB = CONFIG_VARIABLES_GROUP_METADATA[b[0]].position;
|
||||
|
||||
return positionA - positionB;
|
||||
})
|
||||
.map(([name, variables]) => ({
|
||||
name,
|
||||
description: ENVIRONMENT_VARIABLES_GROUP_METADATA[name].description,
|
||||
isHiddenOnLoad:
|
||||
ENVIRONMENT_VARIABLES_GROUP_METADATA[name].isHiddenOnLoad,
|
||||
description: CONFIG_VARIABLES_GROUP_METADATA[name].description,
|
||||
isHiddenOnLoad: CONFIG_VARIABLES_GROUP_METADATA[name].isHiddenOnLoad,
|
||||
variables: variables.sort((a, b) => a.name.localeCompare(b.name)),
|
||||
}));
|
||||
|
||||
@ -168,7 +162,7 @@ export class AdminPanelService {
|
||||
}
|
||||
|
||||
async getVersionInfo(): Promise<VersionInfo> {
|
||||
const currentVersion = this.environmentService.get('APP_VERSION');
|
||||
const currentVersion = this.twentyConfigService.get('APP_VERSION');
|
||||
|
||||
try {
|
||||
const response = await axios.get(
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { Field, ObjectType } from '@nestjs/graphql';
|
||||
|
||||
@ObjectType()
|
||||
export class EnvironmentVariable {
|
||||
export class ConfigVariable {
|
||||
@Field()
|
||||
name: string;
|
||||
|
||||
@ -12,5 +12,5 @@ export class EnvironmentVariable {
|
||||
value: string;
|
||||
|
||||
@Field()
|
||||
sensitive: boolean;
|
||||
isSensitive: boolean;
|
||||
}
|
||||
@ -0,0 +1,23 @@
|
||||
import { Field, ObjectType, registerEnumType } from '@nestjs/graphql';
|
||||
|
||||
import { ConfigVariable } from 'src/engine/core-modules/admin-panel/dtos/config-variable.dto';
|
||||
import { ConfigVariablesGroup } from 'src/engine/core-modules/twenty-config/enums/config-variables-group.enum';
|
||||
|
||||
registerEnumType(ConfigVariablesGroup, {
|
||||
name: 'ConfigVariablesGroup',
|
||||
});
|
||||
|
||||
@ObjectType()
|
||||
export class ConfigVariablesGroupData {
|
||||
@Field(() => [ConfigVariable])
|
||||
variables: ConfigVariable[];
|
||||
|
||||
@Field(() => ConfigVariablesGroup)
|
||||
name: ConfigVariablesGroup;
|
||||
|
||||
@Field(() => String, { defaultValue: '' })
|
||||
description: string;
|
||||
|
||||
@Field(() => Boolean, { defaultValue: false })
|
||||
isHiddenOnLoad: boolean;
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
import { Field, ObjectType } from '@nestjs/graphql';
|
||||
|
||||
import { ConfigVariablesGroupData } from 'src/engine/core-modules/admin-panel/dtos/config-variables-group.dto';
|
||||
|
||||
@ObjectType()
|
||||
export class ConfigVariablesOutput {
|
||||
@Field(() => [ConfigVariablesGroupData])
|
||||
groups: ConfigVariablesGroupData[];
|
||||
}
|
||||
@ -1,24 +0,0 @@
|
||||
import { Field, ObjectType, registerEnumType } from '@nestjs/graphql';
|
||||
|
||||
import { EnvironmentVariablesGroup } from 'src/engine/core-modules/environment/enums/environment-variables-group.enum';
|
||||
|
||||
import { EnvironmentVariable } from './environment-variable.dto';
|
||||
|
||||
registerEnumType(EnvironmentVariablesGroup, {
|
||||
name: 'EnvironmentVariablesGroup',
|
||||
});
|
||||
|
||||
@ObjectType()
|
||||
export class EnvironmentVariablesGroupData {
|
||||
@Field(() => [EnvironmentVariable])
|
||||
variables: EnvironmentVariable[];
|
||||
|
||||
@Field(() => EnvironmentVariablesGroup)
|
||||
name: EnvironmentVariablesGroup;
|
||||
|
||||
@Field(() => String, { defaultValue: '' })
|
||||
description: string;
|
||||
|
||||
@Field(() => Boolean, { defaultValue: false })
|
||||
isHiddenOnLoad: boolean;
|
||||
}
|
||||
@ -1,9 +0,0 @@
|
||||
import { Field, ObjectType } from '@nestjs/graphql';
|
||||
|
||||
import { EnvironmentVariablesGroupData } from './environment-variables-group.dto';
|
||||
|
||||
@ObjectType()
|
||||
export class EnvironmentVariablesOutput {
|
||||
@Field(() => [EnvironmentVariablesGroupData])
|
||||
groups: EnvironmentVariablesGroupData[];
|
||||
}
|
||||
Reference in New Issue
Block a user