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

Function fetchVCards

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

Source from the content-addressed store, hash-verified

9626 })));
9627};
9628const fetchVCards = async (params) => {
9629 const { addressBook, headers, objectUrls, headersToExclude, urlFilter = (url) => url, useMultiGet = true, } = params;
9630 debug$3(`Fetching vcards from ${addressBook === null || addressBook === void 0 ? void 0 : addressBook.url}`);
9631 const requiredFields = ['url'];
9632 if (!addressBook || !hasFields(addressBook, requiredFields)) {
9633 if (!addressBook) {
9634 throw new Error('cannot fetchVCards for undefined addressBook');
9635 }
9636 throw new Error(`addressBook must have ${findMissingFieldNames(addressBook, requiredFields)} before fetchVCards`);
9637 }
9638 const vcardUrls = (objectUrls !== null && objectUrls !== void 0 ? objectUrls :
9639 // fetch all objects of the calendar
9640 (await addressBookQuery({
9641 url: addressBook.url,
9642 props: { [`${DAVNamespaceShort.DAV}:getetag`]: {} },
9643 depth: '1',
9644 headers: excludeHeaders(headers, headersToExclude),
9645 })).map((res) => { var _a; return (res.ok ? ((_a = res.href) !== null && _a !== void 0 ? _a : '') : ''); }))
9646 .map((url) => (url.startsWith('http') || !url ? url : new URL(url, addressBook.url).href))
9647 .filter(urlFilter)
9648 .map((url) => new URL(url).pathname);
9649 let vCardResults = [];
9650 if (vcardUrls.length > 0) {
9651 if (useMultiGet) {
9652 vCardResults = await addressBookMultiGet({
9653 url: addressBook.url,
9654 props: {
9655 [`${DAVNamespaceShort.DAV}:getetag`]: {},
9656 [`${DAVNamespaceShort.CARDDAV}:address-data`]: {},
9657 },
9658 objectUrls: vcardUrls,
9659 depth: '1',
9660 headers: excludeHeaders(headers, headersToExclude),
9661 });
9662 }
9663 else {
9664 vCardResults = await addressBookQuery({
9665 url: addressBook.url,
9666 props: {
9667 [`${DAVNamespaceShort.DAV}:getetag`]: {},
9668 [`${DAVNamespaceShort.CARDDAV}:address-data`]: {},
9669 },
9670 depth: '1',
9671 headers: excludeHeaders(headers, headersToExclude),
9672 });
9673 }
9674 }
9675 return vCardResults.map((res) => {
9676 var _a, _b, _c, _d, _e, _f;
9677 return ({
9678 url: new URL((_a = res.href) !== null && _a !== void 0 ? _a : '', addressBook.url).href,
9679 etag: (_b = res.props) === null || _b === void 0 ? void 0 : _b.getetag,
9680 data: (_e = (_d = (_c = res.props) === null || _c === void 0 ? void 0 : _c.addressData) === null || _d === void 0 ? void 0 : _d._cdata) !== null && _e !== void 0 ? _e : (_f = res.props) === null || _f === void 0 ? void 0 : _f.addressData,
9681 });
9682 });
9683};
9684const createVCard = async (params) => {
9685 const { addressBook, vCardString, filename, headers, headersToExclude } = params;

Callers 1

createAccountFunction · 0.85

Calls 5

hasFieldsFunction · 0.85
findMissingFieldNamesFunction · 0.85
addressBookQueryFunction · 0.85
excludeHeadersFunction · 0.85
addressBookMultiGetFunction · 0.85

Tested by

no test coverage detected