n8n/packages/nodes-base/nodes/Raindrop/Raindrop.node.ts

454 lines
13 KiB
TypeScript
Raw Normal View History

import {
BINARY_ENCODING,
IExecuteFunctions,
} from 'n8n-core';
import {
IBinaryData,
IDataObject,
ILoadOptionsFunctions,
INodeExecutionData,
INodeType,
INodeTypeDescription,
:sparkles: Improve node error handling (#1309) * Add path mapping and response error interfaces * Add error handling and throwing functionality * Refactor error handling into a single function * Re-implement error handling in Hacker News node * Fix linting details * Re-implement error handling in Spotify node * Re-implement error handling in G Suite Admin node * :construction: create basic setup NodeError * :construction: add httpCodes * :construction: add path priolist * :construction: handle statusCode in error, adjust interfaces * :construction: fixing type issues w/Ivan * :construction: add error exploration * 👔 fix linter issues * :wrench: improve object check * :construction: remove path passing from NodeApiError * :construction: add multi error + refactor findProperty method * 👔 allow any * :wrench: handle multi error message callback * :zap: change return type of callback * :zap: add customCallback to MultiError * :construction: refactor to use INode * :hammer: handle arrays, continue search after first null property found * 🚫 refactor method access * :construction: setup NodeErrorView * :zap: change timestamp to Date.now * :books: Add documentation for methods and constants * :construction: change message setting * 🚚 move NodeErrors to workflow * :sparkles: add new ErrorView for Nodes * :art: improve error notification * :art: refactor interfaces * :zap: add WorkflowOperationError, refactor error throwing * 👕 fix linter issues * :art: rename param * :bug: fix handling normal errors * :zap: add usage of NodeApiError * :art: fix throw new error instead of constructor * :art: remove unnecessary code/comments * :art: adjusted spacing + updated status messages * :art: fix tab indentation * ✨ Replace current errors with custom errors (#1576) * :zap: Introduce NodeApiError in catch blocks * :zap: Introduce NodeOperationError in nodes * :zap: Add missing errors and remove incompatible * :zap: Fix NodeOperationError in incompatible nodes * :wrench: Adjust error handling in missed nodes PayPal, FileMaker, Reddit, Taiga and Facebook Graph API nodes * :hammer: Adjust Strava Trigger node error handling * :hammer: Adjust AWS nodes error handling * :hammer: Remove duplicate instantiation of NodeApiError * :bug: fix strava trigger node error handling * Add XML parsing to NodeApiError constructor (#1633) * :bug: Remove type annotation from catch variable * :sparkles: Add XML parsing to NodeApiError * :zap: Simplify error handling in Rekognition node * :zap: Pass in XML flag in generic functions * :fire: Remove try/catch wrappers at call sites * :hammer: Refactor setting description from XML * :hammer: Refactor let to const in resource loaders * :zap: Find property in parsed XML * :zap: Change let to const * :fire: Remove unneeded try/catch block * :shirt: Fix linting issues * :bug: Fix errors from merge conflict resolution * :zap: Add custom errors to latest contributions * :shirt: Fix linting issues * :zap: Refactor MongoDB helpers for custom errors * :bug: Correct custom error type * :zap: Apply feedback to A nodes * :zap: Apply feedback to missed A node * :zap: Apply feedback to B-D nodes * :zap: Apply feedback to E-F nodes * :zap: Apply feedback to G nodes * :zap: Apply feedback to H-L nodes * :zap: Apply feedback to M nodes * :zap: Apply feedback to P nodes * :zap: Apply feedback to R nodes * :zap: Apply feedback to S nodes * :zap: Apply feedback to T nodes * :zap: Apply feedback to V-Z nodes * :zap: Add HTTP code to iterable node error * :hammer: Standardize e as error * :hammer: Standardize err as error * :zap: Fix error handling for non-standard nodes Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <1849459+BHesseldieck@users.noreply.github.com>
2021-04-16 09:33:36 -07:00
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++) {
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)) {
:sparkles: Improve node error handling (#1309) * Add path mapping and response error interfaces * Add error handling and throwing functionality * Refactor error handling into a single function * Re-implement error handling in Hacker News node * Fix linting details * Re-implement error handling in Spotify node * Re-implement error handling in G Suite Admin node * :construction: create basic setup NodeError * :construction: add httpCodes * :construction: add path priolist * :construction: handle statusCode in error, adjust interfaces * :construction: fixing type issues w/Ivan * :construction: add error exploration * 👔 fix linter issues * :wrench: improve object check * :construction: remove path passing from NodeApiError * :construction: add multi error + refactor findProperty method * 👔 allow any * :wrench: handle multi error message callback * :zap: change return type of callback * :zap: add customCallback to MultiError * :construction: refactor to use INode * :hammer: handle arrays, continue search after first null property found * 🚫 refactor method access * :construction: setup NodeErrorView * :zap: change timestamp to Date.now * :books: Add documentation for methods and constants * :construction: change message setting * 🚚 move NodeErrors to workflow * :sparkles: add new ErrorView for Nodes * :art: improve error notification * :art: refactor interfaces * :zap: add WorkflowOperationError, refactor error throwing * 👕 fix linter issues * :art: rename param * :bug: fix handling normal errors * :zap: add usage of NodeApiError * :art: fix throw new error instead of constructor * :art: remove unnecessary code/comments * :art: adjusted spacing + updated status messages * :art: fix tab indentation * ✨ Replace current errors with custom errors (#1576) * :zap: Introduce NodeApiError in catch blocks * :zap: Introduce NodeOperationError in nodes * :zap: Add missing errors and remove incompatible * :zap: Fix NodeOperationError in incompatible nodes * :wrench: Adjust error handling in missed nodes PayPal, FileMaker, Reddit, Taiga and Facebook Graph API nodes * :hammer: Adjust Strava Trigger node error handling * :hammer: Adjust AWS nodes error handling * :hammer: Remove duplicate instantiation of NodeApiError * :bug: fix strava trigger node error handling * Add XML parsing to NodeApiError constructor (#1633) * :bug: Remove type annotation from catch variable * :sparkles: Add XML parsing to NodeApiError * :zap: Simplify error handling in Rekognition node * :zap: Pass in XML flag in generic functions * :fire: Remove try/catch wrappers at call sites * :hammer: Refactor setting description from XML * :hammer: Refactor let to const in resource loaders * :zap: Find property in parsed XML * :zap: Change let to const * :fire: Remove unneeded try/catch block * :shirt: Fix linting issues * :bug: Fix errors from merge conflict resolution * :zap: Add custom errors to latest contributions * :shirt: Fix linting issues * :zap: Refactor MongoDB helpers for custom errors * :bug: Correct custom error type * :zap: Apply feedback to A nodes * :zap: Apply feedback to missed A node * :zap: Apply feedback to B-D nodes * :zap: Apply feedback to E-F nodes * :zap: Apply feedback to G nodes * :zap: Apply feedback to H-L nodes * :zap: Apply feedback to M nodes * :zap: Apply feedback to P nodes * :zap: Apply feedback to R nodes * :zap: Apply feedback to S nodes * :zap: Apply feedback to T nodes * :zap: Apply feedback to V-Z nodes * :zap: Add HTTP code to iterable node error * :hammer: Standardize e as error * :hammer: Standardize err as error * :zap: Fix error handling for non-standard nodes Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <1849459+BHesseldieck@users.noreply.github.com>
2021-04-16 09:33:36 -07:00
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)) {
:sparkles: Improve node error handling (#1309) * Add path mapping and response error interfaces * Add error handling and throwing functionality * Refactor error handling into a single function * Re-implement error handling in Hacker News node * Fix linting details * Re-implement error handling in Spotify node * Re-implement error handling in G Suite Admin node * :construction: create basic setup NodeError * :construction: add httpCodes * :construction: add path priolist * :construction: handle statusCode in error, adjust interfaces * :construction: fixing type issues w/Ivan * :construction: add error exploration * 👔 fix linter issues * :wrench: improve object check * :construction: remove path passing from NodeApiError * :construction: add multi error + refactor findProperty method * 👔 allow any * :wrench: handle multi error message callback * :zap: change return type of callback * :zap: add customCallback to MultiError * :construction: refactor to use INode * :hammer: handle arrays, continue search after first null property found * 🚫 refactor method access * :construction: setup NodeErrorView * :zap: change timestamp to Date.now * :books: Add documentation for methods and constants * :construction: change message setting * 🚚 move NodeErrors to workflow * :sparkles: add new ErrorView for Nodes * :art: improve error notification * :art: refactor interfaces * :zap: add WorkflowOperationError, refactor error throwing * 👕 fix linter issues * :art: rename param * :bug: fix handling normal errors * :zap: add usage of NodeApiError * :art: fix throw new error instead of constructor * :art: remove unnecessary code/comments * :art: adjusted spacing + updated status messages * :art: fix tab indentation * ✨ Replace current errors with custom errors (#1576) * :zap: Introduce NodeApiError in catch blocks * :zap: Introduce NodeOperationError in nodes * :zap: Add missing errors and remove incompatible * :zap: Fix NodeOperationError in incompatible nodes * :wrench: Adjust error handling in missed nodes PayPal, FileMaker, Reddit, Taiga and Facebook Graph API nodes * :hammer: Adjust Strava Trigger node error handling * :hammer: Adjust AWS nodes error handling * :hammer: Remove duplicate instantiation of NodeApiError * :bug: fix strava trigger node error handling * Add XML parsing to NodeApiError constructor (#1633) * :bug: Remove type annotation from catch variable * :sparkles: Add XML parsing to NodeApiError * :zap: Simplify error handling in Rekognition node * :zap: Pass in XML flag in generic functions * :fire: Remove try/catch wrappers at call sites * :hammer: Refactor setting description from XML * :hammer: Refactor let to const in resource loaders * :zap: Find property in parsed XML * :zap: Change let to const * :fire: Remove unneeded try/catch block * :shirt: Fix linting issues * :bug: Fix errors from merge conflict resolution * :zap: Add custom errors to latest contributions * :shirt: Fix linting issues * :zap: Refactor MongoDB helpers for custom errors * :bug: Correct custom error type * :zap: Apply feedback to A nodes * :zap: Apply feedback to missed A node * :zap: Apply feedback to B-D nodes * :zap: Apply feedback to E-F nodes * :zap: Apply feedback to G nodes * :zap: Apply feedback to H-L nodes * :zap: Apply feedback to M nodes * :zap: Apply feedback to P nodes * :zap: Apply feedback to R nodes * :zap: Apply feedback to S nodes * :zap: Apply feedback to T nodes * :zap: Apply feedback to V-Z nodes * :zap: Add HTTP code to iterable node error * :hammer: Standardize e as error * :hammer: Standardize err as error * :zap: Fix error handling for non-standard nodes Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <1849459+BHesseldieck@users.noreply.github.com>
2021-04-16 09:33:36 -07:00
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) {
:sparkles: Improve node error handling (#1309) * Add path mapping and response error interfaces * Add error handling and throwing functionality * Refactor error handling into a single function * Re-implement error handling in Hacker News node * Fix linting details * Re-implement error handling in Spotify node * Re-implement error handling in G Suite Admin node * :construction: create basic setup NodeError * :construction: add httpCodes * :construction: add path priolist * :construction: handle statusCode in error, adjust interfaces * :construction: fixing type issues w/Ivan * :construction: add error exploration * 👔 fix linter issues * :wrench: improve object check * :construction: remove path passing from NodeApiError * :construction: add multi error + refactor findProperty method * 👔 allow any * :wrench: handle multi error message callback * :zap: change return type of callback * :zap: add customCallback to MultiError * :construction: refactor to use INode * :hammer: handle arrays, continue search after first null property found * 🚫 refactor method access * :construction: setup NodeErrorView * :zap: change timestamp to Date.now * :books: Add documentation for methods and constants * :construction: change message setting * 🚚 move NodeErrors to workflow * :sparkles: add new ErrorView for Nodes * :art: improve error notification * :art: refactor interfaces * :zap: add WorkflowOperationError, refactor error throwing * 👕 fix linter issues * :art: rename param * :bug: fix handling normal errors * :zap: add usage of NodeApiError * :art: fix throw new error instead of constructor * :art: remove unnecessary code/comments * :art: adjusted spacing + updated status messages * :art: fix tab indentation * ✨ Replace current errors with custom errors (#1576) * :zap: Introduce NodeApiError in catch blocks * :zap: Introduce NodeOperationError in nodes * :zap: Add missing errors and remove incompatible * :zap: Fix NodeOperationError in incompatible nodes * :wrench: Adjust error handling in missed nodes PayPal, FileMaker, Reddit, Taiga and Facebook Graph API nodes * :hammer: Adjust Strava Trigger node error handling * :hammer: Adjust AWS nodes error handling * :hammer: Remove duplicate instantiation of NodeApiError * :bug: fix strava trigger node error handling * Add XML parsing to NodeApiError constructor (#1633) * :bug: Remove type annotation from catch variable * :sparkles: Add XML parsing to NodeApiError * :zap: Simplify error handling in Rekognition node * :zap: Pass in XML flag in generic functions * :fire: Remove try/catch wrappers at call sites * :hammer: Refactor setting description from XML * :hammer: Refactor let to const in resource loaders * :zap: Find property in parsed XML * :zap: Change let to const * :fire: Remove unneeded try/catch block * :shirt: Fix linting issues * :bug: Fix errors from merge conflict resolution * :zap: Add custom errors to latest contributions * :shirt: Fix linting issues * :zap: Refactor MongoDB helpers for custom errors * :bug: Correct custom error type * :zap: Apply feedback to A nodes * :zap: Apply feedback to missed A node * :zap: Apply feedback to B-D nodes * :zap: Apply feedback to E-F nodes * :zap: Apply feedback to G nodes * :zap: Apply feedback to H-L nodes * :zap: Apply feedback to M nodes * :zap: Apply feedback to P nodes * :zap: Apply feedback to R nodes * :zap: Apply feedback to S nodes * :zap: Apply feedback to T nodes * :zap: Apply feedback to V-Z nodes * :zap: Add HTTP code to iterable node error * :hammer: Standardize e as error * :hammer: Standardize err as error * :zap: Fix error handling for non-standard nodes Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <1849459+BHesseldieck@users.noreply.github.com>
2021-04-16 09:33:36 -07:00
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!');
}
if (!updateFields.cover) {
:sparkles: Improve node error handling (#1309) * Add path mapping and response error interfaces * Add error handling and throwing functionality * Refactor error handling into a single function * Re-implement error handling in Hacker News node * Fix linting details * Re-implement error handling in Spotify node * Re-implement error handling in G Suite Admin node * :construction: create basic setup NodeError * :construction: add httpCodes * :construction: add path priolist * :construction: handle statusCode in error, adjust interfaces * :construction: fixing type issues w/Ivan * :construction: add error exploration * 👔 fix linter issues * :wrench: improve object check * :construction: remove path passing from NodeApiError * :construction: add multi error + refactor findProperty method * 👔 allow any * :wrench: handle multi error message callback * :zap: change return type of callback * :zap: add customCallback to MultiError * :construction: refactor to use INode * :hammer: handle arrays, continue search after first null property found * 🚫 refactor method access * :construction: setup NodeErrorView * :zap: change timestamp to Date.now * :books: Add documentation for methods and constants * :construction: change message setting * 🚚 move NodeErrors to workflow * :sparkles: add new ErrorView for Nodes * :art: improve error notification * :art: refactor interfaces * :zap: add WorkflowOperationError, refactor error throwing * 👕 fix linter issues * :art: rename param * :bug: fix handling normal errors * :zap: add usage of NodeApiError * :art: fix throw new error instead of constructor * :art: remove unnecessary code/comments * :art: adjusted spacing + updated status messages * :art: fix tab indentation * ✨ Replace current errors with custom errors (#1576) * :zap: Introduce NodeApiError in catch blocks * :zap: Introduce NodeOperationError in nodes * :zap: Add missing errors and remove incompatible * :zap: Fix NodeOperationError in incompatible nodes * :wrench: Adjust error handling in missed nodes PayPal, FileMaker, Reddit, Taiga and Facebook Graph API nodes * :hammer: Adjust Strava Trigger node error handling * :hammer: Adjust AWS nodes error handling * :hammer: Remove duplicate instantiation of NodeApiError * :bug: fix strava trigger node error handling * Add XML parsing to NodeApiError constructor (#1633) * :bug: Remove type annotation from catch variable * :sparkles: Add XML parsing to NodeApiError * :zap: Simplify error handling in Rekognition node * :zap: Pass in XML flag in generic functions * :fire: Remove try/catch wrappers at call sites * :hammer: Refactor setting description from XML * :hammer: Refactor let to const in resource loaders * :zap: Find property in parsed XML * :zap: Change let to const * :fire: Remove unneeded try/catch block * :shirt: Fix linting issues * :bug: Fix errors from merge conflict resolution * :zap: Add custom errors to latest contributions * :shirt: Fix linting issues * :zap: Refactor MongoDB helpers for custom errors * :bug: Correct custom error type * :zap: Apply feedback to A nodes * :zap: Apply feedback to missed A node * :zap: Apply feedback to B-D nodes * :zap: Apply feedback to E-F nodes * :zap: Apply feedback to G nodes * :zap: Apply feedback to H-L nodes * :zap: Apply feedback to M nodes * :zap: Apply feedback to P nodes * :zap: Apply feedback to R nodes * :zap: Apply feedback to S nodes * :zap: Apply feedback to T nodes * :zap: Apply feedback to V-Z nodes * :zap: Add HTTP code to iterable node error * :hammer: Standardize e as error * :hammer: Standardize err as error * :zap: Fix error handling for non-standard nodes Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <1849459+BHesseldieck@users.noreply.github.com>
2021-04-16 09:33:36 -07:00
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);
}
return [this.helpers.returnJsonArray(returnData)];
}
}