mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-09 22:24:05 -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 { DatabaseConfig } from './configs/database';
|
||||
import { EmailConfig } from './configs/email';
|
||||
import { VersionNotificationsConfig } from './configs/version-notifications';
|
||||
import { PublicApiConfig } from './configs/public-api';
|
||||
|
||||
@Config
|
||||
|
@ -21,6 +22,9 @@ export class GlobalConfig {
|
|||
@Nested
|
||||
userManagement: UserManagementConfig;
|
||||
|
||||
@Nested
|
||||
versionNotifications: VersionNotificationsConfig;
|
||||
|
||||
@Nested
|
||||
publicApi: PublicApiConfig;
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@ export class InternalHooks {
|
|||
const info = {
|
||||
version_cli: N8N_VERSION,
|
||||
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(
|
||||
'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: {
|
||||
enabled: {
|
||||
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 { isApiEnabled } from '@/PublicApi';
|
||||
import { Logger } from '@/Logger';
|
||||
import { GlobalConfig } from '@n8n/config';
|
||||
|
||||
@Service()
|
||||
export class InstanceRiskReporter implements RiskReporter {
|
||||
constructor(
|
||||
private readonly instanceSettings: InstanceSettings,
|
||||
private readonly logger: Logger,
|
||||
private readonly globalConfig: GlobalConfig,
|
||||
) {}
|
||||
|
||||
async report(workflows: WorkflowEntity[]) {
|
||||
|
@ -87,7 +89,7 @@ export class InstanceRiskReporter implements RiskReporter {
|
|||
|
||||
settings.features = {
|
||||
communityPackagesEnabled: config.getEnv('nodes.communityPackages.enabled'),
|
||||
versionNotificationsEnabled: config.getEnv('versionNotifications.enabled'),
|
||||
versionNotificationsEnabled: this.globalConfig.versionNotifications.enabled,
|
||||
templatesEnabled: config.getEnv('templates.enabled'),
|
||||
publicApiEnabled: isApiEnabled(),
|
||||
};
|
||||
|
@ -142,7 +144,7 @@ export class InstanceRiskReporter implements RiskReporter {
|
|||
}
|
||||
|
||||
private async getNextVersions(currentVersionName: string) {
|
||||
const BASE_URL = config.getEnv('versionNotifications.endpoint');
|
||||
const BASE_URL = this.globalConfig.versionNotifications.endpoint;
|
||||
const { instanceId } = this.instanceSettings;
|
||||
|
||||
const response = await axios.get<n8n.Version[]>(BASE_URL + currentVersionName, {
|
||||
|
|
|
@ -116,9 +116,9 @@ export class FrontendService {
|
|||
oauth2: `${instanceBaseUrl}/${restEndpoint}/oauth2-credential/callback`,
|
||||
},
|
||||
versionNotifications: {
|
||||
enabled: config.getEnv('versionNotifications.enabled'),
|
||||
endpoint: config.getEnv('versionNotifications.endpoint'),
|
||||
infoUrl: config.getEnv('versionNotifications.infoUrl'),
|
||||
enabled: this.globalConfig.versionNotifications.enabled,
|
||||
endpoint: this.globalConfig.versionNotifications.endpoint,
|
||||
infoUrl: this.globalConfig.versionNotifications.infoUrl,
|
||||
},
|
||||
instanceId: this.instanceSettings.instanceId,
|
||||
telemetry: telemetrySettings,
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import nock from 'nock';
|
||||
import config from '@/config';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
import { toReportTitle } from '@/security-audit/utils';
|
||||
import * as constants from '@/constants';
|
||||
|
@ -8,6 +7,7 @@ import type { InstalledNodes } from '@db/entities/InstalledNodes';
|
|||
import type { InstalledPackages } from '@db/entities/InstalledPackages';
|
||||
import { WorkflowRepository } from '@db/repositories/workflow.repository';
|
||||
import Container from 'typedi';
|
||||
import { GlobalConfig } from '@n8n/config';
|
||||
|
||||
type GetSectionKind<C extends Risk.Category> = C extends 'instance'
|
||||
? Risk.InstanceSection
|
||||
|
@ -111,7 +111,7 @@ export const MOCK_PACKAGE: InstalledPackages[] = [
|
|||
];
|
||||
|
||||
export function simulateOutdatedInstanceOnce(versionName = MOCK_01110_N8N_VERSION.name) {
|
||||
const baseUrl = config.getEnv('versionNotifications.endpoint') + '/';
|
||||
const baseUrl = Container.get(GlobalConfig).versionNotifications.endpoint + '/';
|
||||
|
||||
jest
|
||||
.spyOn(constants, 'getN8nPackageJson')
|
||||
|
@ -121,7 +121,7 @@ export function simulateOutdatedInstanceOnce(versionName = MOCK_01110_N8N_VERSIO
|
|||
}
|
||||
|
||||
export function simulateUpToDateInstance(versionName = MOCK_09990_N8N_VERSION.name) {
|
||||
const baseUrl = config.getEnv('versionNotifications.endpoint') + '/';
|
||||
const baseUrl = Container.get(GlobalConfig).versionNotifications.endpoint + '/';
|
||||
|
||||
jest
|
||||
.spyOn(constants, 'getN8nPackageJson')
|
||||
|
|
|
@ -25,6 +25,9 @@ describe('InternalHooks', () => {
|
|||
mode: 'smtp',
|
||||
},
|
||||
},
|
||||
versionNotifications: {
|
||||
enabled: true,
|
||||
},
|
||||
});
|
||||
const internalHooks = new InternalHooks(
|
||||
globalConfig,
|
||||
|
|
Loading…
Reference in a new issue