UNPKG

@pusher/chatkit

Version:

Pusher Chatkit client library for browsers and react native

1 lines 91.3 kB
"use strict";function unwrapExports(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function createCommonjsModule(e,t){return e(t={exports:{}},t.exports),t.exports}var pusherPlatform=createCommonjsModule(function(module){module.exports=function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:n})},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=11)}([function(e,t,r){function n(e){var t={};if(!e)return t;for(var r=0,n=e.split("\r\n");r<n.length;r++){var o=n[r],s=o.indexOf(": ");if(s>0){var i=o.substring(0,s),u=o.substring(s+2);t[i]=u}}return t}Object.defineProperty(t,"__esModule",{value:!0}),t.responseToHeadersObject=n;var o=function(){function e(e,t,r){this.statusCode=e,this.headers=t,this.info=r}return e.fromXHR=function(t){var r=t.responseText;try{r=JSON.parse(t.responseText)}catch(e){}return new e(t.status,n(t.getAllResponseHeaders()),r)},e}();t.ErrorResponse=o;var s=function(){return function(e){this.error=e}}();t.NetworkError=s,function(e){e[e.UNSENT=0]="UNSENT",e[e.OPENED=1]="OPENED",e[e.HEADERS_RECEIVED=2]="HEADERS_RECEIVED",e[e.LOADING=3]="LOADING",e[e.DONE=4]="DONE"}(t.XhrReadyState||(t.XhrReadyState={}))},function(module,exports){var g;g=function(){return this}();try{g=g||Function("return this")()||eval("this")}catch(e){"object"==typeof window&&(g=window)}module.exports=g},function(e,t,r){(function(e){var r;Object.defineProperty(t,"__esModule",{value:!0}),function(e){e[e.VERBOSE=1]="VERBOSE",e[e.DEBUG=2]="DEBUG",e[e.INFO=3]="INFO",e[e.WARNING=4]="WARNING",e[e.ERROR=5]="ERROR"}(r=t.LogLevel||(t.LogLevel={}));var n=function(){function t(t){void 0===t&&(t=2),this.threshold=t;var r=Array(),n="--------------------------------------------------------------------------------";e.console.group||(e.console.group=function(t){r.push(t),e.console.log("%c \nBEGIN GROUP: %c",n,t)}),e.console.groupEnd||(e.console.groupEnd=function(){e.console.log("END GROUP: %c\n%c",r.pop(),n)})}return t.prototype.verbose=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];this.log(e.console.log,r.VERBOSE,t)},t.prototype.debug=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];this.log(e.console.log,r.DEBUG,t)},t.prototype.info=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];this.log(e.console.info,r.INFO,t)},t.prototype.warn=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];this.log(e.console.warn,r.WARNING,t)},t.prototype.error=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];this.log(e.console.error,r.ERROR,t)},t.prototype.log=function(t,n,o){var s=this;if(n>=this.threshold){var i="Logger."+r[n];o.length>1?(e.console.group(),o.forEach(function(e){s.errorAwareLog(t,e,i)}),e.console.groupEnd()):this.errorAwareLog(t,o[0],i)}},t.prototype.errorAwareLog=function(e,t,r){if(void 0!==t&&t.info&&t.info.error_uri){var n=t.info.error_description;e((n||"An error has occurred")+". More information can be found at "+t.info.error_uri+". Error object: ",t)}else e(r+": ",t)},t}();t.ConsoleLogger=n;var o=function(){function e(){}return e.prototype.verbose=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t]},e.prototype.debug=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t]},e.prototype.info=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t]},e.prototype.warn=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t]},e.prototype.error=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t]},e}();t.EmptyLogger=o}).call(t,r(1))},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});var n=r(0);t.createRetryStrategyOptionsOrDefault=function(e){var t=e.initialTimeoutMillis||1e3,r=e.maxTimeoutMillis||5e3,n=-1;return void 0!==e.limit&&null!=e.limit&&(n=e.limit),{increaseTimeout:void 0!==e.increaseTimeout?e.increaseTimeout:function(e){return 2*e>r?r:2*e},initialTimeoutMillis:t,limit:n,maxTimeoutMillis:r}};var o=function(){return function(e){this.waitTimeMillis=e}}();t.Retry=o;var s=function(){return function(e){this.error=e}}();t.DoNotRetry=s;var i=function(){function e(e,t,r){this.options=e,this.logger=t,this.retryUnsafeRequests=r,this.currentRetryCount=0,this.initialTimeoutMillis=e.initialTimeoutMillis,this.maxTimeoutMillis=e.maxTimeoutMillis,this.limit=e.limit,this.increaseTimeoutFunction=e.increaseTimeout,this.currentBackoffMillis=this.initialTimeoutMillis}return e.prototype.attemptRetry=function(e){return this.logger.verbose(this.constructor.name+": Error received",e),this.currentRetryCount>=this.limit&&this.limit>=0?(this.logger.verbose(this.constructor.name+": Retry count is over the maximum limit: "+this.limit),new s(e)):e instanceof n.ErrorResponse&&e.headers["Retry-After"]?(this.logger.verbose(this.constructor.name+": Retry-After header is present, retrying in "+e.headers["Retry-After"]),new o(1e3*parseInt(e.headers["Retry-After"],10))):e instanceof n.NetworkError||e instanceof n.ErrorResponse&&("GET"===(t=(t=e.headers["Request-Method"]).toUpperCase())||"HEAD"===t||"OPTIONS"===t||"SUBSCRIBE"===t)||this.retryUnsafeRequests?this.shouldSafeRetry(e):e instanceof n.NetworkError?this.shouldSafeRetry(e):(this.logger.verbose(this.constructor.name+": Error is not retryable",e),new s(e));var t},e.prototype.shouldSafeRetry=function(e){return e instanceof n.NetworkError?(this.logger.verbose(this.constructor.name+": It's a Network Error, will retry",e),new o(this.calulateMillisToRetry())):e instanceof n.ErrorResponse&&e.statusCode>=500&&e.statusCode<600?(this.logger.verbose(this.constructor.name+": Error 5xx, will retry"),new o(this.calulateMillisToRetry())):(this.logger.verbose(this.constructor.name+": Error is not retryable",e),new s(e))},e.prototype.calulateMillisToRetry=function(){return this.currentBackoffMillis=this.increaseTimeoutFunction(this.currentBackoffMillis),this.logger.verbose(this.constructor.name+": Retrying in "+this.currentBackoffMillis+"ms"),this.currentBackoffMillis},e}();t.RetryResolution=i},function(e,t,r){var n=this&&this.__assign||Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e};Object.defineProperty(t,"__esModule",{value:!0});var o=r(2),s=r(5),i=r(6),u=r(7),a=r(12),c=r(13),h=r(8),l=r(14),p=r(15),f=r(9),d=function(){function e(e){this.options=e,this.host=e.host.replace(/(\/)+$/,""),this.logger=e.logger||new o.ConsoleLogger,this.websocketTransport=new p.default(this.host),this.httpTransport=new l.default(this.host,e.encrypted),this.sdkProduct=e.sdkProduct||"unknown",this.sdkVersion=e.sdkVersion||"unknown",this.sdkPlatform=navigator?"ReactNative"===navigator.product?"react-native":"web":"node"}return e.prototype.request=function(e,t){var r=this;return e.tokenProvider?e.tokenProvider.fetchToken(t).then(function(t){return void 0!==e.headers?e.headers.Authorization="Bearer "+t:e.headers=((r={}).Authorization="Bearer "+t,r),e;var r}).then(function(e){return r.makeRequest(e)}):this.makeRequest(e)},e.prototype.subscribeResuming=function(e,t,r,o,s,u){var l=c.replaceMissingListenersWithNoOps(r),p=a.subscribeStrategyListenersFromSubscriptionListeners(l),d=!1;return i.createResumingStrategy(o,h.createTokenProvidingStrategy(f.createTransportStrategy(e,this.websocketTransport,this.logger),this.logger,u),this.logger,s)({onEnd:p.onEnd,onError:p.onError,onEvent:p.onEvent,onOpen:function(e){d||(d=!0,p.onOpen(e)),l.onSubscribe()},onRetrying:p.onRetrying},n({},t,this.infoHeaders()))},e.prototype.subscribeNonResuming=function(e,t,r,o,s){var i=c.replaceMissingListenersWithNoOps(r),l=a.subscribeStrategyListenersFromSubscriptionListeners(i),p=!1;return u.createRetryingStrategy(o,h.createTokenProvidingStrategy(f.createTransportStrategy(e,this.websocketTransport,this.logger),this.logger,s),this.logger)({onEnd:l.onEnd,onError:l.onError,onEvent:l.onEvent,onOpen:function(e){p||(p=!0,l.onOpen(e)),i.onSubscribe()},onRetrying:l.onRetrying},n({},t,this.infoHeaders()))},e.prototype.infoHeaders=function(){return{"X-SDK-Language":"javascript","X-SDK-Platform":this.sdkPlatform,"X-SDK-Product":this.sdkProduct,"X-SDK-Version":this.sdkVersion}},e.prototype.makeRequest=function(e){var t=this;return s.executeNetworkRequest(function(){return t.httpTransport.request(n({},e,{headers:n({},e.headers,t.infoHeaders())}))},e).catch(function(e){throw t.logger.error(e),e})},e}();t.BaseClient=d},function(e,t,r){(function(e){Object.defineProperty(t,"__esModule",{value:!0});var n=r(0);function o(e,t,r){return e.onreadystatechange=function(){4===e.readyState&&(e.status>=200&&e.status<300?t(e.response):0!==e.status?r(n.ErrorResponse.fromXHR(e)):r(new n.NetworkError("No Connection")))},e}t.executeNetworkRequest=function(e,t){return new Promise(function(r,n){!function(e,t){t.json?e.send(JSON.stringify(t.json)):e.send(t.body)}(o(e(),r,n),t)})},t.sendRawRequest=function(t){return new Promise(function(r,n){var s=o(new e.XMLHttpRequest,r,n);if(s.open(t.method.toUpperCase(),t.url,!0),t.headers)for(var i in t.headers)t.headers.hasOwnProperty(i)&&s.setRequestHeader(i,t.headers[i]);s.send(t.body)})}}).call(t,r(1))},function(e,t,r){(function(e){Object.defineProperty(t,"__esModule",{value:!0});var n=r(0),o=r(3);t.createResumingStrategy=function(e,t,r,n){var i=o.createRetryStrategyOptionsOrDefault(e),u=new o.RetryResolution(i,r);return function(e,n){return new s(r,n,t,e,u)}};var s=function(){return function(e,t,r,n,o){var s=this;this.unsubscribe=function(){s.state.unsubscribe()},this.onTransition=function(e){s.state=e},this.state=new i(this.onTransition,e,t,r,n,o)}}(),i=function(){function e(e,t,r,n,o,s,i){var c=this;this.onTransition=e,this.logger=t,this.headers=r,this.nextSubscribeStrategy=n,this.listeners=o,this.retryResolution=s,this.initialEventId=i;var l=i;t.verbose("ResumingSubscription: transitioning to OpeningSubscriptionState"),l&&(r["Last-Event-Id"]=l,t.verbose("ResumingSubscription: initialEventId is "+l)),this.underlyingSubscription=n({onEnd:function(r){e(new h(t,o,r))},onError:function(i){e(new a(i,e,t,r,o,n,s,l))},onEvent:function(e){l=e.eventId,o.onEvent(e)},onOpen:function(r){e(new u(t,r,o,c.underlyingSubscription,e))},onRetrying:o.onRetrying},r)}return e.prototype.unsubscribe=function(){this.onTransition(new c(this.logger)),this.underlyingSubscription.unsubscribe()},e}(),u=function(){function e(e,t,r,n,o){this.logger=e,this.headers=t,this.listeners=r,this.underlyingSubscription=n,this.onTransition=o,e.verbose("ResumingSubscription: transitioning to OpenSubscriptionState"),r.onOpen(t)}return e.prototype.unsubscribe=function(){this.onTransition(new c(this.logger)),this.underlyingSubscription.unsubscribe()},e}(),a=function(){function t(t,r,s,i,a,c,p,f){var d=this;this.onTransition=r,this.logger=s,this.headers=i,this.listeners=a,this.nextSubscribeStrategy=c,this.retryResolution=p,s.verbose("ResumingSubscription: transitioning to ResumingSubscriptionState");var g=function(t,i){a.onRetrying();var u,c=((u=t)instanceof n.ErrorResponse&&(u.headers["Request-Method"]="SUBSCRIBE"),p.attemptRetry(u));c instanceof o.Retry?d.timeout=e.setTimeout(function(){y(i)},c.waitTimeMillis):r(new l(s,a,t))},y=function(e){s.verbose("ResumingSubscription: trying to re-establish the subscription"),e&&(s.verbose("ResumingSubscription: lastEventId: "+e),i["Last-Event-Id"]=e),d.underlyingSubscription=c({onEnd:function(e){r(new h(s,a,e))},onError:function(e){g(e,f)},onEvent:function(e){f=e.eventId,a.onEvent(e)},onOpen:function(e){r(new u(s,e,a,d.underlyingSubscription,r))},onRetrying:a.onRetrying},i)};g(t,f)}return t.prototype.unsubscribe=function(){this.onTransition(new c(this.logger)),e.clearTimeout(this.timeout),this.underlyingSubscription.unsubscribe()},t}(),c=function(){function e(e,t){this.logger=e,e.verbose("ResumingSubscription: transitioning to EndingSubscriptionState")}return e.prototype.unsubscribe=function(){throw new Error("Subscription is already ending")},e}(),h=function(){function e(e,t,r){this.logger=e,this.listeners=t,e.verbose("ResumingSubscription: transitioning to EndedSubscriptionState"),t.onEnd(r)}return e.prototype.unsubscribe=function(){throw new Error("Subscription has already ended")},e}(),l=function(){function e(e,t,r){this.logger=e,this.listeners=t,e.verbose("ResumingSubscription: transitioning to FailedSubscriptionState",r),t.onError(r)}return e.prototype.unsubscribe=function(){throw new Error("Subscription has already ended")},e}()}).call(t,r(1))},function(e,t,r){(function(e){Object.defineProperty(t,"__esModule",{value:!0});var n=r(0),o=r(3);t.createRetryingStrategy=function(e,t,r){var n=o.createRetryStrategyOptionsOrDefault(e),i=new o.RetryResolution(n,r);return function(e,n){return new s(r,n,e,t,i)}};var s=function(){return function(e,t,r,n,o){var s=this;this.unsubscribe=function(){s.state.unsubscribe()},this.onTransition=function(e){s.state=e},this.state=new i(this.onTransition,e,t,r,n,o)}}(),i=function(){function e(e,t,r,n,o,s){var i=this;this.logger=t,this.headers=r,this.listeners=n,this.nextSubscribeStrategy=o,this.retryResolution=s,t.verbose("RetryingSubscription: transitioning to OpeningSubscriptionState"),this.underlyingSubscription=o({onEnd:function(r){return e(new c(t,n,r))},onError:function(i){return e(new u(i,e,t,r,n,o,s))},onEvent:n.onEvent,onOpen:function(r){return e(new a(t,n,r,i.underlyingSubscription,e))},onRetrying:n.onRetrying},r)}return e.prototype.unsubscribe=function(){throw this.underlyingSubscription.unsubscribe(),new Error("Method not implemented.")},e}(),u=function(){function t(t,r,s,i,u,l,p){var f=this;this.onTransition=r,this.logger=s,this.headers=i,this.listeners=u,this.nextSubscribeStrategy=l,this.retryResolution=p,s.verbose("RetryingSubscription: transitioning to RetryingSubscriptionState");var d=function(t){u.onRetrying();var i,a=((i=t)instanceof n.ErrorResponse&&(i.headers["Request-Method"]="SUBSCRIBE"),p.attemptRetry(i));a instanceof o.Retry?f.timeout=e.setTimeout(function(){g()},a.waitTimeMillis):r(new h(s,u,t))},g=function(){s.verbose("RetryingSubscription: trying to re-establish the subscription");var e=l({onEnd:function(e){return r(new c(s,u,e))},onError:function(e){return d(e)},onEvent:u.onEvent,onOpen:function(t){r(new a(s,u,t,e,r))},onRetrying:u.onRetrying},i)};d(t)}return t.prototype.unsubscribe=function(){e.clearTimeout(this.timeout),this.onTransition(new c(this.logger,this.listeners))},t}(),a=function(){function e(e,t,r,n,o){this.logger=e,this.listeners=t,this.headers=r,this.underlyingSubscription=n,this.onTransition=o,e.verbose("RetryingSubscription: transitioning to OpenSubscriptionState"),t.onOpen(r)}return e.prototype.unsubscribe=function(){this.underlyingSubscription.unsubscribe(),this.onTransition(new c(this.logger,this.listeners))},e}(),c=function(){function e(e,t,r){this.logger=e,this.listeners=t,e.verbose("RetryingSubscription: transitioning to EndedSubscriptionState"),t.onEnd(r)}return e.prototype.unsubscribe=function(){throw new Error("Subscription has already ended")},e}(),h=function(){function e(e,t,r){this.logger=e,this.listeners=t,e.verbose("RetryingSubscription: transitioning to FailedSubscriptionState",r),t.onError(r)}return e.prototype.unsubscribe=function(){throw new Error("Subscription has already ended")},e}()}).call(t,r(1))},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});var n=r(0);t.createTokenProvidingStrategy=function(e,t,r){return r?function(n,s){return new o(t,n,s,r,e)}:e};var o=function(){function e(e,t,r,n,o){var u=this;this.logger=e,this.listeners=t,this.headers=r,this.tokenProvider=n,this.nextSubscribeStrategy=o,this.unsubscribe=function(){u.state.unsubscribe(),u.state=new i(u.logger)},this.state=new s(e,r,o),this.subscribe()}return e.prototype.subscribe=function(){var e=this;this.tokenProvider.fetchToken().then(function(t){var r=Object.assign({},e.listeners);e.state.subscribe(t,{onEnd:function(t){e.state=new i(e.logger),r.onEnd(t)},onError:function(n){e.isTokenExpiredError(n)?(e.tokenProvider.clearToken(t),e.subscribe()):(e.state=new i(e.logger),r.onError(n))},onEvent:e.listeners.onEvent,onOpen:e.listeners.onOpen})}).catch(function(t){e.logger.debug("TokenProvidingSubscription: error when fetching token:",t),e.state=new i(e.logger),e.listeners.onError(t)})},e.prototype.isTokenExpiredError=function(e){return e instanceof n.ErrorResponse&&401===e.statusCode&&"authentication/expired"===e.info},e}(),s=function(){function e(e,t,r){this.logger=e,this.headers=t,this.nextSubscribeStrategy=r,e.verbose("TokenProvidingSubscription: transitioning to ActiveState")}return e.prototype.subscribe=function(e,t){var r=this;this.putTokenIntoHeader(e),this.underlyingSubscription=this.nextSubscribeStrategy({onEnd:function(e){r.logger.verbose("TokenProvidingSubscription: subscription ended"),t.onEnd(e)},onError:function(e){r.logger.verbose("TokenProvidingSubscription: subscription errored:",e),t.onError(e)},onEvent:t.onEvent,onOpen:function(e){r.logger.verbose("TokenProvidingSubscription: subscription opened"),t.onOpen(e)},onRetrying:t.onRetrying},this.headers)},e.prototype.unsubscribe=function(){this.underlyingSubscription.unsubscribe()},e.prototype.putTokenIntoHeader=function(e){this.headers.Authorization="Bearer "+e,this.logger.verbose("TokenProvidingSubscription: token fetched: "+e)},e}(),i=function(){function e(e){this.logger=e,e.verbose("TokenProvidingSubscription: transitioning to InactiveState")}return e.prototype.subscribe=function(e,t){this.logger.verbose("TokenProvidingSubscription: subscribe called in Inactive state; doing nothing")},e.prototype.unsubscribe=function(){this.logger.verbose("TokenProvidingSubscription: unsubscribe called in Inactive state; doing nothing")},e}()},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0}),t.createTransportStrategy=function(e,t,r){return function(r,n){return t.subscribe(e,r,n)}}},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0}),t.HOST_BASE="pusherplatform.io"},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});var n=r(4);t.BaseClient=n.BaseClient;var o=r(10);t.HOST_BASE=o.HOST_BASE;var s=r(16);t.Instance=s.default;var i=r(2);t.ConsoleLogger=i.ConsoleLogger,t.EmptyLogger=i.EmptyLogger;var u=r(0);t.ErrorResponse=u.ErrorResponse,t.NetworkError=u.NetworkError,t.responseToHeadersObject=u.responseToHeadersObject,t.XhrReadyState=u.XhrReadyState;var a=r(5);t.executeNetworkRequest=a.executeNetworkRequest,t.sendRawRequest=a.sendRawRequest;var c=r(6);t.createResumingStrategy=c.createResumingStrategy;var h=r(3);t.createRetryStrategyOptionsOrDefault=h.createRetryStrategyOptionsOrDefault,t.DoNotRetry=h.DoNotRetry,t.Retry=h.Retry,t.RetryResolution=h.RetryResolution;var l=r(7);t.createRetryingStrategy=l.createRetryingStrategy;var p=r(8);t.createTokenProvidingStrategy=p.createTokenProvidingStrategy;var f=r(9);t.createTransportStrategy=f.createTransportStrategy,t.default={BaseClient:n.BaseClient,ConsoleLogger:i.ConsoleLogger,EmptyLogger:i.EmptyLogger,Instance:s.default}},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0}),t.subscribeStrategyListenersFromSubscriptionListeners=function(e){return{onEnd:e.onEnd,onError:e.onError,onEvent:e.onEvent,onOpen:e.onOpen,onRetrying:e.onRetrying}}},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0}),t.replaceMissingListenersWithNoOps=function(e){return{onEnd:e.onEnd||function(e){},onError:e.onError||function(e){},onEvent:e.onEvent||function(e){},onOpen:e.onOpen||function(e){},onRetrying:e.onRetrying||function(){},onSubscribe:e.onSubscribe||function(){}}}},function(e,t,r){(function(e){Object.defineProperty(t,"__esModule",{value:!0});var n,o=r(0);!function(e){e[e.UNOPENED=0]="UNOPENED",e[e.OPENING=1]="OPENING",e[e.OPEN=2]="OPEN",e[e.ENDING=3]="ENDING",e[e.ENDED=4]="ENDED"}(n=t.HttpTransportState||(t.HttpTransportState={}));var s=function(){function t(e,t){var r=this;return this.gotEOS=!1,this.lastNewlineIndex=0,this.state=n.UNOPENED,this.xhr=e,this.listeners=t,this.xhr.onreadystatechange=function(){switch(r.xhr.readyState){case o.XhrReadyState.UNSENT:case o.XhrReadyState.OPENED:case o.XhrReadyState.HEADERS_RECEIVED:r.assertStateIsIn(n.OPENING);break;case o.XhrReadyState.LOADING:r.onLoading();break;case o.XhrReadyState.DONE:r.onDone()}},this.state=n.OPENING,this.xhr.send(),this}return t.prototype.unsubscribe=function(){this.state=n.ENDED,this.xhr.abort(),this.listeners.onEnd&&this.listeners.onEnd(null)},t.prototype.onLoading=function(){if(this.assertStateIsIn(n.OPENING,n.OPEN,n.ENDING),200===this.xhr.status){this.state===n.OPENING&&(this.state=n.OPEN,e.console.log(o.responseToHeadersObject(this.xhr.getAllResponseHeaders())),this.listeners.onOpen&&this.listeners.onOpen(o.responseToHeadersObject(this.xhr.getAllResponseHeaders()))),this.assertStateIsIn(n.OPEN);var t=this.onChunk();this.assertStateIsIn(n.OPEN,n.ENDING),t&&(this.state=n.ENDED,t instanceof o.ErrorResponse&&204!==t.statusCode&&this.listeners.onError&&this.listeners.onError(t))}},t.prototype.onDone=function(){if(200===this.xhr.status){this.state===n.OPENING&&(this.state=n.OPEN,this.listeners.onOpen&&this.listeners.onOpen(o.responseToHeadersObject(this.xhr.getAllResponseHeaders()))),this.assertStateIsIn(n.OPEN,n.ENDING);var e=this.onChunk();e?(this.state=n.ENDED,204===e.statusCode?this.listeners.onEnd&&this.listeners.onEnd(null):this.listeners.onError&&this.listeners.onError(e)):this.state<=n.ENDING?this.listeners.onError&&this.listeners.onError(new Error("HTTP response ended without receiving EOS message")):this.listeners.onEnd&&this.listeners.onEnd(null)}else{if(this.assertStateIsIn(n.OPENING,n.OPEN,n.ENDED),this.state===n.ENDED)return;0===this.xhr.status?this.listeners.onError&&this.listeners.onError(new o.NetworkError("Connection lost.")):this.listeners.onError&&this.listeners.onError(o.ErrorResponse.fromXHR(this.xhr))}},t.prototype.onChunk=function(){this.assertStateIsIn(n.OPEN);var e=this.xhr.responseText,t=e.lastIndexOf("\n");if(t>this.lastNewlineIndex){var r=e.slice(this.lastNewlineIndex,t).split("\n");this.lastNewlineIndex=t;for(var o=0,s=r;o<s.length;o++){var i=s[o];if(0!==i.length){var u=JSON.parse(i),a=this.onMessage(u);if(null!=a)return a}}}},t.prototype.assertStateIsIn=function(){for(var t=this,r=[],o=0;o<arguments.length;o++)r[o]=arguments[o];if(!r.some(function(e){return e===t.state})){var s=r.map(function(e){return n[e]}).join(", "),i=n[this.state];e.console.warn("Expected this.state to be one of ["+s+"] but it is "+i)}},t.prototype.onMessage=function(e){switch(this.assertStateIsIn(n.OPEN),this.verifyMessage(e),e[0]){case 0:return null;case 1:return this.onEventMessage(e);case 255:return this.onEOSMessage(e);default:return new Error("Unknown Message: "+JSON.stringify(e))}},t.prototype.onEventMessage=function(e){if(this.assertStateIsIn(n.OPEN),4!==e.length)return new Error("Event message has "+e.length+" elements (expected 4)");e[0];var t=e[1],r=e[2],o=e[3];return"string"!=typeof t?new Error("Invalid event ID in message: "+JSON.stringify(e)):"object"!=typeof r||Array.isArray(r)?new Error("Invalid event headers in message: "+JSON.stringify(e)):(this.listeners.onEvent&&this.listeners.onEvent({body:o,headers:r,eventId:t}),null)},t.prototype.onEOSMessage=function(e){if(this.assertStateIsIn(n.OPEN),4!==e.length)return new Error("EOS message has "+e.length+" elements (expected 4)");e[0];var t=e[1],r=e[2],s=e[3];return"number"!=typeof t?new Error("Invalid EOS Status Code"):"object"!=typeof r||Array.isArray(r)?new Error("Invalid EOS ElementsHeaders"):(this.state=n.ENDING,new o.ErrorResponse(t,r,s))},t.prototype.verifyMessage=function(e){return this.gotEOS?new Error("Got another message after EOS message"):Array.isArray(e)?e.length<1?new Error("Message is empty array"):void 0:new Error("Message is not an array")},t}(),i=function(){function t(e,t){void 0===t&&(t=!0),this.baseURL=(t?"https":"http")+"://"+e}return t.prototype.request=function(e){return this.createXHR(this.baseURL,e)},t.prototype.subscribe=function(e,t,r){var n={headers:r,method:"SUBSCRIBE",path:e};return new s(this.createXHR(this.baseURL,n),t)},t.prototype.createXHR=function(t,r){var n=new e.XMLHttpRequest,o=t+"/"+r.path.replace(/^\/+/,"");if(n.open(r.method.toUpperCase(),o,!0),n=this.setJSONHeaderIfAppropriate(n,r),r.jwt&&n.setRequestHeader("authorization","Bearer "+r.jwt),r.headers)for(var s in r.headers)r.headers.hasOwnProperty(s)&&n.setRequestHeader(s,r.headers[s]);return n},t.prototype.setJSONHeaderIfAppropriate=function(e,t){return t.json&&e.setRequestHeader("content-type","application/json"),e},t}();t.default=i}).call(t,r(1))},function(e,t,r){(function(e){var n=this&&this.__assign||Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e};Object.defineProperty(t,"__esModule",{value:!0});var o,s=r(0);!function(e){e[e.Connecting=0]="Connecting",e[e.Open=1]="Open",e[e.Closing=2]="Closing",e[e.Closed=3]="Closed"}(o=t.WSReadyState||(t.WSReadyState={}));var i=function(){function e(){this.subscriptions={}}return e.prototype.add=function(e,t,r,n){return this.subscriptions[e]={headers:n,listeners:r,path:t},e},e.prototype.has=function(e){return void 0!==this.subscriptions[e]},e.prototype.isEmpty=function(){return 0===Object.keys(this.subscriptions).length},e.prototype.remove=function(e){return delete this.subscriptions[e]},e.prototype.get=function(e){return this.subscriptions[e]},e.prototype.getAll=function(){return this.subscriptions},e.prototype.getAllAsArray=function(){var e=this;return Object.keys(this.subscriptions).map(function(t){return n({subID:parseInt(t,10)},e.subscriptions[parseInt(t,10)])})},e.prototype.removeAll=function(){this.subscriptions={}},e}(),u=function(){function e(e,t){this.wsTransport=e,this.subID=t}return e.prototype.unsubscribe=function(){this.wsTransport.unsubscribe(this.subID)},e}(),a=function(){function t(e){this.webSocketPath="/ws",this.forcedClose=!1,this.closedError=null,this.baseURL="wss://"+e+this.webSocketPath,this.lastSubscriptionID=0,this.subscriptions=new i,this.pendingSubscriptions=new i,this.connect()}return t.prototype.subscribe=function(e,t,r){this.tryReconnectIfNeeded();var n=this.lastSubscriptionID++;return this.socket.readyState!==o.Open?(this.pendingSubscriptions.add(n,e,t,r),new u(this,n)):(this.subscriptions.add(n,e,t,r),this.sendMessage(this.getMessage(100,n,e,r)),new u(this,n))},t.prototype.unsubscribe=function(e){this.sendMessage(this.getMessage(198,e));var t=this.subscriptions.get(e);t.listeners.onEnd&&t.listeners.onEnd(null),this.subscriptions.remove(e)},t.prototype.connect=function(){var t=this;this.close(),this.forcedClose=!1,this.closedError=null,this.socket=new e.WebSocket(this.baseURL),this.socket.onopen=function(r){t.pendingSubscriptions.getAllAsArray().forEach(function(e){var r=e.subID,n=e.path,o=e.listeners,s=e.headers;t.subscribePending(n,o,s,r)}),t.pendingSubscriptions.removeAll(),t.pingInterval=e.setInterval(function(){if(!t.pongTimeout){var r=(new Date).getTime();1e4>r-t.lastMessageReceivedTimestamp||(t.sendMessage(t.getMessage(16,r)),t.lastSentPingID=r,t.pongTimeout=e.setTimeout(function(){1e4>(new Date).getTime()-t.lastMessageReceivedTimestamp?t.pongTimeout=null:t.close(new s.NetworkError("Pong response wasn't received until timeout."))},1e4))}},3e4)},this.socket.onmessage=function(e){return t.receiveMessage(e)},this.socket.onerror=function(e){t.close(new s.NetworkError("Connection was lost."))},this.socket.onclose=function(e){if(t.forcedClose){var r=t.closedError?function(e){e.listeners.onError&&e.listeners.onError(t.closedError)}:function(e){e.listeners.onEnd&&e.listeners.onEnd(null)},n=!1===t.pendingSubscriptions.isEmpty()?t.pendingSubscriptions:t.subscriptions;n.getAllAsArray().forEach(r),n.removeAll(),t.closedError&&t.tryReconnectIfNeeded()}else t.tryReconnectIfNeeded()}},t.prototype.close=function(t){this.socket instanceof e.WebSocket&&(this.forcedClose=!0,this.closedError=t,this.socket.close(),e.clearTimeout(this.pingInterval),e.clearTimeout(this.pongTimeout),delete this.pongTimeout,this.lastSentPingID=null)},t.prototype.tryReconnectIfNeeded=function(){this.socket.readyState===o.Closed&&this.connect()},t.prototype.subscribePending=function(t,r,n,o){void 0!==o?(this.subscriptions.add(o,t,r,n),this.sendMessage(this.getMessage(100,o,t,n))):e.console.logger.debug("Subscription to path "+t+" has an undefined ID")},t.prototype.getMessage=function(e,t,r,n){return[e,t,r,n]},t.prototype.sendMessage=function(t){if(this.socket.readyState!==o.Open)return e.console.warn("Can't send in \""+o[this.socket.readyState]+'" state');this.socket.send(JSON.stringify(t))},t.prototype.subscription=function(e){return this.subscriptions.get(e)},t.prototype.receiveMessage=function(e){var t;this.lastMessageReceivedTimestamp=(new Date).getTime();try{t=JSON.parse(e.data)}catch(t){return void this.close(new Error("Message is not valid JSON format. Getting "+e.data))}var r=this.validateMessage(t);if(r)this.close(new Error(r.message));else{var n=t.shift();switch(n){case 17:return void this.onPongMessage(t);case 16:return void this.onPingMessage(t);case 99:return void this.onCloseMessage(t)}var o=t.shift(),s=this.subscription(o);if(s){var i=s.listeners;switch(n){case 101:this.onOpenMessage(t,o,i);break;case 102:this.onEventMessage(t,i);break;case 199:this.onEOSMessage(t,o,i);break;default:this.close(new Error("Received non existing type of message."))}}else this.close(new Error('Received message for non existing subscription id: "'+o+'"'))}},t.prototype.validateMessage=function(e){return Array.isArray(e)?e.length<1?new Error("Message is empty array: "+JSON.stringify(e)):null:new Error("Message is expected to be an array. Getting: "+JSON.stringify(e))},t.prototype.onOpenMessage=function(e,t,r){r.onOpen&&r.onOpen(e[1])},t.prototype.onEventMessage=function(e,t){if(3!==e.length)return new Error("Event message has "+e.length+" elements (expected 4)");var r=e[0],n=e[1],o=e[2];return"string"!=typeof r?new Error("Invalid event ID in message: "+JSON.stringify(e)):"object"!=typeof n||Array.isArray(n)?new Error("Invalid event headers in message: "+JSON.stringify(e)):void(t.onEvent&&t.onEvent({eventId:r,headers:n,body:o}))},t.prototype.onEOSMessage=function(e,t,r){if(this.subscriptions.remove(t),3===e.length){var n=e[0],o=e[1],i=e[2];"number"==typeof n?"object"!=typeof o||Array.isArray(o)?r.onError&&r.onError(new Error("Invalid EOS ElementsHeaders")):204!==n?r.onError&&r.onError(new s.ErrorResponse(n,o,i)):r.onEnd&&r.onEnd(null):r.onError&&r.onError(new Error("Invalid EOS Status Code"))}else r.onError&&r.onError(new Error("EOS message has "+e.length+" elements (expected 4)"))},t.prototype.onCloseMessage=function(e){var t=e[0],r=e[1];e[2];return"number"!=typeof t?this.close(new Error("Close message: Invalid EOS Status Code")):"object"!=typeof r||Array.isArray(r)?this.close(new Error("Close message: Invalid EOS ElementsHeaders")):void this.close()},t.prototype.onPongMessage=function(t){var r=t[0];this.lastSentPingID!==r&&this.close(new s.NetworkError("Didn't received pong with proper ID")),e.clearTimeout(this.pongTimeout),delete this.pongTimeout,this.lastSentPingID=null},t.prototype.onPingMessage=function(e){var t=e[0];this.sendMessage(this.getMessage(17,t))},t}();t.default=a}).call(t,r(1))},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});var n=r(4),o=r(10),s=r(2),i=function(){function e(e){if(!e.locator)throw new Error("Expected `locator` property in Instance options!");var t=e.locator.split(":");if(3!==t.length)throw new Error("The instance locator supplied is invalid. Did you copy it correctly from the Pusher dashboard?");if(!e.serviceName)throw new Error("Expected `serviceName` property in Instance options!");if(!e.serviceVersion)throw new Error("Expected `serviceVersion` property in Instance options!");this.platformVersion=t[0],this.cluster=t[1],this.id=t[2],this.serviceName=e.serviceName,this.serviceVersion=e.serviceVersion,this.host=e.host||this.cluster+"."+o.HOST_BASE,this.logger=e.logger||new s.ConsoleLogger,this.client=e.client||new n.BaseClient({encrypted:e.encrypted,host:this.host,logger:this.logger}),this.tokenProvider=e.tokenProvider}return e.prototype.request=function(e,t){return e.path=this.absPath(e.path),null!=e.headers&&void 0!==e.headers||(e.headers={}),e.tokenProvider=e.tokenProvider||this.tokenProvider,this.client.request(e,t)},e.prototype.subscribeNonResuming=function(e){var t=e.headers||{},r=e.retryStrategyOptions||{},n=e.tokenProvider||this.tokenProvider;return this.client.subscribeNonResuming(this.absPath(e.path),t,e.listeners,r,n)},e.prototype.subscribeResuming=function(e){var t=e.headers||{},r=e.retryStrategyOptions||{},n=e.tokenProvider||this.tokenProvider;return this.client.subscribeResuming(this.absPath(e.path),t,e.listeners,r,e.initialEventId,n)},e.prototype.absPath=function(e){return("/services/"+this.serviceName+"/"+this.serviceVersion+"/"+this.id+"/"+e).replace(/\/+/g,"/").replace(/\/+$/,"")},e}();t.default=i}])});unwrapExports(pusherPlatform);var reactNative=pusherPlatform,reactNative_1=reactNative.BaseClient,reactNative_2=reactNative.HOST_BASE,reactNative_3=reactNative.Instance,reactNative_4=reactNative.sendRawRequest;function _isPlaceholder(e){return null!=e&&"object"==typeof e&&!0===e["@@functional/placeholder"]}function _curry1(e){return function t(r){return 0===arguments.length||_isPlaceholder(r)?t:e.apply(this,arguments)}}var always=_curry1(function(e){return function(){return e}}),F=always(!1),T=always(!0);function _curry2(e){return function t(r,n){switch(arguments.length){case 0:return t;case 1:return _isPlaceholder(r)?t:_curry1(function(t){return e(r,t)});default:return _isPlaceholder(r)&&_isPlaceholder(n)?t:_isPlaceholder(r)?_curry1(function(t){return e(t,n)}):_isPlaceholder(n)?_curry1(function(t){return e(r,t)}):e(r,n)}}}var add=_curry2(function(e,t){return Number(e)+Number(t)});function _concat(e,t){var r;e=e||[],t=t||[];var n=e.length,o=t.length,s=[];for(r=0;r<n;)s[s.length]=e[r],r+=1;for(r=0;r<o;)s[s.length]=t[r],r+=1;return s}function _arity(e,t){switch(e){case 0:return function(){return t.apply(this,arguments)};case 1:return function(e){return t.apply(this,arguments)};case 2:return function(e,r){return t.apply(this,arguments)};case 3:return function(e,r,n){return t.apply(this,arguments)};case 4:return function(e,r,n,o){return t.apply(this,arguments)};case 5:return function(e,r,n,o,s){return t.apply(this,arguments)};case 6:return function(e,r,n,o,s,i){return t.apply(this,arguments)};case 7:return function(e,r,n,o,s,i,u){return t.apply(this,arguments)};case 8:return function(e,r,n,o,s,i,u,a){return t.apply(this,arguments)};case 9:return function(e,r,n,o,s,i,u,a,c){return t.apply(this,arguments)};case 10:return function(e,r,n,o,s,i,u,a,c,h){return t.apply(this,arguments)};default:throw new Error("First argument to _arity must be a non-negative integer no greater than ten")}}function _curryN(e,t,r){return function(){for(var n=[],o=0,s=e,i=0;i<t.length||o<arguments.length;){var u;i<t.length&&(!_isPlaceholder(t[i])||o>=arguments.length)?u=t[i]:(u=arguments[o],o+=1),n[i]=u,_isPlaceholder(u)||(s-=1),i+=1}return s<=0?r.apply(this,n):_arity(s,_curryN(e,n,r))}}var curryN=_curry2(function(e,t){return 1===e?_curry1(t):_arity(e,_curryN(e,[],t))});function _curry3(e){return function t(r,n,o){switch(arguments.length){case 0:return t;case 1:return _isPlaceholder(r)?t:_curry2(function(t,n){return e(r,t,n)});case 2:return _isPlaceholder(r)&&_isPlaceholder(n)?t:_isPlaceholder(r)?_curry2(function(t,r){return e(t,n,r)}):_isPlaceholder(n)?_curry2(function(t,n){return e(r,t,n)}):_curry1(function(t){return e(r,n,t)});default:return _isPlaceholder(r)&&_isPlaceholder(n)&&_isPlaceholder(o)?t:_isPlaceholder(r)&&_isPlaceholder(n)?_curry2(function(t,r){return e(t,r,o)}):_isPlaceholder(r)&&_isPlaceholder(o)?_curry2(function(t,r){return e(t,n,r)}):_isPlaceholder(n)&&_isPlaceholder(o)?_curry2(function(t,n){return e(r,t,n)}):_isPlaceholder(r)?_curry1(function(t){return e(t,n,o)}):_isPlaceholder(n)?_curry1(function(t){return e(r,t,o)}):_isPlaceholder(o)?_curry1(function(t){return e(r,n,t)}):e(r,n,o)}}}var _isArray=Array.isArray||function(e){return null!=e&&e.length>=0&&"[object Array]"===Object.prototype.toString.call(e)};function _isTransformer(e){return"function"==typeof e["@@transducer/step"]}function _dispatchable(e,t,r){return function(){if(0===arguments.length)return r();var n=Array.prototype.slice.call(arguments,0),o=n.pop();if(!_isArray(o)){for(var s=0;s<e.length;){if("function"==typeof o[e[s]])return o[e[s]].apply(o,n);s+=1}if(_isTransformer(o))return t.apply(null,n)(o)}return r.apply(this,arguments)}}var _xfBase={init:function(){return this.xf["@@transducer/init"]()},result:function(e){return this.xf["@@transducer/result"](e)}},max=_curry2(function(e,t){return t>e?t:e});function _map(e,t){for(var r=0,n=t.length,o=Array(n);r<n;)o[r]=e(t[r]),r+=1;return o}function _isString(e){return"[object String]"===Object.prototype.toString.call(e)}var _isArrayLike=_curry1(function(e){return!!_isArray(e)||!!e&&("object"==typeof e&&(!_isString(e)&&(1===e.nodeType?!!e.length:0===e.length||e.length>0&&(e.hasOwnProperty(0)&&e.hasOwnProperty(e.length-1)))))}),XWrap=function(){function e(e){this.f=e}return e.prototype["@@transducer/init"]=function(){throw new Error("init not implemented on XWrap")},e.prototype["@@transducer/result"]=function(e){return e},e.prototype["@@transducer/step"]=function(e,t){return this.f(e,t)},e}();function _xwrap(e){return new XWrap(e)}var bind=_curry2(function(e,t){return _arity(e.length,function(){return e.apply(t,arguments)})});function _arrayReduce(e,t,r){for(var n=0,o=r.length;n<o;){if((t=e["@@transducer/step"](t,r[n]))&&t["@@transducer/reduced"]){t=t["@@transducer/value"];break}n+=1}return e["@@transducer/result"](t)}function _iterableReduce(e,t,r){for(var n=r.next();!n.done;){if((t=e["@@transducer/step"](t,n.value))&&t["@@transducer/reduced"]){t=t["@@transducer/value"];break}n=r.next()}return e["@@transducer/result"](t)}function _methodReduce(e,t,r,n){return e["@@transducer/result"](r[n](bind(e["@@transducer/step"],e),t))}var symIterator="undefined"!=typeof Symbol?Symbol.iterator:"@@iterator";function _reduce(e,t,r){if("function"==typeof e&&(e=_xwrap(e)),_isArrayLike(r))return _arrayReduce(e,t,r);if("function"==typeof r["fantasy-land/reduce"])return _methodReduce(e,t,r,"fantasy-land/reduce");if(null!=r[symIterator])return _iterableReduce(e,t,r[symIterator]());if("function"==typeof r.next)return _iterableReduce(e,t,r);if("function"==typeof r.reduce)return _methodReduce(e,t,r,"reduce");throw new TypeError("reduce: list must be array or iterable")}var XMap=function(){function e(e,t){this.xf=t,this.f=e}return e.prototype["@@transducer/init"]=_xfBase.init,e.prototype["@@transducer/result"]=_xfBase.result,e.prototype["@@transducer/step"]=function(e,t){return this.xf["@@transducer/step"](e,this.f(t))},e}(),_xmap=_curry2(function(e,t){return new XMap(e,t)});function _has(e,t){return Object.prototype.hasOwnProperty.call(t,e)}var toString=Object.prototype.toString,_isArguments=function(){return"[object Arguments]"===toString.call(arguments)?function(e){return"[object Arguments]"===toString.call(e)}:function(e){return _has("callee",e)}},hasEnumBug=!{toString:null}.propertyIsEnumerable("toString"),nonEnumerableProps=["constructor","valueOf","isPrototypeOf","toString","propertyIsEnumerable","hasOwnProperty","toLocaleString"],hasArgsEnumBug=function(){return arguments.propertyIsEnumerable("length")}(),contains=function(e,t){for(var r=0;r<e.length;){if(e[r]===t)return!0;r+=1}return!1},_keys="function"!=typeof Object.keys||hasArgsEnumBug?function(e){if(Object(e)!==e)return[];var t,r,n=[],o=hasArgsEnumBug&&_isArguments(e);for(t in e)!_has(t,e)||o&&"length"===t||(n[n.length]=t);if(hasEnumBug)for(r=nonEnumerableProps.length-1;r>=0;)_has(t=nonEnumerableProps[r],e)&&!contains(n,t)&&(n[n.length]=t),r-=1;return n}:function(e){return Object(e)!==e?[]:Object.keys(e)},keys=_curry1(_keys),map=_curry2(_dispatchable(["fantasy-land/map","map"],_xmap,function(e,t){switch(Object.prototype.toString.call(t)){case"[object Function]":return curryN(t.length,function(){return e.call(this,t.apply(this,arguments))});case"[object Object]":return _reduce(function(r,n){return r[n]=e(t[n]),r},{},keys(t));default:return _map(e,t)}})),path=_curry2(function(e,t){for(var r=t,n=0;n<e.length;){if(null==r)return;r=r[e[n]],n+=1}return r}),prop=_curry2(function(e,t){return path([e],t)}),pluck=_curry2(function(e,t){return map(prop(e),t)}),reduce=_curry3(_reduce),ap=_curry2(function(e,t){return"function"==typeof t["fantasy-land/ap"]?t["fantasy-land/ap"](e):"function"==typeof e.ap?e.ap(t):"function"==typeof e?function(r){return e(r)(t(r))}:_reduce(function(e,r){return _concat(e,map(r,t))},[],e)}),append=_curry2(function(e,t){return _concat(t,[e])}),values=_curry1(function(e){for(var t=keys(e),r=t.length,n=[],o=0;o<r;)n[o]=e[t[o]],o+=1;return n});function _isFunction(e){return"[object Function]"===Object.prototype.toString.call(e)}var liftN=_curry2(function(e,t){var r=curryN(e,t);return curryN(e,function(){return _reduce(ap,map(r,arguments[0]),Array.prototype.slice.call(arguments,1))})}),lift=_curry1(function(e){return liftN(e.length,e)}),curry=_curry1(function(e){return curryN(e.length,e)}),call=curry(function(e){return e.apply(this,Array.prototype.slice.call(arguments,1))});function _makeFlat(e){return function t(r){for(var n,o,s,i=[],u=0,a=r.length;u<a;){if(_isArrayLike(r[u]))for(s=0,o=(n=e?t(r[u]):r[u]).length;s<o;)i[i.length]=n[s],s+=1;else i[i.length]=r[u];u+=1}return i}}function _forceReduced(e){return{"@@transducer/value":e,"@@transducer/reduced":!0}}var preservingReduced=function(e){return{"@@transducer/init":_xfBase.init,"@@transducer/result":function(t){return e["@@transducer/result"](t)},"@@transducer/step":function(t,r){var n=e["@@transducer/step"](t,r);return n["@@transducer/reduced"]?_forceReduced(n):n}}},_flatCat=function(e){var t=preservingReduced(e);return{"@@transducer/init":_xfBase.init,"@@transducer/result":function(e){return t["@@transducer/result"](e)},"@@transducer/step":function(e,r){return _isArrayLike(r)?_reduce(t,e,r):_reduce(t,e,[r])}}},_xchain=_curry2(function(e,t){return map(e,_flatCat(t))}),chain=_curry2(_dispatchable(["fantasy-land/chain","chain"],_xchain,function(e,t){return"function"==typeof t?function(r){return e(t(r))(r)}:_makeFlat(!1)(map(e,t))})),type=_curry1(function(e){return null===e?"Null":void 0===e?"Undefined":Object.prototype.toString.call(e).slice(8,-1)}),not=_curry1(function(e){return!e}),complement=lift(not);function _pipe(e,t){return function(){return t.call(this,e.apply(this,arguments))}}function _checkForMethod(e,t){return function(){var r=arguments.length;if(0===r)return t();var n=arguments[r-1];return _isArray(n)||"function"!=typeof n[e]?t.apply(this,arguments):n[e].apply(n,Array.prototype.slice.call(arguments,0,r-1))}}var slice=_curry3(_checkForMethod("slice",function(e,t,r){return Array.prototype.slice.call(r,e,t)})),tail=_curry1(_checkForMethod("tail",slice(1,1/0)));function pipe(){if(0===arguments.length)throw new Error("pipe requires at least one argument");return _arity(arguments[0].length,reduce(_pipe,arguments[0],tail(arguments)))}var reverse=_curry1(function(e){return _isString(e)?e.split("").reverse().join(""):Array.prototype.slice.call(e,0).reverse()});function compose(){if(0===arguments.length)throw new Error("compose requires at least one argument");return pipe.apply(this,reverse(arguments))}function _arrayFromIterator(e){for(var t,r=[];!(t=e.next()).done;)r.push(t.value);return r}function _containsWith(e,t,r){for(var n=0,o=r.length;n<o;){if(e(t,r[n]))return!0;n+=1}return!1}function _functionName(e){var t=String(e).match(/^function (\w*)/);return null==t?"":t[1]}var identical=_curry2(function(e,t){return e===t?0!==e||1/e==1/t:e!=e&&t!=t});function _uniqContentEquals(e,t,r,n){var o=_arrayFromIterator(e);function s(e,t){return _equals(e,t,r.slice(),n.slice())}return!_containsWith(function(e,t){return!_containsWith(s,t,e)},_arrayFromIterator(t),o)}function _equals(e,t,r,n){if(identical(e,t))return!0;var o=type(e);if(o!==type(t))return!1;if(null==e||null==t)return!1;if("function"==typeof e["fantasy-land/equals"]||"function"==typeof t["fantasy-land/equals"])return"function"==typeof e["fantasy-land/equals"]&&e["fantasy-land/equals"](t)&&"function"==typeof t["fantasy-land/equals"]&&t["fantasy-land/equals"](e);if("function"==typeof e.equals||"function"==typeof t.equals)return"function"==typeof e.equals&&e.equals(t)&&"function"==typeof t.equals&&t.equals(e);switch(o){case"Arguments":case"Array":case"Object":if("function"==typeof e.constructor&&"Promise"===_functionName(e.constructor))return e===t;break;case"Boolean":case"Number":case"String":if(typeof e!=typeof t||!identical(e.valueOf(),t.valueOf()))return!1;break;case"Date":if(!identical(e.valueOf(),t.valueOf()))return!1;break;case"Error":return e.name===t.name&&e.message===t.message;case"RegExp":if(e.source!==t.source||e.global!==t.global||e.ignoreCase!==t.ignoreCase||e.multiline!==t.multiline||e.sticky!==t.sticky||e.unicode!==t.unicode)return!1}for(var s=r.length-1;s>=0;){if(r[s]===e)return n[s]===t;s-=1}switch(o){case"Map":return e.size===t.size&&_uniqContentEquals(e.entries(),t.entries(),r.concat([e]),n.concat([t]));case"Set":return e.size===t.size&&_uniqContentEquals(e.values(),t.values(),r.concat([e]),n.concat([t]));case"Arguments":case"Array":case"Object":case"Boolean":case"Number":case"String":case"Date":case"Error":case"RegExp":case"Int8Array":case"Uint8Array":case"Uint8ClampedArray":case"Int16Array":case"Uint16Array":case"Int32Array":case"Uint32Array":case"Float32Array":case"Float64Array":case"ArrayBuffer":break;default:return!1}var i=keys(e);if(i.length!==keys(t).length)return!1;var u=r.concat([e]),a=n.concat([t]);for(s=i.length-1;s>=0;){var c=i[s];if(!_has(c,t)||!_equals(t[c],e[c],u,a))return!1;s-=1}return!0}var equals=_curry2(function(e,t){return _equals(e,t,[],[])});function _indexOf(e,t,r){var n,o;if("function"==typeof e.indexOf)switch(typeof t){case"number":if(0===t){for(n=1/t;r<e.length;){if(0===(o=e[r])&&1/o===n)return r;r+=1}return-1}if(t!=t){for(;r<e.length;){if("number"==typeof(o=e[r])&&o!=o)return r;r+=1}return-1}return e.indexOf(t,r);case"string":case"boolean":case"function":case"undefined":return e.indexOf(t,r);case"object":if(null===t)return e.indexOf(t,r)}for(;r<e.length;){if(equals(e[r],t))return r;r+=1}return-1}function _contains(e,t){return _indexOf(t,e,0)>=0}function _quote(e){return'"'+e.replace(/\\/g,"\\\\").replace(/[\b]/g,"\\b").replace(/\f/g,"\\f").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t").replace(/\v/g,"\\v").replace(/\0/g,"\\0").replace(/"/g,'\\"')+'"'}var pad=function(e){return(e<10?"0":"")+e},_toISOString="function"==typeof Date.prototype.toISOString?function(e){return e.toISOString()}:function(e){return e.getUTCFullYear()+"-"+pad(e.getUTCMonth()+1)+"-"+pad(e.getUTCDate())+"T"+pad(e.getUTCHours())+":"+pad(e.getUTCMinutes())+":"+pad(e.getUTCSeconds())+"."+(e.getUTCMilliseconds()/1e3).toFixed(3).slice(2,5)+"Z"};function _complement(e){return function(){return!e.apply(this,arguments)}}function _filter(e,t){for(var r=0,n=t.length,o=[];r<n;)e(t[r])&&(o[o.length]=t[r]),r+=1;return o}function _isObject(e){return"[object Object]"===Object.prototype.toString.call(e)}var XFilter=function(){function e(e,t){this.xf=t,this.f=e}return e.prototype["@@transducer/init"]=_xfBase.init,e.prototype["@@transducer/result"]=_xfBase.result,e.prototype["@@transducer/step"]=function(e,t){return this.f(t)?this.xf["@@transducer/step"](e,t):e},e}(),_xfilter=_curry2(function(e,t){return new XFilter(e,t)}),filter=_curry2(_dispatchable(["filter"],_xfilter,function(e,t){return _isObject(t)?_reduce(function(r,n){return e(t[n])&&(r[n]=t[n]),r},{},keys(t)):_filter(e,t)})),reject=_curry2(function(e,t){return filter(_complement(e),t)});function _toString(e,t){var r=function(r){var n=t.concat([e]);return _contains(r,n)?"<Circular>":_toString(r,n)},n=function(e,t){return _map(function(t){return _quote(t)+": "+r(e[t])},t.slice().sort())};switch(Object.prototype.toString.call(e)){case"[object Arguments]":return"(function() { return arguments; }("+_map(r,e).join(", ")+"))";case"[object Array]":return"["+_map(r,e).concat(n(e,reject(function(e){return/^\d+$/.test(e)},keys(e)))).join(", ")+"]";case"[object Boolean]":return"object"==typeof e?"new Boolean("+r(e.valueOf())+")":e.toString();case"[object Date]":return"new Date("+(isNaN(e.valueOf())?r(NaN):_quote(_toISOString(e)))+")";case"[object Null]":return"null";case"[object Number]":return"object"==typeof e?"new Number("+r(e.valueOf())+")":1/e==-1/0?"-0":e.toString(10);case"[object String]":return"object"==typeof e?"new String("+r(e.valueOf())+")":_quote(e);case"[object Undefined]":return"undefined";default:if("function"==typeof e.toString){var o=e.toString();if("[object Object]"!==o)return o}return"{"+n(e,keys(e)).join(", ")+"}"}}var toString$1=_curry1(function(e){return _toString(e,[])}),contains$1=_curry2(_contains),converge=_curry2(function(e,t){return curryN(reduce(max,0,pluck("length",t)),function(){var r=arguments,n=this;return e.apply(n,_map(function(e){return e.apply(n,r)},t))})}),XReduceBy=function(){function e(e,t,r,n){this.valueFn=e,this.valueAcc=t,this.keyFn=r,this.xf=n,this.inputs={}}return e.prototype["@@transducer/init"]=_xfBase.init,e.prototype["@@transducer/result"]=function(e){var t;for(t in this.inputs)if(_has(t,this.inputs)&&(e=this.xf["@@transducer/step"](e,this.inputs[t]))["@@transducer/reduced"]){e=e["@@transducer/value"];break}return this.inputs=null,this.xf["@@transducer/result"](e)},e.prototype["@@transducer/step"]=function(e,t){var r=this.keyFn(t);return this.inputs[r]=this.