mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-18 16:11:51 -08:00
33 lines
989 B
TypeScript
33 lines
989 B
TypeScript
import type { Workflow } from '@/n8n-api-client/n8n-api-client.types';
|
|
|
|
import type { AuthenticatedN8nApiClient } from './authenticated-n8n-api-client';
|
|
|
|
export class WorkflowApiClient {
|
|
constructor(private readonly apiClient: AuthenticatedN8nApiClient) {}
|
|
|
|
async getAllWorkflows(): Promise<Workflow[]> {
|
|
const response = await this.apiClient.get<{ count: number; data: Workflow[] }>('/workflows');
|
|
|
|
return response.data.data;
|
|
}
|
|
|
|
async createWorkflow(workflow: unknown): Promise<Workflow> {
|
|
const response = await this.apiClient.post<{ data: Workflow }>('/workflows', workflow);
|
|
|
|
return response.data.data;
|
|
}
|
|
|
|
async activateWorkflow(workflow: Workflow): Promise<Workflow> {
|
|
const response = await this.apiClient.patch<{ data: Workflow }>(`/workflows/${workflow.id}`, {
|
|
...workflow,
|
|
active: true,
|
|
});
|
|
|
|
return response.data.data;
|
|
}
|
|
|
|
async deleteWorkflow(workflowId: Workflow['id']): Promise<void> {
|
|
await this.apiClient.delete(`/workflows/${workflowId}`);
|
|
}
|
|
}
|