MCPcopy Create free account
hub / github.com/bewcloud/bewcloud / fetchCalendars

Function fetchCalendars

lib/models/dav.js:9792–9853  ·  view source on GitHub ↗
(params)

Source from the content-addressed store, hash-verified

9790 });
9791};
9792const fetchCalendars = async (params) => {
9793 const { headers, account, props: customProps, projectedProps, headersToExclude } = params !== null && params !== void 0 ? params : {};
9794 const requiredFields = ['homeUrl', 'rootUrl'];
9795 if (!account || !hasFields(account, requiredFields)) {
9796 if (!account) {
9797 throw new Error('no account for fetchCalendars');
9798 }
9799 throw new Error(`account must have ${findMissingFieldNames(account, requiredFields)} before fetchCalendars`);
9800 }
9801 const res = await propfind({
9802 url: account.homeUrl,
9803 props: customProps !== null && customProps !== void 0 ? customProps : {
9804 [`${DAVNamespaceShort.CALDAV}:calendar-description`]: {},
9805 [`${DAVNamespaceShort.CALDAV}:calendar-timezone`]: {},
9806 [`${DAVNamespaceShort.DAV}:displayname`]: {},
9807 [`${DAVNamespaceShort.CALDAV_APPLE}:calendar-color`]: {},
9808 [`${DAVNamespaceShort.CALENDAR_SERVER}:getctag`]: {},
9809 [`${DAVNamespaceShort.DAV}:resourcetype`]: {},
9810 [`${DAVNamespaceShort.CALDAV}:supported-calendar-component-set`]: {},
9811 [`${DAVNamespaceShort.DAV}:sync-token`]: {},
9812 },
9813 depth: '1',
9814 headers: excludeHeaders(headers, headersToExclude),
9815 });
9816 return Promise.all(res
9817 .filter((r) => { var _a, _b; return Object.keys((_b = (_a = r.props) === null || _a === void 0 ? void 0 : _a.resourcetype) !== null && _b !== void 0 ? _b : {}).includes('calendar'); })
9818 .filter((rc) => {
9819 var _a, _b, _c, _d;
9820 // filter out none iCal format calendars.
9821 const components = (Array.isArray((_a = rc.props) === null || _a === void 0 ? void 0 : _a.supportedCalendarComponentSet.comp)
9822 ? (_b = rc.props) === null || _b === void 0 ? void 0 : _b.supportedCalendarComponentSet.comp.map((sc) => sc._attributes.name)
9823 : [(_d = (_c = rc.props) === null || _c === void 0 ? void 0 : _c.supportedCalendarComponentSet.comp) === null || _d === void 0 ? void 0 : _d._attributes.name]) || [];
9824 return components.some((c) => Object.values(ICALObjects).includes(c));
9825 })
9826 .map((rs) => {
9827 var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
9828 // debug(`Found calendar ${rs.props?.displayname}`);
9829 const description = (_a = rs.props) === null || _a === void 0 ? void 0 : _a.calendarDescription;
9830 const timezone = (_b = rs.props) === null || _b === void 0 ? void 0 : _b.calendarTimezone;
9831 return {
9832 description: typeof description === 'string' ? description : '',
9833 timezone: typeof timezone === 'string' ? timezone : '',
9834 url: new URL((_c = rs.href) !== null && _c !== void 0 ? _c : '', (_d = account.rootUrl) !== null && _d !== void 0 ? _d : '').href,
9835 ctag: (_e = rs.props) === null || _e === void 0 ? void 0 : _e.getctag,
9836 calendarColor: (_f = rs.props) === null || _f === void 0 ? void 0 : _f.calendarColor,
9837 displayName: (_h = (_g = rs.props) === null || _g === void 0 ? void 0 : _g.displayname._cdata) !== null && _h !== void 0 ? _h : (_j = rs.props) === null || _j === void 0 ? void 0 : _j.displayname,
9838 components: Array.isArray((_k = rs.props) === null || _k === void 0 ? void 0 : _k.supportedCalendarComponentSet.comp)
9839 ? (_l = rs.props) === null || _l === void 0 ? void 0 : _l.supportedCalendarComponentSet.comp.map((sc) => sc._attributes.name)
9840 : [(_o = (_m = rs.props) === null || _m === void 0 ? void 0 : _m.supportedCalendarComponentSet.comp) === null || _o === void 0 ? void 0 : _o._attributes.name],
9841 resourcetype: Object.keys((_p = rs.props) === null || _p === void 0 ? void 0 : _p.resourcetype),
9842 syncToken: (_q = rs.props) === null || _q === void 0 ? void 0 : _q.syncToken,
9843 ...conditionalParam('projectedProps', Object.fromEntries(Object.entries((_r = rs.props) !== null && _r !== void 0 ? _r : {}).filter(([key]) => projectedProps === null || projectedProps === void 0 ? void 0 : projectedProps[key]))),
9844 };
9845 })
9846 .map(async (cal) => ({
9847 ...cal,
9848 reports: await supportedReportSet({
9849 collection: cal,

Callers 2

syncCalendarsFunction · 0.85
createAccountFunction · 0.85

Calls 6

hasFieldsFunction · 0.85
findMissingFieldNamesFunction · 0.85
propfindFunction · 0.85
excludeHeadersFunction · 0.85
conditionalParamFunction · 0.85
supportedReportSetFunction · 0.85

Tested by

no test coverage detected