caldav-adapter 5.0.0 → 5.0.1

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": "5.0.0",
4
+ "version": "5.0.1",
5
5
  "author": "Sanders DeNardi and Forward Email LLC",
6
6
  "contributors": [
7
7
  "Sanders DeNardi <sedenardi@gmail.com> (http://www.sandersdenardi.com/)",
@@ -0,0 +1,69 @@
1
+ const _ = require('lodash');
2
+ const xml = require('../../common/xml');
3
+
4
+ // TODO: need to implement tests for MKCALENDAR
5
+ // <https://github.com/sabre-io/dav/blob/da8c1f226f1c053849540a189262274ef6809d1c/tests/Sabre/CalDAV/PluginTest.php#L142-L428>
6
+ module.exports = function (options) {
7
+ return async function (ctx) {
8
+ const { children } = xml.getWithChildren(
9
+ '/CAL:mkcalendar/D:set/D:prop',
10
+ ctx.request.xml
11
+ );
12
+
13
+ const calendar = {};
14
+ for (const child of children) {
15
+ if (!child.localName || !child.textContent) continue;
16
+ switch (child.localName) {
17
+ case 'displayname': {
18
+ calendar.name = child.textContent;
19
+
20
+ break;
21
+ }
22
+
23
+ case 'calendar-description': {
24
+ calendar.description = child.textContent;
25
+
26
+ break;
27
+ }
28
+
29
+ case 'calendar-timezone': {
30
+ calendar.timezone = child.textContent;
31
+
32
+ break;
33
+ }
34
+ // No default
35
+ }
36
+ }
37
+
38
+ // TODO: better error handling
39
+ if (_.isEmpty(calendar)) {
40
+ const err = new TypeError('Calendar update was empty');
41
+ err.xml = ctx.request.body;
42
+ throw err;
43
+ }
44
+
45
+ // TODO: we may need to implement this similar workaround
46
+ // <https://github.com/sabre-io/dav/blob/da8c1f226f1c053849540a189262274ef6809d1c/lib/CalDAV/Plugin.php#L294-L304>
47
+
48
+ // > Clients SHOULD NOT set the DAV: displayname property to be the same as any other calendar collection at the same URI "level".
49
+ // > If a request body is included, it MUST be a CALDAV:mkcalendar XML element.
50
+
51
+ // DAV:displayname
52
+ // CALDAV:calendar-description,
53
+ // CALDAV:supported-calendar-component-set
54
+ // CALDAV:calendar-timezone
55
+
56
+ // <c:mkcalendar xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:ca="http://apple.com/ns/ical/">
57
+ // <d:set>
58
+ // <d:prop>
59
+ // <d:displayname>personal calendar</d:displayname>
60
+ // <c:calendar-description>some calendar description</c:calendar-description>
61
+ // </d:prop>
62
+ // </d:set>
63
+ // </c:mkcalendar>
64
+
65
+ const calendarObject = await options.data.createCalendar(calendar);
66
+ ctx.status = 201;
67
+ ctx.set('ETag', options.data.getETag(calendarObject));
68
+ };
69
+ };
@@ -2,13 +2,15 @@ const { notFound } = require('../../common/x-build');
2
2
  const { setMultistatusResponse, setOptions } = require('../../common/response');
3
3
  const winston = require('../../common/winston');
4
4
  const routePropfind = require('./propfind');
5
+ const routeMkCalendar = require('./mkcalendar');
5
6
  // const routeReport = require('./report');
6
7
 
7
8
  module.exports = function (options) {
8
9
  const log = winston({ ...options, label: 'principal' });
9
10
  const methods = {
10
- propfind: routePropfind(options)
11
+ propfind: routePropfind(options),
11
12
  // report: reportReport(opts)
13
+ mkcalendar: routeMkCalendar(options)
12
14
  };
13
15
 
14
16
  return async function (ctx) {