mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-16 17:46:45 +00:00
refactor(core): Port config for frontend hooks, Redis and AI features (#17728)
This commit is contained in:
8
packages/@n8n/config/src/configs/ai.config.ts
Normal file
8
packages/@n8n/config/src/configs/ai.config.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { Config, Env } from '../decorators';
|
||||
|
||||
@Config
|
||||
export class AiConfig {
|
||||
/** Whether AI features are enabled. */
|
||||
@Env('N8N_AI_ENABLED')
|
||||
enabled: boolean = false;
|
||||
}
|
||||
8
packages/@n8n/config/src/configs/redis.config.ts
Normal file
8
packages/@n8n/config/src/configs/redis.config.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { Config, Env } from '../decorators';
|
||||
|
||||
@Config
|
||||
export class RedisConfig {
|
||||
/** Prefix for all Redis keys managed by n8n. */
|
||||
@Env('N8N_REDIS_KEY_PREFIX')
|
||||
prefix: string = 'n8n';
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import { AiAssistantConfig } from './configs/ai-assistant.config';
|
||||
import { AiConfig } from './configs/ai.config';
|
||||
import { AuthConfig } from './configs/auth.config';
|
||||
import { CacheConfig } from './configs/cache.config';
|
||||
import { CredentialsConfig } from './configs/credentials.config';
|
||||
@@ -21,6 +22,7 @@ import { NodesConfig } from './configs/nodes.config';
|
||||
import { PartialExecutionsConfig } from './configs/partial-executions.config';
|
||||
import { PersonalizationConfig } from './configs/personalization.config';
|
||||
import { PublicApiConfig } from './configs/public-api.config';
|
||||
import { RedisConfig } from './configs/redis.config';
|
||||
import { TaskRunnersConfig } from './configs/runners.config';
|
||||
import { ScalingModeConfig } from './configs/scaling-mode.config';
|
||||
import { SecurityConfig } from './configs/security.config';
|
||||
@@ -195,4 +197,14 @@ export class GlobalConfig {
|
||||
/** Public URL where the editor is accessible. Also used for emails sent from n8n. */
|
||||
@Env('N8N_EDITOR_BASE_URL')
|
||||
editorBaseUrl: string = '';
|
||||
|
||||
/** URLs to external frontend hooks files, separated by semicolons. */
|
||||
@Env('EXTERNAL_FRONTEND_HOOKS_URLS')
|
||||
externalFrontendHooksUrls: string = '';
|
||||
|
||||
@Nested
|
||||
redis: RedisConfig;
|
||||
|
||||
@Nested
|
||||
ai: AiConfig;
|
||||
}
|
||||
|
||||
@@ -348,6 +348,13 @@ describe('GlobalConfig', () => {
|
||||
loginLabel: '',
|
||||
},
|
||||
},
|
||||
redis: {
|
||||
prefix: 'n8n',
|
||||
},
|
||||
externalFrontendHooksUrls: '',
|
||||
ai: {
|
||||
enabled: false,
|
||||
},
|
||||
};
|
||||
|
||||
it('should use all default values when no env variables are defined', () => {
|
||||
|
||||
@@ -126,7 +126,7 @@ export class Start extends BaseCommand<z.infer<typeof flagsSchema>> {
|
||||
private async generateStaticAssets() {
|
||||
// Read the index file and replace the path placeholder
|
||||
const n8nPath = this.globalConfig.path;
|
||||
const hooksUrls = config.getEnv('externalFrontendHooksUrls');
|
||||
const hooksUrls = this.globalConfig.externalFrontendHooksUrls;
|
||||
|
||||
let scriptsString = '';
|
||||
if (hooksUrls) {
|
||||
|
||||
@@ -139,22 +139,6 @@ export const schema = {
|
||||
},
|
||||
},
|
||||
|
||||
externalFrontendHooksUrls: {
|
||||
doc: 'URLs to external frontend hooks files, ; separated',
|
||||
format: String,
|
||||
default: '',
|
||||
env: 'EXTERNAL_FRONTEND_HOOKS_URLS',
|
||||
},
|
||||
|
||||
redis: {
|
||||
prefix: {
|
||||
doc: 'Prefix for all n8n related keys',
|
||||
format: String,
|
||||
default: 'n8n',
|
||||
env: 'N8N_REDIS_KEY_PREFIX',
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
* @important Do not remove until after cloud hooks are updated to stop using convict config.
|
||||
*/
|
||||
@@ -170,10 +154,8 @@ export const schema = {
|
||||
*/
|
||||
ai: {
|
||||
enabled: {
|
||||
doc: 'Whether AI features are enabled',
|
||||
format: Boolean,
|
||||
default: false,
|
||||
env: 'N8N_AI_ENABLED',
|
||||
default: Container.get(GlobalConfig).ai.enabled,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -5,7 +5,6 @@ import { MultiMainMetadata } from '@n8n/decorators';
|
||||
import { Container, Service } from '@n8n/di';
|
||||
import { InstanceSettings } from 'n8n-core';
|
||||
|
||||
import config from '@/config';
|
||||
import { Publisher } from '@/scaling/pubsub/publisher.service';
|
||||
import { RedisClientService } from '@/services/redis-client.service';
|
||||
import { TypedEmitter } from '@/typed-emitter';
|
||||
@@ -48,7 +47,7 @@ export class MultiMainSetup extends TypedEmitter<MultiMainEvents> {
|
||||
private leaderCheckInterval: NodeJS.Timeout | undefined;
|
||||
|
||||
async init() {
|
||||
const prefix = config.getEnv('redis.prefix');
|
||||
const prefix = this.globalConfig.redis.prefix;
|
||||
const validPrefix = this.redisClientService.toValidPrefix(prefix);
|
||||
this.leaderKey = validPrefix + ':main_instance_leader';
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ export class CacheService extends TypedEmitter<CacheEvents> {
|
||||
const { RedisClientService } = await import('../redis-client.service');
|
||||
const redisClientService = Container.get(RedisClientService);
|
||||
|
||||
const prefixBase = config.getEnv('redis.prefix');
|
||||
const prefixBase = this.globalConfig.redis.prefix;
|
||||
const prefix = redisClientService.toValidPrefix(
|
||||
`${prefixBase}:${this.globalConfig.cache.redis.prefix}:`,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user