UNPKG

n8n-nodes-base

Version:

Base nodes of n8n

256 lines 10.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.description = exports.properties = void 0; exports.execute = execute; const utilities_1 = require("../../../../../../utils/utilities"); const descriptions_1 = require("../../descriptions"); const utils_1 = require("../../helpers/utils"); const transport_1 = require("../../transport"); exports.properties = [ descriptions_1.folderRLC, ...descriptions_1.returnAllOrLimit, { displayName: 'Output', name: 'output', type: 'options', default: 'simple', options: [ { name: 'Simplified', value: 'simple', }, { name: 'Raw', value: 'raw', }, { name: 'Select Included Fields', value: 'fields', }, ], }, { displayName: 'Fields', name: 'fields', type: 'multiOptions', description: 'The fields to add to the output', displayOptions: { show: { output: ['fields'], }, }, options: utils_1.messageFields, default: [], }, { displayName: 'Fetching a lot of messages may take a long time. Consider using filters to speed things up', name: 'filtersNotice', type: 'notice', default: '', displayOptions: { show: { returnAll: [true], }, }, }, { displayName: 'Filters', name: 'filtersUI', type: 'fixedCollection', placeholder: 'Add Filters', default: {}, options: [ { displayName: 'Values', name: 'values', values: [ { displayName: 'Filter By', name: 'filterBy', type: 'options', options: [ { name: 'Filters', value: 'filters', }, { name: 'Search', value: 'search', }, ], default: 'filters', }, { displayName: 'Search', name: 'search', type: 'string', default: '', placeholder: 'e.g. automation', description: 'Only return messages that contains search term. Without specific message properties, the search is carried out on the default search properties of from, subject, and body. <a href="https://docs.microsoft.com/en-us/graph/query-parameters#search-parameter target="_blank">More info</a>.', displayOptions: { show: { filterBy: ['search'], }, }, }, { displayName: 'Filters', name: 'filters', type: 'collection', placeholder: 'Add Filter', default: {}, displayOptions: { show: { filterBy: ['filters'], }, }, options: [ { displayName: 'Filter Query', name: 'custom', type: 'string', default: '', placeholder: 'e.g. isRead eq false', hint: 'Search query to filter messages. <a href="https://learn.microsoft.com/en-us/graph/filter-query-parameter">More info</a>.', }, { displayName: 'Has Attachments', name: 'hasAttachments', type: 'boolean', default: false, }, { displayName: 'Read Status', name: 'readStatus', type: 'options', default: 'unread', hint: 'Filter messages by whether they have been read or not', options: [ { // eslint-disable-next-line n8n-nodes-base/node-param-display-name-miscased name: 'Unread and read messages', value: 'both', }, { // eslint-disable-next-line n8n-nodes-base/node-param-display-name-miscased name: 'Unread messages only', value: 'unread', }, { // eslint-disable-next-line n8n-nodes-base/node-param-display-name-miscased name: 'Read messages only', value: 'read', }, ], }, { displayName: 'Received After', name: 'receivedAfter', type: 'dateTime', default: '', description: 'Get all messages received after the specified date. In an expression you can set date using string in ISO format or a timestamp in miliseconds.', }, { displayName: 'Received Before', name: 'receivedBefore', type: 'dateTime', default: '', description: 'Get all messages received before the specified date. In an expression you can set date using string in ISO format or a timestamp in miliseconds.', }, { displayName: 'Sender', name: 'sender', type: 'string', default: '', description: 'Sender name or email to filter by', }, ], }, ], }, ], }, { displayName: 'Options', name: 'options', type: 'collection', placeholder: 'Add option', default: {}, options: [ { displayName: 'Attachments Prefix', name: 'attachmentsPrefix', type: 'string', default: 'attachment_', description: 'Prefix for name of the output fields to put the binary files data in. An index starting from 0 will be added. So if name is "attachment_" the first attachment is saved to "attachment_0".', }, { displayName: 'Download Attachments', name: 'downloadAttachments', type: 'boolean', default: false, description: "Whether the message's attachments will be downloaded and included in the output", }, ], }, ]; const displayOptions = { show: { resource: ['folderMessage'], operation: ['getAll'], }, }; exports.description = (0, utilities_1.updateDisplayOptions)(displayOptions, exports.properties); async function execute(index) { let responseData; const qs = {}; const folderId = (0, utils_1.decodeOutlookId)(this.getNodeParameter('folderId', index, undefined, { extractValue: true, })); const returnAll = this.getNodeParameter('returnAll', index); const filters = this.getNodeParameter('filtersUI.values', index, {}); const options = this.getNodeParameter('options', index, {}); const output = this.getNodeParameter('output', index); if (output === 'fields') { const fields = this.getNodeParameter('fields', index); if (options.downloadAttachments) { fields.push('hasAttachments'); } qs.$select = fields.join(','); } if (output === 'simple') { qs.$select = 'id,conversationId,subject,bodyPreview,from,toRecipients,categories,hasAttachments'; } if (filters.filterBy === 'search' && filters.search !== '') { qs.$search = `"${filters.search}"`; } if (filters.filterBy === 'filters') { const filterString = (0, utils_1.prepareFilterString)(filters); if (filterString) { qs.$filter = filterString; } } const endpoint = `/mailFolders/${folderId}/messages`; if (returnAll) { responseData = await transport_1.microsoftApiRequestAllItems.call(this, 'value', 'GET', endpoint, undefined, qs); } else { qs.$top = this.getNodeParameter('limit', index); responseData = await transport_1.microsoftApiRequest.call(this, 'GET', endpoint, undefined, qs); responseData = responseData.value; } if (output === 'simple') { responseData = (0, utils_1.simplifyOutputMessages)(responseData); } let executionData = []; if (options.downloadAttachments) { const prefix = options.attachmentsPrefix || 'attachment_'; executionData = await transport_1.downloadAttachments.call(this, responseData, prefix); } else { executionData = this.helpers.constructExecutionMetaData(this.helpers.returnJsonArray(responseData), { itemData: { item: index } }); } return executionData; } //# sourceMappingURL=getAll.operation.js.map