🔀 Merge branch 'master' into Improve-Zulip-Node

This commit is contained in:
Jan Oberhauser 2020-05-22 23:13:27 +02:00
commit 5e4fde6c6a
5 changed files with 1248 additions and 124 deletions

View file

@ -12,12 +12,20 @@ export class AgileCrmApi implements ICredentialType {
name: 'email',
type: 'string' as NodePropertyTypes,
default: '',
},
{
},
{
displayName: 'API Key',
name: 'apiKey',
type: 'string' as NodePropertyTypes,
default: '',
},
{
displayName: 'Subdomain',
name: 'subdomain',
type: 'string' as NodePropertyTypes,
default: '',
placeholder: 'example',
description: 'If the domain is https://example.agilecrm.com "example" would have to be entered.',
},
];
}

View file

@ -27,7 +27,7 @@ export async function agileCrmApiRequest(this: IHookFunctions | IExecuteFunction
username: credentials!.email as string,
password: credentials!.apiKey as string
},
uri: uri || `https://n8nio.agilecrm.com/dev/${endpoint}`,
uri: uri || `https://${credentials!.subdomain}.agilecrm.com/dev/${endpoint}`,
json: true,
};
@ -45,8 +45,9 @@ export async function agileCrmApiRequest(this: IHookFunctions | IExecuteFunction
}
export async function agileCrmApiRequestUpdate(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method = 'PUT', endpoint?: string, body: any = {}, query: IDataObject = {}, uri?: string): Promise<any> { // tslint:disable-line:no-any
const baseUri = 'https://n8nio.agilecrm.com/dev/';
const credentials = this.getCredentials('agileCrmApi');
const baseUri = `https://${credentials!.subdomain}.agilecrm.com/dev/`;
const options: OptionsWithUri = {
method,
headers: {

View file

@ -1,13 +1,19 @@
import { OptionsWithUri } from 'request';
import {
OptionsWithUri,
} from 'request';
import {
IExecuteFunctions,
IExecuteSingleFunctions,
IHookFunctions,
ILoadOptionsFunctions,
IExecuteSingleFunctions
} from 'n8n-core';
export async function mailchimpApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, endpoint: string, method: string, body: any = {}, headers?: object): Promise<any> { // tslint:disable-line:no-any
import {
IDataObject,
} from 'n8n-workflow';
export async function mailchimpApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, endpoint: string, method: string, body: any = {}, qs: IDataObject = {} ,headers?: object): Promise<any> { // tslint:disable-line:no-any
const credentials = this.getCredentials('mailchimpApi');
if (credentials === undefined) {
@ -27,6 +33,7 @@ export async function mailchimpApiRequest(this: IHookFunctions | IExecuteFunctio
const options: OptionsWithUri = {
headers: headerWithAuthentication,
method,
qs,
uri: `https://${datacenter}.${host}${endpoint}`,
json: true,
};
@ -34,19 +41,36 @@ export async function mailchimpApiRequest(this: IHookFunctions | IExecuteFunctio
if (Object.keys(body).length !== 0) {
options.body = body;
}
try {
return await this.helpers.request!(options);
} catch (error) {
const errorMessage = error.response.body.message || error.response.body.Message;
if (errorMessage !== undefined) {
throw errorMessage;
if (error.response.body && error.response.body.detail) {
throw new Error(`Mailchimp Error response [${error.statusCode}]: ${error.response.body.detail}`);
}
throw error.response.body;
throw error;
}
}
export async function mailchimpApiRequestAllItems(this: IExecuteFunctions | ILoadOptionsFunctions, endpoint: string, method: string, propertyName: string, body: any = {}, query: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
const returnData: IDataObject[] = [];
let responseData;
query.offset = 0;
query.count = 500;
do {
responseData = await mailchimpApiRequest.call(this, endpoint, method, body, query);
returnData.push.apply(returnData, responseData[propertyName]);
query.offset += query.count;
} while (
responseData[propertyName] && responseData[propertyName].length !== 0
);
return returnData;
}
export function validateJSON(json: string | undefined): any { // tslint:disable-line:no-any
let result;
try {

File diff suppressed because it is too large Load diff

View file

@ -98,9 +98,9 @@ export class Mattermost implements INodeType {
description: 'Soft-deletes a channel',
},
{
name: 'Members',
name: 'Member',
value: 'members',
description: 'Returns the members of a channel.',
description: 'Get a page of members for a channel.',
},
{
name: 'Restore',
@ -317,6 +317,23 @@ export class Mattermost implements INodeType {
},
description: 'The Mattermost Team.',
},
{
displayName: 'Resolve Data',
name: 'resolveData',
type: 'boolean',
displayOptions: {
show: {
resource: [
'channel',
],
operation: [
'members',
],
},
},
default: true,
description: 'By default the response only contain the ID of the user.<br />If this option gets activated it will resolve the user automatically.',
},
{
displayName: 'Return All',
name: 'returnAll',
@ -950,6 +967,11 @@ export class Mattermost implements INodeType {
value: 'getByEmail',
description: 'Get a user by email',
},
{
name: 'Get By ID',
value: 'getById',
description: 'Get a user by id',
},
],
default: '',
description: 'The operation to perform.',
@ -1113,6 +1135,54 @@ export class Mattermost implements INodeType {
default: '',
description: `User's email`,
},
// ----------------------------------
// user:getById
// ----------------------------------
{
displayName: 'User IDs',
name: 'userIds',
type: 'string',
required: true,
displayOptions: {
show: {
resource: [
'user',
],
operation: [
'getById',
],
},
},
default: '',
description: `User's ID`,
},
{
displayName: 'Additional Fields',
name: 'additionalFields',
type: 'collection',
placeholder: 'Add Field',
displayOptions: {
show: {
resource: [
'user',
],
operation: [
'getById',
],
},
},
default: {},
options: [
{
displayName: 'Since',
name: 'since',
type: 'dateTime',
default: '',
description: 'Only return users that have been modified since the given Unix timestamp (in milliseconds).',
},
],
},
],
};
@ -1245,6 +1315,10 @@ export class Mattermost implements INodeType {
let resource: string;
let requestMethod = 'POST';
let returnAll = false;
let userIds: string[] = [];
resource = this.getNodeParameter('resource', 0) as string;
operation = this.getNodeParameter('operation', 0) as string;
// For Post
let body: IDataObject;
@ -1256,9 +1330,6 @@ export class Mattermost implements INodeType {
body = {};
qs = {};
resource = this.getNodeParameter('resource', i) as string;
operation = this.getNodeParameter('operation', i) as string;
if (resource === 'channel') {
if (operation === 'create') {
// ----------------------------------
@ -1509,6 +1580,25 @@ export class Mattermost implements INodeType {
endpoint = `users/email/${email}`;
}
if (operation === 'getById') {
// ----------------------------------
// user:getById
// ----------------------------------
userIds = (this.getNodeParameter('userIds', i) as string).split(',') as string[];
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
if (additionalFields.since) {
qs.since = new Date(additionalFields.since as string).getTime();
}
requestMethod = 'POST';
endpoint = 'users/ids';
//@ts-ignore
body = userIds;
}
}
else {
throw new Error(`The resource "${resource}" is not known!`);
@ -1519,6 +1609,18 @@ export class Mattermost implements INodeType {
responseData = await apiRequestAllItems.call(this, requestMethod, endpoint, body, qs);
} else {
responseData = await apiRequest.call(this, requestMethod, endpoint, body, qs);
if (resource === 'channel' && operation === 'members') {
const resolveData = this.getNodeParameter('resolveData', i) as boolean;
if (resolveData) {
const userIds: string[] = [];
for (const data of responseData) {
userIds.push(data.user_id);
}
if (userIds.length > 0) {
responseData = await apiRequest.call(this, 'POST', 'users/ids', userIds , qs);
}
}
}
}
if (Array.isArray(responseData)) {
returnData.push.apply(returnData, responseData);