mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
refactor(core): Port version notifications config (no-changelog) (#10087)
This commit is contained in:
parent
68d3bebfee
commit
14b12f844d
16
packages/@n8n/config/src/configs/version-notifications.ts
Normal file
16
packages/@n8n/config/src/configs/version-notifications.ts
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
import { Config, Env } from '../decorators';
|
||||||
|
|
||||||
|
@Config
|
||||||
|
export class VersionNotificationsConfig {
|
||||||
|
/** Whether to request notifications about new n8n versions */
|
||||||
|
@Env('N8N_VERSION_NOTIFICATIONS_ENABLED')
|
||||||
|
readonly enabled: boolean = true;
|
||||||
|
|
||||||
|
/** Endpoint to retrieve n8n version information from */
|
||||||
|
@Env('N8N_VERSION_NOTIFICATIONS_ENDPOINT')
|
||||||
|
readonly endpoint: string = 'https://api.n8n.io/api/versions/';
|
||||||
|
|
||||||
|
/** URL for versions panel to page instructing user on how to update n8n instance */
|
||||||
|
@Env('N8N_VERSION_NOTIFICATIONS_INFO_URL')
|
||||||
|
readonly infoUrl: string = 'https://docs.n8n.io/hosting/installation/updating/';
|
||||||
|
}
|
|
@ -2,6 +2,7 @@ import { Config, Nested } from './decorators';
|
||||||
import { CredentialsConfig } from './configs/credentials';
|
import { CredentialsConfig } from './configs/credentials';
|
||||||
import { DatabaseConfig } from './configs/database';
|
import { DatabaseConfig } from './configs/database';
|
||||||
import { EmailConfig } from './configs/email';
|
import { EmailConfig } from './configs/email';
|
||||||
|
import { VersionNotificationsConfig } from './configs/version-notifications';
|
||||||
import { PublicApiConfig } from './configs/public-api';
|
import { PublicApiConfig } from './configs/public-api';
|
||||||
|
|
||||||
@Config
|
@Config
|
||||||
|
@ -21,6 +22,9 @@ export class GlobalConfig {
|
||||||
@Nested
|
@Nested
|
||||||
userManagement: UserManagementConfig;
|
userManagement: UserManagementConfig;
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
versionNotifications: VersionNotificationsConfig;
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
publicApi: PublicApiConfig;
|
publicApi: PublicApiConfig;
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,7 @@ export class InternalHooks {
|
||||||
const info = {
|
const info = {
|
||||||
version_cli: N8N_VERSION,
|
version_cli: N8N_VERSION,
|
||||||
db_type: this.globalConfig.database.type,
|
db_type: this.globalConfig.database.type,
|
||||||
n8n_version_notifications_enabled: config.getEnv('versionNotifications.enabled'),
|
n8n_version_notifications_enabled: this.globalConfig.versionNotifications.enabled,
|
||||||
n8n_disable_production_main_process: config.getEnv(
|
n8n_disable_production_main_process: config.getEnv(
|
||||||
'endpoints.disableProductionWebhooksOnMainProcess',
|
'endpoints.disableProductionWebhooksOnMainProcess',
|
||||||
),
|
),
|
||||||
|
|
|
@ -679,27 +679,6 @@ export const schema = {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
versionNotifications: {
|
|
||||||
enabled: {
|
|
||||||
doc: 'Whether feature is enabled to request notifications about new versions and security updates.',
|
|
||||||
format: Boolean,
|
|
||||||
default: true,
|
|
||||||
env: 'N8N_VERSION_NOTIFICATIONS_ENABLED',
|
|
||||||
},
|
|
||||||
endpoint: {
|
|
||||||
doc: 'Endpoint to retrieve version information from.',
|
|
||||||
format: String,
|
|
||||||
default: 'https://api.n8n.io/api/versions/',
|
|
||||||
env: 'N8N_VERSION_NOTIFICATIONS_ENDPOINT',
|
|
||||||
},
|
|
||||||
infoUrl: {
|
|
||||||
doc: "Url in New Versions Panel with more information on updating one's instance.",
|
|
||||||
format: String,
|
|
||||||
default: 'https://docs.n8n.io/getting-started/installation/updating.html',
|
|
||||||
env: 'N8N_VERSION_NOTIFICATIONS_INFO_URL',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
templates: {
|
templates: {
|
||||||
enabled: {
|
enabled: {
|
||||||
doc: 'Whether templates feature is enabled to load workflow templates.',
|
doc: 'Whether templates feature is enabled to load workflow templates.',
|
||||||
|
|
|
@ -15,12 +15,14 @@ import type { WorkflowEntity } from '@db/entities/WorkflowEntity';
|
||||||
import type { RiskReporter, Risk, n8n } from '@/security-audit/types';
|
import type { RiskReporter, Risk, n8n } from '@/security-audit/types';
|
||||||
import { isApiEnabled } from '@/PublicApi';
|
import { isApiEnabled } from '@/PublicApi';
|
||||||
import { Logger } from '@/Logger';
|
import { Logger } from '@/Logger';
|
||||||
|
import { GlobalConfig } from '@n8n/config';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export class InstanceRiskReporter implements RiskReporter {
|
export class InstanceRiskReporter implements RiskReporter {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly instanceSettings: InstanceSettings,
|
private readonly instanceSettings: InstanceSettings,
|
||||||
private readonly logger: Logger,
|
private readonly logger: Logger,
|
||||||
|
private readonly globalConfig: GlobalConfig,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async report(workflows: WorkflowEntity[]) {
|
async report(workflows: WorkflowEntity[]) {
|
||||||
|
@ -87,7 +89,7 @@ export class InstanceRiskReporter implements RiskReporter {
|
||||||
|
|
||||||
settings.features = {
|
settings.features = {
|
||||||
communityPackagesEnabled: config.getEnv('nodes.communityPackages.enabled'),
|
communityPackagesEnabled: config.getEnv('nodes.communityPackages.enabled'),
|
||||||
versionNotificationsEnabled: config.getEnv('versionNotifications.enabled'),
|
versionNotificationsEnabled: this.globalConfig.versionNotifications.enabled,
|
||||||
templatesEnabled: config.getEnv('templates.enabled'),
|
templatesEnabled: config.getEnv('templates.enabled'),
|
||||||
publicApiEnabled: isApiEnabled(),
|
publicApiEnabled: isApiEnabled(),
|
||||||
};
|
};
|
||||||
|
@ -142,7 +144,7 @@ export class InstanceRiskReporter implements RiskReporter {
|
||||||
}
|
}
|
||||||
|
|
||||||
private async getNextVersions(currentVersionName: string) {
|
private async getNextVersions(currentVersionName: string) {
|
||||||
const BASE_URL = config.getEnv('versionNotifications.endpoint');
|
const BASE_URL = this.globalConfig.versionNotifications.endpoint;
|
||||||
const { instanceId } = this.instanceSettings;
|
const { instanceId } = this.instanceSettings;
|
||||||
|
|
||||||
const response = await axios.get<n8n.Version[]>(BASE_URL + currentVersionName, {
|
const response = await axios.get<n8n.Version[]>(BASE_URL + currentVersionName, {
|
||||||
|
|
|
@ -116,9 +116,9 @@ export class FrontendService {
|
||||||
oauth2: `${instanceBaseUrl}/${restEndpoint}/oauth2-credential/callback`,
|
oauth2: `${instanceBaseUrl}/${restEndpoint}/oauth2-credential/callback`,
|
||||||
},
|
},
|
||||||
versionNotifications: {
|
versionNotifications: {
|
||||||
enabled: config.getEnv('versionNotifications.enabled'),
|
enabled: this.globalConfig.versionNotifications.enabled,
|
||||||
endpoint: config.getEnv('versionNotifications.endpoint'),
|
endpoint: this.globalConfig.versionNotifications.endpoint,
|
||||||
infoUrl: config.getEnv('versionNotifications.infoUrl'),
|
infoUrl: this.globalConfig.versionNotifications.infoUrl,
|
||||||
},
|
},
|
||||||
instanceId: this.instanceSettings.instanceId,
|
instanceId: this.instanceSettings.instanceId,
|
||||||
telemetry: telemetrySettings,
|
telemetry: telemetrySettings,
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import nock from 'nock';
|
import nock from 'nock';
|
||||||
import config from '@/config';
|
|
||||||
import { v4 as uuid } from 'uuid';
|
import { v4 as uuid } from 'uuid';
|
||||||
import { toReportTitle } from '@/security-audit/utils';
|
import { toReportTitle } from '@/security-audit/utils';
|
||||||
import * as constants from '@/constants';
|
import * as constants from '@/constants';
|
||||||
|
@ -8,6 +7,7 @@ import type { InstalledNodes } from '@db/entities/InstalledNodes';
|
||||||
import type { InstalledPackages } from '@db/entities/InstalledPackages';
|
import type { InstalledPackages } from '@db/entities/InstalledPackages';
|
||||||
import { WorkflowRepository } from '@db/repositories/workflow.repository';
|
import { WorkflowRepository } from '@db/repositories/workflow.repository';
|
||||||
import Container from 'typedi';
|
import Container from 'typedi';
|
||||||
|
import { GlobalConfig } from '@n8n/config';
|
||||||
|
|
||||||
type GetSectionKind<C extends Risk.Category> = C extends 'instance'
|
type GetSectionKind<C extends Risk.Category> = C extends 'instance'
|
||||||
? Risk.InstanceSection
|
? Risk.InstanceSection
|
||||||
|
@ -111,7 +111,7 @@ export const MOCK_PACKAGE: InstalledPackages[] = [
|
||||||
];
|
];
|
||||||
|
|
||||||
export function simulateOutdatedInstanceOnce(versionName = MOCK_01110_N8N_VERSION.name) {
|
export function simulateOutdatedInstanceOnce(versionName = MOCK_01110_N8N_VERSION.name) {
|
||||||
const baseUrl = config.getEnv('versionNotifications.endpoint') + '/';
|
const baseUrl = Container.get(GlobalConfig).versionNotifications.endpoint + '/';
|
||||||
|
|
||||||
jest
|
jest
|
||||||
.spyOn(constants, 'getN8nPackageJson')
|
.spyOn(constants, 'getN8nPackageJson')
|
||||||
|
@ -121,7 +121,7 @@ export function simulateOutdatedInstanceOnce(versionName = MOCK_01110_N8N_VERSIO
|
||||||
}
|
}
|
||||||
|
|
||||||
export function simulateUpToDateInstance(versionName = MOCK_09990_N8N_VERSION.name) {
|
export function simulateUpToDateInstance(versionName = MOCK_09990_N8N_VERSION.name) {
|
||||||
const baseUrl = config.getEnv('versionNotifications.endpoint') + '/';
|
const baseUrl = Container.get(GlobalConfig).versionNotifications.endpoint + '/';
|
||||||
|
|
||||||
jest
|
jest
|
||||||
.spyOn(constants, 'getN8nPackageJson')
|
.spyOn(constants, 'getN8nPackageJson')
|
||||||
|
|
|
@ -25,6 +25,9 @@ describe('InternalHooks', () => {
|
||||||
mode: 'smtp',
|
mode: 'smtp',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
versionNotifications: {
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
const internalHooks = new InternalHooks(
|
const internalHooks = new InternalHooks(
|
||||||
globalConfig,
|
globalConfig,
|
||||||
|
|
Loading…
Reference in a new issue