pouchdb-authentication
Advanced tools
Comparing version 0.5.5 to 1.0.0
@@ -1,2 +0,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"]); | ||
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)}); | ||
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).PouchAuthentication=e()}}(function(){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||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){"use strict";function r(e){return e&&"object"==typeof e&&"default"in e?e.default:e}function o(e){return"function"==typeof e.getUrl?p(e.getUrl()).origin:e.__opts&&e.__opts.prefix?e.__opts.prefix:p(e.name).origin}function i(e,t){return d(o(e),(t?"/_node/"+t:"")+"/_config")}function s(e){return d(o(e),"/_users")}function a(e){return d(o(e),"/_session")}function u(e){var t=p(e.name);if(!t.auth)return{};var n=t.username+":"+t.password;return{Authorization:"Basic "+v.btoa(unescape(encodeURIComponent(n)))}}function c(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 f(e){this.status=400,this.name="authentication_error",this.message=e,this.error=!0;try{Error.captureStackTrace(this,f)}catch(e){}}function l(e,t,n,r){var o=["_id","_rev","name","type","roles","password","password_scheme","iterations","derived_key","salt"];if(n.metadata){for(var i in n.metadata)if(n.metadata.hasOwnProperty(i)&&-1!==o.indexOf(i))return r(new f('cannot use reserved word in metadata: "'+i+'"'));t=m.assign(t,n.metadata)}n.roles&&(t=m.assign(t,{roles:n.roles}));var a=s(e)+"/"+encodeURIComponent(t._id),l=m.assign({method:"PUT",url:a,body:t,headers:u(e)},n.ajax||{});y(l,c(r))}var d=r(e(15)),p=r(e(16)),h=r(e(5)),v=e(9),y=r(e(7)),m=e(11),g=r(e(10));h(f,Error);var w=m.toPromise(function(e,t){void 0===t&&(t=e,e={});var n=o(this)+"/_membership",r=m.assign({method:"GET",url:n,headers:u(this)},e.ajax||{});y(r,c(t))}),b=m.toPromise(function(e,t,n,r){var o=this;return void 0===r&&(r=void 0===n?void 0===t?e:t:n,n={}),-1===["http","https"].indexOf(o.type())?r(new f('This plugin only works for the http/https adapter. So you should use new PouchDB("http://mysite.com:5984/mydb") instead.')):e?t?void o.getMembership(n,function(s,a){var f;if(s){if("illegal_database_name"!==s.error)return r(s);f=void 0}else f=a.all_nodes[0];var l=i(o,f),d=(n.configUrl||l)+"/admins/"+encodeURIComponent(e),p=m.assign({method:"PUT",url:d,processData:!1,headers:u(o),body:'"'+t+'"'},n.ajax||{});y(p,c(r))}):r(new f("You must provide a password")):r(new f("You must provide a username"))}),_=m.toPromise(function(e,t,n){var r=this;return void 0===n&&(n=void 0===t?e:t,t={}),-1===["http","https"].indexOf(r.type())?n(new f('This plugin only works for the http/https adapter. So you should use new PouchDB("http://mysite.com:5984/mydb") instead.')):e?void r.getMembership(t,function(o,s){var a;if(o){if("illegal_database_name"!==o.error)return n(o);a=void 0}else a=s.all_nodes[0];var f=i(r,a),l=(t.configUrl||f)+"/admins/"+encodeURIComponent(e),d=m.assign({method:"DELETE",url:l,processData:!1,headers:u(r)},t.ajax||{});y(d,c(n))}):n(new f("You must provide a username"))}),E=m.toPromise(function(e,t,n,r){if(void 0===r&&(r=n,n={}),-1===["http","https"].indexOf(this.type()))return r(new f("this plugin only works for the http/https adapter"));if(!e)return r(new f("you must provide a username"));if(!t)return r(new f("you must provide a password"));var o=m.assign({method:"POST",url:a(this),headers:m.assign({"Content-Type":"application/json"},u(this)),body:{name:e,password:t}},n.ajax||{});y(o,c(r))}),j=m.toPromise(function(e,t){void 0===t&&(t=e,e={});var n=m.assign({method:"DELETE",url:a(this),headers:u(this)},e.ajax||{});y(n,c(t))}),O=m.toPromise(function(e,t){void 0===t&&(t=e,e={});var n=a(this),r=m.assign({method:"GET",url:n,headers:u(this)},e.ajax||{});y(r,c(t))}),S=m.toPromise(function(e,t,n,r){if(void 0===r&&(r=void 0===n?void 0===t?e:t:n,n={}),-1===["http","https"].indexOf(this.type()))return r(new f('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 f("You must provide a username"));if(!t)return r(new f("You must provide a password"));l(this,{name:e,password:t,roles:[],type:"user",_id:"org.couchdb.user:"+e},n,r)}),x=m.toPromise(function(e,t,n){if(void 0===n&&(n=void 0===t?e:t,t={}),!e)return n(new f("you must provide a username"));var r=s(this),o=m.assign({method:"GET",url:r+"/"+encodeURIComponent("org.couchdb.user:"+e),headers:u(this)},t.ajax||{});y(o,c(n))}),A=m.toPromise(function(e,t,n){var r=this;return void 0===n&&(n=void 0===t?e:t,t={}),-1===["http","https"].indexOf(r.type())?n(new f('This plugin only works for the http/https adapter. So you should use new PouchDB("http://mysite.com:5984/mydb") instead.')):e?void r.getUser(e,t,function(e,o){if(e)return n(e);l(r,o,t,n)}):n(new f("You must provide a username"))}),T=m.toPromise(function(e,t,n){var r=this;return void 0===n&&(n=void 0===t?e:t,t={}),-1===["http","https"].indexOf(r.type())?n(new f('This plugin only works for the http/https adapter. So you should use new PouchDB("http://mysite.com:5984/mydb") instead.')):e?void r.getUser(e,t,function(e,o){if(e)return n(e);var i=s(r)+"/"+encodeURIComponent(o._id)+"?rev="+o._rev,a=m.assign({method:"DELETE",url:i,headers:u(r)},t.ajax||{});y(a,c(n))}):n(new f("You must provide a username"))}),C=m.toPromise(function(e,t,n,r){var o=this;return void 0===r&&(r=void 0===n?void 0===t?e:t:n,n={}),-1===["http","https"].indexOf(o.type())?r(new f('This plugin only works for the http/https adapter. So you should use new PouchDB("http://mysite.com:5984/mydb") instead.')):e?t?void o.getUser(e,n,function(e,i){if(e)return r(e);i.password=t;var a=s(o)+"/"+encodeURIComponent(i._id),f=m.assign({method:"PUT",url:a,headers:u(o),body:i},n.ajax||{});y(f,c(r))}):r(new f("You must provide a password")):r(new f("You must provide a username"))}),R=m.toPromise(function(e,t,n,r){var o=this,i=function(e,t){var n=s(o)+"/"+encodeURIComponent(e._id);return function(e){return new g(function(t,n){y(e,c(function(e,r){if(e)return n(e);t(r)}))})}(m.assign({method:"PUT",url:n,headers:u(o),body:e},t.ajax))};return void 0===r&&(r=n,n={}),n.ajax=n.ajax||{},-1===["http","https"].indexOf(o.type())?r(new f('This plugin only works for the http/https adapter. So you should use new PouchDB("http://mysite.com:5984/mydb") instead.')):t?e?void o.getUser(t,n).then(function(){var e=new f("user already exists");throw e.taken=!0,e},function(){return o.getUser(e,n)}).then(function(e){var r=m.clone(e);return delete r._rev,r._id="org.couchdb.user:"+t,r.name=t,r.roles=n.roles||e.roles||{},i(r,n).then(function(){return e._deleted=!0,i(e,n)})}).then(function(e){r(null,e)}).catch(r):r(new f("You must provide a username to rename")):r(new f("You must provide a new username"))}),B={};B.login=E,B.logIn=E,B.logout=j,B.logOut=j,B.getSession=O,B.getMembership=w,B.signUpAdmin=b,B.deleteAdmin=_,B.getUsersDatabaseUrl=function(){return s(this)},B.signup=S,B.signUp=S,B.getUser=x,B.putUser=A,B.deleteUser=T,B.changePassword=C,B.changeUsername=R,"undefined"!=typeof window&&window.PouchDB&&window.PouchDB.plugin(B),t.exports=B},{10:10,11:11,15:15,16:16,5:5,7:7,9:9}],2:[function(e,t,n){"use strict";t.exports=function(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,[])}}},{}],3:[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"object"==typeof e&&null!==e}function s(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(!function(e){return"number"==typeof e}(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,a,u,c;if(this._events||(this._events={}),"error"===e&&(!this._events.error||i(this._events.error)&&!this._events.error.length)){if((t=arguments[1])instanceof Error)throw t;var f=new Error('Uncaught, unspecified "error" event. ('+t+")");throw f.context=t,f}if(n=this._events[e],s(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:a=Array.prototype.slice.call(arguments,1),n.apply(this,a)}else if(i(n))for(a=Array.prototype.slice.call(arguments,1),r=(c=n.slice()).length,u=0;u<r;u++)c[u].apply(this,a);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]?i(this._events[e])?this._events[e].push(t):this._events[e]=[this._events[e],t]:this._events[e]=t,i(this._events[e])&&!this._events[e].warned&&(n=s(this._maxListeners)?r.defaultMaxListeners:this._maxListeners)&&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,s,a;if(!o(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(n=this._events[e],s=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(i(n)){for(a=s;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){return 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)}},{}],4:[function(e,t,n){(function(e){"use strict";function n(){c=!0;for(var e,t,n=f.length;n;){for(t=f,f=[],e=-1;++e<n;)t[e]();n=f.length}c=!1}var r,o=e.MutationObserver||e.WebKitMutationObserver;if(o){var i=0,s=new o(n),a=e.document.createTextNode("");s.observe(a,{characterData:!0}),r=function(){a.data=i=++i%2}}else if(e.setImmediate||void 0===e.MessageChannel)r="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 u=new e.MessageChannel;u.port1.onmessage=n,r=function(){u.port2.postMessage(0)}}var c,f=[];t.exports=function(e){1!==f.push(e)||c||r()}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],5:[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}},{}],6:[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=h,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){f(function(){var r;try{r=t(n)}catch(t){return l.reject(e,t)}r===e?l.reject(e,new TypeError("Cannot resolve promise with itself")):l.resolve(e,r)})}function a(e){var t=e&&e.then;if(e&&("object"==typeof e||"function"==typeof e)&&"function"==typeof t)return function(){t.apply(e,arguments)}}function u(e,t){function n(t){o||(o=!0,l.reject(e,t))}function r(t){o||(o=!0,l.resolve(e,t))}var o=!1,i=c(function(){t(r,n)});"error"===i.status&&n(i.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}var f=e(4),l={},d=["REJECTED"],p=["FULFILLED"],h=["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===p||"function"!=typeof t&&this.state===d)return this;var n=new this.constructor(r);if(this.state!==h){s(n,this.state===p?e:t,this.outcome)}else this.queue.push(new i(n,e,t));return n},i.prototype.callFulfilled=function(e){l.resolve(this.promise,e)},i.prototype.otherCallFulfilled=function(e){s(this.promise,this.onFulfilled,e)},i.prototype.callRejected=function(e){l.reject(this.promise,e)},i.prototype.otherCallRejected=function(e){s(this.promise,this.onRejected,e)},l.resolve=function(e,t){var n=c(a,t);if("error"===n.status)return l.reject(e,n.value);var r=n.value;if(r)u(e,r);else{e.state=p,e.outcome=t;for(var o=-1,i=e.queue.length;++o<i;)e.queue[o].callFulfilled(t)}return e},l.reject=function(e,t){e.state=d,e.outcome=t;for(var n=-1,r=e.queue.length;++n<r;)e.queue[n].callRejected(t);return e},o.resolve=function(e){return e instanceof this?e:l.resolve(new this(r),e)},o.reject=function(e){var t=new this(r);return l.reject(t,e)},o.all=function(e){var t=this;if("[object Array]"!==Object.prototype.toString.call(e))return this.reject(new TypeError("must be an array"));var n=e.length,o=!1;if(!n)return this.resolve([]);for(var i=new Array(n),s=0,a=-1,u=new this(r);++a<n;)!function(e,r){t.resolve(e).then(function(e){i[r]=e,++s!==n||o||(o=!0,l.resolve(u,i))},function(e){o||(o=!0,l.reject(u,e))})}(e[a],a);return u},o.race=function(e){var t=this;if("[object Array]"!==Object.prototype.toString.call(e))return this.reject(new TypeError("must be an array"));var n=e.length,o=!1;if(!n)return this.resolve([]);for(var i=-1,s=new this(r);++i<n;)!function(e){t.resolve(e).then(function(e){o||(o=!0,l.resolve(s,e))},function(e){o||(o=!0,l.reject(s,e))})}(e[i]);return s}},{4:4}],7:[function(e,t,n){"use strict";function r(e,t){var n,r,o,i=new Headers,s={method:e.method,credentials:"include",headers:i};return e.json&&(i.set("Accept","application/json"),i.set("Content-Type",e.headers["Content-Type"]||"application/json")),e.body&&e.processData&&"string"!=typeof e.body?s.body=JSON.stringify(e.body):s.body="body"in e?e.body:null,Object.keys(e.headers).forEach(function(t){e.headers.hasOwnProperty(t)&&i.set(t,e.headers[t])}),n=function(){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}(e.url,s),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):(e.status=o.statusCode,t(e))}).catch(function(e){e||(e=new Error("canceled")),t(e)}),{abort:n.reject}}function o(e,t){return f||e.xhr?function(e,t){var n,r,o=!1,i=function(){o=!0,n.abort(),a()},s={abort:function(){n.abort(),a()}},a=function(){clearTimeout(r),s.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 c in e.headers)e.headers.hasOwnProperty(c)&&n.setRequestHeader(c,e.headers[c]);return e.timeout>0&&(r=setTimeout(i,e.timeout),n.onprogress=function(){clearTimeout(r),4!==n.readyState&&(r=setTimeout(i,e.timeout))},void 0!==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?u.blob([n.response||""],{type:n.getResponseHeader("Content-Type")}):n.responseText,t(null,r,i)}else{var s={};if(o)(s=new Error("ETIMEDOUT")).code="ETIMEDOUT";else if("string"==typeof n.response)try{s=JSON.parse(n.response)}catch(e){}s.status=n.status,t(s)}a()}},e.body&&e.body instanceof Blob?u.readAsArrayBuffer(e.body,function(e){n.send(e)}):n.send(e.body),s}(e,t):r(e,t)}function i(e,t){e=s.clone(e);return(e=s.assign({method:"GET",headers:{},json:!0,processData:!0,timeout:1e4,cache:!1},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),o(e,function(n,r,o){if(n)return t(c.generateErrorFromResponse(n));var i,s=r.headers&&r.headers["content-type"],a=o||"";if(!e.binary&&(e.json||!e.processData)&&"object"!=typeof a&&(/json/.test(s)||/^[\s]*\{/.test(a)&&/\}[\s]*$/.test(a)))try{a=JSON.parse(a.toString())}catch(e){}r.statusCode>=200&&r.statusCode<300?function(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?c.generateErrorFromResponse(e):e})),e.binary,r(null,t,n)}(a,r,t):((i=c.generateErrorFromResponse(a)).status=r.statusCode,t(i))})}var s=e(11),a=function(e){return e&&"object"==typeof e&&"default"in e?e.default:e}(e(10)),u=e(9),c=e(8),f=function(){try{return new XMLHttpRequest,!0}catch(e){return!1}}();t.exports=function(e,t){var n=navigator&&navigator.userAgent?navigator.userAgent.toLowerCase():"",r=-1!==n.indexOf("safari")&&-1===n.indexOf("chrome"),o=-1!==n.indexOf("msie"),s=-1!==n.indexOf("trident"),a=-1!==n.indexOf("edge"),u=r||(o||s||a)&&"GET"===e.method,c=!("cache"in e)||e.cache;if(!/^blob:/.test(e.url)&&(u||!c)){var f=-1!==e.url.indexOf("?");e.url+=(f?"&":"?")+"_nonce="+Date.now()}return i(e,t)}},{10:10,11:11,8:8,9:9}],8:[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}Object.defineProperty(n,"__esModule",{value:!0});(function(e){return e&&"object"==typeof e&&"default"in e?e.default:e})(e(5))(r,Error),r.prototype.toString=function(){return JSON.stringify({status:this.status,name:this.name,message:this.message,reason:this.reason})};var o=new r(401,"unauthorized","Name or password is incorrect."),i=new r(400,"bad_request","Missing JSON list of 'docs'"),s=new r(404,"not_found","missing"),a=new r(409,"conflict","Document update conflict"),u=new r(400,"bad_request","_id field must contain a string"),c=new r(412,"missing_id","_id is required for puts"),f=new r(400,"bad_request","Only reserved document ids may start with underscore."),l=new r(412,"precondition_failed","Database not open"),d=new r(500,"unknown_error","Database encountered an unknown error"),p=new r(500,"badarg","Some query argument is invalid"),h=new r(400,"invalid_request","Request was invalid"),v=new r(400,"query_parse_error","Some query parameter is invalid"),y=new r(500,"doc_validation","Bad special document member"),m=new r(400,"bad_request","Something wrong with the request"),g=new r(400,"bad_request","Document must be a JSON object"),w=new r(404,"not_found","Database not found"),b=new r(500,"indexed_db_went_bad","unknown"),_=new r(500,"web_sql_went_bad","unknown"),E=new r(500,"levelDB_went_went_bad","unknown"),j=new r(403,"forbidden","Forbidden by design doc validate_doc_update function"),O=new r(400,"bad_request","Invalid rev format"),S=new r(412,"file_exists","The database could not be created, the file already exists."),x=new r(412,"missing_stub","A pre-existing attachment stub wasn't found"),A=new r(413,"invalid_url","Provided URL is invalid");n.UNAUTHORIZED=o,n.MISSING_BULK_DOCS=i,n.MISSING_DOC=s,n.REV_CONFLICT=a,n.INVALID_ID=u,n.MISSING_ID=c,n.RESERVED_ID=f,n.NOT_OPEN=l,n.UNKNOWN_ERROR=d,n.BAD_ARG=p,n.INVALID_REQUEST=h,n.QUERY_PARSE_ERROR=v,n.DOC_VALIDATION=y,n.BAD_REQUEST=m,n.NOT_AN_OBJECT=g,n.DB_MISSING=w,n.WSQ_ERROR=_,n.LDB_ERROR=E,n.FORBIDDEN=j,n.INVALID_REV=O,n.FILE_EXISTS=S,n.MISSING_STUB=x,n.IDB_ERROR=b,n.INVALID_URL=A,n.createError=function(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)},n.generateErrorFromResponse=function(e){if("object"!=typeof e){var t=e;(e=d).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}},{5:5}],9:[function(e,t,n){"use strict";function r(e,t){e=e||[],t=t||{};try{return new Blob(e,t)}catch(o){if("TypeError"!==o.name)throw o;for(var n=new("undefined"!=typeof BlobBuilder?BlobBuilder:"undefined"!=typeof MSBlobBuilder?MSBlobBuilder:"undefined"!=typeof MozBlobBuilder?MozBlobBuilder:WebKitBlobBuilder),r=0;r<e.length;r+=1)n.append(e[r]);return n.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 s(e){for(var t="",n=new Uint8Array(e),r=n.byteLength,o=0;o<r;o++)t+=String.fromCharCode(n[o]);return t}function a(e,t){if("undefined"==typeof FileReader)return t(s((new FileReaderSync).readAsArrayBuffer(e)));var n=new FileReader,r="function"==typeof n.readAsBinaryString;n.onloadend=function(e){var n=e.target.result||"";if(r)return t(n);t(s(n))},r?n.readAsBinaryString(e):n.readAsArrayBuffer(e)}function u(e,t){a(e,function(e){t(e)})}Object.defineProperty(n,"__esModule",{value:!0});var c=function(e){return atob(e)},f=function(e){return btoa(e)};n.atob=c,n.btoa=f,n.base64StringToBlobOrBuffer=function(e,t){return i(c(e),t)},n.binaryStringToArrayBuffer=o,n.binaryStringToBlobOrBuffer=i,n.blob=r,n.blobOrBufferToBase64=function(e,t){u(e,function(e){t(f(e))})},n.blobOrBufferToBinaryString=u,n.readAsArrayBuffer=function(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)},n.readAsBinaryString=a,n.typedBuffer=function(){}},{}],10:[function(e,t,n){"use strict";var r=function(e){return e&&"object"==typeof e&&"default"in e?e.default:e}(e(6)),o="function"==typeof Promise?Promise:r;t.exports=o},{6:6}],11:[function(e,t,n){"use strict";function r(e){return e&&"object"==typeof e&&"default"in e?e.default:e}function o(e){if(e instanceof ArrayBuffer)return function(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}(e);var t=e.size,n=e.type;return"function"==typeof e.slice?e.slice(0,t,n):e.webkitSlice(0,t,n)}function i(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]=i(e[n]);return t}if(e instanceof Date)return e.toISOString();if(function(e){return"undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer||"undefined"!=typeof Blob&&e instanceof Blob}(e))return o(e);if(!function(e){var t=Object.getPrototypeOf(e);if(null===t)return!0;var n=t.constructor;return"function"==typeof n&&n instanceof n&&C.call(n)==R}(e))return e;t={};for(n in e)if(Object.prototype.hasOwnProperty.call(e,n)){var s=i(e[n]);void 0!==s&&(t[n]=s)}return t}function s(e){var t=!1;return j(function(n){if(t)throw new Error("once called more than once");t=!0,e.apply(this,n)})}function a(e){return j(function(t){var n=this,r="function"==typeof(t=i(t))[t.length-1]&&t.pop(),o=new E(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))&&"function"==typeof i.then&&r(i)}catch(e){o(e)}});return r&&o.then(function(e){r(null,e)},r),o})}function u(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 c(e){return e}function f(e){return[{ok:e}]}function l(e,t,n){function r(){++l===a&&function(){var e=[];d.forEach(function(t){t.docs.forEach(function(n){e.push({id:t.id,docs:[n]})})}),n(null,{results:e})}()}function o(){if(!(h>=p.length)){var n=Math.min(h+B,p.length),i=p.slice(h,n);!function(n,i){n.forEach(function(n,a){var l=i+a,p=s.get(n),h=u(p[0],["atts_since","attachments"]);h.open_revs=p.map(function(e){return e.rev}),h.open_revs=h.open_revs.filter(c);var v=c;0===h.open_revs.length&&(delete h.open_revs,v=f),["revs","attachments","binary","ajax","latest"].forEach(function(e){e in t&&(h[e]=t[e])}),e.get(n,h,function(e,t){var i;i=e?[{error:e}]:v(t),function(e,t,n){d[e]={id:t,docs:n},r()}(l,n,i),o()})})}(i,h),h+=i.length}}var i=t.docs,s=new O.Map;i.forEach(function(e){s.has(e.id)?s.get(e.id).push(e):s.set(e.id,[e])});var a=s.size,l=0,d=new Array(a),p=[];s.forEach(function(e,t){p.push(t)});var h=0;o()}function d(){return"undefined"!=typeof chrome&&void 0!==chrome.storage&&void 0!==chrome.storage.local}function p(){return b}function h(){S.EventEmitter.call(this),this._listeners={},function(e){d()?chrome.storage.onChanged.addListener(function(t){null!=t.db_name&&e.emit(t.dbName.newValue)}):p()&&("undefined"!=typeof addEventListener?addEventListener("storage",function(t){e.emit(t.key)}):window.attachEvent("storage",function(t){e.emit(t.key)}))}(this)}function v(e){if("undefined"!=typeof console&&"function"==typeof console[e]){var t=Array.prototype.slice.call(arguments,1);console[e].apply(console,t)}}function y(e){var t=0;return e||(t=2e3),function(e,t){return e=parseInt(e,10)||0,(t=parseInt(t,10))!=t||t<=e?t=(e||1)<<1:t+=1,t>6e5&&(e=3e5,t=6e5),~~((t-e)*Math.random()+e)}(e,t)}function m(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&&function(e,t,n){try{return!e(t,n)}catch(e){var r="Filter function threw: "+e.toString();return T.createError(T.BAD_REQUEST,r)}}(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 g(e){if(!e)return null;var t=e.split("/");return 2===t.length?t:1===t.length?[e,e]:null}function w(e,t,n){return new E(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);if(!u)return r({updated:!1,rev:a});u._id=t,u._rev=a,r(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 w(e,t._id,n)})}(e,u,n))})})}Object.defineProperty(n,"__esModule",{value:!0});var b,_=r(e(18)),E=r(e(10)),j=r(e(2)),O=e(12),S=e(3),x=r(e(5)),A=r(e(4)),T=e(13),C=Function.prototype.toString,R=C.call(Object),B=6;if(d())b=!1;else try{localStorage.setItem("_pouch_check_localstorage",1),b=!!localStorage.getItem("_pouch_check_localstorage")}catch(e){b=!1}x(h,S.EventEmitter),h.prototype.addListener=function(e,t,n,r){function o(){if(i._listeners[t])if(s)s="waiting";else{s=!0;var e=u(r,["style","include_docs","attachments","conflicts","filter","doc_ids","view","since","query_params","binary"]);n.changes(e).on("change",function(e){e.seq>r.since&&!r.cancelled&&(r.since=e.seq,r.onChange(e))}).on("complete",function(){"waiting"===s&&A(o),s=!1}).on("error",function(){s=!1})}}if(!this._listeners[t]){var i=this,s=!1;this._listeners[t]=o,this.on(e,o)}},h.prototype.removeListener=function(e,t){t in this._listeners&&(S.EventEmitter.prototype.removeListener.call(this,e,this._listeners[t]),delete this._listeners[t])},h.prototype.notifyLocalWindows=function(e){d()?chrome.storage.local.set({dbName:e}):p()&&(localStorage[e]="a"===localStorage[e]?"b":"a")},h.prototype.notify=function(e){this.emit(e),this.notifyLocalWindows(e)};var D,L,I=D="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},U=L=function(){}.name?function(e){return e.name}:function(e){return e.toString().match(/^\s*function\s*(\S*)\s*\(/)[1]},P=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],k="queryKey",q=/(?:^|&)([^&=]*)=?([^&]*)/g,N=/^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,M=_.v4;n.adapterFun=function(e,t){return a(j(function(n){if(this._closed)return E.reject(new Error("database is closed"));if(this._destroyed)return E.reject(new Error("database is destroyed"));var r=this;return function(e,t,n){if(e.constructor.listeners("debug").length){for(var r=["api",e.name,t],o=0;o<n.length-1;o++)r.push(n[o]);e.constructor.emit("debug",r);var i=n[n.length-1];n[n.length-1]=function(n,r){var o=["api",e.name,t];o=o.concat(n?["error",n]:["success",r]),e.constructor.emit("debug",o),i(n,r)}}}(r,e,n),this.taskqueue.isReady?t.apply(this,n):new E(function(t,o){r.taskqueue.addTask(function(i){i?o(i):t(r[e].apply(r,n))})})}))},n.assign=I,n.bulkGetShim=l,n.changesHandler=h,n.clone=i,n.defaultBackOff=y,n.explainError=function(e,t){v("info","The above "+e+" is totally normal. "+t)},n.filterChange=m,n.flatten=function(e){for(var t=[],n=0,r=e.length;n<r;n++)t=t.concat(e[n]);return t},n.functionName=U,n.guardedConsole=v,n.hasLocalStorage=p,n.invalidIdError=function(e){var t;if(e?"string"!=typeof e?t=T.createError(T.INVALID_ID):/^_/.test(e)&&!/^_(design|local)/.test(e)&&(t=T.createError(T.RESERVED_ID)):t=T.createError(T.MISSING_ID),t)throw t},n.isChromeApp=d,n.isCordova=function(){return"undefined"!=typeof cordova||"undefined"!=typeof PhoneGap||"undefined"!=typeof phonegap},n.isRemote=function(e){return"boolean"==typeof e._remote?e._remote:"function"==typeof e.type&&(v("warn","db.type() is deprecated and will be removed in a future version of PouchDB"),"http"===e.type())},n.listenerCount=function(e,t){return"listenerCount"in e?e.listenerCount(t):S.EventEmitter.listenerCount(e,t)},n.nextTick=A,n.normalizeDdocFunctionName=function(e){var t=g(e);return t?t.join("/"):null},n.once=s,n.parseDdocFunctionName=g,n.parseUri=function(e){for(var t=N.exec(e),n={},r=14;r--;){var o=P[r],i=t[r]||"",s=-1!==["user","password"].indexOf(o);n[o]=s?decodeURIComponent(i):i}return n[k]={},n[P[12]].replace(q,function(e,t,r){t&&(n[k][t]=r)}),n},n.pick=u,n.rev=function(){return _.v4().replace(/-/g,"").toLowerCase()},n.scopeEval=function(e,t){var n=[],r=[];for(var o in t)t.hasOwnProperty(o)&&(n.push(o),r.push(t[o]));return n.push(e),Function.apply(null,n).apply(null,r)},n.toPromise=a,n.upsert=w,n.uuid=M},{10:10,12:12,13:13,18:18,2:2,3:3,4:4,5:5}],12:[function(e,t,n){"use strict";function r(e){return"$"+e}function o(e){return e.substring(1)}function i(){this._store={}}function s(e){if(this._store=new i,e&&Array.isArray(e))for(var t=0,n=e.length;t<n;t++)this.add(e[t])}Object.defineProperty(n,"__esModule",{value:!0}),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];e(this._store[i],i=o(i))}},Object.defineProperty(i.prototype,"size",{get:function(){return Object.keys(this._store).length}}),s.prototype.add=function(e){return this._store.set(e,!0)},s.prototype.has=function(e){return this._store.has(e)},s.prototype.forEach=function(e){this._store.forEach(function(t,n){e(n)})},Object.defineProperty(s.prototype,"size",{get:function(){return this._store.size}}),!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}()?(n.Set=s,n.Map=i):(n.Set=Set,n.Map=Map)},{}],13:[function(e,t,n){arguments[4][8][0].apply(n,arguments)},{5:5,8:8}],14:[function(e,t,n){"use strict";function r(e){return decodeURIComponent(e.replace(/\+/g," "))}var o=Object.prototype.hasOwnProperty;n.stringify=function(e,t){var n=[];"string"!=typeof(t=t||"")&&(t="?");for(var r in e)o.call(e,r)&&n.push(encodeURIComponent(r)+"="+encodeURIComponent(e[r]));return n.length?t+n.join("&"):""},n.parse=function(e){for(var t,n=/([^=?&]+)=?([^&]*)/g,o={};t=n.exec(e);o[r(t[1])]=r(t[2]));return o}},{}],15:[function(e,t,n){!function(e,n,r){void 0!==t&&t.exports?t.exports=r():n.urljoin=r()}(0,this,function(){return function(){var e=arguments;"object"==typeof arguments[0]&&(e=arguments[0],arguments[1]);return function(e,t){return e=function(e,t){return e.substr(0,t.length)===t}(e,"file://")?e.replace(/(\/{0,3})\/*/g,"$1"):(e=e.replace(/:\//g,"://")).replace(/([^:\s\%\3\A])\/+/g,"$1/"),e=e.replace(/\/(\?|&|#[^!])/g,"$1"),e=e.replace(/(\?.+)\?/g,"$1&")}([].slice.call(e,0).join("/"))}})},{}],16:[function(e,t,n){(function(n){"use strict";function r(e){var t,r={},o=typeof(e=e||n.location||{});if("blob:"===e.protocol)r=new i(unescape(e.pathname),{});else if("string"===o){r=new i(e,{});for(t in l)delete r[t]}else if("object"===o){for(t in e)t in l||(r[t]=e[t]);void 0===r.slashes&&(r.slashes=c.test(e.href))}return r}function o(e){var t=u.exec(e);return{protocol:t[1]?t[1].toLowerCase():"",slashes:!!t[2],rest:t[3]}}function i(e,t,n){if(!(this instanceof i))return new i(e,t,n);var u,c,l,d,p,h,v=f.slice(),y=typeof t,m=this,g=0;for("object"!==y&&"string"!==y&&(n=t,t=null),n&&"function"!=typeof n&&(n=a.parse),t=r(t),u=!(c=o(e||"")).protocol&&!c.slashes,m.slashes=c.slashes||u&&t.slashes,m.protocol=c.protocol||t.protocol||"",e=c.rest,c.slashes||(v[2]=[/(.*)/,"pathname"]);g<v.length;g++)l=(d=v[g])[0],h=d[1],l!=l?m[h]=e:"string"==typeof l?~(p=e.indexOf(l))&&("number"==typeof d[2]?(m[h]=e.slice(0,p),e=e.slice(p+d[2])):(m[h]=e.slice(p),e=e.slice(0,p))):(p=l.exec(e))&&(m[h]=p[1],e=e.slice(0,p.index)),m[h]=m[h]||(u&&d[3]?t[h]||"":""),d[4]&&(m[h]=m[h].toLowerCase());n&&(m.query=n(m.query)),u&&t.slashes&&"/"!==m.pathname.charAt(0)&&(""!==m.pathname||""!==t.pathname)&&(m.pathname=function(e,t){for(var n=(t||"/").split("/").slice(0,-1).concat(e.split("/")),r=n.length,o=n[r-1],i=!1,s=0;r--;)"."===n[r]?n.splice(r,1):".."===n[r]?(n.splice(r,1),s++):s&&(0===r&&(i=!0),n.splice(r,1),s--);return i&&n.unshift(""),"."!==o&&".."!==o||n.push(""),n.join("/")}(m.pathname,t.pathname)),s(m.port,m.protocol)||(m.host=m.hostname,m.port=""),m.username=m.password="",m.auth&&(d=m.auth.split(":"),m.username=d[0]||"",m.password=d[1]||""),m.origin=m.protocol&&m.host&&"file:"!==m.protocol?m.protocol+"//"+m.host:"null",m.href=m.toString()}var s=e(17),a=e(14),u=/^([a-z][a-z0-9.+-]*:)?(\/\/)?([\S\s]*)/i,c=/^[A-Za-z][A-Za-z0-9+-.]*:\/\//,f=[["#","hash"],["?","query"],["/","pathname"],["@","auth",1],[NaN,"host",void 0,1,1],[/:(\d+)$/,"port",void 0,1],[NaN,"hostname",void 0,1,1]],l={hash:1,query:1};i.prototype={set:function(e,t,n){var r=this;switch(e){case"query":"string"==typeof t&&t.length&&(t=(n||a.parse)(t)),r[e]=t;break;case"port":r[e]=t,s(t,r.protocol)?t&&(r.host=r.hostname+":"+t):(r.host=r.hostname,r[e]="");break;case"hostname":r[e]=t,r.port&&(t+=":"+r.port),r.host=t;break;case"host":r[e]=t,/:\d+$/.test(t)?(t=t.split(":"),r.port=t.pop(),r.hostname=t.join(":")):(r.hostname=t,r.port="");break;case"protocol":r.protocol=t.toLowerCase(),r.slashes=!n;break;case"pathname":case"hash":if(t){var o="pathname"===e?"/":"#";r[e]=t.charAt(0)!==o?o+t:t}else r[e]=t;break;default:r[e]=t}for(var i=0;i<f.length;i++){var u=f[i];u[4]&&(r[u[1]]=r[u[1]].toLowerCase())}return r.origin=r.protocol&&r.host&&"file:"!==r.protocol?r.protocol+"//"+r.host:"null",r.href=r.toString(),r},toString:function(e){e&&"function"==typeof e||(e=a.stringify);var t,n=this,r=n.protocol;r&&":"!==r.charAt(r.length-1)&&(r+=":");var o=r+(n.slashes?"//":"");return n.username&&(o+=n.username,n.password&&(o+=":"+n.password),o+="@"),o+=n.host+n.pathname,(t="object"==typeof n.query?e(n.query):n.query)&&(o+="?"!==t.charAt(0)?"?"+t:t),n.hash&&(o+=n.hash),o}},i.extractProtocol=o,i.location=r,i.qs=a,t.exports=i}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{14:14,17:17}],17:[function(e,t,n){"use strict";t.exports=function(e,t){if(t=t.split(":")[0],!(e=+e))return!1;switch(t){case"http":case"ws":return 80!==e;case"https":case"wss":return 443!==e;case"ftp":return 21!==e;case"gopher":return 70!==e;case"file":return!1}return 0!==e}},{}],18:[function(e,t,n){var r=e(21),o=e(22),i=o;i.v1=r,i.v4=o,t.exports=i},{21:21,22:22}],19:[function(e,t,n){for(var r=[],o=0;o<256;++o)r[o]=(o+256).toString(16).substr(1);t.exports=function(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++]]}},{}],20:[function(e,t,n){(function(e){var n,r=e.crypto||e.msCrypto;if(r&&r.getRandomValues){var o=new Uint8Array(16);n=function(){return r.getRandomValues(o),o}}if(!n){var i=new Array(16);n=function(){for(var e,t=0;t<16;t++)0==(3&t)&&(e=4294967296*Math.random()),i[t]=e>>>((3&t)<<3)&255;return i}}t.exports=n}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],21:[function(e,t,n){var r=e(20),o=e(19),i=r(),s=[1|i[0],i[1],i[2],i[3],i[4],i[5]],a=16383&(i[6]<<8|i[7]),u=0,c=0;t.exports=function(e,t,n){var r=t&&n||0,i=t||[],f=void 0!==(e=e||{}).clockseq?e.clockseq:a,l=void 0!==e.msecs?e.msecs:(new Date).getTime(),d=void 0!==e.nsecs?e.nsecs:c+1,p=l-u+(d-c)/1e4;if(p<0&&void 0===e.clockseq&&(f=f+1&16383),(p<0||l>u)&&void 0===e.nsecs&&(d=0),d>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");u=l,c=d,a=f;var h=(1e4*(268435455&(l+=122192928e5))+d)%4294967296;i[r++]=h>>>24&255,i[r++]=h>>>16&255,i[r++]=h>>>8&255,i[r++]=255&h;var v=l/4294967296*1e4&268435455;i[r++]=v>>>8&255,i[r++]=255&v,i[r++]=v>>>24&15|16,i[r++]=v>>>16&255,i[r++]=f>>>8|128,i[r++]=255&f;for(var y=e.node||s,m=0;m<6;++m)i[r+m]=y[m];return t||o(i)}},{19:19,20:20}],22:[function(e,t,n){var r=e(20),o=e(19);t.exports=function(e,t,n){var i=t&&n||0;"string"==typeof e&&(t="binary"==e?new Array(16):null,e=null);var s=(e=e||{}).random||(e.rng||r)();if(s[6]=15&s[6]|64,s[8]=63&s[8]|128,t)for(var a=0;a<16;++a)t[i+a]=s[a];return t||o(s)}},{19:19,20:20}]},{},[1])(1)}); |
389
lib/index.js
'use strict'; | ||
var utils = require('./utils'); | ||
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
var urlJoin = _interopDefault(require('url-join')); | ||
var urlParse = _interopDefault(require('url-parse')); | ||
var inherits = _interopDefault(require('inherits')); | ||
var pouchdbBinaryUtils = require('pouchdb-binary-utils'); | ||
var ajaxCore = _interopDefault(require('pouchdb-ajax')); | ||
var pouchdbUtils = require('pouchdb-utils'); | ||
var Promise = _interopDefault(require('pouchdb-promise')); | ||
function getBaseUrl(db) { | ||
if (typeof db.getUrl === 'function') { // pouchdb pre-6.0.0 | ||
return urlParse(db.getUrl()).origin; | ||
} else if (db.__opts && db.__opts.prefix) { // PouchDB.defaults | ||
return db.__opts.prefix; | ||
} else { // pouchdb post-6.0.0 | ||
return urlParse(db.name).origin; | ||
} | ||
} | ||
function getConfigUrl(db, nodeName) { | ||
return urlJoin(getBaseUrl(db), (nodeName ? '/_node/' + nodeName : '') + '/_config'); | ||
} | ||
function getUsersUrl(db) { | ||
return urlJoin(getBaseUrl(db), '/_users'); | ||
} | ||
function getSessionUrl(db) { | ||
return urlJoin(getBaseUrl(db), '/_session'); | ||
} | ||
function getBasicAuthHeaders(db) { | ||
var url = urlParse(db.name); | ||
if (!url.auth) { | ||
return {}; | ||
} | ||
var str = url.username + ':' + url.password; | ||
var token = pouchdbBinaryUtils.btoa(unescape(encodeURIComponent(str))); | ||
return {Authorization: 'Basic ' + token}; | ||
} | ||
function wrapError(callback) { | ||
@@ -11,3 +52,3 @@ // provide more helpful error message | ||
err.message = (err.message || '') + | ||
' Unknown error! Did you remember to enable CORS?'; | ||
' Unknown error! Did you remember to enable CORS?'; | ||
} | ||
@@ -19,25 +60,31 @@ } | ||
function putUser(db, user, opts, callback) { | ||
var reservedWords = ['name', 'password', 'roles', 'type', 'salt', 'metadata']; | ||
if (opts.metadata) { | ||
for (var key in opts.metadata) { | ||
if (opts.hasOwnProperty(key)) { | ||
if (reservedWords.indexOf(key) !== -1 || key.startsWith('_')) { | ||
return callback(new AuthError('cannot use reserved word in metadata: "' + key + '"')); | ||
} | ||
} | ||
} | ||
user = utils.extend(true, user, opts.metadata); | ||
function AuthError(message) { | ||
this.status = 400; | ||
this.name = 'authentication_error'; | ||
this.message = message; | ||
this.error = true; | ||
try { | ||
Error.captureStackTrace(this, AuthError); | ||
} catch (e) {} | ||
} | ||
inherits(AuthError, Error); | ||
var getMembership = pouchdbUtils.toPromise(function (opts, callback) { | ||
var db = this; | ||
if (typeof callback === 'undefined') { | ||
callback = opts; | ||
opts = {}; | ||
} | ||
var url = utils.getUsersUrl(db) + '/' + encodeURIComponent(user._id); | ||
var ajaxOpts = utils.extend(true, { | ||
method : 'PUT', | ||
url : url, | ||
body : user | ||
var url = getBaseUrl(db) + '/_membership'; | ||
var ajaxOpts = pouchdbUtils.assign({ | ||
method: 'GET', | ||
url: url, | ||
headers: getBasicAuthHeaders(db), | ||
}, opts.ajax || {}); | ||
utils.ajax(ajaxOpts, wrapError(callback)); | ||
} | ||
ajaxCore(ajaxOpts, wrapError(callback)); | ||
}); | ||
exports.signup = utils.toPromise(function (username, password, opts, callback) { | ||
var signUpAdmin = pouchdbUtils.toPromise(function (username, password, opts, callback) { | ||
var db = this; | ||
@@ -58,17 +105,69 @@ if (typeof callback === 'undefined') { | ||
var userId = 'org.couchdb.user:' + username; | ||
var user = { | ||
name : username, | ||
password : password, | ||
roles : opts.roles || [], | ||
type : 'user', | ||
_id : userId | ||
}; | ||
db.getMembership(opts, function (error, membership) { | ||
var nodeName; | ||
if (error) { | ||
if (error.error !== 'illegal_database_name') { | ||
return callback(error); | ||
} else { | ||
// Some couchdb-1.x-like server | ||
nodeName = undefined; | ||
} | ||
} else { | ||
// Some couchdb-2.x-like server | ||
nodeName = membership.all_nodes[0]; | ||
} | ||
putUser(db, user, opts, callback); | ||
var configUrl = getConfigUrl(db, nodeName); | ||
var url = (opts.configUrl || configUrl) + '/admins/' + encodeURIComponent(username); | ||
var ajaxOpts = pouchdbUtils.assign({ | ||
method: 'PUT', | ||
url: url, | ||
processData: false, | ||
headers: getBasicAuthHeaders(db), | ||
body: '"' + password + '"', | ||
}, opts.ajax || {}); | ||
ajaxCore(ajaxOpts, wrapError(callback)); | ||
}); | ||
}); | ||
exports.signUp = exports.signup; | ||
var deleteAdmin = pouchdbUtils.toPromise(function (username, opts, callback) { | ||
var db = this; | ||
if (typeof callback === 'undefined') { | ||
callback = typeof opts === 'undefined' ? username : opts; | ||
opts = {}; | ||
} | ||
if (['http', 'https'].indexOf(db.type()) === -1) { | ||
return callback(new AuthError('This plugin only works for the http/https adapter. ' + | ||
'So you should use new PouchDB("http://mysite.com:5984/mydb") instead.')); | ||
} else if (!username) { | ||
return callback(new AuthError('You must provide a username')); | ||
} | ||
exports.login = utils.toPromise(function (username, password, opts, callback) { | ||
db.getMembership(opts, function (error, membership) { | ||
var nodeName; | ||
if (error) { | ||
if (error.error !== 'illegal_database_name') { | ||
return callback(error); | ||
} else { | ||
// Some couchdb-1.x-like server | ||
nodeName = undefined; | ||
} | ||
} else { | ||
// Some couchdb-2.x-like server | ||
nodeName = membership.all_nodes[0]; | ||
} | ||
var configUrl = getConfigUrl(db, nodeName); | ||
var url = (opts.configUrl || configUrl) + '/admins/' + encodeURIComponent(username); | ||
var ajaxOpts = pouchdbUtils.assign({ | ||
method: 'DELETE', | ||
url: url, | ||
processData: false, | ||
headers: getBasicAuthHeaders(db), | ||
}, opts.ajax || {}); | ||
ajaxCore(ajaxOpts, wrapError(callback)); | ||
}); | ||
}); | ||
var logIn = pouchdbUtils.toPromise(function (username, password, opts, callback) { | ||
var db = this; | ||
@@ -89,14 +188,12 @@ if (typeof callback === 'undefined') { | ||
var ajaxOpts = utils.extend(true, { | ||
method : 'POST', | ||
url : utils.getSessionUrl(db), | ||
headers : {'Content-Type': 'application/json'}, | ||
body : JSON.stringify({name: username, password: password}) | ||
var ajaxOpts = pouchdbUtils.assign({ | ||
method: 'POST', | ||
url: getSessionUrl(db), | ||
headers: pouchdbUtils.assign({'Content-Type': 'application/json'}, getBasicAuthHeaders(db)), | ||
body: {name: username, password: password}, | ||
}, opts.ajax || {}); | ||
utils.ajax(ajaxOpts, wrapError(callback)); | ||
ajaxCore(ajaxOpts, wrapError(callback)); | ||
}); | ||
exports.logIn = exports.login; | ||
exports.logout = utils.toPromise(function (opts, callback) { | ||
var logOut = pouchdbUtils.toPromise(function (opts, callback) { | ||
var db = this; | ||
@@ -107,12 +204,11 @@ if (typeof callback === 'undefined') { | ||
} | ||
var ajaxOpts = utils.extend(true, { | ||
method : 'DELETE', | ||
url : utils.getSessionUrl(db) | ||
var ajaxOpts = pouchdbUtils.assign({ | ||
method: 'DELETE', | ||
url: getSessionUrl(db), | ||
headers: getBasicAuthHeaders(db), | ||
}, opts.ajax || {}); | ||
utils.ajax(ajaxOpts, wrapError(callback)); | ||
ajaxCore(ajaxOpts, wrapError(callback)); | ||
}); | ||
exports.logOut = exports.logout; | ||
exports.getSession = utils.toPromise(function (opts, callback) { | ||
var getSession = pouchdbUtils.toPromise(function (opts, callback) { | ||
var db = this; | ||
@@ -123,14 +219,84 @@ if (typeof callback === 'undefined') { | ||
} | ||
var url = utils.getSessionUrl(db); | ||
var url = getSessionUrl(db); | ||
var ajaxOpts = utils.extend(true, { | ||
method : 'GET', | ||
url : url | ||
var ajaxOpts = pouchdbUtils.assign({ | ||
method: 'GET', | ||
url: url, | ||
headers: getBasicAuthHeaders(db), | ||
}, opts.ajax || {}); | ||
utils.ajax(ajaxOpts, wrapError(callback)); | ||
ajaxCore(ajaxOpts, wrapError(callback)); | ||
}); | ||
exports.getUser = utils.toPromise(function (username, opts, callback) { | ||
var getUsersDatabaseUrl = function () { | ||
var db = this; | ||
return getUsersUrl(db); | ||
}; | ||
function updateUser(db, user, opts, callback) { | ||
var reservedWords = [ | ||
'_id', | ||
'_rev', | ||
'name', | ||
'type', | ||
'roles', | ||
'password', | ||
'password_scheme', | ||
'iterations', | ||
'derived_key', | ||
'salt' ]; | ||
if (opts.metadata) { | ||
for (var key in opts.metadata) { | ||
if (opts.metadata.hasOwnProperty(key) && reservedWords.indexOf(key) !== -1) { | ||
return callback(new AuthError('cannot use reserved word in metadata: "' + key + '"')); | ||
} | ||
} | ||
user = pouchdbUtils.assign(user, opts.metadata); | ||
} | ||
if (opts.roles) { | ||
user = pouchdbUtils.assign(user, {roles: opts.roles}); | ||
} | ||
var url = getUsersUrl(db) + '/' + encodeURIComponent(user._id); | ||
var ajaxOpts = pouchdbUtils.assign({ | ||
method: 'PUT', | ||
url: url, | ||
body: user, | ||
headers: getBasicAuthHeaders(db), | ||
}, opts.ajax || {}); | ||
ajaxCore(ajaxOpts, wrapError(callback)); | ||
} | ||
var signUp = pouchdbUtils.toPromise(function (username, password, opts, callback) { | ||
var db = this; | ||
if (typeof callback === 'undefined') { | ||
callback = typeof opts === 'undefined' ? (typeof password === 'undefined' ? | ||
username : password) : opts; | ||
opts = {}; | ||
} | ||
if (['http', 'https'].indexOf(db.type()) === -1) { | ||
return callback(new AuthError('This plugin only works for the http/https adapter. ' + | ||
'So you should use new PouchDB("http://mysite.com:5984/mydb") instead.')); | ||
} else if (!username) { | ||
return callback(new AuthError('You must provide a username')); | ||
} else if (!password) { | ||
return callback(new AuthError('You must provide a password')); | ||
} | ||
var userId = 'org.couchdb.user:' + username; | ||
var user = { | ||
name: username, | ||
password: password, | ||
roles: [], | ||
type: 'user', | ||
_id: userId, | ||
}; | ||
updateUser(db, user, opts, callback); | ||
}); | ||
var getUser = pouchdbUtils.toPromise(function (username, opts, callback) { | ||
var db = this; | ||
if (typeof callback === 'undefined') { | ||
callback = typeof opts === 'undefined' ? username : opts; | ||
@@ -143,11 +309,12 @@ opts = {}; | ||
var url = utils.getUsersUrl(db); | ||
var ajaxOpts = utils.extend(true, { | ||
method : 'GET', | ||
url : url + '/' + encodeURIComponent('org.couchdb.user:' + username) | ||
var url = getUsersUrl(db); | ||
var ajaxOpts = pouchdbUtils.assign({ | ||
method: 'GET', | ||
url: url + '/' + encodeURIComponent('org.couchdb.user:' + username), | ||
headers: getBasicAuthHeaders(db), | ||
}, opts.ajax || {}); | ||
utils.ajax(ajaxOpts, wrapError(callback)); | ||
ajaxCore(ajaxOpts, wrapError(callback)); | ||
}); | ||
exports.putUser = utils.toPromise(function (username, opts, callback) { | ||
var putUser = pouchdbUtils.toPromise(function (username, opts, callback) { | ||
var db = this; | ||
@@ -165,3 +332,3 @@ if (typeof callback === 'undefined') { | ||
return db.getUser(username, opts, function (error, user) { | ||
db.getUser(username, opts, function (error, user) { | ||
if (error) { | ||
@@ -171,9 +338,37 @@ return callback(error); | ||
putUser(db, user, opts, callback); | ||
updateUser(db, user, opts, callback); | ||
}); | ||
}); | ||
exports.changePassword = utils.toPromise(function (username, password, opts, callback) { | ||
var deleteUser = pouchdbUtils.toPromise(function (username, opts, callback) { | ||
var db = this; | ||
if (typeof callback === 'undefined') { | ||
callback = typeof opts === 'undefined' ? username : opts; | ||
opts = {}; | ||
} | ||
if (['http', 'https'].indexOf(db.type()) === -1) { | ||
return callback(new AuthError('This plugin only works for the http/https adapter. ' + | ||
'So you should use new PouchDB("http://mysite.com:5984/mydb") instead.')); | ||
} else if (!username) { | ||
return callback(new AuthError('You must provide a username')); | ||
} | ||
db.getUser(username, opts, function (error, user) { | ||
if (error) { | ||
return callback(error); | ||
} | ||
var url = getUsersUrl(db) + '/' + encodeURIComponent(user._id) + '?rev=' + user._rev; | ||
var ajaxOpts = pouchdbUtils.assign({ | ||
method: 'DELETE', | ||
url: url, | ||
headers: getBasicAuthHeaders(db), | ||
}, opts.ajax || {}); | ||
ajaxCore(ajaxOpts, wrapError(callback)); | ||
}); | ||
}); | ||
var changePassword = pouchdbUtils.toPromise(function (username, password, opts, callback) { | ||
var db = this; | ||
if (typeof callback === 'undefined') { | ||
callback = typeof opts === 'undefined' ? (typeof password === 'undefined' ? | ||
@@ -192,3 +387,3 @@ username : password) : opts; | ||
return db.getUser(username, opts, function (error, user) { | ||
db.getUser(username, opts, function (error, user) { | ||
if (error) { | ||
@@ -200,18 +395,19 @@ return callback(error); | ||
var url = utils.getUsersUrl(db) + '/' + encodeURIComponent(user._id); | ||
var ajaxOpts = utils.extend(true, { | ||
method : 'PUT', | ||
url : url, | ||
body : user | ||
var url = getUsersUrl(db) + '/' + encodeURIComponent(user._id); | ||
var ajaxOpts = pouchdbUtils.assign({ | ||
method: 'PUT', | ||
url: url, | ||
headers: getBasicAuthHeaders(db), | ||
body: user, | ||
}, opts.ajax || {}); | ||
utils.ajax(ajaxOpts, wrapError(callback)); | ||
ajaxCore(ajaxOpts, wrapError(callback)); | ||
}); | ||
}); | ||
exports.changeUsername = utils.toPromise(function (oldUsername, newUsername, opts, callback) { | ||
var changeUsername = pouchdbUtils.toPromise(function (oldUsername, newUsername, opts, callback) { | ||
var db = this; | ||
var USERNAME_PREFIX = 'org.couchdb.user:'; | ||
var ajax = function (opts) { | ||
return new utils.Promise(function (resolve, reject) { | ||
utils.ajax(opts, wrapError(function (err, res) { | ||
return new Promise(function (resolve, reject) { | ||
ajaxCore(opts, wrapError(function (err, res) { | ||
if (err) { | ||
@@ -225,7 +421,8 @@ return reject(err); | ||
var updateUser = function (user, opts) { | ||
var url = utils.getUsersUrl(db) + '/' + encodeURIComponent(user._id); | ||
var updateOpts = utils.extend(true, { | ||
method : 'PUT', | ||
url : url, | ||
body: user | ||
var url = getUsersUrl(db) + '/' + encodeURIComponent(user._id); | ||
var updateOpts = pouchdbUtils.assign({ | ||
method: 'PUT', | ||
url: url, | ||
headers: getBasicAuthHeaders(db), | ||
body: user, | ||
}, opts.ajax); | ||
@@ -250,3 +447,3 @@ return ajax(updateOpts); | ||
return db.getUser(newUsername, opts) | ||
db.getUser(newUsername, opts) | ||
.then(function () { | ||
@@ -260,3 +457,3 @@ var error = new AuthError('user already exists'); | ||
.then(function (user) { | ||
var newUser = utils.clone(user); | ||
var newUser = pouchdbUtils.clone(user); | ||
delete newUser._rev; | ||
@@ -275,17 +472,27 @@ newUser._id = USERNAME_PREFIX + newUsername; | ||
var plugin = {}; | ||
function AuthError(message) { | ||
this.status = 400; | ||
this.name = 'authentication_error'; | ||
this.message = message; | ||
this.error = true; | ||
try { | ||
Error.captureStackTrace(this, AuthError); | ||
} catch (e) {} | ||
} | ||
plugin.login = logIn; | ||
plugin.logIn = logIn; | ||
plugin.logout = logOut; | ||
plugin.logOut = logOut; | ||
plugin.getSession = getSession; | ||
utils.inherits(AuthError, Error); | ||
plugin.getMembership = getMembership; | ||
plugin.signUpAdmin = signUpAdmin; | ||
plugin.deleteAdmin = deleteAdmin; | ||
plugin.getUsersDatabaseUrl = getUsersDatabaseUrl; | ||
plugin.signup = signUp; | ||
plugin.signUp = signUp; | ||
plugin.getUser = getUser; | ||
plugin.putUser = putUser; | ||
plugin.deleteUser = deleteUser; | ||
plugin.changePassword = changePassword; | ||
plugin.changeUsername = changeUsername; | ||
if (typeof window !== 'undefined' && window.PouchDB) { | ||
window.PouchDB.plugin(exports); | ||
window.PouchDB.plugin(plugin); | ||
} | ||
module.exports = plugin; |
129
package.json
{ | ||
"name": "pouchdb-authentication", | ||
"version": "0.5.5", | ||
"version": "1.0.0", | ||
"description": "PouchDB Authentication", | ||
"main": "lib/index.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/nolanlawson/pouchdb-authentication.git" | ||
}, | ||
"scripts": { | ||
"jshint": "jshint -c .jshintrc lib/ test/test.js", | ||
"build-js": "mkdirp dist && browserify . -p bundle-collapser/plugin -s PouchAuthentication > dist/pouchdb.authentication.js", | ||
"min": "uglifyjs dist/pouchdb.authentication.js -mc > dist/pouchdb.authentication.min.js", | ||
"build": "npm run build-js && npm run min", | ||
"dev": "zuul --local 9000 --no-coverage --ui mocha-bdd test/test.js", | ||
"test": "zuul --phantom --ui mocha-bdd test/test.js" | ||
}, | ||
"keywords": [ | ||
@@ -25,34 +12,100 @@ "pouch", | ||
], | ||
"author": "Nolan Lawson <nolan@nolanlawson.com", | ||
"license": "Apache-2.0", | ||
"bugs": { | ||
"url": "https://github.com/nolanlawson/pouchdb-authentication/issues" | ||
"url": "https://github.com/pouchdb-community/pouchdb-authentication/issues" | ||
}, | ||
"license": "Apache-2.0", | ||
"author": { | ||
"name": "Nolan Lawson", | ||
"email": "nolan@nolanlawson.com", | ||
"url": "https://nolanlawson.com/" | ||
}, | ||
"contributors": [ | ||
{ | ||
"name": "Didier Villevalois", | ||
"email": "ptitjes@free.fr" | ||
} | ||
], | ||
"files": [ | ||
"src", | ||
"lib", | ||
"dist" | ||
], | ||
"main": "lib/index.js", | ||
"jsnext:main": "lib/index.es.js", | ||
"module": "lib/index.es.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "git@github.com:pouchdb-community/pouchdb-authentication.git" | ||
}, | ||
"scripts": { | ||
"clean": "rimraf lib dist && mkdirp lib dist", | ||
"rollup-cjs": "rollup -c config/rollup.config.cjs.js && rollup -c config/rollup.config.browser.cjs.js", | ||
"rollup-es": "rollup -c config/rollup.config.es.js && rollup -c config/rollup.config.browser.es.js", | ||
"rollup": "npm-run-all --parallel rollup-cjs rollup-es", | ||
"browserify": "browserify -t brfs -p bundle-collapser/plugin -s PouchAuthentication lib/index.browser.js > dist/pouchdb.authentication.js", | ||
"minify": "uglifyjs -mc < dist/pouchdb.authentication.js > dist/pouchdb.authentication.min.js", | ||
"build": "npm-run-all clean rollup browserify minify", | ||
"prepublishOnly": "npm run build", | ||
"lint": "eslint bin/ src/ test/", | ||
"dev": "npm run test-local", | ||
"test": "npm run rollup-cjs && node bin/run-test.js", | ||
"test-local": "CLIENT=local npm run test", | ||
"test-node": "CLIENT=node npm run test", | ||
"test-phantom": "CLIENT=phantom npm run test", | ||
"release": "standard-version" | ||
}, | ||
"dependencies": { | ||
"inherits": "2.0.1", | ||
"pouchdb-ajax": "6.0.3", | ||
"pouchdb-extend": "0.1.2", | ||
"pouchdb-promise": "6.0.3", | ||
"pouchdb-utils": "6.0.3", | ||
"url-join": "1.1.0" | ||
"inherits": "2.0.3", | ||
"pouchdb-ajax": "~6.4.0", | ||
"pouchdb-binary-utils": "~6.4.0", | ||
"pouchdb-promise": "~6.4.0", | ||
"pouchdb-utils": "~6.4.0", | ||
"url-join": "2.0.2", | ||
"url-parse": "1.2.0" | ||
}, | ||
"devDependencies": { | ||
"bluebird": "^2.0.0", | ||
"browserify": "13.0.1", | ||
"bundle-collapser": "^1.2.1", | ||
"chai": "^3.5.0", | ||
"chai-as-promised": "^5.3.0", | ||
"istanbul": "^0.1.46", | ||
"jshint": "2.8.0", | ||
"add-cors-to-couchdb": "0.0.6", | ||
"brfs": "^1.4.3", | ||
"browserify": "^14.5.0", | ||
"bundle-collapser": "^1.3.0", | ||
"chai": "3.5.0", | ||
"chai-as-promised": "5.3.0", | ||
"eslint": "^4.6.1", | ||
"istanbul": "^0.4.5", | ||
"karma": "^1.7.1", | ||
"karma-browserify": "^5.1.2", | ||
"karma-chai": "^0.1.0", | ||
"karma-mocha": "^1.3.0", | ||
"karma-mocha-reporter": "^2.2.5", | ||
"karma-phantomjs-launcher": "^1.0.4", | ||
"karma-sauce-launcher": "^1.2.0", | ||
"mkdirp": "^0.5.1", | ||
"mocha": "^2.3.3", | ||
"phantomjs-prebuilt": "2.1.7", | ||
"mocha": "^4.0.1", | ||
"npm-run-all": "^3.1.2", | ||
"pouchdb-memory": "^6.0.0", | ||
"uglify-js": "^2.4.24", | ||
"zuul": "^3.10.1" | ||
"pouchdb-server": "^2.3.7", | ||
"rimraf": "^2.5.4", | ||
"rollup": "^0.52.0", | ||
"rollup-plugin-buble": "^0.18.0", | ||
"rollup-plugin-commonjs": "^8.2.6", | ||
"rollup-plugin-inject": "^2.0.0", | ||
"rollup-plugin-node-resolve": "^3.0.0", | ||
"rollup-plugin-replace": "^2.0.0", | ||
"standard-version": "^4.2.0", | ||
"uglify-js": "^3.1.9", | ||
"watchify": "^3.9.0" | ||
}, | ||
"files": [ | ||
"lib", | ||
"dist" | ||
] | ||
"// greenkeeper": [ | ||
"// chai-as-promised is pinned because of breaking changes in 6.0.0 which make phantomjs crash" | ||
], | ||
"greenkeeper": { | ||
"ignore": [ | ||
"chai-as-promised" | ||
] | ||
}, | ||
"standard-version": { | ||
"scripts": { | ||
"postbump": "git checkout -- bower.json" | ||
} | ||
} | ||
} |
@@ -1,10 +0,14 @@ | ||
PouchDB Authentication [![Build Status](https://travis-ci.org/nolanlawson/pouchdb-authentication.svg?branch=master)](https://travis-ci.org/nolanlawson/pouchdb-authentication) | ||
PouchDB Authentication | ||
===== | ||
<img alt="PouchDB Authentication logo by nickcolley" title="PouchDB Authentication logo by nickcolley" width="150px" src="https://raw.githubusercontent.com/nolanlawson/pouchdb-authentication/master/docs/logo.png"/> | ||
[![Build Status](https://travis-ci.org/pouchdb-community/pouchdb-authentication.svg?branch=master)](https://travis-ci.org/pouchdb-community/pouchdb-authentication) | ||
[![Greenkeeper badge](https://badges.greenkeeper.io/pouchdb-community/pouchdb-authentication.svg)](https://greenkeeper.io/) | ||
[![npm version](https://img.shields.io/npm/v/pouchdb-authentication.svg)](https://www.npmjs.com/package/pouchdb-authentication) | ||
<img alt="PouchDB Authentication logo by nickcolley" title="PouchDB Authentication logo by nickcolley" width="150px" src="https://raw.githubusercontent.com/pouchdb-community/pouchdb-authentication/master/docs/logo.png"/> | ||
Easy user authentication for PouchDB/CouchDB. | ||
```js | ||
var db = new PouchDB('http://mysite:5984/mydb', {skipSetup: true}); | ||
var db = new PouchDB('http://mysite:5984/mydb', {skip_setup: true}); | ||
db.login('batman', 'brucewayne').then(function (batman) { | ||
@@ -66,3 +70,3 @@ console.log("I'm Batman."); | ||
- CouchDB v1.3.0+ or IrisCouch | ||
- CouchDB v1.3.0+ | ||
- PouchDB v2.0.0+ | ||
@@ -89,3 +93,3 @@ | ||
Or, just grab the latest `pouchdb.authentication.min.js` from [the releases page](https://github.com/nolanlawson/pouchdb-authentication/releases) and declare it after PouchDB: | ||
Or, just grab the latest `pouchdb.authentication.min.js` from [the releases page](https://github.com/pouchdb-community/pouchdb-authentication/releases) and declare it after PouchDB: | ||
@@ -106,8 +110,6 @@ ```html | ||
Or, get yourself a hosted one at [IrisCouch](http://iriscouch.com/). It works the same. | ||
Next, set up CORS so that PouchDB can access your CouchDB from any URL. For convenience we'll use [add-cors-to-couchdb](https://github.com/pouchdb/add-cors-to-couchdb). | ||
npm install -g add-cors-to-couchdb # may require sudo | ||
add-cors-to-couchdb # for IrisCouch, see add-cors-to-couchdb instructions | ||
add-cors-to-couchdb # | ||
@@ -122,6 +124,6 @@ | ||
```js | ||
var db = new PouchDB('http://localhost:5984/mydb', {skipSetup: true}); | ||
var db = new PouchDB('http://localhost:5984/mydb', {skip_setup: true}); | ||
``` | ||
*(Note that the users are shared across the entire CouchDB instance, not just `mydb`. Also, the `skipSetup` is to prevent PouchDB from doing any HTTP requests to the server while we're not logged in, which would cause a modal authentication popup.)* | ||
*(Note that the users are shared across the entire CouchDB instance, not just `mydb`. Also, the `skip_setup` is to prevent PouchDB from doing any HTTP requests to the server while we're not logged in, which would cause a modal authentication popup.)* | ||
@@ -213,3 +215,3 @@ Of course, you'll probably want to sync that database with a local one: | ||
if (err) { | ||
if (err.name === 'unauthorized') { | ||
if (err.name === 'unauthorized' || err.name === 'forbidden') { | ||
// name or password incorrect | ||
@@ -529,4 +531,6 @@ } else { | ||
Native CouchDB Erlang plugin that automatically creates one database per user. Eventually CouchDB will have a plugin repository, and you'll be able to just click a button to install, but for now you have to install manually. | ||
Native CouchDB Erlang plugin that automatically creates one database per user. The database name is just a hex-encoded hash of the user name, and it completely predictable. | ||
**Update!** This is now much easier to use, because there are [prebuilt Docker images](https://hub.docker.com/r/klaemo/couchdb/) containing the `CouchPerUser` plugin. | ||
#### [couchdb-dbperuser-provisioning](https://github.com/pegli/couchdb-dbperuser-provisioning) | ||
@@ -562,3 +566,3 @@ | ||
To prevent browser HTTP basic authentication modal dialogs of ye olde times, we have to be subtle in the way we use PouchDB. To prevent a rogue unauthenticated request to CouchDB (used to [check whether the remote DB exists][skipsetup]), pass `skipSetup: true` in Pouch's constructor options. Secondly, to authenticate the request against `_session`, add the HTTP basic authorization header to `db.login()`'s [AJAX options](#api). | ||
To prevent browser HTTP basic authentication modal dialogs of ye olde times, we have to be subtle in the way we use PouchDB. To prevent a rogue unauthenticated request to CouchDB (used to [check whether the remote DB exists][skipsetup]), pass `skip_setup: true` in Pouch's constructor options. Secondly, to authenticate the request against `_session`, add the HTTP basic authorization header to `db.login()`'s [AJAX options](#api). | ||
@@ -574,3 +578,3 @@ Example usage: | ||
var pouchOpts = { | ||
skipSetup: true | ||
skip_setup: true | ||
}; | ||
@@ -606,7 +610,7 @@ | ||
npm run dev | ||
npm run test-local | ||
To test in PhantomJS: | ||
npm test | ||
npm run test-phantom | ||
@@ -618,8 +622,8 @@ License | ||
[admin party]: https://raw.githubusercontent.com/nolanlawson/pouchdb-authentication/master/docs/admin_party.png | ||
[blogger]: https://raw.githubusercontent.com/nolanlawson/pouchdb-authentication/master/docs/blogger.png | ||
[blogger ddoc]: https://raw.githubusercontent.com/nolanlawson/pouchdb-authentication/master/docs/blogger_ddoc.png | ||
[new doc button]: https://raw.githubusercontent.com/nolanlawson/pouchdb-authentication/master/docs/new_doc_button.png | ||
[security button]: https://raw.githubusercontent.com/nolanlawson/pouchdb-authentication/master/docs/security_button.png | ||
[employee]: https://raw.githubusercontent.com/nolanlawson/pouchdb-authentication/master/docs/employee.png | ||
[admin party]: https://raw.githubusercontent.com/pouchdb-community/pouchdb-authentication/master/docs/admin_party.png | ||
[blogger]: https://raw.githubusercontent.com/pouchdb-community/pouchdb-authentication/master/docs/blogger.png | ||
[blogger ddoc]: https://raw.githubusercontent.com/pouchdb-community/pouchdb-authentication/master/docs/blogger_ddoc.png | ||
[new doc button]: https://raw.githubusercontent.com/pouchdb-community/pouchdb-authentication/master/docs/new_doc_button.png | ||
[security button]: https://raw.githubusercontent.com/pouchdb-community/pouchdb-authentication/master/docs/security_button.png | ||
[employee]: https://raw.githubusercontent.com/pouchdb-community/pouchdb-authentication/master/docs/employee.png | ||
[cloudant-100k]: https://mail-archives.apache.org/mod_mbox/couchdb-user/201401.mbox/%3C52CEB873.7080404@ironicdesign.com%3E | ||
@@ -626,0 +630,0 @@ [couchperuser-gist]: https://gist.github.com/nolanlawson/9676093 |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
249763
15
5395
2
623
4
7
30
5
+ Addedpouchdb-binary-utils@~6.4.0
+ Addedurl-parse@1.2.0
+ Addedajv@5.5.2(transitive)
+ Addedasynckit@0.4.0(transitive)
+ Addedattempt-x@1.1.3(transitive)
+ Addedaws-sign2@0.7.0(transitive)
+ Addedboom@4.3.15.3.3(transitive)
+ Addedbuffer-from@0.1.1(transitive)
+ Addedcached-constructors-x@1.0.2(transitive)
+ Addedcaseless@0.12.0(transitive)
+ Addedclone-buffer@1.0.0(transitive)
+ Addedco@4.6.0(transitive)
+ Addedcryptiles@3.2.1(transitive)
+ Addedfast-deep-equal@1.1.0(transitive)
+ Addedfast-json-stable-stringify@2.1.0(transitive)
+ Addedform-data@2.3.3(transitive)
+ Addedhar-schema@2.0.0(transitive)
+ Addedhar-validator@5.0.3(transitive)
+ Addedhas-own-property-x@3.2.0(transitive)
+ Addedhas-symbol-support-x@1.4.2(transitive)
+ Addedhas-symbols@1.0.3(transitive)
+ Addedhas-to-string-tag-x@1.4.1(transitive)
+ Addedhas-tostringtag@1.0.2(transitive)
+ Addedhawk@6.0.2(transitive)
+ Addedhoek@4.3.1(transitive)
+ Addedhttp-signature@1.2.0(transitive)
+ Addedinfinity-x@1.0.2(transitive)
+ Addedinherits@2.0.3(transitive)
+ Addedis-array-buffer-x@1.7.0(transitive)
+ Addedis-date-object@1.0.5(transitive)
+ Addedis-falsey-x@1.0.3(transitive)
+ Addedis-finite-x@3.0.4(transitive)
+ Addedis-function-x@3.3.0(transitive)
+ Addedis-index-x@1.1.0(transitive)
+ Addedis-nan-x@1.0.3(transitive)
+ Addedis-nil-x@1.4.2(transitive)
+ Addedis-object-like-x@1.7.1(transitive)
+ Addedis-primitive@2.0.03.0.1(transitive)
+ Addedis-string@1.0.7(transitive)
+ Addedis-symbol@1.0.4(transitive)
+ Addedjson-schema-traverse@0.3.1(transitive)
+ Addedlie@3.1.1(transitive)
+ Addedlodash.isnull@3.0.0(transitive)
+ Addedmath-clamp-x@1.2.0(transitive)
+ Addedmath-sign-x@3.0.0(transitive)
+ Addedmax-safe-integer@1.0.1(transitive)
+ Addednan-x@1.0.2(transitive)
+ Addednormalize-space-x@3.0.0(transitive)
+ Addedobject-get-own-property-descriptor-x@3.2.0(transitive)
+ Addedparse-int-x@2.0.0(transitive)
+ Addedperformance-now@2.1.0(transitive)
+ Addedpouchdb-ajax@6.4.3(transitive)
+ Addedpouchdb-binary-utils@6.4.3(transitive)
+ Addedpouchdb-collections@6.4.3(transitive)
+ Addedpouchdb-errors@6.4.3(transitive)
+ Addedpouchdb-promise@6.4.3(transitive)
+ Addedpouchdb-utils@6.4.3(transitive)
+ Addedproperty-is-enumerable-x@1.1.0(transitive)
+ Addedqs@6.5.3(transitive)
+ Addedquerystringify@1.0.0(transitive)
+ Addedreplace-comments-x@2.0.0(transitive)
+ Addedrequest@2.83.0(transitive)
+ Addedrequire-coercible-to-string-x@1.0.2(transitive)
+ Addedrequire-object-coercible-x@1.4.3(transitive)
+ Addedrequires-port@1.0.0(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsntp@2.1.0(transitive)
+ Addedto-boolean-x@1.0.3(transitive)
+ Addedto-integer-x@3.0.0(transitive)
+ Addedto-number-x@2.0.0(transitive)
+ Addedto-object-x@1.5.0(transitive)
+ Addedto-primitive-x@1.1.0(transitive)
+ Addedto-property-key-x@2.0.2(transitive)
+ Addedto-string-symbols-supported-x@1.0.2(transitive)
+ Addedto-string-tag-x@1.4.3(transitive)
+ Addedto-string-x@1.4.5(transitive)
+ Addedtrim-left-x@3.0.0(transitive)
+ Addedtrim-right-x@3.0.0(transitive)
+ Addedtrim-x@3.0.0(transitive)
+ Addedtunnel-agent@0.6.0(transitive)
+ Addedurl-join@2.0.2(transitive)
+ Addedurl-parse@1.2.0(transitive)
+ Addeduuid@3.2.1(transitive)
+ Addedvalidate.io-undefined@1.0.3(transitive)
+ Addedwhite-space-x@3.0.1(transitive)
- Removedpouchdb-extend@0.1.2
- Removedansi-regex@2.1.1(transitive)
- Removedansi-styles@2.2.1(transitive)
- Removedassert-plus@0.2.0(transitive)
- Removedasync@2.6.4(transitive)
- Removedaws-sign2@0.6.0(transitive)
- Removedbl@1.1.2(transitive)
- Removedboom@2.10.1(transitive)
- Removedcaseless@0.11.0(transitive)
- Removedchalk@1.1.3(transitive)
- Removedcommander@2.20.3(transitive)
- Removedcore-util-is@1.0.3(transitive)
- Removedcryptiles@2.0.5(transitive)
- Removeddebug@2.2.0(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedform-data@1.0.1(transitive)
- Removedgenerate-function@2.3.1(transitive)
- Removedgenerate-object-property@1.2.0(transitive)
- Removedhar-validator@2.0.6(transitive)
- Removedhas-ansi@2.0.0(transitive)
- Removedhawk@3.1.3(transitive)
- Removedhoek@2.16.3(transitive)
- Removedhttp-signature@1.1.1(transitive)
- Removedinherits@2.0.1(transitive)
- Removedis-my-ip-valid@1.0.1(transitive)
- Removedis-my-json-valid@2.20.6(transitive)
- Removedis-property@1.0.2(transitive)
- Removedisarray@1.0.0(transitive)
- Removedjs-extend@1.0.1(transitive)
- Removedjsonpointer@5.0.1(transitive)
- Removedlie@3.1.0(transitive)
- Removedlodash@4.17.21(transitive)
- Removedms@0.7.1(transitive)
- Removednode-uuid@1.4.8(transitive)
- Removedpinkie@2.0.4(transitive)
- Removedpinkie-promise@2.0.1(transitive)
- Removedpouchdb-ajax@6.0.3(transitive)
- Removedpouchdb-binary-utils@6.0.3(transitive)
- Removedpouchdb-collections@6.0.3(transitive)
- Removedpouchdb-errors@6.0.3(transitive)
- Removedpouchdb-extend@0.1.2(transitive)
- Removedpouchdb-md5@6.0.3(transitive)
- Removedpouchdb-promise@6.0.3(transitive)
- Removedpouchdb-utils@6.0.3(transitive)
- Removedprocess-nextick-args@1.0.7(transitive)
- Removedqs@6.2.4(transitive)
- Removedreadable-stream@2.0.6(transitive)
- Removedrequest@2.74.0(transitive)
- Removedsntp@1.0.9(transitive)
- Removedspark-md5@2.0.2(transitive)
- Removedstring_decoder@0.10.31(transitive)
- Removedstrip-ansi@3.0.1(transitive)
- Removedsupports-color@2.0.0(transitive)
- Removedtunnel-agent@0.4.3(transitive)
- Removedurl-join@1.1.0(transitive)
- Removedutil-deprecate@1.0.2(transitive)
- Removedxtend@4.0.2(transitive)
Updatedinherits@2.0.3
Updatedpouchdb-ajax@~6.4.0
Updatedpouchdb-promise@~6.4.0
Updatedpouchdb-utils@~6.4.0
Updatedurl-join@2.0.2