11import { getConfig } from './utils.js'
22import { got } from 'got'
3- import { APIHealthResponse , APIProjectDetails , APIGithubOrgDetails , APIChecklistItem , APICheckItem , APIWorkflowItem , APIWorkflowRunItem , APIBulkImportOperationItem } from './types.js'
3+ import { APIHealthResponse , APIProjectDetails , APIGithubOrgDetails , APIChecklistItem , APICheckItem , APIWorkflowItem , APIOperationCompleted , APIBulkImportOperationItem } from './types.js'
44
55export const apiClient = ( ) => {
66 const config = getConfig ( )
@@ -80,7 +80,7 @@ export const getAllWorkflows = async (): Promise<APIWorkflowItem[]> => {
8080 return response . body as APIWorkflowItem [ ]
8181}
8282
83- export const runWorkflow = async ( workflowId : string , data : any ) : Promise < APIWorkflowRunItem > => {
83+ export const runWorkflow = async ( workflowId : string , data : any ) : Promise < APIOperationCompleted > => {
8484 const client = apiClient ( )
8585 const payload = data ? { data } : { }
8686 const response = await client . post ( `workflow/${ workflowId } /execute` , {
@@ -90,7 +90,7 @@ export const runWorkflow = async (workflowId: string, data: any): Promise<APIWor
9090 if ( response . statusCode !== 202 ) {
9191 throw new Error ( `Failed to run the workflow: ${ response . statusCode } ${ response . body } ` )
9292 }
93- return response . body as APIWorkflowRunItem
93+ return response . body as APIOperationCompleted
9494}
9595
9696export const getAllBulkImportOperations = async ( ) : Promise < APIBulkImportOperationItem [ ] > => {
@@ -101,3 +101,18 @@ export const getAllBulkImportOperations = async (): Promise<APIBulkImportOperati
101101 }
102102 return response . body as APIBulkImportOperationItem [ ]
103103}
104+
105+ export const runBulkImportOperation = async ( id : string , payload : any ) : Promise < APIOperationCompleted > => {
106+ const client = apiClient ( )
107+ const response = await client . post ( 'bulk-import' , {
108+ json : { id, payload } ,
109+ responseType : 'json' ,
110+ throwHttpErrors : false
111+ } )
112+
113+ if ( response . statusCode <= 500 && response . statusCode >= 400 ) {
114+ throw new Error ( `Failed to run the bulk import operation: ${ response . statusCode } ${ JSON . stringify ( response . body , null , 2 ) } ` )
115+ }
116+
117+ return response . body as APIOperationCompleted
118+ }
0 commit comments