@@ -7,8 +7,8 @@ import type { InstantlyCredentials } from "../credentials";
77const INSTANTLY_API_URL = "https://api.instantly.ai/api/v2" ;
88
99type CreateLeadResult =
10- | { success : true ; id : string ; email : string }
11- | { success : false ; error : string } ;
10+ | { success : true ; data : { id : string ; email : string } }
11+ | { success : false ; error : { message : string } } ;
1212
1313export type CreateLeadCoreInput = {
1414 campaignId : string ;
@@ -34,15 +34,15 @@ async function stepHandler(
3434 const apiKey = credentials . INSTANTLY_API_KEY ;
3535
3636 if ( ! apiKey ) {
37- return { success : false , error : "INSTANTLY_API_KEY is required" } ;
37+ return { success : false , error : { message : "INSTANTLY_API_KEY is required" } } ;
3838 }
3939
4040 if ( ! input . campaignId ) {
41- return { success : false , error : "Campaign ID is required" } ;
41+ return { success : false , error : { message : "Campaign ID is required" } } ;
4242 }
4343
4444 if ( ! input . email ) {
45- return { success : false , error : "Email is required" } ;
45+ return { success : false , error : { message : "Email is required" } } ;
4646 }
4747
4848 try {
@@ -51,7 +51,7 @@ async function stepHandler(
5151 try {
5252 customVars = JSON . parse ( input . customVariables ) ;
5353 } catch {
54- return { success : false , error : "Invalid JSON in custom variables" } ;
54+ return { success : false , error : { message : "Invalid JSON in custom variables" } } ;
5555 }
5656 }
5757
@@ -80,20 +80,22 @@ async function stepHandler(
8080 const errorText = await response . text ( ) ;
8181 return {
8282 success : false ,
83- error : `Failed to create lead: ${ response . status } - ${ errorText } ` ,
83+ error : { message : `Failed to create lead: ${ response . status } - ${ errorText } ` } ,
8484 } ;
8585 }
8686
87- const data = ( await response . json ( ) ) as { id : string ; email : string } ;
87+ const responseData = ( await response . json ( ) ) as { id : string ; email : string } ;
8888
8989 return {
9090 success : true ,
91- id : data . id ,
92- email : data . email ,
91+ data : {
92+ id : responseData . id ,
93+ email : responseData . email ,
94+ } ,
9395 } ;
9496 } catch ( error ) {
9597 const message = error instanceof Error ? error . message : String ( error ) ;
96- return { success : false , error : `Failed to create lead: ${ message } ` } ;
98+ return { success : false , error : { message : `Failed to create lead: ${ message } ` } } ;
9799 }
98100}
99101
0 commit comments