diff --git a/dist/leanplum.js b/dist/leanplum.js index fb0c533b..7c1eae1a 100644 --- a/dist/leanplum.js +++ b/dist/leanplum.js @@ -1,2 +1,2 @@ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Leanplum=t():e.Leanplum=t()}(window,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)n.d(r,i,function(t){return e[t]}.bind(null,i));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=6)}([function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default={METHODS:{START:"start",STOP:"stop",ADVANCE:"advance",TRACK:"track",PAUSE_SESSION:"pauseSession",RESUME_SESSION:"resumeSession",PAUSE_STATE:"pauseState",RESUME_STATE:"resumeState",DOWNLOAD_FILE:"downloadFile",MULTI:"multi",SET_VARS:"setVars",GET_VARS:"getVars",SET_USER_ATTRIBUTES:"setUserAttributes",SET_DEVICE_ATTRIBUTES:"setDeviceAttributes",UPLOAD_FILE:"uploadFile",REGISTER_DEVICE:"registerDevice"},SDK_VERSION:"1.9.0",CLIENT:"js",PARAMS:{ACTION:"action",APP_ID:"appId",CLIENT:"client",CLIENT_KEY:"clientKey",CURRENCY_CODE:"currencyCode",DEVICE_ID:"deviceId",SDK_VERSION:"sdkVersion",USER_ID:"userId",NEW_USER_ID:"newUserId",DEV_MODE:"devMode",VERSION_NAME:"versionName",SYSTEM_NAME:"systemName",SYSTEM_VERSION:"systemVersion",BROWSER_NAME:"browserName",BROWSER_VERSION:"browserVersion",DEVICE_NAME:"deviceName",DEVICE_MODEL:"deviceModel",USER_ATTRIBUTES:"userAttributes",LOCALE:"locale",COUNTRY:"country",REGION:"region",CITY:"city",LOCATION:"location",STATE:"state",INFO:"info",EVENT:"event",VALUE:"value",FILENAME:"filename",TIME:"time",DATA:"data",VARS:"vars",FILE:"file",SIZE:"size",VARIATION:"variation",HASH:"hash",EMAIL:"email",VARIABLES:"vars",ACTION_DEFINITIONS:"actionDefinitions",PARAMS:"params",INCLUDE_DEFAULTS:"includeDefaults",INCLUDE_VARIANT_DEBUG_INFO:"includeVariantDebugInfo",NEWSFEED_MESSAGES:"newsfeedMessages",MESSAGE_ID:"messageId",WEB_PUSH_SUBSCRIPTION:"webPushSubscription"},KEYS:{IS_REGISTERED:"isRegistered",LATEST_VERSION:"latestVersion",SYNC_INBOX:"syncNewsfeed",MESSAGES:"messages",VARS:"vars",VARIANTS:"variants",VARIANT_DEBUG_INFO:"variantDebugInfo",ACTION_DEFINITIONS:"actionDefinitions",TOKEN:"token"},DEFAULT_KEYS:{COUNT:"__leanplum_unsynced",ITEM:"__leanplum_unsynced_",VARIABLES:"__leanplum_variables",VARIANTS:"__leanplum_variants",VARIANT_DEBUG_INFO:"__leanplum_variant_debug_info",ACTION_DEFINITIONS:"__leanplum_action_definitions",INBOX_MESSAGES:"__leanplum_inbox_messages",TOKEN:"__leanplum_token",DEVICE_ID:"__leanplum_device_id",USER_ID:"__leanplum_user_id",SESSION:"__leanplum_session",MESSAGE_OCCURRENCES:"__leanplum_message_occurrences",MESSAGE_CACHE:"__leanplum_message_cache",PUSH_SUBSCRIPTION:"__leanplum_push_subscription"},VALUES:{DETECT:"(detect)",DEFAULT_PUSH_ACTION:"Open action"}}},function(e,t,n){"use strict";var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});var i=r(n(0)),s=function(){function e(){this.argString="",this.argValues={}}return e.prototype.add=function(e,t){if(void 0===t)return this;this.argString&&(this.argString+="&");var n="";return n=t instanceof Array?JSON.stringify(t):encodeURIComponent(t),this.argString+=e+"="+n,this.argValues[e]=t,this},e.prototype.body=function(e){return e?(this._body=e,this):this._body},e.prototype.attachApiKeys=function(e,t){return this.add(i.default.PARAMS.APP_ID,e).add(i.default.PARAMS.CLIENT,i.default.CLIENT).add(i.default.PARAMS.CLIENT_KEY,t)},e.prototype.build=function(){return this.argString},e.prototype.buildDict=function(){return this.argValues},e}();t.default=s},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r={local:!0,session:!0},i={local:{},session:{}},s=function(){function e(){}return e.get=function(e,t){return void 0===t&&(t="local"),r[t]?"local"===t?localStorage[e]:sessionStorage.getItem(e):i[t][e]},e.save=function(e,t,n){if(void 0===n&&(n="local"),r[n])try{"local"===n?localStorage[e]=t:sessionStorage.setItem(e,t)}catch(s){r[n]=!1,i[n][e]=t}else i[n][e]=t},e.remove=function(e,t){if(void 0===t&&(t="local"),r[t])try{"local"===t?localStorage.removeItem(e):sessionStorage.removeItem(e)}catch(n){r[t]=!1,delete i[t][e]}else delete i[t][e]},e}();t.default=s},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function(){function e(){this.networkTimeoutSeconds=10,this.requestQueue=[],this.runningRequest=!1}return e.prototype.setNetworkTimeout=function(e){this.networkTimeoutSeconds=e},e.prototype.ajax=function(e,t,n,r,i,s,o){var a=this;if(s){if(this.runningRequest)return this.enqueueRequest(arguments);this.runningRequest=!0}if("undefined"!=typeof XDomainRequest)return"http:"===location.protocol&&0===t.indexOf("https:")&&(t="http:"+t.substring(6)),this.ajaxIE8(e,t,n,r,i,s,o);var u=!1,c=new XMLHttpRequest;c.onreadystatechange=function(){if(4===c.readyState){if(u)return;var e;u=!0;var t=!1;if(o)e=c.responseText;else try{e=JSON.parse(c.responseText)}catch(e){setTimeout((function(){i&&i(null,c)}),0),t=!0}t||(c.status>=200&&c.status<300?setTimeout((function(){r&&r(e,c)}),0):setTimeout((function(){i&&i(e,c)}),0)),s&&(a.runningRequest=!1,a.dequeueRequest())}},c.open(e,t,!0),c.setRequestHeader("Content-Type","text/plain"),c.send(n),setTimeout((function(){u||c.abort()}),1e3*this.networkTimeoutSeconds)},e.prototype.ajaxIE8=function(e,t,n,r,i,s,o){var a=this,u=new XDomainRequest;u.onload=function(){var e,t=!1;if(o)e=u.responseText;else try{e=JSON.parse(u.responseText)}catch(e){setTimeout((function(){i&&i(null,u)}),0),t=!0}t||setTimeout((function(){r&&r(e,u)}),0),s&&(a.runningRequest=!1,a.dequeueRequest())},u.onerror=u.ontimeout=function(){setTimeout((function(){i&&i(null,u)}),0),s&&(a.runningRequest=!1,a.dequeueRequest())},u.onprogress=function(){},u.open(e,t),u.timeout=1e3*this.networkTimeoutSeconds,u.send(n)},e.prototype.enqueueRequest=function(e){this.requestQueue.push(e)},e.prototype.dequeueRequest=function(){var e=this.requestQueue.shift();e&&this.ajax.apply(this,e)},e}();t.default=r},function(e,t,n){(function(e,n){var r="[object Arguments]",i="[object Map]",s="[object Object]",o="[object Set]",a=/^\[object .+?Constructor\]$/,u=/^(?:0|[1-9]\d*)$/,c={};c["[object Float32Array]"]=c["[object Float64Array]"]=c["[object Int8Array]"]=c["[object Int16Array]"]=c["[object Int32Array]"]=c["[object Uint8Array]"]=c["[object Uint8ClampedArray]"]=c["[object Uint16Array]"]=c["[object Uint32Array]"]=!0,c[r]=c["[object Array]"]=c["[object ArrayBuffer]"]=c["[object Boolean]"]=c["[object DataView]"]=c["[object Date]"]=c["[object Error]"]=c["[object Function]"]=c[i]=c["[object Number]"]=c[s]=c["[object RegExp]"]=c[o]=c["[object String]"]=c["[object WeakMap]"]=!1;var l="object"==typeof e&&e&&e.Object===Object&&e,d="object"==typeof self&&self&&self.Object===Object&&self,f=l||d||Function("return this")(),p=t&&!t.nodeType&&t,h=p&&"object"==typeof n&&n&&!n.nodeType&&n,v=h&&h.exports===p,g=v&&l.process,_=function(){try{return g&&g.binding&&g.binding("util")}catch(e){}}(),S=_&&_.isTypedArray;function y(e,t){for(var n=-1,r=null==e?0:e.length;++na))return!1;var c=s.get(e);if(c&&s.get(t))return c==t;var l=-1,d=!0,f=2&n?new se:void 0;for(s.set(e,t),s.set(t,e);++l-1},re.prototype.set=function(e,t){var n=this.__data__,r=ue(n,e);return r<0?(++this.size,n.push([e,t])):n[r][1]=t,this},ie.prototype.clear=function(){this.size=0,this.__data__={hash:new ne,map:new(W||re),string:new ne}},ie.prototype.delete=function(e){var t=ge(this,e).delete(e);return this.size-=t?1:0,t},ie.prototype.get=function(e){return ge(this,e).get(e)},ie.prototype.has=function(e){return ge(this,e).has(e)},ie.prototype.set=function(e,t){var n=ge(this,e),r=n.size;return n.set(e,t),this.size+=n.size==r?0:1,this},se.prototype.add=se.prototype.push=function(e){return this.__data__.set(e,"__lodash_hash_undefined__"),this},se.prototype.has=function(e){return this.__data__.has(e)},oe.prototype.clear=function(){this.__data__=new re,this.size=0},oe.prototype.delete=function(e){var t=this.__data__,n=t.delete(e);return this.size=t.size,n},oe.prototype.get=function(e){return this.__data__.get(e)},oe.prototype.has=function(e){return this.__data__.has(e)},oe.prototype.set=function(e,t){var n=this.__data__;if(n instanceof re){var r=n.__data__;if(!W||r.length<199)return r.push([e,t]),this.size=++n.size,this;n=this.__data__=new ie(r)}return n.set(e,t),this.size=n.size,this};var Se=q?function(e){return null==e?[]:(e=Object(e),function(e,t){for(var n=-1,r=null==e?0:e.length,i=0,s=[];++n-1&&e%1==0&&e-1&&e%1==0&&e<=9007199254740991}function De(e){var t=typeof e;return null!=e&&("object"==t||"function"==t)}function Oe(e){return null!=e&&"object"==typeof e}var we=S?function(e){return function(t){return e(t)}}(S):function(e){return Oe(e)&&Me(e.length)&&!!c[ce(e)]};function Ne(e){return null!=(t=e)&&Me(t.length)&&!Te(t)?ae(e):pe(e);var t}n.exports=function(e,t){return de(e,t)}}).call(this,n(14),n(15)(e))},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function(){function e(){}return e.decodeColor=function(e){var t=255&e,n=255&(e>>=8);return"rgba("+(255&(e>>=8))+","+n+","+t+","+(255&(e>>=8))/255+")"},e.encodeColor=function(e){if("number"==typeof e)return e;var t=/^rgba\((\d+),(\d+),(\d+),(\d+(\.\d+)?)\)$/.exec(e);if(t)return(255*parseInt(t[4],10)<<24)+((255&parseInt(t[1],10))<<16)+((255&parseInt(t[2],10))<<8)+(255&parseInt(t[3],10));var n=/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(e);if(n)return(255<<24)+((255&parseInt(n[1],16))<<16)+((255&parseInt(n[2],16))<<8)+(255&parseInt(n[3],16));throw new Error('Could not parse color "'+e+'"')},e}();t.default=r},function(e,t,n){var r=n(7);e.exports=r.default},function(e,t,n){"use strict";var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});var i=r(n(0)),s=r(n(8)),o=function(){function e(){}return e.setApiPath=function(t){e._lp.setApiPath(t)},e.setEmail=function(){},e.setNetworkTimeout=function(t){e._lp.setNetworkTimeout(t)},e.setAppIdForDevelopmentMode=function(t,n){e._lp.setAppIdForDevelopmentMode(t,n)},e.setAppIdForProductionMode=function(t,n){e._lp.setAppIdForProductionMode(t,n)},e.setSocketHost=function(t){e._lp.setSocketHost(t)},e.setDeviceId=function(t){e._lp.setDeviceId(t)},e.setLocale=function(t){e._lp.setLocale(t)},e.setAppVersion=function(t){e._lp.setAppVersion(t)},e.setDeviceName=function(t){e._lp.setDeviceName(t)},e.setDeviceModel=function(t){e._lp.setDeviceModel(t)},e.setRequestBatching=function(t,n){e._lp.setRequestBatching(t,n)},e.setSystemName=function(t){e._lp.setSystemName(t)},e.setSystemVersion=function(t){e._lp.setSystemVersion(t)},e.setVariables=function(t){e._lp.setVariables(t)},e.setVariantDebugInfoEnabled=function(t){e._lp.setVariantDebugInfoEnabled(t)},e.enableRichInAppMessages=function(t){e._lp.enableRichInAppMessages(t)},e.processMessageEvent=function(t,n){e._lp.processMessageEvent(t,n)},e.getVariantDebugInfo=function(){return e._lp.getVariantDebugInfo()},e.getVariables=function(){return e._lp.getVariables()},e.getVariable=function(){for(var t,n=[],r=0;r=0&&this.startHandlers.splice(t,1)},e.prototype.triggerStartHandlers=function(){for(var e=0;e0){var t=JSON.stringify({data:e}),o=(new i.default).attachApiKeys(r.appId,r.clientKey).add(s.default.PARAMS.SDK_VERSION,s.default.SDK_VERSION).add(s.default.PARAMS.ACTION,s.default.METHODS.MULTI).add(s.default.PARAMS.TIME,((new Date).getTime()/1e3).toString().toString()).build();r.network.ajax("POST",r.apiPath+"?"+o,t,l,d,n.queued)}};if(!p&&this.batchCooldown){var v=(new Date).getTime()/1e3;!this.lastRequestTime||v-this.lastRequestTime>=this.batchCooldown?(p=!0,this.lastRequestTime=v):this.cooldownTimeout||(this.cooldownTimeout=setTimeout((function(){r.cooldownTimeout=null,r.lastRequestTime=(new Date).getTime()/1e3,h()}),1e3*(this.batchCooldown-(v-this.lastRequestTime))))}this.saveRequestForLater(c.buildDict()),p&&h()}},e.prototype.getFileUrl=function(e){if(!e)return"";if(/^https?:/.test(e))return e;var t=(new i.default).attachApiKeys(this.appId,this.clientKey).add(s.default.PARAMS.SDK_VERSION,s.default.SDK_VERSION).add(s.default.PARAMS.ACTION,"downloadFile").add("filename",e);return this.apiPath+"?"+t.build()},e.prototype.setNetworkTimeout=function(e){this.network.setNetworkTimeout(e)},e.prototype.getLastResponse=function(e){var t,n,r,i=null!==(n=null===(t=null==e?void 0:e.response)||void 0===t?void 0:t.length)&&void 0!==n?n:0;return i>0?null===(r=null==e?void 0:e.response)||void 0===r?void 0:r[i-1]:null},e.prototype.isResponseSuccess=function(e){return Boolean(null==e?void 0:e.success)},e.prototype.saveRequestForLater=function(e){var t=this.loadLocal(s.default.DEFAULT_KEYS.COUNT)||0,n=s.default.DEFAULT_KEYS.ITEM+t;this.saveLocal(n,JSON.stringify(e)),t++,this.saveLocal(s.default.DEFAULT_KEYS.COUNT,t)},e.prototype.popUnsentRequests=function(){var e=[],t=this.loadLocal(s.default.DEFAULT_KEYS.COUNT)||0;this.removeLocal(s.default.DEFAULT_KEYS.COUNT);for(var n=0;n0&&i[i.length-1])||6!==s[0]&&2!==s[0])){o=0;continue}if(3===s[0]&&(!i||s[1]>i[0]&&s[1]0){var l=u["HTML Width"];n.style.height=u["HTML Height"]+"px",n.style.width=l,n.style.left="calc((100% - "+l+") / 2)";var d=u["HTML Align"].toLowerCase(),f="top"===d?"bottom":"top";n.style[d]="0",n.style[f]=""}else n.style.top="0";c.track();break;case"track":c.track(o.event,parseFloat(o.value),o.parameters,o.info);break;case"runAction":case"runTrackedAction":c[i+"Named"](o.action);case"close":n.metadata=null,n.parentNode.removeChild(n)}}else console.log("message closed, skipping event processing")},e.prototype.handleMessage=function(e){var t=this;if(this._showRichIAM&&"HTML"===e.message.__name__){this.resolveFiles(e.message);var n=e.message.Template||"";(new a.default).ajax("get",n.replace("-10.html","-11.html"),"",(function(n){return t.renderRichInAppMessage(n,e)}),(function(){}),!1,!0)}else this.events.emit("showMessage",this.resolveFields(e))},e.prototype.renderRichInAppMessage=function(e,t){var n=t.message.messageId,r=JSON.stringify(t.message),i=document.createElement("iframe");i.setAttribute("id","lp-message-"+n),i.style.cssText=["border-width: 0","position: fixed","top: -100%","left: -100%","width: 100%","height: 100%","visibility: hidden","z-index: 100000"].join(";"),document.body.appendChild(i),i.metadata=t,i.contentWindow.messageId=n;var s=e.replace("##Vars##",r).replace("","