!function e(t,n,r){function i(a,s){if(!n[a]){if(!t[a]){var u="function"==typeof require&&require;if(!s&&u)return u(a,!0);if(o)return o(a,!0);var c=new Error("Cannot find module '"+a+"'");throw c.code="MODULE_NOT_FOUND",c}var l=n[a]={exports:{}};t[a][0].call(l.exports,function(e){var n=t[a][1][e];return i(n?n:e)},l,l.exports,e,t,n,r)}return n[a].exports}for(var o="function"==typeof require&&require,a=0;a<r.length;a++)i(r[a]);return i}({1:[function(e,t,n){!function(e,r){"function"==typeof define&&define.amd?define([],r):"object"==typeof n?t.exports=r():e.returnExports=r()}(this,function(){function e(i,o){if("function"!=typeof o)throw new Error("Bad callback given: "+o);if(!i)throw new Error("No options given");var s=i.onResponse;if(i="string"==typeof i?{uri:i}:JSON.parse(JSON.stringify(i)),i.onResponse=s,i.verbose&&(e.log=r()),i.url&&(i.uri=i.url,delete i.url),!i.uri&&""!==i.uri)throw new Error("options.uri is a required argument");if("string"!=typeof i.uri)throw new Error("options.uri must be a string");for(var u=["proxy","_redirectsFollowed","maxRedirects","followRedirect"],c=0;c<u.length;c++)if(i[u[c]])throw new Error("options."+u[c]+" is not supported");if(i.callback=o,i.method=i.method||"GET",i.headers=i.headers||{},i.body=i.body||null,i.timeout=i.timeout||e.DEFAULT_TIMEOUT,i.headers.host)throw new Error("Options.headers.host is not supported");i.json&&(i.headers.accept=i.headers.accept||"application/json","GET"!==i.method&&(i.headers["content-type"]="application/json"),"boolean"!=typeof i.json?i.body=JSON.stringify(i.json):"string"!=typeof i.body&&(i.body=JSON.stringify(i.body)));var l=function(e){var t=[];for(var n in e)e.hasOwnProperty(n)&&t.push(encodeURIComponent(n)+"="+encodeURIComponent(e[n]));return t.join("&")};if(i.qs){var f="string"==typeof i.qs?i.qs:l(i.qs);-1!==i.uri.indexOf("?")?i.uri=i.uri+"&"+f:i.uri=i.uri+"?"+f}var d=function(e){var t={};t.boundry="-------------------------------"+Math.floor(1e9*Math.random());var n=[];for(var r in e)e.hasOwnProperty(r)&&n.push("--"+t.boundry+'\nContent-Disposition: form-data; name="'+r+'"\n\n'+e[r]+"\n");return n.push("--"+t.boundry+"--"),t.body=n.join(""),t.length=t.body.length,t.type="multipart/form-data; boundary="+t.boundry,t};if(i.form){if("string"==typeof i.form)throw"form name unsupported";if("POST"===i.method){var h=(i.encoding||"application/x-www-form-urlencoded").toLowerCase();switch(i.headers["content-type"]=h,h){case"application/x-www-form-urlencoded":i.body=l(i.form).replace(/%20/g,"+");break;case"multipart/form-data":var p=d(i.form);i.body=p.body,i.headers["content-type"]=p.type;break;default:throw new Error("unsupported encoding:"+h)}}}return i.onResponse=i.onResponse||n,i.onResponse===!0&&(i.onResponse=o,i.callback=n),!i.headers.authorization&&i.auth&&(i.headers.authorization="Basic "+a(i.auth.username+":"+i.auth.password)),t(i)}function t(t){function n(){f=!0;var n=new Error("ETIMEDOUT");return n.code="ETIMEDOUT",n.duration=t.timeout,e.log.error("Timeout",{id:l._id,milliseconds:t.timeout}),t.callback(n,l)}function r(n){if(f)return e.log.debug("Ignoring timed out state change",{state:l.readyState,id:l.id});if(e.log.debug("State change",{state:l.readyState,id:l.id,timed_out:f}),l.readyState===s.OPENED){e.log.debug("Request started",{id:l.id});for(var r in t.headers)l.setRequestHeader(r,t.headers[r])}else l.readyState===s.HEADERS_RECEIVED?i():l.readyState===s.LOADING?(i(),a()):l.readyState===s.DONE&&(i(),a(),u())}function i(){if(!g.response){if(g.response=!0,e.log.debug("Got response",{id:l.id,status:l.status}),clearTimeout(l.timeoutTimer),l.statusCode=l.status,d&&0==l.statusCode){var n=new Error("CORS request rejected: "+t.uri);return n.cors="rejected",g.loading=!0,g.end=!0,t.callback(n,l)}t.onResponse(null,l)}}function a(){g.loading||(g.loading=!0,e.log.debug("Response body loading",{id:l.id}))}function u(){if(!g.end){if(g.end=!0,e.log.debug("Request done",{id:l.id}),l.body=l.responseText,t.json)try{l.body=JSON.parse(l.responseText)}catch(n){return t.callback(n,l)}t.callback(null,l,l.body)}}var l=new s,f=!1,d=o(t.uri),h="withCredentials"in l;if(c+=1,l.seq_id=c,l.id=c+": "+t.method+" "+t.uri,l._id=l.id,d&&!h){var p=new Error("Browser does not support cross-origin request: "+t.uri);return p.cors="unsupported",t.callback(p,l)}l.timeoutTimer=setTimeout(n,t.timeout);var g={response:!1,loading:!1,end:!1};return l.onreadystatechange=r,l.open(t.method,t.uri,!0),d&&(l.withCredentials=!!t.withCredentials),l.send(t.body),l}function n(){}function r(){var e,t,r={},o=["trace","debug","info","warn","error"];for(t=0;t<o.length;t++)e=o[t],r[e]=n,"undefined"!=typeof console&&console&&console[e]&&(r[e]=i(console,e));return r}function i(e,t){function n(n,r){return"object"==typeof r&&(n+=" "+JSON.stringify(r)),e[t].call(e,n)}return n}function o(e){var t,n=/^([\w\+\.\-]+:)(?:\/\/([^\/?#:]*)(?::(\d+))?)?/;try{t=location.href}catch(r){t=document.createElement("a"),t.href="",t=t.href}var i=n.exec(t.toLowerCase())||[],o=n.exec(e.toLowerCase()),a=!(!o||o[1]==i[1]&&o[2]==i[2]&&(o[3]||("http:"===o[1]?80:443))==(i[3]||("http:"===i[1]?80:443)));return a}function a(e){var t,n,r,i,o,a,s,u,c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",l=0,f=0,d="",h=[];if(!e)return e;do t=e.charCodeAt(l++),n=e.charCodeAt(l++),r=e.charCodeAt(l++),u=t<<16|n<<8|r,i=u>>18&63,o=u>>12&63,a=u>>6&63,s=63&u,h[f++]=c.charAt(i)+c.charAt(o)+c.charAt(a)+c.charAt(s);while(l<e.length);switch(d=h.join(""),e.length%3){case 1:d=d.slice(0,-2)+"==";break;case 2:d=d.slice(0,-1)+"="}return d}var s=XMLHttpRequest;if(!s)throw new Error("missing XMLHttpRequest");e.log={trace:n,debug:n,info:n,warn:n,error:n};var u=18e4,c=0;e.withCredentials=!1,e.DEFAULT_TIMEOUT=u,e.defaults=function(t,n){var r=function(e){var n=function(n,r){n="string"==typeof n?{uri:n}:JSON.parse(JSON.stringify(n));for(var i in t)void 0===n[i]&&(n[i]=t[i]);return e(n,r)};return n},i=r(e);return i.get=r(e.get),i.post=r(e.post),i.put=r(e.put),i.head=r(e.head),i};var l=["get","put","post","head"];return l.forEach(function(t){var n=t.toUpperCase(),r=t.toLowerCase();e[r]=function(t){"string"==typeof t?t={method:n,uri:t}:(t=JSON.parse(JSON.stringify(t)),t.method=n);var r=[t].concat(Array.prototype.slice.apply(arguments,[1]));return e.apply(this,r)}}),e.couch=function(t,r){function i(e,t,n){if(e)return r(e,t,n);if((t.statusCode<200||t.statusCode>299)&&n.error){e=new Error("CouchDB error: "+(n.error.reason||n.error.error));for(var i in n)e[i]=n[i];return r(e,t,n)}return r(e,t,n)}"string"==typeof t&&(t={uri:t}),t.json=!0,t.body&&(t.json=t.body),delete t.body,r=r||n;var o=e(t,i);return o},e})},{}],2:[function(e,t,n){function r(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function i(e){return"function"==typeof e}function o(e){return"number"==typeof e}function a(e){return"object"==typeof e&&null!==e}function s(e){return void 0===e}t.exports=r,r.EventEmitter=r,r.prototype._events=void 0,r.prototype._maxListeners=void 0,r.defaultMaxListeners=10,r.prototype.setMaxListeners=function(e){if(!o(e)||0>e||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},r.prototype.emit=function(e){var t,n,r,o,u,c;if(this._events||(this._events={}),"error"===e&&(!this._events.error||a(this._events.error)&&!this._events.error.length)){if(t=arguments[1],t instanceof Error)throw t;throw TypeError('Uncaught, unspecified "error" event.')}if(n=this._events[e],s(n))return!1;if(i(n))switch(arguments.length){case 1:n.call(this);break;case 2:n.call(this,arguments[1]);break;case 3:n.call(this,arguments[1],arguments[2]);break;default:for(r=arguments.length,o=new Array(r-1),u=1;r>u;u++)o[u-1]=arguments[u];n.apply(this,o)}else if(a(n)){for(r=arguments.length,o=new Array(r-1),u=1;r>u;u++)o[u-1]=arguments[u];for(c=n.slice(),r=c.length,u=0;r>u;u++)c[u].apply(this,o)}return!0},r.prototype.addListener=function(e,t){var n;if(!i(t))throw TypeError("listener must be a function");if(this._events||(this._events={}),this._events.newListener&&this.emit("newListener",e,i(t.listener)?t.listener:t),this._events[e]?a(this._events[e])?this._events[e].push(t):this._events[e]=[this._events[e],t]:this._events[e]=t,a(this._events[e])&&!this._events[e].warned){var n;n=s(this._maxListeners)?r.defaultMaxListeners:this._maxListeners,n&&n>0&&this._events[e].length>n&&(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())}return this},r.prototype.on=r.prototype.addListener,r.prototype.once=function(e,t){function n(){this.removeListener(e,n),r||(r=!0,t.apply(this,arguments))}if(!i(t))throw TypeError("listener must be a function");var r=!1;return n.listener=t,this.on(e,n),this},r.prototype.removeListener=function(e,t){var n,r,o,s;if(!i(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(n=this._events[e],o=n.length,r=-1,n===t||i(n.listener)&&n.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(a(n)){for(s=o;s-->0;)if(n[s]===t||n[s].listener&&n[s].listener===t){r=s;break}if(0>r)return this;1===n.length?(n.length=0,delete this._events[e]):n.splice(r,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},r.prototype.removeAllListeners=function(e){var t,n;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(n=this._events[e],i(n))this.removeListener(e,n);else for(;n.length;)this.removeListener(e,n[n.length-1]);return delete this._events[e],this},r.prototype.listeners=function(e){var t;return t=this._events&&this._events[e]?i(this._events[e])?[this._events[e]]:this._events[e].slice():[]},r.listenerCount=function(e,t){var n;return n=e._events&&e._events[t]?i(e._events[t])?1:e._events[t].length:0}},{}],3:[function(e,t,n){function r(){l=!1,s.length?c=s.concat(c):f=-1,c.length&&i()}function i(){if(!l){var e=setTimeout(r);l=!0;for(var t=c.length;t;){for(s=c,c=[];++f<t;)s&&s[f].run();f=-1,t=c.length}s=null,l=!1,clearTimeout(e)}}function o(e,t){this.fun=e,this.array=t}function a(){}var s,u=t.exports={},c=[],l=!1,f=-1;u.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)t[n-1]=arguments[n];c.push(new o(e,t)),1!==c.length||l||setTimeout(i,0)},o.prototype.run=function(){this.fun.apply(null,this.array)},u.title="browser",u.browser=!0,u.env={},u.argv=[],u.version="",u.versions={},u.on=a,u.addListener=a,u.once=a,u.off=a,u.removeListener=a,u.removeAllListeners=a,u.emit=a,u.binding=function(e){throw new Error("process.binding is not supported")},u.cwd=function(){return"/"},u.chdir=function(e){throw new Error("process.chdir is not supported")},u.umask=function(){return 0}},{}],4:[function(e,t,n){(function(n,r){(function(){"use strict";function i(e){return"function"==typeof e||"object"==typeof e&&null!==e}function o(e){return"function"==typeof e}function a(e){return"object"==typeof e&&null!==e}function s(e){V=e}function u(e){Y=e}function c(){return function(){n.nextTick(p)}}function l(){return function(){z(p)}}function f(){var e=0,t=new W(p),n=document.createTextNode("");return t.observe(n,{characterData:!0}),function(){n.data=e=++e%2}}function d(){var e=new MessageChannel;return e.port1.onmessage=p,function(){e.port2.postMessage(0)}}function h(){return function(){setTimeout(p,1)}}function p(){for(var e=0;B>e;e+=2){var t=te[e],n=te[e+1];t(n),te[e]=void 0,te[e+1]=void 0}B=0}function g(){try{var t=e,n=t("vertx");return z=n.runOnLoop||n.runOnContext,l()}catch(r){return h()}}function v(){}function y(){return new TypeError("You cannot resolve a promise with itself")}function _(){return new TypeError("A promises callback cannot return that same promise.")}function k(e){try{return e.then}catch(t){return oe.error=t,oe}}function m(e,t,n,r){try{e.call(t,n,r)}catch(i){return i}}function b(e,t,n){Y(function(e){var r=!1,i=m(n,t,function(n){r||(r=!0,t!==n?I(e,n):S(e,n))},function(t){r||(r=!0,C(e,t))},"Settle: "+(e._label||" unknown promise"));!r&&i&&(r=!0,C(e,i))},e)}function w(e,t){t._state===re?S(e,t._result):t._state===ie?C(e,t._result):j(t,void 0,function(t){I(e,t)},function(t){C(e,t)})}function P(e,t){if(t.constructor===e.constructor)w(e,t);else{var n=k(t);n===oe?C(e,oe.error):void 0===n?S(e,t):o(n)?b(e,t,n):S(e,t)}}function I(e,t){e===t?C(e,y()):i(t)?P(e,t):S(e,t)}function T(e){e._onerror&&e._onerror(e._result),O(e)}function S(e,t){e._state===ne&&(e._result=t,e._state=re,0!==e._subscribers.length&&Y(O,e))}function C(e,t){e._state===ne&&(e._state=ie,e._result=t,Y(T,e))}function j(e,t,n,r){var i=e._subscribers,o=i.length;e._onerror=null,i[o]=t,i[o+re]=n,i[o+ie]=r,0===o&&e._state&&Y(O,e)}function O(e){var t=e._subscribers,n=e._state;if(0!==t.length){for(var r,i,o=e._result,a=0;a<t.length;a+=3)r=t[a],i=t[a+n],r?x(n,r,i,o):i(o);e._subscribers.length=0}}function E(){this.error=null}function R(e,t){try{return e(t)}catch(n){return ae.error=n,ae}}function x(e,t,n,r){var i,a,s,u,c=o(n);if(c){if(i=R(n,r),i===ae?(u=!0,a=i.error,i=null):s=!0,t===i)return void C(t,_())}else i=r,s=!0;t._state!==ne||(c&&s?I(t,i):u?C(t,a):e===re?S(t,i):e===ie&&C(t,i))}function A(e,t){try{t(function(t){I(e,t)},function(t){C(e,t)})}catch(n){C(e,n)}}function D(e,t){var n=this;n._instanceConstructor=e,n.promise=new e(v),n._validateInput(t)?(n._input=t,n.length=t.length,n._remaining=t.length,n._init(),0===n.length?S(n.promise,n._result):(n.length=n.length||0,n._enumerate(),0===n._remaining&&S(n.promise,n._result))):C(n.promise,n._validationError())}function L(e){return new se(this,e).promise}function N(e){function t(e){I(i,e)}function n(e){C(i,e)}var r=this,i=new r(v);if(!K(e))return C(i,new TypeError("You must pass an array to race.")),i;for(var o=e.length,a=0;i._state===ne&&o>a;a++)j(r.resolve(e[a]),void 0,t,n);return i}function q(e){var t=this;if(e&&"object"==typeof e&&e.constructor===t)return e;var n=new t(v);return I(n,e),n}function M(e){var t=this,n=new t(v);return C(n,e),n}function U(){throw new TypeError("You must pass a resolver function as the first argument to the promise constructor")}function $(){throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.")}function G(e){this._id=de++,this._state=void 0,this._result=void 0,this._subscribers=[],v!==e&&(o(e)||U(),this instanceof G||$(),A(this,e))}function F(){var e;if("undefined"!=typeof r)e=r;else if("undefined"!=typeof self)e=self;else try{e=Function("return this")()}catch(t){throw new Error("polyfill failed because global object is unavailable in this environment")}var n=e.Promise;(!n||"[object Promise]"!==Object.prototype.toString.call(n.resolve())||n.cast)&&(e.Promise=he)}var J;J=Array.isArray?Array.isArray:function(e){return"[object Array]"===Object.prototype.toString.call(e)};var z,V,H,K=J,B=0,Y=({}.toString,function(e,t){te[B]=e,te[B+1]=t,B+=2,2===B&&(V?V(p):H())}),X="undefined"!=typeof window?window:void 0,Q=X||{},W=Q.MutationObserver||Q.WebKitMutationObserver,Z="undefined"!=typeof n&&"[object process]"==={}.toString.call(n),ee="undefined"!=typeof Uint8ClampedArray&&"undefined"!=typeof importScripts&&"undefined"!=typeof MessageChannel,te=new Array(1e3);H=Z?c():W?f():ee?d():void 0===X&&"function"==typeof e?g():h();var ne=void 0,re=1,ie=2,oe=new E,ae=new E;D.prototype._validateInput=function(e){return K(e)},D.prototype._validationError=function(){return new Error("Array Methods must be provided an Array")},D.prototype._init=function(){this._result=new Array(this.length)};var se=D;D.prototype._enumerate=function(){for(var e=this,t=e.length,n=e.promise,r=e._input,i=0;n._state===ne&&t>i;i++)e._eachEntry(r[i],i)},D.prototype._eachEntry=function(e,t){var n=this,r=n._instanceConstructor;a(e)?e.constructor===r&&e._state!==ne?(e._onerror=null,n._settledAt(e._state,t,e._result)):n._willSettleAt(r.resolve(e),t):(n._remaining--,n._result[t]=e)},D.prototype._settledAt=function(e,t,n){var r=this,i=r.promise;i._state===ne&&(r._remaining--,e===ie?C(i,n):r._result[t]=n),0===r._remaining&&S(i,r._result)},D.prototype._willSettleAt=function(e,t){var n=this;j(e,void 0,function(e){n._settledAt(re,t,e)},function(e){n._settledAt(ie,t,e)})};var ue=L,ce=N,le=q,fe=M,de=0,he=G;G.all=ue,G.race=ce,G.resolve=le,G.reject=fe,G._setScheduler=s,G._setAsap=u,G._asap=Y,G.prototype={constructor:G,then:function(e,t){var n=this,r=n._state;if(r===re&&!e||r===ie&&!t)return this;var i=new this.constructor(v),o=n._result;if(r){var a=arguments[r-1];Y(function(){x(r,i,a,o)})}else j(n,i,e,t);return i},"catch":function(e){return this.then(null,e)}};var pe=F,ge={Promise:he,polyfill:pe};"function"==typeof define&&define.amd?define(function(){return ge}):"undefined"!=typeof t&&t.exports?t.exports=ge:"undefined"!=typeof this&&(this.ES6Promise=ge),pe()}).call(this)}).call(this,e("_process"),"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{_process:3}],5:[function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(n,"__esModule",{value:!0});var i=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),o=e("../core/request"),a=e("../core/promise"),s=e("../core/settings"),u=e("../core/core"),c=e("../core/logger"),l=e("./storage"),f=e("../core/user"),d=new s.Settings,h=null,p="DEFER_REGISTER",g={},v={},y=[],_=function(){function e(t){r(this,e),this._dispatcher=null,this._dispatchIntervalTime=30,this._useEventCaching=!0,this._serviceHost=d.getURL("analytics"),this.logger=new c.Logger({prefix:"Ionic Analytics:"}),this.logger._silence=!0,this.storage=u.IonicPlatform.getStorage(),this.cache=new l.BucketStorage("ionic_analytics"),this._addGlobalPropertyDefaults(),t!==p&&this.register(t)}return i(e,[{key:"_addGlobalPropertyDefaults",value:function(){var e=this;e.setGlobalProperties(function(e,t){t._user=JSON.parse(JSON.stringify(f.User.current())),t._app={app_id:d.get("app_id"),analytics_version:u.IonicPlatform.Version}})}},{key:"_enqueueEvent",value:function(e,t){var n=this;if(g.dryRun)return n.logger.info("event recieved but not sent (dryRun active):"),n.logger.info(e),void n.logger.info(t);n.logger.info("enqueuing event to send later:"),n.logger.info(e),n.logger.info(t),t.keen||(t.keen={}),t.keen.timestamp=(new Date).toISOString();var r=n.cache.get("event_queue")||{};r[e]||(r[e]=[]),r[e].push(t),n.cache.set("event_queue",r)}},{key:"_requestAnalyticsKey",value:function(){var e={method:"GET",json:!0,uri:d.getURL("api")+"/api/v1/app/"+d.get("app_id")+"/keys/write",headers:{Authorization:"basic "+btoa(d.get("app_id")+":"+d.get("api_key"))}};return new o.APIRequest(e)}},{key:"_postEvent",value:function(e,t){var n=this,r={name:[t]};h||n.logger.error("Cannot send events to the analytics server without an Analytics key.");var i={method:"POST",url:n._serviceHost+"/api/v1/events/"+d.get("app_id"),body:r,json:!0,headers:{Authorization:h}};return new o.APIRequest(i)}},{key:"_postEvents",value:function(e){var t=this;h||t.logger.info("Cannot send events to the analytics server without an Analytics key.");var n={method:"POST",url:t._serviceHost+"/api/v1/events/"+d.get("app_id"),body:e,json:!0,headers:{Authorization:h}};return new o.APIRequest(n)}},{key:"_dispatchQueue",value:function(){var e=this,t=this.cache.get("event_queue")||{};0!==Object.keys(t).length&&u.IonicPlatform.deviceConnectedToNetwork()&&e.storage.lockedAsyncCall(e.cache.scopedKey("event_dispatch"),function(){return e._postEvents(t)}).then(function(){e.cache.set("event_queue",{}),e.logger.info("sent events"),e.logger.info(t)},function(n){e._handleDispatchError(n,this,t)})}},{key:"_getRequestStatusCode",value:function(e){var t=!1;return e&&e.requestInfo._lastResponse&&e.requestInfo._lastResponse.statusCode&&(t=e.requestInfo._lastResponse.statusCode),t}},{key:"_handleDispatchError",value:function(e,t,n){var r=this,i=this._getRequestStatusCode(t);"last_call_interrupted"===e?r.cache.set("event_queue",{}):i?(r.cache.set("event_queue",{}),r.logger.error("Error sending analytics data: Server responded with error"),r.logger.error(n)):r.logger.error("Error sending analytics data: Failed to connect to analytics server.")}},{key:"_handleRegisterError",value:function(e,t){var n=this._getRequestStatusCode(t),r=" See http://docs.ionic.io/v1.0/docs/io-quick-start";switch(n){case 401:self.logger.error("The api key and app id you provided did not register on the server. "+r);break;case 404:self.logger.error('The app id you provided ("'+d.get("app_id")+'") was not found.'+r);break;default:self.logger.error("Unable to request analytics key."),self.logger.error(e)}}},{key:"register",value:function(e){var t=this,n=new a.DeferredPromise;return this.hasValidSettings?(g=e||{},g.silent?this.logger._silence=!0:this.logger._silence=!1,g.dryRun&&this.logger.info("dryRun mode is active. Analytics will not send any events."),this._requestAnalyticsKey().then(function(e){h=e.payload.write_key,t.logger.info("successfully registered analytics key"),t.dispatchInterval=t.dispatchInterval,n.resolve(!0)},function(e){t._handleRegisterError(e,this),n.reject(!1)}),n.promise):(n.reject(!1),n.promise)}},{key:"setGlobalProperties",value:function(e){var t=this,n=typeof e;switch(n){case"object":for(var r in e)e.hasOwnProperty(r)&&(v[r]=e[r]);break;case"function":y.push(e);break;default:t.logger.error("setGlobalProperties parameter must be an object or function.")}}},{key:"track",value:function(e,t){var n=this;if(!this.hasValidSettings)return!1;t||(t={});for(var r in v)v.hasOwnProperty(r)&&void 0===t[r]&&(t[r]=v[r]);for(var i=0;i<y.length;i++){var o=y[i];o.call(null,e,t)}this._useEventCaching?n._enqueueEvent(e,t):g.dryRun?(n.logger.info("dryRun active, will not send event"),n.logger.info(e),n.logger.info(t)):n._postEvent(e,t)}},{key:"unsetGlobalProperty",value:function(e){var t=this,n=typeof e;switch(n){case"string":delete v[e];break;case"function":var r=y.indexOf(e);-1===r&&t.logger.error("The function passed to unsetGlobalProperty was not a global property."),y.splice(r,1);break;default:t.logger.error("unsetGlobalProperty parameter must be a string or function.")}}},{key:"hasValidSettings",get:function(){if(!d.get("app_id")||!d.get("api_key")){var e="A valid app_id and api_key are required before you can utilize analytics properly. See http://docs.ionic.io/v1.0/docs/io-quick-start";return this.logger.info(e),!1}return!0}},{key:"dispatchInterval",set:function(e){var t=this;this._dispatchIntervalTime=e,this._dispatcher&&window.clearInterval(this.dispatcher),e>0?(this._dispatcher=window.setInterval(function(){t._dispatchQueue()},1e3*e),this._useEventCaching=!0):this._useEventCaching=!1},get:function(){return this._dispatchIntervalTime}}]),e}();n.Analytics=_},{"../core/core":12,"../core/logger":16,"../core/promise":17,"../core/request":18,"../core/settings":19,"../core/user":21,"./storage":9}],6:[function(e,t,n){"use strict";if("object"==typeof angular&&angular.module){var r=function(e){return["$ionicAnalytics","$ionicGesture",function(t,n){for(var r=["drag","dragstart","dragend","dragleft","dragright","dragup","dragdown","swipe","swipeleft","swiperight","swipeup","swipedown","tap","doubletap","hold","transform","pinch","pinchin","pinchout","rotate"],i=!1,o=0;o<r.length;o++)r[o]===e.toLowerCase()&&(i=!0);return{restrict:"A",link:function(r,o,a){function s(e){var n=r.$eval(a.ionTrackData)||{};c?t.track(c,n):t.trackClick(e.pageX,e.pageY,e.target,{data:n})}var u=e[0].toUpperCase()+e.slice(1),c=a["ionTrack"+u];if(i){var l=n.on(e,s,o);r.$on("$destroy",function(){n.off(l,e,s)})}else o.on(e,s),r.$on("$destroy",function(){o.off(e,s)})}}}]},i=null;angular.module("ionic.service.analytics",["ionic"]).value("IONIC_ANALYTICS_VERSION",Ionic.Analytics.version).factory("$ionicAnalytics",[function(){return i||(i=new Ionic.Analytics("DEFER_REGISTER")),i}]).factory("domSerializer",[function(){return new Ionic.AnalyticSerializers.DOMSerializer}]).run(["$ionicAnalytics","$state",function(e,t){e.setGlobalProperties(function(e,n){n._ui||(n._ui={}),n._ui.active_state=t.current.name})}]),angular.module("ionic.service.analytics").provider("$ionicAutoTrack",[function(){var e={},t=!1;this.disableTracking=function(n){n?e[n]=!0:t=!0},this.$get=[function(){return{isEnabled:function(n){return!t&&!e[n]}}}]}]).run(["$ionicAutoTrack","$ionicAnalytics",function(e,t){e.isEnabled("Load")&&t.track("Load")}]).run(["$ionicAutoTrack","$document","$ionicAnalytics","domSerializer",function(e,t,n,r){e.isEnabled("Tap")&&t.on("click",function(e){var t=e.target.getBoundingClientRect(),i=t.right-t.left,o=t.bottom-t.top,a=(e.pageX-t.left)/i,s=(e.pageY-t.top)/o,u={coordinates:{x:e.pageX,y:e.pageY},target:r.elementSelector(e.target),target_identifier:r.elementName(e.target)};isFinite(a)&&isFinite(s)&&(u.coordinates.x_norm=a,u.coordinates.y_norm=s),n.track("Tap",{_ui:u})})}]).run(["$ionicAutoTrack","$ionicAnalytics","$rootScope",function(e,t,n){e.isEnabled("State Change")&&n.$on("$stateChangeSuccess",function(e,n,r,i,o){t.track("State Change",{from:i.name,to:n.name})})}]).directive("ionTrackClick",r("click")).directive("ionTrackTap",r("tap")).directive("ionTrackDoubletap",r("doubletap")).directive("ionTrackHold",r("hold")).directive("ionTrackRelease",r("release")).directive("ionTrackDrag",r("drag")).directive("ionTrackDragLeft",r("dragleft")).directive("ionTrackDragRight",r("dragright")).directive("ionTrackDragUp",r("dragup")).directive("ionTrackDragDown",r("dragdown")).directive("ionTrackSwipeLeft",r("swipeleft")).directive("ionTrackSwipeRight",r("swiperight")).directive("ionTrackSwipeUp",r("swipeup")).directive("ionTrackSwipeDown",r("swipedown")).directive("ionTrackTransform",r("hold")).directive("ionTrackPinch",r("pinch")).directive("ionTrackPinchIn",r("pinchin")).directive("ionTrackPinchOut",r("pinchout")).directive("ionTrackRotate",r("rotate"))}},{}],7:[function(e,t,n){"use strict";var r=e("./analytics"),i=e("./storage"),o=e("./serializers");window.Ionic=window.Ionic||{},Ionic.Analytics=r.Analytics,Ionic.AnalyticStorage={},Ionic.AnalyticStorage.BucketStorage=i.BucketStorage,Ionic.AnalyticSerializers={},Ionic.AnalyticSerializers.DOMSerializer=o.DOMSerializer},{"./analytics":5,"./serializers":8,"./storage":9}],8:[function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(n,"__esModule",{value:!0});var i=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),o=function(){function e(){r(this,e)}return i(e,[{key:"elementSelector",value:function(e){for(var t=[];"HTML"!==e.tagName;){var n=e.tagName.toLowerCase(),r=e.getAttribute("id");r&&(n+="#"+r);var i=e.className;if(i)for(var o=i.split(" "),a=0;a<o.length;a++){var s=o[a];s&&(n+="."+s)}if(!e.parentNode)return null;var u=Array.prototype.indexOf.call(e.parentNode.children,e);n+=":nth-child("+(u+1)+")",e=e.parentNode,t.push(n)}return t.reverse().join(">")}},{key:"elementName",value:function(e){var t=e.getAttribute("ion-track-name");if(t)return t;var n=e.getAttribute("id");return n?n:null}}]),e}();n.DOMSerializer=o},{}],9:[function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(n,"__esModule",{value:!0});var i=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),o=e("../core/settings"),a=e("../core/core"),s=new o.Settings,u=function(){function e(t){r(this,e),this.name=t,this.baseStorage=a.IonicPlatform.getStorage()}return i(e,[{key:"get",value:function(e){return this.baseStorage.retrieveObject(this.scopedKey(e))}},{key:"set",value:function(e,t){return this.baseStorage.storeObject(this.scopedKey(e),t)}},{key:"scopedKey",value:function(e){return this.name+"_"+e+"_"+s.get("app_id")}}]),e}();n.BucketStorage=u},{"../core/core":12,"../core/settings":19}],10:[function(e,t,n){"use strict";"object"==typeof angular&&angular.module&&angular.module("ionic.service.core",[]).provider("persistentStorage",function(){return{$get:[function(){var e=Ionic.getService("Storage");return e||(e=new Ionic.IO.Storage,Ionic.addService("Storage",e,!0)),e}]}}).factory("$ionicCoreSettings",[function(){return new Ionic.IO.Settings}]).factory("$ionicUser",[function(){return Ionic.User}]).run([function(){Ionic.io()}])},{}],11:[function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e){return s[e]||null}Object.defineProperty(n,"__esModule",{value:!0});var o=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),a=e("./logger"),s={},u=function(){function e(t,n){return r(this,e),this.logger=new a.Logger({prefix:"Ionic App:"}),t&&""!==t?n&&""!==n?(s.id=t,s.apiKey=n,this.devPush=null,void(this.gcmKey=null)):(this.logger.info("No api_key was provided"),!1):(this.logger.info("No app_id was provided"),!1)}return o(e,[{key:"toString",value:function(){return"<IonicApp ['"+this.id+"'>"}},{key:"id",get:function(){return i("id")}},{key:"apiKey",get:function(){return i("apiKey")}}]),e}();n.App=u},{"./logger":16}],12:[function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(n,"__esModule",{value:!0});var i=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),o=e("./events"),a=e("./storage"),s=e("./logger"),u=new o.EventEmitter,c=new a.Storage,l=function(){function e(){r(this,e);var t=this;if(this.logger=new s.Logger({prefix:"Ionic Core:"}),this.logger.info("init"),this._pluginsReady=!1,this.emitter=e.getEmitter(),this._bootstrap(),t.cordovaPlatformUnknown)t.logger.info("attempting to mock plugins"),t._pluginsReady=!0,t.emitter.emit("ionic_core:plugins_ready");else try{document.addEventListener("deviceready",function(){t.logger.info("plugins are ready"),t._pluginsReady=!0,t.emitter.emit("ionic_core:plugins_ready")},!1)}catch(n){t.logger.info("unable to listen for cordova plugins to be ready")}}return i(e,[{key:"_isCordovaAvailable",value:function(){var e=this;if(this.logger.info("searching for cordova.js"),"undefined"!=typeof cordova)return this.logger.info("cordova.js has already been loaded"),!0;for(var t=document.getElementsByTagName("script"),n=t.length,r=0;n>r;r++){var i=t[r].getAttribute("src");if(i){var o=i.split("/"),a=0;try{if(a=o.length,"cordova.js"===o[a-1])return e.logger.info("cordova.js has previously been included."),!0}catch(s){e.logger.info("encountered error while testing for cordova.js presence, "+s.toString())}}}return!1}},{key:"loadCordova",value:function(){var t=this;if(!this._isCordovaAvailable()){var n=document.createElement("script"),r="cordova.js";switch(e.getDeviceTypeByNavigator()){case"android":"file"===window.location.href.substring(0,4)&&(r="file:///android_asset/www/cordova.js");
break;case"ipad":case"iphone":try{var i=window.location.search.match(/cordova_js_bootstrap_resource=(.*?)(&|#|$)/i);i&&(r=decodeURI(i[1]))}catch(o){t.logger.info("could not find cordova_js_bootstrap_resource query param"),t.logger.info(o)}break;case"unknown":return t.cordovaPlatformUnknown=!0,!1}n.setAttribute("src",r),document.head.appendChild(n),t.logger.info("injecting cordova.js")}}},{key:"_bootstrap",value:function(){this.loadCordova()}},{key:"onReady",value:function(e){var t=this;this._pluginsReady?e(t):t.emitter.on("ionic_core:plugins_ready",function(){e(t)})}}],[{key:"getEmitter",value:function(){return u}},{key:"getStorage",value:function(){return c}},{key:"getMain",value:function(){return"undefined"!=typeof Ionic&&Ionic.IO&&Ionic.IO.main?Ionic.IO.main:null}},{key:"getDeviceTypeByNavigator",value:function(){var e=navigator.userAgent,t=e.match(/iPad/i);if(t&&"ipad"===t[0].toLowerCase())return"ipad";var n=e.match(/iPhone/i);if(n&&"iphone"===n[0].toLowerCase())return"iphone";var r=e.match(/Android/i);return r&&"android"===r[0].toLowerCase()?"android":"unknown"}},{key:"isAndroidDevice",value:function(){var t=e.getDeviceTypeByNavigator();return"android"===t?!0:!1}},{key:"isIOSDevice",value:function(){var t=e.getDeviceTypeByNavigator();return"iphone"===t||"ipad"===t?!0:!1}},{key:"deviceConnectedToNetwork",value:function(e){if("undefined"==typeof e&&(e=!1),"undefined"==typeof navigator.connection||"undefined"==typeof navigator.connection.type||"undefined"==typeof Connection)return e?!1:!0;switch(navigator.connection.type){case Connection.ETHERNET:case Connection.WIFI:case Connection.CELL_2G:case Connection.CELL_3G:case Connection.CELL_4G:case Connection.CELL:return!0;default:return!1}}},{key:"Version",get:function(){return"0.2.0"}}]),e}();n.IonicPlatform=l},{"./events":15,"./logger":16,"./storage":20}],13:[function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(n,"__esModule",{value:!0});var i=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),o={},a=function(){function e(t){r(this,e),this.data={},this.setProperties(t)}return i(e,[{key:"setProperties",value:function(e){if(e instanceof Object)for(var t in e)this.data[t]=e[t]}},{key:"toJSON",value:function(){var e=this.data;return{__Ionic_DataTypeSchema:e.name,value:e.value}}},{key:"isValid",value:function(){return this.data.name&&this.data.value?!0:!1}}]),e}(),s=function(){function e(){r(this,e)}return i(e,null,[{key:"get",value:function(e,t){return o[e]?new o[e](t):!1}},{key:"getMapping",value:function(){return o}},{key:"register",value:function(e,t){o[e]=t}},{key:"Schema",get:function(){return a}}]),e}();n.DataType=s;var u=function(){function e(t){if(r(this,e),this.data=[],t instanceof Array)for(var n in t)this.push(t[n])}return i(e,[{key:"toJSON",value:function(){var e=this.data,t=new a({name:"UniqueArray",value:e});return t.toJSON()}},{key:"push",value:function(e){-1===this.data.indexOf(e)&&this.data.push(e)}},{key:"pull",value:function(e){var t=this.data.indexOf(e);this.data.splice(t,1)}}],[{key:"fromStorage",value:function(t){return new e(t)}}]),e}();n.UniqueArray=u,s.register("UniqueArray",u)},{}],14:[function(e,t,n){"use strict";var r=e("./app"),i=e("./core"),o=e("./events"),a=e("./logger"),s=e("./promise"),u=e("./request"),c=e("./settings"),l=e("./storage"),f=e("./user"),d=e("./data-types");window.Ionic=window.Ionic||{},Ionic.Core=i.IonicPlatform,Ionic.User=f.User,Ionic.DataType=d.DataType,Ionic.DataTypes=d.DataType.getMapping(),Ionic.IO={},Ionic.IO.App=r.App,Ionic.IO.EventEmitter=o.EventEmitter,Ionic.IO.Logger=a.Logger,Ionic.IO.Promise=s.Promise,Ionic.IO.DeferredPromise=s.DeferredPromise,Ionic.IO.Request=u.Request,Ionic.IO.Response=u.Response,Ionic.IO.APIRequest=u.APIRequest,Ionic.IO.APIResponse=u.APIResponse,Ionic.IO.Storage=l.Storage,Ionic.IO.Settings=c.Settings;var h={};Ionic.io=function(){return"undefined"==typeof Ionic.IO.main&&(Ionic.IO.main=new Ionic.Core),Ionic.IO.main},Ionic.getService=function(e){return"undefined"!=typeof h[e]&&h[e]?h[e]:!1},Ionic.addService=function(e,t,n){t&&"undefined"==typeof h[e]?h[e]=t:t&&n&&(h[e]=t)},Ionic.removeService=function(e){"undefined"!=typeof h[e]&&delete h[e]},Ionic.io()},{"./app":11,"./core":12,"./data-types":13,"./events":15,"./logger":16,"./promise":17,"./request":18,"./settings":19,"./storage":20,"./user":21}],15:[function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(n,"__esModule",{value:!0});var i=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),o=e("events"),a=function(){function e(){r(this,e),this._emitter=new o}return i(e,[{key:"on",value:function(e,t){return this._emitter.on(e,t)}},{key:"emit",value:function(e,t){return this._emitter.emit(e,t)}}]),e}();n.EventEmitter=a},{events:2}],16:[function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(n,"__esModule",{value:!0});var i=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),o=function(){function e(t){r(this,e);var n=t||{};this._silence=!1,this._prefix=!1,this._options=n,this._bootstrap()}return i(e,[{key:"_bootstrap",value:function(){this._options.prefix&&(this._prefix=this._options.prefix)}},{key:"info",value:function(e){this._silence||(this._prefix?console.log(this._prefix,e):console.log(e))}},{key:"warn",value:function(e){this._silence||(this._prefix?console.log(this._prefix,e):console.log(e))}},{key:"error",value:function(e){this._prefix?console.error(this._prefix,e):console.error(e)}}]),e}();n.Logger=o},{}],17:[function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(n,"__esModule",{value:!0});var i=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),o=e("es6-promise").Promise,a=o;n.Promise=a;var s=function(){function e(){r(this,e);var t=this;this._update=!1,this.promise=new o(function(e,n){t.resolve=e,t.reject=n});var n=this.promise.then;this.promise.then=function(e,r,i){return t._update=i,n.call(t.promise,e,r)}}return i(e,[{key:"notify",value:function(e){this._update&&"function"==typeof this._update&&this._update(e)}}]),e}();n.DeferredPromise=s},{"es6-promise":4}],18:[function(e,t,n){"use strict";function r(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(n,"__esModule",{value:!0});var o=function(e,t,n){for(var r=!0;r;){var i=e,o=t,a=n;s=c=u=void 0,r=!1,null===i&&(i=Function.prototype);var s=Object.getOwnPropertyDescriptor(i,o);if(void 0!==s){if("value"in s)return s.value;var u=s.get;return void 0===u?void 0:u.call(a)}var c=Object.getPrototypeOf(i);if(null===c)return void 0;e=c,t=o,n=a,r=!0}},a=e("./promise"),s=e("browser-request"),u=function d(){i(this,d)};n.Request=u;var c=function h(){i(this,h)};n.Response=c;var l=function(e){function t(){i(this,t),o(Object.getPrototypeOf(t.prototype),"constructor",this).call(this)}return r(t,e),t}(c);n.APIResponse=l;var f=function(e){function t(e){i(this,t),o(Object.getPrototypeOf(t.prototype),"constructor",this).call(this);var n={},r=new a.Promise(function(t,r){s(e,function(e,i,o){if(n._lastError=e,n._lastResponse=i,n._lastResult=o,e)r(e);else if(i.statusCode<200||i.statusCode>=400){var a=new Error("Request Failed with status code of "+i.statusCode);r(a)}else t({response:i,payload:o})})});return r.requestInfo=n,r}return r(t,e),t}(u);n.APIRequest=f},{"./promise":17,"browser-request":1}],19:[function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(n,"__esModule",{value:!0});var i=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),o=function(){function e(){return r(this,e),this._settings=null,this}return i(e,[{key:"factory",value:function(e,t){return this._settings=t(),this}},{key:"get",value:function(e){return this._settings.get(e)}},{key:"finish",value:function(){return this}}]),e}(),a=(new o).factory("$ionicCoreSettings",function(){"IONIC_SETTINGS_STRING_START";var settings = {"dev_push":true}; return { get: function(setting) { if (settings[setting]) { return settings[setting]; } return null; } };"IONIC_SETTINGS_STRING_END"}).finish(),s=function(){function e(){r(this,e),this._locations={api:"https://apps.ionic.io",push:"https://push.ionic.io",analytics:"https://analytics.ionic.io",deploy:"https://apps.ionic.io"},this._devLocations=this.get("dev_locations"),this._devLocations||(this._devLocations={})}return i(e,[{key:"get",value:function(e){return a.get(e)}},{key:"getURL",value:function(e){return this._devLocations[e]?this._devLocations[e]:this._locations[e]?this._locations[e]:null}}]),e}();n.Settings=s},{}],20:[function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(n,"__esModule",{value:!0});var i=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),o=e("./promise"),a=function(){function e(){r(this,e)}return i(e,[{key:"get",value:function(e){return window.localStorage.getItem(e)}},{key:"remove",value:function(e){return window.localStorage.removeItem(e)}},{key:"set",value:function(e,t){return window.localStorage.setItem(e,t)}}]),e}(),s={},u={},c=function(){function e(){r(this,e),this.strategy=new a}return i(e,[{key:"storeObject",value:function(e,t){var n=JSON.stringify(t);this.strategy.set(e,n),s[e]=t}},{key:"deleteObject",value:function(e){this.strategy.remove(e),delete s[e]}},{key:"retrieveObject",value:function(e){var t=s[e];if(t)return t;var n=this.strategy.get(e);if(null===n)return null;try{return JSON.parse(n)}catch(r){return null}}},{key:"lockedAsyncCall",value:function(e,t){var n=this,r=new o.DeferredPromise;return u[e]?(r.reject("in_progress"),r.promise):"locked"===this.strategy.get(e)?(r.reject("last_call_interrupted"),r.promise.then(null,function(){n.strategy.remove(e)}),r.promise):(u[e]=!0,n.strategy.set(e,"locked"),t().then(function(t){r.resolve(t),delete u[e],n.strategy.remove(e)},function(t){r.reject(t),delete u[e],n.strategy.remove(e)},function(e){r.notify(e)}),r.promise)}}]),e}();n.Storage=c},{"./promise":17}],21:[function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(n,"__esModule",{value:!0});var i=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),o=e("./request"),a=e("./promise"),s=e("./settings"),u=e("./core"),c=e("./storage"),l=e("./logger"),f=e("../push/push-token"),d=e("./data-types.js"),h=u.IonicPlatform,p=null,g=new s.Settings,v=new c.Storage,y=g.getURL("api")+"/api/v1/app/"+g.get("app_id")+"/users",_={load:function(e){return y+"/"+e.id},remove:function(e){return y+"/"+e.id},save:function(e){return y+"/"+e.id},identify:function(){return y+"/identify"},addToken:function(){return y+"/pushUnique"}},k=function(){function e(){r(this,e)}return i(e,null,[{key:"delete",value:function(){v.deleteObject(e.label)}},{key:"store",value:function(){v.storeObject(e.label,w.current())}},{key:"getRawData",value:function(){return v.retrieveObject(e.label)||!1}},{key:"load",value:function(){var t=v.retrieveObject(e.label)||!1;return t?w.fromContext(t):!1}},{key:"label",get:function(){return"ionic_io_user_"+g.get("app_id")}}]),e}(),m=function(){function e(t){r(this,e),this.logger=new l.Logger({prefix:"Ionic Push Token:"}),this.tokens={android:[],ios:[]},t&&"object"==typeof t&&(this.tokens=t)}return i(e,[{key:"addToken",value:function(e){var t=null;if("undefined"==typeof e||!e||""===e)return this.logger.info("you need to pass a valid token to addToken()"),!1;if(e.token&&(e=e.token),"DEV"===e.slice(0,3))return this.logger.info("dev tokens cannot be saved to a user as they are a temporary resource"),!1;if(h.isAndroidDevice()?t="android":h.isIOSDevice()&&(t="ios"),null===t||!this.tokens.hasOwnProperty(t))return this.logger.info("cannot determine the token platform. Are you running on an Android or iOS device?"),!1;var n=this.tokens[t],r=!1,i=null;for(i in n)n[i]===e&&(r=!0);return r||n.push(e),!0}},{key:"removeToken",value:function(e){var t;for(t in this.tokens){var n,r=this.tokens[t];for(n in r)r[n]===e.token&&r.splice(n,1)}return!0}}]),e}(),b=function(){function e(t){r(this,e),this.data={},"object"==typeof t&&(this.data=t,this.deserializerDataTypes())}return i(e,[{key:"deserializerDataTypes",value:function(){for(var e in this.data)if("object"==typeof this.data[e]&&this.data[e].__Ionic_DataTypeSchema){var t=this.data[e].__Ionic_DataTypeSchema,n=d.DataType.getMapping();n[t]&&(this.data[e]=n[t].fromStorage(this.data[e].value))}}},{key:"set",value:function(e,t){this.data[e]=t}},{key:"unset",value:function(e){delete this.data[e]}},{key:"get",value:function(e,t){return this.data.hasOwnProperty(e)?this.data[e]:t||null}}]),e}(),w=function(){function e(){r(this,e),this.logger=new l.Logger({prefix:"Ionic User:"}),this._blockLoad=!1,this._blockSave=!1,this._blockDelete=!1,this._dirty=!1,this._fresh=!0,this._unset={},this.push=new m,this.data=new b}return i(e,[{key:"isDirty",value:function(){return this._dirty}},{key:"isFresh",value:function(){return this._fresh}},{key:"isValid",value:function(){return this.id?!0:!1}},{key:"getAPIFormat",value:function(){var e=this,t=this.data.data;return t.user_id=this.id,t._push={android_tokens:this.push.tokens.android,ios_tokens:this.push.tokens.ios},this.isFresh()?t:{update:t,remove:e._unset}}},{key:"getFormat",value:function(e){var t=this,n=null;switch(e){case"api":n=t.getAPIFormat()}return n}},{key:"delete",value:function(){var e=this,t=new a.DeferredPromise;return e.isValid()?(e._blockDelete?(e.logger.info("a delete operation is already in progress for "+this+"."),t.reject(!1)):(e._blockDelete=!0,e._delete(),new o.APIRequest({uri:_.remove(this),method:"DELETE",headers:{Accept:"application/json","Content-Type":"application/json"}}).then(function(n){e._blockDelete=!1,e.logger.info("deleted "+e),t.resolve(n)},function(n){e._blockDelete=!1,e.logger.error(n),t.reject(n)})),t.promise):!1}},{key:"_store",value:function(){this===e.current()&&k.store()}},{key:"_delete",value:function(){this===e.current()&&k["delete"]()}},{key:"save",value:function(){var e=this,t=new a.DeferredPromise;if(e._blockSave)e.logger.info("a save operation is already in progress for "+this+"."),t.reject(!1);else{e._blockSave=!0,e._store();var n=_.save(this),r="PUT";e.isFresh()&&(n=_.identify(this),r="POST"),new o.APIRequest({uri:n,method:r,headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(e.getFormat("api"))}).then(function(n){e._dirty=!1,e.isFresh()||(e._unset={}),e._fresh=!1,e._blockSave=!1,e.logger.info("saved user"),t.resolve(n)},function(n){e._dirty=!0,e._blockSave=!1,e.logger.error(n),t.reject(n)})}return t.promise}},{key:"toString",value:function(){return"<IonicUser ['"+this.id+"']>"}},{key:"addPushToken",value:function(e){return this.push.addToken(e)}},{key:"removePushToken",value:function(e){return e instanceof f.PushToken||(e=new f.PushToken(e)),this.push.removeToken(e)}},{key:"set",value:function(e,t){return delete this._unset[e],this.data.set(e,t)}},{key:"get",value:function(e,t){return this.data.get(e,t)}},{key:"unset",value:function(e){return this._unset[e]=!0,this.data.unset(e)}},{key:"id",set:function(e){return e&&"string"==typeof e&&""!==e?(this._id=e,!0):!1},get:function(){return this._id||null}}],[{key:"current",value:function(t){return t?(p=t,k.store(),p):(p||(p=k.load()),p||(p=new e),p)}},{key:"fromContext",value:function(t){var n=new e;return n.id=t._id,n.data=new b(t.data.data),n.push=new m(t.push.tokens),n._fresh=t._fresh,n._dirty=t._dirty,n}},{key:"load",value:function(t){var n=new a.DeferredPromise,r=new e;return r.id=t,r._blockLoad?(r.logger.info("a load operation is already in progress for "+this+"."),n.reject(!1)):(r._blockLoad=!0,new o.APIRequest({uri:_.load(r),method:"GET",json:!0,headers:{Accept:"application/json","Content-Type":"application/json"}}).then(function(e){r._blockLoad=!1,r.logger.info("loaded user"),r.data=new b(e.payload.custom_data),e.payload._push&&e.payload._push.android_tokens&&(r.push.tokens.android=e.payload._push.android_tokens),e.payload._push&&e.payload._push.ios_tokens&&(r.push.tokens.ios=e.payload._push.ios_tokens),r.image=e.payload.image,r._fresh=!1,n.resolve(r)},function(e){r._blockLoad=!1,r.logger.error(e),n.reject(e)})),n.promise}},{key:"anonymousId",value:function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random()|0,n="x"==e?t:3&t|8;return n.toString(16)})}}]),e}();n.User=w},{"../push/push-token":29,"./core":12,"./data-types.js":13,"./logger":16,"./promise":17,"./request":18,"./settings":19,"./storage":20}],22:[function(e,t,n){"use strict";if("object"==typeof angular&&angular.module){var r=null;angular.module("ionic.service.deploy",[]).factory("$ionicDeploy",[function(){return r||(r=new Ionic.Deploy),r}])}},{}],23:[function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(n,"__esModule",{value:!0});var i=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),o=e("../core/settings"),a=e("../core/promise"),s=e("../core/logger"),u=e("../core/core"),c=e("../core/events"),l=new o.Settings,f="IONIC_DEPLOY_MISSING_PLUGIN",d=5e3,h=6e4,p=function(){function e(){r(this,e);var t=this;this.logger=new s.Logger({prefix:"Ionic Deploy:"}),this._plugin=!1,this._isReady=!1,this._channelTag="production",this._emitter=new c.EventEmitter,this.logger.info("init"),u.IonicPlatform.getMain().onReady(function(){t.initialize(),t._isReady=!0,t._emitter.emit("ionic_deploy:ready")})}return i(e,[{key:"_getPlugin",value:function(){return this._plugin?this._plugin:"undefined"==typeof IonicDeploy?(this.logger.info("plugin is not installed or has not loaded. Have you run `ionic plugin add ionic-plugin-deploy` yet?"),!1):(this._plugin=IonicDeploy,IonicDeploy)}},{key:"initialize",value:function(){var e=this;this.onReady(function(){e._getPlugin()&&e._plugin.init(l.get("app_id"),l.getURL("deploy"))})}},{key:"check",value:function(){var e=this,t=new a.DeferredPromise;return this.onReady(function(){e._getPlugin()?e._plugin.check(l.get("app_id"),e._channelTag,function(n){n&&"true"===n?(e.logger.info("an update is available"),t.resolve(!0)):(e.logger.info("no updates available"),t.resolve(!1))},function(n){e.logger.error("encountered an error while checking for updates"),t.reject(n)}):t.reject(f)}),t.promise}},{key:"download",value:function(){var e=this,t=new a.DeferredPromise;return this.onReady(function(){e._getPlugin()?e._plugin.download(l.get("app_id"),function(n){"true"!==n&&"false"!==n?t.notify(n):("true"===n&&e.logger.info("download complete"),t.resolve("true"===n))},function(e){t.reject(e)}):t.reject(f)}),t.promise}},{key:"extract",value:function(){var e=this,t=new a.DeferredPromise;return this.onReady(function(){e._getPlugin()?e._plugin.extract(l.get("app_id"),function(n){"done"!==n?t.notify(n):("true"===n&&e.logger.info("extraction complete"),t.resolve(n))},function(e){t.reject(e)}):t.reject(f)}),t.promise}},{key:"load",value:function(){var e=this;this.onReady(function(){e._getPlugin()&&e._plugin.redirect(l.get("app_id"))})}},{key:"watch",value:function(e){function t(){i.check().then(function(e){e&&n.notify(e)},function(e){i.logger.info("unable to check for updates, ",e)}),this._checkTimeout&&(this._checkTimeout=setTimeout(t.bind(i),r.interval))}var n=new a.DeferredPromise,r=e||{},i=this;return"undefined"==typeof r.initialDelay&&(r.initialDelay=d),"undefined"==typeof r.interval&&(r.interval=h),this._checkTimeout=setTimeout(t.bind(i),r.initialDelay),n.promise}},{key:"unwatch",value:function(){clearTimeout(this._checkTimeout),this._checkTimeout=null}},{key:"info",value:function(){var e=new a.DeferredPromise,t=this;return this.onReady(function(){t._getPlugin()?t._plugin.info(l.get("app_id"),function(t){e.resolve(t)},function(t){e.reject(t)}):e.reject(f)}),e.promise}},{key:"getVersions",value:function(){var e=new a.DeferredPromise,t=this;return this.onReady(function(){t._getPlugin()?t._plugin.getVersions(l.get("app_id"),function(t){e.resolve(t)},function(t){e.reject(t)}):e.reject(f)}),e.promise}},{key:"deleteVersion",value:function(e){var t=new a.DeferredPromise,n=this;return this.onReady(function(){n._getPlugin()?n._plugin.deleteVersion(l.get("app_id"),e,function(e){t.resolve(e)},function(e){t.reject(e)}):t.reject(f)}),t.promise}},{key:"getMetadata",value:function(e){var t=new a.DeferredPromise,n=this;return this.onReady(function(){n._getPlugin()?n._plugin.getMetadata(l.get("app_id"),e,function(e){t.resolve(e.metadata)},function(e){t.reject(e)}):t.reject(f)}),t.promise}},{key:"setChannel",value:function(e){this._channelTag=e}},{key:"update",value:function(e){var t=new a.DeferredPromise,n=this,r=!1;return"undefined"!=typeof e&&(r=e),this.onReady(function(){n._getPlugin()?n.check().then(function(e){if(e===!0){var i=0;n.download().then(function(e){e||t.reject("download error"),n.extract().then(function(e){e||t.reject("extraction error"),r?t.resolve(!0):(t.resolve(!0),n._plugin.redirect(l.get("app_id")))},function(e){t.reject(e)},function(e){var n=i+e/2;t.notify(n)})},function(e){t.reject(e)},function(e){i=e/2,t.notify(i)})}else t.resolve(!1)},function(e){t.reject(e)}):t.reject(f)}),t.promise}},{key:"onReady",value:function(e){var t=this;this._isReady?e(t):t._emitter.on("ionic_deploy:ready",function(){e(t)})}}]),e}();n.Deploy=p},{"../core/core":12,"../core/events":15,"../core/logger":16,"../core/promise":17,"../core/settings":19}],24:[function(e,t,n){"use strict";var r=e("./deploy");window.Ionic=window.Ionic||{},Ionic.Deploy=r.Deploy},{"./deploy":23}],25:[function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var i=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();if("object"==typeof angular&&angular.module){var o=null;angular.module("ionic.service.push",[]).factory("$ionicPushAction",["$state",function(e){var t=function(){function t(){r(this,t)}return i(t,[{key:"notificationNavigation",value:function(t){var n=!1,r={};try{n=t.additionalData.payload.$state}catch(i){n=!1}try{r=JSON.parse(t.additionalData.payload.$stateParams)}catch(i){r={}}n&&e.go(n,r)}}]),t}();return new t}]).factory("$ionicPush",[function(){return o||(o=new Ionic.Push("DEFER_INIT")),o}]).run(["$ionicPush","$ionicPushAction",function(e,t){e._emitter.on("ionic_push:processNotification",function(e){e&&e.additionalData&&e.additionalData.foreground===!1&&t.notificationNavigation(e)})}])}},{}],26:[function(e,t,n){"use strict";var r=e("./push"),i=e("./push-token");window.Ionic=window.Ionic||{},Ionic.Push=r.Push,Ionic.PushToken=i.PushToken},{"./push":30,"./push-token":29}],27:[function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(n,"__esModule",{value:!0});var i=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),o=e("../core/request"),a=e("../core/settings"),s=e("../core/logger"),u=e("./push-token"),c=new a.Settings,l=function(){function e(){r(this,e),this.logger=new s.Logger({prefix:"Ionic Push (dev):"}),this._serviceHost=c.getURL("push"),this._token=!1,this._watch=!1}return i(e,[{key:"getDevToken",value:function(){var e="DEV-xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random()|0,n="x"===e?t:3&t|8;return n.toString(16)});return this._token=e,this._token}},{key:"init",value:function(e,t){this._push=e,this._emitter=this._push._emitter;var n=this._token,r=this;n||(n=this.getDevToken());var i={method:"POST",uri:this._serviceHost+"/dev/push",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify({dev_token:n})};new o.APIRequest(i).then(function(){var e={registrationId:n};r.logger.info("registered with development push service",n),r._emitter.emit("ionic_push:token",e),"function"==typeof t&&t(new u.PushToken(r._token)),r.watch()},function(e){r.logger.error("error connecting development push service.",e)})}},{key:"checkForNotifications",value:function(){if(!this._token)return!1;var e=this,t={method:"GET",uri:this._serviceHost+"/dev/push/check",headers:{Accept:"application/json","Content-Type":"application/json","X-Ionic-Dev-Token":this._token},json:!0};new o.APIRequest(t).then(function(t){if(t.payload.messages.length>0){var n={message:t.payload.messages[0],title:"DEVELOPMENT PUSH"};e.logger.warn("Ionic Push: Development Push received. Development pushes will not contain payload data."),e._emitter.emit("ionic_push:notification",n)}},function(t){e.logger.error("unable to check for development pushes.",t)})}},{key:"watch",value:function(){this.logger.info("watching for new notifications");var e=this;this._watch||(this._watch=setInterval(function(){e.checkForNotifications()},5e3))}},{key:"halt",value:function(){this._watch&&clearInterval(this._watch)}}]),e}();n.PushDevService=l},{"../core/logger":16,"../core/request":18,"../core/settings":19,"./push-token":29}],28:[function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(n,"__esModule",{value:!0});var i=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),o=function(){function e(){r(this,e),this.asleep=!1,this.closed=!1}return i(e,[{key:"wasAsleep",get:function(){return this.asleep}},{key:"wasClosed",get:function(){return this.closed}}]),e}(),a=function(){function e(t){r(this,e),this._raw=t||{},this._raw.additionalData||(this._raw.additionalData={coldstart:!1,foreground:!0}),this._payload=null,this.app=null,this.text=null,this.title=null,this.count=null,this.sound=null,this.image=null}return i(e,[{key:"processRaw",value:function(){this.text=this._raw.message||null,this.title=this._raw.title||null,this.count=this._raw.count||null,this.sound=this._raw.sound||null,this.image=this._raw.image||null,this.app=new o,this._raw.additionalData.foreground||(this.app.asleep=!0),this._raw.additionalData.coldstart&&(this.app.closed=!0),this._raw.additionalData.payload&&(this._payload=this._raw.additionalData.payload)}},{key:"getRawVersion",value:function(){return this._raw}},{key:"toString",value:function(){return"<PushMessage ['"+this.title+"']>"}},{key:"payload",get:function(){return this._payload||{}}}],[{key:"fromPluginJSON",value:function(t){var n=new e(t);return n.processRaw(),n}}]),e}();n.PushMessage=a},{}],29:[function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(n,"__esModule",{value:!0});var i=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),o=function(){function e(t){r(this,e),this._token=t||null}return i(e,[{key:"toString",value:function(){var e=this._token||"null";return"<PushToken ['"+e+"']>"}},{key:"token",set:function(e){this._token=e},get:function(){return this._token}}]),e}();n.PushToken=o},{}],30:[function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(n,"__esModule",{value:!0});var i=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),o=e("../core/app"),a=e("../core/settings"),s=e("../core/core"),u=e("../core/logger"),c=e("../core/events"),l=e("../core/request"),f=e("../core/promise"),d=e("./push-token"),h=e("./push-message"),p=e("./push-dev"),g=new a.Settings,v="DEFER_INIT",y=g.getURL("api")+"/api/v1/app/"+g.get("app_id")+"/push",_={invalidateToken:function(){return y+"/invalidate-token"}},k=function(){function e(t){r(this,e),this.logger=new u.Logger({prefix:"Ionic Push:"});var n=new o.App(g.get("app_id"),g.get("api_key"));if(n.devPush=g.get("dev_push"),n.gcmKey=g.get("gcm_key"),!n.id||!n.apiKey)return this.logger.error("no app_id or api_key found. (http://docs.ionic.io/docs/io-install)"),!1;if(s.IonicPlatform.isAndroidDevice()&&!n.devPush&&!n.gcmKey)return this.logger.error("GCM project number not found (http://docs.ionic.io/docs/push-android-setup)"),!1;if(this.app=n,this.registerCallback=!1,this.notificationCallback=!1,this.errorCallback=!1,this._token=!1,this._notification=!1,this._debug=!1,this._isReady=!1,this._tokenReady=!1,this._blockRegistration=!1,this._registered=!1,this._emitter=new c.EventEmitter,t!==v){var i=this;s.IonicPlatform.getMain().onReady(function(){i.init(t)})}}return i(e,[{key:"getStorageToken",value:function(){var e=s.IonicPlatform.getStorage(),t=e.retrieveObject("ionic_io_push_token");return t?new d.PushToken(t.token):null}},{key:"clearStorageToken",value:function(){var e=s.IonicPlatform.getStorage();e.deleteObject("ionic_io_push_token")}},{key:"init",value:function(e){if(this._getPushPlugin(),"undefined"==typeof e&&(e={}),"object"!=typeof e)return this.logger.error("init() requires a valid config object."),!1;var t=this;return e.pluginConfig||(e.pluginConfig={}),s.IonicPlatform.isAndroidDevice()&&(e.pluginConfig.android||(e.pluginConfig.android={}),e.pluginConfig.android.senderId||(e.pluginConfig.android.senderID=t.app.gcmKey)),e.onRegister&&this.setRegisterCallback(e.onRegister),e.onNotification&&this.setNotificationCallback(e.onNotification),e.onError&&this.setErrorCallback(e.onError),this._config=e,this._isReady=!0,this._emitter.emit("ionic_push:ready",{config:this._config
}),this}},{key:"addTokenToUser",value:function(e){this._token||this.logger.info("a token must be registered before you can add it to a user."),"object"==typeof e?s.IonicPlatform.isAndroidDevice()?e.addPushToken(this._token,"android"):s.IonicPlatform.isIOSDevice()?e.addPushToken(this._token,"ios"):this.logger.info("token is not a valid Android or iOS registration id. Cannot save to user."):this.logger.info("invalid $ionicUser object passed to $ionicPush.addToUser()")}},{key:"register",value:function(e){this.logger.info("register");var t=this;return this._blockRegistration?(t.logger.info("another registration is already in progress."),!1):(this._blockRegistration=!0,void this.onReady(function(){if(t.app.devPush){var n=new p.PushDevService;t._debugCallbackRegistration(),t._callbackRegistration(),n.init(t,e),t._blockRegistration=!1,t._tokenReady=!0}else t._plugin=PushNotification.init(t._config.pluginConfig),t._plugin.on("registration",function(n){t._blockRegistration=!1,t.token=new d.PushToken(n.registrationId),t._tokenReady=!0,"function"==typeof e&&e(t._token)}),t._debugCallbackRegistration(),t._callbackRegistration();t._registered=!0}))}},{key:"unregister",value:function(){var e=this,t=new f.DeferredPromise,n=null;return s.IonicPlatform.isAndroidDevice()?n="android":s.IonicPlatform.isIOSDevice()&&(n="ios"),n||t.reject("Could not detect the platform, are you on a device?"),e._blockUnregister?(e.logger.info("an unregister operation is already in progress."),t.reject(!1)):(this._plugin&&this._plugin.unregister(function(){},function(){}),new l.APIRequest({uri:_.invalidateToken(e),method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify({platform:n,token:e.getStorageToken().token})}).then(function(n){e._blockUnregister=!1,e.logger.info("unregistered push token: "+e.getStorageToken().token),e.clearStorageToken(),t.resolve(n)},function(n){e._blockUnregister=!1,e.logger.error(n),t.reject(n)})),t.promise}},{key:"getPayload",value:function(e){return e.payload}},{key:"setRegisterCallback",value:function(e){return"function"!=typeof e?(this.logger.info("setRegisterCallback() requires a valid callback function"),!1):(this.registerCallback=e,!0)}},{key:"setNotificationCallback",value:function(e){return"function"!=typeof e?(this.logger.info("setNotificationCallback() requires a valid callback function"),!1):(this.notificationCallback=e,!0)}},{key:"setErrorCallback",value:function(e){return"function"!=typeof e?(this.logger.info("setErrorCallback() requires a valid callback function"),!1):(this.errorCallback=e,!0)}},{key:"_debugRegistrationCallback",value:function(){function e(e){t.token=new d.PushToken(e.registrationId),t.logger.info("(debug) device token registered: "+t._token)}var t=this;return e}},{key:"_debugNotificationCallback",value:function(){function e(e){t._processNotification(e);var n=h.PushMessage.fromPluginJSON(e);t.logger.info("(debug) notification received: "+n),!t.notificationCallback&&t.app.devPush&&alert(n.text)}var t=this;return e}},{key:"_debugErrorCallback",value:function(){function e(e){t.logger.error("(debug) unexpected error occured."),t.logger.error(e)}var t=this;return e}},{key:"_registerCallback",value:function(){function e(e){return t.token=new d.PushToken(e.registrationId),t.registerCallback?t.registerCallback(t._token):void 0}var t=this;return e}},{key:"_notificationCallback",value:function(){function e(e){t._processNotification(e);var n=h.PushMessage.fromPluginJSON(e);return t.notificationCallback?t.notificationCallback(n):void 0}var t=this;return e}},{key:"_errorCallback",value:function(){function e(e){return t.errorCallback?t.errorCallback(e):void 0}var t=this;return e}},{key:"_debugCallbackRegistration",value:function(){this._config.debug&&(this.app.devPush?this._registered||(this._emitter.on("ionic_push:token",this._debugRegistrationCallback()),this._emitter.on("ionic_push:notification",this._debugNotificationCallback()),this._emitter.on("ionic_push:error",this._debugErrorCallback())):(this._plugin.on("registration",this._debugRegistrationCallback()),this._plugin.on("notification",this._debugNotificationCallback()),this._plugin.on("error",this._debugErrorCallback())))}},{key:"_callbackRegistration",value:function(){this.app.devPush?this._registered||(this._emitter.on("ionic_push:token",this._registerCallback()),this._emitter.on("ionic_push:notification",this._notificationCallback()),this._emitter.on("ionic_push:error",this._errorCallback())):(this._plugin.on("registration",this._registerCallback()),this._plugin.on("notification",this._notificationCallback()),this._plugin.on("error",this._errorCallback()))}},{key:"_processNotification",value:function(e){this._notification=e,this._emitter.emit("ionic_push:processNotification",e)}},{key:"_getPushPlugin",value:function(){var e=this,t=!1;try{t=window.PushNotification}catch(n){e.logger.info("something went wrong looking for the PushNotification plugin")}return e.app.devPush||t||!s.IonicPlatform.isIOSDevice()&&!s.IonicPlatform.isAndroidDevice()||e.logger.error("PushNotification plugin is required. Have you run `ionic plugin add phonegap-plugin-push` ?"),t}},{key:"onReady",value:function(e){var t=this;this._isReady?e(t):t._emitter.on("ionic_push:ready",function(){e(t)})}},{key:"token",set:function(e){var t=s.IonicPlatform.getStorage();e instanceof d.PushToken&&t.storeObject("ionic_io_push_token",{token:e.token}),this._token=e}}]),e}();n.Push=k},{"../core/app":11,"../core/core":12,"../core/events":15,"../core/logger":16,"../core/promise":17,"../core/request":18,"../core/settings":19,"./push-dev":27,"./push-message":28,"./push-token":29}]},{},[17,18,15,16,20,19,13,12,21,11,14,10,29,28,27,30,26,25,23,24,22,9,8,5,7,6]);