@mildshield14/ical-booker
Version:
A lightweight, modern CalDAV client for Node.js - discover calendars, check availability, and create bookings
33 lines • 950 B
JavaScript
import fetch from 'node-fetch';
export function basicAuth({ username, password }) {
return `Basic ${Buffer.from(`${username}:${password}`).toString('base64')}`;
}
export async function propfind(url, body, creds, depth = '0') {
const r = await fetch(url, {
method: 'PROPFIND',
headers: {
Authorization: basicAuth(creds),
'Content-Type': 'application/xml',
Depth: depth,
},
body,
});
if (!r.ok)
throw new Error(`${url} → ${r.status}`);
return r.text();
}
export async function report(url, body, creds) {
const r = await fetch(url, {
method: 'REPORT',
headers: {
Authorization: basicAuth(creds),
Depth: '1',
'Content-Type': 'application/xml',
},
body,
});
if (!r.ok)
throw new Error(`${url} → ${r.status}`);
return r.text();
}
//# sourceMappingURL=caldav.js.map