Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@coozzy/cal-dav

Package Overview
Dependencies
Maintainers
2
Versions
87
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@coozzy/cal-dav - npm Package Compare versions

Comparing version 2.2.3 to 2.3.0

12

dist/index.d.ts

@@ -11,4 +11,5 @@ import * as ICAL from 'ical.js';

createEvent(eventUrl: string, id: string, title: string, description: string, location: string, startDate: ICAL.TimeJsonData, endDate: ICAL.TimeJsonData, attendees: Attendee[], categories: string[], organizerEmail: string, prodid: string, privateEvent: boolean): Promise<void>;
updateEvent(eventUrl: string, event: ICAL.Event, title: string, description: string, location: string, startDate: ICAL.TimeJsonData, endDate: ICAL.TimeJsonData, attendees: Attendee[], categories: string[], organizerEmail: string, prodid: string, privateEvent: boolean): Promise<void>;
listEventsInTimeRange(startDate: Date, endDate?: Date): Promise<ICAL.Event[]>;
updateEvent(eventUrl: string, event: ICAL.Event, title: string, description: string, location: string, startDate: ICAL.TimeJsonData, endDate: ICAL.TimeJsonData, attendees: Attendee[], categories: string[], organizerEmail: string, prodid: string, privateEvent: boolean, exceptionEventId?: number): Promise<void>;
deleteOccurrenceEvent(eventUrl: string, event: ICAL.Event, exceptionEventId: number, prodid: string): Promise<void>;
listEventsInTimeRange(startDate: Date, endDate?: Date): Promise<ICAL.EventWithExceptions[]>;
multiGetEvents(eventUrls: string[]): Promise<ICAL.Event[]>;

@@ -25,6 +26,8 @@ createEventWithString(event: string, eventUid: string): Promise<void>;

listAllEvents: () => Promise<ICAL.Event[]>;
listEventsInTimeRange: (startDate: Date, endDate?: Date) => Promise<ICAL.Event[]>;
listEventsInTimeRange: (startDate: Date, endDate?: Date) => Promise<ICAL.EventWithExceptions[]>;
multiGetEvents: (eventUrls: string[]) => Promise<ICAL.Event[]>;
createEvent: (eventUrl: string, id: string, title: string, description: string, location: string, startDate: ICAL.TimeJsonData, endDate: ICAL.TimeJsonData, attendees: Attendee[], categories: string[], organizerEmail: string, prodid: string, privateEvent: boolean) => Promise<void>;
updateEvent: (eventUrl: string, event: ICAL.Event, title: string, description: string, location: string, startDate: ICAL.TimeJsonData, endDate: ICAL.TimeJsonData, attendees: Attendee[], categories: string[], organizerEmail: string, prodid: string, privateEvent: boolean) => Promise<void>;
updateEvent: (eventUrl: string, event: ICAL.Event, title: string, description: string, location: string, startDate: ICAL.TimeJsonData, endDate: ICAL.TimeJsonData, attendees: Attendee[], categories: string[], organizerEmail: string, prodid: string, privateEvent: boolean, exceptionEventId?: number) => Promise<void>;
updateEventProperties: (eventUrl: string, event: ICAL.Event, title: string, description: string, location: string, startDate: ICAL.TimeJsonData, endDate: ICAL.TimeJsonData, attendees: Attendee[], categories: string[], organizerEmail: string, prodid: string, privateEvent: boolean) => string;
deleteOccurrenceEvent: (eventUrl: string, event: ICAL.Event, exceptionEventId: number, prodid: string) => Promise<void>;
createEventWithString: (event: string, eventUid: string) => Promise<void>;

@@ -36,2 +39,3 @@ static parseEvent: (eventData: string) => ICAL.Event;

private addAttendees;
private eventIncludedInDates;
}

@@ -24,4 +24,7 @@ "use strict";

const comp = new ICAL.Component(calData);
const vevent = comp.getFirstSubcomponent('vevent');
const event = new ICAL.Event(vevent);
const vevents = comp.getAllSubcomponents('vevent');
const event = new ICAL.Event(vevents[0], {
strictExceptions: true,
exceptions: vevents.slice(1)
});
event.component.addPropertyWithValue('url', eventUrl);

@@ -79,3 +82,3 @@ _logger.default.info(`CalDavClient.GetEvent: Successfully got event ${event.uid}. `);

if (response.status === 207) {
return this.parseListOfEvents(response.data, 'ListEventsInTimeRange');
return this.parseListOfEvents(response.data, 'ListEventsInTimeRange', startDate, endDate);
}

@@ -139,4 +142,35 @@ return [];

};
this.updateEvent = async (eventUrl, event, title, description, location, startDate, endDate, attendees, categories, organizerEmail, prodid, privateEvent) => {
this.updateEvent = async (eventUrl, event, title, description, location, startDate, endDate, attendees, categories, organizerEmail, prodid, privateEvent, exceptionEventId) => {
try {
let eventString;
let exceptionEventString = '';
if (exceptionEventId) {
eventString = event.toString();
let exceptionEventIdIteration = 1;
let exceptions = {};
if (event.exceptions) {
exceptions = event.exceptions;
}
for (const exception in exceptions) {
exceptionEventString += '\n';
if (exceptionEventIdIteration === exceptionEventId) {
const exceptionEvent = new ICAL.Event(exceptions[exception.toString()].component);
exceptionEventString += this.updateEventProperties(eventUrl, exceptionEvent, title, description, location, startDate, endDate, attendees, categories, organizerEmail, prodid, privateEvent);
} else {
const exceptionEvent = new ICAL.Event(exceptions[exception.toString()].component);
exceptionEventString += exceptionEvent.toString();
}
exceptionEventIdIteration += 1;
}
} else {
eventString = this.updateEventProperties(eventUrl, event, title, description, location, startDate, endDate, attendees, categories, organizerEmail, prodid, privateEvent);
}
eventString += exceptionEventString;
await this.service.createUpdateEvent(`BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:${prodid}\r\n` + eventString + '\r\nEND:VCALENDAR', eventUrl);
} catch (e) {
throw new Error(`CalDavClient.UpdateEvent: ${e.message}. `);
}
};
this.updateEventProperties = (eventUrl, event, title, description, location, startDate, endDate, attendees, categories, organizerEmail, prodid, privateEvent) => {
try {
event.summary = title;

@@ -171,5 +205,31 @@ event.description = description;

eventString = eventString.replace(/ORGANIZER:/gi, 'ORGANIZER;');
return eventString;
} catch (e) {
throw new Error(`CalDavClient.updateEventProperties: ${e.message}. `);
}
};
this.deleteOccurrenceEvent = async (eventUrl, event, exceptionEventId, prodid) => {
try {
let exceptions = {};
if (event.exceptions) {
exceptions = event.exceptions;
}
let exceptionEventString = '';
let exceptionEventIdIteration = 1;
for (const exception in exceptions) {
if (exceptionEventIdIteration === exceptionEventId) {
event.component.addPropertyWithValue('EXDATE', ICAL.Time.fromJSDate(new Date(exception.toString()), true));
} else {
const exceptionEvent = new ICAL.Event(exceptions[exception.toString()].component);
exceptionEventString += '\n';
exceptionEventString += exceptionEvent.toString();
}
exceptionEventIdIteration += 1;
}
let eventString = event.toString();
eventString += exceptionEventString;
console.log('eventString: ' + eventString);
await this.service.createUpdateEvent(`BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:${prodid}\r\n` + eventString + '\r\nEND:VCALENDAR', eventUrl);
} catch (e) {
throw new Error(`CalDavClient.UpdateEvent: ${e.message}. `);
throw new Error(`CalDavClient.DeleteOccurrenceEvent: ${e.message}. `);
}

@@ -184,3 +244,3 @@ };

};
this.parseListOfEvents = async (responseData, method) => {
this.parseListOfEvents = async (responseData, method, startDateFilter, endDateFilter) => {
const eventsData = await this.parser.parseListOfEvents(responseData);

@@ -197,3 +257,48 @@ const events = [];

iCalEvent.component.addPropertyWithValue('url', urlParts[urlParts.length - 1]);
events.push(iCalEvent);
if (!iCalEvent.isRecurring()) {
events.push(iCalEvent);
}
const exDates = iCalEvent.component.getAllProperties('exdate');
const exDatesValues = [];
for (const exDate of exDates) {
exDatesValues.push(new Date(exDate.getFirstValue().toString()).getTime());
}
let exceptions = {};
if (iCalEvent.exceptions) {
exceptions = iCalEvent.exceptions;
}
let exceptionEventId = 1;
const iterator = iCalEvent.iterator();
for (let next = iterator.next(); next; next = iterator.next()) {
if (exDatesValues.find(x => x === new Date(next.toString()).getTime())) {
// occurrence deleted
continue;
}
let isException = false;
for (const exception in exceptions) {
if (new Date(exception.toString()).getTime() === new Date(next.toString()).getTime()) {
isException = true;
const event = new ICAL.Event(exceptions[exception.toString()].component);
event.exceptionEventId = exceptionEventId;
exceptionEventId += 1;
if (this.eventIncludedInDates(event.startDate, event.endDate, startDateFilter, endDateFilter)) {
events.push(event);
}
}
}
if (!isException) {
const diffInMs = new Date(next.toString()).getTime() - new Date(iCalEvent.startDate.toString()).getTime();
const diffInDays = diffInMs / (1000 * 60 * 60 * 24);
const calData = ICAL.parse(eventData.event);
const comp = new ICAL.Component(calData);
const vevent = comp.getFirstSubcomponent('vevent');
const copiediCalEvent = new ICAL.Event(vevent);
copiediCalEvent.component.addPropertyWithValue('url', urlParts[urlParts.length - 1]);
copiediCalEvent.startDate.adjust(diffInDays, 0, 0, 0);
copiediCalEvent.endDate.adjust(diffInDays, 0, 0, 0);
if (this.eventIncludedInDates(copiediCalEvent.startDate, copiediCalEvent.endDate, startDateFilter, endDateFilter)) {
events.push(copiediCalEvent);
}
}
}
}

@@ -235,2 +340,21 @@ }

}
eventIncludedInDates(startDateEvent, endDateEvent, startDateFilter, endDateFilter) {
const startEventTime = new Date(startDateEvent.toString()).getTime();
const endEventTime = new Date(endDateEvent.toString()).getTime();
const startFilterTime = startDateFilter ? startDateFilter.getTime() : null;
const endFilterTime = endDateFilter ? endDateFilter.getTime() : null;
if (!startFilterTime && !endFilterTime) {
return true;
}
if (startFilterTime && !endFilterTime && endEventTime > startFilterTime) {
return true;
}
if (!startFilterTime && endFilterTime && startEventTime < endFilterTime) {
return true;
}
if (startFilterTime && endFilterTime && (startEventTime >= startFilterTime && startEventTime <= endFilterTime || endEventTime >= startFilterTime && endEventTime <= endFilterTime || startEventTime <= startFilterTime && endEventTime >= endFilterTime)) {
return true;
}
return false;
}
}

@@ -237,0 +361,0 @@ exports.DefaultCalDavClient = DefaultCalDavClient;

{
"name": "@coozzy/cal-dav",
"version": "2.2.3",
"version": "2.3.0",
"description": "Simple cal dav client.",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -41,6 +41,12 @@ import * as ICAL from 'ical.js';

prodid: string,
privateEvent: boolean): Promise<void>;
privateEvent: boolean,
exceptionEventId?: number): Promise<void>;
listEventsInTimeRange(startDate: Date, endDate?: Date): Promise<ICAL.Event[]>;
deleteOccurrenceEvent(eventUrl: string,
event: ICAL.Event,
exceptionEventId: number,
prodid: string): Promise<void>;
listEventsInTimeRange(startDate: Date, endDate?: Date): Promise<ICAL.EventWithExceptions[]>;
multiGetEvents(eventUrls: string[]): Promise<ICAL.Event[]>;

@@ -68,5 +74,5 @@

const comp = new ICAL.Component(calData);
const vevent = comp.getFirstSubcomponent('vevent');
const vevents = comp.getAllSubcomponents('vevent');
const event = new ICAL.Event(vevents[0], {strictExceptions: true, exceptions: vevents.slice(1)});
const event = new ICAL.Event(vevent);
event.component.addPropertyWithValue('url', eventUrl);

@@ -127,3 +133,3 @@ logger.info(`CalDavClient.GetEvent: Successfully got event ${event.uid}. `);

listEventsInTimeRange = async(startDate: Date, endDate?: Date): Promise<ICAL.Event[]> => {
listEventsInTimeRange = async(startDate: Date, endDate?: Date): Promise<ICAL.EventWithExceptions[]> => {
try{

@@ -133,3 +139,3 @@ const response = await this.service.listEventsInTimeRange(startDate, endDate);

if(response.status === 207) {
return this.parseListOfEvents(response.data, 'ListEventsInTimeRange');
return this.parseListOfEvents(response.data, 'ListEventsInTimeRange', startDate, endDate);
}

@@ -202,4 +208,37 @@ return [];

updateEvent = async(eventUrl: string, event: ICAL.Event, title: string, description: string, location: string, startDate: ICAL.TimeJsonData, endDate: ICAL.TimeJsonData, attendees: Attendee[], categories: string[], organizerEmail: string, prodid: string, privateEvent: boolean): Promise<void> => {
updateEvent = async(eventUrl: string, event: ICAL.Event, title: string, description: string, location: string, startDate: ICAL.TimeJsonData, endDate: ICAL.TimeJsonData, attendees: Attendee[], categories: string[], organizerEmail: string, prodid: string, privateEvent: boolean, exceptionEventId?: number): Promise<void> => {
try{
let eventString: string;
let exceptionEventString = '';
if (exceptionEventId) {
eventString = event.toString();
let exceptionEventIdIteration = 1;
let exceptions: any = {};
if (event.exceptions) {
exceptions = event.exceptions;
}
for (const exception in exceptions) {
exceptionEventString += '\n';
if (exceptionEventIdIteration === exceptionEventId) {
const exceptionEvent: ICAL.Event = new ICAL.Event(exceptions[exception.toString()].component);
exceptionEventString += this.updateEventProperties(eventUrl, exceptionEvent, title, description, location, startDate, endDate, attendees, categories, organizerEmail, prodid, privateEvent);
} else {
const exceptionEvent: ICAL.Event = new ICAL.Event(exceptions[exception.toString()].component);
exceptionEventString += exceptionEvent.toString();
}
exceptionEventIdIteration += 1;
}
} else {
eventString = this.updateEventProperties(eventUrl, event, title, description, location, startDate, endDate, attendees, categories, organizerEmail, prodid, privateEvent);
}
eventString += exceptionEventString;
await this.service.createUpdateEvent(`BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:${prodid}\r\n` + eventString + '\r\nEND:VCALENDAR', eventUrl);
} catch(e) {
throw new Error(`CalDavClient.UpdateEvent: ${e.message}. `);
}
};
updateEventProperties = (eventUrl: string, event: ICAL.Event, title: string, description: string, location: string, startDate: ICAL.TimeJsonData, endDate: ICAL.TimeJsonData, attendees: Attendee[], categories: string[], organizerEmail: string, prodid: string, privateEvent: boolean): string => {
try{
event.summary = title;

@@ -237,5 +276,33 @@ event.description = description;

return eventString;
} catch(e) {
throw new Error(`CalDavClient.updateEventProperties: ${e.message}. `);
}
};
deleteOccurrenceEvent = async(eventUrl: string, event: ICAL.Event, exceptionEventId: number, prodid: string): Promise<void> => {
try {
let exceptions: any = {};
if (event.exceptions) {
exceptions = event.exceptions;
}
let exceptionEventString = '';
let exceptionEventIdIteration = 1;
for (const exception in exceptions) {
if (exceptionEventIdIteration === exceptionEventId) {
event.component.addPropertyWithValue('EXDATE', ICAL.Time.fromJSDate(new Date(exception.toString()), true));
} else {
const exceptionEvent: ICAL.Event = new ICAL.Event(exceptions[exception.toString()].component);
exceptionEventString += '\n';
exceptionEventString += exceptionEvent.toString();
}
exceptionEventIdIteration += 1;
}
let eventString = event.toString();
eventString += exceptionEventString;
console.log('eventString: ' + eventString);
await this.service.createUpdateEvent(`BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:${prodid}\r\n` + eventString + '\r\nEND:VCALENDAR', eventUrl);
} catch(e) {
throw new Error(`CalDavClient.UpdateEvent: ${e.message}. `);
throw new Error(`CalDavClient.DeleteOccurrenceEvent: ${e.message}. `);
}

@@ -262,5 +329,5 @@ };

private parseListOfEvents = async(responseData: string, method: string): Promise<ICAL.Event[]> => {
private parseListOfEvents = async(responseData: string, method: string, startDateFilter?: Date, endDateFilter?: Date): Promise<ICAL.EventWithExceptions[]> => {
const eventsData = await this.parser.parseListOfEvents(responseData);
const events: ICAL.Event[] = [];
const events: ICAL.EventWithExceptions[] = [];
if(eventsData.length){

@@ -272,6 +339,54 @@ for(const eventData of eventsData){

if (vevent) {
const iCalEvent = new ICAL.Event(vevent);
const iCalEvent: ICAL.Event = new ICAL.Event(vevent);
const urlParts = eventData.url.split('/');
iCalEvent.component.addPropertyWithValue('url', urlParts[urlParts.length - 1]);
events.push(iCalEvent);
if (!iCalEvent.isRecurring()) {
events.push(iCalEvent);
}
const exDates = iCalEvent.component.getAllProperties('exdate');
const exDatesValues: any[] = [];
for (const exDate of exDates) {
exDatesValues.push(new Date(exDate.getFirstValue().toString()).getTime());
}
let exceptions: any = {};
if (iCalEvent.exceptions) {
exceptions = iCalEvent.exceptions;
}
let exceptionEventId = 1;
const iterator = iCalEvent.iterator();
for (let next = iterator.next(); next; next = iterator.next()) {
if (exDatesValues.find(x => x === new Date(next.toString()).getTime())) {
// occurrence deleted
continue;
}
let isException = false;
for (const exception in exceptions) {
if (new Date(exception.toString()).getTime() === new Date(next.toString()).getTime()) {
isException = true;
const event: ICAL.EventWithExceptions = new ICAL.Event(exceptions[exception.toString()].component);
event.exceptionEventId = exceptionEventId;
exceptionEventId += 1;
if (this.eventIncludedInDates(event.startDate, event.endDate, startDateFilter, endDateFilter)) {
events.push(event);
}
}
}
if (!isException) {
const diffInMs = new Date(next.toString()).getTime() - new Date(iCalEvent.startDate.toString()).getTime();
const diffInDays = diffInMs / (1000 * 60 * 60 * 24);
const calData = ICAL.parse(eventData.event);
const comp = new ICAL.Component(calData);
const vevent = comp.getFirstSubcomponent('vevent');
const copiediCalEvent = new ICAL.Event(vevent);
copiediCalEvent.component.addPropertyWithValue('url', urlParts[urlParts.length - 1]);
copiediCalEvent.startDate.adjust(diffInDays, 0, 0, 0);
copiediCalEvent.endDate.adjust(diffInDays, 0, 0, 0);
if (this.eventIncludedInDates(copiediCalEvent.startDate, copiediCalEvent.endDate, startDateFilter, endDateFilter)) {
events.push(copiediCalEvent);
}
}
}
}

@@ -319,2 +434,31 @@ }

}
private eventIncludedInDates(startDateEvent: ICAL.Time, endDateEvent: ICAL.Time, startDateFilter?: Date, endDateFilter?: Date): boolean {
const startEventTime = new Date(startDateEvent.toString()).getTime();
const endEventTime = new Date(endDateEvent.toString()).getTime();
const startFilterTime = startDateFilter ? startDateFilter.getTime() : null;
const endFilterTime = endDateFilter ? endDateFilter.getTime() : null;
if (!startFilterTime && !endFilterTime) {
return true;
}
if (startFilterTime && !endFilterTime && endEventTime > startFilterTime) {
return true;
}
if (!startFilterTime && endFilterTime && startEventTime < endFilterTime) {
return true;
}
if (startFilterTime && endFilterTime &&
((startEventTime >= startFilterTime && startEventTime <= endFilterTime) ||
(endEventTime >= startFilterTime && endEventTime <= endFilterTime) ||
(startEventTime <= startFilterTime && endEventTime >= endFilterTime))
) {
return true;
}
return false;
}
}

@@ -0,1 +1,3 @@

import * as ICAL from 'ical.js';
export type AtendeeStatus = 'ATTENDEE_STATUS_NEEDS_ACTION' |

@@ -2,0 +4,0 @@ 'ATTENDEE_STATUS_ACCEPTED' |

@@ -26,3 +26,4 @@ {

"./node_modules/@types"
]
],
"useUnknownInCatchVariables": false
},

@@ -29,0 +30,0 @@ "include": [

@@ -36,2 +36,6 @@ /* eslint-disable @typescript-eslint/no-explicit-any */

class EventWithExceptions extends Event {
exceptionEventId?: number;
}
export class Event {

@@ -47,6 +51,7 @@ public uid: string;

public sequence: string;
public exceptions: any[];
public component: Component;
public constructor(component?: Component | null, options?: {strictExceptions: boolean; exepctions: Array<Component | Event>});
public constructor(component?: Component | null, options?: {strictExceptions: boolean; exceptions: Array<Component | Event>});

@@ -119,27 +124,27 @@ public isRecurring(): boolean;

export class Duration {
public days: number;
public days: number;
}
export class RecurExpansion {
public complete: boolean;
public complete: boolean;
public next(): Time;
public next(): Time;
}
export class Timezone {
static utcTimezone: Timezone;
static localTimezone: Timezone;
static convertTime(tt: Time, fromZone: Timezone, toZone: Timezone): Time;
static utcTimezone: Timezone;
static localTimezone: Timezone;
static convertTime(tt: Time, fromZone: Timezone, toZone: Timezone): Time;
public tzid: string;
public component: Component;
public tzid: string;
public component: Component;
constructor(data: Component | {
component: string | Component;
tzid?: string;
location?: string;
tznames?: string;
latitude?: number;
longitude?: number;
});
constructor(data: Component | {
component: string | Component;
tzid?: string;
location?: string;
tznames?: string;
latitude?: number;
longitude?: number;
});
}

@@ -167,16 +172,16 @@

export class RecurData {
public freq?: FrequencyValues;
public interval?: number;
public wkst?: WeekDay;
public until?: Time;
public count?: number;
public bysecond?: number[] | number;
public byminute?: number[] | number;
public byhour?: number[] | number;
public byday?: string[] | string;
public bymonthday?: number[] | number;
public byyearday?: number[] | number;
public byweekno?: number[] | number;
public bymonth?: number[] | number;
public bysetpos?: number[] | number;
public freq?: FrequencyValues;
public interval?: number;
public wkst?: WeekDay;
public until?: Time;
public count?: number;
public bysecond?: number[] | number;
public byminute?: number[] | number;
public byhour?: number[] | number;
public byday?: string[] | string;
public bymonthday?: number[] | number;
public byyearday?: number[] | number;
public byweekno?: number[] | number;
public bymonth?: number[] | number;
public bysetpos?: number[] | number;
}

@@ -183,0 +188,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc