Skip to content
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

fix(core): Use explicit types in configs to ensure valid decorator metadata #10433

Merged
merged 2 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/@n8n/config/src/configs/cache.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ import { Config, Env, Nested } from '../decorators';
class MemoryConfig {
/** Max size of memory cache in bytes */
@Env('N8N_CACHE_MEMORY_MAX_SIZE')
maxSize = 3 * 1024 * 1024; // 3 MiB
maxSize: number = 3 * 1024 * 1024; // 3 MiB

/** Time to live (in milliseconds) for data cached in memory. */
@Env('N8N_CACHE_MEMORY_TTL')
ttl = 3600 * 1000; // 1 hour
ttl: number = 3600 * 1000; // 1 hour
}

@Config
class RedisConfig {
/** Prefix for cache keys in Redis. */
@Env('N8N_CACHE_REDIS_KEY_PREFIX')
prefix = 'redis';
prefix: string = 'redis';

/** Time to live (in milliseconds) for data cached in Redis. 0 for no TTL. */
@Env('N8N_CACHE_REDIS_TTL')
ttl = 3600 * 1000; // 1 hour
ttl: number = 3600 * 1000; // 1 hour
}

@Config
Expand Down
6 changes: 3 additions & 3 deletions packages/@n8n/config/src/configs/credentials.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ class CredentialsOverwrite {
* Format: { CREDENTIAL_NAME: { PARAMETER: VALUE }}
*/
@Env('CREDENTIALS_OVERWRITE_DATA')
data = '{}';
data: string = '{}';

/** Internal API endpoint to fetch overwritten credential types from. */
@Env('CREDENTIALS_OVERWRITE_ENDPOINT')
endpoint = '';
endpoint: string = '';
}

@Config
export class CredentialsConfig {
/** Default name for credentials */
@Env('CREDENTIALS_DEFAULT_NAME')
defaultName = 'My credentials';
defaultName: string = 'My credentials';

@Nested
overwrite: CredentialsOverwrite;
Expand Down
42 changes: 21 additions & 21 deletions packages/@n8n/config/src/configs/database.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Config, Env, Nested } from '../decorators';
class LoggingConfig {
/** Whether database logging is enabled. */
@Env('DB_LOGGING_ENABLED')
enabled = false;
enabled: boolean = false;

/**
* Database logging level. Requires `DB_LOGGING_MAX_EXECUTION_TIME` to be higher than `0`.
Expand All @@ -16,7 +16,7 @@ class LoggingConfig {
* Only queries that exceed this time (ms) will be logged. Set `0` to disable.
*/
@Env('DB_LOGGING_MAX_EXECUTION_TIME')
maxQueryExecutionTime = 0;
maxQueryExecutionTime: number = 0;
}

@Config
Expand All @@ -26,54 +26,54 @@ class PostgresSSLConfig {
* If `DB_POSTGRESDB_SSL_CA`, `DB_POSTGRESDB_SSL_CERT`, or `DB_POSTGRESDB_SSL_KEY` are defined, `DB_POSTGRESDB_SSL_ENABLED` defaults to `true`.
*/
@Env('DB_POSTGRESDB_SSL_ENABLED')
enabled = false;
enabled: boolean = false;

/** SSL certificate authority */
@Env('DB_POSTGRESDB_SSL_CA')
ca = '';
ca: string = '';

/** SSL certificate */
@Env('DB_POSTGRESDB_SSL_CERT')
cert = '';
cert: string = '';

/** SSL key */
@Env('DB_POSTGRESDB_SSL_KEY')
key = '';
key: string = '';

/** If unauthorized SSL connections should be rejected */
@Env('DB_POSTGRESDB_SSL_REJECT_UNAUTHORIZED')
rejectUnauthorized = true;
rejectUnauthorized: boolean = true;
}

@Config
class PostgresConfig {
/** Postgres database name */
@Env('DB_POSTGRESDB_DATABASE')
database = 'n8n';
database: string = 'n8n';

/** Postgres database host */
@Env('DB_POSTGRESDB_HOST')
host = 'localhost';
host: string = 'localhost';

/** Postgres database password */
@Env('DB_POSTGRESDB_PASSWORD')
password = '';
password: string = '';

/** Postgres database port */
@Env('DB_POSTGRESDB_PORT')
port: number = 5432;

/** Postgres database user */
@Env('DB_POSTGRESDB_USER')
user = 'postgres';
user: string = 'postgres';

/** Postgres database schema */
@Env('DB_POSTGRESDB_SCHEMA')
schema = 'public';
schema: string = 'public';

/** Postgres database pool size */
@Env('DB_POSTGRESDB_POOL_SIZE')
poolSize = 2;
poolSize: number = 2;

@Nested
ssl: PostgresSSLConfig;
Expand All @@ -83,30 +83,30 @@ class PostgresConfig {
class MysqlConfig {
/** @deprecated MySQL database name */
@Env('DB_MYSQLDB_DATABASE')
database = 'n8n';
database: string = 'n8n';

/** MySQL database host */
@Env('DB_MYSQLDB_HOST')
host = 'localhost';
host: string = 'localhost';

/** MySQL database password */
@Env('DB_MYSQLDB_PASSWORD')
password = '';
password: string = '';

/** MySQL database port */
@Env('DB_MYSQLDB_PORT')
port: number = 3306;

/** MySQL database user */
@Env('DB_MYSQLDB_USER')
user = 'root';
user: string = 'root';
}

@Config
class SqliteConfig {
/** SQLite database file name */
@Env('DB_SQLITE_DATABASE')
database = 'database.sqlite';
database: string = 'database.sqlite';

/** SQLite database pool size. Set to `0` to disable pooling. */
@Env('DB_SQLITE_POOL_SIZE')
Expand All @@ -116,15 +116,15 @@ class SqliteConfig {
* Enable SQLite WAL mode.
*/
@Env('DB_SQLITE_ENABLE_WAL')
enableWAL = this.poolSize > 1;
enableWAL: boolean = this.poolSize > 1;

/**
* Run `VACUUM` on startup to rebuild the database, reducing file size and optimizing indexes.
*
* @warning Long-running blocking operation that will increase startup time.
*/
@Env('DB_SQLITE_VACUUM_ON_STARTUP')
executeVacuumOnStartup = false;
executeVacuumOnStartup: boolean = false;
}

@Config
Expand All @@ -135,7 +135,7 @@ export class DatabaseConfig {

/** Prefix for table names */
@Env('DB_TABLE_PREFIX')
tablePrefix = '';
tablePrefix: string = '';

@Nested
logging: LoggingConfig;
Expand Down
44 changes: 22 additions & 22 deletions packages/@n8n/config/src/configs/endpoints.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,51 @@ import { Config, Env, Nested } from '../decorators';
class PrometheusMetricsConfig {
/** Whether to enable the `/metrics` endpoint to expose Prometheus metrics. */
@Env('N8N_METRICS')
enable = false;
enable: boolean = false;

/** Prefix for Prometheus metric names. */
@Env('N8N_METRICS_PREFIX')
prefix = 'n8n_';
prefix: string = 'n8n_';

/** Whether to expose system and Node.js metrics. See: https://www.npmjs.com/package/prom-client */
@Env('N8N_METRICS_INCLUDE_DEFAULT_METRICS')
includeDefaultMetrics = true;
includeDefaultMetrics: boolean = true;

/** Whether to include a label for workflow ID on workflow metrics. */
@Env('N8N_METRICS_INCLUDE_WORKFLOW_ID_LABEL')
includeWorkflowIdLabel = false;
includeWorkflowIdLabel: boolean = false;

/** Whether to include a label for node type on node metrics. */
@Env('N8N_METRICS_INCLUDE_NODE_TYPE_LABEL')
includeNodeTypeLabel = false;
includeNodeTypeLabel: boolean = false;

/** Whether to include a label for credential type on credential metrics. */
@Env('N8N_METRICS_INCLUDE_CREDENTIAL_TYPE_LABEL')
includeCredentialTypeLabel = false;
includeCredentialTypeLabel: boolean = false;

/** Whether to expose metrics for API endpoints. See: https://www.npmjs.com/package/express-prom-bundle */
@Env('N8N_METRICS_INCLUDE_API_ENDPOINTS')
includeApiEndpoints = false;
includeApiEndpoints: boolean = false;

/** Whether to include a label for the path of API endpoint calls. */
@Env('N8N_METRICS_INCLUDE_API_PATH_LABEL')
includeApiPathLabel = false;
includeApiPathLabel: boolean = false;

/** Whether to include a label for the HTTP method of API endpoint calls. */
@Env('N8N_METRICS_INCLUDE_API_METHOD_LABEL')
includeApiMethodLabel = false;
includeApiMethodLabel: boolean = false;

/** Whether to include a label for the status code of API endpoint calls. */
@Env('N8N_METRICS_INCLUDE_API_STATUS_CODE_LABEL')
includeApiStatusCodeLabel = false;
includeApiStatusCodeLabel: boolean = false;

/** Whether to include metrics for cache hits and misses. */
@Env('N8N_METRICS_INCLUDE_CACHE_METRICS')
includeCacheMetrics = false;
includeCacheMetrics: boolean = false;

/** Whether to include metrics derived from n8n's internal events */
@Env('N8N_METRICS_INCLUDE_MESSAGE_EVENT_BUS_METRICS')
includeMessageEventBusMetrics = false;
includeMessageEventBusMetrics: boolean = false;
}

@Config
Expand All @@ -62,41 +62,41 @@ export class EndpointsConfig {

/** Path segment for REST API endpoints. */
@Env('N8N_ENDPOINT_REST')
rest = 'rest';
rest: string = 'rest';

/** Path segment for form endpoints. */
@Env('N8N_ENDPOINT_FORM')
form = 'form';
form: string = 'form';

/** Path segment for test form endpoints. */
@Env('N8N_ENDPOINT_FORM_TEST')
formTest = 'form-test';
formTest: string = 'form-test';

/** Path segment for waiting form endpoints. */
@Env('N8N_ENDPOINT_FORM_WAIT')
formWaiting = 'form-waiting';
formWaiting: string = 'form-waiting';

/** Path segment for webhook endpoints. */
@Env('N8N_ENDPOINT_WEBHOOK')
webhook = 'webhook';
webhook: string = 'webhook';

/** Path segment for test webhook endpoints. */
@Env('N8N_ENDPOINT_WEBHOOK_TEST')
webhookTest = 'webhook-test';
webhookTest: string = 'webhook-test';

/** Path segment for waiting webhook endpoints. */
@Env('N8N_ENDPOINT_WEBHOOK_WAIT')
webhookWaiting = 'webhook-waiting';
webhookWaiting: string = 'webhook-waiting';

/** Whether to disable n8n's UI (frontend). */
@Env('N8N_DISABLE_UI')
disableUi = false;
disableUi: boolean = false;

/** Whether to disable production webhooks on the main process, when using webhook-specific processes. */
@Env('N8N_DISABLE_PRODUCTION_MAIN_PROCESS')
disableProductionWebhooksOnMainProcess = false;
disableProductionWebhooksOnMainProcess: boolean = false;

/** Colon-delimited list of additional endpoints to not open the UI on. */
@Env('N8N_ADDITIONAL_NON_UI_ROUTES')
additionalNonUIRoutes = '';
additionalNonUIRoutes: string = '';
}
8 changes: 4 additions & 4 deletions packages/@n8n/config/src/configs/event-bus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ import { Config, Env, Nested } from '../decorators';
class LogWriterConfig {
/* of event log files to keep */
@Env('N8N_EVENTBUS_LOGWRITER_KEEPLOGCOUNT')
keepLogCount = 3;
keepLogCount: number = 3;

/** Max size (in KB) of an event log file before a new one is started */
@Env('N8N_EVENTBUS_LOGWRITER_MAXFILESIZEINKB')
maxFileSizeInKB = 10240; // 10 MB
maxFileSizeInKB: number = 10240; // 10 MB

/** Basename of event log file */
@Env('N8N_EVENTBUS_LOGWRITER_LOGBASENAME')
logBaseName = 'n8nEventLog';
logBaseName: string = 'n8nEventLog';
}

@Config
export class EventBusConfig {
/** How often (in ms) to check for unsent event messages. Can in rare cases cause a message to be sent twice. `0` to disable */
@Env('N8N_EVENTBUS_CHECKUNSENTINTERVAL')
checkUnsentInterval = 0;
checkUnsentInterval: number = 0;

/** Endpoint to retrieve n8n version information from */
@Nested
Expand Down
4 changes: 2 additions & 2 deletions packages/@n8n/config/src/configs/external-secrets.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { Config, Env } from '../decorators';
export class ExternalSecretsConfig {
/** How often (in seconds) to check for secret updates */
@Env('N8N_EXTERNAL_SECRETS_UPDATE_INTERVAL')
updateInterval = 300;
updateInterval: number = 300;

/** Whether to prefer GET over LIST when fetching secrets from Hashicorp Vault */
@Env('N8N_EXTERNAL_SECRETS_PREFER_GET')
preferGet = false;
preferGet: boolean = false;
}
10 changes: 5 additions & 5 deletions packages/@n8n/config/src/configs/external-storage.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,29 @@ import { Config, Env, Nested } from '../decorators';
class S3BucketConfig {
/** Name of the n8n bucket in S3-compatible external storage */
@Env('N8N_EXTERNAL_STORAGE_S3_BUCKET_NAME')
name = '';
name: string = '';

/** Region of the n8n bucket in S3-compatible external storage @example "us-east-1" */
@Env('N8N_EXTERNAL_STORAGE_S3_BUCKET_REGION')
region = '';
region: string = '';
}

@Config
class S3CredentialsConfig {
/** Access key in S3-compatible external storage */
@Env('N8N_EXTERNAL_STORAGE_S3_ACCESS_KEY')
accessKey = '';
accessKey: string = '';

/** Access secret in S3-compatible external storage */
@Env('N8N_EXTERNAL_STORAGE_S3_ACCESS_SECRET')
accessSecret = '';
accessSecret: string = '';
}

@Config
class S3Config {
/** Host of the n8n bucket in S3-compatible external storage @example "s3.us-east-1.amazonaws.com" */
@Env('N8N_EXTERNAL_STORAGE_S3_HOST')
host = '';
host: string = '';

@Nested
bucket: S3BucketConfig;
Expand Down
2 changes: 1 addition & 1 deletion packages/@n8n/config/src/configs/nodes.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class NodesConfig {

/** Node type to use as error trigger */
@Env('NODES_ERROR_TRIGGER_TYPE')
errorTriggerType = 'n8n-nodes-base.errorTrigger';
errorTriggerType: string = 'n8n-nodes-base.errorTrigger';

@Nested
communityPackages: CommunityPackagesConfig;
Expand Down
Loading
Loading