@wtfalch/calendar 0.3.0 → 0.3.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/README.md CHANGED
@@ -2,9 +2,17 @@
2
2
 
3
3
  `@wtfalch/calendar` is a JMAP calendar client for Agora, the wtfalch communications app.
4
4
  It reads and writes a person's own events, invites, sharing between colleagues and free/busy straight from Stalwart, with no server code of its own.
5
- It exports `./calendar` (`createCalendarClient`), `./calendar/react` (the `Calendar` component), `./calendar/fake` (`fakeCalendar()`) and `./calendar/calendar.css`, mirroring `@wtfalch/email` and `@wtfalch/messaging`.
5
+ It exports `./calendar` (`createCalendarClient`), `./calendar/react` (the `Calendar` component) and `./calendar/calendar.css`, mirroring `@wtfalch/email` and `@wtfalch/messaging`.
6
6
  See the [calendar plan](https://github.com/wtfalch/messaging/blob/main/.plans/2026-09-17-calendar.md) for the design and [wtfalch/messaging#156](https://github.com/wtfalch/messaging/issues/156) for this package's own ticket.
7
7
 
8
+ ## Importing events
9
+
10
+ Agora's `.ics` import (`apps/agora/src/calendar/ImportIcs.tsx`) is a manual stopgap, not a migration
11
+ path: one calendar per file, at most 2 MB and 500 events per file, and it skips tasks. Each calendar
12
+ is imported by hand. A company move brings calendars in through Vandelay's CalDAV import instead —
13
+ see ["Calendars and contacts"](https://github.com/wtfalch/estate/blob/main/proposals/migration-in.md#calendars-and-contacts)
14
+ in the migration-in plan.
15
+
8
16
  ## Status
9
17
 
10
18
  Published: yes, v0.2.0, 2026-09-22
@@ -194,7 +194,9 @@ async function createEvent(connection, calendarId, event, options) {
194
194
  }
195
195
  /** `importIcs`: parse with `icsToEventDrafts` and `createEvent` once per
196
196
  * draft, onto `calendarId` -- sequentially, so one refused event does not
197
- * leave the rest half-created in an order nobody can predict. A `VEVENT`
197
+ * leave the rest half-created in an order nobody can predict. A draft whose
198
+ * `uid` is already on `calendarId` is not created; its `uid` goes under
199
+ * `existing`, once. A `VEVENT`
198
200
  * `icsToEventDrafts` could not parse is already excluded from `drafts` by
199
201
  * then; its own `skipped` entries ride straight through onto the result
200
202
  * (wtfalch/calendar#46). */
@@ -202,10 +204,38 @@ async function importIcs(connection, calendarId, ics) {
202
204
  return guard('events.import', async () => {
203
205
  const { drafts, skipped } = icsToEventDrafts(ics);
204
206
  const created = [];
207
+ const existing = [];
208
+ if (drafts.length === 0)
209
+ return { created, skipped, existing };
210
+ // One query + one get before anything is created: the uids already on
211
+ // `calendarId`. No server-side `uid` filter (unconfirmed against Stalwart).
212
+ const accountId = await connection.accountId();
213
+ const queryResult = await connection.request('CalendarEvent/query', { accountId });
214
+ const known = new Set();
215
+ if (queryResult.ids.length > 0) {
216
+ const found = await connection.request('CalendarEvent/get', {
217
+ accountId,
218
+ ids: queryResult.ids,
219
+ properties: ['id', 'uid', 'calendarIds'],
220
+ });
221
+ for (const event of found.list) {
222
+ if (event.uid !== undefined && event.calendarIds?.[calendarId])
223
+ known.add(event.uid);
224
+ }
225
+ }
226
+ const reported = new Set();
205
227
  for (const draft of drafts) {
228
+ if (known.has(draft.uid)) {
229
+ if (!reported.has(draft.uid)) {
230
+ reported.add(draft.uid);
231
+ existing.push({ uid: draft.uid });
232
+ }
233
+ continue;
234
+ }
206
235
  created.push(await createEvent(connection, calendarId, { ...draft, calendarId }, undefined));
236
+ known.add(draft.uid);
207
237
  }
208
- return { created, skipped };
238
+ return { created, skipped, existing };
209
239
  });
210
240
  }
211
241
  /**
@@ -19,7 +19,7 @@
19
19
  * JSON envelope RFC 8620 §3.3 defines either way, and it is what
20
20
  * `client.ts`'s own session fetch and `push.ts`'s SSE loop already use for
21
21
  * the same reason (a browser `EventSource` cannot carry an `Authorization`
22
- * header). It also happens to be what `./calendar/fake` needs: intercepting
22
+ * header). It also happens to be what the test fake needs: intercepting
23
23
  * `fetch` is the only way a fake transport can answer real JMAP without a
24
24
  * second, `jmap-jam`-shaped fake underneath it.
25
25
  */
@@ -19,7 +19,7 @@
19
19
  * JSON envelope RFC 8620 §3.3 defines either way, and it is what
20
20
  * `client.ts`'s own session fetch and `push.ts`'s SSE loop already use for
21
21
  * the same reason (a browser `EventSource` cannot carry an `Authorization`
22
- * header). It also happens to be what `./calendar/fake` needs: intercepting
22
+ * header). It also happens to be what the test fake needs: intercepting
23
23
  * `fetch` is the only way a fake transport can answer real JMAP without a
24
24
  * second, `jmap-jam`-shaped fake underneath it.
25
25
  */
@@ -32,6 +32,30 @@ export const CORE_CAPABILITY = 'urn:ietf:params:jmap:core';
32
32
  * ambient browser credentials keeps a refused token from popping the
33
33
  * browser's native Basic-auth prompt over the application's own error. */
34
34
  const NO_BROWSER_CREDENTIALS = { credentials: 'omit' };
35
+ /** Put an absolute URL from the session document onto `origin`, keeping its
36
+ * path, query and `{template}` parts byte for byte. A relative URL, or one
37
+ * already on `origin`, is returned as it came. */
38
+ function onOrigin(url, origin) {
39
+ const authority = /^[a-z][a-z0-9+.-]*:\/\/[^/?#]*/i.exec(url)?.[0];
40
+ return authority && authority !== origin ? origin + url.slice(authority.length) : url;
41
+ }
42
+ /** A server behind a proxy writes its own host into the session document.
43
+ * A browser that follows those URLs leaves the origin it fetched the session
44
+ * from, so every URL is moved back onto that origin. */
45
+ function keepOnOrigin(doc, sessionUrl) {
46
+ let origin;
47
+ try {
48
+ origin = new URL(sessionUrl).origin;
49
+ }
50
+ catch {
51
+ return doc;
52
+ }
53
+ return {
54
+ ...doc,
55
+ apiUrl: onOrigin(doc.apiUrl, origin),
56
+ eventSourceUrl: onOrigin(doc.eventSourceUrl, origin),
57
+ };
58
+ }
35
59
  function looksLikeSession(value) {
36
60
  return (typeof value === 'object' &&
37
61
  value !== null &&
@@ -116,7 +140,7 @@ export class CalendarConnection {
116
140
  if (!looksLikeSession(parsed)) {
117
141
  throw new CalendarError(`${this.#sessionUrl} did not answer with a JMAP session document (${response.status}): ${body.slice(0, 200)}`, { status: response.status, operation: 'client.connect' });
118
142
  }
119
- return parsed;
143
+ return keepOnOrigin(parsed, this.#sessionUrl);
120
144
  }
121
145
  /** The account id this connection reads and writes. */
122
146
  async accountId() {
@@ -474,6 +474,9 @@ export type ImportIcsSkippedEvent = {
474
474
  export type ImportIcsResult = {
475
475
  readonly created: readonly CalendarEvent[];
476
476
  readonly skipped: readonly ImportIcsSkippedEvent[];
477
+ readonly existing: readonly {
478
+ readonly uid: string;
479
+ }[];
477
480
  };
478
481
  /**
479
482
  * One principal's own working day, for `findTime`'s per-attendee
@@ -697,6 +700,11 @@ export interface CalendarClient {
697
700
  * import: every otherwise-valid `VEVENT` in the same document still gets
698
701
  * created, and `ImportIcsResult.skipped` says which ones did not and why
699
702
  * (wtfalch/calendar#46).
703
+ *
704
+ * A `VEVENT` whose `UID` is already on `calendarId` is not created and
705
+ * never overwritten: its `uid` is listed once under
706
+ * `ImportIcsResult.existing`, so importing the same file twice creates
707
+ * nothing the second time. Only `calendarId` counts, not other calendars.
700
708
  */
701
709
  importIcs(calendarId: string, ics: string): Promise<ImportIcsResult>;
702
710
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wtfalch/calendar",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "A JMAP calendar client for Agora, the wtfalch communications app: events, invites, sharing and free/busy over Stalwart, and the React UI on react-big-calendar.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -18,10 +18,6 @@
18
18
  "types": "./dist/calendar/react/index.d.ts",
19
19
  "default": "./dist/calendar/react/index.js"
20
20
  },
21
- "./calendar/fake": {
22
- "types": "./dist/calendar/fake/index.d.ts",
23
- "default": "./dist/calendar/fake/index.js"
24
- },
25
21
  "./calendar/calendar.css": "./dist/calendar/calendar.css",
26
22
  "./package.json": "./package.json"
27
23
  },
@@ -37,7 +33,7 @@
37
33
  "dev": "vite --config dev/vite.config.ts"
38
34
  },
39
35
  "peerDependencies": {
40
- "@wtfalch/design": "^0.21.0",
36
+ "@wtfalch/design": "^0.30.0",
41
37
  "react": "^19.0.0",
42
38
  "react-big-calendar": "^1.20.0",
43
39
  "react-dom": "^19.0.0"
@@ -62,7 +58,7 @@
62
58
  "@types/react-big-calendar": "^1.16.3",
63
59
  "@types/react-dom": "^19",
64
60
  "@vitejs/plugin-react": "^6.1.1",
65
- "@wtfalch/design": "0.21.0",
61
+ "@wtfalch/design": "0.30.0",
66
62
  "jsdom": "^30.0.1",
67
63
  "react": "^19",
68
64
  "react-big-calendar": "^1.20.0",
@@ -1,36 +0,0 @@
1
- /**
2
- * `@wtfalch/calendar/calendar/fake` — a fake transport, not a fake API.
3
- *
4
- * `fakeCalendar()` answers real JMAP over an intercepted `fetch`, the same
5
- * discipline as `@wtfalch/email/mailbox/fake`, so a story or test runs
6
- * through this package's real code — including the `expandRecurrences`,
7
- * `sendSchedulingMessages` and free/busy ACL gates — rather than a stub
8
- * (plan §7; MSG-053 acceptance criteria).
9
- */
10
- import type { CalendarClient } from '../types.ts';
11
- import { BOB, CAROL, ME, OTHER_PRINCIPALS } from './sample.ts';
12
- import type { SeedCalendar, SeedEvent, SeedPrincipal } from './sample.ts';
13
- import { FakeCalendarStore, type FakeOptions } from './store.ts';
14
- export type { CalendarClient, CalendarClientOptions } from '../types.ts';
15
- export { FakeCalendarStore };
16
- export type { FakeOptions, SeedCalendar, SeedEvent, SeedPrincipal };
17
- export { BOB, CAROL, ME, OTHER_PRINCIPALS };
18
- export type FakeCalendar = {
19
- /** A real `CalendarClient`. Everything this package exports works against
20
- * it unchanged, through the real wire code. */
21
- client: CalendarClient;
22
- /** The universe behind it, to seed more data, to drive the other side of
23
- * a scheduling exchange, or to assert on what was sent. */
24
- store: FakeCalendarStore;
25
- /** Stop intercepting. Call it when a story or a test is done; leaving it
26
- * installed leaves the fake answering for the rest of the process. */
27
- dispose: () => void;
28
- };
29
- /**
30
- * A client and the calendar universe it talks to.
31
- *
32
- * Seeded with `ME`'s two calendars (one of them recurring) unless told
33
- * otherwise, plus `BOB` and `CAROL` for the sharing and free/busy demos —
34
- * see `./sample.ts`.
35
- */
36
- export declare function fakeCalendar(options?: FakeOptions): FakeCalendar;
@@ -1,79 +0,0 @@
1
- /**
2
- * `@wtfalch/calendar/calendar/fake` — a fake transport, not a fake API.
3
- *
4
- * `fakeCalendar()` answers real JMAP over an intercepted `fetch`, the same
5
- * discipline as `@wtfalch/email/mailbox/fake`, so a story or test runs
6
- * through this package's real code — including the `expandRecurrences`,
7
- * `sendSchedulingMessages` and free/busy ACL gates — rather than a stub
8
- * (plan §7; MSG-053 acceptance criteria).
9
- */
10
- import { createCalendarClient } from "../index.js";
11
- import { BOB, CAROL, ME, OTHER_PRINCIPALS } from "./sample.js";
12
- import { FakeCalendarStore } from "./store.js";
13
- export { FakeCalendarStore };
14
- export { BOB, CAROL, ME, OTHER_PRINCIPALS };
15
- /** The origin the fake answers for. Anything else goes to the real `fetch`
16
- * untouched, mirroring `@wtfalch/email/mailbox/fake`'s own delegation
17
- * discipline. */
18
- const ORIGIN = 'https://calendar.example.com';
19
- /**
20
- * The interception, copied from `@wtfalch/email/mailbox/fake` rather than
21
- * shared with it: `jmap-jam`-style clients call the bare global `fetch` with
22
- * no way to pass another one, so the global is replaced once, by a function
23
- * that delegates anything not addressed to the fake's own origin to the real
24
- * `fetch`. A count keeps several fakes — this one and `@wtfalch/email`'s, or
25
- * two of this one in the same process — from uninstalling each other.
26
- */
27
- let installed = null;
28
- let live = 0;
29
- function install(route) {
30
- live += 1;
31
- if (installed)
32
- return;
33
- const original = globalThis.fetch;
34
- installed = original;
35
- globalThis.fetch = ((input, init) => {
36
- const answered = route(input, init);
37
- return answered ?? original(input, init);
38
- });
39
- }
40
- function uninstall() {
41
- live -= 1;
42
- if (live > 0 || !installed)
43
- return;
44
- globalThis.fetch = installed;
45
- installed = null;
46
- }
47
- /**
48
- * A client and the calendar universe it talks to.
49
- *
50
- * Seeded with `ME`'s two calendars (one of them recurring) unless told
51
- * otherwise, plus `BOB` and `CAROL` for the sharing and free/busy demos —
52
- * see `./sample.ts`.
53
- */
54
- export function fakeCalendar(options = {}) {
55
- const store = new FakeCalendarStore(options);
56
- install((input, init) => {
57
- const url = String(typeof input === 'object' && input !== null && 'url' in input
58
- ? input.url
59
- : input);
60
- if (!url.startsWith(ORIGIN))
61
- return null;
62
- return store.fetch(url, init);
63
- });
64
- const client = createCalendarClient({
65
- sessionUrl: `${ORIGIN}/.well-known/jmap`,
66
- getAccessToken: () => 'fake',
67
- });
68
- let disposed = false;
69
- return {
70
- client,
71
- store,
72
- dispose: () => {
73
- if (disposed)
74
- return;
75
- disposed = true;
76
- uninstall();
77
- },
78
- };
79
- }
@@ -1,67 +0,0 @@
1
- /**
2
- * A small, fixed calendar universe.
3
- *
4
- * `ME` is the signed-in person `fakeCalendar()` speaks for. `BOB` and `CAROL`
5
- * are never returned by `listCalendars()` — nothing in `CalendarClient` lists
6
- * someone else's own calendars — they exist only so `getAvailability` has two
7
- * principals to tell apart: one who shared a calendar with `ME` (busy periods
8
- * come back) and one who shared nothing (an empty list comes back), per
9
- * MSG-053's fourth load-bearing behaviour
10
- * (https://github.com/wtfalch/messaging/issues/145).
11
- *
12
- * `ME`'s own "Work" calendar carries the one recurring event the rules ask
13
- * for, so a month view has a whole series to draw, not just a single day.
14
- */
15
- import type { AvailabilityInclusion, CalendarEventStatus, CalendarFreeBusyStatus, CalendarRecurrenceRule, CalendarRight } from '../types.ts';
16
- export type SeedEvent = {
17
- /** Stable across every copy of the same invite — the organiser's and each
18
- * attendee's own (#137 "Scheduling"). Also used as this fake's event id,
19
- * since seed data never collides. */
20
- uid: string;
21
- title: string;
22
- description?: string;
23
- /** Minutes from the fake's fixed "now" to the event's start. Negative is
24
- * in the past. */
25
- startOffsetMinutes: number;
26
- durationMinutes: number;
27
- isAllDay?: boolean;
28
- location?: string;
29
- recurrenceRule?: CalendarRecurrenceRule;
30
- status?: CalendarEventStatus;
31
- freeBusyStatus?: CalendarFreeBusyStatus;
32
- };
33
- export type SeedCalendar = {
34
- id: string;
35
- name: string;
36
- description?: string;
37
- color?: string;
38
- isVisible?: boolean;
39
- includeInAvailability?: AvailabilityInclusion;
40
- /** Grantee accountId -> the rights this calendar's owner has given them
41
- * (#138 §1, `shareWith`). */
42
- shareWith?: Record<string, readonly CalendarRight[]>;
43
- events?: readonly SeedEvent[];
44
- };
45
- export type SeedPrincipal = {
46
- accountId: string;
47
- email: string;
48
- name?: string;
49
- calendars: readonly SeedCalendar[];
50
- };
51
- /** "Me": one plain calendar with a single event, one with a recurring weekly
52
- * series. Both visible. Personal starts shared with Bob at the quieter of
53
- * the two levels -- `mayReadFreeBusy` without `mayReadItems` -- so the
54
- * sharing dialog opens onto a real grant rather than only an empty state,
55
- * and so the level a row reads back is exercised rather than assumed. */
56
- export declare const ME: SeedPrincipal;
57
- /** Bob has shared his calendar with "me" — `mayReadItems` only, no
58
- * `mayReadFreeBusy` — because live testing found the first right alone is
59
- * what unlocks `Principal/getAvailability`; the second right changed
60
- * nothing (#145 amendment). He is also the invitee the scheduling tests
61
- * send an invite to. */
62
- export declare const BOB: SeedPrincipal;
63
- /** Carol has shared nothing. `getAvailability('carol', ...)` must come back
64
- * empty even though she has a real, confirmed event on the calendar — no
65
- * share means no data, not even an aggregated blob (#137 "Free/busy"). */
66
- export declare const CAROL: SeedPrincipal;
67
- export declare const OTHER_PRINCIPALS: readonly SeedPrincipal[];
@@ -1,116 +0,0 @@
1
- /**
2
- * A small, fixed calendar universe.
3
- *
4
- * `ME` is the signed-in person `fakeCalendar()` speaks for. `BOB` and `CAROL`
5
- * are never returned by `listCalendars()` — nothing in `CalendarClient` lists
6
- * someone else's own calendars — they exist only so `getAvailability` has two
7
- * principals to tell apart: one who shared a calendar with `ME` (busy periods
8
- * come back) and one who shared nothing (an empty list comes back), per
9
- * MSG-053's fourth load-bearing behaviour
10
- * (https://github.com/wtfalch/messaging/issues/145).
11
- *
12
- * `ME`'s own "Work" calendar carries the one recurring event the rules ask
13
- * for, so a month view has a whole series to draw, not just a single day.
14
- */
15
- /** "Me": one plain calendar with a single event, one with a recurring weekly
16
- * series. Both visible. Personal starts shared with Bob at the quieter of
17
- * the two levels -- `mayReadFreeBusy` without `mayReadItems` -- so the
18
- * sharing dialog opens onto a real grant rather than only an empty state,
19
- * and so the level a row reads back is exercised rather than assumed. */
20
- export const ME = {
21
- accountId: 'me',
22
- email: 'ada@example.com',
23
- name: 'Ada Lovelace',
24
- calendars: [
25
- {
26
- id: 'cal-personal',
27
- name: 'Personal',
28
- color: '#7c5cff',
29
- isVisible: true,
30
- shareWith: { bob: ['mayReadFreeBusy'] },
31
- events: [
32
- {
33
- uid: 'uid-coffee',
34
- title: 'Coffee with Mary',
35
- startOffsetMinutes: 26 * 60,
36
- durationMinutes: 60,
37
- location: 'The usual place',
38
- },
39
- ],
40
- },
41
- {
42
- id: 'cal-work',
43
- name: 'Work',
44
- color: '#2f6fed',
45
- isVisible: true,
46
- events: [
47
- {
48
- uid: 'uid-sync',
49
- title: 'Team sync',
50
- startOffsetMinutes: 24 * 60,
51
- durationMinutes: 30,
52
- recurrenceRule: { frequency: 'weekly', interval: 1, count: 8 },
53
- },
54
- ],
55
- },
56
- ],
57
- };
58
- /** Bob has shared his calendar with "me" — `mayReadItems` only, no
59
- * `mayReadFreeBusy` — because live testing found the first right alone is
60
- * what unlocks `Principal/getAvailability`; the second right changed
61
- * nothing (#145 amendment). He is also the invitee the scheduling tests
62
- * send an invite to. */
63
- export const BOB = {
64
- accountId: 'bob',
65
- email: 'bob@example.org',
66
- name: 'Bob',
67
- calendars: [
68
- {
69
- id: 'bob-cal',
70
- name: 'Bob',
71
- isVisible: true,
72
- shareWith: { me: ['mayReadItems'] },
73
- events: [
74
- {
75
- uid: 'uid-bob-standup',
76
- title: 'Standup',
77
- startOffsetMinutes: 25 * 60,
78
- durationMinutes: 30,
79
- status: 'confirmed',
80
- },
81
- {
82
- uid: 'uid-bob-dentist',
83
- title: 'Dentist',
84
- startOffsetMinutes: 27 * 60 + 30,
85
- durationMinutes: 60,
86
- status: 'confirmed',
87
- },
88
- ],
89
- },
90
- ],
91
- };
92
- /** Carol has shared nothing. `getAvailability('carol', ...)` must come back
93
- * empty even though she has a real, confirmed event on the calendar — no
94
- * share means no data, not even an aggregated blob (#137 "Free/busy"). */
95
- export const CAROL = {
96
- accountId: 'carol',
97
- email: 'carol@example.org',
98
- name: 'Carol',
99
- calendars: [
100
- {
101
- id: 'carol-cal',
102
- name: 'Carol',
103
- isVisible: true,
104
- events: [
105
- {
106
- uid: 'uid-carol-review',
107
- title: 'Design review',
108
- startOffsetMinutes: 26 * 60,
109
- durationMinutes: 60,
110
- status: 'confirmed',
111
- },
112
- ],
113
- },
114
- ],
115
- };
116
- export const OTHER_PRINCIPALS = [BOB, CAROL];
@@ -1,122 +0,0 @@
1
- /**
2
- * A calendar universe in memory, and the JMAP that answers questions about
3
- * it.
4
- *
5
- * **A fake transport, not a fake API.** This answers JMAP calls the same way
6
- * a running Stalwart does, so a component or a client method drawn against
7
- * this fake is drawn through exactly the code that will face a real server —
8
- * including the six load-bearing behaviours confirmed live against Stalwart
9
- * v0.16.20 (https://github.com/wtfalch/messaging/issues/145 for 1-4, issue
10
- * #17 for 5, issue #15 for 6, https://github.com/wtfalch/calendar/issues):
11
- *
12
- * 1. `CalendarEvent/query` without `expandRecurrences` returns master
13
- * events only; with it, and both `after`/`before`, dated occurrences —
14
- * and with it but no bounds, `invalidArguments`
15
- * (https://github.com/wtfalch/messaging/issues/145).
16
- * 2. An invite (`CalendarEvent/set create` with `sendSchedulingMessages`)
17
- * lands a copy straight in the invitee's own calendar. An organiser edit
18
- * (`update` with `sendSchedulingMessages`) bumps `sequence` and mirrors
19
- * the whole `participants` map onto every other copy sharing the same
20
- * `uid`. A reply from someone who is *not* this copy's organiser -- a
21
- * patch touching only one participant's
22
- * `participationStatus`/`participationComment`, `respond`'s own shape --
23
- * is different: it bumps `sequence` nowhere, and it carries only the
24
- * status, never the comment, to the other copies. The organiser sending
25
- * that identical shape on her own event is still an ordinary edit, not a
26
- * reply (T11 live capture and re-capture,
27
- * https://github.com/wtfalch/calendar/issues/11) -- and a reply against a
28
- * synthetic occurrence id is refused outright
29
- * (`"Multiple organizers found in iCalendar object"`), never silently
30
- * written into `recurrenceOverrides`.
31
- * 3. A grant written to `Calendar/set update {shareWith}` reads back on the
32
- * next `Calendar/get` (https://github.com/wtfalch/messaging/issues/145).
33
- * 4. `Principal/getAvailability` returns busy periods for a calendar shared
34
- * with at least `mayReadItems` — no second opt-in needed — and an empty
35
- * list for one shared with nothing at all.
36
- * 5. `CalendarEvent/query`'s `text` filter matches a case-insensitive
37
- * substring of either `title` or `description` in one pass, and needs no
38
- * `after`/`before` at all unless `expandRecurrences` is also set, in
39
- * which case both are still required regardless of `text`.
40
- * 6. An `alerts` map -- offset or absolute trigger, display action,
41
- * `acknowledged` -- round-trips through `CalendarEvent/set create` and
42
- * `get` unchanged (T15, issue #15). A trigger with neither `offset` nor
43
- * `when` is accepted on write but comes back with no `trigger` key at
44
- * all (T15 amendment); `CalendarEvent/set` on `alerts` replaces the
45
- * whole map, so a write that does not carry `acknowledged` forward
46
- * wipes it.
47
- *
48
- * It implements only the methods `@wtfalch/calendar` sends. Anything else
49
- * answers `unknownMethod`, which is what a real server does and what the
50
- * error path expects.
51
- *
52
- * Wire shapes below (`myRights`/`shareWith` as boolean-flag objects, the
53
- * `calendars`/`calendars:parse` capability strings, the session capability
54
- * object's field names, `recurrenceRule` singular, `calendarAddress`, the
55
- * synthetic-occurrence id carrying a `baseEventId`) are grounded in direct
56
- * evidence from #137/#138/#145 rather than guessed; the wire's own method-arg
57
- * shapes for bounds and `expandRecurrences` are accepted in more than one
58
- * place (see `firstString`) since this package's own client, built alongside
59
- * this fake rather than before it, has not settled which one it sends.
60
- */
61
- import type { SeedPrincipal } from './sample.ts';
62
- export type FakeOptions = {
63
- /** The signed-in person. */
64
- me?: SeedPrincipal;
65
- /** Other principals `getAvailability` can be asked about. */
66
- otherPrincipals?: readonly SeedPrincipal[];
67
- /** Fixed "now", so a story's dates and a test's assertions do not move
68
- * between runs — this fake never reads the real clock itself. */
69
- now?: Date;
70
- /** Milliseconds of delay on every request, for looking at a loading
71
- * state. */
72
- latency?: number;
73
- };
74
- export declare class FakeCalendarStore {
75
- #private;
76
- readonly me: SeedPrincipal;
77
- /** Every invite `CalendarEvent/set create` landed in someone else's
78
- * calendar, for a test that asserts the invite actually reached them
79
- * rather than only that the call succeeded. */
80
- readonly invitesSent: {
81
- accountId: string;
82
- eventId: string;
83
- uid: string;
84
- }[];
85
- /** Every reply that propagated a participant-status change to another
86
- * copy of the same event. */
87
- readonly repliesSent: {
88
- accountId: string;
89
- eventId: string;
90
- uid: string;
91
- }[];
92
- constructor(options?: FakeOptions);
93
- /**
94
- * The session document, as Stalwart writes it.
95
- *
96
- * **Every seeded principal is listed in `accounts`, not only `me`**
97
- * (wtfalch/calendar#65): this fake never inspects the bearer token a
98
- * caller actually presents (it is a fake calendar universe, not an auth
99
- * simulator), so it cannot tell "the signed-in browser session" apart from
100
- * "a service credential minted for someone else's account" the way a real
101
- * Stalwart would -- a real server's session document lists only the
102
- * account(s) the presented credential can reach. Listing every seeded
103
- * account here is the honest reflection of that: this fake would answer
104
- * *some* session document for a service credential regardless of whose
105
- * account it names, so it answers one where that account is actually
106
- * there, rather than failing every service-credential test on a check this
107
- * fake has no way to enforce for real. `primaryAccounts` still names `me`
108
- * -- unrelated to whether another account is reachable by naming it
109
- * explicitly via `CalendarClientOptions.accountId`, the same way a real
110
- * session's own primary account says nothing about which other accounts
111
- * the credential can also reach.
112
- */
113
- session(origin: string): Record<string, unknown>;
114
- /** Answer one method call. Exported for the transport, and for a test that
115
- * wants to drive one side of a scheduling exchange directly — the
116
- * invitee's reply, in particular, since `fakeCalendar()` only ever hands
117
- * back one `CalendarClient`, for the organiser. */
118
- call(method: string, args: Record<string, unknown>): Record<string, unknown>;
119
- /** A `fetch` that answers this calendar universe. Hand it to whatever the
120
- * package's client is built on. */
121
- fetch: (input: unknown, init?: RequestInit) => Promise<Response>;
122
- }