1
-
2
-
3
1
import {
4
2
INodeType ,
5
3
INodeTypeDescription ,
@@ -50,10 +48,9 @@ export class Lowcoder implements INodeType {
50
48
name : 'default' ,
51
49
httpMethod : '={{$parameter["httpMethod"]}}' ,
52
50
isFullPath : true ,
53
- responseCode : '200' ,
54
51
responseMode : 'onReceived' ,
55
- responseData : 'allEntries ' ,
56
- responseContentType : '={{$parameter["options"]["responseContentType"]}}' ,
52
+ responseData : '={{$parameter["options"]["responseData"] || "Workflow Resumed!"}} ' ,
53
+ responseContentType : '={{$parameter["options"]["responseContentType"] || "application/json" }}' ,
57
54
responsePropertyName : '={{$parameter["options"]["responsePropertyName"]}}' ,
58
55
responseHeaders : '={{$parameter["options"]["responseHeaders"]}}' ,
59
56
path : '={{$parameter["appId"] || ""}}' ,
@@ -75,7 +72,14 @@ export class Lowcoder implements INodeType {
75
72
default : '' ,
76
73
} ,
77
74
httpMethodsProperty ,
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
+ } ,
79
83
] ,
80
84
} ;
81
85
@@ -113,6 +117,7 @@ export class Lowcoder implements INodeType {
113
117
ignoreBots : boolean ;
114
118
rawBody : Buffer ;
115
119
responseData ?: string ;
120
+ responseCode ?: number ;
116
121
} ;
117
122
const req = this . getRequestObject ( ) ;
118
123
const resp = this . getResponseObject ( ) ;
@@ -122,27 +127,43 @@ export class Lowcoder implements INodeType {
122
127
throw new NodeApiError ( this . getNode ( ) , { } , { message : 'Authorization data is wrong!' } ) ;
123
128
}
124
129
} catch ( error ) {
125
- resp . writeHead ( error . responseCode , { 'WWW-Authenticate' : 'Basic realm="Webhook"' } ) ;
130
+ resp . writeHead ( error . responseCode || 401 , { 'WWW-Authenticate' : 'Basic realm="Webhook"' } ) ;
126
131
resp . end ( error . message ) ;
127
132
return { noWebhookResponse : true } ;
128
133
}
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
+ }
140
160
}
141
161
142
162
async execute ( this : IExecuteFunctions ) : Promise < INodeExecutionData [ ] [ ] > {
143
163
144
164
let waitTill = new Date ( WAIT_TIME_UNLIMITED ) ;
145
-
165
+ const staticData = this . getWorkflowStaticData ( 'node' ) ;
166
+ staticData . previousNodeData = this . getInputData ( ) . map ( item => item . json ) ;
146
167
await this . putExecutionToWait ( waitTill ) ;
147
168
return [ this . getInputData ( ) ] ;
148
169
}
0 commit comments