mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-25 12:44:07 -08:00
⚡ Improvements to Google Tasks node
This commit is contained in:
parent
8116b5f970
commit
d261eb5a12
|
@ -1,6 +1,11 @@
|
||||||
import { ICredentialType, NodePropertyTypes } from 'n8n-workflow';
|
import {
|
||||||
|
ICredentialType,
|
||||||
|
NodePropertyTypes,
|
||||||
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
const scopes = ['https://www.googleapis.com/auth/tasks'];
|
const scopes = [
|
||||||
|
'https://www.googleapis.com/auth/tasks',
|
||||||
|
];
|
||||||
|
|
||||||
export class GoogleTasksOAuth2Api implements ICredentialType {
|
export class GoogleTasksOAuth2Api implements ICredentialType {
|
||||||
name = 'googleTasksOAuth2Api';
|
name = 'googleTasksOAuth2Api';
|
||||||
|
@ -12,6 +17,6 @@ export class GoogleTasksOAuth2Api implements ICredentialType {
|
||||||
name: 'scope',
|
name: 'scope',
|
||||||
type: 'hidden' as NodePropertyTypes,
|
type: 'hidden' as NodePropertyTypes,
|
||||||
default: scopes.join(' ')
|
default: scopes.join(' ')
|
||||||
}
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,16 @@
|
||||||
import { OptionsWithUri } from 'request';
|
import {
|
||||||
|
OptionsWithUri,
|
||||||
|
} from 'request';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
IExecuteFunctions,
|
IExecuteFunctions,
|
||||||
IExecuteSingleFunctions,
|
IExecuteSingleFunctions,
|
||||||
ILoadOptionsFunctions
|
ILoadOptionsFunctions,
|
||||||
} from 'n8n-core';
|
} from 'n8n-core';
|
||||||
|
|
||||||
import { IDataObject } from 'n8n-workflow';
|
import {
|
||||||
|
IDataObject,
|
||||||
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
export async function googleApiRequest(
|
export async function googleApiRequest(
|
||||||
this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions,
|
this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions,
|
||||||
|
@ -27,6 +31,7 @@ export async function googleApiRequest(
|
||||||
uri: uri || `https://www.googleapis.com${resource}`,
|
uri: uri || `https://www.googleapis.com${resource}`,
|
||||||
json: true
|
json: true
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (Object.keys(headers).length !== 0) {
|
if (Object.keys(headers).length !== 0) {
|
||||||
options.headers = Object.assign({}, options.headers, headers);
|
options.headers = Object.assign({}, options.headers, headers);
|
||||||
|
@ -41,10 +46,14 @@ export async function googleApiRequest(
|
||||||
options
|
options
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.response && error.response.body && error.response.body.message) {
|
if (error.response && error.response.body && error.response.body.error) {
|
||||||
|
|
||||||
|
let errors = error.response.body.error.errors;
|
||||||
|
|
||||||
|
errors = errors.map((e: IDataObject) => e.message);
|
||||||
// Try to return the error prettier
|
// Try to return the error prettier
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Google Tasks error response [${error.statusCode}]: ${error.response.body.message}`
|
`Google Tasks error response [${error.statusCode}]: ${errors.join('|')}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
throw error;
|
throw error;
|
||||||
|
|
|
@ -1,16 +1,25 @@
|
||||||
import { IExecuteFunctions } from 'n8n-core';
|
import {
|
||||||
|
IExecuteFunctions,
|
||||||
|
} from 'n8n-core';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
IDataObject,
|
IDataObject,
|
||||||
INodeExecutionData,
|
|
||||||
INodeTypeDescription,
|
|
||||||
INodeType,
|
|
||||||
ILoadOptionsFunctions,
|
ILoadOptionsFunctions,
|
||||||
INodePropertyOptions
|
INodeExecutionData,
|
||||||
|
INodePropertyOptions,
|
||||||
|
INodeType,
|
||||||
|
INodeTypeDescription,
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
import { googleApiRequest, googleApiRequestAllItems } from './GenericFunctions';
|
|
||||||
|
|
||||||
import { taskOperations, taskFields } from './TaskDescription';
|
import {
|
||||||
|
googleApiRequest,
|
||||||
|
googleApiRequestAllItems,
|
||||||
|
} from './GenericFunctions';
|
||||||
|
|
||||||
|
import {
|
||||||
|
taskOperations,
|
||||||
|
taskFields,
|
||||||
|
} from './TaskDescription';
|
||||||
|
|
||||||
export class GoogleTasks implements INodeType {
|
export class GoogleTasks implements INodeType {
|
||||||
description: INodeTypeDescription = {
|
description: INodeTypeDescription = {
|
||||||
|
@ -129,10 +138,6 @@ export class GoogleTasks implements INodeType {
|
||||||
body.deleted = additionalFields.deleted as boolean;
|
body.deleted = additionalFields.deleted as boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (additionalFields.selfLink) {
|
|
||||||
body.selfLink = additionalFields.selfLink as string;
|
|
||||||
}
|
|
||||||
|
|
||||||
responseData = await googleApiRequest.call(
|
responseData = await googleApiRequest.call(
|
||||||
this,
|
this,
|
||||||
'POST',
|
'POST',
|
||||||
|
@ -186,9 +191,6 @@ export class GoogleTasks implements INodeType {
|
||||||
if (options.dueMax) {
|
if (options.dueMax) {
|
||||||
qs.dueMax = options.dueMax as string;
|
qs.dueMax = options.dueMax as string;
|
||||||
}
|
}
|
||||||
if (options.pageToken) {
|
|
||||||
qs.pageToken = options.pageToken as string;
|
|
||||||
}
|
|
||||||
if (options.showCompleted) {
|
if (options.showCompleted) {
|
||||||
qs.showCompleted = options.showCompleted as boolean;
|
qs.showCompleted = options.showCompleted as boolean;
|
||||||
}
|
}
|
||||||
|
@ -198,10 +200,10 @@ export class GoogleTasks implements INodeType {
|
||||||
if (options.showHidden) {
|
if (options.showHidden) {
|
||||||
qs.showHidden = options.showHidden as boolean;
|
qs.showHidden = options.showHidden as boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.updatedMin) {
|
if (options.updatedMin) {
|
||||||
qs.updatedMin = options.updatedMin as string;
|
qs.updatedMin = options.updatedMin as string;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (returnAll) {
|
if (returnAll) {
|
||||||
responseData = await googleApiRequestAllItems.call(
|
responseData = await googleApiRequestAllItems.call(
|
||||||
this,
|
this,
|
||||||
|
@ -261,10 +263,6 @@ export class GoogleTasks implements INodeType {
|
||||||
body.deleted = updateFields.deleted as boolean;
|
body.deleted = updateFields.deleted as boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (updateFields.selfLink) {
|
|
||||||
body.selfLink = updateFields.selfLink as string;
|
|
||||||
}
|
|
||||||
|
|
||||||
responseData = await googleApiRequest.call(
|
responseData = await googleApiRequest.call(
|
||||||
this,
|
this,
|
||||||
'PATCH',
|
'PATCH',
|
||||||
|
@ -274,12 +272,11 @@ export class GoogleTasks implements INodeType {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
if (Array.isArray(responseData)) {
|
||||||
|
returnData.push.apply(returnData, responseData as IDataObject[]);
|
||||||
if (Array.isArray(responseData)) {
|
} else if (responseData !== undefined) {
|
||||||
returnData.push.apply(returnData, responseData as IDataObject[]);
|
returnData.push(responseData as IDataObject);
|
||||||
} else if (responseData !== undefined) {
|
}
|
||||||
returnData.push(responseData as IDataObject);
|
|
||||||
}
|
}
|
||||||
return [this.helpers.returnJsonArray(returnData)];
|
return [this.helpers.returnJsonArray(returnData)];
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
import { INodeProperties } from 'n8n-workflow';
|
import {
|
||||||
|
INodeProperties,
|
||||||
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
export const taskOperations = [
|
export const taskOperations = [
|
||||||
{
|
{
|
||||||
|
@ -46,7 +48,7 @@ export const taskOperations = [
|
||||||
|
|
||||||
export const taskFields = [
|
export const taskFields = [
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
/* task:create */
|
/* task:create */
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
{
|
{
|
||||||
displayName: 'TaskList',
|
displayName: 'TaskList',
|
||||||
|
@ -64,7 +66,7 @@ export const taskFields = [
|
||||||
resource: [
|
resource: [
|
||||||
'task',
|
'task',
|
||||||
],
|
],
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
|
@ -86,14 +88,14 @@ export const taskFields = [
|
||||||
},
|
},
|
||||||
options: [
|
options: [
|
||||||
{
|
{
|
||||||
displayName: 'Completion date',
|
displayName: 'Completion Date',
|
||||||
name: 'completed',
|
name: 'completed',
|
||||||
type: 'dateTime',
|
type: 'dateTime',
|
||||||
default: '',
|
default: '',
|
||||||
description: `Completion date of the task (as a RFC 3339 timestamp). This field is omitted if the task has not been completed.`,
|
description: `Completion date of the task (as a RFC 3339 timestamp). This field is omitted if the task has not been completed.`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Deleted status',
|
displayName: 'Deleted',
|
||||||
name: 'deleted',
|
name: 'deleted',
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
default: false,
|
default: false,
|
||||||
|
@ -127,24 +129,17 @@ export const taskFields = [
|
||||||
default: '',
|
default: '',
|
||||||
description: 'Previous sibling task identifier. If the task is created at the first position among its siblings, this parameter is omitted.',
|
description: 'Previous sibling task identifier. If the task is created at the first position among its siblings, this parameter is omitted.',
|
||||||
},
|
},
|
||||||
{
|
|
||||||
displayName: 'Self Link',
|
|
||||||
name: 'selfLink',
|
|
||||||
type: 'string',
|
|
||||||
default: '',
|
|
||||||
description: 'URL pointing to this task. Used to retrieve, update, or delete this task.',
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
displayName: 'Status',
|
displayName: 'Status',
|
||||||
name: 'status',
|
name: 'status',
|
||||||
type: 'options',
|
type: 'options',
|
||||||
options: [
|
options: [
|
||||||
{
|
{
|
||||||
name: 'needs Action',
|
name: 'Needs Action',
|
||||||
value: 'needsAction',
|
value: 'needsAction',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'completed',
|
name: 'Completed',
|
||||||
value: 'completed',
|
value: 'completed',
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
@ -158,11 +153,10 @@ export const taskFields = [
|
||||||
default: '',
|
default: '',
|
||||||
description: 'Title of the task.',
|
description: 'Title of the task.',
|
||||||
},
|
},
|
||||||
|
],
|
||||||
]
|
|
||||||
},
|
},
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
/* task:delete */
|
/* task:delete */
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
{
|
{
|
||||||
displayName: 'TaskList',
|
displayName: 'TaskList',
|
||||||
|
@ -180,7 +174,7 @@ export const taskFields = [
|
||||||
resource: [
|
resource: [
|
||||||
'task',
|
'task',
|
||||||
],
|
],
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
|
@ -197,12 +191,12 @@ export const taskFields = [
|
||||||
resource: [
|
resource: [
|
||||||
'task',
|
'task',
|
||||||
],
|
],
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
/* task:get */
|
/* task:get */
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
{
|
{
|
||||||
displayName: 'TaskList',
|
displayName: 'TaskList',
|
||||||
|
@ -237,12 +231,12 @@ export const taskFields = [
|
||||||
resource: [
|
resource: [
|
||||||
'task',
|
'task',
|
||||||
],
|
],
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
/* task:getAll */
|
/* task:getAll */
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
{
|
{
|
||||||
displayName: 'TaskList',
|
displayName: 'TaskList',
|
||||||
|
@ -260,7 +254,7 @@ export const taskFields = [
|
||||||
resource: [
|
resource: [
|
||||||
'task',
|
'task',
|
||||||
],
|
],
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
|
@ -276,7 +270,7 @@ export const taskFields = [
|
||||||
resource: [
|
resource: [
|
||||||
'task',
|
'task',
|
||||||
],
|
],
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
default: false,
|
default: false,
|
||||||
description: 'If all results should be returned or only up to a given limit.',
|
description: 'If all results should be returned or only up to a given limit.',
|
||||||
|
@ -296,7 +290,7 @@ export const taskFields = [
|
||||||
returnAll: [
|
returnAll: [
|
||||||
false,
|
false,
|
||||||
],
|
],
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
typeOptions: {
|
typeOptions: {
|
||||||
minValue: 1,
|
minValue: 1,
|
||||||
|
@ -319,9 +313,8 @@ export const taskFields = [
|
||||||
resource: [
|
resource: [
|
||||||
'task',
|
'task',
|
||||||
],
|
],
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
options: [
|
options: [
|
||||||
{
|
{
|
||||||
displayName: 'Completed Max',
|
displayName: 'Completed Max',
|
||||||
|
@ -351,14 +344,6 @@ export const taskFields = [
|
||||||
default: '',
|
default: '',
|
||||||
description: 'Upper bound for a task due date (as a RFC 3339 timestamp) to filter by.',
|
description: 'Upper bound for a task due date (as a RFC 3339 timestamp) to filter by.',
|
||||||
},
|
},
|
||||||
{
|
|
||||||
displayName: 'Page Token',
|
|
||||||
name: 'pageToken',
|
|
||||||
type: 'string',
|
|
||||||
default: '',
|
|
||||||
description: 'Token specifying the result page to return.',
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
{
|
||||||
displayName: 'Show Completed',
|
displayName: 'Show Completed',
|
||||||
name: 'showCompleted',
|
name: 'showCompleted',
|
||||||
|
@ -383,14 +368,14 @@ export const taskFields = [
|
||||||
{
|
{
|
||||||
displayName: 'Updated Min',
|
displayName: 'Updated Min',
|
||||||
name: 'updatedMin',
|
name: 'updatedMin',
|
||||||
type: 'string',
|
type: 'dateTime',
|
||||||
default: '',
|
default: '',
|
||||||
description: 'Lower bound for a task last modification time (as a RFC 3339 timestamp) to filter by.',
|
description: 'Lower bound for a task last modification time (as a RFC 3339 timestamp) to filter by.',
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
/* task:update */
|
/* task:update */
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
{
|
{
|
||||||
displayName: 'TaskList',
|
displayName: 'TaskList',
|
||||||
|
@ -408,7 +393,7 @@ export const taskFields = [
|
||||||
resource: [
|
resource: [
|
||||||
'task',
|
'task',
|
||||||
],
|
],
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
|
@ -425,7 +410,7 @@ export const taskFields = [
|
||||||
resource: [
|
resource: [
|
||||||
'task',
|
'task',
|
||||||
],
|
],
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
|
@ -447,7 +432,7 @@ export const taskFields = [
|
||||||
},
|
},
|
||||||
options: [
|
options: [
|
||||||
{
|
{
|
||||||
displayName: 'Completion date',
|
displayName: 'Completion Date',
|
||||||
name: 'completed',
|
name: 'completed',
|
||||||
type: 'dateTime',
|
type: 'dateTime',
|
||||||
default: '',
|
default: '',
|
||||||
|
@ -455,7 +440,7 @@ export const taskFields = [
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
displayName: 'Deleted status',
|
displayName: 'Deleted',
|
||||||
name: 'deleted',
|
name: 'deleted',
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
default: false,
|
default: false,
|
||||||
|
@ -465,6 +450,9 @@ export const taskFields = [
|
||||||
displayName: 'Notes',
|
displayName: 'Notes',
|
||||||
name: 'notes',
|
name: 'notes',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
|
typeOptions: {
|
||||||
|
alwaysOpenEditWindow: true,
|
||||||
|
},
|
||||||
default: '',
|
default: '',
|
||||||
description: 'Additional Notes.',
|
description: 'Additional Notes.',
|
||||||
},
|
},
|
||||||
|
@ -475,24 +463,17 @@ export const taskFields = [
|
||||||
default: '',
|
default: '',
|
||||||
description: 'Previous sibling task identifier. If the task is created at the first position among its siblings, this parameter is omitted.',
|
description: 'Previous sibling task identifier. If the task is created at the first position among its siblings, this parameter is omitted.',
|
||||||
},
|
},
|
||||||
{
|
|
||||||
displayName: 'Self Link',
|
|
||||||
name: 'selfLink',
|
|
||||||
type: 'string',
|
|
||||||
default: '',
|
|
||||||
description: 'URL pointing to this task. Used to retrieve, update, or delete this task.',
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
displayName: 'Status',
|
displayName: 'Status',
|
||||||
name: 'status',
|
name: 'status',
|
||||||
type: 'options',
|
type: 'options',
|
||||||
options: [
|
options: [
|
||||||
{
|
{
|
||||||
name: 'needs Update',
|
name: 'Needs Update',
|
||||||
value: 'needsAction',
|
value: 'needsAction',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'completed',
|
name: 'Completed',
|
||||||
value: 'completed',
|
value: 'completed',
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
@ -506,8 +487,6 @@ export const taskFields = [
|
||||||
default: '',
|
default: '',
|
||||||
description: 'Title of the task.',
|
description: 'Title of the task.',
|
||||||
},
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
]
|
|
||||||
}
|
|
||||||
] as INodeProperties[];
|
] as INodeProperties[];
|
||||||
|
|
Loading…
Reference in a new issue