/* twilio-sync.js 0.12.1
The following license applies to all parts of this software except as
documented below.

    Copyright (c) 2016, Twilio, inc.
    All rights reserved.

    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions are
    met:

      1. Redistributions of source code must retain the above copyright
         notice, this list of conditions and the following disclaimer.

      2. Redistributions in binary form must reproduce the above copyright
         notice, this list of conditions and the following disclaimer in
         the documentation and/or other materials provided with the
         distribution.

      3. Neither the name of Twilio nor the names of its contributors may
         be used to endorse or promote products derived from this software
         without specific prior written permission.

    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

This software includes loglevel under the following license.

    Copyright (c) 2013 Tim Perry

    Permission is hereby granted, free of charge, to any person
    obtaining a copy of this software and associated documentation
    files (the "Software"), to deal in the Software without
    restriction, including without limitation the rights to use,
    copy, modify, merge, publish, distribute, sublicense, and/or sell
    copies of the Software, and to permit persons to whom the
    Software is furnished to do so, subject to the following
    conditions:

    The above copyright notice and this permission notice shall be
    included in all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
    OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
    HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
    WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
    OTHER DEALINGS IN THE SOFTWARE.

This software includes Backoff library under the following license

    Copyright (C) 2012 Mathieu Turcotte

    Permission is hereby granted, free of charge, to any person obtaining a copy of
    this software and associated documentation files (the "Software"), to deal in
    the Software without restriction, including without limitation the rights to
    use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
    of the Software, and to permit persons to whom the Software is furnished to do
    so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in all
    copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    SOFTWARE.

This software includes Event-to-Promise library under the following license

    Copyright (c) 2014, Julien Fontanet <julien.fontanet@isonoe.net>.

    Permission to use, copy, modify, and/or distribute this software for any purpose
    with or without fee is hereby granted, provided that the above copyright notice
    and this permission notice appear in all copies.

    THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
    REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
    FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
    INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
    OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
    TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
    THIS SOFTWARE.
*/
!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).Twilio||(t.Twilio={})).Sync=e()}}(function(){return function(){return function e(t,r,n){function i(o,a){if(!r[o]){if(!t[o]){var u="function"==typeof require&&require;if(!a&&u)return u(o,!0);if(s)return s(o,!0);var c=new Error("Cannot find module '"+o+"'");throw c.code="MODULE_NOT_FOUND",c}var l=r[o]={exports:{}};t[o][0].call(l.exports,function(e){return i(t[o][1][e]||e)},l,l.exports,e,t,r,n)}return r[o].exports}for(var s="function"==typeof require&&require,o=0;o<n.length;o++)i(n[o]);return i}}()({1:[function(e,t,r){"use strict";var n=a(e("babel-runtime/core-js/get-iterator")),i=a(e("babel-runtime/helpers/slicedToArray")),s=a(e("babel-runtime/helpers/classCallCheck")),o=a(e("babel-runtime/helpers/createClass"));function a(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var u=e("./utils/tree"),c=function(){function e(t,r){(0,s.default)(this,e),this.value=t,this.revision=r||0}return(0,o.default)(e,[{key:"isValid",get:function(){return!0}}]),e}(),l=function(){function e(t){(0,s.default)(this,e),this.revision=t}return(0,o.default)(e,[{key:"isValid",get:function(){return!1}}]),e}(),f=function(){function e(){(0,s.default)(this,e),this.items=new u.TreeMap}return(0,o.default)(e,[{key:"store",value:function(e,t,r){var n=this.items.get(e);return n&&n.revision>r?n.isValid?n.value:null:(this.items.set(e,new c(t,r)),t)}},{key:"delete",value:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]&&arguments[2],n=this.items.get(e);(!n||n.revision<t||n&&!0===r)&&this.items.set(e,new l(t))}},{key:"isKnown",value:function(e,t){var r=this.items.get(e);return r&&r.revision>=t}},{key:"get",value:function(e){var t=this.items.get(e);return t&&t.isValid?t.value:null}},{key:"has",value:function(e){var t=this.items.get(e);return t&&t.isValid}},{key:"forEach",value:function(e){if(this.items){var t=!0,r=!1,s=void 0;try{for(var o,a=(0,n.default)(this.items);!(t=(o=a.next()).done);t=!0){var u=o.value,c=(0,i.default)(u,2),l=c[0],f=c[1];f.isValid&&e(l,f.value)}}catch(e){r=!0,s=e}finally{try{!t&&a.return&&a.return()}finally{if(r)throw s}}}}}]),e}();r.Cache=f,r.default=f},{"./utils/tree":24,"babel-runtime/core-js/get-iterator":27,"babel-runtime/helpers/classCallCheck":43,"babel-runtime/helpers/createClass":44,"babel-runtime/helpers/slicedToArray":48}],2:[function(e,t,r){"use strict";var n=d(e("babel-runtime/core-js/promise")),i=d(e("babel-runtime/regenerator")),s=d(e("babel-runtime/helpers/asyncToGenerator")),o=d(e("babel-runtime/core-js/object/get-prototype-of")),a=d(e("babel-runtime/helpers/classCallCheck")),u=d(e("babel-runtime/helpers/createClass")),c=d(e("babel-runtime/helpers/possibleConstructorReturn")),l=d(e("babel-runtime/helpers/inherits")),f=d(e("babel-runtime/core-js/object/assign"));function d(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var p=e("events"),h=e("twilsock"),b=e("twilio-notifications"),v=e("./utils/uri"),m=e("./utils/syncerror"),y=e("./utils/sanitize"),g=e("./utils/logger"),_=e("./configuration"),k=e("./subscriptions"),w=e("./router"),x=e("./services/network"),j=e("./syncdocument"),C=e("./synclist"),S=e("./syncmap"),T=e("./clientInfo"),E=e("./entitiesCache"),I=e("./services/storage"),M=e("./streams/syncstream"),R=e("./livequery"),O=e("./livequery"),P="data_sync",L=e("../package.json").version;function N(e){if(e){if("string"==typeof e)return{id:e,mode:"open_or_create"};y.validateOptionalTtl(e.ttl),y.validateId(e.id);var t=e.mode||(e.id?"open_or_create":"create_new");return(0,f.default)((0,f.default)({},e),{mode:t})}return{mode:"create_new"}}var A=function(e){function t(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};(0,a.default)(this,t);var n=(0,c.default)(this,(t.__proto__||(0,o.default)(t)).call(this));if(!e)throw new Error("Sync library needs a valid Twilio token to be passed");r.hasOwnProperty("logLevel")?g.default.setLevel(r.logLevel):g.default.setLevel("silent");var i=r.productId=r.productId||P;r.clientMetadata=r.clientMetadata||{},r.clientMetadata.hasOwnProperty("type")||(r.clientMetadata.type=P),r.clientMetadata.hasOwnProperty("sdk")||(r.clientMetadata.sdk="JS",r.clientMetadata.sdkv=L);var s=r.twilsockClient=r.twilsockClient||new h.Twilsock(e,i,r);s.on("tokenAboutToExpire",function(e){return n.emit("tokenAboutToExpire",e)}),s.on("tokenExpired",function(){return n.emit("tokenExpired")}),s.on("connectionError",function(e){return n.emit("connectionError",e)});var u=r.notificationsClient=r.notificationsClient||new b.Notifications(e,r),l=new _.Configuration(r),f=new x.NetworkService(new T.ClientInfo(L),l,s),d=new I.SessionStorage(l);n.localStorageId=null,s.connect(),n.services={config:l,twilsock:s,notifications:u,network:f,storage:d,router:null,subscriptions:null};var p=new k.Subscriptions(n.services),v=new w.Router({config:l,subscriptions:p,notifications:u});return n.services.router=v,n.services.subscriptions=p,n.entities=new E.EntitiesCache,u.on("connectionStateChanged",function(){n.emit("connectionStateChanged",n.services.notifications.connectionState)}),n}return(0,l.default)(t,e),(0,u.default)(t,[{key:"ensureReady",value:function(){var e=(0,s.default)(i.default.mark(function e(){var t;return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(this.services.config.sessionStorageEnabled){e.next=2;break}return e.abrupt("return");case 2:return e.prev=2,e.next=5,this.services.twilsock.storageId();case 5:t=e.sent,this.services.storage.updateStorageId(t.id),e.next=12;break;case 9:e.prev=9,e.t0=e.catch(2),g.default.warn("Failed to initialize storage",e.t0);case 12:case"end":return e.stop()}},e,this,[[2,9]])}));return function(){return e.apply(this,arguments)}}()},{key:"storeRootInSessionCache",value:function(e,t,r){if(this.services.config.sessionStorageEnabled&&t){var n=y.deepClone(r);e!==C.SyncList.type&&e!==S.SyncMap.type||(n.last_event_id=null,delete n.items),this.services.storage.store(e,t,n)}}},{key:"readRootFromSessionCache",value:function(e,t){return this.services.config.sessionStorageEnabled&&t?this.services.storage.read(e,t):null}},{key:"_get",value:function(){var e=(0,s.default)(i.default.mark(function e(t,r){var n,s,o=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(r){e.next=2;break}throw new m.SyncError("Cannot get entity without id",404);case 2:return n=new v.UriBuilder(t).pathSegment(r).queryParam("Include",o?"items":void 0).build(),e.next=5,this.services.network.get(n);case 5:return s=e.sent,e.abrupt("return",s.body);case 7:case"end":return e.stop()}},e,this)}));return function(t,r){return e.apply(this,arguments)}}()},{key:"_createDocument",value:function(e,t,r){var n={unique_name:e,data:t||{}};return void 0!==r&&(n.ttl=r),this.services.network.post(this.services.config.documentsUri,n).then(function(e){return e.body.data=n.data,e.body})}},{key:"_getDocument",value:function(){var e=(0,s.default)(i.default.mark(function e(t){return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.readRootFromSessionCache(j.SyncDocument.type,t)||this._get(this.services.config.documentsUri,t));case 1:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"_createList",value:function(e,t,r,n){var i={unique_name:e,purpose:t,context:r};return void 0!==n&&(i.ttl=n),this.services.network.post(this.services.config.listsUri,i).then(function(e){return e.body})}},{key:"_getList",value:function(){var e=(0,s.default)(i.default.mark(function e(t){return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.readRootFromSessionCache(C.SyncList.type,t)||this._get(this.services.config.listsUri,t));case 1:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"_createMap",value:function(e,t){var r={unique_name:e};return void 0!==t&&(r.ttl=t),this.services.network.post(this.services.config.mapsUri,r).then(function(e){return e.body})}},{key:"_getMap",value:function(){var e=(0,s.default)(i.default.mark(function e(t){var r=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.readRootFromSessionCache(S.SyncMap.type,t)||this._get(this.services.config.mapsUri,t,r));case 1:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"_getStream",value:function(){var e=(0,s.default)(i.default.mark(function e(t){return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.readRootFromSessionCache(M.SyncStream.type,t)||this._get(this.services.config.streamsUri,t,!1));case 1:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"_createStream",value:function(){var e=(0,s.default)(i.default.mark(function e(t,r){var n,s;return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return n={unique_name:t},void 0!==r&&(n.ttl=r),e.next=4,this.services.network.post(this.services.config.streamsUri,n);case 4:return s=e.sent,e.abrupt("return",s.body);case 6:case"end":return e.stop()}},e,this)}));return function(t,r){return e.apply(this,arguments)}}()},{key:"_getLiveQuery",value:function(e){return this.readRootFromSessionCache(R.LiveQuery.type,e)}},{key:"getCached",value:function(e,t){return e&&this.entities.get(e,t)||null}},{key:"removeFromCacheAndSession",value:function(e,t,r){this.entities.remove(t),this.services.config.sessionStorageEnabled&&this.services.storage.remove(e,t,r)}},{key:"document",value:function(){var e=(0,s.default)(i.default.mark(function e(t){var r,n,s,o,a=this;return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.ensureReady();case 2:if(r=N(t),n=void 0,"create_new"!==r.mode){e.next=10;break}return e.next=7,this._createDocument(r.id,r.value,r.ttl);case 7:n=e.sent,e.next=40;break;case 10:if(!(s=this.getCached(r.id,j.SyncDocument.type))){e.next=15;break}return e.abrupt("return",new j.SyncDocument(s));case 15:return e.prev=15,e.next=18,this._getDocument(r.id);case 18:n=e.sent,e.next=40;break;case 21:if(e.prev=21,e.t0=e.catch(15),404===e.t0.status&&"open_existing"!==r.mode){e.next=27;break}throw e.t0;case 27:return e.prev=27,e.next=30,this._createDocument(r.id,r.value,r.ttl);case 30:n=e.sent,e.next=40;break;case 33:if(e.prev=33,e.t1=e.catch(27),409!==e.t1.status){e.next=39;break}return e.abrupt("return",this.document(t));case 39:throw e.t1;case 40:return this.storeRootInSessionCache(j.SyncDocument.type,r.id,n),o=new j.SyncDocumentImpl(this.services,n,function(e,t,r){return a.removeFromCacheAndSession(e,t,r)}),o=this.entities.store(o),e.abrupt("return",new j.SyncDocument(o));case 44:case"end":return e.stop()}},e,this,[[15,21],[27,33]])}));return function(t){return e.apply(this,arguments)}}()},{key:"map",value:function(){var e=(0,s.default)(i.default.mark(function e(t){var r,n,s,o,a=this;return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.ensureReady();case 2:if(r=N(t),n=void 0,"create_new"!==r.mode){e.next=10;break}return e.next=7,this._createMap(r.id,r.ttl);case 7:n=e.sent,e.next=40;break;case 10:if(!(s=this.getCached(r.id,S.SyncMap.type))){e.next=15;break}return e.abrupt("return",new S.SyncMap(s));case 15:return e.prev=15,e.next=18,this._getMap(r.id,r.includeItems);case 18:n=e.sent,e.next=40;break;case 21:if(e.prev=21,e.t0=e.catch(15),404===e.t0.status&&"open_existing"!==r.mode){e.next=27;break}throw e.t0;case 27:return e.prev=27,e.next=30,this._createMap(r.id,r.ttl);case 30:n=e.sent,e.next=40;break;case 33:if(e.prev=33,e.t1=e.catch(27),409!==e.t1.status){e.next=39;break}return e.abrupt("return",this.map(t));case 39:throw e.t1;case 40:return this.storeRootInSessionCache(S.SyncMap.type,r.id,n),o=new S.SyncMapImpl(this.services,n,function(e,t,r){return a.removeFromCacheAndSession(e,t,r)}),o=this.entities.store(o),e.abrupt("return",new S.SyncMap(o));case 44:case"end":return e.stop()}},e,this,[[15,21],[27,33]])}));return function(t){return e.apply(this,arguments)}}()},{key:"list",value:function(){var e=(0,s.default)(i.default.mark(function e(t){var r,n,s,o,a=this;return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.ensureReady();case 2:if(r=N(t),n=void 0,"create_new"!==r.mode){e.next=10;break}return e.next=7,this._createList(r.id,r.purpose,r.context,r.ttl);case 7:n=e.sent,e.next=40;break;case 10:if(!(s=this.getCached(r.id,C.SyncList.type))){e.next=15;break}return e.abrupt("return",new C.SyncList(s));case 15:return e.prev=15,e.next=18,this._getList(r.id);case 18:n=e.sent,e.next=40;break;case 21:if(e.prev=21,e.t0=e.catch(15),404===e.t0.status&&"open_existing"!==r.mode){e.next=27;break}throw e.t0;case 27:return e.prev=27,e.next=30,this._createList(r.id,r.purpose,r.context,r.ttl);case 30:n=e.sent,e.next=40;break;case 33:if(e.prev=33,e.t1=e.catch(27),409!==e.t1.status){e.next=39;break}return e.abrupt("return",this.list(t));case 39:throw e.t1;case 40:return this.storeRootInSessionCache(C.SyncList.type,r.id,n),o=new C.SyncListImpl(this.services,n,function(e,t,r){return a.removeFromCacheAndSession(e,t,r)}),o=this.entities.store(o),e.abrupt("return",new C.SyncList(o));case 44:case"end":return e.stop()}},e,this,[[15,21],[27,33]])}));return function(t){return e.apply(this,arguments)}}()},{key:"stream",value:function(){var e=(0,s.default)(i.default.mark(function e(t){var r,n,s,o,a,u=this;return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.ensureReady();case 2:if(r=N(t),n=void 0,"create_new"!==r.mode){e.next=10;break}return e.next=7,this._createStream(r.id,r.ttl);case 7:n=e.sent,e.next=40;break;case 10:if(!(s=this.getCached(r.id,M.SyncStream.type))){e.next=15;break}return e.abrupt("return",new M.SyncStream(s));case 15:return e.prev=15,e.next=18,this._getStream(r.id);case 18:n=e.sent,e.next=40;break;case 21:if(e.prev=21,e.t0=e.catch(15),404===e.t0.status&&"open_existing"!==r.mode){e.next=27;break}throw e.t0;case 27:return e.prev=27,e.next=30,this._createStream(r.id,r.ttl);case 30:n=e.sent,e.next=40;break;case 33:if(e.prev=33,e.t1=e.catch(27),409!==e.t1.status){e.next=39;break}return e.abrupt("return",this.stream(t));case 39:throw e.t1;case 40:return this.storeRootInSessionCache(M.SyncStream.type,r.id,n),o=function(e,t,r){return u.removeFromCacheAndSession(e,t,r)},a=new M.SyncStreamImpl(this.services,n,o),a=this.entities.store(a),e.abrupt("return",new M.SyncStream(a));case 45:case"end":return e.stop()}},e,this,[[15,21],[27,33]])}));return function(t){return e.apply(this,arguments)}}()},{key:"shutdown",value:function(){var e=(0,s.default)(i.default.mark(function e(){return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.subscriptions.shutdown();case 2:return e.next=4,this.services.twilsock.disconnect();case 4:case"end":return e.stop()}},e,this)}));return function(){return e.apply(this,arguments)}}()},{key:"updateToken",value:function(e){return e?this.services.twilsock.updateToken(e):n.default.reject(new Error("A valid Twilio token should be provided"))}},{key:"liveQuery",value:function(){var e=(0,s.default)(i.default.mark(function e(t,r){var n,s,o,a,u,c=this;return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.ensureReady();case 2:if(t&&"string"==typeof t){e.next=4;break}throw new Error("Index name must contain a non-empty string value");case 4:return n=new v.UriBuilder(this.services.config.insightsUri).pathSegment(t).pathSegment("Items").build(),e.next=7,O.queryItems({network:this.services.network,uri:n,queryString:r,type:R.LiveQuery.type});case 7:return s=e.sent,(o=this.getCached(s.query_id,R.LiveQuery.type))||((a=this._getLiveQuery(s.query_id))||(a={indexName:t,queryExpression:r,sid:s.query_id,queryUri:n,last_event_id:s.last_event_id}),u=function(e,t,r){return c.removeFromCacheAndSession(e,t,r)},o=new R.LiveQueryImpl(a,this.services,u,s.items)),this.storeRootInSessionCache(R.LiveQuery.type,s.query_id,o.liveQueryDescriptor),o=this.entities.store(o),e.abrupt("return",new R.LiveQuery(o));case 13:case"end":return e.stop()}},e,this)}));return function(t,r){return e.apply(this,arguments)}}()},{key:"instantQuery",value:function(){var e=(0,s.default)(i.default.mark(function e(t){var r,n,s=this;return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.ensureReady();case 2:return r=function(e,t){return s.liveQuery(e,t)},n=new R.InstantQuery({indexName:t,network:this.services.network,insightsUri:this.services.config.insightsUri,liveQueryCreator:r}),e.abrupt("return",n);case 5:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"connectionState",get:function(){return this.services.notifications.connectionState}}],[{key:"version",get:function(){return L}}]),t}(p.EventEmitter);r.Client=A,r.SyncClient=A,r.default=A},{"../package.json":233,"./clientInfo":3,"./configuration":5,"./entitiesCache":6,"./livequery":9,"./router":13,"./services/network":14,"./services/storage":15,"./streams/syncstream":16,"./subscriptions":17,"./syncdocument":18,"./synclist":19,"./syncmap":20,"./utils/logger":21,"./utils/sanitize":22,"./utils/syncerror":23,"./utils/uri":25,"babel-runtime/core-js/object/assign":31,"babel-runtime/core-js/object/get-prototype-of":35,"babel-runtime/core-js/promise":37,"babel-runtime/helpers/asyncToGenerator":42,"babel-runtime/helpers/classCallCheck":43,"babel-runtime/helpers/createClass":44,"babel-runtime/helpers/inherits":46,"babel-runtime/helpers/possibleConstructorReturn":47,"babel-runtime/regenerator":51,events:184,"twilio-notifications":196,twilsock:209}],3:[function(e,t,r){"use strict";var n,i=e("babel-runtime/helpers/classCallCheck"),s=(n=i)&&n.__esModule?n:{default:n};Object.defineProperty(r,"__esModule",{value:!0});var o=e("platform"),a=function e(t){(0,s.default)(this,e),this.sdk="js",this.sdkVer=t,this.os=o.os.family,this.osVer=o.os.version,this.pl=o.name,this.plVer=o.version};r.ClientInfo=a,r.default=a},{"babel-runtime/helpers/classCallCheck":43,platform:190}],4:[function(e,t,r){"use strict";var n=u(e("babel-runtime/core-js/object/get-prototype-of")),i=u(e("babel-runtime/helpers/classCallCheck")),s=u(e("babel-runtime/helpers/createClass")),o=u(e("babel-runtime/helpers/possibleConstructorReturn")),a=u(e("babel-runtime/helpers/inherits"));function u(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var c=e("events"),l=e("uuid"),f=function(e){function t(){(0,i.default)(this,t);var e=(0,o.default)(this,(t.__proto__||(0,n.default)(t)).call(this));return e.closed=!1,e.uuid=l(),e}return(0,a.default)(t,e),(0,s.default)(t,[{key:"close",value:function(){this.removeAllListeners(),this.closed=!0}},{key:"ensureNotClosed",value:function(){if(this.closed)throw new Error("Invalid operation on closed object")}},{key:"listenerUuid",get:function(){return this.uuid}}]),t}(c.EventEmitter);r.Closeable=f,r.default=f},{"babel-runtime/core-js/object/get-prototype-of":35,"babel-runtime/helpers/classCallCheck":43,"babel-runtime/helpers/createClass":44,"babel-runtime/helpers/inherits":46,"babel-runtime/helpers/possibleConstructorReturn":47,events:184,uuid:228}],5:[function(e,t,r){"use strict";var n=s(e("babel-runtime/helpers/classCallCheck")),i=s(e("babel-runtime/helpers/createClass"));function s(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var o="/v4/Subscriptions",a="/v3/Maps",u="/v3/Lists",c="/v3/Documents",l="/v3/Streams",f="/v3/Insights";var d=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};(0,n.default)(this,e);var r,i,s,d="https://cds."+(t.region||"us1")+".twilio.com",p=t.cdsUri||d;this.settings={subscriptionsUri:p+o,documentsUri:p+c,listsUri:p+u,mapsUri:p+a,streamsUri:p+l,insightsUri:p+f,sessionStorageEnabled:(r=t.Sync,i="enableSessionStorage",s=!0,r&&void 0!==r[i]?r[i]:s)}}return(0,i.default)(e,[{key:"subscriptionsUri",get:function(){return this.settings.subscriptionsUri}},{key:"documentsUri",get:function(){return this.settings.documentsUri}},{key:"listsUri",get:function(){return this.settings.listsUri}},{key:"mapsUri",get:function(){return this.settings.mapsUri}},{key:"streamsUri",get:function(){return this.settings.streamsUri}},{key:"insightsUri",get:function(){return this.settings.insightsUri}},{key:"backoffConfig",get:function(){return this.settings.backoffConfig||{}}},{key:"sessionStorageEnabled",get:function(){return this.settings.sessionStorageEnabled}}]),e}();r.Configuration=d},{"babel-runtime/helpers/classCallCheck":43,"babel-runtime/helpers/createClass":44}],6:[function(e,t,r){"use strict";var n=o(e("babel-runtime/core-js/map")),i=o(e("babel-runtime/helpers/classCallCheck")),s=o(e("babel-runtime/helpers/createClass"));function o(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var a=function(){function e(){(0,i.default)(this,e),this.names=new n.default,this.entities=new n.default}return(0,s.default)(e,[{key:"store",value:function(e){var t=this.entities.get(e.sid);return t||(this.entities.set(e.sid,e),e.uniqueName&&this.names.set(e.type+"::"+e.uniqueName,e.sid),e)}},{key:"getResolved",value:function(e,t){var r=this.names.get(t+"::"+e);return r?this.entities.get(r):null}},{key:"get",value:function(e,t){return this.entities.get(e)||this.getResolved(e,t)||null}},{key:"remove",value:function(e){var t=this.entities.get(e);t&&(this.entities.delete(e),t.uniqueName&&this.names.delete(t.type+"::"+t.uniqueName))}}]),e}();r.EntitiesCache=a},{"babel-runtime/core-js/map":30,"babel-runtime/helpers/classCallCheck":43,"babel-runtime/helpers/createClass":44}],7:[function(e,t,r){"use strict";var n=a(e("babel-runtime/core-js/get-iterator")),i=a(e("babel-runtime/core-js/map")),s=a(e("babel-runtime/helpers/classCallCheck")),o=a(e("babel-runtime/helpers/createClass"));function a(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var u=function(){function e(t,r){(0,s.default)(this,e),this.services=t,this.removalHandler=r,this.subscriptionState="none",this._attachedListeners=new i.default}return(0,o.default)(e,[{key:"_advanceLastEventId",value:function(e,t){}},{key:"reportFailure",value:function(e){404===e.status?this.onRemoved(!1):this.broadcastEventToListeners("failure",e)}},{key:"_subscribe",value:function(){this.services.router.subscribe(this.sid,this)}},{key:"_unsubscribe",value:function(){this.services.router.unsubscribe(this.sid)}},{key:"_setSubscriptionState",value:function(e){this.subscriptionState=e,this.broadcastEventToListeners("_subscriptionStateChanged",e)}},{key:"close",value:function(){this._unsubscribe(),null!=this.removalHandler&&this.removalHandler(this.type,this.sid,this.uniqueName)}},{key:"attach",value:function(e){var t=e.listenerUuid;this._attachedListeners.get(t)||(this._attachedListeners.size||this._subscribe(),this._attachedListeners.set(t,e))}},{key:"detach",value:function(e){this._attachedListeners.delete(e),this._attachedListeners.size||this.close()}},{key:"broadcastEventToListeners",value:function(e,t){var r=!0,i=!1,s=void 0;try{for(var o,a=(0,n.default)(this._attachedListeners.values());!(r=(o=a.next()).done);r=!0){o.value.emit(e,t)}}catch(e){i=!0,s=e}finally{try{!r&&a.return&&a.return()}finally{if(i)throw s}}}}]),e}();r.SyncEntity=u,r.default=u},{"babel-runtime/core-js/get-iterator":27,"babel-runtime/core-js/map":30,"babel-runtime/helpers/classCallCheck":43,"babel-runtime/helpers/createClass":44}],8:[function(e,t,r){"use strict";var n=s(e("babel-runtime/helpers/classCallCheck")),i=s(e("babel-runtime/helpers/createClass"));function s(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var o=function(){function e(t){(0,n.default)(this,e),this.data=t}return(0,i.default)(e,[{key:"update",value:function(e,t,r,n){return this.data.lastEventId=e,this.data.revision=t,this.data.value=r,this.data.dateUpdated=n,this}},{key:"updateDateExpires",value:function(e){this.data.dateExpires=e}},{key:"uri",get:function(){return this.data.uri}},{key:"revision",get:function(){return this.data.revision}},{key:"lastEventId",get:function(){return this.data.lastEventId}},{key:"dateUpdated",get:function(){return this.data.dateUpdated}},{key:"dateExpires",get:function(){return this.data.dateExpires}},{key:"index",get:function(){return this.data.index}},{key:"value",get:function(){return this.data.value}}]),e}();r.ListItem=o,r.default=o},{"babel-runtime/helpers/classCallCheck":43,"babel-runtime/helpers/createClass":44}],9:[function(e,t,r){"use strict";var n,i=b(e("babel-runtime/core-js/promise")),s=b(e("babel-runtime/core-js/object/assign")),o=b(e("babel-runtime/helpers/get")),a=b(e("babel-runtime/regenerator")),u=b(e("babel-runtime/helpers/asyncToGenerator")),c=b(e("babel-runtime/core-js/object/get-prototype-of")),l=b(e("babel-runtime/helpers/createClass")),f=b(e("babel-runtime/helpers/possibleConstructorReturn")),d=b(e("babel-runtime/helpers/inherits")),p=b(e("babel-runtime/helpers/classCallCheck")),h=(n=(0,u.default)(a.default.mark(function e(t){var r,n,i,s,o,u;return a.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(r=t.network,n=t.queryString,i=t.uri,s=t.type,null!=n){e.next=3;break}throw new m.SyncError("Invalid query",400,54507);case 3:return o={query_string:n},s===j.type&&(o.type=s),e.next=7,r.post(i,o,void 0,!0);case 7:return u=e.sent,e.abrupt("return",u.body);case 9:case"end":return e.stop()}},e,this)})),function(e){return n.apply(this,arguments)});function b(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var v=e("./utils/uri"),m=e("./utils/syncerror"),y=e("./utils/logger"),g=e("events"),_=e("./entity"),k=e("./closeable"),w=e("./cache");r.InsightsItem=function e(){(0,p.default)(this,e)};var x=function(e){function t(e,r,n,i){(0,p.default)(this,t);var s=(0,f.default)(this,(t.__proto__||(0,c.default)(t)).call(this,r,n));return s.descriptor=e,s.cache=new w.Cache,i&&i.forEach(function(e){s.cache.store(e.key,{key:e.key,value:e.data},e.revision)}),s}return(0,d.default)(t,e),(0,l.default)(t,[{key:"onRemoved",value:function(){}},{key:"getItems",value:function(){var e={};return this.cache.forEach(function(t,r){e[t]=r.value}),e}},{key:"_update",value:function(e,t){switch(e.type){case"live_query_item_updated":this.handleItemMutated(e.item_key,e.item_data,e.item_revision);break;case"live_query_item_removed":this.handleItemRemoved(e.item_key,e.item_revision);break;case"live_query_updated":this.handleBatchUpdate(e.items)}t&&this._advanceLastEventId(e.last_event_id)}},{key:"handleItemMutated",value:function(e,t,r){if(this.shouldIgnoreEvent(e,r))y.default.trace("Item "+e+" update skipped, revision: "+r);else{var n={key:e,value:t};this.cache.store(e,n,r),this.broadcastEventToListeners("itemUpdated",n)}}},{key:"handleItemRemoved",value:function(e,t){var r=null===t;this.shouldIgnoreEvent(e,t)?y.default.trace("Item "+e+" delete skipped, revision: "+t):(this.cache.delete(e,t,r),this.broadcastEventToListeners("itemRemoved",{key:e}))}},{key:"handleBatchUpdate",value:function(e){var t=this,r={};for(var n in null!=e&&e.forEach(function(e){r[e.key]={data:e.data,revision:e.revision}}),this.cache.forEach(function(e,n){var i=r[e];null!=i?t.handleItemMutated(e,i.data,i.revision):t.handleItemRemoved(e,null),delete r[e]}),r)this.handleItemMutated(n,r[n].data,r[n].revision)}},{key:"shouldIgnoreEvent",value:function(e,t){return null!=e&&null!=t&&this.cache.isKnown(e,t)}},{key:"_advanceLastEventId",value:function(e,t){this.lastEventId<e&&(this.descriptor.last_event_id=e)}},{key:"sid",get:function(){return this.descriptor.sid}},{key:"uniqueName",get:function(){return null}},{key:"type",get:function(){return t.type}},{key:"lastEventId",get:function(){return this.descriptor.last_event_id}},{key:"indexName",get:function(){return this.descriptor.indexName}},{key:"queryString",get:function(){return this.descriptor.queryExpression}},{key:"queryUri",get:function(){return this.descriptor.queryUri}},{key:"liveQueryDescriptor",get:function(){return this.descriptor}}],[{key:"type",get:function(){return"live_query"}}]),t}(_.SyncEntity);r.LiveQueryImpl=x,r.queryItems=h;var j=function(e){function t(e){(0,p.default)(this,t);var r=(0,f.default)(this,(t.__proto__||(0,c.default)(t)).call(this));return r.liveQueryImpl=e,r.liveQueryImpl.attach(r),r}return(0,d.default)(t,e),(0,l.default)(t,[{key:"close",value:function(){(0,o.default)(t.prototype.__proto__||(0,c.default)(t.prototype),"close",this).call(this),this.liveQueryImpl.detach(this.listenerUuid)}},{key:"getItems",value:function(){return this.ensureNotClosed(),this.liveQueryImpl.getItems()}},{key:"type",get:function(){return x.type}},{key:"lastEventId",get:function(){return this.liveQueryImpl.lastEventId}},{key:"sid",get:function(){return this.liveQueryImpl.sid}}],[{key:"type",get:function(){return x.type}}]),t}(k.Closeable);r.LiveQuery=j;var C=function(e){function t(e){(0,p.default)(this,t);var r=(0,f.default)(this,(t.__proto__||(0,c.default)(t)).call(this));return r.queryExpression=null,r.items={},(0,s.default)(r,e),r.updateIndexName(e.indexName),r}return(0,d.default)(t,e),(0,l.default)(t,[{key:"search",value:function(){var e=(0,u.default)(a.default.mark(function e(t){var r=this;return a.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.items={},e.abrupt("return",h({network:this.network,uri:this.queryUri,queryString:t}).then(function(e){r.queryExpression=t,e.items&&e.items.forEach(function(e){r.items[e.key]=e.data}),r.emit("searchResult",r.getItems())}).catch(function(e){throw y.default.error("Error '"+e.message+"' while executing query '"+t+"'"),r.queryExpression=null,e}));case 2:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"subscribe",value:function(){var e=(0,u.default)(a.default.mark(function e(){return a.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(null!=this.queryExpression){e.next=2;break}return e.abrupt("return",i.default.reject(new m.SyncError("Invalid query",400,54507)));case 2:return e.abrupt("return",this.liveQueryCreator(this.indexName,this.queryExpression));case 3:case"end":return e.stop()}},e,this)}));return function(){return e.apply(this,arguments)}}()},{key:"getItems",value:function(){return this.items}},{key:"updateIndexName",value:function(e){if(!e||"string"!=typeof e)throw new Error("Index name must contain a non-empty string value");this.indexName=e,this.queryUri=this.generateQueryUri(this.indexName)}},{key:"generateQueryUri",value:function(e){return new v.UriBuilder(this.insightsUri).pathSegment(e).pathSegment("Items").build()}},{key:"type",get:function(){return t.type}}],[{key:"type",get:function(){return"instant_query"}}]),t}(g.EventEmitter);r.InstantQuery=C,r.default=j},{"./cache":1,"./closeable":4,"./entity":7,"./utils/logger":21,"./utils/syncerror":23,"./utils/uri":25,"babel-runtime/core-js/object/assign":31,"babel-runtime/core-js/object/get-prototype-of":35,"babel-runtime/core-js/promise":37,"babel-runtime/helpers/asyncToGenerator":42,"babel-runtime/helpers/classCallCheck":43,"babel-runtime/helpers/createClass":44,"babel-runtime/helpers/get":45,"babel-runtime/helpers/inherits":46,"babel-runtime/helpers/possibleConstructorReturn":47,"babel-runtime/regenerator":51,events:184}],10:[function(e,t,r){"use strict";var n=s(e("babel-runtime/helpers/classCallCheck")),i=s(e("babel-runtime/helpers/createClass"));function s(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var o=function(){function e(t){(0,n.default)(this,e),this.descriptor=t}return(0,i.default)(e,[{key:"update",value:function(e,t,r,n){return this.descriptor.last_event_id=e,this.descriptor.revision=t,this.descriptor.data=r,this.descriptor.date_updated=n,this}},{key:"updateDateExpires",value:function(e){this.descriptor.date_expires=e}},{key:"uri",get:function(){return this.descriptor.url}},{key:"revision",get:function(){return this.descriptor.revision}},{key:"lastEventId",get:function(){return this.descriptor.last_event_id}},{key:"dateExpires",get:function(){return this.descriptor.date_expires}},{key:"key",get:function(){return this.descriptor.key}},{key:"value",get:function(){return this.descriptor.data}},{key:"dateUpdated",get:function(){return this.descriptor.date_updated}}]),e}();r.MapItem=o},{"babel-runtime/helpers/classCallCheck":43,"babel-runtime/helpers/createClass":44}],11:[function(e,t,r){"use strict";var n=c(e("babel-runtime/regenerator")),i=c(e("babel-runtime/helpers/asyncToGenerator")),s=c(e("babel-runtime/core-js/map")),o=c(e("babel-runtime/core-js/promise")),a=c(e("babel-runtime/helpers/classCallCheck")),u=c(e("babel-runtime/helpers/createClass"));function c(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var l=function(){function e(t){(0,a.default)(this,e),this.queuedRequests=[],this.isRequestInFlight=!1,this.inputMergingFunction=t}return(0,u.default)(e,[{key:"add",value:function(e,t){var r=this,n=new o.default(function(n,i){return r.queuedRequests.push({input:e,requestFunction:t,resolve:n,reject:i})});return this.wakeupQueue(),n}},{key:"squashAndAdd",value:function(e,t){var r=this.queuedRequests;this.queuedRequests=[];var n=void 0;r.length>0?(n=r.map(function(e){return e.input}).reduce(this.inputMergingFunction),n=this.inputMergingFunction(n,e)):n=e;var i=this.add(n,t);return r.forEach(function(e){return i.then(e.resolve,e.reject)}),i}},{key:"isEmpty",value:function(){return 0===this.queuedRequests.length&&!this.isRequestInFlight}},{key:"wakeupQueue",value:function(){var e=this;if(0!==this.queuedRequests.length&&!this.isRequestInFlight){var t=this.queuedRequests.shift();this.isRequestInFlight=!0,t.requestFunction(t.input).then(t.resolve,t.reject).then(function(t){e.isRequestInFlight=!1,e.wakeupQueue()})}}}]),e}();r.MergingQueue=l;var f=function(){function e(t){(0,a.default)(this,e),this.queueByNamespaceKey=new s.default,this.inputReducer=t}return(0,u.default)(e,[{key:"add",value:function(){var e=(0,i.default)(n.default.mark(function e(t,r,i){return n.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.invokeQueueMethod(t,function(e){return e.add(r,i)}));case 1:case"end":return e.stop()}},e,this)}));return function(t,r,n){return e.apply(this,arguments)}}()},{key:"squashAndAdd",value:function(){var e=(0,i.default)(n.default.mark(function e(t,r,i){return n.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.invokeQueueMethod(t,function(e){return e.squashAndAdd(r,i)}));case 1:case"end":return e.stop()}},e,this)}));return function(t,r,n){return e.apply(this,arguments)}}()},{key:"invokeQueueMethod",value:function(){var e=(0,i.default)(n.default.mark(function e(t,r){var i,s;return n.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.queueByNamespaceKey.has(t)||this.queueByNamespaceKey.set(t,new l(this.inputReducer)),i=this.queueByNamespaceKey.get(t),s=r(i),this.queueByNamespaceKey.get(t).isEmpty()&&this.queueByNamespaceKey.delete(t),e.abrupt("return",s);case 5:case"end":return e.stop()}},e,this)}));return function(t,r){return e.apply(this,arguments)}}()}]),e}();r.NamespacedMergingQueue=f},{"babel-runtime/core-js/map":30,"babel-runtime/core-js/promise":37,"babel-runtime/helpers/asyncToGenerator":42,"babel-runtime/helpers/classCallCheck":43,"babel-runtime/helpers/createClass":44,"babel-runtime/regenerator":51}],12:[function(e,t,r){"use strict";var n=a(e("babel-runtime/regenerator")),i=a(e("babel-runtime/helpers/asyncToGenerator")),s=a(e("babel-runtime/helpers/classCallCheck")),o=a(e("babel-runtime/helpers/createClass"));function a(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var u=function(){function e(t,r,n,i){(0,s.default)(this,e),this.prevToken=n,this.nextToken=i,this.items=t,this.source=r}return(0,o.default)(e,[{key:"nextPage",value:function(){var e=(0,i.default)(n.default.mark(function e(){return n.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(this.hasNextPage){e.next=2;break}throw new Error("No next page");case 2:return e.abrupt("return",this.source(this.nextToken));case 3:case"end":return e.stop()}},e,this)}));return function(){return e.apply(this,arguments)}}()},{key:"prevPage",value:function(){var e=(0,i.default)(n.default.mark(function e(){return n.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(this.hasPrevPage){e.next=2;break}throw new Error("No previous page");case 2:return e.abrupt("return",this.source(this.prevToken));case 3:case"end":return e.stop()}},e,this)}));return function(){return e.apply(this,arguments)}}()},{key:"hasNextPage",get:function(){return!!this.nextToken}},{key:"hasPrevPage",get:function(){return!!this.prevToken}}]),e}();r.Paginator=u},{"babel-runtime/helpers/asyncToGenerator":42,"babel-runtime/helpers/classCallCheck":43,"babel-runtime/helpers/createClass":44,"babel-runtime/regenerator":51}],13:[function(e,t,r){"use strict";var n=s(e("babel-runtime/helpers/classCallCheck")),i=s(e("babel-runtime/helpers/createClass"));function s(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var o=e("./utils/logger"),a="com.twilio.rtd.cds.document",u="com.twilio.rtd.cds.list",c="com.twilio.rtd.cds.map",l="twilio.sync.event",f=function(){function e(t){var r=this;(0,n.default)(this,e),this.config=t.config,this.subscriptions=t.subscriptions,this.notifications=t.notifications,this.notifications.subscribe(l),this.notifications.subscribe(a),this.notifications.subscribe(u),this.notifications.subscribe(c),this.notifications.on("message",function(e,t){return r.onMessage(e,t)}),this.notifications.on("transportReady",function(e){return r.onConnectionStateChanged(e)})}return(0,i.default)(e,[{key:"onMessage",value:function(e,t){switch(o.default.trace("Notification type:",e,"content:",t),e){case a:case u:case c:this.subscriptions.acceptMessage(t,!1);break;case l:this.subscriptions.acceptMessage(t,!0)}}},{key:"subscribe",value:function(e,t){this.subscriptions.add(e,t)}},{key:"unsubscribe",value:function(e){this.subscriptions.remove(e)}},{key:"onConnectionStateChanged",value:function(e){this.subscriptions.onConnectionStateChanged(e)}}]),e}();r.Router=f,r.default=f},{"./utils/logger":21,"babel-runtime/helpers/classCallCheck":43,"babel-runtime/helpers/createClass":44}],14:[function(e,t,r){"use strict";var n=u(e("babel-runtime/core-js/promise")),i=u(e("babel-runtime/core-js/object/assign")),s=u(e("babel-runtime/core-js/json/stringify")),o=u(e("babel-runtime/helpers/classCallCheck")),a=u(e("babel-runtime/helpers/createClass"));function u(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var c=e("uuid"),l=e("../utils/syncerror"),f=e("../utils/logger"),d=e("operation-retrier"),p=e("twilsock");function h(e){if(e.body&&e.body.message)return e.body.message;switch(e.status){case 429:return"Throttled by server";case 404:return"Not found from server";default:return"Error from server"}}function b(e){return e.body?e.body.code:0}function v(e){return 409===e.status?new l.SyncNetworkError(h(e),e.status,b(e),e.body):e.status?new l.SyncError(h(e),e.status,b(e)):e instanceof p.TransportUnavailableError?e:new l.SyncError(e.message,0,0)}var m=function(){function e(t,r,n){(0,o.default)(this,e),this.clientInfo=t,this.config=r,this.transport=n}return(0,a.default)(e,[{key:"createHeaders",value:function(){return{"Content-Type":"application/json","Twilio-Sync-Client-Info":(0,s.default)(this.clientInfo),"Twilio-Request-Id":"RQ"+c.v4().replace(/-/g,"")}}},{key:"backoffConfig",value:function(){return(0,i.default)({min:4e3,max:6e4,maxAttemptsTime:9e4,randomness:.2},this.config.backoffConfig)}},{key:"executeWithRetry",value:function(e){var t=this,r=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return new n.default(function(n,i){var s=[502,503,504];r&&s.push(429);var o=new d.Retrier(t.backoffConfig());o.on("attempt",function(){e().then(function(e){return o.succeeded(e)}).catch(function(e){if(s.includes(e.status)){var t=parseInt(e.headers?e.headers["Retry-After"]:null);o.failed(v(e),isNaN(t)?null:1e3*t)}else"Twilsock disconnected"===e.message?o.failed(v(e)):(o.removeAllListeners(),o.cancel(),i(v(e)))})}),o.on("succeeded",function(e){n(e)}),o.on("cancelled",function(e){return i(v(e))}),o.on("failed",function(e){return i(v(e))}),o.start()})}},{key:"get",value:function(e){var t=this,r=this.createHeaders();return f.default.debug("GET",e,"ID:",r["Twilio-Request-Id"]),this.executeWithRetry(function(){return t.transport.get(e,r)},!0)}},{key:"post",value:function(e,t,r){var n=this,i=arguments.length>3&&void 0!==arguments[3]&&arguments[3],s=this.createHeaders();return null!=r&&(s["If-Match"]=r),f.default.debug("POST",e,"ID:",s["Twilio-Request-Id"]),this.executeWithRetry(function(){return n.transport.post(e,s,t)},i)}},{key:"put",value:function(e,t,r){var n=this,i=this.createHeaders();return null!=r&&(i["If-Match"]=r),f.default.debug("PUT",e,"ID:",i["Twilio-Request-Id"]),this.executeWithRetry(function(){return n.transport.put(e,i,t)},!1)}},{key:"delete",value:function(e){var t=this,r=this.createHeaders();return f.default.debug("DELETE",e,"ID:",r["Twilio-Request-Id"]),this.executeWithRetry(function(){return t.transport.delete(e,r)},!1)}}]),e}();r.NetworkService=m},{"../utils/logger":21,"../utils/syncerror":23,"babel-runtime/core-js/json/stringify":29,"babel-runtime/core-js/object/assign":31,"babel-runtime/core-js/promise":37,"babel-runtime/helpers/classCallCheck":43,"babel-runtime/helpers/createClass":44,"operation-retrier":188,twilsock:209,uuid:228}],15:[function(e,t,r){"use strict";var n=a(e("babel-runtime/core-js/object/assign")),i=a(e("babel-runtime/core-js/json/stringify")),s=a(e("babel-runtime/helpers/classCallCheck")),o=a(e("babel-runtime/helpers/createClass"));function a(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var u=function(){function e(t,r){(0,s.default)(this,e),this.config=t,this.storageId=null;try{this.storage=r||sessionStorage}catch(e){}}return(0,o.default)(e,[{key:"storageKey",value:function(e,t){return this.storageId+"::"+e+"::"+t}},{key:"updateStorageId",value:function(e){this.storageId=e}},{key:"store",value:function(e,t,r){return this.isReady?this._store(this.storageKey(e,t),r):null}},{key:"read",value:function(e,t){return this.isReady?this._read(this.storageKey(e,t)):null}},{key:"remove",value:function(e,t,r){if(!this.isReady)return null;try{this.storage.removeItem(this.storageKey(e,t)),r&&this.storage.removeItem(this.storageKey(e,r))}catch(e){}}},{key:"update",value:function(e,t,r,n){if(!this.isReady)return null;this._apply(this.storageKey(e,t),n),r&&this._apply(this.storageKey(e,r),n)}},{key:"_store",value:function(e,t){try{this.storage.setItem(e,(0,i.default)(t))}catch(e){}}},{key:"_read",value:function(e){try{var t=this.storage.getItem(e);if(t)return JSON.parse(t)}catch(e){}return null}},{key:"_apply",value:function(e,t){var r=this._read(e);if(!r)return!1;this._store(e,(0,n.default)(r,t))}},{key:"isReady",get:function(){return this.config.sessionStorageEnabled&&!!this.storageId}}]),e}();r.SessionStorage=u},{"babel-runtime/core-js/json/stringify":29,"babel-runtime/core-js/object/assign":31,"babel-runtime/helpers/classCallCheck":43,"babel-runtime/helpers/createClass":44}],16:[function(e,t,r){"use strict";var n=f(e("babel-runtime/helpers/get")),i=f(e("babel-runtime/regenerator")),s=f(e("babel-runtime/helpers/asyncToGenerator")),o=f(e("babel-runtime/core-js/object/get-prototype-of")),a=f(e("babel-runtime/helpers/classCallCheck")),u=f(e("babel-runtime/helpers/createClass")),c=f(e("babel-runtime/helpers/possibleConstructorReturn")),l=f(e("babel-runtime/helpers/inherits"));function f(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var d=e("../entity"),p=e("../utils/sanitize"),h=e("../closeable"),b=function(e){function t(e,r,n){(0,a.default)(this,t);var i=(0,c.default)(this,(t.__proto__||(0,o.default)(t)).call(this,e,n));return i.descriptor=r,i}return(0,l.default)(t,e),(0,u.default)(t,[{key:"publishMessage",value:function(){var e=(0,s.default)(i.default.mark(function e(t){var r,n,s,o;return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r={data:t},e.next=3,this.services.network.post(this.links.messages,r);case 3:return n=e.sent,s=n.body,o=this._handleMessagePublished(s.sid,t,!1),e.abrupt("return",o);case 7:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"setTtl",value:function(){var e=(0,s.default)(i.default.mark(function e(t){var r,n;return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return p.validateMandatoryTtl(t),e.prev=1,r={ttl:t},e.next=5,this.services.network.post(this.uri,r);case 5:n=e.sent,this.descriptor.date_expires=n.body.date_expires,e.next=13;break;case 9:throw e.prev=9,e.t0=e.catch(1),404===e.t0.status&&this.onRemoved(!1),e.t0;case 13:case"end":return e.stop()}},e,this,[[1,9]])}));return function(t){return e.apply(this,arguments)}}()},{key:"removeStream",value:function(){var e=(0,s.default)(i.default.mark(function e(){return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.network.delete(this.uri);case 2:this.onRemoved(!0);case 3:case"end":return e.stop()}},e,this)}));return function(){return e.apply(this,arguments)}}()},{key:"_update",value:function(e){switch(e.type){case"stream_message_published":this._handleMessagePublished(e.message_sid,e.message_data,!0);break;case"stream_removed":this.onRemoved(!1)}}},{key:"_handleMessagePublished",value:function(e,t,r){var n={sid:e,value:t};return this.broadcastEventToListeners("messagePublished",{message:n,isLocal:!r}),n}},{key:"onRemoved",value:function(e){this._unsubscribe(),this.removalHandler(this.type,this.sid,this.uniqueName),this.broadcastEventToListeners("removed",{isLocal:e})}},{key:"uri",get:function(){return this.descriptor.url}},{key:"links",get:function(){return this.descriptor.links}},{key:"dateExpires",get:function(){return this.descriptor.date_expires}},{key:"type",get:function(){return"stream"}},{key:"lastEventId",get:function(){return null}},{key:"indexName",get:function(){}},{key:"queryString",get:function(){}},{key:"sid",get:function(){return this.descriptor.sid}},{key:"uniqueName",get:function(){return this.descriptor.unique_name||null}}],[{key:"type",get:function(){return"stream"}}]),t}(d.SyncEntity);r.SyncStreamImpl=b;var v=function(e){function t(e){(0,a.default)(this,t);var r=(0,c.default)(this,(t.__proto__||(0,o.default)(t)).call(this));return r.syncStreamImpl=e,r.syncStreamImpl.attach(r),r}return(0,l.default)(t,e),(0,u.default)(t,[{key:"publishMessage",value:function(){var e=(0,s.default)(i.default.mark(function e(t){return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncStreamImpl.publishMessage(t));case 2:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"setTtl",value:function(){var e=(0,s.default)(i.default.mark(function e(t){return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncStreamImpl.setTtl(t));case 2:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"removeStream",value:function(){var e=(0,s.default)(i.default.mark(function e(){return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncStreamImpl.removeStream());case 2:case"end":return e.stop()}},e,this)}));return function(){return e.apply(this,arguments)}}()},{key:"close",value:function(){(0,n.default)(t.prototype.__proto__||(0,o.default)(t.prototype),"close",this).call(this),this.syncStreamImpl.detach(this.listenerUuid)}},{key:"uri",get:function(){return this.syncStreamImpl.uri}},{key:"links",get:function(){return this.syncStreamImpl.links}},{key:"dateExpires",get:function(){return this.syncStreamImpl.dateExpires}},{key:"type",get:function(){return b.type}},{key:"lastEventId",get:function(){return null}},{key:"sid",get:function(){return this.syncStreamImpl.sid}},{key:"uniqueName",get:function(){return this.syncStreamImpl.uniqueName}}],[{key:"type",get:function(){return b.type}}]),t}(h.default);r.SyncStream=v,r.default=v},{"../closeable":4,"../entity":7,"../utils/sanitize":22,"babel-runtime/core-js/object/get-prototype-of":35,"babel-runtime/helpers/asyncToGenerator":42,"babel-runtime/helpers/classCallCheck":43,"babel-runtime/helpers/createClass":44,"babel-runtime/helpers/get":45,"babel-runtime/helpers/inherits":46,"babel-runtime/helpers/possibleConstructorReturn":47,"babel-runtime/regenerator":51}],17:[function(e,t,r){"use strict";var n=f(e("babel-runtime/regenerator")),i=f(e("babel-runtime/helpers/asyncToGenerator")),s=f(e("babel-runtime/core-js/get-iterator")),o=f(e("babel-runtime/helpers/slicedToArray")),a=f(e("babel-runtime/core-js/object/assign")),u=f(e("babel-runtime/core-js/map")),c=f(e("babel-runtime/helpers/classCallCheck")),l=f(e("babel-runtime/helpers/createClass"));function f(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var d=e("operation-retrier"),p=e("./utils/syncerror"),h=e("./utils/logger"),b=e("twilsock"),v=function(){function e(t){(0,c.default)(this,e),this.localObject=t,this.pendingCorrelationId=null,this.pendingAction=null,this.established=!1,this.retryCount=0}return(0,l.default)(e,[{key:"update",value:function(e,t){this.localObject._update(e,t)}},{key:"updatePending",value:function(e,t){this.pendingAction=e,this.pendingCorrelationId=t}},{key:"reset",value:function(){this.updatePending(null,null),this.retryCount=0,this.established=!1,this.setSubscriptionState("none")}},{key:"markAsFailed",value:function(e){this.rejectedWithError=e.error,this.updatePending(null,null),this.localObject.reportFailure(new p.SyncError("Failed to subscribe on service events: "+e.error.message,e.error.status,e.error.code))}},{key:"complete",value:function(e){this.updatePending(null,null),this.established=!0,this.localObject._advanceLastEventId(e)}},{key:"setSubscriptionState",value:function(e){this.localObject._setSubscriptionState(e)}},{key:"sid",get:function(){return this.localObject.sid}},{key:"type",get:function(){return this.localObject.type}},{key:"lastEventId",get:function(){return this.localObject.lastEventId}},{key:"indexName",get:function(){return this.localObject.indexName}},{key:"queryString",get:function(){return this.localObject.queryString}},{key:"isEstablished",get:function(){return this.established}}]),e}(),m=function(){function e(t){var r=this;(0,c.default)(this,e),this.isConnected=!1,this.maxBatchSize=100,this.subscriptionTtlTimer=null,this.pendingPokeReason=null,this.services=t,this.subscriptions=new u.default,this.persisted=new u.default,this.latestPokeResponseArrivalTimestampByCorrelationId=new u.default;this.backoff=d.Backoff.exponential((0,a.default)({randomisationFactor:.2,initialDelay:100,maxDelay:12e4},this.services.config.backoffConfig)),this.backoff.on("ready",function(){var e=r.getSubscriptionUpdateBatch(),t=e.action,n=e.subscriptions;t?r.applyNewSubscriptionUpdateBatch(t,n):(r.backoff.reset(),h.default.debug("All subscriptions resolved."))})}return(0,l.default)(e,[{key:"getSubscriptionUpdateBatch",value:function(){function e(e,t,r,n){var i=[],a=!0,u=!1,c=void 0;try{for(var l,f=(0,s.default)(e);!(a=(l=f.next()).done);a=!0){var d=l.value,p=(0,o.default)(d,2),h=p[0],b=p[1];if(!t.get(h)&&r!==b.pendingAction&&!b.rejectedWithError&&(i.push(b),n&&i.length>=n))break}}catch(e){u=!0,c=e}finally{try{!a&&f.return&&f.return()}finally{if(u)throw c}}return i}var t=e(this.subscriptions,this.persisted,"establish",this.maxBatchSize);if(t.length>0)return{action:"establish",subscriptions:t};var r=e(this.persisted,this.subscriptions,"cancel",this.maxBatchSize);return r.length>0?{action:"cancel",subscriptions:r}:{action:null,subscriptions:null}}},{key:"persist",value:function(){this.backoff.backoff()}},{key:"applyNewSubscriptionUpdateBatch",value:function(){var e=(0,i.default)(n.default.mark(function e(t,r){var i,o,a,u,c,l,f,d,p,v,m,y,g,_,k,w,x,j,C,S,T=this;return n.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(this.isConnected){e.next=4;break}return h.default.debug("Twilsock connection (required for subscription) not ready; waiting\u2026"),this.backoff.reset(),e.abrupt("return");case 4:for(r=this.processLocalActions(t,r),i=(new Date).getTime(),o=!0,a=!1,u=void 0,e.prev=9,c=(0,s.default)(r);!(o=(l=c.next()).done);o=!0)f=l.value,this.recordActionAttemptOn(f,t,i);e.next=17;break;case 13:e.prev=13,e.t0=e.catch(9),a=!0,u=e.t0;case 17:e.prev=17,e.prev=18,!o&&c.return&&c.return();case 20:if(e.prev=20,!a){e.next=23;break}throw u;case 23:return e.finish(20);case 24:return e.finish(17);case 25:return d=this.pendingPokeReason,this.pendingPokeReason=null,e.prev=27,e.next=30,this.request(t,i,d,r);case 30:p=e.sent,v=p.body.max_batch_size,!isNaN(parseInt(v))&&isFinite(v)&&v>0&&(this.maxBatchSize=v),this.subscriptionTtlTimer||(m=p.body.ttl_in_s,y=!isNaN(parseFloat(m))&&isFinite(m),y&&m>0&&(this.subscriptionTtlTimer=setTimeout(function(){return T.onSubscriptionTtlElapsed()},1e3*m))),"establish"===t&&(g=p.body.estimated_delivery_in_ms,_=!isNaN(parseFloat(g))&&isFinite(g),_&&g>0?setTimeout(function(){return T.verifyPokeDelivery(i,g,r)},g):h.default.error("Invalid timeout: "+g),r.filter(function(e){return e.pendingCorrelationId===i}).forEach(function(e){return e.setSubscriptionState("response_in_flight")})),this.backoff.reset(),e.next=60;break;case 38:for(e.prev=38,e.t1=e.catch(27),k=!0,w=!1,x=void 0,e.prev=43,j=(0,s.default)(r);!(k=(C=j.next()).done);k=!0)S=C.value,this.recordActionFailureOn(S,t);e.next=51;break;case 47:e.prev=47,e.t2=e.catch(43),w=!0,x=e.t2;case 51:e.prev=51,e.prev=52,!k&&j.return&&j.return();case 54:if(e.prev=54,!w){e.next=57;break}throw x;case 57:return e.finish(54);case 58:return e.finish(51);case 59:e.t1 instanceof b.TransportUnavailableError?(h.default.debug("Twilsock connection (required for subscription) not ready (c:"+i+"); waiting\u2026"),this.backoff.reset()):(h.default.debug("Failed an attempt to "+t+" subscriptions (c:"+i+"); retrying",e.t1),this.persist());case 60:case"end":return e.stop()}},e,this,[[9,13,17,25],[18,,20,24],[27,38],[43,47,51,59],[52,,54,58]])}));return function(t,r){return e.apply(this,arguments)}}()},{key:"verifyPokeDelivery",value:function(e,t,r){var n=this,i=this.latestPokeResponseArrivalTimestampByCorrelationId.get(e),s=i?(new Date).getTime()-i:t;s>=t?(r.filter(function(t){return t.pendingCorrelationId===e}).forEach(function(e){e.updatePending(null,null),e.retryCount++,n.persisted.delete(e.sid)}),this.persist(),this.latestPokeResponseArrivalTimestampByCorrelationId.delete(e)):setTimeout(function(){return n.verifyPokeDelivery(e,t,r)},t-s)}},{key:"processLocalActions",value:function(e,t){return"cancel"===e?t.filter(function(e){return!e.rejectedWithError}):t}},{key:"recordActionAttemptOn",value:function(e,t,r){if(e.setSubscriptionState("request_in_flight"),"establish"===t)this.persisted.set(e.sid,e),e.updatePending(t,r);else{var n=this.persisted.get(e.sid);n&&n.updatePending(t,r)}}},{key:"recordActionFailureOn",value:function(e,t){e.setSubscriptionState("none"),e.updatePending(null,null),"establish"===t&&this.persisted.delete(e.sid)}},{key:"request",value:function(e,t,r,n){var i=n.map(function(t){return{object_sid:t.sid,object_type:t.type,last_event_id:"establish"===e?t.lastEventId:void 0,index_name:"establish"===e?t.indexName:void 0,query_string:"establish"===e?t.queryString:void 0}}),s=n.filter(function(e){return e.retryCount>0}).length;h.default.debug("Attempting '"+e+"' request (c:"+t+"):",i);var o={event_protocol_version:3,action:e,correlation_id:t,retried_requests:s,ttl_in_s:-1,requests:i};return"ttl"===r&&(o.reason=r),this.services.network.post(this.services.config.subscriptionsUri,o)}},{key:"add",value:function(e,t){h.default.debug("Establishing intent to subscribe to "+e);var r=this.subscriptions.get(e);r&&t&&r.lastEventId===t.lastEventId||(this.persisted.delete(e),this.subscriptions.set(e,new v(t)),this.persist())}},{key:"remove",value:function(e){h.default.debug("Establishing intent to unsubscribe from "+e),this.subscriptions.delete(e)&&this.persist()}},{key:"acceptMessage",value:function(e,t){h.default.trace("Subscriptions received",e),e.correlation_id&&this.latestPokeResponseArrivalTimestampByCorrelationId.set(e.correlation_id,(new Date).getTime());var r=void 0;switch(e.event_type){case"subscription_established":this.applySubscriptionEstablishedMessage(e.event,e.correlation_id);break;case"subscription_canceled":this.applySubscriptionCancelledMessage(e.event,e.correlation_id);break;case"subscription_failed":this.applySubscriptionFailedMessage(e.event,e.correlation_id);break;case(r=e.event_type.match(/^(?:map|list|document|stream|live_query)_/)||{}).input:var n=void 0;switch(r[0]){case"map_":n=e.event.map_sid;break;case"list_":n=e.event.list_sid;break;case"document_":n=e.event.document_sid;break;case"stream_":n=e.event.stream_sid;break;case"live_query_":n=e.event.query_id,t=!1,!0===e.strictly_ordered&&(t=!0);break;default:n=void 0}this.applyEventToSubscribedEntity(n,e,t);break;default:h.default.debug("Dropping unknown message type "+e.event_type)}}},{key:"applySubscriptionEstablishedMessage",value:function(e,t){var r=e.object_sid,n=this.persisted.get(e.object_sid);n&&n.pendingCorrelationId===t?"interrupted"===e.replay_status?(h.default.debug("Event Replay for subscription to "+r+" (c:"+t+") interrupted; continuing eagerly."),n.updatePending(null,null),this.persisted.delete(n.sid),this.backoff.reset()):"completed"===e.replay_status&&(h.default.debug("Event Replay for subscription to "+r+" (c:"+t+") completed. Subscription is ready."),n.complete(e.last_event_id),this.persisted.set(e.object_sid,n),n.setSubscriptionState("established"),this.backoff.reset()):h.default.debug("Late message for "+e.object_sid+" (c:"+t+") dropped."),this.persist()}},{key:"applySubscriptionCancelledMessage",value:function(e,t){var r=this.persisted.get(e.object_sid);r&&r.pendingCorrelationId===t?(r.updatePending(null,null),r.setSubscriptionState("none"),this.persisted.delete(e.object_sid)):h.default.debug("Late message for "+e.object_sid+" (c:"+t+") dropped."),this.persist()}},{key:"applySubscriptionFailedMessage",value:function(e,t){var r=e.object_sid,n=this.subscriptions.get(r),i=this.persisted.get(r);n&&i?i.pendingCorrelationId===t&&(h.default.error("Failed to subscribe on "+i.sid,e.error),i.markAsFailed(e),i.setSubscriptionState("none")):!n&&i&&(this.persisted.delete(r),i.setSubscriptionState("none")),this.persist()}},{key:"applyEventToSubscribedEntity",value:function(e,t,r){if(e){var n;r=r||(n=this.persisted.get(e))&&n.isEstablished;var i=this.subscriptions.get(e);i?(t.event.type=t.event_type,i.update(t.event,r)):h.default.debug("Message dropped for SID '"+e+"', for which there is no subscription.")}}},{key:"onConnectionStateChanged",value:function(e){this.isConnected=e,e&&this.poke("reconnect")}},{key:"onSubscriptionTtlElapsed",value:function(){this.isConnected&&this.poke("ttl")}},{key:"poke",value:function(e){h.default.debug("Triggering event replay for all subscriptions, reason="+e),this.pendingPokeReason=e,this.subscriptionTtlTimer&&(clearTimeout(this.subscriptionTtlTimer),this.subscriptionTtlTimer=null);var t=[],r=!0,n=!1,i=void 0;try{for(var o,a=(0,s.default)(this.persisted.values());!(r=(o=a.next()).done);r=!0){var u=o.value;u.reset(),u.rejectedWithError&&t.push(u)}}catch(e){n=!0,i=e}finally{try{!r&&a.return&&a.return()}finally{if(n)throw i}}this.persisted.clear();var c=!0,l=!1,f=void 0;try{for(var d,p=(0,s.default)(t);!(c=(d=p.next()).done);c=!0){var b=d.value;this.persisted.set(b.sid,b)}}catch(e){l=!0,f=e}finally{try{!c&&p.return&&p.return()}finally{if(l)throw f}}this.persist()}},{key:"shutdown",value:function(){this.backoff.reset(),this.subscriptions.clear()}}]),e}();r.Subscriptions=m},{"./utils/logger":21,"./utils/syncerror":23,"babel-runtime/core-js/get-iterator":27,"babel-runtime/core-js/map":30,"babel-runtime/core-js/object/assign":31,"babel-runtime/helpers/asyncToGenerator":42,"babel-runtime/helpers/classCallCheck":43,"babel-runtime/helpers/createClass":44,"babel-runtime/helpers/slicedToArray":48,"babel-runtime/regenerator":51,"operation-retrier":188,twilsock:209}],18:[function(e,t,r){"use strict";var n=p(e("babel-runtime/helpers/get")),i=p(e("babel-runtime/core-js/promise")),s=p(e("babel-runtime/core-js/object/assign")),o=p(e("babel-runtime/regenerator")),a=p(e("babel-runtime/helpers/asyncToGenerator")),u=p(e("babel-runtime/core-js/object/get-prototype-of")),c=p(e("babel-runtime/helpers/classCallCheck")),l=p(e("babel-runtime/helpers/createClass")),f=p(e("babel-runtime/helpers/possibleConstructorReturn")),d=p(e("babel-runtime/helpers/inherits"));function p(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var h=e("./utils/syncerror"),b=e("./utils/sanitize"),v=e("./utils/logger"),m=e("./entity"),y=e("./mergingqueue"),g=e("./closeable"),_=function(e){function t(e,r,n){(0,c.default)(this,t);var i=(0,f.default)(this,(t.__proto__||(0,u.default)(t)).call(this,e,n));i.isDeleted=!1;return i.updateMergingQueue=new y.MergingQueue(function(e,t){return"number"==typeof t.ttl?{ttl:t.ttl}:e}),i.descriptor=r,i.descriptor.data=i.descriptor.data||{},i.descriptor.date_updated=new Date(i.descriptor.date_updated),i}return(0,d.default)(t,e),(0,l.default)(t,[{key:"_update",value:function(e){switch(e.date_created=new Date(e.date_created),e.type){case"document_updated":e.id>this.lastEventId?(this.descriptor.last_event_id=e.id,this.descriptor.revision=e.document_revision,this.descriptor.date_updated=e.date_created,this.descriptor.data=e.document_data,this.broadcastEventToListeners("updated",{value:e.document_data,isLocal:!1}),this.services.storage.update(this.type,this.sid,this.uniqueName,{last_event_id:e.id,revision:e.document_revision,date_updated:e.date_created,data:e.document_data})):v.default.trace("Document update skipped, current:",this.lastEventId,", remote:",e.id);break;case"document_removed":this.onRemoved(!1)}}},{key:"set",value:function(){var e=(0,a.default)(o.default.mark(function e(t,r){var n,i=this;return o.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return n=r||{},b.validateOptionalTtl(n.ttl),e.abrupt("return",this.updateMergingQueue.squashAndAdd(n,function(e){return i._setUnconditionally(t,e.ttl)}));case 3:case"end":return e.stop()}},e,this)}));return function(t,r){return e.apply(this,arguments)}}()},{key:"mutate",value:function(){var e=(0,a.default)(o.default.mark(function e(t,r){var n,i=this;return o.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return n=r||{},b.validateOptionalTtl(n.ttl),e.abrupt("return",this.updateMergingQueue.add(n,function(e){return i._setWithIfMatch(t,e.ttl)}));case 3:case"end":return e.stop()}},e,this)}));return function(t,r){return e.apply(this,arguments)}}()},{key:"update",value:function(){var e=(0,a.default)(o.default.mark(function e(t,r){return o.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.mutate(function(e){return(0,s.default)(e,t)},r));case 1:case"end":return e.stop()}},e,this)}));return function(t,r){return e.apply(this,arguments)}}()},{key:"setTtl",value:function(){var e=(0,a.default)(o.default.mark(function e(t){var r;return o.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return b.validateMandatoryTtl(t),e.next=3,this._postUpdateToServer({ttl:t});case 3:r=e.sent,this.descriptor.date_expires=r.date_expires;case 5:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"_setUnconditionally",value:function(){var e=(0,a.default)(o.default.mark(function e(t,r){var n;return o.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._postUpdateToServer({data:t,revision:void 0,ttl:r});case 2:return n=e.sent,this._handleSuccessfulUpdateResult(n),e.abrupt("return",this.value);case 5:case"end":return e.stop()}},e,this)}));return function(t,r){return e.apply(this,arguments)}}()},{key:"_setWithIfMatch",value:function(){var e=(0,a.default)(o.default.mark(function e(t,r){var n,i,s;return o.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!(n=t(b.deepClone(this.value)))){e.next=22;break}return i=this.revision,e.prev=3,e.next=6,this._postUpdateToServer({data:n,revision:i,ttl:r});case 6:return s=e.sent,this._handleSuccessfulUpdateResult(s),e.abrupt("return",this.value);case 11:if(e.prev=11,e.t0=e.catch(3),412!==e.t0.status){e.next=19;break}return e.next=16,this._softSync();case 16:return e.abrupt("return",this._setWithIfMatch(t));case 19:throw e.t0;case 20:e.next=23;break;case 22:return e.abrupt("return",this.value);case 23:case"end":return e.stop()}},e,this,[[3,11]])}));return function(t,r){return e.apply(this,arguments)}}()},{key:"_handleSuccessfulUpdateResult",value:function(e){e.last_event_id>this.descriptor.last_event_id&&(this.descriptor.revision=e.revision,this.descriptor.data=e.data,this.descriptor.last_event_id=e.last_event_id,this.descriptor.date_expires=e.date_expires,this.descriptor.date_updated=new Date(e.date_updated),this.services.storage.update(this.type,this.sid,this.uniqueName,{last_event_id:e.last_event_id,revision:e.revision,date_updated:e.date_updated,data:e.data}),this.broadcastEventToListeners("updated",{value:this.value,isLocal:!0}))}},{key:"_postUpdateToServer",value:function(){var e=(0,a.default)(o.default.mark(function e(t){var r,n,s;return o.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(this.isDeleted){e.next=17;break}return r={data:t.data},void 0!==t.ttl&&(r.ttl=t.ttl),n=t.revision,e.prev=4,e.next=7,this.services.network.post(this.uri,r,n);case 7:return s=e.sent,e.abrupt("return",{revision:s.body.revision,data:t.data,last_event_id:s.body.last_event_id,date_updated:s.body.date_updated,date_expires:s.body.date_expires});case 11:throw e.prev=11,e.t0=e.catch(4),404===e.t0.status&&this.onRemoved(!1),e.t0;case 15:e.next=18;break;case 17:return e.abrupt("return",i.default.reject(new h.SyncError("The Document has been removed",404,54100)));case 18:case"end":return e.stop()}},e,this,[[4,11]])}));return function(t){return e.apply(this,arguments)}}()},{key:"_softSync",value:function(){var e=(0,a.default)(o.default.mark(function e(){var t=this;return o.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.services.network.get(this.uri).then(function(e){var r={type:"document_updated",id:e.body.last_event_id,document_revision:e.body.revision,document_data:e.body.data,date_created:e.body.date_updated};return t._update(r),t}).catch(function(e){404===e.status?t.onRemoved(!1):v.default.error("Can't get updates for "+t.sid+":",e)}));case 1:case"end":return e.stop()}},e,this)}));return function(){return e.apply(this,arguments)}}()},{key:"onRemoved",value:function(e){this.isDeleted||(this.isDeleted=!0,this._unsubscribe(),this.removalHandler(this.type,this.sid,this.uniqueName),this.broadcastEventToListeners("removed",{isLocal:e}))}},{key:"removeDocument",value:function(){var e=(0,a.default)(o.default.mark(function e(){return o.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(this.isDeleted){e.next=6;break}return e.next=3,this.services.network.delete(this.uri);case 3:this.onRemoved(!0),e.next=7;break;case 6:return e.abrupt("return",i.default.reject(new h.SyncError("The Document has been removed",404,54100)));case 7:case"end":return e.stop()}},e,this)}));return function(){return e.apply(this,arguments)}}()},{key:"uri",get:function(){return this.descriptor.url}},{key:"revision",get:function(){return this.descriptor.revision}},{key:"lastEventId",get:function(){return this.descriptor.last_event_id}},{key:"dateExpires",get:function(){return this.descriptor.date_expires}},{key:"type",get:function(){return"document"}},{key:"indexName",get:function(){}},{key:"queryString",get:function(){}},{key:"sid",get:function(){return this.descriptor.sid}},{key:"value",get:function(){return this.descriptor.data}},{key:"dateUpdated",get:function(){return this.descriptor.date_updated}},{key:"uniqueName",get:function(){return this.descriptor.unique_name||null}}],[{key:"type",get:function(){return"document"}}]),t}(m.SyncEntity);r.SyncDocumentImpl=_;var k=function(e){function t(e){(0,c.default)(this,t);var r=(0,f.default)(this,(t.__proto__||(0,u.default)(t)).call(this));return r.syncDocumentImpl=e,r.syncDocumentImpl.attach(r),r}return(0,d.default)(t,e),(0,l.default)(t,[{key:"set",value:function(){var e=(0,a.default)(o.default.mark(function e(t,r){return o.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncDocumentImpl.set(t,r));case 2:case"end":return e.stop()}},e,this)}));return function(t,r){return e.apply(this,arguments)}}()},{key:"mutate",value:function(){var e=(0,a.default)(o.default.mark(function e(t,r){return o.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncDocumentImpl.mutate(t,r));case 2:case"end":return e.stop()}},e,this)}));return function(t,r){return e.apply(this,arguments)}}()},{key:"update",value:function(){var e=(0,a.default)(o.default.mark(function e(t,r){return o.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncDocumentImpl.update(t,r));case 2:case"end":return e.stop()}},e,this)}));return function(t,r){return e.apply(this,arguments)}}()},{key:"setTtl",value:function(){var e=(0,a.default)(o.default.mark(function e(t){return o.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncDocumentImpl.setTtl(t));case 2:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"removeDocument",value:function(){var e=(0,a.default)(o.default.mark(function e(){return o.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncDocumentImpl.removeDocument());case 2:case"end":return e.stop()}},e,this)}));return function(){return e.apply(this,arguments)}}()},{key:"close",value:function(){(0,n.default)(t.prototype.__proto__||(0,u.default)(t.prototype),"close",this).call(this),this.syncDocumentImpl.detach(this.listenerUuid)}},{key:"uri",get:function(){return this.syncDocumentImpl.uri}},{key:"revision",get:function(){return this.syncDocumentImpl.revision}},{key:"lastEventId",get:function(){return this.syncDocumentImpl.lastEventId}},{key:"dateExpires",get:function(){return this.syncDocumentImpl.dateExpires}},{key:"type",get:function(){return _.type}},{key:"sid",get:function(){return this.syncDocumentImpl.sid}},{key:"value",get:function(){return this.syncDocumentImpl.value}},{key:"dateUpdated",get:function(){return this.syncDocumentImpl.dateUpdated}},{key:"uniqueName",get:function(){return this.syncDocumentImpl.uniqueName}}],[{key:"type",get:function(){return _.type}}]),t}(g.default);r.SyncDocument=k,r.default=k},{"./closeable":4,"./entity":7,"./mergingqueue":11,"./utils/logger":21,"./utils/sanitize":22,"./utils/syncerror":23,"babel-runtime/core-js/object/assign":31,"babel-runtime/core-js/object/get-prototype-of":35,"babel-runtime/core-js/promise":37,"babel-runtime/helpers/asyncToGenerator":42,"babel-runtime/helpers/classCallCheck":43,"babel-runtime/helpers/createClass":44,"babel-runtime/helpers/get":45,"babel-runtime/helpers/inherits":46,"babel-runtime/helpers/possibleConstructorReturn":47,"babel-runtime/regenerator":51}],19:[function(e,t,r){"use strict";var n=d(e("babel-runtime/helpers/get")),i=d(e("babel-runtime/core-js/object/assign")),s=d(e("babel-runtime/regenerator")),o=d(e("babel-runtime/helpers/asyncToGenerator")),a=d(e("babel-runtime/core-js/object/get-prototype-of")),u=d(e("babel-runtime/helpers/classCallCheck")),c=d(e("babel-runtime/helpers/createClass")),l=d(e("babel-runtime/helpers/possibleConstructorReturn")),f=d(e("babel-runtime/helpers/inherits"));function d(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var p=e("./utils/sanitize"),h=e("./utils/uri"),b=e("./utils/syncerror"),v=e("./utils/logger"),m=e("./entity"),y=e("./listitem"),g=e("./paginator"),_=e("./cache"),k=e("./mergingqueue"),w=e("./closeable"),x=function(e){function t(e,r,n){(0,u.default)(this,t);var i=(0,l.default)(this,(t.__proto__||(0,a.default)(t)).call(this,e,n));return i.updateMergingQueue=new k.NamespacedMergingQueue(function(e,t){return"number"==typeof t.ttl?{ttl:t.ttl}:e}),i.cache=new _.Cache,i.descriptor=r,i.descriptor.date_updated=new Date(i.descriptor.date_updated),i}return(0,f.default)(t,e),(0,c.default)(t,[{key:"_addOrUpdateItemOnServer",value:function(){var e=(0,o.default)(s.default.mark(function e(t,r,n,i){var o,a;return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return o={data:r},void 0!==i&&(o.ttl=i),e.next=4,this.services.network.post(t,o,n);case 4:return(a=e.sent).body.data=r,a.body.date_updated=new Date(a.body.date_updated),e.abrupt("return",a.body);case 8:case"end":return e.stop()}},e,this)}));return function(t,r,n,i){return e.apply(this,arguments)}}()},{key:"push",value:function(){var e=(0,o.default)(s.default.mark(function e(t,r){var n,i,o;return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return n=(r||{}).ttl,p.validateOptionalTtl(n),e.next=4,this._addOrUpdateItemOnServer(this.links.items,t,void 0,n);case 4:return i=e.sent,o=Number(i.index),this._handleItemMutated(o,i.url,i.last_event_id,i.revision,t,i.date_updated,i.date_expires,!0,!1),e.abrupt("return",this.cache.get(o));case 8:case"end":return e.stop()}},e,this)}));return function(t,r){return e.apply(this,arguments)}}()},{key:"set",value:function(){var e=(0,o.default)(s.default.mark(function e(t,r,n){var i,o=this;return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return i=n||{},p.validateOptionalTtl(i.ttl),e.abrupt("return",this.updateMergingQueue.squashAndAdd(t,i,function(e){return o._updateItemUnconditionally(t,r,e.ttl)}));case 3:case"end":return e.stop()}},e,this)}));return function(t,r,n){return e.apply(this,arguments)}}()},{key:"_updateItemUnconditionally",value:function(){var e=(0,o.default)(s.default.mark(function e(t,r,n){var i,o;return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.get(t);case 2:return i=e.sent,e.next=5,this._addOrUpdateItemOnServer(i.uri,r,void 0,n);case 5:return o=e.sent,this._handleItemMutated(t,o.url,o.last_event_id,o.revision,o.data,o.date_updated,o.date_expires,!1,!1),e.abrupt("return",this.cache.get(t));case 8:case"end":return e.stop()}},e,this)}));return function(t,r,n){return e.apply(this,arguments)}}()},{key:"_updateItemWithIfMatch",value:function(){var e=(0,o.default)(s.default.mark(function e(t,r,n){var i,o,a,u;return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.get(t);case 2:if(i=e.sent,!(o=r(p.deepClone(i.value)))){e.next=25;break}return a=i.revision,e.prev=6,e.next=9,this._addOrUpdateItemOnServer(i.uri,o,a,n);case 9:return u=e.sent,this._handleItemMutated(t,u.url,u.last_event_id,u.revision,u.data,u.date_updated,u.date_expires,!1,!1),e.abrupt("return",this.cache.get(t));case 14:if(e.prev=14,e.t0=e.catch(6),412!==e.t0.status){e.next=22;break}return e.next=19,this._getItemFromServer(t);case 19:return e.abrupt("return",this._updateItemWithIfMatch(t,r,n));case 22:throw e.t0;case 23:e.next=26;break;case 25:return e.abrupt("return",i);case 26:case"end":return e.stop()}},e,this,[[6,14]])}));return function(t,r,n){return e.apply(this,arguments)}}()},{key:"mutate",value:function(){var e=(0,o.default)(s.default.mark(function e(t,r,n){var i,o=this;return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return i=n||{},p.validateOptionalTtl(i.ttl),e.abrupt("return",this.updateMergingQueue.add(t,i,function(e){return o._updateItemWithIfMatch(t,r,e.ttl)}));case 3:case"end":return e.stop()}},e,this)}));return function(t,r,n){return e.apply(this,arguments)}}()},{key:"update",value:function(){var e=(0,o.default)(s.default.mark(function e(t,r,n){return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.mutate(t,function(e){return(0,i.default)(e,r)},n));case 1:case"end":return e.stop()}},e,this)}));return function(t,r,n){return e.apply(this,arguments)}}()},{key:"remove",value:function(){var e=(0,o.default)(s.default.mark(function e(t){var r,n;return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.get(t);case 2:return r=e.sent,e.next=5,this.services.network.delete(r.uri);case 5:n=e.sent,this._handleItemRemoved(t,n.body.last_event_id,void 0,new Date(n.body.date_updated),!1);case 7:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"get",value:function(){var e=(0,o.default)(s.default.mark(function e(t){var r;return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!(r=this.cache.get(t))){e.next=5;break}return e.abrupt("return",r);case 5:return e.abrupt("return",this._getItemFromServer(t));case 6:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"_getItemFromServer",value:function(){var e=(0,o.default)(s.default.mark(function e(t){var r;return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.queryItems({index:t});case 2:if(!((r=e.sent).items.length<1)){e.next=7;break}throw new b.SyncError("No item with index "+t+" found",404,54151);case 7:return e.abrupt("return",r.items[0]);case 8:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"queryItems",value:function(){var e=(0,o.default)(s.default.mark(function e(t){var r,n,i,o,a=this;return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t=t||{},r=new h.UriBuilder(this.links.items).queryParam("From",t.from).queryParam("PageSize",t.limit).queryParam("Index",t.index).queryParam("PageToken",t.pageToken).queryParam("Order",t.order).build(),e.next=4,this.services.network.get(r);case 4:return n=e.sent,i=n.body.items.map(function(e){return e.date_updated=new Date(e.date_updated),a.cache.get(e.index)?a._handleItemMutated(e.index,e.url,e.last_event_id,e.revision,e.data,e.date_updated,e.date_expires,!1,!0):a.cache.store(Number(e.index),new y.ListItem({index:Number(e.index),uri:e.url,revision:e.revision,lastEventId:e.last_event_id,dateUpdated:e.date_updated,dateExpires:e.date_expires,value:e.data}),e.last_event_id),a.cache.get(e.index)}),o=n.body.meta,e.abrupt("return",new g.Paginator(i,function(e){return a.queryItems({pageToken:e})},o.previous_token,o.next_token));case 8:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"getItems",value:function(){var e=(0,o.default)(s.default.mark(function e(t){return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t=t||{},p.validatePageSize(t.pageSize),t.limit=t.pageSize||t.limit||50,t.order=t.order||"asc",e.abrupt("return",this.queryItems(t));case 5:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"getContext",value:function(){var e=(0,o.default)(s.default.mark(function e(){var t;return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(this.context){e.next=5;break}return e.next=3,this.services.network.get(this.links.context);case 3:t=e.sent,this._updateContextIfRequired(t.body.data,t.body.last_event_id);case 5:return e.abrupt("return",this.context);case 6:case"end":return e.stop()}},e,this)}));return function(){return e.apply(this,arguments)}}()},{key:"setTtl",value:function(){var e=(0,o.default)(s.default.mark(function e(t){var r,n;return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return p.validateMandatoryTtl(t),e.prev=1,r={ttl:t},e.next=5,this.services.network.post(this.uri,r);case 5:n=e.sent,this.descriptor.date_expires=n.body.date_expires,e.next=13;break;case 9:throw e.prev=9,e.t0=e.catch(1),404===e.t0.status&&this.onRemoved(!1),e.t0;case 13:case"end":return e.stop()}},e,this,[[1,9]])}));return function(t){return e.apply(this,arguments)}}()},{key:"setItemTtl",value:function(){var e=(0,o.default)(s.default.mark(function e(t,r){var n,i,o;return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return p.validateMandatoryTtl(r),e.next=3,this.get(t);case 3:return n=e.sent,i={ttl:r},e.next=7,this.services.network.post(n.uri,i);case 7:o=e.sent,n.updateDateExpires(o.body.date_expires);case 9:case"end":return e.stop()}},e,this)}));return function(t,r){return e.apply(this,arguments)}}()},{key:"removeList",value:function(){var e=(0,o.default)(s.default.mark(function e(){return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.network.delete(this.uri);case 2:this.onRemoved(!0);case 3:case"end":return e.stop()}},e,this)}));return function(){return e.apply(this,arguments)}}()},{key:"onRemoved",value:function(e){this._unsubscribe(),this.removalHandler(this.type,this.sid,this.uniqueName),this.broadcastEventToListeners("removed",{isLocal:e})}},{key:"shouldIgnoreEvent",value:function(e,t){return this.cache.isKnown(e,t)}},{key:"_update",value:function(e,t){var r=Number(e.item_index);switch(e.date_created=new Date(e.date_created),e.type){case"list_item_added":case"list_item_updated":this._handleItemMutated(r,e.item_url,e.id,e.item_revision,e.item_data,e.date_created,void 0,"list_item_added"===e.type,!0);break;case"list_item_removed":this._handleItemRemoved(r,e.id,e.item_data,e.date_created,!0);break;case"list_context_updated":this._handleContextUpdate(e.context_data,e.id,e.date_created);break;case"list_removed":this.onRemoved(!1)}t&&this._advanceLastEventId(e.id,e.list_revision)}},{key:"_advanceLastEventId",value:function(e,t){this.lastEventId<e&&(this.descriptor.last_event_id=e,t&&(this.descriptor.revision=t))}},{key:"_updateRootDateUpdated",value:function(e){(!this.descriptor.date_updated||e.getTime()>this.descriptor.date_updated.getTime())&&(this.descriptor.date_updated=e,this.services.storage.update(this.type,this.sid,this.uniqueName,{date_updated:e}))}},{key:"_handleItemMutated",value:function(e,t,r,n,i,s,o,a,u){if(this.shouldIgnoreEvent(e,r))v.default.trace("Item ",e," update skipped, current:",this.lastEventId,", remote:",r);else{this._updateRootDateUpdated(s);var c=this.cache.get(e);if(c)c.update(r,n,i,s),this.cache.store(e,c,r),void 0!==o&&c.updateDateExpires(o),this.emitItemMutationEvent(c,u,!1);else{var l=new y.ListItem({index:e,uri:t,lastEventId:r,revision:n,value:i,dateUpdated:s,dateExpires:o});this.cache.store(e,l,r),this.emitItemMutationEvent(l,u,a)}}}},{key:"emitItemMutationEvent",value:function(e,t,r){var n=r?"itemAdded":"itemUpdated";this.broadcastEventToListeners(n,{item:e,isLocal:!t})}},{key:"_handleItemRemoved",value:function(e,t,r,n,i){this._updateRootDateUpdated(n),this.cache.delete(e,t),this.broadcastEventToListeners("itemRemoved",{index:e,isLocal:!i,value:r})}},{key:"_handleContextUpdate",value:function(e,t,r){this._updateRootDateUpdated(r),this._updateContextIfRequired(e,t)&&this.broadcastEventToListeners("contextUpdated",{context:e,isLocal:!1})}},{key:"_updateContextIfRequired",value:function(e,t){return!this.contextEventId||t>this.contextEventId?(this.context=e,this.contextEventId=t,!0):(v.default.trace("Context update skipped, current:",this.lastEventId,", remote:",t),!1)}},{key:"uri",get:function(){return this.descriptor.url}},{key:"revision",get:function(){return this.descriptor.revision}},{key:"lastEventId",get:function(){return this.descriptor.last_event_id}},{key:"links",get:function(){return this.descriptor.links}},{key:"dateExpires",get:function(){return this.descriptor.date_expires}},{key:"type",get:function(){return"list"}},{key:"indexName",get:function(){}},{key:"queryString",get:function(){}},{key:"sid",get:function(){return this.descriptor.sid}},{key:"uniqueName",get:function(){return this.descriptor.unique_name||null}},{key:"dateUpdated",get:function(){return this.descriptor.date_updated}}],[{key:"type",get:function(){return"list"}}]),t}(m.SyncEntity);r.SyncListImpl=x;var j=function(e){function t(e){(0,u.default)(this,t);var r=(0,l.default)(this,(t.__proto__||(0,a.default)(t)).call(this));return r.syncListImpl=e,r.syncListImpl.attach(r),r}return(0,f.default)(t,e),(0,c.default)(t,[{key:"push",value:function(){var e=(0,o.default)(s.default.mark(function e(t,r){return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncListImpl.push(t,r));case 2:case"end":return e.stop()}},e,this)}));return function(t,r){return e.apply(this,arguments)}}()},{key:"set",value:function(){var e=(0,o.default)(s.default.mark(function e(t,r,n){return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncListImpl.set(t,r,n));case 2:case"end":return e.stop()}},e,this)}));return function(t,r,n){return e.apply(this,arguments)}}()},{key:"mutate",value:function(){var e=(0,o.default)(s.default.mark(function e(t,r,n){return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncListImpl.mutate(t,r,n));case 2:case"end":return e.stop()}},e,this)}));return function(t,r,n){return e.apply(this,arguments)}}()},{key:"update",value:function(){var e=(0,o.default)(s.default.mark(function e(t,r,n){return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncListImpl.update(t,r,n));case 2:case"end":return e.stop()}},e,this)}));return function(t,r,n){return e.apply(this,arguments)}}()},{key:"remove",value:function(){var e=(0,o.default)(s.default.mark(function e(t){return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncListImpl.remove(t));case 2:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"get",value:function(){var e=(0,o.default)(s.default.mark(function e(t){return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncListImpl.get(t));case 2:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"getContext",value:function(){var e=(0,o.default)(s.default.mark(function e(){return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncListImpl.getContext());case 2:case"end":return e.stop()}},e,this)}));return function(){return e.apply(this,arguments)}}()},{key:"getItems",value:function(){var e=(0,o.default)(s.default.mark(function e(t){return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncListImpl.getItems(t));case 2:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"setTtl",value:function(){var e=(0,o.default)(s.default.mark(function e(t){return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncListImpl.setTtl(t));case 2:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"setItemTtl",value:function(){var e=(0,o.default)(s.default.mark(function e(t,r){return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncListImpl.setItemTtl(t,r));case 2:case"end":return e.stop()}},e,this)}));return function(t,r){return e.apply(this,arguments)}}()},{key:"removeList",value:function(){var e=(0,o.default)(s.default.mark(function e(){return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncListImpl.removeList());case 2:case"end":return e.stop()}},e,this)}));return function(){return e.apply(this,arguments)}}()},{key:"close",value:function(){(0,n.default)(t.prototype.__proto__||(0,a.default)(t.prototype),"close",this).call(this),this.syncListImpl.detach(this.listenerUuid)}},{key:"uri",get:function(){return this.syncListImpl.uri}},{key:"revision",get:function(){return this.syncListImpl.revision}},{key:"lastEventId",get:function(){return this.syncListImpl.lastEventId}},{key:"links",get:function(){return this.syncListImpl.links}},{key:"dateExpires",get:function(){return this.syncListImpl.dateExpires}},{key:"type",get:function(){return x.type}},{key:"sid",get:function(){return this.syncListImpl.sid}},{key:"uniqueName",get:function(){return this.syncListImpl.uniqueName}},{key:"dateUpdated",get:function(){return this.syncListImpl.dateUpdated}}],[{key:"type",get:function(){return x.type}}]),t}(w.default);r.SyncList=j,r.default=j},{"./cache":1,"./closeable":4,"./entity":7,"./listitem":8,"./mergingqueue":11,"./paginator":12,"./utils/logger":21,"./utils/sanitize":22,"./utils/syncerror":23,"./utils/uri":25,"babel-runtime/core-js/object/assign":31,"babel-runtime/core-js/object/get-prototype-of":35,"babel-runtime/helpers/asyncToGenerator":42,"babel-runtime/helpers/classCallCheck":43,"babel-runtime/helpers/createClass":44,"babel-runtime/helpers/get":45,"babel-runtime/helpers/inherits":46,"babel-runtime/helpers/possibleConstructorReturn":47,"babel-runtime/regenerator":51}],20:[function(e,t,r){"use strict";var n=d(e("babel-runtime/helpers/get")),i=d(e("babel-runtime/core-js/object/assign")),s=d(e("babel-runtime/regenerator")),o=d(e("babel-runtime/helpers/asyncToGenerator")),a=d(e("babel-runtime/core-js/object/get-prototype-of")),u=d(e("babel-runtime/helpers/classCallCheck")),c=d(e("babel-runtime/helpers/createClass")),l=d(e("babel-runtime/helpers/possibleConstructorReturn")),f=d(e("babel-runtime/helpers/inherits"));function d(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var p=e("./utils/sanitize"),h=e("./utils/uri"),b=e("./utils/syncerror"),v=e("./utils/logger"),m=e("./entity"),y=e("./mapitem"),g=e("./paginator"),_=e("./cache"),k=e("./mergingqueue"),w=e("./closeable"),x=function(e){function t(e,r,n){(0,u.default)(this,t);var i=(0,l.default)(this,(t.__proto__||(0,a.default)(t)).call(this,e,n));return i.updateMergingQueue=new k.NamespacedMergingQueue(function(e,t){return"number"==typeof t.ttl?{ttl:t.ttl}:e}),i.cache=new _.Cache,i.descriptor=r,i.descriptor.date_updated=new Date(i.descriptor.date_updated),r.items&&r.items.forEach(function(e){e.date_updated=new Date(e.date_updated),i.cache.store(e.key,new y.MapItem(e),e.last_event_id)}),i}return(0,f.default)(t,e),(0,c.default)(t,[{key:"set",value:function(){var e=(0,o.default)(s.default.mark(function e(t,r,n){var i,o=this;return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return i=n||{},p.validateOptionalTtl(i.ttl),e.abrupt("return",this.updateMergingQueue.squashAndAdd(t,i,function(e){return o._putItemUnconditionally(t,r,e.ttl)}));case 3:case"end":return e.stop()}},e,this)}));return function(t,r,n){return e.apply(this,arguments)}}()},{key:"get",value:function(){var e=(0,o.default)(s.default.mark(function e(t){return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.cache.has(t)){e.next=4;break}return e.abrupt("return",this.cache.get(t));case 4:return e.abrupt("return",this._getItemFromServer(t));case 5:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"_getItemFromServer",value:function(){var e=(0,o.default)(s.default.mark(function e(t){var r;return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.queryItems({key:t});case 2:if(!((r=e.sent).items.length<1)){e.next=7;break}throw new b.SyncError("No item with key "+t+" found",404,54201);case 7:return e.abrupt("return",r.items[0]);case 8:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"mutate",value:function(){var e=(0,o.default)(s.default.mark(function e(t,r,n){var i,o=this;return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return i=n||{},p.validateOptionalTtl(i.ttl),e.abrupt("return",this.updateMergingQueue.add(t,i,function(e){return o._putItemWithIfMatch(t,r,e.ttl)}));case 3:case"end":return e.stop()}},e,this)}));return function(t,r,n){return e.apply(this,arguments)}}()},{key:"update",value:function(){var e=(0,o.default)(s.default.mark(function e(t,r,n){return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.mutate(t,function(e){return(0,i.default)(e,r)},n));case 1:case"end":return e.stop()}},e,this)}));return function(t,r,n){return e.apply(this,arguments)}}()},{key:"_putItemUnconditionally",value:function(){var e=(0,o.default)(s.default.mark(function e(t,r,n){var i,o;return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._putItemToServer(t,r,void 0,n);case 2:return i=e.sent,o=i.item,this._handleItemMutated(o.key,o.url,o.last_event_id,o.revision,o.data,o.date_updated,o.date_expires,i.added,!1),e.abrupt("return",this.cache.get(o.key));case 6:case"end":return e.stop()}},e,this)}));return function(t,r,n){return e.apply(this,arguments)}}()},{key:"_putItemWithIfMatch",value:function(){var e=(0,o.default)(s.default.mark(function e(t,r,n){var i,o,a,u,c;return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.get(t).catch(function(e){if(404===e.status)return new y.MapItem({key:t,data:{},last_event_id:-1,revision:"-1",url:null,date_updated:null,date_expires:null});throw e});case 2:if(i=e.sent,!(o=r(p.deepClone(i.value)))){e.next=26;break}return a=i.revision,e.prev=6,e.next=9,this._putItemToServer(t,o,a,n);case 9:return u=e.sent,c=u.item,this._handleItemMutated(c.key,c.url,c.last_event_id,c.revision,c.data,c.date_updated,c.date_expires,u.added,!1),e.abrupt("return",this.cache.get(c.key));case 15:if(e.prev=15,e.t0=e.catch(6),412!==e.t0.status){e.next=23;break}return e.next=20,this._getItemFromServer(t);case 20:return e.abrupt("return",this._putItemWithIfMatch(t,r,n));case 23:throw e.t0;case 24:e.next=27;break;case 26:return e.abrupt("return",i);case 27:case"end":return e.stop()}},e,this,[[6,15]])}));return function(t,r,n){return e.apply(this,arguments)}}()},{key:"_putItemToServer",value:function(){var e=(0,o.default)(s.default.mark(function e(t,r,n,i){var o,a,u,c,l;return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return o=new h.UriBuilder(this.links.items).pathSegment(t).build(),a={data:r},void 0!==i&&(a.ttl=i),e.prev=3,e.next=6,this.services.network.put(o,a,n);case 6:return u=e.sent,(c=u.body).data=r,c.date_updated=new Date(c.date_updated),l=201===u.status.code,e.abrupt("return",{added:l,item:c});case 14:throw e.prev=14,e.t0=e.catch(3),404===e.t0.status&&this.onRemoved(!1),e.t0;case 18:case"end":return e.stop()}},e,this,[[3,14]])}));return function(t,r,n,i){return e.apply(this,arguments)}}()},{key:"remove",value:function(){var e=(0,o.default)(s.default.mark(function e(t){var r,n;return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(void 0!==t){e.next=2;break}throw new Error("Key argument is invalid");case 2:return e.next=4,this.get(t);case 4:return r=e.sent,e.next=7,this.services.network.delete(r.uri);case 7:n=e.sent,this._handleItemRemoved(t,n.body.last_event_id,void 0,new Date(n.body.date_updated),!1);case 9:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"queryItems",value:function(){var e=(0,o.default)(s.default.mark(function e(t){var r,n,i,o,a=this;return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t=t||{},r=new h.UriBuilder(this.links.items).queryParam("From",t.from).queryParam("PageSize",t.limit).queryParam("Key",t.key).queryParam("PageToken",t.pageToken).queryParam("Order",t.order).build(),e.next=4,this.services.network.get(r);case 4:return n=e.sent,i=n.body.items.map(function(e){return e.date_updated=new Date(e.date_updated),a.cache.get(e.key)?a._handleItemMutated(e.key,e.url,e.last_event_id,e.revision,e.data,e.date_updated,e.date_expires,!1,!0):a.cache.store(e.key,new y.MapItem(e),e.last_event_id),a.cache.get(e.key)}),o=n.body.meta,e.abrupt("return",new g.Paginator(i,function(e){return a.queryItems({pageToken:e})},o.previous_token,o.next_token));case 8:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"getItems",value:function(){var e=(0,o.default)(s.default.mark(function e(t){return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t=t||{},p.validatePageSize(t.pageSize),t.limit=t.pageSize||t.limit||50,t.order=t.order||"asc",e.abrupt("return",this.queryItems(t));case 5:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"shouldIgnoreEvent",value:function(e,t){return this.cache.isKnown(e,t)}},{key:"_update",value:function(e,t){switch(e.date_created=new Date(e.date_created),e.type){case"map_item_added":case"map_item_updated":this._handleItemMutated(e.item_key,e.item_url,e.id,e.item_revision,e.item_data,e.date_created,void 0,"map_item_added"===e.type,!0);break;case"map_item_removed":this._handleItemRemoved(e.item_key,e.id,e.item_data,e.date_created,!0);break;case"map_removed":this.onRemoved(!1)}t&&this._advanceLastEventId(e.id,e.map_revision)}},{key:"_advanceLastEventId",value:function(e,t){this.lastEventId<e&&(this.descriptor.last_event_id=e,t&&(this.descriptor.revision=t))}},{key:"_updateRootDateUpdated",value:function(e){(!this.descriptor.date_updated||e.getTime()>this.descriptor.date_updated.getTime())&&(this.descriptor.date_updated=e,this.services.storage.update(this.type,this.sid,this.uniqueName,{date_updated:e}))}},{key:"_handleItemMutated",value:function(e,t,r,n,i,s,o,a,u){if(this.shouldIgnoreEvent(e,r))v.default.trace("Item ",e," update skipped, current:",this.lastEventId,", remote:",r);else{this._updateRootDateUpdated(s);var c=this.cache.get(e);c?(c.update(r,n,i,s),this.cache.store(e,c,r),void 0!==o&&c.updateDateExpires(o),this.emitItemMutationEvent(c,u,!1)):(c=new y.MapItem({key:e,url:t,last_event_id:r,revision:n,data:i,date_updated:s,date_expires:o}),this.cache.store(e,c,r),this.emitItemMutationEvent(c,u,a))}}},{key:"emitItemMutationEvent",value:function(e,t,r){var n=r?"itemAdded":"itemUpdated";this.broadcastEventToListeners(n,{item:e,isLocal:!t})}},{key:"_handleItemRemoved",value:function(e,t,r,n,i){this._updateRootDateUpdated(n),this.cache.delete(e,t),this.broadcastEventToListeners("itemRemoved",{key:e,isLocal:!i,value:r})}},{key:"onRemoved",value:function(e){this._unsubscribe(),this.removalHandler(this.type,this.sid,this.uniqueName),this.broadcastEventToListeners("removed",{isLocal:e})}},{key:"setTtl",value:function(){var e=(0,o.default)(s.default.mark(function e(t){var r,n;return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return p.validateMandatoryTtl(t),e.prev=1,r={ttl:t},e.next=5,this.services.network.post(this.uri,r);case 5:n=e.sent,this.descriptor.date_expires=n.body.date_expires,e.next=13;break;case 9:throw e.prev=9,e.t0=e.catch(1),404===e.t0.status&&this.onRemoved(!1),e.t0;case 13:case"end":return e.stop()}},e,this,[[1,9]])}));return function(t){return e.apply(this,arguments)}}()},{key:"setItemTtl",value:function(){var e=(0,o.default)(s.default.mark(function e(t,r){var n,i,o;return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return p.validateMandatoryTtl(r),e.next=3,this.get(t);case 3:return n=e.sent,i={ttl:r},e.next=7,this.services.network.post(n.uri,i);case 7:o=e.sent,n.updateDateExpires(o.body.date_expires);case 9:case"end":return e.stop()}},e,this)}));return function(t,r){return e.apply(this,arguments)}}()},{key:"removeMap",value:function(){var e=(0,o.default)(s.default.mark(function e(){return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.network.delete(this.uri);case 2:this.onRemoved(!0);case 3:case"end":return e.stop()}},e,this)}));return function(){return e.apply(this,arguments)}}()},{key:"uri",get:function(){return this.descriptor.url}},{key:"links",get:function(){return this.descriptor.links}},{key:"revision",get:function(){return this.descriptor.revision}},{key:"lastEventId",get:function(){return this.descriptor.last_event_id}},{key:"dateExpires",get:function(){return this.descriptor.date_expires}},{key:"type",get:function(){return"map"}},{key:"indexName",get:function(){}},{key:"queryString",get:function(){}},{key:"sid",get:function(){return this.descriptor.sid}},{key:"uniqueName",get:function(){return this.descriptor.unique_name||null}},{key:"dateUpdated",get:function(){return this.descriptor.date_updated}}],[{key:"type",get:function(){return"map"}}]),t}(m.SyncEntity);r.SyncMapImpl=x;var j=function(e){function t(e){(0,u.default)(this,t);var r=(0,l.default)(this,(t.__proto__||(0,a.default)(t)).call(this));return r.syncMapImpl=e,r.syncMapImpl.attach(r),r}return(0,f.default)(t,e),(0,c.default)(t,[{key:"set",value:function(){var e=(0,o.default)(s.default.mark(function e(t,r,n){return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncMapImpl.set(t,r,n));case 2:case"end":return e.stop()}},e,this)}));return function(t,r,n){return e.apply(this,arguments)}}()},{key:"get",value:function(){var e=(0,o.default)(s.default.mark(function e(t){return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncMapImpl.get(t));case 2:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"mutate",value:function(){var e=(0,o.default)(s.default.mark(function e(t,r,n){return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncMapImpl.mutate(t,r,n));case 2:case"end":return e.stop()}},e,this)}));return function(t,r,n){return e.apply(this,arguments)}}()},{key:"update",value:function(){var e=(0,o.default)(s.default.mark(function e(t,r,n){return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncMapImpl.update(t,r,n));case 2:case"end":return e.stop()}},e,this)}));return function(t,r,n){return e.apply(this,arguments)}}()},{key:"remove",value:function(){var e=(0,o.default)(s.default.mark(function e(t){return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncMapImpl.remove(t));case 2:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"getItems",value:function(){var e=(0,o.default)(s.default.mark(function e(t){return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncMapImpl.getItems(t));case 2:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"setTtl",value:function(){var e=(0,o.default)(s.default.mark(function e(t){return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncMapImpl.setTtl(t));case 2:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"setItemTtl",value:function(){var e=(0,o.default)(s.default.mark(function e(t,r){return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncMapImpl.setItemTtl(t,r));case 2:case"end":return e.stop()}},e,this)}));return function(t,r){return e.apply(this,arguments)}}()},{key:"removeMap",value:function(){var e=(0,o.default)(s.default.mark(function e(){return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.next=3,this.syncMapImpl.removeMap();case 3:case"end":return e.stop()}},e,this)}));return function(){return e.apply(this,arguments)}}()},{key:"close",value:function(){(0,n.default)(t.prototype.__proto__||(0,a.default)(t.prototype),"close",this).call(this),this.syncMapImpl.detach(this.listenerUuid)}},{key:"uri",get:function(){return this.syncMapImpl.uri}},{key:"links",get:function(){return this.syncMapImpl.links}},{key:"revision",get:function(){return this.syncMapImpl.revision}},{key:"lastEventId",get:function(){return this.syncMapImpl.lastEventId}},{key:"dateExpires",get:function(){return this.syncMapImpl.dateExpires}},{key:"type",get:function(){return x.type}},{key:"sid",get:function(){return this.syncMapImpl.sid}},{key:"uniqueName",get:function(){return this.syncMapImpl.uniqueName}},{key:"dateUpdated",get:function(){return this.syncMapImpl.dateUpdated}}],[{key:"type",get:function(){return x.type}}]),t}(w.Closeable);r.SyncMap=j,r.default=j},{"./cache":1,"./closeable":4,"./entity":7,"./mapitem":10,"./mergingqueue":11,"./paginator":12,"./utils/logger":21,"./utils/sanitize":22,"./utils/syncerror":23,"./utils/uri":25,"babel-runtime/core-js/object/assign":31,"babel-runtime/core-js/object/get-prototype-of":35,"babel-runtime/helpers/asyncToGenerator":42,"babel-runtime/helpers/classCallCheck":43,"babel-runtime/helpers/createClass":44,"babel-runtime/helpers/get":45,"babel-runtime/helpers/inherits":46,"babel-runtime/helpers/possibleConstructorReturn":47,"babel-runtime/regenerator":51}],21:[function(e,t,r){"use strict";var n,i=e("babel-runtime/core-js/array/from"),s=(n=i)&&n.__esModule?n:{default:n};Object.defineProperty(r,"__esModule",{value:!0});var o=e("loglevel").getLogger("twilio-sync");function a(e,t){return[(new Date).toISOString()+" Sync "+e+":"].concat((0,s.default)(t))}r.default={setLevel:function(e){o.setLevel(e)},trace:function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];o.trace.apply(null,a("T",t))},debug:function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];o.debug.apply(null,a("D",t))},info:function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];o.info.apply(null,a("I",t))},warn:function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];o.warn.apply(null,a("W",t))},error:function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];o.error.apply(null,a("E",t))}}},{"babel-runtime/core-js/array/from":26,loglevel:186}],22:[function(e,t,r){"use strict";var n=s(e("babel-runtime/helpers/typeof")),i=s(e("babel-runtime/core-js/json/stringify"));function s(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var o=e("./syncerror");function a(e,t){if(!t||void 0!==e){var r,i=void 0===e?"undefined":(0,n.default)(e);if("number"!==i||!(u(r=e)&&r>=0)){var s="object"===i?"object":"'"+e+"' of type '"+i+"'";throw new o.default("Invalid TTL, expected a positive integer of type number, was "+s,400,54011)}}}function u(e){return!isNaN(parseInt(e))&&isFinite(e)}r.deepClone=function(e){return JSON.parse((0,i.default)(e))},r.validateId=function(e){if(void 0!==e){var t=void 0===e?"undefined":(0,n.default)(e);if("string"!==t)throw new Error("Invalid ID type, expected a string, got '"+t+"'")}},r.validateOptionalTtl=function(e){a(e,!0)},r.validateMandatoryTtl=function(e){a(e,!1)},r.validatePageSize=function(e){var t;if(!(void 0===e||u(t=e)&&t>0))throw new o.default("Invalid pageSize parameter. Expected a positive integer, was '"+e+"'.",400,54455)}},{"./syncerror":23,"babel-runtime/core-js/json/stringify":29,"babel-runtime/helpers/typeof":50}],23:[function(e,t,r){"use strict";var n=f(e("babel-runtime/core-js/object/create")),i=f(e("babel-runtime/core-js/object/set-prototype-of")),s=f(e("babel-runtime/core-js/array/from")),o=f(e("babel-runtime/core-js/reflect/construct")),a=f(e("babel-runtime/core-js/object/get-prototype-of")),u=f(e("babel-runtime/helpers/classCallCheck")),c=f(e("babel-runtime/helpers/possibleConstructorReturn")),l=f(e("babel-runtime/helpers/inherits"));function f(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var d=function(e){function t(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;(0,u.default)(this,t);var i=(0,c.default)(this,(t.__proto__||(0,a.default)(t)).call(this));return i.name=i.constructor.name,i.message=e+" (status: "+r+", code: "+n+")",i.status=r,i.code=n,i}return(0,l.default)(t,e),t}(function(e){function t(){var t=(0,o.default)(e,(0,s.default)(arguments));return(0,i.default)(t,(0,a.default)(this)),t}return t.prototype=(0,n.default)(e.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),i.default?(0,i.default)(t,e):t.__proto__=e,t}(Error));r.SyncError=d;var p=function(e){function t(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,i=arguments[3];(0,u.default)(this,t);var s=(0,c.default)(this,(t.__proto__||(0,a.default)(t)).call(this,e,r,n));return s.body=i,s}return(0,l.default)(t,e),t}(d);r.SyncNetworkError=p,r.default=d},{"babel-runtime/core-js/array/from":26,"babel-runtime/core-js/object/create":32,"babel-runtime/core-js/object/get-prototype-of":35,"babel-runtime/core-js/object/set-prototype-of":36,"babel-runtime/core-js/reflect/construct":38,"babel-runtime/helpers/classCallCheck":43,"babel-runtime/helpers/inherits":46,"babel-runtime/helpers/possibleConstructorReturn":47}],24:[function(e,t,r){"use strict";var n=u(e("babel-runtime/regenerator")),i=u(e("babel-runtime/core-js/get-iterator")),s=u(e("babel-runtime/core-js/symbol/iterator")),o=u(e("babel-runtime/helpers/classCallCheck")),a=u(e("babel-runtime/helpers/createClass"));function u(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var c=function(){function e(t,r){(0,o.default)(this,e),this.balanceFactor=0,this.key=t,this.value=r,this.parent=null,this.left=null,this.right=null}return(0,a.default)(e,[{key:"update",value:function(e){this.value=e}},{key:"replace",value:function(e,t){e&&(this.left===t?this.left=t:this.right===t&&(this.right=t))}},{key:"isRoot",get:function(){return null===this.parent}},{key:"isLeaf",get:function(){return null===this.left&&null===this.right}},{key:"isLeftChild",get:function(){return this.parent.left===this}}]),e}(),l=function(){function e(t,r){(0,o.default)(this,e),this.isLessThan=t||function(e,t){return e<t},this.isEqual=r||function(e,t){return e===t},this.root=null,this.count=null}return(0,a.default)(e,[{key:"clear",value:function(){this.root=null,this.count=0}},{key:"set",value:function(e,t){var r=this.getNode(e);r?r.update(t):this.insert(e,t)}},{key:"insert",value:function(e,t){var r=new c(e,t);if(this.count++,this.root){for(var n=this.root;;)if(this.isLessThan(e,n.key)){if(!n.left){n.left=r;break}n=n.left}else{if(!n.right){n.right=r;break}n=n.right}for(r.parent=n,n=r;n.parent;){var i=n.parent,s=i.balanceFactor;if(n.isLeftChild?i.balanceFactor++:i.balanceFactor--,Math.abs(i.balanceFactor)<Math.abs(s))break;if(i.balanceFactor<-1||i.balanceFactor>1){this.rebalance(i);break}n=i}}else this.root=r}},{key:"get",value:function(e){for(var t=this.root;t;){if(this.isEqual(e,t.key))return t.value;t=this.isLessThan(e,t.key)?t.left:t.right}return null}},{key:"delete",value:function(e){var t=this.getNode(e);if(!t||t.key!==e)return null;var r=t.parent,n=t.left,i=t.right;if(!!n!=!!i){var s=n||i;r||s?r&&!s?this.root=s:(r.replace(t,null),this.rebalance(r)):this.root=null}else{for(var o=t.left;o.right;)o=o.right;if(t.left===o)t.isRoot?(this.root=o,o.parent=null):(t.isLeftChild?t.parent.left=o:t.parent.right=o,o.parent=t.parent),o.right=t.right,o.right.parent=o,o.balanceFactor=t.balanceFactor,t={parent:o,isLeftChild:!0};else{var a=o.parent,u=o.left;a.right=u,u&&(u.parent=a),t.isRoot?(this.root=o,o.parent=null):(t.isLeftChild?t.parent.left=o:t.parent.right=o,o.parent=t.parent),o.right=t.right,o.right.parent=o,o.left=t.left,o.left.parent=o,o.balanceFactor=t.balanceFactor,t={parent:a,isLeftChild:!1}}}for(this.count--;t.parent;){var c=t.parent,l=c.balanceFactor;if(t.isLeftChild?c.balanceFactor-=1:c.balanceFactor+=1,Math.abs(c.balanceFactor)>Math.abs(l)){if(!(c.balanceFactor<-1||c.balanceFactor>1))break;if(this.rebalance(c),0!==c.parent.balanceFactor)break;t=c.parent}else t=c}return null}},{key:"getNode",value:function(e){for(var t=this.root;t;){if(this.isEqual(e,t.key))return t;t=this.isLessThan(e,t.key)?t.left:t.right}return null}},{key:"rebalance",value:function(e){e.balanceFactor<0?e.right.balanceFactor>0?(this.rotateRight(e.right),this.rotateLeft(e)):this.rotateLeft(e):e.balanceFactor>0&&(e.left.balanceFactor<0?(this.rotateLeft(e.left),this.rotateRight(e)):this.rotateRight(e))}},{key:"rotateLeft",value:function(e){var t=e.right;e.right=t.left,null!==t.left&&(t.left.parent=e),t.parent=e.parent,null===t.parent?this.root=t:e.isLeftChild?t.parent.left=t:t.parent.right=t,t.left=e,e.parent=t,e.balanceFactor=e.balanceFactor+1-Math.min(t.balanceFactor,0),t.balanceFactor=t.balanceFactor+1-Math.max(e.balanceFactor,0)}},{key:"rotateRight",value:function(e){var t=e.left;e.left=t.right,null!==t.right&&(t.right.parent=e),t.parent=e.parent,null===t.parent?this.root=t:e.isLeftChild?t.parent.left=t:t.parent.right=t,t.right=e,e.parent=t,e.balanceFactor=e.balanceFactor-1-Math.min(t.balanceFactor,0),t.balanceFactor=t.balanceFactor-1-Math.max(e.balanceFactor,0)}},{key:s.default,value:n.default.mark(function e(){var t,r,s,o,a,u;return n.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:t=!0,r=!1,s=void 0,e.prev=3,o=(0,i.default)(this.getIterator());case 5:if(t=(a=o.next()).done){e.next=12;break}return u=a.value,e.next=9,u;case 9:t=!0,e.next=5;break;case 12:e.next=18;break;case 14:e.prev=14,e.t0=e.catch(3),r=!0,s=e.t0;case 18:e.prev=18,e.prev=19,!t&&o.return&&o.return();case 21:if(e.prev=21,!r){e.next=24;break}throw s;case 24:return e.finish(21);case 25:return e.finish(18);case 26:case"end":return e.stop()}},e,this,[[3,14,18,26],[19,,21,25]])})},{key:"getIterator",value:n.default.mark(function e(){var t,r,i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;return n.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:t=this.root;case 1:if(!t){e.next=7;break}if(!this.isEqual(i,t.key)&&(null!==i||t.left)){e.next=4;break}return e.abrupt("break",7);case 4:t=this.isLessThan(i,t.key)||null===i?t.left:t.right,e.next=1;break;case 7:if(t){e.next=9;break}return e.abrupt("return",null);case 9:r=!0;case 10:if(!r){e.next=28;break}return e.next=13,[t.key,t.value];case 13:if(r=!1,!t.right){e.next=20;break}for(t=t.right;t.left;)t=t.left;r=!0,e.next=26;break;case 20:if(!t.parent){e.next=25;break}r=t.parent.left===t,t=t.parent,e.next=26;break;case 25:return e.abrupt("break",36);case 26:e.next=34;break;case 28:if(!t.parent){e.next=33;break}r=t.parent.left===t,t=t.parent,e.next=34;break;case 33:return e.abrupt("break",36);case 34:e.next=10;break;case 36:return e.abrupt("return",null);case 37:case"end":return e.stop()}},e,this)})},{key:"getReverseIterator",value:n.default.mark(function e(){var t,r,i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;return n.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:t=this.root;case 1:if(!t){e.next=7;break}if(!this.isEqual(i,t.key)&&(null!==i||t.right)){e.next=4;break}return e.abrupt("break",7);case 4:t=this.isLessThan(i,t.key)&&null!==i?t.left:t.right,e.next=1;break;case 7:if(t){e.next=9;break}return e.abrupt("return",null);case 9:r=!0;case 10:if(!r){e.next=28;break}return e.next=13,[t.key,t.value];case 13:if(r=!1,!t.left){e.next=20;break}for(t=t.left;t.right;)t=t.right;r=!0,e.next=26;break;case 20:if(!t.parent){e.next=25;break}r=t.parent.right===t,t=t.parent,e.next=26;break;case 25:return e.abrupt("break",36);case 26:e.next=34;break;case 28:if(!t.parent){e.next=33;break}r=t.parent.right===t,t=t.parent,e.next=34;break;case 33:return e.abrupt("break",36);case 34:e.next=10;break;case 36:return e.abrupt("return",null);case 37:case"end":return e.stop()}},e,this)})},{key:"size",get:function(){return this.count}}]),e}();r.TreeMap=l},{"babel-runtime/core-js/get-iterator":27,"babel-runtime/core-js/symbol/iterator":41,"babel-runtime/helpers/classCallCheck":43,"babel-runtime/helpers/createClass":44,"babel-runtime/regenerator":51}],25:[function(e,t,r){"use strict";var n=s(e("babel-runtime/helpers/classCallCheck")),i=s(e("babel-runtime/helpers/createClass"));function s(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var o=function(){function e(t){(0,n.default)(this,e),this.base=t,this.args=new Array,this.paths=new Array}return(0,i.default)(e,[{key:"pathSegment",value:function(e){return this.paths.push(encodeURIComponent(e)),this}},{key:"queryParam",value:function(e,t){return void 0!==t&&this.args.push(encodeURIComponent(e)+"="+encodeURIComponent(t)),this}},{key:"build",value:function(){var e=this.base;return this.paths.length&&(e+="/"+this.paths.join("/")),this.args.length&&(e+="?"+this.args.join("&")),e}}]),e}();r.UriBuilder=o},{"babel-runtime/helpers/classCallCheck":43,"babel-runtime/helpers/createClass":44}],26:[function(e,t,r){t.exports={default:e("core-js/library/fn/array/from"),__esModule:!0}},{"core-js/library/fn/array/from":53}],27:[function(e,t,r){t.exports={default:e("core-js/library/fn/get-iterator"),__esModule:!0}},{"core-js/library/fn/get-iterator":54}],28:[function(e,t,r){t.exports={default:e("core-js/library/fn/is-iterable"),__esModule:!0}},{"core-js/library/fn/is-iterable":55}],29:[function(e,t,r){t.exports={default:e("core-js/library/fn/json/stringify"),__esModule:!0}},{"core-js/library/fn/json/stringify":56}],30:[function(e,t,r){t.exports={default:e("core-js/library/fn/map"),__esModule:!0}},{"core-js/library/fn/map":57}],31:[function(e,t,r){t.exports={default:e("core-js/library/fn/object/assign"),__esModule:!0}},{"core-js/library/fn/object/assign":58}],32:[function(e,t,r){t.exports={default:e("core-js/library/fn/object/create"),__esModule:!0}},{"core-js/library/fn/object/create":59}],33:[function(e,t,r){t.exports={default:e("core-js/library/fn/object/define-property"),__esModule:!0}},{"core-js/library/fn/object/define-property":60}],34:[function(e,t,r){t.exports={default:e("core-js/library/fn/object/get-own-property-descriptor"),__esModule:!0}},{"core-js/library/fn/object/get-own-property-descriptor":61}],35:[function(e,t,r){t.exports={default:e("core-js/library/fn/object/get-prototype-of"),__esModule:!0}},{"core-js/library/fn/object/get-prototype-of":62}],36:[function(e,t,r){t.exports={default:e("core-js/library/fn/object/set-prototype-of"),__esModule:!0}},{"core-js/library/fn/object/set-prototype-of":63}],37:[function(e,t,r){t.exports={default:e("core-js/library/fn/promise"),__esModule:!0}},{"core-js/library/fn/promise":64}],38:[function(e,t,r){t.exports={default:e("core-js/library/fn/reflect/construct"),__esModule:!0}},{"core-js/library/fn/reflect/construct":65}],39:[function(e,t,r){t.exports={default:e("core-js/library/fn/set"),__esModule:!0}},{"core-js/library/fn/set":66}],40:[function(e,t,r){t.exports={default:e("core-js/library/fn/symbol"),__esModule:!0}},{"core-js/library/fn/symbol":67}],41:[function(e,t,r){t.exports={default:e("core-js/library/fn/symbol/iterator"),__esModule:!0}},{"core-js/library/fn/symbol/iterator":68}],42:[function(e,t,r){"use strict";r.__esModule=!0;var n,i=e("../core-js/promise"),s=(n=i)&&n.__esModule?n:{default:n};r.default=function(e){return function(){var t=e.apply(this,arguments);return new s.default(function(e,r){return function n(i,o){try{var a=t[i](o),u=a.value}catch(e){return void r(e)}if(!a.done)return s.default.resolve(u).then(function(e){n("next",e)},function(e){n("throw",e)});e(u)}("next")})}}},{"../core-js/promise":37}],43:[function(e,t,r){"use strict";r.__esModule=!0,r.default=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}},{}],44:[function(e,t,r){"use strict";r.__esModule=!0;var n,i=e("../core-js/object/define-property"),s=(n=i)&&n.__esModule?n:{default:n};r.default=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),(0,s.default)(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}()},{"../core-js/object/define-property":33}],45:[function(e,t,r){"use strict";r.__esModule=!0;var n=s(e("../core-js/object/get-prototype-of")),i=s(e("../core-js/object/get-own-property-descriptor"));function s(e){return e&&e.__esModule?e:{default:e}}r.default=function e(t,r,s){null===t&&(t=Function.prototype);var o=(0,i.default)(t,r);if(void 0===o){var a=(0,n.default)(t);return null===a?void 0:e(a,r,s)}if("value"in o)return o.value;var u=o.get;return void 0!==u?u.call(s):void 0}},{"../core-js/object/get-own-property-descriptor":34,"../core-js/object/get-prototype-of":35}],46:[function(e,t,r){"use strict";r.__esModule=!0;var n=o(e("../core-js/object/set-prototype-of")),i=o(e("../core-js/object/create")),s=o(e("../helpers/typeof"));function o(e){return e&&e.__esModule?e:{default:e}}r.default=function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+(void 0===t?"undefined":(0,s.default)(t)));e.prototype=(0,i.default)(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(n.default?(0,n.default)(e,t):e.__proto__=t)}},{"../core-js/object/create":32,"../core-js/object/set-prototype-of":36,"../helpers/typeof":50}],47:[function(e,t,r){"use strict";r.__esModule=!0;var n,i=e("../helpers/typeof"),s=(n=i)&&n.__esModule?n:{default:n};r.default=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!==(void 0===t?"undefined":(0,s.default)(t))&&"function"!=typeof t?e:t}},{"../helpers/typeof":50}],48:[function(e,t,r){"use strict";r.__esModule=!0;var n=s(e("../core-js/is-iterable")),i=s(e("../core-js/get-iterator"));function s(e){return e&&e.__esModule?e:{default:e}}r.default=function(){return function(e,t){if(Array.isArray(e))return e;if((0,n.default)(Object(e)))return function(e,t){var r=[],n=!0,s=!1,o=void 0;try{for(var a,u=(0,i.default)(e);!(n=(a=u.next()).done)&&(r.push(a.value),!t||r.length!==t);n=!0);}catch(e){s=!0,o=e}finally{try{!n&&u.return&&u.return()}finally{if(s)throw o}}return r}(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}()},{"../core-js/get-iterator":27,"../core-js/is-iterable":28}],49:[function(e,t,r){"use strict";r.__esModule=!0;var n,i=e("../core-js/array/from"),s=(n=i)&&n.__esModule?n:{default:n};r.default=function(e){if(Array.isArray(e)){for(var t=0,r=Array(e.length);t<e.length;t++)r[t]=e[t];return r}return(0,s.default)(e)}},{"../core-js/array/from":26}],50:[function(e,t,r){"use strict";r.__esModule=!0;var n=o(e("../core-js/symbol/iterator")),i=o(e("../core-js/symbol")),s="function"==typeof i.default&&"symbol"==typeof n.default?function(e){return typeof e}:function(e){return e&&"function"==typeof i.default&&e.constructor===i.default&&e!==i.default.prototype?"symbol":typeof e};function o(e){return e&&e.__esModule?e:{default:e}}r.default="function"==typeof i.default&&"symbol"===s(n.default)?function(e){return void 0===e?"undefined":s(e)}:function(e){return e&&"function"==typeof i.default&&e.constructor===i.default&&e!==i.default.prototype?"symbol":void 0===e?"undefined":s(e)}},{"../core-js/symbol":40,"../core-js/symbol/iterator":41}],51:[function(e,t,r){t.exports=e("regenerator-runtime")},{"regenerator-runtime":191}],52:[function(e,t,r){},{}],53:[function(e,t,r){e("../../modules/es6.string.iterator"),e("../../modules/es6.array.from"),t.exports=e("../../modules/_core").Array.from},{"../../modules/_core":84,"../../modules/es6.array.from":158,"../../modules/es6.string.iterator":171}],54:[function(e,t,r){e("../modules/web.dom.iterable"),e("../modules/es6.string.iterator"),t.exports=e("../modules/core.get-iterator")},{"../modules/core.get-iterator":156,"../modules/es6.string.iterator":171,"../modules/web.dom.iterable":183}],55:[function(e,t,r){e("../modules/web.dom.iterable"),e("../modules/es6.string.iterator"),t.exports=e("../modules/core.is-iterable")},{"../modules/core.is-iterable":157,"../modules/es6.string.iterator":171,"../modules/web.dom.iterable":183}],56:[function(e,t,r){var n=e("../../modules/_core"),i=n.JSON||(n.JSON={stringify:JSON.stringify});t.exports=function(e){return i.stringify.apply(i,arguments)}},{"../../modules/_core":84}],57:[function(e,t,r){e("../modules/es6.object.to-string"),e("../modules/es6.string.iterator"),e("../modules/web.dom.iterable"),e("../modules/es6.map"),e("../modules/es7.map.to-json"),e("../modules/es7.map.of"),e("../modules/es7.map.from"),t.exports=e("../modules/_core").Map},{"../modules/_core":84,"../modules/es6.map":160,"../modules/es6.object.to-string":167,"../modules/es6.string.iterator":171,"../modules/es7.map.from":173,"../modules/es7.map.of":174,"../modules/es7.map.to-json":175,"../modules/web.dom.iterable":183}],58:[function(e,t,r){e("../../modules/es6.object.assign"),t.exports=e("../../modules/_core").Object.assign},{"../../modules/_core":84,"../../modules/es6.object.assign":161}],59:[function(e,t,r){e("../../modules/es6.object.create");var n=e("../../modules/_core").Object;t.exports=function(e,t){return n.create(e,t)}},{"../../modules/_core":84,"../../modules/es6.object.create":162}],60:[function(e,t,r){e("../../modules/es6.object.define-property");var n=e("../../modules/_core").Object;t.exports=function(e,t,r){return n.defineProperty(e,t,r)}},{"../../modules/_core":84,"../../modules/es6.object.define-property":163}],61:[function(e,t,r){e("../../modules/es6.object.get-own-property-descriptor");var n=e("../../modules/_core").Object;t.exports=function(e,t){return n.getOwnPropertyDescriptor(e,t)}},{"../../modules/_core":84,"../../modules/es6.object.get-own-property-descriptor":164}],62:[function(e,t,r){e("../../modules/es6.object.get-prototype-of"),t.exports=e("../../modules/_core").Object.getPrototypeOf},{"../../modules/_core":84,"../../modules/es6.object.get-prototype-of":165}],63:[function(e,t,r){e("../../modules/es6.object.set-prototype-of"),t.exports=e("../../modules/_core").Object.setPrototypeOf},{"../../modules/_core":84,"../../modules/es6.object.set-prototype-of":166}],64:[function(e,t,r){e("../modules/es6.object.to-string"),e("../modules/es6.string.iterator"),e("../modules/web.dom.iterable"),e("../modules/es6.promise"),e("../modules/es7.promise.finally"),e("../modules/es7.promise.try"),t.exports=e("../modules/_core").Promise},{"../modules/_core":84,"../modules/es6.object.to-string":167,"../modules/es6.promise":168,"../modules/es6.string.iterator":171,"../modules/es7.promise.finally":176,"../modules/es7.promise.try":177,"../modules/web.dom.iterable":183}],65:[function(e,t,r){e("../../modules/es6.reflect.construct"),t.exports=e("../../modules/_core").Reflect.construct},{"../../modules/_core":84,"../../modules/es6.reflect.construct":169}],66:[function(e,t,r){e("../modules/es6.object.to-string"),e("../modules/es6.string.iterator"),e("../modules/web.dom.iterable"),e("../modules/es6.set"),e("../modules/es7.set.to-json"),e("../modules/es7.set.of"),e("../modules/es7.set.from"),t.exports=e("../modules/_core").Set},{"../modules/_core":84,"../modules/es6.object.to-string":167,"../modules/es6.set":170,"../modules/es6.string.iterator":171,"../modules/es7.set.from":178,"../modules/es7.set.of":179,"../modules/es7.set.to-json":180,"../modules/web.dom.iterable":183}],67:[function(e,t,r){e("../../modules/es6.symbol"),e("../../modules/es6.object.to-string"),e("../../modules/es7.symbol.async-iterator"),e("../../modules/es7.symbol.observable"),t.exports=e("../../modules/_core").Symbol},{"../../modules/_core":84,"../../modules/es6.object.to-string":167,"../../modules/es6.symbol":172,"../../modules/es7.symbol.async-iterator":181,"../../modules/es7.symbol.observable":182}],68:[function(e,t,r){e("../../modules/es6.string.iterator"),e("../../modules/web.dom.iterable"),t.exports=e("../../modules/_wks-ext").f("iterator")},{"../../modules/_wks-ext":153,"../../modules/es6.string.iterator":171,"../../modules/web.dom.iterable":183}],69:[function(e,t,r){t.exports=function(e){if("function"!=typeof e)throw TypeError(e+" is not a function!");return e}},{}],70:[function(e,t,r){t.exports=function(){}},{}],71:[function(e,t,r){t.exports=function(e,t,r,n){if(!(e instanceof t)||void 0!==n&&n in e)throw TypeError(r+": incorrect invocation!");return e}},{}],72:[function(e,t,r){var n=e("./_is-object");t.exports=function(e){if(!n(e))throw TypeError(e+" is not an object!");return e}},{"./_is-object":104}],73:[function(e,t,r){var n=e("./_for-of");t.exports=function(e,t){var r=[];return n(e,!1,r.push,r,t),r}},{"./_for-of":94}],74:[function(e,t,r){var n=e("./_to-iobject"),i=e("./_to-length"),s=e("./_to-absolute-index");t.exports=function(e){return function(t,r,o){var a,u=n(t),c=i(u.length),l=s(o,c);if(e&&r!=r){for(;c>l;)if((a=u[l++])!=a)return!0}else for(;c>l;l++)if((e||l in u)&&u[l]===r)return e||l||0;return!e&&-1}}},{"./_to-absolute-index":143,"./_to-iobject":145,"./_to-length":146}],75:[function(e,t,r){var n=e("./_ctx"),i=e("./_iobject"),s=e("./_to-object"),o=e("./_to-length"),a=e("./_array-species-create");t.exports=function(e,t){var r=1==e,u=2==e,c=3==e,l=4==e,f=6==e,d=5==e||f,p=t||a;return function(t,a,h){for(var b,v,m=s(t),y=i(m),g=n(a,h,3),_=o(y.length),k=0,w=r?p(t,_):u?p(t,0):void 0;_>k;k++)if((d||k in y)&&(v=g(b=y[k],k,m),e))if(r)w[k]=v;else if(v)switch(e){case 3:return!0;case 5:return b;case 6:return k;case 2:w.push(b)}else if(l)return!1;return f?-1:c||l?l:w}}},{"./_array-species-create":77,"./_ctx":86,"./_iobject":101,"./_to-length":146,"./_to-object":147}],76:[function(e,t,r){var n=e("./_is-object"),i=e("./_is-array"),s=e("./_wks")("species");t.exports=function(e){var t;return i(e)&&("function"!=typeof(t=e.constructor)||t!==Array&&!i(t.prototype)||(t=void 0),n(t)&&null===(t=t[s])&&(t=void 0)),void 0===t?Array:t}},{"./_is-array":103,"./_is-object":104,"./_wks":154}],77:[function(e,t,r){var n=e("./_array-species-constructor");t.exports=function(e,t){return new(n(e))(t)}},{"./_array-species-constructor":76}],78:[function(e,t,r){"use strict";var n=e("./_a-function"),i=e("./_is-object"),s=e("./_invoke"),o=[].slice,a={};t.exports=Function.bind||function(e){var t=n(this),r=o.call(arguments,1),u=function(){var n=r.concat(o.call(arguments));return this instanceof u?function(e,t,r){if(!(t in a)){for(var n=[],i=0;i<t;i++)n[i]="a["+i+"]";a[t]=Function("F,a","return new F("+n.join(",")+")")}return a[t](e,r)}(t,n.length,n):s(t,n,e)};return i(t.prototype)&&(u.prototype=t.prototype),u}},{"./_a-function":69,"./_invoke":100,"./_is-object":104}],79:[function(e,t,r){var n=e("./_cof"),i=e("./_wks")("toStringTag"),s="Arguments"==n(function(){return arguments}());t.exports=function(e){var t,r,o;return void 0===e?"Undefined":null===e?"Null":"string"==typeof(r=function(e,t){try{return e[t]}catch(e){}}(t=Object(e),i))?r:s?n(t):"Object"==(o=n(t))&&"function"==typeof t.callee?"Arguments":o}},{"./_cof":80,"./_wks":154}],80:[function(e,t,r){var n={}.toString;t.exports=function(e){return n.call(e).slice(8,-1)}},{}],81:[function(e,t,r){"use strict";var n=e("./_object-dp").f,i=e("./_object-create"),s=e("./_redefine-all"),o=e("./_ctx"),a=e("./_an-instance"),u=e("./_for-of"),c=e("./_iter-define"),l=e("./_iter-step"),f=e("./_set-species"),d=e("./_descriptors"),p=e("./_meta").fastKey,h=e("./_validate-collection"),b=d?"_s":"size",v=function(e,t){var r,n=p(t);if("F"!==n)return e._i[n];for(r=e._f;r;r=r.n)if(r.k==t)return r};t.exports={getConstructor:function(e,t,r,c){var l=e(function(e,n){a(e,l,t,"_i"),e._t=t,e._i=i(null),e._f=void 0,e._l=void 0,e[b]=0,null!=n&&u(n,r,e[c],e)});return s(l.prototype,{clear:function(){for(var e=h(this,t),r=e._i,n=e._f;n;n=n.n)n.r=!0,n.p&&(n.p=n.p.n=void 0),delete r[n.i];e._f=e._l=void 0,e[b]=0},delete:function(e){var r=h(this,t),n=v(r,e);if(n){var i=n.n,s=n.p;delete r._i[n.i],n.r=!0,s&&(s.n=i),i&&(i.p=s),r._f==n&&(r._f=i),r._l==n&&(r._l=s),r[b]--}return!!n},forEach:function(e){h(this,t);for(var r,n=o(e,arguments.length>1?arguments[1]:void 0,3);r=r?r.n:this._f;)for(n(r.v,r.k,this);r&&r.r;)r=r.p},has:function(e){return!!v(h(this,t),e)}}),d&&n(l.prototype,"size",{get:function(){return h(this,t)[b]}}),l},def:function(e,t,r){var n,i,s=v(e,t);return s?s.v=r:(e._l=s={i:i=p(t,!0),k:t,v:r,p:n=e._l,n:void 0,r:!1},e._f||(e._f=s),n&&(n.n=s),e[b]++,"F"!==i&&(e._i[i]=s)),e},getEntry:v,setStrong:function(e,t,r){c(e,t,function(e,r){this._t=h(e,t),this._k=r,this._l=void 0},function(){for(var e=this._k,t=this._l;t&&t.r;)t=t.p;return this._t&&(this._l=t=t?t.n:this._t._f)?l(0,"keys"==e?t.k:"values"==e?t.v:[t.k,t.v]):(this._t=void 0,l(1))},r?"entries":"values",!r,!0),f(t)}}},{"./_an-instance":71,"./_ctx":86,"./_descriptors":88,"./_for-of":94,"./_iter-define":107,"./_iter-step":109,"./_meta":112,"./_object-create":116,"./_object-dp":117,"./_redefine-all":131,"./_set-species":136,"./_validate-collection":151}],82:[function(e,t,r){var n=e("./_classof"),i=e("./_array-from-iterable");t.exports=function(e){return function(){if(n(this)!=e)throw TypeError(e+"#toJSON isn't generic");return i(this)}}},{"./_array-from-iterable":73,"./_classof":79}],83:[function(e,t,r){"use strict";var n=e("./_global"),i=e("./_export"),s=e("./_meta"),o=e("./_fails"),a=e("./_hide"),u=e("./_redefine-all"),c=e("./_for-of"),l=e("./_an-instance"),f=e("./_is-object"),d=e("./_set-to-string-tag"),p=e("./_object-dp").f,h=e("./_array-methods")(0),b=e("./_descriptors");t.exports=function(e,t,r,v,m,y){var g=n[e],_=g,k=m?"set":"add",w=_&&_.prototype,x={};return b&&"function"==typeof _&&(y||w.forEach&&!o(function(){(new _).entries().next()}))?(_=t(function(t,r){l(t,_,e,"_c"),t._c=new g,null!=r&&c(r,m,t[k],t)}),h("add,clear,delete,forEach,get,has,set,keys,values,entries,toJSON".split(","),function(e){var t="add"==e||"set"==e;e in w&&(!y||"clear"!=e)&&a(_.prototype,e,function(r,n){if(l(this,_,e),!t&&y&&!f(r))return"get"==e&&void 0;var i=this._c[e](0===r?0:r,n);return t?this:i})}),y||p(_.prototype,"size",{get:function(){return this._c.size}})):(_=v.getConstructor(t,e,m,k),u(_.prototype,r),s.NEED=!0),d(_,e),x[e]=_,i(i.G+i.W+i.F,x),y||v.setStrong(_,e,m),_}},{"./_an-instance":71,"./_array-methods":75,"./_descriptors":88,"./_export":92,"./_fails":93,"./_for-of":94,"./_global":95,"./_hide":97,"./_is-object":104,"./_meta":112,"./_object-dp":117,"./_redefine-all":131,"./_set-to-string-tag":137}],84:[function(e,t,r){var n=t.exports={version:"2.6.11"};"number"==typeof __e&&(__e=n)},{}],85:[function(e,t,r){"use strict";var n=e("./_object-dp"),i=e("./_property-desc");t.exports=function(e,t,r){t in e?n.f(e,t,i(0,r)):e[t]=r}},{"./_object-dp":117,"./_property-desc":130}],86:[function(e,t,r){var n=e("./_a-function");t.exports=function(e,t,r){if(n(e),void 0===t)return e;switch(r){case 1:return function(r){return e.call(t,r)};case 2:return function(r,n){return e.call(t,r,n)};case 3:return function(r,n,i){return e.call(t,r,n,i)}}return function(){return e.apply(t,arguments)}}},{"./_a-function":69}],87:[function(e,t,r){t.exports=function(e){if(null==e)throw TypeError("Can't call method on  "+e);return e}},{}],88:[function(e,t,r){t.exports=!e("./_fails")(function(){return 7!=Object.defineProperty({},"a",{get:function(){return 7}}).a})},{"./_fails":93}],89:[function(e,t,r){var n=e("./_is-object"),i=e("./_global").document,s=n(i)&&n(i.createElement);t.exports=function(e){return s?i.createElement(e):{}}},{"./_global":95,"./_is-object":104}],90:[function(e,t,r){t.exports="constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf".split(",")},{}],91:[function(e,t,r){var n=e("./_object-keys"),i=e("./_object-gops"),s=e("./_object-pie");t.exports=function(e){var t=n(e),r=i.f;if(r)for(var o,a=r(e),u=s.f,c=0;a.length>c;)u.call(e,o=a[c++])&&t.push(o);return t}},{"./_object-gops":122,"./_object-keys":125,"./_object-pie":126}],92:[function(e,t,r){var n=e("./_global"),i=e("./_core"),s=e("./_ctx"),o=e("./_hide"),a=e("./_has"),u=function(e,t,r){var c,l,f,d=e&u.F,p=e&u.G,h=e&u.S,b=e&u.P,v=e&u.B,m=e&u.W,y=p?i:i[t]||(i[t]={}),g=y.prototype,_=p?n:h?n[t]:(n[t]||{}).prototype;for(c in p&&(r=t),r)(l=!d&&_&&void 0!==_[c])&&a(y,c)||(f=l?_[c]:r[c],y[c]=p&&"function"!=typeof _[c]?r[c]:v&&l?s(f,n):m&&_[c]==f?function(e){var t=function(t,r,n){if(this instanceof e){switch(arguments.length){case 0:return new e;case 1:return new e(t);case 2:return new e(t,r)}return new e(t,r,n)}return e.apply(this,arguments)};return t.prototype=e.prototype,t}(f):b&&"function"==typeof f?s(Function.call,f):f,b&&((y.virtual||(y.virtual={}))[c]=f,e&u.R&&g&&!g[c]&&o(g,c,f)))};u.F=1,u.G=2,u.S=4,u.P=8,u.B=16,u.W=32,u.U=64,u.R=128,t.exports=u},{"./_core":84,"./_ctx":86,"./_global":95,"./_has":96,"./_hide":97}],93:[function(e,t,r){t.exports=function(e){try{return!!e()}catch(e){return!0}}},{}],94:[function(e,t,r){var n=e("./_ctx"),i=e("./_iter-call"),s=e("./_is-array-iter"),o=e("./_an-object"),a=e("./_to-length"),u=e("./core.get-iterator-method"),c={},l={};(r=t.exports=function(e,t,r,f,d){var p,h,b,v,m=d?function(){return e}:u(e),y=n(r,f,t?2:1),g=0;if("function"!=typeof m)throw TypeError(e+" is not iterable!");if(s(m)){for(p=a(e.length);p>g;g++)if((v=t?y(o(h=e[g])[0],h[1]):y(e[g]))===c||v===l)return v}else for(b=m.call(e);!(h=b.next()).done;)if((v=i(b,y,h.value,t))===c||v===l)return v}).BREAK=c,r.RETURN=l},{"./_an-object":72,"./_ctx":86,"./_is-array-iter":102,"./_iter-call":105,"./_to-length":146,"./core.get-iterator-method":155}],95:[function(e,t,r){var n=t.exports="undefined"!=typeof window&&window.Math==Math?window:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")();"number"==typeof __g&&(__g=n)},{}],96:[function(e,t,r){var n={}.hasOwnProperty;t.exports=function(e,t){return n.call(e,t)}},{}],97:[function(e,t,r){var n=e("./_object-dp"),i=e("./_property-desc");t.exports=e("./_descriptors")?function(e,t,r){return n.f(e,t,i(1,r))}:function(e,t,r){return e[t]=r,e}},{"./_descriptors":88,"./_object-dp":117,"./_property-desc":130}],98:[function(e,t,r){var n=e("./_global").document;t.exports=n&&n.documentElement},{"./_global":95}],99:[function(e,t,r){t.exports=!e("./_descriptors")&&!e("./_fails")(function(){return 7!=Object.defineProperty(e("./_dom-create")("div"),"a",{get:function(){return 7}}).a})},{"./_descriptors":88,"./_dom-create":89,"./_fails":93}],100:[function(e,t,r){t.exports=function(e,t,r){var n=void 0===r;switch(t.length){case 0:return n?e():e.call(r);case 1:return n?e(t[0]):e.call(r,t[0]);case 2:return n?e(t[0],t[1]):e.call(r,t[0],t[1]);case 3:return n?e(t[0],t[1],t[2]):e.call(r,t[0],t[1],t[2]);case 4:return n?e(t[0],t[1],t[2],t[3]):e.call(r,t[0],t[1],t[2],t[3])}return e.apply(r,t)}},{}],101:[function(e,t,r){var n=e("./_cof");t.exports=Object("z").propertyIsEnumerable(0)?Object:function(e){return"String"==n(e)?e.split(""):Object(e)}},{"./_cof":80}],102:[function(e,t,r){var n=e("./_iterators"),i=e("./_wks")("iterator"),s=Array.prototype;t.exports=function(e){return void 0!==e&&(n.Array===e||s[i]===e)}},{"./_iterators":110,"./_wks":154}],103:[function(e,t,r){var n=e("./_cof");t.exports=Array.isArray||function(e){return"Array"==n(e)}},{"./_cof":80}],104:[function(e,t,r){t.exports=function(e){return"object"==typeof e?null!==e:"function"==typeof e}},{}],105:[function(e,t,r){var n=e("./_an-object");t.exports=function(e,t,r,i){try{return i?t(n(r)[0],r[1]):t(r)}catch(t){var s=e.return;throw void 0!==s&&n(s.call(e)),t}}},{"./_an-object":72}],106:[function(e,t,r){"use strict";var n=e("./_object-create"),i=e("./_property-desc"),s=e("./_set-to-string-tag"),o={};e("./_hide")(o,e("./_wks")("iterator"),function(){return this}),t.exports=function(e,t,r){e.prototype=n(o,{next:i(1,r)}),s(e,t+" Iterator")}},{"./_hide":97,"./_object-create":116,"./_property-desc":130,"./_set-to-string-tag":137,"./_wks":154}],107:[function(e,t,r){"use strict";var n=e("./_library"),i=e("./_export"),s=e("./_redefine"),o=e("./_hide"),a=e("./_iterators"),u=e("./_iter-create"),c=e("./_set-to-string-tag"),l=e("./_object-gpo"),f=e("./_wks")("iterator"),d=!([].keys&&"next"in[].keys()),p=function(){return this};t.exports=function(e,t,r,h,b,v,m){u(r,t,h);var y,g,_,k=function(e){if(!d&&e in C)return C[e];switch(e){case"keys":case"values":return function(){return new r(this,e)}}return function(){return new r(this,e)}},w=t+" Iterator",x="values"==b,j=!1,C=e.prototype,S=C[f]||C["@@iterator"]||b&&C[b],T=S||k(b),E=b?x?k("entries"):T:void 0,I="Array"==t&&C.entries||S;if(I&&(_=l(I.call(new e)))!==Object.prototype&&_.next&&(c(_,w,!0),n||"function"==typeof _[f]||o(_,f,p)),x&&S&&"values"!==S.name&&(j=!0,T=function(){return S.call(this)}),n&&!m||!d&&!j&&C[f]||o(C,f,T),a[t]=T,a[w]=p,b)if(y={values:x?T:k("values"),keys:v?T:k("keys"),entries:E},m)for(g in y)g in C||s(C,g,y[g]);else i(i.P+i.F*(d||j),t,y);return y}},{"./_export":92,"./_hide":97,"./_iter-create":106,"./_iterators":110,"./_library":111,"./_object-gpo":123,"./_redefine":132,"./_set-to-string-tag":137,"./_wks":154}],108:[function(e,t,r){var n=e("./_wks")("iterator"),i=!1;try{var s=[7][n]();s.return=function(){i=!0},Array.from(s,function(){throw 2})}catch(e){}t.exports=function(e,t){if(!t&&!i)return!1;var r=!1;try{var s=[7],o=s[n]();o.next=function(){return{done:r=!0}},s[n]=function(){return o},e(s)}catch(e){}return r}},{"./_wks":154}],109:[function(e,t,r){t.exports=function(e,t){return{value:t,done:!!e}}},{}],110:[function(e,t,r){t.exports={}},{}],111:[function(e,t,r){t.exports=!0},{}],112:[function(e,t,r){var n=e("./_uid")("meta"),i=e("./_is-object"),s=e("./_has"),o=e("./_object-dp").f,a=0,u=Object.isExtensible||function(){return!0},c=!e("./_fails")(function(){return u(Object.preventExtensions({}))}),l=function(e){o(e,n,{value:{i:"O"+ ++a,w:{}}})},f=t.exports={KEY:n,NEED:!1,fastKey:function(e,t){if(!i(e))return"symbol"==typeof e?e:("string"==typeof e?"S":"P")+e;if(!s(e,n)){if(!u(e))return"F";if(!t)return"E";l(e)}return e[n].i},getWeak:function(e,t){if(!s(e,n)){if(!u(e))return!0;if(!t)return!1;l(e)}return e[n].w},onFreeze:function(e){return c&&f.NEED&&u(e)&&!s(e,n)&&l(e),e}}},{"./_fails":93,"./_has":96,"./_is-object":104,"./_object-dp":117,"./_uid":149}],113:[function(e,t,r){var n=e("./_global"),i=e("./_task").set,s=n.MutationObserver||n.WebKitMutationObserver,o=n.process,a=n.Promise,u="process"==e("./_cof")(o);t.exports=function(){var e,t,r,c=function(){var n,i;for(u&&(n=o.domain)&&n.exit();e;){i=e.fn,e=e.next;try{i()}catch(n){throw e?r():t=void 0,n}}t=void 0,n&&n.enter()};if(u)r=function(){o.nextTick(c)};else if(!s||n.navigator&&n.navigator.standalone)if(a&&a.resolve){var l=a.resolve(void 0);r=function(){l.then(c)}}else r=function(){i.call(n,c)};else{var f=!0,d=document.createTextNode("");new s(c).observe(d,{characterData:!0}),r=function(){d.data=f=!f}}return function(n){var i={fn:n,next:void 0};t&&(t.next=i),e||(e=i,r()),t=i}}},{"./_cof":80,"./_global":95,"./_task":142}],114:[function(e,t,r){"use strict";
// 25.4.1.5 NewPromiseCapability(C)
var n=e("./_a-function");function i(e){var t,r;this.promise=new e(function(e,n){if(void 0!==t||void 0!==r)throw TypeError("Bad Promise constructor");t=e,r=n}),this.resolve=n(t),this.reject=n(r)}t.exports.f=function(e){return new i(e)}},{"./_a-function":69}],115:[function(e,t,r){"use strict";var n=e("./_descriptors"),i=e("./_object-keys"),s=e("./_object-gops"),o=e("./_object-pie"),a=e("./_to-object"),u=e("./_iobject"),c=Object.assign;t.exports=!c||e("./_fails")(function(){var e={},t={},r=Symbol(),n="abcdefghijklmnopqrst";return e[r]=7,n.split("").forEach(function(e){t[e]=e}),7!=c({},e)[r]||Object.keys(c({},t)).join("")!=n})?function(e,t){for(var r=a(e),c=arguments.length,l=1,f=s.f,d=o.f;c>l;)for(var p,h=u(arguments[l++]),b=f?i(h).concat(f(h)):i(h),v=b.length,m=0;v>m;)p=b[m++],n&&!d.call(h,p)||(r[p]=h[p]);return r}:c},{"./_descriptors":88,"./_fails":93,"./_iobject":101,"./_object-gops":122,"./_object-keys":125,"./_object-pie":126,"./_to-object":147}],116:[function(e,t,r){var n=e("./_an-object"),i=e("./_object-dps"),s=e("./_enum-bug-keys"),o=e("./_shared-key")("IE_PROTO"),a=function(){},u=function(){var t,r=e("./_dom-create")("iframe"),n=s.length;for(r.style.display="none",e("./_html").appendChild(r),r.src="javascript:",(t=r.contentWindow.document).open(),t.write("<script>document.F=Object<\/script>"),t.close(),u=t.F;n--;)delete u.prototype[s[n]];return u()};t.exports=Object.create||function(e,t){var r;return null!==e?(a.prototype=n(e),r=new a,a.prototype=null,r[o]=e):r=u(),void 0===t?r:i(r,t)}},{"./_an-object":72,"./_dom-create":89,"./_enum-bug-keys":90,"./_html":98,"./_object-dps":118,"./_shared-key":138}],117:[function(e,t,r){var n=e("./_an-object"),i=e("./_ie8-dom-define"),s=e("./_to-primitive"),o=Object.defineProperty;r.f=e("./_descriptors")?Object.defineProperty:function(e,t,r){if(n(e),t=s(t,!0),n(r),i)try{return o(e,t,r)}catch(e){}if("get"in r||"set"in r)throw TypeError("Accessors not supported!");return"value"in r&&(e[t]=r.value),e}},{"./_an-object":72,"./_descriptors":88,"./_ie8-dom-define":99,"./_to-primitive":148}],118:[function(e,t,r){var n=e("./_object-dp"),i=e("./_an-object"),s=e("./_object-keys");t.exports=e("./_descriptors")?Object.defineProperties:function(e,t){i(e);for(var r,o=s(t),a=o.length,u=0;a>u;)n.f(e,r=o[u++],t[r]);return e}},{"./_an-object":72,"./_descriptors":88,"./_object-dp":117,"./_object-keys":125}],119:[function(e,t,r){var n=e("./_object-pie"),i=e("./_property-desc"),s=e("./_to-iobject"),o=e("./_to-primitive"),a=e("./_has"),u=e("./_ie8-dom-define"),c=Object.getOwnPropertyDescriptor;r.f=e("./_descriptors")?c:function(e,t){if(e=s(e),t=o(t,!0),u)try{return c(e,t)}catch(e){}if(a(e,t))return i(!n.f.call(e,t),e[t])}},{"./_descriptors":88,"./_has":96,"./_ie8-dom-define":99,"./_object-pie":126,"./_property-desc":130,"./_to-iobject":145,"./_to-primitive":148}],120:[function(e,t,r){var n=e("./_to-iobject"),i=e("./_object-gopn").f,s={}.toString,o="object"==typeof window&&window&&Object.getOwnPropertyNames?Object.getOwnPropertyNames(window):[];t.exports.f=function(e){return o&&"[object Window]"==s.call(e)?function(e){try{return i(e)}catch(e){return o.slice()}}(e):i(n(e))}},{"./_object-gopn":121,"./_to-iobject":145}],121:[function(e,t,r){var n=e("./_object-keys-internal"),i=e("./_enum-bug-keys").concat("length","prototype");r.f=Object.getOwnPropertyNames||function(e){return n(e,i)}},{"./_enum-bug-keys":90,"./_object-keys-internal":124}],122:[function(e,t,r){r.f=Object.getOwnPropertySymbols},{}],123:[function(e,t,r){var n=e("./_has"),i=e("./_to-object"),s=e("./_shared-key")("IE_PROTO"),o=Object.prototype;t.exports=Object.getPrototypeOf||function(e){return e=i(e),n(e,s)?e[s]:"function"==typeof e.constructor&&e instanceof e.constructor?e.constructor.prototype:e instanceof Object?o:null}},{"./_has":96,"./_shared-key":138,"./_to-object":147}],124:[function(e,t,r){var n=e("./_has"),i=e("./_to-iobject"),s=e("./_array-includes")(!1),o=e("./_shared-key")("IE_PROTO");t.exports=function(e,t){var r,a=i(e),u=0,c=[];for(r in a)r!=o&&n(a,r)&&c.push(r);for(;t.length>u;)n(a,r=t[u++])&&(~s(c,r)||c.push(r));return c}},{"./_array-includes":74,"./_has":96,"./_shared-key":138,"./_to-iobject":145}],125:[function(e,t,r){var n=e("./_object-keys-internal"),i=e("./_enum-bug-keys");t.exports=Object.keys||function(e){return n(e,i)}},{"./_enum-bug-keys":90,"./_object-keys-internal":124}],126:[function(e,t,r){r.f={}.propertyIsEnumerable},{}],127:[function(e,t,r){var n=e("./_export"),i=e("./_core"),s=e("./_fails");t.exports=function(e,t){var r=(i.Object||{})[e]||Object[e],o={};o[e]=t(r),n(n.S+n.F*s(function(){r(1)}),"Object",o)}},{"./_core":84,"./_export":92,"./_fails":93}],128:[function(e,t,r){t.exports=function(e){try{return{e:!1,v:e()}}catch(e){return{e:!0,v:e}}}},{}],129:[function(e,t,r){var n=e("./_an-object"),i=e("./_is-object"),s=e("./_new-promise-capability");t.exports=function(e,t){if(n(e),i(t)&&t.constructor===e)return t;var r=s.f(e);return(0,r.resolve)(t),r.promise}},{"./_an-object":72,"./_is-object":104,"./_new-promise-capability":114}],130:[function(e,t,r){t.exports=function(e,t){return{enumerable:!(1&e),configurable:!(2&e),writable:!(4&e),value:t}}},{}],131:[function(e,t,r){var n=e("./_hide");t.exports=function(e,t,r){for(var i in t)r&&e[i]?e[i]=t[i]:n(e,i,t[i]);return e}},{"./_hide":97}],132:[function(e,t,r){t.exports=e("./_hide")},{"./_hide":97}],133:[function(e,t,r){"use strict";var n=e("./_export"),i=e("./_a-function"),s=e("./_ctx"),o=e("./_for-of");t.exports=function(e){n(n.S,e,{from:function(e){var t,r,n,a,u=arguments[1];return i(this),(t=void 0!==u)&&i(u),null==e?new this:(r=[],t?(n=0,a=s(u,arguments[2],2),o(e,!1,function(e){r.push(a(e,n++))})):o(e,!1,r.push,r),new this(r))}})}},{"./_a-function":69,"./_ctx":86,"./_export":92,"./_for-of":94}],134:[function(e,t,r){"use strict";var n=e("./_export");t.exports=function(e){n(n.S,e,{of:function(){for(var e=arguments.length,t=new Array(e);e--;)t[e]=arguments[e];return new this(t)}})}},{"./_export":92}],135:[function(e,t,r){var n=e("./_is-object"),i=e("./_an-object"),s=function(e,t){if(i(e),!n(t)&&null!==t)throw TypeError(t+": can't set as prototype!")};t.exports={set:Object.setPrototypeOf||("__proto__"in{}?function(t,r,n){try{(n=e("./_ctx")(Function.call,e("./_object-gopd").f(Object.prototype,"__proto__").set,2))(t,[]),r=!(t instanceof Array)}catch(e){r=!0}return function(e,t){return s(e,t),r?e.__proto__=t:n(e,t),e}}({},!1):void 0),check:s}},{"./_an-object":72,"./_ctx":86,"./_is-object":104,"./_object-gopd":119}],136:[function(e,t,r){"use strict";var n=e("./_global"),i=e("./_core"),s=e("./_object-dp"),o=e("./_descriptors"),a=e("./_wks")("species");t.exports=function(e){var t="function"==typeof i[e]?i[e]:n[e];o&&t&&!t[a]&&s.f(t,a,{configurable:!0,get:function(){return this}})}},{"./_core":84,"./_descriptors":88,"./_global":95,"./_object-dp":117,"./_wks":154}],137:[function(e,t,r){var n=e("./_object-dp").f,i=e("./_has"),s=e("./_wks")("toStringTag");t.exports=function(e,t,r){e&&!i(e=r?e:e.prototype,s)&&n(e,s,{configurable:!0,value:t})}},{"./_has":96,"./_object-dp":117,"./_wks":154}],138:[function(e,t,r){var n=e("./_shared")("keys"),i=e("./_uid");t.exports=function(e){return n[e]||(n[e]=i(e))}},{"./_shared":139,"./_uid":149}],139:[function(e,t,r){var n=e("./_core"),i=e("./_global"),s=i["__core-js_shared__"]||(i["__core-js_shared__"]={});(t.exports=function(e,t){return s[e]||(s[e]=void 0!==t?t:{})})("versions",[]).push({version:n.version,mode:e("./_library")?"pure":"global",copyright:"\xa9 2019 Denis Pushkarev (zloirock.ru)"})},{"./_core":84,"./_global":95,"./_library":111}],140:[function(e,t,r){var n=e("./_an-object"),i=e("./_a-function"),s=e("./_wks")("species");t.exports=function(e,t){var r,o=n(e).constructor;return void 0===o||null==(r=n(o)[s])?t:i(r)}},{"./_a-function":69,"./_an-object":72,"./_wks":154}],141:[function(e,t,r){var n=e("./_to-integer"),i=e("./_defined");t.exports=function(e){return function(t,r){var s,o,a=String(i(t)),u=n(r),c=a.length;return u<0||u>=c?e?"":void 0:(s=a.charCodeAt(u))<55296||s>56319||u+1===c||(o=a.charCodeAt(u+1))<56320||o>57343?e?a.charAt(u):s:e?a.slice(u,u+2):o-56320+(s-55296<<10)+65536}}},{"./_defined":87,"./_to-integer":144}],142:[function(e,t,r){var n,i,s,o=e("./_ctx"),a=e("./_invoke"),u=e("./_html"),c=e("./_dom-create"),l=e("./_global"),f=l.process,d=l.setImmediate,p=l.clearImmediate,h=l.MessageChannel,b=l.Dispatch,v=0,m={},y=function(){var e=+this;if(m.hasOwnProperty(e)){var t=m[e];delete m[e],t()}},g=function(e){y.call(e.data)};d&&p||(d=function(e){for(var t=[],r=1;arguments.length>r;)t.push(arguments[r++]);return m[++v]=function(){a("function"==typeof e?e:Function(e),t)},n(v),v},p=function(e){delete m[e]},"process"==e("./_cof")(f)?n=function(e){f.nextTick(o(y,e,1))}:b&&b.now?n=function(e){b.now(o(y,e,1))}:h?(s=(i=new h).port2,i.port1.onmessage=g,n=o(s.postMessage,s,1)):l.addEventListener&&"function"==typeof postMessage&&!l.importScripts?(n=function(e){l.postMessage(e+"","*")},l.addEventListener("message",g,!1)):n="onreadystatechange"in c("script")?function(e){u.appendChild(c("script")).onreadystatechange=function(){u.removeChild(this),y.call(e)}}:function(e){setTimeout(o(y,e,1),0)}),t.exports={set:d,clear:p}},{"./_cof":80,"./_ctx":86,"./_dom-create":89,"./_global":95,"./_html":98,"./_invoke":100}],143:[function(e,t,r){var n=e("./_to-integer"),i=Math.max,s=Math.min;t.exports=function(e,t){return(e=n(e))<0?i(e+t,0):s(e,t)}},{"./_to-integer":144}],144:[function(e,t,r){var n=Math.ceil,i=Math.floor;t.exports=function(e){return isNaN(e=+e)?0:(e>0?i:n)(e)}},{}],145:[function(e,t,r){var n=e("./_iobject"),i=e("./_defined");t.exports=function(e){return n(i(e))}},{"./_defined":87,"./_iobject":101}],146:[function(e,t,r){var n=e("./_to-integer"),i=Math.min;t.exports=function(e){return e>0?i(n(e),9007199254740991):0}},{"./_to-integer":144}],147:[function(e,t,r){var n=e("./_defined");t.exports=function(e){return Object(n(e))}},{"./_defined":87}],148:[function(e,t,r){var n=e("./_is-object");t.exports=function(e,t){if(!n(e))return e;var r,i;if(t&&"function"==typeof(r=e.toString)&&!n(i=r.call(e)))return i;if("function"==typeof(r=e.valueOf)&&!n(i=r.call(e)))return i;if(!t&&"function"==typeof(r=e.toString)&&!n(i=r.call(e)))return i;throw TypeError("Can't convert object to primitive value")}},{"./_is-object":104}],149:[function(e,t,r){var n=0,i=Math.random();t.exports=function(e){return"Symbol(".concat(void 0===e?"":e,")_",(++n+i).toString(36))}},{}],150:[function(e,t,r){var n=e("./_global").navigator;t.exports=n&&n.userAgent||""},{"./_global":95}],151:[function(e,t,r){var n=e("./_is-object");t.exports=function(e,t){if(!n(e)||e._t!==t)throw TypeError("Incompatible receiver, "+t+" required!");return e}},{"./_is-object":104}],152:[function(e,t,r){var n=e("./_global"),i=e("./_core"),s=e("./_library"),o=e("./_wks-ext"),a=e("./_object-dp").f;t.exports=function(e){var t=i.Symbol||(i.Symbol=s?{}:n.Symbol||{});"_"==e.charAt(0)||e in t||a(t,e,{value:o.f(e)})}},{"./_core":84,"./_global":95,"./_library":111,"./_object-dp":117,"./_wks-ext":153}],153:[function(e,t,r){r.f=e("./_wks")},{"./_wks":154}],154:[function(e,t,r){var n=e("./_shared")("wks"),i=e("./_uid"),s=e("./_global").Symbol,o="function"==typeof s;(t.exports=function(e){return n[e]||(n[e]=o&&s[e]||(o?s:i)("Symbol."+e))}).store=n},{"./_global":95,"./_shared":139,"./_uid":149}],155:[function(e,t,r){var n=e("./_classof"),i=e("./_wks")("iterator"),s=e("./_iterators");t.exports=e("./_core").getIteratorMethod=function(e){if(null!=e)return e[i]||e["@@iterator"]||s[n(e)]}},{"./_classof":79,"./_core":84,"./_iterators":110,"./_wks":154}],156:[function(e,t,r){var n=e("./_an-object"),i=e("./core.get-iterator-method");t.exports=e("./_core").getIterator=function(e){var t=i(e);if("function"!=typeof t)throw TypeError(e+" is not iterable!");return n(t.call(e))}},{"./_an-object":72,"./_core":84,"./core.get-iterator-method":155}],157:[function(e,t,r){var n=e("./_classof"),i=e("./_wks")("iterator"),s=e("./_iterators");t.exports=e("./_core").isIterable=function(e){var t=Object(e);return void 0!==t[i]||"@@iterator"in t||s.hasOwnProperty(n(t))}},{"./_classof":79,"./_core":84,"./_iterators":110,"./_wks":154}],158:[function(e,t,r){"use strict";var n=e("./_ctx"),i=e("./_export"),s=e("./_to-object"),o=e("./_iter-call"),a=e("./_is-array-iter"),u=e("./_to-length"),c=e("./_create-property"),l=e("./core.get-iterator-method");i(i.S+i.F*!e("./_iter-detect")(function(e){Array.from(e)}),"Array",{from:function(e){var t,r,i,f,d=s(e),p="function"==typeof this?this:Array,h=arguments.length,b=h>1?arguments[1]:void 0,v=void 0!==b,m=0,y=l(d);if(v&&(b=n(b,h>2?arguments[2]:void 0,2)),null==y||p==Array&&a(y))for(r=new p(t=u(d.length));t>m;m++)c(r,m,v?b(d[m],m):d[m]);else for(f=y.call(d),r=new p;!(i=f.next()).done;m++)c(r,m,v?o(f,b,[i.value,m],!0):i.value);return r.length=m,r}})},{"./_create-property":85,"./_ctx":86,"./_export":92,"./_is-array-iter":102,"./_iter-call":105,"./_iter-detect":108,"./_to-length":146,"./_to-object":147,"./core.get-iterator-method":155}],159:[function(e,t,r){"use strict";var n=e("./_add-to-unscopables"),i=e("./_iter-step"),s=e("./_iterators"),o=e("./_to-iobject");t.exports=e("./_iter-define")(Array,"Array",function(e,t){this._t=o(e),this._i=0,this._k=t},function(){var e=this._t,t=this._k,r=this._i++;return!e||r>=e.length?(this._t=void 0,i(1)):i(0,"keys"==t?r:"values"==t?e[r]:[r,e[r]])},"values"),s.Arguments=s.Array,n("keys"),n("values"),n("entries")},{"./_add-to-unscopables":70,"./_iter-define":107,"./_iter-step":109,"./_iterators":110,"./_to-iobject":145}],160:[function(e,t,r){"use strict";var n=e("./_collection-strong"),i=e("./_validate-collection");t.exports=e("./_collection")("Map",function(e){return function(){return e(this,arguments.length>0?arguments[0]:void 0)}},{get:function(e){var t=n.getEntry(i(this,"Map"),e);return t&&t.v},set:function(e,t){return n.def(i(this,"Map"),0===e?0:e,t)}},n,!0)},{"./_collection":83,"./_collection-strong":81,"./_validate-collection":151}],161:[function(e,t,r){var n=e("./_export");n(n.S+n.F,"Object",{assign:e("./_object-assign")})},{"./_export":92,"./_object-assign":115}],162:[function(e,t,r){var n=e("./_export");n(n.S,"Object",{create:e("./_object-create")})},{"./_export":92,"./_object-create":116}],163:[function(e,t,r){var n=e("./_export");n(n.S+n.F*!e("./_descriptors"),"Object",{defineProperty:e("./_object-dp").f})},{"./_descriptors":88,"./_export":92,"./_object-dp":117}],164:[function(e,t,r){var n=e("./_to-iobject"),i=e("./_object-gopd").f;e("./_object-sap")("getOwnPropertyDescriptor",function(){return function(e,t){return i(n(e),t)}})},{"./_object-gopd":119,"./_object-sap":127,"./_to-iobject":145}],165:[function(e,t,r){var n=e("./_to-object"),i=e("./_object-gpo");e("./_object-sap")("getPrototypeOf",function(){return function(e){return i(n(e))}})},{"./_object-gpo":123,"./_object-sap":127,"./_to-object":147}],166:[function(e,t,r){var n=e("./_export");n(n.S,"Object",{setPrototypeOf:e("./_set-proto").set})},{"./_export":92,"./_set-proto":135}],167:[function(e,t,r){},{}],168:[function(e,t,r){"use strict";var n,i,s,o,a=e("./_library"),u=e("./_global"),c=e("./_ctx"),l=e("./_classof"),f=e("./_export"),d=e("./_is-object"),p=e("./_a-function"),h=e("./_an-instance"),b=e("./_for-of"),v=e("./_species-constructor"),m=e("./_task").set,y=e("./_microtask")(),g=e("./_new-promise-capability"),_=e("./_perform"),k=e("./_user-agent"),w=e("./_promise-resolve"),x=u.TypeError,j=u.process,C=j&&j.versions,S=C&&C.v8||"",T=u.Promise,E="process"==l(j),I=function(){},M=i=g.f,R=!!function(){try{var t=T.resolve(1),r=(t.constructor={})[e("./_wks")("species")]=function(e){e(I,I)};return(E||"function"==typeof PromiseRejectionEvent)&&t.then(I)instanceof r&&0!==S.indexOf("6.6")&&-1===k.indexOf("Chrome/66")}catch(e){}}(),O=function(e){var t;return!(!d(e)||"function"!=typeof(t=e.then))&&t},P=function(e,t){if(!e._n){e._n=!0;var r=e._c;y(function(){for(var n=e._v,i=1==e._s,s=0,o=function(t){var r,s,o,a=i?t.ok:t.fail,u=t.resolve,c=t.reject,l=t.domain;try{a?(i||(2==e._h&&A(e),e._h=1),!0===a?r=n:(l&&l.enter(),r=a(n),l&&(l.exit(),o=!0)),r===t.promise?c(x("Promise-chain cycle")):(s=O(r))?s.call(r,u,c):u(r)):c(n)}catch(e){l&&!o&&l.exit(),c(e)}};r.length>s;)o(r[s++]);e._c=[],e._n=!1,t&&!e._h&&L(e)})}},L=function(e){m.call(u,function(){var t,r,n,i=e._v,s=N(e);if(s&&(t=_(function(){E?j.emit("unhandledRejection",i,e):(r=u.onunhandledrejection)?r({promise:e,reason:i}):(n=u.console)&&n.error&&n.error("Unhandled promise rejection",i)}),e._h=E||N(e)?2:1),e._a=void 0,s&&t.e)throw t.v})},N=function(e){return 1!==e._h&&0===(e._a||e._c).length},A=function(e){m.call(u,function(){var t;E?j.emit("rejectionHandled",e):(t=u.onrejectionhandled)&&t({promise:e,reason:e._v})})},F=function(e){var t=this;t._d||(t._d=!0,(t=t._w||t)._v=e,t._s=2,t._a||(t._a=t._c.slice()),P(t,!0))},D=function(e){var t,r=this;if(!r._d){r._d=!0,r=r._w||r;try{if(r===e)throw x("Promise can't be resolved itself");(t=O(e))?y(function(){var n={_w:r,_d:!1};try{t.call(e,c(D,n,1),c(F,n,1))}catch(e){F.call(n,e)}}):(r._v=e,r._s=1,P(r,!1))}catch(e){F.call({_w:r,_d:!1},e)}}};R||(T=function(e){h(this,T,"Promise","_h"),p(e),n.call(this);try{e(c(D,this,1),c(F,this,1))}catch(e){F.call(this,e)}},(n=function(e){this._c=[],this._a=void 0,this._s=0,this._d=!1,this._v=void 0,this._h=0,this._n=!1}).prototype=e("./_redefine-all")(T.prototype,{then:function(e,t){var r=M(v(this,T));return r.ok="function"!=typeof e||e,r.fail="function"==typeof t&&t,r.domain=E?j.domain:void 0,this._c.push(r),this._a&&this._a.push(r),this._s&&P(this,!1),r.promise},catch:function(e){return this.then(void 0,e)}}),s=function(){var e=new n;this.promise=e,this.resolve=c(D,e,1),this.reject=c(F,e,1)},g.f=M=function(e){return e===T||e===o?new s(e):i(e)}),f(f.G+f.W+f.F*!R,{Promise:T}),e("./_set-to-string-tag")(T,"Promise"),e("./_set-species")("Promise"),o=e("./_core").Promise,f(f.S+f.F*!R,"Promise",{reject:function(e){var t=M(this);return(0,t.reject)(e),t.promise}}),f(f.S+f.F*(a||!R),"Promise",{resolve:function(e){return w(a&&this===o?T:this,e)}}),f(f.S+f.F*!(R&&e("./_iter-detect")(function(e){T.all(e).catch(I)})),"Promise",{all:function(e){var t=this,r=M(t),n=r.resolve,i=r.reject,s=_(function(){var r=[],s=0,o=1;b(e,!1,function(e){var a=s++,u=!1;r.push(void 0),o++,t.resolve(e).then(function(e){u||(u=!0,r[a]=e,--o||n(r))},i)}),--o||n(r)});return s.e&&i(s.v),r.promise},race:function(e){var t=this,r=M(t),n=r.reject,i=_(function(){b(e,!1,function(e){t.resolve(e).then(r.resolve,n)})});return i.e&&n(i.v),r.promise}})},{"./_a-function":69,"./_an-instance":71,"./_classof":79,"./_core":84,"./_ctx":86,"./_export":92,"./_for-of":94,"./_global":95,"./_is-object":104,"./_iter-detect":108,"./_library":111,"./_microtask":113,"./_new-promise-capability":114,"./_perform":128,"./_promise-resolve":129,"./_redefine-all":131,"./_set-species":136,"./_set-to-string-tag":137,"./_species-constructor":140,"./_task":142,"./_user-agent":150,"./_wks":154}],169:[function(e,t,r){var n=e("./_export"),i=e("./_object-create"),s=e("./_a-function"),o=e("./_an-object"),a=e("./_is-object"),u=e("./_fails"),c=e("./_bind"),l=(e("./_global").Reflect||{}).construct,f=u(function(){function e(){}return!(l(function(){},[],e)instanceof e)}),d=!u(function(){l(function(){})});n(n.S+n.F*(f||d),"Reflect",{construct:function(e,t){s(e),o(t);var r=arguments.length<3?e:s(arguments[2]);if(d&&!f)return l(e,t,r);if(e==r){switch(t.length){case 0:return new e;case 1:return new e(t[0]);case 2:return new e(t[0],t[1]);case 3:return new e(t[0],t[1],t[2]);case 4:return new e(t[0],t[1],t[2],t[3])}var n=[null];return n.push.apply(n,t),new(c.apply(e,n))}var u=r.prototype,p=i(a(u)?u:Object.prototype),h=Function.apply.call(e,p,t);return a(h)?h:p}})},{"./_a-function":69,"./_an-object":72,"./_bind":78,"./_export":92,"./_fails":93,"./_global":95,"./_is-object":104,"./_object-create":116}],170:[function(e,t,r){"use strict";var n=e("./_collection-strong"),i=e("./_validate-collection");t.exports=e("./_collection")("Set",function(e){return function(){return e(this,arguments.length>0?arguments[0]:void 0)}},{add:function(e){return n.def(i(this,"Set"),e=0===e?0:e,e)}},n)},{"./_collection":83,"./_collection-strong":81,"./_validate-collection":151}],171:[function(e,t,r){"use strict";var n=e("./_string-at")(!0);e("./_iter-define")(String,"String",function(e){this._t=String(e),this._i=0},function(){var e,t=this._t,r=this._i;return r>=t.length?{value:void 0,done:!0}:(e=n(t,r),this._i+=e.length,{value:e,done:!1})})},{"./_iter-define":107,"./_string-at":141}],172:[function(e,t,r){"use strict";var n=e("./_global"),i=e("./_has"),s=e("./_descriptors"),o=e("./_export"),a=e("./_redefine"),u=e("./_meta").KEY,c=e("./_fails"),l=e("./_shared"),f=e("./_set-to-string-tag"),d=e("./_uid"),p=e("./_wks"),h=e("./_wks-ext"),b=e("./_wks-define"),v=e("./_enum-keys"),m=e("./_is-array"),y=e("./_an-object"),g=e("./_is-object"),_=e("./_to-object"),k=e("./_to-iobject"),w=e("./_to-primitive"),x=e("./_property-desc"),j=e("./_object-create"),C=e("./_object-gopn-ext"),S=e("./_object-gopd"),T=e("./_object-gops"),E=e("./_object-dp"),I=e("./_object-keys"),M=S.f,R=E.f,O=C.f,P=n.Symbol,L=n.JSON,N=L&&L.stringify,A=p("_hidden"),F=p("toPrimitive"),D={}.propertyIsEnumerable,q=l("symbol-registry"),U=l("symbols"),B=l("op-symbols"),W=Object.prototype,G="function"==typeof P&&!!T.f,z=n.QObject,K=!z||!z.prototype||!z.prototype.findChild,Q=s&&c(function(){return 7!=j(R({},"a",{get:function(){return R(this,"a",{value:7}).a}})).a})?function(e,t,r){var n=M(W,t);n&&delete W[t],R(e,t,r),n&&e!==W&&R(W,t,n)}:R,V=function(e){var t=U[e]=j(P.prototype);return t._k=e,t},$=G&&"symbol"==typeof P.iterator?function(e){return"symbol"==typeof e}:function(e){return e instanceof P},H=function(e,t,r){return e===W&&H(B,t,r),y(e),t=w(t,!0),y(r),i(U,t)?(r.enumerable?(i(e,A)&&e[A][t]&&(e[A][t]=!1),r=j(r,{enumerable:x(0,!1)})):(i(e,A)||R(e,A,x(1,{})),e[A][t]=!0),Q(e,t,r)):R(e,t,r)},X=function(e,t){y(e);for(var r,n=v(t=k(t)),i=0,s=n.length;s>i;)H(e,r=n[i++],t[r]);return e},J=function(e){var t=D.call(this,e=w(e,!0));return!(this===W&&i(U,e)&&!i(B,e))&&(!(t||!i(this,e)||!i(U,e)||i(this,A)&&this[A][e])||t)},Y=function(e,t){if(e=k(e),t=w(t,!0),e!==W||!i(U,t)||i(B,t)){var r=M(e,t);return!r||!i(U,t)||i(e,A)&&e[A][t]||(r.enumerable=!0),r}},Z=function(e){for(var t,r=O(k(e)),n=[],s=0;r.length>s;)i(U,t=r[s++])||t==A||t==u||n.push(t);return n},ee=function(e){for(var t,r=e===W,n=O(r?B:k(e)),s=[],o=0;n.length>o;)!i(U,t=n[o++])||r&&!i(W,t)||s.push(U[t]);return s};G||(a((P=function(){if(this instanceof P)throw TypeError("Symbol is not a constructor!");var e=d(arguments.length>0?arguments[0]:void 0),t=function(r){this===W&&t.call(B,r),i(this,A)&&i(this[A],e)&&(this[A][e]=!1),Q(this,e,x(1,r))};return s&&K&&Q(W,e,{configurable:!0,set:t}),V(e)}).prototype,"toString",function(){return this._k}),S.f=Y,E.f=H,e("./_object-gopn").f=C.f=Z,e("./_object-pie").f=J,T.f=ee,s&&!e("./_library")&&a(W,"propertyIsEnumerable",J,!0),h.f=function(e){return V(p(e))}),o(o.G+o.W+o.F*!G,{Symbol:P});for(var te="hasInstance,isConcatSpreadable,iterator,match,replace,search,species,split,toPrimitive,toStringTag,unscopables".split(","),re=0;te.length>re;)p(te[re++]);for(var ne=I(p.store),ie=0;ne.length>ie;)b(ne[ie++]);o(o.S+o.F*!G,"Symbol",{for:function(e){return i(q,e+="")?q[e]:q[e]=P(e)},keyFor:function(e){if(!$(e))throw TypeError(e+" is not a symbol!");for(var t in q)if(q[t]===e)return t},useSetter:function(){K=!0},useSimple:function(){K=!1}}),o(o.S+o.F*!G,"Object",{create:function(e,t){return void 0===t?j(e):X(j(e),t)},defineProperty:H,defineProperties:X,getOwnPropertyDescriptor:Y,getOwnPropertyNames:Z,getOwnPropertySymbols:ee});var se=c(function(){T.f(1)});o(o.S+o.F*se,"Object",{getOwnPropertySymbols:function(e){return T.f(_(e))}}),L&&o(o.S+o.F*(!G||c(function(){var e=P();return"[null]"!=N([e])||"{}"!=N({a:e})||"{}"!=N(Object(e))})),"JSON",{stringify:function(e){for(var t,r,n=[e],i=1;arguments.length>i;)n.push(arguments[i++]);if(r=t=n[1],(g(t)||void 0!==e)&&!$(e))return m(t)||(t=function(e,t){if("function"==typeof r&&(t=r.call(this,e,t)),!$(t))return t}),n[1]=t,N.apply(L,n)}}),P.prototype[F]||e("./_hide")(P.prototype,F,P.prototype.valueOf),f(P,"Symbol"),f(Math,"Math",!0),f(n.JSON,"JSON",!0)},{"./_an-object":72,"./_descriptors":88,"./_enum-keys":91,"./_export":92,"./_fails":93,"./_global":95,"./_has":96,"./_hide":97,"./_is-array":103,"./_is-object":104,"./_library":111,"./_meta":112,"./_object-create":116,"./_object-dp":117,"./_object-gopd":119,"./_object-gopn":121,"./_object-gopn-ext":120,"./_object-gops":122,"./_object-keys":125,"./_object-pie":126,"./_property-desc":130,"./_redefine":132,"./_set-to-string-tag":137,"./_shared":139,"./_to-iobject":145,"./_to-object":147,"./_to-primitive":148,"./_uid":149,"./_wks":154,"./_wks-define":152,"./_wks-ext":153}],173:[function(e,t,r){e("./_set-collection-from")("Map")},{"./_set-collection-from":133}],174:[function(e,t,r){e("./_set-collection-of")("Map")},{"./_set-collection-of":134}],175:[function(e,t,r){var n=e("./_export");n(n.P+n.R,"Map",{toJSON:e("./_collection-to-json")("Map")})},{"./_collection-to-json":82,"./_export":92}],176:[function(e,t,r){"use strict";var n=e("./_export"),i=e("./_core"),s=e("./_global"),o=e("./_species-constructor"),a=e("./_promise-resolve");n(n.P+n.R,"Promise",{finally:function(e){var t=o(this,i.Promise||s.Promise),r="function"==typeof e;return this.then(r?function(r){return a(t,e()).then(function(){return r})}:e,r?function(r){return a(t,e()).then(function(){throw r})}:e)}})},{"./_core":84,"./_export":92,"./_global":95,"./_promise-resolve":129,"./_species-constructor":140}],177:[function(e,t,r){"use strict";var n=e("./_export"),i=e("./_new-promise-capability"),s=e("./_perform");n(n.S,"Promise",{try:function(e){var t=i.f(this),r=s(e);return(r.e?t.reject:t.resolve)(r.v),t.promise}})},{"./_export":92,"./_new-promise-capability":114,"./_perform":128}],178:[function(e,t,r){e("./_set-collection-from")("Set")},{"./_set-collection-from":133}],179:[function(e,t,r){e("./_set-collection-of")("Set")},{"./_set-collection-of":134}],180:[function(e,t,r){var n=e("./_export");n(n.P+n.R,"Set",{toJSON:e("./_collection-to-json")("Set")})},{"./_collection-to-json":82,"./_export":92}],181:[function(e,t,r){e("./_wks-define")("asyncIterator")},{"./_wks-define":152}],182:[function(e,t,r){e("./_wks-define")("observable")},{"./_wks-define":152}],183:[function(e,t,r){e("./es6.array.iterator");for(var n=e("./_global"),i=e("./_hide"),s=e("./_iterators"),o=e("./_wks")("toStringTag"),a="CSSRuleList,CSSStyleDeclaration,CSSValueList,ClientRectList,DOMRectList,DOMStringList,DOMTokenList,DataTransferItemList,FileList,HTMLAllCollection,HTMLCollection,HTMLFormElement,HTMLSelectElement,MediaList,MimeTypeArray,NamedNodeMap,NodeList,PaintRequestList,Plugin,PluginArray,SVGLengthList,SVGNumberList,SVGPathSegList,SVGPointList,SVGStringList,SVGTransformList,SourceBufferList,StyleSheetList,TextTrackCueList,TextTrackList,TouchList".split(","),u=0;u<a.length;u++){var c=a[u],l=n[c],f=l&&l.prototype;f&&!f[o]&&i(f,o,c),s[c]=s.Array}},{"./_global":95,"./_hide":97,"./_iterators":110,"./_wks":154,"./es6.array.iterator":159}],184:[function(e,t,r){
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
var n=Object.create||function(e){var t=function(){};return t.prototype=e,new t},i=Object.keys||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.push(r);return r},s=Function.prototype.bind||function(e){var t=this;return function(){return t.apply(e,arguments)}};function o(){this._events&&Object.prototype.hasOwnProperty.call(this,"_events")||(this._events=n(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0}t.exports=o,o.EventEmitter=o,o.prototype._events=void 0,o.prototype._maxListeners=void 0;var a,u=10;try{var c={};Object.defineProperty&&Object.defineProperty(c,"x",{value:0}),a=0===c.x}catch(e){a=!1}function l(e){return void 0===e._maxListeners?o.defaultMaxListeners:e._maxListeners}function f(e,t,r,i){var s,o,a;if("function"!=typeof r)throw new TypeError('"listener" argument must be a function');if((o=e._events)?(o.newListener&&(e.emit("newListener",t,r.listener?r.listener:r),o=e._events),a=o[t]):(o=e._events=n(null),e._eventsCount=0),a){if("function"==typeof a?a=o[t]=i?[r,a]:[a,r]:i?a.unshift(r):a.push(r),!a.warned&&(s=l(e))&&s>0&&a.length>s){a.warned=!0;var u=new Error("Possible EventEmitter memory leak detected. "+a.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');u.name="MaxListenersExceededWarning",u.emitter=e,u.type=t,u.count=a.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",u.name,u.message)}}else a=o[t]=r,++e._eventsCount;return e}function d(){if(!this.fired)switch(this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length){case 0:return this.listener.call(this.target);case 1:return this.listener.call(this.target,arguments[0]);case 2:return this.listener.call(this.target,arguments[0],arguments[1]);case 3:return this.listener.call(this.target,arguments[0],arguments[1],arguments[2]);default:for(var e=new Array(arguments.length),t=0;t<e.length;++t)e[t]=arguments[t];this.listener.apply(this.target,e)}}function p(e,t,r){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},i=s.call(d,n);return i.listener=r,n.wrapFn=i,i}function h(e,t,r){var n=e._events;if(!n)return[];var i=n[t];return i?"function"==typeof i?r?[i.listener||i]:[i]:r?function(e){for(var t=new Array(e.length),r=0;r<t.length;++r)t[r]=e[r].listener||e[r];return t}(i):v(i,i.length):[]}function b(e){var t=this._events;if(t){var r=t[e];if("function"==typeof r)return 1;if(r)return r.length}return 0}function v(e,t){for(var r=new Array(t),n=0;n<t;++n)r[n]=e[n];return r}a?Object.defineProperty(o,"defaultMaxListeners",{enumerable:!0,get:function(){return u},set:function(e){if("number"!=typeof e||e<0||e!=e)throw new TypeError('"defaultMaxListeners" must be a positive number');u=e}}):o.defaultMaxListeners=u,o.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||isNaN(e))throw new TypeError('"n" argument must be a positive number');return this._maxListeners=e,this},o.prototype.getMaxListeners=function(){return l(this)},o.prototype.emit=function(e){var t,r,n,i,s,o,a="error"===e;if(o=this._events)a=a&&null==o.error;else if(!a)return!1;if(a){if(arguments.length>1&&(t=arguments[1]),t instanceof Error)throw t;var u=new Error('Unhandled "error" event. ('+t+")");throw u.context=t,u}if(!(r=o[e]))return!1;var c="function"==typeof r;switch(n=arguments.length){case 1:!function(e,t,r){if(t)e.call(r);else for(var n=e.length,i=v(e,n),s=0;s<n;++s)i[s].call(r)}(r,c,this);break;case 2:!function(e,t,r,n){if(t)e.call(r,n);else for(var i=e.length,s=v(e,i),o=0;o<i;++o)s[o].call(r,n)}(r,c,this,arguments[1]);break;case 3:!function(e,t,r,n,i){if(t)e.call(r,n,i);else for(var s=e.length,o=v(e,s),a=0;a<s;++a)o[a].call(r,n,i)}(r,c,this,arguments[1],arguments[2]);break;case 4:!function(e,t,r,n,i,s){if(t)e.call(r,n,i,s);else for(var o=e.length,a=v(e,o),u=0;u<o;++u)a[u].call(r,n,i,s)}(r,c,this,arguments[1],arguments[2],arguments[3]);break;default:for(i=new Array(n-1),s=1;s<n;s++)i[s-1]=arguments[s];!function(e,t,r,n){if(t)e.apply(r,n);else for(var i=e.length,s=v(e,i),o=0;o<i;++o)s[o].apply(r,n)}(r,c,this,i)}return!0},o.prototype.addListener=function(e,t){return f(this,e,t,!1)},o.prototype.on=o.prototype.addListener,o.prototype.prependListener=function(e,t){return f(this,e,t,!0)},o.prototype.once=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.on(e,p(this,e,t)),this},o.prototype.prependOnceListener=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.prependListener(e,p(this,e,t)),this},o.prototype.removeListener=function(e,t){var r,i,s,o,a;if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');if(!(i=this._events))return this;if(!(r=i[e]))return this;if(r===t||r.listener===t)0==--this._eventsCount?this._events=n(null):(delete i[e],i.removeListener&&this.emit("removeListener",e,r.listener||t));else if("function"!=typeof r){for(s=-1,o=r.length-1;o>=0;o--)if(r[o]===t||r[o].listener===t){a=r[o].listener,s=o;break}if(s<0)return this;0===s?r.shift():function(e,t){for(var r=t,n=r+1,i=e.length;n<i;r+=1,n+=1)e[r]=e[n];e.pop()}(r,s),1===r.length&&(i[e]=r[0]),i.removeListener&&this.emit("removeListener",e,a||t)}return this},o.prototype.removeAllListeners=function(e){var t,r,s;if(!(r=this._events))return this;if(!r.removeListener)return 0===arguments.length?(this._events=n(null),this._eventsCount=0):r[e]&&(0==--this._eventsCount?this._events=n(null):delete r[e]),this;if(0===arguments.length){var o,a=i(r);for(s=0;s<a.length;++s)"removeListener"!==(o=a[s])&&this.removeAllListeners(o);return this.removeAllListeners("removeListener"),this._events=n(null),this._eventsCount=0,this}if("function"==typeof(t=r[e]))this.removeListener(e,t);else if(t)for(s=t.length-1;s>=0;s--)this.removeListener(e,t[s]);return this},o.prototype.listeners=function(e){return h(this,e,!0)},o.prototype.rawListeners=function(e){return h(this,e,!1)},o.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):b.call(e,t)},o.prototype.listenerCount=b,o.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]}},{}],185:[function(e,t,r){var n,i;n=this,i=function(){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var i=t[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=e,r.c=t,r.i=function(e){return e},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=5)}([function(e,t,r){"use strict";e.exports=function(e,t){var r,n,i;for(r=1;r<arguments.length;r++)for(i in n=arguments[r])n.hasOwnProperty(i)&&(e[i]=n[i]);return e}},function(e,t,r){"use strict";var n=r(0);e.exports={build:function(e,t){var r,i,s,o=t.plugins;for(r=0,i=o.length;r<i;r++)(s=o[r]).methods&&n(e,s.methods),s.properties&&Object.defineProperties(e,s.properties)},hook:function(e,t,r){var n,i,s,o,a=e.config.plugins,u=[e.context];for(r&&(u=u.concat(r)),n=0,i=a.length;n<i;n++)o=a[n],(s=a[n][t])&&s.apply(o,u)}}},function(e,t,r){"use strict";function n(e){if(0===e.length)return e;var t,r,n=e.split(/[_-]/);if(1===n.length&&n[0][0].toLowerCase()===n[0][0])return e;for(r=n[0].toLowerCase(),t=1;t<n.length;t++)r=r+n[t].charAt(0).toUpperCase()+n[t].substring(1).toLowerCase();return r}n.prepended=function(e,t){return e+(t=n(t))[0].toUpperCase()+t.substring(1)},e.exports=n},function(e,t,r){"use strict";var n=r(0),i=r(2);function s(e,t){e=e||{},this.options=e,this.defaults=t.defaults,this.states=[],this.transitions=[],this.map={},this.lifecycle=this.configureLifecycle(),this.init=this.configureInitTransition(e.init),this.data=this.configureData(e.data),this.methods=this.configureMethods(e.methods),this.map[this.defaults.wildcard]={},this.configureTransitions(e.transitions||[]),this.plugins=this.configurePlugins(e.plugins,t.plugin)}n(s.prototype,{addState:function(e){this.map[e]||(this.states.push(e),this.addStateLifecycleNames(e),this.map[e]={})},addStateLifecycleNames:function(e){this.lifecycle.onEnter[e]=i.prepended("onEnter",e),this.lifecycle.onLeave[e]=i.prepended("onLeave",e),this.lifecycle.on[e]=i.prepended("on",e)},addTransition:function(e){this.transitions.indexOf(e)<0&&(this.transitions.push(e),this.addTransitionLifecycleNames(e))},addTransitionLifecycleNames:function(e){this.lifecycle.onBefore[e]=i.prepended("onBefore",e),this.lifecycle.onAfter[e]=i.prepended("onAfter",e),this.lifecycle.on[e]=i.prepended("on",e)},mapTransition:function(e){var t=e.name,r=e.from,n=e.to;return this.addState(r),"function"!=typeof n&&this.addState(n),this.addTransition(t),this.map[r][t]=e,e},configureLifecycle:function(){return{onBefore:{transition:"onBeforeTransition"},onAfter:{transition:"onAfterTransition"},onEnter:{state:"onEnterState"},onLeave:{state:"onLeaveState"},on:{transition:"onTransition"}}},configureInitTransition:function(e){return"string"==typeof e?this.mapTransition(n({},this.defaults.init,{to:e,active:!0})):"object"==typeof e?this.mapTransition(n({},this.defaults.init,e,{active:!0})):(this.addState(this.defaults.init.from),this.defaults.init)},configureData:function(e){return"function"==typeof e?e:"object"==typeof e?function(){return e}:function(){return{}}},configureMethods:function(e){return e||{}},configurePlugins:function(e,t){var r,n,i;for(r=0,n=(e=e||[]).length;r<n;r++)"function"==typeof(i=e[r])&&(e[r]=i=i()),i.configure&&i.configure(this);return e},configureTransitions:function(e){var t,r,n,i,s,o=this.defaults.wildcard;for(r=0;r<e.length;r++)for(n=e[r],i=Array.isArray(n.from)?n.from:[n.from||o],s=n.to||o,t=0;t<i.length;t++)this.mapTransition({name:n.name,from:i[t],to:s})},transitionFor:function(e,t){var r=this.defaults.wildcard;return this.map[e][t]||this.map[r][t]},transitionsFor:function(e){var t=this.defaults.wildcard;return Object.keys(this.map[e]).concat(Object.keys(this.map[t]))},allStates:function(){return this.states},allTransitions:function(){return this.transitions}}),e.exports=s},function(e,t,r){var n=r(0),i=r(6),s=r(1),o=[null,[]];function a(e,t){this.context=e,this.config=t,this.state=t.init.from,this.observers=[e]}n(a.prototype,{init:function(e){if(n(this.context,this.config.data.apply(this.context,e)),s.hook(this,"init"),this.config.init.active)return this.fire(this.config.init.name,[])},is:function(e){return Array.isArray(e)?e.indexOf(this.state)>=0:this.state===e},isPending:function(){return this.pending},can:function(e){return!this.isPending()&&!!this.seek(e)},cannot:function(e){return!this.can(e)},allStates:function(){return this.config.allStates()},allTransitions:function(){return this.config.allTransitions()},transitions:function(){return this.config.transitionsFor(this.state)},seek:function(e,t){var r=this.config.defaults.wildcard,n=this.config.transitionFor(this.state,e),i=n&&n.to;return"function"==typeof i?i.apply(this.context,t):i===r?this.state:i},fire:function(e,t){return this.transit(e,this.state,this.seek(e,t),t)},transit:function(e,t,r,n){var i=this.config.lifecycle,s=this.config.options.observeUnchangedState||t!==r;return r?this.isPending()?this.context.onPendingTransition(e,t,r):(this.config.addState(r),this.beginTransit(),n.unshift({transition:e,from:t,to:r,fsm:this.context}),this.observeEvents([this.observersForEvent(i.onBefore.transition),this.observersForEvent(i.onBefore[e]),s?this.observersForEvent(i.onLeave.state):o,s?this.observersForEvent(i.onLeave[t]):o,this.observersForEvent(i.on.transition),s?["doTransit",[this]]:o,s?this.observersForEvent(i.onEnter.state):o,s?this.observersForEvent(i.onEnter[r]):o,s?this.observersForEvent(i.on[r]):o,this.observersForEvent(i.onAfter.transition),this.observersForEvent(i.onAfter[e]),this.observersForEvent(i.on[e])],n)):this.context.onInvalidTransition(e,t,r)},beginTransit:function(){this.pending=!0},endTransit:function(e){return this.pending=!1,e},failTransit:function(e){throw this.pending=!1,e},doTransit:function(e){this.state=e.to},observe:function(e){if(2===e.length){var t={};t[e[0]]=e[1],this.observers.push(t)}else this.observers.push(e[0])},observersForEvent:function(e){for(var t,r=0,n=this.observers.length,i=[];r<n;r++)(t=this.observers[r])[e]&&i.push(t);return[e,i,!0]},observeEvents:function(e,t,r,n){if(0===e.length)return this.endTransit(void 0===n||n);var i=e[0][0],o=e[0][1],a=e[0][2];if(t[0].event=i,i&&a&&i!==r&&s.hook(this,"lifecycle",t),0===o.length)return e.shift(),this.observeEvents(e,t,i,n);var u=o.shift(),c=u[i].apply(u,t);return c&&"function"==typeof c.then?c.then(this.observeEvents.bind(this,e,t,i)).catch(this.failTransit.bind(this)):!1===c?this.endTransit(!1):this.observeEvents(e,t,i,c)},onInvalidTransition:function(e,t,r){throw new i("transition is invalid in current state",e,t,r,this.state)},onPendingTransition:function(e,t,r){throw new i("transition is invalid while previous transition is still in progress",e,t,r,this.state)}}),e.exports=a},function(e,t,r){"use strict";var n=r(0),i=r(2),s=r(1),o=r(3),a=r(4),u={is:function(e){return this._fsm.is(e)},can:function(e){return this._fsm.can(e)},cannot:function(e){return this._fsm.cannot(e)},observe:function(){return this._fsm.observe(arguments)},transitions:function(){return this._fsm.transitions()},allTransitions:function(){return this._fsm.allTransitions()},allStates:function(){return this._fsm.allStates()},onInvalidTransition:function(e,t,r){return this._fsm.onInvalidTransition(e,t,r)},onPendingTransition:function(e,t,r){return this._fsm.onPendingTransition(e,t,r)}},c={state:{configurable:!1,enumerable:!0,get:function(){return this._fsm.state},set:function(e){throw Error("use transitions to change state")}}};function l(e){return f(this||{},e)}function f(e,t){return d(e,new o(t,l)),e._fsm(),e}function d(e,t){if("object"!=typeof e||Array.isArray(e))throw Error("StateMachine can only be applied to objects");s.build(e,t),Object.defineProperties(e,c),n(e,u),n(e,t.methods),t.allTransitions().forEach(function(t){e[i(t)]=function(){return this._fsm.fire(t,[].slice.call(arguments))}}),e._fsm=function(){this._fsm=new a(this,t),this._fsm.init(arguments)}}l.version="3.0.1",l.factory=function(){var e,t;"function"==typeof arguments[0]?(e=arguments[0],t=arguments[1]||{}):(e=function(){this._fsm.apply(this,arguments)},t=arguments[0]||{});var r=new o(t,l);return d(e.prototype,r),e.prototype._fsm.config=r,e},l.apply=f,l.defaults={wildcard:"*",init:{name:"init",from:"none"}},e.exports=l},function(e,t,r){"use strict";e.exports=function(e,t,r,n,i){this.message=e,this.transition=t,this.from=r,this.to=n,this.current=i}}])},"object"==typeof r&&"object"==typeof t?t.exports=i():"object"==typeof r?r.StateMachine=i():n.StateMachine=i()},{}],186:[function(e,t,r){
/*
* loglevel - https://github.com/pimterry/loglevel
*
* Copyright (c) 2013 Tim Perry
* Licensed under the MIT license.
*/
!function(e,r){"use strict";"object"==typeof t&&t.exports?t.exports=r():e.log=r()}(this,function(){"use strict";var e=function(){},t="undefined",r=typeof window!==t&&typeof window.navigator!==t&&/Trident\/|MSIE /.test(window.navigator.userAgent),n=["trace","debug","info","warn","error"];function i(e,t){var r=e[t];if("function"==typeof r.bind)return r.bind(e);try{return Function.prototype.bind.call(r,e)}catch(t){return function(){return Function.prototype.apply.apply(r,[e,arguments])}}}function s(){console.log&&(console.log.apply?console.log.apply(console,arguments):Function.prototype.apply.apply(console.log,[console,arguments])),console.trace&&console.trace()}function o(t,r){for(var i=0;i<n.length;i++){var s=n[i];this[s]=i<t?e:this.methodFactory(s,t,r)}this.log=this.debug}function a(n,a,u){return function(n){return"debug"===n&&(n="log"),typeof console!==t&&("trace"===n&&r?s:void 0!==console[n]?i(console,n):void 0!==console.log?i(console,"log"):e)}(n)||function(e,r,n){return function(){typeof console!==t&&(o.call(this,r,n),this[e].apply(this,arguments))}}.apply(this,arguments)}function u(e,r,i){var s,u=this,c="loglevel";function l(){var e;if(typeof window!==t){try{e=window.localStorage[c]}catch(e){}if(typeof e===t)try{var r=window.document.cookie,n=r.indexOf(encodeURIComponent(c)+"=");-1!==n&&(e=/^([^;]+)/.exec(r.slice(n))[1])}catch(e){}return void 0===u.levels[e]&&(e=void 0),e}}e&&(c+=":"+e),u.name=e,u.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},u.methodFactory=i||a,u.getLevel=function(){return s},u.setLevel=function(r,i){if("string"==typeof r&&void 0!==u.levels[r.toUpperCase()]&&(r=u.levels[r.toUpperCase()]),!("number"==typeof r&&r>=0&&r<=u.levels.SILENT))throw"log.setLevel() called with invalid level: "+r;if(s=r,!1!==i&&function(e){var r=(n[e]||"silent").toUpperCase();if(typeof window!==t){try{return void(window.localStorage[c]=r)}catch(e){}try{window.document.cookie=encodeURIComponent(c)+"="+r+";"}catch(e){}}}(r),o.call(u,r,e),typeof console===t&&r<u.levels.SILENT)return"No console available for logging"},u.setDefaultLevel=function(e){l()||u.setLevel(e,!1)},u.enableAll=function(e){u.setLevel(u.levels.TRACE,e)},u.disableAll=function(e){u.setLevel(u.levels.SILENT,e)};var f=l();null==f&&(f=null==r?"WARN":r),u.setLevel(f,!1)}var c=new u,l={};c.getLogger=function(e){if("string"!=typeof e||""===e)throw new TypeError("You must supply a name when creating a logger.");var t=l[e];return t||(t=l[e]=new u(e,c.getLevel(),c.methodFactory)),t};var f=typeof window!==t?window.log:void 0;return c.noConflict=function(){return typeof window!==t&&window.log===c&&(window.log=f),c},c.getLoggers=function(){return l},c})},{}],187:[function(e,t,r){"use strict";var n=u(e("babel-runtime/core-js/object/get-prototype-of")),i=u(e("babel-runtime/helpers/classCallCheck")),s=u(e("babel-runtime/helpers/createClass")),o=u(e("babel-runtime/helpers/possibleConstructorReturn")),a=u(e("babel-runtime/helpers/inherits"));function u(e){return e&&e.__esModule?e:{default:e}}function c(e){return null!=e}Object.defineProperty(r,"__esModule",{value:!0});var l=function(e){function t(e){(0,i.default)(this,t);var r=(0,o.default)(this,(t.__proto__||(0,n.default)(t)).call(this));if(c((e=e||{}).initialDelay)&&e.initialDelay<1)throw new Error("The initial timeout must be equal to or greater than 1.");if(c(e.maxDelay)&&e.maxDelay<=1)throw new Error("The maximal timeout must be greater than 1.");if(c(e.randomisationFactor)&&(e.randomisationFactor<0||e.randomisationFactor>1))throw new Error("The randomisation factor must be between 0 and 1.");if(c(e.factor)&&e.factor<=1)throw new Error("Exponential factor should be greater than 1.");if(r.initialDelay=e.initialDelay||100,r.maxDelay=e.maxDelay||1e4,r.maxDelay<=r.initialDelay)throw new Error("The maximal backoff delay must be greater than the initial backoff delay.");return r.randomisationFactor=e.randomisationFactor||0,r.factor=e.factor||2,r.maxNumberOfRetry=-1,r.reset(),r}return(0,a.default)(t,e),(0,s.default)(t,[{key:"backoff",value:function(e){null==this.timeoutID&&(this.backoffNumber===this.maxNumberOfRetry?(this.emit("fail",e),this.reset()):(this.backoffDelay=this.next(),this.timeoutID=setTimeout(this.onBackoff.bind(this),this.backoffDelay),this.emit("backoff",this.backoffNumber,this.backoffDelay,e)))}},{key:"reset",value:function(){this.backoffDelay=0,this.nextBackoffDelay=this.initialDelay,this.backoffNumber=0,clearTimeout(this.timeoutID),this.timeoutID=null}},{key:"failAfter",value:function(e){if(e<=0)throw new Error("Expected a maximum number of retry greater than 0 but got "+e);this.maxNumberOfRetry=e}},{key:"next",value:function(){this.backoffDelay=Math.min(this.nextBackoffDelay,this.maxDelay),this.nextBackoffDelay=this.backoffDelay*this.factor;var e=1+Math.random()*this.randomisationFactor;return Math.min(this.maxDelay,Math.round(this.backoffDelay*e))}},{key:"onBackoff",value:function(){this.timeoutID=null,this.emit("ready",this.backoffNumber,this.backoffDelay),this.backoffNumber++}}],[{key:"exponential",value:function(e){return new t(e)}}]),t}(e("events").EventEmitter);r.Backoff=l,r.default=l},{"babel-runtime/core-js/object/get-prototype-of":35,"babel-runtime/helpers/classCallCheck":43,"babel-runtime/helpers/createClass":44,"babel-runtime/helpers/inherits":46,"babel-runtime/helpers/possibleConstructorReturn":47,events:184}],188:[function(e,t,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var n=e("./retrier");r.Retrier=n.Retrier;var i=e("./backoff");r.Backoff=i.Backoff,r.default=n.Retrier},{"./backoff":187,"./retrier":189}],189:[function(e,t,r){"use strict";var n=c(e("babel-runtime/core-js/promise")),i=c(e("babel-runtime/core-js/object/get-prototype-of")),s=c(e("babel-runtime/helpers/classCallCheck")),o=c(e("babel-runtime/helpers/createClass")),a=c(e("babel-runtime/helpers/possibleConstructorReturn")),u=c(e("babel-runtime/helpers/inherits"));function c(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var l=function(e){function t(e){(0,s.default)(this,t);var r=(0,a.default)(this,(t.__proto__||(0,i.default)(t)).call(this));return r.minDelay=e.min,r.maxDelay=e.max,r.initialDelay=e.initial||0,r.maxAttemptsCount=e.maxAttemptsCount||0,r.maxAttemptsTime=e.maxAttemptsTime||0,r.randomness=e.randomness||0,r.inProgress=!1,r.attemptNum=0,r.prevDelay=0,r.currDelay=0,r}return(0,u.default)(t,e),(0,o.default)(t,[{key:"attempt",value:function(){clearTimeout(this.timeout),this.attemptNum++,this.timeout=null,this.emit("attempt",this)}},{key:"nextDelay",value:function(e){if("number"==typeof e)return this.prevDelay=0,this.currDelay=e,e;if(0==this.attemptNum)return this.initialDelay;if(1==this.attemptNum)return this.currDelay=this.minDelay,this.currDelay;this.prevDelay=this.currDelay;var t=this.currDelay+this.prevDelay;return this.maxDelay&&t>this.maxDelay&&(this.currDelay=this.maxDelay,t=this.maxDelay),this.currDelay=t,t}},{key:"randomize",value:function(e){var t=e*this.randomness,r=Math.round(Math.random()*t*2-t);return Math.max(0,e+r)}},{key:"scheduleAttempt",value:function(e){var t=this;if(this.maxAttemptsCount&&this.attemptNum>=this.maxAttemptsCount)return this.cleanup(),this.emit("failed",new Error("Maximum attempt count limit reached")),void this.reject(new Error("Maximum attempt count reached"));var r=this.nextDelay(e);if(r=this.randomize(r),this.maxAttemptsTime&&this.startTimestamp+this.maxAttemptsTime<Date.now()+r)return this.cleanup(),this.emit("failed",new Error("Maximum attempt time limit reached")),void this.reject(new Error("Maximum attempt time limit reached"));this.timeout=setTimeout(function(){return t.attempt()},r)}},{key:"cleanup",value:function(){clearTimeout(this.timeout),this.timeout=null,this.inProgress=!1,this.attemptNum=0,this.prevDelay=0,this.currDelay=0}},{key:"start",value:function(){var e=this;if(this.inProgress)throw new Error("Retrier is already in progress");return this.inProgress=!0,new n.default(function(t,r){e.resolve=t,e.reject=r,e.startTimestamp=Date.now(),e.scheduleAttempt(e.initialDelay)})}},{key:"cancel",value:function(){this.timeout&&(clearTimeout(this.timeout),this.timeout=null,this.inProgress=!1,this.emit("cancelled"),this.reject(new Error("Cancelled")))}},{key:"succeeded",value:function(e){this.emit("succeeded",e),this.resolve(e)}},{key:"failed",value:function(e,t){if(this.timeout)throw new Error("Retrier attempt is already in progress");this.scheduleAttempt(t)}},{key:"run",value:function(e){var t=this;return this.on("attempt",function(){e().then(function(e){return t.succeeded(e)}).catch(function(e){return t.failed(e)})}),this.start()}}]),t}(e("events").EventEmitter);r.Retrier=l,r.default=l},{"babel-runtime/core-js/object/get-prototype-of":35,"babel-runtime/core-js/promise":37,"babel-runtime/helpers/classCallCheck":43,"babel-runtime/helpers/createClass":44,"babel-runtime/helpers/inherits":46,"babel-runtime/helpers/possibleConstructorReturn":47,events:184}],190:[function(e,t,r){(function(e){(function(){"use strict";var n={function:!0,object:!0},i=n[typeof window]&&window||this,s=n[typeof r]&&r,o=n[typeof t]&&t&&!t.nodeType&&t,a=s&&o&&"object"==typeof e&&e;!a||a.global!==a&&a.window!==a&&a.self!==a||(i=a);var u=Math.pow(2,53)-1,c=/\bOpera/,l=Object.prototype,f=l.hasOwnProperty,d=l.toString;function p(e){return(e=String(e)).charAt(0).toUpperCase()+e.slice(1)}function h(e){return e=g(e),/^(?:webOS|i(?:OS|P))/.test(e)?e:p(e)}function b(e,t){for(var r in e)f.call(e,r)&&t(e[r],r,e)}function v(e){return null==e?p(e):d.call(e).slice(8,-1)}function m(e){return String(e).replace(/([ -])(?!$)/g,"$1?")}function y(e,t){var r=null;return function(e,t){var r=-1,n=e?e.length:0;if("number"==typeof n&&n>-1&&n<=u)for(;++r<n;)t(e[r],r,e);else b(e,t)}(e,function(n,i){r=t(r,n,i,e)}),r}function g(e){return String(e).replace(/^ +| +$/g,"")}var _=function e(t){var r=i,n=t&&"object"==typeof t&&"String"!=v(t);n&&(r=t,t=null);var s=r.navigator||{},o=s.userAgent||"";t||(t=o);var a,u,l,f,p,_=n?!!s.likeChrome:/\bChrome\b/.test(t)&&!/internal|\n/i.test(d.toString()),k=n?"Object":"ScriptBridgingProxyObject",w=n?"Object":"Environment",x=n&&r.java?"JavaPackage":v(r.java),j=n?"Object":"RuntimeObject",C=/\bJava/.test(x)&&r.java,S=C&&v(r.environment)==w,T=C?"a":"\u03b1",E=C?"b":"\u03b2",I=r.document||{},M=r.operamini||r.opera,R=c.test(R=n&&M?M["[[Class]]"]:v(M))?R:M=null,O=t,P=[],L=null,N=t==o,A=N&&M&&"function"==typeof M.version&&M.version(),F=y([{label:"EdgeHTML",pattern:"Edge"},"Trident",{label:"WebKit",pattern:"AppleWebKit"},"iCab","Presto","NetFront","Tasman","KHTML","Gecko"],function(e,r){return e||RegExp("\\b"+(r.pattern||m(r))+"\\b","i").exec(t)&&(r.label||r)}),D=function(e){return y(e,function(e,r){return e||RegExp("\\b"+(r.pattern||m(r))+"\\b","i").exec(t)&&(r.label||r)})}(["Adobe AIR","Arora","Avant Browser","Breach","Camino","Electron","Epiphany","Fennec","Flock","Galeon","GreenBrowser","iCab","Iceweasel","K-Meleon","Konqueror","Lunascape","Maxthon",{label:"Microsoft Edge",pattern:"Edge"},"Midori","Nook Browser","PaleMoon","PhantomJS","Raven","Rekonq","RockMelt",{label:"Samsung Internet",pattern:"SamsungBrowser"},"SeaMonkey",{label:"Silk",pattern:"(?:Cloud9|Silk-Accelerated)"},"Sleipnir","SlimBrowser",{label:"SRWare Iron",pattern:"Iron"},"Sunrise","Swiftfox","Waterfox","WebPositive","Opera Mini",{label:"Opera Mini",pattern:"OPiOS"},"Opera",{label:"Opera",pattern:"OPR"},"Chrome",{label:"Chrome Mobile",pattern:"(?:CriOS|CrMo)"},{label:"Firefox",pattern:"(?:Firefox|Minefield)"},{label:"Firefox for iOS",pattern:"FxiOS"},{label:"IE",pattern:"IEMobile"},{label:"IE",pattern:"MSIE"},"Safari"]),q=W([{label:"BlackBerry",pattern:"BB10"},"BlackBerry",{label:"Galaxy S",pattern:"GT-I9000"},{label:"Galaxy S2",pattern:"GT-I9100"},{label:"Galaxy S3",pattern:"GT-I9300"},{label:"Galaxy S4",pattern:"GT-I9500"},{label:"Galaxy S5",pattern:"SM-G900"},{label:"Galaxy S6",pattern:"SM-G920"},{label:"Galaxy S6 Edge",pattern:"SM-G925"},{label:"Galaxy S7",pattern:"SM-G930"},{label:"Galaxy S7 Edge",pattern:"SM-G935"},"Google TV","Lumia","iPad","iPod","iPhone","Kindle",{label:"Kindle Fire",pattern:"(?:Cloud9|Silk-Accelerated)"},"Nexus","Nook","PlayBook","PlayStation Vita","PlayStation","TouchPad","Transformer",{label:"Wii U",pattern:"WiiU"},"Wii","Xbox One",{label:"Xbox 360",pattern:"Xbox"},"Xoom"]),U=function(e){return y(e,function(e,r,n){return e||(r[q]||r[/^[a-z]+(?: +[a-z]+\b)*/i.exec(q)]||RegExp("\\b"+m(n)+"(?:\\b|\\w*\\d)","i").exec(t))&&n})}({Apple:{iPad:1,iPhone:1,iPod:1},Archos:{},Amazon:{Kindle:1,"Kindle Fire":1},Asus:{Transformer:1},"Barnes & Noble":{Nook:1},BlackBerry:{PlayBook:1},Google:{"Google TV":1,Nexus:1},HP:{TouchPad:1},HTC:{},LG:{},Microsoft:{Xbox:1,"Xbox One":1},Motorola:{Xoom:1},Nintendo:{"Wii U":1,Wii:1},Nokia:{Lumia:1},Samsung:{"Galaxy S":1,"Galaxy S2":1,"Galaxy S3":1,"Galaxy S4":1},Sony:{PlayStation:1,"PlayStation Vita":1}}),B=function(e){return y(e,function(e,r){var n=r.pattern||m(r);return!e&&(e=RegExp("\\b"+n+"(?:/[\\d.]+|[ \\w.]*)","i").exec(t))&&(e=function(e,t,r){var n={"10.0":"10",6.4:"10 Technical Preview",6.3:"8.1",6.2:"8",6.1:"Server 2008 R2 / 7","6.0":"Server 2008 / Vista",5.2:"Server 2003 / XP 64-bit",5.1:"XP",5.01:"2000 SP1","5.0":"2000","4.0":"NT","4.90":"ME"};return t&&r&&/^Win/i.test(e)&&!/^Windows Phone /i.test(e)&&(n=n[/[\d.]+$/.exec(e)])&&(e="Windows "+n),e=String(e),t&&r&&(e=e.replace(RegExp(t,"i"),r)),e=h(e.replace(/ ce$/i," CE").replace(/\bhpw/i,"web").replace(/\bMacintosh\b/,"Mac OS").replace(/_PowerPC\b/i," OS").replace(/\b(OS X) [^ \d]+/i,"$1").replace(/\bMac (OS X)\b/,"$1").replace(/\/(\d)/," $1").replace(/_/g,".").replace(/(?: BePC|[ .]*fc[ \d.]+)$/i,"").replace(/\bx86\.64\b/gi,"x86_64").replace(/\b(Windows Phone) OS\b/,"$1").replace(/\b(Chrome OS \w+) [\d.]+\b/,"$1").split(" on ")[0])}(e,n,r.label||r)),e})}(["Windows Phone","Android","CentOS",{label:"Chrome OS",pattern:"CrOS"},"Debian","Fedora","FreeBSD","Gentoo","Haiku","Kubuntu","Linux Mint","OpenBSD","Red Hat","SuSE","Ubuntu","Xubuntu","Cygwin","Symbian OS","hpwOS","webOS ","webOS","Tablet OS","Tizen","Linux","Mac OS X","Macintosh","Mac","Windows 98;","Windows "]);function W(e){return y(e,function(e,r){var n=r.pattern||m(r);return!e&&(e=RegExp("\\b"+n+" *\\d+[.\\w_]*","i").exec(t)||RegExp("\\b"+n+" *\\w+-[\\w]*","i").exec(t)||RegExp("\\b"+n+"(?:; *(?:[a-z]+[_-])?[a-z]+\\d+|[^ ();-]*)","i").exec(t))&&((e=String(r.label&&!RegExp(n,"i").test(r.label)?r.label:e).split("/"))[1]&&!/[\d.]+/.test(e[0])&&(e[0]+=" "+e[1]),r=r.label||r,e=h(e[0].replace(RegExp(n,"i"),r).replace(RegExp("; *(?:"+r+"[_-])?","i")," ").replace(RegExp("("+r+")[-_.]?(\\w)","i"),"$1 $2"))),e})}if(F&&(F=[F]),U&&!q&&(q=W([U])),(a=/\bGoogle TV\b/.exec(q))&&(q=a[0]),/\bSimulator\b/i.test(t)&&(q=(q?q+" ":"")+"Simulator"),"Opera Mini"==D&&/\bOPiOS\b/.test(t)&&P.push("running in Turbo/Uncompressed mode"),"IE"==D&&/\blike iPhone OS\b/.test(t)?(U=(a=e(t.replace(/like iPhone OS/,""))).manufacturer,q=a.product):/^iP/.test(q)?(D||(D="Safari"),B="iOS"+((a=/ OS ([\d_]+)/i.exec(t))?" "+a[1].replace(/_/g,"."):"")):"Konqueror"!=D||/buntu/i.test(B)?U&&"Google"!=U&&(/Chrome/.test(D)&&!/\bMobile Safari\b/i.test(t)||/\bVita\b/.test(q))||/\bAndroid\b/.test(B)&&/^Chrome/.test(D)&&/\bVersion\//i.test(t)?(D="Android Browser",B=/\bAndroid\b/.test(B)?B:"Android"):"Silk"==D?(/\bMobi/i.test(t)||(B="Android",P.unshift("desktop mode")),/Accelerated *= *true/i.test(t)&&P.unshift("accelerated")):"PaleMoon"==D&&(a=/\bFirefox\/([\d.]+)\b/.exec(t))?P.push("identifying as Firefox "+a[1]):"Firefox"==D&&(a=/\b(Mobile|Tablet|TV)\b/i.exec(t))?(B||(B="Firefox OS"),q||(q=a[1])):!D||(a=!/\bMinefield\b/i.test(t)&&/\b(?:Firefox|Safari)\b/.exec(D))?(D&&!q&&/[\/,]|^[^(]+?\)/.test(t.slice(t.indexOf(a+"/")+8))&&(D=null),(a=q||U||B)&&(q||U||/\b(?:Android|Symbian OS|Tablet OS|webOS)\b/.test(B))&&(D=/[a-z]+(?: Hat)?/i.exec(/\bAndroid\b/.test(B)?B:a)+" Browser")):"Electron"==D&&(a=(/\bChrome\/([\d.]+)\b/.exec(t)||0)[1])&&P.push("Chromium "+a):B="Kubuntu",A||(A=y(["(?:Cloud9|CriOS|CrMo|Edge|FxiOS|IEMobile|Iron|Opera ?Mini|OPiOS|OPR|Raven|SamsungBrowser|Silk(?!/[\\d.]+$))","Version",m(D),"(?:Firefox|Minefield|NetFront)"],function(e,r){return e||(RegExp(r+"(?:-[\\d.]+/|(?: for [\\w-]+)?[ /-])([\\d.]+[^ ();/_-]*)","i").exec(t)||0)[1]||null})),(a=("iCab"==F&&parseFloat(A)>3?"WebKit":/\bOpera\b/.test(D)&&(/\bOPR\b/.test(t)?"Blink":"Presto"))||/\b(?:Midori|Nook|Safari)\b/i.test(t)&&!/^(?:Trident|EdgeHTML)$/.test(F)&&"WebKit"||!F&&/\bMSIE\b/i.test(t)&&("Mac OS"==B?"Tasman":"Trident")||"WebKit"==F&&/\bPlayStation\b(?! Vita\b)/i.test(D)&&"NetFront")&&(F=[a]),"IE"==D&&(a=(/; *(?:XBLWP|ZuneWP)(\d+)/i.exec(t)||0)[1])?(D+=" Mobile",B="Windows Phone "+(/\+$/.test(a)?a:a+".x"),P.unshift("desktop mode")):/\bWPDesktop\b/i.test(t)?(D="IE Mobile",B="Windows Phone 8.x",P.unshift("desktop mode"),A||(A=(/\brv:([\d.]+)/.exec(t)||0)[1])):"IE"!=D&&"Trident"==F&&(a=/\brv:([\d.]+)/.exec(t))&&(D&&P.push("identifying as "+D+(A?" "+A:"")),D="IE",A=a[1]),N){if(f="global",p=null!=(l=r)?typeof l[f]:"number",/^(?:boolean|number|string|undefined)$/.test(p)||"object"==p&&!l[f])v(a=r.runtime)==k?(D="Adobe AIR",B=a.flash.system.Capabilities.os):v(a=r.phantom)==j?(D="PhantomJS",A=(a=a.version||null)&&a.major+"."+a.minor+"."+a.patch):"number"==typeof I.documentMode&&(a=/\bTrident\/(\d+)/i.exec(t))?(A=[A,I.documentMode],(a=+a[1]+4)!=A[1]&&(P.push("IE "+A[1]+" mode"),F&&(F[1]=""),A[1]=a),A="IE"==D?String(A[1].toFixed(1)):A[0]):"number"==typeof I.documentMode&&/^(?:Chrome|Firefox)\b/.test(D)&&(P.push("masking as "+D+" "+A),D="IE",A="11.0",F=["Trident"],B="Windows");else if(C&&(O=(a=C.lang.System).getProperty("os.arch"),B=B||a.getProperty("os.name")+" "+a.getProperty("os.version")),S){try{A=r.require("ringo/engine").version.join("."),D="RingoJS"}catch(e){(a=r.system)&&a.global.system==r.system&&(D="Narwhal",B||(B=a[0].os||null))}D||(D="Rhino")}else"object"==typeof r.process&&!r.process.browser&&(a=r.process)&&("object"==typeof a.versions&&("string"==typeof a.versions.electron?(P.push("Node "+a.versions.node),D="Electron",A=a.versions.electron):"string"==typeof a.versions.nw&&(P.push("Chromium "+A,"Node "+a.versions.node),D="NW.js",A=a.versions.nw)),D||(D="Node.js",O=a.arch,B=a.platform,A=(A=/[\d.]+/.exec(a.version))?A[0]:null));B=B&&h(B)}if(A&&(a=/(?:[ab]|dp|pre|[ab]\d+pre)(?:\d+\+?)?$/i.exec(A)||/(?:alpha|beta)(?: ?\d)?/i.exec(t+";"+(N&&s.appMinorVersion))||/\bMinefield\b/i.test(t)&&"a")&&(L=/b/i.test(a)?"beta":"alpha",A=A.replace(RegExp(a+"\\+?$"),"")+("beta"==L?E:T)+(/\d+\+?/.exec(a)||"")),"Fennec"==D||"Firefox"==D&&/\b(?:Android|Firefox OS)\b/.test(B))D="Firefox Mobile";else if("Maxthon"==D&&A)A=A.replace(/\.[\d.]+/,".x");else if(/\bXbox\b/i.test(q))"Xbox 360"==q&&(B=null),"Xbox 360"==q&&/\bIEMobile\b/.test(t)&&P.unshift("mobile mode");else if(!/^(?:Chrome|IE|Opera)$/.test(D)&&(!D||q||/Browser|Mobi/.test(D))||"Windows CE"!=B&&!/Mobi/i.test(t))if("IE"==D&&N)try{null===r.external&&P.unshift("platform preview")}catch(e){P.unshift("embedded")}else(/\bBlackBerry\b/.test(q)||/\bBB10\b/.test(t))&&(a=(RegExp(q.replace(/ +/g," *")+"/([.\\d]+)","i").exec(t)||0)[1]||A)?(B=((a=[a,/BB10/.test(t)])[1]?(q=null,U="BlackBerry"):"Device Software")+" "+a[0],A=null):this!=b&&"Wii"!=q&&(N&&M||/Opera/.test(D)&&/\b(?:MSIE|Firefox)\b/i.test(t)||"Firefox"==D&&/\bOS X (?:\d+\.){2,}/.test(B)||"IE"==D&&(B&&!/^Win/.test(B)&&A>5.5||/\bWindows XP\b/.test(B)&&A>8||8==A&&!/\bTrident\b/.test(t)))&&!c.test(a=e.call(b,t.replace(c,"")+";"))&&a.name&&(a="ing as "+a.name+((a=a.version)?" "+a:""),c.test(D)?(/\bIE\b/.test(a)&&"Mac OS"==B&&(B=null),a="identify"+a):(a="mask"+a,D=R?h(R.replace(/([a-z])([A-Z])/g,"$1 $2")):"Opera",/\bIE\b/.test(a)&&(B=null),N||(A=null)),F=["Presto"],P.push(a));else D+=" Mobile";(a=(/\bAppleWebKit\/([\d.]+\+?)/i.exec(t)||0)[1])&&(a=[parseFloat(a.replace(/\.(\d)$/,".0$1")),a],"Safari"==D&&"+"==a[1].slice(-1)?(D="WebKit Nightly",L="alpha",A=a[1].slice(0,-1)):A!=a[1]&&A!=(a[2]=(/\bSafari\/([\d.]+\+?)/i.exec(t)||0)[1])||(A=null),a[1]=(/\bChrome\/([\d.]+)/i.exec(t)||0)[1],537.36==a[0]&&537.36==a[2]&&parseFloat(a[1])>=28&&"WebKit"==F&&(F=["Blink"]),N&&(_||a[1])?(F&&(F[1]="like Chrome"),a=a[1]||((a=a[0])<530?1:a<532?2:a<532.05?3:a<533?4:a<534.03?5:a<534.07?6:a<534.1?7:a<534.13?8:a<534.16?9:a<534.24?10:a<534.3?11:a<535.01?12:a<535.02?"13+":a<535.07?15:a<535.11?16:a<535.19?17:a<536.05?18:a<536.1?19:a<537.01?20:a<537.11?"21+":a<537.13?23:a<537.18?24:a<537.24?25:a<537.36?26:"Blink"!=F?"27":"28")):(F&&(F[1]="like Safari"),a=(a=a[0])<400?1:a<500?2:a<526?3:a<533?4:a<534?"4+":a<535?5:a<537?6:a<538?7:a<601?8:"8"),F&&(F[1]+=" "+(a+="number"==typeof a?".x":/[.+]/.test(a)?"":"+")),"Safari"==D&&(!A||parseInt(A)>45)&&(A=a)),"Opera"==D&&(a=/\bzbov|zvav$/.exec(B))?(D+=" ",P.unshift("desktop mode"),"zvav"==a?(D+="Mini",A=null):D+="Mobile",B=B.replace(RegExp(" *"+a+"$"),"")):"Safari"==D&&/\bChrome\b/.exec(F&&F[1])&&(P.unshift("desktop mode"),D="Chrome Mobile",A=null,/\bOS X\b/.test(B)?(U="Apple",B="iOS 4.3+"):B=null),A&&0==A.indexOf(a=/[\d.]+$/.exec(B))&&t.indexOf("/"+a+"-")>-1&&(B=g(B.replace(a,""))),F&&!/\b(?:Avant|Nook)\b/.test(D)&&(/Browser|Lunascape|Maxthon/.test(D)||"Safari"!=D&&/^iOS/.test(B)&&/\bSafari\b/.test(F[1])||/^(?:Adobe|Arora|Breach|Midori|Opera|Phantom|Rekonq|Rock|Samsung Internet|Sleipnir|Web)/.test(D)&&F[1])&&(a=F[F.length-1])&&P.push(a),P.length&&(P=["("+P.join("; ")+")"]),U&&q&&q.indexOf(U)<0&&P.push("on "+U),q&&P.push((/^on /.test(P[P.length-1])?"":"on ")+q),B&&(a=/ ([\d.+]+)$/.exec(B),u=a&&"/"==B.charAt(B.length-a[0].length-1),B={architecture:32,family:a&&!u?B.replace(a[0],""):B,version:a?a[1]:null,toString:function(){var e=this.version;return this.family+(e&&!u?" "+e:"")+(64==this.architecture?" 64-bit":"")}}),(a=/\b(?:AMD|IA|Win|WOW|x86_|x)64\b/i.exec(O))&&!/\bi686\b/i.test(O)?(B&&(B.architecture=64,B.family=B.family.replace(RegExp(" *"+a),"")),D&&(/\bWOW64\b/i.test(t)||N&&/\w(?:86|32)$/.test(s.cpuClass||s.platform)&&!/\bWin64; x64\b/i.test(t))&&P.unshift("32-bit")):B&&/^OS X/.test(B.family)&&"Chrome"==D&&parseFloat(A)>=39&&(B.architecture=64),t||(t=null);var G={};return G.description=t,G.layout=F&&F[0],G.manufacturer=U,G.name=D,G.prerelease=L,G.product=q,G.ua=t,G.version=D&&A,G.os=B||{architecture:null,family:null,version:null,toString:function(){return"null"}},G.parse=e,G.toString=function(){return this.description||""},G.version&&P.unshift(A),G.name&&P.unshift(D),B&&D&&(B!=String(B).split(" ")[0]||B!=D.split(" ")[0]&&!q)&&P.push(q?"("+B+")":"on "+B),P.length&&(G.description=P.join(" ")),G}();s&&o?b(_,function(e,t){s[t]=e}):i.platform=_}).call(this)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],191:[function(e,t,r){
/**
 * Copyright (c) 2014-present, Facebook, Inc.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */
var n=function(){return this}()||Function("return this")(),i=n.regeneratorRuntime&&Object.getOwnPropertyNames(n).indexOf("regeneratorRuntime")>=0,s=i&&n.regeneratorRuntime;if(n.regeneratorRuntime=void 0,t.exports=e("./runtime"),i)n.regeneratorRuntime=s;else try{delete n.regeneratorRuntime}catch(e){n.regeneratorRuntime=void 0}},{"./runtime":192}],192:[function(e,t,r){
/**
 * Copyright (c) 2014-present, Facebook, Inc.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */
!function(e){"use strict";var r,n=Object.prototype,i=n.hasOwnProperty,s="function"==typeof Symbol?Symbol:{},o=s.iterator||"@@iterator",a=s.asyncIterator||"@@asyncIterator",u=s.toStringTag||"@@toStringTag",c="object"==typeof t,l=e.regeneratorRuntime;if(l)c&&(t.exports=l);else{(l=e.regeneratorRuntime=c?t.exports:{}).wrap=_;var f="suspendedStart",d="suspendedYield",p="executing",h="completed",b={},v={};v[o]=function(){return this};var m=Object.getPrototypeOf,y=m&&m(m(R([])));y&&y!==n&&i.call(y,o)&&(v=y);var g=j.prototype=w.prototype=Object.create(v);x.prototype=g.constructor=j,j.constructor=x,j[u]=x.displayName="GeneratorFunction",l.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===x||"GeneratorFunction"===(t.displayName||t.name))},l.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,j):(e.__proto__=j,u in e||(e[u]="GeneratorFunction")),e.prototype=Object.create(g),e},l.awrap=function(e){return{__await:e}},C(S.prototype),S.prototype[a]=function(){return this},l.AsyncIterator=S,l.async=function(e,t,r,n){var i=new S(_(e,t,r,n));return l.isGeneratorFunction(t)?i:i.next().then(function(e){return e.done?e.value:i.next()})},C(g),g[u]="Generator",g[o]=function(){return this},g.toString=function(){return"[object Generator]"},l.keys=function(e){var t=[];for(var r in e)t.push(r);return t.reverse(),function r(){for(;t.length;){var n=t.pop();if(n in e)return r.value=n,r.done=!1,r}return r.done=!0,r}},l.values=R,M.prototype={constructor:M,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=r,this.done=!1,this.delegate=null,this.method="next",this.arg=r,this.tryEntries.forEach(I),!e)for(var t in this)"t"===t.charAt(0)&&i.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=r)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function n(n,i){return a.type="throw",a.arg=e,t.next=n,i&&(t.method="next",t.arg=r),!!i}for(var s=this.tryEntries.length-1;s>=0;--s){var o=this.tryEntries[s],a=o.completion;if("root"===o.tryLoc)return n("end");if(o.tryLoc<=this.prev){var u=i.call(o,"catchLoc"),c=i.call(o,"finallyLoc");if(u&&c){if(this.prev<o.catchLoc)return n(o.catchLoc,!0);if(this.prev<o.finallyLoc)return n(o.finallyLoc)}else if(u){if(this.prev<o.catchLoc)return n(o.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return n(o.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var n=this.tryEntries[r];if(n.tryLoc<=this.prev&&i.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var s=n;break}}s&&("break"===e||"continue"===e)&&s.tryLoc<=t&&t<=s.finallyLoc&&(s=null);var o=s?s.completion:{};return o.type=e,o.arg=t,s?(this.method="next",this.next=s.finallyLoc,b):this.complete(o)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),b},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),I(r),b}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var i=n.arg;I(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:R(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=r),b}}}function _(e,t,r,n){var i=t&&t.prototype instanceof w?t:w,s=Object.create(i.prototype),o=new M(n||[]);return s._invoke=function(e,t,r){var n=f;return function(i,s){if(n===p)throw new Error("Generator is already running");if(n===h){if("throw"===i)throw s;return O()}for(r.method=i,r.arg=s;;){var o=r.delegate;if(o){var a=T(o,r);if(a){if(a===b)continue;return a}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(n===f)throw n=h,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n=p;var u=k(e,t,r);if("normal"===u.type){if(n=r.done?h:d,u.arg===b)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n=h,r.method="throw",r.arg=u.arg)}}}(e,r,o),s}function k(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}function w(){}function x(){}function j(){}function C(e){["next","throw","return"].forEach(function(t){e[t]=function(e){return this._invoke(t,e)}})}function S(e){var t;this._invoke=function(r,n){function s(){return new Promise(function(t,s){!function t(r,n,s,o){var a=k(e[r],e,n);if("throw"!==a.type){var u=a.arg,c=u.value;return c&&"object"==typeof c&&i.call(c,"__await")?Promise.resolve(c.__await).then(function(e){t("next",e,s,o)},function(e){t("throw",e,s,o)}):Promise.resolve(c).then(function(e){u.value=e,s(u)},o)}o(a.arg)}(r,n,t,s)})}return t=t?t.then(s,s):s()}}function T(e,t){var n=e.iterator[t.method];if(n===r){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=r,T(e,t),"throw"===t.method))return b;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return b}var i=k(n,e.iterator,t.arg);if("throw"===i.type)return t.method="throw",t.arg=i.arg,t.delegate=null,b;var s=i.arg;return s?s.done?(t[e.resultName]=s.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=r),t.delegate=null,b):s:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,b)}function E(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function I(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function M(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(E,this),this.reset(!0)}function R(e){if(e){var t=e[o];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,s=function t(){for(;++n<e.length;)if(i.call(e,n))return t.value=e[n],t.done=!1,t;return t.value=r,t.done=!0,t};return s.next=s}}return{next:O}}function O(){return{value:r,done:!0}}}(function(){return this}()||Function("return this")())},{}],193:[function(e,t,r){"use strict";var n=l(e("babel-runtime/regenerator")),i=l(e("babel-runtime/helpers/asyncToGenerator")),s=l(e("babel-runtime/core-js/object/get-prototype-of")),o=l(e("babel-runtime/helpers/classCallCheck")),a=l(e("babel-runtime/helpers/createClass")),u=l(e("babel-runtime/helpers/possibleConstructorReturn")),c=l(e("babel-runtime/helpers/inherits"));function l(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var f=e("events"),d=e("twilsock"),p=e("./configuration"),h=e("./registrar"),b=e("./logger"),v=function(e){function t(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};(0,o.default)(this,t);var n=(0,u.default)(this,(t.__proto__||(0,s.default)(t)).call(this));if(!e||0===e.length)throw new Error("Token is required for Notifications client");r.logLevel=r.logLevel||"error",b.log.setLevel(r.logLevel);r.minTokenRefreshInterval;var i=r.productId||"notifications";return r.twilsockClient=r.twilsockClient||new d.TwilsockClient(e,i,r),r.transport=r.transport||r.twilsockClient,n.services={twilsock:r.twilsockClient,transport:r.transport,config:new p.Configuration(null,r)},n.registrar=new h.Registrar(i,n.services.transport,n.services.twilsock,n.services.config),n.reliableTransportState={overall:!1,transport:!1,registration:!1,lastEmitted:null},n._onTransportStateChange(n.services.twilsock.isConnected),n.registrar.on("transportReady",function(e){n._onRegistrationStateChange(e?"registered":"")}),n.registrar.on("stateChanged",function(e){n._onRegistrationStateChange(e)}),n.registrar.on("needReliableTransport",n._onNeedReliableTransport.bind(n)),n.services.twilsock.on("message",function(e,t){return n._routeMessage(e,t)}),n.services.twilsock.on("connected",function(e){n._onTransportStateChange(!0),n.registrar.setNotificationId("twilsock",e)}),n.services.twilsock.on("disconnected",function(){n._onTransportStateChange(!1)}),n.services.config.updateToken(e),n.registrar.updateToken(e),n}return(0,c.default)(t,e),(0,a.default)(t,[{key:"_routeMessage",value:function(e,t){b.log.trace("Message arrived: ",e,t),this.emit("message",e,t)}},{key:"_onNeedReliableTransport",value:function(e){e?this.services.twilsock.connect():this.services.twilsock.disconnect()}},{key:"_onRegistrationStateChange",value:function(e){this.reliableTransportState.registration="registered"===e,this._updateTransportState()}},{key:"_onTransportStateChange",value:function(e){this.reliableTransportState.transport=e,this._updateTransportState()}},{key:"_updateTransportState",value:function(){var e=this.reliableTransportState.transport&&this.reliableTransportState.registration;this.reliableTransportState.overall!==e&&(this.reliableTransportState.overall=e,b.log.info("Transport ready:",e),this.emit("transportReady",e)),this.reliableTransportState.lastEmitted!==this.connectionState&&(this.reliableTransportState.lastEmitted=this.connectionState,this.emit("connectionStateChanged",this.connectionState))}},{key:"subscribe",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"twilsock";return b.log.trace("Add subscriptions for message type: ",e,t),this.registrar.subscribe(e,t)}},{key:"unsubscribe",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"twilsock";return b.log.trace("Remove subscriptions for message type: ",e,t),this.registrar.unsubscribe(e,t)}},{key:"handlePushNotification",value:function(e){return{messageType:e.twi_message_type,payload:e.payload}}},{key:"setPushRegistrationId",value:function(e,t){b.log.trace("Set push registration id",e,t),this.registrar.setNotificationId(t,e)}},{key:"updateToken",value:function(){var e=(0,i.default)(n.default.mark(function e(t){return n.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(b.log.info("authTokenUpdated"),this.services.config.token!==t){e.next=3;break}return e.abrupt("return");case 3:return e.next=5,this.services.twilsock.updateToken(t);case 5:this.services.config.updateToken(t),this.registrar.updateToken(t);case 7:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"connectionState",get:function(){return"disconnected"===this.services.twilsock.state?"disconnected":"disconnecting"===this.services.twilsock.state?"disconnecting":"connected"===this.services.twilsock.state&&this.reliableTransportState.registration?"connected":"rejected"===this.services.twilsock.state?"denied":"connecting"}}]),t}(f.EventEmitter);r.Client=v},{"./configuration":194,"./logger":197,"./registrar":199,"babel-runtime/core-js/object/get-prototype-of":35,"babel-runtime/helpers/asyncToGenerator":42,"babel-runtime/helpers/classCallCheck":43,"babel-runtime/helpers/createClass":44,"babel-runtime/helpers/inherits":46,"babel-runtime/helpers/possibleConstructorReturn":47,"babel-runtime/regenerator":51,events:184,twilsock:209}],194:[function(e,t,r){"use strict";var n=s(e("babel-runtime/helpers/classCallCheck")),i=s(e("babel-runtime/helpers/createClass"));function s(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var o=function(){function e(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};(0,n.default)(this,e);var i=r.notifications||{},s="https://ers."+(i.region||r.region||"us1")+".twilio.com/v1/registrations";this.registrarUrl=i.ersUrl||s,this._token=t}return(0,i.default)(e,[{key:"updateToken",value:function(e){this._token=e}},{key:"token",get:function(){return this._token}}]),e}();r.Configuration=o},{"babel-runtime/helpers/classCallCheck":43,"babel-runtime/helpers/createClass":44}],195:[function(e,t,r){"use strict";var n=p(e("babel-runtime/helpers/slicedToArray")),i=p(e("babel-runtime/regenerator")),s=p(e("babel-runtime/helpers/asyncToGenerator")),o=p(e("babel-runtime/core-js/object/get-prototype-of")),a=p(e("babel-runtime/helpers/possibleConstructorReturn")),u=p(e("babel-runtime/helpers/inherits")),c=p(e("babel-runtime/helpers/toConsumableArray")),l=p(e("babel-runtime/core-js/set")),f=p(e("babel-runtime/helpers/classCallCheck")),d=p(e("babel-runtime/helpers/createClass"));function p(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var h=e("events"),b=e("./logger"),v=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:new l.default;(0,f.default)(this,e),this.token=t,this.notificationId=r,this.messageTypes=n}return(0,d.default)(e,[{key:"clone",value:function(){return new e(this.token,this.notificationId,new l.default(this.messageTypes))}}]),e}();function m(e,t){var r=new l.default;return e.notificationId!==t.notificationId&&r.add("notificationId"),e.token!==t.token&&r.add("token"),function(e,t){return[].concat((0,c.default)([].concat((0,c.default)(e)).filter(function(e){return!t.has(e)})),(0,c.default)([].concat((0,c.default)(t)).filter(function(t){return!e.has(t)})))}(e.messageTypes,t.messageTypes).length>0&&r.add("messageType"),[r.size>0,r]}r.RegistrationState=v;var y=function(e){function t(e){(0,f.default)(this,t);var r=(0,a.default)(this,(t.__proto__||(0,o.default)(t)).call(this));return r.config=e,r.desiredState=new v,r.currentState=new v,r.hasActiveAttempt=!1,r}return(0,u.default)(t,e),(0,d.default)(t,[{key:"subscribe",value:function(){var e=(0,s.default)(i.default.mark(function e(t){return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.desiredState.messageTypes.has(t)){e.next=3;break}return b.log.debug("message type already registered ",t),e.abrupt("return");case 3:return this.desiredState.messageTypes.add(t),e.next=6,this.persistRegistration();case 6:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"unsubscribe",value:function(){var e=(0,s.default)(i.default.mark(function e(t){return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(this.desiredState.messageTypes.has(t)){e.next=2;break}return e.abrupt("return");case 2:return this.desiredState.messageTypes.delete(t),e.next=5,this.persistRegistration();case 5:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"updateToken",value:function(e){this.desiredState.token=e,this.persistRegistration()}},{key:"persistRegistration",value:function(){var e=(0,s.default)(i.default.mark(function e(){var t,r,s,o,a,u,c=this;return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(this.config.token&&0!==this.config.token.length){e.next=3;break}return b.log.trace("Can't persist registration: token is not set"),e.abrupt("return");case 3:if(!this.hasActiveAttempt){e.next=6;break}return b.log.trace("One registration attempt is already in progress"),e.abrupt("return");case 6:if(t=m(this.desiredState,this.currentState),r=(0,n.default)(t,2),s=r[0],o=r[1],s){e.next=9;break}return e.abrupt("return");case 9:if(this.currentState.notificationId||o.delete("notificationId"),b.log.trace("Persisting registration",o,this.desiredState),e.prev=11,this.hasActiveAttempt=!0,!((a=this.desiredState.clone()).messageTypes.size>0)){e.next=24;break}return e.next=17,this.updateRegistration(a,o);case 17:u=e.sent,this.currentState.token=u.token,this.currentState.notificationId=u.notificationId,this.currentState.messageTypes=u.messageTypes,this.emit("stateChanged","registered"),e.next=30;break;case 24:return e.next=26,this.removeRegistration();case 26:this.currentState.token=a.token,this.currentState.notificationId=a.notificationId,this.currentState.messageTypes.clear(),this.emit("stateChanged","unregistered");case 30:return e.prev=30,this.hasActiveAttempt=!1,setTimeout(function(){return c.persistRegistration()},0),e.finish(30);case 34:case"end":return e.stop()}},e,this,[[11,,30,34]])}));return function(){return e.apply(this,arguments)}}()},{key:"setNotificationId",value:function(e){this.desiredState.notificationId=e,this.persistRegistration()}}]),t}(h.EventEmitter);r.Connector=y},{"./logger":197,"babel-runtime/core-js/object/get-prototype-of":35,"babel-runtime/core-js/set":39,"babel-runtime/helpers/asyncToGenerator":42,"babel-runtime/helpers/classCallCheck":43,"babel-runtime/helpers/createClass":44,"babel-runtime/helpers/inherits":46,"babel-runtime/helpers/possibleConstructorReturn":47,"babel-runtime/helpers/slicedToArray":48,"babel-runtime/helpers/toConsumableArray":49,"babel-runtime/regenerator":51,events:184}],196:[function(e,t,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var n=e("./client");r.Notifications=n.Client},{"./client":193}],197:[function(e,t,r){"use strict";var n=o(e("babel-runtime/helpers/classCallCheck")),i=o(e("babel-runtime/helpers/createClass")),s=o(e("babel-runtime/core-js/array/from"));function o(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var a=e("loglevel");function u(e,t){return[(new Date).toISOString()+" Notifications "+e+":"].concat((0,s.default)(t))}var c=function(){function e(){(0,n.default)(this,e),this.prefix=""}return(0,i.default)(e,[{key:"setLevel",value:function(e){a.setLevel(e)}},{key:"trace",value:function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];a.debug.apply(null,u("T"+this.prefix,t))}},{key:"debug",value:function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];a.debug.apply(null,u("D"+this.prefix,t))}},{key:"info",value:function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];a.info.apply(null,u("I"+this.prefix,t))}},{key:"warn",value:function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];a.warn.apply(null,u("W"+this.prefix,t))}},{key:"error",value:function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];a.error.apply(null,u("E"+this.prefix,t))}}],[{key:"scope",value:function(){arguments.length>0&&void 0!==arguments[0]&&arguments[0];return new e}}]),e}();r.Logger=c;var l=c.scope();r.log=l},{"babel-runtime/core-js/array/from":26,"babel-runtime/helpers/classCallCheck":43,"babel-runtime/helpers/createClass":44,loglevel:186}],198:[function(e,t,r){"use strict";var n=d(e("babel-runtime/core-js/array/from")),i=d(e("babel-runtime/core-js/object/assign")),s=d(e("babel-runtime/regenerator")),o=d(e("babel-runtime/helpers/asyncToGenerator")),a=d(e("babel-runtime/core-js/object/get-prototype-of")),u=d(e("babel-runtime/helpers/classCallCheck")),c=d(e("babel-runtime/helpers/createClass")),l=d(e("babel-runtime/helpers/possibleConstructorReturn")),f=d(e("babel-runtime/helpers/inherits"));function d(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var p=e("operation-retrier"),h=e("./logger"),b=e("./connector");r.Connector=b.Connector;var v={min:2e3,max:12e4,randomness:.2},m=function(e){function t(e,r,n,i){(0,u.default)(this,t);var s=(0,l.default)(this,(t.__proto__||(0,a.default)(t)).call(this,i));return s.channelType=e,s.context=r,s.transport=n,s}return(0,f.default)(t,e),(0,c.default)(t,[{key:"updateRegistration",value:function(){var e=(0,o.default)(s.default.mark(function e(t,r){return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!r.has("notificationId")){e.next=3;break}return e.next=3,this.removeRegistration();case 3:if(t.notificationId&&t.notificationId.length){e.next=5;break}return e.abrupt("return",t);case 5:return e.next=7,this.register(t);case 7:return e.abrupt("return",t);case 8:case"end":return e.stop()}},e,this)}));return function(t,r){return e.apply(this,arguments)}}()},{key:"removeRegistration",value:function(){var e=(0,o.default)(s.default.mark(function e(){var t,r,n=this;return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(this.registrationId){e.next=2;break}return e.abrupt("return");case 2:return t=this.config.registrarUrl+"/"+this.registrationId+"?productId="+this.context.productId,r={"Content-Type":"application/json","X-Twilio-Token":this.config.token},e.prev=4,h.log.trace("Removing registration for ",this.channelType),e.next=8,new p.Retrier((0,i.default)(v,{maxAttemptsCount:3})).run(function(){return n.transport.delete(t,r)});case 8:h.log.debug("Registration removed for",this.channelType),e.next=15;break;case 11:throw e.prev=11,e.t0=e.catch(4),h.log.error("Failed to remove of registration ",this.channelType,e.t0),e.t0;case 15:case"end":return e.stop()}},e,this,[[4,11]])}));return function(){return e.apply(this,arguments)}}()},{key:"register",value:function(){var e=(0,o.default)(s.default.mark(function e(t){var r,i,o,a,u=this;return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return h.log.trace("Registering",this.channelType,t),r={endpoint_platform:this.context.platform,channel_type:this.channelType,version:this.context.protocolVersion.toString(),message_types:(0,n.default)(t.messageTypes),data:{registration_id:t.notificationId},ttl:"PT24H"},i=this.config.registrarUrl+"?productId="+this.context.productId,o={"Content-Type":"application/json","X-Twilio-Token":t.token},h.log.trace("Creating registration for channel ",this.channelType),e.prev=5,e.next=8,new p.Retrier(v).run(function(){return u.transport.post(i,o,r)});case 8:a=e.sent,this.registrationId=a.body.id,h.log.debug("Registration created: ",a),e.next=17;break;case 13:throw e.prev=13,e.t0=e.catch(5),h.log.error("Registration failed: ",e.t0),e.t0;case 17:case"end":return e.stop()}},e,this,[[5,13]])}));return function(t){return e.apply(this,arguments)}}()}]),t}(b.Connector);r.RegistrarConnector=m},{"./connector":195,"./logger":197,"babel-runtime/core-js/array/from":26,"babel-runtime/core-js/object/assign":31,"babel-runtime/core-js/object/get-prototype-of":35,"babel-runtime/helpers/asyncToGenerator":42,"babel-runtime/helpers/classCallCheck":43,"babel-runtime/helpers/createClass":44,"babel-runtime/helpers/inherits":46,"babel-runtime/helpers/possibleConstructorReturn":47,"babel-runtime/regenerator":51,"operation-retrier":188}],199:[function(e,t,r){"use strict";var n=c(e("babel-runtime/core-js/map")),i=c(e("babel-runtime/core-js/object/get-prototype-of")),s=c(e("babel-runtime/helpers/classCallCheck")),o=c(e("babel-runtime/helpers/createClass")),a=c(e("babel-runtime/helpers/possibleConstructorReturn")),u=c(e("babel-runtime/helpers/inherits"));function c(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var l=e("events"),f=e("./registrar.connector"),d=e("./twilsock.connector"),p=function(e){function t(e,r,o,u){(0,s.default)(this,t);var c=(0,a.default)(this,(t.__proto__||(0,i.default)(t)).call(this));c.config=u,c.connectors=new n.default;var l=c.detectPlatform();return c.connectors.set("gcm",new f.RegistrarConnector("gcm",{protocolVersion:3,productId:e,platform:l},r,u)),c.connectors.set("fcm",new f.RegistrarConnector("fcm",{protocolVersion:3,productId:e,platform:l},r,u)),c.connectors.set("apn",new f.RegistrarConnector("apn",{protocolVersion:4,productId:e,platform:l},r,u)),c.connectors.set("twilsock",new d.TwilsockConnector({productId:e,platform:l},o,u)),c.connectors.get("twilsock").on("transportReady",function(e){return c.emit("transportReady",e)}),c}return(0,u.default)(t,e),(0,o.default)(t,[{key:"setNotificationId",value:function(e,t){this.connector(e).setNotificationId(t)}},{key:"subscribe",value:function(e,t){return this.connector(t).subscribe(e)}},{key:"unsubscribe",value:function(e,t){return this.connector(t).unsubscribe(e)}},{key:"updateToken",value:function(e){this.connectors.forEach(function(t){return t.updateToken(e)})}},{key:"connector",value:function(e){var t=this.connectors.get(e);if(!t)throw new Error("Unknown channel type: "+e);return t}},{key:"detectPlatform",value:function(){var e="";return"undefined"!=typeof navigator?(e="unknown",void 0!==navigator.product&&(e=navigator.product),void 0!==navigator.userAgent&&(e=navigator.userAgent)):e="web",e.substring(0,128)}}]),t}(l.EventEmitter);r.Registrar=p},{"./registrar.connector":198,"./twilsock.connector":200,"babel-runtime/core-js/map":30,"babel-runtime/core-js/object/get-prototype-of":35,"babel-runtime/helpers/classCallCheck":43,"babel-runtime/helpers/createClass":44,"babel-runtime/helpers/inherits":46,"babel-runtime/helpers/possibleConstructorReturn":47,events:184}],200:[function(e,t,r){"use strict";var n=f(e("babel-runtime/core-js/array/from")),i=f(e("babel-runtime/regenerator")),s=f(e("babel-runtime/helpers/asyncToGenerator")),o=f(e("babel-runtime/core-js/object/get-prototype-of")),a=f(e("babel-runtime/helpers/classCallCheck")),u=f(e("babel-runtime/helpers/createClass")),c=f(e("babel-runtime/helpers/possibleConstructorReturn")),l=f(e("babel-runtime/helpers/inherits"));function f(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var d=e("uuid"),p=function(e){function t(e,r,n){(0,a.default)(this,t);var i=(0,c.default)(this,(t.__proto__||(0,o.default)(t)).call(this,n));return i.twilsock=r,i.context=e,e.id=d.v4(),i.twilsock.on("stateChanged",function(e){"connected"!==e&&i.emit("transportReady",!1)}),i.twilsock.on("registered",function(t){e&&t===e.id&&"connected"===r.state&&i.emit("transportReady",!0)}),i}return(0,l.default)(t,e),(0,u.default)(t,[{key:"setNotificationId",value:function(){}},{key:"updateToken",value:function(e){}},{key:"updateContextRequest",value:function(){var e=(0,s.default)(i.default.mark(function e(t){var r;return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r={product_id:this.context.productId,notification_protocol_version:4,endpoint_platform:this.context.platform,message_types:t},this.emit("transportReady",!1),e.next=4,this.twilsock.setNotificationsContext(this.context.id,r);case 4:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"updateRegistration",value:function(){var e=(0,s.default)(i.default.mark(function e(t,r){return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(r.has("messageType")){e.next=2;break}return e.abrupt("return");case 2:return e.next=4,this.updateContextRequest((0,n.default)(t.messageTypes));case 4:return e.abrupt("return",t);case 5:case"end":return e.stop()}},e,this)}));return function(t,r){return e.apply(this,arguments)}}()},{key:"removeRegistration",value:function(){return this.twilsock.removeNotificationsContext(this.context.id)}}]),t}(e("./connector").Connector);r.TwilsockConnector=p},{"./connector":195,"babel-runtime/core-js/array/from":26,"babel-runtime/core-js/object/get-prototype-of":35,"babel-runtime/helpers/asyncToGenerator":42,"babel-runtime/helpers/classCallCheck":43,"babel-runtime/helpers/createClass":44,"babel-runtime/helpers/inherits":46,"babel-runtime/helpers/possibleConstructorReturn":47,"babel-runtime/regenerator":51,uuid:228}],201:[function(e,t,r){"use strict";var n=c(e("babel-runtime/core-js/object/assign")),i=c(e("babel-runtime/core-js/object/get-prototype-of")),s=c(e("babel-runtime/helpers/classCallCheck")),o=c(e("babel-runtime/helpers/possibleConstructorReturn")),a=c(e("babel-runtime/helpers/createClass")),u=c(e("babel-runtime/helpers/inherits"));function c(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var l=e("events"),f=e("operation-retrier"),d=function(e){function t(e){(0,s.default)(this,t);var r=(0,o.default)(this,(t.__proto__||(0,i.default)(t)).call(this));return r.options=e?(0,n.default)({},e):{},r}return(0,u.default)(t,e),(0,a.default)(t,[{key:"inProgress",get:function(){return!!this.retrier}}]),(0,a.default)(t,[{key:"start",value:function(){if(this.inProgress)throw new Error("Already waiting for next attempt, call finishAttempt(success : boolean) to finish it");this.createRetrier()}},{key:"stop",value:function(){this.cleanRetrier(),this.newBackoff=null,this.usedBackoff=null}},{key:"modifyBackoff",value:function(e){this.newBackoff=e}},{key:"attemptFailed",value:function(){if(!this.inProgress)throw new Error("No attempt is in progress");this.newBackoff?!this.usedBackoff||this.usedBackoff<this.newBackoff?this.createRetrier():this.retrier.failed(new Error):this.retrier.failed(new Error)}},{key:"cancel",value:function(){this.retrier&&this.retrier.cancel()}},{key:"cleanRetrier",value:function(){this.retrier&&(this.retrier.removeAllListeners(),this.retrier.cancel(),this.retrier=null)}},{key:"getRetryPolicy",value:function(){var e=(0,n.default)({},this.options);return this.newBackoff&&(e.min=this.newBackoff,e.max=this.options.max&&this.options.max>this.newBackoff?this.options.max:this.newBackoff),e.maxAttemptsCount=this.options.maxAttemptsCount?this.options.maxAttemptsCount+1:void 0,e}},{key:"createRetrier",value:function(){var e=this;this.cleanRetrier();var t=this.getRetryPolicy();this.retrier=new f.Retrier(t),this.retrier.once("attempt",function(){e.retrier.on("attempt",function(){return e.emit("attempt")}),e.retrier.failed(new Error("Skipping first attempt"))}),this.retrier.on("failed",function(t){return e.emit("failed",t)}),this.usedBackoff=this.newBackoff,this.newBackoff=null,this.retrier.start().catch(function(e){})}}]),t}(l.EventEmitter);r.BackoffRetrier=d},{"babel-runtime/core-js/object/assign":31,"babel-runtime/core-js/object/get-prototype-of":35,"babel-runtime/helpers/classCallCheck":43,"babel-runtime/helpers/createClass":44,"babel-runtime/helpers/inherits":46,"babel-runtime/helpers/possibleConstructorReturn":47,events:184,"operation-retrier":188}],202:[function(e,t,r){"use strict";var n=d(e("babel-runtime/regenerator")),i=d(e("babel-runtime/helpers/asyncToGenerator")),s=d(e("babel-runtime/core-js/json/stringify")),o=d(e("babel-runtime/core-js/object/get-prototype-of")),a=d(e("babel-runtime/helpers/classCallCheck")),u=d(e("babel-runtime/helpers/createClass")),c=d(e("babel-runtime/helpers/possibleConstructorReturn")),l=d(e("babel-runtime/helpers/get")),f=d(e("babel-runtime/helpers/inherits"));function d(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var p=e("events"),h=e("./logger"),b=e("./configuration"),v=e("./twilsock"),m=e("./packetinterface"),y=e("./websocketchannel"),g=e("./services/registrations"),_=e("./services/upstream"),k=e("./deferred"),w=e("./index"),x=e("./offlinestorage"),j=e("./tokenStorage"),C=function(e){function t(e,r){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};(0,a.default)(this,t);var i=(0,c.default)(this,(t.__proto__||(0,o.default)(t)).call(this));i.offlineStorageDeferred=new k.Deferred,n.continuationToken=n.continuationToken?n.continuationToken:j.TokenStorage.getStoredToken(r);var s=i.config=new b.Configuration(e,r,n);h.log.setLevel(s.logLevel);var u=new y.WebSocketChannel(s.url),l=n.transport?n.transport:new m.PacketInterface(u,s);return i.channel=n.channel?n.channel:new v.TwilsockImpl(u,l,s),i.registrations=n.registrations?n.registrations:new g.Registrations(l),i.upstream=new _.Upstream(l,i.channel,s),i.registrations.on("registered",function(e){return i.emit("registered",e)}),i.channel.on("message",function(e,t){return setTimeout(function(){return i.emit("message",e,t)},0)}),i.channel.on("stateChanged",function(e){return setTimeout(function(){return i.emit("stateChanged",e)},0)}),i.channel.on("connectionError",function(e){return setTimeout(function(){return i.emit("connectionError",e)},0)}),i.channel.on("tokenAboutToExpire",function(){return setTimeout(function(){return i.emit("tokenAboutToExpire")},0)}),i.channel.on("tokenExpired",function(){return setTimeout(function(){return i.emit("tokenExpired")},0)}),i.channel.on("connected",function(){return i.registrations.updateRegistrations()}),i.channel.on("connected",function(){return i.upstream.sendPendingMessages()}),i.channel.on("connected",function(){return setTimeout(function(){return i.emit("connected")},0)}),i.channel.on("initialized",function(e){i.handleStorageId(r,e),j.TokenStorage.storeToken(e.continuationToken,r),setTimeout(function(){return i.emit("initialized",e)},0)}),i.channel.on("disconnected",function(){return setTimeout(function(){return i.emit("disconnected")},0)}),i.channel.on("disconnected",function(){return i.upstream.rejectPendingMessages()}),i.channel.on("disconnected",function(){return i.offlineStorageDeferred.fail(new w.TwilsockError("Client disconnected"))}),i.offlineStorageDeferred.promise.catch(function(){}),i}return(0,f.default)(t,e),(0,u.default)(t,[{key:"emit",value:function(e){for(var r,n=arguments.length,i=Array(n>1?n-1:0),a=1;a<n;a++)i[a-1]=arguments[a];return h.log.debug("Emitting "+e.toString()+"("+i.map(function(e){return(0,s.default)(e)}).join(", ")+")"),(r=(0,l.default)(t.prototype.__proto__||(0,o.default)(t.prototype),"emit",this)).call.apply(r,[this,e].concat(i))}},{key:"handleStorageId",value:function(e,t){if(t.offlineStorage)if(t.offlineStorage.hasOwnProperty(e))try{this.offlineStorageDeferred.set(x.OfflineProductStorage.create(t.offlineStorage[e])),h.log.debug("Offline storage for '"+e+"' product: "+(0,s.default)(t.offlineStorage[e])+".")}catch(r){this.offlineStorageDeferred.fail(new w.TwilsockError("Failed to parse offline storage for "+e+" "+(0,s.default)(t.offlineStorage[e])+". "+r+"."))}else this.offlineStorageDeferred.fail(new w.TwilsockError("No offline storage id for '"+e+"' product: "+(0,s.default)(t.offlineStorage)));else this.offlineStorageDeferred.fail(new w.TwilsockError("No offline storage id"))}},{key:"storageId",value:function(){return this.offlineStorageDeferred.promise}},{key:"updateToken",value:function(){var e=(0,i.default)(n.default.mark(function e(t){return n.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(h.log.trace("updating token '"+t+"'"),this.config.token!==t){e.next=3;break}return e.abrupt("return");case 3:return this.config.updateToken(t),e.abrupt("return",this.channel.updateToken(t));case 5:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"setNotificationsContext",value:function(e,t){this.registrations.setNotificationsContext(e,t)}},{key:"removeNotificationsContext",value:function(e){this.registrations.removeNotificationsContext(e)}},{key:"connect",value:function(){return this.channel.connect()}},{key:"disconnect",value:function(){return this.channel.disconnect()}},{key:"get",value:function(e,t){return this.upstream.send("GET",e,t)}},{key:"post",value:function(e,t,r){return this.upstream.send("POST",e,t,r)}},{key:"put",value:function(e,t,r){return this.upstream.send("PUT",e,t,r)}},{key:"delete",value:function(e,t){return this.upstream.send("DELETE",e,t)}},{key:"isConnected",get:function(){return this.channel.isConnected}},{key:"state",get:function(){return this.channel.state}}]),t}(p.EventEmitter);r.TwilsockClient=C,r.Twilsock=C},{"./configuration":203,"./deferred":204,"./index":209,"./logger":210,"./offlinestorage":212,"./packetinterface":213,"./services/registrations":223,"./services/upstream":224,"./tokenStorage":225,"./twilsock":226,"./websocketchannel":227,"babel-runtime/core-js/json/stringify":29,"babel-runtime/core-js/object/get-prototype-of":35,"babel-runtime/helpers/asyncToGenerator":42,"babel-runtime/helpers/classCallCheck":43,"babel-runtime/helpers/createClass":44,"babel-runtime/helpers/get":45,"babel-runtime/helpers/inherits":46,"babel-runtime/helpers/possibleConstructorReturn":47,"babel-runtime/regenerator":51,events:184}],203:[function(e,t,r){"use strict";var n=s(e("babel-runtime/helpers/classCallCheck")),i=s(e("babel-runtime/helpers/createClass"));function s(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var o="0.5.11",a=function(){function e(t,r){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};(0,n.default)(this,e),this.activeGrant=r,this._token=t;var s="wss://tsock."+(i.region||"us1")+".twilio.com/v3/wsconnect",a=i.twilsock||i.Twilsock||{};this.url=a.uri||s,this._continuationToken=i.continuationToken?i.continuationToken:null,this.logLevel=i.logLevel?i.logLevel:"error",this.retryPolicy=i.retryPolicy?i.retryPolicy:{min:1e3,max:12e4,randomness:.2},this.clientMetadata=i.clientMetadata?i.clientMetadata:{},this.clientMetadata.ver=o,this.initRegistrations=i.initRegistrations?i.initRegistrations:null,this.tweaks=i.tweaks?i.tweaks:null}return(0,i.default)(e,[{key:"updateToken",value:function(e){this._token=e}},{key:"updateContinuationToken",value:function(e){this._continuationToken=e}},{key:"token",get:function(){return this._token}},{key:"continuationToken",get:function(){return this._continuationToken}}]),e}();r.Configuration=a},{"babel-runtime/helpers/classCallCheck":43,"babel-runtime/helpers/createClass":44}],204:[function(e,t,r){"use strict";var n=o(e("babel-runtime/core-js/promise")),i=o(e("babel-runtime/helpers/classCallCheck")),s=o(e("babel-runtime/helpers/createClass"));function o(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var a=function(){function e(){var t=this;(0,i.default)(this,e),this._promise=new n.default(function(e,r){t._resolve=e,t._reject=r})}return(0,s.default)(e,[{key:"update",value:function(e){this._resolve(e)}},{key:"set",value:function(e){this.current=e,this._resolve(e)}},{key:"fail",value:function(e){this._reject(e)}},{key:"promise",get:function(){return this._promise}}]),e}();r.Deferred=a},{"babel-runtime/core-js/promise":37,"babel-runtime/helpers/classCallCheck":43,"babel-runtime/helpers/createClass":44}],205:[function(e,t,r){"use strict";var n=a(e("babel-runtime/core-js/object/get-prototype-of")),i=a(e("babel-runtime/helpers/classCallCheck")),s=a(e("babel-runtime/helpers/possibleConstructorReturn")),o=a(e("babel-runtime/helpers/inherits"));function a(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var u=function(e){function t(e){return(0,i.default)(this,t),(0,s.default)(this,(t.__proto__||(0,n.default)(t)).call(this,e))}return(0,o.default)(t,e),t}(e("./twilsockerror").TwilsockError);r.TransportUnavailableError=u},{"./twilsockerror":206,"babel-runtime/core-js/object/get-prototype-of":35,"babel-runtime/helpers/classCallCheck":43,"babel-runtime/helpers/inherits":46,"babel-runtime/helpers/possibleConstructorReturn":47}],206:[function(e,t,r){"use strict";var n=f(e("babel-runtime/core-js/object/create")),i=f(e("babel-runtime/core-js/object/set-prototype-of")),s=f(e("babel-runtime/core-js/array/from")),o=f(e("babel-runtime/core-js/reflect/construct")),a=f(e("babel-runtime/core-js/object/get-prototype-of")),u=f(e("babel-runtime/helpers/classCallCheck")),c=f(e("babel-runtime/helpers/possibleConstructorReturn")),l=f(e("babel-runtime/helpers/inherits"));function f(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var d=function(e){function t(e){return(0,u.default)(this,t),(0,c.default)(this,(t.__proto__||(0,a.default)(t)).call(this,e))}return(0,l.default)(t,e),t}(function(e){function t(){var t=(0,o.default)(e,(0,s.default)(arguments));return(0,i.default)(t,(0,a.default)(this)),t}return t.prototype=(0,n.default)(e.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),i.default?(0,i.default)(t,e):t.__proto__=e,t}(Error));r.TwilsockError=d},{"babel-runtime/core-js/array/from":26,"babel-runtime/core-js/object/create":32,"babel-runtime/core-js/object/get-prototype-of":35,"babel-runtime/core-js/object/set-prototype-of":36,"babel-runtime/core-js/reflect/construct":38,"babel-runtime/helpers/classCallCheck":43,"babel-runtime/helpers/inherits":46,"babel-runtime/helpers/possibleConstructorReturn":47}],207:[function(e,t,r){"use strict";var n=a(e("babel-runtime/core-js/object/get-prototype-of")),i=a(e("babel-runtime/helpers/classCallCheck")),s=a(e("babel-runtime/helpers/possibleConstructorReturn")),o=a(e("babel-runtime/helpers/inherits"));function a(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var u=function(e){function t(e,r){(0,i.default)(this,t);var o=(0,s.default)(this,(t.__proto__||(0,n.default)(t)).call(this,e));return o.reply=r,o}return(0,o.default)(t,e),t}(e("./twilsockerror").TwilsockError);r.TwilsockReplyError=u},{"./twilsockerror":206,"babel-runtime/core-js/object/get-prototype-of":35,"babel-runtime/helpers/classCallCheck":43,"babel-runtime/helpers/inherits":46,"babel-runtime/helpers/possibleConstructorReturn":47}],208:[function(e,t,r){"use strict";var n=a(e("babel-runtime/core-js/object/get-prototype-of")),i=a(e("babel-runtime/helpers/classCallCheck")),s=a(e("babel-runtime/helpers/possibleConstructorReturn")),o=a(e("babel-runtime/helpers/inherits"));function a(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var u=function(e){function t(e,r,o){(0,i.default)(this,t);var a=(0,s.default)(this,(t.__proto__||(0,n.default)(t)).call(this,r));return a.status=e,a.description=r,a.body=o,a}return(0,o.default)(t,e),t}(e("./twilsockerror").TwilsockError);r.TwilsockUpstreamError=u},{"./twilsockerror":206,"babel-runtime/core-js/object/get-prototype-of":35,"babel-runtime/helpers/classCallCheck":43,"babel-runtime/helpers/inherits":46,"babel-runtime/helpers/possibleConstructorReturn":47}],209:[function(e,t,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var n=e("./client");r.TwilsockClient=n.TwilsockClient,r.Twilsock=n.TwilsockClient;var i=e("./error/twilsockerror");r.TwilsockError=i.TwilsockError;var s=e("./error/transportunavailableerror");r.TransportUnavailableError=s.TransportUnavailableError},{"./client":202,"./error/transportunavailableerror":205,"./error/twilsockerror":206}],210:[function(e,t,r){"use strict";var n=o(e("babel-runtime/helpers/classCallCheck")),i=o(e("babel-runtime/helpers/createClass")),s=o(e("babel-runtime/core-js/array/from"));function o(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var a=e("loglevel");function u(e,t){return[(new Date).toISOString()+" Twilsock "+e+":"].concat((0,s.default)(t))}var c=function(){function e(t){(0,n.default)(this,e),this.prefix="",this.prefix=null!=t&&t.length>0?" "+t+":":""}return(0,i.default)(e,[{key:"setLevel",value:function(e){a.setLevel(e)}},{key:"trace",value:function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];a.debug.apply(null,u("T",t))}},{key:"debug",value:function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];a.debug.apply(null,u("D",t))}},{key:"info",value:function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];a.info.apply(null,u("I",t))}},{key:"warn",value:function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];a.warn.apply(null,u("W",t))}},{key:"error",value:function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];a.error.apply(null,u("E",t))}}],[{key:"setLevel",value:function(e){a.setLevel(e)}},{key:"trace",value:function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];a.trace.apply(null,u("T",t))}},{key:"debug",value:function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];a.debug.apply(null,u("D",t))}},{key:"info",value:function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];a.info.apply(null,u("I",t))}},{key:"warn",value:function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];a.warn.apply(null,u("W",t))}},{key:"error",value:function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];a.error.apply(null,u("E",t))}}]),e}();r.Logger=c;var l=new c("");r.log=l},{"babel-runtime/core-js/array/from":26,"babel-runtime/helpers/classCallCheck":43,"babel-runtime/helpers/createClass":44,loglevel:186}],211:[function(e,t,r){"use strict";var n=s(e("babel-runtime/helpers/classCallCheck")),i=s(e("babel-runtime/helpers/createClass"));function s(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var o=e("platform"),a=function(){function e(){(0,n.default)(this,e)}return(0,i.default)(e,null,[{key:"getMetadata",value:function(e){"undefined"!=typeof navigator&&o.parse(navigator.userAgent);var t=e&&e.clientMetadata?e.clientMetadata:{},r={env:o.name,envv:o.version,os:o.os.family,osv:o.os.version,osa:o.os.architecture,sdk:"js-default"},n={};return["ver","env","envv","os","osv","osa","type","sdk","sdkv","dev","devv","devt","app","appv"].filter(function(e){return e in t||e in r}).forEach(function(e){return n[e]=e in t?t[e]:r[e]}),n}}]),e}();r.Metadata=a},{"babel-runtime/helpers/classCallCheck":43,"babel-runtime/helpers/createClass":44,platform:190}],212:[function(e,t,r){"use strict";var n=s(e("babel-runtime/helpers/classCallCheck")),i=s(e("babel-runtime/helpers/createClass"));function s(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var o=e("./index"),a=function(){function e(t){(0,n.default)(this,e),this.id=t}return(0,i.default)(e,null,[{key:"create",value:function(t){if(t instanceof Object&&"storage_id"in t)return new e(t.storage_id);throw new o.TwilsockError('Field "storage_id" is missing')}}]),e}();r.OfflineProductStorage=a},{"./index":209,"babel-runtime/helpers/classCallCheck":43,"babel-runtime/helpers/createClass":44}],213:[function(e,t,r){"use strict";var n=f(e("babel-runtime/core-js/promise")),i=f(e("babel-runtime/regenerator")),s=f(e("babel-runtime/helpers/asyncToGenerator")),o=f(e("babel-runtime/core-js/map")),a=f(e("babel-runtime/helpers/createClass")),u=f(e("babel-runtime/helpers/classCallCheck")),c=f(e("babel-runtime/core-js/json/stringify")),l=f(e("babel-runtime/helpers/typeof"));function f(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var d=e("./logger"),p=e("uuid"),h=e("./error/twilsockerror"),b=e("./error/twilsockreplyerror"),v=e("./parser"),m=e("./protocol/messages"),y=e("./metadata");r.PacketResponse=function e(){(0,u.default)(this,e)};var g=function(){function e(t,r){var n=this;(0,u.default)(this,e),this.config=r,this.activeRequests=new o.default,this.channel=t,this.channel.on("reply",function(e){return n.processReply(e)}),this.channel.on("disconnected",function(){n.activeRequests.forEach(function(e){clearTimeout(e.timeout),e.reject(new h.TwilsockError("disconnected"))}),n.activeRequests.clear()})}return(0,a.default)(e,[{key:"processReply",value:function(e){var t,r=this.activeRequests.get(e.id);r&&(clearTimeout(r.timeout),this.activeRequests.delete(e.id),(t=e.status.code)>=200&&t<300?r.resolve(e):(r.reject(new b.TwilsockReplyError("Transport failure: "+e.status.status,e)),d.log.trace("message rejected")))}},{key:"storeRequest",value:function(e,t,r){var n={resolve:t,reject:r,timeout:setTimeout(function(){d.log.trace("request",e,"is timed out"),r(new h.TwilsockError("Twilsock: request timeout: "+e))},3e4)};this.activeRequests.set(e,n)}},{key:"shutdown",value:function(){this.activeRequests.forEach(function(e){clearTimeout(e.timeout),e.reject(new h.TwilsockError("Twilsock: request cancelled by user"))}),this.activeRequests.clear()}},{key:"sendInit",value:function(){var e=(0,s.default)(i.default.mark(function e(){var t,r,n;return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return d.log.trace("sendInit"),t=y.Metadata.getMetadata(this.config),r=new m.Init(this.config.token,this.config.continuationToken,t,this.config.initRegistrations,this.config.tweaks),e.next=5,this.sendWithReply(r);case 5:return n=e.sent,e.abrupt("return",new m.InitReply(n.id,n.header.continuation_token,n.header.continuation_token_status,n.header.offline_storage,n.header.init_registrations,n.header.debug_info));case 7:case"end":return e.stop()}},e,this)}));return function(){return e.apply(this,arguments)}}()},{key:"sendClose",value:function(){var e=new m.Close;this.send(e)}},{key:"sendWithReply",value:function(e,t){var r=this;return new n.default(function(n,i){var s=r.send(e,t);r.storeRequest(s,n,i)})}},{key:"send",value:function(e,t){e.id=e.id||"TM"+p.v4();var r=v.Parser.createPacket(e,function(e){switch(void 0===e?"undefined":(0,l.default)(e)){case"undefined":return"";case"object":return(0,c.default)(e);default:return e}}(t));try{return this.channel.send(r),e.id}catch(t){throw d.log.debug("failed to send ",e,t),d.log.trace(t.stack),t}}},{key:"isConnected",get:function(){return this.channel.isConnected}}]),e}();r.PacketInterface=g},{"./error/twilsockerror":206,"./error/twilsockreplyerror":207,"./logger":210,"./metadata":211,"./parser":214,"./protocol/messages":217,"babel-runtime/core-js/json/stringify":29,"babel-runtime/core-js/map":30,"babel-runtime/core-js/promise":37,"babel-runtime/helpers/asyncToGenerator":42,"babel-runtime/helpers/classCallCheck":43,"babel-runtime/helpers/createClass":44,"babel-runtime/helpers/typeof":50,"babel-runtime/regenerator":51,uuid:228}],214:[function(e,t,r){"use strict";var n=o(e("babel-runtime/core-js/json/stringify")),i=o(e("babel-runtime/helpers/classCallCheck")),s=o(e("babel-runtime/helpers/createClass"));function o(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var a=e("./logger");function u(e){return encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,function(e,t){return String.fromCharCode("0x"+t)}).length}function c(e){var t=Array.prototype.map.call(e,function(e){return String.fromCharCode(e)}).join("").replace(/(.)/g,function(e,t){var r=t.charCodeAt(0).toString(16).toUpperCase();return r.length<2&&(r="0"+r),"%"+r});return decodeURIComponent(t)}function l(e){return JSON.parse(c(e))}var f=function(){function e(){(0,i.default)(this,e)}return(0,s.default)(e,null,[{key:"parse",value:function(e){var t=new Uint8Array(e),r=function(e){for(var t="",r=0;r<e.length;++r){var n=String.fromCharCode(e[r]);if(t+=n,"\r"===n){r+=2;break}}var i=t.split(" ");return{size:r,protocol:i[0],version:i[1],headerSize:Number(i[2])}}(t);if("TWILSOCK"===r.protocol&&"V3.0"===r.version){var n=null;try{n=l(t.subarray(r.size,r.size+r.headerSize))}catch(t){return void a.log.error("failed to parse message header",t,e)}a.log.debug("message received: ",n.method),a.log.trace("message received: ",n);var i=null;if(n.payload_size>0){var s=2+r.size+r.headerSize,o=n.payload_size;if(n.hasOwnProperty("payload_type")&&0!==n.payload_type.indexOf("application/json"))0===n.payload_type.indexOf("text/plain")&&(i=c(t.subarray(s,s+o)));else try{i=l(t.subarray(s,s+o))}catch(t){return void a.log.error("failed to parse message body",t,e)}}return{method:n.method,header:n,payload:i}}a.log.error("unsupported protocol: "+r.protocol+" ver "+r.version)}},{key:"createPacket",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";e.payload_size=u(t);var r,i,s=(0,n.default)(e)+"\r\n",o="TWILSOCK V3.0 "+(u(s)-2)+"\r\n";return a.log.debug("send request:",o+s+t),(r=encodeURIComponent(o+s+t).replace(/%([0-9A-F]{2})/g,function(e,t){return String.fromCharCode("0x"+t)}),i=new Uint8Array(r.length),Array.prototype.forEach.call(r,function(e,t){i[t]=e.charCodeAt(0)}),i).buffer}}]),e}();r.Parser=f},{"./logger":210,"babel-runtime/core-js/json/stringify":29,"babel-runtime/helpers/classCallCheck":43,"babel-runtime/helpers/createClass":44}],215:[function(e,t,r){"use strict";var n,i=e("babel-runtime/helpers/classCallCheck"),s=(n=i)&&n.__esModule?n:{default:n};Object.defineProperty(r,"__esModule",{value:!0});var o=e("uuid");r.AbstractMessage=function e(t){(0,s.default)(this,e),this.id=t||"TM"+o.v4()}},{"babel-runtime/helpers/classCallCheck":43,uuid:228}],216:[function(e,t,r){"use strict";var n=a(e("babel-runtime/core-js/object/get-prototype-of")),i=a(e("babel-runtime/helpers/classCallCheck")),s=a(e("babel-runtime/helpers/possibleConstructorReturn")),o=a(e("babel-runtime/helpers/inherits"));function a(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var u=function(e){function t(){(0,i.default)(this,t);var e=(0,s.default)(this,(t.__proto__||(0,n.default)(t)).call(this));return e.method="close",e}return(0,o.default)(t,e),t}(e("./abstractmessage").AbstractMessage);r.Close=u},{"./abstractmessage":215,"babel-runtime/core-js/object/get-prototype-of":35,"babel-runtime/helpers/classCallCheck":43,"babel-runtime/helpers/inherits":46,"babel-runtime/helpers/possibleConstructorReturn":47}],217:[function(e,t,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var n=e("./init");r.Init=n.Init;var i=e("./initReply");r.InitReply=i.InitReply;var s=e("./update");r.Update=s.Update;var o=e("./message");r.Message=o.Message;var a=e("./reply");r.Reply=a.Reply;var u=e("./close");r.Close=u.Close},{"./close":216,"./init":218,"./initReply":219,"./message":220,"./reply":221,"./update":222}],218:[function(e,t,r){"use strict";var n=a(e("babel-runtime/core-js/object/get-prototype-of")),i=a(e("babel-runtime/helpers/classCallCheck")),s=a(e("babel-runtime/helpers/possibleConstructorReturn")),o=a(e("babel-runtime/helpers/inherits"));function a(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var u=function(e){function t(e,r,o){var a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,u=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null;(0,i.default)(this,t);var c=(0,s.default)(this,(t.__proto__||(0,n.default)(t)).call(this));return c.method="init",c.token=e,c.continuation_token=r,c.metadata=o,c.registrations=a,c.tweaks=u,c.capabilities=["client_update","offline_storage"],c}return(0,o.default)(t,e),t}(e("./abstractmessage").AbstractMessage);r.Init=u},{"./abstractmessage":215,"babel-runtime/core-js/object/get-prototype-of":35,"babel-runtime/helpers/classCallCheck":43,"babel-runtime/helpers/inherits":46,"babel-runtime/helpers/possibleConstructorReturn":47}],219:[function(e,t,r){"use strict";var n=a(e("babel-runtime/core-js/object/get-prototype-of")),i=a(e("babel-runtime/helpers/possibleConstructorReturn")),s=a(e("babel-runtime/helpers/inherits")),o=a(e("babel-runtime/helpers/classCallCheck"));function a(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var u=e("./abstractmessage");r.ContinuationTokenStatus=function e(){(0,o.default)(this,e)};var c=function(e){function t(e,r,s,a,u,c){(0,o.default)(this,t);var l=(0,i.default)(this,(t.__proto__||(0,n.default)(t)).call(this,e));return l.continuationToken=r,l.continuationTokenStatus=s,l.offlineStorage=a,l.initRegistrations=u,l.debugInfo=c,l}return(0,s.default)(t,e),t}(u.AbstractMessage);r.InitReply=c},{"./abstractmessage":215,"babel-runtime/core-js/object/get-prototype-of":35,"babel-runtime/helpers/classCallCheck":43,"babel-runtime/helpers/inherits":46,"babel-runtime/helpers/possibleConstructorReturn":47}],220:[function(e,t,r){"use strict";var n=a(e("babel-runtime/core-js/object/get-prototype-of")),i=a(e("babel-runtime/helpers/classCallCheck")),s=a(e("babel-runtime/helpers/possibleConstructorReturn")),o=a(e("babel-runtime/helpers/inherits"));function a(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var u=function(e){function t(e,r,o){(0,i.default)(this,t);var a=(0,s.default)(this,(t.__proto__||(0,n.default)(t)).call(this));return a.method="message",a.active_grant=e,a.payload_type=r,a.http_request=o,a}return(0,o.default)(t,e),t}(e("./abstractmessage").AbstractMessage);r.Message=u},{"./abstractmessage":215,"babel-runtime/core-js/object/get-prototype-of":35,"babel-runtime/helpers/classCallCheck":43,"babel-runtime/helpers/inherits":46,"babel-runtime/helpers/possibleConstructorReturn":47}],221:[function(e,t,r){"use strict";var n=a(e("babel-runtime/core-js/object/get-prototype-of")),i=a(e("babel-runtime/helpers/classCallCheck")),s=a(e("babel-runtime/helpers/possibleConstructorReturn")),o=a(e("babel-runtime/helpers/inherits"));function a(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var u=function(e){function t(e){(0,i.default)(this,t);var r=(0,s.default)(this,(t.__proto__||(0,n.default)(t)).call(this,e));return r.method="reply",r.payload_type="application/json",r.status={code:200,status:"OK"},r}return(0,o.default)(t,e),t}(e("./abstractmessage").AbstractMessage);r.Reply=u},{"./abstractmessage":215,"babel-runtime/core-js/object/get-prototype-of":35,"babel-runtime/helpers/classCallCheck":43,"babel-runtime/helpers/inherits":46,"babel-runtime/helpers/possibleConstructorReturn":47}],222:[function(e,t,r){"use strict";var n=a(e("babel-runtime/core-js/object/get-prototype-of")),i=a(e("babel-runtime/helpers/classCallCheck")),s=a(e("babel-runtime/helpers/possibleConstructorReturn")),o=a(e("babel-runtime/helpers/inherits"));function a(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var u=function(e){function t(e){(0,i.default)(this,t);var r=(0,s.default)(this,(t.__proto__||(0,n.default)(t)).call(this));return r.method="update",r.token=e,r}return(0,o.default)(t,e),t}(e("./abstractmessage").AbstractMessage);r.Update=u},{"./abstractmessage":215,"babel-runtime/core-js/object/get-prototype-of":35,"babel-runtime/helpers/classCallCheck":43,"babel-runtime/helpers/inherits":46,"babel-runtime/helpers/possibleConstructorReturn":47}],223:[function(e,t,r){"use strict";var n=d(e("babel-runtime/core-js/set")),i=d(e("babel-runtime/regenerator")),s=d(e("babel-runtime/helpers/asyncToGenerator")),o=d(e("babel-runtime/core-js/map")),a=d(e("babel-runtime/core-js/object/get-prototype-of")),u=d(e("babel-runtime/helpers/classCallCheck")),c=d(e("babel-runtime/helpers/createClass")),l=d(e("babel-runtime/helpers/possibleConstructorReturn")),f=d(e("babel-runtime/helpers/inherits"));function d(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var p=e("../logger"),h=e("events"),b=e("uuid"),v=e("../error/twilsockerror"),m=function(e){function t(e){(0,u.default)(this,t);var r=(0,l.default)(this,(t.__proto__||(0,a.default)(t)).call(this));return r.transport=e,r.registrations=new o.default,r.registrationsInProgress=new o.default,r}return(0,f.default)(t,e),(0,c.default)(t,[{key:"putNotificationContext",value:function(){var e=(0,s.default)(i.default.mark(function e(t,r){var n;return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return n={method:"put_notification_ctx",notification_ctx_id:t},e.next=3,this.transport.sendWithReply(n,r);case 3:e.sent;case 4:case"end":return e.stop()}},e,this)}));return function(t,r){return e.apply(this,arguments)}}()},{key:"deleteNotificationContext",value:function(){var e=(0,s.default)(i.default.mark(function e(t){var r;return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r={method:"delete_notification_ctx",notification_ctx_id:t},e.next=3,this.transport.sendWithReply(r);case 3:e.sent;case 4:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"updateRegistration",value:function(){var e=(0,s.default)(i.default.mark(function e(t,r){var s,o;return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return p.log.debug("update registration for context",t),(s=this.registrationsInProgress.get(t))||(s=new n.default,this.registrationsInProgress.set(t,s)),o=b.v4(),s.add(o),e.prev=5,e.next=8,this.putNotificationContext(t,r);case 8:p.log.debug("registration attempt succeeded for context",r),s.delete(o),0===s.size&&(this.registrationsInProgress.delete(t),this.emit("registered",t)),e.next=19;break;case 13:e.prev=13,e.t0=e.catch(5),p.log.warn("registration attempt failed for context",r),p.log.debug(e.t0),s.delete(o),0===s.size&&(this.registrationsInProgress.delete(t),this.emit("registrationFailed",t,e.t0));case 19:case"end":return e.stop()}},e,this,[[5,13]])}));return function(t,r){return e.apply(this,arguments)}}()},{key:"updateRegistrations",value:function(){var e=this;p.log.trace("refreshing "+this.registrations.size+" registrations"),this.registrations.forEach(function(t,r){e.updateRegistration(r,t)})}},{key:"setNotificationsContext",value:function(e,t){if(!e||!t)throw new v.TwilsockError("Invalid arguments provided");this.registrations.set(e,t),this.transport.isConnected&&this.updateRegistration(e,t)}},{key:"removeNotificationsContext",value:function(){var e=(0,s.default)(i.default.mark(function e(t){return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(this.registrations.has(t)){e.next=2;break}return e.abrupt("return");case 2:return e.next=4,this.deleteNotificationContext(t);case 4:this.transport.isConnected&&this.registrations.delete(t);case 5:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()}]),t}(h.EventEmitter);r.Registrations=m},{"../error/twilsockerror":206,"../logger":210,"babel-runtime/core-js/map":30,"babel-runtime/core-js/object/get-prototype-of":35,"babel-runtime/core-js/set":39,"babel-runtime/helpers/asyncToGenerator":42,"babel-runtime/helpers/classCallCheck":43,"babel-runtime/helpers/createClass":44,"babel-runtime/helpers/inherits":46,"babel-runtime/helpers/possibleConstructorReturn":47,"babel-runtime/regenerator":51,events:184,uuid:228}],224:[function(e,t,r){"use strict";var n=u(e("babel-runtime/regenerator")),i=u(e("babel-runtime/helpers/asyncToGenerator")),s=u(e("babel-runtime/core-js/promise")),o=u(e("babel-runtime/helpers/createClass")),a=u(e("babel-runtime/helpers/classCallCheck"));function u(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var c=e("../logger"),l=e("../error/twilsockerror"),f=e("../error/twilsockupstreamerror"),d=e("../protocol/messages"),p=e("../index");function h(e,t){var r=function(e){var t=e.match(/^(https?\:)\/\/(([^:\/?#]*)(?:\:([0-9]+))?)(\/[^?#]*)(\?[^#]*|)(#.*|)$/);if(t){var r={protocol:t[1],host:t[2],hostname:t[3],port:t[4],pathname:t[5],search:t[6],hash:t[7],params:null};if(r.search.length>0){var n=r.search.substring(1);r.params=n.split("&").map(function(e){return e.split("=")}).reduce(function(e,t){return e.hasOwnProperty(t[0])?Array.isArray(e[t[0]])?e[t[0]].push(t[1]):e[t[0]]=[e[t[0]],t[1]]:e[t[0]]=t[1],e},{})}return r}throw new l.TwilsockError("Incorrect URI: "+e)}(t),n={method:e,host:r.host,path:r.pathname};return r.params&&(n.params=r.params),n}var b=function(){function e(t,r,n){(0,a.default)(this,e),this.config=n,this.transport=t,this.pendingMessages=[],this.twilsock=r}return(0,o.default)(e,[{key:"saveMessage",value:function(e){var t=this;return new s.default(function(r,n){var i={message:e,resolve:r,reject:n,alreadyRejected:!1,timeout:setTimeout(function(){c.log.debug("request is timed out"),n(new l.TwilsockError("Twilsock: request timeout")),i.alreadyRejected=!0},2e4)};t.pendingMessages.push(i)})}},{key:"sendPendingMessages",value:function(){for(var e=this,t=function(){var t=e.pendingMessages[0];if(!t.alreadyRejected)try{var r=t.message;e.actualSend(r).then(function(e){return t.resolve(e)}).catch(function(e){return t.reject(e)}),clearTimeout(t.timeout)}catch(e){return c.log.debug("Failed to send pending message",e),"break"}e.pendingMessages.splice(0,1)};this.pendingMessages.length;){if("break"===t())break}}},{key:"rejectPendingMessages",value:function(){this.pendingMessages.forEach(function(e){e.reject(new p.TransportUnavailableError("Can't connect to twilsock")),clearTimeout(e.timeout)}),this.pendingMessages.splice(0,this.pendingMessages.length)}},{key:"actualSend",value:function(){var e=(0,i.default)(n.default.mark(function e(t){var r,i,s,o,a,u;return n.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.to,i=t.headers,s=t.body,o={host:r.host,path:r.path,method:r.method,params:r.params,headers:i},a=new d.Message(this.config.activeGrant,i["Content-Type"]||"application/json",o),e.next=7,this.transport.sendWithReply(a,s);case 7:if(u=e.sent,!((c=u)&&c.header&&c.header.http_status)||(n=u.header.http_status.code)>=200&&n<300){e.next=10;break}throw new f.TwilsockUpstreamError(u.header.http_status.code,u.header.http_status.status,u.body);case 10:return e.abrupt("return",{status:u.header.http_status,headers:u.header.http_headers,body:u.body});case 11:case"end":return e.stop()}var n,c},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"send",value:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=arguments[3];if(this.twilsock.isTerminalState)return s.default.reject(new p.TransportUnavailableError("Can't connect to twilsock"));var i=function(e,t,r,n){return{to:h(e,t),headers:r,body:n}}(e,t,r,n);return this.twilsock.isConnected?this.actualSend(i):this.saveMessage(i)}}]),e}();r.Upstream=b},{"../error/twilsockerror":206,"../error/twilsockupstreamerror":208,"../index":209,"../logger":210,"../protocol/messages":217,"babel-runtime/core-js/promise":37,"babel-runtime/helpers/asyncToGenerator":42,"babel-runtime/helpers/classCallCheck":43,"babel-runtime/helpers/createClass":44,"babel-runtime/regenerator":51}],225:[function(e,t,r){(function(t){"use strict";var n=s(e("babel-runtime/helpers/classCallCheck")),i=s(e("babel-runtime/helpers/createClass"));function s(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var o=function(){function e(){(0,n.default)(this,e)}return(0,i.default)(e,null,[{key:"storeToken",value:function(t,r){e.canStore&&e.sessionStorage.setItem(e.getKeyName(r),t)}},{key:"getStoredToken",value:function(t){return e.canStore?e.sessionStorage.getItem(e.getKeyName(t)):null}},{key:"initialize",value:function(){e.canStore&&(e.sessionStorage.getItem(e.initializedFlag)&&this.clear(),e.sessionStorage.setItem(e.initializedFlag,"true"),e.window.addEventListener("unload",function(){e.sessionStorage.removeItem(e.initializedFlag)}))}},{key:"clear",value:function(){if(e.canStore){for(var t=[],r=0;r<e.sessionStorage.length;r++){var n=e.sessionStorage.key(r);n.startsWith(e.tokenStoragePrefix)&&t.push(n)}t.forEach(function(t){return e.sessionStorage.removeItem(t)}),e.sessionStorage.removeItem(e.initializedFlag)}}},{key:"getKeyName",value:function(t){return""+e.tokenStoragePrefix+t}},{key:"sessionStorage",get:function(){try{return t.sessionStorage}catch(e){return null}}},{key:"window",get:function(){try{return t.window}catch(e){return null}}},{key:"canStore",get:function(){return e.sessionStorage&&e.window}}]),e}();o.initializedFlag="twilio_twilsock_token_storage",o.tokenStoragePrefix="twilio_continuation_token_",r.TokenStorage=o,o.initialize()}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"babel-runtime/helpers/classCallCheck":43,"babel-runtime/helpers/createClass":44}],226:[function(e,t,r){"use strict";var n=d(e("babel-runtime/core-js/promise")),i=d(e("babel-runtime/regenerator")),s=d(e("babel-runtime/helpers/asyncToGenerator")),o=d(e("babel-runtime/core-js/object/get-prototype-of")),a=d(e("babel-runtime/helpers/createClass")),u=d(e("babel-runtime/helpers/possibleConstructorReturn")),c=d(e("babel-runtime/helpers/inherits")),l=d(e("babel-runtime/helpers/classCallCheck")),f=d(e("babel-runtime/core-js/json/stringify"));d(e("babel-runtime/helpers/typeof"));function d(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var p=e("events"),h=e("javascript-state-machine"),b=e("./logger"),v=e("./protocol/messages"),m=e("./parser"),y=e("./error/twilsockreplyerror"),g=e("./backoffretrier");r.Response=function e(){(0,l.default)(this,e)};var _=function(e){function t(e,r,n){(0,l.default)(this,t);var i=(0,u.default)(this,(t.__proto__||(0,o.default)(t)).call(this));return i.terminalStates=["disconnected","rejected"],i.lastEmittedState=void 0,i.tokenExpiredSasCode=20104,i.websocket=e,i.websocket.on("connected",function(){return i.fsm.socketConnected()}),i.websocket.on("disconnected",function(e){return i.fsm.socketClosed()}),i.websocket.on("message",function(e){return i.onIncomingMessage(e)}),i.websocket.on("socketError",function(e){return i.emit("connectionError",{terminal:!1,message:e.message,httpStatusCode:null,errorCode:null})}),i.transport=r,i.config=n,i.retrier=new g.BackoffRetrier(n.retryPolicy),i.retrier.on("attempt",function(){return i.retry()}),i.retrier.on("failed",function(e){b.log.warn("Retrying failed: "+e.message),i.disconnect()}),"undefined"!=typeof window&&void 0!==window.addEventListener&&(window.addEventListener("online",function(){b.log.debug("Browser reported connectivity state: online"),i.fsm.systemOnline()}),window.addEventListener("offline",function(){b.log.debug("Browser reported connectivity state: offline"),i.websocket.close(),i.fsm.socketClosed()})),i.fsm=new h({init:"disconnected",transitions:[{name:"userConnect",from:["disconnected","rejected"],to:"connecting"},{name:"userConnect",from:["connecting","connected"]},{name:"userDisconnect",from:["connecting","initialising","connected","updating","retrying","rejected","waitSocketClosed","waitOffloadSocketClosed"],to:"disconnecting"},{name:"userRetry",from:["retrying"],to:"connecting"},{name:"socketConnected",from:["connecting"],to:"initialising"},{name:"socketClosed",from:["connecting","initialising","connected","updating","error","waitOffloadSocketClosed"],to:"retrying"},{name:"socketClosed",from:["disconnecting"],to:"disconnected"},{name:"socketClosed",from:["waitSocketClosed"],to:"disconnected"},{name:"socketClosed",from:["rejected"],to:"rejected"},{name:"initSuccess",from:["initialising"],to:"connected"},{name:"initError",from:["initialising"],to:"error"},{name:"tokenRejected",from:["initialising","updating"],to:"rejected"},{name:"protocolError",from:["initialising","connected","updating"],to:"error"},{name:"receiveClose",from:["initialising","connected","updating"],to:"waitSocketClosed"},{name:"receiveOffload",from:["initialising","connected","updating"],to:"waitOffloadSocketClosed"},{name:"unsupportedProtocol",from:["initialising","connected","updating"],to:"unsupported"},{name:"receiveFatalClose",from:["initialising","connected","updating"],to:"unsupported"},{name:"userUpdateToken",from:["disconnected","rejected","connecting","retrying"],to:"connecting"},{name:"userUpdateToken",from:["connected"],to:"updating"},{name:"updateSuccess",from:["updating"],to:"connected"},{name:"updateError",from:["updating"],to:"error"},{name:"userSend",from:["connected"],to:"connected"},{name:"systemOnline",from:["retrying"],to:"connecting"}],methods:{onConnecting:function(){i.setupSocket(),i.emit("connecting")},onEnterInitialising:function(){i.sendInit()},onLeaveInitialising:function(){i.cancelInit()},onEnterUpdating:function(){i.sendUpdate()},onLeaveUpdating:function(){i.cancelUpdate()},onEnterRetrying:function(){i.initRetry(),i.emit("connecting")},onEnterConnected:function(){i.resetBackoff(),i.onConnected()},onUserUpdateToken:function(){i.resetBackoff()},onTokenRejected:function(){i.resetBackoff(),i.closeSocket(!0),i.finalizeSocket()},onUserDisconnect:function(){i.closeSocket(!0)},onEnterDisconnecting:function(){i.startDisconnectTimer()},onLeaveDisconnecting:function(){i.cancelDisconnectTimer()},onEnterWaitSocketClosed:function(){i.startDisconnectTimer()},onLeaveWaitSocketClosed:function(){i.cancelDisconnectTimer()},onEnterWaitOffloadSocketClosed:function(){i.startDisconnectTimer()},onLeaveWaitOffloadSocketClosed:function(){i.cancelDisconnectTimer()},onDisconnected:function(){i.resetBackoff(),i.finalizeSocket()},onReceiveClose:function(e,t){i.onCloseReceived(t)},onReceiveOffload:function(e,t){b.log.debug("onreceiveoffload: ",t),i.modifyBackoff(t.body),i.onCloseReceived(t.status)},onUnsupported:function(){i.closeSocket(!0),i.finalizeSocket()},onError:function(e,t){i.closeSocket(t),i.finalizeSocket()},onEnterState:function(e){"none"!==e.from&&i.changeState(e)},onInvalidTransition:function(e,t,r){b.log.warn("FSM: unexpected transition",t,r)}}}),i}return(0,c.default)(t,e),(0,a.default)(t,[{key:"changeState",value:function(e){b.log.debug("FSM: "+e.transition+": "+e.from+" --\x3e "+e.to),this.lastEmittedState!==this.state&&(this.lastEmittedState=this.state,this.emit("stateChanged",this.state))}},{key:"resetBackoff",value:function(){b.log.trace("resetBackoff"),this.retrier.stop()}},{key:"modifyBackoff",value:function(e){b.log.trace("modifyBackoff",e);var t=e?e.backoff_policy:null;t&&"number"==typeof t.reconnect_min_ms&&this.retrier.modifyBackoff(t.reconnect_min_ms)}},{key:"startDisconnectTimer",value:function(){var e=this;b.log.trace("startDisconnectTimer"),this.disconnectingTimer&&(clearTimeout(this.disconnectingTimer),this.disconnectingTimer=null),this.disconnectingTimer=setTimeout(function(){b.log.debug("disconnecting is timed out"),e.closeSocket(!0)},3e3)}},{key:"cancelDisconnectTimer",value:function(){b.log.trace("cancelDisconnectTimer"),this.disconnectingTimer&&(clearTimeout(this.disconnectingTimer),this.disconnectingTimer=null)}},{key:"initRetry",value:function(){b.log.debug("initRetry"),this.retrier.inProgress?this.retrier.attemptFailed():this.retrier.start()}},{key:"retry",value:function(){"connecting"!=this.fsm.state?(b.log.trace("retry"),this.websocket.close(),this.fsm.userRetry()):b.log.trace("can\t retry as already connecting")}},{key:"onConnected",value:function(){this.emit("connected")}},{key:"finalizeSocket",value:function(){b.log.trace("finalizeSocket"),this.websocket.close(),this.emit("disconnected"),this.disconnectedPromiseResolve&&(this.disconnectedPromiseResolve(),this.disconnectedPromiseResolve=null)}},{key:"setupSocket",value:function(){b.log.trace("setupSocket:",this.config.token),this.websocket.connect()}},{key:"onIncomingMessage",value:function(e){var t=m.Parser.parse(e),r=t.method,n=t.header,i=t.payload;if("reply"!==r&&this.confirmReceiving(n),"notification"===r)this.emit("message",n.message_type,i);else if("reply"===n.method)this.transport.processReply({id:n.id,status:n.status,header:n,body:i});else if("client_update"===n.method)"token_about_to_expire"===n.client_update_type&&this.emit("tokenAboutToExpire");else if("close"===n.method)if(308===n.status.code)b.log.debug("Connection has been offloaded"),this.fsm.receiveOffload({status:n.status.status,body:i});else if(406===n.status.code){var s="Server closed connection because can't parse protocol: "+(0,f.default)(n.status);this.emitReplyConnectionError(s,n,!0),b.log.error(s),this.fsm.receiveFatalClose()}else 417===n.status.code?(b.log.error("Server closed connection because can't parse client reply: "+(0,f.default)(n.status)),this.fsm.receiveFatalClose(n.status.status)):410===n.status.code?(b.log.warn("Server closed connection: "+(0,f.default)(n.status)),this.fsm.receiveClose(n.status.status),this.emit("tokenExpired")):401===n.status.code?(b.log.error("Server closed connection: "+(0,f.default)(n.status)),this.fsm.receiveClose(n.status.status)):(b.log.warn("unexpected message: ",n.status),this.fsm.receiveOffload({status:n.status.status,body:null}))}},{key:"sendInit",value:function(){var e=(0,s.default)(i.default.mark(function e(){var t,r;return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return b.log.trace("sendInit"),e.prev=1,e.next=4,this.transport.sendInit();case 4:t=e.sent,this.config.updateContinuationToken(t.continuationToken),this.fsm.initSuccess(t),this.emit("initialized",t),this.emit("tokenUpdated"),e.next=15;break;case 11:e.prev=11,e.t0=e.catch(1),e.t0 instanceof y.TwilsockReplyError?(r=!1,b.log.warn("Init rejected by server: "+(0,f.default)(e.t0.reply.status)),401===e.t0.reply.status.code||403===e.t0.reply.status.code?(r=!0,this.fsm.tokenRejected(e.t0.reply.status),e.t0.reply.status.errorCode===this.tokenExpiredSasCode&&this.emit("tokenExpired")):429===e.t0.reply.status.code?(this.modifyBackoff(e.t0.reply.body),this.fsm.initError(!0)):500===e.t0.reply.status.code?this.fsm.initError(!1):this.fsm.initError(!0),this.emitReplyConnectionError(e.t0.message,e.t0.reply,r)):(this.emit("connectionError",{terminal:!0,message:e.t0.message,httpStatusCode:null,errorCode:null}),this.fsm.initError(!0)),this.emit("tokenUpdated",e.t0);case 15:case"end":return e.stop()}},e,this,[[1,11]])}));return function(){return e.apply(this,arguments)}}()},{key:"sendUpdate",value:function(){var e=(0,s.default)(i.default.mark(function e(){var t,r,n;return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return b.log.trace("sendUpdate"),t=new v.Update(this.config.token),e.prev=2,e.next=5,this.transport.sendWithReply(t);case 5:r=e.sent,this.fsm.updateSuccess(r.body),this.emit("tokenUpdated"),e.next=14;break;case 10:e.prev=10,e.t0=e.catch(2),e.t0 instanceof y.TwilsockReplyError?(n=!1,b.log.warn("Token update rejected by server: "+(0,f.default)(e.t0.reply.status)),401===e.t0.reply.status.code||403===e.t0.reply.status.code?(n=!0,this.fsm.tokenRejected(e.t0.reply.status),e.t0.reply.status.errorCode===this.tokenExpiredSasCode&&this.emit("tokenExpired")):429===e.t0.reply.status.code?(this.modifyBackoff(e.t0.reply.body),this.fsm.updateError(e.t0.reply.status)):this.fsm.updateError(e.t0.reply.status),this.emitReplyConnectionError(e.t0.message,e.t0.reply,n)):(this.emit("error",!1,e.t0.message,null,null),this.fsm.updateError(e.t0)),this.emit("tokenUpdated",e.t0);case 14:case"end":return e.stop()}},e,this,[[2,10]])}));return function(){return e.apply(this,arguments)}}()},{key:"emitReplyConnectionError",value:function(e,t,r){var n=t.status&&t.status.description?t.status.description:e,i=t.status.code,s=t.status&&t.status.errorCode?t.status.errorCode:null;this.emit("connectionError",{terminal:r,message:n,httpStatusCode:i,errorCode:s})}},{key:"cancelInit",value:function(){b.log.trace("cancelInit")}},{key:"cancelUpdate",value:function(){b.log.trace("cancelUpdate")}},{key:"confirmReceiving",value:function(e){b.log.trace("confirmReceiving");try{this.transport.send(new v.Reply(e.id))}catch(e){b.log.debug("failed to confirm packet receiving",e)}}},{key:"closeSocket",value:function(e){var t=this;b.log.trace("closeSocket (graceful: "+e+")"),e&&this.transport.isConnected&&this.transport.sendClose(),this.websocket.close(),setTimeout(function(){return t.fsm.socketClosed()},0)}},{key:"connect",value:function(){b.log.trace("connect"),this.fsm.userConnect()}},{key:"disconnect",value:function(){var e=this;return b.log.trace("disconnect"),this.fsm.is("disconnected")?n.default.resolve():new n.default(function(t){e.disconnectedPromiseResolve=t,e.fsm.userDisconnect()})}},{key:"updateToken",value:function(e){var t=this;return b.log.trace("updateToken:",e),new n.default(function(e,r){t.once("tokenUpdated",function(t){t?r(t):e()}),t.fsm.userUpdateToken()})}},{key:"onCloseReceived",value:function(e){this.websocket.close()}},{key:"isConnected",get:function(){return"connected"===this.state&&this.websocket.isConnected}},{key:"state",get:function(){switch(this.fsm.state){case"connecting":case"initialising":case"retrying":case"error":return"connecting";case"updating":case"connected":return"connected";case"rejected":return"rejected";case"disconnecting":case"waitSocketClosed":case"waitOffloadSocketClosed":return"disconnecting";case"disconnected":default:return"disconnected"}}},{key:"isTerminalState",get:function(){return-1!==this.terminalStates.indexOf(this.fsm.state)}}]),t}(p.EventEmitter);r.TwilsockChannel=_,r.TwilsockImpl=_},{"./backoffretrier":201,"./error/twilsockreplyerror":207,"./logger":210,"./parser":214,"./protocol/messages":217,"babel-runtime/core-js/json/stringify":29,"babel-runtime/core-js/object/get-prototype-of":35,"babel-runtime/core-js/promise":37,"babel-runtime/helpers/asyncToGenerator":42,"babel-runtime/helpers/classCallCheck":43,"babel-runtime/helpers/createClass":44,"babel-runtime/helpers/inherits":46,"babel-runtime/helpers/possibleConstructorReturn":47,"babel-runtime/helpers/typeof":50,"babel-runtime/regenerator":51,events:184,"javascript-state-machine":185}],227:[function(e,t,r){(function(t){"use strict";var n=u(e("babel-runtime/core-js/object/get-prototype-of")),i=u(e("babel-runtime/helpers/classCallCheck")),s=u(e("babel-runtime/helpers/createClass")),o=u(e("babel-runtime/helpers/possibleConstructorReturn")),a=u(e("babel-runtime/helpers/inherits"));function u(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var c=e("events"),l=e("./logger"),f=function(r){function u(r){(0,i.default)(this,u);var s=(0,o.default)(this,(u.__proto__||(0,n.default)(u)).call(this));return s.url=r,s.WebSocket=t.WebSocket||t.MozWebSocket||e("ws"),s}return(0,a.default)(u,r),(0,s.default)(u,[{key:"connect",value:function(){var e=this;l.log.trace("connecting to socket");var t=new this.WebSocket(this.url);t.binaryType="arraybuffer",t.onopen=function(){l.log.debug("socket opened "+e.url),e.emit("connected")},t.onclose=function(t){l.log.debug("socket closed",t),e.emit("disconnected",t)},t.onerror=function(t){l.log.debug("error:",t),e.emit("socketError",t)},t.onmessage=function(t){e.emit("message",t.data)},this.socket=t}},{key:"send",value:function(e){this.socket.send(e)}},{key:"close",value:function(){if(l.log.trace("closing socket"),this.socket){this.socket.onopen=null,this.socket.onclose=null,this.socket.onerror=null,this.socket.onmessage=null;try{this.socket.close()}finally{}}}},{key:"isConnected",get:function(){return this.socket&&1===this.socket.readyState}}]),u}(c.EventEmitter);r.WebSocketChannel=f}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./logger":210,"babel-runtime/core-js/object/get-prototype-of":35,"babel-runtime/helpers/classCallCheck":43,"babel-runtime/helpers/createClass":44,"babel-runtime/helpers/inherits":46,"babel-runtime/helpers/possibleConstructorReturn":47,events:184,ws:52}],228:[function(e,t,r){var n=e("./v1"),i=e("./v4"),s=i;s.v1=n,s.v4=i,t.exports=s},{"./v1":231,"./v4":232}],229:[function(e,t,r){for(var n=[],i=0;i<256;++i)n[i]=(i+256).toString(16).substr(1);t.exports=function(e,t){var r=t||0,i=n;return[i[e[r++]],i[e[r++]],i[e[r++]],i[e[r++]],"-",i[e[r++]],i[e[r++]],"-",i[e[r++]],i[e[r++]],"-",i[e[r++]],i[e[r++]],"-",i[e[r++]],i[e[r++]],i[e[r++]],i[e[r++]],i[e[r++]],i[e[r++]]].join("")}},{}],230:[function(e,t,r){var n="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof window.msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto);if(n){var i=new Uint8Array(16);t.exports=function(){return n(i),i}}else{var s=new Array(16);t.exports=function(){for(var e,t=0;t<16;t++)0==(3&t)&&(e=4294967296*Math.random()),s[t]=e>>>((3&t)<<3)&255;return s}}},{}],231:[function(e,t,r){var n,i,s=e("./lib/rng"),o=e("./lib/bytesToUuid"),a=0,u=0;t.exports=function(e,t,r){var c=t&&r||0,l=t||[],f=(e=e||{}).node||n,d=void 0!==e.clockseq?e.clockseq:i;if(null==f||null==d){var p=s();null==f&&(f=n=[1|p[0],p[1],p[2],p[3],p[4],p[5]]),null==d&&(d=i=16383&(p[6]<<8|p[7]))}var h=void 0!==e.msecs?e.msecs:(new Date).getTime(),b=void 0!==e.nsecs?e.nsecs:u+1,v=h-a+(b-u)/1e4;if(v<0&&void 0===e.clockseq&&(d=d+1&16383),(v<0||h>a)&&void 0===e.nsecs&&(b=0),b>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");a=h,u=b,i=d;var m=(1e4*(268435455&(h+=122192928e5))+b)%4294967296;l[c++]=m>>>24&255,l[c++]=m>>>16&255,l[c++]=m>>>8&255,l[c++]=255&m;var y=h/4294967296*1e4&268435455;l[c++]=y>>>8&255,l[c++]=255&y,l[c++]=y>>>24&15|16,l[c++]=y>>>16&255,l[c++]=d>>>8|128,l[c++]=255&d;for(var g=0;g<6;++g)l[c+g]=f[g];return t||o(l)}},{"./lib/bytesToUuid":229,"./lib/rng":230}],232:[function(e,t,r){var n=e("./lib/rng"),i=e("./lib/bytesToUuid");t.exports=function(e,t,r){var s=t&&r||0;"string"==typeof e&&(t="binary"===e?new Array(16):null,e=null);var o=(e=e||{}).random||(e.rng||n)();if(o[6]=15&o[6]|64,o[8]=63&o[8]|128,t)for(var a=0;a<16;++a)t[s+a]=o[a];return t||i(o)}},{"./lib/bytesToUuid":229,"./lib/rng":230}],233:[function(e,t,r){t.exports={name:"twilio-sync",version:"0.12.1",description:"Twilio Sync client library",main:"lib/index.js",types:"./lib/index.d.ts",author:"Twilio",license:"MIT",dependencies:{"twilio-notifications":"^0.5.8",twilsock:"^0.5.11",loglevel:"^1.6.3","operation-retrier":"^3.0.0",platform:"^1.3.5",uuid:"^3.3.2"},devDependencies:{"@types/chai":"^4.1.7","@types/chai-as-promised":"7.1.0","@types/chai-string":"^1.4.1","@types/mocha":"^5.2.7","@types/node":"^12.0.4","@types/sinon":"^7.0.12","@types/sinon-chai":"^3.2.2","async-test-tools":"^1.0.7","babel-core":"^6.26.0","babel-plugin-transform-builtin-extend":"^1.1.2","babel-plugin-transform-runtime":"^6.23.0","babel-preset-env":"^1.6.1","babel-runtime":"^6.26.0",babelify:"^8.0.0",browserify:"^16.2.3",chai:"^4.2.0","chai-as-promised":"^7.1.1","chai-string":"^1.5.0",cheerio:"^1.0.0-rc.2","cross-env":"^5.2.0",del:"^4.1.1","fancy-log":"^1.3.3",fs:"0.0.2",gulp:"^4.0.2","gulp-babel":"^7.0.1","gulp-derequire":"^2.1.0","gulp-if":"^2.0.2","gulp-insert":"^0.5.0","gulp-rename":"^1.4.0","gulp-sourcemaps":"^2.6.5","gulp-tap":"^1.0.1","gulp-tslint":"^8.1.4","gulp-typescript":"^5.0.1","gulp-uglify-es":"^1.0.4","ink-docstrap":"^1.3.2",jsdoc:"~3.5.5",jsonwebtoken:"^8.5.1",karma:"^4.1.0","karma-browserify":"^6.0.0","karma-browserstack-launcher":"^1.5.1","karma-mocha":"^1.3.0","karma-mocha-reporter":"^2.2.5",mocha:"^6.1.4",nyc:"^14.1.1",path:"^0.12.7",sinon:"^7.3.2","sinon-chai":"^3.3.0","source-map-explorer":"^1.8.0","ts-node":"^8.2.0",tslint:"^5.17.0",twilio:"^3.31.1",typescript:"^3.5.1","uglify-es":"^3.3.10","uglify-save-license":"^0.4.1",underscore:"^1.9.1","vinyl-buffer":"^1.0.1","vinyl-source-stream":"^2.0.0",watchify:"^3.11.1"},browserify:{transform:["babelify"]},engines:{node:">=8"}}},{}]},{},[2])(2)});