2023-03-09 09:13:15 -08:00
|
|
|
import type {
|
|
|
|
IExecuteFunctions,
|
|
|
|
IHookFunctions,
|
|
|
|
IDataObject,
|
|
|
|
ILoadOptionsFunctions,
|
|
|
|
IPairedItemData,
|
|
|
|
} from 'n8n-workflow';
|
2021-11-05 10:37:50 -07:00
|
|
|
|
2023-01-27 03:22:44 -08:00
|
|
|
import type { OptionsWithUri } from 'request';
|
2021-11-05 10:37:50 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Make an authenticated API request to Bubble.
|
|
|
|
*/
|
|
|
|
export async function dropcontactApiRequest(
|
|
|
|
this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions,
|
|
|
|
method: string,
|
|
|
|
endpoint: string,
|
|
|
|
body: IDataObject,
|
|
|
|
qs: IDataObject,
|
|
|
|
) {
|
|
|
|
const options: OptionsWithUri = {
|
|
|
|
method,
|
|
|
|
uri: `https://api.dropcontact.io${endpoint}`,
|
|
|
|
qs,
|
|
|
|
body,
|
|
|
|
json: true,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!Object.keys(body).length) {
|
|
|
|
delete options.body;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Object.keys(qs).length) {
|
|
|
|
delete options.qs;
|
|
|
|
}
|
|
|
|
|
2022-11-22 08:57:17 -08:00
|
|
|
return this.helpers.requestWithAuthentication.call(this, 'dropcontactApi', options);
|
2021-11-05 10:37:50 -07:00
|
|
|
}
|
2023-01-31 11:39:20 -08:00
|
|
|
|
|
|
|
export function mapPairedItemsFrom<T>(iterable: Iterable<T> | ArrayLike<T>): IPairedItemData[] {
|
|
|
|
return Array.from(iterable, (_, i) => i).map((index) => {
|
|
|
|
return {
|
|
|
|
item: index,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|