Skip to content

Commit

Permalink
update in repo versions
Browse files Browse the repository at this point in the history
  • Loading branch information
natelindev committed Jun 24, 2023
1 parent abcd2ed commit da04628
Show file tree
Hide file tree
Showing 10 changed files with 301 additions and 197 deletions.
10 changes: 5 additions & 5 deletions dist/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tsdav",
"version": "2.0.4",
"version": "2.0.5",
"description": "WebDAV, CALDAV, and CARDDAV client for Nodejs and the Browser",
"keywords": [
"dav",
Expand Down Expand Up @@ -54,18 +54,18 @@
"xml-js": "1.6.11"
},
"devDependencies": {
"@rollup/plugin-commonjs": "25.0.1",
"@rollup/plugin-commonjs": "25.0.2",
"@rollup/plugin-node-resolve": "15.1.0",
"@rollup/plugin-typescript": "11.1.1",
"@types/base-64": "1.0.0",
"@types/debug": "4.1.8",
"@types/jest": "29.5.2",
"@types/node": "20.3.1",
"@typescript-eslint/eslint-plugin": "5.59.11",
"@typescript-eslint/parser": "5.59.11",
"@typescript-eslint/eslint-plugin": "5.60.0",
"@typescript-eslint/parser": "5.60.0",
"copyfiles": "2.4.1",
"cross-env": "7.0.3",
"dotenv": "16.3.0",
"dotenv": "16.3.1",
"eslint": "8.43.0",
"eslint-config-airbnb": "19.0.4",
"eslint-config-airbnb-typescript": "17.0.0",
Expand Down
90 changes: 54 additions & 36 deletions dist/tsdav.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,19 @@ const cleanupFalsy = (obj) => Object.entries(obj).reduce((prev, [key, value]) =>
return Object.assign(Object.assign({}, prev), { [key]: value });
return prev;
}, {});
const conditionalParam = (key, param) => {
if (param) {
return {
[key]: param,
};
}
return {};
};

var requestHelpers = /*#__PURE__*/Object.freeze({
__proto__: null,
cleanupFalsy: cleanupFalsy,
conditionalParam: conditionalParam,
getDAVAttribute: getDAVAttribute,
urlContains: urlContains,
urlEquals: urlEquals
Expand Down Expand Up @@ -744,13 +753,7 @@ const calendarMultiGet = (params) => __awaiter(void 0, void 0, void 0, function*
return collectionQuery({
url,
body: {
'calendar-multiget': {
_attributes: getDAVAttribute([exports.DAVNamespace.DAV, exports.DAVNamespace.CALDAV]),
[`${exports.DAVNamespaceShort.DAV}:prop`]: props,
[`${exports.DAVNamespaceShort.DAV}:href`]: objectUrls,
filter: filters,
timezone,
},
'calendar-multiget': Object.assign(Object.assign({ _attributes: getDAVAttribute([exports.DAVNamespace.DAV, exports.DAVNamespace.CALDAV]), [`${exports.DAVNamespaceShort.DAV}:prop`]: props, [`${exports.DAVNamespaceShort.DAV}:href`]: objectUrls }, conditionalParam('filter', filters)), { timezone }),
},
defaultNamespace: exports.DAVNamespaceShort.CALDAV,
depth,
Expand Down Expand Up @@ -781,7 +784,7 @@ const makeCalendar = (params) => __awaiter(void 0, void 0, void 0, function* ()
});
});
const fetchCalendars = (params) => __awaiter(void 0, void 0, void 0, function* () {
const { headers, account, props: customProps } = params !== null && params !== void 0 ? params : {};
const { headers, account, props: customProps, projectedProps } = params !== null && params !== void 0 ? params : {};
const requiredFields = ['homeUrl', 'rootUrl'];
if (!account || !hasFields(account, requiredFields)) {
if (!account) {
Expand Down Expand Up @@ -815,23 +818,13 @@ const fetchCalendars = (params) => __awaiter(void 0, void 0, void 0, function* (
return components.some((c) => Object.values(ICALObjects).includes(c));
})
.map((rs) => {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
// debug(`Found calendar ${rs.props?.displayname}`);
const description = (_a = rs.props) === null || _a === void 0 ? void 0 : _a.calendarDescription;
const timezone = (_b = rs.props) === null || _b === void 0 ? void 0 : _b.calendarTimezone;
return {
description: typeof description === 'string' ? description : '',
timezone: typeof timezone === 'string' ? timezone : '',
url: new URL((_c = rs.href) !== null && _c !== void 0 ? _c : '', (_d = account.rootUrl) !== null && _d !== void 0 ? _d : '').href,
ctag: (_e = rs.props) === null || _e === void 0 ? void 0 : _e.getctag,
calendarColor: (_f = rs.props) === null || _f === void 0 ? void 0 : _f.calendarColor,
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,
components: Array.isArray((_k = rs.props) === null || _k === void 0 ? void 0 : _k.supportedCalendarComponentSet.comp)
return Object.assign({ description: typeof description === 'string' ? description : '', timezone: typeof timezone === 'string' ? timezone : '', url: new URL((_c = rs.href) !== null && _c !== void 0 ? _c : '', (_d = account.rootUrl) !== null && _d !== void 0 ? _d : '').href, ctag: (_e = rs.props) === null || _e === void 0 ? void 0 : _e.getctag, calendarColor: (_f = rs.props) === null || _f === void 0 ? void 0 : _f.calendarColor, 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, components: Array.isArray((_k = rs.props) === null || _k === void 0 ? void 0 : _k.supportedCalendarComponentSet.comp)
? (_l = rs.props) === null || _l === void 0 ? void 0 : _l.supportedCalendarComponentSet.comp.map((sc) => sc._attributes.name)
: [(_m = rs.props) === null || _m === void 0 ? void 0 : _m.supportedCalendarComponentSet.comp._attributes.name],
resourcetype: Object.keys((_o = rs.props) === null || _o === void 0 ? void 0 : _o.resourcetype),
syncToken: (_p = rs.props) === null || _p === void 0 ? void 0 : _p.syncToken,
};
: [(_m = rs.props) === null || _m === void 0 ? void 0 : _m.supportedCalendarComponentSet.comp._attributes.name], resourcetype: Object.keys((_o = rs.props) === null || _o === void 0 ? void 0 : _o.resourcetype), syncToken: (_p = rs.props) === null || _p === void 0 ? void 0 : _p.syncToken }, conditionalParam('projectedProps', Object.fromEntries(Object.entries((_q = rs.props) !== null && _q !== void 0 ? _q : {}).filter(([key]) => projectedProps === null || projectedProps === void 0 ? void 0 : projectedProps[key]))));
})
.map((cal) => __awaiter(void 0, void 0, void 0, function* () {
return (Object.assign(Object.assign({}, cal), { reports: yield supportedReportSet({ collection: cal, headers }) }));
Expand Down Expand Up @@ -1334,14 +1327,27 @@ var authHelpers = /*#__PURE__*/Object.freeze({

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
const createDAVClient = (params) => __awaiter(void 0, void 0, void 0, function* () {
const { serverUrl, credentials, authMethod, defaultAccountType } = params;
const authHeaders =
// eslint-disable-next-line no-nested-ternary
authMethod === 'Basic'
? getBasicAuthHeaders(credentials)
: authMethod === 'Oauth'
? (yield getOauthHeaders(credentials)).headers
: {};
var _a;
const { serverUrl, credentials, authMethod, defaultAccountType, authFunction } = params;
let authHeaders = {};
switch (authMethod) {
case 'Basic':
authHeaders = getBasicAuthHeaders(credentials);
break;
case 'Oauth':
authHeaders = (yield getOauthHeaders(credentials)).headers;
break;
case 'Digest':
authHeaders = {
Authorization: `Digest ${credentials.digestString}`,
};
break;
case 'Custom':
authHeaders = (_a = (yield (authFunction === null || authFunction === void 0 ? void 0 : authFunction(credentials)))) !== null && _a !== void 0 ? _a : {};
break;
default:
throw new Error('Invalid auth method');
}
const defaultAccount = defaultAccountType
? yield createAccount({
account: { serverUrl, credentials, accountType: defaultAccountType },
Expand Down Expand Up @@ -1459,14 +1465,26 @@ class DAVClient {
this.accountType = (_b = params.defaultAccountType) !== null && _b !== void 0 ? _b : 'caldav';
}
login() {
var _a;
return __awaiter(this, void 0, void 0, function* () {
this.authHeaders =
// eslint-disable-next-line no-nested-ternary
this.authMethod === 'Basic'
? getBasicAuthHeaders(this.credentials)
: this.authMethod === 'Oauth'
? (yield getOauthHeaders(this.credentials)).headers
: {};
switch (this.authMethod) {
case 'Basic':
this.authHeaders = getBasicAuthHeaders(this.credentials);
break;
case 'Oauth':
this.authHeaders = (yield getOauthHeaders(this.credentials)).headers;
break;
case 'Digest':
this.authHeaders = {
Authorization: `Digest ${this.credentials.digestString}`,
};
break;
case 'Custom':
this.authHeaders = yield ((_a = this.authFunction) === null || _a === void 0 ? void 0 : _a.call(this, this.credentials));
break;
default:
throw new Error('Invalid auth method');
}
this.account = this.accountType
? yield createAccount({
account: {
Expand Down
90 changes: 54 additions & 36 deletions dist/tsdav.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,19 @@ const cleanupFalsy = (obj) => Object.entries(obj).reduce((prev, [key, value]) =>
return Object.assign(Object.assign({}, prev), { [key]: value });
return prev;
}, {});
const conditionalParam = (key, param) => {
if (param) {
return {
[key]: param,
};
}
return {};
};

var requestHelpers = /*#__PURE__*/Object.freeze({
__proto__: null,
cleanupFalsy: cleanupFalsy,
conditionalParam: conditionalParam,
getDAVAttribute: getDAVAttribute,
urlContains: urlContains,
urlEquals: urlEquals
Expand Down Expand Up @@ -744,13 +753,7 @@ const calendarMultiGet = (params) => __awaiter(void 0, void 0, void 0, function*
return collectionQuery({
url,
body: {
'calendar-multiget': {
_attributes: getDAVAttribute([exports.DAVNamespace.DAV, exports.DAVNamespace.CALDAV]),
[`${exports.DAVNamespaceShort.DAV}:prop`]: props,
[`${exports.DAVNamespaceShort.DAV}:href`]: objectUrls,
filter: filters,
timezone,
},
'calendar-multiget': Object.assign(Object.assign({ _attributes: getDAVAttribute([exports.DAVNamespace.DAV, exports.DAVNamespace.CALDAV]), [`${exports.DAVNamespaceShort.DAV}:prop`]: props, [`${exports.DAVNamespaceShort.DAV}:href`]: objectUrls }, conditionalParam('filter', filters)), { timezone }),
},
defaultNamespace: exports.DAVNamespaceShort.CALDAV,
depth,
Expand Down Expand Up @@ -781,7 +784,7 @@ const makeCalendar = (params) => __awaiter(void 0, void 0, void 0, function* ()
});
});
const fetchCalendars = (params) => __awaiter(void 0, void 0, void 0, function* () {
const { headers, account, props: customProps } = params !== null && params !== void 0 ? params : {};
const { headers, account, props: customProps, projectedProps } = params !== null && params !== void 0 ? params : {};
const requiredFields = ['homeUrl', 'rootUrl'];
if (!account || !hasFields(account, requiredFields)) {
if (!account) {
Expand Down Expand Up @@ -815,23 +818,13 @@ const fetchCalendars = (params) => __awaiter(void 0, void 0, void 0, function* (
return components.some((c) => Object.values(ICALObjects).includes(c));
})
.map((rs) => {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
// debug(`Found calendar ${rs.props?.displayname}`);
const description = (_a = rs.props) === null || _a === void 0 ? void 0 : _a.calendarDescription;
const timezone = (_b = rs.props) === null || _b === void 0 ? void 0 : _b.calendarTimezone;
return {
description: typeof description === 'string' ? description : '',
timezone: typeof timezone === 'string' ? timezone : '',
url: new URL((_c = rs.href) !== null && _c !== void 0 ? _c : '', (_d = account.rootUrl) !== null && _d !== void 0 ? _d : '').href,
ctag: (_e = rs.props) === null || _e === void 0 ? void 0 : _e.getctag,
calendarColor: (_f = rs.props) === null || _f === void 0 ? void 0 : _f.calendarColor,
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,
components: Array.isArray((_k = rs.props) === null || _k === void 0 ? void 0 : _k.supportedCalendarComponentSet.comp)
return Object.assign({ description: typeof description === 'string' ? description : '', timezone: typeof timezone === 'string' ? timezone : '', url: new URL((_c = rs.href) !== null && _c !== void 0 ? _c : '', (_d = account.rootUrl) !== null && _d !== void 0 ? _d : '').href, ctag: (_e = rs.props) === null || _e === void 0 ? void 0 : _e.getctag, calendarColor: (_f = rs.props) === null || _f === void 0 ? void 0 : _f.calendarColor, 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, components: Array.isArray((_k = rs.props) === null || _k === void 0 ? void 0 : _k.supportedCalendarComponentSet.comp)
? (_l = rs.props) === null || _l === void 0 ? void 0 : _l.supportedCalendarComponentSet.comp.map((sc) => sc._attributes.name)
: [(_m = rs.props) === null || _m === void 0 ? void 0 : _m.supportedCalendarComponentSet.comp._attributes.name],
resourcetype: Object.keys((_o = rs.props) === null || _o === void 0 ? void 0 : _o.resourcetype),
syncToken: (_p = rs.props) === null || _p === void 0 ? void 0 : _p.syncToken,
};
: [(_m = rs.props) === null || _m === void 0 ? void 0 : _m.supportedCalendarComponentSet.comp._attributes.name], resourcetype: Object.keys((_o = rs.props) === null || _o === void 0 ? void 0 : _o.resourcetype), syncToken: (_p = rs.props) === null || _p === void 0 ? void 0 : _p.syncToken }, conditionalParam('projectedProps', Object.fromEntries(Object.entries((_q = rs.props) !== null && _q !== void 0 ? _q : {}).filter(([key]) => projectedProps === null || projectedProps === void 0 ? void 0 : projectedProps[key]))));
})
.map((cal) => __awaiter(void 0, void 0, void 0, function* () {
return (Object.assign(Object.assign({}, cal), { reports: yield supportedReportSet({ collection: cal, headers }) }));
Expand Down Expand Up @@ -1334,14 +1327,27 @@ var authHelpers = /*#__PURE__*/Object.freeze({

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
const createDAVClient = (params) => __awaiter(void 0, void 0, void 0, function* () {
const { serverUrl, credentials, authMethod, defaultAccountType } = params;
const authHeaders =
// eslint-disable-next-line no-nested-ternary
authMethod === 'Basic'
? getBasicAuthHeaders(credentials)
: authMethod === 'Oauth'
? (yield getOauthHeaders(credentials)).headers
: {};
var _a;
const { serverUrl, credentials, authMethod, defaultAccountType, authFunction } = params;
let authHeaders = {};
switch (authMethod) {
case 'Basic':
authHeaders = getBasicAuthHeaders(credentials);
break;
case 'Oauth':
authHeaders = (yield getOauthHeaders(credentials)).headers;
break;
case 'Digest':
authHeaders = {
Authorization: `Digest ${credentials.digestString}`,
};
break;
case 'Custom':
authHeaders = (_a = (yield (authFunction === null || authFunction === void 0 ? void 0 : authFunction(credentials)))) !== null && _a !== void 0 ? _a : {};
break;
default:
throw new Error('Invalid auth method');
}
const defaultAccount = defaultAccountType
? yield createAccount({
account: { serverUrl, credentials, accountType: defaultAccountType },
Expand Down Expand Up @@ -1459,14 +1465,26 @@ class DAVClient {
this.accountType = (_b = params.defaultAccountType) !== null && _b !== void 0 ? _b : 'caldav';
}
login() {
var _a;
return __awaiter(this, void 0, void 0, function* () {
this.authHeaders =
// eslint-disable-next-line no-nested-ternary
this.authMethod === 'Basic'
? getBasicAuthHeaders(this.credentials)
: this.authMethod === 'Oauth'
? (yield getOauthHeaders(this.credentials)).headers
: {};
switch (this.authMethod) {
case 'Basic':
this.authHeaders = getBasicAuthHeaders(this.credentials);
break;
case 'Oauth':
this.authHeaders = (yield getOauthHeaders(this.credentials)).headers;
break;
case 'Digest':
this.authHeaders = {
Authorization: `Digest ${this.credentials.digestString}`,
};
break;
case 'Custom':
this.authHeaders = yield ((_a = this.authFunction) === null || _a === void 0 ? void 0 : _a.call(this, this.credentials));
break;
default:
throw new Error('Invalid auth method');
}
this.account = this.accountType
? yield createAccount({
account: {
Expand Down
Loading

0 comments on commit da04628

Please sign in to comment.