caldav-adapter 6.0.1 → 6.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "caldav-adapter",
3
3
  "description": "CalDAV server for Node.js and Koa. Modernized and maintained for Forward Email.",
4
- "version": "6.0.1",
4
+ "version": "6.1.0",
5
5
  "author": "Sanders DeNardi and Forward Email LLC",
6
6
  "contributors": [
7
7
  "Sanders DeNardi <sedenardi@gmail.com> (http://www.sandersdenardi.com/)",
@@ -10,7 +10,6 @@
10
10
  "dependencies": {
11
11
  "@xmldom/xmldom": "^0.8.10",
12
12
  "basic-auth": "^2.0.1",
13
- "ical.js": "^1.5.0",
14
13
  "lodash": "^4.17.21",
15
14
  "moment": "^2.30.1",
16
15
  "path-to-regexp": "^6.2.1",
@@ -5,6 +5,17 @@ module.exports = function (options) {
5
5
  const log = winston({ ...options, label: 'calendar/get' });
6
6
 
7
7
  const exec = async function (ctx, calendar) {
8
+ if (!ctx.state.params.eventId) {
9
+ const events = await options.data.getEventsForCalendar(ctx, {
10
+ principalId: ctx.state.params.principalId,
11
+ calendarId: options.data.getCalendarId(ctx, calendar),
12
+ user: ctx.state.user,
13
+ fullData: true
14
+ });
15
+
16
+ return options.data.buildICS(ctx, events, calendar);
17
+ }
18
+
8
19
  const event = await options.data.getEvent(ctx, {
9
20
  eventId: ctx.state.params.eventId,
10
21
  principalId: ctx.state.params.principalId,
@@ -1,4 +1,3 @@
1
- const ICAL = require('ical.js');
2
1
  const { notFound, preconditionFail } = require('../../../common/x-build');
3
2
  const { setMissingMethod } = require('../../../common/response');
4
3
  const winston = require('../../../common/winston');
@@ -17,34 +16,24 @@ module.exports = function (options) {
17
16
  ctx.request.type !== 'text/calendar' ||
18
17
  typeof ctx.request.body !== 'string'
19
18
  ) {
20
- log.warn('incoming VEVENT not present');
19
+ log.warn('incoming ICS file not present in body');
21
20
  ctx.body = notFound(ctx.url); // Make more meaningful
22
21
  return;
23
22
  }
24
23
 
24
+ //
25
+ // NOTE: if there is no `eventId` then it is updating the entire VCALENDAR
26
+ //
25
27
  if (!ctx.state.params.eventId) {
26
- try {
27
- const parsed = ICAL.parse(ctx.request.body);
28
- if (!parsed || parsed.length === 0) {
29
- const err = new TypeError('ICAL.parse was not successful');
30
- err.parsed = parsed;
31
- throw err;
32
- }
33
-
34
- const comp = new ICAL.Component(parsed);
35
- if (!comp) throw new TypeError('ICAL.Component was not successful');
36
- const vevent = comp.getFirstSubcomponent('vevent');
37
- if (!vevent)
38
- throw new TypeError('comp.getFirstSubcomponent was not successful');
39
- const uid = vevent.getFirstPropertyValue('uid');
40
- if (!uid || typeof uid !== 'string')
41
- throw new TypeError('VEVENT missing UID');
42
- ctx.state.params.eventId = uid;
43
- } catch (err) {
44
- log.warn(err);
45
- ctx.body = notFound(ctx.url); // Make more meaningful
46
- return;
47
- }
28
+ const updatedCalendar = await options.data.updateCalendar(ctx, {
29
+ principalId: ctx.state.params.principalId,
30
+ calendarId: ctx.state.params.calendarId,
31
+ user: ctx.state.user
32
+ });
33
+ /* https://tools.ietf.org/html/rfc4791#section-5.3.2 */
34
+ ctx.status = 201;
35
+ ctx.set('ETag', options.data.getETag(ctx, updatedCalendar));
36
+ return;
48
37
  }
49
38
 
50
39
  const existing = await options.data.getEvent(ctx, {