Skip to content

Commit

Permalink
refactor(core): Move frontend settings to @n8n/api-types (no-changelo…
Browse files Browse the repository at this point in the history
…g) (#10856)
  • Loading branch information
netroy authored Sep 17, 2024
1 parent 3c15890 commit 430c14a
Show file tree
Hide file tree
Showing 24 changed files with 223 additions and 235 deletions.
1 change: 1 addition & 0 deletions cypress/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"start": "cd ..; pnpm start"
},
"devDependencies": {
"@n8n/api-types": "workspace:*",
"@types/lodash": "catalog:",
"eslint-plugin-cypress": "^3.3.0",
"n8n-workflow": "workspace:*"
Expand Down
6 changes: 3 additions & 3 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'cypress-real-events';
import FakeTimers from '@sinonjs/fake-timers';
import type { IN8nUISettings } from 'n8n-workflow';
import type { FrontendSettings } from '@n8n/api-types';
import { WorkflowPage } from '../pages';
import {
BACKEND_BASE_URL,
Expand Down Expand Up @@ -86,8 +86,8 @@ Cypress.Commands.add('signout', () => {
cy.getCookie(N8N_AUTH_COOKIE).should('not.exist');
});

export let settings: Partial<IN8nUISettings>;
Cypress.Commands.add('overrideSettings', (value: Partial<IN8nUISettings>) => {
export let settings: Partial<FrontendSettings>;
Cypress.Commands.add('overrideSettings', (value: Partial<FrontendSettings>) => {
settings = value;
});

Expand Down
4 changes: 2 additions & 2 deletions cypress/support/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Load type definitions that come with Cypress module
/// <reference types="cypress" />

import type { IN8nUISettings } from 'n8n-workflow';
import type { FrontendSettings } from '@n8n/api-types';

Cypress.Keyboard.defaults({
keystrokeDelay: 0,
Expand Down Expand Up @@ -45,7 +45,7 @@ declare global {
*/
signinAsMember(index?: number): void;
signout(): void;
overrideSettings(value: Partial<IN8nUISettings>): void;
overrideSettings(value: Partial<FrontendSettings>): void;
enableFeature(feature: string): void;
disableFeature(feature: string): void;
enableQueueMode(): void;
Expand Down
172 changes: 172 additions & 0 deletions packages/@n8n/api-types/src/frontend-settings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
import type { ExpressionEvaluatorType, LogLevel, WorkflowSettings } from 'n8n-workflow';

export interface IVersionNotificationSettings {
enabled: boolean;
endpoint: string;
infoUrl: string;
}

export interface ITelemetryClientConfig {
url: string;
key: string;
}

export interface ITelemetrySettings {
enabled: boolean;
config?: ITelemetryClientConfig;
}

export type AuthenticationMethod = 'email' | 'ldap' | 'saml';

export interface IUserManagementSettings {
quota: number;
showSetupOnFirstLoad?: boolean;
smtpSetup: boolean;
authenticationMethod: AuthenticationMethod;
}

export interface FrontendSettings {
isDocker?: boolean;
databaseType: 'sqlite' | 'mariadb' | 'mysqldb' | 'postgresdb';
endpointForm: string;
endpointFormTest: string;
endpointFormWaiting: string;
endpointWebhook: string;
endpointWebhookTest: string;
saveDataErrorExecution: WorkflowSettings.SaveDataExecution;
saveDataSuccessExecution: WorkflowSettings.SaveDataExecution;
saveManualExecutions: boolean;
saveExecutionProgress: boolean;
executionTimeout: number;
maxExecutionTimeout: number;
workflowCallerPolicyDefaultOption: WorkflowSettings.CallerPolicy;
oauthCallbackUrls: {
oauth1: string;
oauth2: string;
};
timezone: string;
urlBaseWebhook: string;
urlBaseEditor: string;
versionCli: string;
nodeJsVersion: string;
concurrency: number;
authCookie: {
secure: boolean;
};
binaryDataMode: 'default' | 'filesystem' | 's3';
releaseChannel: 'stable' | 'beta' | 'nightly' | 'dev';
n8nMetadata?: {
userId?: string;
[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;
defaultLocale: string;
userManagement: IUserManagementSettings;
sso: {
saml: {
loginLabel: string;
loginEnabled: boolean;
};
ldap: {
loginLabel: string;
loginEnabled: boolean;
};
};
publicApi: {
enabled: boolean;
latestVersion: number;
path: string;
swaggerUi: {
enabled: boolean;
};
};
workflowTagsDisabled: boolean;
logLevel: LogLevel;
hiringBannerEnabled: boolean;
previewMode: boolean;
templates: {
enabled: boolean;
host: string;
};
missingPackages?: boolean;
executionMode: 'regular' | 'queue';
pushBackend: 'sse' | 'websocket';
communityNodesEnabled: boolean;
aiAssistant: {
enabled: boolean;
};
deployment: {
type: string;
};
isNpmAvailable: boolean;
allowedModules: {
builtIn?: string[];
external?: string[];
};
enterprise: {
sharing: boolean;
ldap: boolean;
saml: boolean;
logStreaming: boolean;
advancedExecutionFilters: boolean;
variables: boolean;
sourceControl: boolean;
auditLogs: boolean;
externalSecrets: boolean;
showNonProdBanner: boolean;
debugInEditor: boolean;
binaryDataS3: boolean;
workflowHistory: boolean;
workerView: boolean;
advancedPermissions: boolean;
projects: {
team: {
limit: number;
};
};
};
hideUsagePage: boolean;
license: {
planName?: string;
consumerId: string;
environment: 'development' | 'production' | 'staging';
};
variables: {
limit: number;
};
expressions: {
evaluator: ExpressionEvaluatorType;
};
mfa: {
enabled: boolean;
};
banners: {
dismissed: string[];
};
ai: {
enabled: boolean;
};
workflowHistory: {
pruneTime: number;
licensePruneTime: number;
};
pruning: {
isEnabled: boolean;
maxAge: number;
maxCount: number;
};
security: {
blockFileAccessToN8nFiles: boolean;
};
}
3 changes: 2 additions & 1 deletion packages/@n8n/api-types/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export type * from './datetime';
export type * from './push';
export type * from './scaling';
export type * from './datetime';
export type * from './frontend-settings';
export type * from './user';

export type { Collaborator } from './push/collaboration';
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/events/relay-event-map.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { AuthenticationMethod } from '@n8n/api-types';
import type {
AuthenticationMethod,
IPersonalizationSurveyAnswersV4,
IRun,
IWorkflowBase,
Expand Down
6 changes: 0 additions & 6 deletions packages/cli/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,6 @@ export interface IExternalHooksFunctions {
};
}

export interface IVersionNotificationSettings {
enabled: boolean;
endpoint: string;
infoUrl: string;
}

export interface IPersonalizationSurveyAnswers {
email: string | null;
codingSkill: string | null;
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { FrontendSettings } from '@n8n/api-types';
import { exec as callbackExec } from 'child_process';
import cookieParser from 'cookie-parser';
import express from 'express';
import { access as fsAccess } from 'fs/promises';
import helmet from 'helmet';
import { InstanceSettings } from 'n8n-core';
import type { IN8nUISettings } from 'n8n-workflow';
import { resolve } from 'path';
import { Container, Service } from 'typedi';
import { promisify } from 'util';
Expand Down Expand Up @@ -252,7 +252,7 @@ export class Server extends AbstractServer {
this.app.get(
`/${this.restEndpoint}/settings`,
ResponseHelper.send(
async (req: express.Request): Promise<IN8nUISettings> =>
async (req: express.Request): Promise<FrontendSettings> =>
frontendService.getSettings(req.headers['push-ref'] as string),
),
);
Expand Down
12 changes: 4 additions & 8 deletions packages/cli/src/services/frontend.service.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import type { FrontendSettings, ITelemetrySettings } from '@n8n/api-types';
import { GlobalConfig } from '@n8n/config';
import { createWriteStream } from 'fs';
import { mkdir } from 'fs/promises';
import uniq from 'lodash/uniq';
import { InstanceSettings } from 'n8n-core';
import type {
ICredentialType,
IN8nUISettings,
INodeTypeBaseDescription,
ITelemetrySettings,
} from 'n8n-workflow';
import type { ICredentialType, INodeTypeBaseDescription } from 'n8n-workflow';
import fs from 'node:fs';
import path from 'path';
import { Container, Service } from 'typedi';
Expand Down Expand Up @@ -37,7 +33,7 @@ import { UrlService } from './url.service';

@Service()
export class FrontendService {
settings: IN8nUISettings;
settings: FrontendSettings;

private communityPackagesService?: CommunityPackagesService;

Expand Down Expand Up @@ -247,7 +243,7 @@ export class FrontendService {
this.writeStaticJSON('credentials', credentials);
}

getSettings(pushRef?: string): IN8nUISettings {
getSettings(pushRef?: string): FrontendSettings {
this.eventService.emit('session-started', { pushRef });

const restEndpoint = this.globalConfig.endpoints.rest;
Expand Down
19 changes: 8 additions & 11 deletions packages/editor-ui/src/Interface.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import type { Component } from 'vue';
import type { NotificationOptions as ElementNotificationOptions } from 'element-plus';
import type { Connection } from '@jsplumb/core';
import type { Iso8601DateTimeString } from '@n8n/api-types';
import type {
FrontendSettings,
Iso8601DateTimeString,
IUserManagementSettings,
IVersionNotificationSettings,
} from '@n8n/api-types';
import type { Scope } from '@n8n/permissions';
import type { IMenuItem, NodeCreatorTag } from 'n8n-design-system';
import type {
Expand Down Expand Up @@ -31,10 +36,8 @@ import type {
FeatureFlags,
ExecutionStatus,
ITelemetryTrackProperties,
IUserManagementSettings,
WorkflowSettings,
IUserSettings,
IN8nUISettings,
BannerName,
INodeExecutionData,
INodeProperties,
Expand Down Expand Up @@ -496,12 +499,6 @@ export interface IUser extends IUserResponse {
mfaEnabled: boolean;
}

export interface IVersionNotificationSettings {
enabled: boolean;
endpoint: string;
infoUrl: string;
}

export interface IUserListAction {
label: string;
value: string;
Expand Down Expand Up @@ -1090,7 +1087,7 @@ export interface INodeCreatorState {

export interface ISettingsState {
initialized: boolean;
settings: IN8nUISettings;
settings: FrontendSettings;
userManagement: IUserManagementSettings;
templatesEndpointHealthy: boolean;
api: {
Expand Down Expand Up @@ -1643,7 +1640,7 @@ export type EnterpriseEditionFeatureKey =
| 'WorkerView'
| 'AdvancedPermissions';

export type EnterpriseEditionFeatureValue = keyof Omit<IN8nUISettings['enterprise'], 'projects'>;
export type EnterpriseEditionFeatureValue = keyof Omit<FrontendSettings['enterprise'], 'projects'>;

export interface IN8nPromptResponse {
updated: boolean;
Expand Down
4 changes: 2 additions & 2 deletions packages/editor-ui/src/__tests__/defaults.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { IN8nUISettings } from 'n8n-workflow';
import type { FrontendSettings } from '@n8n/api-types';

export const defaultSettings: IN8nUISettings = {
export const defaultSettings: FrontendSettings = {
databaseType: 'sqlite',
isDocker: false,
pruning: {
Expand Down
4 changes: 2 additions & 2 deletions packages/editor-ui/src/api/settings.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { IRestApiContext, IN8nPrompts, IN8nPromptResponse } from '../Interface';
import { makeRestApiRequest, get, post } from '@/utils/apiUtils';
import { N8N_IO_BASE_URL, NPM_COMMUNITY_NODE_SEARCH_API_URL } from '@/constants';
import type { IN8nUISettings } from 'n8n-workflow';
import type { FrontendSettings } from '@n8n/api-types';

export async function getSettings(context: IRestApiContext): Promise<IN8nUISettings> {
export async function getSettings(context: IRestApiContext): Promise<FrontendSettings> {
return await makeRestApiRequest(context, 'GET', '/settings');
}

Expand Down
2 changes: 1 addition & 1 deletion packages/editor-ui/src/components/Telemetry.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<script lang="ts" setup>
import type { ITelemetrySettings } from '@n8n/api-types';
import { useRootStore } from '@/stores/root.store';
import { useSettingsStore } from '@/stores/settings.store';
import { useUsersStore } from '@/stores/users.store';
import type { ITelemetrySettings } from 'n8n-workflow';
import { useProjectsStore } from '@/stores/projects.store';
import { computed, onMounted, watch, ref } from 'vue';
import { useTelemetry } from '@/composables/useTelemetry';
Expand Down
3 changes: 2 additions & 1 deletion packages/editor-ui/src/plugins/telemetry/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Plugin } from 'vue';
import type { ITelemetrySettings, ITelemetryTrackProperties, IDataObject } from 'n8n-workflow';
import type { ITelemetrySettings } from '@n8n/api-types';
import type { ITelemetryTrackProperties, IDataObject } from 'n8n-workflow';
import type { RouteLocation } from 'vue-router';

import type { INodeCreateElement, IUpdateInformation } from '@/Interface';
Expand Down
Loading

0 comments on commit 430c14a

Please sign in to comment.