From ac245fdb8d99fce1ab32020f2e18653f04b9ca76 Mon Sep 17 00:00:00 2001 From: Michael Auerswald Date: Fri, 21 Apr 2023 13:30:57 +0200 Subject: [PATCH] refactor(editor): Consolidate IN8nUISettings interface (#6055) * consolidate IN8nUISettings * cleanup --- packages/cli/src/Interfaces.ts | 101 ---------------- packages/cli/src/Server.ts | 6 +- packages/editor-ui/src/Interface.ts | 100 +--------------- .../__tests__/server/endpoints/settings.ts | 22 +++- packages/editor-ui/src/api/settings.ts | 2 +- .../src/components/WorkflowSettings.vue | 4 +- .../src/stores/__tests__/posthog.test.ts | 2 +- .../src/stores/__tests__/sso.test.ts | 2 +- packages/editor-ui/src/stores/settings.ts | 13 ++- .../src/utils/__tests__/userUtils.test.ts | 3 +- packages/workflow/src/Interfaces.ts | 110 +++++++++++++++++- 11 files changed, 151 insertions(+), 214 deletions(-) diff --git a/packages/cli/src/Interfaces.ts b/packages/cli/src/Interfaces.ts index ddbfce8abf..b6f1dd984a 100644 --- a/packages/cli/src/Interfaces.ts +++ b/packages/cli/src/Interfaces.ts @@ -13,7 +13,6 @@ import type { IRunData, IRunExecutionData, ITaskData, - ITelemetrySettings, ITelemetryTrackProperties, IWorkflowBase, CredentialLoadingDetails, @@ -23,8 +22,6 @@ import type { ExecutionStatus, IExecutionsSummary, FeatureFlags, - WorkflowSettings, - AuthenticationMethod, } from 'n8n-workflow'; import type { ActiveWorkflowRunner } from '@/ActiveWorkflowRunner'; @@ -469,90 +466,6 @@ export interface IVersionNotificationSettings { infoUrl: string; } -export interface IN8nUISettings { - endpointWebhook: string; - endpointWebhookTest: string; - saveDataErrorExecution: WorkflowSettings.SaveDataExecution; - saveDataSuccessExecution: WorkflowSettings.SaveDataExecution; - saveManualExecutions: boolean; - executionTimeout: number; - maxExecutionTimeout: number; - workflowCallerPolicyDefaultOption: WorkflowSettings.CallerPolicy; - oauthCallbackUrls: { - oauth1: string; - oauth2: string; - }; - timezone: string; - urlBaseWebhook: string; - urlBaseEditor: string; - versionCli: string; - n8nMetadata?: { - [key: string]: string | number | undefined; - }; - versionNotifications: IVersionNotificationSettings; - instanceId: string; - telemetry: ITelemetrySettings; - posthog: { - enabled: boolean; - apiHost: string; - apiKey: string; - autocapture: boolean; - disableSessionRecording: boolean; - debug: boolean; - }; - personalizationSurveyEnabled: boolean; - userActivationSurveyEnabled: boolean; - defaultLocale: string; - userManagement: IUserManagementSettings; - sso: { - saml: { - loginLabel: string; - loginEnabled: boolean; - }; - ldap: { - loginLabel: string; - loginEnabled: boolean; - }; - }; - publicApi: IPublicApiSettings; - workflowTagsDisabled: boolean; - logLevel: 'info' | 'debug' | 'warn' | 'error' | 'verbose' | 'silent'; - hiringBannerEnabled: boolean; - templates: { - enabled: boolean; - host: string; - }; - onboardingCallPromptEnabled: boolean; - missingPackages?: boolean; - executionMode: 'regular' | 'queue'; - pushBackend: 'sse' | 'websocket'; - communityNodesEnabled: boolean; - deployment: { - type: string; - }; - isNpmAvailable: boolean; - allowedModules: { - builtIn?: string; - external?: string; - }; - enterprise: { - sharing: boolean; - ldap: boolean; - saml: boolean; - logStreaming: boolean; - advancedExecutionFilters: boolean; - variables: boolean; - versionControl: boolean; - }; - hideUsagePage: boolean; - license: { - environment: 'production' | 'staging'; - }; - variables: { - limit: number; - }; -} - export interface IPersonalizationSurveyAnswers { email: string | null; codingSkill: string | null; @@ -570,23 +483,9 @@ export interface IUserSettings { userActivated?: boolean; } -export interface IUserManagementSettings { - enabled: boolean; - showSetupOnFirstLoad?: boolean; - smtpSetup: boolean; - authenticationMethod: AuthenticationMethod; -} export interface IActiveDirectorySettings { enabled: boolean; } -export interface IPublicApiSettings { - enabled: boolean; - latestVersion: number; - path: string; - swaggerUi: { - enabled: boolean; - }; -} export interface IPackageVersions { cli: string; diff --git a/packages/cli/src/Server.ts b/packages/cli/src/Server.ts index 49320cfbc2..c6ae91e280 100644 --- a/packages/cli/src/Server.ts +++ b/packages/cli/src/Server.ts @@ -49,6 +49,7 @@ import type { ICredentialTypes, ExecutionStatus, IExecutionsSummary, + IN8nUISettings, } from 'n8n-workflow'; import { LoggerProxy, jsonParse } from 'n8n-workflow'; @@ -112,7 +113,6 @@ import type { IDiagnosticInfo, IExecutionFlattedDb, IExecutionsStopData, - IN8nUISettings, } from '@/Interfaces'; import { ActiveExecutions } from '@/ActiveExecutions'; import { @@ -313,8 +313,8 @@ class Server extends AbstractServer { }, isNpmAvailable: false, allowedModules: { - builtIn: process.env.NODE_FUNCTION_ALLOW_BUILTIN, - external: process.env.NODE_FUNCTION_ALLOW_EXTERNAL, + builtIn: process.env.NODE_FUNCTION_ALLOW_BUILTIN?.split(',') ?? undefined, + external: process.env.NODE_FUNCTION_ALLOW_EXTERNAL?.split(',') ?? undefined, }, enterprise: { sharing: false, diff --git a/packages/editor-ui/src/Interface.ts b/packages/editor-ui/src/Interface.ts index 84b072f545..9edcf0e76a 100644 --- a/packages/editor-ui/src/Interface.ts +++ b/packages/editor-ui/src/Interface.ts @@ -17,7 +17,6 @@ import { IRun, IRunData, ITaskData, - ITelemetrySettings, IWorkflowSettings as IWorkflowSettingsWorkflow, WorkflowExecuteMode, PublicInstalledPackage, @@ -33,6 +32,9 @@ import { FeatureFlags, ExecutionStatus, ITelemetryTrackProperties, + IN8nUISettings, + IUserManagementSettings, + WorkflowSettings, } from 'n8n-workflow'; import { SignInType } from './constants'; import { FAKE_DOOR_FEATURES, TRIGGER_NODE_FILTER, REGULAR_NODE_FILTER } from './constants'; @@ -641,13 +643,6 @@ export const enum UserManagementAuthenticationMethod { Saml = 'saml', } -export interface IUserManagementConfig { - enabled: boolean; - showSetupOnFirstLoad?: boolean; - smtpSetup: boolean; - authenticationMethod: UserManagementAuthenticationMethod; -} - export interface IPermissionGroup { loginStatus?: ILogInStatus[]; role?: IRole[]; @@ -732,94 +727,14 @@ export interface ITemplatesCategory { export type WorkflowCallerPolicyDefaultOption = 'any' | 'none' | 'workflowsFromAList'; -export interface IN8nUISettings { - endpointWebhook: string; - endpointWebhookTest: string; - saveDataErrorExecution: string; - saveDataSuccessExecution: string; - saveManualExecutions: boolean; - workflowCallerPolicyDefaultOption: WorkflowCallerPolicyDefaultOption; - timezone: string; - executionTimeout: number; - maxExecutionTimeout: number; - oauthCallbackUrls: { - oauth1: string; - oauth2: string; - }; - urlBaseEditor: string; - urlBaseWebhook: string; - versionCli: string; - n8nMetadata?: { - [key: string]: string | number | undefined; - }; - versionNotifications: IVersionNotificationSettings; - instanceId: string; - personalizationSurveyEnabled: boolean; - userActivationSurveyEnabled: boolean; - telemetry: ITelemetrySettings; - userManagement: IUserManagementConfig; - defaultLocale: string; - workflowTagsDisabled: boolean; - logLevel: ILogLevel; - hiringBannerEnabled: boolean; - templates: { - enabled: boolean; - host: string; - }; - posthog: { - enabled: boolean; - apiHost: string; - apiKey: string; - autocapture: boolean; - disableSessionRecording: boolean; - debug: boolean; - }; - executionMode: string; - pushBackend: 'sse' | 'websocket'; - communityNodesEnabled: boolean; - isNpmAvailable: boolean; - publicApi: { - enabled: boolean; - latestVersion: number; - path: string; - swaggerUi: { - enabled: boolean; - }; - }; - sso: { - saml: { - loginLabel: string; - loginEnabled: boolean; - }; - ldap: { - loginLabel: string; - loginEnabled: boolean; - }; - }; - onboardingCallPromptEnabled: boolean; - allowedModules: { - builtIn?: string[]; - external?: string[]; - }; - enterprise: Record; - deployment?: { - type: string | 'default' | 'n8n-internal' | 'cloud' | 'desktop_mac' | 'desktop_win'; - }; - hideUsagePage: boolean; - license: { - environment: 'development' | 'production'; - }; -} - export interface IWorkflowSettings extends IWorkflowSettingsWorkflow { errorWorkflow?: string; - saveDataErrorExecution?: string; - saveDataSuccessExecution?: string; saveManualExecutions?: boolean; timezone?: string; executionTimeout?: number; + maxExecutionTimeout?: number; callerIds?: string; - callerPolicy?: WorkflowCallerPolicyDefaultOption; + callerPolicy?: WorkflowSettings.CallerPolicy; } export interface ITimeoutHMS { @@ -1177,9 +1092,6 @@ export interface UIState { addFirstStepOnLoad: boolean; executionSidebarAutoRefresh: boolean; } - -export type ILogLevel = 'info' | 'debug' | 'warn' | 'error' | 'verbose'; - export type IFakeDoor = { id: FAKE_DOOR_FEATURES; featureName: string; @@ -1221,7 +1133,7 @@ export interface INodeCreatorState { export interface ISettingsState { settings: IN8nUISettings; promptsData: IN8nPrompts; - userManagement: IUserManagementConfig; + userManagement: IUserManagementSettings; templatesEndpointHealthy: boolean; api: { enabled: boolean; diff --git a/packages/editor-ui/src/__tests__/server/endpoints/settings.ts b/packages/editor-ui/src/__tests__/server/endpoints/settings.ts index 374e548d88..e2b5b4e0eb 100644 --- a/packages/editor-ui/src/__tests__/server/endpoints/settings.ts +++ b/packages/editor-ui/src/__tests__/server/endpoints/settings.ts @@ -1,6 +1,6 @@ import { Response, Server } from 'miragejs'; import { AppSchema } from '../types'; -import { IN8nUISettings, ISettingsState } from '@/Interface'; +import { IN8nUISettings } from 'n8n-workflow'; const defaultSettings: IN8nUISettings = { allowedModules: {}, @@ -9,9 +9,15 @@ const defaultSettings: IN8nUISettings = { endpointWebhook: '', endpointWebhookTest: '', enterprise: { + sharing: false, + ldap: false, + saml: false, + logStreaming: false, + advancedExecutionFilters: false, variables: true, + versionControl: false, }, - executionMode: '', + executionMode: 'regular', executionTimeout: 0, hideUsagePage: false, hiringBannerEnabled: false, @@ -33,8 +39,8 @@ const defaultSettings: IN8nUISettings = { }, publicApi: { enabled: false, latestVersion: 0, path: '', swaggerUi: { enabled: false } }, pushBackend: 'websocket', - saveDataErrorExecution: '', - saveDataSuccessExecution: '', + saveDataErrorExecution: 'DEFAULT', + saveDataSuccessExecution: 'DEFAULT', saveManualExecutions: false, sso: { ldap: { loginEnabled: false, loginLabel: '' }, @@ -51,6 +57,7 @@ const defaultSettings: IN8nUISettings = { enabled: true, showSetupOnFirstLoad: true, smtpSetup: true, + authenticationMethod: 'email', }, versionCli: '', versionNotifications: { @@ -60,6 +67,13 @@ const defaultSettings: IN8nUISettings = { }, workflowCallerPolicyDefaultOption: 'any', workflowTagsDisabled: false, + variables: { + limit: -1, + }, + userActivationSurveyEnabled: false, + deployment: { + type: 'default', + }, }; export function routesForSettings(server: Server) { diff --git a/packages/editor-ui/src/api/settings.ts b/packages/editor-ui/src/api/settings.ts index 9bd87f28f7..2205994b7e 100644 --- a/packages/editor-ui/src/api/settings.ts +++ b/packages/editor-ui/src/api/settings.ts @@ -2,11 +2,11 @@ import { IRestApiContext, IN8nPrompts, IN8nValueSurveyData, - IN8nUISettings, IN8nPromptResponse, } from '../Interface'; import { makeRestApiRequest, get, post } from '@/utils'; import { N8N_IO_BASE_URL, NPM_COMMUNITY_NODE_SEARCH_API_URL } from '@/constants'; +import { IN8nUISettings } from 'n8n-workflow'; export function getSettings(context: IRestApiContext): Promise { return makeRestApiRequest(context, 'GET', '/settings'); diff --git a/packages/editor-ui/src/components/WorkflowSettings.vue b/packages/editor-ui/src/components/WorkflowSettings.vue index 04a4c0f0ae..44155cd3dc 100644 --- a/packages/editor-ui/src/components/WorkflowSettings.vue +++ b/packages/editor-ui/src/components/WorkflowSettings.vue @@ -348,7 +348,7 @@ import { import mixins from 'vue-typed-mixins'; -import { deepCopy } from 'n8n-workflow'; +import { WorkflowSettings, deepCopy } from 'n8n-workflow'; import { mapStores } from 'pinia'; import { useWorkflowsStore } from '@/stores/workflows'; import { useSettingsStore } from '@/stores/settings'; @@ -504,7 +504,7 @@ export default mixins(externalHooks, genericHelpers, restApi, showMessage).exten } if (workflowSettings.callerPolicy === undefined) { workflowSettings.callerPolicy = this.defaultValues - .workflowCallerPolicy as WorkflowCallerPolicyDefaultOption; + .workflowCallerPolicy as WorkflowSettings.CallerPolicy; } if (workflowSettings.executionTimeout === undefined) { workflowSettings.executionTimeout = this.rootStore.executionTimeout; diff --git a/packages/editor-ui/src/stores/__tests__/posthog.test.ts b/packages/editor-ui/src/stores/__tests__/posthog.test.ts index ed31f1a252..dbc870fc09 100644 --- a/packages/editor-ui/src/stores/__tests__/posthog.test.ts +++ b/packages/editor-ui/src/stores/__tests__/posthog.test.ts @@ -2,9 +2,9 @@ import { createPinia, setActivePinia } from 'pinia'; import { usePostHog } from '@/stores/posthog'; import { useUsersStore } from '@/stores/users'; import { useSettingsStore } from '@/stores/settings'; -import { IN8nUISettings } from '@/Interface'; import { useRootStore } from '@/stores/n8nRootStore'; import { useTelemetryStore } from '@/stores/telemetry'; +import { IN8nUISettings } from 'n8n-workflow'; const DEFAULT_POSTHOG_SETTINGS: IN8nUISettings['posthog'] = { enabled: true, diff --git a/packages/editor-ui/src/stores/__tests__/sso.test.ts b/packages/editor-ui/src/stores/__tests__/sso.test.ts index eea1d3684e..1e2f0b437b 100644 --- a/packages/editor-ui/src/stores/__tests__/sso.test.ts +++ b/packages/editor-ui/src/stores/__tests__/sso.test.ts @@ -2,8 +2,8 @@ import { createPinia, setActivePinia } from 'pinia'; import { useSettingsStore } from '@/stores/settings'; import { useSSOStore } from '@/stores/sso'; import { merge } from 'lodash-es'; -import { IN8nUISettings } from '@/Interface'; import { SETTINGS_STORE_DEFAULT_STATE } from '@/__tests__/utils'; +import { IN8nUISettings } from 'n8n-workflow'; let ssoStore: ReturnType; let settingsStore: ReturnType; diff --git a/packages/editor-ui/src/stores/settings.ts b/packages/editor-ui/src/stores/settings.ts index 24e48f5a1f..049ea61b59 100644 --- a/packages/editor-ui/src/stores/settings.ts +++ b/packages/editor-ui/src/stores/settings.ts @@ -16,16 +16,19 @@ import { } from '@/constants'; import { ILdapConfig, - ILogLevel, IN8nPromptResponse, IN8nPrompts, - IN8nUISettings, IN8nValueSurveyData, ISettingsState, UserManagementAuthenticationMethod, - WorkflowCallerPolicyDefaultOption, } from '@/Interface'; -import { IDataObject, ITelemetrySettings } from 'n8n-workflow'; +import { + IDataObject, + ILogLevel, + IN8nUISettings, + ITelemetrySettings, + WorkflowSettings, +} from 'n8n-workflow'; import { defineStore } from 'pinia'; import Vue from 'vue'; import { useRootStore } from './n8nRootStore'; @@ -175,7 +178,7 @@ export const useSettingsStore = defineStore(STORES.SETTINGS, { isQueueModeEnabled(): boolean { return this.settings.executionMode === 'queue'; }, - workflowCallerPolicyDefaultOption(): WorkflowCallerPolicyDefaultOption { + workflowCallerPolicyDefaultOption(): WorkflowSettings.CallerPolicy { return this.settings.workflowCallerPolicyDefaultOption; }, isDefaultAuthenticationSaml(): boolean { diff --git a/packages/editor-ui/src/utils/__tests__/userUtils.test.ts b/packages/editor-ui/src/utils/__tests__/userUtils.test.ts index 0a9f98e64d..fbebefc4b4 100644 --- a/packages/editor-ui/src/utils/__tests__/userUtils.test.ts +++ b/packages/editor-ui/src/utils/__tests__/userUtils.test.ts @@ -4,10 +4,11 @@ import { merge } from 'lodash-es'; import { isAuthorized } from '@/utils'; import { useSettingsStore } from '@/stores/settings'; import { useSSOStore } from '@/stores/sso'; -import { IN8nUISettings, IUser } from '@/Interface'; +import { IUser } from '@/Interface'; import { routes } from '@/router'; import { VIEWS } from '@/constants'; import { SETTINGS_STORE_DEFAULT_STATE } from '@/__tests__/utils'; +import { IN8nUISettings } from 'n8n-workflow'; const DEFAULT_SETTINGS: IN8nUISettings = SETTINGS_STORE_DEFAULT_STATE.settings; diff --git a/packages/workflow/src/Interfaces.ts b/packages/workflow/src/Interfaces.ts index e3eccd8a0d..bfc40f0ac8 100644 --- a/packages/workflow/src/Interfaces.ts +++ b/packages/workflow/src/Interfaces.ts @@ -17,6 +17,7 @@ import type { NodeApiError, NodeOperationError } from './NodeErrors'; import type { ExpressionError } from './ExpressionError'; import type { PathLike } from 'fs'; import type { ExecutionStatus } from './ExecutionStatus'; +import type { AuthenticationMethod } from './Authentication'; export interface IAdditionalCredentialOptions { oauth2?: IOAuth2Options; @@ -385,7 +386,6 @@ export interface IDataObject { [key: string]: GenericValue | IDataObject | GenericValue[] | IDataObject[]; } -// export type IExecuteResponsePromiseData = IDataObject; export type IExecuteResponsePromiseData = IDataObject | IN8nHttpFullResponse; export interface INodeTypeNameVersion { @@ -1948,3 +1948,111 @@ export interface ExecutionFilters { waitTill?: boolean; workflowId?: number | string; } + +export interface IVersionNotificationSettings { + enabled: boolean; + endpoint: string; + infoUrl: string; +} + +export interface IUserManagementSettings { + enabled: boolean; + showSetupOnFirstLoad?: boolean; + smtpSetup: boolean; + authenticationMethod: AuthenticationMethod; +} + +export interface IPublicApiSettings { + enabled: boolean; + latestVersion: number; + path: string; + swaggerUi: { + enabled: boolean; + }; +} + +export type ILogLevel = 'info' | 'debug' | 'warn' | 'error' | 'verbose' | 'silent'; + +export interface IN8nUISettings { + endpointWebhook: string; + endpointWebhookTest: string; + saveDataErrorExecution: WorkflowSettings.SaveDataExecution; + saveDataSuccessExecution: WorkflowSettings.SaveDataExecution; + saveManualExecutions: boolean; + executionTimeout: number; + maxExecutionTimeout: number; + workflowCallerPolicyDefaultOption: WorkflowSettings.CallerPolicy; + oauthCallbackUrls: { + oauth1: string; + oauth2: string; + }; + timezone: string; + urlBaseWebhook: string; + urlBaseEditor: string; + versionCli: string; + n8nMetadata?: { + [key: string]: string | number | undefined; + }; + versionNotifications: IVersionNotificationSettings; + instanceId: string; + telemetry: ITelemetrySettings; + posthog: { + enabled: boolean; + apiHost: string; + apiKey: string; + autocapture: boolean; + disableSessionRecording: boolean; + debug: boolean; + }; + personalizationSurveyEnabled: boolean; + userActivationSurveyEnabled: boolean; + defaultLocale: string; + userManagement: IUserManagementSettings; + sso: { + saml: { + loginLabel: string; + loginEnabled: boolean; + }; + ldap: { + loginLabel: string; + loginEnabled: boolean; + }; + }; + publicApi: IPublicApiSettings; + workflowTagsDisabled: boolean; + logLevel: ILogLevel; + hiringBannerEnabled: boolean; + templates: { + enabled: boolean; + host: string; + }; + onboardingCallPromptEnabled: boolean; + missingPackages?: boolean; + executionMode: 'regular' | 'queue'; + pushBackend: 'sse' | 'websocket'; + communityNodesEnabled: boolean; + deployment: { + type: string | 'default' | 'n8n-internal' | 'cloud' | 'desktop_mac' | 'desktop_win'; + }; + isNpmAvailable: boolean; + allowedModules: { + builtIn?: string[]; + external?: string[]; + }; + enterprise: { + sharing: boolean; + ldap: boolean; + saml: boolean; + logStreaming: boolean; + advancedExecutionFilters: boolean; + variables: boolean; + versionControl: boolean; + }; + hideUsagePage: boolean; + license: { + environment: 'development' | 'production' | 'staging'; + }; + variables: { + limit: number; + }; +}