{"version":3,"sources":["webpack:///view-selector2.js","webpack:///webpack/bootstrap 0853746ae09c5b7c1eb6?7fc4*","webpack:///./src/javascript/embed-api/components/view-selector2.js","webpack:///./~/javascript-api-utils/lib/account-summaries/index.js","webpack:///./~/javascript-api-utils/lib/account-summaries/account-summaries.js"],"names":["modules","__webpack_require__","moduleId","installedModules","exports","module","id","loaded","call","m","c","p","_interopRequireDefault","obj","__esModule","default","_javascriptApiUtilsLibAccountSummaries","_javascriptApiUtilsLibAccountSummaries2","gapi","analytics","ready","updateSelect","select","options","innerHTML","map","option","selected","name","join","getIdProp","opts","ids","viewId","prop","value","replace","propertyId","accountId","createComponent","execute","this","setup_","updateAccounts_","changed_","render_","onChange_","bind","set","Error","container","prevOpts","get","Component","prototype","cb","onAuthorize","then","summaries","self","accounts","all","err","emit","auth","isAuthorized","on","view","account","property","getProfile","getAccountByProfileId","getWebPropertyByProfileId","getWebProperty","getAccountByWebPropertyId","views","getAccount","properties","slice","document","getElementById","template","selects","querySelectorAll","onchange","onUserSelect_","props","data","requestAccountSummaries","promise","client","request","path","API_PATH","resp","constructor","resolve","reject","fn","result","items","concat","startIndex","itemsPerPage","totalResults","params","start-index","AccountSummaries","cache","noCache","accounts_","webProperties_","profiles_","accountsById_","webPropertiesById_","propertiesById_","profilesById_","viewsById_","i","webProperties","alias","webProperty","j","push","parent","profiles","profile","k","grandParent","object","referenceProp","aliasName","Object","defineProperty","allWebProperties","allProfiles","webPropertyId","profileId"],"mappings":"CAAS,SAAUA,GCInB,QAAAC,GAAAC,GAGA,GAAAC,EAAAD,GACA,MAAAC,GAAAD,GAAAE,OAGA,IAAAC,GAAAF,EAAAD,IACAE,WACAE,GAAAJ,EACAK,QAAA,EAUA,OANAP,GAAAE,GAAAM,KAAAH,EAAAD,QAAAC,IAAAD,QAAAH,GAGAI,EAAAE,QAAA,EAGAF,EAAAD,QAvBA,GAAAD,KAqCA,OATAF,GAAAQ,EAAAT,EAGAC,EAAAS,EAAAP,EAGAF,EAAAU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WAAAzD,EAAA4H,WAAA5H,EAAAoB,SACAQ,KAAAgC,eAAA5D,EAAA2H,eAAA3H,EAAAwB,aACAI,KAAAmC,WAAA/D,EAAAyB,YASAqE,EAAArD,UAAAsB,WAAA,SAAAtC,GACA,MAAAG,MAAAwE,cAAA3E,IACAG,KAAAwE,cAAA3E,GAAAqB,MASAgD,EAAArD,UAAAmB,eAAA,SAAA+D,GACA,MAAA/F,MAAAyE,mBAAAsB,IACA/F,KAAAyE,mBAAAsB,GAAA7E,MAGA6D,EAAAb,EAAArD,UAAA,iBACA,eAQAqD,EAAArD,UAAAgB,WAAA,SAAAmE,GACA,MAAAhG,MAAA2E,cAAAqB,IACAhG,KAAA2E,cAAAqB,GAAA9E,MAGA6D,EAAAb,EAAArD,UAAA,aACA,WAQAqD,EAAArD,UAAAiB,sBAAA,SAAAkE,GACA,MAAAhG,MAAA2E,cAAAqB,IACAhG,KAAA2E,cAAAqB,GAAAT,aAIAR,EAAAb,EAAArD,UAAA,wBACA,sBASAqD,EAAArD,UAAAkB,0BAAA,SAAAiE,GACA,MAAAhG,MAAA2E,cAAAqB,IACAhG,KAAA2E,cAAAqB,GAAAb,QAGAJ,EAAAb,EAAArD,UAAA,4BACA,uBAQAqD,EAAArD,UAAAoB,0BAAA,SAAA8D,GACA,MAAA/F,MAAAyE,mBAAAsB,IACA/F,KAAAyE,mBAAAsB,GAAAZ,QAGAJ,EAAAb,EAAArD,UAAA,4BACA,0BAwBAjD,EAAAD,QAAAuG","file":"view-selector2.js","sourcesContent":["/******/ (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 = \"\";\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\t// Copyright 2014 Google Inc. All rights reserved.\n\t//\n\t// Licensed under the Apache License, Version 2.0 (the \"License\");\n\t// you may not use this file except in compliance with the License.\n\t// You may obtain a copy of the License at\n\t//\n\t// http://www.apache.org/licenses/LICENSE-2.0\n\t//\n\t// Unless required by applicable law or agreed to in writing, software\n\t// distributed under the License is distributed on an \"AS IS\" BASIS,\n\t// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n\t// See the License for the specific language governing permissions and\n\t// limitations under the License.\n\t\n\t/* global gapi */\n\t\n\t'use strict';\n\t\n\tfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }\n\t\n\tvar _javascriptApiUtilsLibAccountSummaries = __webpack_require__(1);\n\t\n\tvar _javascriptApiUtilsLibAccountSummaries2 = _interopRequireDefault(_javascriptApiUtilsLibAccountSummaries);\n\t\n\t/**\n\t * A ViewSelector2 component for the Embed API.\n\t */\n\tgapi.analytics.ready(function () {\n\t\n\t gapi.analytics.createComponent('ViewSelector2', {\n\t\n\t /**\n\t * Render the view selector instance on the page or update an existing\n\t * instance if any options have changed.\n\t * @return {ViewSelector2} The instance.\n\t */\n\t execute: function execute() {\n\t this.setup_((function () {\n\t this.updateAccounts_();\n\t if (this.changed_) {\n\t this.render_();\n\t this.onChange_();\n\t }\n\t }).bind(this));\n\t\n\t return this;\n\t },\n\t\n\t /**\n\t * Extend the base `set` function with some error checking and handling of\n\t * ID data.\n\t * @extends gapi.analytics.Component.prototype.set\n\t * @param {Object} opts The options to set.\n\t * @return {ViewSelector2}\n\t */\n\t set: function set(opts) {\n\t\n\t if (!!opts.ids + !!opts.viewId + !!opts.propertyId + !!opts.accountId > 1) {\n\t\n\t throw new Error('You cannot specify more than one of the following ' + 'options: \"ids\", \"viewId\", \"accountId\", \"propertyId\"');\n\t }\n\t\n\t if (opts.container && this.container) {\n\t throw new Error('You cannot change containers once a view selector ' + 'has been rendered on the page.');\n\t }\n\t\n\t var prevOpts = this.get();\n\t\n\t if (prevOpts.ids != opts.ids || prevOpts.viewId != opts.viewId || prevOpts.propertyId != opts.propertyId || prevOpts.accountId != opts.accountId) {\n\t\n\t // If new ID data is being set, first unset all existing ID data.\n\t // This prevents the problem where you set an account ID then set a\n\t // view ID for a new view in a different account. Both IDs should not\n\t // persist or there will be problems.\n\t prevOpts.ids = null;\n\t prevOpts.viewId = null;\n\t prevOpts.propertyId = null;\n\t prevOpts.accountId = null;\n\t }\n\t\n\t // Call super.\n\t return gapi.analytics.Component.prototype.set.call(this, opts);\n\t },\n\t\n\t /**\n\t * Set up the view selector instance with values from the Management API's\n\t * accountSummaries.list method via the `accountSummaries` module.\n\t * If the user has not authorized, wait until that happens before\n\t * requesting the account summaries.\n\t * @param {Function} cb A function to be invoked once authorization has\n\t * succeeded and the accountSummaries have been retrieved.\n\t */\n\t setup_: function setup_(cb) {\n\t var self = this;\n\t\n\t function onAuthorize() {\n\t _javascriptApiUtilsLibAccountSummaries2['default'].get().then(function (summaries) {\n\t self.summaries = summaries;\n\t self.accounts = self.summaries.all();\n\t cb();\n\t }, function (err) {\n\t self.emit('error', err);\n\t });\n\t }\n\t\n\t if (gapi.analytics.auth.isAuthorized()) {\n\t onAuthorize();\n\t } else {\n\t gapi.analytics.auth.on('success', onAuthorize);\n\t }\n\t },\n\t\n\t /**\n\t * Update the view selector instance properties with new account\n\t * information.\n\t * @throws {Error} If the user has set an ID value for an account they\n\t * don't have access to.\n\t */\n\t updateAccounts_: function updateAccounts_() {\n\t\n\t var opts = this.get();\n\t var ids = getIdProp(opts);\n\t var view, account, property;\n\t\n\t // If there are no id props, set the defaults.\n\t if (!ids) {\n\t account = this.accounts[0];\n\t property = account && account.properties && account.properties[0];\n\t view = property && property.views && property.views[0];\n\t } else {\n\t switch (ids.prop) {\n\t case 'viewId':\n\t view = this.summaries.getProfile(ids.value);\n\t account = this.summaries.getAccountByProfileId(ids.value);\n\t property = this.summaries.getWebPropertyByProfileId(ids.value);\n\t break;\n\t case 'propertyId':\n\t property = this.summaries.getWebProperty(ids.value);\n\t account = this.summaries.getAccountByWebPropertyId(ids.value);\n\t view = property && property.views && property.views[0];\n\t break;\n\t case 'accountId':\n\t account = this.summaries.getAccount(ids.value);\n\t property = account && account.properties && account.properties[0];\n\t view = property && property.views && property.views[0];\n\t break;\n\t }\n\t }\n\t\n\t if (account || property || view) {\n\t\n\t // Only update if something has changed.\n\t if (account != this.account || property != this.property || view != this.view) {\n\t\n\t // Store what value changed.\n\t this.changed_ = {\n\t account: account && account != this.account,\n\t property: property && property != this.property,\n\t view: view && view != this.view\n\t };\n\t\n\t this.account = account;\n\t this.properties = account.properties;\n\t this.property = property;\n\t this.views = property && property.views;\n\t this.view = view;\n\t this.ids = view && 'ga:' + view.id;\n\t }\n\t } else {\n\t this.emit('error', new Error('You do not have access to ' + ids.prop.slice(0, -2) + ' : ' + ids.value));\n\t }\n\t },\n\t\n\t /**\n\t * Render the view selector based on the users accounts and the\n\t * pre-defined template. Also add event handlers to watch for\n\t * changes.\n\t */\n\t render_: function render_() {\n\t\n\t var opts = this.get();\n\t\n\t this.container = typeof opts.container == 'string' ? document.getElementById(opts.container) : opts.container;\n\t\n\t this.container.innerHTML = opts.template || this.template;\n\t var selects = this.container.querySelectorAll('select');\n\t\n\t var accounts = this.accounts;\n\t var properties = this.properties || [{ name: '(Empty)', id: '' }];\n\t var views = this.views || [{ name: '(Empty)', id: '' }];\n\t\n\t updateSelect(selects[0], accounts, this.account.id);\n\t updateSelect(selects[1], properties, this.property && this.property.id);\n\t updateSelect(selects[2], views, this.view && this.view.id);\n\t\n\t selects[0].onchange = this.onUserSelect_.bind(this, selects[0], 'accountId');\n\t selects[1].onchange = this.onUserSelect_.bind(this, selects[1], 'propertyId');\n\t selects[2].onchange = this.onUserSelect_.bind(this, selects[2], 'viewId');\n\t },\n\t\n\t /**\n\t * A callback that is invoked from the `execute` method whenever the ID\n\t * data has changed. Most of the time this change happens when the user\n\t * has selected a new view in the UI, but it can also happen\n\t * programmatically via the `set` method.\n\t */\n\t onChange_: function onChange_() {\n\t\n\t var props = {\n\t account: this.account,\n\t property: this.property,\n\t view: this.view,\n\t ids: this.view && 'ga:' + this.view.id\n\t };\n\t\n\t if (this.changed_) {\n\t if (this.changed_.account) this.emit('accountChange', props);\n\t if (this.changed_.property) this.emit('propertyChange', props);\n\t if (this.changed_.view) {\n\t this.emit('viewChange', props);\n\t this.emit('idsChange', props);\n\t\n\t // For backwards compatibility with the original ViewSelector.\n\t this.emit('change', props.ids);\n\t }\n\t }\n\t\n\t this.changed_ = null;\n\t },\n\t\n\t /**\n\t * The handler assigned to the `onchange` method of each of the select\n\t * elements. The context is bound to the view selector instance and it is\n\t * invoked with the element and property as its arguments.\n\t * @param {HTMLSelectElement} select The select element.\n\t * @param {string} property The property key to be set on the instance.\n\t */\n\t onUserSelect_: function onUserSelect_(select, property) {\n\t var data = {};\n\t data[property] = select.value;\n\t\n\t this.set(data);\n\t this.execute();\n\t },\n\t\n\t /**\n\t * The html structure used to build the component. Developers can override\n\t * this by passing it to the component constructor. The only requirement\n\t * is that the structure contain three selects. The first will be the\n\t * account select, the second will be the property select, and the third\n\t * will be the view select. Order is important.\n\t */\n\t template: '
' + '
' + ' ' + ' ' + '
' + '
' + ' ' + ' ' + '
' + '
' + ' ' + ' ' + '
' + '
'\n\t });\n\t\n\t /**\n\t * Update a select with the specified options and optionally choose the\n\t * selected option based on the matching ID.\n\t * @param {HTMLSelectElement} select The select element to update.\n\t * @param {Array} options An Array of objects with the keys\n\t * `name` and `id`.\n\t * @param {string} [id] An optional value used to determine the selected\n\t * option.\n\t */\n\t function updateSelect(select, options, id) {\n\t select.innerHTML = options.map(function (option) {\n\t var selected = option.id == id ? 'selected ' : ' ';\n\t return '';\n\t }).join('');\n\t }\n\t\n\t /**\n\t * Given an options object containing a single key that could be either\n\t * \"ids\", \"viewId\", \"propertyId\", or \"accountId\", return a new object\n\t * specifying that key in its `prop` property. If the passed property is\n\t * \"ids\" convert it to \"viewId\".\n\t * @param {Object} opts An options object.\n\t * @return {Object} An object specifying what ID property and value were\n\t * passed.\n\t */\n\t function getIdProp(opts) {\n\t if (opts.ids || opts.viewId) {\n\t return { prop: 'viewId', value: opts.viewId || opts.ids && opts.ids.replace(/^ga:/, '') };\n\t } else if (opts.propertyId) {\n\t return { prop: 'propertyId', value: opts.propertyId };\n\t } else if (opts.accountId) {\n\t return { prop: 'accountId', value: opts.accountId };\n\t }\n\t }\n\t});\n\n/***/ },\n/* 1 */\n/***/ function(module, exports, __webpack_require__) {\n\n\t// Copyright 2015 Google Inc. All rights reserved.\n\t//\n\t// Licensed under the Apache License, Version 2.0 (the \"License\");\n\t// you may not use this file except in compliance with the License.\n\t// You may obtain a copy of the License at\n\t//\n\t// http://www.apache.org/licenses/LICENSE-2.0\n\t//\n\t// Unless required by applicable law or agreed to in writing, software\n\t// distributed under the License is distributed on an \"AS IS\" BASIS,\n\t// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n\t// See the License for the specific language governing permissions and\n\t// limitations under the License.\n\t\n\t\n\t/* global gapi */\n\t\n\tvar AccountSummaries = __webpack_require__(2);\n\t\n\t\n\tvar API_PATH = '/analytics/v3/management/accountSummaries';\n\t\n\t\n\t/**\n\t * Store the accountSummaries result in a promise so the API isn't\n\t * queried unneccesarily.\n\t */\n\tvar cache;\n\t\n\t\n\t/**\n\t * Make a request to the Management API's accountSummaries#list method.\n\t * If the requests returns a partial, paginated response, query again\n\t * until the full summaries are retrieved.\n\t * @return {goog.Promise} A promise that will be resolved with an\n\t * AccountSummaries instance.\n\t */\n\tfunction requestAccountSummaries() {\n\t\n\t var promise = gapi.client.request({path: API_PATH})\n\t // An extra `then` is needed here because `.list` doesn't return a\n\t // \"real\" promise, just a thenable. Calling `.then` gets us access\n\t // to the underlying goog.Promise instance and thus its constructor.\n\t .then(function(resp) { return resp; });\n\t\n\t return new promise.constructor(function(resolve, reject) {\n\t\n\t // Store the summaries array in the closure so multiple requests can\n\t // concat to it.\n\t var summaries = [];\n\t\n\t promise.then(function fn(resp) {\n\t var result = resp.result;\n\t if (result.items) {\n\t summaries = summaries.concat(result.items);\n\t }\n\t else {\n\t reject(new Error('You do not have any Google Analytics accounts. ' +\n\t 'Go to http://google.com/analytics to sign up.'));\n\t }\n\t\n\t if (result.startIndex + result.itemsPerPage <= result.totalResults) {\n\t gapi.client.request({\n\t path: API_PATH,\n\t params: {\n\t 'start-index': result.startIndex + result.itemsPerPage\n\t }\n\t })\n\t // Recursively call this function until the full results are in.\n\t .then(fn);\n\t }\n\t else {\n\t resolve(new AccountSummaries(summaries));\n\t }\n\t })\n\t // Reject the promise if there are any uncaught errors;\n\t .then(null, reject);\n\t });\n\t}\n\t\n\t\n\t/**\n\t * @module accountSummaries\n\t *\n\t * This module requires the `gapi.client` library to be loaded on the page\n\t * and the user to be authenticated.\n\t */\n\tmodule.exports = {\n\t\n\t /**\n\t * Return the `requestAccountSummaries` promise. If the promise exists,\n\t * return it to avoid multiple requests. If the promise does not exist,\n\t * initiate the request and cache the promise.\n\t *\n\t * @param {boolean} noCache When true make a request no matter what.\n\t * @return {goog.Promise} A promise fulfilled with an AccountSummaries\n\t * instance.\n\t */\n\t get: function(noCache) {\n\t if (noCache) cache = null;\n\t return cache || (cache = requestAccountSummaries());\n\t }\n\t};\n\n\n/***/ },\n/* 2 */\n/***/ function(module, exports, __webpack_require__) {\n\n\t// Copyright 2015 Google Inc. All rights reserved.\n\t//\n\t// Licensed under the Apache License, Version 2.0 (the \"License\");\n\t// you may not use this file except in compliance with the License.\n\t// You may obtain a copy of the License at\n\t//\n\t// http://www.apache.org/licenses/LICENSE-2.0\n\t//\n\t// Unless required by applicable law or agreed to in writing, software\n\t// distributed under the License is distributed on an \"AS IS\" BASIS,\n\t// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n\t// See the License for the specific language governing permissions and\n\t// limitations under the License.\n\t\n\t\n\t/**\n\t * @constuctor AccountSummaries\n\t *\n\t * Takes an array of accounts and writes the following new properties:\n\t * `accounts_`, `webProperties_`, `profiles_`, `accountsById_`,\n\t * `webPropertiesById_`, and `profilesById_`.\n\t * Each of the ___ById properties contains an array of objects where the\n\t * key is the entity ID and the value is an object containing the entity and\n\t * the entity's parents. For example, an object in the `profilesById_` array\n\t * might look like this:\n\t * {\n\t * \"1234\": {\n\t * self: {...},\n\t * parent: {...},\n\t * grandParent: {...}\n\t * }\n\t * }\n\t *\n\t * It also aliases the properties `webProperties` to `properties` and\n\t * `profiles` to `views` within the `accounts` array tree.\n\t\n\t * @param {Array} accounts A list of accounts in the format returned by the\n\t * management API's accountSummaries#list method.\n\t * @returns {AccountSummaries}\n\t */\n\tfunction AccountSummaries(accounts) {\n\t\n\t this.accounts_ = accounts;\n\t this.webProperties_ = [];\n\t this.profiles_ = [];\n\t\n\t this.accountsById_ = {};\n\t this.webPropertiesById_ = this.propertiesById_ = {};\n\t this.profilesById_ = this.viewsById_ = {};\n\t\n\t for (var i = 0, account; account = this.accounts_[i]; i++) {\n\t\n\t this.accountsById_[account.id] = {\n\t self: account\n\t };\n\t\n\t if (!account.webProperties) continue;\n\t\n\t // Add aliases.\n\t alias(account, 'webProperties', 'properties');\n\t\n\t for (var j = 0, webProperty; webProperty = account.webProperties[j]; j++) {\n\t\n\t this.webProperties_.push(webProperty);\n\t this.webPropertiesById_[webProperty.id] = {\n\t self: webProperty,\n\t parent: account\n\t };\n\t\n\t if (!webProperty.profiles) continue;\n\t\n\t // Add aliases.\n\t alias(webProperty, 'profiles', 'views');\n\t\n\t for (var k = 0, profile; profile = webProperty.profiles[k]; k++) {\n\t\n\t this.profiles_.push(profile);\n\t this.profilesById_[profile.id] = {\n\t self: profile,\n\t parent: webProperty,\n\t grandParent: account\n\t };\n\t }\n\t }\n\t }\n\t}\n\t\n\t\n\t/**\n\t * Return a list of all accounts this user has access to.\n\t * Since the accounts contain the web properties and the web properties contain\n\t * the profiles, this list contains everything.\n\t * @return {Array}\n\t */\n\tAccountSummaries.prototype.all = function() {\n\t return this.accounts_;\n\t};\n\t\n\talias(AccountSummaries.prototype, 'all',\n\t 'allAccounts');\n\t\n\t\n\t/**\n\t * Return a list of all web properties this user has access to.\n\t * @return {Array}\n\t */\n\tAccountSummaries.prototype.allWebProperties = function() {\n\t return this.webProperties_;\n\t};\n\t\n\talias(AccountSummaries.prototype, 'allWebProperties',\n\t 'allProperties');\n\t\n\t\n\t/**\n\t * Return a list of all profiles this user has access to.\n\t * @return {Array}\n\t */\n\tAccountSummaries.prototype.allProfiles = function() {\n\t return this.profiles_;\n\t};\n\t\n\talias(AccountSummaries.prototype, 'allProfiles',\n\t 'allViews');\n\t\n\t\n\t/**\n\t * Returns an account, web property or profile given the passed ID in the\n\t * `idData` object. The ID data object can contain only one of the\n\t * following properties: \"accountId\", \"webPropertyId\", \"propertyId\",\n\t * \"profileId\", or \"viewId\". If more than one key is passed, an error is\n\t * thrown.\n\t *\n\t * @param {Object} obj An object with no more than one of the following\n\t * keys: \"accountId\", \"webPropertyId\", \"propertyId\", \"profileId\" or\n\t * \"viewId\".\n\t * @return {Object|undefined} The matching account, web property, or\n\t * profile. If none are found, undefined is returned.\n\t */\n\tAccountSummaries.prototype.get = function(obj) {\n\t if (!!obj.accountId +\n\t !!obj.webPropertyId +\n\t !!obj.propertyId +\n\t !!obj.profileId +\n\t !!obj.viewId > 1) {\n\t\n\t throw new Error('get() only accepts an object with a single ' +\n\t 'property: either \"accountId\", \"webPropertyId\", \"propertyId\", ' +\n\t '\"profileId\" or \"viewId\"');\n\t }\n\t return this.getProfile(obj.profileId || obj.viewId) ||\n\t this.getWebProperty(obj.webPropertyId || obj.propertyId) ||\n\t this.getAccount(obj.accountId);\n\t};\n\t\n\t\n\t/**\n\t * Get an account given its ID.\n\t * @param {string|number} accountId\n\t * @return {Object} The account with the given ID.\n\t */\n\tAccountSummaries.prototype.getAccount = function(accountId) {\n\t return this.accountsById_[accountId] &&\n\t this.accountsById_[accountId].self;\n\t};\n\t\n\t\n\t/**\n\t * Get a web property given its ID.\n\t * @param {string} webPropertyId\n\t * @return {Object} The web property with the given ID.\n\t */\n\tAccountSummaries.prototype.getWebProperty = function(webPropertyId) {\n\t return this.webPropertiesById_[webPropertyId] &&\n\t this.webPropertiesById_[webPropertyId].self;\n\t};\n\t\n\talias(AccountSummaries.prototype, 'getWebProperty',\n\t 'getProperty');\n\t\n\t\n\t/**\n\t * Get a profile given its ID.\n\t * @param {string|number} profileId\n\t * @return {Object} The profile with the given ID.\n\t */\n\tAccountSummaries.prototype.getProfile = function(profileId) {\n\t return this.profilesById_[profileId] &&\n\t this.profilesById_[profileId].self;\n\t};\n\t\n\talias(AccountSummaries.prototype, 'getProfile',\n\t 'getView');\n\t\n\t\n\t/**\n\t * Get an account given the ID of one of its profiles.\n\t * @param {string|number} profileId\n\t * @return {Object} The account containing this profile.\n\t */\n\tAccountSummaries.prototype.getAccountByProfileId = function(profileId) {\n\t return this.profilesById_[profileId] &&\n\t this.profilesById_[profileId].grandParent;\n\t};\n\t\n\t\n\talias(AccountSummaries.prototype, 'getAccountByProfileId',\n\t 'getAccountByViewId');\n\t\n\t\n\t\n\t/**\n\t * Get a web property given the ID of one of its profile.\n\t * @param {string|number} profileId\n\t * @return {Object} The web property containing this profile.\n\t */\n\tAccountSummaries.prototype.getWebPropertyByProfileId = function(profileId) {\n\t return this.profilesById_[profileId] &&\n\t this.profilesById_[profileId].parent;\n\t};\n\t\n\talias(AccountSummaries.prototype, 'getWebPropertyByProfileId',\n\t 'getPropertyByViewId');\n\t\n\t\n\t/**\n\t * Get an account given the ID of one of its web properties.\n\t * @param {string|number} webPropertyId\n\t * @return {Object} The account containing this web property.\n\t */\n\tAccountSummaries.prototype.getAccountByWebPropertyId = function(webPropertyId) {\n\t return this.webPropertiesById_[webPropertyId] &&\n\t this.webPropertiesById_[webPropertyId].parent;\n\t};\n\t\n\talias(AccountSummaries.prototype, 'getAccountByWebPropertyId',\n\t 'getAccountByPropertyId');\n\t\n\t\n\t/**\n\t * Alias a property of an object using es5 getters. If es5 getters are not\n\t * supported, just add the aliased property directly to the object.\n\t * @param {Object} object The object for which you want to alias properties.\n\t * @param {string} referenceProp The reference property.\n\t * @param {string} aliasName The reference property's alias name.\n\t */\n\tfunction alias(object, referenceProp, aliasName) {\n\t if (Object.defineProperty) {\n\t Object.defineProperty(object, aliasName, {\n\t get: function() {\n\t return object[referenceProp];\n\t }\n\t });\n\t }\n\t else {\n\t object[aliasName] = object[referenceProp];\n\t }\n\t}\n\t\n\t\n\tmodule.exports = AccountSummaries;\n\n\n/***/ }\n/******/ ]);\n\n\n/** WEBPACK FOOTER **\n ** view-selector2.js\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 = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(0);\n\n\n\n/** WEBPACK FOOTER **\n ** webpack/bootstrap 0853746ae09c5b7c1eb6\n **/","// Copyright 2014 Google Inc. All rights reserved.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n\n/* global gapi */\n\nimport accountSummaries from 'javascript-api-utils/lib/account-summaries';\n\n/**\n * A ViewSelector2 component for the Embed API.\n */\ngapi.analytics.ready(function() {\n\n gapi.analytics.createComponent('ViewSelector2', {\n\n /**\n * Render the view selector instance on the page or update an existing\n * instance if any options have changed.\n * @return {ViewSelector2} The instance.\n */\n execute: function() {\n this.setup_(function() {\n this.updateAccounts_();\n if (this.changed_) {\n this.render_();\n this.onChange_();\n }\n }.bind(this));\n\n return this;\n },\n\n /**\n * Extend the base `set` function with some error checking and handling of\n * ID data.\n * @extends gapi.analytics.Component.prototype.set\n * @param {Object} opts The options to set.\n * @return {ViewSelector2}\n */\n set: function(opts) {\n\n if (!!opts.ids +\n !!opts.viewId +\n !!opts.propertyId +\n !!opts.accountId > 1) {\n\n throw new Error('You cannot specify more than one of the following ' +\n 'options: \"ids\", \"viewId\", \"accountId\", \"propertyId\"');\n }\n\n if (opts.container && this.container) {\n throw new Error('You cannot change containers once a view selector ' +\n 'has been rendered on the page.');\n }\n\n var prevOpts = this.get();\n\n if (prevOpts.ids != opts.ids ||\n prevOpts.viewId != opts.viewId ||\n prevOpts.propertyId != opts.propertyId ||\n prevOpts.accountId != opts.accountId) {\n\n // If new ID data is being set, first unset all existing ID data.\n // This prevents the problem where you set an account ID then set a\n // view ID for a new view in a different account. Both IDs should not\n // persist or there will be problems.\n prevOpts.ids = null;\n prevOpts.viewId = null;\n prevOpts.propertyId = null;\n prevOpts.accountId = null;\n }\n\n // Call super.\n return gapi.analytics.Component.prototype.set.call(this, opts);\n },\n\n /**\n * Set up the view selector instance with values from the Management API's\n * accountSummaries.list method via the `accountSummaries` module.\n * If the user has not authorized, wait until that happens before\n * requesting the account summaries.\n * @param {Function} cb A function to be invoked once authorization has\n * succeeded and the accountSummaries have been retrieved.\n */\n setup_: function(cb) {\n var self = this;\n\n function onAuthorize() {\n accountSummaries.get().then(\n function(summaries) {\n self.summaries = summaries;\n self.accounts = self.summaries.all();\n cb();\n },\n function(err) {\n self.emit('error', err);\n }\n );\n }\n\n if (gapi.analytics.auth.isAuthorized()) {\n onAuthorize();\n }\n else {\n gapi.analytics.auth.on('success', onAuthorize);\n }\n },\n\n /**\n * Update the view selector instance properties with new account\n * information.\n * @throws {Error} If the user has set an ID value for an account they\n * don't have access to.\n */\n updateAccounts_: function() {\n\n var opts = this.get();\n var ids = getIdProp(opts);\n var view, account, property;\n\n // If there are no id props, set the defaults.\n if (!ids) {\n account = this.accounts[0];\n property = account && account.properties && account.properties[0];\n view = property && property.views && property.views[0];\n }\n else {\n switch (ids.prop) {\n case 'viewId':\n view = this.summaries.getProfile(ids.value);\n account = this.summaries.getAccountByProfileId(ids.value);\n property = this.summaries.getWebPropertyByProfileId(ids.value);\n break;\n case 'propertyId':\n property = this.summaries.getWebProperty(ids.value);\n account = this.summaries.getAccountByWebPropertyId(ids.value);\n view = property && property.views && property.views[0];\n break;\n case 'accountId':\n account = this.summaries.getAccount(ids.value);\n property = account && account.properties && account.properties[0];\n view = property && property.views && property.views[0];\n break;\n }\n }\n\n if (account || property || view) {\n\n // Only update if something has changed.\n if (account != this.account ||\n property != this.property ||\n view != this.view) {\n\n // Store what value changed.\n this.changed_ = {\n account: account && account != this.account,\n property: property && property != this.property,\n view: view && view != this.view\n };\n\n this.account = account;\n this.properties = account.properties;\n this.property = property;\n this.views = property && property.views;\n this.view = view;\n this.ids = view && 'ga:' + view.id;\n }\n }\n else {\n this.emit('error', new Error('You do not have access to ' +\n ids.prop.slice(0, -2) + ' : ' + ids.value));\n }\n },\n\n /**\n * Render the view selector based on the users accounts and the\n * pre-defined template. Also add event handlers to watch for\n * changes.\n */\n render_: function() {\n\n var opts = this.get();\n\n this.container = typeof opts.container == 'string' ?\n document.getElementById(opts.container) : opts.container;\n\n this.container.innerHTML = opts.template || this.template;\n var selects = this.container.querySelectorAll('select');\n\n var accounts = this.accounts;\n var properties = this.properties || [{name: '(Empty)', id: ''}];\n var views = this.views || [{name: '(Empty)', id: ''}];\n\n updateSelect(selects[0], accounts, this.account.id);\n updateSelect(selects[1], properties, this.property && this.property.id);\n updateSelect(selects[2], views, this.view && this.view.id);\n\n selects[0].onchange =\n this.onUserSelect_.bind(this, selects[0], 'accountId');\n selects[1].onchange =\n this.onUserSelect_.bind(this, selects[1], 'propertyId');\n selects[2].onchange =\n this.onUserSelect_.bind(this, selects[2], 'viewId');\n },\n\n /**\n * A callback that is invoked from the `execute` method whenever the ID\n * data has changed. Most of the time this change happens when the user\n * has selected a new view in the UI, but it can also happen\n * programmatically via the `set` method.\n */\n onChange_: function() {\n\n var props = {\n account: this.account,\n property: this.property,\n view: this.view,\n ids: this.view && 'ga:' + this.view.id\n };\n\n if (this.changed_) {\n if (this.changed_.account) this.emit('accountChange', props);\n if (this.changed_.property) this.emit('propertyChange', props);\n if (this.changed_.view) {\n this.emit('viewChange', props);\n this.emit('idsChange', props);\n\n // For backwards compatibility with the original ViewSelector.\n this.emit('change', props.ids);\n }\n }\n\n this.changed_ = null;\n },\n\n /**\n * The handler assigned to the `onchange` method of each of the select\n * elements. The context is bound to the view selector instance and it is\n * invoked with the element and property as its arguments.\n * @param {HTMLSelectElement} select The select element.\n * @param {string} property The property key to be set on the instance.\n */\n onUserSelect_: function(select, property) {\n var data = {};\n data[property] = select.value;\n\n this.set(data);\n this.execute();\n },\n\n /**\n * The html structure used to build the component. Developers can override\n * this by passing it to the component constructor. The only requirement\n * is that the structure contain three selects. The first will be the\n * account select, the second will be the property select, and the third\n * will be the view select. Order is important.\n */\n template:\n '
' +\n '
' +\n ' ' +\n ' ' +\n '
' +\n '
' +\n ' ' +\n ' ' +\n '
' +\n '
' +\n ' ' +\n ' ' +\n '
' +\n '
'\n });\n\n\n /**\n * Update a select with the specified options and optionally choose the\n * selected option based on the matching ID.\n * @param {HTMLSelectElement} select The select element to update.\n * @param {Array} options An Array of objects with the keys\n * `name` and `id`.\n * @param {string} [id] An optional value used to determine the selected\n * option.\n */\n function updateSelect(select, options, id) {\n select.innerHTML = options.map(function(option) {\n var selected = option.id == id ? 'selected ' : ' ';\n return '';\n }).join('');\n }\n\n\n /**\n * Given an options object containing a single key that could be either\n * \"ids\", \"viewId\", \"propertyId\", or \"accountId\", return a new object\n * specifying that key in its `prop` property. If the passed property is\n * \"ids\" convert it to \"viewId\".\n * @param {Object} opts An options object.\n * @return {Object} An object specifying what ID property and value were\n * passed.\n */\n function getIdProp(opts) {\n if (opts.ids || opts.viewId) {\n return {prop: 'viewId', value: opts.viewId ||\n (opts.ids && opts.ids.replace(/^ga:/, ''))};\n }\n else if (opts.propertyId) {\n return {prop: 'propertyId', value: opts.propertyId};\n }\n else if (opts.accountId) {\n return {prop: 'accountId', value: opts.accountId};\n }\n }\n\n});\n\n\n\n/** WEBPACK FOOTER **\n ** ./src/javascript/embed-api/components/view-selector2.js\n **/","// Copyright 2015 Google Inc. All rights reserved.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n\n/* global gapi */\n\nvar AccountSummaries = require('./account-summaries');\n\n\nvar API_PATH = '/analytics/v3/management/accountSummaries';\n\n\n/**\n * Store the accountSummaries result in a promise so the API isn't\n * queried unneccesarily.\n */\nvar cache;\n\n\n/**\n * Make a request to the Management API's accountSummaries#list method.\n * If the requests returns a partial, paginated response, query again\n * until the full summaries are retrieved.\n * @return {goog.Promise} A promise that will be resolved with an\n * AccountSummaries instance.\n */\nfunction requestAccountSummaries() {\n\n var promise = gapi.client.request({path: API_PATH})\n // An extra `then` is needed here because `.list` doesn't return a\n // \"real\" promise, just a thenable. Calling `.then` gets us access\n // to the underlying goog.Promise instance and thus its constructor.\n .then(function(resp) { return resp; });\n\n return new promise.constructor(function(resolve, reject) {\n\n // Store the summaries array in the closure so multiple requests can\n // concat to it.\n var summaries = [];\n\n promise.then(function fn(resp) {\n var result = resp.result;\n if (result.items) {\n summaries = summaries.concat(result.items);\n }\n else {\n reject(new Error('You do not have any Google Analytics accounts. ' +\n 'Go to http://google.com/analytics to sign up.'));\n }\n\n if (result.startIndex + result.itemsPerPage <= result.totalResults) {\n gapi.client.request({\n path: API_PATH,\n params: {\n 'start-index': result.startIndex + result.itemsPerPage\n }\n })\n // Recursively call this function until the full results are in.\n .then(fn);\n }\n else {\n resolve(new AccountSummaries(summaries));\n }\n })\n // Reject the promise if there are any uncaught errors;\n .then(null, reject);\n });\n}\n\n\n/**\n * @module accountSummaries\n *\n * This module requires the `gapi.client` library to be loaded on the page\n * and the user to be authenticated.\n */\nmodule.exports = {\n\n /**\n * Return the `requestAccountSummaries` promise. If the promise exists,\n * return it to avoid multiple requests. If the promise does not exist,\n * initiate the request and cache the promise.\n *\n * @param {boolean} noCache When true make a request no matter what.\n * @return {goog.Promise} A promise fulfilled with an AccountSummaries\n * instance.\n */\n get: function(noCache) {\n if (noCache) cache = null;\n return cache || (cache = requestAccountSummaries());\n }\n};\n\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./~/javascript-api-utils/lib/account-summaries/index.js\n ** module id = 1\n ** module chunks = 2\n **/","// Copyright 2015 Google Inc. All rights reserved.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n\n/**\n * @constuctor AccountSummaries\n *\n * Takes an array of accounts and writes the following new properties:\n * `accounts_`, `webProperties_`, `profiles_`, `accountsById_`,\n * `webPropertiesById_`, and `profilesById_`.\n * Each of the ___ById properties contains an array of objects where the\n * key is the entity ID and the value is an object containing the entity and\n * the entity's parents. For example, an object in the `profilesById_` array\n * might look like this:\n * {\n * \"1234\": {\n * self: {...},\n * parent: {...},\n * grandParent: {...}\n * }\n * }\n *\n * It also aliases the properties `webProperties` to `properties` and\n * `profiles` to `views` within the `accounts` array tree.\n\n * @param {Array} accounts A list of accounts in the format returned by the\n * management API's accountSummaries#list method.\n * @returns {AccountSummaries}\n */\nfunction AccountSummaries(accounts) {\n\n this.accounts_ = accounts;\n this.webProperties_ = [];\n this.profiles_ = [];\n\n this.accountsById_ = {};\n this.webPropertiesById_ = this.propertiesById_ = {};\n this.profilesById_ = this.viewsById_ = {};\n\n for (var i = 0, account; account = this.accounts_[i]; i++) {\n\n this.accountsById_[account.id] = {\n self: account\n };\n\n if (!account.webProperties) continue;\n\n // Add aliases.\n alias(account, 'webProperties', 'properties');\n\n for (var j = 0, webProperty; webProperty = account.webProperties[j]; j++) {\n\n this.webProperties_.push(webProperty);\n this.webPropertiesById_[webProperty.id] = {\n self: webProperty,\n parent: account\n };\n\n if (!webProperty.profiles) continue;\n\n // Add aliases.\n alias(webProperty, 'profiles', 'views');\n\n for (var k = 0, profile; profile = webProperty.profiles[k]; k++) {\n\n this.profiles_.push(profile);\n this.profilesById_[profile.id] = {\n self: profile,\n parent: webProperty,\n grandParent: account\n };\n }\n }\n }\n}\n\n\n/**\n * Return a list of all accounts this user has access to.\n * Since the accounts contain the web properties and the web properties contain\n * the profiles, this list contains everything.\n * @return {Array}\n */\nAccountSummaries.prototype.all = function() {\n return this.accounts_;\n};\n\nalias(AccountSummaries.prototype, 'all',\n 'allAccounts');\n\n\n/**\n * Return a list of all web properties this user has access to.\n * @return {Array}\n */\nAccountSummaries.prototype.allWebProperties = function() {\n return this.webProperties_;\n};\n\nalias(AccountSummaries.prototype, 'allWebProperties',\n 'allProperties');\n\n\n/**\n * Return a list of all profiles this user has access to.\n * @return {Array}\n */\nAccountSummaries.prototype.allProfiles = function() {\n return this.profiles_;\n};\n\nalias(AccountSummaries.prototype, 'allProfiles',\n 'allViews');\n\n\n/**\n * Returns an account, web property or profile given the passed ID in the\n * `idData` object. The ID data object can contain only one of the\n * following properties: \"accountId\", \"webPropertyId\", \"propertyId\",\n * \"profileId\", or \"viewId\". If more than one key is passed, an error is\n * thrown.\n *\n * @param {Object} obj An object with no more than one of the following\n * keys: \"accountId\", \"webPropertyId\", \"propertyId\", \"profileId\" or\n * \"viewId\".\n * @return {Object|undefined} The matching account, web property, or\n * profile. If none are found, undefined is returned.\n */\nAccountSummaries.prototype.get = function(obj) {\n if (!!obj.accountId +\n !!obj.webPropertyId +\n !!obj.propertyId +\n !!obj.profileId +\n !!obj.viewId > 1) {\n\n throw new Error('get() only accepts an object with a single ' +\n 'property: either \"accountId\", \"webPropertyId\", \"propertyId\", ' +\n '\"profileId\" or \"viewId\"');\n }\n return this.getProfile(obj.profileId || obj.viewId) ||\n this.getWebProperty(obj.webPropertyId || obj.propertyId) ||\n this.getAccount(obj.accountId);\n};\n\n\n/**\n * Get an account given its ID.\n * @param {string|number} accountId\n * @return {Object} The account with the given ID.\n */\nAccountSummaries.prototype.getAccount = function(accountId) {\n return this.accountsById_[accountId] &&\n this.accountsById_[accountId].self;\n};\n\n\n/**\n * Get a web property given its ID.\n * @param {string} webPropertyId\n * @return {Object} The web property with the given ID.\n */\nAccountSummaries.prototype.getWebProperty = function(webPropertyId) {\n return this.webPropertiesById_[webPropertyId] &&\n this.webPropertiesById_[webPropertyId].self;\n};\n\nalias(AccountSummaries.prototype, 'getWebProperty',\n 'getProperty');\n\n\n/**\n * Get a profile given its ID.\n * @param {string|number} profileId\n * @return {Object} The profile with the given ID.\n */\nAccountSummaries.prototype.getProfile = function(profileId) {\n return this.profilesById_[profileId] &&\n this.profilesById_[profileId].self;\n};\n\nalias(AccountSummaries.prototype, 'getProfile',\n 'getView');\n\n\n/**\n * Get an account given the ID of one of its profiles.\n * @param {string|number} profileId\n * @return {Object} The account containing this profile.\n */\nAccountSummaries.prototype.getAccountByProfileId = function(profileId) {\n return this.profilesById_[profileId] &&\n this.profilesById_[profileId].grandParent;\n};\n\n\nalias(AccountSummaries.prototype, 'getAccountByProfileId',\n 'getAccountByViewId');\n\n\n\n/**\n * Get a web property given the ID of one of its profile.\n * @param {string|number} profileId\n * @return {Object} The web property containing this profile.\n */\nAccountSummaries.prototype.getWebPropertyByProfileId = function(profileId) {\n return this.profilesById_[profileId] &&\n this.profilesById_[profileId].parent;\n};\n\nalias(AccountSummaries.prototype, 'getWebPropertyByProfileId',\n 'getPropertyByViewId');\n\n\n/**\n * Get an account given the ID of one of its web properties.\n * @param {string|number} webPropertyId\n * @return {Object} The account containing this web property.\n */\nAccountSummaries.prototype.getAccountByWebPropertyId = function(webPropertyId) {\n return this.webPropertiesById_[webPropertyId] &&\n this.webPropertiesById_[webPropertyId].parent;\n};\n\nalias(AccountSummaries.prototype, 'getAccountByWebPropertyId',\n 'getAccountByPropertyId');\n\n\n/**\n * Alias a property of an object using es5 getters. If es5 getters are not\n * supported, just add the aliased property directly to the object.\n * @param {Object} object The object for which you want to alias properties.\n * @param {string} referenceProp The reference property.\n * @param {string} aliasName The reference property's alias name.\n */\nfunction alias(object, referenceProp, aliasName) {\n if (Object.defineProperty) {\n Object.defineProperty(object, aliasName, {\n get: function() {\n return object[referenceProp];\n }\n });\n }\n else {\n object[aliasName] = object[referenceProp];\n }\n}\n\n\nmodule.exports = AccountSummaries;\n\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./~/javascript-api-utils/lib/account-summaries/account-summaries.js\n ** module id = 2\n ** module chunks = 2\n **/"],"sourceRoot":""}