@wtfalch/calendar 0.1.0 → 0.3.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/README.md +4 -0
- package/dist/calendar/calendar-client.js +574 -19
- package/dist/calendar/calendar.css +13 -0
- package/dist/calendar/client.d.ts +27 -0
- package/dist/calendar/client.js +101 -0
- package/dist/calendar/fake/sample.d.ts +2 -1
- package/dist/calendar/fake/store.d.ts +51 -8
- package/dist/calendar/fake/store.js +539 -47
- package/dist/calendar/find-time.d.ts +17 -0
- package/dist/calendar/find-time.js +198 -0
- package/dist/calendar/ics.d.ts +73 -0
- package/dist/calendar/ics.js +586 -0
- package/dist/calendar/index.d.ts +3 -1
- package/dist/calendar/index.js +1 -0
- package/dist/calendar/react/Calendar.js +36 -27
- package/dist/calendar/react/EventDetail.js +22 -1
- package/dist/calendar/react/EventEditor.js +65 -3
- package/dist/calendar/types.d.ts +550 -17
- package/dist/calendar/wire.d.ts +161 -5
- package/dist/calendar/wire.js +304 -4
- package/package.json +2 -2
|
@@ -373,6 +373,19 @@
|
|
|
373
373
|
font-size: var(--text-xs);
|
|
374
374
|
}
|
|
375
375
|
|
|
376
|
+
/* The weekly recurrence picker's seven day tiles (wtfalch/calendar#30), a row
|
|
377
|
+
rather than `Checkbox`'s own default full-width stack -- seven full-width
|
|
378
|
+
rows for "which day" would dwarf every other field in the form. */
|
|
379
|
+
.wtcal-weekdays {
|
|
380
|
+
display: flex;
|
|
381
|
+
flex-wrap: wrap;
|
|
382
|
+
gap: var(--space-2);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
.wtcal-weekdays > * {
|
|
386
|
+
flex: 1 1 3rem;
|
|
387
|
+
}
|
|
388
|
+
|
|
376
389
|
/* The recurring-scope question. Both answers are full-width buttons of equal
|
|
377
390
|
width: this screen exists because there is no safe default, and burying one
|
|
378
391
|
answer would invent one. */
|
|
@@ -23,6 +23,7 @@
|
|
|
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
|
*/
|
|
26
|
+
import { CalendarError } from './types.ts';
|
|
26
27
|
export declare const CALENDAR_CAPABILITY = "urn:ietf:params:jmap:calendars";
|
|
27
28
|
export declare const CORE_CAPABILITY = "urn:ietf:params:jmap:core";
|
|
28
29
|
export type CalendarConnectionOptions = {
|
|
@@ -69,6 +70,32 @@ export declare class CalendarConnection {
|
|
|
69
70
|
* token every time (see the class doc comment).
|
|
70
71
|
*/
|
|
71
72
|
request<A extends object, R>(method: string, args: A): Promise<R>;
|
|
73
|
+
/**
|
|
74
|
+
* Several JMAP method calls in one HTTP request — RFC 8620 §3.3 batches
|
|
75
|
+
* method calls into one `methodCalls` array by design, and
|
|
76
|
+
* `Principal/getAvailability` batches exactly like every other JMAP
|
|
77
|
+
* method. Split into as many requests as `#maxCallsInRequest` demands
|
|
78
|
+
* (one call list that fits is one request; findTime's many-principal read
|
|
79
|
+
* is the caller that first needed more than 16 — issue #13) and merged
|
|
80
|
+
* back into one result map, so a caller never has to know the split
|
|
81
|
+
* happened at all.
|
|
82
|
+
*
|
|
83
|
+
* Each call's outcome is keyed by its own id and is either `{data}` or
|
|
84
|
+
* `{error}` — one principal being refused must not take the rest of the
|
|
85
|
+
* batch down with it. A transport-level failure (the request never
|
|
86
|
+
* reached the server, or the server refused a whole chunk's envelope)
|
|
87
|
+
* still throws, the same as `request` does: that is a real outage, not
|
|
88
|
+
* "this one principal cannot be seen."
|
|
89
|
+
*/
|
|
90
|
+
requestMany(calls: readonly {
|
|
91
|
+
id: string;
|
|
92
|
+
method: string;
|
|
93
|
+
args: Record<string, unknown>;
|
|
94
|
+
}[]): Promise<Map<string, {
|
|
95
|
+
data: unknown;
|
|
96
|
+
} | {
|
|
97
|
+
error: CalendarError;
|
|
98
|
+
}>>;
|
|
72
99
|
/** The event source URL for `subscribe`, with its template expanded. */
|
|
73
100
|
eventSourceUrl(options: {
|
|
74
101
|
types: string;
|
package/dist/calendar/client.js
CHANGED
|
@@ -210,6 +210,107 @@ export class CalendarConnection {
|
|
|
210
210
|
}
|
|
211
211
|
return data;
|
|
212
212
|
}
|
|
213
|
+
/**
|
|
214
|
+
* The largest `methodCalls` a session says it will accept, or 16 when it
|
|
215
|
+
* says nothing. Sending more than this in one request is not throttled or
|
|
216
|
+
* partially honoured — the *whole* request is refused, before any call in
|
|
217
|
+
* it runs, with an RFC 8620 §3.6.1 problem document. Measured live for
|
|
218
|
+
* issue #13: the shared campaign Stalwart advertises
|
|
219
|
+
* `urn:ietf:params:jmap:core.maxCallsInRequest: 16`, and a 17-call
|
|
220
|
+
* `Principal/getAvailability` batch against it answers HTTP 400,
|
|
221
|
+
* `{type: "urn:ietf:params:jmap:error:limit", detail: "The request
|
|
222
|
+
* exceeds the maximum number of calls in a single request.", limit:
|
|
223
|
+
* "maxCallsInRequest"}` — pinned verbatim in
|
|
224
|
+
* `test/wire-live-transcript.test.ts`. 16 is also RFC 8620 §3.6's own
|
|
225
|
+
* suggested minimum a server must support, so it is the one number safe to
|
|
226
|
+
* assume when a session is silent about it.
|
|
227
|
+
*/
|
|
228
|
+
async #maxCallsInRequest() {
|
|
229
|
+
const { doc } = await this.#negotiate();
|
|
230
|
+
const raw = doc.capabilities?.[CORE_CAPABILITY]?.maxCallsInRequest;
|
|
231
|
+
return typeof raw === 'number' && raw > 0 ? raw : 16;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Several JMAP method calls in one HTTP request — RFC 8620 §3.3 batches
|
|
235
|
+
* method calls into one `methodCalls` array by design, and
|
|
236
|
+
* `Principal/getAvailability` batches exactly like every other JMAP
|
|
237
|
+
* method. Split into as many requests as `#maxCallsInRequest` demands
|
|
238
|
+
* (one call list that fits is one request; findTime's many-principal read
|
|
239
|
+
* is the caller that first needed more than 16 — issue #13) and merged
|
|
240
|
+
* back into one result map, so a caller never has to know the split
|
|
241
|
+
* happened at all.
|
|
242
|
+
*
|
|
243
|
+
* Each call's outcome is keyed by its own id and is either `{data}` or
|
|
244
|
+
* `{error}` — one principal being refused must not take the rest of the
|
|
245
|
+
* batch down with it. A transport-level failure (the request never
|
|
246
|
+
* reached the server, or the server refused a whole chunk's envelope)
|
|
247
|
+
* still throws, the same as `request` does: that is a real outage, not
|
|
248
|
+
* "this one principal cannot be seen."
|
|
249
|
+
*/
|
|
250
|
+
async requestMany(calls) {
|
|
251
|
+
const chunkSize = await this.#maxCallsInRequest();
|
|
252
|
+
const results = new Map();
|
|
253
|
+
for (let start = 0; start < calls.length; start += chunkSize) {
|
|
254
|
+
const chunk = calls.slice(start, start + chunkSize);
|
|
255
|
+
for (const [id, outcome] of await this.#postBatch(chunk))
|
|
256
|
+
results.set(id, outcome);
|
|
257
|
+
}
|
|
258
|
+
return results;
|
|
259
|
+
}
|
|
260
|
+
/** One HTTP request carrying `calls` verbatim — `requestMany`'s own chunk
|
|
261
|
+
* size is what keeps this under the server's `maxCallsInRequest`; this
|
|
262
|
+
* method does not check it again. */
|
|
263
|
+
async #postBatch(calls) {
|
|
264
|
+
const { doc } = await this.#negotiate();
|
|
265
|
+
const using = await this.#using();
|
|
266
|
+
const token = await this.#getAccessToken();
|
|
267
|
+
let response;
|
|
268
|
+
try {
|
|
269
|
+
response = await fetch(doc.apiUrl, {
|
|
270
|
+
method: 'POST',
|
|
271
|
+
headers: {
|
|
272
|
+
Authorization: `Bearer ${token}`,
|
|
273
|
+
'Content-Type': 'application/json',
|
|
274
|
+
Accept: 'application/json',
|
|
275
|
+
},
|
|
276
|
+
body: JSON.stringify({
|
|
277
|
+
using,
|
|
278
|
+
methodCalls: calls.map(({ method, args, id }) => [method, args, id]),
|
|
279
|
+
}),
|
|
280
|
+
...NO_BROWSER_CREDENTIALS,
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
catch (cause) {
|
|
284
|
+
throw new CalendarError(`could not reach ${doc.apiUrl}`, { operation: 'batch', cause });
|
|
285
|
+
}
|
|
286
|
+
if (response.status === 401 || response.status === 403) {
|
|
287
|
+
// Not just the token: the negotiated session itself may be stale.
|
|
288
|
+
this.#negotiation = undefined;
|
|
289
|
+
throw new CalendarError(`the server rejected the credential for a batched request (${response.status})`, { status: response.status, operation: 'batch' });
|
|
290
|
+
}
|
|
291
|
+
if (!response.ok) {
|
|
292
|
+
throw new CalendarError(`batched request failed with ${response.status}`, {
|
|
293
|
+
status: response.status,
|
|
294
|
+
operation: 'batch',
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
let body;
|
|
298
|
+
try {
|
|
299
|
+
body = await response.json();
|
|
300
|
+
}
|
|
301
|
+
catch (cause) {
|
|
302
|
+
throw new CalendarError('batched request did not answer with JSON', {
|
|
303
|
+
status: response.status,
|
|
304
|
+
operation: 'batch',
|
|
305
|
+
cause,
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
const results = new Map();
|
|
309
|
+
for (const [name, data, id] of body.methodResponses ?? []) {
|
|
310
|
+
results.set(id, name === 'error' ? { error: toCalendarError(data, id) } : { data });
|
|
311
|
+
}
|
|
312
|
+
return results;
|
|
313
|
+
}
|
|
213
314
|
/** The event source URL for `subscribe`, with its template expanded. */
|
|
214
315
|
async eventSourceUrl(options) {
|
|
215
316
|
const { doc } = await this.#negotiate();
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* `ME`'s own "Work" calendar carries the one recurring event the rules ask
|
|
13
13
|
* for, so a month view has a whole series to draw, not just a single day.
|
|
14
14
|
*/
|
|
15
|
-
import type { AvailabilityInclusion, CalendarEventStatus, CalendarRecurrenceRule, CalendarRight } from '../types.ts';
|
|
15
|
+
import type { AvailabilityInclusion, CalendarEventStatus, CalendarFreeBusyStatus, CalendarRecurrenceRule, CalendarRight } from '../types.ts';
|
|
16
16
|
export type SeedEvent = {
|
|
17
17
|
/** Stable across every copy of the same invite — the organiser's and each
|
|
18
18
|
* attendee's own (#137 "Scheduling"). Also used as this fake's event id,
|
|
@@ -28,6 +28,7 @@ export type SeedEvent = {
|
|
|
28
28
|
location?: string;
|
|
29
29
|
recurrenceRule?: CalendarRecurrenceRule;
|
|
30
30
|
status?: CalendarEventStatus;
|
|
31
|
+
freeBusyStatus?: CalendarFreeBusyStatus;
|
|
31
32
|
};
|
|
32
33
|
export type SeedCalendar = {
|
|
33
34
|
id: string;
|
|
@@ -5,21 +5,45 @@
|
|
|
5
5
|
* **A fake transport, not a fake API.** This answers JMAP calls the same way
|
|
6
6
|
* a running Stalwart does, so a component or a client method drawn against
|
|
7
7
|
* this fake is drawn through exactly the code that will face a real server —
|
|
8
|
-
* including the
|
|
9
|
-
* v0.16.20 (https://github.com/wtfalch/messaging/issues/145
|
|
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):
|
|
10
11
|
*
|
|
11
12
|
* 1. `CalendarEvent/query` without `expandRecurrences` returns master
|
|
12
13
|
* events only; with it, and both `after`/`before`, dated occurrences —
|
|
13
|
-
* and with it but no bounds, `invalidArguments
|
|
14
|
+
* and with it but no bounds, `invalidArguments`
|
|
15
|
+
* (https://github.com/wtfalch/messaging/issues/145).
|
|
14
16
|
* 2. An invite (`CalendarEvent/set create` with `sendSchedulingMessages`)
|
|
15
|
-
* lands a copy straight in the invitee's own calendar
|
|
16
|
-
*
|
|
17
|
-
*
|
|
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`.
|
|
18
31
|
* 3. A grant written to `Calendar/set update {shareWith}` reads back on the
|
|
19
|
-
* next `Calendar/get
|
|
32
|
+
* next `Calendar/get` (https://github.com/wtfalch/messaging/issues/145).
|
|
20
33
|
* 4. `Principal/getAvailability` returns busy periods for a calendar shared
|
|
21
34
|
* with at least `mayReadItems` — no second opt-in needed — and an empty
|
|
22
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.
|
|
23
47
|
*
|
|
24
48
|
* It implements only the methods `@wtfalch/calendar` sends. Anything else
|
|
25
49
|
* answers `unknownMethod`, which is what a real server does and what the
|
|
@@ -66,7 +90,26 @@ export declare class FakeCalendarStore {
|
|
|
66
90
|
uid: string;
|
|
67
91
|
}[];
|
|
68
92
|
constructor(options?: FakeOptions);
|
|
69
|
-
/**
|
|
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
|
+
*/
|
|
70
113
|
session(origin: string): Record<string, unknown>;
|
|
71
114
|
/** Answer one method call. Exported for the transport, and for a test that
|
|
72
115
|
* wants to drive one side of a scheduling exchange directly — the
|