refactor(editor): Move settings api to @n8n/rest-api-client (no-changelog) (#16186)

This commit is contained in:
Alex Grozav
2025-06-11 09:57:59 +02:00
committed by GitHub
parent 5015290dbe
commit 2a3fa5088e
15 changed files with 70 additions and 62 deletions

View File

@@ -0,0 +1 @@
export const N8N_IO_BASE_URL = 'https://api.n8n.io/api/';

View File

@@ -0,0 +1 @@
export const NPM_COMMUNITY_NODE_SEARCH_API_URL = 'https://api.npms.io/v2/';

View File

@@ -1,4 +1,6 @@
export * from './api';
export * from './browser'; export * from './browser';
export * from './community-nodes';
export * from './instance'; export * from './instance';
export const LICENSE_FEATURES = { export const LICENSE_FEATURES = {

View File

@@ -1,3 +1,4 @@
import { NPM_COMMUNITY_NODE_SEARCH_API_URL } from '@n8n/constants';
import type { PublicInstalledPackage } from 'n8n-workflow'; import type { PublicInstalledPackage } from 'n8n-workflow';
import type { IRestApiContext } from '../types'; import type { IRestApiContext } from '../types';
@@ -29,3 +30,12 @@ export async function updatePackage(
): Promise<PublicInstalledPackage> { ): Promise<PublicInstalledPackage> {
return await makeRestApiRequest(context, 'PATCH', '/community-packages', { name }); return await makeRestApiRequest(context, 'PATCH', '/community-packages', { name });
} }
export async function getAvailableCommunityPackageCount(): Promise<number> {
const response = await get(
NPM_COMMUNITY_NODE_SEARCH_API_URL,
'search?q=keywords:n8n-community-node-package',
);
return response.total || 0;
}

View File

@@ -9,7 +9,9 @@ export * from './mfa';
export * from './nodeTypes'; export * from './nodeTypes';
export * from './npsSurvey'; export * from './npsSurvey';
export * from './orchestration'; export * from './orchestration';
export * from './prompts';
export * from './roles'; export * from './roles';
export * from './settings';
export * from './sso'; export * from './sso';
export * from './ui'; export * from './ui';
export * from './versions'; export * from './versions';

View File

@@ -0,0 +1,35 @@
import { N8N_IO_BASE_URL } from '@n8n/constants';
import { get, post } from '../utils';
export interface N8nPrompts {
message?: string;
title?: string;
showContactPrompt?: boolean;
}
export interface N8nPromptResponse {
updated: boolean;
}
export async function getPromptsData(instanceId: string, userId: string): Promise<N8nPrompts> {
return await get(
N8N_IO_BASE_URL,
'/prompts',
{},
{ 'n8n-instance-id': instanceId, 'n8n-user-id': userId },
);
}
export async function submitContactInfo(
instanceId: string,
userId: string,
email: string,
): Promise<N8nPromptResponse> {
return await post(
N8N_IO_BASE_URL,
'/prompt',
{ email },
{ 'n8n-instance-id': instanceId, 'n8n-user-id': userId },
);
}

View File

@@ -0,0 +1,8 @@
import type { FrontendSettings } from '@n8n/api-types';
import type { IRestApiContext } from '../types';
import { makeRestApiRequest } from '../utils';
export async function getSettings(context: IRestApiContext): Promise<FrontendSettings> {
return await makeRestApiRequest(context, 'GET', '/settings');
}

View File

@@ -605,12 +605,6 @@ export interface IUserListAction {
guard?: (user: IUser) => boolean; guard?: (user: IUser) => boolean;
} }
export interface IN8nPrompts {
message?: string;
title?: string;
showContactPrompt?: boolean;
}
export const enum UserManagementAuthenticationMethod { export const enum UserManagementAuthenticationMethod {
Email = 'email', Email = 'email',
Ldap = 'ldap', Ldap = 'ldap',
@@ -1433,10 +1427,6 @@ export type EnterpriseEditionFeatureKey =
export type EnterpriseEditionFeatureValue = keyof Omit<FrontendSettings['enterprise'], 'projects'>; export type EnterpriseEditionFeatureValue = keyof Omit<FrontendSettings['enterprise'], 'projects'>;
export interface IN8nPromptResponse {
updated: boolean;
}
export type InputPanel = { export type InputPanel = {
nodeName?: string; nodeName?: string;
run?: number; run?: number;

View File

@@ -1,40 +0,0 @@
import type { IN8nPrompts, IN8nPromptResponse } from '../Interface';
import type { IRestApiContext } from '@n8n/rest-api-client';
import { makeRestApiRequest, get, post } from '@n8n/rest-api-client';
import { N8N_IO_BASE_URL, NPM_COMMUNITY_NODE_SEARCH_API_URL } from '@/constants';
import type { FrontendSettings } from '@n8n/api-types';
export async function getSettings(context: IRestApiContext): Promise<FrontendSettings> {
return await makeRestApiRequest(context, 'GET', '/settings');
}
export async function getPromptsData(instanceId: string, userId: string): Promise<IN8nPrompts> {
return await get(
N8N_IO_BASE_URL,
'/prompts',
{},
{ 'n8n-instance-id': instanceId, 'n8n-user-id': userId },
);
}
export async function submitContactInfo(
instanceId: string,
userId: string,
email: string,
): Promise<IN8nPromptResponse> {
return await post(
N8N_IO_BASE_URL,
'/prompt',
{ email },
{ 'n8n-instance-id': instanceId, 'n8n-user-id': userId },
);
}
export async function getAvailableCommunityPackageCount(): Promise<number> {
const response = await get(
NPM_COMMUNITY_NODE_SEARCH_API_URL,
'search?q=keywords:n8n-community-node-package',
);
return response.total || 0;
}

View File

@@ -1,6 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { computed, ref } from 'vue'; import { computed, ref } from 'vue';
import type { IN8nPromptResponse, ModalKey } from '@/Interface'; import type { N8nPromptResponse } from '@n8n/rest-api-client/api/prompts';
import type { ModalKey } from '@/Interface';
import { VALID_EMAIL_REGEX } from '@/constants'; import { VALID_EMAIL_REGEX } from '@/constants';
import Modal from '@/components/Modal.vue'; import Modal from '@/components/Modal.vue';
import { useSettingsStore } from '@/stores/settings.store'; import { useSettingsStore } from '@/stores/settings.store';
@@ -55,7 +56,7 @@ const closeDialog = () => {
const send = async () => { const send = async () => {
if (isEmailValid.value) { if (isEmailValid.value) {
const response = (await settingsStore.submitContactInfo(email.value)) as IN8nPromptResponse; const response = (await settingsStore.submitContactInfo(email.value)) as N8nPromptResponse;
if (response.updated) { if (response.updated) {
telemetry.track('User closed email modal', { telemetry.track('User closed email modal', {

View File

@@ -96,7 +96,6 @@ export const BREAKPOINT_MD = 992;
export const BREAKPOINT_LG = 1200; export const BREAKPOINT_LG = 1200;
export const BREAKPOINT_XL = 1920; export const BREAKPOINT_XL = 1920;
export const N8N_IO_BASE_URL = 'https://api.n8n.io/api/';
export const DOCS_DOMAIN = 'docs.n8n.io'; export const DOCS_DOMAIN = 'docs.n8n.io';
export const BUILTIN_NODES_DOCS_URL = `https://${DOCS_DOMAIN}/integrations/builtin/`; export const BUILTIN_NODES_DOCS_URL = `https://${DOCS_DOMAIN}/integrations/builtin/`;
export const BUILTIN_CREDENTIALS_DOCS_URL = `https://${DOCS_DOMAIN}/integrations/builtin/credentials/`; export const BUILTIN_CREDENTIALS_DOCS_URL = `https://${DOCS_DOMAIN}/integrations/builtin/credentials/`;
@@ -104,7 +103,6 @@ export const DATA_PINNING_DOCS_URL = `https://${DOCS_DOMAIN}/data/data-pinning/`
export const DATA_EDITING_DOCS_URL = `https://${DOCS_DOMAIN}/data/data-editing/`; export const DATA_EDITING_DOCS_URL = `https://${DOCS_DOMAIN}/data/data-editing/`;
export const SCHEMA_PREVIEW_DOCS_URL = `https://${DOCS_DOMAIN}/data/schema-preview/`; export const SCHEMA_PREVIEW_DOCS_URL = `https://${DOCS_DOMAIN}/data/schema-preview/`;
export const MFA_DOCS_URL = `https://${DOCS_DOMAIN}/user-management/two-factor-auth/`; export const MFA_DOCS_URL = `https://${DOCS_DOMAIN}/user-management/two-factor-auth/`;
export const NPM_COMMUNITY_NODE_SEARCH_API_URL = 'https://api.npms.io/v2/';
export const NPM_PACKAGE_DOCS_BASE_URL = 'https://www.npmjs.com/package/'; export const NPM_PACKAGE_DOCS_BASE_URL = 'https://www.npmjs.com/package/';
export const NPM_KEYWORD_SEARCH_URL = export const NPM_KEYWORD_SEARCH_URL =
'https://www.npmjs.com/search?q=keywords%3An8n-community-node-package'; 'https://www.npmjs.com/search?q=keywords%3An8n-community-node-package';

View File

@@ -1,5 +1,4 @@
import * as communityNodesApi from '@n8n/rest-api-client/api/communityNodes'; import * as communityNodesApi from '@n8n/rest-api-client/api/communityNodes';
import { getAvailableCommunityPackageCount } from '@/api/settings';
import { defineStore } from 'pinia'; import { defineStore } from 'pinia';
import { useRootStore } from '@n8n/stores/useRootStore'; import { useRootStore } from '@n8n/stores/useRootStore';
import type { PublicInstalledPackage } from 'n8n-workflow'; import type { PublicInstalledPackage } from 'n8n-workflow';
@@ -29,7 +28,7 @@ export const useCommunityNodesStore = defineStore(STORES.COMMUNITY_NODES, () =>
const fetchAvailableCommunityPackageCount = async (): Promise<void> => { const fetchAvailableCommunityPackageCount = async (): Promise<void> => {
if (availablePackageCount.value === -1) { if (availablePackageCount.value === -1) {
availablePackageCount.value = await getAvailableCommunityPackageCount(); availablePackageCount.value = await communityNodesApi.getAvailableCommunityPackageCount();
} }
}; };

View File

@@ -12,8 +12,8 @@ import { useRootStore } from '@n8n/stores/useRootStore';
import type { IUserSettings, NpsSurveyState } from 'n8n-workflow'; import type { IUserSettings, NpsSurveyState } from 'n8n-workflow';
import { useSettingsStore } from './settings.store'; import { useSettingsStore } from './settings.store';
import { updateNpsSurveyState } from '@n8n/rest-api-client/api/npsSurvey'; import { updateNpsSurveyState } from '@n8n/rest-api-client/api/npsSurvey';
import type { IN8nPrompts } from '@/Interface'; import type { N8nPrompts } from '@n8n/rest-api-client/api/prompts';
import { getPromptsData } from '@/api/settings'; import { getPromptsData } from '@n8n/rest-api-client/api/prompts';
import { assert } from '@n8n/utils/assert'; import { assert } from '@n8n/utils/assert';
export const MAXIMUM_TIMES_TO_SHOW_SURVEY_IF_IGNORED = 3; export const MAXIMUM_TIMES_TO_SHOW_SURVEY_IF_IGNORED = 3;
@@ -26,7 +26,7 @@ export const useNpsSurveyStore = defineStore('npsSurvey', () => {
const shouldShowNpsSurveyNext = ref<boolean>(false); const shouldShowNpsSurveyNext = ref<boolean>(false);
const currentSurveyState = ref<NpsSurveyState | undefined>(); const currentSurveyState = ref<NpsSurveyState | undefined>();
const currentUserId = ref<string | undefined>(); const currentUserId = ref<string | undefined>();
const promptsData = ref<IN8nPrompts | undefined>(); const promptsData = ref<N8nPrompts | undefined>();
function setupNpsSurveyOnLogin(userId: string, settings?: IUserSettings): void { function setupNpsSurveyOnLogin(userId: string, settings?: IUserSettings): void {
currentUserId.value = userId; currentUserId.value = userId;

View File

@@ -13,7 +13,7 @@ const { sessionStarted } = vi.hoisted(() => ({
sessionStarted: vi.fn(), sessionStarted: vi.fn(),
})); }));
vi.mock('@/api/settings', () => ({ vi.mock('@n8n/rest-api-client/api/settings', () => ({
getSettings, getSettings,
})); }));

View File

@@ -4,7 +4,8 @@ import type { IUserManagementSettings, FrontendSettings } from '@n8n/api-types';
import * as eventsApi from '@n8n/rest-api-client/api/events'; import * as eventsApi from '@n8n/rest-api-client/api/events';
import * as ldapApi from '@n8n/rest-api-client/api/ldap'; import * as ldapApi from '@n8n/rest-api-client/api/ldap';
import * as settingsApi from '@/api/settings'; import * as settingsApi from '@n8n/rest-api-client/api/settings';
import * as promptsApi from '@n8n/rest-api-client/api/prompts';
import { testHealthEndpoint } from '@/api/templates'; import { testHealthEndpoint } from '@/api/templates';
import type { LdapConfig } from '@n8n/rest-api-client/api/ldap'; import type { LdapConfig } from '@n8n/rest-api-client/api/ldap';
import { import {
@@ -332,7 +333,7 @@ export const useSettingsStore = defineStore(STORES.SETTINGS, () => {
const submitContactInfo = async (email: string) => { const submitContactInfo = async (email: string) => {
try { try {
const usersStore = useUsersStore(); const usersStore = useUsersStore();
return await settingsApi.submitContactInfo( return await promptsApi.submitContactInfo(
settings.value.instanceId, settings.value.instanceId,
usersStore.currentUserId || '', usersStore.currentUserId || '',
email, email,