mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
refactor(editor): Move templates api to @n8n/rest-api-client package (no-changelog) (#16542)
This commit is contained in:
@@ -14,7 +14,10 @@ export * from './roles';
|
||||
export * from './settings';
|
||||
export * from './module-settings';
|
||||
export * from './sso';
|
||||
export * from './tags';
|
||||
export * from './templates';
|
||||
export * from './ui';
|
||||
export * from './versions';
|
||||
export * from './webhooks';
|
||||
export * from './workflowHistory';
|
||||
export * from './workflows';
|
||||
|
||||
7
packages/frontend/@n8n/rest-api-client/src/api/tags.ts
Normal file
7
packages/frontend/@n8n/rest-api-client/src/api/tags.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
export interface ITag {
|
||||
id: string;
|
||||
name: string;
|
||||
usageCount?: number;
|
||||
createdAt?: string;
|
||||
updatedAt?: string;
|
||||
}
|
||||
195
packages/frontend/@n8n/rest-api-client/src/api/templates.ts
Normal file
195
packages/frontend/@n8n/rest-api-client/src/api/templates.ts
Normal file
@@ -0,0 +1,195 @@
|
||||
import type { RawAxiosRequestHeaders } from 'axios';
|
||||
import type { INode, INodeCredentialsDetails } from 'n8n-workflow';
|
||||
|
||||
import type { VersionNode } from './versions';
|
||||
import type { WorkflowData } from './workflows';
|
||||
import { get } from '../utils';
|
||||
|
||||
export interface IWorkflowTemplateNode
|
||||
extends Pick<
|
||||
INode,
|
||||
'name' | 'type' | 'position' | 'parameters' | 'typeVersion' | 'webhookId' | 'id' | 'disabled'
|
||||
> {
|
||||
// The credentials in a template workflow have a different type than in a regular workflow
|
||||
credentials?: IWorkflowTemplateNodeCredentials;
|
||||
}
|
||||
|
||||
export interface IWorkflowTemplateNodeCredentials {
|
||||
[key: string]: string | INodeCredentialsDetails;
|
||||
}
|
||||
|
||||
export interface IWorkflowTemplate {
|
||||
id: number;
|
||||
name: string;
|
||||
workflow: Pick<WorkflowData, 'connections' | 'settings' | 'pinData'> & {
|
||||
nodes: IWorkflowTemplateNode[];
|
||||
};
|
||||
}
|
||||
|
||||
export interface ITemplatesNode extends VersionNode {
|
||||
id: number;
|
||||
categories?: ITemplatesCategory[];
|
||||
}
|
||||
|
||||
export interface ITemplatesCollection {
|
||||
id: number;
|
||||
name: string;
|
||||
nodes: ITemplatesNode[];
|
||||
workflows: Array<{ id: number }>;
|
||||
}
|
||||
|
||||
interface ITemplatesImage {
|
||||
id: number;
|
||||
url: string;
|
||||
}
|
||||
|
||||
interface ITemplatesCollectionExtended extends ITemplatesCollection {
|
||||
description: string | null;
|
||||
image: ITemplatesImage[];
|
||||
categories: ITemplatesCategory[];
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
export interface ITemplatesCollectionFull extends ITemplatesCollectionExtended {
|
||||
full: true;
|
||||
}
|
||||
|
||||
export interface ITemplatesCollectionResponse extends ITemplatesCollectionExtended {
|
||||
workflows: ITemplatesWorkflow[];
|
||||
}
|
||||
|
||||
/**
|
||||
* A template without the actual workflow definition
|
||||
*/
|
||||
|
||||
export interface ITemplatesWorkflow {
|
||||
id: number;
|
||||
createdAt: string;
|
||||
name: string;
|
||||
nodes: ITemplatesNode[];
|
||||
totalViews: number;
|
||||
user: {
|
||||
username: string;
|
||||
};
|
||||
}
|
||||
|
||||
export interface ITemplatesWorkflowInfo {
|
||||
nodeCount: number;
|
||||
nodeTypes: {
|
||||
[key: string]: {
|
||||
count: number;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export type TemplateSearchFacet = {
|
||||
field_name: string;
|
||||
sampled: boolean;
|
||||
stats: {
|
||||
total_values: number;
|
||||
};
|
||||
counts: Array<{
|
||||
count: number;
|
||||
highlighted: string;
|
||||
value: string;
|
||||
}>;
|
||||
};
|
||||
|
||||
export interface ITemplatesWorkflowResponse extends ITemplatesWorkflow, IWorkflowTemplate {
|
||||
description: string | null;
|
||||
image: ITemplatesImage[];
|
||||
categories: ITemplatesCategory[];
|
||||
workflowInfo: ITemplatesWorkflowInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* A template with also the full workflow definition
|
||||
*/
|
||||
|
||||
export interface ITemplatesWorkflowFull extends ITemplatesWorkflowResponse {
|
||||
full: true;
|
||||
}
|
||||
|
||||
export interface ITemplatesQuery {
|
||||
categories: string[];
|
||||
search: string;
|
||||
}
|
||||
|
||||
export interface ITemplatesCategory {
|
||||
id: number;
|
||||
name: string;
|
||||
}
|
||||
|
||||
function stringifyArray(arr: string[]) {
|
||||
return arr.join(',');
|
||||
}
|
||||
|
||||
export async function testHealthEndpoint(apiEndpoint: string) {
|
||||
return await get(apiEndpoint, '/health');
|
||||
}
|
||||
|
||||
export async function getCategories(
|
||||
apiEndpoint: string,
|
||||
headers?: RawAxiosRequestHeaders,
|
||||
): Promise<{ categories: ITemplatesCategory[] }> {
|
||||
return await get(apiEndpoint, '/templates/categories', undefined, headers);
|
||||
}
|
||||
|
||||
export async function getCollections(
|
||||
apiEndpoint: string,
|
||||
query: ITemplatesQuery,
|
||||
headers?: RawAxiosRequestHeaders,
|
||||
): Promise<{ collections: ITemplatesCollection[] }> {
|
||||
return await get(
|
||||
apiEndpoint,
|
||||
'/templates/collections',
|
||||
{ category: query.categories, search: query.search },
|
||||
headers,
|
||||
);
|
||||
}
|
||||
|
||||
export async function getWorkflows(
|
||||
apiEndpoint: string,
|
||||
query: { page: number; limit: number; categories: string[]; search: string },
|
||||
headers?: RawAxiosRequestHeaders,
|
||||
): Promise<{
|
||||
totalWorkflows: number;
|
||||
workflows: ITemplatesWorkflow[];
|
||||
filters: TemplateSearchFacet[];
|
||||
}> {
|
||||
return await get(
|
||||
apiEndpoint,
|
||||
'/templates/search',
|
||||
{
|
||||
page: query.page,
|
||||
rows: query.limit,
|
||||
category: stringifyArray(query.categories),
|
||||
search: query.search,
|
||||
},
|
||||
headers,
|
||||
);
|
||||
}
|
||||
|
||||
export async function getCollectionById(
|
||||
apiEndpoint: string,
|
||||
collectionId: string,
|
||||
headers?: RawAxiosRequestHeaders,
|
||||
): Promise<{ collection: ITemplatesCollectionResponse }> {
|
||||
return await get(apiEndpoint, `/templates/collections/${collectionId}`, undefined, headers);
|
||||
}
|
||||
|
||||
export async function getTemplateById(
|
||||
apiEndpoint: string,
|
||||
templateId: string,
|
||||
headers?: RawAxiosRequestHeaders,
|
||||
): Promise<{ workflow: ITemplatesWorkflowResponse }> {
|
||||
return await get(apiEndpoint, `/templates/workflows/${templateId}`, undefined, headers);
|
||||
}
|
||||
|
||||
export async function getWorkflowTemplate(
|
||||
apiEndpoint: string,
|
||||
templateId: string,
|
||||
headers?: RawAxiosRequestHeaders,
|
||||
): Promise<IWorkflowTemplate> {
|
||||
return await get(apiEndpoint, `/workflows/templates/${templateId}`, undefined, headers);
|
||||
}
|
||||
42
packages/frontend/@n8n/rest-api-client/src/api/workflows.ts
Normal file
42
packages/frontend/@n8n/rest-api-client/src/api/workflows.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import type { IWorkflowSettings, IConnections, INode, IPinData } from 'n8n-workflow';
|
||||
|
||||
import type { ITag } from './tags';
|
||||
|
||||
export interface WorkflowMetadata {
|
||||
onboardingId?: string;
|
||||
templateId?: string;
|
||||
instanceId?: string;
|
||||
templateCredsSetupCompleted?: boolean;
|
||||
}
|
||||
|
||||
// Simple version of n8n-workflow.Workflow
|
||||
export interface WorkflowData {
|
||||
id?: string;
|
||||
name?: string;
|
||||
active?: boolean;
|
||||
nodes: INode[];
|
||||
connections: IConnections;
|
||||
settings?: IWorkflowSettings;
|
||||
tags?: string[];
|
||||
pinData?: IPinData;
|
||||
versionId?: string;
|
||||
meta?: WorkflowMetadata;
|
||||
}
|
||||
|
||||
export interface WorkflowDataUpdate {
|
||||
id?: string;
|
||||
name?: string;
|
||||
nodes?: INode[];
|
||||
connections?: IConnections;
|
||||
settings?: IWorkflowSettings;
|
||||
active?: boolean;
|
||||
tags?: ITag[] | string[]; // string[] when store or requested, ITag[] from API response
|
||||
pinData?: IPinData;
|
||||
versionId?: string;
|
||||
meta?: WorkflowMetadata;
|
||||
parentFolderId?: string;
|
||||
}
|
||||
|
||||
export interface WorkflowDataCreate extends WorkflowDataUpdate {
|
||||
projectId?: string;
|
||||
}
|
||||
Reference in New Issue
Block a user