11import {
2- INodeType ,
3- INodeTypeDescription ,
2+ INodeType ,
3+ INodeTypeDescription ,
44ILoadOptionsFunctions ,
55INodeListSearchResult ,
66IExecuteFunctions ,
@@ -15,22 +15,22 @@ import { apiRequest } from './GenericFunctions';
1515import isbot from 'isbot' ;
1616
1717interface LowcoderAppType {
18- applicationId :string ;
19- name :string ;
18+ applicationId :string ;
19+ name :string ;
2020applicationType :number
2121}
2222
2323const WAIT_TIME_UNLIMITED = '3000-01-01T00:00:00.000Z' ;
2424
2525export class Lowcoder implements INodeType {
26- description :INodeTypeDescription = {
26+ description :INodeTypeDescription = {
2727displayName :'Lowcoder' ,
2828name :'lowcoder' ,
2929// eslint-disable-next-line n8n-nodes-base/node-class-description-icon-not-svg
3030icon :'file:lowcoder.png' ,
3131group :[ 'transform' ] ,
3232version :1 ,
33- subtitle :'=app:{{ $parameter["appId"]' ,
33+ subtitle :'=app:{{ $parameter["appId"]' ,
3434description :'Consume Lowcoder API' ,
3535defaults :{
3636name :'Lowcoder' ,
@@ -54,23 +54,23 @@ export class Lowcoder implements INodeType {
5454responsePropertyName :'={{$parameter["options"]["responsePropertyName"]}}' ,
5555responseHeaders :'={{$parameter["options"]["responseHeaders"]}}' ,
5656path :'={{$parameter["appId"] || ""}}' ,
57- restartWebhook :true ,
57+ restartWebhook :true ,
5858} ,
59- ] ,
59+ ] ,
6060properties :[
6161 ...appFields ,
6262{
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+ } ,
7474httpMethodsProperty ,
7575optionsProperty ,
7676{
@@ -81,55 +81,56 @@ export class Lowcoder implements INodeType {
8181description :'The HTTP response code to return' ,
8282} ,
8383] ,
84- } ;
84+ } ;
8585
8686methods = {
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,
99100withContainerSize :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+ } ;
112113
113114async 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 ;
119120responseCode ?:number ;
120- } ;
121- const req = this . getRequestObject ( ) ;
122- const resp = this . getResponseObject ( ) ;
121+ } ;
122+ const req = this . getRequestObject ( ) ;
123+ const resp = this . getResponseObject ( ) ;
123124
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!' } ) ;
127128}
128- } catch ( error ) {
129+ } catch ( error ) {
129130resp . writeHead ( error . responseCode || 401 , { 'WWW-Authenticate' :'Basic realm="Webhook"' } ) ;
130131resp . end ( error . message ) ;
131132return { noWebhookResponse :true } ;
132- }
133+ }
133134
134135const type = req . query . type ;
135136if ( type === 'resume' ) {
@@ -155,14 +156,15 @@ export class Lowcoder implements INodeType {
155156resp . setHeader ( 'Content-Type' , 'application/json' ) ;
156157resp . end ( JSON . stringify ( { message :'Static response: workflow not resumed' , type, previousData} ) ) ;
157158return { noWebhookResponse :true } ;
158- }
159- }
159+ }
160+ }
161+
162+ async execute ( this :IExecuteFunctions ) :Promise < INodeExecutionData [ ] [ ] > {
160163
161- async execute ( this :IExecuteFunctions ) :Promise < INodeExecutionData [ ] [ ] > {
162164let waitTill = new Date ( WAIT_TIME_UNLIMITED ) ;
163165const staticData = this . getWorkflowStaticData ( 'node' ) ;
164166staticData . previousNodeData = this . getInputData ( ) . map ( item => item . json ) ;
165167await this . putExecutionToWait ( waitTill ) ;
166- return [ this . getInputData ( ) ] ;
167- }
168+ return [ this . getInputData ( ) ] ;
169+ }
168170}