From 43462d3fc447ac8d843e98e9dc596e21302b1353 Mon Sep 17 00:00:00 2001 From: Hendrik Leppelsack Date: Thu, 18 Feb 2016 16:33:26 +0100 Subject: integrate dav library instead of loading via bower --- js/dav/.bower.json | 12 + js/dav/.gitignore | 8 + js/dav/.npmignore | 11 + js/dav/.travis.yml | 12 + js/dav/CONTRIBUTING.md | 57 + js/dav/HISTORY.md | 271 + js/dav/LICENSE | 363 + js/dav/Makefile | 60 + js/dav/README.md | 467 ++ js/dav/dav.js | 7323 ++++++++++++++++++++ js/dav/lib/accounts.js | 178 + js/dav/lib/calendars.js | 274 + js/dav/lib/camelize.js | 11 + js/dav/lib/client.js | 115 + js/dav/lib/contacts.js | 291 + js/dav/lib/debug.js | 7 + js/dav/lib/fuzzy_url_equals.js | 10 + js/dav/lib/index.js | 14 + js/dav/lib/model.js | 106 + js/dav/lib/namespace.js | 4 + js/dav/lib/parser.js | 160 + js/dav/lib/polyfill/array_find.js | 25 + js/dav/lib/polyfill/object_assign.js | 35 + js/dav/lib/polyfill/regenerator_runtime.js | 564 ++ js/dav/lib/request.js | 233 + js/dav/lib/sandbox.js | 34 + js/dav/lib/template/address_book_query.js | 16 + js/dav/lib/template/calendar_query.js | 16 + js/dav/lib/template/filter.js | 20 + js/dav/lib/template/index.js | 6 + js/dav/lib/template/mkcol.js | 14 + js/dav/lib/template/prop.js | 65 + js/dav/lib/template/propfind.js | 12 + js/dav/lib/template/proppatch.js | 14 + js/dav/lib/template/sync_collection.js | 13 + js/dav/lib/transport.js | 185 + js/dav/lib/webdav.js | 117 + js/dav/lib/xmlhttprequest.js | 98 + js/dav/package.json | 43 + js/dav/test/integration/accounts_test.js | 177 + js/dav/test/integration/calendars_test.js | 239 + js/dav/test/integration/contacts_test.js | 219 + .../test/integration/data/bastille_day_party.ics | 12 + js/dav/test/integration/data/forrest_gump.vcf | 16 + js/dav/test/integration/data/index.js | 17 + js/dav/test/integration/server/bootstrap.js | 105 + js/dav/test/integration/server/calendarserver.php | 82 + js/dav/test/integration/version_test.js | 10 + js/dav/test/mocha.opts | 5 + js/dav/test/unit/camelize_test.js | 23 + js/dav/test/unit/client_test.js | 265 + js/dav/test/unit/data/address_book_query.xml | 72 + js/dav/test/unit/data/calendar_query.xml | 24 + js/dav/test/unit/data/current_user_principal.xml | 13 + js/dav/test/unit/data/index.js | 23 + js/dav/test/unit/data/propfind.xml | 39 + js/dav/test/unit/data/sync_collection.xml | 16 + js/dav/test/unit/nock_wrapper.js | 47 + js/dav/test/unit/parser_test.js | 66 + .../test/unit/request/address_book_query_test.js | 69 + js/dav/test/unit/request/basic_test.js | 63 + js/dav/test/unit/request/calendar_query_test.js | 107 + js/dav/test/unit/request/propfind_test.js | 84 + js/dav/test/unit/request/sync_collection_test.js | 65 + js/dav/test/unit/sandbox_test.js | 72 + js/dav/test/unit/template_test.js | 69 + js/dav/test/unit/transport_test.js | 256 + js/dav/test/unit/xmlhttprequest_test.js | 81 + js/public/script.js | 32 +- js/vendor/dav/.bower.json | 12 - js/vendor/dav/.gitignore | 8 - js/vendor/dav/.npmignore | 11 - js/vendor/dav/.travis.yml | 12 - js/vendor/dav/CONTRIBUTING.md | 57 - js/vendor/dav/HISTORY.md | 271 - js/vendor/dav/LICENSE | 363 - js/vendor/dav/Makefile | 60 - js/vendor/dav/README.md | 467 -- js/vendor/dav/dav.js | 7323 -------------------- js/vendor/dav/lib/accounts.js | 178 - js/vendor/dav/lib/calendars.js | 274 - js/vendor/dav/lib/camelize.js | 11 - js/vendor/dav/lib/client.js | 115 - js/vendor/dav/lib/contacts.js | 291 - js/vendor/dav/lib/debug.js | 7 - js/vendor/dav/lib/fuzzy_url_equals.js | 10 - js/vendor/dav/lib/index.js | 14 - js/vendor/dav/lib/model.js | 106 - js/vendor/dav/lib/namespace.js | 4 - js/vendor/dav/lib/parser.js | 160 - js/vendor/dav/lib/polyfill/array_find.js | 25 - js/vendor/dav/lib/polyfill/object_assign.js | 35 - js/vendor/dav/lib/polyfill/regenerator_runtime.js | 564 -- js/vendor/dav/lib/request.js | 233 - js/vendor/dav/lib/sandbox.js | 34 - js/vendor/dav/lib/template/address_book_query.js | 16 - js/vendor/dav/lib/template/calendar_query.js | 16 - js/vendor/dav/lib/template/filter.js | 20 - js/vendor/dav/lib/template/index.js | 6 - js/vendor/dav/lib/template/mkcol.js | 14 - js/vendor/dav/lib/template/prop.js | 65 - js/vendor/dav/lib/template/propfind.js | 12 - js/vendor/dav/lib/template/proppatch.js | 14 - js/vendor/dav/lib/template/sync_collection.js | 13 - js/vendor/dav/lib/transport.js | 185 - js/vendor/dav/lib/webdav.js | 117 - js/vendor/dav/lib/xmlhttprequest.js | 98 - js/vendor/dav/package.json | 43 - js/vendor/dav/test/integration/accounts_test.js | 177 - js/vendor/dav/test/integration/calendars_test.js | 239 - js/vendor/dav/test/integration/contacts_test.js | 219 - .../test/integration/data/bastille_day_party.ics | 12 - .../dav/test/integration/data/forrest_gump.vcf | 16 - js/vendor/dav/test/integration/data/index.js | 17 - js/vendor/dav/test/integration/server/bootstrap.js | 105 - .../dav/test/integration/server/calendarserver.php | 82 - js/vendor/dav/test/integration/version_test.js | 10 - js/vendor/dav/test/mocha.opts | 5 - js/vendor/dav/test/unit/camelize_test.js | 23 - js/vendor/dav/test/unit/client_test.js | 265 - .../dav/test/unit/data/address_book_query.xml | 72 - js/vendor/dav/test/unit/data/calendar_query.xml | 24 - .../dav/test/unit/data/current_user_principal.xml | 13 - js/vendor/dav/test/unit/data/index.js | 23 - js/vendor/dav/test/unit/data/propfind.xml | 39 - js/vendor/dav/test/unit/data/sync_collection.xml | 16 - js/vendor/dav/test/unit/nock_wrapper.js | 47 - js/vendor/dav/test/unit/parser_test.js | 66 - .../test/unit/request/address_book_query_test.js | 69 - js/vendor/dav/test/unit/request/basic_test.js | 63 - .../dav/test/unit/request/calendar_query_test.js | 107 - js/vendor/dav/test/unit/request/propfind_test.js | 84 - .../dav/test/unit/request/sync_collection_test.js | 65 - js/vendor/dav/test/unit/sandbox_test.js | 72 - js/vendor/dav/test/unit/template_test.js | 69 - js/vendor/dav/test/unit/transport_test.js | 256 - js/vendor/dav/test/unit/xmlhttprequest_test.js | 81 - 137 files changed, 13616 insertions(+), 13616 deletions(-) create mode 100644 js/dav/.bower.json create mode 100644 js/dav/.gitignore create mode 100644 js/dav/.npmignore create mode 100644 js/dav/.travis.yml create mode 100644 js/dav/CONTRIBUTING.md create mode 100644 js/dav/HISTORY.md create mode 100644 js/dav/LICENSE create mode 100644 js/dav/Makefile create mode 100644 js/dav/README.md create mode 100644 js/dav/dav.js create mode 100644 js/dav/lib/accounts.js create mode 100644 js/dav/lib/calendars.js create mode 100644 js/dav/lib/camelize.js create mode 100644 js/dav/lib/client.js create mode 100644 js/dav/lib/contacts.js create mode 100644 js/dav/lib/debug.js create mode 100644 js/dav/lib/fuzzy_url_equals.js create mode 100644 js/dav/lib/index.js create mode 100644 js/dav/lib/model.js create mode 100644 js/dav/lib/namespace.js create mode 100644 js/dav/lib/parser.js create mode 100644 js/dav/lib/polyfill/array_find.js create mode 100644 js/dav/lib/polyfill/object_assign.js create mode 100644 js/dav/lib/polyfill/regenerator_runtime.js create mode 100644 js/dav/lib/request.js create mode 100644 js/dav/lib/sandbox.js create mode 100644 js/dav/lib/template/address_book_query.js create mode 100644 js/dav/lib/template/calendar_query.js create mode 100644 js/dav/lib/template/filter.js create mode 100644 js/dav/lib/template/index.js create mode 100644 js/dav/lib/template/mkcol.js create mode 100644 js/dav/lib/template/prop.js create mode 100644 js/dav/lib/template/propfind.js create mode 100644 js/dav/lib/template/proppatch.js create mode 100644 js/dav/lib/template/sync_collection.js create mode 100644 js/dav/lib/transport.js create mode 100644 js/dav/lib/webdav.js create mode 100644 js/dav/lib/xmlhttprequest.js create mode 100644 js/dav/package.json create mode 100644 js/dav/test/integration/accounts_test.js create mode 100644 js/dav/test/integration/calendars_test.js create mode 100644 js/dav/test/integration/contacts_test.js create mode 100644 js/dav/test/integration/data/bastille_day_party.ics create mode 100644 js/dav/test/integration/data/forrest_gump.vcf create mode 100644 js/dav/test/integration/data/index.js create mode 100644 js/dav/test/integration/server/bootstrap.js create mode 100644 js/dav/test/integration/server/calendarserver.php create mode 100644 js/dav/test/integration/version_test.js create mode 100644 js/dav/test/mocha.opts create mode 100644 js/dav/test/unit/camelize_test.js create mode 100644 js/dav/test/unit/client_test.js create mode 100644 js/dav/test/unit/data/address_book_query.xml create mode 100644 js/dav/test/unit/data/calendar_query.xml create mode 100644 js/dav/test/unit/data/current_user_principal.xml create mode 100644 js/dav/test/unit/data/index.js create mode 100644 js/dav/test/unit/data/propfind.xml create mode 100644 js/dav/test/unit/data/sync_collection.xml create mode 100644 js/dav/test/unit/nock_wrapper.js create mode 100644 js/dav/test/unit/parser_test.js create mode 100644 js/dav/test/unit/request/address_book_query_test.js create mode 100644 js/dav/test/unit/request/basic_test.js create mode 100644 js/dav/test/unit/request/calendar_query_test.js create mode 100644 js/dav/test/unit/request/propfind_test.js create mode 100644 js/dav/test/unit/request/sync_collection_test.js create mode 100644 js/dav/test/unit/sandbox_test.js create mode 100644 js/dav/test/unit/template_test.js create mode 100644 js/dav/test/unit/transport_test.js create mode 100644 js/dav/test/unit/xmlhttprequest_test.js delete mode 100644 js/vendor/dav/.bower.json delete mode 100644 js/vendor/dav/.gitignore delete mode 100644 js/vendor/dav/.npmignore delete mode 100644 js/vendor/dav/.travis.yml delete mode 100644 js/vendor/dav/CONTRIBUTING.md delete mode 100644 js/vendor/dav/HISTORY.md delete mode 100644 js/vendor/dav/LICENSE delete mode 100644 js/vendor/dav/Makefile delete mode 100644 js/vendor/dav/README.md delete mode 100644 js/vendor/dav/dav.js delete mode 100644 js/vendor/dav/lib/accounts.js delete mode 100644 js/vendor/dav/lib/calendars.js delete mode 100644 js/vendor/dav/lib/camelize.js delete mode 100644 js/vendor/dav/lib/client.js delete mode 100644 js/vendor/dav/lib/contacts.js delete mode 100644 js/vendor/dav/lib/debug.js delete mode 100644 js/vendor/dav/lib/fuzzy_url_equals.js delete mode 100644 js/vendor/dav/lib/index.js delete mode 100644 js/vendor/dav/lib/model.js delete mode 100644 js/vendor/dav/lib/namespace.js delete mode 100644 js/vendor/dav/lib/parser.js delete mode 100644 js/vendor/dav/lib/polyfill/array_find.js delete mode 100644 js/vendor/dav/lib/polyfill/object_assign.js delete mode 100644 js/vendor/dav/lib/polyfill/regenerator_runtime.js delete mode 100644 js/vendor/dav/lib/request.js delete mode 100644 js/vendor/dav/lib/sandbox.js delete mode 100644 js/vendor/dav/lib/template/address_book_query.js delete mode 100644 js/vendor/dav/lib/template/calendar_query.js delete mode 100644 js/vendor/dav/lib/template/filter.js delete mode 100644 js/vendor/dav/lib/template/index.js delete mode 100644 js/vendor/dav/lib/template/mkcol.js delete mode 100644 js/vendor/dav/lib/template/prop.js delete mode 100644 js/vendor/dav/lib/template/propfind.js delete mode 100644 js/vendor/dav/lib/template/proppatch.js delete mode 100644 js/vendor/dav/lib/template/sync_collection.js delete mode 100644 js/vendor/dav/lib/transport.js delete mode 100644 js/vendor/dav/lib/webdav.js delete mode 100644 js/vendor/dav/lib/xmlhttprequest.js delete mode 100644 js/vendor/dav/package.json delete mode 100644 js/vendor/dav/test/integration/accounts_test.js delete mode 100644 js/vendor/dav/test/integration/calendars_test.js delete mode 100644 js/vendor/dav/test/integration/contacts_test.js delete mode 100644 js/vendor/dav/test/integration/data/bastille_day_party.ics delete mode 100644 js/vendor/dav/test/integration/data/forrest_gump.vcf delete mode 100644 js/vendor/dav/test/integration/data/index.js delete mode 100644 js/vendor/dav/test/integration/server/bootstrap.js delete mode 100644 js/vendor/dav/test/integration/server/calendarserver.php delete mode 100644 js/vendor/dav/test/integration/version_test.js delete mode 100644 js/vendor/dav/test/mocha.opts delete mode 100644 js/vendor/dav/test/unit/camelize_test.js delete mode 100644 js/vendor/dav/test/unit/client_test.js delete mode 100644 js/vendor/dav/test/unit/data/address_book_query.xml delete mode 100644 js/vendor/dav/test/unit/data/calendar_query.xml delete mode 100644 js/vendor/dav/test/unit/data/current_user_principal.xml delete mode 100644 js/vendor/dav/test/unit/data/index.js delete mode 100644 js/vendor/dav/test/unit/data/propfind.xml delete mode 100644 js/vendor/dav/test/unit/data/sync_collection.xml delete mode 100644 js/vendor/dav/test/unit/nock_wrapper.js delete mode 100644 js/vendor/dav/test/unit/parser_test.js delete mode 100644 js/vendor/dav/test/unit/request/address_book_query_test.js delete mode 100644 js/vendor/dav/test/unit/request/basic_test.js delete mode 100644 js/vendor/dav/test/unit/request/calendar_query_test.js delete mode 100644 js/vendor/dav/test/unit/request/propfind_test.js delete mode 100644 js/vendor/dav/test/unit/request/sync_collection_test.js delete mode 100644 js/vendor/dav/test/unit/sandbox_test.js delete mode 100644 js/vendor/dav/test/unit/template_test.js delete mode 100644 js/vendor/dav/test/unit/transport_test.js delete mode 100644 js/vendor/dav/test/unit/xmlhttprequest_test.js (limited to 'js') diff --git a/js/dav/.bower.json b/js/dav/.bower.json new file mode 100644 index 00000000..acbb02d5 --- /dev/null +++ b/js/dav/.bower.json @@ -0,0 +1,12 @@ +{ + "name": "dav", + "homepage": "https://github.com/irgendwie/dav", + "_release": "d33ecad1e6", + "_resolution": { + "type": "commit", + "commit": "d33ecad1e64202ec5b35b6911708d1253064b5a7" + }, + "_source": "git@github.com:irgendwie/dav.git", + "_target": "d33ecad1e64202ec5b35b6911708d1253064b5a7", + "_originalSource": "git@github.com:irgendwie/dav.git" +} \ No newline at end of file diff --git a/js/dav/.gitignore b/js/dav/.gitignore new file mode 100644 index 00000000..c54db2af --- /dev/null +++ b/js/dav/.gitignore @@ -0,0 +1,8 @@ +SabreDAV/ + +/*.zip +/build/ +/coverage/ +/dav.js.map +/dav.min.js +/node_modules/ diff --git a/js/dav/.npmignore b/js/dav/.npmignore new file mode 100644 index 00000000..b3d3f89d --- /dev/null +++ b/js/dav/.npmignore @@ -0,0 +1,11 @@ +SabreDAV/ + +/*.zip +/coverage/ +/Makefile +/.git +/.gitignore +/.jshintrc +/.travis.yml +/node_modules +/test diff --git a/js/dav/.travis.yml b/js/dav/.travis.yml new file mode 100644 index 00000000..46b9de7e --- /dev/null +++ b/js/dav/.travis.yml @@ -0,0 +1,12 @@ +# This is a bit weird since this is really a js project, +# but since we're using sabredav for integration testing +# and since travis doesn't support multiple languages +# and since travis additionally always installs a base node.js, +# the easiest thing to do is pretend to be php. +language: php +php: + - "5.4" +before_install: + - "nvm install iojs-v1.8.1" +install: npm install +script: npm test diff --git a/js/dav/CONTRIBUTING.md b/js/dav/CONTRIBUTING.md new file mode 100644 index 00000000..6bd75da0 --- /dev/null +++ b/js/dav/CONTRIBUTING.md @@ -0,0 +1,57 @@ +# Contributing + + + +**Table of Contents** *generated with [DocToc](http://doctoc.herokuapp.com/)* + +- [Under the hood](#under-the-hood) +- [Running the tests](#running-the-tests) +- [Publishing a release](#publishing-a-release) +- [Related Material](#related-material) + + + +### Under the hood + +dav uses npm to manage external dependencies. External npm modules get bundled into the browser js binary with the (excellent) [browserify](http://browserify.org/) utility. dav uses the `DOMParser` and `XMLHttpRequest` web apis (to parse xml and send http requests). All of the async library operations use es6 [Promises](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise). + +### Running the tests + +``` +/////////////////////////////////////// +/ suite / command / +/////////////////////////////////////// +/ integration / make test-integration / +/////////////////////////////////////// +/ lint / make lint / +/////////////////////////////////////// +/ unit / make test-unit / +/////////////////////////////////////// +``` + +Things to note: + ++ As of 1.1.1, all of the tests run dav via nodejs. There are no browser tests (yet). ++ You can add helpful debug logs to test output with the `DEBUG` environment variable. + + Filter logs by setting `DEBUG=dav:*`, `DEBUG=dav:request:*`, etc. ++ Integration tests run against [sabredav](http://sabre.io/) + + The server code lives [here](https://github.com/gaye/dav/blob/master/test/integration/server/calendarserver.php) + + There is a make task which downloads a sabredav release from GitHub that `make test-integration` depends on + + The sabredav instance uses sqlite to store dav collections and objects among other things. + + The code that seeds the database lives [here](https://github.com/gaye/dav/blob/master/test/integration/server/bootstrap.js) + +### Publishing a release + +1. Update `package.json` to reflect the new version. Use [semver](http://semver.org/) to help decide what new version number is best. +2. If there are changes to the public api, document them in the README. Then regenerate the `README.md` table of contents with `make toc`. +3. Add a new entry to `HISTORY.md` with the new version number and a description of the changeset. Regenerate the `HISTORY.md` table of contents with `make toc`. +4. Commit the changes to `package.json`, `HISTORY.md`, and (perhaps) `README.md`. Push to GitHub. +5. Run `make && npm publish`. +6. Create a new GitHub release named `v.{MAJOR}.{MINOR}.{PATCH}` with a description of the changeset. Upload the freshly generated zipball `dav.zip`. + +### Related Material + ++ [Amazing webdav docs](http://sabre.io/dav/) ++ [RFC 4791](http://tools.ietf.org/html/rfc4791) ++ [RFC 5545](http://tools.ietf.org/html/rfc5545) ++ [RFC 6352](http://tools.ietf.org/html/rfc6352) diff --git a/js/dav/HISTORY.md b/js/dav/HISTORY.md new file mode 100644 index 00000000..310d4f97 --- /dev/null +++ b/js/dav/HISTORY.md @@ -0,0 +1,271 @@ + + +**Table of Contents** *generated with [DocToc](http://doctoc.herokuapp.com/)* + +- [1.7.8](#178) +- [1.7.7](#177) +- [1.7.6](#176) +- [1.7.5](#175) +- [1.7.4](#174) +- [1.7.3](#173) +- [1.7.2](#172) +- [1.7.0](#170) +- [1.6.5](#165) +- [1.6.4](#164) +- [1.6.3](#163) +- [1.6.2](#162) +- [1.6.1](#161) +- [1.6.0](#160) +- [1.5.5](#155) +- [1.5.4](#154) +- [1.5.3](#153) +- [1.5.2](#152) +- [1.5.1](#151) +- [1.5.0](#150) +- [1.4.1](#141) +- [1.4.0](#140) +- [1.3.0](#130) +- [1.2.0](#120) +- [1.1.2](#112) +- [1.1.1](#111) +- [1.1.0](#110) +- [1.0.4](#104) +- [1.0.3](#103) +- [1.0.2](#102) +- [1.0.1](#101) +- [1.0.0](#100) +- [0.11.0](#0110) +- [0.10.1](#0101) +- [0.10.0](#0100) +- [0.9.3](#093) +- [0.9.2](#092) +- [0.9.1](#091) +- [0.9.0](#090) +- [0.8.0](#080) +- [0.7.1](#071) +- [0.7.0](#070) +- [0.6.0](#060) +- [0.5.0](#050) +- [0.4.0](#040) +- [0.3.1](#031) +- [0.3.0](#030) +- [0.2.0](#020) +- [0.1.0](#010) + + + +### 1.7.8 + ++ `listCalendars` passes through all calendars that contain iCalendar + objects and not just `VEVENT`s. + +### 1.7.7 + ++ Parser processes href and currentUserPrincipal elements + +### 1.7.6 + ++ Bundle `regeneratorRuntime` and polyfills for `Array.prototype.find` + and `Object.assign` so that consumers don't need babel polyfill. + +### 1.7.5 + ++ Trimmed the binary size to 128k minified ++ Remove babel polyfill ++ Remove handlebars + +### 1.7.4 + ++ Precompile handlebars templates ++ Use custom debug module + +### 1.7.3 + ++ Google CardDAV wasn't working due to a few issues like our url + comparison, Google requiring at least one filter for an addressbook + query, and Google sometimes returning propstats with statuses but no + props. + +### 1.7.2 + ++ Fix outstanding nodejs compatibility issues ++ Expose dav.version + +### 1.7.0 + ++ Remove lodash, json-stringify-safe, don't expose jsonify + +### 1.6.5 + ++ Add brfs as a dependency so that downstream consumers can browserify us + +### 1.6.4 + ++ Workaround https://github.com/substack/brfs/issues/39 + +### 1.6.3 + ++ Convert to use new es6/7 features and transpile with babel + +### 1.6.2 + ++ Export debug library under dav ns + +### 1.6.1 + ++ Don't bundle xmlhttprequest polyfill in browser binary... again + +### 1.6.0 + ++ Add #syncCaldavAccount and #syncCarddavAccount to the public api ++ Expose dav.jsonify and dav.ns ++ Small correctness fix to error case in basic calendar sync + +### 1.5.5 + ++ Bundle XMLHttpRequest polyfill for environments where it's not available + +### 1.5.4 + ++ Fix browser globals + +### 1.5.3 + ++ Don't use window in web workers + +### 1.5.2 + ++ Use xmldom in the browser since it's missing from web workers + +### 1.5.1 + ++ Expose dav browserify configuration to npm consumers + +### 1.5.0 + ++ Decouple requests from the urls they get sent to + +### 1.4.1 + ++ Add missing use strict statement to lib/index.js + +### 1.4.0 + ++ New sandbox interface + +### 1.3.0 + ++ Expose dav.Model, dav.Request, dav.Transport + +### 1.2.0 + ++ Implement client#send + +### 1.1.2 + ++ Trick browserify into not bundling node shims for web apis + +### 1.1.1 + ++ %s/toString/jsonify/ for models + +### 1.1.0 + ++ Support for rfc 6352 carddav + +### 1.0.4 + ++ Implement #toString on models + +### 1.0.3 + ++ Internal DELETE, PUT request refactor + +### 1.0.2 + ++ davinci -> dav + +### 1.0.1 + ++ Fix issues with browserify build + +### 1.0.0 + ++ Update interfaces for pluggable transports, expose transport layer ++ Support for oauth2 authentication ++ Clean up internal multistatus parser + +### 0.11.0 + ++ Support for rfc 6578 webdav sync + +### 0.10.1 + ++ Set request depth to 0 in the "getctag" propfind issued during sync + +### 0.10.0 + ++ Implement time-range filters for calendar queries + +### 0.9.3 + ++ Remove dependencies on ical.js and underscore + +### 0.9.2 + ++ Fix npm package ++ Change npm name to davincijs + +### 0.9.1 + ++ remove nodejs polyfills for DOMParser and XMLHttpRequest from build output ++ generate minified binaries + +### 0.9.0 + ++ Implement davinci.Client interface ++ Add transport layer to decouple request details and sending + +### 0.8.0 + ++ Expose low-level request methods through davinci.request ++ Add hook to requests to override transformResponse + +### 0.7.1 + ++ Expose the underlying, xml parsed dav responses on davinci.Calendar and davinci.CalendarObject models. + +### 0.7.0 + ++ Support providing timezone option to #createAccount and #syncCalendar + +### 0.6.0 + ++ #syncCalendar added to public api ++ The promise returned from #createAccount now resolves with a davinci.Account object instead of an array of davinci.Calendar objects. + +### 0.5.0 + ++ #deleteCalendarObject added to public api + +### 0.4.0 + ++ #updateCalendarObject added to public api ++ Internal api refactoring to expose Request objects + +### 0.3.1 + ++ Patch bug in build due to bug in brfs. + +### 0.3.0 + ++ #createCalendarObject modified to support sandboxing. + +### 0.2.0 + ++ #createCalendarObject added to public api + +### 0.1.0 + ++ #createAccount added to public api ++ #createSandbox added to public api diff --git a/js/dav/LICENSE b/js/dav/LICENSE new file mode 100644 index 00000000..e87a115e --- /dev/null +++ b/js/dav/LICENSE @@ -0,0 +1,363 @@ +Mozilla Public License, version 2.0 + +1. Definitions + +1.1. "Contributor" + + means each individual or legal entity that creates, contributes to the + creation of, or owns Covered Software. + +1.2. "Contributor Version" + + means the combination of the Contributions of others (if any) used by a + Contributor and that particular Contributor's Contribution. + +1.3. "Contribution" + + means Covered Software of a particular Contributor. + +1.4. "Covered Software" + + means Source Code Form to which the initial Contributor has attached the + notice in Exhibit A, the Executable Form of such Source Code Form, and + Modifications of such Source Code Form, in each case including portions + thereof. + +1.5. "Incompatible With Secondary Licenses" + means + + a. that the initial Contributor has attached the notice described in + Exhibit B to the Covered Software; or + + b. that the Covered Software was made available under the terms of + version 1.1 or earlier of the License, but not also under the terms of + a Secondary License. + +1.6. "Executable Form" + + means any form of the work other than Source Code Form. + +1.7. "Larger Work" + + means a work that combines Covered Software with other material, in a + separate file or files, that is not Covered Software. + +1.8. "License" + + means this document. + +1.9. "Licensable" + + means having the right to grant, to the maximum extent possible, whether + at the time of the initial grant or subsequently, any and all of the + rights conveyed by this License. + +1.10. "Modifications" + + means any of the following: + + a. any file in Source Code Form that results from an addition to, + deletion from, or modification of the contents of Covered Software; or + + b. any new file in Source Code Form that contains any Covered Software. + +1.11. "Patent Claims" of a Contributor + + means any patent claim(s), including without limitation, method, + process, and apparatus claims, in any patent Licensable by such + Contributor that would be infringed, but for the grant of the License, + by the making, using, selling, offering for sale, having made, import, + or transfer of either its Contributions or its Contributor Version. + +1.12. "Secondary License" + + means either the GNU General Public License, Version 2.0, the GNU Lesser + General Public License, Version 2.1, the GNU Affero General Public + License, Version 3.0, or any later versions of those licenses. + +1.13. "Source Code Form" + + means the form of the work preferred for making modifications. + +1.14. "You" (or "Your") + + means an individual or a legal entity exercising rights under this + License. For legal entities, "You" includes any entity that controls, is + controlled by, or is under common control with You. For purposes of this + definition, "control" means (a) the power, direct or indirect, to cause + the direction or management of such entity, whether by contract or + otherwise, or (b) ownership of more than fifty percent (50%) of the + outstanding shares or beneficial ownership of such entity. + + +2. License Grants and Conditions + +2.1. Grants + + Each Contributor hereby grants You a world-wide, royalty-free, + non-exclusive license: + + a. under intellectual property rights (other than patent or trademark) + Licensable by such Contributor to use, reproduce, make available, + modify, display, perform, distribute, and otherwise exploit its + Contributions, either on an unmodified basis, with Modifications, or + as part of a Larger Work; and + + b. under Patent Claims of such Contributor to make, use, sell, offer for + sale, have made, import, and otherwise transfer either its + Contributions or its Contributor Version. + +2.2. Effective Date + + The licenses granted in Section 2.1 with respect to any Contribution + become effective for each Contribution on the date the Contributor first + distributes such Contribution. + +2.3. Limitations on Grant Scope + + The licenses granted in this Section 2 are the only rights granted under + this License. No additional rights or licenses will be implied from the + distribution or licensing of Covered Software under this License. + Notwithstanding Section 2.1(b) above, no patent license is granted by a + Contributor: + + a. for any code that a Contributor has removed from Covered Software; or + + b. for infringements caused by: (i) Your and any other third party's + modifications of Covered Software, or (ii) the combination of its + Contributions with other software (except as part of its Contributor + Version); or + + c. under Patent Claims infringed by Covered Software in the absence of + its Contributions. + + This License does not grant any rights in the trademarks, service marks, + or logos of any Contributor (except as may be necessary to comply with + the notice requirements in Section 3.4). + +2.4. Subsequent Licenses + + No Contributor makes additional grants as a result of Your choice to + distribute the Covered Software under a subsequent version of this + License (see Section 10.2) or under the terms of a Secondary License (if + permitted under the terms of Section 3.3). + +2.5. Representation + + Each Contributor represents that the Contributor believes its + Contributions are its original creation(s) or it has sufficient rights to + grant the rights to its Contributions conveyed by this License. + +2.6. Fair Use + + This License is not intended to limit any rights You have under + applicable copyright doctrines of fair use, fair dealing, or other + equivalents. + +2.7. Conditions + + Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in + Section 2.1. + + +3. Responsibilities + +3.1. Distribution of Source Form + + All distribution of Covered Software in Source Code Form, including any + Modifications that You create or to which You contribute, must be under + the terms of this License. You must inform recipients that the Source + Code Form of the Covered Software is governed by the terms of this + License, and how they can obtain a copy of this License. You may not + attempt to alter or restrict the recipients' rights in the Source Code + Form. + +3.2. Distribution of Executable Form + + If You distribute Covered Software in Executable Form then: + + a. such Covered Software must also be made available in Source Code Form, + as described in Section 3.1, and You must inform recipients of the + Executable Form how they can obtain a copy of such Source Code Form by + reasonable means in a timely manner, at a charge no more than the cost + of distribution to the recipient; and + + b. You may distribute such Executable Form under the terms of this + License, or sublicense it under different terms, provided that the + license for the Executable Form does not attempt to limit or alter the + recipients' rights in the Source Code Form under this License. + +3.3. Distribution of a Larger Work + + You may create and distribute a Larger Work under terms of Your choice, + provided that You also comply with the requirements of this License for + the Covered Software. If the Larger Work is a combination of Covered + Software with a work governed by one or more Secondary Licenses, and the + Covered Software is not Incompatible With Secondary Licenses, this + License permits You to additionally distribute such Covered Software + under the terms of such Secondary License(s), so that the recipient of + the Larger Work may, at their option, further distribute the Covered + Software under the terms of either this License or such Secondary + License(s). + +3.4. Notices + + You may not remove or alter the substance of any license notices + (including copyright notices, patent notices, disclaimers of warranty, or + limitations of liability) contained within the Source Code Form of the + Covered Software, except that You may alter any license notices to the + extent required to remedy known factual inaccuracies. + +3.5. Application of Additional Terms + + You may choose to offer, and to charge a fee for, warranty, support, + indemnity or liability obligations to one or more recipients of Covered + Software. However, You may do so only on Your own behalf, and not on + behalf of any Contributor. You must make it absolutely clear that any + such warranty, support, indemnity, or liability obligation is offered by + You alone, and You hereby agree to indemnify every Contributor for any + liability incurred by such Contributor as a result of warranty, support, + indemnity or liability terms You offer. You may include additional + disclaimers of warranty and limitations of liability specific to any + jurisdiction. + +4. Inability to Comply Due to Statute or Regulation + + If it is impossible for You to comply with any of the terms of this License + with respect to some or all of the Covered Software due to statute, + judicial order, or regulation then You must: (a) comply with the terms of + this License to the maximum extent possible; and (b) describe the + limitations and the code they affect. Such description must be placed in a + text file included with all distributions of the Covered Software under + this License. Except to the extent prohibited by statute or regulation, + such description must be sufficiently detailed for a recipient of ordinary + skill to be able to understand it. + +5. Termination + +5.1. The rights granted under this License will terminate automatically if You + fail to comply with any of its terms. However, if You become compliant, + then the rights granted under this License from a particular Contributor + are reinstated (a) provisionally, unless and until such Contributor + explicitly and finally terminates Your grants, and (b) on an ongoing + basis, if such Contributor fails to notify You of the non-compliance by + some reasonable means prior to 60 days after You have come back into + compliance. Moreover, Your grants from a particular Contributor are + reinstated on an ongoing basis if such Contributor notifies You of the + non-compliance by some reasonable means, this is the first time You have + received notice of non-compliance with this License from such + Contributor, and You become compliant prior to 30 days after Your receipt + of the notice. + +5.2. If You initiate litigation against any entity by asserting a patent + infringement claim (excluding declaratory judgment actions, + counter-claims, and cross-claims) alleging that a Contributor Version + directly or indirectly infringes any patent, then the rights granted to + You by any and all Contributors for the Covered Software under Section + 2.1 of this License shall terminate. + +5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user + license agreements (excluding distributors and resellers) which have been + validly granted by You or Your distributors under this License prior to + termination shall survive termination. + +6. Disclaimer of Warranty + + Covered Software is provided under this License on an "as is" basis, + without warranty of any kind, either expressed, implied, or statutory, + including, without limitation, warranties that the Covered Software is free + of defects, merchantable, fit for a particular purpose or non-infringing. + The entire risk as to the quality and performance of the Covered Software + is with You. Should any Covered Software prove defective in any respect, + You (not any Contributor) assume the cost of any necessary servicing, + repair, or correction. This disclaimer of warranty constitutes an essential + part of this License. No use of any Covered Software is authorized under + this License except under this disclaimer. + +7. Limitation of Liability + + Under no circumstances and under no legal theory, whether tort (including + negligence), contract, or otherwise, shall any Contributor, or anyone who + distributes Covered Software as permitted above, be liable to You for any + direct, indirect, special, incidental, or consequential damages of any + character including, without limitation, damages for lost profits, loss of + goodwill, work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses, even if such party shall have been + informed of the possibility of such damages. This limitation of liability + shall not apply to liability for death or personal injury resulting from + such party's negligence to the extent applicable law prohibits such + limitation. Some jurisdictions do not allow the exclusion or limitation of + incidental or consequential damages, so this exclusion and limitation may + not apply to You. + +8. Litigation + + Any litigation relating to this License may be brought only in the courts + of a jurisdiction where the defendant maintains its principal place of + business and such litigation shall be governed by laws of that + jurisdiction, without reference to its conflict-of-law provisions. Nothing + in this Section shall prevent a party's ability to bring cross-claims or + counter-claims. + +9. Miscellaneous + + This License represents the complete agreement concerning the subject + matter hereof. If any provision of this License is held to be + unenforceable, such provision shall be reformed only to the extent + necessary to make it enforceable. Any law or regulation which provides that + the language of a contract shall be construed against the drafter shall not + be used to construe this License against a Contributor. + + +10. Versions of the License + +10.1. New Versions + + Mozilla Foundation is the license steward. Except as provided in Section + 10.3, no one other than the license steward has the right to modify or + publish new versions of this License. Each version will be given a + distinguishing version number. + +10.2. Effect of New Versions + + You may distribute the Covered Software under the terms of the version + of the License under which You originally received the Covered Software, + or under the terms of any subsequent version published by the license + steward. + +10.3. Modified Versions + + If you create software not governed by this License, and you want to + create a new license for such software, you may create and use a + modified version of this License if you rename the license and remove + any references to the name of the license steward (except to note that + such modified license differs from this License). + +10.4. Distributing Source Code Form that is Incompatible With Secondary + Licenses If You choose to distribute Source Code Form that is + Incompatible With Secondary Licenses under the terms of this version of + the License, the notice described in Exhibit B of this License must be + attached. + +Exhibit A - Source Code Form License Notice + + This Source Code Form is subject to the + terms of the Mozilla Public License, v. + 2.0. If a copy of the MPL was not + distributed with this file, You can + obtain one at + http://mozilla.org/MPL/2.0/. + +If it is not possible or desirable to put the notice in a particular file, +then You may include the notice in a location (such as a LICENSE file in a +relevant directory) where a recipient would be likely to look for such a +notice. + +You may add additional accurate notices of copyright ownership. + +Exhibit B - "Incompatible With Secondary Licenses" Notice + + This Source Code Form is "Incompatible + With Secondary Licenses", as defined by + the Mozilla Public License, v. 2.0. + diff --git a/js/dav/Makefile b/js/dav/Makefile new file mode 100644 index 00000000..4ef8d4ab --- /dev/null +++ b/js/dav/Makefile @@ -0,0 +1,60 @@ +HBS := $(shell find lib/template/ -name "*.hbs") +JS := $(shell find lib/ -name "*.js") + +SABRE_DAV_VERSION=2.0.1 +SABRE_DAV_RELEASE=sabredav-$(SABRE_DAV_VERSION) +SABRE_DAV_ZIPBALL=$(SABRE_DAV_RELEASE).zip + +dav.zip: dav.js dav.min.js dav.js.map + zip dav dav.js dav.js.map dav.min.js + +dav.min.js dav.js.map: dav.js node_modules + ./node_modules/.bin/uglifyjs dav.js \ + --lint \ + --screw-ie8 \ + --output ./dav.min.js \ + --source-map ./dav.js.map + +dav.js: build node_modules + rm -rf dav.js /tmp/dav.js + ./node_modules/.bin/browserify --standalone dav ./build/index.js > /tmp/dav.js + cat lib/polyfill/*.js /tmp/dav.js > dav.js + +build: $(JS) $(HBS) node_modules + rm -rf build/ + ./node_modules/.bin/babel lib \ + --modules common \ + --out-dir build \ + --stage 4 + +node_modules: package.json + npm install + +.PHONY: clean +clean: + rm -rf *.zip SabreDAV build coverage dav.* node_modules test/integration/server/SabreDAV + +.PHONY: test +test: test-unit test-integration + +.PHONY: test-unit +test-unit: node_modules + ./node_modules/.bin/mocha test/unit + +.PHONY: test-integration +test-integration: node_modules test/integration/server/SabreDAV + ./node_modules/.bin/mocha test/integration + +.PHONY: toc +toc: node_modules + ./node_modules/.bin/doctoc CONTRIBUTING.md + ./node_modules/.bin/doctoc HISTORY.md + ./node_modules/.bin/doctoc README.md + +test/integration/server/SabreDAV: SabreDAV + cp -r SabreDAV test/integration/server/SabreDAV + cd test/integration/server/SabreDAV && cp ../calendarserver.php calendarserver.php + +SabreDAV: + wget -O $(SABRE_DAV_ZIPBALL) https://github.com/fruux/sabre-dav/releases/download/$(SABRE_DAV_VERSION)/$(SABRE_DAV_ZIPBALL) + unzip -q $(SABRE_DAV_ZIPBALL) diff --git a/js/dav/README.md b/js/dav/README.md new file mode 100644 index 00000000..7c123606 --- /dev/null +++ b/js/dav/README.md @@ -0,0 +1,467 @@ +dav +=== + +[![Build Status](https://travis-ci.org/gaye/dav.png?branch=master)](https://travis-ci.org/gaye/dav) + +WebDAV, CalDAV, and CardDAV client for nodejs and the browser. + + + +**Table of Contents** *generated with [DocToc](http://doctoc.herokuapp.com/)* + +- [API](#api) + - [accounts](#accounts) + - [dav.createAccount(options)](#davcreateaccountoptions) + - [calendars](#calendars) + - [dav.createCalendarObject(calendar, options)](#davcreatecalendarobjectcalendar-options) + - [dav.updateCalendarObject(calendarObject, options)](#davupdatecalendarobjectcalendarobject-options) + - [dav.deleteCalendarObject(calendarObject, options)](#davdeletecalendarobjectcalendarobject-options) + - [dav.syncCalendar(calendar, options)](#davsynccalendarcalendar-options) + - [dav.syncCaldavAccount(account, options)](#davsynccaldavaccountaccount-options) + - [contacts](#contacts) + - [dav.createCard(addressBook, options)](#davcreatecardaddressbook-options) + - [dav.updateCard(card, options)](#davupdatecardcard-options) + - [dav.deleteCard(card, options)](#davdeletecardcard-options) + - [dav.syncAddressBook(addressBook, options)](#davsyncaddressbookaddressbook-options) + - [dav.syncCarddavAccount(account, options)](#davsynccarddavaccountaccount-options) + - [sandbox](#sandbox) + - [dav.Sandbox()](#davsandbox) + - [transport](#transport) + - [dav.transport.Basic(credentials)](#davtransportbasiccredentials) + - [dav.transport.Basic.send(request, options)](#davtransportbasicsendrequest-options) + - [dav.transport.OAuth2(credentials)](#davtransportoauth2credentials) + - [dav.transport.OAuth2.send(request, options)](#davtransportoauth2sendrequest-options) + - [request](#request) + - [dav.request.addressBookQuery(options)](#davrequestaddressbookqueryoptions) + - [dav.request.basic(options)](#davrequestbasicoptions) + - [dav.request.calendarQuery(options)](#davrequestcalendarqueryoptions) + - [dav.request.propfind(options)](#davrequestpropfindoptions) + - [dav.request.syncCollection(options)](#davrequestsynccollectionoptions) + - [Client](#client) + - [dav.Client(xhr, options)](#davclientxhr-options) + - [dav.Client.send(req, options)](#davclientsendreq-options) + - [etc](#etc) + - [dav.ns](#davns) + - [Example Usage](#example-usage) + - [Using the lower-level webdav request api](#using-the-lower-level-webdav-request-api) +- [Debugging](#debugging) + + + +## API + +### accounts + +#### dav.createAccount(options) + +Perform an initial download of a caldav or carddav account's data. Returns a [Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise) which will be fulfilled with a [dav.Account](https://github.com/gaye/dav/blob/master/lib/model/account.js) object. + +``` +Options: + + (String) accountType - one of 'caldav' or 'carddav'. Defaults to 'caldav'. + (Array.) filters - list of caldav filters to send with request. + (Boolean) loadCollections - whether or not to load dav collections. + (Boolean) loadObjects - whether or not to load dav objects. + (dav.Sandbox) sandbox - optional request sandbox. + (String) server - some url for server (needn't be base url). + (String) timezone - VTIMEZONE calendar object. + (dav.Transport) xhr - request sender. +``` + +### calendars + +#### dav.createCalendarObject(calendar, options) + +Create a calendar object on the parameter calendar. Returns a [Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise) which will be fulfilled when the calendar has been created. + +``` +@param {dav.Calendar} calendar the calendar to put the object on. + +Options: + + (String) data - rfc 5545 VCALENDAR object. + (String) filename - name for the calendar ics file. + (dav.Sandbox) sandbox - optional request sandbox. + (dav.Transport) xhr - request sender. +``` + +#### dav.updateCalendarObject(calendarObject, options) + +Persist updates to the parameter calendar object to the server. Returns a [Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise) which will be fulfilled when the calendar has been updated. + +``` +@param {dav.CalendarObject} calendarObject updated calendar object. + +Options: + + (dav.Sandbox) sandbox - optional request sandbox. + (dav.Transport) xhr - request sender. +``` + +#### dav.deleteCalendarObject(calendarObject, options) + +Delete the parameter calendar object on the server. Returns a [Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise) which will be fulfilled when the calendar has been deleted. + +``` +@param {dav.CalendarObject} calendarObject target calendar object. + +Options: + + (dav.Sandbox) sandbox - optional request sandbox. + (dav.Transport) xhr - request sender. +``` + +#### dav.syncCalendar(calendar, options) + +Fetch changes from the remote server to the parameter calendar. Returns a [Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise) which will be fulfilled with an updated [dav.Calendar](https://github.com/gaye/dav/blob/master/lib/model/calendar.js) object once sync is complete. + +``` +@param {dav.Calendar} calendar the calendar to fetch changes for. + +Options: + + (Array.) filters - list of caldav filters to send with request. + (dav.Sandbox) sandbox - optional request sandbox. + (String) syncMethod - either 'basic' or 'webdav'. If unspecified, will + try to do webdav sync and failover to basic sync if rfc 6578 is not + supported by the server. + (String) timezone - VTIMEZONE calendar object. + (dav.Transport) xhr - request sender. +``` + +#### dav.syncCaldavAccount(account, options) + +Fetch changes from the remote server to the account's calendars. Returns a [Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise) which will be fulfilled with an updated [dav.Account](https://github.com/gaye/dav/blob/master/lib/model/account.js) object once sync is complete. + +``` +@param {dav.Account} account the calendar account to sync. + +Options: + + (dav.Sandbox) sandbox - optional request sandbox. + (dav.Transport) xhr - request sender. +``` + +### contacts + +#### dav.createCard(addressBook, options) + +Create a vcard object on the parameter address book. Returns a [Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise) which will be fulfilled when the vcard has been created. + +``` +@param {dav.AddressBook} addressBook the address book to put the object on. + +Options: + + (String) data - VCARD object. + (String) filename - name for the vcard vcf file. + (dav.Sandbox) sandbox - optional request sandbox. + (dav.Transport) xhr - request sender. +``` + +#### dav.updateCard(card, options) + +Persist updates to the parameter vcard object to the server. Returns a [Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise) which will be fulfilled when the vcard has been updated. + +``` +@param {dav.VCard} card updated vcard object. + +Options: + + (dav.Sandbox) sandbox - optional request sandbox. + (dav.Transport) xhr - request sender. +``` + +#### dav.deleteCard(card, options) + +Delete the parameter vcard object on the server. Returns a [Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise) which will be fulfilled when the vcard has been deleted. + +``` +@param {dav.VCard} card target vcard object. + +Options: + + (dav.Sandbox) sandbox - optional request sandbox. + (dav.Transport) xhr - request sender. +``` + +#### dav.syncAddressBook(addressBook, options) + +Fetch changes from the remote server to the parameter address books. Returns a [Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise) which will be fulfilled with an updated [dav.AddressBook](https://github.com/gaye/dav/blob/master/lib/model/address_book.js) object once sync is complete. + +``` +@param {dav.AddressBook} addressBook the address book to fetch changes for. + +Options: + + (dav.Sandbox) sandbox - optional request sandbox. + (String) syncMethod - either 'basic' or 'webdav'. If unspecified, will + try to do webdav sync and failover to basic sync if rfc 6578 is not + supported by the server. + (dav.Transport) xhr - request sender. +``` +#### dav.syncCarddavAccount(account, options) + +Fetch changes from the remote server to the account's address books. Returns a [Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise) which will be fulfilled with an updated [dav.Account](https://github.com/gaye/dav/blob/master/lib/model/account.js) object once sync is complete. + +``` +@param {dav.Account} account the address book account to sync. + +Options: + + (dav.Sandbox) sandbox - optional request sandbox. + (dav.Transport) xhr - request sender. +``` + +### sandbox + +#### dav.Sandbox() + +Create a request sandbox. There is also a deprecated interface +`dav.createSandbox()`. Add requests to the sandbox like so: + +```js +var sandbox = new dav.Sandbox(); +// sandbox instanceof Sandbox +dav.createAccount({ + username: 'Yoshi', + password: 'babybowsersoscaryomg', + server: 'https://caldav.yoshisstory.com', + sandbox: sandbox // <- Insert sandbox here! +}) +.then(function(calendars) { + // etc, etc. +}); +``` +And abort sandboxed requests as a group with `sandbox.abort()`. + +### transport + +#### dav.transport.Basic(credentials) + +Create a new `dav.transport.Basic` object. This sends dav requests using http basic authentication. + +``` +@param {dav.Credentials} credentials user authorization. +``` + +##### dav.transport.Basic.send(request, options) + +``` +@param {dav.Request} request object with request info. +@return {Promise} a promise that will be resolved with an xhr request after its readyState is 4 or the result of applying an optional request `transformResponse` function to the xhr object after its readyState is 4. + +Options: + + (dav.Sandbox) sandbox - optional request sandbox. +``` + +#### dav.transport.OAuth2(credentials) + +Create a new `dav.transport.OAuth2` object. This sends dav requests authorized via rfc 6749 oauth2. + +``` +@param {dav.Credentials} credentials user authorization. +``` + +##### dav.transport.OAuth2.send(request, options) + +``` +@param {dav.Request} request object with request info. +@return {Promise} a promise that will be resolved with an xhr request after its readyState is 4 or the result of applying an optional request `transformResponse` function to the xhr object after its readyState is 4. + +Options: + + (dav.Sandbox) sandbox - optional request sandbox. +``` + +### request + +#### dav.request.addressBookQuery(options) + +``` +Options: + + (String) depth - optional value for Depth header. + (Array.) props - list of props to request. +``` + +#### dav.request.basic(options) + +``` +Options: + + (String) data - put request body. + (String) method - http method. + (String) etag - cached calendar object etag. +``` + +#### dav.request.calendarQuery(options) + +``` +Options: + + (String) depth - optional value for Depth header. + (Array.) filters - list of filters to send with request. + (Array.) props - list of props to request. + (String) timezone - VTIMEZONE calendar object. +``` + +#### dav.request.propfind(options) + +``` +Options: + + (String) depth - optional value for Depth header. + (Array.) props - list of props to request. +``` + +#### dav.request.syncCollection(options) + +``` +Options: + + (String) depth - option value for Depth header. + (Array.) props - list of props to request. + (Number) syncLevel - indicates scope of the sync report request. + (String) syncToken - synchronization token provided by the server. +``` + +### Client + +#### dav.Client(xhr, options) + +Create a new `dav.Client` object. The client interface allows consumers to set their credentials and transport once and then make authorized requests without passing them to each request. Each of the other, public API methods should be available on `dav.Client` objects. + +``` +@param {dav.Transport} xhr - request sender. + +Options: + + (String) baseUrl - root url to resolve relative request urls with. +``` + +##### dav.Client.send(req, options) + +Send a request using this client's transport (and perhaps baseUrl). + +``` +@param {dav.request.Request} req - dav request. +@return {Promise} a promise that will be resolved with an xhr request after its readyState is 4 or the result of applying an optional request `transformResponse` function to the xhr object after its readyState is 4. + +Options: + + (dav.Sandbox) sandbox - optional request sandbox. + (String) url - relative url for request. +``` + +### etc + +#### dav.ns + +Object that holds various xml namespace constants. + +### Example Usage + +```js +var dav = require('dav'); + +var xhr = new dav.transport.Basic( + new dav.Credentials({ + username: 'xxx', + password: 'xxx' + }) +); + +dav.createAccount({ server: 'http://dav.example.com', xhr: xhr }) +.then(function(account) { + // account instanceof dav.Account + account.calendars.forEach(function(calendar) { + console.log('Found calendar named ' + calendar.displayName); + // etc. + }); +}); + +// Or, using the dav.Client interface: + +var client = new dav.Client(xhr); +// No transport arg +client.createAccount({ + server: 'http://dav.example.com', + accountType: 'carddav' +}) +.then(function(account) { + account.addressBooks.forEach(function(addressBook) { + console.log('Found address book name ' + addressBook.displayName); + // etc. + }); +}); +``` + +#### Using the lower-level webdav request api + +_Caution_: The lower-level request api is undergoing some _major_ reworking with frequent changes which will break consumers upgrading from earlier versions. If you're looking for a stable api and can live with the higher-level CalDAV and/or CardDAV abstractions, I _strongly_ recommend those since that api is largely stable. + +``` +var dav = require('dav'); + +var client = new dav.Client( + new dav.transport.Basic( + new dav.Credentials({ + username: 'xxx', + password: 'xxx' + }) + ), + { + baseUrl: 'https://mail.mozilla.com' + } +); + +var req = dav.request.basic({ + method: 'PUT', + data: 'BEGIN:VCALENDAR\nEND:VCALENDAR', + etag: '12345' +}); + +// req instanceof dav.Request + +client.send(req, '/calendars/123.ics') +.then(function(response) { + // response instanceof XMLHttpRequest +}); +``` + +Or perhaps without the client: + +``` +var dav = require('dav'); + +var xhr = new dav.transport.Basic( + new dav.Credentials({ + username: 'xxx', + password: 'xxx' + }) +); + +// xhr instanceof dav.Transport + +var req = dav.request.basic({ + method: 'PUT', + data: 'BEGIN:VCALENDAR\nEND:VCALENDAR', + etag: '12345' +}); + +// req instanceof dav.Request + +xhr.send(req, 'https://mail.mozilla.com/calendars/123.ics') +.then(function(response) { + // response instanceof XMLHttpRequest +}); +``` + +For more example usages, check out the [suite of integration tests](https://github.com/gaye/dav/tree/master/test/integration). + +## Debugging + +dav can tell you a lot of potentially useful things if you set `dav.debug.enabled = true`. diff --git a/js/dav/dav.js b/js/dav/dav.js new file mode 100644 index 00000000..4844c34e --- /dev/null +++ b/js/dav/dav.js @@ -0,0 +1,7323 @@ +/** + * Polyfill from developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/find + */ +if (!Array.prototype.find) { + Array.prototype.find = function(predicate) { + if (this == null) { + throw new TypeError('Array.prototype.find called on null or undefined'); + } + if (typeof predicate !== 'function') { + throw new TypeError('predicate must be a function'); + } + var list = Object(this); + var length = list.length >>> 0; + var thisArg = arguments[1]; + var value; + + for (var i = 0; i < length; i++) { + value = list[i]; + if (predicate.call(thisArg, value, i, list)) { + return value; + } + } + return undefined; + }; +} +/** + * Polyfill from developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object/assign + */ +if (!Object.assign) { + Object.defineProperty(Object, 'assign', { + enumerable: false, + configurable: true, + writable: true, + value: function(target, firstSource) { + 'use strict'; + if (target === undefined || target === null) { + throw new TypeError('Cannot convert first argument to object'); + } + + var to = Object(target); + for (var i = 1; i < arguments.length; i++) { + var nextSource = arguments[i]; + if (nextSource === undefined || nextSource === null) { + continue; + } + nextSource = Object(nextSource); + + var keysArray = Object.keys(Object(nextSource)); + for (var nextIndex = 0, len = keysArray.length; nextIndex < len; nextIndex++) { + var nextKey = keysArray[nextIndex]; + var desc = Object.getOwnPropertyDescriptor(nextSource, nextKey); + if (desc !== undefined && desc.enumerable) { + to[nextKey] = nextSource[nextKey]; + } + } + } + return to; + } + }); +} +/** + * Copyright (c) 2014, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * https://raw.github.com/facebook/regenerator/master/LICENSE file. An + * additional grant of patent rights can be found in the PATENTS file in + * the same directory. + */ + +!(function(global) { + "use strict"; + + var hasOwn = Object.prototype.hasOwnProperty; + var undefined; // More compressible than void 0. + var iteratorSymbol = + typeof Symbol === "function" && Symbol.iterator || "@@iterator"; + + var inModule = typeof module === "object"; + var runtime = global.regeneratorRuntime; + if (runtime) { + if (inModule) { + // If regeneratorRuntime is defined globally and we're in a module, + // make the exports object identical to regeneratorRuntime. + module.exports = runtime; + } + // Don't bother evaluating the rest of this file if the runtime was + // already defined globally. + return; + } + + // Define the runtime globally (as expected by generated code) as either + // module.exports (if we're in a module) or a new, empty object. + runtime = global.regeneratorRuntime = inModule ? module.exports : {}; + + function wrap(innerFn, outerFn, self, tryLocsList) { + // If outerFn provided, then outerFn.prototype instanceof Generator. + var generator = Object.create((outerFn || Generator).prototype); + + generator._invoke = makeInvokeMethod( + innerFn, self || null, + new Context(tryLocsList || []) + ); + + return generator; + } + runtime.wrap = wrap; + + // Try/catch helper to minimize deoptimizations. Returns a completion + // record like context.tryEntries[i].completion. This interface could + // have been (and was previously) designed to take a closure to be + // invoked without arguments, but in all the cases we care about we + // already have an existing method we want to call, so there's no need + // to create a new function object. We can even get away with assuming + // the method takes exactly one argument, since that happens to be true + // in every case, so we don't have to touch the arguments object. The + // only additional allocation required is the completion record, which + // has a stable shape and so hopefully should be cheap to allocate. + function tryCatch(fn, obj, arg) { + try { + return { type: "normal", arg: fn.call(obj, arg) }; + } catch (err) { + return { type: "throw", arg: err }; + } + } + + var GenStateSuspendedStart = "suspendedStart"; + var GenState