mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
✨ Add Form.io Trigger (#2064)
* Initial commit n8n smartsheet and formio nodes 1. created smarsheet node that can add new rew to a particular smarsheet. 2. created formio trigger node which will listen to form.io form submit event and process data. * Added coloum mapping logic form.io field label to smarsheet column title. API and smartsheet sheetId configuration added to smartsheet node. * Added smartsheet api credentials and used it in smartsheet node. * Added logos to the form.io and smartsheet nodes. Removed smartsheet and form.io npm dependencies from the nodes. Added type check for the variables used. fixed tslint errors in the created nodes. * ⚡ Improvements to #1943 * ⚡ Improvements * ⚡ Improvements * ⚡ Some fixes and improvements Co-authored-by: Parthiban Chandrasekar <pbr.reddys@gmail.com> Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
This commit is contained in:
84
packages/nodes-base/nodes/FormIo/GenericFunctions.ts
Normal file
84
packages/nodes-base/nodes/FormIo/GenericFunctions.ts
Normal file
@@ -0,0 +1,84 @@
|
||||
import {
|
||||
IExecuteFunctions,
|
||||
ILoadOptionsFunctions,
|
||||
} from 'n8n-core';
|
||||
|
||||
import {
|
||||
IDataObject,
|
||||
IHookFunctions,
|
||||
IWebhookFunctions,
|
||||
NodeApiError,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
|
||||
interface IFormIoCredentials {
|
||||
environment: 'cloudHosted' | ' selfHosted';
|
||||
domain?: string;
|
||||
email: string,
|
||||
password: string,
|
||||
}
|
||||
|
||||
/**
|
||||
* Method has the logic to get jwt token from Form.io
|
||||
* @param this
|
||||
*/
|
||||
async function getToken(this: IExecuteFunctions | IWebhookFunctions | IHookFunctions | ILoadOptionsFunctions, credentials: IFormIoCredentials) {
|
||||
const base = credentials.domain || 'https://formio.form.io';
|
||||
const options = {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
method: 'POST',
|
||||
body: {
|
||||
data: {
|
||||
email: credentials.email,
|
||||
password: credentials.password,
|
||||
},
|
||||
},
|
||||
uri: `${base}/user/login`,
|
||||
json: true,
|
||||
resolveWithFullResponse: true,
|
||||
};
|
||||
|
||||
console.log('options');
|
||||
console.log(JSON.stringify(options, null, 2));
|
||||
|
||||
try {
|
||||
const responseObject = await this.helpers.request!(options);
|
||||
return responseObject.headers['x-jwt-token'];
|
||||
} catch (error) {
|
||||
throw new Error(`Authentication Failed for Form.io. Please provide valid credentails/ endpoint details`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method will call register or list webhooks based on the passed method in the parameter
|
||||
* @param this
|
||||
* @param method
|
||||
*/
|
||||
export async function formIoApiRequest(this: IHookFunctions | ILoadOptionsFunctions | IWebhookFunctions, method: string, endpoint: string, body = {}, qs = {}): Promise<any> { // tslint:disable-line:no-any
|
||||
|
||||
const credentials = await this.getCredentials('formIoApi') as unknown as IFormIoCredentials;
|
||||
|
||||
const token = await getToken.call(this, credentials);
|
||||
|
||||
const base = credentials.domain || 'https://api.form.io';
|
||||
|
||||
const options = {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'x-jwt-token': token,
|
||||
},
|
||||
method,
|
||||
body,
|
||||
qs,
|
||||
uri: `${base}${endpoint}`,
|
||||
json: true,
|
||||
};
|
||||
|
||||
try {
|
||||
return await this.helpers.request!.call(this, options);
|
||||
} catch (error) {
|
||||
throw new NodeApiError(this.getNode(), error);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user