>>2]>>>24-8*(r%4)&255)<<16|(l[r+1>>>2]>>>24-8*((r+1)%4)&255)<<8|l[r+2>>>2]>>>24-8*((r+2)%4)&255,v=0;4>v&&r+0.75*v>>6*(3-v)&63));if(l=t.charAt(64))for(;d.length%4;)d.push(l);return d.join(\"\")},parse:function(d){var l=d.length,s=this._map,t=s.charAt(64);t&&(t=d.indexOf(t),-1!=t&&(l=t));for(var t=[],r=0,w=0;w<\nl;w++)if(w%4){var v=s.indexOf(d.charAt(w-1))<<2*(w%4),b=s.indexOf(d.charAt(w))>>>6-2*(w%4);t[r>>>2]|=(v|b)<<24-8*(r%4);r++}return p.create(t,r)},_map:\"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\"}})();\n\n// BlockCipher\n(function(u){function p(b,n,a,c,e,j,k){b=b+(n&a|~n&c)+e+k;return(b<>>32-j)+n}function d(b,n,a,c,e,j,k){b=b+(n&c|a&~c)+e+k;return(b<>>32-j)+n}function l(b,n,a,c,e,j,k){b=b+(n^a^c)+e+k;return(b<>>32-j)+n}function s(b,n,a,c,e,j,k){b=b+(a^(n|~c))+e+k;return(b<>>32-j)+n}for(var t=CryptoJS,r=t.lib,w=r.WordArray,v=r.Hasher,r=t.algo,b=[],x=0;64>x;x++)b[x]=4294967296*u.abs(u.sin(x+1))|0;r=r.MD5=v.extend({_doReset:function(){this._hash=new w.init([1732584193,4023233417,2562383102,271733878])},\n_doProcessBlock:function(q,n){for(var a=0;16>a;a++){var c=n+a,e=q[c];q[c]=(e<<8|e>>>24)&16711935|(e<<24|e>>>8)&4278255360}var a=this._hash.words,c=q[n+0],e=q[n+1],j=q[n+2],k=q[n+3],z=q[n+4],r=q[n+5],t=q[n+6],w=q[n+7],v=q[n+8],A=q[n+9],B=q[n+10],C=q[n+11],u=q[n+12],D=q[n+13],E=q[n+14],x=q[n+15],f=a[0],m=a[1],g=a[2],h=a[3],f=p(f,m,g,h,c,7,b[0]),h=p(h,f,m,g,e,12,b[1]),g=p(g,h,f,m,j,17,b[2]),m=p(m,g,h,f,k,22,b[3]),f=p(f,m,g,h,z,7,b[4]),h=p(h,f,m,g,r,12,b[5]),g=p(g,h,f,m,t,17,b[6]),m=p(m,g,h,f,w,22,b[7]),\nf=p(f,m,g,h,v,7,b[8]),h=p(h,f,m,g,A,12,b[9]),g=p(g,h,f,m,B,17,b[10]),m=p(m,g,h,f,C,22,b[11]),f=p(f,m,g,h,u,7,b[12]),h=p(h,f,m,g,D,12,b[13]),g=p(g,h,f,m,E,17,b[14]),m=p(m,g,h,f,x,22,b[15]),f=d(f,m,g,h,e,5,b[16]),h=d(h,f,m,g,t,9,b[17]),g=d(g,h,f,m,C,14,b[18]),m=d(m,g,h,f,c,20,b[19]),f=d(f,m,g,h,r,5,b[20]),h=d(h,f,m,g,B,9,b[21]),g=d(g,h,f,m,x,14,b[22]),m=d(m,g,h,f,z,20,b[23]),f=d(f,m,g,h,A,5,b[24]),h=d(h,f,m,g,E,9,b[25]),g=d(g,h,f,m,k,14,b[26]),m=d(m,g,h,f,v,20,b[27]),f=d(f,m,g,h,D,5,b[28]),h=d(h,f,\nm,g,j,9,b[29]),g=d(g,h,f,m,w,14,b[30]),m=d(m,g,h,f,u,20,b[31]),f=l(f,m,g,h,r,4,b[32]),h=l(h,f,m,g,v,11,b[33]),g=l(g,h,f,m,C,16,b[34]),m=l(m,g,h,f,E,23,b[35]),f=l(f,m,g,h,e,4,b[36]),h=l(h,f,m,g,z,11,b[37]),g=l(g,h,f,m,w,16,b[38]),m=l(m,g,h,f,B,23,b[39]),f=l(f,m,g,h,D,4,b[40]),h=l(h,f,m,g,c,11,b[41]),g=l(g,h,f,m,k,16,b[42]),m=l(m,g,h,f,t,23,b[43]),f=l(f,m,g,h,A,4,b[44]),h=l(h,f,m,g,u,11,b[45]),g=l(g,h,f,m,x,16,b[46]),m=l(m,g,h,f,j,23,b[47]),f=s(f,m,g,h,c,6,b[48]),h=s(h,f,m,g,w,10,b[49]),g=s(g,h,f,m,\nE,15,b[50]),m=s(m,g,h,f,r,21,b[51]),f=s(f,m,g,h,u,6,b[52]),h=s(h,f,m,g,k,10,b[53]),g=s(g,h,f,m,B,15,b[54]),m=s(m,g,h,f,e,21,b[55]),f=s(f,m,g,h,v,6,b[56]),h=s(h,f,m,g,x,10,b[57]),g=s(g,h,f,m,t,15,b[58]),m=s(m,g,h,f,D,21,b[59]),f=s(f,m,g,h,z,6,b[60]),h=s(h,f,m,g,C,10,b[61]),g=s(g,h,f,m,j,15,b[62]),m=s(m,g,h,f,A,21,b[63]);a[0]=a[0]+f|0;a[1]=a[1]+m|0;a[2]=a[2]+g|0;a[3]=a[3]+h|0},_doFinalize:function(){var b=this._data,n=b.words,a=8*this._nDataBytes,c=8*b.sigBytes;n[c>>>5]|=128<<24-c%32;var e=u.floor(a/\n4294967296);n[(c+64>>>9<<4)+15]=(e<<8|e>>>24)&16711935|(e<<24|e>>>8)&4278255360;n[(c+64>>>9<<4)+14]=(a<<8|a>>>24)&16711935|(a<<24|a>>>8)&4278255360;b.sigBytes=4*(n.length+1);this._process();b=this._hash;n=b.words;for(a=0;4>a;a++)c=n[a],n[a]=(c<<8|c>>>24)&16711935|(c<<24|c>>>8)&4278255360;return b},clone:function(){var b=v.clone.call(this);b._hash=this._hash.clone();return b}});t.MD5=v._createHelper(r);t.HmacMD5=v._createHmacHelper(r)})(Math);\n(function(){var u=CryptoJS,p=u.lib,d=p.Base,l=p.WordArray,p=u.algo,s=p.EvpKDF=d.extend({cfg:d.extend({keySize:4,hasher:p.MD5,iterations:1}),init:function(d){this.cfg=this.cfg.extend(d)},compute:function(d,r){for(var p=this.cfg,s=p.hasher.create(),b=l.create(),u=b.words,q=p.keySize,p=p.iterations;u.length>>2]&255}};d.BlockCipher=v.extend({cfg:v.cfg.extend({mode:b,padding:q}),reset:function(){v.reset.call(this);var a=this.cfg,b=a.iv,a=a.mode;if(this._xformMode==this._ENC_XFORM_MODE)var c=a.createEncryptor;else c=a.createDecryptor,this._minBufferSize=1;this._mode=c.call(a,\nthis,b&&b.words)},_doProcessBlock:function(a,b){this._mode.processBlock(a,b)},_doFinalize:function(){var a=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){a.pad(this._data,this.blockSize);var b=this._process(!0)}else b=this._process(!0),a.unpad(b);return b},blockSize:4});var n=d.CipherParams=l.extend({init:function(a){this.mixIn(a)},toString:function(a){return(a||this.formatter).stringify(this)}}),b=(p.format={}).OpenSSL={stringify:function(a){var b=a.ciphertext;a=a.salt;return(a?s.create([1398893684,\n1701076831]).concat(a).concat(b):b).toString(r)},parse:function(a){a=r.parse(a);var b=a.words;if(1398893684==b[0]&&1701076831==b[1]){var c=s.create(b.slice(2,4));b.splice(0,4);a.sigBytes-=16}return n.create({ciphertext:a,salt:c})}},a=d.SerializableCipher=l.extend({cfg:l.extend({format:b}),encrypt:function(a,b,c,d){d=this.cfg.extend(d);var l=a.createEncryptor(c,d);b=l.finalize(b);l=l.cfg;return n.create({ciphertext:b,key:c,iv:l.iv,algorithm:a,mode:l.mode,padding:l.padding,blockSize:a.blockSize,formatter:d.format})},\ndecrypt:function(a,b,c,d){d=this.cfg.extend(d);b=this._parse(b,d.format);return a.createDecryptor(c,d).finalize(b.ciphertext)},_parse:function(a,b){return\"string\"==typeof a?b.parse(a,this):a}}),p=(p.kdf={}).OpenSSL={execute:function(a,b,c,d){d||(d=s.random(8));a=w.create({keySize:b+c}).compute(a,d);c=s.create(a.words.slice(b),4*c);a.sigBytes=4*b;return n.create({key:a,iv:c,salt:d})}},c=d.PasswordBasedCipher=a.extend({cfg:a.cfg.extend({kdf:p}),encrypt:function(b,c,d,l){l=this.cfg.extend(l);d=l.kdf.execute(d,\nb.keySize,b.ivSize);l.iv=d.iv;b=a.encrypt.call(this,b,c,d.key,l);b.mixIn(d);return b},decrypt:function(b,c,d,l){l=this.cfg.extend(l);c=this._parse(c,l.format);d=l.kdf.execute(d,b.keySize,b.ivSize,c.salt);l.iv=d.iv;return a.decrypt.call(this,b,c,d.key,l)}})}();\n\n// AES\n(function(){for(var u=CryptoJS,p=u.lib.BlockCipher,d=u.algo,l=[],s=[],t=[],r=[],w=[],v=[],b=[],x=[],q=[],n=[],a=[],c=0;256>c;c++)a[c]=128>c?c<<1:c<<1^283;for(var e=0,j=0,c=0;256>c;c++){var k=j^j<<1^j<<2^j<<3^j<<4,k=k>>>8^k&255^99;l[e]=k;s[k]=e;var z=a[e],F=a[z],G=a[F],y=257*a[k]^16843008*k;t[e]=y<<24|y>>>8;r[e]=y<<16|y>>>16;w[e]=y<<8|y>>>24;v[e]=y;y=16843009*G^65537*F^257*z^16843008*e;b[k]=y<<24|y>>>8;x[k]=y<<16|y>>>16;q[k]=y<<8|y>>>24;n[k]=y;e?(e=z^a[a[a[G^z]]],j^=a[a[j]]):e=j=1}var H=[0,1,2,4,8,\n16,32,64,128,27,54],d=d.AES=p.extend({_doReset:function(){for(var a=this._key,c=a.words,d=a.sigBytes/4,a=4*((this._nRounds=d+6)+1),e=this._keySchedule=[],j=0;j>>24]<<24|l[k>>>16&255]<<16|l[k>>>8&255]<<8|l[k&255]):(k=k<<8|k>>>24,k=l[k>>>24]<<24|l[k>>>16&255]<<16|l[k>>>8&255]<<8|l[k&255],k^=H[j/d|0]<<24);e[j]=e[j-d]^k}c=this._invKeySchedule=[];for(d=0;dd||4>=j?k:b[l[k>>>24]]^x[l[k>>>16&255]]^q[l[k>>>\n8&255]]^n[l[k&255]]},encryptBlock:function(a,b){this._doCryptBlock(a,b,this._keySchedule,t,r,w,v,l)},decryptBlock:function(a,c){var d=a[c+1];a[c+1]=a[c+3];a[c+3]=d;this._doCryptBlock(a,c,this._invKeySchedule,b,x,q,n,s);d=a[c+1];a[c+1]=a[c+3];a[c+3]=d},_doCryptBlock:function(a,b,c,d,e,j,l,f){for(var m=this._nRounds,g=a[b]^c[0],h=a[b+1]^c[1],k=a[b+2]^c[2],n=a[b+3]^c[3],p=4,r=1;r>>24]^e[h>>>16&255]^j[k>>>8&255]^l[n&255]^c[p++],s=d[h>>>24]^e[k>>>16&255]^j[n>>>8&255]^l[g&255]^c[p++],t=\nd[k>>>24]^e[n>>>16&255]^j[g>>>8&255]^l[h&255]^c[p++],n=d[n>>>24]^e[g>>>16&255]^j[h>>>8&255]^l[k&255]^c[p++],g=q,h=s,k=t;q=(f[g>>>24]<<24|f[h>>>16&255]<<16|f[k>>>8&255]<<8|f[n&255])^c[p++];s=(f[h>>>24]<<24|f[k>>>16&255]<<16|f[n>>>8&255]<<8|f[g&255])^c[p++];t=(f[k>>>24]<<24|f[n>>>16&255]<<16|f[g>>>8&255]<<8|f[h&255])^c[p++];n=(f[n>>>24]<<24|f[g>>>16&255]<<16|f[h>>>8&255]<<8|f[k&255])^c[p++];a[b]=q;a[b+1]=s;a[b+2]=t;a[b+3]=n},keySize:8});u.AES=p._createHelper(d)})();\n\n// Mode ECB\nCryptoJS.mode.ECB = (function () {\n var ECB = CryptoJS.lib.BlockCipherMode.extend();\n\n ECB.Encryptor = ECB.extend({\n processBlock: function (words, offset) {\n this._cipher.encryptBlock(words, offset);\n }\n });\n\n ECB.Decryptor = ECB.extend({\n processBlock: function (words, offset) {\n this._cipher.decryptBlock(words, offset);\n }\n });\n\n return ECB;\n}());// Moved to hmac-sha-256.js\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./bower_components/pubnub/web/pubnub.js\n ** module id = 10\n ** module chunks = 0\n **/","export default class Cache {\n\n static defaultPrefix = 'rc-';\n\n constructor(storage, prefix) {\n this.setPrefix(prefix);\n this._storage = storage;\n }\n\n setPrefix(prefix) {\n this._prefix = prefix || Cache.defaultPrefix;\n return this;\n }\n\n setItem(key, data) {\n this._storage[this._prefixKey(key)] = JSON.stringify(data);\n return this;\n }\n\n removeItem(key) {\n delete this._storage[this._prefixKey(key)];\n return this;\n }\n\n getItem(key) {\n var item = this._storage[this._prefixKey(key)];\n if (!item) return null;\n return JSON.parse(item);\n }\n\n clean() {\n\n for (var key in this._storage) {\n\n if (!this._storage.hasOwnProperty(key)) continue;\n\n if (key.indexOf(this._prefix) === 0) {\n delete this._storage[key];\n }\n\n }\n\n return this;\n\n }\n\n _prefixKey(key) {\n return this._prefix + key;\n }\n\n}\n\n\n/** WEBPACK FOOTER **\n ** ./src/core/Cache.js\n **/","export default class Observable {\n\n constructor() {\n this.off();\n }\n\n hasListeners(event) {\n return (event in this._listeners);\n }\n\n on(events, callback) {\n\n if (typeof events == 'string') events = [events];\n if (!events) throw new Error('No events to subscribe to');\n if (typeof callback !== 'function') throw new Error('Callback must be a function');\n\n events.forEach((event) => {\n\n if (!this.hasListeners(event)) this._listeners[event] = [];\n\n this._listeners[event].push(callback);\n\n });\n\n return this;\n\n }\n\n emit(event, ...args) {\n\n var result = null;\n\n if (!this.hasListeners(event)) return null;\n\n this._listeners[event].some((callback) => {\n\n result = callback.apply(this, args);\n return (result === false);\n\n });\n\n return result;\n\n }\n\n off(event, callback) {\n\n if (!event) {\n\n this._listeners = {};\n\n } else {\n\n if (!callback) {\n\n delete this._listeners[event];\n\n } else {\n\n if (!this.hasListeners(event)) return this;\n\n this._listeners[event].forEach((cb, i) => {\n\n if (cb === callback) delete this._listeners[event][i];\n\n });\n\n }\n\n }\n\n return this;\n\n }\n\n}\n\n\n/** WEBPACK FOOTER **\n ** ./src/core/Observable.js\n **/","import {Promise} from '../core/Externals';\nimport {poll, stopPolling} from './Utils';\n\nexport default class Queue {\n\n static _pollInterval = 250;\n static _releaseTimeout = 5000;\n\n constructor(cache, cacheId) {\n\n this._cache = cache;\n this._cacheId = cacheId;\n this._promise = null;\n\n }\n\n isPaused() {\n\n var time = this._cache.getItem(this._cacheId);\n\n return !!time && Date.now() - parseInt(time) < Queue._releaseTimeout;\n }\n\n pause() {\n this._cache.setItem(this._cacheId, Date.now());\n return this;\n }\n\n resume() {\n this._cache.removeItem(this._cacheId);\n return this;\n }\n\n poll() {\n\n if (this._promise) return this._promise;\n\n this._promise = new Promise((resolve, reject) => {\n\n poll((next) => {\n\n if (this.isPaused()) return next();\n\n this._promise = null;\n\n this.resume(); // this is actually not needed but why not\n\n resolve(null);\n\n }, Queue._pollInterval);\n\n });\n\n return this._promise;\n\n }\n\n}\n\n\n/** WEBPACK FOOTER **\n ** ./src/core/Queue.js\n **/","import {fetch, Request, Response, Headers, Promise} from '../core/Externals';\nimport {queryStringify} from '../core/Utils';\nimport {findHeaderName} from './Utils';\nimport Observable from '../core/Observable';\nimport ApiResponse from './ApiResponse';\n\nexport default class Client extends Observable {\n\n static _allowedMethods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS', 'HEAD'];\n\n events = {\n beforeRequest: 'beforeRequest',\n requestSuccess: 'requestSuccess',\n requestError: 'requestError'\n };\n\n /**\n * @param {Request} request\n * @return {Promise}\n */\n async sendRequest(request) {\n\n var apiResponse = new ApiResponse(request);\n\n try {\n\n //TODO Stop request if listeners return false\n this.emit(this.events.beforeRequest, apiResponse);\n\n apiResponse._response = await this._loadResponse(request);\n\n if (apiResponse._isMultipart() || apiResponse._isJson()) {\n apiResponse._text = await apiResponse.response().text();\n }\n\n if (!apiResponse.ok()) throw new Error('Response has unsuccessful status');\n\n this.emit(this.events.requestSuccess, apiResponse);\n\n return apiResponse;\n\n } catch (e) {\n\n if (!e.apiResponse) e = this.makeError(e, apiResponse);\n\n this.emit(this.events.requestError, e);\n\n throw e;\n\n }\n\n }\n\n /**\n * @param {Request} request\n * @return {Promise}\n * @private\n */\n async _loadResponse(request) {\n return await fetch.call(null, request);\n }\n\n /**\n * Wraps the JS Error object with transaction information\n * @param {Error|IApiError} e\n * @param {ApiResponse} apiResponse\n * @return {IApiError}\n */\n makeError(e, apiResponse) {\n\n // Wrap only if regular error\n if (!e.hasOwnProperty('apiResponse') && !e.hasOwnProperty('originalMessage')) {\n\n e.apiResponse = apiResponse;\n e.originalMessage = e.message;\n e.message = (apiResponse && apiResponse.error(true)) || e.originalMessage;\n\n }\n\n return e;\n\n }\n\n /**\n *\n * @param {object} init\n * @param {object} [init.url]\n * @param {object} [init.body]\n * @param {string} [init.method]\n * @param {object} [init.query]\n * @param {object} [init.headers]\n * @return {Request}\n */\n createRequest(init) {\n\n init = init || {};\n init.headers = init.headers || {};\n\n // Sanity checks\n if (!init.url) throw new Error('Url is not defined');\n if (!init.method) init.method = 'GET';\n if (init.method && Client._allowedMethods.indexOf(init.method) < 0) throw new Error('Method has wrong value: ' + init.method);\n\n // Defaults\n init.credentials = init.credentials || 'include';\n init.mode = init.mode || 'cors';\n\n // Append Query String\n if (init.query) {\n init.url = init.url + (init.url.indexOf('?') > -1 ? '&' : '?') + queryStringify(init.query);\n }\n\n if (!(findHeaderName('Accept', init.headers))) {\n init.headers['Accept'] = ApiResponse._jsonContentType;\n }\n\n // Serialize body\n //TODO Check that body is a plain object\n if (typeof init.body !== 'string' || !init.body) {\n\n var contentTypeHeaderName = findHeaderName(ApiResponse._contentType, init.headers);\n\n if (!contentTypeHeaderName) {\n contentTypeHeaderName = ApiResponse._contentType;\n init.headers[contentTypeHeaderName] = ApiResponse._jsonContentType;\n }\n\n var contentType = init.headers[contentTypeHeaderName];\n\n // Assign a new encoded body\n if (contentType.indexOf(ApiResponse._jsonContentType) > -1) {\n init.body = JSON.stringify(init.body);\n } else if (contentType.indexOf(ApiResponse._urlencodedContentType) > -1) {\n init.body = queryStringify(init.body);\n }\n\n }\n\n // Create a request with encoded body\n var req = new Request(init.url, init);\n\n // Keep the original body accessible directly (for mocks)\n req.originalBody = init.body;\n\n return req;\n\n }\n\n}\n\n/**\n * @name IApiError\n * @property {string} stack\n * @property {string} originalMessage\n * @property {ApiResponse} apiResponse\n */\n\n\n/** WEBPACK FOOTER **\n ** ./src/http/Client.js\n **/","import {fetch, Request, Response, Headers, Promise} from '../core/Externals';\nimport * as utils from '../core/Utils';\n\n/**\n * Creates a response\n * @param stringBody\n * @param init\n * @return {Response}\n */\nexport function createResponse(stringBody, init) {\n\n init = init || {};\n\n var response = new Response(stringBody, init);\n\n //TODO Wait for https://github.com/bitinn/node-fetch/issues/38\n if (utils.isNodeJS()) {\n\n response._text = stringBody;\n response._decode = function() {\n return this._text;\n };\n\n }\n\n return response;\n\n}\n\nexport function findHeaderName(name, headers) {\n name = name.toLowerCase();\n return Object.keys(headers).reduce(function(res, key) {\n if (res) return res;\n if (name == key.toLowerCase()) return key;\n return res;\n }, null);\n}\n\n\n/** WEBPACK FOOTER **\n ** ./src/http/Utils.js\n **/","import {fetch, Request, Response, Headers, Promise} from '../core/Externals';\nimport * as utils from './Utils';\n\nexport default class ApiResponse {\n\n static _contentType = 'Content-Type';\n static _jsonContentType = 'application/json';\n static _multipartContentType = 'multipart/mixed';\n static _urlencodedContentType = 'application/x-www-form-urlencoded';\n static _headerSeparator = ':';\n static _bodySeparator = '\\n\\n';\n static _boundarySeparator = '--';\n\n /**\n * @param {Request} request\n * @param {Response} response\n * @param {string} responseText\n */\n constructor(request, response, responseText) {\n\n /** @type {Request} */\n this._request = request;\n\n /** @type {Response} */\n this._response = response;\n\n this._text = responseText;\n this._json = null;\n this._multipart = [];\n\n }\n\n /**\n * @return {Response}\n */\n response() {\n return this._response;\n }\n\n /**\n * @return {Request}\n */\n request() {\n return this._request;\n }\n\n /**\n * @return {boolean}\n */\n ok() {\n return this._response && this._response.ok;\n }\n\n /**\n * @return {string}\n */\n text() {\n if (!this._isJson() && !this._isMultipart()) throw new Error('Response is not text');\n return this._text;\n }\n\n /**\n * @return {object}\n */\n json() {\n if (!this._isJson()) throw new Error('Response is not JSON');\n if (!this._json) {\n this._json = this._text ? JSON.parse(this._text) : null;\n }\n return this._json;\n }\n\n /**\n * @param [skipOKCheck]\n * @return {string}\n */\n error(skipOKCheck) {\n\n if (this.ok() && !skipOKCheck) return null;\n\n var message = (this._response && this._response.status ? this._response.status + ' ' : '') +\n (this._response && this._response.statusText ? this._response.statusText : '');\n\n try {\n\n if (this.json().message) message = this.json().message;\n if (this.json().error_description) message = this.json().error_description;\n if (this.json().description) message = this.json().description;\n\n } catch (e) {}\n\n return message;\n\n }\n\n /**\n * @return {ApiResponse[]}\n */\n multipart() {\n\n if (!this._isMultipart()) throw new Error('Response is not multipart');\n\n if (!this._multipart.length) {\n\n // Step 1. Split multipart response\n\n var text = this.text();\n\n if (!text) throw new Error('No response body');\n\n var boundary = this._getContentType().match(/boundary=([^;]+)/i)[1];\n\n if (!boundary) throw new Error('Cannot find boundary');\n\n var parts = text.toString().split(ApiResponse._boundarySeparator + boundary);\n\n if (parts[0].trim() === '') parts.shift();\n if (parts[parts.length - 1].trim() == ApiResponse._boundarySeparator) parts.pop();\n\n if (parts.length < 1) throw new Error('No parts in body');\n\n // Step 2. Parse status info\n\n var statusInfo = ApiResponse.create(parts.shift(), this._response.status, this._response.statusText).json();\n\n // Step 3. Parse all other parts\n\n this._multipart = parts.map((part:string, i) => {\n\n var status = statusInfo.response[i].status;\n\n return ApiResponse.create(part, status);\n\n });\n\n }\n\n return this._multipart;\n\n }\n\n _isContentType(contentType) {\n return this._getContentType().indexOf(contentType) > -1;\n }\n\n _getContentType() {\n return this._response.headers.get(ApiResponse._contentType) || '';\n }\n\n _isMultipart() {\n return this._isContentType(ApiResponse._multipartContentType);\n }\n\n _isUrlEncoded() {\n return this._isContentType(ApiResponse._urlencodedContentType);\n }\n\n _isJson() {\n return this._isContentType(ApiResponse._jsonContentType);\n }\n\n /**\n * Method is used to create ApiResponse object from string parts of multipart/mixed response\n * @param {string} [text]\n * @param {number} [status]\n * @param {string} [statusText]\n * @return {ApiResponse}\n */\n static create(text, status, statusText) {\n\n text = text || '';\n status = status || 200;\n statusText = statusText || 'OK';\n\n text = text.replace(/\\r/g, '');\n\n var headers = new Headers(),\n headersAndBody = text.split(ApiResponse._bodySeparator),\n headersText = (headersAndBody.length > 1) ? headersAndBody.shift() : '';\n\n text = headersAndBody.join(ApiResponse._bodySeparator);\n\n (headersText || '')\n .split('\\n')\n .forEach((header:string) => {\n\n var split = header.trim().split(ApiResponse._headerSeparator),\n key = split.shift().trim(),\n value = split.join(ApiResponse._headerSeparator).trim();\n\n if (key) headers.append(key, value);\n\n });\n\n return new ApiResponse(null, utils.createResponse(text, {\n headers: headers,\n status: status,\n statusText: statusText\n }), text);\n\n }\n\n}\n\n\n/** WEBPACK FOOTER **\n ** ./src/http/ApiResponse.js\n **/","import Registry from './Registry';\nimport {default as HttpClient} from '../http/Client';\n\nexport default class Client extends HttpClient {\n\n constructor() {\n super();\n this._registry = new Registry();\n }\n\n registry() {\n return this._registry;\n }\n\n async _loadResponse(request) {\n\n var mock = this._registry.find(request);\n\n return await mock.getResponse(request);\n\n }\n\n}\n\n\n/** WEBPACK FOOTER **\n ** ./src/mocks/ClientMock.js\n **/","import Mock from './Mock';\n\nexport default class Registry {\n\n constructor() {\n this._mocks = [];\n }\n\n add(mock) {\n this._mocks.push(mock);\n return this;\n }\n\n clear() {\n this._mocks = [];\n return this;\n }\n\n find(request) {\n\n //console.log('Registry is looking for', request);\n\n var mock = this._mocks.shift();\n\n if (!mock) throw new Error('No mock in registry for request ' + request.method + ' ' + request.url);\n\n if (!mock.test(request)) throw new Error('Wrong request ' + request.method + ' ' + request.url +\n ' for expected mock ' + mock.method() + ' ' + mock.path());\n\n return mock;\n\n }\n\n apiCall(method:string, path:string, response:any, status, statusText) {\n\n this.add(new Mock(method, path, response, status, statusText));\n\n return this;\n\n }\n\n authentication() {\n\n this.apiCall('POST', '/restapi/oauth/token', {\n 'access_token': 'ACCESS_TOKEN',\n 'token_type': 'bearer',\n 'expires_in': 3600,\n 'refresh_token': 'REFRESH_TOKEN',\n 'refresh_token_expires_in': 60480,\n 'scope': 'SMS RCM Foo Boo',\n 'expireTime': new Date().getTime() + 3600000\n });\n\n return this;\n\n }\n\n logout() {\n\n this.apiCall('POST', '/restapi/oauth/revoke', {});\n\n return this;\n\n }\n\n presenceLoad(id) {\n\n this.apiCall('GET', '/restapi/v1.0/account/~/extension/' + id + '/presence', {\n \"uri\": \"https://platform.ringcentral.com/restapi/v1.0/account/123/extension/\" + id + \"/presence\",\n \"extension\": {\n \"uri\": \"https://platform.ringcentral.com/restapi/v1.0/account/123/extension/\" + id,\n \"id\": id,\n \"extensionNumber\": \"101\"\n },\n \"activeCalls\": [],\n \"presenceStatus\": \"Available\",\n \"telephonyStatus\": \"Ringing\",\n \"userStatus\": \"Available\",\n \"dndStatus\": \"TakeAllCalls\",\n \"extensionId\": id\n });\n\n return this;\n\n }\n\n subscribeGeneric(expiresIn) {\n\n expiresIn = expiresIn || 15 * 60 * 60;\n\n var date = new Date();\n\n this.apiCall('POST', '/restapi/v1.0/subscription', {\n 'eventFilters': [\n '/restapi/v1.0/account/~/extension/~/presence'\n ],\n 'expirationTime': new Date(date.getTime() + (expiresIn * 1000)).toISOString(),\n 'expiresIn': expiresIn,\n 'deliveryMode': {\n 'transportType': 'PubNub',\n 'encryption': false,\n 'address': '123_foo',\n 'subscriberKey': 'sub-c-foo',\n 'secretKey': 'sec-c-bar'\n },\n 'id': 'foo-bar-baz',\n 'creationTime': date.toISOString(),\n 'status': 'Active',\n 'uri': 'https://platform.ringcentral.com/restapi/v1.0/subscription/foo-bar-baz'\n });\n\n return this;\n\n }\n\n subscribeOnPresence(id, detailed) {\n\n id = id || '1';\n\n var date = new Date();\n\n this.apiCall('POST', '/restapi/v1.0/subscription', {\n 'eventFilters': ['/restapi/v1.0/account/~/extension/' + id + '/presence' + (detailed ? '?detailedTelephonyState=true' : '')],\n 'expirationTime': new Date(date.getTime() + (15 * 60 * 60 * 1000)).toISOString(),\n 'deliveryMode': {\n 'transportType': 'PubNub',\n 'encryption': true,\n 'address': '123_foo',\n 'subscriberKey': 'sub-c-foo',\n 'secretKey': 'sec-c-bar',\n 'encryptionAlgorithm': 'AES',\n 'encryptionKey': 'VQwb6EVNcQPBhE/JgFZ2zw=='\n },\n 'creationTime': date.toISOString(),\n 'id': 'foo-bar-baz',\n 'status': 'Active',\n 'uri': 'https://platform.ringcentral.com/restapi/v1.0/subscription/foo-bar-baz'\n });\n\n return this;\n\n }\n\n tokenRefresh(failure) {\n\n if (!failure) {\n\n this.apiCall('POST', '/restapi/oauth/token', {\n 'access_token': 'ACCESS_TOKEN_FROM_REFRESH',\n 'token_type': 'bearer',\n 'expires_in': 3600,\n 'refresh_token': 'REFRESH_TOKEN_FROM_REFRESH',\n 'refresh_token_expires_in': 60480,\n 'scope': 'SMS RCM Foo Boo'\n });\n\n } else {\n\n this.apiCall('POST', '/restapi/oauth/token', {\n 'message': 'Wrong token',\n 'error_description': 'Wrong token',\n 'description': 'Wrong token'\n }, 400);\n\n }\n\n return this;\n\n }\n\n}\n\n\n/** WEBPACK FOOTER **\n ** ./src/mocks/Registry.js\n **/","import ApiResponse from '../http/ApiResponse';\nimport {delay} from '../core/Utils';\nimport {createResponse} from '../http/Utils';\n\nexport default class Mock {\n\n constructor(method, path, json, status, statusText, delay) {\n this._method = method.toUpperCase();\n this._path = path;\n this._json = json || {};\n this._delay = delay || 10;\n this._status = status || 200;\n this._statusText = statusText || 'OK';\n }\n\n path() {\n return this._path;\n }\n\n method() {\n return this._method;\n }\n\n test(request:Request) {\n\n return request.url.indexOf(this._path) > -1 &&\n request.method.toUpperCase() == this._method;\n\n }\n\n async getResponse(request) {\n\n await delay(this._delay);\n\n return this.createResponse(this._json);\n\n }\n\n createResponse(json, init) {\n\n init = init || {};\n\n init.status = init.status || this._status;\n init.statusText = init.statusText || this._statusText;\n\n var str = JSON.stringify(json),\n res = createResponse(str, init);\n\n res.headers.set(ApiResponse._contentType, ApiResponse._jsonContentType);\n\n return res;\n\n }\n\n}\n\n\n/** WEBPACK FOOTER **\n ** ./src/mocks/Mock.js\n **/","import Observable from '../core/Observable';\nimport Queue from '../core/Queue';\nimport Auth from './Auth';\nimport {Promise} from '../core/Externals';\nimport {queryStringify, parseQueryString, delay} from '../core/Utils';\n\nexport default class Platform extends Observable {\n\n static _urlPrefix = '/restapi';\n static _apiVersion = 'v1.0';\n static _accessTokenTtl = null; // Platform server by default sets it to 60 * 60 = 1 hour\n static _refreshTokenTtl = 10 * 60 * 60; // 10 hours\n static _refreshTokenTtlRemember = 7 * 24 * 60 * 60; // 1 week\n static _tokenEndpoint = '/restapi/oauth/token';\n static _revokeEndpoint = '/restapi/oauth/revoke';\n static _authorizeEndpoint = '/restapi/oauth/authorize';\n static _refreshDelayMs = 100;\n static _cacheId = 'platform';\n static _clearCacheOnRefreshError = true;\n\n events = {\n beforeLogin: 'beforeLogin',\n loginSuccess: 'loginSuccess',\n loginError: 'loginError',\n beforeRefresh: 'beforeRefresh',\n refreshSuccess: 'refreshSuccess',\n refreshError: 'refreshError',\n beforeLogout: 'beforeLogout',\n logoutSuccess: 'logoutSuccess',\n logoutError: 'logoutError'\n };\n\n constructor(client, cache, server, appKey, appSecret) {\n\n super();\n\n this._server = server;\n this._appKey = appKey;\n this._appSecret = appSecret;\n\n /** @type {Cache} */\n this._cache = cache;\n\n /** @type {Client} */\n this._client = client;\n\n this._queue = new Queue(this._cache, Platform._cacheId + '-refresh');\n\n this._auth = new Auth(this._cache, Platform._cacheId);\n\n }\n\n /**\n * @return {Auth}\n */\n auth() {\n return this._auth;\n }\n\n /**\n * @return {Client}\n */\n client() {\n return this._client;\n }\n\n /**\n * @param {string} path\n * @param {object} [options]\n * @param {boolean} [options.addServer]\n * @param {string} [options.addMethod]\n * @param {boolean} [options.addToken]\n * @return {string}\n */\n createUrl(path, options) {\n\n path = path || '';\n options = options || {};\n\n var builtUrl = '',\n hasHttp = path.indexOf('http://') != -1 || path.indexOf('https://') != -1;\n\n if (options.addServer && !hasHttp) builtUrl += this._server;\n\n if (path.indexOf(Platform._urlPrefix) == -1 && !hasHttp) builtUrl += Platform._urlPrefix + '/' + Platform._apiVersion;\n\n builtUrl += path;\n\n if (options.addMethod || options.addToken) builtUrl += (path.indexOf('?') > -1 ? '&' : '?');\n\n if (options.addMethod) builtUrl += '_method=' + options.addMethod;\n if (options.addToken) builtUrl += (options.addMethod ? '&' : '') + 'access_token=' + this._auth.accessToken();\n\n return builtUrl;\n\n }\n\n /**\n * @param {string} options.redirectUri\n * @param {string} options.state\n * @param {string} options.brandId\n * @param {string} options.display\n * @param {string} options.prompt\n * @return {string}\n */\n authUrl(options) {\n\n options = options || {};\n\n return this.createUrl(Platform._authorizeEndpoint + '?' + queryStringify({\n 'response_type': 'code',\n 'redirect_uri': options.redirectUri || '',\n 'client_id': this._appKey,\n 'state': options.state || '',\n 'brand_id': options.brandId || '',\n 'display': options.display || '',\n 'prompt': options.prompt || ''\n }), {addServer: true})\n\n }\n\n /**\n * @param {string} url\n * @return {Object}\n */\n parseAuthRedirectUrl(url:string) {\n\n var qs = parseQueryString(url.split('?').reverse()[0]),\n error = qs.error_description || qs.error;\n\n if (error) {\n var e = new Error(error);\n e.error = qs.error;\n throw e;\n }\n\n return qs;\n\n }\n\n /**\n * @return {Promise}\n */\n async loggedIn() {\n\n try {\n await this._ensureAuthentication();\n return true;\n } catch (e) {\n return false;\n }\n\n }\n\n /**\n * @param {string} options.username\n * @param {string} options.password\n * @param {string} options.extension\n * @param {string} options.code\n * @param {string} options.redirectUri\n * @param {string} options.endpointId\n * @returns {Promise}\n */\n async login(options) {\n\n try {\n\n options = options || {};\n\n options.remember = options.remember || false;\n\n this.emit(this.events.beforeLogin);\n\n var body = {\n \"access_token_ttl\": Platform._accessTokenTtl,\n \"refresh_token_ttl\": options.remember ? Platform._refreshTokenTtlRemember : Platform._refreshTokenTtl\n };\n\n if (!options.code) {\n\n body.grant_type = 'password';\n body.username = options.username;\n body.password = options.password;\n body.extension = options.extension || '';\n\n } else if (options.code) {\n\n body.grant_type = 'authorization_code';\n body.code = options.code;\n body.redirect_uri = options.redirectUri;\n //body.client_id = this.getCredentials().key; // not needed\n\n }\n\n if (options.endpointId) body.endpoint_id = options.endpointId;\n\n var apiResponse = await this._tokenRequest(Platform._tokenEndpoint, body),\n json = apiResponse.json();\n\n this._auth\n .setData(json)\n .setRemember(options.remember);\n\n this.emit(this.events.loginSuccess, apiResponse);\n\n return apiResponse;\n\n } catch (e) {\n\n this._cache.clean();\n\n this.emit(this.events.loginError, e);\n\n throw e;\n\n }\n\n }\n\n /**\n * @returns {Promise}\n */\n async refresh() {\n\n try {\n\n this.emit(this.events.beforeRefresh);\n\n if (this._queue.isPaused()) {\n\n await this._queue.poll();\n\n if (!this._isAccessTokenValid()) {\n throw new Error('Automatic authentification timeout');\n }\n\n this.emit(this.events.refreshSuccess, null);\n\n return null;\n\n }\n\n this._queue.pause();\n\n // Make sure all existing AJAX calls had a chance to reach the server\n await delay(Platform._refreshDelayMs);\n\n // Perform sanity checks\n if (!this._auth.refreshToken()) throw new Error('Refresh token is missing');\n if (!this._auth.refreshTokenValid()) throw new Error('Refresh token has expired');\n if (!this._queue.isPaused()) throw new Error('Queue was resumed before refresh call');\n\n /** @type {ApiResponse} */\n var res = await this._tokenRequest(Platform._tokenEndpoint, {\n \"grant_type\": \"refresh_token\",\n \"refresh_token\": this._auth.refreshToken(),\n \"access_token_ttl\": Platform._accessTokenTtl,\n \"refresh_token_ttl\": this._auth.remember() ? Platform._refreshTokenTtlRemember : Platform._refreshTokenTtl\n }),\n json = res.json();\n\n if (!json.access_token) {\n throw this._client.makeError(new Error('Malformed OAuth response'), res);\n }\n\n this._auth.setData(json);\n this._queue.resume();\n\n this.emit(this.events.refreshSuccess, res);\n\n return res;\n\n } catch (e) {\n\n e = this._client.makeError(e);\n\n if (Platform._clearCacheOnRefreshError) {\n this._cache.clean();\n }\n\n this.emit(this.events.refreshError, e);\n\n throw e;\n\n }\n\n }\n\n /**\n * @returns {Promise}\n */\n async logout() {\n\n try {\n\n this.emit(this.events.beforeLogout);\n\n this._queue.pause();\n\n var res = await this._tokenRequest(Platform._revokeEndpoint, {\n token: this._auth.accessToken()\n });\n\n this._queue.resume();\n this._cache.clean();\n\n this.emit(this.events.logoutSuccess, res);\n\n return res;\n\n } catch (e) {\n\n this._queue.resume();\n\n this.emit(this.events.logoutError, e);\n\n throw e;\n\n }\n\n }\n\n /**\n * @param {Request} request\n * @param {object} [options]\n * @param {boolean} [options.skipAuthCheck]\n * @return {Promise}\n */\n async inflateRequest(request, options) {\n\n options = options || {};\n\n if (options.skipAuthCheck) return request;\n\n await this._ensureAuthentication();\n\n request.headers.set('Authorization', this._authHeader());\n //request.url = this.createUrl(request.url, {addServer: true}); //FIXME Spec prevents this...\n\n //TODO Add User-Agent here\n\n return request;\n\n }\n\n /**\n * @param {Request} request\n * @param {object} [options]\n * @param {boolean} [options.skipAuthCheck]\n * @return {Promise}\n */\n async sendRequest(request, options) {\n\n try {\n\n request = await this.inflateRequest(request, options);\n\n return (await this._client.sendRequest(request));\n\n } catch (e) {\n\n // Guard is for errors that come from polling\n if (!e.apiResponse || !e.apiResponse.response() || (e.apiResponse.response().status != 401)) throw e;\n\n this._auth.cancelAccessToken();\n\n return (await this.sendRequest(request, options));\n\n }\n\n }\n\n /**\n * General purpose function to send anything to server\n * @param {string} options.url\n * @param {object} [options.body]\n * @param {string} [options.method]\n * @param {object} [options.query]\n * @param {object} [options.headers]\n * @param {boolean} [options.skipAuthCheck]\n * @return {Promise}\n */\n async send(options = {}) {\n\n //FIXME https://github.com/bitinn/node-fetch/issues/43\n options.url = this.createUrl(options.url, {addServer: true});\n\n return await this.sendRequest(this._client.createRequest(options), options);\n\n }\n\n /**\n * @param {string} url\n * @param {object} [query]\n * @param {object} [options]\n * @param {object} [options.headers]\n * @param {boolean} [options.skipAuthCheck]\n * @return {Promise}\n */\n async get(url, query, options) {\n options = options || {};\n options.method = 'GET';\n options.url = url;\n options.query = query;\n return await this.send(options);\n }\n\n /**\n * @param {string} url\n * @param {object} body\n * @param {object} [query]\n * @param {object} [options]\n * @param {object} [options.headers]\n * @param {boolean} [options.skipAuthCheck]\n * @return {Promise}\n */\n async post(url, body, query, options) {\n options = options || {};\n options.method = 'POST';\n options.url = url;\n options.query = query;\n options.body = body;\n return await this.send(options);\n }\n\n /**\n * @param {string} url\n * @param {object} [body]\n * @param {object} [query]\n * @param {object} [options]\n * @param {object} [options.headers]\n * @param {boolean} [options.skipAuthCheck]\n * @return {Promise}\n */\n async put(url, body, query, options) {\n options = options || {};\n options.method = 'PUT';\n options.url = url;\n options.query = query;\n options.body = body;\n return await this.send(options);\n }\n\n /**\n * @param {string} url\n * @param {string} [query]\n * @param {object} [options]\n * @param {object} [options.headers]\n * @param {boolean} [options.skipAuthCheck]\n * @return {Promise}\n */\n async 'delete'(url, query, options) {\n options = options || {};\n options.method = 'DELETE';\n options.url = url;\n options.query = query;\n return await this.send(options);\n }\n\n async _tokenRequest(path, body) {\n\n return await this.send({\n url: path,\n skipAuthCheck: true,\n body: body,\n method: 'POST',\n headers: {\n 'Authorization': 'Basic ' + this._apiKey(),\n 'Content-Type': 'application/x-www-form-urlencoded'\n }\n });\n\n }\n\n async _ensureAuthentication() {\n\n if (this._isAccessTokenValid()) return null;\n return await this.refresh();\n\n }\n\n _isAccessTokenValid() {\n\n return (this._auth.accessTokenValid() && !this._queue.isPaused());\n\n }\n\n _apiKey() {\n var apiKey = this._appKey + ':' + this._appSecret;\n return (typeof btoa == 'function') ? btoa(apiKey) : new Buffer(apiKey).toString('base64');\n }\n\n _authHeader() {\n var token = this._auth.accessToken();\n return this._auth.tokenType() + (token ? ' ' + token : '');\n }\n\n}\n\n\n/** WEBPACK FOOTER **\n ** ./src/platform/Platform.js\n **/","export default class Auth {\n\n static refreshHandicapMs:number = 60 * 1000; // 1 minute\n static forcedTokenType = 'forced';\n\n constructor(cache, cacheId:string) {\n\n /** @type {Cache} */\n this._cache = cache;\n this._cacheId = cacheId;\n\n }\n\n accessToken() {\n return this.data().access_token;\n }\n\n refreshToken() {\n return this.data().refresh_token;\n }\n\n tokenType() {\n return this.data().token_type;\n }\n\n /**\n * @return {{token_type: string, access_token: string, expires_in: number, refresh_token: string, refresh_token_expires_in: number}}\n */\n data() {\n\n return this._cache.getItem(this._cacheId) || {\n token_type: '',\n access_token: '',\n expires_in: 0,\n refresh_token: '',\n refresh_token_expires_in: 0\n };\n\n }\n\n /**\n * @param {object} newData\n * @return {Auth}\n */\n setData(newData) {\n\n newData = newData || {};\n\n var data = this.data();\n\n Object.keys(newData).forEach((key) => {\n data[key] = newData[key];\n });\n\n data.expire_time = Date.now() + (data.expires_in * 1000);\n data.refresh_token_expire_time = Date.now() + (data.refresh_token_expires_in * 1000);\n\n this._cache.setItem(this._cacheId, data);\n\n return this;\n\n }\n\n /**\n * Check if there is a valid (not expired) access token\n * @return {boolean}\n */\n accessTokenValid() {\n\n var authData = this.data();\n return (authData.token_type === Auth.forcedTokenType || (authData.expire_time - Auth.refreshHandicapMs > Date.now()));\n\n }\n\n /**\n * Check if there is a valid (not expired) access token\n * @return {boolean}\n */\n refreshTokenValid() {\n\n return (this.data().refresh_token_expire_time > Date.now());\n\n }\n\n /**\n * @return {Auth}\n */\n cancelAccessToken() {\n\n return this.setData({\n access_token: '',\n expires_in: 0\n });\n\n }\n\n /**\n * This method sets a special authentication mode used in Service Web\n * @return {Auth}\n */\n forceAuthentication() {\n\n this.setData({\n token_type: Auth.forcedTokenType,\n access_token: '',\n expires_in: 0,\n refresh_token: '',\n refresh_token_expires_in: 0\n });\n\n return this;\n\n }\n\n /**\n * @param remember\n * @return {Auth}\n */\n setRemember(remember) {\n\n return this.setData({remember: remember});\n\n }\n\n /**\n * @return {boolean}\n */\n remember() {\n\n return !!this.data().remember;\n\n }\n\n}\n\n//export interface IAuthData {\n// remember?:boolean;\n// token_type?:string;\n// access_token?:string;\n// expires_in?:number; // actually it's string\n// expire_time?:number;\n// refresh_token?:string;\n// refresh_token_expires_in?:number; // actually it's string\n// refresh_token_expire_time?:number;\n// scope?:string;\n//}\n\n\n\n/** WEBPACK FOOTER **\n ** ./src/platform/Auth.js\n **/","import PubnubMock from './PubnubMock.js';\nimport {PUBNUB} from '../core/Externals';\n\nexport default class PubnubMockFactory {\n\n constructor() {\n this.crypto_obj = PUBNUB.crypto_obj;\n }\n\n init(options:PUBNUBInitOptions) {\n return new PubnubMock(options);\n }\n\n}\n\n\n/** WEBPACK FOOTER **\n ** ./src/pubnub/PubnubFactory.js\n **/","import Observable from '../core/Observable';\nimport {PUBNUB} from '../core/Externals';\n\nexport default class PubnubMock extends Observable {\n\n constructor(options) {\n super();\n this.options = options;\n this.crypto_obj = PUBNUB.crypto_obj;\n }\n\n ready() {}\n\n subscribe(options:PUBNUBSubscribeOptions) {\n this.on('message-' + options.channel, options.message);\n }\n\n unsubscribe(options:PUBNUBUnsubscribeOptions) {\n this.off('message-' + options.channel);\n }\n\n receiveMessage(msg, channel) {\n this.emit('message-' + channel, msg, 'env', channel);\n }\n\n}\n\n\n/** WEBPACK FOOTER **\n ** ./src/pubnub/PubnubMock.js\n **/","import Observable from '../core/Observable';\nimport Client from '../http/Client';\nimport {poll, stopPolling, delay} from '../core/Utils';\n\nexport default class Subscription extends Observable {\n\n static _renewHandicapMs = 2 * 60 * 1000;\n static _pollInterval = 10 * 1000;\n\n events = {\n notification: 'notification',\n removeSuccess: 'removeSuccess',\n removeError: 'removeError',\n renewSuccess: 'renewSuccess',\n renewError: 'renewError',\n subscribeSuccess: 'subscribeSuccess',\n subscribeError: 'subscribeError'\n };\n\n constructor(pubnubFactory, platform) {\n\n super();\n\n this._pubnubFactory = pubnubFactory;\n this._platform = platform;\n this._pubnub = null;\n this._timeout = null;\n this._subscription = {};\n\n }\n\n subscribed(){\n\n return !!(this._subscription.id &&\n this._subscription.deliveryMode &&\n this._subscription.deliveryMode.subscriberKey &&\n this._subscription.deliveryMode.address);\n\n }\n\n /**\n * @return {boolean}\n */\n alive() {\n\n return this.subscribed() && Date.now() < this.expirationTime();\n\n }\n\n expirationTime() {\n return new Date(this._subscription.expirationTime || 0).getTime() - Subscription._renewHandicapMs;\n }\n\n setSubscription(subscription) {\n\n subscription = subscription || {};\n\n this._clearTimeout();\n\n this._subscription = subscription;\n\n if (!this._pubnub) this._subscribeAtPubnub();\n\n this._setTimeout();\n\n return this;\n\n }\n\n subscription() {\n return this._subscription;\n }\n\n /**\n * Creates or updates subscription if there is an active one\n * @returns {Promise}\n */\n async register() {\n\n if (this.alive()) {\n return await this.renew();\n } else {\n return await this.subscribe();\n }\n\n }\n\n eventFilters() {\n return this._subscription.eventFilters || [];\n }\n\n /**\n * @param {string[]} events\n * @return {Subscription}\n */\n addEventFilters(events) {\n this.setEventFilters(this.eventFilters().concat(events));\n return this;\n }\n\n /**\n * @param {string[]} events\n * @return {Subscription}\n */\n setEventFilters(events) {\n this._subscription.eventFilters = events;\n return this;\n }\n\n /**\n * @returns {Promise}\n */\n async subscribe() {\n\n try {\n\n this._clearTimeout();\n\n if (!this.eventFilters().length) throw new Error('Events are undefined');\n\n var response = await this._platform.post('/restapi/v1.0/subscription', {\n eventFilters: this._getFullEventFilters(),\n deliveryMode: {\n transportType: 'PubNub'\n }\n }),\n json = response.json();\n\n this.setSubscription(json)\n .emit(this.events.subscribeSuccess, response);\n\n return response;\n\n\n } catch (e) {\n\n e = this._platform.client().makeError(e);\n\n this.reset()\n .emit(this.events.subscribeError, e);\n\n throw e;\n\n }\n\n }\n\n /**\n * @returns {Promise}\n */\n async renew() {\n\n try {\n\n this._clearTimeout();\n\n if (!this.alive()) throw new Error('Subscription is not alive');\n\n if (!this.eventFilters().length) throw new Error('Events are undefined');\n\n var response = await this._platform.put('/restapi/v1.0/subscription/' + this._subscription.id, {\n eventFilters: this._getFullEventFilters()\n });\n\n var json = response.json();\n\n this.setSubscription(json)\n .emit(this.events.renewSuccess, response);\n\n return response;\n\n } catch (e) {\n\n e = this._platform.client().makeError(e);\n\n this.reset()\n .emit(this.events.renewError, e);\n\n throw e;\n\n }\n\n }\n\n /**\n * @returns {Promise}\n */\n async remove() {\n\n try {\n\n if (!this.subscribed()) throw new Error('No subscription');\n\n var response = await this._platform.delete('/restapi/v1.0/subscription/' + this._subscription.id);\n\n this.reset()\n .emit(this.events.removeSuccess, response);\n\n return response;\n\n } catch (e) {\n\n e = this._platform.client().makeError(e);\n\n this.emit(this.events.removeError, e);\n\n throw e;\n\n }\n\n }\n\n /**\n * @returns {Promise}\n */\n resubscribe() {\n\n return this.reset().setEventFilters(this.eventFilters()).subscribe();\n\n }\n\n /**\n * Remove subscription and disconnect from PUBNUB\n * This method resets subscription at client side but backend is not notified\n */\n reset() {\n this._clearTimeout();\n if (this.subscribed() && this._pubnub) this._pubnub.unsubscribe({channel: this._subscription.deliveryMode.address});\n this._subscription = {};\n return this;\n }\n\n _getFullEventFilters() {\n\n return this.eventFilters().map((event) => {\n return this._platform.createUrl(event);\n });\n\n }\n\n _setTimeout() {\n\n this._clearTimeout();\n\n if (!this.alive()) throw new Error('Subscription is not alive');\n\n poll((next)=> {\n\n if (this.alive()) return next();\n\n this.renew();\n\n }, Subscription._pollInterval, this._timeout);\n\n return this;\n\n }\n\n _clearTimeout() {\n\n stopPolling(this._timeout);\n\n return this;\n\n }\n\n _decrypt(message:any) {\n\n if (!this.subscribed()) throw new Error('No subscription');\n\n if (this._subscription.deliveryMode.encryptionKey) {\n\n var PUBNUB = this._pubnubFactory;\n\n message = PUBNUB.crypto_obj.decrypt(message, this._subscription.deliveryMode.encryptionKey, {\n encryptKey: false,\n keyEncoding: 'base64',\n keyLength: 128,\n mode: 'ecb'\n });\n\n }\n\n return message;\n\n }\n\n _notify(message:any) {\n\n this.emit(this.events.notification, this._decrypt(message));\n\n return this;\n\n }\n\n _subscribeAtPubnub():Subscription {\n\n if (!this.alive()) throw new Error('Subscription is not alive');\n\n var PUBNUB = this._pubnubFactory;\n\n this._pubnub = PUBNUB.init({\n ssl: true,\n subscribe_key: this._subscription.deliveryMode.subscriberKey\n });\n\n this._pubnub.ready();\n\n this._pubnub.subscribe({\n channel: this._subscription.deliveryMode.address,\n message: this._notify.bind(this),\n connect: () => {}\n });\n\n return this;\n\n }\n\n}\n\n//export interface ISubscription {\n// id?:string;\n// uri?: string;\n// eventFilters?:string[];\n// expirationTime?:string; // 2014-03-12T19:54:35.613Z\n// expiresIn?:number;\n// deliveryMode?: {\n// transportType?:string;\n// encryption?:boolean;\n// address?:string;\n// subscriberKey?:string;\n// encryptionKey?:string;\n// secretKey?:string;\n// };\n// creationTime?:string; // 2014-03-12T19:54:35.613Z\n// status?:string; // Active\n//}\n\n\n\n/** WEBPACK FOOTER **\n ** ./src/subscription/Subscription.js\n **/","import Subscription from './Subscription';\nimport Queue from '../core/Queue';\n\nexport default class CachedSubscription extends Subscription {\n\n constructor(pubnubFactory, platform, cache, cacheKey) {\n\n super(pubnubFactory, platform);\n\n this._cache = cache;\n this._cacheKey = cacheKey;\n this._renewQueue = new Queue(this._cache, cacheKey + '-renew');\n this._resubscribeQueue = new Queue(this._cache, cacheKey + '-resubscribe');\n\n this.events = {\n ...this.events,\n queuedRenewSuccess: 'queuedRenewSuccess',\n queuedRenewError: 'queuedRenewError',\n queuedResubscribeSuccess: 'queuedResubscribeSuccess',\n queuedResubscribeError: 'queuedResubscribeError'\n };\n\n this.on(this.events.renewError, () => {\n this.resubscribe();\n });\n\n this.on([this.events.subscribeSuccess, this.events.renewSuccess], () => {\n this._cache.setItem(this._cacheKey, this.subscription());\n });\n\n this.on(this.events.removeSuccess, () => {\n this._cache.removeItem(this._cacheKey);\n });\n\n }\n\n /**\n * TODO Combine with Platform.refresh and move elsewhere\n * @param actionCb\n * @param queue\n * @param successEvent\n * @param errorEvent\n * @param errorMessage\n * @return {*}\n * @private\n */\n async _queue(actionCb, queue, successEvent, errorEvent, errorMessage) {\n\n try {\n\n if (queue.isPaused()) {\n\n await queue.poll();\n\n if (!this.alive()) {\n throw new Error(errorMessage);\n }\n\n this.emit(successEvent, null);\n\n return null;\n\n }\n\n queue.pause();\n\n var res = await actionCb.call(this);\n\n queue.resume();\n\n this.emit(successEvent, res);\n\n return res;\n\n } catch (e) {\n\n this.emit(errorEvent, e);\n\n throw e;\n\n }\n\n }\n\n /**\n * @returns {Promise}\n */\n renew() {\n\n return this._queue(\n super.renew,\n this._renewQueue,\n this.events.queuedRenewSuccess,\n this.events.queuedRenewError,\n 'Subscription is not alive after renew timeout'\n );\n\n }\n\n /**\n * @returns {Promise}\n */\n resubscribe() {\n\n return this._queue(\n super.resubscribe,\n this._resubscribeQueue,\n this.events.queuedResubscribeSuccess,\n this.events.queuedResubscribeError,\n 'Subscription is not alive after resubscribe timeout'\n );\n\n }\n\n /**\n * @param {string[]} events\n * @return {CachedSubscription}\n */\n restore(events) {\n\n var cachedSubscriptionData = this._cache.getItem(this._cacheKey);\n\n if (cachedSubscriptionData) {\n try {\n this.setSubscription(cachedSubscriptionData);\n } catch (e) {}\n } else {\n this.setEventFilters(events);\n }\n\n return this;\n\n }\n\n}\n\n\n/** WEBPACK FOOTER **\n ** ./src/subscription/CachedSubscription.js\n **/","/**\n * Copyright (c) 2014, Facebook, Inc.\n * All rights reserved.\n *\n * This source code is licensed under the BSD-style license found in the\n * https://raw.github.com/facebook/regenerator/master/LICENSE file. An\n * additional grant of patent rights can be found in the PATENTS file in\n * the same directory.\n */\n\n!(function(global) {\n \"use strict\";\n\n var hasOwn = Object.prototype.hasOwnProperty;\n var undefined; // More compressible than void 0.\n var iteratorSymbol =\n typeof Symbol === \"function\" && Symbol.iterator || \"@@iterator\";\n\n var inModule = typeof module === \"object\";\n var runtime = global.regeneratorRuntime;\n if (runtime) {\n if (inModule) {\n // If regeneratorRuntime is defined globally and we're in a module,\n // make the exports object identical to regeneratorRuntime.\n module.exports = runtime;\n }\n // Don't bother evaluating the rest of this file if the runtime was\n // already defined globally.\n return;\n }\n\n // Define the runtime globally (as expected by generated code) as either\n // module.exports (if we're in a module) or a new, empty object.\n runtime = global.regeneratorRuntime = inModule ? module.exports : {};\n\n function wrap(innerFn, outerFn, self, tryLocsList) {\n // If outerFn provided, then outerFn.prototype instanceof Generator.\n var generator = Object.create((outerFn || Generator).prototype);\n var context = new Context(tryLocsList || []);\n\n // The ._invoke method unifies the implementations of the .next,\n // .throw, and .return methods.\n generator._invoke = makeInvokeMethod(innerFn, self, context);\n\n return generator;\n }\n runtime.wrap = wrap;\n\n // Try/catch helper to minimize deoptimizations. Returns a completion\n // record like context.tryEntries[i].completion. This interface could\n // have been (and was previously) designed to take a closure to be\n // invoked without arguments, but in all the cases we care about we\n // already have an existing method we want to call, so there's no need\n // to create a new function object. We can even get away with assuming\n // the method takes exactly one argument, since that happens to be true\n // in every case, so we don't have to touch the arguments object. The\n // only additional allocation required is the completion record, which\n // has a stable shape and so hopefully should be cheap to allocate.\n function tryCatch(fn, obj, arg) {\n try {\n return { type: \"normal\", arg: fn.call(obj, arg) };\n } catch (err) {\n return { type: \"throw\", arg: err };\n }\n }\n\n var GenStateSuspendedStart = \"suspendedStart\";\n var GenStateSuspendedYield = \"suspendedYield\";\n var GenStateExecuting = \"executing\";\n var GenStateCompleted = \"completed\";\n\n // Returning this object from the innerFn has the same effect as\n // breaking out of the dispatch switch statement.\n var ContinueSentinel = {};\n\n // Dummy constructor functions that we use as the .constructor and\n // .constructor.prototype properties for functions that return Generator\n // objects. For full spec compliance, you may wish to configure your\n // minifier not to mangle the names of these two functions.\n function Generator() {}\n function GeneratorFunction() {}\n function GeneratorFunctionPrototype() {}\n\n var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype;\n GeneratorFunction.prototype = Gp.constructor = GeneratorFunctionPrototype;\n GeneratorFunctionPrototype.constructor = GeneratorFunction;\n GeneratorFunction.displayName = \"GeneratorFunction\";\n\n // Helper for defining the .next, .throw, and .return methods of the\n // Iterator interface in terms of a single ._invoke method.\n function defineIteratorMethods(prototype) {\n [\"next\", \"throw\", \"return\"].forEach(function(method) {\n prototype[method] = function(arg) {\n return this._invoke(method, arg);\n };\n });\n }\n\n runtime.isGeneratorFunction = function(genFun) {\n var ctor = typeof genFun === \"function\" && genFun.constructor;\n return ctor\n ? ctor === GeneratorFunction ||\n // For the native GeneratorFunction constructor, the best we can\n // do is to check its .name property.\n (ctor.displayName || ctor.name) === \"GeneratorFunction\"\n : false;\n };\n\n runtime.mark = function(genFun) {\n if (Object.setPrototypeOf) {\n Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);\n } else {\n genFun.__proto__ = GeneratorFunctionPrototype;\n }\n genFun.prototype = Object.create(Gp);\n return genFun;\n };\n\n // Within the body of any async function, `await x` is transformed to\n // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test\n // `value instanceof AwaitArgument` to determine if the yielded value is\n // meant to be awaited. Some may consider the name of this method too\n // cutesy, but they are curmudgeons.\n runtime.awrap = function(arg) {\n return new AwaitArgument(arg);\n };\n\n function AwaitArgument(arg) {\n this.arg = arg;\n }\n\n function AsyncIterator(generator) {\n // This invoke function is written in a style that assumes some\n // calling function (or Promise) will handle exceptions.\n function invoke(method, arg) {\n var result = generator[method](arg);\n var value = result.value;\n return value instanceof AwaitArgument\n ? Promise.resolve(value.arg).then(invokeNext, invokeThrow)\n : Promise.resolve(value).then(function(unwrapped) {\n // When a yielded Promise is resolved, its final value becomes\n // the .value of the Promise<{value,done}> result for the\n // current iteration. If the Promise is rejected, however, the\n // result for this iteration will be rejected with the same\n // reason. Note that rejections of yielded Promises are not\n // thrown back into the generator function, as is the case\n // when an awaited Promise is rejected. This difference in\n // behavior between yield and await is important, because it\n // allows the consumer to decide what to do with the yielded\n // rejection (swallow it and continue, manually .throw it back\n // into the generator, abandon iteration, whatever). With\n // await, by contrast, there is no opportunity to examine the\n // rejection reason outside the generator function, so the\n // only option is to throw it from the await expression, and\n // let the generator function handle the exception.\n result.value = unwrapped;\n return result;\n });\n }\n\n if (typeof process === \"object\" && process.domain) {\n invoke = process.domain.bind(invoke);\n }\n\n var invokeNext = invoke.bind(generator, \"next\");\n var invokeThrow = invoke.bind(generator, \"throw\");\n var invokeReturn = invoke.bind(generator, \"return\");\n var previousPromise;\n\n function enqueue(method, arg) {\n function callInvokeWithMethodAndArg() {\n return invoke(method, arg);\n }\n\n return previousPromise =\n // If enqueue has been called before, then we want to wait until\n // all previous Promises have been resolved before calling invoke,\n // so that results are always delivered in the correct order. If\n // enqueue has not been called before, then it is important to\n // call invoke immediately, without waiting on a callback to fire,\n // so that the async generator function has the opportunity to do\n // any necessary setup in a predictable way. This predictability\n // is why the Promise constructor synchronously invokes its\n // executor callback, and why async functions synchronously\n // execute code before the first await. Since we implement simple\n // async functions in terms of async generators, it is especially\n // important to get this right, even though it requires care.\n previousPromise ? previousPromise.then(\n callInvokeWithMethodAndArg,\n // Avoid propagating failures to Promises returned by later\n // invocations of the iterator.\n callInvokeWithMethodAndArg\n ) : new Promise(function (resolve) {\n resolve(callInvokeWithMethodAndArg());\n });\n }\n\n // Define the unified helper method that is used to implement .next,\n // .throw, and .return (see defineIteratorMethods).\n this._invoke = enqueue;\n }\n\n defineIteratorMethods(AsyncIterator.prototype);\n\n // Note that simple async functions are implemented on top of\n // AsyncIterator objects; they just return a Promise for the value of\n // the final result produced by the iterator.\n runtime.async = function(innerFn, outerFn, self, tryLocsList) {\n var iter = new AsyncIterator(\n wrap(innerFn, outerFn, self, tryLocsList)\n );\n\n return runtime.isGeneratorFunction(outerFn)\n ? iter // If outerFn is a generator, return the full iterator.\n : iter.next().then(function(result) {\n return result.done ? result.value : iter.next();\n });\n };\n\n function makeInvokeMethod(innerFn, self, context) {\n var state = GenStateSuspendedStart;\n\n return function invoke(method, arg) {\n if (state === GenStateExecuting) {\n throw new Error(\"Generator is already running\");\n }\n\n if (state === GenStateCompleted) {\n if (method === \"throw\") {\n throw arg;\n }\n\n // Be forgiving, per 25.3.3.3.3 of the spec:\n // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume\n return doneResult();\n }\n\n while (true) {\n var delegate = context.delegate;\n if (delegate) {\n if (method === \"return\" ||\n (method === \"throw\" && delegate.iterator[method] === undefined)) {\n // A return or throw (when the delegate iterator has no throw\n // method) always terminates the yield* loop.\n context.delegate = null;\n\n // If the delegate iterator has a return method, give it a\n // chance to clean up.\n var returnMethod = delegate.iterator[\"return\"];\n if (returnMethod) {\n var record = tryCatch(returnMethod, delegate.iterator, arg);\n if (record.type === \"throw\") {\n // If the return method threw an exception, let that\n // exception prevail over the original return or throw.\n method = \"throw\";\n arg = record.arg;\n continue;\n }\n }\n\n if (method === \"return\") {\n // Continue with the outer return, now that the delegate\n // iterator has been terminated.\n continue;\n }\n }\n\n var record = tryCatch(\n delegate.iterator[method],\n delegate.iterator,\n arg\n );\n\n if (record.type === \"throw\") {\n context.delegate = null;\n\n // Like returning generator.throw(uncaught), but without the\n // overhead of an extra function call.\n method = \"throw\";\n arg = record.arg;\n continue;\n }\n\n // Delegate generator ran and handled its own exceptions so\n // regardless of what the method was, we continue as if it is\n // \"next\" with an undefined arg.\n method = \"next\";\n arg = undefined;\n\n var info = record.arg;\n if (info.done) {\n context[delegate.resultName] = info.value;\n context.next = delegate.nextLoc;\n } else {\n state = GenStateSuspendedYield;\n return info;\n }\n\n context.delegate = null;\n }\n\n if (method === \"next\") {\n if (state === GenStateSuspendedYield) {\n context.sent = arg;\n } else {\n context.sent = undefined;\n }\n\n } else if (method === \"throw\") {\n if (state === GenStateSuspendedStart) {\n state = GenStateCompleted;\n throw arg;\n }\n\n if (context.dispatchException(arg)) {\n // If the dispatched exception was caught by a catch block,\n // then let that catch block handle the exception normally.\n method = \"next\";\n arg = undefined;\n }\n\n } else if (method === \"return\") {\n context.abrupt(\"return\", arg);\n }\n\n state = GenStateExecuting;\n\n var record = tryCatch(innerFn, self, context);\n if (record.type === \"normal\") {\n // If an exception is thrown from innerFn, we leave state ===\n // GenStateExecuting and loop back for another invocation.\n state = context.done\n ? GenStateCompleted\n : GenStateSuspendedYield;\n\n var info = {\n value: record.arg,\n done: context.done\n };\n\n if (record.arg === ContinueSentinel) {\n if (context.delegate && method === \"next\") {\n // Deliberately forget the last sent value so that we don't\n // accidentally pass it on to the delegate.\n arg = undefined;\n }\n } else {\n return info;\n }\n\n } else if (record.type === \"throw\") {\n state = GenStateCompleted;\n // Dispatch the exception by looping back around to the\n // context.dispatchException(arg) call above.\n method = \"throw\";\n arg = record.arg;\n }\n }\n };\n }\n\n // Define Generator.prototype.{next,throw,return} in terms of the\n // unified ._invoke helper method.\n defineIteratorMethods(Gp);\n\n Gp[iteratorSymbol] = function() {\n return this;\n };\n\n Gp.toString = function() {\n return \"[object Generator]\";\n };\n\n function pushTryEntry(locs) {\n var entry = { tryLoc: locs[0] };\n\n if (1 in locs) {\n entry.catchLoc = locs[1];\n }\n\n if (2 in locs) {\n entry.finallyLoc = locs[2];\n entry.afterLoc = locs[3];\n }\n\n this.tryEntries.push(entry);\n }\n\n function resetTryEntry(entry) {\n var record = entry.completion || {};\n record.type = \"normal\";\n delete record.arg;\n entry.completion = record;\n }\n\n function Context(tryLocsList) {\n // The root entry object (effectively a try statement without a catch\n // or a finally block) gives us a place to store values thrown from\n // locations where there is no enclosing try statement.\n this.tryEntries = [{ tryLoc: \"root\" }];\n tryLocsList.forEach(pushTryEntry, this);\n this.reset(true);\n }\n\n runtime.keys = function(object) {\n var keys = [];\n for (var key in object) {\n keys.push(key);\n }\n keys.reverse();\n\n // Rather than returning an object with a next method, we keep\n // things simple and return the next function itself.\n return function next() {\n while (keys.length) {\n var key = keys.pop();\n if (key in object) {\n next.value = key;\n next.done = false;\n return next;\n }\n }\n\n // To avoid creating an additional object, we just hang the .value\n // and .done properties off the next function object itself. This\n // also ensures that the minifier will not anonymize the function.\n next.done = true;\n return next;\n };\n };\n\n function values(iterable) {\n if (iterable) {\n var iteratorMethod = iterable[iteratorSymbol];\n if (iteratorMethod) {\n return iteratorMethod.call(iterable);\n }\n\n if (typeof iterable.next === \"function\") {\n return iterable;\n }\n\n if (!isNaN(iterable.length)) {\n var i = -1, next = function next() {\n while (++i < iterable.length) {\n if (hasOwn.call(iterable, i)) {\n next.value = iterable[i];\n next.done = false;\n return next;\n }\n }\n\n next.value = undefined;\n next.done = true;\n\n return next;\n };\n\n return next.next = next;\n }\n }\n\n // Return an iterator with no values.\n return { next: doneResult };\n }\n runtime.values = values;\n\n function doneResult() {\n return { value: undefined, done: true };\n }\n\n Context.prototype = {\n constructor: Context,\n\n reset: function(skipTempReset) {\n this.prev = 0;\n this.next = 0;\n this.sent = undefined;\n this.done = false;\n this.delegate = null;\n\n this.tryEntries.forEach(resetTryEntry);\n\n if (!skipTempReset) {\n for (var name in this) {\n // Not sure about the optimal order of these conditions:\n if (name.charAt(0) === \"t\" &&\n hasOwn.call(this, name) &&\n !isNaN(+name.slice(1))) {\n this[name] = undefined;\n }\n }\n }\n },\n\n stop: function() {\n this.done = true;\n\n var rootEntry = this.tryEntries[0];\n var rootRecord = rootEntry.completion;\n if (rootRecord.type === \"throw\") {\n throw rootRecord.arg;\n }\n\n return this.rval;\n },\n\n dispatchException: function(exception) {\n if (this.done) {\n throw exception;\n }\n\n var context = this;\n function handle(loc, caught) {\n record.type = \"throw\";\n record.arg = exception;\n context.next = loc;\n return !!caught;\n }\n\n for (var i = this.tryEntries.length - 1; i >= 0; --i) {\n var entry = this.tryEntries[i];\n var record = entry.completion;\n\n if (entry.tryLoc === \"root\") {\n // Exception thrown outside of any try block that could handle\n // it, so set the completion value of the entire function to\n // throw the exception.\n return handle(\"end\");\n }\n\n if (entry.tryLoc <= this.prev) {\n var hasCatch = hasOwn.call(entry, \"catchLoc\");\n var hasFinally = hasOwn.call(entry, \"finallyLoc\");\n\n if (hasCatch && hasFinally) {\n if (this.prev < entry.catchLoc) {\n return handle(entry.catchLoc, true);\n } else if (this.prev < entry.finallyLoc) {\n return handle(entry.finallyLoc);\n }\n\n } else if (hasCatch) {\n if (this.prev < entry.catchLoc) {\n return handle(entry.catchLoc, true);\n }\n\n } else if (hasFinally) {\n if (this.prev < entry.finallyLoc) {\n return handle(entry.finallyLoc);\n }\n\n } else {\n throw new Error(\"try statement without catch or finally\");\n }\n }\n }\n },\n\n abrupt: function(type, arg) {\n for (var i = this.tryEntries.length - 1; i >= 0; --i) {\n var entry = this.tryEntries[i];\n if (entry.tryLoc <= this.prev &&\n hasOwn.call(entry, \"finallyLoc\") &&\n this.prev < entry.finallyLoc) {\n var finallyEntry = entry;\n break;\n }\n }\n\n if (finallyEntry &&\n (type === \"break\" ||\n type === \"continue\") &&\n finallyEntry.tryLoc <= arg &&\n arg <= finallyEntry.finallyLoc) {\n // Ignore the finally entry if control is not jumping to a\n // location outside the try/catch block.\n finallyEntry = null;\n }\n\n var record = finallyEntry ? finallyEntry.completion : {};\n record.type = type;\n record.arg = arg;\n\n if (finallyEntry) {\n this.next = finallyEntry.finallyLoc;\n } else {\n this.complete(record);\n }\n\n return ContinueSentinel;\n },\n\n complete: function(record, afterLoc) {\n if (record.type === \"throw\") {\n throw record.arg;\n }\n\n if (record.type === \"break\" ||\n record.type === \"continue\") {\n this.next = record.arg;\n } else if (record.type === \"return\") {\n this.rval = record.arg;\n this.next = \"end\";\n } else if (record.type === \"normal\" && afterLoc) {\n this.next = afterLoc;\n }\n },\n\n finish: function(finallyLoc) {\n for (var i = this.tryEntries.length - 1; i >= 0; --i) {\n var entry = this.tryEntries[i];\n if (entry.finallyLoc === finallyLoc) {\n this.complete(entry.completion, entry.afterLoc);\n resetTryEntry(entry);\n return ContinueSentinel;\n }\n }\n },\n\n \"catch\": function(tryLoc) {\n for (var i = this.tryEntries.length - 1; i >= 0; --i) {\n var entry = this.tryEntries[i];\n if (entry.tryLoc === tryLoc) {\n var record = entry.completion;\n if (record.type === \"throw\") {\n var thrown = record.arg;\n resetTryEntry(entry);\n }\n return thrown;\n }\n }\n\n // The context.catch method must only be called with a location\n // argument that corresponds to a known catch block.\n throw new Error(\"illegal catch attempt\");\n },\n\n delegateYield: function(iterable, resultName, nextLoc) {\n this.delegate = {\n iterator: values(iterable),\n resultName: resultName,\n nextLoc: nextLoc\n };\n\n return ContinueSentinel;\n }\n };\n})(\n // Among the various tricks for obtaining a reference to the global\n // object, this seems to be the most reliable technique that does not\n // use indirect eval (which violates Content Security Policy).\n typeof global === \"object\" ? global :\n typeof window === \"object\" ? window :\n typeof self === \"object\" ? self : this\n);\n\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./~/regenerator/runtime.js\n ** module id = 26\n ** module chunks = 0\n **/"],"sourceRoot":"/source/"}
\ No newline at end of file
diff --git a/build/ringcentral.js b/build/ringcentral.js
index a3c3f862..ddf191ba 100644
--- a/build/ringcentral.js
+++ b/build/ringcentral.js
@@ -89,31 +89,35 @@ var _coreObservable = __webpack_require__(8);
var _coreObservable2 = _interopRequireDefault(_coreObservable);
-var _httpClient = __webpack_require__(9);
+var _coreQueue = __webpack_require__(9);
+
+var _coreQueue2 = _interopRequireDefault(_coreQueue);
+
+var _httpClient = __webpack_require__(10);
var _httpClient2 = _interopRequireDefault(_httpClient);
-var _httpApiResponse = __webpack_require__(11);
+var _httpApiResponse = __webpack_require__(12);
var _httpApiResponse2 = _interopRequireDefault(_httpApiResponse);
-var _httpUtils = __webpack_require__(10);
+var _httpUtils = __webpack_require__(11);
var HttpUtils = _interopRequireWildcard(_httpUtils);
-var _mocksClientMock = __webpack_require__(12);
+var _mocksClientMock = __webpack_require__(13);
var _mocksClientMock2 = _interopRequireDefault(_mocksClientMock);
-var _mocksMock = __webpack_require__(14);
+var _mocksMock = __webpack_require__(15);
var _mocksMock2 = _interopRequireDefault(_mocksMock);
-var _mocksRegistry = __webpack_require__(13);
+var _mocksRegistry = __webpack_require__(14);
var _mocksRegistry2 = _interopRequireDefault(_mocksRegistry);
-var _platformPlatform = __webpack_require__(15);
+var _platformPlatform = __webpack_require__(16);
var _platformPlatform2 = _interopRequireDefault(_platformPlatform);
@@ -121,10 +125,6 @@ var _platformAuth = __webpack_require__(17);
var _platformAuth2 = _interopRequireDefault(_platformAuth);
-var _platformQueue = __webpack_require__(16);
-
-var _platformQueue2 = _interopRequireDefault(_platformQueue);
-
var _pubnubPubnubFactory = __webpack_require__(18);
var _pubnubPubnubFactory2 = _interopRequireDefault(_pubnubPubnubFactory);
@@ -133,7 +133,11 @@ var _subscriptionSubscription = __webpack_require__(20);
var _subscriptionSubscription2 = _interopRequireDefault(_subscriptionSubscription);
-__webpack_require__(21);
+var _subscriptionCachedSubscription = __webpack_require__(21);
+
+var _subscriptionCachedSubscription2 = _interopRequireDefault(_subscriptionCachedSubscription);
+
+__webpack_require__(22);
var SDK = (function () {
_createClass(SDK, null, [{
@@ -189,7 +193,15 @@ var SDK = (function () {
*/
SDK.prototype.createSubscription = function createSubscription() {
- return new _subscriptionSubscription2['default'](this._pubnubFactory, this._platform, this._cache);
+ return new _subscriptionSubscription2['default'](this._pubnubFactory, this._platform);
+ };
+
+ /**
+ * @return {CachedSubscription}
+ */
+
+ SDK.prototype.createCachedSubscription = function createCachedSubscription(cacheKey) {
+ return new _subscriptionCachedSubscription2['default'](this._pubnubFactory, this._platform, this._cache, cacheKey);
};
/**
@@ -206,7 +218,8 @@ var SDK = (function () {
Cache: _coreCache2['default'],
Observable: _coreObservable2['default'],
Utils: Utils,
- Externals: Externals
+ Externals: Externals,
+ Queue: _coreQueue2['default']
},
enumerable: true
}, {
@@ -221,8 +234,7 @@ var SDK = (function () {
key: 'platform',
value: {
Auth: _platformAuth2['default'],
- Platform: _platformPlatform2['default'],
- Queue: _platformQueue2['default']
+ Platform: _platformPlatform2['default']
},
enumerable: true
}, {
@@ -425,22 +437,24 @@ var _pubnub = __webpack_require__(6);
var _pubnub2 = _interopRequireDefault(_pubnub);
-var Promise = _es6Promise2['default'] && _es6Promise2['default'].Promise || window.Promise;
+var root = new Function('return this')();
+
+var Promise = _es6Promise2['default'] && _es6Promise2['default'].Promise || root.Promise;
exports.Promise = Promise;
-var fetch = _nodeFetch2['default'] || window.fetch;
+var fetch = root.fetch || _nodeFetch2['default'];
exports.fetch = fetch;
-var Request = fetch.Request || window.Request;
+var Request = root.Request || fetch.Request;
exports.Request = Request;
-var Response = fetch.Response || window.Response;
+var Response = root.Response || fetch.Response;
exports.Response = Response;
-var Headers = fetch.Headers || window.Headers;
+var Headers = root.Headers || fetch.Headers;
exports.Headers = Headers;
-var PUBNUB = _pubnub2['default'] || window.PUBNUB;
+var PUBNUB = root.PUBNUB || _pubnub2['default'];
exports.PUBNUB = PUBNUB;
-var localStorage = typeof window !== 'undefined' && typeof window.localStorage !== 'undefined' ? window.localStorage : {};
+var localStorage = typeof root.localStorage !== 'undefined' ? root.localStorage : {};
exports.localStorage = localStorage;
/***/ },
@@ -631,6 +645,86 @@ exports.__esModule = true;
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
+function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
+
+var _coreExternals = __webpack_require__(3);
+
+var _Utils = __webpack_require__(2);
+
+var Queue = (function () {
+ _createClass(Queue, null, [{
+ key: '_pollInterval',
+ value: 250,
+ enumerable: true
+ }, {
+ key: '_releaseTimeout',
+ value: 5000,
+ enumerable: true
+ }]);
+
+ function Queue(cache, cacheId) {
+ _classCallCheck(this, Queue);
+
+ this._cache = cache;
+ this._cacheId = cacheId;
+ this._promise = null;
+ }
+
+ Queue.prototype.isPaused = function isPaused() {
+
+ var time = this._cache.getItem(this._cacheId);
+
+ return !!time && Date.now() - parseInt(time) < Queue._releaseTimeout;
+ };
+
+ Queue.prototype.pause = function pause() {
+ this._cache.setItem(this._cacheId, Date.now());
+ return this;
+ };
+
+ Queue.prototype.resume = function resume() {
+ this._cache.removeItem(this._cacheId);
+ return this;
+ };
+
+ Queue.prototype.poll = function poll() {
+ var _this = this;
+
+ if (this._promise) return this._promise;
+
+ this._promise = new _coreExternals.Promise(function (resolve, reject) {
+
+ _Utils.poll(function (next) {
+
+ if (_this.isPaused()) return next();
+
+ _this._promise = null;
+
+ _this.resume(); // this is actually not needed but why not
+
+ resolve(null);
+ }, Queue._pollInterval);
+ });
+
+ return this._promise;
+ };
+
+ return Queue;
+})();
+
+exports['default'] = Queue;
+module.exports = exports['default'];
+
+/***/ },
+/* 10 */
+/***/ function(module, exports, __webpack_require__) {
+
+'use strict';
+
+exports.__esModule = true;
+
+var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
@@ -641,13 +735,13 @@ var _coreExternals = __webpack_require__(3);
var _coreUtils = __webpack_require__(2);
-var _Utils = __webpack_require__(10);
+var _Utils = __webpack_require__(11);
var _coreObservable = __webpack_require__(8);
var _coreObservable2 = _interopRequireDefault(_coreObservable);
-var _ApiResponse = __webpack_require__(11);
+var _ApiResponse = __webpack_require__(12);
var _ApiResponse2 = _interopRequireDefault(_ApiResponse);
@@ -857,7 +951,7 @@ exports['default'] = Client;
module.exports = exports['default'];
/***/ },
-/* 10 */
+/* 11 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
@@ -909,7 +1003,7 @@ function findHeaderName(name, headers) {
}
/***/ },
-/* 11 */
+/* 12 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
@@ -924,7 +1018,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
var _coreExternals = __webpack_require__(3);
-var _Utils = __webpack_require__(10);
+var _Utils = __webpack_require__(11);
var utils = _interopRequireWildcard(_Utils);
@@ -1154,7 +1248,7 @@ exports['default'] = ApiResponse;
module.exports = exports['default'];
/***/ },
-/* 12 */
+/* 13 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
@@ -1167,11 +1261,11 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
-var _Registry = __webpack_require__(13);
+var _Registry = __webpack_require__(14);
var _Registry2 = _interopRequireDefault(_Registry);
-var _httpClient = __webpack_require__(9);
+var _httpClient = __webpack_require__(10);
var _httpClient2 = _interopRequireDefault(_httpClient);
@@ -1215,7 +1309,7 @@ exports['default'] = Client;
module.exports = exports['default'];
/***/ },
-/* 13 */
+/* 14 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
@@ -1226,7 +1320,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'd
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
-var _Mock = __webpack_require__(14);
+var _Mock = __webpack_require__(15);
var _Mock2 = _interopRequireDefault(_Mock);
@@ -1393,7 +1487,7 @@ exports['default'] = Registry;
module.exports = exports['default'];
/***/ },
-/* 14 */
+/* 15 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
@@ -1404,13 +1498,13 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'd
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
-var _httpApiResponse = __webpack_require__(11);
+var _httpApiResponse = __webpack_require__(12);
var _httpApiResponse2 = _interopRequireDefault(_httpApiResponse);
var _coreUtils = __webpack_require__(2);
-var _httpUtils = __webpack_require__(10);
+var _httpUtils = __webpack_require__(11);
var Mock = (function () {
function Mock(method, path, json, status, statusText, delay) {
@@ -1476,7 +1570,7 @@ exports['default'] = Mock;
module.exports = exports['default'];
/***/ },
-/* 15 */
+/* 16 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
@@ -1495,9 +1589,9 @@ var _coreObservable = __webpack_require__(8);
var _coreObservable2 = _interopRequireDefault(_coreObservable);
-var _Queue = __webpack_require__(16);
+var _coreQueue = __webpack_require__(9);
-var _Queue2 = _interopRequireDefault(_Queue);
+var _coreQueue2 = _interopRequireDefault(_coreQueue);
var _Auth = __webpack_require__(17);
@@ -1585,7 +1679,7 @@ var Platform = (function (_Observable) {
/** @type {Client} */
this._client = client;
- this._queue = new _Queue2['default'](this._cache, Platform._cacheId + '-refresh');
+ this._queue = new _coreQueue2['default'](this._cache, Platform._cacheId + '-refresh');
this._auth = new _Auth2['default'](this._cache, Platform._cacheId);
}
@@ -2039,8 +2133,8 @@ var Platform = (function (_Observable) {
/**
* General purpose function to send anything to server
+ * @param {string} options.url
* @param {object} [options.body]
- * @param {string} [options.url]
* @param {string} [options.method]
* @param {object} [options.query]
* @param {object} [options.headers]
@@ -2072,7 +2166,7 @@ var Platform = (function (_Observable) {
/**
* @param {string} url
- * @param {object} query
+ * @param {object} [query]
* @param {object} [options]
* @param {object} [options.headers]
* @param {boolean} [options.skipAuthCheck]
@@ -2103,7 +2197,7 @@ var Platform = (function (_Observable) {
/**
* @param {string} url
* @param {object} body
- * @param {object} query
+ * @param {object} [query]
* @param {object} [options]
* @param {object} [options.headers]
* @param {boolean} [options.skipAuthCheck]
@@ -2134,8 +2228,8 @@ var Platform = (function (_Observable) {
/**
* @param {string} url
- * @param {object} body
- * @param {object} query
+ * @param {object} [body]
+ * @param {object} [query]
* @param {object} [options]
* @param {object} [options.headers]
* @param {boolean} [options.skipAuthCheck]
@@ -2166,7 +2260,7 @@ var Platform = (function (_Observable) {
/**
* @param {string} url
- * @param {string} query
+ * @param {string} [query]
* @param {object} [options]
* @param {object} [options.headers]
* @param {boolean} [options.skipAuthCheck]
@@ -2272,88 +2366,6 @@ module.exports = exports['default'];
// Guard is for errors that come from polling
-/***/ },
-/* 16 */
-/***/ function(module, exports, __webpack_require__) {
-
-'use strict';
-
-exports.__esModule = true;
-
-var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
-
-function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
-
-var _coreExternals = __webpack_require__(3);
-
-var _coreUtils = __webpack_require__(2);
-
-var Queue = (function () {
- _createClass(Queue, null, [{
- key: '_pollInterval',
- value: 250,
- enumerable: true
- }, {
- key: '_releaseTimeout',
- value: 5000,
- enumerable: true
- }]);
-
- function Queue(cache, cacheId) {
- _classCallCheck(this, Queue);
-
- this._cache = cache;
- this._cacheId = cacheId;
- this._promise = null;
- }
-
- Queue.prototype.isPaused = function isPaused() {
-
- var storage = this._cache,
- cacheId = this._cacheId,
- time = storage.getItem(cacheId);
-
- return !!time && Date.now() - parseInt(time) < Queue._releaseTimeout;
- };
-
- Queue.prototype.pause = function pause() {
- this._cache.setItem(this._cacheId, Date.now());
- return this;
- };
-
- Queue.prototype.resume = function resume() {
- this._cache.removeItem(this._cacheId);
- return this;
- };
-
- Queue.prototype.poll = function poll() {
- var _this = this;
-
- if (this._promise) return this._promise;
-
- this._promise = new _coreExternals.Promise(function (resolve, reject) {
-
- _coreUtils.poll(function (next) {
-
- if (_this.isPaused()) return next();
-
- _this._promise = null;
-
- _this.resume(); // this is actually not needed but why not
-
- resolve(null);
- }, Queue._pollInterval);
- });
-
- return this._promise;
- };
-
- return Queue;
-})();
-
-exports['default'] = Queue;
-module.exports = exports['default'];
-
/***/ },
/* 17 */
/***/ function(module, exports) {
@@ -2630,7 +2642,7 @@ var _coreObservable = __webpack_require__(8);
var _coreObservable2 = _interopRequireDefault(_coreObservable);
-var _httpClient = __webpack_require__(9);
+var _httpClient = __webpack_require__(10);
var _httpClient2 = _interopRequireDefault(_httpClient);
@@ -2649,7 +2661,7 @@ var Subscription = (function (_Observable) {
enumerable: true
}]);
- function Subscription(pubnubFactory, platform, cache) {
+ function Subscription(pubnubFactory, platform) {
_classCallCheck(this, Subscription);
_Observable.call(this);
@@ -2665,7 +2677,6 @@ var Subscription = (function (_Observable) {
};
this._pubnubFactory = pubnubFactory;
this._platform = platform;
- this._cache = cache;
this._pubnub = null;
this._timeout = null;
this._subscription = {};
@@ -2689,13 +2700,18 @@ var Subscription = (function (_Observable) {
// status?:string; // Active
//}
+ Subscription.prototype.subscribed = function subscribed() {
+
+ return !!(this._subscription.id && this._subscription.deliveryMode && this._subscription.deliveryMode.subscriberKey && this._subscription.deliveryMode.address);
+ };
+
/**
* @return {boolean}
*/
Subscription.prototype.alive = function alive() {
- return !!(this._subscription.id && this._subscription.deliveryMode && this._subscription.deliveryMode.subscriberKey && this._subscription.deliveryMode.address && Date.now() < this.expirationTime());
+ return this.subscribed() && Date.now() < this.expirationTime();
};
Subscription.prototype.expirationTime = function expirationTime() {
@@ -2723,11 +2739,10 @@ var Subscription = (function (_Observable) {
/**
* Creates or updates subscription if there is an active one
- * @param {{events?:string[]}} [options] New array of events
* @returns {Promise}
*/
- Subscription.prototype.register = function register(options) {
+ Subscription.prototype.register = function register() {
return regeneratorRuntime.async(function register$(context$2$0) {
while (1) switch (context$2$0.prev = context$2$0.next) {
case 0:
@@ -2737,14 +2752,14 @@ var Subscription = (function (_Observable) {
}
context$2$0.next = 3;
- return regeneratorRuntime.awrap(this.renew(options));
+ return regeneratorRuntime.awrap(this.renew());
case 3:
return context$2$0.abrupt('return', context$2$0.sent);
case 6:
context$2$0.next = 8;
- return regeneratorRuntime.awrap(this.subscribe(options));
+ return regeneratorRuntime.awrap(this.subscribe());
case 8:
return context$2$0.abrupt('return', context$2$0.sent);
@@ -2781,32 +2796,27 @@ var Subscription = (function (_Observable) {
};
/**
- * @param {{events?:string[]}} [options] New array of events
* @returns {Promise