Skip to content

Twenty config core implementation #11595

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 86 commits into
base: main
Choose a base branch
from

Conversation

ehconitin
Copy link
Contributor

@ehconitin ehconitin commented Apr 16, 2025

ehconitin added 26 commits April 9, 2025 18:56
…as the number of env vars in config variables file
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

(updates since last review)

Based on the recent changes and previous reviews, I'll focus on the most significant updates to the configuration system:

This PR enhances the configuration system with improved caching and initialization handling.

  • Added ConfigInitializationState enum to track configuration loading states (NOT_INITIALIZED, INITIALIZING, INITIALIZED, FAILED)
  • Implemented ConfigSource enum to properly identify configuration origins (ENVIRONMENT, DATABASE, DEFAULT)
  • Added proper handling of environment-only variables through isEnvOnlyConfigVar utility
  • Improved type safety with ConfigVariableType and ConfigVariableOptions types
  • Added basic validation utilities in apply-basic-validators.util.ts for different data types

The changes improve the configuration system's reliability through better state management and type validation while maintaining clear separation between environment and database configurations.

33 file(s) reviewed, 10 comment(s)
Edit PR Review Bot Settings | Greptile

@@ -78,4 +78,4 @@ FRONTEND_URL=http://localhost:3001
# CLOUDFLARE_WEBHOOK_SECRET=
# IS_CONFIG_VARIABLES_IN_DB_ENABLED=false
# ANALYTICS_ENABLED=
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: ANALYTICS_ENABLED is empty but should have a default boolean value (true/false)

Comment on lines 158 to 159
@Cron(`0 */${CONFIG_VARIABLES_REFRESH_INTERVAL_MINUTES} * * * *`)
async refreshExpiredCache(): Promise<void> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Cron job could start before initialization is complete. Consider adding initialization check.

Comment on lines +58 to +60
this.logger.debug(
`Fetching config for ${key as string} in database: ${result?.value}`,
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Logging sensitive configuration values could expose secrets in logs

Suggested change
this.logger.debug(
`Fetching config for ${key as string} in database: ${result?.value}`,
);
this.logger.debug(
`Fetching config for ${key as string}`,
);

Comment on lines +11 to +13
if (typeof value === 'number') {
return value !== 0;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider handling NaN, Infinity, and -Infinity explicitly in number conversion

Comment on lines +32 to +34
provide: TwentyConfigService,
useValue: {},
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Empty mock object for TwentyConfigService may be insufficient. Consider adding necessary mock methods/properties that the service actually uses.

@ehconitin ehconitin requested a review from Copilot April 23, 2025 17:24
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements core configuration functionality along with several refactorings and improvements for the Twenty config system, addressing an issue raised in core-team-issues#760. Key changes include:

  • Introducing a new enum (ConfigInitializationState) and new interfaces/driver implementations for database- and environment-backed configuration.
  • Refactoring config metadata decorators and removing legacy cast decorators, with corresponding updates to conversion services and tests.
  • Adding caching support with a dedicated ConfigCacheService and comprehensive unit tests.

Reviewed Changes

Copilot reviewed 34 out of 35 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/twenty-server/src/engine/core-modules/twenty-config/enums/config-initialization-state.enum.ts Adds a new enum for representing configuration initialization states.
packages/twenty-server/src/engine/core-modules/twenty-config/drivers/interfaces/database-config-driver.interface.ts Introduces an interface for database config drivers with new methods.
packages/twenty-server/src/engine/core-modules/twenty-config/drivers/environment-config.driver.ts & database-config.driver.ts Implements environment and database drivers with logging, error handling, and refresh scheduling.
packages/twenty-server/src/engine/core-modules/twenty-config/decorators/config-variables-metadata.decorator.ts Updates the metadata decorator to support new options (isEnvOnly, type, options) and applies basic validators.
packages/twenty-server/src/engine/core-modules/twenty-config/conversion/config-value-converter.service.ts & spec Adds a service for converting values between DB and app representations with unit tests.
packages/twenty-server/src/engine/core-modules/twenty-config/config-variables.ts Refactors config variable definitions to use type metadata instead of legacy cast decorators.
packages/twenty-server/src/engine/core-modules/twenty-config/cache/config-cache.service.ts & spec Implements a cache service for config values with TTL and negative cache support.
packages/twenty-server/src/engine/core-modules/file/* Cleans up imports by removing unused TwentyConfigService injections.
Files not reviewed (1)
  • packages/twenty-server/package.json: Language not supported
Comments suppressed due to low confidence (1)

packages/twenty-server/src/engine/core-modules/twenty-config/config-variables.ts:42

  • The removal of legacy cast decorators like @CastToBoolean() may lead to unexpected transformation behavior if the new metadata-based validation does not fully replicate the previous behavior. Please verify that the new type metadata and validators cover all transformation scenarios previously handled by the cast decorators.
-  @CastToBoolean()

@ehconitin ehconitin force-pushed the twenty-config-core-implementation branch from 2eaee68 to 8fef8d1 Compare April 24, 2025 20:55
Copy link
Contributor

github-actions bot commented Apr 24, 2025

Warnings
⚠️ Changes were made to the config variables, but not to the documentation - Please review your changes and check if a change needs to be documented!

Generated by 🚫 dangerJS against 275918f

Copy link
Contributor

github-actions bot commented Apr 25, 2025

🚀 Preview Environment Ready!

Your preview environment is available at: http://bore.pub:21544

This environment will automatically shut down when the PR is closed or after 5 hours.

cacheKeys: string[];
} {
return {
positiveEntries: this.foundConfigValuesCache.size,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we get rid of this positive/negative linguo and stick to found/missing you already use

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Core Configuration Service Implementation - DB-level Config
3 participants