/* twilio-chat.js 1.0.1 The following license applies to all parts of this software except as documented below. Copyright (c) 2017, 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 javascript-state-machine under the following license. Copyright (c) 2012, 2013, 2014, 2015, Jake Gordon and 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 This software includes durational under the following license. Copyright (c) 2014 Micheil Smith 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 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 q under the following license. Copyright 2009–2014 Kristopher Michael Kowal. All rights reserved. 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 platform.js under the following license. Copyright 2014 Benjamin Tan Copyright 2011-2015 John-David Dalton 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. */ !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,(t.Twilio||(t.Twilio={})).Chat=e()}}(function(){var e,t,n;return function e(t,n,r){function i(s,a){if(!n[s]){if(!t[s]){var u="function"==typeof require&&require;if(!a&&u)return u(s,!0);if(o)return o(s,!0);var c=new Error("Cannot find module '"+s+"'");throw c.code="MODULE_NOT_FOUND",c}var l=n[s]={exports:{}};t[s][0].call(l.exports,function(e){var n=t[s][1][e];return i(n||e)},l,l.exports,e,t,n,r)}return n[s].exports}for(var o="function"==typeof require&&require,s=0;sidentity parameter");case 2:return t.abrupt("return",this.membersEntity.add(e));case 3:case"end":return t.stop()}},t,this)}))}},{key:"advanceLastConsumedMessageIndex",value:function(e){return T(this,void 0,void 0,c.default.mark(function t(){return c.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if((0,m.default)(e)){t.next=2;break}throw new Error("Channel.advanceLastConsumedMessageIndex requires an integral index parameter");case 2:if(!(null!==this.lastConsumedMessageIndex&&e<=this.lastConsumedMessageIndex)){t.next=4;break}return t.abrupt("return");case 4:return t.next=6,this._subscribeStreams();case 6:return this.services.consumptionHorizon.advanceLastConsumedMessageIndexForChannel(this.sid,e),t.abrupt("return",this);case 8:case"end":return t.stop()}},t,this)}))}},{key:"decline",value:function(){return T(this,void 0,void 0,c.default.mark(function e(){return c.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.session.addCommand("declineInvitation",{channelSid:this.sid});case 2:return e.abrupt("return",this);case 3:case"end":return e.stop()}},e,this)}))}},{key:"delete",value:function(){return T(this,void 0,void 0,c.default.mark(function e(){return c.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.session.addCommand("destroyChannel",{channelSid:this.sid});case 2:return e.abrupt("return",this);case 3:case"end":return e.stop()}},e,this)}))}},{key:"getAttributes",value:function(){return T(this,void 0,void 0,c.default.mark(function e(){return c.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._subscribe();case 2:return e.abrupt("return",this.attributes);case 3:case"end":return e.stop()}},e,this)}))}},{key:"getMessages",value:function(e,t,n){return T(this,void 0,void 0,c.default.mark(function r(){return c.default.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(void 0===t||(0,m.default)(t)){r.next=2;break}throw new Error("Anchor should be a valid message index");case 2:return r.next=4,this._subscribeStreams();case 4:return r.abrupt("return",this.messagesEntity.getMessages(e,t,n));case 5:case"end":return r.stop()}},r,this)}))}},{key:"getMembers",value:function(){return T(this,void 0,void 0,c.default.mark(function e(){return c.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._subscribeStreams();case 2:return e.abrupt("return",this.membersEntity.getMembers());case 3:case"end":return e.stop()}},e,this)}))}},{key:"getMembersCount",value:function(){return T(this,void 0,void 0,c.default.mark(function e(){var t,n,r;return c.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.session.getSessionLinks();case 2:return t=e.sent,n=new M.UriBuilder(t.publicChannelsUrl).path(this.sid).build(),e.next=6,this.services.network.get(n);case 6:return r=e.sent,e.abrupt("return",r.body.members_count);case 8:case"end":return e.stop()}},e,this)}))}},{key:"getMessagesCount",value:function(){return T(this,void 0,void 0,c.default.mark(function e(){var t,n,r;return c.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.session.getSessionLinks();case 2:return t=e.sent,n=new M.UriBuilder(t.publicChannelsUrl).path(this.sid).build(),e.next=6,this.services.network.get(n);case 6:return r=e.sent,e.abrupt("return",r.body.messages_count);case 8:case"end":return e.stop()}},e,this)}))}},{key:"getUnconsumedMessagesCount",value:function(){return T(this,void 0,void 0,c.default.mark(function e(){var t,n,r;return c.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.session.getSessionLinks();case 2:return t=e.sent,n=new M.UriBuilder(t.myChannelsUrl).arg("ChannelSid",this.sid).build(),e.next=6,this.services.network.get(n);case 6:if(r=e.sent,!r.body.channels.length){e.next=9;break}return e.abrupt("return",r.body.channels[0].unread_messages_count||0);case 9:throw new Error("Channel is not in user channels list");case 10:case"end":return e.stop()}},e,this)}))}},{key:"invite",value:function(e){return T(this,void 0,void 0,c.default.mark(function t(){return c.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if("string"==typeof e&&e.length){t.next=2;break}throw new Error("Channel.invite requires an identity parameter");case 2:return t.abrupt("return",this.membersEntity.invite(e));case 3:case"end":return t.stop()}},t,this)}))}},{key:"join",value:function(){return T(this,void 0,void 0,c.default.mark(function e(){return c.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.session.addCommand("joinChannel",{channelSid:this.sid});case 2:return e.abrupt("return",this);case 3:case"end":return e.stop()}},e,this)}))}},{key:"leave",value:function(){return T(this,void 0,void 0,c.default.mark(function e(){return c.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if("joined"!==this.state.status){e.next=3;break}return e.next=3,this.services.session.addCommand("leaveChannel",{channelSid:this.sid});case 3:return e.abrupt("return",this);case 4:case"end":return e.stop()}},e,this)}))}},{key:"removeMember",value:function(e){return T(this,void 0,void 0,c.default.mark(function t(){return c.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(e&&("string"==typeof e||e instanceof P.Member)){t.next=2;break}throw new Error("Channel.removeMember requires a member parameter.");case 2:return t.abrupt("return",this.membersEntity.remove("string"==typeof e?e:e.identity));case 3:case"end":return t.stop()}},t,this)}))}},{key:"sendMessage",value:function(e,t){return T(this,void 0,void 0,c.default.mark(function n(){var r;return c.default.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return n.next=2,this.messagesEntity.send(e,t);case 2:return r=n.sent,n.abrupt("return",r.messageId);case 4:case"end":return n.stop()}},n,this)}))}},{key:"setAllMessagesConsumed",value:function(){return T(this,void 0,void 0,c.default.mark(function e(){var t;return c.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._subscribeStreams();case 2:return e.next=4,this.getMessages(1);case 4:if(t=e.sent,!(t.items.length>0)){e.next=8;break}return e.next=8,this.advanceLastConsumedMessageIndex(t.items[0].index);case 8:return e.abrupt("return",this);case 9:case"end":return e.stop()}},e,this)}))}},{key:"setNoMessagesConsumed",value:function(){return T(this,void 0,void 0,c.default.mark(function e(){return c.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._subscribeStreams();case 2:return this.services.consumptionHorizon.updateLastConsumedMessageIndexForChannel(this.sid,null),e.abrupt("return",this);case 4:case"end":return e.stop()}},e,this)}))}},{key:"typing",value:function(){return this.services.typingIndicator.send(this.sid)}},{key:"updateAttributes",value:function(e){return T(this,void 0,void 0,c.default.mark(function t(){return c.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(e){t.next=4;break}throw new Error("Attributes can't be null");case 4:if(e.constructor===Object){t.next=6;break}throw new Error("Attributes must be a valid JSON object.");case 6:return t.next=8,this.services.session.addCommand("editAttributes",{channelSid:this.sid,attributes:(0,d.default)(e)});case 8:return t.abrupt("return",this);case 9:case"end":return t.stop()}},t,this)}))}},{key:"updateFriendlyName",value:function(e){return T(this,void 0,void 0,c.default.mark(function t(){return c.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(this.state.friendlyName===e){t.next=3;break}return t.next=3,this.services.session.addCommand("editFriendlyName",{channelSid:this.sid,friendlyName:e});case 3:return t.abrupt("return",this);case 4:case"end":return t.stop()}},t,this)}))}},{key:"updateLastConsumedMessageIndex",value:function(e){return T(this,void 0,void 0,c.default.mark(function t(){return c.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if((0,m.default)(e)||null===e){t.next=2;break}throw new Error('Incorrect argument "index": integer number or null expected');case 2:return t.next=4,this._subscribeStreams();case 4:return this.services.consumptionHorizon.updateLastConsumedMessageIndexForChannel(this.sid,e),t.abrupt("return",this);case 6:case"end":return t.stop()}},t,this)}))}},{key:"updateUniqueName",value:function(e){return T(this,void 0,void 0,c.default.mark(function t(){return c.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(this.state.uniqueName===e){t.next=3;break}return t.next=3,this.services.session.addCommand("editUniqueName",{channelSid:this.sid,uniqueName:e});case 3:return t.abrupt("return",this);case 4:case"end":return t.stop()}},t,this)}))}},{key:"getUserDescriptors",value:function(){return T(this,void 0,void 0,c.default.mark(function e(){return c.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.services.users.getChannelUserDescriptors(this.sid));case 1:case"end":return e.stop()}},e,this)}))}},{key:"session",get:function(){return this.services.session}},{key:"status",get:function(){return this.state.status}},{key:"type",get:function(){return this.state.type}},{key:"uniqueName",get:function(){return this.state.uniqueName}},{key:"isPrivate",get:function(){return"private"===this.state.type}},{key:"friendlyName",get:function(){return this.state.friendlyName}},{key:"dateUpdated",get:function(){return this.state.dateUpdated}},{key:"dateCreated",get:function(){return this.state.dateCreated}},{key:"createdBy",get:function(){return this.state.createdBy}},{key:"attributes",get:function(){return this.state.attributes}},{key:"lastConsumedMessageIndex",get:function(){return this.state.lastConsumedMessageIndex}}],[{key:"preprocessUpdate",value:function(e,t){try{"string"==typeof e.attributes?e.attributes=JSON.parse(e.attributes):e.attributes&&(0,d.default)(e.attributes)}catch(n){N.warn("Retrieved malformed attributes from the server for channel: "+t),e.attributes={}}try{e.dateCreated&&(e.dateCreated=new Date(e.dateCreated))}catch(n){N.warn("Retrieved malformed attributes from the server for channel: "+t),delete e.dateCreated}try{e.dateUpdated&&(e.dateUpdated=new Date(e.dateUpdated))}catch(n){N.warn("Retrieved malformed attributes from the server for channel: "+t),delete e.dateUpdated}}}]),t}(R.EventEmitter);n.Channel=U},{"./data/members":6,"./data/messages":7,"./logger":14,"./member":15,"./util/index":28,"babel-runtime/core-js/get-iterator":30,"babel-runtime/core-js/json/stringify":32,"babel-runtime/core-js/map":33,"babel-runtime/core-js/number/is-integer":34,"babel-runtime/core-js/object/get-prototype-of":40,"babel-runtime/core-js/promise":43,"babel-runtime/helpers/classCallCheck":48,"babel-runtime/helpers/createClass":49,"babel-runtime/helpers/inherits":51,"babel-runtime/helpers/possibleConstructorReturn":52,"babel-runtime/regenerator":55,events:201}],2:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function i(e){try{return JSON.parse(e)}catch(e){f.warn("Failed to parse channel attributes",e)}return{}}function o(e){try{return new Date(e)}catch(e){return null}}var s=e("babel-runtime/helpers/classCallCheck"),a=r(s),u=e("babel-runtime/helpers/createClass"),c=r(u);Object.defineProperty(n,"__esModule",{value:!0});var l=e("./logger"),f=new l.Logger,h=function(){function e(t,n){(0,a.default)(this,e),this.client=t,this.descriptor=n,n.sid?(this.sid=n.sid,this.channel=n.sid+".channel"):(this.sid=n.channel_sid,this.channel=n.channel_sid+".channel"),this.uniqueName=n.unique_name,this.friendlyName=n.friendly_name,this.attributes=i(n.attributes),this.createdBy=n.created_by,this.dateCreated=o(n.date_created),this.dateUpdated=o(n.date_updated),this.messagesCount=n.messages_count,this.membersCount=n.members_count,this.type=n.type,this.isPrivate="private"==n.type,this.lastConsumedMessageIndex=n.last_consumed_message_index,n.status?this.status=n.status:this.status="unknown"}return(0,c.default)(e,[{key:"getChannel",value:function(){return this.client.getChannelBySid(this.sid)}}]),e}();n.ChannelDescriptor=h},{"./logger":14,"babel-runtime/helpers/classCallCheck":48,"babel-runtime/helpers/createClass":49}],3:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}var i=e("babel-runtime/regenerator"),o=r(i),s=e("babel-runtime/core-js/object/get-prototype-of"),a=r(s),u=e("babel-runtime/helpers/classCallCheck"),c=r(u),l=e("babel-runtime/helpers/createClass"),f=r(l),h=e("babel-runtime/helpers/possibleConstructorReturn"),d=r(h),p=e("babel-runtime/helpers/inherits"),m=r(p),v=e("babel-runtime/core-js/promise"),b=r(v),y=function(e,t,n,r){return new(n||(n=b.default))(function(i,o){function s(e){try{u(r.next(e))}catch(e){o(e)}}function a(e){try{u(r.throw(e))}catch(e){o(e)}}function u(e){e.done?i(e.value):new n(function(t){t(e.value)}).then(s,a)}u((r=r.apply(e,t||[])).next())})};Object.defineProperty(n,"__esModule",{value:!0});var _=e("events"),g=e("./logger"),k=e("./configuration"),w=e("./user");n.User=w.User;var C=e("./data/publicchannels"),x=e("./services/network"),j=e("./interfaces/notificationtypes"),E=e("./synclist"),S=g.Logger.scope(""),T=e("twilsock"),R=e("twilio-notifications"),A=e("twilio-transport"),I=e("twilio-sync"),P=e("twilio-ems-client"),O=e("./session"),M=e("./data/channels"),N=e("./data/users"),F=e("./services/typingindicator"),U=e("./services/consumptionhorizon"),D=e("./data/userchannels"),L=e("./../package.json").version,B="A valid Twilio token should be provided",q=function(e){function t(e,n){(0,c.default)(this,t);var r=(0,d.default)(this,(t.__proto__||(0,a.default)(t)).call(this));if(r.connectionState="connecting",r.initializePromise=null,r.sessionPromise=null,r.channelsPromise=null,r.publicChannels=null,r.userChannels=null,r.options=n||{},r.options.logLevel=r.options.logLevel||"error",r.options.productId="ip_messaging",r.options.Sync=r.options.Sync||{},r.options.Sync.enableSessionStorage||(r.options.Sync.enableSessionStorage=!1),!e)throw new Error(B);return S.setLevel(r.options.logLevel),r.config=new k.Configuration(null,r.options),r.options.twilsockClient=r.options.twilsockClient||new T(e,r.options),r.options.transport=r.options.transport||new A.Transport(r.options.twilsockClient,r.options),r.options.emsClient=r.options.emsClient||new P.EmsClient(r.options),r.options.notificationsClient=r.options.notificationsClient||new R(e,r.options),r.options.syncClient=r.options.syncClient||new I.SyncClient(e,r.options),r.emsClient=r.options.emsClient,r.datasync=r.options.syncClient,r.transport=r.options.transport,r.twilsock=r.options.twilsockClient,r.notifications=r.options.notificationsClient,r.session=new O.Session(r.datasync,r.transport,r.config),r.sessionPromise=r.session.initialize(e),r.network=new x.Network(r.config,r.session,r.transport),r.users=new N.Users(r.session,r.datasync,{config:r.config,network:r.network}),r.users.on("userSubscribed",r.emit.bind(r,"userSubscribed")),r.users.on("userUpdated",r.emit.bind(r,"userUpdated")),r.users.on("userUnsubscribed",r.emit.bind(r,"userUnsubscribed")),r.consumptionHorizon=new U.ConsumptionHorizon(r.config,r.session),r.typingIndicator=new F.TypingIndicator(r.config,r.transport,r.notifications,r.getChannelBySid.bind(r)),r.syncList=new E.SyncList(r.network,r.session),r.channels=new M.Channels({session:r.session,users:r.users,typingIndicator:r.typingIndicator,consumptionHorizon:r.consumptionHorizon,network:r.network,config:r.config,syncList:r.syncList}),r.channelsPromise=r.sessionPromise.then(function(){return r.channels.on("channelAdded",r.emit.bind(r,"channelAdded")),r.channels.on("channelRemoved",r.emit.bind(r,"channelRemoved")),r.channels.on("channelInvited",r.emit.bind(r,"channelInvited")),r.channels.on("channelJoined",r.emit.bind(r,"channelJoined")),r.channels.on("channelLeft",r.emit.bind(r,"channelLeft")),r.channels.on("channelUpdated",r.emit.bind(r,"channelUpdated")),r.channels.on("memberJoined",r.emit.bind(r,"memberJoined")),r.channels.on("memberLeft",r.emit.bind(r,"memberLeft")),r.channels.on("memberUpdated",r.emit.bind(r,"memberUpdated")),r.channels.on("messageAdded",r.emit.bind(r,"messageAdded")),r.channels.on("messageUpdated",r.emit.bind(r,"messageUpdated")),r.channels.on("messageRemoved",r.emit.bind(r,"messageRemoved")),r.channels.on("typingStarted",r.emit.bind(r,"typingStarted")),r.channels.on("typingEnded",r.emit.bind(r,"typingEnded")),r.channels.fetchChannels()}).then(function(){return r.channels}),r.notifications.on("transportReady",function(e){if(e)r.connectionState="connected",r.session.syncToken().catch(function(e){S.error("Failed to sync session token",e)});else switch(r.twilsock.state){case"rejected":r.connectionState="denied";break;default:r.connectionState="connecting"}r.emit("connectionStateChanged",r.connectionState)}),r.fpaToken=e,r.initializePromise=r._initialize(),r}return(0,m.default)(t,e),(0,f.default)(t,[{key:"_initialize",value:function(){return y(this,void 0,void 0,o.default.mark(function e(){var n,r,i=this;return o.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.emsClient.setToken(this.fpaToken);case 2:return n=e.sent,this.config.updateToken(n.token),e.next=6,this.sessionPromise;case 6:return t.supportedPushChannels.forEach(function(e){return i.subscribeToPushNotifications(e)}),e.next=9,this.session.getSessionLinks();case 9:return r=e.sent,this.publicChannels=new C.PublicChannels(this.config,this,this.network,r.publicChannelsUrl),this.userChannels=new D.UserChannels(this.config,this,this.network,r.myChannelsUrl),e.next=14,this.typingIndicator.initialize();case 14:case"end":return e.stop()}},e,this)}))}},{key:"subscribeToPushNotifications",value:function(e){var t=this;[j.NotificationTypes.NEW_MESSAGE,j.NotificationTypes.ADDED_TO_CHANNEL,j.NotificationTypes.INVITED_TO_CHANNEL,j.NotificationTypes.REMOVED_FROM_CHANNEL,j.NotificationTypes.TYPING_INDICATOR,j.NotificationTypes.CONSUMPTION_UPDATE].forEach(function(n){t.notifications.subscribe(n,e)})}},{key:"initialize",value:function(){var e=this;return this.initializePromise.then(function(){return e})}},{key:"shutdown",value:function(){return this.twilsock.disconnect()}},{key:"updateToken",value:function(e){return y(this,void 0,void 0,o.default.mark(function t(){var n=this;return o.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(S.info("updateToken"),e){t.next=3;break}throw new Error(B);case 3:if(e!==this.fpaToken){t.next=5;break}return t.abrupt("return",this);case 5:return t.abrupt("return",this.emsClient.setToken(e).then(function(e){if("NEW"===e.status)throw S.error("Can't extend token:",e.reason),new Error("Can't extend token:"+e.reason);return e.token}).then(function(t){return n.twilsock.updateToken(e).then(function(){return n.datasync.updateToken(e)}).then(function(){return n.notifications.updateToken(e)}).then(function(){return n.sessionPromise}).then(function(){return n.session.updateToken(t)}).then(function(){return t})}).then(function(t){return n.config.updateToken(t),n.fpaToken=e,n}));case 6:case"end":return t.stop()}},t,this)}))}},{key:"getChannelBySid",value:function(e){return y(this,void 0,void 0,o.default.mark(function t(){var n=this;return o.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(e&&"string"==typeof e){t.next=2;break}throw new Error("Client.getChannelBySid requires a channelSid parameter");case 2:return t.abrupt("return",this.channels.getChannel(e).then(function(t){return t||n.publicChannels.getChannelBySid(e).then(function(e){return n.channels.pushChannel(e)})}));case 3:case"end":return t.stop()}},t,this)}))}},{key:"getChannelByUniqueName",value:function(e){return y(this,void 0,void 0,o.default.mark(function t(){var n=this;return o.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(e&&"string"==typeof e){t.next=2;break}throw new Error("Client.getChannelByUniqueName requires a uniqueName parameter");case 2:return t.abrupt("return",this.publicChannels.getChannelByUniqueName(e).then(function(e){return n.channels.pushChannel(e)}));case 3:case"end":return t.stop()}},t,this)}))}},{key:"getSubscribedChannels",value:function(e){return this.channelsPromise.then(function(t){return t.getChannels(e)})}},{key:"getPublicChannelDescriptors",value:function(){return this.publicChannels.getChannels()}},{key:"getUserChannelDescriptors",value:function(){return this.userChannels.getChannels()}},{key:"createChannel",value:function(e){return e=e||{},this.channelsPromise.then(function(t){return t.addChannel(e)})}},{key:"setPushRegistrationId",value:function(e,n){if(-1===t.supportedPushChannels.indexOf(e))throw new Error("Invalid or unsupported channelType: "+e);this.notifications.setPushRegistrationId(n,e)}},{key:"handlePushNotification",value:function(e){return y(this,void 0,void 0,o.default.mark(function t(){var n;return o.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(S.trace("handlePushNotification, notificationPayload=",e),void 0!==e){t.next=3;break}throw new Error("Push notification payload should be provided");case 3:if(void 0!==(n=e.data)){t.next=6;break}throw new Error("Can't extract data from push payload");case 6:t.t0=n.twi_message_type,t.next=t.t0===j.NotificationTypes.NEW_MESSAGE?9:13;break;case 9:return S.trace("new message notification"),t.next=12,this.getChannelBySid(n.channel_sid).then(function(e){return e.getMessages(30)});case 12:return t.abrupt("break",13);case 13:case"end":return t.stop()}},t,this)}))}},{key:"getUser",value:function(e){return this.users.getUser(e)}},{key:"getUserDescriptor",value:function(e){return y(this,void 0,void 0,o.default.mark(function t(){return o.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",this.users.getUserDescriptor(e));case 1:case"end":return t.stop()}},t,this)}))}},{key:"getSubscribedUsers",value:function(){return y(this,void 0,void 0,o.default.mark(function e(){return o.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.users.getSubscribedUsers());case 1:case"end":return e.stop()}},e,this)}))}},{key:"user",get:function(){return this.users.myself}},{key:"reachabilityEnabled",get:function(){return this.session.reachabilityEnabled}},{key:"token",get:function(){return this.config.token}}],[{key:"create",value:function(e,n){return y(this,void 0,void 0,o.default.mark(function r(){var i;return o.default.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return i=new t(e,n),r.next=3,i.initialize();case 3:return r.abrupt("return",i);case 4:case"end":return r.stop()}},r,this)}))}}]),t}(_.EventEmitter);q.version=L,q.supportedPushChannels=["fcm","apn","gcm"],n.Client=q,n.default=q},{"./../package.json":269,"./configuration":4,"./data/channels":5,"./data/publicchannels":8,"./data/userchannels":9,"./data/users":11,"./interfaces/notificationtypes":12,"./logger":14,"./services/consumptionhorizon":18,"./services/network":19,"./services/typingindicator":20,"./session":21,"./synclist":23,"./user":25,"babel-runtime/core-js/object/get-prototype-of":40,"babel-runtime/core-js/promise":43,"babel-runtime/helpers/classCallCheck":48,"babel-runtime/helpers/createClass":49,"babel-runtime/helpers/inherits":51,"babel-runtime/helpers/possibleConstructorReturn":52,"babel-runtime/regenerator":55,events:201,"twilio-ems-client":215,"twilio-notifications":221,"twilio-sync":232,"twilio-transport":251,twilsock:254}],4:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}var i=e("babel-runtime/helpers/classCallCheck"),o=r(i),s=e("babel-runtime/helpers/createClass"),a=r(s);Object.defineProperty(n,"__esModule",{value:!0});var u="https://aim.twilio.com",c=function(){function e(t,n){(0,o.default)(this,e),n=n||{},this.options=n.Chat||n.IPMessaging||n||{};var r=this.options.apiUri||this.options.typingUri||u;this.token=t,this.baseUrl=r}return(0,a.default)(e,[{key:"updateToken",value:function(e){this.token=e}},{key:"typingIndicatorUri",get:function(){return this.baseUrl+"/v1/typing"}},{key:"typingIndicatorTimeoutDefault",get:function(){return 5e3}},{key:"httpCacheLifetimeDefault",get:function(){return 1e4}},{key:"consumptionReportIntervalDefault",get:function(){return"PT5S"}},{key:"userInfosToSubscribeDefault",get:function(){return 100}},{key:"typingIndicatorTimeoutOverride",get:function(){return this.options.typingIndicatorTimeoutOverride}},{key:"httpCacheLifetimeOverride",get:function(){return this.options.httpCacheLifetimeOverride}},{key:"consumptionReportIntervalOverride",get:function(){return this.options.consumptionReportIntervalOverride}},{key:"userInfosToSubscribeOverride",get:function(){return this.options.userInfosToSubscribeOverride}}]),e}();n.Configuration=c},{"babel-runtime/helpers/classCallCheck":48,"babel-runtime/helpers/createClass":49}],5:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}var i=e("babel-runtime/regenerator"),o=r(i),s=e("babel-runtime/core-js/json/stringify"),a=r(s),u=e("babel-runtime/core-js/set"),c=r(u),l=e("babel-runtime/core-js/map"),f=r(l),h=e("babel-runtime/core-js/object/get-prototype-of"),d=r(h),p=e("babel-runtime/helpers/classCallCheck"),m=r(p),v=e("babel-runtime/helpers/createClass"),b=r(v),y=e("babel-runtime/helpers/possibleConstructorReturn"),_=r(y),g=e("babel-runtime/helpers/inherits"),k=r(g),w=e("babel-runtime/core-js/promise"),C=r(w),x=function(e,t,n,r){return new(n||(n=C.default))(function(i,o){function s(e){try{u(r.next(e))}catch(e){o(e)}}function a(e){try{u(r.throw(e))}catch(e){o(e)}}function u(e){e.done?i(e.value):new n(function(t){t(e.value)}).then(s,a)}u((r=r.apply(e,t||[])).next())})};Object.defineProperty(n,"__esModule",{ value:!0});var j=e("events"),E=e("../logger"),S=e("../channel");n.Channel=S.Channel;var T=E.Logger.scope(""),R=function(e){function t(e){(0,m.default)(this,t);var n=(0,_.default)(this,(t.__proto__||(0,d.default)(t)).call(this));return n.services=e,n.channels=new f.default,n.thumbstones=new c.default,n.syncListFetched=!1,n}return(0,k.default)(t,e),(0,b.default)(t,[{key:"getMap",value:function(){var e=this;return this.services.session.getMyChannelsId().then(function(t){return e.services.session.datasync.map({uniqueName:t,mode:"open"})})}},{key:"addChannel",value:function(e){return x(this,void 0,void 0,o.default.mark(function t(){var n,r,i;return o.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.services.session.addCommand("createChannel",{friendlyName:e.friendlyName,uniqueName:e.uniqueName,type:e.isPrivate?"private":"public",attributes:(0,a.default)(e.attributes)});case 2:if(n=t.sent,!(r=this.channels.get(n.channelSid))){t.next=8;break}return t.next=7,r._subscribe();case 7:return t.abrupt("return",r);case 8:return i=new S.Channel(this.services,{channel:n.channel,name:null,entityName:null,uniqueName:null,attributes:null,createdBy:null,friendlyName:null,lastConsumedMessageIndex:null,type:e.isPrivate?"private":"public",dateCreated:null,dateUpdated:null},n.channelSid),this.channels.set(i.sid,i),this.registerForEvents(i),t.next=13,i._subscribe();case 13:return this.emit("channelAdded",i),t.abrupt("return",i);case 15:case"end":return t.stop()}},t,this)}))}},{key:"fetchChannels",value:function(){var e=this;this.getMap().then(function(t){return x(e,void 0,void 0,o.default.mark(function e(){var n,r,i,s=this;return o.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t.on("itemAdded",function(e){s.upsertChannel("sync",e.key,e.value)}),t.on("itemRemoved",function(e){s.syncListFetched||s.thumbstones.add(e);var t=s.channels.get(e);t&&("joined"!==t.status&&"invited"!==t.status||(t._setStatus("known"),s.emit("channelLeft",t)),t.isPrivate&&(s.channels.delete(e),s.emit("channelRemoved",t)))}),t.on("itemUpdated",function(e){s.upsertChannel("sync",e.key,e.value)}),n=[],e.next=6,this.services.syncList.getPage();case 6:r=e.sent,i=r.items,i.forEach(function(e){n.push(s.upsertChannel("chat",e.channel_sid,e.descriptor))});case 9:if(!r.hasNextPage){e.next=16;break}return e.next=12,r.nextPage();case 12:r=e.sent,r.items.forEach(function(e){n.push(s.upsertChannel("chat",e.channel_sid,e.descriptor))}),e.next=9;break;case 16:return e.abrupt("return",C.default.all(n));case 17:case"end":return e.stop()}},e,this)}))}).then(function(){e.syncListFetched=!0,e.thumbstones.clear(),T.debug("Channels list fetched")}).then(function(){return e}).catch(function(e){throw T.error("Failed to get channels list",e),e})}},{key:"_wrapPaginator",value:function(e,t){var n=this;return t(e.items).then(function(r){return{items:r,hasNextPage:e.hasNextPage,hasPrevPage:e.hasPrevPage,nextPage:function(){return e.nextPage().then(function(e){return n._wrapPaginator(e,t)})},prevPage:function(){return e.prevPage().then(function(e){return n._wrapPaginator(e,t)})}}})}},{key:"getChannels",value:function(e){var t=this;return this.getMap().then(function(t){return t.getItems(e)}).then(function(e){return t._wrapPaginator(e,function(e){return C.default.all(e.map(function(e){return t.upsertChannel("sync",e.key,e.value)}))})})}},{key:"getChannel",value:function(e){var t=this;return this.getMap().then(function(t){return t.getItems({key:e})}).then(function(e){return e.items.map(function(e){return t.upsertChannel("sync",e.key,e.value)})}).then(function(e){return e.length>0?e[0]:null})}},{key:"pushChannel",value:function(e){var t=e.sid,n={name:null,entityName:null,lastConsumedMessageIndex:e.lastConsumedMessageIndex,type:e.type,status:e.status,friendlyName:e.friendlyName,dateUpdated:e.dateUpdated,dateCreated:e.dateCreated,uniqueName:e.uniqueName,createdBy:e.createdBy,attributes:e.attributes,channel:e.channel,sid:t},r=this.channels.get(e.sid);return r||(r=new S.Channel(this.services,n,t),this.registerForEvents(r),this.channels.set(t,r)),r}},{key:"upsertChannel",value:function(e,t,n){var r=this;T.trace("upsertChannel(sid="+t+", data=",n);var i=this.channels.get(t);return i?(T.trace("upsertChannel: channel is known",i),"chat"===e?(T.trace("upsertChannel: channel is known and came from chat, ignoring",t),i._subscribe().then(function(){return i})):("joined"===n.status&&"joined"!==i.status?(i._setStatus("joined"),void 0!==n.lastConsumedMessageIndex&&i._update({lastConsumedMessageIndex:n.lastConsumedMessageIndex}),i._subscribe().then(function(){r.emit("channelJoined",i)})):"invited"===n.status&&"invited"!==i.status?(i._setStatus("invited"),i._subscribe().then(function(){r.emit("channelInvited",i)})):"known"!==n.status||"invited"!==i.status&&"joined"!==i.status?"notParticipating"===n.status&&"private"===n.type?i._subscribe():i._update(n):(i._setStatus("known"),i._update(n),i._subscribe().then(function(){r.emit("channelLeft",i)})),i._subscribe().then(function(){return i}))):"chat"===e&&this.thumbstones.has(t)?void T.trace("upsertChannel: channel is deleted and came again from chat, ignoring",t):(T.trace("upsertChannel: creating local channel object",t),i=new S.Channel(this.services,n,t),this.registerForEvents(i),this.channels.set(t,i),i._subscribe().then(function(){return"joined"===n.status?(i._setStatus("joined"),r.emit("channelJoined",i)):"invited"===n.status&&(i._setStatus("invited"),r.emit("channelInvited",i)),r.emit("channelAdded",i),i}))}},{key:"onChannelRemoved",value:function(e){var t=this.channels.get(e);t&&(this.channels.delete(e),this.emit("channelRemoved",t))}},{key:"registerForEvents",value:function(e){var t=this;e.on("removed",function(){return t.onChannelRemoved(e.sid)}),e.on("updated",function(){return t.emit("channelUpdated",e)}),e.on("memberJoined",this.emit.bind(this,"memberJoined")),e.on("memberLeft",this.emit.bind(this,"memberLeft")),e.on("memberUpdated",this.emit.bind(this,"memberUpdated")),e.on("messageAdded",this.emit.bind(this,"messageAdded")),e.on("messageUpdated",this.emit.bind(this,"messageUpdated")),e.on("messageRemoved",this.emit.bind(this,"messageRemoved")),e.on("typingStarted",this.emit.bind(this,"typingStarted")),e.on("typingEnded",this.emit.bind(this,"typingEnded"))}}]),t}(j.EventEmitter);n.Channels=R},{"../channel":1,"../logger":14,"babel-runtime/core-js/json/stringify":32,"babel-runtime/core-js/map":33,"babel-runtime/core-js/object/get-prototype-of":40,"babel-runtime/core-js/promise":43,"babel-runtime/core-js/set":45,"babel-runtime/helpers/classCallCheck":48,"babel-runtime/helpers/createClass":49,"babel-runtime/helpers/inherits":51,"babel-runtime/helpers/possibleConstructorReturn":52,"babel-runtime/regenerator":55,events:201}],6:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}var i=e("babel-runtime/regenerator"),o=r(i),s=e("babel-runtime/core-js/object/get-prototype-of"),a=r(s),u=e("babel-runtime/helpers/classCallCheck"),c=r(u),l=e("babel-runtime/helpers/createClass"),f=r(l),h=e("babel-runtime/helpers/possibleConstructorReturn"),d=r(h),p=e("babel-runtime/helpers/inherits"),m=r(p),v=e("babel-runtime/core-js/promise"),b=r(v),y=function(e,t,n,r){return new(n||(n=b.default))(function(i,o){function s(e){try{u(r.next(e))}catch(e){o(e)}}function a(e){try{u(r.throw(e))}catch(e){o(e)}}function u(e){e.done?i(e.value):new n(function(t){t(e.value)}).then(s,a)}u((r=r.apply(e,t||[])).next())})};Object.defineProperty(n,"__esModule",{value:!0});var _=e("events"),g=e("../member"),k=e("../logger"),w=k.Logger.scope("Members"),C=function(e){function t(e,n,r,i){(0,c.default)(this,t);var o=(0,d.default)(this,(t.__proto__||(0,a.default)(t)).call(this));return o.users=e,o.channel=n,o.session=r,o.members=i,o.sync=r.datasync,o}return(0,m.default)(t,e),(0,f.default)(t,[{key:"unsubscribe",value:function(){return y(this,void 0,void 0,o.default.mark(function e(){var t;return o.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.rosterEntityPromise){e.next=6;break}return e.next=3,this.rosterEntityPromise;case 3:t=e.sent,t.close(),this.rosterEntityPromise=null;case 6:case"end":return e.stop()}},e,this)}))}},{key:"subscribe",value:function(e){var t=this;return this.rosterEntityPromise=this.rosterEntityPromise||this.sync.map({uniqueName:e,mode:"open"}).then(function(e){e.on("itemAdded",function(e){t.upsertMember(e.key,e.value).then(function(e){t.emit("memberJoined",e)})}),e.on("itemRemoved",function(e){if(t.members.has(e)){var n=t.members.get(e);t.members.delete(e),t.emit("memberLeft",n)}}),e.on("itemUpdated",function(e){t.upsertMember(e.key,e.value)});var n=[];return e.forEach(function(e){n.push(t.upsertMember(e.key,e.value))}).then(function(){return b.default.all(n)}).then(function(){return e})}).catch(function(e){throw t.rosterEntityPromise=null,w.error("Failed to get roster object for channel",t.channel.sid,e),e})}},{key:"upsertMember",value:function(e,t){return y(this,void 0,void 0,o.default.mark(function n(){var r,i=this;return o.default.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(!(r=this.members.get(e))){n.next=3;break}return n.abrupt("return",r._update(t));case 3:return r=new g.Member(this.users,this.channel,t,e),this.members.set(e,r),r.on("updated",function(){return i.emit("memberUpdated",r)}),n.abrupt("return",r);case 7:case"end":return n.stop()}},n,this)}))}},{key:"getMembers",value:function(){var e=this;return this.rosterEntityPromise.then(function(){var t=[];return e.members.forEach(function(e){return t.push(e)}),t})}},{key:"add",value:function(e){return this.session.addCommand("addMember",{channelSid:this.channel.sid,username:e})}},{key:"invite",value:function(e){return this.session.addCommand("inviteMember",{channelSid:this.channel.sid,username:e})}},{key:"remove",value:function(e){return this.session.addCommand("removeMember",{channelSid:this.channel.sid,username:e})}}]),t}(_.EventEmitter);n.Members=C},{"../logger":14,"../member":15,"babel-runtime/core-js/object/get-prototype-of":40,"babel-runtime/core-js/promise":43,"babel-runtime/helpers/classCallCheck":48,"babel-runtime/helpers/createClass":49,"babel-runtime/helpers/inherits":51,"babel-runtime/helpers/possibleConstructorReturn":52,"babel-runtime/regenerator":55,events:201}],7:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}var i=e("babel-runtime/core-js/json/stringify"),o=r(i),s=e("babel-runtime/regenerator"),a=r(s),u=e("babel-runtime/core-js/map"),c=r(u),l=e("babel-runtime/core-js/object/get-prototype-of"),f=r(l),h=e("babel-runtime/helpers/classCallCheck"),d=r(h),p=e("babel-runtime/helpers/createClass"),m=r(p),v=e("babel-runtime/helpers/possibleConstructorReturn"),b=r(v),y=e("babel-runtime/helpers/inherits"),_=r(y),g=e("babel-runtime/core-js/promise"),k=r(g),w=function(e,t,n,r){return new(n||(n=k.default))(function(i,o){function s(e){try{u(r.next(e))}catch(e){o(e)}}function a(e){try{u(r.throw(e))}catch(e){o(e)}}function u(e){e.done?i(e.value):new n(function(t){t(e.value)}).then(s,a)}u((r=r.apply(e,t||[])).next())})};Object.defineProperty(n,"__esModule",{value:!0});var C=e("events"),x=e("../logger"),j=e("../message"),E=x.Logger.scope(""),S=function(e){function t(e,n){(0,d.default)(this,t);var r=(0,b.default)(this,(t.__proto__||(0,f.default)(t)).call(this));return r.channel=e,r.session=n,r.sync=n.datasync,r.messagesByIndex=new c.default,r.messagesListPromise=null,r}return(0,_.default)(t,e),(0,m.default)(t,[{key:"subscribe",value:function(e){var t=this;return this.messagesListPromise=this.messagesListPromise||this.sync.list({uniqueName:e,mode:"open"}).then(function(e){return e.on("itemAdded",function(e){var n=new j.Message(t.channel,t.session,e.index,e.value);if(t.messagesByIndex.has(n.index))return void E.debug("Message arrived, but already known and ignored",t.channel.sid,n.index);t.messagesByIndex.set(n.index,n),n.on("updated",function(){return t.emit("messageUpdated",n)}),t.emit("messageAdded",n)}),e.on("itemRemoved",function(e){if(t.messagesByIndex.has(e)){var n=t.messagesByIndex.get(e);t.messagesByIndex.delete(n.index),n.removeAllListeners("updated"),t.emit("messageRemoved",n)}}),e.on("itemUpdated",function(e){var n=t.messagesByIndex.get(e.index);n&&n._update(e.value)}),e}).catch(function(e){throw t.messagesListPromise=null,E.error("Failed to get messages object for channel",t.channel.sid,e),e})}},{key:"unsubscribe",value:function(){return w(this,void 0,void 0,a.default.mark(function e(){var t;return a.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.messagesListPromise){e.next=6;break}return e.next=3,this.messagesListPromise;case 3:t=e.sent,t.close(),this.messagesListPromise=null;case 6:case"end":return e.stop()}},e,this)}))}},{key:"send",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return w(this,void 0,void 0,a.default.mark(function n(){return a.default.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(t.constructor===Object){n.next=2;break}throw new Error("Attributes must be a valid JSON object");case 2:return n.abrupt("return",this.session.addCommand("sendMessage",{channelSid:this.channel.sid,text:e,attributes:(0,o.default)(t)}));case 3:case"end":return n.stop()}},n,this)}))}},{key:"getMessages",value:function(e,t,n){return t=void 0!==t?t:"end",n=n||"backwards",this._getMessages(e,t,n)}},{key:"wrapPaginator",value:function(e,t,n){var r=this,i="desc"===e,o=function(){return t.nextPage().then(function(t){return r.wrapPaginator(e,t,n)})},s=function(){return t.prevPage().then(function(t){return r.wrapPaginator(e,t,n)})};return n(t.items).then(function(e){return{items:e.sort(function(e,t){return e.index-t.index}),hasPrevPage:i?t.hasNextPage:t.hasPrevPage,hasNextPage:i?t.hasPrevPage:t.hasNextPage,prevPage:i?o:s,nextPage:i?s:o}})}},{key:"_upsertMessage",value:function(e,t){var n=this,r=this.messagesByIndex.get(e);if(r)return r;var i=new j.Message(this.channel,this.session,e,t);return this.messagesByIndex.set(i.index,i),i.on("updated",function(){return n.emit("messageUpdated",i)}),i}},{key:"_getMessages",value:function(e,t,n){var r=this;t=void 0!==t?t:"end",e=e||30;var i="backwards"===n?"desc":"asc";return this.messagesListPromise.then(function(n){return n.getItems({from:"end"!==t?t:void 0,pageSize:e,order:i})}).then(function(e){return r.wrapPaginator(i,e,function(e){return k.default.all(e.map(function(e){return r._upsertMessage(e.index,e.value)}))})})}}]),t}(C.EventEmitter);n.Messages=S},{"../logger":14,"../message":16,"babel-runtime/core-js/json/stringify":32,"babel-runtime/core-js/map":33,"babel-runtime/core-js/object/get-prototype-of":40,"babel-runtime/core-js/promise":43,"babel-runtime/helpers/classCallCheck":48,"babel-runtime/helpers/createClass":49,"babel-runtime/helpers/inherits":51,"babel-runtime/helpers/possibleConstructorReturn":52,"babel-runtime/regenerator":55,events:201}],8:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}var i=e("babel-runtime/regenerator"),o=r(i),s=e("babel-runtime/helpers/classCallCheck"),a=r(s),u=e("babel-runtime/helpers/createClass"),c=r(u),l=e("babel-runtime/core-js/promise"),f=r(l),h=function(e,t,n,r){return new(n||(n=f.default))(function(i,o){function s(e){try{u(r.next(e))}catch(e){o(e)}}function a(e){try{u(r.throw(e))}catch(e){o(e)}}function u(e){e.done?i(e.value):new n(function(t){t(e.value)}).then(s,a)}u((r=r.apply(e,t||[])).next())})};Object.defineProperty(n,"__esModule",{value:!0});var d=e("../util/index"),p=e("../restpaginator"),m=e("../channeldescriptor"),v=function(){function e(t,n,r,i){(0,a.default)(this,e),this.config=t,this.client=n,this.transport=r,this.url=i}return(0,c.default)(e,[{key:"getChannels",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return h(this,void 0,void 0,o.default.mark(function t(){var n,r,i=this;return o.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return n=new d.UriBuilder(this.url).arg("PageToken",e.pageToken).build(),t.next=3,this.transport.get(n);case 3:return r=t.sent,t.abrupt("return",new p.RestPaginator(r.body.channels.map(function(e){return new m.ChannelDescriptor(i.client,e)}),function(e){return i.getChannels({pageToken:e})},r.body.meta.previous_token,r.body.meta.next_token));case 5:case"end":return t.stop()}},t,this)}))}},{key:"getChannelBySid",value:function(e){return h(this,void 0,void 0,o.default.mark(function t(){var n,r;return o.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return n=new d.UriBuilder(this.url).path(e).build(),t.next=3,this.transport.get(n);case 3:return r=t.sent,t.abrupt("return",new m.ChannelDescriptor(this.client,r.body));case 5:case"end":return t.stop()}},t,this)}))}},{key:"getChannelByUniqueName",value:function(e){return h(this,void 0,void 0,o.default.mark(function t(){var n,r;return o.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return n=new d.UriBuilder(this.url).path(encodeURIComponent(e)).build(),t.next=3,this.transport.get(n);case 3:return r=t.sent,t.abrupt("return",new m.ChannelDescriptor(this.client,r.body));case 5:case"end":return t.stop()}},t,this)}))}}]),e}();n.PublicChannels=v},{"../channeldescriptor":2,"../restpaginator":17,"../util/index":28,"babel-runtime/core-js/promise":43,"babel-runtime/helpers/classCallCheck":48,"babel-runtime/helpers/createClass":49,"babel-runtime/regenerator":55}],9:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}var i=e("babel-runtime/regenerator"),o=r(i),s=e("babel-runtime/helpers/classCallCheck"),a=r(s),u=e("babel-runtime/helpers/createClass"),c=r(u),l=e("babel-runtime/core-js/promise"),f=r(l),h=function(e,t,n,r){return new(n||(n=f.default))(function(i,o){function s(e){try{u(r.next(e))}catch(e){o(e)}}function a(e){try{u(r.throw(e))}catch(e){o(e)}}function u(e){e.done?i(e.value):new n(function(t){t(e.value)}).then(s,a)}u((r=r.apply(e,t||[])).next())})};Object.defineProperty(n,"__esModule",{value:!0});var d=e("../util/index"),p=e("../restpaginator"),m=e("../channeldescriptor"),v=function(){function e(t,n,r,i){(0,a.default)(this,e),this.config=t,this.client=n,this.transport=r,this.url=i}return(0,c.default)(e,[{key:"getChannels",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return h(this,void 0,void 0,o.default.mark(function t(){var n,r,i=this;return o.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return n=new d.UriBuilder(this.url).arg("PageToken",e.pageToken).build(),t.next=3,this.transport.get(n);case 3:return r=t.sent,t.abrupt("return",new p.RestPaginator(r.body.channels.map(function(e){return new m.ChannelDescriptor(i.client,e)}),function(e){return i.getChannels({pageToken:e})},r.body.meta.previous_token,r.body.meta.next_token));case 5:case"end":return t.stop()}},t,this)}))}}]),e}();n.UserChannels=v},{"../channeldescriptor":2,"../restpaginator":17,"../util/index":28,"babel-runtime/core-js/promise":43,"babel-runtime/helpers/classCallCheck":48,"babel-runtime/helpers/createClass":49,"babel-runtime/regenerator":55}],10:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}var i=e("babel-runtime/regenerator"),o=r(i),s=e("babel-runtime/helpers/classCallCheck"),a=r(s),u=e("babel-runtime/helpers/createClass"),c=r(u),l=e("babel-runtime/core-js/promise"),f=r(l),h=function(e,t,n,r){return new(n||(n=f.default))(function(i,o){function s(e){try{u(r.next(e))}catch(e){o(e)}}function a(e){try{u(r.throw(e))}catch(e){o(e)}}function u(e){e.done?i(e.value):new n(function(t){t(e.value)}).then(s,a)}u((r=r.apply(e,t||[])).next())})};Object.defineProperty(n,"__esModule",{value:!0});var d=e("../util/index"),p=e("../restpaginator"),m=e("../userdescriptor"),v=function(){function e(t,n,r,i){(0,a.default)(this,e),this.config=t,this.users=n,this.transport=r,this.url=i}return(0,c.default)(e,[{key:"getUserDescriptor",value:function(e){return h(this,void 0,void 0,o.default.mark(function t(){var n,r;return o.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return n=new d.UriBuilder(this.url).path(e).build(),t.next=3,this.transport.get(n);case 3:return r=t.sent,t.abrupt("return",new m.UserDescriptor(this.users,r.body));case 5:case"end":return t.stop()}},t,this)}))}},{key:"getChannelUserDescriptors",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return h(this,void 0,void 0,o.default.mark(function n(){var r,i,s=this;return o.default.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return r=new d.UriBuilder(this.url).arg("ChannelSid",e).arg("PageToken",t.pageToken).build(),n.next=3,this.transport.get(r);case 3:return i=n.sent,n.abrupt("return",new p.RestPaginator(i.body.users.map(function(e){return new m.UserDescriptor(s.users,e)}),function(t){return s.getChannelUserDescriptors(e,t)},i.body.meta.prev_token,i.body.meta.next_token));case 5:case"end":return n.stop()}},n,this)}))}}]),e}();n.UserDescriptors=v},{"../restpaginator":17,"../userdescriptor":26,"../util/index":28,"babel-runtime/core-js/promise":43,"babel-runtime/helpers/classCallCheck":48,"babel-runtime/helpers/createClass":49,"babel-runtime/regenerator":55}],11:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}var i=e("babel-runtime/regenerator"),o=r(i),s=e("babel-runtime/core-js/map"),a=r(s),u=e("babel-runtime/core-js/object/get-prototype-of"),c=r(u),l=e("babel-runtime/helpers/classCallCheck"),f=r(l),h=e("babel-runtime/helpers/createClass"),d=r(h),p=e("babel-runtime/helpers/possibleConstructorReturn"),m=r(p),v=e("babel-runtime/helpers/inherits"),b=r(v),y=e("babel-runtime/core-js/promise"),_=r(y),g=function(e,t,n,r){return new(n||(n=_.default))(function(i,o){function s(e){try{u(r.next(e))}catch(e){o(e)}}function a(e){try{u(r.throw(e))}catch(e){o(e)}}function u(e){e.done?i(e.value):new n(function(t){t(e.value)}).then(s,a)}u((r=r.apply(e,t||[])).next())})};Object.defineProperty(n,"__esModule",{value:!0});var k=e("events"),w=e("../user"),C=e("./userdescriptors"),x=function(e){function t(e,n,r){var i=r.config,o=r.network;(0,f.default)(this,t);var s=(0,m.default)(this,(t.__proto__||(0,c.default)(t)).call(this));return s.fifoStack=[],s.fifoStackMaxLength=100,s.myself=new w.User(null,null,n,e),s.myself.on("updated",function(){return s.emit("userUpdated",s.myself)}),s.myself.on("userSubscribed",function(){return s.emit("userSubscribed",s.myself)}),s.myself.on("userUnsubscribed",function(){s.emit("userUnsubscribed",s.myself),s.myself._ensureFetched()}),s.session=e,s.sync=n,s.subscribedUsers=new a.default,s.userDescriptorsPromise=s.session.getSessionLinks().then(function(e){return s.userDescriptors=new C.UserDescriptors(i,s,o,e.usersUrl),s.userDescriptors}),s.session.getMaxUserInfosToSubscribe().then(function(e){s.fifoStackMaxLength=e}),s.session.getUsersData().then(function(e){return s.myself.identity=e.identity,s.myself.entityName=e.user,s.myself._ensureFetched()}),s}return(0,b.default)(t,e),(0,d.default)(t,[{key:"handleUnsubscribeUser",value:function(e){this.subscribedUsers.has(e.identity)&&this.subscribedUsers.delete(e.identity);var t=-1;this.fifoStack.find(function(n,r){return n==e.identity&&(t=r,!0)})&&this.fifoStack.splice(t,1),this.emit("userUnsubscribed",e)}},{key:"handleSubscribeUser",value:function(e){this.subscribedUsers.has(e.identity)||(this.fifoStack.length>=this.fifoStackMaxLength&&this.subscribedUsers.get(this.fifoStack.shift()).unsubscribe(),this.fifoStack.push(e.identity),this.subscribedUsers.set(e.identity,e),this.emit("userSubscribed",e))}},{key:"getUser",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return g(this,void 0,void 0,o.default.mark(function n(){var r,i,s=this;return o.default.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return n.next=2,this.session.getUsersData();case 2:return n.next=4,this.myself._ensureFetched();case 4:if(e!=this.myself.identity){n.next=6;break}return n.abrupt("return",this.myself);case 6:if(r=this.subscribedUsers.get(e)){n.next=19;break}if(t){n.next=13;break}return n.next=11,this.getUserDescriptor(e);case 11:i=n.sent,t=i._getDescriptor().sync_unique_name;case 13:return r=new w.User(e,t,this.sync,this.session),r.on("updated",function(){return s.emit("userUpdated",r)}),r.on("userSubscribed",function(){return s.handleSubscribeUser(r)}),r.on("userUnsubscribed",function(){return s.handleUnsubscribeUser(r)}),n.next=19,r._ensureFetched();case 19:return n.abrupt("return",r);case 20:case"end":return n.stop()}},n,this)}))}},{key:"getUserDescriptor",value:function(e){return g(this,void 0,void 0,o.default.mark(function t(){return o.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.userDescriptorsPromise;case 2:return t.abrupt("return",this.userDescriptors.getUserDescriptor(e));case 3:case"end":return t.stop()}},t,this)}))}},{key:"getChannelUserDescriptors",value:function(e){return g(this,void 0,void 0,o.default.mark(function t(){return o.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.userDescriptorsPromise;case 2:return t.abrupt("return",this.userDescriptors.getChannelUserDescriptors(e));case 3:case"end":return t.stop()}},t,this)}))}},{key:"getSubscribedUsers",value:function(){return g(this,void 0,void 0,o.default.mark(function e(){var t;return o.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.session.getUsersData();case 2:return e.next=4,this.myself._ensureFetched();case 4:return t=[this.myself],this.subscribedUsers.forEach(function(e){return t.push(e)}),e.abrupt("return",t);case 7:case"end":return e.stop()}},e,this)}))}}]),t}(k.EventEmitter);n.Users=x},{"../user":25,"./userdescriptors":10,"babel-runtime/core-js/map":33,"babel-runtime/core-js/object/get-prototype-of":40,"babel-runtime/core-js/promise":43,"babel-runtime/helpers/classCallCheck":48,"babel-runtime/helpers/createClass":49,"babel-runtime/helpers/inherits":51,"babel-runtime/helpers/possibleConstructorReturn":52,"babel-runtime/regenerator":55,events:201}],12:[function(e,t,n){"use strict";var r=e("babel-runtime/helpers/classCallCheck"),i=function(e){return e&&e.__esModule?e:{default:e}}(r);Object.defineProperty(n,"__esModule",{value:!0});var o=function e(){(0,i.default)(this,e)};o.TYPING_INDICATOR="twilio.ipmsg.typing_indicator",o.NEW_MESSAGE="twilio.channel.new_message",o.ADDED_TO_CHANNEL="twilio.channel.added_to_channel",o.INVITED_TO_CHANNEL="twilio.channel.invited_to_channel",o.REMOVED_FROM_CHANNEL="twilio.channel.removed_from_channel",o.CONSUMPTION_UPDATE="twilio.channel.consumption_update",n.NotificationTypes=o},{"babel-runtime/helpers/classCallCheck":48}],13:[function(e,t,n){"use strict";var r=e("babel-runtime/helpers/classCallCheck"),i=function(e){return e&&e.__esModule?e:{default:e}}(r);Object.defineProperty(n,"__esModule",{value:!0});var o=function e(){(0,i.default)(this,e)};o.HTTP_200_OK=200,o.HTTP_400_BAD_REQUEST=400,o.HTTP_404_NOT_FOUND=404,o.ACCESS_FORBIDDEN_FOR_IDENTITY=54007,o.LIST_NOT_FOUND=54150,n.ResponseCodes=o},{"babel-runtime/helpers/classCallCheck":48}],14:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function i(e,t){return[e].concat((0,l.default)(t))}var o=e("babel-runtime/helpers/classCallCheck"),s=r(o),a=e("babel-runtime/helpers/createClass"),u=r(a),c=e("babel-runtime/core-js/array/from"),l=r(c);Object.defineProperty(n,"__esModule",{value:!0});var f=e("loglevel"),h=function(){function e(){(0,s.default)(this,e),this.prefix=""}return(0,u.default)(e,[{key:"setLevel",value:function(e){f.setLevel(e)}},{key:"trace",value:function(){for(var e=arguments.length,t=Array(e),n=0;n is a required parameter for updateBody");case 2:return t.next=4,this.session.addCommand("editMessage",{channelSid:this.channel.sid,messageIdx:this.index.toString(),text:e});case 4:return t.abrupt("return",this);case 5:case"end":return t.stop()}},t,this)}))}},{key:"updateAttributes",value:function(e){return k(this,void 0,void 0,u.default.mark(function t(){return u.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(void 0!==e){t.next=4;break}throw new Error("Attributes is a required parameter for updateAttributes");case 4:if(e.constructor===Object){t.next=6;break}throw new Error("Attributes must be a valid JSON object");case 6:return t.next=8,this.session.addCommand("editMessageAttributes",{channelSid:this.channel.sid,messageIdx:this.index,attributes:(0,s.default)(e)});case 8:return t.abrupt("return",this);case 9:case"end":return t.stop()}},t,this)}))}},{key:"sid",get:function(){return this.state.sid}},{key:"author",get:function(){return this.state.author}},{key:"body",get:function(){return this.state.body}},{key:"dateUpdated",get:function(){return this.state.dateUpdated}},{key:"index",get:function(){return this.state.index}},{key:"lastUpdatedBy",get:function(){return this.state.lastUpdatedBy}},{key:"timestamp",get:function(){return this.state.timestamp}},{key:"attributes",get:function(){return this.state.attributes}}]),t}(w.EventEmitter);n.Message=E},{"./logger":14,"./util/index":28,"babel-runtime/core-js/json/stringify":32,"babel-runtime/core-js/object/get-prototype-of":40,"babel-runtime/core-js/promise":43,"babel-runtime/helpers/classCallCheck":48,"babel-runtime/helpers/createClass":49,"babel-runtime/helpers/inherits":51,"babel-runtime/helpers/possibleConstructorReturn":52,"babel-runtime/regenerator":55,events:201}],17:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}var i=e("babel-runtime/core-js/promise"),o=r(i),s=e("babel-runtime/helpers/classCallCheck"),a=r(s),u=e("babel-runtime/helpers/createClass"),c=r(u);Object.defineProperty(n,"__esModule",{value:!0});var l=function(){function e(t,n,r,i){(0,a.default)(this,e),this.state={prevToken:r,nextToken:i,source:n,items:t}}return(0,c.default)(e,[{key:"nextPage",value:function(){return this.hasNextPage?this.state.source(this.state.nextToken):o.default.reject(new Error("No next page"))}},{key:"prevPage",value:function(){return this.hasPrevPage?this.state.source(this.state.prevToken):o.default.reject(new Error("No previous page"))}},{key:"hasNextPage",get:function(){return!!this.state.nextToken}},{key:"hasPrevPage",get:function(){return!!this.state.prevToken}},{key:"items",get:function(){return this.state.items}}]),e}();n.RestPaginator=l},{"babel-runtime/core-js/promise":43,"babel-runtime/helpers/classCallCheck":48,"babel-runtime/helpers/createClass":49}],18:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}var i=e("babel-runtime/core-js/map"),o=r(i),s=e("babel-runtime/helpers/classCallCheck"),a=r(s),u=e("babel-runtime/helpers/createClass"),c=r(u);Object.defineProperty(n,"__esModule",{value:!0});var l=function(){function e(t,n){(0,a.default)(this,e),this.session=n,this.consumptionHorizonReports=new o.default,this.consumptionHorizonUpdateTimer=null}return(0,c.default)(e,[{key:"getReportInterval",value:function(){return this.session.getConsumptionReportInterval().then(function(e){return 1e3*e.seconds})}},{key:"delayedSendConsumptionHorizon",value:function(e){var t=this;null===this.consumptionHorizonUpdateTimer&&(this.consumptionHorizonUpdateTimer=setTimeout(function(){var e=[];t.consumptionHorizonReports.forEach(function(t){return e.push(t)}),e.length>0&&t.session.addCommand("consumptionReport",{report:e}),t.consumptionHorizonUpdateTimer=null,t.consumptionHorizonReports.clear()},e))}},{key:"updateLastConsumedMessageIndexForChannel",value:function(e,t){var n=this;this.consumptionHorizonReports.set(e,{channelSid:e,messageIdx:t}),this.getReportInterval().then(function(e){return n.delayedSendConsumptionHorizon(e)})}},{key:"advanceLastConsumedMessageIndexForChannel",value:function(e,t){var n=this,r=this.consumptionHorizonReports.get(e);r&&r.messageIdx>=t||(this.consumptionHorizonReports.set(e,{channelSid:e,messageIdx:t}),this.getReportInterval().then(function(e){return n.delayedSendConsumptionHorizon(e)}))}}]),e}();n.ConsumptionHorizon=l},{"babel-runtime/core-js/map":33,"babel-runtime/helpers/classCallCheck":48,"babel-runtime/helpers/createClass":49}],19:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}var i=e("babel-runtime/regenerator"),o=r(i),s=e("babel-runtime/helpers/slicedToArray"),a=r(s),u=e("babel-runtime/core-js/get-iterator"),c=r(u),l=e("babel-runtime/core-js/number/is-integer"),f=r(l),h=e("babel-runtime/core-js/map"),d=r(h),p=e("babel-runtime/helpers/classCallCheck"),m=r(p),v=e("babel-runtime/helpers/createClass"),b=r(v),y=e("babel-runtime/core-js/promise"),_=r(y),g=function(e,t,n,r){return new(n||(n=_.default))(function(i,o){function s(e){try{u(r.next(e))}catch(e){o(e)}}function a(e){try{u(r.throw(e))}catch(e){o(e)}}function u(e){e.done?i(e.value):new n(function(t){t(e.value)}).then(s,a)}u((r=r.apply(e,t||[])).next())})};Object.defineProperty(n,"__esModule",{value:!0});var k=function(){function e(t,n,r){(0,m.default)(this,e),this.config=t,this.session=n,this.transport=r,this.cache=new d.default,this.cacheLifetime=(0,f.default)(t.httpCacheLifetimeOverride)?t.httpCacheLifetimeOverride:t.httpCacheLifetimeDefault}return(0,b.default)(e,[{key:"isExpired",value:function(e){return!this.cacheLifetime||Date.now()-e>this.cacheLifetime}},{key:"cleanupCache",value:function(){var e=!0,t=!1,n=void 0;try{for(var r,i=(0,c.default)(this.cache);!(e=(r=i.next()).done);e=!0){var o=(0,a.default)(r.value,2),s=o[0],u=o[1];this.isExpired(u.timestamp)&&this.cache.delete(s)}}catch(e){t=!0,n=e}finally{try{!e&&i.return&&i.return()}finally{if(t)throw n}}0===this.cache.size&&clearTimeout(this.timer)}},{key:"pokeTimer",value:function(){var e=this;this.timer=this.timer||setInterval(function(){return e.cleanupCache()},2*this.cacheLifetime)}},{key:"get",value:function(e){return g(this,void 0,void 0,o.default.mark(function t(){var n,r,i;return o.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!(n=this.cache.get(e))||this.isExpired(n.timestamp)){t.next=3;break}return t.abrupt("return",n.response);case 3:return r={"X-Twilio-Token":this.config.token},t.next=6,this.transport.get(e,r);case 6:return i=t.sent,this.cache.set(e,{response:i,timestamp:Date.now()}),this.pokeTimer(),t.abrupt("return",i);case 10:case"end":return t.stop()}},t,this)}))}}]),e}();n.Network=k},{"babel-runtime/core-js/get-iterator":30,"babel-runtime/core-js/map":33,"babel-runtime/core-js/number/is-integer":34,"babel-runtime/core-js/promise":43,"babel-runtime/helpers/classCallCheck":48,"babel-runtime/helpers/createClass":49,"babel-runtime/helpers/slicedToArray":53,"babel-runtime/regenerator":55}],20:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}var i=e("babel-runtime/core-js/promise"),o=r(i),s=e("babel-runtime/core-js/map"),a=r(s),u=e("babel-runtime/helpers/classCallCheck"),c=r(u),l=e("babel-runtime/helpers/createClass"),f=r(l);Object.defineProperty(n,"__esModule",{value:!0});var h=e("../logger"),d=e("../interfaces/notificationtypes"),p=h.Logger.scope("TypingIndicator"),m=function(){function e(t,n,r,i){(0,c.default)(this,e),this.config=t,this.transport=n,this.notifications=r,this.getChannel=i,this.serviceTypingTimeout=null,this.sentUpdates=new a.default}return(0,f.default)(e,[{key:"initialize",value:function(){var e=this;this.notifications.subscribe(d.NotificationTypes.TYPING_INDICATOR,"twilsock"),this.notifications.on("message",function(t,n){t===d.NotificationTypes.TYPING_INDICATOR&&e.handleRemoteTyping(n)})}},{key:"handleRemoteTyping",value:function(e){var t=this;p.trace("Got new typing indicator ",e),this.getChannel(e.channel_sid).then(function(n){n&&n.members.forEach(function(n){n.identity===e.identity&&n._startTyping(t.typingTimeout)})}).catch(function(e){throw p.error(e),e})}},{key:"send",value:function(e){var t=this.sentUpdates.get(e);return t&&t>Date.now()-this.typingTimeout?o.default.resolve():(this.sentUpdates.set(e,Date.now()),this._send(e))}},{key:"_send",value:function(e){var t=this;p.trace("Sending typing indicator");var n=this.config.typingIndicatorUri,r={"X-Twilio-Token":this.config.token,"Content-Type":"application/x-www-form-urlencoded"},i="ChannelSid="+e;return this.transport.post(n,r,i).then(function(e){e.body.hasOwnProperty("typing_timeout")&&(t.serviceTypingTimeout=1e3*e.body.typing_timeout)}).catch(function(e){throw p.error("Failed to send typing indicator:",e),e})}},{key:"typingTimeout",get:function(){return this.config.typingIndicatorTimeoutOverride||this.serviceTypingTimeout||this.config.typingIndicatorTimeoutDefault}}]),e}();n.TypingIndicator=m},{"../interfaces/notificationtypes":12,"../logger":14,"babel-runtime/core-js/map":33,"babel-runtime/core-js/promise":43,"babel-runtime/helpers/classCallCheck":48,"babel-runtime/helpers/createClass":49}],21:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function i(e,t){return!t.some(function(t){return!e.hasOwnProperty(t)})}var o=e("babel-runtime/regenerator"),s=r(o),a=e("babel-runtime/helpers/extends"),u=r(a),c=e("babel-runtime/core-js/map"),l=r(c),f=e("babel-runtime/helpers/createClass"),h=r(f),d=e("babel-runtime/helpers/classCallCheck"),p=r(d),m=e("babel-runtime/core-js/promise"),v=r(m),b=function(e,t,n,r){return new(n||(n=v.default))(function(i,o){function s(e){try{u(r.next(e))}catch(e){o(e)}}function a(e){try{u(r.throw(e))}catch(e){o(e)}}function u(e){e.done?i(e.value):new n(function(t){t(e.value)}).then(s,a)}u((r=r.apply(e,t||[])).next())})};Object.defineProperty(n,"__esModule",{value:!0});var y=e("uuid"),_=e("platform"),g=e("durational"),k=e("./interfaces/responsecodes"),w=e("./logger"),C=e("./sessionerror"),x=e("./util/deferred"),j=e("./../package.json").version,E=w.Logger.scope("Session"),S=function e(){(0,p.default)(this,e)},T=function(){function e(t,n,r){(0,p.default)(this,e);var i="undefined"!=typeof navigator?_.parse(navigator.userAgent):_;this.datasync=t,this.transport=n,this.config=r,this.sessionInfo=new x.Deferred,this.currentContext={},this.token=null,this.tokenSynced=!0,this.pendingCommands=new l.default,this.sessionStreamPromise=null,this.endpointPlatform=["js",j,i.os,i.name,i.version].join("|")}return(0,h.default)(e,[{key:"handleContextUpdate",value:function(e){E.info("Session context updated"),E.debug("new session context:",e),this.currentContext=e,i(e,["identity","userInfo","links","myChannels","channels"])&&(E.info("new session context accepted"),this.sessionInfo.set(e))}},{key:"initialize",value:function(e){var t=this;this.token=e,this.tokenSynced=!1;var n={type:"IpMsgSession",apiVersion:"3",endpointPlatform:this.endpointPlatform,token:e};return this.sessionStreamPromise=this.datasync.list({purpose:"com.twilio.rtd.ipmsg",context:n}).then(function(e){return E.info("Session created",e.sid),t.tokenSynced=!0,e.on("itemAdded",function(e){return t.processCommandResponse(e)}),e.on("itemUpdated",function(e){return t.processCommandResponse(e)}),e.on("contextUpdatedRemotely",function(e){return t.handleContextUpdate(e)}),e}).catch(function(e){throw E.error("Failed to create session",e),e}),this.sessionStreamPromise}},{key:"addCommand",value:function(e,t){return this.processCommand(e,t)}},{key:"processCommand",value:function(e,t){var n=this,r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],i=new S;return i.request=t,i.request.action=e,i.commandId=y.v4(),E.info("Adding command: ",e,i.commandId),E.debug("command arguments:",t,r),new v.default(function(o,s){n.sessionStreamPromise.then(function(e){return n.pendingCommands.set(i.commandId,{resolve:o,reject:s,commandId:i.commandId,request:i.request}),e.push(i)}).then(function(){return E.debug("Command accepted by server",i.commandId)}).catch(function(a){n.pendingCommands.delete(i.commandId),E.error("Failed to add a command to the session",a),a.code!=k.ResponseCodes.ACCESS_FORBIDDEN_FOR_IDENTITY&&a.code!==k.ResponseCodes.LIST_NOT_FOUND||!r?s(new Error("Can't add command: "+a.message)):(E.info("recreating session..."),n.initialize(n.token),o(n.processCommand(e,t,!1)))})})}},{key:"processCommandResponse",value:function(e){if(e.value.hasOwnProperty("response")&&e.value.hasOwnProperty("commandId")&&this.pendingCommands.has(e.value.commandId)){var t=e.value,n=e.value.commandId;if(t.response.status===k.ResponseCodes.HTTP_200_OK){E.debug("Command succeeded: ",t);var r=this.pendingCommands.get(n).resolve;this.pendingCommands.delete(n),r(t.response)}else{E.error("Command failed: ",t);var i=this.pendingCommands.get(n).reject;this.pendingCommands.delete(n),i(new C.SessionError(t.response.statusText,t.response.status))}}}},{key:"updateToken",value:function(e){return this.token=e,this.tokenSynced=!1,this.syncToken()}},{key:"syncToken",value:function(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];return b(this,void 0,void 0,s.default.mark(function t(){var n,r,i,o;return s.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!this.tokenSynced&&!this.tokenSyncInProgress){t.next=3;break}return E.trace("token is already synced or sync is in progress"),t.abrupt("return");case 3:return this.tokenSyncInProgress=!0,t.prev=4,t.next=7,this.getSessionContext();case 7:return n=t.sent,t.next=10,this.sessionStreamPromise;case 10:return r=t.sent,t.next=13,r.updateContext((0,u.default)(n,{token:this.token}));case 13:this.tokenSynced=!0,this.tokenSyncInProgress=!1,t.next=28;break;case 17:if(t.prev=17,t.t0=t.catch(4),t.t0.code!=k.ResponseCodes.ACCESS_FORBIDDEN_FOR_IDENTITY&&t.t0.code!==k.ResponseCodes.LIST_NOT_FOUND||!e){t.next=23;break}return E.info("recreating session..."),this.initialize(this.token),t.abrupt("return",this.syncToken(!1));case 23:throw i="Couldn't update the token in session context",o=k.ResponseCodes.HTTP_400_BAD_REQUEST,E.error(i,t.t0),this.tokenSyncInProgress=!1,new C.SessionError(i,o);case 28:case"end":return t.stop()}},t,this,[[4,17]])}))}},{key:"getSessionContext",value:function(){return this.sessionStreamPromise.then(function(e){return e.getContext()})}},{key:"getSessionLinks",value:function(){return b(this,void 0,void 0,s.default.mark(function e(){var t;return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.sessionInfo.promise;case 2:return t=e.sent,e.abrupt("return",{publicChannelsUrl:this.config.baseUrl+t.links.publicChannelsUrl,myChannelsUrl:this.config.baseUrl+t.links.myChannelsUrl,typingUrl:this.config.baseUrl+t.links.typingUrl,syncListUrl:this.config.baseUrl+t.links.syncListUrl,usersUrl:this.config.baseUrl+t.links.usersUrl});case 4:case"end":return e.stop()}},e,this)}))}},{key:"getChannelsId",value:function(){return b(this,void 0,void 0,s.default.mark(function e(){var t;return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.sessionInfo.promise;case 2:return t=e.sent,e.abrupt("return",t.channels);case 4:case"end":return e.stop()}},e,this)}))}},{key:"getMyChannelsId",value:function(){return b(this,void 0,void 0,s.default.mark(function e(){var t;return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.sessionInfo.promise;case 2:return t=e.sent,e.abrupt("return",t.myChannels);case 4:case"end":return e.stop()}},e,this)}))}},{key:"getMaxUserInfosToSubscribe",value:function(){return b(this,void 0,void 0,s.default.mark(function e(){var t;return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.sessionInfo.promise;case 2:return t=e.sent,e.abrupt("return",this.config.userInfosToSubscribeOverride||t.userInfosToSubscribe||this.config.userInfosToSubscribeDefault);case 4:case"end":return e.stop()}},e,this)}))}},{key:"getUsersData",value:function(){return this.sessionInfo.promise.then(function(e){return{user:e.userInfo,identity:e.identity}})}},{key:"getConsumptionReportInterval",value:function(){return b(this,void 0,void 0,s.default.mark(function e(){var t;return s.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.getSessionContext();case 2:return t=e.sent,e.abrupt("return",g.fromString(this.config.consumptionReportIntervalOverride||t.consumptionReportInterval||this.config.consumptionReportIntervalDefault));case 4:case"end":return e.stop()}},e,this)}))}},{key:"identity",get:function(){return this.sessionInfo.current.identity}},{key:"reachabilityEnabled",get:function(){return this.currentContext.reachabilityEnabled}}]),e}();n.Session=T},{"./../package.json":269,"./interfaces/responsecodes":13,"./logger":14,"./sessionerror":22,"./util/deferred":27,"babel-runtime/core-js/map":33,"babel-runtime/core-js/promise":43,"babel-runtime/helpers/classCallCheck":48,"babel-runtime/helpers/createClass":49,"babel-runtime/helpers/extends":50,"babel-runtime/regenerator":55,durational:199,platform:207,uuid:261}],22:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}var i=e("babel-runtime/core-js/object/get-prototype-of"),o=r(i),s=e("babel-runtime/helpers/classCallCheck"),a=r(s),u=e("babel-runtime/helpers/possibleConstructorReturn"),c=r(u),l=e("babel-runtime/helpers/inherits"),f=r(l);Object.defineProperty(n,"__esModule",{value:!0});var h=function(e){function t(e,n){(0,a.default)(this,t);var r=(0,c.default)(this,(t.__proto__||(0,o.default)(t)).call(this));return r.name=r.constructor.name,r.message=e,r.code=n,Error.captureStackTrace?Error.captureStackTrace(r,r.constructor):r.stack=(new Error).stack,r}return(0,f.default)(t,e),t}(Error);n.SessionError=h},{"babel-runtime/core-js/object/get-prototype-of":40,"babel-runtime/helpers/classCallCheck":48,"babel-runtime/helpers/inherits":51,"babel-runtime/helpers/possibleConstructorReturn":52}],23:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}var i=e("babel-runtime/regenerator"),o=r(i),s=e("babel-runtime/helpers/classCallCheck"),a=r(s),u=e("babel-runtime/helpers/createClass"),c=r(u),l=e("babel-runtime/core-js/promise"),f=r(l),h=function(e,t,n,r){return new(n||(n=f.default))(function(i,o){function s(e){try{u(r.next(e))}catch(e){o(e)}}function a(e){try{u(r.throw(e))}catch(e){o(e)}}function u(e){e.done?i(e.value):new n(function(t){t(e.value)}).then(s,a)}u((r=r.apply(e,t||[])).next())})};Object.defineProperty(n,"__esModule",{value:!0});var d=e("./util/index"),p=e("./restpaginator"),m=e("./synclistdescriptor"),v=function(){function e(t,n){(0,a.default)(this,e),this.network=t,this.session=n}return(0,c.default)(e,[{key:"getPage",value:function(e){return h(this,void 0,void 0,o.default.mark(function t(){var n,r,i,s=this;return o.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return e=e||{},t.next=3,this.session.getSessionLinks();case 3:return n=t.sent,r=new d.UriBuilder(n.syncListUrl).arg("PageToken",e.pageToken).build(),t.next=7,this.network.get(r);case 7:return i=t.sent,t.abrupt("return",new p.RestPaginator(i.body.channels.map(function(e){return new m.SyncListDescriptor(e)}),function(e){return s.getPage({pageToken:e})},i.body.meta.previous_token,i.body.meta.next_token));case 9:case"end":return t.stop()}},t,this)}))}}]),e}();n.SyncList=v},{"./restpaginator":17,"./synclistdescriptor":24,"./util/index":28,"babel-runtime/core-js/promise":43,"babel-runtime/helpers/classCallCheck":48,"babel-runtime/helpers/createClass":49,"babel-runtime/regenerator":55}],24:[function(e,t,n){"use strict";var r=e("babel-runtime/helpers/classCallCheck"),i=function(e){return e&&e.__esModule?e:{default:e}}(r);Object.defineProperty(n,"__esModule",{value:!0});var o=function e(t){(0,i.default)(this,e),this.descriptor=t,this.channel_sid=t.channel_sid,this.status=t.status,this.channel=t.channel,this.messages=t.messages,this.roster=t.roster,this.lastConsumedMessageIndex=t.last_consumed_message_index,this.status=t.status};n.SyncListDescriptor=o},{"babel-runtime/helpers/classCallCheck":48}],25:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}var i=e("babel-runtime/core-js/json/stringify"),o=r(i),s=e("babel-runtime/regenerator"),a=r(s),u=e("babel-runtime/core-js/object/get-prototype-of"),c=r(u),l=e("babel-runtime/helpers/classCallCheck"),f=r(l),h=e("babel-runtime/helpers/createClass"),d=r(h),p=e("babel-runtime/helpers/possibleConstructorReturn"),m=r(p),v=e("babel-runtime/helpers/inherits"),b=r(v),y=e("babel-runtime/core-js/promise"),_=r(y),g=function(e,t,n,r){return new(n||(n=_.default))(function(i,o){function s(e){try{u(r.next(e))}catch(e){o(e)}}function a(e){try{u(r.throw(e))}catch(e){o(e)}}function u(e){e.done?i(e.value):new n(function(t){t(e.value)}).then(s,a)}u((r=r.apply(e,t||[])).next())})};Object.defineProperty(n,"__esModule",{value:!0});var k=e("events"),w=e("./logger"),C=w.Logger.scope("User"),x=function(e){function t(e,n,r,i){(0,f.default)(this,t);var o=(0,m.default)(this,(t.__proto__||(0,c.default)(t)).call(this));return o.subscribed="initializing",o.setMaxListeners(0),o.sync=r,o.session=i,o.state={identity:e,entityName:n,friendlyName:null,attributes:{},online:null,notifiable:null},o}return(0,b.default)(t,e),(0,d.default)(t,[{key:"_update",value:function(e,t){switch(C.debug("User for",this.state.identity,"updated:",e,t),e){case"friendlyName":this.state.friendlyName=t.value;break;case"attributes":try{this.state.attributes=JSON.parse(t.value)}catch(e){this.state.attributes={}}break;case"reachability":this.state.online=t.online,this.state.notifiable=t.notifiable;break;default:return}this.emit("updated",e)}},{key:"_updateReachabilityInfo",value:function(e,t){var n=this;return this.session.reachabilityEnabled?e.get("reachability").then(t).catch(function(e){C.warn("Failed to get reachability info for ",n.state.identity,e)}):_.default.resolve()}},{key:"_fetch",value:function(){return g(this,void 0,void 0,a.default.mark(function e(){var t,n=this;return a.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(this.state.entityName){e.next=2;break}return e.abrupt("return",this);case 2:return t=function(e){return n._update(e.key,e.value)},this.promiseToFetch=this.sync.map({uniqueName:this.state.entityName,mode:"open",optimistic:!0}).then(function(e){return n.entity=e,e.on("itemUpdated",t),_.default.all([e.get("friendlyName").then(t),e.get("attributes").then(t),n._updateReachabilityInfo(e,t)])}).then(function(){return C.debug("Fetched for",n.identity),n.subscribed="subscribed",n.emit("userSubscribed",n),n}).catch(function(e){throw n.promiseToFetch=null,e}),e.abrupt("return",this.promiseToFetch);case 5:case"end":return e.stop()}},e,this)}))}},{key:"_ensureFetched",value:function(){return this.promiseToFetch||this._fetch()}},{key:"updateAttributes",value:function(e){return g(this,void 0,void 0,a.default.mark(function t(){return a.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(e&&e.constructor===Object){t.next=2;break}throw new Error("Attributes must be an object");case 2:if("unsubscribed"!=this.subscribed){t.next=4;break}throw new Error("Can't modify unsubscribed object");case 4:return t.next=6,this.session.addCommand("editUserAttributes",{username:this.state.identity,attributes:(0,o.default)(e)});case 6:return t.abrupt("return",this);case 7:case"end":return t.stop()}},t,this)}))}},{key:"updateFriendlyName",value:function(e){return g(this,void 0,void 0,a.default.mark(function t(){return a.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!e||"string"==typeof e){t.next=2;break}throw new Error("friendlyName must be string or empty");case 2:if("unsubscribed"!=this.subscribed){t.next=4;break}throw new Error("Can't modify unsubscribed object");case 4:return t.next=6,this.session.addCommand("editUserFriendlyName",{username:this.state.identity,friendlyName:e});case 6:return t.abrupt("return",this);case 7:case"end":return t.stop()}},t,this)}))}},{key:"unsubscribe",value:function(){return g(this,void 0,void 0,a.default.mark(function e(){return a.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.promiseToFetch){e.next=7;break}return e.next=3,this.promiseToFetch;case 3:this.entity.close(),this.promiseToFetch=null,this.subscribed="unsubscribed",this.emit("userUnsubscribed",this);case 7:case"end":return e.stop()}},e,this)}))}},{key:"identity",get:function(){return this.state.identity},set:function(e){this.state.identity=e}},{key:"entityName",set:function(e){this.state.entityName=e}},{key:"attributes",get:function(){return this.state.attributes}},{key:"friendlyName",get:function(){return this.state.friendlyName}},{key:"online",get:function(){return this.state.online}},{key:"notifiable",get:function(){return this.state.notifiable}},{key:"isSubscribed",get:function(){return"subscribed"==this.subscribed}}]),t}(k.EventEmitter);n.User=x},{"./logger":14,"babel-runtime/core-js/json/stringify":32,"babel-runtime/core-js/object/get-prototype-of":40,"babel-runtime/core-js/promise":43,"babel-runtime/helpers/classCallCheck":48,"babel-runtime/helpers/createClass":49,"babel-runtime/helpers/inherits":51,"babel-runtime/helpers/possibleConstructorReturn":52,"babel-runtime/regenerator":55,events:201}],26:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function i(e){try{return JSON.parse(e)}catch(e){l.warn("Failed to parse user attributes",e)}return{}}var o=e("babel-runtime/helpers/classCallCheck"),s=r(o),a=e("babel-runtime/helpers/createClass"),u=r(a);Object.defineProperty(n,"__esModule",{value:!0});var c=e("./logger"),l=c.Logger.scope("UserDescriptor"),f=function(){function e(t,n){(0,s.default)(this,e),this.users=t,this.descriptor=n,this.identity=n.identity,this.friendlyName=n.friendly_name,this.attributes=i(n.attributes),this.online=n.is_online,this.notifiable=n.is_notifiable}return(0,u.default)(e,[{key:"subscribe",value:function(){return this.users.getUser(this.identity,this.descriptor.sync_unique_name)}},{key:"_getDescriptor",value:function(){return this.descriptor}}]),e}();n.UserDescriptor=f},{"./logger":14,"babel-runtime/helpers/classCallCheck":48,"babel-runtime/helpers/createClass":49}],27:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}var i=e("babel-runtime/core-js/promise"),o=r(i),s=e("babel-runtime/helpers/classCallCheck"),a=r(s),u=e("babel-runtime/helpers/createClass"),c=r(u);Object.defineProperty(n,"__esModule",{value:!0});var l=function(){function e(){var t=this;(0,a.default)(this,e),this._promise=new o.default(function(e,n){t._resolve=e,t._reject=n})}return(0,c.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}();n.Deferred=l},{"babel-runtime/core-js/promise":43,"babel-runtime/helpers/classCallCheck":48,"babel-runtime/helpers/createClass":49}],28:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function i(e,t){return 0===h.createPatch(e,t).length}function o(e){return JSON.parse((0,f.default)(e))}var s=e("babel-runtime/helpers/classCallCheck"),a=r(s),u=e("babel-runtime/helpers/createClass"),c=r(u),l=e("babel-runtime/core-js/json/stringify"),f=r(l);Object.defineProperty(n,"__esModule",{value:!0});var h=e("rfc6902");n.isDeepEqual=i,n.deepClone=o;var d=function(){function e(t){(0,a.default)(this,e),this.base=t.replace(/\/$/,""),this.args=new Array,this.paths=new Array}return(0,c.default)(e,[{key:"arg",value:function(e,t){return void 0!==t&&this.args.push(e+"="+t),this}},{key:"path",value:function(e){return this.paths.push(e),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}();n.UriBuilder=d},{"babel-runtime/core-js/json/stringify":32,"babel-runtime/helpers/classCallCheck":48,"babel-runtime/helpers/createClass":49,rfc6902:214}],29:[function(e,t,n){t.exports={default:e("core-js/library/fn/array/from"),__esModule:!0}},{ "core-js/library/fn/array/from":70}],30:[function(e,t,n){t.exports={default:e("core-js/library/fn/get-iterator"),__esModule:!0}},{"core-js/library/fn/get-iterator":71}],31:[function(e,t,n){t.exports={default:e("core-js/library/fn/is-iterable"),__esModule:!0}},{"core-js/library/fn/is-iterable":72}],32:[function(e,t,n){t.exports={default:e("core-js/library/fn/json/stringify"),__esModule:!0}},{"core-js/library/fn/json/stringify":73}],33:[function(e,t,n){t.exports={default:e("core-js/library/fn/map"),__esModule:!0}},{"core-js/library/fn/map":74}],34:[function(e,t,n){t.exports={default:e("core-js/library/fn/number/is-integer"),__esModule:!0}},{"core-js/library/fn/number/is-integer":75}],35:[function(e,t,n){t.exports={default:e("core-js/library/fn/object/assign"),__esModule:!0}},{"core-js/library/fn/object/assign":76}],36:[function(e,t,n){t.exports={default:e("core-js/library/fn/object/create"),__esModule:!0}},{"core-js/library/fn/object/create":77}],37:[function(e,t,n){t.exports={default:e("core-js/library/fn/object/define-properties"),__esModule:!0}},{"core-js/library/fn/object/define-properties":78}],38:[function(e,t,n){t.exports={default:e("core-js/library/fn/object/define-property"),__esModule:!0}},{"core-js/library/fn/object/define-property":79}],39:[function(e,t,n){t.exports={default:e("core-js/library/fn/object/freeze"),__esModule:!0}},{"core-js/library/fn/object/freeze":80}],40:[function(e,t,n){t.exports={default:e("core-js/library/fn/object/get-prototype-of"),__esModule:!0}},{"core-js/library/fn/object/get-prototype-of":81}],41:[function(e,t,n){t.exports={default:e("core-js/library/fn/object/keys"),__esModule:!0}},{"core-js/library/fn/object/keys":82}],42:[function(e,t,n){t.exports={default:e("core-js/library/fn/object/set-prototype-of"),__esModule:!0}},{"core-js/library/fn/object/set-prototype-of":83}],43:[function(e,t,n){t.exports={default:e("core-js/library/fn/promise"),__esModule:!0}},{"core-js/library/fn/promise":84}],44:[function(e,t,n){t.exports={default:e("core-js/library/fn/reflect/construct"),__esModule:!0}},{"core-js/library/fn/reflect/construct":85}],45:[function(e,t,n){t.exports={default:e("core-js/library/fn/set"),__esModule:!0}},{"core-js/library/fn/set":86}],46:[function(e,t,n){t.exports={default:e("core-js/library/fn/symbol"),__esModule:!0}},{"core-js/library/fn/symbol":87}],47:[function(e,t,n){t.exports={default:e("core-js/library/fn/symbol/iterator"),__esModule:!0}},{"core-js/library/fn/symbol/iterator":88}],48:[function(e,t,n){"use strict";n.__esModule=!0,n.default=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}},{}],49:[function(e,t,n){"use strict";n.__esModule=!0;var r=e("../core-js/object/define-property"),i=function(e){return e&&e.__esModule?e:{default:e}}(r);n.default=function(){function e(e,t){for(var n=0;n0,"Expected a maximum number of retry greater than 0 but got %s.",e),this.maxNumberOfRetry_=e},r.prototype.backoff=function(e){o.checkState(-1===this.timeoutID_,"Backoff in progress."),this.backoffNumber_===this.maxNumberOfRetry_?(this.emit("fail",e),this.reset()):(this.backoffDelay_=this.backoffStrategy_.next(),this.timeoutID_=setTimeout(this.handlers.backoff,this.backoffDelay_),this.emit("backoff",this.backoffNumber_,this.backoffDelay_,e))},r.prototype.onBackoff_=function(){this.timeoutID_=-1,this.emit("ready",this.backoffNumber_,this.backoffDelay_),this.backoffNumber_++},r.prototype.reset=function(){this.backoffNumber_=0,this.backoffStrategy_.reset(),clearTimeout(this.timeoutID_),this.timeoutID_=-1},t.exports=r},{events:201,precond:208,util:260}],58:[function(e,t,n){function r(e,t,n){i.EventEmitter.call(this),o.checkIsFunction(e,"Expected fn to be a function."),o.checkIsArray(t,"Expected args to be an array."),o.checkIsFunction(n,"Expected callback to be a function."),this.function_=e,this.arguments_=t,this.callback_=n,this.lastResult_=[],this.numRetries_=0,this.backoff_=null,this.strategy_=null,this.failAfter_=-1,this.retryPredicate_=r.DEFAULT_RETRY_PREDICATE_,this.state_=r.State_.PENDING} // Copyright (c) 2012 Mathieu Turcotte // Licensed under the MIT license. var i=e("events"),o=e("precond"),s=e("util"),a=e("./backoff"),u=e("./strategy/fibonacci");s.inherits(r,i.EventEmitter),r.State_={PENDING:0,RUNNING:1,COMPLETED:2,ABORTED:3},r.DEFAULT_RETRY_PREDICATE_=function(e){return!0},r.prototype.isPending=function(){return this.state_==r.State_.PENDING},r.prototype.isRunning=function(){return this.state_==r.State_.RUNNING},r.prototype.isCompleted=function(){return this.state_==r.State_.COMPLETED},r.prototype.isAborted=function(){return this.state_==r.State_.ABORTED},r.prototype.setStrategy=function(e){return o.checkState(this.isPending(),"FunctionCall in progress."),this.strategy_=e,this},r.prototype.retryIf=function(e){return o.checkState(this.isPending(),"FunctionCall in progress."),this.retryPredicate_=e,this},r.prototype.getLastResult=function(){return this.lastResult_.concat()},r.prototype.getNumRetries=function(){return this.numRetries_},r.prototype.failAfter=function(e){return o.checkState(this.isPending(),"FunctionCall in progress."),this.failAfter_=e,this},r.prototype.abort=function(){this.isCompleted()||this.isAborted()||(this.isRunning()&&this.backoff_.reset(),this.state_=r.State_.ABORTED,this.lastResult_=[new Error("Backoff aborted.")],this.emit("abort"),this.doCallback_())},r.prototype.start=function(e){o.checkState(!this.isAborted(),"FunctionCall is aborted."),o.checkState(this.isPending(),"FunctionCall already started.");var t=this.strategy_||new u;this.backoff_=e?e(t):new a(t),this.backoff_.on("ready",this.doCall_.bind(this,!0)),this.backoff_.on("fail",this.doCallback_.bind(this)),this.backoff_.on("backoff",this.handleBackoff_.bind(this)),this.failAfter_>0&&this.backoff_.failAfter(this.failAfter_),this.state_=r.State_.RUNNING,this.doCall_(!1)},r.prototype.doCall_=function(e){e&&this.numRetries_++;var t=["call"].concat(this.arguments_);i.EventEmitter.prototype.emit.apply(this,t);var n=this.handleFunctionCallback_.bind(this);this.function_.apply(null,this.arguments_.concat(n))},r.prototype.doCallback_=function(){this.callback_.apply(null,this.lastResult_)},r.prototype.handleFunctionCallback_=function(){if(!this.isAborted()){var e=Array.prototype.slice.call(arguments);this.lastResult_=e,i.EventEmitter.prototype.emit.apply(this,["callback"].concat(e));var t=e[0];t&&this.retryPredicate_(t)?this.backoff_.backoff(t):(this.state_=r.State_.COMPLETED,this.doCallback_())}},r.prototype.handleBackoff_=function(e,t,n){this.emit("backoff",e,t,n)},t.exports=r},{"./backoff":57,"./strategy/fibonacci":60,events:201,precond:208,util:260}],59:[function(e,t,n){function r(e){s.call(this,e),this.backoffDelay_=0,this.nextBackoffDelay_=this.getInitialDelay(),this.factor_=r.DEFAULT_FACTOR,e&&void 0!==e.factor&&(o.checkArgument(e.factor>1,"Exponential factor should be greater than 1 but got %s.",e.factor),this.factor_=e.factor)} // Copyright (c) 2012 Mathieu Turcotte // Licensed under the MIT license. var i=e("util"),o=e("precond"),s=e("./strategy");i.inherits(r,s),r.DEFAULT_FACTOR=2,r.prototype.next_=function(){return this.backoffDelay_=Math.min(this.nextBackoffDelay_,this.getMaxDelay()),this.nextBackoffDelay_=this.backoffDelay_*this.factor_,this.backoffDelay_},r.prototype.reset_=function(){this.backoffDelay_=0,this.nextBackoffDelay_=this.getInitialDelay()},t.exports=r},{"./strategy":61,precond:208,util:260}],60:[function(e,t,n){function r(e){o.call(this,e),this.backoffDelay_=0,this.nextBackoffDelay_=this.getInitialDelay()} // Copyright (c) 2012 Mathieu Turcotte // Licensed under the MIT license. var i=e("util"),o=e("./strategy");i.inherits(r,o),r.prototype.next_=function(){var e=Math.min(this.nextBackoffDelay_,this.getMaxDelay());return this.nextBackoffDelay_+=this.backoffDelay_,this.backoffDelay_=e,e},r.prototype.reset_=function(){this.nextBackoffDelay_=this.getInitialDelay(),this.backoffDelay_=0},t.exports=r},{"./strategy":61,util:260}],61:[function(e,t,n){function r(e){return void 0!==e&&null!==e}function i(e){if(e=e||{},r(e.initialDelay)&&e.initialDelay<1)throw new Error("The initial timeout must be greater than 0.");if(r(e.maxDelay)&&e.maxDelay<1)throw new Error("The maximal timeout must be greater than 0.");if(this.initialDelay_=e.initialDelay||100,this.maxDelay_=e.maxDelay||1e4,this.maxDelay_<=this.initialDelay_)throw new Error("The maximal backoff delay must be greater than the initial backoff delay.");if(r(e.randomisationFactor)&&(e.randomisationFactor<0||e.randomisationFactor>1))throw new Error("The randomisation factor must be between 0 and 1.");this.randomisationFactor_=e.randomisationFactor||0} // Copyright (c) 2012 Mathieu Turcotte // Licensed under the MIT license. e("events"),e("util");i.prototype.getMaxDelay=function(){return this.maxDelay_},i.prototype.getInitialDelay=function(){return this.initialDelay_},i.prototype.next=function(){var e=this.next_(),t=1+Math.random()*this.randomisationFactor_;return Math.round(e*t)},i.prototype.next_=function(){throw new Error("BackoffStrategy.next_() unimplemented.")},i.prototype.reset=function(){this.reset_()},i.prototype.reset_=function(){throw new Error("BackoffStrategy.reset_() unimplemented.")},t.exports=i},{events:201,util:260}],62:[function(e,t,n){"use strict";function r(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");return"="===e[t-2]?2:"="===e[t-1]?1:0}function i(e){return 3*e.length/4-r(e)}function o(e){var t,n,i,o,s,a,u=e.length;s=r(e),a=new f(3*u/4-s),i=s>0?u-4:u;var c=0;for(t=0,n=0;t>16&255,a[c++]=o>>8&255,a[c++]=255&o;return 2===s?(o=l[e.charCodeAt(t)]<<2|l[e.charCodeAt(t+1)]>>4,a[c++]=255&o):1===s&&(o=l[e.charCodeAt(t)]<<10|l[e.charCodeAt(t+1)]<<4|l[e.charCodeAt(t+2)]>>2,a[c++]=o>>8&255,a[c++]=255&o),a}function s(e){return c[e>>18&63]+c[e>>12&63]+c[e>>6&63]+c[63&e]}function a(e,t,n){for(var r,i=[],o=t;ou?u:s+16383));return 1===r?(t=e[n-1],i+=c[t>>2],i+=c[t<<4&63],i+="=="):2===r&&(t=(e[n-2]<<8)+e[n-1],i+=c[t>>10],i+=c[t>>4&63],i+=c[t<<2&63],i+="="),o.push(i),o.join("")}n.byteLength=i,n.toByteArray=o,n.fromByteArray=u;for(var c=[],l=[],f="undefined"!=typeof Uint8Array?Uint8Array:Array,h="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",d=0,p=h.length;d0;){var t=e.shift();if("function"==typeof t){var n=e.shift(),r=e.shift();t.call(n,r)}else t._settlePromises()}},r.prototype._drainQueues=function(){this._drainQueue(this._normalQueue),this._reset(),this._haveDrainedQueues=!0,this._drainQueue(this._lateQueue)},r.prototype._queueTick=function(){this._isTickUsed||(this._isTickUsed=!0,this._schedule(this.drainQueues))},r.prototype._reset=function(){this._isTickUsed=!1},t.exports=r,t.exports.firstLineError=u},{"./queue":26,"./schedule":29,"./util":36}],3:[function(e,t,n){"use strict";t.exports=function(e,t,n,r){var i=!1,o=function(e,t){this._reject(t)},s=function(e,t){t.promiseRejectionQueued=!0,t.bindingPromise._then(o,o,null,this,e)},a=function(e,t){0==(50397184&this._bitField)&&this._resolveCallback(t.target)},u=function(e,t){t.promiseRejectionQueued||this._reject(e)};e.prototype.bind=function(o){i||(i=!0,e.prototype._propagateFrom=r.propagateFromFunction(),e.prototype._boundValue=r.boundValueFunction());var c=n(o),l=new e(t);l._propagateFrom(this,1);var f=this._target();if(l._setBoundTo(c),c instanceof e){var h={promiseRejectionQueued:!1,promise:l,target:f,bindingPromise:c};f._then(t,s,void 0,l,h),c._then(a,u,void 0,l,h),l._setOnCancel(c)}else l._resolveCallback(f);return l},e.prototype._setBoundTo=function(e){void 0!==e?(this._bitField=2097152|this._bitField,this._boundTo=e):this._bitField=-2097153&this._bitField},e.prototype._isBound=function(){return 2097152==(2097152&this._bitField)},e.bind=function(t,n){return e.resolve(n).bind(t)}}},{}],4:[function(e,t,n){"use strict";function r(){try{Promise===o&&(Promise=i)}catch(e){}return o}var i;"undefined"!=typeof Promise&&(i=Promise);var o=e("./promise")();o.noConflict=r,t.exports=o},{"./promise":22}],5:[function(e,t,n){"use strict";var r=Object.create;if(r){var i=r(null),o=r(null);i[" size"]=o[" size"]=0}t.exports=function(t){function n(e,n){var r;if(null!=e&&(r=e[n]),"function"!=typeof r){var i="Object "+a.classString(e)+" has no method '"+a.toString(n)+"'";throw new t.TypeError(i)}return r}function r(e){return n(e,this.pop()).apply(e,this)}function i(e){return e[this]}function o(e){var t=+this;return t<0&&(t=Math.max(0,t+e.length)),e[t]}var s,a=e("./util"),u=a.canEvaluate;a.isIdentifier;t.prototype.call=function(e){var t=[].slice.call(arguments,1);return t.push(e),this._then(r,void 0,void 0,t,void 0)},t.prototype.get=function(e){var t,n="number"==typeof e;if(n)t=o;else if(u){var r=s(e);t=null!==r?r:i}else t=i;return this._then(t,void 0,void 0,e,void 0)}}},{"./util":36}],6:[function(e,t,n){"use strict";t.exports=function(t,n,r,i){var o=e("./util"),s=o.tryCatch,a=o.errorObj,u=t._async;t.prototype.break=t.prototype.cancel=function(){if(!i.cancellation())return this._warn("cancellation is disabled");for(var e=this,t=e;e._isCancellable();){if(!e._cancelBy(t)){t._isFollowing()?t._followee().cancel():t._cancelBranched();break}var n=e._cancellationParent;if(null==n||!n._isCancellable()){e._isFollowing()?e._followee().cancel():e._cancelBranched();break}e._isFollowing()&&e._followee().cancel(),e._setWillBeCancelled(),t=e,e=n}},t.prototype._branchHasCancelled=function(){this._branchesRemainingToCancel--},t.prototype._enoughBranchesHaveCancelled=function(){return void 0===this._branchesRemainingToCancel||this._branchesRemainingToCancel<=0},t.prototype._cancelBy=function(e){return e===this?(this._branchesRemainingToCancel=0,this._invokeOnCancel(),!0):(this._branchHasCancelled(),!!this._enoughBranchesHaveCancelled()&&(this._invokeOnCancel(),!0))},t.prototype._cancelBranched=function(){this._enoughBranchesHaveCancelled()&&this._cancel()},t.prototype._cancel=function(){this._isCancellable()&&(this._setCancelled(),u.invoke(this._cancelPromises,this,void 0))},t.prototype._cancelPromises=function(){this._length()>0&&this._settlePromises()},t.prototype._unsetOnCancel=function(){this._onCancelField=void 0},t.prototype._isCancellable=function(){return this.isPending()&&!this._isCancelled()},t.prototype.isCancellable=function(){return this.isPending()&&!this.isCancelled()},t.prototype._doInvokeOnCancel=function(e,t){if(o.isArray(e))for(var n=0;n=0)return o[e]}var i=!1,o=[];return e.prototype._promiseCreated=function(){},e.prototype._pushContext=function(){},e.prototype._popContext=function(){return null},e._peekContext=e.prototype._peekContext=function(){},t.prototype._pushContext=function(){void 0!==this._trace&&(this._trace._promiseCreated=null,o.push(this._trace))},t.prototype._popContext=function(){if(void 0!==this._trace){var e=o.pop(),t=e._promiseCreated;return e._promiseCreated=null,t}return null},t.CapturedTrace=null,t.create=n,t.deactivateLongStackTraces=function(){},t.activateLongStackTraces=function(){var n=e.prototype._pushContext,o=e.prototype._popContext,s=e._peekContext,a=e.prototype._peekContext,u=e.prototype._promiseCreated;t.deactivateLongStackTraces=function(){e.prototype._pushContext=n,e.prototype._popContext=o,e._peekContext=s,e.prototype._peekContext=a,e.prototype._promiseCreated=u,i=!1},i=!0,e.prototype._pushContext=t.prototype._pushContext,e.prototype._popContext=t.prototype._popContext,e._peekContext=e.prototype._peekContext=r,e.prototype._promiseCreated=function(){var e=this._peekContext();e&&null==e._promiseCreated&&(e._promiseCreated=this)}},t}},{}],9:[function(e,t,n){"use strict";t.exports=function(t,n){function r(e,t){return{promise:t}}function o(){return!1}function s(e,t,n){var r=this;try{e(t,n,function(e){if("function"!=typeof e)throw new TypeError("onCancel must be a function, got: "+L.toString(e));r._attachCancellationCallback(e)})}catch(e){return e}}function a(e){if(!this._isCancellable())return this;var t=this._onCancel();void 0!==t?L.isArray(t)?t.push(e):this._setOnCancel([t,e]):this._setOnCancel(e)}function u(){return this._onCancelField}function c(e){this._onCancelField=e}function l(){this._cancellationParent=void 0,this._onCancelField=void 0}function f(e,t){if(0!=(1&t)){this._cancellationParent=e;var n=e._branchesRemainingToCancel;void 0===n&&(n=0),e._branchesRemainingToCancel=n+1}0!=(2&t)&&e._isBound()&&this._setBoundTo(e._boundTo)}function h(e,t){0!=(2&t)&&e._isBound()&&this._setBoundTo(e._boundTo)}function d(){var e=this._boundTo;return void 0!==e&&e instanceof t?e.isFulfilled()?e.value():void 0:e}function p(){this._trace=new P(this._peekContext())}function m(e,t){if(B(e)){var n=this._trace;if(void 0!==n&&t&&(n=n._parent),void 0!==n)n.attachExtraTrace(e);else if(!e.__stackCleaned__){var r=x(e);L.notEnumerableProp(e,"stack",r.message+"\n"+r.stack.join("\n")),L.notEnumerableProp(e,"__stackCleaned__",!0)}}}function v(e,t,n,r,i){if(void 0===e&&null!==t&&Q){if(void 0!==i&&i._returnedNonUndefined())return;if(0==(65535&r._bitField))return;n&&(n+=" ");var o="",s="";if(t._trace){for(var a=t._trace.stack.split("\n"),u=w(a),c=u.length-1;c>=0;--c){var l=u[c];if(!z.test(l)){var f=l.match(H);f&&(o="at "+f[1]+":"+f[2]+":"+f[3]+" ");break}}if(u.length>0)for(var h=u[0],c=0;c0&&(s="\n"+a[c-1]);break}}var d="a promise was created in a "+n+"handler "+o+"but was not returned from it, see http://goo.gl/rRqMUw"+s;r._warn(d,!0,t)}}function b(e,t){var n=e+" is deprecated and will be removed in a future version.";return t&&(n+=" Use "+t+" instead."),y(n)}function y(e,n,r){if(se.warnings){var i,o=new D(e);if(n)r._attachExtraTrace(o);else if(se.longStackTraces&&(i=t._peekContext()))i.attachExtraTrace(o);else{var s=x(o);o.stack=s.message+"\n"+s.stack.join("\n")}te("warning",o)||j(o,"",!0)}}function _(e,t){for(var n=0;n=0;--a)if(r[a]===o){s=a;break}for(var a=s;a>=0;--a){var u=r[a];if(t[i]!==u)break;t.pop(),i--}t=r}}function w(e){for(var t=[],n=0;n0&&"SyntaxError"!=e.name&&(t=t.slice(n)),t}function x(e){var t=e.stack,n=e.toString();return t="string"==typeof t&&t.length>0?C(e):[" (No stack trace)"],{message:n,stack:"SyntaxError"==e.name?t:w(t)}}function j(e,t,n){if("undefined"!=typeof console){var r;if(L.isObject(e)){var i=e.stack;r=t+V(i,e)}else r=t+String(e);"function"==typeof N?N(r,n):"function"!=typeof console.log&&"object"!=typeof console.log||console.log(r)}}function E(e,t,n,r){var i=!1;try{"function"==typeof t&&(i=!0,"rejectionHandled"===e?t(r):t(n,r))}catch(e){U.throwLater(e)}"unhandledRejection"===e?te(e,n,r)||i||j(n,"Unhandled rejection "):te(e,r)}function S(e){var t;if("function"==typeof e)t="[function "+(e.name||"anonymous")+"]";else{t=e&&"function"==typeof e.toString?e.toString():L.toString(e);if(/\[object [a-zA-Z0-9$_]+\]/.test(t))try{t=JSON.stringify(e)}catch(e){}0===t.length&&(t="(empty array)")}return"(<"+T(t)+">, no stack trace)"}function T(e){return e.length<41?e:e.substr(0,38)+"..."}function R(){return"function"==typeof oe}function A(e){var t=e.match(ie);if(t)return{fileName:t[1],line:parseInt(t[2],10)}}function I(e,t){if(R()){for(var n,r,i=e.stack.split("\n"),o=t.stack.split("\n"),s=-1,a=-1,u=0;u=a||(re=function(e){if(q.test(e))return!0;var t=A(e);return!!(t&&t.fileName===n&&s<=t.line&&t.line<=a)})}}function P(e){this._parent=e,this._promisesCreated=0;var t=this._length=1+(void 0===e?0:e._length);oe(this,P),t>32&&this.uncycle()}var O,M,N,F=t._getDomain,U=t._async,D=e("./errors").Warning,L=e("./util"),B=L.canAttachTrace,q=/[\\\/]bluebird[\\\/]js[\\\/](release|debug|instrumented)/,z=/\((?:timers\.js):\d+:\d+\)/,H=/[\/<\(](.+?):(\d+):(\d+)\)?\s*$/,W=null,V=null,G=!1,J=!(0==L.env("BLUEBIRD_DEBUG")),$=!(0==L.env("BLUEBIRD_WARNINGS")||!J&&!L.env("BLUEBIRD_WARNINGS")),K=!(0==L.env("BLUEBIRD_LONG_STACK_TRACES")||!J&&!L.env("BLUEBIRD_LONG_STACK_TRACES")),Q=0!=L.env("BLUEBIRD_W_FORGOTTEN_RETURN")&&($||!!L.env("BLUEBIRD_W_FORGOTTEN_RETURN"));t.prototype.suppressUnhandledRejections=function(){var e=this._target();e._bitField=-1048577&e._bitField|524288},t.prototype._ensurePossibleRejectionHandled=function(){0==(524288&this._bitField)&&(this._setRejectionIsUnhandled(),U.invokeLater(this._notifyUnhandledRejection,this,void 0))},t.prototype._notifyUnhandledRejectionIsHandled=function(){E("rejectionHandled",O,void 0,this)},t.prototype._setReturnedNonUndefined=function(){this._bitField=268435456|this._bitField},t.prototype._returnedNonUndefined=function(){return 0!=(268435456&this._bitField)},t.prototype._notifyUnhandledRejection=function(){if(this._isRejectionUnhandled()){var e=this._settledValue();this._setUnhandledRejectionIsNotified(),E("unhandledRejection",M,e,this)}},t.prototype._setUnhandledRejectionIsNotified=function(){this._bitField=262144|this._bitField},t.prototype._unsetUnhandledRejectionIsNotified=function(){this._bitField=-262145&this._bitField},t.prototype._isUnhandledRejectionNotified=function(){return(262144&this._bitField)>0},t.prototype._setRejectionIsUnhandled=function(){this._bitField=1048576|this._bitField},t.prototype._unsetRejectionIsUnhandled=function(){this._bitField=-1048577&this._bitField,this._isUnhandledRejectionNotified()&&(this._unsetUnhandledRejectionIsNotified(),this._notifyUnhandledRejectionIsHandled())},t.prototype._isRejectionUnhandled=function(){return(1048576&this._bitField)>0},t.prototype._warn=function(e,t,n){return y(e,t,n||this)},t.onPossiblyUnhandledRejection=function(e){var t=F();M="function"==typeof e?null===t?e:L.domainBind(t,e):void 0},t.onUnhandledRejectionHandled=function(e){var t=F();O="function"==typeof e?null===t?e:L.domainBind(t,e):void 0};var X=function(){};t.longStackTraces=function(){if(U.haveItemsQueued()&&!se.longStackTraces)throw new Error("cannot enable long stack traces after promises have been created\n\n See http://goo.gl/MqrFmX\n");if(!se.longStackTraces&&R()){var e=t.prototype._captureStackTrace,r=t.prototype._attachExtraTrace;se.longStackTraces=!0,X=function(){if(U.haveItemsQueued()&&!se.longStackTraces)throw new Error("cannot enable long stack traces after promises have been created\n\n See http://goo.gl/MqrFmX\n");t.prototype._captureStackTrace=e,t.prototype._attachExtraTrace=r,n.deactivateLongStackTraces(),U.enableTrampoline(),se.longStackTraces=!1},t.prototype._captureStackTrace=p,t.prototype._attachExtraTrace=m,n.activateLongStackTraces(),U.disableTrampolineIfNecessary()}},t.hasLongStackTraces=function(){return se.longStackTraces&&R()};var Y=function(){try{if("function"==typeof CustomEvent){var e=new CustomEvent("CustomEvent");return L.global.dispatchEvent(e),function(e,t){var n=new CustomEvent(e.toLowerCase(),{detail:t,cancelable:!0});return!L.global.dispatchEvent(n)}}if("function"==typeof Event){var e=new Event("CustomEvent");return L.global.dispatchEvent(e),function(e,t){var n=new Event(e.toLowerCase(),{cancelable:!0});return n.detail=t,!L.global.dispatchEvent(n)}}var e=document.createEvent("CustomEvent");return e.initCustomEvent("testingtheevent",!1,!0,{}),L.global.dispatchEvent(e),function(e,t){var n=document.createEvent("CustomEvent");return n.initCustomEvent(e.toLowerCase(),!1,!0,t),!L.global.dispatchEvent(n)}}catch(e){}return function(){return!1}}(),Z=function(){return L.isNode?function(){return i.emit.apply(i,arguments)}:L.global?function(e){var t="on"+e.toLowerCase(),n=L.global[t];return!!n&&(n.apply(L.global,[].slice.call(arguments,1)),!0)}:function(){return!1}}(),ee={promiseCreated:r,promiseFulfilled:r,promiseRejected:r,promiseResolved:r,promiseCancelled:r,promiseChained:function(e,t,n){return{promise:t,child:n}},warning:function(e,t){return{warning:t}},unhandledRejection:function(e,t,n){return{reason:t,promise:n}},rejectionHandled:r},te=function(e){var t=!1;try{t=Z.apply(null,arguments)}catch(e){U.throwLater(e),t=!0}var n=!1;try{n=Y(e,ee[e].apply(null,arguments))}catch(e){U.throwLater(e),n=!0}return n||t};t.config=function(e){if(e=Object(e),"longStackTraces"in e&&(e.longStackTraces?t.longStackTraces():!e.longStackTraces&&t.hasLongStackTraces()&&X()),"warnings"in e){var n=e.warnings;se.warnings=!!n,Q=se.warnings,L.isObject(n)&&"wForgottenReturn"in n&&(Q=!!n.wForgottenReturn)}if("cancellation"in e&&e.cancellation&&!se.cancellation){if(U.haveItemsQueued())throw new Error("cannot enable cancellation after promises are in use");t.prototype._clearCancellationData=l,t.prototype._propagateFrom=f,t.prototype._onCancel=u,t.prototype._setOnCancel=c,t.prototype._attachCancellationCallback=a,t.prototype._execute=s,ne=f,se.cancellation=!0}return"monitoring"in e&&(e.monitoring&&!se.monitoring?(se.monitoring=!0,t.prototype._fireEvent=te):!e.monitoring&&se.monitoring&&(se.monitoring=!1,t.prototype._fireEvent=o)),t},t.prototype._fireEvent=o,t.prototype._execute=function(e,t,n){try{e(t,n)}catch(e){return e}},t.prototype._onCancel=function(){},t.prototype._setOnCancel=function(e){},t.prototype._attachCancellationCallback=function(e){},t.prototype._captureStackTrace=function(){},t.prototype._attachExtraTrace=function(){},t.prototype._clearCancellationData=function(){},t.prototype._propagateFrom=function(e,t){};var ne=h,re=function(){return!1},ie=/[\/<\(]([^:\/]+):(\d+):(?:\d+)\)?\s*$/;L.inherits(P,Error),n.CapturedTrace=P,P.prototype.uncycle=function(){var e=this._length;if(!(e<2)){for(var t=[],n={},r=0,i=this;void 0!==i;++r)t.push(i),i=i._parent;e=this._length=r;for(var r=e-1;r>=0;--r){var o=t[r].stack;void 0===n[o]&&(n[o]=r)}for(var r=0;r0&&(t[a-1]._parent=void 0,t[a-1]._length=1),t[r]._parent=void 0,t[r]._length=1;var u=r>0?t[r-1]:this;a=0;--l)t[l]._length=c,c++;return}}}},P.prototype.attachExtraTrace=function(e){if(!e.__stackCleaned__){this.uncycle();for(var t=x(e),n=t.message,r=[t.stack],i=this;void 0!==i;)r.push(w(i.stack.split("\n"))),i=i._parent;k(r),g(r),L.notEnumerableProp(e,"stack",_(n,r)),L.notEnumerableProp(e,"__stackCleaned__",!0)}};var oe=function(){var e=/^\s*at\s*/,t=function(e,t){return"string"==typeof e?e:void 0!==t.name&&void 0!==t.message?t.toString():S(t)};if("number"==typeof Error.stackTraceLimit&&"function"==typeof Error.captureStackTrace){Error.stackTraceLimit+=6,W=e,V=t;var n=Error.captureStackTrace;return re=function(e){return q.test(e)},function(e,t){Error.stackTraceLimit+=6,n(e,t),Error.stackTraceLimit-=6}}var r=new Error;if("string"==typeof r.stack&&r.stack.split("\n")[0].indexOf("stackDetection@")>=0)return W=/@/,V=t,G=!0,function(e){e.stack=(new Error).stack};var i;try{throw new Error}catch(e){i="stack"in e}return"stack"in r||!i||"number"!=typeof Error.stackTraceLimit?(V=function(e,t){return"string"==typeof e?e:"object"!=typeof t&&"function"!=typeof t||void 0===t.name||void 0===t.message?S(t):t.toString()},null):(W=e,V=t,function(e){Error.stackTraceLimit+=6;try{throw new Error}catch(t){e.stack=t.stack}Error.stackTraceLimit-=6})}();"undefined"!=typeof console&&void 0!==console.warn&&(N=function(e){console.warn(e)},L.isNode&&i.stderr.isTTY?N=function(e,t){var n=t?"\x1b[33m":"\x1b[31m";console.warn(n+e+"\x1b[0m\n")}:L.isNode||"string"!=typeof(new Error).stack||(N=function(e,t){console.warn("%c"+e,t?"color: darkorange":"color: red")}));var se={warnings:$,longStackTraces:!1,cancellation:!1,monitoring:!1};return K&&t.longStackTraces(),{longStackTraces:function(){return se.longStackTraces},warnings:function(){return se.warnings},cancellation:function(){return se.cancellation},monitoring:function(){return se.monitoring},propagateFromFunction:function(){return ne},boundValueFunction:function(){return d},checkForgottenReturns:v,setBounds:I,warn:y,deprecated:b,CapturedTrace:P,fireDomEvent:Y,fireGlobalEvent:Z}}},{"./errors":12,"./util":36}],10:[function(e,t,n){"use strict";t.exports=function(e){function t(){return this.value}function n(){throw this.reason}e.prototype.return=e.prototype.thenReturn=function(n){return n instanceof e&&n.suppressUnhandledRejections(),this._then(t,void 0,void 0,{value:n},void 0)},e.prototype.throw=e.prototype.thenThrow=function(e){return this._then(n,void 0,void 0,{reason:e},void 0)},e.prototype.catchThrow=function(e){if(arguments.length<=1)return this._then(void 0,n,void 0,{reason:e},void 0);var t=arguments[1],r=function(){throw t};return this.caught(e,r)},e.prototype.catchReturn=function(n){if(arguments.length<=1)return n instanceof e&&n.suppressUnhandledRejections(),this._then(void 0,t,void 0,{value:n},void 0);var r=arguments[1];r instanceof e&&r.suppressUnhandledRejections();var i=function(){return r};return this.caught(n,i)}}},{}],11:[function(e,t,n){"use strict";t.exports=function(e,t){function n(){return o(this)}function r(e,n){return i(e,n,t,t)}var i=e.reduce,o=e.all;e.prototype.each=function(e){return i(this,e,t,0)._then(n,void 0,void 0,this,void 0)},e.prototype.mapSeries=function(e){return i(this,e,t,t)},e.each=function(e,r){return i(e,r,t,0)._then(n,void 0,void 0,e,void 0)},e.mapSeries=r}},{}],12:[function(e,t,n){"use strict";function r(e,t){function n(r){if(!(this instanceof n))return new n(r);f(this,"message","string"==typeof r?r:t),f(this,"name",e),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):Error.call(this)}return l(n,Error),n}function i(e){if(!(this instanceof i))return new i(e);f(this,"name","OperationalError"),f(this,"message",e),this.cause=e,this.isOperational=!0,e instanceof Error?(f(this,"message",e.message),f(this,"stack",e.stack)):Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}var o,s,a=e("./es5"),u=a.freeze,c=e("./util"),l=c.inherits,f=c.notEnumerableProp,h=r("Warning","warning"),d=r("CancellationError","cancellation error"),p=r("TimeoutError","timeout error"),m=r("AggregateError","aggregate error");try{o=TypeError,s=RangeError}catch(e){o=r("TypeError","type error"),s=r("RangeError","range error")}for(var v="join pop push shift unshift slice filter forEach some every map indexOf lastIndexOf reduce reduceRight sort reverse".split(" "),b=0;b1?e.cancelPromise._reject(t):e.cancelPromise._cancel(),e.cancelPromise=null,!0)}function s(){return u.call(this,this.promise._target()._settledValue())}function a(e){if(!o(this,e))return f.e=e,f}function u(e){var r=this.promise,u=this.handler;if(!this.called){this.called=!0;var c=this.isFinallyHandler()?u.call(r._boundValue()):u.call(r._boundValue(),e);if(void 0!==c){r._setReturnedNonUndefined();var h=n(c,r);if(h instanceof t){if(null!=this.cancelPromise){if(h._isCancelled()){var d=new l("late cancellation observer");return r._attachExtraTrace(d),f.e=d,f}h.isPending()&&h._attachCancellationCallback(new i(this))}return h._then(s,a,void 0,this,void 0)}}}return r.isRejected()?(o(this),f.e=e,f):(o(this),e)}var c=e("./util"),l=t.CancellationError,f=c.errorObj;return r.prototype.isFinallyHandler=function(){return 0===this.type},i.prototype._resultCancelled=function(){o(this.finallyHandler)},t.prototype._passThrough=function(e,t,n,i){return"function"!=typeof e?this.then():this._then(n,i,void 0,new r(this,t,e),void 0)},t.prototype.lastly=t.prototype.finally=function(e){return this._passThrough(e,0,u,u)},t.prototype.tap=function(e){return this._passThrough(e,1,u)},r}},{"./util":36}],16:[function(e,t,n){"use strict";t.exports=function(t,n,r,i,o,s){function a(e,n,r){for(var o=0;o0&&"function"==typeof arguments[t]){e=arguments[t];var r}var i=[].slice.call(arguments);e&&i.pop();var r=new n(i).promise();return void 0!==e?r.spread(e):r}}},{"./util":36}],18:[function(e,t,n){"use strict";t.exports=function(t,n,r,i,o,s){function a(e,t,n,r){this.constructor$(e),this._promise._captureStackTrace();var i=c();this._callback=null===i?t:l.domainBind(i,t),this._preservedValues=r===o?new Array(this.length()):null,this._limit=n,this._inFlight=0,this._queue=[],d.invoke(this._asyncInit,this,void 0)}function u(e,n,i,o){if("function"!=typeof n)return r("expecting a function but got "+l.classString(n));var s=0;if(void 0!==i){if("object"!=typeof i||null===i)return t.reject(new TypeError("options argument must be an object but it is "+l.classString(i)));if("number"!=typeof i.concurrency)return t.reject(new TypeError("'concurrency' must be a number but it is "+l.classString(i.concurrency)));s=i.concurrency}return s="number"==typeof s&&isFinite(s)&&s>=1?s:0,new a(e,n,s,o).promise()}var c=t._getDomain,l=e("./util"),f=l.tryCatch,h=l.errorObj,d=t._async;l.inherits(a,n),a.prototype._asyncInit=function(){this._init$(void 0,-2)},a.prototype._init=function(){},a.prototype._promiseFulfilled=function(e,n){var r=this._values,o=this.length(),a=this._preservedValues,u=this._limit;if(n<0){if(n=-1*n-1,r[n]=e,u>=1&&(this._inFlight--,this._drainQueue(),this._isResolved()))return!0}else{if(u>=1&&this._inFlight>=u)return r[n]=e,this._queue.push(n),!1;null!==a&&(a[n]=e);var c=this._promise,l=this._callback,d=c._boundValue();c._pushContext();var p=f(l).call(d,e,n,o),m=c._popContext();if(s.checkForgottenReturns(p,m,null!==a?"Promise.filter":"Promise.map",c),p===h)return this._reject(p.e),!0;var v=i(p,this._promise);if(v instanceof t){v=v._target();var b=v._bitField;if(0==(50397184&b))return u>=1&&this._inFlight++,r[n]=v,v._proxy(this,-1*(n+1)),!1;if(0==(33554432&b))return 0!=(16777216&b)?(this._reject(v._reason()),!0):(this._cancel(),!0);p=v._value()}r[n]=p}return++this._totalResolved>=o&&(null!==a?this._filter(r,a):this._resolve(r),!0)},a.prototype._drainQueue=function(){for(var e=this._queue,t=this._limit,n=this._values;e.length>0&&this._inFlight1){o.deprecated("calling Promise.try with more than 1 argument");var c=arguments[1],l=arguments[2];u=s.isArray(c)?a(e).apply(l,c):a(e).call(l,c)}else u=a(e)();var f=r._popContext();return o.checkForgottenReturns(u,f,"Promise.try",r),r._resolveFromSyncValue(u),r},t.prototype._resolveFromSyncValue=function(e){e===s.errorObj?this._rejectCallback(e.e,!1):this._resolveCallback(e,!0)}}},{"./util":36}],20:[function(e,t,n){"use strict";function r(e){return e instanceof Error&&l.getPrototypeOf(e)===Error.prototype}function i(e){var t;if(r(e)){t=new c(e),t.name=e.name,t.message=e.message,t.stack=e.stack;for(var n=l.keys(e),i=0;i1){var n,r=new Array(t-1),i=0;for(n=0;n0&&"function"!=typeof e&&"function"!=typeof t){var n=".then() only accepts functions but was passed: "+p.classString(e);arguments.length>1&&(n+=", "+p.classString(t)),this._warn(n)}return this._then(e,t,void 0,void 0,void 0)},o.prototype.done=function(e,t){this._then(e,t,void 0,void 0,void 0)._setIsFinal()},o.prototype.spread=function(e){return"function"!=typeof e?h("expecting a function but got "+p.classString(e)):this.all()._then(e,void 0,void 0,w,void 0)},o.prototype.toJSON=function(){var e={isFulfilled:!1,isRejected:!1,fulfillmentValue:void 0,rejectionReason:void 0};return this.isFulfilled()?(e.fulfillmentValue=this.value(),e.isFulfilled=!0):this.isRejected()&&(e.rejectionReason=this.reason(),e.isRejected=!0),e},o.prototype.all=function(){return arguments.length>0&&this._warn(".all() was passed arguments but it does not take any"),new j(this).promise()},o.prototype.error=function(e){return this.caught(p.originatesFromRejection,e)},o.getNewLibraryCopy=t.exports,o.is=function(e){return e instanceof o},o.fromNode=o.fromCallback=function(e){var t=new o(k);t._captureStackTrace();var n=arguments.length>1&&!!Object(arguments[1]).multiArgs,r=O(e)(I(t,n));return r===P&&t._rejectCallback(r.e,!0),t._isFateSealed()||t._setAsyncGuaranteed(),t},o.all=function(e){return new j(e).promise()},o.cast=function(e){var t=x(e);return t instanceof o||(t=new o(k),t._captureStackTrace(),t._setFulfilled(),t._rejectionHandler0=e),t},o.resolve=o.fulfilled=o.cast,o.reject=o.rejected=function(e){var t=new o(k);return t._captureStackTrace(),t._rejectCallback(e,!0),t},o.setScheduler=function(e){if("function"!=typeof e)throw new _("expecting a function but got "+p.classString(e));return b.setScheduler(e)},o.prototype._then=function(e,t,n,r,i){var s=void 0!==i,a=s?i:new o(k),u=this._target(),l=u._bitField;s||(a._propagateFrom(this,3),a._captureStackTrace(),void 0===r&&0!=(2097152&this._bitField)&&(r=0!=(50397184&l)?this._boundValue():u===this?void 0:this._boundTo),this._fireEvent("promiseChained",this,a));var f=c();if(0!=(50397184&l)){var h,d,m=u._settlePromiseCtx;0!=(33554432&l)?(d=u._rejectionHandler0,h=e):0!=(16777216&l)?(d=u._fulfillmentHandler0,h=t,u._unsetRejectionIsUnhandled()):(m=u._settlePromiseLateCancellationObserver,d=new g("late cancellation observer"),u._attachExtraTrace(d),h=t),b.invoke(m,u,{handler:null===f?h:"function"==typeof h&&p.domainBind(f,h),promise:a,receiver:r,value:d})}else u._addCallbacks(e,t,a,r,f);return a},o.prototype._length=function(){return 65535&this._bitField},o.prototype._isFateSealed=function(){return 0!=(117506048&this._bitField)},o.prototype._isFollowing=function(){return 67108864==(67108864&this._bitField)},o.prototype._setLength=function(e){this._bitField=-65536&this._bitField|65535&e},o.prototype._setFulfilled=function(){this._bitField=33554432|this._bitField,this._fireEvent("promiseFulfilled",this)},o.prototype._setRejected=function(){this._bitField=16777216|this._bitField,this._fireEvent("promiseRejected",this)},o.prototype._setFollowing=function(){this._bitField=67108864|this._bitField,this._fireEvent("promiseResolved",this)},o.prototype._setIsFinal=function(){this._bitField=4194304|this._bitField},o.prototype._isFinal=function(){return(4194304&this._bitField)>0},o.prototype._unsetCancelled=function(){this._bitField=-65537&this._bitField},o.prototype._setCancelled=function(){this._bitField=65536|this._bitField,this._fireEvent("promiseCancelled",this)},o.prototype._setWillBeCancelled=function(){this._bitField=8388608|this._bitField},o.prototype._setAsyncGuaranteed=function(){b.hasCustomScheduler()||(this._bitField=134217728|this._bitField)},o.prototype._receiverAt=function(e){var t=0===e?this._receiver0:this[4*e-4+3];if(t!==d)return void 0===t&&this._isBound()?this._boundValue():t},o.prototype._promiseAt=function(e){return this[4*e-4+2]},o.prototype._fulfillmentHandlerAt=function(e){return this[4*e-4+0]},o.prototype._rejectionHandlerAt=function(e){return this[4*e-4+1]},o.prototype._boundValue=function(){},o.prototype._migrateCallback0=function(e){var t=(e._bitField,e._fulfillmentHandler0),n=e._rejectionHandler0,r=e._promise0,i=e._receiverAt(0);void 0===i&&(i=d),this._addCallbacks(t,n,r,i,null)},o.prototype._migrateCallbackAt=function(e,t){var n=e._fulfillmentHandlerAt(t),r=e._rejectionHandlerAt(t),i=e._promiseAt(t),o=e._receiverAt(t);void 0===o&&(o=d),this._addCallbacks(n,r,i,o,null)},o.prototype._addCallbacks=function(e,t,n,r,i){var o=this._length();if(o>=65531&&(o=0,this._setLength(0)),0===o)this._promise0=n,this._receiver0=r,"function"==typeof e&&(this._fulfillmentHandler0=null===i?e:p.domainBind(i,e)),"function"==typeof t&&(this._rejectionHandler0=null===i?t:p.domainBind(i,t));else{var s=4*o-4;this[s+2]=n,this[s+3]=r,"function"==typeof e&&(this[s+0]=null===i?e:p.domainBind(i,e)),"function"==typeof t&&(this[s+1]=null===i?t:p.domainBind(i,t))}return this._setLength(o+1),o},o.prototype._proxy=function(e,t){this._addCallbacks(void 0,void 0,t,e,null)},o.prototype._resolveCallback=function(e,t){if(0==(117506048&this._bitField)){if(e===this)return this._rejectCallback(l(),!1);var n=x(e,this);if(!(n instanceof o))return this._fulfill(e);t&&this._propagateFrom(n,2);var r=n._target();if(r===this)return void this._reject(l());var i=r._bitField;if(0==(50397184&i)){var s=this._length();s>0&&r._migrateCallback0(this);for(var a=1;a>>16)){if(e===this){var n=l();return this._attachExtraTrace(n),this._reject(n)}this._setFulfilled(),this._rejectionHandler0=e,(65535&t)>0&&(0!=(134217728&t)?this._settlePromises():b.settlePromises(this))}},o.prototype._reject=function(e){var t=this._bitField;if(!((117506048&t)>>>16)){if(this._setRejected(),this._fulfillmentHandler0=e,this._isFinal())return b.fatalError(e,p.isNode);(65535&t)>0?b.settlePromises(this):this._ensurePossibleRejectionHandled()}},o.prototype._fulfillPromises=function(e,t){for(var n=1;n0){if(0!=(16842752&e)){var n=this._fulfillmentHandler0;this._settlePromise0(this._rejectionHandler0,n,e),this._rejectPromises(t,n)}else{var r=this._rejectionHandler0;this._settlePromise0(this._fulfillmentHandler0,r,e),this._fulfillPromises(t,r)}this._setLength(0)}this._clearCancellationData()},o.prototype._settledValue=function(){var e=this._bitField;return 0!=(33554432&e)?this._rejectionHandler0:0!=(16777216&e)?this._fulfillmentHandler0:void 0},o.defer=o.pending=function(){return T.deprecated("Promise.defer","new Promise"),{promise:new o(k),resolve:s,reject:a}},p.notEnumerableProp(o,"_makeSelfResolutionError",l),e("./method")(o,k,x,h,T),e("./bind")(o,k,x,T),e("./cancel")(o,j,h,T),e("./direct_resolve")(o),e("./synchronous_inspection")(o),e("./join")(o,j,x,k,b,c),o.Promise=o,o.version="3.4.7",e("./map.js")(o,j,h,x,k,T),e("./call_get.js")(o),e("./using.js")(o,h,x,S,k,T),e("./timers.js")(o,k,T),e("./generators.js")(o,h,k,x,n,T),e("./nodeify.js")(o),e("./promisify.js")(o,k),e("./props.js")(o,j,x,h),e("./race.js")(o,k,x,h),e("./reduce.js")(o,j,h,x,k,T),e("./settle.js")(o,j,T),e("./some.js")(o,j,h),e("./filter.js")(o,k),e("./each.js")(o,k),e("./any.js")(o),p.toFastProperties(o),p.toFastProperties(o.prototype),u({a:1}),u({b:2}),u({c:3}),u(1),u(function(){}),u(void 0),u(!1),u(new o(k)),T.setBounds(v.firstLineError,p.lastLineError),o}},{"./any.js":1,"./async":2,"./bind":3,"./call_get.js":5,"./cancel":6,"./catch_filter":7,"./context":8,"./debuggability":9,"./direct_resolve":10,"./each.js":11,"./errors":12,"./es5":13,"./filter.js":14,"./finally":15,"./generators.js":16,"./join":17,"./map.js":18,"./method":19,"./nodeback":20,"./nodeify.js":21,"./promise_array":23,"./promisify.js":24,"./props.js":25,"./race.js":27,"./reduce.js":28,"./settle.js":30,"./some.js":31,"./synchronous_inspection":32,"./thenables":33,"./timers.js":34,"./using.js":35,"./util":36}],23:[function(e,t,n){"use strict";t.exports=function(t,n,r,i,o){function s(e){switch(e){case-2:return[];case-3:return{}}}function a(e){var r=this._promise=new t(n);e instanceof t&&r._propagateFrom(e,3),r._setOnCancel(this),this._values=e,this._length=0,this._totalResolved=0,this._init(void 0,-2)}var u=e("./util");u.isArray;return u.inherits(a,o),a.prototype.length=function(){return this._length},a.prototype.promise=function(){return this._promise},a.prototype._init=function e(n,o){var a=r(this._values,this._promise);if(a instanceof t){a=a._target();var c=a._bitField;if(this._values=a,0==(50397184&c))return this._promise._setAsyncGuaranteed(),a._then(e,this._reject,void 0,this,o);if(0==(33554432&c))return 0!=(16777216&c)?this._reject(a._reason()):this._cancel();a=a._value()}if(null===(a=u.asArray(a))){var l=i("expecting an array or an iterable object but got "+u.classString(a)).reason();return void this._promise._rejectCallback(l,!1)}if(0===a.length)return void(-5===o?this._resolveEmptyArray():this._resolve(s(o)));this._iterate(a)},a.prototype._iterate=function(e){var n=this.getActualLength(e.length);this._length=n,this._values=this.shouldCopyValues()?new Array(n):this._values;for(var i=this._promise,o=!1,s=null,a=0;a=this._length&&(this._resolve(this._values),!0)},a.prototype._promiseCancelled=function(){return this._cancel(),!0},a.prototype._promiseRejected=function(e){return this._totalResolved++,this._reject(e),!0},a.prototype._resultCancelled=function(){if(!this._isResolved()){var e=this._values;if(this._cancel(),e instanceof t)e.cancel();else for(var n=0;n=this._length){var n;if(this._isMap)n=h(this._values);else{n={};for(var r=this.length(),i=0,o=this.length();i>1},t.prototype.props=function(){return s(this)},t.props=function(e){return s(e)}}},{"./es5":13,"./util":36}],26:[function(e,t,n){"use strict";function r(e,t,n,r,i){for(var o=0;o=this._length&&(this._resolve(this._values),!0)},i.prototype._promiseFulfilled=function(e,t){var n=new o;return n._bitField=33554432,n._settledValueField=e,this._promiseResolved(t,n)},i.prototype._promiseRejected=function(e,t){var n=new o;return n._bitField=16777216,n._settledValueField=e,this._promiseResolved(t,n)},t.settle=function(e){return r.deprecated(".settle()",".reflect()"),new i(e).promise()},t.prototype.settle=function(){return t.settle(this)}}},{"./util":36}],31:[function(e,t,n){"use strict";t.exports=function(t,n,r){function i(e){this.constructor$(e),this._howMany=0,this._unwrap=!1,this._initialized=!1}function o(e,t){if((0|t)!==t||t<0)return r("expecting a positive integer\n\n See http://goo.gl/MqrFmX\n");var n=new i(e),o=n.promise();return n.setHowMany(t),n.init(),o}var s=e("./util"),a=e("./errors").RangeError,u=e("./errors").AggregateError,c=s.isArray,l={};s.inherits(i,n),i.prototype._init=function(){if(this._initialized){if(0===this._howMany)return void this._resolve([]);this._init$(void 0,-5);var e=c(this._values);!this._isResolved()&&e&&this._howMany>this._canPossiblyFulfill()&&this._reject(this._getRangeError(this.length()))}},i.prototype.init=function(){this._initialized=!0,this._init()},i.prototype.setUnwrap=function(){this._unwrap=!0},i.prototype.howMany=function(){return this._howMany},i.prototype.setHowMany=function(e){ this._howMany=e},i.prototype._promiseFulfilled=function(e){return this._addFulfilled(e),this._fulfilled()===this.howMany()&&(this._values.length=this.howMany(),1===this.howMany()&&this._unwrap?this._resolve(this._values[0]):this._resolve(this._values),!0)},i.prototype._promiseRejected=function(e){return this._addRejected(e),this._checkOutcome()},i.prototype._promiseCancelled=function(){return this._values instanceof t||null==this._values?this._cancel():(this._addRejected(l),this._checkOutcome())},i.prototype._checkOutcome=function(){if(this.howMany()>this._canPossiblyFulfill()){for(var e=new u,t=this.length();t0?this._reject(e):this._cancel(),!0}return!1},i.prototype._fulfilled=function(){return this._totalResolved},i.prototype._rejected=function(){return this._values.length-this.length()},i.prototype._addRejected=function(e){this._values.push(e)},i.prototype._addFulfilled=function(e){this._values[this._totalResolved++]=e},i.prototype._canPossiblyFulfill=function(){return this.length()-this._rejected()},i.prototype._getRangeError=function(e){var t="Input array must contain at least "+this._howMany+" items but contains only "+e+" items";return new a(t)},i.prototype._resolveEmptyArray=function(){this._reject(this._getRangeError(0))},t.some=function(e,t){return o(e,t)},t.prototype.some=function(e){return o(this,e)},t._SomePromiseArray=i}},{"./errors":12,"./util":36}],32:[function(e,t,n){"use strict";t.exports=function(e){function t(e){void 0!==e?(e=e._target(),this._bitField=e._bitField,this._settledValueField=e._isFateSealed()?e._settledValue():void 0):(this._bitField=0,this._settledValueField=void 0)}t.prototype._settledValue=function(){return this._settledValueField};var n=t.prototype.value=function(){if(!this.isFulfilled())throw new TypeError("cannot get fulfillment value of a non-fulfilled promise\n\n See http://goo.gl/MqrFmX\n");return this._settledValue()},r=t.prototype.error=t.prototype.reason=function(){if(!this.isRejected())throw new TypeError("cannot get rejection reason of a non-rejected promise\n\n See http://goo.gl/MqrFmX\n");return this._settledValue()},i=t.prototype.isFulfilled=function(){return 0!=(33554432&this._bitField)},o=t.prototype.isRejected=function(){return 0!=(16777216&this._bitField)},s=t.prototype.isPending=function(){return 0==(50397184&this._bitField)},a=t.prototype.isResolved=function(){return 0!=(50331648&this._bitField)};t.prototype.isCancelled=function(){return 0!=(8454144&this._bitField)},e.prototype.__isCancelled=function(){return 65536==(65536&this._bitField)},e.prototype._isCancelled=function(){return this._target().__isCancelled()},e.prototype.isCancelled=function(){return 0!=(8454144&this._target()._bitField)},e.prototype.isPending=function(){return s.call(this._target())},e.prototype.isRejected=function(){return o.call(this._target())},e.prototype.isFulfilled=function(){return i.call(this._target())},e.prototype.isResolved=function(){return a.call(this._target())},e.prototype.value=function(){return n.call(this._target())},e.prototype.reason=function(){var e=this._target();return e._unsetRejectionIsUnhandled(),r.call(e)},e.prototype._value=function(){return this._settledValue()},e.prototype._reason=function(){return this._unsetRejectionIsUnhandled(),this._settledValue()},e.PromiseInspection=t}},{}],33:[function(e,t,n){"use strict";t.exports=function(t,n){function r(e,r){if(l(e)){if(e instanceof t)return e;var i=o(e);if(i===c){r&&r._pushContext();var u=t.reject(i.e);return r&&r._popContext(),u}if("function"==typeof i){if(s(e)){var u=new t(n);return e._then(u._fulfill,u._reject,void 0,u,null),u}return a(e,i,r)}}return e}function i(e){return e.then}function o(e){try{return i(e)}catch(e){return c.e=e,c}}function s(e){try{return f.call(e,"_promise0")}catch(e){return!1}}function a(e,r,i){function o(e){a&&(a._resolveCallback(e),a=null)}function s(e){a&&(a._rejectCallback(e,f,!0),a=null)}var a=new t(n),l=a;i&&i._pushContext(),a._captureStackTrace(),i&&i._popContext();var f=!0,h=u.tryCatch(r).call(e,o,s);return f=!1,a&&h===c&&(a._rejectCallback(h.e,!0,!0),a=null),l}var u=e("./util"),c=u.errorObj,l=u.isObject,f={}.hasOwnProperty;return r}},{"./util":36}],34:[function(e,t,n){"use strict";t.exports=function(t,n,r){function i(e){this.handle=e}function o(e){return clearTimeout(this.handle),e}function s(e){throw clearTimeout(this.handle),e}var a=e("./util"),u=t.TimeoutError;i.prototype._resultCancelled=function(){clearTimeout(this.handle)};var c=function(e){return l(+this).thenReturn(e)},l=t.delay=function(e,o){var s,a;return void 0!==o?(s=t.resolve(o)._then(c,null,null,e,void 0),r.cancellation()&&o instanceof t&&s._setOnCancel(o)):(s=new t(n),a=setTimeout(function(){s._fulfill()},+e),r.cancellation()&&s._setOnCancel(new i(a)),s._captureStackTrace()),s._setAsyncGuaranteed(),s};t.prototype.delay=function(e){return l(e,this)};var f=function(e,t,n){var r;r="string"!=typeof t?t instanceof Error?t:new u("operation timed out"):new u(t),a.markAsOriginatingFromRejection(r),e._attachExtraTrace(r),e._reject(r),null!=n&&n.cancel()};t.prototype.timeout=function(e,t){e=+e;var n,a,u=new i(setTimeout(function(){n.isPending()&&f(n,t,a)},e));return r.cancellation()?(a=this.then(),n=a._then(o,s,void 0,u,void 0),n._setOnCancel(u)):n=this._then(o,s,void 0,u,void 0),n}}},{"./util":36}],35:[function(e,t,n){"use strict";t.exports=function(t,n,r,i,o,s){function a(e){setTimeout(function(){throw e},0)}function u(e){var t=r(e);return t!==e&&"function"==typeof e._isDisposable&&"function"==typeof e._getDisposer&&e._isDisposable()&&t._setDisposable(e._getDisposer()),t}function c(e,n){function i(){if(s>=c)return l._fulfill();var o=u(e[s++]);if(o instanceof t&&o._isDisposable()){try{o=r(o._getDisposer().tryDispose(n),e.promise)}catch(e){return a(e)}if(o instanceof t)return o._then(i,a,null,null,null)}i()}var s=0,c=e.length,l=new t(o);return i(),l}function l(e,t,n){this._data=e,this._promise=t,this._context=n}function f(e,t,n){this.constructor$(e,t,n)}function h(e){return l.isDisposer(e)?(this.resources[this.index]._setDisposable(e),e.promise()):e}function d(e){this.length=e,this.promise=null,this[e-1]=null}var p=e("./util"),m=e("./errors").TypeError,v=e("./util").inherits,b=p.errorObj,y=p.tryCatch,_={};l.prototype.data=function(){return this._data},l.prototype.promise=function(){return this._promise},l.prototype.resource=function(){return this.promise().isFulfilled()?this.promise().value():_},l.prototype.tryDispose=function(e){var t=this.resource(),n=this._context;void 0!==n&&n._pushContext();var r=t!==_?this.doDispose(t,e):null;return void 0!==n&&n._popContext(),this._promise._unsetDisposable(),this._data=null,r},l.isDisposer=function(e){return null!=e&&"function"==typeof e.resource&&"function"==typeof e.tryDispose},v(f,l),f.prototype.doDispose=function(e,t){return this.data().call(e,e,t)},d.prototype._resultCancelled=function(){for(var e=this.length,n=0;n0},t.prototype._getDisposer=function(){return this._disposer},t.prototype._unsetDisposable=function(){this._bitField=-131073&this._bitField,this._disposer=void 0},t.prototype.disposer=function(e){if("function"==typeof e)return new f(e,this,i());throw new m}}},{"./errors":12,"./util":36}],36:[function(e,t,n){"use strict";function r(){try{var e=I;return I=null,e.apply(this,arguments)}catch(e){return A.e=e,A}}function s(e){return I=e,r}function a(e){return null==e||!0===e||!1===e||"string"==typeof e||"number"==typeof e}function u(e){return"function"==typeof e||"object"==typeof e&&null!==e}function c(e){return a(e)?new Error(y(e)):e}function l(e,t){var n,r=e.length,i=new Array(r+1);for(n=0;n1,r=t.length>0&&!(1===t.length&&"constructor"===t[0]),i=N.test(e+"")&&T.names(e).length>0;if(n||r||i)return!0}return!1}catch(e){return!1}}function m(e){function t(){}t.prototype=e;for(var n=8;n--;)new t;return e}function v(e){return F.test(e)}function b(e,t,n){for(var r=new Array(e),i=0;i10||e[0]>0}(),z.isNode&&z.toFastProperties(i);try{throw new Error}catch(e){z.lastLineError=e}t.exports=z},{"./es5":13}]},{},[4])(4)}),"undefined"!=typeof window&&null!==window?window.P=window.Promise:"undefined"!=typeof self&&null!==self&&(self.P=self.Promise)}).call(this,t("_process"),"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{_process:211}],64:[function(e,t,n){(function(){var n,r,i,o=function(e,t){return function(){return e.apply(t,arguments)}},s=[].slice;i=10,r=5,n=function(){function t(e,n,r,i,s){this.maxNb=null!=e?e:0,this.minTime=null!=n?n:0,this.highWater=null!=r?r:-1,this.strategy=null!=i?i:t.prototype.strategy.LEAK,this.rejectOnDrop=null!=s&&s,this.schedulePriority=o(this.schedulePriority,this),this.submitPriority=o(this.submitPriority,this),this.submit=o(this.submit,this),this._nextRequest=Date.now(),this._nbRunning=0,this._queues=this._makeQueues(),this._running={},this._nextIndex=0,this._unblockTime=0,this.penalty=15*this.minTime||5e3,this.interrupt=!1,this.reservoir=null,this.limiter=null,this.events={}}var n;return t.strategy=t.prototype.strategy={LEAK:1,OVERFLOW:2,OVERFLOW_PRIORITY:4,BLOCK:3},t.Cluster=t.prototype.Cluster=e("./Cluster"),t.DLList=t.prototype.DLList=e("./DLList"),t.Promise=t.prototype.Promise=function(){try{return e("bluebird")}catch(e){return n=e,"undefined"!=typeof Promise&&null!==Promise?Promise:function(){throw new Error("Bottleneck: install 'bluebird' or use Node 0.12 or higher for Promise support")}}}(),t.prototype._trigger=function(e,t){return this.rejectOnDrop&&"dropped"===e&&t[0].cb.apply({},[new Error("This job has been dropped by Bottleneck")]),setTimeout(function(n){return function(){var r;return null!=(r=n.events[e])?r.forEach(function(e){return e.apply({},t)}):void 0}}(this),0)},t.prototype._makeQueues=function(){var e,n,r;for(r=[],e=1,n=i;1<=n?e<=n:e>=n;1<=n?++e:--e)r.push(new t.prototype.DLList);return r},t.prototype.chain=function(e){return this.limiter=e,this},t.prototype.isBlocked=function(){return this._unblockTime>=Date.now()},t.prototype._sanitizePriority=function(e){var t;return t=~~e!==e?r:e,t<0?0:t>i-1?i-1:t},t.prototype._find=function(e,t){var n,r,i,o;for(n=r=0,i=e.length;r0})},t.prototype._conditionsCheck=function(){return(this.nbRunning()0)},t.prototype.check=function(){return this._conditionsCheck()&&this._nextRequest-Date.now()<=0},t.prototype._tryToRun=function(){var e,t,n,r,i;return!!(this._conditionsCheck()&&(r=this.nbQueued())>0)&&(this._nbRunning++,null!=this.reservoir&&this.reservoir--,i=Math.max(this._nextRequest-Date.now(),0),this._nextRequest=Date.now()+i+this.minTime,n=this._getFirst(this._queues).shift(),1===r&&this._trigger("empty",[]),e=!1,t=this._nextIndex++,this._running[t]={timeout:setTimeout(function(r){return function(){var i;return i=function(){var i;if(!e&&(e=!0,delete r._running[t],r._nbRunning--,r._tryToRun(),0===r.nbRunning()&&0===r.nbQueued()&&r._trigger("idle",[]),!r.interrupt))return null!=(i=n.cb)?i.apply({},Array.prototype.slice.call(arguments,0)):void 0},null!=r.limiter?r.limiter.submit.apply(r.limiter,Array.prototype.concat(n.task,n.args,i)):n.task.apply({},n.args.concat(i))}}(this),i),job:n},!0)},t.prototype.submit=function(){var e;return e=1<=arguments.length?s.call(arguments,0):[],this.submitPriority.apply({},Array.prototype.concat(r,e))},t.prototype.submitPriority=function(){var e,n,r,i,o,a,u,c;return o=arguments[0],c=arguments[1],e=4<=arguments.length?s.call(arguments,2,r=arguments.length-1):(r=2,[]),n=arguments[r++],i={task:c,args:e,cb:n},o=this._sanitizePriority(o),a=this.highWater>=0&&this.nbQueued()===this.highWater&&!this.check(),this.strategy===t.prototype.strategy.BLOCK&&(a||this.isBlocked())?(this._unblockTime=Date.now()+this.penalty,this._nextRequest=this._unblockTime+this.minTime,this._queues=this._makeQueues(),this._trigger("dropped",[i]),!0):a&&(u=this.strategy===t.prototype.strategy.LEAK?this._getFirst(this._queues.slice(o).reverse()).shift():this.strategy===t.prototype.strategy.OVERFLOW_PRIORITY?this._getFirst(this._queues.slice(o+1).reverse()).shift():this.strategy===t.prototype.strategy.OVERFLOW?i:void 0,null!=u&&this._trigger("dropped",[u]),null==u||this.strategy===t.prototype.strategy.OVERFLOW)?a:(this._queues[o].push(i),this._tryToRun(),a)},t.prototype.schedule=function(){var e;return e=1<=arguments.length?s.call(arguments,0):[],this.schedulePriority.apply({},Array.prototype.concat(r,e))},t.prototype.schedulePriority=function(){var e,n,r,i;return n=arguments[0],r=arguments[1],e=3<=arguments.length?s.call(arguments,2):[],i=function(){var e,t,n;return e=2<=arguments.length?s.call(arguments,0,n=arguments.length-1):(n=0,[]),t=arguments[n++],r.apply({},e).then(function(){var e;return e=1<=arguments.length?s.call(arguments,0):[],t.apply({},Array.prototype.concat(null,e))}).catch(function(){var e;return e=1<=arguments.length?s.call(arguments,0):[],t.apply({},e)})},new t.prototype.Promise(function(t){return function(r,o){return t.submitPriority.apply({},Array.prototype.concat(n,i,e,function(){var e;return e=1<=arguments.length?s.call(arguments,0):[],(null!=e[0]?o:(e.shift(),r)).apply({},e)}))}}(this))},t.prototype.changeSettings=function(e,t,n,r,i){for(this.maxNb=null!=e?e:this.maxNb,this.minTime=null!=t?t:this.minTime,this.highWater=null!=n?n:this.highWater,this.strategy=null!=r?r:this.strategy,this.rejectOnDrop=null!=i?i:this.rejectOnDrop;this._tryToRun(););return this},t.prototype.changePenalty=function(e){return this.penalty=null!=e?e:this.penalty,this},t.prototype.changeReservoir=function(e){for(this.reservoir=e;this._tryToRun(););return this},t.prototype.incrementReservoir=function(e){return null==e&&(e=0),this.changeReservoir(this.reservoir+e),this},t.prototype.on=function(e,t){return null!=this.events[e]?this.events[e].push(t):this.events[e]=[t],this},t.prototype.removeAllListeners=function(e){return null==e&&(e=null),null!=e?delete this.events[e]:this.events={},this},t.prototype.stopAll=function(e){var t,n,r,i,o,a,u;for(this.interrupt=null!=e?e:this.interrupt,i=Object.keys(this._running),t=0,a=i.length;t * @license MIT */ "use strict";function r(e){if(e>K)throw new RangeError("Invalid typed array length");var t=new Uint8Array(e);return t.__proto__=i.prototype,t}function i(e,t,n){if("number"==typeof e){if("string"==typeof t)throw new Error("If encoding is specified then the first argument must be a string");return u(e)}return o(e,t,n)}function o(e,t,n){if("number"==typeof e)throw new TypeError('"value" argument must not be a number');return e instanceof ArrayBuffer?f(e,t,n):"string"==typeof e?c(e,t):h(e)}function s(e){if("number"!=typeof e)throw new TypeError('"size" argument must be a number');if(e<0)throw new RangeError('"size" argument must not be negative')}function a(e,t,n){return s(e),e<=0?r(e):void 0!==t?"string"==typeof n?r(e).fill(t,n):r(e).fill(t):r(e)}function u(e){return s(e),r(e<0?0:0|d(e))}function c(e,t){if("string"==typeof t&&""!==t||(t="utf8"),!i.isEncoding(t))throw new TypeError('"encoding" must be a valid string encoding');var n=0|m(e,t),o=r(n),s=o.write(e,t);return s!==n&&(o=o.slice(0,s)),o}function l(e){for(var t=e.length<0?0:0|d(e.length),n=r(t),i=0;i=K)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+K.toString(16)+" bytes");return 0|e}function p(e){return+e!=e&&(e=0),i.alloc(+e)}function m(e,t){if(i.isBuffer(e))return e.length;if(V(e)||e instanceof ArrayBuffer)return e.byteLength;"string"!=typeof e&&(e=""+e);var n=e.length;if(0===n)return 0;for(var r=!1;;)switch(t){case"ascii":case"latin1":case"binary":return n;case"utf8":case"utf-8":case void 0:return B(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*n;case"hex":return n>>>1;case"base64":return H(e).length;default:if(r)return B(e).length;t=(""+t).toLowerCase(),r=!0}}function v(e,t,n){var r=!1;if((void 0===t||t<0)&&(t=0),t>this.length)return"";if((void 0===n||n>this.length)&&(n=this.length),n<=0)return"";if(n>>>=0,t>>>=0,n<=t)return"";for(e||(e="utf8");;)switch(e){case"hex":return I(this,t,n);case"utf8":case"utf-8":return S(this,t,n);case"ascii":return R(this,t,n);case"latin1":case"binary":return A(this,t,n);case"base64":return E(this,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return P(this,t,n);default:if(r)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),r=!0}}function b(e,t,n){var r=e[t];e[t]=e[n],e[n]=r}function y(e,t,n,r,o){if(0===e.length)return-1;if("string"==typeof n?(r=n,n=0):n>2147483647?n=2147483647:n<-2147483648&&(n=-2147483648),n=+n,G(n)&&(n=o?0:e.length-1),n<0&&(n=e.length+n),n>=e.length){if(o)return-1;n=e.length-1}else if(n<0){if(!o)return-1;n=0}if("string"==typeof t&&(t=i.from(t,r)),i.isBuffer(t))return 0===t.length?-1:_(e,t,n,r,o);if("number"==typeof t)return t&=255,"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(e,t,n):Uint8Array.prototype.lastIndexOf.call(e,t,n):_(e,[t],n,r,o);throw new TypeError("val must be string, number or Buffer")}function _(e,t,n,r,i){function o(e,t){return 1===s?e[t]:e.readUInt16BE(t*s)}var s=1,a=e.length,u=t.length;if(void 0!==r&&("ucs2"===(r=String(r).toLowerCase())||"ucs-2"===r||"utf16le"===r||"utf-16le"===r)){if(e.length<2||t.length<2)return-1;s=2,a/=2,u/=2,n/=2}var c;if(i){var l=-1;for(c=n;ca&&(n=a-u),c=n;c>=0;c--){for(var f=!0,h=0;hi&&(r=i):r=i;var o=t.length;if(o%2!=0)throw new TypeError("Invalid hex string");r>o/2&&(r=o/2);for(var s=0;s239?4:o>223?3:o>191?2:1;if(i+a<=n){var u,c,l,f;switch(a){case 1:o<128&&(s=o);break;case 2:u=e[i+1],128==(192&u)&&(f=(31&o)<<6|63&u)>127&&(s=f);break;case 3:u=e[i+1],c=e[i+2],128==(192&u)&&128==(192&c)&&(f=(15&o)<<12|(63&u)<<6|63&c)>2047&&(f<55296||f>57343)&&(s=f);break;case 4:u=e[i+1],c=e[i+2],l=e[i+3],128==(192&u)&&128==(192&c)&&128==(192&l)&&(f=(15&o)<<18|(63&u)<<12|(63&c)<<6|63&l)>65535&&f<1114112&&(s=f)}}null===s?(s=65533,a=1):s>65535&&(s-=65536,r.push(s>>>10&1023|55296),s=56320|1023&s),r.push(s),i+=a}return T(r)}function T(e){var t=e.length;if(t<=Q)return String.fromCharCode.apply(String,e);for(var n="",r=0;rr)&&(n=r);for(var i="",o=t;on)throw new RangeError("Trying to access beyond buffer length")}function M(e,t,n,r,o,s){if(!i.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>o||te.length)throw new RangeError("Index out of range")}function N(e,t,n,r,i,o){if(n+r>e.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("Index out of range")}function F(e,t,n,r,i){return t=+t,n>>>=0,i||N(e,t,n,4,3.4028234663852886e38,-3.4028234663852886e38),$.write(e,t,n,r,23,4),n+4}function U(e,t,n,r,i){return t=+t,n>>>=0,i||N(e,t,n,8,1.7976931348623157e308,-1.7976931348623157e308),$.write(e,t,n,r,52,8),n+8}function D(e){if(e=e.trim().replace(X,""),e.length<2)return"";for(;e.length%4!=0;)e+="=";return e}function L(e){return e<16?"0"+e.toString(16):e.toString(16)}function B(e,t){t=t||1/0;for(var n,r=e.length,i=null,o=[],s=0;s55295&&n<57344){if(!i){if(n>56319){(t-=3)>-1&&o.push(239,191,189);continue}if(s+1===r){(t-=3)>-1&&o.push(239,191,189);continue}i=n;continue}if(n<56320){(t-=3)>-1&&o.push(239,191,189),i=n;continue}n=65536+(i-55296<<10|n-56320)}else i&&(t-=3)>-1&&o.push(239,191,189);if(i=null,n<128){if((t-=1)<0)break;o.push(n)}else if(n<2048){if((t-=2)<0)break;o.push(n>>6|192,63&n|128)}else if(n<65536){if((t-=3)<0)break;o.push(n>>12|224,n>>6&63|128,63&n|128)}else{if(!(n<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;o.push(n>>18|240,n>>12&63|128,n>>6&63|128,63&n|128)}}return o}function q(e){for(var t=[],n=0;n>8,i=n%256,o.push(i),o.push(r);return o}function H(e){return J.toByteArray(D(e))}function W(e,t,n,r){for(var i=0;i=t.length||i>=e.length);++i)t[i+n]=e[i];return i}function V(e){return"function"==typeof ArrayBuffer.isView&&ArrayBuffer.isView(e)}function G(e){return e!==e}var J=e("base64-js"),$=e("ieee754");n.Buffer=i,n.SlowBuffer=p,n.INSPECT_MAX_BYTES=50;var K=2147483647;n.kMaxLength=K,i.TYPED_ARRAY_SUPPORT=function(){try{var e=new Uint8Array(1);return e.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},42===e.foo()}catch(e){return!1}}(),i.TYPED_ARRAY_SUPPORT||"undefined"==typeof console||"function"!=typeof console.error||console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."),"undefined"!=typeof Symbol&&Symbol.species&&i[Symbol.species]===i&&Object.defineProperty(i,Symbol.species,{value:null,configurable:!0,enumerable:!1,writable:!1}),i.poolSize=8192,i.from=function(e,t,n){return o(e,t,n)},i.prototype.__proto__=Uint8Array.prototype,i.__proto__=Uint8Array,i.alloc=function(e,t,n){return a(e,t,n)},i.allocUnsafe=function(e){return u(e)},i.allocUnsafeSlow=function(e){return u(e)},i.isBuffer=function(e){return null!=e&&!0===e._isBuffer},i.compare=function(e,t){if(!i.isBuffer(e)||!i.isBuffer(t))throw new TypeError("Arguments must be Buffers");if(e===t)return 0;for(var n=e.length,r=t.length,o=0,s=Math.min(n,r);o0&&(e=this.toString("hex",0,t).match(/.{2}/g).join(" "),this.length>t&&(e+=" ... ")),""},i.prototype.compare=function(e,t,n,r,o){if(!i.isBuffer(e))throw new TypeError("Argument must be a Buffer");if(void 0===t&&(t=0),void 0===n&&(n=e?e.length:0),void 0===r&&(r=0),void 0===o&&(o=this.length),t<0||n>e.length||r<0||o>this.length)throw new RangeError("out of range index");if(r>=o&&t>=n)return 0;if(r>=o)return-1;if(t>=n)return 1;if(t>>>=0,n>>>=0,r>>>=0,o>>>=0,this===e)return 0;for(var s=o-r,a=n-t,u=Math.min(s,a),c=this.slice(r,o),l=e.slice(t,n),f=0;f>>=0,isFinite(n)?(n>>>=0,void 0===r&&(r="utf8")):(r=n,n=void 0)}var i=this.length-t;if((void 0===n||n>i)&&(n=i),e.length>0&&(n<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");r||(r="utf8");for(var o=!1;;)switch(r){case"hex":return g(this,e,t,n);case"utf8":case"utf-8":return k(this,e,t,n);case"ascii":return w(this,e,t,n);case"latin1":case"binary":return C(this,e,t,n);case"base64":return x(this,e,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return j(this,e,t,n);default:if(o)throw new TypeError("Unknown encoding: "+r);r=(""+r).toLowerCase(),o=!0}},i.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var Q=4096;i.prototype.slice=function(e,t){var n=this.length;e=~~e,t=void 0===t?n:~~t,e<0?(e+=n)<0&&(e=0):e>n&&(e=n),t<0?(t+=n)<0&&(t=0):t>n&&(t=n),t>>=0,t>>>=0,n||O(e,t,this.length);for(var r=this[e],i=1,o=0;++o>>=0,t>>>=0,n||O(e,t,this.length);for(var r=this[e+--t],i=1;t>0&&(i*=256);)r+=this[e+--t]*i;return r},i.prototype.readUInt8=function(e,t){return e>>>=0,t||O(e,1,this.length),this[e]},i.prototype.readUInt16LE=function(e,t){return e>>>=0,t||O(e,2,this.length),this[e]|this[e+1]<<8},i.prototype.readUInt16BE=function(e,t){return e>>>=0,t||O(e,2,this.length),this[e]<<8|this[e+1]},i.prototype.readUInt32LE=function(e,t){return e>>>=0,t||O(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},i.prototype.readUInt32BE=function(e,t){return e>>>=0,t||O(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},i.prototype.readIntLE=function(e,t,n){e>>>=0,t>>>=0,n||O(e,t,this.length);for(var r=this[e],i=1,o=0;++o=i&&(r-=Math.pow(2,8*t)),r},i.prototype.readIntBE=function(e,t,n){e>>>=0,t>>>=0,n||O(e,t,this.length);for(var r=t,i=1,o=this[e+--r];r>0&&(i*=256);)o+=this[e+--r]*i;return i*=128,o>=i&&(o-=Math.pow(2,8*t)),o},i.prototype.readInt8=function(e,t){return e>>>=0,t||O(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},i.prototype.readInt16LE=function(e,t){e>>>=0,t||O(e,2,this.length);var n=this[e]|this[e+1]<<8;return 32768&n?4294901760|n:n},i.prototype.readInt16BE=function(e,t){e>>>=0,t||O(e,2,this.length);var n=this[e+1]|this[e]<<8;return 32768&n?4294901760|n:n},i.prototype.readInt32LE=function(e,t){return e>>>=0,t||O(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},i.prototype.readInt32BE=function(e,t){return e>>>=0,t||O(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},i.prototype.readFloatLE=function(e,t){return e>>>=0,t||O(e,4,this.length),$.read(this,e,!0,23,4)},i.prototype.readFloatBE=function(e,t){return e>>>=0,t||O(e,4,this.length),$.read(this,e,!1,23,4)},i.prototype.readDoubleLE=function(e,t){return e>>>=0,t||O(e,8,this.length),$.read(this,e,!0,52,8)},i.prototype.readDoubleBE=function(e,t){return e>>>=0,t||O(e,8,this.length),$.read(this,e,!1,52,8)},i.prototype.writeUIntLE=function(e,t,n,r){if(e=+e,t>>>=0,n>>>=0,!r){M(this,e,t,n,Math.pow(2,8*n)-1,0)}var i=1,o=0;for(this[t]=255&e;++o>>=0,n>>>=0,!r){M(this,e,t,n,Math.pow(2,8*n)-1,0)}var i=n-1,o=1;for(this[t+i]=255&e;--i>=0&&(o*=256);)this[t+i]=e/o&255;return t+n},i.prototype.writeUInt8=function(e,t,n){return e=+e,t>>>=0,n||M(this,e,t,1,255,0),this[t]=255&e,t+1},i.prototype.writeUInt16LE=function(e,t,n){return e=+e,t>>>=0,n||M(this,e,t,2,65535,0),this[t]=255&e,this[t+1]=e>>>8,t+2},i.prototype.writeUInt16BE=function(e,t,n){return e=+e,t>>>=0,n||M(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=255&e,t+2},i.prototype.writeUInt32LE=function(e,t,n){return e=+e,t>>>=0,n||M(this,e,t,4,4294967295,0),this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e,t+4},i.prototype.writeUInt32BE=function(e,t,n){return e=+e,t>>>=0,n||M(this,e,t,4,4294967295,0),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},i.prototype.writeIntLE=function(e,t,n,r){if(e=+e,t>>>=0,!r){var i=Math.pow(2,8*n-1);M(this,e,t,n,i-1,-i)}var o=0,s=1,a=0;for(this[t]=255&e;++o>0)-a&255;return t+n},i.prototype.writeIntBE=function(e,t,n,r){if(e=+e,t>>>=0,!r){var i=Math.pow(2,8*n-1);M(this,e,t,n,i-1,-i)}var o=n-1,s=1,a=0;for(this[t+o]=255&e;--o>=0&&(s*=256);)e<0&&0===a&&0!==this[t+o+1]&&(a=1),this[t+o]=(e/s>>0)-a&255;return t+n},i.prototype.writeInt8=function(e,t,n){return e=+e,t>>>=0,n||M(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=255&e,t+1},i.prototype.writeInt16LE=function(e,t,n){return e=+e,t>>>=0,n||M(this,e,t,2,32767,-32768),this[t]=255&e,this[t+1]=e>>>8,t+2},i.prototype.writeInt16BE=function(e,t,n){return e=+e,t>>>=0,n||M(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=255&e,t+2},i.prototype.writeInt32LE=function(e,t,n){return e=+e,t>>>=0,n||M(this,e,t,4,2147483647,-2147483648),this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24,t+4},i.prototype.writeInt32BE=function(e,t,n){return e=+e,t>>>=0,n||M(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},i.prototype.writeFloatLE=function(e,t,n){return F(this,e,t,!0,n)},i.prototype.writeFloatBE=function(e,t,n){return F(this,e,t,!1,n)},i.prototype.writeDoubleLE=function(e,t,n){return U(this,e,t,!0,n)},i.prototype.writeDoubleBE=function(e,t,n){return U(this,e,t,!1,n)},i.prototype.copy=function(e,t,n,r){if(n||(n=0),r||0===r||(r=this.length),t>=e.length&&(t=e.length),t||(t=0),r>0&&r=this.length)throw new RangeError("sourceStart out of bounds");if(r<0)throw new RangeError("sourceEnd out of bounds");r>this.length&&(r=this.length),e.length-t=0;--i)e[i+t]=this[i+n];else if(o<1e3)for(i=0;i>>=0,n=void 0===n?this.length:n>>>0,e||(e=0);var s;if("number"==typeof e)for(s=t;sl;)if((a=u[l++])!=a)return!0}else for(;c>l;l++)if((e||l in u)&&u[l]===n)return e||l||0;return!e&&-1}}},{"./_to-index":160,"./_to-iobject":162,"./_to-length":163}],95:[function(e,t,n){var r=e("./_ctx"),i=e("./_iobject"),o=e("./_to-object"),s=e("./_to-length"),a=e("./_array-species-create");t.exports=function(e,t){var n=1==e,u=2==e,c=3==e,l=4==e,f=6==e,h=5==e||f,d=t||a;return function(t,a,p){for(var m,v,b=o(t),y=i(b),_=r(a,p,3),g=s(y.length),k=0,w=n?d(t,g):u?d(t,0):void 0;g>k;k++)if((h||k in y)&&(m=y[k],v=_(m,k,b),e))if(n)w[k]=v;else if(v)switch(e){case 3:return!0;case 5:return m;case 6:return k;case 2:w.push(m)}else if(l)return!1;return f?-1:c||l?l:w}}},{"./_array-species-create":97,"./_ctx":106,"./_iobject":121,"./_to-length":163,"./_to-object":164}],96:[function(e,t,n){var r=e("./_is-object"),i=e("./_is-array"),o=e("./_wks")("species");t.exports=function(e){var t;return i(e)&&(t=e.constructor,"function"!=typeof t||t!==Array&&!i(t.prototype)||(t=void 0),r(t)&&null===(t=t[o])&&(t=void 0)),void 0===t?Array:t}},{"./_is-array":123,"./_is-object":125,"./_wks":169}],97:[function(e,t,n){var r=e("./_array-species-constructor");t.exports=function(e,t){return new(r(e))(t)}},{"./_array-species-constructor":96}],98:[function(e,t,n){"use strict";var r=e("./_a-function"),i=e("./_is-object"),o=e("./_invoke"),s=[].slice,a={},u=function(e,t,n){if(!(t in a)){for(var r=[],i=0;i1?arguments[1]:void 0,3);t=t?t.n:this._f;)for(n(t.v,t.k,this);t&&t.r;)t=t.p},has:function(e){return!!v(this,e)}}),d&&r(f.prototype,"size",{get:function(){return u(this[m])}}),f},def:function(e,t,n){var r,i,o=v(e,t);return o?o.v=n:(e._l=o={i:i=p(t,!0),k:t,v:n,p:r=e._l,n:void 0,r:!1},e._f||(e._f=o),r&&(r.n=o),e[m]++,"F"!==i&&(e._i[i]=o)),e},getEntry:v,setStrong:function(e,t,n){l(e,t,function(e,t){this._t=e,this._k=t,this._l=void 0},function(){for(var e=this,t=e._k,n=e._l;n&&n.r;)n=n.p;return e._t&&(e._l=n=n?n.n:e._t._f)?"keys"==t?f(0,n.k):"values"==t?f(0,n.v):f(0,[n.k,n.v]):(e._t=void 0,f(1))},n?"entries":"values",!n,!0),h(t)}}},{"./_an-instance":91,"./_ctx":106,"./_defined":107,"./_descriptors":108,"./_for-of":114,"./_iter-define":128,"./_iter-step":130,"./_meta":134,"./_object-create":137,"./_object-dp":138,"./_redefine-all":150,"./_set-species":153}],102:[function(e,t,n){var r=e("./_classof"),i=e("./_array-from-iterable");t.exports=function(e){return function(){if(r(this)!=e)throw TypeError(e+"#toJSON isn't generic");return i(this)}}},{"./_array-from-iterable":93,"./_classof":99}],103:[function(e,t,n){"use strict";var r=e("./_global"),i=e("./_export"),o=e("./_meta"),s=e("./_fails"),a=e("./_hide"),u=e("./_redefine-all"),c=e("./_for-of"),l=e("./_an-instance"),f=e("./_is-object"),h=e("./_set-to-string-tag"),d=e("./_object-dp").f,p=e("./_array-methods")(0),m=e("./_descriptors");t.exports=function(e,t,n,v,b,y){var _=r[e],g=_,k=b?"set":"add",w=g&&g.prototype,C={};return m&&"function"==typeof g&&(y||w.forEach&&!s(function(){(new g).entries().next()}))?(g=t(function(t,n){l(t,g,e,"_c"),t._c=new _,void 0!=n&&c(n,b,t[k],t)}),p("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(g.prototype,e,function(n,r){if(l(this,g,e),!t&&y&&!f(n))return"get"==e&&void 0;var i=this._c[e](0===n?0:n,r);return t?this:i})}),"size"in w&&d(g.prototype,"size",{get:function(){return this._c.size}})):(g=v.getConstructor(t,e,b,k),u(g.prototype,n),o.NEED=!0),h(g,e),C[e]=g,i(i.G+i.W+i.F,C),y||v.setStrong(g,e,b),g}},{"./_an-instance":91,"./_array-methods":95,"./_descriptors":108,"./_export":112,"./_fails":113,"./_for-of":114,"./_global":115,"./_hide":117,"./_is-object":125,"./_meta":134,"./_object-dp":138,"./_redefine-all":150,"./_set-to-string-tag":154}],104:[function(e,t,n){var r=t.exports={version:"2.4.0"};"number"==typeof __e&&(__e=r)},{}],105:[function(e,t,n){"use strict";var r=e("./_object-dp"),i=e("./_property-desc");t.exports=function(e,t,n){t in e?r.f(e,t,i(0,n)):e[t]=n}},{"./_object-dp":138,"./_property-desc":149}],106:[function(e,t,n){var r=e("./_a-function");t.exports=function(e,t,n){if(r(e),void 0===t)return e;switch(n){case 1:return function(n){return e.call(t,n)};case 2:return function(n,r){return e.call(t,n,r)};case 3:return function(n,r,i){return e.call(t,n,r,i)}}return function(){return e.apply(t,arguments)}}},{"./_a-function":89}],107:[function(e,t,n){t.exports=function(e){if(void 0==e)throw TypeError("Can't call method on "+e);return e}},{}],108:[function(e,t,n){t.exports=!e("./_fails")(function(){return 7!=Object.defineProperty({},"a",{get:function(){return 7}}).a})},{"./_fails":113}],109:[function(e,t,n){var r=e("./_is-object"),i=e("./_global").document,o=r(i)&&r(i.createElement);t.exports=function(e){return o?i.createElement(e):{}}},{"./_global":115,"./_is-object":125}],110:[function(e,t,n){t.exports="constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf".split(",")},{}],111:[function(e,t,n){var r=e("./_object-keys"),i=e("./_object-gops"),o=e("./_object-pie");t.exports=function(e){var t=r(e),n=i.f;if(n)for(var s,a=n(e),u=o.f,c=0;a.length>c;)u.call(e,s=a[c++])&&t.push(s);return t}},{"./_object-gops":143,"./_object-keys":146,"./_object-pie":147}],112:[function(e,t,n){var r=e("./_global"),i=e("./_core"),o=e("./_ctx"),s=e("./_hide"),a=function(e,t,n){var u,c,l,f=e&a.F,h=e&a.G,d=e&a.S,p=e&a.P,m=e&a.B,v=e&a.W,b=h?i:i[t]||(i[t]={}),y=b.prototype,_=h?r:d?r[t]:(r[t]||{}).prototype;h&&(n=t);for(u in n)(c=!f&&_&&void 0!==_[u])&&u in b||(l=c?_[u]:n[u],b[u]=h&&"function"!=typeof _[u]?n[u]:m&&c?o(l,r):v&&_[u]==l?function(e){var t=function(t,n,r){if(this instanceof e){switch(arguments.length){case 0:return new e;case 1:return new e(t);case 2:return new e(t,n)}return new e(t,n,r)}return e.apply(this,arguments)};return t.prototype=e.prototype,t}(l):p&&"function"==typeof l?o(Function.call,l):l,p&&((b.virtual||(b.virtual={}))[u]=l, e&a.R&&y&&!y[u]&&s(y,u,l)))};a.F=1,a.G=2,a.S=4,a.P=8,a.B=16,a.W=32,a.U=64,a.R=128,t.exports=a},{"./_core":104,"./_ctx":106,"./_global":115,"./_hide":117}],113:[function(e,t,n){t.exports=function(e){try{return!!e()}catch(e){return!0}}},{}],114:[function(e,t,n){var r=e("./_ctx"),i=e("./_iter-call"),o=e("./_is-array-iter"),s=e("./_an-object"),a=e("./_to-length"),u=e("./core.get-iterator-method"),c={},l={},n=t.exports=function(e,t,n,f,h){var d,p,m,v,b=h?function(){return e}:u(e),y=r(n,f,t?2:1),_=0;if("function"!=typeof b)throw TypeError(e+" is not iterable!");if(o(b)){for(d=a(e.length);d>_;_++)if((v=t?y(s(p=e[_])[0],p[1]):y(e[_]))===c||v===l)return v}else for(m=b.call(e);!(p=m.next()).done;)if((v=i(m,y,p.value,t))===c||v===l)return v};n.BREAK=c,n.RETURN=l},{"./_an-object":92,"./_ctx":106,"./_is-array-iter":122,"./_iter-call":126,"./_to-length":163,"./core.get-iterator-method":170}],115:[function(e,t,n){var r=t.exports="undefined"!=typeof window&&window.Math==Math?window:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")();"number"==typeof __g&&(__g=r)},{}],116:[function(e,t,n){var r={}.hasOwnProperty;t.exports=function(e,t){return r.call(e,t)}},{}],117:[function(e,t,n){var r=e("./_object-dp"),i=e("./_property-desc");t.exports=e("./_descriptors")?function(e,t,n){return r.f(e,t,i(1,n))}:function(e,t,n){return e[t]=n,e}},{"./_descriptors":108,"./_object-dp":138,"./_property-desc":149}],118:[function(e,t,n){t.exports=e("./_global").document&&document.documentElement},{"./_global":115}],119:[function(e,t,n){t.exports=!e("./_descriptors")&&!e("./_fails")(function(){return 7!=Object.defineProperty(e("./_dom-create")("div"),"a",{get:function(){return 7}}).a})},{"./_descriptors":108,"./_dom-create":109,"./_fails":113}],120:[function(e,t,n){t.exports=function(e,t,n){var r=void 0===n;switch(t.length){case 0:return r?e():e.call(n);case 1:return r?e(t[0]):e.call(n,t[0]);case 2:return r?e(t[0],t[1]):e.call(n,t[0],t[1]);case 3:return r?e(t[0],t[1],t[2]):e.call(n,t[0],t[1],t[2]);case 4:return r?e(t[0],t[1],t[2],t[3]):e.call(n,t[0],t[1],t[2],t[3])}return e.apply(n,t)}},{}],121:[function(e,t,n){var r=e("./_cof");t.exports=Object("z").propertyIsEnumerable(0)?Object:function(e){return"String"==r(e)?e.split(""):Object(e)}},{"./_cof":100}],122:[function(e,t,n){var r=e("./_iterators"),i=e("./_wks")("iterator"),o=Array.prototype;t.exports=function(e){return void 0!==e&&(r.Array===e||o[i]===e)}},{"./_iterators":131,"./_wks":169}],123:[function(e,t,n){var r=e("./_cof");t.exports=Array.isArray||function(e){return"Array"==r(e)}},{"./_cof":100}],124:[function(e,t,n){var r=e("./_is-object"),i=Math.floor;t.exports=function(e){return!r(e)&&isFinite(e)&&i(e)===e}},{"./_is-object":125}],125:[function(e,t,n){t.exports=function(e){return"object"==typeof e?null!==e:"function"==typeof e}},{}],126:[function(e,t,n){var r=e("./_an-object");t.exports=function(e,t,n,i){try{return i?t(r(n)[0],n[1]):t(n)}catch(t){var o=e.return;throw void 0!==o&&r(o.call(e)),t}}},{"./_an-object":92}],127:[function(e,t,n){"use strict";var r=e("./_object-create"),i=e("./_property-desc"),o=e("./_set-to-string-tag"),s={};e("./_hide")(s,e("./_wks")("iterator"),function(){return this}),t.exports=function(e,t,n){e.prototype=r(s,{next:i(1,n)}),o(e,t+" Iterator")}},{"./_hide":117,"./_object-create":137,"./_property-desc":149,"./_set-to-string-tag":154,"./_wks":169}],128:[function(e,t,n){"use strict";var r=e("./_library"),i=e("./_export"),o=e("./_redefine"),s=e("./_hide"),a=e("./_has"),u=e("./_iterators"),c=e("./_iter-create"),l=e("./_set-to-string-tag"),f=e("./_object-gpo"),h=e("./_wks")("iterator"),d=!([].keys&&"next"in[].keys()),p=function(){return this};t.exports=function(e,t,n,m,v,b,y){c(n,t,m);var _,g,k,w=function(e){if(!d&&e in E)return E[e];switch(e){case"keys":case"values":return function(){return new n(this,e)}}return function(){return new n(this,e)}},C=t+" Iterator",x="values"==v,j=!1,E=e.prototype,S=E[h]||E["@@iterator"]||v&&E[v],T=S||w(v),R=v?x?w("entries"):T:void 0,A="Array"==t?E.entries||S:S;if(A&&(k=f(A.call(new e)))!==Object.prototype&&(l(k,C,!0),r||a(k,h)||s(k,h,p)),x&&S&&"values"!==S.name&&(j=!0,T=function(){return S.call(this)}),r&&!y||!d&&!j&&E[h]||s(E,h,T),u[t]=T,u[C]=p,v)if(_={values:x?T:w("values"),keys:b?T:w("keys"),entries:R},y)for(g in _)g in E||o(E,g,_[g]);else i(i.P+i.F*(d||j),t,_);return _}},{"./_export":112,"./_has":116,"./_hide":117,"./_iter-create":127,"./_iterators":131,"./_library":133,"./_object-gpo":144,"./_redefine":151,"./_set-to-string-tag":154,"./_wks":169}],129:[function(e,t,n){var r=e("./_wks")("iterator"),i=!1;try{var o=[7][r]();o.return=function(){i=!0},Array.from(o,function(){throw 2})}catch(e){}t.exports=function(e,t){if(!t&&!i)return!1;var n=!1;try{var o=[7],s=o[r]();s.next=function(){return{done:n=!0}},o[r]=function(){return s},e(o)}catch(e){}return n}},{"./_wks":169}],130:[function(e,t,n){t.exports=function(e,t){return{value:t,done:!!e}}},{}],131:[function(e,t,n){t.exports={}},{}],132:[function(e,t,n){var r=e("./_object-keys"),i=e("./_to-iobject");t.exports=function(e,t){for(var n,o=i(e),s=r(o),a=s.length,u=0;a>u;)if(o[n=s[u++]]===t)return n}},{"./_object-keys":146,"./_to-iobject":162}],133:[function(e,t,n){t.exports=!0},{}],134:[function(e,t,n){var r=e("./_uid")("meta"),i=e("./_is-object"),o=e("./_has"),s=e("./_object-dp").f,a=0,u=Object.isExtensible||function(){return!0},c=!e("./_fails")(function(){return u(Object.preventExtensions({}))}),l=function(e){s(e,r,{value:{i:"O"+ ++a,w:{}}})},f=function(e,t){if(!i(e))return"symbol"==typeof e?e:("string"==typeof e?"S":"P")+e;if(!o(e,r)){if(!u(e))return"F";if(!t)return"E";l(e)}return e[r].i},h=function(e,t){if(!o(e,r)){if(!u(e))return!0;if(!t)return!1;l(e)}return e[r].w},d=function(e){return c&&p.NEED&&u(e)&&!o(e,r)&&l(e),e},p=t.exports={KEY:r,NEED:!1,fastKey:f,getWeak:h,onFreeze:d}},{"./_fails":113,"./_has":116,"./_is-object":125,"./_object-dp":138,"./_uid":166}],135:[function(e,t,n){var r=e("./_global"),i=e("./_task").set,o=r.MutationObserver||r.WebKitMutationObserver,s=r.process,a=r.Promise,u="process"==e("./_cof")(s);t.exports=function(){var e,t,n,c=function(){var r,i;for(u&&(r=s.domain)&&r.exit();e;){i=e.fn,e=e.next;try{i()}catch(r){throw e?n():t=void 0,r}}t=void 0,r&&r.enter()};if(u)n=function(){s.nextTick(c)};else if(o){var l=!0,f=document.createTextNode("");new o(c).observe(f,{characterData:!0}),n=function(){f.data=l=!l}}else if(a&&a.resolve){var h=a.resolve();n=function(){h.then(c)}}else n=function(){i.call(r,c)};return function(r){var i={fn:r,next:void 0};t&&(t.next=i),e||(e=i,n()),t=i}}},{"./_cof":100,"./_global":115,"./_task":159}],136:[function(e,t,n){"use strict";var r=e("./_object-keys"),i=e("./_object-gops"),o=e("./_object-pie"),s=e("./_to-object"),a=e("./_iobject"),u=Object.assign;t.exports=!u||e("./_fails")(function(){var e={},t={},n=Symbol(),r="abcdefghijklmnopqrst";return e[n]=7,r.split("").forEach(function(e){t[e]=e}),7!=u({},e)[n]||Object.keys(u({},t)).join("")!=r})?function(e,t){for(var n=s(e),u=arguments.length,c=1,l=i.f,f=o.f;u>c;)for(var h,d=a(arguments[c++]),p=l?r(d).concat(l(d)):r(d),m=p.length,v=0;m>v;)f.call(d,h=p[v++])&&(n[h]=d[h]);return n}:u},{"./_fails":113,"./_iobject":121,"./_object-gops":143,"./_object-keys":146,"./_object-pie":147,"./_to-object":164}],137:[function(e,t,n){var r=e("./_an-object"),i=e("./_object-dps"),o=e("./_enum-bug-keys"),s=e("./_shared-key")("IE_PROTO"),a=function(){},u=function(){var t,n=e("./_dom-create")("iframe"),r=o.length;for(n.style.display="none",e("./_html").appendChild(n),n.src="javascript:",t=n.contentWindow.document,t.open(),t.write("