mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
refactor(core): Post-release refactorings of Public API (#3495)
* ⚡ Post-release refactorings * 🧪 Add `--forceExit` * 🛠 typing refactor (#3486) * 🐛 Fix middleware arguments * 👕 Fix lint * ⚡ Restore commented out block Co-authored-by: Ben Hesseldieck <1849459+BHesseldieck@users.noreply.github.com>
This commit is contained in:
@@ -323,8 +323,7 @@ export async function createManyExecutions(
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a execution in the DB and assigns it to a workflow.
|
||||
* @param user user to assign the workflow to
|
||||
* Store a execution in the DB and assign it to a workflow.
|
||||
*/
|
||||
export async function createExecution(
|
||||
attributes: Partial<ExecutionEntity> = {},
|
||||
@@ -346,48 +345,41 @@ export async function createExecution(
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a execution in the DB and assigns it to a workflow.
|
||||
* @param user user to assign the workflow to
|
||||
* Store a successful execution in the DB and assign it to a workflow.
|
||||
*/
|
||||
export async function createSuccessfullExecution(workflow: WorkflowEntity) {
|
||||
const execution = await createExecution(
|
||||
export async function createSuccessfulExecution(workflow: WorkflowEntity) {
|
||||
return await createExecution(
|
||||
{
|
||||
finished: true,
|
||||
},
|
||||
workflow,
|
||||
);
|
||||
|
||||
return execution;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a execution in the DB and assigns it to a workflow.
|
||||
* @param user user to assign the workflow to
|
||||
* Store an error execution in the DB and assign it to a workflow.
|
||||
*/
|
||||
export async function createErrorExecution(workflow: WorkflowEntity) {
|
||||
const execution = await createExecution(
|
||||
return await createExecution(
|
||||
{
|
||||
finished: false,
|
||||
stoppedAt: new Date(),
|
||||
},
|
||||
workflow,
|
||||
);
|
||||
return execution;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a execution in the DB and assigns it to a workflow.
|
||||
* @param user user to assign the workflow to
|
||||
* Store a waiting execution in the DB and assign it to a workflow.
|
||||
*/
|
||||
export async function createWaitingExecution(workflow: WorkflowEntity) {
|
||||
const execution = await createExecution(
|
||||
return await createExecution(
|
||||
{
|
||||
finished: false,
|
||||
waitTill: new Date(),
|
||||
},
|
||||
workflow,
|
||||
);
|
||||
return execution;
|
||||
}
|
||||
|
||||
// ----------------------------------
|
||||
@@ -417,7 +409,7 @@ export async function createManyWorkflows(
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a workflow in the DB (without a trigger) and optionally assigns it to a user.
|
||||
* Store a workflow in the DB (without a trigger) and optionally assign it to a user.
|
||||
* @param user user to assign the workflow to
|
||||
*/
|
||||
export async function createWorkflow(attributes: Partial<WorkflowEntity> = {}, user?: User) {
|
||||
@@ -450,7 +442,7 @@ export async function createWorkflow(attributes: Partial<WorkflowEntity> = {}, u
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a workflow in the DB (with a trigger) and optionally assigns it to a user.
|
||||
* Store a workflow in the DB (with a trigger) and optionally assign it to a user.
|
||||
* @param user user to assign the workflow to
|
||||
*/
|
||||
export async function createWorkflowWithTrigger(
|
||||
@@ -487,6 +479,7 @@ export async function createWorkflowWithTrigger(
|
||||
},
|
||||
user,
|
||||
);
|
||||
|
||||
return workflow;
|
||||
}
|
||||
|
||||
|
||||
@@ -34,3 +34,12 @@ export type SaveCredentialFunction = (
|
||||
export type PostgresSchemaSection = {
|
||||
[K in 'host' | 'port' | 'schema' | 'user' | 'password']: { env: string };
|
||||
};
|
||||
|
||||
export interface TriggerTime {
|
||||
mode: string;
|
||||
hour: number;
|
||||
minute: number;
|
||||
dayOfMonth: number;
|
||||
weekeday: number;
|
||||
[key: string]: string | number;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { randomBytes } from 'crypto';
|
||||
import { existsSync } from 'fs';
|
||||
|
||||
import express from 'express';
|
||||
import superagent from 'superagent';
|
||||
import request from 'supertest';
|
||||
@@ -7,6 +8,9 @@ import { URL } from 'url';
|
||||
import bodyParser from 'body-parser';
|
||||
import util from 'util';
|
||||
import { createTestAccount } from 'nodemailer';
|
||||
import { set } from 'lodash';
|
||||
import { CronJob } from 'cron';
|
||||
import { BinaryDataManager, UserSettings } from 'n8n-core';
|
||||
import {
|
||||
ICredentialType,
|
||||
IDataObject,
|
||||
@@ -19,10 +23,8 @@ import {
|
||||
ITriggerResponse,
|
||||
LoggerProxy,
|
||||
} from 'n8n-workflow';
|
||||
import { BinaryDataManager, UserSettings } from 'n8n-core';
|
||||
import { CronJob } from 'cron';
|
||||
|
||||
import config = require('../../../config');
|
||||
import config from '../../../config';
|
||||
import { AUTHLESS_ENDPOINTS, PUBLIC_API_REST_PATH_SEGMENT, REST_PATH_SEGMENT } from './constants';
|
||||
import { AUTH_COOKIE_NAME } from '../../../src/constants';
|
||||
import { addRoutes as authMiddleware } from '../../../src/UserManagement/routes';
|
||||
@@ -43,20 +45,17 @@ import { issueJWT } from '../../../src/UserManagement/auth/jwt';
|
||||
import { getLogger } from '../../../src/Logger';
|
||||
import { credentialsController } from '../../../src/api/credentials.api';
|
||||
import { loadPublicApiVersions } from '../../../src/PublicApi/';
|
||||
import type { User } from '../../../src/databases/entities/User';
|
||||
import type { ApiPath, EndpointGroup, PostgresSchemaSection, SmtpTestAccount } from './types';
|
||||
import { Telemetry } from '../../../src/telemetry';
|
||||
import type { N8nApp } from '../../../src/UserManagement/Interfaces';
|
||||
import { set } from 'lodash';
|
||||
interface TriggerTime {
|
||||
mode: string;
|
||||
hour: number;
|
||||
minute: number;
|
||||
dayOfMonth: number;
|
||||
weekeday: number;
|
||||
[key: string]: string | number;
|
||||
}
|
||||
import * as UserManagementMailer from '../../../src/UserManagement/email/UserManagementMailer';
|
||||
import type { User } from '../../../src/databases/entities/User';
|
||||
import type {
|
||||
ApiPath,
|
||||
EndpointGroup,
|
||||
PostgresSchemaSection,
|
||||
SmtpTestAccount,
|
||||
TriggerTime,
|
||||
} from './types';
|
||||
import type { N8nApp } from '../../../src/UserManagement/Interfaces';
|
||||
|
||||
|
||||
/**
|
||||
* Initialize a test server.
|
||||
@@ -75,7 +74,7 @@ export async function initTestServer({
|
||||
app: express(),
|
||||
restEndpoint: REST_PATH_SEGMENT,
|
||||
publicApiEndpoint: PUBLIC_API_REST_PATH_SEGMENT,
|
||||
...(endpointGroups?.includes('credentials') ? { externalHooks: ExternalHooks() } : {}),
|
||||
externalHooks: {},
|
||||
};
|
||||
|
||||
testServer.app.use(bodyParser.json());
|
||||
@@ -90,13 +89,17 @@ export async function initTestServer({
|
||||
|
||||
if (!endpointGroups) return testServer.app;
|
||||
|
||||
if (endpointGroups.includes('credentials')) {
|
||||
testServer.externalHooks = ExternalHooks();
|
||||
}
|
||||
|
||||
const [routerEndpoints, functionEndpoints] = classifyEndpointGroups(endpointGroups);
|
||||
|
||||
if (routerEndpoints.length) {
|
||||
const { apiRouters } = await loadPublicApiVersions(testServer.publicApiEndpoint);
|
||||
const map: Record<string, express.Router | express.Router[]> = {
|
||||
credentials: credentialsController,
|
||||
publicApi: apiRouters
|
||||
publicApi: apiRouters,
|
||||
};
|
||||
|
||||
for (const group of routerEndpoints) {
|
||||
@@ -743,8 +746,8 @@ export async function initNodeTypes() {
|
||||
},
|
||||
},
|
||||
};
|
||||
const nodeTypes = NodeTypes();
|
||||
await nodeTypes.init(types);
|
||||
|
||||
await NodeTypes().init(types);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -759,7 +762,7 @@ export function initTestLogger() {
|
||||
*/
|
||||
export async function initBinaryManager() {
|
||||
const binaryDataConfig = config.getEnv('binaryDataManager');
|
||||
await BinaryDataManager.init(binaryDataConfig, true);
|
||||
await BinaryDataManager.init(binaryDataConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -783,7 +786,7 @@ export function initConfigFile() {
|
||||
*/
|
||||
export function createAgent(
|
||||
app: express.Application,
|
||||
options?: { apiPath?: ApiPath; version?: string | number; auth: boolean; user: User },
|
||||
options?: { auth: boolean; user: User; apiPath?: ApiPath; version?: string | number },
|
||||
) {
|
||||
const agent = request.agent(app);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user