diff --git a/dist/main.bundle.js b/dist/main.bundle.js index 84326dc..885b2c0 100644 --- a/dist/main.bundle.js +++ b/dist/main.bundle.js @@ -5,4 +5,4 @@ var Builton=function(t){var e={};function r(n){if(e[n])return e[n].exports;var o * @author Feross Aboukhadijeh * @license MIT */ -var n=r(42),o=r(43),i=r(44);function u(){return a.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function s(t,e){if(u()=u())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+u().toString(16)+" bytes");return 0|t}function y(t,e){if(a.isBuffer(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var r=t.length;if(0===r)return 0;for(var n=!1;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":case void 0:return L(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return z(t).length;default:if(n)return L(t).length;e=(""+e).toLowerCase(),n=!0}}function b(t,e,r){var n=t[e];t[e]=t[r],t[r]=n}function d(t,e,r,n,o){if(0===t.length)return-1;if("string"==typeof r?(n=r,r=0):2147483647=t.length){if(o)return-1;r=t.length-1}else if(r<0){if(!o)return-1;r=0}if("string"==typeof e&&(e=a.from(e,n)),a.isBuffer(e))return 0===e.length?-1:v(t,e,r,n,o);if("number"==typeof e)return e&=255,a.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):v(t,[e],r,n,o);throw new TypeError("val must be string, number or Buffer")}function v(t,e,r,n,o){var i,u=1,s=t.length,a=e.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;s/=u=2,a/=2,r/=2}function c(t,e){return 1===u?t[e]:t.readUInt16BE(e*u)}if(o){var f=-1;for(i=r;i>8,o=r%256,i.push(o),i.push(n);return i}(e,t.length-r),t,r,n)}function j(t,e,r){return 0===e&&r===t.length?n.fromByteArray(t):n.fromByteArray(t.slice(e,r))}function S(t,e,r){r=Math.min(t.length,r);for(var n=[],o=e;o>>10&1023|55296),f=56320|1023&f),n.push(f),o+=l}return function(t){var e=t.length;if(e<=E)return String.fromCharCode.apply(String,t);for(var r="",n=0;nthis.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(e>>>=0))return"";for(t=t||"utf8";;)switch(t){case"hex":return k(this,e,r);case"utf8":case"utf-8":return S(this,e,r);case"ascii":return T(this,e,r);case"latin1":case"binary":return A(this,e,r);case"base64":return j(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return R(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}.apply(this,arguments)},a.prototype.equals=function(t){if(!a.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t||0===a.compare(this,t)},a.prototype.inspect=function(){var t="",r=e.INSPECT_MAX_BYTES;return 0r&&(t+=" ... ")),""},a.prototype.compare=function(t,e,r,n,o){if(!a.isBuffer(t))throw new TypeError("Argument must be a Buffer");if(void 0===e&&(e=0),void 0===r&&(r=t?t.length:0),void 0===n&&(n=0),void 0===o&&(o=this.length),e<0||r>t.length||n<0||o>this.length)throw new RangeError("out of range index");if(o<=n&&r<=e)return 0;if(o<=n)return-1;if(r<=e)return 1;if(this===t)return 0;for(var i=(o>>>=0)-(n>>>=0),u=(r>>>=0)-(e>>>=0),s=Math.min(i,u),c=this.slice(n,o),f=t.slice(e,r),l=0;lthis.length)throw new RangeError("Attempt to write outside buffer bounds");n=n||"utf8";for(var i=!1;;)switch(n){case"hex":return g(this,t,e,r);case"utf8":case"utf-8":return m(this,t,e,r);case"ascii":return w(this,t,e,r);case"latin1":case"binary":return _(this,t,e,r);case"base64":return O(this,t,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return P(this,t,e,r);default:if(i)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),i=!0}},a.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var E=4096;function T(t,e,r){var n="";r=Math.min(t.length,r);for(var o=e;ot.length)throw new RangeError("Index out of range")}function q(t,e,r,n){e<0&&(e=65535+e+1);for(var o=0,i=Math.min(t.length-r,2);o>>8*(n?o:1-o)}function I(t,e,r,n){e<0&&(e=4294967295+e+1);for(var o=0,i=Math.min(t.length-r,4);o>>8*(n?o:3-o)&255}function D(t,e,r,n){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function B(t,e,r,n,i){return i||D(t,0,r,4),o.write(t,e,r,n,23,4),r+4}function U(t,e,r,n,i){return i||D(t,0,r,8),o.write(t,e,r,n,52,8),r+8}a.prototype.slice=function(t,e){var r,n=this.length;if((t=~~t)<0?(t+=n)<0&&(t=0):n>>8):q(this,t,e,!0),e+2},a.prototype.writeUInt16BE=function(t,e,r){return t=+t,e|=0,r||C(this,t,e,2,65535,0),a.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):q(this,t,e,!1),e+2},a.prototype.writeUInt32LE=function(t,e,r){return t=+t,e|=0,r||C(this,t,e,4,4294967295,0),a.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):I(this,t,e,!0),e+4},a.prototype.writeUInt32BE=function(t,e,r){return t=+t,e|=0,r||C(this,t,e,4,4294967295,0),a.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):I(this,t,e,!1),e+4},a.prototype.writeIntLE=function(t,e,r,n){if(t=+t,e|=0,!n){var o=Math.pow(2,8*r-1);C(this,t,e,r,o-1,-o)}var i=0,u=1,s=0;for(this[e]=255&t;++i>0)-s&255;return e+r},a.prototype.writeIntBE=function(t,e,r,n){if(t=+t,e|=0,!n){var o=Math.pow(2,8*r-1);C(this,t,e,r,o-1,-o)}var i=r-1,u=1,s=0;for(this[e+i]=255&t;0<=--i&&(u*=256);)t<0&&0===s&&0!==this[e+i+1]&&(s=1),this[e+i]=(t/u>>0)-s&255;return e+r},a.prototype.writeInt8=function(t,e,r){return t=+t,e|=0,r||C(this,t,e,1,127,-128),a.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[e]=255&t,e+1},a.prototype.writeInt16LE=function(t,e,r){return t=+t,e|=0,r||C(this,t,e,2,32767,-32768),a.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):q(this,t,e,!0),e+2},a.prototype.writeInt16BE=function(t,e,r){return t=+t,e|=0,r||C(this,t,e,2,32767,-32768),a.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):q(this,t,e,!1),e+2},a.prototype.writeInt32LE=function(t,e,r){return t=+t,e|=0,r||C(this,t,e,4,2147483647,-2147483648),a.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):I(this,t,e,!0),e+4},a.prototype.writeInt32BE=function(t,e,r){return t=+t,e|=0,r||C(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),a.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):I(this,t,e,!1),e+4},a.prototype.writeFloatLE=function(t,e,r){return B(this,t,e,!0,r)},a.prototype.writeFloatBE=function(t,e,r){return B(this,t,e,!1,r)},a.prototype.writeDoubleLE=function(t,e,r){return U(this,t,e,!0,r)},a.prototype.writeDoubleBE=function(t,e,r){return U(this,t,e,!1,r)},a.prototype.copy=function(t,e,r,n){if(r=r||0,n||0===n||(n=this.length),e>=t.length&&(e=t.length),e=e||0,0=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e>>=0,r=void 0===r?this.length:r>>>0,"number"==typeof(t=t||0))for(i=e;i>6|192,63&r|128)}else if(r<65536){if((e-=3)<0)break;i.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;i.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return i}function z(t){return n.toByteArray(function(t){if((t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(M,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function Y(t,e,r,n){for(var o=0;o=e.length||o>=t.length);++o)e[o+r]=t[o];return o}}).call(this,r(41))},function(t,e){var r;r=function(){return this}();try{r=r||new Function("return this")()}catch(t){"object"==typeof window&&(r=window)}t.exports=r},function(t,e,r){"use strict";e.byteLength=function(t){var e=c(t),r=e[0],n=e[1];return 3*(r+n)/4-n},e.toByteArray=function(t){var e,r,n=c(t),u=n[0],s=n[1],a=new i(function(t,e,r){return 3*(e+r)/4-r}(0,u,s)),f=0,l=0>16&255,a[f++]=e>>8&255,a[f++]=255&e;return 2===s&&(e=o[t.charCodeAt(r)]<<2|o[t.charCodeAt(r+1)]>>4,a[f++]=255&e),1===s&&(e=o[t.charCodeAt(r)]<<10|o[t.charCodeAt(r+1)]<<4|o[t.charCodeAt(r+2)]>>2,a[f++]=e>>8&255,a[f++]=255&e),a},e.fromByteArray=function(t){for(var e,r=t.length,o=r%3,i=[],u=0,s=r-o;u>2]+n[e<<4&63]+"==")):2==o&&(e=(t[r-2]<<8)+t[r-1],i.push(n[e>>10]+n[e>>4&63]+n[e<<2&63]+"=")),i.join("")};for(var n=[],o=[],i="undefined"!=typeof Uint8Array?Uint8Array:Array,u="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",s=0,a=u.length;s>18&63]+n[i>>12&63]+n[i>>6&63]+n[63&i]);return u.join("")}o["-".charCodeAt(0)]=62,o["_".charCodeAt(0)]=63},function(t,e){e.read=function(t,e,r,n,o){var i,u,s=8*o-n-1,a=(1<>1,f=-7,l=r?o-1:0,p=r?-1:1,h=t[e+l];for(l+=p,i=h&(1<<-f)-1,h>>=-f,f+=s;0>=-f,f+=n;0>1,p=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,h=n?0:i-1,y=n?1:-1,b=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(s=isNaN(e)?1:0,u=f):(u=Math.floor(Math.log(e)/Math.LN2),e*(a=Math.pow(2,-u))<1&&(u--,a*=2),2<=(e+=1<=u+l?p/a:p*Math.pow(2,1-l))*a&&(u++,a/=2),f<=u+l?(s=0,u=f):1<=u+l?(s=(e*a-1)*Math.pow(2,o),u+=l):(s=e*Math.pow(2,l-1)*Math.pow(2,o),u=0));8<=o;t[r+h]=255&s,h+=y,s/=256,o-=8);for(u=u<o.length(this._area)&&(n--,r--)}return e||this},keys:function(t){return this.each(function(t,e,r){r.push(t)},t||[])},get:function(t,e){var r=o.get(this._area,this._in(t));return null!==r?o.parse(r):e||r},getAll:function(t){return this.each(function(t,e,r){r[t]=e},t||{})},transact:function(t,e,r){var n=this.get(t,r),o=e(n);return this.set(t,void 0===o?n:o),this},set:function(t,e,r){var n=this.get(t);return null!=n&&!1===r?e:o.set(this._area,this._in(t),o.stringify(e),r)||n},setAll:function(t,e){var r,n;for(var o in t)n=t[o],this.set(o,n,e)!==n&&(r=!0);return r},add:function(t,e){var r=this.get(t);if(r instanceof Array)e=r.concat(e);else if(null!==r){var n=typeof r;if(n==typeof e&&"object"==n){for(var i in e)r[i]=e[i];e=r}else e=r+e}return o.set(this._area,this._in(t),o.stringify(e)),e},remove:function(t,e){var r=this.get(t,e);return o.remove(this._area,this._in(t)),r},clear:function(){return this._ns?this.each(function(t){o.remove(this._area,this._in(t))},1):o.clear(this._area),this},clearAll:function(){var t=this._area;for(var e in o.areas)o.areas.hasOwnProperty(e)&&(this._area=o.areas[e],this.clear());return this._area=t,this},_in:function(t){return"string"!=typeof t&&(t=o.stringify(t)),this._ns?this._ns+t:t},_out:function(t){return this._ns?t&&0===t.indexOf(this._ns)?t.substring(this._ns.length):void 0:t}},storageAPI:{length:0,has:function(t){return this.items.hasOwnProperty(t)},key:function(t){var e=0;for(var r in this.items)if(this.has(r)&&t===e++)return r},setItem:function(t,e){this.has(t)||this.length++,this.items[t]=e},removeItem:function(t){this.has(t)&&(delete this.items[t],this.length--)},getItem:function(t){return this.has(t)?this.items[t]:null},clear:function(){for(var t in this.items)this.removeItem(t)},toString:function(){return this.length+" items in "+this.name+"Storage"}}}).Store("local",function(){try{return localStorage}catch(t){}}())).local=i)._=o,i.area("session",function(){try{return sessionStorage}catch(t){}}()),"function"==typeof n&&void 0!==n.amd?n("store2",[],function(){return i}):t.exports?t.exports=i:(this.store&&(o.conflict=this.store),this.store=i)}]); \ No newline at end of file +var n=r(44),o=r(45),i=r(46);function u(){return a.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function s(t,e){if(u()=u())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+u().toString(16)+" bytes");return 0|t}function y(t,e){if(a.isBuffer(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var r=t.length;if(0===r)return 0;for(var n=!1;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":case void 0:return L(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return z(t).length;default:if(n)return L(t).length;e=(""+e).toLowerCase(),n=!0}}function d(t,e,r){var n=t[e];t[e]=t[r],t[r]=n}function b(t,e,r,n,o){if(0===t.length)return-1;if("string"==typeof r?(n=r,r=0):2147483647=t.length){if(o)return-1;r=t.length-1}else if(r<0){if(!o)return-1;r=0}if("string"==typeof e&&(e=a.from(e,n)),a.isBuffer(e))return 0===e.length?-1:v(t,e,r,n,o);if("number"==typeof e)return e&=255,a.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):v(t,[e],r,n,o);throw new TypeError("val must be string, number or Buffer")}function v(t,e,r,n,o){var i,u=1,s=t.length,a=e.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;s/=u=2,a/=2,r/=2}function c(t,e){return 1===u?t[e]:t.readUInt16BE(e*u)}if(o){var f=-1;for(i=r;i>8,o=r%256,i.push(o),i.push(n);return i}(e,t.length-r),t,r,n)}function j(t,e,r){return 0===e&&r===t.length?n.fromByteArray(t):n.fromByteArray(t.slice(e,r))}function S(t,e,r){r=Math.min(t.length,r);for(var n=[],o=e;o>>10&1023|55296),f=56320|1023&f),n.push(f),o+=l}return function(t){var e=t.length;if(e<=E)return String.fromCharCode.apply(String,t);for(var r="",n=0;nthis.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(e>>>=0))return"";for(t=t||"utf8";;)switch(t){case"hex":return A(this,e,r);case"utf8":case"utf-8":return S(this,e,r);case"ascii":return T(this,e,r);case"latin1":case"binary":return k(this,e,r);case"base64":return j(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return R(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}.apply(this,arguments)},a.prototype.equals=function(t){if(!a.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t||0===a.compare(this,t)},a.prototype.inspect=function(){var t="",r=e.INSPECT_MAX_BYTES;return 0r&&(t+=" ... ")),""},a.prototype.compare=function(t,e,r,n,o){if(!a.isBuffer(t))throw new TypeError("Argument must be a Buffer");if(void 0===e&&(e=0),void 0===r&&(r=t?t.length:0),void 0===n&&(n=0),void 0===o&&(o=this.length),e<0||r>t.length||n<0||o>this.length)throw new RangeError("out of range index");if(o<=n&&r<=e)return 0;if(o<=n)return-1;if(r<=e)return 1;if(this===t)return 0;for(var i=(o>>>=0)-(n>>>=0),u=(r>>>=0)-(e>>>=0),s=Math.min(i,u),c=this.slice(n,o),f=t.slice(e,r),l=0;lthis.length)throw new RangeError("Attempt to write outside buffer bounds");n=n||"utf8";for(var i=!1;;)switch(n){case"hex":return g(this,t,e,r);case"utf8":case"utf-8":return m(this,t,e,r);case"ascii":return w(this,t,e,r);case"latin1":case"binary":return _(this,t,e,r);case"base64":return P(this,t,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return O(this,t,e,r);default:if(i)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),i=!0}},a.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var E=4096;function T(t,e,r){var n="";r=Math.min(t.length,r);for(var o=e;ot.length)throw new RangeError("Index out of range")}function q(t,e,r,n){e<0&&(e=65535+e+1);for(var o=0,i=Math.min(t.length-r,2);o>>8*(n?o:1-o)}function I(t,e,r,n){e<0&&(e=4294967295+e+1);for(var o=0,i=Math.min(t.length-r,4);o>>8*(n?o:3-o)&255}function D(t,e,r,n){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function B(t,e,r,n,i){return i||D(t,0,r,4),o.write(t,e,r,n,23,4),r+4}function U(t,e,r,n,i){return i||D(t,0,r,8),o.write(t,e,r,n,52,8),r+8}a.prototype.slice=function(t,e){var r,n=this.length;if((t=~~t)<0?(t+=n)<0&&(t=0):n>>8):q(this,t,e,!0),e+2},a.prototype.writeUInt16BE=function(t,e,r){return t=+t,e|=0,r||C(this,t,e,2,65535,0),a.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):q(this,t,e,!1),e+2},a.prototype.writeUInt32LE=function(t,e,r){return t=+t,e|=0,r||C(this,t,e,4,4294967295,0),a.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):I(this,t,e,!0),e+4},a.prototype.writeUInt32BE=function(t,e,r){return t=+t,e|=0,r||C(this,t,e,4,4294967295,0),a.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):I(this,t,e,!1),e+4},a.prototype.writeIntLE=function(t,e,r,n){if(t=+t,e|=0,!n){var o=Math.pow(2,8*r-1);C(this,t,e,r,o-1,-o)}var i=0,u=1,s=0;for(this[e]=255&t;++i>0)-s&255;return e+r},a.prototype.writeIntBE=function(t,e,r,n){if(t=+t,e|=0,!n){var o=Math.pow(2,8*r-1);C(this,t,e,r,o-1,-o)}var i=r-1,u=1,s=0;for(this[e+i]=255&t;0<=--i&&(u*=256);)t<0&&0===s&&0!==this[e+i+1]&&(s=1),this[e+i]=(t/u>>0)-s&255;return e+r},a.prototype.writeInt8=function(t,e,r){return t=+t,e|=0,r||C(this,t,e,1,127,-128),a.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[e]=255&t,e+1},a.prototype.writeInt16LE=function(t,e,r){return t=+t,e|=0,r||C(this,t,e,2,32767,-32768),a.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):q(this,t,e,!0),e+2},a.prototype.writeInt16BE=function(t,e,r){return t=+t,e|=0,r||C(this,t,e,2,32767,-32768),a.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):q(this,t,e,!1),e+2},a.prototype.writeInt32LE=function(t,e,r){return t=+t,e|=0,r||C(this,t,e,4,2147483647,-2147483648),a.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):I(this,t,e,!0),e+4},a.prototype.writeInt32BE=function(t,e,r){return t=+t,e|=0,r||C(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),a.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):I(this,t,e,!1),e+4},a.prototype.writeFloatLE=function(t,e,r){return B(this,t,e,!0,r)},a.prototype.writeFloatBE=function(t,e,r){return B(this,t,e,!1,r)},a.prototype.writeDoubleLE=function(t,e,r){return U(this,t,e,!0,r)},a.prototype.writeDoubleBE=function(t,e,r){return U(this,t,e,!1,r)},a.prototype.copy=function(t,e,r,n){if(r=r||0,n||0===n||(n=this.length),e>=t.length&&(e=t.length),e=e||0,0=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e>>=0,r=void 0===r?this.length:r>>>0,"number"==typeof(t=t||0))for(i=e;i>6|192,63&r|128)}else if(r<65536){if((e-=3)<0)break;i.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;i.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return i}function z(t){return n.toByteArray(function(t){if((t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(M,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function Y(t,e,r,n){for(var o=0;o=e.length||o>=t.length);++o)e[o+r]=t[o];return o}}).call(this,r(43))},function(t,e){var r;r=function(){return this}();try{r=r||new Function("return this")()}catch(t){"object"==typeof window&&(r=window)}t.exports=r},function(t,e,r){"use strict";e.byteLength=function(t){var e=c(t),r=e[0],n=e[1];return 3*(r+n)/4-n},e.toByteArray=function(t){var e,r,n=c(t),u=n[0],s=n[1],a=new i(function(t,e,r){return 3*(e+r)/4-r}(0,u,s)),f=0,l=0>16&255,a[f++]=e>>8&255,a[f++]=255&e;return 2===s&&(e=o[t.charCodeAt(r)]<<2|o[t.charCodeAt(r+1)]>>4,a[f++]=255&e),1===s&&(e=o[t.charCodeAt(r)]<<10|o[t.charCodeAt(r+1)]<<4|o[t.charCodeAt(r+2)]>>2,a[f++]=e>>8&255,a[f++]=255&e),a},e.fromByteArray=function(t){for(var e,r=t.length,o=r%3,i=[],u=0,s=r-o;u>2]+n[e<<4&63]+"==")):2==o&&(e=(t[r-2]<<8)+t[r-1],i.push(n[e>>10]+n[e>>4&63]+n[e<<2&63]+"=")),i.join("")};for(var n=[],o=[],i="undefined"!=typeof Uint8Array?Uint8Array:Array,u="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",s=0,a=u.length;s>18&63]+n[i>>12&63]+n[i>>6&63]+n[63&i]);return u.join("")}o["-".charCodeAt(0)]=62,o["_".charCodeAt(0)]=63},function(t,e){e.read=function(t,e,r,n,o){var i,u,s=8*o-n-1,a=(1<>1,f=-7,l=r?o-1:0,p=r?-1:1,h=t[e+l];for(l+=p,i=h&(1<<-f)-1,h>>=-f,f+=s;0>=-f,f+=n;0>1,p=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,h=n?0:i-1,y=n?1:-1,d=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(s=isNaN(e)?1:0,u=f):(u=Math.floor(Math.log(e)/Math.LN2),e*(a=Math.pow(2,-u))<1&&(u--,a*=2),2<=(e+=1<=u+l?p/a:p*Math.pow(2,1-l))*a&&(u++,a/=2),f<=u+l?(s=0,u=f):1<=u+l?(s=(e*a-1)*Math.pow(2,o),u+=l):(s=e*Math.pow(2,l-1)*Math.pow(2,o),u=0));8<=o;t[r+h]=255&s,h+=y,s/=256,o-=8);for(u=u<o.length(this._area)&&(n--,r--)}return e||this},keys:function(t){return this.each(function(t,e,r){r.push(t)},t||[])},get:function(t,e){var r=o.get(this._area,this._in(t));return null!==r?o.parse(r):e||r},getAll:function(t){return this.each(function(t,e,r){r[t]=e},t||{})},transact:function(t,e,r){var n=this.get(t,r),o=e(n);return this.set(t,void 0===o?n:o),this},set:function(t,e,r){var n=this.get(t);return null!=n&&!1===r?e:o.set(this._area,this._in(t),o.stringify(e),r)||n},setAll:function(t,e){var r,n;for(var o in t)n=t[o],this.set(o,n,e)!==n&&(r=!0);return r},add:function(t,e){var r=this.get(t);if(r instanceof Array)e=r.concat(e);else if(null!==r){var n=typeof r;if(n==typeof e&&"object"==n){for(var i in e)r[i]=e[i];e=r}else e=r+e}return o.set(this._area,this._in(t),o.stringify(e)),e},remove:function(t,e){var r=this.get(t,e);return o.remove(this._area,this._in(t)),r},clear:function(){return this._ns?this.each(function(t){o.remove(this._area,this._in(t))},1):o.clear(this._area),this},clearAll:function(){var t=this._area;for(var e in o.areas)o.areas.hasOwnProperty(e)&&(this._area=o.areas[e],this.clear());return this._area=t,this},_in:function(t){return"string"!=typeof t&&(t=o.stringify(t)),this._ns?this._ns+t:t},_out:function(t){return this._ns?t&&0===t.indexOf(this._ns)?t.substring(this._ns.length):void 0:t}},storageAPI:{length:0,has:function(t){return this.items.hasOwnProperty(t)},key:function(t){var e=0;for(var r in this.items)if(this.has(r)&&t===e++)return r},setItem:function(t,e){this.has(t)||this.length++,this.items[t]=e},removeItem:function(t){this.has(t)&&(delete this.items[t],this.length--)},getItem:function(t){return this.has(t)?this.items[t]:null},clear:function(){for(var t in this.items)this.removeItem(t)},toString:function(){return this.length+" items in "+this.name+"Storage"}}}).Store("local",function(){try{return localStorage}catch(t){}}())).local=i)._=o,i.area("session",function(){try{return sessionStorage}catch(t){}}()),"function"==typeof n&&void 0!==n.amd?n("store2",[],function(){return i}):t.exports?t.exports=i:(this.store&&(o.conflict=this.store),this.store=i)}]); \ No newline at end of file diff --git a/examples/stripe-firebase-full-order/index.html b/examples/stripe-firebase-full-order/index.html new file mode 100644 index 0000000..9edd331 --- /dev/null +++ b/examples/stripe-firebase-full-order/index.html @@ -0,0 +1,236 @@ + + + + + + Builton SDK & Firebase example + + + + + + + + + +
+
+ +
+
+
Please use a Stripe test card
+
+ +
+
+

+    
+ + + + diff --git a/src/collection/objects/_objects.js b/src/collection/objects/_objects.js index a7ecef0..9b01d6d 100644 --- a/src/collection/objects/_objects.js +++ b/src/collection/objects/_objects.js @@ -59,7 +59,7 @@ class Component { }).then((res) => { const obj = parseJson(res, ResConstructor, json); return Promise.resolve({ res, obj }); - }).catch((err) => Promise.reject(err)); + }).catch((err) => Promise.reject(new Error.BadRequest(err))); } catch (err) { return Promise.reject(err); } diff --git a/src/collection/resources/_resources.js b/src/collection/resources/_resources.js index 007df31..7483442 100644 --- a/src/collection/resources/_resources.js +++ b/src/collection/resources/_resources.js @@ -46,7 +46,7 @@ class Components { }).then((res) => { const obj = parseJson(res, ResConstructor, json); return Promise.resolve({ res, obj }); - }).catch((err) => Promise.reject(err)); + }).catch((err) => Promise.reject(new Error.BadRequest(err))); } catch (err) { return Promise.reject(err); } diff --git a/src/collection/resources/paymentMethods.js b/src/collection/resources/paymentMethods.js index 4cdf76e..92aba3c 100644 --- a/src/collection/resources/paymentMethods.js +++ b/src/collection/resources/paymentMethods.js @@ -1,5 +1,9 @@ +/* eslint-disable max-classes-per-file */ const Components = require('./_resources'); const PaymentMethod = require('../objects/paymentMethod'); +const Error = require('../../utils/error'); +const StripePaymentProvider = require('../../functionality/paymentProvider/stripe'); +const VippsPaymentProvider = require('../../functionality/paymentProvider/vipps'); const { create, del, @@ -16,6 +20,58 @@ class PaymentMethods extends Components { this.request = request; this.apiPath = 'payment_methods'; this.ResConstructor = PaymentMethod; + this.StripePaymentProvider = StripePaymentProvider; + this.VippsPaymentProvider = VippsPaymentProvider; + } + + createWithProvider(provider, { urlParams, json = false } = {}, done) { + const createWithStripe = (stripe, cardElement) => this.create({ + payment_method: 'stripe', + }) + .catch((err) => { + if (done) { + done(err); + } + return Promise.reject(err); + }) + .then((holderPaymentMethod) => stripe.handleCardSetup( + holderPaymentMethod.setup_intent.client_secret, + cardElement, + ) + .catch((err) => { + const error = new Error.StripeError(err); + if (done) { + done(error); + } + return Promise.reject(error); + }) + .then((stripeResponse) => { + if (stripeResponse.error) { + const error = new Error.StripeError(stripeResponse.error); + if (done) { + done(error); + } + return Promise.reject(error); + } + return holderPaymentMethod.update({ + payment_method_id: stripeResponse.setupIntent.payment_method, + }, { urlParams, json }, done); + })); + + const createWithVipps = () => this.create({ + payment_method: 'vipps', + }); + switch (provider.name) { + case 'StripePaymentProvider': + if (provider.stripe && provider.element) { + return createWithStripe(provider.stripe, provider.element); + } + break; + case 'VippsPaymentProvider': + return createWithVipps(); + default: + throw new Error.UnknownPaymentProvider(); + } } } diff --git a/src/collection/resources/payments.js b/src/collection/resources/payments.js index 6ef5ea9..25f08de 100644 --- a/src/collection/resources/payments.js +++ b/src/collection/resources/payments.js @@ -1,5 +1,6 @@ const Components = require('./_resources'); const Payment = require('../objects/payment'); +const Error = require('../../utils/error'); const { create, getFromId, @@ -17,6 +18,73 @@ class Payments extends Components { this.ResConstructor = Payment; } + createWithProvider(provider, body, { urlParams, json = false } = {}, done) { + const createWithStripe = (stripe) => this.create( + body, + ) + .catch((createError) => { + if (createError.status === 422) { + const payments = createError.response.body; + const paymentList = []; + return new Promise((resolve) => { + let result = Promise.resolve(); + payments.forEach((payment) => { + if ( + payment.current_state + && payment.current_state.toUpperCase() === 'PENDING' + && payment.metadata + && payment.metadata.intent_client_secret + && payment.metadata.intent_id + ) { + result = result + .then(() => stripe.handleCardAction(payment.metadata.intent_client_secret)) + .catch((error) => { throw new Error.StripeError(error); }) + .then((stripeResponse) => { + if (stripeResponse.error) { + const error = new Error.StripeError(stripeResponse.error); + if (done) { + done(error); + } + return Promise.reject(error); + } + // eslint-disable-next-line camelcase + const { id, client_secret } = stripeResponse.paymentIntent; + return this.confirm(payment._id.$oid, { + payment_intent_id: id, + payment_client_secret: client_secret, + }, { urlParams, json }, done); + }) + .then((SCAPayment) => { + paymentList.push(new Payment(this.request, SCAPayment)); + }) + .catch((error) => { + paymentList.push(new Payment(this.request, { + ...payment, + error, + })); + }); + } else { + result = result.then(() => paymentList.push(new Payment(this.request, payment))); + } + }); + result.then(() => resolve(paymentList)); + }); + } + }); + + switch (provider.name) { + case 'StripePaymentProvider': + if (provider.stripe && provider.element) { + return createWithStripe(provider.stripe, provider.element); + } + break; + case 'VippsPaymentProvider': + return create(body, { json }, done); + default: + throw new Error.UnknownPaymentProvider(); + } + } + pay(id, ...params) { const obj = new Payment(this.request, id); return obj.pay(...params); diff --git a/src/functionality/paymentProvider/stripe.js b/src/functionality/paymentProvider/stripe.js new file mode 100644 index 0000000..6853e32 --- /dev/null +++ b/src/functionality/paymentProvider/stripe.js @@ -0,0 +1,9 @@ +class StripePaymentProvider { + constructor(stripe, element) { + this.name = 'StripePaymentProvider'; + this.stripe = stripe; + this.element = element; + } +} + +module.exports = StripePaymentProvider; diff --git a/src/functionality/paymentProvider/vipps.js b/src/functionality/paymentProvider/vipps.js new file mode 100644 index 0000000..db39419 --- /dev/null +++ b/src/functionality/paymentProvider/vipps.js @@ -0,0 +1,7 @@ +class VippsPaymentProvider { + constructor() { + this.name = 'VippsPaymentProvider'; + } +} + +module.exports = VippsPaymentProvider; diff --git a/src/utils/error.js b/src/utils/error.js index 79235fb..71f1ef9 100644 --- a/src/utils/error.js +++ b/src/utils/error.js @@ -1,9 +1,14 @@ /* eslint-disable max-classes-per-file */ class ExtendableError extends Error { - constructor(message) { + constructor(message, metadata) { super(); this.message = message; this.name = this.constructor.name; + Object.entries(metadata).forEach(([key, value]) => { + if (!this[key]) { + this[key] = value; + } + }); } } @@ -31,16 +36,37 @@ class AbstractClass extends ExtendableError { } } +class BadRequest extends ExtendableError { + constructor(requestError) { + super(requestError.response.body.message || 'Bad request', requestError); + } +} + +class StripeError extends ExtendableError { + constructor(stripeError) { + super(stripeError.message || 'Payment error', stripeError); + } +} + class ImageUpload extends ExtendableError { constructor() { super('Data needs to be an object { buffer: Buffer, filename: String } or an instance File(client).'); } } +class UnknownPaymentProvider extends ExtendableError { + constructor() { + super('This payment method name doesn\'t exist'); + } +} + module.exports = { MethodNeedsId, AbstractClass, MethodNeedsArg, NotImplemented, + BadRequest, + StripeError, ImageUpload, + UnknownPaymentProvider, }; diff --git a/test/architecture/architecture.json b/test/architecture/architecture.json index f3f61b0..faa0407 100644 --- a/test/architecture/architecture.json +++ b/test/architecture/architecture.json @@ -134,7 +134,8 @@ "create", "getAll", "getFromId", - "set" + "set", + "createWithProvider" ] } } @@ -158,7 +159,10 @@ "create", "getFromId", "getAll", - "set" + "set", + "createWithProvider", + "StripePaymentProvider", + "VippsPaymentProvider" ] } }