mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-25 20:54:07 -08:00
d6239d5bfb
* Update Compression node * Update Crypto node * Update DateTime node * Update EditImage node * Update EmailSend node * Update ExecuteWorkflow node * Update FTP node * Update Function node * Update FunctionItem node * Update ExecuteCommand node * Update OpenWeatherMap node * Update ReadBinaryFile node * Update ReadPdf node * Update RssFeedRead node & add URL validation * Update SpreadsheetFile node * Update Switch node * Update WriteBinaryFile node * Update Xml node * Update ActiveCampaign node * Update Airtable node * Update ApiTemplateIo node * Update Asana node * Update AwsLambda node * Update AwsSns node * Update AwsComprehend node * Update AwsRekognition node * Update AwsS3 node * Fix Error item * Update AwsSes node * Update AwsSqs node * Update Amqp node * Update Bitly node * Update Box node * Update Brandfetch node * Update CircleCi node * Update Clearbit node * Update ClickUp node * Update Cockpit node * Update CoinGecko node * Update Contentful node * Update ConvertKit node * Update Cortex node * Update CustomerIo node * Update DeepL node * Update Demio node * Update Disqus node * Update Drift node * Update Dropbox node * Update GetResponse node * Refactor & Update Ghost node * Update Github node * Update Gitlab node * Update GoogleAnalytics node * Update GoogleBooks node * Update GoogleCalendar node * Update GoogleDrive node * Update Gmail node * Update GoogleSheets node * Update GoogleSlides node * Update GoogleTasks node * Update Gotify node * Update GraphQL node * Update HackerNews node * Update Harvest node * Update HtmlExtract node * Update Hubspot node * Update Hunter node * Update Intercom node * Update Kafka node * Refactor & update Line node * Update LinkedIn node * Update Mailchimp node * Update Mandrill node * Update Matrix node * Update Mautic node * Update Medium node * Update MessageBird node * Update Mindee node * Update Mocean node * Update MondayCom node * Update MicrosoftExcel node * Update MicrosoftOneDrive node * Update MicrosoftOutlook node * Update Affinity node * Update Chargebee node * Update Discourse node * Update Freshdesk node * Update YouTube node * Update InvoiceNinja node * Update MailerLite node * Update Mailgun node * Update Mailjet node * Update Mattermost node * Update Nasa node * Update NextCloud node * Update OpenThesaurus node * Update Orbit node * Update PagerDuty node * Update PayPal node * Update Peekalink node * Update Phantombuster node * Update PostHog node * Update ProfitWell node * Refactor & Update Pushbullet node * Update QuickBooks node * Update Raindrop node * Update Reddit node * Update Rocketchat node * Update S3 node * Update Salesforce node * Update SendGrid node * Update SentryIo node * Update Shopify node * Update Signl4 node * Update Slack node * Update Spontit node * Update Spotify node * Update Storyblok node * Refactor & Update Strapi node * Refactor & Update Strava node * Update Taiga node * Refactor & update Tapfiliate node * Update Telegram node * Update TheHive node * Update Todoist node * Update TravisCi node * Update Trello node * Update Twilio node * Update Twist node * Update Twitter node * Update Uplead node * Update UProc node * Update Vero node * Update Webflow node * Update Wekan node * Update Wordpress node * Update Xero node * Update Yourls node * Update Zendesk node * Update ZohoCrm node * Refactor & Update Zoom node * Update Zulip node * Update Clockify node * Update MongoDb node * Update MySql node * Update MicrosoftTeams node * Update Stackby node * Refactor Discourse node * Support corner-case in Github node update * Support corner-case in Gitlab node update * Refactor & Update GoogleContacts node * Refactor Mindee node * Update Coda node * Lint fixes * Update Beeminder node * Update Google Firebase RealtimeDatabase node * Update HelpScout node * Update Mailcheck node * Update Paddle node * Update Pipedrive node * Update Pushover node * Update Segment node * Refactor & Update Vonage node * Added new conditions to warnings on execute batch cmd * Added keep only properties flag * Fixed code for keep only props * Added dependencies for image editing Co-authored-by: dali <servfrdali@yahoo.fr>
462 lines
13 KiB
TypeScript
462 lines
13 KiB
TypeScript
import {
|
|
BINARY_ENCODING,
|
|
IExecuteFunctions,
|
|
} from 'n8n-core';
|
|
|
|
import {
|
|
IBinaryData,
|
|
IDataObject,
|
|
ILoadOptionsFunctions,
|
|
INodeExecutionData,
|
|
INodeType,
|
|
INodeTypeDescription,
|
|
NodeOperationError,
|
|
} from 'n8n-workflow';
|
|
|
|
import {
|
|
isEmpty,
|
|
omit,
|
|
} from 'lodash';
|
|
|
|
import {
|
|
raindropApiRequest,
|
|
} from './GenericFunctions';
|
|
|
|
import {
|
|
bookmarkFields,
|
|
bookmarkOperations,
|
|
collectionFields,
|
|
collectionOperations,
|
|
tagFields,
|
|
tagOperations,
|
|
userFields,
|
|
userOperations,
|
|
} from './descriptions';
|
|
|
|
export class Raindrop implements INodeType {
|
|
description: INodeTypeDescription = {
|
|
displayName: 'Raindrop',
|
|
name: 'raindrop',
|
|
icon: 'file:raindrop.svg',
|
|
group: ['transform'],
|
|
version: 1,
|
|
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
|
description: 'Consume the Raindrop API',
|
|
defaults: {
|
|
name: 'Raindrop',
|
|
color: '#1988e0',
|
|
},
|
|
inputs: ['main'],
|
|
outputs: ['main'],
|
|
credentials: [
|
|
{
|
|
name: 'raindropOAuth2Api',
|
|
required: true,
|
|
},
|
|
],
|
|
properties: [
|
|
{
|
|
displayName: 'Resource',
|
|
name: 'resource',
|
|
type: 'options',
|
|
options: [
|
|
{
|
|
name: 'Bookmark',
|
|
value: 'bookmark',
|
|
},
|
|
{
|
|
name: 'Collection',
|
|
value: 'collection',
|
|
},
|
|
{
|
|
name: 'Tag',
|
|
value: 'tag',
|
|
},
|
|
{
|
|
name: 'User',
|
|
value: 'user',
|
|
},
|
|
],
|
|
default: 'collection',
|
|
description: 'Resource to consume',
|
|
},
|
|
...bookmarkOperations,
|
|
...bookmarkFields,
|
|
...collectionOperations,
|
|
...collectionFields,
|
|
...tagOperations,
|
|
...tagFields,
|
|
...userOperations,
|
|
...userFields,
|
|
],
|
|
};
|
|
|
|
methods = {
|
|
loadOptions: {
|
|
async getCollections(this: ILoadOptionsFunctions) {
|
|
const responseData = await raindropApiRequest.call(this, 'GET', '/collections', {}, {});
|
|
return responseData.items.map((item: { title: string, _id: string }) => ({
|
|
name: item.title,
|
|
value: item._id,
|
|
}));
|
|
},
|
|
},
|
|
};
|
|
|
|
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
|
const items = this.getInputData();
|
|
|
|
const resource = this.getNodeParameter('resource', 0) as string;
|
|
const operation = this.getNodeParameter('operation', 0) as string;
|
|
|
|
let responseData;
|
|
const returnData: IDataObject[] = [];
|
|
|
|
for (let i = 0; i < items.length; i++) {
|
|
try {
|
|
if (resource === 'bookmark') {
|
|
|
|
// *********************************************************************
|
|
// bookmark
|
|
// *********************************************************************
|
|
|
|
// https://developer.raindrop.io/v1/raindrops
|
|
|
|
if (operation === 'create') {
|
|
|
|
// ----------------------------------
|
|
// bookmark: create
|
|
// ----------------------------------
|
|
|
|
const body: IDataObject = {
|
|
link: this.getNodeParameter('link', i),
|
|
collection: {
|
|
'$id': this.getNodeParameter('collectionId', i),
|
|
},
|
|
};
|
|
|
|
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
|
|
|
if (!isEmpty(additionalFields)) {
|
|
Object.assign(body, additionalFields);
|
|
}
|
|
|
|
if (additionalFields.pleaseParse === true) {
|
|
body.pleaseParse = {};
|
|
delete additionalFields.pleaseParse;
|
|
}
|
|
|
|
if (additionalFields.tags) {
|
|
body.tags = (additionalFields.tags as string).split(',').map(tag => tag.trim()) as string[];
|
|
}
|
|
|
|
const endpoint = `/raindrop`;
|
|
responseData = await raindropApiRequest.call(this, 'POST', endpoint, {}, body);
|
|
responseData = responseData.item;
|
|
|
|
} else if (operation === 'delete') {
|
|
|
|
// ----------------------------------
|
|
// bookmark: delete
|
|
// ----------------------------------
|
|
|
|
const bookmarkId = this.getNodeParameter('bookmarkId', i);
|
|
const endpoint = `/raindrop/${bookmarkId}`;
|
|
responseData = await raindropApiRequest.call(this, 'DELETE', endpoint, {}, {});
|
|
|
|
} else if (operation === 'get') {
|
|
|
|
// ----------------------------------
|
|
// bookmark: get
|
|
// ----------------------------------
|
|
|
|
const bookmarkId = this.getNodeParameter('bookmarkId', i);
|
|
const endpoint = `/raindrop/${bookmarkId}`;
|
|
responseData = await raindropApiRequest.call(this, 'GET', endpoint, {}, {});
|
|
responseData = responseData.item;
|
|
|
|
} else if (operation === 'getAll') {
|
|
|
|
// ----------------------------------
|
|
// bookmark: getAll
|
|
// ----------------------------------
|
|
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
|
|
|
const collectionId = this.getNodeParameter('collectionId', i);
|
|
const endpoint = `/raindrops/${collectionId}`;
|
|
responseData = await raindropApiRequest.call(this, 'GET', endpoint, {}, {});
|
|
responseData = responseData.items;
|
|
|
|
|
|
if (returnAll === false) {
|
|
const limit = this.getNodeParameter('limit', 0) as number;
|
|
responseData = responseData.slice(0, limit);
|
|
}
|
|
|
|
} else if (operation === 'update') {
|
|
|
|
// ----------------------------------
|
|
// bookmark: update
|
|
// ----------------------------------
|
|
|
|
const bookmarkId = this.getNodeParameter('bookmarkId', i);
|
|
|
|
const body = {} as IDataObject;
|
|
|
|
const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
|
|
|
|
if (isEmpty(updateFields)) {
|
|
throw new NodeOperationError(this.getNode(), `Please enter at least one field to update for the ${resource}.`);
|
|
}
|
|
|
|
Object.assign(body, updateFields);
|
|
|
|
if (updateFields.collectionId) {
|
|
body.collection = {
|
|
'$id': updateFields.collectionId,
|
|
};
|
|
delete updateFields.collectionId;
|
|
}
|
|
|
|
if (updateFields.tags) {
|
|
body.tags = (updateFields.tags as string).split(',').map(tag => tag.trim()) as string[];
|
|
}
|
|
|
|
const endpoint = `/raindrop/${bookmarkId}`;
|
|
responseData = await raindropApiRequest.call(this, 'PUT', endpoint, {}, body);
|
|
responseData = responseData.item;
|
|
}
|
|
} else if (resource === 'collection') {
|
|
|
|
// *********************************************************************
|
|
// collection
|
|
// *********************************************************************
|
|
|
|
// https://developer.raindrop.io/v1/collections/methods
|
|
|
|
if (operation === 'create') {
|
|
|
|
// ----------------------------------
|
|
// collection: create
|
|
// ----------------------------------
|
|
|
|
const body = {
|
|
title: this.getNodeParameter('title', i),
|
|
} as IDataObject;
|
|
|
|
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
|
|
|
if (!isEmpty(additionalFields)) {
|
|
Object.assign(body, additionalFields);
|
|
}
|
|
|
|
if (additionalFields.cover) {
|
|
body.cover = [body.cover];
|
|
}
|
|
|
|
if (additionalFields.parentId) {
|
|
body['parent.$id'] = parseInt(additionalFields.parentId as string, 10) as number;
|
|
delete additionalFields.parentId;
|
|
}
|
|
|
|
responseData = await raindropApiRequest.call(this, 'POST', `/collection`, {}, body);
|
|
responseData = responseData.item;
|
|
|
|
} else if (operation === 'delete') {
|
|
|
|
// ----------------------------------
|
|
// collection: delete
|
|
// ----------------------------------
|
|
|
|
const collectionId = this.getNodeParameter('collectionId', i);
|
|
const endpoint = `/collection/${collectionId}`;
|
|
responseData = await raindropApiRequest.call(this, 'DELETE', endpoint, {}, {});
|
|
|
|
} else if (operation === 'get') {
|
|
|
|
// ----------------------------------
|
|
// collection: get
|
|
// ----------------------------------
|
|
|
|
const collectionId = this.getNodeParameter('collectionId', i);
|
|
const endpoint = `/collection/${collectionId}`;
|
|
responseData = await raindropApiRequest.call(this, 'GET', endpoint, {}, {});
|
|
responseData = responseData.item;
|
|
|
|
} else if (operation === 'getAll') {
|
|
|
|
// ----------------------------------
|
|
// collection: getAll
|
|
// ----------------------------------
|
|
|
|
const returnAll = this.getNodeParameter('returnAll', 0) as boolean;
|
|
|
|
const endpoint = this.getNodeParameter('type', i) === 'parent'
|
|
? '/collections'
|
|
: '/collections/childrens';
|
|
|
|
responseData = await raindropApiRequest.call(this, 'GET', endpoint, {}, {});
|
|
responseData = responseData.items;
|
|
|
|
if (returnAll === false) {
|
|
const limit = this.getNodeParameter('limit', 0) as number;
|
|
responseData = responseData.slice(0, limit);
|
|
}
|
|
|
|
} else if (operation === 'update') {
|
|
|
|
// ----------------------------------
|
|
// collection: update
|
|
// ----------------------------------
|
|
|
|
const collectionId = this.getNodeParameter('collectionId', i);
|
|
|
|
const body = {} as IDataObject;
|
|
|
|
const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
|
|
|
|
if (isEmpty(updateFields)) {
|
|
throw new NodeOperationError(this.getNode(), `Please enter at least one field to update for the ${resource}.`);
|
|
}
|
|
|
|
if (updateFields.parentId) {
|
|
body['parent.$id'] = parseInt(updateFields.parentId as string, 10) as number;
|
|
delete updateFields.parentId;
|
|
}
|
|
|
|
Object.assign(body, omit(updateFields, 'binaryPropertyName'));
|
|
|
|
const endpoint = `/collection/${collectionId}`;
|
|
responseData = await raindropApiRequest.call(this, 'PUT', endpoint, {}, body);
|
|
responseData = responseData.item;
|
|
|
|
// cover-specific endpoint
|
|
|
|
if (updateFields.cover) {
|
|
|
|
if (!items[i].binary) {
|
|
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!');
|
|
}
|
|
|
|
if (!updateFields.cover) {
|
|
throw new NodeOperationError(this.getNode(), 'Please enter a binary property to upload a cover image.');
|
|
}
|
|
|
|
const binaryPropertyName = updateFields.cover as string;
|
|
|
|
const binaryData = items[i].binary![binaryPropertyName] as IBinaryData;
|
|
|
|
const formData = {
|
|
cover: {
|
|
value: Buffer.from(binaryData.data, BINARY_ENCODING),
|
|
options: {
|
|
filename: binaryData.fileName,
|
|
contentType: binaryData.mimeType,
|
|
},
|
|
},
|
|
};
|
|
|
|
const endpoint = `/collection/${collectionId}/cover`;
|
|
responseData = await raindropApiRequest.call(this, 'PUT', endpoint, {}, {}, { 'Content-Type': 'multipart/form-data', formData });
|
|
responseData = responseData.item;
|
|
}
|
|
}
|
|
|
|
} else if (resource === 'user') {
|
|
|
|
// *********************************************************************
|
|
// user
|
|
// *********************************************************************
|
|
|
|
// https://developer.raindrop.io/v1/user
|
|
|
|
if (operation === 'get') {
|
|
|
|
// ----------------------------------
|
|
// user: get
|
|
// ----------------------------------
|
|
|
|
const self = this.getNodeParameter('self', i);
|
|
let endpoint = '/user';
|
|
|
|
if (self === false) {
|
|
const userId = this.getNodeParameter('userId', i);
|
|
endpoint += `/${userId}`;
|
|
}
|
|
|
|
responseData = await raindropApiRequest.call(this, 'GET', endpoint, {}, {});
|
|
responseData = responseData.user;
|
|
|
|
}
|
|
|
|
} else if (resource === 'tag') {
|
|
|
|
// *********************************************************************
|
|
// tag
|
|
// *********************************************************************
|
|
|
|
// https://developer.raindrop.io/v1/tags
|
|
|
|
if (operation === 'delete') {
|
|
|
|
// ----------------------------------
|
|
// tag: delete
|
|
// ----------------------------------
|
|
|
|
let endpoint = `/tags`;
|
|
|
|
const body: IDataObject = {
|
|
tags: (this.getNodeParameter('tags', i) as string).split(',') as string[],
|
|
};
|
|
|
|
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
|
|
|
if (additionalFields.collectionId) {
|
|
endpoint += `/${additionalFields.collectionId}`;
|
|
}
|
|
|
|
responseData = await raindropApiRequest.call(this, 'DELETE', endpoint, {}, body);
|
|
|
|
} else if (operation === 'getAll') {
|
|
|
|
// ----------------------------------
|
|
// tag: getAll
|
|
// ----------------------------------
|
|
|
|
let endpoint = `/tags`;
|
|
|
|
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
|
|
|
const filter = this.getNodeParameter('filters', i) as IDataObject;
|
|
|
|
if (filter.collectionId) {
|
|
endpoint += `/${filter.collectionId}`;
|
|
}
|
|
|
|
responseData = await raindropApiRequest.call(this, 'GET', endpoint, {}, {});
|
|
responseData = responseData.items;
|
|
|
|
if (returnAll === false) {
|
|
const limit = this.getNodeParameter('limit', 0) as number;
|
|
responseData = responseData.slice(0, limit);
|
|
}
|
|
}
|
|
}
|
|
|
|
Array.isArray(responseData)
|
|
? returnData.push(...responseData)
|
|
: returnData.push(responseData);
|
|
} catch (error) {
|
|
if (this.continueOnFail()) {
|
|
returnData.push({ error: error.message });
|
|
continue;
|
|
}
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
return [this.helpers.returnJsonArray(returnData)];
|
|
|
|
}
|
|
}
|