@miguelarios/cal-mcp 0.20.0 → 1.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.
- package/CHANGELOG.md +51 -0
- package/LICENSE +21 -0
- package/README.md +8 -3
- package/dist/main.d.ts +2 -2
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +1 -1
- package/dist/main.js.map +1 -1
- package/dist/providers/CalendarBackend.d.ts +94 -0
- package/dist/providers/CalendarBackend.d.ts.map +1 -0
- package/dist/providers/CalendarBackend.js +2 -0
- package/dist/providers/CalendarBackend.js.map +1 -0
- package/dist/providers/types.d.ts +98 -0
- package/dist/providers/types.d.ts.map +1 -0
- package/dist/providers/types.js +2 -0
- package/dist/providers/types.js.map +1 -0
- package/dist/services/CalDavService.d.ts +40 -92
- package/dist/services/CalDavService.d.ts.map +1 -1
- package/dist/services/CalDavService.js +210 -64
- package/dist/services/CalDavService.js.map +1 -1
- package/dist/services/sharing.d.ts +39 -0
- package/dist/services/sharing.d.ts.map +1 -0
- package/dist/services/sharing.js +253 -0
- package/dist/services/sharing.js.map +1 -0
- package/dist/services/urlCache.d.ts +1 -1
- package/dist/services/urlCache.js +2 -2
- package/dist/services/urlCache.js.map +1 -1
- package/dist/tools/calendarManagementTools.d.ts +3 -3
- package/dist/tools/calendarManagementTools.d.ts.map +1 -1
- package/dist/tools/calendarManagementTools.js +108 -33
- package/dist/tools/calendarManagementTools.js.map +1 -1
- package/dist/tools/calendarSchemas.d.ts +67 -45
- package/dist/tools/calendarSchemas.d.ts.map +1 -1
- package/dist/tools/calendarSchemas.js +35 -14
- package/dist/tools/calendarSchemas.js.map +1 -1
- package/dist/tools/calendarTools.d.ts +2 -2
- package/dist/tools/calendarTools.d.ts.map +1 -1
- package/dist/tools/calendarTools.js +160 -112
- package/dist/tools/calendarTools.js.map +1 -1
- package/package.json +8 -4
|
@@ -1,8 +1,27 @@
|
|
|
1
1
|
import { randomBytes } from "node:crypto";
|
|
2
|
-
import { CalendarError, ErrorCode, ValidationError, checkDavCollectionResponse, formatInTimezone, getLocalDateParts, getTimezone, toPimError, zonedTimeToUtc, } from "@miguelarios/pim-core";
|
|
2
|
+
import { CalendarError, ErrorCode, PimError, ValidationError, checkDavCollectionResponse, formatInTimezone, getLocalDateParts, getTimezone, toPimError, zonedTimeToUtc, } from "@miguelarios/pim-core";
|
|
3
3
|
import { generateVTimezoneIcs, parseIcsEvents, parseIcsFreeBusy, } from "@miguelarios/pim-core/ics";
|
|
4
4
|
import { DAVClient } from "tsdav";
|
|
5
|
+
import { SHARING_PROPFIND_BODY, buildShareBody, buildUnshareBody, parseSharing, } from "./sharing.js";
|
|
5
6
|
import { deleteCachedObject, getCachedObject, moveCachedCalendar, purgeCachedCalendar, setCachedObject, } from "./urlCache.js";
|
|
7
|
+
function asError(error) {
|
|
8
|
+
return error instanceof Error ? error : new Error(String(error));
|
|
9
|
+
}
|
|
10
|
+
/** A provider's error, named, with the original's code and retryability. */
|
|
11
|
+
class ProviderError extends PimError {
|
|
12
|
+
constructor(providerId, original) {
|
|
13
|
+
super(`Calendar provider "${providerId}": ${original.message}`, original.code, original.isRetryable);
|
|
14
|
+
this.cause = original;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The provider's error as a new PimError naming which provider failed. A new
|
|
19
|
+
* object rather than an edited message, so the caller's error and its stack
|
|
20
|
+
* are left alone and naming it twice cannot stack prefixes.
|
|
21
|
+
*/
|
|
22
|
+
function providerError(providerId, error) {
|
|
23
|
+
return new ProviderError(providerId, toPimError(asError(error)));
|
|
24
|
+
}
|
|
6
25
|
/**
|
|
7
26
|
* Merges overlapping or touching periods of the same type; output is sorted
|
|
8
27
|
* by start. Periods are visited in start order, so by the time one is
|
|
@@ -387,7 +406,7 @@ export class CalDavService {
|
|
|
387
406
|
return true; // Default to writable on error
|
|
388
407
|
}
|
|
389
408
|
}
|
|
390
|
-
// Returns the CalDAV account username for the given
|
|
409
|
+
// Returns the CalDAV account username for the given calendarId. Used by
|
|
391
410
|
// the tool layer to populate ORGANIZER on events that include attendees —
|
|
392
411
|
// without this, strict CalDAV servers reject the PUT with 412 (see
|
|
393
412
|
// updateEvent and generateEventIcs for context).
|
|
@@ -395,40 +414,80 @@ export class CalDavService {
|
|
|
395
414
|
const { account } = this.resolveAccount(calendarId);
|
|
396
415
|
return account.username;
|
|
397
416
|
}
|
|
417
|
+
/**
|
|
418
|
+
* Every calendar on every provider, or an error naming the first provider
|
|
419
|
+
* that could not be listed. For callers that must not act on a partial
|
|
420
|
+
* view — free/busy and free slots, where a missing provider's busy time
|
|
421
|
+
* would read as free.
|
|
422
|
+
*/
|
|
398
423
|
async listCalendars() {
|
|
399
424
|
const allCalendars = [];
|
|
400
425
|
for (const [providerId, account] of this.accounts) {
|
|
401
426
|
try {
|
|
402
|
-
|
|
403
|
-
const calendars = await client.fetchCalendars({
|
|
404
|
-
props: CALENDAR_LIST_PROPS,
|
|
405
|
-
projectedProps: CALENDAR_LIST_PROJECTION,
|
|
406
|
-
});
|
|
407
|
-
this.calendarsCache.set(providerId, calendars);
|
|
408
|
-
for (const cal of calendars) {
|
|
409
|
-
const displayName = displayNameOf(cal);
|
|
410
|
-
const canWrite = await this.fetchPrivileges(client, cal.url);
|
|
411
|
-
allCalendars.push({
|
|
412
|
-
calendar_id: `${providerId}/${displayName}`,
|
|
413
|
-
display_name: displayName,
|
|
414
|
-
color: cal.calendarColor ?? null,
|
|
415
|
-
description: descriptionOf(cal),
|
|
416
|
-
timezone: timezoneOf(cal),
|
|
417
|
-
order: orderOf(cal),
|
|
418
|
-
source: providerId,
|
|
419
|
-
read_only: !canWrite,
|
|
420
|
-
url: cal.url,
|
|
421
|
-
ctag: cal.ctag,
|
|
422
|
-
});
|
|
423
|
-
}
|
|
427
|
+
allCalendars.push(...(await this.listProviderCalendars(providerId, account)));
|
|
424
428
|
}
|
|
425
429
|
catch (error) {
|
|
426
|
-
throw
|
|
430
|
+
throw providerError(providerId, error);
|
|
427
431
|
}
|
|
428
432
|
}
|
|
429
433
|
return allCalendars;
|
|
430
434
|
}
|
|
431
|
-
/**
|
|
435
|
+
/**
|
|
436
|
+
* The calendars of every provider that answers, plus which ones did not and
|
|
437
|
+
* why (#127). One unreachable provider — a LAN server seen from off that
|
|
438
|
+
* network — no longer hides the others. Only when none answers does this
|
|
439
|
+
* throw, so a single-provider setup fails exactly as before.
|
|
440
|
+
*/
|
|
441
|
+
async listReachableCalendars() {
|
|
442
|
+
const calendars = [];
|
|
443
|
+
const unavailable = [];
|
|
444
|
+
let firstError;
|
|
445
|
+
for (const [providerId, account] of this.accounts) {
|
|
446
|
+
try {
|
|
447
|
+
calendars.push(...(await this.listProviderCalendars(providerId, account)));
|
|
448
|
+
}
|
|
449
|
+
catch (error) {
|
|
450
|
+
firstError ??= error;
|
|
451
|
+
unavailable.push({ provider: providerId, error: toPimError(asError(error)).message });
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
if (unavailable.length > 0 && unavailable.length === this.accounts.size) {
|
|
455
|
+
throw providerError(unavailable[0].provider, firstError);
|
|
456
|
+
}
|
|
457
|
+
return { calendars, unavailable };
|
|
458
|
+
}
|
|
459
|
+
async listProviderCalendars(providerId, account) {
|
|
460
|
+
const client = await this.getClient(account);
|
|
461
|
+
const calendars = await client.fetchCalendars({
|
|
462
|
+
props: CALENDAR_LIST_PROPS,
|
|
463
|
+
projectedProps: CALENDAR_LIST_PROJECTION,
|
|
464
|
+
});
|
|
465
|
+
this.calendarsCache.set(providerId, calendars);
|
|
466
|
+
const out = [];
|
|
467
|
+
for (const cal of calendars) {
|
|
468
|
+
const displayName = displayNameOf(cal);
|
|
469
|
+
const canWrite = await this.fetchPrivileges(client, cal.url);
|
|
470
|
+
out.push({
|
|
471
|
+
calendarId: `${providerId}/${displayName}`,
|
|
472
|
+
displayName: displayName,
|
|
473
|
+
color: cal.calendarColor ?? null,
|
|
474
|
+
description: descriptionOf(cal),
|
|
475
|
+
timezone: timezoneOf(cal),
|
|
476
|
+
order: orderOf(cal),
|
|
477
|
+
source: providerId,
|
|
478
|
+
readOnly: !canWrite,
|
|
479
|
+
url: cal.url,
|
|
480
|
+
// tsdav parses a bare-integer <getctag> (Nextcloud) as a number. It
|
|
481
|
+
// is still a valid change marker, so keep it, as the string it is typed as.
|
|
482
|
+
// Anything else (xml2js yields {} for an empty <getctag/>) is dropped.
|
|
483
|
+
...(typeof cal.ctag === "string" || typeof cal.ctag === "number"
|
|
484
|
+
? { ctag: String(cal.ctag) }
|
|
485
|
+
: {}),
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
return out;
|
|
489
|
+
}
|
|
490
|
+
/** The configured provider IDs — the prefix half of every `calendarId`. */
|
|
432
491
|
listProviders() {
|
|
433
492
|
return [...this.accounts.keys()];
|
|
434
493
|
}
|
|
@@ -457,7 +516,7 @@ export class CalDavService {
|
|
|
457
516
|
throw new ValidationError(`provider is required when several accounts are configured — choose one of: ${known.join(", ")}`, "provider");
|
|
458
517
|
}
|
|
459
518
|
/**
|
|
460
|
-
* Resolves a
|
|
519
|
+
* Resolves a calendarId to the entry it names, so a caller can say what it
|
|
461
520
|
* is about to act on rather than echoing back the string it was handed.
|
|
462
521
|
*/
|
|
463
522
|
async findCalendarEntry(calendarId) {
|
|
@@ -466,8 +525,8 @@ export class CalDavService {
|
|
|
466
525
|
const client = await this.getClient(account);
|
|
467
526
|
const calendar = await this.findCalendar(client, calendarName, account.id);
|
|
468
527
|
return {
|
|
469
|
-
|
|
470
|
-
|
|
528
|
+
calendarId: calendarId,
|
|
529
|
+
displayName: calendarName,
|
|
471
530
|
url: calendar.url,
|
|
472
531
|
provider: account.id,
|
|
473
532
|
};
|
|
@@ -478,6 +537,93 @@ export class CalDavService {
|
|
|
478
537
|
throw toPimError(error instanceof Error ? error : new Error(String(error)));
|
|
479
538
|
}
|
|
480
539
|
}
|
|
540
|
+
/**
|
|
541
|
+
* One authenticated request to a calendar collection. Sharing uses raw
|
|
542
|
+
* requests rather than tsdav: tsdav's XML handling drops namespace prefixes,
|
|
543
|
+
* which collides `D:invite` with `CS:invite` (see sharing.ts).
|
|
544
|
+
*/
|
|
545
|
+
async collectionRequest(calendarId, method, body, headers = {}) {
|
|
546
|
+
const { account, calendarName } = this.resolveAccount(calendarId);
|
|
547
|
+
const client = await this.getClient(account);
|
|
548
|
+
const calendar = await this.findCalendar(client, calendarName, account.id);
|
|
549
|
+
const url = new URL(calendar.url, account.url).toString();
|
|
550
|
+
const response = await fetch(url, {
|
|
551
|
+
method,
|
|
552
|
+
headers: {
|
|
553
|
+
Authorization: `Basic ${Buffer.from(`${account.username}:${account.password}`).toString("base64")}`,
|
|
554
|
+
"Content-Type": "application/xml; charset=utf-8",
|
|
555
|
+
...headers,
|
|
556
|
+
},
|
|
557
|
+
body,
|
|
558
|
+
});
|
|
559
|
+
return {
|
|
560
|
+
status: response.status,
|
|
561
|
+
statusText: response.statusText,
|
|
562
|
+
text: await response.text(),
|
|
563
|
+
url,
|
|
564
|
+
};
|
|
565
|
+
}
|
|
566
|
+
/** Who a calendar is shared with, and at what access (#47). */
|
|
567
|
+
async getCalendarSharing(calendarId) {
|
|
568
|
+
try {
|
|
569
|
+
const res = await this.collectionRequest(calendarId, "PROPFIND", SHARING_PROPFIND_BODY, {
|
|
570
|
+
Depth: "0",
|
|
571
|
+
});
|
|
572
|
+
if (res.status !== 207) {
|
|
573
|
+
throw new CalendarError(`Reading sharing for "${calendarId}" failed: ${res.status} ${res.statusText}`, ErrorCode.OPERATION_FAILED);
|
|
574
|
+
}
|
|
575
|
+
return parseSharing(res.text);
|
|
576
|
+
}
|
|
577
|
+
catch (error) {
|
|
578
|
+
if (error instanceof CalendarError || error instanceof ValidationError)
|
|
579
|
+
throw error;
|
|
580
|
+
throw toPimError(error instanceof Error ? error : new Error(String(error)));
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* Grants (`access` given) or revokes (`access` null) a sharee's access, in
|
|
585
|
+
* whichever sharing dialect the server answered the read with, then returns
|
|
586
|
+
* the calendar's sharing as the server now reports it.
|
|
587
|
+
*/
|
|
588
|
+
async changeCalendarShare(calendarId, sharee, access, summary) {
|
|
589
|
+
if (!sharee.trim())
|
|
590
|
+
throw new ValidationError("sharee is required", "sharee");
|
|
591
|
+
const before = await this.getCalendarSharing(calendarId);
|
|
592
|
+
const protocol = before.protocol;
|
|
593
|
+
if (!before.canBeShared || (protocol !== "calendarserver" && protocol !== "owncloud")) {
|
|
594
|
+
throw new ValidationError(`Calendar "${calendarId}" cannot be shared through this server: it reports neither CalendarServer nor Nextcloud sharing`, "calendar");
|
|
595
|
+
}
|
|
596
|
+
let body;
|
|
597
|
+
try {
|
|
598
|
+
body =
|
|
599
|
+
access === null
|
|
600
|
+
? buildUnshareBody(protocol, sharee)
|
|
601
|
+
: buildShareBody(protocol, sharee, access, summary);
|
|
602
|
+
}
|
|
603
|
+
catch (error) {
|
|
604
|
+
throw new ValidationError(error instanceof Error ? error.message : String(error), "sharee");
|
|
605
|
+
}
|
|
606
|
+
try {
|
|
607
|
+
const res = await this.collectionRequest(calendarId, "POST", body);
|
|
608
|
+
if (res.status < 200 || res.status >= 300) {
|
|
609
|
+
throw new CalendarError(`${access === null ? "Unsharing" : "Sharing"} "${calendarId}" failed: ${res.status} ${res.statusText}`, ErrorCode.OPERATION_FAILED);
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
catch (error) {
|
|
613
|
+
if (error instanceof CalendarError)
|
|
614
|
+
throw error;
|
|
615
|
+
throw toPimError(error instanceof Error ? error : new Error(String(error)));
|
|
616
|
+
}
|
|
617
|
+
try {
|
|
618
|
+
return await this.getCalendarSharing(calendarId);
|
|
619
|
+
}
|
|
620
|
+
catch (error) {
|
|
621
|
+
// The change was applied; only reading it back failed. Saying so keeps a
|
|
622
|
+
// caller from retrying a share, which could send a second invitation.
|
|
623
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
624
|
+
throw new CalendarError(`${access === null ? "Unsharing" : "Sharing"} "${calendarId}" succeeded, but reading the calendar's sharing back failed: ${reason}. Do not repeat the change; call get_calendar_sharing to check.`, ErrorCode.OPERATION_FAILED);
|
|
625
|
+
}
|
|
626
|
+
}
|
|
481
627
|
/**
|
|
482
628
|
* Counts the objects in a calendar with a single depth-1 PROPFIND asking only
|
|
483
629
|
* for etags — no ICS bodies cross the wire. Counts calendar *objects*, so a
|
|
@@ -522,11 +668,11 @@ export class CalDavService {
|
|
|
522
668
|
*/
|
|
523
669
|
async createCalendar(opts) {
|
|
524
670
|
const account = this.resolveProvider(opts.provider);
|
|
525
|
-
// A calendar with no display name has no addressable
|
|
671
|
+
// A calendar with no display name has no addressable calendarId at all —
|
|
526
672
|
// `provider/` resolves to nothing — so creating one is refused rather than
|
|
527
673
|
// quietly made unreachable.
|
|
528
674
|
if (opts.displayName.trim() === "") {
|
|
529
|
-
throw new ValidationError("
|
|
675
|
+
throw new ValidationError("displayName cannot be empty", "displayName");
|
|
530
676
|
}
|
|
531
677
|
if (opts.slug !== undefined && !/^[a-z0-9][a-z0-9-]{0,62}$/.test(opts.slug)) {
|
|
532
678
|
throw new ValidationError(`Invalid slug "${opts.slug}" — use lowercase letters, digits and hyphens, starting with a letter or digit`, "slug");
|
|
@@ -537,7 +683,7 @@ export class CalDavService {
|
|
|
537
683
|
const client = await this.getClient(account);
|
|
538
684
|
const existing = await this.fetchCalendarsFor(client, account.id);
|
|
539
685
|
// A second calendar with the same display name on the same provider would
|
|
540
|
-
// make its
|
|
686
|
+
// make its calendarId ambiguous on *every subsequent call* — the name is
|
|
541
687
|
// not a convenience alias here, it is half the ID, and findCalendar
|
|
542
688
|
// resolves every event operation by exact display-name match. So duplicates
|
|
543
689
|
// are refused rather than suffixed; that also keeps a retried create from
|
|
@@ -599,8 +745,8 @@ export class CalDavService {
|
|
|
599
745
|
// that cache — so drop it or the calendar stays invisible to this process.
|
|
600
746
|
this.calendarsCache.delete(account.id);
|
|
601
747
|
return {
|
|
602
|
-
|
|
603
|
-
|
|
748
|
+
calendarId: `${account.id}/${opts.displayName}`,
|
|
749
|
+
displayName: opts.displayName,
|
|
604
750
|
url,
|
|
605
751
|
provider: account.id,
|
|
606
752
|
};
|
|
@@ -608,7 +754,7 @@ export class CalDavService {
|
|
|
608
754
|
/**
|
|
609
755
|
* Updates a calendar's display name, description and/or colour via PROPPATCH.
|
|
610
756
|
*
|
|
611
|
-
* Renaming changes the calendar's identity: `
|
|
757
|
+
* Renaming changes the calendar's identity: `calendarId` is
|
|
612
758
|
* `provider/DisplayName`, so the old ID stops resolving and the *new* one
|
|
613
759
|
* comes back in the result. The collection URL is untouched — display name
|
|
614
760
|
* and slug are allowed to drift, exactly as in every CalDAV client.
|
|
@@ -619,10 +765,10 @@ export class CalDavService {
|
|
|
619
765
|
opts.color === undefined &&
|
|
620
766
|
opts.timezone === undefined &&
|
|
621
767
|
opts.order === undefined) {
|
|
622
|
-
throw new ValidationError("Nothing to change — provide a
|
|
768
|
+
throw new ValidationError("Nothing to change — provide a displayName, color, description, timezone and/or order");
|
|
623
769
|
}
|
|
624
770
|
if (opts.displayName !== undefined && opts.displayName.trim() === "") {
|
|
625
|
-
throw new ValidationError("
|
|
771
|
+
throw new ValidationError("displayName cannot be empty", "displayName");
|
|
626
772
|
}
|
|
627
773
|
const color = opts.color !== undefined ? normalizeCalendarColor(opts.color) : undefined;
|
|
628
774
|
const timezone = opts.timezone !== undefined ? normalizeCalendarTimezone(opts.timezone) : undefined;
|
|
@@ -631,7 +777,7 @@ export class CalDavService {
|
|
|
631
777
|
const client = await this.getClient(account);
|
|
632
778
|
const calendar = await this.findCalendar(client, calendarName, account.id);
|
|
633
779
|
const url = calendar.url;
|
|
634
|
-
// Renaming onto a name already in use would make that
|
|
780
|
+
// Renaming onto a name already in use would make that calendarId ambiguous
|
|
635
781
|
// — the same reason create refuses duplicates. The calendar being renamed is
|
|
636
782
|
// excluded so re-applying its own name stays a no-op rather than an error.
|
|
637
783
|
if (opts.displayName !== undefined) {
|
|
@@ -677,12 +823,12 @@ export class CalDavService {
|
|
|
677
823
|
const newDisplayName = opts.displayName ?? calendarName;
|
|
678
824
|
const newCalendarId = `${account.id}/${newDisplayName}`;
|
|
679
825
|
this.calendarsCache.delete(account.id);
|
|
680
|
-
// The UID→URL cache is keyed by
|
|
826
|
+
// The UID→URL cache is keyed by calendarId; a rename leaves its entries
|
|
681
827
|
// valid but filed under a key nothing looks up again.
|
|
682
828
|
moveCachedCalendar(calendarId, newCalendarId);
|
|
683
829
|
return {
|
|
684
|
-
|
|
685
|
-
|
|
830
|
+
calendarId: newCalendarId,
|
|
831
|
+
displayName: newDisplayName,
|
|
686
832
|
url,
|
|
687
833
|
provider: account.id,
|
|
688
834
|
};
|
|
@@ -706,8 +852,8 @@ export class CalDavService {
|
|
|
706
852
|
this.calendarsCache.delete(account.id);
|
|
707
853
|
purgeCachedCalendar(calendarId);
|
|
708
854
|
return {
|
|
709
|
-
|
|
710
|
-
|
|
855
|
+
calendarId: calendarId,
|
|
856
|
+
displayName: calendarName,
|
|
711
857
|
url,
|
|
712
858
|
provider: account.id,
|
|
713
859
|
};
|
|
@@ -747,15 +893,15 @@ export class CalDavService {
|
|
|
747
893
|
}
|
|
748
894
|
summaries.push({
|
|
749
895
|
uid: event.uid,
|
|
750
|
-
|
|
896
|
+
calendarId: calendarId,
|
|
751
897
|
title: event.title,
|
|
752
898
|
start: event.start,
|
|
753
899
|
end: event.end,
|
|
754
|
-
|
|
900
|
+
allDay: event.allDay,
|
|
755
901
|
location: event.location,
|
|
756
902
|
status: event.status,
|
|
757
|
-
|
|
758
|
-
|
|
903
|
+
isRecurring: event.isRecurring,
|
|
904
|
+
occurrenceDate: event.occurrenceDate,
|
|
759
905
|
});
|
|
760
906
|
}
|
|
761
907
|
}
|
|
@@ -800,7 +946,7 @@ export class CalDavService {
|
|
|
800
946
|
* exactly as `list_events` would expand it. That covers a plain rule-generated
|
|
801
947
|
* occurrence and an override VEVENT alike: the override's fields (moved time,
|
|
802
948
|
* changed title) come back in place of the master's, which is what a caller
|
|
803
|
-
* holding an `
|
|
949
|
+
* holding an `occurrenceDate` from `list_events` needs (#39).
|
|
804
950
|
*/
|
|
805
951
|
async readEvent(calendarId, uid, occurrenceDate) {
|
|
806
952
|
const { account, calendarName } = this.resolveAccount(calendarId);
|
|
@@ -829,29 +975,29 @@ export class CalDavService {
|
|
|
829
975
|
}
|
|
830
976
|
/**
|
|
831
977
|
* Expands the series over a two-day window around `occurrenceDate` and keeps
|
|
832
|
-
* the instance whose `
|
|
978
|
+
* the instance whose `occurrenceDate` is exactly that instant. The expansion
|
|
833
979
|
* filters on the rule-generated slot (the RECURRENCE-ID), not on an
|
|
834
980
|
* override's own DTSTART, so a moved override is found by its slot like any
|
|
835
981
|
* other occurrence. The window exists because the range is half-open
|
|
836
982
|
* `[start, end)`: a zero-width range would exclude the target itself. The
|
|
837
|
-
* exact match on `
|
|
983
|
+
* exact match on `occurrenceDate` then keeps the neighbours out.
|
|
838
984
|
*/
|
|
839
985
|
pickOccurrence(data, uid, master, occurrenceDate) {
|
|
840
986
|
const target = new Date(occurrenceDate).getTime();
|
|
841
987
|
if (Number.isNaN(target)) {
|
|
842
|
-
throw new ValidationError(`Invalid
|
|
988
|
+
throw new ValidationError(`Invalid occurrenceDate "${occurrenceDate}" — use an ISO 8601 date-time`, "occurrenceDate");
|
|
843
989
|
}
|
|
844
|
-
if (!master.
|
|
845
|
-
throw new ValidationError(`Event "${uid}" is not recurring — omit
|
|
990
|
+
if (!master.isRecurring) {
|
|
991
|
+
throw new ValidationError(`Event "${uid}" is not recurring — omit occurrenceDate to read it`, "occurrenceDate");
|
|
846
992
|
}
|
|
847
993
|
const DAY = 86_400_000;
|
|
848
994
|
const window = {
|
|
849
995
|
start: new Date(target - DAY).toISOString(),
|
|
850
996
|
end: new Date(target + DAY).toISOString(),
|
|
851
997
|
};
|
|
852
|
-
const hit = parseIcsEvents(data, window, this.timezone).find((e) => e.uid === uid && e.
|
|
998
|
+
const hit = parseIcsEvents(data, window, this.timezone).find((e) => e.uid === uid && e.occurrenceDate !== null && Date.parse(e.occurrenceDate) === target);
|
|
853
999
|
if (!hit) {
|
|
854
|
-
throw new CalendarError(`Event "${uid}" has no occurrence at ${occurrenceDate} —
|
|
1000
|
+
throw new CalendarError(`Event "${uid}" has no occurrence at ${occurrenceDate} — occurrenceDate must be a value list_events returned for it`, ErrorCode.EVENT_NOT_FOUND, uid);
|
|
855
1001
|
}
|
|
856
1002
|
return hit;
|
|
857
1003
|
}
|
|
@@ -1102,8 +1248,8 @@ export class CalDavService {
|
|
|
1102
1248
|
end: event.end,
|
|
1103
1249
|
status: event.status,
|
|
1104
1250
|
availability: event.availability,
|
|
1105
|
-
|
|
1106
|
-
|
|
1251
|
+
allDay: event.allDay,
|
|
1252
|
+
calendarId: calendarId,
|
|
1107
1253
|
});
|
|
1108
1254
|
}
|
|
1109
1255
|
}
|
|
@@ -1118,7 +1264,7 @@ export class CalDavService {
|
|
|
1118
1264
|
/** Which candidates actually block time under the given options. */
|
|
1119
1265
|
static blocksTime(e, options) {
|
|
1120
1266
|
// Skip all-day events unless includeAllDayAsBusy
|
|
1121
|
-
if (e.
|
|
1267
|
+
if (e.allDay && !options.includeAllDayAsBusy)
|
|
1122
1268
|
return false;
|
|
1123
1269
|
// Skip free events
|
|
1124
1270
|
if (e.availability === "free")
|
|
@@ -1361,23 +1507,23 @@ export class CalDavService {
|
|
|
1361
1507
|
toEventFull(event, calendarId) {
|
|
1362
1508
|
return {
|
|
1363
1509
|
uid: event.uid,
|
|
1364
|
-
|
|
1510
|
+
calendarId: calendarId,
|
|
1365
1511
|
title: event.title,
|
|
1366
1512
|
start: event.start,
|
|
1367
1513
|
end: event.end,
|
|
1368
|
-
|
|
1514
|
+
allDay: event.allDay,
|
|
1369
1515
|
location: event.location,
|
|
1370
1516
|
status: event.status,
|
|
1371
|
-
|
|
1372
|
-
|
|
1517
|
+
isRecurring: event.isRecurring,
|
|
1518
|
+
occurrenceDate: event.occurrenceDate,
|
|
1373
1519
|
description: event.description,
|
|
1374
1520
|
url: event.url,
|
|
1375
1521
|
availability: event.availability,
|
|
1376
1522
|
attendees: event.attendees,
|
|
1377
1523
|
organizer: event.organizer,
|
|
1378
|
-
|
|
1524
|
+
recurrenceRule: event.recurrenceRule,
|
|
1379
1525
|
created: event.created,
|
|
1380
|
-
|
|
1526
|
+
lastModified: event.lastModified,
|
|
1381
1527
|
alarms: event.alarms,
|
|
1382
1528
|
categories: event.categories,
|
|
1383
1529
|
geo: event.geo,
|