diff --git a/.eslintrc.cjs b/.eslintrc.cjs deleted file mode 100644 index 345a9b72..00000000 --- a/.eslintrc.cjs +++ /dev/null @@ -1,10 +0,0 @@ -/** - * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors - * SPDX-License-Identifier: AGPL-3.0-or-later - */ - -module.exports = { - extends: [ - '@nextcloud', - ], -} diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 00000000..d156b2e4 --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,10 @@ +/** + * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +import { recommendedJavascript } from '@nextcloud/eslint-config' + +export default [ + ...recommendedJavascript, +] diff --git a/package.json b/package.json index 229ae34a..a814838c 100644 --- a/package.json +++ b/package.json @@ -23,8 +23,8 @@ "test": "vitest run", "test:coverage": "vitest run --coverage", "test:watch": "vitest", - "lint": "eslint --ext .js src", - "lint:fix": "eslint --ext .js src --fix" + "lint": "eslint src", + "lint:fix": "eslint src --fix" }, "repository": { "type": "git", diff --git a/src/debug.js b/src/debug.js index 3e1b3ef8..f2a5b8b7 100644 --- a/src/debug.js +++ b/src/debug.js @@ -9,6 +9,7 @@ /** * creates a debug function bound to a context + * * @param {string} context * @return {Function} */ diff --git a/src/errors/attachError.js b/src/errors/attachError.js index 94be5531..5c405691 100644 --- a/src/errors/attachError.js +++ b/src/errors/attachError.js @@ -13,7 +13,6 @@ * @abstract */ export default class AttachError extends Error { - /** * * @param {object} attach @@ -23,5 +22,4 @@ export default class AttachError extends Error { Object.assign(this, attach) } - } diff --git a/src/index.js b/src/index.js index 81d0d1f4..e8be4c3e 100644 --- a/src/index.js +++ b/src/index.js @@ -1,3 +1,7 @@ +import { debugFactory } from './debug.js' +import { AddressBookHome } from './models/addressBookHome.js' +import { CalendarHome } from './models/calendarHome.js' +import { Principal } from './models/principal.js' /** * CDAV Library * @@ -10,11 +14,6 @@ import Parser from './parser.js' import Request from './request.js' import * as NS from './utility/namespaceUtility.js' import * as XMLUtility from './utility/xmlUtility.js' -import { CalendarHome } from './models/calendarHome.js' -import { AddressBookHome } from './models/addressBookHome.js' -import { Principal } from './models/principal.js' - -import { debugFactory } from './debug.js' const debug = debugFactory('index.js') export { debugFactory as debug, NS as namespaces } @@ -23,13 +22,13 @@ export { debugFactory as debug, NS as namespaces } * */ export default class DavClient { - /** * @param {object} options * @param {string} options.rootUrl * @param {{[name: string]: any}} [options.defaultHeaders] A dictionary of default headers to apply to each request. * @param {object} factories */ + // eslint-disable-next-line no-unused-vars constructor(options, factories = {}) { /** * root URL of DAV Server @@ -111,6 +110,7 @@ export default class DavClient { /** * initializes the DAVClient + * * @param {object} options * @return {Promise} */ @@ -218,8 +218,7 @@ export default class DavClient { * @return {Promise<[]>} */ async principalPropertySearchByAddressAndStory(address, story) { - const [skeleton] = XMLUtility.getRootSkeleton( - [NS.DAV, 'principal-property-search']) + const [skeleton] = XMLUtility.getRootSkeleton([NS.DAV, 'principal-property-search']) skeleton.children.push({ name: [NS.DAV, 'property-search'], @@ -372,6 +371,7 @@ export default class DavClient { /** * performs a principal property search + * * @see https://tools.ietf.org/html/rfc3744#section-9.4 * * @param {Array} props @@ -432,6 +432,7 @@ export default class DavClient { return new Principal(null, this._request, principalUrl, body) }).catch((err) => { // TODO: improve error handling + // eslint-disable-next-line no-console console.debug(err) }) } @@ -461,6 +462,7 @@ export default class DavClient { return principals } catch (err) { // TODO: improve error handling + // eslint-disable-next-line no-console console.debug(err) } } @@ -519,6 +521,7 @@ export default class DavClient { /** * Fetches the group-member-set of a principal collection (e.g. a calendar-proxy group). + * * @see https://tools.ietf.org/html/rfc3744#section-4.3 * * @param {string} groupUrl Absolute URL of the proxy group principal @@ -534,6 +537,7 @@ export default class DavClient { /** * Sets the group-member-set of a principal collection (e.g. a calendar-proxy group). + * * @see https://tools.ietf.org/html/rfc3744#section-4.3 * * @param {string} groupUrl Absolute URL of the proxy group principal @@ -561,6 +565,7 @@ export default class DavClient { /** * Fetches the group-membership of a principal (the groups it belongs to). + * * @see https://tools.ietf.org/html/rfc3744#section-4.4 * * @param {string} principalUrl Absolute URL of the principal @@ -636,7 +641,7 @@ export default class DavClient { * * @param {string} ownerPrincipalUrl Absolute URL of the principal who owns the proxy group * @param {string} delegatePrincipalUrl Absolute or relative URL of the principal to add as delegate - * @param {'write'|'read'} [permission='write'] The proxy group to add the delegate to + * @param {'write'|'read'} [permission] The proxy group to add the delegate to * @return {Promise} */ async addDelegate(ownerPrincipalUrl, delegatePrincipalUrl, permission = 'write') { @@ -653,7 +658,7 @@ export default class DavClient { * * @param {string} ownerPrincipalUrl Absolute URL of the principal who owns the proxy group * @param {string} delegatePrincipalUrl Absolute or relative URL of the principal to remove - * @param {'write'|'read'} [permission='write'] The proxy group to remove the delegate from + * @param {'write'|'read'} [permission] The proxy group to remove the delegate from * @return {Promise} */ async removeDelegate(ownerPrincipalUrl, delegatePrincipalUrl, permission = 'write') { @@ -797,5 +802,4 @@ export default class DavClient { const url = this._request.pathname(this.rootUrl) + 'public-calendars/' this.publicCalendarHome = new CalendarHome(this, this._request, url, {}) } - } diff --git a/src/models/addressBook.js b/src/models/addressBook.js index 79f3ad30..f5f27ef0 100644 --- a/src/models/addressBook.js +++ b/src/models/addressBook.js @@ -7,15 +7,14 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ -import { davCollectionShareable } from './davCollectionShareable.js' -import { DavCollection } from './davCollection.js' +import { debugFactory } from '../debug.js' +import addressBookPropSet from '../propset/addressBookPropSet.js' import * as NS from '../utility/namespaceUtility.js' import * as StringUtility from '../utility/stringUtility.js' import * as XMLUtility from '../utility/xmlUtility.js' -import addressBookPropSet from '../propset/addressBookPropSet.js' +import { DavCollection } from './davCollection.js' +import { davCollectionShareable } from './davCollectionShareable.js' import { VCard } from './vcard.js' - -import { debugFactory } from '../debug.js' const debug = debugFactory('AddressBook') /** @@ -33,7 +32,6 @@ const debug = debugFactory('AddressBook') * @augments DavCollection */ export class AddressBook extends davCollectionShareable(DavCollection) { - /** * @inheritDoc */ @@ -121,9 +119,7 @@ export class AddressBook extends davCollectionShareable(DavCollection) { async addressbookQuery(filter, prop = null, limit = null, test = 'anyof') { debug('sending an addressbook-query request') - const [skeleton] = XMLUtility.getRootSkeleton( - [NS.IETF_CARDDAV, 'addressbook-query'], - ) + const [skeleton] = XMLUtility.getRootSkeleton([NS.IETF_CARDDAV, 'addressbook-query']) if (!prop) { skeleton.children.push({ @@ -221,9 +217,7 @@ export class AddressBook extends davCollectionShareable(DavCollection) { * @private */ _buildMultiGetBody(hrefs, prop) { - const [skeleton] = XMLUtility.getRootSkeleton( - [NS.IETF_CARDDAV, 'addressbook-multiget'], - ) + const [skeleton] = XMLUtility.getRootSkeleton([NS.IETF_CARDDAV, 'addressbook-multiget']) if (!prop) { skeleton.children.push({ @@ -283,5 +277,4 @@ export class AddressBook extends davCollectionShareable(DavCollection) { return !!addressBookDataProperty.children } - } diff --git a/src/models/addressBookHome.js b/src/models/addressBookHome.js index 65e04f68..f2bfb40a 100644 --- a/src/models/addressBookHome.js +++ b/src/models/addressBookHome.js @@ -7,11 +7,10 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ -import { DavCollection } from './davCollection.js' +import { debugFactory } from '../debug.js' import * as NS from '../utility/namespaceUtility.js' import { AddressBook } from './addressBook.js' - -import { debugFactory } from '../debug.js' +import { DavCollection } from './davCollection.js' const debug = debugFactory('AddressBookHome') /** @@ -23,7 +22,6 @@ const debug = debugFactory('AddressBookHome') * a server to return multiple address book homes though. */ export class AddressBookHome extends DavCollection { - /** * @inheritDoc */ @@ -66,5 +64,4 @@ export class AddressBookHome extends DavCollection { const name = super._getAvailableNameFromToken(displayname) return super.createCollection(name, props) } - } diff --git a/src/models/calendar.js b/src/models/calendar.js index 66048006..38140d0d 100644 --- a/src/models/calendar.js +++ b/src/models/calendar.js @@ -7,16 +7,15 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ -import { DavCollection } from './davCollection.js' -import { davCollectionPublishable } from './davCollectionPublishable.js' -import { davCollectionShareable } from './davCollectionShareable.js' -import { VObject } from './vobject.js' +import { debugFactory } from '../debug.js' import calendarPropSet from '../propset/calendarPropSet.js' import * as NS from '../utility/namespaceUtility.js' import * as StringUtility from '../utility/stringUtility.js' import * as XMLUtility from '../utility/xmlUtility.js' - -import { debugFactory } from '../debug.js' +import { DavCollection } from './davCollection.js' +import { davCollectionPublishable } from './davCollectionPublishable.js' +import { davCollectionShareable } from './davCollectionShareable.js' +import { VObject } from './vobject.js' const debug = debugFactory('Calendar') /** @@ -40,7 +39,6 @@ const debug = debugFactory('Calendar') * @augments DavCollection */ export class Calendar extends davCollectionPublishable(davCollectionShareable(DavCollection)) { - /** * @inheritDoc */ @@ -147,9 +145,7 @@ export class Calendar extends davCollectionPublishable(davCollectionShareable(Da async calendarQuery(filter, prop = null, timezone = null) { debug('sending an calendar-query request') - const [skeleton] = XMLUtility.getRootSkeleton( - [NS.IETF_CALDAV, 'calendar-query'], - ) + const [skeleton] = XMLUtility.getRootSkeleton([NS.IETF_CALDAV, 'calendar-query']) if (!prop) { skeleton.children.push({ @@ -203,9 +199,7 @@ export class Calendar extends davCollectionPublishable(davCollectionShareable(Da return [] } - const [skeleton] = XMLUtility.getRootSkeleton( - [NS.IETF_CALDAV, 'calendar-multiget'], - ) + const [skeleton] = XMLUtility.getRootSkeleton([NS.IETF_CALDAV, 'calendar-multiget']) if (!prop) { skeleton.children.push({ @@ -242,24 +236,24 @@ export class Calendar extends davCollectionPublishable(davCollectionShareable(Da * @param {Date} to * @return {Promise} */ + // eslint-disable-next-line no-unused-vars async freeBusyQuery(from, to) { - /* eslint-disable no-tabs */ + // debug('sending a free-busy-query request'); // // const [skeleton] = XMLUtility.getRootSkeleton( - // [NS.IETF_CALDAV, 'free-busy-query'], - // [NS.IETF_CALDAV, 'time-range'] + // [NS.IETF_CALDAV, 'free-busy-query'], + // [NS.IETF_CALDAV, 'time-range'] // ); // // skeleton[0][0].attributes.push(['start', Calendar._getICalendarDateTimeFromDateObject(from)]); // skeleton[0][0].attributes.push(['end', Calendar._getICalendarDateTimeFromDateObject(to)]); // // const headers = { - // 'Depth': '1' + // 'Depth': '1' // }; // const body = XMLUtility.serialize(skeleton); // const response = await this._request.report(this.url, headers, body); - /* eslint-enable no-tabs */ // TODO - finish implementation } @@ -336,5 +330,4 @@ export class Calendar extends davCollectionPublishable(davCollectionShareable(Da 'Z', ].join('') } - } diff --git a/src/models/calendarHome.js b/src/models/calendarHome.js index 22559635..08b352c8 100644 --- a/src/models/calendarHome.js +++ b/src/models/calendarHome.js @@ -7,17 +7,16 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ -import { DavCollection } from './davCollection.js' -import { Calendar } from './calendar.js' -import { Subscription } from './subscription.js' -import ScheduleInbox from './scheduleInbox.js' -import ScheduleOutbox from './scheduleOutbox.js' +import { debugFactory } from '../debug.js' import * as NS from '../utility/namespaceUtility.js' import * as XMLUtility from '../utility/xmlUtility.js' - -import { debugFactory } from '../debug.js' +import { Calendar } from './calendar.js' import { CalendarTrashBin } from './calendarTrashBin.js' +import { DavCollection } from './davCollection.js' import { DeletedCalendar } from './deletedCalendar.js' +import ScheduleInbox from './scheduleInbox.js' +import ScheduleOutbox from './scheduleOutbox.js' +import { Subscription } from './subscription.js' const debug = debugFactory('CalendarHome') /** @@ -29,7 +28,6 @@ const debug = debugFactory('CalendarHome') * a server to return multiple calendar homes though. */ export class CalendarHome extends DavCollection { - /** * @inheritDoc */ @@ -71,12 +69,12 @@ export class CalendarHome extends DavCollection { const collections = await super.findAll() return { - calendars: collections.filter(c => c instanceof Calendar && !(c instanceof ScheduleInbox) && !(c instanceof Subscription) && !(c instanceof DeletedCalendar)), - deletedCalendars: collections.filter(c => c instanceof DeletedCalendar), - trashBins: collections.filter(c => c instanceof CalendarTrashBin), - subscriptions: collections.filter(c => c instanceof Subscription), - scheduleInboxes: collections.filter(c => c instanceof ScheduleInbox), - scheduleOutboxes: collections.filter(c => c instanceof ScheduleOutbox), + calendars: collections.filter((c) => c instanceof Calendar && !(c instanceof ScheduleInbox) && !(c instanceof Subscription) && !(c instanceof DeletedCalendar)), + deletedCalendars: collections.filter((c) => c instanceof DeletedCalendar), + trashBins: collections.filter((c) => c instanceof CalendarTrashBin), + subscriptions: collections.filter((c) => c instanceof Subscription), + scheduleInboxes: collections.filter((c) => c instanceof ScheduleInbox), + scheduleOutboxes: collections.filter((c) => c instanceof ScheduleOutbox), } } @@ -254,12 +252,9 @@ export class CalendarHome extends DavCollection { * @return {Promise} */ async enableBirthdayCalendar() { - const [skeleton] = XMLUtility.getRootSkeleton( - [NS.NEXTCLOUD, 'enable-birthday-calendar'], - ) + const [skeleton] = XMLUtility.getRootSkeleton([NS.NEXTCLOUD, 'enable-birthday-calendar']) const xmlBody = XMLUtility.serialize(skeleton) await this._request.post(this.url, {}, xmlBody) } - } diff --git a/src/models/calendarTrashBin.js b/src/models/calendarTrashBin.js index 8f403207..9c2afb5a 100644 --- a/src/models/calendarTrashBin.js +++ b/src/models/calendarTrashBin.js @@ -7,13 +7,12 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ -import { DavCollection } from './davCollection.js' import * as NS from '../utility/namespaceUtility.js' -import { DeletedCalendarObject } from './deletedCalendarObject.js' import * as XMLUtility from '../utility/xmlUtility.js' +import { DavCollection } from './davCollection.js' +import { DeletedCalendarObject } from './deletedCalendarObject.js' export class CalendarTrashBin extends DavCollection { - /** * @inheritDoc */ @@ -26,9 +25,7 @@ export class CalendarTrashBin extends DavCollection { } async findDeletedObjects() { - const [skeleton] = XMLUtility.getRootSkeleton( - [NS.IETF_CALDAV, 'calendar-query'], - ) + const [skeleton] = XMLUtility.getRootSkeleton([NS.IETF_CALDAV, 'calendar-query']) skeleton.children.push({ name: [NS.DAV, 'prop'], children: DeletedCalendarObject.getPropFindList() @@ -61,5 +58,4 @@ export class CalendarTrashBin extends DavCollection { async restore(uri) { await this._request.move(uri, this._url + 'restore/file') } - } diff --git a/src/models/davCollection.js b/src/models/davCollection.js index 522b456e..a1a6b479 100644 --- a/src/models/davCollection.js +++ b/src/models/davCollection.js @@ -7,18 +7,16 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ +import { debugFactory } from '../debug.js' +import davCollectionPropSet from '../propset/davCollectionPropSet.js' import * as NS from '../utility/namespaceUtility.js' import * as StringUtility from '../utility/stringUtility.js' import * as XMLUtility from '../utility/xmlUtility.js' import DAVEventListener from './davEventListener.js' - -import { debugFactory } from '../debug.js' -import davCollectionPropSet from '../propset/davCollectionPropSet.js' import { DavObject } from './davObject.js' const debug = debugFactory('DavCollection') export class DavCollection extends DAVEventListener { - /** * @param {object} parent * @param {Request} request @@ -181,7 +179,8 @@ export class DavCollection extends DAVEventListener { const [skeleton, dPropSet] = XMLUtility.getRootSkeleton( [NS.DAV, 'propertyupdate'], [NS.DAV, 'set'], - [NS.DAV, 'prop']) + [NS.DAV, 'prop'], + ) dPropSet.push(...propSet) @@ -297,6 +296,7 @@ export class DavCollection extends DAVEventListener { /** * checks whether this is of the same type as another collection + * * @param {DavCollection} collection */ isSameCollectionTypeAs(collection) { @@ -376,7 +376,7 @@ export class DavCollection extends DAVEventListener { * @return {string} */ _getAvailableNameFromToken(token) { - return StringUtility.uri(token, name => { + return StringUtility.uri(token, (name) => { return this._childrenNames.indexOf(this._url + name) === -1 && this._childrenNames.indexOf(this._url + name + '/') === -1 }) @@ -384,6 +384,7 @@ export class DavCollection extends DAVEventListener { /** * get updated properties for this collection from server + * * @protected * @return {object} */ @@ -467,5 +468,4 @@ export class DavCollection extends DAVEventListener { [NS.DAV, 'current-user-privilege-set'], ] } - } diff --git a/src/models/davCollectionPublishable.js b/src/models/davCollectionPublishable.js index 2bf92c38..abe7b5bf 100644 --- a/src/models/davCollectionPublishable.js +++ b/src/models/davCollectionPublishable.js @@ -7,10 +7,9 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ +import { debugFactory } from '../debug.js' import * as NS from '../utility/namespaceUtility.js' import * as XMLUtility from '../utility/xmlUtility.js' - -import { debugFactory } from '../debug.js' const debug = debugFactory('DavCollectionPublishable') /** @@ -19,7 +18,6 @@ const debug = debugFactory('DavCollectionPublishable') */ export function davCollectionPublishable(Base) { return class extends Base { - /** * @inheritDoc */ @@ -37,8 +35,7 @@ export function davCollectionPublishable(Base) { async publish() { debug(`Publishing ${this.url}`) - const [skeleton] = XMLUtility.getRootSkeleton( - [NS.CALENDARSERVER, 'publish-calendar']) + const [skeleton] = XMLUtility.getRootSkeleton([NS.CALENDARSERVER, 'publish-calendar']) const xml = XMLUtility.serialize(skeleton) // TODO - ideally the server should return a 'pre-publish-url' as described in the standard @@ -55,8 +52,7 @@ export function davCollectionPublishable(Base) { async unpublish() { debug(`Unpublishing ${this.url}`) - const [skeleton] = XMLUtility.getRootSkeleton( - [NS.CALENDARSERVER, 'unpublish-calendar']) + const [skeleton] = XMLUtility.getRootSkeleton([NS.CALENDARSERVER, 'unpublish-calendar']) const xml = XMLUtility.serialize(skeleton) await this._request.post(this._url, { 'Content-Type': 'application/xml; charset=utf-8' }, xml) @@ -71,6 +67,5 @@ export function davCollectionPublishable(Base) { [NS.CALENDARSERVER, 'publish-url'], ]) } - } } diff --git a/src/models/davCollectionShareable.js b/src/models/davCollectionShareable.js index a6daa0e1..188024b7 100644 --- a/src/models/davCollectionShareable.js +++ b/src/models/davCollectionShareable.js @@ -7,10 +7,9 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ +import { debugFactory } from '../debug.js' import * as NS from '../utility/namespaceUtility.js' import * as XMLUtility from '../utility/xmlUtility.js' - -import { debugFactory } from '../debug.js' const debug = debugFactory('DavCollectionShareable') /** @@ -19,7 +18,6 @@ const debug = debugFactory('DavCollectionShareable') */ export function davCollectionShareable(Base) { return class extends Base { - /** * @inheritDoc */ @@ -41,7 +39,9 @@ export function davCollectionShareable(Base) { async share(principalScheme, writeable = false, summary = '') { debug(`Sharing ${this.url} with ${principalScheme}`) const [skeleton, setProp] = XMLUtility.getRootSkeleton( - [NS.OWNCLOUD, 'share'], [NS.OWNCLOUD, 'set']) + [NS.OWNCLOUD, 'share'], + [NS.OWNCLOUD, 'set'], + ) setProp.push({ name: [NS.DAV, 'href'], @@ -88,7 +88,9 @@ export function davCollectionShareable(Base) { debug(`Unsharing ${this.url} with ${principalScheme}`) const [skeleton, oSetChildren] = XMLUtility.getRootSkeleton( - [NS.OWNCLOUD, 'share'], [NS.OWNCLOUD, 'remove']) + [NS.OWNCLOUD, 'share'], + [NS.OWNCLOUD, 'remove'], + ) oSetChildren.push({ name: [NS.DAV, 'href'], @@ -141,6 +143,5 @@ export function davCollectionShareable(Base) { [NS.CALENDARSERVER, 'allowed-sharing-modes'], ]) } - } } diff --git a/src/models/davEvent.js b/src/models/davEvent.js index bd6be71d..bc7ea7ba 100644 --- a/src/models/davEvent.js +++ b/src/models/davEvent.js @@ -8,7 +8,6 @@ */ export default class DAVEvent { - /** * * @param {string} type @@ -19,5 +18,4 @@ export default class DAVEvent { type, }, options) } - } diff --git a/src/models/davEventListener.js b/src/models/davEventListener.js index 2f6424ce..4c47d41b 100644 --- a/src/models/davEventListener.js +++ b/src/models/davEventListener.js @@ -8,7 +8,6 @@ */ export default class DAVEventListener { - constructor() { this._eventListeners = {} } @@ -65,13 +64,12 @@ export default class DAVEventListener { } }) - listenersToCallAndRemove.forEach(listener => { + listenersToCallAndRemove.forEach((listener) => { this.removeEventListener(type, listener) listener(event) }) - listenersToCall.forEach(listener => { + listenersToCall.forEach((listener) => { listener(event) }) } - } diff --git a/src/models/davObject.js b/src/models/davObject.js index ef19e675..a3e82bb1 100644 --- a/src/models/davObject.js +++ b/src/models/davObject.js @@ -7,12 +7,11 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ -import DAVEventListener from './davEventListener.js' +import { debugFactory } from '../debug.js' import NetworkRequestClientError from '../errors/networkRequestClientError.js' import * as NS from '../utility/namespaceUtility.js' - -import { debugFactory } from '../debug.js' import * as XMLUtility from '../utility/xmlUtility.js' +import DAVEventListener from './davEventListener.js' const debug = debugFactory('DavObject') /** @@ -20,7 +19,6 @@ const debug = debugFactory('DavObject') * @classdesc Generic DavObject aka file */ export class DavObject extends DAVEventListener { - /** * @param {DavCollection} parent - The parent collection this DavObject is a child of * @param {Request} request - The request object initialized by DavClient @@ -73,6 +71,7 @@ export class DavObject extends DAVEventListener { /** * copies a DavObject to a different DavCollection + * * @param {DavCollection} collection * @param {boolean} overwrite * @param headers @@ -100,6 +99,7 @@ export class DavObject extends DAVEventListener { /** * moves a DavObject to a different DavCollection + * * @param {DavCollection} collection * @param {boolean} overwrite * @param headers @@ -128,6 +128,7 @@ export class DavObject extends DAVEventListener { /** * updates the DavObject on the server + * * @return {Promise} */ async update() { @@ -152,7 +153,7 @@ export class DavObject extends DAVEventListener { this._isDirty = false // Don't overwrite content-type, it's set to text/html in the response ... this._props['{DAV:}getetag'] = res.headers.etag || null - Object.entries(this._updatedProperties).forEach(entry => { + Object.entries(this._updatedProperties).forEach((entry) => { const [key, value] = entry if (value === '{urn:ietf:params:xml:ns:carddav}address-data') { @@ -200,14 +201,15 @@ export class DavObject extends DAVEventListener { const [skeleton, dPropSet] = XMLUtility.getRootSkeleton( [NS.DAV, 'propertyupdate'], [NS.DAV, 'set'], - [NS.DAV, 'prop']) + [NS.DAV, 'prop'], + ) dPropSet.push(...propSet) if (propSet.length >= 1) { const body = XMLUtility.serialize(skeleton) await this._request.propPatch(this._url, {}, body) - Object.entries(this._updatedProperties).forEach(entry => { + Object.entries(this._updatedProperties).forEach((entry) => { const [key, value] = entry if (value !== '{urn:ietf:params:xml:ns:carddav}address-data') { @@ -299,5 +301,4 @@ export class DavObject extends DAVEventListener { _registerPropSetFactory(factory) { this._propSetFactory.push(factory) } - } diff --git a/src/models/deletedCalendarObject.js b/src/models/deletedCalendarObject.js index 31516f8b..68547db7 100644 --- a/src/models/deletedCalendarObject.js +++ b/src/models/deletedCalendarObject.js @@ -7,8 +7,8 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ -import { VObject } from './vobject.js' import * as NS from '../utility/namespaceUtility.js' +import { VObject } from './vobject.js' /** * This class represents a deleted calendar object from a calendar trash bin. @@ -16,7 +16,6 @@ import * as NS from '../utility/namespaceUtility.js' * @augments VObject */ export class DeletedCalendarObject extends VObject { - /** * @inheritDoc */ @@ -61,5 +60,4 @@ export class DeletedCalendarObject extends VObject { [NS.NEXTCLOUD, 'delegator'], ]) } - } diff --git a/src/models/principal.js b/src/models/principal.js index b2032c3b..83feba51 100644 --- a/src/models/principal.js +++ b/src/models/principal.js @@ -7,11 +7,10 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ -import { DavObject } from './davObject.js' +import prinicipalPropSet from '../propset/principalPropSet.js' import * as NS from '../utility/namespaceUtility.js' import * as XMLUtility from '../utility/xmlUtility.js' - -import prinicipalPropSet from '../propset/principalPropSet.js' +import { DavObject } from './davObject.js' /** * @typedef {object} PrincipalPropfindOptions @@ -24,7 +23,6 @@ import prinicipalPropSet from '../propset/principalPropSet.js' * @class */ export class Principal extends DavObject { - /** * Creates an object that represents a single principal * as specified in RFC 3744 @@ -124,7 +122,7 @@ export class Principal extends DavObject { this.roomBuildingAddress, ] return data - .filter(value => !!value) + .filter((value) => !!value) .join(', ') }, }, @@ -213,9 +211,7 @@ export class Principal extends DavObject { ) } if (options.enableCardDAV) { - list.push( - [NS.IETF_CARDDAV, 'addressbook-home-set'], - ) + list.push([NS.IETF_CARDDAV, 'addressbook-home-set']) } return list @@ -241,7 +237,8 @@ export class Principal extends DavObject { const [skeleton, dPropSet] = XMLUtility.getRootSkeleton( [NS.DAV, 'propertyupdate'], [NS.DAV, 'set'], - [NS.DAV, 'prop']) + [NS.DAV, 'prop'], + ) dPropSet.push(...propSet) @@ -251,5 +248,4 @@ export class Principal extends DavObject { this._updatedProperties = [] } } - } diff --git a/src/models/scheduleInbox.js b/src/models/scheduleInbox.js index b406fe3e..11fb2ebf 100644 --- a/src/models/scheduleInbox.js +++ b/src/models/scheduleInbox.js @@ -7,12 +7,11 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ -import { Calendar } from './calendar.js' -import * as NS from '../utility/namespaceUtility.js' import scheduleInboxPropSet from '../propset/scheduleInboxPropSet.js' +import * as NS from '../utility/namespaceUtility.js' +import { Calendar } from './calendar.js' export default class ScheduleInbox extends Calendar { - /** * @inheritDoc */ @@ -33,5 +32,4 @@ export default class ScheduleInbox extends Calendar { [NS.IETF_CALDAV, 'calendar-availability'], ]) } - } diff --git a/src/models/scheduleOutbox.js b/src/models/scheduleOutbox.js index 7900ad41..3a4ed280 100644 --- a/src/models/scheduleOutbox.js +++ b/src/models/scheduleOutbox.js @@ -7,11 +7,10 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ -import { DavCollection } from './davCollection.js' import * as NS from '../utility/namespaceUtility.js' +import { DavCollection } from './davCollection.js' export default class ScheduleOutbox extends DavCollection { - /** * Sends a free-busy-request for the scheduling outbox * The data is required to be a valid iTIP data. @@ -47,5 +46,4 @@ export default class ScheduleOutbox extends DavCollection { return result } - } diff --git a/src/models/subscription.js b/src/models/subscription.js index 685c8b2e..a285c4d8 100644 --- a/src/models/subscription.js +++ b/src/models/subscription.js @@ -7,8 +7,8 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ -import { Calendar } from './calendar.js' import * as NS from '../utility/namespaceUtility.js' +import { Calendar } from './calendar.js' /** * This class represents a subscription collection @@ -17,7 +17,6 @@ import * as NS from '../utility/namespaceUtility.js' * On top of that it contains more non-standard apple properties */ export class Subscription extends Calendar { - /** * @inheritDoc */ @@ -43,5 +42,4 @@ export class Subscription extends Calendar { [NS.CALENDARSERVER, 'subscribed-strip-attachments'], ]) } - } diff --git a/src/models/vcard.js b/src/models/vcard.js index da7b048f..f7340985 100644 --- a/src/models/vcard.js +++ b/src/models/vcard.js @@ -7,15 +7,14 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ -import { DavObject } from './davObject.js' -import * as NS from '../utility/namespaceUtility.js' import vcardPropSet from '../propset/vcardPropSet.js' +import * as NS from '../utility/namespaceUtility.js' +import { DavObject } from './davObject.js' /** * @class */ export class VCard extends DavObject { - /** * Creates a VCard that is supposed to store address-data * as specified in RFC 6350. @@ -42,5 +41,4 @@ export class VCard extends DavObject { [NS.IETF_CARDDAV, 'address-data'], ]) } - } diff --git a/src/models/vobject.js b/src/models/vobject.js index d3c003ed..c53c6db6 100644 --- a/src/models/vobject.js +++ b/src/models/vobject.js @@ -7,14 +7,13 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ -import { DavObject } from './davObject.js' import * as NS from '../utility/namespaceUtility.js' +import { DavObject } from './davObject.js' /** * @class */ export class VObject extends DavObject { - /** * Creates a VObject that is supposed to store calendar-data * as specified in RFC 5545. @@ -37,5 +36,4 @@ export class VObject extends DavObject { [NS.IETF_CALDAV, 'calendar-data'], ]) } - } diff --git a/src/parser.js b/src/parser.js index 149d174a..052f384f 100644 --- a/src/parser.js +++ b/src/parser.js @@ -11,13 +11,13 @@ * */ export default class Parser { - /** * */ constructor() { /** * Key Value Map of propertyName => parser + * * @type {object} * @private */ @@ -34,7 +34,7 @@ export default class Parser { * @return {boolean} */ canParse(propertyName) { - return Object.prototype.hasOwnProperty.call(this._parser, propertyName) + return Object.hasOwn(this._parser, propertyName) } /** @@ -609,5 +609,4 @@ export default class Parser { return result } - } diff --git a/src/propset/addressBookPropSet.js b/src/propset/addressBookPropSet.js index e65ad1dc..d71fb11d 100644 --- a/src/propset/addressBookPropSet.js +++ b/src/propset/addressBookPropSet.js @@ -23,22 +23,22 @@ export default function addressBookPropSet(props) { Object.entries(props).forEach(([key, value]) => { switch (key) { - case '{urn:ietf:params:xml:ns:carddav}addressbook-description': - xmlified.push({ - name: [NS.IETF_CARDDAV, 'addressbook-description'], - value, - }) - break + case '{urn:ietf:params:xml:ns:carddav}addressbook-description': + xmlified.push({ + name: [NS.IETF_CARDDAV, 'addressbook-description'], + value, + }) + break - case '{http://owncloud.org/ns}enabled': - xmlified.push({ - name: [NS.OWNCLOUD, 'enabled'], - value: value ? '1' : '0', - }) - break + case '{http://owncloud.org/ns}enabled': + xmlified.push({ + name: [NS.OWNCLOUD, 'enabled'], + value: value ? '1' : '0', + }) + break - default: - break + default: + break } }) diff --git a/src/propset/calendarPropSet.js b/src/propset/calendarPropSet.js index 62610804..70142c00 100644 --- a/src/propset/calendarPropSet.js +++ b/src/propset/calendarPropSet.js @@ -29,72 +29,72 @@ export default function calendarPropSet(props) { Object.entries(props).forEach(([key, value]) => { switch (key) { - case '{http://apple.com/ns/ical/}calendar-order': - xmlified.push({ - name: [NS.APPLE, 'calendar-order'], - value: value.toString(), - }) - break + case '{http://apple.com/ns/ical/}calendar-order': + xmlified.push({ + name: [NS.APPLE, 'calendar-order'], + value: value.toString(), + }) + break - case '{http://apple.com/ns/ical/}calendar-color': - xmlified.push({ - name: [NS.APPLE, 'calendar-color'], - value, - }) - break - - case '{http://calendarserver.org/ns/}source': - xmlified.push({ - name: [NS.CALENDARSERVER, 'source'], - children: [{ - name: [NS.DAV, 'href'], + case '{http://apple.com/ns/ical/}calendar-color': + xmlified.push({ + name: [NS.APPLE, 'calendar-color'], value, - }], - }) - break + }) + break + + case '{http://calendarserver.org/ns/}source': + xmlified.push({ + name: [NS.CALENDARSERVER, 'source'], + children: [{ + name: [NS.DAV, 'href'], + value, + }], + }) + break - case '{urn:ietf:params:xml:ns:caldav}calendar-description': - xmlified.push({ - name: [NS.IETF_CALDAV, 'calendar-description'], - value, - }) - break + case '{urn:ietf:params:xml:ns:caldav}calendar-description': + xmlified.push({ + name: [NS.IETF_CALDAV, 'calendar-description'], + value, + }) + break - case '{urn:ietf:params:xml:ns:caldav}calendar-timezone': - xmlified.push({ - name: [NS.IETF_CALDAV, 'calendar-timezone'], - value, - }) - break + case '{urn:ietf:params:xml:ns:caldav}calendar-timezone': + xmlified.push({ + name: [NS.IETF_CALDAV, 'calendar-timezone'], + value, + }) + break - case '{http://owncloud.org/ns}calendar-enabled': - xmlified.push({ - name: [NS.OWNCLOUD, 'calendar-enabled'], - value: value ? '1' : '0', - }) - break - case '{http://nextcloud.com/ns}default-alarm-part-day': - xmlified.push({ - name: [NS.NEXTCLOUD, 'default-alarm-part-day'], - value, - }) - break - case '{http://nextcloud.com/ns}default-alarm-full-day': - xmlified.push({ - name: [NS.NEXTCLOUD, 'default-alarm-full-day'], - value, - }) - break - case '{urn:ietf:params:xml:ns:caldav}schedule-calendar-transp': - xmlified.push({ - name: [NS.IETF_CALDAV, 'schedule-calendar-transp'], - children: [{ - name: [NS.IETF_CALDAV, value], - }], - }) - break - default: - break + case '{http://owncloud.org/ns}calendar-enabled': + xmlified.push({ + name: [NS.OWNCLOUD, 'calendar-enabled'], + value: value ? '1' : '0', + }) + break + case '{http://nextcloud.com/ns}default-alarm-part-day': + xmlified.push({ + name: [NS.NEXTCLOUD, 'default-alarm-part-day'], + value, + }) + break + case '{http://nextcloud.com/ns}default-alarm-full-day': + xmlified.push({ + name: [NS.NEXTCLOUD, 'default-alarm-full-day'], + value, + }) + break + case '{urn:ietf:params:xml:ns:caldav}schedule-calendar-transp': + xmlified.push({ + name: [NS.IETF_CALDAV, 'schedule-calendar-transp'], + children: [{ + name: [NS.IETF_CALDAV, value], + }], + }) + break + default: + break } }) diff --git a/src/propset/davCollectionPropSet.js b/src/propset/davCollectionPropSet.js index 8c626b4f..7bd924e6 100644 --- a/src/propset/davCollectionPropSet.js +++ b/src/propset/davCollectionPropSet.js @@ -22,15 +22,15 @@ export default function davCollectionPropSet(props) { Object.entries(props).forEach(([key, value]) => { switch (key) { - case '{DAV:}displayname': - xmlified.push({ - name: [NS.DAV, 'displayname'], - value, - }) - break + case '{DAV:}displayname': + xmlified.push({ + name: [NS.DAV, 'displayname'], + value, + }) + break - default: - break + default: + break } }) diff --git a/src/propset/principalPropSet.js b/src/propset/principalPropSet.js index f321698a..f52c22d0 100644 --- a/src/propset/principalPropSet.js +++ b/src/propset/principalPropSet.js @@ -21,17 +21,17 @@ export default function prinicipalPropSet(props) { Object.entries(props).forEach(([key, value]) => { switch (key) { - case '{urn:ietf:params:xml:ns:caldav}schedule-default-calendar-URL': - xmlified.push({ - name: [NS.IETF_CALDAV, 'schedule-default-calendar-URL'], - children: [ - { - name: ['DAV:', 'href'], - value, - }, - ], - }) - break + case '{urn:ietf:params:xml:ns:caldav}schedule-default-calendar-URL': + xmlified.push({ + name: [NS.IETF_CALDAV, 'schedule-default-calendar-URL'], + children: [ + { + name: ['DAV:', 'href'], + value, + }, + ], + }) + break } }) diff --git a/src/propset/scheduleInboxPropSet.js b/src/propset/scheduleInboxPropSet.js index 9836cbb8..6b529cd4 100644 --- a/src/propset/scheduleInboxPropSet.js +++ b/src/propset/scheduleInboxPropSet.js @@ -21,12 +21,12 @@ export default function calendarPropSet(props) { Object.entries(props).forEach(([key, value]) => { switch (key) { - case '{urn:ietf:params:xml:ns:caldav}calendar-availability': - xmlified.push({ - name: [NS.IETF_CALDAV, 'calendar-availability'], - value: value.toString(), - }) - break + case '{urn:ietf:params:xml:ns:caldav}calendar-availability': + xmlified.push({ + name: [NS.IETF_CALDAV, 'calendar-availability'], + value: value.toString(), + }) + break } }) diff --git a/src/propset/vcardPropSet.js b/src/propset/vcardPropSet.js index 0c043dfc..cd2d0f25 100644 --- a/src/propset/vcardPropSet.js +++ b/src/propset/vcardPropSet.js @@ -22,15 +22,15 @@ export default function vcardPropSet(props) { Object.entries(props).forEach(([key, value]) => { switch (key) { - case '{http://nextcloud.com/ns}favorite': - xmlified.push({ - name: [NS.NEXTCLOUD, 'favorite'], - value: value ? '1' : null, - }) - break + case '{http://nextcloud.com/ns}favorite': + xmlified.push({ + name: [NS.NEXTCLOUD, 'favorite'], + value: value ? '1' : null, + }) + break - default: - break + default: + break } }) diff --git a/src/request.js b/src/request.js index e4b5a3c9..90f9d7b7 100644 --- a/src/request.js +++ b/src/request.js @@ -7,22 +7,20 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ -import * as NS from './utility/namespaceUtility.js' -import * as XMLUtility from './utility/xmlUtility.js' import axios from '@nextcloud/axios' - import NetworkRequestAbortedError from './errors/networkRequestAbortedError.js' -import NetworkRequestError from './errors/networkRequestError.js' -import NetworkRequestServerError from './errors/networkRequestServerError.js' import NetworkRequestClientError from './errors/networkRequestClientError.js' +import NetworkRequestError from './errors/networkRequestError.js' import NetworkRequestHttpError from './errors/networkRequestHttpError.js' +import NetworkRequestServerError from './errors/networkRequestServerError.js' +import * as NS from './utility/namespaceUtility.js' +import * as XMLUtility from './utility/xmlUtility.js' /** * Request class is used to send any kind of request to the DAV server * It also parses incoming XML responses */ export default class Request { - /** * Creates a new Request object * @@ -165,7 +163,6 @@ export default class Request { * @return {Promise<{body: string|object, status: number, headers: object}>} */ async lock(url, headers = {}, body = null, abortSignal = null) { - // TODO - add parameters for Depth and Timeout return this.request('LOCK', url, headers, body, abortSignal) @@ -182,7 +179,6 @@ export default class Request { * @return {Promise<{body: string|object, status: number, headers: object}>} */ async unlock(url, headers = {}, body = null, abortSignal = null) { - // TODO - add parameter for Lock-Token return this.request('UNLOCK', url, headers, body, abortSignal) @@ -205,7 +201,7 @@ export default class Request { // create request body const [skeleton, dPropChildren] = XMLUtility.getRootSkeleton([NS.DAV, 'propfind'], [NS.DAV, 'prop']) - dPropChildren.push(...properties.map(p => ({ name: p }))) + dPropChildren.push(...properties.map((p) => ({ name: p }))) const body = XMLUtility.serialize(skeleton) return this.request('PROPFIND', url, headers, body, abortSignal) @@ -265,7 +261,7 @@ export default class Request { * @return {Promise<{body: string|object, status: number, headers: object}>} */ async request(method, url, headers, body, abortSignal) { - const assignHeaders = Object.assign({}, getDefaultHeaders(), this.defaultHeaders, headers) + const assignHeaders = { ...getDefaultHeaders(), ...this.defaultHeaders, ...headers } try { const response = await axios.request({ url: this.absoluteUrl(url), @@ -336,8 +332,7 @@ export default class Request { /** * returns name of file / folder of a url * - * @param url - * @params {string} url + * @param {string} url * @return {string} */ filename(url) { @@ -353,8 +348,7 @@ export default class Request { /** * returns pathname for a URL * - * @param url - * @params {string} url + * @param {string} url * @return {string} */ pathname(url) { @@ -417,7 +411,6 @@ export default class Request { return result } - } /** diff --git a/src/utility/stringUtility.js b/src/utility/stringUtility.js index 1dd51b56..44fce127 100644 --- a/src/utility/stringUtility.js +++ b/src/utility/stringUtility.js @@ -13,7 +13,8 @@ */ function uuidv4() { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { - const r = Math.random() * 16 | 0; const v = c === 'x' ? r : (r & 0x3 | 0x8) + const r = Math.random() * 16 | 0 + const v = c === 'x' ? r : (r & 0x3 | 0x8) return v.toString(16).toUpperCase() }) } diff --git a/src/utility/xmlUtility.js b/src/utility/xmlUtility.js index 986169d7..e2241b44 100644 --- a/src/utility/xmlUtility.js +++ b/src/utility/xmlUtility.js @@ -11,9 +11,8 @@ const serializer = new XMLSerializer() let prefixMap = {} /** - * builds the root skeleton + * builds the root skeleton from the given namespace / name pairs * - * @params {...Array} array of namespace / name pairs * @return {*[]} */ export function getRootSkeleton() { @@ -49,7 +48,7 @@ export function getRootSkeleton() { */ export function serialize(json) { json = json || {} - if (typeof json !== 'object' || !Object.prototype.hasOwnProperty.call(json, 'name')) { + if (typeof json !== 'object' || !Object.hasOwn(json, 'name')) { return '' } @@ -104,7 +103,7 @@ export function resetPrefixMap() { * @param localName */ function getPrefixedNameForNamespace(ns, localName) { - if (!Object.prototype.hasOwnProperty.call(prefixMap, ns)) { + if (!Object.hasOwn(prefixMap, ns)) { prefixMap[ns] = 'x' + Object.keys(prefixMap).length }