feat(Microsoft Outlook Node): Node overhaul (#4449)
[N8N-4995](https://linear.app/n8n/issue/N8N-4995) --------- Co-authored-by: Giulio Andreini <g.andreini@gmail.com>
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
import type { IDataObject, IExecuteFunctions, INodeProperties } from 'n8n-workflow';
|
||||
import { microsoftApiRequest } from '../../transport';
|
||||
import { updateDisplayOptions } from '@utils/utilities';
|
||||
import { folderRLC } from '../../descriptions';
|
||||
import { decodeOutlookId } from '../../helpers/utils';
|
||||
|
||||
export const properties: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Name',
|
||||
name: 'displayName',
|
||||
description: 'Name of the folder',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
placeholder: 'e.g. My Folder',
|
||||
},
|
||||
{
|
||||
displayName: 'Options',
|
||||
name: 'options',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Option',
|
||||
default: {},
|
||||
options: [{ ...folderRLC, displayName: 'Parent Folder', required: false }],
|
||||
},
|
||||
];
|
||||
|
||||
const displayOptions = {
|
||||
show: {
|
||||
resource: ['folder'],
|
||||
operation: ['create'],
|
||||
},
|
||||
};
|
||||
|
||||
export const description = updateDisplayOptions(displayOptions, properties);
|
||||
|
||||
export async function execute(this: IExecuteFunctions, index: number) {
|
||||
const displayName = this.getNodeParameter('displayName', index) as string;
|
||||
|
||||
const folderId = decodeOutlookId(
|
||||
this.getNodeParameter('options.folderId', index, '', {
|
||||
extractValue: true,
|
||||
}) as string,
|
||||
);
|
||||
|
||||
const body: IDataObject = {
|
||||
displayName,
|
||||
};
|
||||
|
||||
let endpoint;
|
||||
|
||||
if (folderId) {
|
||||
endpoint = `/mailFolders/${folderId}/childFolders`;
|
||||
} else {
|
||||
endpoint = '/mailFolders';
|
||||
}
|
||||
|
||||
const responseData = await microsoftApiRequest.call(this, 'POST', endpoint, body);
|
||||
|
||||
const executionData = this.helpers.constructExecutionMetaData(
|
||||
this.helpers.returnJsonArray(responseData as IDataObject[]),
|
||||
{ itemData: { item: index } },
|
||||
);
|
||||
|
||||
return executionData;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import type { IExecuteFunctions, INodeProperties } from 'n8n-workflow';
|
||||
import { microsoftApiRequest } from '../../transport';
|
||||
import { updateDisplayOptions } from '@utils/utilities';
|
||||
import { folderRLC } from '../../descriptions';
|
||||
import { decodeOutlookId } from '../../helpers/utils';
|
||||
|
||||
export const properties: INodeProperties[] = [folderRLC];
|
||||
|
||||
const displayOptions = {
|
||||
show: {
|
||||
resource: ['folder'],
|
||||
operation: ['delete'],
|
||||
},
|
||||
};
|
||||
|
||||
export const description = updateDisplayOptions(displayOptions, properties);
|
||||
|
||||
export async function execute(this: IExecuteFunctions, index: number) {
|
||||
const folderId = decodeOutlookId(
|
||||
this.getNodeParameter('folderId', index, undefined, {
|
||||
extractValue: true,
|
||||
}) as string,
|
||||
);
|
||||
|
||||
await microsoftApiRequest.call(this, 'DELETE', `/mailFolders/${folderId}`);
|
||||
|
||||
const executionData = this.helpers.constructExecutionMetaData(
|
||||
this.helpers.returnJsonArray({ success: true }),
|
||||
{ itemData: { item: index } },
|
||||
);
|
||||
|
||||
return executionData;
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
import type { IDataObject, IExecuteFunctions, INodeProperties } from 'n8n-workflow';
|
||||
import { microsoftApiRequest } from '../../transport';
|
||||
import { updateDisplayOptions } from '@utils/utilities';
|
||||
import { folderFields, folderRLC } from '../../descriptions';
|
||||
import { decodeOutlookId } from '../../helpers/utils';
|
||||
|
||||
export const properties: INodeProperties[] = [
|
||||
folderRLC,
|
||||
{
|
||||
displayName: 'Options',
|
||||
name: 'options',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Option',
|
||||
default: {},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Fields',
|
||||
name: 'fields',
|
||||
type: 'multiOptions',
|
||||
description: 'The fields to add to the output',
|
||||
options: folderFields,
|
||||
default: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
const displayOptions = {
|
||||
show: {
|
||||
resource: ['folder'],
|
||||
operation: ['get'],
|
||||
},
|
||||
};
|
||||
|
||||
export const description = updateDisplayOptions(displayOptions, properties);
|
||||
|
||||
export async function execute(this: IExecuteFunctions, index: number) {
|
||||
const qs: IDataObject = {};
|
||||
|
||||
const folderId = decodeOutlookId(
|
||||
this.getNodeParameter('folderId', index, undefined, {
|
||||
extractValue: true,
|
||||
}) as string,
|
||||
);
|
||||
|
||||
const options = this.getNodeParameter('options', index);
|
||||
|
||||
if (options.fields) {
|
||||
qs.$select = (options.fields as string[]).join(',');
|
||||
}
|
||||
|
||||
if (options.filter) {
|
||||
qs.$filter = options.filter;
|
||||
}
|
||||
const responseData = await microsoftApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/mailFolders/${folderId}`,
|
||||
{},
|
||||
qs,
|
||||
);
|
||||
|
||||
const executionData = this.helpers.constructExecutionMetaData(
|
||||
this.helpers.returnJsonArray(responseData as IDataObject),
|
||||
{ itemData: { item: index } },
|
||||
);
|
||||
|
||||
return executionData;
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
import type { IDataObject, IExecuteFunctions, INodeProperties } from 'n8n-workflow';
|
||||
import { getSubfolders, microsoftApiRequest, microsoftApiRequestAllItems } from '../../transport';
|
||||
import { updateDisplayOptions } from '@utils/utilities';
|
||||
import { folderFields, folderRLC, returnAllOrLimit } from '../../descriptions';
|
||||
|
||||
export const properties: INodeProperties[] = [
|
||||
...returnAllOrLimit,
|
||||
{
|
||||
displayName: 'Filters',
|
||||
name: 'filters',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Filter',
|
||||
default: {},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Filter Query',
|
||||
name: 'filter',
|
||||
type: 'string',
|
||||
default: '',
|
||||
placeholder: "e.g. displayName eq 'My Folder'",
|
||||
hint: 'Search query to filter folders. <a href="https://docs.microsoft.com/en-us/graph/query-parameters#filter-parameter">More info</a>.',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
displayName: 'Options',
|
||||
name: 'options',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Field',
|
||||
default: {},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Fields',
|
||||
name: 'fields',
|
||||
type: 'multiOptions',
|
||||
description: 'The fields to add to the output',
|
||||
options: folderFields,
|
||||
default: [],
|
||||
},
|
||||
{
|
||||
displayName: 'Include Child Folders',
|
||||
name: 'includeChildFolders',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description: 'Whether to include child folders in the response',
|
||||
},
|
||||
{
|
||||
...folderRLC,
|
||||
displayName: 'Parent Folder',
|
||||
required: false,
|
||||
description: 'The folder you want to search in',
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
const displayOptions = {
|
||||
show: {
|
||||
resource: ['folder'],
|
||||
operation: ['getAll'],
|
||||
},
|
||||
};
|
||||
|
||||
export const description = updateDisplayOptions(displayOptions, properties);
|
||||
|
||||
export async function execute(this: IExecuteFunctions, index: number) {
|
||||
let responseData;
|
||||
const qs: IDataObject = {};
|
||||
|
||||
const returnAll = this.getNodeParameter('returnAll', index);
|
||||
const options = this.getNodeParameter('options', index);
|
||||
const filter = this.getNodeParameter('filters.filter', index, '') as string;
|
||||
|
||||
const parentFolderId = this.getNodeParameter('options.folderId', index, '', {
|
||||
extractValue: true,
|
||||
}) as string;
|
||||
|
||||
if (options.fields) {
|
||||
qs.$select = (options.fields as string[]).join(',');
|
||||
}
|
||||
|
||||
if (filter) {
|
||||
qs.$filter = filter;
|
||||
}
|
||||
|
||||
let endpoint;
|
||||
if (parentFolderId) {
|
||||
endpoint = `/mailFolders/${parentFolderId}/childFolders`;
|
||||
} else {
|
||||
endpoint = '/mailFolders';
|
||||
}
|
||||
|
||||
if (returnAll) {
|
||||
responseData = await microsoftApiRequestAllItems.call(this, 'value', 'GET', endpoint, {}, qs);
|
||||
} else {
|
||||
qs.$top = this.getNodeParameter('limit', index);
|
||||
responseData = await microsoftApiRequest.call(this, 'GET', endpoint, {}, qs);
|
||||
responseData = responseData.value;
|
||||
}
|
||||
|
||||
if (options.includeChildFolders) {
|
||||
responseData = await getSubfolders.call(this, responseData as IDataObject[]);
|
||||
}
|
||||
|
||||
const executionData = this.helpers.constructExecutionMetaData(
|
||||
this.helpers.returnJsonArray(responseData as IDataObject[]),
|
||||
{ itemData: { item: index } },
|
||||
);
|
||||
|
||||
return executionData;
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
import type { INodeProperties } from 'n8n-workflow';
|
||||
import * as create from './create.operation';
|
||||
import * as del from './delete.operation';
|
||||
import * as get from './get.operation';
|
||||
import * as getAll from './getAll.operation';
|
||||
import * as update from './update.operation';
|
||||
|
||||
export { create, del as delete, get, getAll, update };
|
||||
|
||||
export const description: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['folder'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Create',
|
||||
value: 'create',
|
||||
description: "Create a mail folder in the root folder of the user's mailbox",
|
||||
action: 'Create a folder',
|
||||
},
|
||||
{
|
||||
name: 'Delete',
|
||||
value: 'delete',
|
||||
description: 'Delete a folder',
|
||||
action: 'Delete a folder',
|
||||
},
|
||||
{
|
||||
name: 'Get',
|
||||
value: 'get',
|
||||
description: 'Retrieve a folder',
|
||||
action: 'Get a folder',
|
||||
},
|
||||
{
|
||||
name: 'Get Many',
|
||||
value: 'getAll',
|
||||
description: 'Get many folders',
|
||||
action: 'Get many folders',
|
||||
},
|
||||
{
|
||||
name: 'Update',
|
||||
value: 'update',
|
||||
description: 'Update a folder',
|
||||
action: 'Update a folder',
|
||||
},
|
||||
],
|
||||
default: 'create',
|
||||
},
|
||||
...create.description,
|
||||
...del.description,
|
||||
...get.description,
|
||||
...getAll.description,
|
||||
...update.description,
|
||||
];
|
||||
@@ -0,0 +1,46 @@
|
||||
import type { IDataObject, IExecuteFunctions, INodeProperties } from 'n8n-workflow';
|
||||
import { microsoftApiRequest } from '../../transport';
|
||||
import { updateDisplayOptions } from '@utils/utilities';
|
||||
import { folderRLC } from '../../descriptions';
|
||||
import { decodeOutlookId } from '../../helpers/utils';
|
||||
|
||||
export const properties: INodeProperties[] = [
|
||||
folderRLC,
|
||||
{
|
||||
displayName: 'Name',
|
||||
name: 'displayName',
|
||||
description: 'Name of the folder',
|
||||
type: 'string',
|
||||
default: '',
|
||||
required: true,
|
||||
},
|
||||
];
|
||||
|
||||
const displayOptions = {
|
||||
show: {
|
||||
resource: ['folder'],
|
||||
operation: ['update'],
|
||||
},
|
||||
};
|
||||
|
||||
export const description = updateDisplayOptions(displayOptions, properties);
|
||||
|
||||
export async function execute(this: IExecuteFunctions, index: number) {
|
||||
const folderId = decodeOutlookId(
|
||||
this.getNodeParameter('folderId', index, undefined, {
|
||||
extractValue: true,
|
||||
}) as string,
|
||||
);
|
||||
const displayName = this.getNodeParameter('displayName', index, undefined) as string;
|
||||
|
||||
const responseData = await microsoftApiRequest.call(this, 'PATCH', `/mailFolders/${folderId}`, {
|
||||
displayName,
|
||||
});
|
||||
|
||||
const executionData = this.helpers.constructExecutionMetaData(
|
||||
this.helpers.returnJsonArray(responseData as IDataObject),
|
||||
{ itemData: { item: index } },
|
||||
);
|
||||
|
||||
return executionData;
|
||||
}
|
||||
Reference in New Issue
Block a user