1-
2-
31import {
42INodeType ,
53INodeTypeDescription ,
@@ -50,10 +48,9 @@ export class Lowcoder implements INodeType {
5048name :'default' ,
5149httpMethod :'={{$parameter["httpMethod"]}}' ,
5250isFullPath :true ,
53- responseCode :'200' ,
5451responseMode :'onReceived' ,
55- responseData :'allEntries ' ,
56- responseContentType :'={{$parameter["options"]["responseContentType"]}}' ,
52+ responseData :'={{$parameter["options"]["responseData"] || "Workflow Resumed!"}} ' ,
53+ responseContentType :'={{$parameter["options"]["responseContentType"] || "application/json" }}' ,
5754responsePropertyName :'={{$parameter["options"]["responsePropertyName"]}}' ,
5855responseHeaders :'={{$parameter["options"]["responseHeaders"]}}' ,
5956path :'={{$parameter["appId"] || ""}}' ,
@@ -75,7 +72,14 @@ export class Lowcoder implements INodeType {
7572default :'' ,
7673} ,
7774httpMethodsProperty ,
78- optionsProperty
75+ optionsProperty ,
76+ {
77+ displayName :'Response Code' ,
78+ name :'responseCode' ,
79+ type :'number' ,
80+ default :200 ,
81+ description :'The HTTP response code to return' ,
82+ } ,
7983] ,
8084} ;
8185
@@ -113,6 +117,7 @@ export class Lowcoder implements INodeType {
113117ignoreBots :boolean ;
114118rawBody :Buffer ;
115119responseData ?:string ;
120+ responseCode ?:number ;
116121} ;
117122const req = this . getRequestObject ( ) ;
118123const resp = this . getResponseObject ( ) ;
@@ -122,27 +127,43 @@ export class Lowcoder implements INodeType {
122127throw new NodeApiError ( this . getNode ( ) , { } , { message :'Authorization data is wrong!' } ) ;
123128}
124129} catch ( error ) {
125- resp . writeHead ( error . responseCode , { 'WWW-Authenticate' :'Basic realm="Webhook"' } ) ;
130+ resp . writeHead ( error . responseCode || 401 , { 'WWW-Authenticate' :'Basic realm="Webhook"' } ) ;
126131resp . end ( error . message ) ;
127132return { noWebhookResponse :true } ;
128133}
129- const body = typeof req . body != 'undefined' ?req . body :{ } ;
130- const returnItem :INodeExecutionData = {
131- binary :{ } ,
132- json :{
133- headers :req . headers ,
134- params :req . params ,
135- query :req . query ,
136- body :body ,
137- } ,
138- } ;
139- return { workflowData :[ [ returnItem ] ] } ;
134+
135+ const type = req . query . type ;
136+ if ( type === 'resume' ) {
137+ // Resume workflow as before
138+ const body = typeof req . body != 'undefined' ?req . body :{ } ;
139+ const returnItem :INodeExecutionData = {
140+ binary :{ } ,
141+ json :{
142+ headers :req . headers ,
143+ params :req . params ,
144+ query :req . query ,
145+ body :body ,
146+ } ,
147+ } ;
148+ const responseCode = options . responseCode || 200 ;
149+ resp . statusCode = responseCode ;
150+ return { workflowData :[ [ returnItem ] ] } ;
151+ } else {
152+ // Return input data, and don't resume
153+ const staticData = this . getWorkflowStaticData ( 'node' ) ;
154+ const previousData = staticData . previousNodeData || [ ] ;
155+ resp . statusCode = 200 ;
156+ resp . setHeader ( 'Content-Type' , 'application/json' ) ;
157+ resp . end ( JSON . stringify ( { message :'Static response: workflow not resumed' , type, previousData} ) ) ;
158+ return { noWebhookResponse :true } ;
159+ }
140160}
141161
142162async execute ( this :IExecuteFunctions ) :Promise < INodeExecutionData [ ] [ ] > {
143163
144164let waitTill = new Date ( WAIT_TIME_UNLIMITED ) ;
145-
165+ const staticData = this . getWorkflowStaticData ( 'node' ) ;
166+ staticData . previousNodeData = this . getInputData ( ) . map ( item => item . json ) ;
146167await this . putExecutionToWait ( waitTill ) ;
147168return [ this . getInputData ( ) ] ;
148169}