UNPKG

n8n-nodes-base

Version:

Base nodes of n8n

385 lines 14.4 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.description = void 0; exports.execute = execute; const ics = __importStar(require("ics")); const moment_timezone_1 = __importDefault(require("moment-timezone")); const n8n_workflow_1 = require("n8n-workflow"); const util_1 = require("util"); const createEvent = (0, util_1.promisify)(ics.createEvent); exports.description = [ { displayName: 'Event Title', name: 'title', type: 'string', default: '', placeholder: 'e.g. New Event', }, { displayName: 'Start', name: 'start', type: 'dateTime', default: '', required: true, description: 'Date and time at which the event begins. (For all-day events, the time will be ignored.).', }, { displayName: 'End', name: 'end', type: 'dateTime', default: '', required: true, description: 'Date and time at which the event ends. (For all-day events, the time will be ignored.).', hint: 'If not set, will be equal to the start date', }, { displayName: 'All Day', name: 'allDay', type: 'boolean', default: false, description: 'Whether the event lasts all day or not', }, { displayName: 'Put Output File in Field', name: 'binaryPropertyName', type: 'string', default: 'data', required: true, hint: 'The name of the output binary field to put the file in', description: 'The field that your iCalendar file will be available under in the output', }, { displayName: 'Options', name: 'additionalFields', type: 'collection', placeholder: 'Add option', default: {}, options: [ { displayName: 'Attendees', name: 'attendeesUi', type: 'fixedCollection', typeOptions: { multipleValues: true, }, placeholder: 'Add Attendee', default: {}, options: [ { displayName: 'Attendees', name: 'attendeeValues', values: [ { displayName: 'Name', name: 'name', type: 'string', required: true, default: '', }, { displayName: 'Email', name: 'email', type: 'string', placeholder: 'e.g. name@email.com', required: true, default: '', }, { displayName: 'RSVP', name: 'rsvp', type: 'boolean', default: false, description: 'Whether the attendee has to confirm attendance or not', }, ], }, ], }, { displayName: 'Busy Status', name: 'busyStatus', type: 'options', options: [ { name: 'Busy', value: 'BUSY', }, { name: 'Tentative', value: 'TENTATIVE', }, ], default: '', description: 'Used to specify busy status for Microsoft applications, like Outlook', }, { displayName: 'Calendar Name', name: 'calName', type: 'string', default: '', description: 'Specifies the calendar (not event) name. Used by Apple iCal and Microsoft Outlook. <a href="https://docs.microsoft.com/en-us/openspecs/exchange_server_protocols/ms-oxcical/1da58449-b97e-46bd-b018-a1ce576f3e6d">More info</a>.', }, { displayName: 'Description', name: 'description', type: 'string', default: '', }, { displayName: 'File Name', name: 'fileName', type: 'string', default: '', placeholder: 'e.g. event.ics', description: 'The name of the file to be generated. Default name is event.ics.', }, { displayName: 'Geolocation', name: 'geolocationUi', type: 'fixedCollection', typeOptions: { multipleValues: false, }, placeholder: 'Add Geolocation', default: {}, options: [ { displayName: 'Geolocation', name: 'geolocationValues', values: [ { displayName: 'Latitude', name: 'lat', type: 'string', default: '', }, { displayName: 'Longitude', name: 'lon', type: 'string', default: '', }, ], }, ], }, { displayName: 'Location', name: 'location', type: 'string', default: '', description: 'The intended venue', }, { displayName: 'Recurrence Rule', name: 'recurrenceRule', type: 'string', default: '', description: 'A rule to define the repeat pattern of the event (RRULE). (<a href="https://icalendar.org/rrule-tool.html">Rule generator</a>).', }, { displayName: 'Organizer', name: 'organizerUi', type: 'fixedCollection', typeOptions: { multipleValues: false, }, placeholder: 'Add Organizer', default: {}, options: [ { displayName: 'Organizer', name: 'organizerValues', values: [ { displayName: 'Name', name: 'name', type: 'string', default: '', required: true, }, { displayName: 'Email', name: 'email', type: 'string', placeholder: 'e.g. name@email.com', default: '', required: true, }, ], }, ], }, { displayName: 'Sequence', name: 'sequence', type: 'number', default: 0, description: 'When sending an update for an event (with the same uid), defines the revision sequence number', }, { displayName: 'Status', name: 'status', type: 'options', options: [ { name: 'Confirmed', value: 'CONFIRMED', }, { name: 'Cancelled', value: 'CANCELLED', }, { name: 'Tentative', value: 'TENTATIVE', }, ], default: 'CONFIRMED', }, { displayName: 'UID', name: 'uid', type: 'string', default: '', description: 'Universally unique ID for the event (will be auto-generated if not specified here). Should be globally unique.', }, { displayName: 'URL', name: 'url', type: 'string', default: '', description: 'URL associated with event', }, { displayName: 'Use Workflow Timezone', name: 'useWorkflowTimezone', type: 'boolean', default: false, description: "Whether to use the workflow timezone set in node's settings rather than UTC", }, ], }, ]; async function execute(items) { const returnData = []; const workflowTimezone = this.getTimezone(); for (let i = 0; i < items.length; i++) { try { const title = this.getNodeParameter('title', i); const allDay = this.getNodeParameter('allDay', i); let start = this.getNodeParameter('start', i); let end = this.getNodeParameter('end', i); if (!end) { end = start; } end = allDay ? (0, moment_timezone_1.default)(end).utc().add(1, 'day').format() : end; const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i); const options = this.getNodeParameter('additionalFields', i); if (options.useWorkflowTimezone) { start = (0, moment_timezone_1.default)(start).tz(workflowTimezone).format(); end = (0, moment_timezone_1.default)(end).tz(workflowTimezone).format(); delete options.useWorkflowTimezone; } let fileName = 'event.ics'; const eventStart = (0, moment_timezone_1.default)(start) .toArray() .splice(0, allDay ? 3 : 6); eventStart[1]++; const eventEnd = (0, moment_timezone_1.default)(end) .toArray() .splice(0, allDay ? 3 : 6); eventEnd[1]++; if (options.fileName) { fileName = options.fileName; } const data = { title, start: eventStart, end: eventEnd, startInputType: 'utc', endInputType: 'utc', }; if (options.geolocationUi) { data.geo = options.geolocationUi.geolocationValues; delete options.geolocationUi; } if (options.organizerUi) { data.organizer = options.organizerUi.organizerValues; delete options.organizerUi; } if (options.attendeesUi) { data.attendees = options.attendeesUi.attendeeValues; delete options.attendeesUi; } Object.assign(data, options); const buffer = Buffer.from((await createEvent(data))); const binaryData = await this.helpers.prepareBinaryData(buffer, fileName, 'text/calendar'); returnData.push({ json: {}, binary: { [binaryPropertyName]: binaryData, }, pairedItem: { item: i, }, }); } catch (error) { const errorDescription = error.description; if (this.continueOnFail()) { returnData.push({ json: { error: error.message, }, pairedItem: { item: i, }, }); continue; } throw new n8n_workflow_1.NodeOperationError(this.getNode(), error, { itemIndex: i, description: errorDescription, }); } } return returnData; } //# sourceMappingURL=createEvent.operation.js.map