Skip to content

Commit

Permalink
v2.0.10
Browse files Browse the repository at this point in the history
  • Loading branch information
natelindev committed Jul 16, 2024
1 parent a1e6965 commit 450d6d8
Show file tree
Hide file tree
Showing 14 changed files with 1,203 additions and 830 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## v2.0.10

**improvements**
- fixed [#191](https://github.com/natelindev/tsdav/issues/191) where `authFunction` is not properly assigned in constructor.
- updated deps.

## v2.0.9

**improvements**
Expand Down
32 changes: 16 additions & 16 deletions dist/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tsdav",
"version": "2.0.9",
"version": "2.0.10",
"description": "WebDAV, CALDAV, and CARDDAV client for Nodejs and the Browser",
"keywords": [
"dav",
Expand Down Expand Up @@ -50,7 +50,7 @@
"dependencies": {
"base-64": "1.0.0",
"cross-fetch": "4.0.0",
"debug": "4.3.4",
"debug": "4.3.5",
"xml-js": "1.6.11"
},
"devDependencies": {
Expand All @@ -60,31 +60,31 @@
"@types/base-64": "1.0.2",
"@types/debug": "4.1.12",
"@types/jest": "29.5.12",
"@types/node": "20.11.19",
"@typescript-eslint/eslint-plugin": "7.0.2",
"@typescript-eslint/parser": "7.0.2",
"@types/node": "20.14.10",
"@typescript-eslint/eslint-plugin": "7.16.1",
"@typescript-eslint/parser": "7.16.1",
"copyfiles": "2.4.1",
"cross-env": "7.0.3",
"dotenv": "16.4.5",
"eslint": "8.56.0",
"eslint": "9.7.0",
"eslint-config-airbnb": "19.0.4",
"eslint-config-airbnb-typescript": "17.1.0",
"eslint-config-airbnb-typescript": "18.0.0",
"eslint-config-prettier": "9.1.0",
"eslint-module-utils": "2.8.0",
"eslint-module-utils": "2.8.1",
"eslint-plugin-import": "2.29.1",
"eslint-plugin-prettier": "5.1.3",
"jest": "29.7.0",
"prettier": "3.2.5",
"rimraf": "5.0.5",
"rollup": "4.12.0",
"rollup-plugin-dts": "6.1.0",
"prettier": "3.3.3",
"rimraf": "5.0.7",
"rollup": "4.18.1",
"rollup-plugin-dts": "6.1.1",
"rollup-plugin-node-builtins": "2.1.2",
"rollup-plugin-polyfill-node": "0.13.0",
"rollup-plugin-terser": "7.0.2",
"sort-package-json": "2.8.0",
"ts-jest": "29.1.2",
"tslib": "2.6.2",
"typescript": "5.3.3"
"sort-package-json": "2.10.0",
"ts-jest": "29.2.2",
"tslib": "2.6.3",
"typescript": "5.5.3"
},
"engines": {
"node": ">=10"
Expand Down
39 changes: 20 additions & 19 deletions dist/tsdav.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ const supportedReportSet = (params) => __awaiter(void 0, void 0, void 0, functio
return ((_e = (_d = (_c = (_b = (_a = res[0]) === null || _a === void 0 ? void 0 : _a.props) === null || _b === void 0 ? void 0 : _b.supportedReportSet) === null || _c === void 0 ? void 0 : _c.supportedReport) === null || _d === void 0 ? void 0 : _d.map((sr) => Object.keys(sr.report)[0])) !== null && _e !== void 0 ? _e : []);
});
const isCollectionDirty = (params) => __awaiter(void 0, void 0, void 0, function* () {
var _f, _g, _h;
var _a, _b, _c;
const { collection, headers, headersToExclude } = params;
const responses = yield propfind({
url: collection.url,
Expand All @@ -415,8 +415,8 @@ const isCollectionDirty = (params) => __awaiter(void 0, void 0, void 0, function
throw new Error('Collection does not exist on server');
}
return {
isDirty: collection.ctag !== ((_f = res.props) === null || _f === void 0 ? void 0 : _f.getctag),
newCtag: (_h = (_g = res.props) === null || _g === void 0 ? void 0 : _g.getctag) === null || _h === void 0 ? void 0 : _h.toString(),
isDirty: collection.ctag !== ((_a = res.props) === null || _a === void 0 ? void 0 : _a.getctag),
newCtag: (_c = (_b = res.props) === null || _b === void 0 ? void 0 : _b.getctag) === null || _c === void 0 ? void 0 : _c.toString(),
};
});
/**
Expand Down Expand Up @@ -447,7 +447,7 @@ const syncCollection = (params) => {
};
/** remote collection to local */
const smartCollectionSync = (params) => __awaiter(void 0, void 0, void 0, function* () {
var _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
const { collection, method, headers, headersToExclude, account, detailedResult } = params;
const requiredFields = ['accountType', 'homeUrl'];
if (!account || !hasFields(account, requiredFields)) {
Expand All @@ -456,7 +456,7 @@ const smartCollectionSync = (params) => __awaiter(void 0, void 0, void 0, functi
}
throw new Error(`account must have ${findMissingFieldNames(account, requiredFields)} before smartCollectionSync`);
}
const syncMethod = method !== null && method !== void 0 ? method : (((_j = collection.reports) === null || _j === void 0 ? void 0 : _j.includes('syncCollection')) ? 'webdav' : 'basic');
const syncMethod = method !== null && method !== void 0 ? method : (((_a = collection.reports) === null || _a === void 0 ? void 0 : _a.includes('syncCollection')) ? 'webdav' : 'basic');
debug$4(`smart collection sync with type ${account.accountType} and method ${syncMethod}`);
if (syncMethod === 'webdav') {
const result = yield syncCollection({
Expand All @@ -478,7 +478,7 @@ const smartCollectionSync = (params) => __awaiter(void 0, void 0, void 0, functi
const changedObjectUrls = objectResponses.filter((o) => o.status !== 404).map((r) => r.href);
const deletedObjectUrls = objectResponses.filter((o) => o.status === 404).map((r) => r.href);
const multiGetObjectResponse = changedObjectUrls.length
? (_l = (yield ((_k = collection === null || collection === void 0 ? void 0 : collection.objectMultiGet) === null || _k === void 0 ? void 0 : _k.call(collection, {
? (_c = (yield ((_b = collection === null || collection === void 0 ? void 0 : collection.objectMultiGet) === null || _b === void 0 ? void 0 : _b.call(collection, {
url: collection.url,
props: {
[`${exports.DAVNamespaceShort.DAV}:getetag`]: {},
Expand All @@ -489,7 +489,7 @@ const smartCollectionSync = (params) => __awaiter(void 0, void 0, void 0, functi
objectUrls: changedObjectUrls,
depth: '1',
headers: excludeHeaders(headers, headersToExclude),
})))) !== null && _l !== void 0 ? _l : []
})))) !== null && _c !== void 0 ? _c : []
: [];
const remoteObjects = multiGetObjectResponse.map((res) => {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
Expand All @@ -501,7 +501,7 @@ const smartCollectionSync = (params) => __awaiter(void 0, void 0, void 0, functi
: (_j = (_h = (_g = res.props) === null || _g === void 0 ? void 0 : _g.addressData) === null || _h === void 0 ? void 0 : _h._cdata) !== null && _j !== void 0 ? _j : (_k = res.props) === null || _k === void 0 ? void 0 : _k.addressData,
};
});
const localObjects = (_m = collection.objects) !== null && _m !== void 0 ? _m : [];
const localObjects = (_d = collection.objects) !== null && _d !== void 0 ? _d : [];
// no existing url
const created = remoteObjects.filter((o) => localObjects.every((lo) => !urlContains(lo.url, o.url)));
// debug(`created objects: ${created.map((o) => o.url).join('\n')}`);
Expand All @@ -524,18 +524,18 @@ const smartCollectionSync = (params) => __awaiter(void 0, void 0, void 0, functi
? { created, updated, deleted }
: [...unchanged, ...created, ...updated],
// all syncToken in the results are the same so we use the first one here
syncToken: (_r = (_q = (_p = (_o = result[0]) === null || _o === void 0 ? void 0 : _o.raw) === null || _p === void 0 ? void 0 : _p.multistatus) === null || _q === void 0 ? void 0 : _q.syncToken) !== null && _r !== void 0 ? _r : collection.syncToken });
syncToken: (_h = (_g = (_f = (_e = result[0]) === null || _e === void 0 ? void 0 : _e.raw) === null || _f === void 0 ? void 0 : _f.multistatus) === null || _g === void 0 ? void 0 : _g.syncToken) !== null && _h !== void 0 ? _h : collection.syncToken });
}
if (syncMethod === 'basic') {
const { isDirty, newCtag } = yield isCollectionDirty({
collection,
headers: excludeHeaders(headers, headersToExclude),
});
const localObjects = (_s = collection.objects) !== null && _s !== void 0 ? _s : [];
const remoteObjects = (_u = (yield ((_t = collection.fetchObjects) === null || _t === void 0 ? void 0 : _t.call(collection, {
const localObjects = (_j = collection.objects) !== null && _j !== void 0 ? _j : [];
const remoteObjects = (_l = (yield ((_k = collection.fetchObjects) === null || _k === void 0 ? void 0 : _k.call(collection, {
collection,
headers: excludeHeaders(headers, headersToExclude),
})))) !== null && _u !== void 0 ? _u : [];
})))) !== null && _l !== void 0 ? _l : [];
// no existing url
const created = remoteObjects.filter((ro) => localObjects.every((lo) => !urlContains(lo.url, ro.url)));
// debug(`created objects: ${created.map((o) => o.url).join('\n')}`);
Expand Down Expand Up @@ -1155,7 +1155,7 @@ const serviceDiscovery = (params) => __awaiter(void 0, void 0, void 0, function*
return endpoint.href;
});
const fetchPrincipalUrl = (params) => __awaiter(void 0, void 0, void 0, function* () {
var _c, _d, _e, _f, _g;
var _a, _b, _c, _d, _e;
const { account, headers, headersToExclude } = params;
const requiredFields = ['rootUrl'];
if (!hasFields(account, requiredFields)) {
Expand All @@ -1176,11 +1176,11 @@ const fetchPrincipalUrl = (params) => __awaiter(void 0, void 0, void 0, function
throw new Error('Invalid credentials');
}
}
debug$1(`Fetched principal url ${(_d = (_c = response.props) === null || _c === void 0 ? void 0 : _c.currentUserPrincipal) === null || _d === void 0 ? void 0 : _d.href}`);
return new URL((_g = (_f = (_e = response.props) === null || _e === void 0 ? void 0 : _e.currentUserPrincipal) === null || _f === void 0 ? void 0 : _f.href) !== null && _g !== void 0 ? _g : '', account.rootUrl).href;
debug$1(`Fetched principal url ${(_b = (_a = response.props) === null || _a === void 0 ? void 0 : _a.currentUserPrincipal) === null || _b === void 0 ? void 0 : _b.href}`);
return new URL((_e = (_d = (_c = response.props) === null || _c === void 0 ? void 0 : _c.currentUserPrincipal) === null || _d === void 0 ? void 0 : _d.href) !== null && _e !== void 0 ? _e : '', account.rootUrl).href;
});
const fetchHomeUrl = (params) => __awaiter(void 0, void 0, void 0, function* () {
var _h, _j;
var _a, _b;
const { account, headers, headersToExclude } = params;
const requiredFields = ['principalUrl', 'rootUrl'];
if (!hasFields(account, requiredFields)) {
Expand All @@ -1200,8 +1200,8 @@ const fetchHomeUrl = (params) => __awaiter(void 0, void 0, void 0, function* ()
throw new Error('cannot find homeUrl');
}
const result = new URL(account.accountType === 'caldav'
? (_h = matched === null || matched === void 0 ? void 0 : matched.props) === null || _h === void 0 ? void 0 : _h.calendarHomeSet.href
: (_j = matched === null || matched === void 0 ? void 0 : matched.props) === null || _j === void 0 ? void 0 : _j.addressbookHomeSet.href, account.rootUrl).href;
? (_a = matched === null || matched === void 0 ? void 0 : matched.props) === null || _a === void 0 ? void 0 : _a.calendarHomeSet.href
: (_b = matched === null || matched === void 0 ? void 0 : matched.props) === null || _b === void 0 ? void 0 : _b.addressbookHomeSet.href, account.rootUrl).href;
debug$1(`Fetched home url ${result}`);
return result;
});
Expand Down Expand Up @@ -1516,10 +1516,11 @@ class DAVClient {
this.credentials = params.credentials;
this.authMethod = (_a = params.authMethod) !== null && _a !== void 0 ? _a : 'Basic';
this.accountType = (_b = params.defaultAccountType) !== null && _b !== void 0 ? _b : 'caldav';
this.authFunction = params.authFunction;
}
login() {
var _a;
return __awaiter(this, void 0, void 0, function* () {
var _a;
switch (this.authMethod) {
case 'Basic':
this.authHeaders = getBasicAuthHeaders(this.credentials);
Expand Down
Loading

0 comments on commit 450d6d8

Please sign in to comment.