tsdav
Version:
WebDAV, CALDAV, and CARDDAV client for Nodejs and the Browser
7 lines • 40.5 kB
JavaScript
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,n)=>{let r={};for(var i in e)t(r,i,{get:e[i],enumerable:!0});return n||t(r,Symbol.toStringTag,{value:`Module`}),r},s=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},c=(n,r,a)=>(a=n==null?{}:e(i(n)),s(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let l=require("debug");l=c(l);let u=require("xml-js");u=c(u);let d=function(e){return e.CALENDAR_SERVER=`http://calendarserver.org/ns/`,e.CALDAV_APPLE=`http://apple.com/ns/ical/`,e.CALDAV=`urn:ietf:params:xml:ns:caldav`,e.CARDDAV=`urn:ietf:params:xml:ns:carddav`,e.DAV=`DAV:`,e}({});const f={"urn:ietf:params:xml:ns:caldav":`xmlns:c`,"urn:ietf:params:xml:ns:carddav":`xmlns:card`,"http://calendarserver.org/ns/":`xmlns:cs`,"http://apple.com/ns/ical/":`xmlns:ca`,"DAV:":`xmlns:d`};let p=function(e){return e.CALDAV=`c`,e.CARDDAV=`card`,e.CALENDAR_SERVER=`cs`,e.CALDAV_APPLE=`ca`,e.DAV=`d`,e}({}),m=function(e){return e.VEVENT=`VEVENT`,e.VTODO=`VTODO`,e.VJOURNAL=`VJOURNAL`,e.VFREEBUSY=`VFREEBUSY`,e.VTIMEZONE=`VTIMEZONE`,e.VALARM=`VALARM`,e}({});const h=e=>e.replace(/[-_]+(\w?)/g,(e,t)=>t?t.toUpperCase():``),g=typeof globalThis<`u`&&typeof globalThis.fetch==`function`?globalThis.fetch.bind(globalThis):(()=>{throw Error("tsdav: global fetch is not available in this runtime. Upgrade to Node.js >= 18, run under a browser/Bun/Deno, or install a fetch polyfill on globalThis before importing tsdav. You can also pass a custom `fetch` implementation to `createDAVClient`, `DAVClient`, or individual request helpers.")}),_=/^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$/,ee=e=>{if(typeof e!=`string`)return e;if(_.test(e)){let t=Number(e);if(!Number.isNaN(t)&&Number.isFinite(t)&&(!Number.isInteger(t)||Number.isSafeInteger(t)))return t}let t=e.toLowerCase();return t===`true`||t!==`false`&&e};var te=o({cleanupFalsy:()=>C,conditionalParam:()=>ne,excludeHeaders:()=>w,getDAVAttribute:()=>S,mergeHeaders:()=>T,urlContains:()=>b,urlEquals:()=>y,urlMatches:()=>x});const v=e=>{let t=e.trim();return t.endsWith(`/`)?t.slice(0,-1):t},y=(e,t)=>!e&&!t?!0:!e||!t?!1:v(e)===v(t),b=(e,t)=>{if(!e&&!t)return!0;if(!e||!t)return!1;let n=v(e),r=v(t);return n.includes(r)||r.includes(n)},x=(e,t,n)=>{if(!e||!t||!n)return y(e,t);try{return y(new URL(e,n).href,new URL(t,n).href)}catch{return y(e,t)}},S=e=>e.reduce((e,t)=>({...e,[f[t]]:t}),{}),C=e=>Object.entries(e).reduce((e,[t,n])=>n?{...e,[t]:n}:e,{}),ne=(e,t)=>t?{[e]:t}:{},w=(e,t)=>{if(!e)return{};if(!t||t.length===0)return e;let n=new Set(t.map(e=>e.toLowerCase()));return Object.fromEntries(Object.entries(e).filter(([e])=>!n.has(e.toLowerCase())))},T=(...e)=>{let t=new Map,n=(e,n)=>{t.set(e.toLowerCase(),[e,n])};for(let t of e)if(t){if(Array.isArray(t)){for(let[e,r]of t)n(e,r);continue}if(typeof t.forEach==`function`){t.forEach((e,t)=>{n(t,e)});continue}for(let[e,r]of Object.entries(t))n(e,r)}return Object.fromEntries(t.values())};var re=o({createObject:()=>O,davRequest:()=>E,deleteObject:()=>A,propfind:()=>D,updateObject:()=>k});const ie=(0,l.default)(`tsdav:request`),ae=e=>{let t=/^\S+\s(?<status>\d+)\s(?<statusText>.+)$/.exec(e??``),n=t?.groups?.status,r=t?.groups?.statusText;return n&&r?{status:Number.parseInt(n,10),statusText:r}:void 0},E=async e=>{let{url:t,init:n,convertIncoming:r=!0,parseOutgoing:i=!0,fetchOptions:a={},fetch:o}=e,s=o??g,{headers:c={},body:l,namespace:d,method:f,attributes:p}=n,m=r&&l!=null?u.default.js2xml({_declaration:{_attributes:{version:`1.0`,encoding:`utf-8`}},_attributes:p,...l},{compact:!0,spaces:2,elementNameFn:e=>d&&!/^.+:.+/.test(e)?`${d}:${e}`:e}):l,_={...a};delete _.headers;let te=T({"Content-Type":`text/xml;charset=UTF-8`},C(c),a.headers),v=await s(t,{..._,headers:te,body:m,method:f}),y=await v.text();if(!v.ok||!v.headers.get(`content-type`)?.toLowerCase().includes(`xml`)||!i||!y){let e=4096,t=y.length>e?`${y.slice(0,e)}…`:y;return[{href:v.url,ok:v.ok,status:v.status,statusText:v.statusText,raw:t}]}let b;try{b=u.default.xml2js(y,{compact:!0,trim:!0,textFn:(e,t)=>{try{let n=t._parent,r=Object.keys(n),i=r[r.length-1];if(!i)return;let a=n[i];if(a.length>0){let t=a,n=a.length-1;t[n]=ee(e)}else n[i]=ee(e)}catch(e){ie(e.stack)}},elementNameFn:e=>h(e.replace(/^.+:/,``)),attributesFn:e=>{let t={...e};return delete t.xmlns,t},ignoreDeclaration:!0})}catch(e){return ie(`Failed to parse DAV response XML: ${e.message}`),[{href:v.url,ok:v.ok,status:v.status,statusText:v.statusText,raw:y}]}return b?.multistatus?(Array.isArray(b.multistatus.response)?b.multistatus.response:[b.multistatus.response]).map(e=>{if(!e)return{status:v.status,statusText:v.statusText,ok:v.ok};let t=ae(e.status),n=t?.status??v.status;return{raw:b,href:e.href,status:n,statusText:t?.statusText??v.statusText,ok:n>=200&&n<300,error:e.error,responsedescription:e.responsedescription,props:(Array.isArray(e.propstat)?e.propstat:[e.propstat]).reduce((e,t)=>{let n=ae(t?.status)?.status;return n&&(n<200||n>=300)?e:{...e,...t?.prop}},{})}}):[{href:v.url,ok:v.ok,status:v.status,statusText:v.statusText,raw:b}]},D=async e=>{let{url:t,props:n,depth:r,headers:i,headersToExclude:a,fetchOptions:o={},fetch:s}=e;return E({url:t,init:{method:`PROPFIND`,headers:w(C({depth:r,...i}),a),namespace:`d`,body:{propfind:{_attributes:S([`urn:ietf:params:xml:ns:caldav`,`http://apple.com/ns/ical/`,`http://calendarserver.org/ns/`,`urn:ietf:params:xml:ns:carddav`,`DAV:`]),prop:n}}},fetchOptions:o,fetch:s})},O=async e=>{let{url:t,data:n,headers:r,headersToExclude:i,fetchOptions:a={},fetch:o}=e,s=o??g,{headers:c,...l}=a;return s(t,{...l,method:`PUT`,body:n,headers:w(T(r,c),i)})},k=async e=>{let{url:t,data:n,etag:r,headers:i,headersToExclude:a,fetchOptions:o={},fetch:s}=e,c=s??g,{headers:l,...u}=o;return c(t,{...u,method:`PUT`,body:n,headers:w(T(C({"If-Match":r,...i}),l),a)})},A=async e=>{let{url:t,headers:n,etag:r,headersToExclude:i,fetchOptions:a={},fetch:o}=e,s=o??g,{headers:c,...l}=a;return s(t,{...l,method:`DELETE`,headers:w(T(C({"If-Match":r,...n}),c),i)})};function j(e,t){let n=e=>t.every(t=>e[t]);return Array.isArray(e)?e.every(e=>n(e)):n(e)}const M=(e,t)=>t.reduce((t,n)=>e[n]?t:`${t.length?`${t},`:``}${n.toString()}`,``);var oe=o({collectionQuery:()=>N,isCollectionDirty:()=>F,makeCollection:()=>ue,smartCollectionSync:()=>L,smartCollectionSyncDetailed:()=>de,supportedReportSet:()=>P,syncCollection:()=>I});const se=(0,l.default)(`tsdav:collection`),ce=(e,t)=>{try{return new URL(e,t).href}catch{return e}},le=(e,t,n)=>{try{return new URL(e,n).pathname.toLowerCase().endsWith(t)}catch{return(e.split(/[?#]/,1)[0]??``).toLowerCase().endsWith(t)}},N=async e=>{let{url:t,body:n,depth:r,defaultNamespace:i=`d`,headers:a,headersToExclude:o,fetchOptions:s={},fetch:c}=e,l=await E({url:t,init:{method:`REPORT`,headers:w(C({depth:r,...a}),o),namespace:i,body:n},fetchOptions:s,fetch:c}),u=l.find(e=>!e.ok||e.status&&e.status>=400);if(u)throw Error(`Collection query failed: ${u.status} ${u.statusText}. ${u.raw?`Raw response: ${u.raw}`:``}`);let d=l[0];return l.length===1&&d&&!d.raw&&d.status&&d.status<300?[]:l},ue=async e=>{let{url:t,props:n,depth:r,headers:i,headersToExclude:a,fetchOptions:o={},fetch:s}=e;return E({url:t,init:{method:`MKCOL`,headers:w(C({depth:r,...i}),a),namespace:`d`,body:n?{mkcol:{set:{prop:n}}}:void 0},fetchOptions:o,fetch:s})},P=async e=>{let{collection:t,headers:n,headersToExclude:r,fetchOptions:i={},fetch:a}=e,o=(await D({url:t.url,props:{"d:supported-report-set":{}},depth:`0`,headers:w(n,r),fetchOptions:i,fetch:a}))[0]?.props?.supportedReportSet?.supportedReport;return o?(Array.isArray(o)?o:[o]).map(e=>e?.report?Object.keys(e.report)[0]:void 0).filter(e=>typeof e==`string`&&e.length>0):[]},F=async e=>{let{collection:t,headers:n,headersToExclude:r,fetchOptions:i={},fetch:a}=e,o=(await D({url:t.url,props:{"cs:getctag":{}},depth:`0`,headers:w(n,r),fetchOptions:i,fetch:a})).find(e=>x(t.url,e.href,t.url));if(!o)throw Error(`Collection does not exist on server`);if(!o.ok)throw Error(`Collection status check failed: ${o.status} ${o.statusText}`);let s=o.props?.getctag;return{isDirty:t.ctag==null||s==null||`${t.ctag}`!=`${s}`,newCtag:s?.toString()}},I=e=>{let{url:t,props:n,headers:r,syncLevel:i,syncToken:a,headersToExclude:o,fetchOptions:s,fetch:c}=e;return E({url:t,init:{method:`REPORT`,namespace:`d`,headers:w({...r},o),body:{"sync-collection":{_attributes:S([`urn:ietf:params:xml:ns:caldav`,`urn:ietf:params:xml:ns:carddav`,`DAV:`]),"sync-level":i,"sync-token":a,"d:prop":n}}},fetchOptions:s,fetch:c})},L=async e=>{let{collection:t,method:n,headers:r,headersToExclude:i,account:a,detailedResult:o,fetchOptions:s={},fetch:c}=e,l=[`accountType`,`homeUrl`];if(!a||!j(a,l))throw Error(a?`account must have ${M(a,l)} before smartCollectionSync`:`no account for smartCollectionSync`);let u=n??(t.reports?.includes(`syncCollection`)?`webdav`:`basic`);if(se(`smart collection sync with type ${a.accountType} and method ${u}`),u===`webdav`){let e=await I({url:t.url,props:{"d:getetag":{},[`${a.accountType===`caldav`?`c`:`card`}:${a.accountType===`caldav`?`calendar-data`:`address-data`}`]:{},"d:displayname":{}},syncLevel:1,syncToken:t.syncToken,headers:w(r,i),fetchOptions:s,fetch:c}),n=e.filter(e=>{let n=a.accountType===`caldav`?`.ics`:`.vcf`;return typeof e.href==`string`&&le(e.href,n,t.url)}),l=n.filter(e=>e.status!==404).map(e=>e.href),u=n.filter(e=>e.status===404).map(e=>e.href),d=t.objectMultiGet;if(l.length>0&&!d)throw Error(`collection.objectMultiGet is required for webdav sync changes`);let f=(l.length?await d?.({url:t.url,props:{"d:getetag":{},[`${a.accountType===`caldav`?`c`:`card`}:${a.accountType===`caldav`?`calendar-data`:`address-data`}`]:{}},objectUrls:l,depth:`1`,headers:w(r,i),fetchOptions:s,fetch:c})??[]:[]).map(e=>({url:ce(e.href??``,t.url),etag:e.props?.getetag==null?void 0:String(e.props.getetag),data:a?.accountType===`caldav`?e.props?.calendarData?._cdata??e.props?.calendarData:e.props?.addressData?._cdata??e.props?.addressData})),p=t.objects??[],m=f.filter(e=>p.every(n=>!x(n.url,e.url,t.url))),h=p.reduce((e,n)=>{let r=f.find(e=>x(e.url,n.url,t.url));return r&&r.etag&&r.etag!==n.etag?[...e,r]:e},[]),g=u.map(e=>({url:ce(e,t.url),etag:``})),_=p.filter(e=>g.every(n=>!x(e.url,n.url,t.url))&&h.every(n=>!x(e.url,n.url,t.url)));return{...t,objects:o?{created:m,updated:h,deleted:g}:[..._,...m,...h],syncToken:e[0]?.raw?.multistatus?.syncToken??t.syncToken}}if(u===`basic`){let{isDirty:e,newCtag:n}=await F({collection:t,headers:w(r,i),fetchOptions:s,fetch:c});if(!e)return o?{...t,objects:{created:[],updated:[],deleted:[]}}:t;let a=t.objects??[];if(!t.fetchObjects)throw Error(`collection.fetchObjects is required for basic sync changes`);let l=await t.fetchObjects({collection:t,headers:w(r,i),fetchOptions:s,fetch:c})??[],u=l.filter(e=>a.every(n=>!x(n.url,e.url,t.url))),d=a.reduce((e,n)=>{let r=l.find(e=>x(e.url,n.url,t.url));return r&&r.etag&&r.etag!==n.etag?[...e,r]:e},[]),f=a.filter(e=>l.every(n=>!x(n.url,e.url,t.url))),p=a.filter(e=>l.some(n=>x(e.url,n.url,t.url)&&n.etag===e.etag));return{...t,objects:o?{created:u,updated:d,deleted:f}:[...p,...u,...d],ctag:n}}return o?{...t,objects:{created:[],updated:[],deleted:[]}}:t},de=async e=>L({...e,detailedResult:!0});var fe=o({addressBookMultiGet:()=>z,addressBookQuery:()=>R,createVCard:()=>me,deleteVCard:()=>ge,fetchAddressBooks:()=>B,fetchVCards:()=>V,updateVCard:()=>he});const pe=(0,l.default)(`tsdav:addressBook`),R=async e=>{let{url:t,props:n,filters:r,depth:i,headers:a,headersToExclude:o,fetchOptions:s={},fetch:c}=e;return N({url:t,body:{"addressbook-query":C({_attributes:S([`urn:ietf:params:xml:ns:carddav`,`DAV:`]),"d:prop":n,filter:r??{"prop-filter":{_attributes:{name:`FN`}}}})},defaultNamespace:`card`,depth:i,headers:w(a,o),fetchOptions:s,fetch:c})},z=async e=>{let{url:t,props:n,objectUrls:r,depth:i,headers:a,headersToExclude:o,fetchOptions:s={},fetch:c}=e;return N({url:t,body:{"addressbook-multiget":C({_attributes:S([`DAV:`,`urn:ietf:params:xml:ns:carddav`]),"d:prop":n,"d:href":r})},defaultNamespace:`card`,depth:i,headers:w(a,o),fetchOptions:s,fetch:c})},B=async e=>{let{account:t,headers:n,props:r,headersToExclude:i,fetchOptions:a={},fetch:o}=e??{},s=[`homeUrl`,`rootUrl`];if(!t||!j(t,s))throw Error(t?`account must have ${M(t,s)} before fetchAddressBooks`:`no account for fetchAddressBooks`);let c=await D({url:t.homeUrl,props:r??{"d:displayname":{},"cs:getctag":{},"d:resourcetype":{},"d:sync-token":{}},depth:`1`,headers:w(n,i),fetchOptions:a,fetch:o});return Promise.all(c.filter(e=>Object.keys(e.props?.resourcetype??{}).includes(`addressbook`)).map(e=>{let n=e.props?.displayname?._cdata??e.props?.displayname;return pe(`Found address book named ${typeof n==`string`?n:``},
props: ${JSON.stringify(e.props)}`),{url:new URL(e.href??``,t.rootUrl??``).href,ctag:e.props?.getctag,displayName:typeof n==`string`?n:``,resourcetype:Object.keys(e.props?.resourcetype??{}),syncToken:e.props?.syncToken}}).map(async e=>({...e,reports:await P({collection:e,headers:w(n,i),fetchOptions:a,fetch:o})})))},V=async e=>{let{addressBook:t,headers:n,objectUrls:r,headersToExclude:i,urlFilter:a=e=>!!e,useMultiGet:o=!0,fetchOptions:s={},fetch:c}=e;pe(`Fetching vcards from ${t?.url}`);let l=[`url`];if(!t||!j(t,l))throw Error(t?`addressBook must have ${M(t,l)} before fetchVCards`:`cannot fetchVCards for undefined addressBook`);let u=(r??(await R({url:t.url,props:{"d:getetag":{}},depth:`1`,headers:w(n,i),fetchOptions:s,fetch:c})).map(e=>e.href??``)).map(e=>e.startsWith(`http`)||!e?e:new URL(e,t.url).href).filter(e=>e&&!y(e,t.url)).filter(a).map(e=>{let t=new URL(e);return`${t.pathname}${t.search}`}),d=[];return u.length>0&&(d=o?await z({url:t.url,props:{"d:getetag":{},"card:address-data":{}},objectUrls:u,depth:`1`,headers:w(n,i),fetchOptions:s,fetch:c}):await R({url:t.url,props:{"d:getetag":{},"card:address-data":{}},depth:`1`,headers:w(n,i),fetchOptions:s,fetch:c})),d.map(e=>({url:new URL(e.href??``,t.url).href,etag:e.props?.getetag==null?void 0:String(e.props.getetag),data:e.props?.addressData?._cdata??e.props?.addressData}))},me=async e=>{let{addressBook:t,vCardString:n,filename:r,headers:i,headersToExclude:a,fetchOptions:o={},fetch:s}=e;return O({url:new URL(r,t.url).href,data:n,headers:w({"content-type":`text/vcard; charset=utf-8`,"If-None-Match":`*`,...i},a),fetchOptions:o,fetch:s})},he=async e=>{let{vCard:t,headers:n,headersToExclude:r,fetchOptions:i={},fetch:a}=e;return k({url:t.url,data:t.data,etag:t.etag,headers:w({"content-type":`text/vcard; charset=utf-8`,...n},r),fetchOptions:i,fetch:a})},ge=async e=>{let{vCard:t,headers:n,headersToExclude:r,fetchOptions:i={},fetch:a}=e;return A({url:t.url,etag:t.etag,headers:w(n,r),fetchOptions:i,fetch:a})};var _e=o({calendarMultiGet:()=>W,calendarQuery:()=>U,createCalendarObject:()=>we,deleteCalendarObject:()=>Ee,fetchCalendarObjects:()=>K,fetchCalendarUserAddresses:()=>Se,fetchCalendars:()=>G,freeBusyQuery:()=>Oe,makeCalendar:()=>Ce,syncCalendars:()=>q,syncCalendarsDetailed:()=>De,updateCalendarObject:()=>Te});const H=(0,l.default)(`tsdav:calendar`),ve=/^\d{4}(-\d\d(-\d\d(T\d\d:\d\d(:\d\d)?(\.\d+)?(([+-]\d\d:\d\d)|Z)?)?)?)?$/i,ye=/^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(\.\d+)?(([+-]\d\d:\d\d)|Z)?$/i,be=e=>{let{start:t,end:n}=e;if(!(ve.test(t)&&ve.test(n)||ye.test(t)&&ye.test(n)))throw Error(`invalid timeRange format, not in ISO8601`);if(Number.isNaN(new Date(t).getTime())||Number.isNaN(new Date(n).getTime()))throw Error(`invalid timeRange: start or end is not a valid date`);if(new Date(t).getTime()>=new Date(n).getTime())throw Error(`invalid timeRange: start must be before end`)},xe=e=>{let t=[];return Array.isArray(e)?t=e.map(e=>e?._attributes?.name):e&&typeof e==`object`&&(t=[e._attributes?.name]),t.filter(e=>typeof e==`string`&&e.length>0)},Se=async e=>{let{account:t,headers:n,headersToExclude:r,fetchOptions:i={},fetch:a}=e,o=[`principalUrl`,`rootUrl`];if(!j(t,o))throw Error(`account must have ${M(t,o)} before fetchUserAddresses`);H(`Fetch user addresses from ${t.principalUrl}`);let s=(await D({url:t.principalUrl,props:{"c:calendar-user-address-set":{}},depth:`0`,headers:w(n,r),fetchOptions:i,fetch:a})).find(e=>x(t.principalUrl,e.href,t.rootUrl));if(!s||!s.ok)throw Error(`cannot find calendarUserAddresses`);let c=s?.props?.calendarUserAddressSet?.href,l=[];Array.isArray(c)?l=c:c&&(l=[c]);let u=l.filter(e=>typeof e==`string`&&e.length>0);return H(`Fetched calendar user addresses ${u}`),u},U=async e=>{let{url:t,props:n,filters:r,timezone:i,depth:a,headers:o,headersToExclude:s,fetchOptions:c={},fetch:l}=e;return N({url:t,body:{"calendar-query":C({_attributes:S([`urn:ietf:params:xml:ns:caldav`,`http://calendarserver.org/ns/`,`http://apple.com/ns/ical/`,`DAV:`]),"d:prop":n,filter:r,timezone:i})},defaultNamespace:`c`,depth:a,headers:w(o,s),fetchOptions:c,fetch:l})},W=async e=>{let{url:t,props:n,objectUrls:r,filters:i,timezone:a,depth:o,headers:s,headersToExclude:c,fetchOptions:l={},fetch:u}=e;return N({url:t,body:{"calendar-multiget":C({_attributes:S([`DAV:`,`urn:ietf:params:xml:ns:caldav`]),"d:prop":n,"d:href":r,filter:i,timezone:a})},defaultNamespace:`c`,depth:o,headers:w(s,c),fetchOptions:l,fetch:u})},Ce=async e=>{let{url:t,props:n,depth:r,headers:i,headersToExclude:a,fetchOptions:o={},fetch:s}=e;return E({url:t,init:{method:`MKCALENDAR`,headers:w(C({depth:r,...i}),a),namespace:`d`,body:{"c:mkcalendar":{_attributes:S([`DAV:`,`urn:ietf:params:xml:ns:caldav`,`http://apple.com/ns/ical/`]),set:{prop:n}}}},fetchOptions:o,fetch:s})},G=async e=>{let{headers:t,account:n,props:r,projectedProps:i,headersToExclude:a,fetchOptions:o={},fetch:s}=e??{},c=[`homeUrl`,`rootUrl`];if(!n||!j(n,c))throw Error(n?`account must have ${M(n,c)} before fetchCalendars`:`no account for fetchCalendars`);let l=await D({url:n.homeUrl,props:r??{"c:calendar-description":{},"c:calendar-timezone":{},"d:displayname":{},"ca:calendar-color":{},"cs:getctag":{},"d:resourcetype":{},"c:supported-calendar-component-set":{},"d:sync-token":{}},depth:`1`,headers:w(t,a),fetchOptions:o,fetch:s});return Promise.all(l.filter(e=>Object.keys(e.props?.resourcetype??{}).includes(`calendar`)).filter(e=>{let t=xe(e.props?.supportedCalendarComponentSet?.comp);return t.length===0||t.some(e=>Object.values(m).includes(e))}).map(e=>{let t=e.props?.calendarDescription,r=e.props?.calendarTimezone,a=e.props?.supportedCalendarComponentSet?.comp,o=Object.entries(e.props??{}).filter(([e])=>i?.[e]);return{description:typeof t==`string`?t:``,timezone:typeof r==`string`?r:``,url:new URL(e.href??``,n.rootUrl??``).href,ctag:e.props?.getctag,calendarColor:e.props?.calendarColor,displayName:e.props?.displayname?._cdata??e.props?.displayname,components:xe(a),resourcetype:Object.keys(e.props?.resourcetype??{}),syncToken:e.props?.syncToken,...i&&o.length>0?{projectedProps:Object.fromEntries(o)}:{}}}).map(async e=>({...e,reports:await P({collection:e,headers:w(t,a),fetchOptions:o,fetch:s})})))},K=async e=>{let{calendar:t,objectUrls:n,filters:r,timeRange:i,headers:a,expand:o,urlFilter:s=e=>!!e?.includes(`.ics`),useMultiGet:c=!0,headersToExclude:l,fetchOptions:u={},fetch:d}=e;i&&be(i),H(`Fetching calendar objects from ${t?.url}`);let f=[`url`];if(!t||!j(t,f))throw Error(t?`calendar must have ${M(t,f)} before fetchCalendarObjects`:`cannot fetchCalendarObjects for undefined calendar`);let p=r??[{"comp-filter":{_attributes:{name:`VCALENDAR`},"comp-filter":{_attributes:{name:`VEVENT`},...i?{"time-range":{_attributes:{start:`${new Date(i.start).toISOString().slice(0,19).replace(/[-:.]/g,``)}Z`,end:`${new Date(i.end).toISOString().slice(0,19).replace(/[-:.]/g,``)}Z`}}}:{}}}}],m=[];n||(m=await U({url:t.url,props:{"d:getetag":{},...o&&i?{"c:calendar-data":{"c:expand":{_attributes:{start:`${new Date(i.start).toISOString().slice(0,19).replace(/[-:.]/g,``)}Z`,end:`${new Date(i.end).toISOString().slice(0,19).replace(/[-:.]/g,``)}Z`}}}}:{}},filters:p,depth:`1`,headers:w(a,l),fetchOptions:u,fetch:d}));let h=(n??m.map(e=>e.href??``)).map(e=>e.startsWith(`http`)||!e?e:new URL(e,t.url).href).filter(s).map(e=>{let t=new URL(e);return`${t.pathname}${t.search}`}),g=[];return h.length>0&&(g=o&&!n?m.filter(e=>{let n=(e.href??``).startsWith(`http`)?e.href:new URL(e.href??``,t.url).href;return s(n??``)}):c?await W({url:t.url,props:{"d:getetag":{},"c:calendar-data":{...o&&i?{"c:expand":{_attributes:{start:`${new Date(i.start).toISOString().slice(0,19).replace(/[-:.]/g,``)}Z`,end:`${new Date(i.end).toISOString().slice(0,19).replace(/[-:.]/g,``)}Z`}}}:{}}},objectUrls:h,depth:`1`,headers:w(a,l),fetchOptions:u,fetch:d}):await U({url:t.url,props:{"d:getetag":{},"c:calendar-data":{...o&&i?{"c:expand":{_attributes:{start:`${new Date(i.start).toISOString().slice(0,19).replace(/[-:.]/g,``)}Z`,end:`${new Date(i.end).toISOString().slice(0,19).replace(/[-:.]/g,``)}Z`}}}:{}}},filters:p,depth:`1`,headers:w(a,l),fetchOptions:u,fetch:d})),g.map(e=>({url:new URL(e.href??``,t.url).href,etag:e.props?.getetag==null?void 0:String(e.props.getetag),data:e.props?.calendarData?._cdata??e.props?.calendarData}))},we=async e=>{let{calendar:t,iCalString:n,filename:r,headers:i,headersToExclude:a,fetchOptions:o={},fetch:s}=e;return O({url:new URL(r,t.url).href,data:n,headers:w({"content-type":`text/calendar; charset=utf-8`,"If-None-Match":`*`,...i},a),fetchOptions:o,fetch:s})},Te=async e=>{let{calendarObject:t,headers:n,headersToExclude:r,fetchOptions:i={},fetch:a}=e;return k({url:t.url,data:t.data,etag:t.etag,headers:w({"content-type":`text/calendar; charset=utf-8`,...n},r),fetchOptions:i,fetch:a})},Ee=async e=>{let{calendarObject:t,headers:n,headersToExclude:r,fetchOptions:i={},fetch:a}=e;return A({url:t.url,etag:t.etag,headers:w(n,r),fetchOptions:i,fetch:a})},q=async e=>{let{oldCalendars:t,account:n,detailedResult:r,headers:i,headersToExclude:a,fetchOptions:o={},fetch:s}=e;if(!n)throw Error(`Must have account before syncCalendars`);let c=t??n.calendars??[],l=await G({account:n,headers:w(i,a),fetchOptions:o,fetch:s}),u=l.filter(e=>c.every(t=>!x(t.url,e.url,n.rootUrl)));H(`new calendars: ${u.map(e=>e.displayName)}`);let d=c.reduce((e,t)=>{let r=l.find(e=>x(e.url,t.url,n.rootUrl));return r&&(r.syncToken&&`${r.syncToken}`!=`${t.syncToken}`||r.ctag&&`${r.ctag}`!=`${t.ctag}`)?[...e,{local:t,remote:r}]:e},[]);H(`updated calendars: ${d.map(({remote:e})=>e.displayName)}`);let f=await Promise.all(d.map(async({local:e,remote:t})=>{let r=async e=>{if(!e)return[];let{collection:t,...n}=e;return K({...n,calendar:t})},c=await L({collection:{...t,ctag:e.ctag,syncToken:e.syncToken,objects:e.objects,objectMultiGet:W,fetchObjects:r},detailedResult:!1,headers:w(i,a),account:n,fetchOptions:o,fetch:s});return{...c,ctag:t.ctag??c.ctag,syncToken:t.syncToken??c.syncToken}})),p=c.filter(e=>l.every(t=>!x(t.url,e.url,n.rootUrl)));H(`deleted calendars: ${p.map(e=>e.displayName)}`);let m=c.filter(e=>l.some(t=>{if(!x(t.url,e.url,n.rootUrl))return!1;let r=!t.syncToken||`${t.syncToken}`==`${e.syncToken}`,i=!t.ctag||`${t.ctag}`==`${e.ctag}`;return r&&i}));return H(`unchanged calendars: ${m.map(e=>e.displayName)}`),r?{created:u,updated:f,deleted:p}:[...m,...u,...f]},De=async e=>q({...e,detailedResult:!0}),Oe=async e=>{let{url:t,timeRange:n,depth:r,headers:i,headersToExclude:a,fetchOptions:o={},fetch:s}=e;if(!n)throw Error(`timeRange is required`);be(n);let c=(await N({url:t,body:{"free-busy-query":C({_attributes:S([`urn:ietf:params:xml:ns:caldav`]),"c:time-range":{_attributes:{start:`${new Date(n.start).toISOString().slice(0,19).replace(/[-:.]/g,``)}Z`,end:`${new Date(n.end).toISOString().slice(0,19).replace(/[-:.]/g,``)}Z`}}})},defaultNamespace:`c`,depth:r,headers:w(i,a),fetchOptions:o,fetch:s}))[0];if(!c)throw Error(`freeBusyQuery returned no response`);return c};var ke=o({createAccount:()=>Y,fetchHomeUrl:()=>Ne,fetchPrincipalUrl:()=>Me,serviceDiscovery:()=>je});const J=(0,l.default)(`tsdav:account`),Ae=(e,t)=>{let n=[t,e,new URL(`/`,e).href];return n.filter((e,t)=>n.indexOf(e)===t)},je=async e=>{J(`Service discovery...`);let{account:t,headers:n,headersToExclude:r,fetchOptions:i={},fetch:a}=e,o=a??g,s=new URL(t.serverUrl),{headers:c,...l}=i,u=new URL(`/.well-known/${t.accountType}`,s);u.protocol=s.protocol??`http`;let d=e=>{if(e.status>=300&&e.status<400){let t=e.headers.get(`Location`);if(typeof t==`string`&&t.length){J(`Service discovery redirected to ${t}`);let e=/^[a-z][a-z0-9+.-]*:/i.test(t),n=new URL(t,s);return n.hostname===u.hostname&&u.port&&!n.port&&(n.port=u.port),e||(n.protocol=s.protocol??`http`),n.href}}};try{let e=d(await o(u.href,{...l,method:`PROPFIND`,headers:w(T({"Content-Type":`text/xml;charset=UTF-8`},n,c),r),body:`<?xml version="1.0" encoding="utf-8" ?>
<d:propfind xmlns:d="DAV:">
<d:prop>
<d:resourcetype/>
</d:prop>
</d:propfind>`,redirect:`manual`}));if(e)return e}catch(e){J(`Service discovery PROPFIND failed: ${e.stack}`)}try{let e=d(await o(u.href,{...l,method:`GET`,headers:w(T(n,c),r),redirect:`manual`}));if(e)return e}catch(e){J(`Service discovery GET failed: ${e.stack}`)}return s.href},Me=async e=>{let{account:t,headers:n,headersToExclude:r,fetchOptions:i={},fetch:a}=e,o=[`rootUrl`];if(!j(t,o))throw Error(`account must have ${M(t,o)} before fetchPrincipalUrl`);J(`Fetching principal url from path ${t.rootUrl}`);let[s]=await D({url:t.rootUrl,props:{"d:current-user-principal":{}},depth:`0`,headers:w(n,r),fetchOptions:i,fetch:a});if(!s?.ok)throw J(`Fetch principal url failed: ${s?.statusText??`empty response`}`),s?.status===401?Error(`Invalid credentials: PROPFIND ${t.rootUrl} returned 401 Unauthorized`):Error(`cannot find principalUrl`);let c=s.props?.currentUserPrincipal?.href;if(typeof c!=`string`||!c.length)throw J(`Fetch principal url failed: missing current-user-principal href`),Error(`cannot find principalUrl`);return J(`Fetched principal url ${c}`),new URL(c,t.rootUrl).href},Ne=async e=>{let{account:t,headers:n,headersToExclude:r,fetchOptions:i={},fetch:a}=e,o=[`principalUrl`,`rootUrl`];if(!j(t,o))throw Error(`account must have ${M(t,o)} before fetchHomeUrl`);J(`Fetch home url from ${t.principalUrl}`);let s=await D({url:t.principalUrl,props:t.accountType===`caldav`?{"c:calendar-home-set":{}}:{"card:addressbook-home-set":{}},depth:`0`,headers:w(n,r),fetchOptions:i,fetch:a}),c=s.find(e=>x(t.principalUrl,e.href,t.rootUrl));if(!c||!c.ok)throw J(`Fetch home url failed with status ${c?.statusText} and error ${JSON.stringify(s.map(e=>e.error))}`),Error(`cannot find homeUrl`);let l=t.accountType===`caldav`?c.props?.calendarHomeSet?.href:c.props?.addressbookHomeSet?.href;if(typeof l!=`string`||l.length===0)throw J(`Fetch home url failed: server did not return a ${t.accountType===`caldav`?`calendar-home-set`:`addressbook-home-set`} href`),Error(`cannot find homeUrl`);let u=new URL(l,t.rootUrl).href;return J(`Fetched home url ${u}`),u},Y=async e=>{let{account:t,headers:n,loadCollections:r=!1,loadObjects:i=!1,headersToExclude:a,fetchOptions:o={},fetch:s}=e,c={...t},l=t.rootUrl??await je({account:t,headers:w(n,a),fetchOptions:o,fetch:s});if(t.rootUrl)c.rootUrl=t.rootUrl;else if(t.principalUrl)c.rootUrl=l;else{let e=async(t,r=0,i)=>{let l=t[r];if(!l)throw i??Error(`cannot find principalUrl`);try{return{rootUrl:l,principalUrl:await Me({account:{...c,rootUrl:l},headers:w(n,a),fetchOptions:o,fetch:s})}}catch(n){return e(t,r+1,n)}},{rootUrl:r,principalUrl:i}=await e(Ae(t.serverUrl,l));c.rootUrl=r,c.principalUrl=i}return c.principalUrl=t.principalUrl??c.principalUrl??await Me({account:c,headers:w(n,a),fetchOptions:o,fetch:s}),c.homeUrl=t.homeUrl??await Ne({account:c,headers:w(n,a),fetchOptions:o,fetch:s}),(r||i)&&(t.accountType===`caldav`?c.calendars=await G({headers:w(n,a),account:c,fetchOptions:o,fetch:s}):t.accountType===`carddav`&&(c.addressBooks=await B({headers:w(n,a),account:c,fetchOptions:o,fetch:s}))),i&&(t.accountType===`caldav`&&c.calendars?c.calendars=await Promise.all(c.calendars.map(async e=>({...e,objects:await K({calendar:e,headers:w(n,a),fetchOptions:o,fetch:s})}))):t.accountType===`carddav`&&c.addressBooks&&(c.addressBooks=await Promise.all(c.addressBooks.map(async e=>({...e,objects:await V({addressBook:e,headers:w(n,a),fetchOptions:o,fetch:s})}))))),c};var Pe=o({defaultParam:()=>Q,fetchOauthTokens:()=>ze,getBasicAuthHeaders:()=>$,getBearerAuthHeaders:()=>Re,getOauthHeaders:()=>Ve,refreshAccessToken:()=>Be});const X=(0,l.default)(`tsdav:authHelper`),Z=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`;var Fe=class extends Error{constructor(e){super(e),this.name=`InvalidCharacterError`}};const Ie=e=>{if(e>255)throw new Fe(`The string to be encoded contains characters outside of the Latin1 range.`)},Le=e=>{let t=``,n=0;for(;n<e.length;){let r=e.charCodeAt(n);if(n+=1,Ie(r),n===e.length){t+=Z[Math.floor(r/4)],t+=`${Z[r%4*16]}==`;break}let i=e.charCodeAt(n);if(n+=1,Ie(i),n===e.length){t+=Z[Math.floor(r/4)],t+=Z[r%4*16+Math.floor(i/16)],t+=`${Z[i%16*4]}=`;break}let a=e.charCodeAt(n);n+=1,Ie(a),t+=Z[Math.floor(r/4)],t+=Z[r%4*16+Math.floor(i/16)],t+=Z[i%16*4+Math.floor(a/64)],t+=Z[a%64]}return t},Q=(e,t)=>(...n)=>{let r=n[0],i={...t,...r};return(t.headers||r?.headers)&&(i.headers=T(t.headers,r?.headers)),e(i)},$=e=>(X(`Basic auth token generated for user "${e.username??``}"`),{authorization:`Basic ${Le(`${e.username}:${e.password}`)}`}),Re=e=>({authorization:`Bearer ${e.accessToken}`}),ze=async(e,t,n)=>{let r=[`authorizationCode`,`redirectUrl`,`clientId`,`clientSecret`,`tokenUrl`];if(!j(e,r))throw Error(`Oauth credentials missing: ${M(e,r)}`);let i=new URLSearchParams({grant_type:`authorization_code`,code:e.authorizationCode,redirect_uri:e.redirectUrl,client_id:e.clientId,client_secret:e.clientSecret});X(`Fetching oauth tokens from ${e.tokenUrl}`);let a=n??g,{headers:o,...s}=t??{},c=await a(e.tokenUrl,{...s,method:`POST`,body:i.toString(),headers:T({"content-type":`application/x-www-form-urlencoded`},o)});return c.ok?await c.json():(X(`Fetch Oauth tokens failed with status ${c.status}`),{})},Be=async(e,t,n)=>{let r=[`refreshToken`,`clientId`,`clientSecret`,`tokenUrl`];if(!j(e,r))throw Error(`Oauth credentials missing: ${M(e,r)}`);let i=new URLSearchParams({client_id:e.clientId,client_secret:e.clientSecret,refresh_token:e.refreshToken,grant_type:`refresh_token`}),a=n??g,{headers:o,...s}=t??{},c=await a(e.tokenUrl,{...s,method:`POST`,body:i.toString(),headers:T({"Content-Type":`application/x-www-form-urlencoded`},o)});return c.ok?await c.json():(X(`Refresh access token failed with status ${c.status}`),{})},Ve=async(e,t,n)=>{X(`Fetching oauth headers`);let r={},i=!1;return e.refreshToken?e.refreshToken&&!e.accessToken||Date.now()>(e.expiration??0)?(r=await Be(e,t,n),i=!0):r={access_token:e.accessToken,refresh_token:e.refreshToken}:(r=await ze(e,t,n),i=!0),i&&(r.access_token&&(e.accessToken=r.access_token),r.refresh_token&&(e.refreshToken=r.refresh_token),typeof r.expires_in==`number`&&(e.expiration=Date.now()+r.expires_in*1e3)),X(`Oauth tokens obtained`),{tokens:r,headers:r.access_token?{authorization:`Bearer ${r.access_token}`}:{}}};var He=o({DAVClient:()=>We,createDAVClient:()=>Ue});const Ue=async e=>{let{serverUrl:t,credentials:n,authMethod:r=`Basic`,defaultAccountType:i,authFunction:a,fetchOptions:o,fetch:s}=e,c={};switch(r){case`Basic`:c=$(n);break;case`Bearer`:c=Re(n);break;case`Oauth`:c=(await Ve(n,o,s)).headers;break;case`Digest`:c={Authorization:`Digest ${n.digestString}`};break;case`Custom`:if(!a)throw Error(`authMethod 'Custom' requires an authFunction to produce request headers`);c=await a(n)??{};break;default:throw Error(`Invalid auth method`)}let l=i?await Y({account:{serverUrl:t,credentials:n,accountType:i},headers:c,fetchOptions:o,fetch:s}):void 0,u=async e=>{let{init:t,fetchOptions:n,fetch:r,...i}=e,{headers:a,...l}=t;return E({...i,init:{...l,headers:{...c,...a}},fetchOptions:n??o,fetch:r??s})},d={headers:c,fetchOptions:o,fetch:s},f={url:t,...d},p={account:l,...d},m=Q(O,f),h=Q(k,f),g=Q(A,f),_=Q(D,d),ee=async e=>{let{account:r,headers:i,loadCollections:a,loadObjects:l,fetchOptions:u,fetch:d}=e,f={serverUrl:t,credentials:n,...r};if(!f.accountType)throw Error("createAccount requires an accountType; pass one via `account.accountType` or set `defaultAccountType` on the client.");return Y({account:f,headers:{...c,...i},loadCollections:a,loadObjects:l,fetchOptions:u??o,fetch:d??s})},te=Q(N,d),v=Q(ue,d),y=Q(I,d),b=Q(P,d),x=Q(F,d),S=Q(L,p),C=Q(de,p),ne=Q(U,d),w=Q(W,d),T=Q(Ce,d),re=Q(G,p),ie=Q(Se,p),ae=Q(K,d),j=Q(we,d),M=Q(Te,d),oe=Q(Ee,d),se=Q(q,p),ce=Q(De,p),le=Q(R,d),fe=Q(z,d);return{davRequest:u,propfind:_,createAccount:ee,createObject:m,updateObject:h,deleteObject:g,calendarQuery:ne,addressBookQuery:le,collectionQuery:te,makeCollection:v,calendarMultiGet:w,makeCalendar:T,syncCollection:y,supportedReportSet:b,isCollectionDirty:x,smartCollectionSync:S,smartCollectionSyncDetailed:C,fetchCalendars:re,fetchCalendarUserAddresses:ie,fetchCalendarObjects:ae,createCalendarObject:j,updateCalendarObject:M,deleteCalendarObject:oe,syncCalendars:se,syncCalendarsDetailed:ce,fetchAddressBooks:Q(B,p),addressBookMultiGet:fe,fetchVCards:Q(V,d),createVCard:Q(me,d),updateVCard:Q(he,d),deleteVCard:Q(ge,d)}};var We=class{constructor(e){this.serverUrl=e.serverUrl,this.credentials=e.credentials,this.authMethod=e.authMethod??`Basic`,this.accountType=e.defaultAccountType??`caldav`,this.authFunction=e.authFunction,this.fetchOptions=e.fetchOptions??{},this.fetchOverride=e.fetch}async login(e){switch(this.authMethod){case`Basic`:this.authHeaders=$(this.credentials);break;case`Bearer`:this.authHeaders=Re(this.credentials);break;case`Oauth`:this.authHeaders=(await Ve(this.credentials,this.fetchOptions,this.fetchOverride)).headers;break;case`Digest`:this.authHeaders={Authorization:`Digest ${this.credentials.digestString}`};break;case`Custom`:if(!this.authFunction)throw Error(`authMethod 'Custom' requires an authFunction to produce request headers`);this.authHeaders=await this.authFunction(this.credentials);break;default:throw Error(`Invalid auth method`)}this.account=this.accountType?await Y({account:{serverUrl:this.serverUrl,credentials:this.credentials,accountType:this.accountType},headers:this.authHeaders,loadCollections:e?.loadCollections,loadObjects:e?.loadObjects,fetchOptions:this.fetchOptions,fetch:this.fetchOverride}):void 0}async davRequest(e){let{init:t,fetchOptions:n,fetch:r,...i}=e,{headers:a,...o}=t;return E({...i,init:{...o,headers:{...this.authHeaders,...a}},fetchOptions:n??this.fetchOptions,fetch:r??this.fetchOverride})}async createObject(...e){return Q(O,{url:this.serverUrl,headers:this.authHeaders,fetchOptions:this.fetchOptions,fetch:this.fetchOverride})(e[0])}async updateObject(...e){return Q(k,{url:this.serverUrl,headers:this.authHeaders,fetchOptions:this.fetchOptions,fetch:this.fetchOverride})(e[0])}async deleteObject(...e){return Q(A,{url:this.serverUrl,headers:this.authHeaders,fetchOptions:this.fetchOptions,fetch:this.fetchOverride})(e[0])}async propfind(...e){return Q(D,{headers:this.authHeaders,fetchOptions:this.fetchOptions,fetch:this.fetchOverride})(e[0])}async createAccount(e){let{account:t,headers:n,loadCollections:r,loadObjects:i,fetchOptions:a,fetch:o}=e,s=t.accountType??this.accountType;if(!s)throw Error("createAccount requires an accountType; pass one via `account.accountType` or configure `defaultAccountType` on the DAVClient.");return Y({account:{serverUrl:this.serverUrl,credentials:this.credentials,...t,accountType:s},headers:{...this.authHeaders,...n},loadCollections:r,loadObjects:i,fetchOptions:a??this.fetchOptions,fetch:o??this.fetchOverride})}async collectionQuery(...e){return Q(N,{headers:this.authHeaders,fetchOptions:this.fetchOptions,fetch:this.fetchOverride})(e[0])}async makeCollection(...e){return Q(ue,{headers:this.authHeaders,fetchOptions:this.fetchOptions,fetch:this.fetchOverride})(e[0])}async syncCollection(...e){return Q(I,{headers:this.authHeaders,fetchOptions:this.fetchOptions,fetch:this.fetchOverride})(e[0])}async supportedReportSet(...e){return Q(P,{headers:this.authHeaders,fetchOptions:this.fetchOptions,fetch:this.fetchOverride})(e[0])}async isCollectionDirty(...e){return Q(F,{headers:this.authHeaders,fetchOptions:this.fetchOptions,fetch:this.fetchOverride})(e[0])}async smartCollectionSync(...e){return Q(L,{headers:this.authHeaders,fetchOptions:this.fetchOptions,fetch:this.fetchOverride,account:this.account})(e[0])}async smartCollectionSyncDetailed(e){return Q(de,{headers:this.authHeaders,fetchOptions:this.fetchOptions,fetch:this.fetchOverride,account:this.account})(e)}async calendarQuery(...e){return Q(U,{headers:this.authHeaders,fetchOptions:this.fetchOptions,fetch:this.fetchOverride})(e[0])}async makeCalendar(...e){return Q(Ce,{headers:this.authHeaders,fetchOptions:this.fetchOptions,fetch:this.fetchOverride})(e[0])}async calendarMultiGet(...e){return Q(W,{headers:this.authHeaders,fetchOptions:this.fetchOptions,fetch:this.fetchOverride})(e[0])}async fetchCalendars(...e){return Q(G,{headers:this.authHeaders,account:this.account,fetchOptions:this.fetchOptions,fetch:this.fetchOverride})(e?.[0])}async fetchCalendarUserAddresses(...e){return Q(Se,{headers:this.authHeaders,account:this.account,fetchOptions:this.fetchOptions,fetch:this.fetchOverride})(e?.[0])}async fetchCalendarObjects(...e){return Q(K,{headers:this.authHeaders,fetchOptions:this.fetchOptions,fetch:this.fetchOverride})(e[0])}async createCalendarObject(...e){return Q(we,{headers:this.authHeaders,fetchOptions:this.fetchOptions,fetch:this.fetchOverride})(e[0])}async updateCalendarObject(...e){return Q(Te,{headers:this.authHeaders,fetchOptions:this.fetchOptions,fetch:this.fetchOverride})(e[0])}async deleteCalendarObject(...e){return Q(Ee,{headers:this.authHeaders,fetchOptions:this.fetchOptions,fetch:this.fetchOverride})(e[0])}async syncCalendars(...e){return Q(q,{headers:this.authHeaders,account:this.account,fetchOptions:this.fetchOptions,fetch:this.fetchOverride})(e[0])}async syncCalendarsDetailed(...e){return Q(De,{headers:this.authHeaders,account:this.account,fetchOptions:this.fetchOptions,fetch:this.fetchOverride})(e[0])}async addressBookQuery(...e){return Q(R,{headers:this.authHeaders,fetchOptions:this.fetchOptions,fetch:this.fetchOverride})(e[0])}async addressBookMultiGet(...e){return Q(z,{headers:this.authHeaders,fetchOptions:this.fetchOptions,fetch:this.fetchOverride})(e[0])}async fetchAddressBooks(...e){return Q(B,{headers:this.authHeaders,account:this.account,fetchOptions:this.fetchOptions,fetch:this.fetchOverride})(e?.[0])}async fetchVCards(...e){return Q(V,{headers:this.authHeaders,fetchOptions:this.fetchOptions,fetch:this.fetchOverride})(e[0])}async createVCard(...e){return Q(me,{headers:this.authHeaders,fetchOptions:this.fetchOptions,fetch:this.fetchOverride})(e[0])}async updateVCard(...e){return Q(he,{headers:this.authHeaders,fetchOptions:this.fetchOptions,fetch:this.fetchOverride})(e[0])}async deleteVCard(...e){return Q(ge,{headers:this.authHeaders,fetchOptions:this.fetchOptions,fetch:this.fetchOverride})(e[0])}},Ge={DAVNamespace:d,DAVNamespaceShort:p,DAVAttributeMap:f,...He,...re,...oe,...ke,...fe,..._e,...Pe,...te};exports.DAVAttributeMap=f,exports.DAVClient=We,exports.DAVNamespace=d,exports.DAVNamespaceShort=p,exports.addressBookMultiGet=z,exports.addressBookQuery=R,exports.calendarMultiGet=W,exports.calendarQuery=U,exports.cleanupFalsy=C,exports.collectionQuery=N,exports.createAccount=Y,exports.createCalendarObject=we,exports.createDAVClient=Ue,exports.createObject=O,exports.createVCard=me,exports.davRequest=E,exports.default=Ge,exports.deleteCalendarObject=Ee,exports.deleteObject=A,exports.deleteVCard=ge,exports.fetchAddressBooks=B,exports.fetchCalendarObjects=K,exports.fetchCalendarUserAddresses=Se,exports.fetchCalendars=G,exports.fetchOauthTokens=ze,exports.fetchVCards=V,exports.freeBusyQuery=Oe,exports.getBasicAuthHeaders=$,exports.getBearerAuthHeaders=Re,exports.getDAVAttribute=S,exports.getOauthHeaders=Ve,exports.isCollectionDirty=F,exports.makeCalendar=Ce,exports.propfind=D,exports.refreshAccessToken=Be,exports.smartCollectionSync=L,exports.smartCollectionSyncDetailed=de,exports.supportedReportSet=P,exports.syncCalendars=q,exports.syncCalendarsDetailed=De,exports.syncCollection=I,exports.updateCalendarObject=Te,exports.updateObject=k,exports.updateVCard=he,exports.urlContains=b,exports.urlEquals=y;