From b9e8c276f0d719231dc74cca1690bf2736de96fb Mon Sep 17 00:00:00 2001 From: Jordan Curtis Date: Fri, 15 Apr 2022 15:06:44 -0700 Subject: [PATCH 1/3] add support for outlook busy status --- lib/builder.js | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/lib/builder.js b/lib/builder.js index 0dee247..2212a42 100644 --- a/lib/builder.js +++ b/lib/builder.js @@ -20,6 +20,7 @@ function ICSFileBuilder() { this.NEWLINE_CHAR = '\r\n'; this.throwError = false; this.ignoreTZIDMismatch = true; + this.busystatus = 'FREE'; } @@ -53,7 +54,7 @@ ICSFileBuilder.prototype.toString = function () { else return c; } } - if (this.spacers)lines.push(''); + if (this.spacers) lines.push(''); lines.push('BEGIN:VTIMEZONE'); for (var key in tzData.VTIMEZONE) { if (tzData.VTIMEZONE.hasOwnProperty(key)) { @@ -62,7 +63,7 @@ ICSFileBuilder.prototype.toString = function () { } else { var ref = tzData.VTIMEZONE[key]; if (ref instanceof Array) ref = ref[0]; - if (this.spacers)lines.push(''); + if (this.spacers) lines.push(''); lines.push('BEGIN:' + key); for (var prop in ref) { if (ref.hasOwnProperty(prop)) { @@ -75,12 +76,12 @@ ICSFileBuilder.prototype.toString = function () { } } lines.push('END:' + key); - if (this.spacers)lines.push(''); + if (this.spacers) lines.push(''); } } } lines.push('END:VTIMEZONE'); - if (this.spacers)lines.push(''); + if (this.spacers) lines.push(''); } for (var idx = 0; idx < this.events.length; idx++) { @@ -89,7 +90,7 @@ ICSFileBuilder.prototype.toString = function () { if (this.throwError) throw _event; else return _event; } - if (this.spacers)lines.push(''); + if (this.spacers) lines.push(''); lines.push('BEGIN:VEVENT'); lines.push('UID:' + _event.uid); lines.push('DTSTAMP:' + _formatDate(_event.stamp)); @@ -107,6 +108,7 @@ ICSFileBuilder.prototype.toString = function () { if (_event.description) lines.push('DESCRIPTION:' + _escape(_event.description)); if (_event.url) lines.push('URL;VALUE=URI:' + _event.url); if (_event.status) lines.push('STATUS:' + _event.status.toUpperCase()); + if (_event.busystatus) lines.push('X-MICROSOFT-CDO-BUSYSTATUS:' + _event.busystatus.toUpperCase()) if (_event.organizer) lines.push('ORGANIZER;' + (!!_event.organizer.sentBy ? ('SENT-BY="MAILTO:' + _event.organizer.sentBy + '":') : '') + 'CN="' + _event.organizer.name.replace(/"/g, '\\"') + '":mailto:' + _event.organizer.email); for (var ac = 0; ac < _event.attendees.length; ac++) { if (_event.attendees[ac] instanceof Error) { @@ -117,12 +119,12 @@ ICSFileBuilder.prototype.toString = function () { } } for (var i = 0; i < _event.alarms.length; i++) { - if (this.spacers)lines.push(''); + if (this.spacers) lines.push(''); lines.push('BEGIN:VALARM'); lines.push('TRIGGER:-PT' + _event.alarms[i] + 'M'); lines.push('ACTION:DISPLAY'); lines.push('END:VALARM'); - if (this.spacers)lines.push(''); + if (this.spacers) lines.push(''); } if (_event.repeating) { var rrlue = 'RRULE:FREQ=' + _event.repeating.freq; @@ -146,7 +148,7 @@ ICSFileBuilder.prototype.toString = function () { } } lines.push('END:VEVENT'); - if (this.spacers)lines.push(''); + if (this.spacers) lines.push(''); } if (this.additionalTags) { for (additionalProp in this.additionalTags) { @@ -184,6 +186,13 @@ ICSFileBuilder.prototype._checkAndBuildEventObject = function (rawEvent) { 'CONFIRMED', 'TENTATIVE', 'CANCELLED' + ], + allowedBusyStatuses = [ + "FREE", + "WORKINGELSEWHERE", + "TENTATIVE", + "BUSY", + "OOF" ]; if (!rawEvent || typeof rawEvent !== 'object') { @@ -291,7 +300,7 @@ ICSFileBuilder.prototype._checkAndBuildEventObject = function (rawEvent) { rsvp: !!att.rsvp }); } else { - event.attendees.push(new Error('Invalid attendee data, name and email is required: ' + JSON.stringify({input: att}))); + event.attendees.push(new Error('Invalid attendee data, name and email is required: ' + JSON.stringify({ input: att }))); } }); @@ -325,6 +334,12 @@ ICSFileBuilder.prototype._checkAndBuildEventObject = function (rawEvent) { } event.status = rawEvent.status; + // Busy Status + if (rawEvent.busystatus && allowedBusyStatuses.indexOf(rawEvent.busystatus.toUpperCase()) === -1) { + return new Error('event.busystatus must be one of the following: ' + busystatus.join(', ')); + } + event.busystatus = rawEvent.busystatus; + // URL event.url = rawEvent.url || null; @@ -335,8 +350,8 @@ ICSFileBuilder.prototype._checkAndBuildEventObject = function (rawEvent) { }; /** - * Export builder - * */ +* Export builder +* */ exports.createIcsFileBuilder = function () { return new ICSFileBuilder(); }; From e9e8664d2fd529b15c07436697e0721b8080faa8 Mon Sep 17 00:00:00 2001 From: Jordan Curtis Date: Fri, 15 Apr 2022 15:13:54 -0700 Subject: [PATCH 2/3] update line spacing --- lib/builder.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/builder.js b/lib/builder.js index 2212a42..97f1f81 100644 --- a/lib/builder.js +++ b/lib/builder.js @@ -54,7 +54,7 @@ ICSFileBuilder.prototype.toString = function () { else return c; } } - if (this.spacers) lines.push(''); + if (this.spacers)lines.push(''); lines.push('BEGIN:VTIMEZONE'); for (var key in tzData.VTIMEZONE) { if (tzData.VTIMEZONE.hasOwnProperty(key)) { @@ -63,7 +63,7 @@ ICSFileBuilder.prototype.toString = function () { } else { var ref = tzData.VTIMEZONE[key]; if (ref instanceof Array) ref = ref[0]; - if (this.spacers) lines.push(''); + if (this.spacers)lines.push(''); lines.push('BEGIN:' + key); for (var prop in ref) { if (ref.hasOwnProperty(prop)) { @@ -76,12 +76,12 @@ ICSFileBuilder.prototype.toString = function () { } } lines.push('END:' + key); - if (this.spacers) lines.push(''); + if (this.spacers)lines.push(''); } } } lines.push('END:VTIMEZONE'); - if (this.spacers) lines.push(''); + if (this.spacers)lines.push(''); } for (var idx = 0; idx < this.events.length; idx++) { @@ -90,7 +90,7 @@ ICSFileBuilder.prototype.toString = function () { if (this.throwError) throw _event; else return _event; } - if (this.spacers) lines.push(''); + if (this.spacers)lines.push(''); lines.push('BEGIN:VEVENT'); lines.push('UID:' + _event.uid); lines.push('DTSTAMP:' + _formatDate(_event.stamp)); @@ -119,12 +119,12 @@ ICSFileBuilder.prototype.toString = function () { } } for (var i = 0; i < _event.alarms.length; i++) { - if (this.spacers) lines.push(''); + if (this.spacers)lines.push(''); lines.push('BEGIN:VALARM'); lines.push('TRIGGER:-PT' + _event.alarms[i] + 'M'); lines.push('ACTION:DISPLAY'); lines.push('END:VALARM'); - if (this.spacers) lines.push(''); + if (this.spacers)lines.push(''); } if (_event.repeating) { var rrlue = 'RRULE:FREQ=' + _event.repeating.freq; @@ -148,7 +148,7 @@ ICSFileBuilder.prototype.toString = function () { } } lines.push('END:VEVENT'); - if (this.spacers) lines.push(''); + if (this.spacers)lines.push(''); } if (this.additionalTags) { for (additionalProp in this.additionalTags) { @@ -350,8 +350,8 @@ ICSFileBuilder.prototype._checkAndBuildEventObject = function (rawEvent) { }; /** -* Export builder -* */ + * Export builder + * */ exports.createIcsFileBuilder = function () { return new ICSFileBuilder(); }; From 7394fc396495bd397c7bdd62f5d009b689744170 Mon Sep 17 00:00:00 2001 From: Jordan Curtis Date: Fri, 15 Apr 2022 15:16:03 -0700 Subject: [PATCH 3/3] update line spacing --- lib/builder.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/builder.js b/lib/builder.js index 97f1f81..f062dbb 100644 --- a/lib/builder.js +++ b/lib/builder.js @@ -300,7 +300,7 @@ ICSFileBuilder.prototype._checkAndBuildEventObject = function (rawEvent) { rsvp: !!att.rsvp }); } else { - event.attendees.push(new Error('Invalid attendee data, name and email is required: ' + JSON.stringify({ input: att }))); + event.attendees.push(new Error('Invalid attendee data, name and email is required: ' + JSON.stringify({input: att}))); } }); @@ -336,7 +336,7 @@ ICSFileBuilder.prototype._checkAndBuildEventObject = function (rawEvent) { // Busy Status if (rawEvent.busystatus && allowedBusyStatuses.indexOf(rawEvent.busystatus.toUpperCase()) === -1) { - return new Error('event.busystatus must be one of the following: ' + busystatus.join(', ')); + return new Error('event.busystatus must be one of the following: ' + allowedBusyStatuses.join(', ')); } event.busystatus = rawEvent.busystatus;