From fac8a802420e4ed58ab43d2448da8770607a2753 Mon Sep 17 00:00:00 2001 From: Kirill Konshin Date: Mon, 13 Feb 2017 13:44:29 -0800 Subject: [PATCH] 3.1.1 Subscriptions fix --- build/ringcentral.js | 74 +++++++++++++++++++++++--------- build/ringcentral.js.map | 2 +- build/ringcentral.min.js | 6 +-- build/ringcentral.min.js.map | 2 +- demo/apiKey.html | 6 +-- demo/backbone.html | 6 +-- demo/core.html | 18 +++++--- demo/fax.html | 6 +-- demo/login.html | 6 +-- demo/refresh.html | 6 +-- demo/requirejs.html | 10 ++--- package.json | 2 +- src/SDK.js | 2 +- src/subscription/Subscription.js | 72 +++++++++++++++++++++++-------- 14 files changed, 145 insertions(+), 73 deletions(-) diff --git a/build/ringcentral.js b/build/ringcentral.js index cf382369..afe9724f 100644 --- a/build/ringcentral.js +++ b/build/ringcentral.js @@ -154,7 +154,7 @@ SDK.prototype.createSubscription = function(options) { */ SDK.prototype.createCachedSubscription = function(options) { - if (typeof arguments[0] == 'string') { + if (typeof arguments[0] === 'string') { options = {cacheKey: arguments[0].toString()}; } else { options = options || {}; @@ -2246,7 +2246,7 @@ var EventEmitter = __webpack_require__(6).EventEmitter; * @property {Platform} _platform * @property {int} _pollInterval * @property {int} _renewHandicapMs - * @property {PUBNUB} _pubnub + * @property {PubNub} _pubnub * @property {string} _pubnubLastChannel * @property {int} _timeout * @property {ISubscription} _subscription @@ -2286,6 +2286,9 @@ function Subscription(options) { /** @private */ this._pubnubLastChannel = null; + /** @private */ + this._pubnubLastSubscribeKey = null; + /** @private */ this._timeout = null; @@ -2515,7 +2518,7 @@ Subscription.prototype.resubscribe = function() { */ Subscription.prototype.reset = function() { this._clearTimeout(); - if (this.subscribed() && this._pubnub) this._pubnub.unsubscribe({channel: this.subscription().deliveryMode.address}); + this._unsubscribeAtPubnub(); this._setSubscription(null); return this; }; @@ -2616,35 +2619,66 @@ Subscription.prototype._subscribeAtPubnub = function() { if (this._pubnub) { - if (this._pubnubLastChannel == deliveryMode.address) { // Nothing to update, keep listening to same channel + if (this._pubnubLastChannel === deliveryMode.address) { + + // Nothing to update, keep listening to same channel return this; - } else if (this._pubnubLastChannel) { // Need to subscribe to new channel - this._pubnub.unsubscribe({channel: this._pubnubLastChannel}); + + } else if (this._pubnubLastSubscribeKey && this._pubnubLastSubscribeKey !== deliveryMode.subscriberKey) { + + // Subscribe key changed, need to reset everything + this._unsubscribeAtPubnub(); + + } else if (this._pubnubLastChannel) { + + // Need to subscribe to new channel + this._pubnub.unsubscribeAll(); + } - // Re-init for new data - this._pubnub = this._pubnub.init({ - ssl: true, - subscribe_key: deliveryMode.subscriberKey - }); + } - } else { + if (!this._pubnub) { - // Init from scratch - this._pubnub = new this._externals.PubNub({ + this._pubnubLastSubscribeKey = deliveryMode.subscriberKey; + + var PubNub = this._externals.PubNub; + + this._pubnub = new PubNub({ ssl: true, - subscribe_key: deliveryMode.subscriberKey + subscribeKey: deliveryMode.subscriberKey + }); + + this._pubnub.addListener({ + status: function(statusEvent) {}, + message: function(m) { + this._notify(m.message); // all other props are ignored + }.bind(this) }); } this._pubnubLastChannel = deliveryMode.address; + this._pubnub.subscribe({channels: [deliveryMode.address]}); - this._pubnub.subscribe({ - channel: deliveryMode.address, - message: this._notify.bind(this), - connect: function() {} - }); + return this; + +}; + +/** + * @return {Subscription} + * @private + */ +Subscription.prototype._unsubscribeAtPubnub = function() { + + if (!this.subscribed() || this._pubnub) return this; + + this._pubnub.removeAllListeners(); + this._pubnub.destroy(); // this will unsubscribe from all + + this._pubnubLastSubscribeKey = null; + this._pubnubLastChannel = null; + this._pubnub = null; return this; diff --git a/build/ringcentral.js.map b/build/ringcentral.js.map index 192dc3e5..1eb0c65b 100644 --- a/build/ringcentral.js.map +++ b/build/ringcentral.js.map @@ -1 +1 @@ -{"version":3,"sources":["webpack:///webpack/universalModuleDefinition","webpack:///webpack/bootstrap c20b2b45729ee57a5332","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;AACA;AACA;AACA;;AAEA;;AAEA,qB;;;;;;AC3HA;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,cAAc,UAAU;AACxB;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;;AAEA;AACA;AACA;;AAEA;;AAEA;;AAEA;;AAEA;AACA;AACA;;AAEA,uB;;;;;;ACrDA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA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ACA;;AAEA;AACA;AACA;;;;;;;ACpCA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;;;;;;;ACZA;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;;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,kEAAkE;;AAElE;;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;;;;;;ACvQA;;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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AAS;AACT;AACA;;AAEA,KAAK;;AAEL;;AAEA;;AAEA;AACA,YAAY;AACZ;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA,SAAS;;AAET;;AAEA;;AAEA;;AAEA;AACA;AACA,YAAY;AACZ;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,YAAY;AACZ;AACA;AACA;;AAEA;;AAEA;;AAEA;;AAEA,8DAA8D;AAC9D;AACA,SAAS,oCAAoC;AAC7C,sCAAsC,iCAAiC;AACvE;;AAEA;AACA;AACA;AACA;AACA,SAAS;;AAET,KAAK;;AAEL;AACA;AACA;AACA;AACA,SAAS;;AAET;;AAEA;;AAEA;AACA;AACA;AACA;AACA,KAAK;;AAEL;;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;;;;;;ACjbA;;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 c20b2b45729ee57a5332","/**\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) {\n\n var response = window.location.hash ? window.location.hash : window.location.search;\n var msg = {};\n msg[Constants.authResponseProperty] = response;\n window.opener.postMessage(msg, origin || window.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 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-2015, Jon Schlinkert.\n * Licensed 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-2015, Jon Schlinkert.\n * Licensed under the MIT License.\n */\n\n'use strict';\n\nmodule.exports = function isObject(val) {\n return val != null && typeof val === 'object'\n && !Array.isArray(val);\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;\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 = this._getContentType().match(/boundary=([^;]+)/i)[1];\n\n if (!boundary) throw new Error('Cannot find boundary');\n\n var parts = text.toString().split(ApiResponse._boundarySeparator + boundary);\n\n if (parts[0].trim() === '') parts.shift();\n if (parts[parts.length - 1].trim() == ApiResponse._boundarySeparator) parts.pop();\n\n if (parts.length < 1) throw new Error('No parts in body');\n\n // Step 2. Parse status info\n\n var statusInfo = 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 if (!this.fetch || !this.Response || !this.Request || !this.Headers) {\n throw new Error('Fetch API is missing');\n }\n\n if (!this.Promise) {\n throw new Error('Promise is missing');\n }\n\n if (!this.localStorage) {\n throw new Error('LocalStorage is missing');\n }\n\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 };\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._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._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\n if (options.addServer && !hasHttp) builtUrl += this._server;\n\n if (path.indexOf(Platform._urlPrefix) == -1 && !hasHttp) builtUrl += Platform._urlPrefix + '/' + Platform._apiVersion;\n\n builtUrl += path;\n\n if (options.addMethod || options.addToken) builtUrl += (path.indexOf('?') > -1 ? '&' : '?');\n\n if (options.addMethod) builtUrl += '_method=' + options.addMethod;\n if (options.addToken) builtUrl += (options.addMethod ? '&' : '') + 'access_token=' + this._auth.accessToken();\n\n return builtUrl;\n\n};\n\n/**\n * @param {string} [options.redirectUri] 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.url = options.url || 400;\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.accessTokenTtl = options.accessTokenTtl;\n if (options.refreshTokenTtl) body.refreshTokenTtl = 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 resolve(this._tokenRequest(Platform._revokeEndpoint, {\n token: this._auth.accessToken()\n }));\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} [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() ||\n (e.apiResponse.response().status != ApiResponse._unauthorizedStatus) ||\n options.retry) throw e;\n\n this._auth.cancelAccessToken();\n\n options.retry = true;\n\n return this.sendRequest(request, options);\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 * @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 * @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 * @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 * @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 * @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// 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/**\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 };\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._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() > this.subscription().expirationTime;\n};\n\nSubscription.prototype.expirationTime = function() {\n return new Date(this.subscription().expirationTime || 0).getTime() - 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\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\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 if (this.subscribed() && this._pubnub) this._pubnub.unsubscribe({channel: this.subscription().deliveryMode.address});\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()) return;\n\n if (this.expired()) {\n this.subscribe();\n } else {\n this.renew();\n }\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) { // Nothing to update, keep listening to same channel\n return this;\n } else if (this._pubnubLastChannel) { // Need to subscribe to new channel\n this._pubnub.unsubscribe({channel: this._pubnubLastChannel});\n }\n\n // Re-init for new data\n this._pubnub = this._pubnub.init({\n ssl: true,\n subscribe_key: deliveryMode.subscriberKey\n });\n\n } else {\n\n // Init from scratch\n this._pubnub = new this._externals.PubNub({\n ssl: true,\n subscribe_key: deliveryMode.subscriberKey\n });\n\n }\n\n this._pubnubLastChannel = deliveryMode.address;\n\n this._pubnub.subscribe({\n channel: deliveryMode.address,\n message: this._notify.bind(this),\n connect: function() {}\n });\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.613Z\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 10513986e26ef7cdf365","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;AACA;AACA;AACA;;AAEA;;AAEA,qB;;;;;;AC3HA;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,cAAc,UAAU;AACxB;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;;AAEA;AACA;AACA;;AAEA;;AAEA;;AAEA;;AAEA;AACA;AACA;;AAEA,uB;;;;;;ACrDA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;;AAEA;AACA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A;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;;;;;;;ACZA;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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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;;;;;;ACvQA;;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;;AAEt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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 10513986e26ef7cdf365","/**\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) {\n\n var response = window.location.hash ? window.location.hash : window.location.search;\n var msg = {};\n msg[Constants.authResponseProperty] = response;\n window.opener.postMessage(msg, origin || window.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 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-2015, Jon Schlinkert.\n * Licensed 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-2015, Jon Schlinkert.\n * Licensed under the MIT License.\n */\n\n'use strict';\n\nmodule.exports = function isObject(val) {\n return val != null && typeof val === 'object'\n && !Array.isArray(val);\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;\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 = this._getContentType().match(/boundary=([^;]+)/i)[1];\n\n if (!boundary) throw new Error('Cannot find boundary');\n\n var parts = text.toString().split(ApiResponse._boundarySeparator + boundary);\n\n if (parts[0].trim() === '') parts.shift();\n if (parts[parts.length - 1].trim() == ApiResponse._boundarySeparator) parts.pop();\n\n if (parts.length < 1) throw new Error('No parts in body');\n\n // Step 2. Parse status info\n\n var statusInfo = 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 if (!this.fetch || !this.Response || !this.Request || !this.Headers) {\n throw new Error('Fetch API is missing');\n }\n\n if (!this.Promise) {\n throw new Error('Promise is missing');\n }\n\n if (!this.localStorage) {\n throw new Error('LocalStorage is missing');\n }\n\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 };\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._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._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\n if (options.addServer && !hasHttp) builtUrl += this._server;\n\n if (path.indexOf(Platform._urlPrefix) == -1 && !hasHttp) builtUrl += Platform._urlPrefix + '/' + Platform._apiVersion;\n\n builtUrl += path;\n\n if (options.addMethod || options.addToken) builtUrl += (path.indexOf('?') > -1 ? '&' : '?');\n\n if (options.addMethod) builtUrl += '_method=' + options.addMethod;\n if (options.addToken) builtUrl += (options.addMethod ? '&' : '') + 'access_token=' + this._auth.accessToken();\n\n return builtUrl;\n\n};\n\n/**\n * @param {string} [options.redirectUri] 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.url = options.url || 400;\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.accessTokenTtl = options.accessTokenTtl;\n if (options.refreshTokenTtl) body.refreshTokenTtl = 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 resolve(this._tokenRequest(Platform._revokeEndpoint, {\n token: this._auth.accessToken()\n }));\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} [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() ||\n (e.apiResponse.response().status != ApiResponse._unauthorizedStatus) ||\n options.retry) throw e;\n\n this._auth.cancelAccessToken();\n\n options.retry = true;\n\n return this.sendRequest(request, options);\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 * @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 * @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 * @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 * @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 * @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// 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/**\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 };\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() > this.subscription().expirationTime;\n};\n\nSubscription.prototype.expirationTime = function() {\n return new Date(this.subscription().expirationTime || 0).getTime() - 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\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\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()) return;\n\n if (this.expired()) {\n this.subscribe();\n } else {\n this.renew();\n }\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 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.613Z\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 06ab39ad..39d4d750 100644 --- a/build/ringcentral.min.js +++ b/build/ringcentral.min.js @@ -1,9 +1,9 @@ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require(void 0),require(void 0),require(void 0)):"function"==typeof define&&define.amd?define(["pubnub","es6-promise","fetch-ponyfill"],t):"object"==typeof exports?exports.SDK=t(require(void 0),require(void 0),require(void 0)):(e.RingCentral=e.RingCentral||{},e.RingCentral.SDK=t(e[void 0],e[void 0],e[void 0]))}(this,function(e,t,r){return function(e){function t(n){if(r[n])return r[n].exports;var s=r[n]={exports:{},id:n,loaded:!1};return e[n].call(s.exports,s,s.exports,t),s.loaded=!0,s.exports}var r={};return t.m=e,t.c=r,t.p="/build/",t(0)}([function(e,t,r){function n(e){this._externals=new h(e),this._cache=new i({externals:this._externals,prefix:e.cachePrefix}),this._client=new o(this._externals),this._platform=new u(s({},e,{externals:this._externals,client:this._client,cache:this._cache}))}var s=r(1),i=r(2),o=r(3),h=r(11),u=r(15),c=r(18),a=r(19),p=r(17);n.version=p.version,n.server={sandbox:"https://platform.devtest.ringcentral.com",production:"https://platform.ringcentral.com"},n.prototype.platform=function(){return this._platform},n.prototype.cache=function(){return this._cache},n.prototype.createSubscription=function(e){return new c(s({},e,{externals:this._externals,platform:this._platform}))},n.prototype.createCachedSubscription=function(e){return e="string"==typeof arguments[0]?{cacheKey:arguments[0].toString()}:e||{},new a(s({},e,{externals:this._externals,platform:this._platform,cache:this._cache}))},n.handleLoginRedirect=function(e){var t=window.location.hash?window.location.hash:window.location.search,r={};r[p.authResponseProperty]=t,window.opener.postMessage(r,e||window.location.origin)},e.exports=n},function(e,t){/* +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require(void 0),require(void 0),require(void 0)):"function"==typeof define&&define.amd?define(["pubnub","es6-promise","fetch-ponyfill"],t):"object"==typeof exports?exports.SDK=t(require(void 0),require(void 0),require(void 0)):(e.RingCentral=e.RingCentral||{},e.RingCentral.SDK=t(e[void 0],e[void 0],e[void 0]))}(this,function(e,t,r){return function(e){function t(n){if(r[n])return r[n].exports;var s=r[n]={exports:{},id:n,loaded:!1};return e[n].call(s.exports,s,s.exports,t),s.loaded=!0,s.exports}var r={};return t.m=e,t.c=r,t.p="/build/",t(0)}([function(e,t,r){function n(e){this._externals=new h(e),this._cache=new i({externals:this._externals,prefix:e.cachePrefix}),this._client=new o(this._externals),this._platform=new u(s({},e,{externals:this._externals,client:this._client,cache:this._cache}))}var s=r(1),i=r(2),o=r(3),h=r(11),u=r(15),a=r(18),c=r(19),p=r(17);n.version=p.version,n.server={sandbox:"https://platform.devtest.ringcentral.com",production:"https://platform.ringcentral.com"},n.prototype.platform=function(){return this._platform},n.prototype.cache=function(){return this._cache},n.prototype.createSubscription=function(e){return new a(s({},e,{externals:this._externals,platform:this._platform}))},n.prototype.createCachedSubscription=function(e){return e="string"==typeof arguments[0]?{cacheKey:arguments[0].toString()}:e||{},new c(s({},e,{externals:this._externals,platform:this._platform,cache:this._cache}))},n.handleLoginRedirect=function(e){var t=window.location.hash?window.location.hash:window.location.search,r={};r[p.authResponseProperty]=t,window.opener.postMessage(r,e||window.location.origin)},e.exports=n},function(e,t){/* object-assign (c) Sindre Sorhus @license MIT */ -"use strict";function r(e){if(null===e||void 0===e)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(e)}function n(){try{if(!Object.assign)return!1;var e=new String("abc");if(e[5]="de","5"===Object.getOwnPropertyNames(e)[0])return!1;for(var t={},r=0;r<10;r++)t["_"+String.fromCharCode(r)]=r;var n=Object.getOwnPropertyNames(t).map(function(e){return t[e]});if("0123456789"!==n.join(""))return!1;var s={};return"abcdefghijklmnopqrst".split("").forEach(function(e){s[e]=e}),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},s)).join("")}catch(e){return!1}}var s=Object.getOwnPropertySymbols,i=Object.prototype.hasOwnProperty,o=Object.prototype.propertyIsEnumerable;e.exports=n()?Object.assign:function(e,t){for(var n,h,u=r(e),c=1;c-1?"&":"?")+u.stringify(e.query)),n("Accept",e.headers)||(e.headers.Accept=h._jsonContentType),i(e.body)||!e.body){var t=n(h._contentType,e.headers);t||(t=h._contentType,e.headers[t]=h._jsonContentType);var r=e.headers[t];r.indexOf(h._jsonContentType)>-1?"GET"!==e.method&&"HEAD"!==e.method||!e.body?e.body=JSON.stringify(e.body):e.body=void 0:r.indexOf(h._urlencodedContentType)>-1&&(e.body=u.stringify(e.body))}var o=new this._externals.Request(e.url,e);return o.originalBody=e.body,o},e.exports=s},function(e,t,r){/*! +"use strict";function r(e){if(null===e||void 0===e)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(e)}function n(){try{if(!Object.assign)return!1;var e=new String("abc");if(e[5]="de","5"===Object.getOwnPropertyNames(e)[0])return!1;for(var t={},r=0;r<10;r++)t["_"+String.fromCharCode(r)]=r;var n=Object.getOwnPropertyNames(t).map(function(e){return t[e]});if("0123456789"!==n.join(""))return!1;var s={};return"abcdefghijklmnopqrst".split("").forEach(function(e){s[e]=e}),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},s)).join("")}catch(e){return!1}}var s=Object.getOwnPropertySymbols,i=Object.prototype.hasOwnProperty,o=Object.prototype.propertyIsEnumerable;e.exports=n()?Object.assign:function(e,t){for(var n,h,u=r(e),a=1;a-1?"&":"?")+u.stringify(e.query)),n("Accept",e.headers)||(e.headers.Accept=h._jsonContentType),i(e.body)||!e.body){var t=n(h._contentType,e.headers);t||(t=h._contentType,e.headers[t]=h._jsonContentType);var r=e.headers[t];r.indexOf(h._jsonContentType)>-1?"GET"!==e.method&&"HEAD"!==e.method||!e.body?e.body=JSON.stringify(e.body):e.body=void 0:r.indexOf(h._urlencodedContentType)>-1&&(e.body=u.stringify(e.body))}var o=new this._externals.Request(e.url,e);return o.originalBody=e.body,o},e.exports=s},function(e,t,r){/*! * is-plain-object * * Copyright (c) 2014-2015, Jon Schlinkert. @@ -15,5 +15,5 @@ object-assign * Copyright (c) 2014-2015, Jon Schlinkert. * Licensed under the MIT License. */ -"use strict";e.exports=function(e){return null!=e&&"object"==typeof e&&!Array.isArray(e)}},function(e,t){function r(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function n(e){return"function"==typeof e}function s(e){return"number"==typeof e}function i(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(!s(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,s,h,u,c;if(this._events||(this._events={}),"error"===e&&(!this._events.error||i(this._events.error)&&!this._events.error.length)){if(t=arguments[1],t instanceof Error)throw t;var a=new Error('Uncaught, unspecified "error" event. ('+t+")");throw a.context=t,a}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(i(r))for(h=Array.prototype.slice.call(arguments,1),c=r.slice(),s=c.length,u=0;u0&&this._events[e].length>s&&(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),s||(s=!0,t.apply(this,arguments))}if(!n(t))throw TypeError("listener must be a function");var s=!1;return r.listener=t,this.on(e,r),this},r.prototype.removeListener=function(e,t){var r,s,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,s=-1,r===t||n(r.listener)&&r.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(i(r)){for(h=o;h-- >0;)if(r[h]===t||r[h].listener&&r[h].listener===t){s=h;break}if(s<0)return this;1===r.length?(r.length=0,delete this._events[e]):r.splice(s,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.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=this._getContentType().match(/boundary=([^;]+)/i)[1];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 s=this._create(n.shift(),this._response.status,this._response.statusText).json();this._multipart=n.map(function(e,t){var r=s.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 s=new this._externals.Headers,i=e.split(r._bodySeparator),o=i.length>1?i.shift():"";e=i.length>0?i.join(r._bodySeparator):null,(o||"").split("\n").forEach(function(e){var t=e.trim().split(r._headerSeparator),n=t.shift().trim(),i=t.join(r._headerSeparator).trim();n&&s.append(n,i)});var h=new this._externals.Response(e,{headers:s,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,s){t=t||"&",n=n||"=";var i={};if("string"!=typeof e||0===e.length)return i;var o=/\+/g;e=e.split(t);var h=1e3;s&&"number"==typeof s.maxKeys&&(h=s.maxKeys);var u=e.length;h>0&&u>h&&(u=h);for(var c=0;c=0?(a=d.substr(0,_),p=d.substr(_+1)):(a=d,p=""),l=decodeURIComponent(a),f=decodeURIComponent(p),r(i,l)?Array.isArray(i[l])?i[l].push(f):i[l]=[i[l],f]:i[l]=f}return i}},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,s){return t=t||"&",n=n||"=",null===e&&(e=void 0),"object"==typeof e?Object.keys(e).map(function(s){var i=encodeURIComponent(r(s))+n;return Array.isArray(e[s])?e[s].map(function(e){return i+encodeURIComponent(r(e))}).join(t):i+encodeURIComponent(r(e[s]))}).join(t):s?encodeURIComponent(r(s))+n+encodeURIComponent(r(e)):""}},function(e,t,r){(function(t){function n(e){e=e||{},this.PubNub=e.PubNub||h.PubNub||s,this.localStorage=e.localStorage||("undefined"!=typeof h.localStorage?h.localStorage:{}),this.Promise=e.Promise||h.Promise||i&&i.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 s=r(12),i=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){s.call(this),this.events={beforeLogin:"beforeLogin",loginSuccess:"loginSuccess",loginError:"loginError",beforeRefresh:"beforeRefresh",refreshSuccess:"refreshSuccess",refreshError:"refreshError",beforeLogout:"beforeLogout",logoutSuccess:"logoutSuccess",logoutError:"logoutError"},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._refreshPromise=null,this._auth=new h({cache:this._cache,cacheId:n._cacheId,refreshHandicapMs:e.refreshHandicapMs})}var s=r(6).EventEmitter,i=r(8),o=r(1),h=r(16),u=r(17),c=r(7);n._urlPrefix="/restapi",n._apiVersion="v1.0",n._tokenEndpoint="/restapi/oauth/token",n._revokeEndpoint="/restapi/oauth/revoke",n._authorizeEndpoint="/restapi/oauth/authorize",n._cacheId="platform",n.prototype=Object.create(s.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="",s=e.indexOf("http://")!=-1||e.indexOf("https://")!=-1;return t.addServer&&!s&&(r+=this._server),e.indexOf(n._urlPrefix)!=-1||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+"?"+i.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=i.parse(r);if(!n)throw new Error("Unable to parse response");var s=n.error_description||n.error;if(s){var o=new Error(s);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.url=e.url||400,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,s=void 0!==window.screenTop?window.screenTop:screen.top,i=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=i/2-e.width/2+n,c=o/2-e.height/2+s,a=window.open(e.url,"_blank","_blank"==e.target?"scrollbars=yes, status=yes, width="+e.width+", height="+e.height+", left="+h+", top="+c:"");if(!a)throw new Error("Could not open login window. Please allow popups for this site");a.focus&&a.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;a.close(),window[l](f,d);var s=this.parseLoginRedirect(n.data[e.property]);if(!s.code&&!s.access_token)throw new Error("No authorization code or token");t(s)}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.accessTokenTtl=e.accessTokenTtl),e.refreshTokenTtl&&(r.refreshTokenTtl=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){this.emit(this.events.beforeLogout),e(this._tokenRequest(n._revokeEndpoint,{token:this._auth.accessToken()}))}.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(r){if(!r.apiResponse||!r.apiResponse.response()||r.apiResponse.response().status!=c._unauthorizedStatus||t.retry)throw r;return this._auth.cancelAccessToken(),t.retry=!0,this.sendRequest(e,t)}.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":c._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.1.0";e.exports={version:n,authResponseProperty:"RCAuthorizationResponse"}},function(e,t,r){function n(e){s.call(this),e=e||{},this.events={notification:"notification",removeSuccess:"removeSuccess",removeError:"removeError",renewSuccess:"renewSuccess",renewError:"renewError",subscribeSuccess:"subscribeSuccess",subscribeError:"subscribeError"},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._timeout=null,this._subscription=null}var s=r(6).EventEmitter;n.prototype=Object.create(s.prototype),n.prototype.subscribed=function(){var e=this.subscription();return!!(e.id&&e.deliveryMode&&e.deliveryMode.subscriberKey&&e.deliveryMode.address)},n.prototype.alive=function(){return this.subscribed()&&Date.now()this.subscription().expirationTime)},n.prototype.expirationTime=function(){return new Date(this.subscription().expirationTime||0).getTime()-this._renewHandicapMs},n.prototype.setSubscription=function(e){return e=e||{},this._clearTimeout(),this._setSubscription(e),this._subscribeAtPubnub(),this._setTimeout(),this},n.prototype.subscription=function(){return this._subscription||{}},n.prototype.register=function(){return this.alive()?this.renew():this.subscribe()},n.prototype.eventFilters=function(){return this.subscription().eventFilters||[]},n.prototype.addEventFilters=function(e){return this.setEventFilters(this.eventFilters().concat(e)),this},n.prototype.setEventFilters=function(e){var t=this.subscription();return t.eventFilters=e,this._setSubscription(t),this},n.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))},n.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))},n.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))},n.prototype.resubscribe=function(){var e=this.eventFilters();return this.reset().setEventFilters(e).subscribe()},n.prototype.reset=function(){return this._clearTimeout(),this.subscribed()&&this._pubnub&&this._pubnub.unsubscribe({channel:this.subscription().deliveryMode.address}),this._setSubscription(null),this},n.prototype._setSubscription=function(e){this._subscription=e},n.prototype._getFullEventFilters=function(){return this.eventFilters().map(function(e){return this._platform.createUrl(e)}.bind(this))},n.prototype._setTimeout=function(){if(this._clearTimeout(),!this.alive())throw new Error("Subscription is not alive");return this._timeout=setInterval(function(){this.alive()||(this.expired()?this.subscribe():this.renew())}.bind(this),this._pollInterval),this},n.prototype._clearTimeout=function(){return clearInterval(this._timeout),this},n.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},n.prototype._notify=function(e){return this.emit(this.events.notification,this._decrypt(e)),this},n.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._pubnubLastChannel&&this._pubnub.unsubscribe({channel:this._pubnubLastChannel}),this._pubnub=this._pubnub.init({ssl:!0,subscribe_key:e.subscriberKey})}else this._pubnub=new this._externals.PubNub({ssl:!0,subscribe_key:e.subscriberKey});return this._pubnubLastChannel=e.address,this._pubnub.subscribe({channel:e.address,message:this._notify.bind(this),connect:function(){}}),this},e.exports=n},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,s.call(this,e),this._cache=e.cache,this._subscription=void 0}var s=r(18);n.prototype=Object.create(s.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)}},function(e,t){function r(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function n(e){return"function"==typeof e}function s(e){return"number"==typeof e}function i(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(!s(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,s,h,u,a;if(this._events||(this._events={}),"error"===e&&(!this._events.error||i(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(i(r))for(h=Array.prototype.slice.call(arguments,1),a=r.slice(),s=a.length,u=0;u0&&this._events[e].length>s&&(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),s||(s=!0,t.apply(this,arguments))}if(!n(t))throw TypeError("listener must be a function");var s=!1;return r.listener=t,this.on(e,r),this},r.prototype.removeListener=function(e,t){var r,s,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,s=-1,r===t||n(r.listener)&&r.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(i(r)){for(h=o;h-- >0;)if(r[h]===t||r[h].listener&&r[h].listener===t){s=h;break}if(s<0)return this;1===r.length?(r.length=0,delete this._events[e]):r.splice(s,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.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=this._getContentType().match(/boundary=([^;]+)/i)[1];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 s=this._create(n.shift(),this._response.status,this._response.statusText).json();this._multipart=n.map(function(e,t){var r=s.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 s=new this._externals.Headers,i=e.split(r._bodySeparator),o=i.length>1?i.shift():"";e=i.length>0?i.join(r._bodySeparator):null,(o||"").split("\n").forEach(function(e){var t=e.trim().split(r._headerSeparator),n=t.shift().trim(),i=t.join(r._headerSeparator).trim();n&&s.append(n,i)});var h=new this._externals.Response(e,{headers:s,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,s){t=t||"&",n=n||"=";var i={};if("string"!=typeof e||0===e.length)return i;var o=/\+/g;e=e.split(t);var h=1e3;s&&"number"==typeof s.maxKeys&&(h=s.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(i,l)?Array.isArray(i[l])?i[l].push(f):i[l]=[i[l],f]:i[l]=f}return i}},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,s){return t=t||"&",n=n||"=",null===e&&(e=void 0),"object"==typeof e?Object.keys(e).map(function(s){var i=encodeURIComponent(r(s))+n;return Array.isArray(e[s])?e[s].map(function(e){return i+encodeURIComponent(r(e))}).join(t):i+encodeURIComponent(r(e[s]))}).join(t):s?encodeURIComponent(r(s))+n+encodeURIComponent(r(e)):""}},function(e,t,r){(function(t){function n(e){e=e||{},this.PubNub=e.PubNub||h.PubNub||s,this.localStorage=e.localStorage||("undefined"!=typeof h.localStorage?h.localStorage:{}),this.Promise=e.Promise||h.Promise||i&&i.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 s=r(12),i=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){s.call(this),this.events={beforeLogin:"beforeLogin",loginSuccess:"loginSuccess",loginError:"loginError",beforeRefresh:"beforeRefresh",refreshSuccess:"refreshSuccess",refreshError:"refreshError",beforeLogout:"beforeLogout",logoutSuccess:"logoutSuccess",logoutError:"logoutError"},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._refreshPromise=null,this._auth=new h({cache:this._cache,cacheId:n._cacheId,refreshHandicapMs:e.refreshHandicapMs})}var s=r(6).EventEmitter,i=r(8),o=r(1),h=r(16),u=r(17),a=r(7);n._urlPrefix="/restapi",n._apiVersion="v1.0",n._tokenEndpoint="/restapi/oauth/token",n._revokeEndpoint="/restapi/oauth/revoke",n._authorizeEndpoint="/restapi/oauth/authorize",n._cacheId="platform",n.prototype=Object.create(s.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="",s=e.indexOf("http://")!=-1||e.indexOf("https://")!=-1;return t.addServer&&!s&&(r+=this._server),e.indexOf(n._urlPrefix)!=-1||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+"?"+i.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=i.parse(r);if(!n)throw new Error("Unable to parse response");var s=n.error_description||n.error;if(s){var o=new Error(s);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.url=e.url||400,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,s=void 0!==window.screenTop?window.screenTop:screen.top,i=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=i/2-e.width/2+n,a=o/2-e.height/2+s,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 s=this.parseLoginRedirect(n.data[e.property]);if(!s.code&&!s.access_token)throw new Error("No authorization code or token");t(s)}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.accessTokenTtl=e.accessTokenTtl),e.refreshTokenTtl&&(r.refreshTokenTtl=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){this.emit(this.events.beforeLogout),e(this._tokenRequest(n._revokeEndpoint,{token:this._auth.accessToken()}))}.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(r){if(!r.apiResponse||!r.apiResponse.response()||r.apiResponse.response().status!=a._unauthorizedStatus||t.retry)throw r;return this._auth.cancelAccessToken(),t.retry=!0,this.sendRequest(e,t)}.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.1.0";e.exports={version:n,authResponseProperty:"RCAuthorizationResponse"}},function(e,t,r){function n(e){s.call(this),e=e||{},this.events={notification:"notification",removeSuccess:"removeSuccess",removeError:"removeError",renewSuccess:"renewSuccess",renewError:"renewError",subscribeSuccess:"subscribeSuccess",subscribeError:"subscribeError"},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 s=r(6).EventEmitter;n.prototype=Object.create(s.prototype),n.prototype.subscribed=function(){var e=this.subscription();return!!(e.id&&e.deliveryMode&&e.deliveryMode.subscriberKey&&e.deliveryMode.address)},n.prototype.alive=function(){return this.subscribed()&&Date.now()this.subscription().expirationTime)},n.prototype.expirationTime=function(){return new Date(this.subscription().expirationTime||0).getTime()-this._renewHandicapMs},n.prototype.setSubscription=function(e){return e=e||{},this._clearTimeout(),this._setSubscription(e),this._subscribeAtPubnub(),this._setTimeout(),this},n.prototype.subscription=function(){return this._subscription||{}},n.prototype.register=function(){return this.alive()?this.renew():this.subscribe()},n.prototype.eventFilters=function(){return this.subscription().eventFilters||[]},n.prototype.addEventFilters=function(e){return this.setEventFilters(this.eventFilters().concat(e)),this},n.prototype.setEventFilters=function(e){var t=this.subscription();return t.eventFilters=e,this._setSubscription(t),this},n.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))},n.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))},n.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))},n.prototype.resubscribe=function(){var e=this.eventFilters();return this.reset().setEventFilters(e).subscribe()},n.prototype.reset=function(){return this._clearTimeout(),this._unsubscribeAtPubnub(),this._setSubscription(null),this},n.prototype._setSubscription=function(e){this._subscription=e},n.prototype._getFullEventFilters=function(){return this.eventFilters().map(function(e){return this._platform.createUrl(e)}.bind(this))},n.prototype._setTimeout=function(){if(this._clearTimeout(),!this.alive())throw new Error("Subscription is not alive");return this._timeout=setInterval(function(){this.alive()||(this.expired()?this.subscribe():this.renew())}.bind(this),this._pollInterval),this},n.prototype._clearTimeout=function(){return clearInterval(this._timeout),this},n.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},n.prototype._notify=function(e){return this.emit(this.events.notification,this._decrypt(e)),this},n.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,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},n.prototype._unsubscribeAtPubnub=function(){return!this.subscribed()||this._pubnub?this:(this._pubnub.removeAllListeners(),this._pubnub.destroy(),this._pubnubLastSubscribeKey=null,this._pubnubLastChannel=null,this._pubnub=null,this)},e.exports=n},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,s.call(this,e),this._cache=e.cache,this._subscription=void 0}var s=r(18);n.prototype=Object.create(s.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 f12c7bf1..7acf4ea4 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 c20b2b45729ee57a5332?7780","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","response","window","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","_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","_server","_appKey","appKey","_appSecret","appSecret","_redirectUri","redirectUri","_refreshDelayMs","refreshDelayMs","_clearCacheOnRefreshError","clearCacheOnRefreshError","_userAgent","appName","appVersion","_refreshPromise","_auth","Auth","cacheId","_cacheId","refreshHandicapMs","_urlPrefix","_apiVersion","_tokenEndpoint","_revokeEndpoint","_authorizeEndpoint","delay","timeout","reject","setTimeout","auth","createUrl","path","builtUrl","hasHttp","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","win","open","focus","eventMethod","addEventListener","eventRemoveMethod","messageEvent","eventListener","close","loginOptions","code","access_token","loggedIn","ensureLoggedIn","login","grant_type","username","password","extension","endpointId","endpoint_id","accessTokenTtl","refreshTokenTtl","_tokenRequest","setData","_refresh","refreshToken","refreshTokenValid","refresh_token","access_token_ttl","expires_in","refresh_token_ttl","refresh_token_expires_in","refresh","logout","token","inflateRequest","skipAuthCheck","set","_authHeader","retry","cancelAccessToken","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","notification","removeSuccess","removeError","renewSuccess","renewError","subscribeSuccess","subscribeError","_pollInterval","pollInterval","_renewHandicapMs","renewHandicapMs","_pubnub","_pubnubLastChannel","_timeout","_subscription","subscribed","subscription","deliveryMode","subscriberKey","address","alive","expirationTime","expired","getTime","setSubscription","_clearTimeout","_setSubscription","_subscribeAtPubnub","_setTimeout","register","renew","subscribe","eventFilters","addEventFilters","setEventFilters","concat","_getFullEventFilters","transportType","reset","remove","delete","resubscribe","filters","unsubscribe","channel","event","setInterval","clearInterval","_decrypt","encryptionKey","decrypt","encryptKey","keyEncoding","keyLength","_notify","ssl","subscribe_key","connect","_cacheKey","restore"],"mappings":"CAAA,SAAAA,EAAAC,GACA,gBAAAC,UAAA,gBAAAC,QACAA,OAAAD,QAAAD,EAAAG,QAAAC,QAAAD,QAAAC,QA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AAua,qBAItCva,KAAAsa,QAAAta,KAAAsa,QAAA3R,MACAuU,KAAA,EACAC,cAAAvC,EAAAC,oBAMA7a,MAAAsa,QAAA,GAAAta,MAAAgB,WAAAyP,QACAyM,KAAA,EACAC,cAAAvC,EAAAC,eAaA,OARA7a,MAAAua,mBAAAK,EAAAE,QAEA9a,KAAAsa,QAAAoB,WACAa,QAAA3B,EAAAE,QACAtS,QAAAxI,KAAAid,QAAAnV,KAAA9H,MACAod,QAAA,eAGApd,MAIAL,EAAAD,QAAAoC,GpBmtEM,SAASnC,EAAQD,EAASW,GqBpmFhC,QAAA0B,GAAAhB,GAIA,GAFAA,SAEAA,EAAA2B,SAAA,SAAAwF,OAAA,gEAGAlI,MAAAqd,UAAAtc,EAAA2B,SAEAZ,EAAApB,KAAAV,KAAAe,GAGAf,KAAAkB,OAAAH,EAAAc,MAGA7B,KAAAya,cAAA5a,OA7BA,GAAAiC,GAAAzB,EAAA,GAiCA0B,GAAAM,UAAAqB,OAAA4D,OAAAxF,EAAAO,WAEAN,EAAAM,UAAAsY,aAAA,WACA,MAAA3a,MAAAkB,OAAAgF,QAAAlG,KAAAqd,gBAGAtb,EAAAM,UAAAgZ,iBAAA,SAAAV,GACA,MAAA3a,MAAAkB,OAAAyE,QAAA3F,KAAAqd,UAAA1C,IAQA5Y,EAAAM,UAAAib,QAAA,SAAAxW,GAMA,MAJA9G,MAAA2b,eAAApW,QACAvF,KAAA6b,gBAAA/U,GAGA9G,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) {\n\n var response = window.location.hash ? window.location.hash : window.location.search;\n var msg = {};\n msg[Constants.authResponseProperty] = response;\n window.opener.postMessage(msg, origin || window.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 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-2015, Jon Schlinkert.\n * Licensed 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-2015, Jon Schlinkert.\n * Licensed under the MIT License.\n */\n\n'use strict';\n\nmodule.exports = function isObject(val) {\n return val != null && typeof val === 'object'\n && !Array.isArray(val);\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;\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 = this._getContentType().match(/boundary=([^;]+)/i)[1];\n\n if (!boundary) throw new Error('Cannot find boundary');\n\n var parts = text.toString().split(ApiResponse._boundarySeparator + boundary);\n\n if (parts[0].trim() === '') parts.shift();\n if (parts[parts.length - 1].trim() == ApiResponse._boundarySeparator) parts.pop();\n\n if (parts.length < 1) throw new Error('No parts in body');\n\n // Step 2. Parse status info\n\n var statusInfo = 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 if (!this.fetch || !this.Response || !this.Request || !this.Headers) {\n throw new Error('Fetch API is missing');\n }\n\n if (!this.Promise) {\n throw new Error('Promise is missing');\n }\n\n if (!this.localStorage) {\n throw new Error('LocalStorage is missing');\n }\n\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 };\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._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._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\n if (options.addServer && !hasHttp) builtUrl += this._server;\n\n if (path.indexOf(Platform._urlPrefix) == -1 && !hasHttp) builtUrl += Platform._urlPrefix + '/' + Platform._apiVersion;\n\n builtUrl += path;\n\n if (options.addMethod || options.addToken) builtUrl += (path.indexOf('?') > -1 ? '&' : '?');\n\n if (options.addMethod) builtUrl += '_method=' + options.addMethod;\n if (options.addToken) builtUrl += (options.addMethod ? '&' : '') + 'access_token=' + this._auth.accessToken();\n\n return builtUrl;\n\n};\n\n/**\n * @param {string} [options.redirectUri] 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.url = options.url || 400;\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.accessTokenTtl = options.accessTokenTtl;\n if (options.refreshTokenTtl) body.refreshTokenTtl = 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 resolve(this._tokenRequest(Platform._revokeEndpoint, {\n token: this._auth.accessToken()\n }));\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} [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() ||\n (e.apiResponse.response().status != ApiResponse._unauthorizedStatus) ||\n options.retry) throw e;\n\n this._auth.cancelAccessToken();\n\n options.retry = true;\n\n return this.sendRequest(request, options);\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 * @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 * @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 * @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 * @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 * @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/* 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.1.0\");\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/**\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 };\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._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() > this.subscription().expirationTime;\n};\n\nSubscription.prototype.expirationTime = function() {\n return new Date(this.subscription().expirationTime || 0).getTime() - 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\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\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 if (this.subscribed() && this._pubnub) this._pubnub.unsubscribe({channel: this.subscription().deliveryMode.address});\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()) return;\n\n if (this.expired()) {\n this.subscribe();\n } else {\n this.renew();\n }\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) { // Nothing to update, keep listening to same channel\n return this;\n } else if (this._pubnubLastChannel) { // Need to subscribe to new channel\n this._pubnub.unsubscribe({channel: this._pubnubLastChannel});\n }\n\n // Re-init for new data\n this._pubnub = this._pubnub.init({\n ssl: true,\n subscribe_key: deliveryMode.subscriberKey\n });\n\n } else {\n\n // Init from scratch\n this._pubnub = new this._externals.PubNub({\n ssl: true,\n subscribe_key: deliveryMode.subscriberKey\n });\n\n }\n\n this._pubnubLastChannel = deliveryMode.address;\n\n this._pubnub.subscribe({\n channel: deliveryMode.address,\n message: this._notify.bind(this),\n connect: function() {}\n });\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.613Z\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 c20b2b45729ee57a5332","/**\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) {\n\n var response = window.location.hash ? window.location.hash : window.location.search;\n var msg = {};\n msg[Constants.authResponseProperty] = response;\n window.opener.postMessage(msg, origin || window.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 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-2015, Jon Schlinkert.\n * Licensed 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-2015, Jon Schlinkert.\n * Licensed under the MIT License.\n */\n\n'use strict';\n\nmodule.exports = function isObject(val) {\n return val != null && typeof val === 'object'\n && !Array.isArray(val);\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;\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 = this._getContentType().match(/boundary=([^;]+)/i)[1];\n\n if (!boundary) throw new Error('Cannot find boundary');\n\n var parts = text.toString().split(ApiResponse._boundarySeparator + boundary);\n\n if (parts[0].trim() === '') parts.shift();\n if (parts[parts.length - 1].trim() == ApiResponse._boundarySeparator) parts.pop();\n\n if (parts.length < 1) throw new Error('No parts in body');\n\n // Step 2. Parse status info\n\n var statusInfo = 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 if (!this.fetch || !this.Response || !this.Request || !this.Headers) {\n throw new Error('Fetch API is missing');\n }\n\n if (!this.Promise) {\n throw new Error('Promise is missing');\n }\n\n if (!this.localStorage) {\n throw new Error('LocalStorage is missing');\n }\n\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 };\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._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._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\n if (options.addServer && !hasHttp) builtUrl += this._server;\n\n if (path.indexOf(Platform._urlPrefix) == -1 && !hasHttp) builtUrl += Platform._urlPrefix + '/' + Platform._apiVersion;\n\n builtUrl += path;\n\n if (options.addMethod || options.addToken) builtUrl += (path.indexOf('?') > -1 ? '&' : '?');\n\n if (options.addMethod) builtUrl += '_method=' + options.addMethod;\n if (options.addToken) builtUrl += (options.addMethod ? '&' : '') + 'access_token=' + this._auth.accessToken();\n\n return builtUrl;\n\n};\n\n/**\n * @param {string} [options.redirectUri] 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.url = options.url || 400;\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.accessTokenTtl = options.accessTokenTtl;\n if (options.refreshTokenTtl) body.refreshTokenTtl = 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 resolve(this._tokenRequest(Platform._revokeEndpoint, {\n token: this._auth.accessToken()\n }));\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} [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() ||\n (e.apiResponse.response().status != ApiResponse._unauthorizedStatus) ||\n options.retry) throw e;\n\n this._auth.cancelAccessToken();\n\n options.retry = true;\n\n return this.sendRequest(request, options);\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 * @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 * @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 * @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 * @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 * @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// 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/**\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 };\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._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() > this.subscription().expirationTime;\n};\n\nSubscription.prototype.expirationTime = function() {\n return new Date(this.subscription().expirationTime || 0).getTime() - 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\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\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 if (this.subscribed() && this._pubnub) this._pubnub.unsubscribe({channel: this.subscription().deliveryMode.address});\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()) return;\n\n if (this.expired()) {\n this.subscribe();\n } else {\n this.renew();\n }\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) { // Nothing to update, keep listening to same channel\n return this;\n } else if (this._pubnubLastChannel) { // Need to subscribe to new channel\n this._pubnub.unsubscribe({channel: this._pubnubLastChannel});\n }\n\n // Re-init for new data\n this._pubnub = this._pubnub.init({\n ssl: true,\n subscribe_key: deliveryMode.subscriberKey\n });\n\n } else {\n\n // Init from scratch\n this._pubnub = new this._externals.PubNub({\n ssl: true,\n subscribe_key: deliveryMode.subscriberKey\n });\n\n }\n\n this._pubnubLastChannel = deliveryMode.address;\n\n this._pubnub.subscribe({\n channel: deliveryMode.address,\n message: this._notify.bind(this),\n connect: function() {}\n });\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.613Z\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 10513986e26ef7cdf365?991e","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","response","window","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","_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","_server","_appKey","appKey","_appSecret","appSecret","_redirectUri","redirectUri","_refreshDelayMs","refreshDelayMs","_clearCacheOnRefreshError","clearCacheOnRefreshError","_userAgent","appName","appVersion","_refreshPromise","_auth","Auth","cacheId","_cacheId","refreshHandicapMs","_urlPrefix","_apiVersion","_tokenEndpoint","_revokeEndpoint","_authorizeEndpoint","delay","timeout","reject","setTimeout","auth","createUrl","path","builtUrl","hasHttp","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","win","open","focus","eventMethod","addEventListener","eventRemoveMethod","messageEvent","eventListener","close","loginOptions","code","access_token","loggedIn","ensureLoggedIn","login","grant_type","username","password","extension","endpointId","endpoint_id","accessTokenTtl","refreshTokenTtl","_tokenRequest","setData","_refresh","refreshToken","refreshTokenValid","refresh_token","access_token_ttl","expires_in","refresh_token_ttl","refresh_token_expires_in","refresh","logout","token","inflateRequest","skipAuthCheck","set","_authHeader","retry","cancelAccessToken","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","notification","removeSuccess","removeError","renewSuccess","renewError","subscribeSuccess","subscribeError","_pollInterval","pollInterval","_renewHandicapMs","renewHandicapMs","_pubnub","_pubnubLastChannel","_pubnubLastSubscribeKey","_timeout","_subscription","subscribed","subscription","deliveryMode","subscriberKey","address","alive","expirationTime","expired","getTime","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","subscribeKey","statusEvent","channels","destroy","_cacheKey","restore"],"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,SAAAC,EAAAC,EAAAC,GACD,MCAgB,UAAUC,GCN1B,QAAAC,GAAAC,GAGA,GAAAC,EAAAD,GACA,MAAAC,GAAAD,GAAAZ,OAGA,IAAAC,GAAAY,EAAAD,IACAZ,WACAc,GAAAF,EACAG,QAAA,EAUA,OANAL,GAAAE,GAAAI,KAAAf,EAAAD,QAAAC,IAAAD,QAAAW,GAGAV,EAAAc,QAAA,EAGAd,EAAAD,QAvBA,GAAAa,KAqCA,OATAF,GAAAM,EAAAP,EAGAC,EAAAO,EAAAL,EAGAF,EAAAQ,EAAA,UAGAR,EAAA,KDgBM,SAASV,EAAQD,EAASW,GElBhC,QAAAS,GAAAC,GAGAf,KAAAgB,WAAA,GAAAC,GAAAF,GAGAf,KAAAkB,OAAA,GAAAC,IACAC,UAAApB,KAAAgB,WACAK,OAAAN,EAAAO,cAIAtB,KAAAuB,QAAA,GAAAC,GAAAxB,KAAAgB,YAGAhB,KAAAyB,UAAA,GAAAC,GAAAC,KAAiDZ,GACjDK,UAAApB,KAAAgB,WACAY,OAAA5B,KAAAuB,QACAM,MAAA7B,KAAAkB,UAnDA,GAAAS,GAAAtB,EAAA,GACAc,EAA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gF,QAAAlG,KAAAwd,gBAGAzb,EAAAM,UAAAiZ,iBAAA,SAAAV,GACA,MAAA5a,MAAAkB,OAAAyE,QAAA3F,KAAAwd,UAAA5C,IAQA7Y,EAAAM,UAAAob,QAAA,SAAA3W,GAMA,MAJA9G,MAAA4b,eAAArW,QACAvF,KAAA8b,gBAAAhV,GAGA9G,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) {\n\n var response = window.location.hash ? window.location.hash : window.location.search;\n var msg = {};\n msg[Constants.authResponseProperty] = response;\n window.opener.postMessage(msg, origin || window.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 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-2015, Jon Schlinkert.\n * Licensed 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-2015, Jon Schlinkert.\n * Licensed under the MIT License.\n */\n\n'use strict';\n\nmodule.exports = function isObject(val) {\n return val != null && typeof val === 'object'\n && !Array.isArray(val);\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;\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 = this._getContentType().match(/boundary=([^;]+)/i)[1];\n\n if (!boundary) throw new Error('Cannot find boundary');\n\n var parts = text.toString().split(ApiResponse._boundarySeparator + boundary);\n\n if (parts[0].trim() === '') parts.shift();\n if (parts[parts.length - 1].trim() == ApiResponse._boundarySeparator) parts.pop();\n\n if (parts.length < 1) throw new Error('No parts in body');\n\n // Step 2. Parse status info\n\n var statusInfo = 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 if (!this.fetch || !this.Response || !this.Request || !this.Headers) {\n throw new Error('Fetch API is missing');\n }\n\n if (!this.Promise) {\n throw new Error('Promise is missing');\n }\n\n if (!this.localStorage) {\n throw new Error('LocalStorage is missing');\n }\n\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 };\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._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._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\n if (options.addServer && !hasHttp) builtUrl += this._server;\n\n if (path.indexOf(Platform._urlPrefix) == -1 && !hasHttp) builtUrl += Platform._urlPrefix + '/' + Platform._apiVersion;\n\n builtUrl += path;\n\n if (options.addMethod || options.addToken) builtUrl += (path.indexOf('?') > -1 ? '&' : '?');\n\n if (options.addMethod) builtUrl += '_method=' + options.addMethod;\n if (options.addToken) builtUrl += (options.addMethod ? '&' : '') + 'access_token=' + this._auth.accessToken();\n\n return builtUrl;\n\n};\n\n/**\n * @param {string} [options.redirectUri] 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.url = options.url || 400;\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.accessTokenTtl = options.accessTokenTtl;\n if (options.refreshTokenTtl) body.refreshTokenTtl = 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 resolve(this._tokenRequest(Platform._revokeEndpoint, {\n token: this._auth.accessToken()\n }));\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} [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() ||\n (e.apiResponse.response().status != ApiResponse._unauthorizedStatus) ||\n options.retry) throw e;\n\n this._auth.cancelAccessToken();\n\n options.retry = true;\n\n return this.sendRequest(request, options);\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 * @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 * @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 * @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 * @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 * @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/* 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.1.0\");\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/**\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 };\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() > this.subscription().expirationTime;\n};\n\nSubscription.prototype.expirationTime = function() {\n return new Date(this.subscription().expirationTime || 0).getTime() - 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\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\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()) return;\n\n if (this.expired()) {\n this.subscribe();\n } else {\n this.renew();\n }\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 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.613Z\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 10513986e26ef7cdf365","/**\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) {\n\n var response = window.location.hash ? window.location.hash : window.location.search;\n var msg = {};\n msg[Constants.authResponseProperty] = response;\n window.opener.postMessage(msg, origin || window.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 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-2015, Jon Schlinkert.\n * Licensed 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-2015, Jon Schlinkert.\n * Licensed under the MIT License.\n */\n\n'use strict';\n\nmodule.exports = function isObject(val) {\n return val != null && typeof val === 'object'\n && !Array.isArray(val);\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;\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 = this._getContentType().match(/boundary=([^;]+)/i)[1];\n\n if (!boundary) throw new Error('Cannot find boundary');\n\n var parts = text.toString().split(ApiResponse._boundarySeparator + boundary);\n\n if (parts[0].trim() === '') parts.shift();\n if (parts[parts.length - 1].trim() == ApiResponse._boundarySeparator) parts.pop();\n\n if (parts.length < 1) throw new Error('No parts in body');\n\n // Step 2. Parse status info\n\n var statusInfo = 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 if (!this.fetch || !this.Response || !this.Request || !this.Headers) {\n throw new Error('Fetch API is missing');\n }\n\n if (!this.Promise) {\n throw new Error('Promise is missing');\n }\n\n if (!this.localStorage) {\n throw new Error('LocalStorage is missing');\n }\n\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 };\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._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._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\n if (options.addServer && !hasHttp) builtUrl += this._server;\n\n if (path.indexOf(Platform._urlPrefix) == -1 && !hasHttp) builtUrl += Platform._urlPrefix + '/' + Platform._apiVersion;\n\n builtUrl += path;\n\n if (options.addMethod || options.addToken) builtUrl += (path.indexOf('?') > -1 ? '&' : '?');\n\n if (options.addMethod) builtUrl += '_method=' + options.addMethod;\n if (options.addToken) builtUrl += (options.addMethod ? '&' : '') + 'access_token=' + this._auth.accessToken();\n\n return builtUrl;\n\n};\n\n/**\n * @param {string} [options.redirectUri] 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.url = options.url || 400;\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.accessTokenTtl = options.accessTokenTtl;\n if (options.refreshTokenTtl) body.refreshTokenTtl = 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 resolve(this._tokenRequest(Platform._revokeEndpoint, {\n token: this._auth.accessToken()\n }));\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} [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() ||\n (e.apiResponse.response().status != ApiResponse._unauthorizedStatus) ||\n options.retry) throw e;\n\n this._auth.cancelAccessToken();\n\n options.retry = true;\n\n return this.sendRequest(request, options);\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 * @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 * @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 * @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 * @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 * @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// 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/**\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 };\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() > this.subscription().expirationTime;\n};\n\nSubscription.prototype.expirationTime = function() {\n return new Date(this.subscription().expirationTime || 0).getTime() - 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\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\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()) return;\n\n if (this.expired()) {\n this.subscribe();\n } else {\n this.renew();\n }\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 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.613Z\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 e2cf56d2..34267cdc 100644 --- a/demo/apiKey.html +++ b/demo/apiKey.html @@ -74,9 +74,9 @@

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