caldav-adapter 8.0.0 → 8.0.2
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/parse-body.js
CHANGED
|
@@ -9,7 +9,7 @@ module.exports = async function (ctx) {
|
|
|
9
9
|
});
|
|
10
10
|
} catch (err) {
|
|
11
11
|
// <https://github.com/stream-utils/raw-body/blob/f62e660e7c50891844f5615de075ab145c1f6129/README.md?plain=1#L82-L116>
|
|
12
|
-
if (ctx?.app?.emit) ctx.app.emit('error', err);
|
|
12
|
+
if (ctx?.app?.emit) ctx.app.emit('error', err, ctx);
|
|
13
13
|
else throw err;
|
|
14
14
|
}
|
|
15
15
|
|
|
@@ -17,7 +17,7 @@ module.exports = async function (ctx) {
|
|
|
17
17
|
try {
|
|
18
18
|
ctx.request.xml = new DOMParser().parseFromString(ctx.request.body);
|
|
19
19
|
} catch (err) {
|
|
20
|
-
if (ctx?.app?.emit) ctx.app.emit('error', err);
|
|
20
|
+
if (ctx?.app?.emit) ctx.app.emit('error', err, ctx);
|
|
21
21
|
else throw err;
|
|
22
22
|
}
|
|
23
23
|
}
|
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.0.
|
|
4
|
+
"version": "8.0.2",
|
|
5
5
|
"author": "Sanders DeNardi and Forward Email LLC",
|
|
6
6
|
"contributors": [
|
|
7
7
|
"Sanders DeNardi <sedenardi@gmail.com> (http://www.sandersdenardi.com/)",
|
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
const _ = require('lodash');
|
|
2
2
|
const xml = require('../../../common/xml');
|
|
3
3
|
const { build, multistatus } = require('../../../common/x-build');
|
|
4
|
+
const { setMissingMethod } = require('../../../common/response');
|
|
4
5
|
const commonTags = require('../../../common/tags');
|
|
5
6
|
|
|
6
7
|
module.exports = function (options) {
|
|
7
8
|
const tags = commonTags(options);
|
|
8
9
|
|
|
9
10
|
const exec = async function (ctx, calendar) {
|
|
11
|
+
if (calendar.readonly) {
|
|
12
|
+
setMissingMethod(ctx);
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
10
16
|
const { children } = xml.getWithChildren(
|
|
11
17
|
'/D:propertyupdate/D:set/D:prop',
|
|
12
18
|
ctx.request.xml
|
|
@@ -18,6 +18,10 @@ module.exports = function (options) {
|
|
|
18
18
|
typeof ctx.request.body !== 'string'
|
|
19
19
|
) {
|
|
20
20
|
log.warn('incoming ICS file not present in body');
|
|
21
|
+
// TODO: we may want to rewrite all this
|
|
22
|
+
// so that set `setMultistatusResponse` for example only where appropriate
|
|
23
|
+
// (otherwise it's going to have DAV and XML headers when it doesn't need to)
|
|
24
|
+
setMissingMethod(ctx);
|
|
21
25
|
ctx.body = notFound(ctx.url); // Make more meaningful
|
|
22
26
|
return;
|
|
23
27
|
}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
const { notFound } = require('../../common/x-build');
|
|
2
|
-
const {
|
|
2
|
+
const {
|
|
3
|
+
setMissingMethod,
|
|
4
|
+
setMultistatusResponse,
|
|
5
|
+
setOptions
|
|
6
|
+
} = require('../../common/response');
|
|
3
7
|
const winston = require('../../common/winston');
|
|
4
8
|
const routeMkCalendar = require('../principal/mkcalendar');
|
|
5
9
|
const routerUserPropfind = require('./user/propfind');
|
|
@@ -21,7 +25,7 @@ module.exports = function (options) {
|
|
|
21
25
|
propfind: routerCalPropfind(options),
|
|
22
26
|
report: routerCalReport(options),
|
|
23
27
|
get: routerCalGet(options),
|
|
24
|
-
// proppatch: routerCalProppatch(
|
|
28
|
+
// proppatch: routerCalProppatch(options),
|
|
25
29
|
put: routerCalPut(options),
|
|
26
30
|
delete: routerCalDelete(options),
|
|
27
31
|
mkcalendar: routeMkCalendar(options)
|
|
@@ -30,7 +34,6 @@ module.exports = function (options) {
|
|
|
30
34
|
return async function (ctx) {
|
|
31
35
|
const method = ctx.method.toLowerCase();
|
|
32
36
|
const { calendarId } = ctx.state.params;
|
|
33
|
-
setMultistatusResponse(ctx);
|
|
34
37
|
|
|
35
38
|
if (calendarId) {
|
|
36
39
|
// Check calendar exists & user has access
|
|
@@ -50,12 +53,14 @@ module.exports = function (options) {
|
|
|
50
53
|
|
|
51
54
|
if (!calendar && method !== 'mkcalendar') {
|
|
52
55
|
log.warn(`calendar not found: ${calendarId}`);
|
|
56
|
+
setMissingMethod(ctx);
|
|
53
57
|
ctx.body = notFound(ctx.url);
|
|
54
58
|
return;
|
|
55
59
|
}
|
|
56
60
|
|
|
57
61
|
if (!calMethods[method]) {
|
|
58
62
|
log.warn(`method handler not found: ${method}`);
|
|
63
|
+
setMissingMethod(ctx);
|
|
59
64
|
ctx.body = notFound(ctx.url);
|
|
60
65
|
return;
|
|
61
66
|
}
|
|
@@ -66,6 +71,7 @@ module.exports = function (options) {
|
|
|
66
71
|
ctx.body = await calMethods[method](ctx, calendar);
|
|
67
72
|
} else {
|
|
68
73
|
log.warn(`method handler not found: ${method}`);
|
|
74
|
+
setMissingMethod(ctx);
|
|
69
75
|
ctx.body = notFound(ctx.url);
|
|
70
76
|
}
|
|
71
77
|
} else {
|
|
@@ -76,16 +82,20 @@ module.exports = function (options) {
|
|
|
76
82
|
|
|
77
83
|
if (!userMethods[method]) {
|
|
78
84
|
log.warn(`method handler not found: ${method}`);
|
|
85
|
+
setMissingMethod(ctx);
|
|
79
86
|
ctx.body = notFound(ctx.url);
|
|
80
87
|
return;
|
|
81
88
|
}
|
|
82
89
|
|
|
83
90
|
if (typeof userMethods[method].exec === 'function') {
|
|
91
|
+
setMultistatusResponse(ctx);
|
|
84
92
|
ctx.body = await userMethods[method].exec(ctx);
|
|
85
93
|
} else if (typeof userMethods[method] === 'function') {
|
|
94
|
+
setMultistatusResponse(ctx);
|
|
86
95
|
ctx.body = await userMethods[method](ctx);
|
|
87
96
|
} else {
|
|
88
97
|
log.warn(`method handler not found: ${method}`);
|
|
98
|
+
setMissingMethod(ctx);
|
|
89
99
|
ctx.body = notFound(ctx.url);
|
|
90
100
|
}
|
|
91
101
|
}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
const { notFound } = require('../../common/x-build');
|
|
2
|
-
const {
|
|
2
|
+
const {
|
|
3
|
+
setMissingMethod,
|
|
4
|
+
setMultistatusResponse,
|
|
5
|
+
setOptions
|
|
6
|
+
} = require('../../common/response');
|
|
3
7
|
const winston = require('../../common/winston');
|
|
4
8
|
const routePropfind = require('./propfind');
|
|
5
9
|
const routeMkCalendar = require('./mkcalendar');
|
|
@@ -10,12 +14,16 @@ module.exports = function (options) {
|
|
|
10
14
|
const methods = {
|
|
11
15
|
propfind: routePropfind(options),
|
|
12
16
|
// report: reportReport(opts)
|
|
17
|
+
//
|
|
18
|
+
// TODO: proppatch
|
|
19
|
+
// NOTE: fennel implements this with 403 forbidden
|
|
20
|
+
// <https://github.com/LordEidi/fennel.js/blob/abfc371701fcb2581d8f1382426f0ef9e9846554/handler/principal.js#L317-L340>
|
|
21
|
+
//
|
|
13
22
|
mkcalendar: routeMkCalendar(options)
|
|
14
23
|
};
|
|
15
24
|
|
|
16
25
|
return async function (ctx) {
|
|
17
26
|
const method = ctx.method.toLowerCase();
|
|
18
|
-
setMultistatusResponse(ctx);
|
|
19
27
|
|
|
20
28
|
if (method === 'options') {
|
|
21
29
|
setOptions(ctx, ['OPTIONS', 'PROPFIND']);
|
|
@@ -24,10 +32,12 @@ module.exports = function (options) {
|
|
|
24
32
|
|
|
25
33
|
if (!methods[method]) {
|
|
26
34
|
log.warn(`method handler not found: ${method}`);
|
|
35
|
+
setMissingMethod(ctx);
|
|
27
36
|
ctx.body = notFound(ctx.url);
|
|
28
37
|
return;
|
|
29
38
|
}
|
|
30
39
|
|
|
40
|
+
setMultistatusResponse(ctx);
|
|
31
41
|
ctx.body = await methods[method](ctx);
|
|
32
42
|
};
|
|
33
43
|
};
|