1
1
import {
2
- INodeType ,
3
- INodeTypeDescription ,
2
+ INodeType ,
3
+ INodeTypeDescription ,
4
4
ILoadOptionsFunctions ,
5
5
INodeListSearchResult ,
6
6
IExecuteFunctions ,
@@ -15,22 +15,22 @@ import { apiRequest } from './GenericFunctions';
15
15
import isbot from 'isbot' ;
16
16
17
17
interface LowcoderAppType {
18
- applicationId : string ;
19
- name : string ;
18
+ applicationId : string ;
19
+ name : string ;
20
20
applicationType : number
21
21
}
22
22
23
23
const WAIT_TIME_UNLIMITED = '3000-01-01T00:00:00.000Z' ;
24
24
25
25
export class Lowcoder implements INodeType {
26
- description : INodeTypeDescription = {
26
+ description : INodeTypeDescription = {
27
27
displayName : 'Lowcoder' ,
28
28
name : 'lowcoder' ,
29
29
// eslint-disable-next-line n8n-nodes-base/node-class-description-icon-not-svg
30
30
icon : 'file:lowcoder.png' ,
31
31
group : [ 'transform' ] ,
32
32
version : 1 ,
33
- subtitle : '=app:{{ $parameter["appId"]' ,
33
+ subtitle : '=app:{{ $parameter["appId"]' ,
34
34
description : 'Consume Lowcoder API' ,
35
35
defaults : {
36
36
name : 'Lowcoder' ,
@@ -54,23 +54,23 @@ export class Lowcoder implements INodeType {
54
54
responsePropertyName : '={{$parameter["options"]["responsePropertyName"]}}' ,
55
55
responseHeaders : '={{$parameter["options"]["responseHeaders"]}}' ,
56
56
path : '={{$parameter["appId"] || ""}}' ,
57
- restartWebhook : true ,
57
+ restartWebhook : true ,
58
58
} ,
59
- ] ,
59
+ ] ,
60
60
properties : [
61
61
...appFields ,
62
62
{
63
- displayName : 'Resume the workflow by calling this Webhook: http(s)://{n8n-url}/webhook-waiting/{Workflow-Execution-ID}/{Lowcoder-App-ID}' ,
64
- name : 'webhookNotice' ,
65
- type : 'notice' ,
66
- default : '' ,
67
- } ,
68
- {
69
- displayName : 'The Workflow-Execution-ID is available via the n8n Rest API' ,
70
- name : 'webhookNotice' ,
71
- type : 'notice' ,
72
- default : '' ,
73
- } ,
63
+ displayName : 'Resume the workflow by calling this Webhook: http(s)://{n8n-url}/webhook-waiting/{Workflow-Execution-ID}/{Lowcoder-App-ID}' ,
64
+ name : 'webhookNotice' ,
65
+ type : 'notice' ,
66
+ default : '' ,
67
+ } ,
68
+ {
69
+ displayName : 'The Workflow-Execution-ID is available via the n8n Rest API' ,
70
+ name : 'webhookNotice' ,
71
+ type : 'notice' ,
72
+ default : '' ,
73
+ } ,
74
74
httpMethodsProperty ,
75
75
optionsProperty ,
76
76
{
@@ -81,55 +81,56 @@ export class Lowcoder implements INodeType {
81
81
description : 'The HTTP response code to return' ,
82
82
} ,
83
83
] ,
84
- } ;
84
+ } ;
85
85
86
86
methods = {
87
- listSearch : {
88
- async searchApps (
89
- this : ILoadOptionsFunctions ,
90
- query ?: string ,
91
- ) : Promise < INodeListSearchResult > {
92
- const searchResults = await apiRequest . call (
93
- this ,
94
- 'GET' ,
95
- 'applications/list' ,
96
- { } ,
97
- {
98
- query,
87
+ listSearch : {
88
+ async searchApps (
89
+ this : ILoadOptionsFunctions ,
90
+ query ?: string ,
91
+ ) : Promise < INodeListSearchResult > {
92
+
93
+ const searchResults = await apiRequest . call (
94
+ this ,
95
+ 'GET' ,
96
+ 'applications/list' ,
97
+ { } ,
98
+ {
99
+ query,
99
100
withContainerSize : false
100
- } ,
101
- ) ;
102
- console . log ( searchResults ) ;
103
- return {
104
- results : searchResults . data . map ( ( b : LowcoderAppType ) => ( {
105
- name : `${ b . name } (${ b . applicationType == 2 ? "Module" : "App" } )` ,
106
- value : b . applicationId ,
107
- } ) ) ,
108
- } ;
109
- } ,
110
- } ,
111
- } ;
101
+ } ,
102
+ ) ;
103
+ console . log ( searchResults ) ;
104
+ return {
105
+ results : searchResults . data . map ( ( b : LowcoderAppType ) => ( {
106
+ name : `${ b . name } (${ b . applicationType == 2 ? "Module" : "App" } )` ,
107
+ value : b . applicationId ,
108
+ } ) ) ,
109
+ } ;
110
+ } ,
111
+ } ,
112
+ } ;
112
113
113
114
async webhook ( this : IWebhookFunctions ) : Promise < IWebhookResponseData > {
114
- const options = this . getNodeParameter ( 'options' , { } ) as {
115
- binaryData : boolean ;
116
- ignoreBots : boolean ;
117
- rawBody : Buffer ;
118
- responseData ?: string ;
115
+ const options = this . getNodeParameter ( 'options' , { } ) as {
116
+ binaryData : boolean ;
117
+ ignoreBots : boolean ;
118
+ rawBody : Buffer ;
119
+ responseData ?: string ;
119
120
responseCode ?: number ;
120
- } ;
121
- const req = this . getRequestObject ( ) ;
122
- const resp = this . getResponseObject ( ) ;
121
+ } ;
122
+ const req = this . getRequestObject ( ) ;
123
+ const resp = this . getResponseObject ( ) ;
123
124
124
- try {
125
- if ( options . ignoreBots && isbot ( req . headers [ 'user-agent' ] ) ) {
126
- throw new NodeApiError ( this . getNode ( ) , { } , { message : 'Authorization data is wrong!' } ) ;
125
+ try {
126
+ if ( options . ignoreBots && isbot ( req . headers [ 'user-agent' ] ) ) {
127
+ throw new NodeApiError ( this . getNode ( ) , { } , { message : 'Authorization data is wrong!' } ) ;
127
128
}
128
- } catch ( error ) {
129
+ } catch ( error ) {
129
130
resp . writeHead ( error . responseCode || 401 , { 'WWW-Authenticate' : 'Basic realm="Webhook"' } ) ;
130
131
resp . end ( error . message ) ;
131
132
return { noWebhookResponse : true } ;
132
- }
133
+ }
133
134
134
135
const type = req . query . type ;
135
136
if ( type === 'resume' ) {
@@ -155,14 +156,15 @@ export class Lowcoder implements INodeType {
155
156
resp . setHeader ( 'Content-Type' , 'application/json' ) ;
156
157
resp . end ( JSON . stringify ( { message : 'Static response: workflow not resumed' , type, previousData } ) ) ;
157
158
return { noWebhookResponse : true } ;
158
- }
159
- }
159
+ }
160
+ }
161
+
162
+ async execute ( this : IExecuteFunctions ) : Promise < INodeExecutionData [ ] [ ] > {
160
163
161
- async execute ( this : IExecuteFunctions ) : Promise < INodeExecutionData [ ] [ ] > {
162
164
let waitTill = new Date ( WAIT_TIME_UNLIMITED ) ;
163
165
const staticData = this . getWorkflowStaticData ( 'node' ) ;
164
166
staticData . previousNodeData = this . getInputData ( ) . map ( item => item . json ) ;
165
167
await this . putExecutionToWait ( waitTill ) ;
166
- return [ this . getInputData ( ) ] ;
167
- }
168
+ return [ this . getInputData ( ) ] ;
169
+ }
168
170
}
0 commit comments