From c53461ed430aa31ac1ce3b47c48a609070843e85 Mon Sep 17 00:00:00 2001 From: Kirill Konshin Date: Wed, 29 Apr 2020 10:46:04 -0700 Subject: [PATCH] Additional logging & pubnub origin (#134) * Additional logging & pubnub origin --- .gitignore | 1 + .travis.yml | 1 + build/ringcentral.js | 11 +- build/ringcentral.js.map | 2 +- build/ringcentral.min.js | 2 +- build/ringcentral.min.js.map | 2 +- demo/apiKey.html | 2 +- demo/backbone.html | 2 +- demo/core.html | 5 +- demo/fax.html | 2 +- demo/login.html | 2 +- demo/mms.html | 2 +- demo/refresh.html | 2 +- package-lock.json | 7352 ++++++++++++++++++++++++++++++ package.json | 4 +- src/subscription/Subscription.js | 11 +- 16 files changed, 7385 insertions(+), 18 deletions(-) create mode 100644 package-lock.json diff --git a/.gitignore b/.gitignore index 92f749a6..ce1a0f52 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.env .svn .DS_Store .idea diff --git a/.travis.yml b/.travis.yml index 6a988efd..4fcd1722 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,7 @@ language: node_js node_js: - 6 - stable +dist: trusty cache: directories: - $HOME/.npm diff --git a/build/ringcentral.js b/build/ringcentral.js index 527f87f6..998ec3ab 100644 --- a/build/ringcentral.js +++ b/build/ringcentral.js @@ -2346,7 +2346,8 @@ function Subscription(options) { subscribeSuccess: 'subscribeSuccess', subscribeError: 'subscribeError', automaticRenewSuccess: 'automaticRenewSuccess', - automaticRenewError: 'automaticRenewError' + automaticRenewError: 'automaticRenewError', + status: 'status' }; /** @private */ @@ -2749,11 +2750,15 @@ Subscription.prototype._subscribeAtPubnub = function() { this._pubnub = new PubNub({ ssl: true, restore: true, - subscribeKey: deliveryMode.subscriberKey + subscribeKey: deliveryMode.subscriberKey, + origin: 'ringcentral.pubnubapi.com', + keepAlive: true }); this._pubnub.addListener({ - status: function(statusEvent) {}, + status: function(statusEvent) { + this.emit(this.events.status, statusEvent); + }.bind(this), message: function(m) { this._notify(m.message); // all other props are ignored }.bind(this) diff --git a/build/ringcentral.js.map b/build/ringcentral.js.map index f22e47e9..3d68231b 100644 --- a/build/ringcentral.js.map +++ b/build/ringcentral.js.map @@ -1 +1 @@ -{"version":3,"sources":["webpack:///webpack/universalModuleDefinition","webpack:///webpack/bootstrap 3e92ff87335340dc908b","webpack:///./src/SDK.js","webpack:///./~/object-assign/index.js","webpack:///./src/core/Cache.js","webpack:///./src/http/Client.js","webpack:///./~/is-plain-object/index.js","webpack:///./~/isobject/index.js","webpack:///./~/events/events.js","webpack:///./src/http/ApiResponse.js","webpack:///./~/querystring/index.js","webpack:///./~/querystring/decode.js","webpack:///./~/querystring/encode.js","webpack:///./src/core/Externals.js","webpack:///external {\"amd\":\"pubnub\"}","webpack:///external {\"amd\":\"es6-promise\"}","webpack:///external {\"amd\":\"fetch-ponyfill\"}","webpack:///./src/platform/Platform.js","webpack:///./src/platform/Auth.js","webpack:///./src/core/Constants.js","webpack:///./src/subscription/Subscription.js","webpack:///./src/subscription/CachedSubscription.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,iDAAiD;AACjD,CAAC;AACD,O;ACVA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA,uBAAe;AACf;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;;;;;;ACtCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,WAAW,OAAO;AAClB,WAAW,OAAO;AAClB,WAAW,OAAO;AAClB,WAAW,OAAO;AAClB,WAAW,OAAO;AAClB,WAAW,OAAO;AAClB,WAAW,OAAO;AAClB,WAAW,OAAO;AAClB,WAAW,sBAAsB;AACjC,WAAW,QAAQ;AACnB,WAAW,MAAM;AACjB,WAAW,sBAAsB;AACjC,WAAW,uBAAuB;AAClC,WAAW,sBAAsB;AACjC,WAAW,IAAI;AACf,WAAW,IAAI;AACf,WAAW,QAAQ;AACnB,cAAc,UAAU;AACxB,cAAc,MAAM;AACpB,cAAc,OAAO;AACrB,cAAc,SAAS;AACvB;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA,KAAK;;AAEL;AACA;;AAEA;AACA,iDAAiD;AACjD;AACA;AACA;AACA,KAAK;;AAEL;;AAEA;;AAEA;AACA;AACA;AACA;;AAEA;AACA,YAAY;AACZ;AACA;AACA;AACA;;AAEA;AACA,YAAY;AACZ;AACA;AACA;AACA;;AAEA;AACA,WAAW,IAAI;AACf,WAAW,IAAI;AACf,YAAY;AACZ;AACA;AACA,2CAA2C;AAC3C;AACA;AACA,KAAK;AACL;;AAEA;AACA,WAAW,OAAO;AAClB,WAAW,IAAI;AACf,WAAW,IAAI;AACf,YAAY;AACZ;AACA;;AAEA;AACA,mBAAmB;AACnB,KAAK;AACL;AACA;;AAEA,iDAAiD;AACjD;AACA;AACA;AACA,KAAK;;AAEL;;AAEA;;AAEA;;AAEA;AACA;AACA;AACA;;AAEA;;AAEA,qB;;;;;;AC7HA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA,gCAAgC;AAChC;AACA;AACA;AACA;;AAEA;AACA;AACA,iBAAiB,QAAQ;AACzB;AACA;AACA;AACA;AACA,GAAG;AACH;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,GAAG;AACH,kCAAkC;AAClC;AACA;AACA;;AAEA;AACA,EAAE;AACF;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA,gBAAgB,sBAAsB;AACtC;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,kBAAkB,oBAAoB;AACtC;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;;;;;;ACzFA;AACA,WAAW,UAAU;AACrB,WAAW,OAAO;AAClB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;AACA;;AAEA;AACA;;AAEA;;AAEA;;AAEA;AACA,aAAa,OAAO;AACpB,cAAc,OAAO;AACrB,cAAc,OAAO;AACrB,cAAc,YAAY;AAC1B;;AAEA,wB;;;;;;AC/LA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;;;;;;;ACpCA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;;;;;;;ACXA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,iBAAiB;AACjB,OAAO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;AACH;AACA;AACA;AACA,eAAe,SAAS;AACxB;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;;AAEA;AACA;AACA;;AAEA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA,GAAG;AACH,oBAAoB,SAAS;AAC7B;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA,KAAK;AACL;AACA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA,GAAG;AACH;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;;;;;;AC7SA;AACA,WAAW,UAAU;AACrB,WAAW,QAAQ;AACnB,WAAW,SAAS;AACpB,WAAW,OAAO;AAClB,cAAc,UAAU;AACxB,cAAc,QAAQ;AACtB,cAAc,SAAS;AACvB,cAAc,OAAO;AACrB,cAAc,OAAO;AACrB,cAAc,cAAc;AAC5B;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,WAAW,SAAS;AACpB,YAAY;AACZ;AACA;;AAEA;;AAEA;;AAEA;AACA;;AAEA;;AAEA,KAAK;;AAEL;AACA;;AAEA,KAAK;;AAEL;;AAEA;AACA,YAAY;AACZ;AACA;AACA;AACA;;AAEA;AACA,YAAY;AACZ;AACA;AACA;AACA;;AAEA;AACA,YAAY;AACZ;AACA;AACA;AACA;;AAEA;AACA,YAAY;AACZ;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,YAAY;AACZ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,YAAY;AACZ;AACA;;AAEA;;AAEA;AACA;;AAEA;;AAEA;AACA;AACA;;AAEA,KAAK;;AAEL;;AAEA;;AAEA;AACA;AACA,YAAY;AACZ;AACA;AACA;AACA;AACA;;AAEA;AACA,YAAY;AACZ;AACA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;AACA,kEAAkE;AAClE,SAAS;AACT;AACA;;AAEA;;AAEA;;AAEA;AACA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA,SAAS;;AAET;;AAEA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,WAAW,OAAO;AAClB,WAAW,OAAO;AAClB,WAAW,OAAO;AAClB;AACA,YAAY;AACZ;AACA;;AAEA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;;AAEA,SAAS;;AAET;AACA;AACA;AACA;AACA,KAAK;;AAEL;AACA;AACA;AACA;AACA;AACA,KAAK;;AAEL;;AAEA,6B;;;;;;AC9QA;;AAEA;AACA;;;;;;;ACHA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA,iBAAiB,SAAS;AAC1B;AACA;AACA;;AAEA;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA,KAAK;AACL;AACA,KAAK;AACL;AACA;AACA;;AAEA;AACA;;;;;;;AC/EA;AACA;AACA;AACA;AACA;AACA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;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;;AAGA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,KAAK;;AAEL;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA,SAAS;AACT,KAAK;AACL;;AAEA;AACA,YAAY;AACZ;AACA;AACA;AACA;;AAEA;AACA,YAAY;AACZ;AACA;AACA;AACA;;AAEA;AACA,WAAW,OAAO;AAClB,WAAW,OAAO;AAClB,WAAW,QAAQ;AACnB,WAAW,OAAO;AAClB,WAAW,QAAQ;AACnB,YAAY;AACZ;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA,SAAS;;AAET;;AAEA;AACA;AACA;;AAEA;;AAEA;;AAEA;AACA;;AAEA;;AAEA;;AAEA;AACA,WAAW,OAAO;AAClB,WAAW,OAAO;AAClB,WAAW,OAAO;AAClB,WAAW,OAAO;AAClB,WAAW,OAAO;AAClB,WAAW,QAAQ;AACnB,YAAY;AACZ;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,IAAI,gBAAgB;;AAE7B;;AAEA;AACA,WAAW,OAAO;AAClB,YAAY;AACZ;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,WAAW,OAAO;AAClB,WAAW,OAAO;AAClB,WAAW,OAAO;AAClB,WAAW,OAAO;AAClB,WAAW,OAAO;AAClB,WAAW,OAAO;AAClB,WAAW,OAAO;AAClB,YAAY;AACZ;AACA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;AACA;AACA,uCAAuC;AACvC;AACA;AACA;;;;;;;ACrHA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,E;;;;;;ACVA;;AAEA;AACA,2BAA2B,EAAE,SAAS,EAAE;;AAExC;AACA;AACA;;AAEA;AACA;AACA,WAAW,OAAO;AAClB,YAAY;AACZ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,WAAW,SAAS;AACpB,WAAW,UAAU;AACrB,WAAW,IAAI;AACf,WAAW,IAAI;AACf,cAAc,UAAU;AACxB,cAAc,SAAS;AACvB,cAAc,IAAI;AAClB,cAAc,IAAI;AAClB,cAAc,OAAO;AACrB,cAAc,OAAO;AACrB,cAAc,IAAI;AAClB,cAAc,cAAc;AAC5B;AACA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;AACA;AACA;AACA;;AAEA;;AAEA;AACA,YAAY;AACZ;AACA;AACA;AACA;;AAEA;AACA,YAAY;AACZ;AACA;AACA;AACA;AACA;;AAEA;AACA,YAAY;AACZ;AACA;AACA;AACA;;AAEA;AACA,WAAW,cAAc;AACzB,YAAY;AACZ;AACA;;AAEA;;AAEA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;AACA,YAAY;AACZ;AACA;AACA;AACA;;AAEA;AACA;AACA,aAAa;AACb;AACA;;AAEA;AACA;AACA,KAAK;AACL;AACA;;AAEA;;AAEA;AACA,YAAY;AACZ;AACA;AACA;AACA;;AAEA;AACA,WAAW,SAAS;AACpB,YAAY;AACZ;AACA;AACA;AACA;AACA;;AAEA;AACA,WAAW,SAAS;AACpB,YAAY;AACZ;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,aAAa;AACb;A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;AAEA;AACA;AACA;AACA;AACA,SAAS;;AAET;AACA,4CAA4C;AAC5C;AACA,wCAAwC;AACxC,aAAa;AACb,SAAS;;AAET;;AAEA;AACA,4BAA4B,iCAAiC;;AAE7D;;AAEA;;AAEA;AACA,YAAY;AACZ;AACA;AACA;;AAEA;;AAEA;AACA,2BAA2B;;AAE3B;AACA;AACA;;AAEA;;AAEA;;AAEA;;AAEA;AACA;AACA,aAAa,OAAO;AACpB,cAAc,OAAO;AACrB,cAAc,OAAO;AACrB,cAAc,SAAS;AACvB,cAAc,OAAO;AACrB,cAAc,IAAI;AAClB,cAAc,OAAO;AACrB,cAAc,QAAQ;AACtB,cAAc,OAAO;AACrB,cAAc,OAAO;AACrB,cAAc,OAAO;AACrB,cAAc,OAAO;AACrB,cAAc,OAAO;AACrB,cAAc,OAAO;AACrB,G;;;;;;AC/fA;;AAEA;AACA,WAAW,SAAS;AACpB,WAAW,UAAU;AACrB,WAAW,MAAM;AACjB,WAAW,OAAO;AAClB,WAAW,IAAI;AACf,WAAW,IAAI;AACf,YAAY;AACZ;AACA,cAAc,MAAM;AACpB;AACA;AACA;;AAEA;;AAEA;;AAEA;AACA;;AAEA;;AAEA;AACA;;AAEA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA,WAAW,SAAS;AACpB,YAAY;AACZ;AACA;;AAEA;AACA;AACA;;AAEA;;AAEA;;AAEA,oC","file":"ringcentral.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory(require(undefined), require(undefined), require(undefined));\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([\"pubnub\", \"es6-promise\", \"fetch-ponyfill\"], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"SDK\"] = factory(require(undefined), require(undefined), require(undefined));\n\telse\n\t\troot[\"RingCentral\"] = root[\"RingCentral\"] || {}, root[\"RingCentral\"][\"SDK\"] = factory(root[undefined], root[undefined], root[undefined]);\n})(this, function(__WEBPACK_EXTERNAL_MODULE_12__, __WEBPACK_EXTERNAL_MODULE_13__, __WEBPACK_EXTERNAL_MODULE_14__) {\nreturn \n\n\n// WEBPACK FOOTER //\n// webpack/universalModuleDefinition"," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\texports: {},\n \t\t\tid: moduleId,\n \t\t\tloaded: false\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.loaded = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"/build/\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(0);\n\n\n\n// WEBPACK FOOTER //\n// webpack/bootstrap 3e92ff87335340dc908b","/**\n * @namespace RingCentral\n */\nvar objectAssign = require('object-assign');\nvar Cache = require(\"./core/Cache\");\nvar Client = require(\"./http/Client\");\nvar Externals = require(\"./core/Externals\");\nvar Platform = require(\"./platform/Platform\");\nvar Subscription = require(\"./subscription/Subscription\");\nvar CachedSubscription = require(\"./subscription/CachedSubscription\");\nvar Constants = require(\"./core/Constants\");\n\n/**\n * @constructor\n * @param {string} options.server\n * @param {string} options.appSecret\n * @param {string} options.appKey\n * @param {string} [options.cachePrefix]\n * @param {string} [options.appName]\n * @param {string} [options.appVersion]\n * @param {string} [options.redirectUri]\n * @param {PubNub} [options.PubNub]\n * @param {function(new:Promise)} [options.Promise]\n * @param {Storage} [options.localStorage]\n * @param {fetch} [options.fetch]\n * @param {function(new:Request)} [options.Request]\n * @param {function(new:Response)} [options.Response]\n * @param {function(new:Headers)} [options.Headers]\n * @param {int} [options.refreshDelayMs]\n * @param {int} [options.refreshHandicapMs]\n * @param {boolean} [options.clearCacheOnRefreshError]\n * @property {Externals} _externals\n * @property {Cache} _cache\n * @property {Client} _client\n * @property {Platform} _platform\n */\nfunction SDK(options) {\n\n /** @private */\n this._externals = new Externals(options);\n\n /** @private */\n this._cache = new Cache({\n externals: this._externals,\n prefix: options.cachePrefix\n });\n\n /** @private */\n this._client = new Client(this._externals);\n\n /** @private */\n this._platform = new Platform(objectAssign({}, options, {\n externals: this._externals,\n client: this._client,\n cache: this._cache\n }));\n\n}\n\nSDK.version = Constants.version;\n\nSDK.server = {\n sandbox: 'https://platform.devtest.ringcentral.com',\n production: 'https://platform.ringcentral.com'\n};\n\n/**\n * @return {Platform}\n */\nSDK.prototype.platform = function() {\n return this._platform;\n};\n\n/**\n * @return {Cache}\n */\nSDK.prototype.cache = function() {\n return this._cache;\n};\n\n/**\n * @param {int} [options.pollInterval]\n * @param {int} [options.renewHandicapMs]\n * @return {Subscription}\n */\nSDK.prototype.createSubscription = function(options) {\n return new Subscription(objectAssign({}, options, {\n externals: this._externals,\n platform: this._platform\n }));\n};\n\n/**\n * @param {string} options.cacheKey\n * @param {int} [options.pollInterval]\n * @param {int} [options.renewHandicapMs]\n * @return {CachedSubscription}\n */\nSDK.prototype.createCachedSubscription = function(options) {\n\n if (typeof arguments[0] === 'string') {\n options = {cacheKey: arguments[0].toString()};\n } else {\n options = options || {};\n }\n\n return new CachedSubscription(objectAssign({}, options, {\n externals: this._externals,\n platform: this._platform,\n cache: this._cache\n }));\n\n};\n\nSDK.handleLoginRedirect = function(origin, win) {\n\n win = win || window;\n\n var response = win.location.hash ? win.location.hash : win.location.search;\n var msg = {};\n msg[Constants.authResponseProperty] = response;\n win.opener.postMessage(msg, origin || win.location.origin);\n\n};\n\nmodule.exports = SDK;\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/SDK.js\n// module id = 0\n// module chunks = 0 1","/*\nobject-assign\n(c) Sindre Sorhus\n@license MIT\n*/\n\n'use strict';\n/* eslint-disable no-unused-vars */\nvar getOwnPropertySymbols = Object.getOwnPropertySymbols;\nvar hasOwnProperty = Object.prototype.hasOwnProperty;\nvar propIsEnumerable = Object.prototype.propertyIsEnumerable;\n\nfunction toObject(val) {\n\tif (val === null || val === undefined) {\n\t\tthrow new TypeError('Object.assign cannot be called with null or undefined');\n\t}\n\n\treturn Object(val);\n}\n\nfunction shouldUseNative() {\n\ttry {\n\t\tif (!Object.assign) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Detect buggy property enumeration order in older V8 versions.\n\n\t\t// https://bugs.chromium.org/p/v8/issues/detail?id=4118\n\t\tvar test1 = new String('abc'); // eslint-disable-line no-new-wrappers\n\t\ttest1[5] = 'de';\n\t\tif (Object.getOwnPropertyNames(test1)[0] === '5') {\n\t\t\treturn false;\n\t\t}\n\n\t\t// https://bugs.chromium.org/p/v8/issues/detail?id=3056\n\t\tvar test2 = {};\n\t\tfor (var i = 0; i < 10; i++) {\n\t\t\ttest2['_' + String.fromCharCode(i)] = i;\n\t\t}\n\t\tvar order2 = Object.getOwnPropertyNames(test2).map(function (n) {\n\t\t\treturn test2[n];\n\t\t});\n\t\tif (order2.join('') !== '0123456789') {\n\t\t\treturn false;\n\t\t}\n\n\t\t// https://bugs.chromium.org/p/v8/issues/detail?id=3056\n\t\tvar test3 = {};\n\t\t'abcdefghijklmnopqrst'.split('').forEach(function (letter) {\n\t\t\ttest3[letter] = letter;\n\t\t});\n\t\tif (Object.keys(Object.assign({}, test3)).join('') !==\n\t\t\t\t'abcdefghijklmnopqrst') {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn true;\n\t} catch (err) {\n\t\t// We don't expect any of the above to throw, but better to be safe.\n\t\treturn false;\n\t}\n}\n\nmodule.exports = shouldUseNative() ? Object.assign : function (target, source) {\n\tvar from;\n\tvar to = toObject(target);\n\tvar symbols;\n\n\tfor (var s = 1; s < arguments.length; s++) {\n\t\tfrom = Object(arguments[s]);\n\n\t\tfor (var key in from) {\n\t\t\tif (hasOwnProperty.call(from, key)) {\n\t\t\t\tto[key] = from[key];\n\t\t\t}\n\t\t}\n\n\t\tif (getOwnPropertySymbols) {\n\t\t\tsymbols = getOwnPropertySymbols(from);\n\t\t\tfor (var i = 0; i < symbols.length; i++) {\n\t\t\t\tif (propIsEnumerable.call(from, symbols[i])) {\n\t\t\t\t\tto[symbols[i]] = from[symbols[i]];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn to;\n};\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./~/object-assign/index.js\n// module id = 1\n// module chunks = 0 1","/**\n * @param {Externals} options.externals\n * @param {string} [options.prefix]\n * @property {Externals} _externals\n */\nfunction Cache(options) {\n\n /** @private */\n this._prefix = options.prefix || Cache.defaultPrefix;\n\n /** @private */\n this._externals = options.externals;\n\n}\n\nCache.defaultPrefix = 'rc-';\n\nCache.prototype.setItem = function(key, data) {\n this._externals.localStorage[this._prefixKey(key)] = JSON.stringify(data);\n return this;\n};\n\nCache.prototype.removeItem = function(key) {\n delete this._externals.localStorage[this._prefixKey(key)];\n return this;\n};\n\nCache.prototype.getItem = function(key) {\n var item = this._externals.localStorage[this._prefixKey(key)];\n if (!item) return null;\n return JSON.parse(item);\n};\n\nCache.prototype.clean = function() {\n\n for (var key in this._externals.localStorage) {\n\n /* istanbul ignore next */\n if (!this._externals.localStorage.hasOwnProperty(key)) continue;\n\n if (key.indexOf(this._prefix) === 0) {\n delete this._externals.localStorage[key];\n }\n\n }\n\n return this;\n\n};\n\nCache.prototype._prefixKey = function(key) {\n return this._prefix + key;\n};\n\nmodule.exports = Cache;\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/core/Cache.js\n// module id = 2\n// module chunks = 0 1","var isPlainObject = require(\"is-plain-object\");\nvar EventEmitter = require(\"events\").EventEmitter;\nvar ApiResponse = require(\"./ApiResponse\");\nvar qs = require(\"querystring\");\n\nfunction 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 * @param {Externals} externals\n * @property {Externals} _externals\n */\nfunction Client(externals) {\n\n EventEmitter.call(this);\n\n /** @private */\n this._externals = externals;\n\n this.events = {\n beforeRequest: 'beforeRequest',\n requestSuccess: 'requestSuccess',\n requestError: 'requestError'\n };\n\n}\n\nClient._allowedMethods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS', 'HEAD'];\n\nClient.prototype = Object.create(EventEmitter.prototype);\n\n/**\n * @param {Request} request\n * @return {Promise}\n */\nClient.prototype.sendRequest = function(request) {\n\n var apiResponse = new ApiResponse({\n externals: this._externals,\n request: request\n });\n\n return (new this._externals.Promise(function(resolve) {\n\n //TODO Stop request if listeners return false\n this.emit(this.events.beforeRequest, apiResponse);\n\n resolve(this._loadResponse(request));\n\n }.bind(this))).then(function(response) {\n\n return apiResponse.receiveResponse(response);\n\n }).then(function() {\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 }.bind(this)).catch(function(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 }.bind(this));\n\n};\n\n/**\n * @param {Request} request\n * @return {Promise}\n * @private\n */\nClient.prototype._loadResponse = function(request) {\n return this._externals.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 */\nClient.prototype.makeError = function(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 * @param {object} [init.credentials]\n * @param {object} [init.mode]\n * @return {Request}\n */\nClient.prototype.createRequest = function(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 init.method = init.method.toUpperCase();\n if (init.method && Client._allowedMethods.indexOf(init.method) < 0) {\n throw new Error('Method has wrong value: ' + init.method);\n }\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 ? '&' : '?') + qs.stringify(init.query);\n }\n\n if (!(findHeaderName('Accept', init.headers))) {\n init.headers.Accept = ApiResponse._jsonContentType;\n }\n\n // Serialize body\n if (isPlainObject(init.body) || !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 if ((init.method === 'GET' || init.method === 'HEAD') && !!init.body) {\n // oddly setting body to null still result in TypeError in phantomjs\n init.body = undefined;\n } else {\n init.body = JSON.stringify(init.body);\n }\n\n } else if (contentType.indexOf(ApiResponse._urlencodedContentType) > -1) {\n init.body = qs.stringify(init.body);\n }\n\n }\n\n // Create a request with encoded body\n var req = new this._externals.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 * @typedef {object} IApiError\n * @property {string} stack\n * @property {string} originalMessage\n * @property {ApiResponse} apiResponse\n */\n\nmodule.exports = Client;\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/http/Client.js\n// module id = 3\n// module chunks = 0 1","/*!\n * is-plain-object \n *\n * Copyright (c) 2014-2017, Jon Schlinkert.\n * Released under the MIT License.\n */\n\n'use strict';\n\nvar isObject = require('isobject');\n\nfunction isObjectObject(o) {\n return isObject(o) === true\n && Object.prototype.toString.call(o) === '[object Object]';\n}\n\nmodule.exports = function isPlainObject(o) {\n var ctor,prot;\n\n if (isObjectObject(o) === false) return false;\n\n // If has modified constructor\n ctor = o.constructor;\n if (typeof ctor !== 'function') return false;\n\n // If has modified prototype\n prot = ctor.prototype;\n if (isObjectObject(prot) === false) return false;\n\n // If constructor does not have an Object-specific method\n if (prot.hasOwnProperty('isPrototypeOf') === false) {\n return false;\n }\n\n // Most likely a plain Object\n return true;\n};\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./~/is-plain-object/index.js\n// module id = 4\n// module chunks = 0 1","/*!\n * isobject \n *\n * Copyright (c) 2014-2017, Jon Schlinkert.\n * Released under the MIT License.\n */\n\n'use strict';\n\nmodule.exports = function isObject(val) {\n return val != null && typeof val === 'object' && Array.isArray(val) === false;\n};\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./~/isobject/index.js\n// module id = 5\n// module chunks = 0 1","// Copyright Joyent, Inc. and other Node contributors.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a\n// copy of this software and associated documentation files (the\n// \"Software\"), to deal in the Software without restriction, including\n// without limitation the rights to use, copy, modify, merge, publish,\n// distribute, sublicense, and/or sell copies of the Software, and to permit\n// persons to whom the Software is furnished to do so, subject to the\n// following conditions:\n//\n// The above copyright notice and this permission notice shall be included\n// in all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\n// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN\n// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,\n// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE\n// USE OR OTHER DEALINGS IN THE SOFTWARE.\n\nfunction EventEmitter() {\n this._events = this._events || {};\n this._maxListeners = this._maxListeners || undefined;\n}\nmodule.exports = EventEmitter;\n\n// Backwards-compat with node 0.10.x\nEventEmitter.EventEmitter = EventEmitter;\n\nEventEmitter.prototype._events = undefined;\nEventEmitter.prototype._maxListeners = undefined;\n\n// By default EventEmitters will print a warning if more than 10 listeners are\n// added to it. This is a useful default which helps finding memory leaks.\nEventEmitter.defaultMaxListeners = 10;\n\n// Obviously not all Emitters should be limited to 10. This function allows\n// that to be increased. Set to zero for unlimited.\nEventEmitter.prototype.setMaxListeners = function(n) {\n if (!isNumber(n) || n < 0 || isNaN(n))\n throw TypeError('n must be a positive number');\n this._maxListeners = n;\n return this;\n};\n\nEventEmitter.prototype.emit = function(type) {\n var er, handler, len, args, i, listeners;\n\n if (!this._events)\n this._events = {};\n\n // If there is no 'error' event listener then throw.\n if (type === 'error') {\n if (!this._events.error ||\n (isObject(this._events.error) && !this._events.error.length)) {\n er = arguments[1];\n if (er instanceof Error) {\n throw er; // Unhandled 'error' event\n } else {\n // At least give some kind of context to the user\n var err = new Error('Uncaught, unspecified \"error\" event. (' + er + ')');\n err.context = er;\n throw err;\n }\n }\n }\n\n handler = this._events[type];\n\n if (isUndefined(handler))\n return false;\n\n if (isFunction(handler)) {\n switch (arguments.length) {\n // fast cases\n case 1:\n handler.call(this);\n break;\n case 2:\n handler.call(this, arguments[1]);\n break;\n case 3:\n handler.call(this, arguments[1], arguments[2]);\n break;\n // slower\n default:\n args = Array.prototype.slice.call(arguments, 1);\n handler.apply(this, args);\n }\n } else if (isObject(handler)) {\n args = Array.prototype.slice.call(arguments, 1);\n listeners = handler.slice();\n len = listeners.length;\n for (i = 0; i < len; i++)\n listeners[i].apply(this, args);\n }\n\n return true;\n};\n\nEventEmitter.prototype.addListener = function(type, listener) {\n var m;\n\n if (!isFunction(listener))\n throw TypeError('listener must be a function');\n\n if (!this._events)\n this._events = {};\n\n // To avoid recursion in the case that type === \"newListener\"! Before\n // adding it to the listeners, first emit \"newListener\".\n if (this._events.newListener)\n this.emit('newListener', type,\n isFunction(listener.listener) ?\n listener.listener : listener);\n\n if (!this._events[type])\n // Optimize the case of one listener. Don't need the extra array object.\n this._events[type] = listener;\n else if (isObject(this._events[type]))\n // If we've already got an array, just append.\n this._events[type].push(listener);\n else\n // Adding the second element, need to change to array.\n this._events[type] = [this._events[type], listener];\n\n // Check for listener leak\n if (isObject(this._events[type]) && !this._events[type].warned) {\n if (!isUndefined(this._maxListeners)) {\n m = this._maxListeners;\n } else {\n m = EventEmitter.defaultMaxListeners;\n }\n\n if (m && m > 0 && this._events[type].length > m) {\n this._events[type].warned = true;\n console.error('(node) warning: possible EventEmitter memory ' +\n 'leak detected. %d listeners added. ' +\n 'Use emitter.setMaxListeners() to increase limit.',\n this._events[type].length);\n if (typeof console.trace === 'function') {\n // not supported in IE 10\n console.trace();\n }\n }\n }\n\n return this;\n};\n\nEventEmitter.prototype.on = EventEmitter.prototype.addListener;\n\nEventEmitter.prototype.once = function(type, listener) {\n if (!isFunction(listener))\n throw TypeError('listener must be a function');\n\n var fired = false;\n\n function g() {\n this.removeListener(type, g);\n\n if (!fired) {\n fired = true;\n listener.apply(this, arguments);\n }\n }\n\n g.listener = listener;\n this.on(type, g);\n\n return this;\n};\n\n// emits a 'removeListener' event iff the listener was removed\nEventEmitter.prototype.removeListener = function(type, listener) {\n var list, position, length, i;\n\n if (!isFunction(listener))\n throw TypeError('listener must be a function');\n\n if (!this._events || !this._events[type])\n return this;\n\n list = this._events[type];\n length = list.length;\n position = -1;\n\n if (list === listener ||\n (isFunction(list.listener) && list.listener === listener)) {\n delete this._events[type];\n if (this._events.removeListener)\n this.emit('removeListener', type, listener);\n\n } else if (isObject(list)) {\n for (i = length; i-- > 0;) {\n if (list[i] === listener ||\n (list[i].listener && list[i].listener === listener)) {\n position = i;\n break;\n }\n }\n\n if (position < 0)\n return this;\n\n if (list.length === 1) {\n list.length = 0;\n delete this._events[type];\n } else {\n list.splice(position, 1);\n }\n\n if (this._events.removeListener)\n this.emit('removeListener', type, listener);\n }\n\n return this;\n};\n\nEventEmitter.prototype.removeAllListeners = function(type) {\n var key, listeners;\n\n if (!this._events)\n return this;\n\n // not listening for removeListener, no need to emit\n if (!this._events.removeListener) {\n if (arguments.length === 0)\n this._events = {};\n else if (this._events[type])\n delete this._events[type];\n return this;\n }\n\n // emit removeListener for all listeners on all events\n if (arguments.length === 0) {\n for (key in this._events) {\n if (key === 'removeListener') continue;\n this.removeAllListeners(key);\n }\n this.removeAllListeners('removeListener');\n this._events = {};\n return this;\n }\n\n listeners = this._events[type];\n\n if (isFunction(listeners)) {\n this.removeListener(type, listeners);\n } else if (listeners) {\n // LIFO order\n while (listeners.length)\n this.removeListener(type, listeners[listeners.length - 1]);\n }\n delete this._events[type];\n\n return this;\n};\n\nEventEmitter.prototype.listeners = function(type) {\n var ret;\n if (!this._events || !this._events[type])\n ret = [];\n else if (isFunction(this._events[type]))\n ret = [this._events[type]];\n else\n ret = this._events[type].slice();\n return ret;\n};\n\nEventEmitter.prototype.listenerCount = function(type) {\n if (this._events) {\n var evlistener = this._events[type];\n\n if (isFunction(evlistener))\n return 1;\n else if (evlistener)\n return evlistener.length;\n }\n return 0;\n};\n\nEventEmitter.listenerCount = function(emitter, type) {\n return emitter.listenerCount(type);\n};\n\nfunction isFunction(arg) {\n return typeof arg === 'function';\n}\n\nfunction isNumber(arg) {\n return typeof arg === 'number';\n}\n\nfunction isObject(arg) {\n return typeof arg === 'object' && arg !== null;\n}\n\nfunction isUndefined(arg) {\n return arg === void 0;\n}\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./~/events/events.js\n// module id = 6\n// module chunks = 0 1","/**\n * @param {Externals} options.externals\n * @param {Request} [options.request]\n * @param {Response} [options.response]\n * @param {string} [options.responseText]\n * @property {Externals} _externals\n * @property {Request} _request\n * @property {Response} _response\n * @property {string} _text\n * @property {object} _json\n * @property {ApiResponse[]} _multipart\n */\nfunction ApiResponse(options) {\n\n /** @private */\n this._externals = options.externals;\n\n /** @private */\n this._request = options.request;\n\n /** @private */\n this._response = options.response;\n\n /** @private */\n this._text = options.responseText || '';\n\n /** @private */\n this._json = null;\n\n /** @private */\n this._multipart = [];\n\n}\n\nApiResponse._contentType = 'Content-Type';\nApiResponse._jsonContentType = 'application/json';\nApiResponse._multipartContentType = 'multipart/mixed';\nApiResponse._urlencodedContentType = 'application/x-www-form-urlencoded';\nApiResponse._headerSeparator = ':';\nApiResponse._bodySeparator = '\\n\\n';\nApiResponse._boundarySeparator = '--';\nApiResponse._unauthorizedStatus = 401;\nApiResponse._rateLimitStatus = 429;\n\n/**\n * @param {Response} response\n * @return {Promise}\n */\nApiResponse.prototype.receiveResponse = function(response) {\n\n this._response = response;\n\n return (new this._externals.Promise(function(resolve) {\n\n // Ignore if not textual type\n if (!this._isMultipart() && !this._isJson()) return resolve('');\n\n return resolve(this.response().text());\n\n }.bind(this))).then(function(text) {\n\n this._text = text;\n return text;\n\n }.bind(this));\n\n};\n\n/**\n * @return {Response}\n */\nApiResponse.prototype.response = function() {\n return this._response;\n};\n\n/**\n * @return {Request}\n */\nApiResponse.prototype.request = function() {\n return this._request;\n};\n\n/**\n * @return {boolean}\n */\nApiResponse.prototype.ok = function() {\n return this._response && this._response.ok;\n};\n\n/**\n * @return {string}\n */\nApiResponse.prototype.text = function() {\n // Since we read text only in case JSON or Multipart\n if (!this._isJson() && !this._isMultipart()) throw new Error('Response is not text');\n return this._text;\n};\n\n/**\n * @return {object}\n */\nApiResponse.prototype.json = function() {\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 */\nApiResponse.prototype.error = function(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 * If it is not known upfront what would be the response, client code can treat any response as multipart\n * @return {ApiResponse[]}\n */\nApiResponse.prototype.toMultipart = function() {\n if (!this._isMultipart()) return [this];\n return this.multipart();\n};\n\n/**\n * @return {ApiResponse[]}\n */\nApiResponse.prototype.multipart = function() {\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;\n\n try {\n boundary = this._getContentType().match(/boundary=([^;]+)/i)[1];\n } catch (e) {\n throw new Error('Cannot find boundary');\n }\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 = this._create(parts.shift(), this._response.status, this._response.statusText).json();\n\n // Step 3. Parse all other parts\n\n this._multipart = parts.map(function(part, i) {\n\n var status = statusInfo.response[i].status;\n\n return this._create(part, status);\n\n }.bind(this));\n\n }\n\n return this._multipart;\n\n};\n\n/**\n * @private\n */\nApiResponse.prototype._isContentType = function(contentType) {\n return this._getContentType().indexOf(contentType) > -1;\n};\n\n/**\n * @private\n */\nApiResponse.prototype._getContentType = function() {\n return this._response.headers.get(ApiResponse._contentType) || '';\n};\n\n/**\n * @private\n */\nApiResponse.prototype._isMultipart = function() {\n return this._isContentType(ApiResponse._multipartContentType);\n};\n\n/**\n * @private\n */\nApiResponse.prototype._isJson = function() {\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 * @private\n * @return {ApiResponse}\n */\nApiResponse.prototype._create = function(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 this._externals.Headers(),\n headersAndBody = text.split(ApiResponse._bodySeparator),\n headersText = (headersAndBody.length > 1) ? headersAndBody.shift() : '';\n\n text = headersAndBody.length > 0 ? headersAndBody.join(ApiResponse._bodySeparator) : null;\n\n (headersText || '')\n .split('\\n')\n .forEach(function(header) {\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 var response = new this._externals.Response(text, {\n headers: headers,\n status: status,\n statusText: statusText\n });\n\n return new ApiResponse({\n externals: this._externals,\n request: null,\n response: response,\n responseText: text\n });\n\n};\n\nmodule.exports = ApiResponse;\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/http/ApiResponse.js\n// module id = 7\n// module chunks = 0 1","'use strict';\n\nexports.decode = exports.parse = require('./decode');\nexports.encode = exports.stringify = require('./encode');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./~/querystring/index.js\n// module id = 8\n// module chunks = 0 1","// Copyright Joyent, Inc. and other Node contributors.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a\n// copy of this software and associated documentation files (the\n// \"Software\"), to deal in the Software without restriction, including\n// without limitation the rights to use, copy, modify, merge, publish,\n// distribute, sublicense, and/or sell copies of the Software, and to permit\n// persons to whom the Software is furnished to do so, subject to the\n// following conditions:\n//\n// The above copyright notice and this permission notice shall be included\n// in all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\n// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN\n// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,\n// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE\n// USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n'use strict';\n\n// If obj.hasOwnProperty has been overridden, then calling\n// obj.hasOwnProperty(prop) will break.\n// See: https://github.com/joyent/node/issues/1707\nfunction hasOwnProperty(obj, prop) {\n return Object.prototype.hasOwnProperty.call(obj, prop);\n}\n\nmodule.exports = function(qs, sep, eq, options) {\n sep = sep || '&';\n eq = eq || '=';\n var obj = {};\n\n if (typeof qs !== 'string' || qs.length === 0) {\n return obj;\n }\n\n var regexp = /\\+/g;\n qs = qs.split(sep);\n\n var maxKeys = 1000;\n if (options && typeof options.maxKeys === 'number') {\n maxKeys = options.maxKeys;\n }\n\n var len = qs.length;\n // maxKeys <= 0 means that we should not limit keys count\n if (maxKeys > 0 && len > maxKeys) {\n len = maxKeys;\n }\n\n for (var i = 0; i < len; ++i) {\n var x = qs[i].replace(regexp, '%20'),\n idx = x.indexOf(eq),\n kstr, vstr, k, v;\n\n if (idx >= 0) {\n kstr = x.substr(0, idx);\n vstr = x.substr(idx + 1);\n } else {\n kstr = x;\n vstr = '';\n }\n\n k = decodeURIComponent(kstr);\n v = decodeURIComponent(vstr);\n\n if (!hasOwnProperty(obj, k)) {\n obj[k] = v;\n } else if (Array.isArray(obj[k])) {\n obj[k].push(v);\n } else {\n obj[k] = [obj[k], v];\n }\n }\n\n return obj;\n};\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./~/querystring/decode.js\n// module id = 9\n// module chunks = 0 1","// Copyright Joyent, Inc. and other Node contributors.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a\n// copy of this software and associated documentation files (the\n// \"Software\"), to deal in the Software without restriction, including\n// without limitation the rights to use, copy, modify, merge, publish,\n// distribute, sublicense, and/or sell copies of the Software, and to permit\n// persons to whom the Software is furnished to do so, subject to the\n// following conditions:\n//\n// The above copyright notice and this permission notice shall be included\n// in all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\n// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN\n// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,\n// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE\n// USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n'use strict';\n\nvar stringifyPrimitive = function(v) {\n switch (typeof v) {\n case 'string':\n return v;\n\n case 'boolean':\n return v ? 'true' : 'false';\n\n case 'number':\n return isFinite(v) ? v : '';\n\n default:\n return '';\n }\n};\n\nmodule.exports = function(obj, sep, eq, name) {\n sep = sep || '&';\n eq = eq || '=';\n if (obj === null) {\n obj = undefined;\n }\n\n if (typeof obj === 'object') {\n return Object.keys(obj).map(function(k) {\n var ks = encodeURIComponent(stringifyPrimitive(k)) + eq;\n if (Array.isArray(obj[k])) {\n return obj[k].map(function(v) {\n return ks + encodeURIComponent(stringifyPrimitive(v));\n }).join(sep);\n } else {\n return ks + encodeURIComponent(stringifyPrimitive(obj[k]));\n }\n }).join(sep);\n\n }\n\n if (!name) return '';\n return encodeURIComponent(stringifyPrimitive(name)) + eq +\n encodeURIComponent(stringifyPrimitive(obj));\n};\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./~/querystring/encode.js\n// module id = 10\n// module chunks = 0 1","var pubnub = require(\"pubnub\");\nvar es6Promise = require(\"es6-promise\");\nvar FetchPonyfill = require(\"fetch-ponyfill\");\n\nvar root = (typeof window !== \"undefined\" && window) ||\n (typeof global !== \"undefined\" && global) ||\n (function(){ return this; })();\n\n/**\n * @constructor\n * @param {PubNub} [options.PubNub]\n * @param {function(new:Promise)} [options.Promise]\n * @param {Storage} [options.localStorage]\n * @param {fetch} [options.fetch]\n * @param {function(new:Request)} [options.Request]\n * @param {function(new:Response)} [options.Response]\n * @param {function(new:Headers)} [options.Headers]\n * @property {PubNub} PubNub\n * @property {Storage} localStorage\n * @property {function(new:Promise)} Promise\n * @property {fetch} fetch\n * @property {function(new:Request)} Request\n * @property {function(new:Response)} Response\n * @property {function(new:Headers)} Headers\n */\nfunction Externals(options) {\n\n options = options || {};\n\n this.PubNub = options.PubNub || root.PubNub || pubnub;\n this.localStorage = options.localStorage || ((typeof root.localStorage !== 'undefined') ? root.localStorage : {});\n this.Promise = options.Promise || root.Promise || (es6Promise && es6Promise.Promise);\n\n var fetchPonyfill = FetchPonyfill ? FetchPonyfill({Promise: this.Promise}) : {};\n\n this.fetch = options.fetch || root.fetch || fetchPonyfill.fetch;\n this.Request = options.Request || root.Request || fetchPonyfill.Request;\n this.Response = options.Response || root.Response || fetchPonyfill.Response;\n this.Headers = options.Headers || root.Headers || fetchPonyfill.Headers;\n\n /* istanbul ignore next */\n if (!this.fetch || !this.Response || !this.Request || !this.Headers) {\n throw new Error('Fetch API is missing');\n }\n\n /* istanbul ignore next */\n if (!this.Promise) {\n throw new Error('Promise is missing');\n }\n\n /* istanbul ignore next */\n if (!this.localStorage) {\n throw new Error('LocalStorage is missing');\n }\n\n /* istanbul ignore next */\n if (!this.PubNub) {\n throw new Error('PubNub is missing');\n }\n\n}\n\nmodule.exports = Externals;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/core/Externals.js\n// module id = 11\n// module chunks = 0 1","module.exports = __WEBPACK_EXTERNAL_MODULE_12__;\n\n\n//////////////////\n// WEBPACK FOOTER\n// external {\"amd\":\"pubnub\"}\n// module id = 12\n// module chunks = 0 1","module.exports = __WEBPACK_EXTERNAL_MODULE_13__;\n\n\n//////////////////\n// WEBPACK FOOTER\n// external {\"amd\":\"es6-promise\"}\n// module id = 13\n// module chunks = 0 1","module.exports = __WEBPACK_EXTERNAL_MODULE_14__;\n\n\n//////////////////\n// WEBPACK FOOTER\n// external {\"amd\":\"fetch-ponyfill\"}\n// module id = 14\n// module chunks = 0 1","var EventEmitter = require(\"events\").EventEmitter;\nvar qs = require(\"querystring\");\nvar objectAssign = require('object-assign');\nvar Auth = require(\"./Auth\");\nvar Constants = require(\"../core/Constants\");\nvar ApiResponse = require(\"../http/ApiResponse\");\n\n/**\n * @constructor\n * @param {string} options.server\n * @param {string} options.appSecret\n * @param {string} options.appKey\n * @param {string} [options.appName]\n * @param {string} [options.appVersion]\n * @param {string} [options.redirectUri]\n * @param {int} [options.refreshDelayMs]\n * @param {int} [options.refreshHandicapMs]\n * @param {boolean} [options.clearCacheOnRefreshError]\n * @param {Externals} options.externals\n * @param {Cache} options.cache\n * @param {Client} options.client\n * @property {Externals} _externals\n * @property {Cache} _cache\n * @property {Client} _client\n * @property {Promise} _refreshPromise\n * @property {Auth} _auth\n */\nfunction Platform(options) {\n\n EventEmitter.call(this);\n\n this.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 rateLimitError: 'rateLimitError'\n };\n\n options = options || {};\n\n /** @private */\n this._server = options.server;\n\n /** @private */\n this._appKey = options.appKey;\n\n /** @private */\n this._appSecret = options.appSecret;\n\n /** @private */\n this._redirectUri = options.redirectUri || '';\n\n /** @private */\n this._refreshDelayMs = options.refreshDelayMs || 100;\n\n /** @private */\n this._clearCacheOnRefreshError = typeof options.clearCacheOnRefreshError !== 'undefined' ?\n options.clearCacheOnRefreshError :\n true;\n\n /** @private */\n this._userAgent = (options.appName ?\n (options.appName + (options.appVersion ? '/' + options.appVersion : '')) + ' ' :\n '') + 'RCJSSDK/' + Constants.version;\n\n /** @private */\n this._externals = options.externals;\n\n /** @private */\n this._cache = options.cache;\n\n /** @private */\n this._client = options.client;\n\n /** @private */\n this._knownPrefixes = options.knownPrefixes || Platform._knownPrefixes;\n\n\n /** @private */\n this._refreshPromise = null;\n\n /** @private */\n this._auth = new Auth({\n cache: this._cache,\n cacheId: Platform._cacheId,\n refreshHandicapMs: options.refreshHandicapMs\n });\n\n}\n\nPlatform._urlPrefix = '/restapi';\nPlatform._apiVersion = 'v1.0';\nPlatform._knownPrefixes = ['/rcvideo'];\nPlatform._tokenEndpoint = '/restapi/oauth/token';\nPlatform._revokeEndpoint = '/restapi/oauth/revoke';\nPlatform._authorizeEndpoint = '/restapi/oauth/authorize';\nPlatform._cacheId = 'platform';\n\nPlatform.prototype = Object.create(EventEmitter.prototype);\n\nPlatform.prototype.delay = function(timeout) {\n return new this._externals.Promise(function(resolve, reject) {\n setTimeout(function() {\n resolve(null);\n }, timeout);\n });\n};\n\n/**\n * @return {Auth}\n */\nPlatform.prototype.auth = function() {\n return this._auth;\n};\n\n/**\n * @return {Client}\n */\nPlatform.prototype.client = function() {\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 */\nPlatform.prototype.createUrl = function(path, options) {\n\n path = path || '';\n options = options || {};\n\n var builtUrl = '',\n hasHttp = path.indexOf('http://') != -1 || path.indexOf('https://') != -1,\n alreadyPrefixed = this._knownPrefixes.some(function(prefix) {\n return path.indexOf(prefix) === 0;\n });\n\n if (options.addServer && !hasHttp) builtUrl += this._server;\n\n if (path.indexOf(Platform._urlPrefix) == -1 && !hasHttp && !alreadyPrefixed) {\n builtUrl += Platform._urlPrefix + '/' + Platform._apiVersion;\n }\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] Overrides default RedirectURI\n * @param {string} [options.state]\n * @param {string} [options.brandId]\n * @param {string} [options.display]\n * @param {string} [options.prompt]\n * @param {boolean} [options.implicit] Use Implicit Grant flow\n * @return {string}\n */\nPlatform.prototype.loginUrl = function(options) {\n\n options = options || {};\n\n return this.createUrl(Platform._authorizeEndpoint + '?' + qs.stringify({\n 'response_type': options.implicit ? 'token' : 'code',\n 'redirect_uri': options.redirectUri || this._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 */\nPlatform.prototype.parseLoginRedirect = function(url) {\n\n function getParts(url, separator) {\n return url.split(separator).reverse()[0];\n }\n\n var response = (url.indexOf('#') === 0 && getParts(url, '#')) ||\n (url.indexOf('?') === 0 && getParts(url, '?')) ||\n null;\n\n if (!response) throw new Error('Unable to parse response');\n\n var queryString = qs.parse(response);\n\n if (!queryString) throw new Error('Unable to parse response');\n\n var error = queryString.error_description || queryString.error;\n\n if (error) {\n var e = new Error(error);\n e.error = queryString.error;\n throw e;\n }\n\n return queryString;\n\n};\n\n/**\n * Convenience method to handle 3-legged OAuth\n *\n * Attention! This is an experimental method and it's signature and behavior may change without notice.\n *\n * @experimental\n * @param {string} options.url\n * @param {number} [options.width]\n * @param {number} [options.height]\n * @param {object} [options.login] additional options for login()\n * @param {string} [options.origin]\n * @param {string} [options.property] name of window.postMessage's event data property\n * @param {string} [options.target] target for window.open()\n * @return {Promise}\n */\nPlatform.prototype.loginWindow = function(options) {\n\n return new this._externals.Promise(function(resolve, reject) {\n\n if (typeof window === 'undefined') throw new Error('This method can be used only in browser');\n\n if (!options.url) throw new Error('Missing mandatory URL parameter');\n\n options = options || {};\n options.width = options.width || 400;\n options.height = options.height || 600;\n options.origin = options.origin || window.location.origin;\n options.property = options.property || Constants.authResponseProperty;\n options.target = options.target || '_blank';\n\n var dualScreenLeft = window.screenLeft !== undefined ? window.screenLeft : screen.left;\n var dualScreenTop = window.screenTop !== undefined ? window.screenTop : screen.top;\n\n var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width;\n var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;\n\n var left = ((width / 2) - (options.width / 2)) + dualScreenLeft;\n var top = ((height / 2) - (options.height / 2)) + dualScreenTop;\n var win = window.open(options.url, '_blank', (options.target == '_blank') ? 'scrollbars=yes, status=yes, width=' + options.width + ', height=' + options.height + ', left=' + left + ', top=' + top : '');\n\n if (!win) {\n throw new Error('Could not open login window. Please allow popups for this site');\n }\n\n if (win.focus) win.focus();\n\n var eventMethod = window.addEventListener ? 'addEventListener' : 'attachEvent';\n var eventRemoveMethod = eventMethod == 'addEventListener' ? 'removeEventListener' : 'detachEvent';\n var messageEvent = eventMethod == 'addEventListener' ? 'message' : 'onmessage';\n\n var eventListener = function(e) {\n\n try {\n\n if (e.origin != options.origin) return;\n if (!e.data || !e.data[options.property]) return; // keep waiting\n\n win.close();\n window[eventRemoveMethod](messageEvent, eventListener);\n\n\n var loginOptions = this.parseLoginRedirect(e.data[options.property]);\n\n if (!loginOptions.code && !loginOptions.access_token) throw new Error('No authorization code or token');\n\n resolve(loginOptions);\n\n /* jshint -W002 */\n } catch (e) {\n reject(e);\n }\n\n }.bind(this);\n\n window[eventMethod](messageEvent, eventListener, false);\n\n }.bind(this));\n\n};\n\n/**\n * @return {Promise}\n */\nPlatform.prototype.loggedIn = function() {\n\n return this.ensureLoggedIn().then(function() {\n return true;\n }).catch(function() {\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 * @param {string} [options.accessTokenTtl]\n * @param {string} [options.refreshTokenTtl]\n * @param {string} [options.access_token]\n * @returns {Promise}\n */\nPlatform.prototype.login = function(options) {\n\n return (new this._externals.Promise(function(resolve) {\n\n options = options || {};\n\n this.emit(this.events.beforeLogin);\n\n var body = {};\n\n if (options.access_token) {\n\n //TODO Potentially make a request to /oauth/tokeninfo\n return resolve(options);\n\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 || this._redirectUri;\n //body.client_id = this.getCredentials().key; // not needed\n\n }\n\n if (options.endpointId) body.endpoint_id = options.endpointId;\n if (options.accessTokenTtl) body.access_token_ttl = options.accessTokenTtl;\n if (options.refreshTokenTtl) body.refresh_token_ttl = options.refreshTokenTtl;\n\n resolve(this._tokenRequest(Platform._tokenEndpoint, body));\n\n }.bind(this))).then(function(res) {\n\n var apiResponse = res.json ? res : null;\n var json = apiResponse && apiResponse.json() || res;\n\n this._auth.setData(json);\n\n this.emit(this.events.loginSuccess, apiResponse);\n\n return apiResponse;\n\n }.bind(this)).catch(function(e) {\n\n if (this._clearCacheOnRefreshError) {\n this._cache.clean();\n }\n\n this.emit(this.events.loginError, e);\n\n throw e;\n\n }.bind(this));\n\n};\n\n/**\n * @returns {Promise}\n * @private\n */\nPlatform.prototype._refresh = function() {\n\n return this.delay(this._refreshDelayMs).then(function() {\n\n this.emit(this.events.beforeRefresh);\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\n return this._tokenRequest(Platform._tokenEndpoint, {\n \"grant_type\": \"refresh_token\",\n \"refresh_token\": this._auth.refreshToken(),\n \"access_token_ttl\": this._auth.data().expires_in + 1,\n \"refresh_token_ttl\": this._auth.data().refresh_token_expires_in + 1\n });\n\n }.bind(this)).then(function(/** @type {ApiResponse} */ res) {\n\n var 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\n this.emit(this.events.refreshSuccess, res);\n\n return res;\n\n }.bind(this)).catch(function(e) {\n\n e = this._client.makeError(e);\n\n if (this._clearCacheOnRefreshError) {\n this._cache.clean();\n }\n\n this.emit(this.events.refreshError, e);\n\n throw e;\n\n }.bind(this));\n\n};\n\n/**\n * @returns {Promise}\n */\nPlatform.prototype.refresh = function() {\n\n if (!this._refreshPromise) {\n\n this._refreshPromise = this._refresh()\n .then(function(res) {\n this._refreshPromise = null;\n return res;\n }.bind(this))\n .catch(function(e) {\n this._refreshPromise = null;\n throw e;\n }.bind(this));\n\n }\n\n return this._refreshPromise;\n\n};\n\n/**\n * @returns {Promise}\n */\nPlatform.prototype.logout = function() {\n\n return (new this._externals.Promise(function(resolve) {\n\n this.emit(this.events.beforeLogout);\n\n if (!this._appSecret) {\n resolve(null);\n return;\n }\n\n resolve(this._tokenRequest(Platform._revokeEndpoint, {\n token: this._auth.accessToken()\n }));\n }.bind(this))).then(function(res) {\n\n this._cache.clean();\n\n this.emit(this.events.logoutSuccess, res);\n\n return res;\n\n }.bind(this)).catch(function(e) {\n\n this.emit(this.events.logoutError, e);\n\n throw e;\n\n }.bind(this));\n\n};\n\n/**\n * @param {Request} request\n * @param {object} [options]\n * @param {boolean} [options.skipAuthCheck]\n * @return {Promise}\n */\nPlatform.prototype.inflateRequest = function(request, options) {\n\n options = options || {};\n\n if (options.skipAuthCheck) return this._externals.Promise.resolve(request);\n\n return this.ensureLoggedIn().then(function() {\n\n request.headers.set('X-User-Agent', this._userAgent);\n request.headers.set('Client-Id', this._appKey);\n request.headers.set('Authorization', this._authHeader());\n //request.url = this.createUrl(request.url, {addServer: true}); //FIXME Spec prevents this...\n\n return request;\n\n }.bind(this));\n\n};\n\n/**\n * @param {Request} request\n * @param {object} [options]\n * @param {boolean} [options.skipAuthCheck]\n * @param {boolean|int} [options.handleRateLimit]\n * @param {boolean} [options.retry] Will be set by this method if SDK makes second request\n * @return {Promise}\n */\nPlatform.prototype.sendRequest = function(request, options) {\n\n return this.inflateRequest(request, options).then(function(request) {\n\n options = options || {};\n\n return this._client.sendRequest(request);\n\n }.bind(this)).catch(function(e) {\n\n // Guard is for errors that come from polling\n if (!e.apiResponse || !e.apiResponse.response() || options.retry) throw e;\n\n var response = e.apiResponse.response();\n var status = response.status;\n\n if ((status != ApiResponse._unauthorizedStatus) &&\n (status != ApiResponse._rateLimitStatus)) throw e;\n\n options.retry = true;\n\n var retryAfter = 0;\n\n if (status == ApiResponse._unauthorizedStatus) {\n this._auth.cancelAccessToken();\n }\n\n if (status == ApiResponse._rateLimitStatus) {\n\n var defaultRetryAfter = (!options.handleRateLimit || typeof options.handleRateLimit == 'boolean' ? 60 : options.handleRateLimit);\n\n // FIXME retry-after is custom header, by default, it can't be retrieved. Server should add header: 'Access-Control-Expose-Headers: retry-after'.\n retryAfter = parseFloat(response.headers.get('retry-after') || defaultRetryAfter) * 1000;\n\n e.retryAfter = retryAfter;\n\n this.emit(this.events.rateLimitError, e);\n\n if (!options.handleRateLimit) throw e;\n\n }\n\n return this.delay(retryAfter).then(function() {\n return this.sendRequest(this._client.createRequest(options), options);\n }.bind(this));\n\n }.bind(this));\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 * @param {boolean|int} [options.handleRateLimit]\n * @return {Promise}\n */\nPlatform.prototype.send = function(options) {\n\n options = options || {};\n\n //FIXME https://github.com/bitinn/node-fetch/issues/43\n options.url = this.createUrl(options.url, {addServer: true});\n\n return 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 * @param {boolean|int} [options.handleRateLimit]\n * @return {Promise}\n */\nPlatform.prototype.get = function(url, query, options) {\n return this.send(objectAssign({}, {method: 'GET', url: url, query: query}, 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 * @param {boolean|int} [options.handleRateLimit]\n * @return {Promise}\n */\nPlatform.prototype.post = function(url, body, query, options) {\n return this.send(objectAssign({}, {method: 'POST', url: url, query: query, body: body}, 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 * @param {boolean|int} [options.handleRateLimit]\n * @return {Promise}\n */\nPlatform.prototype.put = function(url, body, query, options) {\n return this.send(objectAssign({}, {method: 'PUT', url: url, query: query, body: body}, 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 * @param {boolean|int} [options.handleRateLimit]\n * @return {Promise}\n */\nPlatform.prototype['delete'] = function(url, query, options) {\n return this.send(objectAssign({}, {method: 'DELETE', url: url, query: query}, options));\n};\n\nPlatform.prototype.ensureLoggedIn = function() {\n if (this._isAccessTokenValid()) return this._externals.Promise.resolve();\n return this.refresh();\n};\n\n/**\n * @param path\n * @param body\n * @return {Promise.}\n * @private\n */\nPlatform.prototype._tokenRequest = function(path, body) {\n\n return this.send({\n url: path,\n skipAuthCheck: true,\n body: body,\n method: 'POST',\n headers: {\n 'Authorization': 'Basic ' + this._apiKey(),\n 'Content-Type': ApiResponse._urlencodedContentType\n }\n });\n\n};\n\n/**\n * @return {boolean}\n * @private\n */\nPlatform.prototype._isAccessTokenValid = function() {\n return this._auth.accessTokenValid();\n};\n\n/**\n * @return {string}\n * @private\n */\nPlatform.prototype._apiKey = function() {\n var apiKey = this._appKey + ':' + this._appSecret;\n return (typeof btoa == 'function') ? btoa(apiKey) : new Buffer(apiKey).toString('base64');\n};\n\n/**\n * @return {string}\n * @private\n */\nPlatform.prototype._authHeader = function() {\n var token = this._auth.accessToken();\n return this._auth.tokenType() + (token ? ' ' + token : '');\n};\n\nmodule.exports = Platform;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/platform/Platform.js\n// module id = 15\n// module chunks = 0 1","/**\n * @param {Cache} options.cache\n * @param {string} options.cacheId\n * @param {int} [options.refreshHandicapMs]\n * @constructor\n * @property {Cache} _cache\n * @property {int} _refreshHandicapMs\n * @property {string} _cacheId\n */\nfunction Auth(options) {\n\n /** @private */\n this._cache = options.cache;\n\n /** @private */\n this._cacheId = options.cacheId;\n\n /** @private */\n this._refreshHandicapMs = options.refreshHandicapMs || 60 * 1000; // 1 minute\n\n}\n\nAuth.prototype.accessToken = function() {\n return this.data().access_token;\n};\n\nAuth.prototype.refreshToken = function() {\n return this.data().refresh_token;\n};\n\nAuth.prototype.tokenType = function() {\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 */\nAuth.prototype.data = function() {\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 */\nAuth.prototype.setData = function(newData) {\n\n newData = newData || {};\n\n var data = this.data();\n\n Object.keys(newData).forEach(function(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 */\nAuth.prototype.accessTokenValid = function() {\n\n var authData = this.data();\n return (authData.expire_time - this._refreshHandicapMs > Date.now());\n\n};\n\n/**\n * Check if there is a valid (not expired) access token\n * @return {boolean}\n */\nAuth.prototype.refreshTokenValid = function() {\n\n return (this.data().refresh_token_expire_time > Date.now());\n\n};\n\n/**\n * @return {Auth}\n */\nAuth.prototype.cancelAccessToken = function() {\n\n return this.setData({\n access_token: '',\n expires_in: 0\n });\n\n};\n\nmodule.exports = Auth;\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//////////////////\n// WEBPACK FOOTER\n// ./src/platform/Auth.js\n// module id = 16\n// module chunks = 0 1","var version = process.env.RCSDK_VERSION;\n\n// This will become false during the Webpack build, so no traces of package.json will be there\nif (!process.env.RCSDK_VERSION) {\n version = require('../../package.json').version;\n}\n\nmodule.exports = {\n version: version,\n authResponseProperty: 'RCAuthorizationResponse'\n};\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/core/Constants.js\n// module id = 17\n// module chunks = 0 1","var EventEmitter = require(\"events\").EventEmitter;\n\n// detect ISO 8601 format string with +00[:00] timezone notations\nvar ISO_REG_EXP = /(\\+[\\d]{2}):?([\\d]{2})?$/;\n\nfunction buildIEFriendlyString(match, $1, $2) {\n return $1 + ':' + ($2 || '00');\n}\n\n/**\n *\n * @param {string} time\n * @return {number}\n */\nfunction parseISOString(time) {\n time = time || 0;\n if (typeof time === 'string') {\n return Date.parse(time.replace(ISO_REG_EXP, buildIEFriendlyString));\n }\n return time;\n}\n\n/**\n * @param {Platform} options.platform\n * @param {Externals} options.externals\n * @param {int} [options.pollInterval]\n * @param {int} [options.renewHandicapMs]\n * @property {Externals} _externals\n * @property {Platform} _platform\n * @property {int} _pollInterval\n * @property {int} _renewHandicapMs\n * @property {PubNub} _pubnub\n * @property {string} _pubnubLastChannel\n * @property {int} _timeout\n * @property {ISubscription} _subscription\n * @constructor\n */\nfunction Subscription(options) {\n\n EventEmitter.call(this);\n\n options = options || {};\n\n this.events = {\n notification: 'notification',\n removeSuccess: 'removeSuccess',\n removeError: 'removeError',\n renewSuccess: 'renewSuccess',\n renewError: 'renewError',\n subscribeSuccess: 'subscribeSuccess',\n subscribeError: 'subscribeError',\n automaticRenewSuccess: 'automaticRenewSuccess',\n automaticRenewError: 'automaticRenewError'\n };\n\n /** @private */\n this._externals = options.externals;\n\n /** @private */\n this._platform = options.platform;\n\n /** @private */\n this._pollInterval = options.pollInterval || 10 * 1000;\n\n /** @private */\n this._renewHandicapMs = options.renewHandicapMs || 2 * 60 * 1000;\n\n /** @private */\n this._pubnub = null;\n\n /** @private */\n this._pubnubLastChannel = null;\n\n /** @private */\n this._pubnubLastSubscribeKey = null;\n\n /** @private */\n this._timeout = null;\n\n /** @private */\n this._subscription = null;\n\n}\n\nSubscription.prototype = Object.create(EventEmitter.prototype);\n\nSubscription.prototype.subscribed = function() {\n\n var subscription = this.subscription();\n\n return !!(subscription.id &&\n subscription.deliveryMode &&\n subscription.deliveryMode.subscriberKey &&\n subscription.deliveryMode.address);\n\n};\n\n/**\n * @return {boolean}\n */\nSubscription.prototype.alive = function() {\n return this.subscribed() && Date.now() < this.expirationTime();\n};\n\n/**\n * @return {boolean}\n */\nSubscription.prototype.expired = function() {\n if (!this.subscribed()) return true;\n return !this.subscribed() || Date.now() > parseISOString(this.subscription().expirationTime);\n};\n\n/**\n * @return {number}\n */\nSubscription.prototype.expirationTime = function() {\n return parseISOString(this.subscription().expirationTime) - this._renewHandicapMs;\n};\n\n/**\n * @param {ISubscription} subscription\n * @return {Subscription}\n */\nSubscription.prototype.setSubscription = function(subscription) {\n\n subscription = subscription || {};\n\n this._clearTimeout();\n this._setSubscription(subscription);\n this._subscribeAtPubnub();\n this._setTimeout();\n\n return this;\n\n};\n\n/**\n * @return {ISubscription}\n */\nSubscription.prototype.subscription = function() {\n return this._subscription || {};\n};\n\n/**\n * Creates or updates subscription if there is an active one\n * @returns {Promise}\n */\nSubscription.prototype.register = function() {\n\n if (this.alive()) {\n return this.renew();\n } else {\n return this.subscribe();\n }\n\n};\n\n/**\n * @return {string[]}\n */\nSubscription.prototype.eventFilters = function() {\n return this.subscription().eventFilters || [];\n};\n\n/**\n * @param {string[]} events\n * @return {Subscription}\n */\nSubscription.prototype.addEventFilters = function(events) {\n this.setEventFilters(this.eventFilters().concat(events));\n return this;\n};\n\n/**\n * @param {string[]} events\n * @return {Subscription}\n */\nSubscription.prototype.setEventFilters = function(events) {\n var subscription = this.subscription();\n subscription.eventFilters = events;\n this._setSubscription(subscription);\n return this;\n};\n\n/**\n * @returns {Promise}\n */\nSubscription.prototype.subscribe = function() {\n\n return (new this._externals.Promise(function(resolve) {\n\n this._clearTimeout();\n\n if (!this.eventFilters().length) throw new Error('Events are undefined');\n\n resolve(this._platform.post('/subscription', {\n eventFilters: this._getFullEventFilters(),\n deliveryMode: {\n transportType: 'PubNub'\n }\n }));\n\n }.bind(this))).then(function(response) {\n\n var json = response.json();\n\n this.setSubscription(json)\n .emit(this.events.subscribeSuccess, response);\n\n return response;\n\n }.bind(this)).catch(function(e) {\n\n e = this._platform.client().makeError(e);\n // `reset` will remove pubnub instance.\n // so if network is broken for a long time, pubnub will be removed. And client can not receive notification anymore.\n this.reset()\n .emit(this.events.subscribeError, e);\n\n throw e;\n\n }.bind(this));\n\n};\n\n/**\n * @returns {Promise}\n */\nSubscription.prototype.renew = function() {\n\n return (new this._externals.Promise(function(resolve) {\n\n this._clearTimeout();\n\n if (!this.subscribed()) throw new Error('No subscription');\n\n if (!this.eventFilters().length) throw new Error('Events are undefined');\n\n resolve(this._platform.put('/subscription/' + this.subscription().id, {\n eventFilters: this._getFullEventFilters()\n }));\n\n }.bind(this))).then(function(response) {\n\n var json = response.json();\n\n this.setSubscription(json)\n .emit(this.events.renewSuccess, response);\n\n return response;\n\n }.bind(this)).catch(function(e) {\n\n e = this._platform.client().makeError(e);\n // `reset` will remove pubnub instance.\n // so if network is broken for a long time, pubnub will be removed. And client can not receive notification anymore.\n this.reset()\n .emit(this.events.renewError, e);\n\n throw e;\n\n }.bind(this));\n\n};\n\n/**\n * @returns {Promise}\n */\nSubscription.prototype.remove = function() {\n\n return (new this._externals.Promise(function(resolve) {\n\n if (!this.subscribed()) throw new Error('No subscription');\n\n resolve(this._platform.delete('/subscription/' + this.subscription().id));\n\n }.bind(this))).then(function(response) {\n\n this.reset()\n .emit(this.events.removeSuccess, response);\n\n return response;\n\n }.bind(this)).catch(function(e) {\n\n e = this._platform.client().makeError(e);\n\n this.emit(this.events.removeError, e);\n\n throw e;\n\n }.bind(this));\n\n};\n\n/**\n * @returns {Promise}\n */\nSubscription.prototype.resubscribe = function() {\n var filters = this.eventFilters();\n return this.reset().setEventFilters(filters).subscribe();\n};\n\n/**\n * Remove subscription and disconnect from PubNub\n * This method resets subscription at client side but backend is not notified\n * @return {Subscription}\n */\nSubscription.prototype.reset = function() {\n this._clearTimeout();\n this._unsubscribeAtPubnub();\n this._setSubscription(null);\n return this;\n};\n\n/**\n * @param subscription\n * @private\n */\nSubscription.prototype._setSubscription = function(subscription) {\n this._subscription = subscription;\n};\n\n/**\n * @return {string[]}\n * @private\n */\nSubscription.prototype._getFullEventFilters = function() {\n\n return this.eventFilters().map(function(event) {\n return this._platform.createUrl(event);\n }.bind(this));\n\n};\n\n/**\n * @return {Subscription}\n * @private\n */\nSubscription.prototype._setTimeout = function() {\n\n this._clearTimeout();\n\n if (!this.alive()) throw new Error('Subscription is not alive');\n\n this._timeout = setInterval(function() {\n\n if (this.alive()) {\n return;\n }\n\n this._clearTimeout();\n\n (new this._externals.Promise(function(resolve) {\n\n if (this.expired()) {\n resolve(this.subscribe());\n } else {\n resolve(this.renew());\n }\n\n }.bind(this))).then(function(res) {\n\n this.emit(this.events.automaticRenewSuccess, res);\n\n }.bind(this)).catch(function(e) {\n\n this.emit(this.events.automaticRenewError, e);\n\n }.bind(this));\n\n }.bind(this), this._pollInterval);\n\n return this;\n\n};\n\n/**\n * @return {Subscription}\n * @private\n */\nSubscription.prototype._clearTimeout = function() {\n clearInterval(this._timeout);\n return this;\n};\n\nSubscription.prototype._decrypt = function(message) {\n\n if (!this.subscribed()) throw new Error('No subscription');\n\n if (this.subscription().deliveryMode.encryptionKey) {\n\n message = this._pubnub.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/**\n * @param message\n * @return {Subscription}\n * @private\n */\nSubscription.prototype._notify = function(message) {\n this.emit(this.events.notification, this._decrypt(message));\n return this;\n};\n\n/**\n * @return {Subscription}\n * @private\n */\nSubscription.prototype._subscribeAtPubnub = function() {\n\n if (!this.alive()) throw new Error('Subscription is not alive');\n\n var deliveryMode = this.subscription().deliveryMode;\n\n if (this._pubnub) {\n\n if (this._pubnubLastChannel === deliveryMode.address) {\n\n // Nothing to update, keep listening to same channel\n return this;\n\n } else if (this._pubnubLastSubscribeKey && this._pubnubLastSubscribeKey !== deliveryMode.subscriberKey) {\n\n // Subscribe key changed, need to reset everything\n this._unsubscribeAtPubnub();\n\n } else if (this._pubnubLastChannel) {\n\n // Need to subscribe to new channel\n this._pubnub.unsubscribeAll();\n\n }\n\n }\n\n if (!this._pubnub) {\n\n this._pubnubLastSubscribeKey = deliveryMode.subscriberKey;\n\n var PubNub = this._externals.PubNub;\n\n this._pubnub = new PubNub({\n ssl: true,\n restore: true,\n subscribeKey: deliveryMode.subscriberKey\n });\n\n this._pubnub.addListener({\n status: function(statusEvent) {},\n message: function(m) {\n this._notify(m.message); // all other props are ignored\n }.bind(this)\n });\n\n }\n\n this._pubnubLastChannel = deliveryMode.address;\n this._pubnub.subscribe({channels: [deliveryMode.address]});\n\n return this;\n\n};\n\n/**\n * @return {Subscription}\n * @private\n */\nSubscription.prototype._unsubscribeAtPubnub = function() {\n\n if (!this.subscribed() || !this._pubnub) return this;\n\n this._pubnub.removeAllListeners();\n this._pubnub.destroy(); // this will unsubscribe from all\n\n this._pubnubLastSubscribeKey = null;\n this._pubnubLastChannel = null;\n this._pubnub = null;\n\n return this;\n\n};\n\nmodule.exports = Subscription;\n\n/**\n * The complete Triforce, or one or more components of the Triforce.\n * @typedef {Object} ISubscription\n * @property {string} [id]\n * @property {string} [uri]\n * @property {string[]} [eventFilters]\n * @property {string} [expirationTime] Format: 2014-03-12T19:54:35.613+0000\n * @property {int} [expiresIn]\n * @property {string} [deliveryMode.transportType]\n * @property {boolean} [deliveryMode.encryption]\n * @property {string} [deliveryMode.address]\n * @property {string} [deliveryMode.subscriberKey]\n * @property {string} [deliveryMode.encryptionKey]\n * @property {string} [deliveryMode.secretKey]\n * @property {string} [creationTime]\n * @property {string} [status] Active\n */\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/subscription/Subscription.js\n// module id = 18\n// module chunks = 0 1","var Subscription = require(\"./Subscription\");\n\n/**\n * @param {Platform} options.platform\n * @param {Externals} options.externals\n * @param {Cache} options.cache\n * @param {string} options.cacheKey\n * @param {int} [options.pollInterval]\n * @param {int} [options.renewHandicapMs]\n * @return {CachedSubscription}\n * @constructor\n * @property {Cache} _cache\n * @extends Subscription\n */\nfunction CachedSubscription(options) {\n\n options = options || {};\n\n if (!options.cacheKey) throw new Error('Cached Subscription requires cacheKey parameter to be defined');\n\n /** @private */\n this._cacheKey = options.cacheKey;\n\n Subscription.call(this, options);\n\n /** @private */\n this._cache = options.cache;\n\n // This is not used in this class\n this._subscription = undefined;\n\n}\n\nCachedSubscription.prototype = Object.create(Subscription.prototype);\n\nCachedSubscription.prototype.subscription = function() {\n return this._cache.getItem(this._cacheKey) || {};\n};\n\nCachedSubscription.prototype._setSubscription = function(subscription) {\n return this._cache.setItem(this._cacheKey, subscription);\n};\n\n/**\n * This function checks whether there are any pre-defined eventFilters in cache and if not -- uses provided as defaults\n * @param {string[]} events\n * @return {CachedSubscription}\n */\nCachedSubscription.prototype.restore = function(events) {\n\n if (!this.eventFilters().length) {\n this.setEventFilters(events);\n }\n\n return this;\n\n};\n\nmodule.exports = CachedSubscription;\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/subscription/CachedSubscription.js\n// module id = 19\n// module chunks = 0 1"],"sourceRoot":""} \ No newline at end of file +{"version":3,"sources":["webpack:///webpack/universalModuleDefinition","webpack:///webpack/bootstrap 9170c9929c7a92918002","webpack:///./src/SDK.js","webpack:///./~/object-assign/index.js","webpack:///./src/core/Cache.js","webpack:///./src/http/Client.js","webpack:///./~/is-plain-object/index.js","webpack:///./~/isobject/index.js","webpack:///./~/events/events.js","webpack:///./src/http/ApiResponse.js","webpack:///./~/querystring/index.js","webpack:///./~/querystring/decode.js","webpack:///./~/querystring/encode.js","webpack:///./src/core/Externals.js","webpack:///external {\"amd\":\"pubnub\"}","webpack:///external {\"amd\":\"es6-promise\"}","webpack:///external {\"amd\":\"fetch-ponyfill\"}","webpack:///./src/platform/Platform.js","webpack:///./src/platform/Auth.js","webpack:///./src/core/Constants.js","webpack:///./src/subscription/Subscription.js","webpack:///./src/subscription/CachedSubscription.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,iDAAiD;AACjD,CAAC;AACD,O;ACVA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA,uBAAe;AACf;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;;;;;;ACtCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,WAAW,OAAO;AAClB,WAAW,OAAO;AAClB,WAAW,OAAO;AAClB,WAAW,OAAO;AAClB,WAAW,OAAO;AAClB,WAAW,OAAO;AAClB,WAAW,OAAO;AAClB,WAAW,OAAO;AAClB,WAAW,sBAAsB;AACjC,WAAW,QAAQ;AACnB,WAAW,MAAM;AACjB,WAAW,sBAAsB;AACjC,WAAW,uBAAuB;AAClC,WAAW,sBAAsB;AACjC,WAAW,IAAI;AACf,WAAW,IAAI;AACf,WAAW,QAAQ;AACnB,cAAc,UAAU;AACxB,cAAc,MAAM;AACpB,cAAc,OAAO;AACrB,cAAc,SAAS;AACvB;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA,KAAK;;AAEL;AACA;;AAEA;AACA,iDAAiD;AACjD;AACA;AACA;AACA,KAAK;;AAEL;;AAEA;;AAEA;AACA;AACA;AACA;;AAEA;AACA,YAAY;AACZ;AACA;AACA;AACA;;AAEA;AACA,YAAY;AACZ;AACA;AACA;AACA;;AAEA;AACA,WAAW,IAAI;AACf,WAAW,IAAI;AACf,YAAY;AACZ;AACA;AACA,2CAA2C;AAC3C;AACA;AACA,KAAK;AACL;;AAEA;AACA,WAAW,OAAO;AAClB,WAAW,IAAI;AACf,WAAW,IAAI;AACf,YAAY;AACZ;AACA;;AAEA;AACA,mBAAmB;AACnB,KAAK;AACL;AACA;;AAEA,iDAAiD;AACjD;AACA;AACA;AACA,KAAK;;AAEL;;AAEA;;AAEA;;AAEA;AACA;AACA;AACA;;AAEA;;AAEA,qB;;;;;;AC7HA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA,gCAAgC;AAChC;AACA;AACA;AACA;;AAEA;AACA;AACA,iBAAiB,QAAQ;AACzB;AACA;AACA;AACA;AACA,GAAG;AACH;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,GAAG;AACH,kCAAkC;AAClC;AACA;AACA;;AAEA;AACA,EAAE;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AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA,aAAa;AACb;AACA;;AAEA,SAAS;AACT;AACA;;AAEA;;AAEA;AACA;;AAEA;AACA;;AAEA;;AAEA;;AAEA;AACA,aAAa,OAAO;AACpB,cAAc,OAAO;AACrB,cAAc,OAAO;AACrB,cAAc,YAAY;AAC1B;;AAEA,wB;;;;;;AC/LA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;;;;;;;ACpCA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;;;;;;;ACXA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,iBAAiB;AACjB,OAAO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;AACH;AACA;AACA;AACA,eAAe,SAAS;AACxB;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;;AAEA;AACA;AACA;;AAEA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA,GAAG;AACH,oBAAoB,SAAS;AAC7B;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA,KAAK;AACL;AACA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA,GAAG;AACH;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;;;;;;AC7SA;AACA,WAAW,UAAU;AACrB,WAAW,QAAQ;AACnB,WAAW,SAAS;AACpB,WAAW,OAAO;AAClB,cAAc,UAAU;AACxB,cAAc,QAAQ;AACtB,cAAc,SAAS;AACvB,cAAc,OAAO;AACrB,cAAc,OAAO;AACrB,cAAc,cAAc;AAC5B;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,WAAW,SAAS;AACpB,YAAY;AACZ;AACA;;AAEA;;AAEA;;AAEA;AACA;;AAEA;;AAEA,KAAK;;AAEL;AACA;;AAEA,KAAK;;AAEL;;AAEA;AACA,YAAY;AACZ;AACA;AACA;AACA;;AAEA;AACA,YAAY;AACZ;AACA;AACA;AACA;;AAEA;AACA,YAAY;AACZ;AACA;AACA;AACA;;AAEA;AACA,YAAY;AACZ;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,YAAY;AACZ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,YAAY;AACZ;AACA;;AAEA;;AAEA;AACA;;AAEA;;AAEA;AACA;AACA;;AAEA,KAAK;;AAEL;;AAEA;;AAEA;AACA;AACA,YAAY;AACZ;AACA;AACA;AACA;AACA;;AAEA;AACA,YAAY;AACZ;AACA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;AACA,kEAAkE;AAClE,SAAS;AACT;AACA;;AAEA;;AAEA;;AAEA;AACA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA,SAAS;;AAET;;AAEA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,WAAW,OAAO;AAClB,WAAW,OAAO;AAClB,WAAW,OAAO;AAClB;AACA,YAAY;AACZ;AACA;;AAEA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;;AAEA,SAAS;;AAET;AACA;AACA;AACA;AACA,KAAK;;AAEL;AACA;AACA;AACA;AACA;AACA,KAAK;;AAEL;;AAEA,6B;;;;;;AC9QA;;AAEA;AACA;;;;;;;ACHA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA,iBAAiB,SAAS;AAC1B;AACA;AACA;;AAEA;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA,KAAK;AACL;AACA,KAAK;AACL;AACA;AACA;;AAEA;AACA;;;;;;;AC/EA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT,OAAO;AACP;AACA;AACA,KAAK;;AAEL;;AAEA;AACA;AACA;AACA;;;;;;;AC/DA;AACA;AACA;;AAEA;AACA;AACA,uBAAuB,aAAa,EAAE;;AAEtC;AACA;AACA,WAAW,OAAO;AAClB,WAAW,sBAAsB;AACjC,WAAW,QAAQ;AACnB,WAAW,MAAM;AACjB,WAAW,sBAAsB;AACjC,WAAW,uBAAuB;AAClC,WAAW,sBAAsB;AACjC,cAAc,OAAO;AACrB,cAAc,QAAQ;AACtB,cAAc,sBAAsB;AACpC,cAAc,MAAM;AACpB,cAAc,sBAAsB;AACpC,cAAc,uBAAuB;AACrC,cAAc,sBAAsB;AACpC;AACA;;AAEA;;AAEA;AACA,oHAAoH;AACpH;;AAEA,uDAAuD,sBAAsB;;AAE7E;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;;AAEA;;;;;;;;AC9DA,gD;;;;;;ACAA,gD;;;;;;ACAA,gD;;;;;;ACAA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,WAAW,OAAO;AAClB,WAAW,OAAO;AAClB,WAAW,OAAO;AAClB,WAAW,OAAO;AAClB,WAAW,OAAO;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;;AAEA;;AAEA;;AAEA;AACA;AACA,YAAY;AACZ;AACA;;AAEA;AACA;;AAEA;;AAEA;AACA;AACA,YAAY;AACZ;AACA;;AAEA;;AAEA;;AAEA;AACA,YAAY;AACZ;AACA;;AAEA;AACA;AACA;AACA,KAAK;;AAEL;;AAEA;;AAEA;AACA;AACA;AACA;AACA,yBAAyB;AACzB;AACA;AACA,uCAAuC;AACvC;AACA;AACA;;;;;;;ACrHA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,E;;;;;;ACVA;;AAEA;AACA,2BAA2B,EAAE,SAAS,EAAE;;AAExC;AACA;AACA;;AAEA;AACA;AACA,WAAW,OAAO;AAClB,YAAY;AACZ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,WAAW,SAAS;AACpB,WAAW,UAAU;AACrB,WAAW,IAAI;AACf,WAAW,IAAI;AACf,cAAc,UAAU;AACxB,cAAc,SAAS;AACvB,cAAc,IAAI;AAClB,cAAc,IAAI;AAClB,cAAc,OAAO;AACrB,cAAc,OAAO;AACrB,cAAc,IAAI;AAClB,cAAc,cAAc;AAC5B;AACA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;AACA;AACA;AACA;;AAEA;;AAEA;AACA,YAAY;AACZ;AACA;AACA;AACA;;AAEA;AACA,YAAY;AACZ;AACA;AACA;AACA;AACA;;AAEA;AACA,YAAY;AACZ;AACA;AACA;AACA;;AAEA;AACA,WAAW,cAAc;AACzB,YAAY;AACZ;AACA;;AAEA;;AAEA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;AACA,YAAY;AACZ;AACA;AACA;AACA;;AAEA;AACA;AACA,aAAa;AACb;AACA;;A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;AAET;;AAEA;;AAEA;;AAEA;AACA;AACA,YAAY;AACZ;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,YAAY;AACZ;AACA;AACA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;AACA;;AAEA,SAAS;;AAET;AACA;;AAEA,SAAS;;AAET;AACA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;;AAET;AACA;AACA;AACA,aAAa;AACb;AACA,wCAAwC;AACxC,aAAa;AACb,SAAS;;AAET;;AAEA;AACA,4BAA4B,iCAAiC;;AAE7D;;AAEA;;AAEA;AACA,YAAY;AACZ;AACA;AACA;;AAEA;;AAEA;AACA,2BAA2B;;AAE3B;AACA;AACA;;AAEA;;AAEA;;AAEA;;AAEA;AACA;AACA,aAAa,OAAO;AACpB,cAAc,OAAO;AACrB,cAAc,OAAO;AACrB,cAAc,SAAS;AACvB,cAAc,OAAO;AACrB,cAAc,IAAI;AAClB,cAAc,OAAO;AACrB,cAAc,QAAQ;AACtB,cAAc,OAAO;AACrB,cAAc,OAAO;AACrB,cAAc,OAAO;AACrB,cAAc,OAAO;AACrB,cAAc,OAAO;AACrB,cAAc,OAAO;AACrB,G;;;;;;ACpgBA;;AAEA;AACA,WAAW,SAAS;AACpB,WAAW,UAAU;AACrB,WAAW,MAAM;AACjB,WAAW,OAAO;AAClB,WAAW,IAAI;AACf,WAAW,IAAI;AACf,YAAY;AACZ;AACA,cAAc,MAAM;AACpB;AACA;AACA;;AAEA;;AAEA;;AAEA;AACA;;AAEA;;AAEA;AACA;;AAEA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA,WAAW,SAAS;AACpB,YAAY;AACZ;AACA;;AAEA;AACA;AACA;;AAEA;;AAEA;;AAEA,oC","file":"ringcentral.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory(require(undefined), require(undefined), require(undefined));\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([\"pubnub\", \"es6-promise\", \"fetch-ponyfill\"], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"SDK\"] = factory(require(undefined), require(undefined), require(undefined));\n\telse\n\t\troot[\"RingCentral\"] = root[\"RingCentral\"] || {}, root[\"RingCentral\"][\"SDK\"] = factory(root[undefined], root[undefined], root[undefined]);\n})(this, function(__WEBPACK_EXTERNAL_MODULE_12__, __WEBPACK_EXTERNAL_MODULE_13__, __WEBPACK_EXTERNAL_MODULE_14__) {\nreturn \n\n\n// WEBPACK FOOTER //\n// webpack/universalModuleDefinition"," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\texports: {},\n \t\t\tid: moduleId,\n \t\t\tloaded: false\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.loaded = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"/build/\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(0);\n\n\n\n// WEBPACK FOOTER //\n// webpack/bootstrap 9170c9929c7a92918002","/**\n * @namespace RingCentral\n */\nvar objectAssign = require('object-assign');\nvar Cache = require(\"./core/Cache\");\nvar Client = require(\"./http/Client\");\nvar Externals = require(\"./core/Externals\");\nvar Platform = require(\"./platform/Platform\");\nvar Subscription = require(\"./subscription/Subscription\");\nvar CachedSubscription = require(\"./subscription/CachedSubscription\");\nvar Constants = require(\"./core/Constants\");\n\n/**\n * @constructor\n * @param {string} options.server\n * @param {string} options.appSecret\n * @param {string} options.appKey\n * @param {string} [options.cachePrefix]\n * @param {string} [options.appName]\n * @param {string} [options.appVersion]\n * @param {string} [options.redirectUri]\n * @param {PubNub} [options.PubNub]\n * @param {function(new:Promise)} [options.Promise]\n * @param {Storage} [options.localStorage]\n * @param {fetch} [options.fetch]\n * @param {function(new:Request)} [options.Request]\n * @param {function(new:Response)} [options.Response]\n * @param {function(new:Headers)} [options.Headers]\n * @param {int} [options.refreshDelayMs]\n * @param {int} [options.refreshHandicapMs]\n * @param {boolean} [options.clearCacheOnRefreshError]\n * @property {Externals} _externals\n * @property {Cache} _cache\n * @property {Client} _client\n * @property {Platform} _platform\n */\nfunction SDK(options) {\n\n /** @private */\n this._externals = new Externals(options);\n\n /** @private */\n this._cache = new Cache({\n externals: this._externals,\n prefix: options.cachePrefix\n });\n\n /** @private */\n this._client = new Client(this._externals);\n\n /** @private */\n this._platform = new Platform(objectAssign({}, options, {\n externals: this._externals,\n client: this._client,\n cache: this._cache\n }));\n\n}\n\nSDK.version = Constants.version;\n\nSDK.server = {\n sandbox: 'https://platform.devtest.ringcentral.com',\n production: 'https://platform.ringcentral.com'\n};\n\n/**\n * @return {Platform}\n */\nSDK.prototype.platform = function() {\n return this._platform;\n};\n\n/**\n * @return {Cache}\n */\nSDK.prototype.cache = function() {\n return this._cache;\n};\n\n/**\n * @param {int} [options.pollInterval]\n * @param {int} [options.renewHandicapMs]\n * @return {Subscription}\n */\nSDK.prototype.createSubscription = function(options) {\n return new Subscription(objectAssign({}, options, {\n externals: this._externals,\n platform: this._platform\n }));\n};\n\n/**\n * @param {string} options.cacheKey\n * @param {int} [options.pollInterval]\n * @param {int} [options.renewHandicapMs]\n * @return {CachedSubscription}\n */\nSDK.prototype.createCachedSubscription = function(options) {\n\n if (typeof arguments[0] === 'string') {\n options = {cacheKey: arguments[0].toString()};\n } else {\n options = options || {};\n }\n\n return new CachedSubscription(objectAssign({}, options, {\n externals: this._externals,\n platform: this._platform,\n cache: this._cache\n }));\n\n};\n\nSDK.handleLoginRedirect = function(origin, win) {\n\n win = win || window;\n\n var response = win.location.hash ? win.location.hash : win.location.search;\n var msg = {};\n msg[Constants.authResponseProperty] = response;\n win.opener.postMessage(msg, origin || win.location.origin);\n\n};\n\nmodule.exports = SDK;\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/SDK.js\n// module id = 0\n// module chunks = 0 1","/*\nobject-assign\n(c) Sindre Sorhus\n@license MIT\n*/\n\n'use strict';\n/* eslint-disable no-unused-vars */\nvar getOwnPropertySymbols = Object.getOwnPropertySymbols;\nvar hasOwnProperty = Object.prototype.hasOwnProperty;\nvar propIsEnumerable = Object.prototype.propertyIsEnumerable;\n\nfunction toObject(val) {\n\tif (val === null || val === undefined) {\n\t\tthrow new TypeError('Object.assign cannot be called with null or undefined');\n\t}\n\n\treturn Object(val);\n}\n\nfunction shouldUseNative() {\n\ttry {\n\t\tif (!Object.assign) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Detect buggy property enumeration order in older V8 versions.\n\n\t\t// https://bugs.chromium.org/p/v8/issues/detail?id=4118\n\t\tvar test1 = new String('abc'); // eslint-disable-line no-new-wrappers\n\t\ttest1[5] = 'de';\n\t\tif (Object.getOwnPropertyNames(test1)[0] === '5') {\n\t\t\treturn false;\n\t\t}\n\n\t\t// https://bugs.chromium.org/p/v8/issues/detail?id=3056\n\t\tvar test2 = {};\n\t\tfor (var i = 0; i < 10; i++) {\n\t\t\ttest2['_' + String.fromCharCode(i)] = i;\n\t\t}\n\t\tvar order2 = Object.getOwnPropertyNames(test2).map(function (n) {\n\t\t\treturn test2[n];\n\t\t});\n\t\tif (order2.join('') !== '0123456789') {\n\t\t\treturn false;\n\t\t}\n\n\t\t// https://bugs.chromium.org/p/v8/issues/detail?id=3056\n\t\tvar test3 = {};\n\t\t'abcdefghijklmnopqrst'.split('').forEach(function (letter) {\n\t\t\ttest3[letter] = letter;\n\t\t});\n\t\tif (Object.keys(Object.assign({}, test3)).join('') !==\n\t\t\t\t'abcdefghijklmnopqrst') {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn true;\n\t} catch (err) {\n\t\t// We don't expect any of the above to throw, but better to be safe.\n\t\treturn false;\n\t}\n}\n\nmodule.exports = shouldUseNative() ? Object.assign : function (target, source) {\n\tvar from;\n\tvar to = toObject(target);\n\tvar symbols;\n\n\tfor (var s = 1; s < arguments.length; s++) {\n\t\tfrom = Object(arguments[s]);\n\n\t\tfor (var key in from) {\n\t\t\tif (hasOwnProperty.call(from, key)) {\n\t\t\t\tto[key] = from[key];\n\t\t\t}\n\t\t}\n\n\t\tif (getOwnPropertySymbols) {\n\t\t\tsymbols = getOwnPropertySymbols(from);\n\t\t\tfor (var i = 0; i < symbols.length; i++) {\n\t\t\t\tif (propIsEnumerable.call(from, symbols[i])) {\n\t\t\t\t\tto[symbols[i]] = from[symbols[i]];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn to;\n};\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./~/object-assign/index.js\n// module id = 1\n// module chunks = 0 1","/**\n * @param {Externals} options.externals\n * @param {string} [options.prefix]\n * @property {Externals} _externals\n */\nfunction Cache(options) {\n\n /** @private */\n this._prefix = options.prefix || Cache.defaultPrefix;\n\n /** @private */\n this._externals = options.externals;\n\n}\n\nCache.defaultPrefix = 'rc-';\n\nCache.prototype.setItem = function(key, data) {\n this._externals.localStorage[this._prefixKey(key)] = JSON.stringify(data);\n return this;\n};\n\nCache.prototype.removeItem = function(key) {\n delete this._externals.localStorage[this._prefixKey(key)];\n return this;\n};\n\nCache.prototype.getItem = function(key) {\n var item = this._externals.localStorage[this._prefixKey(key)];\n if (!item) return null;\n return JSON.parse(item);\n};\n\nCache.prototype.clean = function() {\n\n for (var key in this._externals.localStorage) {\n\n /* istanbul ignore next */\n if (!this._externals.localStorage.hasOwnProperty(key)) continue;\n\n if (key.indexOf(this._prefix) === 0) {\n delete this._externals.localStorage[key];\n }\n\n }\n\n return this;\n\n};\n\nCache.prototype._prefixKey = function(key) {\n return this._prefix + key;\n};\n\nmodule.exports = Cache;\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/core/Cache.js\n// module id = 2\n// module chunks = 0 1","var isPlainObject = require(\"is-plain-object\");\nvar EventEmitter = require(\"events\").EventEmitter;\nvar ApiResponse = require(\"./ApiResponse\");\nvar qs = require(\"querystring\");\n\nfunction 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 * @param {Externals} externals\n * @property {Externals} _externals\n */\nfunction Client(externals) {\n\n EventEmitter.call(this);\n\n /** @private */\n this._externals = externals;\n\n this.events = {\n beforeRequest: 'beforeRequest',\n requestSuccess: 'requestSuccess',\n requestError: 'requestError'\n };\n\n}\n\nClient._allowedMethods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS', 'HEAD'];\n\nClient.prototype = Object.create(EventEmitter.prototype);\n\n/**\n * @param {Request} request\n * @return {Promise}\n */\nClient.prototype.sendRequest = function(request) {\n\n var apiResponse = new ApiResponse({\n externals: this._externals,\n request: request\n });\n\n return (new this._externals.Promise(function(resolve) {\n\n //TODO Stop request if listeners return false\n this.emit(this.events.beforeRequest, apiResponse);\n\n resolve(this._loadResponse(request));\n\n }.bind(this))).then(function(response) {\n\n return apiResponse.receiveResponse(response);\n\n }).then(function() {\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 }.bind(this)).catch(function(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 }.bind(this));\n\n};\n\n/**\n * @param {Request} request\n * @return {Promise}\n * @private\n */\nClient.prototype._loadResponse = function(request) {\n return this._externals.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 */\nClient.prototype.makeError = function(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 * @param {object} [init.credentials]\n * @param {object} [init.mode]\n * @return {Request}\n */\nClient.prototype.createRequest = function(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 init.method = init.method.toUpperCase();\n if (init.method && Client._allowedMethods.indexOf(init.method) < 0) {\n throw new Error('Method has wrong value: ' + init.method);\n }\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 ? '&' : '?') + qs.stringify(init.query);\n }\n\n if (!(findHeaderName('Accept', init.headers))) {\n init.headers.Accept = ApiResponse._jsonContentType;\n }\n\n // Serialize body\n if (isPlainObject(init.body) || !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 if ((init.method === 'GET' || init.method === 'HEAD') && !!init.body) {\n // oddly setting body to null still result in TypeError in phantomjs\n init.body = undefined;\n } else {\n init.body = JSON.stringify(init.body);\n }\n\n } else if (contentType.indexOf(ApiResponse._urlencodedContentType) > -1) {\n init.body = qs.stringify(init.body);\n }\n\n }\n\n // Create a request with encoded body\n var req = new this._externals.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 * @typedef {object} IApiError\n * @property {string} stack\n * @property {string} originalMessage\n * @property {ApiResponse} apiResponse\n */\n\nmodule.exports = Client;\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/http/Client.js\n// module id = 3\n// module chunks = 0 1","/*!\n * is-plain-object \n *\n * Copyright (c) 2014-2017, Jon Schlinkert.\n * Released under the MIT License.\n */\n\n'use strict';\n\nvar isObject = require('isobject');\n\nfunction isObjectObject(o) {\n return isObject(o) === true\n && Object.prototype.toString.call(o) === '[object Object]';\n}\n\nmodule.exports = function isPlainObject(o) {\n var ctor,prot;\n\n if (isObjectObject(o) === false) return false;\n\n // If has modified constructor\n ctor = o.constructor;\n if (typeof ctor !== 'function') return false;\n\n // If has modified prototype\n prot = ctor.prototype;\n if (isObjectObject(prot) === false) return false;\n\n // If constructor does not have an Object-specific method\n if (prot.hasOwnProperty('isPrototypeOf') === false) {\n return false;\n }\n\n // Most likely a plain Object\n return true;\n};\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./~/is-plain-object/index.js\n// module id = 4\n// module chunks = 0 1","/*!\n * isobject \n *\n * Copyright (c) 2014-2017, Jon Schlinkert.\n * Released under the MIT License.\n */\n\n'use strict';\n\nmodule.exports = function isObject(val) {\n return val != null && typeof val === 'object' && Array.isArray(val) === false;\n};\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./~/isobject/index.js\n// module id = 5\n// module chunks = 0 1","// Copyright Joyent, Inc. and other Node contributors.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a\n// copy of this software and associated documentation files (the\n// \"Software\"), to deal in the Software without restriction, including\n// without limitation the rights to use, copy, modify, merge, publish,\n// distribute, sublicense, and/or sell copies of the Software, and to permit\n// persons to whom the Software is furnished to do so, subject to the\n// following conditions:\n//\n// The above copyright notice and this permission notice shall be included\n// in all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\n// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN\n// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,\n// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE\n// USE OR OTHER DEALINGS IN THE SOFTWARE.\n\nfunction EventEmitter() {\n this._events = this._events || {};\n this._maxListeners = this._maxListeners || undefined;\n}\nmodule.exports = EventEmitter;\n\n// Backwards-compat with node 0.10.x\nEventEmitter.EventEmitter = EventEmitter;\n\nEventEmitter.prototype._events = undefined;\nEventEmitter.prototype._maxListeners = undefined;\n\n// By default EventEmitters will print a warning if more than 10 listeners are\n// added to it. This is a useful default which helps finding memory leaks.\nEventEmitter.defaultMaxListeners = 10;\n\n// Obviously not all Emitters should be limited to 10. This function allows\n// that to be increased. Set to zero for unlimited.\nEventEmitter.prototype.setMaxListeners = function(n) {\n if (!isNumber(n) || n < 0 || isNaN(n))\n throw TypeError('n must be a positive number');\n this._maxListeners = n;\n return this;\n};\n\nEventEmitter.prototype.emit = function(type) {\n var er, handler, len, args, i, listeners;\n\n if (!this._events)\n this._events = {};\n\n // If there is no 'error' event listener then throw.\n if (type === 'error') {\n if (!this._events.error ||\n (isObject(this._events.error) && !this._events.error.length)) {\n er = arguments[1];\n if (er instanceof Error) {\n throw er; // Unhandled 'error' event\n } else {\n // At least give some kind of context to the user\n var err = new Error('Uncaught, unspecified \"error\" event. (' + er + ')');\n err.context = er;\n throw err;\n }\n }\n }\n\n handler = this._events[type];\n\n if (isUndefined(handler))\n return false;\n\n if (isFunction(handler)) {\n switch (arguments.length) {\n // fast cases\n case 1:\n handler.call(this);\n break;\n case 2:\n handler.call(this, arguments[1]);\n break;\n case 3:\n handler.call(this, arguments[1], arguments[2]);\n break;\n // slower\n default:\n args = Array.prototype.slice.call(arguments, 1);\n handler.apply(this, args);\n }\n } else if (isObject(handler)) {\n args = Array.prototype.slice.call(arguments, 1);\n listeners = handler.slice();\n len = listeners.length;\n for (i = 0; i < len; i++)\n listeners[i].apply(this, args);\n }\n\n return true;\n};\n\nEventEmitter.prototype.addListener = function(type, listener) {\n var m;\n\n if (!isFunction(listener))\n throw TypeError('listener must be a function');\n\n if (!this._events)\n this._events = {};\n\n // To avoid recursion in the case that type === \"newListener\"! Before\n // adding it to the listeners, first emit \"newListener\".\n if (this._events.newListener)\n this.emit('newListener', type,\n isFunction(listener.listener) ?\n listener.listener : listener);\n\n if (!this._events[type])\n // Optimize the case of one listener. Don't need the extra array object.\n this._events[type] = listener;\n else if (isObject(this._events[type]))\n // If we've already got an array, just append.\n this._events[type].push(listener);\n else\n // Adding the second element, need to change to array.\n this._events[type] = [this._events[type], listener];\n\n // Check for listener leak\n if (isObject(this._events[type]) && !this._events[type].warned) {\n if (!isUndefined(this._maxListeners)) {\n m = this._maxListeners;\n } else {\n m = EventEmitter.defaultMaxListeners;\n }\n\n if (m && m > 0 && this._events[type].length > m) {\n this._events[type].warned = true;\n console.error('(node) warning: possible EventEmitter memory ' +\n 'leak detected. %d listeners added. ' +\n 'Use emitter.setMaxListeners() to increase limit.',\n this._events[type].length);\n if (typeof console.trace === 'function') {\n // not supported in IE 10\n console.trace();\n }\n }\n }\n\n return this;\n};\n\nEventEmitter.prototype.on = EventEmitter.prototype.addListener;\n\nEventEmitter.prototype.once = function(type, listener) {\n if (!isFunction(listener))\n throw TypeError('listener must be a function');\n\n var fired = false;\n\n function g() {\n this.removeListener(type, g);\n\n if (!fired) {\n fired = true;\n listener.apply(this, arguments);\n }\n }\n\n g.listener = listener;\n this.on(type, g);\n\n return this;\n};\n\n// emits a 'removeListener' event iff the listener was removed\nEventEmitter.prototype.removeListener = function(type, listener) {\n var list, position, length, i;\n\n if (!isFunction(listener))\n throw TypeError('listener must be a function');\n\n if (!this._events || !this._events[type])\n return this;\n\n list = this._events[type];\n length = list.length;\n position = -1;\n\n if (list === listener ||\n (isFunction(list.listener) && list.listener === listener)) {\n delete this._events[type];\n if (this._events.removeListener)\n this.emit('removeListener', type, listener);\n\n } else if (isObject(list)) {\n for (i = length; i-- > 0;) {\n if (list[i] === listener ||\n (list[i].listener && list[i].listener === listener)) {\n position = i;\n break;\n }\n }\n\n if (position < 0)\n return this;\n\n if (list.length === 1) {\n list.length = 0;\n delete this._events[type];\n } else {\n list.splice(position, 1);\n }\n\n if (this._events.removeListener)\n this.emit('removeListener', type, listener);\n }\n\n return this;\n};\n\nEventEmitter.prototype.removeAllListeners = function(type) {\n var key, listeners;\n\n if (!this._events)\n return this;\n\n // not listening for removeListener, no need to emit\n if (!this._events.removeListener) {\n if (arguments.length === 0)\n this._events = {};\n else if (this._events[type])\n delete this._events[type];\n return this;\n }\n\n // emit removeListener for all listeners on all events\n if (arguments.length === 0) {\n for (key in this._events) {\n if (key === 'removeListener') continue;\n this.removeAllListeners(key);\n }\n this.removeAllListeners('removeListener');\n this._events = {};\n return this;\n }\n\n listeners = this._events[type];\n\n if (isFunction(listeners)) {\n this.removeListener(type, listeners);\n } else if (listeners) {\n // LIFO order\n while (listeners.length)\n this.removeListener(type, listeners[listeners.length - 1]);\n }\n delete this._events[type];\n\n return this;\n};\n\nEventEmitter.prototype.listeners = function(type) {\n var ret;\n if (!this._events || !this._events[type])\n ret = [];\n else if (isFunction(this._events[type]))\n ret = [this._events[type]];\n else\n ret = this._events[type].slice();\n return ret;\n};\n\nEventEmitter.prototype.listenerCount = function(type) {\n if (this._events) {\n var evlistener = this._events[type];\n\n if (isFunction(evlistener))\n return 1;\n else if (evlistener)\n return evlistener.length;\n }\n return 0;\n};\n\nEventEmitter.listenerCount = function(emitter, type) {\n return emitter.listenerCount(type);\n};\n\nfunction isFunction(arg) {\n return typeof arg === 'function';\n}\n\nfunction isNumber(arg) {\n return typeof arg === 'number';\n}\n\nfunction isObject(arg) {\n return typeof arg === 'object' && arg !== null;\n}\n\nfunction isUndefined(arg) {\n return arg === void 0;\n}\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./~/events/events.js\n// module id = 6\n// module chunks = 0 1","/**\n * @param {Externals} options.externals\n * @param {Request} [options.request]\n * @param {Response} [options.response]\n * @param {string} [options.responseText]\n * @property {Externals} _externals\n * @property {Request} _request\n * @property {Response} _response\n * @property {string} _text\n * @property {object} _json\n * @property {ApiResponse[]} _multipart\n */\nfunction ApiResponse(options) {\n\n /** @private */\n this._externals = options.externals;\n\n /** @private */\n this._request = options.request;\n\n /** @private */\n this._response = options.response;\n\n /** @private */\n this._text = options.responseText || '';\n\n /** @private */\n this._json = null;\n\n /** @private */\n this._multipart = [];\n\n}\n\nApiResponse._contentType = 'Content-Type';\nApiResponse._jsonContentType = 'application/json';\nApiResponse._multipartContentType = 'multipart/mixed';\nApiResponse._urlencodedContentType = 'application/x-www-form-urlencoded';\nApiResponse._headerSeparator = ':';\nApiResponse._bodySeparator = '\\n\\n';\nApiResponse._boundarySeparator = '--';\nApiResponse._unauthorizedStatus = 401;\nApiResponse._rateLimitStatus = 429;\n\n/**\n * @param {Response} response\n * @return {Promise}\n */\nApiResponse.prototype.receiveResponse = function(response) {\n\n this._response = response;\n\n return (new this._externals.Promise(function(resolve) {\n\n // Ignore if not textual type\n if (!this._isMultipart() && !this._isJson()) return resolve('');\n\n return resolve(this.response().text());\n\n }.bind(this))).then(function(text) {\n\n this._text = text;\n return text;\n\n }.bind(this));\n\n};\n\n/**\n * @return {Response}\n */\nApiResponse.prototype.response = function() {\n return this._response;\n};\n\n/**\n * @return {Request}\n */\nApiResponse.prototype.request = function() {\n return this._request;\n};\n\n/**\n * @return {boolean}\n */\nApiResponse.prototype.ok = function() {\n return this._response && this._response.ok;\n};\n\n/**\n * @return {string}\n */\nApiResponse.prototype.text = function() {\n // Since we read text only in case JSON or Multipart\n if (!this._isJson() && !this._isMultipart()) throw new Error('Response is not text');\n return this._text;\n};\n\n/**\n * @return {object}\n */\nApiResponse.prototype.json = function() {\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 */\nApiResponse.prototype.error = function(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 * If it is not known upfront what would be the response, client code can treat any response as multipart\n * @return {ApiResponse[]}\n */\nApiResponse.prototype.toMultipart = function() {\n if (!this._isMultipart()) return [this];\n return this.multipart();\n};\n\n/**\n * @return {ApiResponse[]}\n */\nApiResponse.prototype.multipart = function() {\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;\n\n try {\n boundary = this._getContentType().match(/boundary=([^;]+)/i)[1];\n } catch (e) {\n throw new Error('Cannot find boundary');\n }\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 = this._create(parts.shift(), this._response.status, this._response.statusText).json();\n\n // Step 3. Parse all other parts\n\n this._multipart = parts.map(function(part, i) {\n\n var status = statusInfo.response[i].status;\n\n return this._create(part, status);\n\n }.bind(this));\n\n }\n\n return this._multipart;\n\n};\n\n/**\n * @private\n */\nApiResponse.prototype._isContentType = function(contentType) {\n return this._getContentType().indexOf(contentType) > -1;\n};\n\n/**\n * @private\n */\nApiResponse.prototype._getContentType = function() {\n return this._response.headers.get(ApiResponse._contentType) || '';\n};\n\n/**\n * @private\n */\nApiResponse.prototype._isMultipart = function() {\n return this._isContentType(ApiResponse._multipartContentType);\n};\n\n/**\n * @private\n */\nApiResponse.prototype._isJson = function() {\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 * @private\n * @return {ApiResponse}\n */\nApiResponse.prototype._create = function(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 this._externals.Headers(),\n headersAndBody = text.split(ApiResponse._bodySeparator),\n headersText = (headersAndBody.length > 1) ? headersAndBody.shift() : '';\n\n text = headersAndBody.length > 0 ? headersAndBody.join(ApiResponse._bodySeparator) : null;\n\n (headersText || '')\n .split('\\n')\n .forEach(function(header) {\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 var response = new this._externals.Response(text, {\n headers: headers,\n status: status,\n statusText: statusText\n });\n\n return new ApiResponse({\n externals: this._externals,\n request: null,\n response: response,\n responseText: text\n });\n\n};\n\nmodule.exports = ApiResponse;\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/http/ApiResponse.js\n// module id = 7\n// module chunks = 0 1","'use strict';\n\nexports.decode = exports.parse = require('./decode');\nexports.encode = exports.stringify = require('./encode');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./~/querystring/index.js\n// module id = 8\n// module chunks = 0 1","// Copyright Joyent, Inc. and other Node contributors.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a\n// copy of this software and associated documentation files (the\n// \"Software\"), to deal in the Software without restriction, including\n// without limitation the rights to use, copy, modify, merge, publish,\n// distribute, sublicense, and/or sell copies of the Software, and to permit\n// persons to whom the Software is furnished to do so, subject to the\n// following conditions:\n//\n// The above copyright notice and this permission notice shall be included\n// in all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\n// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN\n// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,\n// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE\n// USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n'use strict';\n\n// If obj.hasOwnProperty has been overridden, then calling\n// obj.hasOwnProperty(prop) will break.\n// See: https://github.com/joyent/node/issues/1707\nfunction hasOwnProperty(obj, prop) {\n return Object.prototype.hasOwnProperty.call(obj, prop);\n}\n\nmodule.exports = function(qs, sep, eq, options) {\n sep = sep || '&';\n eq = eq || '=';\n var obj = {};\n\n if (typeof qs !== 'string' || qs.length === 0) {\n return obj;\n }\n\n var regexp = /\\+/g;\n qs = qs.split(sep);\n\n var maxKeys = 1000;\n if (options && typeof options.maxKeys === 'number') {\n maxKeys = options.maxKeys;\n }\n\n var len = qs.length;\n // maxKeys <= 0 means that we should not limit keys count\n if (maxKeys > 0 && len > maxKeys) {\n len = maxKeys;\n }\n\n for (var i = 0; i < len; ++i) {\n var x = qs[i].replace(regexp, '%20'),\n idx = x.indexOf(eq),\n kstr, vstr, k, v;\n\n if (idx >= 0) {\n kstr = x.substr(0, idx);\n vstr = x.substr(idx + 1);\n } else {\n kstr = x;\n vstr = '';\n }\n\n k = decodeURIComponent(kstr);\n v = decodeURIComponent(vstr);\n\n if (!hasOwnProperty(obj, k)) {\n obj[k] = v;\n } else if (Array.isArray(obj[k])) {\n obj[k].push(v);\n } else {\n obj[k] = [obj[k], v];\n }\n }\n\n return obj;\n};\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./~/querystring/decode.js\n// module id = 9\n// module chunks = 0 1","// Copyright Joyent, Inc. and other Node contributors.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a\n// copy of this software and associated documentation files (the\n// \"Software\"), to deal in the Software without restriction, including\n// without limitation the rights to use, copy, modify, merge, publish,\n// distribute, sublicense, and/or sell copies of the Software, and to permit\n// persons to whom the Software is furnished to do so, subject to the\n// following conditions:\n//\n// The above copyright notice and this permission notice shall be included\n// in all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\n// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN\n// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,\n// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE\n// USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n'use strict';\n\nvar stringifyPrimitive = function(v) {\n switch (typeof v) {\n case 'string':\n return v;\n\n case 'boolean':\n return v ? 'true' : 'false';\n\n case 'number':\n return isFinite(v) ? v : '';\n\n default:\n return '';\n }\n};\n\nmodule.exports = function(obj, sep, eq, name) {\n sep = sep || '&';\n eq = eq || '=';\n if (obj === null) {\n obj = undefined;\n }\n\n if (typeof obj === 'object') {\n return Object.keys(obj).map(function(k) {\n var ks = encodeURIComponent(stringifyPrimitive(k)) + eq;\n if (Array.isArray(obj[k])) {\n return obj[k].map(function(v) {\n return ks + encodeURIComponent(stringifyPrimitive(v));\n }).join(sep);\n } else {\n return ks + encodeURIComponent(stringifyPrimitive(obj[k]));\n }\n }).join(sep);\n\n }\n\n if (!name) return '';\n return encodeURIComponent(stringifyPrimitive(name)) + eq +\n encodeURIComponent(stringifyPrimitive(obj));\n};\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./~/querystring/encode.js\n// module id = 10\n// module chunks = 0 1","var pubnub = require(\"pubnub\");\nvar es6Promise = require(\"es6-promise\");\nvar FetchPonyfill = require(\"fetch-ponyfill\");\n\nvar root = (typeof window !== \"undefined\" && window) ||\n (typeof global !== \"undefined\" && global) ||\n (function(){ return this; })();\n\n/**\n * @constructor\n * @param {PubNub} [options.PubNub]\n * @param {function(new:Promise)} [options.Promise]\n * @param {Storage} [options.localStorage]\n * @param {fetch} [options.fetch]\n * @param {function(new:Request)} [options.Request]\n * @param {function(new:Response)} [options.Response]\n * @param {function(new:Headers)} [options.Headers]\n * @property {PubNub} PubNub\n * @property {Storage} localStorage\n * @property {function(new:Promise)} Promise\n * @property {fetch} fetch\n * @property {function(new:Request)} Request\n * @property {function(new:Response)} Response\n * @property {function(new:Headers)} Headers\n */\nfunction Externals(options) {\n\n options = options || {};\n\n this.PubNub = options.PubNub || root.PubNub || pubnub;\n this.localStorage = options.localStorage || ((typeof root.localStorage !== 'undefined') ? root.localStorage : {});\n this.Promise = options.Promise || root.Promise || (es6Promise && es6Promise.Promise);\n\n var fetchPonyfill = FetchPonyfill ? FetchPonyfill({Promise: this.Promise}) : {};\n\n this.fetch = options.fetch || root.fetch || fetchPonyfill.fetch;\n this.Request = options.Request || root.Request || fetchPonyfill.Request;\n this.Response = options.Response || root.Response || fetchPonyfill.Response;\n this.Headers = options.Headers || root.Headers || fetchPonyfill.Headers;\n\n /* istanbul ignore next */\n if (!this.fetch || !this.Response || !this.Request || !this.Headers) {\n throw new Error('Fetch API is missing');\n }\n\n /* istanbul ignore next */\n if (!this.Promise) {\n throw new Error('Promise is missing');\n }\n\n /* istanbul ignore next */\n if (!this.localStorage) {\n throw new Error('LocalStorage is missing');\n }\n\n /* istanbul ignore next */\n if (!this.PubNub) {\n throw new Error('PubNub is missing');\n }\n\n}\n\nmodule.exports = Externals;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/core/Externals.js\n// module id = 11\n// module chunks = 0 1","module.exports = __WEBPACK_EXTERNAL_MODULE_12__;\n\n\n//////////////////\n// WEBPACK FOOTER\n// external {\"amd\":\"pubnub\"}\n// module id = 12\n// module chunks = 0 1","module.exports = __WEBPACK_EXTERNAL_MODULE_13__;\n\n\n//////////////////\n// WEBPACK FOOTER\n// external {\"amd\":\"es6-promise\"}\n// module id = 13\n// module chunks = 0 1","module.exports = __WEBPACK_EXTERNAL_MODULE_14__;\n\n\n//////////////////\n// WEBPACK FOOTER\n// external {\"amd\":\"fetch-ponyfill\"}\n// module id = 14\n// module chunks = 0 1","var EventEmitter = require(\"events\").EventEmitter;\nvar qs = require(\"querystring\");\nvar objectAssign = require('object-assign');\nvar Auth = require(\"./Auth\");\nvar Constants = require(\"../core/Constants\");\nvar ApiResponse = require(\"../http/ApiResponse\");\n\n/**\n * @constructor\n * @param {string} options.server\n * @param {string} options.appSecret\n * @param {string} options.appKey\n * @param {string} [options.appName]\n * @param {string} [options.appVersion]\n * @param {string} [options.redirectUri]\n * @param {int} [options.refreshDelayMs]\n * @param {int} [options.refreshHandicapMs]\n * @param {boolean} [options.clearCacheOnRefreshError]\n * @param {Externals} options.externals\n * @param {Cache} options.cache\n * @param {Client} options.client\n * @property {Externals} _externals\n * @property {Cache} _cache\n * @property {Client} _client\n * @property {Promise} _refreshPromise\n * @property {Auth} _auth\n */\nfunction Platform(options) {\n\n EventEmitter.call(this);\n\n this.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 rateLimitError: 'rateLimitError'\n };\n\n options = options || {};\n\n /** @private */\n this._server = options.server;\n\n /** @private */\n this._appKey = options.appKey;\n\n /** @private */\n this._appSecret = options.appSecret;\n\n /** @private */\n this._redirectUri = options.redirectUri || '';\n\n /** @private */\n this._refreshDelayMs = options.refreshDelayMs || 100;\n\n /** @private */\n this._clearCacheOnRefreshError = typeof options.clearCacheOnRefreshError !== 'undefined' ?\n options.clearCacheOnRefreshError :\n true;\n\n /** @private */\n this._userAgent = (options.appName ?\n (options.appName + (options.appVersion ? '/' + options.appVersion : '')) + ' ' :\n '') + 'RCJSSDK/' + Constants.version;\n\n /** @private */\n this._externals = options.externals;\n\n /** @private */\n this._cache = options.cache;\n\n /** @private */\n this._client = options.client;\n\n /** @private */\n this._knownPrefixes = options.knownPrefixes || Platform._knownPrefixes;\n\n\n /** @private */\n this._refreshPromise = null;\n\n /** @private */\n this._auth = new Auth({\n cache: this._cache,\n cacheId: Platform._cacheId,\n refreshHandicapMs: options.refreshHandicapMs\n });\n\n}\n\nPlatform._urlPrefix = '/restapi';\nPlatform._apiVersion = 'v1.0';\nPlatform._knownPrefixes = ['/rcvideo'];\nPlatform._tokenEndpoint = '/restapi/oauth/token';\nPlatform._revokeEndpoint = '/restapi/oauth/revoke';\nPlatform._authorizeEndpoint = '/restapi/oauth/authorize';\nPlatform._cacheId = 'platform';\n\nPlatform.prototype = Object.create(EventEmitter.prototype);\n\nPlatform.prototype.delay = function(timeout) {\n return new this._externals.Promise(function(resolve, reject) {\n setTimeout(function() {\n resolve(null);\n }, timeout);\n });\n};\n\n/**\n * @return {Auth}\n */\nPlatform.prototype.auth = function() {\n return this._auth;\n};\n\n/**\n * @return {Client}\n */\nPlatform.prototype.client = function() {\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 */\nPlatform.prototype.createUrl = function(path, options) {\n\n path = path || '';\n options = options || {};\n\n var builtUrl = '',\n hasHttp = path.indexOf('http://') != -1 || path.indexOf('https://') != -1,\n alreadyPrefixed = this._knownPrefixes.some(function(prefix) {\n return path.indexOf(prefix) === 0;\n });\n\n if (options.addServer && !hasHttp) builtUrl += this._server;\n\n if (path.indexOf(Platform._urlPrefix) == -1 && !hasHttp && !alreadyPrefixed) {\n builtUrl += Platform._urlPrefix + '/' + Platform._apiVersion;\n }\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] Overrides default RedirectURI\n * @param {string} [options.state]\n * @param {string} [options.brandId]\n * @param {string} [options.display]\n * @param {string} [options.prompt]\n * @param {boolean} [options.implicit] Use Implicit Grant flow\n * @return {string}\n */\nPlatform.prototype.loginUrl = function(options) {\n\n options = options || {};\n\n return this.createUrl(Platform._authorizeEndpoint + '?' + qs.stringify({\n 'response_type': options.implicit ? 'token' : 'code',\n 'redirect_uri': options.redirectUri || this._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 */\nPlatform.prototype.parseLoginRedirect = function(url) {\n\n function getParts(url, separator) {\n return url.split(separator).reverse()[0];\n }\n\n var response = (url.indexOf('#') === 0 && getParts(url, '#')) ||\n (url.indexOf('?') === 0 && getParts(url, '?')) ||\n null;\n\n if (!response) throw new Error('Unable to parse response');\n\n var queryString = qs.parse(response);\n\n if (!queryString) throw new Error('Unable to parse response');\n\n var error = queryString.error_description || queryString.error;\n\n if (error) {\n var e = new Error(error);\n e.error = queryString.error;\n throw e;\n }\n\n return queryString;\n\n};\n\n/**\n * Convenience method to handle 3-legged OAuth\n *\n * Attention! This is an experimental method and it's signature and behavior may change without notice.\n *\n * @experimental\n * @param {string} options.url\n * @param {number} [options.width]\n * @param {number} [options.height]\n * @param {object} [options.login] additional options for login()\n * @param {string} [options.origin]\n * @param {string} [options.property] name of window.postMessage's event data property\n * @param {string} [options.target] target for window.open()\n * @return {Promise}\n */\nPlatform.prototype.loginWindow = function(options) {\n\n return new this._externals.Promise(function(resolve, reject) {\n\n if (typeof window === 'undefined') throw new Error('This method can be used only in browser');\n\n if (!options.url) throw new Error('Missing mandatory URL parameter');\n\n options = options || {};\n options.width = options.width || 400;\n options.height = options.height || 600;\n options.origin = options.origin || window.location.origin;\n options.property = options.property || Constants.authResponseProperty;\n options.target = options.target || '_blank';\n\n var dualScreenLeft = window.screenLeft !== undefined ? window.screenLeft : screen.left;\n var dualScreenTop = window.screenTop !== undefined ? window.screenTop : screen.top;\n\n var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width;\n var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;\n\n var left = ((width / 2) - (options.width / 2)) + dualScreenLeft;\n var top = ((height / 2) - (options.height / 2)) + dualScreenTop;\n var win = window.open(options.url, '_blank', (options.target == '_blank') ? 'scrollbars=yes, status=yes, width=' + options.width + ', height=' + options.height + ', left=' + left + ', top=' + top : '');\n\n if (!win) {\n throw new Error('Could not open login window. Please allow popups for this site');\n }\n\n if (win.focus) win.focus();\n\n var eventMethod = window.addEventListener ? 'addEventListener' : 'attachEvent';\n var eventRemoveMethod = eventMethod == 'addEventListener' ? 'removeEventListener' : 'detachEvent';\n var messageEvent = eventMethod == 'addEventListener' ? 'message' : 'onmessage';\n\n var eventListener = function(e) {\n\n try {\n\n if (e.origin != options.origin) return;\n if (!e.data || !e.data[options.property]) return; // keep waiting\n\n win.close();\n window[eventRemoveMethod](messageEvent, eventListener);\n\n\n var loginOptions = this.parseLoginRedirect(e.data[options.property]);\n\n if (!loginOptions.code && !loginOptions.access_token) throw new Error('No authorization code or token');\n\n resolve(loginOptions);\n\n /* jshint -W002 */\n } catch (e) {\n reject(e);\n }\n\n }.bind(this);\n\n window[eventMethod](messageEvent, eventListener, false);\n\n }.bind(this));\n\n};\n\n/**\n * @return {Promise}\n */\nPlatform.prototype.loggedIn = function() {\n\n return this.ensureLoggedIn().then(function() {\n return true;\n }).catch(function() {\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 * @param {string} [options.accessTokenTtl]\n * @param {string} [options.refreshTokenTtl]\n * @param {string} [options.access_token]\n * @returns {Promise}\n */\nPlatform.prototype.login = function(options) {\n\n return (new this._externals.Promise(function(resolve) {\n\n options = options || {};\n\n this.emit(this.events.beforeLogin);\n\n var body = {};\n\n if (options.access_token) {\n\n //TODO Potentially make a request to /oauth/tokeninfo\n return resolve(options);\n\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 || this._redirectUri;\n //body.client_id = this.getCredentials().key; // not needed\n\n }\n\n if (options.endpointId) body.endpoint_id = options.endpointId;\n if (options.accessTokenTtl) body.access_token_ttl = options.accessTokenTtl;\n if (options.refreshTokenTtl) body.refresh_token_ttl = options.refreshTokenTtl;\n\n resolve(this._tokenRequest(Platform._tokenEndpoint, body));\n\n }.bind(this))).then(function(res) {\n\n var apiResponse = res.json ? res : null;\n var json = apiResponse && apiResponse.json() || res;\n\n this._auth.setData(json);\n\n this.emit(this.events.loginSuccess, apiResponse);\n\n return apiResponse;\n\n }.bind(this)).catch(function(e) {\n\n if (this._clearCacheOnRefreshError) {\n this._cache.clean();\n }\n\n this.emit(this.events.loginError, e);\n\n throw e;\n\n }.bind(this));\n\n};\n\n/**\n * @returns {Promise}\n * @private\n */\nPlatform.prototype._refresh = function() {\n\n return this.delay(this._refreshDelayMs).then(function() {\n\n this.emit(this.events.beforeRefresh);\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\n return this._tokenRequest(Platform._tokenEndpoint, {\n \"grant_type\": \"refresh_token\",\n \"refresh_token\": this._auth.refreshToken(),\n \"access_token_ttl\": this._auth.data().expires_in + 1,\n \"refresh_token_ttl\": this._auth.data().refresh_token_expires_in + 1\n });\n\n }.bind(this)).then(function(/** @type {ApiResponse} */ res) {\n\n var 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\n this.emit(this.events.refreshSuccess, res);\n\n return res;\n\n }.bind(this)).catch(function(e) {\n\n e = this._client.makeError(e);\n\n if (this._clearCacheOnRefreshError) {\n this._cache.clean();\n }\n\n this.emit(this.events.refreshError, e);\n\n throw e;\n\n }.bind(this));\n\n};\n\n/**\n * @returns {Promise}\n */\nPlatform.prototype.refresh = function() {\n\n if (!this._refreshPromise) {\n\n this._refreshPromise = this._refresh()\n .then(function(res) {\n this._refreshPromise = null;\n return res;\n }.bind(this))\n .catch(function(e) {\n this._refreshPromise = null;\n throw e;\n }.bind(this));\n\n }\n\n return this._refreshPromise;\n\n};\n\n/**\n * @returns {Promise}\n */\nPlatform.prototype.logout = function() {\n\n return (new this._externals.Promise(function(resolve) {\n\n this.emit(this.events.beforeLogout);\n\n if (!this._appSecret) {\n resolve(null);\n return;\n }\n\n resolve(this._tokenRequest(Platform._revokeEndpoint, {\n token: this._auth.accessToken()\n }));\n }.bind(this))).then(function(res) {\n\n this._cache.clean();\n\n this.emit(this.events.logoutSuccess, res);\n\n return res;\n\n }.bind(this)).catch(function(e) {\n\n this.emit(this.events.logoutError, e);\n\n throw e;\n\n }.bind(this));\n\n};\n\n/**\n * @param {Request} request\n * @param {object} [options]\n * @param {boolean} [options.skipAuthCheck]\n * @return {Promise}\n */\nPlatform.prototype.inflateRequest = function(request, options) {\n\n options = options || {};\n\n if (options.skipAuthCheck) return this._externals.Promise.resolve(request);\n\n return this.ensureLoggedIn().then(function() {\n\n request.headers.set('X-User-Agent', this._userAgent);\n request.headers.set('Client-Id', this._appKey);\n request.headers.set('Authorization', this._authHeader());\n //request.url = this.createUrl(request.url, {addServer: true}); //FIXME Spec prevents this...\n\n return request;\n\n }.bind(this));\n\n};\n\n/**\n * @param {Request} request\n * @param {object} [options]\n * @param {boolean} [options.skipAuthCheck]\n * @param {boolean|int} [options.handleRateLimit]\n * @param {boolean} [options.retry] Will be set by this method if SDK makes second request\n * @return {Promise}\n */\nPlatform.prototype.sendRequest = function(request, options) {\n\n return this.inflateRequest(request, options).then(function(request) {\n\n options = options || {};\n\n return this._client.sendRequest(request);\n\n }.bind(this)).catch(function(e) {\n\n // Guard is for errors that come from polling\n if (!e.apiResponse || !e.apiResponse.response() || options.retry) throw e;\n\n var response = e.apiResponse.response();\n var status = response.status;\n\n if ((status != ApiResponse._unauthorizedStatus) &&\n (status != ApiResponse._rateLimitStatus)) throw e;\n\n options.retry = true;\n\n var retryAfter = 0;\n\n if (status == ApiResponse._unauthorizedStatus) {\n this._auth.cancelAccessToken();\n }\n\n if (status == ApiResponse._rateLimitStatus) {\n\n var defaultRetryAfter = (!options.handleRateLimit || typeof options.handleRateLimit == 'boolean' ? 60 : options.handleRateLimit);\n\n // FIXME retry-after is custom header, by default, it can't be retrieved. Server should add header: 'Access-Control-Expose-Headers: retry-after'.\n retryAfter = parseFloat(response.headers.get('retry-after') || defaultRetryAfter) * 1000;\n\n e.retryAfter = retryAfter;\n\n this.emit(this.events.rateLimitError, e);\n\n if (!options.handleRateLimit) throw e;\n\n }\n\n return this.delay(retryAfter).then(function() {\n return this.sendRequest(this._client.createRequest(options), options);\n }.bind(this));\n\n }.bind(this));\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 * @param {boolean|int} [options.handleRateLimit]\n * @return {Promise}\n */\nPlatform.prototype.send = function(options) {\n\n options = options || {};\n\n //FIXME https://github.com/bitinn/node-fetch/issues/43\n options.url = this.createUrl(options.url, {addServer: true});\n\n return 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 * @param {boolean|int} [options.handleRateLimit]\n * @return {Promise}\n */\nPlatform.prototype.get = function(url, query, options) {\n return this.send(objectAssign({}, {method: 'GET', url: url, query: query}, 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 * @param {boolean|int} [options.handleRateLimit]\n * @return {Promise}\n */\nPlatform.prototype.post = function(url, body, query, options) {\n return this.send(objectAssign({}, {method: 'POST', url: url, query: query, body: body}, 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 * @param {boolean|int} [options.handleRateLimit]\n * @return {Promise}\n */\nPlatform.prototype.put = function(url, body, query, options) {\n return this.send(objectAssign({}, {method: 'PUT', url: url, query: query, body: body}, 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 * @param {boolean|int} [options.handleRateLimit]\n * @return {Promise}\n */\nPlatform.prototype['delete'] = function(url, query, options) {\n return this.send(objectAssign({}, {method: 'DELETE', url: url, query: query}, options));\n};\n\nPlatform.prototype.ensureLoggedIn = function() {\n if (this._isAccessTokenValid()) return this._externals.Promise.resolve();\n return this.refresh();\n};\n\n/**\n * @param path\n * @param body\n * @return {Promise.}\n * @private\n */\nPlatform.prototype._tokenRequest = function(path, body) {\n\n return this.send({\n url: path,\n skipAuthCheck: true,\n body: body,\n method: 'POST',\n headers: {\n 'Authorization': 'Basic ' + this._apiKey(),\n 'Content-Type': ApiResponse._urlencodedContentType\n }\n });\n\n};\n\n/**\n * @return {boolean}\n * @private\n */\nPlatform.prototype._isAccessTokenValid = function() {\n return this._auth.accessTokenValid();\n};\n\n/**\n * @return {string}\n * @private\n */\nPlatform.prototype._apiKey = function() {\n var apiKey = this._appKey + ':' + this._appSecret;\n return (typeof btoa == 'function') ? btoa(apiKey) : new Buffer(apiKey).toString('base64');\n};\n\n/**\n * @return {string}\n * @private\n */\nPlatform.prototype._authHeader = function() {\n var token = this._auth.accessToken();\n return this._auth.tokenType() + (token ? ' ' + token : '');\n};\n\nmodule.exports = Platform;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/platform/Platform.js\n// module id = 15\n// module chunks = 0 1","/**\n * @param {Cache} options.cache\n * @param {string} options.cacheId\n * @param {int} [options.refreshHandicapMs]\n * @constructor\n * @property {Cache} _cache\n * @property {int} _refreshHandicapMs\n * @property {string} _cacheId\n */\nfunction Auth(options) {\n\n /** @private */\n this._cache = options.cache;\n\n /** @private */\n this._cacheId = options.cacheId;\n\n /** @private */\n this._refreshHandicapMs = options.refreshHandicapMs || 60 * 1000; // 1 minute\n\n}\n\nAuth.prototype.accessToken = function() {\n return this.data().access_token;\n};\n\nAuth.prototype.refreshToken = function() {\n return this.data().refresh_token;\n};\n\nAuth.prototype.tokenType = function() {\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 */\nAuth.prototype.data = function() {\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 */\nAuth.prototype.setData = function(newData) {\n\n newData = newData || {};\n\n var data = this.data();\n\n Object.keys(newData).forEach(function(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 */\nAuth.prototype.accessTokenValid = function() {\n\n var authData = this.data();\n return (authData.expire_time - this._refreshHandicapMs > Date.now());\n\n};\n\n/**\n * Check if there is a valid (not expired) access token\n * @return {boolean}\n */\nAuth.prototype.refreshTokenValid = function() {\n\n return (this.data().refresh_token_expire_time > Date.now());\n\n};\n\n/**\n * @return {Auth}\n */\nAuth.prototype.cancelAccessToken = function() {\n\n return this.setData({\n access_token: '',\n expires_in: 0\n });\n\n};\n\nmodule.exports = Auth;\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//////////////////\n// WEBPACK FOOTER\n// ./src/platform/Auth.js\n// module id = 16\n// module chunks = 0 1","var version = process.env.RCSDK_VERSION;\n\n// This will become false during the Webpack build, so no traces of package.json will be there\nif (!process.env.RCSDK_VERSION) {\n version = require('../../package.json').version;\n}\n\nmodule.exports = {\n version: version,\n authResponseProperty: 'RCAuthorizationResponse'\n};\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/core/Constants.js\n// module id = 17\n// module chunks = 0 1","var EventEmitter = require(\"events\").EventEmitter;\n\n// detect ISO 8601 format string with +00[:00] timezone notations\nvar ISO_REG_EXP = /(\\+[\\d]{2}):?([\\d]{2})?$/;\n\nfunction buildIEFriendlyString(match, $1, $2) {\n return $1 + ':' + ($2 || '00');\n}\n\n/**\n *\n * @param {string} time\n * @return {number}\n */\nfunction parseISOString(time) {\n time = time || 0;\n if (typeof time === 'string') {\n return Date.parse(time.replace(ISO_REG_EXP, buildIEFriendlyString));\n }\n return time;\n}\n\n/**\n * @param {Platform} options.platform\n * @param {Externals} options.externals\n * @param {int} [options.pollInterval]\n * @param {int} [options.renewHandicapMs]\n * @property {Externals} _externals\n * @property {Platform} _platform\n * @property {int} _pollInterval\n * @property {int} _renewHandicapMs\n * @property {PubNub} _pubnub\n * @property {string} _pubnubLastChannel\n * @property {int} _timeout\n * @property {ISubscription} _subscription\n * @constructor\n */\nfunction Subscription(options) {\n\n EventEmitter.call(this);\n\n options = options || {};\n\n this.events = {\n notification: 'notification',\n removeSuccess: 'removeSuccess',\n removeError: 'removeError',\n renewSuccess: 'renewSuccess',\n renewError: 'renewError',\n subscribeSuccess: 'subscribeSuccess',\n subscribeError: 'subscribeError',\n automaticRenewSuccess: 'automaticRenewSuccess',\n automaticRenewError: 'automaticRenewError',\n status: 'status'\n };\n\n /** @private */\n this._externals = options.externals;\n\n /** @private */\n this._platform = options.platform;\n\n /** @private */\n this._pollInterval = options.pollInterval || 10 * 1000;\n\n /** @private */\n this._renewHandicapMs = options.renewHandicapMs || 2 * 60 * 1000;\n\n /** @private */\n this._pubnub = null;\n\n /** @private */\n this._pubnubLastChannel = null;\n\n /** @private */\n this._pubnubLastSubscribeKey = null;\n\n /** @private */\n this._timeout = null;\n\n /** @private */\n this._subscription = null;\n\n}\n\nSubscription.prototype = Object.create(EventEmitter.prototype);\n\nSubscription.prototype.subscribed = function() {\n\n var subscription = this.subscription();\n\n return !!(subscription.id &&\n subscription.deliveryMode &&\n subscription.deliveryMode.subscriberKey &&\n subscription.deliveryMode.address);\n\n};\n\n/**\n * @return {boolean}\n */\nSubscription.prototype.alive = function() {\n return this.subscribed() && Date.now() < this.expirationTime();\n};\n\n/**\n * @return {boolean}\n */\nSubscription.prototype.expired = function() {\n if (!this.subscribed()) return true;\n return !this.subscribed() || Date.now() > parseISOString(this.subscription().expirationTime);\n};\n\n/**\n * @return {number}\n */\nSubscription.prototype.expirationTime = function() {\n return parseISOString(this.subscription().expirationTime) - this._renewHandicapMs;\n};\n\n/**\n * @param {ISubscription} subscription\n * @return {Subscription}\n */\nSubscription.prototype.setSubscription = function(subscription) {\n\n subscription = subscription || {};\n\n this._clearTimeout();\n this._setSubscription(subscription);\n this._subscribeAtPubnub();\n this._setTimeout();\n\n return this;\n\n};\n\n/**\n * @return {ISubscription}\n */\nSubscription.prototype.subscription = function() {\n return this._subscription || {};\n};\n\n/**\n * Creates or updates subscription if there is an active one\n * @returns {Promise}\n */\nSubscription.prototype.register = function() {\n\n if (this.alive()) {\n return this.renew();\n } else {\n return this.subscribe();\n }\n\n};\n\n/**\n * @return {string[]}\n */\nSubscription.prototype.eventFilters = function() {\n return this.subscription().eventFilters || [];\n};\n\n/**\n * @param {string[]} events\n * @return {Subscription}\n */\nSubscription.prototype.addEventFilters = function(events) {\n this.setEventFilters(this.eventFilters().concat(events));\n return this;\n};\n\n/**\n * @param {string[]} events\n * @return {Subscription}\n */\nSubscription.prototype.setEventFilters = function(events) {\n var subscription = this.subscription();\n subscription.eventFilters = events;\n this._setSubscription(subscription);\n return this;\n};\n\n/**\n * @returns {Promise}\n */\nSubscription.prototype.subscribe = function() {\n\n return (new this._externals.Promise(function(resolve) {\n\n this._clearTimeout();\n\n if (!this.eventFilters().length) throw new Error('Events are undefined');\n\n resolve(this._platform.post('/subscription', {\n eventFilters: this._getFullEventFilters(),\n deliveryMode: {\n transportType: 'PubNub'\n }\n }));\n\n }.bind(this))).then(function(response) {\n\n var json = response.json();\n\n this.setSubscription(json)\n .emit(this.events.subscribeSuccess, response);\n\n return response;\n\n }.bind(this)).catch(function(e) {\n\n e = this._platform.client().makeError(e);\n // `reset` will remove pubnub instance.\n // so if network is broken for a long time, pubnub will be removed. And client can not receive notification anymore.\n this.reset()\n .emit(this.events.subscribeError, e);\n\n throw e;\n\n }.bind(this));\n\n};\n\n/**\n * @returns {Promise}\n */\nSubscription.prototype.renew = function() {\n\n return (new this._externals.Promise(function(resolve) {\n\n this._clearTimeout();\n\n if (!this.subscribed()) throw new Error('No subscription');\n\n if (!this.eventFilters().length) throw new Error('Events are undefined');\n\n resolve(this._platform.put('/subscription/' + this.subscription().id, {\n eventFilters: this._getFullEventFilters()\n }));\n\n }.bind(this))).then(function(response) {\n\n var json = response.json();\n\n this.setSubscription(json)\n .emit(this.events.renewSuccess, response);\n\n return response;\n\n }.bind(this)).catch(function(e) {\n\n e = this._platform.client().makeError(e);\n // `reset` will remove pubnub instance.\n // so if network is broken for a long time, pubnub will be removed. And client can not receive notification anymore.\n this.reset()\n .emit(this.events.renewError, e);\n\n throw e;\n\n }.bind(this));\n\n};\n\n/**\n * @returns {Promise}\n */\nSubscription.prototype.remove = function() {\n\n return (new this._externals.Promise(function(resolve) {\n\n if (!this.subscribed()) throw new Error('No subscription');\n\n resolve(this._platform.delete('/subscription/' + this.subscription().id));\n\n }.bind(this))).then(function(response) {\n\n this.reset()\n .emit(this.events.removeSuccess, response);\n\n return response;\n\n }.bind(this)).catch(function(e) {\n\n e = this._platform.client().makeError(e);\n\n this.emit(this.events.removeError, e);\n\n throw e;\n\n }.bind(this));\n\n};\n\n/**\n * @returns {Promise}\n */\nSubscription.prototype.resubscribe = function() {\n var filters = this.eventFilters();\n return this.reset().setEventFilters(filters).subscribe();\n};\n\n/**\n * Remove subscription and disconnect from PubNub\n * This method resets subscription at client side but backend is not notified\n * @return {Subscription}\n */\nSubscription.prototype.reset = function() {\n this._clearTimeout();\n this._unsubscribeAtPubnub();\n this._setSubscription(null);\n return this;\n};\n\n/**\n * @param subscription\n * @private\n */\nSubscription.prototype._setSubscription = function(subscription) {\n this._subscription = subscription;\n};\n\n/**\n * @return {string[]}\n * @private\n */\nSubscription.prototype._getFullEventFilters = function() {\n\n return this.eventFilters().map(function(event) {\n return this._platform.createUrl(event);\n }.bind(this));\n\n};\n\n/**\n * @return {Subscription}\n * @private\n */\nSubscription.prototype._setTimeout = function() {\n\n this._clearTimeout();\n\n if (!this.alive()) throw new Error('Subscription is not alive');\n\n this._timeout = setInterval(function() {\n\n if (this.alive()) {\n return;\n }\n\n this._clearTimeout();\n\n (new this._externals.Promise(function(resolve) {\n\n if (this.expired()) {\n resolve(this.subscribe());\n } else {\n resolve(this.renew());\n }\n\n }.bind(this))).then(function(res) {\n\n this.emit(this.events.automaticRenewSuccess, res);\n\n }.bind(this)).catch(function(e) {\n\n this.emit(this.events.automaticRenewError, e);\n\n }.bind(this));\n\n }.bind(this), this._pollInterval);\n\n return this;\n\n};\n\n/**\n * @return {Subscription}\n * @private\n */\nSubscription.prototype._clearTimeout = function() {\n clearInterval(this._timeout);\n return this;\n};\n\nSubscription.prototype._decrypt = function(message) {\n\n if (!this.subscribed()) throw new Error('No subscription');\n\n if (this.subscription().deliveryMode.encryptionKey) {\n\n message = this._pubnub.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/**\n * @param message\n * @return {Subscription}\n * @private\n */\nSubscription.prototype._notify = function(message) {\n this.emit(this.events.notification, this._decrypt(message));\n return this;\n};\n\n/**\n * @return {Subscription}\n * @private\n */\nSubscription.prototype._subscribeAtPubnub = function() {\n\n if (!this.alive()) throw new Error('Subscription is not alive');\n\n var deliveryMode = this.subscription().deliveryMode;\n\n if (this._pubnub) {\n\n if (this._pubnubLastChannel === deliveryMode.address) {\n\n // Nothing to update, keep listening to same channel\n return this;\n\n } else if (this._pubnubLastSubscribeKey && this._pubnubLastSubscribeKey !== deliveryMode.subscriberKey) {\n\n // Subscribe key changed, need to reset everything\n this._unsubscribeAtPubnub();\n\n } else if (this._pubnubLastChannel) {\n\n // Need to subscribe to new channel\n this._pubnub.unsubscribeAll();\n\n }\n\n }\n\n if (!this._pubnub) {\n\n this._pubnubLastSubscribeKey = deliveryMode.subscriberKey;\n\n var PubNub = this._externals.PubNub;\n\n this._pubnub = new PubNub({\n ssl: true,\n restore: true,\n subscribeKey: deliveryMode.subscriberKey,\n origin: 'ringcentral.pubnubapi.com',\n keepAlive: true\n });\n\n this._pubnub.addListener({\n status: function(statusEvent) {\n this.emit(this.events.status, statusEvent);\n }.bind(this),\n message: function(m) {\n this._notify(m.message); // all other props are ignored\n }.bind(this)\n });\n\n }\n\n this._pubnubLastChannel = deliveryMode.address;\n this._pubnub.subscribe({channels: [deliveryMode.address]});\n\n return this;\n\n};\n\n/**\n * @return {Subscription}\n * @private\n */\nSubscription.prototype._unsubscribeAtPubnub = function() {\n\n if (!this.subscribed() || !this._pubnub) return this;\n\n this._pubnub.removeAllListeners();\n this._pubnub.destroy(); // this will unsubscribe from all\n\n this._pubnubLastSubscribeKey = null;\n this._pubnubLastChannel = null;\n this._pubnub = null;\n\n return this;\n\n};\n\nmodule.exports = Subscription;\n\n/**\n * The complete Triforce, or one or more components of the Triforce.\n * @typedef {Object} ISubscription\n * @property {string} [id]\n * @property {string} [uri]\n * @property {string[]} [eventFilters]\n * @property {string} [expirationTime] Format: 2014-03-12T19:54:35.613+0000\n * @property {int} [expiresIn]\n * @property {string} [deliveryMode.transportType]\n * @property {boolean} [deliveryMode.encryption]\n * @property {string} [deliveryMode.address]\n * @property {string} [deliveryMode.subscriberKey]\n * @property {string} [deliveryMode.encryptionKey]\n * @property {string} [deliveryMode.secretKey]\n * @property {string} [creationTime]\n * @property {string} [status] Active\n */\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/subscription/Subscription.js\n// module id = 18\n// module chunks = 0 1","var Subscription = require(\"./Subscription\");\n\n/**\n * @param {Platform} options.platform\n * @param {Externals} options.externals\n * @param {Cache} options.cache\n * @param {string} options.cacheKey\n * @param {int} [options.pollInterval]\n * @param {int} [options.renewHandicapMs]\n * @return {CachedSubscription}\n * @constructor\n * @property {Cache} _cache\n * @extends Subscription\n */\nfunction CachedSubscription(options) {\n\n options = options || {};\n\n if (!options.cacheKey) throw new Error('Cached Subscription requires cacheKey parameter to be defined');\n\n /** @private */\n this._cacheKey = options.cacheKey;\n\n Subscription.call(this, options);\n\n /** @private */\n this._cache = options.cache;\n\n // This is not used in this class\n this._subscription = undefined;\n\n}\n\nCachedSubscription.prototype = Object.create(Subscription.prototype);\n\nCachedSubscription.prototype.subscription = function() {\n return this._cache.getItem(this._cacheKey) || {};\n};\n\nCachedSubscription.prototype._setSubscription = function(subscription) {\n return this._cache.setItem(this._cacheKey, subscription);\n};\n\n/**\n * This function checks whether there are any pre-defined eventFilters in cache and if not -- uses provided as defaults\n * @param {string[]} events\n * @return {CachedSubscription}\n */\nCachedSubscription.prototype.restore = function(events) {\n\n if (!this.eventFilters().length) {\n this.setEventFilters(events);\n }\n\n return this;\n\n};\n\nmodule.exports = CachedSubscription;\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/subscription/CachedSubscription.js\n// module id = 19\n// module chunks = 0 1"],"sourceRoot":""} \ No newline at end of file diff --git a/build/ringcentral.min.js b/build/ringcentral.min.js index 05f1a03b..f9a04d18 100644 --- a/build/ringcentral.min.js +++ b/build/ringcentral.min.js @@ -15,5 +15,5 @@ object-assign * Copyright (c) 2014-2017, Jon Schlinkert. * Released under the MIT License. */ -"use strict";e.exports=function(e){return null!=e&&"object"==typeof e&&Array.isArray(e)===!1}},function(e,t){function r(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function n(e){return"function"==typeof e}function i(e){return"number"==typeof e}function s(e){return"object"==typeof e&&null!==e}function o(e){return void 0===e}e.exports=r,r.EventEmitter=r,r.prototype._events=void 0,r.prototype._maxListeners=void 0,r.defaultMaxListeners=10,r.prototype.setMaxListeners=function(e){if(!i(e)||e<0||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},r.prototype.emit=function(e){var t,r,i,h,u,a;if(this._events||(this._events={}),"error"===e&&(!this._events.error||s(this._events.error)&&!this._events.error.length)){if(t=arguments[1],t instanceof Error)throw t;var c=new Error('Uncaught, unspecified "error" event. ('+t+")");throw c.context=t,c}if(r=this._events[e],o(r))return!1;if(n(r))switch(arguments.length){case 1:r.call(this);break;case 2:r.call(this,arguments[1]);break;case 3:r.call(this,arguments[1],arguments[2]);break;default:h=Array.prototype.slice.call(arguments,1),r.apply(this,h)}else if(s(r))for(h=Array.prototype.slice.call(arguments,1),a=r.slice(),i=a.length,u=0;u0&&this._events[e].length>i&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"==typeof console.trace&&console.trace())),this},r.prototype.on=r.prototype.addListener,r.prototype.once=function(e,t){function r(){this.removeListener(e,r),i||(i=!0,t.apply(this,arguments))}if(!n(t))throw TypeError("listener must be a function");var i=!1;return r.listener=t,this.on(e,r),this},r.prototype.removeListener=function(e,t){var r,i,o,h;if(!n(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(r=this._events[e],o=r.length,i=-1,r===t||n(r.listener)&&r.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(s(r)){for(h=o;h-- >0;)if(r[h]===t||r[h].listener&&r[h].listener===t){i=h;break}if(i<0)return this;1===r.length?(r.length=0,delete this._events[e]):r.splice(i,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},r.prototype.removeAllListeners=function(e){var t,r;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(r=this._events[e],n(r))this.removeListener(e,r);else if(r)for(;r.length;)this.removeListener(e,r[r.length-1]);return delete this._events[e],this},r.prototype.listeners=function(e){var t;return t=this._events&&this._events[e]?n(this._events[e])?[this._events[e]]:this._events[e].slice():[]},r.prototype.listenerCount=function(e){if(this._events){var t=this._events[e];if(n(t))return 1;if(t)return t.length}return 0},r.listenerCount=function(e,t){return e.listenerCount(t)}},function(e,t){function r(e){this._externals=e.externals,this._request=e.request,this._response=e.response,this._text=e.responseText||"",this._json=null,this._multipart=[]}r._contentType="Content-Type",r._jsonContentType="application/json",r._multipartContentType="multipart/mixed",r._urlencodedContentType="application/x-www-form-urlencoded",r._headerSeparator=":",r._bodySeparator="\n\n",r._boundarySeparator="--",r._unauthorizedStatus=401,r._rateLimitStatus=429,r.prototype.receiveResponse=function(e){return this._response=e,new this._externals.Promise(function(e){return e(this._isMultipart()||this._isJson()?this.response().text():"")}.bind(this)).then(function(e){return this._text=e,e}.bind(this))},r.prototype.response=function(){return this._response},r.prototype.request=function(){return this._request},r.prototype.ok=function(){return this._response&&this._response.ok},r.prototype.text=function(){if(!this._isJson()&&!this._isMultipart())throw new Error("Response is not text");return this._text},r.prototype.json=function(){if(!this._isJson())throw new Error("Response is not JSON");return this._json||(this._json=this._text?JSON.parse(this._text):null),this._json},r.prototype.error=function(e){if(this.ok()&&!e)return null;var t=(this._response&&this._response.status?this._response.status+" ":"")+(this._response&&this._response.statusText?this._response.statusText:"");try{this.json().message&&(t=this.json().message),this.json().error_description&&(t=this.json().error_description),this.json().description&&(t=this.json().description)}catch(e){}return t},r.prototype.toMultipart=function(){return this._isMultipart()?this.multipart():[this]},r.prototype.multipart=function(){if(!this._isMultipart())throw new Error("Response is not multipart");if(!this._multipart.length){var e=this.text();if(!e)throw new Error("No response body");var t;try{t=this._getContentType().match(/boundary=([^;]+)/i)[1]}catch(e){throw new Error("Cannot find boundary")}if(!t)throw new Error("Cannot find boundary");var n=e.toString().split(r._boundarySeparator+t);if(""===n[0].trim()&&n.shift(),n[n.length-1].trim()==r._boundarySeparator&&n.pop(),n.length<1)throw new Error("No parts in body");var i=this._create(n.shift(),this._response.status,this._response.statusText).json();this._multipart=n.map(function(e,t){var r=i.response[t].status;return this._create(e,r)}.bind(this))}return this._multipart},r.prototype._isContentType=function(e){return this._getContentType().indexOf(e)>-1},r.prototype._getContentType=function(){return this._response.headers.get(r._contentType)||""},r.prototype._isMultipart=function(){return this._isContentType(r._multipartContentType)},r.prototype._isJson=function(){return this._isContentType(r._jsonContentType)},r.prototype._create=function(e,t,n){e=e||"",t=t||200,n=n||"OK",e=e.replace(/\r/g,"");var i=new this._externals.Headers,s=e.split(r._bodySeparator),o=s.length>1?s.shift():"";e=s.length>0?s.join(r._bodySeparator):null,(o||"").split("\n").forEach(function(e){var t=e.trim().split(r._headerSeparator),n=t.shift().trim(),s=t.join(r._headerSeparator).trim();n&&i.append(n,s)});var h=new this._externals.Response(e,{headers:i,status:t,statusText:n});return new r({externals:this._externals,request:null,response:h,responseText:e})},e.exports=r},function(e,t,r){"use strict";t.decode=t.parse=r(9),t.encode=t.stringify=r(10)},function(e,t){"use strict";function r(e,t){return Object.prototype.hasOwnProperty.call(e,t)}e.exports=function(e,t,n,i){t=t||"&",n=n||"=";var s={};if("string"!=typeof e||0===e.length)return s;var o=/\+/g;e=e.split(t);var h=1e3;i&&"number"==typeof i.maxKeys&&(h=i.maxKeys);var u=e.length;h>0&&u>h&&(u=h);for(var a=0;a=0?(c=d.substr(0,_),p=d.substr(_+1)):(c=d,p=""),l=decodeURIComponent(c),f=decodeURIComponent(p),r(s,l)?Array.isArray(s[l])?s[l].push(f):s[l]=[s[l],f]:s[l]=f}return s}},function(e,t){"use strict";var r=function(e){switch(typeof e){case"string":return e;case"boolean":return e?"true":"false";case"number":return isFinite(e)?e:"";default:return""}};e.exports=function(e,t,n,i){return t=t||"&",n=n||"=",null===e&&(e=void 0),"object"==typeof e?Object.keys(e).map(function(i){var s=encodeURIComponent(r(i))+n;return Array.isArray(e[i])?e[i].map(function(e){return s+encodeURIComponent(r(e))}).join(t):s+encodeURIComponent(r(e[i]))}).join(t):i?encodeURIComponent(r(i))+n+encodeURIComponent(r(e)):""}},function(e,t,r){(function(t){function n(e){e=e||{},this.PubNub=e.PubNub||h.PubNub||i,this.localStorage=e.localStorage||("undefined"!=typeof h.localStorage?h.localStorage:{}),this.Promise=e.Promise||h.Promise||s&&s.Promise;var t=o?o({Promise:this.Promise}):{};if(this.fetch=e.fetch||h.fetch||t.fetch,this.Request=e.Request||h.Request||t.Request,this.Response=e.Response||h.Response||t.Response,this.Headers=e.Headers||h.Headers||t.Headers,!(this.fetch&&this.Response&&this.Request&&this.Headers))throw new Error("Fetch API is missing");if(!this.Promise)throw new Error("Promise is missing");if(!this.localStorage)throw new Error("LocalStorage is missing");if(!this.PubNub)throw new Error("PubNub is missing")}var i=r(12),s=r(13),o=r(14),h="undefined"!=typeof window&&window||"undefined"!=typeof t&&t||function(){return this}();e.exports=n}).call(t,function(){return this}())},function(t,r){t.exports=e},function(e,r){e.exports=t},function(e,t){e.exports=r},function(e,t,r){function n(e){i.call(this),this.events={beforeLogin:"beforeLogin",loginSuccess:"loginSuccess",loginError:"loginError",beforeRefresh:"beforeRefresh",refreshSuccess:"refreshSuccess",refreshError:"refreshError",beforeLogout:"beforeLogout",logoutSuccess:"logoutSuccess",logoutError:"logoutError",rateLimitError:"rateLimitError"},e=e||{},this._server=e.server,this._appKey=e.appKey,this._appSecret=e.appSecret,this._redirectUri=e.redirectUri||"",this._refreshDelayMs=e.refreshDelayMs||100,this._clearCacheOnRefreshError="undefined"==typeof e.clearCacheOnRefreshError||e.clearCacheOnRefreshError,this._userAgent=(e.appName?e.appName+(e.appVersion?"/"+e.appVersion:"")+" ":"")+"RCJSSDK/"+u.version,this._externals=e.externals,this._cache=e.cache,this._client=e.client,this._knownPrefixes=e.knownPrefixes||n._knownPrefixes,this._refreshPromise=null,this._auth=new h({cache:this._cache,cacheId:n._cacheId,refreshHandicapMs:e.refreshHandicapMs})}var i=r(6).EventEmitter,s=r(8),o=r(1),h=r(16),u=r(17),a=r(7);n._urlPrefix="/restapi",n._apiVersion="v1.0",n._knownPrefixes=["/rcvideo"],n._tokenEndpoint="/restapi/oauth/token",n._revokeEndpoint="/restapi/oauth/revoke",n._authorizeEndpoint="/restapi/oauth/authorize",n._cacheId="platform",n.prototype=Object.create(i.prototype),n.prototype.delay=function(e){return new this._externals.Promise(function(t,r){setTimeout(function(){t(null)},e)})},n.prototype.auth=function(){return this._auth},n.prototype.client=function(){return this._client},n.prototype.createUrl=function(e,t){e=e||"",t=t||{};var r="",i=e.indexOf("http://")!=-1||e.indexOf("https://")!=-1,s=this._knownPrefixes.some(function(t){return 0===e.indexOf(t)});return t.addServer&&!i&&(r+=this._server),e.indexOf(n._urlPrefix)!=-1||i||s||(r+=n._urlPrefix+"/"+n._apiVersion),r+=e,(t.addMethod||t.addToken)&&(r+=e.indexOf("?")>-1?"&":"?"),t.addMethod&&(r+="_method="+t.addMethod),t.addToken&&(r+=(t.addMethod?"&":"")+"access_token="+this._auth.accessToken()),r},n.prototype.loginUrl=function(e){return e=e||{},this.createUrl(n._authorizeEndpoint+"?"+s.stringify({response_type:e.implicit?"token":"code",redirect_uri:e.redirectUri||this._redirectUri,client_id:this._appKey,state:e.state||"",brand_id:e.brandId||"",display:e.display||"",prompt:e.prompt||""}),{addServer:!0})},n.prototype.parseLoginRedirect=function(e){function t(e,t){return e.split(t).reverse()[0]}var r=0===e.indexOf("#")&&t(e,"#")||0===e.indexOf("?")&&t(e,"?")||null;if(!r)throw new Error("Unable to parse response");var n=s.parse(r);if(!n)throw new Error("Unable to parse response");var i=n.error_description||n.error;if(i){var o=new Error(i);throw o.error=n.error,o}return n},n.prototype.loginWindow=function(e){return new this._externals.Promise(function(t,r){if("undefined"==typeof window)throw new Error("This method can be used only in browser");if(!e.url)throw new Error("Missing mandatory URL parameter");e=e||{},e.width=e.width||400,e.height=e.height||600,e.origin=e.origin||window.location.origin,e.property=e.property||u.authResponseProperty,e.target=e.target||"_blank";var n=void 0!==window.screenLeft?window.screenLeft:screen.left,i=void 0!==window.screenTop?window.screenTop:screen.top,s=window.innerWidth?window.innerWidth:document.documentElement.clientWidth?document.documentElement.clientWidth:screen.width,o=window.innerHeight?window.innerHeight:document.documentElement.clientHeight?document.documentElement.clientHeight:screen.height,h=s/2-e.width/2+n,a=o/2-e.height/2+i,c=window.open(e.url,"_blank","_blank"==e.target?"scrollbars=yes, status=yes, width="+e.width+", height="+e.height+", left="+h+", top="+a:"");if(!c)throw new Error("Could not open login window. Please allow popups for this site");c.focus&&c.focus();var p=window.addEventListener?"addEventListener":"attachEvent",l="addEventListener"==p?"removeEventListener":"detachEvent",f="addEventListener"==p?"message":"onmessage",d=function(n){try{if(n.origin!=e.origin)return;if(!n.data||!n.data[e.property])return;c.close(),window[l](f,d);var i=this.parseLoginRedirect(n.data[e.property]);if(!i.code&&!i.access_token)throw new Error("No authorization code or token");t(i)}catch(e){r(e)}}.bind(this);window[p](f,d,!1)}.bind(this))},n.prototype.loggedIn=function(){return this.ensureLoggedIn().then(function(){return!0}).catch(function(){return!1})},n.prototype.login=function(e){return new this._externals.Promise(function(t){e=e||{},this.emit(this.events.beforeLogin);var r={};return e.access_token?t(e):(e.code?e.code&&(r.grant_type="authorization_code",r.code=e.code,r.redirect_uri=e.redirectUri||this._redirectUri):(r.grant_type="password",r.username=e.username,r.password=e.password,r.extension=e.extension||""),e.endpointId&&(r.endpoint_id=e.endpointId),e.accessTokenTtl&&(r.access_token_ttl=e.accessTokenTtl),e.refreshTokenTtl&&(r.refresh_token_ttl=e.refreshTokenTtl),void t(this._tokenRequest(n._tokenEndpoint,r)))}.bind(this)).then(function(e){var t=e.json?e:null,r=t&&t.json()||e;return this._auth.setData(r),this.emit(this.events.loginSuccess,t),t}.bind(this)).catch(function(e){throw this._clearCacheOnRefreshError&&this._cache.clean(),this.emit(this.events.loginError,e),e}.bind(this))},n.prototype._refresh=function(){return this.delay(this._refreshDelayMs).then(function(){if(this.emit(this.events.beforeRefresh),!this._auth.refreshToken())throw new Error("Refresh token is missing");if(!this._auth.refreshTokenValid())throw new Error("Refresh token has expired");return this._tokenRequest(n._tokenEndpoint,{grant_type:"refresh_token",refresh_token:this._auth.refreshToken(),access_token_ttl:this._auth.data().expires_in+1,refresh_token_ttl:this._auth.data().refresh_token_expires_in+1})}.bind(this)).then(function(e){var t=e.json();if(!t.access_token)throw this._client.makeError(new Error("Malformed OAuth response"),e);return this._auth.setData(t),this.emit(this.events.refreshSuccess,e),e}.bind(this)).catch(function(e){throw e=this._client.makeError(e),this._clearCacheOnRefreshError&&this._cache.clean(),this.emit(this.events.refreshError,e),e}.bind(this))},n.prototype.refresh=function(){return this._refreshPromise||(this._refreshPromise=this._refresh().then(function(e){return this._refreshPromise=null,e}.bind(this)).catch(function(e){throw this._refreshPromise=null,e}.bind(this))),this._refreshPromise},n.prototype.logout=function(){return new this._externals.Promise(function(e){return this.emit(this.events.beforeLogout),this._appSecret?void e(this._tokenRequest(n._revokeEndpoint,{token:this._auth.accessToken()})):void e(null)}.bind(this)).then(function(e){return this._cache.clean(),this.emit(this.events.logoutSuccess,e),e}.bind(this)).catch(function(e){throw this.emit(this.events.logoutError,e),e}.bind(this))},n.prototype.inflateRequest=function(e,t){return t=t||{},t.skipAuthCheck?this._externals.Promise.resolve(e):this.ensureLoggedIn().then(function(){return e.headers.set("X-User-Agent",this._userAgent),e.headers.set("Client-Id",this._appKey),e.headers.set("Authorization",this._authHeader()),e}.bind(this))},n.prototype.sendRequest=function(e,t){return this.inflateRequest(e,t).then(function(e){return t=t||{},this._client.sendRequest(e)}.bind(this)).catch(function(e){if(!e.apiResponse||!e.apiResponse.response()||t.retry)throw e;var r=e.apiResponse.response(),n=r.status;if(n!=a._unauthorizedStatus&&n!=a._rateLimitStatus)throw e;t.retry=!0;var i=0;if(n==a._unauthorizedStatus&&this._auth.cancelAccessToken(),n==a._rateLimitStatus){var s=t.handleRateLimit&&"boolean"!=typeof t.handleRateLimit?t.handleRateLimit:60;if(i=1e3*parseFloat(r.headers.get("retry-after")||s),e.retryAfter=i,this.emit(this.events.rateLimitError,e),!t.handleRateLimit)throw e}return this.delay(i).then(function(){return this.sendRequest(this._client.createRequest(t),t)}.bind(this))}.bind(this))},n.prototype.send=function(e){return e=e||{},e.url=this.createUrl(e.url,{addServer:!0}),this.sendRequest(this._client.createRequest(e),e)},n.prototype.get=function(e,t,r){return this.send(o({},{method:"GET",url:e,query:t},r))},n.prototype.post=function(e,t,r,n){return this.send(o({},{method:"POST",url:e,query:r,body:t},n))},n.prototype.put=function(e,t,r,n){return this.send(o({},{method:"PUT",url:e,query:r,body:t},n))},n.prototype.delete=function(e,t,r){return this.send(o({},{method:"DELETE",url:e,query:t},r))},n.prototype.ensureLoggedIn=function(){return this._isAccessTokenValid()?this._externals.Promise.resolve():this.refresh()},n.prototype._tokenRequest=function(e,t){return this.send({url:e,skipAuthCheck:!0,body:t,method:"POST",headers:{Authorization:"Basic "+this._apiKey(),"Content-Type":a._urlencodedContentType}})},n.prototype._isAccessTokenValid=function(){return this._auth.accessTokenValid()},n.prototype._apiKey=function(){var e=this._appKey+":"+this._appSecret;return"function"==typeof btoa?btoa(e):new Buffer(e).toString("base64")},n.prototype._authHeader=function(){var e=this._auth.accessToken();return this._auth.tokenType()+(e?" "+e:"")},e.exports=n},function(e,t){function r(e){this._cache=e.cache,this._cacheId=e.cacheId,this._refreshHandicapMs=e.refreshHandicapMs||6e4}r.prototype.accessToken=function(){return this.data().access_token},r.prototype.refreshToken=function(){return this.data().refresh_token},r.prototype.tokenType=function(){return this.data().token_type},r.prototype.data=function(){return this._cache.getItem(this._cacheId)||{token_type:"",access_token:"",expires_in:0,refresh_token:"",refresh_token_expires_in:0}},r.prototype.setData=function(e){e=e||{};var t=this.data();return Object.keys(e).forEach(function(r){t[r]=e[r]}),t.expire_time=Date.now()+1e3*t.expires_in,t.refresh_token_expire_time=Date.now()+1e3*t.refresh_token_expires_in,this._cache.setItem(this._cacheId,t),this},r.prototype.accessTokenValid=function(){var e=this.data();return e.expire_time-this._refreshHandicapMs>Date.now()},r.prototype.refreshTokenValid=function(){return this.data().refresh_token_expire_time>Date.now()},r.prototype.cancelAccessToken=function(){return this.setData({access_token:"",expires_in:0})},e.exports=r},function(e,t,r){var n="3.2.2";e.exports={version:n,authResponseProperty:"RCAuthorizationResponse"}},function(e,t,r){function n(e,t,r){return t+":"+(r||"00")}function i(e){return e=e||0,"string"==typeof e?Date.parse(e.replace(h,n)):e}function s(e){o.call(this),e=e||{},this.events={notification:"notification",removeSuccess:"removeSuccess",removeError:"removeError",renewSuccess:"renewSuccess",renewError:"renewError",subscribeSuccess:"subscribeSuccess",subscribeError:"subscribeError",automaticRenewSuccess:"automaticRenewSuccess",automaticRenewError:"automaticRenewError"},this._externals=e.externals,this._platform=e.platform,this._pollInterval=e.pollInterval||1e4,this._renewHandicapMs=e.renewHandicapMs||12e4,this._pubnub=null,this._pubnubLastChannel=null,this._pubnubLastSubscribeKey=null,this._timeout=null,this._subscription=null}var o=r(6).EventEmitter,h=/(\+[\d]{2}):?([\d]{2})?$/;s.prototype=Object.create(o.prototype),s.prototype.subscribed=function(){var e=this.subscription();return!!(e.id&&e.deliveryMode&&e.deliveryMode.subscriberKey&&e.deliveryMode.address)},s.prototype.alive=function(){return this.subscribed()&&Date.now()i(this.subscription().expirationTime))},s.prototype.expirationTime=function(){return i(this.subscription().expirationTime)-this._renewHandicapMs},s.prototype.setSubscription=function(e){return e=e||{},this._clearTimeout(),this._setSubscription(e),this._subscribeAtPubnub(),this._setTimeout(),this},s.prototype.subscription=function(){return this._subscription||{}},s.prototype.register=function(){return this.alive()?this.renew():this.subscribe()},s.prototype.eventFilters=function(){return this.subscription().eventFilters||[]},s.prototype.addEventFilters=function(e){return this.setEventFilters(this.eventFilters().concat(e)),this},s.prototype.setEventFilters=function(e){var t=this.subscription();return t.eventFilters=e,this._setSubscription(t),this},s.prototype.subscribe=function(){return new this._externals.Promise(function(e){if(this._clearTimeout(),!this.eventFilters().length)throw new Error("Events are undefined");e(this._platform.post("/subscription",{eventFilters:this._getFullEventFilters(),deliveryMode:{transportType:"PubNub"}}))}.bind(this)).then(function(e){var t=e.json();return this.setSubscription(t).emit(this.events.subscribeSuccess,e),e}.bind(this)).catch(function(e){throw e=this._platform.client().makeError(e),this.reset().emit(this.events.subscribeError,e),e}.bind(this))},s.prototype.renew=function(){return new this._externals.Promise(function(e){if(this._clearTimeout(),!this.subscribed())throw new Error("No subscription");if(!this.eventFilters().length)throw new Error("Events are undefined");e(this._platform.put("/subscription/"+this.subscription().id,{eventFilters:this._getFullEventFilters()}))}.bind(this)).then(function(e){var t=e.json();return this.setSubscription(t).emit(this.events.renewSuccess,e),e}.bind(this)).catch(function(e){throw e=this._platform.client().makeError(e),this.reset().emit(this.events.renewError,e),e}.bind(this))},s.prototype.remove=function(){return new this._externals.Promise(function(e){if(!this.subscribed())throw new Error("No subscription");e(this._platform.delete("/subscription/"+this.subscription().id))}.bind(this)).then(function(e){return this.reset().emit(this.events.removeSuccess,e),e}.bind(this)).catch(function(e){throw e=this._platform.client().makeError(e),this.emit(this.events.removeError,e),e}.bind(this))},s.prototype.resubscribe=function(){var e=this.eventFilters();return this.reset().setEventFilters(e).subscribe()},s.prototype.reset=function(){return this._clearTimeout(),this._unsubscribeAtPubnub(),this._setSubscription(null),this},s.prototype._setSubscription=function(e){this._subscription=e},s.prototype._getFullEventFilters=function(){return this.eventFilters().map(function(e){return this._platform.createUrl(e)}.bind(this))},s.prototype._setTimeout=function(){if(this._clearTimeout(),!this.alive())throw new Error("Subscription is not alive");return this._timeout=setInterval(function(){this.alive()||(this._clearTimeout(),new this._externals.Promise(function(e){e(this.expired()?this.subscribe():this.renew())}.bind(this)).then(function(e){this.emit(this.events.automaticRenewSuccess,e)}.bind(this)).catch(function(e){this.emit(this.events.automaticRenewError,e)}.bind(this)))}.bind(this),this._pollInterval),this},s.prototype._clearTimeout=function(){return clearInterval(this._timeout),this},s.prototype._decrypt=function(e){if(!this.subscribed())throw new Error("No subscription");return this.subscription().deliveryMode.encryptionKey&&(e=this._pubnub.decrypt(e,this.subscription().deliveryMode.encryptionKey,{encryptKey:!1,keyEncoding:"base64",keyLength:128,mode:"ecb"})),e},s.prototype._notify=function(e){return this.emit(this.events.notification,this._decrypt(e)),this},s.prototype._subscribeAtPubnub=function(){if(!this.alive())throw new Error("Subscription is not alive");var e=this.subscription().deliveryMode;if(this._pubnub){if(this._pubnubLastChannel===e.address)return this;this._pubnubLastSubscribeKey&&this._pubnubLastSubscribeKey!==e.subscriberKey?this._unsubscribeAtPubnub():this._pubnubLastChannel&&this._pubnub.unsubscribeAll()}if(!this._pubnub){this._pubnubLastSubscribeKey=e.subscriberKey;var t=this._externals.PubNub;this._pubnub=new t({ssl:!0,restore:!0,subscribeKey:e.subscriberKey}),this._pubnub.addListener({status:function(e){},message:function(e){this._notify(e.message)}.bind(this)})}return this._pubnubLastChannel=e.address,this._pubnub.subscribe({channels:[e.address]}),this},s.prototype._unsubscribeAtPubnub=function(){return this.subscribed()&&this._pubnub?(this._pubnub.removeAllListeners(),this._pubnub.destroy(),this._pubnubLastSubscribeKey=null,this._pubnubLastChannel=null,this._pubnub=null,this):this},e.exports=s},function(e,t,r){function n(e){if(e=e||{},!e.cacheKey)throw new Error("Cached Subscription requires cacheKey parameter to be defined");this._cacheKey=e.cacheKey,i.call(this,e),this._cache=e.cache,this._subscription=void 0}var i=r(18);n.prototype=Object.create(i.prototype),n.prototype.subscription=function(){return this._cache.getItem(this._cacheKey)||{}},n.prototype._setSubscription=function(e){return this._cache.setItem(this._cacheKey,e)},n.prototype.restore=function(e){return this.eventFilters().length||this.setEventFilters(e),this},e.exports=n}])}); +"use strict";e.exports=function(e){return null!=e&&"object"==typeof e&&Array.isArray(e)===!1}},function(e,t){function r(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function n(e){return"function"==typeof e}function i(e){return"number"==typeof e}function s(e){return"object"==typeof e&&null!==e}function o(e){return void 0===e}e.exports=r,r.EventEmitter=r,r.prototype._events=void 0,r.prototype._maxListeners=void 0,r.defaultMaxListeners=10,r.prototype.setMaxListeners=function(e){if(!i(e)||e<0||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},r.prototype.emit=function(e){var t,r,i,h,u,a;if(this._events||(this._events={}),"error"===e&&(!this._events.error||s(this._events.error)&&!this._events.error.length)){if(t=arguments[1],t instanceof Error)throw t;var c=new Error('Uncaught, unspecified "error" event. ('+t+")");throw c.context=t,c}if(r=this._events[e],o(r))return!1;if(n(r))switch(arguments.length){case 1:r.call(this);break;case 2:r.call(this,arguments[1]);break;case 3:r.call(this,arguments[1],arguments[2]);break;default:h=Array.prototype.slice.call(arguments,1),r.apply(this,h)}else if(s(r))for(h=Array.prototype.slice.call(arguments,1),a=r.slice(),i=a.length,u=0;u0&&this._events[e].length>i&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"==typeof console.trace&&console.trace())),this},r.prototype.on=r.prototype.addListener,r.prototype.once=function(e,t){function r(){this.removeListener(e,r),i||(i=!0,t.apply(this,arguments))}if(!n(t))throw TypeError("listener must be a function");var i=!1;return r.listener=t,this.on(e,r),this},r.prototype.removeListener=function(e,t){var r,i,o,h;if(!n(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(r=this._events[e],o=r.length,i=-1,r===t||n(r.listener)&&r.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(s(r)){for(h=o;h-- >0;)if(r[h]===t||r[h].listener&&r[h].listener===t){i=h;break}if(i<0)return this;1===r.length?(r.length=0,delete this._events[e]):r.splice(i,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},r.prototype.removeAllListeners=function(e){var t,r;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(r=this._events[e],n(r))this.removeListener(e,r);else if(r)for(;r.length;)this.removeListener(e,r[r.length-1]);return delete this._events[e],this},r.prototype.listeners=function(e){var t;return t=this._events&&this._events[e]?n(this._events[e])?[this._events[e]]:this._events[e].slice():[]},r.prototype.listenerCount=function(e){if(this._events){var t=this._events[e];if(n(t))return 1;if(t)return t.length}return 0},r.listenerCount=function(e,t){return e.listenerCount(t)}},function(e,t){function r(e){this._externals=e.externals,this._request=e.request,this._response=e.response,this._text=e.responseText||"",this._json=null,this._multipart=[]}r._contentType="Content-Type",r._jsonContentType="application/json",r._multipartContentType="multipart/mixed",r._urlencodedContentType="application/x-www-form-urlencoded",r._headerSeparator=":",r._bodySeparator="\n\n",r._boundarySeparator="--",r._unauthorizedStatus=401,r._rateLimitStatus=429,r.prototype.receiveResponse=function(e){return this._response=e,new this._externals.Promise(function(e){return e(this._isMultipart()||this._isJson()?this.response().text():"")}.bind(this)).then(function(e){return this._text=e,e}.bind(this))},r.prototype.response=function(){return this._response},r.prototype.request=function(){return this._request},r.prototype.ok=function(){return this._response&&this._response.ok},r.prototype.text=function(){if(!this._isJson()&&!this._isMultipart())throw new Error("Response is not text");return this._text},r.prototype.json=function(){if(!this._isJson())throw new Error("Response is not JSON");return this._json||(this._json=this._text?JSON.parse(this._text):null),this._json},r.prototype.error=function(e){if(this.ok()&&!e)return null;var t=(this._response&&this._response.status?this._response.status+" ":"")+(this._response&&this._response.statusText?this._response.statusText:"");try{this.json().message&&(t=this.json().message),this.json().error_description&&(t=this.json().error_description),this.json().description&&(t=this.json().description)}catch(e){}return t},r.prototype.toMultipart=function(){return this._isMultipart()?this.multipart():[this]},r.prototype.multipart=function(){if(!this._isMultipart())throw new Error("Response is not multipart");if(!this._multipart.length){var e=this.text();if(!e)throw new Error("No response body");var t;try{t=this._getContentType().match(/boundary=([^;]+)/i)[1]}catch(e){throw new Error("Cannot find boundary")}if(!t)throw new Error("Cannot find boundary");var n=e.toString().split(r._boundarySeparator+t);if(""===n[0].trim()&&n.shift(),n[n.length-1].trim()==r._boundarySeparator&&n.pop(),n.length<1)throw new Error("No parts in body");var i=this._create(n.shift(),this._response.status,this._response.statusText).json();this._multipart=n.map(function(e,t){var r=i.response[t].status;return this._create(e,r)}.bind(this))}return this._multipart},r.prototype._isContentType=function(e){return this._getContentType().indexOf(e)>-1},r.prototype._getContentType=function(){return this._response.headers.get(r._contentType)||""},r.prototype._isMultipart=function(){return this._isContentType(r._multipartContentType)},r.prototype._isJson=function(){return this._isContentType(r._jsonContentType)},r.prototype._create=function(e,t,n){e=e||"",t=t||200,n=n||"OK",e=e.replace(/\r/g,"");var i=new this._externals.Headers,s=e.split(r._bodySeparator),o=s.length>1?s.shift():"";e=s.length>0?s.join(r._bodySeparator):null,(o||"").split("\n").forEach(function(e){var t=e.trim().split(r._headerSeparator),n=t.shift().trim(),s=t.join(r._headerSeparator).trim();n&&i.append(n,s)});var h=new this._externals.Response(e,{headers:i,status:t,statusText:n});return new r({externals:this._externals,request:null,response:h,responseText:e})},e.exports=r},function(e,t,r){"use strict";t.decode=t.parse=r(9),t.encode=t.stringify=r(10)},function(e,t){"use strict";function r(e,t){return Object.prototype.hasOwnProperty.call(e,t)}e.exports=function(e,t,n,i){t=t||"&",n=n||"=";var s={};if("string"!=typeof e||0===e.length)return s;var o=/\+/g;e=e.split(t);var h=1e3;i&&"number"==typeof i.maxKeys&&(h=i.maxKeys);var u=e.length;h>0&&u>h&&(u=h);for(var a=0;a=0?(c=d.substr(0,_),p=d.substr(_+1)):(c=d,p=""),l=decodeURIComponent(c),f=decodeURIComponent(p),r(s,l)?Array.isArray(s[l])?s[l].push(f):s[l]=[s[l],f]:s[l]=f}return s}},function(e,t){"use strict";var r=function(e){switch(typeof e){case"string":return e;case"boolean":return e?"true":"false";case"number":return isFinite(e)?e:"";default:return""}};e.exports=function(e,t,n,i){return t=t||"&",n=n||"=",null===e&&(e=void 0),"object"==typeof e?Object.keys(e).map(function(i){var s=encodeURIComponent(r(i))+n;return Array.isArray(e[i])?e[i].map(function(e){return s+encodeURIComponent(r(e))}).join(t):s+encodeURIComponent(r(e[i]))}).join(t):i?encodeURIComponent(r(i))+n+encodeURIComponent(r(e)):""}},function(e,t,r){(function(t){function n(e){e=e||{},this.PubNub=e.PubNub||h.PubNub||i,this.localStorage=e.localStorage||("undefined"!=typeof h.localStorage?h.localStorage:{}),this.Promise=e.Promise||h.Promise||s&&s.Promise;var t=o?o({Promise:this.Promise}):{};if(this.fetch=e.fetch||h.fetch||t.fetch,this.Request=e.Request||h.Request||t.Request,this.Response=e.Response||h.Response||t.Response,this.Headers=e.Headers||h.Headers||t.Headers,!(this.fetch&&this.Response&&this.Request&&this.Headers))throw new Error("Fetch API is missing");if(!this.Promise)throw new Error("Promise is missing");if(!this.localStorage)throw new Error("LocalStorage is missing");if(!this.PubNub)throw new Error("PubNub is missing")}var i=r(12),s=r(13),o=r(14),h="undefined"!=typeof window&&window||"undefined"!=typeof t&&t||function(){return this}();e.exports=n}).call(t,function(){return this}())},function(t,r){t.exports=e},function(e,r){e.exports=t},function(e,t){e.exports=r},function(e,t,r){function n(e){i.call(this),this.events={beforeLogin:"beforeLogin",loginSuccess:"loginSuccess",loginError:"loginError",beforeRefresh:"beforeRefresh",refreshSuccess:"refreshSuccess",refreshError:"refreshError",beforeLogout:"beforeLogout",logoutSuccess:"logoutSuccess",logoutError:"logoutError",rateLimitError:"rateLimitError"},e=e||{},this._server=e.server,this._appKey=e.appKey,this._appSecret=e.appSecret,this._redirectUri=e.redirectUri||"",this._refreshDelayMs=e.refreshDelayMs||100,this._clearCacheOnRefreshError="undefined"==typeof e.clearCacheOnRefreshError||e.clearCacheOnRefreshError,this._userAgent=(e.appName?e.appName+(e.appVersion?"/"+e.appVersion:"")+" ":"")+"RCJSSDK/"+u.version,this._externals=e.externals,this._cache=e.cache,this._client=e.client,this._knownPrefixes=e.knownPrefixes||n._knownPrefixes,this._refreshPromise=null,this._auth=new h({cache:this._cache,cacheId:n._cacheId,refreshHandicapMs:e.refreshHandicapMs})}var i=r(6).EventEmitter,s=r(8),o=r(1),h=r(16),u=r(17),a=r(7);n._urlPrefix="/restapi",n._apiVersion="v1.0",n._knownPrefixes=["/rcvideo"],n._tokenEndpoint="/restapi/oauth/token",n._revokeEndpoint="/restapi/oauth/revoke",n._authorizeEndpoint="/restapi/oauth/authorize",n._cacheId="platform",n.prototype=Object.create(i.prototype),n.prototype.delay=function(e){return new this._externals.Promise(function(t,r){setTimeout(function(){t(null)},e)})},n.prototype.auth=function(){return this._auth},n.prototype.client=function(){return this._client},n.prototype.createUrl=function(e,t){e=e||"",t=t||{};var r="",i=e.indexOf("http://")!=-1||e.indexOf("https://")!=-1,s=this._knownPrefixes.some(function(t){return 0===e.indexOf(t)});return t.addServer&&!i&&(r+=this._server),e.indexOf(n._urlPrefix)!=-1||i||s||(r+=n._urlPrefix+"/"+n._apiVersion),r+=e,(t.addMethod||t.addToken)&&(r+=e.indexOf("?")>-1?"&":"?"),t.addMethod&&(r+="_method="+t.addMethod),t.addToken&&(r+=(t.addMethod?"&":"")+"access_token="+this._auth.accessToken()),r},n.prototype.loginUrl=function(e){return e=e||{},this.createUrl(n._authorizeEndpoint+"?"+s.stringify({response_type:e.implicit?"token":"code",redirect_uri:e.redirectUri||this._redirectUri,client_id:this._appKey,state:e.state||"",brand_id:e.brandId||"",display:e.display||"",prompt:e.prompt||""}),{addServer:!0})},n.prototype.parseLoginRedirect=function(e){function t(e,t){return e.split(t).reverse()[0]}var r=0===e.indexOf("#")&&t(e,"#")||0===e.indexOf("?")&&t(e,"?")||null;if(!r)throw new Error("Unable to parse response");var n=s.parse(r);if(!n)throw new Error("Unable to parse response");var i=n.error_description||n.error;if(i){var o=new Error(i);throw o.error=n.error,o}return n},n.prototype.loginWindow=function(e){return new this._externals.Promise(function(t,r){if("undefined"==typeof window)throw new Error("This method can be used only in browser");if(!e.url)throw new Error("Missing mandatory URL parameter");e=e||{},e.width=e.width||400,e.height=e.height||600,e.origin=e.origin||window.location.origin,e.property=e.property||u.authResponseProperty,e.target=e.target||"_blank";var n=void 0!==window.screenLeft?window.screenLeft:screen.left,i=void 0!==window.screenTop?window.screenTop:screen.top,s=window.innerWidth?window.innerWidth:document.documentElement.clientWidth?document.documentElement.clientWidth:screen.width,o=window.innerHeight?window.innerHeight:document.documentElement.clientHeight?document.documentElement.clientHeight:screen.height,h=s/2-e.width/2+n,a=o/2-e.height/2+i,c=window.open(e.url,"_blank","_blank"==e.target?"scrollbars=yes, status=yes, width="+e.width+", height="+e.height+", left="+h+", top="+a:"");if(!c)throw new Error("Could not open login window. Please allow popups for this site");c.focus&&c.focus();var p=window.addEventListener?"addEventListener":"attachEvent",l="addEventListener"==p?"removeEventListener":"detachEvent",f="addEventListener"==p?"message":"onmessage",d=function(n){try{if(n.origin!=e.origin)return;if(!n.data||!n.data[e.property])return;c.close(),window[l](f,d);var i=this.parseLoginRedirect(n.data[e.property]);if(!i.code&&!i.access_token)throw new Error("No authorization code or token");t(i)}catch(e){r(e)}}.bind(this);window[p](f,d,!1)}.bind(this))},n.prototype.loggedIn=function(){return this.ensureLoggedIn().then(function(){return!0}).catch(function(){return!1})},n.prototype.login=function(e){return new this._externals.Promise(function(t){e=e||{},this.emit(this.events.beforeLogin);var r={};return e.access_token?t(e):(e.code?e.code&&(r.grant_type="authorization_code",r.code=e.code,r.redirect_uri=e.redirectUri||this._redirectUri):(r.grant_type="password",r.username=e.username,r.password=e.password,r.extension=e.extension||""),e.endpointId&&(r.endpoint_id=e.endpointId),e.accessTokenTtl&&(r.access_token_ttl=e.accessTokenTtl),e.refreshTokenTtl&&(r.refresh_token_ttl=e.refreshTokenTtl),void t(this._tokenRequest(n._tokenEndpoint,r)))}.bind(this)).then(function(e){var t=e.json?e:null,r=t&&t.json()||e;return this._auth.setData(r),this.emit(this.events.loginSuccess,t),t}.bind(this)).catch(function(e){throw this._clearCacheOnRefreshError&&this._cache.clean(),this.emit(this.events.loginError,e),e}.bind(this))},n.prototype._refresh=function(){return this.delay(this._refreshDelayMs).then(function(){if(this.emit(this.events.beforeRefresh),!this._auth.refreshToken())throw new Error("Refresh token is missing");if(!this._auth.refreshTokenValid())throw new Error("Refresh token has expired");return this._tokenRequest(n._tokenEndpoint,{grant_type:"refresh_token",refresh_token:this._auth.refreshToken(),access_token_ttl:this._auth.data().expires_in+1,refresh_token_ttl:this._auth.data().refresh_token_expires_in+1})}.bind(this)).then(function(e){var t=e.json();if(!t.access_token)throw this._client.makeError(new Error("Malformed OAuth response"),e);return this._auth.setData(t),this.emit(this.events.refreshSuccess,e),e}.bind(this)).catch(function(e){throw e=this._client.makeError(e),this._clearCacheOnRefreshError&&this._cache.clean(),this.emit(this.events.refreshError,e),e}.bind(this))},n.prototype.refresh=function(){return this._refreshPromise||(this._refreshPromise=this._refresh().then(function(e){return this._refreshPromise=null,e}.bind(this)).catch(function(e){throw this._refreshPromise=null,e}.bind(this))),this._refreshPromise},n.prototype.logout=function(){return new this._externals.Promise(function(e){return this.emit(this.events.beforeLogout),this._appSecret?void e(this._tokenRequest(n._revokeEndpoint,{token:this._auth.accessToken()})):void e(null)}.bind(this)).then(function(e){return this._cache.clean(),this.emit(this.events.logoutSuccess,e),e}.bind(this)).catch(function(e){throw this.emit(this.events.logoutError,e),e}.bind(this))},n.prototype.inflateRequest=function(e,t){return t=t||{},t.skipAuthCheck?this._externals.Promise.resolve(e):this.ensureLoggedIn().then(function(){return e.headers.set("X-User-Agent",this._userAgent),e.headers.set("Client-Id",this._appKey),e.headers.set("Authorization",this._authHeader()),e}.bind(this))},n.prototype.sendRequest=function(e,t){return this.inflateRequest(e,t).then(function(e){return t=t||{},this._client.sendRequest(e)}.bind(this)).catch(function(e){if(!e.apiResponse||!e.apiResponse.response()||t.retry)throw e;var r=e.apiResponse.response(),n=r.status;if(n!=a._unauthorizedStatus&&n!=a._rateLimitStatus)throw e;t.retry=!0;var i=0;if(n==a._unauthorizedStatus&&this._auth.cancelAccessToken(),n==a._rateLimitStatus){var s=t.handleRateLimit&&"boolean"!=typeof t.handleRateLimit?t.handleRateLimit:60;if(i=1e3*parseFloat(r.headers.get("retry-after")||s),e.retryAfter=i,this.emit(this.events.rateLimitError,e),!t.handleRateLimit)throw e}return this.delay(i).then(function(){return this.sendRequest(this._client.createRequest(t),t)}.bind(this))}.bind(this))},n.prototype.send=function(e){return e=e||{},e.url=this.createUrl(e.url,{addServer:!0}),this.sendRequest(this._client.createRequest(e),e)},n.prototype.get=function(e,t,r){return this.send(o({},{method:"GET",url:e,query:t},r))},n.prototype.post=function(e,t,r,n){return this.send(o({},{method:"POST",url:e,query:r,body:t},n))},n.prototype.put=function(e,t,r,n){return this.send(o({},{method:"PUT",url:e,query:r,body:t},n))},n.prototype.delete=function(e,t,r){return this.send(o({},{method:"DELETE",url:e,query:t},r))},n.prototype.ensureLoggedIn=function(){return this._isAccessTokenValid()?this._externals.Promise.resolve():this.refresh()},n.prototype._tokenRequest=function(e,t){return this.send({url:e,skipAuthCheck:!0,body:t,method:"POST",headers:{Authorization:"Basic "+this._apiKey(),"Content-Type":a._urlencodedContentType}})},n.prototype._isAccessTokenValid=function(){return this._auth.accessTokenValid()},n.prototype._apiKey=function(){var e=this._appKey+":"+this._appSecret;return"function"==typeof btoa?btoa(e):new Buffer(e).toString("base64")},n.prototype._authHeader=function(){var e=this._auth.accessToken();return this._auth.tokenType()+(e?" "+e:"")},e.exports=n},function(e,t){function r(e){this._cache=e.cache,this._cacheId=e.cacheId,this._refreshHandicapMs=e.refreshHandicapMs||6e4}r.prototype.accessToken=function(){return this.data().access_token},r.prototype.refreshToken=function(){return this.data().refresh_token},r.prototype.tokenType=function(){return this.data().token_type},r.prototype.data=function(){return this._cache.getItem(this._cacheId)||{token_type:"",access_token:"",expires_in:0,refresh_token:"",refresh_token_expires_in:0}},r.prototype.setData=function(e){e=e||{};var t=this.data();return Object.keys(e).forEach(function(r){t[r]=e[r]}),t.expire_time=Date.now()+1e3*t.expires_in,t.refresh_token_expire_time=Date.now()+1e3*t.refresh_token_expires_in,this._cache.setItem(this._cacheId,t),this},r.prototype.accessTokenValid=function(){var e=this.data();return e.expire_time-this._refreshHandicapMs>Date.now()},r.prototype.refreshTokenValid=function(){return this.data().refresh_token_expire_time>Date.now()},r.prototype.cancelAccessToken=function(){return this.setData({access_token:"",expires_in:0})},e.exports=r},function(e,t,r){var n="3.2.2";e.exports={version:n,authResponseProperty:"RCAuthorizationResponse"}},function(e,t,r){function n(e,t,r){return t+":"+(r||"00")}function i(e){return e=e||0,"string"==typeof e?Date.parse(e.replace(h,n)):e}function s(e){o.call(this),e=e||{},this.events={notification:"notification",removeSuccess:"removeSuccess",removeError:"removeError",renewSuccess:"renewSuccess",renewError:"renewError",subscribeSuccess:"subscribeSuccess",subscribeError:"subscribeError",automaticRenewSuccess:"automaticRenewSuccess",automaticRenewError:"automaticRenewError",status:"status"},this._externals=e.externals,this._platform=e.platform,this._pollInterval=e.pollInterval||1e4,this._renewHandicapMs=e.renewHandicapMs||12e4,this._pubnub=null,this._pubnubLastChannel=null,this._pubnubLastSubscribeKey=null,this._timeout=null,this._subscription=null}var o=r(6).EventEmitter,h=/(\+[\d]{2}):?([\d]{2})?$/;s.prototype=Object.create(o.prototype),s.prototype.subscribed=function(){var e=this.subscription();return!!(e.id&&e.deliveryMode&&e.deliveryMode.subscriberKey&&e.deliveryMode.address)},s.prototype.alive=function(){return this.subscribed()&&Date.now()i(this.subscription().expirationTime))},s.prototype.expirationTime=function(){return i(this.subscription().expirationTime)-this._renewHandicapMs},s.prototype.setSubscription=function(e){return e=e||{},this._clearTimeout(),this._setSubscription(e),this._subscribeAtPubnub(),this._setTimeout(),this},s.prototype.subscription=function(){return this._subscription||{}},s.prototype.register=function(){return this.alive()?this.renew():this.subscribe()},s.prototype.eventFilters=function(){return this.subscription().eventFilters||[]},s.prototype.addEventFilters=function(e){return this.setEventFilters(this.eventFilters().concat(e)),this},s.prototype.setEventFilters=function(e){var t=this.subscription();return t.eventFilters=e,this._setSubscription(t),this},s.prototype.subscribe=function(){return new this._externals.Promise(function(e){if(this._clearTimeout(),!this.eventFilters().length)throw new Error("Events are undefined");e(this._platform.post("/subscription",{eventFilters:this._getFullEventFilters(),deliveryMode:{transportType:"PubNub"}}))}.bind(this)).then(function(e){var t=e.json();return this.setSubscription(t).emit(this.events.subscribeSuccess,e),e}.bind(this)).catch(function(e){throw e=this._platform.client().makeError(e),this.reset().emit(this.events.subscribeError,e),e}.bind(this))},s.prototype.renew=function(){return new this._externals.Promise(function(e){if(this._clearTimeout(),!this.subscribed())throw new Error("No subscription");if(!this.eventFilters().length)throw new Error("Events are undefined");e(this._platform.put("/subscription/"+this.subscription().id,{eventFilters:this._getFullEventFilters()}))}.bind(this)).then(function(e){var t=e.json();return this.setSubscription(t).emit(this.events.renewSuccess,e),e}.bind(this)).catch(function(e){throw e=this._platform.client().makeError(e),this.reset().emit(this.events.renewError,e),e}.bind(this))},s.prototype.remove=function(){return new this._externals.Promise(function(e){if(!this.subscribed())throw new Error("No subscription");e(this._platform.delete("/subscription/"+this.subscription().id))}.bind(this)).then(function(e){return this.reset().emit(this.events.removeSuccess,e),e}.bind(this)).catch(function(e){throw e=this._platform.client().makeError(e),this.emit(this.events.removeError,e),e}.bind(this))},s.prototype.resubscribe=function(){var e=this.eventFilters();return this.reset().setEventFilters(e).subscribe()},s.prototype.reset=function(){return this._clearTimeout(),this._unsubscribeAtPubnub(),this._setSubscription(null),this},s.prototype._setSubscription=function(e){this._subscription=e},s.prototype._getFullEventFilters=function(){return this.eventFilters().map(function(e){return this._platform.createUrl(e)}.bind(this))},s.prototype._setTimeout=function(){if(this._clearTimeout(),!this.alive())throw new Error("Subscription is not alive");return this._timeout=setInterval(function(){this.alive()||(this._clearTimeout(),new this._externals.Promise(function(e){e(this.expired()?this.subscribe():this.renew())}.bind(this)).then(function(e){this.emit(this.events.automaticRenewSuccess,e)}.bind(this)).catch(function(e){this.emit(this.events.automaticRenewError,e)}.bind(this)))}.bind(this),this._pollInterval),this},s.prototype._clearTimeout=function(){return clearInterval(this._timeout),this},s.prototype._decrypt=function(e){if(!this.subscribed())throw new Error("No subscription");return this.subscription().deliveryMode.encryptionKey&&(e=this._pubnub.decrypt(e,this.subscription().deliveryMode.encryptionKey,{encryptKey:!1,keyEncoding:"base64",keyLength:128,mode:"ecb"})),e},s.prototype._notify=function(e){return this.emit(this.events.notification,this._decrypt(e)),this},s.prototype._subscribeAtPubnub=function(){if(!this.alive())throw new Error("Subscription is not alive");var e=this.subscription().deliveryMode;if(this._pubnub){if(this._pubnubLastChannel===e.address)return this;this._pubnubLastSubscribeKey&&this._pubnubLastSubscribeKey!==e.subscriberKey?this._unsubscribeAtPubnub():this._pubnubLastChannel&&this._pubnub.unsubscribeAll()}if(!this._pubnub){this._pubnubLastSubscribeKey=e.subscriberKey;var t=this._externals.PubNub;this._pubnub=new t({ssl:!0,restore:!0,subscribeKey:e.subscriberKey,origin:"ringcentral.pubnubapi.com",keepAlive:!0}),this._pubnub.addListener({status:function(e){this.emit(this.events.status,e)}.bind(this),message:function(e){this._notify(e.message)}.bind(this)})}return this._pubnubLastChannel=e.address,this._pubnub.subscribe({channels:[e.address]}),this},s.prototype._unsubscribeAtPubnub=function(){return this.subscribed()&&this._pubnub?(this._pubnub.removeAllListeners(),this._pubnub.destroy(),this._pubnubLastSubscribeKey=null,this._pubnubLastChannel=null,this._pubnub=null,this):this},e.exports=s},function(e,t,r){function n(e){if(e=e||{},!e.cacheKey)throw new Error("Cached Subscription requires cacheKey parameter to be defined");this._cacheKey=e.cacheKey,i.call(this,e),this._cache=e.cache,this._subscription=void 0}var i=r(18);n.prototype=Object.create(i.prototype),n.prototype.subscription=function(){return this._cache.getItem(this._cacheKey)||{}},n.prototype._setSubscription=function(e){return this._cache.setItem(this._cacheKey,e)},n.prototype.restore=function(e){return this.eventFilters().length||this.setEventFilters(e),this},e.exports=n}])}); //# sourceMappingURL=ringcentral.min.js.map \ No newline at end of file diff --git a/build/ringcentral.min.js.map b/build/ringcentral.min.js.map index 1aeaa407..e11d2021 100644 --- a/build/ringcentral.min.js.map +++ b/build/ringcentral.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["webpack:///webpack/universalModuleDefinition?5ca6","webpack:///ringcentral.min.js","webpack:///webpack/bootstrap 3e92ff87335340dc908b?ea2c","webpack:///./src/SDK.js?d032","webpack:///./~/object-assign/index.js?2927","webpack:///./src/core/Cache.js?1256","webpack:///./src/http/Client.js?4230","webpack:///./~/is-plain-object/index.js?2af1","webpack:///./~/isobject/index.js?cf96","webpack:///./~/events/events.js?7c71","webpack:///./src/http/ApiResponse.js?d4a4","webpack:///./~/querystring/index.js?fce8","webpack:///./~/querystring/decode.js?c250","webpack:///./~/querystring/encode.js?e86b","webpack:///./src/core/Externals.js?fdf1","webpack:///external {\"amd\":\"pubnub\"}?3fcf","webpack:///external {\"amd\":\"es6-promise\"}?8a6b","webpack:///external {\"amd\":\"fetch-ponyfill\"}?ec6e","webpack:///./src/platform/Platform.js?8f42","webpack:///./src/platform/Auth.js?cef5","webpack:///./src/core/Constants.js?22d0","webpack:///./src/subscription/Subscription.js?3ae8","webpack:///./src/subscription/CachedSubscription.js?3294"],"names":["root","factory","exports","module","require","undefined","define","amd","this","__WEBPACK_EXTERNAL_MODULE_12__","__WEBPACK_EXTERNAL_MODULE_13__","__WEBPACK_EXTERNAL_MODULE_14__","modules","__webpack_require__","moduleId","installedModules","id","loaded","call","m","c","p","SDK","options","_externals","Externals","_cache","Cache","externals","prefix","cachePrefix","_client","Client","_platform","Platform","objectAssign","client","cache","Subscription","CachedSubscription","Constants","version","server","sandbox","production","prototype","platform","createSubscription","createCachedSubscription","arguments","cacheKey","toString","handleLoginRedirect","origin","win","window","response","location","hash","search","msg","authResponseProperty","opener","postMessage","toObject","val","TypeError","Object","shouldUseNative","assign","test1","String","getOwnPropertyNames","test2","i","fromCharCode","order2","map","n","join","test3","split","forEach","letter","keys","err","getOwnPropertySymbols","hasOwnProperty","propIsEnumerable","propertyIsEnumerable","target","source","from","symbols","to","s","length","key","_prefix","defaultPrefix","setItem","data","localStorage","_prefixKey","JSON","stringify","removeItem","getItem","item","parse","clean","indexOf","findHeaderName","name","headers","toLowerCase","reduce","res","EventEmitter","events","beforeRequest","requestSuccess","requestError","isPlainObject","ApiResponse","qs","_allowedMethods","create","sendRequest","request","apiResponse","Promise","resolve","emit","_loadResponse","bind","then","receiveResponse","ok","Error","catch","e","makeError","fetch","originalMessage","message","error","createRequest","init","url","method","toUpperCase","credentials","mode","query","Accept","_jsonContentType","body","contentTypeHeaderName","_contentType","contentType","_urlencodedContentType","req","Request","originalBody","isObjectObject","o","isObject","ctor","prot","constructor","Array","isArray","_events","_maxListeners","isFunction","arg","isNumber","isUndefined","defaultMaxListeners","setMaxListeners","isNaN","type","er","handler","len","args","listeners","context","slice","apply","addListener","listener","newListener","push","warned","console","trace","on","once","g","removeListener","fired","list","position","splice","removeAllListeners","ret","listenerCount","evlistener","emitter","_request","_response","_text","responseText","_json","_multipart","_multipartContentType","_headerSeparator","_bodySeparator","_boundarySeparator","_unauthorizedStatus","_rateLimitStatus","_isMultipart","_isJson","text","json","skipOKCheck","status","statusText","error_description","description","toMultipart","multipart","boundary","_getContentType","match","parts","trim","shift","pop","statusInfo","_create","part","_isContentType","get","replace","Headers","headersAndBody","headersText","header","value","append","Response","decode","encode","obj","prop","sep","eq","regexp","maxKeys","kstr","vstr","k","v","x","idx","substr","decodeURIComponent","stringifyPrimitive","isFinite","ks","encodeURIComponent","global","PubNub","pubnub","es6Promise","fetchPonyfill","FetchPonyfill","beforeLogin","loginSuccess","loginError","beforeRefresh","refreshSuccess","refreshError","beforeLogout","logoutSuccess","logoutError","rateLimitError","_server","_appKey","appKey","_appSecret","appSecret","_redirectUri","redirectUri","_refreshDelayMs","refreshDelayMs","_clearCacheOnRefreshError","clearCacheOnRefreshError","_userAgent","appName","appVersion","_knownPrefixes","knownPrefixes","_refreshPromise","_auth","Auth","cacheId","_cacheId","refreshHandicapMs","_urlPrefix","_apiVersion","_tokenEndpoint","_revokeEndpoint","_authorizeEndpoint","delay","timeout","reject","setTimeout","auth","createUrl","path","builtUrl","hasHttp","alreadyPrefixed","some","addServer","addMethod","addToken","accessToken","loginUrl","response_type","implicit","redirect_uri","client_id","state","brand_id","brandId","display","prompt","parseLoginRedirect","getParts","separator","reverse","queryString","loginWindow","width","height","property","dualScreenLeft","screenLeft","screen","left","dualScreenTop","screenTop","top","innerWidth","document","documentElement","clientWidth","innerHeight","clientHeight","open","focus","eventMethod","addEventListener","eventRemoveMethod","messageEvent","eventListener","close","loginOptions","code","access_token","loggedIn","ensureLoggedIn","login","grant_type","username","password","extension","endpointId","endpoint_id","accessTokenTtl","access_token_ttl","refreshTokenTtl","refresh_token_ttl","_tokenRequest","setData","_refresh","refreshToken","refreshTokenValid","refresh_token","expires_in","refresh_token_expires_in","refresh","logout","token","inflateRequest","skipAuthCheck","set","_authHeader","retry","retryAfter","cancelAccessToken","defaultRetryAfter","handleRateLimit","parseFloat","send","post","put","_isAccessTokenValid","Authorization","_apiKey","Content-Type","accessTokenValid","apiKey","btoa","Buffer","tokenType","_refreshHandicapMs","token_type","newData","expire_time","Date","now","refresh_token_expire_time","authData","buildIEFriendlyString","$1","$2","parseISOString","time","ISO_REG_EXP","notification","removeSuccess","removeError","renewSuccess","renewError","subscribeSuccess","subscribeError","automaticRenewSuccess","automaticRenewError","_pollInterval","pollInterval","_renewHandicapMs","renewHandicapMs","_pubnub","_pubnubLastChannel","_pubnubLastSubscribeKey","_timeout","_subscription","subscribed","subscription","deliveryMode","subscriberKey","address","alive","expirationTime","expired","setSubscription","_clearTimeout","_setSubscription","_subscribeAtPubnub","_setTimeout","register","renew","subscribe","eventFilters","addEventFilters","setEventFilters","concat","_getFullEventFilters","transportType","reset","remove","delete","resubscribe","filters","_unsubscribeAtPubnub","event","setInterval","clearInterval","_decrypt","encryptionKey","decrypt","encryptKey","keyEncoding","keyLength","_notify","unsubscribeAll","ssl","restore","subscribeKey","statusEvent","channels","destroy","_cacheKey"],"mappings":"CAAA,SAAAA,EAAAC,GACA,gBAAAC,UAAA,gBAAAC,QACAA,OAAAD,QAAAD,EAAAG,QAAAC,QAAAD,QAAAC,QAAAD,QAAAC,SACA,kBAAAC,gBAAAC,IACAD,QAAA,yCAAA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tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory(require(undefined), require(undefined), require(undefined));\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([\"pubnub\", \"es6-promise\", \"fetch-ponyfill\"], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"SDK\"] = factory(require(undefined), require(undefined), require(undefined));\n\telse\n\t\troot[\"RingCentral\"] = root[\"RingCentral\"] || {}, root[\"RingCentral\"][\"SDK\"] = factory(root[undefined], root[undefined], root[undefined]);\n})(this, function(__WEBPACK_EXTERNAL_MODULE_12__, __WEBPACK_EXTERNAL_MODULE_13__, __WEBPACK_EXTERNAL_MODULE_14__) {\nreturn \n\n\n// WEBPACK FOOTER //\n// webpack/universalModuleDefinition","(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory(require(undefined), require(undefined), require(undefined));\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([\"pubnub\", \"es6-promise\", \"fetch-ponyfill\"], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"SDK\"] = factory(require(undefined), require(undefined), require(undefined));\n\telse\n\t\troot[\"RingCentral\"] = root[\"RingCentral\"] || {}, root[\"RingCentral\"][\"SDK\"] = factory(root[undefined], root[undefined], root[undefined]);\n})(this, function(__WEBPACK_EXTERNAL_MODULE_12__, __WEBPACK_EXTERNAL_MODULE_13__, __WEBPACK_EXTERNAL_MODULE_14__) {\nreturn /******/ (function(modules) { // webpackBootstrap\n/******/ \t// The module cache\n/******/ \tvar installedModules = {};\n/******/\n/******/ \t// The require function\n/******/ \tfunction __webpack_require__(moduleId) {\n/******/\n/******/ \t\t// Check if module is in cache\n/******/ \t\tif(installedModules[moduleId])\n/******/ \t\t\treturn installedModules[moduleId].exports;\n/******/\n/******/ \t\t// Create a new module (and put it into the cache)\n/******/ \t\tvar module = installedModules[moduleId] = {\n/******/ \t\t\texports: {},\n/******/ \t\t\tid: moduleId,\n/******/ \t\t\tloaded: false\n/******/ \t\t};\n/******/\n/******/ \t\t// Execute the module function\n/******/ \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n/******/\n/******/ \t\t// Flag the module as loaded\n/******/ \t\tmodule.loaded = true;\n/******/\n/******/ \t\t// Return the exports of the module\n/******/ \t\treturn module.exports;\n/******/ \t}\n/******/\n/******/\n/******/ \t// expose the modules object (__webpack_modules__)\n/******/ \t__webpack_require__.m = modules;\n/******/\n/******/ \t// expose the module cache\n/******/ \t__webpack_require__.c = installedModules;\n/******/\n/******/ \t// __webpack_public_path__\n/******/ \t__webpack_require__.p = \"/build/\";\n/******/\n/******/ \t// Load entry module and return exports\n/******/ \treturn __webpack_require__(0);\n/******/ })\n/************************************************************************/\n/******/ ([\n/* 0 */\n/***/ function(module, exports, __webpack_require__) {\n\n/**\n * @namespace RingCentral\n */\nvar objectAssign = __webpack_require__(1);\nvar Cache = __webpack_require__(2);\nvar Client = __webpack_require__(3);\nvar Externals = __webpack_require__(11);\nvar Platform = __webpack_require__(15);\nvar Subscription = __webpack_require__(18);\nvar CachedSubscription = __webpack_require__(19);\nvar Constants = __webpack_require__(17);\n\n/**\n * @constructor\n * @param {string} options.server\n * @param {string} options.appSecret\n * @param {string} options.appKey\n * @param {string} [options.cachePrefix]\n * @param {string} [options.appName]\n * @param {string} [options.appVersion]\n * @param {string} [options.redirectUri]\n * @param {PubNub} [options.PubNub]\n * @param {function(new:Promise)} [options.Promise]\n * @param {Storage} [options.localStorage]\n * @param {fetch} [options.fetch]\n * @param {function(new:Request)} [options.Request]\n * @param {function(new:Response)} [options.Response]\n * @param {function(new:Headers)} [options.Headers]\n * @param {int} [options.refreshDelayMs]\n * @param {int} [options.refreshHandicapMs]\n * @param {boolean} [options.clearCacheOnRefreshError]\n * @property {Externals} _externals\n * @property {Cache} _cache\n * @property {Client} _client\n * @property {Platform} _platform\n */\nfunction SDK(options) {\n\n /** @private */\n this._externals = new Externals(options);\n\n /** @private */\n this._cache = new Cache({\n externals: this._externals,\n prefix: options.cachePrefix\n });\n\n /** @private */\n this._client = new Client(this._externals);\n\n /** @private */\n this._platform = new Platform(objectAssign({}, options, {\n externals: this._externals,\n client: this._client,\n cache: this._cache\n }));\n\n}\n\nSDK.version = Constants.version;\n\nSDK.server = {\n sandbox: 'https://platform.devtest.ringcentral.com',\n production: 'https://platform.ringcentral.com'\n};\n\n/**\n * @return {Platform}\n */\nSDK.prototype.platform = function() {\n return this._platform;\n};\n\n/**\n * @return {Cache}\n */\nSDK.prototype.cache = function() {\n return this._cache;\n};\n\n/**\n * @param {int} [options.pollInterval]\n * @param {int} [options.renewHandicapMs]\n * @return {Subscription}\n */\nSDK.prototype.createSubscription = function(options) {\n return new Subscription(objectAssign({}, options, {\n externals: this._externals,\n platform: this._platform\n }));\n};\n\n/**\n * @param {string} options.cacheKey\n * @param {int} [options.pollInterval]\n * @param {int} [options.renewHandicapMs]\n * @return {CachedSubscription}\n */\nSDK.prototype.createCachedSubscription = function(options) {\n\n if (typeof arguments[0] === 'string') {\n options = {cacheKey: arguments[0].toString()};\n } else {\n options = options || {};\n }\n\n return new CachedSubscription(objectAssign({}, options, {\n externals: this._externals,\n platform: this._platform,\n cache: this._cache\n }));\n\n};\n\nSDK.handleLoginRedirect = function(origin, win) {\n\n win = win || window;\n\n var response = win.location.hash ? win.location.hash : win.location.search;\n var msg = {};\n msg[Constants.authResponseProperty] = response;\n win.opener.postMessage(msg, origin || win.location.origin);\n\n};\n\nmodule.exports = SDK;\n\n/***/ },\n/* 1 */\n/***/ function(module, exports) {\n\n/*\nobject-assign\n(c) Sindre Sorhus\n@license MIT\n*/\n\n'use strict';\n/* eslint-disable no-unused-vars */\nvar getOwnPropertySymbols = Object.getOwnPropertySymbols;\nvar hasOwnProperty = Object.prototype.hasOwnProperty;\nvar propIsEnumerable = Object.prototype.propertyIsEnumerable;\n\nfunction toObject(val) {\n\tif (val === null || val === undefined) {\n\t\tthrow new TypeError('Object.assign cannot be called with null or undefined');\n\t}\n\n\treturn Object(val);\n}\n\nfunction shouldUseNative() {\n\ttry {\n\t\tif (!Object.assign) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Detect buggy property enumeration order in older V8 versions.\n\n\t\t// https://bugs.chromium.org/p/v8/issues/detail?id=4118\n\t\tvar test1 = new String('abc'); // eslint-disable-line no-new-wrappers\n\t\ttest1[5] = 'de';\n\t\tif (Object.getOwnPropertyNames(test1)[0] === '5') {\n\t\t\treturn false;\n\t\t}\n\n\t\t// https://bugs.chromium.org/p/v8/issues/detail?id=3056\n\t\tvar test2 = {};\n\t\tfor (var i = 0; i < 10; i++) {\n\t\t\ttest2['_' + String.fromCharCode(i)] = i;\n\t\t}\n\t\tvar order2 = Object.getOwnPropertyNames(test2).map(function (n) {\n\t\t\treturn test2[n];\n\t\t});\n\t\tif (order2.join('') !== '0123456789') {\n\t\t\treturn false;\n\t\t}\n\n\t\t// https://bugs.chromium.org/p/v8/issues/detail?id=3056\n\t\tvar test3 = {};\n\t\t'abcdefghijklmnopqrst'.split('').forEach(function (letter) {\n\t\t\ttest3[letter] = letter;\n\t\t});\n\t\tif (Object.keys(Object.assign({}, test3)).join('') !==\n\t\t\t\t'abcdefghijklmnopqrst') {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn true;\n\t} catch (err) {\n\t\t// We don't expect any of the above to throw, but better to be safe.\n\t\treturn false;\n\t}\n}\n\nmodule.exports = shouldUseNative() ? Object.assign : function (target, source) {\n\tvar from;\n\tvar to = toObject(target);\n\tvar symbols;\n\n\tfor (var s = 1; s < arguments.length; s++) {\n\t\tfrom = Object(arguments[s]);\n\n\t\tfor (var key in from) {\n\t\t\tif (hasOwnProperty.call(from, key)) {\n\t\t\t\tto[key] = from[key];\n\t\t\t}\n\t\t}\n\n\t\tif (getOwnPropertySymbols) {\n\t\t\tsymbols = getOwnPropertySymbols(from);\n\t\t\tfor (var i = 0; i < symbols.length; i++) {\n\t\t\t\tif (propIsEnumerable.call(from, symbols[i])) {\n\t\t\t\t\tto[symbols[i]] = from[symbols[i]];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn to;\n};\n\n\n/***/ },\n/* 2 */\n/***/ function(module, exports) {\n\n/**\n * @param {Externals} options.externals\n * @param {string} [options.prefix]\n * @property {Externals} _externals\n */\nfunction Cache(options) {\n\n /** @private */\n this._prefix = options.prefix || Cache.defaultPrefix;\n\n /** @private */\n this._externals = options.externals;\n\n}\n\nCache.defaultPrefix = 'rc-';\n\nCache.prototype.setItem = function(key, data) {\n this._externals.localStorage[this._prefixKey(key)] = JSON.stringify(data);\n return this;\n};\n\nCache.prototype.removeItem = function(key) {\n delete this._externals.localStorage[this._prefixKey(key)];\n return this;\n};\n\nCache.prototype.getItem = function(key) {\n var item = this._externals.localStorage[this._prefixKey(key)];\n if (!item) return null;\n return JSON.parse(item);\n};\n\nCache.prototype.clean = function() {\n\n for (var key in this._externals.localStorage) {\n\n /* istanbul ignore next */\n if (!this._externals.localStorage.hasOwnProperty(key)) continue;\n\n if (key.indexOf(this._prefix) === 0) {\n delete this._externals.localStorage[key];\n }\n\n }\n\n return this;\n\n};\n\nCache.prototype._prefixKey = function(key) {\n return this._prefix + key;\n};\n\nmodule.exports = Cache;\n\n/***/ },\n/* 3 */\n/***/ function(module, exports, __webpack_require__) {\n\nvar isPlainObject = __webpack_require__(4);\nvar EventEmitter = __webpack_require__(6).EventEmitter;\nvar ApiResponse = __webpack_require__(7);\nvar qs = __webpack_require__(8);\n\nfunction 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 * @param {Externals} externals\n * @property {Externals} _externals\n */\nfunction Client(externals) {\n\n EventEmitter.call(this);\n\n /** @private */\n this._externals = externals;\n\n this.events = {\n beforeRequest: 'beforeRequest',\n requestSuccess: 'requestSuccess',\n requestError: 'requestError'\n };\n\n}\n\nClient._allowedMethods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS', 'HEAD'];\n\nClient.prototype = Object.create(EventEmitter.prototype);\n\n/**\n * @param {Request} request\n * @return {Promise}\n */\nClient.prototype.sendRequest = function(request) {\n\n var apiResponse = new ApiResponse({\n externals: this._externals,\n request: request\n });\n\n return (new this._externals.Promise(function(resolve) {\n\n //TODO Stop request if listeners return false\n this.emit(this.events.beforeRequest, apiResponse);\n\n resolve(this._loadResponse(request));\n\n }.bind(this))).then(function(response) {\n\n return apiResponse.receiveResponse(response);\n\n }).then(function() {\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 }.bind(this)).catch(function(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 }.bind(this));\n\n};\n\n/**\n * @param {Request} request\n * @return {Promise}\n * @private\n */\nClient.prototype._loadResponse = function(request) {\n return this._externals.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 */\nClient.prototype.makeError = function(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 * @param {object} [init.credentials]\n * @param {object} [init.mode]\n * @return {Request}\n */\nClient.prototype.createRequest = function(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 init.method = init.method.toUpperCase();\n if (init.method && Client._allowedMethods.indexOf(init.method) < 0) {\n throw new Error('Method has wrong value: ' + init.method);\n }\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 ? '&' : '?') + qs.stringify(init.query);\n }\n\n if (!(findHeaderName('Accept', init.headers))) {\n init.headers.Accept = ApiResponse._jsonContentType;\n }\n\n // Serialize body\n if (isPlainObject(init.body) || !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 if ((init.method === 'GET' || init.method === 'HEAD') && !!init.body) {\n // oddly setting body to null still result in TypeError in phantomjs\n init.body = undefined;\n } else {\n init.body = JSON.stringify(init.body);\n }\n\n } else if (contentType.indexOf(ApiResponse._urlencodedContentType) > -1) {\n init.body = qs.stringify(init.body);\n }\n\n }\n\n // Create a request with encoded body\n var req = new this._externals.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 * @typedef {object} IApiError\n * @property {string} stack\n * @property {string} originalMessage\n * @property {ApiResponse} apiResponse\n */\n\nmodule.exports = Client;\n\n/***/ },\n/* 4 */\n/***/ function(module, exports, __webpack_require__) {\n\n/*!\n * is-plain-object \n *\n * Copyright (c) 2014-2017, Jon Schlinkert.\n * Released under the MIT License.\n */\n\n'use strict';\n\nvar isObject = __webpack_require__(5);\n\nfunction isObjectObject(o) {\n return isObject(o) === true\n && Object.prototype.toString.call(o) === '[object Object]';\n}\n\nmodule.exports = function isPlainObject(o) {\n var ctor,prot;\n\n if (isObjectObject(o) === false) return false;\n\n // If has modified constructor\n ctor = o.constructor;\n if (typeof ctor !== 'function') return false;\n\n // If has modified prototype\n prot = ctor.prototype;\n if (isObjectObject(prot) === false) return false;\n\n // If constructor does not have an Object-specific method\n if (prot.hasOwnProperty('isPrototypeOf') === false) {\n return false;\n }\n\n // Most likely a plain Object\n return true;\n};\n\n\n/***/ },\n/* 5 */\n/***/ function(module, exports) {\n\n/*!\n * isobject \n *\n * Copyright (c) 2014-2017, Jon Schlinkert.\n * Released under the MIT License.\n */\n\n'use strict';\n\nmodule.exports = function isObject(val) {\n return val != null && typeof val === 'object' && Array.isArray(val) === false;\n};\n\n\n/***/ },\n/* 6 */\n/***/ function(module, exports) {\n\n// Copyright Joyent, Inc. and other Node contributors.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a\n// copy of this software and associated documentation files (the\n// \"Software\"), to deal in the Software without restriction, including\n// without limitation the rights to use, copy, modify, merge, publish,\n// distribute, sublicense, and/or sell copies of the Software, and to permit\n// persons to whom the Software is furnished to do so, subject to the\n// following conditions:\n//\n// The above copyright notice and this permission notice shall be included\n// in all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\n// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN\n// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,\n// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE\n// USE OR OTHER DEALINGS IN THE SOFTWARE.\n\nfunction EventEmitter() {\n this._events = this._events || {};\n this._maxListeners = this._maxListeners || undefined;\n}\nmodule.exports = EventEmitter;\n\n// Backwards-compat with node 0.10.x\nEventEmitter.EventEmitter = EventEmitter;\n\nEventEmitter.prototype._events = undefined;\nEventEmitter.prototype._maxListeners = undefined;\n\n// By default EventEmitters will print a warning if more than 10 listeners are\n// added to it. This is a useful default which helps finding memory leaks.\nEventEmitter.defaultMaxListeners = 10;\n\n// Obviously not all Emitters should be limited to 10. This function allows\n// that to be increased. Set to zero for unlimited.\nEventEmitter.prototype.setMaxListeners = function(n) {\n if (!isNumber(n) || n < 0 || isNaN(n))\n throw TypeError('n must be a positive number');\n this._maxListeners = n;\n return this;\n};\n\nEventEmitter.prototype.emit = function(type) {\n var er, handler, len, args, i, listeners;\n\n if (!this._events)\n this._events = {};\n\n // If there is no 'error' event listener then throw.\n if (type === 'error') {\n if (!this._events.error ||\n (isObject(this._events.error) && !this._events.error.length)) {\n er = arguments[1];\n if (er instanceof Error) {\n throw er; // Unhandled 'error' event\n } else {\n // At least give some kind of context to the user\n var err = new Error('Uncaught, unspecified \"error\" event. (' + er + ')');\n err.context = er;\n throw err;\n }\n }\n }\n\n handler = this._events[type];\n\n if (isUndefined(handler))\n return false;\n\n if (isFunction(handler)) {\n switch (arguments.length) {\n // fast cases\n case 1:\n handler.call(this);\n break;\n case 2:\n handler.call(this, arguments[1]);\n break;\n case 3:\n handler.call(this, arguments[1], arguments[2]);\n break;\n // slower\n default:\n args = Array.prototype.slice.call(arguments, 1);\n handler.apply(this, args);\n }\n } else if (isObject(handler)) {\n args = Array.prototype.slice.call(arguments, 1);\n listeners = handler.slice();\n len = listeners.length;\n for (i = 0; i < len; i++)\n listeners[i].apply(this, args);\n }\n\n return true;\n};\n\nEventEmitter.prototype.addListener = function(type, listener) {\n var m;\n\n if (!isFunction(listener))\n throw TypeError('listener must be a function');\n\n if (!this._events)\n this._events = {};\n\n // To avoid recursion in the case that type === \"newListener\"! Before\n // adding it to the listeners, first emit \"newListener\".\n if (this._events.newListener)\n this.emit('newListener', type,\n isFunction(listener.listener) ?\n listener.listener : listener);\n\n if (!this._events[type])\n // Optimize the case of one listener. Don't need the extra array object.\n this._events[type] = listener;\n else if (isObject(this._events[type]))\n // If we've already got an array, just append.\n this._events[type].push(listener);\n else\n // Adding the second element, need to change to array.\n this._events[type] = [this._events[type], listener];\n\n // Check for listener leak\n if (isObject(this._events[type]) && !this._events[type].warned) {\n if (!isUndefined(this._maxListeners)) {\n m = this._maxListeners;\n } else {\n m = EventEmitter.defaultMaxListeners;\n }\n\n if (m && m > 0 && this._events[type].length > m) {\n this._events[type].warned = true;\n console.error('(node) warning: possible EventEmitter memory ' +\n 'leak detected. %d listeners added. ' +\n 'Use emitter.setMaxListeners() to increase limit.',\n this._events[type].length);\n if (typeof console.trace === 'function') {\n // not supported in IE 10\n console.trace();\n }\n }\n }\n\n return this;\n};\n\nEventEmitter.prototype.on = EventEmitter.prototype.addListener;\n\nEventEmitter.prototype.once = function(type, listener) {\n if (!isFunction(listener))\n throw TypeError('listener must be a function');\n\n var fired = false;\n\n function g() {\n this.removeListener(type, g);\n\n if (!fired) {\n fired = true;\n listener.apply(this, arguments);\n }\n }\n\n g.listener = listener;\n this.on(type, g);\n\n return this;\n};\n\n// emits a 'removeListener' event iff the listener was removed\nEventEmitter.prototype.removeListener = function(type, listener) {\n var list, position, length, i;\n\n if (!isFunction(listener))\n throw TypeError('listener must be a function');\n\n if (!this._events || !this._events[type])\n return this;\n\n list = this._events[type];\n length = list.length;\n position = -1;\n\n if (list === listener ||\n (isFunction(list.listener) && list.listener === listener)) {\n delete this._events[type];\n if (this._events.removeListener)\n this.emit('removeListener', type, listener);\n\n } else if (isObject(list)) {\n for (i = length; i-- > 0;) {\n if (list[i] === listener ||\n (list[i].listener && list[i].listener === listener)) {\n position = i;\n break;\n }\n }\n\n if (position < 0)\n return this;\n\n if (list.length === 1) {\n list.length = 0;\n delete this._events[type];\n } else {\n list.splice(position, 1);\n }\n\n if (this._events.removeListener)\n this.emit('removeListener', type, listener);\n }\n\n return this;\n};\n\nEventEmitter.prototype.removeAllListeners = function(type) {\n var key, listeners;\n\n if (!this._events)\n return this;\n\n // not listening for removeListener, no need to emit\n if (!this._events.removeListener) {\n if (arguments.length === 0)\n this._events = {};\n else if (this._events[type])\n delete this._events[type];\n return this;\n }\n\n // emit removeListener for all listeners on all events\n if (arguments.length === 0) {\n for (key in this._events) {\n if (key === 'removeListener') continue;\n this.removeAllListeners(key);\n }\n this.removeAllListeners('removeListener');\n this._events = {};\n return this;\n }\n\n listeners = this._events[type];\n\n if (isFunction(listeners)) {\n this.removeListener(type, listeners);\n } else if (listeners) {\n // LIFO order\n while (listeners.length)\n this.removeListener(type, listeners[listeners.length - 1]);\n }\n delete this._events[type];\n\n return this;\n};\n\nEventEmitter.prototype.listeners = function(type) {\n var ret;\n if (!this._events || !this._events[type])\n ret = [];\n else if (isFunction(this._events[type]))\n ret = [this._events[type]];\n else\n ret = this._events[type].slice();\n return ret;\n};\n\nEventEmitter.prototype.listenerCount = function(type) {\n if (this._events) {\n var evlistener = this._events[type];\n\n if (isFunction(evlistener))\n return 1;\n else if (evlistener)\n return evlistener.length;\n }\n return 0;\n};\n\nEventEmitter.listenerCount = function(emitter, type) {\n return emitter.listenerCount(type);\n};\n\nfunction isFunction(arg) {\n return typeof arg === 'function';\n}\n\nfunction isNumber(arg) {\n return typeof arg === 'number';\n}\n\nfunction isObject(arg) {\n return typeof arg === 'object' && arg !== null;\n}\n\nfunction isUndefined(arg) {\n return arg === void 0;\n}\n\n\n/***/ },\n/* 7 */\n/***/ function(module, exports) {\n\n/**\n * @param {Externals} options.externals\n * @param {Request} [options.request]\n * @param {Response} [options.response]\n * @param {string} [options.responseText]\n * @property {Externals} _externals\n * @property {Request} _request\n * @property {Response} _response\n * @property {string} _text\n * @property {object} _json\n * @property {ApiResponse[]} _multipart\n */\nfunction ApiResponse(options) {\n\n /** @private */\n this._externals = options.externals;\n\n /** @private */\n this._request = options.request;\n\n /** @private */\n this._response = options.response;\n\n /** @private */\n this._text = options.responseText || '';\n\n /** @private */\n this._json = null;\n\n /** @private */\n this._multipart = [];\n\n}\n\nApiResponse._contentType = 'Content-Type';\nApiResponse._jsonContentType = 'application/json';\nApiResponse._multipartContentType = 'multipart/mixed';\nApiResponse._urlencodedContentType = 'application/x-www-form-urlencoded';\nApiResponse._headerSeparator = ':';\nApiResponse._bodySeparator = '\\n\\n';\nApiResponse._boundarySeparator = '--';\nApiResponse._unauthorizedStatus = 401;\nApiResponse._rateLimitStatus = 429;\n\n/**\n * @param {Response} response\n * @return {Promise}\n */\nApiResponse.prototype.receiveResponse = function(response) {\n\n this._response = response;\n\n return (new this._externals.Promise(function(resolve) {\n\n // Ignore if not textual type\n if (!this._isMultipart() && !this._isJson()) return resolve('');\n\n return resolve(this.response().text());\n\n }.bind(this))).then(function(text) {\n\n this._text = text;\n return text;\n\n }.bind(this));\n\n};\n\n/**\n * @return {Response}\n */\nApiResponse.prototype.response = function() {\n return this._response;\n};\n\n/**\n * @return {Request}\n */\nApiResponse.prototype.request = function() {\n return this._request;\n};\n\n/**\n * @return {boolean}\n */\nApiResponse.prototype.ok = function() {\n return this._response && this._response.ok;\n};\n\n/**\n * @return {string}\n */\nApiResponse.prototype.text = function() {\n // Since we read text only in case JSON or Multipart\n if (!this._isJson() && !this._isMultipart()) throw new Error('Response is not text');\n return this._text;\n};\n\n/**\n * @return {object}\n */\nApiResponse.prototype.json = function() {\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 */\nApiResponse.prototype.error = function(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 * If it is not known upfront what would be the response, client code can treat any response as multipart\n * @return {ApiResponse[]}\n */\nApiResponse.prototype.toMultipart = function() {\n if (!this._isMultipart()) return [this];\n return this.multipart();\n};\n\n/**\n * @return {ApiResponse[]}\n */\nApiResponse.prototype.multipart = function() {\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;\n\n try {\n boundary = this._getContentType().match(/boundary=([^;]+)/i)[1];\n } catch (e) {\n throw new Error('Cannot find boundary');\n }\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 = this._create(parts.shift(), this._response.status, this._response.statusText).json();\n\n // Step 3. Parse all other parts\n\n this._multipart = parts.map(function(part, i) {\n\n var status = statusInfo.response[i].status;\n\n return this._create(part, status);\n\n }.bind(this));\n\n }\n\n return this._multipart;\n\n};\n\n/**\n * @private\n */\nApiResponse.prototype._isContentType = function(contentType) {\n return this._getContentType().indexOf(contentType) > -1;\n};\n\n/**\n * @private\n */\nApiResponse.prototype._getContentType = function() {\n return this._response.headers.get(ApiResponse._contentType) || '';\n};\n\n/**\n * @private\n */\nApiResponse.prototype._isMultipart = function() {\n return this._isContentType(ApiResponse._multipartContentType);\n};\n\n/**\n * @private\n */\nApiResponse.prototype._isJson = function() {\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 * @private\n * @return {ApiResponse}\n */\nApiResponse.prototype._create = function(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 this._externals.Headers(),\n headersAndBody = text.split(ApiResponse._bodySeparator),\n headersText = (headersAndBody.length > 1) ? headersAndBody.shift() : '';\n\n text = headersAndBody.length > 0 ? headersAndBody.join(ApiResponse._bodySeparator) : null;\n\n (headersText || '')\n .split('\\n')\n .forEach(function(header) {\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 var response = new this._externals.Response(text, {\n headers: headers,\n status: status,\n statusText: statusText\n });\n\n return new ApiResponse({\n externals: this._externals,\n request: null,\n response: response,\n responseText: text\n });\n\n};\n\nmodule.exports = ApiResponse;\n\n/***/ },\n/* 8 */\n/***/ function(module, exports, __webpack_require__) {\n\n'use strict';\n\nexports.decode = exports.parse = __webpack_require__(9);\nexports.encode = exports.stringify = __webpack_require__(10);\n\n\n/***/ },\n/* 9 */\n/***/ function(module, exports) {\n\n// Copyright Joyent, Inc. and other Node contributors.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a\n// copy of this software and associated documentation files (the\n// \"Software\"), to deal in the Software without restriction, including\n// without limitation the rights to use, copy, modify, merge, publish,\n// distribute, sublicense, and/or sell copies of the Software, and to permit\n// persons to whom the Software is furnished to do so, subject to the\n// following conditions:\n//\n// The above copyright notice and this permission notice shall be included\n// in all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\n// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN\n// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,\n// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE\n// USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n'use strict';\n\n// If obj.hasOwnProperty has been overridden, then calling\n// obj.hasOwnProperty(prop) will break.\n// See: https://github.com/joyent/node/issues/1707\nfunction hasOwnProperty(obj, prop) {\n return Object.prototype.hasOwnProperty.call(obj, prop);\n}\n\nmodule.exports = function(qs, sep, eq, options) {\n sep = sep || '&';\n eq = eq || '=';\n var obj = {};\n\n if (typeof qs !== 'string' || qs.length === 0) {\n return obj;\n }\n\n var regexp = /\\+/g;\n qs = qs.split(sep);\n\n var maxKeys = 1000;\n if (options && typeof options.maxKeys === 'number') {\n maxKeys = options.maxKeys;\n }\n\n var len = qs.length;\n // maxKeys <= 0 means that we should not limit keys count\n if (maxKeys > 0 && len > maxKeys) {\n len = maxKeys;\n }\n\n for (var i = 0; i < len; ++i) {\n var x = qs[i].replace(regexp, '%20'),\n idx = x.indexOf(eq),\n kstr, vstr, k, v;\n\n if (idx >= 0) {\n kstr = x.substr(0, idx);\n vstr = x.substr(idx + 1);\n } else {\n kstr = x;\n vstr = '';\n }\n\n k = decodeURIComponent(kstr);\n v = decodeURIComponent(vstr);\n\n if (!hasOwnProperty(obj, k)) {\n obj[k] = v;\n } else if (Array.isArray(obj[k])) {\n obj[k].push(v);\n } else {\n obj[k] = [obj[k], v];\n }\n }\n\n return obj;\n};\n\n\n/***/ },\n/* 10 */\n/***/ function(module, exports) {\n\n// Copyright Joyent, Inc. and other Node contributors.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a\n// copy of this software and associated documentation files (the\n// \"Software\"), to deal in the Software without restriction, including\n// without limitation the rights to use, copy, modify, merge, publish,\n// distribute, sublicense, and/or sell copies of the Software, and to permit\n// persons to whom the Software is furnished to do so, subject to the\n// following conditions:\n//\n// The above copyright notice and this permission notice shall be included\n// in all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\n// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN\n// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,\n// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE\n// USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n'use strict';\n\nvar stringifyPrimitive = function(v) {\n switch (typeof v) {\n case 'string':\n return v;\n\n case 'boolean':\n return v ? 'true' : 'false';\n\n case 'number':\n return isFinite(v) ? v : '';\n\n default:\n return '';\n }\n};\n\nmodule.exports = function(obj, sep, eq, name) {\n sep = sep || '&';\n eq = eq || '=';\n if (obj === null) {\n obj = undefined;\n }\n\n if (typeof obj === 'object') {\n return Object.keys(obj).map(function(k) {\n var ks = encodeURIComponent(stringifyPrimitive(k)) + eq;\n if (Array.isArray(obj[k])) {\n return obj[k].map(function(v) {\n return ks + encodeURIComponent(stringifyPrimitive(v));\n }).join(sep);\n } else {\n return ks + encodeURIComponent(stringifyPrimitive(obj[k]));\n }\n }).join(sep);\n\n }\n\n if (!name) return '';\n return encodeURIComponent(stringifyPrimitive(name)) + eq +\n encodeURIComponent(stringifyPrimitive(obj));\n};\n\n\n/***/ },\n/* 11 */\n/***/ function(module, exports, __webpack_require__) {\n\n/* WEBPACK VAR INJECTION */(function(global) {var pubnub = __webpack_require__(12);\nvar es6Promise = __webpack_require__(13);\nvar FetchPonyfill = __webpack_require__(14);\n\nvar root = (typeof window !== \"undefined\" && window) ||\n (typeof global !== \"undefined\" && global) ||\n (function(){ return this; })();\n\n/**\n * @constructor\n * @param {PubNub} [options.PubNub]\n * @param {function(new:Promise)} [options.Promise]\n * @param {Storage} [options.localStorage]\n * @param {fetch} [options.fetch]\n * @param {function(new:Request)} [options.Request]\n * @param {function(new:Response)} [options.Response]\n * @param {function(new:Headers)} [options.Headers]\n * @property {PubNub} PubNub\n * @property {Storage} localStorage\n * @property {function(new:Promise)} Promise\n * @property {fetch} fetch\n * @property {function(new:Request)} Request\n * @property {function(new:Response)} Response\n * @property {function(new:Headers)} Headers\n */\nfunction Externals(options) {\n\n options = options || {};\n\n this.PubNub = options.PubNub || root.PubNub || pubnub;\n this.localStorage = options.localStorage || ((typeof root.localStorage !== 'undefined') ? root.localStorage : {});\n this.Promise = options.Promise || root.Promise || (es6Promise && es6Promise.Promise);\n\n var fetchPonyfill = FetchPonyfill ? FetchPonyfill({Promise: this.Promise}) : {};\n\n this.fetch = options.fetch || root.fetch || fetchPonyfill.fetch;\n this.Request = options.Request || root.Request || fetchPonyfill.Request;\n this.Response = options.Response || root.Response || fetchPonyfill.Response;\n this.Headers = options.Headers || root.Headers || fetchPonyfill.Headers;\n\n /* istanbul ignore next */\n if (!this.fetch || !this.Response || !this.Request || !this.Headers) {\n throw new Error('Fetch API is missing');\n }\n\n /* istanbul ignore next */\n if (!this.Promise) {\n throw new Error('Promise is missing');\n }\n\n /* istanbul ignore next */\n if (!this.localStorage) {\n throw new Error('LocalStorage is missing');\n }\n\n /* istanbul ignore next */\n if (!this.PubNub) {\n throw new Error('PubNub is missing');\n }\n\n}\n\nmodule.exports = Externals;\n\n/* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))\n\n/***/ },\n/* 12 */\n/***/ function(module, exports) {\n\nmodule.exports = __WEBPACK_EXTERNAL_MODULE_12__;\n\n/***/ },\n/* 13 */\n/***/ function(module, exports) {\n\nmodule.exports = __WEBPACK_EXTERNAL_MODULE_13__;\n\n/***/ },\n/* 14 */\n/***/ function(module, exports) {\n\nmodule.exports = __WEBPACK_EXTERNAL_MODULE_14__;\n\n/***/ },\n/* 15 */\n/***/ function(module, exports, __webpack_require__) {\n\nvar EventEmitter = __webpack_require__(6).EventEmitter;\nvar qs = __webpack_require__(8);\nvar objectAssign = __webpack_require__(1);\nvar Auth = __webpack_require__(16);\nvar Constants = __webpack_require__(17);\nvar ApiResponse = __webpack_require__(7);\n\n/**\n * @constructor\n * @param {string} options.server\n * @param {string} options.appSecret\n * @param {string} options.appKey\n * @param {string} [options.appName]\n * @param {string} [options.appVersion]\n * @param {string} [options.redirectUri]\n * @param {int} [options.refreshDelayMs]\n * @param {int} [options.refreshHandicapMs]\n * @param {boolean} [options.clearCacheOnRefreshError]\n * @param {Externals} options.externals\n * @param {Cache} options.cache\n * @param {Client} options.client\n * @property {Externals} _externals\n * @property {Cache} _cache\n * @property {Client} _client\n * @property {Promise} _refreshPromise\n * @property {Auth} _auth\n */\nfunction Platform(options) {\n\n EventEmitter.call(this);\n\n this.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 rateLimitError: 'rateLimitError'\n };\n\n options = options || {};\n\n /** @private */\n this._server = options.server;\n\n /** @private */\n this._appKey = options.appKey;\n\n /** @private */\n this._appSecret = options.appSecret;\n\n /** @private */\n this._redirectUri = options.redirectUri || '';\n\n /** @private */\n this._refreshDelayMs = options.refreshDelayMs || 100;\n\n /** @private */\n this._clearCacheOnRefreshError = typeof options.clearCacheOnRefreshError !== 'undefined' ?\n options.clearCacheOnRefreshError :\n true;\n\n /** @private */\n this._userAgent = (options.appName ?\n (options.appName + (options.appVersion ? '/' + options.appVersion : '')) + ' ' :\n '') + 'RCJSSDK/' + Constants.version;\n\n /** @private */\n this._externals = options.externals;\n\n /** @private */\n this._cache = options.cache;\n\n /** @private */\n this._client = options.client;\n\n /** @private */\n this._knownPrefixes = options.knownPrefixes || Platform._knownPrefixes;\n\n\n /** @private */\n this._refreshPromise = null;\n\n /** @private */\n this._auth = new Auth({\n cache: this._cache,\n cacheId: Platform._cacheId,\n refreshHandicapMs: options.refreshHandicapMs\n });\n\n}\n\nPlatform._urlPrefix = '/restapi';\nPlatform._apiVersion = 'v1.0';\nPlatform._knownPrefixes = ['/rcvideo'];\nPlatform._tokenEndpoint = '/restapi/oauth/token';\nPlatform._revokeEndpoint = '/restapi/oauth/revoke';\nPlatform._authorizeEndpoint = '/restapi/oauth/authorize';\nPlatform._cacheId = 'platform';\n\nPlatform.prototype = Object.create(EventEmitter.prototype);\n\nPlatform.prototype.delay = function(timeout) {\n return new this._externals.Promise(function(resolve, reject) {\n setTimeout(function() {\n resolve(null);\n }, timeout);\n });\n};\n\n/**\n * @return {Auth}\n */\nPlatform.prototype.auth = function() {\n return this._auth;\n};\n\n/**\n * @return {Client}\n */\nPlatform.prototype.client = function() {\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 */\nPlatform.prototype.createUrl = function(path, options) {\n\n path = path || '';\n options = options || {};\n\n var builtUrl = '',\n hasHttp = path.indexOf('http://') != -1 || path.indexOf('https://') != -1,\n alreadyPrefixed = this._knownPrefixes.some(function(prefix) {\n return path.indexOf(prefix) === 0;\n });\n\n if (options.addServer && !hasHttp) builtUrl += this._server;\n\n if (path.indexOf(Platform._urlPrefix) == -1 && !hasHttp && !alreadyPrefixed) {\n builtUrl += Platform._urlPrefix + '/' + Platform._apiVersion;\n }\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] Overrides default RedirectURI\n * @param {string} [options.state]\n * @param {string} [options.brandId]\n * @param {string} [options.display]\n * @param {string} [options.prompt]\n * @param {boolean} [options.implicit] Use Implicit Grant flow\n * @return {string}\n */\nPlatform.prototype.loginUrl = function(options) {\n\n options = options || {};\n\n return this.createUrl(Platform._authorizeEndpoint + '?' + qs.stringify({\n 'response_type': options.implicit ? 'token' : 'code',\n 'redirect_uri': options.redirectUri || this._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 */\nPlatform.prototype.parseLoginRedirect = function(url) {\n\n function getParts(url, separator) {\n return url.split(separator).reverse()[0];\n }\n\n var response = (url.indexOf('#') === 0 && getParts(url, '#')) ||\n (url.indexOf('?') === 0 && getParts(url, '?')) ||\n null;\n\n if (!response) throw new Error('Unable to parse response');\n\n var queryString = qs.parse(response);\n\n if (!queryString) throw new Error('Unable to parse response');\n\n var error = queryString.error_description || queryString.error;\n\n if (error) {\n var e = new Error(error);\n e.error = queryString.error;\n throw e;\n }\n\n return queryString;\n\n};\n\n/**\n * Convenience method to handle 3-legged OAuth\n *\n * Attention! This is an experimental method and it's signature and behavior may change without notice.\n *\n * @experimental\n * @param {string} options.url\n * @param {number} [options.width]\n * @param {number} [options.height]\n * @param {object} [options.login] additional options for login()\n * @param {string} [options.origin]\n * @param {string} [options.property] name of window.postMessage's event data property\n * @param {string} [options.target] target for window.open()\n * @return {Promise}\n */\nPlatform.prototype.loginWindow = function(options) {\n\n return new this._externals.Promise(function(resolve, reject) {\n\n if (typeof window === 'undefined') throw new Error('This method can be used only in browser');\n\n if (!options.url) throw new Error('Missing mandatory URL parameter');\n\n options = options || {};\n options.width = options.width || 400;\n options.height = options.height || 600;\n options.origin = options.origin || window.location.origin;\n options.property = options.property || Constants.authResponseProperty;\n options.target = options.target || '_blank';\n\n var dualScreenLeft = window.screenLeft !== undefined ? window.screenLeft : screen.left;\n var dualScreenTop = window.screenTop !== undefined ? window.screenTop : screen.top;\n\n var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width;\n var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;\n\n var left = ((width / 2) - (options.width / 2)) + dualScreenLeft;\n var top = ((height / 2) - (options.height / 2)) + dualScreenTop;\n var win = window.open(options.url, '_blank', (options.target == '_blank') ? 'scrollbars=yes, status=yes, width=' + options.width + ', height=' + options.height + ', left=' + left + ', top=' + top : '');\n\n if (!win) {\n throw new Error('Could not open login window. Please allow popups for this site');\n }\n\n if (win.focus) win.focus();\n\n var eventMethod = window.addEventListener ? 'addEventListener' : 'attachEvent';\n var eventRemoveMethod = eventMethod == 'addEventListener' ? 'removeEventListener' : 'detachEvent';\n var messageEvent = eventMethod == 'addEventListener' ? 'message' : 'onmessage';\n\n var eventListener = function(e) {\n\n try {\n\n if (e.origin != options.origin) return;\n if (!e.data || !e.data[options.property]) return; // keep waiting\n\n win.close();\n window[eventRemoveMethod](messageEvent, eventListener);\n\n\n var loginOptions = this.parseLoginRedirect(e.data[options.property]);\n\n if (!loginOptions.code && !loginOptions.access_token) throw new Error('No authorization code or token');\n\n resolve(loginOptions);\n\n /* jshint -W002 */\n } catch (e) {\n reject(e);\n }\n\n }.bind(this);\n\n window[eventMethod](messageEvent, eventListener, false);\n\n }.bind(this));\n\n};\n\n/**\n * @return {Promise}\n */\nPlatform.prototype.loggedIn = function() {\n\n return this.ensureLoggedIn().then(function() {\n return true;\n }).catch(function() {\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 * @param {string} [options.accessTokenTtl]\n * @param {string} [options.refreshTokenTtl]\n * @param {string} [options.access_token]\n * @returns {Promise}\n */\nPlatform.prototype.login = function(options) {\n\n return (new this._externals.Promise(function(resolve) {\n\n options = options || {};\n\n this.emit(this.events.beforeLogin);\n\n var body = {};\n\n if (options.access_token) {\n\n //TODO Potentially make a request to /oauth/tokeninfo\n return resolve(options);\n\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 || this._redirectUri;\n //body.client_id = this.getCredentials().key; // not needed\n\n }\n\n if (options.endpointId) body.endpoint_id = options.endpointId;\n if (options.accessTokenTtl) body.access_token_ttl = options.accessTokenTtl;\n if (options.refreshTokenTtl) body.refresh_token_ttl = options.refreshTokenTtl;\n\n resolve(this._tokenRequest(Platform._tokenEndpoint, body));\n\n }.bind(this))).then(function(res) {\n\n var apiResponse = res.json ? res : null;\n var json = apiResponse && apiResponse.json() || res;\n\n this._auth.setData(json);\n\n this.emit(this.events.loginSuccess, apiResponse);\n\n return apiResponse;\n\n }.bind(this)).catch(function(e) {\n\n if (this._clearCacheOnRefreshError) {\n this._cache.clean();\n }\n\n this.emit(this.events.loginError, e);\n\n throw e;\n\n }.bind(this));\n\n};\n\n/**\n * @returns {Promise}\n * @private\n */\nPlatform.prototype._refresh = function() {\n\n return this.delay(this._refreshDelayMs).then(function() {\n\n this.emit(this.events.beforeRefresh);\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\n return this._tokenRequest(Platform._tokenEndpoint, {\n \"grant_type\": \"refresh_token\",\n \"refresh_token\": this._auth.refreshToken(),\n \"access_token_ttl\": this._auth.data().expires_in + 1,\n \"refresh_token_ttl\": this._auth.data().refresh_token_expires_in + 1\n });\n\n }.bind(this)).then(function(/** @type {ApiResponse} */ res) {\n\n var 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\n this.emit(this.events.refreshSuccess, res);\n\n return res;\n\n }.bind(this)).catch(function(e) {\n\n e = this._client.makeError(e);\n\n if (this._clearCacheOnRefreshError) {\n this._cache.clean();\n }\n\n this.emit(this.events.refreshError, e);\n\n throw e;\n\n }.bind(this));\n\n};\n\n/**\n * @returns {Promise}\n */\nPlatform.prototype.refresh = function() {\n\n if (!this._refreshPromise) {\n\n this._refreshPromise = this._refresh()\n .then(function(res) {\n this._refreshPromise = null;\n return res;\n }.bind(this))\n .catch(function(e) {\n this._refreshPromise = null;\n throw e;\n }.bind(this));\n\n }\n\n return this._refreshPromise;\n\n};\n\n/**\n * @returns {Promise}\n */\nPlatform.prototype.logout = function() {\n\n return (new this._externals.Promise(function(resolve) {\n\n this.emit(this.events.beforeLogout);\n\n if (!this._appSecret) {\n resolve(null);\n return;\n }\n\n resolve(this._tokenRequest(Platform._revokeEndpoint, {\n token: this._auth.accessToken()\n }));\n }.bind(this))).then(function(res) {\n\n this._cache.clean();\n\n this.emit(this.events.logoutSuccess, res);\n\n return res;\n\n }.bind(this)).catch(function(e) {\n\n this.emit(this.events.logoutError, e);\n\n throw e;\n\n }.bind(this));\n\n};\n\n/**\n * @param {Request} request\n * @param {object} [options]\n * @param {boolean} [options.skipAuthCheck]\n * @return {Promise}\n */\nPlatform.prototype.inflateRequest = function(request, options) {\n\n options = options || {};\n\n if (options.skipAuthCheck) return this._externals.Promise.resolve(request);\n\n return this.ensureLoggedIn().then(function() {\n\n request.headers.set('X-User-Agent', this._userAgent);\n request.headers.set('Client-Id', this._appKey);\n request.headers.set('Authorization', this._authHeader());\n //request.url = this.createUrl(request.url, {addServer: true}); //FIXME Spec prevents this...\n\n return request;\n\n }.bind(this));\n\n};\n\n/**\n * @param {Request} request\n * @param {object} [options]\n * @param {boolean} [options.skipAuthCheck]\n * @param {boolean|int} [options.handleRateLimit]\n * @param {boolean} [options.retry] Will be set by this method if SDK makes second request\n * @return {Promise}\n */\nPlatform.prototype.sendRequest = function(request, options) {\n\n return this.inflateRequest(request, options).then(function(request) {\n\n options = options || {};\n\n return this._client.sendRequest(request);\n\n }.bind(this)).catch(function(e) {\n\n // Guard is for errors that come from polling\n if (!e.apiResponse || !e.apiResponse.response() || options.retry) throw e;\n\n var response = e.apiResponse.response();\n var status = response.status;\n\n if ((status != ApiResponse._unauthorizedStatus) &&\n (status != ApiResponse._rateLimitStatus)) throw e;\n\n options.retry = true;\n\n var retryAfter = 0;\n\n if (status == ApiResponse._unauthorizedStatus) {\n this._auth.cancelAccessToken();\n }\n\n if (status == ApiResponse._rateLimitStatus) {\n\n var defaultRetryAfter = (!options.handleRateLimit || typeof options.handleRateLimit == 'boolean' ? 60 : options.handleRateLimit);\n\n // FIXME retry-after is custom header, by default, it can't be retrieved. Server should add header: 'Access-Control-Expose-Headers: retry-after'.\n retryAfter = parseFloat(response.headers.get('retry-after') || defaultRetryAfter) * 1000;\n\n e.retryAfter = retryAfter;\n\n this.emit(this.events.rateLimitError, e);\n\n if (!options.handleRateLimit) throw e;\n\n }\n\n return this.delay(retryAfter).then(function() {\n return this.sendRequest(this._client.createRequest(options), options);\n }.bind(this));\n\n }.bind(this));\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 * @param {boolean|int} [options.handleRateLimit]\n * @return {Promise}\n */\nPlatform.prototype.send = function(options) {\n\n options = options || {};\n\n //FIXME https://github.com/bitinn/node-fetch/issues/43\n options.url = this.createUrl(options.url, {addServer: true});\n\n return 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 * @param {boolean|int} [options.handleRateLimit]\n * @return {Promise}\n */\nPlatform.prototype.get = function(url, query, options) {\n return this.send(objectAssign({}, {method: 'GET', url: url, query: query}, 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 * @param {boolean|int} [options.handleRateLimit]\n * @return {Promise}\n */\nPlatform.prototype.post = function(url, body, query, options) {\n return this.send(objectAssign({}, {method: 'POST', url: url, query: query, body: body}, 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 * @param {boolean|int} [options.handleRateLimit]\n * @return {Promise}\n */\nPlatform.prototype.put = function(url, body, query, options) {\n return this.send(objectAssign({}, {method: 'PUT', url: url, query: query, body: body}, 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 * @param {boolean|int} [options.handleRateLimit]\n * @return {Promise}\n */\nPlatform.prototype['delete'] = function(url, query, options) {\n return this.send(objectAssign({}, {method: 'DELETE', url: url, query: query}, options));\n};\n\nPlatform.prototype.ensureLoggedIn = function() {\n if (this._isAccessTokenValid()) return this._externals.Promise.resolve();\n return this.refresh();\n};\n\n/**\n * @param path\n * @param body\n * @return {Promise.}\n * @private\n */\nPlatform.prototype._tokenRequest = function(path, body) {\n\n return this.send({\n url: path,\n skipAuthCheck: true,\n body: body,\n method: 'POST',\n headers: {\n 'Authorization': 'Basic ' + this._apiKey(),\n 'Content-Type': ApiResponse._urlencodedContentType\n }\n });\n\n};\n\n/**\n * @return {boolean}\n * @private\n */\nPlatform.prototype._isAccessTokenValid = function() {\n return this._auth.accessTokenValid();\n};\n\n/**\n * @return {string}\n * @private\n */\nPlatform.prototype._apiKey = function() {\n var apiKey = this._appKey + ':' + this._appSecret;\n return (typeof btoa == 'function') ? btoa(apiKey) : new Buffer(apiKey).toString('base64');\n};\n\n/**\n * @return {string}\n * @private\n */\nPlatform.prototype._authHeader = function() {\n var token = this._auth.accessToken();\n return this._auth.tokenType() + (token ? ' ' + token : '');\n};\n\nmodule.exports = Platform;\n\n\n/***/ },\n/* 16 */\n/***/ function(module, exports) {\n\n/**\n * @param {Cache} options.cache\n * @param {string} options.cacheId\n * @param {int} [options.refreshHandicapMs]\n * @constructor\n * @property {Cache} _cache\n * @property {int} _refreshHandicapMs\n * @property {string} _cacheId\n */\nfunction Auth(options) {\n\n /** @private */\n this._cache = options.cache;\n\n /** @private */\n this._cacheId = options.cacheId;\n\n /** @private */\n this._refreshHandicapMs = options.refreshHandicapMs || 60 * 1000; // 1 minute\n\n}\n\nAuth.prototype.accessToken = function() {\n return this.data().access_token;\n};\n\nAuth.prototype.refreshToken = function() {\n return this.data().refresh_token;\n};\n\nAuth.prototype.tokenType = function() {\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 */\nAuth.prototype.data = function() {\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 */\nAuth.prototype.setData = function(newData) {\n\n newData = newData || {};\n\n var data = this.data();\n\n Object.keys(newData).forEach(function(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 */\nAuth.prototype.accessTokenValid = function() {\n\n var authData = this.data();\n return (authData.expire_time - this._refreshHandicapMs > Date.now());\n\n};\n\n/**\n * Check if there is a valid (not expired) access token\n * @return {boolean}\n */\nAuth.prototype.refreshTokenValid = function() {\n\n return (this.data().refresh_token_expire_time > Date.now());\n\n};\n\n/**\n * @return {Auth}\n */\nAuth.prototype.cancelAccessToken = function() {\n\n return this.setData({\n access_token: '',\n expires_in: 0\n });\n\n};\n\nmodule.exports = Auth;\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/* 17 */\n/***/ function(module, exports, __webpack_require__) {\n\nvar version = (\"3.2.2\");\n\n// This will become false during the Webpack build, so no traces of package.json will be there\nif (false) {\n version = require('../../package.json').version;\n}\n\nmodule.exports = {\n version: version,\n authResponseProperty: 'RCAuthorizationResponse'\n};\n\n/***/ },\n/* 18 */\n/***/ function(module, exports, __webpack_require__) {\n\nvar EventEmitter = __webpack_require__(6).EventEmitter;\n\n// detect ISO 8601 format string with +00[:00] timezone notations\nvar ISO_REG_EXP = /(\\+[\\d]{2}):?([\\d]{2})?$/;\n\nfunction buildIEFriendlyString(match, $1, $2) {\n return $1 + ':' + ($2 || '00');\n}\n\n/**\n *\n * @param {string} time\n * @return {number}\n */\nfunction parseISOString(time) {\n time = time || 0;\n if (typeof time === 'string') {\n return Date.parse(time.replace(ISO_REG_EXP, buildIEFriendlyString));\n }\n return time;\n}\n\n/**\n * @param {Platform} options.platform\n * @param {Externals} options.externals\n * @param {int} [options.pollInterval]\n * @param {int} [options.renewHandicapMs]\n * @property {Externals} _externals\n * @property {Platform} _platform\n * @property {int} _pollInterval\n * @property {int} _renewHandicapMs\n * @property {PubNub} _pubnub\n * @property {string} _pubnubLastChannel\n * @property {int} _timeout\n * @property {ISubscription} _subscription\n * @constructor\n */\nfunction Subscription(options) {\n\n EventEmitter.call(this);\n\n options = options || {};\n\n this.events = {\n notification: 'notification',\n removeSuccess: 'removeSuccess',\n removeError: 'removeError',\n renewSuccess: 'renewSuccess',\n renewError: 'renewError',\n subscribeSuccess: 'subscribeSuccess',\n subscribeError: 'subscribeError',\n automaticRenewSuccess: 'automaticRenewSuccess',\n automaticRenewError: 'automaticRenewError'\n };\n\n /** @private */\n this._externals = options.externals;\n\n /** @private */\n this._platform = options.platform;\n\n /** @private */\n this._pollInterval = options.pollInterval || 10 * 1000;\n\n /** @private */\n this._renewHandicapMs = options.renewHandicapMs || 2 * 60 * 1000;\n\n /** @private */\n this._pubnub = null;\n\n /** @private */\n this._pubnubLastChannel = null;\n\n /** @private */\n this._pubnubLastSubscribeKey = null;\n\n /** @private */\n this._timeout = null;\n\n /** @private */\n this._subscription = null;\n\n}\n\nSubscription.prototype = Object.create(EventEmitter.prototype);\n\nSubscription.prototype.subscribed = function() {\n\n var subscription = this.subscription();\n\n return !!(subscription.id &&\n subscription.deliveryMode &&\n subscription.deliveryMode.subscriberKey &&\n subscription.deliveryMode.address);\n\n};\n\n/**\n * @return {boolean}\n */\nSubscription.prototype.alive = function() {\n return this.subscribed() && Date.now() < this.expirationTime();\n};\n\n/**\n * @return {boolean}\n */\nSubscription.prototype.expired = function() {\n if (!this.subscribed()) return true;\n return !this.subscribed() || Date.now() > parseISOString(this.subscription().expirationTime);\n};\n\n/**\n * @return {number}\n */\nSubscription.prototype.expirationTime = function() {\n return parseISOString(this.subscription().expirationTime) - this._renewHandicapMs;\n};\n\n/**\n * @param {ISubscription} subscription\n * @return {Subscription}\n */\nSubscription.prototype.setSubscription = function(subscription) {\n\n subscription = subscription || {};\n\n this._clearTimeout();\n this._setSubscription(subscription);\n this._subscribeAtPubnub();\n this._setTimeout();\n\n return this;\n\n};\n\n/**\n * @return {ISubscription}\n */\nSubscription.prototype.subscription = function() {\n return this._subscription || {};\n};\n\n/**\n * Creates or updates subscription if there is an active one\n * @returns {Promise}\n */\nSubscription.prototype.register = function() {\n\n if (this.alive()) {\n return this.renew();\n } else {\n return this.subscribe();\n }\n\n};\n\n/**\n * @return {string[]}\n */\nSubscription.prototype.eventFilters = function() {\n return this.subscription().eventFilters || [];\n};\n\n/**\n * @param {string[]} events\n * @return {Subscription}\n */\nSubscription.prototype.addEventFilters = function(events) {\n this.setEventFilters(this.eventFilters().concat(events));\n return this;\n};\n\n/**\n * @param {string[]} events\n * @return {Subscription}\n */\nSubscription.prototype.setEventFilters = function(events) {\n var subscription = this.subscription();\n subscription.eventFilters = events;\n this._setSubscription(subscription);\n return this;\n};\n\n/**\n * @returns {Promise}\n */\nSubscription.prototype.subscribe = function() {\n\n return (new this._externals.Promise(function(resolve) {\n\n this._clearTimeout();\n\n if (!this.eventFilters().length) throw new Error('Events are undefined');\n\n resolve(this._platform.post('/subscription', {\n eventFilters: this._getFullEventFilters(),\n deliveryMode: {\n transportType: 'PubNub'\n }\n }));\n\n }.bind(this))).then(function(response) {\n\n var json = response.json();\n\n this.setSubscription(json)\n .emit(this.events.subscribeSuccess, response);\n\n return response;\n\n }.bind(this)).catch(function(e) {\n\n e = this._platform.client().makeError(e);\n // `reset` will remove pubnub instance.\n // so if network is broken for a long time, pubnub will be removed. And client can not receive notification anymore.\n this.reset()\n .emit(this.events.subscribeError, e);\n\n throw e;\n\n }.bind(this));\n\n};\n\n/**\n * @returns {Promise}\n */\nSubscription.prototype.renew = function() {\n\n return (new this._externals.Promise(function(resolve) {\n\n this._clearTimeout();\n\n if (!this.subscribed()) throw new Error('No subscription');\n\n if (!this.eventFilters().length) throw new Error('Events are undefined');\n\n resolve(this._platform.put('/subscription/' + this.subscription().id, {\n eventFilters: this._getFullEventFilters()\n }));\n\n }.bind(this))).then(function(response) {\n\n var json = response.json();\n\n this.setSubscription(json)\n .emit(this.events.renewSuccess, response);\n\n return response;\n\n }.bind(this)).catch(function(e) {\n\n e = this._platform.client().makeError(e);\n // `reset` will remove pubnub instance.\n // so if network is broken for a long time, pubnub will be removed. And client can not receive notification anymore.\n this.reset()\n .emit(this.events.renewError, e);\n\n throw e;\n\n }.bind(this));\n\n};\n\n/**\n * @returns {Promise}\n */\nSubscription.prototype.remove = function() {\n\n return (new this._externals.Promise(function(resolve) {\n\n if (!this.subscribed()) throw new Error('No subscription');\n\n resolve(this._platform.delete('/subscription/' + this.subscription().id));\n\n }.bind(this))).then(function(response) {\n\n this.reset()\n .emit(this.events.removeSuccess, response);\n\n return response;\n\n }.bind(this)).catch(function(e) {\n\n e = this._platform.client().makeError(e);\n\n this.emit(this.events.removeError, e);\n\n throw e;\n\n }.bind(this));\n\n};\n\n/**\n * @returns {Promise}\n */\nSubscription.prototype.resubscribe = function() {\n var filters = this.eventFilters();\n return this.reset().setEventFilters(filters).subscribe();\n};\n\n/**\n * Remove subscription and disconnect from PubNub\n * This method resets subscription at client side but backend is not notified\n * @return {Subscription}\n */\nSubscription.prototype.reset = function() {\n this._clearTimeout();\n this._unsubscribeAtPubnub();\n this._setSubscription(null);\n return this;\n};\n\n/**\n * @param subscription\n * @private\n */\nSubscription.prototype._setSubscription = function(subscription) {\n this._subscription = subscription;\n};\n\n/**\n * @return {string[]}\n * @private\n */\nSubscription.prototype._getFullEventFilters = function() {\n\n return this.eventFilters().map(function(event) {\n return this._platform.createUrl(event);\n }.bind(this));\n\n};\n\n/**\n * @return {Subscription}\n * @private\n */\nSubscription.prototype._setTimeout = function() {\n\n this._clearTimeout();\n\n if (!this.alive()) throw new Error('Subscription is not alive');\n\n this._timeout = setInterval(function() {\n\n if (this.alive()) {\n return;\n }\n\n this._clearTimeout();\n\n (new this._externals.Promise(function(resolve) {\n\n if (this.expired()) {\n resolve(this.subscribe());\n } else {\n resolve(this.renew());\n }\n\n }.bind(this))).then(function(res) {\n\n this.emit(this.events.automaticRenewSuccess, res);\n\n }.bind(this)).catch(function(e) {\n\n this.emit(this.events.automaticRenewError, e);\n\n }.bind(this));\n\n }.bind(this), this._pollInterval);\n\n return this;\n\n};\n\n/**\n * @return {Subscription}\n * @private\n */\nSubscription.prototype._clearTimeout = function() {\n clearInterval(this._timeout);\n return this;\n};\n\nSubscription.prototype._decrypt = function(message) {\n\n if (!this.subscribed()) throw new Error('No subscription');\n\n if (this.subscription().deliveryMode.encryptionKey) {\n\n message = this._pubnub.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/**\n * @param message\n * @return {Subscription}\n * @private\n */\nSubscription.prototype._notify = function(message) {\n this.emit(this.events.notification, this._decrypt(message));\n return this;\n};\n\n/**\n * @return {Subscription}\n * @private\n */\nSubscription.prototype._subscribeAtPubnub = function() {\n\n if (!this.alive()) throw new Error('Subscription is not alive');\n\n var deliveryMode = this.subscription().deliveryMode;\n\n if (this._pubnub) {\n\n if (this._pubnubLastChannel === deliveryMode.address) {\n\n // Nothing to update, keep listening to same channel\n return this;\n\n } else if (this._pubnubLastSubscribeKey && this._pubnubLastSubscribeKey !== deliveryMode.subscriberKey) {\n\n // Subscribe key changed, need to reset everything\n this._unsubscribeAtPubnub();\n\n } else if (this._pubnubLastChannel) {\n\n // Need to subscribe to new channel\n this._pubnub.unsubscribeAll();\n\n }\n\n }\n\n if (!this._pubnub) {\n\n this._pubnubLastSubscribeKey = deliveryMode.subscriberKey;\n\n var PubNub = this._externals.PubNub;\n\n this._pubnub = new PubNub({\n ssl: true,\n restore: true,\n subscribeKey: deliveryMode.subscriberKey\n });\n\n this._pubnub.addListener({\n status: function(statusEvent) {},\n message: function(m) {\n this._notify(m.message); // all other props are ignored\n }.bind(this)\n });\n\n }\n\n this._pubnubLastChannel = deliveryMode.address;\n this._pubnub.subscribe({channels: [deliveryMode.address]});\n\n return this;\n\n};\n\n/**\n * @return {Subscription}\n * @private\n */\nSubscription.prototype._unsubscribeAtPubnub = function() {\n\n if (!this.subscribed() || !this._pubnub) return this;\n\n this._pubnub.removeAllListeners();\n this._pubnub.destroy(); // this will unsubscribe from all\n\n this._pubnubLastSubscribeKey = null;\n this._pubnubLastChannel = null;\n this._pubnub = null;\n\n return this;\n\n};\n\nmodule.exports = Subscription;\n\n/**\n * The complete Triforce, or one or more components of the Triforce.\n * @typedef {Object} ISubscription\n * @property {string} [id]\n * @property {string} [uri]\n * @property {string[]} [eventFilters]\n * @property {string} [expirationTime] Format: 2014-03-12T19:54:35.613+0000\n * @property {int} [expiresIn]\n * @property {string} [deliveryMode.transportType]\n * @property {boolean} [deliveryMode.encryption]\n * @property {string} [deliveryMode.address]\n * @property {string} [deliveryMode.subscriberKey]\n * @property {string} [deliveryMode.encryptionKey]\n * @property {string} [deliveryMode.secretKey]\n * @property {string} [creationTime]\n * @property {string} [status] Active\n */\n\n/***/ },\n/* 19 */\n/***/ function(module, exports, __webpack_require__) {\n\nvar Subscription = __webpack_require__(18);\n\n/**\n * @param {Platform} options.platform\n * @param {Externals} options.externals\n * @param {Cache} options.cache\n * @param {string} options.cacheKey\n * @param {int} [options.pollInterval]\n * @param {int} [options.renewHandicapMs]\n * @return {CachedSubscription}\n * @constructor\n * @property {Cache} _cache\n * @extends Subscription\n */\nfunction CachedSubscription(options) {\n\n options = options || {};\n\n if (!options.cacheKey) throw new Error('Cached Subscription requires cacheKey parameter to be defined');\n\n /** @private */\n this._cacheKey = options.cacheKey;\n\n Subscription.call(this, options);\n\n /** @private */\n this._cache = options.cache;\n\n // This is not used in this class\n this._subscription = undefined;\n\n}\n\nCachedSubscription.prototype = Object.create(Subscription.prototype);\n\nCachedSubscription.prototype.subscription = function() {\n return this._cache.getItem(this._cacheKey) || {};\n};\n\nCachedSubscription.prototype._setSubscription = function(subscription) {\n return this._cache.setItem(this._cacheKey, subscription);\n};\n\n/**\n * This function checks whether there are any pre-defined eventFilters in cache and if not -- uses provided as defaults\n * @param {string[]} events\n * @return {CachedSubscription}\n */\nCachedSubscription.prototype.restore = function(events) {\n\n if (!this.eventFilters().length) {\n this.setEventFilters(events);\n }\n\n return this;\n\n};\n\nmodule.exports = CachedSubscription;\n\n/***/ }\n/******/ ])\n});\n;\n\n\n// WEBPACK FOOTER //\n// ringcentral.min.js"," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\texports: {},\n \t\t\tid: moduleId,\n \t\t\tloaded: false\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.loaded = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"/build/\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(0);\n\n\n\n// WEBPACK FOOTER //\n// webpack/bootstrap 3e92ff87335340dc908b","/**\n * @namespace RingCentral\n */\nvar objectAssign = require('object-assign');\nvar Cache = require(\"./core/Cache\");\nvar Client = require(\"./http/Client\");\nvar Externals = require(\"./core/Externals\");\nvar Platform = require(\"./platform/Platform\");\nvar Subscription = require(\"./subscription/Subscription\");\nvar CachedSubscription = require(\"./subscription/CachedSubscription\");\nvar Constants = require(\"./core/Constants\");\n\n/**\n * @constructor\n * @param {string} options.server\n * @param {string} options.appSecret\n * @param {string} options.appKey\n * @param {string} [options.cachePrefix]\n * @param {string} [options.appName]\n * @param {string} [options.appVersion]\n * @param {string} [options.redirectUri]\n * @param {PubNub} [options.PubNub]\n * @param {function(new:Promise)} [options.Promise]\n * @param {Storage} [options.localStorage]\n * @param {fetch} [options.fetch]\n * @param {function(new:Request)} [options.Request]\n * @param {function(new:Response)} [options.Response]\n * @param {function(new:Headers)} [options.Headers]\n * @param {int} [options.refreshDelayMs]\n * @param {int} [options.refreshHandicapMs]\n * @param {boolean} [options.clearCacheOnRefreshError]\n * @property {Externals} _externals\n * @property {Cache} _cache\n * @property {Client} _client\n * @property {Platform} _platform\n */\nfunction SDK(options) {\n\n /** @private */\n this._externals = new Externals(options);\n\n /** @private */\n this._cache = new Cache({\n externals: this._externals,\n prefix: options.cachePrefix\n });\n\n /** @private */\n this._client = new Client(this._externals);\n\n /** @private */\n this._platform = new Platform(objectAssign({}, options, {\n externals: this._externals,\n client: this._client,\n cache: this._cache\n }));\n\n}\n\nSDK.version = Constants.version;\n\nSDK.server = {\n sandbox: 'https://platform.devtest.ringcentral.com',\n production: 'https://platform.ringcentral.com'\n};\n\n/**\n * @return {Platform}\n */\nSDK.prototype.platform = function() {\n return this._platform;\n};\n\n/**\n * @return {Cache}\n */\nSDK.prototype.cache = function() {\n return this._cache;\n};\n\n/**\n * @param {int} [options.pollInterval]\n * @param {int} [options.renewHandicapMs]\n * @return {Subscription}\n */\nSDK.prototype.createSubscription = function(options) {\n return new Subscription(objectAssign({}, options, {\n externals: this._externals,\n platform: this._platform\n }));\n};\n\n/**\n * @param {string} options.cacheKey\n * @param {int} [options.pollInterval]\n * @param {int} [options.renewHandicapMs]\n * @return {CachedSubscription}\n */\nSDK.prototype.createCachedSubscription = function(options) {\n\n if (typeof arguments[0] === 'string') {\n options = {cacheKey: arguments[0].toString()};\n } else {\n options = options || {};\n }\n\n return new CachedSubscription(objectAssign({}, options, {\n externals: this._externals,\n platform: this._platform,\n cache: this._cache\n }));\n\n};\n\nSDK.handleLoginRedirect = function(origin, win) {\n\n win = win || window;\n\n var response = win.location.hash ? win.location.hash : win.location.search;\n var msg = {};\n msg[Constants.authResponseProperty] = response;\n win.opener.postMessage(msg, origin || win.location.origin);\n\n};\n\nmodule.exports = SDK;\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/SDK.js\n// module id = 0\n// module chunks = 0 1","/*\nobject-assign\n(c) Sindre Sorhus\n@license MIT\n*/\n\n'use strict';\n/* eslint-disable no-unused-vars */\nvar getOwnPropertySymbols = Object.getOwnPropertySymbols;\nvar hasOwnProperty = Object.prototype.hasOwnProperty;\nvar propIsEnumerable = Object.prototype.propertyIsEnumerable;\n\nfunction toObject(val) {\n\tif (val === null || val === undefined) {\n\t\tthrow new TypeError('Object.assign cannot be called with null or undefined');\n\t}\n\n\treturn Object(val);\n}\n\nfunction shouldUseNative() {\n\ttry {\n\t\tif (!Object.assign) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Detect buggy property enumeration order in older V8 versions.\n\n\t\t// https://bugs.chromium.org/p/v8/issues/detail?id=4118\n\t\tvar test1 = new String('abc'); // eslint-disable-line no-new-wrappers\n\t\ttest1[5] = 'de';\n\t\tif (Object.getOwnPropertyNames(test1)[0] === '5') {\n\t\t\treturn false;\n\t\t}\n\n\t\t// https://bugs.chromium.org/p/v8/issues/detail?id=3056\n\t\tvar test2 = {};\n\t\tfor (var i = 0; i < 10; i++) {\n\t\t\ttest2['_' + String.fromCharCode(i)] = i;\n\t\t}\n\t\tvar order2 = Object.getOwnPropertyNames(test2).map(function (n) {\n\t\t\treturn test2[n];\n\t\t});\n\t\tif (order2.join('') !== '0123456789') {\n\t\t\treturn false;\n\t\t}\n\n\t\t// https://bugs.chromium.org/p/v8/issues/detail?id=3056\n\t\tvar test3 = {};\n\t\t'abcdefghijklmnopqrst'.split('').forEach(function (letter) {\n\t\t\ttest3[letter] = letter;\n\t\t});\n\t\tif (Object.keys(Object.assign({}, test3)).join('') !==\n\t\t\t\t'abcdefghijklmnopqrst') {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn true;\n\t} catch (err) {\n\t\t// We don't expect any of the above to throw, but better to be safe.\n\t\treturn false;\n\t}\n}\n\nmodule.exports = shouldUseNative() ? Object.assign : function (target, source) {\n\tvar from;\n\tvar to = toObject(target);\n\tvar symbols;\n\n\tfor (var s = 1; s < arguments.length; s++) {\n\t\tfrom = Object(arguments[s]);\n\n\t\tfor (var key in from) {\n\t\t\tif (hasOwnProperty.call(from, key)) {\n\t\t\t\tto[key] = from[key];\n\t\t\t}\n\t\t}\n\n\t\tif (getOwnPropertySymbols) {\n\t\t\tsymbols = getOwnPropertySymbols(from);\n\t\t\tfor (var i = 0; i < symbols.length; i++) {\n\t\t\t\tif (propIsEnumerable.call(from, symbols[i])) {\n\t\t\t\t\tto[symbols[i]] = from[symbols[i]];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn to;\n};\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./~/object-assign/index.js\n// module id = 1\n// module chunks = 0 1","/**\n * @param {Externals} options.externals\n * @param {string} [options.prefix]\n * @property {Externals} _externals\n */\nfunction Cache(options) {\n\n /** @private */\n this._prefix = options.prefix || Cache.defaultPrefix;\n\n /** @private */\n this._externals = options.externals;\n\n}\n\nCache.defaultPrefix = 'rc-';\n\nCache.prototype.setItem = function(key, data) {\n this._externals.localStorage[this._prefixKey(key)] = JSON.stringify(data);\n return this;\n};\n\nCache.prototype.removeItem = function(key) {\n delete this._externals.localStorage[this._prefixKey(key)];\n return this;\n};\n\nCache.prototype.getItem = function(key) {\n var item = this._externals.localStorage[this._prefixKey(key)];\n if (!item) return null;\n return JSON.parse(item);\n};\n\nCache.prototype.clean = function() {\n\n for (var key in this._externals.localStorage) {\n\n /* istanbul ignore next */\n if (!this._externals.localStorage.hasOwnProperty(key)) continue;\n\n if (key.indexOf(this._prefix) === 0) {\n delete this._externals.localStorage[key];\n }\n\n }\n\n return this;\n\n};\n\nCache.prototype._prefixKey = function(key) {\n return this._prefix + key;\n};\n\nmodule.exports = Cache;\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/core/Cache.js\n// module id = 2\n// module chunks = 0 1","var isPlainObject = require(\"is-plain-object\");\nvar EventEmitter = require(\"events\").EventEmitter;\nvar ApiResponse = require(\"./ApiResponse\");\nvar qs = require(\"querystring\");\n\nfunction 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 * @param {Externals} externals\n * @property {Externals} _externals\n */\nfunction Client(externals) {\n\n EventEmitter.call(this);\n\n /** @private */\n this._externals = externals;\n\n this.events = {\n beforeRequest: 'beforeRequest',\n requestSuccess: 'requestSuccess',\n requestError: 'requestError'\n };\n\n}\n\nClient._allowedMethods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS', 'HEAD'];\n\nClient.prototype = Object.create(EventEmitter.prototype);\n\n/**\n * @param {Request} request\n * @return {Promise}\n */\nClient.prototype.sendRequest = function(request) {\n\n var apiResponse = new ApiResponse({\n externals: this._externals,\n request: request\n });\n\n return (new this._externals.Promise(function(resolve) {\n\n //TODO Stop request if listeners return false\n this.emit(this.events.beforeRequest, apiResponse);\n\n resolve(this._loadResponse(request));\n\n }.bind(this))).then(function(response) {\n\n return apiResponse.receiveResponse(response);\n\n }).then(function() {\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 }.bind(this)).catch(function(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 }.bind(this));\n\n};\n\n/**\n * @param {Request} request\n * @return {Promise}\n * @private\n */\nClient.prototype._loadResponse = function(request) {\n return this._externals.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 */\nClient.prototype.makeError = function(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 * @param {object} [init.credentials]\n * @param {object} [init.mode]\n * @return {Request}\n */\nClient.prototype.createRequest = function(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 init.method = init.method.toUpperCase();\n if (init.method && Client._allowedMethods.indexOf(init.method) < 0) {\n throw new Error('Method has wrong value: ' + init.method);\n }\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 ? '&' : '?') + qs.stringify(init.query);\n }\n\n if (!(findHeaderName('Accept', init.headers))) {\n init.headers.Accept = ApiResponse._jsonContentType;\n }\n\n // Serialize body\n if (isPlainObject(init.body) || !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 if ((init.method === 'GET' || init.method === 'HEAD') && !!init.body) {\n // oddly setting body to null still result in TypeError in phantomjs\n init.body = undefined;\n } else {\n init.body = JSON.stringify(init.body);\n }\n\n } else if (contentType.indexOf(ApiResponse._urlencodedContentType) > -1) {\n init.body = qs.stringify(init.body);\n }\n\n }\n\n // Create a request with encoded body\n var req = new this._externals.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 * @typedef {object} IApiError\n * @property {string} stack\n * @property {string} originalMessage\n * @property {ApiResponse} apiResponse\n */\n\nmodule.exports = Client;\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/http/Client.js\n// module id = 3\n// module chunks = 0 1","/*!\n * is-plain-object \n *\n * Copyright (c) 2014-2017, Jon Schlinkert.\n * Released under the MIT License.\n */\n\n'use strict';\n\nvar isObject = require('isobject');\n\nfunction isObjectObject(o) {\n return isObject(o) === true\n && Object.prototype.toString.call(o) === '[object Object]';\n}\n\nmodule.exports = function isPlainObject(o) {\n var ctor,prot;\n\n if (isObjectObject(o) === false) return false;\n\n // If has modified constructor\n ctor = o.constructor;\n if (typeof ctor !== 'function') return false;\n\n // If has modified prototype\n prot = ctor.prototype;\n if (isObjectObject(prot) === false) return false;\n\n // If constructor does not have an Object-specific method\n if (prot.hasOwnProperty('isPrototypeOf') === false) {\n return false;\n }\n\n // Most likely a plain Object\n return true;\n};\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./~/is-plain-object/index.js\n// module id = 4\n// module chunks = 0 1","/*!\n * isobject \n *\n * Copyright (c) 2014-2017, Jon Schlinkert.\n * Released under the MIT License.\n */\n\n'use strict';\n\nmodule.exports = function isObject(val) {\n return val != null && typeof val === 'object' && Array.isArray(val) === false;\n};\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./~/isobject/index.js\n// module id = 5\n// module chunks = 0 1","// Copyright Joyent, Inc. and other Node contributors.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a\n// copy of this software and associated documentation files (the\n// \"Software\"), to deal in the Software without restriction, including\n// without limitation the rights to use, copy, modify, merge, publish,\n// distribute, sublicense, and/or sell copies of the Software, and to permit\n// persons to whom the Software is furnished to do so, subject to the\n// following conditions:\n//\n// The above copyright notice and this permission notice shall be included\n// in all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\n// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN\n// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,\n// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE\n// USE OR OTHER DEALINGS IN THE SOFTWARE.\n\nfunction EventEmitter() {\n this._events = this._events || {};\n this._maxListeners = this._maxListeners || undefined;\n}\nmodule.exports = EventEmitter;\n\n// Backwards-compat with node 0.10.x\nEventEmitter.EventEmitter = EventEmitter;\n\nEventEmitter.prototype._events = undefined;\nEventEmitter.prototype._maxListeners = undefined;\n\n// By default EventEmitters will print a warning if more than 10 listeners are\n// added to it. This is a useful default which helps finding memory leaks.\nEventEmitter.defaultMaxListeners = 10;\n\n// Obviously not all Emitters should be limited to 10. This function allows\n// that to be increased. Set to zero for unlimited.\nEventEmitter.prototype.setMaxListeners = function(n) {\n if (!isNumber(n) || n < 0 || isNaN(n))\n throw TypeError('n must be a positive number');\n this._maxListeners = n;\n return this;\n};\n\nEventEmitter.prototype.emit = function(type) {\n var er, handler, len, args, i, listeners;\n\n if (!this._events)\n this._events = {};\n\n // If there is no 'error' event listener then throw.\n if (type === 'error') {\n if (!this._events.error ||\n (isObject(this._events.error) && !this._events.error.length)) {\n er = arguments[1];\n if (er instanceof Error) {\n throw er; // Unhandled 'error' event\n } else {\n // At least give some kind of context to the user\n var err = new Error('Uncaught, unspecified \"error\" event. (' + er + ')');\n err.context = er;\n throw err;\n }\n }\n }\n\n handler = this._events[type];\n\n if (isUndefined(handler))\n return false;\n\n if (isFunction(handler)) {\n switch (arguments.length) {\n // fast cases\n case 1:\n handler.call(this);\n break;\n case 2:\n handler.call(this, arguments[1]);\n break;\n case 3:\n handler.call(this, arguments[1], arguments[2]);\n break;\n // slower\n default:\n args = Array.prototype.slice.call(arguments, 1);\n handler.apply(this, args);\n }\n } else if (isObject(handler)) {\n args = Array.prototype.slice.call(arguments, 1);\n listeners = handler.slice();\n len = listeners.length;\n for (i = 0; i < len; i++)\n listeners[i].apply(this, args);\n }\n\n return true;\n};\n\nEventEmitter.prototype.addListener = function(type, listener) {\n var m;\n\n if (!isFunction(listener))\n throw TypeError('listener must be a function');\n\n if (!this._events)\n this._events = {};\n\n // To avoid recursion in the case that type === \"newListener\"! Before\n // adding it to the listeners, first emit \"newListener\".\n if (this._events.newListener)\n this.emit('newListener', type,\n isFunction(listener.listener) ?\n listener.listener : listener);\n\n if (!this._events[type])\n // Optimize the case of one listener. Don't need the extra array object.\n this._events[type] = listener;\n else if (isObject(this._events[type]))\n // If we've already got an array, just append.\n this._events[type].push(listener);\n else\n // Adding the second element, need to change to array.\n this._events[type] = [this._events[type], listener];\n\n // Check for listener leak\n if (isObject(this._events[type]) && !this._events[type].warned) {\n if (!isUndefined(this._maxListeners)) {\n m = this._maxListeners;\n } else {\n m = EventEmitter.defaultMaxListeners;\n }\n\n if (m && m > 0 && this._events[type].length > m) {\n this._events[type].warned = true;\n console.error('(node) warning: possible EventEmitter memory ' +\n 'leak detected. %d listeners added. ' +\n 'Use emitter.setMaxListeners() to increase limit.',\n this._events[type].length);\n if (typeof console.trace === 'function') {\n // not supported in IE 10\n console.trace();\n }\n }\n }\n\n return this;\n};\n\nEventEmitter.prototype.on = EventEmitter.prototype.addListener;\n\nEventEmitter.prototype.once = function(type, listener) {\n if (!isFunction(listener))\n throw TypeError('listener must be a function');\n\n var fired = false;\n\n function g() {\n this.removeListener(type, g);\n\n if (!fired) {\n fired = true;\n listener.apply(this, arguments);\n }\n }\n\n g.listener = listener;\n this.on(type, g);\n\n return this;\n};\n\n// emits a 'removeListener' event iff the listener was removed\nEventEmitter.prototype.removeListener = function(type, listener) {\n var list, position, length, i;\n\n if (!isFunction(listener))\n throw TypeError('listener must be a function');\n\n if (!this._events || !this._events[type])\n return this;\n\n list = this._events[type];\n length = list.length;\n position = -1;\n\n if (list === listener ||\n (isFunction(list.listener) && list.listener === listener)) {\n delete this._events[type];\n if (this._events.removeListener)\n this.emit('removeListener', type, listener);\n\n } else if (isObject(list)) {\n for (i = length; i-- > 0;) {\n if (list[i] === listener ||\n (list[i].listener && list[i].listener === listener)) {\n position = i;\n break;\n }\n }\n\n if (position < 0)\n return this;\n\n if (list.length === 1) {\n list.length = 0;\n delete this._events[type];\n } else {\n list.splice(position, 1);\n }\n\n if (this._events.removeListener)\n this.emit('removeListener', type, listener);\n }\n\n return this;\n};\n\nEventEmitter.prototype.removeAllListeners = function(type) {\n var key, listeners;\n\n if (!this._events)\n return this;\n\n // not listening for removeListener, no need to emit\n if (!this._events.removeListener) {\n if (arguments.length === 0)\n this._events = {};\n else if (this._events[type])\n delete this._events[type];\n return this;\n }\n\n // emit removeListener for all listeners on all events\n if (arguments.length === 0) {\n for (key in this._events) {\n if (key === 'removeListener') continue;\n this.removeAllListeners(key);\n }\n this.removeAllListeners('removeListener');\n this._events = {};\n return this;\n }\n\n listeners = this._events[type];\n\n if (isFunction(listeners)) {\n this.removeListener(type, listeners);\n } else if (listeners) {\n // LIFO order\n while (listeners.length)\n this.removeListener(type, listeners[listeners.length - 1]);\n }\n delete this._events[type];\n\n return this;\n};\n\nEventEmitter.prototype.listeners = function(type) {\n var ret;\n if (!this._events || !this._events[type])\n ret = [];\n else if (isFunction(this._events[type]))\n ret = [this._events[type]];\n else\n ret = this._events[type].slice();\n return ret;\n};\n\nEventEmitter.prototype.listenerCount = function(type) {\n if (this._events) {\n var evlistener = this._events[type];\n\n if (isFunction(evlistener))\n return 1;\n else if (evlistener)\n return evlistener.length;\n }\n return 0;\n};\n\nEventEmitter.listenerCount = function(emitter, type) {\n return emitter.listenerCount(type);\n};\n\nfunction isFunction(arg) {\n return typeof arg === 'function';\n}\n\nfunction isNumber(arg) {\n return typeof arg === 'number';\n}\n\nfunction isObject(arg) {\n return typeof arg === 'object' && arg !== null;\n}\n\nfunction isUndefined(arg) {\n return arg === void 0;\n}\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./~/events/events.js\n// module id = 6\n// module chunks = 0 1","/**\n * @param {Externals} options.externals\n * @param {Request} [options.request]\n * @param {Response} [options.response]\n * @param {string} [options.responseText]\n * @property {Externals} _externals\n * @property {Request} _request\n * @property {Response} _response\n * @property {string} _text\n * @property {object} _json\n * @property {ApiResponse[]} _multipart\n */\nfunction ApiResponse(options) {\n\n /** @private */\n this._externals = options.externals;\n\n /** @private */\n this._request = options.request;\n\n /** @private */\n this._response = options.response;\n\n /** @private */\n this._text = options.responseText || '';\n\n /** @private */\n this._json = null;\n\n /** @private */\n this._multipart = [];\n\n}\n\nApiResponse._contentType = 'Content-Type';\nApiResponse._jsonContentType = 'application/json';\nApiResponse._multipartContentType = 'multipart/mixed';\nApiResponse._urlencodedContentType = 'application/x-www-form-urlencoded';\nApiResponse._headerSeparator = ':';\nApiResponse._bodySeparator = '\\n\\n';\nApiResponse._boundarySeparator = '--';\nApiResponse._unauthorizedStatus = 401;\nApiResponse._rateLimitStatus = 429;\n\n/**\n * @param {Response} response\n * @return {Promise}\n */\nApiResponse.prototype.receiveResponse = function(response) {\n\n this._response = response;\n\n return (new this._externals.Promise(function(resolve) {\n\n // Ignore if not textual type\n if (!this._isMultipart() && !this._isJson()) return resolve('');\n\n return resolve(this.response().text());\n\n }.bind(this))).then(function(text) {\n\n this._text = text;\n return text;\n\n }.bind(this));\n\n};\n\n/**\n * @return {Response}\n */\nApiResponse.prototype.response = function() {\n return this._response;\n};\n\n/**\n * @return {Request}\n */\nApiResponse.prototype.request = function() {\n return this._request;\n};\n\n/**\n * @return {boolean}\n */\nApiResponse.prototype.ok = function() {\n return this._response && this._response.ok;\n};\n\n/**\n * @return {string}\n */\nApiResponse.prototype.text = function() {\n // Since we read text only in case JSON or Multipart\n if (!this._isJson() && !this._isMultipart()) throw new Error('Response is not text');\n return this._text;\n};\n\n/**\n * @return {object}\n */\nApiResponse.prototype.json = function() {\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 */\nApiResponse.prototype.error = function(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 * If it is not known upfront what would be the response, client code can treat any response as multipart\n * @return {ApiResponse[]}\n */\nApiResponse.prototype.toMultipart = function() {\n if (!this._isMultipart()) return [this];\n return this.multipart();\n};\n\n/**\n * @return {ApiResponse[]}\n */\nApiResponse.prototype.multipart = function() {\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;\n\n try {\n boundary = this._getContentType().match(/boundary=([^;]+)/i)[1];\n } catch (e) {\n throw new Error('Cannot find boundary');\n }\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 = this._create(parts.shift(), this._response.status, this._response.statusText).json();\n\n // Step 3. Parse all other parts\n\n this._multipart = parts.map(function(part, i) {\n\n var status = statusInfo.response[i].status;\n\n return this._create(part, status);\n\n }.bind(this));\n\n }\n\n return this._multipart;\n\n};\n\n/**\n * @private\n */\nApiResponse.prototype._isContentType = function(contentType) {\n return this._getContentType().indexOf(contentType) > -1;\n};\n\n/**\n * @private\n */\nApiResponse.prototype._getContentType = function() {\n return this._response.headers.get(ApiResponse._contentType) || '';\n};\n\n/**\n * @private\n */\nApiResponse.prototype._isMultipart = function() {\n return this._isContentType(ApiResponse._multipartContentType);\n};\n\n/**\n * @private\n */\nApiResponse.prototype._isJson = function() {\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 * @private\n * @return {ApiResponse}\n */\nApiResponse.prototype._create = function(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 this._externals.Headers(),\n headersAndBody = text.split(ApiResponse._bodySeparator),\n headersText = (headersAndBody.length > 1) ? headersAndBody.shift() : '';\n\n text = headersAndBody.length > 0 ? headersAndBody.join(ApiResponse._bodySeparator) : null;\n\n (headersText || '')\n .split('\\n')\n .forEach(function(header) {\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 var response = new this._externals.Response(text, {\n headers: headers,\n status: status,\n statusText: statusText\n });\n\n return new ApiResponse({\n externals: this._externals,\n request: null,\n response: response,\n responseText: text\n });\n\n};\n\nmodule.exports = ApiResponse;\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/http/ApiResponse.js\n// module id = 7\n// module chunks = 0 1","'use strict';\n\nexports.decode = exports.parse = require('./decode');\nexports.encode = exports.stringify = require('./encode');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./~/querystring/index.js\n// module id = 8\n// module chunks = 0 1","// Copyright Joyent, Inc. and other Node contributors.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a\n// copy of this software and associated documentation files (the\n// \"Software\"), to deal in the Software without restriction, including\n// without limitation the rights to use, copy, modify, merge, publish,\n// distribute, sublicense, and/or sell copies of the Software, and to permit\n// persons to whom the Software is furnished to do so, subject to the\n// following conditions:\n//\n// The above copyright notice and this permission notice shall be included\n// in all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\n// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN\n// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,\n// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE\n// USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n'use strict';\n\n// If obj.hasOwnProperty has been overridden, then calling\n// obj.hasOwnProperty(prop) will break.\n// See: https://github.com/joyent/node/issues/1707\nfunction hasOwnProperty(obj, prop) {\n return Object.prototype.hasOwnProperty.call(obj, prop);\n}\n\nmodule.exports = function(qs, sep, eq, options) {\n sep = sep || '&';\n eq = eq || '=';\n var obj = {};\n\n if (typeof qs !== 'string' || qs.length === 0) {\n return obj;\n }\n\n var regexp = /\\+/g;\n qs = qs.split(sep);\n\n var maxKeys = 1000;\n if (options && typeof options.maxKeys === 'number') {\n maxKeys = options.maxKeys;\n }\n\n var len = qs.length;\n // maxKeys <= 0 means that we should not limit keys count\n if (maxKeys > 0 && len > maxKeys) {\n len = maxKeys;\n }\n\n for (var i = 0; i < len; ++i) {\n var x = qs[i].replace(regexp, '%20'),\n idx = x.indexOf(eq),\n kstr, vstr, k, v;\n\n if (idx >= 0) {\n kstr = x.substr(0, idx);\n vstr = x.substr(idx + 1);\n } else {\n kstr = x;\n vstr = '';\n }\n\n k = decodeURIComponent(kstr);\n v = decodeURIComponent(vstr);\n\n if (!hasOwnProperty(obj, k)) {\n obj[k] = v;\n } else if (Array.isArray(obj[k])) {\n obj[k].push(v);\n } else {\n obj[k] = [obj[k], v];\n }\n }\n\n return obj;\n};\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./~/querystring/decode.js\n// module id = 9\n// module chunks = 0 1","// Copyright Joyent, Inc. and other Node contributors.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a\n// copy of this software and associated documentation files (the\n// \"Software\"), to deal in the Software without restriction, including\n// without limitation the rights to use, copy, modify, merge, publish,\n// distribute, sublicense, and/or sell copies of the Software, and to permit\n// persons to whom the Software is furnished to do so, subject to the\n// following conditions:\n//\n// The above copyright notice and this permission notice shall be included\n// in all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\n// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN\n// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,\n// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE\n// USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n'use strict';\n\nvar stringifyPrimitive = function(v) {\n switch (typeof v) {\n case 'string':\n return v;\n\n case 'boolean':\n return v ? 'true' : 'false';\n\n case 'number':\n return isFinite(v) ? v : '';\n\n default:\n return '';\n }\n};\n\nmodule.exports = function(obj, sep, eq, name) {\n sep = sep || '&';\n eq = eq || '=';\n if (obj === null) {\n obj = undefined;\n }\n\n if (typeof obj === 'object') {\n return Object.keys(obj).map(function(k) {\n var ks = encodeURIComponent(stringifyPrimitive(k)) + eq;\n if (Array.isArray(obj[k])) {\n return obj[k].map(function(v) {\n return ks + encodeURIComponent(stringifyPrimitive(v));\n }).join(sep);\n } else {\n return ks + encodeURIComponent(stringifyPrimitive(obj[k]));\n }\n }).join(sep);\n\n }\n\n if (!name) return '';\n return encodeURIComponent(stringifyPrimitive(name)) + eq +\n encodeURIComponent(stringifyPrimitive(obj));\n};\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./~/querystring/encode.js\n// module id = 10\n// module chunks = 0 1","var pubnub = require(\"pubnub\");\nvar es6Promise = require(\"es6-promise\");\nvar FetchPonyfill = require(\"fetch-ponyfill\");\n\nvar root = (typeof window !== \"undefined\" && window) ||\n (typeof global !== \"undefined\" && global) ||\n (function(){ return this; })();\n\n/**\n * @constructor\n * @param {PubNub} [options.PubNub]\n * @param {function(new:Promise)} [options.Promise]\n * @param {Storage} [options.localStorage]\n * @param {fetch} [options.fetch]\n * @param {function(new:Request)} [options.Request]\n * @param {function(new:Response)} [options.Response]\n * @param {function(new:Headers)} [options.Headers]\n * @property {PubNub} PubNub\n * @property {Storage} localStorage\n * @property {function(new:Promise)} Promise\n * @property {fetch} fetch\n * @property {function(new:Request)} Request\n * @property {function(new:Response)} Response\n * @property {function(new:Headers)} Headers\n */\nfunction Externals(options) {\n\n options = options || {};\n\n this.PubNub = options.PubNub || root.PubNub || pubnub;\n this.localStorage = options.localStorage || ((typeof root.localStorage !== 'undefined') ? root.localStorage : {});\n this.Promise = options.Promise || root.Promise || (es6Promise && es6Promise.Promise);\n\n var fetchPonyfill = FetchPonyfill ? FetchPonyfill({Promise: this.Promise}) : {};\n\n this.fetch = options.fetch || root.fetch || fetchPonyfill.fetch;\n this.Request = options.Request || root.Request || fetchPonyfill.Request;\n this.Response = options.Response || root.Response || fetchPonyfill.Response;\n this.Headers = options.Headers || root.Headers || fetchPonyfill.Headers;\n\n /* istanbul ignore next */\n if (!this.fetch || !this.Response || !this.Request || !this.Headers) {\n throw new Error('Fetch API is missing');\n }\n\n /* istanbul ignore next */\n if (!this.Promise) {\n throw new Error('Promise is missing');\n }\n\n /* istanbul ignore next */\n if (!this.localStorage) {\n throw new Error('LocalStorage is missing');\n }\n\n /* istanbul ignore next */\n if (!this.PubNub) {\n throw new Error('PubNub is missing');\n }\n\n}\n\nmodule.exports = Externals;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/core/Externals.js\n// module id = 11\n// module chunks = 0 1","module.exports = __WEBPACK_EXTERNAL_MODULE_12__;\n\n\n//////////////////\n// WEBPACK FOOTER\n// external {\"amd\":\"pubnub\"}\n// module id = 12\n// module chunks = 0 1","module.exports = __WEBPACK_EXTERNAL_MODULE_13__;\n\n\n//////////////////\n// WEBPACK FOOTER\n// external {\"amd\":\"es6-promise\"}\n// module id = 13\n// module chunks = 0 1","module.exports = __WEBPACK_EXTERNAL_MODULE_14__;\n\n\n//////////////////\n// WEBPACK FOOTER\n// external {\"amd\":\"fetch-ponyfill\"}\n// module id = 14\n// module chunks = 0 1","var EventEmitter = require(\"events\").EventEmitter;\nvar qs = require(\"querystring\");\nvar objectAssign = require('object-assign');\nvar Auth = require(\"./Auth\");\nvar Constants = require(\"../core/Constants\");\nvar ApiResponse = require(\"../http/ApiResponse\");\n\n/**\n * @constructor\n * @param {string} options.server\n * @param {string} options.appSecret\n * @param {string} options.appKey\n * @param {string} [options.appName]\n * @param {string} [options.appVersion]\n * @param {string} [options.redirectUri]\n * @param {int} [options.refreshDelayMs]\n * @param {int} [options.refreshHandicapMs]\n * @param {boolean} [options.clearCacheOnRefreshError]\n * @param {Externals} options.externals\n * @param {Cache} options.cache\n * @param {Client} options.client\n * @property {Externals} _externals\n * @property {Cache} _cache\n * @property {Client} _client\n * @property {Promise} _refreshPromise\n * @property {Auth} _auth\n */\nfunction Platform(options) {\n\n EventEmitter.call(this);\n\n this.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 rateLimitError: 'rateLimitError'\n };\n\n options = options || {};\n\n /** @private */\n this._server = options.server;\n\n /** @private */\n this._appKey = options.appKey;\n\n /** @private */\n this._appSecret = options.appSecret;\n\n /** @private */\n this._redirectUri = options.redirectUri || '';\n\n /** @private */\n this._refreshDelayMs = options.refreshDelayMs || 100;\n\n /** @private */\n this._clearCacheOnRefreshError = typeof options.clearCacheOnRefreshError !== 'undefined' ?\n options.clearCacheOnRefreshError :\n true;\n\n /** @private */\n this._userAgent = (options.appName ?\n (options.appName + (options.appVersion ? '/' + options.appVersion : '')) + ' ' :\n '') + 'RCJSSDK/' + Constants.version;\n\n /** @private */\n this._externals = options.externals;\n\n /** @private */\n this._cache = options.cache;\n\n /** @private */\n this._client = options.client;\n\n /** @private */\n this._knownPrefixes = options.knownPrefixes || Platform._knownPrefixes;\n\n\n /** @private */\n this._refreshPromise = null;\n\n /** @private */\n this._auth = new Auth({\n cache: this._cache,\n cacheId: Platform._cacheId,\n refreshHandicapMs: options.refreshHandicapMs\n });\n\n}\n\nPlatform._urlPrefix = '/restapi';\nPlatform._apiVersion = 'v1.0';\nPlatform._knownPrefixes = ['/rcvideo'];\nPlatform._tokenEndpoint = '/restapi/oauth/token';\nPlatform._revokeEndpoint = '/restapi/oauth/revoke';\nPlatform._authorizeEndpoint = '/restapi/oauth/authorize';\nPlatform._cacheId = 'platform';\n\nPlatform.prototype = Object.create(EventEmitter.prototype);\n\nPlatform.prototype.delay = function(timeout) {\n return new this._externals.Promise(function(resolve, reject) {\n setTimeout(function() {\n resolve(null);\n }, timeout);\n });\n};\n\n/**\n * @return {Auth}\n */\nPlatform.prototype.auth = function() {\n return this._auth;\n};\n\n/**\n * @return {Client}\n */\nPlatform.prototype.client = function() {\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 */\nPlatform.prototype.createUrl = function(path, options) {\n\n path = path || '';\n options = options || {};\n\n var builtUrl = '',\n hasHttp = path.indexOf('http://') != -1 || path.indexOf('https://') != -1,\n alreadyPrefixed = this._knownPrefixes.some(function(prefix) {\n return path.indexOf(prefix) === 0;\n });\n\n if (options.addServer && !hasHttp) builtUrl += this._server;\n\n if (path.indexOf(Platform._urlPrefix) == -1 && !hasHttp && !alreadyPrefixed) {\n builtUrl += Platform._urlPrefix + '/' + Platform._apiVersion;\n }\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] Overrides default RedirectURI\n * @param {string} [options.state]\n * @param {string} [options.brandId]\n * @param {string} [options.display]\n * @param {string} [options.prompt]\n * @param {boolean} [options.implicit] Use Implicit Grant flow\n * @return {string}\n */\nPlatform.prototype.loginUrl = function(options) {\n\n options = options || {};\n\n return this.createUrl(Platform._authorizeEndpoint + '?' + qs.stringify({\n 'response_type': options.implicit ? 'token' : 'code',\n 'redirect_uri': options.redirectUri || this._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 */\nPlatform.prototype.parseLoginRedirect = function(url) {\n\n function getParts(url, separator) {\n return url.split(separator).reverse()[0];\n }\n\n var response = (url.indexOf('#') === 0 && getParts(url, '#')) ||\n (url.indexOf('?') === 0 && getParts(url, '?')) ||\n null;\n\n if (!response) throw new Error('Unable to parse response');\n\n var queryString = qs.parse(response);\n\n if (!queryString) throw new Error('Unable to parse response');\n\n var error = queryString.error_description || queryString.error;\n\n if (error) {\n var e = new Error(error);\n e.error = queryString.error;\n throw e;\n }\n\n return queryString;\n\n};\n\n/**\n * Convenience method to handle 3-legged OAuth\n *\n * Attention! This is an experimental method and it's signature and behavior may change without notice.\n *\n * @experimental\n * @param {string} options.url\n * @param {number} [options.width]\n * @param {number} [options.height]\n * @param {object} [options.login] additional options for login()\n * @param {string} [options.origin]\n * @param {string} [options.property] name of window.postMessage's event data property\n * @param {string} [options.target] target for window.open()\n * @return {Promise}\n */\nPlatform.prototype.loginWindow = function(options) {\n\n return new this._externals.Promise(function(resolve, reject) {\n\n if (typeof window === 'undefined') throw new Error('This method can be used only in browser');\n\n if (!options.url) throw new Error('Missing mandatory URL parameter');\n\n options = options || {};\n options.width = options.width || 400;\n options.height = options.height || 600;\n options.origin = options.origin || window.location.origin;\n options.property = options.property || Constants.authResponseProperty;\n options.target = options.target || '_blank';\n\n var dualScreenLeft = window.screenLeft !== undefined ? window.screenLeft : screen.left;\n var dualScreenTop = window.screenTop !== undefined ? window.screenTop : screen.top;\n\n var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width;\n var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;\n\n var left = ((width / 2) - (options.width / 2)) + dualScreenLeft;\n var top = ((height / 2) - (options.height / 2)) + dualScreenTop;\n var win = window.open(options.url, '_blank', (options.target == '_blank') ? 'scrollbars=yes, status=yes, width=' + options.width + ', height=' + options.height + ', left=' + left + ', top=' + top : '');\n\n if (!win) {\n throw new Error('Could not open login window. Please allow popups for this site');\n }\n\n if (win.focus) win.focus();\n\n var eventMethod = window.addEventListener ? 'addEventListener' : 'attachEvent';\n var eventRemoveMethod = eventMethod == 'addEventListener' ? 'removeEventListener' : 'detachEvent';\n var messageEvent = eventMethod == 'addEventListener' ? 'message' : 'onmessage';\n\n var eventListener = function(e) {\n\n try {\n\n if (e.origin != options.origin) return;\n if (!e.data || !e.data[options.property]) return; // keep waiting\n\n win.close();\n window[eventRemoveMethod](messageEvent, eventListener);\n\n\n var loginOptions = this.parseLoginRedirect(e.data[options.property]);\n\n if (!loginOptions.code && !loginOptions.access_token) throw new Error('No authorization code or token');\n\n resolve(loginOptions);\n\n /* jshint -W002 */\n } catch (e) {\n reject(e);\n }\n\n }.bind(this);\n\n window[eventMethod](messageEvent, eventListener, false);\n\n }.bind(this));\n\n};\n\n/**\n * @return {Promise}\n */\nPlatform.prototype.loggedIn = function() {\n\n return this.ensureLoggedIn().then(function() {\n return true;\n }).catch(function() {\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 * @param {string} [options.accessTokenTtl]\n * @param {string} [options.refreshTokenTtl]\n * @param {string} [options.access_token]\n * @returns {Promise}\n */\nPlatform.prototype.login = function(options) {\n\n return (new this._externals.Promise(function(resolve) {\n\n options = options || {};\n\n this.emit(this.events.beforeLogin);\n\n var body = {};\n\n if (options.access_token) {\n\n //TODO Potentially make a request to /oauth/tokeninfo\n return resolve(options);\n\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 || this._redirectUri;\n //body.client_id = this.getCredentials().key; // not needed\n\n }\n\n if (options.endpointId) body.endpoint_id = options.endpointId;\n if (options.accessTokenTtl) body.access_token_ttl = options.accessTokenTtl;\n if (options.refreshTokenTtl) body.refresh_token_ttl = options.refreshTokenTtl;\n\n resolve(this._tokenRequest(Platform._tokenEndpoint, body));\n\n }.bind(this))).then(function(res) {\n\n var apiResponse = res.json ? res : null;\n var json = apiResponse && apiResponse.json() || res;\n\n this._auth.setData(json);\n\n this.emit(this.events.loginSuccess, apiResponse);\n\n return apiResponse;\n\n }.bind(this)).catch(function(e) {\n\n if (this._clearCacheOnRefreshError) {\n this._cache.clean();\n }\n\n this.emit(this.events.loginError, e);\n\n throw e;\n\n }.bind(this));\n\n};\n\n/**\n * @returns {Promise}\n * @private\n */\nPlatform.prototype._refresh = function() {\n\n return this.delay(this._refreshDelayMs).then(function() {\n\n this.emit(this.events.beforeRefresh);\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\n return this._tokenRequest(Platform._tokenEndpoint, {\n \"grant_type\": \"refresh_token\",\n \"refresh_token\": this._auth.refreshToken(),\n \"access_token_ttl\": this._auth.data().expires_in + 1,\n \"refresh_token_ttl\": this._auth.data().refresh_token_expires_in + 1\n });\n\n }.bind(this)).then(function(/** @type {ApiResponse} */ res) {\n\n var 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\n this.emit(this.events.refreshSuccess, res);\n\n return res;\n\n }.bind(this)).catch(function(e) {\n\n e = this._client.makeError(e);\n\n if (this._clearCacheOnRefreshError) {\n this._cache.clean();\n }\n\n this.emit(this.events.refreshError, e);\n\n throw e;\n\n }.bind(this));\n\n};\n\n/**\n * @returns {Promise}\n */\nPlatform.prototype.refresh = function() {\n\n if (!this._refreshPromise) {\n\n this._refreshPromise = this._refresh()\n .then(function(res) {\n this._refreshPromise = null;\n return res;\n }.bind(this))\n .catch(function(e) {\n this._refreshPromise = null;\n throw e;\n }.bind(this));\n\n }\n\n return this._refreshPromise;\n\n};\n\n/**\n * @returns {Promise}\n */\nPlatform.prototype.logout = function() {\n\n return (new this._externals.Promise(function(resolve) {\n\n this.emit(this.events.beforeLogout);\n\n if (!this._appSecret) {\n resolve(null);\n return;\n }\n\n resolve(this._tokenRequest(Platform._revokeEndpoint, {\n token: this._auth.accessToken()\n }));\n }.bind(this))).then(function(res) {\n\n this._cache.clean();\n\n this.emit(this.events.logoutSuccess, res);\n\n return res;\n\n }.bind(this)).catch(function(e) {\n\n this.emit(this.events.logoutError, e);\n\n throw e;\n\n }.bind(this));\n\n};\n\n/**\n * @param {Request} request\n * @param {object} [options]\n * @param {boolean} [options.skipAuthCheck]\n * @return {Promise}\n */\nPlatform.prototype.inflateRequest = function(request, options) {\n\n options = options || {};\n\n if (options.skipAuthCheck) return this._externals.Promise.resolve(request);\n\n return this.ensureLoggedIn().then(function() {\n\n request.headers.set('X-User-Agent', this._userAgent);\n request.headers.set('Client-Id', this._appKey);\n request.headers.set('Authorization', this._authHeader());\n //request.url = this.createUrl(request.url, {addServer: true}); //FIXME Spec prevents this...\n\n return request;\n\n }.bind(this));\n\n};\n\n/**\n * @param {Request} request\n * @param {object} [options]\n * @param {boolean} [options.skipAuthCheck]\n * @param {boolean|int} [options.handleRateLimit]\n * @param {boolean} [options.retry] Will be set by this method if SDK makes second request\n * @return {Promise}\n */\nPlatform.prototype.sendRequest = function(request, options) {\n\n return this.inflateRequest(request, options).then(function(request) {\n\n options = options || {};\n\n return this._client.sendRequest(request);\n\n }.bind(this)).catch(function(e) {\n\n // Guard is for errors that come from polling\n if (!e.apiResponse || !e.apiResponse.response() || options.retry) throw e;\n\n var response = e.apiResponse.response();\n var status = response.status;\n\n if ((status != ApiResponse._unauthorizedStatus) &&\n (status != ApiResponse._rateLimitStatus)) throw e;\n\n options.retry = true;\n\n var retryAfter = 0;\n\n if (status == ApiResponse._unauthorizedStatus) {\n this._auth.cancelAccessToken();\n }\n\n if (status == ApiResponse._rateLimitStatus) {\n\n var defaultRetryAfter = (!options.handleRateLimit || typeof options.handleRateLimit == 'boolean' ? 60 : options.handleRateLimit);\n\n // FIXME retry-after is custom header, by default, it can't be retrieved. Server should add header: 'Access-Control-Expose-Headers: retry-after'.\n retryAfter = parseFloat(response.headers.get('retry-after') || defaultRetryAfter) * 1000;\n\n e.retryAfter = retryAfter;\n\n this.emit(this.events.rateLimitError, e);\n\n if (!options.handleRateLimit) throw e;\n\n }\n\n return this.delay(retryAfter).then(function() {\n return this.sendRequest(this._client.createRequest(options), options);\n }.bind(this));\n\n }.bind(this));\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 * @param {boolean|int} [options.handleRateLimit]\n * @return {Promise}\n */\nPlatform.prototype.send = function(options) {\n\n options = options || {};\n\n //FIXME https://github.com/bitinn/node-fetch/issues/43\n options.url = this.createUrl(options.url, {addServer: true});\n\n return 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 * @param {boolean|int} [options.handleRateLimit]\n * @return {Promise}\n */\nPlatform.prototype.get = function(url, query, options) {\n return this.send(objectAssign({}, {method: 'GET', url: url, query: query}, 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 * @param {boolean|int} [options.handleRateLimit]\n * @return {Promise}\n */\nPlatform.prototype.post = function(url, body, query, options) {\n return this.send(objectAssign({}, {method: 'POST', url: url, query: query, body: body}, 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 * @param {boolean|int} [options.handleRateLimit]\n * @return {Promise}\n */\nPlatform.prototype.put = function(url, body, query, options) {\n return this.send(objectAssign({}, {method: 'PUT', url: url, query: query, body: body}, 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 * @param {boolean|int} [options.handleRateLimit]\n * @return {Promise}\n */\nPlatform.prototype['delete'] = function(url, query, options) {\n return this.send(objectAssign({}, {method: 'DELETE', url: url, query: query}, options));\n};\n\nPlatform.prototype.ensureLoggedIn = function() {\n if (this._isAccessTokenValid()) return this._externals.Promise.resolve();\n return this.refresh();\n};\n\n/**\n * @param path\n * @param body\n * @return {Promise.}\n * @private\n */\nPlatform.prototype._tokenRequest = function(path, body) {\n\n return this.send({\n url: path,\n skipAuthCheck: true,\n body: body,\n method: 'POST',\n headers: {\n 'Authorization': 'Basic ' + this._apiKey(),\n 'Content-Type': ApiResponse._urlencodedContentType\n }\n });\n\n};\n\n/**\n * @return {boolean}\n * @private\n */\nPlatform.prototype._isAccessTokenValid = function() {\n return this._auth.accessTokenValid();\n};\n\n/**\n * @return {string}\n * @private\n */\nPlatform.prototype._apiKey = function() {\n var apiKey = this._appKey + ':' + this._appSecret;\n return (typeof btoa == 'function') ? btoa(apiKey) : new Buffer(apiKey).toString('base64');\n};\n\n/**\n * @return {string}\n * @private\n */\nPlatform.prototype._authHeader = function() {\n var token = this._auth.accessToken();\n return this._auth.tokenType() + (token ? ' ' + token : '');\n};\n\nmodule.exports = Platform;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/platform/Platform.js\n// module id = 15\n// module chunks = 0 1","/**\n * @param {Cache} options.cache\n * @param {string} options.cacheId\n * @param {int} [options.refreshHandicapMs]\n * @constructor\n * @property {Cache} _cache\n * @property {int} _refreshHandicapMs\n * @property {string} _cacheId\n */\nfunction Auth(options) {\n\n /** @private */\n this._cache = options.cache;\n\n /** @private */\n this._cacheId = options.cacheId;\n\n /** @private */\n this._refreshHandicapMs = options.refreshHandicapMs || 60 * 1000; // 1 minute\n\n}\n\nAuth.prototype.accessToken = function() {\n return this.data().access_token;\n};\n\nAuth.prototype.refreshToken = function() {\n return this.data().refresh_token;\n};\n\nAuth.prototype.tokenType = function() {\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 */\nAuth.prototype.data = function() {\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 */\nAuth.prototype.setData = function(newData) {\n\n newData = newData || {};\n\n var data = this.data();\n\n Object.keys(newData).forEach(function(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 */\nAuth.prototype.accessTokenValid = function() {\n\n var authData = this.data();\n return (authData.expire_time - this._refreshHandicapMs > Date.now());\n\n};\n\n/**\n * Check if there is a valid (not expired) access token\n * @return {boolean}\n */\nAuth.prototype.refreshTokenValid = function() {\n\n return (this.data().refresh_token_expire_time > Date.now());\n\n};\n\n/**\n * @return {Auth}\n */\nAuth.prototype.cancelAccessToken = function() {\n\n return this.setData({\n access_token: '',\n expires_in: 0\n });\n\n};\n\nmodule.exports = Auth;\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//////////////////\n// WEBPACK FOOTER\n// ./src/platform/Auth.js\n// module id = 16\n// module chunks = 0 1","var version = process.env.RCSDK_VERSION;\n\n// This will become false during the Webpack build, so no traces of package.json will be there\nif (!process.env.RCSDK_VERSION) {\n version = require('../../package.json').version;\n}\n\nmodule.exports = {\n version: version,\n authResponseProperty: 'RCAuthorizationResponse'\n};\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/core/Constants.js\n// module id = 17\n// module chunks = 0 1","var EventEmitter = require(\"events\").EventEmitter;\n\n// detect ISO 8601 format string with +00[:00] timezone notations\nvar ISO_REG_EXP = /(\\+[\\d]{2}):?([\\d]{2})?$/;\n\nfunction buildIEFriendlyString(match, $1, $2) {\n return $1 + ':' + ($2 || '00');\n}\n\n/**\n *\n * @param {string} time\n * @return {number}\n */\nfunction parseISOString(time) {\n time = time || 0;\n if (typeof time === 'string') {\n return Date.parse(time.replace(ISO_REG_EXP, buildIEFriendlyString));\n }\n return time;\n}\n\n/**\n * @param {Platform} options.platform\n * @param {Externals} options.externals\n * @param {int} [options.pollInterval]\n * @param {int} [options.renewHandicapMs]\n * @property {Externals} _externals\n * @property {Platform} _platform\n * @property {int} _pollInterval\n * @property {int} _renewHandicapMs\n * @property {PubNub} _pubnub\n * @property {string} _pubnubLastChannel\n * @property {int} _timeout\n * @property {ISubscription} _subscription\n * @constructor\n */\nfunction Subscription(options) {\n\n EventEmitter.call(this);\n\n options = options || {};\n\n this.events = {\n notification: 'notification',\n removeSuccess: 'removeSuccess',\n removeError: 'removeError',\n renewSuccess: 'renewSuccess',\n renewError: 'renewError',\n subscribeSuccess: 'subscribeSuccess',\n subscribeError: 'subscribeError',\n automaticRenewSuccess: 'automaticRenewSuccess',\n automaticRenewError: 'automaticRenewError'\n };\n\n /** @private */\n this._externals = options.externals;\n\n /** @private */\n this._platform = options.platform;\n\n /** @private */\n this._pollInterval = options.pollInterval || 10 * 1000;\n\n /** @private */\n this._renewHandicapMs = options.renewHandicapMs || 2 * 60 * 1000;\n\n /** @private */\n this._pubnub = null;\n\n /** @private */\n this._pubnubLastChannel = null;\n\n /** @private */\n this._pubnubLastSubscribeKey = null;\n\n /** @private */\n this._timeout = null;\n\n /** @private */\n this._subscription = null;\n\n}\n\nSubscription.prototype = Object.create(EventEmitter.prototype);\n\nSubscription.prototype.subscribed = function() {\n\n var subscription = this.subscription();\n\n return !!(subscription.id &&\n subscription.deliveryMode &&\n subscription.deliveryMode.subscriberKey &&\n subscription.deliveryMode.address);\n\n};\n\n/**\n * @return {boolean}\n */\nSubscription.prototype.alive = function() {\n return this.subscribed() && Date.now() < this.expirationTime();\n};\n\n/**\n * @return {boolean}\n */\nSubscription.prototype.expired = function() {\n if (!this.subscribed()) return true;\n return !this.subscribed() || Date.now() > parseISOString(this.subscription().expirationTime);\n};\n\n/**\n * @return {number}\n */\nSubscription.prototype.expirationTime = function() {\n return parseISOString(this.subscription().expirationTime) - this._renewHandicapMs;\n};\n\n/**\n * @param {ISubscription} subscription\n * @return {Subscription}\n */\nSubscription.prototype.setSubscription = function(subscription) {\n\n subscription = subscription || {};\n\n this._clearTimeout();\n this._setSubscription(subscription);\n this._subscribeAtPubnub();\n this._setTimeout();\n\n return this;\n\n};\n\n/**\n * @return {ISubscription}\n */\nSubscription.prototype.subscription = function() {\n return this._subscription || {};\n};\n\n/**\n * Creates or updates subscription if there is an active one\n * @returns {Promise}\n */\nSubscription.prototype.register = function() {\n\n if (this.alive()) {\n return this.renew();\n } else {\n return this.subscribe();\n }\n\n};\n\n/**\n * @return {string[]}\n */\nSubscription.prototype.eventFilters = function() {\n return this.subscription().eventFilters || [];\n};\n\n/**\n * @param {string[]} events\n * @return {Subscription}\n */\nSubscription.prototype.addEventFilters = function(events) {\n this.setEventFilters(this.eventFilters().concat(events));\n return this;\n};\n\n/**\n * @param {string[]} events\n * @return {Subscription}\n */\nSubscription.prototype.setEventFilters = function(events) {\n var subscription = this.subscription();\n subscription.eventFilters = events;\n this._setSubscription(subscription);\n return this;\n};\n\n/**\n * @returns {Promise}\n */\nSubscription.prototype.subscribe = function() {\n\n return (new this._externals.Promise(function(resolve) {\n\n this._clearTimeout();\n\n if (!this.eventFilters().length) throw new Error('Events are undefined');\n\n resolve(this._platform.post('/subscription', {\n eventFilters: this._getFullEventFilters(),\n deliveryMode: {\n transportType: 'PubNub'\n }\n }));\n\n }.bind(this))).then(function(response) {\n\n var json = response.json();\n\n this.setSubscription(json)\n .emit(this.events.subscribeSuccess, response);\n\n return response;\n\n }.bind(this)).catch(function(e) {\n\n e = this._platform.client().makeError(e);\n // `reset` will remove pubnub instance.\n // so if network is broken for a long time, pubnub will be removed. And client can not receive notification anymore.\n this.reset()\n .emit(this.events.subscribeError, e);\n\n throw e;\n\n }.bind(this));\n\n};\n\n/**\n * @returns {Promise}\n */\nSubscription.prototype.renew = function() {\n\n return (new this._externals.Promise(function(resolve) {\n\n this._clearTimeout();\n\n if (!this.subscribed()) throw new Error('No subscription');\n\n if (!this.eventFilters().length) throw new Error('Events are undefined');\n\n resolve(this._platform.put('/subscription/' + this.subscription().id, {\n eventFilters: this._getFullEventFilters()\n }));\n\n }.bind(this))).then(function(response) {\n\n var json = response.json();\n\n this.setSubscription(json)\n .emit(this.events.renewSuccess, response);\n\n return response;\n\n }.bind(this)).catch(function(e) {\n\n e = this._platform.client().makeError(e);\n // `reset` will remove pubnub instance.\n // so if network is broken for a long time, pubnub will be removed. And client can not receive notification anymore.\n this.reset()\n .emit(this.events.renewError, e);\n\n throw e;\n\n }.bind(this));\n\n};\n\n/**\n * @returns {Promise}\n */\nSubscription.prototype.remove = function() {\n\n return (new this._externals.Promise(function(resolve) {\n\n if (!this.subscribed()) throw new Error('No subscription');\n\n resolve(this._platform.delete('/subscription/' + this.subscription().id));\n\n }.bind(this))).then(function(response) {\n\n this.reset()\n .emit(this.events.removeSuccess, response);\n\n return response;\n\n }.bind(this)).catch(function(e) {\n\n e = this._platform.client().makeError(e);\n\n this.emit(this.events.removeError, e);\n\n throw e;\n\n }.bind(this));\n\n};\n\n/**\n * @returns {Promise}\n */\nSubscription.prototype.resubscribe = function() {\n var filters = this.eventFilters();\n return this.reset().setEventFilters(filters).subscribe();\n};\n\n/**\n * Remove subscription and disconnect from PubNub\n * This method resets subscription at client side but backend is not notified\n * @return {Subscription}\n */\nSubscription.prototype.reset = function() {\n this._clearTimeout();\n this._unsubscribeAtPubnub();\n this._setSubscription(null);\n return this;\n};\n\n/**\n * @param subscription\n * @private\n */\nSubscription.prototype._setSubscription = function(subscription) {\n this._subscription = subscription;\n};\n\n/**\n * @return {string[]}\n * @private\n */\nSubscription.prototype._getFullEventFilters = function() {\n\n return this.eventFilters().map(function(event) {\n return this._platform.createUrl(event);\n }.bind(this));\n\n};\n\n/**\n * @return {Subscription}\n * @private\n */\nSubscription.prototype._setTimeout = function() {\n\n this._clearTimeout();\n\n if (!this.alive()) throw new Error('Subscription is not alive');\n\n this._timeout = setInterval(function() {\n\n if (this.alive()) {\n return;\n }\n\n this._clearTimeout();\n\n (new this._externals.Promise(function(resolve) {\n\n if (this.expired()) {\n resolve(this.subscribe());\n } else {\n resolve(this.renew());\n }\n\n }.bind(this))).then(function(res) {\n\n this.emit(this.events.automaticRenewSuccess, res);\n\n }.bind(this)).catch(function(e) {\n\n this.emit(this.events.automaticRenewError, e);\n\n }.bind(this));\n\n }.bind(this), this._pollInterval);\n\n return this;\n\n};\n\n/**\n * @return {Subscription}\n * @private\n */\nSubscription.prototype._clearTimeout = function() {\n clearInterval(this._timeout);\n return this;\n};\n\nSubscription.prototype._decrypt = function(message) {\n\n if (!this.subscribed()) throw new Error('No subscription');\n\n if (this.subscription().deliveryMode.encryptionKey) {\n\n message = this._pubnub.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/**\n * @param message\n * @return {Subscription}\n * @private\n */\nSubscription.prototype._notify = function(message) {\n this.emit(this.events.notification, this._decrypt(message));\n return this;\n};\n\n/**\n * @return {Subscription}\n * @private\n */\nSubscription.prototype._subscribeAtPubnub = function() {\n\n if (!this.alive()) throw new Error('Subscription is not alive');\n\n var deliveryMode = this.subscription().deliveryMode;\n\n if (this._pubnub) {\n\n if (this._pubnubLastChannel === deliveryMode.address) {\n\n // Nothing to update, keep listening to same channel\n return this;\n\n } else if (this._pubnubLastSubscribeKey && this._pubnubLastSubscribeKey !== deliveryMode.subscriberKey) {\n\n // Subscribe key changed, need to reset everything\n this._unsubscribeAtPubnub();\n\n } else if (this._pubnubLastChannel) {\n\n // Need to subscribe to new channel\n this._pubnub.unsubscribeAll();\n\n }\n\n }\n\n if (!this._pubnub) {\n\n this._pubnubLastSubscribeKey = deliveryMode.subscriberKey;\n\n var PubNub = this._externals.PubNub;\n\n this._pubnub = new PubNub({\n ssl: true,\n restore: true,\n subscribeKey: deliveryMode.subscriberKey\n });\n\n this._pubnub.addListener({\n status: function(statusEvent) {},\n message: function(m) {\n this._notify(m.message); // all other props are ignored\n }.bind(this)\n });\n\n }\n\n this._pubnubLastChannel = deliveryMode.address;\n this._pubnub.subscribe({channels: [deliveryMode.address]});\n\n return this;\n\n};\n\n/**\n * @return {Subscription}\n * @private\n */\nSubscription.prototype._unsubscribeAtPubnub = function() {\n\n if (!this.subscribed() || !this._pubnub) return this;\n\n this._pubnub.removeAllListeners();\n this._pubnub.destroy(); // this will unsubscribe from all\n\n this._pubnubLastSubscribeKey = null;\n this._pubnubLastChannel = null;\n this._pubnub = null;\n\n return this;\n\n};\n\nmodule.exports = Subscription;\n\n/**\n * The complete Triforce, or one or more components of the Triforce.\n * @typedef {Object} ISubscription\n * @property {string} [id]\n * @property {string} [uri]\n * @property {string[]} [eventFilters]\n * @property {string} [expirationTime] Format: 2014-03-12T19:54:35.613+0000\n * @property {int} [expiresIn]\n * @property {string} [deliveryMode.transportType]\n * @property {boolean} [deliveryMode.encryption]\n * @property {string} [deliveryMode.address]\n * @property {string} [deliveryMode.subscriberKey]\n * @property {string} [deliveryMode.encryptionKey]\n * @property {string} [deliveryMode.secretKey]\n * @property {string} [creationTime]\n * @property {string} [status] Active\n */\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/subscription/Subscription.js\n// module id = 18\n// module chunks = 0 1","var Subscription = require(\"./Subscription\");\n\n/**\n * @param {Platform} options.platform\n * @param {Externals} options.externals\n * @param {Cache} options.cache\n * @param {string} options.cacheKey\n * @param {int} [options.pollInterval]\n * @param {int} [options.renewHandicapMs]\n * @return {CachedSubscription}\n * @constructor\n * @property {Cache} _cache\n * @extends Subscription\n */\nfunction CachedSubscription(options) {\n\n options = options || {};\n\n if (!options.cacheKey) throw new Error('Cached Subscription requires cacheKey parameter to be defined');\n\n /** @private */\n this._cacheKey = options.cacheKey;\n\n Subscription.call(this, options);\n\n /** @private */\n this._cache = options.cache;\n\n // This is not used in this class\n this._subscription = undefined;\n\n}\n\nCachedSubscription.prototype = Object.create(Subscription.prototype);\n\nCachedSubscription.prototype.subscription = function() {\n return this._cache.getItem(this._cacheKey) || {};\n};\n\nCachedSubscription.prototype._setSubscription = function(subscription) {\n return this._cache.setItem(this._cacheKey, subscription);\n};\n\n/**\n * This function checks whether there are any pre-defined eventFilters in cache and if not -- uses provided as defaults\n * @param {string[]} events\n * @return {CachedSubscription}\n */\nCachedSubscription.prototype.restore = function(events) {\n\n if (!this.eventFilters().length) {\n this.setEventFilters(events);\n }\n\n return this;\n\n};\n\nmodule.exports = CachedSubscription;\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/subscription/CachedSubscription.js\n// module id = 19\n// module chunks = 0 1"],"sourceRoot":""} \ No newline at end of file +{"version":3,"sources":["webpack:///webpack/universalModuleDefinition?5ca6","webpack:///ringcentral.min.js","webpack:///webpack/bootstrap 9170c9929c7a92918002?42c3","webpack:///./src/SDK.js?d032","webpack:///./~/object-assign/index.js?2927","webpack:///./src/core/Cache.js?1256","webpack:///./src/http/Client.js?4230","webpack:///./~/is-plain-object/index.js?2af1","webpack:///./~/isobject/index.js?cf96","webpack:///./~/events/events.js?7c71","webpack:///./src/http/ApiResponse.js?d4a4","webpack:///./~/querystring/index.js?fce8","webpack:///./~/querystring/decode.js?c250","webpack:///./~/querystring/encode.js?e86b","webpack:///./src/core/Externals.js?fdf1","webpack:///external {\"amd\":\"pubnub\"}?3fcf","webpack:///external {\"amd\":\"es6-promise\"}?8a6b","webpack:///external {\"amd\":\"fetch-ponyfill\"}?ec6e","webpack:///./src/platform/Platform.js?8f42","webpack:///./src/platform/Auth.js?cef5","webpack:///./src/core/Constants.js?22d0","webpack:///./src/subscription/Subscription.js?3ae8","webpack:///./src/subscription/CachedSubscription.js?3294"],"names":["root","factory","exports","module","require","undefined","define","amd","this","__WEBPACK_EXTERNAL_MODULE_12__","__WEBPACK_EXTERNAL_MODULE_13__","__WEBPACK_EXTERNAL_MODULE_14__","modules","__webpack_require__","moduleId","installedModules","id","loaded","call","m","c","p","SDK","options","_externals","Externals","_cache","Cache","externals","prefix","cachePrefix","_client","Client","_platform","Platform","objectAssign","client","cache","Subscription","CachedSubscription","Constants","version","server","sandbox","production","prototype","platform","createSubscription","createCachedSubscription","arguments","cacheKey","toString","handleLoginRedirect","origin","win","window","response","location","hash","search","msg","authResponseProperty","opener","postMessage","toObject","val","TypeError","Object","shouldUseNative","assign","test1","String","getOwnPropertyNames","test2","i","fromCharCode","order2","map","n","join","test3","split","forEach","letter","keys","err","getOwnPropertySymbols","hasOwnProperty","propIsEnumerable","propertyIsEnumerable","target","source","from","symbols","to","s","length","key","_prefix","defaultPrefix","setItem","data","localStorage","_prefixKey","JSON","stringify","removeItem","getItem","item","parse","clean","indexOf","findHeaderName","name","headers","toLowerCase","reduce","res","EventEmitter","events","beforeRequest","requestSuccess","requestError","isPlainObject","ApiResponse","qs","_allowedMethods","create","sendRequest","request","apiResponse","Promise","resolve","emit","_loadResponse","bind","then","receiveResponse","ok","Error","catch","e","makeError","fetch","originalMessage","message","error","createRequest","init","url","method","toUpperCase","credentials","mode","query","Accept","_jsonContentType","body","contentTypeHeaderName","_contentType","contentType","_urlencodedContentType","req","Request","originalBody","isObjectObject","o","isObject","ctor","prot","constructor","Array","isArray","_events","_maxListeners","isFunction","arg","isNumber","isUndefined","defaultMaxListeners","setMaxListeners","isNaN","type","er","handler","len","args","listeners","context","slice","apply","addListener","listener","newListener","push","warned","console","trace","on","once","g","removeListener","fired","list","position","splice","removeAllListeners","ret","listenerCount","evlistener","emitter","_request","_response","_text","responseText","_json","_multipart","_multipartContentType","_headerSeparator","_bodySeparator","_boundarySeparator","_unauthorizedStatus","_rateLimitStatus","_isMultipart","_isJson","text","json","skipOKCheck","status","statusText","error_description","description","toMultipart","multipart","boundary","_getContentType","match","parts","trim","shift","pop","statusInfo","_create","part","_isContentType","get","replace","Headers","headersAndBody","headersText","header","value","append","Response","decode","encode","obj","prop","sep","eq","regexp","maxKeys","kstr","vstr","k","v","x","idx","substr","decodeURIComponent","stringifyPrimitive","isFinite","ks","encodeURIComponent","global","PubNub","pubnub","es6Promise","fetchPonyfill","FetchPonyfill","beforeLogin","loginSuccess","loginError","beforeRefresh","refreshSuccess","refreshError","beforeLogout","logoutSuccess","logoutError","rateLimitError","_server","_appKey","appKey","_appSecret","appSecret","_redirectUri","redirectUri","_refreshDelayMs","refreshDelayMs","_clearCacheOnRefreshError","clearCacheOnRefreshError","_userAgent","appName","appVersion","_knownPrefixes","knownPrefixes","_refreshPromise","_auth","Auth","cacheId","_cacheId","refreshHandicapMs","_urlPrefix","_apiVersion","_tokenEndpoint","_revokeEndpoint","_authorizeEndpoint","delay","timeout","reject","setTimeout","auth","createUrl","path","builtUrl","hasHttp","alreadyPrefixed","some","addServer","addMethod","addToken","accessToken","loginUrl","response_type","implicit","redirect_uri","client_id","state","brand_id","brandId","display","prompt","parseLoginRedirect","getParts","separator","reverse","queryString","loginWindow","width","height","property","dualScreenLeft","screenLeft","screen","left","dualScreenTop","screenTop","top","innerWidth","document","documentElement","clientWidth","innerHeight","clientHeight","open","focus","eventMethod","addEventListener","eventRemoveMethod","messageEvent","eventListener","close","loginOptions","code","access_token","loggedIn","ensureLoggedIn","login","grant_type","username","password","extension","endpointId","endpoint_id","accessTokenTtl","access_token_ttl","refreshTokenTtl","refresh_token_ttl","_tokenRequest","setData","_refresh","refreshToken","refreshTokenValid","refresh_token","expires_in","refresh_token_expires_in","refresh","logout","token","inflateRequest","skipAuthCheck","set","_authHeader","retry","retryAfter","cancelAccessToken","defaultRetryAfter","handleRateLimit","parseFloat","send","post","put","_isAccessTokenValid","Authorization","_apiKey","Content-Type","accessTokenValid","apiKey","btoa","Buffer","tokenType","_refreshHandicapMs","token_type","newData","expire_time","Date","now","refresh_token_expire_time","authData","buildIEFriendlyString","$1","$2","parseISOString","time","ISO_REG_EXP","notification","removeSuccess","removeError","renewSuccess","renewError","subscribeSuccess","subscribeError","automaticRenewSuccess","automaticRenewError","_pollInterval","pollInterval","_renewHandicapMs","renewHandicapMs","_pubnub","_pubnubLastChannel","_pubnubLastSubscribeKey","_timeout","_subscription","subscribed","subscription","deliveryMode","subscriberKey","address","alive","expirationTime","expired","setSubscription","_clearTimeout","_setSubscription","_subscribeAtPubnub","_setTimeout","register","renew","subscribe","eventFilters","addEventFilters","setEventFilters","concat","_getFullEventFilters","transportType","reset","remove","delete","resubscribe","filters","_unsubscribeAtPubnub","event","setInterval","clearInterval","_decrypt","encryptionKey","decrypt","encryptKey","keyEncoding","keyLength","_notify","unsubscribeAll","ssl","restore","subscribeKey","keepAlive","statusEvent","channels","destroy","_cacheKey"],"mappings":"CAAA,SAAAA,EAAAC,GACA,gBAAAC,UAAA,gBAAAC,QACAA,OAAAD,QAAAD,EAAAG,QAAAC,QAAAD,QAAAC,QAAAD,QAAAC,SACA,kBAAAC,gBAAAC,IACAD,QAAA,yCAAAL,GACA,gBAAAC,SACAA,QAAA,IAAAD,EAAAG,QAAAC,QAAAD,QAAAC,QAAAD,QAAAC,UAEAL,EAAA,YAAAA,EAAA,gBAAiDA,EAAA,gBAAAC,EAAAD,EAAAK,QAAAL,EAAAK,QAAAL,EAAAK,WAChDG,KAAA,S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b,QAAAjQ,aACAqC,OAAA,SAAA4Q,GACAxe,KAAA6H,KAAA7H,KAAA+G,OAAA6G,OAAA4Q,IACazW,KAAA/H,MACbyI,QAAA,SAAA9H,GACAX,KAAAke,QAAAvd,EAAA8H,UACaV,KAAA/H,QAQb,MAHAA,MAAAyb,mBAAAM,EAAAE,QACAjc,KAAAwb,QAAAoB,WAA4B6B,UAAA1C,EAAAE,WAE5Bjc,MAQA8B,EAAAO,UAAAmb,qBAAA,WAEA,MAAAxd,MAAA6b,cAAA7b,KAAAwb,SAEAxb,KAAAwb,QAAAlP,qBACAtM,KAAAwb,QAAAkD,UAEA1e,KAAA0b,wBAAA,KACA1b,KAAAyb,mBAAA,KACAzb,KAAAwb,QAAA,KAEAxb,MATAA,MAaAL,EAAAD,QAAAoC,GpB8wEM,SAASnC,EAAQD,EAASW,GqBlvFhC,QAAA0B,GAAAhB,GAIA,GAFAA,SAEAA,EAAA2B,SAAA,SAAAyF,OAAA,gEAGAnI,MAAA2e,UAAA5d,EAAA2B,SAEAZ,EAAApB,KAAAV,KAAAe,GAGAf,KAAAkB,OAAAH,EAAAc,MAGA7B,KAAA4b,cAAA/b,OA7BA,GAAAiC,GAAAzB,EAAA,GAiCA0B,GAAAM,UAAAsB,OAAA4D,OAAAzF,EAAAO,WAEAN,EAAAM,UAAAyZ,aAAA,WACA,MAAA9b,MAAAkB,OAAAiF,QAAAnG,KAAA2e,gBAGA5c,EAAAM,UAAAka,iBAAA,SAAAT,GACA,MAAA9b,MAAAkB,OAAA0E,QAAA5F,KAAA2e,UAAA7C,IAQA/Z,EAAAM,UAAAgc,QAAA,SAAAtX,GAMA,MAJA/G,MAAA6c,eAAArX,QACAxF,KAAA+c,gBAAAhW,GAGA/G,MAIAL,EAAAD,QAAAqC","file":"ringcentral.min.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory(require(undefined), require(undefined), require(undefined));\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([\"pubnub\", \"es6-promise\", \"fetch-ponyfill\"], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"SDK\"] = factory(require(undefined), require(undefined), require(undefined));\n\telse\n\t\troot[\"RingCentral\"] = root[\"RingCentral\"] || {}, root[\"RingCentral\"][\"SDK\"] = factory(root[undefined], root[undefined], root[undefined]);\n})(this, function(__WEBPACK_EXTERNAL_MODULE_12__, __WEBPACK_EXTERNAL_MODULE_13__, __WEBPACK_EXTERNAL_MODULE_14__) {\nreturn \n\n\n// WEBPACK FOOTER //\n// webpack/universalModuleDefinition","(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory(require(undefined), require(undefined), require(undefined));\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([\"pubnub\", \"es6-promise\", \"fetch-ponyfill\"], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"SDK\"] = factory(require(undefined), require(undefined), require(undefined));\n\telse\n\t\troot[\"RingCentral\"] = root[\"RingCentral\"] || {}, root[\"RingCentral\"][\"SDK\"] = factory(root[undefined], root[undefined], root[undefined]);\n})(this, function(__WEBPACK_EXTERNAL_MODULE_12__, __WEBPACK_EXTERNAL_MODULE_13__, __WEBPACK_EXTERNAL_MODULE_14__) {\nreturn /******/ (function(modules) { // webpackBootstrap\n/******/ \t// The module cache\n/******/ \tvar installedModules = {};\n/******/\n/******/ \t// The require function\n/******/ \tfunction __webpack_require__(moduleId) {\n/******/\n/******/ \t\t// Check if module is in cache\n/******/ \t\tif(installedModules[moduleId])\n/******/ \t\t\treturn installedModules[moduleId].exports;\n/******/\n/******/ \t\t// Create a new module (and put it into the cache)\n/******/ \t\tvar module = installedModules[moduleId] = {\n/******/ \t\t\texports: {},\n/******/ \t\t\tid: moduleId,\n/******/ \t\t\tloaded: false\n/******/ \t\t};\n/******/\n/******/ \t\t// Execute the module function\n/******/ \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n/******/\n/******/ \t\t// Flag the module as loaded\n/******/ \t\tmodule.loaded = true;\n/******/\n/******/ \t\t// Return the exports of the module\n/******/ \t\treturn module.exports;\n/******/ \t}\n/******/\n/******/\n/******/ \t// expose the modules object (__webpack_modules__)\n/******/ \t__webpack_require__.m = modules;\n/******/\n/******/ \t// expose the module cache\n/******/ \t__webpack_require__.c = installedModules;\n/******/\n/******/ \t// __webpack_public_path__\n/******/ \t__webpack_require__.p = \"/build/\";\n/******/\n/******/ \t// Load entry module and return exports\n/******/ \treturn __webpack_require__(0);\n/******/ })\n/************************************************************************/\n/******/ ([\n/* 0 */\n/***/ function(module, exports, __webpack_require__) {\n\n/**\n * @namespace RingCentral\n */\nvar objectAssign = __webpack_require__(1);\nvar Cache = __webpack_require__(2);\nvar Client = __webpack_require__(3);\nvar Externals = __webpack_require__(11);\nvar Platform = __webpack_require__(15);\nvar Subscription = __webpack_require__(18);\nvar CachedSubscription = __webpack_require__(19);\nvar Constants = __webpack_require__(17);\n\n/**\n * @constructor\n * @param {string} options.server\n * @param {string} options.appSecret\n * @param {string} options.appKey\n * @param {string} [options.cachePrefix]\n * @param {string} [options.appName]\n * @param {string} [options.appVersion]\n * @param {string} [options.redirectUri]\n * @param {PubNub} [options.PubNub]\n * @param {function(new:Promise)} [options.Promise]\n * @param {Storage} [options.localStorage]\n * @param {fetch} [options.fetch]\n * @param {function(new:Request)} [options.Request]\n * @param {function(new:Response)} [options.Response]\n * @param {function(new:Headers)} [options.Headers]\n * @param {int} [options.refreshDelayMs]\n * @param {int} [options.refreshHandicapMs]\n * @param {boolean} [options.clearCacheOnRefreshError]\n * @property {Externals} _externals\n * @property {Cache} _cache\n * @property {Client} _client\n * @property {Platform} _platform\n */\nfunction SDK(options) {\n\n /** @private */\n this._externals = new Externals(options);\n\n /** @private */\n this._cache = new Cache({\n externals: this._externals,\n prefix: options.cachePrefix\n });\n\n /** @private */\n this._client = new Client(this._externals);\n\n /** @private */\n this._platform = new Platform(objectAssign({}, options, {\n externals: this._externals,\n client: this._client,\n cache: this._cache\n }));\n\n}\n\nSDK.version = Constants.version;\n\nSDK.server = {\n sandbox: 'https://platform.devtest.ringcentral.com',\n production: 'https://platform.ringcentral.com'\n};\n\n/**\n * @return {Platform}\n */\nSDK.prototype.platform = function() {\n return this._platform;\n};\n\n/**\n * @return {Cache}\n */\nSDK.prototype.cache = function() {\n return this._cache;\n};\n\n/**\n * @param {int} [options.pollInterval]\n * @param {int} [options.renewHandicapMs]\n * @return {Subscription}\n */\nSDK.prototype.createSubscription = function(options) {\n return new Subscription(objectAssign({}, options, {\n externals: this._externals,\n platform: this._platform\n }));\n};\n\n/**\n * @param {string} options.cacheKey\n * @param {int} [options.pollInterval]\n * @param {int} [options.renewHandicapMs]\n * @return {CachedSubscription}\n */\nSDK.prototype.createCachedSubscription = function(options) {\n\n if (typeof arguments[0] === 'string') {\n options = {cacheKey: arguments[0].toString()};\n } else {\n options = options || {};\n }\n\n return new CachedSubscription(objectAssign({}, options, {\n externals: this._externals,\n platform: this._platform,\n cache: this._cache\n }));\n\n};\n\nSDK.handleLoginRedirect = function(origin, win) {\n\n win = win || window;\n\n var response = win.location.hash ? win.location.hash : win.location.search;\n var msg = {};\n msg[Constants.authResponseProperty] = response;\n win.opener.postMessage(msg, origin || win.location.origin);\n\n};\n\nmodule.exports = SDK;\n\n/***/ },\n/* 1 */\n/***/ function(module, exports) {\n\n/*\nobject-assign\n(c) Sindre Sorhus\n@license MIT\n*/\n\n'use strict';\n/* eslint-disable no-unused-vars */\nvar getOwnPropertySymbols = Object.getOwnPropertySymbols;\nvar hasOwnProperty = Object.prototype.hasOwnProperty;\nvar propIsEnumerable = Object.prototype.propertyIsEnumerable;\n\nfunction toObject(val) {\n\tif (val === null || val === undefined) {\n\t\tthrow new TypeError('Object.assign cannot be called with null or undefined');\n\t}\n\n\treturn Object(val);\n}\n\nfunction shouldUseNative() {\n\ttry {\n\t\tif (!Object.assign) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Detect buggy property enumeration order in older V8 versions.\n\n\t\t// https://bugs.chromium.org/p/v8/issues/detail?id=4118\n\t\tvar test1 = new String('abc'); // eslint-disable-line no-new-wrappers\n\t\ttest1[5] = 'de';\n\t\tif (Object.getOwnPropertyNames(test1)[0] === '5') {\n\t\t\treturn false;\n\t\t}\n\n\t\t// https://bugs.chromium.org/p/v8/issues/detail?id=3056\n\t\tvar test2 = {};\n\t\tfor (var i = 0; i < 10; i++) {\n\t\t\ttest2['_' + String.fromCharCode(i)] = i;\n\t\t}\n\t\tvar order2 = Object.getOwnPropertyNames(test2).map(function (n) {\n\t\t\treturn test2[n];\n\t\t});\n\t\tif (order2.join('') !== '0123456789') {\n\t\t\treturn false;\n\t\t}\n\n\t\t// https://bugs.chromium.org/p/v8/issues/detail?id=3056\n\t\tvar test3 = {};\n\t\t'abcdefghijklmnopqrst'.split('').forEach(function (letter) {\n\t\t\ttest3[letter] = letter;\n\t\t});\n\t\tif (Object.keys(Object.assign({}, test3)).join('') !==\n\t\t\t\t'abcdefghijklmnopqrst') {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn true;\n\t} catch (err) {\n\t\t// We don't expect any of the above to throw, but better to be safe.\n\t\treturn false;\n\t}\n}\n\nmodule.exports = shouldUseNative() ? Object.assign : function (target, source) {\n\tvar from;\n\tvar to = toObject(target);\n\tvar symbols;\n\n\tfor (var s = 1; s < arguments.length; s++) {\n\t\tfrom = Object(arguments[s]);\n\n\t\tfor (var key in from) {\n\t\t\tif (hasOwnProperty.call(from, key)) {\n\t\t\t\tto[key] = from[key];\n\t\t\t}\n\t\t}\n\n\t\tif (getOwnPropertySymbols) {\n\t\t\tsymbols = getOwnPropertySymbols(from);\n\t\t\tfor (var i = 0; i < symbols.length; i++) {\n\t\t\t\tif (propIsEnumerable.call(from, symbols[i])) {\n\t\t\t\t\tto[symbols[i]] = from[symbols[i]];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn to;\n};\n\n\n/***/ },\n/* 2 */\n/***/ function(module, exports) {\n\n/**\n * @param {Externals} options.externals\n * @param {string} [options.prefix]\n * @property {Externals} _externals\n */\nfunction Cache(options) {\n\n /** @private */\n this._prefix = options.prefix || Cache.defaultPrefix;\n\n /** @private */\n this._externals = options.externals;\n\n}\n\nCache.defaultPrefix = 'rc-';\n\nCache.prototype.setItem = function(key, data) {\n this._externals.localStorage[this._prefixKey(key)] = JSON.stringify(data);\n return this;\n};\n\nCache.prototype.removeItem = function(key) {\n delete this._externals.localStorage[this._prefixKey(key)];\n return this;\n};\n\nCache.prototype.getItem = function(key) {\n var item = this._externals.localStorage[this._prefixKey(key)];\n if (!item) return null;\n return JSON.parse(item);\n};\n\nCache.prototype.clean = function() {\n\n for (var key in this._externals.localStorage) {\n\n /* istanbul ignore next */\n if (!this._externals.localStorage.hasOwnProperty(key)) continue;\n\n if (key.indexOf(this._prefix) === 0) {\n delete this._externals.localStorage[key];\n }\n\n }\n\n return this;\n\n};\n\nCache.prototype._prefixKey = function(key) {\n return this._prefix + key;\n};\n\nmodule.exports = Cache;\n\n/***/ },\n/* 3 */\n/***/ function(module, exports, __webpack_require__) {\n\nvar isPlainObject = __webpack_require__(4);\nvar EventEmitter = __webpack_require__(6).EventEmitter;\nvar ApiResponse = __webpack_require__(7);\nvar qs = __webpack_require__(8);\n\nfunction 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 * @param {Externals} externals\n * @property {Externals} _externals\n */\nfunction Client(externals) {\n\n EventEmitter.call(this);\n\n /** @private */\n this._externals = externals;\n\n this.events = {\n beforeRequest: 'beforeRequest',\n requestSuccess: 'requestSuccess',\n requestError: 'requestError'\n };\n\n}\n\nClient._allowedMethods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS', 'HEAD'];\n\nClient.prototype = Object.create(EventEmitter.prototype);\n\n/**\n * @param {Request} request\n * @return {Promise}\n */\nClient.prototype.sendRequest = function(request) {\n\n var apiResponse = new ApiResponse({\n externals: this._externals,\n request: request\n });\n\n return (new this._externals.Promise(function(resolve) {\n\n //TODO Stop request if listeners return false\n this.emit(this.events.beforeRequest, apiResponse);\n\n resolve(this._loadResponse(request));\n\n }.bind(this))).then(function(response) {\n\n return apiResponse.receiveResponse(response);\n\n }).then(function() {\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 }.bind(this)).catch(function(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 }.bind(this));\n\n};\n\n/**\n * @param {Request} request\n * @return {Promise}\n * @private\n */\nClient.prototype._loadResponse = function(request) {\n return this._externals.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 */\nClient.prototype.makeError = function(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 * @param {object} [init.credentials]\n * @param {object} [init.mode]\n * @return {Request}\n */\nClient.prototype.createRequest = function(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 init.method = init.method.toUpperCase();\n if (init.method && Client._allowedMethods.indexOf(init.method) < 0) {\n throw new Error('Method has wrong value: ' + init.method);\n }\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 ? '&' : '?') + qs.stringify(init.query);\n }\n\n if (!(findHeaderName('Accept', init.headers))) {\n init.headers.Accept = ApiResponse._jsonContentType;\n }\n\n // Serialize body\n if (isPlainObject(init.body) || !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 if ((init.method === 'GET' || init.method === 'HEAD') && !!init.body) {\n // oddly setting body to null still result in TypeError in phantomjs\n init.body = undefined;\n } else {\n init.body = JSON.stringify(init.body);\n }\n\n } else if (contentType.indexOf(ApiResponse._urlencodedContentType) > -1) {\n init.body = qs.stringify(init.body);\n }\n\n }\n\n // Create a request with encoded body\n var req = new this._externals.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 * @typedef {object} IApiError\n * @property {string} stack\n * @property {string} originalMessage\n * @property {ApiResponse} apiResponse\n */\n\nmodule.exports = Client;\n\n/***/ },\n/* 4 */\n/***/ function(module, exports, __webpack_require__) {\n\n/*!\n * is-plain-object \n *\n * Copyright (c) 2014-2017, Jon Schlinkert.\n * Released under the MIT License.\n */\n\n'use strict';\n\nvar isObject = __webpack_require__(5);\n\nfunction isObjectObject(o) {\n return isObject(o) === true\n && Object.prototype.toString.call(o) === '[object Object]';\n}\n\nmodule.exports = function isPlainObject(o) {\n var ctor,prot;\n\n if (isObjectObject(o) === false) return false;\n\n // If has modified constructor\n ctor = o.constructor;\n if (typeof ctor !== 'function') return false;\n\n // If has modified prototype\n prot = ctor.prototype;\n if (isObjectObject(prot) === false) return false;\n\n // If constructor does not have an Object-specific method\n if (prot.hasOwnProperty('isPrototypeOf') === false) {\n return false;\n }\n\n // Most likely a plain Object\n return true;\n};\n\n\n/***/ },\n/* 5 */\n/***/ function(module, exports) {\n\n/*!\n * isobject \n *\n * Copyright (c) 2014-2017, Jon Schlinkert.\n * Released under the MIT License.\n */\n\n'use strict';\n\nmodule.exports = function isObject(val) {\n return val != null && typeof val === 'object' && Array.isArray(val) === false;\n};\n\n\n/***/ },\n/* 6 */\n/***/ function(module, exports) {\n\n// Copyright Joyent, Inc. and other Node contributors.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a\n// copy of this software and associated documentation files (the\n// \"Software\"), to deal in the Software without restriction, including\n// without limitation the rights to use, copy, modify, merge, publish,\n// distribute, sublicense, and/or sell copies of the Software, and to permit\n// persons to whom the Software is furnished to do so, subject to the\n// following conditions:\n//\n// The above copyright notice and this permission notice shall be included\n// in all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\n// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN\n// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,\n// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE\n// USE OR OTHER DEALINGS IN THE SOFTWARE.\n\nfunction EventEmitter() {\n this._events = this._events || {};\n this._maxListeners = this._maxListeners || undefined;\n}\nmodule.exports = EventEmitter;\n\n// Backwards-compat with node 0.10.x\nEventEmitter.EventEmitter = EventEmitter;\n\nEventEmitter.prototype._events = undefined;\nEventEmitter.prototype._maxListeners = undefined;\n\n// By default EventEmitters will print a warning if more than 10 listeners are\n// added to it. This is a useful default which helps finding memory leaks.\nEventEmitter.defaultMaxListeners = 10;\n\n// Obviously not all Emitters should be limited to 10. This function allows\n// that to be increased. Set to zero for unlimited.\nEventEmitter.prototype.setMaxListeners = function(n) {\n if (!isNumber(n) || n < 0 || isNaN(n))\n throw TypeError('n must be a positive number');\n this._maxListeners = n;\n return this;\n};\n\nEventEmitter.prototype.emit = function(type) {\n var er, handler, len, args, i, listeners;\n\n if (!this._events)\n this._events = {};\n\n // If there is no 'error' event listener then throw.\n if (type === 'error') {\n if (!this._events.error ||\n (isObject(this._events.error) && !this._events.error.length)) {\n er = arguments[1];\n if (er instanceof Error) {\n throw er; // Unhandled 'error' event\n } else {\n // At least give some kind of context to the user\n var err = new Error('Uncaught, unspecified \"error\" event. (' + er + ')');\n err.context = er;\n throw err;\n }\n }\n }\n\n handler = this._events[type];\n\n if (isUndefined(handler))\n return false;\n\n if (isFunction(handler)) {\n switch (arguments.length) {\n // fast cases\n case 1:\n handler.call(this);\n break;\n case 2:\n handler.call(this, arguments[1]);\n break;\n case 3:\n handler.call(this, arguments[1], arguments[2]);\n break;\n // slower\n default:\n args = Array.prototype.slice.call(arguments, 1);\n handler.apply(this, args);\n }\n } else if (isObject(handler)) {\n args = Array.prototype.slice.call(arguments, 1);\n listeners = handler.slice();\n len = listeners.length;\n for (i = 0; i < len; i++)\n listeners[i].apply(this, args);\n }\n\n return true;\n};\n\nEventEmitter.prototype.addListener = function(type, listener) {\n var m;\n\n if (!isFunction(listener))\n throw TypeError('listener must be a function');\n\n if (!this._events)\n this._events = {};\n\n // To avoid recursion in the case that type === \"newListener\"! Before\n // adding it to the listeners, first emit \"newListener\".\n if (this._events.newListener)\n this.emit('newListener', type,\n isFunction(listener.listener) ?\n listener.listener : listener);\n\n if (!this._events[type])\n // Optimize the case of one listener. Don't need the extra array object.\n this._events[type] = listener;\n else if (isObject(this._events[type]))\n // If we've already got an array, just append.\n this._events[type].push(listener);\n else\n // Adding the second element, need to change to array.\n this._events[type] = [this._events[type], listener];\n\n // Check for listener leak\n if (isObject(this._events[type]) && !this._events[type].warned) {\n if (!isUndefined(this._maxListeners)) {\n m = this._maxListeners;\n } else {\n m = EventEmitter.defaultMaxListeners;\n }\n\n if (m && m > 0 && this._events[type].length > m) {\n this._events[type].warned = true;\n console.error('(node) warning: possible EventEmitter memory ' +\n 'leak detected. %d listeners added. ' +\n 'Use emitter.setMaxListeners() to increase limit.',\n this._events[type].length);\n if (typeof console.trace === 'function') {\n // not supported in IE 10\n console.trace();\n }\n }\n }\n\n return this;\n};\n\nEventEmitter.prototype.on = EventEmitter.prototype.addListener;\n\nEventEmitter.prototype.once = function(type, listener) {\n if (!isFunction(listener))\n throw TypeError('listener must be a function');\n\n var fired = false;\n\n function g() {\n this.removeListener(type, g);\n\n if (!fired) {\n fired = true;\n listener.apply(this, arguments);\n }\n }\n\n g.listener = listener;\n this.on(type, g);\n\n return this;\n};\n\n// emits a 'removeListener' event iff the listener was removed\nEventEmitter.prototype.removeListener = function(type, listener) {\n var list, position, length, i;\n\n if (!isFunction(listener))\n throw TypeError('listener must be a function');\n\n if (!this._events || !this._events[type])\n return this;\n\n list = this._events[type];\n length = list.length;\n position = -1;\n\n if (list === listener ||\n (isFunction(list.listener) && list.listener === listener)) {\n delete this._events[type];\n if (this._events.removeListener)\n this.emit('removeListener', type, listener);\n\n } else if (isObject(list)) {\n for (i = length; i-- > 0;) {\n if (list[i] === listener ||\n (list[i].listener && list[i].listener === listener)) {\n position = i;\n break;\n }\n }\n\n if (position < 0)\n return this;\n\n if (list.length === 1) {\n list.length = 0;\n delete this._events[type];\n } else {\n list.splice(position, 1);\n }\n\n if (this._events.removeListener)\n this.emit('removeListener', type, listener);\n }\n\n return this;\n};\n\nEventEmitter.prototype.removeAllListeners = function(type) {\n var key, listeners;\n\n if (!this._events)\n return this;\n\n // not listening for removeListener, no need to emit\n if (!this._events.removeListener) {\n if (arguments.length === 0)\n this._events = {};\n else if (this._events[type])\n delete this._events[type];\n return this;\n }\n\n // emit removeListener for all listeners on all events\n if (arguments.length === 0) {\n for (key in this._events) {\n if (key === 'removeListener') continue;\n this.removeAllListeners(key);\n }\n this.removeAllListeners('removeListener');\n this._events = {};\n return this;\n }\n\n listeners = this._events[type];\n\n if (isFunction(listeners)) {\n this.removeListener(type, listeners);\n } else if (listeners) {\n // LIFO order\n while (listeners.length)\n this.removeListener(type, listeners[listeners.length - 1]);\n }\n delete this._events[type];\n\n return this;\n};\n\nEventEmitter.prototype.listeners = function(type) {\n var ret;\n if (!this._events || !this._events[type])\n ret = [];\n else if (isFunction(this._events[type]))\n ret = [this._events[type]];\n else\n ret = this._events[type].slice();\n return ret;\n};\n\nEventEmitter.prototype.listenerCount = function(type) {\n if (this._events) {\n var evlistener = this._events[type];\n\n if (isFunction(evlistener))\n return 1;\n else if (evlistener)\n return evlistener.length;\n }\n return 0;\n};\n\nEventEmitter.listenerCount = function(emitter, type) {\n return emitter.listenerCount(type);\n};\n\nfunction isFunction(arg) {\n return typeof arg === 'function';\n}\n\nfunction isNumber(arg) {\n return typeof arg === 'number';\n}\n\nfunction isObject(arg) {\n return typeof arg === 'object' && arg !== null;\n}\n\nfunction isUndefined(arg) {\n return arg === void 0;\n}\n\n\n/***/ },\n/* 7 */\n/***/ function(module, exports) {\n\n/**\n * @param {Externals} options.externals\n * @param {Request} [options.request]\n * @param {Response} [options.response]\n * @param {string} [options.responseText]\n * @property {Externals} _externals\n * @property {Request} _request\n * @property {Response} _response\n * @property {string} _text\n * @property {object} _json\n * @property {ApiResponse[]} _multipart\n */\nfunction ApiResponse(options) {\n\n /** @private */\n this._externals = options.externals;\n\n /** @private */\n this._request = options.request;\n\n /** @private */\n this._response = options.response;\n\n /** @private */\n this._text = options.responseText || '';\n\n /** @private */\n this._json = null;\n\n /** @private */\n this._multipart = [];\n\n}\n\nApiResponse._contentType = 'Content-Type';\nApiResponse._jsonContentType = 'application/json';\nApiResponse._multipartContentType = 'multipart/mixed';\nApiResponse._urlencodedContentType = 'application/x-www-form-urlencoded';\nApiResponse._headerSeparator = ':';\nApiResponse._bodySeparator = '\\n\\n';\nApiResponse._boundarySeparator = '--';\nApiResponse._unauthorizedStatus = 401;\nApiResponse._rateLimitStatus = 429;\n\n/**\n * @param {Response} response\n * @return {Promise}\n */\nApiResponse.prototype.receiveResponse = function(response) {\n\n this._response = response;\n\n return (new this._externals.Promise(function(resolve) {\n\n // Ignore if not textual type\n if (!this._isMultipart() && !this._isJson()) return resolve('');\n\n return resolve(this.response().text());\n\n }.bind(this))).then(function(text) {\n\n this._text = text;\n return text;\n\n }.bind(this));\n\n};\n\n/**\n * @return {Response}\n */\nApiResponse.prototype.response = function() {\n return this._response;\n};\n\n/**\n * @return {Request}\n */\nApiResponse.prototype.request = function() {\n return this._request;\n};\n\n/**\n * @return {boolean}\n */\nApiResponse.prototype.ok = function() {\n return this._response && this._response.ok;\n};\n\n/**\n * @return {string}\n */\nApiResponse.prototype.text = function() {\n // Since we read text only in case JSON or Multipart\n if (!this._isJson() && !this._isMultipart()) throw new Error('Response is not text');\n return this._text;\n};\n\n/**\n * @return {object}\n */\nApiResponse.prototype.json = function() {\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 */\nApiResponse.prototype.error = function(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 * If it is not known upfront what would be the response, client code can treat any response as multipart\n * @return {ApiResponse[]}\n */\nApiResponse.prototype.toMultipart = function() {\n if (!this._isMultipart()) return [this];\n return this.multipart();\n};\n\n/**\n * @return {ApiResponse[]}\n */\nApiResponse.prototype.multipart = function() {\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;\n\n try {\n boundary = this._getContentType().match(/boundary=([^;]+)/i)[1];\n } catch (e) {\n throw new Error('Cannot find boundary');\n }\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 = this._create(parts.shift(), this._response.status, this._response.statusText).json();\n\n // Step 3. Parse all other parts\n\n this._multipart = parts.map(function(part, i) {\n\n var status = statusInfo.response[i].status;\n\n return this._create(part, status);\n\n }.bind(this));\n\n }\n\n return this._multipart;\n\n};\n\n/**\n * @private\n */\nApiResponse.prototype._isContentType = function(contentType) {\n return this._getContentType().indexOf(contentType) > -1;\n};\n\n/**\n * @private\n */\nApiResponse.prototype._getContentType = function() {\n return this._response.headers.get(ApiResponse._contentType) || '';\n};\n\n/**\n * @private\n */\nApiResponse.prototype._isMultipart = function() {\n return this._isContentType(ApiResponse._multipartContentType);\n};\n\n/**\n * @private\n */\nApiResponse.prototype._isJson = function() {\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 * @private\n * @return {ApiResponse}\n */\nApiResponse.prototype._create = function(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 this._externals.Headers(),\n headersAndBody = text.split(ApiResponse._bodySeparator),\n headersText = (headersAndBody.length > 1) ? headersAndBody.shift() : '';\n\n text = headersAndBody.length > 0 ? headersAndBody.join(ApiResponse._bodySeparator) : null;\n\n (headersText || '')\n .split('\\n')\n .forEach(function(header) {\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 var response = new this._externals.Response(text, {\n headers: headers,\n status: status,\n statusText: statusText\n });\n\n return new ApiResponse({\n externals: this._externals,\n request: null,\n response: response,\n responseText: text\n });\n\n};\n\nmodule.exports = ApiResponse;\n\n/***/ },\n/* 8 */\n/***/ function(module, exports, __webpack_require__) {\n\n'use strict';\n\nexports.decode = exports.parse = __webpack_require__(9);\nexports.encode = exports.stringify = __webpack_require__(10);\n\n\n/***/ },\n/* 9 */\n/***/ function(module, exports) {\n\n// Copyright Joyent, Inc. and other Node contributors.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a\n// copy of this software and associated documentation files (the\n// \"Software\"), to deal in the Software without restriction, including\n// without limitation the rights to use, copy, modify, merge, publish,\n// distribute, sublicense, and/or sell copies of the Software, and to permit\n// persons to whom the Software is furnished to do so, subject to the\n// following conditions:\n//\n// The above copyright notice and this permission notice shall be included\n// in all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\n// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN\n// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,\n// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE\n// USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n'use strict';\n\n// If obj.hasOwnProperty has been overridden, then calling\n// obj.hasOwnProperty(prop) will break.\n// See: https://github.com/joyent/node/issues/1707\nfunction hasOwnProperty(obj, prop) {\n return Object.prototype.hasOwnProperty.call(obj, prop);\n}\n\nmodule.exports = function(qs, sep, eq, options) {\n sep = sep || '&';\n eq = eq || '=';\n var obj = {};\n\n if (typeof qs !== 'string' || qs.length === 0) {\n return obj;\n }\n\n var regexp = /\\+/g;\n qs = qs.split(sep);\n\n var maxKeys = 1000;\n if (options && typeof options.maxKeys === 'number') {\n maxKeys = options.maxKeys;\n }\n\n var len = qs.length;\n // maxKeys <= 0 means that we should not limit keys count\n if (maxKeys > 0 && len > maxKeys) {\n len = maxKeys;\n }\n\n for (var i = 0; i < len; ++i) {\n var x = qs[i].replace(regexp, '%20'),\n idx = x.indexOf(eq),\n kstr, vstr, k, v;\n\n if (idx >= 0) {\n kstr = x.substr(0, idx);\n vstr = x.substr(idx + 1);\n } else {\n kstr = x;\n vstr = '';\n }\n\n k = decodeURIComponent(kstr);\n v = decodeURIComponent(vstr);\n\n if (!hasOwnProperty(obj, k)) {\n obj[k] = v;\n } else if (Array.isArray(obj[k])) {\n obj[k].push(v);\n } else {\n obj[k] = [obj[k], v];\n }\n }\n\n return obj;\n};\n\n\n/***/ },\n/* 10 */\n/***/ function(module, exports) {\n\n// Copyright Joyent, Inc. and other Node contributors.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a\n// copy of this software and associated documentation files (the\n// \"Software\"), to deal in the Software without restriction, including\n// without limitation the rights to use, copy, modify, merge, publish,\n// distribute, sublicense, and/or sell copies of the Software, and to permit\n// persons to whom the Software is furnished to do so, subject to the\n// following conditions:\n//\n// The above copyright notice and this permission notice shall be included\n// in all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\n// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN\n// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,\n// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE\n// USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n'use strict';\n\nvar stringifyPrimitive = function(v) {\n switch (typeof v) {\n case 'string':\n return v;\n\n case 'boolean':\n return v ? 'true' : 'false';\n\n case 'number':\n return isFinite(v) ? v : '';\n\n default:\n return '';\n }\n};\n\nmodule.exports = function(obj, sep, eq, name) {\n sep = sep || '&';\n eq = eq || '=';\n if (obj === null) {\n obj = undefined;\n }\n\n if (typeof obj === 'object') {\n return Object.keys(obj).map(function(k) {\n var ks = encodeURIComponent(stringifyPrimitive(k)) + eq;\n if (Array.isArray(obj[k])) {\n return obj[k].map(function(v) {\n return ks + encodeURIComponent(stringifyPrimitive(v));\n }).join(sep);\n } else {\n return ks + encodeURIComponent(stringifyPrimitive(obj[k]));\n }\n }).join(sep);\n\n }\n\n if (!name) return '';\n return encodeURIComponent(stringifyPrimitive(name)) + eq +\n encodeURIComponent(stringifyPrimitive(obj));\n};\n\n\n/***/ },\n/* 11 */\n/***/ function(module, exports, __webpack_require__) {\n\n/* WEBPACK VAR INJECTION */(function(global) {var pubnub = __webpack_require__(12);\nvar es6Promise = __webpack_require__(13);\nvar FetchPonyfill = __webpack_require__(14);\n\nvar root = (typeof window !== \"undefined\" && window) ||\n (typeof global !== \"undefined\" && global) ||\n (function(){ return this; })();\n\n/**\n * @constructor\n * @param {PubNub} [options.PubNub]\n * @param {function(new:Promise)} [options.Promise]\n * @param {Storage} [options.localStorage]\n * @param {fetch} [options.fetch]\n * @param {function(new:Request)} [options.Request]\n * @param {function(new:Response)} [options.Response]\n * @param {function(new:Headers)} [options.Headers]\n * @property {PubNub} PubNub\n * @property {Storage} localStorage\n * @property {function(new:Promise)} Promise\n * @property {fetch} fetch\n * @property {function(new:Request)} Request\n * @property {function(new:Response)} Response\n * @property {function(new:Headers)} Headers\n */\nfunction Externals(options) {\n\n options = options || {};\n\n this.PubNub = options.PubNub || root.PubNub || pubnub;\n this.localStorage = options.localStorage || ((typeof root.localStorage !== 'undefined') ? root.localStorage : {});\n this.Promise = options.Promise || root.Promise || (es6Promise && es6Promise.Promise);\n\n var fetchPonyfill = FetchPonyfill ? FetchPonyfill({Promise: this.Promise}) : {};\n\n this.fetch = options.fetch || root.fetch || fetchPonyfill.fetch;\n this.Request = options.Request || root.Request || fetchPonyfill.Request;\n this.Response = options.Response || root.Response || fetchPonyfill.Response;\n this.Headers = options.Headers || root.Headers || fetchPonyfill.Headers;\n\n /* istanbul ignore next */\n if (!this.fetch || !this.Response || !this.Request || !this.Headers) {\n throw new Error('Fetch API is missing');\n }\n\n /* istanbul ignore next */\n if (!this.Promise) {\n throw new Error('Promise is missing');\n }\n\n /* istanbul ignore next */\n if (!this.localStorage) {\n throw new Error('LocalStorage is missing');\n }\n\n /* istanbul ignore next */\n if (!this.PubNub) {\n throw new Error('PubNub is missing');\n }\n\n}\n\nmodule.exports = Externals;\n\n/* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))\n\n/***/ },\n/* 12 */\n/***/ function(module, exports) {\n\nmodule.exports = __WEBPACK_EXTERNAL_MODULE_12__;\n\n/***/ },\n/* 13 */\n/***/ function(module, exports) {\n\nmodule.exports = __WEBPACK_EXTERNAL_MODULE_13__;\n\n/***/ },\n/* 14 */\n/***/ function(module, exports) {\n\nmodule.exports = __WEBPACK_EXTERNAL_MODULE_14__;\n\n/***/ },\n/* 15 */\n/***/ function(module, exports, __webpack_require__) {\n\nvar EventEmitter = __webpack_require__(6).EventEmitter;\nvar qs = __webpack_require__(8);\nvar objectAssign = __webpack_require__(1);\nvar Auth = __webpack_require__(16);\nvar Constants = __webpack_require__(17);\nvar ApiResponse = __webpack_require__(7);\n\n/**\n * @constructor\n * @param {string} options.server\n * @param {string} options.appSecret\n * @param {string} options.appKey\n * @param {string} [options.appName]\n * @param {string} [options.appVersion]\n * @param {string} [options.redirectUri]\n * @param {int} [options.refreshDelayMs]\n * @param {int} [options.refreshHandicapMs]\n * @param {boolean} [options.clearCacheOnRefreshError]\n * @param {Externals} options.externals\n * @param {Cache} options.cache\n * @param {Client} options.client\n * @property {Externals} _externals\n * @property {Cache} _cache\n * @property {Client} _client\n * @property {Promise} _refreshPromise\n * @property {Auth} _auth\n */\nfunction Platform(options) {\n\n EventEmitter.call(this);\n\n this.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 rateLimitError: 'rateLimitError'\n };\n\n options = options || {};\n\n /** @private */\n this._server = options.server;\n\n /** @private */\n this._appKey = options.appKey;\n\n /** @private */\n this._appSecret = options.appSecret;\n\n /** @private */\n this._redirectUri = options.redirectUri || '';\n\n /** @private */\n this._refreshDelayMs = options.refreshDelayMs || 100;\n\n /** @private */\n this._clearCacheOnRefreshError = typeof options.clearCacheOnRefreshError !== 'undefined' ?\n options.clearCacheOnRefreshError :\n true;\n\n /** @private */\n this._userAgent = (options.appName ?\n (options.appName + (options.appVersion ? '/' + options.appVersion : '')) + ' ' :\n '') + 'RCJSSDK/' + Constants.version;\n\n /** @private */\n this._externals = options.externals;\n\n /** @private */\n this._cache = options.cache;\n\n /** @private */\n this._client = options.client;\n\n /** @private */\n this._knownPrefixes = options.knownPrefixes || Platform._knownPrefixes;\n\n\n /** @private */\n this._refreshPromise = null;\n\n /** @private */\n this._auth = new Auth({\n cache: this._cache,\n cacheId: Platform._cacheId,\n refreshHandicapMs: options.refreshHandicapMs\n });\n\n}\n\nPlatform._urlPrefix = '/restapi';\nPlatform._apiVersion = 'v1.0';\nPlatform._knownPrefixes = ['/rcvideo'];\nPlatform._tokenEndpoint = '/restapi/oauth/token';\nPlatform._revokeEndpoint = '/restapi/oauth/revoke';\nPlatform._authorizeEndpoint = '/restapi/oauth/authorize';\nPlatform._cacheId = 'platform';\n\nPlatform.prototype = Object.create(EventEmitter.prototype);\n\nPlatform.prototype.delay = function(timeout) {\n return new this._externals.Promise(function(resolve, reject) {\n setTimeout(function() {\n resolve(null);\n }, timeout);\n });\n};\n\n/**\n * @return {Auth}\n */\nPlatform.prototype.auth = function() {\n return this._auth;\n};\n\n/**\n * @return {Client}\n */\nPlatform.prototype.client = function() {\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 */\nPlatform.prototype.createUrl = function(path, options) {\n\n path = path || '';\n options = options || {};\n\n var builtUrl = '',\n hasHttp = path.indexOf('http://') != -1 || path.indexOf('https://') != -1,\n alreadyPrefixed = this._knownPrefixes.some(function(prefix) {\n return path.indexOf(prefix) === 0;\n });\n\n if (options.addServer && !hasHttp) builtUrl += this._server;\n\n if (path.indexOf(Platform._urlPrefix) == -1 && !hasHttp && !alreadyPrefixed) {\n builtUrl += Platform._urlPrefix + '/' + Platform._apiVersion;\n }\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] Overrides default RedirectURI\n * @param {string} [options.state]\n * @param {string} [options.brandId]\n * @param {string} [options.display]\n * @param {string} [options.prompt]\n * @param {boolean} [options.implicit] Use Implicit Grant flow\n * @return {string}\n */\nPlatform.prototype.loginUrl = function(options) {\n\n options = options || {};\n\n return this.createUrl(Platform._authorizeEndpoint + '?' + qs.stringify({\n 'response_type': options.implicit ? 'token' : 'code',\n 'redirect_uri': options.redirectUri || this._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 */\nPlatform.prototype.parseLoginRedirect = function(url) {\n\n function getParts(url, separator) {\n return url.split(separator).reverse()[0];\n }\n\n var response = (url.indexOf('#') === 0 && getParts(url, '#')) ||\n (url.indexOf('?') === 0 && getParts(url, '?')) ||\n null;\n\n if (!response) throw new Error('Unable to parse response');\n\n var queryString = qs.parse(response);\n\n if (!queryString) throw new Error('Unable to parse response');\n\n var error = queryString.error_description || queryString.error;\n\n if (error) {\n var e = new Error(error);\n e.error = queryString.error;\n throw e;\n }\n\n return queryString;\n\n};\n\n/**\n * Convenience method to handle 3-legged OAuth\n *\n * Attention! This is an experimental method and it's signature and behavior may change without notice.\n *\n * @experimental\n * @param {string} options.url\n * @param {number} [options.width]\n * @param {number} [options.height]\n * @param {object} [options.login] additional options for login()\n * @param {string} [options.origin]\n * @param {string} [options.property] name of window.postMessage's event data property\n * @param {string} [options.target] target for window.open()\n * @return {Promise}\n */\nPlatform.prototype.loginWindow = function(options) {\n\n return new this._externals.Promise(function(resolve, reject) {\n\n if (typeof window === 'undefined') throw new Error('This method can be used only in browser');\n\n if (!options.url) throw new Error('Missing mandatory URL parameter');\n\n options = options || {};\n options.width = options.width || 400;\n options.height = options.height || 600;\n options.origin = options.origin || window.location.origin;\n options.property = options.property || Constants.authResponseProperty;\n options.target = options.target || '_blank';\n\n var dualScreenLeft = window.screenLeft !== undefined ? window.screenLeft : screen.left;\n var dualScreenTop = window.screenTop !== undefined ? window.screenTop : screen.top;\n\n var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width;\n var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;\n\n var left = ((width / 2) - (options.width / 2)) + dualScreenLeft;\n var top = ((height / 2) - (options.height / 2)) + dualScreenTop;\n var win = window.open(options.url, '_blank', (options.target == '_blank') ? 'scrollbars=yes, status=yes, width=' + options.width + ', height=' + options.height + ', left=' + left + ', top=' + top : '');\n\n if (!win) {\n throw new Error('Could not open login window. Please allow popups for this site');\n }\n\n if (win.focus) win.focus();\n\n var eventMethod = window.addEventListener ? 'addEventListener' : 'attachEvent';\n var eventRemoveMethod = eventMethod == 'addEventListener' ? 'removeEventListener' : 'detachEvent';\n var messageEvent = eventMethod == 'addEventListener' ? 'message' : 'onmessage';\n\n var eventListener = function(e) {\n\n try {\n\n if (e.origin != options.origin) return;\n if (!e.data || !e.data[options.property]) return; // keep waiting\n\n win.close();\n window[eventRemoveMethod](messageEvent, eventListener);\n\n\n var loginOptions = this.parseLoginRedirect(e.data[options.property]);\n\n if (!loginOptions.code && !loginOptions.access_token) throw new Error('No authorization code or token');\n\n resolve(loginOptions);\n\n /* jshint -W002 */\n } catch (e) {\n reject(e);\n }\n\n }.bind(this);\n\n window[eventMethod](messageEvent, eventListener, false);\n\n }.bind(this));\n\n};\n\n/**\n * @return {Promise}\n */\nPlatform.prototype.loggedIn = function() {\n\n return this.ensureLoggedIn().then(function() {\n return true;\n }).catch(function() {\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 * @param {string} [options.accessTokenTtl]\n * @param {string} [options.refreshTokenTtl]\n * @param {string} [options.access_token]\n * @returns {Promise}\n */\nPlatform.prototype.login = function(options) {\n\n return (new this._externals.Promise(function(resolve) {\n\n options = options || {};\n\n this.emit(this.events.beforeLogin);\n\n var body = {};\n\n if (options.access_token) {\n\n //TODO Potentially make a request to /oauth/tokeninfo\n return resolve(options);\n\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 || this._redirectUri;\n //body.client_id = this.getCredentials().key; // not needed\n\n }\n\n if (options.endpointId) body.endpoint_id = options.endpointId;\n if (options.accessTokenTtl) body.access_token_ttl = options.accessTokenTtl;\n if (options.refreshTokenTtl) body.refresh_token_ttl = options.refreshTokenTtl;\n\n resolve(this._tokenRequest(Platform._tokenEndpoint, body));\n\n }.bind(this))).then(function(res) {\n\n var apiResponse = res.json ? res : null;\n var json = apiResponse && apiResponse.json() || res;\n\n this._auth.setData(json);\n\n this.emit(this.events.loginSuccess, apiResponse);\n\n return apiResponse;\n\n }.bind(this)).catch(function(e) {\n\n if (this._clearCacheOnRefreshError) {\n this._cache.clean();\n }\n\n this.emit(this.events.loginError, e);\n\n throw e;\n\n }.bind(this));\n\n};\n\n/**\n * @returns {Promise}\n * @private\n */\nPlatform.prototype._refresh = function() {\n\n return this.delay(this._refreshDelayMs).then(function() {\n\n this.emit(this.events.beforeRefresh);\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\n return this._tokenRequest(Platform._tokenEndpoint, {\n \"grant_type\": \"refresh_token\",\n \"refresh_token\": this._auth.refreshToken(),\n \"access_token_ttl\": this._auth.data().expires_in + 1,\n \"refresh_token_ttl\": this._auth.data().refresh_token_expires_in + 1\n });\n\n }.bind(this)).then(function(/** @type {ApiResponse} */ res) {\n\n var 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\n this.emit(this.events.refreshSuccess, res);\n\n return res;\n\n }.bind(this)).catch(function(e) {\n\n e = this._client.makeError(e);\n\n if (this._clearCacheOnRefreshError) {\n this._cache.clean();\n }\n\n this.emit(this.events.refreshError, e);\n\n throw e;\n\n }.bind(this));\n\n};\n\n/**\n * @returns {Promise}\n */\nPlatform.prototype.refresh = function() {\n\n if (!this._refreshPromise) {\n\n this._refreshPromise = this._refresh()\n .then(function(res) {\n this._refreshPromise = null;\n return res;\n }.bind(this))\n .catch(function(e) {\n this._refreshPromise = null;\n throw e;\n }.bind(this));\n\n }\n\n return this._refreshPromise;\n\n};\n\n/**\n * @returns {Promise}\n */\nPlatform.prototype.logout = function() {\n\n return (new this._externals.Promise(function(resolve) {\n\n this.emit(this.events.beforeLogout);\n\n if (!this._appSecret) {\n resolve(null);\n return;\n }\n\n resolve(this._tokenRequest(Platform._revokeEndpoint, {\n token: this._auth.accessToken()\n }));\n }.bind(this))).then(function(res) {\n\n this._cache.clean();\n\n this.emit(this.events.logoutSuccess, res);\n\n return res;\n\n }.bind(this)).catch(function(e) {\n\n this.emit(this.events.logoutError, e);\n\n throw e;\n\n }.bind(this));\n\n};\n\n/**\n * @param {Request} request\n * @param {object} [options]\n * @param {boolean} [options.skipAuthCheck]\n * @return {Promise}\n */\nPlatform.prototype.inflateRequest = function(request, options) {\n\n options = options || {};\n\n if (options.skipAuthCheck) return this._externals.Promise.resolve(request);\n\n return this.ensureLoggedIn().then(function() {\n\n request.headers.set('X-User-Agent', this._userAgent);\n request.headers.set('Client-Id', this._appKey);\n request.headers.set('Authorization', this._authHeader());\n //request.url = this.createUrl(request.url, {addServer: true}); //FIXME Spec prevents this...\n\n return request;\n\n }.bind(this));\n\n};\n\n/**\n * @param {Request} request\n * @param {object} [options]\n * @param {boolean} [options.skipAuthCheck]\n * @param {boolean|int} [options.handleRateLimit]\n * @param {boolean} [options.retry] Will be set by this method if SDK makes second request\n * @return {Promise}\n */\nPlatform.prototype.sendRequest = function(request, options) {\n\n return this.inflateRequest(request, options).then(function(request) {\n\n options = options || {};\n\n return this._client.sendRequest(request);\n\n }.bind(this)).catch(function(e) {\n\n // Guard is for errors that come from polling\n if (!e.apiResponse || !e.apiResponse.response() || options.retry) throw e;\n\n var response = e.apiResponse.response();\n var status = response.status;\n\n if ((status != ApiResponse._unauthorizedStatus) &&\n (status != ApiResponse._rateLimitStatus)) throw e;\n\n options.retry = true;\n\n var retryAfter = 0;\n\n if (status == ApiResponse._unauthorizedStatus) {\n this._auth.cancelAccessToken();\n }\n\n if (status == ApiResponse._rateLimitStatus) {\n\n var defaultRetryAfter = (!options.handleRateLimit || typeof options.handleRateLimit == 'boolean' ? 60 : options.handleRateLimit);\n\n // FIXME retry-after is custom header, by default, it can't be retrieved. Server should add header: 'Access-Control-Expose-Headers: retry-after'.\n retryAfter = parseFloat(response.headers.get('retry-after') || defaultRetryAfter) * 1000;\n\n e.retryAfter = retryAfter;\n\n this.emit(this.events.rateLimitError, e);\n\n if (!options.handleRateLimit) throw e;\n\n }\n\n return this.delay(retryAfter).then(function() {\n return this.sendRequest(this._client.createRequest(options), options);\n }.bind(this));\n\n }.bind(this));\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 * @param {boolean|int} [options.handleRateLimit]\n * @return {Promise}\n */\nPlatform.prototype.send = function(options) {\n\n options = options || {};\n\n //FIXME https://github.com/bitinn/node-fetch/issues/43\n options.url = this.createUrl(options.url, {addServer: true});\n\n return 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 * @param {boolean|int} [options.handleRateLimit]\n * @return {Promise}\n */\nPlatform.prototype.get = function(url, query, options) {\n return this.send(objectAssign({}, {method: 'GET', url: url, query: query}, 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 * @param {boolean|int} [options.handleRateLimit]\n * @return {Promise}\n */\nPlatform.prototype.post = function(url, body, query, options) {\n return this.send(objectAssign({}, {method: 'POST', url: url, query: query, body: body}, 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 * @param {boolean|int} [options.handleRateLimit]\n * @return {Promise}\n */\nPlatform.prototype.put = function(url, body, query, options) {\n return this.send(objectAssign({}, {method: 'PUT', url: url, query: query, body: body}, 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 * @param {boolean|int} [options.handleRateLimit]\n * @return {Promise}\n */\nPlatform.prototype['delete'] = function(url, query, options) {\n return this.send(objectAssign({}, {method: 'DELETE', url: url, query: query}, options));\n};\n\nPlatform.prototype.ensureLoggedIn = function() {\n if (this._isAccessTokenValid()) return this._externals.Promise.resolve();\n return this.refresh();\n};\n\n/**\n * @param path\n * @param body\n * @return {Promise.}\n * @private\n */\nPlatform.prototype._tokenRequest = function(path, body) {\n\n return this.send({\n url: path,\n skipAuthCheck: true,\n body: body,\n method: 'POST',\n headers: {\n 'Authorization': 'Basic ' + this._apiKey(),\n 'Content-Type': ApiResponse._urlencodedContentType\n }\n });\n\n};\n\n/**\n * @return {boolean}\n * @private\n */\nPlatform.prototype._isAccessTokenValid = function() {\n return this._auth.accessTokenValid();\n};\n\n/**\n * @return {string}\n * @private\n */\nPlatform.prototype._apiKey = function() {\n var apiKey = this._appKey + ':' + this._appSecret;\n return (typeof btoa == 'function') ? btoa(apiKey) : new Buffer(apiKey).toString('base64');\n};\n\n/**\n * @return {string}\n * @private\n */\nPlatform.prototype._authHeader = function() {\n var token = this._auth.accessToken();\n return this._auth.tokenType() + (token ? ' ' + token : '');\n};\n\nmodule.exports = Platform;\n\n\n/***/ },\n/* 16 */\n/***/ function(module, exports) {\n\n/**\n * @param {Cache} options.cache\n * @param {string} options.cacheId\n * @param {int} [options.refreshHandicapMs]\n * @constructor\n * @property {Cache} _cache\n * @property {int} _refreshHandicapMs\n * @property {string} _cacheId\n */\nfunction Auth(options) {\n\n /** @private */\n this._cache = options.cache;\n\n /** @private */\n this._cacheId = options.cacheId;\n\n /** @private */\n this._refreshHandicapMs = options.refreshHandicapMs || 60 * 1000; // 1 minute\n\n}\n\nAuth.prototype.accessToken = function() {\n return this.data().access_token;\n};\n\nAuth.prototype.refreshToken = function() {\n return this.data().refresh_token;\n};\n\nAuth.prototype.tokenType = function() {\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 */\nAuth.prototype.data = function() {\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 */\nAuth.prototype.setData = function(newData) {\n\n newData = newData || {};\n\n var data = this.data();\n\n Object.keys(newData).forEach(function(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 */\nAuth.prototype.accessTokenValid = function() {\n\n var authData = this.data();\n return (authData.expire_time - this._refreshHandicapMs > Date.now());\n\n};\n\n/**\n * Check if there is a valid (not expired) access token\n * @return {boolean}\n */\nAuth.prototype.refreshTokenValid = function() {\n\n return (this.data().refresh_token_expire_time > Date.now());\n\n};\n\n/**\n * @return {Auth}\n */\nAuth.prototype.cancelAccessToken = function() {\n\n return this.setData({\n access_token: '',\n expires_in: 0\n });\n\n};\n\nmodule.exports = Auth;\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/* 17 */\n/***/ function(module, exports, __webpack_require__) {\n\nvar version = (\"3.2.2\");\n\n// This will become false during the Webpack build, so no traces of package.json will be there\nif (false) {\n version = require('../../package.json').version;\n}\n\nmodule.exports = {\n version: version,\n authResponseProperty: 'RCAuthorizationResponse'\n};\n\n/***/ },\n/* 18 */\n/***/ function(module, exports, __webpack_require__) {\n\nvar EventEmitter = __webpack_require__(6).EventEmitter;\n\n// detect ISO 8601 format string with +00[:00] timezone notations\nvar ISO_REG_EXP = /(\\+[\\d]{2}):?([\\d]{2})?$/;\n\nfunction buildIEFriendlyString(match, $1, $2) {\n return $1 + ':' + ($2 || '00');\n}\n\n/**\n *\n * @param {string} time\n * @return {number}\n */\nfunction parseISOString(time) {\n time = time || 0;\n if (typeof time === 'string') {\n return Date.parse(time.replace(ISO_REG_EXP, buildIEFriendlyString));\n }\n return time;\n}\n\n/**\n * @param {Platform} options.platform\n * @param {Externals} options.externals\n * @param {int} [options.pollInterval]\n * @param {int} [options.renewHandicapMs]\n * @property {Externals} _externals\n * @property {Platform} _platform\n * @property {int} _pollInterval\n * @property {int} _renewHandicapMs\n * @property {PubNub} _pubnub\n * @property {string} _pubnubLastChannel\n * @property {int} _timeout\n * @property {ISubscription} _subscription\n * @constructor\n */\nfunction Subscription(options) {\n\n EventEmitter.call(this);\n\n options = options || {};\n\n this.events = {\n notification: 'notification',\n removeSuccess: 'removeSuccess',\n removeError: 'removeError',\n renewSuccess: 'renewSuccess',\n renewError: 'renewError',\n subscribeSuccess: 'subscribeSuccess',\n subscribeError: 'subscribeError',\n automaticRenewSuccess: 'automaticRenewSuccess',\n automaticRenewError: 'automaticRenewError',\n status: 'status'\n };\n\n /** @private */\n this._externals = options.externals;\n\n /** @private */\n this._platform = options.platform;\n\n /** @private */\n this._pollInterval = options.pollInterval || 10 * 1000;\n\n /** @private */\n this._renewHandicapMs = options.renewHandicapMs || 2 * 60 * 1000;\n\n /** @private */\n this._pubnub = null;\n\n /** @private */\n this._pubnubLastChannel = null;\n\n /** @private */\n this._pubnubLastSubscribeKey = null;\n\n /** @private */\n this._timeout = null;\n\n /** @private */\n this._subscription = null;\n\n}\n\nSubscription.prototype = Object.create(EventEmitter.prototype);\n\nSubscription.prototype.subscribed = function() {\n\n var subscription = this.subscription();\n\n return !!(subscription.id &&\n subscription.deliveryMode &&\n subscription.deliveryMode.subscriberKey &&\n subscription.deliveryMode.address);\n\n};\n\n/**\n * @return {boolean}\n */\nSubscription.prototype.alive = function() {\n return this.subscribed() && Date.now() < this.expirationTime();\n};\n\n/**\n * @return {boolean}\n */\nSubscription.prototype.expired = function() {\n if (!this.subscribed()) return true;\n return !this.subscribed() || Date.now() > parseISOString(this.subscription().expirationTime);\n};\n\n/**\n * @return {number}\n */\nSubscription.prototype.expirationTime = function() {\n return parseISOString(this.subscription().expirationTime) - this._renewHandicapMs;\n};\n\n/**\n * @param {ISubscription} subscription\n * @return {Subscription}\n */\nSubscription.prototype.setSubscription = function(subscription) {\n\n subscription = subscription || {};\n\n this._clearTimeout();\n this._setSubscription(subscription);\n this._subscribeAtPubnub();\n this._setTimeout();\n\n return this;\n\n};\n\n/**\n * @return {ISubscription}\n */\nSubscription.prototype.subscription = function() {\n return this._subscription || {};\n};\n\n/**\n * Creates or updates subscription if there is an active one\n * @returns {Promise}\n */\nSubscription.prototype.register = function() {\n\n if (this.alive()) {\n return this.renew();\n } else {\n return this.subscribe();\n }\n\n};\n\n/**\n * @return {string[]}\n */\nSubscription.prototype.eventFilters = function() {\n return this.subscription().eventFilters || [];\n};\n\n/**\n * @param {string[]} events\n * @return {Subscription}\n */\nSubscription.prototype.addEventFilters = function(events) {\n this.setEventFilters(this.eventFilters().concat(events));\n return this;\n};\n\n/**\n * @param {string[]} events\n * @return {Subscription}\n */\nSubscription.prototype.setEventFilters = function(events) {\n var subscription = this.subscription();\n subscription.eventFilters = events;\n this._setSubscription(subscription);\n return this;\n};\n\n/**\n * @returns {Promise}\n */\nSubscription.prototype.subscribe = function() {\n\n return (new this._externals.Promise(function(resolve) {\n\n this._clearTimeout();\n\n if (!this.eventFilters().length) throw new Error('Events are undefined');\n\n resolve(this._platform.post('/subscription', {\n eventFilters: this._getFullEventFilters(),\n deliveryMode: {\n transportType: 'PubNub'\n }\n }));\n\n }.bind(this))).then(function(response) {\n\n var json = response.json();\n\n this.setSubscription(json)\n .emit(this.events.subscribeSuccess, response);\n\n return response;\n\n }.bind(this)).catch(function(e) {\n\n e = this._platform.client().makeError(e);\n // `reset` will remove pubnub instance.\n // so if network is broken for a long time, pubnub will be removed. And client can not receive notification anymore.\n this.reset()\n .emit(this.events.subscribeError, e);\n\n throw e;\n\n }.bind(this));\n\n};\n\n/**\n * @returns {Promise}\n */\nSubscription.prototype.renew = function() {\n\n return (new this._externals.Promise(function(resolve) {\n\n this._clearTimeout();\n\n if (!this.subscribed()) throw new Error('No subscription');\n\n if (!this.eventFilters().length) throw new Error('Events are undefined');\n\n resolve(this._platform.put('/subscription/' + this.subscription().id, {\n eventFilters: this._getFullEventFilters()\n }));\n\n }.bind(this))).then(function(response) {\n\n var json = response.json();\n\n this.setSubscription(json)\n .emit(this.events.renewSuccess, response);\n\n return response;\n\n }.bind(this)).catch(function(e) {\n\n e = this._platform.client().makeError(e);\n // `reset` will remove pubnub instance.\n // so if network is broken for a long time, pubnub will be removed. And client can not receive notification anymore.\n this.reset()\n .emit(this.events.renewError, e);\n\n throw e;\n\n }.bind(this));\n\n};\n\n/**\n * @returns {Promise}\n */\nSubscription.prototype.remove = function() {\n\n return (new this._externals.Promise(function(resolve) {\n\n if (!this.subscribed()) throw new Error('No subscription');\n\n resolve(this._platform.delete('/subscription/' + this.subscription().id));\n\n }.bind(this))).then(function(response) {\n\n this.reset()\n .emit(this.events.removeSuccess, response);\n\n return response;\n\n }.bind(this)).catch(function(e) {\n\n e = this._platform.client().makeError(e);\n\n this.emit(this.events.removeError, e);\n\n throw e;\n\n }.bind(this));\n\n};\n\n/**\n * @returns {Promise}\n */\nSubscription.prototype.resubscribe = function() {\n var filters = this.eventFilters();\n return this.reset().setEventFilters(filters).subscribe();\n};\n\n/**\n * Remove subscription and disconnect from PubNub\n * This method resets subscription at client side but backend is not notified\n * @return {Subscription}\n */\nSubscription.prototype.reset = function() {\n this._clearTimeout();\n this._unsubscribeAtPubnub();\n this._setSubscription(null);\n return this;\n};\n\n/**\n * @param subscription\n * @private\n */\nSubscription.prototype._setSubscription = function(subscription) {\n this._subscription = subscription;\n};\n\n/**\n * @return {string[]}\n * @private\n */\nSubscription.prototype._getFullEventFilters = function() {\n\n return this.eventFilters().map(function(event) {\n return this._platform.createUrl(event);\n }.bind(this));\n\n};\n\n/**\n * @return {Subscription}\n * @private\n */\nSubscription.prototype._setTimeout = function() {\n\n this._clearTimeout();\n\n if (!this.alive()) throw new Error('Subscription is not alive');\n\n this._timeout = setInterval(function() {\n\n if (this.alive()) {\n return;\n }\n\n this._clearTimeout();\n\n (new this._externals.Promise(function(resolve) {\n\n if (this.expired()) {\n resolve(this.subscribe());\n } else {\n resolve(this.renew());\n }\n\n }.bind(this))).then(function(res) {\n\n this.emit(this.events.automaticRenewSuccess, res);\n\n }.bind(this)).catch(function(e) {\n\n this.emit(this.events.automaticRenewError, e);\n\n }.bind(this));\n\n }.bind(this), this._pollInterval);\n\n return this;\n\n};\n\n/**\n * @return {Subscription}\n * @private\n */\nSubscription.prototype._clearTimeout = function() {\n clearInterval(this._timeout);\n return this;\n};\n\nSubscription.prototype._decrypt = function(message) {\n\n if (!this.subscribed()) throw new Error('No subscription');\n\n if (this.subscription().deliveryMode.encryptionKey) {\n\n message = this._pubnub.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/**\n * @param message\n * @return {Subscription}\n * @private\n */\nSubscription.prototype._notify = function(message) {\n this.emit(this.events.notification, this._decrypt(message));\n return this;\n};\n\n/**\n * @return {Subscription}\n * @private\n */\nSubscription.prototype._subscribeAtPubnub = function() {\n\n if (!this.alive()) throw new Error('Subscription is not alive');\n\n var deliveryMode = this.subscription().deliveryMode;\n\n if (this._pubnub) {\n\n if (this._pubnubLastChannel === deliveryMode.address) {\n\n // Nothing to update, keep listening to same channel\n return this;\n\n } else if (this._pubnubLastSubscribeKey && this._pubnubLastSubscribeKey !== deliveryMode.subscriberKey) {\n\n // Subscribe key changed, need to reset everything\n this._unsubscribeAtPubnub();\n\n } else if (this._pubnubLastChannel) {\n\n // Need to subscribe to new channel\n this._pubnub.unsubscribeAll();\n\n }\n\n }\n\n if (!this._pubnub) {\n\n this._pubnubLastSubscribeKey = deliveryMode.subscriberKey;\n\n var PubNub = this._externals.PubNub;\n\n this._pubnub = new PubNub({\n ssl: true,\n restore: true,\n subscribeKey: deliveryMode.subscriberKey,\n origin: 'ringcentral.pubnubapi.com',\n keepAlive: true\n });\n\n this._pubnub.addListener({\n status: function(statusEvent) {\n this.emit(this.events.status, statusEvent);\n }.bind(this),\n message: function(m) {\n this._notify(m.message); // all other props are ignored\n }.bind(this)\n });\n\n }\n\n this._pubnubLastChannel = deliveryMode.address;\n this._pubnub.subscribe({channels: [deliveryMode.address]});\n\n return this;\n\n};\n\n/**\n * @return {Subscription}\n * @private\n */\nSubscription.prototype._unsubscribeAtPubnub = function() {\n\n if (!this.subscribed() || !this._pubnub) return this;\n\n this._pubnub.removeAllListeners();\n this._pubnub.destroy(); // this will unsubscribe from all\n\n this._pubnubLastSubscribeKey = null;\n this._pubnubLastChannel = null;\n this._pubnub = null;\n\n return this;\n\n};\n\nmodule.exports = Subscription;\n\n/**\n * The complete Triforce, or one or more components of the Triforce.\n * @typedef {Object} ISubscription\n * @property {string} [id]\n * @property {string} [uri]\n * @property {string[]} [eventFilters]\n * @property {string} [expirationTime] Format: 2014-03-12T19:54:35.613+0000\n * @property {int} [expiresIn]\n * @property {string} [deliveryMode.transportType]\n * @property {boolean} [deliveryMode.encryption]\n * @property {string} [deliveryMode.address]\n * @property {string} [deliveryMode.subscriberKey]\n * @property {string} [deliveryMode.encryptionKey]\n * @property {string} [deliveryMode.secretKey]\n * @property {string} [creationTime]\n * @property {string} [status] Active\n */\n\n/***/ },\n/* 19 */\n/***/ function(module, exports, __webpack_require__) {\n\nvar Subscription = __webpack_require__(18);\n\n/**\n * @param {Platform} options.platform\n * @param {Externals} options.externals\n * @param {Cache} options.cache\n * @param {string} options.cacheKey\n * @param {int} [options.pollInterval]\n * @param {int} [options.renewHandicapMs]\n * @return {CachedSubscription}\n * @constructor\n * @property {Cache} _cache\n * @extends Subscription\n */\nfunction CachedSubscription(options) {\n\n options = options || {};\n\n if (!options.cacheKey) throw new Error('Cached Subscription requires cacheKey parameter to be defined');\n\n /** @private */\n this._cacheKey = options.cacheKey;\n\n Subscription.call(this, options);\n\n /** @private */\n this._cache = options.cache;\n\n // This is not used in this class\n this._subscription = undefined;\n\n}\n\nCachedSubscription.prototype = Object.create(Subscription.prototype);\n\nCachedSubscription.prototype.subscription = function() {\n return this._cache.getItem(this._cacheKey) || {};\n};\n\nCachedSubscription.prototype._setSubscription = function(subscription) {\n return this._cache.setItem(this._cacheKey, subscription);\n};\n\n/**\n * This function checks whether there are any pre-defined eventFilters in cache and if not -- uses provided as defaults\n * @param {string[]} events\n * @return {CachedSubscription}\n */\nCachedSubscription.prototype.restore = function(events) {\n\n if (!this.eventFilters().length) {\n this.setEventFilters(events);\n }\n\n return this;\n\n};\n\nmodule.exports = CachedSubscription;\n\n/***/ }\n/******/ ])\n});\n;\n\n\n// WEBPACK FOOTER //\n// ringcentral.min.js"," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\texports: {},\n \t\t\tid: moduleId,\n \t\t\tloaded: false\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.loaded = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"/build/\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(0);\n\n\n\n// WEBPACK FOOTER //\n// webpack/bootstrap 9170c9929c7a92918002","/**\n * @namespace RingCentral\n */\nvar objectAssign = require('object-assign');\nvar Cache = require(\"./core/Cache\");\nvar Client = require(\"./http/Client\");\nvar Externals = require(\"./core/Externals\");\nvar Platform = require(\"./platform/Platform\");\nvar Subscription = require(\"./subscription/Subscription\");\nvar CachedSubscription = require(\"./subscription/CachedSubscription\");\nvar Constants = require(\"./core/Constants\");\n\n/**\n * @constructor\n * @param {string} options.server\n * @param {string} options.appSecret\n * @param {string} options.appKey\n * @param {string} [options.cachePrefix]\n * @param {string} [options.appName]\n * @param {string} [options.appVersion]\n * @param {string} [options.redirectUri]\n * @param {PubNub} [options.PubNub]\n * @param {function(new:Promise)} [options.Promise]\n * @param {Storage} [options.localStorage]\n * @param {fetch} [options.fetch]\n * @param {function(new:Request)} [options.Request]\n * @param {function(new:Response)} [options.Response]\n * @param {function(new:Headers)} [options.Headers]\n * @param {int} [options.refreshDelayMs]\n * @param {int} [options.refreshHandicapMs]\n * @param {boolean} [options.clearCacheOnRefreshError]\n * @property {Externals} _externals\n * @property {Cache} _cache\n * @property {Client} _client\n * @property {Platform} _platform\n */\nfunction SDK(options) {\n\n /** @private */\n this._externals = new Externals(options);\n\n /** @private */\n this._cache = new Cache({\n externals: this._externals,\n prefix: options.cachePrefix\n });\n\n /** @private */\n this._client = new Client(this._externals);\n\n /** @private */\n this._platform = new Platform(objectAssign({}, options, {\n externals: this._externals,\n client: this._client,\n cache: this._cache\n }));\n\n}\n\nSDK.version = Constants.version;\n\nSDK.server = {\n sandbox: 'https://platform.devtest.ringcentral.com',\n production: 'https://platform.ringcentral.com'\n};\n\n/**\n * @return {Platform}\n */\nSDK.prototype.platform = function() {\n return this._platform;\n};\n\n/**\n * @return {Cache}\n */\nSDK.prototype.cache = function() {\n return this._cache;\n};\n\n/**\n * @param {int} [options.pollInterval]\n * @param {int} [options.renewHandicapMs]\n * @return {Subscription}\n */\nSDK.prototype.createSubscription = function(options) {\n return new Subscription(objectAssign({}, options, {\n externals: this._externals,\n platform: this._platform\n }));\n};\n\n/**\n * @param {string} options.cacheKey\n * @param {int} [options.pollInterval]\n * @param {int} [options.renewHandicapMs]\n * @return {CachedSubscription}\n */\nSDK.prototype.createCachedSubscription = function(options) {\n\n if (typeof arguments[0] === 'string') {\n options = {cacheKey: arguments[0].toString()};\n } else {\n options = options || {};\n }\n\n return new CachedSubscription(objectAssign({}, options, {\n externals: this._externals,\n platform: this._platform,\n cache: this._cache\n }));\n\n};\n\nSDK.handleLoginRedirect = function(origin, win) {\n\n win = win || window;\n\n var response = win.location.hash ? win.location.hash : win.location.search;\n var msg = {};\n msg[Constants.authResponseProperty] = response;\n win.opener.postMessage(msg, origin || win.location.origin);\n\n};\n\nmodule.exports = SDK;\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/SDK.js\n// module id = 0\n// module chunks = 0 1","/*\nobject-assign\n(c) Sindre Sorhus\n@license MIT\n*/\n\n'use strict';\n/* eslint-disable no-unused-vars */\nvar getOwnPropertySymbols = Object.getOwnPropertySymbols;\nvar hasOwnProperty = Object.prototype.hasOwnProperty;\nvar propIsEnumerable = Object.prototype.propertyIsEnumerable;\n\nfunction toObject(val) {\n\tif (val === null || val === undefined) {\n\t\tthrow new TypeError('Object.assign cannot be called with null or undefined');\n\t}\n\n\treturn Object(val);\n}\n\nfunction shouldUseNative() {\n\ttry {\n\t\tif (!Object.assign) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Detect buggy property enumeration order in older V8 versions.\n\n\t\t// https://bugs.chromium.org/p/v8/issues/detail?id=4118\n\t\tvar test1 = new String('abc'); // eslint-disable-line no-new-wrappers\n\t\ttest1[5] = 'de';\n\t\tif (Object.getOwnPropertyNames(test1)[0] === '5') {\n\t\t\treturn false;\n\t\t}\n\n\t\t// https://bugs.chromium.org/p/v8/issues/detail?id=3056\n\t\tvar test2 = {};\n\t\tfor (var i = 0; i < 10; i++) {\n\t\t\ttest2['_' + String.fromCharCode(i)] = i;\n\t\t}\n\t\tvar order2 = Object.getOwnPropertyNames(test2).map(function (n) {\n\t\t\treturn test2[n];\n\t\t});\n\t\tif (order2.join('') !== '0123456789') {\n\t\t\treturn false;\n\t\t}\n\n\t\t// https://bugs.chromium.org/p/v8/issues/detail?id=3056\n\t\tvar test3 = {};\n\t\t'abcdefghijklmnopqrst'.split('').forEach(function (letter) {\n\t\t\ttest3[letter] = letter;\n\t\t});\n\t\tif (Object.keys(Object.assign({}, test3)).join('') !==\n\t\t\t\t'abcdefghijklmnopqrst') {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn true;\n\t} catch (err) {\n\t\t// We don't expect any of the above to throw, but better to be safe.\n\t\treturn false;\n\t}\n}\n\nmodule.exports = shouldUseNative() ? Object.assign : function (target, source) {\n\tvar from;\n\tvar to = toObject(target);\n\tvar symbols;\n\n\tfor (var s = 1; s < arguments.length; s++) {\n\t\tfrom = Object(arguments[s]);\n\n\t\tfor (var key in from) {\n\t\t\tif (hasOwnProperty.call(from, key)) {\n\t\t\t\tto[key] = from[key];\n\t\t\t}\n\t\t}\n\n\t\tif (getOwnPropertySymbols) {\n\t\t\tsymbols = getOwnPropertySymbols(from);\n\t\t\tfor (var i = 0; i < symbols.length; i++) {\n\t\t\t\tif (propIsEnumerable.call(from, symbols[i])) {\n\t\t\t\t\tto[symbols[i]] = from[symbols[i]];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn to;\n};\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./~/object-assign/index.js\n// module id = 1\n// module chunks = 0 1","/**\n * @param {Externals} options.externals\n * @param {string} [options.prefix]\n * @property {Externals} _externals\n */\nfunction Cache(options) {\n\n /** @private */\n this._prefix = options.prefix || Cache.defaultPrefix;\n\n /** @private */\n this._externals = options.externals;\n\n}\n\nCache.defaultPrefix = 'rc-';\n\nCache.prototype.setItem = function(key, data) {\n this._externals.localStorage[this._prefixKey(key)] = JSON.stringify(data);\n return this;\n};\n\nCache.prototype.removeItem = function(key) {\n delete this._externals.localStorage[this._prefixKey(key)];\n return this;\n};\n\nCache.prototype.getItem = function(key) {\n var item = this._externals.localStorage[this._prefixKey(key)];\n if (!item) return null;\n return JSON.parse(item);\n};\n\nCache.prototype.clean = function() {\n\n for (var key in this._externals.localStorage) {\n\n /* istanbul ignore next */\n if (!this._externals.localStorage.hasOwnProperty(key)) continue;\n\n if (key.indexOf(this._prefix) === 0) {\n delete this._externals.localStorage[key];\n }\n\n }\n\n return this;\n\n};\n\nCache.prototype._prefixKey = function(key) {\n return this._prefix + key;\n};\n\nmodule.exports = Cache;\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/core/Cache.js\n// module id = 2\n// module chunks = 0 1","var isPlainObject = require(\"is-plain-object\");\nvar EventEmitter = require(\"events\").EventEmitter;\nvar ApiResponse = require(\"./ApiResponse\");\nvar qs = require(\"querystring\");\n\nfunction 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 * @param {Externals} externals\n * @property {Externals} _externals\n */\nfunction Client(externals) {\n\n EventEmitter.call(this);\n\n /** @private */\n this._externals = externals;\n\n this.events = {\n beforeRequest: 'beforeRequest',\n requestSuccess: 'requestSuccess',\n requestError: 'requestError'\n };\n\n}\n\nClient._allowedMethods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS', 'HEAD'];\n\nClient.prototype = Object.create(EventEmitter.prototype);\n\n/**\n * @param {Request} request\n * @return {Promise}\n */\nClient.prototype.sendRequest = function(request) {\n\n var apiResponse = new ApiResponse({\n externals: this._externals,\n request: request\n });\n\n return (new this._externals.Promise(function(resolve) {\n\n //TODO Stop request if listeners return false\n this.emit(this.events.beforeRequest, apiResponse);\n\n resolve(this._loadResponse(request));\n\n }.bind(this))).then(function(response) {\n\n return apiResponse.receiveResponse(response);\n\n }).then(function() {\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 }.bind(this)).catch(function(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 }.bind(this));\n\n};\n\n/**\n * @param {Request} request\n * @return {Promise}\n * @private\n */\nClient.prototype._loadResponse = function(request) {\n return this._externals.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 */\nClient.prototype.makeError = function(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 * @param {object} [init.credentials]\n * @param {object} [init.mode]\n * @return {Request}\n */\nClient.prototype.createRequest = function(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 init.method = init.method.toUpperCase();\n if (init.method && Client._allowedMethods.indexOf(init.method) < 0) {\n throw new Error('Method has wrong value: ' + init.method);\n }\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 ? '&' : '?') + qs.stringify(init.query);\n }\n\n if (!(findHeaderName('Accept', init.headers))) {\n init.headers.Accept = ApiResponse._jsonContentType;\n }\n\n // Serialize body\n if (isPlainObject(init.body) || !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 if ((init.method === 'GET' || init.method === 'HEAD') && !!init.body) {\n // oddly setting body to null still result in TypeError in phantomjs\n init.body = undefined;\n } else {\n init.body = JSON.stringify(init.body);\n }\n\n } else if (contentType.indexOf(ApiResponse._urlencodedContentType) > -1) {\n init.body = qs.stringify(init.body);\n }\n\n }\n\n // Create a request with encoded body\n var req = new this._externals.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 * @typedef {object} IApiError\n * @property {string} stack\n * @property {string} originalMessage\n * @property {ApiResponse} apiResponse\n */\n\nmodule.exports = Client;\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/http/Client.js\n// module id = 3\n// module chunks = 0 1","/*!\n * is-plain-object \n *\n * Copyright (c) 2014-2017, Jon Schlinkert.\n * Released under the MIT License.\n */\n\n'use strict';\n\nvar isObject = require('isobject');\n\nfunction isObjectObject(o) {\n return isObject(o) === true\n && Object.prototype.toString.call(o) === '[object Object]';\n}\n\nmodule.exports = function isPlainObject(o) {\n var ctor,prot;\n\n if (isObjectObject(o) === false) return false;\n\n // If has modified constructor\n ctor = o.constructor;\n if (typeof ctor !== 'function') return false;\n\n // If has modified prototype\n prot = ctor.prototype;\n if (isObjectObject(prot) === false) return false;\n\n // If constructor does not have an Object-specific method\n if (prot.hasOwnProperty('isPrototypeOf') === false) {\n return false;\n }\n\n // Most likely a plain Object\n return true;\n};\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./~/is-plain-object/index.js\n// module id = 4\n// module chunks = 0 1","/*!\n * isobject \n *\n * Copyright (c) 2014-2017, Jon Schlinkert.\n * Released under the MIT License.\n */\n\n'use strict';\n\nmodule.exports = function isObject(val) {\n return val != null && typeof val === 'object' && Array.isArray(val) === false;\n};\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./~/isobject/index.js\n// module id = 5\n// module chunks = 0 1","// Copyright Joyent, Inc. and other Node contributors.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a\n// copy of this software and associated documentation files (the\n// \"Software\"), to deal in the Software without restriction, including\n// without limitation the rights to use, copy, modify, merge, publish,\n// distribute, sublicense, and/or sell copies of the Software, and to permit\n// persons to whom the Software is furnished to do so, subject to the\n// following conditions:\n//\n// The above copyright notice and this permission notice shall be included\n// in all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\n// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN\n// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,\n// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE\n// USE OR OTHER DEALINGS IN THE SOFTWARE.\n\nfunction EventEmitter() {\n this._events = this._events || {};\n this._maxListeners = this._maxListeners || undefined;\n}\nmodule.exports = EventEmitter;\n\n// Backwards-compat with node 0.10.x\nEventEmitter.EventEmitter = EventEmitter;\n\nEventEmitter.prototype._events = undefined;\nEventEmitter.prototype._maxListeners = undefined;\n\n// By default EventEmitters will print a warning if more than 10 listeners are\n// added to it. This is a useful default which helps finding memory leaks.\nEventEmitter.defaultMaxListeners = 10;\n\n// Obviously not all Emitters should be limited to 10. This function allows\n// that to be increased. Set to zero for unlimited.\nEventEmitter.prototype.setMaxListeners = function(n) {\n if (!isNumber(n) || n < 0 || isNaN(n))\n throw TypeError('n must be a positive number');\n this._maxListeners = n;\n return this;\n};\n\nEventEmitter.prototype.emit = function(type) {\n var er, handler, len, args, i, listeners;\n\n if (!this._events)\n this._events = {};\n\n // If there is no 'error' event listener then throw.\n if (type === 'error') {\n if (!this._events.error ||\n (isObject(this._events.error) && !this._events.error.length)) {\n er = arguments[1];\n if (er instanceof Error) {\n throw er; // Unhandled 'error' event\n } else {\n // At least give some kind of context to the user\n var err = new Error('Uncaught, unspecified \"error\" event. (' + er + ')');\n err.context = er;\n throw err;\n }\n }\n }\n\n handler = this._events[type];\n\n if (isUndefined(handler))\n return false;\n\n if (isFunction(handler)) {\n switch (arguments.length) {\n // fast cases\n case 1:\n handler.call(this);\n break;\n case 2:\n handler.call(this, arguments[1]);\n break;\n case 3:\n handler.call(this, arguments[1], arguments[2]);\n break;\n // slower\n default:\n args = Array.prototype.slice.call(arguments, 1);\n handler.apply(this, args);\n }\n } else if (isObject(handler)) {\n args = Array.prototype.slice.call(arguments, 1);\n listeners = handler.slice();\n len = listeners.length;\n for (i = 0; i < len; i++)\n listeners[i].apply(this, args);\n }\n\n return true;\n};\n\nEventEmitter.prototype.addListener = function(type, listener) {\n var m;\n\n if (!isFunction(listener))\n throw TypeError('listener must be a function');\n\n if (!this._events)\n this._events = {};\n\n // To avoid recursion in the case that type === \"newListener\"! Before\n // adding it to the listeners, first emit \"newListener\".\n if (this._events.newListener)\n this.emit('newListener', type,\n isFunction(listener.listener) ?\n listener.listener : listener);\n\n if (!this._events[type])\n // Optimize the case of one listener. Don't need the extra array object.\n this._events[type] = listener;\n else if (isObject(this._events[type]))\n // If we've already got an array, just append.\n this._events[type].push(listener);\n else\n // Adding the second element, need to change to array.\n this._events[type] = [this._events[type], listener];\n\n // Check for listener leak\n if (isObject(this._events[type]) && !this._events[type].warned) {\n if (!isUndefined(this._maxListeners)) {\n m = this._maxListeners;\n } else {\n m = EventEmitter.defaultMaxListeners;\n }\n\n if (m && m > 0 && this._events[type].length > m) {\n this._events[type].warned = true;\n console.error('(node) warning: possible EventEmitter memory ' +\n 'leak detected. %d listeners added. ' +\n 'Use emitter.setMaxListeners() to increase limit.',\n this._events[type].length);\n if (typeof console.trace === 'function') {\n // not supported in IE 10\n console.trace();\n }\n }\n }\n\n return this;\n};\n\nEventEmitter.prototype.on = EventEmitter.prototype.addListener;\n\nEventEmitter.prototype.once = function(type, listener) {\n if (!isFunction(listener))\n throw TypeError('listener must be a function');\n\n var fired = false;\n\n function g() {\n this.removeListener(type, g);\n\n if (!fired) {\n fired = true;\n listener.apply(this, arguments);\n }\n }\n\n g.listener = listener;\n this.on(type, g);\n\n return this;\n};\n\n// emits a 'removeListener' event iff the listener was removed\nEventEmitter.prototype.removeListener = function(type, listener) {\n var list, position, length, i;\n\n if (!isFunction(listener))\n throw TypeError('listener must be a function');\n\n if (!this._events || !this._events[type])\n return this;\n\n list = this._events[type];\n length = list.length;\n position = -1;\n\n if (list === listener ||\n (isFunction(list.listener) && list.listener === listener)) {\n delete this._events[type];\n if (this._events.removeListener)\n this.emit('removeListener', type, listener);\n\n } else if (isObject(list)) {\n for (i = length; i-- > 0;) {\n if (list[i] === listener ||\n (list[i].listener && list[i].listener === listener)) {\n position = i;\n break;\n }\n }\n\n if (position < 0)\n return this;\n\n if (list.length === 1) {\n list.length = 0;\n delete this._events[type];\n } else {\n list.splice(position, 1);\n }\n\n if (this._events.removeListener)\n this.emit('removeListener', type, listener);\n }\n\n return this;\n};\n\nEventEmitter.prototype.removeAllListeners = function(type) {\n var key, listeners;\n\n if (!this._events)\n return this;\n\n // not listening for removeListener, no need to emit\n if (!this._events.removeListener) {\n if (arguments.length === 0)\n this._events = {};\n else if (this._events[type])\n delete this._events[type];\n return this;\n }\n\n // emit removeListener for all listeners on all events\n if (arguments.length === 0) {\n for (key in this._events) {\n if (key === 'removeListener') continue;\n this.removeAllListeners(key);\n }\n this.removeAllListeners('removeListener');\n this._events = {};\n return this;\n }\n\n listeners = this._events[type];\n\n if (isFunction(listeners)) {\n this.removeListener(type, listeners);\n } else if (listeners) {\n // LIFO order\n while (listeners.length)\n this.removeListener(type, listeners[listeners.length - 1]);\n }\n delete this._events[type];\n\n return this;\n};\n\nEventEmitter.prototype.listeners = function(type) {\n var ret;\n if (!this._events || !this._events[type])\n ret = [];\n else if (isFunction(this._events[type]))\n ret = [this._events[type]];\n else\n ret = this._events[type].slice();\n return ret;\n};\n\nEventEmitter.prototype.listenerCount = function(type) {\n if (this._events) {\n var evlistener = this._events[type];\n\n if (isFunction(evlistener))\n return 1;\n else if (evlistener)\n return evlistener.length;\n }\n return 0;\n};\n\nEventEmitter.listenerCount = function(emitter, type) {\n return emitter.listenerCount(type);\n};\n\nfunction isFunction(arg) {\n return typeof arg === 'function';\n}\n\nfunction isNumber(arg) {\n return typeof arg === 'number';\n}\n\nfunction isObject(arg) {\n return typeof arg === 'object' && arg !== null;\n}\n\nfunction isUndefined(arg) {\n return arg === void 0;\n}\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./~/events/events.js\n// module id = 6\n// module chunks = 0 1","/**\n * @param {Externals} options.externals\n * @param {Request} [options.request]\n * @param {Response} [options.response]\n * @param {string} [options.responseText]\n * @property {Externals} _externals\n * @property {Request} _request\n * @property {Response} _response\n * @property {string} _text\n * @property {object} _json\n * @property {ApiResponse[]} _multipart\n */\nfunction ApiResponse(options) {\n\n /** @private */\n this._externals = options.externals;\n\n /** @private */\n this._request = options.request;\n\n /** @private */\n this._response = options.response;\n\n /** @private */\n this._text = options.responseText || '';\n\n /** @private */\n this._json = null;\n\n /** @private */\n this._multipart = [];\n\n}\n\nApiResponse._contentType = 'Content-Type';\nApiResponse._jsonContentType = 'application/json';\nApiResponse._multipartContentType = 'multipart/mixed';\nApiResponse._urlencodedContentType = 'application/x-www-form-urlencoded';\nApiResponse._headerSeparator = ':';\nApiResponse._bodySeparator = '\\n\\n';\nApiResponse._boundarySeparator = '--';\nApiResponse._unauthorizedStatus = 401;\nApiResponse._rateLimitStatus = 429;\n\n/**\n * @param {Response} response\n * @return {Promise}\n */\nApiResponse.prototype.receiveResponse = function(response) {\n\n this._response = response;\n\n return (new this._externals.Promise(function(resolve) {\n\n // Ignore if not textual type\n if (!this._isMultipart() && !this._isJson()) return resolve('');\n\n return resolve(this.response().text());\n\n }.bind(this))).then(function(text) {\n\n this._text = text;\n return text;\n\n }.bind(this));\n\n};\n\n/**\n * @return {Response}\n */\nApiResponse.prototype.response = function() {\n return this._response;\n};\n\n/**\n * @return {Request}\n */\nApiResponse.prototype.request = function() {\n return this._request;\n};\n\n/**\n * @return {boolean}\n */\nApiResponse.prototype.ok = function() {\n return this._response && this._response.ok;\n};\n\n/**\n * @return {string}\n */\nApiResponse.prototype.text = function() {\n // Since we read text only in case JSON or Multipart\n if (!this._isJson() && !this._isMultipart()) throw new Error('Response is not text');\n return this._text;\n};\n\n/**\n * @return {object}\n */\nApiResponse.prototype.json = function() {\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 */\nApiResponse.prototype.error = function(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 * If it is not known upfront what would be the response, client code can treat any response as multipart\n * @return {ApiResponse[]}\n */\nApiResponse.prototype.toMultipart = function() {\n if (!this._isMultipart()) return [this];\n return this.multipart();\n};\n\n/**\n * @return {ApiResponse[]}\n */\nApiResponse.prototype.multipart = function() {\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;\n\n try {\n boundary = this._getContentType().match(/boundary=([^;]+)/i)[1];\n } catch (e) {\n throw new Error('Cannot find boundary');\n }\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 = this._create(parts.shift(), this._response.status, this._response.statusText).json();\n\n // Step 3. Parse all other parts\n\n this._multipart = parts.map(function(part, i) {\n\n var status = statusInfo.response[i].status;\n\n return this._create(part, status);\n\n }.bind(this));\n\n }\n\n return this._multipart;\n\n};\n\n/**\n * @private\n */\nApiResponse.prototype._isContentType = function(contentType) {\n return this._getContentType().indexOf(contentType) > -1;\n};\n\n/**\n * @private\n */\nApiResponse.prototype._getContentType = function() {\n return this._response.headers.get(ApiResponse._contentType) || '';\n};\n\n/**\n * @private\n */\nApiResponse.prototype._isMultipart = function() {\n return this._isContentType(ApiResponse._multipartContentType);\n};\n\n/**\n * @private\n */\nApiResponse.prototype._isJson = function() {\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 * @private\n * @return {ApiResponse}\n */\nApiResponse.prototype._create = function(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 this._externals.Headers(),\n headersAndBody = text.split(ApiResponse._bodySeparator),\n headersText = (headersAndBody.length > 1) ? headersAndBody.shift() : '';\n\n text = headersAndBody.length > 0 ? headersAndBody.join(ApiResponse._bodySeparator) : null;\n\n (headersText || '')\n .split('\\n')\n .forEach(function(header) {\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 var response = new this._externals.Response(text, {\n headers: headers,\n status: status,\n statusText: statusText\n });\n\n return new ApiResponse({\n externals: this._externals,\n request: null,\n response: response,\n responseText: text\n });\n\n};\n\nmodule.exports = ApiResponse;\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/http/ApiResponse.js\n// module id = 7\n// module chunks = 0 1","'use strict';\n\nexports.decode = exports.parse = require('./decode');\nexports.encode = exports.stringify = require('./encode');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./~/querystring/index.js\n// module id = 8\n// module chunks = 0 1","// Copyright Joyent, Inc. and other Node contributors.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a\n// copy of this software and associated documentation files (the\n// \"Software\"), to deal in the Software without restriction, including\n// without limitation the rights to use, copy, modify, merge, publish,\n// distribute, sublicense, and/or sell copies of the Software, and to permit\n// persons to whom the Software is furnished to do so, subject to the\n// following conditions:\n//\n// The above copyright notice and this permission notice shall be included\n// in all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\n// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN\n// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,\n// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE\n// USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n'use strict';\n\n// If obj.hasOwnProperty has been overridden, then calling\n// obj.hasOwnProperty(prop) will break.\n// See: https://github.com/joyent/node/issues/1707\nfunction hasOwnProperty(obj, prop) {\n return Object.prototype.hasOwnProperty.call(obj, prop);\n}\n\nmodule.exports = function(qs, sep, eq, options) {\n sep = sep || '&';\n eq = eq || '=';\n var obj = {};\n\n if (typeof qs !== 'string' || qs.length === 0) {\n return obj;\n }\n\n var regexp = /\\+/g;\n qs = qs.split(sep);\n\n var maxKeys = 1000;\n if (options && typeof options.maxKeys === 'number') {\n maxKeys = options.maxKeys;\n }\n\n var len = qs.length;\n // maxKeys <= 0 means that we should not limit keys count\n if (maxKeys > 0 && len > maxKeys) {\n len = maxKeys;\n }\n\n for (var i = 0; i < len; ++i) {\n var x = qs[i].replace(regexp, '%20'),\n idx = x.indexOf(eq),\n kstr, vstr, k, v;\n\n if (idx >= 0) {\n kstr = x.substr(0, idx);\n vstr = x.substr(idx + 1);\n } else {\n kstr = x;\n vstr = '';\n }\n\n k = decodeURIComponent(kstr);\n v = decodeURIComponent(vstr);\n\n if (!hasOwnProperty(obj, k)) {\n obj[k] = v;\n } else if (Array.isArray(obj[k])) {\n obj[k].push(v);\n } else {\n obj[k] = [obj[k], v];\n }\n }\n\n return obj;\n};\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./~/querystring/decode.js\n// module id = 9\n// module chunks = 0 1","// Copyright Joyent, Inc. and other Node contributors.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a\n// copy of this software and associated documentation files (the\n// \"Software\"), to deal in the Software without restriction, including\n// without limitation the rights to use, copy, modify, merge, publish,\n// distribute, sublicense, and/or sell copies of the Software, and to permit\n// persons to whom the Software is furnished to do so, subject to the\n// following conditions:\n//\n// The above copyright notice and this permission notice shall be included\n// in all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\n// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN\n// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,\n// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE\n// USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n'use strict';\n\nvar stringifyPrimitive = function(v) {\n switch (typeof v) {\n case 'string':\n return v;\n\n case 'boolean':\n return v ? 'true' : 'false';\n\n case 'number':\n return isFinite(v) ? v : '';\n\n default:\n return '';\n }\n};\n\nmodule.exports = function(obj, sep, eq, name) {\n sep = sep || '&';\n eq = eq || '=';\n if (obj === null) {\n obj = undefined;\n }\n\n if (typeof obj === 'object') {\n return Object.keys(obj).map(function(k) {\n var ks = encodeURIComponent(stringifyPrimitive(k)) + eq;\n if (Array.isArray(obj[k])) {\n return obj[k].map(function(v) {\n return ks + encodeURIComponent(stringifyPrimitive(v));\n }).join(sep);\n } else {\n return ks + encodeURIComponent(stringifyPrimitive(obj[k]));\n }\n }).join(sep);\n\n }\n\n if (!name) return '';\n return encodeURIComponent(stringifyPrimitive(name)) + eq +\n encodeURIComponent(stringifyPrimitive(obj));\n};\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./~/querystring/encode.js\n// module id = 10\n// module chunks = 0 1","var pubnub = require(\"pubnub\");\nvar es6Promise = require(\"es6-promise\");\nvar FetchPonyfill = require(\"fetch-ponyfill\");\n\nvar root = (typeof window !== \"undefined\" && window) ||\n (typeof global !== \"undefined\" && global) ||\n (function(){ return this; })();\n\n/**\n * @constructor\n * @param {PubNub} [options.PubNub]\n * @param {function(new:Promise)} [options.Promise]\n * @param {Storage} [options.localStorage]\n * @param {fetch} [options.fetch]\n * @param {function(new:Request)} [options.Request]\n * @param {function(new:Response)} [options.Response]\n * @param {function(new:Headers)} [options.Headers]\n * @property {PubNub} PubNub\n * @property {Storage} localStorage\n * @property {function(new:Promise)} Promise\n * @property {fetch} fetch\n * @property {function(new:Request)} Request\n * @property {function(new:Response)} Response\n * @property {function(new:Headers)} Headers\n */\nfunction Externals(options) {\n\n options = options || {};\n\n this.PubNub = options.PubNub || root.PubNub || pubnub;\n this.localStorage = options.localStorage || ((typeof root.localStorage !== 'undefined') ? root.localStorage : {});\n this.Promise = options.Promise || root.Promise || (es6Promise && es6Promise.Promise);\n\n var fetchPonyfill = FetchPonyfill ? FetchPonyfill({Promise: this.Promise}) : {};\n\n this.fetch = options.fetch || root.fetch || fetchPonyfill.fetch;\n this.Request = options.Request || root.Request || fetchPonyfill.Request;\n this.Response = options.Response || root.Response || fetchPonyfill.Response;\n this.Headers = options.Headers || root.Headers || fetchPonyfill.Headers;\n\n /* istanbul ignore next */\n if (!this.fetch || !this.Response || !this.Request || !this.Headers) {\n throw new Error('Fetch API is missing');\n }\n\n /* istanbul ignore next */\n if (!this.Promise) {\n throw new Error('Promise is missing');\n }\n\n /* istanbul ignore next */\n if (!this.localStorage) {\n throw new Error('LocalStorage is missing');\n }\n\n /* istanbul ignore next */\n if (!this.PubNub) {\n throw new Error('PubNub is missing');\n }\n\n}\n\nmodule.exports = Externals;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/core/Externals.js\n// module id = 11\n// module chunks = 0 1","module.exports = __WEBPACK_EXTERNAL_MODULE_12__;\n\n\n//////////////////\n// WEBPACK FOOTER\n// external {\"amd\":\"pubnub\"}\n// module id = 12\n// module chunks = 0 1","module.exports = __WEBPACK_EXTERNAL_MODULE_13__;\n\n\n//////////////////\n// WEBPACK FOOTER\n// external {\"amd\":\"es6-promise\"}\n// module id = 13\n// module chunks = 0 1","module.exports = __WEBPACK_EXTERNAL_MODULE_14__;\n\n\n//////////////////\n// WEBPACK FOOTER\n// external {\"amd\":\"fetch-ponyfill\"}\n// module id = 14\n// module chunks = 0 1","var EventEmitter = require(\"events\").EventEmitter;\nvar qs = require(\"querystring\");\nvar objectAssign = require('object-assign');\nvar Auth = require(\"./Auth\");\nvar Constants = require(\"../core/Constants\");\nvar ApiResponse = require(\"../http/ApiResponse\");\n\n/**\n * @constructor\n * @param {string} options.server\n * @param {string} options.appSecret\n * @param {string} options.appKey\n * @param {string} [options.appName]\n * @param {string} [options.appVersion]\n * @param {string} [options.redirectUri]\n * @param {int} [options.refreshDelayMs]\n * @param {int} [options.refreshHandicapMs]\n * @param {boolean} [options.clearCacheOnRefreshError]\n * @param {Externals} options.externals\n * @param {Cache} options.cache\n * @param {Client} options.client\n * @property {Externals} _externals\n * @property {Cache} _cache\n * @property {Client} _client\n * @property {Promise} _refreshPromise\n * @property {Auth} _auth\n */\nfunction Platform(options) {\n\n EventEmitter.call(this);\n\n this.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 rateLimitError: 'rateLimitError'\n };\n\n options = options || {};\n\n /** @private */\n this._server = options.server;\n\n /** @private */\n this._appKey = options.appKey;\n\n /** @private */\n this._appSecret = options.appSecret;\n\n /** @private */\n this._redirectUri = options.redirectUri || '';\n\n /** @private */\n this._refreshDelayMs = options.refreshDelayMs || 100;\n\n /** @private */\n this._clearCacheOnRefreshError = typeof options.clearCacheOnRefreshError !== 'undefined' ?\n options.clearCacheOnRefreshError :\n true;\n\n /** @private */\n this._userAgent = (options.appName ?\n (options.appName + (options.appVersion ? '/' + options.appVersion : '')) + ' ' :\n '') + 'RCJSSDK/' + Constants.version;\n\n /** @private */\n this._externals = options.externals;\n\n /** @private */\n this._cache = options.cache;\n\n /** @private */\n this._client = options.client;\n\n /** @private */\n this._knownPrefixes = options.knownPrefixes || Platform._knownPrefixes;\n\n\n /** @private */\n this._refreshPromise = null;\n\n /** @private */\n this._auth = new Auth({\n cache: this._cache,\n cacheId: Platform._cacheId,\n refreshHandicapMs: options.refreshHandicapMs\n });\n\n}\n\nPlatform._urlPrefix = '/restapi';\nPlatform._apiVersion = 'v1.0';\nPlatform._knownPrefixes = ['/rcvideo'];\nPlatform._tokenEndpoint = '/restapi/oauth/token';\nPlatform._revokeEndpoint = '/restapi/oauth/revoke';\nPlatform._authorizeEndpoint = '/restapi/oauth/authorize';\nPlatform._cacheId = 'platform';\n\nPlatform.prototype = Object.create(EventEmitter.prototype);\n\nPlatform.prototype.delay = function(timeout) {\n return new this._externals.Promise(function(resolve, reject) {\n setTimeout(function() {\n resolve(null);\n }, timeout);\n });\n};\n\n/**\n * @return {Auth}\n */\nPlatform.prototype.auth = function() {\n return this._auth;\n};\n\n/**\n * @return {Client}\n */\nPlatform.prototype.client = function() {\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 */\nPlatform.prototype.createUrl = function(path, options) {\n\n path = path || '';\n options = options || {};\n\n var builtUrl = '',\n hasHttp = path.indexOf('http://') != -1 || path.indexOf('https://') != -1,\n alreadyPrefixed = this._knownPrefixes.some(function(prefix) {\n return path.indexOf(prefix) === 0;\n });\n\n if (options.addServer && !hasHttp) builtUrl += this._server;\n\n if (path.indexOf(Platform._urlPrefix) == -1 && !hasHttp && !alreadyPrefixed) {\n builtUrl += Platform._urlPrefix + '/' + Platform._apiVersion;\n }\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] Overrides default RedirectURI\n * @param {string} [options.state]\n * @param {string} [options.brandId]\n * @param {string} [options.display]\n * @param {string} [options.prompt]\n * @param {boolean} [options.implicit] Use Implicit Grant flow\n * @return {string}\n */\nPlatform.prototype.loginUrl = function(options) {\n\n options = options || {};\n\n return this.createUrl(Platform._authorizeEndpoint + '?' + qs.stringify({\n 'response_type': options.implicit ? 'token' : 'code',\n 'redirect_uri': options.redirectUri || this._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 */\nPlatform.prototype.parseLoginRedirect = function(url) {\n\n function getParts(url, separator) {\n return url.split(separator).reverse()[0];\n }\n\n var response = (url.indexOf('#') === 0 && getParts(url, '#')) ||\n (url.indexOf('?') === 0 && getParts(url, '?')) ||\n null;\n\n if (!response) throw new Error('Unable to parse response');\n\n var queryString = qs.parse(response);\n\n if (!queryString) throw new Error('Unable to parse response');\n\n var error = queryString.error_description || queryString.error;\n\n if (error) {\n var e = new Error(error);\n e.error = queryString.error;\n throw e;\n }\n\n return queryString;\n\n};\n\n/**\n * Convenience method to handle 3-legged OAuth\n *\n * Attention! This is an experimental method and it's signature and behavior may change without notice.\n *\n * @experimental\n * @param {string} options.url\n * @param {number} [options.width]\n * @param {number} [options.height]\n * @param {object} [options.login] additional options for login()\n * @param {string} [options.origin]\n * @param {string} [options.property] name of window.postMessage's event data property\n * @param {string} [options.target] target for window.open()\n * @return {Promise}\n */\nPlatform.prototype.loginWindow = function(options) {\n\n return new this._externals.Promise(function(resolve, reject) {\n\n if (typeof window === 'undefined') throw new Error('This method can be used only in browser');\n\n if (!options.url) throw new Error('Missing mandatory URL parameter');\n\n options = options || {};\n options.width = options.width || 400;\n options.height = options.height || 600;\n options.origin = options.origin || window.location.origin;\n options.property = options.property || Constants.authResponseProperty;\n options.target = options.target || '_blank';\n\n var dualScreenLeft = window.screenLeft !== undefined ? window.screenLeft : screen.left;\n var dualScreenTop = window.screenTop !== undefined ? window.screenTop : screen.top;\n\n var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width;\n var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;\n\n var left = ((width / 2) - (options.width / 2)) + dualScreenLeft;\n var top = ((height / 2) - (options.height / 2)) + dualScreenTop;\n var win = window.open(options.url, '_blank', (options.target == '_blank') ? 'scrollbars=yes, status=yes, width=' + options.width + ', height=' + options.height + ', left=' + left + ', top=' + top : '');\n\n if (!win) {\n throw new Error('Could not open login window. Please allow popups for this site');\n }\n\n if (win.focus) win.focus();\n\n var eventMethod = window.addEventListener ? 'addEventListener' : 'attachEvent';\n var eventRemoveMethod = eventMethod == 'addEventListener' ? 'removeEventListener' : 'detachEvent';\n var messageEvent = eventMethod == 'addEventListener' ? 'message' : 'onmessage';\n\n var eventListener = function(e) {\n\n try {\n\n if (e.origin != options.origin) return;\n if (!e.data || !e.data[options.property]) return; // keep waiting\n\n win.close();\n window[eventRemoveMethod](messageEvent, eventListener);\n\n\n var loginOptions = this.parseLoginRedirect(e.data[options.property]);\n\n if (!loginOptions.code && !loginOptions.access_token) throw new Error('No authorization code or token');\n\n resolve(loginOptions);\n\n /* jshint -W002 */\n } catch (e) {\n reject(e);\n }\n\n }.bind(this);\n\n window[eventMethod](messageEvent, eventListener, false);\n\n }.bind(this));\n\n};\n\n/**\n * @return {Promise}\n */\nPlatform.prototype.loggedIn = function() {\n\n return this.ensureLoggedIn().then(function() {\n return true;\n }).catch(function() {\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 * @param {string} [options.accessTokenTtl]\n * @param {string} [options.refreshTokenTtl]\n * @param {string} [options.access_token]\n * @returns {Promise}\n */\nPlatform.prototype.login = function(options) {\n\n return (new this._externals.Promise(function(resolve) {\n\n options = options || {};\n\n this.emit(this.events.beforeLogin);\n\n var body = {};\n\n if (options.access_token) {\n\n //TODO Potentially make a request to /oauth/tokeninfo\n return resolve(options);\n\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 || this._redirectUri;\n //body.client_id = this.getCredentials().key; // not needed\n\n }\n\n if (options.endpointId) body.endpoint_id = options.endpointId;\n if (options.accessTokenTtl) body.access_token_ttl = options.accessTokenTtl;\n if (options.refreshTokenTtl) body.refresh_token_ttl = options.refreshTokenTtl;\n\n resolve(this._tokenRequest(Platform._tokenEndpoint, body));\n\n }.bind(this))).then(function(res) {\n\n var apiResponse = res.json ? res : null;\n var json = apiResponse && apiResponse.json() || res;\n\n this._auth.setData(json);\n\n this.emit(this.events.loginSuccess, apiResponse);\n\n return apiResponse;\n\n }.bind(this)).catch(function(e) {\n\n if (this._clearCacheOnRefreshError) {\n this._cache.clean();\n }\n\n this.emit(this.events.loginError, e);\n\n throw e;\n\n }.bind(this));\n\n};\n\n/**\n * @returns {Promise}\n * @private\n */\nPlatform.prototype._refresh = function() {\n\n return this.delay(this._refreshDelayMs).then(function() {\n\n this.emit(this.events.beforeRefresh);\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\n return this._tokenRequest(Platform._tokenEndpoint, {\n \"grant_type\": \"refresh_token\",\n \"refresh_token\": this._auth.refreshToken(),\n \"access_token_ttl\": this._auth.data().expires_in + 1,\n \"refresh_token_ttl\": this._auth.data().refresh_token_expires_in + 1\n });\n\n }.bind(this)).then(function(/** @type {ApiResponse} */ res) {\n\n var 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\n this.emit(this.events.refreshSuccess, res);\n\n return res;\n\n }.bind(this)).catch(function(e) {\n\n e = this._client.makeError(e);\n\n if (this._clearCacheOnRefreshError) {\n this._cache.clean();\n }\n\n this.emit(this.events.refreshError, e);\n\n throw e;\n\n }.bind(this));\n\n};\n\n/**\n * @returns {Promise}\n */\nPlatform.prototype.refresh = function() {\n\n if (!this._refreshPromise) {\n\n this._refreshPromise = this._refresh()\n .then(function(res) {\n this._refreshPromise = null;\n return res;\n }.bind(this))\n .catch(function(e) {\n this._refreshPromise = null;\n throw e;\n }.bind(this));\n\n }\n\n return this._refreshPromise;\n\n};\n\n/**\n * @returns {Promise}\n */\nPlatform.prototype.logout = function() {\n\n return (new this._externals.Promise(function(resolve) {\n\n this.emit(this.events.beforeLogout);\n\n if (!this._appSecret) {\n resolve(null);\n return;\n }\n\n resolve(this._tokenRequest(Platform._revokeEndpoint, {\n token: this._auth.accessToken()\n }));\n }.bind(this))).then(function(res) {\n\n this._cache.clean();\n\n this.emit(this.events.logoutSuccess, res);\n\n return res;\n\n }.bind(this)).catch(function(e) {\n\n this.emit(this.events.logoutError, e);\n\n throw e;\n\n }.bind(this));\n\n};\n\n/**\n * @param {Request} request\n * @param {object} [options]\n * @param {boolean} [options.skipAuthCheck]\n * @return {Promise}\n */\nPlatform.prototype.inflateRequest = function(request, options) {\n\n options = options || {};\n\n if (options.skipAuthCheck) return this._externals.Promise.resolve(request);\n\n return this.ensureLoggedIn().then(function() {\n\n request.headers.set('X-User-Agent', this._userAgent);\n request.headers.set('Client-Id', this._appKey);\n request.headers.set('Authorization', this._authHeader());\n //request.url = this.createUrl(request.url, {addServer: true}); //FIXME Spec prevents this...\n\n return request;\n\n }.bind(this));\n\n};\n\n/**\n * @param {Request} request\n * @param {object} [options]\n * @param {boolean} [options.skipAuthCheck]\n * @param {boolean|int} [options.handleRateLimit]\n * @param {boolean} [options.retry] Will be set by this method if SDK makes second request\n * @return {Promise}\n */\nPlatform.prototype.sendRequest = function(request, options) {\n\n return this.inflateRequest(request, options).then(function(request) {\n\n options = options || {};\n\n return this._client.sendRequest(request);\n\n }.bind(this)).catch(function(e) {\n\n // Guard is for errors that come from polling\n if (!e.apiResponse || !e.apiResponse.response() || options.retry) throw e;\n\n var response = e.apiResponse.response();\n var status = response.status;\n\n if ((status != ApiResponse._unauthorizedStatus) &&\n (status != ApiResponse._rateLimitStatus)) throw e;\n\n options.retry = true;\n\n var retryAfter = 0;\n\n if (status == ApiResponse._unauthorizedStatus) {\n this._auth.cancelAccessToken();\n }\n\n if (status == ApiResponse._rateLimitStatus) {\n\n var defaultRetryAfter = (!options.handleRateLimit || typeof options.handleRateLimit == 'boolean' ? 60 : options.handleRateLimit);\n\n // FIXME retry-after is custom header, by default, it can't be retrieved. Server should add header: 'Access-Control-Expose-Headers: retry-after'.\n retryAfter = parseFloat(response.headers.get('retry-after') || defaultRetryAfter) * 1000;\n\n e.retryAfter = retryAfter;\n\n this.emit(this.events.rateLimitError, e);\n\n if (!options.handleRateLimit) throw e;\n\n }\n\n return this.delay(retryAfter).then(function() {\n return this.sendRequest(this._client.createRequest(options), options);\n }.bind(this));\n\n }.bind(this));\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 * @param {boolean|int} [options.handleRateLimit]\n * @return {Promise}\n */\nPlatform.prototype.send = function(options) {\n\n options = options || {};\n\n //FIXME https://github.com/bitinn/node-fetch/issues/43\n options.url = this.createUrl(options.url, {addServer: true});\n\n return 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 * @param {boolean|int} [options.handleRateLimit]\n * @return {Promise}\n */\nPlatform.prototype.get = function(url, query, options) {\n return this.send(objectAssign({}, {method: 'GET', url: url, query: query}, 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 * @param {boolean|int} [options.handleRateLimit]\n * @return {Promise}\n */\nPlatform.prototype.post = function(url, body, query, options) {\n return this.send(objectAssign({}, {method: 'POST', url: url, query: query, body: body}, 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 * @param {boolean|int} [options.handleRateLimit]\n * @return {Promise}\n */\nPlatform.prototype.put = function(url, body, query, options) {\n return this.send(objectAssign({}, {method: 'PUT', url: url, query: query, body: body}, 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 * @param {boolean|int} [options.handleRateLimit]\n * @return {Promise}\n */\nPlatform.prototype['delete'] = function(url, query, options) {\n return this.send(objectAssign({}, {method: 'DELETE', url: url, query: query}, options));\n};\n\nPlatform.prototype.ensureLoggedIn = function() {\n if (this._isAccessTokenValid()) return this._externals.Promise.resolve();\n return this.refresh();\n};\n\n/**\n * @param path\n * @param body\n * @return {Promise.}\n * @private\n */\nPlatform.prototype._tokenRequest = function(path, body) {\n\n return this.send({\n url: path,\n skipAuthCheck: true,\n body: body,\n method: 'POST',\n headers: {\n 'Authorization': 'Basic ' + this._apiKey(),\n 'Content-Type': ApiResponse._urlencodedContentType\n }\n });\n\n};\n\n/**\n * @return {boolean}\n * @private\n */\nPlatform.prototype._isAccessTokenValid = function() {\n return this._auth.accessTokenValid();\n};\n\n/**\n * @return {string}\n * @private\n */\nPlatform.prototype._apiKey = function() {\n var apiKey = this._appKey + ':' + this._appSecret;\n return (typeof btoa == 'function') ? btoa(apiKey) : new Buffer(apiKey).toString('base64');\n};\n\n/**\n * @return {string}\n * @private\n */\nPlatform.prototype._authHeader = function() {\n var token = this._auth.accessToken();\n return this._auth.tokenType() + (token ? ' ' + token : '');\n};\n\nmodule.exports = Platform;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/platform/Platform.js\n// module id = 15\n// module chunks = 0 1","/**\n * @param {Cache} options.cache\n * @param {string} options.cacheId\n * @param {int} [options.refreshHandicapMs]\n * @constructor\n * @property {Cache} _cache\n * @property {int} _refreshHandicapMs\n * @property {string} _cacheId\n */\nfunction Auth(options) {\n\n /** @private */\n this._cache = options.cache;\n\n /** @private */\n this._cacheId = options.cacheId;\n\n /** @private */\n this._refreshHandicapMs = options.refreshHandicapMs || 60 * 1000; // 1 minute\n\n}\n\nAuth.prototype.accessToken = function() {\n return this.data().access_token;\n};\n\nAuth.prototype.refreshToken = function() {\n return this.data().refresh_token;\n};\n\nAuth.prototype.tokenType = function() {\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 */\nAuth.prototype.data = function() {\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 */\nAuth.prototype.setData = function(newData) {\n\n newData = newData || {};\n\n var data = this.data();\n\n Object.keys(newData).forEach(function(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 */\nAuth.prototype.accessTokenValid = function() {\n\n var authData = this.data();\n return (authData.expire_time - this._refreshHandicapMs > Date.now());\n\n};\n\n/**\n * Check if there is a valid (not expired) access token\n * @return {boolean}\n */\nAuth.prototype.refreshTokenValid = function() {\n\n return (this.data().refresh_token_expire_time > Date.now());\n\n};\n\n/**\n * @return {Auth}\n */\nAuth.prototype.cancelAccessToken = function() {\n\n return this.setData({\n access_token: '',\n expires_in: 0\n });\n\n};\n\nmodule.exports = Auth;\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//////////////////\n// WEBPACK FOOTER\n// ./src/platform/Auth.js\n// module id = 16\n// module chunks = 0 1","var version = process.env.RCSDK_VERSION;\n\n// This will become false during the Webpack build, so no traces of package.json will be there\nif (!process.env.RCSDK_VERSION) {\n version = require('../../package.json').version;\n}\n\nmodule.exports = {\n version: version,\n authResponseProperty: 'RCAuthorizationResponse'\n};\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/core/Constants.js\n// module id = 17\n// module chunks = 0 1","var EventEmitter = require(\"events\").EventEmitter;\n\n// detect ISO 8601 format string with +00[:00] timezone notations\nvar ISO_REG_EXP = /(\\+[\\d]{2}):?([\\d]{2})?$/;\n\nfunction buildIEFriendlyString(match, $1, $2) {\n return $1 + ':' + ($2 || '00');\n}\n\n/**\n *\n * @param {string} time\n * @return {number}\n */\nfunction parseISOString(time) {\n time = time || 0;\n if (typeof time === 'string') {\n return Date.parse(time.replace(ISO_REG_EXP, buildIEFriendlyString));\n }\n return time;\n}\n\n/**\n * @param {Platform} options.platform\n * @param {Externals} options.externals\n * @param {int} [options.pollInterval]\n * @param {int} [options.renewHandicapMs]\n * @property {Externals} _externals\n * @property {Platform} _platform\n * @property {int} _pollInterval\n * @property {int} _renewHandicapMs\n * @property {PubNub} _pubnub\n * @property {string} _pubnubLastChannel\n * @property {int} _timeout\n * @property {ISubscription} _subscription\n * @constructor\n */\nfunction Subscription(options) {\n\n EventEmitter.call(this);\n\n options = options || {};\n\n this.events = {\n notification: 'notification',\n removeSuccess: 'removeSuccess',\n removeError: 'removeError',\n renewSuccess: 'renewSuccess',\n renewError: 'renewError',\n subscribeSuccess: 'subscribeSuccess',\n subscribeError: 'subscribeError',\n automaticRenewSuccess: 'automaticRenewSuccess',\n automaticRenewError: 'automaticRenewError',\n status: 'status'\n };\n\n /** @private */\n this._externals = options.externals;\n\n /** @private */\n this._platform = options.platform;\n\n /** @private */\n this._pollInterval = options.pollInterval || 10 * 1000;\n\n /** @private */\n this._renewHandicapMs = options.renewHandicapMs || 2 * 60 * 1000;\n\n /** @private */\n this._pubnub = null;\n\n /** @private */\n this._pubnubLastChannel = null;\n\n /** @private */\n this._pubnubLastSubscribeKey = null;\n\n /** @private */\n this._timeout = null;\n\n /** @private */\n this._subscription = null;\n\n}\n\nSubscription.prototype = Object.create(EventEmitter.prototype);\n\nSubscription.prototype.subscribed = function() {\n\n var subscription = this.subscription();\n\n return !!(subscription.id &&\n subscription.deliveryMode &&\n subscription.deliveryMode.subscriberKey &&\n subscription.deliveryMode.address);\n\n};\n\n/**\n * @return {boolean}\n */\nSubscription.prototype.alive = function() {\n return this.subscribed() && Date.now() < this.expirationTime();\n};\n\n/**\n * @return {boolean}\n */\nSubscription.prototype.expired = function() {\n if (!this.subscribed()) return true;\n return !this.subscribed() || Date.now() > parseISOString(this.subscription().expirationTime);\n};\n\n/**\n * @return {number}\n */\nSubscription.prototype.expirationTime = function() {\n return parseISOString(this.subscription().expirationTime) - this._renewHandicapMs;\n};\n\n/**\n * @param {ISubscription} subscription\n * @return {Subscription}\n */\nSubscription.prototype.setSubscription = function(subscription) {\n\n subscription = subscription || {};\n\n this._clearTimeout();\n this._setSubscription(subscription);\n this._subscribeAtPubnub();\n this._setTimeout();\n\n return this;\n\n};\n\n/**\n * @return {ISubscription}\n */\nSubscription.prototype.subscription = function() {\n return this._subscription || {};\n};\n\n/**\n * Creates or updates subscription if there is an active one\n * @returns {Promise}\n */\nSubscription.prototype.register = function() {\n\n if (this.alive()) {\n return this.renew();\n } else {\n return this.subscribe();\n }\n\n};\n\n/**\n * @return {string[]}\n */\nSubscription.prototype.eventFilters = function() {\n return this.subscription().eventFilters || [];\n};\n\n/**\n * @param {string[]} events\n * @return {Subscription}\n */\nSubscription.prototype.addEventFilters = function(events) {\n this.setEventFilters(this.eventFilters().concat(events));\n return this;\n};\n\n/**\n * @param {string[]} events\n * @return {Subscription}\n */\nSubscription.prototype.setEventFilters = function(events) {\n var subscription = this.subscription();\n subscription.eventFilters = events;\n this._setSubscription(subscription);\n return this;\n};\n\n/**\n * @returns {Promise}\n */\nSubscription.prototype.subscribe = function() {\n\n return (new this._externals.Promise(function(resolve) {\n\n this._clearTimeout();\n\n if (!this.eventFilters().length) throw new Error('Events are undefined');\n\n resolve(this._platform.post('/subscription', {\n eventFilters: this._getFullEventFilters(),\n deliveryMode: {\n transportType: 'PubNub'\n }\n }));\n\n }.bind(this))).then(function(response) {\n\n var json = response.json();\n\n this.setSubscription(json)\n .emit(this.events.subscribeSuccess, response);\n\n return response;\n\n }.bind(this)).catch(function(e) {\n\n e = this._platform.client().makeError(e);\n // `reset` will remove pubnub instance.\n // so if network is broken for a long time, pubnub will be removed. And client can not receive notification anymore.\n this.reset()\n .emit(this.events.subscribeError, e);\n\n throw e;\n\n }.bind(this));\n\n};\n\n/**\n * @returns {Promise}\n */\nSubscription.prototype.renew = function() {\n\n return (new this._externals.Promise(function(resolve) {\n\n this._clearTimeout();\n\n if (!this.subscribed()) throw new Error('No subscription');\n\n if (!this.eventFilters().length) throw new Error('Events are undefined');\n\n resolve(this._platform.put('/subscription/' + this.subscription().id, {\n eventFilters: this._getFullEventFilters()\n }));\n\n }.bind(this))).then(function(response) {\n\n var json = response.json();\n\n this.setSubscription(json)\n .emit(this.events.renewSuccess, response);\n\n return response;\n\n }.bind(this)).catch(function(e) {\n\n e = this._platform.client().makeError(e);\n // `reset` will remove pubnub instance.\n // so if network is broken for a long time, pubnub will be removed. And client can not receive notification anymore.\n this.reset()\n .emit(this.events.renewError, e);\n\n throw e;\n\n }.bind(this));\n\n};\n\n/**\n * @returns {Promise}\n */\nSubscription.prototype.remove = function() {\n\n return (new this._externals.Promise(function(resolve) {\n\n if (!this.subscribed()) throw new Error('No subscription');\n\n resolve(this._platform.delete('/subscription/' + this.subscription().id));\n\n }.bind(this))).then(function(response) {\n\n this.reset()\n .emit(this.events.removeSuccess, response);\n\n return response;\n\n }.bind(this)).catch(function(e) {\n\n e = this._platform.client().makeError(e);\n\n this.emit(this.events.removeError, e);\n\n throw e;\n\n }.bind(this));\n\n};\n\n/**\n * @returns {Promise}\n */\nSubscription.prototype.resubscribe = function() {\n var filters = this.eventFilters();\n return this.reset().setEventFilters(filters).subscribe();\n};\n\n/**\n * Remove subscription and disconnect from PubNub\n * This method resets subscription at client side but backend is not notified\n * @return {Subscription}\n */\nSubscription.prototype.reset = function() {\n this._clearTimeout();\n this._unsubscribeAtPubnub();\n this._setSubscription(null);\n return this;\n};\n\n/**\n * @param subscription\n * @private\n */\nSubscription.prototype._setSubscription = function(subscription) {\n this._subscription = subscription;\n};\n\n/**\n * @return {string[]}\n * @private\n */\nSubscription.prototype._getFullEventFilters = function() {\n\n return this.eventFilters().map(function(event) {\n return this._platform.createUrl(event);\n }.bind(this));\n\n};\n\n/**\n * @return {Subscription}\n * @private\n */\nSubscription.prototype._setTimeout = function() {\n\n this._clearTimeout();\n\n if (!this.alive()) throw new Error('Subscription is not alive');\n\n this._timeout = setInterval(function() {\n\n if (this.alive()) {\n return;\n }\n\n this._clearTimeout();\n\n (new this._externals.Promise(function(resolve) {\n\n if (this.expired()) {\n resolve(this.subscribe());\n } else {\n resolve(this.renew());\n }\n\n }.bind(this))).then(function(res) {\n\n this.emit(this.events.automaticRenewSuccess, res);\n\n }.bind(this)).catch(function(e) {\n\n this.emit(this.events.automaticRenewError, e);\n\n }.bind(this));\n\n }.bind(this), this._pollInterval);\n\n return this;\n\n};\n\n/**\n * @return {Subscription}\n * @private\n */\nSubscription.prototype._clearTimeout = function() {\n clearInterval(this._timeout);\n return this;\n};\n\nSubscription.prototype._decrypt = function(message) {\n\n if (!this.subscribed()) throw new Error('No subscription');\n\n if (this.subscription().deliveryMode.encryptionKey) {\n\n message = this._pubnub.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/**\n * @param message\n * @return {Subscription}\n * @private\n */\nSubscription.prototype._notify = function(message) {\n this.emit(this.events.notification, this._decrypt(message));\n return this;\n};\n\n/**\n * @return {Subscription}\n * @private\n */\nSubscription.prototype._subscribeAtPubnub = function() {\n\n if (!this.alive()) throw new Error('Subscription is not alive');\n\n var deliveryMode = this.subscription().deliveryMode;\n\n if (this._pubnub) {\n\n if (this._pubnubLastChannel === deliveryMode.address) {\n\n // Nothing to update, keep listening to same channel\n return this;\n\n } else if (this._pubnubLastSubscribeKey && this._pubnubLastSubscribeKey !== deliveryMode.subscriberKey) {\n\n // Subscribe key changed, need to reset everything\n this._unsubscribeAtPubnub();\n\n } else if (this._pubnubLastChannel) {\n\n // Need to subscribe to new channel\n this._pubnub.unsubscribeAll();\n\n }\n\n }\n\n if (!this._pubnub) {\n\n this._pubnubLastSubscribeKey = deliveryMode.subscriberKey;\n\n var PubNub = this._externals.PubNub;\n\n this._pubnub = new PubNub({\n ssl: true,\n restore: true,\n subscribeKey: deliveryMode.subscriberKey,\n origin: 'ringcentral.pubnubapi.com',\n keepAlive: true\n });\n\n this._pubnub.addListener({\n status: function(statusEvent) {\n this.emit(this.events.status, statusEvent);\n }.bind(this),\n message: function(m) {\n this._notify(m.message); // all other props are ignored\n }.bind(this)\n });\n\n }\n\n this._pubnubLastChannel = deliveryMode.address;\n this._pubnub.subscribe({channels: [deliveryMode.address]});\n\n return this;\n\n};\n\n/**\n * @return {Subscription}\n * @private\n */\nSubscription.prototype._unsubscribeAtPubnub = function() {\n\n if (!this.subscribed() || !this._pubnub) return this;\n\n this._pubnub.removeAllListeners();\n this._pubnub.destroy(); // this will unsubscribe from all\n\n this._pubnubLastSubscribeKey = null;\n this._pubnubLastChannel = null;\n this._pubnub = null;\n\n return this;\n\n};\n\nmodule.exports = Subscription;\n\n/**\n * The complete Triforce, or one or more components of the Triforce.\n * @typedef {Object} ISubscription\n * @property {string} [id]\n * @property {string} [uri]\n * @property {string[]} [eventFilters]\n * @property {string} [expirationTime] Format: 2014-03-12T19:54:35.613+0000\n * @property {int} [expiresIn]\n * @property {string} [deliveryMode.transportType]\n * @property {boolean} [deliveryMode.encryption]\n * @property {string} [deliveryMode.address]\n * @property {string} [deliveryMode.subscriberKey]\n * @property {string} [deliveryMode.encryptionKey]\n * @property {string} [deliveryMode.secretKey]\n * @property {string} [creationTime]\n * @property {string} [status] Active\n */\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/subscription/Subscription.js\n// module id = 18\n// module chunks = 0 1","var Subscription = require(\"./Subscription\");\n\n/**\n * @param {Platform} options.platform\n * @param {Externals} options.externals\n * @param {Cache} options.cache\n * @param {string} options.cacheKey\n * @param {int} [options.pollInterval]\n * @param {int} [options.renewHandicapMs]\n * @return {CachedSubscription}\n * @constructor\n * @property {Cache} _cache\n * @extends Subscription\n */\nfunction CachedSubscription(options) {\n\n options = options || {};\n\n if (!options.cacheKey) throw new Error('Cached Subscription requires cacheKey parameter to be defined');\n\n /** @private */\n this._cacheKey = options.cacheKey;\n\n Subscription.call(this, options);\n\n /** @private */\n this._cache = options.cache;\n\n // This is not used in this class\n this._subscription = undefined;\n\n}\n\nCachedSubscription.prototype = Object.create(Subscription.prototype);\n\nCachedSubscription.prototype.subscription = function() {\n return this._cache.getItem(this._cacheKey) || {};\n};\n\nCachedSubscription.prototype._setSubscription = function(subscription) {\n return this._cache.setItem(this._cacheKey, subscription);\n};\n\n/**\n * This function checks whether there are any pre-defined eventFilters in cache and if not -- uses provided as defaults\n * @param {string[]} events\n * @return {CachedSubscription}\n */\nCachedSubscription.prototype.restore = function(events) {\n\n if (!this.eventFilters().length) {\n this.setEventFilters(events);\n }\n\n return this;\n\n};\n\nmodule.exports = CachedSubscription;\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/subscription/CachedSubscription.js\n// module id = 19\n// module chunks = 0 1"],"sourceRoot":""} \ No newline at end of file diff --git a/demo/apiKey.html b/demo/apiKey.html index 154b163c..ae61de72 100644 --- a/demo/apiKey.html +++ b/demo/apiKey.html @@ -76,7 +76,7 @@

- + - + - + - + - + - + - +