refactor(pre-installed-apps): extract parsePreInstalledApps util

The `@ValidateIf` callback on EXA_API_KEY in config-variables.ts (added
in the stacked PR) reimplements the same comma-split-trim-filter logic
as PreInstalledAppsService.getPreInstalledPackageNames. Extract the
pure parser once so the startup-validator and the runtime service can
share the invariant (whitespace, empty handling) — if the parsing rule
ever changes, both sites update together.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Félix Malfait
2026-04-22 16:32:49 +02:00
co-authored by Claude Opus 4.7
parent 3931281b6f
commit adb68668fb
2 changed files with 13 additions and 6 deletions
@@ -10,6 +10,7 @@ import { ApplicationRegistrationVariableEntity } from 'src/engine/core-modules/a
import { ApplicationRegistrationEntity } from 'src/engine/core-modules/application/application-registration/application-registration.entity';
import { ApplicationRegistrationSourceType } from 'src/engine/core-modules/application/application-registration/enums/application-registration-source-type.enum';
import { ApplicationRegistrationService } from 'src/engine/core-modules/application/application-registration/application-registration.service';
import { parsePreInstalledApps } from 'src/engine/core-modules/application/pre-installed-apps/utils/parse-pre-installed-apps.util';
import { SecretEncryptionService } from 'src/engine/core-modules/secret-encryption/secret-encryption.service';
import { TwentyConfigService } from 'src/engine/core-modules/twenty-config/twenty-config.service';
@@ -49,12 +50,9 @@ export class PreInstalledAppsService implements OnApplicationBootstrap {
}
getPreInstalledPackageNames(): string[] {
const raw = this.twentyConfigService.get('PRE_INSTALLED_APPS') ?? '';
return raw
.split(',')
.map((name) => name.trim())
.filter((name) => name.length > 0);
return parsePreInstalledApps(
this.twentyConfigService.get('PRE_INSTALLED_APPS'),
);
}
// Idempotent: fetches each pre-installed package's manifest from the
@@ -0,0 +1,9 @@
// Parses the `PRE_INSTALLED_APPS` env string into a list of npm package
// names. Shared between the config validator (at startup-time) and
// PreInstalledAppsService (at runtime) so the two code paths can't drift
// on whitespace/empty handling.
export const parsePreInstalledApps = (raw: string | undefined): string[] =>
(raw ?? '')
.split(',')
.map((name) => name.trim())
.filter((name) => name.length > 0);