/** * Minimal CalDAV client over an injectable HTTP transport. * * Scope * ───── * - Principal discovery (PROPFIND `current-user-principal`) * - Calendar home discovery (PROPFIND `calendar-home-set`) * - Calendar collection listing (PROPFIND Depth 1, filtered to `calendar` * resourcetypes) * - Event listing via `calendar-query` REPORT with a VEVENT time-range * filter * - `discover()`, a convenience that chains all three discovery steps * * Every method returns a typed, discriminated result, `{ ok: true, ... }` * or `{ ok: false, problem, fix }`, instead of throwing on HTTP-level or * protocol-level failure. Exceptions are reserved for programmer error * (e.g. passing a non-URL string where a URL is required is still handled * defensively below rather than thrown, since a live server address is * exactly the kind of input that can be malformed). * * Credentials are never included in a returned value, an error message, or * a log line anywhere in this module, failures are described in plain * language keyed off the HTTP status code only. * * Transport injection * ──────────────────── * All I/O goes through `CalDavHttpPort`, injected at construction. The only * place real network I/O happens is `createFetchCalDavHttpPort()` below, * which wraps the global `fetch`. Tests supply a fake port (or drive the * real fetch-backed port against an in-process HTTP server). */ import { type CalDavEventRecord } from './caldav-parse.js'; export interface CalDavHttpResponse { readonly status: number; readonly headers: Readonly>; readonly body: string; } export interface CalDavHttpRequest { readonly method: string; readonly url: string; readonly headers: Readonly>; readonly body?: string; } export interface CalDavHttpPort { request(input: CalDavHttpRequest): Promise; } export type CalDavAuth = { readonly kind: 'basic'; readonly username: string; readonly password: string; } | { readonly kind: 'bearer'; readonly accessToken: string; }; /** A plain-language, credential-free failure: what went wrong and what to do about it. */ export interface CalDavProblem { readonly problem: string; readonly fix: string; } export type CalDavResult = ({ readonly ok: true; } & T) | ({ readonly ok: false; } & CalDavProblem); export interface CalDavCalendar { readonly href: string; readonly displayName: string; readonly etag?: string; } export interface CalDavListedEvent extends CalDavEventRecord { readonly href: string; readonly etag?: string; } export interface CalDavClientOptions { readonly http: CalDavHttpPort; readonly auth: CalDavAuth; } export declare class CalDavClient { private readonly http; private readonly auth; constructor(options: CalDavClientOptions); /** PROPFIND Depth 0 for `current-user-principal`. */ discoverPrincipal(baseUrl: string): Promise>; /** PROPFIND Depth 0 for `calendar-home-set`. */ discoverCalendarHome(principalUrl: string): Promise>; /** PROPFIND Depth 1, returning collections whose resourcetype includes `calendar`. */ listCalendars(homeUrl: string): Promise>; /** `calendar-query` REPORT with a VEVENT time-range filter. */ listEvents(calendarUrl: string, range: { readonly start: Date; readonly end: Date; }): Promise>; /** Convenience: principal → calendar home → calendars, in one call. */ discover(baseUrl: string): Promise>; /** * Sends one PROPFIND/REPORT request and classifies the outcome. Returns * `{ ok: true, body }` on a CalDAV-successful response, or a * `{ ok: false, problem, fix }` result for both transport failures (the * request never completed) and HTTP-level failures (it completed with a * non-2xx/207 status), the caller never has to distinguish the two. */ private send; } //# sourceMappingURL=caldav-client.d.ts.map