pouchdb.authentication.min.js 41 KB

12
  1. !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,t.PouchAuthentication=e()}}(function(){var e;return function e(t,n,r){function o(s,a){if(!n[s]){if(!t[s]){var u="function"==typeof require&&require;if(!a&&u)return u(s,!0);if(i)return i(s,!0);var c=new Error("Cannot find module '"+s+"'");throw c.code="MODULE_NOT_FOUND",c}var f=n[s]={exports:{}};t[s][0].call(f.exports,function(e){var n=t[s][1][e];return o(n?n:e)},f,f.exports,e,t,n,r)}return n[s].exports}for(var i="function"==typeof require&&require,s=0;s<r.length;s++)o(r[s]);return o}({1:[function(e,t,n){(function(t){"use strict";function r(e){return"function"==typeof e.getUrl?e.getUrl().replace(/\/[^\/]+\/?$/,""):e.name.replace(/\/[^\/]+\/?$/,"")}var o=e(13),i=e(16);n.getUsersUrl=function(e){return i(r(e),"/_users")},n.getSessionUrl=function(e){return i(r(e),"/_session")},n.once=function(e){var t=!1;return n.getArguments(function(n){if(t)throw console.trace(),new Error("once called more than once");t=!0,e.apply(this,n)})},n.getArguments=function(e){return function(){for(var t=arguments.length,n=new Array(t),r=-1;++r<t;)n[r]=arguments[r];return e.call(this,n)}},n.toPromise=function(e){return n.getArguments(function(r){var i,s=this,a="function"==typeof r[r.length-1]&&r.pop();a&&(i=function(e,n){t.nextTick(function(){a(e,n)})});var u=new o(function(t,o){try{var i=n.once(function(e,n){e?o(e):t(n)});r.push(i),e.apply(s,r)}catch(e){o(e)}});return i&&u.then(function(e){i(null,e)},i),u.cancel=function(){return this},u})},n.inherits=e(7),n.extend=e(12),n.ajax=e(11),n.clone=function(e){return n.extend(!0,{},e)},n.uuid=e(14).uuid,n.Promise=o}).call(this,e(15))},{11:11,12:12,13:13,14:14,15:15,16:16,7:7}],2:[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,[])}}t.exports=r},{}],3:[function(e,t,n){function r(){return"WebkitAppearance"in document.documentElement.style||window.console&&(console.firebug||console.exception&&console.table)||navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31}function o(){var e=arguments,t=this.useColors;if(e[0]=(t?"%c":"")+this.namespace+(t?" %c":" ")+e[0]+(t?"%c ":" ")+"+"+n.humanize(this.diff),!t)return e;var r="color: "+this.color;e=[e[0],r,"color: inherit"].concat(Array.prototype.slice.call(e,1));var o=0,i=0;return e[0].replace(/%[a-z%]/g,function(e){"%%"!==e&&(o++,"%c"===e&&(i=o))}),e.splice(i,0,r),e}function i(){return"object"==typeof console&&console.log&&Function.prototype.apply.call(console.log,console,arguments)}function s(e){try{null==e?n.storage.removeItem("debug"):n.storage.debug=e}catch(e){}}function a(){var e;try{e=n.storage.debug}catch(e){}return e}function u(){try{return window.localStorage}catch(e){}}n=t.exports=e(4),n.log=i,n.formatArgs=o,n.save=s,n.load=a,n.useColors=r,n.storage="undefined"!=typeof chrome&&"undefined"!=typeof chrome.storage?chrome.storage.local:u(),n.colors=["lightseagreen","forestgreen","goldenrod","dodgerblue","darkorchid","crimson"],n.formatters.j=function(e){return JSON.stringify(e)},n.enable(a())},{4:4}],4:[function(e,t,n){function r(){return n.colors[f++%n.colors.length]}function o(e){function t(){}function o(){var e=o,t=+new Date,i=t-(c||t);e.diff=i,e.prev=c,e.curr=t,c=t,null==e.useColors&&(e.useColors=n.useColors()),null==e.color&&e.useColors&&(e.color=r());var s=Array.prototype.slice.call(arguments);s[0]=n.coerce(s[0]),"string"!=typeof s[0]&&(s=["%o"].concat(s));var a=0;s[0]=s[0].replace(/%([a-z%])/g,function(t,r){if("%%"===t)return t;a++;var o=n.formatters[r];if("function"==typeof o){var i=s[a];t=o.call(e,i),s.splice(a,1),a--}return t}),"function"==typeof n.formatArgs&&(s=n.formatArgs.apply(e,s));var u=o.log||n.log||console.log.bind(console);u.apply(e,s)}t.enabled=!1,o.enabled=!0;var i=n.enabled(e)?o:t;return i.namespace=e,i}function i(e){n.save(e);for(var t=(e||"").split(/[\s,]+/),r=t.length,o=0;o<r;o++)t[o]&&(e=t[o].replace(/\*/g,".*?"),"-"===e[0]?n.skips.push(new RegExp("^"+e.substr(1)+"$")):n.names.push(new RegExp("^"+e+"$")))}function s(){n.enable("")}function a(e){var t,r;for(t=0,r=n.skips.length;t<r;t++)if(n.skips[t].test(e))return!1;for(t=0,r=n.names.length;t<r;t++)if(n.names[t].test(e))return!0;return!1}function u(e){return e instanceof Error?e.stack||e.message:e}n=t.exports=o,n.coerce=u,n.disable=s,n.enable=i,n.enabled=a,n.humanize=e(10),n.names=[],n.skips=[],n.formatters={};var c,f=0},{10:10}],5:[function(e,t,n){function r(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function o(e){return"function"==typeof e}function i(e){return"number"==typeof e}function s(e){return"object"==typeof e&&null!==e}function a(e){return void 0===e}t.exports=r,r.EventEmitter=r,r.prototype._events=void 0,r.prototype._maxListeners=void 0,r.defaultMaxListeners=10,r.prototype.setMaxListeners=function(e){if(!i(e)||e<0||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},r.prototype.emit=function(e){var t,n,r,i,u,c;if(this._events||(this._events={}),"error"===e&&(!this._events.error||s(this._events.error)&&!this._events.error.length)){if(t=arguments[1],t instanceof Error)throw t;var f=new Error('Uncaught, unspecified "error" event. ('+t+")");throw f.context=t,f}if(n=this._events[e],a(n))return!1;if(o(n))switch(arguments.length){case 1:n.call(this);break;case 2:n.call(this,arguments[1]);break;case 3:n.call(this,arguments[1],arguments[2]);break;default:i=Array.prototype.slice.call(arguments,1),n.apply(this,i)}else if(s(n))for(i=Array.prototype.slice.call(arguments,1),c=n.slice(),r=c.length,u=0;u<r;u++)c[u].apply(this,i);return!0},r.prototype.addListener=function(e,t){var n;if(!o(t))throw TypeError("listener must be a function");return this._events||(this._events={}),this._events.newListener&&this.emit("newListener",e,o(t.listener)?t.listener:t),this._events[e]?s(this._events[e])?this._events[e].push(t):this._events[e]=[this._events[e],t]:this._events[e]=t,s(this._events[e])&&!this._events[e].warned&&(n=a(this._maxListeners)?r.defaultMaxListeners:this._maxListeners,n&&n>0&&this._events[e].length>n&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"==typeof console.trace&&console.trace())),this},r.prototype.on=r.prototype.addListener,r.prototype.once=function(e,t){function n(){this.removeListener(e,n),r||(r=!0,t.apply(this,arguments))}if(!o(t))throw TypeError("listener must be a function");var r=!1;return n.listener=t,this.on(e,n),this},r.prototype.removeListener=function(e,t){var n,r,i,a;if(!o(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(n=this._events[e],i=n.length,r=-1,n===t||o(n.listener)&&n.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(s(n)){for(a=i;a-- >0;)if(n[a]===t||n[a].listener&&n[a].listener===t){r=a;break}if(r<0)return this;1===n.length?(n.length=0,delete this._events[e]):n.splice(r,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},r.prototype.removeAllListeners=function(e){var t,n;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(n=this._events[e],o(n))this.removeListener(e,n);else if(n)for(;n.length;)this.removeListener(e,n[n.length-1]);return delete this._events[e],this},r.prototype.listeners=function(e){var t;return t=this._events&&this._events[e]?o(this._events[e])?[this._events[e]]:this._events[e].slice():[]},r.prototype.listenerCount=function(e){if(this._events){var t=this._events[e];if(o(t))return 1;if(t)return t.length}return 0},r.listenerCount=function(e,t){return e.listenerCount(t)}},{}],6:[function(e,t,n){(function(e){"use strict";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=e.MutationObserver||e.WebKitMutationObserver;if(i){var s=0,a=new i(n),u=e.document.createTextNode("");a.observe(u,{characterData:!0}),o=function(){u.data=s=++s%2}}else if(e.setImmediate||"undefined"==typeof e.MessageChannel)o="document"in e&&"onreadystatechange"in e.document.createElement("script")?function(){var t=e.document.createElement("script");t.onreadystatechange=function(){n(),t.onreadystatechange=null,t.parentNode.removeChild(t),t=null},e.document.documentElement.appendChild(t)}:function(){setTimeout(n,0)};else{var c=new e.MessageChannel;c.port1.onmessage=n,o=function(){c.port2.postMessage(0)}}var f,l=[];t.exports=r}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],7:[function(e,t,n){"function"==typeof Object.create?t.exports=function(e,t){e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}})}:t.exports=function(e,t){e.super_=t;var n=function(){};n.prototype=t.prototype,e.prototype=new n,e.prototype.constructor=e}},{}],8:[function(e,t,n){(function(e){e("object"==typeof n?n:this)}).call(this,function(e){var t=Array.prototype.slice,n=Array.prototype.forEach,r=function(e){if("object"!=typeof e)throw e+" is not an object";var o=t.call(arguments,1);return n.call(o,function(t){if(t)for(var n in t)"object"==typeof t[n]&&e[n]?r.call(e,e[n],t[n]):e[n]=t[n]}),e};e.extend=r})},{}],9:[function(e,t,n){"use strict";function r(){}function o(e){if("function"!=typeof e)throw new TypeError("resolver must be a function");this.state=g,this.queue=[],this.outcome=void 0,e!==r&&u(this,e)}function i(e,t,n){this.promise=e,"function"==typeof t&&(this.onFulfilled=t,this.callFulfilled=this.otherCallFulfilled),"function"==typeof n&&(this.onRejected=n,this.callRejected=this.otherCallRejected)}function s(e,t,n){p(function(){var r;try{r=t(n)}catch(t){return y.reject(e,t)}r===e?y.reject(e,new TypeError("Cannot resolve promise with itself")):y.resolve(e,r)})}function a(e){var t=e&&e.then;if(e&&"object"==typeof e&&"function"==typeof t)return function(){t.apply(e,arguments)}}function u(e,t){function n(t){i||(i=!0,y.reject(e,t))}function r(t){i||(i=!0,y.resolve(e,t))}function o(){t(r,n)}var i=!1,s=c(o);"error"===s.status&&n(s.value)}function c(e,t){var n={};try{n.value=e(t),n.status="success"}catch(e){n.status="error",n.value=e}return n}function f(e){return e instanceof this?e:y.resolve(new this(r),e)}function l(e){var t=new this(r);return y.reject(t,e)}function d(e){function t(e,t){function r(e){s[t]=e,++a!==o||i||(i=!0,y.resolve(c,s))}n.resolve(e).then(r,function(e){i||(i=!0,y.reject(c,e))})}var n=this;if("[object Array]"!==Object.prototype.toString.call(e))return this.reject(new TypeError("must be an array"));var o=e.length,i=!1;if(!o)return this.resolve([]);for(var s=new Array(o),a=0,u=-1,c=new this(r);++u<o;)t(e[u],u);return c}function h(e){function t(e){n.resolve(e).then(function(e){i||(i=!0,y.resolve(a,e))},function(e){i||(i=!0,y.reject(a,e))})}var n=this;if("[object Array]"!==Object.prototype.toString.call(e))return this.reject(new TypeError("must be an array"));var o=e.length,i=!1;if(!o)return this.resolve([]);for(var s=-1,a=new this(r);++s<o;)t(e[s]);return a}var p=e(6),y={},v=["REJECTED"],m=["FULFILLED"],g=["PENDING"];t.exports=o,o.prototype.catch=function(e){return this.then(null,e)},o.prototype.then=function(e,t){if("function"!=typeof e&&this.state===m||"function"!=typeof t&&this.state===v)return this;var n=new this.constructor(r);if(this.state!==g){var o=this.state===m?e:t;s(n,o,this.outcome)}else this.queue.push(new i(n,e,t));return n},i.prototype.callFulfilled=function(e){y.resolve(this.promise,e)},i.prototype.otherCallFulfilled=function(e){s(this.promise,this.onFulfilled,e)},i.prototype.callRejected=function(e){y.reject(this.promise,e)},i.prototype.otherCallRejected=function(e){s(this.promise,this.onRejected,e)},y.resolve=function(e,t){var n=c(a,t);if("error"===n.status)return y.reject(e,n.value);var r=n.value;if(r)u(e,r);else{e.state=m,e.outcome=t;for(var o=-1,i=e.queue.length;++o<i;)e.queue[o].callFulfilled(t)}return e},y.reject=function(e,t){e.state=v,e.outcome=t;for(var n=-1,r=e.queue.length;++n<r;)e.queue[n].callRejected(t);return e},o.resolve=f,o.reject=l,o.all=d,o.race=h},{6:6}],10:[function(e,t,n){function r(e){if(e=""+e,!(e.length>1e4)){var t=/^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(e);if(t){var n=parseFloat(t[1]),r=(t[2]||"ms").toLowerCase();switch(r){case"years":case"year":case"yrs":case"yr":case"y":return n*l;case"days":case"day":case"d":return n*f;case"hours":case"hour":case"hrs":case"hr":case"h":return n*c;case"minutes":case"minute":case"mins":case"min":case"m":return n*u;case"seconds":case"second":case"secs":case"sec":case"s":return n*a;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return n}}}}function o(e){return e>=f?Math.round(e/f)+"d":e>=c?Math.round(e/c)+"h":e>=u?Math.round(e/u)+"m":e>=a?Math.round(e/a)+"s":e+"ms"}function i(e){return s(e,f,"day")||s(e,c,"hour")||s(e,u,"minute")||s(e,a,"second")||e+" ms"}function s(e,t,n){if(!(e<t))return e<1.5*t?Math.floor(e/t)+" "+n:Math.ceil(e/t)+" "+n+"s"}var a=1e3,u=60*a,c=60*u,f=24*c,l=365.25*f;t.exports=function(e,t){return t=t||{},"string"==typeof e?r(e):t.long?i(e):o(e)}},{}],11:[function(e,t,n){"use strict";function r(e){return e&&"object"==typeof e&&"default"in e?e.default:e}function o(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 i(e,t){if("undefined"==typeof FileReader)return t((new FileReaderSync).readAsArrayBuffer(e));var n=new FileReader;n.onloadend=function(e){var n=e.target.result||new ArrayBuffer(0);t(n)},n.readAsArrayBuffer(e)}function s(){for(var e={},t=new A(function(t,n){e.resolve=t,e.reject=n}),n=new Array(arguments.length),r=0;r<n.length;r++)n[r]=arguments[r];return e.promise=t,A.resolve().then(function(){return fetch.apply(null,n)}).then(function(t){e.resolve(t)}).catch(function(t){e.reject(t)}),e}function a(e,t){var n,r,o,a=new Headers,u={method:e.method,credentials:"include",headers:a};return e.json&&(a.set("Accept","application/json"),a.set("Content-Type",e.headers["Content-Type"]||"application/json")),e.body&&e.body instanceof Blob?i(e.body,function(e){u.body=e}):e.body&&e.processData&&"string"!=typeof e.body?u.body=JSON.stringify(e.body):"body"in e?u.body=e.body:u.body=null,Object.keys(e.headers).forEach(function(t){e.headers.hasOwnProperty(t)&&a.set(t,e.headers[t])}),n=s(e.url,u),e.timeout>0&&(r=setTimeout(function(){n.reject(new Error("Load timeout for resource: "+e.url))},e.timeout)),n.promise.then(function(t){return o={statusCode:t.status},e.timeout>0&&clearTimeout(r),o.statusCode>=200&&o.statusCode<300?e.binary?t.blob():t.text():t.json()}).then(function(e){o.statusCode>=200&&o.statusCode<300?t(null,o,e):t(e,o)}).catch(function(e){t(e,o)}),{abort:n.reject}}function u(e,t){var n,r,s=!1,a=function(){n.abort(),f()},u=function(){s=!0,n.abort(),f()},c={abort:a},f=function(){clearTimeout(r),c.abort=function(){},n&&(n.onprogress=void 0,n.upload&&(n.upload.onprogress=void 0),n.onreadystatechange=void 0,n=void 0)};n=e.xhr?new e.xhr:new XMLHttpRequest;try{n.open(e.method,e.url)}catch(e){return t(new Error(e.name||"Url is invalid"))}n.withCredentials=!("withCredentials"in e)||e.withCredentials,"GET"===e.method?delete e.headers["Content-Type"]:e.json&&(e.headers.Accept="application/json",e.headers["Content-Type"]=e.headers["Content-Type"]||"application/json",e.body&&e.processData&&"string"!=typeof e.body&&(e.body=JSON.stringify(e.body))),e.binary&&(n.responseType="arraybuffer"),"body"in e||(e.body=null);for(var l in e.headers)e.headers.hasOwnProperty(l)&&n.setRequestHeader(l,e.headers[l]);return e.timeout>0&&(r=setTimeout(u,e.timeout),n.onprogress=function(){clearTimeout(r),4!==n.readyState&&(r=setTimeout(u,e.timeout))},"undefined"!=typeof n.upload&&(n.upload.onprogress=n.onprogress)),n.onreadystatechange=function(){if(4===n.readyState){var r={statusCode:n.status};if(n.status>=200&&n.status<300){var i;i=e.binary?o([n.response||""],{type:n.getResponseHeader("Content-Type")}):n.responseText,t(null,r,i)}else{var a={};if(s)a=new Error("ETIMEDOUT"),a.code="ETIMEDOUT";else if("string"==typeof n.response)try{a=JSON.parse(n.response)}catch(e){}a.status=n.status,t(a)}f()}},e.body&&e.body instanceof Blob?i(e.body,function(e){n.send(e)}):n.send(e.body),c}function c(){try{return new XMLHttpRequest,!0}catch(e){return!1}}function f(e,t){return q||e.xhr?u(e,t):a(e,t)}function l(e){Error.call(this,e.reason),this.status=e.status,this.name=e.error,this.message=e.reason,this.error=!0}function d(e){if("object"!=typeof e){var t=e;e=P,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}function h(e){return"undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer||"undefined"!=typeof Blob&&e instanceof Blob}function p(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 y(e){if(e instanceof ArrayBuffer)return p(e);var t=e.size,n=e.type;return"function"==typeof e.slice?e.slice(0,t,n):e.webkitSlice(0,t,n)}function v(e){var t=Object.getPrototypeOf(e);if(null===t)return!0;var n=t.constructor;return"function"==typeof n&&n instanceof n&&B.call(n)==D}function m(e){var t,n,r;if(!e||"object"!=typeof e)return e;if(Array.isArray(e)){for(t=[],n=0,r=e.length;n<r;n++)t[n]=m(e[n]);return t}if(e instanceof Date)return e.toISOString();if(h(e))return y(e);if(!v(e))return e;t={};for(n in e)if(Object.prototype.hasOwnProperty.call(e,n)){var o=m(e[n]);"undefined"!=typeof o&&(t[n]=o)}return t}function g(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 w(){return"undefined"!=typeof chrome&&"undefined"!=typeof chrome.storage&&"undefined"!=typeof chrome.storage.local}function b(){return U}function _(e){w()?chrome.storage.onChanged.addListener(function(t){null!=t.db_name&&e.emit(t.dbName.newValue)}):b()&&("undefined"!=typeof addEventListener?addEventListener("storage",function(t){e.emit(t.key)}):window.attachEvent("storage",function(t){e.emit(t.key)}))}function j(){C.EventEmitter.call(this),this._listeners={},_(this)}function x(){return""}function E(e,t){function n(t,n,r){if(!e.binary&&e.json&&"string"==typeof t)try{t=JSON.parse(t)}catch(e){return r(e)}Array.isArray(t)&&(t=t.map(function(e){return e.error||e.missing?d(e):e})),e.binary&&N(t,n),r(null,t,n)}e=m(e);var r={method:"GET",headers:{},json:!0,processData:!0,timeout:1e4,cache:!1};return e=S.extend(r,e),e.json&&(e.binary||(e.headers.Accept="application/json"),e.headers["Content-Type"]=e.headers["Content-Type"]||"application/json"),e.binary&&(e.encoding=null,e.json=!1),e.processData||(e.json=!1),f(e,function(r,o,i){if(r)return t(d(r));var s,a=o.headers&&o.headers["content-type"],u=i||x();if(!e.binary&&(e.json||!e.processData)&&"object"!=typeof u&&(/json/.test(a)||/^[\s]*\{/.test(u)&&/\}[\s]*$/.test(u)))try{u=JSON.parse(u.toString())}catch(e){}o.statusCode>=200&&o.statusCode<300?n(u,o,t):(s=d(u),s.status=o.statusCode,t(s))})}function T(e,t){var n=navigator&&navigator.userAgent?navigator.userAgent.toLowerCase():"",r=n.indexOf("safari")!==-1&&n.indexOf("chrome")===-1,o=n.indexOf("msie")!==-1,i=n.indexOf("edge")!==-1,s=r||(o||i)&&"GET"===e.method,a=!("cache"in e)||e.cache,u=/^blob:/.test(e.url);if(!u&&(s||!a)){var c=e.url.indexOf("?")!==-1;e.url+=(c?"&":"?")+"_nonce="+Date.now()}return E(e,t)}var O=r(e(9)),S=e(8),L=r(e(7)),k=(r(e(2)),r(e(3))),C=e(5),A="function"==typeof Promise?Promise:O,q=c();L(l,Error),l.prototype.toString=function(){return JSON.stringify({status:this.status,name:this.name,message:this.message,reason:this.reason})};var U,P=(new l({status:401,error:"unauthorized",reason:"Name or password is incorrect."}),new l({status:400,error:"bad_request",reason:"Missing JSON list of 'docs'"}),new l({status:404,error:"not_found",reason:"missing"}),new l({status:409,error:"conflict",reason:"Document update conflict"}),new l({status:400,error:"bad_request",reason:"_id field must contain a string"}),new l({status:412,error:"missing_id",reason:"_id is required for puts"}),new l({status:400,error:"bad_request",reason:"Only reserved document ids may start with underscore."}),new l({status:412,error:"precondition_failed",reason:"Database not open"}),new l({status:500,error:"unknown_error",reason:"Database encountered an unknown error"})),B=(new l({status:500,error:"badarg",reason:"Some query argument is invalid"}),new l({status:400,error:"invalid_request",reason:"Request was invalid"}),new l({status:400,error:"query_parse_error",reason:"Some query parameter is invalid"}),new l({status:500,error:"doc_validation",reason:"Bad special document member"}),new l({status:400,error:"bad_request",reason:"Something wrong with the request"}),new l({status:400,error:"bad_request",reason:"Document must be a JSON object"}),new l({status:404,error:"not_found",reason:"Database not found"}),new l({status:500,error:"indexed_db_went_bad",reason:"unknown"}),new l({status:500,error:"web_sql_went_bad",reason:"unknown"}),new l({status:500,error:"levelDB_went_went_bad",reason:"unknown"}),new l({status:403,error:"forbidden",reason:"Forbidden by design doc validate_doc_update function"}),new l({status:400,error:"bad_request",reason:"Invalid rev format"}),new l({status:412,error:"file_exists",reason:"The database could not be created, the file already exists."}),new l({status:412,error:"missing_stub"}),new l({status:413,error:"invalid_url",reason:"Provided URL is invalid"}),Function.prototype.toString),D=B.call(Object);k("pouchdb:api");if(w())U=!1;else try{localStorage.setItem("_pouch_check_localstorage",1),U=!!localStorage.getItem("_pouch_check_localstorage")}catch(e){U=!1}L(j,C.EventEmitter),j.prototype.addListener=function(e,t,n,r){function o(){function e(){s=!1}if(i._listeners[t]){if(s)return void(s="waiting");s=!0;var a=g(r,["style","include_docs","attachments","conflicts","filter","doc_ids","view","since","query_params","binary"]);n.changes(a).on("change",function(e){e.seq>r.since&&!r.cancelled&&(r.since=e.seq,r.onChange(e))}).on("complete",function(){"waiting"===s&&setTimeout(function(){o()},0),s=!1}).on("error",e)}}if(!this._listeners[t]){var i=this,s=!1;this._listeners[t]=o,this.on(e,o)}},j.prototype.removeListener=function(e,t){t in this._listeners&&(C.EventEmitter.prototype.removeListener.call(this,e,this._listeners[t]),delete this._listeners[t])},j.prototype.notifyLocalWindows=function(e){w()?chrome.storage.local.set({dbName:e}):b()&&(localStorage[e]="a"===localStorage[e]?"b":"a")},j.prototype.notify=function(e){this.emit(e),this.notifyLocalWindows(e)};var N=("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),function(){});t.exports=T},{2:2,3:3,5:5,7:7,8:8,9:9}],12:[function(e,t,n){"use strict";function r(e){return null===e?String(e):"object"==typeof e||"function"==typeof e?c[h.call(e)]||"object":typeof e}function o(e){return null!==e&&e===e.window}function i(e){if(!e||"object"!==r(e)||e.nodeType||o(e))return!1;try{if(e.constructor&&!p.call(e,"constructor")&&!p.call(e.constructor.prototype,"isPrototypeOf"))return!1}catch(e){return!1}var t;for(t in e);return void 0===t||p.call(e,t)}function s(e){return"function"===r(e)}function a(){for(var e=[],t=-1,n=arguments.length,r=new Array(n);++t<n;)r[t]=arguments[t];var o={};e.push({args:r,result:{container:o,key:"key"}});for(var i;i=e.pop();)u(e,i.args,i.result);return o.key}function u(e,t,n){var r,o,a,u,c,f,l,d=t[0]||{},h=1,p=t.length,v=!1,m=/\d+/;for("boolean"==typeof d&&(v=d,d=t[1]||{},h=2),"object"==typeof d||s(d)||(d={}),p===h&&(d=this,--h);h<p;h++)if(null!=(r=t[h])){l=y(r);for(o in r)if(!(o in Object.prototype)){if(l&&!m.test(o))continue;if(a=d[o],u=r[o],d===u)continue;v&&u&&(i(u)||(c=y(u)))?(c?(c=!1,f=a&&y(a)?a:[]):f=a&&i(a)?a:{},e.push({args:[v,f,u],result:{container:d,key:o}})):void 0!==u&&(y(r)&&s(u)||(d[o]=u))}}n.container[n.key]=d}for(var c={},f=["Boolean","Number","String","Function","Array","Date","RegExp","Object","Error"],l=0;l<f.length;l++){var d=f[l];c["[object "+d+"]"]=d.toLowerCase()}var h=c.toString,p=c.hasOwnProperty,y=Array.isArray||function(e){return"array"===r(e)};t.exports=a},{}],13:[function(e,t,n){"use strict";function r(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var o=r(e(9)),i="function"==typeof Promise?Promise:o;t.exports=i},{9:9}],14:[function(e,t,n){(function(t){"use strict";function r(e){return e&&"object"==typeof e&&"default"in e?e.default:e}function o(e){return"undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer||"undefined"!=typeof Blob&&e instanceof Blob}function i(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 s(e){if(e instanceof ArrayBuffer)return i(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&&K.call(n)==V}function u(e){var t,n,r;if(!e||"object"!=typeof e)return e;if(Array.isArray(e)){for(t=[],n=0,r=e.length;n<r;n++)t[n]=u(e[n]);return t}if(e instanceof Date)return e.toISOString();if(o(e))return s(e);if(!a(e))return e;t={};for(n in e)if(Object.prototype.hasOwnProperty.call(e,n)){var i=u(e[n]);"undefined"!=typeof i&&(t[n]=i)}return t}function c(e){var t=!1;return $(function(n){if(t)throw new Error("once called more than once");t=!0,e.apply(this,n)})}function f(e){return $(function(n){n=u(n);var r,o=this,i="function"==typeof n[n.length-1]&&n.pop();i&&(r=function(e,n){t.nextTick(function(){i(e,n)})});var s=new H(function(t,r){var i;try{var s=c(function(e,n){e?r(e):t(n)});n.push(s),i=e.apply(o,n),i&&"function"==typeof i.then&&t(i)}catch(e){r(e)}});return r&&s.then(function(e){r(null,e)},r),s})}function l(e,t){function n(e,t,n){if(X.enabled){for(var r=[e.name,t],o=0;o<n.length-1;o++)r.push(n[o]);X.apply(null,r);var i=n[n.length-1];n[n.length-1]=function(n,r){var o=[e.name,t];o=o.concat(n?["error",n]:["success",r]),X.apply(null,o),i(n,r)}}}return f($(function(r){if(this._closed)return H.reject(new Error("database is closed"));if(this._destroyed)return H.reject(new Error("database is destroyed"));var o=this;return n(o,e,r),this.taskqueue.isReady?t.apply(this,r):new H(function(t,n){o.taskqueue.addTask(function(i){i?n(i):t(o[e].apply(o,r))})})}))}function d(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 h(e){return e}function p(e){return[{ok:e}]}function y(e,t,n){function r(){var e=[];y.forEach(function(t){t.docs.forEach(function(n){e.push({id:t.id,docs:[n]})})}),n(null,{results:e})}function o(){++l===f&&r()}function i(e,t,n){y[e]={id:t,docs:n},o()}function s(){if(!(m>=v.length)){var e=Math.min(m+Q,v.length),t=v.slice(m,e);a(t,m),m+=t.length}}function a(n,r){n.forEach(function(n,o){var a=r+o,u=c[n],f=d(u[0],["atts_since","attachments"]);f.open_revs=u.map(function(e){return e.rev}),f.open_revs=f.open_revs.filter(h);var l=h;0===f.open_revs.length&&(delete f.open_revs,l=p),["revs","attachments","binary","ajax"].forEach(function(e){e in t&&(f[e]=t[e])}),e.get(n,f,function(e,t){var r;r=e?[{error:e}]:l(t),i(a,n,r),s()})})}var u=t.docs,c={};u.forEach(function(e){e.id in c?c[e.id].push(e):c[e.id]=[e]});var f=Object.keys(c).length,l=0,y=new Array(f),v=Object.keys(c),m=0;s()}function v(){return"undefined"!=typeof chrome&&"undefined"!=typeof chrome.storage&&"undefined"!=typeof chrome.storage.local}function m(){return J}function g(e){v()?chrome.storage.onChanged.addListener(function(t){null!=t.db_name&&e.emit(t.dbName.newValue)}):m()&&("undefined"!=typeof addEventListener?addEventListener("storage",function(t){e.emit(t.key)}):window.attachEvent("storage",function(t){e.emit(t.key)}))}function w(){W.EventEmitter.call(this),this._listeners={},g(this)}function b(e){if("undefined"!==console&&e in console){var t=Array.prototype.slice.call(arguments,1);console[e].apply(console,t)}}function _(e,t){var n=6e5;e=parseInt(e,10)||0,t=parseInt(t,10),t!==t||t<=e?t=(e||1)<<1:t+=1,t>n&&(e=n>>1,t=n);var r=Math.random(),o=t-e;return~~(o*r+e)}function j(e){var t=0;return e||(t=2e3),_(e,t)}function x(e,t){b("info","The above "+e+" is totally normal. "+t)}function E(e,t){for(var n in t)if(t.hasOwnProperty(n)){var r=u(t[n]);"undefined"!=typeof r&&(e[n]=r)}}function T(e,t,n){return E(e,t),n&&E(e,n),e}function O(e){Error.call(this,e.reason),this.status=e.status,this.name=e.error,this.message=e.reason,this.error=!0}function S(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=O.prototype,new n(t)}function L(e,t,n){try{return!e(t,n)}catch(e){var r="Filter function threw: "+e.toString();return S(re,r)}}function k(e){var t={},n=e.filter&&"function"==typeof e.filter;return t.query=e.query_params,function(r){r.doc||(r.doc={});var o=n&&L(e.filter,r.doc,t);if("object"==typeof o)return o;if(o)return!1;if(e.include_docs){if(!e.attachments)for(var i in r.doc._attachments)r.doc._attachments.hasOwnProperty(i)&&(r.doc._attachments[i].stub=!0)}else delete r.doc;return!0}}function C(e){for(var t=[],n=0,r=e.length;n<r;n++)t=t.concat(e[n]);return t}function A(){}function q(e){var t;if(e?"string"!=typeof e?t=S(ee):/^_/.test(e)&&!/^_(design|local)/.test(e)&&(t=S(ne)):t=S(te),t)throw t}function U(){return"undefined"!=typeof cordova||"undefined"!=typeof PhoneGap||"undefined"!=typeof phonegap}function P(e,t){return"listenerCount"in e?e.listenerCount(t):W.EventEmitter.listenerCount(e,t)}function B(e){if(!e)return null;var t=e.split("/");return 2===t.length?t:1===t.length?[e,e]:null}function D(e){var t=B(e);return t?t.join("/"):null}function N(e){for(var t=ce.exec(e),n={},r=14;r--;){var o=se[r],i=t[r]||"",s=["user","password"].indexOf(o)!==-1;n[o]=s?decodeURIComponent(i):i}return n[ae]={},n[se[12]].replace(ue,function(e,t,r){t&&(n[ae][t]=r)}),n}function M(e,t,n){return new H(function(r,o){e.get(t,function(i,s){if(i){if(404!==i.status)return o(i);s={}}var a=s._rev,u=n(s);return u?(u._id=t,u._rev=a,void r(R(e,u,n))):r({updated:!1,rev:a})})})}function R(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)})}function I(e){return 0|Math.random()*e}function F(e,t){t=t||fe.length;var n="",r=-1;if(e){for(;++r<e;)n+=fe[I(t)];return n}for(;++r<36;)switch(r){case 8:case 13:case 18:case 23:n+="-";break;case 19:n+=fe[3&I(16)|8];break;default:n+=fe[I(16)]}return n}Object.defineProperty(n,"__esModule",{value:!0});var J,z=r(e(9)),$=r(e(2)),G=r(e(3)),W=e(5),Y=r(e(7)),H="function"==typeof Promise?Promise:z,K=Function.prototype.toString,V=K.call(Object),X=G("pouchdb:api"),Q=6;if(v())J=!1;else try{localStorage.setItem("_pouch_check_localstorage",1),J=!!localStorage.getItem("_pouch_check_localstorage")}catch(e){J=!1}Y(w,W.EventEmitter),w.prototype.addListener=function(e,t,n,r){function o(){function e(){s=!1}if(i._listeners[t]){if(s)return void(s="waiting");s=!0;var a=d(r,["style","include_docs","attachments","conflicts","filter","doc_ids","view","since","query_params","binary"]);
  2. n.changes(a).on("change",function(e){e.seq>r.since&&!r.cancelled&&(r.since=e.seq,r.onChange(e))}).on("complete",function(){"waiting"===s&&setTimeout(function(){o()},0),s=!1}).on("error",e)}}if(!this._listeners[t]){var i=this,s=!1;this._listeners[t]=o,this.on(e,o)}},w.prototype.removeListener=function(e,t){t in this._listeners&&(W.EventEmitter.prototype.removeListener.call(this,e,this._listeners[t]),delete this._listeners[t])},w.prototype.notifyLocalWindows=function(e){v()?chrome.storage.local.set({dbName:e}):m()&&(localStorage[e]="a"===localStorage[e]?"b":"a")},w.prototype.notify=function(e){this.emit(e),this.notifyLocalWindows(e)},Y(O,Error),O.prototype.toString=function(){return JSON.stringify({status:this.status,name:this.name,message:this.message,reason:this.reason})};var Z,ee=(new O({status:401,error:"unauthorized",reason:"Name or password is incorrect."}),new O({status:400,error:"bad_request",reason:"Missing JSON list of 'docs'"}),new O({status:404,error:"not_found",reason:"missing"}),new O({status:409,error:"conflict",reason:"Document update conflict"}),new O({status:400,error:"bad_request",reason:"_id field must contain a string"})),te=new O({status:412,error:"missing_id",reason:"_id is required for puts"}),ne=new O({status:400,error:"bad_request",reason:"Only reserved document ids may start with underscore."}),re=(new O({status:412,error:"precondition_failed",reason:"Database not open"}),new O({status:500,error:"unknown_error",reason:"Database encountered an unknown error"}),new O({status:500,error:"badarg",reason:"Some query argument is invalid"}),new O({status:400,error:"invalid_request",reason:"Request was invalid"}),new O({status:400,error:"query_parse_error",reason:"Some query parameter is invalid"}),new O({status:500,error:"doc_validation",reason:"Bad special document member"}),new O({status:400,error:"bad_request",reason:"Something wrong with the request"})),oe=(new O({status:400,error:"bad_request",reason:"Document must be a JSON object"}),new O({status:404,error:"not_found",reason:"Database not found"}),new O({status:500,error:"indexed_db_went_bad",reason:"unknown"}),new O({status:500,error:"web_sql_went_bad",reason:"unknown"}),new O({status:500,error:"levelDB_went_went_bad",reason:"unknown"}),new O({status:403,error:"forbidden",reason:"Forbidden by design doc validate_doc_update function"}),new O({status:400,error:"bad_request",reason:"Invalid rev format"}),new O({status:412,error:"file_exists",reason:"The database could not be created, the file already exists."}),new O({status:412,error:"missing_stub"}),new O({status:413,error:"invalid_url",reason:"Provided URL is invalid"}),A.name);Z=oe?function(e){return e.name}:function(e){return e.toString().match(/^\s*function\s*(\S*)\s*\(/)[1]};var ie=Z,se=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],ae="queryKey",ue=/(?:^|&)([^&=]*)=?([^&]*)/g,ce=/^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,fe="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split("");n.adapterFun=l,n.bulkGetShim=y,n.changesHandler=w,n.clone=u,n.defaultBackOff=j,n.explainError=x,n.extend=T,n.filterChange=k,n.flatten=C,n.functionName=ie,n.guardedConsole=b,n.hasLocalStorage=m,n.invalidIdError=q,n.isChromeApp=v,n.isCordova=U,n.listenerCount=P,n.normalizeDdocFunctionName=D,n.once=c,n.parseDdocFunctionName=B,n.parseUri=N,n.pick=d,n.toPromise=f,n.upsert=M,n.uuid=F}).call(this,e(15))},{15:15,2:2,3:3,5:5,7:7,9:9}],15:[function(e,t,n){function r(){throw new Error("setTimeout has not been defined")}function o(){throw new Error("clearTimeout has not been defined")}function i(e){if(l===setTimeout)return setTimeout(e,0);if((l===r||!l)&&setTimeout)return l=setTimeout,setTimeout(e,0);try{return l(e,0)}catch(t){try{return l.call(null,e,0)}catch(t){return l.call(this,e,0)}}}function s(e){if(d===clearTimeout)return clearTimeout(e);if((d===o||!d)&&clearTimeout)return d=clearTimeout,clearTimeout(e);try{return d(e)}catch(t){try{return d.call(null,e)}catch(t){return d.call(this,e)}}}function a(){v&&p&&(v=!1,p.length?y=p.concat(y):m=-1,y.length&&u())}function u(){if(!v){var e=i(a);v=!0;for(var t=y.length;t;){for(p=y,y=[];++m<t;)p&&p[m].run();m=-1,t=y.length}p=null,v=!1,s(e)}}function c(e,t){this.fun=e,this.array=t}function f(){}var l,d,h=t.exports={};!function(){try{l="function"==typeof setTimeout?setTimeout:r}catch(e){l=r}try{d="function"==typeof clearTimeout?clearTimeout:o}catch(e){d=o}}();var p,y=[],v=!1,m=-1;h.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)t[n-1]=arguments[n];y.push(new c(e,t)),1!==y.length||v||i(u)},c.prototype.run=function(){this.fun.apply(null,this.array)},h.title="browser",h.browser=!0,h.env={},h.argv=[],h.version="",h.versions={},h.on=f,h.addListener=f,h.once=f,h.off=f,h.removeListener=f,h.removeAllListeners=f,h.emit=f,h.binding=function(e){throw new Error("process.binding is not supported")},h.cwd=function(){return"/"},h.chdir=function(e){throw new Error("process.chdir is not supported")},h.umask=function(){return 0}},{}],16:[function(t,n,r){!function(t,r,o){"undefined"!=typeof n&&n.exports?n.exports=o():"function"==typeof e&&e.amd?e(o):r[t]=o()}("urljoin",this,function(){function e(e,t){return e=e.replace(/:\//g,"://"),e=e.replace(/([^:\s])\/+/g,"$1/"),e=e.replace(/\/(\?|&|#[^!])/g,"$1"),e=e.replace(/(\?.+)\?/g,"$1&")}return function(){var t=arguments,n={};"object"==typeof arguments[0]&&(t=arguments[0],n=arguments[1]||{});var r=[].slice.call(t,0).join("/");return e(r,n)}})},{}],17:[function(e,t,n){"use strict";function r(e){return function(t,n){return t&&"unknown_error"===t.name&&(t.message=(t.message||"")+" Unknown error! Did you remember to enable CORS?"),e(t,n)}}function o(e,t,n,o){var a=["name","password","roles","type","salt","metadata"];if(n.metadata){for(var u in n.metadata)if(n.hasOwnProperty(u)&&(a.indexOf(u)!==-1||u.startsWith("_")))return o(new i('cannot use reserved word in metadata: "'+u+'"'));t=s.extend(!0,t,n.metadata)}var c=s.getUsersUrl(e)+"/"+encodeURIComponent(t._id),f=s.extend(!0,{method:"PUT",url:c,body:t},n.ajax||{});s.ajax(f,r(o))}function i(e){this.status=400,this.name="authentication_error",this.message=e,this.error=!0;try{Error.captureStackTrace(this,i)}catch(e){}}var s=e(1);n.signup=s.toPromise(function(e,t,n,r){var s=this;if("undefined"==typeof r&&(r="undefined"==typeof n?"undefined"==typeof t?e:t:n,n={}),["http","https"].indexOf(s.type())===-1)return r(new i('This plugin only works for the http/https adapter. So you should use new PouchDB("http://mysite.com:5984/mydb") instead.'));if(!e)return r(new i("You must provide a username"));if(!t)return r(new i("You must provide a password"));var a="org.couchdb.user:"+e,u={name:e,password:t,roles:n.roles||[],type:"user",_id:a};o(s,u,n,r)}),n.signUp=n.signup,n.login=s.toPromise(function(e,t,n,o){var a=this;if("undefined"==typeof o&&(o=n,n={}),["http","https"].indexOf(a.type())===-1)return o(new i("this plugin only works for the http/https adapter"));if(!e)return o(new i("you must provide a username"));if(!t)return o(new i("you must provide a password"));var u=s.extend(!0,{method:"POST",url:s.getSessionUrl(a),headers:{"Content-Type":"application/json"},body:JSON.stringify({name:e,password:t})},n.ajax||{});s.ajax(u,r(o))}),n.logIn=n.login,n.logout=s.toPromise(function(e,t){var n=this;"undefined"==typeof t&&(t=e,e={});var o=s.extend(!0,{method:"DELETE",url:s.getSessionUrl(n)},e.ajax||{});s.ajax(o,r(t))}),n.logOut=n.logout,n.getSession=s.toPromise(function(e,t){var n=this;"undefined"==typeof t&&(t=e,e={});var o=s.getSessionUrl(n),i=s.extend(!0,{method:"GET",url:o},e.ajax||{});s.ajax(i,r(t))}),n.getUser=s.toPromise(function(e,t,n){var o=this;if("undefined"==typeof n&&(n="undefined"==typeof t?e:t,t={}),!e)return n(new i("you must provide a username"));var a=s.getUsersUrl(o),u=s.extend(!0,{method:"GET",url:a+"/"+encodeURIComponent("org.couchdb.user:"+e)},t.ajax||{});s.ajax(u,r(n))}),n.putUser=s.toPromise(function(e,t,n){var r=this;return"undefined"==typeof n&&(n="undefined"==typeof t?e:t,t={}),["http","https"].indexOf(r.type())===-1?n(new i('This plugin only works for the http/https adapter. So you should use new PouchDB("http://mysite.com:5984/mydb") instead.')):e?r.getUser(e,t,function(e,i){return e?n(e):void o(r,i,t,n)}):n(new i("You must provide a username"))}),n.changePassword=s.toPromise(function(e,t,n,o){var a=this;return"undefined"==typeof o&&(o="undefined"==typeof n?"undefined"==typeof t?e:t:n,n={}),["http","https"].indexOf(a.type())===-1?o(new i('This plugin only works for the http/https adapter. So you should use new PouchDB("http://mysite.com:5984/mydb") instead.')):e?t?a.getUser(e,n,function(e,i){if(e)return o(e);i.password=t;var u=s.getUsersUrl(a)+"/"+encodeURIComponent(i._id),c=s.extend(!0,{method:"PUT",url:u,body:i},n.ajax||{});s.ajax(c,r(o))}):o(new i("You must provide a password")):o(new i("You must provide a username"))}),n.changeUsername=s.toPromise(function(e,t,n,o){var a=this,u="org.couchdb.user:",c=function(e){return new s.Promise(function(t,n){s.ajax(e,r(function(e,r){return e?n(e):void t(r)}))})},f=function(e,t){var n=s.getUsersUrl(a)+"/"+encodeURIComponent(e._id),r=s.extend(!0,{method:"PUT",url:n,body:e},t.ajax);return c(r)};return"undefined"==typeof o&&(o=n,n={}),n.ajax=n.ajax||{},["http","https"].indexOf(a.type())===-1?o(new i('This plugin only works for the http/https adapter. So you should use new PouchDB("http://mysite.com:5984/mydb") instead.')):t?e?a.getUser(t,n).then(function(){var e=new i("user already exists");throw e.taken=!0,e},function(){return a.getUser(e,n)}).then(function(e){var r=s.clone(e);return delete r._rev,r._id=u+t,r.name=t,r.roles=n.roles||e.roles||{},f(r,n).then(function(){return e._deleted=!0,f(e,n)})}).then(function(e){o(null,e)}).catch(o):o(new i("You must provide a username to rename")):o(new i("You must provide a new username"))}),s.inherits(i,Error),"undefined"!=typeof window&&window.PouchDB&&window.PouchDB.plugin(n)},{1:1}]},{},[17])(17)});