caldav-adapter 4.3.0 → 5.0.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.
Files changed (93) hide show
  1. package/.commitlintrc.js +3 -0
  2. package/.editorconfig +9 -0
  3. package/.gitattributes +1 -0
  4. package/.github/workflows/ci.yml +24 -0
  5. package/.husky/commit-msg +4 -0
  6. package/.husky/pre-commit +4 -0
  7. package/.lintstagedrc.js +5 -0
  8. package/.prettierrc.js +5 -0
  9. package/.remarkignore +1 -0
  10. package/.remarkrc.js +3 -0
  11. package/.xo-config.js +8 -0
  12. package/LICENSE +21 -0
  13. package/README.md +26 -240
  14. package/common/parse-body.js +16 -0
  15. package/common/response.js +51 -0
  16. package/common/tags.js +412 -0
  17. package/common/winston.js +32 -0
  18. package/common/x-build.js +109 -0
  19. package/common/xml.js +36 -0
  20. package/index.js +171 -0
  21. package/package.json +58 -40
  22. package/routes/calendar/calendar/calendar-multiget.js +48 -0
  23. package/routes/calendar/calendar/calendar-query.js +80 -0
  24. package/routes/calendar/calendar/delete.js +40 -0
  25. package/routes/calendar/calendar/event-response.js +37 -0
  26. package/routes/calendar/calendar/expand-property.js +11 -0
  27. package/routes/calendar/calendar/get.js +27 -0
  28. package/routes/calendar/calendar/propfind.js +73 -0
  29. package/routes/calendar/calendar/proppatch.js +32 -0
  30. package/routes/calendar/calendar/put.js +76 -0
  31. package/routes/calendar/calendar/report.js +36 -0
  32. package/routes/calendar/calendar/sync-collection.js +36 -0
  33. package/routes/calendar/calendar.js +80 -0
  34. package/routes/calendar/user/propfind.js +60 -0
  35. package/routes/calendar/user/proppatch.js +31 -0
  36. package/routes/principal/principal.js +31 -0
  37. package/routes/principal/propfind.js +32 -0
  38. package/routes/principal/report.js +27 -0
  39. package/test/test.js +8 -0
  40. package/lib/common/date.d.ts +0 -2
  41. package/lib/common/date.js +0 -11
  42. package/lib/common/eventBuild.d.ts +0 -6
  43. package/lib/common/eventBuild.js +0 -170
  44. package/lib/common/parseBody.d.ts +0 -2
  45. package/lib/common/parseBody.js +0 -21
  46. package/lib/common/response.d.ts +0 -6
  47. package/lib/common/response.js +0 -53
  48. package/lib/common/tags.d.ts +0 -263
  49. package/lib/common/tags.js +0 -337
  50. package/lib/common/winston.d.ts +0 -11
  51. package/lib/common/winston.js +0 -26
  52. package/lib/common/xBuild.d.ts +0 -17
  53. package/lib/common/xBuild.js +0 -80
  54. package/lib/common/xml.d.ts +0 -17
  55. package/lib/common/xml.js +0 -30
  56. package/lib/index.d.ts +0 -143
  57. package/lib/index.js +0 -8
  58. package/lib/koa.d.ts +0 -21
  59. package/lib/koa.js +0 -130
  60. package/lib/routes/calendar/calendar/calendar-multiget.d.ts +0 -7
  61. package/lib/routes/calendar/calendar/calendar-multiget.js +0 -68
  62. package/lib/routes/calendar/calendar/calendar-query.d.ts +0 -7
  63. package/lib/routes/calendar/calendar/calendar-query.js +0 -62
  64. package/lib/routes/calendar/calendar/delete.d.ts +0 -5
  65. package/lib/routes/calendar/calendar/delete.js +0 -40
  66. package/lib/routes/calendar/calendar/eventResponse.d.ts +0 -7
  67. package/lib/routes/calendar/calendar/eventResponse.js +0 -36
  68. package/lib/routes/calendar/calendar/expand-property.d.ts +0 -7
  69. package/lib/routes/calendar/calendar/expand-property.js +0 -15
  70. package/lib/routes/calendar/calendar/get.d.ts +0 -5
  71. package/lib/routes/calendar/calendar/get.js +0 -30
  72. package/lib/routes/calendar/calendar/propfind.d.ts +0 -8
  73. package/lib/routes/calendar/calendar/propfind.js +0 -76
  74. package/lib/routes/calendar/calendar/proppatch.d.ts +0 -5
  75. package/lib/routes/calendar/calendar/proppatch.js +0 -53
  76. package/lib/routes/calendar/calendar/put.d.ts +0 -5
  77. package/lib/routes/calendar/calendar/put.js +0 -68
  78. package/lib/routes/calendar/calendar/report.d.ts +0 -5
  79. package/lib/routes/calendar/calendar/report.js +0 -39
  80. package/lib/routes/calendar/calendar/sync-collection.d.ts +0 -10
  81. package/lib/routes/calendar/calendar/sync-collection.js +0 -57
  82. package/lib/routes/calendar/calendar.d.ts +0 -3
  83. package/lib/routes/calendar/calendar.js +0 -78
  84. package/lib/routes/calendar/user/propfind.d.ts +0 -5
  85. package/lib/routes/calendar/user/propfind.js +0 -64
  86. package/lib/routes/calendar/user/proppatch.d.ts +0 -5
  87. package/lib/routes/calendar/user/proppatch.js +0 -52
  88. package/lib/routes/principal/principal.d.ts +0 -3
  89. package/lib/routes/principal/principal.js +0 -32
  90. package/lib/routes/principal/propfind.d.ts +0 -3
  91. package/lib/routes/principal/propfind.js +0 -50
  92. package/lib/routes/principal/report.d.ts +0 -3
  93. package/lib/routes/principal/report.js +0 -32
@@ -1,26 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const winston_1 = require("winston");
4
- function default_1(opts) {
5
- const logger = (0, winston_1.createLogger)({
6
- level: opts.logLevel || 'debug',
7
- format: winston_1.format.combine(winston_1.format.colorize(), winston_1.format.timestamp({
8
- format: 'YYYY-MM-DD HH:mm:ss:SSS'
9
- }), winston_1.format.label({ label: opts.label }), winston_1.format.align(), winston_1.format.printf(((info) => {
10
- return `${info.timestamp} ${info.level} [${info.label}]: ${info.message}`;
11
- })))
12
- });
13
- if (opts.logEnabled) {
14
- logger.add(new winston_1.transports.Console());
15
- }
16
- else {
17
- logger.silent = true;
18
- }
19
- logger.morganStream = {
20
- write: function (message) {
21
- logger.verbose(message.trim());
22
- },
23
- };
24
- return logger;
25
- }
26
- exports.default = default_1;
@@ -1,17 +0,0 @@
1
- type XmlElement = {
2
- [tag: string]: any;
3
- };
4
- export declare const buildTag: (namespaceURI: string, localName: string) => string;
5
- export declare const href: (url: string) => XmlElement;
6
- export declare const build: (obj: XmlElement) => string;
7
- export declare const multistatus: (responses?: any, other?: object) => XmlElement;
8
- export declare const status: {
9
- readonly 200: "HTTP/1.1 200 OK";
10
- readonly 403: "HTTP/1.1 403 Forbidden";
11
- readonly 404: "HTTP/1.1 404 Not Found";
12
- };
13
- export declare const response: (url: string, status: string, props?: object[]) => XmlElement;
14
- export declare const missingPropstats: (props: any) => any;
15
- export declare const notFound: (href: string) => string;
16
- export declare const preconditionFail: (url: string, reason: string) => string;
17
- export {};
@@ -1,80 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.preconditionFail = exports.notFound = exports.missingPropstats = exports.response = exports.status = exports.multistatus = exports.build = exports.href = exports.buildTag = void 0;
7
- const xmlbuilder2_1 = require("xmlbuilder2");
8
- const xml_1 = require("./xml");
9
- const mapKeys_1 = __importDefault(require("lodash/mapKeys"));
10
- const nsMap = function () {
11
- return (0, mapKeys_1.default)(xml_1.namespaces, (v, k) => {
12
- return `@xmlns:${k}`;
13
- });
14
- };
15
- const buildTag = function (namespaceURI, localName) {
16
- return `${xml_1.nsLookup[namespaceURI]}:${localName}`;
17
- };
18
- exports.buildTag = buildTag;
19
- const href = function (url) {
20
- return { [(0, exports.buildTag)('DAV:', 'href')]: url };
21
- };
22
- exports.href = href;
23
- const build = function (obj) {
24
- const doc = (0, xmlbuilder2_1.create)(obj, { version: '1.0', encoding: 'UTF-8', noDoubleEncoding: true });
25
- return doc.end({ prettyPrint: true });
26
- };
27
- exports.build = build;
28
- const multistatus = function (responses, other) {
29
- const res = {
30
- [(0, exports.buildTag)('DAV:', 'multistatus')]: nsMap()
31
- };
32
- if (responses === null || responses === void 0 ? void 0 : responses.length) {
33
- res[(0, exports.buildTag)('DAV:', 'multistatus')][(0, exports.buildTag)('DAV:', 'response')] = responses;
34
- }
35
- if (other) {
36
- res[(0, exports.buildTag)('DAV:', 'multistatus')] = Object.assign(res[(0, exports.buildTag)('DAV:', 'multistatus')], other);
37
- }
38
- return res;
39
- };
40
- exports.multistatus = multistatus;
41
- exports.status = {
42
- 200: 'HTTP/1.1 200 OK',
43
- 403: 'HTTP/1.1 403 Forbidden',
44
- 404: 'HTTP/1.1 404 Not Found'
45
- };
46
- const response = function (url, status, props) {
47
- const res = (0, exports.href)(url);
48
- res[(0, exports.buildTag)('DAV:', 'propstat')] = [{
49
- [(0, exports.buildTag)('DAV:', 'status')]: status
50
- }];
51
- if (props && props.length) {
52
- res[(0, exports.buildTag)('DAV:', 'propstat')][0][(0, exports.buildTag)('DAV:', 'prop')] = Object.assign({}, ...props);
53
- }
54
- return res;
55
- };
56
- exports.response = response;
57
- const missingPropstats = function (props) {
58
- return props.reduce((res, v) => {
59
- res[(0, exports.buildTag)('DAV:', 'prop')][v] = '';
60
- return res;
61
- }, {
62
- [(0, exports.buildTag)('DAV:', 'status')]: exports.status[404],
63
- [(0, exports.buildTag)('DAV:', 'prop')]: {}
64
- });
65
- };
66
- exports.missingPropstats = missingPropstats;
67
- const notFound = function (href) {
68
- return (0, exports.build)((0, exports.multistatus)([(0, exports.response)(href, exports.status[404])]));
69
- };
70
- exports.notFound = notFound;
71
- /* https://tools.ietf.org/html/rfc4791#section-5.3.2.1 */
72
- const preconditionFail = function (url, reason) {
73
- const res = {
74
- 'D:error': Object.assign({
75
- [(0, exports.buildTag)('urn:ietf:params:xml:ns:caldav', reason)]: url
76
- }, nsMap())
77
- };
78
- return (0, exports.build)(res);
79
- };
80
- exports.preconditionFail = preconditionFail;
@@ -1,17 +0,0 @@
1
- export declare const namespaces: {
2
- readonly D: "DAV:";
3
- readonly CAL: "urn:ietf:params:xml:ns:caldav";
4
- readonly CS: "http://calendarserver.org/ns/";
5
- readonly ICAL: "http://apple.com/ns/ical/";
6
- };
7
- export declare const nsLookup: {
8
- readonly 'DAV:': "D";
9
- readonly 'urn:ietf:params:xml:ns:caldav': "CAL";
10
- readonly 'http://calendarserver.org/ns/': "CS";
11
- readonly 'http://apple.com/ns/ical/': "ICAL";
12
- };
13
- export declare const get: <T extends Node>(path: string, doc: Document) => T[];
14
- export declare const getWithChildren: (path: string, doc: Document) => {
15
- propNode: Element[];
16
- children: Element[];
17
- };
package/lib/common/xml.js DELETED
@@ -1,30 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getWithChildren = exports.get = exports.nsLookup = exports.namespaces = void 0;
7
- const xpath_1 = __importDefault(require("xpath"));
8
- exports.namespaces = {
9
- D: 'DAV:',
10
- CAL: 'urn:ietf:params:xml:ns:caldav',
11
- CS: 'http://calendarserver.org/ns/',
12
- ICAL: 'http://apple.com/ns/ical/'
13
- };
14
- exports.nsLookup = {
15
- 'DAV:': 'D',
16
- 'urn:ietf:params:xml:ns:caldav': 'CAL',
17
- 'http://calendarserver.org/ns/': 'CS',
18
- 'http://apple.com/ns/ical/': 'ICAL'
19
- };
20
- const select = xpath_1.default.useNamespaces(exports.namespaces);
21
- const get = function (path, doc) {
22
- return select(path, doc);
23
- };
24
- exports.get = get;
25
- const getWithChildren = function (path, doc) {
26
- const propNode = (0, exports.get)(path, doc);
27
- const children = propNode[0] ? Array.from(propNode[0].childNodes) : [];
28
- return { propNode, children };
29
- };
30
- exports.getWithChildren = getWithChildren;
package/lib/index.d.ts DELETED
@@ -1,143 +0,0 @@
1
- import { AlarmData } from 'ical-generator';
2
- export type CalDavAuthPrincipal = {
3
- principalId: string;
4
- principalName: string;
5
- };
6
- export type CalDavCalendar = {
7
- calendarId: string;
8
- ownerId?: string;
9
- calendarName: string;
10
- timeZone: string;
11
- order: number;
12
- readOnly: boolean;
13
- color?: string;
14
- syncToken: string;
15
- createdOn?: string;
16
- };
17
- export type CalDavRecurrence = {
18
- recurrenceId: string;
19
- summary?: string;
20
- location?: string;
21
- description: string;
22
- htmlDescription?: string;
23
- url?: string;
24
- categories?: string[];
25
- alarms?: AlarmData[];
26
- startDate: string;
27
- endDate: string;
28
- timeZone: string;
29
- createdOn?: string;
30
- lastModifiedOn?: string;
31
- };
32
- export type CalDavRecurring = {
33
- freq: 'SECONDLY' | 'MINUTELY' | 'DAILY' | 'WEEKLY' | 'MONTHLY' | 'YEARLY' | 'HOURLY';
34
- until?: string;
35
- exdate?: string[];
36
- recurrences?: CalDavRecurrence[];
37
- };
38
- export type CalDavEvent = {
39
- eventId: string;
40
- calendarId?: string;
41
- summary: string;
42
- location?: string;
43
- description: string;
44
- htmlDescription?: string;
45
- url?: string;
46
- categories?: string[];
47
- alarms?: AlarmData[];
48
- startDate: string;
49
- endDate: string;
50
- duration?: string;
51
- timeZone?: string;
52
- createdOn: string;
53
- lastModifiedOn: string;
54
- ical?: string;
55
- recurring?: CalDavRecurring;
56
- };
57
- export type CalDavAuthenticate = (opts: {
58
- username: string;
59
- password: string;
60
- principalId: string;
61
- }) => Promise<CalDavAuthPrincipal>;
62
- export type CalDavGetCalendar = (opts: {
63
- calendarId: string;
64
- principalId: string;
65
- user: any;
66
- }) => Promise<CalDavCalendar>;
67
- export type CalDavGetCalendarsForPrincipal = (opts: {
68
- principalId: string;
69
- user: any;
70
- }) => Promise<CalDavCalendar[]>;
71
- export type CalDavGetEventsForCalendar = (opts: {
72
- calendarId: string;
73
- principalId: string;
74
- fullData: boolean;
75
- user: any;
76
- }) => Promise<CalDavEvent[]>;
77
- export type CalDavGetEventsByDate = (opts: {
78
- calendarId: string;
79
- principalId: string;
80
- start: string;
81
- end: string;
82
- fullData: boolean;
83
- user: any;
84
- }) => Promise<CalDavEvent[]>;
85
- export type CalDavGetEvent = (opts: {
86
- eventId: string;
87
- calendarId: string;
88
- principalId: string;
89
- fullData: boolean;
90
- user: any;
91
- }) => Promise<CalDavEvent>;
92
- export type CalDavCreateEvent = (opts: {
93
- event: CalDavEvent;
94
- calendarId: string;
95
- principalId: string;
96
- user: any;
97
- }) => Promise<CalDavEvent>;
98
- export type CalDavUpdateEvent = (opts: {
99
- event: CalDavEvent;
100
- calendarId: string;
101
- principalId: string;
102
- user: any;
103
- }) => Promise<CalDavEvent>;
104
- export type CalDavDeleteEvent = (opts: {
105
- eventId: string;
106
- calendarId: string;
107
- principalId: string;
108
- user: any;
109
- }) => Promise<void>;
110
- export type CalDavOptionsLogging = {
111
- logEnabled?: boolean;
112
- logLevel?: string;
113
- };
114
- export type CalDavOptionsData = {
115
- data: {
116
- getCalendar: CalDavGetCalendar;
117
- getCalendarsForPrincipal: CalDavGetCalendarsForPrincipal;
118
- getEventsForCalendar: CalDavGetEventsForCalendar;
119
- getEventsByDate: CalDavGetEventsByDate;
120
- getEvent: CalDavGetEvent;
121
- createEvent: CalDavCreateEvent;
122
- updateEvent: CalDavUpdateEvent;
123
- deleteEvent: CalDavDeleteEvent;
124
- };
125
- };
126
- export type CalDavOptionsProId = {
127
- proId: {
128
- company: string;
129
- product: string;
130
- language: string;
131
- };
132
- };
133
- export type CalDavOptionsModule = CalDavOptionsLogging & CalDavOptionsData & CalDavOptionsProId;
134
- export type CalDavOptions = CalDavOptionsModule & {
135
- authenticate: CalDavAuthenticate;
136
- authRealm: string;
137
- caldavRoot?: string;
138
- calendarRoot?: string;
139
- principalRoot?: string;
140
- disableWellKnown?: boolean;
141
- };
142
- import koa from './koa';
143
- export { koa };
package/lib/index.js DELETED
@@ -1,8 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.koa = void 0;
7
- const koa_1 = __importDefault(require("./koa"));
8
- exports.koa = koa_1.default;
package/lib/koa.d.ts DELETED
@@ -1,21 +0,0 @@
1
- import { CalDavOptions, CalDavAuthPrincipal } from '.';
2
- import { Request, ParameterizedContext } from 'koa';
3
- import { FullCalendar } from 'ical';
4
- interface CalendarRequest extends Request {
5
- body?: string;
6
- xml?: Document;
7
- ical?: FullCalendar;
8
- }
9
- export interface CalendarState {
10
- user?: CalDavAuthPrincipal;
11
- params: {
12
- principalId?: string;
13
- [key: string]: any;
14
- };
15
- [key: string]: any;
16
- }
17
- export interface CalendarContext extends ParameterizedContext<CalendarState> {
18
- request: CalendarRequest;
19
- }
20
- export default function (opts: CalDavOptions): (ctx: CalendarContext, next: any) => Promise<void>;
21
- export {};
package/lib/koa.js DELETED
@@ -1,130 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const path_1 = require("path");
7
- const path_to_regexp_1 = require("path-to-regexp");
8
- const basic_auth_1 = __importDefault(require("basic-auth"));
9
- const parseBody_1 = __importDefault(require("./common/parseBody"));
10
- const winston_1 = __importDefault(require("./common/winston"));
11
- const calendar_1 = __importDefault(require("./routes/calendar/calendar"));
12
- const principal_1 = __importDefault(require("./routes/principal/principal"));
13
- const defaults = {
14
- caldavRoot: '/',
15
- calendarRoot: 'cal',
16
- principalRoot: 'p',
17
- logEnabled: false
18
- };
19
- function default_1(opts) {
20
- opts = Object.assign(defaults, opts);
21
- const log = (0, winston_1.default)(Object.assign(Object.assign({}, opts), { label: 'index' }));
22
- const rootRoute = path_1.posix.join('/', opts.caldavRoot);
23
- const calendarRoute = path_1.posix.join(rootRoute, opts.calendarRoot);
24
- const principalRoute = path_1.posix.join(rootRoute, opts.principalRoot, '/');
25
- const rootRegexp = (0, path_to_regexp_1.pathToRegexp)(path_1.posix.join(rootRoute, '/:params*'));
26
- const calendarRegex = { keys: [] };
27
- calendarRegex.regexp = (0, path_to_regexp_1.pathToRegexp)(path_1.posix.join(calendarRoute, '/:principalId/:calendarId?/:eventId*'), calendarRegex.keys);
28
- const principalRegex = { keys: [] };
29
- principalRegex.regexp = (0, path_to_regexp_1.pathToRegexp)(path_1.posix.join(principalRoute, '/:principalId?'), principalRegex.keys);
30
- const calendarRoutes = (0, calendar_1.default)({
31
- logEnabled: opts.logEnabled,
32
- logLevel: opts.logLevel,
33
- proId: opts.proId,
34
- data: opts.data
35
- });
36
- const principalRoutes = (0, principal_1.default)({
37
- logEnabled: opts.logEnabled,
38
- logLevel: opts.logLevel,
39
- proId: opts.proId,
40
- data: opts.data
41
- });
42
- const fillParams = function (ctx) {
43
- ctx.state.params = {};
44
- let regex;
45
- if (calendarRegex.regexp.test(ctx.url)) {
46
- regex = calendarRegex;
47
- }
48
- else if (principalRegex.regexp.test(ctx.url)) {
49
- regex = principalRegex;
50
- }
51
- if (!regex) {
52
- return;
53
- }
54
- const captures = ctx.url.match(regex.regexp);
55
- for (let i = 0; i < regex.keys.length; i++) {
56
- let captured = captures[i + 1];
57
- if (typeof captured === 'string') {
58
- captured = decodeURIComponent(captured);
59
- }
60
- ctx.state.params[regex.keys[i].name] = captured;
61
- if (typeof captured === 'string' && captured.endsWith('.ics')) {
62
- ctx.state.params[regex.keys[i].name] = captured.slice(0, -4);
63
- }
64
- }
65
- };
66
- const auth = async function (ctx) {
67
- const creds = (0, basic_auth_1.default)(ctx);
68
- if (!creds) {
69
- ctx.status = 401;
70
- ctx.response.set('WWW-Authenticate', `Basic realm="${opts.authRealm}"`);
71
- return false;
72
- }
73
- ctx.state.user = await opts.authenticate({
74
- username: creds.name,
75
- password: creds.pass,
76
- principalId: ctx.state.params.principalId
77
- });
78
- if (!ctx.state.user) {
79
- ctx.status = 401;
80
- ctx.response.set('WWW-Authenticate', `Basic realm="${opts.authRealm}"`);
81
- return false;
82
- }
83
- if (!ctx.state.params.principalId) {
84
- ctx.state.params.principalId = ctx.state.user.principalId;
85
- }
86
- return true;
87
- };
88
- const fillRoutes = function (ctx) {
89
- ctx.state.principalRootUrl = principalRoute;
90
- if (ctx.state.params.principalId) {
91
- ctx.state.calendarHomeUrl = path_1.posix.join(calendarRoute, ctx.state.params.principalId, '/');
92
- ctx.state.principalUrl = path_1.posix.join(principalRoute, ctx.state.params.principalId, '/');
93
- if (ctx.state.params.calendarId) {
94
- ctx.state.calendarUrl = path_1.posix.join(calendarRoute, ctx.state.params.principalId, ctx.state.params.calendarId, '/');
95
- }
96
- }
97
- };
98
- return async function (ctx, next) {
99
- if (ctx.url.toLowerCase() === '/.well-known/caldav' && !opts.disableWellKnown) {
100
- // return ctx.redirect(rootRoute);
101
- ctx.status = 404;
102
- return;
103
- }
104
- if (!rootRegexp.test(ctx.url)) {
105
- await next();
106
- return;
107
- }
108
- ctx.state.caldav = true;
109
- fillParams(ctx);
110
- const authed = await auth(ctx);
111
- if (!authed) {
112
- return;
113
- }
114
- fillRoutes(ctx);
115
- await (0, parseBody_1.default)(ctx);
116
- log.verbose(`REQUEST BODY: ${ctx.request.body ? ('\n' + ctx.request.body) : 'empty'}`);
117
- if (calendarRegex.regexp.test(ctx.url)) {
118
- await calendarRoutes(ctx);
119
- }
120
- else if (principalRegex.regexp.test(ctx.url)) {
121
- await principalRoutes(ctx);
122
- }
123
- else {
124
- ctx.redirect(principalRoute);
125
- return;
126
- }
127
- log.verbose(`RESPONSE BODY: ${ctx.body ? ('\n' + ctx.body) : 'empty'}`);
128
- };
129
- }
130
- exports.default = default_1;
@@ -1,7 +0,0 @@
1
- import { CalDavOptionsModule, CalDavCalendar } from '../../..';
2
- import { CalendarContext } from '../../../koa';
3
- export default function (opts: CalDavOptionsModule): (ctx: CalendarContext, calendar: CalDavCalendar) => Promise<{
4
- responses: {
5
- [tag: string]: any;
6
- }[];
7
- }>;
@@ -1,68 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- const xml = __importStar(require("../../../common/xml"));
30
- const xBuild_1 = require("../../../common/xBuild");
31
- const lodash_1 = __importDefault(require("lodash"));
32
- const winston_1 = __importDefault(require("../../../common/winston"));
33
- const eventBuild_1 = __importDefault(require("../../../common/eventBuild"));
34
- function default_1(opts) {
35
- const log = (0, winston_1.default)(Object.assign(Object.assign({}, opts), { label: 'calendar/report/calendar-multiget' }));
36
- const { buildICS } = (0, eventBuild_1.default)(opts);
37
- return async function (ctx, calendar) {
38
- const hrefs = xml.get('/CAL:calendar-multiget/D:href', ctx.request.xml);
39
- const eventActions = lodash_1.default.map(hrefs, async (node) => {
40
- const href = node.textContent;
41
- if (!href) {
42
- return (0, xBuild_1.response)(href, xBuild_1.status[404]);
43
- }
44
- const hrefParts = href.split('/');
45
- const eventId = hrefParts[hrefParts.length - 1].slice(0, -4);
46
- const event = await opts.data.getEvent({
47
- principalId: ctx.state.params.principalId,
48
- calendarId: ctx.state.params.calendarId,
49
- eventId: eventId,
50
- user: ctx.state.user,
51
- fullData: true
52
- });
53
- log.debug(`event ${event ? 'found' : 'missing'}: ${eventId}`);
54
- if (!event) {
55
- return (0, xBuild_1.response)(href, xBuild_1.status[404]);
56
- }
57
- const ics = buildICS(event, calendar);
58
- return (0, xBuild_1.response)(href, xBuild_1.status[200], [{
59
- 'D:getetag': event.lastModifiedOn
60
- }, {
61
- 'CAL:calendar-data': ics
62
- }]);
63
- });
64
- const responses = await Promise.all(eventActions);
65
- return { responses };
66
- };
67
- }
68
- exports.default = default_1;
@@ -1,7 +0,0 @@
1
- import { CalDavOptionsModule, CalDavCalendar } from '../../..';
2
- import { CalendarContext } from '../../../koa';
3
- export default function (opts: CalDavOptionsModule): (ctx: CalendarContext, calendar: CalDavCalendar) => Promise<{
4
- responses: {
5
- [tag: string]: any;
6
- }[];
7
- }>;
@@ -1,62 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- const xml = __importStar(require("../../../common/xml"));
30
- const date_1 = require("../../../common/date");
31
- const lodash_1 = __importDefault(require("lodash"));
32
- const eventResponse_1 = __importDefault(require("./eventResponse"));
33
- function default_1(opts) {
34
- // const log = winston({ ...opts, label: 'calendar/report/calendar-query' });
35
- const eventResponse = (0, eventResponse_1.default)(opts);
36
- return async function (ctx, calendar) {
37
- /* https://tools.ietf.org/html/rfc4791#section-9.9 */
38
- const filters = xml.get('/CAL:calendar-query/CAL:filter/CAL:comp-filter[@name=\'VCALENDAR\']/CAL:comp-filter[@name=\'VEVENT\']/CAL:time-range', ctx.request.xml);
39
- if (!filters || !filters[0]) {
40
- return { responses: [] };
41
- }
42
- const filter = filters[0];
43
- const startAttr = lodash_1.default.find(filter.attributes, { localName: 'start' });
44
- const start = startAttr ? (0, date_1.formatted)(startAttr.nodeValue) : null;
45
- const endAttr = lodash_1.default.find(filter.attributes, { localName: 'end' });
46
- const end = endAttr ? (0, date_1.formatted)(endAttr.nodeValue) : null;
47
- const { children } = xml.getWithChildren('/CAL:calendar-query/D:prop', ctx.request.xml);
48
- const fullData = lodash_1.default.some(children, (child) => {
49
- return child.localName === 'calendar-data';
50
- });
51
- const events = await opts.data.getEventsByDate({
52
- principalId: ctx.state.params.principalId,
53
- calendarId: calendar.calendarId,
54
- start: start,
55
- end: end,
56
- user: ctx.state.user,
57
- fullData: fullData
58
- });
59
- return await eventResponse(ctx, events, calendar, children);
60
- };
61
- }
62
- exports.default = default_1;
@@ -1,5 +0,0 @@
1
- import { CalDavOptionsModule, CalDavCalendar } from '../../..';
2
- import { CalendarContext } from '../../../koa';
3
- export default function (opts: CalDavOptionsModule): {
4
- exec: (ctx: CalendarContext, calendar: CalDavCalendar) => Promise<void>;
5
- };
@@ -1,40 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const xBuild_1 = require("../../../common/xBuild");
7
- const response_1 = require("../../../common/response");
8
- const winston_1 = __importDefault(require("../../../common/winston"));
9
- /* https://tools.ietf.org/html/rfc2518#section-8.6 */
10
- function default_1(opts) {
11
- const log = (0, winston_1.default)(Object.assign(Object.assign({}, opts), { label: 'calendar/delete' }));
12
- const exec = async function (ctx, calendar) {
13
- if (calendar.readOnly) {
14
- return (0, response_1.setMissingMethod)(ctx);
15
- }
16
- if (!ctx.state.params.eventId) {
17
- log.warn('eventId param not present');
18
- ctx.body = (0, xBuild_1.notFound)(ctx.url); // make more meaningful
19
- return;
20
- }
21
- const existing = await opts.data.getEvent({
22
- principalId: ctx.state.params.principalId,
23
- calendarId: ctx.state.params.calendarId,
24
- eventId: ctx.state.params.eventId,
25
- user: ctx.state.user,
26
- fullData: false
27
- });
28
- log.debug(`existing event${existing ? '' : ' not'} found`);
29
- await opts.data.deleteEvent({
30
- principalId: ctx.state.params.principalId,
31
- calendarId: ctx.state.params.calendarId,
32
- eventId: ctx.state.params.eventId,
33
- user: ctx.state.user
34
- });
35
- };
36
- return {
37
- exec
38
- };
39
- }
40
- exports.default = default_1;