mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
🔀 Merge branch 'master' into Improve-Zulip-Node
This commit is contained in:
commit
5e4fde6c6a
|
@ -12,12 +12,20 @@ export class AgileCrmApi implements ICredentialType {
|
||||||
name: 'email',
|
name: 'email',
|
||||||
type: 'string' as NodePropertyTypes,
|
type: 'string' as NodePropertyTypes,
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'API Key',
|
displayName: 'API Key',
|
||||||
name: 'apiKey',
|
name: 'apiKey',
|
||||||
type: 'string' as NodePropertyTypes,
|
type: 'string' as NodePropertyTypes,
|
||||||
default: '',
|
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.',
|
||||||
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ export async function agileCrmApiRequest(this: IHookFunctions | IExecuteFunction
|
||||||
username: credentials!.email as string,
|
username: credentials!.email as string,
|
||||||
password: credentials!.apiKey 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,
|
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
|
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 credentials = this.getCredentials('agileCrmApi');
|
||||||
|
const baseUri = `https://${credentials!.subdomain}.agilecrm.com/dev/`;
|
||||||
const options: OptionsWithUri = {
|
const options: OptionsWithUri = {
|
||||||
method,
|
method,
|
||||||
headers: {
|
headers: {
|
||||||
|
|
|
@ -1,13 +1,19 @@
|
||||||
import { OptionsWithUri } from 'request';
|
import {
|
||||||
|
OptionsWithUri,
|
||||||
|
} from 'request';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
IExecuteFunctions,
|
IExecuteFunctions,
|
||||||
|
IExecuteSingleFunctions,
|
||||||
IHookFunctions,
|
IHookFunctions,
|
||||||
ILoadOptionsFunctions,
|
ILoadOptionsFunctions,
|
||||||
IExecuteSingleFunctions
|
|
||||||
} from 'n8n-core';
|
} 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');
|
const credentials = this.getCredentials('mailchimpApi');
|
||||||
|
|
||||||
if (credentials === undefined) {
|
if (credentials === undefined) {
|
||||||
|
@ -27,6 +33,7 @@ export async function mailchimpApiRequest(this: IHookFunctions | IExecuteFunctio
|
||||||
const options: OptionsWithUri = {
|
const options: OptionsWithUri = {
|
||||||
headers: headerWithAuthentication,
|
headers: headerWithAuthentication,
|
||||||
method,
|
method,
|
||||||
|
qs,
|
||||||
uri: `https://${datacenter}.${host}${endpoint}`,
|
uri: `https://${datacenter}.${host}${endpoint}`,
|
||||||
json: true,
|
json: true,
|
||||||
};
|
};
|
||||||
|
@ -34,19 +41,36 @@ export async function mailchimpApiRequest(this: IHookFunctions | IExecuteFunctio
|
||||||
if (Object.keys(body).length !== 0) {
|
if (Object.keys(body).length !== 0) {
|
||||||
options.body = body;
|
options.body = body;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return await this.helpers.request!(options);
|
return await this.helpers.request!(options);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const errorMessage = error.response.body.message || error.response.body.Message;
|
if (error.response.body && error.response.body.detail) {
|
||||||
|
throw new Error(`Mailchimp Error response [${error.statusCode}]: ${error.response.body.detail}`);
|
||||||
if (errorMessage !== undefined) {
|
|
||||||
throw errorMessage;
|
|
||||||
}
|
}
|
||||||
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
|
export function validateJSON(json: string | undefined): any { // tslint:disable-line:no-any
|
||||||
let result;
|
let result;
|
||||||
try {
|
try {
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -98,9 +98,9 @@ export class Mattermost implements INodeType {
|
||||||
description: 'Soft-deletes a channel',
|
description: 'Soft-deletes a channel',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Members',
|
name: 'Member',
|
||||||
value: 'members',
|
value: 'members',
|
||||||
description: 'Returns the members of a channel.',
|
description: 'Get a page of members for a channel.',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Restore',
|
name: 'Restore',
|
||||||
|
@ -317,6 +317,23 @@ export class Mattermost implements INodeType {
|
||||||
},
|
},
|
||||||
description: 'The Mattermost Team.',
|
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',
|
displayName: 'Return All',
|
||||||
name: 'returnAll',
|
name: 'returnAll',
|
||||||
|
@ -950,6 +967,11 @@ export class Mattermost implements INodeType {
|
||||||
value: 'getByEmail',
|
value: 'getByEmail',
|
||||||
description: 'Get a user by email',
|
description: 'Get a user by email',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'Get By ID',
|
||||||
|
value: 'getById',
|
||||||
|
description: 'Get a user by id',
|
||||||
|
},
|
||||||
],
|
],
|
||||||
default: '',
|
default: '',
|
||||||
description: 'The operation to perform.',
|
description: 'The operation to perform.',
|
||||||
|
@ -1113,6 +1135,54 @@ export class Mattermost implements INodeType {
|
||||||
default: '',
|
default: '',
|
||||||
description: `User's email`,
|
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 resource: string;
|
||||||
let requestMethod = 'POST';
|
let requestMethod = 'POST';
|
||||||
let returnAll = false;
|
let returnAll = false;
|
||||||
|
let userIds: string[] = [];
|
||||||
|
|
||||||
|
resource = this.getNodeParameter('resource', 0) as string;
|
||||||
|
operation = this.getNodeParameter('operation', 0) as string;
|
||||||
|
|
||||||
// For Post
|
// For Post
|
||||||
let body: IDataObject;
|
let body: IDataObject;
|
||||||
|
@ -1256,9 +1330,6 @@ export class Mattermost implements INodeType {
|
||||||
body = {};
|
body = {};
|
||||||
qs = {};
|
qs = {};
|
||||||
|
|
||||||
resource = this.getNodeParameter('resource', i) as string;
|
|
||||||
operation = this.getNodeParameter('operation', i) as string;
|
|
||||||
|
|
||||||
if (resource === 'channel') {
|
if (resource === 'channel') {
|
||||||
if (operation === 'create') {
|
if (operation === 'create') {
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
|
@ -1509,6 +1580,25 @@ export class Mattermost implements INodeType {
|
||||||
endpoint = `users/email/${email}`;
|
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 {
|
else {
|
||||||
throw new Error(`The resource "${resource}" is not known!`);
|
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);
|
responseData = await apiRequestAllItems.call(this, requestMethod, endpoint, body, qs);
|
||||||
} else {
|
} else {
|
||||||
responseData = await apiRequest.call(this, requestMethod, endpoint, body, qs);
|
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)) {
|
if (Array.isArray(responseData)) {
|
||||||
returnData.push.apply(returnData, responseData);
|
returnData.push.apply(returnData, responseData);
|
||||||
|
|
Loading…
Reference in a new issue