mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
✨ Add Bubble.io Node (#1493)
* 🎉 Register node and credentials * 🎨 Add SVG icon * 🎨 Fix SVG icon size and positioning * ⚡ Add API credentials * ⚡ Add description for object * ⚡ Add generic functions * ⚡ Add preliminary node * ⚡ Improvements * ⚡ Minor improvements Co-authored-by: ricardo <ricardoespinoza105@gmail.com> Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
This commit is contained in:
101
packages/nodes-base/nodes/Bubble/GenericFunctions.ts
Normal file
101
packages/nodes-base/nodes/Bubble/GenericFunctions.ts
Normal file
@@ -0,0 +1,101 @@
|
||||
import {
|
||||
IExecuteFunctions,
|
||||
IHookFunctions,
|
||||
} from 'n8n-core';
|
||||
|
||||
import {
|
||||
IDataObject,
|
||||
ILoadOptionsFunctions,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import {
|
||||
OptionsWithUri,
|
||||
} from 'request';
|
||||
|
||||
/**
|
||||
* Make an authenticated API request to Bubble.
|
||||
*/
|
||||
export async function bubbleApiRequest(
|
||||
this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions,
|
||||
method: string,
|
||||
endpoint: string,
|
||||
body: IDataObject,
|
||||
qs: IDataObject,
|
||||
) {
|
||||
|
||||
const { apiToken, appName, domain, environment, hosting } = this.getCredentials('bubbleApi') as {
|
||||
apiToken: string,
|
||||
appName: string,
|
||||
domain: string,
|
||||
environment: 'development' | 'live',
|
||||
hosting: 'bubbleHosted' | 'selfHosted',
|
||||
};
|
||||
|
||||
const rootUrl = hosting === 'bubbleHosted' ? `https://${appName}.bubbleapps.io` : domain;
|
||||
const urlSegment = environment === 'development' ? '/version-test/api/1.1' : '/api/1.1';
|
||||
|
||||
const options: OptionsWithUri = {
|
||||
headers: {
|
||||
'user-agent': 'n8n',
|
||||
'Authorization': `Bearer ${apiToken}`,
|
||||
},
|
||||
method,
|
||||
uri: `${rootUrl}${urlSegment}${endpoint}`,
|
||||
qs,
|
||||
body,
|
||||
json: true,
|
||||
};
|
||||
|
||||
if (!Object.keys(body).length) {
|
||||
delete options.body;
|
||||
}
|
||||
|
||||
if (!Object.keys(qs).length) {
|
||||
delete options.qs;
|
||||
}
|
||||
|
||||
try {
|
||||
return await this.helpers.request!(options);
|
||||
} catch (error) {
|
||||
if (error?.response?.body?.body?.message) {
|
||||
const errorMessage = error.response.body.body.message;
|
||||
throw new Error(`Bubble.io error response [${error.statusCode}]: ${errorMessage}`);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Make an authenticated API request to Bubble and return all results.
|
||||
*/
|
||||
export async function bubbleApiRequestAllItems(
|
||||
this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions,
|
||||
method: string,
|
||||
endpoint: string,
|
||||
body: IDataObject,
|
||||
qs: IDataObject,
|
||||
) {
|
||||
const returnData: IDataObject[] = [];
|
||||
|
||||
let responseData;
|
||||
qs.limit = 100;
|
||||
do {
|
||||
responseData = await bubbleApiRequest.call(this, method, endpoint, body, qs);
|
||||
qs.cursor = responseData.cursor;
|
||||
returnData.push.apply(returnData, responseData['response']['results']);
|
||||
} while (
|
||||
responseData.response.remaining !== 0
|
||||
);
|
||||
|
||||
return returnData;
|
||||
}
|
||||
|
||||
export function validateJSON(json: string | undefined): any { // tslint:disable-line:no-any
|
||||
let result;
|
||||
try {
|
||||
result = JSON.parse(json!);
|
||||
} catch (exception) {
|
||||
result = undefined;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
Reference in New Issue
Block a user