cozy-client-js
Version:
Javascript library to interact with a cozy
1 lines • 244 kB
JavaScript
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("client",[],t):"object"==typeof exports?exports.client=t():(e.cozy=e.cozy||{},e.cozy.client=t())}("undefined"!=typeof self?self:this,function(){return function(e){function t(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var n={};return t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=23)}([function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function i(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function a(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return e.fullpath(t).then(function(t){var r=void 0;return r=n.disableAuth?fetch(t,n):n.manualAuthCredentials?u(e,t,n,n.manualAuthCredentials):e.authorize().then(function(r){return u(e,t,n,r)}),r.then(function(t){return l(t,e._invalidTokenErrorHandler)})})}function u(e,t,n,r){return r&&(n.headers=n.headers||{},n.headers.Authorization=r.token.toAuthHeader()),n.credentials="include",Promise.all([e.isV2(),fetch(t,n)]).then(function(o){var i=p(o,2),a=i[0],s=i[1];if(400!==s.status&&401!==s.status||a||!r||n.dontRetry)return s;var c=r.client,f=r.token;return c&&f instanceof v.AccessToken?(n.dontRetry=!0,(0,y.retry)(function(){return(0,v.refreshToken)(e,c,f)},3)().then(function(t){return e.saveCredentials(c,t)}).then(function(r){return u(e,t,n,r)})):s})}function s(e,t,n,r){var o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{},i=void 0===o.processJSONAPI||o.processJSONAPI;return f(e,t,n,r,o).then(function(e){return d(e,i)})}function c(e,t,n,r){return f(e,t,n,r,arguments.length>4&&void 0!==arguments[4]?arguments[4]:{}).then(function(e){return d(e,!1)})}function f(e,t,n,r){var o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};o.method=t;var i=o.headers=o.headers||{};return i.Accept="application/json","GET"!==t&&"HEAD"!==t&&void 0!==r&&(i["Content-Type"]?o.body=r:(i["Content-Type"]="application/json",o.body=JSON.stringify(r))),a(e,n,o)}function l(e,t){if(e.ok)return e;var n=void 0,r=e.headers.get("content-type");return n=r&&r.indexOf("json")>=0?e.json():e.text(),n.then(function(n){var r=new _(e,n);throw _.isInvalidToken(r)&&t&&t(r),r})}function d(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],n=e.headers.get("content-type");if(!n||n.indexOf("json")<0)return e.text(function(t){throw new _(e,new Error("Response is not JSON: "+t))});var r=e.json();return 0===n.indexOf("application/vnd.api+json")&&t?r.then(m.default):r}function h(e){try{var t=window.location.origin;if(0===e.url.indexOf(t.replace(/^(https?:\/\/\w+)-\w+\./,"$1."))){var n=t+"?"+(0,y.encodeQuery)({disconnect:1});window.location=n}}catch(t){console.warn("Unable to handle invalid token error",t,e)}}Object.defineProperty(t,"__esModule",{value:!0}),t.FetchError=void 0;var p=function(){function e(e,t){var n=[],r=!0,o=!1,i=void 0;try{for(var a,u=e[Symbol.iterator]();!(r=(a=u.next()).done)&&(n.push(a.value),!t||n.length!==t);r=!0);}catch(e){o=!0,i=e}finally{try{!r&&u.return&&u.return()}finally{if(o)throw i}}return n}return function(t,n){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return e(t,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}();t.cozyFetch=a,t.cozyFetchJSON=s,t.cozyFetchRawJSON=c,t.handleInvalidTokenError=h;var v=n(4),y=n(1),g=n(13),m=function(e){return e&&e.__esModule?e:{default:e}}(g),_=t.FetchError=function(e){function t(e,n){r(this,t);var i=o(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return Error.captureStackTrace&&Error.captureStackTrace(i,i.constructor),i.name="FetchError",i.response=e,i.url=e.url,i.status=e.status,i.reason=n,Object.defineProperty(i,"message",{value:n.message||("string"==typeof n?n:JSON.stringify(n))}),i}return i(t,e),t}(Error);_.isUnauthorized=function(e){return"FetchError"===e.name&&401===e.status},_.isNotFound=function(e){return"FetchError"===e.name&&404===e.status},_.isInvalidToken=function(e){return"FetchError"===e.name&&(400===e.status||401===e.status)&&e.reason&&("Invalid JWT token"===e.reason.error||"Expired token"===e.reason.error)}},function(e,t,n){"use strict";function r(e){return function(){for(var t=arguments.length,n=Array(t),r=0;r<t;r++)n[r]=arguments[r];var i=e.apply(this,n);if(!o(i))return i;var a=n.length;if(0!==a&&"function"==typeof n[a-1]){var u=n[a-1];i.then(function(e){return u(null,e)},function(e){return u(e,null)})}}}function o(e){return!!e&&"function"==typeof e.then}function i(){return"undefined"==typeof navigator||navigator.onLine}function a(){return!i()}function u(e,t){return new Promise(function(n){setTimeout(n,e,t)})}function s(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:300;return function r(){for(var o=arguments.length,i=Array(o),a=0;a<o;a++)i[a]=arguments[a];return e.apply(void 0,i).catch(function(e){if(--t<0)throw e;return u(f(n,t)).then(function(){return r.apply(void 0,i)})})}}function c(e){return e*(1+(2*Math.random()-1)*v)}function f(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;return c(e*Math.pow(2,t-1))}function l(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"",o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null,i="/data/";t||(i+=encodeURIComponent(n)+"/"),""!==r&&(i+=encodeURIComponent(r));var a=d(o);return""!==a&&(i+="?"+a),i}function d(e){if(!e)return"";var t="";for(var n in e)""!==t&&(t+="&"),t+=encodeURIComponent(n)+"="+encodeURIComponent(e[n]);return t}function h(e){var t=e.indexOf("?");t<0&&(t=e.length);var n={},r=e.indexOf("#");if(r<0&&(r=e.length),r<t)return n;var o=e.slice(t+1,r);if(""===o)return n;for(var i=o.split("&"),a=0;a<i.length;a++){var u=i[a].split("=");if(0!==u.length&&""!==u[0]){var s=decodeURIComponent(u[0]);if(!n.hasOwnProperty(s))if(1===u.length)n[s]=!0;else{if(2!==u.length)throw new Error("Malformed URL");n[s]=decodeURIComponent(u[1])}}}return n}function p(e){-1===y.indexOf(e)&&(y.push(e),console.warn("cozy-client-js",e))}Object.defineProperty(t,"__esModule",{value:!0}),t.unpromiser=r,t.isPromise=o,t.isOnline=i,t.isOffline=a,t.sleep=u,t.retry=s,t.getFuzzedDelay=c,t.getBackedoffDelay=f,t.createPath=l,t.encodeQuery=d,t.decodeQuery=h,t.warn=p;var v=.3,y=[]},function(e,t,n){"use strict";function r(e,t,n){var r=-1!==n.indexOf(".");if(t&&r){var i=u[n];return i||n.replace(/\./g,"-")}if(!t&&!r){var s=a[n];if(s)return(0,o.warn)("you are using a non-qualified doctype "+n+" assumed to be "+s),s;throw new Error("Doctype "+n+" should be qualified.")}return n}Object.defineProperty(t,"__esModule",{value:!0}),t.DOCTYPE_FILES=void 0,t.normalizeDoctype=r;var o=n(1),i=t.DOCTYPE_FILES="io.cozy.files",a={files:i,folder:i,contact:"io.cozy.contacts",event:"io.cozy.events",track:"io.cozy.labs.music.track",playlist:"io.cozy.labs.music.playlist"},u={};Object.keys(a).forEach(function(e){u[a[e]]=e})},function(e,t,n){"use strict";function r(e){return"undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer||"undefined"!=typeof Blob&&e instanceof Blob}function o(e){if("function"==typeof e.slice)return e.slice(0);var t=new ArrayBuffer(e.byteLength),n=new Uint8Array(t),r=new Uint8Array(e);return n.set(r),t}function i(e){if(e instanceof ArrayBuffer)return o(e);var t=e.size,n=e.type;return"function"==typeof e.slice?e.slice(0,t,n):e.webkitSlice(0,t,n)}function a(e){var t=Object.getPrototypeOf(e);if(null===t)return!0;var n=t.constructor;return"function"==typeof n&&n instanceof n&&T.call(n)==C}function u(e){var t,n,o;if(!e||"object"!=typeof e)return e;if(Array.isArray(e)){for(t=[],n=0,o=e.length;n<o;n++)t[n]=u(e[n]);return t}if(e instanceof Date)return e.toISOString();if(r(e))return i(e);if(!a(e))return e;t={};for(n in e)if(Object.prototype.hasOwnProperty.call(e,n)){var s=u(e[n]);void 0!==s&&(t[n]=s)}return t}function s(e){var t=!1;return w()(function(n){if(t)throw new Error("once called more than once");t=!0,e.apply(this,n)})}function c(e){return w()(function(t){t=u(t);var n=this,r="function"==typeof t[t.length-1]&&t.pop(),o=new Promise(function(r,o){var i;try{var a=s(function(e,t){e?o(e):r(t)});t.push(a),i=e.apply(n,t),i&&"function"==typeof i.then&&r(i)}catch(e){o(e)}});return r&&o.then(function(e){r(null,e)},r),o})}function f(e,t){for(var n={},r=0,o=t.length;r<o;r++){var i=t[r];i in e&&(n[i]=e[i])}return n}function l(){return P}function d(e){l()&&addEventListener("storage",function(t){e.emit(t.key)})}function h(){j.EventEmitter.call(this),this._listeners={},d(this)}function p(e){if("undefined"!=typeof console&&"function"==typeof console[e]){var t=Array.prototype.slice.call(arguments,1);console[e].apply(console,t)}}function v(e){for(var t=[],n=0,r=e.length;n<r;n++)t=t.concat(e[n]);return t}function y(){}function g(e){return"boolean"==typeof e._remote?e._remote:"function"==typeof e.type&&(p("warn","db.type() is deprecated and will be removed in a future version of PouchDB"),"http"===e.type())}function m(e,t,n){return new Promise(function(r,o){e.get(t,function(i,a){if(i){if(404!==i.status)return o(i);a={}}var u=a._rev,s=n(a);if(!s)return r({updated:!1,rev:u});s._id=t,s._rev=u,r(_(e,s,n))})})}function _(e,t,n){return e.put(t).then(function(e){return{updated:!0,rev:e.rev}},function(r){if(409!==r.status)throw r;return m(e,t._id,n)})}n.d(t,"a",function(){return q}),n.d(t,"b",function(){return u}),n.d(t,"c",function(){return v}),n.d(t,"d",function(){return p}),n.d(t,"e",function(){return g}),n.d(t,"g",function(){return c}),n.d(t,"h",function(){return m});var b=n(8),w=n.n(b),k=(n(9),n(15)),O=n.n(k),j=n(16),E=(n.n(j),n(43)),S=n.n(E),x=(n(10),n(18)),A=n.n(x);n(11),n(3);n.d(t,"f",function(){return O.a});var P,T=Function.prototype.toString,C=T.call(Object);try{localStorage.setItem("_pouch_check_localstorage",1),P=!!localStorage.getItem("_pouch_check_localstorage")}catch(e){P=!1}S()(h,j.EventEmitter),h.prototype.addListener=function(e,t,n,r){function o(){function e(){a=!1}if(i._listeners[t]){if(a)return void(a="waiting");a=!0;var u=f(r,["style","include_docs","attachments","conflicts","filter","doc_ids","view","since","query_params","binary","return_docs"]);n.changes(u).on("change",function(e){e.seq>r.since&&!r.cancelled&&(r.since=e.seq,r.onChange(e))}).on("complete",function(){"waiting"===a&&O()(o),a=!1}).on("error",e)}}if(!this._listeners[t]){var i=this,a=!1;this._listeners[t]=o,this.on(e,o)}},h.prototype.removeListener=function(e,t){t in this._listeners&&(j.EventEmitter.prototype.removeListener.call(this,e,this._listeners[t]),delete this._listeners[t])},h.prototype.notifyLocalWindows=function(e){l()&&(localStorage[e]="a"===localStorage[e]?"b":"a")},h.prototype.notify=function(e){this.emit(e),this.notifyLocalWindows(e)};var I;I="function"==typeof Object.assign?Object.assign:function(e){for(var t=Object(e),n=1;n<arguments.length;n++){var r=arguments[n];if(null!=r)for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(t[o]=r[o])}return t};var q=I,D=y.name;A.a.v4},function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){return t||(t=e._clientParams),t instanceof j?t:new j(t)}function i(e,t){var n=o(e,t);return n.isRegistered()?Promise.reject(new Error("Client already registered")):(0,b.cozyFetchJSON)(e,"POST","/auth/register",n.toRegisterJSON(),{disableAuth:!0}).then(function(e){return new j(e)})}function a(e,t){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],r=o(e,t);if(!r.isRegistered())return Promise.reject(new Error("Client not registered"));var i=r.toRegisterJSON();return i.client_id=r.clientID,n&&(i.client_secret=r.clientSecret),(0,b.cozyFetchJSON)(e,"PUT","/auth/register/"+r.clientID,i,{manualAuthCredentials:{token:r}}).then(function(e){return c(e,r)})}function u(e,t){var n=o(e,t);return n.isRegistered()?(0,b.cozyFetchJSON)(e,"DELETE","/auth/register/"+n.clientID,null,{manualAuthCredentials:{token:n}}):Promise.reject(new Error("Client not registered"))}function s(e,t){var n=o(e,t);return n.isRegistered()?(0,_.isOffline)()?Promise.resolve(n):(0,b.cozyFetchJSON)(e,"GET","/auth/register/"+n.clientID,null,{manualAuthCredentials:{token:n}}).then(function(e){return c(e,n)}).catch(function(e){if(b.FetchError.isUnauthorized(e)||b.FetchError.isNotFound(e))throw new Error("Client has been revoked");throw e}):Promise.reject(new Error("Client not registered"))}function c(e,t){var n=new j(e);return!!t&&""!==t.registrationAccessToken&&""===n.registrationAccessToken&&(n.registrationAccessToken=t.registrationAccessToken),n}function f(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[];if(t instanceof j||(t=new j(t)),!t.isRegistered())throw new Error("Client not registered");var r=y(),o={client_id:t.clientID,redirect_uri:t.redirectURI,state:r,response_type:"code",scope:n.join(" ")};return{url:e._url+"/auth/authorize?"+(0,_.encodeQuery)(o),state:r}}function l(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"";if(!n)return Promise.reject(new Error("Missing state value"));var o=v(r);return null===o?Promise.reject(new Error("Missing states from current URL")):n!==o.state?Promise.reject(new Error("Given state does not match url query state")):p(e,t,null,{grant_type:"authorization_code",code:o.code})}function d(e,t,n){return p(e,t,n,{grant_type:"refresh_token",refresh_token:n.refreshToken})}function h(e,t,n,r){function o(o){if(u++>0)throw o;return t.clear().then(function(){return h(e,t,n,r)})}function a(){return t.clear().then(function(){return i(e,n)}).then(function(r){var o=f(e,r,n.scopes),i=o.url,a=o.state;return t.save(O,{client:r,url:i,state:a})})}if(arguments.length>4&&void 0!==arguments[4]&&arguments[4])return t.clear().then(function(){return h(e,t,n,r,!1)});var u=0;return Promise.all([t.load(k),t.load(O)]).then(function(n){var i=g(n,2),u=i[0],c=i[1];if(u){var f=void 0,d=void 0;try{f=new j(u.client),d=new E(u.token)}catch(e){return o(e)}return s(e,f).then(function(e){return{client:e,token:d}}).catch(function(e){if(b.FetchError.isUnauthorized(e)||b.FetchError.isNotFound(e))throw new Error("Client has been revoked");return{client:f,token:d}})}var h=void 0;h=c?Promise.resolve(c):a();var p=void 0,v=void 0,y=void 0;return h.then(function(e){return p=e.client,v=e.state,Promise.resolve(r(p,e.url))}).then(function(t){return l(e,p,v,t)}).then(function(e){y=e}).then(function(){return t.delete(O)}).then(function(){return{client:p,token:y}})}).then(function(e){return t.save(k,e)},function(e){if(b.FetchError.isUnauthorized(e))return o(e);throw e})}function p(e,t,n,r){if(t instanceof j||(t=new j(t)),!t.isRegistered())return Promise.reject(new Error("Client not registered"));var o=(0,_.encodeQuery)(Object.assign({},r,{client_id:t.clientID,client_secret:t.clientSecret}));return(0,b.cozyFetchJSON)(e,"POST","/auth/access_token",o,{disableAuth:null===n,dontRetry:!0,manualAuthCredentials:{client:t,token:n},headers:{"Content-Type":"application/x-www-form-urlencoded"}}).then(function(e){return e.refreshToken=e.refreshToken||r.refresh_token,new E(e)})}function v(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";""===e&&"undefined"!=typeof window&&(e=window.location.href);var t=(0,_.decodeQuery)(e);return t.hasOwnProperty("state")?{state:t.state,code:t.code}:null}function y(){var e=void 0;if("undefined"!=typeof window&&void 0!==window.crypto&&"function"==typeof window.crypto.getRandomValues)e=new Uint8Array(w),window.crypto.getRandomValues(e);else try{e=n(!function(){var e=new Error('Cannot find module "crypto"');throw e.code="MODULE_NOT_FOUND",e}()).randomBytes(w)}catch(t){e=null}if(!e){e=new Array(w);for(var t=0;t<e.length;t++)e[t]=Math.floor(255*Math.random())}return btoa(String.fromCharCode.apply(null,e)).replace(/=+$/,"").replace(/\//g,"_").replace(/\+/g,"-")}Object.defineProperty(t,"__esModule",{value:!0}),t.AppToken=t.AccessToken=t.Client=t.StateKey=t.CredsKey=void 0;var g=function(){function e(e,t){var n=[],r=!0,o=!1,i=void 0;try{for(var a,u=e[Symbol.iterator]();!(r=(a=u.next()).done)&&(n.push(a.value),!t||n.length!==t);r=!0);}catch(e){o=!0,i=e}finally{try{!r&&u.return&&u.return()}finally{if(o)throw i}}return n}return function(t,n){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return e(t,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),m=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();t.client=o,t.registerClient=i,t.updateClient=a,t.unregisterClient=u,t.getClient=s,t.getAuthCodeURL=f,t.getAccessToken=l,t.refreshToken=d,t.oauthFlow=h;var _=n(1),b=n(0),w=16,k=t.CredsKey="creds",O=t.StateKey="state",j=t.Client=function(){function e(t){if(r(this,e),this.clientID=t.clientID||t.client_id||"",this.clientSecret=t.clientSecret||t.client_secret||"",this.registrationAccessToken=t.registrationAccessToken||t.registration_access_token||"",t.redirect_uris?this.redirectURI=t.redirect_uris[0]||"":this.redirectURI=t.redirectURI||"",this.softwareID=t.softwareID||t.software_id||"",this.softwareVersion=t.softwareVersion||t.software_version||"",this.clientName=t.clientName||t.client_name||"",this.clientKind=t.clientKind||t.client_kind||"",this.clientURI=t.clientURI||t.client_uri||"",this.logoURI=t.logoURI||t.logo_uri||"",this.policyURI=t.policyURI||t.policy_uri||"",this.notificationPlatform=t.notificationPlatform||t.notification_platform||"",this.notificationDeviceToken=t.notificationDeviceToken||t.notification_device_token||"",!this.registrationAccessToken){if(""===this.redirectURI)throw new Error("Missing redirectURI field");if(""===this.softwareID)throw new Error("Missing softwareID field");if(""===this.clientName)throw new Error("Missing clientName field")}}return m(e,[{key:"isRegistered",value:function(){return""!==this.clientID}},{key:"toRegisterJSON",value:function(){return{redirect_uris:[this.redirectURI],software_id:this.softwareID,software_version:this.softwareVersion,client_name:this.clientName,client_kind:this.clientKind,client_uri:this.clientURI,logo_uri:this.logoURI,policy_uri:this.policyURI,notification_platform:this.notificationPlatform,notification_device_token:this.notificationDeviceToken}}},{key:"toAuthHeader",value:function(){return"Bearer "+this.registrationAccessToken}}]),e}(),E=t.AccessToken=function(){function e(t){r(this,e),this.tokenType=t.tokenType||t.token_type,this.accessToken=t.accessToken||t.access_token,this.refreshToken=t.refreshToken||t.refresh_token,this.scope=t.scope}return m(e,[{key:"toAuthHeader",value:function(){return"Bearer "+this.accessToken}},{key:"toBasicAuth",value:function(){return"user:"+this.accessToken+"@"}}]),e}();t.AppToken=function(){function e(t){r(this,e),this.token=t.token||""}return m(e,[{key:"toAuthHeader",value:function(){return"Bearer "+this.token}},{key:"toBasicAuth",value:function(){return"user:"+this.token+"@"}}]),e}()},function(e,t,n){e.exports=n(29)},function(e,t,n){"use strict";function r(e,t){var n=e.attributes.services,r=t?(n||[]).filter(t):n;return o(r)}Object.defineProperty(t,"__esModule",{value:!0}),t.pickService=r;var o=(t.errorSerializer=function(){function e(e,t){var n=Object.assign(t,e);return["name","message"].reduce(function(n,r){return e[r]&&(t[r]=e[r]),n},n)}return{serialize:function(t){return e(t,{})},deserialize:function(t){return e(t,new Error(t.message))}}}(),function(e){return e&&e[0]})},function(e,t){var n;n=function(){return this}();try{n=n||Function("return this")()||(0,eval)("this")}catch(e){"object"==typeof window&&(n=window)}e.exports=n},function(e,t,n){"use strict";function r(e){return function(){var t=arguments.length;if(t){for(var n=[],r=-1;++r<t;)n[r]=arguments[r];return e.call(this,n)}return e.call(this,[])}}e.exports=r},function(e,t,n){"use strict";function r(e){return"$"+e}function o(e){return e.substring(1)}function i(){this._store={}}function a(e){if(this._store=new i,e&&Array.isArray(e))for(var t=0,n=e.length;t<n;t++)this.add(e[t])}n.d(t,"b",function(){return u}),n.d(t,"a",function(){return s}),i.prototype.get=function(e){var t=r(e);return this._store[t]},i.prototype.set=function(e,t){var n=r(e);return this._store[n]=t,!0},i.prototype.has=function(e){return r(e)in this._store},i.prototype.delete=function(e){var t=r(e),n=t in this._store;return delete this._store[t],n},i.prototype.forEach=function(e){for(var t=Object.keys(this._store),n=0,r=t.length;n<r;n++){var i=t[n],a=this._store[i];i=o(i),e(a,i)}},Object.defineProperty(i.prototype,"size",{get:function(){return Object.keys(this._store).length}}),a.prototype.add=function(e){return this._store.set(e,!0)},a.prototype.has=function(e){return this._store.has(e)},a.prototype.forEach=function(e){this._store.forEach(function(t,n){e(n)})},Object.defineProperty(a.prototype,"size",{get:function(){return this._store.size}});var u,s;!function(){if("undefined"==typeof Symbol||"undefined"==typeof Map||"undefined"==typeof Set)return!1;var e=Object.getOwnPropertyDescriptor(Map,Symbol.species);return e&&"get"in e&&Map[Symbol.species]===Map}()?(u=a,s=i):(u=Set,s=Map)},function(e,t,n){"use strict";function r(e,t,n){Error.call(this,n),this.status=e,this.name=t,this.message=n,this.error=!0}function o(e,t){function n(t){for(var n in e)"function"!=typeof e[n]&&(this[n]=e[n]);void 0!==t&&(this.reason=t)}return n.prototype=r.prototype,new n(t)}function i(e){if("object"!=typeof e){var t=e;e=f,e.data=t}return"error"in e&&"conflict"===e.error&&(e.name="conflict",e.status=409),"name"in e||(e.name=e.error||"unknown"),"status"in e||(e.status=500),"message"in e||(e.message=e.message||e.reason),e}n.d(t,"b",function(){return u}),n.d(t,"c",function(){return s}),n.d(t,"d",function(){return c}),n.d(t,"a",function(){return l}),n.d(t,"e",function(){return o}),n.d(t,"f",function(){return i});var a=n(44);n.n(a)()(r,Error),r.prototype.toString=function(){return JSON.stringify({status:this.status,name:this.name,message:this.message,reason:this.reason})};var u=(new r(401,"unauthorized","Name or password is incorrect."),new r(400,"bad_request","Missing JSON list of 'docs'"),new r(404,"not_found","missing"),new r(409,"conflict","Document update conflict"),new r(400,"bad_request","_id field must contain a string")),s=new r(412,"missing_id","_id is required for puts"),c=new r(400,"bad_request","Only reserved document ids may start with underscore."),f=(new r(412,"precondition_failed","Database not open"),new r(500,"unknown_error","Database encountered an unknown error")),l=(new r(500,"badarg","Some query argument is invalid"),new r(400,"invalid_request","Request was invalid"),new r(400,"query_parse_error","Some query parameter is invalid"),new r(500,"doc_validation","Bad special document member"),new r(400,"bad_request","Something wrong with the request"));new r(400,"bad_request","Document must be a JSON object"),new r(404,"not_found","Database not found"),new r(500,"indexed_db_went_bad","unknown"),new r(500,"web_sql_went_bad","unknown"),new r(500,"levelDB_went_went_bad","unknown"),new r(403,"forbidden","Forbidden by design doc validate_doc_update function"),new r(400,"bad_request","Invalid rev format"),new r(412,"file_exists","The database could not be created, the file already exists."),new r(412,"missing_stub","A pre-existing attachment stub wasn't found"),new r(413,"invalid_url","Provided URL is invalid")},function(e,t,n){"use strict";(function(e){function r(e){return i.a.hash(e)}n.d(t,"a",function(){return r});var o=(n(21),n(17)),i=n.n(o);e.setImmediate||e.setTimeout}).call(t,n(7))},function(e,t,n){"use strict";function r(e,t,n){for(var r="",o=n-e.length;r.length<o;)r+=t;return r}function o(e,t,n){return r(e,t,n)+e}function i(e,t){if(e===t)return 0;e=a(e),t=a(t);var n=v(e),r=v(t);if(n-r!=0)return n-r;switch(typeof e){case"number":return e-t;case"boolean":return e<t?-1:1;case"string":return h(e,t)}return Array.isArray(e)?d(e,t):p(e,t)}function a(e){switch(typeof e){case"undefined":return null;case"number":return e===1/0||e===-1/0||isNaN(e)?null:e;case"object":var t=e;if(Array.isArray(e)){var n=e.length;e=new Array(n);for(var r=0;r<n;r++)e[r]=a(t[r])}else{if(e instanceof Date)return e.toJSON();if(null!==e){e={};for(var o in t)if(t.hasOwnProperty(o)){var i=t[o];void 0!==i&&(e[o]=a(i))}}}}return e}function u(e){if(null!==e)switch(typeof e){case"boolean":return e?1:0;case"number":return y(e);case"string":return e.replace(/\u0002/g,"").replace(/\u0001/g,"").replace(/\u0000/g,"");case"object":var t=Array.isArray(e),n=t?e:Object.keys(e),r=-1,o=n.length,i="";if(t)for(;++r<o;)i+=s(n[r]);else for(;++r<o;){var a=n[r];i+=s(a)+s(e[a])}return i}return""}function s(e){return e=a(e),v(e)+_+u(e)+"\0"}function c(e,t){var n,r=t;if("1"===e[t])n=0,t++;else{var o="0"===e[t];t++;var i="",a=e.substring(t,t+m),u=parseInt(a,10)+g;for(o&&(u=-u),t+=m;;){var s=e[t];if("\0"===s)break;i+=s,t++}i=i.split("."),n=1===i.length?parseInt(i,10):parseFloat(i[0]+"."+i[1]),o&&(n-=10),0!==u&&(n=parseFloat(n+"e"+u))}return{num:n,length:t-r}}function f(e,t){var n=e.pop();if(t.length){var r=t[t.length-1];n===r.element&&(t.pop(),r=t[t.length-1]);var o=r.element,i=r.index;if(Array.isArray(o))o.push(n);else if(i===e.length-2){var a=e.pop();o[a]=n}else e.push(n)}}function l(e){for(var t=[],n=[],r=0;;){var o=e[r++];if("\0"!==o)switch(o){case"1":t.push(null);break;case"2":t.push("1"===e[r]),r++;break;case"3":var i=c(e,r);t.push(i.num),r+=i.length;break;case"4":for(var a="";;){var u=e[r];if("\0"===u)break;a+=u,r++}a=a.replace(/\u0001\u0001/g,"\0").replace(/\u0001\u0002/g,"").replace(/\u0002\u0002/g,""),t.push(a);break;case"5":var s={element:[],index:t.length};t.push(s.element),n.push(s);break;case"6":var l={element:{},index:t.length};t.push(l.element),n.push(l);break;default:throw new Error("bad collationIndex or unexpectedly reached end of input: "+o)}else{if(1===t.length)return t.pop();f(t,n)}}}function d(e,t){for(var n=Math.min(e.length,t.length),r=0;r<n;r++){var o=i(e[r],t[r]);if(0!==o)return o}return e.length===t.length?0:e.length>t.length?1:-1}function h(e,t){return e===t?0:e>t?1:-1}function p(e,t){for(var n=Object.keys(e),r=Object.keys(t),o=Math.min(n.length,r.length),a=0;a<o;a++){var u=i(n[a],r[a]);if(0!==u)return u;if(0!==(u=i(e[n[a]],t[r[a]])))return u}return n.length===r.length?0:n.length>r.length?1:-1}function v(e){var t=["boolean","number","string","object"],n=t.indexOf(typeof e);return~n?null===e?1:Array.isArray(e)?5:n<3?n+2:n+3:Array.isArray(e)?5:void 0}function y(e){if(0===e)return"1";var t=e.toExponential().split(/e\+?/),n=parseInt(t[1],10),r=e<0,i=r?"0":"2",a=(r?-n:n)-g,u=o(a.toString(),"0",m);i+=_+u;var s=Math.abs(parseFloat(t[0]));r&&(s=10-s);var c=s.toFixed(20);return c=c.replace(/\.?0+$/,""),i+=_+c}n.d(t,"a",function(){return i}),n.d(t,"b",function(){return a}),n.d(t,"d",function(){return s}),n.d(t,"c",function(){return l});var g=-324,m=3,_=""},function(e,t,n){"use strict";function r(e){return e.type+"/"+e.id}function o(e,t){return e[r(t)]}function i(e,t,n){var i={_id:e.id,_type:e.type,_rev:e.meta&&e.meta.rev,links:Object.assign({},e.links,n),attributes:e.attributes,relations:function(n){var r=e.relationships[n];if(void 0!==r&&void 0!==r.data)return null===r.data?null:Array.isArray(r.data)?r.data.map(function(e){return o(t,e)}):o(t,r.data)}};return e.relationships&&(i.relationships=e.relationships),t[r(e)]=i,i}function a(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=e.included;return Array.isArray(n)&&n.forEach(function(n){return i(n,t,e.links)}),Array.isArray(e.data)?e.data.map(function(n){return i(n,t,e.links)}):i(e.data,t,e.links)}Object.defineProperty(t,"__esModule",{value:!0}),t.default=a},function(e,t,n){"use strict";function r(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t.default=e,t}function o(e){return function(){var t=e.apply(this,arguments);return new Promise(function(e,n){function r(o,i){try{var a=t[o](i),u=a.value}catch(e){return void n(e)}if(!a.done)return Promise.resolve(u).then(function(e){r("next",e)},function(e){r("throw",e)});e(u)}return r("next")})}}function i(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:[];if(!t)throw new Error('Misformed intent, "action" property must be provided');if(!n)throw new Error('Misformed intent, "type" property must be provided');var i=(0,p.cozyFetchJSON)(e,"POST","/intents",{data:{type:"io.cozy.intents",attributes:{action:t,type:n,data:r,permissions:o}}});return i.start=function(t,n){var o={filteredServices:r.filteredServices,onReadyCallback:n};return delete r.filteredServices,i.then(function(n){return g.start(e,n,t,r,o)})},i}function a(e,t,n){return _.start(e,t,n)}function u(e){return e.replace(/\?[^/#]*/,"")}function s(e){return!["object","function"].includes(void 0===e?"undefined":d(e))}function c(e,t){var n=Object.keys(t).filter(function(e){return s(t[e])}).map(function(e){return e+"="+t[e]});return n.length?e+"?"+n.join("&"):e}Object.defineProperty(t,"__esModule",{value:!0}),t.redirect=t.getRedirectionURL=void 0;var f=n(5),l=function(e){return e&&e.__esModule?e:{default:e}}(f),d="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},h=t.getRedirectionURL=function(){var e=o(l.default.mark(function e(t,n,r){var o,a,s;return l.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(n||r){e.next=2;break}throw new Error("Cannot retrieve redirection, at least type or doc must be provided");case 2:return e.next=4,i(t,"REDIRECT",n,r);case 4:if(o=e.sent,a=(0,v.pickService)(o)){e.next=8;break}throw new Error("Unable to find a service");case 8:return s=u(a.href),e.abrupt("return",r?c(s,r):s);case 10:case"end":return e.stop()}},e,this)}));return function(t,n,r){return e.apply(this,arguments)}}();t.redirect=function(){var e=o(l.default.mark(function e(t,n,r,o){var i;return l.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(window){e.next=2;break}throw new Error("redirect() method can only be called in a browser");case 2:return e.next=4,h(t,n,r);case 4:if(i=e.sent,!o||"function"!=typeof o){e.next=7;break}return e.abrupt("return",o(i));case 7:window.location.href=i;case 8:case"end":return e.stop()}},e,this)}));return function(t,n,r,o){return e.apply(this,arguments)}}();t.create=i,t.createService=a;var p=n(0),v=n(6),y=n(31),g=r(y),m=n(32),_=r(m)},function(e,t,n){"use strict";(function(t){function n(){f=!0;for(var e,t,n=l.length;n;){for(t=l,l=[],e=-1;++e<n;)t[e]();n=l.length}f=!1}function r(e){1!==l.push(e)||f||o()}var o,i=t.MutationObserver||t.WebKitMutationObserver;if(i){var a=0,u=new i(n),s=t.document.createTextNode("");u.observe(s,{characterData:!0}),o=function(){s.data=a=++a%2}}else if(t.setImmediate||void 0===t.MessageChannel)o="document"in t&&"onreadystatechange"in t.document.createElement("script")?function(){var e=t.document.createElement("script");e.onreadystatechange=function(){n(),e.onreadystatechange=null,e.parentNode.removeChild(e),e=null},t.document.documentElement.appendChild(e)}:function(){setTimeout(n,0)};else{var c=new t.MessageChannel;c.port1.onmessage=n,o=function(){c.port2.postMessage(0)}}var f,l=[];e.exports=r}).call(t,n(7))},function(e,t,n){"use strict";function r(e){console&&console.warn&&console.warn(e)}function o(){o.init.call(this)}function i(e){if("function"!=typeof e)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}function a(e){return void 0===e._maxListeners?o.defaultMaxListeners:e._maxListeners}function u(e,t,n,o){var u,s,c;if(i(n),s=e._events,void 0===s?(s=e._events=Object.create(null),e._eventsCount=0):(void 0!==s.newListener&&(e.emit("newListener",t,n.listener?n.listener:n),s=e._events),c=s[t]),void 0===c)c=s[t]=n,++e._eventsCount;else if("function"==typeof c?c=s[t]=o?[n,c]:[c,n]:o?c.unshift(n):c.push(n),(u=a(e))>0&&c.length>u&&!c.warned){c.warned=!0;var f=new Error("Possible EventEmitter memory leak detected. "+c.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");f.name="MaxListenersExceededWarning",f.emitter=e,f.type=t,f.count=c.length,r(f)}return e}function s(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,0===arguments.length?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function c(e,t,n){var r={fired:!1,wrapFn:void 0,target:e,type:t,listener:n},o=s.bind(r);return o.listener=n,r.wrapFn=o,o}function f(e,t,n){var r=e._events;if(void 0===r)return[];var o=r[t];return void 0===o?[]:"function"==typeof o?n?[o.listener||o]:[o]:n?p(o):d(o,o.length)}function l(e){var t=this._events;if(void 0!==t){var n=t[e];if("function"==typeof n)return 1;if(void 0!==n)return n.length}return 0}function d(e,t){for(var n=new Array(t),r=0;r<t;++r)n[r]=e[r];return n}function h(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}function p(e){for(var t=new Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}function v(e,t){return new Promise(function(n,r){function o(){void 0!==i&&e.removeListener("error",i),n([].slice.call(arguments))}var i;"error"!==t&&(i=function(n){e.removeListener(t,o),r(n)},e.once("error",i)),e.once(t,o)})}var y,g="object"==typeof Reflect?Reflect:null,m=g&&"function"==typeof g.apply?g.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)};y=g&&"function"==typeof g.ownKeys?g.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var _=Number.isNaN||function(e){return e!==e};e.exports=o,e.exports.once=v,o.EventEmitter=o,o.prototype._events=void 0,o.prototype._eventsCount=0,o.prototype._maxListeners=void 0;var b=10;Object.defineProperty(o,"defaultMaxListeners",{enumerable:!0,get:function(){return b},set:function(e){if("number"!=typeof e||e<0||_(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");b=e}}),o.init=function(){void 0!==this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},o.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||_(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this},o.prototype.getMaxListeners=function(){return a(this)},o.prototype.emit=function(e){for(var t=[],n=1;n<arguments.length;n++)t.push(arguments[n]);var r="error"===e,o=this._events;if(void 0!==o)r=r&&void 0===o.error;else if(!r)return!1;if(r){var i;if(t.length>0&&(i=t[0]),i instanceof Error)throw i;var a=new Error("Unhandled error."+(i?" ("+i.message+")":""));throw a.context=i,a}var u=o[e];if(void 0===u)return!1;if("function"==typeof u)m(u,this,t);else for(var s=u.length,c=d(u,s),n=0;n<s;++n)m(c[n],this,t);return!0},o.prototype.addListener=function(e,t){return u(this,e,t,!1)},o.prototype.on=o.prototype.addListener,o.prototype.prependListener=function(e,t){return u(this,e,t,!0)},o.prototype.once=function(e,t){return i(t),this.on(e,c(this,e,t)),this},o.prototype.prependOnceListener=function(e,t){return i(t),this.prependListener(e,c(this,e,t)),this},o.prototype.removeListener=function(e,t){var n,r,o,a,u;if(i(t),void 0===(r=this._events))return this;if(void 0===(n=r[e]))return this;if(n===t||n.listener===t)0==--this._eventsCount?this._events=Object.create(null):(delete r[e],r.removeListener&&this.emit("removeListener",e,n.listener||t));else if("function"!=typeof n){for(o=-1,a=n.length-1;a>=0;a--)if(n[a]===t||n[a].listener===t){u=n[a].listener,o=a;break}if(o<0)return this;0===o?n.shift():h(n,o),1===n.length&&(r[e]=n[0]),void 0!==r.removeListener&&this.emit("removeListener",e,u||t)}return this},o.prototype.off=o.prototype.removeListener,o.prototype.removeAllListeners=function(e){var t,n,r;if(void 0===(n=this._events))return this;if(void 0===n.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==n[e]&&(0==--this._eventsCount?this._events=Object.create(null):delete n[e]),this;if(0===arguments.length){var o,i=Object.keys(n);for(r=0;r<i.length;++r)"removeListener"!==(o=i[r])&&this.removeAllListeners(o);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(t=n[e]))this.removeListener(e,t);else if(void 0!==t)for(r=t.length-1;r>=0;r--)this.removeListener(e,t[r]);return this},o.prototype.listeners=function(e){return f(this,e,!0)},o.prototype.rawListeners=function(e){return f(this,e,!1)},o.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):l.call(e,t)},o.prototype.listenerCount=l,o.prototype.eventNames=function(){return this._eventsCount>0?y(this._events):[]}},function(e,t,n){!function(t){e.exports=t()}(function(e){"use strict";function t(e,t){var n=e[0],r=e[1],o=e[2],i=e[3];n+=(r&o|~r&i)+t[0]-680876936|0,n=(n<<7|n>>>25)+r|0,i+=(n&r|~n&o)+t[1]-389564586|0,i=(i<<12|i>>>20)+n|0,o+=(i&n|~i&r)+t[2]+606105819|0,o=(o<<17|o>>>15)+i|0,r+=(o&i|~o&n)+t[3]-1044525330|0,r=(r<<22|r>>>10)+o|0,n+=(r&o|~r&i)+t[4]-176418897|0,n=(n<<7|n>>>25)+r|0,i+=(n&r|~n&o)+t[5]+1200080426|0,i=(i<<12|i>>>20)+n|0,o+=(i&n|~i&r)+t[6]-1473231341|0,o=(o<<17|o>>>15)+i|0,r+=(o&i|~o&n)+t[7]-45705983|0,r=(r<<22|r>>>10)+o|0,n+=(r&o|~r&i)+t[8]+1770035416|0,n=(n<<7|n>>>25)+r|0,i+=(n&r|~n&o)+t[9]-1958414417|0,i=(i<<12|i>>>20)+n|0,o+=(i&n|~i&r)+t[10]-42063|0,o=(o<<17|o>>>15)+i|0,r+=(o&i|~o&n)+t[11]-1990404162|0,r=(r<<22|r>>>10)+o|0,n+=(r&o|~r&i)+t[12]+1804603682|0,n=(n<<7|n>>>25)+r|0,i+=(n&r|~n&o)+t[13]-40341101|0,i=(i<<12|i>>>20)+n|0,o+=(i&n|~i&r)+t[14]-1502002290|0,o=(o<<17|o>>>15)+i|0,r+=(o&i|~o&n)+t[15]+1236535329|0,r=(r<<22|r>>>10)+o|0,n+=(r&i|o&~i)+t[1]-165796510|0,n=(n<<5|n>>>27)+r|0,i+=(n&o|r&~o)+t[6]-1069501632|0,i=(i<<9|i>>>23)+n|0,o+=(i&r|n&~r)+t[11]+643717713|0,o=(o<<14|o>>>18)+i|0,r+=(o&n|i&~n)+t[0]-373897302|0,r=(r<<20|r>>>12)+o|0,n+=(r&i|o&~i)+t[5]-701558691|0,n=(n<<5|n>>>27)+r|0,i+=(n&o|r&~o)+t[10]+38016083|0,i=(i<<9|i>>>23)+n|0,o+=(i&r|n&~r)+t[15]-660478335|0,o=(o<<14|o>>>18)+i|0,r+=(o&n|i&~n)+t[4]-405537848|0,r=(r<<20|r>>>12)+o|0,n+=(r&i|o&~i)+t[9]+568446438|0,n=(n<<5|n>>>27)+r|0,i+=(n&o|r&~o)+t[14]-1019803690|0,i=(i<<9|i>>>23)+n|0,o+=(i&r|n&~r)+t[3]-187363961|0,o=(o<<14|o>>>18)+i|0,r+=(o&n|i&~n)+t[8]+1163531501|0,r=(r<<20|r>>>12)+o|0,n+=(r&i|o&~i)+t[13]-1444681467|0,n=(n<<5|n>>>27)+r|0,i+=(n&o|r&~o)+t[2]-51403784|0,i=(i<<9|i>>>23)+n|0,o+=(i&r|n&~r)+t[7]+1735328473|0,o=(o<<14|o>>>18)+i|0,r+=(o&n|i&~n)+t[12]-1926607734|0,r=(r<<20|r>>>12)+o|0,n+=(r^o^i)+t[5]-378558|0,n=(n<<4|n>>>28)+r|0,i+=(n^r^o)+t[8]-2022574463|0,i=(i<<11|i>>>21)+n|0,o+=(i^n^r)+t[11]+1839030562|0,o=(o<<16|o>>>16)+i|0,r+=(o^i^n)+t[14]-35309556|0,r=(r<<23|r>>>9)+o|0,n+=(r^o^i)+t[1]-1530992060|0,n=(n<<4|n>>>28)+r|0,i+=(n^r^o)+t[4]+1272893353|0,i=(i<<11|i>>>21)+n|0,o+=(i^n^r)+t[7]-155497632|0,o=(o<<16|o>>>16)+i|0,r+=(o^i^n)+t[10]-1094730640|0,r=(r<<23|r>>>9)+o|0,n+=(r^o^i)+t[13]+681279174|0,n=(n<<4|n>>>28)+r|0,i+=(n^r^o)+t[0]-358537222|0,i=(i<<11|i>>>21)+n|0,o+=(i^n^r)+t[3]-722521979|0,o=(o<<16|o>>>16)+i|0,r+=(o^i^n)+t[6]+76029189|0,r=(r<<23|r>>>9)+o|0,n+=(r^o^i)+t[9]-640364487|0,n=(n<<4|n>>>28)+r|0,i+=(n^r^o)+t[12]-421815835|0,i=(i<<11|i>>>21)+n|0,o+=(i^n^r)+t[15]+530742520|0,o=(o<<16|o>>>16)+i|0,r+=(o^i^n)+t[2]-995338651|0,r=(r<<23|r>>>9)+o|0,n+=(o^(r|~i))+t[0]-198630844|0,n=(n<<6|n>>>26)+r|0,i+=(r^(n|~o))+t[7]+1126891415|0,i=(i<<10|i>>>22)+n|0,o+=(n^(i|~r))+t[14]-1416354905|0,o=(o<<15|o>>>17)+i|0,r+=(i^(o|~n))+t[5]-57434055|0,r=(r<<21|r>>>11)+o|0,n+=(o^(r|~i))+t[12]+1700485571|0,n=(n<<6|n>>>26)+r|0,i+=(r^(n|~o))+t[3]-1894986606|0,i=(i<<10|i>>>22)+n|0,o+=(n^(i|~r))+t[10]-1051523|0,o=(o<<15|o>>>17)+i|0,r+=(i^(o|~n))+t[1]-2054922799|0,r=(r<<21|r>>>11)+o|0,n+=(o^(r|~i))+t[8]+1873313359|0,n=(n<<6|n>>>26)+r|0,i+=(r^(n|~o))+t[15]-30611744|0,i=(i<<10|i>>>22)+n|0,o+=(n^(i|~r))+t[6]-1560198380|0,o=(o<<15|o>>>17)+i|0,r+=(i^(o|~n))+t[13]+1309151649|0,r=(r<<21|r>>>11)+o|0,n+=(o^(r|~i))+t[4]-145523070|0,n=(n<<6|n>>>26)+r|0,i+=(r^(n|~o))+t[11]-1120210379|0,i=(i<<10|i>>>22)+n|0,o+=(n^(i|~r))+t[2]+718787259|0,o=(o<<15|o>>>17)+i|0,r+=(i^(o|~n))+t[9]-343485551|0,r=(r<<21|r>>>11)+o|0,e[0]=n+e[0]|0,e[1]=r+e[1]|0,e[2]=o+e[2]|0,e[3]=i+e[3]|0}function n(e){var t,n=[];for(t=0;t<64;t+=4)n[t>>2]=e.charCodeAt(t)+(e.charCodeAt(t+1)<<8)+(e.charCodeAt(t+2)<<16)+(e.charCodeAt(t+3)<<24);return n}function r(e){var t,n=[];for(t=0;t<64;t+=4)n[t>>2]=e[t]+(e[t+1]<<8)+(e[t+2]<<16)+(e[t+3]<<24);return n}function o(e){var r,o,i,a,u,s,c=e.length,f=[1732584193,-271733879,-1732584194,271733878];for(r=64;r<=c;r+=64)t(f,n(e.substring(r-64,r)));for(e=e.substring(r-64),o=e.length,i=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],r=0;r<o;r+=1)i[r>>2]|=e.charCodeAt(r)<<(r%4<<3);if(i[r>>2]|=128<<(r%4<<3),r>55)for(t(f,i),r=0;r<16;r+=1)i[r]=0;return a=8*c,a=a.toString(16).match(/(.*?)(.{0,8})$/),u=parseInt(a[2],16),s=parseInt(a[1],16)||0,i[14]=u,i[15]=s,t(f,i),f}function i(e){var n,o,i,a,u,s,c=e.length,f=[1732584193,-271733879,-1732584194,271733878];for(n=64;n<=c;n+=64)t(f,r(e.subarray(n-64,n)));for(e=n-64<c?e.subarray(n-64):new Uint8Array(0),o=e.length,i=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],n=0;n<o;n+=1)i[n>>2]|=e[n]<<(n%4<<3);if(i[n>>2]|=128<<(n%4<<3),n>55)for(t(f,i),n=0;n<16;n+=1)i[n]=0;return a=8*c,a=a.toString(16).match(/(.*?)(.{0,8})$/),u=parseInt(a[2],16),s=parseInt(a[1],16)||0,i[14]=u,i[15]=s,t(f,i),f}function a(e){var t,n="";for(t=0;t<4;t+=1)n+=p[e>>8*t+4&15]+p[e>>8*t&15];return n}function u(e){var t;for(t=0;t<e.length;t+=1)e[t]=a(e[t]);return e.join("")}function s(e){return/[\u0080-\uFFFF]/.test(e)&&(e=unescape(encodeURIComponent(e))),e}function c(e,t){var n,r=e.length,o=new ArrayBuffer(r),i=new Uint8Array(o);for(n=0;n<r;n+=1)i[n]=e.charCodeAt(n);return t?i:o}function f(e){return String.fromCharCode.apply(null,new Uint8Array(e))}function l(e,t,n){var r=new Uint8Array(e.byteLength+t.byteLength);return r.set(new Uint8Array(e)),r.set(new Uint8Array(t),e.byteLength),n?r:r.buffer}function d(e){var t,n=[],r=e.length;for(t=0;t<r-1;t+=2)n.push(parseInt(e.substr(t,2),16));return String.fromCharCode.apply(String,n)}function h(){this.reset()}var p=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"];return"5d41402abc4b2a76b9719d911017c592"!==u(o("hello"))&&function(e,t){var n=(65535&e)+(65535&t);return(e>>16)+(t>>16)+(n>>16)<<16|65535&n},"undefined"==typeof ArrayBuffer||ArrayBuffer.prototype.slice||function(){function t(e,t){return e=0|e||0,e<0?Math.max(e+t,0):Math.min(e,t)}ArrayBuffer.prototype.slice=function(n,r){var o,i,a,u,s=this.byteLength,c=t(n,s),f=s;return r!==e&&(f=t(r,s)),c>f?new ArrayBuffer(0):(o=f-c,i=new ArrayBuffer(o),a=new Uint8Array(i),u=new Uint8Array(this,c,o),a.set(u),i)}}(),h.prototype.append=function(e){return this.appendBinary(s(e)),this},h.prototype.appendBinary=function(e){this._buff+=e,this._length+=e.length;var r,o=this._buff.length;for(r=64;r<=o;r+=64)t(this._hash,n(this._buff.substring(r-64,r)));return this._buff=this._buff.substring(r-64),this},h.prototype.end=function(e){var t,n,r=this._buff,o=r.length,i=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(t=0;t<o;t+=1)i[t>>2]|=r.charCodeAt(t)<<(t%4<<3);return this._finish(i,o),n=u(this._hash),e&&(n=d(n)),this.reset(),n},h.prototype.reset=function(){return this._buff="",this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},h.prototype.getState=function(){return{buff:this._buff,length:this._length,hash:this._hash}},h.prototype.setState=function(e){return this._buff=e.buff,this._length=e.length,this._hash=e.hash,this},h.prototype.destroy=function(){delete this._hash,delete this._buff,delete this._length},h.prototype._finish=function(e,n){var r,o,i,a=n;if(e[a>>2]|=128<<(a%4<<3),a>55)for(t(this._hash,e),a=0;a<16;a+=1)e[a]=0;r=8*this._length,r=r.toString(16).match(/(.*?)(.{0,8})$/),o=parseInt(r[2],16),i=parseInt(r[1],16)||0,e[14]=o,e[15]=i,t(this._hash,e)},h.hash=function(e,t){return h.hashBinary(s(e),t)},h.hashBinary=function(e,t){var n=o(e),r=u(n);return t?d(r):r},h.ArrayBuffer=function(){this.reset()},h.ArrayBuffer.prototype.append=function(e){var n,o=l(this._buff.buffer,e,!0),i=o.length;for(this._length+=e.byteLength,n=64;n<=i;n+=64)t(this._hash,r(o.subarray(n-64,n)));return this._buff=n-64<i?new Uint8Array(o.buffer.slice(n-64)):new Uint8Array(0),this},h.ArrayBuffer.prototype.end=function(e){var t,n,r=this._buff,o=r.length,i=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(t=0;t<o;t+=1)i[t>>2]|=r[t]<<(t%4<<3);return this._finish(i,o),n=u(this._hash),e&&(n=d(n)),this.reset(),n},h.ArrayBuffer.prototype.reset=function(){return this._buff=new Uint8Array(0),this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},h.ArrayBuffer.prototype.getState=function(){var e=h.prototype.getState.call(this);return e.buff=f(e.buff),e},h.ArrayBuffer.prototype.setState=function(e){return e.buff=c(e.buff,!0),h.prototype.setState.call(this,e)},h.ArrayBuffer.prototype.destroy=h.prototype.destroy,h.ArrayBuffer.prototype._finish=h.prototype._finish,h.ArrayBuffer.hash=function(e,t){var n=i(new Uint8Array(e)),r=u(n);return t?d(r):r},h})},function(e,t,n){var r=n(39),o=n(40),i=o;i.v1=r,i.v4=o,e.exports=i},function(e,t){var n="undefined"!=typeof crypto&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&msCrypto.getRandomValues.bind(msCrypto);if(n){var r=new Uint8Array(16);e.exports=function(){return n(r),r}}else{var o=new Array(16);e.exports=function(){for(var e,t=0;t<16;t++)0==(3&t)&&(e=4294967296*Math.random()),o[t]=e>>>((3&t)<<3)&255;return o}}},function(e,t){function n(e,t){var n=t||0,o=r;return o[e[n++]]+o[e[n++]]+o[e[n++]]+o[e[n++]]+"-"+o[e[n++]]+o[e[n++]]+"-"+o[e[n++]]+o[e[n++]]+"-"+o[e[n++]]+o[e[n++]]+"-"+o[e[n++]]+o[e[n++]]+o[e[n++]]+o[e[n++]]+o[e[n++]]+o[e[n++]]}for(var r=[],o=0;o<256;++o)r[o]=(o+256).toString(16).substr(1);e.exports=n},function(e,t,n){"use strict";function r(e,t){e=e||[],t=t||{};try{return new Blob(e,t)}catch(i){if("TypeError"!==i.name)throw i;for(var n="undefined"!=typeof BlobBuilder?BlobBuilder:"undefined"!=typeof MSBlobBuilder?MSBlobBuilder:"undefined"!=typeof MozBlobBuilder?MozBlobBuilder:WebKitBlobBuilder,r=new n,o=0;o<e.length;o+=1)r.append(e[o]);return r.getBlob(t.type)}}function o(e){for(var t=e.length,n=new ArrayBuffer(t),r=new Uint8Array(n),o=0;o<t;o++)r[o]=e.charCodeAt(o);return n}function i(e,t){return r([o(e)],{type:t})}function a(e,t){return i(s(e),t)}function u(e,t){var n=new FileReader;n.onloadend=function(e){var n=e.target.result||new ArrayBuffer(0);t(n)},n.readAsArrayBuffer(e)}n.d(t,"b",function(){return c}),n.d(t,"a",function(){return a}),n.d(t,"c",function(){return u});var s=function(e){return atob(e)},c=function(e){return btoa(e)}},function(e,t,n){"use strict";n.d(t,"a",function(){return r});var r=("undefined"!=typeof AbortController&&AbortController,fetch,Headers)},function(e,t,n){"use strict";function r(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t.default=e,t}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(){throw new Error("Missing onRegistered callback")}function a(e,t){return function(){for(var n=arguments.length,r=Array(n),o=0;o<n;o++)r[o]=arguments[o];return t.apply(void 0,[e].concat(r))}}function u(e,t,n,r){for(var o in n){var i=a(e,n[o]);r&&(i=(0,f.unpromiser)(i)),t[o]=i}}var s=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},c=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),f=n(1),l=n(24),d=n(25),h=n(4),p=r(h),v=n(26),y=r(v),g=n(0),m=r(g),_=n(27),b=r(_),w=n(28),k=r(w),O=n(14),j=r(O),E=n(33),S=r(E),x=n(34),A=r(x),P=n(49),T=r(P),C=n(50),I=r(C),q=p.AppToken,D=p.AccessToken,R=p.Client,L={softwareID:"github.com/cozy/cozy-client-js"},$={create:y.create,find:y.find,findMany:y.findMany,findAll:y.findAll,update:y.update,delete:y._delete,updateAttributes:y.updateAttributes,changesFeed:y.changesFeed,defineIndex:b.defineIndex,query:b.query,addReferencedFiles:I.addReferencedFiles,removeReferencedFiles:I.removeReferencedFiles,listReferencedFiles:I.listReferencedFiles,fetchReferencedFiles:I.fetchReferencedFiles,destroy:function(){return(0,f.warn)("destroy is deprecated, use cozy.data.delete instead."),y._delete.apply(y,arguments)}},B={client:p.client,registerClient:p.registerClient,updateClient:p.updateClient,unregisterClient:p.unregisterClient,getClient:p.getClient,getAuthCodeURL:p.getAuthCodeURL,getAccessToken:p.getAccessToken,refreshToken:p.refreshToken},F={create:k.create,createDirectory:k.createDirectory,createDirectoryByPath:k.createDirectoryByPath,updateById:k.updateById,updateAttributesById:k.updateAttributesById,updateAttributesByPath:k.updateAttributesByPath,trashById:k.trashById,statById:k.statById,statByPath:k.statByPath,downloadById:k.do