2023-04-24 03:18:24 -07:00
|
|
|
import type { IExecutionsCurrentSummaryExtended, IRestApiContext } from '@/Interface';
|
|
|
|
import type { ExecutionFilters, ExecutionOptions, IDataObject } from 'n8n-workflow';
|
2023-05-10 08:10:03 -07:00
|
|
|
import { makeRestApiRequest } from '@/utils/apiUtils';
|
2021-05-29 11:31:21 -07:00
|
|
|
|
|
|
|
export async function getNewWorkflow(context: IRestApiContext, name?: string) {
|
2022-12-29 03:20:43 -08:00
|
|
|
const response = await makeRestApiRequest(context, 'GET', '/workflows/new', name ? { name } : {});
|
2022-05-16 09:19:33 -07:00
|
|
|
return {
|
|
|
|
name: response.name,
|
|
|
|
onboardingFlowEnabled: response.onboardingFlowEnabled === true,
|
|
|
|
};
|
2021-06-22 10:33:07 -07:00
|
|
|
}
|
|
|
|
|
2023-01-26 23:51:32 -08:00
|
|
|
export async function getWorkflow(context: IRestApiContext, id: string, filter?: object) {
|
|
|
|
const sendData = filter ? { filter } : undefined;
|
|
|
|
|
2023-05-10 08:10:03 -07:00
|
|
|
return makeRestApiRequest(context, 'GET', `/workflows/${id}`, sendData);
|
2023-01-26 23:51:32 -08:00
|
|
|
}
|
|
|
|
|
2022-10-18 06:28:21 -07:00
|
|
|
export async function getWorkflows(context: IRestApiContext, filter?: object) {
|
|
|
|
const sendData = filter ? { filter } : undefined;
|
|
|
|
|
2023-05-10 08:10:03 -07:00
|
|
|
return makeRestApiRequest(context, 'GET', '/workflows', sendData);
|
2022-10-18 06:28:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function getActiveWorkflows(context: IRestApiContext) {
|
2023-05-10 08:10:03 -07:00
|
|
|
return makeRestApiRequest(context, 'GET', '/active');
|
2022-10-18 06:28:21 -07:00
|
|
|
}
|
|
|
|
|
2022-10-26 01:02:56 -07:00
|
|
|
export async function getCurrentExecutions(context: IRestApiContext, filter: IDataObject) {
|
2023-05-10 08:10:03 -07:00
|
|
|
return makeRestApiRequest(context, 'GET', '/executions-current', { filter });
|
2022-10-26 01:02:56 -07:00
|
|
|
}
|
|
|
|
|
2023-04-11 09:43:47 -07:00
|
|
|
export async function getExecutions(
|
|
|
|
context: IRestApiContext,
|
|
|
|
filter?: ExecutionFilters,
|
|
|
|
options?: ExecutionOptions,
|
|
|
|
): Promise<{ count: number; results: IExecutionsCurrentSummaryExtended[]; estimated: boolean }> {
|
2023-05-10 08:10:03 -07:00
|
|
|
return makeRestApiRequest(context, 'GET', '/executions', { filter, ...options });
|
2022-10-26 01:02:56 -07:00
|
|
|
}
|
2022-12-27 05:51:48 -08:00
|
|
|
|
|
|
|
export async function getExecutionData(context: IRestApiContext, executionId: string) {
|
2023-05-10 08:10:03 -07:00
|
|
|
return makeRestApiRequest(context, 'GET', `/executions/${executionId}`);
|
2022-12-27 05:51:48 -08:00
|
|
|
}
|