caldav-adapter 8.2.10 → 8.3.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/common/tags.js CHANGED
@@ -90,18 +90,18 @@ module.exports = function (options) {
90
90
  },
91
91
  getcontenttype: {
92
92
  doc: 'https://tools.ietf.org/html/rfc2518#section-13.5',
93
- async resp({ resource }) {
93
+ async resp({ resource, event }) {
94
94
  if (resource === 'calendar') {
95
95
  return {
96
- [buildTag(dav, 'getcontenttype')]:
97
- 'text/calendar; charset=utf-8; component=VEVENT'
96
+ [buildTag(dav, 'getcontenttype')]: 'text/calendar; charset=utf-8'
98
97
  };
99
98
  }
100
99
 
101
100
  if (resource === 'event') {
101
+ const componentType = event?.componentType || 'VEVENT';
102
102
  return {
103
103
  [buildTag(dav, 'getcontenttype')]:
104
- 'text/calendar; charset=utf-8; component=VEVENT'
104
+ `text/calendar; charset=utf-8; component=${componentType}`
105
105
  };
106
106
  }
107
107
  }
@@ -360,9 +360,10 @@ module.exports = function (options) {
360
360
  if (resource === 'calendar') {
361
361
  return {
362
362
  [buildTag(cal, 'supported-calendar-component-set')]: {
363
- [buildTag(cal, 'comp')]: {
364
- '@name': 'VEVENT'
365
- }
363
+ [buildTag(cal, 'comp')]: [
364
+ { '@name': 'VEVENT' },
365
+ { '@name': 'VTODO' }
366
+ ]
366
367
  }
367
368
  };
368
369
  }
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": "8.2.10",
4
+ "version": "8.3.0",
5
5
  "author": "Sanders DeNardi and Forward Email LLC",
6
6
  "contributors": [
7
7
  "Sanders DeNardi <sedenardi@gmail.com> (http://www.sandersdenardi.com/)",
@@ -8,10 +8,21 @@ module.exports = function (options) {
8
8
  const eventResponse = calEventResponse(options);
9
9
  return async function (ctx, calendar) {
10
10
  /* https://tools.ietf.org/html/rfc4791#section-9.9 */
11
- const filters = xml.get(
11
+ const veventFilters = xml.get(
12
12
  "/CAL:calendar-query/CAL:filter/CAL:comp-filter[@name='VCALENDAR']/CAL:comp-filter[@name='VEVENT']/CAL:time-range",
13
13
  ctx.request.xml
14
14
  );
15
+ const vtodoFilters = xml.get(
16
+ "/CAL:calendar-query/CAL:filter/CAL:comp-filter[@name='VCALENDAR']/CAL:comp-filter[@name='VTODO']/CAL:time-range",
17
+ ctx.request.xml
18
+ );
19
+
20
+ const filters = veventFilters || vtodoFilters;
21
+ const componentType = veventFilters
22
+ ? 'VEVENT'
23
+ : vtodoFilters
24
+ ? 'VTODO'
25
+ : null;
15
26
  const { children } = xml.getWithChildren(
16
27
  '/CAL:calendar-query/D:prop',
17
28
  ctx.request.xml
@@ -25,7 +36,8 @@ module.exports = function (options) {
25
36
  principalId: ctx.state.params.principalId,
26
37
  calendarId: options.data.getCalendarId(ctx, calendar),
27
38
  user: ctx.state.user,
28
- fullData
39
+ fullData,
40
+ componentType
29
41
  });
30
42
 
31
43
  return eventResponse(ctx, events, calendar, children);
@@ -73,7 +85,8 @@ module.exports = function (options) {
73
85
  start,
74
86
  end,
75
87
  user: ctx.state.user,
76
- fullData
88
+ fullData,
89
+ componentType
77
90
  });
78
91
  return eventResponse(ctx, events, calendar, children);
79
92
  };
@@ -0,0 +1,27 @@
1
+ const {
2
+ build,
3
+ multistatus,
4
+ response,
5
+ status,
6
+ href,
7
+ buildTag
8
+ } = require('../../common/x-build');
9
+
10
+ module.exports = function (_options) {
11
+ return async function (ctx) {
12
+ // GET requests to principals should return the current user principal
13
+ // This is what CalDAV clients expect when they follow redirects from root URL
14
+
15
+ const principalInfo = [
16
+ {
17
+ [buildTag('DAV:', 'current-user-principal')]: href(
18
+ ctx.state.principalUrl
19
+ )
20
+ }
21
+ ];
22
+
23
+ const resps = response(ctx.url, status[200], principalInfo);
24
+ const ms = multistatus([resps]);
25
+ return build(ms);
26
+ };
27
+ };
@@ -6,6 +6,7 @@ const {
6
6
  } = require('../../common/response');
7
7
  const winston = require('../../common/winston');
8
8
  const routePropfind = require('./propfind');
9
+ const routeGet = require('./get'); // New GET handler
9
10
  const routeMkCalendar = require('./mkcalendar');
10
11
  // const routeReport = require('./report');
11
12
 
@@ -13,7 +14,7 @@ module.exports = function (options) {
13
14
  const log = winston({ ...options, label: 'principal' });
14
15
  const methods = {
15
16
  propfind: routePropfind(options),
16
- get: routePropfind(options), // Handle GET same as PROPFIND for redirected requests
17
+ get: routeGet(options), // Use proper GET handler instead of reusing PROPFIND
17
18
  // report: reportReport(opts)
18
19
  //
19
20
  // TODO: proppatch
package/test/test.js CHANGED
@@ -6,3 +6,36 @@ const caldavAdapter = require('..');
6
6
  test('exports a function', (t) => {
7
7
  t.true(typeof caldavAdapter === 'function');
8
8
  });
9
+
10
+ test('VTODO supported component set includes VTODO', (t) => {
11
+ const options = {
12
+ data: {
13
+ getCalendarId: () => 'test',
14
+ buildICS: () => 'test',
15
+ getETag: () => 'test'
16
+ }
17
+ };
18
+
19
+ const { tags } = require('../common/tags')(options);
20
+ const supportedComponentSetTag =
21
+ tags['urn:ietf:params:xml:ns:caldav']['supported-calendar-component-set'];
22
+
23
+ t.is(typeof supportedComponentSetTag, 'object');
24
+ t.is(typeof supportedComponentSetTag.resp, 'function');
25
+ });
26
+
27
+ test('VTODO content type is dynamic based on component', (t) => {
28
+ const options = {
29
+ data: {
30
+ getCalendarId: () => 'test',
31
+ buildICS: () => 'test',
32
+ getETag: () => 'test'
33
+ }
34
+ };
35
+
36
+ const { tags } = require('../common/tags')(options);
37
+ const contentTypeTag = tags['DAV:'].getcontenttype;
38
+
39
+ t.is(typeof contentTypeTag, 'object');
40
+ t.is(typeof contentTypeTag.resp, 'function');
41
+ });