n8n-nodes-base
Version:
Base nodes of n8n
108 lines • 3.68 kB
JavaScript
;
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.draftRLC,
{
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: '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: ['draft'],
operation: ['get'],
},
};
exports.description = (0, utilities_1.updateDisplayOptions)(displayOptions, exports.properties);
async function execute(index) {
let responseData;
const qs = {};
const draftId = this.getNodeParameter('draftId', index, undefined, {
extractValue: true,
});
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';
}
responseData = await transport_1.microsoftApiRequest.call(this, 'GET', `/messages/${draftId}`, undefined, qs);
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=get.operation.js.map