n8n-3867-progressively-apply-prettier-to-all (#3873)

* 🔨 formatting nodes with prettier
This commit is contained in:
Michael Kret
2022-08-17 18:50:24 +03:00
committed by GitHub
parent f2d326c7f0
commit 91d7e16c81
1072 changed files with 42357 additions and 59109 deletions

View File

@@ -8,9 +8,7 @@ export const conversationOperations: INodeProperties[] = [
noDataExpression: true,
displayOptions: {
show: {
resource: [
'conversation',
],
resource: ['conversation'],
},
},
options: [
@@ -44,9 +42,9 @@ export const conversationOperations: INodeProperties[] = [
];
export const conversationFields: INodeProperties[] = [
/* -------------------------------------------------------------------------- */
/* conversation:create */
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* conversation:create */
/* -------------------------------------------------------------------------- */
{
displayName: 'Mailbox Name or ID',
name: 'mailboxId',
@@ -57,16 +55,13 @@ export const conversationFields: INodeProperties[] = [
required: true,
displayOptions: {
show: {
operation: [
'create',
],
resource: [
'conversation',
],
operation: ['create'],
resource: ['conversation'],
},
},
default: '',
description: 'ID of a mailbox where the conversation is being created. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
description:
'ID of a mailbox where the conversation is being created. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
},
{
displayName: 'Status',
@@ -89,12 +84,8 @@ export const conversationFields: INodeProperties[] = [
],
displayOptions: {
show: {
operation: [
'create',
],
resource: [
'conversation',
],
operation: ['create'],
resource: ['conversation'],
},
},
default: '',
@@ -110,12 +101,8 @@ export const conversationFields: INodeProperties[] = [
},
displayOptions: {
show: {
operation: [
'create',
],
resource: [
'conversation',
],
operation: ['create'],
resource: ['conversation'],
},
},
default: '',
@@ -142,12 +129,8 @@ export const conversationFields: INodeProperties[] = [
],
displayOptions: {
show: {
operation: [
'create',
],
resource: [
'conversation',
],
operation: ['create'],
resource: ['conversation'],
},
},
default: '',
@@ -160,16 +143,13 @@ export const conversationFields: INodeProperties[] = [
default: true,
displayOptions: {
show: {
operation: [
'create',
],
resource: [
'conversation',
],
operation: ['create'],
resource: ['conversation'],
},
},
// eslint-disable-next-line n8n-nodes-base/node-param-description-boolean-without-whether
description: 'By default the response only contain the ID to resource. If this option gets activated, it will resolve the data automatically.',
description:
'By default the response only contain the ID to resource. If this option gets activated, it will resolve the data automatically.',
},
{
displayName: 'Additional Fields',
@@ -179,12 +159,8 @@ export const conversationFields: INodeProperties[] = [
default: {},
displayOptions: {
show: {
operation: [
'create',
],
resource: [
'conversation',
],
operation: ['create'],
resource: ['conversation'],
},
},
options: [
@@ -200,7 +176,8 @@ export const conversationFields: INodeProperties[] = [
name: 'autoReply',
type: 'boolean',
default: false,
description: 'Whether set to true, an auto reply will be sent as long as there is at least one customer thread in the conversation',
description:
'Whether set to true, an auto reply will be sent as long as there is at least one customer thread in the conversation',
},
{
displayName: 'Closed At',
@@ -243,7 +220,8 @@ export const conversationFields: INodeProperties[] = [
loadOptionsMethod: 'getTags',
},
default: [],
description: 'List of tags to be added to the conversation. Choose from the list, or specify IDs using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
description:
'List of tags to be added to the conversation. Choose from the list, or specify IDs using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
},
{
displayName: 'User ID',
@@ -264,12 +242,8 @@ export const conversationFields: INodeProperties[] = [
},
displayOptions: {
show: {
operation: [
'create',
],
resource: [
'conversation',
],
operation: ['create'],
resource: ['conversation'],
},
},
default: {},
@@ -321,9 +295,7 @@ export const conversationFields: INodeProperties[] = [
name: 'bcc',
displayOptions: {
show: {
type: [
'customer',
],
type: ['customer'],
},
},
type: 'string',
@@ -339,9 +311,7 @@ export const conversationFields: INodeProperties[] = [
name: 'cc',
displayOptions: {
show: {
type: [
'customer',
],
type: ['customer'],
},
},
type: 'string',
@@ -357,9 +327,7 @@ export const conversationFields: INodeProperties[] = [
name: 'draft',
displayOptions: {
show: {
type: [
'reply',
],
type: ['reply'],
},
},
type: 'boolean',
@@ -370,9 +338,9 @@ export const conversationFields: INodeProperties[] = [
},
],
},
/* -------------------------------------------------------------------------- */
/* conversation:get */
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* conversation:get */
/* -------------------------------------------------------------------------- */
{
displayName: 'Conversation ID',
name: 'conversationId',
@@ -381,18 +349,14 @@ export const conversationFields: INodeProperties[] = [
required: true,
displayOptions: {
show: {
resource: [
'conversation',
],
operation: [
'get',
],
resource: ['conversation'],
operation: ['get'],
},
},
},
/* -------------------------------------------------------------------------- */
/* conversation:delete */
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* conversation:delete */
/* -------------------------------------------------------------------------- */
{
displayName: 'Conversation ID',
name: 'conversationId',
@@ -401,30 +365,22 @@ export const conversationFields: INodeProperties[] = [
required: true,
displayOptions: {
show: {
resource: [
'conversation',
],
operation: [
'delete',
],
resource: ['conversation'],
operation: ['delete'],
},
},
},
/* -------------------------------------------------------------------------- */
/* conversation:getAll */
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* conversation:getAll */
/* -------------------------------------------------------------------------- */
{
displayName: 'Return All',
name: 'returnAll',
type: 'boolean',
displayOptions: {
show: {
operation: [
'getAll',
],
resource: [
'conversation',
],
operation: ['getAll'],
resource: ['conversation'],
},
},
default: false,
@@ -436,15 +392,9 @@ export const conversationFields: INodeProperties[] = [
type: 'number',
displayOptions: {
show: {
operation: [
'getAll',
],
resource: [
'conversation',
],
returnAll: [
false,
],
operation: ['getAll'],
resource: ['conversation'],
returnAll: [false],
},
},
typeOptions: {
@@ -461,12 +411,8 @@ export const conversationFields: INodeProperties[] = [
default: {},
displayOptions: {
show: {
resource: [
'conversation',
],
operation: [
'getAll',
],
resource: ['conversation'],
operation: ['getAll'],
},
},
options: [
@@ -529,7 +475,8 @@ export const conversationFields: INodeProperties[] = [
alwaysOpenEditWindow: true,
},
default: '',
description: 'Advanced search <a href="https://developer.helpscout.com/mailbox-api/endpoints/conversations/list/#query">Examples</a>',
description:
'Advanced search <a href="https://developer.helpscout.com/mailbox-api/endpoints/conversations/list/#query">Examples</a>',
},
{
displayName: 'Sort Field',
@@ -633,7 +580,8 @@ export const conversationFields: INodeProperties[] = [
loadOptionsMethod: 'getTags',
},
default: [],
description: 'Filter conversation by tags. Choose from the list, or specify IDs using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
description:
'Filter conversation by tags. Choose from the list, or specify IDs using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
},
],
},

File diff suppressed because it is too large Load Diff

View File

@@ -8,9 +8,7 @@ export const customerOperations: INodeProperties[] = [
noDataExpression: true,
displayOptions: {
show: {
resource: [
'customer',
],
resource: ['customer'],
},
},
options: [
@@ -50,9 +48,9 @@ export const customerOperations: INodeProperties[] = [
];
export const customerFields: INodeProperties[] = [
/* -------------------------------------------------------------------------- */
/* customer:create */
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* customer:create */
/* -------------------------------------------------------------------------- */
{
displayName: 'Resolve Data',
name: 'resolveData',
@@ -60,16 +58,13 @@ export const customerFields: INodeProperties[] = [
default: true,
displayOptions: {
show: {
operation: [
'create',
],
resource: [
'customer',
],
operation: ['create'],
resource: ['customer'],
},
},
// eslint-disable-next-line n8n-nodes-base/node-param-description-boolean-without-whether
description: 'By default the response only contain the ID to resource. If this option gets activated, it will resolve the data automatically.',
description:
'By default the response only contain the ID to resource. If this option gets activated, it will resolve the data automatically.',
},
{
displayName: 'Additional Fields',
@@ -79,12 +74,8 @@ export const customerFields: INodeProperties[] = [
default: {},
displayOptions: {
show: {
operation: [
'create',
],
resource: [
'customer',
],
operation: ['create'],
resource: ['customer'],
},
},
options: [
@@ -103,7 +94,8 @@ export const customerFields: INodeProperties[] = [
name: 'firstName',
type: 'string',
default: '',
description: 'First name of the customer. When defined it must be between 1 and 40 characters.',
description:
'First name of the customer. When defined it must be between 1 and 40 characters.',
},
{
displayName: 'Gender',
@@ -178,12 +170,8 @@ export const customerFields: INodeProperties[] = [
type: 'fixedCollection',
displayOptions: {
show: {
operation: [
'create',
],
resource: [
'customer',
],
operation: ['create'],
resource: ['customer'],
},
},
default: {},
@@ -220,7 +208,8 @@ export const customerFields: INodeProperties[] = [
displayName: 'Country Name or ID',
name: 'country',
type: 'options',
description: 'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
description:
'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
typeOptions: {
loadOptionsMethod: 'getCountriesCodes',
},
@@ -246,12 +235,8 @@ export const customerFields: INodeProperties[] = [
},
displayOptions: {
show: {
operation: [
'create',
],
resource: [
'customer',
],
operation: ['create'],
resource: ['customer'],
},
},
default: {},
@@ -326,12 +311,8 @@ export const customerFields: INodeProperties[] = [
},
displayOptions: {
show: {
operation: [
'create',
],
resource: [
'customer',
],
operation: ['create'],
resource: ['customer'],
},
},
default: {},
@@ -382,12 +363,8 @@ export const customerFields: INodeProperties[] = [
},
displayOptions: {
show: {
operation: [
'create',
],
resource: [
'customer',
],
operation: ['create'],
resource: ['customer'],
},
},
default: {},
@@ -446,12 +423,8 @@ export const customerFields: INodeProperties[] = [
},
displayOptions: {
show: {
operation: [
'create',
],
resource: [
'customer',
],
operation: ['create'],
resource: ['customer'],
},
},
default: {},
@@ -538,12 +511,8 @@ export const customerFields: INodeProperties[] = [
},
displayOptions: {
show: {
operation: [
'create',
],
resource: [
'customer',
],
operation: ['create'],
resource: ['customer'],
},
},
default: {},
@@ -563,21 +532,17 @@ export const customerFields: INodeProperties[] = [
},
],
},
/* -------------------------------------------------------------------------- */
/* customer:getAll */
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* customer:getAll */
/* -------------------------------------------------------------------------- */
{
displayName: 'Return All',
name: 'returnAll',
type: 'boolean',
displayOptions: {
show: {
operation: [
'getAll',
],
resource: [
'customer',
],
operation: ['getAll'],
resource: ['customer'],
},
},
default: false,
@@ -589,15 +554,9 @@ export const customerFields: INodeProperties[] = [
type: 'number',
displayOptions: {
show: {
operation: [
'getAll',
],
resource: [
'customer',
],
returnAll: [
false,
],
operation: ['getAll'],
resource: ['customer'],
returnAll: [false],
},
},
typeOptions: {
@@ -614,12 +573,8 @@ export const customerFields: INodeProperties[] = [
default: {},
displayOptions: {
show: {
resource: [
'customer',
],
operation: [
'getAll',
],
resource: ['customer'],
operation: ['getAll'],
},
},
options: [
@@ -700,13 +655,14 @@ export const customerFields: INodeProperties[] = [
alwaysOpenEditWindow: true,
},
default: '',
description: 'Advanced search <a href="https://developer.helpscout.com/mailbox-api/endpoints/customers/list/#query">Examples</a>',
description:
'Advanced search <a href="https://developer.helpscout.com/mailbox-api/endpoints/customers/list/#query">Examples</a>',
},
],
},
/* -------------------------------------------------------------------------- */
/* customer:get */
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* customer:get */
/* -------------------------------------------------------------------------- */
{
displayName: 'Customer ID',
name: 'customerId',
@@ -715,18 +671,14 @@ export const customerFields: INodeProperties[] = [
required: true,
displayOptions: {
show: {
resource: [
'customer',
],
operation: [
'get',
],
resource: ['customer'],
operation: ['get'],
},
},
},
/* -------------------------------------------------------------------------- */
/* customer:update */
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* customer:update */
/* -------------------------------------------------------------------------- */
{
displayName: 'Customer ID',
name: 'customerId',
@@ -734,12 +686,8 @@ export const customerFields: INodeProperties[] = [
default: '',
displayOptions: {
show: {
operation: [
'update',
],
resource: [
'customer',
],
operation: ['update'],
resource: ['customer'],
},
},
},
@@ -751,12 +699,8 @@ export const customerFields: INodeProperties[] = [
default: {},
displayOptions: {
show: {
operation: [
'update',
],
resource: [
'customer',
],
operation: ['update'],
resource: ['customer'],
},
},
options: [
@@ -775,7 +719,8 @@ export const customerFields: INodeProperties[] = [
name: 'firstName',
type: 'string',
default: '',
description: 'First name of the customer. When defined it must be between 1 and 40 characters.',
description:
'First name of the customer. When defined it must be between 1 and 40 characters.',
},
{
displayName: 'Gender',

View File

@@ -1,6 +1,4 @@
import {
OptionsWithUri,
} from 'request';
import { OptionsWithUri } from 'request';
import {
IExecuteFunctions,
@@ -9,15 +7,21 @@ import {
ILoadOptionsFunctions,
} from 'n8n-core';
import {
IDataObject, NodeApiError,
} from 'n8n-workflow';
import { IDataObject, NodeApiError } from 'n8n-workflow';
import {
get,
} from 'lodash';
import { get } from 'lodash';
export async function helpscoutApiRequest(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions | IHookFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
export async function helpscoutApiRequest(
this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions | IHookFunctions,
method: string,
resource: string,
// tslint:disable-next-line:no-any
body: any = {},
qs: IDataObject = {},
uri?: string,
option: IDataObject = {},
// tslint:disable-next-line:no-any
): Promise<any> {
let options: OptionsWithUri = {
headers: {
'Content-Type': 'application/json',
@@ -42,8 +46,16 @@ export async function helpscoutApiRequest(this: IExecuteFunctions | IExecuteSing
}
}
export async function helpscoutApiRequestAllItems(this: IExecuteFunctions | ILoadOptionsFunctions | IHookFunctions, propertyName: string, method: string, endpoint: string, body: any = {}, query: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
export async function helpscoutApiRequestAllItems(
this: IExecuteFunctions | ILoadOptionsFunctions | IHookFunctions,
propertyName: string,
method: string,
endpoint: string,
// tslint:disable-next-line:no-any
body: any = {},
query: IDataObject = {},
// tslint:disable-next-line:no-any
): Promise<any> {
const returnData: IDataObject[] = [];
let responseData;

View File

@@ -1,6 +1,4 @@
import {
IExecuteFunctions,
} from 'n8n-core';
import { IExecuteFunctions } from 'n8n-core';
import {
IBinaryKeyData,
@@ -13,48 +11,23 @@ import {
NodeOperationError,
} from 'n8n-workflow';
import {
countriesCodes
} from './CountriesCodes';
import { countriesCodes } from './CountriesCodes';
import {
conversationFields,
conversationOperations,
} from './ConversationDescription';
import { conversationFields, conversationOperations } from './ConversationDescription';
import {
customerFields,
customerOperations,
} from './CustomerDescription';
import { customerFields, customerOperations } from './CustomerDescription';
import {
ICustomer,
} from './CustomerInterface';
import { ICustomer } from './CustomerInterface';
import {
IConversation,
} from './ConversationInterface';
import { IConversation } from './ConversationInterface';
import {
helpscoutApiRequest,
helpscoutApiRequestAllItems,
} from './GenericFunctions';
import { helpscoutApiRequest, helpscoutApiRequestAllItems } from './GenericFunctions';
import {
mailboxFields,
mailboxOperations,
} from './MailboxDescription';
import { mailboxFields, mailboxOperations } from './MailboxDescription';
import {
threadFields,
threadOperations,
} from './ThreadDescription';
import {
IAttachment,
IThread,
} from './ThreadInterface';
import { threadFields, threadOperations } from './ThreadDescription';
import { IAttachment, IThread } from './ThreadInterface';
export class HelpScout implements INodeType {
description: INodeTypeDescription = {
@@ -133,7 +106,12 @@ export class HelpScout implements INodeType {
// select them easily
async getTags(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const returnData: INodePropertyOptions[] = [];
const tags = await helpscoutApiRequestAllItems.call(this, '_embedded.tags', 'GET', '/v2/tags');
const tags = await helpscoutApiRequestAllItems.call(
this,
'_embedded.tags',
'GET',
'/v2/tags',
);
for (const tag of tags) {
const tagName = tag.name;
const tagId = tag.id;
@@ -148,7 +126,12 @@ export class HelpScout implements INodeType {
// select them easily
async getMailboxes(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const returnData: INodePropertyOptions[] = [];
const mailboxes = await helpscoutApiRequestAllItems.call(this, '_embedded.mailboxes', 'GET', '/v2/mailboxes');
const mailboxes = await helpscoutApiRequestAllItems.call(
this,
'_embedded.mailboxes',
'GET',
'/v2/mailboxes',
);
for (const mailbox of mailboxes) {
const mailboxName = mailbox.name;
const mailboxId = mailbox.id;
@@ -181,7 +164,8 @@ export class HelpScout implements INodeType {
const type = this.getNodeParameter('type', i) as string;
const resolveData = this.getNodeParameter('resolveData', i) as boolean;
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
const threads = (this.getNodeParameter('threadsUi', i) as IDataObject).threadsValues as IDataObject[];
const threads = (this.getNodeParameter('threadsUi', i) as IDataObject)
.threadsValues as IDataObject[];
const body: IConversation = {
mailboxId,
status,
@@ -204,7 +188,11 @@ export class HelpScout implements INodeType {
delete body.customerEmail;
}
if (body.customer === undefined) {
throw new NodeOperationError(this.getNode(), 'Either customer email or customer ID must be set', { itemIndex: i });
throw new NodeOperationError(
this.getNode(),
'Either customer email or customer ID must be set',
{ itemIndex: i },
);
}
if (threads) {
for (let i = 0; i < threads.length; i++) {
@@ -217,7 +205,15 @@ export class HelpScout implements INodeType {
}
body.threads = threads;
}
responseData = await helpscoutApiRequest.call(this, 'POST', '/v2/conversations', body, qs, undefined, { resolveWithFullResponse: true });
responseData = await helpscoutApiRequest.call(
this,
'POST',
'/v2/conversations',
body,
qs,
undefined,
{ resolveWithFullResponse: true },
);
const id = responseData.headers['resource-id'];
const uri = responseData.headers.location;
if (resolveData) {
@@ -232,13 +228,21 @@ export class HelpScout implements INodeType {
//https://developer.helpscout.com/mailbox-api/endpoints/conversations/delete
if (operation === 'delete') {
const conversationId = this.getNodeParameter('conversationId', i) as string;
responseData = await helpscoutApiRequest.call(this, 'DELETE', `/v2/conversations/${conversationId}`);
responseData = await helpscoutApiRequest.call(
this,
'DELETE',
`/v2/conversations/${conversationId}`,
);
responseData = { success: true };
}
//https://developer.helpscout.com/mailbox-api/endpoints/conversations/get
if (operation === 'get') {
const conversationId = this.getNodeParameter('conversationId', i) as string;
responseData = await helpscoutApiRequest.call(this, 'GET', `/v2/conversations/${conversationId}`);
responseData = await helpscoutApiRequest.call(
this,
'GET',
`/v2/conversations/${conversationId}`,
);
}
//https://developer.helpscout.com/mailbox-api/endpoints/conversations/list
if (operation === 'getAll') {
@@ -246,10 +250,24 @@ export class HelpScout implements INodeType {
const options = this.getNodeParameter('options', i) as IDataObject;
Object.assign(qs, options);
if (returnAll) {
responseData = await helpscoutApiRequestAllItems.call(this, '_embedded.conversations', 'GET', '/v2/conversations', {}, qs);
responseData = await helpscoutApiRequestAllItems.call(
this,
'_embedded.conversations',
'GET',
'/v2/conversations',
{},
qs,
);
} else {
qs.limit = this.getNodeParameter('limit', i) as number;
responseData = await helpscoutApiRequestAllItems.call(this, '_embedded.conversations', 'GET', '/v2/conversations', {}, qs);
responseData = await helpscoutApiRequestAllItems.call(
this,
'_embedded.conversations',
'GET',
'/v2/conversations',
{},
qs,
);
responseData = responseData.splice(0, qs.limit);
}
}
@@ -259,12 +277,18 @@ export class HelpScout implements INodeType {
if (operation === 'create') {
const resolveData = this.getNodeParameter('resolveData', i) as boolean;
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
const chats = (this.getNodeParameter('chatsUi', i) as IDataObject).chatsValues as IDataObject[];
const address = (this.getNodeParameter('addressUi', i) as IDataObject).addressValue as IDataObject;
const emails = (this.getNodeParameter('emailsUi', i) as IDataObject).emailsValues as IDataObject[];
const phones = (this.getNodeParameter('phonesUi', i) as IDataObject).phonesValues as IDataObject[];
const socialProfiles = (this.getNodeParameter('socialProfilesUi', i) as IDataObject).socialProfilesValues as IDataObject[];
const websites = (this.getNodeParameter('websitesUi', i) as IDataObject).websitesValues as IDataObject[];
const chats = (this.getNodeParameter('chatsUi', i) as IDataObject)
.chatsValues as IDataObject[];
const address = (this.getNodeParameter('addressUi', i) as IDataObject)
.addressValue as IDataObject;
const emails = (this.getNodeParameter('emailsUi', i) as IDataObject)
.emailsValues as IDataObject[];
const phones = (this.getNodeParameter('phonesUi', i) as IDataObject)
.phonesValues as IDataObject[];
const socialProfiles = (this.getNodeParameter('socialProfilesUi', i) as IDataObject)
.socialProfilesValues as IDataObject[];
const websites = (this.getNodeParameter('websitesUi', i) as IDataObject)
.websitesValues as IDataObject[];
let body: ICustomer = {};
body = Object.assign({}, additionalFields);
if (body.age) {
@@ -290,9 +314,19 @@ export class HelpScout implements INodeType {
body.websites = websites;
}
if (Object.keys(body).length === 0) {
throw new NodeOperationError(this.getNode(), 'You have to set at least one field', { itemIndex: i });
throw new NodeOperationError(this.getNode(), 'You have to set at least one field', {
itemIndex: i,
});
}
responseData = await helpscoutApiRequest.call(this, 'POST', '/v2/customers', body, qs, undefined, { resolveWithFullResponse: true });
responseData = await helpscoutApiRequest.call(
this,
'POST',
'/v2/customers',
body,
qs,
undefined,
{ resolveWithFullResponse: true },
);
const id = responseData.headers['resource-id'];
const uri = responseData.headers.location;
if (resolveData) {
@@ -306,12 +340,23 @@ export class HelpScout implements INodeType {
}
//https://developer.helpscout.com/mailbox-api/endpoints/customer_properties/list
if (operation === 'properties') {
responseData = await helpscoutApiRequestAllItems.call(this, '_embedded.customer-properties', 'GET', '/v2/customer-properties', {}, qs);
responseData = await helpscoutApiRequestAllItems.call(
this,
'_embedded.customer-properties',
'GET',
'/v2/customer-properties',
{},
qs,
);
}
//https://developer.helpscout.com/mailbox-api/endpoints/customers/get
if (operation === 'get') {
const customerId = this.getNodeParameter('customerId', i) as string;
responseData = await helpscoutApiRequest.call(this, 'GET', `/v2/customers/${customerId}`);
responseData = await helpscoutApiRequest.call(
this,
'GET',
`/v2/customers/${customerId}`,
);
}
//https://developer.helpscout.com/mailbox-api/endpoints/customers/list
if (operation === 'getAll') {
@@ -319,10 +364,24 @@ export class HelpScout implements INodeType {
const options = this.getNodeParameter('options', i) as IDataObject;
Object.assign(qs, options);
if (returnAll) {
responseData = await helpscoutApiRequestAllItems.call(this, '_embedded.customers', 'GET', '/v2/customers', {}, qs);
responseData = await helpscoutApiRequestAllItems.call(
this,
'_embedded.customers',
'GET',
'/v2/customers',
{},
qs,
);
} else {
qs.limit = this.getNodeParameter('limit', i) as number;
responseData = await helpscoutApiRequestAllItems.call(this, '_embedded.customers', 'GET', '/v2/customers', {}, qs);
responseData = await helpscoutApiRequestAllItems.call(
this,
'_embedded.customers',
'GET',
'/v2/customers',
{},
qs,
);
responseData = responseData.splice(0, qs.limit);
}
}
@@ -336,9 +395,19 @@ export class HelpScout implements INodeType {
body.age = body.age.toString();
}
if (Object.keys(body).length === 0) {
throw new NodeOperationError(this.getNode(), 'You have to set at least one field', { itemIndex: i });
throw new NodeOperationError(this.getNode(), 'You have to set at least one field', {
itemIndex: i,
});
}
responseData = await helpscoutApiRequest.call(this, 'PUT', `/v2/customers/${customerId}`, body, qs, undefined, { resolveWithFullResponse: true });
responseData = await helpscoutApiRequest.call(
this,
'PUT',
`/v2/customers/${customerId}`,
body,
qs,
undefined,
{ resolveWithFullResponse: true },
);
responseData = { success: true };
}
}
@@ -346,16 +415,36 @@ export class HelpScout implements INodeType {
//https://developer.helpscout.com/mailbox-api/endpoints/mailboxes/get
if (operation === 'get') {
const mailboxId = this.getNodeParameter('mailboxId', i) as string;
responseData = await helpscoutApiRequest.call(this, 'GET', `/v2/mailboxes/${mailboxId}`, {}, qs);
responseData = await helpscoutApiRequest.call(
this,
'GET',
`/v2/mailboxes/${mailboxId}`,
{},
qs,
);
}
//https://developer.helpscout.com/mailbox-api/endpoints/mailboxes/list
if (operation === 'getAll') {
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
if (returnAll) {
responseData = await helpscoutApiRequestAllItems.call(this, '_embedded.mailboxes', 'GET', '/v2/mailboxes', {}, qs);
responseData = await helpscoutApiRequestAllItems.call(
this,
'_embedded.mailboxes',
'GET',
'/v2/mailboxes',
{},
qs,
);
} else {
qs.limit = this.getNodeParameter('limit', i) as number;
responseData = await helpscoutApiRequestAllItems.call(this, '_embedded.mailboxes', 'GET', '/v2/mailboxes', {}, qs);
responseData = await helpscoutApiRequestAllItems.call(
this,
'_embedded.mailboxes',
'GET',
'/v2/mailboxes',
{},
qs,
);
responseData = responseData.splice(0, qs.limit);
}
}
@@ -388,18 +477,31 @@ export class HelpScout implements INodeType {
delete body.customerEmail;
}
if (body.customer === undefined) {
throw new NodeOperationError(this.getNode(), 'Either customer email or customer ID must be set', { itemIndex: i });
throw new NodeOperationError(
this.getNode(),
'Either customer email or customer ID must be set',
{ itemIndex: i },
);
}
if (attachments) {
if (attachments.attachmentsValues
&& (attachments.attachmentsValues as IDataObject[]).length !== 0) {
body.attachments?.push.apply(body.attachments, attachments.attachmentsValues as IAttachment[]);
if (
attachments.attachmentsValues &&
(attachments.attachmentsValues as IDataObject[]).length !== 0
) {
body.attachments?.push.apply(
body.attachments,
attachments.attachmentsValues as IAttachment[],
);
}
if (attachments.attachmentsBinary
&& (attachments.attachmentsBinary as IDataObject[]).length !== 0
&& items[i].binary) {
if (
attachments.attachmentsBinary &&
(attachments.attachmentsBinary as IDataObject[]).length !== 0 &&
items[i].binary
) {
const mapFunction = (value: IDataObject): IAttachment => {
const binaryProperty = (items[i].binary as IBinaryKeyData)[value.property as string];
const binaryProperty = (items[i].binary as IBinaryKeyData)[
value.property as string
];
if (binaryProperty) {
return {
fileName: binaryProperty.fileName || 'unknown',
@@ -407,13 +509,27 @@ export class HelpScout implements INodeType {
mimeType: binaryProperty.mimeType,
};
} else {
throw new NodeOperationError(this.getNode(), `Binary property ${value.property} does not exist on input`, { itemIndex: i });
throw new NodeOperationError(
this.getNode(),
`Binary property ${value.property} does not exist on input`,
{ itemIndex: i },
);
}
};
body.attachments?.push.apply(body.attachments, (attachments.attachmentsBinary as IDataObject[]).map(mapFunction) as IAttachment[]);
body.attachments?.push.apply(
body.attachments,
(attachments.attachmentsBinary as IDataObject[]).map(
mapFunction,
) as IAttachment[],
);
}
}
responseData = await helpscoutApiRequest.call(this, 'POST', `/v2/conversations/${conversationId}/chats`, body);
responseData = await helpscoutApiRequest.call(
this,
'POST',
`/v2/conversations/${conversationId}/chats`,
body,
);
responseData = { success: true };
}
//https://developer.helpscout.com/mailbox-api/endpoints/conversations/threads/list
@@ -421,10 +537,22 @@ export class HelpScout implements INodeType {
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
const conversationId = this.getNodeParameter('conversationId', i) as string;
if (returnAll) {
responseData = await helpscoutApiRequestAllItems.call(this, '_embedded.threads', 'GET', `/v2/conversations/${conversationId}/threads`);
responseData = await helpscoutApiRequestAllItems.call(
this,
'_embedded.threads',
'GET',
`/v2/conversations/${conversationId}/threads`,
);
} else {
qs.limit = this.getNodeParameter('limit', i) as number;
responseData = await helpscoutApiRequestAllItems.call(this, '_embedded.threads', 'GET', `/v2/conversations/${conversationId}/threads`, {}, qs);
responseData = await helpscoutApiRequestAllItems.call(
this,
'_embedded.threads',
'GET',
`/v2/conversations/${conversationId}/threads`,
{},
qs,
);
responseData = responseData.splice(0, qs.limit);
}
}

View File

@@ -1,23 +1,10 @@
import {
IHookFunctions,
IWebhookFunctions,
} from 'n8n-core';
import { IHookFunctions, IWebhookFunctions } from 'n8n-core';
import {
IDataObject,
INodeType,
INodeTypeDescription,
IWebhookResponseData,
} from 'n8n-workflow';
import { IDataObject, INodeType, INodeTypeDescription, IWebhookResponseData } from 'n8n-workflow';
import {
helpscoutApiRequest,
helpscoutApiRequestAllItems,
} from './GenericFunctions';
import { helpscoutApiRequest, helpscoutApiRequestAllItems } from './GenericFunctions';
import {
createHmac,
} from 'crypto';
import { createHmac } from 'crypto';
export class HelpScoutTrigger implements INodeType {
description: INodeTypeDescription = {
@@ -52,7 +39,6 @@ export class HelpScoutTrigger implements INodeType {
name: 'events',
type: 'multiOptions',
options: [
{
name: 'Conversation - Assigned',
value: 'convo.assigned',
@@ -106,7 +92,6 @@ export class HelpScoutTrigger implements INodeType {
required: true,
},
],
};
// @ts-ignore (because of request)
@@ -120,13 +105,18 @@ export class HelpScoutTrigger implements INodeType {
// Check all the webhooks which exist already if it is identical to the
// one that is supposed to get created.
const endpoint = '/v2/webhooks';
const data = await helpscoutApiRequestAllItems.call(this, '_embedded.webhooks', 'GET', endpoint, {});
const data = await helpscoutApiRequestAllItems.call(
this,
'_embedded.webhooks',
'GET',
endpoint,
{},
);
for (const webhook of data) {
if (webhook.url === webhookUrl) {
for (const event of events) {
if (!webhook.events.includes(event)
&& webhook.state === 'enabled') {
if (!webhook.events.includes(event) && webhook.state === 'enabled') {
return false;
}
}
@@ -150,7 +140,15 @@ export class HelpScoutTrigger implements INodeType {
secret: Math.random().toString(36).substring(2, 15),
};
const responseData = await helpscoutApiRequest.call(this, 'POST', endpoint, body, {}, undefined, { resolveWithFullResponse: true });
const responseData = await helpscoutApiRequest.call(
this,
'POST',
endpoint,
body,
{},
undefined,
{ resolveWithFullResponse: true },
);
if (responseData.headers['resource-id'] === undefined) {
// Required data is missing so was not successful
@@ -164,7 +162,6 @@ export class HelpScoutTrigger implements INodeType {
async delete(this: IHookFunctions): Promise<boolean> {
const webhookData = this.getWorkflowStaticData('node');
if (webhookData.webhookId !== undefined) {
const endpoint = `/v2/webhooks/${webhookData.webhookId}`;
try {
await helpscoutApiRequest.call(this, 'DELETE', endpoint);
@@ -190,15 +187,16 @@ export class HelpScoutTrigger implements INodeType {
if (headerData['x-helpscout-signature'] === undefined) {
return {};
}
//@ts-ignore
const computedSignature = createHmac('sha1', webhookData.secret as string).update(req.rawBody).digest('base64');
const computedSignature = createHmac('sha1', webhookData.secret as string)
//@ts-ignore
.update(req.rawBody)
.digest('base64');
if (headerData['x-helpscout-signature'] !== computedSignature) {
return {};
}
return {
workflowData: [
this.helpers.returnJsonArray(bodyData),
],
workflowData: [this.helpers.returnJsonArray(bodyData)],
};
}
}

View File

@@ -8,9 +8,7 @@ export const mailboxOperations: INodeProperties[] = [
noDataExpression: true,
displayOptions: {
show: {
resource: [
'mailbox',
],
resource: ['mailbox'],
},
},
options: [
@@ -32,10 +30,9 @@ export const mailboxOperations: INodeProperties[] = [
];
export const mailboxFields: INodeProperties[] = [
/* -------------------------------------------------------------------------- */
/* mailbox:get */
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* mailbox:get */
/* -------------------------------------------------------------------------- */
{
displayName: 'Mailbox ID',
name: 'mailboxId',
@@ -44,30 +41,22 @@ export const mailboxFields: INodeProperties[] = [
required: true,
displayOptions: {
show: {
resource: [
'mailbox',
],
operation: [
'get',
],
resource: ['mailbox'],
operation: ['get'],
},
},
},
/* -------------------------------------------------------------------------- */
/* mailbox:getAll */
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* mailbox:getAll */
/* -------------------------------------------------------------------------- */
{
displayName: 'Return All',
name: 'returnAll',
type: 'boolean',
displayOptions: {
show: {
operation: [
'getAll',
],
resource: [
'mailbox',
],
operation: ['getAll'],
resource: ['mailbox'],
},
},
default: false,
@@ -79,15 +68,9 @@ export const mailboxFields: INodeProperties[] = [
type: 'number',
displayOptions: {
show: {
operation: [
'getAll',
],
resource: [
'mailbox',
],
returnAll: [
false,
],
operation: ['getAll'],
resource: ['mailbox'],
returnAll: [false],
},
},
typeOptions: {

View File

@@ -8,9 +8,7 @@ export const threadOperations: INodeProperties[] = [
noDataExpression: true,
displayOptions: {
show: {
resource: [
'thread',
],
resource: ['thread'],
},
},
options: [
@@ -32,9 +30,9 @@ export const threadOperations: INodeProperties[] = [
];
export const threadFields: INodeProperties[] = [
/* -------------------------------------------------------------------------- */
/* thread:create */
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* thread:create */
/* -------------------------------------------------------------------------- */
{
displayName: 'Conversation ID',
name: 'conversationId',
@@ -43,12 +41,8 @@ export const threadFields: INodeProperties[] = [
required: true,
displayOptions: {
show: {
resource: [
'thread',
],
operation: [
'create',
],
resource: ['thread'],
operation: ['create'],
},
},
},
@@ -59,12 +53,8 @@ export const threadFields: INodeProperties[] = [
required: true,
displayOptions: {
show: {
resource: [
'thread',
],
operation: [
'create',
],
resource: ['thread'],
operation: ['create'],
},
},
options: [
@@ -102,12 +92,8 @@ export const threadFields: INodeProperties[] = [
required: true,
displayOptions: {
show: {
resource: [
'thread',
],
operation: [
'create',
],
resource: ['thread'],
operation: ['create'],
},
},
description: 'The chat text',
@@ -120,12 +106,8 @@ export const threadFields: INodeProperties[] = [
default: {},
displayOptions: {
show: {
operation: [
'create',
],
resource: [
'thread',
],
operation: ['create'],
resource: ['thread'],
},
},
options: [
@@ -154,9 +136,7 @@ export const threadFields: INodeProperties[] = [
default: false,
displayOptions: {
show: {
'/type': [
'note',
],
'/type': ['note'],
},
},
description: 'Whether a draft reply is created',
@@ -180,12 +160,8 @@ export const threadFields: INodeProperties[] = [
},
displayOptions: {
show: {
operation: [
'create',
],
resource: [
'thread',
],
operation: ['create'],
resource: ['thread'],
},
},
options: [
@@ -226,7 +202,8 @@ export const threadFields: INodeProperties[] = [
name: 'property',
type: 'string',
default: 'data',
description: 'Name of the binary properties which contain data which should be added to email as attachment',
description:
'Name of the binary properties which contain data which should be added to email as attachment',
},
],
},
@@ -234,9 +211,9 @@ export const threadFields: INodeProperties[] = [
default: {},
description: 'Array of supported attachments to add to the message',
},
/* -------------------------------------------------------------------------- */
/* thread:getAll */
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* thread:getAll */
/* -------------------------------------------------------------------------- */
{
displayName: 'Conversation ID',
name: 'conversationId',
@@ -245,12 +222,8 @@ export const threadFields: INodeProperties[] = [
required: true,
displayOptions: {
show: {
resource: [
'thread',
],
operation: [
'getAll',
],
resource: ['thread'],
operation: ['getAll'],
},
},
},
@@ -260,12 +233,8 @@ export const threadFields: INodeProperties[] = [
type: 'boolean',
displayOptions: {
show: {
operation: [
'getAll',
],
resource: [
'thread',
],
operation: ['getAll'],
resource: ['thread'],
},
},
default: false,
@@ -277,15 +246,9 @@ export const threadFields: INodeProperties[] = [
type: 'number',
displayOptions: {
show: {
operation: [
'getAll',
],
resource: [
'thread',
],
returnAll: [
false,
],
operation: ['getAll'],
resource: ['thread'],
returnAll: [false],
},
},
typeOptions: {