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