From 07ed01d9fc4273f40a581e63dccdbebd1dc503c4 Mon Sep 17 00:00:00 2001 From: Alex Grozav Date: Tue, 10 Jun 2025 09:47:51 +0200 Subject: [PATCH] refactor(editor): Migrate `versions` api to `@n8n/rest-client-api` (no-changelog) (#16147) --- packages/@n8n/constants/src/index.ts | 7 +--- packages/@n8n/constants/src/instance.ts | 7 ++++ .../@n8n/rest-api-client/src/api/index.ts | 1 + .../@n8n/rest-api-client/src/api/versions.ts | 39 +++++++++++++++++++ packages/frontend/editor-ui/src/Interface.ts | 33 ++-------------- .../frontend/editor-ui/src/api/versions.ts | 12 ------ .../editor-ui/src/components/NodeIcon.vue | 5 ++- .../editor-ui/src/components/VersionCard.vue | 6 +-- packages/frontend/editor-ui/src/constants.ts | 3 -- .../editor-ui/src/stores/versions.store.ts | 10 ++--- .../frontend/editor-ui/src/utils/nodeIcon.ts | 4 +- 11 files changed, 65 insertions(+), 62 deletions(-) create mode 100644 packages/@n8n/constants/src/instance.ts create mode 100644 packages/frontend/@n8n/rest-api-client/src/api/versions.ts delete mode 100644 packages/frontend/editor-ui/src/api/versions.ts diff --git a/packages/@n8n/constants/src/index.ts b/packages/@n8n/constants/src/index.ts index 6b8ede8435..d419e3846d 100644 --- a/packages/@n8n/constants/src/index.ts +++ b/packages/@n8n/constants/src/index.ts @@ -1,4 +1,5 @@ export * from './browser'; +export * from './instance'; export const LICENSE_FEATURES = { SHARING: 'feat:sharing', @@ -96,9 +97,3 @@ export const LDAP_DEFAULT_CONFIGURATION: LdapConfig = { searchPageSize: 0, searchTimeout: 60, }; - -export const INSTANCE_TYPES = ['main', 'webhook', 'worker'] as const; -export type InstanceType = (typeof INSTANCE_TYPES)[number]; - -export const INSTANCE_ROLES = ['unset', 'leader', 'follower'] as const; -export type InstanceRole = (typeof INSTANCE_ROLES)[number]; diff --git a/packages/@n8n/constants/src/instance.ts b/packages/@n8n/constants/src/instance.ts new file mode 100644 index 0000000000..df4cbf6357 --- /dev/null +++ b/packages/@n8n/constants/src/instance.ts @@ -0,0 +1,7 @@ +export const INSTANCE_ID_HEADER = 'n8n-instance-id'; + +export const INSTANCE_TYPES = ['main', 'webhook', 'worker'] as const; +export type InstanceType = (typeof INSTANCE_TYPES)[number]; + +export const INSTANCE_ROLES = ['unset', 'leader', 'follower'] as const; +export type InstanceRole = (typeof INSTANCE_ROLES)[number]; diff --git a/packages/frontend/@n8n/rest-api-client/src/api/index.ts b/packages/frontend/@n8n/rest-api-client/src/api/index.ts index 35d7e7d22c..17b55a35cc 100644 --- a/packages/frontend/@n8n/rest-api-client/src/api/index.ts +++ b/packages/frontend/@n8n/rest-api-client/src/api/index.ts @@ -10,4 +10,5 @@ export * from './orchestration'; export * from './roles'; export * from './sso'; export * from './ui'; +export * from './versions'; export * from './webhooks'; diff --git a/packages/frontend/@n8n/rest-api-client/src/api/versions.ts b/packages/frontend/@n8n/rest-api-client/src/api/versions.ts new file mode 100644 index 0000000000..88f5aebeac --- /dev/null +++ b/packages/frontend/@n8n/rest-api-client/src/api/versions.ts @@ -0,0 +1,39 @@ +import { INSTANCE_ID_HEADER } from '@n8n/constants'; +import type { INodeParameters } from 'n8n-workflow'; + +import { get } from '../utils'; + +export interface VersionNode { + name: string; + displayName: string; + icon: string; + iconUrl?: string; + defaults: INodeParameters; + iconData: { + type: string; + icon?: string; + fileBuffer?: string; + }; + typeVersion?: number; +} + +export interface Version { + name: string; + nodes: VersionNode[]; + createdAt: string; + description: string; + documentationUrl: string; + hasBreakingChange: boolean; + hasSecurityFix: boolean; + hasSecurityIssue: boolean; + securityIssueFixVersion: string; +} + +export async function getNextVersions( + endpoint: string, + version: string, + instanceId: string, +): Promise { + const headers = { [INSTANCE_ID_HEADER as string]: instanceId }; + return await get(endpoint, version, {}, headers); +} diff --git a/packages/frontend/editor-ui/src/Interface.ts b/packages/frontend/editor-ui/src/Interface.ts index f98ec3141c..dd2629d2b8 100644 --- a/packages/frontend/editor-ui/src/Interface.ts +++ b/packages/frontend/editor-ui/src/Interface.ts @@ -45,6 +45,7 @@ import type { ITaskData, ISourceData, } from 'n8n-workflow'; +import type { Version, VersionNode } from '@n8n/rest-api-client/api/versions'; import type { AI_NODE_CREATOR_VIEW, @@ -900,33 +901,7 @@ export interface ITagRow { canDelete?: boolean; } -export interface IVersion { - name: string; - nodes: IVersionNode[]; - createdAt: string; - description: string; - documentationUrl: string; - hasBreakingChange: boolean; - hasSecurityFix: boolean; - hasSecurityIssue: boolean; - securityIssueFixVersion: string; -} - -export interface IVersionNode { - name: string; - displayName: string; - icon: string; - iconUrl?: string; - defaults: INodeParameters; - iconData: { - type: string; - icon?: string; - fileBuffer?: string; - }; - typeVersion?: number; -} - -export interface ITemplatesNode extends IVersionNode { +export interface ITemplatesNode extends VersionNode { id: number; categories?: ITemplatesCategory[]; } @@ -1164,8 +1139,8 @@ export interface ITemplateState { export interface IVersionsState { versionNotificationSettings: IVersionNotificationSettings; - nextVersions: IVersion[]; - currentVersion: IVersion | undefined; + nextVersions: Version[]; + currentVersion: Version | undefined; } export interface IWorkflowsMap { diff --git a/packages/frontend/editor-ui/src/api/versions.ts b/packages/frontend/editor-ui/src/api/versions.ts deleted file mode 100644 index da9a55b21c..0000000000 --- a/packages/frontend/editor-ui/src/api/versions.ts +++ /dev/null @@ -1,12 +0,0 @@ -import type { IVersion } from '@/Interface'; -import { INSTANCE_ID_HEADER } from '@/constants'; -import { get } from '@n8n/rest-api-client'; - -export async function getNextVersions( - endpoint: string, - version: string, - instanceId: string, -): Promise { - const headers = { [INSTANCE_ID_HEADER as string]: instanceId }; - return await get(endpoint, version, {}, headers); -} diff --git a/packages/frontend/editor-ui/src/components/NodeIcon.vue b/packages/frontend/editor-ui/src/components/NodeIcon.vue index 9a534d915c..dfb399f5c1 100644 --- a/packages/frontend/editor-ui/src/components/NodeIcon.vue +++ b/packages/frontend/editor-ui/src/components/NodeIcon.vue @@ -1,8 +1,9 @@ diff --git a/packages/frontend/editor-ui/src/constants.ts b/packages/frontend/editor-ui/src/constants.ts index 6d605bcb07..fa8c17d550 100644 --- a/packages/frontend/editor-ui/src/constants.ts +++ b/packages/frontend/editor-ui/src/constants.ts @@ -324,9 +324,6 @@ export const NODE_CONNECTION_TYPE_ALLOW_MULTIPLE: NodeConnectionType[] = [ NodeConnectionTypes.Main, ]; -// General -export const INSTANCE_ID_HEADER = 'n8n-instance-id'; - /** PERSONALIZATION SURVEY */ export const EMAIL_KEY = 'email'; export const WORK_AREA_KEY = 'workArea'; diff --git a/packages/frontend/editor-ui/src/stores/versions.store.ts b/packages/frontend/editor-ui/src/stores/versions.store.ts index 681f8e6eb7..d0b2ed870d 100644 --- a/packages/frontend/editor-ui/src/stores/versions.store.ts +++ b/packages/frontend/editor-ui/src/stores/versions.store.ts @@ -1,20 +1,20 @@ import type { IVersionNotificationSettings } from '@n8n/api-types'; -import * as versionsApi from '@/api/versions'; +import * as versionsApi from '@n8n/rest-api-client/api/versions'; import { VERSIONS_MODAL_KEY } from '@/constants'; import { STORES } from '@n8n/stores'; -import type { IVersion } from '@/Interface'; +import type { Version } from '@n8n/rest-api-client/api/versions'; import { defineStore } from 'pinia'; import { useRootStore } from '@n8n/stores/useRootStore'; import { useToast } from '@/composables/useToast'; import { useUIStore } from '@/stores/ui.store'; import { computed, ref } from 'vue'; -type SetVersionParams = { versions: IVersion[]; currentVersion: string }; +type SetVersionParams = { versions: Version[]; currentVersion: string }; export const useVersionsStore = defineStore(STORES.VERSIONS, () => { const versionNotificationSettings = ref({ enabled: false, endpoint: '', infoUrl: '' }); - const nextVersions = ref([]); - const currentVersion = ref(); + const nextVersions = ref([]); + const currentVersion = ref(); const { showToast } = useToast(); const uiStore = useUIStore(); diff --git a/packages/frontend/editor-ui/src/utils/nodeIcon.ts b/packages/frontend/editor-ui/src/utils/nodeIcon.ts index ac71543dc3..7fec0696f7 100644 --- a/packages/frontend/editor-ui/src/utils/nodeIcon.ts +++ b/packages/frontend/editor-ui/src/utils/nodeIcon.ts @@ -1,5 +1,5 @@ import { type INodeTypeDescription } from 'n8n-workflow'; -import type { IVersionNode } from '../Interface'; +import type { VersionNode } from '@n8n/rest-api-client/api/versions'; import { useRootStore } from '@n8n/stores/useRootStore'; import { useUIStore } from '../stores/ui.store'; import { getThemedValue } from './nodeTypesUtils'; @@ -20,7 +20,7 @@ type IconNodeTypeDescription = Pick< INodeTypeDescription, 'icon' | 'iconUrl' | 'iconColor' | 'defaults' | 'badgeIconUrl' | 'name' >; -type IconVersionNode = Pick; +type IconVersionNode = Pick; export type IconNodeType = IconNodeTypeDescription | IconVersionNode; export const getNodeIcon = (nodeType: IconNodeType): string | null => {