Skip to content

Commit 6cf0720

Browse files
authored
refactor(editor): Extract API Requests into @n8n/rest-api-client package (no-changelog) (#15930)
1 parent a18822a commit 6cf0720

File tree

90 files changed

+502
-279
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+502
-279
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const BROWSER_ID_STORAGE_KEY = 'n8n-browserId';

packages/@n8n/constants/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
export * from './browser';
2+
13
export const LICENSE_FEATURES = {
24
SHARING: 'feat:sharing',
35
LDAP: 'feat:ldap',

packages/@n8n/utils/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
"dist"
77
],
88
"exports": {
9+
"./dist/*": {
10+
"types": "./dist/*.d.ts",
11+
"import": "./dist/*.js",
12+
"require": "./dist/*.cjs"
13+
},
914
"./*": {
1015
"types": "./dist/*.d.ts",
1116
"import": "./dist/*.js",
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
import type { UserConfig } from 'vitest/node';
1+
import type { InlineConfig } from 'vitest/node';
2+
import type { UserConfig } from 'vite';
3+
4+
export const createVitestConfig: (options?: InlineConfig) => UserConfig;
25

36
export const vitestConfig: UserConfig;

packages/@n8n/vitest-config/frontend.mjs

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,41 @@ import { defineConfig as defineVitestConfig } from 'vitest/config';
22

33
/**
44
* Define a Vitest configuration
5-
*
6-
* @returns {import('vitest/node').UserConfig}
5+
* @param {import('vitest/node').InlineConfig} options - The options to pass to the Vitest configuration
6+
* @returns {import('vite').UserConfig}
77
*/
8-
export const vitestConfig = defineVitestConfig({
9-
test: {
10-
silent: true,
11-
globals: true,
12-
environment: 'jsdom',
13-
setupFiles: ['./src/__tests__/setup.ts'],
14-
coverage: {
15-
enabled: false,
16-
all: false,
17-
provider: 'v8',
18-
reporter: ['text-summary', 'lcov', 'html-spa'],
19-
},
20-
css: {
21-
modules: {
22-
classNameStrategy: 'non-scoped',
8+
export const createVitestConfig = (options = {}) => {
9+
const vitestConfig = defineVitestConfig({
10+
test: {
11+
silent: true,
12+
globals: true,
13+
environment: 'jsdom',
14+
setupFiles: ['./src/__tests__/setup.ts'],
15+
coverage: {
16+
enabled: false,
17+
all: false,
18+
provider: 'v8',
19+
reporter: ['text-summary', 'lcov', 'html-spa'],
20+
},
21+
css: {
22+
modules: {
23+
classNameStrategy: 'non-scoped',
24+
},
2325
},
26+
...options,
2427
},
25-
},
26-
});
28+
});
2729

28-
if (process.env.COVERAGE_ENABLED === 'true') {
29-
const { coverage } = vitestConfig.test;
30-
coverage.enabled = true;
31-
if (process.env.CI === 'true') {
32-
coverage.all = true;
33-
coverage.reporter = ['cobertura'];
30+
if (process.env.COVERAGE_ENABLED === 'true') {
31+
const { coverage } = vitestConfig.test;
32+
coverage.enabled = true;
33+
if (process.env.CI === 'true') {
34+
coverage.all = true;
35+
coverage.reporter = ['cobertura'];
36+
}
3437
}
35-
}
38+
39+
return vitestConfig;
40+
};
41+
42+
export const vitestConfig = createVitestConfig();
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const sharedOptions = require('@n8n/eslint-config/shared');
2+
3+
/**
4+
* @type {import('@types/eslint').ESLint.ConfigData}
5+
*/
6+
module.exports = {
7+
extends: ['@n8n/eslint-config/frontend'],
8+
9+
...sharedOptions(__dirname, 'frontend'),
10+
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
dist
12+
dist-ssr
13+
*.local
14+
15+
# Editor directories and files
16+
.vscode/*
17+
!.vscode/extensions.json
18+
.idea
19+
.DS_Store
20+
*.suo
21+
*.ntvs*
22+
*.njsproj
23+
*.sln
24+
*.sw?
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# @n8n/rest-api-client
2+
3+
This package contains the REST API calls for n8n.
4+
5+
## Table of Contents
6+
7+
- [Features](#features)
8+
- [Contributing](#contributing)
9+
- [License](#license)
10+
11+
## Features
12+
13+
- Provides a REST API for n8n
14+
- Supports authentication and authorization
15+
16+
## Contributing
17+
18+
For more details, please read our [CONTRIBUTING.md](CONTRIBUTING.md).
19+
20+
## License
21+
22+
For more details, please read our [LICENSE.md](LICENSE.md).
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"$schema": "../../../../node_modules/@biomejs/biome/configuration_schema.json",
3+
"extends": ["../../../../biome.jsonc"]
4+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"name": "@n8n/rest-api-client",
3+
"type": "module",
4+
"version": "1.0.0",
5+
"files": [
6+
"dist"
7+
],
8+
"main": "./dist/index.cjs",
9+
"module": "./dist/index.js",
10+
"types": "./dist/index.d.ts",
11+
"exports": {
12+
".": {
13+
"types": "./dist/index.d.ts",
14+
"import": "./dist/index.js",
15+
"require": "./dist/index.cjs"
16+
},
17+
"./*": {
18+
"types": "./dist/*.d.ts",
19+
"import": "./dist/*.js",
20+
"require": "./dist/*.cjs"
21+
}
22+
},
23+
"scripts": {
24+
"dev": "vite",
25+
"build": "pnpm run typecheck && tsup",
26+
"preview": "vite preview",
27+
"typecheck": "vue-tsc --noEmit",
28+
"test": "vitest run",
29+
"test:dev": "vitest --silent=false",
30+
"lint": "eslint src --ext .js,.ts,.vue --quiet",
31+
"lintfix": "eslint src --ext .js,.ts,.vue --fix",
32+
"format": "biome format --write . && prettier --write . --ignore-path ../../../../.prettierignore",
33+
"format:check": "biome ci . && prettier --check . --ignore-path ../../../../.prettierignore"
34+
},
35+
"dependencies": {
36+
"@n8n/api-types": "workspace:*",
37+
"@n8n/constants": "workspace:*",
38+
"@n8n/permissions": "workspace:*",
39+
"@n8n/utils": "workspace:*",
40+
"js-base64": "catalog:",
41+
"n8n-workflow": "workspace:*",
42+
"axios": "catalog:",
43+
"flatted": "catalog:"
44+
},
45+
"devDependencies": {
46+
"@n8n/eslint-config": "workspace:*",
47+
"@n8n/i18n": "workspace:*",
48+
"@n8n/typescript-config": "workspace:*",
49+
"@n8n/vitest-config": "workspace:*",
50+
"@testing-library/jest-dom": "catalog:frontend",
51+
"@testing-library/user-event": "catalog:frontend",
52+
"tsup": "catalog:",
53+
"typescript": "catalog:frontend",
54+
"vite": "catalog:frontend",
55+
"vitest": "catalog:frontend"
56+
},
57+
"license": "See LICENSE.md file in the root of the repository"
58+
}

packages/frontend/editor-ui/src/api/api-keys.ts renamed to packages/frontend/@n8n/rest-api-client/src/api/api-keys.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import type { IRestApiContext } from '@/Interface';
2-
import { makeRestApiRequest } from '@/utils/apiUtils';
31
import type {
42
CreateApiKeyRequestDto,
53
UpdateApiKeyRequestDto,
@@ -8,6 +6,9 @@ import type {
86
} from '@n8n/api-types';
97
import type { ApiKeyScope } from '@n8n/permissions';
108

9+
import type { IRestApiContext } from '../types';
10+
import { makeRestApiRequest } from '../utils';
11+
1112
export async function getApiKeys(context: IRestApiContext): Promise<ApiKey[]> {
1213
return await makeRestApiRequest(context, 'GET', '/api-keys');
1314
}

packages/frontend/editor-ui/src/api/communityNodes.ts renamed to packages/frontend/@n8n/rest-api-client/src/api/communityNodes.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import type { IRestApiContext } from '@/Interface';
21
import type { PublicInstalledPackage } from 'n8n-workflow';
3-
import { get, post, makeRestApiRequest } from '@/utils/apiUtils';
2+
3+
import type { IRestApiContext } from '../types';
4+
import { get, post, makeRestApiRequest } from '../utils';
45

56
export async function getInstalledCommunityNodes(
67
context: IRestApiContext,

packages/frontend/editor-ui/src/api/ctas.ts renamed to packages/frontend/@n8n/rest-api-client/src/api/ctas.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { IRestApiContext } from '@/Interface';
2-
import { get } from '@/utils/apiUtils';
1+
import type { IRestApiContext } from '../types';
2+
import { get } from '../utils';
33

44
export async function getBecomeCreatorCta(context: IRestApiContext): Promise<boolean> {
55
const response = await get(context.baseUrl, '/cta/become-creator');

packages/frontend/editor-ui/src/api/eventbus.ee.ts renamed to packages/frontend/@n8n/rest-api-client/src/api/eventbus.ee.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import type { IRestApiContext } from '@/Interface';
2-
import { makeRestApiRequest } from '@/utils/apiUtils';
31
import type { IDataObject, MessageEventBusDestinationOptions } from 'n8n-workflow';
42

3+
import type { IRestApiContext } from '../types';
4+
import { makeRestApiRequest } from '../utils';
5+
56
export type ApiMessageEventBusDestinationOptions = MessageEventBusDestinationOptions & {
67
id: string;
78
};

packages/frontend/editor-ui/src/api/events.ts renamed to packages/frontend/@n8n/rest-api-client/src/api/events.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { IRestApiContext } from '@/Interface';
2-
import { makeRestApiRequest } from '@/utils/apiUtils';
1+
import type { IRestApiContext } from '../types';
2+
import { makeRestApiRequest } from '../utils';
33

44
export async function sessionStarted(context: IRestApiContext): Promise<void> {
55
return await makeRestApiRequest(context, 'GET', '/events/session-started');

packages/frontend/@n8n/rest-api-client/src/api/execution.ts

Whitespace-only changes.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export * from './api-keys';
2+
export * from './communityNodes';
3+
export * from './ctas';
4+
export * from './eventbus.ee';
5+
export * from './events';
6+
export * from './mfa';
7+
export * from './nodeTypes';
8+
export * from './npsSurvey';
9+
export * from './orchestration';
10+
export * from './roles';
11+
export * from './ui';
12+
export * from './webhooks';

packages/frontend/editor-ui/src/api/mfa.ts renamed to packages/frontend/@n8n/rest-api-client/src/api/mfa.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { IRestApiContext } from '@/Interface';
2-
import { makeRestApiRequest } from '@/utils/apiUtils';
1+
import type { IRestApiContext } from '../types';
2+
import { makeRestApiRequest } from '../utils';
33

44
export async function canEnableMFA(context: IRestApiContext) {
55
return await makeRestApiRequest(context, 'POST', '/mfa/can-enable');

packages/frontend/editor-ui/src/api/nodeTypes.ts renamed to packages/frontend/@n8n/rest-api-client/src/api/nodeTypes.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,20 @@ import type {
55
ResourceLocatorRequestDto,
66
ResourceMapperFieldsRequestDto,
77
} from '@n8n/api-types';
8-
import { makeRestApiRequest } from '@/utils/apiUtils';
9-
import type { IRestApiContext } from '@/Interface';
108
import type { INodeTranslationHeaders } from '@n8n/i18n';
119
import axios from 'axios';
12-
import {
13-
type INodeListSearchResult,
14-
type INodePropertyOptions,
15-
type INodeTypeDescription,
16-
type INodeTypeNameVersion,
17-
type NodeParameterValueType,
18-
type ResourceMapperFields,
19-
sleep,
10+
import type {
11+
INodeListSearchResult,
12+
INodePropertyOptions,
13+
INodeTypeDescription,
14+
INodeTypeNameVersion,
15+
NodeParameterValueType,
16+
ResourceMapperFields,
2017
} from 'n8n-workflow';
18+
import { sleep } from 'n8n-workflow';
19+
20+
import type { IRestApiContext } from '../types';
21+
import { makeRestApiRequest } from '../utils';
2122

2223
async function fetchNodeTypesJsonWithRetry(url: string, retries = 5, delay = 500) {
2324
for (let attempt = 0; attempt < retries; attempt++) {
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import type { IRestApiContext } from '@/Interface';
2-
import { makeRestApiRequest } from '@/utils/apiUtils';
31
import type { NpsSurveyState } from 'n8n-workflow';
42

3+
import type { IRestApiContext } from '../types';
4+
import { makeRestApiRequest } from '../utils';
5+
56
export async function updateNpsSurveyState(context: IRestApiContext, state: NpsSurveyState) {
67
await makeRestApiRequest(context, 'PATCH', '/user-settings/nps-survey', state);
78
}

packages/frontend/editor-ui/src/api/orchestration.ts renamed to packages/frontend/@n8n/rest-api-client/src/api/orchestration.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { IRestApiContext } from '@/Interface';
2-
import { makeRestApiRequest } from '@/utils/apiUtils';
1+
import type { IRestApiContext } from '../types';
2+
import { makeRestApiRequest } from '../utils';
33

44
const GET_STATUS_ENDPOINT = '/orchestration/worker/status';
55

packages/frontend/editor-ui/src/api/roles.api.ts renamed to packages/frontend/@n8n/rest-api-client/src/api/roles.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { AllRolesMap } from '@n8n/permissions';
2-
import type { IRestApiContext } from '@/Interface';
3-
import { makeRestApiRequest } from '@/utils/apiUtils';
2+
3+
import type { IRestApiContext } from '../types';
4+
import { makeRestApiRequest } from '../utils';
45

56
export const getRoles = async (context: IRestApiContext): Promise<AllRolesMap> => {
67
return await makeRestApiRequest(context, 'GET', '/roles');

packages/frontend/editor-ui/src/api/ui.ts renamed to packages/frontend/@n8n/rest-api-client/src/api/ui.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import type { IRestApiContext } from '@/Interface';
2-
import { makeRestApiRequest } from '@/utils/apiUtils';
31
import type { BannerName } from '@n8n/api-types';
42

3+
import type { IRestApiContext } from '../types';
4+
import { makeRestApiRequest } from '../utils';
5+
56
export async function dismissBannerPermanently(
67
context: IRestApiContext,
78
data: { bannerName: BannerName; dismissedBanners: string[] },

packages/frontend/editor-ui/src/api/webhooks.ts renamed to packages/frontend/@n8n/rest-api-client/src/api/webhooks.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { makeRestApiRequest } from '@/utils/apiUtils';
2-
import type { IRestApiContext } from '@/Interface';
31
import type { IHttpRequestMethods } from 'n8n-workflow';
42

3+
import type { IRestApiContext } from '../types';
4+
import { makeRestApiRequest } from '../utils';
5+
56
type WebhookData = {
67
workflowId: string;
78
webhookPath: string;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export * from './api';
2+
export * from './types';
3+
export * from './utils';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/// <reference types="vite/client" />
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export interface IRestApiContext {
2+
baseUrl: string;
3+
pushRef: string;
4+
}

packages/frontend/editor-ui/src/utils/apiUtils.test.ts renamed to packages/frontend/@n8n/rest-api-client/src/utils.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ResponseError, STREAM_SEPERATOR, streamRequest } from './apiUtils';
1+
import { ResponseError, STREAM_SEPERATOR, streamRequest } from './utils';
22

33
describe('streamRequest', () => {
44
it('should stream data from the API endpoint', async () => {

0 commit comments

Comments
 (0)